meta-cloud-api 0.0.2 → 0.0.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.
Files changed (43) hide show
  1. package/README.md +216 -0
  2. package/package.json +34 -4
  3. package/src/api/base.ts +0 -19
  4. package/src/api/encryption.ts +0 -34
  5. package/src/api/flow.ts +0 -253
  6. package/src/api/index.ts +0 -24
  7. package/src/api/media.ts +0 -52
  8. package/src/api/messages.ts +0 -160
  9. package/src/api/phoneNumber.ts +0 -59
  10. package/src/api/qrCode.ts +0 -64
  11. package/src/api/registration.ts +0 -38
  12. package/src/api/template.ts +0 -70
  13. package/src/api/twoStepVerification.ts +0 -24
  14. package/src/api/waba.ts +0 -55
  15. package/src/httpsClient.ts +0 -83
  16. package/src/index.ts +0 -3
  17. package/src/request.ts +0 -104
  18. package/src/types/base.ts +0 -5
  19. package/src/types/config.ts +0 -68
  20. package/src/types/encryption.ts +0 -11
  21. package/src/types/enums.ts +0 -563
  22. package/src/types/flow.ts +0 -274
  23. package/src/types/httpsClient.ts +0 -28
  24. package/src/types/index.ts +0 -16
  25. package/src/types/logger.ts +0 -7
  26. package/src/types/media.ts +0 -31
  27. package/src/types/messages.ts +0 -453
  28. package/src/types/phoneNumber.ts +0 -111
  29. package/src/types/qrCode.ts +0 -30
  30. package/src/types/registration.ts +0 -17
  31. package/src/types/request.ts +0 -66
  32. package/src/types/template.ts +0 -134
  33. package/src/types/twoStepVerification.ts +0 -9
  34. package/src/types/waba.ts +0 -18
  35. package/src/types/whatsapp.ts +0 -31
  36. package/src/utils/.gitkeep +0 -0
  37. package/src/utils/generateXHub256Sig.ts +0 -5
  38. package/src/utils/importConfig.ts +0 -55
  39. package/src/utils/index.ts +0 -2
  40. package/src/utils/isMetaError.ts +0 -44
  41. package/src/utils/logger.ts +0 -46
  42. package/src/utils/objectToQueryString.ts +0 -16
  43. package/src/whatsapp.ts +0 -96
@@ -1,453 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
-
9
- import { BaseClass } from './base';
10
- import {
11
- MessageTypesEnum,
12
- ComponentTypesEnum,
13
- LanguagesEnum,
14
- ParametersTypesEnum,
15
- CurrencyCodesEnum,
16
- ButtonTypesEnum,
17
- ButtonPositionEnum,
18
- InteractiveTypesEnum,
19
- } from './enums';
20
- import { GeneralRequestBody, RequesterResponseInterface } from './request';
21
-
22
- export type GeneralMessageBody = GeneralRequestBody & {
23
- /**
24
- * The Meta messaging product name.
25
- * @default 'whatsapp'
26
- */
27
- messaging_product: 'whatsapp';
28
- };
29
-
30
- export type StatusObject = {
31
- status: 'read';
32
- message_id: string;
33
- };
34
-
35
- export type StatusRequestBody = GeneralMessageBody & StatusObject;
36
-
37
- type ConTextObject = {
38
- message_id: string;
39
- };
40
-
41
- export type MessageRequestBody<T extends MessageTypesEnum> = GeneralMessageBody & {
42
- recipient_type?: string;
43
- to: string;
44
- context?: ConTextObject;
45
- type?: T;
46
- };
47
-
48
- type MetaAudioMediaObject = {
49
- id: string;
50
- link?: never;
51
- };
52
-
53
- type HostedAudioMediaObject = {
54
- id?: never;
55
- link: string;
56
- };
57
-
58
- export type AudioMediaObject = MetaAudioMediaObject | HostedAudioMediaObject;
59
-
60
- export type AudioMessageRequestBody = MessageRequestBody<MessageTypesEnum.Audio> & {
61
- [MessageTypesEnum.Audio]: [AudioMediaObject];
62
- };
63
-
64
- type AddressesObject = {
65
- street?: string;
66
- city?: string;
67
- state?: string;
68
- zip?: string;
69
- country?: string;
70
- country_code?: string;
71
- type?: 'HOME' | 'WORK' | string;
72
- };
73
-
74
- type EmailObject = {
75
- email?: string;
76
- type?: 'HOME' | 'WORK' | string;
77
- };
78
-
79
- type NameObject = {
80
- formatted_name: string;
81
- first_name?: string;
82
- last_name?: string;
83
- middle_name?: string;
84
- suffix?: string;
85
- prefix?: string;
86
- };
87
-
88
- type OrgObject = {
89
- company?: string;
90
- department?: string;
91
- title?: string;
92
- };
93
-
94
- type PhoneObject = {
95
- phone?: 'PHONE_NUMBER';
96
- type?: 'CELL' | 'MAIN' | 'IPHONE' | 'HOME' | 'WORK' | string;
97
- wa_id?: string;
98
- };
99
-
100
- type URLObject = {
101
- url?: string;
102
- type?: 'HOME' | 'WORK' | string;
103
- };
104
-
105
- export type ContactObject = {
106
- addresses?: AddressesObject[];
107
- birthday?: `${number}${number}${number}${number}-${number}${number}-${number}${number}`;
108
- emails?: EmailObject[];
109
- name: NameObject;
110
- org?: OrgObject;
111
- phones?: PhoneObject[];
112
- urls?: URLObject[];
113
- };
114
-
115
- export type ContactsMessageRequestBody = MessageRequestBody<MessageTypesEnum.Contacts> & {
116
- [MessageTypesEnum.Contacts]: [ContactObject];
117
- };
118
-
119
- type MetaDocumentMediaObject = {
120
- id: string;
121
- link?: never;
122
- caption?: string;
123
- filename?: string;
124
- };
125
-
126
- type HostedDocumentMediaObject = {
127
- id?: never;
128
- link: string;
129
- caption?: string;
130
- filename?: string;
131
- };
132
-
133
- export type DocumentMediaObject = MetaDocumentMediaObject | HostedDocumentMediaObject;
134
-
135
- export type DocumentMessageRequestBody = MessageRequestBody<MessageTypesEnum.Document> & {
136
- [MessageTypesEnum.Document]: [DocumentMediaObject];
137
- };
138
-
139
- type MetaImageMediaObject = {
140
- id: string;
141
- link?: never;
142
- caption?: string;
143
- };
144
-
145
- type HostedImageMediaObject = {
146
- id?: never;
147
- link: string;
148
- caption?: string;
149
- };
150
-
151
- export type ImageMediaObject = MetaImageMediaObject | HostedImageMediaObject;
152
-
153
- export type ImageMessageRequestBody = MessageRequestBody<MessageTypesEnum.Image> & {
154
- [MessageTypesEnum.Image]: [ImageMediaObject];
155
- };
156
-
157
- type ProductObject = {
158
- product_retailer_id: string;
159
- };
160
-
161
- type SimpleTextObject = {
162
- text: string;
163
- };
164
-
165
- type RowObject = {
166
- id: string;
167
- title: string;
168
- description?: string;
169
- };
170
-
171
- type MultiProductSectionObject = {
172
- product_items: ProductObject[];
173
- rows?: never;
174
- title?: string;
175
- };
176
-
177
- type ListSectionObject = {
178
- product_items?: never;
179
- rows: RowObject[];
180
- title?: string;
181
- };
182
-
183
- type SectionObject = MultiProductSectionObject | ListSectionObject;
184
-
185
- type ButtonObject = {
186
- title: string;
187
- id: string;
188
- };
189
-
190
- type ReplyButtonObject = {
191
- type: 'reply';
192
- reply: ButtonObject;
193
- };
194
-
195
- type ActionObject = {
196
- button?: string;
197
- buttons?: ReplyButtonObject[];
198
- catalog_id?: string;
199
- product_retailer_id?: string;
200
- sections?: SectionObject;
201
- };
202
-
203
- type HeaderObject = {
204
- type: 'document' | 'image' | 'text' | 'video';
205
- document?: DocumentMediaObject;
206
- image?: ImageMediaObject;
207
- text?: string;
208
- video?: VideoMediaObject;
209
- };
210
-
211
- type ButtonInteractiveObject = {
212
- type: InteractiveTypesEnum.Button;
213
- body: SimpleTextObject;
214
- footer?: SimpleTextObject;
215
- header?: HeaderObject;
216
- action: ActionObject;
217
- };
218
-
219
- type ListInteractiveObject = {
220
- type: InteractiveTypesEnum.List;
221
- body: SimpleTextObject;
222
- footer?: SimpleTextObject;
223
- header?: HeaderObject;
224
- action: ActionObject;
225
- };
226
-
227
- type ProductInteractiveObject = {
228
- type: InteractiveTypesEnum.Product;
229
- body?: SimpleTextObject;
230
- footer?: SimpleTextObject;
231
- header?: HeaderObject;
232
- action: ActionObject;
233
- };
234
-
235
- type ProductListInteractiveObject = {
236
- type: InteractiveTypesEnum.ProductList;
237
- body: SimpleTextObject;
238
- footer?: SimpleTextObject;
239
- header: HeaderObject;
240
- action: ActionObject;
241
- };
242
-
243
- export type InteractiveObject =
244
- | ButtonInteractiveObject
245
- | ListInteractiveObject
246
- | ProductInteractiveObject
247
- | ProductListInteractiveObject;
248
-
249
- export type InteractiveMessageRequestBody = MessageRequestBody<MessageTypesEnum.Interactive> & {
250
- [MessageTypesEnum.Interactive]: InteractiveObject;
251
- };
252
-
253
- type MetaStickerMediaObject = {
254
- id: string;
255
- link?: never;
256
- };
257
-
258
- type HostedStickerMediaObject = {
259
- id?: never;
260
- link: string;
261
- };
262
-
263
- export type StickerMediaObject = MetaStickerMediaObject | HostedStickerMediaObject;
264
-
265
- export type StickerMessageRequestBody = MessageRequestBody<MessageTypesEnum.Sticker> & {
266
- [MessageTypesEnum.Sticker]: [StickerMediaObject];
267
- };
268
-
269
- type ReActionObject = {
270
- message_id: string;
271
- emoji: string;
272
- };
273
-
274
- export type ReactionMessageRequestBody = MessageRequestBody<MessageTypesEnum.Reaction> & ReActionObject;
275
-
276
- export type TextObject = {
277
- body: string;
278
- preview_url?: boolean;
279
- };
280
-
281
- export type TextMessageRequestBody = MessageRequestBody<MessageTypesEnum.Text> & {
282
- [MessageTypesEnum.Text]: [TextObject];
283
- };
284
-
285
- type MetaHostedVideoMediaObject = {
286
- id: string;
287
- link?: never;
288
- caption?: string;
289
- };
290
-
291
- type SelfHostedVideoMediaObject = {
292
- id?: never;
293
- link: string;
294
- caption?: string;
295
- };
296
-
297
- export type VideoMediaObject = MetaHostedVideoMediaObject | SelfHostedVideoMediaObject;
298
-
299
- export type VideoMessageRequestBody = MessageRequestBody<MessageTypesEnum.Video> & {
300
- [MessageTypesEnum.Video]: [VideoMediaObject];
301
- };
302
-
303
- type LanguageObject = {
304
- policy: 'deterministic';
305
- code: LanguagesEnum;
306
- };
307
-
308
- type ParametersObject<T extends ParametersTypesEnum> = {
309
- type: T;
310
- };
311
-
312
- type TextParametersObject = ParametersObject<ParametersTypesEnum.Text> & SimpleTextObject;
313
-
314
- type CurrencyObject = {
315
- fallback_value: string;
316
- code: CurrencyCodesEnum;
317
- amount_1000: number;
318
- };
319
-
320
- type CurrencyParametersObject = ParametersObject<ParametersTypesEnum.Currency> & {
321
- currency: CurrencyObject;
322
- };
323
-
324
- type DateTimeObject = {
325
- fallback_value: string;
326
- };
327
-
328
- type DateTimeParametersObject = ParametersObject<ParametersTypesEnum.Currency> & {
329
- date_time: DateTimeObject;
330
- };
331
-
332
- type DocumentParametersObject = ParametersObject<ParametersTypesEnum.Document> & DocumentMediaObject;
333
-
334
- type ImageParametersObject = ParametersObject<ParametersTypesEnum.Image> & ImageMediaObject;
335
-
336
- type VideoParametersObject = ParametersObject<ParametersTypesEnum.Video> & VideoMediaObject;
337
-
338
- type QuickReplyButtonParametersObject = {
339
- type: ParametersTypesEnum.Payload;
340
- payload: string;
341
- };
342
-
343
- type URLButtonParametersObject = SimpleTextObject & {
344
- type: ParametersTypesEnum.Text;
345
- };
346
-
347
- type ButtonParameterObject = QuickReplyButtonParametersObject | URLButtonParametersObject;
348
-
349
- type ComponentObject<T extends ComponentTypesEnum> = {
350
- type: T;
351
- parameters: (
352
- | CurrencyParametersObject
353
- | DateTimeParametersObject
354
- | DocumentParametersObject
355
- | ImageParametersObject
356
- | TextParametersObject
357
- | VideoParametersObject
358
- )[];
359
- };
360
-
361
- type ButtonComponentObject = ComponentObject<ComponentTypesEnum.Button> & {
362
- parameters: ButtonParameterObject;
363
- sub_type: ButtonTypesEnum;
364
- index: ButtonPositionEnum;
365
- };
366
-
367
- export type MessageTemplateObject<T extends ComponentTypesEnum> = {
368
- name: string;
369
- language: LanguageObject;
370
- components?: (ComponentObject<T> | ButtonComponentObject)[];
371
- };
372
-
373
- export type MessageTemplateRequestBody<T extends ComponentTypesEnum> = MessageRequestBody<MessageTypesEnum.Template> &
374
- MessageTemplateObject<T>;
375
-
376
- export type LocationObject = {
377
- longitude: number;
378
- latitude: number;
379
- name?: string;
380
- address?: string;
381
- };
382
-
383
- export type LocationMessageRequestBody = MessageRequestBody<MessageTypesEnum.Location> & {
384
- [MessageTypesEnum.Location]: [LocationObject];
385
- };
386
-
387
- export type MessagesResponse = GeneralMessageBody & {
388
- contacts: [
389
- {
390
- input: string;
391
- wa_id: string;
392
- },
393
- ];
394
- messages: [
395
- {
396
- id: string;
397
- },
398
- ];
399
- };
400
-
401
- export declare class MessagesClass extends BaseClass {
402
- audio(
403
- body: AudioMediaObject,
404
- recipient: number,
405
- replyMessageId?: string,
406
- ): Promise<RequesterResponseInterface<MessagesResponse>>;
407
- contacts(
408
- body: [ContactObject],
409
- recipient: number,
410
- replyMessageId?: string,
411
- ): Promise<RequesterResponseInterface<MessagesResponse>>;
412
- document(
413
- body: DocumentMediaObject,
414
- recipient: number,
415
- replyMessageId?: string,
416
- ): Promise<RequesterResponseInterface<MessagesResponse>>;
417
- image(
418
- body: ImageMediaObject,
419
- recipient: number,
420
- replyMessageId?: string,
421
- ): Promise<RequesterResponseInterface<MessagesResponse>>;
422
- interactive(
423
- body: InteractiveObject,
424
- recipient: number,
425
- replyMessageId?: string,
426
- ): Promise<RequesterResponseInterface<MessagesResponse>>;
427
- location(
428
- body: LocationObject,
429
- recipient: number,
430
- replyMessageId?: string,
431
- ): Promise<RequesterResponseInterface<MessagesResponse>>;
432
- status(body: StatusObject): Promise<RequesterResponseInterface<MessagesResponse>>;
433
- sticker(
434
- body: StickerMediaObject,
435
- recipient: number,
436
- replyMessageId?: string,
437
- ): Promise<RequesterResponseInterface<MessagesResponse>>;
438
- template(
439
- body: MessageTemplateObject<ComponentTypesEnum>,
440
- recipient: number,
441
- replyMessageId?: string,
442
- ): Promise<RequesterResponseInterface<MessagesResponse>>;
443
- text(
444
- body: TextObject,
445
- recipient: number,
446
- replyMessageId?: string,
447
- ): Promise<RequesterResponseInterface<MessagesResponse>>;
448
- video(
449
- body: VideoMediaObject,
450
- recipient: number,
451
- replyMessageId?: string,
452
- ): Promise<RequesterResponseInterface<MessagesResponse>>;
453
- }
@@ -1,111 +0,0 @@
1
- import { Paging, RequesterResponseInterface, ResponseData, ResponseSuccess } from './request';
2
-
3
- export type QualityRating = 'GREEN' | 'YELLOW' | 'RED' | 'NA';
4
-
5
- export type AccountMode = 'LIVE' | 'SANDBOX';
6
-
7
- export type CodeVerificationStatus =
8
- | 'NOT_VERIFIED'
9
- | 'VERIFIED'
10
- | 'EXPIRED'
11
- | 'PENDING'
12
- | 'DELETED'
13
- | 'MIGRATED'
14
- | 'BANNED'
15
- | 'RESTRICTED'
16
- | 'RATE_LIMITED'
17
- | 'FLAGGED'
18
- | 'CONNECTED'
19
- | 'DISCONNECTED'
20
- | 'UNKNOWN'
21
- | 'UNVERIFIED';
22
-
23
- export type MessagingLimitTier = 'TIER_50' | 'TIER_250' | 'TIER_1K' | 'TIER_10K' | 'TIER_100K' | 'TIER_UNLIMITED';
24
-
25
- export type PlatformType = 'CLOUD_API' | 'ON_PREMISE' | 'NOT_APPLICABLE';
26
-
27
- export type ThroughputLevel = 'STANDARD' | 'HIGH' | 'NOT_APPLICABLE';
28
-
29
- export type HealthStatusEntity = {
30
- entity_type: string;
31
- id: string;
32
- can_send_message: string;
33
- additional_info?: string[];
34
- errors?: Array<{
35
- error_code: number;
36
- error_description: string;
37
- possible_solution: string;
38
- }>;
39
- };
40
-
41
- export type HealthStatus = {
42
- can_send_message: string;
43
- entities: HealthStatusEntity[];
44
- };
45
-
46
- export type QualityScore = {
47
- score: QualityRating;
48
- };
49
-
50
- export type Throughput = {
51
- level: ThroughputLevel;
52
- };
53
-
54
- export type PhoneNumberResponse = {
55
- display_phone_number: string;
56
- id: string;
57
- quality_rating: QualityRating;
58
- verified_name: string;
59
- account_mode?: AccountMode;
60
- certificate?: string;
61
- code_verification_status?: CodeVerificationStatus;
62
- conversational_automation?: Record<string, unknown>;
63
- eligibility_for_api_business_global_search?: string;
64
- health_status?: HealthStatus;
65
- is_official_business_account?: boolean;
66
- is_on_biz_app?: boolean;
67
- is_pin_enabled?: boolean;
68
- is_preverified_number?: boolean;
69
- last_onboarded_time?: string;
70
- messaging_limit_tier?: MessagingLimitTier;
71
- name_status?: string;
72
- new_certificate?: string;
73
- new_name_status?: string;
74
- platform_type?: PlatformType;
75
- quality_score?: QualityScore;
76
- search_visibility?: string;
77
- status?: CodeVerificationStatus;
78
- throughput?: Throughput;
79
- };
80
-
81
- export type Cursors = {
82
- before: string;
83
- after: string;
84
- };
85
-
86
- export type PhoneNumbersResponse = {
87
- data: PhoneNumberResponse[];
88
- paging: Paging;
89
- };
90
-
91
- export type RequestVerificationCodeRequest = {
92
- code_method: 'SMS' | 'VOICE';
93
- language: string;
94
- };
95
-
96
- export type VerifyCodeRequest = {
97
- code: string;
98
- };
99
-
100
- export type TwoStepVerificationParams = {
101
- pin: string;
102
- };
103
-
104
- export declare class PhoneNumberClass {
105
- getPhoneNumberById(fields?: string): Promise<RequesterResponseInterface<PhoneNumberResponse>>;
106
- getPhoneNumbers(): Promise<RequesterResponseInterface<PhoneNumbersResponse>>;
107
- requestVerificationCode(
108
- params: RequestVerificationCodeRequest,
109
- ): Promise<RequesterResponseInterface<ResponseSuccess>>;
110
- verifyCode(params: VerifyCodeRequest): Promise<RequesterResponseInterface<ResponseSuccess>>;
111
- }
@@ -1,30 +0,0 @@
1
- import { ResponseSuccess } from './request';
2
-
3
- import { RequesterResponseInterface, ResponseData } from './request';
4
-
5
- export type QrCodeResponse = {
6
- code: string;
7
- prefilled_message: string;
8
- deep_link_url: string;
9
- qr_image_url?: string;
10
- };
11
-
12
- export type QrCodesResponse = ResponseData<QrCodeResponse[]>;
13
-
14
- export type CreateQrCodeRequest = {
15
- prefilled_message: string;
16
- generate_qr_image?: 'SVG' | 'PNG';
17
- };
18
-
19
- export type UpdateQrCodeRequest = {
20
- code: string;
21
- prefilled_message: string;
22
- };
23
-
24
- export interface QrCodeClass {
25
- createQrCode(request: CreateQrCodeRequest): Promise<RequesterResponseInterface<QrCodeResponse>>;
26
- getQrCodes(): Promise<RequesterResponseInterface<QrCodesResponse>>;
27
- getQrCode(qrCodeId: string): Promise<RequesterResponseInterface<QrCodeResponse>>;
28
- updateQrCode(request: UpdateQrCodeRequest): Promise<RequesterResponseInterface<QrCodeResponse>>;
29
- deleteQrCode(qrCodeId: string): Promise<RequesterResponseInterface<ResponseSuccess>>;
30
- }
@@ -1,17 +0,0 @@
1
- import { RequesterResponseInterface, ResponseSuccess } from './request';
2
- import { DataLocalizationRegionEnum } from './enums';
3
-
4
- export type RegistrationRequest = {
5
- messaging_product: 'whatsapp';
6
- pin: string;
7
- data_localization_region?: DataLocalizationRegionEnum;
8
- };
9
-
10
- export interface RegistrationClass {
11
- register(
12
- pin: string,
13
- dataLocalizationRegion?: DataLocalizationRegionEnum,
14
- ): Promise<RequesterResponseInterface<ResponseSuccess>>;
15
-
16
- deregister(): Promise<RequesterResponseInterface<ResponseSuccess>>;
17
- }
@@ -1,66 +0,0 @@
1
- import { HttpMethodsEnum } from './enums';
2
-
3
- export type GeneralRequestBody = Record<string, any>;
4
-
5
- export interface GeneralHeaderInterface {
6
- /**
7
- * Authorization token. This is required for all HTTP requests made to the graph API.
8
- * @default 'Bearer '
9
- */
10
- Authorization: string;
11
-
12
- /**
13
- * Content type of the message being sent. This is required for all HTTP requests made to the graph API.
14
- * @default 'application/json'
15
- */
16
- 'Content-Type': string;
17
-
18
- /**
19
- * User agent field sent in all requests. This is used to gather SDK usage metrics and help
20
- * better triage support requests.
21
- * @default `WA_SDK/${ SDK_version } (Node.js ${ process.version })`
22
- */
23
- 'User-Agent': string;
24
- }
25
-
26
- export interface RequesterResponseInterface<T> {
27
- json: () => Promise<T>;
28
- }
29
-
30
- export interface ResponseSuccess {
31
- success: boolean;
32
- }
33
-
34
- export interface ResponseData<T> {
35
- data: T;
36
- }
37
-
38
- export interface ResponsePagination<T> {
39
- data: T[];
40
- paging: Paging;
41
- }
42
-
43
- export interface Paging {
44
- cursors: {
45
- before: string;
46
- after: string;
47
- };
48
- next: string;
49
- }
50
-
51
- export declare class RequesterClass {
52
- constructor(
53
- host: string,
54
- apiVersion: string,
55
- phoneNumberId: number,
56
- accessToken: string,
57
- businessAcctId: string,
58
- userAgent: string,
59
- );
60
- sendRequest: (
61
- method: HttpMethodsEnum,
62
- path: string,
63
- timeout: number,
64
- body?: any,
65
- ) => Promise<RequesterResponseInterface<any>>;
66
- }