@omni-co/embed 0.4.10 → 0.4.12

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/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 && 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);
@@ -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
  };
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 && 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);
@@ -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
  };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.4.10",
2
+ "version": "0.4.12",
3
3
  "license": "MIT",
4
4
  "name": "@omni-co/embed",
5
5
  "author": "Nate Agrin <nate@exploreomni.com>",