akribes 0.21.17
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/CHANGELOG.md +30 -0
- package/LICENSE +21 -0
- package/README.md +160 -0
- package/dist/client.d.ts +240 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +272 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +196 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +274 -0
- package/dist/errors.js.map +1 -0
- package/dist/execution/index.d.ts +3 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +3 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/replay.d.ts +37 -0
- package/dist/execution/replay.d.ts.map +1 -0
- package/dist/execution/replay.js +59 -0
- package/dist/execution/replay.js.map +1 -0
- package/dist/execution/steps.d.ts +327 -0
- package/dist/execution/steps.d.ts.map +1 -0
- package/dist/execution/steps.js +1068 -0
- package/dist/execution/steps.js.map +1 -0
- package/dist/http.d.ts +53 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +141 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/runStream.d.ts +176 -0
- package/dist/runStream.d.ts.map +1 -0
- package/dist/runStream.js +408 -0
- package/dist/runStream.js.map +1 -0
- package/dist/sse.d.ts +46 -0
- package/dist/sse.d.ts.map +1 -0
- package/dist/sse.js +218 -0
- package/dist/sse.js.map +1 -0
- package/dist/sub/bench.d.ts +182 -0
- package/dist/sub/bench.d.ts.map +1 -0
- package/dist/sub/bench.js +420 -0
- package/dist/sub/bench.js.map +1 -0
- package/dist/sub/channels.d.ts +22 -0
- package/dist/sub/channels.d.ts.map +1 -0
- package/dist/sub/channels.js +32 -0
- package/dist/sub/channels.js.map +1 -0
- package/dist/sub/clients.d.ts +79 -0
- package/dist/sub/clients.d.ts.map +1 -0
- package/dist/sub/clients.js +190 -0
- package/dist/sub/clients.js.map +1 -0
- package/dist/sub/documents.d.ts +113 -0
- package/dist/sub/documents.d.ts.map +1 -0
- package/dist/sub/documents.js +329 -0
- package/dist/sub/documents.js.map +1 -0
- package/dist/sub/evals.d.ts +71 -0
- package/dist/sub/evals.d.ts.map +1 -0
- package/dist/sub/evals.js +86 -0
- package/dist/sub/evals.js.map +1 -0
- package/dist/sub/events.d.ts +65 -0
- package/dist/sub/events.d.ts.map +1 -0
- package/dist/sub/events.js +154 -0
- package/dist/sub/events.js.map +1 -0
- package/dist/sub/executions.d.ts +255 -0
- package/dist/sub/executions.d.ts.map +1 -0
- package/dist/sub/executions.js +322 -0
- package/dist/sub/executions.js.map +1 -0
- package/dist/sub/mcp.d.ts +51 -0
- package/dist/sub/mcp.d.ts.map +1 -0
- package/dist/sub/mcp.js +42 -0
- package/dist/sub/mcp.js.map +1 -0
- package/dist/sub/projects.d.ts +73 -0
- package/dist/sub/projects.d.ts.map +1 -0
- package/dist/sub/projects.js +101 -0
- package/dist/sub/projects.js.map +1 -0
- package/dist/sub/scripts.d.ts +58 -0
- package/dist/sub/scripts.d.ts.map +1 -0
- package/dist/sub/scripts.js +82 -0
- package/dist/sub/scripts.js.map +1 -0
- package/dist/sub/tokens.d.ts +126 -0
- package/dist/sub/tokens.d.ts.map +1 -0
- package/dist/sub/tokens.js +105 -0
- package/dist/sub/tokens.js.map +1 -0
- package/dist/sub/versions.d.ts +29 -0
- package/dist/sub/versions.d.ts.map +1 -0
- package/dist/sub/versions.js +52 -0
- package/dist/sub/versions.js.map +1 -0
- package/dist/tokenSafety.d.ts +15 -0
- package/dist/tokenSafety.d.ts.map +1 -0
- package/dist/tokenSafety.js +24 -0
- package/dist/tokenSafety.js.map +1 -0
- package/dist/types.d.ts +1147 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +132 -0
- package/dist/types.js.map +1 -0
- package/dist/workflowEvents.d.ts +297 -0
- package/dist/workflowEvents.d.ts.map +1 -0
- package/dist/workflowEvents.js +612 -0
- package/dist/workflowEvents.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/sub/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAEjE,MAAM,MAAM,SAAS,GAAG;IACtB,MAAM,EAAE,WAAW,GAAG,UAAU,GAAG,SAAS,GAAG,gBAAgB,CAAC;IAChE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,uEAAuE;AACvE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,oEAAoE;AACpE,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,qBAAa,SAAS;IAElB,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,SAAS;gBADT,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,MAAM;IAG3B,OAAO,CAAC,IAAI;IAIN,WAAW,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAIzE,SAAS,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAIrE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,SAAS,CAAC;IAIhF;;;OAGG;IACG,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAOxF;;;;OAIG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;CAYrF"}
|
package/dist/sub/mcp.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export class McpClient {
|
|
2
|
+
http;
|
|
3
|
+
projectId;
|
|
4
|
+
constructor(http, projectId) {
|
|
5
|
+
this.http = http;
|
|
6
|
+
this.projectId = projectId;
|
|
7
|
+
}
|
|
8
|
+
base() {
|
|
9
|
+
return `${this.http.getBaseUrl()}/projects/${this.projectId}/mcp`;
|
|
10
|
+
}
|
|
11
|
+
async listServers(opts) {
|
|
12
|
+
return (await this.http.fetchOk(`${this.base()}/servers`, opts)).json();
|
|
13
|
+
}
|
|
14
|
+
async listTools(opts) {
|
|
15
|
+
return (await this.http.fetchOk(`${this.base()}/tools`, opts)).json();
|
|
16
|
+
}
|
|
17
|
+
async health(alias, opts) {
|
|
18
|
+
return (await this.http.fetchOk(`${this.base()}/servers/${encodeURIComponent(alias)}/health`, opts)).json();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Force a fresh `tools/list` against the remote MCP server and update the
|
|
22
|
+
* pinned schema in the DB. Returns the new tool count.
|
|
23
|
+
*/
|
|
24
|
+
async refresh(alias, opts) {
|
|
25
|
+
return (await this.http.fetchOk(`${this.base()}/servers/${encodeURIComponent(alias)}/refresh`, { method: 'POST', signal: opts?.signal })).json();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Compare the pinned schema against the remote server's live `tools/list`
|
|
29
|
+
* and report added/removed tool names. The server populates `added` and
|
|
30
|
+
* `removed` arrays even when nothing has drifted (both empty in that case).
|
|
31
|
+
*/
|
|
32
|
+
async drift(alias, opts) {
|
|
33
|
+
const res = await (await this.http.fetchOk(`${this.base()}/servers/${encodeURIComponent(alias)}/drift`, opts)).json();
|
|
34
|
+
return {
|
|
35
|
+
drifted: !!res.drifted,
|
|
36
|
+
added: res.added ?? [],
|
|
37
|
+
removed: res.removed ?? [],
|
|
38
|
+
reason: res.reason,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/sub/mcp.ts"],"names":[],"mappings":"AAwBA,MAAM,OAAO,SAAS;IAEV;IACA;IAFV,YACU,IAAgB,EAChB,SAAiB;QADjB,SAAI,GAAJ,IAAI,CAAY;QAChB,cAAS,GAAT,SAAS,CAAQ;IACxB,CAAC;IAEI,IAAI;QACV,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,aAAa,IAAI,CAAC,SAAS,MAAM,CAAC;IACpE,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,IAA+B;QAC/C,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC1E,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,IAA+B;QAC7C,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACxE,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAa,EAAE,IAA+B;QACzD,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,YAAY,kBAAkB,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9G,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO,CAAC,KAAa,EAAE,IAA+B;QAC1D,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAC7B,GAAG,IAAI,CAAC,IAAI,EAAE,YAAY,kBAAkB,CAAC,KAAK,CAAC,UAAU,EAC7D,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CACzC,CAAC,CAAC,IAAI,EAAE,CAAC;IACZ,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAK,CAAC,KAAa,EAAE,IAA+B;QACxD,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CACxC,GAAG,IAAI,CAAC,IAAI,EAAE,YAAY,kBAAkB,CAAC,KAAK,CAAC,QAAQ,EAC3D,IAAI,CACL,CAAC,CAAC,IAAI,EAA6B,CAAC;QACrC,OAAO;YACL,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO;YACtB,KAAK,EAAE,GAAG,CAAC,KAAK,IAAI,EAAE;YACtB,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE;YAC1B,MAAM,EAAE,GAAG,CAAC,MAAM;SACnB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { HttpClient } from '../http';
|
|
2
|
+
import type { Project, Script, ScriptChannel, ProjectCost } from '../types';
|
|
3
|
+
export declare class ProjectsClient {
|
|
4
|
+
private http;
|
|
5
|
+
constructor(http: HttpClient);
|
|
6
|
+
private get base();
|
|
7
|
+
private scriptPath;
|
|
8
|
+
list(opts?: {
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}): Promise<Project[]>;
|
|
11
|
+
create(name: string, opts?: {
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
}): Promise<Project>;
|
|
14
|
+
/** Fetch a project by numeric id or name. The server resolves either,
|
|
15
|
+
* so callers holding only a URL slug don't need a name→id round-trip. */
|
|
16
|
+
get(id: number | string, opts?: {
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
}): Promise<Project>;
|
|
19
|
+
update(id: number, name: string, opts?: {
|
|
20
|
+
signal?: AbortSignal;
|
|
21
|
+
}): Promise<Project>;
|
|
22
|
+
delete(id: number, opts?: {
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}): Promise<void>;
|
|
25
|
+
/** List scripts for a specific project (cross-project, no bound projectId required).
|
|
26
|
+
* Accepts a numeric id or a name — the server resolves either. */
|
|
27
|
+
listScripts(projectId: number | string, opts?: {
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
}): Promise<Script[]>;
|
|
30
|
+
/** List channels for a script in a specific project (cross-project). */
|
|
31
|
+
listChannels(projectId: number, scriptName: string, opts?: {
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
}): Promise<ScriptChannel[]>;
|
|
34
|
+
/** Delete a script in a specific project (cross-project). */
|
|
35
|
+
deleteScript(projectId: number, scriptName: string, opts?: {
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
}): Promise<void>;
|
|
38
|
+
/** Rename a script in a specific project (cross-project). */
|
|
39
|
+
renameScript(projectId: number, scriptName: string, newName: string, opts?: {
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
}): Promise<void>;
|
|
42
|
+
/** Duplicate a script within the same project. Copies versions, channels, and draft — not executions. */
|
|
43
|
+
duplicateScript(projectId: number, scriptName: string, opts?: {
|
|
44
|
+
signal?: AbortSignal;
|
|
45
|
+
}): Promise<Script>;
|
|
46
|
+
/** Duplicate an entire project with all its scripts. */
|
|
47
|
+
duplicate(id: number, opts?: {
|
|
48
|
+
signal?: AbortSignal;
|
|
49
|
+
}): Promise<Project>;
|
|
50
|
+
/** Reorder projects. Pass an array of project IDs in the desired order. */
|
|
51
|
+
reorder(order: number[], opts?: {
|
|
52
|
+
signal?: AbortSignal;
|
|
53
|
+
}): Promise<void>;
|
|
54
|
+
/** Reorder scripts within a project. Pass an array of script IDs in the desired order. */
|
|
55
|
+
reorderScripts(projectId: number, order: number[], opts?: {
|
|
56
|
+
signal?: AbortSignal;
|
|
57
|
+
}): Promise<void>;
|
|
58
|
+
/** Move a script from one project to another. Returns the updated script. */
|
|
59
|
+
moveScript(projectId: number, scriptName: string, targetProjectId: number, opts?: {
|
|
60
|
+
signal?: AbortSignal;
|
|
61
|
+
}): Promise<Script>;
|
|
62
|
+
/** Get cost aggregation for an arbitrary project (the project the client was
|
|
63
|
+
* constructed against is NOT used). Mirrors `executions.getProjectCost()`
|
|
64
|
+
* but takes an explicit `projectId`, so callers like Studio's Sidebar
|
|
65
|
+
* can roll up costs for every expanded project — not just the active one
|
|
66
|
+
* (#837). */
|
|
67
|
+
getCost(projectId: number, opts?: {
|
|
68
|
+
since?: string;
|
|
69
|
+
until?: string;
|
|
70
|
+
signal?: AbortSignal;
|
|
71
|
+
}): Promise<ProjectCost>;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=projects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projects.d.ts","sourceRoot":"","sources":["../../src/sub/projects.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5E,qBAAa,cAAc;IACb,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEpC,OAAO,KAAK,IAAI,GAAmD;IAEnE,OAAO,CAAC,UAAU;IAIZ,I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AW,CAAC;CAUxH"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export class ProjectsClient {
|
|
2
|
+
http;
|
|
3
|
+
constructor(http) {
|
|
4
|
+
this.http = http;
|
|
5
|
+
}
|
|
6
|
+
get base() { return `${this.http.getBaseUrl()}/projects`; }
|
|
7
|
+
scriptPath(projectId, scriptName, ...segments) {
|
|
8
|
+
return this.http.scriptPath(projectId, scriptName, ...segments);
|
|
9
|
+
}
|
|
10
|
+
async list(opts) {
|
|
11
|
+
return (await this.http.fetchOk(this.base, opts)).json();
|
|
12
|
+
}
|
|
13
|
+
async create(name, opts) {
|
|
14
|
+
return (await this.http.fetchOk(this.base, {
|
|
15
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
16
|
+
body: JSON.stringify({ name }), signal: opts?.signal,
|
|
17
|
+
})).json();
|
|
18
|
+
}
|
|
19
|
+
/** Fetch a project by numeric id or name. The server resolves either,
|
|
20
|
+
* so callers holding only a URL slug don't need a name→id round-trip. */
|
|
21
|
+
async get(id, opts) {
|
|
22
|
+
return (await this.http.fetchOk(`${this.base}/${encodeURIComponent(String(id))}`, opts)).json();
|
|
23
|
+
}
|
|
24
|
+
async update(id, name, opts) {
|
|
25
|
+
return (await this.http.fetchOk(`${this.base}/${id}`, {
|
|
26
|
+
method: 'PATCH', headers: { 'Content-Type': 'application/json' },
|
|
27
|
+
body: JSON.stringify({ name }), signal: opts?.signal,
|
|
28
|
+
})).json();
|
|
29
|
+
}
|
|
30
|
+
async delete(id, opts) {
|
|
31
|
+
await this.http.fetchOk(`${this.base}/${id}`, { method: 'DELETE', signal: opts?.signal });
|
|
32
|
+
}
|
|
33
|
+
/** List scripts for a specific project (cross-project, no bound projectId required).
|
|
34
|
+
* Accepts a numeric id or a name — the server resolves either. */
|
|
35
|
+
async listScripts(projectId, opts) {
|
|
36
|
+
return (await this.http.fetchOk(`${this.base}/${encodeURIComponent(String(projectId))}/scripts`, opts)).json();
|
|
37
|
+
}
|
|
38
|
+
/** List channels for a script in a specific project (cross-project). */
|
|
39
|
+
async listChannels(projectId, scriptName, opts) {
|
|
40
|
+
return (await this.http.fetchOk(`${this.scriptPath(projectId, scriptName, 'channels')}`, opts)).json();
|
|
41
|
+
}
|
|
42
|
+
/** Delete a script in a specific project (cross-project). */
|
|
43
|
+
async deleteScript(projectId, scriptName, opts) {
|
|
44
|
+
await this.http.fetchOk(`${this.scriptPath(projectId, scriptName)}`, { method: 'DELETE', signal: opts?.signal });
|
|
45
|
+
}
|
|
46
|
+
/** Rename a script in a specific project (cross-project). */
|
|
47
|
+
async renameScript(projectId, scriptName, newName, opts) {
|
|
48
|
+
await this.http.fetchOk(`${this.scriptPath(projectId, scriptName)}`, {
|
|
49
|
+
method: 'PATCH', headers: { 'Content-Type': 'application/json' },
|
|
50
|
+
body: JSON.stringify({ new_name: newName }), signal: opts?.signal,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** Duplicate a script within the same project. Copies versions, channels, and draft — not executions. */
|
|
54
|
+
async duplicateScript(projectId, scriptName, opts) {
|
|
55
|
+
return (await this.http.fetchOk(`${this.scriptPath(projectId, scriptName, 'duplicate')}`, {
|
|
56
|
+
method: 'POST', signal: opts?.signal,
|
|
57
|
+
})).json();
|
|
58
|
+
}
|
|
59
|
+
/** Duplicate an entire project with all its scripts. */
|
|
60
|
+
async duplicate(id, opts) {
|
|
61
|
+
return (await this.http.fetchOk(`${this.base}/${id}/duplicate`, {
|
|
62
|
+
method: 'POST', signal: opts?.signal,
|
|
63
|
+
})).json();
|
|
64
|
+
}
|
|
65
|
+
/** Reorder projects. Pass an array of project IDs in the desired order. */
|
|
66
|
+
async reorder(order, opts) {
|
|
67
|
+
await this.http.fetchOk(`${this.base}/reorder`, {
|
|
68
|
+
method: 'PUT', headers: { 'Content-Type': 'application/json' },
|
|
69
|
+
body: JSON.stringify({ order }), signal: opts?.signal,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** Reorder scripts within a project. Pass an array of script IDs in the desired order. */
|
|
73
|
+
async reorderScripts(projectId, order, opts) {
|
|
74
|
+
await this.http.fetchOk(`${this.base}/${projectId}/scripts/reorder`, {
|
|
75
|
+
method: 'PUT', headers: { 'Content-Type': 'application/json' },
|
|
76
|
+
body: JSON.stringify({ order }), signal: opts?.signal,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/** Move a script from one project to another. Returns the updated script. */
|
|
80
|
+
async moveScript(projectId, scriptName, targetProjectId, opts) {
|
|
81
|
+
return (await this.http.fetchOk(`${this.scriptPath(projectId, scriptName, 'move')}`, {
|
|
82
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
83
|
+
body: JSON.stringify({ target_project_id: targetProjectId }), signal: opts?.signal,
|
|
84
|
+
})).json();
|
|
85
|
+
}
|
|
86
|
+
/** Get cost aggregation for an arbitrary project (the project the client was
|
|
87
|
+
* constructed against is NOT used). Mirrors `executions.getProjectCost()`
|
|
88
|
+
* but takes an explicit `projectId`, so callers like Studio's Sidebar
|
|
89
|
+
* can roll up costs for every expanded project — not just the active one
|
|
90
|
+
* (#837). */
|
|
91
|
+
async getCost(projectId, opts) {
|
|
92
|
+
const params = new URLSearchParams();
|
|
93
|
+
if (opts?.since)
|
|
94
|
+
params.set('since', opts.since);
|
|
95
|
+
if (opts?.until)
|
|
96
|
+
params.set('until', opts.until);
|
|
97
|
+
const qs = params.toString();
|
|
98
|
+
return (await this.http.fetchOk(`${this.base}/${projectId}/cost${qs ? `?${qs}` : ''}`, { signal: opts?.signal })).json();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=projects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projects.js","sourceRoot":"","sources":["../../src/sub/projects.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,cAAc;IACL;IAApB,YAAoB,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAExC,IAAY,IAAI,KAA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AAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACjD,IAAI,IAAI,EAAE,KAAK;YAAE,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACjD,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC7B,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAC7B,GAAG,IAAI,CAAC,IAAI,IAAI,SAAS,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EACrD,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CACzB,CAAC,CAAC,IAAI,EAAE,CAAC;IACZ,CAAC;CACF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { HttpClient } from '../http';
|
|
2
|
+
import type { Script, DraftResponse, PutDraftResponse, ScriptGraph } from '../types';
|
|
3
|
+
export declare class ScriptsClient {
|
|
4
|
+
private http;
|
|
5
|
+
private projectId;
|
|
6
|
+
constructor(http: HttpClient, projectId: number);
|
|
7
|
+
private path;
|
|
8
|
+
list(opts?: {
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}): Promise<Script[]>;
|
|
11
|
+
create(name: string, source: string, opts?: {
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
}): Promise<Script>;
|
|
14
|
+
get(name: string, opts?: {
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}): Promise<Script | null>;
|
|
17
|
+
rename(oldName: string, newName: string, opts?: {
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
delete(name: string, opts?: {
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
}): Promise<void>;
|
|
23
|
+
getDraft(name: string, opts?: {
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
}): Promise<DraftResponse | null>;
|
|
26
|
+
saveDraft(name: string, source: string, opts?: {
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
}): Promise<PutDraftResponse>;
|
|
29
|
+
getGraph(name: string, opts?: {
|
|
30
|
+
version?: number;
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
}): Promise<ScriptGraph | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Duplicate a script within this project. The server picks a copy name
|
|
35
|
+
* (e.g. `foo copy`) and returns the new script. Per-project sugar over
|
|
36
|
+
* `projects.duplicateScript(projectId, name)`.
|
|
37
|
+
*/
|
|
38
|
+
duplicate(name: string, opts?: {
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
}): Promise<Script>;
|
|
41
|
+
/**
|
|
42
|
+
* Move a script to another project. Returns the moved script (now scoped
|
|
43
|
+
* to the target project). Per-project sugar over
|
|
44
|
+
* `projects.moveScript(projectId, name, targetProjectId)`.
|
|
45
|
+
*/
|
|
46
|
+
moveTo(name: string, targetProjectId: number, opts?: {
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
}): Promise<Script>;
|
|
49
|
+
/**
|
|
50
|
+
* Set the sort order of scripts in this project. `order` is the list of
|
|
51
|
+
* script IDs in the desired order. Per-project sugar over
|
|
52
|
+
* `projects.reorderScripts(projectId, order)`.
|
|
53
|
+
*/
|
|
54
|
+
reorder(order: number[], opts?: {
|
|
55
|
+
signal?: AbortSignal;
|
|
56
|
+
}): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=scripts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["../../src/sub/scripts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAErF,qBAAa,aAAa;IAEtB,OAAO,CAAC,IAAI;IACZ,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AW,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAQ5G;;;;OAIG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAM/E;;;;OAIG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAOrG;;;;OAIG;IACG,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAS/E"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { nullOn404 } from '../http';
|
|
2
|
+
export class ScriptsClient {
|
|
3
|
+
http;
|
|
4
|
+
projectId;
|
|
5
|
+
constructor(http, projectId) {
|
|
6
|
+
this.http = http;
|
|
7
|
+
this.projectId = projectId;
|
|
8
|
+
}
|
|
9
|
+
path(name, ...segments) {
|
|
10
|
+
return this.http.scriptPath(this.projectId, name, ...segments);
|
|
11
|
+
}
|
|
12
|
+
async list(opts) {
|
|
13
|
+
return (await this.http.fetchOk(`${this.http.getBaseUrl()}/projects/${this.projectId}/scripts`, opts)).json();
|
|
14
|
+
}
|
|
15
|
+
async create(name, source, opts) {
|
|
16
|
+
return (await this.http.fetchOk(`${this.http.getBaseUrl()}/projects/${this.projectId}/scripts?name=${encodeURIComponent(name)}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ source }), signal: opts?.signal })).json();
|
|
17
|
+
}
|
|
18
|
+
async get(name, opts) {
|
|
19
|
+
return nullOn404(async () => (await this.http.fetchOk(this.path(name), opts)).json());
|
|
20
|
+
}
|
|
21
|
+
async rename(oldName, newName, opts) {
|
|
22
|
+
await this.http.fetchOk(this.path(oldName), {
|
|
23
|
+
method: 'PATCH', headers: { 'Content-Type': 'application/json' },
|
|
24
|
+
body: JSON.stringify({ new_name: newName }), signal: opts?.signal,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async delete(name, opts) {
|
|
28
|
+
await this.http.fetchOk(this.path(name), { method: 'DELETE', signal: opts?.signal });
|
|
29
|
+
}
|
|
30
|
+
async getDraft(name, opts) {
|
|
31
|
+
return nullOn404(async () => (await this.http.fetchOk(this.path(name, 'draft'), opts)).json());
|
|
32
|
+
}
|
|
33
|
+
async saveDraft(name, source, opts) {
|
|
34
|
+
const res = await this.http.fetchOk(this.path(name, 'draft'), {
|
|
35
|
+
method: 'PUT', headers: { 'Content-Type': 'application/json' },
|
|
36
|
+
body: JSON.stringify({ source }), signal: opts?.signal,
|
|
37
|
+
});
|
|
38
|
+
const text = await res.text();
|
|
39
|
+
if (!text)
|
|
40
|
+
return { schema_warnings: [], inputs: [], type_defs: {} };
|
|
41
|
+
return JSON.parse(text);
|
|
42
|
+
}
|
|
43
|
+
async getGraph(name, opts) {
|
|
44
|
+
const url = new URL(this.path(name, 'graph'));
|
|
45
|
+
if (opts?.version !== undefined)
|
|
46
|
+
url.searchParams.set('version', String(opts.version));
|
|
47
|
+
return nullOn404(async () => (await this.http.fetchOk(url.toString(), { signal: opts?.signal })).json());
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Duplicate a script within this project. The server picks a copy name
|
|
51
|
+
* (e.g. `foo copy`) and returns the new script. Per-project sugar over
|
|
52
|
+
* `projects.duplicateScript(projectId, name)`.
|
|
53
|
+
*/
|
|
54
|
+
async duplicate(name, opts) {
|
|
55
|
+
return (await this.http.fetchOk(this.path(name, 'duplicate'), {
|
|
56
|
+
method: 'POST', signal: opts?.signal,
|
|
57
|
+
})).json();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Move a script to another project. Returns the moved script (now scoped
|
|
61
|
+
* to the target project). Per-project sugar over
|
|
62
|
+
* `projects.moveScript(projectId, name, targetProjectId)`.
|
|
63
|
+
*/
|
|
64
|
+
async moveTo(name, targetProjectId, opts) {
|
|
65
|
+
return (await this.http.fetchOk(this.path(name, 'move'), {
|
|
66
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
67
|
+
body: JSON.stringify({ target_project_id: targetProjectId }), signal: opts?.signal,
|
|
68
|
+
})).json();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Set the sort order of scripts in this project. `order` is the list of
|
|
72
|
+
* script IDs in the desired order. Per-project sugar over
|
|
73
|
+
* `projects.reorderScripts(projectId, order)`.
|
|
74
|
+
*/
|
|
75
|
+
async reorder(order, opts) {
|
|
76
|
+
await this.http.fetchOk(`${this.http.getBaseUrl()}/projects/${this.projectId}/scripts/reorder`, {
|
|
77
|
+
method: 'PUT', headers: { 'Content-Type': 'application/json' },
|
|
78
|
+
body: JSON.stringify({ order }), signal: opts?.signal,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=scripts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["../../src/sub/scripts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpC,MAAM,OAAO,aAAa;IAEd;IACA;IAFV,YACU,IAAgB,EAChB,SAAiB;QADjB,SAAI,GAAJ,IAAI,CAAY;QAChB,cAAS,GAAT,SAAS,CAAQ;IACxB,CAAC;IAEI,IAAI,CAAC,IAAY,EAAE,GAAG,QAAkB;QAC9C,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,CAAC;IACjE,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAA+B;QACxC,OAAO,CAAC,M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QAC5D,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CACrB,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,aAAa,IAAI,CAAC,SAAS,kBAAkB,EACtE;YACE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC9D,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;SACtD,CACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { HttpClient } from '../http';
|
|
2
|
+
import type { TokenInfo, MintTokenResponse } from '../types';
|
|
3
|
+
export type TokenScopes = {
|
|
4
|
+
/** `'*'` for all projects, or an array of project IDs. */
|
|
5
|
+
projects: '*' | number[];
|
|
6
|
+
/** Permission level. `admin` can mint/revoke tokens; `editor` can modify
|
|
7
|
+
* scripts and executions; `viewer` is read-only. */
|
|
8
|
+
role: 'admin' | 'editor' | 'viewer';
|
|
9
|
+
/** Optional: restrict the token to specific script names. */
|
|
10
|
+
scripts?: string[];
|
|
11
|
+
/** Optional: restrict the token to specific execution IDs (one-off
|
|
12
|
+
* read-only sharing). */
|
|
13
|
+
executions?: string[];
|
|
14
|
+
/** Whether the new token may itself mint child tokens. Defaults to
|
|
15
|
+
* `false`. Service tokens always pass; scoped minters must already have
|
|
16
|
+
* `can_mint` set on their own scopes for this to be honored. Use `true`
|
|
17
|
+
* for long-lived Personal API Keys; leave `false` for browser sessions. */
|
|
18
|
+
can_mint?: boolean;
|
|
19
|
+
/** Optional org binding. When set, the minted token deserializes with
|
|
20
|
+
* `org_id: <value>`; when omitted, the server stamps it `NULL`. Org-aware
|
|
21
|
+
* callers (e.g. Studio's multi-tenant flow) must pass this through or
|
|
22
|
+
* newly-created projects become invisible to the same user's org-wide
|
|
23
|
+
* tokens. */
|
|
24
|
+
org_id?: number;
|
|
25
|
+
};
|
|
26
|
+
export type MintTokenRequest = {
|
|
27
|
+
/** Email used for metrics attribution and offboarding. Optional but
|
|
28
|
+
* strongly recommended for end-user tokens so you can later revoke all
|
|
29
|
+
* tokens for a removed user via {@link TokensClient.revokeByEmail}. */
|
|
30
|
+
user_email?: string;
|
|
31
|
+
scopes: TokenScopes;
|
|
32
|
+
/** Token lifetime in seconds. Server-enforced max is 90 days
|
|
33
|
+
* (`90 * 24 * 3600 = 7_776_000`). Use ~28800 (8 h) for browser sessions
|
|
34
|
+
* and 7_776_000 (90 days) for CLI tokens. */
|
|
35
|
+
expires_in: number;
|
|
36
|
+
/** Human-readable label shown in the token list UI. Max 128 chars. */
|
|
37
|
+
label: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Token management API.
|
|
41
|
+
*
|
|
42
|
+
* **The auth model in one paragraph:** akribes-server has two token types.
|
|
43
|
+
* Service tokens live in env vars (`AKRIBES_SERVICE_TOKEN_<NAME>=<scope>:<secret>`)
|
|
44
|
+
* and never expire — your backend uses one to talk to akribes-server. Scoped
|
|
45
|
+
* tokens are minted at runtime via this client and stored in the DB. They
|
|
46
|
+
* expire (max 90 days), can be revoked, and are what you hand out to
|
|
47
|
+
* browsers / end-users / CLIs.
|
|
48
|
+
*
|
|
49
|
+
* @example Backend → mint a per-user token for a browser session
|
|
50
|
+
* ```ts
|
|
51
|
+
* // your backend has AKRIBES_SERVICE_TOKEN=*:secret in its env
|
|
52
|
+
* const akribes = new AkribesClient({
|
|
53
|
+
* baseUrl: 'https://akribes.example.com',
|
|
54
|
+
* token: process.env.AKRIBES_SERVICE_TOKEN!,
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* const minted = await akribes.tokens.mint({
|
|
58
|
+
* user_email: session.user.email,
|
|
59
|
+
* scopes: { projects: '*', role: 'admin' },
|
|
60
|
+
* expires_in: 8 * 3600, // 8 hour browser session
|
|
61
|
+
* label: `web-session:${session.id}`,
|
|
62
|
+
* });
|
|
63
|
+
* // → ship `minted.token` to the browser; the browser uses it directly
|
|
64
|
+
* // against akribes-server.
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @example One-off read-only share for a single execution
|
|
68
|
+
* ```ts
|
|
69
|
+
* const minted = await akribes.tokens.mint({
|
|
70
|
+
* user_email: 'guest@acme.com',
|
|
71
|
+
* scopes: {
|
|
72
|
+
* projects: [2],
|
|
73
|
+
* role: 'viewer',
|
|
74
|
+
* executions: [executionId], // read-only on this single exec
|
|
75
|
+
* },
|
|
76
|
+
* expires_in: 3600,
|
|
77
|
+
* label: `share:${executionId}`,
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example Offboarding — revoke every token for a removed user
|
|
82
|
+
* ```ts
|
|
83
|
+
* await akribes.tokens.revokeByEmail('removed@example.com');
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare class TokensClient {
|
|
87
|
+
private http;
|
|
88
|
+
constructor(http: HttpClient);
|
|
89
|
+
private get base();
|
|
90
|
+
/** Mint a new scoped token. Only service tokens can mint. */
|
|
91
|
+
mint(req: MintTokenRequest, opts?: {
|
|
92
|
+
signal?: AbortSignal;
|
|
93
|
+
}): Promise<MintTokenResponse>;
|
|
94
|
+
/** List tokens. Service tokens see all; scoped tokens see only their own.
|
|
95
|
+
*
|
|
96
|
+
* Pagination + filters mirror akribes-server's `GET /tokens` query params:
|
|
97
|
+
*
|
|
98
|
+
* - `limit` / `offset` — page size (server default 50, max 500) and offset
|
|
99
|
+
* into the result set. Scoped-token callers ignore these (their list
|
|
100
|
+
* is already capped to their own row).
|
|
101
|
+
* - `userEmail` — service-token only; narrows the list to one user's
|
|
102
|
+
* tokens. Use this on per-user surfaces (e.g. a Personal API Keys page)
|
|
103
|
+
* so users with older tokens never drop off the first page.
|
|
104
|
+
* - `includeRevoked` / `includeExpired` — surface tokens hidden by
|
|
105
|
+
* default. Useful for offboarding tooling.
|
|
106
|
+
*/
|
|
107
|
+
list(opts?: {
|
|
108
|
+
signal?: AbortSignal;
|
|
109
|
+
limit?: number;
|
|
110
|
+
offset?: number;
|
|
111
|
+
userEmail?: string;
|
|
112
|
+
includeRevoked?: boolean;
|
|
113
|
+
includeExpired?: boolean;
|
|
114
|
+
}): Promise<TokenInfo[]>;
|
|
115
|
+
/** Revoke a single token by ID. */
|
|
116
|
+
revoke(tokenId: string, opts?: {
|
|
117
|
+
signal?: AbortSignal;
|
|
118
|
+
}): Promise<void>;
|
|
119
|
+
/** Revoke all tokens for a user email (offboarding). Only service tokens can do this. */
|
|
120
|
+
revokeByEmail(email: string, opts?: {
|
|
121
|
+
signal?: AbortSignal;
|
|
122
|
+
}): Promise<{
|
|
123
|
+
revoked: number;
|
|
124
|
+
}>;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/sub/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7D,MAAM,MAAM,WAAW,GAAG;IACxB,0DAA0D;IAC1D,QAAQ,EAAE,GAAG,GAAG,MAAM,EAAE,CAAC;IACzB;yDACqD;IACrD,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACpC,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;8BAC0B;IAC1B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;;gFAG4E;IAC5E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;kBAIc;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;4EAEwE;IACxE,UAAU,CAAC,EAAE,MAAM,CAAC;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|
+
* Service tokens live in env vars (`AKRIBES_SERVICE_TOKEN_<NAME>=<scope>:<secret>`)
|
|
6
|
+
* and never expire — your backend uses one to talk to akribes-server. Scoped
|
|
7
|
+
* tokens are minted at runtime via this client and stored in the DB. They
|
|
8
|
+
* expire (max 90 days), can be revoked, and are what you hand out to
|
|
9
|
+
* browsers / end-users / CLIs.
|
|
10
|
+
*
|
|
11
|
+
* @example Backend → mint a per-user token for a browser session
|
|
12
|
+
* ```ts
|
|
13
|
+
* // your backend has AKRIBES_SERVICE_TOKEN=*:secret in its env
|
|
14
|
+
* const akribes = new AkribesClient({
|
|
15
|
+
* baseUrl: 'https://akribes.example.com',
|
|
16
|
+
* token: process.env.AKRIBES_SERVICE_TOKEN!,
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* const minted = await akribes.tokens.mint({
|
|
20
|
+
* user_email: session.user.email,
|
|
21
|
+
* scopes: { projects: '*', role: 'admin' },
|
|
22
|
+
* expires_in: 8 * 3600, // 8 hour browser session
|
|
23
|
+
* label: `web-session:${session.id}`,
|
|
24
|
+
* });
|
|
25
|
+
* // → ship `minted.token` to the browser; the browser uses it directly
|
|
26
|
+
* // against akribes-server.
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example One-off read-only share for a single execution
|
|
30
|
+
* ```ts
|
|
31
|
+
* const minted = await akribes.tokens.mint({
|
|
32
|
+
* user_email: 'guest@acme.com',
|
|
33
|
+
* scopes: {
|
|
34
|
+
* projects: [2],
|
|
35
|
+
* role: 'viewer',
|
|
36
|
+
* executions: [executionId], // read-only on this single exec
|
|
37
|
+
* },
|
|
38
|
+
* expires_in: 3600,
|
|
39
|
+
* label: `share:${executionId}`,
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example Offboarding — revoke every token for a removed user
|
|
44
|
+
* ```ts
|
|
45
|
+
* await akribes.tokens.revokeByEmail('removed@example.com');
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export class TokensClient {
|
|
49
|
+
http;
|
|
50
|
+
constructor(http) {
|
|
51
|
+
this.http = http;
|
|
52
|
+
}
|
|
53
|
+
get base() { return `${this.http.getBaseUrl()}/tokens`; }
|
|
54
|
+
/** Mint a new scoped token. Only service tokens can mint. */
|
|
55
|
+
async mint(req, opts) {
|
|
56
|
+
return (await this.http.fetchOk(this.base, {
|
|
57
|
+
method: 'POST',
|
|
58
|
+
headers: { 'Content-Type': 'application/json' },
|
|
59
|
+
body: JSON.stringify(req),
|
|
60
|
+
signal: opts?.signal,
|
|
61
|
+
})).json();
|
|
62
|
+
}
|
|
63
|
+
/** List tokens. Service tokens see all; scoped tokens see only their own.
|
|
64
|
+
*
|
|
65
|
+
* Pagination + filters mirror akribes-server's `GET /tokens` query params:
|
|
66
|
+
*
|
|
67
|
+
* - `limit` / `offset` — page size (server default 50, max 500) and offset
|
|
68
|
+
* into the result set. Scoped-token callers ignore these (their list
|
|
69
|
+
* is already capped to their own row).
|
|
70
|
+
* - `userEmail` — service-token only; narrows the list to one user's
|
|
71
|
+
* tokens. Use this on per-user surfaces (e.g. a Personal API Keys page)
|
|
72
|
+
* so users with older tokens never drop off the first page.
|
|
73
|
+
* - `includeRevoked` / `includeExpired` — surface tokens hidden by
|
|
74
|
+
* default. Useful for offboarding tooling.
|
|
75
|
+
*/
|
|
76
|
+
async list(opts) {
|
|
77
|
+
const params = new URLSearchParams();
|
|
78
|
+
if (opts?.limit != null)
|
|
79
|
+
params.set('limit', String(opts.limit));
|
|
80
|
+
if (opts?.offset != null)
|
|
81
|
+
params.set('offset', String(opts.offset));
|
|
82
|
+
if (opts?.userEmail)
|
|
83
|
+
params.set('user_email', opts.userEmail);
|
|
84
|
+
if (opts?.includeRevoked)
|
|
85
|
+
params.set('include_revoked', 'true');
|
|
86
|
+
if (opts?.includeExpired)
|
|
87
|
+
params.set('include_expired', 'true');
|
|
88
|
+
const qs = params.toString();
|
|
89
|
+
const url = qs ? `${this.base}?${qs}` : this.base;
|
|
90
|
+
return (await this.http.fetchOk(url, { signal: opts?.signal })).json();
|
|
91
|
+
}
|
|
92
|
+
/** Revoke a single token by ID. */
|
|
93
|
+
async revoke(tokenId, opts) {
|
|
94
|
+
await this.http.fetchOk(`${this.base}/${encodeURIComponent(tokenId)}`, {
|
|
95
|
+
method: 'DELETE', signal: opts?.signal,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/** Revoke all tokens for a user email (offboarding). Only service tokens can do this. */
|
|
99
|
+
async revokeByEmail(email, opts) {
|
|
100
|
+
return (await this.http.fetchOk(`${this.base}?user_email=${encodeURIComponent(email)}`, {
|
|
101
|
+
method: 'DELETE', signal: opts?.signal,
|
|
102
|
+
})).json();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../src/sub/tokens.ts"],"names":[],"mappings":"AAyCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,OAAO,YAAY;IACH;IAApB,YAAoB,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAExC,IAAY,IAAI,KAAK,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC;IAEjE,6DAA6D;IAC7D,KAAK,CAAC,IAAI,CAAC,GAAqB,EAAE,IAA+B;QAC/D,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE;YACzC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC;YACzB,MAAM,EAAE,IAAI,EAAE,MAAM;SACrB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC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