@crvouga/mockingbird-preview 0.0.0-stage → 0.1.0
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/README.md +355 -2
- package/dist/chunk-WAMTSUKW.js +400 -0
- package/dist/chunk-WAMTSUKW.js.map +7 -0
- package/dist/dev-proxy.d.ts +176 -0
- package/dist/dev-proxy.js +15 -0
- package/dist/dev-proxy.js.map +7 -0
- package/dist/index.d.ts +229 -0
- package/dist/index.js +1008 -0
- package/dist/index.js.map +7 -0
- package/dist/node.d.ts +14 -0
- package/dist/node.js +76 -0
- package/dist/node.js.map +7 -0
- package/dist/types-CQYnWD6z.d.ts +27 -0
- package/package.json +57 -4
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NON_PROD_PATTERNS,
|
|
3
|
+
createDevProxy,
|
|
4
|
+
devBaseUrlName,
|
|
5
|
+
devProviders,
|
|
6
|
+
devProxyWorker
|
|
7
|
+
} from "./chunk-WAMTSUKW.js";
|
|
8
|
+
export {
|
|
9
|
+
NON_PROD_PATTERNS,
|
|
10
|
+
createDevProxy,
|
|
11
|
+
devBaseUrlName,
|
|
12
|
+
devProviders,
|
|
13
|
+
devProxyWorker
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=dev-proxy.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { P as PreviewFetch, a as PreviewPort } from './types-CQYnWD6z.js';
|
|
2
|
+
export { c as createPreviewClient, s as servePreviewPort } from './types-CQYnWD6z.js';
|
|
3
|
+
export { DevEnv, DevManifest, DevProvider, DevProxyOptions, NON_PROD_PATTERNS, createDevProxy, devBaseUrlName, devProviders, devProxyWorker } from './dev-proxy.js';
|
|
4
|
+
|
|
5
|
+
type PreviewDownload = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
6
|
+
type PreviewArtifact = {
|
|
7
|
+
format: 1;
|
|
8
|
+
commit: string;
|
|
9
|
+
sha256: string;
|
|
10
|
+
bytes: number;
|
|
11
|
+
encoding: "identity" | "gzip";
|
|
12
|
+
url: string;
|
|
13
|
+
};
|
|
14
|
+
type LegacyPreviewArtifact = {
|
|
15
|
+
version: 1;
|
|
16
|
+
sha256: string;
|
|
17
|
+
url: string;
|
|
18
|
+
compression?: "gzip";
|
|
19
|
+
};
|
|
20
|
+
declare function parsePreviewArtifact(value: unknown): PreviewArtifact;
|
|
21
|
+
declare function digestPreviewBytes(bytes: Uint8Array): Promise<string>;
|
|
22
|
+
declare function createPreviewArtifact(bytes: Uint8Array, options: {
|
|
23
|
+
commit: string;
|
|
24
|
+
encoding?: "identity" | "gzip";
|
|
25
|
+
url: string;
|
|
26
|
+
}): Promise<PreviewArtifact>;
|
|
27
|
+
declare function loadPreviewArtifact(manifest: unknown, options?: {
|
|
28
|
+
fetch?: PreviewDownload;
|
|
29
|
+
expectedCommit?: string;
|
|
30
|
+
maximumBytes?: number;
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
}): Promise<Uint8Array<ArrayBuffer>>;
|
|
33
|
+
|
|
34
|
+
type PullRequestFacts = {
|
|
35
|
+
state: "open" | "closed";
|
|
36
|
+
repository: string;
|
|
37
|
+
headRepository: string;
|
|
38
|
+
head: string;
|
|
39
|
+
};
|
|
40
|
+
declare function selectPreviewAction(facts: PullRequestFacts, builtCommit: string): "deploy" | "remove" | "skip";
|
|
41
|
+
type ManagedPreview = {
|
|
42
|
+
name: string;
|
|
43
|
+
updatedAt: number;
|
|
44
|
+
};
|
|
45
|
+
declare function planPreviewSweep(options: {
|
|
46
|
+
previews: ManagedPreview[];
|
|
47
|
+
openNames: ReadonlySet<string>;
|
|
48
|
+
owns: (name: string) => boolean;
|
|
49
|
+
now: number;
|
|
50
|
+
retentionMs: number;
|
|
51
|
+
capacity: number;
|
|
52
|
+
}): {
|
|
53
|
+
name: string;
|
|
54
|
+
reason: "orphaned" | "expired" | "capacity";
|
|
55
|
+
}[];
|
|
56
|
+
|
|
57
|
+
type PreviewAssetFile = {
|
|
58
|
+
path: string;
|
|
59
|
+
bytes: Uint8Array;
|
|
60
|
+
contentType: string;
|
|
61
|
+
};
|
|
62
|
+
type CloudflarePreview = {
|
|
63
|
+
id: string;
|
|
64
|
+
name: string;
|
|
65
|
+
updatedAt: string;
|
|
66
|
+
urls: string[];
|
|
67
|
+
};
|
|
68
|
+
/** Uses named Worker Previews only. Never calls the production script/deployment update endpoint. */
|
|
69
|
+
declare function createCloudflarePreviews(options: {
|
|
70
|
+
accountId: string;
|
|
71
|
+
workerName: string;
|
|
72
|
+
token: string;
|
|
73
|
+
fetch?: PreviewDownload;
|
|
74
|
+
}): {
|
|
75
|
+
deploy: (input: {
|
|
76
|
+
name: string;
|
|
77
|
+
commit: string;
|
|
78
|
+
files: PreviewAssetFile[];
|
|
79
|
+
currentPullRequest: () => Promise<PullRequestFacts>;
|
|
80
|
+
headers?: string;
|
|
81
|
+
compatibilityDate?: string;
|
|
82
|
+
htmlHandling?: "auto-trailing-slash" | "force-trailing-slash" | "drop-trailing-slash" | "none";
|
|
83
|
+
notFoundHandling?: "none" | "404-page" | "single-page-application";
|
|
84
|
+
}) => Promise<{
|
|
85
|
+
action: "remove" | "skip";
|
|
86
|
+
preview?: never;
|
|
87
|
+
deploymentId?: never;
|
|
88
|
+
} | {
|
|
89
|
+
action: string;
|
|
90
|
+
preview: CloudflarePreview;
|
|
91
|
+
deploymentId?: never;
|
|
92
|
+
} | {
|
|
93
|
+
action: string;
|
|
94
|
+
preview: CloudflarePreview;
|
|
95
|
+
deploymentId: string;
|
|
96
|
+
}>;
|
|
97
|
+
list: () => Promise<CloudflarePreview[]>;
|
|
98
|
+
remove: (name: string) => Promise<void>;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
type DevMode = "emulated" | "dev";
|
|
102
|
+
type DevServiceSpec = {
|
|
103
|
+
/** Provider id at the proxy, e.g. "stripe". */
|
|
104
|
+
id: string;
|
|
105
|
+
/** "Stripe" */
|
|
106
|
+
label: string;
|
|
107
|
+
/** "Payments" */
|
|
108
|
+
category?: string;
|
|
109
|
+
/** The emulator runtime's own fetch (for /__admin/upstream). */
|
|
110
|
+
admin: (request: Request) => Promise<Response>;
|
|
111
|
+
/** A reason when this emulator cannot forward (no `upstream` support). */
|
|
112
|
+
unsupported?: string;
|
|
113
|
+
};
|
|
114
|
+
/** Structurally identical to `SystemServiceMode` in `@crvouga/mockingbird-ui`. */
|
|
115
|
+
type SystemServiceModeLike = "emulated" | "dev";
|
|
116
|
+
/** Structurally identical to `SystemService` in `@crvouga/mockingbird-ui`. */
|
|
117
|
+
type SystemServiceLike = {
|
|
118
|
+
id: string;
|
|
119
|
+
label: string;
|
|
120
|
+
category?: string;
|
|
121
|
+
mode: SystemServiceModeLike;
|
|
122
|
+
/** Why dev cannot be chosen; undefined when it can. */
|
|
123
|
+
unavailable?: string;
|
|
124
|
+
};
|
|
125
|
+
/** Structurally identical to `SystemDevStatus` in `@crvouga/mockingbird-ui`. */
|
|
126
|
+
type SystemDevStatusLike = {
|
|
127
|
+
state: "ready" | "unreachable" | "none";
|
|
128
|
+
/** One sentence shown in the access panel. */
|
|
129
|
+
message: string;
|
|
130
|
+
/** The proxy URL, displayed. */
|
|
131
|
+
endpoint?: string;
|
|
132
|
+
};
|
|
133
|
+
/** Structurally identical to `SystemServices` in `@crvouga/mockingbird-ui`. */
|
|
134
|
+
type SystemServicesLike = {
|
|
135
|
+
list(): Promise<{
|
|
136
|
+
dev: SystemDevStatusLike;
|
|
137
|
+
services: readonly SystemServiceLike[];
|
|
138
|
+
}>;
|
|
139
|
+
setMode(id: string, mode: SystemServiceModeLike): Promise<void>;
|
|
140
|
+
};
|
|
141
|
+
type DevUpstream = {
|
|
142
|
+
baseUrl: string;
|
|
143
|
+
fetch: (request: Request) => Promise<Response>;
|
|
144
|
+
rewriteAuth: (request: Request) => Request;
|
|
145
|
+
};
|
|
146
|
+
type DevResources = {
|
|
147
|
+
/** For createRuntime({ upstream }): baseUrl `${proxy}/${id}`, fetch goes to the proxy as-is, rewriteAuth drops authorization and cookies. */
|
|
148
|
+
upstream(id: string): DevUpstream;
|
|
149
|
+
/** The SystemServices provider the UI harness takes. */
|
|
150
|
+
controls(services: readonly DevServiceSpec[]): SystemServicesLike;
|
|
151
|
+
};
|
|
152
|
+
type DevStorage = Pick<Storage, "getItem" | "setItem" | "removeItem">;
|
|
153
|
+
type DevResourcesOptions = {
|
|
154
|
+
/** Absolute, or relative to location.origin (e.g. "/__dev"). Undefined = dev resources not offered. */
|
|
155
|
+
proxyUrl?: string;
|
|
156
|
+
/** Per-viewer storage for the chosen modes. Default: localStorage, try/catch wrapped. */
|
|
157
|
+
storage?: DevStorage;
|
|
158
|
+
fetch?: (request: Request) => Promise<Response>;
|
|
159
|
+
};
|
|
160
|
+
/** Storage keys (per origin). */
|
|
161
|
+
declare const DEV_STORAGE_KEYS: {
|
|
162
|
+
readonly modes: "mockingbird.dev.modes";
|
|
163
|
+
};
|
|
164
|
+
declare const DEV_MESSAGES: {
|
|
165
|
+
readonly none: "No dev proxy is configured for this preview";
|
|
166
|
+
readonly ready: "Dev resources are available: switch a service to send its requests to its dev resource";
|
|
167
|
+
};
|
|
168
|
+
declare const createDevResources: (options?: DevResourcesOptions) => DevResources;
|
|
169
|
+
|
|
170
|
+
type PreviewSystem = {
|
|
171
|
+
fetch: PreviewFetch;
|
|
172
|
+
dispose?: () => void | Promise<void>;
|
|
173
|
+
};
|
|
174
|
+
type PreviewHostStatus = {
|
|
175
|
+
state: "starting" | "ready" | "failed" | "disposed";
|
|
176
|
+
generation: number;
|
|
177
|
+
artifact: string;
|
|
178
|
+
clients: number;
|
|
179
|
+
};
|
|
180
|
+
/** Boot and reset are serialized. Each connection owns its requests, never the shared system. */
|
|
181
|
+
declare function createPreviewHost(options: {
|
|
182
|
+
artifact: string;
|
|
183
|
+
boot: (context: {
|
|
184
|
+
generation: number;
|
|
185
|
+
signal: AbortSignal;
|
|
186
|
+
}) => PreviewSystem | Promise<PreviewSystem>;
|
|
187
|
+
allow?: (url: URL) => boolean;
|
|
188
|
+
}): {
|
|
189
|
+
connect: (port: PreviewPort) => () => void;
|
|
190
|
+
fetch: PreviewFetch;
|
|
191
|
+
reset: () => Promise<void>;
|
|
192
|
+
dispose: () => Promise<void>;
|
|
193
|
+
status: () => PreviewHostStatus;
|
|
194
|
+
ready: () => Promise<void>;
|
|
195
|
+
};
|
|
196
|
+
declare function sharedPreviewWorkerName(identity: {
|
|
197
|
+
application: string;
|
|
198
|
+
artifact: string;
|
|
199
|
+
generation: number;
|
|
200
|
+
}): string;
|
|
201
|
+
|
|
202
|
+
declare function connectSharedPreviewWorker(url: string | URL, options: {
|
|
203
|
+
application: string;
|
|
204
|
+
artifact: string;
|
|
205
|
+
generation: number;
|
|
206
|
+
timeoutMs?: number;
|
|
207
|
+
}): {
|
|
208
|
+
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
209
|
+
readonly pending: number;
|
|
210
|
+
worker: SharedWorker;
|
|
211
|
+
dispose: () => void;
|
|
212
|
+
};
|
|
213
|
+
declare function connectDedicatedPreviewWorker(url: string | URL, options?: {
|
|
214
|
+
timeoutMs?: number;
|
|
215
|
+
}): {
|
|
216
|
+
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
217
|
+
readonly pending: number;
|
|
218
|
+
worker: Worker;
|
|
219
|
+
dispose: () => void;
|
|
220
|
+
};
|
|
221
|
+
type WorkerScope = {
|
|
222
|
+
addEventListener: (type: string, listener: (event: MessageEvent) => void) => void;
|
|
223
|
+
removeEventListener: (type: string, listener: (event: MessageEvent) => void) => void;
|
|
224
|
+
};
|
|
225
|
+
/** Installs shared-worker connect events or dedicated-worker transferred-port handshakes. */
|
|
226
|
+
declare function installPreviewWorkerHost(host: ReturnType<typeof createPreviewHost>, scope: WorkerScope): () => Promise<void>;
|
|
227
|
+
|
|
228
|
+
export { DEV_MESSAGES, DEV_STORAGE_KEYS, PreviewFetch, PreviewPort, connectDedicatedPreviewWorker, connectSharedPreviewWorker, createCloudflarePreviews, createDevResources, createPreviewArtifact, createPreviewHost, digestPreviewBytes, installPreviewWorkerHost, loadPreviewArtifact, parsePreviewArtifact, planPreviewSweep, selectPreviewAction, sharedPreviewWorkerName };
|
|
229
|
+
export type { CloudflarePreview, DevMode, DevResources, DevResourcesOptions, DevServiceSpec, DevStorage, DevUpstream, LegacyPreviewArtifact, ManagedPreview, PreviewArtifact, PreviewAssetFile, PreviewDownload, PreviewHostStatus, PreviewSystem, PullRequestFacts, SystemDevStatusLike, SystemServiceLike, SystemServiceModeLike, SystemServicesLike };
|