crossbar-client 1.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.
- package/LICENSE +15 -0
- package/README.md +136 -0
- package/dist/index.cjs +841 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +959 -0
- package/dist/index.d.ts +959 -0
- package/dist/index.js +796 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,841 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AccountsResource: () => AccountsResource,
|
|
24
|
+
CallflowsResource: () => CallflowsResource,
|
|
25
|
+
CdrsResource: () => CdrsResource,
|
|
26
|
+
ChannelsResource: () => ChannelsResource,
|
|
27
|
+
ConferencesResource: () => ConferencesResource,
|
|
28
|
+
CrossbarAuthError: () => CrossbarAuthError,
|
|
29
|
+
CrossbarClient: () => CrossbarClient,
|
|
30
|
+
CrossbarError: () => CrossbarError,
|
|
31
|
+
DevicesResource: () => DevicesResource,
|
|
32
|
+
FaxesResource: () => FaxesResource,
|
|
33
|
+
MediaResource: () => MediaResource,
|
|
34
|
+
MenusResource: () => MenusResource,
|
|
35
|
+
PhoneNumbersResource: () => PhoneNumbersResource,
|
|
36
|
+
TemporalRulesResource: () => TemporalRulesResource,
|
|
37
|
+
TokenResource: () => TokenResource,
|
|
38
|
+
UsersResource: () => UsersResource,
|
|
39
|
+
VoicemailsResource: () => VoicemailsResource,
|
|
40
|
+
WebhooksResource: () => WebhooksResource,
|
|
41
|
+
mergePaginate: () => mergePaginate
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(index_exports);
|
|
44
|
+
|
|
45
|
+
// src/errors.ts
|
|
46
|
+
var CrossbarError = class extends Error {
|
|
47
|
+
constructor(message, status, requestId, body) {
|
|
48
|
+
super(message);
|
|
49
|
+
this.message = message;
|
|
50
|
+
this.status = status;
|
|
51
|
+
this.requestId = requestId;
|
|
52
|
+
this.body = body;
|
|
53
|
+
this.name = "CrossbarError";
|
|
54
|
+
this.status = status;
|
|
55
|
+
this.requestId = requestId;
|
|
56
|
+
this.body = body;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var CrossbarAuthError = class extends CrossbarError {
|
|
60
|
+
constructor(message, requestId, body) {
|
|
61
|
+
super(message, 401, requestId, body);
|
|
62
|
+
this.name = "CrossbarAuthError";
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/resources/accounts.ts
|
|
67
|
+
var AccountsResource = class {
|
|
68
|
+
constructor(client) {
|
|
69
|
+
this.client = client;
|
|
70
|
+
}
|
|
71
|
+
async get(accountId, options) {
|
|
72
|
+
return this.client.get(`/accounts/${accountId}`, options);
|
|
73
|
+
}
|
|
74
|
+
async create(parentAccountId, data, options) {
|
|
75
|
+
return this.client.put(`/accounts/${parentAccountId}`, data, options);
|
|
76
|
+
}
|
|
77
|
+
async update(accountId, data, options) {
|
|
78
|
+
return this.client.post(`/accounts/${accountId}`, data, options);
|
|
79
|
+
}
|
|
80
|
+
async patch(accountId, data, options) {
|
|
81
|
+
return this.client.patch(`/accounts/${accountId}`, data, options);
|
|
82
|
+
}
|
|
83
|
+
async remove(accountId, options) {
|
|
84
|
+
return this.client.delete(`/accounts/${accountId}`, options);
|
|
85
|
+
}
|
|
86
|
+
async children(accountId, options) {
|
|
87
|
+
return this.client.get(`/accounts/${accountId}/children`, options);
|
|
88
|
+
}
|
|
89
|
+
async descendants(accountId, options) {
|
|
90
|
+
return this.client.get(`/accounts/${accountId}/descendants`, options);
|
|
91
|
+
}
|
|
92
|
+
async siblings(accountId, options) {
|
|
93
|
+
return this.client.get(`/accounts/${accountId}/siblings`, options);
|
|
94
|
+
}
|
|
95
|
+
async parents(accountId, options) {
|
|
96
|
+
return this.client.get(`/accounts/${accountId}/parents`, options);
|
|
97
|
+
}
|
|
98
|
+
async tree(accountId, options) {
|
|
99
|
+
return this.client.get(`/accounts/${accountId}/tree`, options);
|
|
100
|
+
}
|
|
101
|
+
async getApiKey(accountId, options) {
|
|
102
|
+
return this.client.get(`/accounts/${accountId}/api_key`, options);
|
|
103
|
+
}
|
|
104
|
+
async regenerateApiKey(accountId, options) {
|
|
105
|
+
return this.client.put(
|
|
106
|
+
`/accounts/${accountId}/api_key`,
|
|
107
|
+
void 0,
|
|
108
|
+
options
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
async move(accountId, toAccountId, options) {
|
|
112
|
+
return this.client.post(`/accounts/${accountId}/move`, { to: toAccountId }, options);
|
|
113
|
+
}
|
|
114
|
+
async promoteReseller(accountId, options) {
|
|
115
|
+
return this.client.put(`/accounts/${accountId}/reseller`, void 0, options);
|
|
116
|
+
}
|
|
117
|
+
async demoteReseller(accountId, options) {
|
|
118
|
+
return this.client.delete(`/accounts/${accountId}/reseller`, options);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// src/types.ts
|
|
123
|
+
function mergePaginate(options) {
|
|
124
|
+
if (!options) return void 0;
|
|
125
|
+
const { paginate, ...rest } = options;
|
|
126
|
+
if (paginate === false) {
|
|
127
|
+
return { ...rest, query: { ...rest.query, paginate: "false" } };
|
|
128
|
+
}
|
|
129
|
+
return rest;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/resources/callflows.ts
|
|
133
|
+
var CallflowsResource = class {
|
|
134
|
+
constructor(client) {
|
|
135
|
+
this.client = client;
|
|
136
|
+
}
|
|
137
|
+
async list(accountId, options) {
|
|
138
|
+
return this.client.get(`/accounts/${accountId}/callflows`, mergePaginate(options));
|
|
139
|
+
}
|
|
140
|
+
async get(accountId, callflowId, options) {
|
|
141
|
+
return this.client.get(`/accounts/${accountId}/callflows/${callflowId}`, options);
|
|
142
|
+
}
|
|
143
|
+
async create(accountId, data, options) {
|
|
144
|
+
return this.client.put(`/accounts/${accountId}/callflows`, data, options);
|
|
145
|
+
}
|
|
146
|
+
async update(accountId, callflowId, data, options) {
|
|
147
|
+
return this.client.post(`/accounts/${accountId}/callflows/${callflowId}`, data, options);
|
|
148
|
+
}
|
|
149
|
+
async patch(accountId, callflowId, data, options) {
|
|
150
|
+
return this.client.patch(`/accounts/${accountId}/callflows/${callflowId}`, data, options);
|
|
151
|
+
}
|
|
152
|
+
async remove(accountId, callflowId, options) {
|
|
153
|
+
return this.client.delete(`/accounts/${accountId}/callflows/${callflowId}`, options);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// src/resources/cdrs.ts
|
|
158
|
+
function mergeCdrOptions(options) {
|
|
159
|
+
if (!options) return void 0;
|
|
160
|
+
const { created_from, created_to, ...rest } = options;
|
|
161
|
+
const merged = mergePaginate(rest);
|
|
162
|
+
if (created_from === void 0 && created_to === void 0) return merged;
|
|
163
|
+
return {
|
|
164
|
+
...merged,
|
|
165
|
+
query: {
|
|
166
|
+
...merged?.query,
|
|
167
|
+
...created_from !== void 0 && { created_from },
|
|
168
|
+
...created_to !== void 0 && { created_to }
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
var CdrsResource = class {
|
|
173
|
+
constructor(client) {
|
|
174
|
+
this.client = client;
|
|
175
|
+
}
|
|
176
|
+
async list(accountId, options) {
|
|
177
|
+
return this.client.get(`/accounts/${accountId}/cdrs`, mergeCdrOptions(options));
|
|
178
|
+
}
|
|
179
|
+
async get(accountId, cdrId, options) {
|
|
180
|
+
return this.client.get(`/accounts/${accountId}/cdrs/${cdrId}`, options);
|
|
181
|
+
}
|
|
182
|
+
async listByUser(accountId, userId, options) {
|
|
183
|
+
return this.client.get(
|
|
184
|
+
`/accounts/${accountId}/users/${userId}/cdrs`,
|
|
185
|
+
mergeCdrOptions(options)
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// src/resources/channels.ts
|
|
191
|
+
var ChannelsResource = class {
|
|
192
|
+
constructor(client) {
|
|
193
|
+
this.client = client;
|
|
194
|
+
}
|
|
195
|
+
async list(accountId, options) {
|
|
196
|
+
return this.client.get(`/accounts/${accountId}/channels`, options);
|
|
197
|
+
}
|
|
198
|
+
async get(accountId, callId, options) {
|
|
199
|
+
return this.client.get(`/accounts/${accountId}/channels/${callId}`, options);
|
|
200
|
+
}
|
|
201
|
+
async hangup(accountId, callId, options) {
|
|
202
|
+
return this.client.delete(`/accounts/${accountId}/channels/${callId}`, options);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// src/resources/conferences.ts
|
|
207
|
+
var ConferencesResource = class {
|
|
208
|
+
constructor(client) {
|
|
209
|
+
this.client = client;
|
|
210
|
+
}
|
|
211
|
+
async list(accountId, options) {
|
|
212
|
+
return this.client.get(`/accounts/${accountId}/conferences`, mergePaginate(options));
|
|
213
|
+
}
|
|
214
|
+
async get(accountId, conferenceId, options) {
|
|
215
|
+
return this.client.get(`/accounts/${accountId}/conferences/${conferenceId}`, options);
|
|
216
|
+
}
|
|
217
|
+
async create(accountId, data, options) {
|
|
218
|
+
return this.client.put(`/accounts/${accountId}/conferences`, data, options);
|
|
219
|
+
}
|
|
220
|
+
async update(accountId, conferenceId, data, options) {
|
|
221
|
+
return this.client.post(`/accounts/${accountId}/conferences/${conferenceId}`, data, options);
|
|
222
|
+
}
|
|
223
|
+
async patch(accountId, conferenceId, data, options) {
|
|
224
|
+
return this.client.patch(
|
|
225
|
+
`/accounts/${accountId}/conferences/${conferenceId}`,
|
|
226
|
+
data,
|
|
227
|
+
options
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
async remove(accountId, conferenceId, options) {
|
|
231
|
+
return this.client.delete(`/accounts/${accountId}/conferences/${conferenceId}`, options);
|
|
232
|
+
}
|
|
233
|
+
async participants(accountId, conferenceId, options) {
|
|
234
|
+
return this.client.get(
|
|
235
|
+
`/accounts/${accountId}/conferences/${conferenceId}/participants`,
|
|
236
|
+
options
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
async muteParticipant(accountId, conferenceId, participantId, options) {
|
|
240
|
+
return this.client.post(
|
|
241
|
+
`/accounts/${accountId}/conferences/${conferenceId}/participants/${participantId}/mute`,
|
|
242
|
+
void 0,
|
|
243
|
+
options
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
async unmuteParticipant(accountId, conferenceId, participantId, options) {
|
|
247
|
+
return this.client.post(
|
|
248
|
+
`/accounts/${accountId}/conferences/${conferenceId}/participants/${participantId}/unmute`,
|
|
249
|
+
void 0,
|
|
250
|
+
options
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
async deafParticipant(accountId, conferenceId, participantId, options) {
|
|
254
|
+
return this.client.post(
|
|
255
|
+
`/accounts/${accountId}/conferences/${conferenceId}/participants/${participantId}/deaf`,
|
|
256
|
+
void 0,
|
|
257
|
+
options
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
async undeafParticipant(accountId, conferenceId, participantId, options) {
|
|
261
|
+
return this.client.post(
|
|
262
|
+
`/accounts/${accountId}/conferences/${conferenceId}/participants/${participantId}/undeaf`,
|
|
263
|
+
void 0,
|
|
264
|
+
options
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
async kickParticipant(accountId, conferenceId, participantId, options) {
|
|
268
|
+
return this.client.delete(
|
|
269
|
+
`/accounts/${accountId}/conferences/${conferenceId}/participants/${participantId}`,
|
|
270
|
+
options
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
// src/resources/devices.ts
|
|
276
|
+
var DevicesResource = class {
|
|
277
|
+
constructor(client) {
|
|
278
|
+
this.client = client;
|
|
279
|
+
}
|
|
280
|
+
async list(accountId, options) {
|
|
281
|
+
return this.client.get(`/accounts/${accountId}/devices`, mergePaginate(options));
|
|
282
|
+
}
|
|
283
|
+
async get(accountId, deviceId, options) {
|
|
284
|
+
return this.client.get(`/accounts/${accountId}/devices/${deviceId}`, options);
|
|
285
|
+
}
|
|
286
|
+
async create(accountId, data, options) {
|
|
287
|
+
return this.client.put(`/accounts/${accountId}/devices`, data, options);
|
|
288
|
+
}
|
|
289
|
+
async update(accountId, deviceId, data, options) {
|
|
290
|
+
return this.client.post(`/accounts/${accountId}/devices/${deviceId}`, data, options);
|
|
291
|
+
}
|
|
292
|
+
async patch(accountId, deviceId, data, options) {
|
|
293
|
+
return this.client.patch(`/accounts/${accountId}/devices/${deviceId}`, data, options);
|
|
294
|
+
}
|
|
295
|
+
async remove(accountId, deviceId, options) {
|
|
296
|
+
return this.client.delete(`/accounts/${accountId}/devices/${deviceId}`, options);
|
|
297
|
+
}
|
|
298
|
+
async status(accountId, options) {
|
|
299
|
+
return this.client.get(`/accounts/${accountId}/devices/status`, options);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
// src/resources/faxes.ts
|
|
304
|
+
var FaxesResource = class {
|
|
305
|
+
constructor(client) {
|
|
306
|
+
this.client = client;
|
|
307
|
+
}
|
|
308
|
+
async listInbox(accountId, options) {
|
|
309
|
+
return this.client.get(`/accounts/${accountId}/faxes/inbox`, mergePaginate(options));
|
|
310
|
+
}
|
|
311
|
+
async listOutbox(accountId, options) {
|
|
312
|
+
return this.client.get(`/accounts/${accountId}/faxes/outbox`, mergePaginate(options));
|
|
313
|
+
}
|
|
314
|
+
async getInbox(accountId, faxId, options) {
|
|
315
|
+
return this.client.get(`/accounts/${accountId}/faxes/inbox/${faxId}`, options);
|
|
316
|
+
}
|
|
317
|
+
async getOutbox(accountId, faxId, options) {
|
|
318
|
+
return this.client.get(`/accounts/${accountId}/faxes/outbox/${faxId}`, options);
|
|
319
|
+
}
|
|
320
|
+
async send(accountId, data, options) {
|
|
321
|
+
return this.client.put(`/accounts/${accountId}/faxes`, data, options);
|
|
322
|
+
}
|
|
323
|
+
async removeInbox(accountId, faxId, options) {
|
|
324
|
+
return this.client.delete(`/accounts/${accountId}/faxes/inbox/${faxId}`, options);
|
|
325
|
+
}
|
|
326
|
+
async removeOutbox(accountId, faxId, options) {
|
|
327
|
+
return this.client.delete(`/accounts/${accountId}/faxes/outbox/${faxId}`, options);
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
// src/resources/media.ts
|
|
332
|
+
var MediaResource = class {
|
|
333
|
+
constructor(client) {
|
|
334
|
+
this.client = client;
|
|
335
|
+
}
|
|
336
|
+
async list(accountId, options) {
|
|
337
|
+
return this.client.get(`/accounts/${accountId}/media`, mergePaginate(options));
|
|
338
|
+
}
|
|
339
|
+
async get(accountId, mediaId, options) {
|
|
340
|
+
return this.client.get(`/accounts/${accountId}/media/${mediaId}`, options);
|
|
341
|
+
}
|
|
342
|
+
async create(accountId, data, options) {
|
|
343
|
+
return this.client.put(`/accounts/${accountId}/media`, data, options);
|
|
344
|
+
}
|
|
345
|
+
async update(accountId, mediaId, data, options) {
|
|
346
|
+
return this.client.post(`/accounts/${accountId}/media/${mediaId}`, data, options);
|
|
347
|
+
}
|
|
348
|
+
async patch(accountId, mediaId, data, options) {
|
|
349
|
+
return this.client.patch(`/accounts/${accountId}/media/${mediaId}`, data, options);
|
|
350
|
+
}
|
|
351
|
+
async remove(accountId, mediaId, options) {
|
|
352
|
+
return this.client.delete(`/accounts/${accountId}/media/${mediaId}`, options);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
// src/resources/menus.ts
|
|
357
|
+
var MenusResource = class {
|
|
358
|
+
constructor(client) {
|
|
359
|
+
this.client = client;
|
|
360
|
+
}
|
|
361
|
+
async list(accountId, options) {
|
|
362
|
+
return this.client.get(`/accounts/${accountId}/menus`, mergePaginate(options));
|
|
363
|
+
}
|
|
364
|
+
async get(accountId, menuId, options) {
|
|
365
|
+
return this.client.get(`/accounts/${accountId}/menus/${menuId}`, options);
|
|
366
|
+
}
|
|
367
|
+
async create(accountId, data, options) {
|
|
368
|
+
return this.client.put(`/accounts/${accountId}/menus`, data, options);
|
|
369
|
+
}
|
|
370
|
+
async update(accountId, menuId, data, options) {
|
|
371
|
+
return this.client.post(`/accounts/${accountId}/menus/${menuId}`, data, options);
|
|
372
|
+
}
|
|
373
|
+
async patch(accountId, menuId, data, options) {
|
|
374
|
+
return this.client.patch(`/accounts/${accountId}/menus/${menuId}`, data, options);
|
|
375
|
+
}
|
|
376
|
+
async remove(accountId, menuId, options) {
|
|
377
|
+
return this.client.delete(`/accounts/${accountId}/menus/${menuId}`, options);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
// src/resources/phone-numbers.ts
|
|
382
|
+
var PhoneNumbersResource = class {
|
|
383
|
+
constructor(client) {
|
|
384
|
+
this.client = client;
|
|
385
|
+
}
|
|
386
|
+
async list(accountId, options) {
|
|
387
|
+
return this.client.get(`/accounts/${accountId}/phone_numbers`, mergePaginate(options));
|
|
388
|
+
}
|
|
389
|
+
async get(accountId, number, options) {
|
|
390
|
+
return this.client.get(
|
|
391
|
+
`/accounts/${accountId}/phone_numbers/${encodeURIComponent(number)}`,
|
|
392
|
+
options
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
async create(accountId, number, data, options) {
|
|
396
|
+
return this.client.put(
|
|
397
|
+
`/accounts/${accountId}/phone_numbers/${encodeURIComponent(number)}`,
|
|
398
|
+
data,
|
|
399
|
+
options
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
async update(accountId, number, data, options) {
|
|
403
|
+
return this.client.post(
|
|
404
|
+
`/accounts/${accountId}/phone_numbers/${encodeURIComponent(number)}`,
|
|
405
|
+
data,
|
|
406
|
+
options
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
async patch(accountId, number, data, options) {
|
|
410
|
+
return this.client.patch(
|
|
411
|
+
`/accounts/${accountId}/phone_numbers/${encodeURIComponent(number)}`,
|
|
412
|
+
data,
|
|
413
|
+
options
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
async remove(accountId, number, options) {
|
|
417
|
+
return this.client.delete(
|
|
418
|
+
`/accounts/${accountId}/phone_numbers/${encodeURIComponent(number)}`,
|
|
419
|
+
options
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
async activate(accountId, number, data, options) {
|
|
423
|
+
return this.client.put(
|
|
424
|
+
`/accounts/${accountId}/phone_numbers/${encodeURIComponent(number)}/activate`,
|
|
425
|
+
data,
|
|
426
|
+
options
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
async reserve(accountId, number, data, options) {
|
|
430
|
+
return this.client.put(
|
|
431
|
+
`/accounts/${accountId}/phone_numbers/${encodeURIComponent(number)}/reserve`,
|
|
432
|
+
data,
|
|
433
|
+
options
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
async portIn(accountId, number, data, options) {
|
|
437
|
+
return this.client.put(
|
|
438
|
+
`/accounts/${accountId}/phone_numbers/${encodeURIComponent(number)}/port_in`,
|
|
439
|
+
data,
|
|
440
|
+
options
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
// src/resources/temporal-rules.ts
|
|
446
|
+
var TemporalRulesResource = class {
|
|
447
|
+
constructor(client) {
|
|
448
|
+
this.client = client;
|
|
449
|
+
}
|
|
450
|
+
async list(accountId, options) {
|
|
451
|
+
return this.client.get(`/accounts/${accountId}/temporal_rules`, mergePaginate(options));
|
|
452
|
+
}
|
|
453
|
+
async get(accountId, ruleId, options) {
|
|
454
|
+
return this.client.get(`/accounts/${accountId}/temporal_rules/${ruleId}`, options);
|
|
455
|
+
}
|
|
456
|
+
async create(accountId, data, options) {
|
|
457
|
+
return this.client.put(`/accounts/${accountId}/temporal_rules`, data, options);
|
|
458
|
+
}
|
|
459
|
+
async update(accountId, ruleId, data, options) {
|
|
460
|
+
return this.client.post(`/accounts/${accountId}/temporal_rules/${ruleId}`, data, options);
|
|
461
|
+
}
|
|
462
|
+
async patch(accountId, ruleId, data, options) {
|
|
463
|
+
return this.client.patch(`/accounts/${accountId}/temporal_rules/${ruleId}`, data, options);
|
|
464
|
+
}
|
|
465
|
+
async remove(accountId, ruleId, options) {
|
|
466
|
+
return this.client.delete(`/accounts/${accountId}/temporal_rules/${ruleId}`, options);
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
// src/resources/token.ts
|
|
471
|
+
var TokenResource = class {
|
|
472
|
+
constructor(client) {
|
|
473
|
+
this.client = client;
|
|
474
|
+
}
|
|
475
|
+
async info(options) {
|
|
476
|
+
return this.client.get("/token_auth", options);
|
|
477
|
+
}
|
|
478
|
+
async invalidate(options) {
|
|
479
|
+
return this.client.delete("/token_auth", options);
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
// src/resources/users.ts
|
|
484
|
+
var UsersResource = class {
|
|
485
|
+
constructor(client) {
|
|
486
|
+
this.client = client;
|
|
487
|
+
}
|
|
488
|
+
async list(accountId, options) {
|
|
489
|
+
return this.client.get(`/accounts/${accountId}/users`, mergePaginate(options));
|
|
490
|
+
}
|
|
491
|
+
async get(accountId, userId, options) {
|
|
492
|
+
return this.client.get(`/accounts/${accountId}/users/${userId}`, options);
|
|
493
|
+
}
|
|
494
|
+
async create(accountId, data, options) {
|
|
495
|
+
return this.client.put(`/accounts/${accountId}/users`, data, options);
|
|
496
|
+
}
|
|
497
|
+
async update(accountId, userId, data, options) {
|
|
498
|
+
return this.client.post(`/accounts/${accountId}/users/${userId}`, data, options);
|
|
499
|
+
}
|
|
500
|
+
async patch(accountId, userId, data, options) {
|
|
501
|
+
return this.client.patch(`/accounts/${accountId}/users/${userId}`, data, options);
|
|
502
|
+
}
|
|
503
|
+
async remove(accountId, userId, options) {
|
|
504
|
+
return this.client.delete(`/accounts/${accountId}/users/${userId}`, options);
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
// src/resources/voicemails.ts
|
|
509
|
+
var VoicemailsResource = class {
|
|
510
|
+
constructor(client) {
|
|
511
|
+
this.client = client;
|
|
512
|
+
}
|
|
513
|
+
async list(accountId, options) {
|
|
514
|
+
return this.client.get(`/accounts/${accountId}/vmboxes`, mergePaginate(options));
|
|
515
|
+
}
|
|
516
|
+
async get(accountId, vmboxId, options) {
|
|
517
|
+
return this.client.get(`/accounts/${accountId}/vmboxes/${vmboxId}`, options);
|
|
518
|
+
}
|
|
519
|
+
async create(accountId, data, options) {
|
|
520
|
+
return this.client.put(`/accounts/${accountId}/vmboxes`, data, options);
|
|
521
|
+
}
|
|
522
|
+
async update(accountId, vmboxId, data, options) {
|
|
523
|
+
return this.client.post(`/accounts/${accountId}/vmboxes/${vmboxId}`, data, options);
|
|
524
|
+
}
|
|
525
|
+
async patch(accountId, vmboxId, data, options) {
|
|
526
|
+
return this.client.patch(`/accounts/${accountId}/vmboxes/${vmboxId}`, data, options);
|
|
527
|
+
}
|
|
528
|
+
async remove(accountId, vmboxId, options) {
|
|
529
|
+
return this.client.delete(`/accounts/${accountId}/vmboxes/${vmboxId}`, options);
|
|
530
|
+
}
|
|
531
|
+
async messages(accountId, vmboxId, options) {
|
|
532
|
+
return this.client.get(
|
|
533
|
+
`/accounts/${accountId}/vmboxes/${vmboxId}/messages`,
|
|
534
|
+
options
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
async getMessage(accountId, vmboxId, messageId, options) {
|
|
538
|
+
return this.client.get(
|
|
539
|
+
`/accounts/${accountId}/vmboxes/${vmboxId}/messages/${messageId}`,
|
|
540
|
+
options
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
async updateMessage(accountId, vmboxId, messageId, data, options) {
|
|
544
|
+
return this.client.post(
|
|
545
|
+
`/accounts/${accountId}/vmboxes/${vmboxId}/messages/${messageId}`,
|
|
546
|
+
data,
|
|
547
|
+
options
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
async deleteMessage(accountId, vmboxId, messageId, options) {
|
|
551
|
+
return this.client.delete(
|
|
552
|
+
`/accounts/${accountId}/vmboxes/${vmboxId}/messages/${messageId}`,
|
|
553
|
+
options
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
// src/resources/webhooks.ts
|
|
559
|
+
var WebhooksResource = class {
|
|
560
|
+
constructor(client) {
|
|
561
|
+
this.client = client;
|
|
562
|
+
}
|
|
563
|
+
async list(accountId, options) {
|
|
564
|
+
return this.client.get(`/accounts/${accountId}/webhooks`, mergePaginate(options));
|
|
565
|
+
}
|
|
566
|
+
async get(accountId, webhookId, options) {
|
|
567
|
+
return this.client.get(`/accounts/${accountId}/webhooks/${webhookId}`, options);
|
|
568
|
+
}
|
|
569
|
+
async create(accountId, data, options) {
|
|
570
|
+
return this.client.put(`/accounts/${accountId}/webhooks`, data, options);
|
|
571
|
+
}
|
|
572
|
+
async update(accountId, webhookId, data, options) {
|
|
573
|
+
return this.client.post(`/accounts/${accountId}/webhooks/${webhookId}`, data, options);
|
|
574
|
+
}
|
|
575
|
+
async patch(accountId, webhookId, data, options) {
|
|
576
|
+
return this.client.patch(`/accounts/${accountId}/webhooks/${webhookId}`, data, options);
|
|
577
|
+
}
|
|
578
|
+
async remove(accountId, webhookId, options) {
|
|
579
|
+
return this.client.delete(`/accounts/${accountId}/webhooks/${webhookId}`, options);
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
// src/client.ts
|
|
584
|
+
var DEFAULT_VERSION = "v2";
|
|
585
|
+
var CrossbarClient = class {
|
|
586
|
+
baseUrl;
|
|
587
|
+
version;
|
|
588
|
+
defaultHeaders;
|
|
589
|
+
defaultTimeout;
|
|
590
|
+
retryConfig;
|
|
591
|
+
authConfig;
|
|
592
|
+
authToken;
|
|
593
|
+
_http;
|
|
594
|
+
_accounts;
|
|
595
|
+
_tokenAuth;
|
|
596
|
+
_users;
|
|
597
|
+
_devices;
|
|
598
|
+
_callflows;
|
|
599
|
+
_voicemails;
|
|
600
|
+
_phoneNumbers;
|
|
601
|
+
_cdrs;
|
|
602
|
+
_channels;
|
|
603
|
+
_conferences;
|
|
604
|
+
_faxes;
|
|
605
|
+
_media;
|
|
606
|
+
_menus;
|
|
607
|
+
_temporalRules;
|
|
608
|
+
_webhooks;
|
|
609
|
+
constructor(config) {
|
|
610
|
+
this.baseUrl = config.url.replace(/\/+$/, "");
|
|
611
|
+
this.version = config.version ?? DEFAULT_VERSION;
|
|
612
|
+
this.defaultHeaders = { ...config.headers };
|
|
613
|
+
this.defaultTimeout = config.timeout;
|
|
614
|
+
this.retryConfig = config.retry ?? {};
|
|
615
|
+
this.authConfig = config.auth;
|
|
616
|
+
if (config.auth?.type === "token") {
|
|
617
|
+
this.authToken = config.auth.token;
|
|
618
|
+
}
|
|
619
|
+
this._http = {
|
|
620
|
+
get: (path, options) => this.request("GET", path, void 0, options),
|
|
621
|
+
put: (path, data, options) => this.request("PUT", path, data, options),
|
|
622
|
+
post: (path, data, options) => this.request("POST", path, data, options),
|
|
623
|
+
patch: (path, data, options) => this.request("PATCH", path, data, options),
|
|
624
|
+
delete: (path, options) => this.request("DELETE", path, void 0, options)
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
get http() {
|
|
628
|
+
return this._http;
|
|
629
|
+
}
|
|
630
|
+
get accounts() {
|
|
631
|
+
this._accounts ??= new AccountsResource(this._http);
|
|
632
|
+
return this._accounts;
|
|
633
|
+
}
|
|
634
|
+
get tokenAuth() {
|
|
635
|
+
this._tokenAuth ??= new TokenResource(this._http);
|
|
636
|
+
return this._tokenAuth;
|
|
637
|
+
}
|
|
638
|
+
get users() {
|
|
639
|
+
this._users ??= new UsersResource(this._http);
|
|
640
|
+
return this._users;
|
|
641
|
+
}
|
|
642
|
+
get devices() {
|
|
643
|
+
this._devices ??= new DevicesResource(this._http);
|
|
644
|
+
return this._devices;
|
|
645
|
+
}
|
|
646
|
+
get callflows() {
|
|
647
|
+
this._callflows ??= new CallflowsResource(this._http);
|
|
648
|
+
return this._callflows;
|
|
649
|
+
}
|
|
650
|
+
get voicemails() {
|
|
651
|
+
this._voicemails ??= new VoicemailsResource(this._http);
|
|
652
|
+
return this._voicemails;
|
|
653
|
+
}
|
|
654
|
+
get phoneNumbers() {
|
|
655
|
+
this._phoneNumbers ??= new PhoneNumbersResource(this._http);
|
|
656
|
+
return this._phoneNumbers;
|
|
657
|
+
}
|
|
658
|
+
get cdrs() {
|
|
659
|
+
this._cdrs ??= new CdrsResource(this._http);
|
|
660
|
+
return this._cdrs;
|
|
661
|
+
}
|
|
662
|
+
get channels() {
|
|
663
|
+
this._channels ??= new ChannelsResource(this._http);
|
|
664
|
+
return this._channels;
|
|
665
|
+
}
|
|
666
|
+
get conferences() {
|
|
667
|
+
this._conferences ??= new ConferencesResource(this._http);
|
|
668
|
+
return this._conferences;
|
|
669
|
+
}
|
|
670
|
+
get faxes() {
|
|
671
|
+
this._faxes ??= new FaxesResource(this._http);
|
|
672
|
+
return this._faxes;
|
|
673
|
+
}
|
|
674
|
+
get media() {
|
|
675
|
+
this._media ??= new MediaResource(this._http);
|
|
676
|
+
return this._media;
|
|
677
|
+
}
|
|
678
|
+
get menus() {
|
|
679
|
+
this._menus ??= new MenusResource(this._http);
|
|
680
|
+
return this._menus;
|
|
681
|
+
}
|
|
682
|
+
get temporalRules() {
|
|
683
|
+
this._temporalRules ??= new TemporalRulesResource(this._http);
|
|
684
|
+
return this._temporalRules;
|
|
685
|
+
}
|
|
686
|
+
get webhooks() {
|
|
687
|
+
this._webhooks ??= new WebhooksResource(this._http);
|
|
688
|
+
return this._webhooks;
|
|
689
|
+
}
|
|
690
|
+
get token() {
|
|
691
|
+
return this.authToken;
|
|
692
|
+
}
|
|
693
|
+
set token(value) {
|
|
694
|
+
this.authToken = value;
|
|
695
|
+
}
|
|
696
|
+
async authenticate() {
|
|
697
|
+
if (!this.authConfig) {
|
|
698
|
+
throw new CrossbarError("No auth configuration provided", 0);
|
|
699
|
+
}
|
|
700
|
+
if (this.authConfig.type === "token") {
|
|
701
|
+
this.authToken = this.authConfig.token;
|
|
702
|
+
return {
|
|
703
|
+
data: {},
|
|
704
|
+
status: "success",
|
|
705
|
+
request_id: "",
|
|
706
|
+
auth_token: this.authToken
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
if (this.authConfig.type === "credentials") {
|
|
710
|
+
const body = {
|
|
711
|
+
credentials: this.authConfig.credentials
|
|
712
|
+
};
|
|
713
|
+
if (this.authConfig.accountName) {
|
|
714
|
+
body.account_name = this.authConfig.accountName;
|
|
715
|
+
}
|
|
716
|
+
if (this.authConfig.accountId) {
|
|
717
|
+
body.account_id = this.authConfig.accountId;
|
|
718
|
+
}
|
|
719
|
+
return this.executeRequest("PUT", "/user_auth", body);
|
|
720
|
+
}
|
|
721
|
+
return this.executeRequest("PUT", "/api_auth", {
|
|
722
|
+
api_key: this.authConfig.apiKey
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
async request(method, path, data, options) {
|
|
726
|
+
const { maxRetries = 1, reAuthOn401 = true, retryDelay = 0 } = this.retryConfig;
|
|
727
|
+
let serverErrorAttempts = 0;
|
|
728
|
+
let reAuthed = false;
|
|
729
|
+
for (; ; ) {
|
|
730
|
+
try {
|
|
731
|
+
return await this.executeRequest(method, path, data, options);
|
|
732
|
+
} catch (err) {
|
|
733
|
+
if (err instanceof CrossbarAuthError && reAuthOn401 && !reAuthed && this.canReAuth()) {
|
|
734
|
+
reAuthed = true;
|
|
735
|
+
await this.authenticate();
|
|
736
|
+
continue;
|
|
737
|
+
}
|
|
738
|
+
if (err instanceof CrossbarError && err.status >= 500 && serverErrorAttempts < maxRetries) {
|
|
739
|
+
serverErrorAttempts++;
|
|
740
|
+
if (retryDelay > 0) {
|
|
741
|
+
await new Promise((res) => setTimeout(res, retryDelay));
|
|
742
|
+
}
|
|
743
|
+
continue;
|
|
744
|
+
}
|
|
745
|
+
throw err;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
canReAuth() {
|
|
750
|
+
return this.authConfig?.type === "credentials" || this.authConfig?.type === "api_key";
|
|
751
|
+
}
|
|
752
|
+
async executeRequest(method, path, data, options) {
|
|
753
|
+
const url = this.buildUrl(path, options?.query);
|
|
754
|
+
const headers = this.buildHeaders(options);
|
|
755
|
+
const fetchOptions = { method, headers };
|
|
756
|
+
if (data !== void 0) {
|
|
757
|
+
fetchOptions.body = JSON.stringify({ data });
|
|
758
|
+
}
|
|
759
|
+
const timeout = options?.timeout ?? this.defaultTimeout;
|
|
760
|
+
if (timeout || options?.signal) {
|
|
761
|
+
const signals = [];
|
|
762
|
+
if (timeout) signals.push(AbortSignal.timeout(timeout));
|
|
763
|
+
if (options?.signal) signals.push(options.signal);
|
|
764
|
+
fetchOptions.signal = signals.length === 1 ? signals[0] : AbortSignal.any(signals);
|
|
765
|
+
}
|
|
766
|
+
const response = await fetch(url, fetchOptions);
|
|
767
|
+
const body = await response.json();
|
|
768
|
+
if (body.auth_token) {
|
|
769
|
+
this.authToken = body.auth_token;
|
|
770
|
+
}
|
|
771
|
+
if (!response.ok) {
|
|
772
|
+
const message = body.message ?? body.error ?? `HTTP ${response.status}`;
|
|
773
|
+
if (response.status === 401) {
|
|
774
|
+
throw new CrossbarAuthError(message, body.request_id, body);
|
|
775
|
+
}
|
|
776
|
+
throw new CrossbarError(
|
|
777
|
+
message,
|
|
778
|
+
response.status,
|
|
779
|
+
body.request_id,
|
|
780
|
+
body
|
|
781
|
+
);
|
|
782
|
+
}
|
|
783
|
+
return {
|
|
784
|
+
data: body.data,
|
|
785
|
+
status: body.status,
|
|
786
|
+
request_id: body.request_id ?? "",
|
|
787
|
+
auth_token: body.auth_token,
|
|
788
|
+
page_size: body.page_size,
|
|
789
|
+
next_start_key: body.next_start_key,
|
|
790
|
+
start_key: body.start_key
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
buildUrl(path, query) {
|
|
794
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
795
|
+
let url = `${this.baseUrl}/${this.version}${normalizedPath}`;
|
|
796
|
+
if (query) {
|
|
797
|
+
const params = new URLSearchParams();
|
|
798
|
+
for (const [key, value] of Object.entries(query)) {
|
|
799
|
+
if (value !== void 0) params.set(key, String(value));
|
|
800
|
+
}
|
|
801
|
+
const qs = params.toString();
|
|
802
|
+
if (qs) url += `?${qs}`;
|
|
803
|
+
}
|
|
804
|
+
return url;
|
|
805
|
+
}
|
|
806
|
+
buildHeaders(options) {
|
|
807
|
+
const headers = {
|
|
808
|
+
"Content-Type": "application/json",
|
|
809
|
+
Accept: "application/json",
|
|
810
|
+
...this.defaultHeaders,
|
|
811
|
+
...options?.headers
|
|
812
|
+
};
|
|
813
|
+
if (this.authToken) {
|
|
814
|
+
headers["X-Auth-Token"] = this.authToken;
|
|
815
|
+
}
|
|
816
|
+
return headers;
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
820
|
+
0 && (module.exports = {
|
|
821
|
+
AccountsResource,
|
|
822
|
+
CallflowsResource,
|
|
823
|
+
CdrsResource,
|
|
824
|
+
ChannelsResource,
|
|
825
|
+
ConferencesResource,
|
|
826
|
+
CrossbarAuthError,
|
|
827
|
+
CrossbarClient,
|
|
828
|
+
CrossbarError,
|
|
829
|
+
DevicesResource,
|
|
830
|
+
FaxesResource,
|
|
831
|
+
MediaResource,
|
|
832
|
+
MenusResource,
|
|
833
|
+
PhoneNumbersResource,
|
|
834
|
+
TemporalRulesResource,
|
|
835
|
+
TokenResource,
|
|
836
|
+
UsersResource,
|
|
837
|
+
VoicemailsResource,
|
|
838
|
+
WebhooksResource,
|
|
839
|
+
mergePaginate
|
|
840
|
+
});
|
|
841
|
+
//# sourceMappingURL=index.cjs.map
|