@archie/devtools 0.0.10 → 0.0.11
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 +53 -111
- package/dist/chunk-QZ7TP4HQ.mjs +7 -0
- package/dist/client/client.d.mts +41 -2
- package/dist/client/client.d.ts +41 -2
- package/dist/client/client.js +8545 -5
- package/dist/client/client.mjs +8594 -3
- package/dist/index.d.mts +28 -23
- package/dist/index.d.ts +28 -23
- package/dist/index.js +500 -8
- package/dist/index.mjs +490 -8
- package/package.json +21 -20
- package/dist/chunk-D5EA6RR5.mjs +0 -47
- package/dist/chunk-EQV632XF.mjs +0 -66
- package/dist/chunk-REJDPYAO.mjs +0 -101
- package/dist/client/inject-inspector/auto.d.mts +0 -2
- package/dist/client/inject-inspector/auto.d.ts +0 -2
- package/dist/client/inject-inspector/auto.js +0 -133
- package/dist/client/inject-inspector/auto.mjs +0 -7
- package/dist/client/inject-inspector/injectInspector.d.mts +0 -57
- package/dist/client/inject-inspector/injectInspector.d.ts +0 -57
- package/dist/client/inject-inspector/injectInspector.js +0 -160
- package/dist/client/inject-inspector/injectInspector.mjs +0 -9
- package/dist/client/route-listener/routeListener.d.mts +0 -49
- package/dist/client/route-listener/routeListener.d.ts +0 -49
- package/dist/client/route-listener/routeListener.js +0 -90
- package/dist/client/route-listener/routeListener.mjs +0 -6
- package/dist/constants/archieOrigins.d.mts +0 -48
- package/dist/constants/archieOrigins.d.ts +0 -48
- package/dist/constants/archieOrigins.js +0 -77
- package/dist/constants/archieOrigins.mjs +0 -18
package/dist/chunk-EQV632XF.mjs
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// src/client/route-listener/routeListener.ts
|
|
2
|
-
function extractAllRoutes(routes, parentPath = "") {
|
|
3
|
-
const result = [];
|
|
4
|
-
for (const route of routes) {
|
|
5
|
-
const path = route.path ? (parentPath + "/" + route.path).replace(/\/+/g, "/") : parentPath || "/";
|
|
6
|
-
if (route.path !== void 0 || route.index) {
|
|
7
|
-
result.push({
|
|
8
|
-
id: route.id,
|
|
9
|
-
path: route.index ? parentPath || "/" : path,
|
|
10
|
-
hasChildren: !!(route.children && route.children.length > 0)
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
if (route.children) {
|
|
14
|
-
result.push(...extractAllRoutes(route.children, path));
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return result;
|
|
18
|
-
}
|
|
19
|
-
function broadcastRouteState(target, state, allRoutes) {
|
|
20
|
-
try {
|
|
21
|
-
const message = {
|
|
22
|
-
type: "ARCHIE_ROUTE_UPDATE",
|
|
23
|
-
payload: {
|
|
24
|
-
path: state.location.pathname,
|
|
25
|
-
search: state.location.search,
|
|
26
|
-
hash: state.location.hash,
|
|
27
|
-
matches: state.matches.map((m) => ({
|
|
28
|
-
id: m.route.id,
|
|
29
|
-
pathname: m.pathname,
|
|
30
|
-
params: m.params
|
|
31
|
-
})),
|
|
32
|
-
allRoutes,
|
|
33
|
-
timestamp: Date.now()
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
target.postMessage(message, "*");
|
|
37
|
-
} catch {
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function setupArchieRouteListener(router) {
|
|
41
|
-
const target = window.parent !== window ? window.parent : window.opener;
|
|
42
|
-
if (!target) {
|
|
43
|
-
return () => {
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
broadcastRouteState(target, router.state, extractAllRoutes(router.routes));
|
|
47
|
-
const unsubscribe = router.subscribe((state) => {
|
|
48
|
-
const currentRoutes = extractAllRoutes(router.routes);
|
|
49
|
-
broadcastRouteState(target, state, currentRoutes);
|
|
50
|
-
});
|
|
51
|
-
const handleMessage = (event) => {
|
|
52
|
-
if (event.data?.type === "ARCHIE_QUERY_ROUTES") {
|
|
53
|
-
const currentRoutes = extractAllRoutes(router.routes);
|
|
54
|
-
broadcastRouteState(target, router.state, currentRoutes);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
window.addEventListener("message", handleMessage);
|
|
58
|
-
return () => {
|
|
59
|
-
unsubscribe();
|
|
60
|
-
window.removeEventListener("message", handleMessage);
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export {
|
|
65
|
-
setupArchieRouteListener
|
|
66
|
-
};
|
package/dist/chunk-REJDPYAO.mjs
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getAllowedOriginPatterns,
|
|
3
|
-
getAllowedOrigins,
|
|
4
|
-
isPreviewOrigin
|
|
5
|
-
} from "./chunk-D5EA6RR5.mjs";
|
|
6
|
-
|
|
7
|
-
// src/client/inject-inspector/injectInspector.ts
|
|
8
|
-
var DEFAULT_SCRIPT_ID = "archie-inspector-script";
|
|
9
|
-
var REMOTE_INSPECTOR_SCRIPT_URL = "https://pub-bf238c278d9644b39ec34ecaca1d315c.r2.dev/inspector.standalone.js";
|
|
10
|
-
function getInspectorScriptUrl(base, cacheBust = true) {
|
|
11
|
-
const separator = base.includes("?") ? "&" : "?";
|
|
12
|
-
return cacheBust ? `${base}${separator}h=${Date.now()}` : base;
|
|
13
|
-
}
|
|
14
|
-
function isLocalDev(referrer) {
|
|
15
|
-
if (!referrer) return true;
|
|
16
|
-
try {
|
|
17
|
-
const u = new URL(referrer);
|
|
18
|
-
return u.hostname === "localhost" || u.hostname === "127.0.0.1";
|
|
19
|
-
} catch {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function injectInspector(opts = {}) {
|
|
24
|
-
if (typeof document === "undefined") return null;
|
|
25
|
-
const id = opts.id ?? DEFAULT_SCRIPT_ID;
|
|
26
|
-
const existing = document.getElementById(id);
|
|
27
|
-
if (existing) return Promise.resolve(existing);
|
|
28
|
-
const win = typeof window !== "undefined" ? window : null;
|
|
29
|
-
if (win) {
|
|
30
|
-
const referrer = typeof document.referrer === "string" ? document.referrer : "";
|
|
31
|
-
const dev = opts.dev ?? isLocalDev(referrer);
|
|
32
|
-
let allowed;
|
|
33
|
-
if (opts.allowedOrigins !== void 0 && opts.allowedOrigins !== "*") {
|
|
34
|
-
const v = opts.allowedOrigins;
|
|
35
|
-
allowed = typeof v === "string" ? [v] : Array.isArray(v) ? v : [];
|
|
36
|
-
} else {
|
|
37
|
-
allowed = getAllowedOrigins(dev);
|
|
38
|
-
}
|
|
39
|
-
if (allowed.length > 0) {
|
|
40
|
-
win["__ARCHIE_INSPECTOR_ALLOWED_ORIGINS__"] = allowed;
|
|
41
|
-
}
|
|
42
|
-
const patterns = getAllowedOriginPatterns();
|
|
43
|
-
if (patterns.length > 0) {
|
|
44
|
-
win["__ARCHIE_INSPECTOR_ALLOWED_ORIGIN_PATTERNS__"] = patterns;
|
|
45
|
-
}
|
|
46
|
-
let target;
|
|
47
|
-
if (opts.targetOrigin !== void 0 && opts.targetOrigin !== "*") {
|
|
48
|
-
target = opts.targetOrigin || void 0;
|
|
49
|
-
} else if (referrer) {
|
|
50
|
-
try {
|
|
51
|
-
const referrerOrigin = new URL(referrer).origin;
|
|
52
|
-
if (!isPreviewOrigin(referrerOrigin)) {
|
|
53
|
-
target = referrerOrigin;
|
|
54
|
-
}
|
|
55
|
-
} catch {
|
|
56
|
-
target = void 0;
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
target = void 0;
|
|
60
|
-
}
|
|
61
|
-
if (target) {
|
|
62
|
-
win["__ARCHIE_INSPECTOR_TARGET_ORIGIN__"] = target;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
const useRemote = opts.scriptSource !== "local";
|
|
66
|
-
if (useRemote) {
|
|
67
|
-
const script = document.createElement("script");
|
|
68
|
-
script.id = id;
|
|
69
|
-
script.src = getInspectorScriptUrl(opts.scriptUrl ?? REMOTE_INSPECTOR_SCRIPT_URL, true);
|
|
70
|
-
document.head.appendChild(script);
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
const localInspectorModulePath = "./inspector.js";
|
|
74
|
-
return import(
|
|
75
|
-
/* @vite-ignore */
|
|
76
|
-
localInspectorModulePath
|
|
77
|
-
).then((m) => {
|
|
78
|
-
try {
|
|
79
|
-
m.default();
|
|
80
|
-
} catch (err) {
|
|
81
|
-
if (typeof console !== "undefined" && console.error) {
|
|
82
|
-
console.error("[Archie DevTools] Inspector failed to run:", err);
|
|
83
|
-
}
|
|
84
|
-
throw err;
|
|
85
|
-
}
|
|
86
|
-
const script = document.createElement("script");
|
|
87
|
-
script.id = id;
|
|
88
|
-
document.head.appendChild(script);
|
|
89
|
-
return script;
|
|
90
|
-
}).catch((err) => {
|
|
91
|
-
if (typeof console !== "undefined" && console.error) {
|
|
92
|
-
console.error("[Archie DevTools] Failed to load inspector:", err);
|
|
93
|
-
}
|
|
94
|
-
throw err;
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export {
|
|
99
|
-
REMOTE_INSPECTOR_SCRIPT_URL,
|
|
100
|
-
injectInspector
|
|
101
|
-
};
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// src/constants/archieOrigins.ts
|
|
4
|
-
var ARCHIE_HOST_ORIGINS = [
|
|
5
|
-
"https://app.dev.archie-platform.com",
|
|
6
|
-
"https://app.staging.archie-platform.com",
|
|
7
|
-
"https://app.archie.com"
|
|
8
|
-
];
|
|
9
|
-
var ARCHIE_PREVIEW_ORIGIN_SUFFIXES = [
|
|
10
|
-
".staging.archie-platform.com",
|
|
11
|
-
".archie-platform.com",
|
|
12
|
-
".archie.com"
|
|
13
|
-
];
|
|
14
|
-
var PREVIEW_DEPLOY_HOST_SUFFIXES = [
|
|
15
|
-
".previews.staging.archie-platform.com",
|
|
16
|
-
".previews.archie-platform.com",
|
|
17
|
-
".previews.archie.com"
|
|
18
|
-
];
|
|
19
|
-
var LOCAL_DEV_ORIGINS = [
|
|
20
|
-
"http://localhost:3000",
|
|
21
|
-
"http://localhost:3001"
|
|
22
|
-
];
|
|
23
|
-
function getAllowedOrigins(includeLocal = false) {
|
|
24
|
-
const list = [...ARCHIE_HOST_ORIGINS];
|
|
25
|
-
if (includeLocal) list.push(...LOCAL_DEV_ORIGINS);
|
|
26
|
-
return list;
|
|
27
|
-
}
|
|
28
|
-
function getAllowedOriginPatterns() {
|
|
29
|
-
return [...ARCHIE_PREVIEW_ORIGIN_SUFFIXES];
|
|
30
|
-
}
|
|
31
|
-
function isPreviewOrigin(origin) {
|
|
32
|
-
if (!origin || typeof origin !== "string") return false;
|
|
33
|
-
try {
|
|
34
|
-
const host = new URL(origin).host;
|
|
35
|
-
return PREVIEW_DEPLOY_HOST_SUFFIXES.some((suffix) => host.endsWith(suffix));
|
|
36
|
-
} catch {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// src/client/inject-inspector/injectInspector.ts
|
|
42
|
-
var DEFAULT_SCRIPT_ID = "archie-inspector-script";
|
|
43
|
-
var REMOTE_INSPECTOR_SCRIPT_URL = "https://pub-bf238c278d9644b39ec34ecaca1d315c.r2.dev/inspector.standalone.js";
|
|
44
|
-
function getInspectorScriptUrl(base, cacheBust = true) {
|
|
45
|
-
const separator = base.includes("?") ? "&" : "?";
|
|
46
|
-
return cacheBust ? `${base}${separator}h=${Date.now()}` : base;
|
|
47
|
-
}
|
|
48
|
-
function isLocalDev(referrer) {
|
|
49
|
-
if (!referrer) return true;
|
|
50
|
-
try {
|
|
51
|
-
const u = new URL(referrer);
|
|
52
|
-
return u.hostname === "localhost" || u.hostname === "127.0.0.1";
|
|
53
|
-
} catch {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
function injectInspector(opts = {}) {
|
|
58
|
-
if (typeof document === "undefined") return null;
|
|
59
|
-
const id = opts.id ?? DEFAULT_SCRIPT_ID;
|
|
60
|
-
const existing = document.getElementById(id);
|
|
61
|
-
if (existing) return Promise.resolve(existing);
|
|
62
|
-
const win = typeof window !== "undefined" ? window : null;
|
|
63
|
-
if (win) {
|
|
64
|
-
const referrer = typeof document.referrer === "string" ? document.referrer : "";
|
|
65
|
-
const dev = opts.dev ?? isLocalDev(referrer);
|
|
66
|
-
let allowed;
|
|
67
|
-
if (opts.allowedOrigins !== void 0 && opts.allowedOrigins !== "*") {
|
|
68
|
-
const v = opts.allowedOrigins;
|
|
69
|
-
allowed = typeof v === "string" ? [v] : Array.isArray(v) ? v : [];
|
|
70
|
-
} else {
|
|
71
|
-
allowed = getAllowedOrigins(dev);
|
|
72
|
-
}
|
|
73
|
-
if (allowed.length > 0) {
|
|
74
|
-
win["__ARCHIE_INSPECTOR_ALLOWED_ORIGINS__"] = allowed;
|
|
75
|
-
}
|
|
76
|
-
const patterns = getAllowedOriginPatterns();
|
|
77
|
-
if (patterns.length > 0) {
|
|
78
|
-
win["__ARCHIE_INSPECTOR_ALLOWED_ORIGIN_PATTERNS__"] = patterns;
|
|
79
|
-
}
|
|
80
|
-
let target;
|
|
81
|
-
if (opts.targetOrigin !== void 0 && opts.targetOrigin !== "*") {
|
|
82
|
-
target = opts.targetOrigin || void 0;
|
|
83
|
-
} else if (referrer) {
|
|
84
|
-
try {
|
|
85
|
-
const referrerOrigin = new URL(referrer).origin;
|
|
86
|
-
if (!isPreviewOrigin(referrerOrigin)) {
|
|
87
|
-
target = referrerOrigin;
|
|
88
|
-
}
|
|
89
|
-
} catch {
|
|
90
|
-
target = void 0;
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
target = void 0;
|
|
94
|
-
}
|
|
95
|
-
if (target) {
|
|
96
|
-
win["__ARCHIE_INSPECTOR_TARGET_ORIGIN__"] = target;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
const useRemote = opts.scriptSource !== "local";
|
|
100
|
-
if (useRemote) {
|
|
101
|
-
const script = document.createElement("script");
|
|
102
|
-
script.id = id;
|
|
103
|
-
script.src = getInspectorScriptUrl(opts.scriptUrl ?? REMOTE_INSPECTOR_SCRIPT_URL, true);
|
|
104
|
-
document.head.appendChild(script);
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
const localInspectorModulePath = "./inspector.js";
|
|
108
|
-
return import(
|
|
109
|
-
/* @vite-ignore */
|
|
110
|
-
localInspectorModulePath
|
|
111
|
-
).then((m) => {
|
|
112
|
-
try {
|
|
113
|
-
m.default();
|
|
114
|
-
} catch (err) {
|
|
115
|
-
if (typeof console !== "undefined" && console.error) {
|
|
116
|
-
console.error("[Archie DevTools] Inspector failed to run:", err);
|
|
117
|
-
}
|
|
118
|
-
throw err;
|
|
119
|
-
}
|
|
120
|
-
const script = document.createElement("script");
|
|
121
|
-
script.id = id;
|
|
122
|
-
document.head.appendChild(script);
|
|
123
|
-
return script;
|
|
124
|
-
}).catch((err) => {
|
|
125
|
-
if (typeof console !== "undefined" && console.error) {
|
|
126
|
-
console.error("[Archie DevTools] Failed to load inspector:", err);
|
|
127
|
-
}
|
|
128
|
-
throw err;
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// src/client/inject-inspector/auto.ts
|
|
133
|
-
injectInspector({ scriptSource: "remote" });
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default CDN URL for the standalone inspector script.
|
|
3
|
-
* Override via InjectOptions.scriptUrl when you need SRI, a private CDN, or a pinned version.
|
|
4
|
-
* Note: cache-busting with Date.now() is intentional (avoids stale inspectors) but
|
|
5
|
-
* incompatible with Subresource Integrity — pass a fixed scriptUrl + integrity attribute externally if needed.
|
|
6
|
-
*/
|
|
7
|
-
declare const REMOTE_INSPECTOR_SCRIPT_URL = "https://pub-bf238c278d9644b39ec34ecaca1d315c.r2.dev/inspector.standalone.js";
|
|
8
|
-
/** Only configured domains (Archie host origins) and optionally localhost in dev. "*" is never used. */
|
|
9
|
-
type InjectOptions = {
|
|
10
|
-
id?: string;
|
|
11
|
-
/**
|
|
12
|
-
* Origin(s) allowed to send postMessage commands to the inspector.
|
|
13
|
-
* If not set, uses Archie host origins + localhost when dev is true.
|
|
14
|
-
* "*" is not allowed; pass an array of concrete origins.
|
|
15
|
-
*/
|
|
16
|
-
allowedOrigins?: string | string[];
|
|
17
|
-
/**
|
|
18
|
-
* Origin to which the inspector sends postMessage replies (the parent window).
|
|
19
|
-
* If not set and in an iframe, uses document.referrer origin — except when the page
|
|
20
|
-
* is a preview iframe (*.previews.staging.archie-platform.com), in which case you
|
|
21
|
-
* must pass the parent app origin (e.g. https://app.dev.archie-platform.com).
|
|
22
|
-
* "*" is not allowed.
|
|
23
|
-
*/
|
|
24
|
-
targetOrigin?: string;
|
|
25
|
-
/**
|
|
26
|
-
* When true, allowedOrigins default includes localhost for local testing.
|
|
27
|
-
* When undefined, inferred from document.referrer (localhost or missing = dev).
|
|
28
|
-
*/
|
|
29
|
-
dev?: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Where to load the inspector script from.
|
|
32
|
-
* - "remote" (default): load from REMOTE_INSPECTOR_SCRIPT_URL with a dynamic hash to avoid cache.
|
|
33
|
-
* - "local": load from the bundled module (import('./inspector.js')).
|
|
34
|
-
*/
|
|
35
|
-
scriptSource?: 'remote' | 'local';
|
|
36
|
-
/**
|
|
37
|
-
* Override the remote script URL (e.g. your own CDN, a pinned version, or a URL with SRI hash).
|
|
38
|
-
* Only used when scriptSource is "remote" (default). Defaults to REMOTE_INSPECTOR_SCRIPT_URL.
|
|
39
|
-
* Example: 'https://my-cdn.com/inspector.standalone.js'
|
|
40
|
-
*/
|
|
41
|
-
scriptUrl?: string;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Loads and runs the Archie inspector script (dynamic import).
|
|
45
|
-
* Safe to call multiple times: avoids duplicate execution by id.
|
|
46
|
-
* No-op when run outside the browser (e.g. SSR).
|
|
47
|
-
*
|
|
48
|
-
* Security: Origin restrictions are always set (never "*"). We do not inject
|
|
49
|
-
* script via eval/Function or write HTML (innerHTML/insertAdjacentHTML).
|
|
50
|
-
* The inspector only accepts postMessage from allowlisted origins and
|
|
51
|
-
* sanitizes style values before applying to the DOM.
|
|
52
|
-
*
|
|
53
|
-
* @returns Promise that resolves to the marker script element, or null if not in browser / already present
|
|
54
|
-
*/
|
|
55
|
-
declare function injectInspector(opts?: InjectOptions): Promise<HTMLScriptElement | null> | null;
|
|
56
|
-
|
|
57
|
-
export { type InjectOptions, REMOTE_INSPECTOR_SCRIPT_URL, injectInspector };
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default CDN URL for the standalone inspector script.
|
|
3
|
-
* Override via InjectOptions.scriptUrl when you need SRI, a private CDN, or a pinned version.
|
|
4
|
-
* Note: cache-busting with Date.now() is intentional (avoids stale inspectors) but
|
|
5
|
-
* incompatible with Subresource Integrity — pass a fixed scriptUrl + integrity attribute externally if needed.
|
|
6
|
-
*/
|
|
7
|
-
declare const REMOTE_INSPECTOR_SCRIPT_URL = "https://pub-bf238c278d9644b39ec34ecaca1d315c.r2.dev/inspector.standalone.js";
|
|
8
|
-
/** Only configured domains (Archie host origins) and optionally localhost in dev. "*" is never used. */
|
|
9
|
-
type InjectOptions = {
|
|
10
|
-
id?: string;
|
|
11
|
-
/**
|
|
12
|
-
* Origin(s) allowed to send postMessage commands to the inspector.
|
|
13
|
-
* If not set, uses Archie host origins + localhost when dev is true.
|
|
14
|
-
* "*" is not allowed; pass an array of concrete origins.
|
|
15
|
-
*/
|
|
16
|
-
allowedOrigins?: string | string[];
|
|
17
|
-
/**
|
|
18
|
-
* Origin to which the inspector sends postMessage replies (the parent window).
|
|
19
|
-
* If not set and in an iframe, uses document.referrer origin — except when the page
|
|
20
|
-
* is a preview iframe (*.previews.staging.archie-platform.com), in which case you
|
|
21
|
-
* must pass the parent app origin (e.g. https://app.dev.archie-platform.com).
|
|
22
|
-
* "*" is not allowed.
|
|
23
|
-
*/
|
|
24
|
-
targetOrigin?: string;
|
|
25
|
-
/**
|
|
26
|
-
* When true, allowedOrigins default includes localhost for local testing.
|
|
27
|
-
* When undefined, inferred from document.referrer (localhost or missing = dev).
|
|
28
|
-
*/
|
|
29
|
-
dev?: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Where to load the inspector script from.
|
|
32
|
-
* - "remote" (default): load from REMOTE_INSPECTOR_SCRIPT_URL with a dynamic hash to avoid cache.
|
|
33
|
-
* - "local": load from the bundled module (import('./inspector.js')).
|
|
34
|
-
*/
|
|
35
|
-
scriptSource?: 'remote' | 'local';
|
|
36
|
-
/**
|
|
37
|
-
* Override the remote script URL (e.g. your own CDN, a pinned version, or a URL with SRI hash).
|
|
38
|
-
* Only used when scriptSource is "remote" (default). Defaults to REMOTE_INSPECTOR_SCRIPT_URL.
|
|
39
|
-
* Example: 'https://my-cdn.com/inspector.standalone.js'
|
|
40
|
-
*/
|
|
41
|
-
scriptUrl?: string;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Loads and runs the Archie inspector script (dynamic import).
|
|
45
|
-
* Safe to call multiple times: avoids duplicate execution by id.
|
|
46
|
-
* No-op when run outside the browser (e.g. SSR).
|
|
47
|
-
*
|
|
48
|
-
* Security: Origin restrictions are always set (never "*"). We do not inject
|
|
49
|
-
* script via eval/Function or write HTML (innerHTML/insertAdjacentHTML).
|
|
50
|
-
* The inspector only accepts postMessage from allowlisted origins and
|
|
51
|
-
* sanitizes style values before applying to the DOM.
|
|
52
|
-
*
|
|
53
|
-
* @returns Promise that resolves to the marker script element, or null if not in browser / already present
|
|
54
|
-
*/
|
|
55
|
-
declare function injectInspector(opts?: InjectOptions): Promise<HTMLScriptElement | null> | null;
|
|
56
|
-
|
|
57
|
-
export { type InjectOptions, REMOTE_INSPECTOR_SCRIPT_URL, injectInspector };
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/client/inject-inspector/injectInspector.ts
|
|
21
|
-
var injectInspector_exports = {};
|
|
22
|
-
__export(injectInspector_exports, {
|
|
23
|
-
REMOTE_INSPECTOR_SCRIPT_URL: () => REMOTE_INSPECTOR_SCRIPT_URL,
|
|
24
|
-
injectInspector: () => injectInspector
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(injectInspector_exports);
|
|
27
|
-
|
|
28
|
-
// src/constants/archieOrigins.ts
|
|
29
|
-
var ARCHIE_HOST_ORIGINS = [
|
|
30
|
-
"https://app.dev.archie-platform.com",
|
|
31
|
-
"https://app.staging.archie-platform.com",
|
|
32
|
-
"https://app.archie.com"
|
|
33
|
-
];
|
|
34
|
-
var ARCHIE_PREVIEW_ORIGIN_SUFFIXES = [
|
|
35
|
-
".staging.archie-platform.com",
|
|
36
|
-
".archie-platform.com",
|
|
37
|
-
".archie.com"
|
|
38
|
-
];
|
|
39
|
-
var PREVIEW_DEPLOY_HOST_SUFFIXES = [
|
|
40
|
-
".previews.staging.archie-platform.com",
|
|
41
|
-
".previews.archie-platform.com",
|
|
42
|
-
".previews.archie.com"
|
|
43
|
-
];
|
|
44
|
-
var LOCAL_DEV_ORIGINS = [
|
|
45
|
-
"http://localhost:3000",
|
|
46
|
-
"http://localhost:3001"
|
|
47
|
-
];
|
|
48
|
-
function getAllowedOrigins(includeLocal = false) {
|
|
49
|
-
const list = [...ARCHIE_HOST_ORIGINS];
|
|
50
|
-
if (includeLocal) list.push(...LOCAL_DEV_ORIGINS);
|
|
51
|
-
return list;
|
|
52
|
-
}
|
|
53
|
-
function getAllowedOriginPatterns() {
|
|
54
|
-
return [...ARCHIE_PREVIEW_ORIGIN_SUFFIXES];
|
|
55
|
-
}
|
|
56
|
-
function isPreviewOrigin(origin) {
|
|
57
|
-
if (!origin || typeof origin !== "string") return false;
|
|
58
|
-
try {
|
|
59
|
-
const host = new URL(origin).host;
|
|
60
|
-
return PREVIEW_DEPLOY_HOST_SUFFIXES.some((suffix) => host.endsWith(suffix));
|
|
61
|
-
} catch {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/client/inject-inspector/injectInspector.ts
|
|
67
|
-
var DEFAULT_SCRIPT_ID = "archie-inspector-script";
|
|
68
|
-
var REMOTE_INSPECTOR_SCRIPT_URL = "https://pub-bf238c278d9644b39ec34ecaca1d315c.r2.dev/inspector.standalone.js";
|
|
69
|
-
function getInspectorScriptUrl(base, cacheBust = true) {
|
|
70
|
-
const separator = base.includes("?") ? "&" : "?";
|
|
71
|
-
return cacheBust ? `${base}${separator}h=${Date.now()}` : base;
|
|
72
|
-
}
|
|
73
|
-
function isLocalDev(referrer) {
|
|
74
|
-
if (!referrer) return true;
|
|
75
|
-
try {
|
|
76
|
-
const u = new URL(referrer);
|
|
77
|
-
return u.hostname === "localhost" || u.hostname === "127.0.0.1";
|
|
78
|
-
} catch {
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
function injectInspector(opts = {}) {
|
|
83
|
-
if (typeof document === "undefined") return null;
|
|
84
|
-
const id = opts.id ?? DEFAULT_SCRIPT_ID;
|
|
85
|
-
const existing = document.getElementById(id);
|
|
86
|
-
if (existing) return Promise.resolve(existing);
|
|
87
|
-
const win = typeof window !== "undefined" ? window : null;
|
|
88
|
-
if (win) {
|
|
89
|
-
const referrer = typeof document.referrer === "string" ? document.referrer : "";
|
|
90
|
-
const dev = opts.dev ?? isLocalDev(referrer);
|
|
91
|
-
let allowed;
|
|
92
|
-
if (opts.allowedOrigins !== void 0 && opts.allowedOrigins !== "*") {
|
|
93
|
-
const v = opts.allowedOrigins;
|
|
94
|
-
allowed = typeof v === "string" ? [v] : Array.isArray(v) ? v : [];
|
|
95
|
-
} else {
|
|
96
|
-
allowed = getAllowedOrigins(dev);
|
|
97
|
-
}
|
|
98
|
-
if (allowed.length > 0) {
|
|
99
|
-
win["__ARCHIE_INSPECTOR_ALLOWED_ORIGINS__"] = allowed;
|
|
100
|
-
}
|
|
101
|
-
const patterns = getAllowedOriginPatterns();
|
|
102
|
-
if (patterns.length > 0) {
|
|
103
|
-
win["__ARCHIE_INSPECTOR_ALLOWED_ORIGIN_PATTERNS__"] = patterns;
|
|
104
|
-
}
|
|
105
|
-
let target;
|
|
106
|
-
if (opts.targetOrigin !== void 0 && opts.targetOrigin !== "*") {
|
|
107
|
-
target = opts.targetOrigin || void 0;
|
|
108
|
-
} else if (referrer) {
|
|
109
|
-
try {
|
|
110
|
-
const referrerOrigin = new URL(referrer).origin;
|
|
111
|
-
if (!isPreviewOrigin(referrerOrigin)) {
|
|
112
|
-
target = referrerOrigin;
|
|
113
|
-
}
|
|
114
|
-
} catch {
|
|
115
|
-
target = void 0;
|
|
116
|
-
}
|
|
117
|
-
} else {
|
|
118
|
-
target = void 0;
|
|
119
|
-
}
|
|
120
|
-
if (target) {
|
|
121
|
-
win["__ARCHIE_INSPECTOR_TARGET_ORIGIN__"] = target;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
const useRemote = opts.scriptSource !== "local";
|
|
125
|
-
if (useRemote) {
|
|
126
|
-
const script = document.createElement("script");
|
|
127
|
-
script.id = id;
|
|
128
|
-
script.src = getInspectorScriptUrl(opts.scriptUrl ?? REMOTE_INSPECTOR_SCRIPT_URL, true);
|
|
129
|
-
document.head.appendChild(script);
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
const localInspectorModulePath = "./inspector.js";
|
|
133
|
-
return import(
|
|
134
|
-
/* @vite-ignore */
|
|
135
|
-
localInspectorModulePath
|
|
136
|
-
).then((m) => {
|
|
137
|
-
try {
|
|
138
|
-
m.default();
|
|
139
|
-
} catch (err) {
|
|
140
|
-
if (typeof console !== "undefined" && console.error) {
|
|
141
|
-
console.error("[Archie DevTools] Inspector failed to run:", err);
|
|
142
|
-
}
|
|
143
|
-
throw err;
|
|
144
|
-
}
|
|
145
|
-
const script = document.createElement("script");
|
|
146
|
-
script.id = id;
|
|
147
|
-
document.head.appendChild(script);
|
|
148
|
-
return script;
|
|
149
|
-
}).catch((err) => {
|
|
150
|
-
if (typeof console !== "undefined" && console.error) {
|
|
151
|
-
console.error("[Archie DevTools] Failed to load inspector:", err);
|
|
152
|
-
}
|
|
153
|
-
throw err;
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
157
|
-
0 && (module.exports = {
|
|
158
|
-
REMOTE_INSPECTOR_SCRIPT_URL,
|
|
159
|
-
injectInspector
|
|
160
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Router } from '@remix-run/router';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Route information for the sitemap
|
|
5
|
-
*/
|
|
6
|
-
interface RouteInfo {
|
|
7
|
-
id: string | undefined;
|
|
8
|
-
path: string;
|
|
9
|
-
hasChildren: boolean;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Type definition for the route update message
|
|
13
|
-
*/
|
|
14
|
-
interface ArchieRouteUpdateMessage {
|
|
15
|
-
type: 'ARCHIE_ROUTE_UPDATE';
|
|
16
|
-
payload: {
|
|
17
|
-
path: string;
|
|
18
|
-
search: string;
|
|
19
|
-
hash: string;
|
|
20
|
-
matches: Array<{
|
|
21
|
-
id: string | undefined;
|
|
22
|
-
pathname: string;
|
|
23
|
-
params: Record<string, string | undefined>;
|
|
24
|
-
}>;
|
|
25
|
-
allRoutes: RouteInfo[];
|
|
26
|
-
timestamp: number;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Archie Route Listener Setup
|
|
31
|
-
*
|
|
32
|
-
* Subscribes to the React Router instance to detect route changes
|
|
33
|
-
* and broadcast them to the host editor (iframe parent or popup opener).
|
|
34
|
-
*
|
|
35
|
-
* @param router - The React Router instance (from createBrowserRouter)
|
|
36
|
-
* @returns Unsubscribe function to stop listening
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```typescript
|
|
40
|
-
* import { setupArchieRouteListener } from '@archie/devtools/client';
|
|
41
|
-
* import { router } from './App';
|
|
42
|
-
*
|
|
43
|
-
* const unsubscribe = setupArchieRouteListener(router);
|
|
44
|
-
* // Later: unsubscribe();
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
declare function setupArchieRouteListener(router: Router): () => void;
|
|
48
|
-
|
|
49
|
-
export { type ArchieRouteUpdateMessage, type RouteInfo, setupArchieRouteListener };
|