Auto-commit 2026-04-29 16:31
This commit is contained in:
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("/");
|
||||
}
|
||||
Reference in New Issue
Block a user