@abbox/inspector 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,7 @@ function createNextBabelConfig(options = {}) {
10
10
  const enabled =
11
11
  options.enabled ??
12
12
  (process.env.ABBBOX_INSPECTOR === "1" ||
13
+ process.env.ABBBOX_INSPECTION_MODE === "production" ||
13
14
  process.env.NEXT_PUBLIC_ABBOX_INSPECTOR === "1" ||
14
15
  process.env.VERCEL_ENV === "preview");
15
16
 
@@ -1,3 +1,3 @@
1
1
  export { type WithAbboxInspectorOptions, withAbboxInspector, DEFAULT_VIEWER_FRAME_ANCESTORS, } from "./with-abbox-inspector.js";
2
- export { isAbboxInspectorBuildEnabled, isAbboxInspectorRuntimeEnabled, } from "./preview-env.js";
2
+ export { type AbboxInspectionMode, getBakedInspectionMode, getBakedViewerOrigin, isAbboxInspectorBuildEnabled, isAbboxInspectorProductionRuntime, isAbboxInspectorRuntimeEnabled, } from "./preview-env.js";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,yBAAyB,EAC9B,kBAAkB,EAClB,8BAA8B,GAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,GAC/B,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,yBAAyB,EAC9B,kBAAkB,EAClB,8BAA8B,GAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,KAAK,mBAAmB,EACxB,sBAAsB,EACtB,oBAAoB,EACpB,4BAA4B,EAC5B,iCAAiC,EACjC,8BAA8B,GAC/B,MAAM,kBAAkB,CAAC"}
@@ -1,2 +1,2 @@
1
1
  export { withAbboxInspector, DEFAULT_VIEWER_FRAME_ANCESTORS, } from "./with-abbox-inspector.js";
2
- export { isAbboxInspectorBuildEnabled, isAbboxInspectorRuntimeEnabled, } from "./preview-env.js";
2
+ export { getBakedInspectionMode, getBakedViewerOrigin, isAbboxInspectorBuildEnabled, isAbboxInspectorProductionRuntime, isAbboxInspectorRuntimeEnabled, } from "./preview-env.js";
@@ -1,8 +1,15 @@
1
+ export type AbboxInspectionMode = "preview" | "production";
1
2
  /**
2
3
  * When true, Inspector instrumentation, CSP frame-ancestors, and client bootstrap are allowed.
3
- * Production Vercel deploys (VERCEL_ENV=production) stay off unless ABBBOX_INSPECTOR=1 is set explicitly.
4
+ * Preview Vercel deploys stay on by default; production deploys require explicit
5
+ * `ABBBOX_INSPECTION_MODE=production` (set by @abbox/cli production mode).
4
6
  */
5
7
  export declare function isAbboxInspectorBuildEnabled(): boolean;
8
+ /** Baked inspection mode in the client bundle (not query parameters). */
9
+ export declare function getBakedInspectionMode(): AbboxInspectionMode | "off";
6
10
  /** Client-side: Inspector may connect to the Viewer iframe host. */
7
11
  export declare function isAbboxInspectorRuntimeEnabled(): boolean;
12
+ export declare function isAbboxInspectorProductionRuntime(): boolean;
13
+ /** Primary Viewer origin baked at install time (production mode host validation). */
14
+ export declare function getBakedViewerOrigin(): string | undefined;
8
15
  //# sourceMappingURL=preview-env.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"preview-env.d.ts","sourceRoot":"","sources":["../../src/next/preview-env.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,4BAA4B,IAAI,OAAO,CAItD;AAED,oEAAoE;AACpE,wBAAgB,8BAA8B,IAAI,OAAO,CAOxD"}
1
+ {"version":3,"file":"preview-env.d.ts","sourceRoot":"","sources":["../../src/next/preview-env.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,YAAY,CAAC;AAE3D;;;;GAIG;AACH,wBAAgB,4BAA4B,IAAI,OAAO,CAKtD;AAED,yEAAyE;AACzE,wBAAgB,sBAAsB,IAAI,mBAAmB,GAAG,KAAK,CAOpE;AAED,oEAAoE;AACpE,wBAAgB,8BAA8B,IAAI,OAAO,CAExD;AAED,wBAAgB,iCAAiC,IAAI,OAAO,CAE3D;AAED,qFAAqF;AACrF,wBAAgB,oBAAoB,IAAI,MAAM,GAAG,SAAS,CAGzD"}
@@ -1,22 +1,39 @@
1
1
  /**
2
2
  * When true, Inspector instrumentation, CSP frame-ancestors, and client bootstrap are allowed.
3
- * Production Vercel deploys (VERCEL_ENV=production) stay off unless ABBBOX_INSPECTOR=1 is set explicitly.
3
+ * Preview Vercel deploys stay on by default; production deploys require explicit
4
+ * `ABBBOX_INSPECTION_MODE=production` (set by @abbox/cli production mode).
4
5
  */
5
6
  export function isAbboxInspectorBuildEnabled() {
6
7
  if (process.env.ABBBOX_INSPECTOR === "1")
7
8
  return true;
9
+ if (process.env.ABBBOX_INSPECTION_MODE === "production")
10
+ return true;
8
11
  if (process.env.VERCEL_ENV === "preview")
9
12
  return true;
10
13
  return false;
11
14
  }
15
+ /** Baked inspection mode in the client bundle (not query parameters). */
16
+ export function getBakedInspectionMode() {
17
+ const explicit = process.env.NEXT_PUBLIC_ABBOX_INSPECTION_MODE;
18
+ if (explicit === "production")
19
+ return "production";
20
+ if (explicit === "preview")
21
+ return "preview";
22
+ if (process.env.NEXT_PUBLIC_ABBOX_INSPECTOR === "1")
23
+ return "preview";
24
+ if (process.env.NEXT_PUBLIC_VERCEL_ENV === "preview")
25
+ return "preview";
26
+ return "off";
27
+ }
12
28
  /** Client-side: Inspector may connect to the Viewer iframe host. */
13
29
  export function isAbboxInspectorRuntimeEnabled() {
14
- if (process.env.NEXT_PUBLIC_ABBOX_INSPECTOR === "1")
15
- return true;
16
- if (process.env.VERCEL_ENV === "preview")
17
- return true;
18
- if (typeof process.env.NEXT_PUBLIC_VERCEL_ENV === "string") {
19
- return process.env.NEXT_PUBLIC_VERCEL_ENV === "preview";
20
- }
21
- return false;
30
+ return getBakedInspectionMode() !== "off";
31
+ }
32
+ export function isAbboxInspectorProductionRuntime() {
33
+ return getBakedInspectionMode() === "production";
34
+ }
35
+ /** Primary Viewer origin baked at install time (production mode host validation). */
36
+ export function getBakedViewerOrigin() {
37
+ const raw = process.env.NEXT_PUBLIC_ABBOX_VIEWER_ORIGIN;
38
+ return raw?.trim() ? raw.replace(/\/$/, "") : undefined;
22
39
  }
@@ -6,18 +6,23 @@ export type NextConfigLike = {
6
6
  [key: string]: unknown;
7
7
  };
8
8
  export type WithAbboxInspectorOptions = {
9
- /** When false, returns config unchanged (default: ABBBOX_INSPECTOR=1). */
9
+ /** When false, returns config unchanged (default: build gate in preview-env). */
10
10
  enabled?: boolean;
11
11
  /**
12
12
  * Origins allowed to embed this app in an iframe (Abbox Viewer).
13
- * Defaults to common local Viewer ports.
13
+ * Defaults to hosted viewer + common local Viewer ports.
14
14
  */
15
15
  frameAncestors?: string[];
16
+ /**
17
+ * Primary Viewer origin for production-mode postMessage validation.
18
+ * Defaults to the first `frameAncestors` entry.
19
+ */
20
+ viewerOrigin?: string;
16
21
  };
17
22
  export declare const DEFAULT_VIEWER_FRAME_ANCESTORS: string[];
18
23
  /**
19
- * Merge Next.js config for local Abbox Live Preview: iframe embedding headers
20
- * and public env flag for client bootstrap.
24
+ * Merge Next.js config for Abbox inspection: iframe embedding headers
25
+ * and public env flags for client bootstrap.
21
26
  *
22
27
  * JSX instrumentation uses a webpack babel-loader rule (no root babel.config.js),
23
28
  * so `next/font` in app/layout.tsx can keep using SWC.
@@ -1 +1 @@
1
- {"version":3,"file":"with-abbox-inspector.d.ts","sourceRoot":"","sources":["../../src/next/with-abbox-inspector.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACzC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE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MAAM,EAAE,CAAC;IAC1B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAIF,eAAO,MAAM,8BAA8B,UAM1C,CAAC;AAcF;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,MAAM,EAAE,CAAC,EACT,OAAO,GAAE,yBAA8B,GACtC,CAAC,CAiFH"}
@@ -14,9 +14,15 @@ function inspectorEnabled(explicit) {
14
14
  return explicit;
15
15
  return isAbboxInspectorBuildEnabled();
16
16
  }
17
+ function bakedInspectionMode() {
18
+ if (process.env.ABBBOX_INSPECTION_MODE === "production") {
19
+ return "production";
20
+ }
21
+ return "preview";
22
+ }
17
23
  /**
18
- * Merge Next.js config for local Abbox Live Preview: iframe embedding headers
19
- * and public env flag for client bootstrap.
24
+ * Merge Next.js config for Abbox inspection: iframe embedding headers
25
+ * and public env flags for client bootstrap.
20
26
  *
21
27
  * JSX instrumentation uses a webpack babel-loader rule (no root babel.config.js),
22
28
  * so `next/font` in app/layout.tsx can keep using SWC.
@@ -28,7 +34,11 @@ export function withAbboxInspector(config, options = {}) {
28
34
  const base = config;
29
35
  const { applyAbboxWebpackInstrumentation } = require("./webpack-instrumentation.cjs");
30
36
  const ancestors = options.frameAncestors ?? DEFAULT_VIEWER_FRAME_ANCESTORS;
37
+ const viewerOrigin = options.viewerOrigin?.replace(/\/$/, "") ??
38
+ ancestors.find((a) => a.startsWith("https://")) ??
39
+ ancestors[0];
31
40
  const csp = `frame-ancestors 'self' ${ancestors.join(" ")}`;
41
+ const mode = bakedInspectionMode();
32
42
  const headers = async () => {
33
43
  const existing = typeof base.headers === "function"
34
44
  ? await base.headers()
@@ -72,6 +82,8 @@ export function withAbboxInspector(config, options = {}) {
72
82
  env: {
73
83
  ...(base.env ?? {}),
74
84
  NEXT_PUBLIC_ABBOX_INSPECTOR: "1",
85
+ NEXT_PUBLIC_ABBOX_INSPECTION_MODE: mode,
86
+ NEXT_PUBLIC_ABBOX_VIEWER_ORIGIN: viewerOrigin,
75
87
  NEXT_PUBLIC_VERCEL_ENV: process.env.VERCEL_ENV ?? "",
76
88
  },
77
89
  headers,
@@ -3,8 +3,8 @@ export type BootstrapOptions = {
3
3
  allowedHostOrigins?: string[];
4
4
  };
5
5
  /**
6
- * Entry for instrumented preview apps. Activates when `abboxSession` is in the
7
- * URL on authorized preview deployments (Vercel preview or local `dev:abbox`).
6
+ * Entry for instrumented apps. Activates only when the build baked an authorized
7
+ * inspection mode and `abboxSession` is present (not sufficient on its own for security).
8
8
  */
9
9
  export declare function bootstrapInspectorPreview(options?: BootstrapOptions): void;
10
10
  //# sourceMappingURL=bootstrap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/runtime/bootstrap.ts"],"names":[],"mappings":"AAsBA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC/B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,GAAE,gBAAqB,GAC7B,IAAI,CAyBN"}
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/runtime/bootstrap.ts"],"names":[],"mappings":"AAsCA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC/B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,GAAE,gBAAqB,GAC7B,IAAI,CAmCN"}
@@ -1,7 +1,7 @@
1
1
  import { withLocalhostAliases } from "../host/origin-aliases.js";
2
2
  import { createInspectorClient } from "../host/client-bridge.js";
3
- import { isAbboxInspectorRuntimeEnabled } from "../next/preview-env.js";
4
- /** Viewer origins used when `abboxHostOrigin` is missing from the iframe URL. */
3
+ import { getBakedViewerOrigin, isAbboxInspectorProductionRuntime, isAbboxInspectorRuntimeEnabled, } from "../next/preview-env.js";
4
+ /** Viewer origins used when `abboxHostOrigin` is missing (preview mode only). */
5
5
  const DEFAULT_VIEWER_ORIGINS = [
6
6
  "https://viewer.abbox.com",
7
7
  "http://localhost:5173",
@@ -19,9 +19,16 @@ function viewerOriginsFromReferrer() {
19
19
  return [];
20
20
  }
21
21
  }
22
+ function normalizeOrigin(origin) {
23
+ return origin.replace(/\/$/, "");
24
+ }
25
+ function isAllowedHostOrigin(hostOrigin, allowed) {
26
+ const normalized = normalizeOrigin(hostOrigin);
27
+ return allowed.some((o) => normalizeOrigin(o) === normalized);
28
+ }
22
29
  /**
23
- * Entry for instrumented preview apps. Activates when `abboxSession` is in the
24
- * URL on authorized preview deployments (Vercel preview or local `dev:abbox`).
30
+ * Entry for instrumented apps. Activates only when the build baked an authorized
31
+ * inspection mode and `abboxSession` is present (not sufficient on its own for security).
25
32
  */
26
33
  export function bootstrapInspectorPreview(options = {}) {
27
34
  if (typeof window === "undefined")
@@ -32,15 +39,25 @@ export function bootstrapInspectorPreview(options = {}) {
32
39
  const sessionFromUrl = params.get("abboxSession");
33
40
  if (!sessionFromUrl)
34
41
  return;
35
- const sessionId = options.sessionId ?? sessionFromUrl ?? "local-dev";
42
+ const sessionId = options.sessionId ?? sessionFromUrl;
36
43
  const hostParam = params.get("abboxHostOrigin");
37
- const allowedHostOrigins = withLocalhostAliases(options.allowedHostOrigins ??
38
- (hostParam
39
- ? [hostParam]
40
- : [
41
- ...viewerOriginsFromReferrer(),
42
- ...DEFAULT_VIEWER_ORIGINS,
43
- ]));
44
+ let allowedHostOrigins;
45
+ if (isAbboxInspectorProductionRuntime()) {
46
+ if (!hostParam)
47
+ return;
48
+ const bakedViewer = getBakedViewerOrigin();
49
+ const allowed = withLocalhostAliases(options.allowedHostOrigins ??
50
+ (bakedViewer ? [bakedViewer] : DEFAULT_VIEWER_ORIGINS));
51
+ if (!isAllowedHostOrigin(hostParam, allowed))
52
+ return;
53
+ allowedHostOrigins = withLocalhostAliases([hostParam]);
54
+ }
55
+ else {
56
+ allowedHostOrigins = withLocalhostAliases(options.allowedHostOrigins ??
57
+ (hostParam
58
+ ? [hostParam]
59
+ : [...viewerOriginsFromReferrer(), ...DEFAULT_VIEWER_ORIGINS]));
60
+ }
44
61
  const client = createInspectorClient({
45
62
  sessionId,
46
63
  allowedHostOrigins,
package/docs/TRUST.md CHANGED
@@ -1,18 +1,25 @@
1
- # Trust model (Live Preview)
1
+ # Trust model (Live Preview & production inspection)
2
2
 
3
3
  ## What is protected
4
4
 
5
- - **Production deployments** (`VERCEL_ENV=production`): no JSX instrumentation, no `frame-ancestors` for the viewer, client bootstrap does not run (even if `?abboxSession` is present).
6
- - **Preview deployments** (`VERCEL_ENV=preview`): instrumentation and iframe embedding headers are enabled at build time.
5
+ - **Default (preview-only install)**: `VERCEL_ENV=production` deploys have no JSX instrumentation, no `frame-ancestors` for the viewer, and client bootstrap does not run.
6
+ - **Preview deployments** (`VERCEL_ENV=preview`): instrumentation and iframe embedding headers at build time; runtime follows baked preview mode.
7
+ - **Production inspection (explicit opt-in via `@abbox/cli init --mode production`)**: production Vercel builds use webpack instrumentation and bake `NEXT_PUBLIC_ABBOX_INSPECTION_MODE=production`. Runtime still requires a baked mode flag — query parameters alone cannot enable inspection.
8
+ - **Production runtime**: requires `abboxSession` **and** `abboxHostOrigin` matching the Viewer origin configured at install (`NEXT_PUBLIC_ABBOX_VIEWER_ORIGIN`). No broad Viewer fallback list.
7
9
  - **postMessage**: channel, version, session id, and origin allow-lists on host and client. No `targetOrigin: "*"`.
8
- - **Viewer**: preview URL host allow-list (configurable via `VITE_ABBOX_PREVIEW_HOST_ALLOWLIST`).
10
+ - **Viewer**: preview targets use a host allow-list; production website mode accepts customer HTTPS origins (customer must have opted in on their site).
9
11
 
10
12
  ## What is not authentication
11
13
 
12
14
  - `VERCEL_ENV=preview` only means “this build was a Vercel preview deployment.” Anyone with the preview URL can load that deployment.
13
- - `abboxSession` in the query string is a protocol correlation id, not a secret.
14
- - Customers should treat Vercel preview URLs as capability URLs (protect with Vercel access controls if needed).
15
+ - `abboxSession` is a protocol correlation id generated by the Viewer, not proof that the Viewer user owns the embedded site.
16
+ - **Production inspection opt-in** means the site owner deliberately ships instrumentation and `frame-ancestors` allowing the configured Viewer. That is explicit capability exposure, not cryptographic proof of ownership.
17
+ - Abbox does not receive page contents or credentials in this milestone; inspection stays between the Viewer and the customer origin via `postMessage`.
15
18
 
16
19
  ## CSP
17
20
 
18
21
  `withAbboxInspector` adds `Content-Security-Policy: frame-ancestors …` without removing other CSP headers you configure. Remove conflicting `X-Frame-Options: DENY` in your platform if embedding fails.
22
+
23
+ ## Server-side authorization
24
+
25
+ This milestone does **not** include a backend that verifies domain ownership. Customers who need stronger guarantees should treat production inspection as a controlled internal tool or wait for a future domain-verification flow.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abbox/inspector",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -10,6 +10,7 @@ function createNextBabelConfig(options = {}) {
10
10
  const enabled =
11
11
  options.enabled ??
12
12
  (process.env.ABBBOX_INSPECTOR === "1" ||
13
+ process.env.ABBBOX_INSPECTION_MODE === "production" ||
13
14
  process.env.NEXT_PUBLIC_ABBOX_INSPECTOR === "1" ||
14
15
  process.env.VERCEL_ENV === "preview");
15
16