ab-ecosystem-cpass 1.0.11 → 1.0.13
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 +1 -0
- package/dist/client.d.ts +6 -0
- package/dist/client.js +7 -0
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/embedded-signup.d.ts +46 -0
- package/dist/internal/embedded-signup.js +318 -0
- package/dist/internal/embedded-signup.js.map +1 -0
- package/dist/resources/channels/onboarding.d.ts +89 -0
- package/dist/resources/channels/onboarding.js +96 -0
- package/dist/resources/channels/onboarding.js.map +1 -0
- package/dist/types/campaign.d.ts +8 -0
- package/dist/types/channels.d.ts +129 -0
- package/dist/types/channels.js.map +1 -1
- package/docs/audience/canned-replies.md +3 -0
- package/docs/audience/contact-tags.md +4 -0
- package/docs/audience/contacts.md +30 -1
- package/docs/audience/crm-triggers.md +3 -0
- package/docs/audience/custom-fields.md +23 -0
- package/docs/audience/exports.md +6 -0
- package/docs/audience/imports.md +7 -0
- package/docs/audience/notifications.md +11 -0
- package/docs/audience/scheduled-messages.md +5 -0
- package/docs/audience/segments.md +4 -0
- package/docs/audience/webhooks.md +7 -0
- package/docs/campaign/campaigns.md +27 -0
- package/docs/channels/activity.md +3 -0
- package/docs/channels/billing.md +2 -0
- package/docs/channels/channel-props.md +19 -0
- package/docs/channels/channels.md +35 -2
- package/docs/channels/onboarding.md +530 -0
- package/docs/channels/templates.md +22 -0
- package/docs/channels/wallet.md +2 -0
- package/docs/channels/webhooks.md +6 -0
- package/docs/data-store.md +18 -0
- package/docs/inbox/connection.md +88 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -229,6 +229,7 @@ same pages ship inside the package, so they are readable offline at
|
|
|
229
229
|
| --- | --- | --- |
|
|
230
230
|
| `crm.channels` | [channels](https://github.com/udghatan-dev/crm-sdk/blob/main/packages/sdk-js/docs/channels/channels.md) | `list` `get` `updateDetails` `disable` `rotateToken` `getProp` `setProp` |
|
|
231
231
|
| — | [channel properties](https://github.com/udghatan-dev/crm-sdk/blob/main/packages/sdk-js/docs/channels/channel-props.md) | every `prop` `getProp`/`setProp` accepts |
|
|
232
|
+
| `crm.channelOnboarding` | [connecting a channel](https://github.com/udghatan-dev/crm-sdk/blob/main/packages/sdk-js/docs/channels/onboarding.md) | `types` `url` `pending` `complete` `exchange` `connect` |
|
|
232
233
|
| `crm.templates` | [templates](https://github.com/udghatan-dev/crm-sdk/blob/main/packages/sdk-js/docs/channels/templates.md) | `list` `get` `create` `update` `delete` `sync` |
|
|
233
234
|
| `crm.channelWebhooks` | [channel webhooks](https://github.com/udghatan-dev/crm-sdk/blob/main/packages/sdk-js/docs/channels/webhooks.md) | `list` `get` `create` `update` `delete` |
|
|
234
235
|
| `crm.billing` | [conversation billing](https://github.com/udghatan-dev/crm-sdk/blob/main/packages/sdk-js/docs/channels/billing.md) | `list` `stats` |
|
package/dist/client.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { InboxMedia } from './resources/audience/inbox-media';
|
|
|
14
14
|
import { Notifications } from './resources/audience/notifications';
|
|
15
15
|
import { DataStoreCollections, DataStoreRecords, DataStores } from './resources/data-stores';
|
|
16
16
|
import { Channels } from './resources/channels/channels';
|
|
17
|
+
import { ChannelOnboarding } from './resources/channels/onboarding';
|
|
17
18
|
import { Templates } from './resources/channels/templates';
|
|
18
19
|
import { ChannelWebhooks } from './resources/channels/webhooks';
|
|
19
20
|
import { Billing } from './resources/channels/billing';
|
|
@@ -95,6 +96,11 @@ export declare class CrmClient {
|
|
|
95
96
|
readonly dataStoreRecords: DataStoreRecords;
|
|
96
97
|
/** Channels, and the provider properties that hang off them. */
|
|
97
98
|
readonly channels: Channels;
|
|
99
|
+
/**
|
|
100
|
+
* Connecting a new channel. Separate from `channels` because it is the one
|
|
101
|
+
* channel operation that walks a person through a dialog on Meta's own site.
|
|
102
|
+
*/
|
|
103
|
+
readonly channelOnboarding: ChannelOnboarding;
|
|
98
104
|
/** WhatsApp message templates, per channel. */
|
|
99
105
|
readonly templates: Templates;
|
|
100
106
|
/** Channel webhooks: where a channel's message traffic is delivered. */
|
package/dist/client.js
CHANGED
|
@@ -19,6 +19,7 @@ const notifications_1 = require("./resources/audience/notifications");
|
|
|
19
19
|
const data_stores_1 = require("./resources/data-stores");
|
|
20
20
|
// Channels
|
|
21
21
|
const channels_1 = require("./resources/channels/channels");
|
|
22
|
+
const onboarding_1 = require("./resources/channels/onboarding");
|
|
22
23
|
const templates_1 = require("./resources/channels/templates");
|
|
23
24
|
const webhooks_2 = require("./resources/channels/webhooks");
|
|
24
25
|
const billing_1 = require("./resources/channels/billing");
|
|
@@ -103,6 +104,11 @@ class CrmClient {
|
|
|
103
104
|
// -- Channels -------------------------------------------------------------
|
|
104
105
|
/** Channels, and the provider properties that hang off them. */
|
|
105
106
|
channels;
|
|
107
|
+
/**
|
|
108
|
+
* Connecting a new channel. Separate from `channels` because it is the one
|
|
109
|
+
* channel operation that walks a person through a dialog on Meta's own site.
|
|
110
|
+
*/
|
|
111
|
+
channelOnboarding;
|
|
106
112
|
/** WhatsApp message templates, per channel. */
|
|
107
113
|
templates;
|
|
108
114
|
/** Channel webhooks: where a channel's message traffic is delivered. */
|
|
@@ -148,6 +154,7 @@ class CrmClient {
|
|
|
148
154
|
this.dataStoreCollections = new data_stores_1.DataStoreCollections(http);
|
|
149
155
|
this.dataStoreRecords = new data_stores_1.DataStoreRecords(http);
|
|
150
156
|
this.channels = new channels_1.Channels(http);
|
|
157
|
+
this.channelOnboarding = new onboarding_1.ChannelOnboarding(http);
|
|
151
158
|
this.templates = new templates_1.Templates(http);
|
|
152
159
|
this.channelWebhooks = new webhooks_2.ChannelWebhooks(http);
|
|
153
160
|
this.billing = new billing_1.Billing(http);
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],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,mBAAQ,CAAC,IAAI,CAAC,CAAC;QAEnC,uEAAuE;QACvE,yEAAyE;QACzE,WAAW;QACX,IAAI,CAAC,SAAS,GAAG,IAAI,qBAAS,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,gBAAgB,GAAG,IAAI,oCAAgB,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;CACF;AA1ID,8BA0IC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -25,6 +25,9 @@ export { CampaignMessages } from './resources/campaign-messages';
|
|
|
25
25
|
*/
|
|
26
26
|
export { MAX_BULK_RECEIVERS, buildReceivers, normaliseColumn, normaliseNumbers, parseDelimited, resolveAudience, type BulkAudienceInput, type CampaignReceiver, type ResolvedAudience, } from './resources/campaign-audience';
|
|
27
27
|
export { Channels, type SetPropOptions } from './resources/channels/channels';
|
|
28
|
+
export { ChannelOnboarding, type ConnectOptions } from './resources/channels/onboarding';
|
|
29
|
+
/** The popup drivers on their own, for a console that calls `url()` itself. */
|
|
30
|
+
export { awaitSignupReturn, openSignup, EmbeddedSignupError, type OpenSignupOptions, } from './internal/embedded-signup';
|
|
28
31
|
export { Templates } from './resources/channels/templates';
|
|
29
32
|
export { ChannelWebhooks } from './resources/channels/webhooks';
|
|
30
33
|
export { Billing } from './resources/channels/billing';
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Activity = exports.Wallet = exports.Billing = exports.ChannelWebhooks = exports.Templates = exports.Channels = exports.resolveAudience = exports.parseDelimited = exports.normaliseNumbers = exports.normaliseColumn = exports.buildReceivers = exports.MAX_BULK_RECEIVERS = exports.CampaignMessages = exports.Campaigns = exports.InboxMedia = exports.DataStoreRecords = exports.DataStoreCollections = exports.DataStores = exports.Notifications = exports.Webhooks = exports.Exports = exports.Imports = exports.CrmTriggers = exports.Segments = exports.CustomFields = exports.CannedReplies = exports.ContactNotes = exports.ContactTags = exports.Contacts = exports.CHANNELS = exports.AUDIENCE = void 0;
|
|
17
|
+
exports.Activity = exports.Wallet = exports.Billing = exports.ChannelWebhooks = exports.Templates = exports.EmbeddedSignupError = exports.openSignup = exports.awaitSignupReturn = exports.ChannelOnboarding = exports.Channels = exports.resolveAudience = exports.parseDelimited = exports.normaliseNumbers = exports.normaliseColumn = exports.buildReceivers = exports.MAX_BULK_RECEIVERS = exports.CampaignMessages = exports.Campaigns = exports.InboxMedia = exports.DataStoreRecords = exports.DataStoreCollections = exports.DataStores = exports.Notifications = exports.Webhooks = exports.Exports = exports.Imports = exports.CrmTriggers = exports.Segments = exports.CustomFields = exports.CannedReplies = exports.ContactNotes = exports.ContactTags = exports.Contacts = exports.CHANNELS = exports.AUDIENCE = void 0;
|
|
18
18
|
__exportStar(require("./client"), exports);
|
|
19
19
|
__exportStar(require("./http"), exports);
|
|
20
20
|
__exportStar(require("./errors"), exports);
|
|
@@ -71,6 +71,13 @@ Object.defineProperty(exports, "resolveAudience", { enumerable: true, get: funct
|
|
|
71
71
|
// Channels
|
|
72
72
|
var channels_1 = require("./resources/channels/channels");
|
|
73
73
|
Object.defineProperty(exports, "Channels", { enumerable: true, get: function () { return channels_1.Channels; } });
|
|
74
|
+
var onboarding_1 = require("./resources/channels/onboarding");
|
|
75
|
+
Object.defineProperty(exports, "ChannelOnboarding", { enumerable: true, get: function () { return onboarding_1.ChannelOnboarding; } });
|
|
76
|
+
/** The popup drivers on their own, for a console that calls `url()` itself. */
|
|
77
|
+
var embedded_signup_1 = require("./internal/embedded-signup");
|
|
78
|
+
Object.defineProperty(exports, "awaitSignupReturn", { enumerable: true, get: function () { return embedded_signup_1.awaitSignupReturn; } });
|
|
79
|
+
Object.defineProperty(exports, "openSignup", { enumerable: true, get: function () { return embedded_signup_1.openSignup; } });
|
|
80
|
+
Object.defineProperty(exports, "EmbeddedSignupError", { enumerable: true, get: function () { return embedded_signup_1.EmbeddedSignupError; } });
|
|
74
81
|
var templates_1 = require("./resources/channels/templates");
|
|
75
82
|
Object.defineProperty(exports, "Templates", { enumerable: true, get: function () { return templates_1.Templates; } });
|
|
76
83
|
var webhooks_2 = require("./resources/channels/webhooks");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,yCAAuB;AACvB,2CAAyB;AACzB,0CAAwB;AAExB,2CAAuD;AAA9C,iGAAA,QAAQ,OAAA;AAAE,iGAAA,QAAQ,OAAA;AAE3B,WAAW;AACX,0DAAyD;AAAhD,oGAAA,QAAQ,OAAA;AACjB,kEAAgE;AAAvD,2GAAA,WAAW,OAAA;AACpB,oEAAkE;AAAzD,6GAAA,YAAY,OAAA;AACrB,sEAAoE;AAA3D,+GAAA,aAAa,OAAA;AACtB,oEAAkE;AAAzD,6GAAA,YAAY,OAAA;AACrB,0DAAyD;AAAhD,oGAAA,QAAQ,OAAA;AACjB,kEAAgE;AAAvD,2GAAA,WAAW,OAAA;AACpB,sEAA8D;AAArD,yGAAA,OAAO,OAAA;AAChB,sEAA8D;AAArD,yGAAA,OAAO,OAAA;AAChB,0DAAyD;AAAhD,oGAAA,QAAQ,OAAA;AACjB,oEAAmE;AAA1D,8GAAA,aAAa,OAAA;AACtB,uDAIiC;AAH/B,yGAAA,UAAU,OAAA;AACV,mHAAA,oBAAoB,OAAA;AACpB,+GAAA,gBAAgB,OAAA;AAElB,gEAI0C;AAHxC,yGAAA,UAAU,OAAA;AAKZ,WAAW;AACX,mDAS+B;AAR7B,sGAAA,SAAS,OAAA;AASX,mEAAiE;AAAxD,qHAAA,gBAAgB,OAAA;AACzB;;;;GAIG;AACH,mEAUuC;AATrC,uHAAA,kBAAkB,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AR7B,sGAAA,SAAS,OAAA;AASX,mEAAiE;AAAxD,qHAAA,gBAAgB,OAAA;AACzB;;;;GAIG;AACH,mEAUuC;AATrC,uHAAA,kBAAkB,OAAA;AAClB,mHAAA,cAAc,OAAA;AACd,oHAAA,eAAe,OAAA;AACf,qHAAA,gBAAgB,OAAA;AAChB,mHAAA,cAAc,OAAA;AACd,oHAAA,eAAe,OAAA;AAMjB,WAAW;AACX,0DAA8E;AAArE,oGAAA,QAAQ,OAAA;AACjB,8DAAyF;AAAhF,+GAAA,iBAAiB,OAAA;AAC1B,+EAA+E;AAC/E,8DAKoC;AAJlC,oHAAA,iBAAiB,OAAA;AACjB,6GAAA,UAAU,OAAA;AACV,sHAAA,mBAAmB,OAAA;AAGrB,4DAA2D;AAAlD,sGAAA,SAAS,OAAA;AAClB,0DAAgE;AAAvD,2GAAA,eAAe,OAAA;AACxB,wDAAuD;AAA9C,kGAAA,OAAO,OAAA;AAChB,sDAAqD;AAA5C,gGAAA,MAAM,OAAA;AACf,0DAAyD;AAAhD,oGAAA,QAAQ,OAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { OnboardingReturn, SignupCredentials } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Two drivers for the same popup. {@link awaitSignupReturn} is the one to use:
|
|
4
|
+
* the code goes to the service's callback, so it only waits for the popup to
|
|
5
|
+
* come back to our origin. {@link openSignup} is the older half-and-half (code
|
|
6
|
+
* on the redirect, ids by `postMessage`), for a BSP app whose registered
|
|
7
|
+
* redirect is a page of yours -- what `/onboarding/exchange` exists for.
|
|
8
|
+
*/
|
|
9
|
+
/** How the popup is opened, and how to follow its progress. */
|
|
10
|
+
export interface OpenSignupOptions {
|
|
11
|
+
/** Window name, so a second call reuses the popup rather than opening two. */
|
|
12
|
+
name?: string;
|
|
13
|
+
width?: number;
|
|
14
|
+
height?: number;
|
|
15
|
+
/** How long to wait for both halves. Default 15 minutes. */
|
|
16
|
+
timeoutMs?: number;
|
|
17
|
+
/** For a console showing more than a spinner. `step` is Meta's own `current_step`. */
|
|
18
|
+
onProgress?: (event: {
|
|
19
|
+
phase: 'opened' | 'step' | 'code' | 'ids' | 'returned';
|
|
20
|
+
step?: string;
|
|
21
|
+
}) => void;
|
|
22
|
+
}
|
|
23
|
+
/** Thrown for every way the dialog can fail to produce credentials. */
|
|
24
|
+
export declare class EmbeddedSignupError extends Error {
|
|
25
|
+
readonly code: 'unsupported_environment' | 'popup_blocked' | 'popup_closed' | 'cancelled' | 'signup_error' | 'timeout';
|
|
26
|
+
/** The service's own code, when the refusal came back on the return URL. */
|
|
27
|
+
readonly reason?: string | undefined;
|
|
28
|
+
constructor(code: 'unsupported_environment' | 'popup_blocked' | 'popup_closed' | 'cancelled' | 'signup_error' | 'timeout', message: string,
|
|
29
|
+
/** The service's own code, when the refusal came back on the return URL. */
|
|
30
|
+
reason?: string | undefined);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The redirect flow: open the dialog, wait for the popup to come back to our
|
|
34
|
+
* origin with the service's outcome on it. Nothing here reads Meta, so the
|
|
35
|
+
* return has to be a page on **this** origin -- a cross-origin one cannot be
|
|
36
|
+
* read, and the wait ends as `popup_closed`.
|
|
37
|
+
*
|
|
38
|
+
* Call it **straight from a click handler**, or the `window.open` is blocked.
|
|
39
|
+
*/
|
|
40
|
+
export declare const awaitSignupReturn: (url: string, options?: OpenSignupOptions) => Promise<OnboardingReturn>;
|
|
41
|
+
/**
|
|
42
|
+
* The older driver, for a BSP app whose registered redirect is a page of yours:
|
|
43
|
+
* it waits for the code *and* the ids, which is what `/onboarding/exchange`
|
|
44
|
+
* takes. Call it **straight from a click handler**, as above.
|
|
45
|
+
*/
|
|
46
|
+
export declare const openSignup: (url: string, options?: OpenSignupOptions) => Promise<SignupCredentials>;
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.openSignup = exports.awaitSignupReturn = exports.EmbeddedSignupError = void 0;
|
|
4
|
+
/** Thrown for every way the dialog can fail to produce credentials. */
|
|
5
|
+
class EmbeddedSignupError extends Error {
|
|
6
|
+
code;
|
|
7
|
+
reason;
|
|
8
|
+
constructor(code, message,
|
|
9
|
+
/** The service's own code, when the refusal came back on the return URL. */
|
|
10
|
+
reason) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.reason = reason;
|
|
14
|
+
this.name = 'EmbeddedSignupError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.EmbeddedSignupError = EmbeddedSignupError;
|
|
18
|
+
/** The events that carry the ids. The second is a number off the WA Business app. */
|
|
19
|
+
const FINISH_EVENTS = ['FINISH', 'FINISH_WHATSAPP_BUSINESS_APP_ONBOARDING'];
|
|
20
|
+
/** Origins Meta posts the signup events from. */
|
|
21
|
+
const META_ORIGINS = ['https://www.facebook.com', 'https://web.facebook.com', 'https://business.facebook.com'];
|
|
22
|
+
const DEFAULT_TIMEOUT_MS = 15 * 60 * 1000;
|
|
23
|
+
const browser = () => {
|
|
24
|
+
const candidate = globalThis.window;
|
|
25
|
+
return candidate && typeof candidate.open === 'function' ? candidate : undefined;
|
|
26
|
+
};
|
|
27
|
+
/** An object in most browsers, a JSON string in some. */
|
|
28
|
+
const parsePayload = (data) => {
|
|
29
|
+
if (typeof data === 'string') {
|
|
30
|
+
try {
|
|
31
|
+
const parsed = JSON.parse(data);
|
|
32
|
+
return typeof parsed === 'object' && parsed !== null ? parsed : undefined;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return typeof data === 'object' && data !== null ? data : undefined;
|
|
39
|
+
};
|
|
40
|
+
const str = (value) => (typeof value === 'string' && value ? value : undefined);
|
|
41
|
+
const decodeBase64 = (value) => {
|
|
42
|
+
try {
|
|
43
|
+
const json = globalThis.atob?.(value);
|
|
44
|
+
return json ? parsePayload(json) : undefined;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* A redirect page may post its whole query string rather than an object, and
|
|
52
|
+
* may wrap it in a base64 `json` param, as our panel does.
|
|
53
|
+
*/
|
|
54
|
+
const fromSameOrigin = (data) => {
|
|
55
|
+
if (typeof data === 'string') {
|
|
56
|
+
const text = data.trim();
|
|
57
|
+
if (!text || !/[?&=]/.test(text))
|
|
58
|
+
return undefined;
|
|
59
|
+
const params = new URLSearchParams(text.startsWith('?') ? text.slice(1) : text);
|
|
60
|
+
const wrapped = params.get('json');
|
|
61
|
+
if (wrapped) {
|
|
62
|
+
const payload = decodeBase64(wrapped);
|
|
63
|
+
// `{ success: false, data: '<message>' }` on a refusal.
|
|
64
|
+
if (payload?.success === false)
|
|
65
|
+
return { error: str(payload.data) ?? 'Signup was refused' };
|
|
66
|
+
const inner = (payload?.data ?? payload);
|
|
67
|
+
return inner ?? undefined;
|
|
68
|
+
}
|
|
69
|
+
return Object.fromEntries(params.entries());
|
|
70
|
+
}
|
|
71
|
+
const payload = parsePayload(data);
|
|
72
|
+
return payload?.type === 'CRM_CHANNEL_ONBOARDING' ? payload : undefined;
|
|
73
|
+
};
|
|
74
|
+
/** Centred, and named so a second call reuses the window rather than opening two. */
|
|
75
|
+
const openPopup = (win, url, options) => {
|
|
76
|
+
const width = options.width ?? 620;
|
|
77
|
+
const height = options.height ?? 760;
|
|
78
|
+
const left = Math.max(0, ((win.screen?.width ?? width) - width) / 2);
|
|
79
|
+
const top = Math.max(0, ((win.screen?.height ?? height) - height) / 2);
|
|
80
|
+
return win.open(url, options.name ?? 'wa_embedded_signup', `popup=1,width=${width},height=${height},left=${left},top=${top},scrollbars=1,resizable=1`);
|
|
81
|
+
};
|
|
82
|
+
/** A console's progress callback is never allowed to break the flow. */
|
|
83
|
+
const report = (options, phase, step) => {
|
|
84
|
+
try {
|
|
85
|
+
options.onProgress?.({ phase, step });
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// Theirs to fix, not ours to propagate.
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* The redirect flow: open the dialog, wait for the popup to come back to our
|
|
93
|
+
* origin with the service's outcome on it. Nothing here reads Meta, so the
|
|
94
|
+
* return has to be a page on **this** origin -- a cross-origin one cannot be
|
|
95
|
+
* read, and the wait ends as `popup_closed`.
|
|
96
|
+
*
|
|
97
|
+
* Call it **straight from a click handler**, or the `window.open` is blocked.
|
|
98
|
+
*/
|
|
99
|
+
const awaitSignupReturn = (url, options = {}) => {
|
|
100
|
+
const win = browser();
|
|
101
|
+
if (!win) {
|
|
102
|
+
return Promise.reject(new EmbeddedSignupError('unsupported_environment', 'Embedded signup needs a browser; drive the onboarding calls yourself outside one'));
|
|
103
|
+
}
|
|
104
|
+
const popup = openPopup(win, url, options);
|
|
105
|
+
if (!popup) {
|
|
106
|
+
return Promise.reject(new EmbeddedSignupError('popup_blocked', 'The signup window was blocked; allow popups and try again'));
|
|
107
|
+
}
|
|
108
|
+
return new Promise((resolve, reject) => {
|
|
109
|
+
let settled = false;
|
|
110
|
+
const finish = (outcome) => {
|
|
111
|
+
if (settled)
|
|
112
|
+
return;
|
|
113
|
+
settled = true;
|
|
114
|
+
win.removeEventListener('message', onMessage);
|
|
115
|
+
win.clearInterval(poll);
|
|
116
|
+
win.clearTimeout(timer);
|
|
117
|
+
try {
|
|
118
|
+
if (!popup.closed)
|
|
119
|
+
popup.close();
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// Cross-origin as it closed; the window is the user's problem now.
|
|
123
|
+
}
|
|
124
|
+
outcome();
|
|
125
|
+
};
|
|
126
|
+
/** True once something carrying a `status` has been dealt with. */
|
|
127
|
+
const take = (returned) => {
|
|
128
|
+
const status = str(returned?.status);
|
|
129
|
+
if (!returned || !status)
|
|
130
|
+
return false;
|
|
131
|
+
report(options, 'returned');
|
|
132
|
+
if (status === 'error') {
|
|
133
|
+
finish(() => reject(new EmbeddedSignupError('signup_error', str(returned.message) ?? 'The number could not be connected', str(returned.code))));
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
finish(() => resolve(returned));
|
|
137
|
+
return true;
|
|
138
|
+
};
|
|
139
|
+
// For a return page that posts its query and closes itself, which the poll
|
|
140
|
+
// would never get to read.
|
|
141
|
+
const onMessage = (event) => {
|
|
142
|
+
if (event.origin !== win.location.origin)
|
|
143
|
+
return;
|
|
144
|
+
take(fromSameOrigin(event.data));
|
|
145
|
+
};
|
|
146
|
+
const poll = win.setInterval(() => {
|
|
147
|
+
if (popup.closed) {
|
|
148
|
+
finish(() => reject(new EmbeddedSignupError('popup_closed', 'The signup window was closed before it finished')));
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
// Reading this throws while the window is still on Meta's origin.
|
|
153
|
+
take(popup.location.search ? fromSameOrigin(popup.location.search) : undefined);
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
// Still at Meta, so there is nothing to read yet.
|
|
157
|
+
}
|
|
158
|
+
}, 400);
|
|
159
|
+
const timer = win.setTimeout(() => {
|
|
160
|
+
finish(() => reject(new EmbeddedSignupError('timeout', 'The signup window was not completed in time')));
|
|
161
|
+
}, options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
162
|
+
win.addEventListener('message', onMessage);
|
|
163
|
+
report(options, 'opened');
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
exports.awaitSignupReturn = awaitSignupReturn;
|
|
167
|
+
/**
|
|
168
|
+
* The older driver, for a BSP app whose registered redirect is a page of yours:
|
|
169
|
+
* it waits for the code *and* the ids, which is what `/onboarding/exchange`
|
|
170
|
+
* takes. Call it **straight from a click handler**, as above.
|
|
171
|
+
*/
|
|
172
|
+
const openSignup = (url, options = {}) => {
|
|
173
|
+
const win = browser();
|
|
174
|
+
if (!win) {
|
|
175
|
+
return Promise.reject(new EmbeddedSignupError('unsupported_environment', 'Embedded signup needs a browser; drive the three onboarding calls yourself outside one'));
|
|
176
|
+
}
|
|
177
|
+
const popup = openPopup(win, url, options);
|
|
178
|
+
if (!popup) {
|
|
179
|
+
return Promise.reject(new EmbeddedSignupError('popup_blocked', 'The signup window was blocked; allow popups and try again'));
|
|
180
|
+
}
|
|
181
|
+
return new Promise((resolve, reject) => {
|
|
182
|
+
let code;
|
|
183
|
+
let state;
|
|
184
|
+
let wabaId;
|
|
185
|
+
let phoneNumberId;
|
|
186
|
+
let settled = false;
|
|
187
|
+
const progress = (phase, step) => {
|
|
188
|
+
try {
|
|
189
|
+
options.onProgress?.({ phase, step });
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
// A console's callback is not allowed to break the flow.
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const finish = (outcome) => {
|
|
196
|
+
if (settled)
|
|
197
|
+
return;
|
|
198
|
+
settled = true;
|
|
199
|
+
win.removeEventListener('message', onMessage);
|
|
200
|
+
win.clearInterval(poll);
|
|
201
|
+
win.clearTimeout(timer);
|
|
202
|
+
// On success too: the console is about to render that confirmation properly.
|
|
203
|
+
try {
|
|
204
|
+
if (!popup.closed)
|
|
205
|
+
popup.close();
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
// Cross-origin as it closed; the window is the user's problem now.
|
|
209
|
+
}
|
|
210
|
+
outcome();
|
|
211
|
+
};
|
|
212
|
+
/** Resolves only once both halves are in. */
|
|
213
|
+
const settleIfComplete = () => {
|
|
214
|
+
if (code && state && wabaId && phoneNumberId) {
|
|
215
|
+
const credentials = { code, state, wabaId, phoneNumberId };
|
|
216
|
+
finish(() => resolve(credentials));
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
const onMessage = (event) => {
|
|
220
|
+
// Our own redirect page posting back, rather than the poll reading its URL.
|
|
221
|
+
// It may hold all three, so it can finish the flow on its own.
|
|
222
|
+
if (event.origin === win.location.origin) {
|
|
223
|
+
const returned = fromSameOrigin(event.data);
|
|
224
|
+
if (returned) {
|
|
225
|
+
const error = str(returned.error) ?? str(returned.error_description);
|
|
226
|
+
if (error) {
|
|
227
|
+
finish(() => reject(new EmbeddedSignupError('signup_error', error)));
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
code = str(returned.code) ?? code;
|
|
231
|
+
state = str(returned.state) ?? state;
|
|
232
|
+
wabaId = str(returned.waba_id) ?? wabaId;
|
|
233
|
+
phoneNumberId = str(returned.phone_number_id) ?? phoneNumberId;
|
|
234
|
+
if (code)
|
|
235
|
+
progress('code');
|
|
236
|
+
if (wabaId && phoneNumberId)
|
|
237
|
+
progress('ids');
|
|
238
|
+
settleIfComplete();
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const payload = parsePayload(event.data);
|
|
243
|
+
if (!payload)
|
|
244
|
+
return;
|
|
245
|
+
if (!META_ORIGINS.includes(event.origin))
|
|
246
|
+
return;
|
|
247
|
+
if (payload.type !== 'WA_EMBEDDED_SIGNUP')
|
|
248
|
+
return;
|
|
249
|
+
const data = (payload.data ?? {});
|
|
250
|
+
// Backing out is not worth a stack trace, but it has to reject or the
|
|
251
|
+
// promise never settles.
|
|
252
|
+
if (payload.event === 'CANCEL') {
|
|
253
|
+
const step = typeof data.current_step === 'string' ? data.current_step : undefined;
|
|
254
|
+
finish(() => reject(new EmbeddedSignupError('cancelled', step ? `Signup was cancelled at the "${step}" step` : 'Signup was cancelled')));
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (payload.event === 'ERROR') {
|
|
258
|
+
const message = typeof data.error_message === 'string' ? data.error_message : 'Meta reported an error';
|
|
259
|
+
finish(() => reject(new EmbeddedSignupError('signup_error', message)));
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
// Only a finish event carries the ids; the rest are step changes.
|
|
263
|
+
if (FINISH_EVENTS.includes(String(payload.event))) {
|
|
264
|
+
wabaId = str(data.waba_id) ?? wabaId;
|
|
265
|
+
phoneNumberId = str(data.phone_number_id) ?? phoneNumberId;
|
|
266
|
+
}
|
|
267
|
+
if (wabaId && phoneNumberId)
|
|
268
|
+
progress('ids');
|
|
269
|
+
else if (typeof data.current_step === 'string')
|
|
270
|
+
progress('step', data.current_step);
|
|
271
|
+
settleIfComplete();
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* Same-origin once the dialog redirects to our `redirect_uri`; before that
|
|
275
|
+
* reading `location` throws. Also the only signal that the window was closed.
|
|
276
|
+
*/
|
|
277
|
+
const poll = win.setInterval(() => {
|
|
278
|
+
if (popup.closed) {
|
|
279
|
+
finish(() => reject(new EmbeddedSignupError('popup_closed', code || wabaId
|
|
280
|
+
? 'The signup window was closed before it finished'
|
|
281
|
+
: 'The signup window was closed')));
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
if (code && wabaId && phoneNumberId)
|
|
285
|
+
return;
|
|
286
|
+
try {
|
|
287
|
+
const returned = popup.location.search ? fromSameOrigin(popup.location.search) : undefined;
|
|
288
|
+
if (!returned)
|
|
289
|
+
return;
|
|
290
|
+
// A refusal arrives here and never as a message; without this the popup
|
|
291
|
+
// just sits there.
|
|
292
|
+
const error = str(returned.error) ?? str(returned.error_description);
|
|
293
|
+
if (error) {
|
|
294
|
+
finish(() => reject(new EmbeddedSignupError('signup_error', error)));
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (!returned.code)
|
|
298
|
+
return;
|
|
299
|
+
code = str(returned.code) ?? code;
|
|
300
|
+
state = str(returned.state) ?? state;
|
|
301
|
+
wabaId = str(returned.waba_id) ?? wabaId;
|
|
302
|
+
phoneNumberId = str(returned.phone_number_id) ?? phoneNumberId;
|
|
303
|
+
progress('code');
|
|
304
|
+
settleIfComplete();
|
|
305
|
+
}
|
|
306
|
+
catch {
|
|
307
|
+
// Still on Meta's origin, so there is nothing to read yet.
|
|
308
|
+
}
|
|
309
|
+
}, 400);
|
|
310
|
+
const timer = win.setTimeout(() => {
|
|
311
|
+
finish(() => reject(new EmbeddedSignupError('timeout', 'The signup window was not completed in time')));
|
|
312
|
+
}, options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
313
|
+
win.addEventListener('message', onMessage);
|
|
314
|
+
progress('opened');
|
|
315
|
+
});
|
|
316
|
+
};
|
|
317
|
+
exports.openSignup = openSignup;
|
|
318
|
+
//# sourceMappingURL=embedded-signup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedded-signup.js","sourceRoot":"","sources":["../../src/internal/embedded-signup.ts"],"names":[],"mappings":";;;AAsBA,uEAAuE;AACvE,MAAa,mBAAoB,SAAQ,KAAK;IAEjC;IASA;IAVX,YACW,IAMI,EACb,OAAe;IACf,4EAA4E;IACnE,MAAe;QAExB,KAAK,CAAC,OAAO,CAAC,CAAC;QAXN,SAAI,GAAJ,IAAI,CAMA;QAGJ,WAAM,GAAN,MAAM,CAAS;QAGxB,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAhBD,kDAgBC;AAED,qFAAqF;AACrF,MAAM,aAAa,GAAG,CAAC,QAAQ,EAAE,yCAAyC,CAAC,CAAC;AAE5E,iDAAiD;AACjD,MAAM,YAAY,GAAG,CAAC,0BAA0B,EAAE,0BAA0B,EAAE,+BAA+B,CAAC,CAAC;AAE/G,MAAM,kBAAkB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAoB1C,MAAM,OAAO,GAAG,GAA8B,EAAE;IAC9C,MAAM,SAAS,GAAI,UAAmC,CAAC,MAAmC,CAAC;IAC3F,OAAO,SAAS,IAAI,OAAO,SAAS,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AACnF,CAAC,CAAC;AAEF,yDAAyD;AACzD,MAAM,YAAY,GAAG,CAAC,IAAa,EAAuC,EAAE;IAC1E,IAAI,OA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,QAAQ,CAAC,IAAI;oBAAE,OAAO;gBAE3B,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;gBAClC,KAAK,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;gBACrC,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC;gBACzC,aAAa,GAAG,GAAG,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,aAAa,CAAC;gBAC/D,QAAQ,CAAC,MAAM,CAAC,CAAC;gBACjB,gBAAgB,EAAE,CAAC;YACrB,CAAC;YAAC,MAAM,CAAC;gBACP,2DAA2D;YAC7D,CAAC;QACH,CAAC,EAAE,GAAG,CAAC,CAAC;QAER,MAAM,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,EAAE;YAChC,MAAM,CAAC,GAAG,EAAE,CACV,MAAM,CAAC,IAAI,mBAAmB,CAAC,SAAS,EAAE,6CAA6C,CAAC,CAAC,CAC1F,CAAC;QACJ,CAAC,EAAE,OAAO,CAAC,SAAS,IAAI,kBAAkB,CAAC,CAAC;QAE5C,GAAG,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAC3C,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AArLW,QAAA,UAAU,cAqLrB"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { ChannelOnboardingOption, ChannelResponse, CompleteOnboardingInput, OnboardingChannelType, OnboardingExchangeInput, OnboardingExchangeResult, OnboardingPendingResult, OnboardingUrlInput, OnboardingUrlResult } from '../../types';
|
|
2
|
+
import type { HttpClient } from '../../http';
|
|
3
|
+
import { type OpenSignupOptions } from '../../internal/embedded-signup';
|
|
4
|
+
/** Options for the one-call driver. */
|
|
5
|
+
export interface ConnectOptions extends OpenSignupOptions {
|
|
6
|
+
/** Which family to connect. Only `whatsapp` today, and the default. */
|
|
7
|
+
type?: OnboardingChannelType;
|
|
8
|
+
/** The inclusion to spend, when the plan carries more than one. */
|
|
9
|
+
slug?: string;
|
|
10
|
+
/** The BSP to connect through, by provider code. Omit for the active one. */
|
|
11
|
+
provider?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Where the popup is handed back to. **Required**, and it has to be a page on
|
|
14
|
+
* this page's own origin -- that is what makes the outcome readable from here.
|
|
15
|
+
*/
|
|
16
|
+
redirectUri: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Connecting a channel. The browser only runs Meta's dialog: Meta returns to
|
|
20
|
+
* the service's callback, which redeems the code and sends the browser back to
|
|
21
|
+
* `redirectUri` with a `status` and a `token` -- no credential reaches this
|
|
22
|
+
* page. `connect()` drives all of it; or call `url()`, open the dialog
|
|
23
|
+
* yourself, and read the return off your own landing page.
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* // In the click handler for "Connect WhatsApp" -- not after an await.
|
|
27
|
+
* const candidate = await crm.channelOnboarding.connect({
|
|
28
|
+
* redirectUri: 'https://console.example.com/channels/connected',
|
|
29
|
+
* });
|
|
30
|
+
* // One number, or several to choose between: candidate.numbers
|
|
31
|
+
* const { data: channel } = await crm.channelOnboarding.complete({
|
|
32
|
+
* token: candidate.id,
|
|
33
|
+
* phoneNumberId: chosen.id,
|
|
34
|
+
* name: form.name,
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare class ChannelOnboarding {
|
|
39
|
+
private readonly http;
|
|
40
|
+
constructor(http: HttpClient);
|
|
41
|
+
/**
|
|
42
|
+
* `GET /v1/channels/onboarding/types` -- the families this caller can connect
|
|
43
|
+
* right now. Anything the plan, the provider record or their role rules out is
|
|
44
|
+
* left out, so an empty list means "nothing to offer". Scope: `channels:read`.
|
|
45
|
+
*/
|
|
46
|
+
types(): Promise<{
|
|
47
|
+
data: ChannelOnboardingOption[];
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* `POST /v1/channels/onboarding/url` -- the page to open. **Meta refuses to
|
|
51
|
+
* be framed**: use a popup, or navigate. 402 if the plan has no room.
|
|
52
|
+
*
|
|
53
|
+
* `url` is a launcher on the app's own domain that forwards to the dialog
|
|
54
|
+
* (`dialogUrl`); `redirectUri` is where *we* return the browser, not what
|
|
55
|
+
* Meta is given -- that is `callbackUri`.
|
|
56
|
+
*/
|
|
57
|
+
url(input: OnboardingUrlInput): Promise<{
|
|
58
|
+
data: OnboardingUrlResult;
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* `GET /v1/channels/onboarding/pending/:token` -- what the return URL's
|
|
62
|
+
* `token` refers to: the numbers it covers, and the form's prefill.
|
|
63
|
+
*/
|
|
64
|
+
pending(token: string): Promise<{
|
|
65
|
+
data: OnboardingPendingResult;
|
|
66
|
+
}>;
|
|
67
|
+
/**
|
|
68
|
+
* `POST /v1/channels/onboarding/exchange` -- redeems a code you hold yourself,
|
|
69
|
+
* for a BSP app whose registered redirect is a page of yours rather than the
|
|
70
|
+
* service's callback. **Creates nothing**: show `phoneNumber` and confirm.
|
|
71
|
+
*/
|
|
72
|
+
exchange(input: OnboardingExchangeInput): Promise<{
|
|
73
|
+
data: OnboardingExchangeResult;
|
|
74
|
+
}>;
|
|
75
|
+
/**
|
|
76
|
+
* `POST /v1/channels/onboarding/complete` -- creates the channel, **inactive**:
|
|
77
|
+
* `setProp(id, 'wa_pin_update')` brings it up, or `wa_biz_update` for a WA Biz number.
|
|
78
|
+
*/
|
|
79
|
+
complete(input: CompleteOnboardingInput): Promise<ChannelResponse>;
|
|
80
|
+
/**
|
|
81
|
+
* The URL, the dialog, and the record the callback leaves behind, in one call.
|
|
82
|
+
* **Call it straight from the click handler**, or the popup is blocked.
|
|
83
|
+
* Rejects with `EmbeddedSignupError`; `reason` carries the service's own code.
|
|
84
|
+
*
|
|
85
|
+
* What comes back is a *candidate* -- nothing exists until `complete()`, and
|
|
86
|
+
* if it holds several numbers the person picks one.
|
|
87
|
+
*/
|
|
88
|
+
connect(options: ConnectOptions): Promise<OnboardingPendingResult>;
|
|
89
|
+
}
|