@hitch42/applet 0.1.1-beta.13 → 0.1.1-beta.14
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/vite.js +8 -26
- package/package.json +1 -1
package/dist/vite.js
CHANGED
|
@@ -296,16 +296,17 @@ function createDevWorkflows(options) {
|
|
|
296
296
|
const APPLET_COMPATIBILITY_DATE = "2026-07-14";
|
|
297
297
|
const APPLET_COMPATIBILITY_FLAGS = ["nodejs_compat"];
|
|
298
298
|
let activeDevListener;
|
|
299
|
-
function clientBootstrapScript(parentOrigin, appletCode) {
|
|
299
|
+
function clientBootstrapScript(parentOrigin, appletCode, cacheQueries) {
|
|
300
300
|
return `(function () {
|
|
301
301
|
var parentOrigin = ${parentOrigin === void 0 ? "null" : JSON.stringify(parentOrigin)};
|
|
302
302
|
var appletCode = ${JSON.stringify(appletCode)};
|
|
303
303
|
var appletCodePattern = ${APPLET_CODE_PATTERN.toString()};
|
|
304
|
+
var cacheQueries = ${cacheQueries} && window.parent !== window && parentOrigin !== null;
|
|
304
305
|
|
|
305
306
|
Object.defineProperty(window, "__hitchCacheContext", {
|
|
306
307
|
configurable: false,
|
|
307
308
|
writable: false,
|
|
308
|
-
value:
|
|
309
|
+
value: cacheQueries
|
|
309
310
|
? fetch("/__applet/context/" + encodeURIComponent(appletCode), {
|
|
310
311
|
credentials: "same-origin",
|
|
311
312
|
headers: { accept: "application/json" }
|
|
@@ -324,7 +325,7 @@ function clientBootstrapScript(parentOrigin, appletCode) {
|
|
|
324
325
|
Object.defineProperty(window, "__hitchCacheDatabase", {
|
|
325
326
|
configurable: false,
|
|
326
327
|
writable: false,
|
|
327
|
-
value:
|
|
328
|
+
value: cacheQueries
|
|
328
329
|
? (function () {
|
|
329
330
|
var database = (${openQueryCacheDatabase.toString()})();
|
|
330
331
|
database.catch(function () {});
|
|
@@ -568,8 +569,7 @@ function applet(sourceDefinition) {
|
|
|
568
569
|
devContext = {
|
|
569
570
|
person,
|
|
570
571
|
proxy,
|
|
571
|
-
orgUrl
|
|
572
|
-
cacheBuster: randomUUID()
|
|
572
|
+
orgUrl
|
|
573
573
|
};
|
|
574
574
|
if (hasServer && devListener === void 0) {
|
|
575
575
|
if (activeDevListener?.listening) activeDevListener.close();
|
|
@@ -627,7 +627,7 @@ function applet(sourceDefinition) {
|
|
|
627
627
|
configureServer(server) {
|
|
628
628
|
if (devContext === void 0) return;
|
|
629
629
|
const { manifest } = requireAppletConfig();
|
|
630
|
-
const { person, proxy, orgUrl
|
|
630
|
+
const { person, proxy, orgUrl } = devContext;
|
|
631
631
|
const orgOrigin = new URL(orgUrl).origin;
|
|
632
632
|
devLogger = server.config.logger;
|
|
633
633
|
const skipSleep = process.env.HITCH_DEV_SKIP_SLEEP === "1";
|
|
@@ -685,24 +685,6 @@ function applet(sourceDefinition) {
|
|
|
685
685
|
server.middlewares.use((request, response, next) => {
|
|
686
686
|
if (request.url === mount || request.url?.startsWith(`${mount}?`)) request.url = `${mount}/${request.url.slice(mount.length)}`;
|
|
687
687
|
const url = request.url ?? "";
|
|
688
|
-
const pathname = url.split("?", 1)[0] ?? "";
|
|
689
|
-
if (pathname.startsWith("/__applet/context/")) {
|
|
690
|
-
if (pathname !== `/__applet/context/${manifest.code}` || request.method !== "GET") {
|
|
691
|
-
response.writeHead(404).end();
|
|
692
|
-
return;
|
|
693
|
-
}
|
|
694
|
-
if (refusesClient(request.headers, request.socket.remoteAddress)) {
|
|
695
|
-
response.writeHead(403).end();
|
|
696
|
-
return;
|
|
697
|
-
}
|
|
698
|
-
response.setHeader("Cache-Control", "no-store");
|
|
699
|
-
response.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
700
|
-
response.end(JSON.stringify({
|
|
701
|
-
cacheBuster,
|
|
702
|
-
cacheScope: person.id
|
|
703
|
-
}));
|
|
704
|
-
return;
|
|
705
|
-
}
|
|
706
688
|
if (url === "/_hitch/client.js" || url.startsWith("/_hitch/client.js?")) {
|
|
707
689
|
response.statusCode = 200;
|
|
708
690
|
response.setHeader("Cache-Control", "no-store");
|
|
@@ -739,7 +721,7 @@ function applet(sourceDefinition) {
|
|
|
739
721
|
},
|
|
740
722
|
transformIndexHtml: {
|
|
741
723
|
order: "post",
|
|
742
|
-
handler(html) {
|
|
724
|
+
handler(html, { server }) {
|
|
743
725
|
const parentOrigin = devContext?.orgUrl === void 0 ? themeStylesheetUrl === void 0 ? void 0 : new URL(themeStylesheetUrl).origin : new URL(devContext.orgUrl).origin;
|
|
744
726
|
return {
|
|
745
727
|
html: themeStylesheetUrl === void 0 ? html : html.replace("href=\"/theme.css\"", `href="${themeStylesheetUrl}"`),
|
|
@@ -753,7 +735,7 @@ function applet(sourceDefinition) {
|
|
|
753
735
|
injectTo: "head-prepend"
|
|
754
736
|
}, {
|
|
755
737
|
tag: "script",
|
|
756
|
-
children: clientBootstrapScript(parentOrigin, requireAppletConfig().manifest.code),
|
|
738
|
+
children: clientBootstrapScript(parentOrigin, requireAppletConfig().manifest.code, server === void 0),
|
|
757
739
|
injectTo: "head-prepend"
|
|
758
740
|
}]
|
|
759
741
|
};
|