@dereekb/nestjs 14.14.0 → 14.15.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/eslint/package.json +2 -2
- package/mailgun/index.esm.js +148 -4
- package/mailgun/package.json +6 -6
- package/mailgun/src/lib/mailgun.diagnostic.d.ts +110 -1
- package/openai/package.json +6 -6
- package/openrouter/package.json +3 -3
- package/package.json +3 -3
- package/stripe/package.json +6 -6
- package/twilio/index.esm.js +1181 -129
- package/twilio/package.json +6 -6
- package/twilio/src/lib/index.d.ts +1 -0
- package/twilio/src/lib/lookup/lookup.module.d.ts +19 -1
- package/twilio/src/lib/twilio.api.d.ts +11 -1
- package/twilio/src/lib/twilio.config.d.ts +55 -1
- package/twilio/src/lib/twilio.diagnostic.d.ts +306 -0
- package/twilio/src/lib/twilio.module.d.ts +38 -2
- package/twilio/src/lib/twilio.service.d.ts +4 -0
- package/twilio/src/lib/verify/verify.module.d.ts +19 -1
- package/twilio/src/lib/webhook/index.d.ts +2 -0
- package/twilio/src/lib/webhook/webhook.twilio.config.d.ts +11 -6
- package/twilio/src/lib/webhook/webhook.twilio.d.ts +11 -1
- package/twilio/src/lib/webhook/webhook.twilio.module.d.ts +35 -3
- package/twilio/src/lib/webhook/webhook.twilio.optout.d.ts +63 -0
- package/twilio/src/lib/webhook/webhook.twilio.service.d.ts +1 -2
- package/twilio/src/lib/webhook/webhook.twilio.url.d.ts +57 -0
- package/typeform/package.json +6 -6
- package/vapiai/package.json +6 -6
package/twilio/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dereekb/nestjs/twilio",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.15.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"peerDependencies": {
|
|
7
|
-
"@dereekb/date": "14.
|
|
8
|
-
"@dereekb/model": "14.
|
|
9
|
-
"@dereekb/nestjs": "14.
|
|
10
|
-
"@dereekb/rxjs": "14.
|
|
11
|
-
"@dereekb/util": "14.
|
|
7
|
+
"@dereekb/date": "14.15.0",
|
|
8
|
+
"@dereekb/model": "14.15.0",
|
|
9
|
+
"@dereekb/nestjs": "14.15.0",
|
|
10
|
+
"@dereekb/rxjs": "14.15.0",
|
|
11
|
+
"@dereekb/util": "14.15.0",
|
|
12
12
|
"@nestjs/common": "^12.0.1",
|
|
13
13
|
"@nestjs/config": "^12.0.0",
|
|
14
14
|
"express": "^5.2.1",
|
|
@@ -1,7 +1,25 @@
|
|
|
1
|
+
import { type ModuleMetadata } from '@nestjs/common';
|
|
2
|
+
import { type Maybe } from '@dereekb/util';
|
|
3
|
+
export interface ProvideAppTwilioLookupMetadataConfig extends Pick<ModuleMetadata, 'imports' | 'exports' | 'providers'> {
|
|
4
|
+
/**
|
|
5
|
+
* Module that exports the `TwilioApi`, typically the app's module built by `appTwilioModuleMetadata()`.
|
|
6
|
+
*
|
|
7
|
+
* Defaults to {@link TwilioModule}.
|
|
8
|
+
*/
|
|
9
|
+
readonly dependencyModule?: Maybe<Required<ModuleMetadata>['imports']['0']>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Convenience function used to generate ModuleMetadata for an app's Twilio Lookup v2 (phone validation, carrier info) module.
|
|
13
|
+
*
|
|
14
|
+
* @param config - The module metadata configuration including the dependency module.
|
|
15
|
+
* @returns NestJS ModuleMetadata for registering the Twilio Lookup module.
|
|
16
|
+
*/
|
|
17
|
+
export declare function appTwilioLookupModuleMetadata(config?: Maybe<ProvideAppTwilioLookupMetadataConfig>): ModuleMetadata;
|
|
1
18
|
/**
|
|
2
19
|
* NestJS module that exposes Twilio Lookup v2 (phone validation, carrier info).
|
|
3
20
|
*
|
|
4
|
-
* Imports {@link TwilioModule} for the underlying Twilio client.
|
|
21
|
+
* Imports {@link TwilioModule} for the underlying Twilio client. Use {@link appTwilioLookupModuleMetadata}
|
|
22
|
+
* to use the app's own Twilio module instead.
|
|
5
23
|
*/
|
|
6
24
|
export declare class TwilioLookupModule {
|
|
7
25
|
}
|
|
@@ -2,8 +2,18 @@ import { Twilio } from './twilio.interop';
|
|
|
2
2
|
import { TwilioServiceConfig } from './twilio.config';
|
|
3
3
|
export declare class TwilioApi {
|
|
4
4
|
readonly config: TwilioServiceConfig;
|
|
5
|
-
|
|
5
|
+
private _client?;
|
|
6
6
|
constructor(config: TwilioServiceConfig);
|
|
7
|
+
/**
|
|
8
|
+
* The Twilio SDK client, created on first access.
|
|
9
|
+
*
|
|
10
|
+
* Created lazily because the SDK constructor throws when the Account SID does not start with `AC`, so a
|
|
11
|
+
* config holding the placeholder values of a committed `.env` can still be provided. Accessing the client
|
|
12
|
+
* with such a config throws.
|
|
13
|
+
*
|
|
14
|
+
* @returns The Twilio SDK client.
|
|
15
|
+
*/
|
|
16
|
+
get client(): Twilio;
|
|
7
17
|
}
|
|
8
18
|
/**
|
|
9
19
|
* Provides a reference to a TwilioApi instance.
|
|
@@ -6,7 +6,6 @@ export declare const TWILIO_API_KEY_SID_ENV_VAR = "TWILIO_API_KEY_SID";
|
|
|
6
6
|
export declare const TWILIO_API_KEY_SECRET_ENV_VAR = "TWILIO_API_KEY_SECRET";
|
|
7
7
|
export declare const TWILIO_PHONE_NUMBER_ENV_VAR = "TWILIO_PHONE_NUMBER";
|
|
8
8
|
export declare const TWILIO_MESSAGING_SERVICE_SID_ENV_VAR = "TWILIO_MESSAGING_SERVICE_SID";
|
|
9
|
-
export declare const TWILIO_STATUS_CALLBACK_URL_ENV_VAR = "TWILIO_STATUS_CALLBACK_URL";
|
|
10
9
|
export declare const TWILIO_SANDBOX_ENV_VAR = "TWILIO_SANDBOX";
|
|
11
10
|
/**
|
|
12
11
|
* Twilio client credentials. Either {@link authToken} or the {@link apiKeySid}/{@link apiKeySecret}
|
|
@@ -47,6 +46,9 @@ export interface TwilioMessagesConfig {
|
|
|
47
46
|
/**
|
|
48
47
|
* Default status callback URL applied to outbound messages when the caller does not
|
|
49
48
|
* supply one explicitly.
|
|
49
|
+
*
|
|
50
|
+
* Not read from the environment. Build it from the app's public webhook URL with
|
|
51
|
+
* `twilioWebhookUrls()`.
|
|
50
52
|
*/
|
|
51
53
|
readonly defaultStatusCallback?: Maybe<TwilioStatusCallbackUrl>;
|
|
52
54
|
/**
|
|
@@ -69,3 +71,55 @@ export declare abstract class TwilioServiceConfig {
|
|
|
69
71
|
readonly messages: TwilioMessagesConfig;
|
|
70
72
|
static assertValidConfig(config: TwilioServiceConfig): void;
|
|
71
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Values treated as unset by {@link usableTwilioServiceConfig}.
|
|
76
|
+
*
|
|
77
|
+
* These are the stand-in values a committed `.env` ships with, which are truthy and so pass
|
|
78
|
+
* {@link TwilioServiceConfig.assertValidConfig}, but crash the `twilio` SDK constructor.
|
|
79
|
+
*/
|
|
80
|
+
export declare const TWILIO_PLACEHOLDER_CONFIG_VALUES: readonly string[];
|
|
81
|
+
/**
|
|
82
|
+
* Returns true if the input is unset or one of the {@link TWILIO_PLACEHOLDER_CONFIG_VALUES}.
|
|
83
|
+
*
|
|
84
|
+
* @param value - Configured value to check.
|
|
85
|
+
* @returns True if the value should be treated as unset.
|
|
86
|
+
*/
|
|
87
|
+
export declare function isPlaceholderTwilioConfigValue(value: Maybe<string>): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Returns a copy of the input config with its placeholder and malformed values removed, or
|
|
90
|
+
* undefined if what remains cannot send SMS.
|
|
91
|
+
*
|
|
92
|
+
* A usable config has:
|
|
93
|
+
* - an Account SID starting with `AC`
|
|
94
|
+
* - an Auth Token, or an API Key SID starting with `SK` together with its secret
|
|
95
|
+
* - a sender phone number starting with `+`, or a Messaging Service SID starting with `MG`
|
|
96
|
+
*
|
|
97
|
+
* Values that are unset, one of the {@link TWILIO_PLACEHOLDER_CONFIG_VALUES}, or missing their
|
|
98
|
+
* expected prefix are dropped from the returned config, so a placeholder Messaging Service SID or
|
|
99
|
+
* API key never shadows a real sender or auth token. A status callback URL that is not an
|
|
100
|
+
* `http(s)` URL is dropped as well, since it does not affect whether the config can send.
|
|
101
|
+
*
|
|
102
|
+
* `twilioServiceConfigFactory()` uses this to remove placeholder values from a usable environment config.
|
|
103
|
+
*
|
|
104
|
+
* @param config - Config to check, typically read from the environment.
|
|
105
|
+
* @returns The usable config, or undefined if the config cannot send SMS.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* const config = usableTwilioServiceConfig(twilioServiceConfigFromConfigService(configService));
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare function usableTwilioServiceConfig(config: Maybe<TwilioServiceConfig>): Maybe<TwilioServiceConfig>;
|
|
113
|
+
/**
|
|
114
|
+
* Returns true if {@link usableTwilioServiceConfig} can build a usable config from the input.
|
|
115
|
+
*
|
|
116
|
+
* Use it to decide whether a provided `TwilioService` can send, e.g.
|
|
117
|
+
* `isUsableTwilioServiceConfig(twilioService.twilioApi.config)`.
|
|
118
|
+
*
|
|
119
|
+
* Note that a usable config may still carry placeholder values; pass the input through
|
|
120
|
+
* {@link usableTwilioServiceConfig} to get a copy with them removed before using it.
|
|
121
|
+
*
|
|
122
|
+
* @param config - Config to check, typically read from the environment.
|
|
123
|
+
* @returns True if the config can send SMS.
|
|
124
|
+
*/
|
|
125
|
+
export declare function isUsableTwilioServiceConfig(config: Maybe<TwilioServiceConfig>): config is TwilioServiceConfig;
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module twilio.diagnostic
|
|
3
|
+
*
|
|
4
|
+
* Read-only helpers over the Twilio Messages, Accounts, and Lookup APIs.
|
|
5
|
+
*
|
|
6
|
+
* These exist to answer "why did this number not get the text?" without sending anything. They are all
|
|
7
|
+
* failure-tolerant: an unreachable API surfaces as an `unknown` result rather than a thrown error, so a
|
|
8
|
+
* diagnostic routine can report what it could learn instead of aborting, and never mistakes an outage
|
|
9
|
+
* for a problem with the number.
|
|
10
|
+
*/
|
|
11
|
+
import { type Maybe } from '@dereekb/util';
|
|
12
|
+
import { type TwilioApi } from './twilio.api';
|
|
13
|
+
import { type TwilioMessageSid, type TwilioMessageStatus, type TwilioPhoneNumber } from './twilio.type';
|
|
14
|
+
/**
|
|
15
|
+
* The default number of messages to read back when inspecting a number's recent texts.
|
|
16
|
+
*/
|
|
17
|
+
export declare const DEFAULT_TWILIO_RECENT_MESSAGES_LIMIT = 20;
|
|
18
|
+
/**
|
|
19
|
+
* The default window of history to inspect when reading a number's recent texts.
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_TWILIO_RECENT_MESSAGES_WINDOW_DAYS = 30;
|
|
22
|
+
/**
|
|
23
|
+
* Twilio error codes relevant to delivery diagnosis.
|
|
24
|
+
*
|
|
25
|
+
* Twilio reports these on a failed or undelivered message, and on the error a rejected send throws. Twilio
|
|
26
|
+
* notes that the code for a given cause may change as it improves its errors, so treat them as hints and
|
|
27
|
+
* keep the error message alongside. Unknown codes are passed through untouched.
|
|
28
|
+
*/
|
|
29
|
+
export declare enum TwilioMessageErrorCode {
|
|
30
|
+
/**
|
|
31
|
+
* The `To` number is not a valid phone number.
|
|
32
|
+
*/
|
|
33
|
+
INVALID_TO_NUMBER = 21211,
|
|
34
|
+
/**
|
|
35
|
+
* The recipient replied STOP, so the sender may not text them until they reply START.
|
|
36
|
+
*/
|
|
37
|
+
UNSUBSCRIBED_RECIPIENT = 21610,
|
|
38
|
+
/**
|
|
39
|
+
* The `To` number is not a mobile number, so it cannot receive texts.
|
|
40
|
+
*/
|
|
41
|
+
NOT_A_MOBILE_NUMBER = 21614,
|
|
42
|
+
/**
|
|
43
|
+
* The account's message queue overflowed. Temporary.
|
|
44
|
+
*/
|
|
45
|
+
QUEUE_OVERFLOW = 30001,
|
|
46
|
+
/**
|
|
47
|
+
* The Twilio account is suspended.
|
|
48
|
+
*/
|
|
49
|
+
ACCOUNT_SUSPENDED = 30002,
|
|
50
|
+
/**
|
|
51
|
+
* The phone is switched off or out of coverage. Usually temporary.
|
|
52
|
+
*/
|
|
53
|
+
UNREACHABLE_DESTINATION_HANDSET = 30003,
|
|
54
|
+
/**
|
|
55
|
+
* The carrier or the phone blocked the message.
|
|
56
|
+
*/
|
|
57
|
+
MESSAGE_BLOCKED = 30004,
|
|
58
|
+
/**
|
|
59
|
+
* The number does not exist or is no longer in service.
|
|
60
|
+
*/
|
|
61
|
+
UNKNOWN_DESTINATION_HANDSET = 30005,
|
|
62
|
+
/**
|
|
63
|
+
* The number is a landline, or its carrier cannot receive texts.
|
|
64
|
+
*/
|
|
65
|
+
LANDLINE_OR_UNREACHABLE_CARRIER = 30006,
|
|
66
|
+
/**
|
|
67
|
+
* The carrier filtered the message, usually as suspected spam.
|
|
68
|
+
*/
|
|
69
|
+
MESSAGE_FILTERED = 30007,
|
|
70
|
+
/**
|
|
71
|
+
* Twilio could not determine why the message failed. Often temporary.
|
|
72
|
+
*/
|
|
73
|
+
UNKNOWN_ERROR = 30008,
|
|
74
|
+
/**
|
|
75
|
+
* The sending number is not registered for A2P 10DLC messaging, so US carriers block it.
|
|
76
|
+
*/
|
|
77
|
+
UNREGISTERED_NUMBER = 30034
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A message as read back for diagnosis.
|
|
81
|
+
*/
|
|
82
|
+
export interface TwilioDiagnosticMessage {
|
|
83
|
+
readonly sid: TwilioMessageSid;
|
|
84
|
+
readonly status: TwilioMessageStatus;
|
|
85
|
+
readonly to: string;
|
|
86
|
+
/**
|
|
87
|
+
* Set when the message failed or was not delivered. See {@link TwilioMessageErrorCode}.
|
|
88
|
+
*/
|
|
89
|
+
readonly errorCode?: Maybe<number>;
|
|
90
|
+
/**
|
|
91
|
+
* Twilio's description of `errorCode`.
|
|
92
|
+
*/
|
|
93
|
+
readonly errorMessage?: Maybe<string>;
|
|
94
|
+
/**
|
|
95
|
+
* When the message was sent. Unset while it is still queued.
|
|
96
|
+
*/
|
|
97
|
+
readonly dateSent?: Maybe<Date>;
|
|
98
|
+
readonly dateCreated?: Maybe<Date>;
|
|
99
|
+
/**
|
|
100
|
+
* When the message's status last changed.
|
|
101
|
+
*/
|
|
102
|
+
readonly dateUpdated?: Maybe<Date>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The fields of a Twilio message instance that {@link twilioDiagnosticMessage} reads.
|
|
106
|
+
*/
|
|
107
|
+
export interface TwilioDiagnosticMessageInput {
|
|
108
|
+
readonly sid: string;
|
|
109
|
+
readonly status: string;
|
|
110
|
+
readonly to: string;
|
|
111
|
+
readonly errorCode?: Maybe<number>;
|
|
112
|
+
readonly errorMessage?: Maybe<string>;
|
|
113
|
+
readonly dateSent?: Maybe<Date>;
|
|
114
|
+
readonly dateCreated?: Maybe<Date>;
|
|
115
|
+
readonly dateUpdated?: Maybe<Date>;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Converts a Twilio message instance to a {@link TwilioDiagnosticMessage}.
|
|
119
|
+
*
|
|
120
|
+
* @param message - The message instance.
|
|
121
|
+
* @returns The diagnostic message.
|
|
122
|
+
*/
|
|
123
|
+
export declare function twilioDiagnosticMessage(message: TwilioDiagnosticMessageInput): TwilioDiagnosticMessage;
|
|
124
|
+
/**
|
|
125
|
+
* Returns the time a message last changed state: its update time, falling back to its send and creation times.
|
|
126
|
+
*
|
|
127
|
+
* @param message - The message.
|
|
128
|
+
* @returns The time, if Twilio recorded any.
|
|
129
|
+
*/
|
|
130
|
+
export declare function twilioDiagnosticMessageDate(message: TwilioDiagnosticMessage): Maybe<Date>;
|
|
131
|
+
/**
|
|
132
|
+
* Returns the Twilio error code of a thrown Twilio error, such as the error a rejected send throws.
|
|
133
|
+
*
|
|
134
|
+
* @param error - The thrown value.
|
|
135
|
+
* @returns The error code, if the error carries one.
|
|
136
|
+
*/
|
|
137
|
+
export declare function twilioErrorCode(error: unknown): Maybe<number>;
|
|
138
|
+
/**
|
|
139
|
+
* Returns the HTTP status of a thrown Twilio error.
|
|
140
|
+
*
|
|
141
|
+
* @param error - The thrown value.
|
|
142
|
+
* @returns The HTTP status, if the error carries one.
|
|
143
|
+
*/
|
|
144
|
+
export declare function twilioErrorStatus(error: unknown): Maybe<number>;
|
|
145
|
+
/**
|
|
146
|
+
* Why a diagnostic read could not be made.
|
|
147
|
+
*/
|
|
148
|
+
export interface TwilioDiagnosticError {
|
|
149
|
+
/**
|
|
150
|
+
* The error message.
|
|
151
|
+
*/
|
|
152
|
+
readonly message: string;
|
|
153
|
+
/**
|
|
154
|
+
* The HTTP status Twilio responded with, if it responded. 401 and 403 mean the credentials were refused, or are not
|
|
155
|
+
* allowed to read the resource, such as a Standard API key reading the account.
|
|
156
|
+
*/
|
|
157
|
+
readonly status?: Maybe<number>;
|
|
158
|
+
/**
|
|
159
|
+
* Twilio's error code, if it gave one.
|
|
160
|
+
*/
|
|
161
|
+
readonly code?: Maybe<number>;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Converts a thrown value to a {@link TwilioDiagnosticError}.
|
|
165
|
+
*
|
|
166
|
+
* @param error - The thrown value.
|
|
167
|
+
* @returns The diagnostic error.
|
|
168
|
+
*/
|
|
169
|
+
export declare function twilioDiagnosticError(error: unknown): TwilioDiagnosticError;
|
|
170
|
+
/**
|
|
171
|
+
* Whether a diagnostic read was refused because of the credentials, rather than failing to reach Twilio.
|
|
172
|
+
*
|
|
173
|
+
* @param error - The read's error, if it failed.
|
|
174
|
+
* @returns True if Twilio answered with 401 or 403.
|
|
175
|
+
*/
|
|
176
|
+
export declare function isTwilioDiagnosticPermissionError(error: Maybe<TwilioDiagnosticError>): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Options for {@link twilioRecentMessagesForRecipient}.
|
|
179
|
+
*/
|
|
180
|
+
export interface TwilioRecentMessagesForRecipientOptions {
|
|
181
|
+
/**
|
|
182
|
+
* The maximum number of messages to read back. Defaults to {@link DEFAULT_TWILIO_RECENT_MESSAGES_LIMIT}.
|
|
183
|
+
*/
|
|
184
|
+
readonly limit?: Maybe<number>;
|
|
185
|
+
/**
|
|
186
|
+
* Only read back messages sent after this time.
|
|
187
|
+
*/
|
|
188
|
+
readonly dateSentAfter?: Maybe<Date>;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Result of {@link twilioRecentMessagesForRecipient}.
|
|
192
|
+
*/
|
|
193
|
+
export interface TwilioRecentMessagesForRecipientResult {
|
|
194
|
+
/**
|
|
195
|
+
* The messages sent to the number, newest first. Empty when none were found or they could not be read.
|
|
196
|
+
*/
|
|
197
|
+
readonly messages: TwilioDiagnosticMessage[];
|
|
198
|
+
/**
|
|
199
|
+
* True if the messages could not be read.
|
|
200
|
+
*/
|
|
201
|
+
readonly unknown?: Maybe<boolean>;
|
|
202
|
+
/**
|
|
203
|
+
* Why the messages could not be read.
|
|
204
|
+
*/
|
|
205
|
+
readonly error?: Maybe<TwilioDiagnosticError>;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Reads the messages recently sent to a number, newest first.
|
|
209
|
+
*
|
|
210
|
+
* @param api - The Twilio API.
|
|
211
|
+
* @param to - The number the messages were sent to.
|
|
212
|
+
* @param options - How many messages to read, and how far back.
|
|
213
|
+
* @returns The messages, with `unknown` set if they could not be read.
|
|
214
|
+
*/
|
|
215
|
+
export declare function twilioRecentMessagesForRecipient(api: TwilioApi, to: TwilioPhoneNumber, options?: Maybe<TwilioRecentMessagesForRecipientOptions>): Promise<TwilioRecentMessagesForRecipientResult>;
|
|
216
|
+
/**
|
|
217
|
+
* Result of {@link twilioMessageForSid}.
|
|
218
|
+
*/
|
|
219
|
+
export interface TwilioMessageForSidResult {
|
|
220
|
+
/**
|
|
221
|
+
* The message, if it exists.
|
|
222
|
+
*/
|
|
223
|
+
readonly message?: Maybe<TwilioDiagnosticMessage>;
|
|
224
|
+
/**
|
|
225
|
+
* True if the message could not be read. A message that does not exist is not unknown.
|
|
226
|
+
*/
|
|
227
|
+
readonly unknown?: Maybe<boolean>;
|
|
228
|
+
/**
|
|
229
|
+
* Why the message could not be read.
|
|
230
|
+
*/
|
|
231
|
+
readonly error?: Maybe<TwilioDiagnosticError>;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Reads a single message, such as a test message whose outcome is being followed.
|
|
235
|
+
*
|
|
236
|
+
* @param api - The Twilio API.
|
|
237
|
+
* @param sid - The message SID.
|
|
238
|
+
* @returns The message, with `unknown` set if it could not be read.
|
|
239
|
+
*/
|
|
240
|
+
export declare function twilioMessageForSid(api: TwilioApi, sid: TwilioMessageSid): Promise<TwilioMessageForSidResult>;
|
|
241
|
+
/**
|
|
242
|
+
* The state of the Twilio account.
|
|
243
|
+
*/
|
|
244
|
+
export interface TwilioAccountState {
|
|
245
|
+
/**
|
|
246
|
+
* Twilio's status for the account. `active` is healthy; `suspended` and `closed` send nothing.
|
|
247
|
+
*/
|
|
248
|
+
readonly status?: Maybe<string>;
|
|
249
|
+
/**
|
|
250
|
+
* True if the state could not be read.
|
|
251
|
+
*/
|
|
252
|
+
readonly unknown?: Maybe<boolean>;
|
|
253
|
+
/**
|
|
254
|
+
* Why the state could not be read.
|
|
255
|
+
*/
|
|
256
|
+
readonly error?: Maybe<TwilioDiagnosticError>;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Reads the account's state.
|
|
260
|
+
*
|
|
261
|
+
* Twilio does not let a Standard API key read the account, so with one this is always `unknown`, with a permission
|
|
262
|
+
* error. See {@link isTwilioDiagnosticPermissionError}.
|
|
263
|
+
*
|
|
264
|
+
* An account that is not `active` sends nothing regardless of the recipient, so this distinguishes a system-wide
|
|
265
|
+
* outage from a per-recipient problem.
|
|
266
|
+
*
|
|
267
|
+
* @param api - The Twilio API.
|
|
268
|
+
* @returns The account's state, with `unknown` set if it could not be read.
|
|
269
|
+
*/
|
|
270
|
+
export declare function twilioAccountState(api: TwilioApi): Promise<TwilioAccountState>;
|
|
271
|
+
/**
|
|
272
|
+
* Result of {@link twilioLookupPhoneNumberForDiagnosis}.
|
|
273
|
+
*/
|
|
274
|
+
export interface TwilioPhoneNumberDiagnosis {
|
|
275
|
+
/**
|
|
276
|
+
* Whether Twilio could resolve the number to a valid phone number. Unset when the lookup could not be made.
|
|
277
|
+
*/
|
|
278
|
+
readonly valid?: Maybe<boolean>;
|
|
279
|
+
/**
|
|
280
|
+
* The line type, such as `mobile`, `landline` or `nonFixedVoip`, when it was requested and Twilio knows it.
|
|
281
|
+
*/
|
|
282
|
+
readonly lineType?: Maybe<string>;
|
|
283
|
+
/**
|
|
284
|
+
* The carrier name, when the line type was requested and Twilio knows it.
|
|
285
|
+
*/
|
|
286
|
+
readonly carrierName?: Maybe<string>;
|
|
287
|
+
/**
|
|
288
|
+
* True if the lookup could not be made.
|
|
289
|
+
*/
|
|
290
|
+
readonly unknown?: Maybe<boolean>;
|
|
291
|
+
/**
|
|
292
|
+
* Why the lookup could not be made.
|
|
293
|
+
*/
|
|
294
|
+
readonly error?: Maybe<TwilioDiagnosticError>;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Looks up a number with Twilio Lookup v2.
|
|
298
|
+
*
|
|
299
|
+
* Unlike {@link TwilioLookupService.lookup}, a failed lookup is reported as `unknown` rather than as an invalid number.
|
|
300
|
+
*
|
|
301
|
+
* @param api - The Twilio API.
|
|
302
|
+
* @param phoneNumber - The number to look up.
|
|
303
|
+
* @param includeLineType - Whether to request the line type. Twilio charges per lookup for it.
|
|
304
|
+
* @returns The diagnosis, with `unknown` set if the lookup could not be made.
|
|
305
|
+
*/
|
|
306
|
+
export declare function twilioLookupPhoneNumberForDiagnosis(api: TwilioApi, phoneNumber: TwilioPhoneNumber, includeLineType?: Maybe<boolean>): Promise<TwilioPhoneNumberDiagnosis>;
|
|
@@ -1,17 +1,53 @@
|
|
|
1
|
+
import { type ModuleMetadata } from '@nestjs/common';
|
|
1
2
|
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import { type Maybe } from '@dereekb/util';
|
|
2
4
|
import { TwilioServiceConfig } from './twilio.config';
|
|
5
|
+
import { TwilioWebhookUrlsConfig } from './webhook/webhook.twilio.url';
|
|
6
|
+
/**
|
|
7
|
+
* Reads a {@link TwilioServiceConfig} from environment variables without validating it.
|
|
8
|
+
*
|
|
9
|
+
* {@link twilioServiceConfigFactory} builds the validated config from it.
|
|
10
|
+
*
|
|
11
|
+
* @param configService - NestJS config service for reading environment variables.
|
|
12
|
+
* @returns The unvalidated {@link TwilioServiceConfig}.
|
|
13
|
+
*/
|
|
14
|
+
export declare function twilioServiceConfigFromConfigService(configService: ConfigService): TwilioServiceConfig;
|
|
3
15
|
/**
|
|
4
16
|
* Factory that creates a {@link TwilioServiceConfig} from environment variables.
|
|
5
17
|
*
|
|
18
|
+
* When the environment holds a usable config, its placeholder values are removed (see
|
|
19
|
+
* {@link usableTwilioServiceConfig}), so a placeholder Messaging Service SID or API key never shadows a real
|
|
20
|
+
* sender or auth token. Otherwise the placeholder values are kept, which lets the app start; {@link TwilioApi}
|
|
21
|
+
* only creates the SDK client when it is first used.
|
|
22
|
+
*
|
|
6
23
|
* @param configService - NestJS config service for reading environment variables.
|
|
24
|
+
* @param webhookUrlsConfig - The app's public webhook URLs. When set, outbound texts request status callbacks at its status callback URL.
|
|
7
25
|
* @returns A validated {@link TwilioServiceConfig}.
|
|
8
26
|
*/
|
|
9
|
-
export declare function twilioServiceConfigFactory(configService: ConfigService): TwilioServiceConfig;
|
|
27
|
+
export declare function twilioServiceConfigFactory(configService: ConfigService, webhookUrlsConfig?: Maybe<TwilioWebhookUrlsConfig>): TwilioServiceConfig;
|
|
28
|
+
export interface ProvideAppTwilioMetadataConfig extends Pick<ModuleMetadata, 'imports' | 'exports' | 'providers'> {
|
|
29
|
+
/**
|
|
30
|
+
* Optional module that exports a {@link TwilioWebhookUrlsConfig}. When provided, outbound texts request status
|
|
31
|
+
* callbacks at the app's `/webhook/twilio/status` route.
|
|
32
|
+
*/
|
|
33
|
+
readonly dependencyModule?: Maybe<Required<ModuleMetadata>['imports']['0']>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Convenience function used to generate ModuleMetadata for an app's Twilio module, which provides
|
|
37
|
+
* {@link TwilioApi} and {@link TwilioService} for sending SMS.
|
|
38
|
+
*
|
|
39
|
+
* Reads the Twilio credentials and default sender from environment variables.
|
|
40
|
+
*
|
|
41
|
+
* @param config - The module metadata configuration including the optional dependency module.
|
|
42
|
+
* @returns NestJS ModuleMetadata for registering the Twilio module.
|
|
43
|
+
*/
|
|
44
|
+
export declare function appTwilioModuleMetadata(config?: Maybe<ProvideAppTwilioMetadataConfig>): ModuleMetadata;
|
|
10
45
|
/**
|
|
11
46
|
* NestJS module that provides the {@link TwilioApi} and {@link TwilioService} for sending SMS
|
|
12
47
|
* via Twilio.
|
|
13
48
|
*
|
|
14
|
-
* Reads Twilio credentials and default sender configuration from environment variables.
|
|
49
|
+
* Reads Twilio credentials and default sender configuration from environment variables. Use
|
|
50
|
+
* {@link appTwilioModuleMetadata} to supply the app's webhook URLs.
|
|
15
51
|
*/
|
|
16
52
|
export declare class TwilioModule {
|
|
17
53
|
}
|
|
@@ -60,6 +60,10 @@ export interface TwilioSendSmsResult {
|
|
|
60
60
|
* Error message captured if the send failed.
|
|
61
61
|
*/
|
|
62
62
|
readonly error?: Maybe<string>;
|
|
63
|
+
/**
|
|
64
|
+
* Twilio error code captured if the send failed, such as 21610 for a recipient who replied STOP. See {@link TwilioMessageErrorCode}.
|
|
65
|
+
*/
|
|
66
|
+
readonly errorCode?: Maybe<number>;
|
|
63
67
|
}
|
|
64
68
|
export declare class TwilioService {
|
|
65
69
|
private readonly logger;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { type ModuleMetadata } from '@nestjs/common';
|
|
1
2
|
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import { type Maybe } from '@dereekb/util';
|
|
2
4
|
import { TwilioVerifyServiceConfig } from './verify.config';
|
|
3
5
|
/**
|
|
4
6
|
* Factory that creates a {@link TwilioVerifyServiceConfig} from environment variables.
|
|
@@ -7,11 +9,27 @@ import { TwilioVerifyServiceConfig } from './verify.config';
|
|
|
7
9
|
* @returns A validated {@link TwilioVerifyServiceConfig}.
|
|
8
10
|
*/
|
|
9
11
|
export declare function twilioVerifyServiceConfigFactory(configService: ConfigService): TwilioVerifyServiceConfig;
|
|
12
|
+
export interface ProvideAppTwilioVerifyMetadataConfig extends Pick<ModuleMetadata, 'imports' | 'exports' | 'providers'> {
|
|
13
|
+
/**
|
|
14
|
+
* Module that exports the `TwilioApi`, typically the app's module built by `appTwilioModuleMetadata()`.
|
|
15
|
+
*
|
|
16
|
+
* Defaults to {@link TwilioModule}.
|
|
17
|
+
*/
|
|
18
|
+
readonly dependencyModule?: Maybe<Required<ModuleMetadata>['imports']['0']>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Convenience function used to generate ModuleMetadata for an app's Twilio Verify (OTP / 2FA) module.
|
|
22
|
+
*
|
|
23
|
+
* @param config - The module metadata configuration including the dependency module.
|
|
24
|
+
* @returns NestJS ModuleMetadata for registering the Twilio Verify module.
|
|
25
|
+
*/
|
|
26
|
+
export declare function appTwilioVerifyModuleMetadata(config?: Maybe<ProvideAppTwilioVerifyMetadataConfig>): ModuleMetadata;
|
|
10
27
|
/**
|
|
11
28
|
* NestJS module that exposes Twilio Verify (OTP / 2FA) for starting verifications and
|
|
12
29
|
* checking submitted codes.
|
|
13
30
|
*
|
|
14
|
-
* Imports {@link TwilioModule} for the underlying Twilio client.
|
|
31
|
+
* Imports {@link TwilioModule} for the underlying Twilio client. Use {@link appTwilioVerifyModuleMetadata}
|
|
32
|
+
* to use the app's own Twilio module instead.
|
|
15
33
|
*/
|
|
16
34
|
export declare class TwilioVerifyModule {
|
|
17
35
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './webhook.twilio';
|
|
2
|
+
export * from './webhook.twilio.optout';
|
|
2
3
|
export * from './webhook.twilio.config';
|
|
4
|
+
export * from './webhook.twilio.url';
|
|
3
5
|
export * from './webhook.twilio.verify';
|
|
4
6
|
export * from './webhook.twilio.service';
|
|
5
7
|
export * from './webhook.twilio.controller';
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { type Maybe } from '@dereekb/util';
|
|
2
2
|
export declare const TWILIO_WEBHOOK_AUTH_TOKEN_ENV_VAR = "TWILIO_WEBHOOK_AUTH_TOKEN";
|
|
3
|
-
export declare const TWILIO_WEBHOOK_BASE_URL_ENV_VAR = "TWILIO_WEBHOOK_BASE_URL";
|
|
4
3
|
export declare const TWILIO_WEBHOOK_SKIP_VERIFY_ENV_VAR = "TWILIO_WEBHOOK_SKIP_VERIFY";
|
|
5
4
|
export interface TwilioWebhookConfig {
|
|
6
5
|
/**
|
|
7
|
-
* Twilio Auth Token used to verify the X-Twilio-Signature header.
|
|
8
|
-
*
|
|
6
|
+
* Twilio Auth Token used to verify the X-Twilio-Signature header. Required.
|
|
7
|
+
*
|
|
8
|
+
* `twilioWebhookServiceConfigFactory()` reads it from `TWILIO_WEBHOOK_AUTH_TOKEN`, falling back to
|
|
9
|
+
* `TWILIO_AUTH_TOKEN`.
|
|
9
10
|
*/
|
|
10
11
|
readonly authToken?: Maybe<string>;
|
|
11
12
|
/**
|
|
12
|
-
*
|
|
13
|
-
* request signature over the full URL it called, so behind a proxy the public
|
|
14
|
-
* supplied here for verification to succeed.
|
|
13
|
+
* Public origin Twilio calls the webhook on (e.g. `https://api.example.com`). Twilio computes the
|
|
14
|
+
* request signature over the full URL it called, so behind a proxy the public origin must be
|
|
15
|
+
* supplied here for verification to succeed. When unset, the URL is rebuilt from the request's
|
|
16
|
+
* `X-Forwarded-Proto` / `X-Forwarded-Host` / `Host` headers.
|
|
17
|
+
*
|
|
18
|
+
* Not read from the environment. Build it from the app's public webhook URL with
|
|
19
|
+
* `twilioWebhookUrls()`.
|
|
15
20
|
*/
|
|
16
21
|
readonly baseUrl?: Maybe<string>;
|
|
17
22
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Maybe, type Handler, type HandlerBindAccessor, type HandlerMappedSetFunction } from '@dereekb/util';
|
|
2
|
-
import { type TwilioAccountSid, type TwilioMessageSid, type TwilioMessageStatus, type TwilioPhoneNumber } from '../twilio.type';
|
|
2
|
+
import { type TwilioAccountSid, type TwilioMessageSid, type TwilioMessageStatus, type TwilioMessagingServiceSid, type TwilioPhoneNumber } from '../twilio.type';
|
|
3
|
+
import { type TwilioOptOutType } from './webhook.twilio.optout';
|
|
3
4
|
/**
|
|
4
5
|
* Twilio webhook event type.
|
|
5
6
|
*/
|
|
@@ -40,6 +41,15 @@ export interface TwilioIncomingMessagePayload {
|
|
|
40
41
|
readonly FromState?: Maybe<string>;
|
|
41
42
|
readonly FromZip?: Maybe<string>;
|
|
42
43
|
readonly FromCountry?: Maybe<string>;
|
|
44
|
+
/**
|
|
45
|
+
* The Messaging Service the message was sent to, if it was sent to one.
|
|
46
|
+
*/
|
|
47
|
+
readonly MessagingServiceSid?: Maybe<TwilioMessagingServiceSid>;
|
|
48
|
+
/**
|
|
49
|
+
* The opt-out keyword type Twilio matched the message to, if any. Only sent for messages to a Messaging Service, or to a number with
|
|
50
|
+
* Advanced Opt-Out. See {@link twilioIncomingMessageOptOutType}, which also matches the default keywords when it is absent.
|
|
51
|
+
*/
|
|
52
|
+
readonly OptOutType?: Maybe<TwilioOptOutType>;
|
|
43
53
|
/**
|
|
44
54
|
* Resolved MediaUrl0..MediaUrlN entries, ordered by index. Empty array when no media.
|
|
45
55
|
*/
|