@netlify/spark-ui 1.26.0-alpha.2 → 1.26.0-alpha.3

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.
@@ -1,9 +1,9 @@
1
- import { Deploy, Digest } from './types';
1
+ import { DropResponse, Digest } from './types';
2
2
  export interface DropClient {
3
3
  getToken(): Promise<string>;
4
- createDeploy(digest: Digest, token: string): Promise<Deploy>;
4
+ createDeploy(digest: Digest, token: string): Promise<DropResponse>;
5
5
  uploadFile(deployId: string, path: string, content: ArrayBuffer, token: string): Promise<void>;
6
- waitUntilReady(deploy: Deploy, token: string): Promise<void>;
6
+ waitUntilReady(deploy: DropResponse, token: string): Promise<void>;
7
7
  }
8
8
  /**
9
9
  * Unauthenticated drop client. Authorized server-side by the Referer header,
@@ -13,7 +13,7 @@ export declare class AnonymousDropClient implements DropClient {
13
13
  private apiBase;
14
14
  constructor(apiBase?: string);
15
15
  getToken(): Promise<string>;
16
- createDeploy(files: Digest, token: string): Promise<Deploy>;
16
+ createDeploy(files: Digest, token: string): Promise<DropResponse>;
17
17
  uploadFile(deployId: string, path: string, content: ArrayBuffer, token: string): Promise<void>;
18
- waitUntilReady(deploy: Deploy, token: string): Promise<void>;
18
+ waitUntilReady(deploy: DropResponse, token: string): Promise<void>;
19
19
  }
@@ -27,7 +27,7 @@ class n {
27
27
  }
28
28
  async waitUntilReady(e, o) {
29
29
  for (let t = 0; t < 600; t++) {
30
- const a = await fetch(`${this.apiBase}/deploys/${e.id}`, {
30
+ const a = await fetch(`${this.apiBase}/deploys/${e.deploy_id}`, {
31
31
  headers: { Authorization: `Bearer ${o}` }
32
32
  });
33
33
  if (a.ok && (await a.json()).state === "ready") return;
@@ -8,8 +8,17 @@ export interface ProcessedFile {
8
8
  name: string;
9
9
  }
10
10
  export type Digest = Record<string, string>;
11
- export interface Deploy {
11
+ /**
12
+ * Response body of `POST /api/v1/drop`. Not a canonical Deploy resource —
13
+ * it's a mixed shape carrying both the anonymous site and the initial deploy
14
+ * so the client has everything it needs to upload, poll, and hand off to the
15
+ * user in one round trip.
16
+ */
17
+ export interface DropResponse {
18
+ /** site id (UUID) — surfaced to callers so they can build claim links */
12
19
  id: string;
20
+ /** deploy id (BSON) — used for `/deploys/{deploy_id}` reads and file PUTs */
21
+ deploy_id: string;
13
22
  /** the *.netlify.app subdomain assigned to the anonymous site */
14
23
  subdomain: string;
15
24
  /** SHAs the backend does NOT yet have — only these get uploaded */
@@ -17,7 +26,7 @@ export interface Deploy {
17
26
  state?: string;
18
27
  }
19
28
  export interface DeployResult {
20
- deploy: Deploy;
29
+ deploy: DropResponse;
21
30
  /** drop token — persist this to later claim the site into an account */
22
31
  token: string;
23
32
  url: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@netlify/spark-ui",
3
3
  "description": "Assets, design tokens, components, and utilities",
4
- "version": "1.26.0-alpha.2",
4
+ "version": "1.26.0-alpha.3",
5
5
  "type": "module",
6
6
  "main": "dist/components/preact/index.js",
7
7
  "types": "dist/components/preact/index.d.ts",
@@ -1,10 +1,10 @@
1
- import type { Deploy, Digest } from './types';
1
+ import type { DropResponse, Digest } from './types';
2
2
 
3
3
  export interface DropClient {
4
4
  getToken(): Promise<string>;
5
- createDeploy(digest: Digest, token: string): Promise<Deploy>;
5
+ createDeploy(digest: Digest, token: string): Promise<DropResponse>;
6
6
  uploadFile(deployId: string, path: string, content: ArrayBuffer, token: string): Promise<void>;
7
- waitUntilReady(deploy: Deploy, token: string): Promise<void>;
7
+ waitUntilReady(deploy: DropResponse, token: string): Promise<void>;
8
8
  }
9
9
 
10
10
  const API = 'https://api.netlify.com/api/v1';
@@ -22,7 +22,7 @@ export class AnonymousDropClient implements DropClient {
22
22
  return (await res.json()).token;
23
23
  }
24
24
 
25
- async createDeploy(files: Digest, token: string): Promise<Deploy> {
25
+ async createDeploy(files: Digest, token: string): Promise<DropResponse> {
26
26
  const res = await fetch(`${this.apiBase}/drop`, {
27
27
  method: 'POST',
28
28
  headers: { 'Content-Type': 'application/json' },
@@ -47,10 +47,13 @@ export class AnonymousDropClient implements DropClient {
47
47
  if (!res.ok) throw new Error(`upload ${path} failed: ${res.status}`);
48
48
  }
49
49
 
50
- async waitUntilReady(deploy: Deploy, token: string): Promise<void> {
50
+ async waitUntilReady(deploy: DropResponse, token: string): Promise<void> {
51
51
  // Poll the deploy with the drop token until ready.
52
+ // Note: `/deploys/{id}` expects the deploy_id (BSON), not the site id (UUID)
53
+ // that lives at `deploy.id`. See drop_controller.rb; Deploy.find(uuid) is nil
54
+ // and the request 401s misleadingly via require_current_actor!.
52
55
  for (let i = 0; i < 600; i++) {
53
- const res = await fetch(`${this.apiBase}/deploys/${deploy.id}`, {
56
+ const res = await fetch(`${this.apiBase}/deploys/${deploy.deploy_id}`, {
54
57
  headers: { Authorization: `Bearer ${token}` },
55
58
  });
56
59
  if (res.ok && (await res.json()).state === 'ready') return;
@@ -10,8 +10,17 @@ export interface ProcessedFile {
10
10
 
11
11
  export type Digest = Record<string, string>; // { "/index.html": "<sha1>" }
12
12
 
13
- export interface Deploy {
13
+ /**
14
+ * Response body of `POST /api/v1/drop`. Not a canonical Deploy resource —
15
+ * it's a mixed shape carrying both the anonymous site and the initial deploy
16
+ * so the client has everything it needs to upload, poll, and hand off to the
17
+ * user in one round trip.
18
+ */
19
+ export interface DropResponse {
20
+ /** site id (UUID) — surfaced to callers so they can build claim links */
14
21
  id: string;
22
+ /** deploy id (BSON) — used for `/deploys/{deploy_id}` reads and file PUTs */
23
+ deploy_id: string;
15
24
  /** the *.netlify.app subdomain assigned to the anonymous site */
16
25
  subdomain: string;
17
26
  /** SHAs the backend does NOT yet have — only these get uploaded */
@@ -20,7 +29,7 @@ export interface Deploy {
20
29
  }
21
30
 
22
31
  export interface DeployResult {
23
- deploy: Deploy;
32
+ deploy: DropResponse;
24
33
  /** drop token — persist this to later claim the site into an account */
25
34
  token: string;
26
35
  url: string; // https://<subdomain>.netlify.app