ab-ecosystem-cpass 1.0.11 → 1.0.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.
Files changed (37) hide show
  1. package/README.md +1 -0
  2. package/dist/client.d.ts +6 -0
  3. package/dist/client.js +7 -0
  4. package/dist/client.js.map +1 -1
  5. package/dist/index.d.ts +3 -0
  6. package/dist/index.js +7 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/internal/embedded-signup.d.ts +29 -0
  9. package/dist/internal/embedded-signup.js +175 -0
  10. package/dist/internal/embedded-signup.js.map +1 -0
  11. package/dist/resources/channels/onboarding.d.ts +62 -0
  12. package/dist/resources/channels/onboarding.js +76 -0
  13. package/dist/resources/channels/onboarding.js.map +1 -0
  14. package/dist/types/channels.d.ts +79 -0
  15. package/docs/audience/canned-replies.md +3 -0
  16. package/docs/audience/contact-tags.md +4 -0
  17. package/docs/audience/contacts.md +23 -0
  18. package/docs/audience/crm-triggers.md +3 -0
  19. package/docs/audience/custom-fields.md +23 -0
  20. package/docs/audience/exports.md +6 -0
  21. package/docs/audience/imports.md +7 -0
  22. package/docs/audience/notifications.md +11 -0
  23. package/docs/audience/scheduled-messages.md +5 -0
  24. package/docs/audience/segments.md +4 -0
  25. package/docs/audience/webhooks.md +7 -0
  26. package/docs/campaign/campaigns.md +20 -0
  27. package/docs/channels/activity.md +3 -0
  28. package/docs/channels/billing.md +2 -0
  29. package/docs/channels/channel-props.md +19 -0
  30. package/docs/channels/channels.md +34 -2
  31. package/docs/channels/onboarding.md +324 -0
  32. package/docs/channels/templates.md +22 -0
  33. package/docs/channels/wallet.md +2 -0
  34. package/docs/channels/webhooks.md +6 -0
  35. package/docs/data-store.md +18 -0
  36. package/docs/inbox/connection.md +88 -0
  37. 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` `exchange` `complete` `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);
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,iCAAwD;AAExD,WAAW;AACX,4DAAyD;AACzD,oEAAgE;AAChE,sEAAkE;AAClE,wEAAoE;AACpE,sEAAkE;AAClE,4DAAyD;AACzD,oEAAgE;AAChE,wEAA8D;AAC9D,wEAA8D;AAC9D,4DAAyD;AACzD,gFAA4E;AAC5E,kEAA8D;AAC9D,sEAAmE;AACnE,yDAIiC;AAEjC,WAAW;AACX,4DAAyD;AACzD,8DAA2D;AAC3D,4DAAgE;AAChE,0DAAuD;AACvD,wDAAqD;AACrD,4DAAyD;AAEzD,WAAW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VERS, 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 driver on its own, for a console that calls `url()` itself. */
30
+ export { 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.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,12 @@ 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 driver on its own, for a console that calls `url()` itself. */
77
+ var embedded_signup_1 = require("./internal/embedded-signup");
78
+ Object.defineProperty(exports, "openSignup", { enumerable: true, get: function () { return embedded_signup_1.openSignup; } });
79
+ Object.defineProperty(exports, "EmbeddedSignupError", { enumerable: true, get: function () { return embedded_signup_1.EmbeddedSignupError; } });
74
80
  var templates_1 = require("./resources/channels/templates");
75
81
  Object.defineProperty(exports, "Templates", { enumerable: true, get: function () { return templates_1.Templates; } });
76
82
  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,6GAA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dialog answers in two halves -- the code on the redirect, the ids by
4
+ * `postMessage` -- and neither is usable alone, so `openSignup` waits for both.
5
+ */
6
+ /** How the popup is opened, and how to follow its progress. */
7
+ export interface OpenSignupOptions {
8
+ /** Window name, so a second call reuses the popup rather than opening two. */
9
+ name?: string;
10
+ width?: number;
11
+ height?: number;
12
+ /** How long to wait for both halves. Default 15 minutes. */
13
+ timeoutMs?: number;
14
+ /** For a console showing more than a spinner. `step` is Meta's own `current_step`. */
15
+ onProgress?: (event: {
16
+ phase: 'opened' | 'step' | 'code' | 'ids';
17
+ step?: string;
18
+ }) => void;
19
+ }
20
+ /** Thrown for every way the dialog can fail to produce credentials. */
21
+ export declare class EmbeddedSignupError extends Error {
22
+ readonly code: 'unsupported_environment' | 'popup_blocked' | 'popup_closed' | 'cancelled' | 'signup_error' | 'timeout';
23
+ constructor(code: 'unsupported_environment' | 'popup_blocked' | 'popup_closed' | 'cancelled' | 'signup_error' | 'timeout', message: string);
24
+ }
25
+ /**
26
+ * Call this **straight from a click handler**: a `window.open` a browser does not
27
+ * attribute to a gesture is blocked, and that looks like the user's popup blocker.
28
+ */
29
+ export declare const openSignup: (url: string, options?: OpenSignupOptions) => Promise<SignupCredentials>;
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openSignup = exports.EmbeddedSignupError = void 0;
4
+ /** Thrown for every way the dialog can fail to produce credentials. */
5
+ class EmbeddedSignupError extends Error {
6
+ code;
7
+ constructor(code, message) {
8
+ super(message);
9
+ this.code = code;
10
+ this.name = 'EmbeddedSignupError';
11
+ }
12
+ }
13
+ exports.EmbeddedSignupError = EmbeddedSignupError;
14
+ /** Origins Meta posts the signup events from. */
15
+ const META_ORIGINS = ['https://www.facebook.com', 'https://web.facebook.com', 'https://business.facebook.com'];
16
+ const DEFAULT_TIMEOUT_MS = 15 * 60 * 1000;
17
+ const browser = () => {
18
+ const candidate = globalThis.window;
19
+ return candidate && typeof candidate.open === 'function' ? candidate : undefined;
20
+ };
21
+ /** An object in most browsers, a JSON string in some. */
22
+ const parsePayload = (data) => {
23
+ if (typeof data === 'string') {
24
+ try {
25
+ const parsed = JSON.parse(data);
26
+ return typeof parsed === 'object' && parsed !== null ? parsed : undefined;
27
+ }
28
+ catch {
29
+ return undefined;
30
+ }
31
+ }
32
+ return typeof data === 'object' && data !== null ? data : undefined;
33
+ };
34
+ /**
35
+ * Call this **straight from a click handler**: a `window.open` a browser does not
36
+ * attribute to a gesture is blocked, and that looks like the user's popup blocker.
37
+ */
38
+ const openSignup = (url, options = {}) => {
39
+ const win = browser();
40
+ if (!win) {
41
+ return Promise.reject(new EmbeddedSignupError('unsupported_environment', 'Embedded signup needs a browser; drive the three onboarding calls yourself outside one'));
42
+ }
43
+ const width = options.width ?? 620;
44
+ const height = options.height ?? 760;
45
+ const left = Math.max(0, ((win.screen?.width ?? width) - width) / 2);
46
+ const top = Math.max(0, ((win.screen?.height ?? height) - height) / 2);
47
+ const popup = win.open(url, options.name ?? 'wa_embedded_signup', `popup=1,width=${width},height=${height},left=${left},top=${top},scrollbars=1,resizable=1`);
48
+ if (!popup) {
49
+ return Promise.reject(new EmbeddedSignupError('popup_blocked', 'The signup window was blocked; allow popups and try again'));
50
+ }
51
+ return new Promise((resolve, reject) => {
52
+ let code;
53
+ let state;
54
+ let wabaId;
55
+ let phoneNumberId;
56
+ let settled = false;
57
+ const progress = (phase, step) => {
58
+ try {
59
+ options.onProgress?.({ phase, step });
60
+ }
61
+ catch {
62
+ // A console's callback is not allowed to break the flow.
63
+ }
64
+ };
65
+ const finish = (outcome) => {
66
+ if (settled)
67
+ return;
68
+ settled = true;
69
+ win.removeEventListener('message', onMessage);
70
+ win.clearInterval(poll);
71
+ win.clearTimeout(timer);
72
+ // On success too: the console is about to render that confirmation properly.
73
+ try {
74
+ if (!popup.closed)
75
+ popup.close();
76
+ }
77
+ catch {
78
+ // Cross-origin as it closed; the window is the user's problem now.
79
+ }
80
+ outcome();
81
+ };
82
+ /** Resolves only once both halves are in. */
83
+ const settleIfComplete = () => {
84
+ if (code && state && wabaId && phoneNumberId) {
85
+ const credentials = { code, state, wabaId, phoneNumberId };
86
+ finish(() => resolve(credentials));
87
+ }
88
+ };
89
+ const onMessage = (event) => {
90
+ const payload = parsePayload(event.data);
91
+ if (!payload)
92
+ return;
93
+ // Our own redirect page posting back, rather than the poll reading its URL.
94
+ if (event.origin === win.location.origin && payload.type === 'CRM_CHANNEL_ONBOARDING') {
95
+ if (typeof payload.code === 'string')
96
+ code = payload.code;
97
+ if (typeof payload.state === 'string')
98
+ state = payload.state;
99
+ if (code)
100
+ progress('code');
101
+ settleIfComplete();
102
+ return;
103
+ }
104
+ if (!META_ORIGINS.includes(event.origin))
105
+ return;
106
+ if (payload.type !== 'WA_EMBEDDED_SIGNUP')
107
+ return;
108
+ const data = (payload.data ?? {});
109
+ // Backing out is not worth a stack trace, but it has to reject or the
110
+ // promise never settles.
111
+ if (payload.event === 'CANCEL') {
112
+ const step = typeof data.current_step === 'string' ? data.current_step : undefined;
113
+ finish(() => reject(new EmbeddedSignupError('cancelled', step ? `Signup was cancelled at the "${step}" step` : 'Signup was cancelled')));
114
+ return;
115
+ }
116
+ if (payload.event === 'ERROR') {
117
+ const message = typeof data.error_message === 'string' ? data.error_message : 'Meta reported an error';
118
+ finish(() => reject(new EmbeddedSignupError('signup_error', message)));
119
+ return;
120
+ }
121
+ if (typeof data.waba_id === 'string')
122
+ wabaId = data.waba_id;
123
+ if (typeof data.phone_number_id === 'string')
124
+ phoneNumberId = data.phone_number_id;
125
+ if (wabaId && phoneNumberId)
126
+ progress('ids');
127
+ else if (typeof data.current_step === 'string')
128
+ progress('step', data.current_step);
129
+ settleIfComplete();
130
+ };
131
+ /**
132
+ * Same-origin once the dialog redirects to our `redirect_uri`; before that
133
+ * reading `location` throws. Also the only signal that the window was closed.
134
+ */
135
+ const poll = win.setInterval(() => {
136
+ if (popup.closed) {
137
+ finish(() => reject(new EmbeddedSignupError('popup_closed', code || wabaId
138
+ ? 'The signup window was closed before it finished'
139
+ : 'The signup window was closed')));
140
+ return;
141
+ }
142
+ if (code)
143
+ return;
144
+ try {
145
+ const search = popup.location.search;
146
+ if (!search)
147
+ return;
148
+ const params = new URLSearchParams(search);
149
+ const returned = params.get('code');
150
+ if (!returned) {
151
+ // A refusal arrives here and never as a message; without this the
152
+ // popup just sits there.
153
+ const error = params.get('error_description') ?? params.get('error');
154
+ if (error)
155
+ finish(() => reject(new EmbeddedSignupError('signup_error', error)));
156
+ return;
157
+ }
158
+ code = returned;
159
+ state = params.get('state') ?? state;
160
+ progress('code');
161
+ settleIfComplete();
162
+ }
163
+ catch {
164
+ // Still on Meta's origin, so there is nothing to read yet.
165
+ }
166
+ }, 400);
167
+ const timer = win.setTimeout(() => {
168
+ finish(() => reject(new EmbeddedSignupError('timeout', 'The signup window was not completed in time')));
169
+ }, options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
170
+ win.addEventListener('message', onMessage);
171
+ progress('opened');
172
+ });
173
+ };
174
+ exports.openSignup = openSignup;
175
+ //# sourceMappingURL=embedded-signup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embedded-signup.js","sourceRoot":"","sources":["../../src/internal/embedded-signup.ts"],"names":[],"mappings":";;;AAmBA,uEAAuE;AACvE,MAAa,mBAAoB,SAAQ,KAAK;IAEjC;IADX,YACW,IAMI,EACb,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QATN,SAAI,GAAJ,IAAI,CAMA;QAIb,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAdD,kDAcC;AAED,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,UA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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;AA3KW,QAAA,UAAU,cA2KrB"}
@@ -0,0 +1,62 @@
1
+ import type { ChannelOnboardingOption, ChannelResponse, CompleteOnboardingInput, OnboardingChannelType, OnboardingExchangeInput, OnboardingExchangeResult, 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
+ /** A non-default redirect, which must be one the service is configured for. */
11
+ redirectUri?: string;
12
+ }
13
+ /**
14
+ * Connecting a channel. `connect()` does steps 1 to 3 and hands back the number
15
+ * to confirm; or call `url()`, open the dialog yourself, then `exchange()`.
16
+ * Either way the browser never sees a Meta credential.
17
+ *
18
+ * ```ts
19
+ * // In the click handler for "Connect WhatsApp" -- not after an await.
20
+ * const candidate = await crm.channelOnboarding.connect();
21
+ * // Show candidate.phoneNumber, prefill a form from candidate.defaults...
22
+ * const { data: channel } = await crm.channelOnboarding.complete({
23
+ * token: candidate.id,
24
+ * name: form.name,
25
+ * });
26
+ * ```
27
+ */
28
+ export declare class ChannelOnboarding {
29
+ private readonly http;
30
+ constructor(http: HttpClient);
31
+ /**
32
+ * `GET /v1/channels/onboarding/types` -- every family, available or not, so a
33
+ * picker greys rows out. Check `available`, show `reason`. Scope: `channels:read`.
34
+ */
35
+ types(): Promise<{
36
+ data: ChannelOnboardingOption[];
37
+ }>;
38
+ /**
39
+ * `POST /v1/channels/onboarding/url` -- the dialog URL and the `state` to hand
40
+ * back. **Meta refuses to be framed**: use a popup. 402 if the plan has no room.
41
+ */
42
+ url(input?: OnboardingUrlInput): Promise<{
43
+ data: OnboardingUrlResult;
44
+ }>;
45
+ /**
46
+ * `POST /v1/channels/onboarding/exchange` -- redeems the code. **Creates
47
+ * nothing**: show `phoneNumber`, Meta's own description, and let them confirm.
48
+ */
49
+ exchange(input: OnboardingExchangeInput): Promise<{
50
+ data: OnboardingExchangeResult;
51
+ }>;
52
+ /**
53
+ * `POST /v1/channels/onboarding/complete` -- creates the channel, **inactive**:
54
+ * `setProp(id, 'wa_pin_update')` brings it up, or `wa_biz_update` for a WA Biz number.
55
+ */
56
+ complete(input: CompleteOnboardingInput): Promise<ChannelResponse>;
57
+ /**
58
+ * The URL, the dialog and the exchange in one call. **Call it straight from the
59
+ * click handler**, or the popup is blocked. Rejects with `EmbeddedSignupError`.
60
+ */
61
+ connect(options?: ConnectOptions): Promise<OnboardingExchangeResult>;
62
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChannelOnboarding = void 0;
4
+ const paths_1 = require("../paths");
5
+ const embedded_signup_1 = require("../../internal/embedded-signup");
6
+ const ONBOARDING = `${paths_1.CHANNELS}/onboarding`;
7
+ /**
8
+ * Connecting a channel. `connect()` does steps 1 to 3 and hands back the number
9
+ * to confirm; or call `url()`, open the dialog yourself, then `exchange()`.
10
+ * Either way the browser never sees a Meta credential.
11
+ *
12
+ * ```ts
13
+ * // In the click handler for "Connect WhatsApp" -- not after an await.
14
+ * const candidate = await crm.channelOnboarding.connect();
15
+ * // Show candidate.phoneNumber, prefill a form from candidate.defaults...
16
+ * const { data: channel } = await crm.channelOnboarding.complete({
17
+ * token: candidate.id,
18
+ * name: form.name,
19
+ * });
20
+ * ```
21
+ */
22
+ class ChannelOnboarding {
23
+ http;
24
+ constructor(http) {
25
+ this.http = http;
26
+ }
27
+ /**
28
+ * `GET /v1/channels/onboarding/types` -- every family, available or not, so a
29
+ * picker greys rows out. Check `available`, show `reason`. Scope: `channels:read`.
30
+ */
31
+ types() {
32
+ return this.http.request('GET', `${ONBOARDING}/types`);
33
+ }
34
+ /**
35
+ * `POST /v1/channels/onboarding/url` -- the dialog URL and the `state` to hand
36
+ * back. **Meta refuses to be framed**: use a popup. 402 if the plan has no room.
37
+ */
38
+ url(input = {}) {
39
+ return this.http.request('POST', `${ONBOARDING}/url`, { body: input });
40
+ }
41
+ /**
42
+ * `POST /v1/channels/onboarding/exchange` -- redeems the code. **Creates
43
+ * nothing**: show `phoneNumber`, Meta's own description, and let them confirm.
44
+ */
45
+ exchange(input) {
46
+ return this.http.request('POST', `${ONBOARDING}/exchange`, {
47
+ body: input,
48
+ });
49
+ }
50
+ /**
51
+ * `POST /v1/channels/onboarding/complete` -- creates the channel, **inactive**:
52
+ * `setProp(id, 'wa_pin_update')` brings it up, or `wa_biz_update` for a WA Biz number.
53
+ */
54
+ complete(input) {
55
+ return this.http.request('POST', `${ONBOARDING}/complete`, { body: input });
56
+ }
57
+ /**
58
+ * The URL, the dialog and the exchange in one call. **Call it straight from the
59
+ * click handler**, or the popup is blocked. Rejects with `EmbeddedSignupError`.
60
+ */
61
+ async connect(options = {}) {
62
+ const { type, slug, redirectUri, ...popup } = options;
63
+ const { data: session } = await this.url({ type, slug, redirectUri });
64
+ const credentials = await (0, embedded_signup_1.openSignup)(session.url, popup);
65
+ const { data } = await this.exchange({
66
+ // The one we issued, since the dialog may or may not return it.
67
+ state: session.state,
68
+ code: credentials.code,
69
+ wabaId: credentials.wabaId,
70
+ phoneNumberId: credentials.phoneNumberId,
71
+ });
72
+ return data;
73
+ }
74
+ }
75
+ exports.ChannelOnboarding = ChannelOnboarding;
76
+ //# sourceMappingURL=onboarding.js.map
@@ -0,0 +1 @@
1
+ {"version":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,WAAW,GAAsB,MAAM,IAAA,4BAAU,EAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAE5E,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC;YACnC,gEAAgE;YAChE,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,MAAM,EAAE,WAAW,CAAC,MAAM;YAC1B,aAAa,EAAE,WAAW,CAAC,aAAa;SACzC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAzDD,8CAyDC"}
@@ -381,3 +381,82 @@ export interface ListActivityLogsQuery extends ListQuery {
381
381
  /** Restrict to a period. */
382
382
  range?: UnixRange;
383
383
  }
384
+ /** Channel families the onboarding endpoints can connect today. */
385
+ export type OnboardingChannelType = 'whatsapp';
386
+ /** Every family the picker shows, implemented or not. */
387
+ export type OfferableChannelType = 'whatsapp' | 'facebook' | 'instagram';
388
+ /** Why a family cannot be connected right now. */
389
+ export type OnboardingUnavailableReason = 'not_included' | 'quota_exceeded' | 'not_supported' | 'provider_not_configured' | 'not_permitted';
390
+ /** One row of the "add a channel" picker. */
391
+ export interface ChannelOnboardingOption {
392
+ type: OfferableChannelType;
393
+ label: string;
394
+ available: boolean;
395
+ /** The inclusion a channel would be created against. Pass back to `url()`. */
396
+ slug?: string;
397
+ limit?: number;
398
+ used?: number;
399
+ remaining?: number;
400
+ /** Set only when `available` is false. */
401
+ reason?: OnboardingUnavailableReason;
402
+ }
403
+ export interface OnboardingUrlInput {
404
+ type?: OnboardingChannelType;
405
+ /** Only needed when the plan carries more than one channel inclusion. */
406
+ slug?: string;
407
+ /** Must be one of the service's configured redirects. Omit for the default. */
408
+ redirectUri?: string;
409
+ }
410
+ export interface OnboardingUrlResult {
411
+ /** Open in a popup. Meta refuses to render the dialog in an iframe. */
412
+ url: string;
413
+ /** Opaque; hand back to `exchange()` unchanged. */
414
+ state: string;
415
+ redirectUri: string;
416
+ expiresAt: IsoDate;
417
+ provider: string;
418
+ remaining?: number;
419
+ }
420
+ /** What Meta reports about the number, for the confirmation card. */
421
+ export interface OnboardingPhoneNumber {
422
+ id: string;
423
+ wabaId: string;
424
+ /** Formatted, e.g. `+91 93116 36081`. */
425
+ displayPhoneNumber: string;
426
+ verifiedName: string;
427
+ status?: string;
428
+ codeVerificationStatus?: string;
429
+ qualityRating?: string;
430
+ }
431
+ export interface OnboardingExchangeInput {
432
+ state: string;
433
+ code: string;
434
+ wabaId: string;
435
+ phoneNumberId: string;
436
+ }
437
+ export interface OnboardingExchangeResult {
438
+ /** The pending record's id. Pass to `complete()` as `token`. */
439
+ id: string;
440
+ expiresAt: IsoDate;
441
+ phoneNumber: OnboardingPhoneNumber;
442
+ /** Prefill for the final form. */
443
+ defaults: {
444
+ name: string;
445
+ color: string;
446
+ currency: ChannelCurrency;
447
+ };
448
+ }
449
+ export interface CompleteOnboardingInput {
450
+ /** The `id` from `exchange()`. */
451
+ token: string;
452
+ name: string;
453
+ color?: string;
454
+ currency?: ChannelCurrency;
455
+ }
456
+ /** What the Meta dialog hands back, once both halves of it have arrived. */
457
+ export interface SignupCredentials {
458
+ code: string;
459
+ state: string;
460
+ wabaId: string;
461
+ phoneNumberId: string;
462
+ }
@@ -22,6 +22,9 @@ Two kinds, and the difference is who gets the last word:
22
22
  | [`update`](#update) | `PATCH /v1/audience/canned-replies/:reply` | `canned_replies:write` |
23
23
  | [`delete`](#delete) | `DELETE /v1/audience/canned-replies/:reply` | `canned_replies:write` |
24
24
 
25
+ **Permissions** — `CRM.CHAT.CANNED_REPLY`: `LIST`, `READ`, `CREATE`, `UPDATE`,
26
+ `DELETE`. Account-level, so `data_scope` does not narrow it.
27
+
25
28
  ## Addressing a reply: `:reply` is an id **or** a name
26
29
 
27
30
  A 24-hex-character path segment is read as an **id**; anything else as a
@@ -14,6 +14,10 @@ tag **ids** on a write, and hands back the full tag documents resolved into
14
14
  | [`update`](#update) | `PATCH /v1/audience/contact-tags/:id` | `contact_tags:write` |
15
15
  | [`delete`](#delete) | `DELETE /v1/audience/contact-tags/:id` | `contact_tags:write` |
16
16
 
17
+ **Permissions** — `CRM.CONTACT.TAG`: `LIST` to list, `READ` to read one,
18
+ `CREATE`, `UPDATE`, `DELETE`. A tag is account-level, so a role's `data_scope`
19
+ does not narrow this list — a member who holds `LIST` sees the account's tags.
20
+
17
21
  ## The tag object
18
22
 
19
23
  ```ts
@@ -19,6 +19,29 @@ land on the caller's own.
19
19
  | [`delete`](#delete) | `DELETE /v1/audience/contacts/:id` | `contacts:write` |
20
20
  | [`iterate`](#iterate) | — (walks `list`) | `contacts:read` |
21
21
 
22
+ **Permissions** — each route also names a permission key, and a team member
23
+ needs it. An owner does not.
24
+
25
+ | Action | Key |
26
+ | --- | --- |
27
+ | `list` | `CRM.CONTACT.LIST` |
28
+ | `get` | `CRM.CONTACT.READ` |
29
+ | `create` | `CRM.CONTACT.CREATE` |
30
+ | `update` | `CRM.CONTACT.UPDATE` |
31
+ | `delete` | `CRM.CONTACT.DELETE` |
32
+
33
+ A refusal is `403` with code `A403` (the role does not hold the key) or `E403`
34
+ (the account's plan does not cover contacts — `details.feature` names it). An
35
+ owner can meet `E403` but never `A403`.
36
+
37
+ Separately from that, how many contacts a member can see is their role's
38
+ `data_scope`: `own` — the default — returns the contacts assigned to them as
39
+ `agent`, and `all` returns the account's. A contact assigned to nobody is the
40
+ account's and not visible to an `own`-scoped member. Reading, updating or
41
+ deleting a contact outside that scope is `404`, never `403`: a `403` would
42
+ confirm the contact exists, which is what the scope is hiding.
43
+
44
+
22
45
  ## The contact object
23
46
 
24
47
  ```ts
@@ -25,6 +25,9 @@ mean on the list.
25
25
  | [`delete`](#delete) | `DELETE /v1/audience/crm-triggers/:id` | `crm_triggers:write` |
26
26
  | [`logs`](#logs) | `GET /v1/audience/crm-triggers/logs` | `crm_triggers:read` |
27
27
 
28
+ **Permissions** — `CRM.TRIGGER`: `LIST`, `READ` (one trigger, and the log
29
+ endpoint), `CREATE`, `UPDATE`, `DELETE`.
30
+
28
31
  ## The trigger object
29
32
 
30
33
  ```ts