@netlify/spark-ui 1.31.0-alpha.3 → 1.31.0-alpha.5

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.
Files changed (100) hide show
  1. package/dist/components/index.d.ts +2 -2
  2. package/dist/components/preact/DropZone/DropZone.d.ts +27 -9
  3. package/dist/components/preact/DropZone/DropZone.js +59 -54
  4. package/dist/components/preact/DropZone/DropZone.test.d.ts +1 -0
  5. package/dist/components/preact/DropZone/index.d.ts +3 -3
  6. package/dist/components/preact/DropZone/index.js +29 -27
  7. package/dist/components/preact/DropZone/useDropDeploy.d.ts +9 -6
  8. package/dist/components/preact/DropZone/useDropDeploy.js +182 -131
  9. package/dist/components/preact/DropZone/useDropDeploy.test.d.ts +1 -0
  10. package/dist/components/preact/index.d.ts +2 -2
  11. package/dist/components/preact/index.js +24 -18
  12. package/dist/drop-core/analytics.d.ts +107 -0
  13. package/dist/drop-core/analytics.js +21 -0
  14. package/dist/drop-core/analytics.test.d.ts +1 -0
  15. package/dist/drop-core/authedApi.d.ts +45 -0
  16. package/dist/drop-core/authedApi.js +30 -0
  17. package/dist/drop-core/authedApi.test.d.ts +1 -0
  18. package/dist/{components/preact/DropZone/drop-core → drop-core}/authedDropClient.d.ts +4 -11
  19. package/dist/drop-core/authedDropClient.js +100 -0
  20. package/dist/drop-core/authedDropClient.test.d.ts +1 -0
  21. package/dist/{components/preact/DropZone/drop-core → drop-core}/buildClient.d.ts +5 -13
  22. package/dist/drop-core/buildClient.js +85 -0
  23. package/dist/drop-core/buildClient.test.d.ts +1 -0
  24. package/dist/drop-core/buildStash.d.ts +37 -0
  25. package/dist/drop-core/buildStash.js +84 -0
  26. package/dist/drop-core/buildStash.test.d.ts +0 -0
  27. package/dist/{components/preact/DropZone/drop-core → drop-core}/client.d.ts +3 -1
  28. package/dist/drop-core/client.js +47 -0
  29. package/dist/drop-core/constants.d.ts +29 -0
  30. package/dist/drop-core/constants.js +10 -0
  31. package/dist/{components/preact/DropZone/drop-core → drop-core}/deploy.d.ts +9 -0
  32. package/dist/drop-core/deploy.js +66 -0
  33. package/dist/drop-core/deploy.test.d.ts +1 -0
  34. package/dist/drop-core/detectBuild.test.d.ts +1 -0
  35. package/dist/drop-core/digest.test.d.ts +1 -0
  36. package/dist/{components/preact/DropZone/drop-core → drop-core}/errors.d.ts +29 -0
  37. package/dist/drop-core/errors.js +119 -0
  38. package/dist/drop-core/errors.test.d.ts +1 -0
  39. package/dist/drop-core/fileTypes.test.d.ts +1 -0
  40. package/dist/drop-core/index.d.ts +25 -0
  41. package/dist/drop-core/index.js +47 -0
  42. package/dist/{components/preact/DropZone/drop-core → drop-core}/readFiles.js +2 -2
  43. package/dist/drop-core/readFiles.test.d.ts +1 -0
  44. package/dist/{components/preact/DropZone/drop-core → drop-core}/types.d.ts +10 -0
  45. package/dist/{components/preact/DropZone/drop-core → drop-core}/zip.js +1 -1
  46. package/dist/drop-core/zip.test.d.ts +1 -0
  47. package/package.json +4 -1
  48. package/packages/components/index.ts +19 -0
  49. package/packages/components/preact/DropZone/DropZone.test.ts +71 -0
  50. package/packages/components/preact/DropZone/DropZone.tsx +29 -9
  51. package/packages/components/preact/DropZone/index.tsx +14 -3
  52. package/packages/components/preact/DropZone/useDropDeploy.test.ts +376 -0
  53. package/packages/components/preact/DropZone/useDropDeploy.ts +301 -145
  54. package/packages/components/preact/index.ts +19 -2
  55. package/packages/drop-core/README.md +91 -0
  56. package/packages/drop-core/analytics.test.ts +17 -0
  57. package/packages/drop-core/analytics.ts +122 -0
  58. package/packages/drop-core/authedApi.test.ts +100 -0
  59. package/packages/drop-core/authedApi.ts +81 -0
  60. package/packages/drop-core/authedDropClient.test.ts +196 -0
  61. package/packages/{components/preact/DropZone/drop-core → drop-core}/authedDropClient.ts +30 -72
  62. package/packages/drop-core/buildClient.test.ts +112 -0
  63. package/packages/{components/preact/DropZone/drop-core → drop-core}/buildClient.ts +27 -57
  64. package/packages/drop-core/buildStash.test.ts +85 -0
  65. package/packages/drop-core/buildStash.ts +185 -0
  66. package/packages/{components/preact/DropZone/drop-core → drop-core}/client.ts +18 -6
  67. package/packages/drop-core/constants.ts +39 -0
  68. package/packages/drop-core/deploy.test.ts +177 -0
  69. package/packages/{components/preact/DropZone/drop-core → drop-core}/deploy.ts +59 -9
  70. package/packages/drop-core/detectBuild.test.ts +139 -0
  71. package/packages/drop-core/digest.test.ts +24 -0
  72. package/packages/drop-core/errors.test.ts +98 -0
  73. package/packages/{components/preact/DropZone/drop-core → drop-core}/errors.ts +68 -11
  74. package/packages/drop-core/fileTypes.test.ts +37 -0
  75. package/packages/drop-core/index.ts +44 -0
  76. package/packages/drop-core/readFiles.test.ts +124 -0
  77. package/packages/{components/preact/DropZone/drop-core → drop-core}/types.ts +12 -6
  78. package/packages/drop-core/zip.test.ts +92 -0
  79. package/dist/components/preact/DropZone/drop-core/authedDropClient.js +0 -123
  80. package/dist/components/preact/DropZone/drop-core/buildClient.js +0 -99
  81. package/dist/components/preact/DropZone/drop-core/client.js +0 -45
  82. package/dist/components/preact/DropZone/drop-core/deploy.js +0 -48
  83. package/dist/components/preact/DropZone/drop-core/errors.js +0 -82
  84. package/dist/components/preact/DropZone/drop-core/index.d.ts +0 -11
  85. package/dist/components/preact/DropZone/drop-core/index.js +0 -36
  86. package/packages/components/preact/DropZone/drop-core/index.ts +0 -11
  87. /package/dist/{components/preact/DropZone/drop-core → drop-core}/detectBuild.d.ts +0 -0
  88. /package/dist/{components/preact/DropZone/drop-core → drop-core}/detectBuild.js +0 -0
  89. /package/dist/{components/preact/DropZone/drop-core → drop-core}/digest.d.ts +0 -0
  90. /package/dist/{components/preact/DropZone/drop-core → drop-core}/digest.js +0 -0
  91. /package/dist/{components/preact/DropZone/drop-core → drop-core}/fileTypes.d.ts +0 -0
  92. /package/dist/{components/preact/DropZone/drop-core → drop-core}/fileTypes.js +0 -0
  93. /package/dist/{components/preact/DropZone/drop-core → drop-core}/readFiles.d.ts +0 -0
  94. /package/dist/{components/preact/DropZone/drop-core → drop-core}/types.js +0 -0
  95. /package/dist/{components/preact/DropZone/drop-core → drop-core}/zip.d.ts +0 -0
  96. /package/packages/{components/preact/DropZone/drop-core → drop-core}/detectBuild.ts +0 -0
  97. /package/packages/{components/preact/DropZone/drop-core → drop-core}/digest.ts +0 -0
  98. /package/packages/{components/preact/DropZone/drop-core → drop-core}/fileTypes.ts +0 -0
  99. /package/packages/{components/preact/DropZone/drop-core → drop-core}/readFiles.ts +0 -0
  100. /package/packages/{components/preact/DropZone/drop-core → drop-core}/zip.ts +0 -0
@@ -1,99 +0,0 @@
1
- var d = Object.defineProperty;
2
- var p = (r, t, e) => t in r ? d(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
- var i = (r, t, e) => p(r, typeof t != "symbol" ? t + "" : t, e);
4
- import { NotAuthenticatedError as n, SiteCreateError as h, BuildCreateError as u, BuildFailedError as w, BuildTimeoutError as y } from "./errors.js";
5
- const f = "/access-control/bb-api/api/v1", B = "https://api.netlify.com/api/v1", m = 1e3, S = 10 * 60 * 1e3, T = /* @__PURE__ */ new Set(["ready", "error", "rejected"]);
6
- class _ {
7
- constructor({
8
- proxyBase: t = f,
9
- apiBase: e = B,
10
- getUploadToken: a,
11
- accountSlug: o,
12
- title: s = "Build from drop deployment",
13
- pollIntervalMs: l = m,
14
- timeoutMs: c = S
15
- }) {
16
- i(this, "proxyBase");
17
- i(this, "apiBase");
18
- i(this, "getUploadToken");
19
- i(this, "accountSlug");
20
- i(this, "title");
21
- i(this, "pollIntervalMs");
22
- i(this, "timeoutMs");
23
- this.proxyBase = t, this.apiBase = e, this.getUploadToken = a, this.accountSlug = o, this.title = s, this.pollIntervalMs = l, this.timeoutMs = c;
24
- }
25
- /**
26
- * Create the site the build deploys into. Goes through the proxy with
27
- * `credentials: 'include'` so the app session authorizes it; without an
28
- * account slug the API picks the user's default account.
29
- */
30
- async createSite() {
31
- const t = this.accountSlug ? `/${this.accountSlug}/sites` : "/sites", e = await fetch(`${this.proxyBase}${t}`, {
32
- method: "POST",
33
- credentials: "include",
34
- headers: { "Content-Type": "application/json" },
35
- body: JSON.stringify({ created_via: "drop" })
36
- });
37
- if (e.status === 401 || e.status === 403) throw new n();
38
- if (!e.ok) throw new h(e.status);
39
- return e.json();
40
- }
41
- /**
42
- * Upload the source archive and enqueue a build. Direct to `api.netlify.com`
43
- * (see the note on `apiBase`), authorized by a freshly minted bearer token.
44
- * `Content-Type` is left unset on purpose so the browser adds the multipart
45
- * boundary itself.
46
- *
47
- * Known ceiling: this is one request on a 30s token, and re-minting can't
48
- * help once it is in flight. A zip that takes longer than that to upload will
49
- * fail — the app origin gets 300s for exactly this reason, and lifting the
50
- * limit for other origins is a platform-side change.
51
- */
52
- async createBuildFromZip(t, e) {
53
- const a = await this.getUploadToken();
54
- if (!a) throw new n();
55
- const o = new FormData();
56
- o.append("zip", e), o.append("title", this.title);
57
- const s = await fetch(`${this.apiBase}/sites/${t}/builds`, {
58
- method: "POST",
59
- headers: { Authorization: `Bearer ${a}` },
60
- body: o
61
- });
62
- if (s.status === 401 || s.status === 403) throw new n();
63
- if (!s.ok) throw new u(s.status);
64
- return s.json();
65
- }
66
- /**
67
- * Poll the build's deploy until it settles, mirroring
68
- * `AnonymousDropClient.waitUntilReady` — resolve on `ready`, throw on
69
- * `error`/`rejected`, throw on timeout. A build that hasn't been given a
70
- * deploy id yet has nothing pollable, so it resolves immediately and the
71
- * caller falls back to the site page.
72
- *
73
- * Optional in the drop flow, and off by default: a build takes minutes, so
74
- * the useful hand-off is usually the project page rather than a spinner.
75
- * Polling rides the session cookie, so it cannot outlive its credentials the
76
- * way a 30s bearer would.
77
- */
78
- async waitUntilBuildReady(t) {
79
- if (!t.deploy_id) return;
80
- const e = this.timeoutMs / this.pollIntervalMs;
81
- for (let a = 0; a < e; a++) {
82
- const o = await fetch(`${this.proxyBase}/deploys/${t.deploy_id}`, {
83
- credentials: "include"
84
- });
85
- if (o.ok) {
86
- const s = await o.json();
87
- if (s.state && T.has(s.state)) {
88
- if (s.state === "ready") return;
89
- throw new w(s.error_message);
90
- }
91
- }
92
- await new Promise((s) => setTimeout(s, this.pollIntervalMs));
93
- }
94
- throw new y();
95
- }
96
- }
97
- export {
98
- _ as AuthenticatedBuildClient
99
- };
@@ -1,45 +0,0 @@
1
- function r(s, t) {
2
- return Object.assign(new Error(`${s} failed: ${t}`), { status: t });
3
- }
4
- const n = "https://api.netlify.com/api/v1";
5
- class p {
6
- constructor(t = n) {
7
- this.apiBase = t;
8
- }
9
- async getToken() {
10
- const t = await fetch(`${this.apiBase}/drop/token`, { method: "POST" });
11
- if (!t.ok) throw r("drop/token", t.status);
12
- return (await t.json()).token;
13
- }
14
- async createDeploy(t, o) {
15
- const e = await fetch(`${this.apiBase}/drop`, {
16
- method: "POST",
17
- headers: { "Content-Type": "application/json" },
18
- body: JSON.stringify({ files: t, token: o })
19
- });
20
- if (!e.ok) throw r("drop", e.status);
21
- return e.json();
22
- }
23
- async uploadFile(t, o, e, a) {
24
- const i = await fetch(`${this.apiBase}/deploys/${t}/files${o}`, {
25
- method: "PUT",
26
- headers: { "Content-Type": "application/octet-stream", Authorization: `Bearer ${a}` },
27
- body: e
28
- });
29
- if (!i.ok) throw r(`upload ${o}`, i.status);
30
- }
31
- async waitUntilReady(t, o) {
32
- for (let e = 0; e < 600; e++) {
33
- const a = await fetch(`${this.apiBase}/deploys/${t.deploy_id}`, {
34
- headers: { Authorization: `Bearer ${o}` }
35
- });
36
- if (a.ok && (await a.json()).state === "ready") return;
37
- await new Promise((i) => setTimeout(i, 1e3));
38
- }
39
- throw new Error("Deploy did not become ready in time");
40
- }
41
- }
42
- export {
43
- p as AnonymousDropClient,
44
- r as apiError
45
- };
@@ -1,48 +0,0 @@
1
- import { getDigest as w } from "./digest.js";
2
- import { zipFiles as y } from "./zip.js";
3
- const f = 5;
4
- async function m(i, l, n, t, p, a) {
5
- const u = n.filter((d) => t.has(d.sha));
6
- let e = 0, h = 0;
7
- const c = async () => {
8
- for (; e < u.length; ) {
9
- const d = u[e++];
10
- await i.uploadFile(l, d.path, d.content, p), a == null || a(++h);
11
- }
12
- };
13
- await Promise.all(Array.from({ length: Math.min(f, u.length) }, c));
14
- }
15
- async function s(i, l, n = {}) {
16
- if (!l.length) throw new Error("No files to deploy");
17
- const { onProgress: t } = n;
18
- t == null || t({ phase: "creating" });
19
- const p = await i.getToken(), a = await i.createDeploy(w(l), p), u = a.required.length;
20
- return t == null || t({ phase: "uploading", uploaded: 0, total: u }), await m(
21
- i,
22
- a.deploy_id,
23
- l,
24
- new Set(a.required),
25
- p,
26
- (e) => t == null ? void 0 : t({ phase: "uploading", uploaded: e, total: u })
27
- ), t == null || t({ phase: "processing" }), await i.waitUntilReady(a, p), t == null || t({ phase: "ready" }), { deploy: a, token: p, url: `https://${a.subdomain}.netlify.app` };
28
- }
29
- async function F(i, l, n = {}) {
30
- if (!l.length) throw new Error("No files to deploy");
31
- const { onProgress: t, waitForBuild: p = !1 } = n;
32
- t == null || t({ phase: "zipping" });
33
- const { file: a, buildSettings: u } = await y(l);
34
- t == null || t({ phase: "creating" });
35
- const e = await i.createSite();
36
- t == null || t({ phase: "uploading" });
37
- const h = await i.createBuildFromZip(e.id, a);
38
- return t == null || t({ phase: "building" }), p && await i.waitUntilBuildReady(h), t == null || t({ phase: "ready" }), {
39
- site: e,
40
- build: h,
41
- buildSettings: u,
42
- url: e.ssl_url || e.url || `https://${e.name}.netlify.app`
43
- };
44
- }
45
- export {
46
- F as deployBuild,
47
- s as deployFiles
48
- };
@@ -1,82 +0,0 @@
1
- var n = Object.defineProperty;
2
- var i = (e, t, r) => t in e ? n(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var a = (e, t, r) => i(e, typeof t != "symbol" ? t + "" : t, r);
4
- class o extends Error {
5
- constructor() {
6
- super("unsupported single file"), this.name = "UnsupportedDropError";
7
- }
8
- }
9
- class s extends Error {
10
- constructor(t = "not authenticated") {
11
- super(t), this.name = "NotAuthenticatedError";
12
- }
13
- }
14
- class u extends Error {
15
- constructor(r) {
16
- super(`site create failed${r ? `: ${r}` : ""}`);
17
- a(this, "status");
18
- this.name = "SiteCreateError", this.status = r;
19
- }
20
- }
21
- class f extends Error {
22
- constructor(r) {
23
- super(`build create failed${r ? `: ${r}` : ""}`);
24
- a(this, "status");
25
- this.name = "BuildCreateError", this.status = r;
26
- }
27
- }
28
- class l extends Error {
29
- constructor(t) {
30
- super(t ? `build failed: ${t}` : "build failed"), this.reason = t, this.name = "BuildFailedError";
31
- }
32
- }
33
- class d extends Error {
34
- constructor() {
35
- super("Build did not finish in time"), this.name = "BuildTimeoutError";
36
- }
37
- }
38
- function h(e) {
39
- if (!(e instanceof Error)) return "Something went wrong. Please try again.";
40
- if (e instanceof o)
41
- return "To deploy, drop a folder or a .zip file — or a single HTML page.";
42
- if (e instanceof s)
43
- return "Please log in to Netlify to deploy a project that needs a build, then try again.";
44
- if (e instanceof u)
45
- return "We couldn't create a project for this build. Please try again.";
46
- if (e instanceof l)
47
- return e.reason ? `Your build failed: ${e.reason}` : "Your build failed. Check your build settings and try again.";
48
- if (e instanceof d)
49
- return "Your build is taking longer than expected. It may still finish — check your Netlify dashboard.";
50
- if (e.message === "Deploy did not become ready in time")
51
- return "Your site is taking longer than expected to go live. Please try again in a moment.";
52
- if (e instanceof TypeError)
53
- return "Couldn't connect to Netlify. Check your internet connection and try again.";
54
- const t = "status" in e && typeof e.status == "number" ? e.status : void 0;
55
- switch (t) {
56
- case 429:
57
- return "Too many attempts — please wait a moment and try again.";
58
- case 413:
59
- return "Your upload is too large to deploy this way.";
60
- case 404:
61
- return "We couldn't find that deploy. Please try again.";
62
- case 401:
63
- case 403:
64
- return "That request wasn't allowed. Please try again.";
65
- case 500:
66
- case 502:
67
- case 503:
68
- case 504:
69
- return "Netlify's servers are having trouble right now. Please try again shortly.";
70
- default:
71
- return t ? "Something went wrong talking to Netlify. Please try again." : "Something went wrong. Please try again.";
72
- }
73
- }
74
- export {
75
- f as BuildCreateError,
76
- l as BuildFailedError,
77
- d as BuildTimeoutError,
78
- s as NotAuthenticatedError,
79
- u as SiteCreateError,
80
- o as UnsupportedDropError,
81
- h as humanizeDropError
82
- };
@@ -1,11 +0,0 @@
1
- export * from './types';
2
- export * from './digest';
3
- export * from './readFiles';
4
- export * from './fileTypes';
5
- export * from './detectBuild';
6
- export * from './client';
7
- export * from './authedDropClient';
8
- export * from './buildClient';
9
- export * from './zip';
10
- export * from './deploy';
11
- export * from './errors';
@@ -1,36 +0,0 @@
1
- import { getDigest as t } from "./digest.js";
2
- import { getSingleNonIndexHtmlFileName as i, hasMultipleHtmlFilesWithoutIndex as l, readDataTransfer as n, readFileList as p, renameSingleNonIndexHtmlToIndex as d } from "./readFiles.js";
3
- import { getFileTypes as a } from "./fileTypes.js";
4
- import { detectBuild as x, inferBuildSettings as f } from "./detectBuild.js";
5
- import { AnonymousDropClient as g, apiError as E } from "./client.js";
6
- import { AuthenticatedDropClient as F } from "./authedDropClient.js";
7
- import { AuthenticatedBuildClient as D } from "./buildClient.js";
8
- import { generateNetlifyToml as C, zipFiles as N } from "./zip.js";
9
- import { deployBuild as c, deployFiles as A } from "./deploy.js";
10
- import { BuildCreateError as S, BuildFailedError as H, BuildTimeoutError as z, NotAuthenticatedError as L, SiteCreateError as M, UnsupportedDropError as U, humanizeDropError as W } from "./errors.js";
11
- export {
12
- g as AnonymousDropClient,
13
- D as AuthenticatedBuildClient,
14
- F as AuthenticatedDropClient,
15
- S as BuildCreateError,
16
- H as BuildFailedError,
17
- z as BuildTimeoutError,
18
- L as NotAuthenticatedError,
19
- M as SiteCreateError,
20
- U as UnsupportedDropError,
21
- E as apiError,
22
- c as deployBuild,
23
- A as deployFiles,
24
- x as detectBuild,
25
- C as generateNetlifyToml,
26
- t as getDigest,
27
- a as getFileTypes,
28
- i as getSingleNonIndexHtmlFileName,
29
- l as hasMultipleHtmlFilesWithoutIndex,
30
- W as humanizeDropError,
31
- f as inferBuildSettings,
32
- n as readDataTransfer,
33
- p as readFileList,
34
- d as renameSingleNonIndexHtmlToIndex,
35
- N as zipFiles
36
- };
@@ -1,11 +0,0 @@
1
- export * from './types';
2
- export * from './digest';
3
- export * from './readFiles';
4
- export * from './fileTypes';
5
- export * from './detectBuild';
6
- export * from './client';
7
- export * from './authedDropClient';
8
- export * from './buildClient';
9
- export * from './zip';
10
- export * from './deploy';
11
- export * from './errors';