meta-cloud-api 0.1.21 → 0.1.23

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 (138) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +210 -140
  3. package/dist/api/base.d.mts +1 -1
  4. package/dist/api/base.d.ts +1 -1
  5. package/dist/api/businessProfile.d.mts +1 -1
  6. package/dist/api/businessProfile.d.ts +1 -1
  7. package/dist/api/businessProfile.js +1 -1
  8. package/dist/api/encryption.d.mts +1 -1
  9. package/dist/api/encryption.d.ts +1 -1
  10. package/dist/api/flow.d.mts +1 -1
  11. package/dist/api/flow.d.ts +1 -1
  12. package/dist/api/flow.js +1 -1
  13. package/dist/api/flow.mjs +1 -1
  14. package/dist/api/index.d.mts +1 -1
  15. package/dist/api/index.d.ts +1 -1
  16. package/dist/api/index.js +1 -1
  17. package/dist/api/index.mjs +1 -1
  18. package/dist/api/media.d.mts +1 -1
  19. package/dist/api/media.d.ts +1 -1
  20. package/dist/api/media.js +1 -1
  21. package/dist/api/messages.d.mts +1 -1
  22. package/dist/api/messages.d.ts +1 -1
  23. package/dist/api/phoneNumber.d.mts +1 -1
  24. package/dist/api/phoneNumber.d.ts +1 -1
  25. package/dist/api/phoneNumber.js +1 -1
  26. package/dist/api/phoneNumber.mjs +1 -1
  27. package/dist/api/qrCode.d.mts +1 -1
  28. package/dist/api/qrCode.d.ts +1 -1
  29. package/dist/api/qrCode.js +1 -1
  30. package/dist/api/qrCode.mjs +1 -1
  31. package/dist/api/registration.d.mts +1 -1
  32. package/dist/api/registration.d.ts +1 -1
  33. package/dist/api/template.d.mts +1 -1
  34. package/dist/api/template.d.ts +1 -1
  35. package/dist/api/template.js +1 -1
  36. package/dist/api/template.mjs +1 -1
  37. package/dist/api/twoStepVerification.d.mts +1 -1
  38. package/dist/api/twoStepVerification.d.ts +1 -1
  39. package/dist/api/twoStepVerification.js +1 -1
  40. package/dist/api/twoStepVerification.mjs +1 -1
  41. package/dist/api/waba.d.mts +1 -1
  42. package/dist/api/waba.d.ts +1 -1
  43. package/dist/api/waba.js +1 -1
  44. package/dist/api/waba.mjs +1 -1
  45. package/dist/{enums-BYfW0iLO.d.mts → enums-Bcd3jLw2.d.mts} +0 -1
  46. package/dist/{enums-BYfW0iLO.d.ts → enums-Bcd3jLw2.d.ts} +0 -1
  47. package/dist/httpsClient.d.mts +1 -1
  48. package/dist/httpsClient.d.ts +1 -1
  49. package/dist/index.d.mts +2 -2
  50. package/dist/index.d.ts +2 -2
  51. package/dist/index.js +1 -1
  52. package/dist/index.js.map +1 -1
  53. package/dist/index.mjs +1 -1
  54. package/dist/index.mjs.map +1 -1
  55. package/dist/request.d.mts +2 -2
  56. package/dist/request.d.ts +2 -2
  57. package/dist/request.js +1 -1
  58. package/dist/request.js.map +1 -1
  59. package/dist/request.mjs +1 -1
  60. package/dist/request.mjs.map +1 -1
  61. package/dist/types/base.d.mts +1 -1
  62. package/dist/types/base.d.ts +1 -1
  63. package/dist/types/businessProfile.d.mts +1 -1
  64. package/dist/types/businessProfile.d.ts +1 -1
  65. package/dist/types/config.d.mts +1 -6
  66. package/dist/types/config.d.ts +1 -6
  67. package/dist/types/config.js.map +1 -1
  68. package/dist/types/encryption.d.mts +1 -1
  69. package/dist/types/encryption.d.ts +1 -1
  70. package/dist/types/enums.d.mts +1 -1
  71. package/dist/types/enums.d.ts +1 -1
  72. package/dist/types/enums.js +1 -1
  73. package/dist/types/enums.js.map +1 -1
  74. package/dist/types/enums.mjs +1 -1
  75. package/dist/types/enums.mjs.map +1 -1
  76. package/dist/types/flow.d.mts +1 -1
  77. package/dist/types/flow.d.ts +1 -1
  78. package/dist/types/httpsClient.d.mts +1 -1
  79. package/dist/types/httpsClient.d.ts +1 -1
  80. package/dist/types/index.d.mts +2 -2
  81. package/dist/types/index.d.ts +2 -2
  82. package/dist/types/index.js +1 -1
  83. package/dist/types/index.js.map +1 -1
  84. package/dist/types/index.mjs +1 -1
  85. package/dist/types/index.mjs.map +1 -1
  86. package/dist/types/media.d.mts +1 -1
  87. package/dist/types/media.d.ts +1 -1
  88. package/dist/types/messages.d.mts +1 -1
  89. package/dist/types/messages.d.ts +1 -1
  90. package/dist/types/phoneNumber.d.mts +1 -1
  91. package/dist/types/phoneNumber.d.ts +1 -1
  92. package/dist/types/qrCode.d.mts +1 -1
  93. package/dist/types/qrCode.d.ts +1 -1
  94. package/dist/types/registration.d.mts +1 -1
  95. package/dist/types/registration.d.ts +1 -1
  96. package/dist/types/request.d.mts +2 -2
  97. package/dist/types/request.d.ts +2 -2
  98. package/dist/types/request.js.map +1 -1
  99. package/dist/types/template.d.mts +1 -1
  100. package/dist/types/template.d.ts +1 -1
  101. package/dist/types/twoStepVerification.d.mts +1 -1
  102. package/dist/types/twoStepVerification.d.ts +1 -1
  103. package/dist/types/waba.d.mts +1 -1
  104. package/dist/types/waba.d.ts +1 -1
  105. package/dist/types/webhook.d.mts +42 -2
  106. package/dist/types/webhook.d.ts +42 -2
  107. package/dist/types/webhook.js.map +1 -1
  108. package/dist/types/webhook.mjs.map +1 -1
  109. package/dist/types/whatsapp.d.mts +1 -2
  110. package/dist/types/whatsapp.d.ts +1 -2
  111. package/dist/types/whatsapp.js.map +1 -1
  112. package/dist/utils/filters.d.mts +1 -1
  113. package/dist/utils/filters.d.ts +1 -1
  114. package/dist/utils/importConfig.d.mts +1 -1
  115. package/dist/utils/importConfig.d.ts +1 -1
  116. package/dist/utils/importConfig.js +1 -1
  117. package/dist/utils/importConfig.js.map +1 -1
  118. package/dist/utils/importConfig.mjs +1 -1
  119. package/dist/utils/importConfig.mjs.map +1 -1
  120. package/dist/utils/index.d.mts +1 -1
  121. package/dist/utils/index.d.ts +1 -1
  122. package/dist/utils/index.js +1 -1
  123. package/dist/utils/index.js.map +1 -1
  124. package/dist/utils/index.mjs +1 -1
  125. package/dist/utils/index.mjs.map +1 -1
  126. package/dist/webhook.d.mts +1 -1
  127. package/dist/webhook.d.ts +1 -1
  128. package/dist/webhook.js +1 -1
  129. package/dist/webhook.js.map +1 -1
  130. package/dist/webhook.mjs +1 -1
  131. package/dist/webhook.mjs.map +1 -1
  132. package/dist/whatsapp.d.mts +1 -1
  133. package/dist/whatsapp.d.ts +1 -1
  134. package/dist/whatsapp.js +1 -1
  135. package/dist/whatsapp.js.map +1 -1
  136. package/dist/whatsapp.mjs +1 -1
  137. package/dist/whatsapp.mjs.map +1 -1
  138. package/package.json +1 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2025] [froggy1014]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,27 +1,24 @@
1
1
  # Meta Cloud API
2
2
 
3
- A TypeScript SDK for the Meta Cloud API that provides a clean, strongly-typed interface for interacting with WhatsApp's Cloud API and other Meta platform services.
3
+ <div style="display: flex; align-items: center;">
4
+ <img src="../../public/README.svg" alt="Meta Cloud API" style="flex: 1; width: 100px;">
5
+ <div style="flex: 1; padding-left: 20px;">
6
+ <p>Meta Cloud API - A powerful TypeScript wrapper for Meta's Cloud API, providing a clean and type-safe interface for WhatsApp Business Platform integration.</p>
7
+ </div>
8
+ </div>
4
9
 
5
- [![npm version](https://img.shields.io/npm/v/meta-cloud-api.svg)](https://www.npmjs.com/package/meta-cloud-api)
6
- [![npm downloads](https://img.shields.io/npm/dm/meta-cloud-api.svg)](https://www.npmjs.com/package/meta-cloud-api)
7
- [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/froggy1014/meta-cloud-api/blob/main/LICENSE)
10
+ ## Resources
11
+
12
+ - [Documentation](https://www.meta-cloud-api.xyz/)
13
+ - [API Reference (Swagger)](https://meta-cloud-api-swagger.vercel.app/api-docs/)
8
14
 
9
15
  ## Features
10
16
 
11
- - **Strongly Typed**: Full TypeScript support with comprehensive type definitions
12
- - **Modular Design**: API components are organized logically for ease of use
13
- - **Error Handling**: Standardized error handling for Meta API responses
14
- - **Complete API Coverage**: Support for all WhatsApp Cloud API functionality
15
- - Messages API (text, templates, media, interactive, etc.)
16
- - Templates API
17
- - Media API
18
- - Phone Number API
19
- - Flow API
20
- - QR Code API
21
- - Registration API
22
- - WABA (WhatsApp Business Account) API
23
- - Two-Step Verification API
24
- - Encryption API
17
+ - **Type-Safe Development** - Built with TypeScript to provide code completion and catch errors during development
18
+ - **Comprehensive Coverage** - Full support for WhatsApp Business Platform APIs
19
+ - **Clean Interface** - Intuitive methods organized by domain for improved code readability
20
+ - **Error Handling** - Standardized error handling with detailed Meta API error information
21
+ - **Webhook Handler** - Built-in support for webhook verification and message handling
25
22
 
26
23
  ## Installation
27
24
 
@@ -36,122 +33,193 @@ pnpm add meta-cloud-api
36
33
  ## Quick Start
37
34
 
38
35
  ```typescript
39
- import WhatsApp from 'meta-cloud-api';
40
-
41
- // Initialize with configuration object
42
- const whatsapp = new WhatsApp({
43
- phoneNumberId: YOUR_PHONE_NUMBER_ID,
44
- accessToken: 'YOUR_ACCESS_TOKEN'
45
- });
46
-
47
- // You can also use environment variables (.env file)
48
- // const whatsapp = new WhatsApp();
49
-
50
- // Send a text message
51
- async function sendMessage() {
52
- try {
53
- const response = await whatsapp.messages.text(
54
- { body: "Hello from Meta Cloud API!" },
55
- 15551234567
56
- );
57
- console.log(`Message sent successfully with ID: ${response.messages[0].id}`);
58
- } catch (error) {
59
- console.error('Error sending message:', error);
60
- }
61
- }
62
- ```
36
+ import WhatsApp, { MessageTypesEnum } from 'meta-cloud-api';
63
37
 
64
- ## Environment Variables
38
+ // Initialize the client
39
+ const client = new WhatsApp({
40
+ accessToken: process.env.CLOUD_API_ACCESS_TOKEN,
41
+ phoneNumberId: Number(process.env.WA_PHONE_NUMBER_ID),
42
+ businessAcctId: process.env.WA_BUSINESS_ACCOUNT_ID
43
+ });
65
44
 
66
- Create a `.env` file with your WhatsApp Cloud API credentials:
45
+ // Send a WhatsApp text message
46
+ const response = await client.messages.text({
47
+ to: '+1234567890',
48
+ body: 'Hello from Meta Cloud API!'
49
+ });
67
50
 
51
+ console.log(`Message ID: ${response.messages[0].id}`);
68
52
  ```
69
- WA_BASE_URL=graph.facebook.com
70
- M4D_APP_ID=your_app_id
71
- M4D_APP_SECRET=your_app_secret
72
- WA_PHONE_NUMBER_ID=your_phone_number_id
73
- WA_BUSINESS_ACCOUNT_ID=your_business_account_id
74
- CLOUD_API_ACCESS_TOKEN=your_access_token
75
- CLOUD_API_VERSION=17.0
76
- ```
77
53
 
78
- ## API Documentation
54
+ ## Usage Examples
55
+
56
+ ### Messaging
57
+
58
+ Send different types of messages through WhatsApp Business Platform:
79
59
 
80
- ### Messages API
60
+ #### Text Message
81
61
 
82
- Send various types of WhatsApp messages:
62
+ ```typescript
63
+ const result = await client.messages.text({
64
+ to: "15551234567",
65
+ body: "Hello from Meta Cloud API!"
66
+ });
67
+ ```
68
+
69
+ #### Template Message
83
70
 
84
71
  ```typescript
85
- // Text message
86
- await whatsapp.messages.text(
87
- { body: "Hello world!" },
88
- 15551234567
89
- );
90
-
91
- // Image message
92
- await whatsapp.messages.image(
93
- { link: "https://example.com/image.jpg" },
94
- 15551234567
95
- );
96
-
97
- // Document message
98
- await whatsapp.messages.document(
99
- {
100
- link: "https://example.com/document.pdf",
101
- filename: "Important Document.pdf"
102
- },
103
- 15551234567
104
- );
105
-
106
- // Template message
107
- await whatsapp.messages.template(
108
- {
109
- name: "sample_shipping_confirmation",
110
- language: { code: "en_US" },
72
+ import { ComponentTypesEnum, LanguagesEnum, ParametersTypesEnum } from 'meta-cloud-api';
73
+
74
+ const result = await client.messages.template({
75
+ to: "15551234567",
76
+ body: {
77
+ name: "shipping_confirmation",
78
+ language: {
79
+ code: LanguagesEnum.English_US,
80
+ policy: "deterministic"
81
+ },
111
82
  components: [
112
83
  {
113
- type: "body",
84
+ type: ComponentTypesEnum.Body,
114
85
  parameters: [
115
- { type: "text", text: "John" },
116
- { type: "text", text: "12345" }
86
+ {
87
+ type: ParametersTypesEnum.Text,
88
+ text: "John Doe"
89
+ },
90
+ {
91
+ type: ParametersTypesEnum.Text,
92
+ text: "12345"
93
+ }
117
94
  ]
118
95
  }
119
96
  ]
120
- },
121
- 15551234567
122
- );
123
-
124
- // Interactive message with buttons
125
- await whatsapp.messages.interactive(
126
- {
127
- type: "button",
128
- body: { text: "Please select an option:" },
97
+ }
98
+ });
99
+ ```
100
+
101
+ #### Media Message
102
+
103
+ ```typescript
104
+ const result = await client.messages.image({
105
+ to: "15551234567",
106
+ body: {
107
+ link: "https://example.com/image.jpg"
108
+ }
109
+ });
110
+ ```
111
+
112
+ #### Interactive Message
113
+
114
+ ```typescript
115
+ import { InteractiveTypesEnum } from 'meta-cloud-api';
116
+
117
+ const result = await client.messages.interactive({
118
+ to: "15551234567",
119
+ body: {
120
+ type: InteractiveTypesEnum.Button,
121
+ body: {
122
+ text: "What would you like to do?"
123
+ },
129
124
  action: {
130
125
  buttons: [
131
- { type: "reply", reply: { id: "btn1", title: "Option 1" } },
132
- { type: "reply", reply: { id: "btn2", title: "Option 2" } }
126
+ {
127
+ type: "reply",
128
+ reply: {
129
+ id: "help_button",
130
+ title: "Get Help"
131
+ }
132
+ },
133
+ {
134
+ type: "reply",
135
+ reply: {
136
+ id: "info_button",
137
+ title: "Account Info"
138
+ }
139
+ }
133
140
  ]
134
141
  }
135
- },
136
- 15551234567
137
- );
142
+ }
143
+ });
144
+ ```
145
+
146
+ ## Example Projects
147
+
148
+ We provide ready-to-use example projects demonstrating how to integrate Meta Cloud API in different frameworks:
149
+
150
+ - [Express.js Example](./examples/express-example) - A simple Express.js server with webhook handling for WhatsApp messages
151
+ - [Next.js Example](./examples/nextjs-page-router-example) - Integration with Next.js Pages Router, showing how to handle webhooks in a Next.js API route
152
+
153
+ Each example includes its own README with setup instructions and demonstration of core features.
154
+
155
+ ### Webhook Integration
156
+
157
+ Set up a webhook to receive messages and events from the WhatsApp API:
158
+
159
+ ```typescript
160
+ import WhatsApp, {
161
+ WebhookHandler,
162
+ MessageTypesEnum,
163
+ WebhookMessage
164
+ } from 'meta-cloud-api';
165
+
166
+ // Initialize the handler
167
+ const webhookHandler = new WebhookHandler({
168
+ accessToken: process.env.CLOUD_API_ACCESS_TOKEN,
169
+ phoneNumberId: Number(process.env.WA_PHONE_NUMBER_ID),
170
+ businessAcctId: process.env.WA_BUSINESS_ACCOUNT_ID,
171
+ webhookVerificationToken: process.env.WEBHOOK_VERIFICATION_TOKEN
172
+ });
173
+
174
+ // Handle webhook verification
175
+ app.get('/webhook', (req, res) => {
176
+ webhookHandler.handleVerificationRequest(req, res);
177
+ });
178
+
179
+ // Handle incoming messages
180
+ app.post('/webhook', (req, res) => {
181
+ webhookHandler.handleWebhookRequest(req, res);
182
+ });
183
+
184
+ // Pre-process all messages (e.g., mark as read)
185
+ webhookHandler.onMessagePreProcess(async (client: WhatsApp, message: WebhookMessage) => {
186
+ await client.messages.markAsRead({ messageId: message.id });
187
+ });
188
+
189
+ // Handle text messages
190
+ webhookHandler.onMessage(MessageTypesEnum.Text, async (client: WhatsApp, message: WebhookMessage) => {
191
+ if (message.text?.body) {
192
+ await client.messages.text({
193
+ body: `You said: "${message.text.body}"`,
194
+ to: message.from
195
+ });
196
+ }
197
+ });
198
+
199
+ // Handle image messages
200
+ webhookHandler.onMessage(MessageTypesEnum.Image, async (client: WhatsApp, message: WebhookMessage) => {
201
+ await client.messages.text({
202
+ body: "Thanks for the image!",
203
+ to: message.from
204
+ });
205
+ });
138
206
  ```
139
207
 
140
- ### Templates API
208
+ ### Templates
141
209
 
142
- Work with message templates:
210
+ Manage message templates for your WhatsApp Business account:
143
211
 
144
212
  ```typescript
145
- // Get all templates
146
- const templates = await whatsapp.template.getTemplates({
147
- limit: 20
213
+ // List all templates
214
+ const templates = await client.templates.list({
215
+ businessId: process.env.WA_BUSINESS_ACCOUNT_ID
148
216
  });
149
217
 
150
218
  // Create a new template
151
- await whatsapp.template.createTemplate({
152
- name: "my_template",
219
+ const newTemplate = await client.templates.create({
220
+ businessId: process.env.WA_BUSINESS_ACCOUNT_ID,
221
+ name: "my_special_template",
153
222
  category: "MARKETING",
154
- language: "en_US",
155
223
  components: [
156
224
  {
157
225
  type: "HEADER",
@@ -160,57 +228,59 @@ await whatsapp.template.createTemplate({
160
228
  },
161
229
  {
162
230
  type: "BODY",
163
- text: "Hi {{1}}, check out our latest offer: {{2}}!"
231
+ text: "Hi {{1}}, we have a special offer for you: {{2}}% off your next purchase!"
232
+ },
233
+ {
234
+ type: "FOOTER",
235
+ text: "Tap the button below to shop now"
164
236
  }
165
- ]
237
+ ],
238
+ language: "en_US"
166
239
  });
167
240
  ```
168
241
 
169
- ### Media API
242
+ ### Media Management
170
243
 
171
- Handle media files:
244
+ Upload and retrieve media for your messages:
172
245
 
173
246
  ```typescript
174
- // Upload media
175
- const mediaResponse = await whatsapp.media.uploadMedia(
176
- new File(['...'], 'image.jpg', { type: 'image/jpeg' })
177
- );
247
+ import fs from 'fs';
178
248
 
179
- // Get media details
180
- const mediaDetails = await whatsapp.media.getMediaById(mediaResponse.id);
249
+ // Upload media
250
+ const mediaUpload = await client.media.upload({
251
+ file: fs.createReadStream("./path/to/image.jpg"),
252
+ type: "image/jpeg"
253
+ });
181
254
 
182
- // Delete media
183
- await whatsapp.media.deleteMedia(mediaResponse.id);
255
+ // Get media URL
256
+ const media = await client.media.get({
257
+ mediaId: mediaUpload.id
258
+ });
184
259
  ```
185
260
 
186
- ## Error Handling
261
+ ### Business Profile
187
262
 
188
- The package provides standard error handling for Meta API responses:
263
+ Update your WhatsApp Business profile information:
189
264
 
190
265
  ```typescript
191
- try {
192
- await whatsapp.messages.text(
193
- { body: "Hello world!" },
194
- 15551234567
195
- );
196
- } catch (error) {
197
- if (error.name === 'MetaError') {
198
- console.error(`Meta API Error: ${error.error.message}`);
199
- console.error(`Error Code: ${error.error.code}`);
200
-
201
- if (error.error.error_data) {
202
- console.error(`Details: ${error.error.error_data.details}`);
203
- }
204
- } else {
205
- console.error('Unexpected error:', error);
206
- }
207
- }
266
+ const profile = await client.businessProfile.update({
267
+ about: "We provide the best service!",
268
+ address: "123 Business St, City",
269
+ description: "Premium products and services",
270
+ email: "contact@business.com",
271
+ websites: ["https://www.business.com"]
272
+ });
208
273
  ```
209
274
 
210
- ## License
275
+ ## Requirements
211
276
 
212
- This project is licensed under the MIT License - see the [LICENSE](https://github.com/froggy1014/meta-cloud-api/blob/main/LICENSE) file for details.
277
+ - TypeScript 4.5+
278
+ - Node.js 18 LTS or later
213
279
 
214
280
  ## Contributing
215
281
 
216
- Contributions welcome! Please feel free to submit a Pull Request.
282
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
283
+
284
+ ## License
285
+
286
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
@@ -1,4 +1,4 @@
1
- import { H as HttpMethodsEnum } from '../enums-BYfW0iLO.mjs';
1
+ import { H as HttpMethodsEnum } from '../enums-Bcd3jLw2.mjs';
2
2
  import { BaseClass } from '../types/base.mjs';
3
3
  import { WabaConfigType } from '../types/config.mjs';
4
4
  import { RequesterClass } from '../types/request.mjs';
@@ -1,4 +1,4 @@
1
- import { H as HttpMethodsEnum } from '../enums-BYfW0iLO.js';
1
+ import { H as HttpMethodsEnum } from '../enums-Bcd3jLw2.js';
2
2
  import { BaseClass } from '../types/base.js';
3
3
  import { WabaConfigType } from '../types/config.js';
4
4
  import { RequesterClass } from '../types/request.js';
@@ -2,7 +2,7 @@ import { BusinessProfileClass, BusinessProfileFieldsParam, BusinessProfileRespon
2
2
  import { WabaConfigType } from '../types/config.mjs';
3
3
  import { RequesterClass, ResponseSuccess } from '../types/request.mjs';
4
4
  import BaseAPI from './base.mjs';
5
- import '../enums-BYfW0iLO.mjs';
5
+ import '../enums-Bcd3jLw2.mjs';
6
6
  import '../types/base.mjs';
7
7
 
8
8
  /**
@@ -2,7 +2,7 @@ import { BusinessProfileClass, BusinessProfileFieldsParam, BusinessProfileRespon
2
2
  import { WabaConfigType } from '../types/config.js';
3
3
  import { RequesterClass, ResponseSuccess } from '../types/request.js';
4
4
  import BaseAPI from './base.js';
5
- import '../enums-BYfW0iLO.js';
5
+ import '../enums-Bcd3jLw2.js';
6
6
  import '../types/base.js';
7
7
 
8
8
  /**
@@ -1,2 +1,2 @@
1
- "use strict";var U=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var T=(i,t)=>{for(var R in t)U(i,R,{get:t[R],enumerable:!0})},I=(i,t,R,P)=>{if(t&&typeof t=="object"||typeof t=="function")for(let A of O(t))!p.call(i,A)&&A!==R&&U(i,A,{get:()=>t[A],enumerable:!(P=G(t,A))||P.enumerable});return i};var K=i=>I(U({},"__esModule",{value:!0}),i);var F={};T(F,{default:()=>N});module.exports=K(F);function l(i){if(!i)return"";let t="";return Array.isArray(i)?t=i.join(","):t=Object.entries(i).filter(([R,P])=>P).map(([R])=>R).join(","),t?`?fields=${t}`:""}var B=i=>{if(!i||Object.keys(i).length===0)return"";let t=new URLSearchParams;for(let[P,A]of Object.entries(i))A!==void 0&&t.append(P,String(A));let R=t.toString();return R?`?${R}`:""};var S=class{name;debug;constructor(t,R=!1){this.name=t,this.debug=R}log(...t){if(this.debug){let R=`[ ${Date.now()} ]`;this.name&&(R+=` - ${this.name}`),console.log.apply(console,[R,": ",...t])}}error(...t){let R=`[ ${Date.now()} ] - ERROR`;this.name&&(R+=` - ${this.name}`),console.error.apply(console,[R,": ",...t])}warn(...t){let R=`[ ${Date.now()} ] - WARN`;this.name&&(R+=` - ${this.name}`),console.warn.apply(console,[R,": ",...t])}info(...t){let R=`[ ${Date.now()} ] - INFO`;this.name&&(R+=` - ${this.name}`),console.info.apply(console,[R,": ",...t])}};var _="BaseAPI",f=!1,M=new S(_,process.env.DEBUG==="true"||f),D=class{config;client;constructor(t,R){this.config=t,this.client=R,M.log("Initialized with HTTPSClient")}sendJson(t,R,P,A){return this.client.getJson(t,R,P,A)}sendFormData(t,R,P,A){return this.client.sendFormData(t,R,P,A)}sendUrlEncodedForm(t,R,P,A){return this.client.sendUrlEncodedForm(t,R,P,A)}};var N=class extends D{endpoint="whatsapp_business_profile";constructor(t,R){super(t,R)}async getBusinessProfile(t){return this.sendJson("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}${l(t)}`,this.config.REQUEST_TIMEOUT,null)}async updateBusinessProfile(t){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async createUploadSession(t,R,P){let A=B({file_length:t,file_type:R,file_name:P});return this.sendJson("POST",`app/uploads/${A}`,this.config.REQUEST_TIMEOUT,null)}async uploadMedia(t,R){return this.sendJson("POST",`${t}`,this.config.REQUEST_TIMEOUT,R)}async getUploadHandle(t){return this.sendJson("GET",`${t}`,this.config.REQUEST_TIMEOUT,null)}};
1
+ "use strict";var U=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var T=(i,t)=>{for(var R in t)U(i,R,{get:t[R],enumerable:!0})},I=(i,t,R,P)=>{if(t&&typeof t=="object"||typeof t=="function")for(let A of O(t))!p.call(i,A)&&A!==R&&U(i,A,{get:()=>t[A],enumerable:!(P=G(t,A))||P.enumerable});return i};var K=i=>I(U({},"__esModule",{value:!0}),i);var F={};T(F,{default:()=>N});module.exports=K(F);function l(i){if(!i)return"";let t="";return Array.isArray(i)?t=i.join(","):t=Object.entries(i).filter(([R,P])=>P).map(([R])=>R).join(","),t?`?fields=${t}`:""}var B=i=>{if(!i||Object.keys(i).length===0)return"";let t=new URLSearchParams;for(let[P,A]of Object.entries(i))A!==void 0&&t.append(P,String(A));let R=t.toString();return R?`?${R}`:""};var S=class{name;debug;constructor(t,R=!1){this.name=t,this.debug=R}log(...t){if(this.debug){let R=`[ ${Date.now()} ]`;this.name&&(R+=` - ${this.name}`),console.log.apply(console,[R,": ",...t])}}error(...t){let R=`[ ${Date.now()} ] - ERROR`;this.name&&(R+=` - ${this.name}`),console.error.apply(console,[R,": ",...t])}warn(...t){let R=`[ ${Date.now()} ] - WARN`;this.name&&(R+=` - ${this.name}`),console.warn.apply(console,[R,": ",...t])}info(...t){let R=`[ ${Date.now()} ] - INFO`;this.name&&(R+=` - ${this.name}`),console.info.apply(console,[R,": ",...t])}};var f="BaseAPI",M=!1,_=new S(f,process.env.DEBUG==="true"||M),D=class{config;client;constructor(t,R){this.config=t,this.client=R,_.log("Initialized with HTTPSClient")}sendJson(t,R,P,A){return this.client.getJson(t,R,P,A)}sendFormData(t,R,P,A){return this.client.sendFormData(t,R,P,A)}sendUrlEncodedForm(t,R,P,A){return this.client.sendUrlEncodedForm(t,R,P,A)}};var N=class extends D{endpoint="whatsapp_business_profile";constructor(t,R){super(t,R)}async getBusinessProfile(t){return this.sendJson("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}${l(t)}`,this.config.REQUEST_TIMEOUT,null)}async updateBusinessProfile(t){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async createUploadSession(t,R,P){let A=B({file_length:t,file_type:R,file_name:P});return this.sendJson("POST",`app/uploads/${A}`,this.config.REQUEST_TIMEOUT,null)}async uploadMedia(t,R){return this.sendJson("POST",`${t}`,this.config.REQUEST_TIMEOUT,R)}async getUploadHandle(t){return this.sendJson("GET",`${t}`,this.config.REQUEST_TIMEOUT,null)}};
2
2
  //# sourceMappingURL=businessProfile.js.map
@@ -2,7 +2,7 @@ import { WabaConfigType } from '../types/config.mjs';
2
2
  import { EncryptionClass, EncryptionPublicKeyResponse } from '../types/encryption.mjs';
3
3
  import { RequesterClass, ResponseSuccess } from '../types/request.mjs';
4
4
  import BaseAPI from './base.mjs';
5
- import '../enums-BYfW0iLO.mjs';
5
+ import '../enums-Bcd3jLw2.mjs';
6
6
  import '../types/base.mjs';
7
7
 
8
8
  declare class EncryptionAPI extends BaseAPI implements EncryptionClass {
@@ -2,7 +2,7 @@ import { WabaConfigType } from '../types/config.js';
2
2
  import { EncryptionClass, EncryptionPublicKeyResponse } from '../types/encryption.js';
3
3
  import { RequesterClass, ResponseSuccess } from '../types/request.js';
4
4
  import BaseAPI from './base.js';
5
- import '../enums-BYfW0iLO.js';
5
+ import '../enums-Bcd3jLw2.js';
6
6
  import '../types/base.js';
7
7
 
8
8
  declare class EncryptionAPI extends BaseAPI implements EncryptionClass {
@@ -2,7 +2,7 @@ import { WabaConfigType } from '../types/config.mjs';
2
2
  import { FlowClass, FlowsListResponse, FlowCategoryEnum, CreateFlowResponse, Flow, FlowPreviewResponse, FlowAssetsResponse, UpdateFlowResponse, ValidateFlowJsonResponse, FlowMigrationResponse } from '../types/flow.mjs';
3
3
  import { RequesterClass, ResponseSuccess } from '../types/request.mjs';
4
4
  import BaseAPI from './base.mjs';
5
- import '../enums-BYfW0iLO.mjs';
5
+ import '../enums-Bcd3jLw2.mjs';
6
6
  import '../types/base.mjs';
7
7
 
8
8
  declare class FlowAPI extends BaseAPI implements FlowClass {
@@ -2,7 +2,7 @@ import { WabaConfigType } from '../types/config.js';
2
2
  import { FlowClass, FlowsListResponse, FlowCategoryEnum, CreateFlowResponse, Flow, FlowPreviewResponse, FlowAssetsResponse, UpdateFlowResponse, ValidateFlowJsonResponse, FlowMigrationResponse } from '../types/flow.js';
3
3
  import { RequesterClass, ResponseSuccess } from '../types/request.js';
4
4
  import BaseAPI from './base.js';
5
- import '../enums-BYfW0iLO.js';
5
+ import '../enums-Bcd3jLw2.js';
6
6
  import '../types/base.js';
7
7
 
8
8
  declare class FlowAPI extends BaseAPI implements FlowClass {
package/dist/api/flow.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var N=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var G=(A,i)=>{for(var t in i)N(A,t,{get:i[t],enumerable:!0})},f=(A,i,t,R)=>{if(i&&typeof i=="object"||typeof i=="function")for(let l of U(i))!_.call(A,l)&&l!==t&&N(A,l,{get:()=>i[l],enumerable:!(R=O(i,l))||R.enumerable});return A};var F=A=>f(N({},"__esModule",{value:!0}),A);var M={};G(M,{default:()=>D});module.exports=F(M);var S=class{name;debug;constructor(i,t=!1){this.name=i,this.debug=t}log(...i){if(this.debug){let t=`[ ${Date.now()} ]`;this.name&&(t+=` - ${this.name}`),console.log.apply(console,[t,": ",...i])}}error(...i){let t=`[ ${Date.now()} ] - ERROR`;this.name&&(t+=` - ${this.name}`),console.error.apply(console,[t,": ",...i])}warn(...i){let t=`[ ${Date.now()} ] - WARN`;this.name&&(t+=` - ${this.name}`),console.warn.apply(console,[t,": ",...i])}info(...i){let t=`[ ${Date.now()} ] - INFO`;this.name&&(t+=` - ${this.name}`),console.info.apply(console,[t,": ",...i])}};var w="BaseAPI",T=!1,I=new S(w,process.env.DEBUG==="true"||T),P=class{config;client;constructor(i,t){this.config=i,this.client=t,I.log("Initialized with HTTPSClient")}sendJson(i,t,R,l){return this.client.getJson(i,t,R,l)}sendFormData(i,t,R,l){return this.client.sendFormData(i,t,R,l)}sendUrlEncodedForm(i,t,R,l){return this.client.sendUrlEncodedForm(i,t,R,l)}};var K="FlowAPI",h=!1,B=new S(K,process.env.DEBUG==="true"||h),D=class extends P{constructor(i,t){super(i,t),B.log("FlowAPI initialized")}async listFlows(i){return this.sendJson("GET",`/${i}/flows`,this.config.REQUEST_TIMEOUT,null)}async createFlow(i,t){let R={name:t.name,categories:t.categories,...t.endpoint_uri&&{endpoint_uri:t.endpoint_uri},...t.clone_flow_id&&{clone_flow_id:t.clone_flow_id},...t.flow_json&&{flow_json:t.flow_json},...t.publish!==void 0&&{publish:t.publish}};return this.sendJson("POST",`/${i}/flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(R))}async getFlow(i,t,R){let l=new URLSearchParams;t&&l.append("fields",t),R&&l.append("date_format",R);let p=l.toString()?`?${l.toString()}`:"";return this.sendJson("GET",`/${i}${p}`,this.config.REQUEST_TIMEOUT,null)}async getFlowPreview(i,t=!1){let R=`preview.invalidate(${t})`;return this.getFlow(i,R)}async updateFlowMetadata(i,t){let R={...t.name&&{name:t.name},...t.categories&&{categories:t.categories},...t.endpoint_uri&&{endpoint_uri:t.endpoint_uri},...t.application_id&&{application_id:t.application_id}};return this.sendJson("POST",`/${i}`,this.config.REQUEST_TIMEOUT,JSON.stringify(R))}async deleteFlow(i){return this.sendJson("DELETE",`/${i}`,this.config.REQUEST_TIMEOUT,null)}async listAssets(i){return this.sendJson("GET",`/${i}/assets`,this.config.REQUEST_TIMEOUT,null)}async updateFlowJson(i,t){let R=new FormData,l;if(t.file instanceof Buffer)l=new globalThis.Blob([t.file]),R.append("file",l);else if(typeof t.file=="object"&&!(t.file instanceof Blob))try{l=new globalThis.Blob([JSON.stringify(t.file,null,2)],{type:"application/json"}),R.append("file",l)}catch{throw new Error("Failed to stringify JSON object for Flow JSON update.")}else if(t.file instanceof Blob)l=t.file,R.append("file",l);else throw new Error("Invalid file type provided for Flow JSON update. Must be a Buffer, JSON object, or Blob.");return R.append("asset_type","FLOW_JSON"),R.append("name",t.name||"flow.json"),this.sendFormData("POST",`/${i}/assets`,this.config.REQUEST_TIMEOUT,R)}async validateFlowJson(i,t){try{let R=await this.updateFlowJson(i,{file:t}),l=!R.validation_errors||R.validation_errors.length===0;return{...R,valid:l}}catch(R){throw B.error("Error during Flow JSON validation attempt:",R),R}}async publishFlow(i){return this.sendJson("POST",`/${i}/publish`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async deprecateFlow(i){return this.sendJson("POST",`/${i}/deprecate`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async migrateFlows(i,t){let R={source_waba_id:t.source_waba_id,...t.source_flow_names&&{source_flow_names:t.source_flow_names}};return this.sendJson("POST",`/${i}/migrate_flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(R))}};
1
+ "use strict";var N=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var _=(A,i)=>{for(var t in i)N(A,t,{get:i[t],enumerable:!0})},f=(A,i,t,l)=>{if(i&&typeof i=="object"||typeof i=="function")for(let R of G(i))!U.call(A,R)&&R!==t&&N(A,R,{get:()=>i[R],enumerable:!(l=O(i,R))||l.enumerable});return A};var F=A=>f(N({},"__esModule",{value:!0}),A);var M={};_(M,{default:()=>D});module.exports=F(M);var S=class{name;debug;constructor(i,t=!1){this.name=i,this.debug=t}log(...i){if(this.debug){let t=`[ ${Date.now()} ]`;this.name&&(t+=` - ${this.name}`),console.log.apply(console,[t,": ",...i])}}error(...i){let t=`[ ${Date.now()} ] - ERROR`;this.name&&(t+=` - ${this.name}`),console.error.apply(console,[t,": ",...i])}warn(...i){let t=`[ ${Date.now()} ] - WARN`;this.name&&(t+=` - ${this.name}`),console.warn.apply(console,[t,": ",...i])}info(...i){let t=`[ ${Date.now()} ] - INFO`;this.name&&(t+=` - ${this.name}`),console.info.apply(console,[t,": ",...i])}};var w="BaseAPI",T=!1,I=new S(w,process.env.DEBUG==="true"||T),P=class{config;client;constructor(i,t){this.config=i,this.client=t,I.log("Initialized with HTTPSClient")}sendJson(i,t,l,R){return this.client.getJson(i,t,l,R)}sendFormData(i,t,l,R){return this.client.sendFormData(i,t,l,R)}sendUrlEncodedForm(i,t,l,R){return this.client.sendUrlEncodedForm(i,t,l,R)}};var K="FlowAPI",h=!1,B=new S(K,process.env.DEBUG==="true"||h),D=class extends P{constructor(i,t){super(i,t),B.log("FlowAPI initialized")}async listFlows(i){return this.sendJson("GET",`/${i}/flows`,this.config.REQUEST_TIMEOUT,null)}async createFlow(i,t){let l={name:t.name,categories:t.categories,...t.endpoint_uri&&{endpoint_uri:t.endpoint_uri},...t.clone_flow_id&&{clone_flow_id:t.clone_flow_id},...t.flow_json&&{flow_json:t.flow_json},...t.publish!==void 0&&{publish:t.publish}};return this.sendJson("POST",`/${i}/flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(l))}async getFlow(i,t,l){let R=new URLSearchParams;t&&R.append("fields",t),l&&R.append("date_format",l);let p=R.toString()?`?${R.toString()}`:"";return this.sendJson("GET",`/${i}${p}`,this.config.REQUEST_TIMEOUT,null)}async getFlowPreview(i,t=!1){let l=`preview.invalidate(${t})`;return this.getFlow(i,l)}async updateFlowMetadata(i,t){let l={...t.name&&{name:t.name},...t.categories&&{categories:t.categories},...t.endpoint_uri&&{endpoint_uri:t.endpoint_uri},...t.application_id&&{application_id:t.application_id}};return this.sendJson("POST",`/${i}`,this.config.REQUEST_TIMEOUT,JSON.stringify(l))}async deleteFlow(i){return this.sendJson("DELETE",`/${i}`,this.config.REQUEST_TIMEOUT,null)}async listAssets(i){return this.sendJson("GET",`/${i}/assets`,this.config.REQUEST_TIMEOUT,null)}async updateFlowJson(i,t){let l=new FormData,R;if(t.file instanceof Buffer)R=new globalThis.Blob([t.file]),l.append("file",R);else if(typeof t.file=="object"&&!(t.file instanceof Blob))try{R=new globalThis.Blob([JSON.stringify(t.file,null,2)],{type:"application/json"}),l.append("file",R)}catch{throw new Error("Failed to stringify JSON object for Flow JSON update.")}else if(t.file instanceof Blob)R=t.file,l.append("file",R);else throw new Error("Invalid file type provided for Flow JSON update. Must be a Buffer, JSON object, or Blob.");return l.append("asset_type","FLOW_JSON"),l.append("name",t.name||"flow.json"),this.sendFormData("POST",`/${i}/assets`,this.config.REQUEST_TIMEOUT,l)}async validateFlowJson(i,t){try{let l=await this.updateFlowJson(i,{file:t}),R=!l.validation_errors||l.validation_errors.length===0;return{...l,valid:R}}catch(l){throw B.error("Error during Flow JSON validation attempt:",l),l}}async publishFlow(i){return this.sendJson("POST",`/${i}/publish`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async deprecateFlow(i){return this.sendJson("POST",`/${i}/deprecate`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async migrateFlows(i,t){let l={source_waba_id:t.source_waba_id,...t.source_flow_names&&{source_flow_names:t.source_flow_names}};return this.sendJson("POST",`/${i}/migrate_flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(l))}};
2
2
  //# sourceMappingURL=flow.js.map
package/dist/api/flow.mjs CHANGED
@@ -1,2 +1,2 @@
1
- var A=class{name;debug;constructor(i,t=!1){this.name=i,this.debug=t}log(...i){if(this.debug){let t=`[ ${Date.now()} ]`;this.name&&(t+=` - ${this.name}`),console.log.apply(console,[t,": ",...i])}}error(...i){let t=`[ ${Date.now()} ] - ERROR`;this.name&&(t+=` - ${this.name}`),console.error.apply(console,[t,": ",...i])}warn(...i){let t=`[ ${Date.now()} ] - WARN`;this.name&&(t+=` - ${this.name}`),console.warn.apply(console,[t,": ",...i])}info(...i){let t=`[ ${Date.now()} ] - INFO`;this.name&&(t+=` - ${this.name}`),console.info.apply(console,[t,": ",...i])}};var B="BaseAPI",O=!1,U=new A(B,process.env.DEBUG==="true"||O),S=class{config;client;constructor(i,t){this.config=i,this.client=t,U.log("Initialized with HTTPSClient")}sendJson(i,t,R,l){return this.client.getJson(i,t,R,l)}sendFormData(i,t,R,l){return this.client.sendFormData(i,t,R,l)}sendUrlEncodedForm(i,t,R,l){return this.client.sendUrlEncodedForm(i,t,R,l)}};var _="FlowAPI",G=!1,N=new A(_,process.env.DEBUG==="true"||G),D=class extends S{constructor(i,t){super(i,t),N.log("FlowAPI initialized")}async listFlows(i){return this.sendJson("GET",`/${i}/flows`,this.config.REQUEST_TIMEOUT,null)}async createFlow(i,t){let R={name:t.name,categories:t.categories,...t.endpoint_uri&&{endpoint_uri:t.endpoint_uri},...t.clone_flow_id&&{clone_flow_id:t.clone_flow_id},...t.flow_json&&{flow_json:t.flow_json},...t.publish!==void 0&&{publish:t.publish}};return this.sendJson("POST",`/${i}/flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(R))}async getFlow(i,t,R){let l=new URLSearchParams;t&&l.append("fields",t),R&&l.append("date_format",R);let P=l.toString()?`?${l.toString()}`:"";return this.sendJson("GET",`/${i}${P}`,this.config.REQUEST_TIMEOUT,null)}async getFlowPreview(i,t=!1){let R=`preview.invalidate(${t})`;return this.getFlow(i,R)}async updateFlowMetadata(i,t){let R={...t.name&&{name:t.name},...t.categories&&{categories:t.categories},...t.endpoint_uri&&{endpoint_uri:t.endpoint_uri},...t.application_id&&{application_id:t.application_id}};return this.sendJson("POST",`/${i}`,this.config.REQUEST_TIMEOUT,JSON.stringify(R))}async deleteFlow(i){return this.sendJson("DELETE",`/${i}`,this.config.REQUEST_TIMEOUT,null)}async listAssets(i){return this.sendJson("GET",`/${i}/assets`,this.config.REQUEST_TIMEOUT,null)}async updateFlowJson(i,t){let R=new FormData,l;if(t.file instanceof Buffer)l=new globalThis.Blob([t.file]),R.append("file",l);else if(typeof t.file=="object"&&!(t.file instanceof Blob))try{l=new globalThis.Blob([JSON.stringify(t.file,null,2)],{type:"application/json"}),R.append("file",l)}catch{throw new Error("Failed to stringify JSON object for Flow JSON update.")}else if(t.file instanceof Blob)l=t.file,R.append("file",l);else throw new Error("Invalid file type provided for Flow JSON update. Must be a Buffer, JSON object, or Blob.");return R.append("asset_type","FLOW_JSON"),R.append("name",t.name||"flow.json"),this.sendFormData("POST",`/${i}/assets`,this.config.REQUEST_TIMEOUT,R)}async validateFlowJson(i,t){try{let R=await this.updateFlowJson(i,{file:t}),l=!R.validation_errors||R.validation_errors.length===0;return{...R,valid:l}}catch(R){throw N.error("Error during Flow JSON validation attempt:",R),R}}async publishFlow(i){return this.sendJson("POST",`/${i}/publish`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async deprecateFlow(i){return this.sendJson("POST",`/${i}/deprecate`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async migrateFlows(i,t){let R={source_waba_id:t.source_waba_id,...t.source_flow_names&&{source_flow_names:t.source_flow_names}};return this.sendJson("POST",`/${i}/migrate_flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(R))}};export{D as default};
1
+ var A=class{name;debug;constructor(i,t=!1){this.name=i,this.debug=t}log(...i){if(this.debug){let t=`[ ${Date.now()} ]`;this.name&&(t+=` - ${this.name}`),console.log.apply(console,[t,": ",...i])}}error(...i){let t=`[ ${Date.now()} ] - ERROR`;this.name&&(t+=` - ${this.name}`),console.error.apply(console,[t,": ",...i])}warn(...i){let t=`[ ${Date.now()} ] - WARN`;this.name&&(t+=` - ${this.name}`),console.warn.apply(console,[t,": ",...i])}info(...i){let t=`[ ${Date.now()} ] - INFO`;this.name&&(t+=` - ${this.name}`),console.info.apply(console,[t,": ",...i])}};var B="BaseAPI",O=!1,G=new A(B,process.env.DEBUG==="true"||O),S=class{config;client;constructor(i,t){this.config=i,this.client=t,G.log("Initialized with HTTPSClient")}sendJson(i,t,l,R){return this.client.getJson(i,t,l,R)}sendFormData(i,t,l,R){return this.client.sendFormData(i,t,l,R)}sendUrlEncodedForm(i,t,l,R){return this.client.sendUrlEncodedForm(i,t,l,R)}};var U="FlowAPI",_=!1,N=new A(U,process.env.DEBUG==="true"||_),D=class extends S{constructor(i,t){super(i,t),N.log("FlowAPI initialized")}async listFlows(i){return this.sendJson("GET",`/${i}/flows`,this.config.REQUEST_TIMEOUT,null)}async createFlow(i,t){let l={name:t.name,categories:t.categories,...t.endpoint_uri&&{endpoint_uri:t.endpoint_uri},...t.clone_flow_id&&{clone_flow_id:t.clone_flow_id},...t.flow_json&&{flow_json:t.flow_json},...t.publish!==void 0&&{publish:t.publish}};return this.sendJson("POST",`/${i}/flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(l))}async getFlow(i,t,l){let R=new URLSearchParams;t&&R.append("fields",t),l&&R.append("date_format",l);let P=R.toString()?`?${R.toString()}`:"";return this.sendJson("GET",`/${i}${P}`,this.config.REQUEST_TIMEOUT,null)}async getFlowPreview(i,t=!1){let l=`preview.invalidate(${t})`;return this.getFlow(i,l)}async updateFlowMetadata(i,t){let l={...t.name&&{name:t.name},...t.categories&&{categories:t.categories},...t.endpoint_uri&&{endpoint_uri:t.endpoint_uri},...t.application_id&&{application_id:t.application_id}};return this.sendJson("POST",`/${i}`,this.config.REQUEST_TIMEOUT,JSON.stringify(l))}async deleteFlow(i){return this.sendJson("DELETE",`/${i}`,this.config.REQUEST_TIMEOUT,null)}async listAssets(i){return this.sendJson("GET",`/${i}/assets`,this.config.REQUEST_TIMEOUT,null)}async updateFlowJson(i,t){let l=new FormData,R;if(t.file instanceof Buffer)R=new globalThis.Blob([t.file]),l.append("file",R);else if(typeof t.file=="object"&&!(t.file instanceof Blob))try{R=new globalThis.Blob([JSON.stringify(t.file,null,2)],{type:"application/json"}),l.append("file",R)}catch{throw new Error("Failed to stringify JSON object for Flow JSON update.")}else if(t.file instanceof Blob)R=t.file,l.append("file",R);else throw new Error("Invalid file type provided for Flow JSON update. Must be a Buffer, JSON object, or Blob.");return l.append("asset_type","FLOW_JSON"),l.append("name",t.name||"flow.json"),this.sendFormData("POST",`/${i}/assets`,this.config.REQUEST_TIMEOUT,l)}async validateFlowJson(i,t){try{let l=await this.updateFlowJson(i,{file:t}),R=!l.validation_errors||l.validation_errors.length===0;return{...l,valid:R}}catch(l){throw N.error("Error during Flow JSON validation attempt:",l),l}}async publishFlow(i){return this.sendJson("POST",`/${i}/publish`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async deprecateFlow(i){return this.sendJson("POST",`/${i}/deprecate`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async migrateFlows(i,t){let l={source_waba_id:t.source_waba_id,...t.source_flow_names&&{source_flow_names:t.source_flow_names}};return this.sendJson("POST",`/${i}/migrate_flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(l))}};export{D as default};
2
2
  //# sourceMappingURL=flow.mjs.map
@@ -10,7 +10,7 @@ export { default as RegistrationAPI } from './registration.mjs';
10
10
  export { default as TemplateAPI } from './template.mjs';
11
11
  export { default as TwoStepVerificationAPI } from './twoStepVerification.mjs';
12
12
  export { default as WabaAPI } from './waba.mjs';
13
- import '../enums-BYfW0iLO.mjs';
13
+ import '../enums-Bcd3jLw2.mjs';
14
14
  import '../types/base.mjs';
15
15
  import '../types/config.mjs';
16
16
  import '../types/request.mjs';
@@ -10,7 +10,7 @@ export { default as RegistrationAPI } from './registration.js';
10
10
  export { default as TemplateAPI } from './template.js';
11
11
  export { default as TwoStepVerificationAPI } from './twoStepVerification.js';
12
12
  export { default as WabaAPI } from './waba.js';
13
- import '../enums-BYfW0iLO.js';
13
+ import '../enums-Bcd3jLw2.js';
14
14
  import '../types/base.js';
15
15
  import '../types/config.js';
16
16
  import '../types/request.js';