@gymspace/evolution 1.0.0 → 1.0.2

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 (100) hide show
  1. package/dist/index.d.mts +26 -19
  2. package/dist/index.d.ts +26 -19
  3. package/dist/index.js +173 -62
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +173 -62
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +1 -3
  8. package/src/api/errors.ts +0 -220
  9. package/src/api/routes.ts +0 -76
  10. package/src/api/service.ts +0 -141
  11. package/src/index.ts +0 -89
  12. package/src/modules/chats/index.ts +0 -253
  13. package/src/modules/chats/schemas/archive.ts +0 -15
  14. package/src/modules/chats/schemas/check.ts +0 -20
  15. package/src/modules/chats/schemas/delete-message.ts +0 -16
  16. package/src/modules/chats/schemas/fetch-profile-picture.ts +0 -13
  17. package/src/modules/chats/schemas/find-all.ts +0 -49
  18. package/src/modules/chats/schemas/find-contacts.ts +0 -17
  19. package/src/modules/chats/schemas/find-messages.ts +0 -55
  20. package/src/modules/chats/schemas/find-status-message.ts +0 -11
  21. package/src/modules/chats/schemas/get-base64-from-media-message.ts +0 -20
  22. package/src/modules/chats/schemas/index.ts +0 -33
  23. package/src/modules/chats/schemas/mark-as-read.ts +0 -20
  24. package/src/modules/chats/schemas/mark-as-unread.ts +0 -17
  25. package/src/modules/chats/schemas/presence.ts +0 -41
  26. package/src/modules/chats/schemas/update-message.ts +0 -16
  27. package/src/modules/groups/index.ts +0 -246
  28. package/src/modules/groups/schemas/accept-invite-code.ts +0 -14
  29. package/src/modules/groups/schemas/common.ts +0 -89
  30. package/src/modules/groups/schemas/create.ts +0 -15
  31. package/src/modules/groups/schemas/fetch-invite-code.ts +0 -13
  32. package/src/modules/groups/schemas/find-all.ts +0 -26
  33. package/src/modules/groups/schemas/find-by-invite-code.ts +0 -39
  34. package/src/modules/groups/schemas/find-by-jid.ts +0 -14
  35. package/src/modules/groups/schemas/find-members.ts +0 -16
  36. package/src/modules/groups/schemas/index.ts +0 -24
  37. package/src/modules/groups/schemas/leave.ts +0 -14
  38. package/src/modules/groups/schemas/revoke-invite-code.ts +0 -14
  39. package/src/modules/groups/schemas/send-group-invite.ts +0 -15
  40. package/src/modules/groups/schemas/toggle-ephemeral.ts +0 -15
  41. package/src/modules/groups/schemas/update-description.ts +0 -15
  42. package/src/modules/groups/schemas/update-members.ts +0 -18
  43. package/src/modules/groups/schemas/update-picture.ts +0 -15
  44. package/src/modules/groups/schemas/update-setting.ts +0 -16
  45. package/src/modules/groups/schemas/update-subject.ts +0 -15
  46. package/src/modules/index.ts +0 -7
  47. package/src/modules/instance/index.ts +0 -126
  48. package/src/modules/instance/schemas/connect.ts +0 -14
  49. package/src/modules/instance/schemas/connection-state.ts +0 -16
  50. package/src/modules/instance/schemas/create.ts +0 -99
  51. package/src/modules/instance/schemas/delete.ts +0 -21
  52. package/src/modules/instance/schemas/fetch-all.ts +0 -57
  53. package/src/modules/instance/schemas/index.ts +0 -8
  54. package/src/modules/instance/schemas/logout.ts +0 -22
  55. package/src/modules/instance/schemas/restart.ts +0 -13
  56. package/src/modules/instance/schemas/set-presence.ts +0 -20
  57. package/src/modules/messages/index.ts +0 -246
  58. package/src/modules/messages/schemas/audio.ts +0 -12
  59. package/src/modules/messages/schemas/base.ts +0 -11
  60. package/src/modules/messages/schemas/contact.ts +0 -70
  61. package/src/modules/messages/schemas/document.ts +0 -12
  62. package/src/modules/messages/schemas/image.ts +0 -12
  63. package/src/modules/messages/schemas/index.ts +0 -31
  64. package/src/modules/messages/schemas/list.ts +0 -36
  65. package/src/modules/messages/schemas/location.ts +0 -76
  66. package/src/modules/messages/schemas/media.ts +0 -51
  67. package/src/modules/messages/schemas/poll.ts +0 -87
  68. package/src/modules/messages/schemas/reaction.ts +0 -21
  69. package/src/modules/messages/schemas/status.ts +0 -18
  70. package/src/modules/messages/schemas/sticker.ts +0 -77
  71. package/src/modules/messages/schemas/template.ts +0 -39
  72. package/src/modules/messages/schemas/text.ts +0 -88
  73. package/src/modules/messages/schemas/video.ts +0 -12
  74. package/src/modules/messages/schemas/voice.ts +0 -94
  75. package/src/modules/profile/index.ts +0 -110
  76. package/src/modules/profile/schemas/fetch-business-profile.ts +0 -29
  77. package/src/modules/profile/schemas/fetch-privacy-settings.ts +0 -11
  78. package/src/modules/profile/schemas/fetch-profile.ts +0 -23
  79. package/src/modules/profile/schemas/index.ts +0 -8
  80. package/src/modules/profile/schemas/remove-picture.ts +0 -4
  81. package/src/modules/profile/schemas/update-name.ts +0 -11
  82. package/src/modules/profile/schemas/update-picture.ts +0 -11
  83. package/src/modules/profile/schemas/update-privacy-settings.ts +0 -18
  84. package/src/modules/profile/schemas/update-status.ts +0 -11
  85. package/src/modules/settings/index.ts +0 -28
  86. package/src/modules/settings/schemas/find.ts +0 -11
  87. package/src/modules/settings/schemas/index.ts +0 -2
  88. package/src/modules/settings/schemas/set.ts +0 -18
  89. package/src/modules/webhook/index.ts +0 -28
  90. package/src/modules/webhook/schemas/find.ts +0 -7
  91. package/src/modules/webhook/schemas/index.ts +0 -2
  92. package/src/modules/webhook/schemas/set.ts +0 -16
  93. package/src/schemas/client.ts +0 -23
  94. package/src/schemas/common.ts +0 -44
  95. package/src/types/api.ts +0 -17
  96. package/src/types/events.ts +0 -53
  97. package/src/types/messages.ts +0 -5
  98. package/src/types/tags.ts +0 -14
  99. package/src/types/webhooks.ts +0 -255
  100. package/src/utils/phone-numer-from-jid.ts +0 -9
package/dist/index.d.mts CHANGED
@@ -1,5 +1,3 @@
1
- import * as libphonenumber_js from 'libphonenumber-js';
2
-
3
1
  declare enum MessageUpdateStatus {
4
2
  DELIVERY_ACK = "DELIVERY_ACK",
5
3
  READ = "READ",
@@ -254,6 +252,11 @@ interface ClientOptions {
254
252
  * Custom headers to include in requests
255
253
  */
256
254
  headers?: Record<string, string>;
255
+ /**
256
+ * Enable debug logs (curl commands and API responses)
257
+ * @default false
258
+ */
259
+ debug?: boolean;
257
260
  }
258
261
 
259
262
  interface APIRequestInit {
@@ -277,11 +280,12 @@ declare class ApiService {
277
280
  setInstance(instance: string): void;
278
281
  request<T = unknown>(path: string, options?: APIRequestInit): Promise<T>;
279
282
  private makeInit;
280
- get<T = unknown>(path: string, options?: Omit<APIRequestInit, "method">): Promise<T>;
281
- post<T = unknown>(path: string, options?: Omit<APIRequestInit, "method">): Promise<T>;
282
- put<T = unknown>(path: string, options?: Omit<APIRequestInit, "method">): Promise<T>;
283
- patch<T = unknown>(path: string, options?: Omit<APIRequestInit, "method">): Promise<T>;
284
- delete<T = unknown>(path: string, options?: Omit<APIRequestInit, "method">): Promise<T>;
283
+ private generateCurlCommand;
284
+ get<T = unknown>(path: string, options?: Omit<APIRequestInit, 'method'>): Promise<T>;
285
+ post<T = unknown>(path: string, options?: Omit<APIRequestInit, 'method'>): Promise<T>;
286
+ put<T = unknown>(path: string, options?: Omit<APIRequestInit, 'method'>): Promise<T>;
287
+ patch<T = unknown>(path: string, options?: Omit<APIRequestInit, 'method'>): Promise<T>;
288
+ delete<T = unknown>(path: string, options?: Omit<APIRequestInit, 'method'>): Promise<T>;
285
289
  }
286
290
 
287
291
  type Jid = `${string}@s.whatsapp.net` | string;
@@ -836,19 +840,19 @@ interface CreateInstanceRequest {
836
840
  qrcode?: boolean;
837
841
  number?: string;
838
842
  integration?: string;
839
- rejectCall?: boolean;
843
+ reject_call?: boolean;
840
844
  msgCall?: string;
841
- groupsIgnore?: boolean;
842
- alwaysOnline?: boolean;
843
- readMessages?: boolean;
844
- readStatus?: boolean;
845
+ groups_ignore?: boolean;
846
+ always_online?: boolean;
847
+ read_messages?: boolean;
848
+ read_status?: boolean;
845
849
  syncFullHistory?: boolean;
846
850
  proxyHost?: string;
847
851
  proxyPort?: string;
848
852
  proxyProtocol?: "http" | "https";
849
853
  proxyUsername?: string;
850
854
  proxyPassword?: string;
851
- webhook?: WebhookConfig;
855
+ webhook?: string | WebhookConfig;
852
856
  rabbitmq?: RabbitMQConfig;
853
857
  sqs?: SQSConfig;
854
858
  chatwootAccountId?: number;
@@ -1678,11 +1682,13 @@ declare enum WebhookEventSetup {
1678
1682
  }
1679
1683
 
1680
1684
  interface SetRequest {
1681
- enabled: boolean;
1682
- url: string;
1683
- webhookByEvents: boolean;
1684
- webhookBase64: boolean;
1685
- events: WebhookEventSetup[];
1685
+ webhook: {
1686
+ enabled: boolean;
1687
+ url: string;
1688
+ events: WebhookEventSetup[];
1689
+ base64: boolean;
1690
+ byEvents: boolean;
1691
+ };
1686
1692
  }
1687
1693
  interface SetResponse {
1688
1694
  message: string;
@@ -1713,8 +1719,9 @@ declare class EvolutionApiError extends Error {
1713
1719
  /**
1714
1720
  * Get phone number from JID
1715
1721
  * @param jid - JID (remote JID)
1722
+ * @returns Phone number with + prefix or the raw number from JID
1716
1723
  */
1717
- declare function phoneNumberFromJid(jid: string): libphonenumber_js.E164Number;
1724
+ declare function phoneNumberFromJid(jid: string): string;
1718
1725
 
1719
1726
  interface PollMessageOptions extends BaseMessageOptions {
1720
1727
  /**
package/dist/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import * as libphonenumber_js from 'libphonenumber-js';
2
-
3
1
  declare enum MessageUpdateStatus {
4
2
  DELIVERY_ACK = "DELIVERY_ACK",
5
3
  READ = "READ",
@@ -254,6 +252,11 @@ interface ClientOptions {
254
252
  * Custom headers to include in requests
255
253
  */
256
254
  headers?: Record<string, string>;
255
+ /**
256
+ * Enable debug logs (curl commands and API responses)
257
+ * @default false
258
+ */
259
+ debug?: boolean;
257
260
  }
258
261
 
259
262
  interface APIRequestInit {
@@ -277,11 +280,12 @@ declare class ApiService {
277
280
  setInstance(instance: string): void;
278
281
  request<T = unknown>(path: string, options?: APIRequestInit): Promise<T>;
279
282
  private makeInit;
280
- get<T = unknown>(path: string, options?: Omit<APIRequestInit, "method">): Promise<T>;
281
- post<T = unknown>(path: string, options?: Omit<APIRequestInit, "method">): Promise<T>;
282
- put<T = unknown>(path: string, options?: Omit<APIRequestInit, "method">): Promise<T>;
283
- patch<T = unknown>(path: string, options?: Omit<APIRequestInit, "method">): Promise<T>;
284
- delete<T = unknown>(path: string, options?: Omit<APIRequestInit, "method">): Promise<T>;
283
+ private generateCurlCommand;
284
+ get<T = unknown>(path: string, options?: Omit<APIRequestInit, 'method'>): Promise<T>;
285
+ post<T = unknown>(path: string, options?: Omit<APIRequestInit, 'method'>): Promise<T>;
286
+ put<T = unknown>(path: string, options?: Omit<APIRequestInit, 'method'>): Promise<T>;
287
+ patch<T = unknown>(path: string, options?: Omit<APIRequestInit, 'method'>): Promise<T>;
288
+ delete<T = unknown>(path: string, options?: Omit<APIRequestInit, 'method'>): Promise<T>;
285
289
  }
286
290
 
287
291
  type Jid = `${string}@s.whatsapp.net` | string;
@@ -836,19 +840,19 @@ interface CreateInstanceRequest {
836
840
  qrcode?: boolean;
837
841
  number?: string;
838
842
  integration?: string;
839
- rejectCall?: boolean;
843
+ reject_call?: boolean;
840
844
  msgCall?: string;
841
- groupsIgnore?: boolean;
842
- alwaysOnline?: boolean;
843
- readMessages?: boolean;
844
- readStatus?: boolean;
845
+ groups_ignore?: boolean;
846
+ always_online?: boolean;
847
+ read_messages?: boolean;
848
+ read_status?: boolean;
845
849
  syncFullHistory?: boolean;
846
850
  proxyHost?: string;
847
851
  proxyPort?: string;
848
852
  proxyProtocol?: "http" | "https";
849
853
  proxyUsername?: string;
850
854
  proxyPassword?: string;
851
- webhook?: WebhookConfig;
855
+ webhook?: string | WebhookConfig;
852
856
  rabbitmq?: RabbitMQConfig;
853
857
  sqs?: SQSConfig;
854
858
  chatwootAccountId?: number;
@@ -1678,11 +1682,13 @@ declare enum WebhookEventSetup {
1678
1682
  }
1679
1683
 
1680
1684
  interface SetRequest {
1681
- enabled: boolean;
1682
- url: string;
1683
- webhookByEvents: boolean;
1684
- webhookBase64: boolean;
1685
- events: WebhookEventSetup[];
1685
+ webhook: {
1686
+ enabled: boolean;
1687
+ url: string;
1688
+ events: WebhookEventSetup[];
1689
+ base64: boolean;
1690
+ byEvents: boolean;
1691
+ };
1686
1692
  }
1687
1693
  interface SetResponse {
1688
1694
  message: string;
@@ -1713,8 +1719,9 @@ declare class EvolutionApiError extends Error {
1713
1719
  /**
1714
1720
  * Get phone number from JID
1715
1721
  * @param jid - JID (remote JID)
1722
+ * @returns Phone number with + prefix or the raw number from JID
1716
1723
  */
1717
- declare function phoneNumberFromJid(jid: string): libphonenumber_js.E164Number;
1724
+ declare function phoneNumberFromJid(jid: string): string;
1718
1725
 
1719
1726
  interface PollMessageOptions extends BaseMessageOptions {
1720
1727
  /**
package/dist/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var libphonenumberJs = require('libphonenumber-js');
4
-
5
3
  // src/types/webhooks.ts
6
4
  var ConnectionState = /* @__PURE__ */ ((ConnectionState2) => {
7
5
  ConnectionState2["OPEN"] = "open";
@@ -66,7 +64,7 @@ var EvolutionApiError = class _EvolutionApiError extends Error {
66
64
  relevantDetails.push(`Server Message: ${response.message}`);
67
65
  }
68
66
  }
69
- if (relevantDetails.length > 0) {
67
+ if (relevantDetails?.length > 0) {
70
68
  result += `
71
69
  ${relevantDetails.join("\n ")}`;
72
70
  }
@@ -94,54 +92,59 @@ function extractErrorMessage(response) {
94
92
  return response;
95
93
  }
96
94
  if (typeof response === "object" && response !== null) {
97
- const errorObj = response;
98
- const messagePaths = [
99
- // Evolution API specific nested structure (most common)
100
- errorObj.response?.response?.message?.[0],
101
- errorObj.response?.response?.error,
102
- errorObj.response?.response?.description,
103
- // Evolution API first level nested
104
- Array.isArray(errorObj.response?.message) ? errorObj.response.message[0] : null,
105
- errorObj.response?.error,
106
- errorObj.response?.description,
107
- // Direct error message
108
- Array.isArray(errorObj.message) ? errorObj.message[0] : errorObj.message,
109
- errorObj.error,
110
- errorObj.description,
111
- errorObj.detail,
112
- // Other nested error messages
113
- errorObj.data?.error,
114
- errorObj.data?.message,
115
- // Array format messages (fallback)
116
- Array.isArray(errorObj.error) ? errorObj.error[0] : null,
117
- Array.isArray(errorObj.errors) ? errorObj.errors[0] : null
118
- ];
119
- for (const path of messagePaths) {
120
- if (typeof path === "string" && path.trim()) {
121
- return path.trim();
95
+ try {
96
+ const errorObj = response;
97
+ const messagePaths = [
98
+ // Evolution API specific nested structure (most common)
99
+ errorObj.response?.response?.message?.[0],
100
+ errorObj.response?.response?.error,
101
+ errorObj.response?.response?.description,
102
+ // Evolution API first level nested
103
+ Array.isArray(errorObj.response?.message) ? errorObj.response.message[0] : null,
104
+ errorObj.response?.error,
105
+ errorObj.response?.description,
106
+ // Direct error message
107
+ Array.isArray(errorObj.message) ? errorObj.message[0] : errorObj.message,
108
+ errorObj.error,
109
+ errorObj.description,
110
+ errorObj.detail,
111
+ // Other nested error messages
112
+ errorObj.data?.error,
113
+ errorObj.data?.message,
114
+ // Array format messages (fallback)
115
+ Array.isArray(errorObj.error) ? errorObj.error[0] : null,
116
+ Array.isArray(errorObj.errors) ? errorObj.errors[0] : null
117
+ ].filter(Boolean);
118
+ for (const path of messagePaths) {
119
+ if (path && typeof path === "string" && path.length > 0 && path.trim()) {
120
+ return path.trim();
121
+ }
122
+ if (path && typeof path === "object" && path !== null) {
123
+ const nestedMessage = extractErrorMessage(path);
124
+ if (nestedMessage) {
125
+ return nestedMessage;
126
+ }
127
+ }
122
128
  }
123
- if (typeof path === "object" && path !== null) {
124
- const nestedMessage = extractErrorMessage(path);
125
- if (nestedMessage) {
126
- return nestedMessage;
129
+ if (errorObj.validation && Array.isArray(errorObj.validation)) {
130
+ const validationErrors = errorObj.validation.map((v) => v?.message || v?.error || String(v)).filter(Boolean).join(", ");
131
+ if (validationErrors) {
132
+ return `Validation error: ${validationErrors}`;
127
133
  }
128
134
  }
129
- }
130
- if (errorObj.validation && Array.isArray(errorObj.validation)) {
131
- const validationErrors = errorObj.validation.map((v) => v.message || v.error || String(v)).filter(Boolean).join(", ");
132
- if (validationErrors) {
133
- return `Validation error: ${validationErrors}`;
135
+ if (errorObj.statusCode && errorObj.statusText) {
136
+ return `${errorObj.statusCode}: ${errorObj.statusText}`;
134
137
  }
135
- }
136
- if (errorObj.statusCode && errorObj.statusText) {
137
- return `${errorObj.statusCode}: ${errorObj.statusText}`;
138
- }
139
- if (Object.keys(errorObj).length > 0) {
140
- try {
141
- return JSON.stringify(errorObj);
142
- } catch {
143
- return "[Complex error object]";
138
+ const keys = Object.keys(errorObj);
139
+ if (keys && keys.length > 0) {
140
+ try {
141
+ return JSON.stringify(errorObj);
142
+ } catch {
143
+ return "[Complex error object]";
144
+ }
144
145
  }
146
+ } catch (error) {
147
+ return "[Error parsing error message]";
145
148
  }
146
149
  }
147
150
  return null;
@@ -156,6 +159,18 @@ var ApiService = class {
156
159
  this.options.instance = instance;
157
160
  }
158
161
  async request(path, options = {}) {
162
+ if (!path || typeof path !== "string" || path?.trim()?.length === 0) {
163
+ throw new EvolutionApiError("Invalid path parameter", {
164
+ message: "Path must be a non-empty string",
165
+ path
166
+ });
167
+ }
168
+ if (!this.options.serverUrl || typeof this.options.serverUrl !== "string") {
169
+ throw new EvolutionApiError("Invalid server URL configuration", {
170
+ message: "Server URL must be configured and be a valid string",
171
+ serverUrl: this.options.serverUrl
172
+ });
173
+ }
159
174
  const { isInstanceUrl = true } = options;
160
175
  let instance = this.options.instance;
161
176
  if (options.instance) {
@@ -164,7 +179,9 @@ var ApiService = class {
164
179
  }
165
180
  if (isInstanceUrl && !instance) {
166
181
  throw new EvolutionApiError("Instance not set", {
167
- message: "Please set the instance before making a request or pass instance in the method options."
182
+ message: "Please set the instance before making a request or pass instance in the method options.",
183
+ path,
184
+ isInstanceUrl
168
185
  });
169
186
  }
170
187
  const { init, params } = this.makeInit(options);
@@ -173,24 +190,65 @@ var ApiService = class {
173
190
  if (params.toString()) {
174
191
  url.search = params.toString();
175
192
  }
193
+ const curlCommand = this.generateCurlCommand(
194
+ init.method || "GET",
195
+ url.toString(),
196
+ init.headers,
197
+ init.body
198
+ );
199
+ if (this.options.debug) {
200
+ console.log("\n=== CURL COMMAND ===");
201
+ console.log(curlCommand);
202
+ console.log("===================\n");
203
+ }
176
204
  let response;
177
205
  let data;
206
+ let responseText = "";
178
207
  try {
179
208
  response = await fetch(url, init);
180
- data = await response.json();
209
+ responseText = await response.text();
210
+ data = responseText ? JSON.parse(responseText) : null;
181
211
  } catch (error) {
182
- throw new EvolutionApiError("Network or parsing error", error);
212
+ if (this.options.debug) {
213
+ console.log(error);
214
+ console.log("\n=== CURL COMMAND (ERROR) ===");
215
+ console.log(curlCommand);
216
+ console.log("============================\n");
217
+ }
218
+ if (error instanceof SyntaxError && error.message.includes("JSON")) {
219
+ throw new EvolutionApiError("Failed to parse response as JSON", {
220
+ originalError: error,
221
+ responseText: responseText || "Empty response",
222
+ url: url.toString(),
223
+ status: response?.status
224
+ });
225
+ }
226
+ throw new EvolutionApiError("Network or parsing error", {
227
+ originalError: error,
228
+ url: url.toString(),
229
+ responseText: responseText || "No response"
230
+ });
231
+ }
232
+ if (this.options.debug) {
233
+ console.log("\n=== API RESPONSE ===");
234
+ console.log(JSON.stringify(data, null, 2));
235
+ console.log("===================\n");
183
236
  }
184
237
  if (!response.ok) {
238
+ if (this.options.debug) {
239
+ console.log("\n=== CURL COMMAND (HTTP ERROR) ===");
240
+ console.log(curlCommand);
241
+ console.log("================================\n");
242
+ }
185
243
  const errorMessage = extractErrorMessage(data) || `Request failed with status ${response.status}: ${response.statusText}`;
186
244
  throw new EvolutionApiError(
187
245
  errorMessage,
188
246
  {
189
247
  message: errorMessage,
190
- response: JSON.stringify(data),
248
+ response: data || {},
191
249
  url: url.toString(),
192
250
  params: params.toString(),
193
- body: JSON.stringify(options.body)
251
+ body: options.body || {}
194
252
  },
195
253
  response.status
196
254
  );
@@ -221,6 +279,35 @@ var ApiService = class {
221
279
  }
222
280
  return { init, params };
223
281
  }
282
+ generateCurlCommand(method, url, headers, body) {
283
+ const curlParts = ["curl"];
284
+ if (method !== "GET") {
285
+ curlParts.push(`-X ${method}`);
286
+ }
287
+ let headerEntries;
288
+ if (headers instanceof Headers) {
289
+ const entries = [];
290
+ headers.forEach((value, key) => {
291
+ entries.push([key, value]);
292
+ });
293
+ headerEntries = entries;
294
+ } else {
295
+ headerEntries = Object.entries(headers);
296
+ }
297
+ headerEntries.forEach(([key, value]) => {
298
+ if (key.toLowerCase() !== "apikey") {
299
+ curlParts.push(`-H '${key}: ${value}'`);
300
+ } else {
301
+ curlParts.push(`-H '${key}: [REDACTED]'`);
302
+ }
303
+ });
304
+ if (body) {
305
+ const bodyStr = typeof body === "string" ? body : JSON.stringify(body);
306
+ curlParts.push(`-d '${bodyStr}'`);
307
+ }
308
+ curlParts.push(`'${url}'`);
309
+ return curlParts.join(" \\\n ");
310
+ }
224
311
  async get(path, options = {}) {
225
312
  return this.request(path, { ...options, method: "GET" });
226
313
  }
@@ -314,10 +401,43 @@ var Routes = {
314
401
  SetPresence: "instance/setPresence"
315
402
  }
316
403
  };
317
- var validatePhoneNumber = (value) => libphonenumberJs.isValidPhoneNumber(value);
404
+
405
+ // src/schemas/common.ts
406
+ var validatePhoneNumber = (value) => {
407
+ const phoneRegex = /^\+\d{7,15}$/;
408
+ return phoneRegex.test(value);
409
+ };
318
410
  var validateJid = (value) => value.endsWith("@s.whatsapp.net");
319
411
  var validateGroupJid = (value) => value.endsWith("@g.us");
320
412
 
413
+ // src/types/tags.ts
414
+ var Jid = (jid) => jid;
415
+ var GroupJid = (jid) => jid;
416
+ var MessageId = (id) => id;
417
+ var ChatId = (id) => id;
418
+
419
+ // src/utils/phone-numer-from-jid.ts
420
+ function phoneNumberFromJid(jid) {
421
+ const numberPart = jid.split("@")[0];
422
+ if (jid.endsWith("@s.whatsapp.net")) {
423
+ return `+${numberPart}`;
424
+ }
425
+ return numberPart;
426
+ }
427
+
428
+ // src/modules/chats/schemas/find-all.ts
429
+ var FindAllChatsResponseTransform = (chats) => chats.map((chat) => ({
430
+ id: ChatId(chat.id),
431
+ jid: chat.remoteJid.endsWith("@g.us") ? GroupJid(chat.remoteJid) : Jid(chat.remoteJid),
432
+ phoneNumber: phoneNumberFromJid(chat.remoteJid),
433
+ name: chat.name || void 0,
434
+ labels: chat.labels || void 0,
435
+ createdAt: new Date(chat.createdAt),
436
+ updatedAt: new Date(chat.updatedAt),
437
+ pushName: chat.pushName || void 0,
438
+ pictureUrl: chat.profilePicUrl || void 0
439
+ }));
440
+
321
441
  // src/modules/chats/index.ts
322
442
  var ChatsModule = class {
323
443
  constructor(api) {
@@ -347,7 +467,7 @@ var ChatsModule = class {
347
467
  body: {},
348
468
  ...methodOptions
349
469
  });
350
- return response;
470
+ return FindAllChatsResponseTransform(response);
351
471
  }
352
472
  /**
353
473
  * Updates presence status
@@ -977,9 +1097,6 @@ var WebhookModule = class {
977
1097
  return response;
978
1098
  }
979
1099
  };
980
- function phoneNumberFromJid(jid) {
981
- return libphonenumberJs.parsePhoneNumber(`+${jid.split("@")[0]}`).number;
982
- }
983
1100
 
984
1101
  // src/types/messages.ts
985
1102
  var MessageUpdateStatus = /* @__PURE__ */ ((MessageUpdateStatus2) => {
@@ -989,12 +1106,6 @@ var MessageUpdateStatus = /* @__PURE__ */ ((MessageUpdateStatus2) => {
989
1106
  return MessageUpdateStatus2;
990
1107
  })(MessageUpdateStatus || {});
991
1108
 
992
- // src/types/tags.ts
993
- var Jid = (jid) => jid;
994
- var GroupJid = (jid) => jid;
995
- var MessageId = (id) => id;
996
- var ChatId = (id) => id;
997
-
998
1109
  // src/types/events.ts
999
1110
  var WebhookEvent = /* @__PURE__ */ ((WebhookEvent2) => {
1000
1111
  WebhookEvent2["APPLICATION_STARTUP"] = "application.startup";