@omni-co/embed 0.4.11 → 0.5.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.
@@ -2,7 +2,7 @@ import { EmbedSsoContentDiscoveryProps, EmbedSsoDashboardProps, EmbedSsoWorkbook
2
2
  export declare const embedSsoDashboard: (props: EmbedSsoDashboardProps) => Promise<string>;
3
3
  export declare const embedSsoWorkbook: (props: EmbedSsoWorkbookProps) => Promise<string>;
4
4
  /**
5
- * *IN BETA* Generates an embed login URL using the passed-in content discovery page id.
5
+ * Generates an embed login URL using the passed-in content discovery page id.
6
6
  * @param EmbedSsoContentDiscoveryProps
7
7
  * @returns Promise wrapped around a generated embed login url.
8
8
  */
package/lib/cjs/embed.js CHANGED
@@ -86,7 +86,8 @@ const embedSsoContent = async (props) => {
86
86
  url.searchParams.append("nonce", nonce);
87
87
  url.searchParams.append("signature", signature);
88
88
  userAttributes && url.searchParams.append("userAttributes", userAttributes);
89
- accessBoost !== undefined && url.searchParams.append("accessBoost", accessBoost.toString());
89
+ accessBoost !== undefined &&
90
+ url.searchParams.append("accessBoost", accessBoost.toString());
90
91
  entity && url.searchParams.append("entity", entity);
91
92
  prefersDark && url.searchParams.append("prefersDark", prefersDark);
92
93
  theme && url.searchParams.append("theme", theme);
@@ -116,12 +117,14 @@ const embedSsoWorkbook = async (props) => {
116
117
  };
117
118
  exports.embedSsoWorkbook = embedSsoWorkbook;
118
119
  /**
119
- * *IN BETA* Generates an embed login URL using the passed-in content discovery page id.
120
+ * Generates an embed login URL using the passed-in content discovery page id.
120
121
  * @param EmbedSsoContentDiscoveryProps
121
122
  * @returns Promise wrapped around a generated embed login url.
122
123
  */
123
124
  const embedSsoContentDiscovery = async (props) => {
124
- const contentPath = `/${props.path}`;
125
+ // Entity paths for the Content Discovery embed no longer require stripping the leading `/`.
126
+ // This check maintains backwards compatibility with the old behavior.
127
+ const contentPath = props.path.startsWith('/') ? props.path : `/${props.path}`;
125
128
  return embedSsoContent({
126
129
  ...props,
127
130
  contentPath,
@@ -89,7 +89,35 @@ type SignatureProps = {
89
89
  */
90
90
  userAttributes?: string;
91
91
  };
92
+ /**
93
+ * Creates a signature value for the /embed/login endpoint.
94
+ */
92
95
  export declare const getSignature: ({ secret, ...props }: SignatureProps) => string;
96
+ type RequestUrl = {
97
+ requestUrl: string;
98
+ };
99
+ type GenerateSessionSignatureProps = Omit<SignatureProps, "loginUrl" | "prefersDark" | "theme"> & RequestUrl;
100
+ /**
101
+ * Creates a signature value for the /embed/sso/generate-session endpoint.
102
+ *
103
+ * For context, the /embed/sso/generate-session endpoint is step 1 of the
104
+ * embed 2-step login flow. All requests to this endpoint require a signature
105
+ * that is generated based on all other request parameters. That signature is
106
+ * validated by the Omni app server to ensure the request is authentic.
107
+ */
108
+ export declare const signSessionRequest: ({ requestUrl, secret, ...props }: GenerateSessionSignatureProps) => string;
109
+ type UseSessionSignatureProps = Pick<SignatureProps, "nonce" | "prefersDark" | "theme" | "secret"> & RequestUrl & {
110
+ sessionId: string;
111
+ };
112
+ /**
113
+ * Creates a signature value for the /embed/sso/redeem-session endpoint.
114
+ *
115
+ * For context, the /embed/sso/redeem-session endpoint is step 2 of the
116
+ * embed 2-step login flow. All requests to this endpoint require a signature
117
+ * that is generated based on all other request parameters. That signature is
118
+ * validated by the Omni app server to ensure the request is authentic.
119
+ */
120
+ export declare const signSessionRedemption: ({ requestUrl, nonce, sessionId, secret, prefersDark, theme, }: UseSessionSignatureProps) => string;
93
121
  export declare const TEST_ONLY: {
94
122
  generateStringForSignature: ({ loginUrl, contentPath, externalId, name, nonce, accessBoost, connectionRoles, customTheme, customThemeId, email, entity, entityFolderContentRole, filterSearchParam, groups, linkAccess, mode, prefersDark, theme, userAttributes, }: Omit<SignatureProps, "secret">) => string;
95
123
  };
@@ -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.TEST_ONLY = exports.getSignature = exports.hmacSign = void 0;
6
+ exports.TEST_ONLY = exports.signSessionRedemption = exports.signSessionRequest = exports.getSignature = exports.hmacSign = void 0;
7
7
  const crypto_1 = __importDefault(require("crypto"));
8
8
  const base64url_1 = __importDefault(require("base64url"));
9
9
  const hmacSign = (data, secret) => {
@@ -52,10 +52,54 @@ accessBoost, connectionRoles, customTheme, customThemeId, email, entity, entityF
52
52
  .trim()
53
53
  .replace(/\n\s+/g, "\n");
54
54
  };
55
+ /**
56
+ * Creates a signature value for the /embed/login endpoint.
57
+ */
55
58
  const getSignature = ({ secret, ...props }) => {
56
59
  return (0, exports.hmacSign)(generateStringForSignature(props), secret);
57
60
  };
58
61
  exports.getSignature = getSignature;
62
+ /**
63
+ * Creates a signature value for the /embed/sso/generate-session endpoint.
64
+ *
65
+ * For context, the /embed/sso/generate-session endpoint is step 1 of the
66
+ * embed 2-step login flow. All requests to this endpoint require a signature
67
+ * that is generated based on all other request parameters. That signature is
68
+ * validated by the Omni app server to ensure the request is authentic.
69
+ */
70
+ const signSessionRequest = ({ requestUrl, secret, ...props }) => {
71
+ return (0, exports.getSignature)({ secret, loginUrl: requestUrl, ...props });
72
+ };
73
+ exports.signSessionRequest = signSessionRequest;
74
+ /**
75
+ * Creates a signature value for the /embed/sso/redeem-session endpoint.
76
+ *
77
+ * For context, the /embed/sso/redeem-session endpoint is step 2 of the
78
+ * embed 2-step login flow. All requests to this endpoint require a signature
79
+ * that is generated based on all other request parameters. That signature is
80
+ * validated by the Omni app server to ensure the request is authentic.
81
+ */
82
+ const signSessionRedemption = ({ requestUrl, nonce, sessionId, secret, prefersDark, theme, }) => {
83
+ const optionalParamsMap = {
84
+ ...(prefersDark && { prefersDark }),
85
+ ...(theme && { theme }),
86
+ };
87
+ const optionalParams = Object.keys(optionalParamsMap)
88
+ .sort() // guarantees the order of the optional params is Alphabetical
89
+ .map((key) => {
90
+ return optionalParamsMap[key];
91
+ });
92
+ const signatureString = `
93
+ ${requestUrl}
94
+ ${nonce}
95
+ ${sessionId}
96
+ ${optionalParams.join("\n")}
97
+ `
98
+ .trim()
99
+ .replace(/\n\s+/g, "\n");
100
+ return (0, exports.hmacSign)(signatureString, secret);
101
+ };
102
+ exports.signSessionRedemption = signSessionRedemption;
59
103
  exports.TEST_ONLY = {
60
104
  generateStringForSignature,
61
105
  };
@@ -188,8 +188,6 @@ export declare enum EmbeddedContent {
188
188
  Dashboard = "dashboards",
189
189
  Workbook = "w"
190
190
  }
191
- export declare const EmbedSsoContentDiscoveryPaths: readonly ["my", "entity-folder", "root"];
192
- export type EmbedSsoContentDiscoveryPath = (typeof EmbedSsoContentDiscoveryPaths)[number];
193
191
  export declare enum EmbedConnectionRoles {
194
192
  RESTRICTED_QUERIER = "RESTRICTED_QUERIER",
195
193
  VIEWER = "VIEWER",
@@ -218,6 +216,6 @@ export type EmbedSsoContentDiscoveryProps = EmbedSsoBaseProps & {
218
216
  /**
219
217
  * Path name of the content discovery page to embed.
220
218
  */
221
- path: EmbedSsoContentDiscoveryPath;
219
+ path: string;
222
220
  };
223
221
  export {};
package/lib/cjs/types.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EmbedEntityFolderContentRoles = exports.EmbedConnectionRoles = exports.EmbedSsoContentDiscoveryPaths = exports.EmbeddedContent = exports.CustomThemeProperty = exports.EmbedSessionMode = void 0;
3
+ exports.EmbedEntityFolderContentRoles = exports.EmbedConnectionRoles = exports.EmbeddedContent = exports.CustomThemeProperty = exports.EmbedSessionMode = void 0;
4
4
  var EmbedSessionMode;
5
5
  (function (EmbedSessionMode) {
6
6
  EmbedSessionMode["Application"] = "APPLICATION";
@@ -68,11 +68,6 @@ var EmbeddedContent;
68
68
  EmbeddedContent["Dashboard"] = "dashboards";
69
69
  EmbeddedContent["Workbook"] = "w";
70
70
  })(EmbeddedContent || (exports.EmbeddedContent = EmbeddedContent = {}));
71
- exports.EmbedSsoContentDiscoveryPaths = [
72
- "my",
73
- "entity-folder",
74
- "root",
75
- ];
76
71
  var EmbedConnectionRoles;
77
72
  (function (EmbedConnectionRoles) {
78
73
  EmbedConnectionRoles["RESTRICTED_QUERIER"] = "RESTRICTED_QUERIER";
@@ -2,7 +2,7 @@ import { EmbedSsoContentDiscoveryProps, EmbedSsoDashboardProps, EmbedSsoWorkbook
2
2
  export declare const embedSsoDashboard: (props: EmbedSsoDashboardProps) => Promise<string>;
3
3
  export declare const embedSsoWorkbook: (props: EmbedSsoWorkbookProps) => Promise<string>;
4
4
  /**
5
- * *IN BETA* Generates an embed login URL using the passed-in content discovery page id.
5
+ * Generates an embed login URL using the passed-in content discovery page id.
6
6
  * @param EmbedSsoContentDiscoveryProps
7
7
  * @returns Promise wrapped around a generated embed login url.
8
8
  */
package/lib/esm/embed.js CHANGED
@@ -83,7 +83,8 @@ const embedSsoContent = async (props) => {
83
83
  url.searchParams.append("nonce", nonce);
84
84
  url.searchParams.append("signature", signature);
85
85
  userAttributes && url.searchParams.append("userAttributes", userAttributes);
86
- accessBoost !== undefined && url.searchParams.append("accessBoost", accessBoost.toString());
86
+ accessBoost !== undefined &&
87
+ url.searchParams.append("accessBoost", accessBoost.toString());
87
88
  entity && url.searchParams.append("entity", entity);
88
89
  prefersDark && url.searchParams.append("prefersDark", prefersDark);
89
90
  theme && url.searchParams.append("theme", theme);
@@ -111,12 +112,14 @@ export const embedSsoWorkbook = async (props) => {
111
112
  return embedSsoContent({ ...props, contentPath });
112
113
  };
113
114
  /**
114
- * *IN BETA* Generates an embed login URL using the passed-in content discovery page id.
115
+ * Generates an embed login URL using the passed-in content discovery page id.
115
116
  * @param EmbedSsoContentDiscoveryProps
116
117
  * @returns Promise wrapped around a generated embed login url.
117
118
  */
118
119
  export const embedSsoContentDiscovery = async (props) => {
119
- const contentPath = `/${props.path}`;
120
+ // Entity paths for the Content Discovery embed no longer require stripping the leading `/`.
121
+ // This check maintains backwards compatibility with the old behavior.
122
+ const contentPath = props.path.startsWith('/') ? props.path : `/${props.path}`;
120
123
  return embedSsoContent({
121
124
  ...props,
122
125
  contentPath,
@@ -89,7 +89,35 @@ type SignatureProps = {
89
89
  */
90
90
  userAttributes?: string;
91
91
  };
92
+ /**
93
+ * Creates a signature value for the /embed/login endpoint.
94
+ */
92
95
  export declare const getSignature: ({ secret, ...props }: SignatureProps) => string;
96
+ type RequestUrl = {
97
+ requestUrl: string;
98
+ };
99
+ type GenerateSessionSignatureProps = Omit<SignatureProps, "loginUrl" | "prefersDark" | "theme"> & RequestUrl;
100
+ /**
101
+ * Creates a signature value for the /embed/sso/generate-session endpoint.
102
+ *
103
+ * For context, the /embed/sso/generate-session endpoint is step 1 of the
104
+ * embed 2-step login flow. All requests to this endpoint require a signature
105
+ * that is generated based on all other request parameters. That signature is
106
+ * validated by the Omni app server to ensure the request is authentic.
107
+ */
108
+ export declare const signSessionRequest: ({ requestUrl, secret, ...props }: GenerateSessionSignatureProps) => string;
109
+ type UseSessionSignatureProps = Pick<SignatureProps, "nonce" | "prefersDark" | "theme" | "secret"> & RequestUrl & {
110
+ sessionId: string;
111
+ };
112
+ /**
113
+ * Creates a signature value for the /embed/sso/redeem-session endpoint.
114
+ *
115
+ * For context, the /embed/sso/redeem-session endpoint is step 2 of the
116
+ * embed 2-step login flow. All requests to this endpoint require a signature
117
+ * that is generated based on all other request parameters. That signature is
118
+ * validated by the Omni app server to ensure the request is authentic.
119
+ */
120
+ export declare const signSessionRedemption: ({ requestUrl, nonce, sessionId, secret, prefersDark, theme, }: UseSessionSignatureProps) => string;
93
121
  export declare const TEST_ONLY: {
94
122
  generateStringForSignature: ({ loginUrl, contentPath, externalId, name, nonce, accessBoost, connectionRoles, customTheme, customThemeId, email, entity, entityFolderContentRole, filterSearchParam, groups, linkAccess, mode, prefersDark, theme, userAttributes, }: Omit<SignatureProps, "secret">) => string;
95
123
  };
@@ -45,9 +45,51 @@ accessBoost, connectionRoles, customTheme, customThemeId, email, entity, entityF
45
45
  .trim()
46
46
  .replace(/\n\s+/g, "\n");
47
47
  };
48
+ /**
49
+ * Creates a signature value for the /embed/login endpoint.
50
+ */
48
51
  export const getSignature = ({ secret, ...props }) => {
49
52
  return hmacSign(generateStringForSignature(props), secret);
50
53
  };
54
+ /**
55
+ * Creates a signature value for the /embed/sso/generate-session endpoint.
56
+ *
57
+ * For context, the /embed/sso/generate-session endpoint is step 1 of the
58
+ * embed 2-step login flow. All requests to this endpoint require a signature
59
+ * that is generated based on all other request parameters. That signature is
60
+ * validated by the Omni app server to ensure the request is authentic.
61
+ */
62
+ export const signSessionRequest = ({ requestUrl, secret, ...props }) => {
63
+ return getSignature({ secret, loginUrl: requestUrl, ...props });
64
+ };
65
+ /**
66
+ * Creates a signature value for the /embed/sso/redeem-session endpoint.
67
+ *
68
+ * For context, the /embed/sso/redeem-session endpoint is step 2 of the
69
+ * embed 2-step login flow. All requests to this endpoint require a signature
70
+ * that is generated based on all other request parameters. That signature is
71
+ * validated by the Omni app server to ensure the request is authentic.
72
+ */
73
+ export const signSessionRedemption = ({ requestUrl, nonce, sessionId, secret, prefersDark, theme, }) => {
74
+ const optionalParamsMap = {
75
+ ...(prefersDark && { prefersDark }),
76
+ ...(theme && { theme }),
77
+ };
78
+ const optionalParams = Object.keys(optionalParamsMap)
79
+ .sort() // guarantees the order of the optional params is Alphabetical
80
+ .map((key) => {
81
+ return optionalParamsMap[key];
82
+ });
83
+ const signatureString = `
84
+ ${requestUrl}
85
+ ${nonce}
86
+ ${sessionId}
87
+ ${optionalParams.join("\n")}
88
+ `
89
+ .trim()
90
+ .replace(/\n\s+/g, "\n");
91
+ return hmacSign(signatureString, secret);
92
+ };
51
93
  export const TEST_ONLY = {
52
94
  generateStringForSignature,
53
95
  };
@@ -188,8 +188,6 @@ export declare enum EmbeddedContent {
188
188
  Dashboard = "dashboards",
189
189
  Workbook = "w"
190
190
  }
191
- export declare const EmbedSsoContentDiscoveryPaths: readonly ["my", "entity-folder", "root"];
192
- export type EmbedSsoContentDiscoveryPath = (typeof EmbedSsoContentDiscoveryPaths)[number];
193
191
  export declare enum EmbedConnectionRoles {
194
192
  RESTRICTED_QUERIER = "RESTRICTED_QUERIER",
195
193
  VIEWER = "VIEWER",
@@ -218,6 +216,6 @@ export type EmbedSsoContentDiscoveryProps = EmbedSsoBaseProps & {
218
216
  /**
219
217
  * Path name of the content discovery page to embed.
220
218
  */
221
- path: EmbedSsoContentDiscoveryPath;
219
+ path: string;
222
220
  };
223
221
  export {};
package/lib/esm/types.js CHANGED
@@ -65,11 +65,6 @@ export var EmbeddedContent;
65
65
  EmbeddedContent["Dashboard"] = "dashboards";
66
66
  EmbeddedContent["Workbook"] = "w";
67
67
  })(EmbeddedContent || (EmbeddedContent = {}));
68
- export const EmbedSsoContentDiscoveryPaths = [
69
- "my",
70
- "entity-folder",
71
- "root",
72
- ];
73
68
  export var EmbedConnectionRoles;
74
69
  (function (EmbedConnectionRoles) {
75
70
  EmbedConnectionRoles["RESTRICTED_QUERIER"] = "RESTRICTED_QUERIER";
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.4.11",
2
+ "version": "0.5.0",
3
3
  "license": "MIT",
4
4
  "name": "@omni-co/embed",
5
5
  "author": "Nate Agrin <nate@exploreomni.com>",
@@ -8,6 +8,7 @@
8
8
  ],
9
9
  "devDependencies": {
10
10
  "@types/node": "^20.8.9",
11
+ "semantic-release": "^24.2.1",
11
12
  "typescript": "^5.2.2",
12
13
  "vitest": "^0.34.6"
13
14
  },