@retainer/sdk 0.0.0-stage → 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/dist/index.js ADDED
@@ -0,0 +1,748 @@
1
+ import { isMaintenance, maintenanceFetch } from './maintenance.js';
2
+ export { isMaintenance, retryAfterMs, waitForRetry } from './maintenance.js';
3
+ export class RetainerApiError extends Error {
4
+ status;
5
+ code;
6
+ details;
7
+ constructor(status, code, message, details) {
8
+ super(message);
9
+ this.status = status;
10
+ this.code = code;
11
+ this.details = details;
12
+ this.name = 'RetainerApiError';
13
+ }
14
+ }
15
+ const isFailedChange = (body) => typeof body === 'object' && body !== null && body.status === 'failed';
16
+ export class RetainerClient {
17
+ options;
18
+ baseUrl;
19
+ fetchImpl;
20
+ constructor(options) {
21
+ this.options = options;
22
+ this.baseUrl = options.baseUrl.replace(/\/+$/, '');
23
+ const fetcher = options.fetch ?? globalThis.fetch.bind(globalThis);
24
+ this.fetchImpl = (input, init) => maintenanceFetch(fetcher, input, init);
25
+ }
26
+ headers() {
27
+ if (this.options.accessToken) {
28
+ return {
29
+ authorization: `Bearer ${this.options.accessToken}`,
30
+ ...(this.options.workspace ? { 'X-Retainer-Workspace': this.options.workspace } : {}),
31
+ ...(this.options.approval ? { 'X-Retainer-Approval': this.options.approval } : {}),
32
+ };
33
+ }
34
+ if (this.options.apiKey)
35
+ return { authorization: `Bearer ${this.options.apiKey}` };
36
+ return this.options.workspace
37
+ ? { 'X-Retainer-Client': 'web', 'X-Retainer-Workspace': this.options.workspace }
38
+ : { 'X-Retainer-Client': 'web' };
39
+ }
40
+ /** `isResult` lets an error status whose body is a result come back as one. */
41
+ async request(path, init = {}, isResult) {
42
+ const response = await this.fetchImpl(`${this.baseUrl}${path}`, {
43
+ ...init,
44
+ credentials: this.options.credentials ?? 'same-origin',
45
+ headers: {
46
+ ...this.headers(),
47
+ ...(init.body ? { 'content-type': 'application/json' } : {}),
48
+ ...init.headers,
49
+ },
50
+ });
51
+ if (response.status === 204)
52
+ return undefined;
53
+ const body = (await response.json());
54
+ if (!response.ok && !isResult?.(body)) {
55
+ if (response.status === 401 && path !== '/auth/session')
56
+ this.options.onUnauthorized?.();
57
+ throw new RetainerApiError(response.status, body.error?.code ?? 'request_failed', body.error?.message ?? response.statusText, body.error?.details);
58
+ }
59
+ return body;
60
+ }
61
+ query(path, params, signal) {
62
+ const qs = new URLSearchParams();
63
+ for (const [k, v] of Object.entries(params))
64
+ if (v !== undefined)
65
+ qs.set(k, String(v));
66
+ return { path: `${path}${qs.size ? `?${qs}` : ''}`, signal };
67
+ }
68
+ get(path, params = {}, signal) {
69
+ const q = this.query(path, params, signal);
70
+ return this.request(q.path, { signal });
71
+ }
72
+ send(method, path, body, signal, idempotencyKey) {
73
+ return this.request(path, {
74
+ method,
75
+ body: body === undefined ? undefined : JSON.stringify(body),
76
+ signal,
77
+ headers: idempotencyKey ? { 'idempotency-key': idempotencyKey } : {},
78
+ });
79
+ }
80
+ post(path, body, signal, idempotencyKey) {
81
+ return this.send('POST', path, body, signal, idempotencyKey);
82
+ }
83
+ /** Health reports database outages in its response body, including HTTP 503. */
84
+ async health() {
85
+ const response = await this.fetchImpl(`${this.baseUrl}/health`);
86
+ if (await isMaintenance(response)) {
87
+ throw new RetainerApiError(503, 'maintenance', 'Retainer is updating. Please retry shortly.');
88
+ }
89
+ return (await response.json());
90
+ }
91
+ signIn(key) {
92
+ return this.post('/auth/session', { key });
93
+ }
94
+ signOut() {
95
+ return this.request('/auth/session', { method: 'DELETE' });
96
+ }
97
+ me(signal) {
98
+ return this.get('/v1/me', {}, signal);
99
+ }
100
+ schema(signal) {
101
+ return this.get('/v1/schema', {}, signal);
102
+ }
103
+ templates(signal) {
104
+ return this.get('/v1/templates', {}, signal);
105
+ }
106
+ applyTemplate(name) {
107
+ return this.post(`/v1/templates/${encodeURIComponent(name)}/apply`);
108
+ }
109
+ queryRecords(object, input = {}, signal) {
110
+ return this.post(`/v1/objects/${encodeURIComponent(object)}/query`, input, signal);
111
+ }
112
+ record(id, include = ['provenance', 'relationReferences'], signal) {
113
+ return this.get(`/v1/records/${encodeURIComponent(id)}`, { include: include.join(',') }, signal);
114
+ }
115
+ linkedRecords(id, options = {}) {
116
+ const { signal, ...query } = options;
117
+ return this.get(`/v1/records/${encodeURIComponent(id)}/linked`, query, signal);
118
+ }
119
+ createRecord(object, input, idempotencyKey) {
120
+ return this.post(`/v1/objects/${encodeURIComponent(object)}/records`, input, undefined, idempotencyKey);
121
+ }
122
+ upsertRecord(object, input) {
123
+ return this.post(`/v1/objects/${encodeURIComponent(object)}/upsert`, input);
124
+ }
125
+ patchRecord(id, input) {
126
+ return this.request(`/v1/records/${encodeURIComponent(id)}`, {
127
+ method: 'PATCH',
128
+ body: JSON.stringify(input),
129
+ });
130
+ }
131
+ /** What deleting the record would delete with it; changes nothing. */
132
+ deleteImpact(id, signal) {
133
+ return this.get(`/v1/records/${encodeURIComponent(id)}/delete-impact`, {}, signal);
134
+ }
135
+ /** What deleting several records together would delete with them. */
136
+ bulkDeleteImpact(ids, signal) {
137
+ return this.post('/v1/records/delete-impact', { ids }, signal);
138
+ }
139
+ /** The total and requested aggregates over the records a filter matches. */
140
+ aggregate(object, input = {}, signal) {
141
+ return this.post(`/v1/objects/${encodeURIComponent(object)}/aggregate`, input, signal);
142
+ }
143
+ deleteRecord(id, bindings) {
144
+ return this.request(`/v1/records/${encodeURIComponent(id)}`, {
145
+ method: 'DELETE',
146
+ ...(bindings ? { body: JSON.stringify({ bindings }) } : {}),
147
+ });
148
+ }
149
+ /** The object's saved views the caller can see, in their saved order. */
150
+ views(object, signal) {
151
+ return this.get(`/v1/objects/${encodeURIComponent(object)}/views`, {}, signal);
152
+ }
153
+ view(id, signal) {
154
+ return this.get(`/v1/views/${encodeURIComponent(id)}`, {}, signal);
155
+ }
156
+ createView(object, input) {
157
+ return this.post(`/v1/objects/${encodeURIComponent(object)}/views`, input);
158
+ }
159
+ /** Changes only the keys given; `null` clears a setting. */
160
+ updateView(id, input) {
161
+ return this.request(`/v1/views/${encodeURIComponent(id)}`, {
162
+ method: 'PATCH',
163
+ body: JSON.stringify(input),
164
+ });
165
+ }
166
+ deleteView(id) {
167
+ return this.request(`/v1/views/${encodeURIComponent(id)}`, {
168
+ method: 'DELETE',
169
+ });
170
+ }
171
+ /** Merges `input.recordId` into `id`, which survives. Retrying with the same key is safe. */
172
+ mergeRecords(id, input, idempotencyKey) {
173
+ return this.post(`/v1/records/${encodeURIComponent(id)}/merge`, input, undefined, idempotencyKey);
174
+ }
175
+ /**
176
+ * Deletes the signed-in person's personal memory in this workspace (4.6):
177
+ * web sessions only; agents cannot clear it.
178
+ */
179
+ clearMyMemory() {
180
+ return this.post('/v1/records/me/forget');
181
+ }
182
+ /** Erases a person and what was logged about them (needs the `admin` scope). Not reversible. */
183
+ forget(id) {
184
+ return this.post(`/v1/records/${encodeURIComponent(id)}/forget`);
185
+ }
186
+ search(input, signal) {
187
+ return this.post('/v1/search', input, signal);
188
+ }
189
+ context(id, input = {}, signal) {
190
+ return this.get(`/v1/records/${encodeURIComponent(id)}/context`, input, signal);
191
+ }
192
+ mergeSuggestion(id, keep) {
193
+ return this.post(`/v1/review/merges/${encodeURIComponent(id)}/merge`, { keep });
194
+ }
195
+ dismissMergeSuggestion(id) {
196
+ return this.post(`/v1/review/merges/${encodeURIComponent(id)}/dismiss`);
197
+ }
198
+ review(options = {}) {
199
+ const { signal, ...params } = options;
200
+ return this.get('/v1/review', params, signal);
201
+ }
202
+ assertion(id, signal) {
203
+ return this.get(`/v1/assertions/${encodeURIComponent(id)}`, {}, signal);
204
+ }
205
+ decideAssertion(id, decision) {
206
+ return this.post(`/v1/assertions/${encodeURIComponent(id)}/${decision}`);
207
+ }
208
+ assertions(id, options = {}) {
209
+ const { signal, ...params } = options;
210
+ return this.get(`/v1/records/${encodeURIComponent(id)}/assertions`, params, signal);
211
+ }
212
+ /**
213
+ * Events attached directly to a record, newest first, each with how it is
214
+ * attached (`via`). `link` narrows to participant, about or field.
215
+ */
216
+ recordEvents(id, options = {}) {
217
+ const { signal, ...params } = options;
218
+ return this.get(`/v1/records/${encodeURIComponent(id)}/events`, params, signal);
219
+ }
220
+ /**
221
+ * A record's timeline (8): events (direct and rolled up, with `via`),
222
+ * values asserted for its fields and its facts, newest first. Filters for
223
+ * one kind (`fields`, `eventTypes`) leave the others out unless `types`
224
+ * names them.
225
+ */
226
+ timeline(id, options = {}) {
227
+ const { signal, types, fields, eventTypes, ...params } = options;
228
+ return this.get(`/v1/records/${encodeURIComponent(id)}/timeline`, {
229
+ ...params,
230
+ types: types?.join(','),
231
+ fields: fields?.join(','),
232
+ eventTypes: eventTypes?.join(','),
233
+ }, signal);
234
+ }
235
+ /**
236
+ * A record's current facts, or a profile's: `workspace` for workspace
237
+ * memory, `me` for the caller's personal memory (personal memory spec 4.4).
238
+ */
239
+ facts(id, options = {}) {
240
+ const { signal, ...params } = options;
241
+ return this.get(`/v1/records/${encodeURIComponent(id)}/facts`, params, signal);
242
+ }
243
+ /**
244
+ * Adds a fact to a record or a profile (`workspace`, `me`). `supersedes`
245
+ * replaces a current fact: on the same record it corrects it, elsewhere it
246
+ * moves it (4.9).
247
+ */
248
+ remember(id, input, idempotencyKey) {
249
+ return this.post(`/v1/records/${encodeURIComponent(id)}/facts`, input, undefined, idempotencyKey);
250
+ }
251
+ retractFact(id) {
252
+ return this.request(`/v1/facts/${encodeURIComponent(id)}`, {
253
+ method: 'DELETE',
254
+ });
255
+ }
256
+ /** A record's comments, newest first, with their total. A merged ID follows the merge. */
257
+ listComments(id, options = {}) {
258
+ const { signal, ...params } = options;
259
+ return this.get(`/v1/records/${encodeURIComponent(id)}/comments`, params, signal);
260
+ }
261
+ /** Adds a comment (a `user` key only). Retrying with the same key adds it once. */
262
+ addComment(id, input, idempotencyKey) {
263
+ return this.post(`/v1/records/${encodeURIComponent(id)}/comments`, input, undefined, idempotencyKey);
264
+ }
265
+ /** Edits a comment's body; its author only. */
266
+ editComment(id, input, idempotencyKey) {
267
+ return this.send('PATCH', `/v1/comments/${encodeURIComponent(id)}`, input, undefined, idempotencyKey);
268
+ }
269
+ /** Deletes a comment; its author, or a `user` key with `admin`. */
270
+ deleteComment(id, idempotencyKey) {
271
+ return this.send('DELETE', `/v1/comments/${encodeURIComponent(id)}`, undefined, undefined, idempotencyKey);
272
+ }
273
+ /** One live event: the record with its built-in columns and links. */
274
+ event(id, signal) {
275
+ return this.get(`/v1/events/${encodeURIComponent(id)}`, {}, signal);
276
+ }
277
+ /** Events, new records and grouped record writes, newest added first. */
278
+ workspaceFeed(input = {}, signal) {
279
+ return this.post('/v1/feed/query', input, signal);
280
+ }
281
+ /**
282
+ * Events of every event type in one page, newest first (`POST /v1/events/query`).
283
+ * Filters take `type`, `occurredAt`, `channel` and `externalId`; `linked` finds
284
+ * the events attached to one record.
285
+ */
286
+ queryEvents(input = {}, signal) {
287
+ return this.post('/v1/events/query', input, signal);
288
+ }
289
+ /**
290
+ * Logs an event; idempotent by channel and externalId. After creating an
291
+ * unmatched person, re-log with the same handle/role and their recordId.
292
+ * `added.participants.matched` includes participants resolved in place.
293
+ */
294
+ logEvent(input) {
295
+ return this.post('/v1/events', input);
296
+ }
297
+ /**
298
+ * Moves events to another event type, keeping their IDs, identities, links
299
+ * and the claims that cite them (`POST /v1/events/move`). Moving needs a
300
+ * `user` key with the `admin` scope; `dryRun: true` reports the plan with
301
+ * `schema:write` and changes nothing.
302
+ */
303
+ moveEvents(input) {
304
+ return this.post('/v1/events/move', input);
305
+ }
306
+ /**
307
+ * Adds links and retries eligible unmatched participants in place; idempotent.
308
+ * Successful resolutions are included in `added.participants.matched`.
309
+ */
310
+ addEventLinks(id, input) {
311
+ return this.post(`/v1/events/${encodeURIComponent(id)}/links`, input);
312
+ }
313
+ /** Removes one participant (a person's key only). */
314
+ removeParticipant(id, participantId) {
315
+ return this.request(`/v1/events/${encodeURIComponent(id)}/participants/${encodeURIComponent(participantId)}`, { method: 'DELETE' });
316
+ }
317
+ /** Removes a record from an event's `about` list (a person's key only). */
318
+ removeAbout(id, recordId) {
319
+ return this.request(`/v1/events/${encodeURIComponent(id)}/about/${encodeURIComponent(recordId)}`, { method: 'DELETE' });
320
+ }
321
+ /** Deletes an event and retracts the claims that cite it. */
322
+ deleteEvent(id, bindings) {
323
+ return this.request(`/v1/events/${encodeURIComponent(id)}`, {
324
+ method: 'DELETE',
325
+ ...(bindings ? { body: JSON.stringify({ bindings }) } : {}),
326
+ });
327
+ }
328
+ claims(id, options = {}) {
329
+ const { signal, ...params } = options;
330
+ return this.get(`/v1/events/${encodeURIComponent(id)}/claims`, params, signal);
331
+ }
332
+ fileErasureStatus(ids) {
333
+ return this.post('/v1/files/erasure-status', { ids });
334
+ }
335
+ createFileIntent(input, idempotencyKey) {
336
+ return this.post('/v1/files/intents', input, undefined, idempotencyKey);
337
+ }
338
+ finalizeFile(id) {
339
+ return this.post(`/v1/files/${encodeURIComponent(id)}/finalize`);
340
+ }
341
+ file(id, signal) {
342
+ return this.get(`/v1/files/${encodeURIComponent(id)}`, {}, signal);
343
+ }
344
+ downloadFile(id) {
345
+ return this.post(`/v1/files/${encodeURIComponent(id)}/download`);
346
+ }
347
+ extensionCatalog(signal) {
348
+ return this.get('/v1/extensions/catalog', {}, signal);
349
+ }
350
+ verifySource(installationId, input) {
351
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/source/verify`, input);
352
+ }
353
+ reserveSourceItem(installationId, input) {
354
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/source-items`, input);
355
+ }
356
+ sourceConnection(installationId) {
357
+ return this.get(`/v1/extensions/${encodeURIComponent(installationId)}/source`);
358
+ }
359
+ sourceSyncStatus(installationId, signal) {
360
+ return this.get(`/v1/extensions/${encodeURIComponent(installationId)}/source-sync`, {}, signal);
361
+ }
362
+ beginSourceScan(installationId, input) {
363
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/source-sync`, input);
364
+ }
365
+ reserveSourceItems(installationId, input) {
366
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/source-items/batch`, input);
367
+ }
368
+ sourceItem(installationId, itemId) {
369
+ return this.get(`/v1/extensions/${encodeURIComponent(installationId)}/source-items/${encodeURIComponent(itemId)}`);
370
+ }
371
+ changes(input = {}) {
372
+ const { signal, ...params } = input;
373
+ return this.get('/v1/changes', params, signal);
374
+ }
375
+ change(position, signal) {
376
+ return this.get(`/v1/changes/${encodeURIComponent(position)}`, {}, signal);
377
+ }
378
+ gmailImportWindow(installationId) {
379
+ return this.get(`/v1/extensions/${encodeURIComponent(installationId)}/runtime/gmail/window`);
380
+ }
381
+ gmailTarget(installationId, additionId, complete = false) {
382
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/runtime/gmail/target`, {
383
+ additionId,
384
+ complete,
385
+ });
386
+ }
387
+ releaseGmailConnection(installationId) {
388
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/runtime/gmail/release`, {});
389
+ }
390
+ prepareGmailMessage(installationId, input) {
391
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/runtime/gmail/prepare`, input);
392
+ }
393
+ appendGmailMessage(installationId, input) {
394
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/runtime/gmail/messages`, input);
395
+ }
396
+ /** The full text behind an event (an email's body, a transcript), or its thread's, oldest first. */
397
+ eventContent(eventId, after, signal) {
398
+ return this.get(`/v1/events/${encodeURIComponent(eventId)}/content`, { after }, signal);
399
+ }
400
+ prepareSourceItem(installationId, itemId, participants) {
401
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/source-items/${encodeURIComponent(itemId)}/prepare`, { participants });
402
+ }
403
+ markSourceUnavailable(installationId, itemId, input) {
404
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/source-items/${encodeURIComponent(itemId)}/unavailable`, input);
405
+ }
406
+ sourceRecoveryItems(installationId, options = {}) {
407
+ const { signal, ...params } = options;
408
+ return this.get(`/v1/extensions/${encodeURIComponent(installationId)}/source-items`, params, signal);
409
+ }
410
+ syncSourceEvent(installationId, input) {
411
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/source-events`, input);
412
+ }
413
+ sourceTaskSchema(installationId) {
414
+ return this.get(`/v1/extensions/${encodeURIComponent(installationId)}/source-tasks/schema`);
415
+ }
416
+ syncSourceTasks(installationId, itemId, input) {
417
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/source-items/${encodeURIComponent(itemId)}/tasks`, input);
418
+ }
419
+ disconnectSource(installationId) {
420
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/source/disconnect`);
421
+ }
422
+ extensions(signal) {
423
+ return this.get('/v1/extensions', {}, signal);
424
+ }
425
+ /** Standalone apps' sidebar links for the workspace's members (extensions spec 8). */
426
+ extensionLinks(signal) {
427
+ return this.get('/v1/extensions/links', {}, signal);
428
+ }
429
+ /**
430
+ * A standalone app's own credential writes its installation's generated
431
+ * secret, with revision CAS (extensions spec 8). A `409 revision_conflict`
432
+ * carries the current revision in its details, never the value.
433
+ */
434
+ writeGeneratedSecret(installationId, name, input) {
435
+ return this.send('PUT', `/v1/extensions/${encodeURIComponent(installationId)}/generated-secrets/${encodeURIComponent(name)}`, input);
436
+ }
437
+ extension(id, signal) {
438
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}`, {}, signal);
439
+ }
440
+ extensionBindings(id, signal) {
441
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/bindings`, {}, signal);
442
+ }
443
+ previewExtension(input) {
444
+ return this.post('/v1/extensions/preview', input);
445
+ }
446
+ installExtension(input, idempotencyKey) {
447
+ return this.post('/v1/extensions', input, undefined, idempotencyKey);
448
+ }
449
+ extensionConnections(id, signal) {
450
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/connections`, {}, signal);
451
+ }
452
+ authorizeGmail(id, historyDays) {
453
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/connections/gmail/authorize`, {
454
+ shareGmail: true,
455
+ historyDays,
456
+ });
457
+ }
458
+ finishGmailAuthorization(id, attemptId) {
459
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/connections/gmail/complete`, { attemptId });
460
+ }
461
+ stageExtensionConnectionSecret(id, input) {
462
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/connections/secrets`, input);
463
+ }
464
+ connectExtension(id, input) {
465
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/connections`, input);
466
+ }
467
+ /** Start an OAuth connection; navigate the browser to `authorizationUrl`. */
468
+ authorizeExtensionConnection(id, input) {
469
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/connections/authorize`, input);
470
+ }
471
+ /** Finish the OAuth round trip from the callback page, with the provider's code or error. */
472
+ completeExtensionAuthorization(id, input) {
473
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/connections/authorize/complete`, input);
474
+ }
475
+ /** Hide the release notice the member saw; `at` is `releaseNotice.at`, unchanged. */
476
+ dismissReleaseNotice(id, connection, at) {
477
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/connections/${encodeURIComponent(connection)}/release-notice/dismiss`, { at });
478
+ }
479
+ /** The operator's OAuth client, for a live run whose function holds the token secret. */
480
+ extensionOAuthClient(id) {
481
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/runtime/oauth-client`);
482
+ }
483
+ disconnectExtension(id, connection) {
484
+ return this.send('DELETE', `/v1/extensions/${encodeURIComponent(id)}/connections/${encodeURIComponent(connection)}`);
485
+ }
486
+ extensionRuns(id, options = {}) {
487
+ const { signal, ...params } = options;
488
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/runs`, params, signal);
489
+ }
490
+ retryExtensionRun(id, runId, idempotencyKey) {
491
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/runs/${encodeURIComponent(runId)}/retry`, undefined, undefined, idempotencyKey);
492
+ }
493
+ upgradeExtension(id, input, idempotencyKey) {
494
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/upgrade`, { ...input, installationId: id }, undefined, idempotencyKey);
495
+ }
496
+ reconnectExtension(id, connectionOrInput, inputOrKey) {
497
+ if (typeof connectionOrInput === 'string' && typeof inputOrKey !== 'string')
498
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/connections/${encodeURIComponent(connectionOrInput)}/reconnect`, inputOrKey);
499
+ if (typeof connectionOrInput !== 'string' && typeof inputOrKey === 'string')
500
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/reconnect`, connectionOrInput, undefined, inputOrKey);
501
+ throw new TypeError('invalid reconnect arguments');
502
+ }
503
+ updateExtensionSettings(id, input) {
504
+ return this.send('PATCH', `/v1/extensions/${encodeURIComponent(id)}/settings`, input);
505
+ }
506
+ enableExtension(id) {
507
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/enable`);
508
+ }
509
+ stageExtensionSecret(input) {
510
+ return this.post('/v1/extensions/secrets', input);
511
+ }
512
+ /**
513
+ * The fill-only mapped write of a run whose function declares `mappedWrite`:
514
+ * fills only mapped fields that have no value and were not cleared. A
515
+ * `confidence` below the workspace's threshold holds the values for review
516
+ * (agent actors only).
517
+ */
518
+ extensionMappedWrite(installationId, input) {
519
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/runtime/mapped-writes`, input);
520
+ }
521
+ /**
522
+ * Queue child jobs and compare-and-set one KV value, all or nothing. A KV
523
+ * value can't be JSON `null` (422 `invalid_input`): a missing key reads as
524
+ * null, and KV has no delete.
525
+ */
526
+ extensionCheckpoint(id, input) {
527
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/runtime/checkpoint`, input);
528
+ }
529
+ extensionKv(id, key) {
530
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/runtime/kv/${encodeURIComponent(key)}`);
531
+ }
532
+ extensionSecret(id, name) {
533
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/runtime/secrets/${encodeURIComponent(name)}`);
534
+ }
535
+ /** Store provider-generated signing/refresh material with revision CAS; live runs only. */
536
+ setExtensionSecret(id, name, input) {
537
+ return this.request(`/v1/extensions/${encodeURIComponent(id)}/runtime/secrets/${encodeURIComponent(name)}`, { method: 'PUT', body: JSON.stringify(input) });
538
+ }
539
+ /** Recompute only the release-pinned last-contact fields. Values, provenance and actor are server-derived. */
540
+ reconcileLastContact(id, input) {
541
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/runtime/last-contact`, input);
542
+ }
543
+ /** Reserve a durable callback before provider registration returns its signing material. Setup only. */
544
+ prepareExtensionWebhook(id, input) {
545
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/runtime/webhooks/prepare`, input);
546
+ }
547
+ retireExtensionWebhook(id, input) {
548
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/runtime/webhooks/retire`, input);
549
+ }
550
+ /** Registered setup verifier only, after attesting its provider source account. */
551
+ bindExtensionWebhook(id, input) {
552
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/runtime/webhooks`, input);
553
+ }
554
+ extensionWebhooks(id) {
555
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/runtime/webhooks`);
556
+ }
557
+ extensionCredentials(id, signal) {
558
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/credentials`, {}, signal);
559
+ }
560
+ createExtensionKey(id, input) {
561
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/keys`, input);
562
+ }
563
+ revokeExtensionCredential(id, credentialId) {
564
+ return this.request(`/v1/extensions/${encodeURIComponent(id)}/credentials/${encodeURIComponent(credentialId)}`, { method: 'DELETE' });
565
+ }
566
+ disableExtension(id) {
567
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/disable`);
568
+ }
569
+ cancelExtensionSuggestions(id, version) {
570
+ const query = version ? `?version=${encodeURIComponent(version)}` : '';
571
+ return this.send('DELETE', `/v1/extensions/${encodeURIComponent(id)}/suggestions${query}`);
572
+ }
573
+ configureExtension(id, version) {
574
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/configure`, {
575
+ version,
576
+ });
577
+ }
578
+ /** An installation's model use this calendar month (UTC). */
579
+ extensionUsage(id, signal) {
580
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/usage`, undefined, signal);
581
+ }
582
+ extensionSuggestions(id, version, signal) {
583
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/suggestions`, { version }, signal);
584
+ }
585
+ saveExtensionSuggestions(id, input) {
586
+ return this.send('PUT', `/v1/extensions/${encodeURIComponent(id)}/runtime/suggestions`, input);
587
+ }
588
+ turnOnExtension(id, input, key) {
589
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/turn-on`, input, undefined, key);
590
+ }
591
+ approveExtensionAccess(id, input, key) {
592
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/access`, input, undefined, key);
593
+ }
594
+ uninstallExtension(id) {
595
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/uninstall`);
596
+ }
597
+ schemaChanges(options = {}) {
598
+ const { signal, ...params } = options;
599
+ return this.get('/v1/schema/changes', params, signal);
600
+ }
601
+ schemaChange(id, signal) {
602
+ return this.get(`/v1/schema/changes/${encodeURIComponent(id)}`, {}, signal);
603
+ }
604
+ /**
605
+ * A change that existing records block comes back as 409 with the change
606
+ * itself (`status: "failed"`, its `error` and the blocking `recordIds`),
607
+ * so it is returned like any other outcome rather than thrown.
608
+ */
609
+ proposeSchemaChange(operations, reason) {
610
+ return this.request('/v1/schema/changes', { method: 'POST', body: JSON.stringify({ operations, reason }) }, isFailedChange);
611
+ }
612
+ decideSchemaChange(id, decision) {
613
+ return this.request(`/v1/schema/changes/${encodeURIComponent(id)}/${decision}`, { method: 'POST' }, isFailedChange);
614
+ }
615
+ // Routines (routines spec §5, §6).
616
+ routineCapabilities(signal) {
617
+ return this.get('/v1/routines/capabilities', {}, signal);
618
+ }
619
+ /** Checks a routine; `wait` seconds for the sandbox's type-check before answering with a job. */
620
+ validateRoutine(input, wait = 15) {
621
+ return this.post(`/v1/routines/validate?wait=${wait}`, input);
622
+ }
623
+ previewRoutine(input) {
624
+ return this.post('/v1/routines/preview', input);
625
+ }
626
+ routinePreview(previewId, signal) {
627
+ return this.get(`/v1/routines/previews/${encodeURIComponent(previewId)}`, {}, signal);
628
+ }
629
+ routineJob(jobId, signal) {
630
+ return this.get(`/v1/routines/jobs/${encodeURIComponent(jobId)}`, {}, signal);
631
+ }
632
+ /** Asks the built-in builder for a routine from a description; poll the job. */
633
+ buildRoutine(description, routineId) {
634
+ return this.post('/v1/routines/build', {
635
+ description,
636
+ ...(routineId ? { routineId } : {}),
637
+ });
638
+ }
639
+ proposeRoutine(input) {
640
+ return this.post('/v1/routines', input);
641
+ }
642
+ routines(signal) {
643
+ return this.get('/v1/routines', {}, signal);
644
+ }
645
+ routine(id, signal) {
646
+ return this.get(`/v1/routines/${encodeURIComponent(id)}`, {}, signal);
647
+ }
648
+ routineRun(id, runId, signal) {
649
+ return this.get(`/v1/routines/${encodeURIComponent(id)}/runs/${encodeURIComponent(runId)}`, {}, signal);
650
+ }
651
+ decideRoutineVersion(id, versionId, decision) {
652
+ return this.post(`/v1/routines/${encodeURIComponent(id)}/versions/${encodeURIComponent(versionId)}/${decision}`, {});
653
+ }
654
+ /** Runs a version once for real, on one record, as the admin who asks. */
655
+ testRoutine(id, versionId, recordId) {
656
+ return this.post(`/v1/routines/${encodeURIComponent(id)}/versions/${encodeURIComponent(versionId)}/test`, { recordId });
657
+ }
658
+ setRoutineState(id, action) {
659
+ return this.post(`/v1/routines/${encodeURIComponent(id)}/${action}`, {});
660
+ }
661
+ releaseHeldRuns(id, action) {
662
+ return this.post(`/v1/routines/${encodeURIComponent(id)}/held`, {
663
+ action,
664
+ });
665
+ }
666
+ /** Runs an active schedule routine's tick now; its regular schedule is unchanged. */
667
+ runRoutineNow(id) {
668
+ return this.post(`/v1/routines/${encodeURIComponent(id)}/run-now`, {});
669
+ }
670
+ runRoutine(id, recordIds) {
671
+ return this.post(`/v1/routines/${encodeURIComponent(id)}/run`, {
672
+ recordIds,
673
+ });
674
+ }
675
+ routineButtons(object, signal) {
676
+ return this.get('/v1/routines/buttons', { object }, signal);
677
+ }
678
+ setTimeZone(timeZone) {
679
+ return this.send('PUT', '/v1/workspace/time-zone', { timeZone });
680
+ }
681
+ }
682
+ const ws = (id) => `/account/workspaces/${encodeURIComponent(id)}`;
683
+ const org = (id) => `/account/organizations/${encodeURIComponent(id)}`;
684
+ const approval = (id) => `/account/cli/approvals/${encodeURIComponent(id)}`;
685
+ export class RetainerAccountClient extends RetainerClient {
686
+ account() {
687
+ return this.get('/account');
688
+ }
689
+ organization(id) {
690
+ return this.get(org(id));
691
+ }
692
+ invitations(id) {
693
+ return this.get(`${org(id)}/invitations`);
694
+ }
695
+ invite(id, input) {
696
+ return this.send('POST', `${org(id)}/invitations`, input);
697
+ }
698
+ revokeInvitation(id, invitationId) {
699
+ return this.send('DELETE', `${org(id)}/invitations/${encodeURIComponent(invitationId)}`);
700
+ }
701
+ members(id) {
702
+ return this.get(`${ws(id)}/members`);
703
+ }
704
+ setMemberRole(target, userId, role) {
705
+ const workspace = 'workspaceId' in target;
706
+ return this.send(workspace ? 'PUT' : 'PATCH', `${workspace ? ws(target.workspaceId) : org(target.organizationId)}/members/${encodeURIComponent(userId)}`, { role });
707
+ }
708
+ removeMember(target, userId) {
709
+ return this.send('DELETE', `${'workspaceId' in target ? ws(target.workspaceId) : org(target.organizationId)}/members/${encodeURIComponent(userId)}`);
710
+ }
711
+ createWorkspace(input) {
712
+ return this.send('POST', '/account/workspaces', input);
713
+ }
714
+ renameWorkspace(id, name) {
715
+ return this.send('PATCH', ws(id), { name });
716
+ }
717
+ deleteWorkspace(id, name) {
718
+ return this.send('DELETE', ws(id), { name });
719
+ }
720
+ keys(id) {
721
+ return this.get(`${ws(id)}/keys`);
722
+ }
723
+ createKey(id, name, access) {
724
+ return this.send('POST', `${ws(id)}/keys`, { name, access });
725
+ }
726
+ revokeKey(id, keyId) {
727
+ return this.send('DELETE', `${ws(id)}/keys/${encodeURIComponent(keyId)}`);
728
+ }
729
+ connections(id) {
730
+ return this.get(id ? `${ws(id)}/connections` : '/account/connections');
731
+ }
732
+ disconnect(id, workspaceId) {
733
+ return this.send('DELETE', `${workspaceId ? ws(workspaceId) : '/account'}/connections/${encodeURIComponent(id)}`);
734
+ }
735
+ startElevation(input) {
736
+ return this.send('POST', '/account/cli/approvals', input);
737
+ }
738
+ approval(id) {
739
+ return this.get(approval(id));
740
+ }
741
+ endElevation(id) {
742
+ return this.send('POST', `${approval(id)}/end`);
743
+ }
744
+ logout() {
745
+ return this.send('DELETE', '/account/cli/login');
746
+ }
747
+ }
748
+ //# sourceMappingURL=index.js.map