@omni-co/embed 0.2.1 → 0.3.0-pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,28 +1,89 @@
1
- # omni-embed-sdk
1
+ # Omni Embed SSO Typescript SDK
2
2
 
3
- ## ⚠️ OmniEmbedSDK uses NPM! ⚠️
3
+ ## Install
4
4
 
5
- Publishing to npmjs.org was complicated with Yarn. Until that issue is resolved, please use NPM to manage this package.
5
+ npm:
6
+ ```
7
+ npm install @omni-co/embed
8
+ ```
6
9
 
7
- ## Installation
10
+ yarn:
11
+ ```
12
+ yarn add @omni-co/embed
13
+ ```
8
14
 
9
- 1. git clone the repository
10
- 2. `npm install`
11
- 3. `npm run test`
15
+ ## Basic Example
12
16
 
13
- ## Publishing
17
+ ```ts
18
+ import { embedSsoDashboard } from '@omni-co/embed'
14
19
 
15
- 1. Create a new branch
16
- 2. Edit the package.json version number appropriately
17
- 3. Open a PR
18
- 4. Merge the PR
19
- 5. Nav to the Releases page in Github: https://github.com/exploreomni/embed-sdk/releases
20
- 6. Click "Draft new Release"
21
- 7. Click "Choose a tag" and type in the new tag name. Convention is to prefix the new version with `v`. Example: `v1.0.0`
22
- 8. Leave target as `main`
23
- 9. Enter a title, usually just the release version eg `v1.0.0`
24
- 10. Add a description
25
- 11. Ensure `Set as latest release` is ticked, if that's appropriate
26
- 12. Click `Publish release`
20
+ // This creates a signed embed sso link for a dashboard
21
+ // in the omni account named Acme.
22
+ const iframeUrl = embedSsoDashboard({
23
+ contentId: "miU0hL6z",
24
+ externalId: "wile.e@coyote.co",
25
+ name: "Wile E",
26
+ organizationName: "acme",
27
+ secret: "abcdefghijklmnopqrstuvwxyz123456",
28
+ });
29
+ ```
27
30
 
28
- 🥳 - The [github action defined here](https://github.com/exploreomni/embed-sdk/blob/main/.github/workflows/publish.yml) should publish the new release to npmjs.org.
31
+ ## Kitchen Sink Example
32
+
33
+ ```ts
34
+ import { embedSsoDashboard } from '@omni-co/embed'
35
+
36
+ // This creates a signed embed sso link for a dashboard
37
+ // in the omni account named Acme.
38
+ const iframeUrl = embedSsoDashboard({
39
+ contentId: "miU0hL6z",
40
+ externalId: "wile.e@coyote.co",
41
+ entity: "cartoon",
42
+ name: "Wile E",
43
+ organizationName: "acme",
44
+ secret: "abcdefghijklmnopqrstuvwxyz123456",
45
+ prefersDark: "system",
46
+ theme: "vibes",
47
+ userAttributes: { tool: "anvil" }
48
+ });
49
+ ```
50
+
51
+ ## embedSsoDashboard
52
+
53
+ This is the type signature for the embedSsoDashboard function:
54
+
55
+ ```ts
56
+ type EmbedSsoDashboardProps = {
57
+ // Short GUID of the dashboard. Can be obtained via the dashboard's url.
58
+ contentId: string;
59
+
60
+ // Required identifier to associate the external user with an
61
+ // automatically generated internal Omni user.
62
+ externalId: string;
63
+
64
+ // Required name of the external user.
65
+ name: string;
66
+
67
+ // Required Omni organization which contains the dashboard.
68
+ organizationName: string;
69
+
70
+ // Signing secret available to Omni admins.
71
+ secret: string;
72
+
73
+ // Optional identifier to associate the user with an external
74
+ // organization or system.
75
+ entity?: string;
76
+
77
+ // Optional user attributes to be passed to user associated with the
78
+ // externalId. User attributes must be created in Omni before being
79
+ // defined and given a value here.
80
+ userAttributes?: Record<string, string>;
81
+
82
+ // Optional dark mode setting. Can be one of "true", "false", or "system".
83
+ prefersDark?: string;
84
+
85
+ // Optional theme setting. Can be one of "dawn", "vibes", "breeze" or "blank".
86
+ theme?: string;
87
+ };
88
+
89
+ ```
@@ -1,5 +1,5 @@
1
- import { random32ByteString } from "./random-str";
2
- import { getSignature } from "./signature";
1
+ import { random32ByteString } from "./random-str.js";
2
+ import { getSignature } from "./signature.js";
3
3
  const defaultEmbedDomain = "embed-omniapp.co";
4
4
  const embedLoginRoute = "/embed/login";
5
5
  const embedDashboardPath = "/embed/dashboards";
@@ -33,8 +33,8 @@ export const embedSsoDashboard = (props) => {
33
33
  validateProps(props);
34
34
  let { contentId, domain, externalId, name, nonce, organizationName, port, secret, userAttributes: rawUserAttributes, entity, prefersDark, theme, } = props;
35
35
  // Handle defaults
36
- nonce = nonce ?? random32ByteString();
37
- domain = domain ?? defaultEmbedDomain;
36
+ nonce = nonce !== null && nonce !== void 0 ? nonce : random32ByteString();
37
+ domain = domain !== null && domain !== void 0 ? domain : defaultEmbedDomain;
38
38
  const userAttributes = rawUserAttributes && JSON.stringify(rawUserAttributes);
39
39
  // Generate the url for the embed login route
40
40
  const url = new URL(embedLoginRoute, `https://${organizationName.toLocaleLowerCase()}.${domain}${port ? `:${port}` : ""}`);
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./embed.js";
2
+ export * from "./signature.js";
package/lib/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./embed.js";
2
+ export * from "./signature.js";
@@ -1,3 +1,14 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import crypto from "crypto";
2
13
  export const hmacSign = (data, secret) => {
3
14
  const hmac = crypto.createHmac("sha256", secret);
@@ -21,7 +32,8 @@ const generateStringForSignature = ({ loginUrl, contentPath, externalId, name, n
21
32
  .trim()
22
33
  .replace(/\n\s+/g, "\n");
23
34
  };
24
- export const getSignature = ({ secret, ...props }) => {
35
+ export const getSignature = (_a) => {
36
+ var { secret } = _a, props = __rest(_a, ["secret"]);
25
37
  return hmacSign(generateStringForSignature(props), secret);
26
38
  };
27
39
  export const TEST_ONLY = {
package/package.json CHANGED
@@ -1,10 +1,8 @@
1
1
  {
2
- "version": "0.2.1",
2
+ "version": "0.3.0-pre.1",
3
3
  "license": "MIT",
4
4
  "name": "@omni-co/embed",
5
5
  "author": "Nate Agrin <nate@exploreomni.com>",
6
- "main": "lib/cjs/index.js",
7
- "module": "lib/esm/index.js",
8
6
  "files": [
9
7
  "lib/**/*"
10
8
  ],
@@ -14,7 +12,7 @@
14
12
  "vitest": "^0.34.6"
15
13
  },
16
14
  "scripts": {
17
- "build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json",
15
+ "build": "npm run clean && tsc -p tsconfig.json",
18
16
  "clean": "rm -rf lib",
19
17
  "prepublishOnly": "npm run build",
20
18
  "test": "vitest",
@@ -22,5 +20,8 @@
22
20
  },
23
21
  "dependencies": {
24
22
  "nanoid": "^5.0.2"
25
- }
23
+ },
24
+ "exports": "./lib/index.js",
25
+ "types": "./lib/index.d.ts",
26
+ "type": "module"
26
27
  }
package/lib/cjs/embed.js DELETED
@@ -1,71 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.embedSsoDashboard = void 0;
4
- const random_str_1 = require("./random-str");
5
- const signature_1 = require("./signature");
6
- const defaultEmbedDomain = "embed-omniapp.co";
7
- const embedLoginRoute = "/embed/login";
8
- const embedDashboardPath = "/embed/dashboards";
9
- const validateProps = (props) => {
10
- const { contentId, externalId, name, nonce, organizationName, secret, userAttributes, } = props;
11
- if (!contentId) {
12
- throw new Error("contentId is required");
13
- }
14
- if (!externalId) {
15
- throw new Error("externalId is required");
16
- }
17
- if (!name) {
18
- throw new Error("name is required");
19
- }
20
- if (!organizationName) {
21
- throw new Error("organizationName is required");
22
- }
23
- if (!secret) {
24
- throw new Error("secret is required");
25
- }
26
- if (nonce && nonce.length !== 32) {
27
- throw new Error("nonce must be 32 characters");
28
- }
29
- if (typeof userAttributes !== "object") {
30
- if (userAttributes) {
31
- throw new Error("userAttributes must be an object");
32
- }
33
- }
34
- };
35
- const embedSsoDashboard = (props) => {
36
- validateProps(props);
37
- let { contentId, domain, externalId, name, nonce, organizationName, port, secret, userAttributes: rawUserAttributes, entity, prefersDark, theme, } = props;
38
- // Handle defaults
39
- nonce = nonce ?? (0, random_str_1.random32ByteString)();
40
- domain = domain ?? defaultEmbedDomain;
41
- const userAttributes = rawUserAttributes && JSON.stringify(rawUserAttributes);
42
- // Generate the url for the embed login route
43
- const url = new URL(embedLoginRoute, `https://${organizationName.toLocaleLowerCase()}.${domain}${port ? `:${port}` : ""}`);
44
- // Generate the content path
45
- const contentPath = `${embedDashboardPath}/${contentId}`;
46
- // Get a signature for the request
47
- const signature = (0, signature_1.getSignature)({
48
- loginUrl: url.toString(),
49
- contentPath,
50
- externalId,
51
- name,
52
- nonce,
53
- secret,
54
- userAttributes,
55
- entity,
56
- prefersDark,
57
- theme,
58
- });
59
- // Build and return the signed url
60
- url.searchParams.append("contentPath", contentPath);
61
- url.searchParams.append("externalId", externalId);
62
- url.searchParams.append("name", name);
63
- url.searchParams.append("nonce", nonce);
64
- url.searchParams.append("signature", signature);
65
- userAttributes && url.searchParams.append("userAttributes", userAttributes);
66
- entity && url.searchParams.append("entity", entity);
67
- prefersDark && url.searchParams.append("prefersDark", prefersDark);
68
- theme && url.searchParams.append("theme", theme);
69
- return url.toString();
70
- };
71
- exports.embedSsoDashboard = embedSsoDashboard;
@@ -1,2 +0,0 @@
1
- export * from "./embed";
2
- export * from "./signature";
package/lib/cjs/index.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./embed"), exports);
18
- __exportStar(require("./signature"), exports);
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.random32ByteString = void 0;
4
- const nanoid_1 = require("nanoid");
5
- const humanReadableByteSpace = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
6
- // Generates a random 32 byte, human readable string.
7
- // Based on math at https://zelark.github.io/nano-id-cc/
8
- // at 1000 Ids/s it would take more than 1 quadrillion years or
9
- // 8,730,800,738,924,245T IDs, in order to have a 1% probability
10
- // of at least one collision.
11
- exports.random32ByteString = (0, nanoid_1.customAlphabet)(humanReadableByteSpace, 32);
@@ -1,37 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TEST_ONLY = exports.getSignature = exports.hmacSign = void 0;
7
- const crypto_1 = __importDefault(require("crypto"));
8
- const hmacSign = (data, secret) => {
9
- const hmac = crypto_1.default.createHmac("sha256", secret);
10
- hmac.update(data);
11
- return hmac.digest("base64url");
12
- };
13
- exports.hmacSign = hmacSign;
14
- const generateStringForSignature = ({ loginUrl, contentPath, externalId, name, nonce, userAttributes, entity, prefersDark, theme, }) => {
15
- const optionalParams = [];
16
- entity && optionalParams.push(entity);
17
- prefersDark && optionalParams.push(prefersDark);
18
- theme && optionalParams.push(theme);
19
- userAttributes && optionalParams.push(userAttributes);
20
- return `
21
- ${loginUrl}
22
- ${contentPath}
23
- ${externalId}
24
- ${name}
25
- ${nonce}
26
- ${optionalParams.join("\n")}
27
- `
28
- .trim()
29
- .replace(/\n\s+/g, "\n");
30
- };
31
- const getSignature = ({ secret, ...props }) => {
32
- return (0, exports.hmacSign)(generateStringForSignature(props), secret);
33
- };
34
- exports.getSignature = getSignature;
35
- exports.TEST_ONLY = {
36
- generateStringForSignature,
37
- };
@@ -1,16 +0,0 @@
1
- type EmbedSsoProps = {
2
- contentId: string;
3
- domain?: string;
4
- externalId: string;
5
- name: string;
6
- nonce?: string;
7
- organizationName: string;
8
- port?: number;
9
- secret: string;
10
- userAttributes?: Record<string, string>;
11
- entity?: string;
12
- prefersDark?: string;
13
- theme?: string;
14
- };
15
- export declare const embedSsoDashboard: (props: EmbedSsoProps) => string;
16
- export {};
@@ -1,2 +0,0 @@
1
- export * from "./embed";
2
- export * from "./signature";
package/lib/esm/index.js DELETED
@@ -1,2 +0,0 @@
1
- export * from "./embed";
2
- export * from "./signature";
@@ -1 +0,0 @@
1
- export declare const random32ByteString: (size?: number | undefined) => string;
@@ -1,55 +0,0 @@
1
- export declare const hmacSign: (data: string, secret: string) => string;
2
- type SignatureProps = {
3
- /**
4
- * The protocol, domain, optional port and /embed/login route of the request.
5
- *
6
- * Example: `https://example.embed-omniapp.com/embed/login`
7
- */
8
- loginUrl: string;
9
- /**
10
- * The path to the content being embedded.
11
- *
12
- * Example: /embed/dashboards/123abc
13
- */
14
- contentPath: string;
15
- /**
16
- * The external id of the user.
17
- */
18
- externalId: string;
19
- /**
20
- * The name of the user.
21
- */
22
- name: string;
23
- /**
24
- * The nonce of the request.
25
- */
26
- nonce: string;
27
- /**
28
- * The secret used to sign the request
29
- */
30
- secret: string;
31
- /**
32
- * The user attributes to be sent with the request. Expected to be a stringified JSON object.
33
- *
34
- * Example: '{ "team": "Lakers" }'
35
- */
36
- userAttributes?: string;
37
- /**
38
- * The entity that the created embed user will belong to. Practically speaking, the embed
39
- * user will this value assigned to its omni_user_embed_entity user attribute.
40
- */
41
- entity?: string;
42
- /**
43
- * Whether the user prefers light, dark, or system theme.
44
- */
45
- prefersDark?: string;
46
- /**
47
- * The theme of the embed.
48
- */
49
- theme?: string;
50
- };
51
- export declare const getSignature: ({ secret, ...props }: SignatureProps) => string;
52
- export declare const TEST_ONLY: {
53
- generateStringForSignature: ({ loginUrl, contentPath, externalId, name, nonce, userAttributes, entity, prefersDark, theme, }: Omit<SignatureProps, "secret">) => string;
54
- };
55
- export {};
@@ -1,16 +1,16 @@
1
1
  type EmbedSsoProps = {
2
2
  contentId: string;
3
- domain?: string;
4
3
  externalId: string;
5
4
  name: string;
6
- nonce?: string;
7
5
  organizationName: string;
8
- port?: number;
9
6
  secret: string;
10
- userAttributes?: Record<string, string>;
11
7
  entity?: string;
8
+ userAttributes?: Record<string, string>;
12
9
  prefersDark?: string;
13
10
  theme?: string;
11
+ domain?: string;
12
+ nonce?: string;
13
+ port?: number;
14
14
  };
15
15
  export declare const embedSsoDashboard: (props: EmbedSsoProps) => string;
16
16
  export {};
File without changes
File without changes
File without changes