@netlify/spark-ui 1.31.0-alpha.4 → 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.
- package/dist/components/preact/DropZone/DropZone.d.ts +6 -7
- package/dist/components/preact/DropZone/DropZone.js +5 -5
- package/dist/components/preact/DropZone/index.js +29 -29
- package/dist/components/preact/DropZone/useDropDeploy.d.ts +0 -1
- package/dist/components/preact/DropZone/useDropDeploy.js +25 -27
- package/dist/components/preact/index.js +10 -10
- package/dist/drop-core/authedApi.d.ts +0 -10
- package/dist/drop-core/authedApi.js +15 -20
- package/dist/drop-core/authedDropClient.d.ts +4 -11
- package/dist/drop-core/authedDropClient.js +24 -33
- package/dist/drop-core/buildClient.js +17 -16
- package/dist/drop-core/client.d.ts +3 -1
- package/dist/drop-core/client.js +19 -17
- package/dist/drop-core/constants.d.ts +29 -0
- package/dist/drop-core/constants.js +10 -0
- package/dist/drop-core/deploy.d.ts +2 -0
- package/dist/drop-core/deploy.js +56 -43
- package/dist/drop-core/errors.d.ts +29 -0
- package/dist/drop-core/errors.js +70 -33
- package/dist/drop-core/index.d.ts +22 -11
- package/dist/drop-core/index.js +45 -49
- package/package.json +1 -1
- package/packages/components/preact/DropZone/DropZone.tsx +6 -7
- package/packages/components/preact/DropZone/useDropDeploy.ts +13 -22
- package/packages/drop-core/README.md +91 -0
- package/packages/drop-core/authedApi.ts +0 -13
- package/packages/drop-core/authedDropClient.ts +12 -33
- package/packages/drop-core/buildClient.ts +2 -3
- package/packages/drop-core/client.ts +18 -6
- package/packages/drop-core/constants.ts +39 -0
- package/packages/drop-core/deploy.test.ts +42 -0
- package/packages/drop-core/deploy.ts +41 -5
- package/packages/drop-core/errors.test.ts +32 -3
- package/packages/drop-core/errors.ts +67 -10
- package/packages/drop-core/index.ts +41 -11
- package/packages/drop-core/readFiles.test.ts +0 -1
|
@@ -17,12 +17,11 @@ interface Props {
|
|
|
17
17
|
*/
|
|
18
18
|
siteDashboardUrl?: (siteName: string) => string;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* point at your own destination.
|
|
20
|
+
* The signup hand-off for a build-required drop that can't be built here (no
|
|
21
|
+
* session, or no build wiring). The drop is stashed on this origin first, so
|
|
22
|
+
* a flow that returns the visitor to this page deploys it automatically —
|
|
23
|
+
* see `resumeStashedBuilds`. Defaults to the app signup page with
|
|
24
|
+
* `next=/drop`.
|
|
26
25
|
*/
|
|
27
26
|
buildSignupUrl?: string;
|
|
28
27
|
/**
|
|
@@ -32,7 +31,7 @@ interface Props {
|
|
|
32
31
|
* build-required drops build in place instead of being handed off to the app.
|
|
33
32
|
* On netlify.com this reads `GET /access-control/generate-access-control-token`.
|
|
34
33
|
* Resolving `null` means "no session": static drops fall back to the anonymous
|
|
35
|
-
* claim flow
|
|
34
|
+
* claim flow; build drops are stashed and handed to `buildSignupUrl`.
|
|
36
35
|
* See [Logged-in visitors](#logged-in-visitors).
|
|
37
36
|
*/
|
|
38
37
|
getUploadToken?: () => Promise<string | null>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { u as e } from "../../../chunks/jsxRuntime.module.Bzuv3cXw.js";
|
|
2
2
|
import { A as E, d as K, y as L } from "../../../chunks/hooks.module.DRcxknIz.js";
|
|
3
|
-
import {
|
|
3
|
+
import { DROPZONE_EVENTS as W } from "../../../drop-core/analytics.js";
|
|
4
|
+
import { readFileList as q, readDataTransfer as H } from "../../../drop-core/readFiles.js";
|
|
4
5
|
import { getFileTypes as z } from "../../../drop-core/fileTypes.js";
|
|
5
6
|
import "../../../drop-core/detectBuild.js";
|
|
6
7
|
import "../../../drop-core/zip.js";
|
|
7
|
-
import { DROPZONE_EVENTS as H } from "../../../drop-core/analytics.js";
|
|
8
8
|
import { useDropDeploy as J } from "./useDropDeploy.js";
|
|
9
9
|
import { Fragment as w } from "preact";
|
|
10
10
|
import '../../../assets/DropZone.css';const Q = 120, X = (r) => `https://app.netlify.com/drop/${r}`, Y = (r) => `https://app.netlify.com/projects/${r}`, ee = "https://app.netlify.com/signup?next=/drop&utm_campaign=drop", re = ({ siteName: r }) => `https://app.netlify.com/projects/${r}`;
|
|
@@ -55,7 +55,7 @@ function fe({
|
|
|
55
55
|
track: m
|
|
56
56
|
}), { active: p, keepActive: V, endDrag: M } = te(), h = E(null), v = (t) => {
|
|
57
57
|
var n;
|
|
58
|
-
m(
|
|
58
|
+
m(W.BROWSE_OPENED, { method: t }), (n = h.current) == null || n.click();
|
|
59
59
|
}, Z = f && (p || i || s.kind === "error"), G = [
|
|
60
60
|
"n-dropzone",
|
|
61
61
|
p && "is-active",
|
|
@@ -78,7 +78,7 @@ function fe({
|
|
|
78
78
|
onDrop: (t) => {
|
|
79
79
|
if (t.preventDefault(), M(), i) return;
|
|
80
80
|
const n = t.dataTransfer;
|
|
81
|
-
n && b(() =>
|
|
81
|
+
n && b(() => H(n), "drag", z(n.files));
|
|
82
82
|
},
|
|
83
83
|
onClick: (t) => {
|
|
84
84
|
!i && t.target === t.currentTarget && v("click");
|
|
@@ -102,7 +102,7 @@ function fe({
|
|
|
102
102
|
const n = t.currentTarget;
|
|
103
103
|
if ((D = n.files) != null && D.length) {
|
|
104
104
|
const k = n.files;
|
|
105
|
-
b(() =>
|
|
105
|
+
b(() => q(k), "browse", z(k));
|
|
106
106
|
}
|
|
107
107
|
n.value = "";
|
|
108
108
|
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import { default as o } from "./DropZone.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
2
|
+
import { BuildCreateError as i, BuildFailedError as p, BuildTimeoutError as d, NotAuthenticatedError as l, SiteCreateError as u, UnsupportedDropError as a, humanizeDropError as f } from "../../../drop-core/errors.js";
|
|
3
|
+
import { DROPZONE_EVENTS as n } from "../../../drop-core/analytics.js";
|
|
4
|
+
import { readDataTransfer as E, readFileList as s } from "../../../drop-core/readFiles.js";
|
|
5
|
+
import { getFileTypes as D } from "../../../drop-core/fileTypes.js";
|
|
6
|
+
import { detectBuild as F, inferBuildSettings as c } from "../../../drop-core/detectBuild.js";
|
|
7
|
+
import { zipFiles as y } from "../../../drop-core/zip.js";
|
|
8
|
+
import { AnonymousDropClient as T } from "../../../drop-core/client.js";
|
|
9
|
+
import { AuthenticatedDropClient as S } from "../../../drop-core/authedDropClient.js";
|
|
10
|
+
import { AuthenticatedBuildClient as z } from "../../../drop-core/buildClient.js";
|
|
11
|
+
import { deployBuild as Z, deployFiles as L } from "../../../drop-core/deploy.js";
|
|
12
12
|
export {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
T as AnonymousDropClient,
|
|
14
|
+
z as AuthenticatedBuildClient,
|
|
15
|
+
S as AuthenticatedDropClient,
|
|
16
|
+
i as BuildCreateError,
|
|
17
|
+
p as BuildFailedError,
|
|
18
|
+
d as BuildTimeoutError,
|
|
19
|
+
n as DROPZONE_EVENTS,
|
|
20
20
|
o as DropZone,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
l as NotAuthenticatedError,
|
|
22
|
+
u as SiteCreateError,
|
|
23
|
+
a as UnsupportedDropError,
|
|
24
|
+
Z as deployBuild,
|
|
25
|
+
L as deployFiles,
|
|
26
|
+
F as detectBuild,
|
|
27
|
+
D as getFileTypes,
|
|
28
|
+
f as humanizeDropError,
|
|
29
|
+
c as inferBuildSettings,
|
|
30
|
+
E as readDataTransfer,
|
|
31
|
+
s as readFileList,
|
|
32
|
+
y as zipFiles
|
|
33
33
|
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { d as R, A as S, y as nt } from "../../../chunks/hooks.module.DRcxknIz.js";
|
|
2
|
-
import {
|
|
3
|
-
import { detectBuild as st } from "../../../drop-core/detectBuild.js";
|
|
4
|
-
import { AnonymousDropClient as dt } from "../../../drop-core/client.js";
|
|
5
|
-
import { humanizeDropError as lt, NotAuthenticatedError as O } from "../../../drop-core/errors.js";
|
|
6
|
-
import { AuthenticatedDropClient as ut } from "../../../drop-core/authedDropClient.js";
|
|
7
|
-
import { AuthenticatedBuildClient as ct } from "../../../drop-core/buildClient.js";
|
|
8
|
-
import { zipFiles as mt } from "../../../drop-core/zip.js";
|
|
9
|
-
import { hasDropStashMarker as ft, loadDropStash as gt, clearDropStash as E, saveDropStash as ht } from "../../../drop-core/buildStash.js";
|
|
10
|
-
import { deployZippedBuild as pt, deployFiles as v } from "../../../drop-core/deploy.js";
|
|
2
|
+
import { humanizeDropError as rt, isNotAuthenticatedError as O } from "../../../drop-core/errors.js";
|
|
11
3
|
import { DROPZONE_EVENTS as c } from "../../../drop-core/analytics.js";
|
|
4
|
+
import { renameSingleNonIndexHtmlToIndex as at, getSingleNonIndexHtmlFileName as ot, hasMultipleHtmlFilesWithoutIndex as st } from "../../../drop-core/readFiles.js";
|
|
5
|
+
import { detectBuild as dt } from "../../../drop-core/detectBuild.js";
|
|
6
|
+
import { zipFiles as lt } from "../../../drop-core/zip.js";
|
|
7
|
+
import { AnonymousDropClient as ut } from "../../../drop-core/client.js";
|
|
8
|
+
import { AuthenticatedDropClient as ct } from "../../../drop-core/authedDropClient.js";
|
|
9
|
+
import { AuthenticatedBuildClient as mt } from "../../../drop-core/buildClient.js";
|
|
10
|
+
import { deployZippedBuild as ft, deployFiles as v } from "../../../drop-core/deploy.js";
|
|
11
|
+
import { hasDropStashMarker as gt, loadDropStash as ht, clearDropStash as E, saveDropStash as pt } from "../../../drop-core/buildStash.js";
|
|
12
12
|
function I(l) {
|
|
13
13
|
switch (l.phase) {
|
|
14
14
|
case "zipping":
|
|
@@ -25,8 +25,8 @@ function I(l) {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
function wt(l) {
|
|
28
|
-
const m =
|
|
29
|
-
return m ? `No index.html found — "${m}" won’t be served at the site root.` :
|
|
28
|
+
const m = ot(l);
|
|
29
|
+
return m ? `No index.html found — "${m}" won’t be served at the site root.` : st(l) ? "No index.html found — your site may not have a landing page." : null;
|
|
30
30
|
}
|
|
31
31
|
function St(l, m) {
|
|
32
32
|
try {
|
|
@@ -56,18 +56,16 @@ function Pt({
|
|
|
56
56
|
track: q
|
|
57
57
|
}) {
|
|
58
58
|
const u = (n, t) => (
|
|
59
|
-
// The
|
|
60
|
-
// signature (so payloads stay closed for consumers), and the checking that
|
|
61
|
-
// matters happened against DropZoneEventProperties[E] above.
|
|
59
|
+
// The event interfaces carry no index signature, hence the cast to TrackFn's record.
|
|
62
60
|
q(n, t)
|
|
63
|
-
), [b, a] = R({ kind: "idle" }), [U, _] = R(null), j = S(m ?? new
|
|
64
|
-
Y ?? (p ? new
|
|
61
|
+
), [b, a] = R({ kind: "idle" }), [U, _] = R(null), j = S(m ?? new ut(l)).current, w = S(
|
|
62
|
+
Y ?? (p ? new mt({ proxyBase: N, getUploadToken: p, accountSlug: A }) : null)
|
|
65
63
|
).current, y = S(
|
|
66
|
-
M ?? (p ? new
|
|
64
|
+
M ?? (p ? new ct({ proxyBase: N, getUploadToken: p, accountSlug: A }) : null)
|
|
67
65
|
).current, J = b.kind !== "idle" && b.kind !== "error";
|
|
68
66
|
async function x(n, t) {
|
|
69
67
|
try {
|
|
70
|
-
const { site: i, build: r, buildSettings: o, url: e } = await
|
|
68
|
+
const { site: i, build: r, buildSettings: o, url: e } = await ft(n, t, {
|
|
71
69
|
onProgress: (s) => a(I(s)),
|
|
72
70
|
waitForBuild: Z
|
|
73
71
|
});
|
|
@@ -80,7 +78,7 @@ function Pt({
|
|
|
80
78
|
buildSettings: o
|
|
81
79
|
};
|
|
82
80
|
} catch (i) {
|
|
83
|
-
if (i
|
|
81
|
+
if (O(i)) return null;
|
|
84
82
|
throw i;
|
|
85
83
|
}
|
|
86
84
|
}
|
|
@@ -90,7 +88,7 @@ function Pt({
|
|
|
90
88
|
a({ kind: "error", message: e }), u(c.DEPLOY_FAILED, { method: t, reason: s, ...r, ...d }), g == null || g({ message: e, reason: s });
|
|
91
89
|
};
|
|
92
90
|
try {
|
|
93
|
-
const e =
|
|
91
|
+
const e = at(await n());
|
|
94
92
|
if (!e.length) {
|
|
95
93
|
o("No files found to deploy.", "No files found to deploy.", { file_count: 0 });
|
|
96
94
|
return;
|
|
@@ -100,11 +98,11 @@ function Pt({
|
|
|
100
98
|
file_count: e.length,
|
|
101
99
|
...r
|
|
102
100
|
});
|
|
103
|
-
const s = { source: t, fileCount: e.length, typeProps: r }, d =
|
|
101
|
+
const s = { source: t, fileCount: e.length, typeProps: r }, d = dt(e);
|
|
104
102
|
d.buildRequired ? await T(e, d, s) : await G(e, s);
|
|
105
103
|
} catch (e) {
|
|
106
104
|
const s = e instanceof Error ? e.message : String(e);
|
|
107
|
-
o(
|
|
105
|
+
o(rt(e), s);
|
|
108
106
|
}
|
|
109
107
|
}
|
|
110
108
|
async function T(n, t, { source: i, fileCount: r, typeProps: o }) {
|
|
@@ -120,7 +118,7 @@ function Pt({
|
|
|
120
118
|
let e = !1;
|
|
121
119
|
if (w) {
|
|
122
120
|
a({ kind: "zipping" });
|
|
123
|
-
const s = await
|
|
121
|
+
const s = await lt(n), d = await x(w, s);
|
|
124
122
|
if (d) {
|
|
125
123
|
a({ kind: "redirecting", target: "build" }), u(c.BUILD_DEPLOY_SUCCEEDED, {
|
|
126
124
|
method: i,
|
|
@@ -132,7 +130,7 @@ function Pt({
|
|
|
132
130
|
}), f == null || f(d), window.location.assign(C(d));
|
|
133
131
|
return;
|
|
134
132
|
}
|
|
135
|
-
e = await
|
|
133
|
+
e = await pt(s.file, s.buildSettings), e && u(c.PROJECT_STASHED, {
|
|
136
134
|
method: i,
|
|
137
135
|
reason: t.reason,
|
|
138
136
|
file_count: r,
|
|
@@ -151,7 +149,7 @@ function Pt({
|
|
|
151
149
|
onProgress: (i) => a(I(i))
|
|
152
150
|
});
|
|
153
151
|
} catch (i) {
|
|
154
|
-
if (i
|
|
152
|
+
if (O(i)) return null;
|
|
155
153
|
throw i;
|
|
156
154
|
}
|
|
157
155
|
}
|
|
@@ -179,7 +177,7 @@ function Pt({
|
|
|
179
177
|
n ? window.location.assign(H(t)) : window.location.assign(`${z(t)}#drop_token=${i}`);
|
|
180
178
|
}
|
|
181
179
|
async function X(n) {
|
|
182
|
-
const t = await
|
|
180
|
+
const t = await ht();
|
|
183
181
|
if (!t) {
|
|
184
182
|
await E();
|
|
185
183
|
return;
|
|
@@ -205,7 +203,7 @@ function Pt({
|
|
|
205
203
|
}
|
|
206
204
|
const F = S(!1);
|
|
207
205
|
nt(() => {
|
|
208
|
-
F.current || !$ || !w || !
|
|
206
|
+
F.current || !$ || !w || !gt() || (F.current = !0, X(w));
|
|
209
207
|
}, []);
|
|
210
208
|
function tt() {
|
|
211
209
|
_(null), a({ kind: "idle" });
|
|
@@ -9,19 +9,19 @@ import "preact";
|
|
|
9
9
|
import "../../chunks/hooks.module.DRcxknIz.js";
|
|
10
10
|
import { default as D } from "./SearchModal/components/SearchModal/SearchModal.js";
|
|
11
11
|
import { default as N } from "./DropZone/DropZone.js";
|
|
12
|
+
import { humanizeDropError as k } from "../../drop-core/errors.js";
|
|
13
|
+
import { DROPZONE_EVENTS as K } from "../../drop-core/analytics.js";
|
|
12
14
|
import "../../drop-core/readFiles.js";
|
|
13
|
-
import { getFileTypes as
|
|
15
|
+
import { getFileTypes as O } from "../../drop-core/fileTypes.js";
|
|
14
16
|
import "../../drop-core/detectBuild.js";
|
|
15
|
-
import { humanizeDropError as K } from "../../drop-core/errors.js";
|
|
16
|
-
import { AuthenticatedDropClient as O } from "../../drop-core/authedDropClient.js";
|
|
17
|
-
import { AuthenticatedBuildClient as b } from "../../drop-core/buildClient.js";
|
|
18
17
|
import "../../drop-core/zip.js";
|
|
19
|
-
import {
|
|
18
|
+
import { AuthenticatedDropClient as b } from "../../drop-core/authedDropClient.js";
|
|
19
|
+
import { AuthenticatedBuildClient as B } from "../../drop-core/buildClient.js";
|
|
20
20
|
export {
|
|
21
21
|
y as AskNetlify,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
B as AuthenticatedBuildClient,
|
|
23
|
+
b as AuthenticatedDropClient,
|
|
24
|
+
K as DROPZONE_EVENTS,
|
|
25
25
|
N as DropZone,
|
|
26
26
|
x as Icon,
|
|
27
27
|
m as KeyboardKey,
|
|
@@ -30,6 +30,6 @@ export {
|
|
|
30
30
|
s as SearchLink,
|
|
31
31
|
D as SearchModal,
|
|
32
32
|
S as SearchToggle,
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
O as getFileTypes,
|
|
34
|
+
k as humanizeDropError
|
|
35
35
|
};
|
|
@@ -6,16 +6,6 @@ import { BuildSite } from './types';
|
|
|
6
6
|
* (Uploads are the exception — the proxy's Lambda caps request bodies at
|
|
7
7
|
* ~6MB — and each client handles its own, bearer-authorized.)
|
|
8
8
|
*/
|
|
9
|
-
/**
|
|
10
|
-
* Default root for proxied JSON calls. On netlify.com the `/access-control/*`
|
|
11
|
-
* rewrite targets the app's access-control function, making this path the API
|
|
12
|
-
* root. The paths a given origin may call are allowlisted server-side.
|
|
13
|
-
*/
|
|
14
|
-
export declare const DEFAULT_PROXY_BASE = "/access-control/bb-api/api/v1";
|
|
15
|
-
/** Direct api.netlify.com root for the uploads the proxy can't carry. */
|
|
16
|
-
export declare const DEFAULT_API_BASE = "https://api.netlify.com/api/v1";
|
|
17
|
-
export declare const DEFAULT_POLL_INTERVAL_MS = 1000;
|
|
18
|
-
export declare const DEFAULT_TIMEOUT_MS: number;
|
|
19
9
|
/**
|
|
20
10
|
* Create a site in the visitor's account via `POST {proxyBase}/sites` (scoped
|
|
21
11
|
* to `accountSlug` when given, else the user's default account), attributed
|
|
@@ -1,35 +1,30 @@
|
|
|
1
1
|
import { NotAuthenticatedError as d, SiteCreateError as l } from "./errors.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const r = o ? `/${o}/sites` : "/sites", t = await fetch(`${s}${r}`, {
|
|
2
|
+
async function f(r, o) {
|
|
3
|
+
const s = o ? `/${o}/sites` : "/sites", e = await fetch(`${r}${s}`, {
|
|
5
4
|
method: "POST",
|
|
6
5
|
credentials: "include",
|
|
7
6
|
headers: { "Content-Type": "application/json" },
|
|
8
7
|
body: JSON.stringify({ created_via: "drop" })
|
|
9
8
|
});
|
|
10
|
-
if (
|
|
11
|
-
if (!
|
|
12
|
-
return
|
|
9
|
+
if (e.status === 401 || e.status === 403) throw new d();
|
|
10
|
+
if (!e.ok) throw new l(e.status);
|
|
11
|
+
return e.json();
|
|
13
12
|
}
|
|
14
|
-
const
|
|
15
|
-
async function
|
|
16
|
-
const { proxyBase: o, deployId:
|
|
13
|
+
const u = /* @__PURE__ */ new Set(["ready", "error", "rejected"]);
|
|
14
|
+
async function y(r) {
|
|
15
|
+
const { proxyBase: o, deployId: s, pollIntervalMs: e, timeoutMs: i } = r, c = i / e;
|
|
17
16
|
for (let n = 0; n < c; n++) {
|
|
18
|
-
const a = await fetch(`${o}/deploys/${
|
|
17
|
+
const a = await fetch(`${o}/deploys/${s}`, { credentials: "include" });
|
|
19
18
|
if (a.ok) {
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
return
|
|
19
|
+
const t = await a.json();
|
|
20
|
+
if (t.state && u.has(t.state))
|
|
21
|
+
return t.state === "ready" ? { outcome: "ready" } : { outcome: "failed", errorMessage: t.error_message };
|
|
23
22
|
}
|
|
24
|
-
await new Promise((
|
|
23
|
+
await new Promise((t) => setTimeout(t, e));
|
|
25
24
|
}
|
|
26
25
|
return { outcome: "timed-out" };
|
|
27
26
|
}
|
|
28
27
|
export {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
f as DEFAULT_PROXY_BASE,
|
|
32
|
-
m as DEFAULT_TIMEOUT_MS,
|
|
33
|
-
A as createSiteInAccount,
|
|
34
|
-
E as pollDeployUntilSettled
|
|
28
|
+
f as createSiteInAccount,
|
|
29
|
+
y as pollDeployUntilSettled
|
|
35
30
|
};
|
|
@@ -62,21 +62,14 @@ export declare class AuthenticatedDropClient implements DropClient {
|
|
|
62
62
|
private cachedToken?;
|
|
63
63
|
constructor({ proxyBase, apiBase, getUploadToken, accountSlug, pollIntervalMs, timeoutMs, }: AuthenticatedDropClientConfig);
|
|
64
64
|
/**
|
|
65
|
-
* The auth gate
|
|
66
|
-
* logged-out visitor fail cleanly and fall back to the anonymous flow.
|
|
67
|
-
* returned token is threaded through `deployFiles`, but only the uploads
|
|
68
|
-
* actually need one, and they re-mint rather than trusting this to still be
|
|
69
|
-
* valid by the time they run.
|
|
65
|
+
* The auth gate: minting here, before anything is created, is what lets a
|
|
66
|
+
* logged-out visitor fail cleanly and fall back to the anonymous flow.
|
|
70
67
|
*/
|
|
71
68
|
getToken(): Promise<string>;
|
|
72
69
|
/**
|
|
73
70
|
* A token young enough to authorize an upload, minting a new one once the
|
|
74
|
-
* cached one nears its 30s expiry.
|
|
75
|
-
*
|
|
76
|
-
* Deliberately NOT `NotAuthenticatedError` when minting fails: by the time
|
|
77
|
-
* uploads run the site already exists, and that error would send the drop
|
|
78
|
-
* back through the anonymous path — leaving an empty project behind and
|
|
79
|
-
* deploying a duplicate. See the class doc.
|
|
71
|
+
* cached one nears its 30s expiry. A mint failure here is a plain `Error`,
|
|
72
|
+
* never `NotAuthenticatedError` — the site exists by now (class doc).
|
|
80
73
|
*/
|
|
81
74
|
private freshToken;
|
|
82
75
|
/**
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var a = (i, e, t) =>
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
class
|
|
1
|
+
var c = Object.defineProperty;
|
|
2
|
+
var d = (i, e, t) => e in i ? c(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
+
var a = (i, e, t) => d(i, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { createSiteInAccount as p, pollDeployUntilSettled as h } from "./authedApi.js";
|
|
5
|
+
import { DEFAULT_PROXY_BASE as u, DEFAULT_API_BASE as y, DEFAULT_POLL_INTERVAL_MS as T, DEFAULT_TIMEOUT_MS as m, TOKEN_REUSE_MS as w } from "./constants.js";
|
|
6
|
+
import { apiError as l } from "./client.js";
|
|
7
|
+
import { NotAuthenticatedError as k, DeployFailedError as f, DeployTimeoutError as _ } from "./errors.js";
|
|
8
|
+
class B {
|
|
9
9
|
constructor({
|
|
10
|
-
proxyBase: e =
|
|
11
|
-
apiBase: t =
|
|
10
|
+
proxyBase: e = u,
|
|
11
|
+
apiBase: t = y,
|
|
12
12
|
getUploadToken: o,
|
|
13
13
|
accountSlug: s,
|
|
14
|
-
pollIntervalMs: n =
|
|
15
|
-
timeoutMs: r =
|
|
14
|
+
pollIntervalMs: n = T,
|
|
15
|
+
timeoutMs: r = m
|
|
16
16
|
}) {
|
|
17
17
|
a(this, "proxyBase");
|
|
18
18
|
a(this, "apiBase");
|
|
@@ -24,29 +24,22 @@ class M {
|
|
|
24
24
|
this.proxyBase = e, this.apiBase = t, this.getUploadToken = o, this.accountSlug = s, this.pollIntervalMs = n, this.timeoutMs = r;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
* The auth gate
|
|
28
|
-
* logged-out visitor fail cleanly and fall back to the anonymous flow.
|
|
29
|
-
* returned token is threaded through `deployFiles`, but only the uploads
|
|
30
|
-
* actually need one, and they re-mint rather than trusting this to still be
|
|
31
|
-
* valid by the time they run.
|
|
27
|
+
* The auth gate: minting here, before anything is created, is what lets a
|
|
28
|
+
* logged-out visitor fail cleanly and fall back to the anonymous flow.
|
|
32
29
|
*/
|
|
33
30
|
async getToken() {
|
|
34
31
|
const e = await this.getUploadToken();
|
|
35
|
-
if (!e) throw new
|
|
32
|
+
if (!e) throw new k();
|
|
36
33
|
return this.cachedToken = { value: e, mintedAt: Date.now() }, e;
|
|
37
34
|
}
|
|
38
35
|
/**
|
|
39
36
|
* A token young enough to authorize an upload, minting a new one once the
|
|
40
|
-
* cached one nears its 30s expiry.
|
|
41
|
-
*
|
|
42
|
-
* Deliberately NOT `NotAuthenticatedError` when minting fails: by the time
|
|
43
|
-
* uploads run the site already exists, and that error would send the drop
|
|
44
|
-
* back through the anonymous path — leaving an empty project behind and
|
|
45
|
-
* deploying a duplicate. See the class doc.
|
|
37
|
+
* cached one nears its 30s expiry. A mint failure here is a plain `Error`,
|
|
38
|
+
* never `NotAuthenticatedError` — the site exists by now (class doc).
|
|
46
39
|
*/
|
|
47
40
|
async freshToken() {
|
|
48
41
|
const e = Date.now();
|
|
49
|
-
if (this.cachedToken && e - this.cachedToken.mintedAt <
|
|
42
|
+
if (this.cachedToken && e - this.cachedToken.mintedAt < w)
|
|
50
43
|
return this.cachedToken.value;
|
|
51
44
|
const t = await this.getUploadToken();
|
|
52
45
|
if (!t) throw new Error("could not renew the upload token");
|
|
@@ -58,13 +51,13 @@ class M {
|
|
|
58
51
|
* `deployFiles` runs unchanged over either client.
|
|
59
52
|
*/
|
|
60
53
|
async createDeploy(e, t) {
|
|
61
|
-
const o = await
|
|
54
|
+
const o = await p(this.proxyBase, this.accountSlug), s = await fetch(`${this.proxyBase}/sites/${o.id}/deploys`, {
|
|
62
55
|
method: "POST",
|
|
63
56
|
credentials: "include",
|
|
64
57
|
headers: { "Content-Type": "application/json" },
|
|
65
58
|
body: JSON.stringify({ files: e, deploy_source: "drop" })
|
|
66
59
|
});
|
|
67
|
-
if (!s.ok) throw
|
|
60
|
+
if (!s.ok) throw l("deploy create", s.status);
|
|
68
61
|
const n = await s.json();
|
|
69
62
|
return {
|
|
70
63
|
id: o.id,
|
|
@@ -84,7 +77,7 @@ class M {
|
|
|
84
77
|
headers: { "Content-Type": "application/octet-stream", Authorization: `Bearer ${n}` },
|
|
85
78
|
body: o
|
|
86
79
|
});
|
|
87
|
-
if (!r.ok) throw
|
|
80
|
+
if (!r.ok) throw l(`upload ${t}`, r.status);
|
|
88
81
|
}
|
|
89
82
|
/**
|
|
90
83
|
* Poll the deploy through the proxy until it settles: resolve on `ready`,
|
|
@@ -92,18 +85,16 @@ class M {
|
|
|
92
85
|
* than a bearer, so a deploy taking minutes can't outlive its own credentials.
|
|
93
86
|
*/
|
|
94
87
|
async waitUntilReady(e, t) {
|
|
95
|
-
const o = await
|
|
88
|
+
const o = await h({
|
|
96
89
|
proxyBase: this.proxyBase,
|
|
97
90
|
deployId: e.deploy_id,
|
|
98
91
|
pollIntervalMs: this.pollIntervalMs,
|
|
99
92
|
timeoutMs: this.timeoutMs
|
|
100
93
|
});
|
|
101
94
|
if (o.outcome !== "ready")
|
|
102
|
-
throw o.outcome === "failed" ? new
|
|
103
|
-
o.errorMessage ? `deploy failed: ${o.errorMessage}` : "deploy failed"
|
|
104
|
-
) : new Error("Deploy did not become ready in time");
|
|
95
|
+
throw o.outcome === "failed" ? new f(o.errorMessage) : new _();
|
|
105
96
|
}
|
|
106
97
|
}
|
|
107
98
|
export {
|
|
108
|
-
|
|
99
|
+
B as AuthenticatedDropClient
|
|
109
100
|
};
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var o = (r, t, e) =>
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
1
|
+
var u = Object.defineProperty;
|
|
2
|
+
var d = (r, t, e) => t in r ? u(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
3
|
+
var o = (r, t, e) => d(r, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { createSiteInAccount as c, pollDeployUntilSettled as h } from "./authedApi.js";
|
|
5
|
+
import { DEFAULT_PROXY_BASE as m, DEFAULT_API_BASE as B, DEFAULT_POLL_INTERVAL_MS as y, DEFAULT_TIMEOUT_MS as w } from "./constants.js";
|
|
6
|
+
import { NotAuthenticatedError as l, BuildCreateError as f, BuildFailedError as A, BuildTimeoutError as E } from "./errors.js";
|
|
7
|
+
class U {
|
|
7
8
|
constructor({
|
|
8
|
-
proxyBase: t =
|
|
9
|
-
apiBase: e =
|
|
9
|
+
proxyBase: t = m,
|
|
10
|
+
apiBase: e = B,
|
|
10
11
|
getUploadToken: a,
|
|
11
12
|
accountSlug: s,
|
|
12
13
|
title: i = "Build from drop deployment",
|
|
13
|
-
pollIntervalMs: n =
|
|
14
|
-
timeoutMs:
|
|
14
|
+
pollIntervalMs: n = y,
|
|
15
|
+
timeoutMs: p = w
|
|
15
16
|
}) {
|
|
16
17
|
o(this, "proxyBase");
|
|
17
18
|
o(this, "apiBase");
|
|
@@ -20,7 +21,7 @@ class _ {
|
|
|
20
21
|
o(this, "title");
|
|
21
22
|
o(this, "pollIntervalMs");
|
|
22
23
|
o(this, "timeoutMs");
|
|
23
|
-
this.proxyBase = t, this.apiBase = e, this.getUploadToken = a, this.accountSlug = s, this.title = i, this.pollIntervalMs = n, this.timeoutMs =
|
|
24
|
+
this.proxyBase = t, this.apiBase = e, this.getUploadToken = a, this.accountSlug = s, this.title = i, this.pollIntervalMs = n, this.timeoutMs = p;
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
27
|
* Create the site the build deploys into. A logged-out visitor fails here,
|
|
@@ -28,7 +29,7 @@ class _ {
|
|
|
28
29
|
* mapping that makes the signup fallback safe.
|
|
29
30
|
*/
|
|
30
31
|
async createSite() {
|
|
31
|
-
return
|
|
32
|
+
return c(this.proxyBase, this.accountSlug);
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
35
|
* Upload the source archive and enqueue a build. Direct to `api.netlify.com`
|
|
@@ -52,7 +53,7 @@ class _ {
|
|
|
52
53
|
body: s
|
|
53
54
|
});
|
|
54
55
|
if (i.status === 401 || i.status === 403) throw new l();
|
|
55
|
-
if (!i.ok) throw new
|
|
56
|
+
if (!i.ok) throw new f(i.status);
|
|
56
57
|
return i.json();
|
|
57
58
|
}
|
|
58
59
|
/**
|
|
@@ -69,16 +70,16 @@ class _ {
|
|
|
69
70
|
*/
|
|
70
71
|
async waitUntilBuildReady(t) {
|
|
71
72
|
if (!t.deploy_id) return;
|
|
72
|
-
const e = await
|
|
73
|
+
const e = await h({
|
|
73
74
|
proxyBase: this.proxyBase,
|
|
74
75
|
deployId: t.deploy_id,
|
|
75
76
|
pollIntervalMs: this.pollIntervalMs,
|
|
76
77
|
timeoutMs: this.timeoutMs
|
|
77
78
|
});
|
|
78
79
|
if (e.outcome !== "ready")
|
|
79
|
-
throw e.outcome === "failed" ? new
|
|
80
|
+
throw e.outcome === "failed" ? new A(e.errorMessage) : new E();
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
export {
|
|
83
|
-
|
|
84
|
+
U as AuthenticatedBuildClient
|
|
84
85
|
};
|
|
@@ -15,7 +15,9 @@ export interface DropClient {
|
|
|
15
15
|
*/
|
|
16
16
|
export declare class AnonymousDropClient implements DropClient {
|
|
17
17
|
private apiBase;
|
|
18
|
-
|
|
18
|
+
private pollIntervalMs;
|
|
19
|
+
private timeoutMs;
|
|
20
|
+
constructor(apiBase?: string, pollIntervalMs?: number, timeoutMs?: number);
|
|
19
21
|
getToken(): Promise<string>;
|
|
20
22
|
createDeploy(files: Digest, token: string): Promise<DropResponse>;
|
|
21
23
|
uploadFile(deployId: string, path: string, content: ArrayBuffer, token: string): Promise<void>;
|