meta-cloud-api 0.2.31 → 0.2.33

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.
@@ -0,0 +1,507 @@
1
+ import { b as ResponseSuccess, a as BaseAPI, R as RequesterClass } from './base-BG2gtoDs.js';
2
+ import { WabaConfigType } from './shared/types/config.js';
3
+
4
+ /**
5
+ * Enum for Flow Status
6
+ */
7
+ declare enum FlowStatusEnum {
8
+ Draft = "DRAFT",
9
+ Published = "PUBLISHED",
10
+ Throttled = "THROTTLED",
11
+ Blocked = "BLOCKED",
12
+ Deprecated = "DEPRECATED"
13
+ }
14
+ /**
15
+ * Enum for Flow Categories
16
+ */
17
+ declare enum FlowCategoryEnum {
18
+ SignUp = "SIGN_UP",
19
+ SignIn = "SIGN_IN",
20
+ AppointmentBooking = "APPOINTMENT_BOOKING",
21
+ LeadGeneration = "LEAD_GENERATION",
22
+ ContactUs = "CONTACT_US",
23
+ CustomerSupport = "CUSTOMER_SUPPORT",
24
+ Survey = "SURVEY",
25
+ Other = "OTHER"
26
+ }
27
+ declare enum FlowActionEnum {
28
+ INIT = "INIT",
29
+ BACK = "BACK",
30
+ DATA_EXCHANGE = "data_exchange"
31
+ }
32
+ /**
33
+ * Enum for Flow Types in webhook handlers
34
+ * Used to register handlers for specific flow events
35
+ */
36
+ declare enum FlowTypeEnum {
37
+ /** Health check/ping requests */
38
+ Ping = "ping",
39
+ /** Data exchange requests */
40
+ Change = "data_exchange",
41
+ /** Error notification requests */
42
+ Error = "error",
43
+ /** Match all flow action types */
44
+ All = "*"
45
+ }
46
+ type FlowType = (typeof FlowTypeEnum)[keyof typeof FlowTypeEnum];
47
+ /**
48
+ * Flow Validation Error Pointer
49
+ */
50
+ interface FlowValidationErrorPointer {
51
+ line_start: number;
52
+ line_end: number;
53
+ column_start: number;
54
+ column_end: number;
55
+ path: string;
56
+ }
57
+ /**
58
+ * Flow Validation Error
59
+ */
60
+ interface FlowValidationError {
61
+ error: string;
62
+ error_type: string;
63
+ message: string;
64
+ line_start: number;
65
+ line_end: number;
66
+ column_start: number;
67
+ column_end: number;
68
+ pointers: FlowValidationErrorPointer[];
69
+ }
70
+ /**
71
+ * Flow Item
72
+ */
73
+ interface Flow {
74
+ id: string;
75
+ name: string;
76
+ status: FlowStatusEnum;
77
+ categories: FlowCategoryEnum[];
78
+ validation_errors: FlowValidationError[];
79
+ }
80
+ /**
81
+ * Pagination Cursors
82
+ */
83
+ interface PaginationCursors {
84
+ before: string;
85
+ after: string;
86
+ }
87
+ /**
88
+ * Pagination Object
89
+ */
90
+ interface Pagination {
91
+ cursors: PaginationCursors;
92
+ }
93
+ /**
94
+ * Flows List Response
95
+ */
96
+ interface FlowsListResponse {
97
+ data: Flow[];
98
+ paging: Pagination;
99
+ }
100
+ /**
101
+ * Flow Asset
102
+ */
103
+ interface FlowAsset {
104
+ name: string;
105
+ asset_type: string;
106
+ download_url: string;
107
+ }
108
+ /**
109
+ * Flow Assets Response
110
+ */
111
+ interface FlowAssetsResponse {
112
+ data: FlowAsset[];
113
+ paging: Pagination;
114
+ }
115
+ /**
116
+ * Flow Preview
117
+ */
118
+ interface FlowPreview {
119
+ preview_url: string;
120
+ expires_at: string;
121
+ }
122
+ /**
123
+ * Flow Preview Response
124
+ */
125
+ interface FlowPreviewResponse {
126
+ preview: FlowPreview;
127
+ id: string;
128
+ }
129
+ /**
130
+ * Flow Migration Result
131
+ */
132
+ interface FlowMigrationResult {
133
+ source_name: string;
134
+ source_id: string;
135
+ migrated_id: string;
136
+ }
137
+ /**
138
+ * Flow Migration Failure
139
+ */
140
+ interface FlowMigrationFailure {
141
+ source_name: string;
142
+ error_code: string;
143
+ error_message: string;
144
+ }
145
+ /**
146
+ * Create Flow Response
147
+ */
148
+ interface CreateFlowResponse {
149
+ id: string;
150
+ success: boolean;
151
+ validation_errors?: FlowValidationError[];
152
+ }
153
+ /**
154
+ * Update Flow Response
155
+ */
156
+ interface UpdateFlowResponse {
157
+ success: boolean;
158
+ validation_errors?: FlowValidationError[];
159
+ }
160
+ /**
161
+ * Flow Migration Response
162
+ */
163
+ interface FlowMigrationResponse {
164
+ migrated_flows: FlowMigrationResult[];
165
+ failed_flows: FlowMigrationFailure[];
166
+ }
167
+ /**
168
+ * Validate Flow JSON Response
169
+ */
170
+ interface ValidateFlowJsonResponse {
171
+ valid: boolean;
172
+ success: boolean;
173
+ validation_errors?: FlowValidationError[];
174
+ }
175
+ /**
176
+ * WhatsApp Flow Endpoint - Health Check Request
177
+ * Represents the structure of a health check request
178
+ */
179
+ interface FlowHealthCheckRequest {
180
+ action: 'ping';
181
+ version: '3.0';
182
+ }
183
+ /**
184
+ * WhatsApp Flow Endpoint - Health Check Response
185
+ * The expected response structure for health check requests
186
+ */
187
+ interface FlowHealthCheckResponse {
188
+ data: {
189
+ status: 'active';
190
+ };
191
+ }
192
+ /**
193
+ * WhatsApp Flow Endpoint - Data Exchange Request
194
+ * Represents the structure of a data exchange request
195
+ */
196
+ interface FlowDataExchangeRequest {
197
+ version: '3.0';
198
+ action: FlowActionEnum;
199
+ screen: string;
200
+ flow_token: string;
201
+ data?: Record<string, any> & {
202
+ error_message?: string;
203
+ };
204
+ }
205
+ /**
206
+ * WhatsApp Flow Endpoint - Data Exchange Response
207
+ * The expected response structure for data exchange requests
208
+ */
209
+ interface FlowDataExchangeResponse {
210
+ screen?: string;
211
+ data?: Record<string, any | {
212
+ error_message?: string;
213
+ }>;
214
+ }
215
+ /**
216
+ * WhatsApp Flow Endpoint - Success Screen Response
217
+ * The expected response structure for success screen requests
218
+ */
219
+ interface FlowSuccessScreenResponse {
220
+ screen: 'SUCCESS';
221
+ data: {
222
+ extension_message_response?: {
223
+ params?: {
224
+ flow_token: string;
225
+ [key: string]: string;
226
+ };
227
+ };
228
+ };
229
+ }
230
+ /**
231
+ * WhatsApp Flow Endpoint - Error Notification Request
232
+ * Represents the structure of an error notification request
233
+ */
234
+ interface FlowErrorNotificationRequest {
235
+ version: '3.0';
236
+ action: Exclude<FlowActionEnum, FlowActionEnum.BACK>;
237
+ screen: string;
238
+ flow_token: string;
239
+ data: {
240
+ error: string;
241
+ error_message: string;
242
+ };
243
+ }
244
+ /**
245
+ * WhatsApp Flow Endpoint - Error Notification Response
246
+ * The expected response structure for error notification requests
247
+ */
248
+ interface FlowErrorNotificationResponse {
249
+ acknowledged: boolean;
250
+ }
251
+ /**
252
+ * WhatsApp Flow Endpoint - Comprehensive Request Object
253
+ * A combined type that includes all possible fields from different request types
254
+ * with all fields being optional for flexibility
255
+ */
256
+ interface FlowEndpointRequest {
257
+ version?: '3.0';
258
+ action?: 'ping' | FlowActionEnum;
259
+ screen?: string;
260
+ flow_token?: string;
261
+ data?: Record<string, any> & {
262
+ error_key?: string;
263
+ error_message?: string;
264
+ };
265
+ }
266
+ /**
267
+ * WhatsApp Flow Endpoint - Response
268
+ * Union type for all possible response types from a Flow endpoint
269
+ */
270
+ type FlowEndpointResponse = FlowHealthCheckResponse | FlowDataExchangeResponse | FlowErrorNotificationResponse | FlowSuccessScreenResponse;
271
+ interface FlowClass {
272
+ /**
273
+ * List Flows
274
+ *
275
+ * @param wabaId - The WABA ID
276
+ * @returns Promise with the list of flows
277
+ */
278
+ listFlows(wabaId: string): Promise<FlowsListResponse>;
279
+ /**
280
+ * Create Flow
281
+ *
282
+ * @param wabaId - The WABA ID
283
+ * @param data - The flow data including name, categories, endpoint_uri, and optional clone_flow_id
284
+ * @returns Promise with the created flow ID
285
+ */
286
+ createFlow(wabaId: string, data: {
287
+ name: string;
288
+ categories?: FlowCategoryEnum[];
289
+ endpoint_uri?: string;
290
+ clone_flow_id?: string;
291
+ flow_json?: string;
292
+ publish?: boolean;
293
+ }): Promise<CreateFlowResponse>;
294
+ /**
295
+ * Get Flow
296
+ *
297
+ * @param flowId - The flow ID
298
+ * @param fields - Optional fields to return
299
+ * @param dateFormat - Optional date format
300
+ * @returns Promise with the flow details
301
+ */
302
+ getFlow(flowId: string, fields?: string, dateFormat?: string): Promise<Flow | FlowPreviewResponse>;
303
+ /**
304
+ * Update Flow Metadata
305
+ *
306
+ * @param flowId - The flow ID
307
+ * @param data - The flow metadata to update
308
+ * @returns Promise with the success status
309
+ */
310
+ updateFlowMetadata(flowId: string, data: {
311
+ name?: string;
312
+ categories?: FlowCategoryEnum[];
313
+ endpoint_uri?: string;
314
+ application_id?: string;
315
+ }): Promise<ResponseSuccess>;
316
+ /**
317
+ * Delete Flow
318
+ *
319
+ * @param flowId - The flow ID
320
+ * @returns Promise with the success status
321
+ */
322
+ deleteFlow(flowId: string): Promise<ResponseSuccess>;
323
+ /**
324
+ * List Assets (Get Flow JSON URL)
325
+ *
326
+ * @param flowId - The flow ID
327
+ * @returns Promise with the list of assets
328
+ */
329
+ listAssets(flowId: string): Promise<FlowAssetsResponse>;
330
+ /**
331
+ * Update Flow JSON
332
+ *
333
+ * @param flowId - The flow ID
334
+ * @param data - The asset data including asset_type, file, and name
335
+ * @returns Promise with the success status and validation errors
336
+ */
337
+ updateFlowJson(flowId: string, data: {
338
+ file: Blob | Buffer | object;
339
+ name?: string;
340
+ }): Promise<UpdateFlowResponse>;
341
+ /**
342
+ * Validate Flow JSON by attempting an update without publishing.
343
+ * This is a convenience method; the API doesn't have a dedicated validation endpoint.
344
+ *
345
+ * @param flowId - The ID of the Flow (must exist, can be in DRAFT status).
346
+ * @param flowJsonData - The Flow JSON content as a Buffer, JSON object, or Blob.
347
+ * @returns Promise indicating if the JSON is valid and includes validation errors if any.
348
+ */
349
+ validateFlowJson(flowId: string, flowJsonData: Blob | Buffer | object): Promise<ValidateFlowJsonResponse>;
350
+ /**
351
+ * Publish Flow
352
+ *
353
+ * @param flowId - The flow ID
354
+ * @returns Promise with the success status
355
+ */
356
+ publishFlow(flowId: string): Promise<ResponseSuccess>;
357
+ /**
358
+ * Deprecate Flow
359
+ *
360
+ * @param flowId - The flow ID
361
+ * @returns Promise with the success status
362
+ */
363
+ deprecateFlow(flowId: string): Promise<ResponseSuccess>;
364
+ /**
365
+ * Migrate Flows
366
+ *
367
+ * @param wabaId - The destination WABA ID
368
+ * @param data - The migration data including source_waba_id and optional source_flow_names
369
+ * @returns Promise with migration results
370
+ */
371
+ migrateFlows(wabaId: string, data: {
372
+ source_waba_id: string;
373
+ source_flow_names?: string[];
374
+ }): Promise<FlowMigrationResponse>;
375
+ }
376
+
377
+ /**
378
+ * API for managing WhatsApp Flows.
379
+ *
380
+ * This API allows you to:
381
+ * - List flows
382
+ * - Create flows
383
+ * - Get flow details and previews
384
+ * - Update flow metadata and JSON
385
+ * - Delete flows
386
+ * - Publish and deprecate flows
387
+ * - Migrate flows between WABAs
388
+ * - Validate flow JSON
389
+ */
390
+ declare class FlowApi extends BaseAPI implements FlowClass {
391
+ constructor(config: WabaConfigType, client: RequesterClass);
392
+ /**
393
+ * List Flows
394
+ *
395
+ * @param wabaId - The WABA ID
396
+ * @returns Promise with the list of flows
397
+ */
398
+ listFlows(wabaId: string): Promise<FlowsListResponse>;
399
+ /**
400
+ * Create Flow
401
+ *
402
+ * @param wabaId - The WABA ID
403
+ * @param data - The flow data including name, categories, endpoint_uri, and optional clone_flow_id
404
+ * @returns Promise with the created flow ID and validation errors if any
405
+ */
406
+ createFlow(wabaId: string, data: {
407
+ name: string;
408
+ categories?: FlowCategoryEnum[];
409
+ endpoint_uri?: string;
410
+ clone_flow_id?: string;
411
+ flow_json?: string;
412
+ publish?: boolean;
413
+ }): Promise<CreateFlowResponse>;
414
+ /**
415
+ * Get Flow details
416
+ *
417
+ * @param flowId - The flow ID
418
+ * @param fields - Optional fields to return (e.g., 'name,status,preview.invalidate(false)')
419
+ * @param dateFormat - Optional date format
420
+ * @returns Promise with the flow details or preview response
421
+ */
422
+ getFlow(flowId: string, fields?: string, dateFormat?: string): Promise<Flow | FlowPreviewResponse>;
423
+ /**
424
+ * Get Flow Preview URL
425
+ *
426
+ * @param flowId - The flow ID
427
+ * @param invalidate - Optional. If true, invalidates existing preview and generates a new one. Defaults to false.
428
+ * @returns Promise with the flow preview details
429
+ */
430
+ getFlowPreview(flowId: string, invalidate?: boolean): Promise<FlowPreviewResponse>;
431
+ /**
432
+ * Update Flow Metadata
433
+ *
434
+ * @param flowId - The flow ID
435
+ * @param data - The flow metadata to update (name, categories, endpoint_uri, application_id)
436
+ * @returns Promise with the success status
437
+ */
438
+ updateFlowMetadata(flowId: string, data: {
439
+ name?: string;
440
+ categories?: FlowCategoryEnum[];
441
+ endpoint_uri?: string;
442
+ application_id?: string;
443
+ }): Promise<ResponseSuccess>;
444
+ /**
445
+ * Delete Flow (only works if the Flow is in DRAFT status)
446
+ *
447
+ * @param flowId - The flow ID
448
+ * @returns Promise with the success status
449
+ */
450
+ deleteFlow(flowId: string): Promise<ResponseSuccess>;
451
+ /**
452
+ * List Assets (e.g., get Flow JSON download URL)
453
+ *
454
+ * @param flowId - The flow ID
455
+ * @returns Promise with the list of assets
456
+ */
457
+ listAssets(flowId: string): Promise<FlowAssetsResponse>;
458
+ /**
459
+ * Update Flow JSON by uploading a file, buffer, JSON object, or Blob.
460
+ *
461
+ * @param flowId - The flow ID
462
+ * @param data - Object containing the file data and optional name.
463
+ * @param data.file - The Flow JSON content as a Buffer, JSON object, or Blob.
464
+ * @param data.name - Optional name for the asset, defaults to 'flow.json'.
465
+ * @returns Promise with the success status and validation errors, if any.
466
+ */
467
+ updateFlowJson(flowId: string, data: {
468
+ file: Blob | Buffer | object;
469
+ name?: string;
470
+ }): Promise<UpdateFlowResponse>;
471
+ /**
472
+ * Validate Flow JSON by attempting an update without publishing.
473
+ * This is a convenience method; the API doesn't have a dedicated validation endpoint.
474
+ *
475
+ * @param flowId - The ID of the Flow (must exist, can be in DRAFT status).
476
+ * @param flowJsonData - The Flow JSON content as a file path (string), Buffer, JSON object, or Blob.
477
+ * @returns Promise indicating if the JSON is valid and includes validation errors if any.
478
+ */
479
+ validateFlowJson(flowId: string, flowJsonData: Blob | Buffer | object): Promise<ValidateFlowJsonResponse>;
480
+ /**
481
+ * Publish Flow
482
+ *
483
+ * @param flowId - The flow ID
484
+ * @returns Promise with the success status
485
+ */
486
+ publishFlow(flowId: string): Promise<ResponseSuccess>;
487
+ /**
488
+ * Deprecate Flow
489
+ *
490
+ * @param flowId - The flow ID
491
+ * @returns Promise with the success status
492
+ */
493
+ deprecateFlow(flowId: string): Promise<ResponseSuccess>;
494
+ /**
495
+ * Migrate Flows between WABAs
496
+ *
497
+ * @param destinationWabaId - The destination WABA ID
498
+ * @param data - The migration data including source_waba_id and optional source_flow_names
499
+ * @returns Promise with migration results (successes and failures)
500
+ */
501
+ migrateFlows(destinationWabaId: string, data: {
502
+ source_waba_id: string;
503
+ source_flow_names?: string[];
504
+ }): Promise<FlowMigrationResponse>;
505
+ }
506
+
507
+ export { type CreateFlowResponse as C, FlowApi as F, type UpdateFlowResponse as U, type ValidateFlowJsonResponse as V, type FlowEndpointRequest as a, type FlowDataExchangeRequest as b, FlowActionEnum as c, type FlowErrorNotificationRequest as d, type FlowHealthCheckRequest as e, type FlowType as f, type Flow as g, type FlowClass as h, type FlowEndpointResponse as i, FlowTypeEnum as j, type FlowAssetsResponse as k, FlowCategoryEnum as l, type FlowMigrationResponse as m, type FlowPreviewResponse as n, type FlowsListResponse as o, FlowStatusEnum as p, type FlowValidationError as q };
@@ -0,0 +1,89 @@
1
+ import { b as ResponseSuccess, a as BaseAPI, R as RequesterClass } from './base-BG2gtoDs.js';
2
+ import { WabaConfigType } from './shared/types/config.js';
3
+
4
+ type MediaResponse = {
5
+ id: string;
6
+ url: string;
7
+ mime_type: string;
8
+ sha256: string;
9
+ file_size: number;
10
+ messaging_product: 'whatsapp';
11
+ };
12
+ type MediasResponse = {
13
+ data: MediaResponse[];
14
+ paging: {
15
+ cursors: {
16
+ before: string;
17
+ after: string;
18
+ };
19
+ };
20
+ };
21
+ type UploadMediaResponse = {
22
+ id: string;
23
+ };
24
+ interface MediaClass {
25
+ getMediaById(mediaId: string, phone_number_id?: string): Promise<MediaResponse>;
26
+ uploadMedia(file: File, messagingProduct?: string): Promise<UploadMediaResponse>;
27
+ deleteMedia(mediaId: string, phone_number_id?: string): Promise<ResponseSuccess>;
28
+ downloadMedia(mediaUrl: string): Promise<Blob>;
29
+ }
30
+
31
+ /**
32
+ * API for managing WhatsApp Media.
33
+ *
34
+ * This API allows you to:
35
+ * - Get media information by ID
36
+ * - Upload media files
37
+ * - Delete media files
38
+ * - Download media files from URLs
39
+ */
40
+ declare class MediaApi extends BaseAPI implements MediaClass {
41
+ private readonly endpoint;
42
+ constructor(config: WabaConfigType, client: RequesterClass);
43
+ /**
44
+ * Retrieve media information by media ID.
45
+ *
46
+ * @param mediaId The media ID to retrieve information for
47
+ * @param phone_number_id Optional phone number ID (defaults to configured one)
48
+ * @returns Media information including URL, mime type, file size, etc.
49
+ *
50
+ * @example
51
+ * const mediaInfo = await whatsappClient.media.getMediaById('media_id_123');
52
+ */
53
+ getMediaById(mediaId: string, phone_number_id?: string): Promise<MediaResponse>;
54
+ /**
55
+ * Upload a media file to WhatsApp.
56
+ *
57
+ * @param file The file to upload
58
+ * @param messagingProduct The messaging product (default: 'whatsapp')
59
+ * @returns Upload response containing the media ID
60
+ *
61
+ * @example
62
+ * const file = new File([buffer], 'image.jpg', { type: 'image/jpeg' });
63
+ * const result = await whatsappClient.media.uploadMedia(file);
64
+ */
65
+ uploadMedia(file: File, messagingProduct?: string): Promise<UploadMediaResponse>;
66
+ /**
67
+ * Delete a media file.
68
+ *
69
+ * @param mediaId The media ID to delete
70
+ * @param phone_number_id Optional phone number ID (defaults to configured one)
71
+ * @returns Response indicating success or failure
72
+ *
73
+ * @example
74
+ * await whatsappClient.media.deleteMedia('media_id_123');
75
+ */
76
+ deleteMedia(mediaId: string, phone_number_id?: string): Promise<ResponseSuccess>;
77
+ /**
78
+ * Download media from a URL.
79
+ *
80
+ * @param mediaUrl The URL to download media from
81
+ * @returns Blob containing the media data
82
+ *
83
+ * @example
84
+ * const blob = await whatsappClient.media.downloadMedia('https://...');
85
+ */
86
+ downloadMedia(mediaUrl: string): Promise<Blob>;
87
+ }
88
+
89
+ export { MediaApi as M, type UploadMediaResponse as U, type MediaClass as a, type MediaResponse as b, type MediasResponse as c };