@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.
@@ -0,0 +1,549 @@
1
+ import { z } from 'zod';
2
+
3
+ interface APIClientOptions {
4
+ apiKey: string;
5
+ baseURL?: string;
6
+ timeout?: number;
7
+ maxRetries?: number;
8
+ fetch?: typeof globalThis.fetch;
9
+ defaultHeaders?: Record<string, string>;
10
+ }
11
+ declare class APIClient {
12
+ protected _apiKey: string;
13
+ protected _baseURL: string;
14
+ protected _maxRetries: number;
15
+ protected _timeout: number;
16
+ protected _fetch: typeof globalThis.fetch;
17
+ protected _defaultHeaders: Record<string, string>;
18
+ constructor(options: APIClientOptions);
19
+ private _buildHeaders;
20
+ protected _request<T>(method: string, path: string, options?: {
21
+ body?: Record<string, unknown> | null;
22
+ query?: Record<string, unknown> | null;
23
+ castTo?: z.ZodType<T>;
24
+ extraHeaders?: Record<string, string>;
25
+ extraQuery?: Record<string, unknown>;
26
+ timeout?: number;
27
+ }): Promise<T | null>;
28
+ private _shouldRetry;
29
+ private _retryDelay;
30
+ private _sleep;
31
+ _get<T>(path: string, options: {
32
+ castTo: z.ZodType<T>;
33
+ query?: Record<string, unknown> | null;
34
+ extraHeaders?: Record<string, string>;
35
+ extraQuery?: Record<string, unknown>;
36
+ timeout?: number;
37
+ }): Promise<T>;
38
+ _post<T>(path: string, options: {
39
+ body?: Record<string, unknown> | null;
40
+ castTo: z.ZodType<T>;
41
+ extraHeaders?: Record<string, string>;
42
+ extraQuery?: Record<string, unknown>;
43
+ timeout?: number;
44
+ }): Promise<T>;
45
+ _put<T>(path: string, options: {
46
+ body?: Record<string, unknown> | null;
47
+ castTo: z.ZodType<T>;
48
+ extraHeaders?: Record<string, string>;
49
+ extraQuery?: Record<string, unknown>;
50
+ timeout?: number;
51
+ }): Promise<T>;
52
+ _delete(path: string, options?: {
53
+ extraHeaders?: Record<string, string>;
54
+ timeout?: number;
55
+ }): Promise<void>;
56
+ }
57
+
58
+ declare class APIResource {
59
+ protected _client: APIClient;
60
+ protected _accountId: string;
61
+ constructor(client: APIClient, accountId: string);
62
+ protected get _basePath(): string;
63
+ }
64
+
65
+ declare class Page<T> {
66
+ data: T[];
67
+ meta: {
68
+ total: number;
69
+ page: number;
70
+ pageSize: number;
71
+ };
72
+ private _client;
73
+ private _path;
74
+ private _itemSchema;
75
+ private _query;
76
+ constructor(data: T[], meta: {
77
+ total: number;
78
+ page: number;
79
+ pageSize: number;
80
+ });
81
+ /** @internal */
82
+ _setClient(client: APIClient, path: string, itemSchema: z.ZodType<T>, query: Record<string, unknown>): void;
83
+ hasNextPage(): boolean;
84
+ nextPage(): Promise<Page<T>>;
85
+ [Symbol.iterator](): Iterator<T>;
86
+ autoPagingIter(): AsyncGenerator<T>;
87
+ }
88
+
89
+ declare const CallSchema: z.ZodObject<{
90
+ callId: z.ZodString;
91
+ status: z.ZodEnum<["queued", "ringing", "in-progress", "completed", "failed"]>;
92
+ to: z.ZodString;
93
+ from: z.ZodString;
94
+ direction: z.ZodEnum<["outbound", "inbound"]>;
95
+ duration: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
96
+ accountId: z.ZodString;
97
+ dateCreated: z.ZodString;
98
+ dateUpdated: z.ZodOptional<z.ZodNullable<z.ZodString>>;
99
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
100
+ callId: z.ZodString;
101
+ status: z.ZodEnum<["queued", "ringing", "in-progress", "completed", "failed"]>;
102
+ to: z.ZodString;
103
+ from: z.ZodString;
104
+ direction: z.ZodEnum<["outbound", "inbound"]>;
105
+ duration: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
106
+ accountId: z.ZodString;
107
+ dateCreated: z.ZodString;
108
+ dateUpdated: z.ZodOptional<z.ZodNullable<z.ZodString>>;
109
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
110
+ callId: z.ZodString;
111
+ status: z.ZodEnum<["queued", "ringing", "in-progress", "completed", "failed"]>;
112
+ to: z.ZodString;
113
+ from: z.ZodString;
114
+ direction: z.ZodEnum<["outbound", "inbound"]>;
115
+ duration: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
116
+ accountId: z.ZodString;
117
+ dateCreated: z.ZodString;
118
+ dateUpdated: z.ZodOptional<z.ZodNullable<z.ZodString>>;
119
+ }, z.ZodTypeAny, "passthrough">>;
120
+ type Call = z.infer<typeof CallSchema>;
121
+ declare const CallControlResponseSchema: z.ZodObject<{
122
+ callId: z.ZodString;
123
+ status: z.ZodString;
124
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
125
+ callId: z.ZodString;
126
+ status: z.ZodString;
127
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
128
+ callId: z.ZodString;
129
+ status: z.ZodString;
130
+ }, z.ZodTypeAny, "passthrough">>;
131
+ type CallControlResponse = z.infer<typeof CallControlResponseSchema>;
132
+
133
+ interface CallCreateParams {
134
+ to: string;
135
+ from: string;
136
+ url: string;
137
+ statusCallback?: string;
138
+ statusCallbackEvent?: string;
139
+ }
140
+ interface CallListParams {
141
+ status?: 'queued' | 'ringing' | 'in-progress' | 'completed' | 'failed';
142
+ page?: number;
143
+ pageSize?: number;
144
+ }
145
+ interface CallUpdateParams {
146
+ status?: 'completed';
147
+ }
148
+
149
+ declare class Calls extends APIResource {
150
+ create(params: CallCreateParams, options?: {
151
+ extraHeaders?: Record<string, string>;
152
+ extraQuery?: Record<string, unknown>;
153
+ timeout?: number;
154
+ }): Promise<Call>;
155
+ list(params?: CallListParams, options?: {
156
+ extraHeaders?: Record<string, string>;
157
+ extraQuery?: Record<string, unknown>;
158
+ timeout?: number;
159
+ }): Promise<Page<Call>>;
160
+ get(callId: string, options?: {
161
+ extraHeaders?: Record<string, string>;
162
+ extraQuery?: Record<string, unknown>;
163
+ timeout?: number;
164
+ }): Promise<Call>;
165
+ update(callId: string, params?: {
166
+ status?: 'completed';
167
+ }, options?: {
168
+ extraHeaders?: Record<string, string>;
169
+ extraQuery?: Record<string, unknown>;
170
+ timeout?: number;
171
+ }): Promise<CallControlResponse>;
172
+ }
173
+
174
+ declare const MessageSchema: z.ZodObject<{
175
+ messageId: z.ZodString;
176
+ status: z.ZodEnum<["queued", "sending", "sent", "failed", "received"]>;
177
+ type: z.ZodEnum<["sms", "mms", "rcs", "kakao"]>;
178
+ to: z.ZodString;
179
+ from: z.ZodString;
180
+ body: z.ZodOptional<z.ZodNullable<z.ZodString>>;
181
+ direction: z.ZodEnum<["outbound", "inbound"]>;
182
+ accountId: z.ZodString;
183
+ dateCreated: z.ZodString;
184
+ dateUpdated: z.ZodOptional<z.ZodNullable<z.ZodString>>;
185
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
186
+ messageId: z.ZodString;
187
+ status: z.ZodEnum<["queued", "sending", "sent", "failed", "received"]>;
188
+ type: z.ZodEnum<["sms", "mms", "rcs", "kakao"]>;
189
+ to: z.ZodString;
190
+ from: z.ZodString;
191
+ body: z.ZodOptional<z.ZodNullable<z.ZodString>>;
192
+ direction: z.ZodEnum<["outbound", "inbound"]>;
193
+ accountId: z.ZodString;
194
+ dateCreated: z.ZodString;
195
+ dateUpdated: z.ZodOptional<z.ZodNullable<z.ZodString>>;
196
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
197
+ messageId: z.ZodString;
198
+ status: z.ZodEnum<["queued", "sending", "sent", "failed", "received"]>;
199
+ type: z.ZodEnum<["sms", "mms", "rcs", "kakao"]>;
200
+ to: z.ZodString;
201
+ from: z.ZodString;
202
+ body: z.ZodOptional<z.ZodNullable<z.ZodString>>;
203
+ direction: z.ZodEnum<["outbound", "inbound"]>;
204
+ accountId: z.ZodString;
205
+ dateCreated: z.ZodString;
206
+ dateUpdated: z.ZodOptional<z.ZodNullable<z.ZodString>>;
207
+ }, z.ZodTypeAny, "passthrough">>;
208
+ type Message = z.infer<typeof MessageSchema>;
209
+
210
+ interface MessageCreateParams {
211
+ to: string;
212
+ from: string;
213
+ body: string;
214
+ type?: 'sms' | 'mms' | 'rcs' | 'kakao';
215
+ subject?: string;
216
+ }
217
+ interface MessageListParams {
218
+ type?: 'sms' | 'mms' | 'rcs' | 'kakao';
219
+ status?: 'queued' | 'sending' | 'sent' | 'failed' | 'received';
220
+ page?: number;
221
+ pageSize?: number;
222
+ }
223
+
224
+ declare class Messages extends APIResource {
225
+ create(params: MessageCreateParams, options?: {
226
+ extraHeaders?: Record<string, string>;
227
+ extraQuery?: Record<string, unknown>;
228
+ timeout?: number;
229
+ }): Promise<Message>;
230
+ list(params?: MessageListParams, options?: {
231
+ extraHeaders?: Record<string, string>;
232
+ extraQuery?: Record<string, unknown>;
233
+ timeout?: number;
234
+ }): Promise<Page<Message>>;
235
+ get(messageId: string, options?: {
236
+ extraHeaders?: Record<string, string>;
237
+ extraQuery?: Record<string, unknown>;
238
+ timeout?: number;
239
+ }): Promise<Message>;
240
+ }
241
+
242
+ declare const PhoneNumberSchema: z.ZodObject<{
243
+ number: z.ZodString;
244
+ source: z.ZodOptional<z.ZodNullable<z.ZodString>>;
245
+ webhookUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
246
+ webhookMethod: z.ZodOptional<z.ZodNullable<z.ZodEnum<["POST", "GET"]>>>;
247
+ createdAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
248
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
249
+ number: z.ZodString;
250
+ source: z.ZodOptional<z.ZodNullable<z.ZodString>>;
251
+ webhookUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
252
+ webhookMethod: z.ZodOptional<z.ZodNullable<z.ZodEnum<["POST", "GET"]>>>;
253
+ createdAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
254
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
255
+ number: z.ZodString;
256
+ source: z.ZodOptional<z.ZodNullable<z.ZodString>>;
257
+ webhookUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
258
+ webhookMethod: z.ZodOptional<z.ZodNullable<z.ZodEnum<["POST", "GET"]>>>;
259
+ createdAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
260
+ }, z.ZodTypeAny, "passthrough">>;
261
+ type PhoneNumber = z.infer<typeof PhoneNumberSchema>;
262
+ type NumberListItem = PhoneNumber;
263
+ type NumberUpdateResponse = PhoneNumber;
264
+
265
+ declare class Numbers extends APIResource {
266
+ create(params?: {
267
+ webhookUrl?: string;
268
+ }, options?: {
269
+ extraHeaders?: Record<string, string>;
270
+ extraQuery?: Record<string, unknown>;
271
+ timeout?: number;
272
+ }): Promise<PhoneNumber>;
273
+ list(options?: {
274
+ extraHeaders?: Record<string, string>;
275
+ extraQuery?: Record<string, unknown>;
276
+ timeout?: number;
277
+ }): Promise<NumberListItem[]>;
278
+ update(number: string, params?: {
279
+ webhookUrl?: string;
280
+ webhookMethod?: 'POST' | 'GET';
281
+ }, options?: {
282
+ extraHeaders?: Record<string, string>;
283
+ extraQuery?: Record<string, unknown>;
284
+ timeout?: number;
285
+ }): Promise<NumberUpdateResponse>;
286
+ delete(number: string, options?: {
287
+ extraHeaders?: Record<string, string>;
288
+ timeout?: number;
289
+ }): Promise<void>;
290
+ }
291
+
292
+ declare const WebhookLogSchema: z.ZodObject<{
293
+ id: z.ZodString;
294
+ webhookId: z.ZodString;
295
+ event: z.ZodString;
296
+ requestUrl: z.ZodString;
297
+ requestPayload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
298
+ responseStatus: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
299
+ responseBody: z.ZodOptional<z.ZodNullable<z.ZodString>>;
300
+ responseTimeMs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
301
+ status: z.ZodEnum<["pending", "delivered", "failed"]>;
302
+ attempt: z.ZodNumber;
303
+ maxAttempts: z.ZodNumber;
304
+ createdAt: z.ZodString;
305
+ completedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
306
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
307
+ id: z.ZodString;
308
+ webhookId: z.ZodString;
309
+ event: z.ZodString;
310
+ requestUrl: z.ZodString;
311
+ requestPayload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
312
+ responseStatus: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
313
+ responseBody: z.ZodOptional<z.ZodNullable<z.ZodString>>;
314
+ responseTimeMs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
315
+ status: z.ZodEnum<["pending", "delivered", "failed"]>;
316
+ attempt: z.ZodNumber;
317
+ maxAttempts: z.ZodNumber;
318
+ createdAt: z.ZodString;
319
+ completedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
320
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
321
+ id: z.ZodString;
322
+ webhookId: z.ZodString;
323
+ event: z.ZodString;
324
+ requestUrl: z.ZodString;
325
+ requestPayload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
326
+ responseStatus: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
327
+ responseBody: z.ZodOptional<z.ZodNullable<z.ZodString>>;
328
+ responseTimeMs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
329
+ status: z.ZodEnum<["pending", "delivered", "failed"]>;
330
+ attempt: z.ZodNumber;
331
+ maxAttempts: z.ZodNumber;
332
+ createdAt: z.ZodString;
333
+ completedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
334
+ }, z.ZodTypeAny, "passthrough">>;
335
+ type WebhookLog = z.infer<typeof WebhookLogSchema>;
336
+
337
+ declare class WebhookLogs extends APIResource {
338
+ list(webhookId: string, params?: {
339
+ page?: number;
340
+ pageSize?: number;
341
+ }, options?: {
342
+ extraHeaders?: Record<string, string>;
343
+ extraQuery?: Record<string, unknown>;
344
+ timeout?: number;
345
+ }): Promise<Page<WebhookLog>>;
346
+ }
347
+
348
+ declare class AccountContext {
349
+ private _client;
350
+ private _accountId;
351
+ constructor(client: APIClient, accountId: string);
352
+ get calls(): Calls;
353
+ get messages(): Messages;
354
+ get numbers(): Numbers;
355
+ get webhookLogs(): WebhookLogs;
356
+ }
357
+
358
+ declare class ClawOpsError extends Error {
359
+ constructor(message: string);
360
+ }
361
+ declare class APIError extends ClawOpsError {
362
+ readonly request: {
363
+ method: string;
364
+ url: string;
365
+ };
366
+ constructor(message: string, request: {
367
+ method: string;
368
+ url: string;
369
+ });
370
+ }
371
+ declare class APIStatusError extends APIError {
372
+ readonly status: number;
373
+ readonly body: unknown;
374
+ readonly headers: Headers | undefined;
375
+ constructor(message: string, response: {
376
+ status: number;
377
+ headers?: Headers;
378
+ }, body: unknown, request: {
379
+ method: string;
380
+ url: string;
381
+ });
382
+ }
383
+ declare class BadRequestError extends APIStatusError {
384
+ readonly status: 400;
385
+ constructor(message: string, response: {
386
+ status: number;
387
+ headers?: Headers;
388
+ }, body: unknown, request: {
389
+ method: string;
390
+ url: string;
391
+ });
392
+ }
393
+ declare class AuthenticationError extends APIStatusError {
394
+ readonly status: 401;
395
+ constructor(message: string, response: {
396
+ status: number;
397
+ headers?: Headers;
398
+ }, body: unknown, request: {
399
+ method: string;
400
+ url: string;
401
+ });
402
+ }
403
+ declare class PermissionDeniedError extends APIStatusError {
404
+ readonly status: 403;
405
+ constructor(message: string, response: {
406
+ status: number;
407
+ headers?: Headers;
408
+ }, body: unknown, request: {
409
+ method: string;
410
+ url: string;
411
+ });
412
+ }
413
+ declare class NotFoundError extends APIStatusError {
414
+ readonly status: 404;
415
+ constructor(message: string, response: {
416
+ status: number;
417
+ headers?: Headers;
418
+ }, body: unknown, request: {
419
+ method: string;
420
+ url: string;
421
+ });
422
+ }
423
+ declare class ConflictError extends APIStatusError {
424
+ readonly status: 409;
425
+ constructor(message: string, response: {
426
+ status: number;
427
+ headers?: Headers;
428
+ }, body: unknown, request: {
429
+ method: string;
430
+ url: string;
431
+ });
432
+ }
433
+ declare class UnprocessableEntityError extends APIStatusError {
434
+ readonly status: 422;
435
+ constructor(message: string, response: {
436
+ status: number;
437
+ headers?: Headers;
438
+ }, body: unknown, request: {
439
+ method: string;
440
+ url: string;
441
+ });
442
+ }
443
+ declare class InternalServerError extends APIStatusError {
444
+ readonly status: 500;
445
+ constructor(message: string, response: {
446
+ status: number;
447
+ headers?: Headers;
448
+ }, body: unknown, request: {
449
+ method: string;
450
+ url: string;
451
+ });
452
+ }
453
+ declare class ServiceUnavailableError extends APIStatusError {
454
+ readonly status: 503;
455
+ constructor(message: string, response: {
456
+ status: number;
457
+ headers?: Headers;
458
+ }, body: unknown, request: {
459
+ method: string;
460
+ url: string;
461
+ });
462
+ }
463
+ declare class APIConnectionError extends APIError {
464
+ constructor(request: {
465
+ method: string;
466
+ url: string;
467
+ }, message?: string);
468
+ }
469
+ declare class APITimeoutError extends APIConnectionError {
470
+ constructor(request: {
471
+ method: string;
472
+ url: string;
473
+ });
474
+ }
475
+ declare class APIResponseValidationError extends APIError {
476
+ readonly status: number;
477
+ constructor(response: {
478
+ status: number;
479
+ }, request: {
480
+ method: string;
481
+ url: string;
482
+ });
483
+ }
484
+ declare class AgentError extends ClawOpsError {
485
+ constructor(message: string);
486
+ }
487
+ declare class AgentConnectionError extends AgentError {
488
+ constructor(message?: string);
489
+ }
490
+
491
+ declare class WebhookVerificationError extends ClawOpsError {
492
+ constructor(message?: string);
493
+ }
494
+ declare class Webhooks {
495
+ verify(options: {
496
+ url: string;
497
+ params: Record<string, string>;
498
+ signature: string;
499
+ signingKey: string;
500
+ }): boolean;
501
+ static _computeSignature(url: string, params: Record<string, string>, signingKey: string): string;
502
+ }
503
+
504
+ interface ClawOpsOptions {
505
+ apiKey?: string;
506
+ accountId?: string;
507
+ baseURL?: string;
508
+ timeout?: number;
509
+ maxRetries?: number;
510
+ fetch?: typeof globalThis.fetch;
511
+ defaultHeaders?: Record<string, string>;
512
+ }
513
+ declare class ClawOps extends APIClient {
514
+ private _defaultAccountId;
515
+ constructor(options?: ClawOpsOptions);
516
+ get calls(): Calls;
517
+ get messages(): Messages;
518
+ get numbers(): Numbers;
519
+ get webhookLogs(): WebhookLogs;
520
+ get webhooks(): Webhooks;
521
+ accounts(accountId: string): AccountContext;
522
+ }
523
+
524
+ declare const VERSION = "0.1.0";
525
+
526
+ declare const PaginationMetaSchema: z.ZodObject<{
527
+ total: z.ZodNumber;
528
+ page: z.ZodNumber;
529
+ pageSize: z.ZodNumber;
530
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
531
+ total: z.ZodNumber;
532
+ page: z.ZodNumber;
533
+ pageSize: z.ZodNumber;
534
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
535
+ total: z.ZodNumber;
536
+ page: z.ZodNumber;
537
+ pageSize: z.ZodNumber;
538
+ }, z.ZodTypeAny, "passthrough">>;
539
+ type PaginationMeta = z.infer<typeof PaginationMetaSchema>;
540
+
541
+ interface NumberCreateParams {
542
+ webhookUrl?: string;
543
+ }
544
+ interface NumberUpdateParams {
545
+ webhookUrl?: string;
546
+ webhookMethod?: 'POST' | 'GET';
547
+ }
548
+
549
+ export { APIClient, type APIClientOptions, APIConnectionError, APIError, APIResponseValidationError, APIStatusError, APITimeoutError, AccountContext, AgentConnectionError, AgentError, AuthenticationError, BadRequestError, type Call, type CallControlResponse, type CallCreateParams, type CallListParams, type CallUpdateParams, Calls, ClawOps, ClawOpsError, type ClawOpsOptions, ConflictError, InternalServerError, type Message, type MessageCreateParams, type MessageListParams, Messages, NotFoundError, type NumberCreateParams, type NumberListItem, type NumberUpdateParams, type NumberUpdateResponse, Numbers, Page, type PaginationMeta, PermissionDeniedError, type PhoneNumber, ServiceUnavailableError, UnprocessableEntityError, VERSION, type WebhookLog, WebhookLogs, WebhookVerificationError, Webhooks, ClawOps as default };