@wats/graph 0.3.2 → 0.3.4
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 +32 -1
- package/dist/endpoints/businessManagement.d.ts +144 -0
- package/dist/endpoints/businessManagement.js +273 -1
- package/dist/endpoints/calling.d.ts +3 -0
- package/dist/endpoints/flows.d.ts +3 -0
- package/dist/endpoints/messages/builders-basic.d.ts +11 -0
- package/dist/endpoints/messages/builders-basic.js +272 -0
- package/dist/endpoints/messages/builders-interactive.d.ts +11 -0
- package/dist/endpoints/messages/builders-interactive.js +156 -0
- package/dist/endpoints/messages/builders-template.d.ts +3 -0
- package/dist/endpoints/messages/builders-template.js +121 -0
- package/dist/endpoints/messages/callables.d.ts +31 -0
- package/dist/endpoints/messages/callables.js +57 -0
- package/dist/endpoints/messages/index.d.ts +6 -0
- package/dist/endpoints/messages/index.js +56 -0
- package/dist/endpoints/messages/types.d.ts +363 -0
- package/dist/endpoints/messages/types.js +0 -0
- package/dist/endpoints/messages/validation.d.ts +43 -0
- package/dist/endpoints/messages/validation.js +277 -0
- package/dist/endpoints/messages.d.ts +1 -375
- package/dist/endpoints/messages.js +1 -675
- package/dist/endpoints/templates/builders.js +23 -0
- package/dist/endpoints/templates/callables.d.ts +1 -0
- package/dist/endpoints/templates/callables.js +4 -2
- package/dist/endpoints/templates/groups.d.ts +126 -0
- package/dist/endpoints/templates/groups.js +156 -0
- package/dist/endpoints/templates/index.d.ts +3 -1
- package/dist/endpoints/templates/index.js +8 -0
- package/dist/endpoints/templates/types.d.ts +14 -1
- package/dist/endpoints/templates.d.ts +2 -2
- package/dist/endpoints/templates.js +6 -0
- package/dist/endpoints/waba/phoneNumbers.d.ts +2 -0
- package/dist/endpoints/wabaEndpoints.d.ts +5 -2
- package/dist/endpoints/wabaEndpoints.js +6 -0
- package/dist/errorSubclasses.d.ts +28 -0
- package/dist/errorSubclasses.js +63 -0
- package/dist/subclients/phoneNumberClient.d.ts +18 -2
- package/dist/subclients/phoneNumberClient.js +72 -1
- package/dist/subclients/wabaClient.d.ts +15 -1
- package/dist/subclients/wabaClient.js +33 -0
- package/package.json +10 -1
package/README.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
1
|
# @wats/graph
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Graph client, transport seam, endpoint callables, typed Graph errors, pagination helpers, MockTransport, and WhatsApp endpoint-family helpers.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @wats/graph
|
|
9
|
+
npm i @wats/graph
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { GraphClient, createFetchTransport, sendMessage } from "@wats/graph";
|
|
16
|
+
|
|
17
|
+
const graph = new GraphClient({
|
|
18
|
+
accessToken: process.env.WATS_ACCESS_TOKEN ?? "",
|
|
19
|
+
apiVersion: "v25.0",
|
|
20
|
+
transport: createFetchTransport()
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
await sendMessage(graph, { phoneNumberId: "1234567890" }, {
|
|
24
|
+
messaging_product: "whatsapp",
|
|
25
|
+
to: "15551234567",
|
|
26
|
+
type: "text",
|
|
27
|
+
text: { body: "Hello from WATS" }
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Use `createMockTransport` from `@wats/graph/testing` for credential-free tests and examples. Some endpoint families are still expanding and should be treated according to the API stability policy.
|
|
32
|
+
|
|
33
|
+
Docs: https://github.com/Switchbord/wats
|
|
34
|
+
License: MIT
|
|
@@ -12,6 +12,8 @@ export interface WabaInfo {
|
|
|
12
12
|
readonly is_enabled_for_insights?: boolean;
|
|
13
13
|
readonly marketing_messages_lite_api_status?: string;
|
|
14
14
|
readonly marketing_messages_onboarding_status?: string;
|
|
15
|
+
/** WATS-91 / Graph v24+ portfolio-level messaging limit. */
|
|
16
|
+
readonly whatsapp_business_manager_messaging_limit?: string;
|
|
15
17
|
readonly ownership_type?: string;
|
|
16
18
|
readonly health_status?: unknown;
|
|
17
19
|
readonly currency?: string;
|
|
@@ -38,9 +40,15 @@ export interface PhoneNumberInfo {
|
|
|
38
40
|
readonly verified_name?: string;
|
|
39
41
|
readonly quality_rating?: string;
|
|
40
42
|
readonly code_verification_status?: string;
|
|
43
|
+
/** WATS-95 display-name certification status when requested via `fields=name_status`. */
|
|
44
|
+
readonly name_status?: string;
|
|
41
45
|
readonly platform_type?: string;
|
|
42
46
|
readonly throughput?: unknown;
|
|
43
47
|
readonly webhook_configuration?: unknown;
|
|
48
|
+
/** Graph phone-number field; v24+ semantics return the business-portfolio messaging limit. */
|
|
49
|
+
readonly messaging_limit_tier?: string;
|
|
50
|
+
/** WATS-91 / Graph v24+ explicit portfolio-level messaging limit field. */
|
|
51
|
+
readonly whatsapp_business_manager_messaging_limit?: string;
|
|
44
52
|
readonly [key: string]: unknown;
|
|
45
53
|
}
|
|
46
54
|
export interface PhoneNumberSettingsEntry {
|
|
@@ -101,6 +109,94 @@ export interface GetPhoneNumberSettingsInput {
|
|
|
101
109
|
/** Maps to Graph query parameter `include_sip_credentials`; responses may contain sensitive SIP credentials. */
|
|
102
110
|
readonly includeSipCredentials?: boolean;
|
|
103
111
|
}
|
|
112
|
+
export interface StorageConfigurationInput {
|
|
113
|
+
readonly status: "ENABLED" | "DISABLED" | string;
|
|
114
|
+
readonly [key: string]: unknown;
|
|
115
|
+
}
|
|
116
|
+
export interface UpdatePhoneNumberSettingsInput {
|
|
117
|
+
readonly phoneNumberId: string;
|
|
118
|
+
readonly storageConfiguration?: StorageConfigurationInput;
|
|
119
|
+
}
|
|
120
|
+
export interface PhoneNumberSettingsUpdateResponse {
|
|
121
|
+
readonly success?: boolean;
|
|
122
|
+
readonly [key: string]: unknown;
|
|
123
|
+
}
|
|
124
|
+
export interface BlockedUser {
|
|
125
|
+
readonly messaging_product?: string;
|
|
126
|
+
readonly wa_id?: string;
|
|
127
|
+
readonly [key: string]: unknown;
|
|
128
|
+
}
|
|
129
|
+
export interface BlockedUsersResponse {
|
|
130
|
+
readonly data?: readonly BlockedUser[];
|
|
131
|
+
readonly paging?: GraphPaging;
|
|
132
|
+
readonly [key: string]: unknown;
|
|
133
|
+
}
|
|
134
|
+
export interface BlockedUserOperation {
|
|
135
|
+
readonly input?: string;
|
|
136
|
+
readonly wa_id?: string;
|
|
137
|
+
readonly [key: string]: unknown;
|
|
138
|
+
}
|
|
139
|
+
export interface BlockUsersResponse {
|
|
140
|
+
readonly block_users?: {
|
|
141
|
+
readonly added_users?: readonly BlockedUserOperation[];
|
|
142
|
+
readonly [key: string]: unknown;
|
|
143
|
+
};
|
|
144
|
+
readonly messaging_product?: string;
|
|
145
|
+
readonly [key: string]: unknown;
|
|
146
|
+
}
|
|
147
|
+
export interface UnblockUsersResponse {
|
|
148
|
+
readonly block_users?: {
|
|
149
|
+
readonly removed_users?: readonly BlockedUserOperation[];
|
|
150
|
+
readonly [key: string]: unknown;
|
|
151
|
+
};
|
|
152
|
+
readonly messaging_product?: string;
|
|
153
|
+
readonly [key: string]: unknown;
|
|
154
|
+
}
|
|
155
|
+
export interface ListBlockedUsersInput {
|
|
156
|
+
readonly phoneNumberId: string;
|
|
157
|
+
}
|
|
158
|
+
export interface BlockUsersInput {
|
|
159
|
+
readonly phoneNumberId: string;
|
|
160
|
+
readonly users: readonly string[];
|
|
161
|
+
}
|
|
162
|
+
export interface UnblockUsersInput {
|
|
163
|
+
readonly phoneNumberId: string;
|
|
164
|
+
readonly users: readonly string[];
|
|
165
|
+
}
|
|
166
|
+
export interface OfficialBusinessAccountStatusResponse {
|
|
167
|
+
readonly id?: string;
|
|
168
|
+
readonly oba_status?: string;
|
|
169
|
+
readonly status_message?: string;
|
|
170
|
+
readonly [key: string]: unknown;
|
|
171
|
+
}
|
|
172
|
+
export interface GetOfficialBusinessAccountStatusInput {
|
|
173
|
+
readonly phoneNumberId: string;
|
|
174
|
+
readonly fields?: BusinessManagementFields;
|
|
175
|
+
}
|
|
176
|
+
export interface RequestOfficialBusinessAccountReviewInput {
|
|
177
|
+
readonly phoneNumberId: string;
|
|
178
|
+
readonly businessWebsiteUrl: string;
|
|
179
|
+
readonly primaryCountryOfOperation: string;
|
|
180
|
+
readonly primaryLanguage?: string;
|
|
181
|
+
readonly parentBusinessOrBrand?: string;
|
|
182
|
+
readonly supportingLinks?: readonly string[];
|
|
183
|
+
readonly additionalSupportingInformation?: string;
|
|
184
|
+
}
|
|
185
|
+
export interface OfficialBusinessAccountReviewResponse {
|
|
186
|
+
readonly success?: boolean;
|
|
187
|
+
readonly message?: string;
|
|
188
|
+
readonly updated_status?: OfficialBusinessAccountStatusResponse;
|
|
189
|
+
readonly tracking_id?: string;
|
|
190
|
+
readonly [key: string]: unknown;
|
|
191
|
+
}
|
|
192
|
+
export interface SubmitDisplayNameForReviewInput {
|
|
193
|
+
readonly phoneNumberId: string;
|
|
194
|
+
readonly newDisplayName: string;
|
|
195
|
+
}
|
|
196
|
+
export interface SubmitDisplayNameForReviewResponse {
|
|
197
|
+
readonly success?: boolean;
|
|
198
|
+
readonly [key: string]: unknown;
|
|
199
|
+
}
|
|
104
200
|
export interface GetBusinessProfileInput {
|
|
105
201
|
readonly phoneNumberId: string;
|
|
106
202
|
readonly fields?: BusinessManagementFields;
|
|
@@ -110,11 +206,23 @@ export interface GetCommerceSettingsInput {
|
|
|
110
206
|
readonly fields?: BusinessManagementFields;
|
|
111
207
|
}
|
|
112
208
|
type WireParams = Record<string, string>;
|
|
209
|
+
export declare function buildUpdatePhoneNumberSettingsBody(input: UpdatePhoneNumberSettingsInput): Record<string, unknown>;
|
|
210
|
+
export declare function normalizeUpdatePhoneNumberSettingsParams(input: UpdatePhoneNumberSettingsInput): WireParams;
|
|
113
211
|
export declare function normalizeWabaInfoParams(input: GetWabaInfoInput): WireParams;
|
|
114
212
|
export declare function normalizeListSubscribedAppsParams(input: ListSubscribedAppsInput): WireParams;
|
|
115
213
|
export declare function normalizeListPhoneNumbersParams(input: ListPhoneNumbersInput): WireParams;
|
|
116
214
|
export declare function normalizePhoneNumberInfoParams(input: GetPhoneNumberInfoInput): WireParams;
|
|
117
215
|
export declare function normalizePhoneNumberSettingsParams(input: GetPhoneNumberSettingsInput): WireParams;
|
|
216
|
+
export declare function normalizeListBlockedUsersParams(input: ListBlockedUsersInput): WireParams;
|
|
217
|
+
export declare function buildBlockUsersBody(input: BlockUsersInput | UnblockUsersInput): Record<string, unknown>;
|
|
218
|
+
export declare function normalizeBlockUsersParams(input: BlockUsersInput): WireParams;
|
|
219
|
+
export declare function buildUnblockUsersBody(input: UnblockUsersInput): Record<string, unknown>;
|
|
220
|
+
export declare function normalizeUnblockUsersParams(input: UnblockUsersInput): WireParams;
|
|
221
|
+
export declare function normalizeOfficialBusinessAccountStatusParams(input: GetOfficialBusinessAccountStatusInput): WireParams;
|
|
222
|
+
export declare function buildOfficialBusinessAccountReviewBody(input: RequestOfficialBusinessAccountReviewInput): Record<string, unknown>;
|
|
223
|
+
export declare function normalizeOfficialBusinessAccountReviewParams(input: RequestOfficialBusinessAccountReviewInput): WireParams;
|
|
224
|
+
export declare function buildDisplayNameReviewBody(input: SubmitDisplayNameForReviewInput): Record<string, unknown>;
|
|
225
|
+
export declare function normalizeDisplayNameReviewParams(input: SubmitDisplayNameForReviewInput): WireParams;
|
|
118
226
|
export declare function normalizeBusinessProfileParams(input: GetBusinessProfileInput): WireParams;
|
|
119
227
|
export declare function normalizeCommerceSettingsParams(input: GetCommerceSettingsInput): WireParams;
|
|
120
228
|
export declare function sanitizeBusinessManagementOptions(opts: EndpointInvokeOptions | undefined, helperName: string): EndpointInvokeOptions | undefined;
|
|
@@ -142,6 +250,42 @@ export declare const getPhoneNumberSettings: ((client: GraphClient, params: GetP
|
|
|
142
250
|
include_sip_credentials?: string;
|
|
143
251
|
}, never, PhoneNumberSettingsResponse>;
|
|
144
252
|
};
|
|
253
|
+
export declare const updatePhoneNumberSettings: ((client: GraphClient, params: UpdatePhoneNumberSettingsInput, body?: never, opts?: EndpointInvokeOptions) => Promise<PhoneNumberSettingsUpdateResponse>) & {
|
|
254
|
+
definition: import("../endpoint.js").EndpointDefinition<{
|
|
255
|
+
phoneNumberId: string;
|
|
256
|
+
}, UpdatePhoneNumberSettingsInput, PhoneNumberSettingsUpdateResponse>;
|
|
257
|
+
};
|
|
258
|
+
export declare const listBlockedUsers: ((client: GraphClient, params: ListBlockedUsersInput, body?: never, opts?: EndpointInvokeOptions) => Promise<BlockedUsersResponse>) & {
|
|
259
|
+
definition: import("../endpoint.js").EndpointDefinition<{
|
|
260
|
+
phoneNumberId: string;
|
|
261
|
+
}, never, BlockedUsersResponse>;
|
|
262
|
+
};
|
|
263
|
+
export declare const blockUsers: ((client: GraphClient, params: BlockUsersInput, body?: never, opts?: EndpointInvokeOptions) => Promise<BlockUsersResponse>) & {
|
|
264
|
+
definition: import("../endpoint.js").EndpointDefinition<{
|
|
265
|
+
phoneNumberId: string;
|
|
266
|
+
}, BlockUsersInput, BlockUsersResponse>;
|
|
267
|
+
};
|
|
268
|
+
export declare const unblockUsers: ((client: GraphClient, params: UnblockUsersInput, body?: never, opts?: EndpointInvokeOptions) => Promise<UnblockUsersResponse>) & {
|
|
269
|
+
definition: import("../endpoint.js").EndpointDefinition<{
|
|
270
|
+
phoneNumberId: string;
|
|
271
|
+
}, UnblockUsersInput, UnblockUsersResponse>;
|
|
272
|
+
};
|
|
273
|
+
export declare const getOfficialBusinessAccountStatus: ((client: GraphClient, params: GetOfficialBusinessAccountStatusInput, body?: never, opts?: EndpointInvokeOptions) => Promise<OfficialBusinessAccountStatusResponse>) & {
|
|
274
|
+
definition: import("../endpoint.js").EndpointDefinition<{
|
|
275
|
+
phoneNumberId: string;
|
|
276
|
+
fields?: string;
|
|
277
|
+
}, never, OfficialBusinessAccountStatusResponse>;
|
|
278
|
+
};
|
|
279
|
+
export declare const requestOfficialBusinessAccountReview: ((client: GraphClient, params: RequestOfficialBusinessAccountReviewInput, body?: never, opts?: EndpointInvokeOptions) => Promise<OfficialBusinessAccountReviewResponse>) & {
|
|
280
|
+
definition: import("../endpoint.js").EndpointDefinition<{
|
|
281
|
+
phoneNumberId: string;
|
|
282
|
+
}, RequestOfficialBusinessAccountReviewInput, OfficialBusinessAccountReviewResponse>;
|
|
283
|
+
};
|
|
284
|
+
export declare const submitDisplayNameForReview: ((client: GraphClient, params: SubmitDisplayNameForReviewInput, body?: never, opts?: EndpointInvokeOptions) => Promise<SubmitDisplayNameForReviewResponse>) & {
|
|
285
|
+
definition: import("../endpoint.js").EndpointDefinition<{
|
|
286
|
+
phoneNumberId: string;
|
|
287
|
+
}, SubmitDisplayNameForReviewInput, SubmitDisplayNameForReviewResponse>;
|
|
288
|
+
};
|
|
145
289
|
export declare const getBusinessProfile: ((client: GraphClient, params: GetBusinessProfileInput, body?: never, opts?: EndpointInvokeOptions) => Promise<BusinessProfileResponse>) & {
|
|
146
290
|
definition: import("../endpoint.js").EndpointDefinition<{
|
|
147
291
|
phoneNumberId: string;
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
assertQueryString as assertInternalQueryString
|
|
8
8
|
} from "../internal/validation/strings.js";
|
|
9
|
-
import { assertJoinedStringQueryArray } from "../internal/validation/arrays.js";
|
|
9
|
+
import { assertDenseDataArray, assertJoinedStringQueryArray } from "../internal/validation/arrays.js";
|
|
10
10
|
import { sanitizeHeaderInit } from "../internal/validation/headers.js";
|
|
11
11
|
import {
|
|
12
12
|
assertPlainDataRecord,
|
|
@@ -18,6 +18,13 @@ const MAX_FIELD_ARRAY_LENGTH = 50;
|
|
|
18
18
|
const MAX_FIELD_ITEM_LENGTH = 128;
|
|
19
19
|
const MAX_CURSOR_LENGTH = 512;
|
|
20
20
|
const MAX_PERCENT_DECODE_ROUNDS = 8;
|
|
21
|
+
const MAX_BLOCK_USERS = 50;
|
|
22
|
+
const MAX_RECIPIENT_DIGITS = 15;
|
|
23
|
+
const MAX_DISPLAY_NAME_LENGTH = 128;
|
|
24
|
+
const MAX_OBA_TEXT_LENGTH = 2048;
|
|
25
|
+
const MAX_OBA_URL_LENGTH = 2048;
|
|
26
|
+
const MAX_OBA_SUPPORTING_LINKS = 10;
|
|
27
|
+
const MIN_OBA_SUPPORTING_LINKS = 5;
|
|
21
28
|
function validationError(message, cause) {
|
|
22
29
|
return new GraphRequestValidationError(message, cause);
|
|
23
30
|
}
|
|
@@ -112,6 +119,119 @@ function optionalIncludeSipCredentials(record, helperName) {
|
|
|
112
119
|
}
|
|
113
120
|
return value ? "true" : "false";
|
|
114
121
|
}
|
|
122
|
+
function assertRecipient(value, fieldName, helperName) {
|
|
123
|
+
if (typeof value !== "string") {
|
|
124
|
+
throw validationError(`Invalid ${helperName} input: ${fieldName} must be a phone-number string.`);
|
|
125
|
+
}
|
|
126
|
+
if (value.length === 0 || value.trim().length === 0) {
|
|
127
|
+
throw validationError(`Invalid ${helperName} input: ${fieldName} must be a non-empty phone-number string.`);
|
|
128
|
+
}
|
|
129
|
+
for (let index = 0;index < value.length; index += 1) {
|
|
130
|
+
const code = value.charCodeAt(index);
|
|
131
|
+
if (code < 32 || code === 127) {
|
|
132
|
+
throw validationError(`Invalid ${helperName} input: ${fieldName} must not contain control characters.`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (value.includes("/") || value.includes("\\") || value.includes("?") || value.includes("#") || value.includes(":") || value.includes("@")) {
|
|
136
|
+
throw validationError(`Invalid ${helperName} input: ${fieldName} must be a phone-number string, not a path, URL, or address.`);
|
|
137
|
+
}
|
|
138
|
+
if (!/^\+?\d{1,15}$/u.test(value)) {
|
|
139
|
+
throw validationError(`Invalid ${helperName} input: ${fieldName} must be E.164-ish digits with optional leading + and at most ${MAX_RECIPIENT_DIGITS} digits.`);
|
|
140
|
+
}
|
|
141
|
+
return value;
|
|
142
|
+
}
|
|
143
|
+
function normalizeBlockUserList(value, helperName) {
|
|
144
|
+
const items = assertDenseDataArray(value, {
|
|
145
|
+
helperName,
|
|
146
|
+
path: "users",
|
|
147
|
+
minLength: 1,
|
|
148
|
+
maxLength: MAX_BLOCK_USERS,
|
|
149
|
+
invalidTypeMessage: `Invalid ${helperName} input: users must be an array of phone-number strings.`,
|
|
150
|
+
invalidLengthMessage: `Invalid ${helperName} input: users length must be between 1 and ${MAX_BLOCK_USERS}.`,
|
|
151
|
+
sparseArrayMessage: `Invalid ${helperName} input: users must not contain sparse array holes.`,
|
|
152
|
+
unsafePrototypeKeyMessage: `Invalid ${helperName} input: users contains an unsafe prototype key.`,
|
|
153
|
+
unsupportedPropertyMessage: `Invalid ${helperName} input: users contains unsupported properties.`
|
|
154
|
+
});
|
|
155
|
+
return items.map((item, index) => ({ user: assertRecipient(item, `users[${index}]`, helperName) }));
|
|
156
|
+
}
|
|
157
|
+
function assertBoundedPlainString(value, fieldName, helperName, maxLength) {
|
|
158
|
+
const out = assertQueryString(value, fieldName, helperName, maxLength);
|
|
159
|
+
return out;
|
|
160
|
+
}
|
|
161
|
+
function assertHttpUrl(value, fieldName, helperName) {
|
|
162
|
+
const raw = assertBoundedPlainString(value, fieldName, helperName, MAX_OBA_URL_LENGTH);
|
|
163
|
+
let parsed;
|
|
164
|
+
try {
|
|
165
|
+
parsed = new URL(raw);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
throw validationError(`Invalid ${helperName} input: ${fieldName} must be an http(s) URL.`, error);
|
|
168
|
+
}
|
|
169
|
+
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
|
|
170
|
+
throw validationError(`Invalid ${helperName} input: ${fieldName} must be an http(s) URL.`);
|
|
171
|
+
}
|
|
172
|
+
return raw;
|
|
173
|
+
}
|
|
174
|
+
function optionalBoundedString(record, key, helperName) {
|
|
175
|
+
const value = ownDataValue(record, key, helperName, false);
|
|
176
|
+
if (value === undefined)
|
|
177
|
+
return;
|
|
178
|
+
return assertBoundedPlainString(value, key, helperName, MAX_OBA_TEXT_LENGTH);
|
|
179
|
+
}
|
|
180
|
+
function optionalSupportingLinks(record, helperName) {
|
|
181
|
+
const value = ownDataValue(record, "supportingLinks", helperName, false);
|
|
182
|
+
if (value === undefined)
|
|
183
|
+
return;
|
|
184
|
+
const items = assertDenseDataArray(value, {
|
|
185
|
+
helperName,
|
|
186
|
+
path: "supportingLinks",
|
|
187
|
+
minLength: MIN_OBA_SUPPORTING_LINKS,
|
|
188
|
+
maxLength: MAX_OBA_SUPPORTING_LINKS,
|
|
189
|
+
invalidTypeMessage: `Invalid ${helperName} input: supportingLinks must be an array of http(s) URLs.`,
|
|
190
|
+
invalidLengthMessage: `Invalid ${helperName} input: supportingLinks length must be between ${MIN_OBA_SUPPORTING_LINKS} and ${MAX_OBA_SUPPORTING_LINKS}.`,
|
|
191
|
+
sparseArrayMessage: `Invalid ${helperName} input: supportingLinks must not contain sparse array holes.`,
|
|
192
|
+
unsafePrototypeKeyMessage: `Invalid ${helperName} input: supportingLinks contains an unsafe prototype key.`,
|
|
193
|
+
unsupportedPropertyMessage: `Invalid ${helperName} input: supportingLinks contains unsupported properties.`
|
|
194
|
+
});
|
|
195
|
+
const out = items.map((item, index) => assertHttpUrl(item, `supportingLinks[${index}]`, helperName));
|
|
196
|
+
if (new Set(out).size !== out.length) {
|
|
197
|
+
throw validationError(`Invalid ${helperName} input: supportingLinks must not contain duplicates.`);
|
|
198
|
+
}
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
function sanitizeStorageConfiguration(value, helperName) {
|
|
202
|
+
const record = assertPlainRecord(value, helperName, "storageConfiguration");
|
|
203
|
+
const status = ownDataValue(record, "status", helperName, true);
|
|
204
|
+
const out = {
|
|
205
|
+
status: assertQueryString(status, "storageConfiguration.status", helperName, 32).toUpperCase()
|
|
206
|
+
};
|
|
207
|
+
for (const [key, nested] of Object.entries(record)) {
|
|
208
|
+
if (key === "status")
|
|
209
|
+
continue;
|
|
210
|
+
if (key === "dataLocalizationRegion" || key === "data_localization_region") {
|
|
211
|
+
throw validationError(`Invalid ${helperName} input: dataLocalizationRegion is not supported; use storageConfiguration.`);
|
|
212
|
+
}
|
|
213
|
+
if (nested !== undefined)
|
|
214
|
+
out[key] = nested;
|
|
215
|
+
}
|
|
216
|
+
return out;
|
|
217
|
+
}
|
|
218
|
+
export function buildUpdatePhoneNumberSettingsBody(input) {
|
|
219
|
+
const helperName = "updatePhoneNumberSettings";
|
|
220
|
+
const record = assertPlainRecord(input, "updatePhoneNumberSettings");
|
|
221
|
+
if (ownDataValue(record, "dataLocalizationRegion", "updatePhoneNumberSettings", false) !== undefined || ownDataValue(record, "data_localization_region", "updatePhoneNumberSettings", false) !== undefined) {
|
|
222
|
+
throw validationError("Invalid updatePhoneNumberSettings input: dataLocalizationRegion is not supported; use storageConfiguration.");
|
|
223
|
+
}
|
|
224
|
+
const storageConfiguration = ownDataValue(record, "storageConfiguration", "updatePhoneNumberSettings", false);
|
|
225
|
+
if (storageConfiguration === undefined) {
|
|
226
|
+
throw validationError("Invalid updatePhoneNumberSettings input: storageConfiguration is required.");
|
|
227
|
+
}
|
|
228
|
+
return { storage_configuration: sanitizeStorageConfiguration(storageConfiguration, "updatePhoneNumberSettings") };
|
|
229
|
+
}
|
|
230
|
+
export function normalizeUpdatePhoneNumberSettingsParams(input) {
|
|
231
|
+
const helperName = "updatePhoneNumberSettings";
|
|
232
|
+
const record = assertPlainRecord(input, "updatePhoneNumberSettings");
|
|
233
|
+
return { phoneNumberId: assertPathId(ownDataValue(record, "phoneNumberId", "updatePhoneNumberSettings", true), "phoneNumberId", "updatePhoneNumberSettings") };
|
|
234
|
+
}
|
|
115
235
|
export function normalizeWabaInfoParams(input) {
|
|
116
236
|
const helperName = "getWabaInfo";
|
|
117
237
|
const record = assertPlainRecord(input, "getWabaInfo");
|
|
@@ -165,6 +285,85 @@ export function normalizePhoneNumberSettingsParams(input) {
|
|
|
165
285
|
out.include_sip_credentials = includeSipCredentials;
|
|
166
286
|
return out;
|
|
167
287
|
}
|
|
288
|
+
export function normalizeListBlockedUsersParams(input) {
|
|
289
|
+
const helperName = "listBlockedUsers";
|
|
290
|
+
const record = assertPlainRecord(input, "listBlockedUsers");
|
|
291
|
+
return { phoneNumberId: assertPathId(ownDataValue(record, "phoneNumberId", "listBlockedUsers", true), "phoneNumberId", "listBlockedUsers") };
|
|
292
|
+
}
|
|
293
|
+
export function buildBlockUsersBody(input) {
|
|
294
|
+
const helperName = "blockUsers";
|
|
295
|
+
const record = assertPlainRecord(input, "blockUsers");
|
|
296
|
+
return {
|
|
297
|
+
messaging_product: "whatsapp",
|
|
298
|
+
block_users: normalizeBlockUserList(ownDataValue(record, "users", "blockUsers", true), "blockUsers")
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
export function normalizeBlockUsersParams(input) {
|
|
302
|
+
const helperName = "blockUsers";
|
|
303
|
+
const record = assertPlainRecord(input, "blockUsers");
|
|
304
|
+
return { phoneNumberId: assertPathId(ownDataValue(record, "phoneNumberId", "blockUsers", true), "phoneNumberId", "blockUsers") };
|
|
305
|
+
}
|
|
306
|
+
export function buildUnblockUsersBody(input) {
|
|
307
|
+
const helperName = "unblockUsers";
|
|
308
|
+
const record = assertPlainRecord(input, "unblockUsers");
|
|
309
|
+
return {
|
|
310
|
+
messaging_product: "whatsapp",
|
|
311
|
+
block_users: normalizeBlockUserList(ownDataValue(record, "users", "unblockUsers", true), "unblockUsers")
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
export function normalizeUnblockUsersParams(input) {
|
|
315
|
+
const helperName = "unblockUsers";
|
|
316
|
+
const record = assertPlainRecord(input, "unblockUsers");
|
|
317
|
+
return { phoneNumberId: assertPathId(ownDataValue(record, "phoneNumberId", "unblockUsers", true), "phoneNumberId", "unblockUsers") };
|
|
318
|
+
}
|
|
319
|
+
export function normalizeOfficialBusinessAccountStatusParams(input) {
|
|
320
|
+
const helperName = "getOfficialBusinessAccountStatus";
|
|
321
|
+
const record = assertPlainRecord(input, "getOfficialBusinessAccountStatus");
|
|
322
|
+
const out = { phoneNumberId: assertPathId(ownDataValue(record, "phoneNumberId", "getOfficialBusinessAccountStatus", true), "phoneNumberId", "getOfficialBusinessAccountStatus") };
|
|
323
|
+
const fields = optionalFields(record, "getOfficialBusinessAccountStatus");
|
|
324
|
+
if (fields !== undefined)
|
|
325
|
+
out.fields = fields;
|
|
326
|
+
return out;
|
|
327
|
+
}
|
|
328
|
+
export function buildOfficialBusinessAccountReviewBody(input) {
|
|
329
|
+
const helperName = "requestOfficialBusinessAccountReview";
|
|
330
|
+
const record = assertPlainRecord(input, "requestOfficialBusinessAccountReview");
|
|
331
|
+
const out = {
|
|
332
|
+
business_website_url: assertHttpUrl(ownDataValue(record, "businessWebsiteUrl", "requestOfficialBusinessAccountReview", true), "businessWebsiteUrl", "requestOfficialBusinessAccountReview"),
|
|
333
|
+
primary_country_of_operation: assertBoundedPlainString(ownDataValue(record, "primaryCountryOfOperation", "requestOfficialBusinessAccountReview", true), "primaryCountryOfOperation", "requestOfficialBusinessAccountReview", 2).toUpperCase()
|
|
334
|
+
};
|
|
335
|
+
if (!/^[A-Z]{2}$/u.test(out.primary_country_of_operation)) {
|
|
336
|
+
throw validationError("Invalid requestOfficialBusinessAccountReview input: primaryCountryOfOperation must be an ISO 3166-1 alpha-2 country code.");
|
|
337
|
+
}
|
|
338
|
+
const primaryLanguage = optionalBoundedString(record, "primaryLanguage", "requestOfficialBusinessAccountReview");
|
|
339
|
+
const parentBusinessOrBrand = optionalBoundedString(record, "parentBusinessOrBrand", "requestOfficialBusinessAccountReview");
|
|
340
|
+
const supportingLinks = optionalSupportingLinks(record, "requestOfficialBusinessAccountReview");
|
|
341
|
+
const additional = optionalBoundedString(record, "additionalSupportingInformation", "requestOfficialBusinessAccountReview");
|
|
342
|
+
if (primaryLanguage !== undefined)
|
|
343
|
+
out.primary_language = primaryLanguage;
|
|
344
|
+
if (parentBusinessOrBrand !== undefined)
|
|
345
|
+
out.parent_business_or_brand = parentBusinessOrBrand;
|
|
346
|
+
if (supportingLinks !== undefined)
|
|
347
|
+
out.supporting_links = supportingLinks;
|
|
348
|
+
if (additional !== undefined)
|
|
349
|
+
out.additional_supporting_information = additional;
|
|
350
|
+
return out;
|
|
351
|
+
}
|
|
352
|
+
export function normalizeOfficialBusinessAccountReviewParams(input) {
|
|
353
|
+
const helperName = "requestOfficialBusinessAccountReview";
|
|
354
|
+
const record = assertPlainRecord(input, "requestOfficialBusinessAccountReview");
|
|
355
|
+
return { phoneNumberId: assertPathId(ownDataValue(record, "phoneNumberId", "requestOfficialBusinessAccountReview", true), "phoneNumberId", "requestOfficialBusinessAccountReview") };
|
|
356
|
+
}
|
|
357
|
+
export function buildDisplayNameReviewBody(input) {
|
|
358
|
+
const helperName = "submitDisplayNameForReview";
|
|
359
|
+
const record = assertPlainRecord(input, "submitDisplayNameForReview");
|
|
360
|
+
return { new_display_name: assertBoundedPlainString(ownDataValue(record, "newDisplayName", "submitDisplayNameForReview", true), "newDisplayName", "submitDisplayNameForReview", MAX_DISPLAY_NAME_LENGTH) };
|
|
361
|
+
}
|
|
362
|
+
export function normalizeDisplayNameReviewParams(input) {
|
|
363
|
+
const helperName = "submitDisplayNameForReview";
|
|
364
|
+
const record = assertPlainRecord(input, "submitDisplayNameForReview");
|
|
365
|
+
return { phoneNumberId: assertPathId(ownDataValue(record, "phoneNumberId", "submitDisplayNameForReview", true), "phoneNumberId", "submitDisplayNameForReview") };
|
|
366
|
+
}
|
|
168
367
|
export function normalizeBusinessProfileParams(input) {
|
|
169
368
|
const helperName = "getBusinessProfile";
|
|
170
369
|
const record = assertPlainRecord(input, "getBusinessProfile");
|
|
@@ -241,6 +440,51 @@ const getPhoneNumberSettingsRaw = defineEndpoint({
|
|
|
241
440
|
include_sip_credentials: { in: "query" }
|
|
242
441
|
}
|
|
243
442
|
});
|
|
443
|
+
const listBlockedUsersRaw = defineEndpoint({
|
|
444
|
+
method: "GET",
|
|
445
|
+
pathTemplate: "/{phoneNumberId}/block_users",
|
|
446
|
+
params: { phoneNumberId: { in: "path", required: true } }
|
|
447
|
+
});
|
|
448
|
+
const blockUsersRaw = defineEndpoint({
|
|
449
|
+
method: "POST",
|
|
450
|
+
pathTemplate: "/{phoneNumberId}/block_users",
|
|
451
|
+
params: { phoneNumberId: { in: "path", required: true } },
|
|
452
|
+
bodyContentType: "application/json",
|
|
453
|
+
buildBody: buildBlockUsersBody
|
|
454
|
+
});
|
|
455
|
+
const unblockUsersRaw = defineEndpoint({
|
|
456
|
+
method: "DELETE",
|
|
457
|
+
pathTemplate: "/{phoneNumberId}/block_users",
|
|
458
|
+
params: { phoneNumberId: { in: "path", required: true } },
|
|
459
|
+
bodyContentType: "application/json",
|
|
460
|
+
buildBody: buildUnblockUsersBody
|
|
461
|
+
});
|
|
462
|
+
const getOfficialBusinessAccountStatusRaw = defineEndpoint({
|
|
463
|
+
method: "GET",
|
|
464
|
+
pathTemplate: "/{phoneNumberId}/official_business_account",
|
|
465
|
+
params: { phoneNumberId: { in: "path", required: true }, fields: { in: "query" } }
|
|
466
|
+
});
|
|
467
|
+
const requestOfficialBusinessAccountReviewRaw = defineEndpoint({
|
|
468
|
+
method: "POST",
|
|
469
|
+
pathTemplate: "/{phoneNumberId}/official_business_account",
|
|
470
|
+
params: { phoneNumberId: { in: "path", required: true } },
|
|
471
|
+
bodyContentType: "application/json",
|
|
472
|
+
buildBody: buildOfficialBusinessAccountReviewBody
|
|
473
|
+
});
|
|
474
|
+
const submitDisplayNameForReviewRaw = defineEndpoint({
|
|
475
|
+
method: "POST",
|
|
476
|
+
pathTemplate: "/{phoneNumberId}",
|
|
477
|
+
params: { phoneNumberId: { in: "path", required: true } },
|
|
478
|
+
bodyContentType: "application/json",
|
|
479
|
+
buildBody: buildDisplayNameReviewBody
|
|
480
|
+
});
|
|
481
|
+
const updatePhoneNumberSettingsRaw = defineEndpoint({
|
|
482
|
+
method: "POST",
|
|
483
|
+
pathTemplate: "/{phoneNumberId}/settings",
|
|
484
|
+
params: { phoneNumberId: { in: "path", required: true } },
|
|
485
|
+
bodyContentType: "application/json",
|
|
486
|
+
buildBody: buildUpdatePhoneNumberSettingsBody
|
|
487
|
+
});
|
|
244
488
|
const getBusinessProfileRaw = defineEndpoint({
|
|
245
489
|
method: "GET",
|
|
246
490
|
pathTemplate: "/{phoneNumberId}/whatsapp_business_profile",
|
|
@@ -267,6 +511,34 @@ export const getPhoneNumberSettings = Object.assign(async function getPhoneNumbe
|
|
|
267
511
|
assertNoBody(body, "getPhoneNumberSettings");
|
|
268
512
|
return getPhoneNumberSettingsRaw(client, normalizePhoneNumberSettingsParams(params), undefined, sanitizeBusinessManagementOptions(opts, "getPhoneNumberSettings"));
|
|
269
513
|
}, { definition: getPhoneNumberSettingsRaw.definition });
|
|
514
|
+
export const updatePhoneNumberSettings = Object.assign(async function updatePhoneNumberSettings(client, params, body, opts) {
|
|
515
|
+
assertNoBody(body, "updatePhoneNumberSettings");
|
|
516
|
+
return updatePhoneNumberSettingsRaw(client, normalizeUpdatePhoneNumberSettingsParams(params), params, sanitizeBusinessManagementOptions(opts, "updatePhoneNumberSettings"));
|
|
517
|
+
}, { definition: updatePhoneNumberSettingsRaw.definition });
|
|
518
|
+
export const listBlockedUsers = Object.assign(async function listBlockedUsers(client, params, body, opts) {
|
|
519
|
+
assertNoBody(body, "listBlockedUsers");
|
|
520
|
+
return listBlockedUsersRaw(client, normalizeListBlockedUsersParams(params), undefined, sanitizeBusinessManagementOptions(opts, "listBlockedUsers"));
|
|
521
|
+
}, { definition: listBlockedUsersRaw.definition });
|
|
522
|
+
export const blockUsers = Object.assign(async function blockUsers(client, params, body, opts) {
|
|
523
|
+
assertNoBody(body, "blockUsers");
|
|
524
|
+
return blockUsersRaw(client, normalizeBlockUsersParams(params), params, sanitizeBusinessManagementOptions(opts, "blockUsers"));
|
|
525
|
+
}, { definition: blockUsersRaw.definition });
|
|
526
|
+
export const unblockUsers = Object.assign(async function unblockUsers(client, params, body, opts) {
|
|
527
|
+
assertNoBody(body, "unblockUsers");
|
|
528
|
+
return unblockUsersRaw(client, normalizeUnblockUsersParams(params), params, sanitizeBusinessManagementOptions(opts, "unblockUsers"));
|
|
529
|
+
}, { definition: unblockUsersRaw.definition });
|
|
530
|
+
export const getOfficialBusinessAccountStatus = Object.assign(async function getOfficialBusinessAccountStatus(client, params, body, opts) {
|
|
531
|
+
assertNoBody(body, "getOfficialBusinessAccountStatus");
|
|
532
|
+
return getOfficialBusinessAccountStatusRaw(client, normalizeOfficialBusinessAccountStatusParams(params), undefined, sanitizeBusinessManagementOptions(opts, "getOfficialBusinessAccountStatus"));
|
|
533
|
+
}, { definition: getOfficialBusinessAccountStatusRaw.definition });
|
|
534
|
+
export const requestOfficialBusinessAccountReview = Object.assign(async function requestOfficialBusinessAccountReview(client, params, body, opts) {
|
|
535
|
+
assertNoBody(body, "requestOfficialBusinessAccountReview");
|
|
536
|
+
return requestOfficialBusinessAccountReviewRaw(client, normalizeOfficialBusinessAccountReviewParams(params), params, sanitizeBusinessManagementOptions(opts, "requestOfficialBusinessAccountReview"));
|
|
537
|
+
}, { definition: requestOfficialBusinessAccountReviewRaw.definition });
|
|
538
|
+
export const submitDisplayNameForReview = Object.assign(async function submitDisplayNameForReview(client, params, body, opts) {
|
|
539
|
+
assertNoBody(body, "submitDisplayNameForReview");
|
|
540
|
+
return submitDisplayNameForReviewRaw(client, normalizeDisplayNameReviewParams(params), params, sanitizeBusinessManagementOptions(opts, "submitDisplayNameForReview"));
|
|
541
|
+
}, { definition: submitDisplayNameForReviewRaw.definition });
|
|
270
542
|
export const getBusinessProfile = Object.assign(async function getBusinessProfile(client, params, body, opts) {
|
|
271
543
|
assertNoBody(body, "getBusinessProfile");
|
|
272
544
|
return getBusinessProfileRaw(client, normalizeBusinessProfileParams(params), undefined, sanitizeBusinessManagementOptions(opts, "getBusinessProfile"));
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @experimental Calling endpoint helpers may change in 0.x minors while live calling parity expands.
|
|
3
|
+
*/
|
|
1
4
|
import { type EndpointInvokeOptions } from "../endpoint.js";
|
|
2
5
|
import type { GraphClient } from "../client.js";
|
|
3
6
|
export type CallAction = "connect" | "pre_accept" | "accept" | "reject" | "terminate";
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @experimental Flow DSL and data-channel helpers may change in 0.x minors while WATS expands Flow parity.
|
|
3
|
+
*/
|
|
1
4
|
export { FLOW_JSON_MAX_ARRAY_LENGTH, FLOW_JSON_MAX_BYTES, FLOW_JSON_MAX_COMPONENTS, FLOW_JSON_MAX_DEPTH, FLOW_JSON_MAX_SCREENS, FLOW_JSON_MAX_STRING_LENGTH, FLOW_MAX_CATEGORIES, buildFlowCloseResponse, buildFlowErrorResponse, buildFlowJson, buildFlowScreenResponse, createFlow, deleteFlow, deprecateFlow, getFlow, getFlowAssets, listFlows, publishFlow, updateFlowJson, updateFlowMetadata, validateFlowJson } from "./flows/index.js";
|
|
2
5
|
export type { CreateFlowBody, FlowAssetDetails, FlowAssetsResponse, FlowCategory, FlowCloseResponse, FlowCloseResponseInput, FlowDetails, FlowErrorResponse, FlowErrorResponseInput, FlowJson, FlowListResponse, FlowMutationResponse, FlowScreenResponse, FlowScreenResponseInput, FlowStatus, GetFlowAssetsInput, GetFlowInput, GraphPaging, ListFlowsInput, UpdateFlowJsonBody, UpdateFlowMetadataBody } from "./flows/index.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { GraphMessagesAudioPayload, GraphMessagesContactsPayload, GraphMessagesDocumentPayload, GraphMessagesImagePayload, GraphMessagesLocationPayload, GraphMessagesReactionPayload, GraphMessagesRemoveReactionInput, GraphMessagesSendAudioInput, GraphMessagesSendContactsInput, GraphMessagesSendDocumentInput, GraphMessagesSendImageInput, GraphMessagesSendLocationInput, GraphMessagesSendReactionInput, GraphMessagesSendStickerInput, GraphMessagesSendTextInput, GraphMessagesSendVideoInput, GraphMessagesStickerPayload, GraphMessagesTextPayload, GraphMessagesVideoPayload } from "./types.js";
|
|
2
|
+
export declare function buildSendTextPayload(input: GraphMessagesSendTextInput): GraphMessagesTextPayload;
|
|
3
|
+
export declare function buildSendImagePayload(input: GraphMessagesSendImageInput): GraphMessagesImagePayload;
|
|
4
|
+
export declare function buildSendVideoPayload(input: GraphMessagesSendVideoInput): GraphMessagesVideoPayload;
|
|
5
|
+
export declare function buildSendAudioPayload(input: GraphMessagesSendAudioInput): GraphMessagesAudioPayload;
|
|
6
|
+
export declare function buildSendDocumentPayload(input: GraphMessagesSendDocumentInput): GraphMessagesDocumentPayload;
|
|
7
|
+
export declare function buildSendStickerPayload(input: GraphMessagesSendStickerInput): GraphMessagesStickerPayload;
|
|
8
|
+
export declare function buildSendLocationPayload(input: GraphMessagesSendLocationInput): GraphMessagesLocationPayload;
|
|
9
|
+
export declare function buildSendContactsPayload(input: GraphMessagesSendContactsInput): GraphMessagesContactsPayload;
|
|
10
|
+
export declare function buildSendReactionPayload(input: GraphMessagesSendReactionInput): GraphMessagesReactionPayload;
|
|
11
|
+
export declare function buildRemoveReactionPayload(input: GraphMessagesRemoveReactionInput): GraphMessagesReactionPayload;
|