meta-cloud-api 0.0.3 → 0.0.5

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 (173) hide show
  1. package/README.md +216 -0
  2. package/dist/api/base.d.mts +1 -1
  3. package/dist/api/base.d.ts +1 -1
  4. package/dist/api/businessProfile.d.mts +142 -0
  5. package/dist/api/businessProfile.d.ts +142 -0
  6. package/dist/api/businessProfile.js +2 -0
  7. package/dist/api/businessProfile.js.map +1 -0
  8. package/dist/api/businessProfile.mjs +2 -0
  9. package/dist/api/businessProfile.mjs.map +1 -0
  10. package/dist/api/encryption.d.mts +1 -1
  11. package/dist/api/encryption.d.ts +1 -1
  12. package/dist/api/encryption.js +1 -1
  13. package/dist/api/encryption.mjs +1 -1
  14. package/dist/api/flow.d.mts +1 -1
  15. package/dist/api/flow.d.ts +1 -1
  16. package/dist/api/flow.js +1 -1
  17. package/dist/api/flow.mjs +1 -1
  18. package/dist/api/index.d.mts +16 -14
  19. package/dist/api/index.d.ts +16 -14
  20. package/dist/api/index.js +1 -1
  21. package/dist/api/index.js.map +1 -1
  22. package/dist/api/index.mjs +1 -1
  23. package/dist/api/index.mjs.map +1 -1
  24. package/dist/api/media.d.mts +1 -1
  25. package/dist/api/media.d.ts +1 -1
  26. package/dist/api/media.js +1 -1
  27. package/dist/api/media.mjs +1 -1
  28. package/dist/api/messages.d.mts +1 -1
  29. package/dist/api/messages.d.ts +1 -1
  30. package/dist/api/messages.js +1 -1
  31. package/dist/api/messages.mjs +1 -1
  32. package/dist/api/phoneNumber.d.mts +1 -1
  33. package/dist/api/phoneNumber.d.ts +1 -1
  34. package/dist/api/phoneNumber.js +1 -1
  35. package/dist/api/phoneNumber.mjs +1 -1
  36. package/dist/api/qrCode.d.mts +1 -1
  37. package/dist/api/qrCode.d.ts +1 -1
  38. package/dist/api/qrCode.js +1 -1
  39. package/dist/api/qrCode.mjs +1 -1
  40. package/dist/api/registration.d.mts +1 -1
  41. package/dist/api/registration.d.ts +1 -1
  42. package/dist/api/registration.js +1 -1
  43. package/dist/api/registration.mjs +1 -1
  44. package/dist/api/template.d.mts +1 -1
  45. package/dist/api/template.d.ts +1 -1
  46. package/dist/api/template.js +1 -1
  47. package/dist/api/template.mjs +1 -1
  48. package/dist/api/twoStepVerification.d.mts +1 -1
  49. package/dist/api/twoStepVerification.d.ts +1 -1
  50. package/dist/api/twoStepVerification.js +1 -1
  51. package/dist/api/twoStepVerification.mjs +1 -1
  52. package/dist/api/waba.d.mts +1 -1
  53. package/dist/api/waba.d.ts +1 -1
  54. package/dist/api/waba.js +1 -1
  55. package/dist/api/waba.mjs +1 -1
  56. package/dist/{enums-D6WRUWH9.d.mts → enums-Dn5Y1Nom.d.mts} +94 -2
  57. package/dist/{enums-D6WRUWH9.d.ts → enums-Dn5Y1Nom.d.ts} +94 -2
  58. package/dist/httpsClient.d.mts +1 -1
  59. package/dist/httpsClient.d.ts +1 -1
  60. package/dist/index.d.mts +20 -18
  61. package/dist/index.d.ts +20 -18
  62. package/dist/index.js +1 -1
  63. package/dist/index.js.map +1 -1
  64. package/dist/index.mjs +1 -1
  65. package/dist/index.mjs.map +1 -1
  66. package/dist/request.d.mts +1 -1
  67. package/dist/request.d.ts +1 -1
  68. package/dist/types/base.d.mts +1 -1
  69. package/dist/types/base.d.ts +1 -1
  70. package/dist/types/businessProfile.d.mts +147 -0
  71. package/dist/types/businessProfile.d.ts +147 -0
  72. package/dist/types/businessProfile.js +2 -0
  73. package/dist/types/businessProfile.js.map +1 -0
  74. package/dist/types/businessProfile.mjs +1 -0
  75. package/dist/types/businessProfile.mjs.map +1 -0
  76. package/dist/types/config.d.mts +1 -1
  77. package/dist/types/config.d.ts +1 -1
  78. package/dist/types/encryption.d.mts +1 -1
  79. package/dist/types/encryption.d.ts +1 -1
  80. package/dist/types/enums.d.mts +1 -1
  81. package/dist/types/enums.d.ts +1 -1
  82. package/dist/types/enums.js +1 -1
  83. package/dist/types/enums.js.map +1 -1
  84. package/dist/types/enums.mjs +1 -1
  85. package/dist/types/enums.mjs.map +1 -1
  86. package/dist/types/flow.d.mts +1 -1
  87. package/dist/types/flow.d.ts +1 -1
  88. package/dist/types/httpsClient.d.mts +1 -1
  89. package/dist/types/httpsClient.d.ts +1 -1
  90. package/dist/types/index.d.mts +3 -1
  91. package/dist/types/index.d.ts +3 -1
  92. package/dist/types/index.js +1 -1
  93. package/dist/types/index.js.map +1 -1
  94. package/dist/types/index.mjs +1 -1
  95. package/dist/types/index.mjs.map +1 -1
  96. package/dist/types/media.d.mts +1 -1
  97. package/dist/types/media.d.ts +1 -1
  98. package/dist/types/messages.d.mts +1 -1
  99. package/dist/types/messages.d.ts +1 -1
  100. package/dist/types/phoneNumber.d.mts +1 -1
  101. package/dist/types/phoneNumber.d.ts +1 -1
  102. package/dist/types/qrCode.d.mts +1 -1
  103. package/dist/types/qrCode.d.ts +1 -1
  104. package/dist/types/registration.d.mts +1 -1
  105. package/dist/types/registration.d.ts +1 -1
  106. package/dist/types/request.d.mts +1 -1
  107. package/dist/types/request.d.ts +1 -1
  108. package/dist/types/template.d.mts +1 -1
  109. package/dist/types/template.d.ts +1 -1
  110. package/dist/types/twoStepVerification.d.mts +1 -1
  111. package/dist/types/twoStepVerification.d.ts +1 -1
  112. package/dist/types/waba.d.mts +1 -1
  113. package/dist/types/waba.d.ts +1 -1
  114. package/dist/types/whatsapp.d.mts +28 -0
  115. package/dist/types/whatsapp.d.ts +28 -0
  116. package/dist/types/whatsapp.js +1 -1
  117. package/dist/types/whatsapp.js.map +1 -1
  118. package/dist/utils/importConfig.d.mts +14 -1
  119. package/dist/utils/importConfig.d.ts +14 -1
  120. package/dist/utils/importConfig.js +1 -1
  121. package/dist/utils/importConfig.mjs +1 -1
  122. package/dist/utils/index.d.mts +14 -1
  123. package/dist/utils/index.d.ts +14 -1
  124. package/dist/utils/index.js +1 -1
  125. package/dist/utils/index.mjs +1 -1
  126. package/dist/whatsapp.d.mts +21 -18
  127. package/dist/whatsapp.d.ts +21 -18
  128. package/dist/whatsapp.js +1 -1
  129. package/dist/whatsapp.js.map +1 -1
  130. package/dist/whatsapp.mjs +1 -1
  131. package/dist/whatsapp.mjs.map +1 -1
  132. package/package.json +2 -2
  133. package/src/api/base.ts +0 -19
  134. package/src/api/encryption.ts +0 -34
  135. package/src/api/flow.ts +0 -253
  136. package/src/api/index.ts +0 -24
  137. package/src/api/media.ts +0 -52
  138. package/src/api/messages.ts +0 -160
  139. package/src/api/phoneNumber.ts +0 -59
  140. package/src/api/qrCode.ts +0 -64
  141. package/src/api/registration.ts +0 -38
  142. package/src/api/template.ts +0 -70
  143. package/src/api/twoStepVerification.ts +0 -24
  144. package/src/api/waba.ts +0 -55
  145. package/src/httpsClient.ts +0 -83
  146. package/src/index.ts +0 -3
  147. package/src/request.ts +0 -104
  148. package/src/types/base.ts +0 -5
  149. package/src/types/config.ts +0 -68
  150. package/src/types/encryption.ts +0 -11
  151. package/src/types/enums.ts +0 -563
  152. package/src/types/flow.ts +0 -274
  153. package/src/types/httpsClient.ts +0 -28
  154. package/src/types/index.ts +0 -16
  155. package/src/types/logger.ts +0 -7
  156. package/src/types/media.ts +0 -31
  157. package/src/types/messages.ts +0 -453
  158. package/src/types/phoneNumber.ts +0 -111
  159. package/src/types/qrCode.ts +0 -30
  160. package/src/types/registration.ts +0 -17
  161. package/src/types/request.ts +0 -66
  162. package/src/types/template.ts +0 -134
  163. package/src/types/twoStepVerification.ts +0 -9
  164. package/src/types/waba.ts +0 -18
  165. package/src/types/whatsapp.ts +0 -31
  166. package/src/utils/.gitkeep +0 -0
  167. package/src/utils/generateXHub256Sig.ts +0 -5
  168. package/src/utils/importConfig.ts +0 -55
  169. package/src/utils/index.ts +0 -2
  170. package/src/utils/isMetaError.ts +0 -44
  171. package/src/utils/logger.ts +0 -46
  172. package/src/utils/objectToQueryString.ts +0 -16
  173. package/src/whatsapp.ts +0 -96
package/README.md ADDED
@@ -0,0 +1,216 @@
1
+ # Meta Cloud API
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.
4
+
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)
8
+
9
+ ## Features
10
+
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
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ npm install meta-cloud-api
30
+ # or
31
+ yarn add meta-cloud-api
32
+ # or
33
+ pnpm add meta-cloud-api
34
+ ```
35
+
36
+ ## Quick Start
37
+
38
+ ```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
+ ```
63
+
64
+ ## Environment Variables
65
+
66
+ Create a `.env` file with your WhatsApp Cloud API credentials:
67
+
68
+ ```
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
+
78
+ ## API Documentation
79
+
80
+ ### Messages API
81
+
82
+ Send various types of WhatsApp messages:
83
+
84
+ ```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" },
111
+ components: [
112
+ {
113
+ type: "body",
114
+ parameters: [
115
+ { type: "text", text: "John" },
116
+ { type: "text", text: "12345" }
117
+ ]
118
+ }
119
+ ]
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:" },
129
+ action: {
130
+ buttons: [
131
+ { type: "reply", reply: { id: "btn1", title: "Option 1" } },
132
+ { type: "reply", reply: { id: "btn2", title: "Option 2" } }
133
+ ]
134
+ }
135
+ },
136
+ 15551234567
137
+ );
138
+ ```
139
+
140
+ ### Templates API
141
+
142
+ Work with message templates:
143
+
144
+ ```typescript
145
+ // Get all templates
146
+ const templates = await whatsapp.template.getTemplates({
147
+ limit: 20
148
+ });
149
+
150
+ // Create a new template
151
+ await whatsapp.template.createTemplate({
152
+ name: "my_template",
153
+ category: "MARKETING",
154
+ language: "en_US",
155
+ components: [
156
+ {
157
+ type: "HEADER",
158
+ format: "TEXT",
159
+ text: "Special Offer"
160
+ },
161
+ {
162
+ type: "BODY",
163
+ text: "Hi {{1}}, check out our latest offer: {{2}}!"
164
+ }
165
+ ]
166
+ });
167
+ ```
168
+
169
+ ### Media API
170
+
171
+ Handle media files:
172
+
173
+ ```typescript
174
+ // Upload media
175
+ const mediaResponse = await whatsapp.media.uploadMedia(
176
+ new File(['...'], 'image.jpg', { type: 'image/jpeg' })
177
+ );
178
+
179
+ // Get media details
180
+ const mediaDetails = await whatsapp.media.getMediaById(mediaResponse.id);
181
+
182
+ // Delete media
183
+ await whatsapp.media.deleteMedia(mediaResponse.id);
184
+ ```
185
+
186
+ ## Error Handling
187
+
188
+ The package provides standard error handling for Meta API responses:
189
+
190
+ ```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
+ }
208
+ ```
209
+
210
+ ## License
211
+
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.
213
+
214
+ ## Contributing
215
+
216
+ Contributions welcome! Please feel free to submit a Pull Request.
@@ -1,7 +1,7 @@
1
1
  import { BaseClass } from '../types/base.mjs';
2
2
  import { WabaConfigType } from '../types/config.mjs';
3
3
  import { RequesterClass } from '../types/request.mjs';
4
- import '../enums-D6WRUWH9.mjs';
4
+ import '../enums-Dn5Y1Nom.mjs';
5
5
 
6
6
  declare class BaseAPI implements BaseClass {
7
7
  protected config: WabaConfigType;
@@ -1,7 +1,7 @@
1
1
  import { BaseClass } from '../types/base.js';
2
2
  import { WabaConfigType } from '../types/config.js';
3
3
  import { RequesterClass } from '../types/request.js';
4
- import '../enums-D6WRUWH9.js';
4
+ import '../enums-Dn5Y1Nom.js';
5
5
 
6
6
  declare class BaseAPI implements BaseClass {
7
7
  protected config: WabaConfigType;
@@ -0,0 +1,142 @@
1
+ import { BusinessProfileClass, BusinessProfileResponse, UpdateBusinessProfileRequest, UploadSessionResponse, UploadHandle } from '../types/businessProfile.mjs';
2
+ import { WabaConfigType } from '../types/config.mjs';
3
+ import { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request.mjs';
4
+ import BaseAPI from './base.mjs';
5
+ import '../enums-Dn5Y1Nom.mjs';
6
+ import '../types/base.mjs';
7
+
8
+ /**
9
+ * API for managing WhatsApp Business Profiles and profile pictures.
10
+ *
11
+ * This API allows you to:
12
+ * - Get business profile information
13
+ * - Update business profile details
14
+ * - Upload profile pictures using a three-step process:
15
+ * 1. Create an upload session
16
+ * 2. Upload the image binary data
17
+ * 3. Get the upload handle to use when updating the profile
18
+ */
19
+ declare class BusinessProfileAPI extends BaseAPI implements BusinessProfileClass {
20
+ private readonly endpoint;
21
+ constructor(config: WabaConfigType, client: RequesterClass);
22
+ /**
23
+ * Get your business profile information.
24
+ *
25
+ * Use this method to retrieve details about your WhatsApp business profile, including
26
+ * about text, address, description, email, profile picture URL, websites, and vertical.
27
+ *
28
+ * @param fields Fields to be returned in the response. If not specified, all fields will be returned.
29
+ * Possible values: about, address, description, email, profile_picture_url, websites, vertical
30
+ * @returns The business profile information.
31
+ *
32
+ * @example
33
+ * // Get all business profile fields
34
+ * const profile = await whatsappClient.businessProfile.getBusinessProfile();
35
+ *
36
+ * // Get specific business profile fields
37
+ * const profile = await whatsappClient.businessProfile.getBusinessProfile('about,address,email');
38
+ */
39
+ getBusinessProfile(fields?: string): Promise<RequesterResponseInterface<BusinessProfileResponse>>;
40
+ /**
41
+ * Update your business profile.
42
+ *
43
+ * Use this method to update one or more fields of your WhatsApp business profile.
44
+ *
45
+ * @param updateRequest The request object containing the fields to update.
46
+ * - messaging_product: Required. Always set to "whatsapp".
47
+ * - about: Optional. Business's About text (1-139 characters).
48
+ * - address: Optional. Business address (max 256 characters).
49
+ * - description: Optional. Business description (max 512 characters).
50
+ * - vertical: Optional. Business category (use BusinessVerticalEnum for type safety).
51
+ * - email: Optional. Contact email (valid format, max 128 characters).
52
+ * - websites: Optional. Up to 2 URLs (max 256 characters each).
53
+ * - profile_picture_handle: Optional. Handle from upload process.
54
+ * @returns Response indicating success or failure.
55
+ *
56
+ * @example
57
+ * // Update business profile with multiple fields including vertical using enum
58
+ * await whatsappClient.businessProfile.updateBusinessProfile({
59
+ * messaging_product: 'whatsapp',
60
+ * about: 'We provide excellent service',
61
+ * email: 'contact@example.com',
62
+ * websites: ['https://example.com'],
63
+ * vertical: BusinessVerticalEnum.RETAIL
64
+ * });
65
+ */
66
+ updateBusinessProfile(updateRequest: UpdateBusinessProfileRequest): Promise<RequesterResponseInterface<ResponseSuccess>>;
67
+ /**
68
+ * Create an upload session for a profile picture.
69
+ *
70
+ * This is the first step in the profile picture upload process.
71
+ *
72
+ * @param fileLength Length of the file to be uploaded in bytes.
73
+ * @param fileType MIME type of the file (e.g., 'image/jpeg').
74
+ * @param fileName Name of the file with extension.
75
+ * @returns Response containing the upload session ID needed for the next step.
76
+ *
77
+ * @example
78
+ * // Create upload session for profile picture
79
+ * const session = await whatsappClient.businessProfile.createUploadSession(
80
+ * fileBuffer.length,
81
+ * 'image/jpeg',
82
+ * 'profile.jpg'
83
+ * );
84
+ * const uploadSessionId = session.upload_session_id;
85
+ */
86
+ createUploadSession(fileLength: number, fileType: string, fileName: string): Promise<RequesterResponseInterface<UploadSessionResponse>>;
87
+ /**
88
+ * Upload media file to the upload session.
89
+ *
90
+ * This is the second step in the profile picture upload process.
91
+ * Upload the binary content of the file to the previously created upload session.
92
+ *
93
+ * @param uploadId The upload session ID from createUploadSession response.
94
+ * @param file The binary data of the file (Buffer).
95
+ * @returns Response indicating success or failure.
96
+ *
97
+ * @example
98
+ * // Upload the actual file content
99
+ * await whatsappClient.businessProfile.uploadMedia(
100
+ * uploadSessionId,
101
+ * fileBuffer
102
+ * );
103
+ */
104
+ uploadMedia(uploadId: string, file: Buffer): Promise<RequesterResponseInterface<ResponseSuccess>>;
105
+ /**
106
+ * Get the upload handle information.
107
+ *
108
+ * This is the third step in the profile picture upload process.
109
+ * After uploading the file, get the handle to use when updating the profile.
110
+ *
111
+ * @param uploadId The upload session ID from createUploadSession response.
112
+ * @returns Response containing the upload handle information.
113
+ *
114
+ * @example
115
+ * // Complete profile picture update process
116
+ * // 1. Create upload session
117
+ * const session = await whatsappClient.businessProfile.createUploadSession(
118
+ * fileBuffer.length, 'image/jpeg', 'profile.jpg'
119
+ * );
120
+ *
121
+ * // 2. Upload the image data
122
+ * await whatsappClient.businessProfile.uploadMedia(
123
+ * session.upload_session_id, fileBuffer
124
+ * );
125
+ *
126
+ * // 3. Get the handle for the uploaded file
127
+ * const handleInfo = await whatsappClient.businessProfile.getUploadHandle(
128
+ * session.upload_session_id
129
+ * );
130
+ *
131
+ * // 4. Update profile with new picture and business information
132
+ * await whatsappClient.businessProfile.updateBusinessProfile({
133
+ * messaging_product: 'whatsapp',
134
+ * profile_picture_handle: handleInfo.handle,
135
+ * vertical: BusinessVerticalEnum.RESTAURANT,
136
+ * about: 'Delicious food served daily'
137
+ * });
138
+ */
139
+ getUploadHandle(uploadId: string): Promise<RequesterResponseInterface<UploadHandle>>;
140
+ }
141
+
142
+ export { BusinessProfileAPI as default };
@@ -0,0 +1,142 @@
1
+ import { BusinessProfileClass, BusinessProfileResponse, UpdateBusinessProfileRequest, UploadSessionResponse, UploadHandle } from '../types/businessProfile.js';
2
+ import { WabaConfigType } from '../types/config.js';
3
+ import { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request.js';
4
+ import BaseAPI from './base.js';
5
+ import '../enums-Dn5Y1Nom.js';
6
+ import '../types/base.js';
7
+
8
+ /**
9
+ * API for managing WhatsApp Business Profiles and profile pictures.
10
+ *
11
+ * This API allows you to:
12
+ * - Get business profile information
13
+ * - Update business profile details
14
+ * - Upload profile pictures using a three-step process:
15
+ * 1. Create an upload session
16
+ * 2. Upload the image binary data
17
+ * 3. Get the upload handle to use when updating the profile
18
+ */
19
+ declare class BusinessProfileAPI extends BaseAPI implements BusinessProfileClass {
20
+ private readonly endpoint;
21
+ constructor(config: WabaConfigType, client: RequesterClass);
22
+ /**
23
+ * Get your business profile information.
24
+ *
25
+ * Use this method to retrieve details about your WhatsApp business profile, including
26
+ * about text, address, description, email, profile picture URL, websites, and vertical.
27
+ *
28
+ * @param fields Fields to be returned in the response. If not specified, all fields will be returned.
29
+ * Possible values: about, address, description, email, profile_picture_url, websites, vertical
30
+ * @returns The business profile information.
31
+ *
32
+ * @example
33
+ * // Get all business profile fields
34
+ * const profile = await whatsappClient.businessProfile.getBusinessProfile();
35
+ *
36
+ * // Get specific business profile fields
37
+ * const profile = await whatsappClient.businessProfile.getBusinessProfile('about,address,email');
38
+ */
39
+ getBusinessProfile(fields?: string): Promise<RequesterResponseInterface<BusinessProfileResponse>>;
40
+ /**
41
+ * Update your business profile.
42
+ *
43
+ * Use this method to update one or more fields of your WhatsApp business profile.
44
+ *
45
+ * @param updateRequest The request object containing the fields to update.
46
+ * - messaging_product: Required. Always set to "whatsapp".
47
+ * - about: Optional. Business's About text (1-139 characters).
48
+ * - address: Optional. Business address (max 256 characters).
49
+ * - description: Optional. Business description (max 512 characters).
50
+ * - vertical: Optional. Business category (use BusinessVerticalEnum for type safety).
51
+ * - email: Optional. Contact email (valid format, max 128 characters).
52
+ * - websites: Optional. Up to 2 URLs (max 256 characters each).
53
+ * - profile_picture_handle: Optional. Handle from upload process.
54
+ * @returns Response indicating success or failure.
55
+ *
56
+ * @example
57
+ * // Update business profile with multiple fields including vertical using enum
58
+ * await whatsappClient.businessProfile.updateBusinessProfile({
59
+ * messaging_product: 'whatsapp',
60
+ * about: 'We provide excellent service',
61
+ * email: 'contact@example.com',
62
+ * websites: ['https://example.com'],
63
+ * vertical: BusinessVerticalEnum.RETAIL
64
+ * });
65
+ */
66
+ updateBusinessProfile(updateRequest: UpdateBusinessProfileRequest): Promise<RequesterResponseInterface<ResponseSuccess>>;
67
+ /**
68
+ * Create an upload session for a profile picture.
69
+ *
70
+ * This is the first step in the profile picture upload process.
71
+ *
72
+ * @param fileLength Length of the file to be uploaded in bytes.
73
+ * @param fileType MIME type of the file (e.g., 'image/jpeg').
74
+ * @param fileName Name of the file with extension.
75
+ * @returns Response containing the upload session ID needed for the next step.
76
+ *
77
+ * @example
78
+ * // Create upload session for profile picture
79
+ * const session = await whatsappClient.businessProfile.createUploadSession(
80
+ * fileBuffer.length,
81
+ * 'image/jpeg',
82
+ * 'profile.jpg'
83
+ * );
84
+ * const uploadSessionId = session.upload_session_id;
85
+ */
86
+ createUploadSession(fileLength: number, fileType: string, fileName: string): Promise<RequesterResponseInterface<UploadSessionResponse>>;
87
+ /**
88
+ * Upload media file to the upload session.
89
+ *
90
+ * This is the second step in the profile picture upload process.
91
+ * Upload the binary content of the file to the previously created upload session.
92
+ *
93
+ * @param uploadId The upload session ID from createUploadSession response.
94
+ * @param file The binary data of the file (Buffer).
95
+ * @returns Response indicating success or failure.
96
+ *
97
+ * @example
98
+ * // Upload the actual file content
99
+ * await whatsappClient.businessProfile.uploadMedia(
100
+ * uploadSessionId,
101
+ * fileBuffer
102
+ * );
103
+ */
104
+ uploadMedia(uploadId: string, file: Buffer): Promise<RequesterResponseInterface<ResponseSuccess>>;
105
+ /**
106
+ * Get the upload handle information.
107
+ *
108
+ * This is the third step in the profile picture upload process.
109
+ * After uploading the file, get the handle to use when updating the profile.
110
+ *
111
+ * @param uploadId The upload session ID from createUploadSession response.
112
+ * @returns Response containing the upload handle information.
113
+ *
114
+ * @example
115
+ * // Complete profile picture update process
116
+ * // 1. Create upload session
117
+ * const session = await whatsappClient.businessProfile.createUploadSession(
118
+ * fileBuffer.length, 'image/jpeg', 'profile.jpg'
119
+ * );
120
+ *
121
+ * // 2. Upload the image data
122
+ * await whatsappClient.businessProfile.uploadMedia(
123
+ * session.upload_session_id, fileBuffer
124
+ * );
125
+ *
126
+ * // 3. Get the handle for the uploaded file
127
+ * const handleInfo = await whatsappClient.businessProfile.getUploadHandle(
128
+ * session.upload_session_id
129
+ * );
130
+ *
131
+ * // 4. Update profile with new picture and business information
132
+ * await whatsappClient.businessProfile.updateBusinessProfile({
133
+ * messaging_product: 'whatsapp',
134
+ * profile_picture_handle: handleInfo.handle,
135
+ * vertical: BusinessVerticalEnum.RESTAURANT,
136
+ * about: 'Delicious food served daily'
137
+ * });
138
+ */
139
+ getUploadHandle(uploadId: string): Promise<RequesterResponseInterface<UploadHandle>>;
140
+ }
141
+
142
+ export { BusinessProfileAPI as default };
@@ -0,0 +1,2 @@
1
+ "use strict";var U=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var I=(A,t)=>{for(var R in t)U(A,R,{get:t[R],enumerable:!0})},l=(A,t,R,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let S of O(t))!p.call(A,S)&&S!==R&&U(A,S,{get:()=>t[S],enumerable:!(i=G(t,S))||i.enumerable});return A};var T=A=>l(U({},"__esModule",{value:!0}),A);var f={};I(f,{default:()=>N});module.exports=T(f);var B=A=>{if(!A||Object.keys(A).length===0)return"";let t=new URLSearchParams;for(let[i,S]of Object.entries(A))S!==void 0&&t.append(i,String(S));let R=t.toString();return R?`?${R}`:""};var P=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 K="BaseAPI",M=!1,_=new P(K,process.env.DEBUG==="true"||M),D=class{config;client;constructor(t,R){this.config=t,this.client=R,_.log("Initialized with HTTPSClient")}};var N=class extends D{endpoint="whatsapp_business_profile";constructor(t,R){super(t,R)}async getBusinessProfile(t){let R=t?B({fields:t}):"";return this.client.sendRequest("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}${R}`,this.config.REQUEST_TIMEOUT,null)}async updateBusinessProfile(t){return this.client.sendRequest("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async createUploadSession(t,R,i){let S=B({file_length:t,file_type:R,file_name:i});return this.client.sendRequest("POST",`app/uploads/${S}`,this.config.REQUEST_TIMEOUT,null)}async uploadMedia(t,R){return this.client.sendRequest("POST",`${t}`,this.config.REQUEST_TIMEOUT,R)}async getUploadHandle(t){return this.client.sendRequest("GET",`${t}`,this.config.REQUEST_TIMEOUT,null)}};
2
+ //# sourceMappingURL=businessProfile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/api/businessProfile.ts","../../src/utils/objectToQueryString.ts","../../src/utils/logger.ts","../../src/api/base.ts"],"sourcesContent":["import {\n BusinessProfileClass,\n BusinessProfileResponse,\n UpdateBusinessProfileRequest,\n UploadHandle,\n UploadSessionResponse,\n} from '../types/businessProfile';\nimport type { WabaConfigType } from '../types/config';\nimport { HttpMethodsEnum, WabaConfigEnum } from '../types/enums';\nimport type { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request';\nimport { objectToQueryString } from '../utils/objectToQueryString';\nimport BaseAPI from './base';\n\n/**\n * API for managing WhatsApp Business Profiles and profile pictures.\n *\n * This API allows you to:\n * - Get business profile information\n * - Update business profile details\n * - Upload profile pictures using a three-step process:\n * 1. Create an upload session\n * 2. Upload the image binary data\n * 3. Get the upload handle to use when updating the profile\n */\nexport default class BusinessProfileAPI extends BaseAPI implements BusinessProfileClass {\n private readonly endpoint = 'whatsapp_business_profile';\n\n constructor(config: WabaConfigType, client: RequesterClass) {\n super(config, client);\n }\n\n /**\n * Get your business profile information.\n *\n * Use this method to retrieve details about your WhatsApp business profile, including\n * about text, address, description, email, profile picture URL, websites, and vertical.\n *\n * @param fields Fields to be returned in the response. If not specified, all fields will be returned.\n * Possible values: about, address, description, email, profile_picture_url, websites, vertical\n * @returns The business profile information.\n *\n * @example\n * // Get all business profile fields\n * const profile = await whatsappClient.businessProfile.getBusinessProfile();\n *\n * // Get specific business profile fields\n * const profile = await whatsappClient.businessProfile.getBusinessProfile('about,address,email');\n */\n async getBusinessProfile(fields?: string): Promise<RequesterResponseInterface<BusinessProfileResponse>> {\n const queryParams = fields ? objectToQueryString({ fields }) : '';\n return this.client.sendRequest(\n HttpMethodsEnum.Get,\n `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}${queryParams}`,\n this.config[WabaConfigEnum.RequestTimeout],\n null,\n );\n }\n\n /**\n * Update your business profile.\n *\n * Use this method to update one or more fields of your WhatsApp business profile.\n *\n * @param updateRequest The request object containing the fields to update.\n * - messaging_product: Required. Always set to \"whatsapp\".\n * - about: Optional. Business's About text (1-139 characters).\n * - address: Optional. Business address (max 256 characters).\n * - description: Optional. Business description (max 512 characters).\n * - vertical: Optional. Business category (use BusinessVerticalEnum for type safety).\n * - email: Optional. Contact email (valid format, max 128 characters).\n * - websites: Optional. Up to 2 URLs (max 256 characters each).\n * - profile_picture_handle: Optional. Handle from upload process.\n * @returns Response indicating success or failure.\n *\n * @example\n * // Update business profile with multiple fields including vertical using enum\n * await whatsappClient.businessProfile.updateBusinessProfile({\n * messaging_product: 'whatsapp',\n * about: 'We provide excellent service',\n * email: 'contact@example.com',\n * websites: ['https://example.com'],\n * vertical: BusinessVerticalEnum.RETAIL\n * });\n */\n async updateBusinessProfile(\n updateRequest: UpdateBusinessProfileRequest,\n ): Promise<RequesterResponseInterface<ResponseSuccess>> {\n return this.client.sendRequest(\n HttpMethodsEnum.Post,\n `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}`,\n this.config[WabaConfigEnum.RequestTimeout],\n JSON.stringify(updateRequest),\n );\n }\n\n /**\n * Create an upload session for a profile picture.\n *\n * This is the first step in the profile picture upload process.\n *\n * @param fileLength Length of the file to be uploaded in bytes.\n * @param fileType MIME type of the file (e.g., 'image/jpeg').\n * @param fileName Name of the file with extension.\n * @returns Response containing the upload session ID needed for the next step.\n *\n * @example\n * // Create upload session for profile picture\n * const session = await whatsappClient.businessProfile.createUploadSession(\n * fileBuffer.length,\n * 'image/jpeg',\n * 'profile.jpg'\n * );\n * const uploadSessionId = session.upload_session_id;\n */\n async createUploadSession(\n fileLength: number,\n fileType: string,\n fileName: string,\n ): Promise<RequesterResponseInterface<UploadSessionResponse>> {\n const queryParams = objectToQueryString({\n file_length: fileLength,\n file_type: fileType,\n file_name: fileName,\n });\n\n return this.client.sendRequest(\n HttpMethodsEnum.Post,\n `app/uploads/${queryParams}`,\n this.config[WabaConfigEnum.RequestTimeout],\n null,\n );\n }\n\n /**\n * Upload media file to the upload session.\n *\n * This is the second step in the profile picture upload process.\n * Upload the binary content of the file to the previously created upload session.\n *\n * @param uploadId The upload session ID from createUploadSession response.\n * @param file The binary data of the file (Buffer).\n * @returns Response indicating success or failure.\n *\n * @example\n * // Upload the actual file content\n * await whatsappClient.businessProfile.uploadMedia(\n * uploadSessionId,\n * fileBuffer\n * );\n */\n async uploadMedia(uploadId: string, file: Buffer): Promise<RequesterResponseInterface<ResponseSuccess>> {\n return this.client.sendRequest(\n HttpMethodsEnum.Post,\n `${uploadId}`,\n this.config[WabaConfigEnum.RequestTimeout],\n file,\n );\n }\n\n /**\n * Get the upload handle information.\n *\n * This is the third step in the profile picture upload process.\n * After uploading the file, get the handle to use when updating the profile.\n *\n * @param uploadId The upload session ID from createUploadSession response.\n * @returns Response containing the upload handle information.\n *\n * @example\n * // Complete profile picture update process\n * // 1. Create upload session\n * const session = await whatsappClient.businessProfile.createUploadSession(\n * fileBuffer.length, 'image/jpeg', 'profile.jpg'\n * );\n *\n * // 2. Upload the image data\n * await whatsappClient.businessProfile.uploadMedia(\n * session.upload_session_id, fileBuffer\n * );\n *\n * // 3. Get the handle for the uploaded file\n * const handleInfo = await whatsappClient.businessProfile.getUploadHandle(\n * session.upload_session_id\n * );\n *\n * // 4. Update profile with new picture and business information\n * await whatsappClient.businessProfile.updateBusinessProfile({\n * messaging_product: 'whatsapp',\n * profile_picture_handle: handleInfo.handle,\n * vertical: BusinessVerticalEnum.RESTAURANT,\n * about: 'Delicious food served daily'\n * });\n */\n async getUploadHandle(uploadId: string): Promise<RequesterResponseInterface<UploadHandle>> {\n return this.client.sendRequest(\n HttpMethodsEnum.Get,\n `${uploadId}`,\n this.config[WabaConfigEnum.RequestTimeout],\n null,\n );\n }\n}\n","export const objectToQueryString = (params: Record<string, any>): string => {\n if (!params || Object.keys(params).length === 0) {\n return '';\n }\n\n const searchParams = new URLSearchParams();\n\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined) {\n searchParams.append(key, String(value));\n }\n }\n\n const queryString = searchParams.toString();\n return queryString ? `?${queryString}` : '';\n};\n","// @ts-nocheck\nimport type { LoggerInterface } from '../types/logger';\n\nexport default class Logger implements LoggerInterface {\n private name: string;\n private debug: boolean;\n\n constructor(name: string, debug: boolean = false) {\n this.name = name;\n this.debug = debug;\n }\n\n log(...data: any[]) {\n if (this.debug) {\n let prefix = `[ ${Date.now()} ]`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.log.apply(console, [prefix, ': ', ...data]);\n }\n }\n\n error(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - ERROR`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.error.apply(console, [prefix, ': ', ...data]);\n }\n\n warn(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - WARN`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.warn.apply(console, [prefix, ': ', ...data]);\n }\n\n info(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - INFO`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.info.apply(console, [prefix, ': ', ...data]);\n }\n}\n","import Logger from '../utils/logger';\nimport type { BaseClass } from '../types/base';\nimport type { WabaConfigType } from '../types/config';\nimport type { RequesterClass } from '../types/request';\n\nconst LIB_NAME = 'BaseAPI';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\n\nexport default class BaseAPI implements BaseClass {\n protected config: WabaConfigType;\n protected client: RequesterClass;\n\n constructor(config: WabaConfigType, client: RequesterClass) {\n this.config = config;\n this.client = client;\n LOGGER.log('Initialized with HTTPSClient');\n }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GCAO,IAAMI,EAAuBC,GAAwC,CACxE,GAAI,CAACA,GAAU,OAAO,KAAKA,CAAM,EAAE,SAAW,EAC1C,MAAO,GAGX,IAAMC,EAAe,IAAI,gBAEzB,OAAW,CAACC,EAAKC,CAAK,IAAK,OAAO,QAAQH,CAAM,EACxCG,IAAU,QACVF,EAAa,OAAOC,EAAK,OAAOC,CAAK,CAAC,EAI9C,IAAMC,EAAcH,EAAa,SAAS,EAC1C,OAAOG,EAAc,IAAIA,CAAW,GAAK,EAC7C,ECZA,IAAqBC,EAArB,KAAuD,CAC3C,KACA,MAER,YAAYC,EAAcC,EAAiB,GAAO,CAC9C,KAAK,KAAOD,EACZ,KAAK,MAAQC,CACjB,CAEA,OAAOC,EAAa,CAChB,GAAI,KAAK,MAAO,CACZ,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,KACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,QAAQ,IAAI,MAAM,QAAS,CAACA,EAAQ,KAAM,GAAGD,CAAI,CAAC,CACtD,CACJ,CAEA,SAASA,EAAa,CAClB,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,aACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,QAAQ,MAAM,MAAM,QAAS,CAACA,EAAQ,KAAM,GAAGD,CAAI,CAAC,CACxD,CAEA,QAAQA,EAAa,CACjB,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,YACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,QAAQ,KAAK,MAAM,QAAS,CAACA,EAAQ,KAAM,GAAGD,CAAI,CAAC,CACvD,CAEA,QAAQA,EAAa,CACjB,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,YACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,QAAQ,KAAK,MAAM,QAAS,CAACA,EAAQ,KAAM,GAAGD,CAAI,CAAC,CACvD,CACJ,ECxCA,IAAME,EAAW,UACXC,EAAY,GACZC,EAAS,IAAIC,EAAOH,EAAU,QAAQ,IAAI,QAAU,QAAUC,CAAS,EAExDG,EAArB,KAAkD,CACpC,OACA,OAEV,YAAYC,EAAwBC,EAAwB,CACxD,KAAK,OAASD,EACd,KAAK,OAASC,EACdJ,EAAO,IAAI,8BAA8B,CAC7C,CACJ,EHMA,IAAqBK,EAArB,cAAgDC,CAAwC,CACnE,SAAW,4BAE5B,YAAYC,EAAwBC,EAAwB,CACxD,MAAMD,EAAQC,CAAM,CACxB,CAmBA,MAAM,mBAAmBC,EAA+E,CACpG,IAAMC,EAAcD,EAASE,EAAoB,CAAE,OAAAF,CAAO,CAAC,EAAI,GAC/D,OAAO,KAAK,OAAO,kBAEf,GAAG,KAAK,OAAO,kBAA6B,IAAI,KAAK,QAAQ,GAAGC,CAAW,GAC3E,KAAK,OAAO,gBACZ,IACJ,CACJ,CA4BA,MAAM,sBACFE,EACoD,CACpD,OAAO,KAAK,OAAO,mBAEf,GAAG,KAAK,OAAO,kBAA6B,IAAI,KAAK,QAAQ,GAC7D,KAAK,OAAO,gBACZ,KAAK,UAAUA,CAAa,CAChC,CACJ,CAqBA,MAAM,oBACFC,EACAC,EACAC,EAC0D,CAC1D,IAAML,EAAcC,EAAoB,CACpC,YAAaE,EACb,UAAWC,EACX,UAAWC,CACf,CAAC,EAED,OAAO,KAAK,OAAO,mBAEf,eAAeL,CAAW,GAC1B,KAAK,OAAO,gBACZ,IACJ,CACJ,CAmBA,MAAM,YAAYM,EAAkBC,EAAoE,CACpG,OAAO,KAAK,OAAO,mBAEf,GAAGD,CAAQ,GACX,KAAK,OAAO,gBACZC,CACJ,CACJ,CAoCA,MAAM,gBAAgBD,EAAqE,CACvF,OAAO,KAAK,OAAO,kBAEf,GAAGA,CAAQ,GACX,KAAK,OAAO,gBACZ,IACJ,CACJ,CACJ","names":["businessProfile_exports","__export","BusinessProfileAPI","__toCommonJS","objectToQueryString","params","searchParams","key","value","queryString","Logger","name","debug","data","prefix","LIB_NAME","LOG_LOCAL","LOGGER","Logger","BaseAPI","config","client","BusinessProfileAPI","BaseAPI","config","client","fields","queryParams","objectToQueryString","updateRequest","fileLength","fileType","fileName","uploadId","file"]}
@@ -0,0 +1,2 @@
1
+ var N=A=>{if(!A||Object.keys(A).length===0)return"";let t=new URLSearchParams;for(let[D,P]of Object.entries(A))P!==void 0&&t.append(D,String(P));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 B="BaseAPI",G=!1,O=new S(B,process.env.DEBUG==="true"||G),i=class{config;client;constructor(t,R){this.config=t,this.client=R,O.log("Initialized with HTTPSClient")}};var U=class extends i{endpoint="whatsapp_business_profile";constructor(t,R){super(t,R)}async getBusinessProfile(t){let R=t?N({fields:t}):"";return this.client.sendRequest("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}${R}`,this.config.REQUEST_TIMEOUT,null)}async updateBusinessProfile(t){return this.client.sendRequest("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async createUploadSession(t,R,D){let P=N({file_length:t,file_type:R,file_name:D});return this.client.sendRequest("POST",`app/uploads/${P}`,this.config.REQUEST_TIMEOUT,null)}async uploadMedia(t,R){return this.client.sendRequest("POST",`${t}`,this.config.REQUEST_TIMEOUT,R)}async getUploadHandle(t){return this.client.sendRequest("GET",`${t}`,this.config.REQUEST_TIMEOUT,null)}};export{U as default};
2
+ //# sourceMappingURL=businessProfile.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/objectToQueryString.ts","../../src/utils/logger.ts","../../src/api/base.ts","../../src/api/businessProfile.ts"],"sourcesContent":["export const objectToQueryString = (params: Record<string, any>): string => {\n if (!params || Object.keys(params).length === 0) {\n return '';\n }\n\n const searchParams = new URLSearchParams();\n\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined) {\n searchParams.append(key, String(value));\n }\n }\n\n const queryString = searchParams.toString();\n return queryString ? `?${queryString}` : '';\n};\n","// @ts-nocheck\nimport type { LoggerInterface } from '../types/logger';\n\nexport default class Logger implements LoggerInterface {\n private name: string;\n private debug: boolean;\n\n constructor(name: string, debug: boolean = false) {\n this.name = name;\n this.debug = debug;\n }\n\n log(...data: any[]) {\n if (this.debug) {\n let prefix = `[ ${Date.now()} ]`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.log.apply(console, [prefix, ': ', ...data]);\n }\n }\n\n error(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - ERROR`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.error.apply(console, [prefix, ': ', ...data]);\n }\n\n warn(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - WARN`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.warn.apply(console, [prefix, ': ', ...data]);\n }\n\n info(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - INFO`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.info.apply(console, [prefix, ': ', ...data]);\n }\n}\n","import Logger from '../utils/logger';\nimport type { BaseClass } from '../types/base';\nimport type { WabaConfigType } from '../types/config';\nimport type { RequesterClass } from '../types/request';\n\nconst LIB_NAME = 'BaseAPI';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\n\nexport default class BaseAPI implements BaseClass {\n protected config: WabaConfigType;\n protected client: RequesterClass;\n\n constructor(config: WabaConfigType, client: RequesterClass) {\n this.config = config;\n this.client = client;\n LOGGER.log('Initialized with HTTPSClient');\n }\n}\n","import {\n BusinessProfileClass,\n BusinessProfileResponse,\n UpdateBusinessProfileRequest,\n UploadHandle,\n UploadSessionResponse,\n} from '../types/businessProfile';\nimport type { WabaConfigType } from '../types/config';\nimport { HttpMethodsEnum, WabaConfigEnum } from '../types/enums';\nimport type { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request';\nimport { objectToQueryString } from '../utils/objectToQueryString';\nimport BaseAPI from './base';\n\n/**\n * API for managing WhatsApp Business Profiles and profile pictures.\n *\n * This API allows you to:\n * - Get business profile information\n * - Update business profile details\n * - Upload profile pictures using a three-step process:\n * 1. Create an upload session\n * 2. Upload the image binary data\n * 3. Get the upload handle to use when updating the profile\n */\nexport default class BusinessProfileAPI extends BaseAPI implements BusinessProfileClass {\n private readonly endpoint = 'whatsapp_business_profile';\n\n constructor(config: WabaConfigType, client: RequesterClass) {\n super(config, client);\n }\n\n /**\n * Get your business profile information.\n *\n * Use this method to retrieve details about your WhatsApp business profile, including\n * about text, address, description, email, profile picture URL, websites, and vertical.\n *\n * @param fields Fields to be returned in the response. If not specified, all fields will be returned.\n * Possible values: about, address, description, email, profile_picture_url, websites, vertical\n * @returns The business profile information.\n *\n * @example\n * // Get all business profile fields\n * const profile = await whatsappClient.businessProfile.getBusinessProfile();\n *\n * // Get specific business profile fields\n * const profile = await whatsappClient.businessProfile.getBusinessProfile('about,address,email');\n */\n async getBusinessProfile(fields?: string): Promise<RequesterResponseInterface<BusinessProfileResponse>> {\n const queryParams = fields ? objectToQueryString({ fields }) : '';\n return this.client.sendRequest(\n HttpMethodsEnum.Get,\n `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}${queryParams}`,\n this.config[WabaConfigEnum.RequestTimeout],\n null,\n );\n }\n\n /**\n * Update your business profile.\n *\n * Use this method to update one or more fields of your WhatsApp business profile.\n *\n * @param updateRequest The request object containing the fields to update.\n * - messaging_product: Required. Always set to \"whatsapp\".\n * - about: Optional. Business's About text (1-139 characters).\n * - address: Optional. Business address (max 256 characters).\n * - description: Optional. Business description (max 512 characters).\n * - vertical: Optional. Business category (use BusinessVerticalEnum for type safety).\n * - email: Optional. Contact email (valid format, max 128 characters).\n * - websites: Optional. Up to 2 URLs (max 256 characters each).\n * - profile_picture_handle: Optional. Handle from upload process.\n * @returns Response indicating success or failure.\n *\n * @example\n * // Update business profile with multiple fields including vertical using enum\n * await whatsappClient.businessProfile.updateBusinessProfile({\n * messaging_product: 'whatsapp',\n * about: 'We provide excellent service',\n * email: 'contact@example.com',\n * websites: ['https://example.com'],\n * vertical: BusinessVerticalEnum.RETAIL\n * });\n */\n async updateBusinessProfile(\n updateRequest: UpdateBusinessProfileRequest,\n ): Promise<RequesterResponseInterface<ResponseSuccess>> {\n return this.client.sendRequest(\n HttpMethodsEnum.Post,\n `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}`,\n this.config[WabaConfigEnum.RequestTimeout],\n JSON.stringify(updateRequest),\n );\n }\n\n /**\n * Create an upload session for a profile picture.\n *\n * This is the first step in the profile picture upload process.\n *\n * @param fileLength Length of the file to be uploaded in bytes.\n * @param fileType MIME type of the file (e.g., 'image/jpeg').\n * @param fileName Name of the file with extension.\n * @returns Response containing the upload session ID needed for the next step.\n *\n * @example\n * // Create upload session for profile picture\n * const session = await whatsappClient.businessProfile.createUploadSession(\n * fileBuffer.length,\n * 'image/jpeg',\n * 'profile.jpg'\n * );\n * const uploadSessionId = session.upload_session_id;\n */\n async createUploadSession(\n fileLength: number,\n fileType: string,\n fileName: string,\n ): Promise<RequesterResponseInterface<UploadSessionResponse>> {\n const queryParams = objectToQueryString({\n file_length: fileLength,\n file_type: fileType,\n file_name: fileName,\n });\n\n return this.client.sendRequest(\n HttpMethodsEnum.Post,\n `app/uploads/${queryParams}`,\n this.config[WabaConfigEnum.RequestTimeout],\n null,\n );\n }\n\n /**\n * Upload media file to the upload session.\n *\n * This is the second step in the profile picture upload process.\n * Upload the binary content of the file to the previously created upload session.\n *\n * @param uploadId The upload session ID from createUploadSession response.\n * @param file The binary data of the file (Buffer).\n * @returns Response indicating success or failure.\n *\n * @example\n * // Upload the actual file content\n * await whatsappClient.businessProfile.uploadMedia(\n * uploadSessionId,\n * fileBuffer\n * );\n */\n async uploadMedia(uploadId: string, file: Buffer): Promise<RequesterResponseInterface<ResponseSuccess>> {\n return this.client.sendRequest(\n HttpMethodsEnum.Post,\n `${uploadId}`,\n this.config[WabaConfigEnum.RequestTimeout],\n file,\n );\n }\n\n /**\n * Get the upload handle information.\n *\n * This is the third step in the profile picture upload process.\n * After uploading the file, get the handle to use when updating the profile.\n *\n * @param uploadId The upload session ID from createUploadSession response.\n * @returns Response containing the upload handle information.\n *\n * @example\n * // Complete profile picture update process\n * // 1. Create upload session\n * const session = await whatsappClient.businessProfile.createUploadSession(\n * fileBuffer.length, 'image/jpeg', 'profile.jpg'\n * );\n *\n * // 2. Upload the image data\n * await whatsappClient.businessProfile.uploadMedia(\n * session.upload_session_id, fileBuffer\n * );\n *\n * // 3. Get the handle for the uploaded file\n * const handleInfo = await whatsappClient.businessProfile.getUploadHandle(\n * session.upload_session_id\n * );\n *\n * // 4. Update profile with new picture and business information\n * await whatsappClient.businessProfile.updateBusinessProfile({\n * messaging_product: 'whatsapp',\n * profile_picture_handle: handleInfo.handle,\n * vertical: BusinessVerticalEnum.RESTAURANT,\n * about: 'Delicious food served daily'\n * });\n */\n async getUploadHandle(uploadId: string): Promise<RequesterResponseInterface<UploadHandle>> {\n return this.client.sendRequest(\n HttpMethodsEnum.Get,\n `${uploadId}`,\n this.config[WabaConfigEnum.RequestTimeout],\n null,\n );\n }\n}\n"],"mappings":"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","names":["objectToQueryString","params","searchParams","key","value","queryString","Logger","name","debug","data","prefix","LIB_NAME","LOG_LOCAL","LOGGER","Logger","BaseAPI","config","client","BusinessProfileAPI","BaseAPI","config","client","fields","queryParams","objectToQueryString","updateRequest","fileLength","fileType","fileName","uploadId","file"]}
@@ -2,7 +2,7 @@ import { WabaConfigType } from '../types/config.mjs';
2
2
  import { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request.mjs';
3
3
  import BaseAPI from './base.mjs';
4
4
  import { EncryptionClass, EncryptionPublicKeyResponse } from '../types/encryption.mjs';
5
- import '../enums-D6WRUWH9.mjs';
5
+ import '../enums-Dn5Y1Nom.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 { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request.js';
3
3
  import BaseAPI from './base.js';
4
4
  import { EncryptionClass, EncryptionPublicKeyResponse } from '../types/encryption.js';
5
- import '../enums-D6WRUWH9.js';
5
+ import '../enums-Dn5Y1Nom.js';
6
6
  import '../types/base.js';
7
7
 
8
8
  declare class EncryptionAPI extends BaseAPI implements EncryptionClass {
@@ -1,2 +1,2 @@
1
- "use strict";var B=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var K=(i,t)=>{for(var R in t)B(i,R,{get:t[R],enumerable:!0})},p=(i,t,R,N)=>{if(t&&typeof t=="object"||typeof t=="function")for(let D of G(t))!l.call(i,D)&&D!==R&&B(i,D,{get:()=>t[D],enumerable:!(N=U(t,D))||N.enumerable});return i};var I=i=>p(B({},"__esModule",{value:!0}),i);var F={};K(F,{default:()=>P});module.exports=I(F);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 O="BaseAPI",M=!1,_=new S(O,process.env.DEBUG==="true"||M),A=class{config;client;constructor(t,R){this.config=t,this.client=R,_.log("Initialized with HTTPSClient")}};var P=class extends A{endpoint="whatsapp_business_encryption";constructor(t,R){super(t,R)}async getEncryptionPublicKey(){return this.client.sendRequest("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,null)}async setEncryptionPublicKey(t){let R=new FormData;return R.append("business_public_key",t),this.client.sendRequest("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,R)}};
1
+ "use strict";var i=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var I=(A,R)=>{for(var t in R)i(A,t,{get:R[t],enumerable:!0})},K=(A,R,t,G)=>{if(R&&typeof R=="object"||typeof R=="function")for(let S of B(R))!O.call(A,S)&&S!==t&&i(A,S,{get:()=>R[S],enumerable:!(G=U(R,S))||G.enumerable});return A};var p=A=>K(i({},"__esModule",{value:!0}),A);var _={};I(_,{default:()=>N});module.exports=p(_);var D=class{name;debug;constructor(R,t=!1){this.name=R,this.debug=t}log(...R){if(this.debug){let t=`[ ${Date.now()} ]`;this.name&&(t+=` - ${this.name}`),console.log.apply(console,[t,": ",...R])}}error(...R){let t=`[ ${Date.now()} ] - ERROR`;this.name&&(t+=` - ${this.name}`),console.error.apply(console,[t,": ",...R])}warn(...R){let t=`[ ${Date.now()} ] - WARN`;this.name&&(t+=` - ${this.name}`),console.warn.apply(console,[t,": ",...R])}info(...R){let t=`[ ${Date.now()} ] - INFO`;this.name&&(t+=` - ${this.name}`),console.info.apply(console,[t,": ",...R])}};var T="BaseAPI",M=!1,l=new D(T,process.env.DEBUG==="true"||M),P=class{config;client;constructor(R,t){this.config=R,this.client=t,l.log("Initialized with HTTPSClient")}};var N=class extends P{endpoint="whatsapp_business_encryption";constructor(R,t){super(R,t)}async getEncryptionPublicKey(){return this.client.sendRequest("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,null)}async setEncryptionPublicKey(R){let t=new FormData;return t.append("business_public_key",R),this.client.sendRequest("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,t)}};
2
2
  //# sourceMappingURL=encryption.js.map
@@ -1,2 +1,2 @@
1
- var i=class{name;debug;constructor(R,t=!1){this.name=R,this.debug=t}log(...R){if(this.debug){let t=`[ ${Date.now()} ]`;this.name&&(t+=` - ${this.name}`),console.log.apply(console,[t,": ",...R])}}error(...R){let t=`[ ${Date.now()} ] - ERROR`;this.name&&(t+=` - ${this.name}`),console.error.apply(console,[t,": ",...R])}warn(...R){let t=`[ ${Date.now()} ] - WARN`;this.name&&(t+=` - ${this.name}`),console.warn.apply(console,[t,": ",...R])}info(...R){let t=`[ ${Date.now()} ] - INFO`;this.name&&(t+=` - ${this.name}`),console.info.apply(console,[t,": ",...R])}};var P="BaseAPI",B=!1,N=new i(P,process.env.DEBUG==="true"||B),D=class{config;client;constructor(R,t){this.config=R,this.client=t,N.log("Initialized with HTTPSClient")}};var S=class extends D{endpoint="whatsapp_business_encryption";constructor(R,t){super(R,t)}async getEncryptionPublicKey(){return this.client.sendRequest("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,null)}async setEncryptionPublicKey(R){let t=new FormData;return t.append("business_public_key",R),this.client.sendRequest("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,t)}};export{S as default};
1
+ var A=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 N="BaseAPI",i=!1,G=new A(N,process.env.DEBUG==="true"||i),S=class{config;client;constructor(t,R){this.config=t,this.client=R,G.log("Initialized with HTTPSClient")}};var D=class extends S{endpoint="whatsapp_business_encryption";constructor(t,R){super(t,R)}async getEncryptionPublicKey(){return this.client.sendRequest("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,null)}async setEncryptionPublicKey(t){let R=new FormData;return R.append("business_public_key",t),this.client.sendRequest("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,R)}};export{D as default};
2
2
  //# sourceMappingURL=encryption.mjs.map