@drawbridge/drawbridge-utils 0.0.63 → 0.0.65

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/dist/index.cjs CHANGED
@@ -164,8 +164,8 @@ var constants_default = {
164
164
  draws: 0,
165
165
  exports: 0,
166
166
  entries: 0,
167
- fields: 2,
168
- integrations: 1,
167
+ fields: 0,
168
+ integrations: 0,
169
169
  leads: 0,
170
170
  links: 0,
171
171
  pages: 0,
package/dist/index.d.cts CHANGED
@@ -85,8 +85,8 @@ var constantsData = {
85
85
  draws : 0,
86
86
  exports : 0,
87
87
  entries : 0,
88
- fields : 2,
89
- integrations : 1,
88
+ fields : 0,
89
+ integrations : 0,
90
90
  leads : 0,
91
91
  links : 0,
92
92
  pages : 0,
package/dist/index.d.ts CHANGED
@@ -85,8 +85,8 @@ var constantsData = {
85
85
  draws : 0,
86
86
  exports : 0,
87
87
  entries : 0,
88
- fields : 2,
89
- integrations : 1,
88
+ fields : 0,
89
+ integrations : 0,
90
90
  leads : 0,
91
91
  links : 0,
92
92
  pages : 0,
package/dist/index.js CHANGED
@@ -108,8 +108,8 @@ var constants_default = {
108
108
  draws: 0,
109
109
  exports: 0,
110
110
  entries: 0,
111
- fields: 2,
112
- integrations: 1,
111
+ fields: 0,
112
+ integrations: 0,
113
113
  leads: 0,
114
114
  links: 0,
115
115
  pages: 0,
package/dist/phone.cjs ADDED
@@ -0,0 +1,48 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // lib/phone.js
20
+ var phone_exports = {};
21
+ __export(phone_exports, {
22
+ isValid: () => isValid,
23
+ toE164: () => toE164
24
+ });
25
+ module.exports = __toCommonJS(phone_exports);
26
+ var import_libphonenumber_js = require("libphonenumber-js");
27
+ var toE164 = (value, country) => {
28
+ if (!value) return null;
29
+ try {
30
+ const parsed = (0, import_libphonenumber_js.parsePhoneNumberFromString)(String(value), country);
31
+ return parsed ? parsed.number : null;
32
+ } catch {
33
+ return null;
34
+ }
35
+ };
36
+ var isValid = (value, country) => {
37
+ if (!value) return false;
38
+ try {
39
+ return (0, import_libphonenumber_js.isValidPhoneNumber)(String(value), country);
40
+ } catch {
41
+ return false;
42
+ }
43
+ };
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ isValid,
47
+ toE164
48
+ });
@@ -0,0 +1,45 @@
1
+ import { isValidPhoneNumber, parsePhoneNumberFromString } from 'libphonenumber-js';
2
+
3
+ // Canonicalize a phone value to E.164 (e.g. '+15551234567'), or null if it cannot
4
+ // be parsed. `country` (ISO 3166-1 alpha-2, e.g. 'US') is only needed for
5
+ // national-format input; E.164 input (Shopify webhooks, react-phone-number-input)
6
+ // parses without it. Lenient by design — returns the canonical form for any
7
+ // parseable number so order/lead phone matching does not drop valid-but-unusual
8
+ // numbers; clearly garbage input yields null.
9
+ const toE164 = ( value, country ) => {
10
+
11
+ if( ! value ) return null;
12
+
13
+ try {
14
+
15
+ const parsed = parsePhoneNumberFromString( String( value ), country );
16
+
17
+ return parsed ? parsed.number : null;
18
+
19
+ } catch {
20
+
21
+ return null;
22
+
23
+ }
24
+
25
+ };
26
+
27
+ // Strict validity check (wraps libphonenumber-js). Mirrors the validation
28
+ // drawbridge-api's submission route already performs on lead phone input.
29
+ const isValid = ( value, country ) => {
30
+
31
+ if( ! value ) return false;
32
+
33
+ try {
34
+
35
+ return isValidPhoneNumber( String( value ), country );
36
+
37
+ } catch {
38
+
39
+ return false;
40
+
41
+ }
42
+
43
+ };
44
+
45
+ export { isValid, toE164 };
@@ -0,0 +1,45 @@
1
+ import { isValidPhoneNumber, parsePhoneNumberFromString } from 'libphonenumber-js';
2
+
3
+ // Canonicalize a phone value to E.164 (e.g. '+15551234567'), or null if it cannot
4
+ // be parsed. `country` (ISO 3166-1 alpha-2, e.g. 'US') is only needed for
5
+ // national-format input; E.164 input (Shopify webhooks, react-phone-number-input)
6
+ // parses without it. Lenient by design — returns the canonical form for any
7
+ // parseable number so order/lead phone matching does not drop valid-but-unusual
8
+ // numbers; clearly garbage input yields null.
9
+ const toE164 = ( value, country ) => {
10
+
11
+ if( ! value ) return null;
12
+
13
+ try {
14
+
15
+ const parsed = parsePhoneNumberFromString( String( value ), country );
16
+
17
+ return parsed ? parsed.number : null;
18
+
19
+ } catch {
20
+
21
+ return null;
22
+
23
+ }
24
+
25
+ };
26
+
27
+ // Strict validity check (wraps libphonenumber-js). Mirrors the validation
28
+ // drawbridge-api's submission route already performs on lead phone input.
29
+ const isValid = ( value, country ) => {
30
+
31
+ if( ! value ) return false;
32
+
33
+ try {
34
+
35
+ return isValidPhoneNumber( String( value ), country );
36
+
37
+ } catch {
38
+
39
+ return false;
40
+
41
+ }
42
+
43
+ };
44
+
45
+ export { isValid, toE164 };
package/dist/phone.js ADDED
@@ -0,0 +1,23 @@
1
+ // lib/phone.js
2
+ import { parsePhoneNumberFromString, isValidPhoneNumber } from "libphonenumber-js";
3
+ var toE164 = (value, country) => {
4
+ if (!value) return null;
5
+ try {
6
+ const parsed = parsePhoneNumberFromString(String(value), country);
7
+ return parsed ? parsed.number : null;
8
+ } catch {
9
+ return null;
10
+ }
11
+ };
12
+ var isValid = (value, country) => {
13
+ if (!value) return false;
14
+ try {
15
+ return isValidPhoneNumber(String(value), country);
16
+ } catch {
17
+ return false;
18
+ }
19
+ };
20
+ export {
21
+ isValid,
22
+ toE164
23
+ };
package/package.json CHANGED
@@ -7,6 +7,7 @@
7
7
  "axios": "1.16.0",
8
8
  "currency-codes": "2.2.0",
9
9
  "disposable-email-domains": "1.0.62",
10
+ "libphonenumber-js": "1.13.4",
10
11
  "nanoid": "3.3.8",
11
12
  "qs": "6.15.2",
12
13
  "slugify": "1.6.6",
@@ -86,6 +87,11 @@
86
87
  "import": "./dist/orders.js",
87
88
  "require": "./dist/orders.cjs"
88
89
  },
90
+ "./phone": {
91
+ "types": "./dist/phone.d.ts",
92
+ "import": "./dist/phone.js",
93
+ "require": "./dist/phone.cjs"
94
+ },
89
95
  "./redirect": {
90
96
  "types": "./dist/redirect.d.ts",
91
97
  "import": "./dist/redirect.js",
@@ -157,5 +163,5 @@
157
163
  "build": "tsup && npm publish"
158
164
  },
159
165
  "types": "dist/index.d.ts",
160
- "version": "0.0.63"
166
+ "version": "0.0.65"
161
167
  }