@superdurable/connector-twilio-messaging 0.0.0-stage → 0.1.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 +49 -2
- package/dex-connector.json +82 -0
- package/dist/chunk-RO6VVVPT.js +145 -0
- package/dist/connection-DU3WOoJL.d.ts +140 -0
- package/dist/index.d.ts +155 -0
- package/dist/index.js +548 -0
- package/dist/mock.d.ts +60 -0
- package/dist/mock.js +137 -0
- package/package.json +60 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Super Durable
|
|
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
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Twilio Messaging TypeScript connector
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@superdurable/connector-twilio-messaging` provides the `sendMessage` Mutation
|
|
4
|
+
and `getMessage` Query for Dex TypeScript applications. The package ships
|
|
5
|
+
manifest-generated contracts and Step factories; `src/client.ts` and
|
|
6
|
+
`src/operations.ts` implement the Twilio Messages HTTP behavior.
|
|
7
|
+
|
|
8
|
+
Install with `npm install @superdurable/connector-twilio-messaging@0.1.0`.
|
|
9
|
+
Use Node.js 22 or 24 and the released Connector SDK version in `package.json`.
|
|
10
|
+
|
|
11
|
+
## Connection
|
|
12
|
+
|
|
13
|
+
Create a Twilio account or subaccount in the [Twilio Console](https://console.twilio.com/).
|
|
14
|
+
In Dex Web **Connections**, set `accountSid` to the account's `AC` SID from
|
|
15
|
+
**Account Dashboard > Account Info**. Choose `auth-token` and save the secret
|
|
16
|
+
`auth_token` from that panel, or choose `api-key` and save `api_key_sid` and
|
|
17
|
+
secret `api_key_secret` from **Account > API keys & tokens**. The key must
|
|
18
|
+
belong to the same account and Region. `defaultSender` can be an E.164 number,
|
|
19
|
+
`whatsapp:` number, or Messaging Service `MG` SID; blank requires `sender` on
|
|
20
|
+
each request. Leave `endpoint` and `maxResponseBytes` blank for their manifest
|
|
21
|
+
defaults. Secrets are resolved for every call and never belong in Flow input.
|
|
22
|
+
Stored credentials without `auth_method` use `auth-token`; a rejected static
|
|
23
|
+
credential requires updating the connection rather than an automatic refresh.
|
|
24
|
+
|
|
25
|
+
The runnable [text-message-delivery example](examples/text-message-delivery/README.md)
|
|
26
|
+
uses `newProjectConnection(project, ConnectionName)` and the generated
|
|
27
|
+
`newSendMessageStep` and `newGetMessageStep`. Its static connection name is
|
|
28
|
+
`twilio-messaging`.
|
|
29
|
+
|
|
30
|
+
## Behavior
|
|
31
|
+
|
|
32
|
+
`sendMessage` sends `To`, an optional body, ordered media URLs, and either
|
|
33
|
+
`From` or `MessagingServiceSid`. Form values use Go-compatible query escaping,
|
|
34
|
+
including `%2A` for `*` and an unescaped `~`. Twilio has no Messages create idempotency key.
|
|
35
|
+
The SDK fence records a heartbeat before dispatch and permits a resend only
|
|
36
|
+
after proof of no send or Twilio's 429 or 503 response. A valid 2xx Message
|
|
37
|
+
selects `accepted`; a conclusive 4xx selects `providerRejected`; an ambiguous
|
|
38
|
+
transport or response selects uncertainty. `getMessage` reads a Message SID,
|
|
39
|
+
retries transport, 408, 429, and 5xx failures, and selects `found`, `notFound`,
|
|
40
|
+
`providerRejected`, or `invalidResponse` for final results. Unwired optional
|
|
41
|
+
branches fail the Flow.
|
|
42
|
+
|
|
43
|
+
Outputs contain only Twilio's safe message metadata. The body, media URLs,
|
|
44
|
+
credential values, and provider error prose are excluded. Status and request
|
|
45
|
+
count behavior is replayed against Go recordings in
|
|
46
|
+
`conformance/connectors/twilio/messaging/scenarios.json`.
|
|
47
|
+
|
|
48
|
+
Run `npm ci && npm run check` in this directory. The example's Dex Worker and
|
|
49
|
+
Client integration check needs `dexcli dev` and `DEX_FLOW_SERVICE_ADDRESS`.
|
|
50
|
+
Live Twilio authorization, message creation, and delivery were not verified.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"connectorId": "twilio-messaging",
|
|
3
|
+
"releaseTag": "connectors/twilio/messaging/go/v0.23.0",
|
|
4
|
+
"package": {
|
|
5
|
+
"ecosystem": "npm",
|
|
6
|
+
"name": "@superdurable/connector-twilio-messaging",
|
|
7
|
+
"version": "0.1.0"
|
|
8
|
+
},
|
|
9
|
+
"factories": [
|
|
10
|
+
{
|
|
11
|
+
"name": "newSendMessageStep",
|
|
12
|
+
"kind": "mutation",
|
|
13
|
+
"operationId": "sendMessage",
|
|
14
|
+
"fields": {
|
|
15
|
+
"stepType": "stepType",
|
|
16
|
+
"annotations": "annotations",
|
|
17
|
+
"connectionName": "connectionName",
|
|
18
|
+
"resultAttribute": "resultAttribute"
|
|
19
|
+
},
|
|
20
|
+
"branches": [
|
|
21
|
+
{
|
|
22
|
+
"id": "accepted",
|
|
23
|
+
"field": "accepted",
|
|
24
|
+
"optional": false
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"id": "providerRejected",
|
|
28
|
+
"field": "providerRejected",
|
|
29
|
+
"optional": true
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"id": "uncertain",
|
|
33
|
+
"field": "uncertain",
|
|
34
|
+
"optional": true
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"id": "defect",
|
|
38
|
+
"field": "defect",
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": "newGetMessageStep",
|
|
45
|
+
"kind": "query",
|
|
46
|
+
"operationId": "getMessage",
|
|
47
|
+
"fields": {
|
|
48
|
+
"stepType": "stepType",
|
|
49
|
+
"annotations": "annotations",
|
|
50
|
+
"connectionName": "connectionName",
|
|
51
|
+
"resultAttribute": "resultAttribute"
|
|
52
|
+
},
|
|
53
|
+
"branches": [
|
|
54
|
+
{
|
|
55
|
+
"id": "found",
|
|
56
|
+
"field": "found",
|
|
57
|
+
"optional": false
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"id": "notFound",
|
|
61
|
+
"field": "notFound",
|
|
62
|
+
"optional": true
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"id": "providerRejected",
|
|
66
|
+
"field": "providerRejected",
|
|
67
|
+
"optional": true
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"id": "invalidResponse",
|
|
71
|
+
"field": "invalidResponse",
|
|
72
|
+
"optional": true
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"id": "defect",
|
|
76
|
+
"field": "defect",
|
|
77
|
+
"optional": true
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// src/generated/definitions.ts
|
|
2
|
+
var ConnectorID = "twilio-messaging";
|
|
3
|
+
var ProviderID = "twilio";
|
|
4
|
+
var SendMessageBranch = {
|
|
5
|
+
Accepted: "accepted",
|
|
6
|
+
ProviderRejected: "providerRejected",
|
|
7
|
+
Uncertain: "uncertain",
|
|
8
|
+
Defect: "defect"
|
|
9
|
+
};
|
|
10
|
+
var SendMessageBranchAccepted = SendMessageBranch.Accepted;
|
|
11
|
+
var SendMessageBranchProviderRejected = SendMessageBranch.ProviderRejected;
|
|
12
|
+
var SendMessageBranchUncertain = SendMessageBranch.Uncertain;
|
|
13
|
+
var SendMessageBranchDefect = SendMessageBranch.Defect;
|
|
14
|
+
var SendMessageDefinition = {
|
|
15
|
+
operation: { connectorId: ConnectorID, operationId: "sendMessage" },
|
|
16
|
+
branches: [
|
|
17
|
+
{ id: "accepted", description: "Twilio created the message and returned its SID; delivery status arrives later through getMessage." },
|
|
18
|
+
{ id: "providerRejected", description: "Twilio conclusively rejected the message, such as an invalid To number, an unverified trial recipient, an unsubscribed recipient, or an unusable sender; nothing was sent.", optional: true },
|
|
19
|
+
{ id: "uncertain", description: "The request was dispatched but its outcome cannot be confirmed; Twilio has no idempotency key, so the message may exist and must not be resent automatically.", optional: true },
|
|
20
|
+
{ id: "defect", description: "Local input, connection configuration, or connector definition is invalid.", optional: true }
|
|
21
|
+
],
|
|
22
|
+
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "sync", executeRetry: { initialIntervalMs: 1e3, backoffCoefficient: 2, maximumIntervalMs: 3e4, maximumAttempts: 5, totalDurationMs: 12e4 } }
|
|
23
|
+
};
|
|
24
|
+
var GetMessageBranch = {
|
|
25
|
+
Found: "found",
|
|
26
|
+
NotFound: "notFound",
|
|
27
|
+
ProviderRejected: "providerRejected",
|
|
28
|
+
InvalidResponse: "invalidResponse",
|
|
29
|
+
Defect: "defect"
|
|
30
|
+
};
|
|
31
|
+
var GetMessageBranchFound = GetMessageBranch.Found;
|
|
32
|
+
var GetMessageBranchNotFound = GetMessageBranch.NotFound;
|
|
33
|
+
var GetMessageBranchProviderRejected = GetMessageBranch.ProviderRejected;
|
|
34
|
+
var GetMessageBranchInvalidResponse = GetMessageBranch.InvalidResponse;
|
|
35
|
+
var GetMessageBranchDefect = GetMessageBranch.Defect;
|
|
36
|
+
var GetMessageDefinition = {
|
|
37
|
+
operation: { connectorId: ConnectorID, operationId: "getMessage" },
|
|
38
|
+
branches: [
|
|
39
|
+
{ id: "found", description: "The message exists and its current status was read." },
|
|
40
|
+
{ id: "notFound", description: "The account has no message with that SID.", optional: true },
|
|
41
|
+
{ id: "providerRejected", description: "Twilio conclusively rejected the message query.", optional: true },
|
|
42
|
+
{ id: "invalidResponse", description: "Twilio returned an invalid or oversized message response.", optional: true },
|
|
43
|
+
{ id: "defect", description: "Local input, connection configuration, or connector definition is invalid.", optional: true }
|
|
44
|
+
],
|
|
45
|
+
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/generated/models.ts
|
|
49
|
+
import { z } from "zod";
|
|
50
|
+
import { SecretString } from "@superdurable/connectors-sdk";
|
|
51
|
+
var ConfigSchema = z.object({
|
|
52
|
+
"accountSid": z.string(),
|
|
53
|
+
"defaultSender": z.string().optional(),
|
|
54
|
+
"endpoint": z.string().optional(),
|
|
55
|
+
"maxResponseBytes": z.number().int().optional()
|
|
56
|
+
});
|
|
57
|
+
function decodeCredentials(value) {
|
|
58
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new TypeError("credential fields are invalid");
|
|
59
|
+
const fields = value;
|
|
60
|
+
const selectedMethod = fields["auth_method"] ?? "";
|
|
61
|
+
if (typeof selectedMethod !== "string") throw new TypeError("credential auth_method is invalid");
|
|
62
|
+
const method = selectedMethod || "auth-token";
|
|
63
|
+
const credentials = { authMethodId: method };
|
|
64
|
+
if (method === "auth-token") {
|
|
65
|
+
if (fields["auth_token"] != null && typeof fields["auth_token"] !== "string") throw new TypeError("credential auth_token has an invalid type");
|
|
66
|
+
if (!fields["auth_token"]) throw new TypeError("credential auth_token is required");
|
|
67
|
+
if (fields["auth_token"]) credentials.authToken = new SecretString(fields["auth_token"]);
|
|
68
|
+
} else if (method === "api-key") {
|
|
69
|
+
if (fields["api_key_sid"] != null && typeof fields["api_key_sid"] !== "string") throw new TypeError("credential api_key_sid has an invalid type");
|
|
70
|
+
if (!fields["api_key_sid"]) throw new TypeError("credential api_key_sid is required");
|
|
71
|
+
if (fields["api_key_sid"]) credentials.apiKeySid = fields["api_key_sid"];
|
|
72
|
+
if (fields["api_key_secret"] != null && typeof fields["api_key_secret"] !== "string") throw new TypeError("credential api_key_secret has an invalid type");
|
|
73
|
+
if (!fields["api_key_secret"]) throw new TypeError("credential api_key_secret is required");
|
|
74
|
+
if (fields["api_key_secret"]) credentials.apiKeySecret = new SecretString(fields["api_key_secret"]);
|
|
75
|
+
} else {
|
|
76
|
+
throw new TypeError("credential auth_method is invalid");
|
|
77
|
+
}
|
|
78
|
+
return credentials;
|
|
79
|
+
}
|
|
80
|
+
var SendMessageInputSchema = z.strictObject({
|
|
81
|
+
"to": z.string(),
|
|
82
|
+
"body": z.string().optional(),
|
|
83
|
+
"mediaUrls": z.array(z.string()).optional(),
|
|
84
|
+
"sender": z.string().optional()
|
|
85
|
+
});
|
|
86
|
+
var MessageSchema = z.strictObject({
|
|
87
|
+
"sid": z.string().optional(),
|
|
88
|
+
"accountSid": z.string(),
|
|
89
|
+
"messagingServiceSid": z.string().optional(),
|
|
90
|
+
"from": z.string().optional(),
|
|
91
|
+
"to": z.string(),
|
|
92
|
+
"status": z.string().optional(),
|
|
93
|
+
"direction": z.string().optional(),
|
|
94
|
+
"errorCode": z.number().int().optional(),
|
|
95
|
+
"segmentCount": z.number().int().optional(),
|
|
96
|
+
"mediaCount": z.number().int().optional(),
|
|
97
|
+
"price": z.string().optional(),
|
|
98
|
+
"priceUnit": z.string().optional(),
|
|
99
|
+
"createdAt": z.iso.datetime({ offset: true }),
|
|
100
|
+
"sentAt": z.iso.datetime({ offset: true }),
|
|
101
|
+
"updatedAt": z.iso.datetime({ offset: true })
|
|
102
|
+
});
|
|
103
|
+
var GetMessageInputSchema = z.strictObject({
|
|
104
|
+
"messageSid": z.string()
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// src/generated/connection.ts
|
|
108
|
+
import { ConnectionRefSchema } from "@superdurable/connectors-sdk";
|
|
109
|
+
var Connection = class {
|
|
110
|
+
/** Stable provider and connection name. */
|
|
111
|
+
reference;
|
|
112
|
+
/** Bound provider operations. */
|
|
113
|
+
operations;
|
|
114
|
+
/** Validate a reference and bind operations. */
|
|
115
|
+
constructor(reference, operations) {
|
|
116
|
+
this.reference = ConnectionRefSchema.parse(reference);
|
|
117
|
+
if (this.reference.provider !== ProviderID) throw new TypeError("connection provider differs from the manifest");
|
|
118
|
+
if (!operations) throw new TypeError("connector operations are required");
|
|
119
|
+
this.operations = operations;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
function newConnection(client, reference) {
|
|
123
|
+
if (!client) throw new TypeError("connector client is required");
|
|
124
|
+
return new Connection(reference, client);
|
|
125
|
+
}
|
|
126
|
+
function newConnectionWithOperations(operations, reference) {
|
|
127
|
+
return new Connection(reference, operations);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export {
|
|
131
|
+
ConnectorID,
|
|
132
|
+
ProviderID,
|
|
133
|
+
SendMessageBranch,
|
|
134
|
+
SendMessageDefinition,
|
|
135
|
+
GetMessageBranch,
|
|
136
|
+
GetMessageDefinition,
|
|
137
|
+
ConfigSchema,
|
|
138
|
+
decodeCredentials,
|
|
139
|
+
SendMessageInputSchema,
|
|
140
|
+
MessageSchema,
|
|
141
|
+
GetMessageInputSchema,
|
|
142
|
+
Connection,
|
|
143
|
+
newConnection,
|
|
144
|
+
newConnectionWithOperations
|
|
145
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { SecretString, Mutation, Query, ConnectionRef } from '@superdurable/connectors-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/** Connector configuration; omitted fields use manifest defaults. */
|
|
5
|
+
interface Config {
|
|
6
|
+
/** Non-secret Account SID from https://console.twilio.com > Account Dashboard > Account Info; it is AC followed by 32 hexadecimal characters and names the account or subaccount that owns the sender and every sent message. Required: both authentication methods send it in the Messages API path. */
|
|
7
|
+
accountSid: string;
|
|
8
|
+
/** Sender used when a send names none. Copy an SMS-capable number from https://console.twilio.com/us1/develop/phone-numbers/manage/incoming (Phone Numbers > Manage > Active numbers) in E.164 form such as +14155550100, a WhatsApp sender from Messaging > Senders > WhatsApp senders written whatsapp:+14155550100, or a Messaging Service SID (MG followed by 32 hexadecimal characters) from Messaging > Services; short codes and alphanumeric sender IDs need a Messaging Service. Not secret. Blank means every send must name its own sender. */
|
|
9
|
+
defaultSender?: string;
|
|
10
|
+
/** Twilio REST API base URL including the 2010-04-01 version segment; leave blank for the United States (US1) Region. Enter a regional URL such as https://api.dublin.ie1.twilio.com/2010-04-01 only when the account and its credentials were created in that Twilio Region. */
|
|
11
|
+
endpoint?: string;
|
|
12
|
+
/** Maximum complete Twilio API response in bytes. Leave blank to keep the displayed safety limit; enter a positive integer only to change it. An oversized getMessage response selects invalidResponse, and an oversized response to an accepted send selects uncertain. */
|
|
13
|
+
maxResponseBytes?: number;
|
|
14
|
+
}
|
|
15
|
+
/** Runtime schema for manifest configuration. */
|
|
16
|
+
declare const ConfigSchema: z.ZodObject<{
|
|
17
|
+
accountSid: z.ZodString;
|
|
18
|
+
defaultSender: z.ZodOptional<z.ZodString>;
|
|
19
|
+
endpoint: z.ZodOptional<z.ZodString>;
|
|
20
|
+
maxResponseBytes: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
/** Private connector credentials resolved by the host. */
|
|
23
|
+
interface Credentials {
|
|
24
|
+
/** Selected authorization method. */
|
|
25
|
+
authMethodId?: string;
|
|
26
|
+
/** Non-secret API key SID shown after Create API key at https://console.twilio.com/us1/account/keys-credentials/api-keys (Account > API keys & tokens); SK followed by 32 hexadecimal characters. The key must belong to the Account SID above and to the Twilio Region of the endpoint. It is stored with its secret, so replacing a key replaces both without an application restart. */
|
|
27
|
+
apiKeySid?: string;
|
|
28
|
+
/** Secret shown once after Create API key at https://console.twilio.com/us1/account/keys-credentials/api-keys; 32 characters. Twilio never shows it again, so create a new key when it is lost. Stored only in this credential field. */
|
|
29
|
+
apiKeySecret?: SecretString;
|
|
30
|
+
/** Secret primary Auth Token from https://console.twilio.com > Account Dashboard > Account Info > Auth Token > Show; 32 hexadecimal characters for the Account SID above. Stored only in this credential field; after a Twilio rotation, paste the new token here. */
|
|
31
|
+
authToken?: SecretString;
|
|
32
|
+
}
|
|
33
|
+
/** Decode private credential fields for the selected authorization method. */
|
|
34
|
+
declare function decodeCredentials(value: unknown): Credentials;
|
|
35
|
+
/** SendMessageInput describes one message to one recipient. */
|
|
36
|
+
interface SendMessageInput {
|
|
37
|
+
/** To is the recipient: an E.164 number such as +14155550100, or whatsapp:+14155550100. */
|
|
38
|
+
"to": string;
|
|
39
|
+
/** Body is the message text, at most 1600 characters. It may be empty only when MediaURLs is set. */
|
|
40
|
+
"body"?: string | undefined;
|
|
41
|
+
/** MediaURLs lists at most 10 public HTTPS URLs that Twilio fetches and attaches, which makes an SMS an MMS. */
|
|
42
|
+
"mediaUrls"?: Array<string> | undefined;
|
|
43
|
+
/** Sender overrides the connection's defaultSender with an E.164 number, a whatsapp: address, or
|
|
44
|
+
* an MG Messaging Service SID. Blank uses defaultSender. */
|
|
45
|
+
"sender"?: string | undefined;
|
|
46
|
+
}
|
|
47
|
+
/** Message is the connector-safe subset of a Twilio Message resource.
|
|
48
|
+
*
|
|
49
|
+
* It never contains the message body, media URLs, or Twilio's error message
|
|
50
|
+
* text. After sendMessage selects providerRejected or uncertain, SID and
|
|
51
|
+
* Status are empty and the value echoes the requested account, sender, and
|
|
52
|
+
* recipient; ErrorCode then holds the rejection's Twilio error code. */
|
|
53
|
+
interface Message {
|
|
54
|
+
/** SID is Twilio's message identifier: SM or MM followed by 32 hexadecimal characters. */
|
|
55
|
+
"sid"?: string | undefined;
|
|
56
|
+
/** AccountSID is the AC account that owns the message. */
|
|
57
|
+
"accountSid": string;
|
|
58
|
+
/** MessagingServiceSID is the MG Messaging Service that sent the message, when one was used. */
|
|
59
|
+
"messagingServiceSid"?: string | undefined;
|
|
60
|
+
/** From is the sending number, WhatsApp address, short code, or alphanumeric sender ID.
|
|
61
|
+
* It is empty until a Messaging Service chooses a sender. */
|
|
62
|
+
"from"?: string | undefined;
|
|
63
|
+
/** To is the recipient in E.164 form, or a whatsapp: address. */
|
|
64
|
+
"to": string;
|
|
65
|
+
/** Status is Twilio's delivery status. */
|
|
66
|
+
"status"?: "accepted" | "canceled" | "delivered" | "failed" | "queued" | "read" | "scheduled" | "sending" | "sent" | "undelivered" | (string & {}) | undefined;
|
|
67
|
+
/** Direction is Twilio's direction value, such as outbound-api. */
|
|
68
|
+
"direction"?: string | undefined;
|
|
69
|
+
/** ErrorCode is Twilio's numeric error code, documented at https://www.twilio.com/docs/api/errors; zero means none. */
|
|
70
|
+
"errorCode"?: number | undefined;
|
|
71
|
+
/** SegmentCount is the number of SMS segments Twilio billed or will bill. */
|
|
72
|
+
"segmentCount"?: number | undefined;
|
|
73
|
+
/** MediaCount is the number of media items attached to the message. */
|
|
74
|
+
"mediaCount"?: number | undefined;
|
|
75
|
+
/** Price is Twilio's decimal price, usually negative, once known. */
|
|
76
|
+
"price"?: string | undefined;
|
|
77
|
+
/** PriceUnit is the ISO 4217 currency of Price. */
|
|
78
|
+
"priceUnit"?: string | undefined;
|
|
79
|
+
/** CreatedAt is when Twilio created the message; zero means unknown. */
|
|
80
|
+
"createdAt": string;
|
|
81
|
+
/** SentAt is when Twilio sent the message; zero means not yet sent. */
|
|
82
|
+
"sentAt": string;
|
|
83
|
+
/** UpdatedAt is when Twilio last changed the message; zero means unknown. */
|
|
84
|
+
"updatedAt": string;
|
|
85
|
+
}
|
|
86
|
+
/** GetMessageInput identifies one message. */
|
|
87
|
+
interface GetMessageInput {
|
|
88
|
+
/** MessageSID is the SM or MM message SID returned by sendMessage. */
|
|
89
|
+
"messageSid": string;
|
|
90
|
+
}
|
|
91
|
+
/** Runtime validator for SendMessageInput. */
|
|
92
|
+
declare const SendMessageInputSchema: z.ZodObject<{
|
|
93
|
+
to: z.ZodString;
|
|
94
|
+
body: z.ZodOptional<z.ZodString>;
|
|
95
|
+
mediaUrls: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
96
|
+
sender: z.ZodOptional<z.ZodString>;
|
|
97
|
+
}, z.core.$strict>;
|
|
98
|
+
/** Runtime validator for Message. */
|
|
99
|
+
declare const MessageSchema: z.ZodObject<{
|
|
100
|
+
sid: z.ZodOptional<z.ZodString>;
|
|
101
|
+
accountSid: z.ZodString;
|
|
102
|
+
messagingServiceSid: z.ZodOptional<z.ZodString>;
|
|
103
|
+
from: z.ZodOptional<z.ZodString>;
|
|
104
|
+
to: z.ZodString;
|
|
105
|
+
status: z.ZodOptional<z.ZodString>;
|
|
106
|
+
direction: z.ZodOptional<z.ZodString>;
|
|
107
|
+
errorCode: z.ZodOptional<z.ZodNumber>;
|
|
108
|
+
segmentCount: z.ZodOptional<z.ZodNumber>;
|
|
109
|
+
mediaCount: z.ZodOptional<z.ZodNumber>;
|
|
110
|
+
price: z.ZodOptional<z.ZodString>;
|
|
111
|
+
priceUnit: z.ZodOptional<z.ZodString>;
|
|
112
|
+
createdAt: z.ZodISODateTime;
|
|
113
|
+
sentAt: z.ZodISODateTime;
|
|
114
|
+
updatedAt: z.ZodISODateTime;
|
|
115
|
+
}, z.core.$strict>;
|
|
116
|
+
/** Runtime validator for GetMessageInput. */
|
|
117
|
+
declare const GetMessageInputSchema: z.ZodObject<{
|
|
118
|
+
messageSid: z.ZodString;
|
|
119
|
+
}, z.core.$strict>;
|
|
120
|
+
|
|
121
|
+
/** Typed operations supplied by a client or mock. */
|
|
122
|
+
interface Operations {
|
|
123
|
+
/** Invoke sendMessage through this connection. */
|
|
124
|
+
sendMessage(): Mutation<SendMessageInput, Message>;
|
|
125
|
+
/** Invoke getMessage through this connection. */
|
|
126
|
+
getMessage(): Query<GetMessageInput, Message>;
|
|
127
|
+
}
|
|
128
|
+
/** Named connector connection kept outside Flow state. */
|
|
129
|
+
declare class Connection<BoundOperations = Operations> {
|
|
130
|
+
/** Stable provider and connection name. */
|
|
131
|
+
readonly reference: ConnectionRef;
|
|
132
|
+
/** Bound provider operations. */
|
|
133
|
+
readonly operations: BoundOperations;
|
|
134
|
+
/** Validate a reference and bind operations. */
|
|
135
|
+
constructor(reference: ConnectionRef, operations: BoundOperations);
|
|
136
|
+
}
|
|
137
|
+
/** Bind scripted operations to a named connection. */
|
|
138
|
+
declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
|
|
139
|
+
|
|
140
|
+
export { type Config as C, type GetMessageInput as G, type Message as M, type Operations as O, type SendMessageInput as S, type Credentials as a, Connection as b, ConfigSchema as c, GetMessageInputSchema as d, MessageSchema as e, SendMessageInputSchema as f, decodeCredentials as g, newConnectionWithOperations as n };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { ProviderRequest, ProviderResponse } from '@superdurable/connectors-sdk/providerhttp';
|
|
2
|
+
import * as _superdurable_connectors_sdk from '@superdurable/connectors-sdk';
|
|
3
|
+
import { Query, Mutation, Call, MutationAttempt, QueryAttempt, CredentialProvider, Failure, ReceiptDraft, QueryStepConfig, QueryResult, QueryStep, MutationStepConfig, MutationResult, MutationStep, QueryDefinition, MutationDefinition } from '@superdurable/connectors-sdk';
|
|
4
|
+
import { G as GetMessageInput, M as Message, S as SendMessageInput, C as Config, a as Credentials, b as Connection } from './connection-DU3WOoJL.js';
|
|
5
|
+
export { c as ConfigSchema, d as GetMessageInputSchema, e as MessageSchema, f as SendMessageInputSchema, g as decodeCredentials, n as newConnectionWithOperations } from './connection-DU3WOoJL.js';
|
|
6
|
+
import { LoadedProject } from '@superdurable/connectors-sdk/projectconfig';
|
|
7
|
+
import { StepTarget } from '@superdurable/dex';
|
|
8
|
+
import 'zod';
|
|
9
|
+
|
|
10
|
+
/** Send one Twilio message behind a durable single-dispatch fence. */
|
|
11
|
+
declare class SendMessageOperation implements Mutation<SendMessageInput, Message> {
|
|
12
|
+
private readonly client;
|
|
13
|
+
/** Bind one client. */ constructor(client: TwilioClient);
|
|
14
|
+
/** Stable manifest definition. */ definition(): _superdurable_connectors_sdk.QueryDefinition;
|
|
15
|
+
/** Receipt identity only; Twilio does not accept an idempotency header. */ idempotencyKey(callId: string): string;
|
|
16
|
+
/** Classify one fenced provider attempt. */
|
|
17
|
+
invoke(call: Call, input: SendMessageInput): Promise<MutationAttempt<Message>>;
|
|
18
|
+
}
|
|
19
|
+
/** Read one Twilio message status. */
|
|
20
|
+
declare class GetMessageOperation implements Query<GetMessageInput, Message> {
|
|
21
|
+
private readonly client;
|
|
22
|
+
/** Bind one client. */ constructor(client: TwilioClient);
|
|
23
|
+
/** Stable manifest definition. */ definition(): _superdurable_connectors_sdk.QueryDefinition;
|
|
24
|
+
/** Classify one provider read. */
|
|
25
|
+
invoke(call: Call, input: GetMessageInput): Promise<QueryAttempt<Message>>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Testable Twilio HTTP sender. */
|
|
29
|
+
type TwilioRequestSender = (request: ProviderRequest) => Promise<ProviderResponse>;
|
|
30
|
+
/** Constructor dependencies. */
|
|
31
|
+
interface TwilioClientOptions {
|
|
32
|
+
/** Provider transport. */ send?: TwilioRequestSender;
|
|
33
|
+
/** Receipt clock. */ now?: () => Date;
|
|
34
|
+
}
|
|
35
|
+
/** Complete response or a classified transport failure. */
|
|
36
|
+
type TwilioExchange = {
|
|
37
|
+
response: ProviderResponse;
|
|
38
|
+
isTooLarge: boolean;
|
|
39
|
+
isBodyReadFailed: boolean;
|
|
40
|
+
} | {
|
|
41
|
+
error: Error;
|
|
42
|
+
isProvablyNotSent: boolean;
|
|
43
|
+
};
|
|
44
|
+
/** Validated sender address or Messaging Service. */
|
|
45
|
+
interface MessageSender {
|
|
46
|
+
fromAddress: string;
|
|
47
|
+
messagingServiceSid: string;
|
|
48
|
+
}
|
|
49
|
+
/** Basic authentication material kept outside Dex state. */
|
|
50
|
+
interface TwilioAuthorization {
|
|
51
|
+
username: string;
|
|
52
|
+
password: string;
|
|
53
|
+
}
|
|
54
|
+
/** Credential lookup outcome without secret-bearing errors. */
|
|
55
|
+
type AuthorizationResult = {
|
|
56
|
+
authorization: TwilioAuthorization;
|
|
57
|
+
} | {
|
|
58
|
+
failure: Failure;
|
|
59
|
+
isTransient: boolean;
|
|
60
|
+
};
|
|
61
|
+
/** Authenticated Twilio Messages API client. */
|
|
62
|
+
declare class TwilioClient {
|
|
63
|
+
/** Account SID used in the Messages path. */ readonly accountSid: string;
|
|
64
|
+
/** Fully qualified Messages collection URL. */ readonly messagesURL: string;
|
|
65
|
+
/** Optional default sender. */ readonly defaultSender: MessageSender;
|
|
66
|
+
/** Maximum successful response size. */ readonly maxResponseBytes: number;
|
|
67
|
+
private readonly credentials;
|
|
68
|
+
private readonly send;
|
|
69
|
+
private readonly now;
|
|
70
|
+
private readonly addressPolicy;
|
|
71
|
+
/** Validate config and retain provider dependencies. */
|
|
72
|
+
constructor(config: Config, credentials: CredentialProvider<Credentials>, options?: TwilioClientOptions);
|
|
73
|
+
/** Bind the non-idempotent send mutation. */ sendMessage(): SendMessageOperation;
|
|
74
|
+
/** Bind the message status query. */ getMessage(): GetMessageOperation;
|
|
75
|
+
/** Resolve current credentials without leaking lookup errors. */
|
|
76
|
+
authorization(call: Call, operation: string): Promise<AuthorizationResult>;
|
|
77
|
+
/** Ask the credential host for a newer credential after a rejected send. */
|
|
78
|
+
authorizationAfterRejection(call: Call): Promise<AuthorizationResult>;
|
|
79
|
+
private validateAuthorization;
|
|
80
|
+
/** Send one request; only successful responses use the configured body limit. */
|
|
81
|
+
exchange(call: Call, authorization: TwilioAuthorization, method: string, url: string, form?: URLSearchParams, signal?: AbortSignal): Promise<TwilioExchange>;
|
|
82
|
+
/** Decode a safe Twilio Message subset. */
|
|
83
|
+
decodeMessage(body: Uint8Array, authorization: TwilioAuthorization): Message;
|
|
84
|
+
/** Make a safe receipt with exact provider IDs. */
|
|
85
|
+
receipt(call: Call, response?: ProviderResponse, objectId?: string, errorCode?: number): ReceiptDraft;
|
|
86
|
+
/** Current receipt time for Retry-After. */ currentTime(): Date;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Bind a validated Twilio client to a static connection. */
|
|
90
|
+
declare function newConnection(client: TwilioClient, name: string): Connection;
|
|
91
|
+
/** Build a Twilio client from one project connection and its private credentials. */
|
|
92
|
+
declare function newProjectConnection(project: LoadedProject, connectionName: string, options?: TwilioClientOptions): Connection;
|
|
93
|
+
|
|
94
|
+
/** Configuration for the sendMessage connector Step. */
|
|
95
|
+
interface SendMessageStepConfig<StepInput, OperationInput = SendMessageInput, OperationOutput = Message> extends Omit<MutationStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
|
|
96
|
+
/** Named connection supplying this operation. */
|
|
97
|
+
connection: Connection<{
|
|
98
|
+
sendMessage(): Mutation<OperationInput, OperationOutput>;
|
|
99
|
+
}>;
|
|
100
|
+
/** Name matching the bound connection. */
|
|
101
|
+
connectionName: string;
|
|
102
|
+
/** Twilio created the message and returned its SID; delivery status arrives later through getMessage. */
|
|
103
|
+
accepted: StepTarget<MutationResult<OperationOutput>>;
|
|
104
|
+
/** Twilio conclusively rejected the message, such as an invalid To number, an unverified trial recipient, an unsubscribed recipient, or an unusable sender; nothing was sent. */
|
|
105
|
+
providerRejected?: StepTarget<MutationResult<OperationOutput>>;
|
|
106
|
+
/** The request was dispatched but its outcome cannot be confirmed; Twilio has no idempotency key, so the message may exist and must not be resent automatically. */
|
|
107
|
+
uncertain?: StepTarget<MutationResult<OperationOutput>>;
|
|
108
|
+
/** Local input, connection configuration, or connector definition is invalid. */
|
|
109
|
+
defect?: StepTarget<MutationResult<OperationOutput>>;
|
|
110
|
+
}
|
|
111
|
+
/** Build the sendMessage Step from a named connection. */
|
|
112
|
+
declare function newSendMessageStep<StepInput, OperationInput = SendMessageInput, OperationOutput = Message>(configuration: SendMessageStepConfig<StepInput, OperationInput, OperationOutput>): MutationStep<StepInput, OperationInput, OperationOutput>;
|
|
113
|
+
/** Configuration for the getMessage connector Step. */
|
|
114
|
+
interface GetMessageStepConfig<StepInput, OperationInput = GetMessageInput, OperationOutput = Message> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
|
|
115
|
+
/** Named connection supplying this operation. */
|
|
116
|
+
connection: Connection<{
|
|
117
|
+
getMessage(): Query<OperationInput, OperationOutput>;
|
|
118
|
+
}>;
|
|
119
|
+
/** Name matching the bound connection. */
|
|
120
|
+
connectionName: string;
|
|
121
|
+
/** The message exists and its current status was read. */
|
|
122
|
+
found: StepTarget<QueryResult<OperationOutput>>;
|
|
123
|
+
/** The account has no message with that SID. */
|
|
124
|
+
notFound?: StepTarget<QueryResult<OperationOutput>>;
|
|
125
|
+
/** Twilio conclusively rejected the message query. */
|
|
126
|
+
providerRejected?: StepTarget<QueryResult<OperationOutput>>;
|
|
127
|
+
/** Twilio returned an invalid or oversized message response. */
|
|
128
|
+
invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
|
|
129
|
+
/** Local input, connection configuration, or connector definition is invalid. */
|
|
130
|
+
defect?: StepTarget<QueryResult<OperationOutput>>;
|
|
131
|
+
}
|
|
132
|
+
/** Build the getMessage Step from a named connection. */
|
|
133
|
+
declare function newGetMessageStep<StepInput, OperationInput = GetMessageInput, OperationOutput = Message>(configuration: GetMessageStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
|
|
134
|
+
|
|
135
|
+
/** Branch IDs for sendMessage. */
|
|
136
|
+
declare const SendMessageBranch: {
|
|
137
|
+
readonly Accepted: "accepted";
|
|
138
|
+
readonly ProviderRejected: "providerRejected";
|
|
139
|
+
readonly Uncertain: "uncertain";
|
|
140
|
+
readonly Defect: "defect";
|
|
141
|
+
};
|
|
142
|
+
/** Manifest definition for sendMessage. */
|
|
143
|
+
declare const SendMessageDefinition: MutationDefinition;
|
|
144
|
+
/** Branch IDs for getMessage. */
|
|
145
|
+
declare const GetMessageBranch: {
|
|
146
|
+
readonly Found: "found";
|
|
147
|
+
readonly NotFound: "notFound";
|
|
148
|
+
readonly ProviderRejected: "providerRejected";
|
|
149
|
+
readonly InvalidResponse: "invalidResponse";
|
|
150
|
+
readonly Defect: "defect";
|
|
151
|
+
};
|
|
152
|
+
/** Manifest definition for getMessage. */
|
|
153
|
+
declare const GetMessageDefinition: QueryDefinition;
|
|
154
|
+
|
|
155
|
+
export { Config, Connection, Credentials, GetMessageBranch, GetMessageDefinition, GetMessageInput, GetMessageOperation, Message, SendMessageBranch, SendMessageDefinition, SendMessageInput, SendMessageOperation, TwilioClient, type TwilioClientOptions, type TwilioRequestSender, newConnection, newGetMessageStep, newProjectConnection, newSendMessageStep };
|