@dereekb/nestjs 13.11.18 → 13.12.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/discord/package.json +4 -4
- package/discord/src/lib/discord.api.spec.client.d.ts +20 -0
- package/eslint/index.cjs.js +148 -115
- package/eslint/index.esm.js +148 -115
- package/eslint/package.json +1 -1
- package/mailgun/package.json +6 -6
- package/openai/package.json +6 -6
- package/package.json +11 -4
- package/stripe/package.json +6 -6
- package/twilio/index.cjs.default.js +1 -0
- package/twilio/index.cjs.js +2184 -0
- package/twilio/index.cjs.mjs +2 -0
- package/twilio/index.d.ts +1 -0
- package/twilio/index.esm.js +2159 -0
- package/twilio/package.json +27 -0
- package/twilio/src/index.d.ts +1 -0
- package/twilio/src/lib/index.d.ts +8 -0
- package/twilio/src/lib/lookup/index.d.ts +4 -0
- package/twilio/src/lib/lookup/lookup.api.d.ts +7 -0
- package/twilio/src/lib/lookup/lookup.module.d.ts +7 -0
- package/twilio/src/lib/lookup/lookup.service.d.ts +39 -0
- package/twilio/src/lib/lookup/lookup.type.d.ts +37 -0
- package/twilio/src/lib/twilio.api.d.ts +13 -0
- package/twilio/src/lib/twilio.config.d.ts +71 -0
- package/twilio/src/lib/twilio.module.d.ts +17 -0
- package/twilio/src/lib/twilio.service.d.ts +91 -0
- package/twilio/src/lib/twilio.type.d.ts +53 -0
- package/twilio/src/lib/verify/index.d.ts +4 -0
- package/twilio/src/lib/verify/verify.api.d.ts +10 -0
- package/twilio/src/lib/verify/verify.config.d.ts +22 -0
- package/twilio/src/lib/verify/verify.module.d.ts +17 -0
- package/twilio/src/lib/verify/verify.service.d.ts +83 -0
- package/twilio/src/lib/webhook/index.d.ts +6 -0
- package/twilio/src/lib/webhook/webhook.twilio.config.d.ts +28 -0
- package/twilio/src/lib/webhook/webhook.twilio.controller.d.ts +9 -0
- package/twilio/src/lib/webhook/webhook.twilio.d.ts +68 -0
- package/twilio/src/lib/webhook/webhook.twilio.module.d.ts +22 -0
- package/twilio/src/lib/webhook/webhook.twilio.service.d.ts +21 -0
- package/twilio/src/lib/webhook/webhook.twilio.verify.d.ts +53 -0
- package/typeform/package.json +6 -6
- package/vapiai/package.json +6 -6
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dereekb/nestjs/twilio",
|
|
3
|
+
"version": "13.12.1",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@dereekb/date": "13.12.1",
|
|
6
|
+
"@dereekb/model": "13.12.1",
|
|
7
|
+
"@dereekb/nestjs": "13.12.1",
|
|
8
|
+
"@dereekb/rxjs": "13.12.1",
|
|
9
|
+
"@dereekb/util": "13.12.1",
|
|
10
|
+
"@nestjs/common": "^11.1.19",
|
|
11
|
+
"@nestjs/config": "^4.0.4",
|
|
12
|
+
"express": "^5.2.1",
|
|
13
|
+
"twilio": "^6.0.2"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
"./package.json": "./package.json",
|
|
17
|
+
".": {
|
|
18
|
+
"module": "./index.esm.js",
|
|
19
|
+
"types": "./index.d.ts",
|
|
20
|
+
"import": "./index.cjs.mjs",
|
|
21
|
+
"default": "./index.cjs.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"module": "./index.esm.js",
|
|
25
|
+
"main": "./index.cjs.js",
|
|
26
|
+
"types": "./index.d.ts"
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TwilioApi } from '../twilio.api';
|
|
2
|
+
export declare class TwilioLookupApi {
|
|
3
|
+
private readonly _twilioApi;
|
|
4
|
+
constructor(twilioApi: TwilioApi);
|
|
5
|
+
get twilioApi(): TwilioApi;
|
|
6
|
+
get phoneNumbers(): import("twilio/lib/rest/lookups/v2/phoneNumber").PhoneNumberListInstance;
|
|
7
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type Maybe } from '@dereekb/util';
|
|
2
|
+
import { TwilioLookupApi } from './lookup.api';
|
|
3
|
+
import { type TwilioLookupResult } from './lookup.type';
|
|
4
|
+
export interface TwilioLookupInput {
|
|
5
|
+
/**
|
|
6
|
+
* Phone number to look up. Can be in any format Twilio accepts.
|
|
7
|
+
*/
|
|
8
|
+
readonly phoneNumber: string;
|
|
9
|
+
/**
|
|
10
|
+
* When true, requests the `line_type_intelligence` data set so that carrier info is included
|
|
11
|
+
* in the result. NOTE: Twilio charges per-lookup for this data set; do not enable in hot paths
|
|
12
|
+
* without an explicit need.
|
|
13
|
+
*/
|
|
14
|
+
readonly includeCarrier?: Maybe<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* ISO 3166-1 alpha-2 country code Twilio uses when interpreting nationally-formatted numbers.
|
|
17
|
+
*/
|
|
18
|
+
readonly countryCode?: Maybe<string>;
|
|
19
|
+
}
|
|
20
|
+
export declare class TwilioLookupService {
|
|
21
|
+
private readonly logger;
|
|
22
|
+
private readonly _twilioLookupApi;
|
|
23
|
+
constructor(twilioLookupApi: TwilioLookupApi);
|
|
24
|
+
get twilioLookupApi(): TwilioLookupApi;
|
|
25
|
+
/**
|
|
26
|
+
* Validates and normalizes a phone number via Twilio Lookup v2. Optionally returns carrier
|
|
27
|
+
* information when `includeCarrier` is set (additional Twilio charges apply).
|
|
28
|
+
*
|
|
29
|
+
* @param input - Phone number to look up plus optional carrier / country-code flags.
|
|
30
|
+
* @returns The lookup result, with `valid: false` when Twilio cannot resolve the number.
|
|
31
|
+
*/
|
|
32
|
+
lookup(input: TwilioLookupInput): Promise<TwilioLookupResult>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Provides a reference to a TwilioLookupService instance.
|
|
36
|
+
*/
|
|
37
|
+
export interface TwilioLookupServiceRef {
|
|
38
|
+
readonly twilioLookupService: TwilioLookupService;
|
|
39
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Maybe } from '@dereekb/util';
|
|
2
|
+
import { type TwilioPhoneNumber } from '../twilio.type';
|
|
3
|
+
/**
|
|
4
|
+
* Carrier information returned by the Twilio Lookup v2 API when the `line_type_intelligence`
|
|
5
|
+
* data set is requested.
|
|
6
|
+
*/
|
|
7
|
+
export interface TwilioLookupCarrierInfo {
|
|
8
|
+
readonly carrierName?: Maybe<string>;
|
|
9
|
+
readonly type?: Maybe<string>;
|
|
10
|
+
readonly mobileCountryCode?: Maybe<string>;
|
|
11
|
+
readonly mobileNetworkCode?: Maybe<string>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Result of a Twilio Lookup v2 phone-number lookup.
|
|
15
|
+
*/
|
|
16
|
+
export interface TwilioLookupResult {
|
|
17
|
+
/**
|
|
18
|
+
* Whether Twilio could resolve the number to a valid phone number.
|
|
19
|
+
*/
|
|
20
|
+
readonly valid: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The phone number in E.164 format, as normalized by Twilio.
|
|
23
|
+
*/
|
|
24
|
+
readonly phoneNumber: TwilioPhoneNumber;
|
|
25
|
+
/**
|
|
26
|
+
* ISO country code (alpha-2) for the phone number.
|
|
27
|
+
*/
|
|
28
|
+
readonly countryCode?: Maybe<string>;
|
|
29
|
+
/**
|
|
30
|
+
* National-format representation of the number.
|
|
31
|
+
*/
|
|
32
|
+
readonly nationalFormat?: Maybe<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Carrier information, populated only when `includeCarrier` was set on the lookup request.
|
|
35
|
+
*/
|
|
36
|
+
readonly carrier?: Maybe<TwilioLookupCarrierInfo>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Twilio } from 'twilio';
|
|
2
|
+
import { TwilioServiceConfig } from './twilio.config';
|
|
3
|
+
export declare class TwilioApi {
|
|
4
|
+
readonly config: TwilioServiceConfig;
|
|
5
|
+
readonly client: Twilio;
|
|
6
|
+
constructor(config: TwilioServiceConfig);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Provides a reference to a TwilioApi instance.
|
|
10
|
+
*/
|
|
11
|
+
export interface TwilioApiRef {
|
|
12
|
+
readonly twilioApi: TwilioApi;
|
|
13
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type Maybe } from '@dereekb/util';
|
|
2
|
+
import { type TwilioAccountSid, type TwilioApiKeySecret, type TwilioApiKeySid, type TwilioAuthToken, type TwilioMessagingServiceSid, type TwilioPhoneNumber, type TwilioStatusCallbackUrl } from './twilio.type';
|
|
3
|
+
export declare const TWILIO_ACCOUNT_SID_ENV_VAR = "TWILIO_ACCOUNT_SID";
|
|
4
|
+
export declare const TWILIO_AUTH_TOKEN_ENV_VAR = "TWILIO_AUTH_TOKEN";
|
|
5
|
+
export declare const TWILIO_API_KEY_SID_ENV_VAR = "TWILIO_API_KEY_SID";
|
|
6
|
+
export declare const TWILIO_API_KEY_SECRET_ENV_VAR = "TWILIO_API_KEY_SECRET";
|
|
7
|
+
export declare const TWILIO_PHONE_NUMBER_ENV_VAR = "TWILIO_PHONE_NUMBER";
|
|
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
|
+
export declare const TWILIO_SANDBOX_ENV_VAR = "TWILIO_SANDBOX";
|
|
11
|
+
/**
|
|
12
|
+
* Twilio client credentials. Either {@link authToken} or the {@link apiKeySid}/{@link apiKeySecret}
|
|
13
|
+
* pair is required.
|
|
14
|
+
*/
|
|
15
|
+
export interface TwilioCredentials {
|
|
16
|
+
/**
|
|
17
|
+
* Twilio Account SID. Required.
|
|
18
|
+
*/
|
|
19
|
+
readonly accountSid: TwilioAccountSid;
|
|
20
|
+
/**
|
|
21
|
+
* Twilio Auth Token. Required unless an API key SID + secret is provided.
|
|
22
|
+
*/
|
|
23
|
+
readonly authToken?: Maybe<TwilioAuthToken>;
|
|
24
|
+
/**
|
|
25
|
+
* Twilio API Key SID. When provided together with `apiKeySecret`, this is used in place of the
|
|
26
|
+
* raw auth token when authenticating SDK requests.
|
|
27
|
+
*/
|
|
28
|
+
readonly apiKeySid?: Maybe<TwilioApiKeySid>;
|
|
29
|
+
/**
|
|
30
|
+
* Secret value paired with `apiKeySid`.
|
|
31
|
+
*/
|
|
32
|
+
readonly apiKeySecret?: Maybe<TwilioApiKeySecret>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Default values for outbound message sends.
|
|
36
|
+
*/
|
|
37
|
+
export interface TwilioMessagesConfig {
|
|
38
|
+
/**
|
|
39
|
+
* Default sender phone number (E.164). Optional if `messagingServiceSid` is provided.
|
|
40
|
+
*/
|
|
41
|
+
readonly defaultFrom?: Maybe<TwilioPhoneNumber>;
|
|
42
|
+
/**
|
|
43
|
+
* Default Twilio Messaging Service SID. When set, Twilio chooses the sender from the
|
|
44
|
+
* messaging service's number pool.
|
|
45
|
+
*/
|
|
46
|
+
readonly messagingServiceSid?: Maybe<TwilioMessagingServiceSid>;
|
|
47
|
+
/**
|
|
48
|
+
* Default status callback URL applied to outbound messages when the caller does not
|
|
49
|
+
* supply one explicitly.
|
|
50
|
+
*/
|
|
51
|
+
readonly defaultStatusCallback?: Maybe<TwilioStatusCallbackUrl>;
|
|
52
|
+
/**
|
|
53
|
+
* When true, suppresses real SDK calls and returns a synthetic result. Mirrors the
|
|
54
|
+
* mailgun sandbox flag for local development and testing.
|
|
55
|
+
*/
|
|
56
|
+
readonly sandbox?: Maybe<boolean>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Configuration for {@link TwilioApi} and {@link TwilioService}.
|
|
60
|
+
*/
|
|
61
|
+
export declare abstract class TwilioServiceConfig {
|
|
62
|
+
/**
|
|
63
|
+
* Client credentials.
|
|
64
|
+
*/
|
|
65
|
+
readonly twilio: TwilioCredentials;
|
|
66
|
+
/**
|
|
67
|
+
* Outbound message defaults.
|
|
68
|
+
*/
|
|
69
|
+
readonly messages: TwilioMessagesConfig;
|
|
70
|
+
static assertValidConfig(config: TwilioServiceConfig): void;
|
|
71
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ConfigService } from '@nestjs/config';
|
|
2
|
+
import { TwilioServiceConfig } from './twilio.config';
|
|
3
|
+
/**
|
|
4
|
+
* Factory that creates a {@link TwilioServiceConfig} from environment variables.
|
|
5
|
+
*
|
|
6
|
+
* @param configService - NestJS config service for reading environment variables.
|
|
7
|
+
* @returns A validated {@link TwilioServiceConfig}.
|
|
8
|
+
*/
|
|
9
|
+
export declare function twilioServiceConfigFactory(configService: ConfigService): TwilioServiceConfig;
|
|
10
|
+
/**
|
|
11
|
+
* NestJS module that provides the {@link TwilioApi} and {@link TwilioService} for sending SMS
|
|
12
|
+
* via Twilio.
|
|
13
|
+
*
|
|
14
|
+
* Reads Twilio credentials and default sender configuration from environment variables.
|
|
15
|
+
*/
|
|
16
|
+
export declare class TwilioModule {
|
|
17
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type Maybe } from '@dereekb/util';
|
|
2
|
+
import { TwilioApi } from './twilio.api';
|
|
3
|
+
import { type TwilioMessageSid, type TwilioMessageStatus, type TwilioMessagingServiceSid, type TwilioPhoneNumber, type TwilioStatusCallbackUrl } from './twilio.type';
|
|
4
|
+
/**
|
|
5
|
+
* Maximum number of concurrent SMS send requests issued by {@link TwilioService.sendBulkSms}.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_TWILIO_SEND_SMS_MAX_PARALLEL_TASKS = 5;
|
|
8
|
+
/**
|
|
9
|
+
* Input for sending a single SMS message via Twilio.
|
|
10
|
+
*/
|
|
11
|
+
export interface TwilioSendSmsInput {
|
|
12
|
+
/**
|
|
13
|
+
* Recipient phone number in E.164 format.
|
|
14
|
+
*/
|
|
15
|
+
readonly to: TwilioPhoneNumber;
|
|
16
|
+
/**
|
|
17
|
+
* Message body. Twilio segments any body longer than 160 GSM-7 chars (or 70 UCS-2 chars).
|
|
18
|
+
*/
|
|
19
|
+
readonly body: string;
|
|
20
|
+
/**
|
|
21
|
+
* Sender phone number (E.164). Overrides the configured default. Ignored when
|
|
22
|
+
* `messagingServiceSid` is provided.
|
|
23
|
+
*/
|
|
24
|
+
readonly from?: Maybe<TwilioPhoneNumber>;
|
|
25
|
+
/**
|
|
26
|
+
* Twilio Messaging Service SID to send from. Overrides the configured default and
|
|
27
|
+
* takes precedence over `from`.
|
|
28
|
+
*/
|
|
29
|
+
readonly messagingServiceSid?: Maybe<TwilioMessagingServiceSid>;
|
|
30
|
+
/**
|
|
31
|
+
* Status callback URL. Overrides the configured default.
|
|
32
|
+
*/
|
|
33
|
+
readonly statusCallback?: Maybe<TwilioStatusCallbackUrl>;
|
|
34
|
+
/**
|
|
35
|
+
* Optional URLs of media (MMS) to attach.
|
|
36
|
+
*/
|
|
37
|
+
readonly mediaUrl?: Maybe<string[]>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Result of a single SMS send attempt.
|
|
41
|
+
*/
|
|
42
|
+
export interface TwilioSendSmsResult {
|
|
43
|
+
/**
|
|
44
|
+
* Twilio Message SID assigned by the API. `null` when the send was suppressed by sandbox mode.
|
|
45
|
+
*/
|
|
46
|
+
readonly sid: Maybe<TwilioMessageSid>;
|
|
47
|
+
/**
|
|
48
|
+
* Recipient phone number this result corresponds to.
|
|
49
|
+
*/
|
|
50
|
+
readonly to: TwilioPhoneNumber;
|
|
51
|
+
/**
|
|
52
|
+
* Twilio-reported status at the time of the API response.
|
|
53
|
+
*/
|
|
54
|
+
readonly status: TwilioMessageStatus;
|
|
55
|
+
/**
|
|
56
|
+
* When true, the message was suppressed by sandbox mode and never sent to Twilio.
|
|
57
|
+
*/
|
|
58
|
+
readonly sandboxed: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Error message captured if the send failed.
|
|
61
|
+
*/
|
|
62
|
+
readonly error?: Maybe<string>;
|
|
63
|
+
}
|
|
64
|
+
export declare class TwilioService {
|
|
65
|
+
private readonly logger;
|
|
66
|
+
private readonly _twilioApi;
|
|
67
|
+
constructor(twilioApi: TwilioApi);
|
|
68
|
+
get twilioApi(): TwilioApi;
|
|
69
|
+
/**
|
|
70
|
+
* Sends a single SMS through Twilio. Honors the configured sandbox flag.
|
|
71
|
+
*
|
|
72
|
+
* @param input - Recipient, body, and optional sender/callback/media overrides.
|
|
73
|
+
* @returns The result of the send attempt, including the Twilio Message SID on success.
|
|
74
|
+
*/
|
|
75
|
+
sendSms(input: TwilioSendSmsInput): Promise<TwilioSendSmsResult>;
|
|
76
|
+
/**
|
|
77
|
+
* Sends a batch of SMS messages through Twilio with bounded parallelism. Failures are
|
|
78
|
+
* captured per-message and never reject the returned promise.
|
|
79
|
+
*
|
|
80
|
+
* @param inputs - Array of SMS send inputs, one per recipient.
|
|
81
|
+
* @param maxParallelTasks - Maximum concurrent Twilio requests in flight.
|
|
82
|
+
* @returns One {@link TwilioSendSmsResult} per input, in input order.
|
|
83
|
+
*/
|
|
84
|
+
sendBulkSms(inputs: TwilioSendSmsInput[], maxParallelTasks?: number): Promise<TwilioSendSmsResult[]>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Provides a reference to a TwilioService instance.
|
|
88
|
+
*/
|
|
89
|
+
export interface TwilioServiceRef {
|
|
90
|
+
readonly twilioService: TwilioService;
|
|
91
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type E164PhoneNumber } from '@dereekb/util';
|
|
2
|
+
/**
|
|
3
|
+
* Twilio Account SID (starts with `AC`).
|
|
4
|
+
*/
|
|
5
|
+
export type TwilioAccountSid = string;
|
|
6
|
+
/**
|
|
7
|
+
* Twilio Auth Token used for API authentication.
|
|
8
|
+
*/
|
|
9
|
+
export type TwilioAuthToken = string;
|
|
10
|
+
/**
|
|
11
|
+
* Twilio API Key SID (starts with `SK`). Optional alternative to using the auth token directly.
|
|
12
|
+
*/
|
|
13
|
+
export type TwilioApiKeySid = string;
|
|
14
|
+
/**
|
|
15
|
+
* Secret value paired with a TwilioApiKeySid.
|
|
16
|
+
*/
|
|
17
|
+
export type TwilioApiKeySecret = string;
|
|
18
|
+
/**
|
|
19
|
+
* Twilio Messaging Service SID (starts with `MG`).
|
|
20
|
+
*/
|
|
21
|
+
export type TwilioMessagingServiceSid = string;
|
|
22
|
+
/**
|
|
23
|
+
* Twilio Verify Service SID (starts with `VA`).
|
|
24
|
+
*/
|
|
25
|
+
export type TwilioVerifyServiceSid = string;
|
|
26
|
+
/**
|
|
27
|
+
* Twilio Message SID (starts with `SM` or `MM`).
|
|
28
|
+
*/
|
|
29
|
+
export type TwilioMessageSid = string;
|
|
30
|
+
/**
|
|
31
|
+
* URL of a Twilio status callback endpoint.
|
|
32
|
+
*/
|
|
33
|
+
export type TwilioStatusCallbackUrl = string;
|
|
34
|
+
/**
|
|
35
|
+
* Phone number in E.164 format used as either a sender or recipient.
|
|
36
|
+
*/
|
|
37
|
+
export type TwilioPhoneNumber = E164PhoneNumber;
|
|
38
|
+
/**
|
|
39
|
+
* Status values reported by Twilio for a Message resource.
|
|
40
|
+
*
|
|
41
|
+
* https://www.twilio.com/docs/sms/api/message-resource#message-status-values
|
|
42
|
+
*/
|
|
43
|
+
export type TwilioMessageStatus = 'accepted' | 'queued' | 'sending' | 'sent' | 'receiving' | 'received' | 'delivered' | 'undelivered' | 'failed' | 'read' | 'canceled' | 'scheduled' | 'partially_delivered';
|
|
44
|
+
/**
|
|
45
|
+
* Status values reported by Twilio Verify for a verification attempt.
|
|
46
|
+
*
|
|
47
|
+
* https://www.twilio.com/docs/verify/api/verification#verification-properties
|
|
48
|
+
*/
|
|
49
|
+
export type TwilioVerificationStatus = 'pending' | 'approved' | 'canceled' | 'max_attempts_reached' | 'deleted' | 'failed' | 'expired';
|
|
50
|
+
/**
|
|
51
|
+
* Channel a Twilio Verify verification is delivered through.
|
|
52
|
+
*/
|
|
53
|
+
export type TwilioVerifyChannel = 'sms' | 'call' | 'email' | 'whatsapp';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TwilioApi } from '../twilio.api';
|
|
2
|
+
import { TwilioVerifyServiceConfig } from './verify.config';
|
|
3
|
+
export declare class TwilioVerifyApi {
|
|
4
|
+
private readonly _twilioApi;
|
|
5
|
+
private readonly _config;
|
|
6
|
+
constructor(twilioApi: TwilioApi, config: TwilioVerifyServiceConfig);
|
|
7
|
+
get twilioApi(): TwilioApi;
|
|
8
|
+
get verifyService(): import("twilio/lib/rest/verify/v2/service").ServiceContext;
|
|
9
|
+
get config(): TwilioVerifyServiceConfig;
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Maybe } from '@dereekb/util';
|
|
2
|
+
import { type TwilioVerifyServiceSid } from '../twilio.type';
|
|
3
|
+
export declare const TWILIO_VERIFY_SERVICE_SID_ENV_VAR = "TWILIO_VERIFY_SERVICE_SID";
|
|
4
|
+
export interface TwilioVerifyConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Twilio Verify Service SID. Required.
|
|
7
|
+
*/
|
|
8
|
+
readonly verifyServiceSid: TwilioVerifyServiceSid;
|
|
9
|
+
/**
|
|
10
|
+
* Default channel used when starting a verification.
|
|
11
|
+
*
|
|
12
|
+
* Defaults to `'sms'`.
|
|
13
|
+
*/
|
|
14
|
+
readonly defaultChannel?: Maybe<'sms' | 'call' | 'email' | 'whatsapp'>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Configuration for {@link TwilioVerifyApi} and {@link TwilioVerifyService}.
|
|
18
|
+
*/
|
|
19
|
+
export declare abstract class TwilioVerifyServiceConfig {
|
|
20
|
+
readonly twilioVerify: TwilioVerifyConfig;
|
|
21
|
+
static assertValidConfig(config: TwilioVerifyServiceConfig): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ConfigService } from '@nestjs/config';
|
|
2
|
+
import { TwilioVerifyServiceConfig } from './verify.config';
|
|
3
|
+
/**
|
|
4
|
+
* Factory that creates a {@link TwilioVerifyServiceConfig} from environment variables.
|
|
5
|
+
*
|
|
6
|
+
* @param configService - NestJS config service for reading environment variables.
|
|
7
|
+
* @returns A validated {@link TwilioVerifyServiceConfig}.
|
|
8
|
+
*/
|
|
9
|
+
export declare function twilioVerifyServiceConfigFactory(configService: ConfigService): TwilioVerifyServiceConfig;
|
|
10
|
+
/**
|
|
11
|
+
* NestJS module that exposes Twilio Verify (OTP / 2FA) for starting verifications and
|
|
12
|
+
* checking submitted codes.
|
|
13
|
+
*
|
|
14
|
+
* Imports {@link TwilioModule} for the underlying Twilio client.
|
|
15
|
+
*/
|
|
16
|
+
export declare class TwilioVerifyModule {
|
|
17
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type Maybe } from '@dereekb/util';
|
|
2
|
+
import { type TwilioPhoneNumber, type TwilioVerificationStatus, type TwilioVerifyChannel } from '../twilio.type';
|
|
3
|
+
import { TwilioVerifyApi } from './verify.api';
|
|
4
|
+
/**
|
|
5
|
+
* Input for starting a Twilio Verify check.
|
|
6
|
+
*/
|
|
7
|
+
export interface TwilioStartVerificationInput {
|
|
8
|
+
/**
|
|
9
|
+
* Recipient phone number / address (E.164 for SMS/call, email for email channel).
|
|
10
|
+
*/
|
|
11
|
+
readonly to: string;
|
|
12
|
+
/**
|
|
13
|
+
* Delivery channel. Defaults to the configured default channel.
|
|
14
|
+
*/
|
|
15
|
+
readonly channel?: Maybe<TwilioVerifyChannel>;
|
|
16
|
+
/**
|
|
17
|
+
* BCP-47 locale code for the verification message template (e.g. `en`, `es`).
|
|
18
|
+
*/
|
|
19
|
+
readonly locale?: Maybe<string>;
|
|
20
|
+
/**
|
|
21
|
+
* Optional custom code (Twilio Verify Premium feature).
|
|
22
|
+
*/
|
|
23
|
+
readonly customCode?: Maybe<string>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Result of a started verification.
|
|
27
|
+
*/
|
|
28
|
+
export interface TwilioStartVerificationResult {
|
|
29
|
+
readonly sid: string;
|
|
30
|
+
readonly to: string;
|
|
31
|
+
readonly channel: TwilioVerifyChannel;
|
|
32
|
+
readonly status: TwilioVerificationStatus;
|
|
33
|
+
readonly valid: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Input for checking a verification code.
|
|
37
|
+
*/
|
|
38
|
+
export interface TwilioCheckVerificationInput {
|
|
39
|
+
/**
|
|
40
|
+
* The phone number / address the code was sent to.
|
|
41
|
+
*/
|
|
42
|
+
readonly to: TwilioPhoneNumber | string;
|
|
43
|
+
/**
|
|
44
|
+
* The code supplied by the user.
|
|
45
|
+
*/
|
|
46
|
+
readonly code: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Result of a verification check.
|
|
50
|
+
*/
|
|
51
|
+
export interface TwilioCheckVerificationResult {
|
|
52
|
+
readonly sid: string;
|
|
53
|
+
readonly to: string;
|
|
54
|
+
readonly status: TwilioVerificationStatus;
|
|
55
|
+
readonly valid: boolean;
|
|
56
|
+
}
|
|
57
|
+
export declare class TwilioVerifyService {
|
|
58
|
+
private readonly _twilioVerifyApi;
|
|
59
|
+
constructor(twilioVerifyApi: TwilioVerifyApi);
|
|
60
|
+
get twilioVerifyApi(): TwilioVerifyApi;
|
|
61
|
+
/**
|
|
62
|
+
* Starts a verification for the given recipient. Twilio generates and dispatches the code.
|
|
63
|
+
*
|
|
64
|
+
* @param input - Recipient, optional channel override, optional locale and customCode.
|
|
65
|
+
* @returns The Twilio verification record (status, channel, SID).
|
|
66
|
+
*/
|
|
67
|
+
startVerification(input: TwilioStartVerificationInput): Promise<TwilioStartVerificationResult>;
|
|
68
|
+
/**
|
|
69
|
+
* Checks a previously-issued verification code.
|
|
70
|
+
*
|
|
71
|
+
* Returns `valid: true` only when Twilio reports the verification as `approved`.
|
|
72
|
+
*
|
|
73
|
+
* @param input - Recipient address and the submitted code.
|
|
74
|
+
* @returns The verification-check result, with `valid` reflecting Twilio's `approved` status.
|
|
75
|
+
*/
|
|
76
|
+
checkVerification(input: TwilioCheckVerificationInput): Promise<TwilioCheckVerificationResult>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Provides a reference to a TwilioVerifyService instance.
|
|
80
|
+
*/
|
|
81
|
+
export interface TwilioVerifyServiceRef {
|
|
82
|
+
readonly twilioVerifyService: TwilioVerifyService;
|
|
83
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Maybe } from '@dereekb/util';
|
|
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
|
+
export declare const TWILIO_WEBHOOK_SKIP_VERIFY_ENV_VAR = "TWILIO_WEBHOOK_SKIP_VERIFY";
|
|
5
|
+
export interface TwilioWebhookConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Twilio Auth Token used to verify the X-Twilio-Signature header. When unset, the value
|
|
8
|
+
* configured on {@link TwilioServiceConfig} is used.
|
|
9
|
+
*/
|
|
10
|
+
readonly authToken?: Maybe<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Base URL of the deployed webhook (e.g. `https://api.example.com`). Twilio computes the
|
|
13
|
+
* request signature over the full URL it called, so behind a proxy the public URL must be
|
|
14
|
+
* supplied here for verification to succeed.
|
|
15
|
+
*/
|
|
16
|
+
readonly baseUrl?: Maybe<string>;
|
|
17
|
+
/**
|
|
18
|
+
* When true, signature verification is skipped. Intended for local development against
|
|
19
|
+
* Twilio's test mode; never enable in production.
|
|
20
|
+
*/
|
|
21
|
+
readonly skipVerify?: Maybe<boolean>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Configuration for the Twilio webhook controller / service.
|
|
25
|
+
*/
|
|
26
|
+
export declare abstract class TwilioWebhookServiceConfig {
|
|
27
|
+
readonly twilioWebhook: TwilioWebhookConfig;
|
|
28
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type RawBodyBuffer } from '@dereekb/nestjs';
|
|
2
|
+
import { type Request } from 'express';
|
|
3
|
+
import { TwilioWebhookService } from './webhook.twilio.service';
|
|
4
|
+
export declare class TwilioWebhookController {
|
|
5
|
+
private readonly _twilioWebhookService;
|
|
6
|
+
constructor(twilioWebhookService: TwilioWebhookService);
|
|
7
|
+
handleStatus(req: Request, rawBody: RawBodyBuffer): Promise<void>;
|
|
8
|
+
handleIncoming(req: Request, rawBody: RawBodyBuffer): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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';
|
|
3
|
+
/**
|
|
4
|
+
* Twilio webhook event type.
|
|
5
|
+
*/
|
|
6
|
+
export type TwilioWebhookEventType = 'status' | 'incoming';
|
|
7
|
+
/**
|
|
8
|
+
* Parameters delivered by Twilio for a Message status callback.
|
|
9
|
+
*
|
|
10
|
+
* https://www.twilio.com/docs/messaging/api/message-resource#message-status-callback-parameters
|
|
11
|
+
*/
|
|
12
|
+
export interface TwilioStatusCallbackPayload {
|
|
13
|
+
readonly MessageSid: TwilioMessageSid;
|
|
14
|
+
readonly MessageStatus: TwilioMessageStatus;
|
|
15
|
+
readonly AccountSid: TwilioAccountSid;
|
|
16
|
+
readonly From?: Maybe<TwilioPhoneNumber>;
|
|
17
|
+
readonly To?: Maybe<TwilioPhoneNumber>;
|
|
18
|
+
readonly ApiVersion?: Maybe<string>;
|
|
19
|
+
readonly ErrorCode?: Maybe<string>;
|
|
20
|
+
readonly ErrorMessage?: Maybe<string>;
|
|
21
|
+
/**
|
|
22
|
+
* The full set of fields Twilio sent, in case the consumer needs non-standard ones.
|
|
23
|
+
*/
|
|
24
|
+
readonly raw: Readonly<Record<string, string>>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parameters delivered by Twilio for an incoming SMS / MMS.
|
|
28
|
+
*
|
|
29
|
+
* https://www.twilio.com/docs/messaging/guides/webhook-request#incoming-message-parameters
|
|
30
|
+
*/
|
|
31
|
+
export interface TwilioIncomingMessagePayload {
|
|
32
|
+
readonly MessageSid: TwilioMessageSid;
|
|
33
|
+
readonly AccountSid: TwilioAccountSid;
|
|
34
|
+
readonly From: TwilioPhoneNumber;
|
|
35
|
+
readonly To: TwilioPhoneNumber;
|
|
36
|
+
readonly Body: string;
|
|
37
|
+
readonly NumMedia: number;
|
|
38
|
+
readonly NumSegments?: Maybe<number>;
|
|
39
|
+
readonly FromCity?: Maybe<string>;
|
|
40
|
+
readonly FromState?: Maybe<string>;
|
|
41
|
+
readonly FromZip?: Maybe<string>;
|
|
42
|
+
readonly FromCountry?: Maybe<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Resolved MediaUrl0..MediaUrlN entries, ordered by index. Empty array when no media.
|
|
45
|
+
*/
|
|
46
|
+
readonly mediaUrls: readonly string[];
|
|
47
|
+
/**
|
|
48
|
+
* The full set of fields Twilio sent.
|
|
49
|
+
*/
|
|
50
|
+
readonly raw: Readonly<Record<string, string>>;
|
|
51
|
+
}
|
|
52
|
+
export type TwilioStatusCallbackEvent = {
|
|
53
|
+
readonly type: 'status';
|
|
54
|
+
readonly payload: TwilioStatusCallbackPayload;
|
|
55
|
+
};
|
|
56
|
+
export type TwilioIncomingMessageEvent = {
|
|
57
|
+
readonly type: 'incoming';
|
|
58
|
+
readonly payload: TwilioIncomingMessagePayload;
|
|
59
|
+
};
|
|
60
|
+
export type TwilioWebhookEvent = TwilioStatusCallbackEvent | TwilioIncomingMessageEvent;
|
|
61
|
+
export declare const twilioWebhookEventHandlerFactory: import("@dereekb/util").HandlerFactory<TwilioWebhookEvent, TwilioWebhookEventType, boolean>;
|
|
62
|
+
export type TwilioHandlerMappedSetFunction<T extends TwilioWebhookEvent = TwilioWebhookEvent> = HandlerMappedSetFunction<T>;
|
|
63
|
+
export interface TwilioWebhookEventHandlerConfigurer extends HandlerBindAccessor<TwilioWebhookEvent, TwilioWebhookEventType> {
|
|
64
|
+
readonly handleStatusCallback: TwilioHandlerMappedSetFunction<TwilioStatusCallbackEvent>;
|
|
65
|
+
readonly handleIncomingMessage: TwilioHandlerMappedSetFunction<TwilioIncomingMessageEvent>;
|
|
66
|
+
}
|
|
67
|
+
export declare const twilioWebhookEventHandlerConfigurerFactory: import("@dereekb/util").HandlerConfigurerFactory<TwilioWebhookEventHandlerConfigurer, TwilioWebhookEvent, TwilioWebhookEventType, boolean>;
|
|
68
|
+
export type TwilioWebhookEventHandler = Handler<TwilioWebhookEvent, TwilioWebhookEventType>;
|