@limitry/sdk 0.0.0-stage → 1.0.0-rc.1
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 +202 -0
- package/NOTICE +2 -0
- package/README.md +25 -2
- package/dist/brand.d.ts +6 -0
- package/dist/brand.js +7 -0
- package/dist/errors.d.ts +9 -0
- package/dist/errors.js +18 -0
- package/dist/index.d.ts +483 -0
- package/dist/index.js +73 -0
- package/dist/product/index.d.ts +24 -0
- package/dist/product/index.js +7 -0
- package/dist/product/limits.d.ts +110 -0
- package/dist/product/limits.js +234 -0
- package/dist/resources.d.ts +71 -0
- package/dist/resources.gen.d.ts +400 -0
- package/dist/resources.gen.js +83 -0
- package/dist/resources.js +40 -0
- package/dist/retry.d.ts +42 -0
- package/dist/retry.js +116 -0
- package/dist/v1.gen.d.ts +4207 -0
- package/dist/v1.gen.js +1 -0
- package/dist/webhooks.d.ts +39 -0
- package/dist/webhooks.js +88 -0
- package/package.json +36 -4
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { type Input, type RawClient, type RequestOptions } from "./resources.ts";
|
|
2
|
+
/** The resource methods for a client (./resources.ts). */
|
|
3
|
+
export declare function resources(client: RawClient): {
|
|
4
|
+
checks: {
|
|
5
|
+
create: (input: Input<"/checks", "post">, options?: RequestOptions) => Promise<{
|
|
6
|
+
allowed: boolean;
|
|
7
|
+
id: string;
|
|
8
|
+
reason: {
|
|
9
|
+
code: "limit_exceeded" | "too_many_reservations";
|
|
10
|
+
limit: string | null;
|
|
11
|
+
} | null;
|
|
12
|
+
remaining: import("./v1.gen.ts").components["schemas"]["CheckRemaining"][];
|
|
13
|
+
reservation?: {
|
|
14
|
+
expiresAt: string;
|
|
15
|
+
id: string;
|
|
16
|
+
};
|
|
17
|
+
retryAfterSeconds: number | null;
|
|
18
|
+
}>;
|
|
19
|
+
};
|
|
20
|
+
limits: {
|
|
21
|
+
archive: (limitId: string | number, options?: RequestOptions) => Promise<undefined>;
|
|
22
|
+
create: (input: Input<"/limits", "post">, options?: RequestOptions) => Promise<{
|
|
23
|
+
action: string;
|
|
24
|
+
amount: number;
|
|
25
|
+
archivedAt: string | null;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
enabled: boolean;
|
|
28
|
+
every: number;
|
|
29
|
+
failMode: "open" | "closed";
|
|
30
|
+
id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
rolling: boolean;
|
|
33
|
+
start: "calendar" | "anchor" | "first_use";
|
|
34
|
+
subject: import("./v1.gen.ts").components["schemas"]["LimitSubject"];
|
|
35
|
+
unit: string;
|
|
36
|
+
updatedAt: string;
|
|
37
|
+
version: number;
|
|
38
|
+
window: "minute" | "hour" | "day" | "week" | "month" | "year" | "total" | "concurrent";
|
|
39
|
+
}>;
|
|
40
|
+
get: (limitId: string | number, options?: RequestOptions) => Promise<{
|
|
41
|
+
action: string;
|
|
42
|
+
amount: number;
|
|
43
|
+
archivedAt: string | null;
|
|
44
|
+
createdAt: string;
|
|
45
|
+
enabled: boolean;
|
|
46
|
+
every: number;
|
|
47
|
+
failMode: "open" | "closed";
|
|
48
|
+
id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
rolling: boolean;
|
|
51
|
+
start: "calendar" | "anchor" | "first_use";
|
|
52
|
+
subject: import("./v1.gen.ts").components["schemas"]["LimitSubject"];
|
|
53
|
+
unit: string;
|
|
54
|
+
updatedAt: string;
|
|
55
|
+
version: number;
|
|
56
|
+
window: "minute" | "hour" | "day" | "week" | "month" | "year" | "total" | "concurrent";
|
|
57
|
+
}>;
|
|
58
|
+
grants: {
|
|
59
|
+
create: (limitId: string | number, input: Input<"/limits/{limitId}/grants", "post">, options?: RequestOptions) => Promise<{
|
|
60
|
+
amount: number;
|
|
61
|
+
createdAt: string;
|
|
62
|
+
createdByUserId: string | null;
|
|
63
|
+
id: string;
|
|
64
|
+
limitId: string;
|
|
65
|
+
note: string;
|
|
66
|
+
subject: {
|
|
67
|
+
id: string;
|
|
68
|
+
kind: string;
|
|
69
|
+
};
|
|
70
|
+
}>;
|
|
71
|
+
list: (limitId: string | number, options?: RequestOptions) => Promise<{
|
|
72
|
+
items: import("./v1.gen.ts").components["schemas"]["LimitGrant"][];
|
|
73
|
+
}>;
|
|
74
|
+
};
|
|
75
|
+
list: (input?: Input<"/limits", "get">, options?: RequestOptions) => Promise<{
|
|
76
|
+
items: import("./v1.gen.ts").components["schemas"]["Limit"][];
|
|
77
|
+
nextCursor: string | null;
|
|
78
|
+
}>;
|
|
79
|
+
restore: (limitId: string | number, options?: RequestOptions) => Promise<{
|
|
80
|
+
action: string;
|
|
81
|
+
amount: number;
|
|
82
|
+
archivedAt: string | null;
|
|
83
|
+
createdAt: string;
|
|
84
|
+
enabled: boolean;
|
|
85
|
+
every: number;
|
|
86
|
+
failMode: "open" | "closed";
|
|
87
|
+
id: string;
|
|
88
|
+
name: string;
|
|
89
|
+
rolling: boolean;
|
|
90
|
+
start: "calendar" | "anchor" | "first_use";
|
|
91
|
+
subject: import("./v1.gen.ts").components["schemas"]["LimitSubject"];
|
|
92
|
+
unit: string;
|
|
93
|
+
updatedAt: string;
|
|
94
|
+
version: number;
|
|
95
|
+
window: "minute" | "hour" | "day" | "week" | "month" | "year" | "total" | "concurrent";
|
|
96
|
+
}>;
|
|
97
|
+
sync: (input: Input<"/limits/sync", "post">, options?: RequestOptions) => Promise<{
|
|
98
|
+
archived: string[];
|
|
99
|
+
created: string[];
|
|
100
|
+
dryRun: boolean;
|
|
101
|
+
unchanged: string[];
|
|
102
|
+
updated: {
|
|
103
|
+
changes: {
|
|
104
|
+
[key: string]: {
|
|
105
|
+
from: string | number | boolean | null;
|
|
106
|
+
to: string | number | boolean | null;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
name: string;
|
|
110
|
+
}[];
|
|
111
|
+
}>;
|
|
112
|
+
update: (limitId: string | number, input?: Input<"/limits/{limitId}", "patch">, options?: RequestOptions) => Promise<{
|
|
113
|
+
action: string;
|
|
114
|
+
amount: number;
|
|
115
|
+
archivedAt: string | null;
|
|
116
|
+
createdAt: string;
|
|
117
|
+
enabled: boolean;
|
|
118
|
+
every: number;
|
|
119
|
+
failMode: "open" | "closed";
|
|
120
|
+
id: string;
|
|
121
|
+
name: string;
|
|
122
|
+
rolling: boolean;
|
|
123
|
+
start: "calendar" | "anchor" | "first_use";
|
|
124
|
+
subject: import("./v1.gen.ts").components["schemas"]["LimitSubject"];
|
|
125
|
+
unit: string;
|
|
126
|
+
updatedAt: string;
|
|
127
|
+
version: number;
|
|
128
|
+
window: "minute" | "hour" | "day" | "week" | "month" | "year" | "total" | "concurrent";
|
|
129
|
+
}>;
|
|
130
|
+
};
|
|
131
|
+
reservations: {
|
|
132
|
+
commit: (reservationId: string | number, input: Input<"/reservations/{reservationId}/commit", "post">, options?: RequestOptions) => Promise<{
|
|
133
|
+
cost: number;
|
|
134
|
+
expiresAt: string;
|
|
135
|
+
id: string;
|
|
136
|
+
reserved: number;
|
|
137
|
+
status: "held" | "committed" | "released" | "expired";
|
|
138
|
+
}>;
|
|
139
|
+
extend: (reservationId: string | number, input?: Input<"/reservations/{reservationId}/extend", "post">, options?: RequestOptions) => Promise<{
|
|
140
|
+
cost: number;
|
|
141
|
+
expiresAt: string;
|
|
142
|
+
id: string;
|
|
143
|
+
reserved: number;
|
|
144
|
+
status: "held" | "committed" | "released" | "expired";
|
|
145
|
+
}>;
|
|
146
|
+
release: (reservationId: string | number, options?: RequestOptions) => Promise<{
|
|
147
|
+
cost: number;
|
|
148
|
+
expiresAt: string;
|
|
149
|
+
id: string;
|
|
150
|
+
reserved: number;
|
|
151
|
+
status: "held" | "committed" | "released" | "expired";
|
|
152
|
+
}>;
|
|
153
|
+
};
|
|
154
|
+
subjects: {
|
|
155
|
+
get: (subjectKind: string | number, subjectId: string | number, options?: RequestOptions) => Promise<{
|
|
156
|
+
anchor: string | null;
|
|
157
|
+
subject: import("./v1.gen.ts").components["schemas"]["SubjectRef"];
|
|
158
|
+
}>;
|
|
159
|
+
reset: (subjectKind: string | number, subjectId: string | number, input?: Input<"/subjects/{subjectKind}/{subjectId}/reset", "post">, options?: RequestOptions) => Promise<{
|
|
160
|
+
reset: string[];
|
|
161
|
+
subject: import("./v1.gen.ts").components["schemas"]["SubjectRef"];
|
|
162
|
+
}>;
|
|
163
|
+
update: (subjectKind: string | number, subjectId: string | number, input: Input<"/subjects/{subjectKind}/{subjectId}", "patch">, options?: RequestOptions) => Promise<{
|
|
164
|
+
anchor: string | null;
|
|
165
|
+
subject: import("./v1.gen.ts").components["schemas"]["SubjectRef"];
|
|
166
|
+
}>;
|
|
167
|
+
};
|
|
168
|
+
usage: {
|
|
169
|
+
query: (input: Input<"/usage", "get">, options?: RequestOptions) => Promise<{
|
|
170
|
+
granularity: "hour" | "day";
|
|
171
|
+
limitId: string;
|
|
172
|
+
points: {
|
|
173
|
+
allowed: number;
|
|
174
|
+
denied: number;
|
|
175
|
+
start: string;
|
|
176
|
+
used: number;
|
|
177
|
+
}[];
|
|
178
|
+
}>;
|
|
179
|
+
standing: (input: Input<"/usage/standing", "get">, options?: RequestOptions) => Promise<{
|
|
180
|
+
environment: string;
|
|
181
|
+
limits: {
|
|
182
|
+
action: string;
|
|
183
|
+
amount: number;
|
|
184
|
+
limit: string;
|
|
185
|
+
name: string;
|
|
186
|
+
remaining: number;
|
|
187
|
+
resetsAt: string | null;
|
|
188
|
+
rolling: boolean;
|
|
189
|
+
shared: boolean;
|
|
190
|
+
subject: {
|
|
191
|
+
id: string;
|
|
192
|
+
kind: string;
|
|
193
|
+
};
|
|
194
|
+
unit: string;
|
|
195
|
+
used: number;
|
|
196
|
+
window: "minute" | "hour" | "day" | "week" | "month" | "year" | "total" | "concurrent";
|
|
197
|
+
}[];
|
|
198
|
+
subject: {
|
|
199
|
+
id: string;
|
|
200
|
+
kind: string;
|
|
201
|
+
};
|
|
202
|
+
}>;
|
|
203
|
+
subjects: (input: Input<"/usage/subjects", "get">, options?: RequestOptions) => Promise<{
|
|
204
|
+
items: {
|
|
205
|
+
denied: number;
|
|
206
|
+
over: boolean;
|
|
207
|
+
remaining: number;
|
|
208
|
+
subject: {
|
|
209
|
+
id: string;
|
|
210
|
+
kind: string;
|
|
211
|
+
};
|
|
212
|
+
used: number;
|
|
213
|
+
}[];
|
|
214
|
+
limitId: string;
|
|
215
|
+
windowStart: string;
|
|
216
|
+
}>;
|
|
217
|
+
};
|
|
218
|
+
user: {
|
|
219
|
+
me: (options?: RequestOptions) => Promise<{
|
|
220
|
+
email: string;
|
|
221
|
+
id: string;
|
|
222
|
+
name: string;
|
|
223
|
+
workspaces: {
|
|
224
|
+
id: string;
|
|
225
|
+
name: string;
|
|
226
|
+
role: string;
|
|
227
|
+
slug: string;
|
|
228
|
+
}[];
|
|
229
|
+
}>;
|
|
230
|
+
revokeToken: (options?: RequestOptions) => Promise<undefined>;
|
|
231
|
+
};
|
|
232
|
+
workspace: {
|
|
233
|
+
approvalActions: {
|
|
234
|
+
list: (options?: RequestOptions) => Promise<{
|
|
235
|
+
items: {
|
|
236
|
+
approverRoles: string[];
|
|
237
|
+
createsSecret: boolean;
|
|
238
|
+
id: string;
|
|
239
|
+
input: {
|
|
240
|
+
[key: string]: unknown;
|
|
241
|
+
};
|
|
242
|
+
title: string;
|
|
243
|
+
}[];
|
|
244
|
+
}>;
|
|
245
|
+
};
|
|
246
|
+
approvalRequests: {
|
|
247
|
+
create: (input: Input<"/workspace/approval-requests", "post">, options?: RequestOptions) => Promise<{
|
|
248
|
+
action: string;
|
|
249
|
+
approveUrl: string;
|
|
250
|
+
createdAt: string;
|
|
251
|
+
decidedAt: string | null;
|
|
252
|
+
expiresAt: string;
|
|
253
|
+
id: string;
|
|
254
|
+
input: {
|
|
255
|
+
[key: string]: unknown;
|
|
256
|
+
};
|
|
257
|
+
reason: string;
|
|
258
|
+
requestedBy: string | null;
|
|
259
|
+
result: {
|
|
260
|
+
[key: string]: unknown;
|
|
261
|
+
} | null;
|
|
262
|
+
secret: {
|
|
263
|
+
envVar: string;
|
|
264
|
+
name: string;
|
|
265
|
+
} | null;
|
|
266
|
+
status: "pending" | "approved" | "completed" | "denied" | "failed" | "expired";
|
|
267
|
+
summary: string;
|
|
268
|
+
title: string;
|
|
269
|
+
}>;
|
|
270
|
+
get: (requestId: string | number, options?: RequestOptions) => Promise<{
|
|
271
|
+
action: string;
|
|
272
|
+
approveUrl: string;
|
|
273
|
+
createdAt: string;
|
|
274
|
+
decidedAt: string | null;
|
|
275
|
+
expiresAt: string;
|
|
276
|
+
id: string;
|
|
277
|
+
input: {
|
|
278
|
+
[key: string]: unknown;
|
|
279
|
+
};
|
|
280
|
+
reason: string;
|
|
281
|
+
requestedBy: string | null;
|
|
282
|
+
result: {
|
|
283
|
+
[key: string]: unknown;
|
|
284
|
+
} | null;
|
|
285
|
+
secret: {
|
|
286
|
+
envVar: string;
|
|
287
|
+
name: string;
|
|
288
|
+
} | null;
|
|
289
|
+
status: "pending" | "approved" | "completed" | "denied" | "failed" | "expired";
|
|
290
|
+
summary: string;
|
|
291
|
+
title: string;
|
|
292
|
+
}>;
|
|
293
|
+
redeem: (requestId: string | number, options?: RequestOptions) => Promise<{
|
|
294
|
+
envVar: string | null;
|
|
295
|
+
request: import("./v1.gen.ts").components["schemas"]["ApprovalRequest"];
|
|
296
|
+
secret: string | null;
|
|
297
|
+
}>;
|
|
298
|
+
};
|
|
299
|
+
auditEvents: {
|
|
300
|
+
list: (input?: Input<"/workspace/audit-events", "get">, options?: RequestOptions) => Promise<{
|
|
301
|
+
items: import("./v1.gen.ts").components["schemas"]["AuditEvent"][];
|
|
302
|
+
nextCursor: string | null;
|
|
303
|
+
}>;
|
|
304
|
+
};
|
|
305
|
+
eventTypes: {
|
|
306
|
+
list: (options?: RequestOptions) => Promise<{
|
|
307
|
+
items: {
|
|
308
|
+
description: string;
|
|
309
|
+
type: string;
|
|
310
|
+
}[];
|
|
311
|
+
}>;
|
|
312
|
+
};
|
|
313
|
+
get: (options?: RequestOptions) => Promise<{
|
|
314
|
+
id: string;
|
|
315
|
+
name: string;
|
|
316
|
+
}>;
|
|
317
|
+
invitations: {
|
|
318
|
+
list: (input?: Input<"/workspace/invitations", "get">, options?: RequestOptions) => Promise<{
|
|
319
|
+
items: import("./v1.gen.ts").components["schemas"]["Invitation"][];
|
|
320
|
+
nextCursor: string | null;
|
|
321
|
+
}>;
|
|
322
|
+
};
|
|
323
|
+
members: {
|
|
324
|
+
list: (input?: Input<"/workspace/members", "get">, options?: RequestOptions) => Promise<{
|
|
325
|
+
items: import("./v1.gen.ts").components["schemas"]["Member"][];
|
|
326
|
+
nextCursor: string | null;
|
|
327
|
+
}>;
|
|
328
|
+
};
|
|
329
|
+
teams: {
|
|
330
|
+
list: (input?: Input<"/workspace/teams", "get">, options?: RequestOptions) => Promise<{
|
|
331
|
+
items: import("./v1.gen.ts").components["schemas"]["Team"][];
|
|
332
|
+
nextCursor: string | null;
|
|
333
|
+
}>;
|
|
334
|
+
};
|
|
335
|
+
usage: (options?: RequestOptions) => Promise<{
|
|
336
|
+
meters: {
|
|
337
|
+
description: string;
|
|
338
|
+
id: string;
|
|
339
|
+
limit: number | null;
|
|
340
|
+
used: number;
|
|
341
|
+
}[];
|
|
342
|
+
notices?: string[];
|
|
343
|
+
periodEnd: string;
|
|
344
|
+
periodStart: string;
|
|
345
|
+
}>;
|
|
346
|
+
webhookDeliveries: {
|
|
347
|
+
list: (endpointId: string | number, input?: Input<"/workspace/webhook-endpoints/{endpointId}/deliveries", "get">, options?: RequestOptions) => Promise<{
|
|
348
|
+
items: import("./v1.gen.ts").components["schemas"]["WebhookDelivery"][];
|
|
349
|
+
nextCursor: string | null;
|
|
350
|
+
}>;
|
|
351
|
+
redeliver: (endpointId: string | number, deliveryId: string | number, options?: RequestOptions) => Promise<{
|
|
352
|
+
deliveryId: string;
|
|
353
|
+
ok?: boolean;
|
|
354
|
+
queued: boolean;
|
|
355
|
+
status?: number | null;
|
|
356
|
+
}>;
|
|
357
|
+
};
|
|
358
|
+
webhookEndpoints: {
|
|
359
|
+
create: (input: Input<"/workspace/webhook-endpoints", "post">, options?: RequestOptions) => Promise<{
|
|
360
|
+
endpoint: import("./v1.gen.ts").components["schemas"]["WebhookEndpoint"];
|
|
361
|
+
secret: string;
|
|
362
|
+
}>;
|
|
363
|
+
delete: (endpointId: string | number, options?: RequestOptions) => Promise<undefined>;
|
|
364
|
+
enable: (endpointId: string | number, options?: RequestOptions) => Promise<{
|
|
365
|
+
consecutiveFailures: number;
|
|
366
|
+
createdAt: string;
|
|
367
|
+
description: string | null;
|
|
368
|
+
enabled: boolean;
|
|
369
|
+
environment: string | null;
|
|
370
|
+
eventTypes: string[] | null;
|
|
371
|
+
id: string;
|
|
372
|
+
lastAttemptAt: string | null;
|
|
373
|
+
lastStatus: number | null;
|
|
374
|
+
url: string;
|
|
375
|
+
}>;
|
|
376
|
+
get: (endpointId: string | number, options?: RequestOptions) => Promise<{
|
|
377
|
+
consecutiveFailures: number;
|
|
378
|
+
createdAt: string;
|
|
379
|
+
description: string | null;
|
|
380
|
+
enabled: boolean;
|
|
381
|
+
environment: string | null;
|
|
382
|
+
eventTypes: string[] | null;
|
|
383
|
+
id: string;
|
|
384
|
+
lastAttemptAt: string | null;
|
|
385
|
+
lastStatus: number | null;
|
|
386
|
+
url: string;
|
|
387
|
+
}>;
|
|
388
|
+
list: (options?: RequestOptions) => Promise<{
|
|
389
|
+
items: import("./v1.gen.ts").components["schemas"]["WebhookEndpoint"][];
|
|
390
|
+
nextCursor: string | null;
|
|
391
|
+
}>;
|
|
392
|
+
test: (endpointId: string | number, options?: RequestOptions) => Promise<{
|
|
393
|
+
deliveryId: string;
|
|
394
|
+
ok?: boolean;
|
|
395
|
+
queued: boolean;
|
|
396
|
+
status?: number | null;
|
|
397
|
+
}>;
|
|
398
|
+
};
|
|
399
|
+
};
|
|
400
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// GENERATED from apps/api/src/routes/v1 by `pnpm sdk:generate` — gitignored,
|
|
2
|
+
// regenerated by `pnpm generate` and by this package's typecheck / test /
|
|
3
|
+
// build. Do not edit; do not commit.
|
|
4
|
+
import { call } from "./resources.js";
|
|
5
|
+
/** The resource methods for a client (./resources.ts). */
|
|
6
|
+
export function resources(client) {
|
|
7
|
+
return {
|
|
8
|
+
checks: {
|
|
9
|
+
create: /** Check whether a subject may act */ (input, options) => call(client, { "method": "post", "path": "/checks", "query": [], "hasBody": true }, {}, input, options),
|
|
10
|
+
},
|
|
11
|
+
limits: {
|
|
12
|
+
archive: /** Archive a limit */ (limitId, options) => call(client, { "method": "post", "path": "/limits/{limitId}/archive", "query": [], "hasBody": false }, { "limitId": limitId }, undefined, options),
|
|
13
|
+
create: /** Create a limit */ (input, options) => call(client, { "method": "post", "path": "/limits", "query": [], "hasBody": true }, {}, input, options),
|
|
14
|
+
get: /** Get a limit */ (limitId, options) => call(client, { "method": "get", "path": "/limits/{limitId}", "query": [], "hasBody": false }, { "limitId": limitId }, undefined, options),
|
|
15
|
+
grants: {
|
|
16
|
+
create: /** Add credits to a balance */ (limitId, input, options) => call(client, { "method": "post", "path": "/limits/{limitId}/grants", "query": [], "hasBody": true }, { "limitId": limitId }, input, options),
|
|
17
|
+
list: /** List a balance's grants */ (limitId, options) => call(client, { "method": "get", "path": "/limits/{limitId}/grants", "query": [], "hasBody": false }, { "limitId": limitId }, undefined, options),
|
|
18
|
+
},
|
|
19
|
+
list: /** List limits */ (input, options) => call(client, { "method": "get", "path": "/limits", "query": ["limit", "cursor", "subjectKind", "action", "archived"], "hasBody": false }, {}, input, options),
|
|
20
|
+
restore: /** Restore an archived limit */ (limitId, options) => call(client, { "method": "post", "path": "/limits/{limitId}/restore", "query": [], "hasBody": false }, { "limitId": limitId }, undefined, options),
|
|
21
|
+
sync: /** Sync limits from a list */ (input, options) => call(client, { "method": "post", "path": "/limits/sync", "query": [], "hasBody": true }, {}, input, options),
|
|
22
|
+
update: /** Change a limit */ (limitId, input, options) => call(client, { "method": "patch", "path": "/limits/{limitId}", "query": [], "hasBody": true }, { "limitId": limitId }, input, options),
|
|
23
|
+
},
|
|
24
|
+
reservations: {
|
|
25
|
+
commit: /** Commit a reservation */ (reservationId, input, options) => call(client, { "method": "post", "path": "/reservations/{reservationId}/commit", "query": [], "hasBody": true }, { "reservationId": reservationId }, input, options),
|
|
26
|
+
extend: /** Extend a reservation */ (reservationId, input, options) => call(client, { "method": "post", "path": "/reservations/{reservationId}/extend", "query": [], "hasBody": true }, { "reservationId": reservationId }, input, options),
|
|
27
|
+
release: /** Release a reservation */ (reservationId, options) => call(client, { "method": "post", "path": "/reservations/{reservationId}/release", "query": [], "hasBody": false }, { "reservationId": reservationId }, undefined, options),
|
|
28
|
+
},
|
|
29
|
+
subjects: {
|
|
30
|
+
get: /** Get a subject */ (subjectKind, subjectId, options) => call(client, { "method": "get", "path": "/subjects/{subjectKind}/{subjectId}", "query": [], "hasBody": false }, { "subjectKind": subjectKind, "subjectId": subjectId }, undefined, options),
|
|
31
|
+
reset: /** Reset a subject's limits */ (subjectKind, subjectId, input, options) => call(client, { "method": "post", "path": "/subjects/{subjectKind}/{subjectId}/reset", "query": [], "hasBody": true }, { "subjectKind": subjectKind, "subjectId": subjectId }, input, options),
|
|
32
|
+
update: /** Set a subject's anchor */ (subjectKind, subjectId, input, options) => call(client, { "method": "patch", "path": "/subjects/{subjectKind}/{subjectId}", "query": [], "hasBody": true }, { "subjectKind": subjectKind, "subjectId": subjectId }, input, options),
|
|
33
|
+
},
|
|
34
|
+
usage: {
|
|
35
|
+
query: /** Get a limit's usage over time */ (input, options) => call(client, { "method": "get", "path": "/usage", "query": ["limitId", "subjectKind", "subjectId", "from", "to", "granularity"], "hasBody": false }, {}, input, options),
|
|
36
|
+
standing: /** Get where a subject stands */ (input, options) => call(client, { "method": "get", "path": "/usage/standing", "query": ["kind", "id", "shared"], "hasBody": false }, {}, input, options),
|
|
37
|
+
subjects: /** List who is using a limit now */ (input, options) => call(client, { "method": "get", "path": "/usage/subjects", "query": ["limitId", "limit"], "hasBody": false }, {}, input, options),
|
|
38
|
+
},
|
|
39
|
+
user: {
|
|
40
|
+
me: /** Get the current user */ (options) => call(client, { "method": "get", "path": "/user/me", "query": [], "hasBody": false }, {}, undefined, options),
|
|
41
|
+
revokeToken: /** Revoke the token making this request */ (options) => call(client, { "method": "delete", "path": "/user/token", "query": [], "hasBody": false }, {}, undefined, options),
|
|
42
|
+
},
|
|
43
|
+
workspace: {
|
|
44
|
+
approvalActions: {
|
|
45
|
+
list: /** List the actions you can ask approval for */ (options) => call(client, { "method": "get", "path": "/workspace/approval-actions", "query": [], "hasBody": false }, {}, undefined, options),
|
|
46
|
+
},
|
|
47
|
+
approvalRequests: {
|
|
48
|
+
create: /** Ask a person to approve an action */ (input, options) => call(client, { "method": "post", "path": "/workspace/approval-requests", "query": [], "hasBody": true }, {}, input, options),
|
|
49
|
+
get: /** Check an approval request */ (requestId, options) => call(client, { "method": "get", "path": "/workspace/approval-requests/{requestId}", "query": [], "hasBody": false }, { "requestId": requestId }, undefined, options),
|
|
50
|
+
redeem: /** Redeem an approved request */ (requestId, options) => call(client, { "method": "post", "path": "/workspace/approval-requests/{requestId}/redeem", "query": [], "hasBody": false }, { "requestId": requestId }, undefined, options),
|
|
51
|
+
},
|
|
52
|
+
auditEvents: {
|
|
53
|
+
list: /** List workspace audit events */ (input, options) => call(client, { "method": "get", "path": "/workspace/audit-events", "query": ["limit", "cursor"], "hasBody": false }, {}, input, options),
|
|
54
|
+
},
|
|
55
|
+
eventTypes: {
|
|
56
|
+
list: /** List event types */ (options) => call(client, { "method": "get", "path": "/workspace/event-types", "query": [], "hasBody": false }, {}, undefined, options),
|
|
57
|
+
},
|
|
58
|
+
get: /** Get the current workspace */ (options) => call(client, { "method": "get", "path": "/workspace", "query": [], "hasBody": false }, {}, undefined, options),
|
|
59
|
+
invitations: {
|
|
60
|
+
list: /** List pending invitations */ (input, options) => call(client, { "method": "get", "path": "/workspace/invitations", "query": ["limit", "cursor"], "hasBody": false }, {}, input, options),
|
|
61
|
+
},
|
|
62
|
+
members: {
|
|
63
|
+
list: /** List workspace members */ (input, options) => call(client, { "method": "get", "path": "/workspace/members", "query": ["limit", "cursor"], "hasBody": false }, {}, input, options),
|
|
64
|
+
},
|
|
65
|
+
teams: {
|
|
66
|
+
list: /** List teams */ (input, options) => call(client, { "method": "get", "path": "/workspace/teams", "query": ["limit", "cursor"], "hasBody": false }, {}, input, options),
|
|
67
|
+
},
|
|
68
|
+
usage: /** Get your plan's usage this period */ (options) => call(client, { "method": "get", "path": "/workspace/usage", "query": [], "hasBody": false }, {}, undefined, options),
|
|
69
|
+
webhookDeliveries: {
|
|
70
|
+
list: /** List an endpoint's deliveries */ (endpointId, input, options) => call(client, { "method": "get", "path": "/workspace/webhook-endpoints/{endpointId}/deliveries", "query": ["limit", "cursor"], "hasBody": false }, { "endpointId": endpointId }, input, options),
|
|
71
|
+
redeliver: /** Redeliver an event */ (endpointId, deliveryId, options) => call(client, { "method": "post", "path": "/workspace/webhook-endpoints/{endpointId}/deliveries/{deliveryId}/redeliver", "query": [], "hasBody": false }, { "endpointId": endpointId, "deliveryId": deliveryId }, undefined, options),
|
|
72
|
+
},
|
|
73
|
+
webhookEndpoints: {
|
|
74
|
+
create: /** Add a webhook endpoint */ (input, options) => call(client, { "method": "post", "path": "/workspace/webhook-endpoints", "query": [], "hasBody": true }, {}, input, options),
|
|
75
|
+
delete: /** Remove a webhook endpoint */ (endpointId, options) => call(client, { "method": "delete", "path": "/workspace/webhook-endpoints/{endpointId}", "query": [], "hasBody": false }, { "endpointId": endpointId }, undefined, options),
|
|
76
|
+
enable: /** Re-enable a webhook endpoint */ (endpointId, options) => call(client, { "method": "post", "path": "/workspace/webhook-endpoints/{endpointId}/enable", "query": [], "hasBody": false }, { "endpointId": endpointId }, undefined, options),
|
|
77
|
+
get: /** Get a webhook endpoint */ (endpointId, options) => call(client, { "method": "get", "path": "/workspace/webhook-endpoints/{endpointId}", "query": [], "hasBody": false }, { "endpointId": endpointId }, undefined, options),
|
|
78
|
+
list: /** List webhook endpoints */ (options) => call(client, { "method": "get", "path": "/workspace/webhook-endpoints", "query": [], "hasBody": false }, {}, undefined, options),
|
|
79
|
+
test: /** Send a test event */ (endpointId, options) => call(client, { "method": "post", "path": "/workspace/webhook-endpoints/{endpointId}/test", "query": [], "hasBody": false }, { "endpointId": endpointId }, undefined, options),
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { apiErrorFrom } from "./errors.js";
|
|
2
|
+
/** Makes the call; the data, or throws ApiError. */
|
|
3
|
+
export async function call(client, op, pathParams, input, options = {}, content) {
|
|
4
|
+
const query = {};
|
|
5
|
+
const body = {};
|
|
6
|
+
for (const [name, value] of Object.entries(input ?? {})) {
|
|
7
|
+
if (value === undefined)
|
|
8
|
+
continue;
|
|
9
|
+
(op.query.includes(name) ? query : body)[name] = value;
|
|
10
|
+
}
|
|
11
|
+
const headers = {
|
|
12
|
+
...options.headers,
|
|
13
|
+
...(options.idempotencyKey
|
|
14
|
+
? { "idempotency-key": options.idempotencyKey }
|
|
15
|
+
: {}),
|
|
16
|
+
};
|
|
17
|
+
const request = client.request;
|
|
18
|
+
// Raw bytes go as they are, typed by the Blob (else the route's type).
|
|
19
|
+
const raw = op.rawBody
|
|
20
|
+
? content instanceof Blob
|
|
21
|
+
? content
|
|
22
|
+
: new Blob([content])
|
|
23
|
+
: undefined;
|
|
24
|
+
const { data, error, response } = await request(op.method, op.path, {
|
|
25
|
+
params: { path: pathParams, query },
|
|
26
|
+
...(op.hasBody ? { body } : {}),
|
|
27
|
+
...(raw
|
|
28
|
+
? {
|
|
29
|
+
body: raw,
|
|
30
|
+
bodySerializer: (value) => value,
|
|
31
|
+
headers: { "content-type": raw.type || op.rawBody, ...headers },
|
|
32
|
+
}
|
|
33
|
+
: { headers }),
|
|
34
|
+
...(op.rawResponse ? { parseAs: "blob" } : {}),
|
|
35
|
+
});
|
|
36
|
+
if (error !== undefined || !response.ok) {
|
|
37
|
+
throw apiErrorFrom(error, response);
|
|
38
|
+
}
|
|
39
|
+
return data;
|
|
40
|
+
}
|
package/dist/retry.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safe retries, one rule for every client (the SDK, the CLI, the MCP
|
|
3
|
+
* server; docs/architecture.md "Idempotency"): a WRITE gets one
|
|
4
|
+
* Idempotency-Key per logical call, and every automatic retry of that
|
|
5
|
+
* call sends the same key, so the API runs it once however many times
|
|
6
|
+
* it is sent. Without a key a timed-out create that actually ran would
|
|
7
|
+
* run again on retry; with a fresh key per attempt it would too.
|
|
8
|
+
*
|
|
9
|
+
* Retried: a network failure, 408, 429, 500, 502, 503, 504, and 409
|
|
10
|
+
* `idempotency_in_progress` (the first attempt is still running). Waits
|
|
11
|
+
* the response's Retry-After when it gives one, else a jittered backoff
|
|
12
|
+
* (0.5s, 1s, … capped at 8s); a Retry-After longer than MAX_WAIT_MS is
|
|
13
|
+
* handed back to the caller rather than slept through. A request whose
|
|
14
|
+
* own signal aborted (a caller's timeout) is never retried: the caller
|
|
15
|
+
* decided.
|
|
16
|
+
*/
|
|
17
|
+
export declare const DEFAULT_MAX_RETRIES = 2;
|
|
18
|
+
export declare const MAX_WAIT_MS = 20000;
|
|
19
|
+
/** The longest key a caller may pass where a client derives keys from it. */
|
|
20
|
+
export declare const MAX_BASE_KEY = 200;
|
|
21
|
+
type Fetch = (request: Request) => Promise<Response>;
|
|
22
|
+
export type RetryOptions = {
|
|
23
|
+
/** Retries after the first attempt (default 2; 0 = never retry). */
|
|
24
|
+
maxRetries?: number;
|
|
25
|
+
/** The key for a write that has none (default: a random UUID). */
|
|
26
|
+
key?: (method: string, path: string) => string | Promise<string>;
|
|
27
|
+
/** Waits (tests pass a fake). */
|
|
28
|
+
sleep?: (ms: number) => Promise<void>;
|
|
29
|
+
};
|
|
30
|
+
/** `fetch` with the rule above. Each request is one logical call. */
|
|
31
|
+
export declare function withRetries(fetch: Fetch, options?: RetryOptions): Fetch;
|
|
32
|
+
/**
|
|
33
|
+
* Keys for a command or tool call that may make several writes, from
|
|
34
|
+
* one key its caller chose (`--idempotency-key`, an MCP tool's
|
|
35
|
+
* `idempotencyKey`): each write gets `<key>:<16 hex>`, a digest of its
|
|
36
|
+
* method, path and how many times the call wrote there before — so the
|
|
37
|
+
* same call run again sends the same keys, write for write, and a write
|
|
38
|
+
* it skips the second time shifts no other write's key. Without a key,
|
|
39
|
+
* a fresh UUID per write.
|
|
40
|
+
*/
|
|
41
|
+
export declare function keysFrom(base: string | undefined): (method: string, path: string) => Promise<string>;
|
|
42
|
+
export {};
|