@zapyapi/sdk 1.0.0-beta.13 → 1.0.0-beta.15

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.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  var axios = require('axios');
4
4
 
5
5
  /** SDK version - auto-generated from package.json */
6
- const SDK_VERSION = '1.0.0-beta.13';
6
+ const SDK_VERSION = '1.0.0-beta.15';
7
7
 
8
8
  /**
9
9
  * Custom error classes for @zapyapi/sdk
@@ -1496,19 +1496,53 @@ const ZapyEventTypes = {
1496
1496
  * Phone number utilities for @zapyapi/sdk
1497
1497
  */
1498
1498
  /**
1499
- * Normalize a phone number to the format expected by the API
1499
+ * UUID v4 regex pattern for detecting Zapy contact IDs
1500
+ */
1501
+ const UUID_V4_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
1502
+ /**
1503
+ * Valid WhatsApp ID suffixes
1504
+ */
1505
+ const WHATSAPP_ID_SUFFIXES = ['@s.whatsapp.net', '@c.us', '@g.us', '@lid'];
1506
+ /**
1507
+ * Check if a string is a valid WhatsApp ID (JID/LID)
1508
+ */
1509
+ function isWhatsAppId(value) {
1510
+ return WHATSAPP_ID_SUFFIXES.some(suffix => value.endsWith(suffix));
1511
+ }
1512
+ /**
1513
+ * Normalize a phone number or WhatsApp identifier to the format expected by the API
1514
+ *
1515
+ * Accepts:
1516
+ * - Phone numbers (with or without country code)
1517
+ * - Zapy contact UUIDs
1518
+ * - WhatsApp JIDs (e.g., 5511999999999@s.whatsapp.net)
1519
+ * - WhatsApp LIDs (e.g., 932757054219706064@lid)
1520
+ * - WhatsApp group IDs (e.g., 120363404090439360@g.us)
1521
+ * - Legacy format (e.g., 5511999999999@c.us)
1500
1522
  *
1501
- * @param phone - Phone number in various formats
1502
- * @returns Normalized phone number
1523
+ * @param phone - Phone number or WhatsApp identifier in various formats
1524
+ * @returns Normalized identifier ready for the API
1503
1525
  *
1504
1526
  * @example
1505
- * normalizePhone('11999999999') // '5511999999999'
1506
- * normalizePhone('5511999999999') // '5511999999999'
1507
- * normalizePhone('+5511999999999') // '5511999999999'
1508
- * normalizePhone('5511999999999@s.whatsapp.net') // '5511999999999@s.whatsapp.net'
1527
+ * normalizePhone('11999999999') // '5511999999999'
1528
+ * normalizePhone('5511999999999') // '5511999999999'
1529
+ * normalizePhone('+5511999999999') // '5511999999999'
1530
+ * normalizePhone('5511999999999@s.whatsapp.net') // '5511999999999@s.whatsapp.net'
1531
+ * normalizePhone('932757054219706064@lid') // '932757054219706064@lid'
1532
+ * normalizePhone('120363404090439360@g.us') // '120363404090439360@g.us'
1533
+ * normalizePhone('5f2528b2-93f5-4b90-883a-c423dafc25b1') // '5f2528b2-93f5-4b90-883a-c423dafc25b1'
1509
1534
  */
1510
1535
  function normalizePhone(phone) {
1511
- // If it's already a WhatsApp ID, return as-is
1536
+ // If it's a UUID (Zapy contact ID), return as-is
1537
+ if (UUID_V4_REGEX.test(phone)) {
1538
+ return phone;
1539
+ }
1540
+ // If it's already a valid WhatsApp ID (JID/LID/group), return as-is
1541
+ if (isWhatsAppId(phone)) {
1542
+ return phone;
1543
+ }
1544
+ // If it contains @ but isn't a valid WhatsApp ID, still pass through
1545
+ // (let the server validate and provide a proper error message)
1512
1546
  if (phone.includes('@')) {
1513
1547
  return phone;
1514
1548
  }
@@ -1526,15 +1560,23 @@ function normalizePhone(phone) {
1526
1560
  return cleaned;
1527
1561
  }
1528
1562
  /**
1529
- * Validate if a string is a valid phone number format
1563
+ * Validate if a string is a valid phone number or WhatsApp identifier
1530
1564
  *
1531
- * @param phone - Phone number to validate
1532
- * @returns Whether the phone number is valid
1565
+ * @param phone - Phone number or WhatsApp identifier to validate
1566
+ * @returns Whether the input is valid
1533
1567
  */
1534
1568
  function isValidPhone(phone) {
1535
- // WhatsApp IDs are valid
1569
+ // UUIDs (Zapy contact IDs) are valid
1570
+ if (UUID_V4_REGEX.test(phone)) {
1571
+ return true;
1572
+ }
1573
+ // WhatsApp IDs (JID/LID/group) are valid
1574
+ if (isWhatsAppId(phone)) {
1575
+ return true;
1576
+ }
1577
+ // If it contains @ but isn't a valid WhatsApp ID, it's invalid
1536
1578
  if (phone.includes('@')) {
1537
- return phone.endsWith('@s.whatsapp.net') || phone.endsWith('@c.us') || phone.endsWith('@g.us') || phone.endsWith('@lid');
1579
+ return false;
1538
1580
  }
1539
1581
  // Clean and check if it's a valid number
1540
1582
  const cleaned = phone.replace(/[^\d]/g, '');
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.13';
4
+ const SDK_VERSION = '1.0.0-beta.15';
5
5
 
6
6
  /**
7
7
  * Custom error classes for @zapyapi/sdk
@@ -1494,19 +1494,53 @@ const ZapyEventTypes = {
1494
1494
  * Phone number utilities for @zapyapi/sdk
1495
1495
  */
1496
1496
  /**
1497
- * Normalize a phone number to the format expected by the API
1497
+ * UUID v4 regex pattern for detecting Zapy contact IDs
1498
+ */
1499
+ const UUID_V4_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
1500
+ /**
1501
+ * Valid WhatsApp ID suffixes
1502
+ */
1503
+ const WHATSAPP_ID_SUFFIXES = ['@s.whatsapp.net', '@c.us', '@g.us', '@lid'];
1504
+ /**
1505
+ * Check if a string is a valid WhatsApp ID (JID/LID)
1506
+ */
1507
+ function isWhatsAppId(value) {
1508
+ return WHATSAPP_ID_SUFFIXES.some(suffix => value.endsWith(suffix));
1509
+ }
1510
+ /**
1511
+ * Normalize a phone number or WhatsApp identifier to the format expected by the API
1512
+ *
1513
+ * Accepts:
1514
+ * - Phone numbers (with or without country code)
1515
+ * - Zapy contact UUIDs
1516
+ * - WhatsApp JIDs (e.g., 5511999999999@s.whatsapp.net)
1517
+ * - WhatsApp LIDs (e.g., 932757054219706064@lid)
1518
+ * - WhatsApp group IDs (e.g., 120363404090439360@g.us)
1519
+ * - Legacy format (e.g., 5511999999999@c.us)
1498
1520
  *
1499
- * @param phone - Phone number in various formats
1500
- * @returns Normalized phone number
1521
+ * @param phone - Phone number or WhatsApp identifier in various formats
1522
+ * @returns Normalized identifier ready for the API
1501
1523
  *
1502
1524
  * @example
1503
- * normalizePhone('11999999999') // '5511999999999'
1504
- * normalizePhone('5511999999999') // '5511999999999'
1505
- * normalizePhone('+5511999999999') // '5511999999999'
1506
- * normalizePhone('5511999999999@s.whatsapp.net') // '5511999999999@s.whatsapp.net'
1525
+ * normalizePhone('11999999999') // '5511999999999'
1526
+ * normalizePhone('5511999999999') // '5511999999999'
1527
+ * normalizePhone('+5511999999999') // '5511999999999'
1528
+ * normalizePhone('5511999999999@s.whatsapp.net') // '5511999999999@s.whatsapp.net'
1529
+ * normalizePhone('932757054219706064@lid') // '932757054219706064@lid'
1530
+ * normalizePhone('120363404090439360@g.us') // '120363404090439360@g.us'
1531
+ * normalizePhone('5f2528b2-93f5-4b90-883a-c423dafc25b1') // '5f2528b2-93f5-4b90-883a-c423dafc25b1'
1507
1532
  */
1508
1533
  function normalizePhone(phone) {
1509
- // If it's already a WhatsApp ID, return as-is
1534
+ // If it's a UUID (Zapy contact ID), return as-is
1535
+ if (UUID_V4_REGEX.test(phone)) {
1536
+ return phone;
1537
+ }
1538
+ // If it's already a valid WhatsApp ID (JID/LID/group), return as-is
1539
+ if (isWhatsAppId(phone)) {
1540
+ return phone;
1541
+ }
1542
+ // If it contains @ but isn't a valid WhatsApp ID, still pass through
1543
+ // (let the server validate and provide a proper error message)
1510
1544
  if (phone.includes('@')) {
1511
1545
  return phone;
1512
1546
  }
@@ -1524,15 +1558,23 @@ function normalizePhone(phone) {
1524
1558
  return cleaned;
1525
1559
  }
1526
1560
  /**
1527
- * Validate if a string is a valid phone number format
1561
+ * Validate if a string is a valid phone number or WhatsApp identifier
1528
1562
  *
1529
- * @param phone - Phone number to validate
1530
- * @returns Whether the phone number is valid
1563
+ * @param phone - Phone number or WhatsApp identifier to validate
1564
+ * @returns Whether the input is valid
1531
1565
  */
1532
1566
  function isValidPhone(phone) {
1533
- // WhatsApp IDs are valid
1567
+ // UUIDs (Zapy contact IDs) are valid
1568
+ if (UUID_V4_REGEX.test(phone)) {
1569
+ return true;
1570
+ }
1571
+ // WhatsApp IDs (JID/LID/group) are valid
1572
+ if (isWhatsAppId(phone)) {
1573
+ return true;
1574
+ }
1575
+ // If it contains @ but isn't a valid WhatsApp ID, it's invalid
1534
1576
  if (phone.includes('@')) {
1535
- return phone.endsWith('@s.whatsapp.net') || phone.endsWith('@c.us') || phone.endsWith('@g.us') || phone.endsWith('@lid');
1577
+ return false;
1536
1578
  }
1537
1579
  // Clean and check if it's a valid number
1538
1580
  const cleaned = phone.replace(/[^\d]/g, '');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zapyapi/sdk",
3
- "version": "1.0.0-beta.13",
3
+ "version": "1.0.0-beta.15",
4
4
  "description": "Official TypeScript SDK for ZapyAPI - WhatsApp API",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -2,23 +2,34 @@
2
2
  * Phone number utilities for @zapyapi/sdk
3
3
  */
4
4
  /**
5
- * Normalize a phone number to the format expected by the API
5
+ * Normalize a phone number or WhatsApp identifier to the format expected by the API
6
6
  *
7
- * @param phone - Phone number in various formats
8
- * @returns Normalized phone number
7
+ * Accepts:
8
+ * - Phone numbers (with or without country code)
9
+ * - Zapy contact UUIDs
10
+ * - WhatsApp JIDs (e.g., 5511999999999@s.whatsapp.net)
11
+ * - WhatsApp LIDs (e.g., 932757054219706064@lid)
12
+ * - WhatsApp group IDs (e.g., 120363404090439360@g.us)
13
+ * - Legacy format (e.g., 5511999999999@c.us)
14
+ *
15
+ * @param phone - Phone number or WhatsApp identifier in various formats
16
+ * @returns Normalized identifier ready for the API
9
17
  *
10
18
  * @example
11
- * normalizePhone('11999999999') // '5511999999999'
12
- * normalizePhone('5511999999999') // '5511999999999'
13
- * normalizePhone('+5511999999999') // '5511999999999'
14
- * normalizePhone('5511999999999@s.whatsapp.net') // '5511999999999@s.whatsapp.net'
19
+ * normalizePhone('11999999999') // '5511999999999'
20
+ * normalizePhone('5511999999999') // '5511999999999'
21
+ * normalizePhone('+5511999999999') // '5511999999999'
22
+ * normalizePhone('5511999999999@s.whatsapp.net') // '5511999999999@s.whatsapp.net'
23
+ * normalizePhone('932757054219706064@lid') // '932757054219706064@lid'
24
+ * normalizePhone('120363404090439360@g.us') // '120363404090439360@g.us'
25
+ * normalizePhone('5f2528b2-93f5-4b90-883a-c423dafc25b1') // '5f2528b2-93f5-4b90-883a-c423dafc25b1'
15
26
  */
16
27
  export declare function normalizePhone(phone: string): string;
17
28
  /**
18
- * Validate if a string is a valid phone number format
29
+ * Validate if a string is a valid phone number or WhatsApp identifier
19
30
  *
20
- * @param phone - Phone number to validate
21
- * @returns Whether the phone number is valid
31
+ * @param phone - Phone number or WhatsApp identifier to validate
32
+ * @returns Whether the input is valid
22
33
  */
23
34
  export declare function isValidPhone(phone: string): boolean;
24
35
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"phone.d.ts","sourceRoot":"","sources":["../../../../../libs/sdk/src/utils/phone.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAqBpD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAYnD;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE5C;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGhD"}
1
+ {"version":3,"file":"phone.d.ts","sourceRoot":"","sources":["../../../../../libs/sdk/src/utils/phone.ts"],"names":[],"mappings":"AAAA;;GAEG;AAmBH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAgCpD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAsBnD;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE5C;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGhD"}
package/src/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /** SDK version - auto-generated from package.json */
2
- export declare const SDK_VERSION = "1.0.0-beta.13";
2
+ export declare const SDK_VERSION = "1.0.0-beta.15";
3
3
  //# sourceMappingURL=version.d.ts.map