@kubb/studio 5.2.6 → 5.2.7
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/README.md +32 -0
- package/dist/index.cjs +51 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +104 -1
- package/dist/index.js +50 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,109 @@ import { Config, Hookable, KubbHooks } from "@kubb/core";
|
|
|
11
11
|
export declare class InvalidAgentTokenError extends Error {
|
|
12
12
|
constructor(studioUrl: string, options?: ErrorOptions);
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Status values returned by Studio's jobs API.
|
|
16
|
+
*/
|
|
17
|
+
type StudioJobStatus = 'queued' | 'running' | 'success' | 'failed';
|
|
18
|
+
/**
|
|
19
|
+
* Package view returned on a successful snapshot job from Studio.
|
|
20
|
+
*/
|
|
21
|
+
type StudioSnapshot = {
|
|
22
|
+
/**
|
|
23
|
+
* Immutable snapshot id.
|
|
24
|
+
*/
|
|
25
|
+
id: string;
|
|
26
|
+
/**
|
|
27
|
+
* npm package name, or `null` when Studio stored none.
|
|
28
|
+
*/
|
|
29
|
+
name: string | null;
|
|
30
|
+
/**
|
|
31
|
+
* npm package version, or `null` when Studio stored none.
|
|
32
|
+
*/
|
|
33
|
+
version: string | null;
|
|
34
|
+
/**
|
|
35
|
+
* Subresource integrity hash for the tarball, or `null` when unavailable.
|
|
36
|
+
*/
|
|
37
|
+
integrity: string | null;
|
|
38
|
+
/**
|
|
39
|
+
* Preferable download path, often the readable `/packages/{agentSlug}/{name}.tgz` form.
|
|
40
|
+
*/
|
|
41
|
+
url: string;
|
|
42
|
+
/**
|
|
43
|
+
* Stable download path keyed by snapshot id.
|
|
44
|
+
*/
|
|
45
|
+
snapshotIdUrl: string;
|
|
46
|
+
/**
|
|
47
|
+
* ISO timestamp after which Studio may delete the tarball.
|
|
48
|
+
*/
|
|
49
|
+
expiresAt: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Job record from `POST /api/jobs` and `GET /api/jobs/{id}`.
|
|
53
|
+
*/
|
|
54
|
+
type StudioJob = {
|
|
55
|
+
/**
|
|
56
|
+
* Job id returned by Studio when the job was queued.
|
|
57
|
+
*/
|
|
58
|
+
id: string;
|
|
59
|
+
/**
|
|
60
|
+
* Current status. Poll until `success` or `failed`.
|
|
61
|
+
*/
|
|
62
|
+
status: StudioJobStatus;
|
|
63
|
+
/**
|
|
64
|
+
* Failure message when `status` is `failed`.
|
|
65
|
+
*/
|
|
66
|
+
error?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Package view when a snapshot job finished successfully.
|
|
69
|
+
*/
|
|
70
|
+
snapshot?: StudioSnapshot;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Queues a generation or snapshot job on Studio (`POST /api/jobs`).
|
|
74
|
+
*
|
|
75
|
+
* Returns as soon as Studio accepts the job (`202`). Poll with {@link waitForJob} until it finishes.
|
|
76
|
+
* Authenticates with the organization CI API key via `x-api-key`.
|
|
77
|
+
*
|
|
78
|
+
* @example Snapshot job
|
|
79
|
+
* ```ts
|
|
80
|
+
* const job = await createJob({
|
|
81
|
+
* studioUrl: 'https://kubb.studio',
|
|
82
|
+
* token: process.env.KUBB_TOKEN!,
|
|
83
|
+
* type: 'snapshot',
|
|
84
|
+
* agentId: agent.id,
|
|
85
|
+
* name: '@kubb/demo',
|
|
86
|
+
* version: '1.0.0',
|
|
87
|
+
* })
|
|
88
|
+
* const finished = await waitForJob({ studioUrl, token, id: job.id })
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare function createJob({ studioUrl, token, type, agentId, name, version, config }: {
|
|
92
|
+
studioUrl: string;
|
|
93
|
+
token: string;
|
|
94
|
+
type: 'generation' | 'snapshot';
|
|
95
|
+
agentId: string;
|
|
96
|
+
name?: string;
|
|
97
|
+
version?: string;
|
|
98
|
+
config?: Record<string, unknown>;
|
|
99
|
+
}): Promise<StudioJob>;
|
|
100
|
+
/**
|
|
101
|
+
* Polls `GET /api/jobs/{id}` until the job reaches `success` or `failed`.
|
|
102
|
+
*
|
|
103
|
+
* A `failed` job resolves normally. Check `job.status` and `job.error`. Throws only when the
|
|
104
|
+
* deadline passes before Studio finishes.
|
|
105
|
+
*/
|
|
106
|
+
export declare function waitForJob({ studioUrl, token, id, timeoutMs }: {
|
|
107
|
+
studioUrl: string;
|
|
108
|
+
token: string;
|
|
109
|
+
id: string;
|
|
110
|
+
/**
|
|
111
|
+
* How long to keep polling before throwing, in milliseconds.
|
|
112
|
+
*
|
|
113
|
+
* @default 60000
|
|
114
|
+
*/
|
|
115
|
+
timeoutMs?: number;
|
|
116
|
+
}): Promise<StudioJob>;
|
|
14
117
|
//#endregion
|
|
15
118
|
//#region src/StudioSession.d.ts
|
|
16
119
|
type StudioSessionOptions = {
|
|
@@ -377,5 +480,5 @@ type PollOptions = {
|
|
|
377
480
|
*/
|
|
378
481
|
export declare function pollForPairingToken({ studioUrl, session, signal }: PollOptions): Promise<PairingResult>;
|
|
379
482
|
//#endregion
|
|
380
|
-
export { type Client, type ClientOptions, type ConnectionOptions, type StudioConnectedContext, createJobId };
|
|
483
|
+
export { type Client, type ClientOptions, type ConnectionOptions, type StudioConnectedContext, type StudioJob, type StudioJobStatus, type StudioSnapshot, createJobId };
|
|
381
484
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -564,9 +564,57 @@ async function disconnect({ sessionId, token, studioUrl, slug }) {
|
|
|
564
564
|
console.warn(styleText("yellow", `[${tag}] Failed to notify Studio of disconnection: ${getErrorMessage(error)}`));
|
|
565
565
|
}
|
|
566
566
|
}
|
|
567
|
+
/**
|
|
568
|
+
* Queues a generation or snapshot job on Studio (`POST /api/jobs`).
|
|
569
|
+
*
|
|
570
|
+
* Returns as soon as Studio accepts the job (`202`). Poll with {@link waitForJob} until it finishes.
|
|
571
|
+
* Authenticates with the organization CI API key via `x-api-key`.
|
|
572
|
+
*
|
|
573
|
+
* @example Snapshot job
|
|
574
|
+
* ```ts
|
|
575
|
+
* const job = await createJob({
|
|
576
|
+
* studioUrl: 'https://kubb.studio',
|
|
577
|
+
* token: process.env.KUBB_TOKEN!,
|
|
578
|
+
* type: 'snapshot',
|
|
579
|
+
* agentId: agent.id,
|
|
580
|
+
* name: '@kubb/demo',
|
|
581
|
+
* version: '1.0.0',
|
|
582
|
+
* })
|
|
583
|
+
* const finished = await waitForJob({ studioUrl, token, id: job.id })
|
|
584
|
+
* ```
|
|
585
|
+
*/
|
|
586
|
+
async function createJob({ studioUrl, token, type, agentId, name, version, config }) {
|
|
587
|
+
const { job } = await ofetch(`${studioUrl}/api/jobs`, {
|
|
588
|
+
method: "POST",
|
|
589
|
+
headers: { "x-api-key": token },
|
|
590
|
+
body: {
|
|
591
|
+
type,
|
|
592
|
+
agentId,
|
|
593
|
+
name,
|
|
594
|
+
version,
|
|
595
|
+
config
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
return job;
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Polls `GET /api/jobs/{id}` until the job reaches `success` or `failed`.
|
|
602
|
+
*
|
|
603
|
+
* A `failed` job resolves normally. Check `job.status` and `job.error`. Throws only when the
|
|
604
|
+
* deadline passes before Studio finishes.
|
|
605
|
+
*/
|
|
606
|
+
async function waitForJob({ studioUrl, token, id, timeoutMs = 6e4 }) {
|
|
607
|
+
const deadline = Date.now() + timeoutMs;
|
|
608
|
+
for (;;) {
|
|
609
|
+
const { job } = await ofetch(`${studioUrl}/api/jobs/${id}`, { headers: { "x-api-key": token } });
|
|
610
|
+
if (job.status === "success" || job.status === "failed") return job;
|
|
611
|
+
if (Date.now() >= deadline) throw new Error("Timed out waiting for the Studio job");
|
|
612
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
613
|
+
}
|
|
614
|
+
}
|
|
567
615
|
//#endregion
|
|
568
616
|
//#region package.json
|
|
569
|
-
var version = "5.2.
|
|
617
|
+
var version = "5.2.7";
|
|
570
618
|
//#endregion
|
|
571
619
|
//#region src/hooks.ts
|
|
572
620
|
/**
|
|
@@ -2442,6 +2490,6 @@ async function pollForPairingToken({ studioUrl = agentDefaults.studioUrl, sessio
|
|
|
2442
2490
|
throw new Error("The pairing code expired, pair again");
|
|
2443
2491
|
}
|
|
2444
2492
|
//#endregion
|
|
2445
|
-
export { InvalidAgentTokenError, PairingCanceledError, createClient, createFileStorage, createJobId, defaultStudioUrl, pollForPairingToken, runConnection, setStorage, startPairing };
|
|
2493
|
+
export { InvalidAgentTokenError, PairingCanceledError, createClient, createFileStorage, createJob, createJobId, defaultStudioUrl, pollForPairingToken, runConnection, setStorage, startPairing, waitForJob };
|
|
2446
2494
|
|
|
2447
2495
|
//# sourceMappingURL=index.js.map
|