Auto-commit 2026-04-29 16:31
This commit is contained in:
34
node_modules/twilio/lib/base/ApiResponse.d.ts
generated
vendored
Normal file
34
node_modules/twilio/lib/base/ApiResponse.d.ts
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* API Response wrapper containing HTTP metadata
|
||||
*
|
||||
* This interface is returned by *WithHttpInfo methods and provides access to:
|
||||
* - The response data (resource instance, page, or boolean)
|
||||
* - HTTP status code
|
||||
* - Response headers
|
||||
*/
|
||||
export interface ApiResponse<T> {
|
||||
/**
|
||||
* The response data
|
||||
* - For create/fetch/update: Resource instance
|
||||
* - For delete/remove: boolean indicating success
|
||||
* - For page: Page object
|
||||
*/
|
||||
body: T;
|
||||
/**
|
||||
* HTTP status code from the response
|
||||
* - 200: Success (fetch, update)
|
||||
* - 201: Created (create)
|
||||
* - 204: No Content (delete)
|
||||
* - 4xx/5xx: Error responses
|
||||
*/
|
||||
statusCode: number;
|
||||
/**
|
||||
* Response headers as key-value pairs
|
||||
* Common headers include:
|
||||
* - Content-Type
|
||||
* - X-RateLimit-Remaining
|
||||
* - X-RateLimit-Limit
|
||||
* - X-Request-ID
|
||||
*/
|
||||
headers: Record<string, string>;
|
||||
}
|
||||
2
node_modules/twilio/lib/base/ApiResponse.js
generated
vendored
Normal file
2
node_modules/twilio/lib/base/ApiResponse.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
121
node_modules/twilio/lib/base/BaseTwilio.d.ts
generated
vendored
Normal file
121
node_modules/twilio/lib/base/BaseTwilio.d.ts
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
import RequestClient from "./RequestClient";
|
||||
import { ValidationClientOptions } from "./ValidationClient";
|
||||
import { HttpMethod } from "../interfaces";
|
||||
import { Headers } from "../http/request";
|
||||
import AuthStrategy from "../auth_strategy/AuthStrategy";
|
||||
import CredentialProvider from "../credential_provider/CredentialProvider";
|
||||
declare namespace Twilio {
|
||||
interface ClientOpts {
|
||||
httpClient?: RequestClient;
|
||||
accountSid?: string;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
edge?: string;
|
||||
region?: string;
|
||||
lazyLoading?: boolean;
|
||||
logLevel?: string;
|
||||
userAgentExtensions?: string[];
|
||||
autoRetry?: boolean;
|
||||
maxRetryDelay?: number;
|
||||
maxRetries?: number;
|
||||
validationClient?: ValidationClientOptions;
|
||||
/**
|
||||
https.Agent options
|
||||
*/
|
||||
timeout?: number;
|
||||
keepAlive?: boolean;
|
||||
keepAliveMsecs?: number;
|
||||
maxSockets?: number;
|
||||
maxTotalSockets?: number;
|
||||
maxFreeSockets?: number;
|
||||
scheduling?: "fifo" | "lifo" | undefined;
|
||||
ca?: string | Buffer;
|
||||
}
|
||||
interface RequestOpts {
|
||||
method?: HttpMethod;
|
||||
uri?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
authStrategy?: AuthStrategy;
|
||||
headers?: Headers;
|
||||
params?: object;
|
||||
data?: object;
|
||||
timeout?: number;
|
||||
allowRedirects?: boolean;
|
||||
logLevel?: string;
|
||||
}
|
||||
/**
|
||||
* Parent class for Twilio Client that implements request & validation logic
|
||||
*/
|
||||
class Client {
|
||||
username?: string;
|
||||
password?: string;
|
||||
accountSid: string;
|
||||
credentialProvider?: CredentialProvider;
|
||||
opts?: ClientOpts;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
edge?: string;
|
||||
region?: string;
|
||||
logLevel?: string;
|
||||
autoRetry?: boolean;
|
||||
maxRetryDelay?: number;
|
||||
maxRetries?: number;
|
||||
validationClient?: ValidationClientOptions;
|
||||
/**
|
||||
https.Agent options
|
||||
*/
|
||||
timeout?: number;
|
||||
keepAlive?: boolean;
|
||||
keepAliveMsecs?: number;
|
||||
maxSockets?: number;
|
||||
maxTotalSockets?: number;
|
||||
maxFreeSockets?: number;
|
||||
scheduling?: "fifo" | "lifo" | undefined;
|
||||
ca?: string | Buffer;
|
||||
userAgentExtensions?: string[];
|
||||
_httpClient?: RequestClient;
|
||||
/**
|
||||
* Create a BaseTwilio instance
|
||||
*
|
||||
* @param username -
|
||||
* The username used for authentication. This is normally account sid, but if using key/secret auth will be
|
||||
* the api key sid.
|
||||
* @param password -
|
||||
* The password used for authentication. This is normally auth token, but if using key/secret auth will be
|
||||
* the secret.
|
||||
* @param opts - The options argument
|
||||
*
|
||||
* @returns A new instance of BaseTwilio
|
||||
*/
|
||||
constructor(username?: string, password?: string, opts?: ClientOpts);
|
||||
setOpts(opts?: ClientOpts): void;
|
||||
setAccountSid(accountSid?: string): void;
|
||||
setCredentialProvider(credentialProvider: CredentialProvider): void;
|
||||
invalidateBasicAuth(): void;
|
||||
invalidateOAuth(): void;
|
||||
get httpClient(): RequestClient;
|
||||
/**
|
||||
* Makes a request to the Twilio API using the configured http client.
|
||||
* Authentication information is automatically added if none is provided.
|
||||
*
|
||||
* @param opts - The options argument
|
||||
*/
|
||||
request(opts: RequestOpts): Promise<any>;
|
||||
/**
|
||||
* Adds a region and/or edge to a given hostname
|
||||
*
|
||||
* @param hostname - A URI hostname (e.g. api.twilio.com)
|
||||
* @param targetEdge - The targeted edge location (e.g. sydney)
|
||||
* @param targetRegion - The targeted region location (e.g. au1)
|
||||
*/
|
||||
getHostname(hostname: string, targetEdge: string | undefined, targetRegion: string | undefined): string;
|
||||
/**
|
||||
* Test if your environment is impacted by a TLS or certificate
|
||||
* change is by sending an HTTP request to the test endpoint
|
||||
*
|
||||
* @throws RestException if the request fails
|
||||
*
|
||||
*/
|
||||
validateSslCert(): Promise<any>;
|
||||
}
|
||||
}
|
||||
export = Twilio;
|
||||
232
node_modules/twilio/lib/base/BaseTwilio.js
generated
vendored
Normal file
232
node_modules/twilio/lib/base/BaseTwilio.js
generated
vendored
Normal file
@@ -0,0 +1,232 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
const RequestClient_1 = __importDefault(require("./RequestClient")); /* jshint ignore:line */
|
||||
const os = require("os"); /* jshint ignore:line */
|
||||
const url = require("url"); /* jshint ignore:line */
|
||||
const moduleInfo = require("../../package.json"); /* jshint ignore:line */
|
||||
const util = require("util"); /* jshint ignore:line */
|
||||
const RestException = require("../base/RestException"); /* jshint ignore:line */
|
||||
var Twilio;
|
||||
(function (Twilio) {
|
||||
/* jshint ignore:start */
|
||||
/**
|
||||
* Parent class for Twilio Client that implements request & validation logic
|
||||
*/
|
||||
/* jshint ignore:end */
|
||||
class Client {
|
||||
/* jshint ignore:start */
|
||||
/**
|
||||
* Create a BaseTwilio instance
|
||||
*
|
||||
* @param username -
|
||||
* The username used for authentication. This is normally account sid, but if using key/secret auth will be
|
||||
* the api key sid.
|
||||
* @param password -
|
||||
* The password used for authentication. This is normally auth token, but if using key/secret auth will be
|
||||
* the secret.
|
||||
* @param opts - The options argument
|
||||
*
|
||||
* @returns A new instance of BaseTwilio
|
||||
*/
|
||||
/* jshint ignore:end */
|
||||
constructor(username, password, opts) {
|
||||
this.setOpts(opts);
|
||||
this.username =
|
||||
username ??
|
||||
this.env?.TWILIO_ACCOUNT_SID ??
|
||||
process.env.TWILIO_ACCOUNT_SID;
|
||||
this.password =
|
||||
password ??
|
||||
this.env?.TWILIO_AUTH_TOKEN ??
|
||||
process.env.TWILIO_AUTH_TOKEN;
|
||||
this.accountSid = "";
|
||||
this.setAccountSid(this.opts?.accountSid || this.username);
|
||||
this.invalidateOAuth();
|
||||
}
|
||||
setOpts(opts) {
|
||||
this.opts = opts || {};
|
||||
this.env = this.opts.env || {};
|
||||
this.edge =
|
||||
this.opts.edge ?? this.env.TWILIO_EDGE ?? process.env.TWILIO_EDGE;
|
||||
this.region =
|
||||
this.opts.region ?? this.env.TWILIO_REGION ?? process.env.TWILIO_REGION;
|
||||
this.logLevel =
|
||||
this.opts.logLevel ??
|
||||
this.env.TWILIO_LOG_LEVEL ??
|
||||
process.env.TWILIO_LOG_LEVEL;
|
||||
this.timeout = this.opts.timeout;
|
||||
this.keepAlive = this.opts.keepAlive;
|
||||
this.keepAliveMsecs = this.opts.keepAliveMsecs;
|
||||
this.maxSockets = this.opts.maxSockets;
|
||||
this.maxTotalSockets = this.opts.maxTotalSockets;
|
||||
this.maxFreeSockets = this.opts.maxFreeSockets;
|
||||
this.scheduling = this.opts.scheduling;
|
||||
this.ca = this.opts.ca;
|
||||
this.autoRetry = this.opts.autoRetry || false;
|
||||
this.maxRetryDelay = this.opts.maxRetryDelay;
|
||||
this.maxRetries = this.opts.maxRetries;
|
||||
this.validationClient = this.opts.validationClient;
|
||||
this.userAgentExtensions = this.opts.userAgentExtensions || [];
|
||||
this._httpClient = this.opts.httpClient;
|
||||
if (this.opts.lazyLoading === false) {
|
||||
this._httpClient = this.httpClient;
|
||||
}
|
||||
}
|
||||
setAccountSid(accountSid) {
|
||||
this.accountSid = accountSid || "";
|
||||
if (this.accountSid && !this.accountSid?.startsWith("AC")) {
|
||||
const apiKeyMsg = this.accountSid?.startsWith("SK")
|
||||
? ". The given SID indicates an API Key which requires the accountSid to be passed as an additional option"
|
||||
: "";
|
||||
throw new Error("accountSid must start with AC" + apiKeyMsg);
|
||||
}
|
||||
}
|
||||
setCredentialProvider(credentialProvider) {
|
||||
this.credentialProvider = credentialProvider;
|
||||
this.accountSid = "";
|
||||
this.invalidateBasicAuth();
|
||||
}
|
||||
invalidateBasicAuth() {
|
||||
this.username = undefined;
|
||||
this.password = undefined;
|
||||
}
|
||||
invalidateOAuth() {
|
||||
this.credentialProvider = undefined;
|
||||
}
|
||||
get httpClient() {
|
||||
if (!this._httpClient) {
|
||||
this._httpClient = new RequestClient_1.default({
|
||||
timeout: this.timeout,
|
||||
keepAlive: this.keepAlive,
|
||||
keepAliveMsecs: this.keepAliveMsecs,
|
||||
maxSockets: this.maxSockets,
|
||||
maxTotalSockets: this.maxTotalSockets,
|
||||
maxFreeSockets: this.maxFreeSockets,
|
||||
scheduling: this.scheduling,
|
||||
ca: this.ca,
|
||||
autoRetry: this.autoRetry,
|
||||
maxRetryDelay: this.maxRetryDelay,
|
||||
maxRetries: this.maxRetries,
|
||||
validationClient: this.validationClient,
|
||||
});
|
||||
}
|
||||
return this._httpClient;
|
||||
}
|
||||
/* jshint ignore:start */
|
||||
/**
|
||||
* Makes a request to the Twilio API using the configured http client.
|
||||
* Authentication information is automatically added if none is provided.
|
||||
*
|
||||
* @param opts - The options argument
|
||||
*/
|
||||
/* jshint ignore:end */
|
||||
request(opts) {
|
||||
opts = opts || {};
|
||||
if (!opts.method) {
|
||||
throw new Error("method is required");
|
||||
}
|
||||
if (!opts.uri) {
|
||||
throw new Error("uri is required");
|
||||
}
|
||||
const username = opts.username || this.username;
|
||||
const password = opts.password || this.password;
|
||||
const authStrategy = opts.authStrategy || this.credentialProvider?.toAuthStrategy();
|
||||
if (!authStrategy) {
|
||||
if (!username) {
|
||||
(() => {
|
||||
throw new Error("username is required");
|
||||
})();
|
||||
}
|
||||
if (!password) {
|
||||
(() => {
|
||||
throw new Error("password is required");
|
||||
})();
|
||||
}
|
||||
}
|
||||
const headers = opts.headers || {};
|
||||
const pkgVersion = moduleInfo.version;
|
||||
const osName = os.platform();
|
||||
const osArch = os.arch();
|
||||
const nodeVersion = process.version;
|
||||
headers["User-Agent"] = util.format("twilio-node/%s (%s %s) node/%s", pkgVersion, osName, osArch, nodeVersion);
|
||||
this.userAgentExtensions?.forEach((extension) => {
|
||||
headers["User-Agent"] += ` ${extension}`;
|
||||
});
|
||||
headers["Accept-Charset"] = "utf-8";
|
||||
if ((opts.method === "post" || opts.method === "put") &&
|
||||
!headers["Content-Type"]) {
|
||||
headers["Content-Type"] = "application/x-www-form-urlencoded";
|
||||
}
|
||||
if (opts.method !== "delete" && !headers["Accept"]) {
|
||||
headers["Accept"] = "application/json";
|
||||
}
|
||||
var uri = new url.URL(opts.uri);
|
||||
uri.hostname = this.getHostname(uri.hostname, this.edge, this.region);
|
||||
return this.httpClient?.request({
|
||||
method: opts.method,
|
||||
uri: uri.href,
|
||||
username: username,
|
||||
password: password,
|
||||
authStrategy: authStrategy,
|
||||
headers: headers,
|
||||
params: opts.params,
|
||||
data: opts.data,
|
||||
timeout: opts.timeout,
|
||||
allowRedirects: opts.allowRedirects,
|
||||
// use the Twilio client's log-level if the httpClient's log-level is unspecified
|
||||
logLevel: opts.logLevel || this.opts?.logLevel,
|
||||
});
|
||||
}
|
||||
/* jshint ignore:start */
|
||||
/**
|
||||
* Adds a region and/or edge to a given hostname
|
||||
*
|
||||
* @param hostname - A URI hostname (e.g. api.twilio.com)
|
||||
* @param targetEdge - The targeted edge location (e.g. sydney)
|
||||
* @param targetRegion - The targeted region location (e.g. au1)
|
||||
*/
|
||||
/* jshint ignore:end */
|
||||
getHostname(hostname, targetEdge, targetRegion) {
|
||||
const defaultRegion = "us1";
|
||||
const domain = hostname.split(".").slice(-2).join(".");
|
||||
const prefix = hostname.split("." + domain)[0];
|
||||
let [product, edge, region] = prefix.split(".");
|
||||
if (edge && !region) {
|
||||
region = edge;
|
||||
edge = undefined;
|
||||
}
|
||||
region = targetRegion || region || (targetEdge && defaultRegion);
|
||||
if (!region) {
|
||||
return hostname;
|
||||
}
|
||||
edge = targetEdge || edge;
|
||||
return [product, edge, region, domain].filter((part) => part).join(".");
|
||||
}
|
||||
/* jshint ignore:start */
|
||||
/**
|
||||
* Test if your environment is impacted by a TLS or certificate
|
||||
* change is by sending an HTTP request to the test endpoint
|
||||
*
|
||||
* @throws RestException if the request fails
|
||||
*
|
||||
*/
|
||||
/* jshint ignore:end */
|
||||
validateSslCert() {
|
||||
return this.httpClient
|
||||
?.request({
|
||||
method: "get",
|
||||
uri: "https://tls-test.twilio.com:443",
|
||||
})
|
||||
.then((response) => {
|
||||
if (response["statusCode"] < 200 || response["statusCode"] >= 300) {
|
||||
throw new RestException(response);
|
||||
}
|
||||
return response;
|
||||
});
|
||||
}
|
||||
}
|
||||
Twilio.Client = Client;
|
||||
})(Twilio || (Twilio = {}));
|
||||
module.exports = Twilio;
|
||||
29
node_modules/twilio/lib/base/Domain.d.ts
generated
vendored
Normal file
29
node_modules/twilio/lib/base/Domain.d.ts
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Client as BaseTwilio, RequestOpts } from "./BaseTwilio";
|
||||
/**
|
||||
* Base domain object
|
||||
*/
|
||||
export default class Domain {
|
||||
twilio: BaseTwilio;
|
||||
baseUrl: string;
|
||||
/**
|
||||
* Creates a Domain instance
|
||||
*
|
||||
* @param twilio - A Twilio Client
|
||||
* @param baseUrl - Base url for this domain
|
||||
*/
|
||||
constructor(twilio: BaseTwilio, baseUrl: string);
|
||||
/**
|
||||
* Turn a uri into an absolute url
|
||||
*
|
||||
* @param uri - uri to transform
|
||||
* @returns absolute url
|
||||
*/
|
||||
absoluteUrl(uri?: string): string;
|
||||
/**
|
||||
* Make request to this domain
|
||||
*
|
||||
* @param opts - request options
|
||||
* @returns request promise
|
||||
*/
|
||||
request(opts: RequestOpts): Promise<any>;
|
||||
}
|
||||
53
node_modules/twilio/lib/base/Domain.js
generated
vendored
Normal file
53
node_modules/twilio/lib/base/Domain.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const utility_1 = require("./utility");
|
||||
/**
|
||||
* Base domain object
|
||||
*/
|
||||
class Domain {
|
||||
/**
|
||||
* Creates a Domain instance
|
||||
*
|
||||
* @param twilio - A Twilio Client
|
||||
* @param baseUrl - Base url for this domain
|
||||
*/
|
||||
constructor(twilio, baseUrl) {
|
||||
this.twilio = twilio;
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
/**
|
||||
* Turn a uri into an absolute url
|
||||
*
|
||||
* @param uri - uri to transform
|
||||
* @returns absolute url
|
||||
*/
|
||||
absoluteUrl(uri) {
|
||||
var result = "";
|
||||
if (typeof this.baseUrl === "string") {
|
||||
const cleanBaseUrl = (0, utility_1.trim)(this.baseUrl, "/");
|
||||
result += cleanBaseUrl;
|
||||
result += "/";
|
||||
}
|
||||
if (typeof uri === "string") {
|
||||
uri = (0, utility_1.trim)(uri, "/");
|
||||
if (result === "") {
|
||||
result += "/";
|
||||
}
|
||||
result += uri;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Make request to this domain
|
||||
*
|
||||
* @param opts - request options
|
||||
* @returns request promise
|
||||
*/
|
||||
request(opts) {
|
||||
return this.twilio.request({
|
||||
...opts,
|
||||
uri: this.absoluteUrl(opts.uri),
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.default = Domain;
|
||||
104
node_modules/twilio/lib/base/Page.d.ts
generated
vendored
Normal file
104
node_modules/twilio/lib/base/Page.d.ts
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
import Version from "./Version";
|
||||
import Response from "../http/response";
|
||||
export interface TwilioResponsePayload {
|
||||
[key: string]: any;
|
||||
first_page_uri: string;
|
||||
next_page_uri: string;
|
||||
page: number;
|
||||
page_size: number;
|
||||
previous_page_uri: string;
|
||||
uri: string;
|
||||
meta?: {
|
||||
key?: string;
|
||||
next_page_url?: string;
|
||||
previous_page_url?: string;
|
||||
};
|
||||
}
|
||||
interface Solution {
|
||||
[name: string]: any;
|
||||
}
|
||||
export default class Page<TVersion extends Version, TPayload extends TwilioResponsePayload, TResource, TInstance> {
|
||||
nextPageUrl?: string;
|
||||
previousPageUrl?: string;
|
||||
instances: TInstance[];
|
||||
_version: TVersion;
|
||||
_payload: TPayload;
|
||||
_solution: Solution;
|
||||
/**
|
||||
*
|
||||
* Base page object to maintain request state.
|
||||
*
|
||||
* @param version - A twilio version instance
|
||||
* @param response - The http response
|
||||
* @param solution - path solution
|
||||
*/
|
||||
constructor(version: TVersion, response: Response<string | TPayload>, solution: Solution);
|
||||
/**
|
||||
* Meta keys returned in a list request
|
||||
*
|
||||
* @constant META_KEYS
|
||||
*/
|
||||
static META_KEYS: string[];
|
||||
/**
|
||||
* Get the url of the previous page of records
|
||||
*
|
||||
* @returns url of the previous page, or undefined if the
|
||||
* previous page URI/URL is not defined.
|
||||
*/
|
||||
getPreviousPageUrl(): string | undefined;
|
||||
/**
|
||||
* Get the url of the next page of records
|
||||
*
|
||||
* @returns url of the next page, or undefined if the
|
||||
* next page URI/URL is not defined.
|
||||
*/
|
||||
getNextPageUrl(): string | undefined;
|
||||
/**
|
||||
* Build a new instance given a json payload
|
||||
*
|
||||
* @param payload - Payload response from the API
|
||||
* @returns instance of a resource
|
||||
*/
|
||||
getInstance(payload: any): TInstance;
|
||||
/**
|
||||
* Load a list of records
|
||||
*
|
||||
* @param resources - json payload of records
|
||||
* @returns list of resources
|
||||
*/
|
||||
loadInstances(resources: TResource[]): TInstance[];
|
||||
/**
|
||||
* Fetch the next page of records
|
||||
*
|
||||
* @returns promise that resolves to next page of results,
|
||||
* or undefined if there isn't a nextPageUrl undefined.
|
||||
*/
|
||||
nextPage(): Promise<Page<TVersion, TPayload, TResource, TInstance>> | undefined;
|
||||
/**
|
||||
* Fetch the previous page of records
|
||||
*
|
||||
* @returns promise that resolves to previous page of
|
||||
* results, or undefined if there isn't a previousPageUrl undefined.
|
||||
*/
|
||||
previousPage(): Promise<Page<TVersion, TPayload, TResource, TInstance>> | undefined;
|
||||
/**
|
||||
* Parse json response from API
|
||||
*
|
||||
* @param response - API response
|
||||
*
|
||||
* @throws Error If non 200 status code is returned
|
||||
*
|
||||
* @returns json parsed response
|
||||
*/
|
||||
processResponse(response: Response<string | TPayload>): TPayload;
|
||||
/**
|
||||
* Load a page of records
|
||||
*
|
||||
* @param {object} payload json payload
|
||||
* @return {array} the page of records
|
||||
*/
|
||||
loadPage(payload: TPayload): TResource[];
|
||||
forOwn(obj: object, iteratee: (val: any, key: string, object: object) => void): void;
|
||||
toJSON(): object;
|
||||
}
|
||||
export {};
|
||||
195
node_modules/twilio/lib/base/Page.js
generated
vendored
Normal file
195
node_modules/twilio/lib/base/Page.js
generated
vendored
Normal file
@@ -0,0 +1,195 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const RestException_1 = __importDefault(require("./RestException"));
|
||||
class Page {
|
||||
/**
|
||||
*
|
||||
* Base page object to maintain request state.
|
||||
*
|
||||
* @param version - A twilio version instance
|
||||
* @param response - The http response
|
||||
* @param solution - path solution
|
||||
*/
|
||||
constructor(version, response, solution) {
|
||||
let payload = this.processResponse(response);
|
||||
this._version = version;
|
||||
this._payload = payload;
|
||||
this._solution = solution;
|
||||
this.nextPageUrl = this.getNextPageUrl();
|
||||
this.previousPageUrl = this.getPreviousPageUrl();
|
||||
this.instances = this.loadInstances(this.loadPage(payload));
|
||||
}
|
||||
/**
|
||||
* Get the url of the previous page of records
|
||||
*
|
||||
* @returns url of the previous page, or undefined if the
|
||||
* previous page URI/URL is not defined.
|
||||
*/
|
||||
getPreviousPageUrl() {
|
||||
if (this._payload.meta &&
|
||||
"previous_page_url" in this._payload.meta &&
|
||||
this._payload.meta.previous_page_url) {
|
||||
// jshint ignore:line
|
||||
return this._payload.meta.previous_page_url; // jshint ignore:line
|
||||
}
|
||||
if ("previous_page_uri" in this._payload &&
|
||||
this._payload.previous_page_uri) {
|
||||
// jshint ignore:line
|
||||
return this._version._domain.absoluteUrl(this._payload.previous_page_uri); // jshint ignore:line
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/**
|
||||
* Get the url of the next page of records
|
||||
*
|
||||
* @returns url of the next page, or undefined if the
|
||||
* next page URI/URL is not defined.
|
||||
*/
|
||||
getNextPageUrl() {
|
||||
if (this._payload.meta &&
|
||||
"next_page_url" in this._payload.meta &&
|
||||
this._payload.meta.next_page_url) {
|
||||
// jshint ignore:line
|
||||
return this._payload.meta.next_page_url; // jshint ignore:line
|
||||
}
|
||||
if ("next_page_uri" in this._payload && this._payload.next_page_uri) {
|
||||
// jshint ignore:line
|
||||
return this._version._domain.absoluteUrl(this._payload.next_page_uri); // jshint ignore:line
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/**
|
||||
* Build a new instance given a json payload
|
||||
*
|
||||
* @param payload - Payload response from the API
|
||||
* @returns instance of a resource
|
||||
*/
|
||||
getInstance(payload) {
|
||||
throw new Error("Page.get_instance() must be implemented in the derived class");
|
||||
}
|
||||
/**
|
||||
* Load a list of records
|
||||
*
|
||||
* @param resources - json payload of records
|
||||
* @returns list of resources
|
||||
*/
|
||||
loadInstances(resources) {
|
||||
let instances = [];
|
||||
resources.forEach((resource) => {
|
||||
instances.push(this.getInstance(resource));
|
||||
});
|
||||
return instances;
|
||||
}
|
||||
/**
|
||||
* Fetch the next page of records
|
||||
*
|
||||
* @returns promise that resolves to next page of results,
|
||||
* or undefined if there isn't a nextPageUrl undefined.
|
||||
*/
|
||||
nextPage() {
|
||||
if (!this.nextPageUrl) {
|
||||
return undefined;
|
||||
}
|
||||
var reqPromise = this._version._domain.twilio.request({
|
||||
method: "get",
|
||||
uri: this.nextPageUrl,
|
||||
});
|
||||
var nextPagePromise = reqPromise.then(function (response) {
|
||||
return new this.constructor(this._version, response, this._solution);
|
||||
}.bind(this));
|
||||
return nextPagePromise;
|
||||
}
|
||||
/**
|
||||
* Fetch the previous page of records
|
||||
*
|
||||
* @returns promise that resolves to previous page of
|
||||
* results, or undefined if there isn't a previousPageUrl undefined.
|
||||
*/
|
||||
previousPage() {
|
||||
if (!this.previousPageUrl) {
|
||||
return undefined;
|
||||
}
|
||||
var reqPromise = this._version._domain.twilio.request({
|
||||
method: "get",
|
||||
uri: this.previousPageUrl,
|
||||
});
|
||||
var prevPagePromise = reqPromise.then(function (response) {
|
||||
return new this.constructor(this._version, response, this._solution);
|
||||
}.bind(this));
|
||||
return prevPagePromise;
|
||||
}
|
||||
/**
|
||||
* Parse json response from API
|
||||
*
|
||||
* @param response - API response
|
||||
*
|
||||
* @throws Error If non 200 status code is returned
|
||||
*
|
||||
* @returns json parsed response
|
||||
*/
|
||||
processResponse(response) {
|
||||
if (response.statusCode !== 200) {
|
||||
throw new RestException_1.default(response);
|
||||
}
|
||||
if (typeof response.body === "string") {
|
||||
return JSON.parse(response.body);
|
||||
}
|
||||
return response.body;
|
||||
}
|
||||
/**
|
||||
* Load a page of records
|
||||
*
|
||||
* @param {object} payload json payload
|
||||
* @return {array} the page of records
|
||||
*/
|
||||
loadPage(payload) {
|
||||
if (payload.meta?.key) {
|
||||
return payload[payload.meta.key];
|
||||
}
|
||||
const keys = Object.keys(payload).filter((key) => !Page.META_KEYS.includes(key));
|
||||
if (keys.length === 1) {
|
||||
return payload[keys[0]];
|
||||
}
|
||||
for (const key of keys)
|
||||
if (Array.isArray(payload[key]))
|
||||
return payload[key];
|
||||
throw new Error("Page Records cannot be deserialized");
|
||||
}
|
||||
forOwn(obj, iteratee) {
|
||||
obj = Object(obj);
|
||||
for (const [key, val] of Object.entries(obj)) {
|
||||
iteratee(val, key, obj);
|
||||
}
|
||||
}
|
||||
toJSON() {
|
||||
const clone = {};
|
||||
this.forOwn(this, (value, key) => {
|
||||
if (!key.startsWith("_") && typeof value !== "function") {
|
||||
clone[key] = value;
|
||||
}
|
||||
});
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Meta keys returned in a list request
|
||||
*
|
||||
* @constant META_KEYS
|
||||
*/
|
||||
Page.META_KEYS = [
|
||||
"end",
|
||||
"first_page_uri",
|
||||
"last_page_uri",
|
||||
"next_page_uri",
|
||||
"num_pages",
|
||||
"page",
|
||||
"page_size",
|
||||
"previous_page_uri",
|
||||
"start",
|
||||
"total",
|
||||
"uri",
|
||||
];
|
||||
exports.default = Page;
|
||||
186
node_modules/twilio/lib/base/RequestClient.d.ts
generated
vendored
Normal file
186
node_modules/twilio/lib/base/RequestClient.d.ts
generated
vendored
Normal file
@@ -0,0 +1,186 @@
|
||||
import { HttpMethod } from "../interfaces";
|
||||
import { AxiosInstance, InternalAxiosRequestConfig } from "axios";
|
||||
import Response from "../http/response";
|
||||
import Request, { Headers } from "../http/request";
|
||||
import AuthStrategy from "../auth_strategy/AuthStrategy";
|
||||
import { ValidationClientOptions } from "./ValidationClient";
|
||||
declare class RequestClient {
|
||||
defaultTimeout: number;
|
||||
axios: AxiosInstance;
|
||||
lastResponse?: Response<any>;
|
||||
lastRequest?: Request<any>;
|
||||
autoRetry: boolean;
|
||||
maxRetryDelay: number;
|
||||
maxRetries: number;
|
||||
keepAlive: boolean;
|
||||
/**
|
||||
* Make http request
|
||||
* @param opts - The options passed to https.Agent
|
||||
* @param opts.timeout - https.Agent timeout option. Used as the socket timeout, AND as the default request timeout.
|
||||
* @param opts.keepAlive - https.Agent keepAlive option
|
||||
* @param opts.keepAliveMsecs - https.Agent keepAliveMsecs option
|
||||
* @param opts.maxSockets - https.Agent maxSockets option
|
||||
* @param opts.maxTotalSockets - https.Agent maxTotalSockets option
|
||||
* @param opts.maxFreeSockets - https.Agent maxFreeSockets option
|
||||
* @param opts.scheduling - https.Agent scheduling option
|
||||
* @param opts.autoRetry - Enable auto-retry requests with exponential backoff on 429 responses. Defaults to false.
|
||||
* @param opts.maxRetryDelay - Max retry delay in milliseconds for 429 Too Many Request response retries. Defaults to 3000.
|
||||
* @param opts.maxRetries - Max number of request retries for 429 Too Many Request responses. Defaults to 3.
|
||||
* @param opts.validationClient - Validation client for PKCV
|
||||
*/
|
||||
constructor(opts?: RequestClient.RequestClientOptions);
|
||||
/**
|
||||
* Make http request
|
||||
* @param opts - The options argument
|
||||
* @param opts.method - The http method
|
||||
* @param opts.uri - The request uri
|
||||
* @param opts.username - The username used for auth
|
||||
* @param opts.password - The password used for auth
|
||||
* @param opts.authStrategy - The authStrategy for API call
|
||||
* @param opts.headers - The request headers
|
||||
* @param opts.params - The request params
|
||||
* @param opts.data - The request data
|
||||
* @param opts.timeout - The request timeout in milliseconds (default 30000)
|
||||
* @param opts.allowRedirects - Should the client follow redirects
|
||||
* @param opts.forever - Set to true to use the forever-agent
|
||||
* @param opts.logLevel - Show debug logs
|
||||
*/
|
||||
request<TData>(opts: RequestClient.RequestOptions<TData>): Promise<Response<TData>>;
|
||||
filterLoggingHeaders(headers: Headers): string[];
|
||||
/**
|
||||
* ValidationInterceptor adds the Twilio-Client-Validation header to the request
|
||||
* @param validationClient - The validation client for PKCV
|
||||
* <p>Usage Example:</p>
|
||||
* ```javascript
|
||||
* import axios from "axios";
|
||||
* // Initialize validation client with credentials
|
||||
* const validationClient = {
|
||||
* accountSid: "ACXXXXXXXXXXXXXXXX",
|
||||
* credentialSid: "CRXXXXXXXXXXXXXXXX",
|
||||
* signingKey: "SKXXXXXXXXXXXXXXXX",
|
||||
* privateKey: "private key",
|
||||
* algorithm: "PS256",
|
||||
* }
|
||||
* // construct an axios instance
|
||||
* const instance = axios.create();
|
||||
* instance.interceptors.request.use(
|
||||
* ValidationInterceptor(opts.validationClient)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
validationInterceptor(validationClient: ValidationClientOptions): (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig<any>;
|
||||
private logRequest;
|
||||
}
|
||||
declare namespace RequestClient {
|
||||
interface RequestOptions<TData = any, TParams = object> {
|
||||
/**
|
||||
* The HTTP method
|
||||
*/
|
||||
method: HttpMethod;
|
||||
/**
|
||||
* The request URI
|
||||
*/
|
||||
uri: string;
|
||||
/**
|
||||
* The username used for auth
|
||||
*/
|
||||
username?: string;
|
||||
/**
|
||||
* The password used for auth
|
||||
*/
|
||||
password?: string;
|
||||
/**
|
||||
* The AuthStrategy for API Call
|
||||
*/
|
||||
authStrategy?: AuthStrategy;
|
||||
/**
|
||||
* The request headers
|
||||
*/
|
||||
headers?: Headers;
|
||||
/**
|
||||
* The object of params added as query string to the request
|
||||
*/
|
||||
params?: TParams;
|
||||
/**
|
||||
* The form data that should be submitted
|
||||
*/
|
||||
data?: TData;
|
||||
/**
|
||||
* The request timeout in milliseconds
|
||||
*/
|
||||
timeout?: number;
|
||||
/**
|
||||
* Should the client follow redirects
|
||||
*/
|
||||
allowRedirects?: boolean;
|
||||
/**
|
||||
* Set to true to use the forever-agent
|
||||
*/
|
||||
forever?: boolean;
|
||||
/**
|
||||
* Set to 'debug' to enable debug logging
|
||||
*/
|
||||
logLevel?: string;
|
||||
}
|
||||
interface RequestClientOptions {
|
||||
/**
|
||||
* A timeout in milliseconds. This will be used as the HTTPS agent's socket
|
||||
* timeout, AND as the default request timeout.
|
||||
*/
|
||||
timeout?: number;
|
||||
/**
|
||||
* https.Agent keepAlive option
|
||||
*/
|
||||
keepAlive?: boolean;
|
||||
/**
|
||||
* https.Agent keepAliveMSecs option
|
||||
*/
|
||||
keepAliveMsecs?: number;
|
||||
/**
|
||||
* https.Agent maxSockets option
|
||||
*/
|
||||
maxSockets?: number;
|
||||
/**
|
||||
* https.Agent maxTotalSockets option
|
||||
*/
|
||||
maxTotalSockets?: number;
|
||||
/**
|
||||
* https.Agent maxFreeSockets option
|
||||
*/
|
||||
maxFreeSockets?: number;
|
||||
/**
|
||||
* https.Agent scheduling option
|
||||
*/
|
||||
scheduling?: "fifo" | "lifo" | undefined;
|
||||
/**
|
||||
* The private CA certificate bundle (if private SSL certificate)
|
||||
*/
|
||||
ca?: string | Buffer;
|
||||
/**
|
||||
* Enable auto-retry with exponential backoff when receiving 429 Errors from
|
||||
* the API. Disabled by default.
|
||||
*/
|
||||
autoRetry?: boolean;
|
||||
/**
|
||||
* Maximum retry delay in milliseconds for 429 Error response retries.
|
||||
* Defaults to 3000.
|
||||
*/
|
||||
maxRetryDelay?: number;
|
||||
/**
|
||||
* Maximum number of request retries for 429 Error responses. Defaults to 3.
|
||||
*/
|
||||
maxRetries?: number;
|
||||
/**
|
||||
* Validation client for Public Key Client Validation
|
||||
* On setting this with your credentials, Twilio validates:
|
||||
<ul>
|
||||
<li>The request comes from a sender who is in control of the private key.</li>
|
||||
<li>The message has not been modified in transit.</li>
|
||||
</ul>
|
||||
* That the message has not been modified in transit.
|
||||
* Refer our doc for details - https://www.twilio.com/docs/iam/pkcv
|
||||
*/
|
||||
validationClient?: ValidationClientOptions;
|
||||
}
|
||||
}
|
||||
export = RequestClient;
|
||||
281
node_modules/twilio/lib/base/RequestClient.js
generated
vendored
Normal file
281
node_modules/twilio/lib/base/RequestClient.js
generated
vendored
Normal file
@@ -0,0 +1,281 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
const axios_1 = __importStar(require("axios"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
|
||||
const qs_1 = __importDefault(require("qs"));
|
||||
const https = __importStar(require("https"));
|
||||
const response_1 = __importDefault(require("../http/response"));
|
||||
const request_1 = __importDefault(require("../http/request"));
|
||||
const ValidationToken_1 = __importDefault(require("../jwt/validation/ValidationToken"));
|
||||
const DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded";
|
||||
const DEFAULT_TIMEOUT = 30000;
|
||||
const DEFAULT_INITIAL_RETRY_INTERVAL_MILLIS = 100;
|
||||
const DEFAULT_MAX_RETRY_DELAY = 3000;
|
||||
const DEFAULT_MAX_RETRIES = 3;
|
||||
const DEFAULT_MAX_SOCKETS = 20;
|
||||
const DEFAULT_MAX_FREE_SOCKETS = 5;
|
||||
const DEFAULT_MAX_TOTAL_SOCKETS = 100;
|
||||
function getExponentialBackoffResponseHandler(axios, opts) {
|
||||
const maxIntervalMillis = opts.maxIntervalMillis;
|
||||
const maxRetries = opts.maxRetries;
|
||||
return function (res) {
|
||||
const config = res.config;
|
||||
if (res.status !== 429) {
|
||||
return res;
|
||||
}
|
||||
const retryCount = (config.retryCount || 0) + 1;
|
||||
if (retryCount <= maxRetries) {
|
||||
config.retryCount = retryCount;
|
||||
const baseDelay = Math.min(maxIntervalMillis, DEFAULT_INITIAL_RETRY_INTERVAL_MILLIS * Math.pow(2, retryCount));
|
||||
const delay = Math.floor(baseDelay * Math.random()); // Full jitter backoff
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => resolve(axios(config)), delay);
|
||||
});
|
||||
}
|
||||
return res;
|
||||
};
|
||||
}
|
||||
class RequestClient {
|
||||
/**
|
||||
* Make http request
|
||||
* @param opts - The options passed to https.Agent
|
||||
* @param opts.timeout - https.Agent timeout option. Used as the socket timeout, AND as the default request timeout.
|
||||
* @param opts.keepAlive - https.Agent keepAlive option
|
||||
* @param opts.keepAliveMsecs - https.Agent keepAliveMsecs option
|
||||
* @param opts.maxSockets - https.Agent maxSockets option
|
||||
* @param opts.maxTotalSockets - https.Agent maxTotalSockets option
|
||||
* @param opts.maxFreeSockets - https.Agent maxFreeSockets option
|
||||
* @param opts.scheduling - https.Agent scheduling option
|
||||
* @param opts.autoRetry - Enable auto-retry requests with exponential backoff on 429 responses. Defaults to false.
|
||||
* @param opts.maxRetryDelay - Max retry delay in milliseconds for 429 Too Many Request response retries. Defaults to 3000.
|
||||
* @param opts.maxRetries - Max number of request retries for 429 Too Many Request responses. Defaults to 3.
|
||||
* @param opts.validationClient - Validation client for PKCV
|
||||
*/
|
||||
constructor(opts) {
|
||||
opts = opts || {};
|
||||
this.defaultTimeout = opts.timeout || DEFAULT_TIMEOUT;
|
||||
this.autoRetry = opts.autoRetry || false;
|
||||
this.maxRetryDelay = opts.maxRetryDelay || DEFAULT_MAX_RETRY_DELAY;
|
||||
this.maxRetries = opts.maxRetries || DEFAULT_MAX_RETRIES;
|
||||
this.keepAlive = opts.keepAlive !== false;
|
||||
// construct an https agent
|
||||
let agentOpts = {
|
||||
timeout: this.defaultTimeout,
|
||||
keepAlive: this.keepAlive,
|
||||
keepAliveMsecs: opts.keepAliveMsecs,
|
||||
maxSockets: opts.maxSockets || DEFAULT_MAX_SOCKETS, // no of sockets open per host
|
||||
maxTotalSockets: opts.maxTotalSockets || DEFAULT_MAX_TOTAL_SOCKETS, // no of sockets open in total
|
||||
maxFreeSockets: opts.maxFreeSockets || DEFAULT_MAX_FREE_SOCKETS, // no of free sockets open per host
|
||||
scheduling: opts.scheduling,
|
||||
ca: opts.ca,
|
||||
};
|
||||
// sets https agent CA bundle if defined in CA bundle filepath env variable
|
||||
if (process.env.TWILIO_CA_BUNDLE !== undefined) {
|
||||
if (agentOpts.ca === undefined) {
|
||||
agentOpts.ca = fs.readFileSync(process.env.TWILIO_CA_BUNDLE);
|
||||
}
|
||||
}
|
||||
let agent;
|
||||
if (process.env.HTTP_PROXY) {
|
||||
// Note: if process.env.HTTP_PROXY is set, we're not able to apply the given
|
||||
// socket timeout. See: https://github.com/TooTallNate/node-https-proxy-agent/pull/96
|
||||
agent = (0, https_proxy_agent_1.default)(process.env.HTTP_PROXY);
|
||||
}
|
||||
else {
|
||||
agent = new https.Agent(agentOpts);
|
||||
}
|
||||
// construct an axios instance
|
||||
this.axios = axios_1.default.create();
|
||||
this.axios.defaults.headers.post["Content-Type"] = DEFAULT_CONTENT_TYPE;
|
||||
this.axios.defaults.httpsAgent = agent;
|
||||
if (opts.autoRetry) {
|
||||
this.axios.interceptors.response.use(getExponentialBackoffResponseHandler(this.axios, {
|
||||
maxIntervalMillis: this.maxRetryDelay,
|
||||
maxRetries: this.maxRetries,
|
||||
}));
|
||||
}
|
||||
// if validation client is set, intercept the request using ValidationInterceptor
|
||||
if (opts.validationClient) {
|
||||
this.axios.interceptors.request.use(this.validationInterceptor(opts.validationClient));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Make http request
|
||||
* @param opts - The options argument
|
||||
* @param opts.method - The http method
|
||||
* @param opts.uri - The request uri
|
||||
* @param opts.username - The username used for auth
|
||||
* @param opts.password - The password used for auth
|
||||
* @param opts.authStrategy - The authStrategy for API call
|
||||
* @param opts.headers - The request headers
|
||||
* @param opts.params - The request params
|
||||
* @param opts.data - The request data
|
||||
* @param opts.timeout - The request timeout in milliseconds (default 30000)
|
||||
* @param opts.allowRedirects - Should the client follow redirects
|
||||
* @param opts.forever - Set to true to use the forever-agent
|
||||
* @param opts.logLevel - Show debug logs
|
||||
*/
|
||||
async request(opts) {
|
||||
if (!opts.method) {
|
||||
throw new Error("http method is required");
|
||||
}
|
||||
if (!opts.uri) {
|
||||
throw new Error("uri is required");
|
||||
}
|
||||
var headers = opts.headers || {};
|
||||
if (!headers.Connection && !headers.connection)
|
||||
headers.Connection = this.keepAlive ? "keep-alive" : "close";
|
||||
let auth = undefined;
|
||||
if (opts.username && opts.password) {
|
||||
auth = Buffer.from(opts.username + ":" + opts.password).toString("base64");
|
||||
headers.Authorization = "Basic " + auth;
|
||||
}
|
||||
else if (opts.authStrategy) {
|
||||
headers.Authorization = await opts.authStrategy.getAuthString();
|
||||
}
|
||||
const options = {
|
||||
timeout: opts.timeout || this.defaultTimeout,
|
||||
maxRedirects: opts.allowRedirects ? 10 : 0,
|
||||
url: opts.uri,
|
||||
method: opts.method,
|
||||
headers: opts.headers,
|
||||
proxy: false,
|
||||
validateStatus: (status) => status >= 100 && status < 600,
|
||||
};
|
||||
if (opts.data && options.headers) {
|
||||
if (options.headers["Content-Type"] === "application/x-www-form-urlencoded") {
|
||||
options.data = qs_1.default.stringify(opts.data, { arrayFormat: "repeat" });
|
||||
}
|
||||
else if (options.headers["Content-Type"] === "application/json") {
|
||||
options.data = opts.data;
|
||||
}
|
||||
}
|
||||
if (opts.params) {
|
||||
options.params = opts.params;
|
||||
options.paramsSerializer = (params) => {
|
||||
return qs_1.default.stringify(params, { arrayFormat: "repeat" });
|
||||
};
|
||||
}
|
||||
const requestOptions = {
|
||||
method: opts.method,
|
||||
url: opts.uri,
|
||||
auth: auth,
|
||||
params: options.params,
|
||||
data: opts.data,
|
||||
headers: opts.headers,
|
||||
};
|
||||
if (opts.logLevel === "debug") {
|
||||
this.logRequest(requestOptions);
|
||||
}
|
||||
const _this = this;
|
||||
this.lastResponse = undefined;
|
||||
this.lastRequest = new request_1.default(requestOptions);
|
||||
return this.axios(options)
|
||||
.then((response) => {
|
||||
if (opts.logLevel === "debug") {
|
||||
console.log(`response.statusCode: ${response.status}`);
|
||||
console.log(`response.headers: ${JSON.stringify(response.headers)}`);
|
||||
}
|
||||
_this.lastResponse = new response_1.default(response.status, response.data, response.headers);
|
||||
return {
|
||||
statusCode: response.status,
|
||||
body: response.data,
|
||||
headers: response.headers,
|
||||
};
|
||||
})
|
||||
.catch((error) => {
|
||||
_this.lastResponse = undefined;
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
filterLoggingHeaders(headers) {
|
||||
return Object.keys(headers).filter((header) => {
|
||||
return !"authorization".includes(header.toLowerCase());
|
||||
});
|
||||
}
|
||||
/**
|
||||
* ValidationInterceptor adds the Twilio-Client-Validation header to the request
|
||||
* @param validationClient - The validation client for PKCV
|
||||
* <p>Usage Example:</p>
|
||||
* ```javascript
|
||||
* import axios from "axios";
|
||||
* // Initialize validation client with credentials
|
||||
* const validationClient = {
|
||||
* accountSid: "ACXXXXXXXXXXXXXXXX",
|
||||
* credentialSid: "CRXXXXXXXXXXXXXXXX",
|
||||
* signingKey: "SKXXXXXXXXXXXXXXXX",
|
||||
* privateKey: "private key",
|
||||
* algorithm: "PS256",
|
||||
* }
|
||||
* // construct an axios instance
|
||||
* const instance = axios.create();
|
||||
* instance.interceptors.request.use(
|
||||
* ValidationInterceptor(opts.validationClient)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
validationInterceptor(validationClient) {
|
||||
return function (config) {
|
||||
config.headers = config.headers || new axios_1.AxiosHeaders();
|
||||
try {
|
||||
config.headers["Twilio-Client-Validation"] = new ValidationToken_1.default(validationClient).fromHttpRequest(config);
|
||||
}
|
||||
catch (err) {
|
||||
console.log("Error creating Twilio-Client-Validation header:", err);
|
||||
throw err;
|
||||
}
|
||||
return config;
|
||||
};
|
||||
}
|
||||
logRequest(options) {
|
||||
console.log("-- BEGIN Twilio API Request --");
|
||||
console.log(`${options.method} ${options.url}`);
|
||||
if (options.params) {
|
||||
console.log("Querystring:");
|
||||
console.log(options.params);
|
||||
}
|
||||
if (options.headers) {
|
||||
console.log("Headers:");
|
||||
const filteredHeaderKeys = this.filterLoggingHeaders(options.headers);
|
||||
filteredHeaderKeys.forEach((header) => console.log(`${header}: ${options.headers?.header}`));
|
||||
}
|
||||
console.log("-- END Twilio API Request --");
|
||||
}
|
||||
}
|
||||
module.exports = RequestClient;
|
||||
16
node_modules/twilio/lib/base/RestException.d.ts
generated
vendored
Normal file
16
node_modules/twilio/lib/base/RestException.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
interface RestExceptionError {
|
||||
status: number;
|
||||
message?: string;
|
||||
code?: number;
|
||||
moreInfo?: string;
|
||||
details?: object;
|
||||
}
|
||||
export default class RestException extends Error implements RestExceptionError {
|
||||
status: number;
|
||||
message: string;
|
||||
code?: number;
|
||||
moreInfo?: string;
|
||||
details?: object;
|
||||
constructor(response: any);
|
||||
}
|
||||
export {};
|
||||
33
node_modules/twilio/lib/base/RestException.js
generated
vendored
Normal file
33
node_modules/twilio/lib/base/RestException.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
class RestException extends Error {
|
||||
constructor(response) {
|
||||
super("[HTTP " + response.statusCode + "] Failed to execute request");
|
||||
const isResponseBodyString = typeof response.body == "string";
|
||||
const body = isResponseBodyString
|
||||
? parseResponseBody(response.body)
|
||||
: response.body;
|
||||
this.status = response.statusCode;
|
||||
if (body !== null) {
|
||||
this.message = body.message;
|
||||
this.code = body.code;
|
||||
this.moreInfo = body.more_info; /* jshint ignore:line */
|
||||
this.details = body.details;
|
||||
}
|
||||
else {
|
||||
this.message =
|
||||
"[HTTP " + response.statusCode + "] Failed to execute request";
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.default = RestException;
|
||||
function parseResponseBody(response_body) {
|
||||
let body = null;
|
||||
try {
|
||||
body = JSON.parse(response_body);
|
||||
}
|
||||
catch (catchError) {
|
||||
body = null;
|
||||
}
|
||||
return body;
|
||||
}
|
||||
134
node_modules/twilio/lib/base/TokenPage.d.ts
generated
vendored
Normal file
134
node_modules/twilio/lib/base/TokenPage.d.ts
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
import Version from "./Version";
|
||||
import Response from "../http/response";
|
||||
/**
|
||||
* Token-based pagination metadata structure
|
||||
* Used for APIs that return pagination tokens instead of URLs
|
||||
*/
|
||||
export interface TokenPaginationPayload {
|
||||
[key: string]: any;
|
||||
meta: {
|
||||
key: string;
|
||||
pageSize?: number;
|
||||
nextToken?: string | null;
|
||||
previousToken?: string | null;
|
||||
};
|
||||
}
|
||||
interface Solution {
|
||||
[name: string]: any;
|
||||
}
|
||||
/**
|
||||
* TokenPage handles token-based pagination where the API returns
|
||||
* nextToken/previousToken strings instead of full URLs.
|
||||
*
|
||||
* Example response format:
|
||||
* {
|
||||
* "meta": {
|
||||
* "key": "items",
|
||||
* "pageSize": 50,
|
||||
* "nextToken": "abc123",
|
||||
* "previousToken": "xyz789"
|
||||
* },
|
||||
* "items": [
|
||||
* { "id": 1, "name": "Item 1" },
|
||||
* { "id": 2, "name": "Item 2" }
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
export default class TokenPage<TVersion extends Version, TPayload extends TokenPaginationPayload, TResource, TInstance> {
|
||||
instances: TInstance[];
|
||||
protected _version: TVersion;
|
||||
protected _payload: TPayload;
|
||||
protected _solution: Solution;
|
||||
private readonly _uri;
|
||||
private readonly _params;
|
||||
/**
|
||||
* Base page object to maintain request state for token-based pagination.
|
||||
*
|
||||
* @param version - A twilio version instance
|
||||
* @param response - The http response
|
||||
* @param uri - The URI for making pagination requests
|
||||
* @param data - The request parameters
|
||||
* @param solution - path solution
|
||||
*/
|
||||
constructor(version: TVersion, response: Response<string | TPayload>, uri: string, data?: Record<string, any>, solution?: Solution);
|
||||
/**
|
||||
* Parse json response from API
|
||||
*
|
||||
* @param response - API response
|
||||
*
|
||||
* @throws Error If non 200 status code is returned
|
||||
*
|
||||
* @returns json parsed response
|
||||
*/
|
||||
processResponse(response: Response<string | TPayload>): TPayload;
|
||||
/**
|
||||
* Load a page of records from the payload
|
||||
*
|
||||
* @param payload - json payload
|
||||
* @returns the page of records
|
||||
*/
|
||||
loadPage(payload: TPayload): TResource[];
|
||||
/**
|
||||
* Build a new instance given a json payload
|
||||
*
|
||||
* @param payload - Payload response from the API
|
||||
* @returns instance of a resource
|
||||
*/
|
||||
getInstance(payload: TResource): TInstance;
|
||||
/**
|
||||
* Load a list of records
|
||||
*
|
||||
* @param resources - json payload of records
|
||||
* @returns list of resources
|
||||
*/
|
||||
loadInstances(resources: TResource[]): TInstance[];
|
||||
toJSON(): object;
|
||||
/**
|
||||
* Returns the key that identifies the collection in the response.
|
||||
*
|
||||
* @returns the key or undefined if doesn't exist
|
||||
*/
|
||||
get key(): string | undefined;
|
||||
/**
|
||||
* Returns the page size or undefined if doesn't exist.
|
||||
*
|
||||
* @returns the page size or undefined
|
||||
*/
|
||||
get pageSize(): number | undefined;
|
||||
/**
|
||||
* Returns the next_token for pagination or undefined if doesn't exist.
|
||||
*
|
||||
* @returns the next token or undefined
|
||||
*/
|
||||
get nextToken(): string | undefined;
|
||||
/**
|
||||
* Returns the previous_token for pagination or undefined if doesn't exist.
|
||||
*
|
||||
* @returns the previous token or undefined
|
||||
*/
|
||||
get previousToken(): string | undefined;
|
||||
/**
|
||||
* Internal helper to fetch a page using a given token.
|
||||
*
|
||||
* @param token - The pagination token to use
|
||||
* @returns promise that resolves to the page or undefined if no token exists
|
||||
*/
|
||||
private _getPage;
|
||||
/**
|
||||
* Fetch the next page of records using token-based pagination.
|
||||
* Makes a request to the same URI with pageToken set to nextToken.
|
||||
*
|
||||
* @returns promise that resolves to next page of results,
|
||||
* or undefined if there isn't a nextToken.
|
||||
*/
|
||||
nextPage(): Promise<TokenPage<TVersion, TPayload, TResource, TInstance>> | undefined;
|
||||
/**
|
||||
* Fetch the previous page of records using token-based pagination.
|
||||
* Makes a request to the same URI with pageToken set to previousToken.
|
||||
*
|
||||
* @returns promise that resolves to previous page of results,
|
||||
* or undefined if there isn't a previousToken.
|
||||
*/
|
||||
previousPage(): Promise<TokenPage<TVersion, TPayload, TResource, TInstance>> | undefined;
|
||||
}
|
||||
export {};
|
||||
197
node_modules/twilio/lib/base/TokenPage.js
generated
vendored
Normal file
197
node_modules/twilio/lib/base/TokenPage.js
generated
vendored
Normal file
@@ -0,0 +1,197 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const RestException_1 = __importDefault(require("./RestException"));
|
||||
/**
|
||||
* TokenPage handles token-based pagination where the API returns
|
||||
* nextToken/previousToken strings instead of full URLs.
|
||||
*
|
||||
* Example response format:
|
||||
* {
|
||||
* "meta": {
|
||||
* "key": "items",
|
||||
* "pageSize": 50,
|
||||
* "nextToken": "abc123",
|
||||
* "previousToken": "xyz789"
|
||||
* },
|
||||
* "items": [
|
||||
* { "id": 1, "name": "Item 1" },
|
||||
* { "id": 2, "name": "Item 2" }
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
class TokenPage {
|
||||
/**
|
||||
* Base page object to maintain request state for token-based pagination.
|
||||
*
|
||||
* @param version - A twilio version instance
|
||||
* @param response - The http response
|
||||
* @param uri - The URI for making pagination requests
|
||||
* @param data - The request parameters
|
||||
* @param solution - path solution
|
||||
*/
|
||||
constructor(version, response, uri, data = {}, solution = {}) {
|
||||
const payload = this.processResponse(response);
|
||||
this._version = version;
|
||||
this._payload = payload;
|
||||
this._solution = solution;
|
||||
this._uri = uri;
|
||||
this._params = data;
|
||||
this.instances = this.loadInstances(this.loadPage(payload));
|
||||
}
|
||||
/**
|
||||
* Parse json response from API
|
||||
*
|
||||
* @param response - API response
|
||||
*
|
||||
* @throws Error If non 200 status code is returned
|
||||
*
|
||||
* @returns json parsed response
|
||||
*/
|
||||
processResponse(response) {
|
||||
if (response.statusCode !== 200) {
|
||||
throw new RestException_1.default(response);
|
||||
}
|
||||
if (typeof response.body === "string") {
|
||||
return JSON.parse(response.body);
|
||||
}
|
||||
return response.body;
|
||||
}
|
||||
/**
|
||||
* Load a page of records from the payload
|
||||
*
|
||||
* @param payload - json payload
|
||||
* @returns the page of records
|
||||
*/
|
||||
loadPage(payload) {
|
||||
if (payload.meta?.key) {
|
||||
return payload[payload.meta.key];
|
||||
}
|
||||
throw new Error("Token pagination requires meta.key to be present in response");
|
||||
}
|
||||
/**
|
||||
* Build a new instance given a json payload
|
||||
*
|
||||
* @param payload - Payload response from the API
|
||||
* @returns instance of a resource
|
||||
*/
|
||||
getInstance(payload) {
|
||||
throw new Error("TokenPage.getInstance() must be implemented in the derived class");
|
||||
}
|
||||
/**
|
||||
* Load a list of records
|
||||
*
|
||||
* @param resources - json payload of records
|
||||
* @returns list of resources
|
||||
*/
|
||||
loadInstances(resources) {
|
||||
const instances = [];
|
||||
resources.forEach((resource) => {
|
||||
instances.push(this.getInstance(resource));
|
||||
});
|
||||
return instances;
|
||||
}
|
||||
toJSON() {
|
||||
const clone = {};
|
||||
Object.entries(this).forEach(([key, value]) => {
|
||||
if (!key.startsWith("_") && typeof value !== "function") {
|
||||
clone[key] = value;
|
||||
}
|
||||
});
|
||||
return clone;
|
||||
}
|
||||
/**
|
||||
* Returns the key that identifies the collection in the response.
|
||||
*
|
||||
* @returns the key or undefined if doesn't exist
|
||||
*/
|
||||
get key() {
|
||||
if (this._payload.meta && this._payload.meta.key) {
|
||||
return this._payload.meta.key;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/**
|
||||
* Returns the page size or undefined if doesn't exist.
|
||||
*
|
||||
* @returns the page size or undefined
|
||||
*/
|
||||
get pageSize() {
|
||||
if (this._payload.meta && this._payload.meta.pageSize) {
|
||||
return this._payload.meta.pageSize;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/**
|
||||
* Returns the next_token for pagination or undefined if doesn't exist.
|
||||
*
|
||||
* @returns the next token or undefined
|
||||
*/
|
||||
get nextToken() {
|
||||
if (this._payload.meta &&
|
||||
this._payload.meta.nextToken !== undefined &&
|
||||
this._payload.meta.nextToken !== null) {
|
||||
return this._payload.meta.nextToken;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/**
|
||||
* Returns the previous_token for pagination or undefined if doesn't exist.
|
||||
*
|
||||
* @returns the previous token or undefined
|
||||
*/
|
||||
get previousToken() {
|
||||
if (this._payload.meta &&
|
||||
this._payload.meta.previousToken !== undefined &&
|
||||
this._payload.meta.previousToken !== null) {
|
||||
return this._payload.meta.previousToken;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/**
|
||||
* Internal helper to fetch a page using a given token.
|
||||
*
|
||||
* @param token - The pagination token to use
|
||||
* @returns promise that resolves to the page or undefined if no token exists
|
||||
*/
|
||||
_getPage(token) {
|
||||
if (!token) {
|
||||
return undefined;
|
||||
}
|
||||
if (!this._uri) {
|
||||
throw new Error("URI must be provided for token pagination");
|
||||
}
|
||||
const params = { ...this._params, pageToken: token };
|
||||
const responsePromise = this._version.page({
|
||||
method: "get",
|
||||
uri: this._uri,
|
||||
params: params,
|
||||
});
|
||||
return responsePromise.then((response) => {
|
||||
return new this.constructor(this._version, response, this._uri, this._params, this._solution);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Fetch the next page of records using token-based pagination.
|
||||
* Makes a request to the same URI with pageToken set to nextToken.
|
||||
*
|
||||
* @returns promise that resolves to next page of results,
|
||||
* or undefined if there isn't a nextToken.
|
||||
*/
|
||||
nextPage() {
|
||||
return this._getPage(this.nextToken);
|
||||
}
|
||||
/**
|
||||
* Fetch the previous page of records using token-based pagination.
|
||||
* Makes a request to the same URI with pageToken set to previousToken.
|
||||
*
|
||||
* @returns promise that resolves to previous page of results,
|
||||
* or undefined if there isn't a previousToken.
|
||||
*/
|
||||
previousPage() {
|
||||
return this._getPage(this.previousToken);
|
||||
}
|
||||
}
|
||||
exports.default = TokenPage;
|
||||
30
node_modules/twilio/lib/base/TwilioServiceException.d.ts
generated
vendored
Normal file
30
node_modules/twilio/lib/base/TwilioServiceException.d.ts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
interface ValidationError {
|
||||
detail: string;
|
||||
pointer: string;
|
||||
}
|
||||
interface TwilioServiceErrorResponse {
|
||||
type: string;
|
||||
title: string;
|
||||
status: number;
|
||||
detail?: string;
|
||||
instance?: string;
|
||||
code: number;
|
||||
errors?: ValidationError[];
|
||||
}
|
||||
export default class TwilioServiceException extends Error implements TwilioServiceErrorResponse {
|
||||
type: string;
|
||||
title: string;
|
||||
status: number;
|
||||
detail?: string;
|
||||
instance?: string;
|
||||
code: number;
|
||||
errors?: ValidationError[];
|
||||
constructor(response: any);
|
||||
/**
|
||||
* Check if a response body matches the RFC-9457 structure
|
||||
* @param body - The response body to check
|
||||
* @returns true if the body has the required RFC-9457 fields
|
||||
*/
|
||||
static isRFC9457Response(body: any): boolean;
|
||||
}
|
||||
export {};
|
||||
54
node_modules/twilio/lib/base/TwilioServiceException.js
generated
vendored
Normal file
54
node_modules/twilio/lib/base/TwilioServiceException.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
class TwilioServiceException extends Error {
|
||||
constructor(response) {
|
||||
const isResponseBodyString = typeof response.body == "string";
|
||||
const body = isResponseBodyString
|
||||
? parseResponseBody(response.body)
|
||||
: response.body;
|
||||
// Initialize status first for the error message
|
||||
const status = body?.status || response.statusCode;
|
||||
super(`[HTTP ${status}] ${body?.title || "Failed to execute request"}`);
|
||||
// Set all required properties
|
||||
this.type = body?.type || "";
|
||||
this.title = body?.title || "Failed to execute request";
|
||||
this.status = status;
|
||||
this.code = body?.code || 0;
|
||||
// Set optional properties
|
||||
if (body?.detail) {
|
||||
this.detail = body.detail;
|
||||
}
|
||||
if (body?.instance) {
|
||||
this.instance = body.instance;
|
||||
}
|
||||
if (body?.errors) {
|
||||
this.errors = body.errors;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check if a response body matches the RFC-9457 structure
|
||||
* @param body - The response body to check
|
||||
* @returns true if the body has the required RFC-9457 fields
|
||||
*/
|
||||
static isRFC9457Response(body) {
|
||||
if (!body || typeof body !== "object") {
|
||||
return false;
|
||||
}
|
||||
// Check for required fields according to the spec
|
||||
return (typeof body.type === "string" &&
|
||||
typeof body.title === "string" &&
|
||||
typeof body.status === "number" &&
|
||||
typeof body.code === "number");
|
||||
}
|
||||
}
|
||||
exports.default = TwilioServiceException;
|
||||
function parseResponseBody(response_body) {
|
||||
let body = null;
|
||||
try {
|
||||
body = JSON.parse(response_body);
|
||||
}
|
||||
catch (catchError) {
|
||||
body = null;
|
||||
}
|
||||
return body;
|
||||
}
|
||||
10
node_modules/twilio/lib/base/ValidationClient.d.ts
generated
vendored
Normal file
10
node_modules/twilio/lib/base/ValidationClient.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
declare namespace ValidationClient {
|
||||
interface ValidationClientOptions {
|
||||
accountSid: string;
|
||||
credentialSid: string;
|
||||
signingKey: string;
|
||||
privateKey: string;
|
||||
algorithm?: string;
|
||||
}
|
||||
}
|
||||
export = ValidationClient;
|
||||
2
node_modules/twilio/lib/base/ValidationClient.js
generated
vendored
Normal file
2
node_modules/twilio/lib/base/ValidationClient.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
241
node_modules/twilio/lib/base/Version.d.ts
generated
vendored
Normal file
241
node_modules/twilio/lib/base/Version.d.ts
generated
vendored
Normal file
@@ -0,0 +1,241 @@
|
||||
import Domain from "./Domain";
|
||||
import { RequestOpts } from "./BaseTwilio";
|
||||
import { ApiResponse } from "./ApiResponse";
|
||||
export interface PageLimitOptions {
|
||||
/**
|
||||
* The maximum number of items to fetch
|
||||
*/
|
||||
limit: number;
|
||||
/**
|
||||
* The maximum number of items to return with every request
|
||||
*/
|
||||
pageSize: number;
|
||||
}
|
||||
export interface PageLimit {
|
||||
limit: number;
|
||||
pageSize: number;
|
||||
}
|
||||
export default class Version {
|
||||
_domain: Domain;
|
||||
_version: Version | string;
|
||||
/**
|
||||
*
|
||||
* Base version object
|
||||
*
|
||||
* @param domain - twilio domain
|
||||
* @param version - api version
|
||||
*/
|
||||
constructor(domain: Domain, version: string | Version);
|
||||
get domain(): Domain;
|
||||
/**
|
||||
* Throws the appropriate exception based on the response format
|
||||
*
|
||||
* @param response - the response object
|
||||
* @throws TwilioServiceException if response matches RFC-9457 format
|
||||
* @throws RestException for legacy format
|
||||
*/
|
||||
private throwException;
|
||||
/**
|
||||
* Generate absolute url from a uri
|
||||
*
|
||||
* @param uri - uri to transform
|
||||
* @returns transformed url
|
||||
*/
|
||||
absoluteUrl(uri: string): string;
|
||||
/**
|
||||
* Generate relative url from a uri
|
||||
*
|
||||
* @param uri - uri to transform
|
||||
* @returns transformed url
|
||||
*/
|
||||
relativeUrl(uri: string): string;
|
||||
/**
|
||||
* Make a request against the domain
|
||||
*
|
||||
* @param opts - request options
|
||||
* @returns promise that resolves to request response
|
||||
*/
|
||||
request(opts: RequestOpts): Promise<any>;
|
||||
/**
|
||||
* Create a new record
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws Error If response returns non 2xx or 201 status code
|
||||
*
|
||||
* @returns promise that resolves to created record
|
||||
*/
|
||||
create(opts: RequestOpts): Promise<any>;
|
||||
/**
|
||||
* Fetch an instance of a record
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws Error If response returns non 2xx or 3xx status code
|
||||
*
|
||||
* @returns promise that resolves to fetched result
|
||||
*/
|
||||
fetch(opts: RequestOpts): Promise<any>;
|
||||
/**
|
||||
* Fetch a page of records
|
||||
*
|
||||
* @param opts - request options
|
||||
* @returns promise that resolves to page of records
|
||||
*/
|
||||
page(opts: RequestOpts): Promise<any>;
|
||||
/**
|
||||
* Update a record
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws Error If response returns non 2xx status code
|
||||
*
|
||||
* @returns promise that resolves to updated result
|
||||
*/
|
||||
update(opts: RequestOpts): Promise<any>;
|
||||
/**
|
||||
* Patch a record
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws Error If response returns non 2xx status code
|
||||
*
|
||||
* @returns promise that resolves to patched result
|
||||
*/
|
||||
patch(opts: RequestOpts): Promise<any>;
|
||||
/**
|
||||
* Delete a record
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws Error If response returns a 5xx status
|
||||
*
|
||||
* @returns promise that resolves to true if record was deleted
|
||||
*/
|
||||
remove(opts: RequestOpts): Promise<boolean>;
|
||||
/**
|
||||
* Create a new record and return response metadata
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws TwilioServiceException if response matches RFC-9457 format
|
||||
* @throws RestException for legacy format
|
||||
* @throws Error If response returns non 2xx or 201 status code
|
||||
*
|
||||
* @returns promise that resolves to ApiResponse with created record and metadata
|
||||
*/
|
||||
createWithResponseInfo<T>(opts: RequestOpts): Promise<ApiResponse<T>>;
|
||||
/**
|
||||
* Fetch an instance of a record and return response metadata
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws TwilioServiceException if response matches RFC-9457 format
|
||||
* @throws RestException for legacy format
|
||||
* @throws Error If response returns non 2xx or 3xx status code
|
||||
*
|
||||
* @returns promise that resolves to ApiResponse with fetched record and metadata
|
||||
*/
|
||||
fetchWithResponseInfo<T>(opts: RequestOpts): Promise<ApiResponse<T>>;
|
||||
/**
|
||||
* Update a record and return response metadata
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws TwilioServiceException if response matches RFC-9457 format
|
||||
* @throws RestException for legacy format
|
||||
* @throws Error If response returns non 2xx status code
|
||||
*
|
||||
* @returns promise that resolves to ApiResponse with updated record and metadata
|
||||
*/
|
||||
updateWithResponseInfo<T>(opts: RequestOpts): Promise<ApiResponse<T>>;
|
||||
/**
|
||||
* Patch a record and return response metadata
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws TwilioServiceException if response matches RFC-9457 format
|
||||
* @throws RestException for legacy format
|
||||
* @throws Error If response returns non 2xx status code
|
||||
*
|
||||
* @returns promise that resolves to ApiResponse with patched record and metadata
|
||||
*/
|
||||
patchWithResponseInfo<T>(opts: RequestOpts): Promise<ApiResponse<T>>;
|
||||
/**
|
||||
* Delete a record and return response metadata
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws TwilioServiceException if response matches RFC-9457 format
|
||||
* @throws RestException for legacy format
|
||||
* @throws Error If response returns a 5xx status
|
||||
*
|
||||
* @returns promise that resolves to ApiResponse with boolean and metadata
|
||||
*/
|
||||
removeWithResponseInfo(opts: RequestOpts): Promise<ApiResponse<boolean>>;
|
||||
/**
|
||||
* Process limits for list requests
|
||||
*
|
||||
* @param opts.limit - The maximum number of items to fetch
|
||||
* @param opts.pageSize - The maximum number of items to return with every request
|
||||
*
|
||||
*/
|
||||
readLimits(opts: PageLimitOptions): PageLimit;
|
||||
setPromiseCallback(operationPromise: any, callback: any): Promise<any>;
|
||||
/**
|
||||
* For each record instance, executes a provided callback function with that
|
||||
* instance
|
||||
*
|
||||
* @param params - Parameters (Optional)
|
||||
* @param params.limit - Optional maximum number of record instances to
|
||||
* fetch
|
||||
* @param params.pageSize - Optional maximum number of records to return
|
||||
* with every request
|
||||
* @param params.callback - Callback function to call with each
|
||||
* record instance
|
||||
* @param params.done - Optional done function to call when all
|
||||
* records are processed, the limit is reached, or an error occurs.
|
||||
* Receives an error argument if an error occurs.
|
||||
* @param callback - Callback function to call with each record.
|
||||
* Receives a done function argument that will short-circuit the for-each
|
||||
* loop that may accept an error argument.
|
||||
* @returns Returns a promise that resolves when all records
|
||||
* processed or if the limit is reached, and rejects with an error if an
|
||||
* error occurs and is not handled in the user provided done function.
|
||||
*/
|
||||
each<T>(params?: any, callback?: (item: T, done: (err?: Error) => void) => void): Promise<void>;
|
||||
list<T>(params?: any, callback?: (error: Error | null, items: T) => any): Promise<any>;
|
||||
/**
|
||||
* For each record instance, executes a provided callback function with that
|
||||
* instance and captures HTTP response metadata from the first page
|
||||
*
|
||||
* @param params - Parameters (Optional)
|
||||
* @param params.limit - Optional maximum number of record instances to
|
||||
* fetch
|
||||
* @param params.pageSize - Optional maximum number of records to return
|
||||
* with every request
|
||||
* @param params.callback - Callback function to call with each
|
||||
* record instance
|
||||
* @param params.done - Optional done function to call when all
|
||||
* records are processed, the limit is reached, or an error occurs.
|
||||
* Receives an error argument if an error occurs, and ApiResponse metadata.
|
||||
* @param callback - Callback function to call with each record.
|
||||
* Receives a done function argument that will short-circuit the for-each
|
||||
* loop that may accept an error argument.
|
||||
* @returns Returns a promise that resolves with first page metadata when all records
|
||||
* processed or if the limit is reached, and rejects with an error if an
|
||||
* error occurs and is not handled in the user provided done function.
|
||||
*/
|
||||
eachWithHttpInfo<T>(params?: any, callback?: (item: T, done: (err?: Error) => void) => void): Promise<ApiResponse<void>>;
|
||||
/**
|
||||
* Fetches all records and returns them as an array with HTTP response metadata
|
||||
* from the first page
|
||||
*
|
||||
* @param params - Parameters (Optional)
|
||||
* @param params.limit - Optional maximum number of record instances to fetch
|
||||
* @param params.pageSize - Optional maximum number of records to return with every request
|
||||
* @param callback - Optional callback function
|
||||
* @returns Promise that resolves to ApiResponse with array of all records and first page metadata
|
||||
*/
|
||||
listWithHttpInfo<T>(params?: any, callback?: (error: Error | null, items: ApiResponse<T[]>) => any): Promise<ApiResponse<T[]>>;
|
||||
}
|
||||
747
node_modules/twilio/lib/base/Version.js
generated
vendored
Normal file
747
node_modules/twilio/lib/base/Version.js
generated
vendored
Normal file
@@ -0,0 +1,747 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const RestException_1 = __importDefault(require("./RestException"));
|
||||
const TwilioServiceException_1 = __importDefault(require("./TwilioServiceException"));
|
||||
const utility_1 = require("./utility");
|
||||
class Version {
|
||||
/**
|
||||
*
|
||||
* Base version object
|
||||
*
|
||||
* @param domain - twilio domain
|
||||
* @param version - api version
|
||||
*/
|
||||
constructor(domain, version) {
|
||||
this._domain = domain;
|
||||
this._version = version;
|
||||
}
|
||||
get domain() {
|
||||
return this._domain;
|
||||
}
|
||||
/**
|
||||
* Throws the appropriate exception based on the response format
|
||||
*
|
||||
* @param response - the response object
|
||||
* @throws TwilioServiceException if response matches RFC-9457 format
|
||||
* @throws RestException for legacy format
|
||||
*/
|
||||
throwException(response) {
|
||||
const isResponseBodyString = typeof response.body === "string";
|
||||
let body = null;
|
||||
if (isResponseBodyString) {
|
||||
try {
|
||||
body = JSON.parse(response.body);
|
||||
}
|
||||
catch (e) {
|
||||
// If parsing fails, body remains null
|
||||
}
|
||||
}
|
||||
else {
|
||||
body = response.body;
|
||||
}
|
||||
// Check if response matches RFC-9457 format
|
||||
if (TwilioServiceException_1.default.isRFC9457Response(body)) {
|
||||
throw new TwilioServiceException_1.default(response);
|
||||
}
|
||||
// Fall back to legacy RestException
|
||||
throw new RestException_1.default(response);
|
||||
}
|
||||
/**
|
||||
* Generate absolute url from a uri
|
||||
*
|
||||
* @param uri - uri to transform
|
||||
* @returns transformed url
|
||||
*/
|
||||
absoluteUrl(uri) {
|
||||
return this._domain.absoluteUrl(this.relativeUrl(uri));
|
||||
}
|
||||
/**
|
||||
* Generate relative url from a uri
|
||||
*
|
||||
* @param uri - uri to transform
|
||||
* @returns transformed url
|
||||
*/
|
||||
relativeUrl(uri) {
|
||||
var result = "";
|
||||
if (typeof this._version === "string") {
|
||||
const version = (0, utility_1.trim)(this._version, "/");
|
||||
result += version;
|
||||
result += "/";
|
||||
}
|
||||
if (typeof uri === "string") {
|
||||
uri = (0, utility_1.trim)(uri, "/");
|
||||
if (result === "") {
|
||||
result += "/";
|
||||
}
|
||||
result += uri;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Make a request against the domain
|
||||
*
|
||||
* @param opts - request options
|
||||
* @returns promise that resolves to request response
|
||||
*/
|
||||
request(opts) {
|
||||
return this._domain.request({
|
||||
...opts,
|
||||
uri: this.relativeUrl(opts.uri || ""),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Create a new record
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws Error If response returns non 2xx or 201 status code
|
||||
*
|
||||
* @returns promise that resolves to created record
|
||||
*/
|
||||
create(opts) {
|
||||
var qResponse = this.request(opts);
|
||||
qResponse = qResponse.then((response) => {
|
||||
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||
this.throwException(response);
|
||||
}
|
||||
if (typeof response.body === "string") {
|
||||
return JSON.parse(response.body);
|
||||
}
|
||||
return response.body;
|
||||
});
|
||||
return qResponse;
|
||||
}
|
||||
/**
|
||||
* Fetch an instance of a record
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws Error If response returns non 2xx or 3xx status code
|
||||
*
|
||||
* @returns promise that resolves to fetched result
|
||||
*/
|
||||
fetch(opts) {
|
||||
var qResponse = this.request(opts);
|
||||
qResponse = qResponse.then((response) => {
|
||||
if (response.statusCode < 200 || response.statusCode >= 400) {
|
||||
this.throwException(response);
|
||||
}
|
||||
if (typeof response.body === "string") {
|
||||
return JSON.parse(response.body);
|
||||
}
|
||||
return response.body;
|
||||
});
|
||||
return qResponse;
|
||||
}
|
||||
/**
|
||||
* Fetch a page of records
|
||||
*
|
||||
* @param opts - request options
|
||||
* @returns promise that resolves to page of records
|
||||
*/
|
||||
page(opts) {
|
||||
return this.request(opts);
|
||||
}
|
||||
/**
|
||||
* Update a record
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws Error If response returns non 2xx status code
|
||||
*
|
||||
* @returns promise that resolves to updated result
|
||||
*/
|
||||
update(opts) {
|
||||
var qResponse = this.request(opts);
|
||||
qResponse = qResponse.then((response) => {
|
||||
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||
this.throwException(response);
|
||||
}
|
||||
if (typeof response.body === "string") {
|
||||
return JSON.parse(response.body);
|
||||
}
|
||||
return response.body;
|
||||
});
|
||||
return qResponse;
|
||||
}
|
||||
/**
|
||||
* Patch a record
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws Error If response returns non 2xx status code
|
||||
*
|
||||
* @returns promise that resolves to patched result
|
||||
*/
|
||||
async patch(opts) {
|
||||
const response = await this.request(opts);
|
||||
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||
this.throwException(response);
|
||||
}
|
||||
return typeof response.body === "string"
|
||||
? JSON.parse(response.body)
|
||||
: response.body;
|
||||
}
|
||||
/**
|
||||
* Delete a record
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws Error If response returns a 5xx status
|
||||
*
|
||||
* @returns promise that resolves to true if record was deleted
|
||||
*/
|
||||
remove(opts) {
|
||||
let qResponse = this.request(opts);
|
||||
qResponse = qResponse.then((response) => {
|
||||
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||
this.throwException(response);
|
||||
}
|
||||
return true; // if response code is 2XX, deletion was successful
|
||||
});
|
||||
return qResponse;
|
||||
}
|
||||
/**
|
||||
* Create a new record and return response metadata
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws TwilioServiceException if response matches RFC-9457 format
|
||||
* @throws RestException for legacy format
|
||||
* @throws Error If response returns non 2xx or 201 status code
|
||||
*
|
||||
* @returns promise that resolves to ApiResponse with created record and metadata
|
||||
*/
|
||||
createWithResponseInfo(opts) {
|
||||
return this.request(opts).then((response) => {
|
||||
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||
this.throwException(response);
|
||||
}
|
||||
let body;
|
||||
if (typeof response.body === "string") {
|
||||
body = JSON.parse(response.body);
|
||||
}
|
||||
else {
|
||||
body = response.body;
|
||||
}
|
||||
return {
|
||||
body: body,
|
||||
statusCode: response.statusCode,
|
||||
headers: response.headers,
|
||||
};
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Fetch an instance of a record and return response metadata
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws TwilioServiceException if response matches RFC-9457 format
|
||||
* @throws RestException for legacy format
|
||||
* @throws Error If response returns non 2xx or 3xx status code
|
||||
*
|
||||
* @returns promise that resolves to ApiResponse with fetched record and metadata
|
||||
*/
|
||||
fetchWithResponseInfo(opts) {
|
||||
return this.request(opts).then((response) => {
|
||||
if (response.statusCode < 200 || response.statusCode >= 400) {
|
||||
this.throwException(response);
|
||||
}
|
||||
let body;
|
||||
if (typeof response.body === "string") {
|
||||
body = JSON.parse(response.body);
|
||||
}
|
||||
else {
|
||||
body = response.body;
|
||||
}
|
||||
return {
|
||||
body: body,
|
||||
statusCode: response.statusCode,
|
||||
headers: response.headers,
|
||||
};
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Update a record and return response metadata
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws TwilioServiceException if response matches RFC-9457 format
|
||||
* @throws RestException for legacy format
|
||||
* @throws Error If response returns non 2xx status code
|
||||
*
|
||||
* @returns promise that resolves to ApiResponse with updated record and metadata
|
||||
*/
|
||||
updateWithResponseInfo(opts) {
|
||||
return this.request(opts).then((response) => {
|
||||
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||
this.throwException(response);
|
||||
}
|
||||
let body;
|
||||
if (typeof response.body === "string") {
|
||||
body = JSON.parse(response.body);
|
||||
}
|
||||
else {
|
||||
body = response.body;
|
||||
}
|
||||
return {
|
||||
body: body,
|
||||
statusCode: response.statusCode,
|
||||
headers: response.headers,
|
||||
};
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Patch a record and return response metadata
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws TwilioServiceException if response matches RFC-9457 format
|
||||
* @throws RestException for legacy format
|
||||
* @throws Error If response returns non 2xx status code
|
||||
*
|
||||
* @returns promise that resolves to ApiResponse with patched record and metadata
|
||||
*/
|
||||
async patchWithResponseInfo(opts) {
|
||||
const response = await this.request(opts);
|
||||
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||
this.throwException(response);
|
||||
}
|
||||
let body;
|
||||
if (typeof response.body === "string") {
|
||||
body = JSON.parse(response.body);
|
||||
}
|
||||
else {
|
||||
body = response.body;
|
||||
}
|
||||
return {
|
||||
body: body,
|
||||
statusCode: response.statusCode,
|
||||
headers: response.headers,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Delete a record and return response metadata
|
||||
*
|
||||
* @param opts - request options
|
||||
*
|
||||
* @throws TwilioServiceException if response matches RFC-9457 format
|
||||
* @throws RestException for legacy format
|
||||
* @throws Error If response returns a 5xx status
|
||||
*
|
||||
* @returns promise that resolves to ApiResponse with boolean and metadata
|
||||
*/
|
||||
removeWithResponseInfo(opts) {
|
||||
return this.request(opts).then((response) => {
|
||||
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||
this.throwException(response);
|
||||
}
|
||||
return {
|
||||
body: true, // if response code is 2XX, deletion was successful
|
||||
statusCode: response.statusCode,
|
||||
headers: response.headers,
|
||||
};
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Process limits for list requests
|
||||
*
|
||||
* @param opts.limit - The maximum number of items to fetch
|
||||
* @param opts.pageSize - The maximum number of items to return with every request
|
||||
*
|
||||
*/
|
||||
readLimits(opts) {
|
||||
var limit = opts.limit;
|
||||
var pageSize = opts.pageSize;
|
||||
if ((limit && !Number.isFinite(limit)) || limit <= 0) {
|
||||
throw new TypeError("Parameter limit must be a positive integer");
|
||||
}
|
||||
if (pageSize && (!Number.isFinite(pageSize) || pageSize <= 0)) {
|
||||
throw new TypeError("Parameter pageSize must be a positive integer");
|
||||
}
|
||||
if (limit && !pageSize) {
|
||||
pageSize = limit;
|
||||
}
|
||||
return {
|
||||
limit: limit,
|
||||
pageSize: pageSize,
|
||||
};
|
||||
}
|
||||
setPromiseCallback(operationPromise, callback) {
|
||||
if (typeof callback === "function") {
|
||||
operationPromise = operationPromise
|
||||
.then((value) => callback(null, value))
|
||||
.catch((error) => callback(error));
|
||||
}
|
||||
return operationPromise;
|
||||
}
|
||||
/**
|
||||
* For each record instance, executes a provided callback function with that
|
||||
* instance
|
||||
*
|
||||
* @param params - Parameters (Optional)
|
||||
* @param params.limit - Optional maximum number of record instances to
|
||||
* fetch
|
||||
* @param params.pageSize - Optional maximum number of records to return
|
||||
* with every request
|
||||
* @param params.callback - Callback function to call with each
|
||||
* record instance
|
||||
* @param params.done - Optional done function to call when all
|
||||
* records are processed, the limit is reached, or an error occurs.
|
||||
* Receives an error argument if an error occurs.
|
||||
* @param callback - Callback function to call with each record.
|
||||
* Receives a done function argument that will short-circuit the for-each
|
||||
* loop that may accept an error argument.
|
||||
* @returns Returns a promise that resolves when all records
|
||||
* processed or if the limit is reached, and rejects with an error if an
|
||||
* error occurs and is not handled in the user provided done function.
|
||||
*/
|
||||
each(params, callback) {
|
||||
if (typeof params === "function") {
|
||||
callback = params;
|
||||
params = {};
|
||||
}
|
||||
else {
|
||||
params = params || {};
|
||||
}
|
||||
if (params.callback) {
|
||||
callback = params.callback;
|
||||
}
|
||||
if (typeof callback === "undefined") {
|
||||
throw new Error("Callback function must be provided");
|
||||
}
|
||||
let done = false;
|
||||
let doneCalled = false;
|
||||
let currentPage = 1;
|
||||
let currentResource = 0;
|
||||
let limits = {};
|
||||
let pPending = true;
|
||||
let pResolve;
|
||||
let pReject;
|
||||
if (this._version instanceof Version) {
|
||||
limits = this._version.readLimits({
|
||||
limit: params.limit,
|
||||
pageSize: params.pageSize,
|
||||
});
|
||||
}
|
||||
function onComplete(error) {
|
||||
let unhandledError = error;
|
||||
done = true;
|
||||
if (typeof params.done === "function" && !doneCalled) {
|
||||
try {
|
||||
params.done(unhandledError);
|
||||
unhandledError = null;
|
||||
}
|
||||
catch (e) {
|
||||
unhandledError = e;
|
||||
}
|
||||
}
|
||||
doneCalled = true;
|
||||
if (pPending) {
|
||||
if (unhandledError) {
|
||||
pReject(unhandledError);
|
||||
}
|
||||
else {
|
||||
pResolve();
|
||||
}
|
||||
pPending = false;
|
||||
}
|
||||
}
|
||||
function fetchNextPage(fn) {
|
||||
let promise = fn();
|
||||
if (typeof promise === "undefined") {
|
||||
onComplete();
|
||||
return;
|
||||
}
|
||||
promise
|
||||
.then((page) => {
|
||||
try {
|
||||
page.instances.forEach(function (instance) {
|
||||
if (done ||
|
||||
(typeof params.limit !== "undefined" &&
|
||||
currentResource >= params.limit)) {
|
||||
done = true;
|
||||
return false;
|
||||
}
|
||||
currentResource++;
|
||||
callback?.(instance, onComplete);
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
return onComplete(e);
|
||||
}
|
||||
if (!done) {
|
||||
currentPage++;
|
||||
fetchNextPage(page.nextPage.bind(page));
|
||||
}
|
||||
else {
|
||||
onComplete();
|
||||
}
|
||||
})
|
||||
.catch(onComplete);
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
pResolve = resolve;
|
||||
pReject = reject;
|
||||
fetchNextPage(this.page.bind(this, Object.assign(params, limits)));
|
||||
});
|
||||
}
|
||||
list(params, callback) {
|
||||
if (typeof params === "function") {
|
||||
callback = params;
|
||||
params = {};
|
||||
}
|
||||
else {
|
||||
params = params || {};
|
||||
}
|
||||
let allResources = [];
|
||||
params.callback = function (resource, done) {
|
||||
allResources.push(resource);
|
||||
if (typeof params.limit !== "undefined" &&
|
||||
allResources.length === params.limit) {
|
||||
done();
|
||||
}
|
||||
};
|
||||
let operationPromise = new Promise((resolve, reject) => {
|
||||
params.done = function (error) {
|
||||
if (typeof error === "undefined") {
|
||||
resolve(allResources);
|
||||
}
|
||||
else {
|
||||
reject(error);
|
||||
}
|
||||
};
|
||||
});
|
||||
if (this._version instanceof Version) {
|
||||
operationPromise = this._version.setPromiseCallback(operationPromise, callback);
|
||||
}
|
||||
this.each(params);
|
||||
return operationPromise;
|
||||
}
|
||||
/**
|
||||
* For each record instance, executes a provided callback function with that
|
||||
* instance and captures HTTP response metadata from the first page
|
||||
*
|
||||
* @param params - Parameters (Optional)
|
||||
* @param params.limit - Optional maximum number of record instances to
|
||||
* fetch
|
||||
* @param params.pageSize - Optional maximum number of records to return
|
||||
* with every request
|
||||
* @param params.callback - Callback function to call with each
|
||||
* record instance
|
||||
* @param params.done - Optional done function to call when all
|
||||
* records are processed, the limit is reached, or an error occurs.
|
||||
* Receives an error argument if an error occurs, and ApiResponse metadata.
|
||||
* @param callback - Callback function to call with each record.
|
||||
* Receives a done function argument that will short-circuit the for-each
|
||||
* loop that may accept an error argument.
|
||||
* @returns Returns a promise that resolves with first page metadata when all records
|
||||
* processed or if the limit is reached, and rejects with an error if an
|
||||
* error occurs and is not handled in the user provided done function.
|
||||
*/
|
||||
eachWithHttpInfo(params, callback) {
|
||||
if (typeof params === "function") {
|
||||
callback = params;
|
||||
params = {};
|
||||
}
|
||||
else {
|
||||
params = params || {};
|
||||
}
|
||||
if (params.callback) {
|
||||
callback = params.callback;
|
||||
}
|
||||
if (typeof callback === "undefined") {
|
||||
throw new Error("Callback function must be provided");
|
||||
}
|
||||
let done = false;
|
||||
let doneCalled = false;
|
||||
let currentPage = 1;
|
||||
let currentResource = 0;
|
||||
let limits = {};
|
||||
let pPending = true;
|
||||
let pResolve;
|
||||
let pReject;
|
||||
let firstPageMetadata = null;
|
||||
if (this._version instanceof Version) {
|
||||
limits = this._version.readLimits({
|
||||
limit: params.limit,
|
||||
pageSize: params.pageSize,
|
||||
});
|
||||
}
|
||||
function onComplete(error) {
|
||||
let unhandledError = error;
|
||||
done = true;
|
||||
if (typeof params.done === "function" && !doneCalled) {
|
||||
try {
|
||||
params.done(unhandledError, firstPageMetadata);
|
||||
unhandledError = null;
|
||||
}
|
||||
catch (e) {
|
||||
unhandledError = e;
|
||||
}
|
||||
}
|
||||
doneCalled = true;
|
||||
if (pPending) {
|
||||
if (unhandledError) {
|
||||
pReject(unhandledError);
|
||||
}
|
||||
else {
|
||||
// firstPageMetadata is guaranteed to be set here because:
|
||||
// 1. If no page was fetched, we already rejected with error
|
||||
// 2. If page was fetched, firstPageMetadata was set in the .then() handler
|
||||
pResolve({
|
||||
body: undefined,
|
||||
statusCode: firstPageMetadata.statusCode,
|
||||
headers: firstPageMetadata.headers,
|
||||
});
|
||||
}
|
||||
pPending = false;
|
||||
}
|
||||
}
|
||||
function fetchNextPageWithInfo(fn) {
|
||||
let promise = fn();
|
||||
if (typeof promise === "undefined" || promise === null) {
|
||||
// If this is the first page and we got null/undefined, that's an error
|
||||
// If this is a subsequent page, null means "no more pages" (success)
|
||||
if (currentPage === 1) {
|
||||
pReject(new Error("Page method did not return a Promise"));
|
||||
pPending = false;
|
||||
}
|
||||
else {
|
||||
onComplete();
|
||||
}
|
||||
return;
|
||||
}
|
||||
promise
|
||||
.then((response) => {
|
||||
// Handle both cases:
|
||||
// 1. Version.page() returns { statusCode, body, headers }
|
||||
// 2. Resource.page() returns Page object directly
|
||||
let pageData = response.body !== undefined ? response.body : response;
|
||||
// Capture first page metadata on first page
|
||||
if (currentPage === 1 && !firstPageMetadata) {
|
||||
if (response.statusCode !== undefined) {
|
||||
// Case 1: Response structure with metadata
|
||||
firstPageMetadata = {
|
||||
statusCode: response.statusCode,
|
||||
headers: response.headers || {},
|
||||
};
|
||||
}
|
||||
else {
|
||||
// Case 2: Direct Page object (no metadata available)
|
||||
firstPageMetadata = {
|
||||
statusCode: 200,
|
||||
headers: {},
|
||||
};
|
||||
}
|
||||
}
|
||||
// Parse body if it's a string
|
||||
if (typeof pageData === "string") {
|
||||
pageData = JSON.parse(pageData);
|
||||
}
|
||||
try {
|
||||
pageData.instances.forEach(function (instance) {
|
||||
if (done ||
|
||||
(typeof params.limit !== "undefined" &&
|
||||
currentResource >= params.limit)) {
|
||||
done = true;
|
||||
return false;
|
||||
}
|
||||
currentResource++;
|
||||
callback?.(instance, onComplete);
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
return onComplete(e);
|
||||
}
|
||||
if (!done) {
|
||||
currentPage++;
|
||||
// Page's nextPage method should already return response structure
|
||||
const nextPageFn = pageData.nextPage?.bind(pageData);
|
||||
if (nextPageFn) {
|
||||
fetchNextPageWithInfo(nextPageFn);
|
||||
}
|
||||
else {
|
||||
onComplete();
|
||||
}
|
||||
}
|
||||
else {
|
||||
onComplete();
|
||||
}
|
||||
})
|
||||
.catch(onComplete);
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
pResolve = resolve;
|
||||
pReject = reject;
|
||||
const pageParams = Object.assign({}, params, limits);
|
||||
fetchNextPageWithInfo(() => {
|
||||
// Use pageWithHttpInfo() if available to capture HTTP metadata, otherwise use page()
|
||||
// When called from resources, this.pageWithHttpInfo exists and returns { statusCode, body, headers }
|
||||
// When called from Version directly, this.page returns { statusCode, body, headers }
|
||||
if (typeof this.pageWithHttpInfo === "function") {
|
||||
return this.pageWithHttpInfo(pageParams);
|
||||
}
|
||||
return this.page(pageParams);
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Fetches all records and returns them as an array with HTTP response metadata
|
||||
* from the first page
|
||||
*
|
||||
* @param params - Parameters (Optional)
|
||||
* @param params.limit - Optional maximum number of record instances to fetch
|
||||
* @param params.pageSize - Optional maximum number of records to return with every request
|
||||
* @param callback - Optional callback function
|
||||
* @returns Promise that resolves to ApiResponse with array of all records and first page metadata
|
||||
*/
|
||||
listWithHttpInfo(params, callback) {
|
||||
if (typeof params === "function") {
|
||||
callback = params;
|
||||
params = {};
|
||||
}
|
||||
else {
|
||||
params = params || {};
|
||||
}
|
||||
let allResources = [];
|
||||
let firstPageMetadata = null;
|
||||
params.callback = function (resource, done) {
|
||||
allResources.push(resource);
|
||||
if (typeof params.limit !== "undefined" &&
|
||||
allResources.length === params.limit) {
|
||||
done();
|
||||
}
|
||||
};
|
||||
let operationPromise = new Promise((resolve, reject) => {
|
||||
params.done = function (error, metadata) {
|
||||
if (metadata) {
|
||||
firstPageMetadata = metadata;
|
||||
}
|
||||
if (typeof error === "undefined") {
|
||||
// firstPageMetadata is guaranteed to be set here because:
|
||||
// eachWithHttpInfo either:
|
||||
// 1. Rejects with error (no page fetched)
|
||||
// 2. Passes metadata to done callback (page was fetched)
|
||||
resolve({
|
||||
body: allResources,
|
||||
statusCode: firstPageMetadata.statusCode,
|
||||
headers: firstPageMetadata.headers,
|
||||
});
|
||||
}
|
||||
else {
|
||||
reject(error);
|
||||
}
|
||||
};
|
||||
});
|
||||
if (this._version instanceof Version) {
|
||||
operationPromise = this._version.setPromiseCallback(operationPromise, callback);
|
||||
}
|
||||
this.eachWithHttpInfo(params);
|
||||
return operationPromise;
|
||||
}
|
||||
}
|
||||
exports.default = Version;
|
||||
41
node_modules/twilio/lib/base/deserialize.d.ts
generated
vendored
Normal file
41
node_modules/twilio/lib/base/deserialize.d.ts
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
export interface NumberParser {
|
||||
(n: string): number;
|
||||
}
|
||||
/**
|
||||
* @namespace deserialize
|
||||
*/
|
||||
/**
|
||||
* Parse a string into a Date object
|
||||
*
|
||||
* @param s - Date string in YYYY-MM-DD format
|
||||
* @returns Date object, or the original date string if the argument is not a valid date
|
||||
*/
|
||||
export declare function iso8601Date(s: string): string | Date;
|
||||
/**
|
||||
* Parse a string into a Date object
|
||||
*
|
||||
* @param s - Date string in YYYY-MM-DD[T]HH:mm:ss[Z] format
|
||||
* @returns Date object, or the original date string if the argument is not a valid date
|
||||
*/
|
||||
export declare function iso8601DateTime(s: string): string | Date;
|
||||
/**
|
||||
* Parse a string into a Date object
|
||||
*
|
||||
* @param s - Date string in ddd, DD MMM YYYY HH:mm:ss [+0000] format
|
||||
* @returns Date object, or the original date string if the argument is not a valid date
|
||||
*/
|
||||
export declare function rfc2822DateTime(s: string): string | Date;
|
||||
/**
|
||||
* Parse a string into a decimal
|
||||
*
|
||||
* @param d - Decimal value as string
|
||||
* @returns Number, or the original string if the argument is NaN
|
||||
*/
|
||||
export declare function decimal(d: string): string | number;
|
||||
/**
|
||||
* Parse a string into a integer
|
||||
*
|
||||
* @param i - Integer value as string
|
||||
* @returns Number, or the original string if the argument is NaN
|
||||
*/
|
||||
export declare function integer(i: string): string | number;
|
||||
75
node_modules/twilio/lib/base/deserialize.js
generated
vendored
Normal file
75
node_modules/twilio/lib/base/deserialize.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.iso8601Date = iso8601Date;
|
||||
exports.iso8601DateTime = iso8601DateTime;
|
||||
exports.rfc2822DateTime = rfc2822DateTime;
|
||||
exports.decimal = decimal;
|
||||
exports.integer = integer;
|
||||
const dayjs_1 = __importDefault(require("dayjs"));
|
||||
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
||||
dayjs_1.default.extend(utc_1.default);
|
||||
/**
|
||||
* @namespace deserialize
|
||||
*/
|
||||
/**
|
||||
* Parse a string into a Date object
|
||||
*
|
||||
* @param s - Date string in YYYY-MM-DD format
|
||||
* @returns Date object, or the original date string if the argument is not a valid date
|
||||
*/
|
||||
function iso8601Date(s) {
|
||||
return parseDate(s, "YYYY-MM-DD");
|
||||
}
|
||||
/**
|
||||
* Parse a string into a Date object
|
||||
*
|
||||
* @param s - Date string in YYYY-MM-DD[T]HH:mm:ss[Z] format
|
||||
* @returns Date object, or the original date string if the argument is not a valid date
|
||||
*/
|
||||
function iso8601DateTime(s) {
|
||||
return parseDate(s, "YYYY-MM-DD[T]HH:mm:ss[Z]");
|
||||
}
|
||||
/**
|
||||
* Parse a string into a Date object
|
||||
*
|
||||
* @param s - Date string in ddd, DD MMM YYYY HH:mm:ss [+0000] format
|
||||
* @returns Date object, or the original date string if the argument is not a valid date
|
||||
*/
|
||||
function rfc2822DateTime(s) {
|
||||
return parseDate(s, "ddd, DD MMM YYYY HH:mm:ss [+0000]");
|
||||
}
|
||||
/**
|
||||
* Parse a string into a decimal
|
||||
*
|
||||
* @param d - Decimal value as string
|
||||
* @returns Number, or the original string if the argument is NaN
|
||||
*/
|
||||
function decimal(d) {
|
||||
return parseNumber(d, parseFloat);
|
||||
}
|
||||
/**
|
||||
* Parse a string into a integer
|
||||
*
|
||||
* @param i - Integer value as string
|
||||
* @returns Number, or the original string if the argument is NaN
|
||||
*/
|
||||
function integer(i) {
|
||||
return parseNumber(i, parseInt);
|
||||
}
|
||||
function parseDate(s, format) {
|
||||
var m = dayjs_1.default.utc(s, format);
|
||||
if (m.isValid()) {
|
||||
return m.toDate();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
function parseNumber(n, parser) {
|
||||
var parsed = parser(n);
|
||||
if (typeof parsed === "number" && isNaN(parsed)) {
|
||||
return n;
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
53
node_modules/twilio/lib/base/serialize.d.ts
generated
vendored
Normal file
53
node_modules/twilio/lib/base/serialize.d.ts
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
import TwiML from "../twiml/TwiML";
|
||||
/**
|
||||
* @namespace serialize
|
||||
*/
|
||||
/**
|
||||
* Turns a Date object into a string if parameter is a Date otherwise returns the parameter
|
||||
*
|
||||
* @param d - date object to format
|
||||
* @returns date formatted in YYYY-MM-DD form, otherwise the
|
||||
* provided parameter.
|
||||
*/
|
||||
export declare function iso8601Date<T>(date: T | Date): T | string;
|
||||
/**
|
||||
* Turns a Date object into a string if parameter is a Date otherwise returns the parameter
|
||||
*
|
||||
* @param d - date object to format
|
||||
* @returns date formatted in YYYY-MM-DD[T]HH:mm:ss[Z] form, otherwise the
|
||||
* provided parameter.
|
||||
*/
|
||||
export declare function iso8601DateTime<T>(date: T | Date): T | string;
|
||||
/**
|
||||
* Turns a map of params int oa flattened map separated by dots if the parameter is an object, otherwise returns an empty map
|
||||
*
|
||||
* @param m - map to transform
|
||||
* @param prefix - to append to each flattened value
|
||||
* @returns flattened map
|
||||
*/
|
||||
export declare function prefixedCollapsibleMap<T extends {}>(m: T, prefix?: string): T;
|
||||
/**
|
||||
* Turns an object into a JSON string if the parameter is an object, otherwise returns the passed in object
|
||||
*
|
||||
* @param o - json object or array
|
||||
* @returns stringified object
|
||||
*/
|
||||
export declare function object<T>(o: T): T;
|
||||
/**
|
||||
* Coerces a boolean literal into a string
|
||||
*
|
||||
* @param input - boolean or string to be coerced
|
||||
* @returns a string 'true' or 'false' if passed a boolean, else the value
|
||||
*/
|
||||
export declare function bool(input: string | boolean): string | "true" | "false";
|
||||
export declare function twiml(input: TwiML | string): string;
|
||||
type MapFunction<TInput, TOutput> = (input: TInput) => TOutput;
|
||||
/**
|
||||
* Maps transform over each element in input if input is an array
|
||||
*
|
||||
* @param input - array to map transform over, if not an array then it is
|
||||
* returned as is.
|
||||
* @returns new array with transform applied to each element.
|
||||
*/
|
||||
export declare function map<TInput, TOutput>(input: Array<TInput>, transform: MapFunction<TInput, TOutput>): Array<TOutput>;
|
||||
export {};
|
||||
121
node_modules/twilio/lib/base/serialize.js
generated
vendored
Normal file
121
node_modules/twilio/lib/base/serialize.js
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.iso8601Date = iso8601Date;
|
||||
exports.iso8601DateTime = iso8601DateTime;
|
||||
exports.prefixedCollapsibleMap = prefixedCollapsibleMap;
|
||||
exports.object = object;
|
||||
exports.bool = bool;
|
||||
exports.twiml = twiml;
|
||||
exports.map = map;
|
||||
const dayjs_1 = __importDefault(require("dayjs"));
|
||||
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
||||
dayjs_1.default.extend(utc_1.default);
|
||||
/**
|
||||
* @namespace serialize
|
||||
*/
|
||||
/**
|
||||
* Turns a Date object into a string if parameter is a Date otherwise returns the parameter
|
||||
*
|
||||
* @param d - date object to format
|
||||
* @returns date formatted in YYYY-MM-DD form, otherwise the
|
||||
* provided parameter.
|
||||
*/
|
||||
function iso8601Date(date) {
|
||||
if (!date || !(date instanceof Date)) {
|
||||
return date;
|
||||
}
|
||||
else {
|
||||
return dayjs_1.default.utc(date).format("YYYY-MM-DD");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Turns a Date object into a string if parameter is a Date otherwise returns the parameter
|
||||
*
|
||||
* @param d - date object to format
|
||||
* @returns date formatted in YYYY-MM-DD[T]HH:mm:ss[Z] form, otherwise the
|
||||
* provided parameter.
|
||||
*/
|
||||
function iso8601DateTime(date) {
|
||||
if (!date || !(date instanceof Date)) {
|
||||
return date;
|
||||
}
|
||||
else {
|
||||
return dayjs_1.default.utc(date).format("YYYY-MM-DD[T]HH:mm:ss[Z]");
|
||||
}
|
||||
}
|
||||
function prefixedCollapsibleMap(m, prefix) {
|
||||
if (!m ||
|
||||
typeof m !== "object" ||
|
||||
Object.prototype.toString.call(m) !== "[object Object]") {
|
||||
return {};
|
||||
}
|
||||
function flatten(m, result, previous) {
|
||||
result = result || {};
|
||||
previous = previous || [];
|
||||
Object.keys(m).forEach((key) => {
|
||||
const unionKeys = [...previous];
|
||||
if (!unionKeys.includes(key)) {
|
||||
unionKeys.push(key);
|
||||
}
|
||||
if (typeof m[key] === "object" &&
|
||||
Object.prototype.toString.call(m[key]) === "[object Object]") {
|
||||
flatten(m[key], result, unionKeys);
|
||||
}
|
||||
else {
|
||||
result[unionKeys.join(".")] = m[key];
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
var flattened = flatten(m);
|
||||
var result = flattened;
|
||||
if (prefix) {
|
||||
result = {};
|
||||
Object.keys(flattened).forEach((key) => {
|
||||
result[prefix + "." + key] = flattened[key];
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function object(o) {
|
||||
if (typeof o === "object") {
|
||||
return JSON.stringify(o);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
/**
|
||||
* Coerces a boolean literal into a string
|
||||
*
|
||||
* @param input - boolean or string to be coerced
|
||||
* @returns a string 'true' or 'false' if passed a boolean, else the value
|
||||
*/
|
||||
function bool(input) {
|
||||
if (typeof input === "string") {
|
||||
return input;
|
||||
}
|
||||
if (typeof input === "boolean" ||
|
||||
(typeof input === "object" &&
|
||||
Object.prototype.toString.call(input) === "[object Boolean]")) {
|
||||
return input.toString();
|
||||
}
|
||||
return input;
|
||||
}
|
||||
function twiml(input) {
|
||||
return input.toString();
|
||||
}
|
||||
/**
|
||||
* Maps transform over each element in input if input is an array
|
||||
*
|
||||
* @param input - array to map transform over, if not an array then it is
|
||||
* returned as is.
|
||||
* @returns new array with transform applied to each element.
|
||||
*/
|
||||
function map(input, transform) {
|
||||
if (typeof input === "object" && Array.isArray(input)) {
|
||||
return input.map((element) => transform(element));
|
||||
}
|
||||
return input;
|
||||
}
|
||||
2
node_modules/twilio/lib/base/utility.d.ts
generated
vendored
Normal file
2
node_modules/twilio/lib/base/utility.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export declare const trim: (str: string, c?: string) => string;
|
||||
export declare function isValidPathParam(param: any): boolean;
|
||||
13
node_modules/twilio/lib/base/utility.js
generated
vendored
Normal file
13
node_modules/twilio/lib/base/utility.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.trim = void 0;
|
||||
exports.isValidPathParam = isValidPathParam;
|
||||
const INVALID_PATH_PARAM_CHARS = ["/", "?"];
|
||||
const trim = (str, c = "\\s") => str.replace(new RegExp(`^([${c}]*)(.*?)([${c}]*)$`), "$2");
|
||||
exports.trim = trim;
|
||||
function isValidPathParam(param) {
|
||||
if (param === null || param === undefined)
|
||||
return false;
|
||||
const paramString = param.toString();
|
||||
return INVALID_PATH_PARAM_CHARS.every((invalidChar) => !paramString.includes(invalidChar));
|
||||
}
|
||||
10
node_modules/twilio/lib/base/values.d.ts
generated
vendored
Normal file
10
node_modules/twilio/lib/base/values.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @namespace values
|
||||
*/
|
||||
/**
|
||||
* Removes all undefined values of an object
|
||||
*
|
||||
* @param obj - object to filter
|
||||
* @returns object with no undefined values
|
||||
*/
|
||||
export declare function of(obj: Object): Object;
|
||||
15
node_modules/twilio/lib/base/values.js
generated
vendored
Normal file
15
node_modules/twilio/lib/base/values.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
/**
|
||||
* @namespace values
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.of = of;
|
||||
/**
|
||||
* Removes all undefined values of an object
|
||||
*
|
||||
* @param obj - object to filter
|
||||
* @returns object with no undefined values
|
||||
*/
|
||||
function of(obj) {
|
||||
return Object.fromEntries(Object.entries(obj).filter((entry) => entry[1] !== undefined));
|
||||
}
|
||||
Reference in New Issue
Block a user