@omni-co/embed 0.3.12 → 0.3.14

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.
@@ -1,3 +1,9 @@
1
- import { EmbedSsoDashboardProps, EmbedSsoWorkbookProps } from "./types";
1
+ import { EmbedSsoContentDiscoveryProps, EmbedSsoDashboardProps, EmbedSsoWorkbookProps } from "./types";
2
2
  export declare const embedSsoDashboard: (props: EmbedSsoDashboardProps) => Promise<string>;
3
3
  export declare const embedSsoWorkbook: (props: EmbedSsoWorkbookProps) => Promise<string>;
4
+ /**
5
+ * *IN BETA* Generates an embed login URL using the passed-in content discovery page id.
6
+ * @param EmbedSsoContentDiscoveryProps
7
+ * @returns Promise wrapped around a generated embed login url.
8
+ */
9
+ export declare const embedSsoContentDiscovery: (props: EmbedSsoContentDiscoveryProps) => Promise<string>;
package/lib/cjs/embed.js CHANGED
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.embedSsoWorkbook = exports.embedSsoDashboard = void 0;
3
+ exports.embedSsoContentDiscovery = exports.embedSsoWorkbook = exports.embedSsoDashboard = void 0;
4
4
  const random_str_1 = require("./random-str");
5
5
  const signature_1 = require("./signature");
6
6
  const types_1 = require("./types");
7
7
  const defaultEmbedDomain = "embed-omniapp.co";
8
- const embedLoginPath = '/embed/login';
8
+ const embedLoginPath = "/embed/login";
9
9
  const validateProps = (props) => {
10
- const { externalId, name, nonce, organizationName, secret, userAttributes, } = props;
10
+ const { externalId, name, nonce, organizationName, secret, userAttributes } = props;
11
11
  if (!externalId) {
12
12
  throw new Error("externalId is required");
13
13
  }
@@ -31,12 +31,13 @@ const validateProps = (props) => {
31
31
  };
32
32
  const embedSsoContent = async (props) => {
33
33
  validateProps(props);
34
- let { contentPath, customTheme: rawCustomTheme, domain, externalId, filterSearchParam, linkAccess, name, nonce, organizationName, port, secret, userAttributes: rawUserAttributes, entity, prefersDark, theme, } = props;
34
+ let { connectionRoles: rawConnectionRoles, contentPath, customTheme: rawCustomTheme, domain, externalId, filterSearchParam, linkAccess, name, nonce, organizationName, port, secret, userAttributes: rawUserAttributes, entity, prefersDark, theme, } = props;
35
35
  // Handle defaults
36
36
  nonce = nonce !== null && nonce !== void 0 ? nonce : (await (0, random_str_1.random32ByteString)());
37
37
  domain = domain !== null && domain !== void 0 ? domain : defaultEmbedDomain;
38
38
  const userAttributes = rawUserAttributes && JSON.stringify(rawUserAttributes);
39
39
  const customTheme = rawCustomTheme && JSON.stringify(rawCustomTheme);
40
+ const connectionRoles = rawConnectionRoles && JSON.stringify(rawConnectionRoles);
40
41
  // Generate the url for the embed login route
41
42
  const url = new URL(embedLoginPath, `https://${organizationName.toLocaleLowerCase()}.${domain}${port ? `:${port}` : ""}`);
42
43
  // Get a signature for the request
@@ -54,6 +55,7 @@ const embedSsoContent = async (props) => {
54
55
  filterSearchParam,
55
56
  linkAccess,
56
57
  customTheme,
58
+ connectionRoles,
57
59
  });
58
60
  // Build and return the signed url
59
61
  url.searchParams.append("contentPath", contentPath);
@@ -69,6 +71,8 @@ const embedSsoContent = async (props) => {
69
71
  url.searchParams.append("filterSearchParam", filterSearchParam);
70
72
  linkAccess && url.searchParams.append("linkAccess", linkAccess);
71
73
  customTheme && url.searchParams.append("customTheme", customTheme);
74
+ connectionRoles &&
75
+ url.searchParams.append("connectionRoles", connectionRoles);
72
76
  return url.toString();
73
77
  };
74
78
  const buildContentPath = (contentType, contentId) => `/${contentType}/${contentId}`;
@@ -82,3 +86,16 @@ const embedSsoWorkbook = async (props) => {
82
86
  return embedSsoContent({ ...props, contentPath });
83
87
  };
84
88
  exports.embedSsoWorkbook = embedSsoWorkbook;
89
+ /**
90
+ * *IN BETA* Generates an embed login URL using the passed-in content discovery page id.
91
+ * @param EmbedSsoContentDiscoveryProps
92
+ * @returns Promise wrapped around a generated embed login url.
93
+ */
94
+ const embedSsoContentDiscovery = async (props) => {
95
+ const contentPath = `/${props.path}`;
96
+ return embedSsoContent({
97
+ ...props,
98
+ contentPath,
99
+ });
100
+ };
101
+ exports.embedSsoContentDiscovery = embedSsoContentDiscovery;
@@ -29,24 +29,20 @@ type SignatureProps = {
29
29
  */
30
30
  secret: string;
31
31
  /**
32
- * The user attributes to be sent with the request. Expected to be a stringified JSON object.
32
+ * The connection roles to be associated with the embed user. Expected to be a stringified JSON object.
33
+ */
34
+ connectionRoles?: string;
35
+ /**
36
+ * The custom theme to be sent with the request. Expected to be a stringified JSON object.
33
37
  *
34
- * Example: '{ "team": "Lakers" }'
38
+ * Example: '{ "dashboard-background-color": "hotpink" }'
35
39
  */
36
- userAttributes?: string;
40
+ customTheme?: string;
37
41
  /**
38
42
  * The entity that the created embed user will belong to. Practically speaking, the embed
39
43
  * user will this value assigned to its omni_user_embed_entity user attribute.
40
44
  */
41
45
  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
46
  /**
51
47
  * Filter search parameter.
52
48
  */
@@ -56,14 +52,22 @@ type SignatureProps = {
56
52
  */
57
53
  linkAccess?: string;
58
54
  /**
59
- * The custom theme to be sent with the request. Expected to be a stringified JSON object.
55
+ * Whether the user prefers light, dark, or system theme.
56
+ */
57
+ prefersDark?: string;
58
+ /**
59
+ * The theme of the embed.
60
+ */
61
+ theme?: string;
62
+ /**
63
+ * The user attributes to be sent with the request. Expected to be a stringified JSON object.
60
64
  *
61
- * Example: '{ "dashboard-background-color": "hotpink" }'
65
+ * Example: '{ "team": "Lakers" }'
62
66
  */
63
- customTheme?: string;
67
+ userAttributes?: string;
64
68
  };
65
69
  export declare const getSignature: ({ secret, ...props }: SignatureProps) => string;
66
70
  export declare const TEST_ONLY: {
67
- generateStringForSignature: ({ loginUrl, contentPath, externalId, name, nonce, userAttributes, entity, prefersDark, theme, filterSearchParam, linkAccess, customTheme, }: Omit<SignatureProps, "secret">) => string;
71
+ generateStringForSignature: ({ loginUrl, contentPath, externalId, name, nonce, connectionRoles, customTheme, entity, filterSearchParam, linkAccess, prefersDark, theme, userAttributes, }: Omit<SignatureProps, "secret">) => string;
68
72
  };
69
73
  export {};
@@ -13,10 +13,17 @@ const hmacSign = (data, secret) => {
13
13
  return base64url_1.default.fromBase64(b64);
14
14
  };
15
15
  exports.hmacSign = hmacSign;
16
- const generateStringForSignature = ({ loginUrl, contentPath, externalId, name, nonce, userAttributes, entity, prefersDark, theme, filterSearchParam, linkAccess, customTheme, }) => {
16
+ const generateStringForSignature = ({
17
+ // Required parameters
18
+ loginUrl, contentPath, externalId, name, nonce,
19
+ // Optional parameters
20
+ connectionRoles, customTheme, entity, filterSearchParam, linkAccess, prefersDark, theme, userAttributes, }) => {
17
21
  const optionalParams = [];
18
- entity && optionalParams.push(entity);
22
+ // Optional parameters should be pushed into the optionalParams array in ALPHABETICAL order
23
+ // for customers producing embed login URLs.
24
+ connectionRoles && optionalParams.push(connectionRoles);
19
25
  customTheme && optionalParams.push(customTheme);
26
+ entity && optionalParams.push(entity);
20
27
  filterSearchParam && optionalParams.push(filterSearchParam);
21
28
  linkAccess && optionalParams.push(linkAccess);
22
29
  prefersDark && optionalParams.push(prefersDark);
@@ -1,6 +1,5 @@
1
1
  type UserAttributeValue = string | string[] | number | number[];
2
2
  type EmbedSsoBaseProps = {
3
- contentId: string;
4
3
  externalId: string;
5
4
  name: string;
6
5
  organizationName: string;
@@ -21,6 +20,12 @@ type EmbedSsoDashboardOnlyProps = {
21
20
  type EmbedContentIdProp = {
22
21
  contentId: string;
23
22
  };
23
+ type EmbedContentPathProp = {
24
+ contentPath: string;
25
+ };
26
+ type EmbedConnectionRolesProp = {
27
+ connectionRoles: Record<string, EmbedConnectionRoles>;
28
+ };
24
29
  export type CustomThemeProperties = {
25
30
  "dashboard-background"?: string;
26
31
  "dashboard-tile-background"?: string;
@@ -43,9 +48,21 @@ export declare enum EmbeddedContent {
43
48
  Dashboard = "dashboards",
44
49
  Workbook = "w"
45
50
  }
51
+ export declare const EmbedSsoContentDiscoveryPaths: readonly ["my"];
52
+ export type EmbedSsoContentDiscoveryPath = (typeof EmbedSsoContentDiscoveryPaths)[number];
53
+ export declare enum EmbedConnectionRoles {
54
+ RESTRICTED_QUERIER = "RESTRICTED_QUERIER"
55
+ }
56
+ export type EmbedSsoContentProps = EmbedSsoBaseProps & EmbedSsoDashboardOnlyProps & EmbedContentPathProp & Partial<EmbedConnectionRolesProp>;
46
57
  /**
47
- * Consumers of this SDK will rely on these two types to embed workbooks and dashboards.
58
+ * Consumers of this SDK will rely on these three types to embed workbooks and dashboards.
48
59
  */
49
60
  export type EmbedSsoDashboardProps = EmbedSsoBaseProps & EmbedSsoDashboardOnlyProps & EmbedContentIdProp;
50
61
  export type EmbedSsoWorkbookProps = EmbedSsoBaseProps & EmbedContentIdProp;
62
+ export type EmbedSsoContentDiscoveryProps = EmbedSsoBaseProps & EmbedConnectionRolesProp & {
63
+ /**
64
+ * Path name of the content discovery page to embed.
65
+ */
66
+ path: EmbedSsoContentDiscoveryPath;
67
+ };
51
68
  export {};
package/lib/cjs/types.js CHANGED
@@ -1,8 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EmbeddedContent = void 0;
3
+ exports.EmbedConnectionRoles = exports.EmbedSsoContentDiscoveryPaths = exports.EmbeddedContent = void 0;
4
4
  var EmbeddedContent;
5
5
  (function (EmbeddedContent) {
6
6
  EmbeddedContent["Dashboard"] = "dashboards";
7
7
  EmbeddedContent["Workbook"] = "w";
8
8
  })(EmbeddedContent || (exports.EmbeddedContent = EmbeddedContent = {}));
9
+ exports.EmbedSsoContentDiscoveryPaths = ["my"];
10
+ var EmbedConnectionRoles;
11
+ (function (EmbedConnectionRoles) {
12
+ // TODO: Eventually we'll want to add VIEWER. Currently though, since the sole use case of the
13
+ // connectionRoles parameter is personal content creation, I'm refraining from adding "VIEWER" to
14
+ // keep scope as limited as possible.
15
+ EmbedConnectionRoles["RESTRICTED_QUERIER"] = "RESTRICTED_QUERIER";
16
+ })(EmbedConnectionRoles || (exports.EmbedConnectionRoles = EmbedConnectionRoles = {}));
@@ -1,3 +1,9 @@
1
- import { EmbedSsoDashboardProps, EmbedSsoWorkbookProps } from "./types";
1
+ import { EmbedSsoContentDiscoveryProps, EmbedSsoDashboardProps, EmbedSsoWorkbookProps } from "./types";
2
2
  export declare const embedSsoDashboard: (props: EmbedSsoDashboardProps) => Promise<string>;
3
3
  export declare const embedSsoWorkbook: (props: EmbedSsoWorkbookProps) => Promise<string>;
4
+ /**
5
+ * *IN BETA* Generates an embed login URL using the passed-in content discovery page id.
6
+ * @param EmbedSsoContentDiscoveryProps
7
+ * @returns Promise wrapped around a generated embed login url.
8
+ */
9
+ export declare const embedSsoContentDiscovery: (props: EmbedSsoContentDiscoveryProps) => Promise<string>;
package/lib/esm/embed.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { random32ByteString } from "./random-str";
2
2
  import { getSignature } from "./signature";
3
- import { EmbeddedContent } from "./types";
3
+ import { EmbeddedContent, } from "./types";
4
4
  const defaultEmbedDomain = "embed-omniapp.co";
5
- const embedLoginPath = '/embed/login';
5
+ const embedLoginPath = "/embed/login";
6
6
  const validateProps = (props) => {
7
- const { externalId, name, nonce, organizationName, secret, userAttributes, } = props;
7
+ const { externalId, name, nonce, organizationName, secret, userAttributes } = props;
8
8
  if (!externalId) {
9
9
  throw new Error("externalId is required");
10
10
  }
@@ -28,12 +28,13 @@ const validateProps = (props) => {
28
28
  };
29
29
  const embedSsoContent = async (props) => {
30
30
  validateProps(props);
31
- let { contentPath, customTheme: rawCustomTheme, domain, externalId, filterSearchParam, linkAccess, name, nonce, organizationName, port, secret, userAttributes: rawUserAttributes, entity, prefersDark, theme, } = props;
31
+ let { connectionRoles: rawConnectionRoles, contentPath, customTheme: rawCustomTheme, domain, externalId, filterSearchParam, linkAccess, name, nonce, organizationName, port, secret, userAttributes: rawUserAttributes, entity, prefersDark, theme, } = props;
32
32
  // Handle defaults
33
33
  nonce = nonce !== null && nonce !== void 0 ? nonce : (await random32ByteString());
34
34
  domain = domain !== null && domain !== void 0 ? domain : defaultEmbedDomain;
35
35
  const userAttributes = rawUserAttributes && JSON.stringify(rawUserAttributes);
36
36
  const customTheme = rawCustomTheme && JSON.stringify(rawCustomTheme);
37
+ const connectionRoles = rawConnectionRoles && JSON.stringify(rawConnectionRoles);
37
38
  // Generate the url for the embed login route
38
39
  const url = new URL(embedLoginPath, `https://${organizationName.toLocaleLowerCase()}.${domain}${port ? `:${port}` : ""}`);
39
40
  // Get a signature for the request
@@ -51,6 +52,7 @@ const embedSsoContent = async (props) => {
51
52
  filterSearchParam,
52
53
  linkAccess,
53
54
  customTheme,
55
+ connectionRoles,
54
56
  });
55
57
  // Build and return the signed url
56
58
  url.searchParams.append("contentPath", contentPath);
@@ -66,6 +68,8 @@ const embedSsoContent = async (props) => {
66
68
  url.searchParams.append("filterSearchParam", filterSearchParam);
67
69
  linkAccess && url.searchParams.append("linkAccess", linkAccess);
68
70
  customTheme && url.searchParams.append("customTheme", customTheme);
71
+ connectionRoles &&
72
+ url.searchParams.append("connectionRoles", connectionRoles);
69
73
  return url.toString();
70
74
  };
71
75
  const buildContentPath = (contentType, contentId) => `/${contentType}/${contentId}`;
@@ -77,3 +81,15 @@ export const embedSsoWorkbook = async (props) => {
77
81
  const contentPath = `${buildContentPath(EmbeddedContent.Workbook, props.contentId)}/duplicate`;
78
82
  return embedSsoContent({ ...props, contentPath });
79
83
  };
84
+ /**
85
+ * *IN BETA* Generates an embed login URL using the passed-in content discovery page id.
86
+ * @param EmbedSsoContentDiscoveryProps
87
+ * @returns Promise wrapped around a generated embed login url.
88
+ */
89
+ export const embedSsoContentDiscovery = async (props) => {
90
+ const contentPath = `/${props.path}`;
91
+ return embedSsoContent({
92
+ ...props,
93
+ contentPath,
94
+ });
95
+ };
@@ -29,24 +29,20 @@ type SignatureProps = {
29
29
  */
30
30
  secret: string;
31
31
  /**
32
- * The user attributes to be sent with the request. Expected to be a stringified JSON object.
32
+ * The connection roles to be associated with the embed user. Expected to be a stringified JSON object.
33
+ */
34
+ connectionRoles?: string;
35
+ /**
36
+ * The custom theme to be sent with the request. Expected to be a stringified JSON object.
33
37
  *
34
- * Example: '{ "team": "Lakers" }'
38
+ * Example: '{ "dashboard-background-color": "hotpink" }'
35
39
  */
36
- userAttributes?: string;
40
+ customTheme?: string;
37
41
  /**
38
42
  * The entity that the created embed user will belong to. Practically speaking, the embed
39
43
  * user will this value assigned to its omni_user_embed_entity user attribute.
40
44
  */
41
45
  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
46
  /**
51
47
  * Filter search parameter.
52
48
  */
@@ -56,14 +52,22 @@ type SignatureProps = {
56
52
  */
57
53
  linkAccess?: string;
58
54
  /**
59
- * The custom theme to be sent with the request. Expected to be a stringified JSON object.
55
+ * Whether the user prefers light, dark, or system theme.
56
+ */
57
+ prefersDark?: string;
58
+ /**
59
+ * The theme of the embed.
60
+ */
61
+ theme?: string;
62
+ /**
63
+ * The user attributes to be sent with the request. Expected to be a stringified JSON object.
60
64
  *
61
- * Example: '{ "dashboard-background-color": "hotpink" }'
65
+ * Example: '{ "team": "Lakers" }'
62
66
  */
63
- customTheme?: string;
67
+ userAttributes?: string;
64
68
  };
65
69
  export declare const getSignature: ({ secret, ...props }: SignatureProps) => string;
66
70
  export declare const TEST_ONLY: {
67
- generateStringForSignature: ({ loginUrl, contentPath, externalId, name, nonce, userAttributes, entity, prefersDark, theme, filterSearchParam, linkAccess, customTheme, }: Omit<SignatureProps, "secret">) => string;
71
+ generateStringForSignature: ({ loginUrl, contentPath, externalId, name, nonce, connectionRoles, customTheme, entity, filterSearchParam, linkAccess, prefersDark, theme, userAttributes, }: Omit<SignatureProps, "secret">) => string;
68
72
  };
69
73
  export {};
@@ -6,10 +6,17 @@ export const hmacSign = (data, secret) => {
6
6
  const b64 = hmac.digest("base64");
7
7
  return base64url.fromBase64(b64);
8
8
  };
9
- const generateStringForSignature = ({ loginUrl, contentPath, externalId, name, nonce, userAttributes, entity, prefersDark, theme, filterSearchParam, linkAccess, customTheme, }) => {
9
+ const generateStringForSignature = ({
10
+ // Required parameters
11
+ loginUrl, contentPath, externalId, name, nonce,
12
+ // Optional parameters
13
+ connectionRoles, customTheme, entity, filterSearchParam, linkAccess, prefersDark, theme, userAttributes, }) => {
10
14
  const optionalParams = [];
11
- entity && optionalParams.push(entity);
15
+ // Optional parameters should be pushed into the optionalParams array in ALPHABETICAL order
16
+ // for customers producing embed login URLs.
17
+ connectionRoles && optionalParams.push(connectionRoles);
12
18
  customTheme && optionalParams.push(customTheme);
19
+ entity && optionalParams.push(entity);
13
20
  filterSearchParam && optionalParams.push(filterSearchParam);
14
21
  linkAccess && optionalParams.push(linkAccess);
15
22
  prefersDark && optionalParams.push(prefersDark);
@@ -1,6 +1,5 @@
1
1
  type UserAttributeValue = string | string[] | number | number[];
2
2
  type EmbedSsoBaseProps = {
3
- contentId: string;
4
3
  externalId: string;
5
4
  name: string;
6
5
  organizationName: string;
@@ -21,6 +20,12 @@ type EmbedSsoDashboardOnlyProps = {
21
20
  type EmbedContentIdProp = {
22
21
  contentId: string;
23
22
  };
23
+ type EmbedContentPathProp = {
24
+ contentPath: string;
25
+ };
26
+ type EmbedConnectionRolesProp = {
27
+ connectionRoles: Record<string, EmbedConnectionRoles>;
28
+ };
24
29
  export type CustomThemeProperties = {
25
30
  "dashboard-background"?: string;
26
31
  "dashboard-tile-background"?: string;
@@ -43,9 +48,21 @@ export declare enum EmbeddedContent {
43
48
  Dashboard = "dashboards",
44
49
  Workbook = "w"
45
50
  }
51
+ export declare const EmbedSsoContentDiscoveryPaths: readonly ["my"];
52
+ export type EmbedSsoContentDiscoveryPath = (typeof EmbedSsoContentDiscoveryPaths)[number];
53
+ export declare enum EmbedConnectionRoles {
54
+ RESTRICTED_QUERIER = "RESTRICTED_QUERIER"
55
+ }
56
+ export type EmbedSsoContentProps = EmbedSsoBaseProps & EmbedSsoDashboardOnlyProps & EmbedContentPathProp & Partial<EmbedConnectionRolesProp>;
46
57
  /**
47
- * Consumers of this SDK will rely on these two types to embed workbooks and dashboards.
58
+ * Consumers of this SDK will rely on these three types to embed workbooks and dashboards.
48
59
  */
49
60
  export type EmbedSsoDashboardProps = EmbedSsoBaseProps & EmbedSsoDashboardOnlyProps & EmbedContentIdProp;
50
61
  export type EmbedSsoWorkbookProps = EmbedSsoBaseProps & EmbedContentIdProp;
62
+ export type EmbedSsoContentDiscoveryProps = EmbedSsoBaseProps & EmbedConnectionRolesProp & {
63
+ /**
64
+ * Path name of the content discovery page to embed.
65
+ */
66
+ path: EmbedSsoContentDiscoveryPath;
67
+ };
51
68
  export {};
package/lib/esm/types.js CHANGED
@@ -3,3 +3,11 @@ export var EmbeddedContent;
3
3
  EmbeddedContent["Dashboard"] = "dashboards";
4
4
  EmbeddedContent["Workbook"] = "w";
5
5
  })(EmbeddedContent || (EmbeddedContent = {}));
6
+ export const EmbedSsoContentDiscoveryPaths = ["my"];
7
+ export var EmbedConnectionRoles;
8
+ (function (EmbedConnectionRoles) {
9
+ // TODO: Eventually we'll want to add VIEWER. Currently though, since the sole use case of the
10
+ // connectionRoles parameter is personal content creation, I'm refraining from adding "VIEWER" to
11
+ // keep scope as limited as possible.
12
+ EmbedConnectionRoles["RESTRICTED_QUERIER"] = "RESTRICTED_QUERIER";
13
+ })(EmbedConnectionRoles || (EmbedConnectionRoles = {}));
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.3.12",
2
+ "version": "0.3.14",
3
3
  "license": "MIT",
4
4
  "name": "@omni-co/embed",
5
5
  "author": "Nate Agrin <nate@exploreomni.com>",