@abwaters/cicd-plugin-twilio 1.0.0
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/README.md +68 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +174 -0
- package/dist/index.js.map +1 -0
- package/dist/schema.d.ts +18 -0
- package/dist/schema.js +22 -0
- package/dist/schema.js.map +1 -0
- package/dist/twilio-sdk.d.ts +6 -0
- package/dist/twilio-sdk.js +60 -0
- package/dist/twilio-sdk.js.map +1 -0
- package/dist/types.d.ts +27 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bryan Waters
|
|
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/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# @abwaters/cicd-plugin-twilio
|
|
2
|
+
|
|
3
|
+
[](https://github.com/abwaters/cicd-plugin-twilio/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/abwaters/cicd-plugin-twilio/blob/main/package.json)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
Twilio webhook plugin for [`@abwaters/cicd`](https://github.com/abwaters/cicd).
|
|
8
|
+
|
|
9
|
+
During `deploy` and `rollback`, this plugin points a Twilio phone number's SMS webhook (or a messaging service's inbound webhook) at the deployed API Gateway URL for the stage. During `info --verbose`, it reports the current webhook configuration.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @abwaters/cicd-plugin-twilio
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The package is published to both the public **npm registry** and **GitHub Packages**.
|
|
18
|
+
|
|
19
|
+
Installing from npm works with no extra configuration. To install from GitHub Packages instead, point the `@abwaters` scope at it in your `~/.npmrc` (or project `.npmrc`):
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
@abwaters:registry=https://npm.pkg.github.com
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Then add it to your `cicd.json`:
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"plugins": ["@abwaters/cicd-plugin-twilio"],
|
|
30
|
+
"stages": [
|
|
31
|
+
{
|
|
32
|
+
"stage": "prod",
|
|
33
|
+
"mapping": { "domain": "api.example.com", "path": "" },
|
|
34
|
+
"twilio": {
|
|
35
|
+
"messagingSid": "MGxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
|
36
|
+
"smsWebhookApi": "myapp-sms-api"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`messagingSid` accepts a Twilio phone number SID (`PN...`) or a messaging service SID (`MG...`), and supports the standard `!ImportValue`, `!ParameterStore`, and `!SetEnv` prefixes for runtime resolution.
|
|
44
|
+
|
|
45
|
+
`smsWebhookApi` must be the `name` of an `api` export in `cicd.json`; the plugin composes the webhook URL from that API's stage mapping.
|
|
46
|
+
|
|
47
|
+
## Credentials
|
|
48
|
+
|
|
49
|
+
Set in the environment of whoever runs `cicd deploy`:
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
TWILIO_ACCOUNT_SID=AC...
|
|
53
|
+
TWILIO_AUTH_TOKEN=...
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
If either is missing, the plugin logs a verbose-mode skip and does nothing — useful for stages that aren't using Twilio.
|
|
57
|
+
|
|
58
|
+
## CLI flags
|
|
59
|
+
|
|
60
|
+
- `--no-twilio` — skip the plugin for a single invocation, even when listed
|
|
61
|
+
- `--env`, `--api`, `--sns`, `--sqs`, `--workers`, `--web` — all auto-skip plugins (existing core behavior)
|
|
62
|
+
|
|
63
|
+
## Build
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npm install
|
|
67
|
+
npm run build
|
|
68
|
+
```
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const sdk = __importStar(require("./twilio-sdk"));
|
|
37
|
+
const schema_1 = require("./schema");
|
|
38
|
+
async function resolveSid(ctx, raw) {
|
|
39
|
+
if (raw.startsWith('!')) {
|
|
40
|
+
const resolved = await ctx.resolveVariable(raw);
|
|
41
|
+
if (!resolved)
|
|
42
|
+
return null;
|
|
43
|
+
return resolved;
|
|
44
|
+
}
|
|
45
|
+
return raw;
|
|
46
|
+
}
|
|
47
|
+
function getCreds(ctx) {
|
|
48
|
+
const accountSid = ctx.env.TWILIO_ACCOUNT_SID;
|
|
49
|
+
const authToken = ctx.env.TWILIO_AUTH_TOKEN;
|
|
50
|
+
if (!accountSid || !authToken)
|
|
51
|
+
return null;
|
|
52
|
+
return { accountSid, authToken };
|
|
53
|
+
}
|
|
54
|
+
async function deployHandler(ctx) {
|
|
55
|
+
const cfg = ctx.pluginConfig;
|
|
56
|
+
if (!cfg)
|
|
57
|
+
return null;
|
|
58
|
+
const creds = getCreds(ctx);
|
|
59
|
+
if (!creds) {
|
|
60
|
+
ctx.logger.verbose(` - Twilio credentials not found in environment, skipping`);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const apiExport = await ctx.getExport(cfg.smsWebhookApi);
|
|
64
|
+
if (!apiExport) {
|
|
65
|
+
ctx.logger.verbose(` - Twilio smsWebhookApi '${cfg.smsWebhookApi}' not found in exports, skipping`);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const mappingPath = ctx.composeMappingPath(apiExport);
|
|
69
|
+
const webhookUrl = 'https://' + ctx.stageConfig.mapping.domain + (mappingPath ? '/' + mappingPath : '');
|
|
70
|
+
const sid = await resolveSid(ctx, cfg.messagingSid);
|
|
71
|
+
if (!sid) {
|
|
72
|
+
ctx.logger.verbose(` - Could not resolve Twilio messagingSid, skipping`);
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const isMessagingService = sdk.isMessagingServiceSid(sid);
|
|
76
|
+
if (ctx.dryRun) {
|
|
77
|
+
const type = isMessagingService ? 'messaging service' : 'phone number';
|
|
78
|
+
ctx.logger.verbose(` - WOULD update Twilio ${type} ${sid} webhook to ${webhookUrl}`);
|
|
79
|
+
return {
|
|
80
|
+
summaryLines: [`\nTwilio:`, ` ${sid.padEnd(40)} ${webhookUrl}`],
|
|
81
|
+
summaryParts: ['Twilio webhook updated'],
|
|
82
|
+
raw: { messagingSid: sid, webhookUrl, action: 'updated' },
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (isMessagingService) {
|
|
86
|
+
ctx.logger.verbose(`\n * Updating Twilio messaging service webhook:`);
|
|
87
|
+
ctx.logger.verbose(` - messaging service SID: ${sid}`);
|
|
88
|
+
ctx.logger.verbose(` - webhook URL: ${webhookUrl}`);
|
|
89
|
+
const result = await sdk.updateMessagingServiceWebhook(creds.accountSid, creds.authToken, sid, webhookUrl);
|
|
90
|
+
ctx.logger.verbose(` - updated ${result.friendlyName} → ${result.inboundRequestUrl}`);
|
|
91
|
+
return {
|
|
92
|
+
summaryLines: [`\nTwilio:`, ` ${sid.padEnd(40)} ${result.inboundRequestUrl}`],
|
|
93
|
+
summaryParts: ['Twilio webhook updated'],
|
|
94
|
+
raw: {
|
|
95
|
+
messagingSid: sid,
|
|
96
|
+
friendlyName: result.friendlyName,
|
|
97
|
+
webhookUrl: result.inboundRequestUrl,
|
|
98
|
+
action: 'updated',
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
ctx.logger.verbose(`\n * Updating Twilio phone number webhook:`);
|
|
104
|
+
ctx.logger.verbose(` - phone number SID: ${sid}`);
|
|
105
|
+
ctx.logger.verbose(` - webhook URL: ${webhookUrl}`);
|
|
106
|
+
const result = await sdk.updatePhoneNumberWebhook(creds.accountSid, creds.authToken, sid, webhookUrl);
|
|
107
|
+
ctx.logger.verbose(` - updated ${result.phoneNumber} → ${result.smsUrl}`);
|
|
108
|
+
return {
|
|
109
|
+
summaryLines: [`\nTwilio:`, ` ${sid.padEnd(40)} ${result.smsUrl}`],
|
|
110
|
+
summaryParts: ['Twilio webhook updated'],
|
|
111
|
+
raw: {
|
|
112
|
+
messagingSid: sid,
|
|
113
|
+
phoneNumber: result.phoneNumber,
|
|
114
|
+
webhookUrl: result.smsUrl,
|
|
115
|
+
action: 'updated',
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async function infoHandler(ctx) {
|
|
121
|
+
const creds = getCreds(ctx);
|
|
122
|
+
if (!creds)
|
|
123
|
+
return null;
|
|
124
|
+
const rows = [];
|
|
125
|
+
for (const stage of ctx.stages) {
|
|
126
|
+
const cfg = stage.twilio;
|
|
127
|
+
if (!cfg)
|
|
128
|
+
continue;
|
|
129
|
+
const sid = await resolveSid(ctx, cfg.messagingSid);
|
|
130
|
+
if (!sid) {
|
|
131
|
+
ctx.logger.verbose(` - Could not resolve Twilio messagingSid for stage ${stage.stage}, skipping`);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (sdk.isMessagingServiceSid(sid)) {
|
|
135
|
+
try {
|
|
136
|
+
const svc = await sdk.getMessagingService(creds.accountSid, creds.authToken, sid);
|
|
137
|
+
rows.push({ stage: stage.stage, label: svc.friendlyName, webhookUrl: svc.inboundRequestUrl || 'not set', type: 'messaging-service' });
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
ctx.logger.verbose(` - Error fetching messaging service ${sid}: ${e.message}`);
|
|
141
|
+
rows.push({ stage: stage.stage, label: sid, webhookUrl: `error: ${e.message}`, type: 'messaging-service' });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
try {
|
|
146
|
+
const phone = await sdk.getPhoneNumber(creds.accountSid, creds.authToken, sid);
|
|
147
|
+
rows.push({ stage: stage.stage, label: phone.phoneNumber, webhookUrl: phone.smsUrl, type: 'phone-number' });
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
ctx.logger.verbose(` - Error fetching phone number ${sid}: ${e.message}`);
|
|
151
|
+
rows.push({ stage: stage.stage, label: sid, webhookUrl: `error: ${e.message}`, type: 'phone-number' });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (rows.length === 0)
|
|
156
|
+
return null;
|
|
157
|
+
const labelWidth = Math.max(0, ...rows.map(r => r.label.length));
|
|
158
|
+
const lines = [`\nTwilio:`];
|
|
159
|
+
for (const r of rows) {
|
|
160
|
+
const typeTag = r.type === 'messaging-service' ? '[svc] ' : '[num] ';
|
|
161
|
+
lines.push(` ${r.stage.padEnd(15)} ${typeTag}${r.label.padEnd(labelWidth)} ${r.webhookUrl}`);
|
|
162
|
+
}
|
|
163
|
+
return { summaryLines: lines, summaryParts: [], raw: rows };
|
|
164
|
+
}
|
|
165
|
+
const plugin = {
|
|
166
|
+
name: 'twilio',
|
|
167
|
+
scopeFlag: 'noTwilio',
|
|
168
|
+
stageSchema: schema_1.stageSchema,
|
|
169
|
+
deploy: deployHandler,
|
|
170
|
+
rollback: deployHandler,
|
|
171
|
+
info: infoHandler,
|
|
172
|
+
};
|
|
173
|
+
exports.default = plugin;
|
|
174
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,kDAAoC;AACpC,qCAAuC;AAGvC,KAAK,UAAU,UAAU,CAAC,GAAsC,EAAE,GAAW;IACzE,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QAChD,IAAI,CAAC,QAAQ;YAAE,OAAO,IAAI,CAAC;QAC3B,OAAO,QAAQ,CAAC;IACpB,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AAED,SAAS,QAAQ,CAAC,GAAsC;IACpD,MAAM,UAAU,GAAG,GAAG,CAAC,GAAG,CAAC,kBAAkB,CAAC;IAC9C,MAAM,SAAS,GAAG,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC;IAC5C,IAAI,CAAC,UAAU,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAC3C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;AACrC,CAAC;AAED,KAAK,UAAU,aAAa,CAAC,GAAkB;IAC3C,MAAM,GAAG,GAAG,GAAG,CAAC,YAA6C,CAAC;IAC9D,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAC;IAEtB,MAAM,KAAK,GAAG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: string[];
|
|
5
|
+
properties: {
|
|
6
|
+
messagingSid: {
|
|
7
|
+
type: string;
|
|
8
|
+
description: string;
|
|
9
|
+
pattern: string;
|
|
10
|
+
};
|
|
11
|
+
smsWebhookApi: {
|
|
12
|
+
type: string;
|
|
13
|
+
description: string;
|
|
14
|
+
minLength: number;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
additionalProperties: boolean;
|
|
18
|
+
};
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stageSchema = void 0;
|
|
4
|
+
exports.stageSchema = {
|
|
5
|
+
type: 'object',
|
|
6
|
+
description: 'Twilio webhook configuration for this stage. Accepts a phone number SID (PNxxxxxxxx) or messaging service SID (MGxxxxxxxx).',
|
|
7
|
+
required: ['messagingSid', 'smsWebhookApi'],
|
|
8
|
+
properties: {
|
|
9
|
+
messagingSid: {
|
|
10
|
+
type: 'string',
|
|
11
|
+
description: 'Twilio phone number SID (PNxxxxxxxx) or messaging service SID (MGxxxxxxxx). Supports !ImportValue, !ParameterStore, !SetEnv.',
|
|
12
|
+
pattern: '^(PN|MG)[a-f0-9]{32}$|^!',
|
|
13
|
+
},
|
|
14
|
+
smsWebhookApi: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
description: 'Name of the API export to use for building the SMS webhook URL',
|
|
17
|
+
minLength: 1,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
additionalProperties: false,
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG;IACvB,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,6HAA6H;IAC1I,QAAQ,EAAE,CAAC,cAAc,EAAE,eAAe,CAAC;IAC3C,UAAU,EAAE;QACR,YAAY,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,8HAA8H;YAC3I,OAAO,EAAE,0BAA0B;SACtC;QACD,aAAa,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,gEAAgE;YAC7E,SAAS,EAAE,CAAC;SACf;KACJ;IACD,oBAAoB,EAAE,KAAK;CAC9B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TwilioPhoneResult, TwilioPhoneInfo, TwilioMessagingResult, TwilioMessagingInfo } from './types';
|
|
2
|
+
export declare function updatePhoneNumberWebhook(accountSid: string, authToken: string, phoneNumberSid: string, smsUrl: string): Promise<TwilioPhoneResult>;
|
|
3
|
+
export declare function getPhoneNumber(accountSid: string, authToken: string, phoneNumberSid: string): Promise<TwilioPhoneInfo>;
|
|
4
|
+
export declare function updateMessagingServiceWebhook(accountSid: string, authToken: string, messagingServiceSid: string, inboundRequestUrl: string): Promise<TwilioMessagingResult>;
|
|
5
|
+
export declare function getMessagingService(accountSid: string, authToken: string, messagingServiceSid: string): Promise<TwilioMessagingInfo>;
|
|
6
|
+
export declare function isMessagingServiceSid(sid: string): boolean;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.updatePhoneNumberWebhook = updatePhoneNumberWebhook;
|
|
7
|
+
exports.getPhoneNumber = getPhoneNumber;
|
|
8
|
+
exports.updateMessagingServiceWebhook = updateMessagingServiceWebhook;
|
|
9
|
+
exports.getMessagingService = getMessagingService;
|
|
10
|
+
exports.isMessagingServiceSid = isMessagingServiceSid;
|
|
11
|
+
const twilio_1 = __importDefault(require("twilio"));
|
|
12
|
+
async function updatePhoneNumberWebhook(accountSid, authToken, phoneNumberSid, smsUrl) {
|
|
13
|
+
const client = (0, twilio_1.default)(accountSid, authToken);
|
|
14
|
+
const result = await client.incomingPhoneNumbers(phoneNumberSid).update({
|
|
15
|
+
smsUrl,
|
|
16
|
+
smsMethod: 'POST'
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
sid: result.sid,
|
|
20
|
+
phoneNumber: result.phoneNumber,
|
|
21
|
+
smsUrl: result.smsUrl
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async function getPhoneNumber(accountSid, authToken, phoneNumberSid) {
|
|
25
|
+
const client = (0, twilio_1.default)(accountSid, authToken);
|
|
26
|
+
const result = await client.incomingPhoneNumbers(phoneNumberSid).fetch();
|
|
27
|
+
return {
|
|
28
|
+
sid: result.sid,
|
|
29
|
+
phoneNumber: result.phoneNumber,
|
|
30
|
+
friendlyName: result.friendlyName,
|
|
31
|
+
smsUrl: result.smsUrl,
|
|
32
|
+
smsMethod: result.smsMethod
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async function updateMessagingServiceWebhook(accountSid, authToken, messagingServiceSid, inboundRequestUrl) {
|
|
36
|
+
const client = (0, twilio_1.default)(accountSid, authToken);
|
|
37
|
+
const result = await client.messaging.v1.services(messagingServiceSid).update({
|
|
38
|
+
inboundRequestUrl,
|
|
39
|
+
inboundMethod: 'POST'
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
sid: result.sid,
|
|
43
|
+
friendlyName: result.friendlyName,
|
|
44
|
+
inboundRequestUrl: result.inboundRequestUrl
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
async function getMessagingService(accountSid, authToken, messagingServiceSid) {
|
|
48
|
+
const client = (0, twilio_1.default)(accountSid, authToken);
|
|
49
|
+
const result = await client.messaging.v1.services(messagingServiceSid).fetch();
|
|
50
|
+
return {
|
|
51
|
+
sid: result.sid,
|
|
52
|
+
friendlyName: result.friendlyName,
|
|
53
|
+
inboundRequestUrl: result.inboundRequestUrl,
|
|
54
|
+
inboundMethod: result.inboundMethod
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function isMessagingServiceSid(sid) {
|
|
58
|
+
return !!sid && sid.startsWith('MG');
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=twilio-sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"twilio-sdk.js","sourceRoot":"","sources":["../src/twilio-sdk.ts"],"names":[],"mappings":";;;;;AAQA,4DAWC;AAED,wCAUC;AAED,sEAWC;AAED,kDASC;AAED,sDAEC;AA3DD,oDAA4B;AAQrB,KAAK,UAAU,wBAAwB,CAAC,UAAkB,EAAE,SAAiB,EAAE,cAAsB,EAAE,MAAc;IACxH,MAAM,MAAM,GAAG,IAAA,gBAAM,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IAC7C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC;QACpE,MAAM;QACN,SAAS,EAAE,MAAM;KACpB,CAAC,CAAC;IACH,OAAO;QACH,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,MAAM,EAAE,MAAM,CAAC,MAAM;KACxB,CAAC;AACN,CAAC;AAEM,KAAK,UAAU,cAAc,CAAC,UAAkB,EAAE,SAAiB,EAAE,cAAsB;IAC9F,MAAM,MAAM,GAAG,IAAA,gBAAM,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IAC7C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC,KAAK,EAAE,CAAC;IACzE,OAAO;QACH,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,SAAS,EAAE,MAAM,CAAC,SAAS;KAC9B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
|
6
|
+
sid: string;
|
|
7
|
+
phoneNumber: string;
|
|
8
|
+
smsUrl: string;
|
|
9
|
+
}
|
|
10
|
+
export interface TwilioPhoneInfo {
|
|
11
|
+
sid: string;
|
|
12
|
+
phoneNumber: string;
|
|
13
|
+
friendlyName: string;
|
|
14
|
+
smsUrl: string;
|
|
15
|
+
smsMethod: string;
|
|
16
|
+
}
|
|
17
|
+
export interface TwilioMessagingResult {
|
|
18
|
+
sid: string;
|
|
19
|
+
friendlyName: string;
|
|
20
|
+
inboundRequestUrl: string;
|
|
21
|
+
}
|
|
22
|
+
export interface TwilioMessagingInfo {
|
|
23
|
+
sid: string;
|
|
24
|
+
friendlyName: string;
|
|
25
|
+
inboundRequestUrl: string;
|
|
26
|
+
inboundMethod: string;
|
|
27
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@abwaters/cicd-plugin-twilio",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Twilio webhook plugin for @abwaters/cicd — keeps phone-number/messaging-service SMS webhooks pointed at the deployed API stage",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/abwaters/cicd-plugin-twilio.git"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"prepublishOnly": "npm run build"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@abwaters/cicd": "^1.0.0"
|
|
25
|
+
},
|
|
26
|
+
"peerDependenciesMeta": {
|
|
27
|
+
"@abwaters/cicd": {
|
|
28
|
+
"optional": true
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"twilio": "^6.0.2"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@abwaters/cicd": "^1.1.0",
|
|
36
|
+
"@types/node": "^25.9.0",
|
|
37
|
+
"typescript": "^6.0.3"
|
|
38
|
+
}
|
|
39
|
+
}
|