@usemogul/connect-common 0.2.0 → 0.4.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 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",resize:"mogul:resize",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"},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:resize":return typeof e.height=="number"?{type:"mogul:resize",height:e.height}:null;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}},g=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=g;
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"},c=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}},l=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=c(e.connectedIdentity);return typeof e.sourceId=="number"&&typeof e.accountId=="string"&&n?{type:"mogul:success",sourceId:e.sourceId,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=l;exports.parseParentMessage=a;
package/dist/index.d.cts CHANGED
@@ -10,10 +10,21 @@ export declare const CONNECT_ERROR_CODE: {
10
10
  */
11
11
  readonly clientMismatch: "client_mismatch";
12
12
  /**
13
- * Frame: the connection succeeded, but the integration ID or a complete
13
+ * Frame: the connection succeeded, but the source ID or a complete
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
@@ -59,8 +66,8 @@ export declare type FrameMessage = {
59
66
  * Otherwise the frame sends `mogul:error` `identity_unavailable` instead.
60
67
  */
61
68
  type: 'mogul:success';
62
- /** The created integration — the handle for later royalty-report API calls. */
63
- integrationId: number;
69
+ /** The connected source. Used for royalty-report API calls. */
70
+ sourceId: number;
64
71
  /** Mogul account the integration belongs to (from the session token). */
65
72
  accountId: string;
66
73
  /** Identity parsed from the connected integration. */
package/dist/index.d.ts CHANGED
@@ -10,10 +10,21 @@ export declare const CONNECT_ERROR_CODE: {
10
10
  */
11
11
  readonly clientMismatch: "client_mismatch";
12
12
  /**
13
- * Frame: the connection succeeded, but the integration ID or a complete
13
+ * Frame: the connection succeeded, but the source ID or a complete
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
@@ -59,8 +66,8 @@ export declare type FrameMessage = {
59
66
  * Otherwise the frame sends `mogul:error` `identity_unavailable` instead.
60
67
  */
61
68
  type: 'mogul:success';
62
- /** The created integration — the handle for later royalty-report API calls. */
63
- integrationId: number;
69
+ /** The connected source. Used for royalty-report API calls. */
70
+ sourceId: number;
64
71
  /** Mogul account the integration belongs to (from the session token). */
65
72
  accountId: string;
66
73
  /** Identity parsed from the connected integration. */
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
- }, s = {
7
+ }, c = {
9
8
  init: "mogul:init",
10
9
  logout: "mogul:logout"
11
- }, l = {
10
+ }, s = {
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. */
@@ -19,10 +18,21 @@ const u = {
19
18
  */
20
19
  clientMismatch: "client_mismatch",
21
20
  /**
22
- * Frame: the connection succeeded, but the integration ID or a complete
21
+ * Frame: the connection succeeded, but the source 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
- }, c = (t) => {
49
+ }, l = (t) => {
40
50
  if (typeof t != "object" || t === null) return null;
41
51
  const e = t;
42
52
  switch (e.type) {
@@ -44,15 +54,13 @@ 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
52
60
  );
53
- return typeof e.integrationId == "number" && typeof e.accountId == "string" && n ? {
61
+ return typeof e.sourceId == "number" && typeof e.accountId == "string" && n ? {
54
62
  type: "mogul:success",
55
- integrationId: e.integrationId,
63
+ sourceId: e.sourceId,
56
64
  accountId: e.accountId,
57
65
  connectedIdentity: n
58
66
  } : null;
@@ -62,7 +70,7 @@ const u = {
62
70
  default:
63
71
  return null;
64
72
  }
65
- }, g = (t) => {
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
- l as CONNECT_ERROR_CODE,
88
+ s as CONNECT_ERROR_CODE,
81
89
  u as FRAME_EVENT,
82
- s as PARENT_EVENT,
83
- c as parseFrameMessage,
84
- g as parseParentMessage
90
+ c as PARENT_EVENT,
91
+ l 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.2.0",
3
+ "version": "0.4.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",