@zapyapi/sdk 1.0.0-beta.4 → 1.0.0-beta.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.
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import axios from 'axios';
2
2
 
3
3
  /** SDK version - auto-generated from package.json */
4
- const SDK_VERSION = '1.0.0-beta.4';
4
+ const SDK_VERSION = '1.0.0-beta.5';
5
5
 
6
6
  /**
7
7
  * Custom error classes for @zapyapi/sdk
@@ -10,11 +10,30 @@ const SDK_VERSION = '1.0.0-beta.4';
10
10
  * Base error class for all ZapyAPI errors
11
11
  */
12
12
  class ZapyError extends Error {
13
- constructor(message) {
14
- super(message);
13
+ /**
14
+ * Original error that caused this error (if any)
15
+ */
16
+ cause;
17
+ constructor(message, cause) {
18
+ super(message, {
19
+ cause
20
+ });
15
21
  this.name = 'ZapyError';
16
22
  Object.setPrototypeOf(this, ZapyError.prototype);
17
23
  }
24
+ /**
25
+ * Get a detailed string representation of the error
26
+ */
27
+ toDetailedString() {
28
+ let result = `${this.name}: ${this.message}`;
29
+ if (this.cause) {
30
+ result += `\nCaused by: ${this.cause.message}`;
31
+ if (this.cause.stack) {
32
+ result += `\n${this.cause.stack}`;
33
+ }
34
+ }
35
+ return result;
36
+ }
18
37
  }
19
38
  /**
20
39
  * Error thrown when the API returns an error response
@@ -36,13 +55,28 @@ class ZapyApiError extends ZapyError {
36
55
  * Additional error details
37
56
  */
38
57
  details;
39
- constructor(message, statusCode, code, requestId, details) {
40
- super(message);
58
+ /**
59
+ * HTTP method used in the request
60
+ */
61
+ method;
62
+ /**
63
+ * URL that was requested
64
+ */
65
+ url;
66
+ /**
67
+ * Raw response body (for debugging)
68
+ */
69
+ responseBody;
70
+ constructor(message, statusCode, code, options) {
71
+ super(message, options?.cause);
41
72
  this.name = 'ZapyApiError';
42
73
  this.statusCode = statusCode;
43
74
  this.code = code;
44
- this.requestId = requestId;
45
- this.details = details;
75
+ this.requestId = options?.requestId;
76
+ this.details = options?.details;
77
+ this.method = options?.method;
78
+ this.url = options?.url;
79
+ this.responseBody = options?.responseBody;
46
80
  Object.setPrototypeOf(this, ZapyApiError.prototype);
47
81
  }
48
82
  /**
@@ -52,10 +86,81 @@ class ZapyApiError extends ZapyError {
52
86
  const statusCode = error.response?.status ?? 500;
53
87
  const data = error.response?.data;
54
88
  const requestId = error.response?.headers?.['x-request-id'];
55
- if (data && typeof data === 'object' && 'code' in data) {
56
- return new ZapyApiError(data.message || error.message, statusCode, data.code, requestId || data.requestId, data.details);
89
+ const method = error.config?.method?.toUpperCase();
90
+ const url = error.config?.url;
91
+ // Build a descriptive message
92
+ let message;
93
+ if (data && typeof data === 'object' && 'message' in data && data.message) {
94
+ message = data.message;
95
+ } else if (error.message) {
96
+ message = error.message;
97
+ } else {
98
+ message = `Request failed with status ${statusCode}`;
99
+ }
100
+ // Add context to the message
101
+ const context = [];
102
+ if (method && url) {
103
+ context.push(`${method} ${url}`);
104
+ }
105
+ if (statusCode) {
106
+ context.push(`Status: ${statusCode}`);
57
107
  }
58
- return new ZapyApiError(error.message || 'An unexpected error occurred', statusCode, 'UNKNOWN_ERROR', requestId);
108
+ if (requestId) {
109
+ context.push(`Request ID: ${requestId}`);
110
+ }
111
+ const fullMessage = context.length > 0 ? `${message} [${context.join(' | ')}]` : message;
112
+ const code = data && typeof data === 'object' && 'code' in data && data.code ? data.code : 'UNKNOWN_ERROR';
113
+ const details = data && typeof data === 'object' && 'details' in data ? data.details : undefined;
114
+ return new ZapyApiError(fullMessage, statusCode, code, {
115
+ requestId: requestId || (data && typeof data === 'object' && 'requestId' in data ? data.requestId : undefined),
116
+ details,
117
+ method,
118
+ url,
119
+ responseBody: data,
120
+ cause: error
121
+ });
122
+ }
123
+ /**
124
+ * Get a detailed string representation for logging
125
+ */
126
+ toDetailedString() {
127
+ const lines = [`${this.name}: ${this.message}`, ` Status Code: ${this.statusCode}`, ` Error Code: ${this.code}`];
128
+ if (this.method && this.url) {
129
+ lines.push(` Request: ${this.method} ${this.url}`);
130
+ }
131
+ if (this.requestId) {
132
+ lines.push(` Request ID: ${this.requestId}`);
133
+ }
134
+ if (this.details && Object.keys(this.details).length > 0) {
135
+ lines.push(` Details: ${JSON.stringify(this.details, null, 2)}`);
136
+ }
137
+ if (this.responseBody && typeof this.responseBody === 'object') {
138
+ lines.push(` Response Body: ${JSON.stringify(this.responseBody, null, 2)}`);
139
+ }
140
+ if (this.cause) {
141
+ lines.push(` Caused by: ${this.cause.message}`);
142
+ if (this.cause.stack) {
143
+ lines.push(` Stack: ${this.cause.stack.split('\n').slice(1, 4).join('\n ')}`);
144
+ }
145
+ }
146
+ return lines.join('\n');
147
+ }
148
+ /**
149
+ * Convert to a plain object for logging/serialization
150
+ */
151
+ toJSON() {
152
+ return {
153
+ name: this.name,
154
+ message: this.message,
155
+ statusCode: this.statusCode,
156
+ code: this.code,
157
+ requestId: this.requestId,
158
+ method: this.method,
159
+ url: this.url,
160
+ details: this.details,
161
+ responseBody: this.responseBody,
162
+ cause: this.cause?.message
163
+ };
59
164
  }
60
165
  }
61
166
  /**
@@ -72,16 +177,32 @@ class ValidationError extends ZapyError {
72
177
  this.details = details;
73
178
  Object.setPrototypeOf(this, ValidationError.prototype);
74
179
  }
180
+ toDetailedString() {
181
+ const fieldErrors = Object.entries(this.details).map(([field, errors]) => ` ${field}: ${errors.join(', ')}`).join('\n');
182
+ return `${this.name}: ${this.message}\n${fieldErrors}`;
183
+ }
184
+ toJSON() {
185
+ return {
186
+ name: this.name,
187
+ message: this.message,
188
+ details: this.details
189
+ };
190
+ }
75
191
  }
76
192
  /**
77
193
  * Error thrown when an instance is not found
78
194
  */
79
195
  class InstanceNotFoundError extends ZapyApiError {
80
- constructor(instanceId, requestId) {
81
- super(`Instance '${instanceId}' not found`, 404, 'INSTANCE_NOT_FOUND', requestId, {
82
- instanceId
196
+ instanceId;
197
+ constructor(instanceId, options) {
198
+ super(`Instance '${instanceId}' not found`, 404, 'INSTANCE_NOT_FOUND', {
199
+ ...options,
200
+ details: {
201
+ instanceId
202
+ }
83
203
  });
84
204
  this.name = 'InstanceNotFoundError';
205
+ this.instanceId = instanceId;
85
206
  Object.setPrototypeOf(this, InstanceNotFoundError.prototype);
86
207
  }
87
208
  }
@@ -89,8 +210,8 @@ class InstanceNotFoundError extends ZapyApiError {
89
210
  * Error thrown when authentication fails
90
211
  */
91
212
  class AuthenticationError extends ZapyApiError {
92
- constructor(message = 'Invalid or missing API key', requestId) {
93
- super(message, 401, 'UNAUTHORIZED', requestId);
213
+ constructor(message = 'Invalid or missing API key', options) {
214
+ super(message, 401, 'UNAUTHORIZED', options);
94
215
  this.name = 'AuthenticationError';
95
216
  Object.setPrototypeOf(this, AuthenticationError.prototype);
96
217
  }
@@ -103,14 +224,89 @@ class RateLimitError extends ZapyApiError {
103
224
  * Timestamp when the rate limit resets (Unix ms)
104
225
  */
105
226
  retryAfter;
106
- constructor(message = 'Rate limit exceeded', retryAfter, requestId) {
107
- super(message, 429, 'RATE_LIMIT_EXCEEDED', requestId, {
108
- retryAfter
227
+ constructor(message = 'Rate limit exceeded', retryAfter, options) {
228
+ super(message, 429, 'RATE_LIMIT_EXCEEDED', {
229
+ ...options,
230
+ details: retryAfter ? {
231
+ retryAfter
232
+ } : undefined
109
233
  });
110
234
  this.name = 'RateLimitError';
111
235
  this.retryAfter = retryAfter;
112
236
  Object.setPrototypeOf(this, RateLimitError.prototype);
113
237
  }
238
+ /**
239
+ * Get the Date when the rate limit resets
240
+ */
241
+ getRetryAfterDate() {
242
+ return this.retryAfter ? new Date(this.retryAfter) : undefined;
243
+ }
244
+ }
245
+ /**
246
+ * Error thrown when a network error occurs (no response received)
247
+ */
248
+ class NetworkError extends ZapyError {
249
+ /**
250
+ * HTTP method used in the request
251
+ */
252
+ method;
253
+ /**
254
+ * URL that was requested
255
+ */
256
+ url;
257
+ /**
258
+ * Error code (e.g., ECONNREFUSED, ETIMEDOUT)
259
+ */
260
+ code;
261
+ constructor(message, options) {
262
+ super(message, options?.cause);
263
+ this.name = 'NetworkError';
264
+ this.method = options?.method;
265
+ this.url = options?.url;
266
+ this.code = options?.code;
267
+ Object.setPrototypeOf(this, NetworkError.prototype);
268
+ }
269
+ toDetailedString() {
270
+ const lines = [`${this.name}: ${this.message}`];
271
+ if (this.code) {
272
+ lines.push(` Error Code: ${this.code}`);
273
+ }
274
+ if (this.method && this.url) {
275
+ lines.push(` Request: ${this.method} ${this.url}`);
276
+ }
277
+ if (this.cause) {
278
+ lines.push(` Caused by: ${this.cause.message}`);
279
+ }
280
+ return lines.join('\n');
281
+ }
282
+ toJSON() {
283
+ return {
284
+ name: this.name,
285
+ message: this.message,
286
+ code: this.code,
287
+ method: this.method,
288
+ url: this.url,
289
+ cause: this.cause?.message
290
+ };
291
+ }
292
+ }
293
+ /**
294
+ * Error thrown when request times out
295
+ */
296
+ class TimeoutError extends NetworkError {
297
+ /**
298
+ * Timeout duration in milliseconds
299
+ */
300
+ timeout;
301
+ constructor(message = 'Request timed out', options) {
302
+ super(message, {
303
+ ...options,
304
+ code: 'ETIMEDOUT'
305
+ });
306
+ this.name = 'TimeoutError';
307
+ this.timeout = options?.timeout;
308
+ Object.setPrototypeOf(this, TimeoutError.prototype);
309
+ }
114
310
  }
115
311
 
116
312
  /**
@@ -126,18 +322,58 @@ class BaseResource {
126
322
  */
127
323
  handleError(error) {
128
324
  if (this.isAxiosError(error)) {
129
- const statusCode = error.response?.status;
130
- const retryAfter = error.response?.headers?.['retry-after'];
325
+ const method = error.config?.method?.toUpperCase();
326
+ const url = error.config?.url;
327
+ const requestId = error.response?.headers?.['x-request-id'];
328
+ // Network errors (no response received)
329
+ if (!error.response) {
330
+ const code = error.code;
331
+ // Timeout errors
332
+ if (code === 'ECONNABORTED' || code === 'ETIMEDOUT' || error.message?.includes('timeout')) {
333
+ const timeout = error.config?.timeout;
334
+ throw new TimeoutError(`Request timed out${timeout ? ` after ${timeout}ms` : ''}`, {
335
+ method,
336
+ url,
337
+ timeout,
338
+ cause: error
339
+ });
340
+ }
341
+ // Other network errors (connection refused, DNS failure, etc.)
342
+ throw new NetworkError(error.message || 'Network error occurred', {
343
+ method,
344
+ url,
345
+ code,
346
+ cause: error
347
+ });
348
+ }
349
+ const statusCode = error.response.status;
350
+ const retryAfter = error.response.headers?.['retry-after'];
131
351
  if (statusCode === 401) {
132
- throw new AuthenticationError(error.response?.data?.message || 'Invalid or missing API key', error.response?.headers?.['x-request-id']);
352
+ throw new AuthenticationError(error.response.data?.message || 'Invalid or missing API key', {
353
+ requestId,
354
+ method,
355
+ url,
356
+ cause: error
357
+ });
133
358
  }
134
359
  if (statusCode === 429) {
135
- throw new RateLimitError(error.response?.data?.message || 'Rate limit exceeded', retryAfter ? parseInt(retryAfter, 10) * 1000 : undefined, error.response?.headers?.['x-request-id']);
360
+ const retryAfterMs = retryAfter ? parseInt(retryAfter, 10) * 1000 : undefined;
361
+ throw new RateLimitError(error.response.data?.message || 'Rate limit exceeded', retryAfterMs, {
362
+ requestId,
363
+ method,
364
+ url,
365
+ cause: error
366
+ });
136
367
  }
137
368
  throw ZapyApiError.fromAxiosError(error);
138
369
  }
370
+ if (error instanceof ZapyError) {
371
+ throw error;
372
+ }
139
373
  if (error instanceof Error) {
140
- throw new ZapyApiError(error.message, 500, 'UNKNOWN_ERROR');
374
+ throw new ZapyApiError(error.message, 500, 'UNKNOWN_ERROR', {
375
+ cause: error
376
+ });
141
377
  }
142
378
  throw new ZapyApiError('An unexpected error occurred', 500, 'UNKNOWN_ERROR');
143
379
  }
@@ -1237,6 +1473,126 @@ function isContactDeduplicatedEvent(event) {
1237
1473
  return event.event === 'contact-deduplicated';
1238
1474
  }
1239
1475
 
1476
+ /**
1477
+ * WhatsApp Message Event Types
1478
+ * Comprehensive type definitions for all WhatsApp message types
1479
+ */
1480
+ // ============================================================================
1481
+ // Message Status
1482
+ // ============================================================================
1483
+ var ZapyMessageStatusEnum;
1484
+ (function (ZapyMessageStatusEnum) {
1485
+ ZapyMessageStatusEnum["UNKNOWN"] = "UNKNOWN";
1486
+ ZapyMessageStatusEnum["ERROR"] = "ERROR";
1487
+ ZapyMessageStatusEnum["PENDING"] = "PENDING";
1488
+ ZapyMessageStatusEnum["SENT"] = "SENT";
1489
+ ZapyMessageStatusEnum["RECEIVED"] = "RECEIVED";
1490
+ ZapyMessageStatusEnum["READ"] = "READ";
1491
+ ZapyMessageStatusEnum["PLAYED"] = "PLAYED";
1492
+ })(ZapyMessageStatusEnum || (ZapyMessageStatusEnum = {}));
1493
+ var ZapyMessageType;
1494
+ (function (ZapyMessageType) {
1495
+ ZapyMessageType["TEXT"] = "text";
1496
+ ZapyMessageType["IMAGE"] = "image";
1497
+ ZapyMessageType["VIDEO"] = "video";
1498
+ ZapyMessageType["AUDIO"] = "audio";
1499
+ ZapyMessageType["DOCUMENT"] = "document";
1500
+ ZapyMessageType["STICKER"] = "sticker";
1501
+ ZapyMessageType["LOCATION"] = "location";
1502
+ ZapyMessageType["LIVE_LOCATION"] = "live_location";
1503
+ ZapyMessageType["CONTACT"] = "contact";
1504
+ ZapyMessageType["REACTION"] = "reaction";
1505
+ ZapyMessageType["EDITED"] = "edited";
1506
+ ZapyMessageType["DELETED"] = "deleted";
1507
+ ZapyMessageType["POLL"] = "poll";
1508
+ ZapyMessageType["POLL_VOTE"] = "poll_vote";
1509
+ ZapyMessageType["CALL"] = "call";
1510
+ ZapyMessageType["UNSUPPORTED"] = "unsupported";
1511
+ })(ZapyMessageType || (ZapyMessageType = {}));
1512
+ // ============================================================================
1513
+ // Type Guards
1514
+ // ============================================================================
1515
+ function isTextMessage(message) {
1516
+ return message.messageType === ZapyMessageType.TEXT;
1517
+ }
1518
+ function isImageMessage(message) {
1519
+ return message.messageType === ZapyMessageType.IMAGE;
1520
+ }
1521
+ function isVideoMessage(message) {
1522
+ return message.messageType === ZapyMessageType.VIDEO;
1523
+ }
1524
+ function isAudioMessage(message) {
1525
+ return message.messageType === ZapyMessageType.AUDIO;
1526
+ }
1527
+ function isDocumentMessage(message) {
1528
+ return message.messageType === ZapyMessageType.DOCUMENT;
1529
+ }
1530
+ function isStickerMessage(message) {
1531
+ return message.messageType === ZapyMessageType.STICKER;
1532
+ }
1533
+ function isLocationMessage(message) {
1534
+ return message.messageType === ZapyMessageType.LOCATION;
1535
+ }
1536
+ function isLiveLocationMessage(message) {
1537
+ return message.messageType === ZapyMessageType.LIVE_LOCATION;
1538
+ }
1539
+ function isContactMessage(message) {
1540
+ return message.messageType === ZapyMessageType.CONTACT;
1541
+ }
1542
+ function isReactionMessage(message) {
1543
+ return message.messageType === ZapyMessageType.REACTION;
1544
+ }
1545
+ function isEditedMessage(message) {
1546
+ return message.messageType === ZapyMessageType.EDITED;
1547
+ }
1548
+ function isDeletedMessage(message) {
1549
+ return message.messageType === ZapyMessageType.DELETED;
1550
+ }
1551
+ function isPollMessage(message) {
1552
+ return message.messageType === ZapyMessageType.POLL;
1553
+ }
1554
+ function isPollVoteMessage(message) {
1555
+ return message.messageType === ZapyMessageType.POLL_VOTE;
1556
+ }
1557
+ function isCallMessage(message) {
1558
+ return message.messageType === ZapyMessageType.CALL;
1559
+ }
1560
+ function isUnsupportedMessage(message) {
1561
+ return message.messageType === ZapyMessageType.UNSUPPORTED;
1562
+ }
1563
+ function isMediaMessage(message) {
1564
+ return [ZapyMessageType.IMAGE, ZapyMessageType.VIDEO, ZapyMessageType.AUDIO, ZapyMessageType.DOCUMENT, ZapyMessageType.STICKER].includes(message.messageType);
1565
+ }
1566
+
1567
+ var WhatsappInstanceStatus;
1568
+ (function (WhatsappInstanceStatus) {
1569
+ WhatsappInstanceStatus["STOPPED"] = "stopped";
1570
+ WhatsappInstanceStatus["MANUALLY_STOPPED"] = "manually_stopped";
1571
+ WhatsappInstanceStatus["CONNECTING"] = "connecting";
1572
+ WhatsappInstanceStatus["PENDING_QR_CODE_SCAN"] = "pending_qr_code_scan";
1573
+ WhatsappInstanceStatus["CONNECTED"] = "connected";
1574
+ WhatsappInstanceStatus["ERROR"] = "error";
1575
+ WhatsappInstanceStatus["CREATED"] = "created";
1576
+ WhatsappInstanceStatus["QR_TIMEOUT"] = "qr_timeout";
1577
+ WhatsappInstanceStatus["PAYMENT_PENDING"] = "payment_pending";
1578
+ })(WhatsappInstanceStatus || (WhatsappInstanceStatus = {}));
1579
+
1580
+ // Re-export all event types
1581
+ /**
1582
+ * Event type constants for type-safe event handling
1583
+ */
1584
+ const ZapyEventTypes = {
1585
+ MESSAGE: 'message',
1586
+ MESSAGE_STATUS: 'message-status',
1587
+ REACTION: 'reaction',
1588
+ PRESENCE: 'presence',
1589
+ QR_CODE: 'qr-code',
1590
+ CONTACT_CREATED: 'contact-created',
1591
+ CONTACT_UPDATED: 'contact-updated',
1592
+ CONTACT_DEDUPLICATED: 'contact-deduplicated',
1593
+ INSTANCE_STATUS: 'instance-status'
1594
+ };
1595
+
1240
1596
  /**
1241
1597
  * Phone number utilities for @zapyapi/sdk
1242
1598
  */
@@ -1412,4 +1768,4 @@ function verifySignatureWithCrypto(crypto, payload, signature, secret) {
1412
1768
  return crypto.timingSafeEqual(Buffer.from(signature, 'utf8'), Buffer.from(expectedSignature, 'utf8'));
1413
1769
  }
1414
1770
 
1415
- export { AuthenticationError, ConnectionStatus, InstanceNotFoundError, InstanceStatus, MessageAckStatus, MessageType, RateLimitError, ValidationError, WebhookEventType, WebhookQueueStatus, ZapyApiError, ZapyClient, ZapyError, createClient, extractPhone, isContactCreatedEvent, isContactDeduplicatedEvent, isContactUpdatedEvent, isGroup, isMessageEvent, isMessageStatusEvent, isQRCodeEvent, isValidPhone, normalizePhone, verifyWebhookSignature, verifyWebhookSignatureAsync };
1771
+ export { AuthenticationError, ConnectionStatus, InstanceNotFoundError, InstanceStatus, MessageAckStatus, MessageType, NetworkError, RateLimitError, TimeoutError, ValidationError, WebhookEventType, WebhookQueueStatus, WhatsappInstanceStatus, ZapyApiError, ZapyClient, ZapyError, ZapyEventTypes, ZapyMessageStatusEnum, ZapyMessageType, createClient, extractPhone, isAudioMessage, isCallMessage, isContactCreatedEvent, isContactDeduplicatedEvent, isContactMessage, isContactUpdatedEvent, isDeletedMessage, isDocumentMessage, isEditedMessage, isGroup, isImageMessage, isLiveLocationMessage, isLocationMessage, isMediaMessage, isMessageEvent, isMessageStatusEvent, isPollMessage, isPollVoteMessage, isQRCodeEvent, isReactionMessage, isStickerMessage, isTextMessage, isUnsupportedMessage, isValidPhone, isVideoMessage, normalizePhone, verifyWebhookSignature, verifyWebhookSignatureAsync };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zapyapi/sdk",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.5",
4
4
  "description": "Official TypeScript SDK for ZapyAPI - WhatsApp API",
5
5
  "type": "module",
6
6
  "main": "./index.cjs",
package/src/errors.d.ts CHANGED
@@ -7,7 +7,15 @@ import type { ApiErrorResponse } from './types/common.types';
7
7
  * Base error class for all ZapyAPI errors
8
8
  */
9
9
  export declare class ZapyError extends Error {
10
- constructor(message: string);
10
+ /**
11
+ * Original error that caused this error (if any)
12
+ */
13
+ readonly cause?: Error;
14
+ constructor(message: string, cause?: Error);
15
+ /**
16
+ * Get a detailed string representation of the error
17
+ */
18
+ toDetailedString(): string;
11
19
  }
12
20
  /**
13
21
  * Error thrown when the API returns an error response
@@ -29,11 +37,38 @@ export declare class ZapyApiError extends ZapyError {
29
37
  * Additional error details
30
38
  */
31
39
  readonly details?: Record<string, unknown>;
32
- constructor(message: string, statusCode: number, code: string, requestId?: string, details?: Record<string, unknown>);
40
+ /**
41
+ * HTTP method used in the request
42
+ */
43
+ readonly method?: string;
44
+ /**
45
+ * URL that was requested
46
+ */
47
+ readonly url?: string;
48
+ /**
49
+ * Raw response body (for debugging)
50
+ */
51
+ readonly responseBody?: unknown;
52
+ constructor(message: string, statusCode: number, code: string, options?: {
53
+ requestId?: string;
54
+ details?: Record<string, unknown>;
55
+ method?: string;
56
+ url?: string;
57
+ responseBody?: unknown;
58
+ cause?: Error;
59
+ });
33
60
  /**
34
61
  * Create a ZapyApiError from an Axios error
35
62
  */
36
63
  static fromAxiosError(error: AxiosError<ApiErrorResponse>): ZapyApiError;
64
+ /**
65
+ * Get a detailed string representation for logging
66
+ */
67
+ toDetailedString(): string;
68
+ /**
69
+ * Convert to a plain object for logging/serialization
70
+ */
71
+ toJSON(): Record<string, unknown>;
37
72
  }
38
73
  /**
39
74
  * Error thrown when input validation fails
@@ -44,18 +79,30 @@ export declare class ValidationError extends ZapyError {
44
79
  */
45
80
  readonly details: Record<string, string[]>;
46
81
  constructor(message: string, details: Record<string, string[]>);
82
+ toDetailedString(): string;
83
+ toJSON(): Record<string, unknown>;
47
84
  }
48
85
  /**
49
86
  * Error thrown when an instance is not found
50
87
  */
51
88
  export declare class InstanceNotFoundError extends ZapyApiError {
52
- constructor(instanceId: string, requestId?: string);
89
+ readonly instanceId: string;
90
+ constructor(instanceId: string, options?: {
91
+ requestId?: string;
92
+ method?: string;
93
+ url?: string;
94
+ });
53
95
  }
54
96
  /**
55
97
  * Error thrown when authentication fails
56
98
  */
57
99
  export declare class AuthenticationError extends ZapyApiError {
58
- constructor(message?: string, requestId?: string);
100
+ constructor(message?: string, options?: {
101
+ requestId?: string;
102
+ method?: string;
103
+ url?: string;
104
+ cause?: Error;
105
+ });
59
106
  }
60
107
  /**
61
108
  * Error thrown when rate limit is exceeded
@@ -65,6 +112,55 @@ export declare class RateLimitError extends ZapyApiError {
65
112
  * Timestamp when the rate limit resets (Unix ms)
66
113
  */
67
114
  readonly retryAfter?: number;
68
- constructor(message?: string, retryAfter?: number, requestId?: string);
115
+ constructor(message?: string, retryAfter?: number, options?: {
116
+ requestId?: string;
117
+ method?: string;
118
+ url?: string;
119
+ cause?: Error;
120
+ });
121
+ /**
122
+ * Get the Date when the rate limit resets
123
+ */
124
+ getRetryAfterDate(): Date | undefined;
125
+ }
126
+ /**
127
+ * Error thrown when a network error occurs (no response received)
128
+ */
129
+ export declare class NetworkError extends ZapyError {
130
+ /**
131
+ * HTTP method used in the request
132
+ */
133
+ readonly method?: string;
134
+ /**
135
+ * URL that was requested
136
+ */
137
+ readonly url?: string;
138
+ /**
139
+ * Error code (e.g., ECONNREFUSED, ETIMEDOUT)
140
+ */
141
+ readonly code?: string;
142
+ constructor(message: string, options?: {
143
+ method?: string;
144
+ url?: string;
145
+ code?: string;
146
+ cause?: Error;
147
+ });
148
+ toDetailedString(): string;
149
+ toJSON(): Record<string, unknown>;
150
+ }
151
+ /**
152
+ * Error thrown when request times out
153
+ */
154
+ export declare class TimeoutError extends NetworkError {
155
+ /**
156
+ * Timeout duration in milliseconds
157
+ */
158
+ readonly timeout?: number;
159
+ constructor(message?: string, options?: {
160
+ timeout?: number;
161
+ method?: string;
162
+ url?: string;
163
+ cause?: Error;
164
+ });
69
165
  }
70
166
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../libs/sdk/src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAExC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D;;GAEG;AACH,qBAAa,SAAU,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM;CAK5B;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,SAAS;IACzC;;OAEG;IACH,SAAgB,UAAU,EAAE,MAAM,CAAC;IAEnC;;OAEG;IACH,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,SAAgB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnC;;OAEG;IACH,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAGhD,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,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MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;IAUlE,gBAAgB,IAAI,MAAM;IAkBnC,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAUlC;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,YAAY;IAC5C;;OAEG;IACH,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC;gBAG/B,OAAO,SAAsB,EAC7B,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAO/E"}
package/src/index.d.ts CHANGED
@@ -30,9 +30,10 @@
30
30
  * ```
31
31
  */
32
32
  export { ZapyClient, createClient } from './client';
33
- export { ZapyError, ZapyApiError, ValidationError, InstanceNotFoundError, AuthenticationError, RateLimitError, } from './errors';
34
- export { WebhookEventType, InstanceStatus, MessageAckStatus, MessageType, WebhookQueueStatus, ConnectionStatus, } from './types';
33
+ export { ZapyError, ZapyApiError, ValidationError, InstanceNotFoundError, AuthenticationError, RateLimitError, NetworkError, TimeoutError, } from './errors';
34
+ export { WebhookEventType, InstanceStatus, MessageAckStatus, MessageType, WebhookQueueStatus, ConnectionStatus, ZapyMessageStatusEnum, ZapyMessageType, WhatsappInstanceStatus, ZapyEventTypes, } from './types';
35
35
  export { isMessageEvent, isMessageStatusEvent, isQRCodeEvent, isContactCreatedEvent, isContactUpdatedEvent, isContactDeduplicatedEvent, } from './types';
36
- export type { ZapyClientOptions, PaginationQuery, PaginatedResponse, ApiErrorResponse, Instance, CreateInstanceOptions, QRCodeResponse, InstanceStatusResponse, CheckNumberResult, CheckNumbersResponse, PresenceType, SendPresenceOptions, ProfilePictureResponse, GroupParticipant, GroupMetadata, BaseMessageOptions, SendTextMessageOptions, MediaSource, SendImageMessageOptions, SendVideoMessageOptions, SendAudioNoteMessageOptions, SendAudioFileMessageOptions, SendDocumentMessageOptions, SendLocationMessageOptions, ContactCardInfo, SendContactMessageOptions, SendStickerMessageOptions, SendReactionOptions, ForwardMessageOptions, EditMessageOptions, MessageResponse, ReadMessageResponse, MediaDownloadLinkResponse, WebhookEventBase, MessageParticipant, MediaInfo, MessageEventData, MessageWebhookEvent, MessageStatusEventData, MessageAckWebhookEvent, QRCodeEventData, QRCodeWebhookEvent, ContactInfo, ContactCreatedEventData, ContactCreatedWebhookEvent, ContactUpdatedEventData, ContactUpdatedWebhookEvent, ContactDeduplicatedEventData, ContactDeduplicatedWebhookEvent, ConnectionEventData, ConnectionWebhookEvent, WebhookEvent, UserWebhookConfig, UpsertWebhookConfigInput, WebhookQueueStatusResponse, WebhookResumeResult, } from './types';
36
+ export { isTextMessage, isImageMessage, isVideoMessage, isAudioMessage, isDocumentMessage, isStickerMessage, isLocationMessage, isLiveLocationMessage, isContactMessage, isReactionMessage, isEditedMessage, isDeletedMessage, isPollMessage, isPollVoteMessage, isCallMessage, isUnsupportedMessage, isMediaMessage, } from './types';
37
+ export type { ZapyClientOptions, PaginationQuery, PaginatedResponse, ApiErrorResponse, Instance, CreateInstanceOptions, QRCodeResponse, InstanceStatusResponse, CheckNumberResult, CheckNumbersResponse, PresenceType, SendPresenceOptions, ProfilePictureResponse, GroupParticipant, GroupMetadata, BaseMessageOptions, SendTextMessageOptions, MediaSource, SendImageMessageOptions, SendVideoMessageOptions, SendAudioNoteMessageOptions, SendAudioFileMessageOptions, SendDocumentMessageOptions, SendLocationMessageOptions, ContactCardInfo, SendContactMessageOptions, SendStickerMessageOptions, SendReactionOptions, ForwardMessageOptions, EditMessageOptions, MessageResponse, ReadMessageResponse, MediaDownloadLinkResponse, WebhookEventBase, MessageParticipant, MediaInfo, MessageEventData, MessageWebhookEvent, MessageStatusEventData, MessageAckWebhookEvent, QRCodeEventData, QRCodeWebhookEvent, ContactInfo, ContactCreatedEventData, ContactCreatedWebhookEvent, ContactUpdatedEventData, ContactUpdatedWebhookEvent, ContactDeduplicatedEventData, ContactDeduplicatedWebhookEvent, ConnectionEventData, ConnectionWebhookEvent, WebhookEvent, UserWebhookConfig, UpsertWebhookConfigInput, WebhookQueueStatusResponse, WebhookResumeResult, ZapyMessageStatus, ZapyCallStatus, BaseZapyMessage, QuotedMessage, ZapyTextMessage, BaseMediaMessage, ZapyImageMessage, ZapyVideoMessage, ZapyAudioMessage, ZapyDocumentMessage, ZapyStickerMessage, ZapyLocationMessage, ZapyLiveLocationMessage, ZapyContactInfo, ZapyContactMessage, ZapyReactionMessage, ZapyEditedMessage, ZapyDeletedMessage, PollOption, ZapyPollMessage, ZapyPollVoteMessage, ZapyCallMessage, ZapyUnsupportedMessage, ZapyMessage, ZapyContact, ZapyContactCreatedEvent, ZapyContactUpdatedEvent, ZapyContactDeduplicatedEvent, ZapyInstanceStatusEvent, ZapyPresenceStatus, ZapyPresenceEvent, ZapyQRCodeEvent, ZapyReactionEvent, ZapyEventMap, ZapyEventType, ZapyEvent, ZapyWebhookPayload, } from './types';
37
38
  export { normalizePhone, isValidPhone, isGroup, extractPhone, verifyWebhookSignature, verifyWebhookSignatureAsync, } from './utils';
38
39
  //# sourceMappingURL=index.d.ts.map