@omni-co/embed 0.1.4 → 0.2.0

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 +1,28 @@
1
1
  # omni-embed-sdk
2
+
3
+ ## ⚠️ OmniEmbedSDK uses NPM! ⚠️
4
+
5
+ Publishing to npmjs.org was complicated with Yarn. Until that issue is resolved, please use NPM to manage this package.
6
+
7
+ ## Installation
8
+
9
+ 1. git clone the repository
10
+ 2. `npm install`
11
+ 3. `npm run test`
12
+
13
+ ## Publishing
14
+
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`
27
+
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.
@@ -8,6 +8,7 @@ type EmbedSsoProps = {
8
8
  port?: number;
9
9
  secret: string;
10
10
  userAttributes?: Record<string, string>;
11
+ entity?: string;
11
12
  };
12
13
  export declare const embedSsoDashboard: (props: EmbedSsoProps) => string;
13
14
  export {};
package/lib/cjs/embed.js CHANGED
@@ -34,7 +34,7 @@ const validateProps = (props) => {
34
34
  };
35
35
  const embedSsoDashboard = (props) => {
36
36
  validateProps(props);
37
- let { contentId, domain, externalId, name, nonce, organizationName, port, secret, userAttributes: rawUserAttributes, } = props;
37
+ let { contentId, domain, externalId, name, nonce, organizationName, port, secret, userAttributes: rawUserAttributes, entity, } = props;
38
38
  // Handle defaults
39
39
  nonce = nonce ?? (0, random_str_1.random32ByteString)();
40
40
  domain = domain ?? defaultEmbedDomain;
@@ -52,6 +52,7 @@ const embedSsoDashboard = (props) => {
52
52
  nonce,
53
53
  secret,
54
54
  userAttributes,
55
+ entity,
55
56
  });
56
57
  // Build and return the signed url
57
58
  url.searchParams.append("contentPath", contentPath);
@@ -60,6 +61,7 @@ const embedSsoDashboard = (props) => {
60
61
  url.searchParams.append("nonce", nonce);
61
62
  url.searchParams.append("signature", signature);
62
63
  userAttributes && url.searchParams.append("userAttributes", userAttributes);
64
+ entity && url.searchParams.append("entity", entity);
63
65
  return url.toString();
64
66
  };
65
67
  exports.embedSsoDashboard = embedSsoDashboard;
@@ -34,6 +34,14 @@ type SignatureProps = {
34
34
  * Example: '{ "team": "Lakers" }'
35
35
  */
36
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
+ export declare const getSignature: ({ secret, ...props }: SignatureProps) => string;
44
+ export declare const TEST_ONLY: {
45
+ generateStringForSignature: ({ loginUrl, contentPath, externalId, name, nonce, userAttributes, entity, }: Omit<SignatureProps, "secret">) => string;
37
46
  };
38
- export declare const getSignature: ({ loginUrl, contentPath, externalId, name, nonce, secret, userAttributes, }: SignatureProps) => string;
39
47
  export {};
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getSignature = exports.hmacSign = void 0;
6
+ exports.TEST_ONLY = exports.getSignature = exports.hmacSign = void 0;
7
7
  const crypto_1 = __importDefault(require("crypto"));
8
8
  const hmacSign = (data, secret) => {
9
9
  const hmac = crypto_1.default.createHmac("sha256", secret);
@@ -11,17 +11,25 @@ const hmacSign = (data, secret) => {
11
11
  return hmac.digest("base64url");
12
12
  };
13
13
  exports.hmacSign = hmacSign;
14
- const getSignature = ({ loginUrl, contentPath, externalId, name, nonce, secret, userAttributes, }) => {
15
- const validationStr = `
16
- ${loginUrl}
17
- ${contentPath}
18
- ${externalId}
19
- ${name}
20
- ${nonce}
21
- ${userAttributes}
22
- `
14
+ const generateStringForSignature = ({ loginUrl, contentPath, externalId, name, nonce, userAttributes, entity, }) => {
15
+ const optionalParams = [];
16
+ entity && optionalParams.push(entity);
17
+ userAttributes && optionalParams.push(userAttributes);
18
+ return `
19
+ ${loginUrl}
20
+ ${contentPath}
21
+ ${externalId}
22
+ ${name}
23
+ ${nonce}
24
+ ${optionalParams.join("\n")}
25
+ `
23
26
  .trim()
24
27
  .replace(/\n\s+/g, "\n");
25
- return (0, exports.hmacSign)(validationStr, secret);
28
+ };
29
+ const getSignature = ({ secret, ...props }) => {
30
+ return (0, exports.hmacSign)(generateStringForSignature(props), secret);
26
31
  };
27
32
  exports.getSignature = getSignature;
33
+ exports.TEST_ONLY = {
34
+ generateStringForSignature,
35
+ };
@@ -8,6 +8,7 @@ type EmbedSsoProps = {
8
8
  port?: number;
9
9
  secret: string;
10
10
  userAttributes?: Record<string, string>;
11
+ entity?: string;
11
12
  };
12
13
  export declare const embedSsoDashboard: (props: EmbedSsoProps) => string;
13
14
  export {};
package/lib/esm/embed.js CHANGED
@@ -31,7 +31,7 @@ const validateProps = (props) => {
31
31
  };
32
32
  export const embedSsoDashboard = (props) => {
33
33
  validateProps(props);
34
- let { contentId, domain, externalId, name, nonce, organizationName, port, secret, userAttributes: rawUserAttributes, } = props;
34
+ let { contentId, domain, externalId, name, nonce, organizationName, port, secret, userAttributes: rawUserAttributes, entity, } = props;
35
35
  // Handle defaults
36
36
  nonce = nonce ?? random32ByteString();
37
37
  domain = domain ?? defaultEmbedDomain;
@@ -49,6 +49,7 @@ export const embedSsoDashboard = (props) => {
49
49
  nonce,
50
50
  secret,
51
51
  userAttributes,
52
+ entity,
52
53
  });
53
54
  // Build and return the signed url
54
55
  url.searchParams.append("contentPath", contentPath);
@@ -57,5 +58,6 @@ export const embedSsoDashboard = (props) => {
57
58
  url.searchParams.append("nonce", nonce);
58
59
  url.searchParams.append("signature", signature);
59
60
  userAttributes && url.searchParams.append("userAttributes", userAttributes);
61
+ entity && url.searchParams.append("entity", entity);
60
62
  return url.toString();
61
63
  };
@@ -34,6 +34,14 @@ type SignatureProps = {
34
34
  * Example: '{ "team": "Lakers" }'
35
35
  */
36
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
+ export declare const getSignature: ({ secret, ...props }: SignatureProps) => string;
44
+ export declare const TEST_ONLY: {
45
+ generateStringForSignature: ({ loginUrl, contentPath, externalId, name, nonce, userAttributes, entity, }: Omit<SignatureProps, "secret">) => string;
37
46
  };
38
- export declare const getSignature: ({ loginUrl, contentPath, externalId, name, nonce, secret, userAttributes, }: SignatureProps) => string;
39
47
  export {};
@@ -4,16 +4,24 @@ export const hmacSign = (data, secret) => {
4
4
  hmac.update(data);
5
5
  return hmac.digest("base64url");
6
6
  };
7
- export const getSignature = ({ loginUrl, contentPath, externalId, name, nonce, secret, userAttributes, }) => {
8
- const validationStr = `
9
- ${loginUrl}
10
- ${contentPath}
11
- ${externalId}
12
- ${name}
13
- ${nonce}
14
- ${userAttributes}
15
- `
7
+ const generateStringForSignature = ({ loginUrl, contentPath, externalId, name, nonce, userAttributes, entity, }) => {
8
+ const optionalParams = [];
9
+ entity && optionalParams.push(entity);
10
+ userAttributes && optionalParams.push(userAttributes);
11
+ return `
12
+ ${loginUrl}
13
+ ${contentPath}
14
+ ${externalId}
15
+ ${name}
16
+ ${nonce}
17
+ ${optionalParams.join("\n")}
18
+ `
16
19
  .trim()
17
20
  .replace(/\n\s+/g, "\n");
18
- return hmacSign(validationStr, secret);
21
+ };
22
+ export const getSignature = ({ secret, ...props }) => {
23
+ return hmacSign(generateStringForSignature(props), secret);
24
+ };
25
+ export const TEST_ONLY = {
26
+ generateStringForSignature,
19
27
  };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.1.4",
2
+ "version": "0.2.0",
3
3
  "license": "MIT",
4
4
  "name": "@omni-co/embed",
5
5
  "author": "Nate Agrin <nate@exploreomni.com>",
@@ -17,7 +17,8 @@
17
17
  "build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json",
18
18
  "clean": "rm -rf lib",
19
19
  "prepublishOnly": "npm run build",
20
- "test": "vitest"
20
+ "test": "vitest",
21
+ "test:watch": "vitest --watch"
21
22
  },
22
23
  "dependencies": {
23
24
  "nanoid": "^5.0.2"