@jadedm/nestjs-verify-twilio 0.5.0 → 0.6.1
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/LICENSE +21 -0
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Manish Jadhav (jadedm)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
9
|
var __export = (target, all) => {
|
|
@@ -16,6 +18,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
18
|
}
|
|
17
19
|
return to;
|
|
18
20
|
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
19
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
30
|
|
|
21
31
|
// src/index.ts
|
|
@@ -26,7 +36,7 @@ __export(src_exports, {
|
|
|
26
36
|
module.exports = __toCommonJS(src_exports);
|
|
27
37
|
|
|
28
38
|
// src/twilio-sms.provider.ts
|
|
29
|
-
var import_twilio = require("twilio");
|
|
39
|
+
var import_twilio = __toESM(require("twilio"));
|
|
30
40
|
var TRANSIENT_STATUS_CODES = /* @__PURE__ */ new Set([
|
|
31
41
|
429,
|
|
32
42
|
500,
|
|
@@ -44,7 +54,7 @@ var TwilioSmsProvider = class {
|
|
|
44
54
|
maxRetries;
|
|
45
55
|
retryBaseMs;
|
|
46
56
|
constructor(opts) {
|
|
47
|
-
this.client = new import_twilio.Twilio(opts.accountSid, opts.authToken);
|
|
57
|
+
this.client = new import_twilio.default.Twilio(opts.accountSid, opts.authToken);
|
|
48
58
|
this.from = opts.from;
|
|
49
59
|
this.maxRetries = opts.maxRetries ?? 2;
|
|
50
60
|
this.retryBaseMs = opts.retryBaseMs ?? 250;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/twilio-sms.provider.ts"],"sourcesContent":["export * from './twilio-sms.provider.js';\n","import type {\n SmsProvider,\n SmsSendParams,\n SmsSendResult,\n} from '@jadedm/nestjs-verify';\nimport { Twilio } from 'twilio';\n\nexport interface TwilioSmsProviderOptions {\n accountSid: string;\n authToken: string;\n /** E.164 sender number, or Messaging Service SID (starts with MG…). */\n from: string;\n /** Retry budget for transient (5xx, network) failures. Default 2. */\n maxRetries?: number;\n /** Base delay in ms for exponential backoff. Default 250. */\n retryBaseMs?: number;\n}\n\n/**\n * Errors Twilio considers transient — worth retrying. Everything else\n * (invalid number, blocked recipient, geo-permission) is terminal.\n */\nconst TRANSIENT_STATUS_CODES = new Set([429, 500, 502, 503, 504]);\n\nexport class TwilioSmsProvider implements SmsProvider {\n readonly name = 'twilio';\n private readonly client: Twilio;\n private readonly from: string;\n private readonly maxRetries: number;\n private readonly retryBaseMs: number;\n\n constructor(opts: TwilioSmsProviderOptions) {\n this.client = new Twilio(opts.accountSid, opts.authToken);\n this.from = opts.from;\n this.maxRetries = opts.maxRetries ?? 2;\n this.retryBaseMs = opts.retryBaseMs ?? 250;\n }\n\n async send(params: SmsSendParams): Promise<SmsSendResult> {\n const useMessagingService = this.from.startsWith('MG');\n let attempt = 0;\n let lastErr: unknown;\n while (attempt <= this.maxRetries) {\n try {\n const message = await this.client.messages.create({\n to: params.to,\n body: params.body,\n ...(useMessagingService\n ? { messagingServiceSid: this.from }\n : { from: this.from }),\n });\n return { providerMessageId: message.sid, provider: this.name };\n } catch (err) {\n lastErr = err;\n const status = (err as { status?: number }).status;\n if (status && !TRANSIENT_STATUS_CODES.has(status)) throw err;\n if (attempt === this.maxRetries) break;\n await this.sleep(this.retryBaseMs * 2 ** attempt);\n attempt++;\n }\n }\n throw lastErr;\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((r) => setTimeout(r, ms));\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/twilio-sms.provider.ts"],"sourcesContent":["export * from './twilio-sms.provider.js';\n","import type {\n SmsProvider,\n SmsSendParams,\n SmsSendResult,\n} from '@jadedm/nestjs-verify';\nimport type { Twilio } from 'twilio';\n// twilio is CommonJS without an __esModule flag, so Node's ESM loader exposes\n// only its default export. A named `import { Twilio }` loads under vitest and in\n// the CommonJS build but fails for ESM consumers (#21).\nimport twilio from 'twilio';\n\nexport interface TwilioSmsProviderOptions {\n accountSid: string;\n authToken: string;\n /** E.164 sender number, or Messaging Service SID (starts with MG…). */\n from: string;\n /** Retry budget for transient (5xx, network) failures. Default 2. */\n maxRetries?: number;\n /** Base delay in ms for exponential backoff. Default 250. */\n retryBaseMs?: number;\n}\n\n/**\n * Errors Twilio considers transient — worth retrying. Everything else\n * (invalid number, blocked recipient, geo-permission) is terminal.\n */\nconst TRANSIENT_STATUS_CODES = new Set([429, 500, 502, 503, 504]);\n\nexport class TwilioSmsProvider implements SmsProvider {\n readonly name = 'twilio';\n private readonly client: Twilio;\n private readonly from: string;\n private readonly maxRetries: number;\n private readonly retryBaseMs: number;\n\n constructor(opts: TwilioSmsProviderOptions) {\n this.client = new twilio.Twilio(opts.accountSid, opts.authToken);\n this.from = opts.from;\n this.maxRetries = opts.maxRetries ?? 2;\n this.retryBaseMs = opts.retryBaseMs ?? 250;\n }\n\n async send(params: SmsSendParams): Promise<SmsSendResult> {\n const useMessagingService = this.from.startsWith('MG');\n let attempt = 0;\n let lastErr: unknown;\n while (attempt <= this.maxRetries) {\n try {\n const message = await this.client.messages.create({\n to: params.to,\n body: params.body,\n ...(useMessagingService\n ? { messagingServiceSid: this.from }\n : { from: this.from }),\n });\n return { providerMessageId: message.sid, provider: this.name };\n } catch (err) {\n lastErr = err;\n const status = (err as { status?: number }).status;\n if (status && !TRANSIENT_STATUS_CODES.has(status)) throw err;\n if (attempt === this.maxRetries) break;\n await this.sleep(this.retryBaseMs * 2 ** attempt);\n attempt++;\n }\n }\n throw lastErr;\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((r) => setTimeout(r, ms));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACSA,oBAAmB;AAiBnB,IAAMA,yBAAyB,oBAAIC,IAAI;EAAC;EAAK;EAAK;EAAK;EAAK;CAAI;AAEzD,IAAMC,oBAAN,MAAMA;EAtBb,OAsBaA;;;EACFC,OAAO;EACCC;EACAC;EACAC;EACAC;EAEjB,YAAYC,MAAgC;AAC1C,SAAKJ,SAAS,IAAIK,cAAAA,QAAOC,OAAOF,KAAKG,YAAYH,KAAKI,SAAS;AAC/D,SAAKP,OAAOG,KAAKH;AACjB,SAAKC,aAAaE,KAAKF,cAAc;AACrC,SAAKC,cAAcC,KAAKD,eAAe;EACzC;EAEA,MAAMM,KAAKC,QAA+C;AACxD,UAAMC,sBAAsB,KAAKV,KAAKW,WAAW,IAAA;AACjD,QAAIC,UAAU;AACd,QAAIC;AACJ,WAAOD,WAAW,KAAKX,YAAY;AACjC,UAAI;AACF,cAAMa,UAAU,MAAM,KAAKf,OAAOgB,SAASC,OAAO;UAChDC,IAAIR,OAAOQ;UACXC,MAAMT,OAAOS;UACb,GAAIR,sBACA;YAAES,qBAAqB,KAAKnB;UAAK,IACjC;YAAEA,MAAM,KAAKA;UAAK;QACxB,CAAA;AACA,eAAO;UAAEoB,mBAAmBN,QAAQO;UAAKC,UAAU,KAAKxB;QAAK;MAC/D,SAASyB,KAAK;AACZV,kBAAUU;AACV,cAAMC,SAAUD,IAA4BC;AAC5C,YAAIA,UAAU,CAAC7B,uBAAuB8B,IAAID,MAAAA,EAAS,OAAMD;AACzD,YAAIX,YAAY,KAAKX,WAAY;AACjC,cAAM,KAAKyB,MAAM,KAAKxB,cAAc,KAAKU,OAAAA;AACzCA;MACF;IACF;AACA,UAAMC;EACR;EAEQa,MAAMC,IAA2B;AACvC,WAAO,IAAIC,QAAQ,CAACC,MAAMC,WAAWD,GAAGF,EAAAA,CAAAA;EAC1C;AACF;","names":["TRANSIENT_STATUS_CODES","Set","TwilioSmsProvider","name","client","from","maxRetries","retryBaseMs","opts","twilio","Twilio","accountSid","authToken","send","params","useMessagingService","startsWith","attempt","lastErr","message","messages","create","to","body","messagingServiceSid","providerMessageId","sid","provider","err","status","has","sleep","ms","Promise","r","setTimeout"]}
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/twilio-sms.provider.ts
|
|
5
|
-
import
|
|
5
|
+
import twilio from "twilio";
|
|
6
6
|
var TRANSIENT_STATUS_CODES = /* @__PURE__ */ new Set([
|
|
7
7
|
429,
|
|
8
8
|
500,
|
|
@@ -20,7 +20,7 @@ var TwilioSmsProvider = class {
|
|
|
20
20
|
maxRetries;
|
|
21
21
|
retryBaseMs;
|
|
22
22
|
constructor(opts) {
|
|
23
|
-
this.client = new Twilio(opts.accountSid, opts.authToken);
|
|
23
|
+
this.client = new twilio.Twilio(opts.accountSid, opts.authToken);
|
|
24
24
|
this.from = opts.from;
|
|
25
25
|
this.maxRetries = opts.maxRetries ?? 2;
|
|
26
26
|
this.retryBaseMs = opts.retryBaseMs ?? 250;
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/twilio-sms.provider.ts"],"sourcesContent":["import type {\n SmsProvider,\n SmsSendParams,\n SmsSendResult,\n} from '@jadedm/nestjs-verify';\nimport { Twilio } from 'twilio';\n\nexport interface TwilioSmsProviderOptions {\n accountSid: string;\n authToken: string;\n /** E.164 sender number, or Messaging Service SID (starts with MG…). */\n from: string;\n /** Retry budget for transient (5xx, network) failures. Default 2. */\n maxRetries?: number;\n /** Base delay in ms for exponential backoff. Default 250. */\n retryBaseMs?: number;\n}\n\n/**\n * Errors Twilio considers transient — worth retrying. Everything else\n * (invalid number, blocked recipient, geo-permission) is terminal.\n */\nconst TRANSIENT_STATUS_CODES = new Set([429, 500, 502, 503, 504]);\n\nexport class TwilioSmsProvider implements SmsProvider {\n readonly name = 'twilio';\n private readonly client: Twilio;\n private readonly from: string;\n private readonly maxRetries: number;\n private readonly retryBaseMs: number;\n\n constructor(opts: TwilioSmsProviderOptions) {\n this.client = new Twilio(opts.accountSid, opts.authToken);\n this.from = opts.from;\n this.maxRetries = opts.maxRetries ?? 2;\n this.retryBaseMs = opts.retryBaseMs ?? 250;\n }\n\n async send(params: SmsSendParams): Promise<SmsSendResult> {\n const useMessagingService = this.from.startsWith('MG');\n let attempt = 0;\n let lastErr: unknown;\n while (attempt <= this.maxRetries) {\n try {\n const message = await this.client.messages.create({\n to: params.to,\n body: params.body,\n ...(useMessagingService\n ? { messagingServiceSid: this.from }\n : { from: this.from }),\n });\n return { providerMessageId: message.sid, provider: this.name };\n } catch (err) {\n lastErr = err;\n const status = (err as { status?: number }).status;\n if (status && !TRANSIENT_STATUS_CODES.has(status)) throw err;\n if (attempt === this.maxRetries) break;\n await this.sleep(this.retryBaseMs * 2 ** attempt);\n attempt++;\n }\n }\n throw lastErr;\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((r) => setTimeout(r, ms));\n }\n}\n"],"mappings":";;;;
|
|
1
|
+
{"version":3,"sources":["../src/twilio-sms.provider.ts"],"sourcesContent":["import type {\n SmsProvider,\n SmsSendParams,\n SmsSendResult,\n} from '@jadedm/nestjs-verify';\nimport type { Twilio } from 'twilio';\n// twilio is CommonJS without an __esModule flag, so Node's ESM loader exposes\n// only its default export. A named `import { Twilio }` loads under vitest and in\n// the CommonJS build but fails for ESM consumers (#21).\nimport twilio from 'twilio';\n\nexport interface TwilioSmsProviderOptions {\n accountSid: string;\n authToken: string;\n /** E.164 sender number, or Messaging Service SID (starts with MG…). */\n from: string;\n /** Retry budget for transient (5xx, network) failures. Default 2. */\n maxRetries?: number;\n /** Base delay in ms for exponential backoff. Default 250. */\n retryBaseMs?: number;\n}\n\n/**\n * Errors Twilio considers transient — worth retrying. Everything else\n * (invalid number, blocked recipient, geo-permission) is terminal.\n */\nconst TRANSIENT_STATUS_CODES = new Set([429, 500, 502, 503, 504]);\n\nexport class TwilioSmsProvider implements SmsProvider {\n readonly name = 'twilio';\n private readonly client: Twilio;\n private readonly from: string;\n private readonly maxRetries: number;\n private readonly retryBaseMs: number;\n\n constructor(opts: TwilioSmsProviderOptions) {\n this.client = new twilio.Twilio(opts.accountSid, opts.authToken);\n this.from = opts.from;\n this.maxRetries = opts.maxRetries ?? 2;\n this.retryBaseMs = opts.retryBaseMs ?? 250;\n }\n\n async send(params: SmsSendParams): Promise<SmsSendResult> {\n const useMessagingService = this.from.startsWith('MG');\n let attempt = 0;\n let lastErr: unknown;\n while (attempt <= this.maxRetries) {\n try {\n const message = await this.client.messages.create({\n to: params.to,\n body: params.body,\n ...(useMessagingService\n ? { messagingServiceSid: this.from }\n : { from: this.from }),\n });\n return { providerMessageId: message.sid, provider: this.name };\n } catch (err) {\n lastErr = err;\n const status = (err as { status?: number }).status;\n if (status && !TRANSIENT_STATUS_CODES.has(status)) throw err;\n if (attempt === this.maxRetries) break;\n await this.sleep(this.retryBaseMs * 2 ** attempt);\n attempt++;\n }\n }\n throw lastErr;\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((r) => setTimeout(r, ms));\n }\n}\n"],"mappings":";;;;AASA,OAAOA,YAAY;AAiBnB,IAAMC,yBAAyB,oBAAIC,IAAI;EAAC;EAAK;EAAK;EAAK;EAAK;CAAI;AAEzD,IAAMC,oBAAN,MAAMA;EAtBb,OAsBaA;;;EACFC,OAAO;EACCC;EACAC;EACAC;EACAC;EAEjB,YAAYC,MAAgC;AAC1C,SAAKJ,SAAS,IAAIK,OAAOC,OAAOF,KAAKG,YAAYH,KAAKI,SAAS;AAC/D,SAAKP,OAAOG,KAAKH;AACjB,SAAKC,aAAaE,KAAKF,cAAc;AACrC,SAAKC,cAAcC,KAAKD,eAAe;EACzC;EAEA,MAAMM,KAAKC,QAA+C;AACxD,UAAMC,sBAAsB,KAAKV,KAAKW,WAAW,IAAA;AACjD,QAAIC,UAAU;AACd,QAAIC;AACJ,WAAOD,WAAW,KAAKX,YAAY;AACjC,UAAI;AACF,cAAMa,UAAU,MAAM,KAAKf,OAAOgB,SAASC,OAAO;UAChDC,IAAIR,OAAOQ;UACXC,MAAMT,OAAOS;UACb,GAAIR,sBACA;YAAES,qBAAqB,KAAKnB;UAAK,IACjC;YAAEA,MAAM,KAAKA;UAAK;QACxB,CAAA;AACA,eAAO;UAAEoB,mBAAmBN,QAAQO;UAAKC,UAAU,KAAKxB;QAAK;MAC/D,SAASyB,KAAK;AACZV,kBAAUU;AACV,cAAMC,SAAUD,IAA4BC;AAC5C,YAAIA,UAAU,CAAC7B,uBAAuB8B,IAAID,MAAAA,EAAS,OAAMD;AACzD,YAAIX,YAAY,KAAKX,WAAY;AACjC,cAAM,KAAKyB,MAAM,KAAKxB,cAAc,KAAKU,OAAAA;AACzCA;MACF;IACF;AACA,UAAMC;EACR;EAEQa,MAAMC,IAA2B;AACvC,WAAO,IAAIC,QAAQ,CAACC,MAAMC,WAAWD,GAAGF,EAAAA,CAAAA;EAC1C;AACF;","names":["twilio","TRANSIENT_STATUS_CODES","Set","TwilioSmsProvider","name","client","from","maxRetries","retryBaseMs","opts","twilio","Twilio","accountSid","authToken","send","params","useMessagingService","startsWith","attempt","lastErr","message","messages","create","to","body","messagingServiceSid","providerMessageId","sid","provider","err","status","has","sleep","ms","Promise","r","setTimeout"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jadedm/nestjs-verify-twilio",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Twilio SMS provider adapter for @jadedm/nestjs-verify.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nestjs",
|
|
@@ -36,18 +36,18 @@
|
|
|
36
36
|
"README.md",
|
|
37
37
|
"LICENSE"
|
|
38
38
|
],
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"twilio": "^4.0.0 || ^5.0.0",
|
|
41
|
+
"@jadedm/nestjs-verify": "^0.6.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"twilio": "^5.0.0",
|
|
45
|
+
"@jadedm/nestjs-verify": "0.6.0"
|
|
46
|
+
},
|
|
39
47
|
"scripts": {
|
|
40
48
|
"build": "tsup",
|
|
41
49
|
"typecheck": "tsc --noEmit",
|
|
42
50
|
"test": "vitest run --passWithNoTests",
|
|
43
51
|
"clean": "rm -rf dist"
|
|
44
|
-
},
|
|
45
|
-
"peerDependencies": {
|
|
46
|
-
"@jadedm/nestjs-verify": "workspace:^",
|
|
47
|
-
"twilio": "^4.0.0 || ^5.0.0"
|
|
48
|
-
},
|
|
49
|
-
"devDependencies": {
|
|
50
|
-
"@jadedm/nestjs-verify": "workspace:*",
|
|
51
|
-
"twilio": "^5.0.0"
|
|
52
52
|
}
|
|
53
|
-
}
|
|
53
|
+
}
|