diff --git a/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/1.png b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/1.png new file mode 100644 index 00000000..726cde47 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/1.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/10.png b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/10.png new file mode 100644 index 00000000..a88d5d8b Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/10.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/2.png b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/2.png new file mode 100644 index 00000000..7087109c Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/2.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/3.png b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/3.png new file mode 100644 index 00000000..aae562bf Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/3.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/4.png b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/4.png new file mode 100644 index 00000000..85d1e24d Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/4.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/5.png b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/5.png new file mode 100644 index 00000000..ce0d7728 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/5.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/6.png b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/6.png new file mode 100644 index 00000000..b7b3cd01 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/6.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/7.png b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/7.png new file mode 100644 index 00000000..b053ded8 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/7.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/8.png b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/8.png new file mode 100644 index 00000000..3cf0e617 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/8.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/9.png b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/9.png new file mode 100644 index 00000000..3aff50c3 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/9.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/Sigma_Footer.png b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/Sigma_Footer.png new file mode 100644 index 00000000..df51d771 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/_shared_assets/Sigma_Footer.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/apics10.png b/site/sigmaguides/embedding_15_embed_sdk/assets/apics10.png new file mode 100644 index 00000000..d35254d1 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/apics10.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/apics11.png b/site/sigmaguides/embedding_15_embed_sdk/assets/apics11.png new file mode 100644 index 00000000..6ab53ef3 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/apics11.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/apics2.png b/site/sigmaguides/embedding_15_embed_sdk/assets/apics2.png new file mode 100644 index 00000000..087560c9 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/apics2.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/facebook.png b/site/sigmaguides/embedding_15_embed_sdk/assets/facebook.png new file mode 100644 index 00000000..fa3f0e02 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/facebook.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/greencheckbox.png b/site/sigmaguides/embedding_15_embed_sdk/assets/greencheckbox.png new file mode 100644 index 00000000..69cb876e Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/greencheckbox.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/horizonalline.png b/site/sigmaguides/embedding_15_embed_sdk/assets/horizonalline.png new file mode 100644 index 00000000..7c49d872 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/horizonalline.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/linkedin.png b/site/sigmaguides/embedding_15_embed_sdk/assets/linkedin.png new file mode 100644 index 00000000..d1a0636d Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/linkedin.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk1.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk1.png new file mode 100644 index 00000000..24aa7af9 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk1.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk10.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk10.png new file mode 100644 index 00000000..f26e9fae Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk10.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk11.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk11.png new file mode 100644 index 00000000..a4b5ffe7 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk11.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk12.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk12.png new file mode 100644 index 00000000..124c8d34 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk12.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk13.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk13.png new file mode 100644 index 00000000..89ff0cb3 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk13.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk14.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk14.png new file mode 100644 index 00000000..cb176a52 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk14.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk15.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk15.png new file mode 100644 index 00000000..8a433132 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk15.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk16.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk16.png new file mode 100644 index 00000000..4468cc04 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk16.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk17.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk17.png new file mode 100644 index 00000000..e3274d78 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk17.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk18.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk18.png new file mode 100644 index 00000000..1c7654f9 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk18.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk19.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk19.png new file mode 100644 index 00000000..4c76232a Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk19.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk2.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk2.png new file mode 100644 index 00000000..6a671e1d Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk2.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk20.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk20.png new file mode 100644 index 00000000..e1f40019 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk20.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk21.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk21.png new file mode 100644 index 00000000..d7df724c Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk21.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk22.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk22.png new file mode 100644 index 00000000..b1f3ff48 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk22.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk23.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk23.png new file mode 100644 index 00000000..07b64e85 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk23.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk24.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk24.png new file mode 100644 index 00000000..83700026 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk24.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk25.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk25.png new file mode 100644 index 00000000..c50a6704 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk25.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk26.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk26.png new file mode 100644 index 00000000..7f9eccaa Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk26.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk27.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk27.png new file mode 100644 index 00000000..7549421a Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk27.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk28.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk28.png new file mode 100644 index 00000000..ed6c7fa7 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk28.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk29.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk29.png new file mode 100644 index 00000000..fe4a91cf Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk29.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk3.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk3.png new file mode 100644 index 00000000..5aeaeeb6 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk3.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk30.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk30.png new file mode 100644 index 00000000..86ee7c6e Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk30.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk31.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk31.png new file mode 100644 index 00000000..e5a16c78 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk31.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk5.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk5.png new file mode 100644 index 00000000..7ef28eae Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk5.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk6.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk6.png new file mode 100644 index 00000000..7d11a817 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk6.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk7.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk7.png new file mode 100644 index 00000000..c28e637e Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk7.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk8.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk8.png new file mode 100644 index 00000000..4cb1cb31 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk8.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sdk9.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk9.png new file mode 100644 index 00000000..21c6ba41 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sdk9.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/sigma_footer.png b/site/sigmaguides/embedding_15_embed_sdk/assets/sigma_footer.png new file mode 100644 index 00000000..df51d771 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/sigma_footer.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/assets/twitter.png b/site/sigmaguides/embedding_15_embed_sdk/assets/twitter.png new file mode 100644 index 00000000..5a827d72 Binary files /dev/null and b/site/sigmaguides/embedding_15_embed_sdk/assets/twitter.png differ diff --git a/site/sigmaguides/embedding_15_embed_sdk/embedding_15_embed_sdk.md b/site/sigmaguides/embedding_15_embed_sdk/embedding_15_embed_sdk.md new file mode 100644 index 00000000..2ff931c5 --- /dev/null +++ b/site/sigmaguides/embedding_15_embed_sdk/embedding_15_embed_sdk.md @@ -0,0 +1,684 @@ +author: pballai +id: embedding_15_embed_sdk +summary: embedding_15_embed_sdk +categories: Embedding +environments: web +status: hidden +feedback link: https://github.com/sigmacomputing/sigmaquickstarts/issues +tags: +lastUpdated: 2024-08-12 + +# Embedding 15: Embed-SDK for React + +## Overview +Duration: 5 + +Sigma provides many methods to allow users and developers to interact with its systems including web-ui, REST API, Javascript Embed API and an SDK for the React framework. + +The Embed-SDK for [React](https://react.dev/) provides an addition avenue, targeted at software developers who prefer to use a software development kit (SDK), as opposed to using the Sigmas JavaScript Embed-API, which can require writing additional code. + +There are several reasons why developers might choose one over the other. Each method offers distinct advantages depending on the project requirements, developer expertise, and desired level of control or simplicity. + +Some of those reasons can be: + +### Simplification of Integration: +**Ease of Use:** An SDK typically provides higher-level abstractions and utilities that simplify integration into various frameworks and environments. It’s often designed to handle common tasks, setup, and error handling more automatically. + +**Reduced Boilerplate Code:** Using an SDK can significantly reduce the amount of code developers need to write themselves, as it often includes methods that encapsulate multiple steps of a process into single function calls. + +### Consistency and Reliability: +**Standardized Code:** SDKs provide a standardized way of interacting with an API, which can reduce errors and inconsistencies in how different developers or teams implement their solutions. + +**Maintained by Source:** Since SDKs are usually provided and maintained by the source company (in this case, Sigma), they are likely to be well-supported and updated regularly, ensuring compatibility with the latest versions of the API. + +### Framework-Specific Integration: +**Framework Optimizations:** SDKs often include optimizations for specific programming frameworks (like React, Angular, or Vue.js). For example, a React SDK might use hooks or context providers to integrate more seamlessly with React apps. + +**Handling Dependencies:** The SDK might automatically manage dependencies and interactions with other libraries, which can help in maintaining clean and efficient codebases. + +Choosing between an SDK and directly using an API depends on the specific needs of your project, your team’s expertise, and the level of custom functionality required. + +SDKs are generally recommended for most standard implementations due to their ease of use, while direct API integration might be better suited for more customized or lower-level integrations. + +### Target Audience +Developers interested in evaluating Sigma software development kit ("SDK") for [React.](https://react.dev/) + +### Prerequisites + + + + + + + +![Footer](assets/sigma_footer.png) + +## Source Code Editor - VSCode +Duration: 5 + +For this QuickStart, we will demonstrate using Visual Studio Code (VSCode), but you may use any IDE you prefer. + +VSCode, is a source-code editor developed by Microsoft for Windows, Linux and macOS. Features include support for debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded Git. + +[Install VSCode from Microsoft's download site.](https://code.visualstudio.com/download) + +Run the installation with all defaults. + +Open VSCode and make sure it loads without error. + +![Footer](assets/sigma_footer.png) + + +## Clone Embed-SDK Repository (repo) +Duration: 5 + +To save you time, we've stored all the necessary project files in Git-Hub ("git"). Simply clone the git repo using a VSCode to download a copy to our local computer. + +To clone the git repository in VSCode, click the link to `Clone Git Repository`: + + + +Paste this URL and hit enter: +```code +https://github.com/sigmacomputing/embed-sdk.git +``` + +VSCode will prompt for the location to store the files on your computer. Navigate to the a top-level folder of your choice and click the `Select as Repository Destination` button. + + + +When prompted, open the cloned repository. + +The repository contains the entire `Embed-SDK` for you to explore, and there is a sample application we will use for demonstration. + +Before we do that, we need to install a few other dependencies to prepare the project folder for initial use. + +![Footer](assets/sigma_footer.png) + + +## Environment Setup +Duration: 20 + +We need to install Node and other related packages. While this can be done manually, Homebrew allows us to install Node and pnpm with a simple command. + +This avoids the need to manually download and install from the official websites. + +Using VSCode, open a new terminal session: + + + +Paste the following command into terminal and press Enter. This command will download and install Homebrew: + +```code +/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" +``` + +The system will prompt for your system password, and then wait till enter is pressed: + + + +Homebrew will be downloaded and setup. Once completed, a success message will be shown: + + + +To verify the installation, run the command: +```code +brew --version +``` + +A version number should be returned. If not, review the next section. + +### Brew: command not found error +This error generally indicates that brew cannot be found by the terminal session. This can be resolved by manually adding Homebrew to the path. + +In terminal, open your .zshrc file with this command (still in terminal): +```code +nano ~/.zshrc +``` + +Add the following line at the end of the file to include Homebrew’s path: +```code +export PATH="/opt/homebrew/bin:$PATH" +``` + + + + +Save the changes, overwriting the existing file (the commands are shown on the editor's footer). + +Close the editor after saving. + +Reload your shell configuration by running this command: +```code +source ~/.zshrc +``` + +The terminal prompt will reappear with no reply. + +Retry brew verification: +```code +brew --version +``` + +The expected response looks like this: + + + +![Footer](assets/sigma_footer.png) + + +### Runtime Environment - Node.js + +Node.js (Node) is an open-source, cross-platform, back-end JavaScript runtime environment that runs on a JavaScript engine and executes JavaScript plaintext outside a web browser, which was designed to build scalable network applications. + +We will install Node by using a terminal session in VSCode and leverage Homebrew via command line. + +In VSCode, open a new terminal session and run the following command to check if Node is already installed: + +```code +node -v +``` + +In our case, we see a recent version number, so no need to install again: + + + +If Node.js is not already installed, install it by running the following command: + +```code +brew install node +``` + +This command will download and install the latest stable version of Node along with npm (Node Package Manager) on your system. Once the installation is complete, you can verify the installation by checking the versions of Node.js as described earlier. + + + +### Additional Dependencies + +#### Corepack +Corepack is a Node.js tool intended to manage versions of your package managers (Yarn, pnpm) without needing global installs of these package managers. It comes pre-installed with Node.js starting from version 16.10. We need to enable it. + +Run the following command to enable `Corepack`: + +```code +corepack enable +``` + +The terminal prompt will appear with no other message unless there is an error. + + + +#### pnpm +pnpm is a package manager like npm or Yarn, known for its efficiency regarding disk space and speed. + +Running pnpm i installs the dependencies listed in your project’s package.json file. It creates a node_modules directory where all your project’s dependencies are stored and also updates the pnpm-lock.yaml file, which ensures that the same versions of the dependencies are installed every time you or anyone else runs pnpm install. + +Run the following command to install `pnpm`: + +```code +pnpm i +``` + +The results look like this: + + + +![Footer](assets/sigma_footer.png) + + + +## Start Development Server + +We are ready to test the `Embed-SDK` application. Run the following command in terminal: + +```code +pnpm run dev +``` + +The first time, the system may prompt to allow network connections. Click `Allow`, as this is only running on our local machine, port 3000. + +This starts the development server and when ready will appear like this. + + + +Open a browser and navigate to: +```code +http://localhost:3000 +``` + +Sigma has provided a sample application page, with useful links. + + + +In the next section will will look at how the embed is configured in code. + +![Footer](assets/sigma_footer.png) + + +## Sample Application +Duration: 5 + +From the landing page, click the link for the `Sample Application`. + +The sample application has an example of a Sigma embed (provided from a Sigma instance) along with a list of the primary files involved. + +The list of files has tooltips to provide general information but the files themselves are commented to assist you. + + + +### Primary source files + +There are five files involved in this example embed: + + + +```code +# .env +# Sigma Embed Credentials. These two values will need to be changed when using your own Sigma instance to embed content + +# Values from my Sigma instance +# EMBED_CLIENT_ID= +# EMBED_SECRET= + +# Original values from git +EMBED_CLIENT_ID=eeb0cc6caa7d5aa25088145c08041d1fa98de36916545fbe0fe7d31442509d38 +EMBED_SECRET=0d5ec5ab0c1c3f452c146ebd74f645c0ac17a27137bd93d2e3ad5313be3624c476fced8a2f5ca8dc49dcf4f54548a95752600fe22a02b50b584ba90a8affdb55 +``` + + + +```code +/* utils.tx */ +/* contains utility functions that facilitate the embedding of Sigma dashboards into a web application by generating signed URLs */ + +import { type ClassValue, clsx } from "clsx"; +import { twMerge } from "tailwind-merge"; +import { v4 as uuid } from "uuid"; + +/** + * Merges Tailwind CSS classes conditionally. + * @param inputs - An array of class values to conditionally merge. + * @returns A string of merged class names. + */ +export function cn(...inputs: ClassValue[]) { + return twMerge(clsx(inputs)); +} + +/** + * Converts an ArrayBuffer to a hex string. + * - Converts the buffer to a byte array. + * - Maps each byte to a two-character hex string. + * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#converting_a_digest_to_a_hex_string + */ +export function bufferToHex(buffer: ArrayBuffer) { + return Array.from(new Uint8Array(buffer)) + .map((b) => b.toString(16).padStart(2, "0")) + .join(""); +} + +/** + * Uses the Web Crypto API to create a SHA256 HMAC hex string. + * @param key - The key used for signing. + * @param data - The data to be signed. + * @returns An object containing the hex string of the HMAC signature. + */ +async function simpleHmac({ key, data }: { key: string; data: string }) { + const encoder = new TextEncoder(); + const encodedKey = encoder.encode(key); + const encodedData = encoder.encode(data); + + // Import the key for HMAC signing + const hmacKey = await crypto.subtle.importKey( + "raw", + encodedKey, + { + name: "HMAC", + hash: "SHA-256", + }, + true, + ["sign", "verify"], + ); + + // Sign the data using the imported key + const signature = await crypto.subtle.sign("HMAC", hmacKey, encodedData); + + // Convert the signature to a hex string + const hex = bufferToHex(signature); + + return { hex }; +} + +/** + * Signs a Sigma embed URL with a cryptographic signature. + * @param dashboard - The base URL of the Sigma dashboard or visualization. + * @returns A signed URL with appended query parameters. + */ +export async function signEmbedUrl(dashboard: string): Promise { + const { EMBED_SECRET, EMBED_CLIENT_ID } = process.env; + if (!EMBED_SECRET || !EMBED_CLIENT_ID) { + throw new Error("SIGMA_EMBED_SECRET is not set"); + } + + // Sigma Embed Parameters (normally, these are generated programmatically) + const searchParamsObject = { + ":mode": "userbacked", // mode for secure embedding + ":email": "embed-sdk@sigmacomputing.com", // Email associated with the embedded session + ":external_user_team": "Embed-SDK-Team", // External team associated with the user + ":account_type": "viewer", // Account type, e.g., viewer or editor + ":nonce": uuid(), // Unique identifier for the session to prevent replay attacks + ":time": `${Math.floor(new Date().getTime() / 1000)}`, // Current timestamp in seconds + ":session_length": "36000", // Session length in seconds (10 hours) + ":client_id": EMBED_CLIENT_ID, // Client ID for authentication + ":external_user_id": "123", // External user ID for tracking purposes + }; + + const searchParams = new URLSearchParams(searchParamsObject); + + // Append search parameters to the base dashboard URL + const urlWithSearchParams = `${dashboard}?${searchParams.toString()}`; + + // Create a cryptographic signature using the embed secret + const SIGNATURE = await simpleHmac({ + key: EMBED_SECRET, + data: urlWithSearchParams, + }); + + // Append the signature to the query parameters + searchParams.append(":signature", SIGNATURE.hex); + + // Construct the final signed URL + const signedUrl = `${dashboard}?${searchParams.toString()}`; + + return signedUrl; +} +``` + + + +```code +// basic-example-wrapper.tsx +// The SignedIframe component is responsible for securely embedding a Sigma Computing dashboard into a React application. +// signEmbedUrl: This function is imported from the Sigma Embed SDK library and is used to generate a signed URL for secure access to a Sigma dashboard. + +// Import the signEmbedUrl function from the utilities module +import { signEmbedUrl } from "@/lib/utils"; +// Import the BasicExample component, which is responsible for rendering the iframe +import BasicExample from "./basic-example-embed"; + +// Define an asynchronous component to sign the URL and render the iframe +export default async function SignedIframe() { + // The base URL for the Sigma Computing dashboard or visualization to be embedded + const src = "https://app.sigmacomputing.com/embed/2jRbZzf2xabnOdBvd3TPRE"; + + try { + // Await the signed URL by passing the base URL to the signEmbedUrl function + const signedSrc = await signEmbedUrl(src); + + // Log the base and signed URLs as output in server-side terminal session + console.log("Signed URL:", signedSrc); + + // Return the BasicExample component with the signed URL as a prop + return ; + } catch (error) { + // Log any errors encountered during signing + console.error("Error signing URL:", error); + return

Error loading iframe

; + } +} +``` + + + +```code +// basic-example-embed.tsx +// Utilizes the Sigma Computing Embed SDK to integrate an iframe within a React application. + +"use client"; // Next.js directive to ensure this component runs only on the client-side. + +import React from "react"; +// Import the useSigmaIframe hook from the Sigma Computing React Embed SDK +import { useSigmaIframe } from "@sigmacomputing/react-embed-sdk"; + +// Define the BasicExample component, which receives a 'src' prop for the iframe URL +export default function BasicExample({ src }: { src: string }) { + // Destructure the iframeRef, loading, and error values from the useSigmaIframe hook + const { iframeRef, loading, error } = useSigmaIframe(); + + return ( + // Parent container with full height +
+ {/* Conditional rendering: Display loading text if the iframe is loading */} + {loading &&

Loading...

} + {/* Conditional rendering: Display error message if there is an error loading the iframe */} + {error &&

Error loading iframe

} + {/* Render the iframe, filling the parent container */} +