@wats/graph 0.3.1 → 0.3.3
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/dist/client.d.ts +2 -2
- package/dist/client.js +3 -3
- package/dist/createFetchTransport.d.ts +1 -1
- package/dist/createFetchTransport.js +1 -1
- package/dist/createMockTransport.d.ts +1 -1
- package/dist/endpoint.d.ts +1 -1
- package/dist/endpoint.js +1 -1
- package/dist/endpoints/businessManagement.d.ts +153 -9
- package/dist/endpoints/businessManagement.js +279 -7
- package/dist/endpoints/calling.d.ts +7 -7
- package/dist/endpoints/calling.js +2 -2
- package/dist/endpoints/flows/callables.d.ts +10 -10
- package/dist/endpoints/flows/callables.js +2 -2
- package/dist/endpoints/flows/dataExchange.d.ts +1 -1
- package/dist/endpoints/flows/dataExchange.js +2 -2
- package/dist/endpoints/flows/flowJson.d.ts +1 -1
- package/dist/endpoints/flows/flowJson.js +1 -1
- package/dist/endpoints/flows/index.d.ts +6 -6
- package/dist/endpoints/flows/index.js +4 -4
- package/dist/endpoints/flows/shared.d.ts +1 -1
- package/dist/endpoints/flows/shared.js +1 -1
- package/dist/endpoints/flows/types.d.ts +1 -1
- package/dist/endpoints/flows.d.ts +2 -2
- package/dist/endpoints/flows.js +1 -1
- package/dist/endpoints/media.d.ts +1 -1
- package/dist/endpoints/media.js +1 -1
- 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.d.ts +1 -1
- package/dist/endpoints/templates/builders.js +24 -1
- package/dist/endpoints/templates/callables.d.ts +7 -6
- package/dist/endpoints/templates/callables.js +7 -5
- package/dist/endpoints/templates/groups.d.ts +126 -0
- package/dist/endpoints/templates/groups.js +156 -0
- package/dist/endpoints/templates/index.d.ts +7 -5
- package/dist/endpoints/templates/index.js +11 -3
- package/dist/endpoints/templates/shared.d.ts +2 -2
- package/dist/endpoints/templates/shared.js +1 -1
- package/dist/endpoints/templates/types.d.ts +15 -2
- package/dist/endpoints/templates/validation.d.ts +1 -1
- package/dist/endpoints/templates/validation.js +2 -2
- package/dist/endpoints/templates.d.ts +2 -2
- package/dist/endpoints/templates.js +7 -1
- package/dist/endpoints/waba/index.d.ts +4 -4
- package/dist/endpoints/waba/index.js +1 -1
- package/dist/endpoints/waba/phoneNumbers.d.ts +6 -4
- package/dist/endpoints/waba/phoneNumbers.js +3 -3
- package/dist/endpoints/wabaEndpoints.d.ts +6 -6
- package/dist/endpoints/wabaEndpoints.js +9 -3
- package/dist/errorRegistry.d.ts +1 -1
- package/dist/errorSubclasses.d.ts +30 -2
- package/dist/errorSubclasses.js +65 -2
- package/dist/errors.js +1 -1
- package/dist/index.d.ts +20 -20
- package/dist/index.js +15 -15
- package/dist/internal/validation/arrays.js +2 -2
- package/dist/internal/validation/errors.d.ts +1 -1
- package/dist/internal/validation/errors.js +1 -1
- package/dist/internal/validation/headers.js +3 -3
- package/dist/internal/validation/index.d.ts +8 -8
- package/dist/internal/validation/index.js +8 -8
- package/dist/internal/validation/json.js +4 -4
- package/dist/internal/validation/options.js +2 -2
- package/dist/internal/validation/paths.js +2 -2
- package/dist/internal/validation/records.js +2 -2
- package/dist/internal/validation/strings.js +1 -1
- package/dist/pagination.d.ts +2 -2
- package/dist/subclients/phoneNumberClient.d.ts +21 -5
- package/dist/subclients/phoneNumberClient.js +78 -7
- package/dist/subclients/wabaClient.d.ts +19 -5
- package/dist/subclients/wabaClient.js +39 -6
- package/package.json +10 -1
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
export interface GraphMessagesSendMessageInput {
|
|
2
|
+
phoneNumberId: string;
|
|
3
|
+
to: string;
|
|
4
|
+
text: string;
|
|
5
|
+
previewUrl?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface GraphMessagesSendTextInput {
|
|
8
|
+
readonly to: string;
|
|
9
|
+
readonly text: string;
|
|
10
|
+
readonly previewUrl?: boolean;
|
|
11
|
+
readonly replyToMessageId?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface GraphMessagesSendMediaInput {
|
|
14
|
+
readonly to: string;
|
|
15
|
+
readonly mediaId?: string;
|
|
16
|
+
readonly link?: string;
|
|
17
|
+
readonly replyToMessageId?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface GraphMessagesSendCaptionedMediaInput extends GraphMessagesSendMediaInput {
|
|
20
|
+
readonly caption?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface GraphMessagesSendDocumentInput extends GraphMessagesSendCaptionedMediaInput {
|
|
23
|
+
readonly filename?: string;
|
|
24
|
+
}
|
|
25
|
+
export type GraphMessagesSendImageInput = GraphMessagesSendCaptionedMediaInput;
|
|
26
|
+
export type GraphMessagesSendVideoInput = GraphMessagesSendCaptionedMediaInput;
|
|
27
|
+
export interface GraphMessagesSendAudioInput extends GraphMessagesSendMediaInput {
|
|
28
|
+
/** Graph v24+ voice-message designation for audio sends. Defaults to omitted/false. */
|
|
29
|
+
readonly voice?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export type GraphMessagesSendStickerInput = GraphMessagesSendMediaInput;
|
|
32
|
+
export interface GraphMessagesSendLocationInput {
|
|
33
|
+
readonly to: string;
|
|
34
|
+
readonly latitude: number;
|
|
35
|
+
readonly longitude: number;
|
|
36
|
+
readonly name?: string;
|
|
37
|
+
readonly address?: string;
|
|
38
|
+
readonly replyToMessageId?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface GraphMessagesContactNameInput {
|
|
41
|
+
readonly formattedName?: string;
|
|
42
|
+
readonly firstName?: string;
|
|
43
|
+
readonly lastName?: string;
|
|
44
|
+
readonly middleName?: string;
|
|
45
|
+
readonly suffix?: string;
|
|
46
|
+
readonly prefix?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface GraphMessagesContactPhoneInput {
|
|
49
|
+
readonly phone?: string;
|
|
50
|
+
readonly type?: string;
|
|
51
|
+
readonly waId?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface GraphMessagesContactEmailInput {
|
|
54
|
+
readonly email: string;
|
|
55
|
+
readonly type?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface GraphMessagesContactUrlInput {
|
|
58
|
+
readonly url: string;
|
|
59
|
+
readonly type?: string;
|
|
60
|
+
}
|
|
61
|
+
export interface GraphMessagesContactAddressInput {
|
|
62
|
+
readonly street?: string;
|
|
63
|
+
readonly city?: string;
|
|
64
|
+
readonly state?: string;
|
|
65
|
+
readonly zip?: string;
|
|
66
|
+
readonly country?: string;
|
|
67
|
+
readonly countryCode?: string;
|
|
68
|
+
readonly type?: string;
|
|
69
|
+
}
|
|
70
|
+
export interface GraphMessagesContactOrgInput {
|
|
71
|
+
readonly company?: string;
|
|
72
|
+
readonly department?: string;
|
|
73
|
+
readonly title?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface GraphMessagesContactInput {
|
|
76
|
+
readonly name: GraphMessagesContactNameInput;
|
|
77
|
+
readonly phones?: readonly GraphMessagesContactPhoneInput[];
|
|
78
|
+
readonly emails?: readonly GraphMessagesContactEmailInput[];
|
|
79
|
+
readonly urls?: readonly GraphMessagesContactUrlInput[];
|
|
80
|
+
readonly addresses?: readonly GraphMessagesContactAddressInput[];
|
|
81
|
+
readonly org?: GraphMessagesContactOrgInput;
|
|
82
|
+
readonly birthday?: string;
|
|
83
|
+
}
|
|
84
|
+
export interface GraphMessagesSendContactsInput {
|
|
85
|
+
readonly to: string;
|
|
86
|
+
readonly contacts: readonly GraphMessagesContactInput[];
|
|
87
|
+
readonly replyToMessageId?: string;
|
|
88
|
+
}
|
|
89
|
+
export interface GraphMessagesSendReactionInput {
|
|
90
|
+
readonly to: string;
|
|
91
|
+
readonly messageId: string;
|
|
92
|
+
readonly emoji: string;
|
|
93
|
+
}
|
|
94
|
+
export interface GraphMessagesRemoveReactionInput {
|
|
95
|
+
readonly to: string;
|
|
96
|
+
readonly messageId: string;
|
|
97
|
+
}
|
|
98
|
+
export interface GraphMessagesSendButtonsInput {
|
|
99
|
+
readonly to: string;
|
|
100
|
+
readonly bodyText: string;
|
|
101
|
+
readonly buttons: readonly {
|
|
102
|
+
readonly id: string;
|
|
103
|
+
readonly title: string;
|
|
104
|
+
}[];
|
|
105
|
+
readonly headerText?: string;
|
|
106
|
+
readonly footerText?: string;
|
|
107
|
+
readonly replyToMessageId?: string;
|
|
108
|
+
}
|
|
109
|
+
export interface GraphMessagesSendListInput {
|
|
110
|
+
readonly to: string;
|
|
111
|
+
readonly bodyText: string;
|
|
112
|
+
readonly buttonText: string;
|
|
113
|
+
readonly sections: readonly {
|
|
114
|
+
readonly title?: string;
|
|
115
|
+
readonly rows: readonly {
|
|
116
|
+
readonly id: string;
|
|
117
|
+
readonly title: string;
|
|
118
|
+
readonly description?: string;
|
|
119
|
+
}[];
|
|
120
|
+
}[];
|
|
121
|
+
readonly headerText?: string;
|
|
122
|
+
readonly footerText?: string;
|
|
123
|
+
readonly replyToMessageId?: string;
|
|
124
|
+
}
|
|
125
|
+
export interface GraphMessagesSendCtaUrlInput {
|
|
126
|
+
readonly to: string;
|
|
127
|
+
readonly bodyText: string;
|
|
128
|
+
readonly displayText: string;
|
|
129
|
+
readonly url: string;
|
|
130
|
+
readonly footerText?: string;
|
|
131
|
+
readonly replyToMessageId?: string;
|
|
132
|
+
}
|
|
133
|
+
export interface GraphMessagesSendCallPermissionRequestInput {
|
|
134
|
+
readonly to: string;
|
|
135
|
+
readonly bodyText: string;
|
|
136
|
+
readonly footerText?: string;
|
|
137
|
+
readonly replyToMessageId?: string;
|
|
138
|
+
}
|
|
139
|
+
export interface GraphMessagesSendProductInput {
|
|
140
|
+
readonly to: string;
|
|
141
|
+
readonly catalogId: string;
|
|
142
|
+
readonly productRetailerId: string;
|
|
143
|
+
readonly bodyText?: string;
|
|
144
|
+
readonly footerText?: string;
|
|
145
|
+
readonly replyToMessageId?: string;
|
|
146
|
+
}
|
|
147
|
+
export interface GraphMessagesSendProductsInput {
|
|
148
|
+
readonly to: string;
|
|
149
|
+
readonly catalogId: string;
|
|
150
|
+
readonly headerText: string;
|
|
151
|
+
readonly bodyText: string;
|
|
152
|
+
readonly sections: readonly {
|
|
153
|
+
readonly title: string;
|
|
154
|
+
readonly productItems: readonly {
|
|
155
|
+
readonly productRetailerId: string;
|
|
156
|
+
}[];
|
|
157
|
+
}[];
|
|
158
|
+
readonly footerText?: string;
|
|
159
|
+
readonly replyToMessageId?: string;
|
|
160
|
+
}
|
|
161
|
+
export interface GraphMessagesSendCatalogInput {
|
|
162
|
+
readonly to: string;
|
|
163
|
+
readonly bodyText: string;
|
|
164
|
+
readonly footerText?: string;
|
|
165
|
+
readonly thumbnailProductRetailerId?: string;
|
|
166
|
+
readonly replyToMessageId?: string;
|
|
167
|
+
}
|
|
168
|
+
export interface GraphMessagesRequestLocationInput {
|
|
169
|
+
readonly to: string;
|
|
170
|
+
readonly bodyText: string;
|
|
171
|
+
readonly replyToMessageId?: string;
|
|
172
|
+
}
|
|
173
|
+
export interface GraphMessagesMarkMessageAsReadInput {
|
|
174
|
+
readonly messageId: string;
|
|
175
|
+
}
|
|
176
|
+
export type GraphMessagesTypingIndicatorInput = GraphMessagesMarkMessageAsReadInput;
|
|
177
|
+
export interface GraphMessagesTemplateComponentInput {
|
|
178
|
+
readonly type: string;
|
|
179
|
+
readonly parameters?: readonly Record<string, unknown>[];
|
|
180
|
+
readonly subType?: string;
|
|
181
|
+
readonly index?: string;
|
|
182
|
+
}
|
|
183
|
+
export interface GraphMessagesSendTemplateInput {
|
|
184
|
+
readonly to: string;
|
|
185
|
+
readonly name: string;
|
|
186
|
+
readonly languageCode: string;
|
|
187
|
+
readonly components?: readonly GraphMessagesTemplateComponentInput[];
|
|
188
|
+
readonly replyToMessageId?: string;
|
|
189
|
+
}
|
|
190
|
+
export type GraphMessagesMarketingProductPolicy = "CLOUD_API_FALLBACK" | "STRICT";
|
|
191
|
+
export type GraphMessagesMarketingMessageStatus = "accepted" | "held_for_quality_assessment" | "paused" | string;
|
|
192
|
+
export interface GraphMessagesSendMarketingTemplateInput {
|
|
193
|
+
readonly to?: string;
|
|
194
|
+
readonly recipient?: string;
|
|
195
|
+
readonly name: string;
|
|
196
|
+
readonly languageCode: string;
|
|
197
|
+
readonly components?: readonly GraphMessagesTemplateComponentInput[];
|
|
198
|
+
readonly productPolicy?: GraphMessagesMarketingProductPolicy;
|
|
199
|
+
readonly messageActivitySharing?: boolean;
|
|
200
|
+
}
|
|
201
|
+
export interface GraphMessagesSendResponse {
|
|
202
|
+
messaging_product?: string;
|
|
203
|
+
contacts?: Array<{
|
|
204
|
+
input?: string;
|
|
205
|
+
wa_id?: string;
|
|
206
|
+
}>;
|
|
207
|
+
messages?: Array<{
|
|
208
|
+
id: string;
|
|
209
|
+
}>;
|
|
210
|
+
}
|
|
211
|
+
export interface GraphMessagesMarketingTemplateResponse {
|
|
212
|
+
messaging_product?: string;
|
|
213
|
+
contacts?: Array<{
|
|
214
|
+
input?: string;
|
|
215
|
+
wa_id?: string;
|
|
216
|
+
/** WATS-98 BSUID response field returned for Business-Scoped User ID sends. */
|
|
217
|
+
user_id?: string;
|
|
218
|
+
}>;
|
|
219
|
+
messages?: Array<{
|
|
220
|
+
id: string;
|
|
221
|
+
/** WATS-98 /marketing_messages status: accepted, held_for_quality_assessment, or paused. */
|
|
222
|
+
message_status?: GraphMessagesMarketingMessageStatus;
|
|
223
|
+
}>;
|
|
224
|
+
}
|
|
225
|
+
export interface GraphMessagesMarketingTemplatePayload {
|
|
226
|
+
messaging_product: "whatsapp";
|
|
227
|
+
recipient_type: "individual";
|
|
228
|
+
to?: string;
|
|
229
|
+
recipient?: string;
|
|
230
|
+
type: "template";
|
|
231
|
+
template: Record<string, unknown>;
|
|
232
|
+
product_policy?: GraphMessagesMarketingProductPolicy;
|
|
233
|
+
message_activity_sharing?: boolean;
|
|
234
|
+
}
|
|
235
|
+
export interface GraphMessagesTextPayload {
|
|
236
|
+
messaging_product: "whatsapp";
|
|
237
|
+
to: string;
|
|
238
|
+
type: "text";
|
|
239
|
+
text: {
|
|
240
|
+
body: string;
|
|
241
|
+
preview_url?: boolean;
|
|
242
|
+
};
|
|
243
|
+
context?: {
|
|
244
|
+
message_id: string;
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
export type GraphMessagesMediaType = "image" | "video" | "audio" | "document" | "sticker";
|
|
248
|
+
interface GraphMessagesMediaReferencePayload {
|
|
249
|
+
id?: string;
|
|
250
|
+
link?: string;
|
|
251
|
+
caption?: string;
|
|
252
|
+
filename?: string;
|
|
253
|
+
}
|
|
254
|
+
interface GraphMessagesAudioReferencePayload extends GraphMessagesMediaReferencePayload {
|
|
255
|
+
voice?: boolean;
|
|
256
|
+
}
|
|
257
|
+
export type GraphMessagesImagePayload = {
|
|
258
|
+
messaging_product: "whatsapp";
|
|
259
|
+
to: string;
|
|
260
|
+
type: "image";
|
|
261
|
+
image: GraphMessagesMediaReferencePayload;
|
|
262
|
+
context?: {
|
|
263
|
+
message_id: string;
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
export type GraphMessagesVideoPayload = {
|
|
267
|
+
messaging_product: "whatsapp";
|
|
268
|
+
to: string;
|
|
269
|
+
type: "video";
|
|
270
|
+
video: GraphMessagesMediaReferencePayload;
|
|
271
|
+
context?: {
|
|
272
|
+
message_id: string;
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
export type GraphMessagesAudioPayload = {
|
|
276
|
+
messaging_product: "whatsapp";
|
|
277
|
+
to: string;
|
|
278
|
+
type: "audio";
|
|
279
|
+
audio: GraphMessagesAudioReferencePayload;
|
|
280
|
+
context?: {
|
|
281
|
+
message_id: string;
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
export type GraphMessagesDocumentPayload = {
|
|
285
|
+
messaging_product: "whatsapp";
|
|
286
|
+
to: string;
|
|
287
|
+
type: "document";
|
|
288
|
+
document: GraphMessagesMediaReferencePayload;
|
|
289
|
+
context?: {
|
|
290
|
+
message_id: string;
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
export type GraphMessagesStickerPayload = {
|
|
294
|
+
messaging_product: "whatsapp";
|
|
295
|
+
to: string;
|
|
296
|
+
type: "sticker";
|
|
297
|
+
sticker: GraphMessagesMediaReferencePayload;
|
|
298
|
+
context?: {
|
|
299
|
+
message_id: string;
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
export type GraphMessagesMediaPayload = GraphMessagesImagePayload | GraphMessagesVideoPayload | GraphMessagesAudioPayload | GraphMessagesDocumentPayload | GraphMessagesStickerPayload;
|
|
303
|
+
export type GraphMessagesLocationPayload = {
|
|
304
|
+
messaging_product: "whatsapp";
|
|
305
|
+
to: string;
|
|
306
|
+
type: "location";
|
|
307
|
+
location: {
|
|
308
|
+
latitude: number;
|
|
309
|
+
longitude: number;
|
|
310
|
+
name?: string;
|
|
311
|
+
address?: string;
|
|
312
|
+
};
|
|
313
|
+
context?: {
|
|
314
|
+
message_id: string;
|
|
315
|
+
};
|
|
316
|
+
};
|
|
317
|
+
export type GraphMessagesContactsPayload = {
|
|
318
|
+
messaging_product: "whatsapp";
|
|
319
|
+
to: string;
|
|
320
|
+
type: "contacts";
|
|
321
|
+
contacts: readonly Record<string, unknown>[];
|
|
322
|
+
context?: {
|
|
323
|
+
message_id: string;
|
|
324
|
+
};
|
|
325
|
+
};
|
|
326
|
+
export type GraphMessagesReactionPayload = {
|
|
327
|
+
messaging_product: "whatsapp";
|
|
328
|
+
to: string;
|
|
329
|
+
type: "reaction";
|
|
330
|
+
reaction: {
|
|
331
|
+
message_id: string;
|
|
332
|
+
emoji: string;
|
|
333
|
+
};
|
|
334
|
+
};
|
|
335
|
+
export type GraphMessagesInteractivePayload = {
|
|
336
|
+
messaging_product: "whatsapp";
|
|
337
|
+
to: string;
|
|
338
|
+
type: "interactive";
|
|
339
|
+
interactive: Record<string, unknown>;
|
|
340
|
+
context?: {
|
|
341
|
+
message_id: string;
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
export type GraphMessagesTemplatePayload = {
|
|
345
|
+
messaging_product: "whatsapp";
|
|
346
|
+
to: string;
|
|
347
|
+
type: "template";
|
|
348
|
+
template: Record<string, unknown>;
|
|
349
|
+
context?: {
|
|
350
|
+
message_id: string;
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
export type GraphMessagesStatusPayload = {
|
|
354
|
+
messaging_product: "whatsapp";
|
|
355
|
+
status: "read";
|
|
356
|
+
message_id: string;
|
|
357
|
+
typing_indicator?: {
|
|
358
|
+
type: "text";
|
|
359
|
+
};
|
|
360
|
+
};
|
|
361
|
+
export type GraphMessagesRemainingPayload = GraphMessagesLocationPayload | GraphMessagesContactsPayload | GraphMessagesReactionPayload | GraphMessagesInteractivePayload | GraphMessagesTemplatePayload | GraphMessagesStatusPayload;
|
|
362
|
+
export type GraphMessagesSendBody = GraphMessagesTextPayload | GraphMessagesMediaPayload | GraphMessagesRemainingPayload;
|
|
363
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const GRAPH_MESSAGES_TEXT_BODY_MAX_LENGTH = 4096;
|
|
2
|
+
export declare const GRAPH_MESSAGES_RECIPIENT_MAX_DIGITS = 15;
|
|
3
|
+
export declare const GRAPH_MESSAGES_REPLY_TO_MESSAGE_ID_MAX_LENGTH = 256;
|
|
4
|
+
export declare const GRAPH_MESSAGES_MEDIA_ID_MAX_LENGTH = 2048;
|
|
5
|
+
export declare const GRAPH_MESSAGES_MEDIA_LINK_MAX_LENGTH = 2048;
|
|
6
|
+
export declare const GRAPH_MESSAGES_MEDIA_CAPTION_MAX_LENGTH = 1024;
|
|
7
|
+
export declare const GRAPH_MESSAGES_DOCUMENT_FILENAME_MAX_LENGTH = 256;
|
|
8
|
+
export declare const GRAPH_MESSAGES_GENERAL_TEXT_MAX_LENGTH = 1024;
|
|
9
|
+
export declare const GRAPH_MESSAGES_SHORT_LABEL_MAX_LENGTH = 60;
|
|
10
|
+
export declare const GRAPH_MESSAGES_BUTTON_TITLE_MAX_LENGTH = 20;
|
|
11
|
+
export declare const GRAPH_MESSAGES_BUTTON_ID_MAX_LENGTH = 256;
|
|
12
|
+
export declare const GRAPH_MESSAGES_SECTION_TITLE_MAX_LENGTH = 24;
|
|
13
|
+
export declare const GRAPH_MESSAGES_ROW_TITLE_MAX_LENGTH = 24;
|
|
14
|
+
export declare const GRAPH_MESSAGES_ROW_DESCRIPTION_MAX_LENGTH = 72;
|
|
15
|
+
export declare const GRAPH_MESSAGES_MAX_REPLY_BUTTONS = 3;
|
|
16
|
+
export declare const GRAPH_MESSAGES_MAX_LIST_SECTIONS = 10;
|
|
17
|
+
export declare const GRAPH_MESSAGES_MAX_LIST_ROWS = 10;
|
|
18
|
+
export declare const GRAPH_MESSAGES_MAX_CONTACTS = 257;
|
|
19
|
+
export declare const GRAPH_MESSAGES_MAX_PRODUCT_ITEMS = 30;
|
|
20
|
+
export declare function isPlainOptionsObject(value: unknown): value is Record<string, unknown>;
|
|
21
|
+
export declare function hasControlChar(value: string): boolean;
|
|
22
|
+
export declare function assertValidRecipient(to: unknown, helperName?: string): string;
|
|
23
|
+
export declare function assertValidText(text: unknown): string;
|
|
24
|
+
export declare function assertValidReplyToMessageId(value: unknown): string;
|
|
25
|
+
export declare function assertNonEmptyControlFreeString(value: unknown, fieldName: string, maxLength: number, helperName: string): string;
|
|
26
|
+
export declare function assertNoUnsupportedMediaFields(input: Record<string, unknown>, helperName: string, options: {
|
|
27
|
+
readonly caption: boolean;
|
|
28
|
+
readonly filename: boolean;
|
|
29
|
+
}): void;
|
|
30
|
+
export declare function assertValidMediaLink(value: unknown, helperName: string): string;
|
|
31
|
+
export declare function assertValidNumberInRange(value: unknown, fieldName: string, min: number, max: number, helperName: string): number;
|
|
32
|
+
export declare function maybeText(value: unknown, fieldName: string, maxLength: number, helperName: string): string | undefined;
|
|
33
|
+
export declare function withReplyContext<T extends object>(payload: T, input: Record<string, unknown>): T & {
|
|
34
|
+
context?: {
|
|
35
|
+
message_id: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export declare function asRecordInput(input: unknown, helperName: string): Record<string, unknown>;
|
|
39
|
+
export declare function assertBoundedArray(value: unknown, fieldName: string, min: number, max: number, helperName: string): readonly unknown[];
|
|
40
|
+
export declare function mapValidatedArray<T>(values: readonly unknown[], mapper: (value: unknown, index: number) => T): T[];
|
|
41
|
+
export declare function assertOnlyKnownKeys(record: Record<string, unknown>, allowed: readonly string[], helperName: string): void;
|
|
42
|
+
export declare function inspectTemplateValue<T>(helperName: string, path: string, inspector: () => T): T;
|
|
43
|
+
export declare function sanitizeTemplateParameter(value: unknown, helperName: string, path: string, seen: WeakSet<object>, depth?: number): unknown;
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { GraphRequestValidationError } from "../../errors.js";
|
|
2
|
+
export const GRAPH_MESSAGES_TEXT_BODY_MAX_LENGTH = 4096;
|
|
3
|
+
export const GRAPH_MESSAGES_RECIPIENT_MAX_DIGITS = 15;
|
|
4
|
+
export const GRAPH_MESSAGES_REPLY_TO_MESSAGE_ID_MAX_LENGTH = 256;
|
|
5
|
+
export const GRAPH_MESSAGES_MEDIA_ID_MAX_LENGTH = 2048;
|
|
6
|
+
export const GRAPH_MESSAGES_MEDIA_LINK_MAX_LENGTH = 2048;
|
|
7
|
+
export const GRAPH_MESSAGES_MEDIA_CAPTION_MAX_LENGTH = 1024;
|
|
8
|
+
export const GRAPH_MESSAGES_DOCUMENT_FILENAME_MAX_LENGTH = 256;
|
|
9
|
+
export const GRAPH_MESSAGES_GENERAL_TEXT_MAX_LENGTH = 1024;
|
|
10
|
+
export const GRAPH_MESSAGES_SHORT_LABEL_MAX_LENGTH = 60;
|
|
11
|
+
export const GRAPH_MESSAGES_BUTTON_TITLE_MAX_LENGTH = 20;
|
|
12
|
+
export const GRAPH_MESSAGES_BUTTON_ID_MAX_LENGTH = 256;
|
|
13
|
+
export const GRAPH_MESSAGES_SECTION_TITLE_MAX_LENGTH = 24;
|
|
14
|
+
export const GRAPH_MESSAGES_ROW_TITLE_MAX_LENGTH = 24;
|
|
15
|
+
export const GRAPH_MESSAGES_ROW_DESCRIPTION_MAX_LENGTH = 72;
|
|
16
|
+
export const GRAPH_MESSAGES_MAX_REPLY_BUTTONS = 3;
|
|
17
|
+
export const GRAPH_MESSAGES_MAX_LIST_SECTIONS = 10;
|
|
18
|
+
export const GRAPH_MESSAGES_MAX_LIST_ROWS = 10;
|
|
19
|
+
export const GRAPH_MESSAGES_MAX_CONTACTS = 257;
|
|
20
|
+
export const GRAPH_MESSAGES_MAX_PRODUCT_ITEMS = 30;
|
|
21
|
+
export function isPlainOptionsObject(value) {
|
|
22
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23
|
+
}
|
|
24
|
+
export function hasControlChar(value) {
|
|
25
|
+
for (let i = 0;i < value.length; i += 1) {
|
|
26
|
+
const code = value.charCodeAt(i);
|
|
27
|
+
if (code < 32 || code === 127)
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
export function assertValidRecipient(to, helperName = "sendText") {
|
|
33
|
+
if (typeof to !== "string") {
|
|
34
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: to must be a phone-number string.`);
|
|
35
|
+
}
|
|
36
|
+
if (to.length === 0 || to.trim().length === 0) {
|
|
37
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: to must be a non-empty phone-number string.`);
|
|
38
|
+
}
|
|
39
|
+
if (hasControlChar(to)) {
|
|
40
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: to must not contain control characters (CR/LF/NUL/etc.).`);
|
|
41
|
+
}
|
|
42
|
+
if (to.includes("/") || to.includes("\\") || to.includes("?") || to.includes("#") || to.includes(":") || to.includes("@")) {
|
|
43
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: to must be a phone-number string, not a path, URL, or address.`);
|
|
44
|
+
}
|
|
45
|
+
if (!/^\+?\d{1,15}$/.test(to)) {
|
|
46
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: to must be E.164-ish digits with optional leading + and at most ${GRAPH_MESSAGES_RECIPIENT_MAX_DIGITS} digits.`);
|
|
47
|
+
}
|
|
48
|
+
return to;
|
|
49
|
+
}
|
|
50
|
+
export function assertValidText(text) {
|
|
51
|
+
if (typeof text !== "string") {
|
|
52
|
+
throw new GraphRequestValidationError("Invalid sendText input: text must be a string.");
|
|
53
|
+
}
|
|
54
|
+
if (text.length === 0 || text.trim().length === 0) {
|
|
55
|
+
throw new GraphRequestValidationError("Invalid sendText input: text must be a non-empty string.");
|
|
56
|
+
}
|
|
57
|
+
if (text.length > GRAPH_MESSAGES_TEXT_BODY_MAX_LENGTH) {
|
|
58
|
+
throw new GraphRequestValidationError(`Invalid sendText input: text exceeds ${GRAPH_MESSAGES_TEXT_BODY_MAX_LENGTH}-character limit.`);
|
|
59
|
+
}
|
|
60
|
+
return text;
|
|
61
|
+
}
|
|
62
|
+
export function assertValidReplyToMessageId(value) {
|
|
63
|
+
if (typeof value !== "string") {
|
|
64
|
+
throw new GraphRequestValidationError("Invalid sendText input: replyToMessageId must be a string when provided.");
|
|
65
|
+
}
|
|
66
|
+
if (value.length === 0 || value.trim().length === 0) {
|
|
67
|
+
throw new GraphRequestValidationError("Invalid sendText input: replyToMessageId must be non-empty when provided.");
|
|
68
|
+
}
|
|
69
|
+
if (hasControlChar(value)) {
|
|
70
|
+
throw new GraphRequestValidationError("Invalid sendText input: replyToMessageId must not contain control characters (CR/LF/NUL/etc.).");
|
|
71
|
+
}
|
|
72
|
+
if (value.length > GRAPH_MESSAGES_REPLY_TO_MESSAGE_ID_MAX_LENGTH) {
|
|
73
|
+
throw new GraphRequestValidationError(`Invalid sendText input: replyToMessageId exceeds ${GRAPH_MESSAGES_REPLY_TO_MESSAGE_ID_MAX_LENGTH}-character limit.`);
|
|
74
|
+
}
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
export function assertNonEmptyControlFreeString(value, fieldName, maxLength, helperName) {
|
|
78
|
+
if (typeof value !== "string") {
|
|
79
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must be a string when provided.`);
|
|
80
|
+
}
|
|
81
|
+
if (value.length === 0 || value.trim().length === 0) {
|
|
82
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must be non-empty when provided.`);
|
|
83
|
+
}
|
|
84
|
+
if (hasControlChar(value)) {
|
|
85
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must not contain control characters (CR/LF/NUL/etc.).`);
|
|
86
|
+
}
|
|
87
|
+
if (value.length > maxLength) {
|
|
88
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} exceeds ${maxLength}-character limit.`);
|
|
89
|
+
}
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
export function assertNoUnsupportedMediaFields(input, helperName, options) {
|
|
93
|
+
if (!options.caption && input.caption !== undefined) {
|
|
94
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: caption is not supported for this media type.`);
|
|
95
|
+
}
|
|
96
|
+
if (!options.filename && input.filename !== undefined) {
|
|
97
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: filename is only supported for document messages.`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export function assertValidMediaLink(value, helperName) {
|
|
101
|
+
const link = assertNonEmptyControlFreeString(value, "link", GRAPH_MESSAGES_MEDIA_LINK_MAX_LENGTH, helperName);
|
|
102
|
+
if (/\s/.test(link)) {
|
|
103
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: link must not contain whitespace.`);
|
|
104
|
+
}
|
|
105
|
+
let url;
|
|
106
|
+
try {
|
|
107
|
+
url = new URL(link);
|
|
108
|
+
} catch {
|
|
109
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: link must be a valid http(s) URL.`);
|
|
110
|
+
}
|
|
111
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
112
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: link must use http or https.`);
|
|
113
|
+
}
|
|
114
|
+
return link;
|
|
115
|
+
}
|
|
116
|
+
export function assertValidNumberInRange(value, fieldName, min, max, helperName) {
|
|
117
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < min || value > max) {
|
|
118
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must be a finite number between ${min} and ${max}.`);
|
|
119
|
+
}
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
export function maybeText(value, fieldName, maxLength, helperName) {
|
|
123
|
+
if (value === undefined)
|
|
124
|
+
return;
|
|
125
|
+
return assertNonEmptyControlFreeString(value, fieldName, maxLength, helperName);
|
|
126
|
+
}
|
|
127
|
+
export function withReplyContext(payload, input) {
|
|
128
|
+
if (input.replyToMessageId === undefined)
|
|
129
|
+
return payload;
|
|
130
|
+
return {
|
|
131
|
+
...payload,
|
|
132
|
+
context: { message_id: assertValidReplyToMessageId(input.replyToMessageId) }
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
export function asRecordInput(input, helperName) {
|
|
136
|
+
if (!isPlainOptionsObject(input)) {
|
|
137
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: expected an options object.`);
|
|
138
|
+
}
|
|
139
|
+
return input;
|
|
140
|
+
}
|
|
141
|
+
function assertArray(value, fieldName, helperName) {
|
|
142
|
+
const isArray = inspectTemplateValue(helperName, fieldName, () => Array.isArray(value));
|
|
143
|
+
if (!isArray) {
|
|
144
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must be an array.`);
|
|
145
|
+
}
|
|
146
|
+
return value;
|
|
147
|
+
}
|
|
148
|
+
export function assertBoundedArray(value, fieldName, min, max, helperName) {
|
|
149
|
+
const arr = assertArray(value, fieldName, helperName);
|
|
150
|
+
const length = inspectTemplateValue(helperName, fieldName, () => arr.length);
|
|
151
|
+
if (!Number.isInteger(length) || length < min || length > max) {
|
|
152
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} length must be between ${min} and ${max}.`);
|
|
153
|
+
}
|
|
154
|
+
for (let i = 0;i < length; i += 1) {
|
|
155
|
+
const hasIndex = inspectTemplateValue(helperName, fieldName, () => (i in arr));
|
|
156
|
+
if (!hasIndex) {
|
|
157
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must not contain sparse array holes.`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const proto = inspectTemplateValue(helperName, fieldName, () => Object.getPrototypeOf(arr));
|
|
161
|
+
if (proto !== Array.prototype) {
|
|
162
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must use Array.prototype.`);
|
|
163
|
+
}
|
|
164
|
+
const descriptors = inspectTemplateValue(helperName, fieldName, () => Object.getOwnPropertyDescriptors(arr));
|
|
165
|
+
if (descriptors.map !== undefined || Object.prototype.hasOwnProperty.call(descriptors, Symbol.iterator)) {
|
|
166
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must not override Array.prototype methods.`);
|
|
167
|
+
}
|
|
168
|
+
const copy = [];
|
|
169
|
+
for (let i = 0;i < length; i += 1) {
|
|
170
|
+
const descriptor = descriptors[String(i)];
|
|
171
|
+
if (descriptor === undefined) {
|
|
172
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must not contain inherited elements.`);
|
|
173
|
+
}
|
|
174
|
+
if (typeof descriptor.get === "function" || typeof descriptor.set === "function") {
|
|
175
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must not use accessors.`);
|
|
176
|
+
}
|
|
177
|
+
copy.push(descriptor.value);
|
|
178
|
+
}
|
|
179
|
+
return copy;
|
|
180
|
+
}
|
|
181
|
+
export function mapValidatedArray(values, mapper) {
|
|
182
|
+
const out = [];
|
|
183
|
+
for (let i = 0;i < values.length; i += 1) {
|
|
184
|
+
out.push(mapper(values[i], i));
|
|
185
|
+
}
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
export function assertOnlyKnownKeys(record, allowed, helperName) {
|
|
189
|
+
const allowedSet = new Set(allowed);
|
|
190
|
+
for (const key of Object.keys(record)) {
|
|
191
|
+
if (!allowedSet.has(key)) {
|
|
192
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: unknown field ${key}.`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
export function inspectTemplateValue(helperName, path, inspector) {
|
|
197
|
+
try {
|
|
198
|
+
return inspector();
|
|
199
|
+
} catch (error) {
|
|
200
|
+
if (error instanceof GraphRequestValidationError)
|
|
201
|
+
throw error;
|
|
202
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} could not be inspected.`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
export function sanitizeTemplateParameter(value, helperName, path, seen, depth = 0) {
|
|
206
|
+
if (depth > 6) {
|
|
207
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} exceeds maximum nesting depth.`);
|
|
208
|
+
}
|
|
209
|
+
if (typeof value === "string") {
|
|
210
|
+
if (value.length === 0 || value.length > GRAPH_MESSAGES_MEDIA_ID_MAX_LENGTH || hasControlChar(value)) {
|
|
211
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} contains an invalid string.`);
|
|
212
|
+
}
|
|
213
|
+
return value;
|
|
214
|
+
}
|
|
215
|
+
if (typeof value === "number") {
|
|
216
|
+
if (!Number.isFinite(value)) {
|
|
217
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} contains a non-finite number.`);
|
|
218
|
+
}
|
|
219
|
+
return value;
|
|
220
|
+
}
|
|
221
|
+
if (value === null || typeof value === "boolean")
|
|
222
|
+
return value;
|
|
223
|
+
if (value === undefined)
|
|
224
|
+
return;
|
|
225
|
+
const maybeObject = value;
|
|
226
|
+
const isArrayValue = inspectTemplateValue(helperName, path, () => Array.isArray(maybeObject));
|
|
227
|
+
if (isArrayValue) {
|
|
228
|
+
const own = inspectTemplateValue(helperName, path, () => Object.getOwnPropertyDescriptors(maybeObject));
|
|
229
|
+
if (Object.prototype.hasOwnProperty.call(own, "toJSON") || inspectTemplateValue(helperName, path, () => ("toJSON" in maybeObject))) {
|
|
230
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} must not define toJSON.`);
|
|
231
|
+
}
|
|
232
|
+
for (const [key, descriptor] of Object.entries(own)) {
|
|
233
|
+
if (typeof descriptor.get === "function" || typeof descriptor.set === "function") {
|
|
234
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path}.${key} must not use accessors.`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return mapValidatedArray(assertBoundedArray(value, path, 0, 100, helperName), (entry, index) => sanitizeTemplateParameter(entry, helperName, `${path}[${index}]`, seen, depth + 1));
|
|
238
|
+
}
|
|
239
|
+
if (!isPlainOptionsObject(value)) {
|
|
240
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} must be JSON-serializable.`);
|
|
241
|
+
}
|
|
242
|
+
const record = value;
|
|
243
|
+
const proto = inspectTemplateValue(helperName, path, () => Object.getPrototypeOf(record));
|
|
244
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
245
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} must be a plain object.`);
|
|
246
|
+
}
|
|
247
|
+
const descriptors = inspectTemplateValue(helperName, path, () => Object.getOwnPropertyDescriptors(record));
|
|
248
|
+
if (Object.prototype.hasOwnProperty.call(descriptors, "toJSON") || inspectTemplateValue(helperName, path, () => ("toJSON" in record))) {
|
|
249
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} must not define toJSON.`);
|
|
250
|
+
}
|
|
251
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
252
|
+
if (typeof descriptor.get === "function" || typeof descriptor.set === "function") {
|
|
253
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path}.${key} must not use accessors.`);
|
|
254
|
+
}
|
|
255
|
+
if (typeof descriptor.value === "function" || typeof descriptor.value === "symbol") {
|
|
256
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path}.${key} must be JSON-serializable.`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (seen.has(record)) {
|
|
260
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} must not contain cycles.`);
|
|
261
|
+
}
|
|
262
|
+
seen.add(record);
|
|
263
|
+
const out = {};
|
|
264
|
+
try {
|
|
265
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
266
|
+
if (key.length === 0 || key.length > GRAPH_MESSAGES_SHORT_LABEL_MAX_LENGTH || hasControlChar(key)) {
|
|
267
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} contains an invalid key.`);
|
|
268
|
+
}
|
|
269
|
+
const sanitized = sanitizeTemplateParameter(descriptor.value, helperName, `${path}.${key}`, seen, depth + 1);
|
|
270
|
+
if (sanitized !== undefined)
|
|
271
|
+
out[key] = sanitized;
|
|
272
|
+
}
|
|
273
|
+
} finally {
|
|
274
|
+
seen.delete(record);
|
|
275
|
+
}
|
|
276
|
+
return out;
|
|
277
|
+
}
|