@teamlearners/clawops 0.1.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 +21 -0
- package/README.md +313 -0
- package/dist/agent/index.cjs +2668 -0
- package/dist/agent/index.cjs.map +1 -0
- package/dist/agent/index.d.cts +821 -0
- package/dist/agent/index.d.ts +821 -0
- package/dist/agent/index.js +2613 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/chunk-JNSHMKDI.cjs +175 -0
- package/dist/chunk-JNSHMKDI.cjs.map +1 -0
- package/dist/chunk-UKAT24I6.js +152 -0
- package/dist/chunk-UKAT24I6.js.map +1 -0
- package/dist/index.cjs +601 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +549 -0
- package/dist/index.d.ts +549 -0
- package/dist/index.js +523 -0
- package/dist/index.js.map +1 -0
- package/package.json +71 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var chunkJNSHMKDI_cjs = require('./chunk-JNSHMKDI.cjs');
|
|
6
|
+
var zod = require('zod');
|
|
7
|
+
var crypto = require('crypto');
|
|
8
|
+
|
|
9
|
+
// src/version.ts
|
|
10
|
+
var VERSION = "0.1.0";
|
|
11
|
+
|
|
12
|
+
// src/base-client.ts
|
|
13
|
+
var LOCALHOST_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "0.0.0.0", "[::1]"]);
|
|
14
|
+
function validateBaseUrl(url) {
|
|
15
|
+
let parsed;
|
|
16
|
+
try {
|
|
17
|
+
parsed = new URL(url);
|
|
18
|
+
} catch {
|
|
19
|
+
throw new chunkJNSHMKDI_cjs.ClawOpsError(`Invalid base_url: ${url}`);
|
|
20
|
+
}
|
|
21
|
+
if (parsed.protocol === "https:") return url;
|
|
22
|
+
if (parsed.protocol === "http:" && LOCALHOST_HOSTS.has(parsed.hostname)) return url;
|
|
23
|
+
throw new chunkJNSHMKDI_cjs.ClawOpsError(
|
|
24
|
+
`base_url\uC740 HTTPS\uB97C \uC0AC\uC6A9\uD574\uC57C \uD569\uB2C8\uB2E4 (\uBC1B\uC740 \uAC12: '${url}'). \uB85C\uCEEC \uAC1C\uBC1C \uC2DC\uC5D0\uB294 http://localhost\uB97C \uC0AC\uC6A9\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4.`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
var APIClient = class {
|
|
28
|
+
_apiKey;
|
|
29
|
+
_baseURL;
|
|
30
|
+
_maxRetries;
|
|
31
|
+
_timeout;
|
|
32
|
+
_fetch;
|
|
33
|
+
_defaultHeaders;
|
|
34
|
+
constructor(options) {
|
|
35
|
+
this._apiKey = options.apiKey;
|
|
36
|
+
this._baseURL = validateBaseUrl((options.baseURL ?? chunkJNSHMKDI_cjs.DEFAULT_BASE_URL).replace(/\/+$/, ""));
|
|
37
|
+
this._maxRetries = options.maxRetries ?? chunkJNSHMKDI_cjs.DEFAULT_MAX_RETRIES;
|
|
38
|
+
this._timeout = options.timeout ?? chunkJNSHMKDI_cjs.DEFAULT_TIMEOUT;
|
|
39
|
+
this._fetch = options.fetch ?? globalThis.fetch;
|
|
40
|
+
this._defaultHeaders = options.defaultHeaders ?? {};
|
|
41
|
+
}
|
|
42
|
+
_buildHeaders(extra) {
|
|
43
|
+
const headers = {
|
|
44
|
+
Authorization: `Bearer ${this._apiKey}`,
|
|
45
|
+
"Content-Type": "application/json",
|
|
46
|
+
Accept: "application/json",
|
|
47
|
+
"User-Agent": `claw-ops-node/${VERSION}`,
|
|
48
|
+
...this._defaultHeaders
|
|
49
|
+
};
|
|
50
|
+
if (extra) Object.assign(headers, extra);
|
|
51
|
+
return headers;
|
|
52
|
+
}
|
|
53
|
+
async _request(method2, path, options = {}) {
|
|
54
|
+
const headers = this._buildHeaders(options.extraHeaders);
|
|
55
|
+
const params = new URLSearchParams();
|
|
56
|
+
const queryObj = { ...options.query, ...options.extraQuery };
|
|
57
|
+
for (const [k, v] of Object.entries(queryObj)) {
|
|
58
|
+
if (v != null) params.set(k, String(v));
|
|
59
|
+
}
|
|
60
|
+
const queryString = params.toString();
|
|
61
|
+
const url = `${this._baseURL}${path}${queryString ? `?${queryString}` : ""}`;
|
|
62
|
+
const reqTimeout = options.timeout ?? this._timeout;
|
|
63
|
+
let retriesLeft = this._maxRetries;
|
|
64
|
+
while (true) {
|
|
65
|
+
const controller = new AbortController();
|
|
66
|
+
const timeoutId = setTimeout(() => controller.abort(), reqTimeout);
|
|
67
|
+
let response;
|
|
68
|
+
try {
|
|
69
|
+
response = await this._fetch(url, {
|
|
70
|
+
method: method2,
|
|
71
|
+
headers,
|
|
72
|
+
body: options.body ? JSON.stringify(options.body) : void 0,
|
|
73
|
+
signal: controller.signal
|
|
74
|
+
});
|
|
75
|
+
} catch (err) {
|
|
76
|
+
clearTimeout(timeoutId);
|
|
77
|
+
if (err instanceof DOMException && err.name === "AbortError") {
|
|
78
|
+
if (retriesLeft > 0) {
|
|
79
|
+
retriesLeft--;
|
|
80
|
+
await this._sleep(this._retryDelay(this._maxRetries - retriesLeft));
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
throw new chunkJNSHMKDI_cjs.APITimeoutError({ method: method2, url });
|
|
84
|
+
}
|
|
85
|
+
if (retriesLeft > 0) {
|
|
86
|
+
retriesLeft--;
|
|
87
|
+
await this._sleep(this._retryDelay(this._maxRetries - retriesLeft));
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
throw new chunkJNSHMKDI_cjs.APIConnectionError({ method: method2, url });
|
|
91
|
+
} finally {
|
|
92
|
+
clearTimeout(timeoutId);
|
|
93
|
+
}
|
|
94
|
+
if (response.ok) {
|
|
95
|
+
if (response.status === 204 || !options.castTo) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
let json;
|
|
99
|
+
try {
|
|
100
|
+
json = await response.json();
|
|
101
|
+
} catch {
|
|
102
|
+
throw new chunkJNSHMKDI_cjs.APIResponseValidationError({ status: response.status }, { method: method2, url });
|
|
103
|
+
}
|
|
104
|
+
const parsed = options.castTo.safeParse(json);
|
|
105
|
+
if (!parsed.success) {
|
|
106
|
+
throw new chunkJNSHMKDI_cjs.APIResponseValidationError({ status: response.status }, { method: method2, url });
|
|
107
|
+
}
|
|
108
|
+
return parsed.data;
|
|
109
|
+
}
|
|
110
|
+
if (retriesLeft > 0 && this._shouldRetry(response.status)) {
|
|
111
|
+
retriesLeft--;
|
|
112
|
+
await this._sleep(this._retryDelay(this._maxRetries - retriesLeft));
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
let body;
|
|
116
|
+
try {
|
|
117
|
+
body = await response.json();
|
|
118
|
+
} catch {
|
|
119
|
+
body = null;
|
|
120
|
+
}
|
|
121
|
+
throw chunkJNSHMKDI_cjs.makeStatusError(response.status, body, response.headers, { method: method2, url });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
_shouldRetry(status) {
|
|
125
|
+
return status === 408 || status === 409 || status === 429 || status >= 500;
|
|
126
|
+
}
|
|
127
|
+
_retryDelay(retriesTaken) {
|
|
128
|
+
const delay = Math.min(chunkJNSHMKDI_cjs.INITIAL_RETRY_DELAY * 2 ** retriesTaken, chunkJNSHMKDI_cjs.MAX_RETRY_DELAY);
|
|
129
|
+
return delay * (1 + Math.random());
|
|
130
|
+
}
|
|
131
|
+
_sleep(ms) {
|
|
132
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
133
|
+
}
|
|
134
|
+
async _get(path, options) {
|
|
135
|
+
const result = await this._request(method("GET"), path, options);
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
async _post(path, options) {
|
|
139
|
+
const result = await this._request("POST", path, options);
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
async _put(path, options) {
|
|
143
|
+
const result = await this._request("PUT", path, options);
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
async _delete(path, options = {}) {
|
|
147
|
+
await this._request("DELETE", path, options);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
function method(m) {
|
|
151
|
+
return m;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/resource.ts
|
|
155
|
+
var APIResource = class {
|
|
156
|
+
_client;
|
|
157
|
+
_accountId;
|
|
158
|
+
constructor(client, accountId) {
|
|
159
|
+
this._client = client;
|
|
160
|
+
this._accountId = accountId;
|
|
161
|
+
}
|
|
162
|
+
get _basePath() {
|
|
163
|
+
return `/v1/accounts/${this._accountId}`;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// src/util.ts
|
|
168
|
+
function stripNotGiven(data) {
|
|
169
|
+
const result = {};
|
|
170
|
+
for (const [k, v] of Object.entries(data)) {
|
|
171
|
+
if (v != null) {
|
|
172
|
+
result[k] = v;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
var PaginationMetaSchema = zod.z.object({
|
|
178
|
+
total: zod.z.number(),
|
|
179
|
+
page: zod.z.number(),
|
|
180
|
+
pageSize: zod.z.number()
|
|
181
|
+
}).passthrough();
|
|
182
|
+
|
|
183
|
+
// src/pagination.ts
|
|
184
|
+
function PageSchema(itemSchema) {
|
|
185
|
+
return zod.z.object({
|
|
186
|
+
data: zod.z.array(itemSchema),
|
|
187
|
+
meta: PaginationMetaSchema
|
|
188
|
+
}).passthrough();
|
|
189
|
+
}
|
|
190
|
+
var Page = class _Page {
|
|
191
|
+
data;
|
|
192
|
+
meta;
|
|
193
|
+
_client = null;
|
|
194
|
+
_path = "";
|
|
195
|
+
_itemSchema = null;
|
|
196
|
+
_query = {};
|
|
197
|
+
constructor(data, meta) {
|
|
198
|
+
this.data = data;
|
|
199
|
+
this.meta = meta;
|
|
200
|
+
}
|
|
201
|
+
/** @internal */
|
|
202
|
+
_setClient(client, path, itemSchema, query) {
|
|
203
|
+
this._client = client;
|
|
204
|
+
this._path = path;
|
|
205
|
+
this._itemSchema = itemSchema;
|
|
206
|
+
this._query = query;
|
|
207
|
+
}
|
|
208
|
+
hasNextPage() {
|
|
209
|
+
return (this.meta.page + 1) * this.meta.pageSize < this.meta.total;
|
|
210
|
+
}
|
|
211
|
+
async nextPage() {
|
|
212
|
+
if (!this._client || !this._itemSchema) {
|
|
213
|
+
throw new Error("Page client is not set");
|
|
214
|
+
}
|
|
215
|
+
if (!this.hasNextPage()) {
|
|
216
|
+
throw new Error("No more pages");
|
|
217
|
+
}
|
|
218
|
+
const nextQuery = { ...this._query, page: this.meta.page + 1 };
|
|
219
|
+
const schema = PageSchema(this._itemSchema);
|
|
220
|
+
const raw = await this._client._get(this._path, {
|
|
221
|
+
castTo: schema,
|
|
222
|
+
query: nextQuery
|
|
223
|
+
});
|
|
224
|
+
const page = new _Page(raw.data, raw.meta);
|
|
225
|
+
page._setClient(this._client, this._path, this._itemSchema, this._query);
|
|
226
|
+
return page;
|
|
227
|
+
}
|
|
228
|
+
[Symbol.iterator]() {
|
|
229
|
+
return this.data[Symbol.iterator]();
|
|
230
|
+
}
|
|
231
|
+
async *autoPagingIter() {
|
|
232
|
+
let page = this;
|
|
233
|
+
while (true) {
|
|
234
|
+
for (const item of page.data) {
|
|
235
|
+
yield item;
|
|
236
|
+
}
|
|
237
|
+
if (!page.hasNextPage()) break;
|
|
238
|
+
page = await page.nextPage();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
var CallSchema = zod.z.object({
|
|
243
|
+
callId: zod.z.string(),
|
|
244
|
+
status: zod.z.enum(["queued", "ringing", "in-progress", "completed", "failed"]),
|
|
245
|
+
to: zod.z.string(),
|
|
246
|
+
from: zod.z.string(),
|
|
247
|
+
direction: zod.z.enum(["outbound", "inbound"]),
|
|
248
|
+
duration: zod.z.number().nullable().optional(),
|
|
249
|
+
accountId: zod.z.string(),
|
|
250
|
+
dateCreated: zod.z.string(),
|
|
251
|
+
dateUpdated: zod.z.string().nullable().optional()
|
|
252
|
+
}).passthrough();
|
|
253
|
+
var CallControlResponseSchema = zod.z.object({
|
|
254
|
+
callId: zod.z.string(),
|
|
255
|
+
status: zod.z.string()
|
|
256
|
+
}).passthrough();
|
|
257
|
+
|
|
258
|
+
// src/resources/calls.ts
|
|
259
|
+
var Calls = class extends APIResource {
|
|
260
|
+
async create(params, options = {}) {
|
|
261
|
+
const body = stripNotGiven({
|
|
262
|
+
To: params.to,
|
|
263
|
+
From: params.from,
|
|
264
|
+
Url: params.url,
|
|
265
|
+
StatusCallback: params.statusCallback,
|
|
266
|
+
StatusCallbackEvent: params.statusCallbackEvent
|
|
267
|
+
});
|
|
268
|
+
return this._client._post(`${this._basePath}/calls`, {
|
|
269
|
+
body,
|
|
270
|
+
castTo: CallSchema,
|
|
271
|
+
...options
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
async list(params = {}, options = {}) {
|
|
275
|
+
const query = stripNotGiven({
|
|
276
|
+
status: params.status,
|
|
277
|
+
page: params.page,
|
|
278
|
+
pageSize: params.pageSize
|
|
279
|
+
});
|
|
280
|
+
const path = `${this._basePath}/calls`;
|
|
281
|
+
const schema = PageSchema(CallSchema);
|
|
282
|
+
const raw = await this._client._get(path, {
|
|
283
|
+
castTo: schema,
|
|
284
|
+
query: Object.keys(query).length ? query : void 0,
|
|
285
|
+
...options
|
|
286
|
+
});
|
|
287
|
+
const page = new Page(raw.data, raw.meta);
|
|
288
|
+
page._setClient(this._client, path, CallSchema, query);
|
|
289
|
+
return page;
|
|
290
|
+
}
|
|
291
|
+
async get(callId, options = {}) {
|
|
292
|
+
return this._client._get(`${this._basePath}/calls/${callId}`, {
|
|
293
|
+
castTo: CallSchema,
|
|
294
|
+
...options
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
async update(callId, params = {}, options = {}) {
|
|
298
|
+
return this._client._post(`${this._basePath}/calls/${callId}`, {
|
|
299
|
+
body: { Status: params.status ?? "completed" },
|
|
300
|
+
castTo: CallControlResponseSchema,
|
|
301
|
+
...options
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
var MessageSchema = zod.z.object({
|
|
306
|
+
messageId: zod.z.string(),
|
|
307
|
+
status: zod.z.enum(["queued", "sending", "sent", "failed", "received"]),
|
|
308
|
+
type: zod.z.enum(["sms", "mms", "rcs", "kakao"]),
|
|
309
|
+
to: zod.z.string(),
|
|
310
|
+
from: zod.z.string(),
|
|
311
|
+
body: zod.z.string().nullable().optional(),
|
|
312
|
+
direction: zod.z.enum(["outbound", "inbound"]),
|
|
313
|
+
accountId: zod.z.string(),
|
|
314
|
+
dateCreated: zod.z.string(),
|
|
315
|
+
dateUpdated: zod.z.string().nullable().optional()
|
|
316
|
+
}).passthrough();
|
|
317
|
+
|
|
318
|
+
// src/resources/messages.ts
|
|
319
|
+
var Messages = class extends APIResource {
|
|
320
|
+
async create(params, options = {}) {
|
|
321
|
+
const body = stripNotGiven({
|
|
322
|
+
To: params.to,
|
|
323
|
+
From: params.from,
|
|
324
|
+
Body: params.body,
|
|
325
|
+
Type: params.type,
|
|
326
|
+
Subject: params.subject
|
|
327
|
+
});
|
|
328
|
+
return this._client._post(`${this._basePath}/messages`, {
|
|
329
|
+
body,
|
|
330
|
+
castTo: MessageSchema,
|
|
331
|
+
...options
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
async list(params = {}, options = {}) {
|
|
335
|
+
const query = stripNotGiven({
|
|
336
|
+
type: params.type,
|
|
337
|
+
status: params.status,
|
|
338
|
+
page: params.page,
|
|
339
|
+
pageSize: params.pageSize
|
|
340
|
+
});
|
|
341
|
+
const path = `${this._basePath}/messages`;
|
|
342
|
+
const schema = PageSchema(MessageSchema);
|
|
343
|
+
const raw = await this._client._get(path, {
|
|
344
|
+
castTo: schema,
|
|
345
|
+
query: Object.keys(query).length ? query : void 0,
|
|
346
|
+
...options
|
|
347
|
+
});
|
|
348
|
+
const page = new Page(raw.data, raw.meta);
|
|
349
|
+
page._setClient(this._client, path, MessageSchema, query);
|
|
350
|
+
return page;
|
|
351
|
+
}
|
|
352
|
+
async get(messageId, options = {}) {
|
|
353
|
+
return this._client._get(`${this._basePath}/messages/${messageId}`, {
|
|
354
|
+
castTo: MessageSchema,
|
|
355
|
+
...options
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
var PhoneNumberSchema = zod.z.object({
|
|
360
|
+
number: zod.z.string(),
|
|
361
|
+
source: zod.z.string().nullable().optional(),
|
|
362
|
+
webhookUrl: zod.z.string().nullable().optional(),
|
|
363
|
+
webhookMethod: zod.z.enum(["POST", "GET"]).nullable().optional(),
|
|
364
|
+
createdAt: zod.z.string().nullable().optional()
|
|
365
|
+
}).passthrough();
|
|
366
|
+
|
|
367
|
+
// src/resources/numbers.ts
|
|
368
|
+
var Numbers = class extends APIResource {
|
|
369
|
+
async create(params = {}, options = {}) {
|
|
370
|
+
const body = stripNotGiven({ webhookUrl: params.webhookUrl });
|
|
371
|
+
return this._client._post(`${this._basePath}/numbers`, {
|
|
372
|
+
body: Object.keys(body).length ? body : void 0,
|
|
373
|
+
castTo: PhoneNumberSchema,
|
|
374
|
+
...options
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
async list(options = {}) {
|
|
378
|
+
const schema = zod.z.object({ data: zod.z.array(PhoneNumberSchema) }).passthrough();
|
|
379
|
+
const result = await this._client._get(`${this._basePath}/numbers`, {
|
|
380
|
+
castTo: schema,
|
|
381
|
+
...options
|
|
382
|
+
});
|
|
383
|
+
return result.data;
|
|
384
|
+
}
|
|
385
|
+
async update(number, params = {}, options = {}) {
|
|
386
|
+
const body = stripNotGiven({
|
|
387
|
+
webhookUrl: params.webhookUrl,
|
|
388
|
+
webhookMethod: params.webhookMethod
|
|
389
|
+
});
|
|
390
|
+
return this._client._put(`${this._basePath}/numbers/${number}`, {
|
|
391
|
+
body,
|
|
392
|
+
castTo: PhoneNumberSchema,
|
|
393
|
+
...options
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
async delete(number, options = {}) {
|
|
397
|
+
await this._client._delete(`${this._basePath}/numbers/${number}`, options);
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
var WebhookLogSchema = zod.z.object({
|
|
401
|
+
id: zod.z.string(),
|
|
402
|
+
webhookId: zod.z.string(),
|
|
403
|
+
event: zod.z.string(),
|
|
404
|
+
requestUrl: zod.z.string(),
|
|
405
|
+
requestPayload: zod.z.record(zod.z.unknown()),
|
|
406
|
+
responseStatus: zod.z.number().nullable().optional(),
|
|
407
|
+
responseBody: zod.z.string().nullable().optional(),
|
|
408
|
+
responseTimeMs: zod.z.number().nullable().optional(),
|
|
409
|
+
status: zod.z.enum(["pending", "delivered", "failed"]),
|
|
410
|
+
attempt: zod.z.number(),
|
|
411
|
+
maxAttempts: zod.z.number(),
|
|
412
|
+
createdAt: zod.z.string(),
|
|
413
|
+
completedAt: zod.z.string().nullable().optional()
|
|
414
|
+
}).passthrough();
|
|
415
|
+
|
|
416
|
+
// src/resources/webhook-logs.ts
|
|
417
|
+
var WebhookLogs = class extends APIResource {
|
|
418
|
+
async list(webhookId, params = {}, options = {}) {
|
|
419
|
+
const query = stripNotGiven({ page: params.page, pageSize: params.pageSize });
|
|
420
|
+
const path = `${this._basePath}/webhooks/${webhookId}/logs`;
|
|
421
|
+
const schema = PageSchema(WebhookLogSchema);
|
|
422
|
+
const raw = await this._client._get(path, {
|
|
423
|
+
castTo: schema,
|
|
424
|
+
query: Object.keys(query).length ? query : void 0,
|
|
425
|
+
...options
|
|
426
|
+
});
|
|
427
|
+
const page = new Page(raw.data, raw.meta);
|
|
428
|
+
page._setClient(this._client, path, WebhookLogSchema, query);
|
|
429
|
+
return page;
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
// src/resources/accounts.ts
|
|
434
|
+
var AccountContext = class {
|
|
435
|
+
_client;
|
|
436
|
+
_accountId;
|
|
437
|
+
constructor(client, accountId) {
|
|
438
|
+
this._client = client;
|
|
439
|
+
this._accountId = accountId;
|
|
440
|
+
}
|
|
441
|
+
get calls() {
|
|
442
|
+
return new Calls(this._client, this._accountId);
|
|
443
|
+
}
|
|
444
|
+
get messages() {
|
|
445
|
+
return new Messages(this._client, this._accountId);
|
|
446
|
+
}
|
|
447
|
+
get numbers() {
|
|
448
|
+
return new Numbers(this._client, this._accountId);
|
|
449
|
+
}
|
|
450
|
+
get webhookLogs() {
|
|
451
|
+
return new WebhookLogs(this._client, this._accountId);
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
var WebhookVerificationError = class extends chunkJNSHMKDI_cjs.ClawOpsError {
|
|
455
|
+
constructor(message = "Webhook \uC11C\uBA85\uC774 \uC77C\uCE58\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.") {
|
|
456
|
+
super(message);
|
|
457
|
+
this.name = "WebhookVerificationError";
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
var Webhooks = class _Webhooks {
|
|
461
|
+
verify(options) {
|
|
462
|
+
const expected = _Webhooks._computeSignature(options.url, options.params, options.signingKey);
|
|
463
|
+
const expectedBuf = Buffer.from(expected, "utf-8");
|
|
464
|
+
const signatureBuf = Buffer.from(options.signature, "utf-8");
|
|
465
|
+
if (expectedBuf.length !== signatureBuf.length || !crypto.timingSafeEqual(expectedBuf, signatureBuf)) {
|
|
466
|
+
throw new WebhookVerificationError();
|
|
467
|
+
}
|
|
468
|
+
return true;
|
|
469
|
+
}
|
|
470
|
+
static _computeSignature(url, params, signingKey) {
|
|
471
|
+
const sortedParams = Object.keys(params).sort().map((k) => `${k}${params[k]}`).join("");
|
|
472
|
+
const dataToSign = url + sortedParams;
|
|
473
|
+
const digest = crypto.createHmac("sha256", signingKey).update(dataToSign, "utf-8").digest();
|
|
474
|
+
return digest.toString("base64");
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
// src/client.ts
|
|
479
|
+
var ClawOps = class extends APIClient {
|
|
480
|
+
_defaultAccountId;
|
|
481
|
+
constructor(options = {}) {
|
|
482
|
+
let apiKey = options.apiKey ?? process.env.CLAWOPS_API_KEY;
|
|
483
|
+
if (!apiKey) {
|
|
484
|
+
throw new chunkJNSHMKDI_cjs.ClawOpsError("apiKey\uB97C \uC9C0\uC815\uD558\uAC70\uB098 CLAWOPS_API_KEY \uD658\uACBD\uBCC0\uC218\uB97C \uC124\uC815\uD558\uC138\uC694.");
|
|
485
|
+
}
|
|
486
|
+
let accountId = options.accountId ?? process.env.CLAWOPS_ACCOUNT_ID;
|
|
487
|
+
if (!accountId) {
|
|
488
|
+
throw new chunkJNSHMKDI_cjs.ClawOpsError("accountId\uB97C \uC9C0\uC815\uD558\uAC70\uB098 CLAWOPS_ACCOUNT_ID \uD658\uACBD\uBCC0\uC218\uB97C \uC124\uC815\uD558\uC138\uC694.");
|
|
489
|
+
}
|
|
490
|
+
const baseURL = options.baseURL ?? process.env.CLAWOPS_BASE_URL ?? chunkJNSHMKDI_cjs.DEFAULT_BASE_URL;
|
|
491
|
+
super({
|
|
492
|
+
apiKey,
|
|
493
|
+
baseURL,
|
|
494
|
+
timeout: options.timeout,
|
|
495
|
+
maxRetries: options.maxRetries,
|
|
496
|
+
fetch: options.fetch,
|
|
497
|
+
defaultHeaders: options.defaultHeaders
|
|
498
|
+
});
|
|
499
|
+
this._defaultAccountId = accountId;
|
|
500
|
+
}
|
|
501
|
+
get calls() {
|
|
502
|
+
return new Calls(this, this._defaultAccountId);
|
|
503
|
+
}
|
|
504
|
+
get messages() {
|
|
505
|
+
return new Messages(this, this._defaultAccountId);
|
|
506
|
+
}
|
|
507
|
+
get numbers() {
|
|
508
|
+
return new Numbers(this, this._defaultAccountId);
|
|
509
|
+
}
|
|
510
|
+
get webhookLogs() {
|
|
511
|
+
return new WebhookLogs(this, this._defaultAccountId);
|
|
512
|
+
}
|
|
513
|
+
get webhooks() {
|
|
514
|
+
return new Webhooks();
|
|
515
|
+
}
|
|
516
|
+
accounts(accountId) {
|
|
517
|
+
return new AccountContext(this, accountId);
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
// src/client-default.ts
|
|
522
|
+
var client_default_default = ClawOps;
|
|
523
|
+
|
|
524
|
+
Object.defineProperty(exports, "APIConnectionError", {
|
|
525
|
+
enumerable: true,
|
|
526
|
+
get: function () { return chunkJNSHMKDI_cjs.APIConnectionError; }
|
|
527
|
+
});
|
|
528
|
+
Object.defineProperty(exports, "APIError", {
|
|
529
|
+
enumerable: true,
|
|
530
|
+
get: function () { return chunkJNSHMKDI_cjs.APIError; }
|
|
531
|
+
});
|
|
532
|
+
Object.defineProperty(exports, "APIResponseValidationError", {
|
|
533
|
+
enumerable: true,
|
|
534
|
+
get: function () { return chunkJNSHMKDI_cjs.APIResponseValidationError; }
|
|
535
|
+
});
|
|
536
|
+
Object.defineProperty(exports, "APIStatusError", {
|
|
537
|
+
enumerable: true,
|
|
538
|
+
get: function () { return chunkJNSHMKDI_cjs.APIStatusError; }
|
|
539
|
+
});
|
|
540
|
+
Object.defineProperty(exports, "APITimeoutError", {
|
|
541
|
+
enumerable: true,
|
|
542
|
+
get: function () { return chunkJNSHMKDI_cjs.APITimeoutError; }
|
|
543
|
+
});
|
|
544
|
+
Object.defineProperty(exports, "AgentConnectionError", {
|
|
545
|
+
enumerable: true,
|
|
546
|
+
get: function () { return chunkJNSHMKDI_cjs.AgentConnectionError; }
|
|
547
|
+
});
|
|
548
|
+
Object.defineProperty(exports, "AgentError", {
|
|
549
|
+
enumerable: true,
|
|
550
|
+
get: function () { return chunkJNSHMKDI_cjs.AgentError; }
|
|
551
|
+
});
|
|
552
|
+
Object.defineProperty(exports, "AuthenticationError", {
|
|
553
|
+
enumerable: true,
|
|
554
|
+
get: function () { return chunkJNSHMKDI_cjs.AuthenticationError; }
|
|
555
|
+
});
|
|
556
|
+
Object.defineProperty(exports, "BadRequestError", {
|
|
557
|
+
enumerable: true,
|
|
558
|
+
get: function () { return chunkJNSHMKDI_cjs.BadRequestError; }
|
|
559
|
+
});
|
|
560
|
+
Object.defineProperty(exports, "ClawOpsError", {
|
|
561
|
+
enumerable: true,
|
|
562
|
+
get: function () { return chunkJNSHMKDI_cjs.ClawOpsError; }
|
|
563
|
+
});
|
|
564
|
+
Object.defineProperty(exports, "ConflictError", {
|
|
565
|
+
enumerable: true,
|
|
566
|
+
get: function () { return chunkJNSHMKDI_cjs.ConflictError; }
|
|
567
|
+
});
|
|
568
|
+
Object.defineProperty(exports, "InternalServerError", {
|
|
569
|
+
enumerable: true,
|
|
570
|
+
get: function () { return chunkJNSHMKDI_cjs.InternalServerError; }
|
|
571
|
+
});
|
|
572
|
+
Object.defineProperty(exports, "NotFoundError", {
|
|
573
|
+
enumerable: true,
|
|
574
|
+
get: function () { return chunkJNSHMKDI_cjs.NotFoundError; }
|
|
575
|
+
});
|
|
576
|
+
Object.defineProperty(exports, "PermissionDeniedError", {
|
|
577
|
+
enumerable: true,
|
|
578
|
+
get: function () { return chunkJNSHMKDI_cjs.PermissionDeniedError; }
|
|
579
|
+
});
|
|
580
|
+
Object.defineProperty(exports, "ServiceUnavailableError", {
|
|
581
|
+
enumerable: true,
|
|
582
|
+
get: function () { return chunkJNSHMKDI_cjs.ServiceUnavailableError; }
|
|
583
|
+
});
|
|
584
|
+
Object.defineProperty(exports, "UnprocessableEntityError", {
|
|
585
|
+
enumerable: true,
|
|
586
|
+
get: function () { return chunkJNSHMKDI_cjs.UnprocessableEntityError; }
|
|
587
|
+
});
|
|
588
|
+
exports.APIClient = APIClient;
|
|
589
|
+
exports.AccountContext = AccountContext;
|
|
590
|
+
exports.Calls = Calls;
|
|
591
|
+
exports.ClawOps = ClawOps;
|
|
592
|
+
exports.Messages = Messages;
|
|
593
|
+
exports.Numbers = Numbers;
|
|
594
|
+
exports.Page = Page;
|
|
595
|
+
exports.VERSION = VERSION;
|
|
596
|
+
exports.WebhookLogs = WebhookLogs;
|
|
597
|
+
exports.WebhookVerificationError = WebhookVerificationError;
|
|
598
|
+
exports.Webhooks = Webhooks;
|
|
599
|
+
exports.default = client_default_default;
|
|
600
|
+
//# sourceMappingURL=index.cjs.map
|
|
601
|
+
//# sourceMappingURL=index.cjs.map
|