@omni-co/embed 0.2.0 → 0.2.2
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 +70 -21
- package/lib/cjs/embed.d.ts +6 -4
- package/lib/cjs/embed.js +5 -1
- package/lib/cjs/signature.d.ts +9 -1
- package/lib/cjs/signature.js +3 -1
- package/lib/esm/embed.d.ts +6 -4
- package/lib/esm/embed.js +5 -1
- package/lib/esm/signature.d.ts +9 -1
- package/lib/esm/signature.js +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,28 +1,77 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Omni Embed SSO Typescript SDK
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Basic Example
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
```ts
|
|
6
|
+
import { embedSsoDashboard } from '@omni-co/embed'
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
// This creates a signed embed sso link for a dashboard
|
|
9
|
+
// in the omni account named Acme.
|
|
10
|
+
const iframeUrl = embedSsoDashboard({
|
|
11
|
+
contentId: "miU0hL6z",
|
|
12
|
+
externalId: "wile.e@coyote.co",
|
|
13
|
+
name: "Wile E",
|
|
14
|
+
organizationName: "acme",
|
|
15
|
+
secret: "abcdefghijklmnopqrstuvwxyz123456",
|
|
16
|
+
});
|
|
17
|
+
```
|
|
8
18
|
|
|
9
|
-
|
|
10
|
-
2. `npm install`
|
|
11
|
-
3. `npm run test`
|
|
19
|
+
## Kitchen Sink Example
|
|
12
20
|
|
|
13
|
-
|
|
21
|
+
```ts
|
|
22
|
+
import { embedSsoDashboard } from '@omni-co/embed'
|
|
14
23
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
// This creates a signed embed sso link for a dashboard
|
|
25
|
+
// in the omni account named Acme.
|
|
26
|
+
const iframeUrl = embedSsoDashboard({
|
|
27
|
+
contentId: "miU0hL6z",
|
|
28
|
+
externalId: "wile.e@coyote.co",
|
|
29
|
+
entity: "cartoon",
|
|
30
|
+
name: "Wile E",
|
|
31
|
+
organizationName: "acme",
|
|
32
|
+
secret: "abcdefghijklmnopqrstuvwxyz123456",
|
|
33
|
+
prefersDark: "system",
|
|
34
|
+
theme: "vibes",
|
|
35
|
+
userAttributes: { tool: "anvil" }
|
|
36
|
+
});
|
|
37
|
+
```
|
|
27
38
|
|
|
28
|
-
|
|
39
|
+
## embedSsoDashboard
|
|
40
|
+
|
|
41
|
+
This is the type signature for the embedSsoDashboard function:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
type EmbedSsoDashboardProps = {
|
|
45
|
+
// Short GUID of the dashboard. Can be obtained via the dashboard's url.
|
|
46
|
+
contentId: string;
|
|
47
|
+
|
|
48
|
+
// Required identifier to associate the external user with an
|
|
49
|
+
// automatically generated internal Omni user.
|
|
50
|
+
externalId: string;
|
|
51
|
+
|
|
52
|
+
// Required name of the external user.
|
|
53
|
+
name: string;
|
|
54
|
+
|
|
55
|
+
// Required Omni organization which contains the dashboard.
|
|
56
|
+
organizationName: string;
|
|
57
|
+
|
|
58
|
+
// Signing secret available to Omni admins.
|
|
59
|
+
secret: string;
|
|
60
|
+
|
|
61
|
+
// Optional identifier to associate the user with an external
|
|
62
|
+
// organization or system.
|
|
63
|
+
entity?: string;
|
|
64
|
+
|
|
65
|
+
// Optional user attributes to be passed to user associated with the
|
|
66
|
+
// externalId. User attributes must be created in Omni before being
|
|
67
|
+
// defined and given a value here.
|
|
68
|
+
userAttributes?: Record<string, string>;
|
|
69
|
+
|
|
70
|
+
// Optional dark mode setting. Can be one of "true", "false", or "system".
|
|
71
|
+
prefersDark?: string;
|
|
72
|
+
|
|
73
|
+
// Optional theme setting. Can be one of "dawn", "vibes", "breeze" or "blank".
|
|
74
|
+
theme?: string;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
```
|
package/lib/cjs/embed.d.ts
CHANGED
|
@@ -1,14 +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>;
|
|
9
|
+
prefersDark?: string;
|
|
10
|
+
theme?: string;
|
|
11
|
+
domain?: string;
|
|
12
|
+
nonce?: string;
|
|
13
|
+
port?: number;
|
|
12
14
|
};
|
|
13
15
|
export declare const embedSsoDashboard: (props: EmbedSsoProps) => string;
|
|
14
16
|
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, entity, } = props;
|
|
37
|
+
let { contentId, domain, externalId, name, nonce, organizationName, port, secret, userAttributes: rawUserAttributes, entity, prefersDark, theme, } = props;
|
|
38
38
|
// Handle defaults
|
|
39
39
|
nonce = nonce ?? (0, random_str_1.random32ByteString)();
|
|
40
40
|
domain = domain ?? defaultEmbedDomain;
|
|
@@ -53,6 +53,8 @@ const embedSsoDashboard = (props) => {
|
|
|
53
53
|
secret,
|
|
54
54
|
userAttributes,
|
|
55
55
|
entity,
|
|
56
|
+
prefersDark,
|
|
57
|
+
theme,
|
|
56
58
|
});
|
|
57
59
|
// Build and return the signed url
|
|
58
60
|
url.searchParams.append("contentPath", contentPath);
|
|
@@ -62,6 +64,8 @@ const embedSsoDashboard = (props) => {
|
|
|
62
64
|
url.searchParams.append("signature", signature);
|
|
63
65
|
userAttributes && url.searchParams.append("userAttributes", userAttributes);
|
|
64
66
|
entity && url.searchParams.append("entity", entity);
|
|
67
|
+
prefersDark && url.searchParams.append("prefersDark", prefersDark);
|
|
68
|
+
theme && url.searchParams.append("theme", theme);
|
|
65
69
|
return url.toString();
|
|
66
70
|
};
|
|
67
71
|
exports.embedSsoDashboard = embedSsoDashboard;
|
package/lib/cjs/signature.d.ts
CHANGED
|
@@ -39,9 +39,17 @@ type SignatureProps = {
|
|
|
39
39
|
* user will this value assigned to its omni_user_embed_entity user attribute.
|
|
40
40
|
*/
|
|
41
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;
|
|
42
50
|
};
|
|
43
51
|
export declare const getSignature: ({ secret, ...props }: SignatureProps) => string;
|
|
44
52
|
export declare const TEST_ONLY: {
|
|
45
|
-
generateStringForSignature: ({ loginUrl, contentPath, externalId, name, nonce, userAttributes, entity, }: Omit<SignatureProps, "secret">) => string;
|
|
53
|
+
generateStringForSignature: ({ loginUrl, contentPath, externalId, name, nonce, userAttributes, entity, prefersDark, theme, }: Omit<SignatureProps, "secret">) => string;
|
|
46
54
|
};
|
|
47
55
|
export {};
|
package/lib/cjs/signature.js
CHANGED
|
@@ -11,9 +11,11 @@ const hmacSign = (data, secret) => {
|
|
|
11
11
|
return hmac.digest("base64url");
|
|
12
12
|
};
|
|
13
13
|
exports.hmacSign = hmacSign;
|
|
14
|
-
const generateStringForSignature = ({ loginUrl, contentPath, externalId, name, nonce, userAttributes, entity, }) => {
|
|
14
|
+
const generateStringForSignature = ({ loginUrl, contentPath, externalId, name, nonce, userAttributes, entity, prefersDark, theme, }) => {
|
|
15
15
|
const optionalParams = [];
|
|
16
16
|
entity && optionalParams.push(entity);
|
|
17
|
+
prefersDark && optionalParams.push(prefersDark);
|
|
18
|
+
theme && optionalParams.push(theme);
|
|
17
19
|
userAttributes && optionalParams.push(userAttributes);
|
|
18
20
|
return `
|
|
19
21
|
${loginUrl}
|
package/lib/esm/embed.d.ts
CHANGED
|
@@ -1,14 +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>;
|
|
9
|
+
prefersDark?: string;
|
|
10
|
+
theme?: string;
|
|
11
|
+
domain?: string;
|
|
12
|
+
nonce?: string;
|
|
13
|
+
port?: number;
|
|
12
14
|
};
|
|
13
15
|
export declare const embedSsoDashboard: (props: EmbedSsoProps) => string;
|
|
14
16
|
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, entity, } = props;
|
|
34
|
+
let { contentId, domain, externalId, name, nonce, organizationName, port, secret, userAttributes: rawUserAttributes, entity, prefersDark, theme, } = props;
|
|
35
35
|
// Handle defaults
|
|
36
36
|
nonce = nonce ?? random32ByteString();
|
|
37
37
|
domain = domain ?? defaultEmbedDomain;
|
|
@@ -50,6 +50,8 @@ export const embedSsoDashboard = (props) => {
|
|
|
50
50
|
secret,
|
|
51
51
|
userAttributes,
|
|
52
52
|
entity,
|
|
53
|
+
prefersDark,
|
|
54
|
+
theme,
|
|
53
55
|
});
|
|
54
56
|
// Build and return the signed url
|
|
55
57
|
url.searchParams.append("contentPath", contentPath);
|
|
@@ -59,5 +61,7 @@ export const embedSsoDashboard = (props) => {
|
|
|
59
61
|
url.searchParams.append("signature", signature);
|
|
60
62
|
userAttributes && url.searchParams.append("userAttributes", userAttributes);
|
|
61
63
|
entity && url.searchParams.append("entity", entity);
|
|
64
|
+
prefersDark && url.searchParams.append("prefersDark", prefersDark);
|
|
65
|
+
theme && url.searchParams.append("theme", theme);
|
|
62
66
|
return url.toString();
|
|
63
67
|
};
|
package/lib/esm/signature.d.ts
CHANGED
|
@@ -39,9 +39,17 @@ type SignatureProps = {
|
|
|
39
39
|
* user will this value assigned to its omni_user_embed_entity user attribute.
|
|
40
40
|
*/
|
|
41
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;
|
|
42
50
|
};
|
|
43
51
|
export declare const getSignature: ({ secret, ...props }: SignatureProps) => string;
|
|
44
52
|
export declare const TEST_ONLY: {
|
|
45
|
-
generateStringForSignature: ({ loginUrl, contentPath, externalId, name, nonce, userAttributes, entity, }: Omit<SignatureProps, "secret">) => string;
|
|
53
|
+
generateStringForSignature: ({ loginUrl, contentPath, externalId, name, nonce, userAttributes, entity, prefersDark, theme, }: Omit<SignatureProps, "secret">) => string;
|
|
46
54
|
};
|
|
47
55
|
export {};
|
package/lib/esm/signature.js
CHANGED
|
@@ -4,9 +4,11 @@ export const hmacSign = (data, secret) => {
|
|
|
4
4
|
hmac.update(data);
|
|
5
5
|
return hmac.digest("base64url");
|
|
6
6
|
};
|
|
7
|
-
const generateStringForSignature = ({ loginUrl, contentPath, externalId, name, nonce, userAttributes, entity, }) => {
|
|
7
|
+
const generateStringForSignature = ({ loginUrl, contentPath, externalId, name, nonce, userAttributes, entity, prefersDark, theme, }) => {
|
|
8
8
|
const optionalParams = [];
|
|
9
9
|
entity && optionalParams.push(entity);
|
|
10
|
+
prefersDark && optionalParams.push(prefersDark);
|
|
11
|
+
theme && optionalParams.push(theme);
|
|
10
12
|
userAttributes && optionalParams.push(userAttributes);
|
|
11
13
|
return `
|
|
12
14
|
${loginUrl}
|
package/package.json
CHANGED