twilio-taskrouter 0.8.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- /*! twilio-taskrouter.js 0.8.4 */
1
+ /*! twilio-taskrouter.js 2.0.0 */
package/dist/types.d.ts CHANGED
@@ -1,15 +1,16 @@
1
- import EventEmitter from "events";
1
+ import { EventEmitter } from 'events';
2
+ import TypedEmitter from 'typed-emitter';
2
3
 
3
4
  export as namespace TaskRouter;
4
- export class Worker extends EventEmitter {
5
- constructor(token: string, options?: any);
5
+ export class Worker extends (EventEmitter as new () => TypedEmitter<WorkerEvents>) {
6
+ constructor(token: string, options?: WorkerOptions);
6
7
 
7
8
  readonly accountSid: string;
8
9
  readonly activities: Map<string, Activity>;
9
10
  readonly activity: Activity;
10
11
  readonly activitySid: string;
11
12
  readonly available: boolean;
12
- readonly attributes: Object;
13
+ readonly attributes: Record<string, any>;
13
14
  readonly channels: Map<string, Channel>;
14
15
  readonly connectActivitySid: string;
15
16
  readonly dateCreated: Date;
@@ -26,7 +27,7 @@ export class Worker extends EventEmitter {
26
27
  readonly friendlyName: string;
27
28
  version: string;
28
29
 
29
- createTask(to: string, from: string, workflowSid: string, taskQueueSid: string, options: Object): Promise<string>
30
+ createTask(to: string, from: string, workflowSid: string, taskQueueSid: string, options?: TaskOptions): Promise<string>;
30
31
  disconnect(): void;
31
32
  setAttributes(attributes: any): Promise<Worker>;
32
33
  updateToken(newToken: string): void;
@@ -37,6 +38,18 @@ export class Supervisor extends Worker {
37
38
  monitor(taskSid: string, reservationSid: string, extraParams: Object): Promise<void>;
38
39
  }
39
40
 
41
+ interface WorkerEvents {
42
+ activityUpdated: (worker: Worker) => void;
43
+ attributesUpdated: (worker: Worker) => void;
44
+ disconnected: (worker: Worker) => void;
45
+ error: (error: Error) => void;
46
+ ready: (worker: Worker) => void;
47
+ reservationCreated: (reservation: Reservation) => void;
48
+ reservationFailed: (reservation: Reservation) => void;
49
+ tokenExpired: () => void;
50
+ tokenUpdated: () => void;
51
+ }
52
+
40
53
  export interface Activity {
41
54
  readonly accountSid: string;
42
55
  readonly available: boolean;
@@ -47,14 +60,16 @@ export interface Activity {
47
60
  readonly sid: string;
48
61
  readonly workspaceSid: string;
49
62
 
50
- setAsCurrent(): Promise<Activity>;
63
+ setAsCurrent(options?: ActivityOptions): Promise<Activity>;
51
64
  }
52
65
 
53
- export interface Channel {
66
+ export class Channel extends (EventEmitter as new () => TypedEmitter<ChannelEvents>) {
54
67
  readonly accountSid: string;
68
+ readonly assignedTasks: number;
55
69
  readonly available: boolean;
56
- readonly capacity: number;
57
70
  readonly availableCapacityPercentage: number;
71
+ readonly capacity: number;
72
+ readonly lastReservedTime: Date;
58
73
  readonly dateCreated: Date;
59
74
  readonly dateUpdated: Date;
60
75
  readonly sid: string;
@@ -64,10 +79,15 @@ export interface Channel {
64
79
  readonly workspaceSid: string;
65
80
  }
66
81
 
67
- export interface Task extends NodeJS.EventEmitter {
82
+ interface ChannelEvents {
83
+ availabilityUpdated: (channel: Channel) => void;
84
+ capacityUpdated: (channel: Channel) => void;
85
+ }
86
+
87
+ export class Task extends (EventEmitter as new () => TypedEmitter<TaskEvents>) {
68
88
  readonly addOns: Object;
69
89
  readonly age: number;
70
- readonly attributes: Object;
90
+ readonly attributes: Record<string, any>;
71
91
  readonly dateCreated: Date;
72
92
  readonly dateUpdated: Date;
73
93
  readonly priority: number;
@@ -79,33 +99,40 @@ export interface Task extends NodeJS.EventEmitter {
79
99
  readonly taskChannelSid: string;
80
100
  readonly taskChannelUniqueName: string;
81
101
  readonly timeout: number;
102
+ readonly transfers: Transfers;
82
103
  readonly workflowName: string;
83
104
  readonly workflowSid: string;
84
105
  readonly routingTarget: string;
85
106
  readonly version: string;
86
107
 
87
108
  complete(reason: string): Promise<Task>;
109
+ hold(targetWorkerSid: string, onHold: boolean, options?: TaskHoldOptions): Promise<Task>;
110
+ kick(workerSid: string): Promise<Task>;
88
111
  setAttributes(attributes: Object): Promise<Task>;
89
112
  transfer(to: string, options: TransferOptions): Promise<Task>;
90
113
  wrapUp(options: WrappingOptions): Promise<Task>;
91
114
  updateParticipant(options: TaskParticipantOptions): Promise<Task>;
92
- kick(workerSid: string): Promise<Task>;
93
- hold(targetWorkerSid: string, onHold: boolean, options: HoldOptions): Promise<Task>;
94
115
  fetchLatestVersion(): Promise<Task>;
95
116
  }
96
117
 
97
- export interface Reservation extends NodeJS.EventEmitter {
118
+ interface TaskEvents {
119
+ canceled: (task: Task) => void;
120
+ completed: (task: Task) => void;
121
+ transferInitiated: (outgoingTransfer: OutgoingTransfer) => void;
122
+ updated: (task: Task) => void;
123
+ wrapup: (task: Task) => void;
124
+ }
125
+
126
+ export class Reservation extends (EventEmitter as new () => TypedEmitter<ReservationEvents>) {
98
127
  readonly accountSid: string;
99
128
  readonly dateCreated: Date;
100
129
  readonly dateUpdated: Date;
101
130
  readonly sid: string;
102
- readonly status: "pending" | "accepted" | "rejected" | "timeout" | "canceled" | "rescinded";
103
- readonly taskChannelSid: string;
104
- readonly taskChannelUniqueName: string;
105
- readonly taskSid: string;
131
+ readonly status: "pending" | "accepted" | "rejected" | "timeout" | "canceled" | "rescinded" | "wrapping" | "completed";
132
+ readonly task: Task;
133
+ readonly timeout: number;
106
134
  readonly workerSid: string;
107
135
  readonly workspaceSid: string;
108
- readonly task: Task;
109
136
  readonly canceledReasonCode?: number;
110
137
  readonly version: string;
111
138
 
@@ -113,28 +140,38 @@ export interface Reservation extends NodeJS.EventEmitter {
113
140
  complete(): Promise<Reservation>;
114
141
  wrap(): Promise<Reservation>;
115
142
  call(from: string, url: string, options?: CallOptions): Promise<Reservation>;
116
- dequeue(options?: DequeueOptions): Promise<Reservation>;
117
143
  conference(options?: ConferenceOptions): Promise<Reservation>;
144
+ dequeue(options?: DequeueOptions): Promise<Reservation>;
118
145
  redirect(callSid: string, url: string, options?: RedirectOptions): Promise<Reservation>;
119
146
  reject(options?: RejectOptions): Promise<Reservation>;
120
147
  updateParticipant(options: ReservationParticipantOptions): Promise<Reservation>;
121
148
  fetchLatestVersion(): Promise<Reservation>;
122
149
  }
123
150
 
151
+ interface ReservationEvents {
152
+ accepted: (reservation: Reservation) => void;
153
+ canceled: (reservation: Reservation) => void;
154
+ completed: (reservation: Reservation) => void;
155
+ rejected: (reservation: Reservation) => void;
156
+ rescinded: (reservation: Reservation) => void;
157
+ timeout: (reservation: Reservation) => void;
158
+ wrapup: (reservation: Reservation) => void;
159
+ }
160
+
124
161
  export interface TaskQueue {
125
- sid: string;
126
- queueSid: string;
127
- accountSid: string;
128
- workspaceSid: string;
129
- name: string;
130
- queueName: string;
131
- assignmentActivityName: string;
132
- reservationActivityName: string;
133
- assignmentActivitySid: string;
134
- reservationActivitySid: string;
135
- targetWorkers: string;
136
- maxReservedWorkers: number;
137
- taskOrder: string;
162
+ readonly sid: string;
163
+ readonly queueSid: string;
164
+ readonly queueName: string;
165
+ readonly accountSid: string;
166
+ readonly workplaceSid: string;
167
+ readonly name: string;
168
+ readonly assignmentActivityName: string;
169
+ readonly reservationActivityName: string;
170
+ readonly assignmentActivitySid: string;
171
+ readonly reservationActivitySid: string;
172
+ readonly targetWorkers: string;
173
+ readonly maxReservedWorkers: number;
174
+ readonly taskOrder: string;
138
175
  dateCreated: Date;
139
176
  dateUpdated: Date;
140
177
  }
@@ -157,7 +194,7 @@ type FetchWorkersParams = {
157
194
  ActivityName?: string;
158
195
  TargetWorkersExpression?: string;
159
196
  Ordering?: "DateStatusChanged:asc" | "DateStatusChanged:desc"
160
- maxWorkers?: number;
197
+ MaxWorkers?: number;
161
198
  };
162
199
 
163
200
  export class Workspace {
@@ -171,13 +208,44 @@ export class Workspace {
171
208
  fetchTaskQueues(params?: FetchTaskQueuesParams): Promise<Map<string, TaskQueue>>;
172
209
  }
173
210
 
211
+ export interface Transfers {
212
+ readonly incoming: IncomingTransfer;
213
+ readonly outgoing: OutgoingTransfer;
214
+ }
215
+
216
+ export interface IncomingTransfer {
217
+ readonly dateCreated: Date;
218
+ readonly dateUpdated: Date;
219
+ readonly mode: "WARM" | "COLD";
220
+ readonly reservationSid: string;
221
+ readonly sid: string;
222
+ readonly status: "INITIATED" | "FAILED" | "COMPLETE" | "CANCELED";
223
+ readonly to: string;
224
+ readonly type: "QUEUE" | "WORKER";
225
+ readonly workerSid: string;
226
+ }
227
+
228
+ export interface OutgoingTransfer extends EventEmitter {
229
+ readonly dateCreated: Date;
230
+ readonly dateUpdated: Date;
231
+ readonly mode: "WARM" | "COLD";
232
+ readonly reservationSid: string;
233
+ readonly sid: string;
234
+ readonly status: "INITIATED" | "FAILED" | "COMPLETED" | "CANCELED";
235
+ readonly to: string;
236
+ readonly transferFailedReason: string;
237
+ readonly type: "QUEUE" | "WORKER";
238
+ readonly workerSid: string;
239
+
240
+ cancel(): Promise<OutgoingTransfer>;
241
+ }
242
+
174
243
  export interface CallOptions {
175
- readonly statusCallbackUrl?: string;
176
244
  readonly accept?: boolean;
177
245
  readonly record?: boolean;
246
+ readonly statusCallbackUrl?: string;
178
247
  readonly to?: string;
179
248
  readonly timeout?: number;
180
-
181
249
  }
182
250
 
183
251
  export interface DequeueOptions {
@@ -231,26 +299,52 @@ export interface RejectOptions {
231
299
  }
232
300
 
233
301
  export interface TransferOptions {
234
- attributes: Object;
235
- mode: "COLD" | "WARM";
236
- priority: number;
302
+ attributes?: Object;
303
+ mode?: "COLD" | "WARM";
304
+ priority?: number;
237
305
  }
238
306
 
239
- export interface HoldOptions {
240
- holdUrl: string;
241
- holdMethod: "GET"
307
+ export interface TaskParticipantOptions extends TaskHoldOptions {
308
+ hold: boolean;
242
309
  }
243
310
 
244
- export interface TaskParticipantOptions extends HoldOptions {
245
- hold: boolean;
311
+ export interface WrappingOptions {
312
+ reason: string;
246
313
  }
247
314
 
248
315
  export interface ReservationParticipantOptions {
249
- endConferenceOnExit: boolean;
250
- mute: boolean;
251
- beepOnExit: boolean;
316
+ endConferenceOnExit?: boolean;
317
+ mute?: boolean;
318
+ beepOnExit?: boolean;
252
319
  }
253
320
 
254
- export interface WrappingOptions {
255
- reason: string;
321
+ export interface WorkerOptions {
322
+ connectActivitySid?: string;
323
+ closeExistingSessions?: boolean;
324
+ logLevel?: "error" | "warn" | "info" | "debug" | "trace" | "silent";
325
+ ebServer?: string;
326
+ wsServer?: string;
327
+ eventHandlerClass?: string;
328
+ region?: string;
329
+ }
330
+
331
+ export interface TaskOptions {
332
+ attributes?: any;
333
+ taskChannelUniqueName?: string;
334
+ taskChannelSid?: string;
335
+ }
336
+
337
+ export interface ActivityOptions {
338
+ rejectPendingReservations?: boolean;
339
+ }
340
+
341
+ export interface TaskHoldOptions {
342
+ holdUrl?: string;
343
+ holdMethod?: string;
344
+ }
345
+
346
+ export interface TaskTransferOptions {
347
+ attributes?: any;
348
+ mode?: "WARM" | "COLD";
349
+ priority?: string;
256
350
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "twilio-taskrouter",
3
3
  "title": "Twilio TaskRouter",
4
- "version": "0.8.4",
4
+ "version": "2.0.0",
5
5
  "description": "Twilio TaskRouter JavaScript library",
6
6
  "homepage": "https://www.twilio.com",
7
7
  "author": "Wanjun Li <wli@twilio.com>",
@@ -42,20 +42,28 @@
42
42
  "postbuild": "yarn docs && yarn coverage",
43
43
  "docs": "node ./scripts/docs.js ./dist/docs",
44
44
  "coverage": "nyc --report-dir coverage --reporter lcov --reporter text-summary yarn test:unit",
45
- "test:setup": "node test/integration_test_setup/IntegrationTestSetup.js"
45
+ "test:setup": "node test/integration_test_setup/IntegrationTestSetup.js",
46
+ "sample-app:install": "yarn --cwd sample-app install",
47
+ "sample-app:build": "yarn --cwd sample-app build",
48
+ "sample-app:start": "yarn --cwd sample-app start",
49
+ "sample-app:dev": "yarn --cwd sample-app dev",
50
+ "sample-app:lint": "yarn --cwd sample-app lint",
51
+ "sample-app:format": "yarn --cwd sample-app format"
46
52
  },
47
53
  "repository": {
48
54
  "type": "git",
49
55
  "url": "https://github.com/twilio/twilio-taskrouter.js.git"
50
56
  },
51
57
  "dependencies": {
58
+ "axios": "^0.21.2",
59
+ "events": "3.3.0",
52
60
  "jwt-decode": "^3.1.2",
53
- "lodash": "^4.17.5",
61
+ "lodash": "^4.17.21",
54
62
  "loglevel": "^1.4.1",
55
63
  "path-browserify": "^1.0.1",
64
+ "typed-emitter": "^2.1.0",
56
65
  "util": "^0.12.4",
57
- "ws": "^7.4.6",
58
- "xmlhttprequest": "^1.8.0"
66
+ "ws": "^7.4.6"
59
67
  },
60
68
  "devDependencies": {
61
69
  "@babel/core": "^7.16.0",
@@ -68,7 +76,6 @@
68
76
  "@types/express": "^4.17.7",
69
77
  "@types/qs": "^6.9.4",
70
78
  "async-test-tools": "^1.0.7",
71
- "axios": "^0.21.2",
72
79
  "babel-eslint": "^10.1.0",
73
80
  "babel-loader": "^8.2.3",
74
81
  "chai": "^4.1.2",