@base44-preview/vite-plugin 1.0.52-pr.149.3cc7eef → 1.0.52-pr.150.911b6c2
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 +33 -0
- package/dist/hidden-source-maps-plugin.d.ts +39 -0
- package/dist/hidden-source-maps-plugin.d.ts.map +1 -0
- package/dist/hidden-source-maps-plugin.js +70 -0
- package/dist/hidden-source-maps-plugin.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/private-data-sources/manifest.d.ts.map +1 -1
- package/dist/private-data-sources/manifest.js +1 -11
- package/dist/private-data-sources/manifest.js.map +1 -1
- package/dist/private-data-sources/runtime-environment.d.ts +0 -2
- package/dist/private-data-sources/runtime-environment.d.ts.map +1 -1
- package/dist/private-data-sources/runtime-environment.js +0 -2
- package/dist/private-data-sources/runtime-environment.js.map +1 -1
- package/dist/private-data-sources-plugin.d.ts.map +1 -1
- package/dist/private-data-sources-plugin.js +2 -19
- package/dist/private-data-sources-plugin.js.map +1 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +4 -1
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/hidden-source-maps-plugin.ts +102 -0
- package/src/index.ts +7 -0
- package/src/private-data-sources/cloudflare-workers.d.ts +0 -4
- package/src/private-data-sources/manifest.ts +1 -10
- package/src/private-data-sources/runtime-environment.ts +0 -3
- package/src/private-data-sources-plugin.ts +2 -20
- package/src/utils.ts +6 -1
- package/dist/private-data-sources/preview-env.d.ts +0 -2
- package/dist/private-data-sources/preview-env.d.ts.map +0 -1
- package/dist/private-data-sources/preview-env.js +0 -4
- package/dist/private-data-sources/preview-env.js.map +0 -1
- package/dist/private-data-sources/preview.d.ts +0 -4
- package/dist/private-data-sources/preview.d.ts.map +0 -1
- package/dist/private-data-sources/preview.js +0 -34
- package/dist/private-data-sources/preview.js.map +0 -1
- package/dist/private-data-sources-preview.d.ts +0 -38
- package/dist/private-data-sources-preview.d.ts.map +0 -1
- package/dist/private-data-sources-preview.js +0 -79
- package/dist/private-data-sources-preview.js.map +0 -1
- package/src/private-data-sources/preview-env.ts +0 -3
- package/src/private-data-sources/preview.ts +0 -37
- package/src/private-data-sources-preview.ts +0 -104
package/README.md
CHANGED
|
@@ -47,6 +47,8 @@ The plugin registers these sub-plugins when running in a sandbox (`MODAL_SANDBOX
|
|
|
47
47
|
4. **html-injections** — Injects sandbox-side scripts into the HTML while serving. Under bundled dev mode its sibling **html-injections-bundled** injects them instead, before the HTML is bundled.
|
|
48
48
|
5. **html-injections-production** — Injects the analytics tracker into production builds.
|
|
49
49
|
|
|
50
|
+
In or out of a sandbox, `base44-hidden-source-maps` joins any build run with `BASE44_HIDDEN_SOURCE_MAPS=1` (see [Hidden source maps](#hidden-source-maps-base44-builds)).
|
|
51
|
+
|
|
50
52
|
Dev and production are told apart by the Vite command (`serve` vs `build`), not by the presence of a dev server in the HTML transform context — bundled dev runs the HTML through the build-shaped transform, where no server is passed.
|
|
51
53
|
|
|
52
54
|
Outside a sandbox, only the core plugin runs (with optional API proxy support via `VITE_BASE44_APP_BASE_URL`).
|
|
@@ -136,6 +138,37 @@ read `ok: true`. That window is already covered server-side by the existing
|
|
|
136
138
|
`dev_server_error_classifier` (install / start failures surface as `409`). This
|
|
137
139
|
endpoint's job is **post-load HMR / compile errors**, not cold-start failures.
|
|
138
140
|
|
|
141
|
+
### Hidden source maps (Base44 builds)
|
|
142
|
+
|
|
143
|
+
A Base44 platform option, set by Base44's build environment rather than by the
|
|
144
|
+
app. When `vite build` runs with
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
BASE44_HIDDEN_SOURCE_MAPS=1
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
the `base44-hidden-source-maps` sub-plugin gives the browser build source maps
|
|
151
|
+
that the platform stores privately and uses to map browser stack traces to the
|
|
152
|
+
app's own files:
|
|
153
|
+
|
|
154
|
+
- **Hidden.** `build.sourcemap: "hidden"`: `.map` files are emitted, but no
|
|
155
|
+
bundle file carries a `sourceMappingURL` comment, so browsers never fetch them.
|
|
156
|
+
- **No source text.** `sourcemapExcludeSources` is set on every output (under
|
|
157
|
+
`build.rollupOptions.output` before Vite 8, `build.rolldownOptions.output` on
|
|
158
|
+
Vite 8), so a map holds file names and positions only.
|
|
159
|
+
- **The app's choice wins.** If `build.sourcemap` is already set, by the app's
|
|
160
|
+
config or by another plugin, to any value including `false`, source maps are
|
|
161
|
+
left exactly as configured.
|
|
162
|
+
- **Browser build only.** With Vite environments (6+) only the client
|
|
163
|
+
environment changes; an SSR or Worker build keeps its own config. A Vite 5
|
|
164
|
+
`vite build --ssr` is left alone too.
|
|
165
|
+
- **Build only.** The dev server and `vite preview` are untouched.
|
|
166
|
+
|
|
167
|
+
Like `BASE44_BUILD_STATUS_ENABLED`, the variable is read when the plugin
|
|
168
|
+
assembles its plugin list, so the app's `vite.config.js` does not change. Unset,
|
|
169
|
+
or set to anything other than `1`, the sub-plugin is not added and the build
|
|
170
|
+
output is byte-identical to a build without it.
|
|
171
|
+
|
|
139
172
|
### Route request logs (full-stack apps)
|
|
140
173
|
|
|
141
174
|
Dev-only. While a Nitro server route serves a request that carries
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { BuildEnvironmentOptions, Plugin } from "vite";
|
|
2
|
+
/**
|
|
3
|
+
* Hidden source maps for the browser build, for Base44's build environment.
|
|
4
|
+
*
|
|
5
|
+
* `index.ts` adds this plugin only when `BASE44_HIDDEN_SOURCE_MAPS=1`. It sets
|
|
6
|
+
* `build.sourcemap: "hidden"`, so the bundle carries no `sourceMappingURL`
|
|
7
|
+
* comment, and leaves the source text out of the maps. The platform keeps the
|
|
8
|
+
* maps private and uses them to map browser stack traces to the app's files.
|
|
9
|
+
*
|
|
10
|
+
* - Build only (`apply: "build"`): the dev server and `vite preview` never see it.
|
|
11
|
+
* - Browser build only: under Vite's environments (6+) only the client
|
|
12
|
+
* environment changes, so an SSR or Worker build keeps its own config.
|
|
13
|
+
* - The app's choice wins: a `build.sourcemap` already set, `false` included,
|
|
14
|
+
* leaves source maps exactly as configured.
|
|
15
|
+
*/
|
|
16
|
+
type RollupOutput = Record<string, unknown>;
|
|
17
|
+
type BuildOptions = BuildEnvironmentOptions & {
|
|
18
|
+
rolldownOptions?: {
|
|
19
|
+
output?: RollupOutput | RollupOutput[];
|
|
20
|
+
} & Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
export interface HiddenSourceMapsOptions {
|
|
23
|
+
/** Whether bundler options live under `rolldownOptions`. Defaults to the installed Vite's. */
|
|
24
|
+
rolldown?: boolean;
|
|
25
|
+
/** Whether Vite has environments (`configEnvironment`). Defaults to the installed Vite's. */
|
|
26
|
+
environments?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The build options with hidden, sourceless maps, or `null` when the app chose
|
|
30
|
+
* its own `sourcemap`. Builds new objects all the way down: Vite shares nested
|
|
31
|
+
* build objects between the top-level config and every environment, so editing
|
|
32
|
+
* one in place would leak into the SSR build.
|
|
33
|
+
*/
|
|
34
|
+
export declare function withHiddenSourceMaps(build: BuildOptions | undefined, { rolldown }: {
|
|
35
|
+
rolldown: boolean;
|
|
36
|
+
}): BuildOptions | null;
|
|
37
|
+
export declare function hiddenSourceMapsPlugin({ rolldown, environments, }?: HiddenSourceMapsOptions): Plugin;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=hidden-source-maps-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hidden-source-maps-plugin.d.ts","sourceRoot":"","sources":["../src/hidden-source-maps-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAG5D;;;;;;;;;;;;;GAaG;AAEH,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC5C,KAAK,YAAY,GAAG,uBAAuB,GAAG;IAE5C,eAAe,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,YAAY,GAAG,YAAY,EAAE,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxF,CAAC;AAEF,MAAM,WAAW,uBAAuB;IACtC,8FAA8F;IAC9F,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6FAA6F;IAC7F,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAOD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,YAAY,GAAG,SAAS,EAC/B,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,GAClC,YAAY,GAAG,IAAI,CAmBrB;AAED,wBAAgB,sBAAsB,CAAC,EACrC,QAAyB,EACzB,YAA6B,GAC9B,GAAE,uBAA4B,GAAG,MAAM,CAgCvC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { isVite6OrLater, isVite8OrLater } from "./utils.js";
|
|
2
|
+
const excludeSources = (output) => ({
|
|
3
|
+
...output,
|
|
4
|
+
sourcemapExcludeSources: true,
|
|
5
|
+
});
|
|
6
|
+
/**
|
|
7
|
+
* The build options with hidden, sourceless maps, or `null` when the app chose
|
|
8
|
+
* its own `sourcemap`. Builds new objects all the way down: Vite shares nested
|
|
9
|
+
* build objects between the top-level config and every environment, so editing
|
|
10
|
+
* one in place would leak into the SSR build.
|
|
11
|
+
*/
|
|
12
|
+
export function withHiddenSourceMaps(build, { rolldown }) {
|
|
13
|
+
if (build?.sourcemap !== undefined)
|
|
14
|
+
return null;
|
|
15
|
+
// Vite 8 aliases `rollupOptions` to `rolldownOptions` with a getter. Read
|
|
16
|
+
// either, write only the one this Vite reads, and drop the other so the two
|
|
17
|
+
// never disagree.
|
|
18
|
+
const { rollupOptions, rolldownOptions, ...rest } = (build ?? {});
|
|
19
|
+
const bundlerOptions = (rolldown ? rolldownOptions ?? rollupOptions : rollupOptions) ?? {};
|
|
20
|
+
const { output } = bundlerOptions;
|
|
21
|
+
return {
|
|
22
|
+
...rest,
|
|
23
|
+
sourcemap: "hidden",
|
|
24
|
+
[rolldown ? "rolldownOptions" : "rollupOptions"]: {
|
|
25
|
+
...bundlerOptions,
|
|
26
|
+
// An app may build several outputs; each one leaves its sources out.
|
|
27
|
+
output: Array.isArray(output) ? output.map(excludeSources) : excludeSources(output),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export function hiddenSourceMapsPlugin({ rolldown = isVite8OrLater, environments = isVite6OrLater, } = {}) {
|
|
32
|
+
return {
|
|
33
|
+
name: "base44-hidden-source-maps",
|
|
34
|
+
apply: "build",
|
|
35
|
+
// Run after other plugins' config hooks, so a source-map choice made by a
|
|
36
|
+
// framework plugin counts as the app's own.
|
|
37
|
+
config: {
|
|
38
|
+
order: "post",
|
|
39
|
+
handler(config, env) {
|
|
40
|
+
// Vite 6+ is handled per environment below: the top-level build
|
|
41
|
+
// options feed the SSR environment too.
|
|
42
|
+
if (environments)
|
|
43
|
+
return;
|
|
44
|
+
// Vite 5 runs an SSR build as its own `vite build --ssr`.
|
|
45
|
+
if (config.build?.ssr || env.isSsrBuild)
|
|
46
|
+
return;
|
|
47
|
+
const build = withHiddenSourceMaps(config.build, { rolldown });
|
|
48
|
+
if (build)
|
|
49
|
+
config.build = build;
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
configEnvironment: {
|
|
53
|
+
order: "post",
|
|
54
|
+
handler(name, config) {
|
|
55
|
+
if (!environments)
|
|
56
|
+
return;
|
|
57
|
+
const consumer = config.consumer ?? (name === "client" ? "client" : "server");
|
|
58
|
+
if (consumer !== "client")
|
|
59
|
+
return;
|
|
60
|
+
const build = withHiddenSourceMaps(config.build, { rolldown });
|
|
61
|
+
// Assigned rather than returned: Vite merges a returned config into the
|
|
62
|
+
// existing one, which would append to an `output` array instead of
|
|
63
|
+
// updating each entry.
|
|
64
|
+
if (build)
|
|
65
|
+
config.build = build;
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=hidden-source-maps-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hidden-source-maps-plugin.js","sourceRoot":"","sources":["../src/hidden-source-maps-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AA8B5D,MAAM,cAAc,GAAG,CAAC,MAAgC,EAAgB,EAAE,CAAC,CAAC;IAC1E,GAAG,MAAM;IACT,uBAAuB,EAAE,IAAI;CAC9B,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAA+B,EAC/B,EAAE,QAAQ,EAAyB;IAEnC,IAAI,KAAK,EAAE,SAAS,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAEhD,0EAA0E;IAC1E,4EAA4E;IAC5E,kBAAkB;IAClB,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,GAAG,IAAI,EAAE,GAAG,CAAC,KAAK,IAAI,EAAE,CAAiB,CAAC;IAClF,MAAM,cAAc,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,eAAe,IAAI,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;IAC3F,MAAM,EAAE,MAAM,EAAE,GAAG,cAA4D,CAAC;IAEhF,OAAO;QACL,GAAG,IAAI;QACP,SAAS,EAAE,QAAQ;QACnB,CAAC,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,eAAe,CAAC,EAAE;YAChD,GAAG,cAAc;YACjB,qEAAqE;YACrE,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,CAA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index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,MAAM,CAAC;AAY/C,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAmBlD,eAAO,MAAM,uBAAuB,UAWnC,CAAC;AAeF,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,IAAI,GAAE;IACJ,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CACvB,iBAqQP"}
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import { base44RuntimePlugin } from "./base44-runtime-plugin.js";
|
|
|
9
9
|
import { workerdCompatPlugin } from "./workerd-compat-plugin.js";
|
|
10
10
|
import { privateDataSourcesPlugin } from "./private-data-sources-plugin.js";
|
|
11
11
|
import { routeRequestLogPlugin } from "./route-request-log/vite-plugin.js";
|
|
12
|
+
import { hiddenSourceMapsPlugin } from "./hidden-source-maps-plugin.js";
|
|
12
13
|
const PLATFORM_API_PROXY_PATH = "^/api/(apps|app-logs)([/?]|$)";
|
|
13
14
|
const isRunningInSandbox = !!process.env.MODAL_SANDBOX_ID;
|
|
14
15
|
// Both optimizer spellings mean the same thing here: treat .js files as JSX,
|
|
@@ -241,6 +242,12 @@ export default function vitePlugin(opts = {}) {
|
|
|
241
242
|
// because Nitro runs dev routes in a worker whose console the Vite process
|
|
242
243
|
// never sees. Inert for apps without Nitro and for requests without the id.
|
|
243
244
|
routeRequestLogPlugin(),
|
|
245
|
+
// Base44's build environment sets BASE44_HIDDEN_SOURCE_MAPS=1 to get private
|
|
246
|
+
// source maps for the browser build. Gated here, like build-status, so an
|
|
247
|
+
// unset flag leaves the pipeline and the build output exactly as before.
|
|
248
|
+
...(process.env.BASE44_HIDDEN_SOURCE_MAPS === "1"
|
|
249
|
+
? [hiddenSourceMapsPlugin()]
|
|
250
|
+
: []),
|
|
244
251
|
];
|
|
245
252
|
}
|
|
246
253
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAA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@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/private-data-sources/manifest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/private-data-sources/manifest.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC;AAiCjE,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAMpE;AAED,wBAAgB,0BAA0B,CACxC,aAAa,EAAE,OAAO,EACtB,YAAY,EAAE,MAAM,GACnB,8BAA8B,CAEhC;AAkCD,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,OAAO,EACtB,YAAY,CAAC,EAAE,MAAM,GACpB,8BAA8B,CA2BhC;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,8BAA8B,GAAG,OAAO,CAWvF;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,8BAA8B,GACpC,8BAA8B,CAEhC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { previewBinding, previewPorts } from "./preview.js";
|
|
2
1
|
import { workerEnvironment } from "./runtime-environment.js";
|
|
3
2
|
const PRIVATE_DATA_SOURCES_MANIFEST_ENV = "BASE44_PRIVATE_DATA_SOURCES";
|
|
4
3
|
function readStringVar(key) {
|
|
@@ -69,9 +68,7 @@ export function lookupPrivateDataSource(requestedName, expectedType) {
|
|
|
69
68
|
.filter((match) => match.rank !== null)
|
|
70
69
|
.sort((a, b) => a.rank - b.rank);
|
|
71
70
|
if (matches.length === 0) {
|
|
72
|
-
throw new Error(
|
|
73
|
-
? `Private data source "${requestedName}" is not shared with this app`
|
|
74
|
-
: `Private data source "${requestedName}" is not bound to this app. Private data sources are available on the published app, not in the editor's live preview`);
|
|
71
|
+
throw new Error(`Private data source "${requestedName}" is not bound to this app. Private data sources are available on the published app, not in the editor's live preview`);
|
|
75
72
|
}
|
|
76
73
|
const typeMatches = expectedType
|
|
77
74
|
? matches.filter((candidate) => privateDataSourceMatchesExpectedType(candidate.entry, expectedType))
|
|
@@ -91,13 +88,6 @@ export function privateDataSourceBinding(entry) {
|
|
|
91
88
|
if (!entry.bindingName) {
|
|
92
89
|
throw new Error(`Private data source "${entry.name}" has no Worker binding name`);
|
|
93
90
|
}
|
|
94
|
-
const ports = previewPorts();
|
|
95
|
-
if (ports) {
|
|
96
|
-
const port = ports[entry.bindingName];
|
|
97
|
-
if (!port)
|
|
98
|
-
throw new Error(`Private data source "${entry.name}" has no preview connection; restart the preview`);
|
|
99
|
-
return previewBinding(entry, port);
|
|
100
|
-
}
|
|
101
91
|
const binding = workerEnvironment()[entry.bindingName];
|
|
102
92
|
if (!binding) {
|
|
103
93
|
throw new Error(`Private data source binding "${entry.bindingName}" is missing from the Worker environment`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/private-data-sources/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/private-data-sources/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAG7D,MAAM,iCAAiC,GAAG,6BAA6B,CAAC;AAExE,SAAS,aAAa,CAAC,GAAW;IAChC,MAAM,KAAK,GAAG,iBAAiB,EAAE,CAAC,GAAG,CAAC,CAAC;IACvC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACvD,CAAC;AAED,IAAI,cAAsF,CAAC;AAE3F,qFAAqF;AACrF,iGAAiG;AACjG,SAAS,8BAA8B;IACrC,MAAM,GAAG,GAAG,aAAa,CAAC,iCAAiC,CAAC,CAAC;IAC7D,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IACpB,IAAI,cAAc,EAAE,GAAG,K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AAI,KAAK,CAAC,wBAAwB,KAAK,CAAC,IAAI,8BAA8B,CAAC,CAAC;IACpF,CAAC;IACD,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IACvD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,gCAAgC,KAAK,CAAC,WAAW,0CAA0C,CAC5F,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,KAAqC;IAErC,OAAO,uBAAuB,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-environment.d.ts","sourceRoot":"","sources":["../../src/private-data-sources/runtime-environment.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime-environment.d.ts","sourceRoot":"","sources":["../../src/private-data-sources/runtime-environment.ts"],"names":[],"mappings":"AAGA,wBAAgB,iBAAiB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE3D"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { connect } from "cloudflare:sockets";
|
|
2
1
|
import { env } from "cloudflare:workers";
|
|
3
2
|
// TanStack server code reads the bindings and the manifest off the ambient worker `env`.
|
|
4
3
|
export function workerEnvironment() {
|
|
5
4
|
return env;
|
|
6
5
|
}
|
|
7
|
-
export const socketConnect = connect;
|
|
8
6
|
//# sourceMappingURL=runtime-environment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-environment.js","sourceRoot":"","sources":["../../src/private-data-sources/runtime-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"runtime-environment.js","sourceRoot":"","sources":["../../src/private-data-sources/runtime-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAEzC,yFAAyF;AACzF,MAAM,UAAU,iBAAiB;IAC/B,OAAO,GAA8B,CAAC;AACxC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-data-sources-plugin.d.ts","sourceRoot":"","sources":["../src/private-data-sources-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,MAAM,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"private-data-sources-plugin.d.ts","sourceRoot":"","sources":["../src/private-data-sources-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,MAAM,EAAE,MAAM,MAAM,CAAC;AA+ClD,wBAAgB,wBAAwB,IAAI,MAAM,CA2BjD"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
import { normalizePath } from "vite";
|
|
4
|
-
import { GATEWAY_TOKEN_ENV, GATEWAY_URL_ENV, startPreviewForwarders } from "./private-data-sources-preview.js";
|
|
5
|
-
import { PREVIEW_PORTS_ENV } from "./private-data-sources/preview-env.js";
|
|
6
4
|
/**
|
|
7
5
|
* Serves `base44:private-data-sources/<type>` to TanStack server code, so it
|
|
8
6
|
* reaches a workspace private data source with the SAME import a backend
|
|
@@ -15,10 +13,8 @@ import { PREVIEW_PORTS_ENV } from "./private-data-sources/preview-env.js";
|
|
|
15
13
|
* `env` from `cloudflare:workers`. Each specifier resolves to the compiled file
|
|
16
14
|
* so Vite bundles it like any source module.
|
|
17
15
|
*
|
|
18
|
-
* The bindings exist only on the deployed worker
|
|
19
|
-
*
|
|
20
|
-
* starts localhost forwarders to it and the same helpers connect through them; without one,
|
|
21
|
-
* a lookup throws, saying the source is available on the published app.
|
|
16
|
+
* The bindings exist only on the deployed worker: in the editor's dev preview a
|
|
17
|
+
* lookup throws, saying the source is available on the published app.
|
|
22
18
|
*/
|
|
23
19
|
const NAMESPACE = "base44:private-data-sources";
|
|
24
20
|
const PREFIX = `${NAMESPACE}/`;
|
|
@@ -34,7 +30,6 @@ const SOURCE_TYPES = new Set([
|
|
|
34
30
|
"sqlserver",
|
|
35
31
|
]);
|
|
36
32
|
const IMPORTER_QUERY = "?importer=";
|
|
37
|
-
const MANIFEST_ENV = "BASE44_PRIVATE_DATA_SOURCES";
|
|
38
33
|
const MODULES_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), "private-data-sources");
|
|
39
34
|
function failureReason(specifier, environment) {
|
|
40
35
|
const sourceType = specifier.startsWith(PREFIX) ? specifier.slice(PREFIX.length) : "";
|
|
@@ -52,18 +47,6 @@ export function privateDataSourcesPlugin() {
|
|
|
52
47
|
name: "base44-private-data-sources",
|
|
53
48
|
// Ahead of Vite's own resolution so the bare scheme is never read as a URL.
|
|
54
49
|
enforce: "pre",
|
|
55
|
-
// Before the Cloudflare plugin builds the workerd env from process.env, so server code sees the ports.
|
|
56
|
-
async config(_config, { command }) {
|
|
57
|
-
const gatewayUrl = process.env[GATEWAY_URL_ENV];
|
|
58
|
-
const token = process.env[GATEWAY_TOKEN_ENV];
|
|
59
|
-
const manifest = process.env[MANIFEST_ENV];
|
|
60
|
-
if (command !== "serve" || process.env[PREVIEW_PORTS_ENV] || !gatewayUrl || !token || !manifest)
|
|
61
|
-
return;
|
|
62
|
-
const { ports } = await startPreviewForwarders({ gatewayUrl, token, entries: JSON.parse(manifest) });
|
|
63
|
-
process.env[PREVIEW_PORTS_ENV] = JSON.stringify(ports);
|
|
64
|
-
// Only the forwarders need the token; keep it out of the app's server env.
|
|
65
|
-
delete process.env[GATEWAY_TOKEN_ENV];
|
|
66
|
-
},
|
|
67
50
|
// Like base44-runtime: errors are raised in `load`, never `resolveId`, so the
|
|
68
51
|
// dep scan of not-yet-stripped server code in the client environment survives.
|
|
69
52
|
resolveId(id, importer) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-data-sources-plugin.js","sourceRoot":"","sources":["../src/private-data-sources-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAe,MAAM,MAAM,CAAC;AAElD
|
|
1
|
+
{"version":3,"file":"private-data-sources-plugin.js","sourceRoot":"","sources":["../src/private-data-sources-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAe,MAAM,MAAM,CAAC;AAElD;;;;;;;;;;;;;;GAcG;AAEH,MAAM,SAAS,GAAG,6BAA6B,CAAC;AAChD,MAAM,MAAM,GAAG,GAAG,SAAS,GAAG,CAAC;AAC/B,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC;IAC3B,eAAe;IACf,MAAM;IACN,SAAS;IACT,SAAS;IACT,OAAO;IACP,QAAQ;IACR,UAAU;IACV,OAAO;IACP,WAAW;CACZ,CAAC,CAAC;AACH,MAAM,cAAc,GAAG,YAAY,CAAC;AAEpC,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,sBAAsB,CAAC,CAAC;AAEpG,SAAS,aAAa,CAAC,SAAiB,EAAE,WAA+B;IACvE,MAAM,UAAU,GAAG,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtF,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;QAClC,OAAO,IAAI,SAAS,oDAAoD,CAAC,GAAG,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE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C,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;YACrE,IAAI,SAAS,KAAK,SAAS,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC;gBAAE,OAAO,IAAI,CAAC;YAC1E,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,kBAAkB,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YAChG,MAAM,MAAM,GAAG,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;YAChE,IAAI,CAAC,KAAK,CAAC,GAAG,MAAM,IAAI,IAAI,SAAS,0BAA0B,GAAG,IAAI,EAAE,CAAC,CAAC;QAC5E,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,cAAc,SAAiB,CAAC;AAI7C,eAAO,MAAM,cAAc,SAAiB,CAAC;AAc7C,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAAE,EAClB,IAAI,EAAE,MAAM,GACX,MAAM,EAAE,CAmBV"}
|
package/dist/utils.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { readFileSync, existsSync } from "fs";
|
|
2
2
|
import { join } from "path";
|
|
3
3
|
import { version as viteVersion } from "vite";
|
|
4
|
+
const viteMajor = Number(viteVersion.split(".")[0]);
|
|
5
|
+
// Vite 6 added environments (`environments`, `configEnvironment`).
|
|
6
|
+
export const isVite6OrLater = viteMajor >= 6;
|
|
4
7
|
// Vite 8 pre-bundles deps with Rolldown instead of esbuild and deprecates
|
|
5
8
|
// `optimizeDeps.esbuildOptions`.
|
|
6
|
-
export const isVite8OrLater =
|
|
9
|
+
export const isVite8OrLater = viteMajor >= 8;
|
|
7
10
|
/**
|
|
8
11
|
* The package that owns an optimizeDeps entry. Deep entries like
|
|
9
12
|
* `react-dom/client` are separate entries to Vite's optimizer but are declared
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,MAAM,CAAC;AAE9C,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,MAAM,CAAC;AAE9C,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpD,mEAAmE;AACnE,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,IAAI,CAAC,CAAC;AAE7C,0EAA0E;AAC1E,iCAAiC;AACjC,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,IAAI,CAAC,CAAC;AAE7C;;;;GAIG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;QAC1B,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAChC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,QAAkB,EAClB,IAAY;IAEZ,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;QACnD,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;YACjC,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC;QACvE,MAAM,OAAO,GAAG;YACd,GAAG,WAAW,CAAC,YAAY;YAC3B,GAAG,WAAW,CAAC,eAAe;YAC9B,GAAG,WAAW,CAAC,gBAAgB;SAChC,CAAC;QAEF,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC;IACjE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;QAC5D,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { BuildEnvironmentOptions, Plugin } from "vite";
|
|
2
|
+
import { isVite6OrLater, isVite8OrLater } from "./utils.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Hidden source maps for the browser build, for Base44's build environment.
|
|
6
|
+
*
|
|
7
|
+
* `index.ts` adds this plugin only when `BASE44_HIDDEN_SOURCE_MAPS=1`. It sets
|
|
8
|
+
* `build.sourcemap: "hidden"`, so the bundle carries no `sourceMappingURL`
|
|
9
|
+
* comment, and leaves the source text out of the maps. The platform keeps the
|
|
10
|
+
* maps private and uses them to map browser stack traces to the app's files.
|
|
11
|
+
*
|
|
12
|
+
* - Build only (`apply: "build"`): the dev server and `vite preview` never see it.
|
|
13
|
+
* - Browser build only: under Vite's environments (6+) only the client
|
|
14
|
+
* environment changes, so an SSR or Worker build keeps its own config.
|
|
15
|
+
* - The app's choice wins: a `build.sourcemap` already set, `false` included,
|
|
16
|
+
* leaves source maps exactly as configured.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
type RollupOutput = Record<string, unknown>;
|
|
20
|
+
type BuildOptions = BuildEnvironmentOptions & {
|
|
21
|
+
// Vite 8's spelling. Vite 7's types do not know it.
|
|
22
|
+
rolldownOptions?: { output?: RollupOutput | RollupOutput[] } & Record<string, unknown>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export interface HiddenSourceMapsOptions {
|
|
26
|
+
/** Whether bundler options live under `rolldownOptions`. Defaults to the installed Vite's. */
|
|
27
|
+
rolldown?: boolean;
|
|
28
|
+
/** Whether Vite has environments (`configEnvironment`). Defaults to the installed Vite's. */
|
|
29
|
+
environments?: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const excludeSources = (output: RollupOutput | undefined): RollupOutput => ({
|
|
33
|
+
...output,
|
|
34
|
+
sourcemapExcludeSources: true,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The build options with hidden, sourceless maps, or `null` when the app chose
|
|
39
|
+
* its own `sourcemap`. Builds new objects all the way down: Vite shares nested
|
|
40
|
+
* build objects between the top-level config and every environment, so editing
|
|
41
|
+
* one in place would leak into the SSR build.
|
|
42
|
+
*/
|
|
43
|
+
export function withHiddenSourceMaps(
|
|
44
|
+
build: BuildOptions | undefined,
|
|
45
|
+
{ rolldown }: { rolldown: boolean }
|
|
46
|
+
): BuildOptions | null {
|
|
47
|
+
if (build?.sourcemap !== undefined) return null;
|
|
48
|
+
|
|
49
|
+
// Vite 8 aliases `rollupOptions` to `rolldownOptions` with a getter. Read
|
|
50
|
+
// either, write only the one this Vite reads, and drop the other so the two
|
|
51
|
+
// never disagree.
|
|
52
|
+
const { rollupOptions, rolldownOptions, ...rest } = (build ?? {}) as BuildOptions;
|
|
53
|
+
const bundlerOptions = (rolldown ? rolldownOptions ?? rollupOptions : rollupOptions) ?? {};
|
|
54
|
+
const { output } = bundlerOptions as { output?: RollupOutput | RollupOutput[] };
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
...rest,
|
|
58
|
+
sourcemap: "hidden",
|
|
59
|
+
[rolldown ? "rolldownOptions" : "rollupOptions"]: {
|
|
60
|
+
...bundlerOptions,
|
|
61
|
+
// An app may build several outputs; each one leaves its sources out.
|
|
62
|
+
output: Array.isArray(output) ? output.map(excludeSources) : excludeSources(output),
|
|
63
|
+
},
|
|
64
|
+
} as BuildOptions;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function hiddenSourceMapsPlugin({
|
|
68
|
+
rolldown = isVite8OrLater,
|
|
69
|
+
environments = isVite6OrLater,
|
|
70
|
+
}: HiddenSourceMapsOptions = {}): Plugin {
|
|
71
|
+
return {
|
|
72
|
+
name: "base44-hidden-source-maps",
|
|
73
|
+
apply: "build",
|
|
74
|
+
// Run after other plugins' config hooks, so a source-map choice made by a
|
|
75
|
+
// framework plugin counts as the app's own.
|
|
76
|
+
config: {
|
|
77
|
+
order: "post",
|
|
78
|
+
handler(config, env) {
|
|
79
|
+
// Vite 6+ is handled per environment below: the top-level build
|
|
80
|
+
// options feed the SSR environment too.
|
|
81
|
+
if (environments) return;
|
|
82
|
+
// Vite 5 runs an SSR build as its own `vite build --ssr`.
|
|
83
|
+
if (config.build?.ssr || env.isSsrBuild) return;
|
|
84
|
+
const build = withHiddenSourceMaps(config.build, { rolldown });
|
|
85
|
+
if (build) config.build = build;
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
configEnvironment: {
|
|
89
|
+
order: "post",
|
|
90
|
+
handler(name, config) {
|
|
91
|
+
if (!environments) return;
|
|
92
|
+
const consumer = config.consumer ?? (name === "client" ? "client" : "server");
|
|
93
|
+
if (consumer !== "client") return;
|
|
94
|
+
const build = withHiddenSourceMaps(config.build, { rolldown });
|
|
95
|
+
// Assigned rather than returned: Vite merges a returned config into the
|
|
96
|
+
// existing one, which would append to an `output` array instead of
|
|
97
|
+
// updating each entry.
|
|
98
|
+
if (build) config.build = build;
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { base44RuntimePlugin } from "./base44-runtime-plugin.js";
|
|
|
10
10
|
import { workerdCompatPlugin } from "./workerd-compat-plugin.js";
|
|
11
11
|
import { privateDataSourcesPlugin } from "./private-data-sources-plugin.js";
|
|
12
12
|
import { routeRequestLogPlugin } from "./route-request-log/vite-plugin.js";
|
|
13
|
+
import { hiddenSourceMapsPlugin } from "./hidden-source-maps-plugin.js";
|
|
13
14
|
export type { DocumentScript } from "./consts.js";
|
|
14
15
|
|
|
15
16
|
const PLATFORM_API_PROXY_PATH = "^/api/(apps|app-logs)([/?]|$)";
|
|
@@ -316,5 +317,11 @@ export default function vitePlugin(
|
|
|
316
317
|
// because Nitro runs dev routes in a worker whose console the Vite process
|
|
317
318
|
// never sees. Inert for apps without Nitro and for requests without the id.
|
|
318
319
|
routeRequestLogPlugin(),
|
|
320
|
+
// Base44's build environment sets BASE44_HIDDEN_SOURCE_MAPS=1 to get private
|
|
321
|
+
// source maps for the browser build. Gated here, like build-status, so an
|
|
322
|
+
// unset flag leaves the pipeline and the build output exactly as before.
|
|
323
|
+
...(process.env.BASE44_HIDDEN_SOURCE_MAPS === "1"
|
|
324
|
+
? [hiddenSourceMapsPlugin()]
|
|
325
|
+
: []),
|
|
319
326
|
];
|
|
320
327
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { previewBinding, previewPorts } from "./preview.js";
|
|
2
1
|
import { workerEnvironment } from "./runtime-environment.js";
|
|
3
2
|
import type { PrivateDataSourceManifestEntry } from "./types.js";
|
|
4
3
|
|
|
@@ -90,9 +89,7 @@ export function lookupPrivateDataSource(
|
|
|
90
89
|
.sort((a, b) => a.rank - b.rank);
|
|
91
90
|
if (matches.length === 0) {
|
|
92
91
|
throw new Error(
|
|
93
|
-
|
|
94
|
-
? `Private data source "${requestedName}" is not shared with this app`
|
|
95
|
-
: `Private data source "${requestedName}" is not bound to this app. Private data sources are available on the published app, not in the editor's live preview`,
|
|
92
|
+
`Private data source "${requestedName}" is not bound to this app. Private data sources are available on the published app, not in the editor's live preview`,
|
|
96
93
|
);
|
|
97
94
|
}
|
|
98
95
|
|
|
@@ -118,12 +115,6 @@ export function privateDataSourceBinding(entry: PrivateDataSourceManifestEntry):
|
|
|
118
115
|
if (!entry.bindingName) {
|
|
119
116
|
throw new Error(`Private data source "${entry.name}" has no Worker binding name`);
|
|
120
117
|
}
|
|
121
|
-
const ports = previewPorts();
|
|
122
|
-
if (ports) {
|
|
123
|
-
const port = ports[entry.bindingName];
|
|
124
|
-
if (!port) throw new Error(`Private data source "${entry.name}" has no preview connection; restart the preview`);
|
|
125
|
-
return previewBinding(entry, port);
|
|
126
|
-
}
|
|
127
118
|
const binding = workerEnvironment()[entry.bindingName];
|
|
128
119
|
if (!binding) {
|
|
129
120
|
throw new Error(
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { connect } from "cloudflare:sockets";
|
|
2
1
|
import { env } from "cloudflare:workers";
|
|
3
2
|
|
|
4
3
|
// TanStack server code reads the bindings and the manifest off the ambient worker `env`.
|
|
5
4
|
export function workerEnvironment(): Record<string, unknown> {
|
|
6
5
|
return env as Record<string, unknown>;
|
|
7
6
|
}
|
|
8
|
-
|
|
9
|
-
export const socketConnect = connect;
|
|
@@ -2,9 +2,6 @@ import path from "node:path";
|
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
import { normalizePath, type Plugin } from "vite";
|
|
4
4
|
|
|
5
|
-
import { GATEWAY_TOKEN_ENV, GATEWAY_URL_ENV, startPreviewForwarders } from "./private-data-sources-preview.js";
|
|
6
|
-
import { PREVIEW_PORTS_ENV } from "./private-data-sources/preview-env.js";
|
|
7
|
-
|
|
8
5
|
/**
|
|
9
6
|
* Serves `base44:private-data-sources/<type>` to TanStack server code, so it
|
|
10
7
|
* reaches a workspace private data source with the SAME import a backend
|
|
@@ -17,10 +14,8 @@ import { PREVIEW_PORTS_ENV } from "./private-data-sources/preview-env.js";
|
|
|
17
14
|
* `env` from `cloudflare:workers`. Each specifier resolves to the compiled file
|
|
18
15
|
* so Vite bundles it like any source module.
|
|
19
16
|
*
|
|
20
|
-
* The bindings exist only on the deployed worker
|
|
21
|
-
*
|
|
22
|
-
* starts localhost forwarders to it and the same helpers connect through them; without one,
|
|
23
|
-
* a lookup throws, saying the source is available on the published app.
|
|
17
|
+
* The bindings exist only on the deployed worker: in the editor's dev preview a
|
|
18
|
+
* lookup throws, saying the source is available on the published app.
|
|
24
19
|
*/
|
|
25
20
|
|
|
26
21
|
const NAMESPACE = "base44:private-data-sources";
|
|
@@ -37,7 +32,6 @@ const SOURCE_TYPES = new Set([
|
|
|
37
32
|
"sqlserver",
|
|
38
33
|
]);
|
|
39
34
|
const IMPORTER_QUERY = "?importer=";
|
|
40
|
-
const MANIFEST_ENV = "BASE44_PRIVATE_DATA_SOURCES";
|
|
41
35
|
|
|
42
36
|
const MODULES_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), "private-data-sources");
|
|
43
37
|
|
|
@@ -59,18 +53,6 @@ export function privateDataSourcesPlugin(): Plugin {
|
|
|
59
53
|
// Ahead of Vite's own resolution so the bare scheme is never read as a URL.
|
|
60
54
|
enforce: "pre",
|
|
61
55
|
|
|
62
|
-
// Before the Cloudflare plugin builds the workerd env from process.env, so server code sees the ports.
|
|
63
|
-
async config(_config, { command }) {
|
|
64
|
-
const gatewayUrl = process.env[GATEWAY_URL_ENV];
|
|
65
|
-
const token = process.env[GATEWAY_TOKEN_ENV];
|
|
66
|
-
const manifest = process.env[MANIFEST_ENV];
|
|
67
|
-
if (command !== "serve" || process.env[PREVIEW_PORTS_ENV] || !gatewayUrl || !token || !manifest) return;
|
|
68
|
-
const { ports } = await startPreviewForwarders({ gatewayUrl, token, entries: JSON.parse(manifest) });
|
|
69
|
-
process.env[PREVIEW_PORTS_ENV] = JSON.stringify(ports);
|
|
70
|
-
// Only the forwarders need the token; keep it out of the app's server env.
|
|
71
|
-
delete process.env[GATEWAY_TOKEN_ENV];
|
|
72
|
-
},
|
|
73
|
-
|
|
74
56
|
// Like base44-runtime: errors are raised in `load`, never `resolveId`, so the
|
|
75
57
|
// dep scan of not-yet-stripped server code in the client environment survives.
|
|
76
58
|
resolveId(id, importer) {
|
package/src/utils.ts
CHANGED
|
@@ -2,9 +2,14 @@ import { readFileSync, existsSync } from "fs";
|
|
|
2
2
|
import { join } from "path";
|
|
3
3
|
import { version as viteVersion } from "vite";
|
|
4
4
|
|
|
5
|
+
const viteMajor = Number(viteVersion.split(".")[0]);
|
|
6
|
+
|
|
7
|
+
// Vite 6 added environments (`environments`, `configEnvironment`).
|
|
8
|
+
export const isVite6OrLater = viteMajor >= 6;
|
|
9
|
+
|
|
5
10
|
// Vite 8 pre-bundles deps with Rolldown instead of esbuild and deprecates
|
|
6
11
|
// `optimizeDeps.esbuildOptions`.
|
|
7
|
-
export const isVite8OrLater =
|
|
12
|
+
export const isVite8OrLater = viteMajor >= 8;
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
15
|
* The package that owns an optimizeDeps entry. Deep entries like
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preview-env.d.ts","sourceRoot":"","sources":["../../src/private-data-sources/preview-env.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,6BAA6B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preview-env.js","sourceRoot":"","sources":["../../src/private-data-sources/preview-env.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,gFAAgF;AAChF,MAAM,CAAC,MAAM,iBAAiB,GAAG,0BAA0B,CAAC"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { PrivateDataSourceManifestEntry } from "./types.js";
|
|
2
|
-
export declare function previewPorts(): Record<string, number> | null;
|
|
3
|
-
export declare function previewBinding(entry: PrivateDataSourceManifestEntry, port: number): unknown;
|
|
4
|
-
//# sourceMappingURL=preview.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../src/private-data-sources/preview.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC;AAKjE,wBAAgB,YAAY,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAG5D;AAGD,wBAAgB,cAAc,CAAC,KAAK,EAAE,8BAA8B,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAuB3F"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { PREVIEW_PORTS_ENV } from "./preview-env.js";
|
|
2
|
-
import { socketConnect, workerEnvironment } from "./runtime-environment.js";
|
|
3
|
-
const LOCALHOST = "127.0.0.1";
|
|
4
|
-
const HTTP_TYPES = new Set(["http", "elasticsearch"]);
|
|
5
|
-
export function previewPorts() {
|
|
6
|
-
const raw = workerEnvironment()[PREVIEW_PORTS_ENV];
|
|
7
|
-
return typeof raw === "string" && raw ? JSON.parse(raw) : null;
|
|
8
|
-
}
|
|
9
|
-
// Stands in for the Worker binding with the same shape, pointed at the local forwarder.
|
|
10
|
-
export function previewBinding(entry, port) {
|
|
11
|
-
if (entry.type && HTTP_TYPES.has(entry.type)) {
|
|
12
|
-
return {
|
|
13
|
-
fetch() {
|
|
14
|
-
throw new Error(`Private data source "${entry.name}" is an HTTP source; those aren't available in the live preview yet`);
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
if (entry.bindingKind === "hyperdrive") {
|
|
19
|
-
// The gateway logs in to Hyperdrive itself and ignores these credentials.
|
|
20
|
-
const user = "preview";
|
|
21
|
-
const password = "preview";
|
|
22
|
-
const database = entry.database ?? "";
|
|
23
|
-
return {
|
|
24
|
-
host: LOCALHOST,
|
|
25
|
-
port,
|
|
26
|
-
user,
|
|
27
|
-
password,
|
|
28
|
-
database,
|
|
29
|
-
connectionString: `postgresql://${user}:${password}@${LOCALHOST}:${port}/${encodeURIComponent(database)}`,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
return { connect: (_address, options) => socketConnect({ hostname: LOCALHOST, port }, options) };
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=preview.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preview.js","sourceRoot":"","sources":["../../src/private-data-sources/preview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAG5E,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;AAEtD,MAAM,UAAU,YAAY;IAC1B,MAAM,GAAG,GAAG,iBAAiB,EAAE,CAAC,iBAAiB,CAAC,CAAC;IACnD,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,CAAC,CAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAA4B,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7F,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,cAAc,CAAC,KAAqC,EAAE,IAAY;IAChF,IAAI,KAAK,CAAC,IAAI,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7C,OAAO;YACL,KAAK;gBACH,MAAM,IAAI,KAAK,CAAC,wBAAwB,KAAK,CAAC,IAAI,qEAAqE,CAAC,CAAC;YAC3H,CAAC;SACF,CAAC;IACJ,CAAC;IACD,IAAI,KAAK,CAAC,WAAW,KAAK,YAAY,EAAE,CAAC;QACvC,0EAA0E;QAC1E,MAAM,IAAI,GAAG,SAAS,CAAC;QACvB,MAAM,QAAQ,GAAG,SAAS,CAAC;QAC3B,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC;QACtC,OAAO;YACL,IAAI,EAAE,SAAS;YACf,IAAI;YACJ,IAAI;YACJ,QAAQ;YACR,QAAQ;YACR,gBAAgB,EAAE,gBAAgB,IAAI,IAAI,QAAQ,IAAI,SAAS,IAAI,IAAI,IAAI,kBAAkB,CAAC,QAAQ,CAAC,EAAE;SAC1G,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,CAAC,QAAiB,EAAE,OAAiB,EAAE,EAAE,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,EAAE,CAAC;AACtH,CAAC"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { PrivateDataSourceManifestEntry } from "./private-data-sources/types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Dev-server side of private data sources in the editor's live preview. The sandbox
|
|
4
|
-
* has no Worker bindings, so for each source in the preview manifest this listens on a
|
|
5
|
-
* localhost port and carries every TCP connection to the workspace's PDS gateway over a
|
|
6
|
-
* WebSocket. Server code's helpers point their drivers at those ports (preview.ts).
|
|
7
|
-
* Protocol: docs/features/cloudflare-backend-functions/private-data-sources-gateway.md in apper.
|
|
8
|
-
*/
|
|
9
|
-
export declare const GATEWAY_URL_ENV = "BASE44_PDS_GATEWAY_URL";
|
|
10
|
-
export declare const GATEWAY_TOKEN_ENV = "BASE44_PDS_GATEWAY_TOKEN";
|
|
11
|
-
export declare const FAILURE_COOLDOWN_MS = 5000;
|
|
12
|
-
interface GatewaySocket {
|
|
13
|
-
binaryType: string;
|
|
14
|
-
onmessage: ((event: {
|
|
15
|
-
data: unknown;
|
|
16
|
-
}) => void) | null;
|
|
17
|
-
onclose: ((event: {
|
|
18
|
-
code: number;
|
|
19
|
-
reason: string;
|
|
20
|
-
}) => void) | null;
|
|
21
|
-
onerror: (() => void) | null;
|
|
22
|
-
send(data: Uint8Array): void;
|
|
23
|
-
close(): void;
|
|
24
|
-
}
|
|
25
|
-
export interface PreviewForwarderOptions {
|
|
26
|
-
gatewayUrl: string;
|
|
27
|
-
token: string;
|
|
28
|
-
entries: PrivateDataSourceManifestEntry[];
|
|
29
|
-
openWebSocket?: (url: string, headers: Record<string, string>) => GatewaySocket;
|
|
30
|
-
warn?: (message: string) => void;
|
|
31
|
-
}
|
|
32
|
-
/** Starts one forwarder per source; resolves once all listen, with binding name -> local port. */
|
|
33
|
-
export declare function startPreviewForwarders(options: PreviewForwarderOptions): Promise<{
|
|
34
|
-
ports: Record<string, number>;
|
|
35
|
-
close: () => Promise<unknown[]>;
|
|
36
|
-
}>;
|
|
37
|
-
export {};
|
|
38
|
-
//# sourceMappingURL=private-data-sources-preview.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"private-data-sources-preview.d.ts","sourceRoot":"","sources":["../src/private-data-sources-preview.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AAEtF;;;;;;GAMG;AAEH,eAAO,MAAM,eAAe,2BAA2B,CAAC;AACxD,eAAO,MAAM,iBAAiB,6BAA6B,CAAC;AAK5D,eAAO,MAAM,mBAAmB,OAAQ,CAAC;AAEzC,UAAU,aAAa;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,CAAC,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACvD,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACpE,OAAO,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC;IAC7B,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;IAC7B,KAAK,IAAI,IAAI,CAAC;CACf;AAED,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,8BAA8B,EAAE,CAAC;IAC1C,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,aAAa,CAAC;IAChF,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AA0CD,kGAAkG;AAClG,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB;;;GAyB5E"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import net from "node:net";
|
|
2
|
-
/**
|
|
3
|
-
* Dev-server side of private data sources in the editor's live preview. The sandbox
|
|
4
|
-
* has no Worker bindings, so for each source in the preview manifest this listens on a
|
|
5
|
-
* localhost port and carries every TCP connection to the workspace's PDS gateway over a
|
|
6
|
-
* WebSocket. Server code's helpers point their drivers at those ports (preview.ts).
|
|
7
|
-
* Protocol: docs/features/cloudflare-backend-functions/private-data-sources-gateway.md in apper.
|
|
8
|
-
*/
|
|
9
|
-
export const GATEWAY_URL_ENV = "BASE44_PDS_GATEWAY_URL";
|
|
10
|
-
export const GATEWAY_TOKEN_ENV = "BASE44_PDS_GATEWAY_TOKEN";
|
|
11
|
-
const READY_FRAME = "OK";
|
|
12
|
-
// Gateway close codes that mean "this source won't answer": fail later connections fast
|
|
13
|
-
// for a while, because drivers otherwise reconnect in a tight loop.
|
|
14
|
-
const FAILURE_CODES = new Set([4401, 4404, 4501, 4502, 4503]);
|
|
15
|
-
export const FAILURE_COOLDOWN_MS = 5_000;
|
|
16
|
-
const nodeWebSocket = (url, headers) =>
|
|
17
|
-
// Node's WebSocket (undici) accepts headers; the browser one doesn't, but this only runs in the dev server.
|
|
18
|
-
new WebSocket(url, {
|
|
19
|
-
headers,
|
|
20
|
-
});
|
|
21
|
-
function forwardConnection(socket, entry, options, onFailure) {
|
|
22
|
-
socket.pause();
|
|
23
|
-
const url = `${options.gatewayUrl}?source=${encodeURIComponent(entry.name ?? "")}`;
|
|
24
|
-
const ws = (options.openWebSocket ?? nodeWebSocket)(url, { Authorization: `Bearer ${options.token}` });
|
|
25
|
-
ws.binaryType = "arraybuffer";
|
|
26
|
-
let ready = false;
|
|
27
|
-
ws.onmessage = ({ data }) => {
|
|
28
|
-
if (!ready) {
|
|
29
|
-
if (data !== READY_FRAME)
|
|
30
|
-
return;
|
|
31
|
-
ready = true;
|
|
32
|
-
socket.on("data", (chunk) => ws.send(chunk));
|
|
33
|
-
socket.resume();
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
socket.write(Buffer.from(data));
|
|
37
|
-
};
|
|
38
|
-
ws.onclose = ({ code, reason }) => {
|
|
39
|
-
if (FAILURE_CODES.has(code)) {
|
|
40
|
-
onFailure(`${reason || "connection refused"} (gateway code ${code})`);
|
|
41
|
-
socket.destroy();
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
socket.end();
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
ws.onerror = () => socket.destroy();
|
|
48
|
-
socket.on("close", () => ws.close());
|
|
49
|
-
socket.on("error", () => ws.close());
|
|
50
|
-
}
|
|
51
|
-
/** Starts one forwarder per source; resolves once all listen, with binding name -> local port. */
|
|
52
|
-
export async function startPreviewForwarders(options) {
|
|
53
|
-
const warn = options.warn ?? ((message) => console.warn(message));
|
|
54
|
-
const servers = [];
|
|
55
|
-
const ports = {};
|
|
56
|
-
for (const entry of options.entries) {
|
|
57
|
-
if (!entry.bindingName || !entry.name)
|
|
58
|
-
continue;
|
|
59
|
-
let blockedUntil = 0;
|
|
60
|
-
const server = net.createServer((socket) => {
|
|
61
|
-
if (Date.now() < blockedUntil) {
|
|
62
|
-
socket.destroy();
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
forwardConnection(socket, entry, options, (reason) => {
|
|
66
|
-
blockedUntil = Date.now() + FAILURE_COOLDOWN_MS;
|
|
67
|
-
warn(`[base44] Private data source "${entry.name}": ${reason}`);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
71
|
-
servers.push(server);
|
|
72
|
-
ports[entry.bindingName] = server.address().port;
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
ports,
|
|
76
|
-
close: () => Promise.all(servers.map((server) => new Promise((resolve) => server.close(resolve)))),
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=private-data-sources-preview.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"private-data-sources-preview.js","sourceRoot":"","sources":["../src/private-data-sources-preview.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAI3B;;;;;;GAMG;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,wBAAwB,CAAC;AACxD,MAAM,CAAC,MAAM,iBAAiB,GAAG,0BAA0B,CAAC;AAC5D,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,wFAAwF;AACxF,oEAAoE;AACpE,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAC9D,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAmBzC,MAAM,aAAa,GAAG,CAAC,GAAW,EAAE,OAA+B,EAAE,E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CAAC,CAAC;YAClE,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;QAC7E,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACrB,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAI,MAAM,CAAC,OAAO,EAAsB,CAAC,IAAI,CAAC;IACxE,CAAC;IACD,OAAO;QACL,KAAK;QACL,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;KACnG,CAAC;AACJ,CAAC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { PREVIEW_PORTS_ENV } from "./preview-env.js";
|
|
2
|
-
import { socketConnect, workerEnvironment } from "./runtime-environment.js";
|
|
3
|
-
import type { PrivateDataSourceManifestEntry } from "./types.js";
|
|
4
|
-
|
|
5
|
-
const LOCALHOST = "127.0.0.1";
|
|
6
|
-
const HTTP_TYPES = new Set(["http", "elasticsearch"]);
|
|
7
|
-
|
|
8
|
-
export function previewPorts(): Record<string, number> | null {
|
|
9
|
-
const raw = workerEnvironment()[PREVIEW_PORTS_ENV];
|
|
10
|
-
return typeof raw === "string" && raw ? (JSON.parse(raw) as Record<string, number>) : null;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// Stands in for the Worker binding with the same shape, pointed at the local forwarder.
|
|
14
|
-
export function previewBinding(entry: PrivateDataSourceManifestEntry, port: number): unknown {
|
|
15
|
-
if (entry.type && HTTP_TYPES.has(entry.type)) {
|
|
16
|
-
return {
|
|
17
|
-
fetch() {
|
|
18
|
-
throw new Error(`Private data source "${entry.name}" is an HTTP source; those aren't available in the live preview yet`);
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
if (entry.bindingKind === "hyperdrive") {
|
|
23
|
-
// The gateway logs in to Hyperdrive itself and ignores these credentials.
|
|
24
|
-
const user = "preview";
|
|
25
|
-
const password = "preview";
|
|
26
|
-
const database = entry.database ?? "";
|
|
27
|
-
return {
|
|
28
|
-
host: LOCALHOST,
|
|
29
|
-
port,
|
|
30
|
-
user,
|
|
31
|
-
password,
|
|
32
|
-
database,
|
|
33
|
-
connectionString: `postgresql://${user}:${password}@${LOCALHOST}:${port}/${encodeURIComponent(database)}`,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
return { connect: (_address: unknown, options?: unknown) => socketConnect({ hostname: LOCALHOST, port }, options) };
|
|
37
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import net from "node:net";
|
|
2
|
-
|
|
3
|
-
import type { PrivateDataSourceManifestEntry } from "./private-data-sources/types.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Dev-server side of private data sources in the editor's live preview. The sandbox
|
|
7
|
-
* has no Worker bindings, so for each source in the preview manifest this listens on a
|
|
8
|
-
* localhost port and carries every TCP connection to the workspace's PDS gateway over a
|
|
9
|
-
* WebSocket. Server code's helpers point their drivers at those ports (preview.ts).
|
|
10
|
-
* Protocol: docs/features/cloudflare-backend-functions/private-data-sources-gateway.md in apper.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
export const GATEWAY_URL_ENV = "BASE44_PDS_GATEWAY_URL";
|
|
14
|
-
export const GATEWAY_TOKEN_ENV = "BASE44_PDS_GATEWAY_TOKEN";
|
|
15
|
-
const READY_FRAME = "OK";
|
|
16
|
-
// Gateway close codes that mean "this source won't answer": fail later connections fast
|
|
17
|
-
// for a while, because drivers otherwise reconnect in a tight loop.
|
|
18
|
-
const FAILURE_CODES = new Set([4401, 4404, 4501, 4502, 4503]);
|
|
19
|
-
export const FAILURE_COOLDOWN_MS = 5_000;
|
|
20
|
-
|
|
21
|
-
interface GatewaySocket {
|
|
22
|
-
binaryType: string;
|
|
23
|
-
onmessage: ((event: { data: unknown }) => void) | null;
|
|
24
|
-
onclose: ((event: { code: number; reason: string }) => void) | null;
|
|
25
|
-
onerror: (() => void) | null;
|
|
26
|
-
send(data: Uint8Array): void;
|
|
27
|
-
close(): void;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface PreviewForwarderOptions {
|
|
31
|
-
gatewayUrl: string;
|
|
32
|
-
token: string;
|
|
33
|
-
entries: PrivateDataSourceManifestEntry[];
|
|
34
|
-
openWebSocket?: (url: string, headers: Record<string, string>) => GatewaySocket;
|
|
35
|
-
warn?: (message: string) => void;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const nodeWebSocket = (url: string, headers: Record<string, string>) =>
|
|
39
|
-
// Node's WebSocket (undici) accepts headers; the browser one doesn't, but this only runs in the dev server.
|
|
40
|
-
new (WebSocket as unknown as new (url: string, init: { headers: Record<string, string> }) => GatewaySocket)(url, {
|
|
41
|
-
headers,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
function forwardConnection(
|
|
45
|
-
socket: net.Socket,
|
|
46
|
-
entry: PrivateDataSourceManifestEntry,
|
|
47
|
-
options: PreviewForwarderOptions,
|
|
48
|
-
onFailure: (reason: string) => void,
|
|
49
|
-
) {
|
|
50
|
-
socket.pause();
|
|
51
|
-
const url = `${options.gatewayUrl}?source=${encodeURIComponent(entry.name ?? "")}`;
|
|
52
|
-
const ws = (options.openWebSocket ?? nodeWebSocket)(url, { Authorization: `Bearer ${options.token}` });
|
|
53
|
-
ws.binaryType = "arraybuffer";
|
|
54
|
-
let ready = false;
|
|
55
|
-
ws.onmessage = ({ data }) => {
|
|
56
|
-
if (!ready) {
|
|
57
|
-
if (data !== READY_FRAME) return;
|
|
58
|
-
ready = true;
|
|
59
|
-
socket.on("data", (chunk: Buffer) => ws.send(chunk));
|
|
60
|
-
socket.resume();
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
socket.write(Buffer.from(data as ArrayBuffer));
|
|
64
|
-
};
|
|
65
|
-
ws.onclose = ({ code, reason }) => {
|
|
66
|
-
if (FAILURE_CODES.has(code)) {
|
|
67
|
-
onFailure(`${reason || "connection refused"} (gateway code ${code})`);
|
|
68
|
-
socket.destroy();
|
|
69
|
-
} else {
|
|
70
|
-
socket.end();
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
ws.onerror = () => socket.destroy();
|
|
74
|
-
socket.on("close", () => ws.close());
|
|
75
|
-
socket.on("error", () => ws.close());
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Starts one forwarder per source; resolves once all listen, with binding name -> local port. */
|
|
79
|
-
export async function startPreviewForwarders(options: PreviewForwarderOptions) {
|
|
80
|
-
const warn = options.warn ?? ((message: string) => console.warn(message));
|
|
81
|
-
const servers: net.Server[] = [];
|
|
82
|
-
const ports: Record<string, number> = {};
|
|
83
|
-
for (const entry of options.entries) {
|
|
84
|
-
if (!entry.bindingName || !entry.name) continue;
|
|
85
|
-
let blockedUntil = 0;
|
|
86
|
-
const server = net.createServer((socket) => {
|
|
87
|
-
if (Date.now() < blockedUntil) {
|
|
88
|
-
socket.destroy();
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
forwardConnection(socket, entry, options, (reason) => {
|
|
92
|
-
blockedUntil = Date.now() + FAILURE_COOLDOWN_MS;
|
|
93
|
-
warn(`[base44] Private data source "${entry.name}": ${reason}`);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
97
|
-
servers.push(server);
|
|
98
|
-
ports[entry.bindingName] = (server.address() as net.AddressInfo).port;
|
|
99
|
-
}
|
|
100
|
-
return {
|
|
101
|
-
ports,
|
|
102
|
-
close: () => Promise.all(servers.map((server) => new Promise((resolve) => server.close(resolve)))),
|
|
103
|
-
};
|
|
104
|
-
}
|