@pixeyedev/storybook 0.4.2 → 0.4.4
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.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/upload.d.ts +7 -9
- package/dist/upload.js +56 -20
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,3 +4,5 @@ export type { UploadBundleOptions, UploadBundleResult } from './upload.js';
|
|
|
4
4
|
export { uploadBundle } from './upload.js';
|
|
5
5
|
export type { BundleValidation } from './validate.js';
|
|
6
6
|
export { validateBundle } from './validate.js';
|
|
7
|
+
export type { StorybookFinalizeResponse, StorybookUploadResponse } from '@pixeyedev/shared';
|
|
8
|
+
export { StorybookFinalizeResponseSchema, StorybookUploadResponseSchema } from '@pixeyedev/shared';
|
package/dist/index.js
CHANGED
package/dist/upload.d.ts
CHANGED
|
@@ -7,21 +7,19 @@ export interface UploadBundleOptions {
|
|
|
7
7
|
buffer: Buffer;
|
|
8
8
|
storyCount: number;
|
|
9
9
|
componentCount: number;
|
|
10
|
+
prNumber?: number;
|
|
10
11
|
}
|
|
11
12
|
export interface UploadBundleResult {
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
buildId: string;
|
|
14
|
+
pipelineId: string;
|
|
14
15
|
skipped: boolean;
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* Upload a Storybook bundle to Pixeye for server-side rendering.
|
|
18
19
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* storybook
|
|
23
|
-
*
|
|
24
|
-
* For now, this registers the build metadata so it appears in the
|
|
25
|
-
* Pixeye dashboard. Server-side rendering is not yet available.
|
|
20
|
+
* Flow:
|
|
21
|
+
* 1. POST /api/v1/storybook/uploads — get presigned URL + upload record
|
|
22
|
+
* 2. PUT bundle to presigned URL (skipped if bundle hash already exists)
|
|
23
|
+
* 3. POST /api/v1/storybook/uploads/:id/finalize — create build + pipeline
|
|
26
24
|
*/
|
|
27
25
|
export declare const uploadBundle: (opts: UploadBundleOptions) => Promise<UploadBundleResult>;
|
package/dist/upload.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import { PixeyeError } from '@pixeyedev/core';
|
|
1
|
+
import { isRetryableHttpError, maskPresignedUrl, PixeyeError, withRetry } from '@pixeyedev/core';
|
|
2
|
+
import { StorybookFinalizeResponseSchema, StorybookUploadResponseSchema } from '@pixeyedev/shared';
|
|
2
3
|
/**
|
|
3
4
|
* Upload a Storybook bundle to Pixeye for server-side rendering.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* storybook
|
|
9
|
-
*
|
|
10
|
-
* For now, this registers the build metadata so it appears in the
|
|
11
|
-
* Pixeye dashboard. Server-side rendering is not yet available.
|
|
6
|
+
* Flow:
|
|
7
|
+
* 1. POST /api/v1/storybook/uploads — get presigned URL + upload record
|
|
8
|
+
* 2. PUT bundle to presigned URL (skipped if bundle hash already exists)
|
|
9
|
+
* 3. POST /api/v1/storybook/uploads/:id/finalize — create build + pipeline
|
|
12
10
|
*/
|
|
13
11
|
export const uploadBundle = async (opts) => {
|
|
14
12
|
const baseUrl = opts.serverUrl.replace(/\/$/, '');
|
|
15
|
-
//
|
|
16
|
-
const
|
|
13
|
+
// Step 1: Create upload record + get presigned URL
|
|
14
|
+
const uploadRes = await fetch(`${baseUrl}/api/v1/storybook/uploads`, {
|
|
17
15
|
method: 'POST',
|
|
18
16
|
headers: {
|
|
19
17
|
'Content-Type': 'application/json',
|
|
@@ -23,19 +21,57 @@ export const uploadBundle = async (opts) => {
|
|
|
23
21
|
projectToken: opts.token,
|
|
24
22
|
commitSha: opts.commitSha,
|
|
25
23
|
branch: opts.branch,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
hash: opts.hash,
|
|
25
|
+
storyCount: opts.storyCount,
|
|
26
|
+
componentCount: opts.componentCount,
|
|
27
|
+
sizeBytes: opts.buffer.length,
|
|
28
|
+
...(opts.prNumber !== undefined && opts.prNumber !== null && { prNumber: opts.prNumber })
|
|
29
29
|
})
|
|
30
30
|
});
|
|
31
|
-
if (!
|
|
32
|
-
const text = await
|
|
33
|
-
throw new PixeyeError(
|
|
31
|
+
if (!uploadRes.ok) {
|
|
32
|
+
const text = await uploadRes.text();
|
|
33
|
+
throw new PixeyeError(uploadRes.status, '/api/v1/storybook/uploads', text);
|
|
34
|
+
}
|
|
35
|
+
const uploadData = StorybookUploadResponseSchema.parse(await uploadRes.json());
|
|
36
|
+
const skipped = uploadData.bundleExists;
|
|
37
|
+
// Step 2: Upload bundle to presigned URL (skip if already exists)
|
|
38
|
+
if (!skipped) {
|
|
39
|
+
const maskedUrl = maskPresignedUrl(uploadData.presignedUrl);
|
|
40
|
+
await withRetry(async () => {
|
|
41
|
+
const putRes = await fetch(uploadData.presignedUrl, {
|
|
42
|
+
method: 'PUT',
|
|
43
|
+
body: new Uint8Array(opts.buffer),
|
|
44
|
+
headers: { 'Content-Type': 'application/gzip' }
|
|
45
|
+
});
|
|
46
|
+
if (!putRes.ok) {
|
|
47
|
+
const text = await putRes.text();
|
|
48
|
+
throw new PixeyeError(putRes.status, maskedUrl, text);
|
|
49
|
+
}
|
|
50
|
+
}, isRetryableHttpError, {
|
|
51
|
+
maxAttempts: 3,
|
|
52
|
+
baseDelayMs: 1000,
|
|
53
|
+
onRetry: (attempt, err) => {
|
|
54
|
+
console.warn(`[pixeye] Bundle upload retry ${attempt}/3: ${err.message}`);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// Step 3: Finalize — creates build + pipeline, enqueues render job
|
|
59
|
+
const finalizeRes = await fetch(`${baseUrl}/api/v1/storybook/uploads/${uploadData.uploadId}/finalize`, {
|
|
60
|
+
method: 'POST',
|
|
61
|
+
headers: {
|
|
62
|
+
'Content-Type': 'application/json',
|
|
63
|
+
Authorization: `Bearer ${opts.token}`
|
|
64
|
+
},
|
|
65
|
+
body: JSON.stringify({ projectToken: opts.token })
|
|
66
|
+
});
|
|
67
|
+
if (!finalizeRes.ok) {
|
|
68
|
+
const text = await finalizeRes.text();
|
|
69
|
+
throw new PixeyeError(finalizeRes.status, `/api/v1/storybook/uploads/${uploadData.uploadId}/finalize`, text);
|
|
34
70
|
}
|
|
35
|
-
const
|
|
71
|
+
const finalizeData = StorybookFinalizeResponseSchema.parse(await finalizeRes.json());
|
|
36
72
|
return {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
skipped
|
|
73
|
+
buildId: finalizeData.buildId,
|
|
74
|
+
pipelineId: finalizeData.pipelineId,
|
|
75
|
+
skipped
|
|
40
76
|
};
|
|
41
77
|
};
|