Auto-commit 2026-04-29 16:31
This commit is contained in:
186
node_modules/twilio/lib/jwt/AccessToken.d.ts
generated
vendored
Normal file
186
node_modules/twilio/lib/jwt/AccessToken.d.ts
generated
vendored
Normal file
@@ -0,0 +1,186 @@
|
||||
declare class AccessToken implements AccessToken.AccessTokenOptions {
|
||||
static DEFAULT_ALGORITHM: "HS256";
|
||||
static ALGORITHMS: string[];
|
||||
accountSid: string;
|
||||
keySid: string;
|
||||
secret: string;
|
||||
ttl: number;
|
||||
identity: string;
|
||||
nbf?: number;
|
||||
region?: string;
|
||||
grants: AccessToken.Grant<any, any, any>[];
|
||||
/**
|
||||
* @param accountSid - The account's unique ID to which access is scoped
|
||||
* @param keySid - The signing key's unique ID
|
||||
* @param secret - The secret to sign the token with
|
||||
* @param options - ...
|
||||
* @param options.ttl - Time to live in seconds (default 3600)
|
||||
* @param options.identity - The identity of the first person. Required.
|
||||
* @param options.nbf - Time from epoch in seconds for not before value
|
||||
* @param options.region - The region value associated with this account
|
||||
*/
|
||||
constructor(accountSid: string, keySid: string, secret: string, options: AccessToken.AccessTokenOptions);
|
||||
addGrant<T extends AccessToken.Grant<any, any, any>>(grant: T): void;
|
||||
toJwt(algorithm?: "HS256" | "HS384" | "HS512"): string;
|
||||
}
|
||||
declare namespace AccessToken {
|
||||
abstract class Grant<TOptions, TPayload, TKey> {
|
||||
key: TKey;
|
||||
protected constructor(key: TKey);
|
||||
abstract toPayload(): TPayload;
|
||||
}
|
||||
interface TaskRouterGrantOptions {
|
||||
workspaceSid?: string;
|
||||
workerSid?: string;
|
||||
role?: string;
|
||||
}
|
||||
interface TaskRouterGrantPayload {
|
||||
workspace_sid?: string;
|
||||
worker_sid?: string;
|
||||
role?: string;
|
||||
}
|
||||
interface ChatGrantOptions {
|
||||
serviceSid?: string;
|
||||
endpointId?: string;
|
||||
deploymentRoleSid?: string;
|
||||
pushCredentialSid?: string;
|
||||
}
|
||||
interface ChatGrantPayload {
|
||||
service_sid?: string;
|
||||
endpoint_id?: string;
|
||||
deployment_role_sid?: string;
|
||||
push_credential_sid?: string;
|
||||
}
|
||||
interface VideoGrantOptions {
|
||||
room?: string;
|
||||
}
|
||||
interface VideoGrantPayload {
|
||||
room?: string;
|
||||
}
|
||||
interface SyncGrantOptions {
|
||||
serviceSid?: string;
|
||||
endpointId?: string;
|
||||
}
|
||||
interface SyncGrantPayload {
|
||||
service_sid?: string;
|
||||
endpoint_id?: string;
|
||||
}
|
||||
interface VoiceGrantOptions {
|
||||
incomingAllow?: boolean;
|
||||
outgoingApplicationSid?: string;
|
||||
outgoingApplicationParams?: object;
|
||||
pushCredentialSid?: string;
|
||||
endpointId?: string;
|
||||
}
|
||||
interface VoiceGrantPayload {
|
||||
incoming?: {
|
||||
allow: boolean;
|
||||
};
|
||||
outgoing?: {
|
||||
application_sid: string;
|
||||
params?: object;
|
||||
};
|
||||
push_credential_sid?: string;
|
||||
endpoint_id?: string;
|
||||
}
|
||||
interface PlaybackGrantOptions {
|
||||
grant?: object;
|
||||
}
|
||||
interface PlaybackGrantPayload {
|
||||
grant?: object;
|
||||
}
|
||||
interface AccessTokenOptions {
|
||||
/**
|
||||
* Time to live in seconds
|
||||
*/
|
||||
ttl?: number;
|
||||
/**
|
||||
* The identity of the first person. Required.
|
||||
*/
|
||||
identity: string;
|
||||
/**
|
||||
* Time from epoch in seconds for not before value
|
||||
*/
|
||||
nbf?: number;
|
||||
/**
|
||||
* The region value associated with this account
|
||||
*/
|
||||
region?: string;
|
||||
}
|
||||
class TaskRouterGrant extends Grant<TaskRouterGrantOptions, TaskRouterGrantPayload, "task_router"> implements TaskRouterGrantOptions {
|
||||
workspaceSid?: string;
|
||||
workerSid?: string;
|
||||
role?: string;
|
||||
/**
|
||||
* @param options - ...
|
||||
* @param options.workspaceSid - The workspace unique ID
|
||||
* @param options.workerSid - The worker unique ID
|
||||
* @param options.role - The role of the grant
|
||||
*/
|
||||
constructor(options?: TaskRouterGrantOptions);
|
||||
toPayload(): TaskRouterGrantPayload;
|
||||
}
|
||||
class ChatGrant extends Grant<ChatGrantOptions, ChatGrantPayload, "chat"> implements ChatGrantOptions {
|
||||
serviceSid?: string;
|
||||
endpointId?: string;
|
||||
deploymentRoleSid?: string;
|
||||
pushCredentialSid?: string;
|
||||
/**
|
||||
* @param options - ...
|
||||
* @param options.serviceSid - The service unique ID
|
||||
* @param options.endpointId - The endpoint ID
|
||||
* @param options.deploymentRoleSid - SID of the deployment role to be
|
||||
* assigned to the user
|
||||
* @param options.pushCredentialSid - The Push Credentials SID
|
||||
*/
|
||||
constructor(options?: ChatGrantOptions);
|
||||
toPayload(): ChatGrantPayload;
|
||||
}
|
||||
class VideoGrant extends Grant<VideoGrantOptions, VideoGrantPayload, "video"> implements VideoGrantOptions {
|
||||
room?: string;
|
||||
/**
|
||||
* @param options - ...
|
||||
* @param options.room - The Room name or Room sid.
|
||||
*/
|
||||
constructor(options?: VideoGrantOptions);
|
||||
toPayload(): VideoGrantPayload;
|
||||
}
|
||||
class SyncGrant extends Grant<SyncGrantOptions, SyncGrantPayload, "data_sync"> implements SyncGrantOptions {
|
||||
serviceSid?: string;
|
||||
endpointId?: string;
|
||||
/**
|
||||
* @param options.serviceSid - The service unique ID
|
||||
* @param options.endpointId - The endpoint ID
|
||||
*/
|
||||
constructor(options?: SyncGrantOptions);
|
||||
toPayload(): SyncGrantPayload;
|
||||
}
|
||||
class VoiceGrant extends Grant<VoiceGrantOptions, VoiceGrantPayload, "voice"> implements VoiceGrantOptions {
|
||||
incomingAllow?: boolean;
|
||||
outgoingApplicationSid?: string;
|
||||
outgoingApplicationParams?: object;
|
||||
pushCredentialSid?: string;
|
||||
endpointId?: string;
|
||||
/**
|
||||
* @param options - ...
|
||||
* @param options.incomingAllow - Whether or not this endpoint is allowed to receive incoming calls as grants.identity
|
||||
* @param options.outgoingApplicationSid - application sid to call when placing outgoing call
|
||||
* @param options.outgoingApplicationParams - request params to pass to the application
|
||||
* @param options.pushCredentialSid - Push Credential Sid to use when registering to receive incoming call notifications
|
||||
* @param options.endpointId - Specify an endpoint identifier for this device, which will allow the developer
|
||||
* to direct calls to a specific endpoint when multiple devices are associated with a single identity
|
||||
*/
|
||||
constructor(options?: VoiceGrantOptions);
|
||||
toPayload(): VoiceGrantPayload;
|
||||
}
|
||||
class PlaybackGrant extends Grant<PlaybackGrantOptions, PlaybackGrantPayload, "player"> implements PlaybackGrantOptions {
|
||||
grant?: object;
|
||||
/**
|
||||
* @param options - ...
|
||||
* @param options.grant - The PlaybackGrant retrieved from Twilio's API
|
||||
*/
|
||||
constructor(options?: PlaybackGrantOptions);
|
||||
toPayload(): PlaybackGrantPayload;
|
||||
}
|
||||
}
|
||||
export = AccessToken;
|
||||
256
node_modules/twilio/lib/jwt/AccessToken.js
generated
vendored
Normal file
256
node_modules/twilio/lib/jwt/AccessToken.js
generated
vendored
Normal file
@@ -0,0 +1,256 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
||||
class AccessToken {
|
||||
/**
|
||||
* @param accountSid - The account's unique ID to which access is scoped
|
||||
* @param keySid - The signing key's unique ID
|
||||
* @param secret - The secret to sign the token with
|
||||
* @param options - ...
|
||||
* @param options.ttl - Time to live in seconds (default 3600)
|
||||
* @param options.identity - The identity of the first person. Required.
|
||||
* @param options.nbf - Time from epoch in seconds for not before value
|
||||
* @param options.region - The region value associated with this account
|
||||
*/
|
||||
constructor(accountSid, keySid, secret, options) {
|
||||
if (!accountSid) {
|
||||
throw new Error("accountSid is required");
|
||||
}
|
||||
if (!keySid) {
|
||||
throw new Error("keySid is required");
|
||||
}
|
||||
if (!secret) {
|
||||
throw new Error("secret is required");
|
||||
}
|
||||
if (!options || !options.identity) {
|
||||
throw new Error("identity is required to be specified in options");
|
||||
}
|
||||
this.accountSid = accountSid;
|
||||
this.keySid = keySid;
|
||||
this.secret = secret;
|
||||
this.ttl = options.ttl || 3600;
|
||||
this.identity = options.identity;
|
||||
this.nbf = options.nbf;
|
||||
this.region = options.region;
|
||||
this.grants = [];
|
||||
}
|
||||
addGrant(grant) {
|
||||
this.grants.push(grant);
|
||||
}
|
||||
toJwt(algorithm) {
|
||||
algorithm = algorithm || AccessToken.DEFAULT_ALGORITHM;
|
||||
if (!AccessToken.ALGORITHMS.includes(algorithm)) {
|
||||
throw new Error("Algorithm not supported. Allowed values are " +
|
||||
AccessToken.ALGORITHMS.join(", "));
|
||||
}
|
||||
let grants = {};
|
||||
if (Number.isInteger(this.identity) || typeof this.identity === "string") {
|
||||
grants.identity = String(this.identity);
|
||||
}
|
||||
for (const grant of this.grants) {
|
||||
grants[grant.key] = grant.toPayload();
|
||||
}
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
let payload = {
|
||||
jti: this.keySid + "-" + now,
|
||||
grants: grants,
|
||||
};
|
||||
if (typeof this.nbf === "number") {
|
||||
payload.nbf = this.nbf;
|
||||
}
|
||||
let header = {
|
||||
cty: "twilio-fpa;v=1",
|
||||
typ: "JWT",
|
||||
};
|
||||
if (this.region && typeof this.region === "string") {
|
||||
header.twr = this.region;
|
||||
}
|
||||
return jsonwebtoken_1.default.sign(payload, this.secret, {
|
||||
header: header,
|
||||
algorithm: algorithm,
|
||||
issuer: this.keySid,
|
||||
subject: this.accountSid,
|
||||
expiresIn: this.ttl,
|
||||
});
|
||||
}
|
||||
}
|
||||
AccessToken.DEFAULT_ALGORITHM = "HS256";
|
||||
AccessToken.ALGORITHMS = ["HS256", "HS384", "HS512"];
|
||||
(function (AccessToken) {
|
||||
class Grant {
|
||||
constructor(key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
AccessToken.Grant = Grant;
|
||||
class TaskRouterGrant extends Grant {
|
||||
/**
|
||||
* @param options - ...
|
||||
* @param options.workspaceSid - The workspace unique ID
|
||||
* @param options.workerSid - The worker unique ID
|
||||
* @param options.role - The role of the grant
|
||||
*/
|
||||
constructor(options) {
|
||||
options = options || {};
|
||||
super("task_router");
|
||||
this.workspaceSid = options.workspaceSid;
|
||||
this.workerSid = options.workerSid;
|
||||
this.role = options.role;
|
||||
}
|
||||
toPayload() {
|
||||
let grant = {};
|
||||
if (this.workspaceSid) {
|
||||
grant.workspace_sid = this.workspaceSid;
|
||||
}
|
||||
if (this.workerSid) {
|
||||
grant.worker_sid = this.workerSid;
|
||||
}
|
||||
if (this.role) {
|
||||
grant.role = this.role;
|
||||
}
|
||||
return grant;
|
||||
}
|
||||
}
|
||||
AccessToken.TaskRouterGrant = TaskRouterGrant;
|
||||
class ChatGrant extends Grant {
|
||||
/**
|
||||
* @param options - ...
|
||||
* @param options.serviceSid - The service unique ID
|
||||
* @param options.endpointId - The endpoint ID
|
||||
* @param options.deploymentRoleSid - SID of the deployment role to be
|
||||
* assigned to the user
|
||||
* @param options.pushCredentialSid - The Push Credentials SID
|
||||
*/
|
||||
constructor(options) {
|
||||
options = options || {};
|
||||
super("chat");
|
||||
this.serviceSid = options.serviceSid;
|
||||
this.endpointId = options.endpointId;
|
||||
this.deploymentRoleSid = options.deploymentRoleSid;
|
||||
this.pushCredentialSid = options.pushCredentialSid;
|
||||
}
|
||||
toPayload() {
|
||||
let grant = {};
|
||||
if (this.serviceSid) {
|
||||
grant.service_sid = this.serviceSid;
|
||||
}
|
||||
if (this.endpointId) {
|
||||
grant.endpoint_id = this.endpointId;
|
||||
}
|
||||
if (this.deploymentRoleSid) {
|
||||
grant.deployment_role_sid = this.deploymentRoleSid;
|
||||
}
|
||||
if (this.pushCredentialSid) {
|
||||
grant.push_credential_sid = this.pushCredentialSid;
|
||||
}
|
||||
return grant;
|
||||
}
|
||||
}
|
||||
AccessToken.ChatGrant = ChatGrant;
|
||||
class VideoGrant extends Grant {
|
||||
/**
|
||||
* @param options - ...
|
||||
* @param options.room - The Room name or Room sid.
|
||||
*/
|
||||
constructor(options) {
|
||||
options = options || {};
|
||||
super("video");
|
||||
this.room = options.room;
|
||||
}
|
||||
toPayload() {
|
||||
let grant = {};
|
||||
if (this.room) {
|
||||
grant.room = this.room;
|
||||
}
|
||||
return grant;
|
||||
}
|
||||
}
|
||||
AccessToken.VideoGrant = VideoGrant;
|
||||
class SyncGrant extends Grant {
|
||||
/**
|
||||
* @param options.serviceSid - The service unique ID
|
||||
* @param options.endpointId - The endpoint ID
|
||||
*/
|
||||
constructor(options) {
|
||||
options = options || {};
|
||||
super("data_sync");
|
||||
this.serviceSid = options.serviceSid;
|
||||
this.endpointId = options.endpointId;
|
||||
}
|
||||
toPayload() {
|
||||
let grant = {};
|
||||
if (this.serviceSid) {
|
||||
grant.service_sid = this.serviceSid;
|
||||
}
|
||||
if (this.endpointId) {
|
||||
grant.endpoint_id = this.endpointId;
|
||||
}
|
||||
return grant;
|
||||
}
|
||||
}
|
||||
AccessToken.SyncGrant = SyncGrant;
|
||||
class VoiceGrant extends Grant {
|
||||
/**
|
||||
* @param options - ...
|
||||
* @param options.incomingAllow - Whether or not this endpoint is allowed to receive incoming calls as grants.identity
|
||||
* @param options.outgoingApplicationSid - application sid to call when placing outgoing call
|
||||
* @param options.outgoingApplicationParams - request params to pass to the application
|
||||
* @param options.pushCredentialSid - Push Credential Sid to use when registering to receive incoming call notifications
|
||||
* @param options.endpointId - Specify an endpoint identifier for this device, which will allow the developer
|
||||
* to direct calls to a specific endpoint when multiple devices are associated with a single identity
|
||||
*/
|
||||
constructor(options) {
|
||||
options = options || {};
|
||||
super("voice");
|
||||
this.incomingAllow = options.incomingAllow;
|
||||
this.outgoingApplicationSid = options.outgoingApplicationSid;
|
||||
this.outgoingApplicationParams = options.outgoingApplicationParams;
|
||||
this.pushCredentialSid = options.pushCredentialSid;
|
||||
this.endpointId = options.endpointId;
|
||||
}
|
||||
toPayload() {
|
||||
let grant = {};
|
||||
if (this.incomingAllow === true) {
|
||||
grant.incoming = { allow: true };
|
||||
}
|
||||
if (this.outgoingApplicationSid) {
|
||||
grant.outgoing = {
|
||||
application_sid: this.outgoingApplicationSid,
|
||||
};
|
||||
if (this.outgoingApplicationParams) {
|
||||
grant.outgoing.params = this.outgoingApplicationParams;
|
||||
}
|
||||
}
|
||||
if (this.pushCredentialSid) {
|
||||
grant.push_credential_sid = this.pushCredentialSid;
|
||||
}
|
||||
if (this.endpointId) {
|
||||
grant.endpoint_id = this.endpointId;
|
||||
}
|
||||
return grant;
|
||||
}
|
||||
}
|
||||
AccessToken.VoiceGrant = VoiceGrant;
|
||||
class PlaybackGrant extends Grant {
|
||||
/**
|
||||
* @param options - ...
|
||||
* @param options.grant - The PlaybackGrant retrieved from Twilio's API
|
||||
*/
|
||||
constructor(options) {
|
||||
options = options || {};
|
||||
super("player");
|
||||
this.grant = options.grant;
|
||||
}
|
||||
toPayload() {
|
||||
let grant = {};
|
||||
if (this.grant) {
|
||||
grant = this.grant;
|
||||
}
|
||||
return grant;
|
||||
}
|
||||
}
|
||||
AccessToken.PlaybackGrant = PlaybackGrant;
|
||||
})(AccessToken || (AccessToken = {}));
|
||||
module.exports = AccessToken;
|
||||
61
node_modules/twilio/lib/jwt/ClientCapability.d.ts
generated
vendored
Normal file
61
node_modules/twilio/lib/jwt/ClientCapability.d.ts
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
export interface Scope {
|
||||
scope: string;
|
||||
payload(): string;
|
||||
}
|
||||
export interface OutgoingClientScopeOptions {
|
||||
applicationSid: string;
|
||||
clientName?: string;
|
||||
params?: object;
|
||||
}
|
||||
export interface ClientCapabilityOptions {
|
||||
accountSid: string;
|
||||
authToken: string;
|
||||
ttl?: number;
|
||||
}
|
||||
/**
|
||||
* @param filters
|
||||
*/
|
||||
export declare class EventStreamScope implements Scope {
|
||||
scope: string;
|
||||
filters: object;
|
||||
constructor(filters?: object);
|
||||
payload(): string;
|
||||
}
|
||||
/**
|
||||
* @param clientName
|
||||
*/
|
||||
export declare class IncomingClientScope implements Scope {
|
||||
scope: string;
|
||||
clientName: string;
|
||||
constructor(clientName: string);
|
||||
payload(): string;
|
||||
}
|
||||
export declare class OutgoingClientScope implements Scope {
|
||||
scope: string;
|
||||
applicationSid: string;
|
||||
clientName?: string;
|
||||
params?: object;
|
||||
/**
|
||||
* @param options - ...
|
||||
* @param options.applicationSid - the application sid
|
||||
* @param options.clientName - the client name
|
||||
* @param options.params - parameters
|
||||
*/
|
||||
constructor(options: OutgoingClientScopeOptions);
|
||||
payload(): string;
|
||||
}
|
||||
/**
|
||||
* @param options
|
||||
*/
|
||||
export default class ClientCapability {
|
||||
static EventStreamScope: typeof EventStreamScope;
|
||||
static IncomingClientScope: typeof IncomingClientScope;
|
||||
static OutgoingClientScope: typeof OutgoingClientScope;
|
||||
accountSid: string;
|
||||
authToken: string;
|
||||
ttl: number;
|
||||
scopes: Scope[];
|
||||
constructor(options: ClientCapabilityOptions);
|
||||
addScope(scope: Scope): void;
|
||||
toJwt(): string;
|
||||
}
|
||||
122
node_modules/twilio/lib/jwt/ClientCapability.js
generated
vendored
Normal file
122
node_modules/twilio/lib/jwt/ClientCapability.js
generated
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.OutgoingClientScope = exports.IncomingClientScope = exports.EventStreamScope = void 0;
|
||||
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
||||
const querystring_1 = __importDefault(require("querystring"));
|
||||
/**
|
||||
* @param filters
|
||||
*/
|
||||
class EventStreamScope {
|
||||
constructor(filters) {
|
||||
this.scope = "scope:stream:subscribe";
|
||||
this.filters = filters || {};
|
||||
}
|
||||
payload() {
|
||||
var queryArgs = ["path=/2010-04-01/Events"];
|
||||
if (Object.keys(this.filters).length > 0) {
|
||||
var queryParams = Object.entries(this.filters).map((filter) => {
|
||||
return [querystring_1.default.escape(filter[0]), querystring_1.default.escape(filter[1])].join("=");
|
||||
});
|
||||
var filterParams = queryParams.join("&");
|
||||
queryArgs.push(["appParams", querystring_1.default.escape(filterParams)].join("="));
|
||||
}
|
||||
var queryString = queryArgs.join("&");
|
||||
return [this.scope, queryString].join("?");
|
||||
}
|
||||
}
|
||||
exports.EventStreamScope = EventStreamScope;
|
||||
/**
|
||||
* @param clientName
|
||||
*/
|
||||
class IncomingClientScope {
|
||||
constructor(clientName) {
|
||||
this.scope = "scope:client:incoming";
|
||||
this.clientName = clientName;
|
||||
}
|
||||
payload() {
|
||||
var query = ["clientName", querystring_1.default.escape(this.clientName)].join("=");
|
||||
return [this.scope, query].join("?");
|
||||
}
|
||||
}
|
||||
exports.IncomingClientScope = IncomingClientScope;
|
||||
class OutgoingClientScope {
|
||||
/**
|
||||
* @param options - ...
|
||||
* @param options.applicationSid - the application sid
|
||||
* @param options.clientName - the client name
|
||||
* @param options.params - parameters
|
||||
*/
|
||||
constructor(options) {
|
||||
this.scope = "scope:client:outgoing";
|
||||
if (!options) {
|
||||
throw new Error('Required parameter "options" missing.');
|
||||
}
|
||||
if (typeof options !== "object") {
|
||||
throw new TypeError('Parameter "options" must be a type Object');
|
||||
}
|
||||
if (!options.applicationSid) {
|
||||
throw new Error('Required parameter "options.applicationSid" missing.');
|
||||
}
|
||||
this.applicationSid = options.applicationSid;
|
||||
this.clientName = options.clientName;
|
||||
this.params = options.params;
|
||||
}
|
||||
payload() {
|
||||
var queryArgs = [["appSid", querystring_1.default.escape(this.applicationSid)].join("=")];
|
||||
if (typeof this.clientName === "string") {
|
||||
queryArgs.push(["clientName", querystring_1.default.escape(this.clientName)].join("="));
|
||||
}
|
||||
if (typeof this.params === "object") {
|
||||
var queryParams = Object.entries(this.params).map((param) => {
|
||||
return [querystring_1.default.escape(param[0]), querystring_1.default.escape(param[1])].join("=");
|
||||
});
|
||||
var filterParams = queryParams.join("&");
|
||||
queryArgs.push(["appParams", querystring_1.default.escape(filterParams)].join("="));
|
||||
}
|
||||
var queryString = queryArgs.join("&");
|
||||
return [this.scope, queryString].join("?");
|
||||
}
|
||||
}
|
||||
exports.OutgoingClientScope = OutgoingClientScope;
|
||||
/**
|
||||
* @param options
|
||||
*/
|
||||
class ClientCapability {
|
||||
constructor(options) {
|
||||
if (!options) {
|
||||
throw new Error('Required parameter "options" missing.');
|
||||
}
|
||||
if (typeof options !== "object") {
|
||||
throw new TypeError('Parameter "options" must be a type Object');
|
||||
}
|
||||
if (!options.accountSid) {
|
||||
throw new Error('Required parameter "options.accountSid" missing.');
|
||||
}
|
||||
if (!options.authToken) {
|
||||
throw new Error('Required parameter "options.authToken" missing.');
|
||||
}
|
||||
this.accountSid = options.accountSid;
|
||||
this.authToken = options.authToken;
|
||||
this.ttl = options.ttl || 3600;
|
||||
this.scopes = [];
|
||||
}
|
||||
addScope(scope) {
|
||||
this.scopes.push(scope);
|
||||
}
|
||||
toJwt() {
|
||||
const scope = this.scopes.map((scope) => scope.payload()).join(" ");
|
||||
var payload = {
|
||||
scope: scope,
|
||||
iss: this.accountSid,
|
||||
exp: Math.floor(new Date().valueOf() / 1000) + this.ttl,
|
||||
};
|
||||
return jsonwebtoken_1.default.sign(payload, this.authToken);
|
||||
}
|
||||
}
|
||||
ClientCapability.EventStreamScope = EventStreamScope;
|
||||
ClientCapability.IncomingClientScope = IncomingClientScope;
|
||||
ClientCapability.OutgoingClientScope = OutgoingClientScope;
|
||||
exports.default = ClientCapability;
|
||||
74
node_modules/twilio/lib/jwt/taskrouter/TaskRouterCapability.d.ts
generated
vendored
Normal file
74
node_modules/twilio/lib/jwt/taskrouter/TaskRouterCapability.d.ts
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
export interface TaskRouterCapabilityOptions {
|
||||
accountSid: string;
|
||||
authToken: string;
|
||||
workspaceSid: string;
|
||||
channelId: string;
|
||||
friendlyName?: string;
|
||||
ttl?: number;
|
||||
version?: string;
|
||||
}
|
||||
export interface PolicyOptions {
|
||||
/** Policy URL */
|
||||
url?: string;
|
||||
/** HTTP Method */
|
||||
method?: string;
|
||||
/** Request query filter allowances */
|
||||
queryFilter?: object;
|
||||
/** Request post filter allowances */
|
||||
postFilter?: object;
|
||||
/** Allow the policy */
|
||||
allow?: boolean;
|
||||
}
|
||||
export interface PolicyPayload {
|
||||
url: string;
|
||||
method: string;
|
||||
query_filter: object;
|
||||
post_filter: object;
|
||||
allow: boolean;
|
||||
}
|
||||
/**
|
||||
* Create a new Policy
|
||||
*/
|
||||
export declare class Policy {
|
||||
url: string;
|
||||
method: string;
|
||||
queryFilter: object;
|
||||
postFilter: object;
|
||||
allow: boolean;
|
||||
/**
|
||||
* Create a new Policy instance
|
||||
*
|
||||
* @param options - ...
|
||||
* @param options.url - Policy URL
|
||||
* @param options.method - HTTP Method
|
||||
* @param options.queryFilter - Request query filter allowances
|
||||
* @param options.postFilter - Request post filter allowances
|
||||
* @param options.allowed - Allow the policy
|
||||
*/
|
||||
constructor(options?: PolicyOptions);
|
||||
payload(): PolicyPayload;
|
||||
}
|
||||
export default class TaskRouterCapability {
|
||||
accountSid: string;
|
||||
authToken: string;
|
||||
workspaceSid: string;
|
||||
channelId: string;
|
||||
ttl: number;
|
||||
version: string;
|
||||
policies: Policy[];
|
||||
friendlyName?: string;
|
||||
/**
|
||||
* @param options - ...
|
||||
* @param options.accountSid - account sid
|
||||
* @param options.authToken - auth token
|
||||
* @param options.workspaceSid - workspace sid
|
||||
* @param options.channelId - taskrouter channel id
|
||||
* @param options.friendlyName - friendly name for the jwt
|
||||
* @param options.ttl - time to live
|
||||
* @param options.version - taskrouter version
|
||||
*/
|
||||
constructor(options: TaskRouterCapabilityOptions);
|
||||
static Policy: typeof Policy;
|
||||
addPolicy(policy: Policy): void;
|
||||
toJwt(): string;
|
||||
}
|
||||
101
node_modules/twilio/lib/jwt/taskrouter/TaskRouterCapability.js
generated
vendored
Normal file
101
node_modules/twilio/lib/jwt/taskrouter/TaskRouterCapability.js
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Policy = void 0;
|
||||
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
||||
/**
|
||||
* Create a new Policy
|
||||
*/
|
||||
class Policy {
|
||||
/**
|
||||
* Create a new Policy instance
|
||||
*
|
||||
* @param options - ...
|
||||
* @param options.url - Policy URL
|
||||
* @param options.method - HTTP Method
|
||||
* @param options.queryFilter - Request query filter allowances
|
||||
* @param options.postFilter - Request post filter allowances
|
||||
* @param options.allowed - Allow the policy
|
||||
*/
|
||||
constructor(options) {
|
||||
options = options || {};
|
||||
this.url = options.url || "";
|
||||
this.method = options.method || "GET";
|
||||
this.queryFilter = options.queryFilter || {};
|
||||
this.postFilter = options.postFilter || {};
|
||||
this.allow = options.allow || true;
|
||||
}
|
||||
payload() {
|
||||
return {
|
||||
url: this.url,
|
||||
method: this.method,
|
||||
query_filter: this.queryFilter,
|
||||
post_filter: this.postFilter,
|
||||
allow: this.allow,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.Policy = Policy;
|
||||
class TaskRouterCapability {
|
||||
/**
|
||||
* @param options - ...
|
||||
* @param options.accountSid - account sid
|
||||
* @param options.authToken - auth token
|
||||
* @param options.workspaceSid - workspace sid
|
||||
* @param options.channelId - taskrouter channel id
|
||||
* @param options.friendlyName - friendly name for the jwt
|
||||
* @param options.ttl - time to live
|
||||
* @param options.version - taskrouter version
|
||||
*/
|
||||
constructor(options) {
|
||||
if (!options) {
|
||||
throw new Error('Required parameter "options" missing.');
|
||||
}
|
||||
if (!options.accountSid) {
|
||||
throw new Error('Required parameter "options.accountSid" missing.');
|
||||
}
|
||||
if (!options.authToken) {
|
||||
throw new Error('Required parameter "options.authToken" missing.');
|
||||
}
|
||||
if (!options.workspaceSid) {
|
||||
throw new Error('Required parameter "options.workspaceSid" missing.');
|
||||
}
|
||||
if (!options.channelId) {
|
||||
throw new Error('Required parameter "options.channelId" missing.');
|
||||
}
|
||||
this.accountSid = options.accountSid;
|
||||
this.authToken = options.authToken;
|
||||
this.workspaceSid = options.workspaceSid;
|
||||
this.channelId = options.channelId;
|
||||
this.friendlyName = options.friendlyName;
|
||||
this.ttl = options.ttl || 3600;
|
||||
this.version = options.version || "v1";
|
||||
this.policies = [];
|
||||
}
|
||||
addPolicy(policy) {
|
||||
this.policies.push(policy);
|
||||
}
|
||||
toJwt() {
|
||||
var payload = {
|
||||
iss: this.accountSid,
|
||||
exp: Math.floor(new Date().valueOf() / 1000) + this.ttl,
|
||||
version: this.version,
|
||||
friendly_name: this.friendlyName,
|
||||
account_sid: this.accountSid,
|
||||
channel: this.channelId,
|
||||
workspace_sid: this.workspaceSid,
|
||||
policies: this.policies.map((policy) => policy.payload()),
|
||||
};
|
||||
if (this.channelId.startsWith("WK")) {
|
||||
payload.worker_sid = this.channelId;
|
||||
}
|
||||
else if (this.channelId.startsWith("WQ")) {
|
||||
payload.taskqueue_sid = this.channelId;
|
||||
}
|
||||
return jsonwebtoken_1.default.sign(payload, this.authToken);
|
||||
}
|
||||
}
|
||||
TaskRouterCapability.Policy = Policy;
|
||||
exports.default = TaskRouterCapability;
|
||||
66
node_modules/twilio/lib/jwt/taskrouter/util.d.ts
generated
vendored
Normal file
66
node_modules/twilio/lib/jwt/taskrouter/util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
import { Policy } from "./TaskRouterCapability";
|
||||
/**
|
||||
* Build the default Policies for a worker
|
||||
*
|
||||
* @param version - TaskRouter version
|
||||
* @param workspaceSid - workspace sid
|
||||
* @param workerSid - worker sid
|
||||
* @returns list of Policies
|
||||
*/
|
||||
export declare function defaultWorkerPolicies(version: string, workspaceSid: string, workerSid: string): Policy[];
|
||||
/**
|
||||
* Build the default Event Bridge Policies
|
||||
*
|
||||
* @param accountSid - account sid
|
||||
* @param channelId - channel id
|
||||
* @returns list of Policies
|
||||
*/
|
||||
export declare function defaultEventBridgePolicies(accountSid: string, channelId: string): Policy[];
|
||||
/**
|
||||
* Generate TaskRouter workspace url
|
||||
*
|
||||
* @param workspaceSid - workspace sid or '**' for all workspaces
|
||||
* @returns generated url
|
||||
*/
|
||||
export declare function workspacesUrl(workspaceSid?: string): string;
|
||||
/**
|
||||
* Generate TaskRouter task queue url
|
||||
*
|
||||
* @param workspaceSid - workspace sid
|
||||
* @param taskQueueSid - task queue sid or '**' for all task queues
|
||||
* @returns generated url
|
||||
*/
|
||||
export declare function taskQueuesUrl(workspaceSid: string, taskQueueSid?: string): string;
|
||||
/**
|
||||
* Generate TaskRouter task url
|
||||
*
|
||||
* @param workspaceSid - workspace sid
|
||||
* @param taskSid - task sid or '**' for all tasks
|
||||
* @returns generated url
|
||||
*/
|
||||
export declare function tasksUrl(workspaceSid: string, taskSid?: string): string;
|
||||
/**
|
||||
* Generate TaskRouter activity url
|
||||
*
|
||||
* @param workspaceSid - workspace sid
|
||||
* @param activitySid - activity sid or '**' for all activities
|
||||
* @returns generated url
|
||||
*/
|
||||
export declare function activitiesUrl(workspaceSid: string, activitySid?: string): string;
|
||||
/**
|
||||
* Generate TaskRouter worker url
|
||||
*
|
||||
* @param workspaceSid - workspace sid
|
||||
* @param workerSid - worker sid or '**' for all workers
|
||||
* @returns generated url
|
||||
*/
|
||||
export declare function workersUrl(workspaceSid: string, workerSid?: string): string;
|
||||
/**
|
||||
* Generate TaskRouter worker reservation url
|
||||
*
|
||||
* @param workspaceSid - workspace sid
|
||||
* @param workerSid - worker sid
|
||||
* @param reservationSid - reservation sid or '**' for all reservations
|
||||
* @returns generated url
|
||||
*/
|
||||
export declare function reservationsUrl(workspaceSid: string, workerSid: string, reservationSid?: string): string;
|
||||
168
node_modules/twilio/lib/jwt/taskrouter/util.js
generated
vendored
Normal file
168
node_modules/twilio/lib/jwt/taskrouter/util.js
generated
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.defaultWorkerPolicies = defaultWorkerPolicies;
|
||||
exports.defaultEventBridgePolicies = defaultEventBridgePolicies;
|
||||
exports.workspacesUrl = workspacesUrl;
|
||||
exports.taskQueuesUrl = taskQueuesUrl;
|
||||
exports.tasksUrl = tasksUrl;
|
||||
exports.activitiesUrl = activitiesUrl;
|
||||
exports.workersUrl = workersUrl;
|
||||
exports.reservationsUrl = reservationsUrl;
|
||||
const TaskRouterCapability_1 = require("./TaskRouterCapability");
|
||||
const EVENT_URL_BASE = "https://event-bridge.twilio.com/v1/wschannels";
|
||||
const TASKROUTER_BASE_URL = "https://taskrouter.twilio.com";
|
||||
const TASKROUTER_VERSION = "v1";
|
||||
/**
|
||||
* Build the default Policies for a worker
|
||||
*
|
||||
* @param version - TaskRouter version
|
||||
* @param workspaceSid - workspace sid
|
||||
* @param workerSid - worker sid
|
||||
* @returns list of Policies
|
||||
*/
|
||||
function defaultWorkerPolicies(version, workspaceSid, workerSid) {
|
||||
var activities = new TaskRouterCapability_1.Policy({
|
||||
url: [
|
||||
TASKROUTER_BASE_URL,
|
||||
version,
|
||||
"Workspaces",
|
||||
workspaceSid,
|
||||
"Activities",
|
||||
].join("/"),
|
||||
method: "GET",
|
||||
allow: true,
|
||||
});
|
||||
var tasks = new TaskRouterCapability_1.Policy({
|
||||
url: [
|
||||
TASKROUTER_BASE_URL,
|
||||
version,
|
||||
"Workspaces",
|
||||
workspaceSid,
|
||||
"Tasks",
|
||||
"**",
|
||||
].join("/"),
|
||||
method: "GET",
|
||||
allow: true,
|
||||
});
|
||||
var reservations = new TaskRouterCapability_1.Policy({
|
||||
url: [
|
||||
TASKROUTER_BASE_URL,
|
||||
version,
|
||||
"Workspaces",
|
||||
workspaceSid,
|
||||
"Workers",
|
||||
workerSid,
|
||||
"Reservations",
|
||||
"**",
|
||||
].join("/"),
|
||||
method: "GET",
|
||||
allow: true,
|
||||
});
|
||||
var workerFetch = new TaskRouterCapability_1.Policy({
|
||||
url: [
|
||||
TASKROUTER_BASE_URL,
|
||||
version,
|
||||
"Workspaces",
|
||||
workspaceSid,
|
||||
"Workers",
|
||||
workerSid,
|
||||
].join("/"),
|
||||
method: "GET",
|
||||
allow: true,
|
||||
});
|
||||
return [activities, tasks, reservations, workerFetch];
|
||||
}
|
||||
/**
|
||||
* Build the default Event Bridge Policies
|
||||
*
|
||||
* @param accountSid - account sid
|
||||
* @param channelId - channel id
|
||||
* @returns list of Policies
|
||||
*/
|
||||
function defaultEventBridgePolicies(accountSid, channelId) {
|
||||
var url = [EVENT_URL_BASE, accountSid, channelId].join("/");
|
||||
return [
|
||||
new TaskRouterCapability_1.Policy({
|
||||
url: url,
|
||||
method: "GET",
|
||||
allow: true,
|
||||
}),
|
||||
new TaskRouterCapability_1.Policy({
|
||||
url: url,
|
||||
method: "POST",
|
||||
allow: true,
|
||||
}),
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Generate TaskRouter workspace url
|
||||
*
|
||||
* @param workspaceSid - workspace sid or '**' for all workspaces
|
||||
* @returns generated url
|
||||
*/
|
||||
function workspacesUrl(workspaceSid) {
|
||||
return [TASKROUTER_BASE_URL, TASKROUTER_VERSION, "Workspaces", workspaceSid]
|
||||
.filter((item) => typeof item === "string")
|
||||
.join("/");
|
||||
}
|
||||
/**
|
||||
* Generate TaskRouter task queue url
|
||||
*
|
||||
* @param workspaceSid - workspace sid
|
||||
* @param taskQueueSid - task queue sid or '**' for all task queues
|
||||
* @returns generated url
|
||||
*/
|
||||
function taskQueuesUrl(workspaceSid, taskQueueSid) {
|
||||
return [workspacesUrl(workspaceSid), "TaskQueues", taskQueueSid]
|
||||
.filter((item) => typeof item === "string")
|
||||
.join("/");
|
||||
}
|
||||
/**
|
||||
* Generate TaskRouter task url
|
||||
*
|
||||
* @param workspaceSid - workspace sid
|
||||
* @param taskSid - task sid or '**' for all tasks
|
||||
* @returns generated url
|
||||
*/
|
||||
function tasksUrl(workspaceSid, taskSid) {
|
||||
return [workspacesUrl(workspaceSid), "Tasks", taskSid]
|
||||
.filter((item) => typeof item === "string")
|
||||
.join("/");
|
||||
}
|
||||
/**
|
||||
* Generate TaskRouter activity url
|
||||
*
|
||||
* @param workspaceSid - workspace sid
|
||||
* @param activitySid - activity sid or '**' for all activities
|
||||
* @returns generated url
|
||||
*/
|
||||
function activitiesUrl(workspaceSid, activitySid) {
|
||||
return [workspacesUrl(workspaceSid), "Activities", activitySid]
|
||||
.filter((item) => typeof item === "string")
|
||||
.join("/");
|
||||
}
|
||||
/**
|
||||
* Generate TaskRouter worker url
|
||||
*
|
||||
* @param workspaceSid - workspace sid
|
||||
* @param workerSid - worker sid or '**' for all workers
|
||||
* @returns generated url
|
||||
*/
|
||||
function workersUrl(workspaceSid, workerSid) {
|
||||
return [workspacesUrl(workspaceSid), "Workers", workerSid]
|
||||
.filter((item) => typeof item === "string")
|
||||
.join("/");
|
||||
}
|
||||
/**
|
||||
* Generate TaskRouter worker reservation url
|
||||
*
|
||||
* @param workspaceSid - workspace sid
|
||||
* @param workerSid - worker sid
|
||||
* @param reservationSid - reservation sid or '**' for all reservations
|
||||
* @returns generated url
|
||||
*/
|
||||
function reservationsUrl(workspaceSid, workerSid, reservationSid) {
|
||||
return [workersUrl(workspaceSid, workerSid), "Reservations", reservationSid]
|
||||
.filter((item) => typeof item === "string")
|
||||
.join("/");
|
||||
}
|
||||
20
node_modules/twilio/lib/jwt/validation/RequestCanonicalizer.d.ts
generated
vendored
Normal file
20
node_modules/twilio/lib/jwt/validation/RequestCanonicalizer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
declare class RequestCanonicalizer {
|
||||
method: string;
|
||||
uri: string;
|
||||
queryParams: Record<string, string>;
|
||||
requestBody: any;
|
||||
headers: Record<string, string>;
|
||||
constructor(method: string, uri: string, queryParams: Record<string, string>, requestBody: any, headers: Record<string, string>);
|
||||
getCanonicalizedMethod(): string;
|
||||
customEncode(str: string): string;
|
||||
ASCIICompare(a: string, b: string): number;
|
||||
getCanonicalizedPath(): string;
|
||||
getCanonicalizedQueryParams(): string;
|
||||
getCanonicalizedHeaders(): string;
|
||||
getCanonicalizedHashedHeaders(): string;
|
||||
getCanonicalizedRequestBody(): string;
|
||||
sha256Hex(body: string): string;
|
||||
getCanonicalizedRequestString(): string;
|
||||
create(): string;
|
||||
}
|
||||
export default RequestCanonicalizer;
|
||||
97
node_modules/twilio/lib/jwt/validation/RequestCanonicalizer.js
generated
vendored
Normal file
97
node_modules/twilio/lib/jwt/validation/RequestCanonicalizer.js
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const crypto_1 = __importDefault(require("crypto"));
|
||||
class RequestCanonicalizer {
|
||||
constructor(method, uri, queryParams, requestBody, headers) {
|
||||
this.method = method;
|
||||
this.uri = uri;
|
||||
this.queryParams = queryParams;
|
||||
this.requestBody = requestBody;
|
||||
this.headers = headers;
|
||||
}
|
||||
getCanonicalizedMethod() {
|
||||
return this.method.toUpperCase();
|
||||
}
|
||||
customEncode(str) {
|
||||
return encodeURIComponent(decodeURIComponent(str))
|
||||
.replace(/\*/g, "%2A")
|
||||
.replace(/%7E/g, "~");
|
||||
}
|
||||
ASCIICompare(a, b) {
|
||||
if (a < b)
|
||||
return -1;
|
||||
return a > b ? 1 : 0;
|
||||
}
|
||||
getCanonicalizedPath() {
|
||||
// Remove query string from path
|
||||
const path = this.uri.split("?")[0];
|
||||
// Normalize duplicate slashes (but preserve the leading one)
|
||||
const normalizedPath = path.replace(/\/+/g, "/");
|
||||
// We must preserve slashes (as path delimiters) but encode each segment
|
||||
// Split and encode, but first decode each segment to avoid double-encoding
|
||||
return normalizedPath
|
||||
.split("/")
|
||||
.map((segment) => this.customEncode(segment))
|
||||
.join("/");
|
||||
}
|
||||
getCanonicalizedQueryParams() {
|
||||
if (!this.queryParams) {
|
||||
return "";
|
||||
}
|
||||
// sort query params on the basis of '{key}={value}'
|
||||
const sortedQueryParams = Object.entries(this.queryParams)
|
||||
.map(([key, value]) => {
|
||||
return `${key}=${value}`;
|
||||
})
|
||||
.sort((a, b) => this.ASCIICompare(a, b)) // forces ASCII sorting using custom compare
|
||||
.map((param) => {
|
||||
const [key, value] = param.split("=");
|
||||
return `${this.customEncode(key)}=${this.customEncode(value)}`; // encode and concatenate as `key=value`
|
||||
});
|
||||
return sortedQueryParams.join("&");
|
||||
}
|
||||
getCanonicalizedHeaders() {
|
||||
// sort headers on the basis of '{key}:{value}'
|
||||
const sortedHeaders = Object.keys(this.headers)
|
||||
.map((key) => {
|
||||
if (!this.headers[key]) {
|
||||
return `${key.toLowerCase()}:`;
|
||||
}
|
||||
return `${key.toLowerCase()}:${this.headers[key].trim()}`;
|
||||
})
|
||||
.sort((a, b) => this.ASCIICompare(a, b)); // forces ASCII sorting using custom compare
|
||||
return `${sortedHeaders.join("\n")}\n`;
|
||||
}
|
||||
getCanonicalizedHashedHeaders() {
|
||||
const sortedHeaders = Object.keys(this.headers).sort((a, b) => this.ASCIICompare(a, b)); // forces ASCII sorting using custom compare
|
||||
return sortedHeaders.join(";");
|
||||
}
|
||||
getCanonicalizedRequestBody() {
|
||||
if (!this.requestBody) {
|
||||
return "";
|
||||
}
|
||||
if (typeof this.requestBody === "string") {
|
||||
return this.sha256Hex(this.requestBody);
|
||||
}
|
||||
else
|
||||
return this.sha256Hex(JSON.stringify(this.requestBody));
|
||||
}
|
||||
sha256Hex(body) {
|
||||
return crypto_1.default.createHash("sha256").update(body).digest("hex");
|
||||
}
|
||||
getCanonicalizedRequestString() {
|
||||
return `${this.getCanonicalizedMethod()}
|
||||
${this.getCanonicalizedPath()}
|
||||
${this.getCanonicalizedQueryParams()}
|
||||
${this.getCanonicalizedHeaders()}
|
||||
${this.getCanonicalizedHashedHeaders()}
|
||||
${this.getCanonicalizedRequestBody()}`;
|
||||
}
|
||||
create() {
|
||||
return this.sha256Hex(this.getCanonicalizedRequestString());
|
||||
}
|
||||
}
|
||||
exports.default = RequestCanonicalizer;
|
||||
45
node_modules/twilio/lib/jwt/validation/ValidationToken.d.ts
generated
vendored
Normal file
45
node_modules/twilio/lib/jwt/validation/ValidationToken.d.ts
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
import { ValidationClientOptions } from "../../base/ValidationClient";
|
||||
import RequestCanonicalizer from "./RequestCanonicalizer";
|
||||
import jwt, { Algorithm } from "jsonwebtoken";
|
||||
declare class ValidationToken {
|
||||
static readonly DEFAULT_ALGORITHM: "RS256";
|
||||
static readonly ALGORITHMS: readonly [jwt.Algorithm, jwt.Algorithm];
|
||||
private readonly _accountSid;
|
||||
private readonly _credentialSid;
|
||||
private readonly _signingKey;
|
||||
private readonly _privateKey;
|
||||
private readonly _algorithm;
|
||||
ttl: number;
|
||||
get accountSid(): string;
|
||||
get credentialSid(): string;
|
||||
get signingKey(): string;
|
||||
get privateKey(): string;
|
||||
get algorithm(): Algorithm;
|
||||
/**
|
||||
* @constructor
|
||||
* @param opts - The Options used to configure the ValidationToken
|
||||
* @param opts.accountSid - The account SID
|
||||
* @param opts.credentialSid - The credential SID for public key submitted to Twilio
|
||||
* @param opts.signingKey - The signing key
|
||||
* @param opts.privateKey - The private key for signing the token
|
||||
* @param opts.algorithm - The algorithm to use for signing the token
|
||||
* @param opts.ttl - The time to live for the token in seconds
|
||||
*/
|
||||
constructor(opts: ValidationClientOptions);
|
||||
/**
|
||||
* Generates a `RequestCanonicalizer` instance for the given HTTP request.
|
||||
*
|
||||
* @param request - The HTTP request object containing details such as headers, URL, method, query parameters, and body.
|
||||
* @throws {Error} If the request URL or method is missing.
|
||||
* @returns {RequestCanonicalizer} - An instance of `RequestCanonicalizer` initialized with the canonicalized request details.
|
||||
*/
|
||||
getRequestCanonicalizer(request: any): RequestCanonicalizer;
|
||||
/**
|
||||
* Generate a JWT token to include in the request header for PKCV
|
||||
* @param request - The request object
|
||||
* @returns {string} - The JWT token
|
||||
*/
|
||||
fromHttpRequest(request: any): string;
|
||||
}
|
||||
declare namespace ValidationToken { }
|
||||
export = ValidationToken;
|
||||
121
node_modules/twilio/lib/jwt/validation/ValidationToken.js
generated
vendored
Normal file
121
node_modules/twilio/lib/jwt/validation/ValidationToken.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 };
|
||||
};
|
||||
const RequestCanonicalizer_1 = __importDefault(require("./RequestCanonicalizer"));
|
||||
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
||||
class ValidationToken {
|
||||
get accountSid() {
|
||||
return this._accountSid;
|
||||
}
|
||||
get credentialSid() {
|
||||
return this._credentialSid;
|
||||
}
|
||||
get signingKey() {
|
||||
return this._signingKey;
|
||||
}
|
||||
get privateKey() {
|
||||
return this._privateKey;
|
||||
}
|
||||
get algorithm() {
|
||||
return this._algorithm;
|
||||
}
|
||||
/**
|
||||
* @constructor
|
||||
* @param opts - The Options used to configure the ValidationToken
|
||||
* @param opts.accountSid - The account SID
|
||||
* @param opts.credentialSid - The credential SID for public key submitted to Twilio
|
||||
* @param opts.signingKey - The signing key
|
||||
* @param opts.privateKey - The private key for signing the token
|
||||
* @param opts.algorithm - The algorithm to use for signing the token
|
||||
* @param opts.ttl - The time to live for the token in seconds
|
||||
*/
|
||||
constructor(opts) {
|
||||
if (!opts.accountSid) {
|
||||
throw new Error("accountSid is required");
|
||||
}
|
||||
if (!opts.credentialSid) {
|
||||
throw new Error("credentialSid is required");
|
||||
}
|
||||
if (!opts.signingKey) {
|
||||
throw new Error("signingKey is required");
|
||||
}
|
||||
if (!opts.privateKey) {
|
||||
throw new Error("privateKey is required");
|
||||
}
|
||||
const algorithm = opts.algorithm ?? ValidationToken.DEFAULT_ALGORITHM; // default to RS256;
|
||||
if (!ValidationToken.ALGORITHMS.includes(algorithm)) {
|
||||
throw new Error("Algorithm not supported. Allowed values are " +
|
||||
ValidationToken.ALGORITHMS.join(", "));
|
||||
}
|
||||
this._accountSid = opts.accountSid;
|
||||
this._credentialSid = opts.credentialSid;
|
||||
this._signingKey = opts.signingKey;
|
||||
this._privateKey = opts.privateKey;
|
||||
this._algorithm = algorithm;
|
||||
this.ttl = 300;
|
||||
}
|
||||
/**
|
||||
* Generates a `RequestCanonicalizer` instance for the given HTTP request.
|
||||
*
|
||||
* @param request - The HTTP request object containing details such as headers, URL, method, query parameters, and body.
|
||||
* @throws {Error} If the request URL or method is missing.
|
||||
* @returns {RequestCanonicalizer} - An instance of `RequestCanonicalizer` initialized with the canonicalized request details.
|
||||
*/
|
||||
getRequestCanonicalizer(request) {
|
||||
const headers = request.headers ?? {};
|
||||
const requestUrl = request.url;
|
||||
const method = request.method;
|
||||
const queryParams = request.params;
|
||||
const requestBody = request.data;
|
||||
if (!requestUrl) {
|
||||
throw new Error("Url is required");
|
||||
}
|
||||
if (!method) {
|
||||
throw new Error("Method is required");
|
||||
}
|
||||
const url = new URL(requestUrl);
|
||||
let signedHeaders = {
|
||||
host: url.host,
|
||||
authorization: headers["Authorization"],
|
||||
};
|
||||
return new RequestCanonicalizer_1.default(method, url.pathname, queryParams, requestBody, signedHeaders);
|
||||
}
|
||||
/**
|
||||
* Generate a JWT token to include in the request header for PKCV
|
||||
* @param request - The request object
|
||||
* @returns {string} - The JWT token
|
||||
*/
|
||||
fromHttpRequest(request) {
|
||||
try {
|
||||
const requestCanonicalizer = this.getRequestCanonicalizer(request);
|
||||
const canonicalizedRequest = requestCanonicalizer.create();
|
||||
const header = {
|
||||
cty: "twilio-pkrv;v=1",
|
||||
typ: "JWT",
|
||||
alg: this._algorithm,
|
||||
kid: this._credentialSid,
|
||||
};
|
||||
const payload = {
|
||||
iss: this._signingKey,
|
||||
sub: this._accountSid,
|
||||
hrh: requestCanonicalizer.getCanonicalizedHashedHeaders(),
|
||||
rqh: canonicalizedRequest,
|
||||
};
|
||||
return jsonwebtoken_1.default.sign(payload, this._privateKey, {
|
||||
header: header,
|
||||
algorithm: this._algorithm,
|
||||
expiresIn: this.ttl,
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
throw new Error("Error generating JWT token " + err);
|
||||
}
|
||||
}
|
||||
}
|
||||
ValidationToken.DEFAULT_ALGORITHM = "RS256";
|
||||
ValidationToken.ALGORITHMS = [
|
||||
"RS256",
|
||||
"PS256",
|
||||
];
|
||||
module.exports = ValidationToken;
|
||||
Reference in New Issue
Block a user