@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
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* deployed as a one-asset site (matches react-ui).
|
|
7
7
|
*/
|
|
8
8
|
export class UnsupportedDropError extends Error {
|
|
9
|
+
readonly code = 'unsupported-drop';
|
|
10
|
+
|
|
9
11
|
constructor() {
|
|
10
12
|
super('unsupported single file');
|
|
11
13
|
this.name = 'UnsupportedDropError';
|
|
@@ -21,14 +23,30 @@ export class UnsupportedDropError extends Error {
|
|
|
21
23
|
* through login/signup and have them drop again.
|
|
22
24
|
*/
|
|
23
25
|
export class NotAuthenticatedError extends Error {
|
|
26
|
+
readonly code = 'not-authenticated';
|
|
27
|
+
|
|
24
28
|
constructor(message = 'not authenticated') {
|
|
25
29
|
super(message);
|
|
26
30
|
this.name = 'NotAuthenticatedError';
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Whether an error is the pre-mutation "no session" signal, however it
|
|
36
|
+
* traveled. This package ships as both raw TypeScript (`./components`) and
|
|
37
|
+
* compiled dist (`./preact`, `./drop-core`), so two copies of the class can
|
|
38
|
+
* coexist in one app and defeat `instanceof` — the `code` brand is the
|
|
39
|
+
* copy-proof fallback. Control flow that decides whether an anonymous retry
|
|
40
|
+
* is safe must use this, never a bare `instanceof`.
|
|
41
|
+
*/
|
|
42
|
+
export function isNotAuthenticatedError(err: unknown): err is NotAuthenticatedError {
|
|
43
|
+
if (err instanceof NotAuthenticatedError) return true;
|
|
44
|
+
return err instanceof Error && (err as { code?: string }).code === 'not-authenticated';
|
|
45
|
+
}
|
|
46
|
+
|
|
30
47
|
/** `POST …/sites` failed, so there is nothing to build into. Carries the HTTP status. */
|
|
31
48
|
export class SiteCreateError extends Error {
|
|
49
|
+
readonly code = 'site-create-failed';
|
|
32
50
|
status?: number;
|
|
33
51
|
|
|
34
52
|
constructor(status?: number) {
|
|
@@ -43,6 +61,7 @@ export class SiteCreateError extends Error {
|
|
|
43
61
|
* started. Distinct from `BuildFailedError`, which is a build that ran and broke.
|
|
44
62
|
*/
|
|
45
63
|
export class BuildCreateError extends Error {
|
|
64
|
+
readonly code = 'build-create-failed';
|
|
46
65
|
status?: number;
|
|
47
66
|
|
|
48
67
|
constructor(status?: number) {
|
|
@@ -59,6 +78,8 @@ export class BuildCreateError extends Error {
|
|
|
59
78
|
* it is surfaced to the user rather than swallowed.
|
|
60
79
|
*/
|
|
61
80
|
export class BuildFailedError extends Error {
|
|
81
|
+
readonly code = 'build-failed';
|
|
82
|
+
|
|
62
83
|
constructor(public reason?: string) {
|
|
63
84
|
super(reason ? `build failed: ${reason}` : 'build failed');
|
|
64
85
|
this.name = 'BuildFailedError';
|
|
@@ -67,12 +88,37 @@ export class BuildFailedError extends Error {
|
|
|
67
88
|
|
|
68
89
|
/** The build hadn't settled before the poller gave up. The build itself may still finish. */
|
|
69
90
|
export class BuildTimeoutError extends Error {
|
|
91
|
+
readonly code = 'build-timeout';
|
|
92
|
+
|
|
70
93
|
constructor() {
|
|
71
94
|
super('Build did not finish in time');
|
|
72
95
|
this.name = 'BuildTimeoutError';
|
|
73
96
|
}
|
|
74
97
|
}
|
|
75
98
|
|
|
99
|
+
/**
|
|
100
|
+
* A static deploy ran and ended in `error`/`rejected`. Like a build failure,
|
|
101
|
+
* the API's `error_message` is the actionable part, so it travels on the error.
|
|
102
|
+
*/
|
|
103
|
+
export class DeployFailedError extends Error {
|
|
104
|
+
readonly code = 'deploy-failed';
|
|
105
|
+
|
|
106
|
+
constructor(public reason?: string) {
|
|
107
|
+
super(reason ? `deploy failed: ${reason}` : 'deploy failed');
|
|
108
|
+
this.name = 'DeployFailedError';
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The deploy hadn't gone ready before the poller gave up. It may still finish. */
|
|
113
|
+
export class DeployTimeoutError extends Error {
|
|
114
|
+
readonly code = 'deploy-timeout';
|
|
115
|
+
|
|
116
|
+
constructor() {
|
|
117
|
+
super('Deploy did not become ready in time');
|
|
118
|
+
this.name = 'DeployTimeoutError';
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
76
122
|
/**
|
|
77
123
|
* Turn a raw deploy failure into copy a non-technical user can act on.
|
|
78
124
|
* The original message is still tracked via analytics — this is only for display.
|
|
@@ -80,31 +126,42 @@ export class BuildTimeoutError extends Error {
|
|
|
80
126
|
export function humanizeDropError(err: unknown): string {
|
|
81
127
|
if (!(err instanceof Error)) return 'Something went wrong. Please try again.';
|
|
82
128
|
|
|
83
|
-
|
|
129
|
+
// Match on the `code` brand rather than instanceof: raw-TS and dist copies
|
|
130
|
+
// of these classes can coexist (see isNotAuthenticatedError).
|
|
131
|
+
const code = (err as { code?: string }).code;
|
|
132
|
+
|
|
133
|
+
if (code === 'unsupported-drop') {
|
|
84
134
|
return 'To deploy, drop a folder or a .zip file — or a single HTML page.';
|
|
85
135
|
}
|
|
86
136
|
|
|
87
|
-
if (
|
|
137
|
+
if (code === 'not-authenticated') {
|
|
88
138
|
return 'Please log in to Netlify to deploy this project, then try again.';
|
|
89
139
|
}
|
|
90
140
|
|
|
91
|
-
if (
|
|
141
|
+
if (code === 'site-create-failed') {
|
|
92
142
|
return "We couldn't create a project for this build. Please try again.";
|
|
93
143
|
}
|
|
94
144
|
|
|
95
|
-
// The
|
|
96
|
-
//
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
145
|
+
// The failure's own error message is the only actionable part, so pass it
|
|
146
|
+
// straight through instead of a generic apology.
|
|
147
|
+
if (code === 'build-failed') {
|
|
148
|
+
const reason = (err as BuildFailedError).reason;
|
|
149
|
+
return reason
|
|
150
|
+
? `Your build failed: ${reason}`
|
|
100
151
|
: 'Your build failed. Check your build settings and try again.';
|
|
101
152
|
}
|
|
153
|
+
if (code === 'deploy-failed') {
|
|
154
|
+
const reason = (err as DeployFailedError).reason;
|
|
155
|
+
return reason
|
|
156
|
+
? `Your deploy failed: ${reason}`
|
|
157
|
+
: 'Your deploy failed. Please try again.';
|
|
158
|
+
}
|
|
102
159
|
|
|
103
|
-
if (
|
|
160
|
+
if (code === 'build-timeout') {
|
|
104
161
|
return 'Your build is taking longer than expected. It may still finish — check your Netlify dashboard.';
|
|
105
162
|
}
|
|
106
163
|
|
|
107
|
-
if (
|
|
164
|
+
if (code === 'deploy-timeout') {
|
|
108
165
|
return 'Your site is taking longer than expected to go live. Please try again in a moment.';
|
|
109
166
|
}
|
|
110
167
|
// fetch() rejects with a TypeError when the network is unreachable (offline, DNS, CORS, etc).
|
|
@@ -1,14 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The public surface of drop-core — nothing is public unless named here.
|
|
3
|
+
* `export *` is reserved for the three modules that are contracts in their
|
|
4
|
+
* entirety: types, errors, and the analytics event map.
|
|
5
|
+
*/
|
|
6
|
+
|
|
1
7
|
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 './authedApi';
|
|
8
|
-
export * from './authedDropClient';
|
|
9
|
-
export * from './buildClient';
|
|
10
|
-
export * from './zip';
|
|
11
|
-
export * from './buildStash';
|
|
12
|
-
export * from './deploy';
|
|
13
8
|
export * from './errors';
|
|
14
9
|
export * from './analytics';
|
|
10
|
+
|
|
11
|
+
// Reading a drop into deployable files
|
|
12
|
+
export {
|
|
13
|
+
getSingleNonIndexHtmlFileName,
|
|
14
|
+
hasMultipleHtmlFilesWithoutIndex,
|
|
15
|
+
readDataTransfer,
|
|
16
|
+
readFileList,
|
|
17
|
+
renameSingleNonIndexHtmlToIndex,
|
|
18
|
+
} from './readFiles';
|
|
19
|
+
export { getFileTypes } from './fileTypes';
|
|
20
|
+
|
|
21
|
+
// Build detection and archive synthesis
|
|
22
|
+
export { detectBuild, inferBuildSettings } from './detectBuild';
|
|
23
|
+
export type { BuildDetection, BuildReason, InferredBuildSettings } from './detectBuild';
|
|
24
|
+
export { zipFiles } from './zip';
|
|
25
|
+
export type { ZipOptions, ZipResult } from './zip';
|
|
26
|
+
|
|
27
|
+
// Deploy clients — anonymous (claim flow) and authenticated (into the account)
|
|
28
|
+
export { AnonymousDropClient } from './client';
|
|
29
|
+
export type { DropClient } from './client';
|
|
30
|
+
export { AuthenticatedDropClient } from './authedDropClient';
|
|
31
|
+
export type { AuthenticatedDropClientConfig } from './authedDropClient';
|
|
32
|
+
export { AuthenticatedBuildClient } from './buildClient';
|
|
33
|
+
export type { AuthenticatedBuildClientConfig, BuildClient, BuildResponse } from './buildClient';
|
|
34
|
+
|
|
35
|
+
// Deploy orchestration
|
|
36
|
+
export { deployBuild, deployFiles, deployZippedBuild } from './deploy';
|
|
37
|
+
export type { BuildDeployOptions, BuildDeployResult, DeployOptions } from './deploy';
|
|
38
|
+
|
|
39
|
+
// Carrying a build drop across the signup round-trip
|
|
40
|
+
export { clearDropStash, hasDropStashMarker, loadDropStash, saveDropStash } from './buildStash';
|
|
41
|
+
export type { DropBuildStash } from './buildStash';
|
|
42
|
+
|
|
43
|
+
// Documented defaults consumers may want to reference
|
|
44
|
+
export { DEFAULT_API_BASE, DEFAULT_PROXY_BASE, UPLOAD_RETRY_DELAYS_MS } from './constants';
|
|
@@ -81,7 +81,6 @@ describe('readFileList', () => {
|
|
|
81
81
|
const files = await readFileList(
|
|
82
82
|
asFileList([new File([bytes.buffer.slice(0) as ArrayBuffer], 'my-site.zip')])
|
|
83
83
|
);
|
|
84
|
-
// Junk gone, common "my-site/" root stripped.
|
|
85
84
|
expect(files.map(f => f.path).sort()).toEqual(['/css/site.css', '/index.html']);
|
|
86
85
|
});
|
|
87
86
|
});
|