@usemogul/connect-common 0.2.0 → 0.3.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 +2 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.js +20 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,8 @@ Zero runtime dependencies. Ships ESM + CJS + TypeScript types.
|
|
|
14
14
|
- `ConnectedIdentity` — identity payload carried on `mogul:success`
|
|
15
15
|
- `FRAME_EVENT` / `PARENT_EVENT` — event-name constants
|
|
16
16
|
- `CONNECT_ERROR_CODE` / `ConnectErrorCode` — the `mogul:error` codes
|
|
17
|
-
(`token_error`, `invalid_target`, `client_mismatch`, `identity_unavailable
|
|
17
|
+
(`token_error`, `invalid_target`, `client_mismatch`, `identity_unavailable`,
|
|
18
|
+
`origin_not_allowed`, `verification_failed`).
|
|
18
19
|
`mogul:error.code` stays typed as `string` on the wire, so handle unknown codes.
|
|
19
20
|
- `parseFrameMessage(data)` — for the loader: validates untrusted `postMessage`
|
|
20
21
|
data into a known `FrameMessage`, or `null`.
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i={ready:"mogul:ready",requestToken:"mogul:request-token",
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i={ready:"mogul:ready",requestToken:"mogul:request-token",success:"mogul:success",exit:"mogul:exit",error:"mogul:error"},s={init:"mogul:init",logout:"mogul:logout"},u={tokenError:"token_error",invalidTarget:"invalid_target",clientMismatch:"client_mismatch",identityUnavailable:"identity_unavailable",originNotAllowed:"origin_not_allowed",verificationFailed:"verification_failed"},l=t=>{if(typeof t!="object"||t===null)return;const e=t;if(typeof e.id!="string"||typeof e.name!="string"||!Array.isArray(e.accounts))return;const n=[];for(const o of e.accounts){if(typeof o!="object"||o===null)return;const r=o;if(typeof r.id!="string"||typeof r.name!="string")return;n.push({id:r.id,name:r.name})}return{id:e.id,name:e.name,accounts:n}},c=t=>{if(typeof t!="object"||t===null)return null;const e=t;switch(e.type){case"mogul:ready":case"mogul:request-token":case"mogul:exit":return{type:e.type};case"mogul:success":{const n=l(e.connectedIdentity);return typeof e.integrationId=="number"&&typeof e.accountId=="string"&&n?{type:"mogul:success",integrationId:e.integrationId,accountId:e.accountId,connectedIdentity:n}:null}case"mogul:error":return typeof e.code=="string"?{type:"mogul:error",code:e.code}:null;default:return null}},a=t=>{if(typeof t!="object"||t===null)return null;const e=t;switch(e.type){case"mogul:init":{const{token:n,clientId:o,locale:r}=e;return typeof n!="string"||n.length===0||typeof o!="string"||o.length===0?null:typeof r=="string"?{type:"mogul:init",token:n,clientId:o,locale:r}:{type:"mogul:init",token:n,clientId:o}}case"mogul:logout":return{type:"mogul:logout"};default:return null}};exports.CONNECT_ERROR_CODE=u;exports.FRAME_EVENT=i;exports.PARENT_EVENT=s;exports.parseFrameMessage=c;exports.parseParentMessage=a;
|
package/dist/index.d.cts
CHANGED
|
@@ -14,6 +14,17 @@ export declare const CONNECT_ERROR_CODE: {
|
|
|
14
14
|
* identity couldn't be resolved, so no `mogul:success` is sent.
|
|
15
15
|
*/
|
|
16
16
|
readonly identityUnavailable: "identity_unavailable";
|
|
17
|
+
/**
|
|
18
|
+
* Frame: the embedding page's origin isn't registered for the partner the
|
|
19
|
+
* session token belongs to (or the token's partner doesn't match `clientId`),
|
|
20
|
+
* so the token is refused and the flow never loads.
|
|
21
|
+
*/
|
|
22
|
+
readonly originNotAllowed: "origin_not_allowed";
|
|
23
|
+
/**
|
|
24
|
+
* Frame: the frame couldn't reach Mogul to verify the embedding origin, so
|
|
25
|
+
* the token is refused. Transient: remount (or the next `mogul:init`) retries.
|
|
26
|
+
*/
|
|
27
|
+
readonly verificationFailed: "verification_failed";
|
|
17
28
|
};
|
|
18
29
|
|
|
19
30
|
/** Identity the connected source resolved to, parsed from the integration. */
|
|
@@ -38,7 +49,6 @@ export declare type ConnectErrorCode = (typeof CONNECT_ERROR_CODE)[keyof typeof
|
|
|
38
49
|
export declare const FRAME_EVENT: {
|
|
39
50
|
readonly ready: "mogul:ready";
|
|
40
51
|
readonly requestToken: "mogul:request-token";
|
|
41
|
-
readonly resize: "mogul:resize";
|
|
42
52
|
readonly success: "mogul:success";
|
|
43
53
|
readonly exit: "mogul:exit";
|
|
44
54
|
readonly error: "mogul:error";
|
|
@@ -49,9 +59,6 @@ export declare type FrameMessage = {
|
|
|
49
59
|
type: 'mogul:ready';
|
|
50
60
|
} | {
|
|
51
61
|
type: 'mogul:request-token';
|
|
52
|
-
} | {
|
|
53
|
-
type: 'mogul:resize';
|
|
54
|
-
height: number;
|
|
55
62
|
} | {
|
|
56
63
|
/**
|
|
57
64
|
* Sent when the user dismisses the success screen (Done), and only when
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,17 @@ export declare const CONNECT_ERROR_CODE: {
|
|
|
14
14
|
* identity couldn't be resolved, so no `mogul:success` is sent.
|
|
15
15
|
*/
|
|
16
16
|
readonly identityUnavailable: "identity_unavailable";
|
|
17
|
+
/**
|
|
18
|
+
* Frame: the embedding page's origin isn't registered for the partner the
|
|
19
|
+
* session token belongs to (or the token's partner doesn't match `clientId`),
|
|
20
|
+
* so the token is refused and the flow never loads.
|
|
21
|
+
*/
|
|
22
|
+
readonly originNotAllowed: "origin_not_allowed";
|
|
23
|
+
/**
|
|
24
|
+
* Frame: the frame couldn't reach Mogul to verify the embedding origin, so
|
|
25
|
+
* the token is refused. Transient: remount (or the next `mogul:init`) retries.
|
|
26
|
+
*/
|
|
27
|
+
readonly verificationFailed: "verification_failed";
|
|
17
28
|
};
|
|
18
29
|
|
|
19
30
|
/** Identity the connected source resolved to, parsed from the integration. */
|
|
@@ -38,7 +49,6 @@ export declare type ConnectErrorCode = (typeof CONNECT_ERROR_CODE)[keyof typeof
|
|
|
38
49
|
export declare const FRAME_EVENT: {
|
|
39
50
|
readonly ready: "mogul:ready";
|
|
40
51
|
readonly requestToken: "mogul:request-token";
|
|
41
|
-
readonly resize: "mogul:resize";
|
|
42
52
|
readonly success: "mogul:success";
|
|
43
53
|
readonly exit: "mogul:exit";
|
|
44
54
|
readonly error: "mogul:error";
|
|
@@ -49,9 +59,6 @@ export declare type FrameMessage = {
|
|
|
49
59
|
type: 'mogul:ready';
|
|
50
60
|
} | {
|
|
51
61
|
type: 'mogul:request-token';
|
|
52
|
-
} | {
|
|
53
|
-
type: 'mogul:resize';
|
|
54
|
-
height: number;
|
|
55
62
|
} | {
|
|
56
63
|
/**
|
|
57
64
|
* Sent when the user dismisses the success screen (Done), and only when
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
const u = {
|
|
2
2
|
ready: "mogul:ready",
|
|
3
3
|
requestToken: "mogul:request-token",
|
|
4
|
-
resize: "mogul:resize",
|
|
5
4
|
success: "mogul:success",
|
|
6
5
|
exit: "mogul:exit",
|
|
7
6
|
error: "mogul:error"
|
|
8
|
-
},
|
|
7
|
+
}, l = {
|
|
9
8
|
init: "mogul:init",
|
|
10
9
|
logout: "mogul:logout"
|
|
11
|
-
},
|
|
10
|
+
}, c = {
|
|
12
11
|
/** Loader: the partner's `getToken()` threw. */
|
|
13
12
|
tokenError: "token_error",
|
|
14
13
|
/** Frame: the preselected `/embed/connect/<target>` isn't a known source. */
|
|
@@ -22,7 +21,18 @@ const u = {
|
|
|
22
21
|
* Frame: the connection succeeded, but the integration ID or a complete
|
|
23
22
|
* identity couldn't be resolved, so no `mogul:success` is sent.
|
|
24
23
|
*/
|
|
25
|
-
identityUnavailable: "identity_unavailable"
|
|
24
|
+
identityUnavailable: "identity_unavailable",
|
|
25
|
+
/**
|
|
26
|
+
* Frame: the embedding page's origin isn't registered for the partner the
|
|
27
|
+
* session token belongs to (or the token's partner doesn't match `clientId`),
|
|
28
|
+
* so the token is refused and the flow never loads.
|
|
29
|
+
*/
|
|
30
|
+
originNotAllowed: "origin_not_allowed",
|
|
31
|
+
/**
|
|
32
|
+
* Frame: the frame couldn't reach Mogul to verify the embedding origin, so
|
|
33
|
+
* the token is refused. Transient: remount (or the next `mogul:init`) retries.
|
|
34
|
+
*/
|
|
35
|
+
verificationFailed: "verification_failed"
|
|
26
36
|
}, i = (t) => {
|
|
27
37
|
if (typeof t != "object" || t === null) return;
|
|
28
38
|
const e = t;
|
|
@@ -36,7 +46,7 @@ const u = {
|
|
|
36
46
|
n.push({ id: r.id, name: r.name });
|
|
37
47
|
}
|
|
38
48
|
return { id: e.id, name: e.name, accounts: n };
|
|
39
|
-
},
|
|
49
|
+
}, s = (t) => {
|
|
40
50
|
if (typeof t != "object" || t === null) return null;
|
|
41
51
|
const e = t;
|
|
42
52
|
switch (e.type) {
|
|
@@ -44,8 +54,6 @@ const u = {
|
|
|
44
54
|
case "mogul:request-token":
|
|
45
55
|
case "mogul:exit":
|
|
46
56
|
return { type: e.type };
|
|
47
|
-
case "mogul:resize":
|
|
48
|
-
return typeof e.height == "number" ? { type: "mogul:resize", height: e.height } : null;
|
|
49
57
|
case "mogul:success": {
|
|
50
58
|
const n = i(
|
|
51
59
|
e.connectedIdentity
|
|
@@ -62,7 +70,7 @@ const u = {
|
|
|
62
70
|
default:
|
|
63
71
|
return null;
|
|
64
72
|
}
|
|
65
|
-
},
|
|
73
|
+
}, a = (t) => {
|
|
66
74
|
if (typeof t != "object" || t === null) return null;
|
|
67
75
|
const e = t;
|
|
68
76
|
switch (e.type) {
|
|
@@ -77,9 +85,9 @@ const u = {
|
|
|
77
85
|
}
|
|
78
86
|
};
|
|
79
87
|
export {
|
|
80
|
-
|
|
88
|
+
c as CONNECT_ERROR_CODE,
|
|
81
89
|
u as FRAME_EVENT,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
l as PARENT_EVENT,
|
|
91
|
+
s as parseFrameMessage,
|
|
92
|
+
a as parseParentMessage
|
|
85
93
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usemogul/connect-common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Shared schemas for the Mogul Connect embedded component: message types, event-name constants, and validators shared by the connect-js loader and the Mogul application.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "shawn@usemogul.com",
|