@contember/engine-panel 2.2.0-alpha.17 → 2.2.0-alpha.19
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/development/src/PanelAssets.cjs +2 -2
- package/dist/development/src/PanelAssets.cjs.map +1 -1
- package/dist/development/src/PanelController.cjs +3 -3
- package/dist/development/src/PanelController.cjs.map +1 -1
- package/dist/development/src/PanelMount.cjs +2 -2
- package/dist/development/src/PanelMount.cjs.map +1 -1
- package/dist/development/src/PanelMount.js +2 -2
- package/dist/development/src/PanelMount.js.map +1 -1
- package/dist/development/src/PanelPlugin.cjs +3 -1
- package/dist/development/src/PanelPlugin.cjs.map +1 -1
- package/dist/development/src/PanelPlugin.js +3 -1
- package/dist/development/src/PanelPlugin.js.map +1 -1
- package/dist/development/src/generated/assets.cjs +38 -38
- package/dist/development/src/generated/assets.cjs.map +1 -1
- package/dist/development/src/generated/assets.js +38 -38
- package/dist/development/src/generated/assets.js.map +1 -1
- package/dist/production/src/PanelAssets.cjs +2 -2
- package/dist/production/src/PanelAssets.cjs.map +1 -1
- package/dist/production/src/PanelController.cjs +3 -3
- package/dist/production/src/PanelController.cjs.map +1 -1
- package/dist/production/src/PanelMount.cjs +2 -2
- package/dist/production/src/PanelMount.cjs.map +1 -1
- package/dist/production/src/PanelMount.js +2 -2
- package/dist/production/src/PanelMount.js.map +1 -1
- package/dist/production/src/PanelPlugin.cjs +3 -1
- package/dist/production/src/PanelPlugin.cjs.map +1 -1
- package/dist/production/src/PanelPlugin.js +3 -1
- package/dist/production/src/PanelPlugin.js.map +1 -1
- package/dist/production/src/generated/assets.cjs +38 -38
- package/dist/production/src/generated/assets.cjs.map +1 -1
- package/dist/production/src/generated/assets.js +38 -38
- package/dist/production/src/generated/assets.js.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/PanelMount.d.ts +1 -1
- package/dist/types/PanelMount.d.ts.map +1 -1
- package/dist/types/PanelPlugin.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/PanelMount.ts +2 -2
- package/src/PanelPlugin.ts +3 -1
- package/tests/cases/unit/panelMount.test.ts +13 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
3
|
+
const zlib = require("node:zlib");
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
6
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
@@ -39,7 +39,7 @@ class PanelAssetStore {
|
|
|
39
39
|
}
|
|
40
40
|
let identity = this.identity.get(path);
|
|
41
41
|
if (!identity) {
|
|
42
|
-
identity =
|
|
42
|
+
identity = zlib.gunzipSync(gzip);
|
|
43
43
|
this.identity.set(path, identity);
|
|
44
44
|
}
|
|
45
45
|
return identity;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PanelAssets.cjs","sources":["../../../../packages/engine-panel/src/PanelAssets.ts"],"sourcesContent":["import { gunzipSync } from 'node:zlib'\n\n/**\n * A single file of the built panel UI. Every entry is stored gzip-compressed and base64-encoded so\n * the whole panel can be bundled into `dist/start.js` — the engine docker image contains nothing but\n * that one file, so there is no directory to serve from.\n */\nexport interface PanelAsset {\n\treadonly contentType: string\n\t/** gzip-compressed content, base64-encoded. */\n\treadonly gzip: string\n}\n\n/** Keys are paths relative to the panel root, without a leading slash (`assets/index-a1b2.js`). */\nexport type PanelAssetMap = Readonly<Record<string, PanelAsset>>\n\nexport const indexAssetPath = 'index.html'\n\nexport class PanelAssetStore {\n\tprivate readonly gzip = new Map<string, Buffer>()\n\tprivate readonly identity = new Map<string, Buffer>()\n\n\tconstructor(private readonly assets: PanelAssetMap) {}\n\n\t/** True when the panel was not built into this binary — see `scripts/buildAssets.ts`. */\n\tpublic isEmpty(): boolean {\n\t\treturn this.get(indexAssetPath) === undefined\n\t}\n\n\tpublic getContentType(path: string): string | undefined {\n\t\treturn this.get(path)?.contentType\n\t}\n\n\t/** Gzipped bytes, decoded from base64 on first use and kept for the process lifetime. */\n\tpublic getGzip(path: string): Buffer | undefined {\n\t\tconst asset = this.get(path)\n\t\tif (!asset) {\n\t\t\treturn undefined\n\t\t}\n\t\tlet decoded = this.gzip.get(path)\n\t\tif (!decoded) {\n\t\t\tdecoded = Buffer.from(asset.gzip, 'base64')\n\t\t\tthis.gzip.set(path, decoded)\n\t\t}\n\t\treturn decoded\n\t}\n\n\t/** Uncompressed bytes, decoded once for clients that do not accept gzip. */\n\tpublic getIdentity(path: string): Buffer | undefined {\n\t\tconst gzip = this.getGzip(path)\n\t\tif (gzip === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tlet identity = this.identity.get(path)\n\t\tif (!identity) {\n\t\t\tidentity = gunzipSync(gzip)\n\t\t\tthis.identity.set(path, identity)\n\t\t}\n\t\treturn identity\n\t}\n\n\t/**\n\t * The map is a plain object literal, so a request for `constructor` or `toString` would otherwise\n\t * resolve an inherited member and blow up further down. The route is unauthenticated.\n\t */\n\tprivate get(path: string): PanelAsset | undefined {\n\t\treturn Object.hasOwn(this.assets, path) ? this.assets[path] : undefined\n\t}\n}\n"],"names":["gunzipSync"],"mappings":";;;;;;AAgBO,MAAM,iBAAiB;AAEvB,MAAM,gBAAgB;AAAA,EAI5B,YAA6B,QAAuB;AAAvB,SAAA,SAAA;AAH7B,kBAAA,MAAiB,4BAAW,IAAA,CAAoB;AAChD,kBAAA,MAAiB,gCAAe,IAAA,CAAoB;AAAA,EAEC;AAAA;AAAA,EAG9C,UAAmB;AACzB,WAAO,KAAK,IAAI,cAAc,MAAM;AAAA,EACrC;AAAA,EAEO,eAAe,MAAkC;AACvD,WAAO,KAAK,IAAI,IAAI,GAAG;AAAA,EACxB;AAAA;AAAA,EAGO,QAAQ,MAAkC;AAChD,UAAM,QAAQ,KAAK,IAAI,IAAI;AAC3B,QAAI,CAAC,OAAO;AACX,aAAO;AAAA,IACR;AACA,QAAI,UAAU,KAAK,KAAK,IAAI,IAAI;AAChC,QAAI,CAAC,SAAS;AACb,gBAAU,OAAO,KAAK,MAAM,MAAM,QAAQ;AAC1C,WAAK,KAAK,IAAI,MAAM,OAAO;AAAA,IAC5B;AACA,WAAO;AAAA,EACR;AAAA;AAAA,EAGO,YAAY,MAAkC;AACpD,UAAM,OAAO,KAAK,QAAQ,IAAI;AAC9B,QAAI,SAAS,QAAW;AACvB,aAAO;AAAA,IACR;AACA,QAAI,WAAW,KAAK,SAAS,IAAI,IAAI;AACrC,QAAI,CAAC,UAAU;AACd,iBAAWA,
|
|
1
|
+
{"version":3,"file":"PanelAssets.cjs","sources":["../../../../packages/engine-panel/src/PanelAssets.ts"],"sourcesContent":["import { gunzipSync } from 'node:zlib'\n\n/**\n * A single file of the built panel UI. Every entry is stored gzip-compressed and base64-encoded so\n * the whole panel can be bundled into `dist/start.js` — the engine docker image contains nothing but\n * that one file, so there is no directory to serve from.\n */\nexport interface PanelAsset {\n\treadonly contentType: string\n\t/** gzip-compressed content, base64-encoded. */\n\treadonly gzip: string\n}\n\n/** Keys are paths relative to the panel root, without a leading slash (`assets/index-a1b2.js`). */\nexport type PanelAssetMap = Readonly<Record<string, PanelAsset>>\n\nexport const indexAssetPath = 'index.html'\n\nexport class PanelAssetStore {\n\tprivate readonly gzip = new Map<string, Buffer>()\n\tprivate readonly identity = new Map<string, Buffer>()\n\n\tconstructor(private readonly assets: PanelAssetMap) {}\n\n\t/** True when the panel was not built into this binary — see `scripts/buildAssets.ts`. */\n\tpublic isEmpty(): boolean {\n\t\treturn this.get(indexAssetPath) === undefined\n\t}\n\n\tpublic getContentType(path: string): string | undefined {\n\t\treturn this.get(path)?.contentType\n\t}\n\n\t/** Gzipped bytes, decoded from base64 on first use and kept for the process lifetime. */\n\tpublic getGzip(path: string): Buffer | undefined {\n\t\tconst asset = this.get(path)\n\t\tif (!asset) {\n\t\t\treturn undefined\n\t\t}\n\t\tlet decoded = this.gzip.get(path)\n\t\tif (!decoded) {\n\t\t\tdecoded = Buffer.from(asset.gzip, 'base64')\n\t\t\tthis.gzip.set(path, decoded)\n\t\t}\n\t\treturn decoded\n\t}\n\n\t/** Uncompressed bytes, decoded once for clients that do not accept gzip. */\n\tpublic getIdentity(path: string): Buffer | undefined {\n\t\tconst gzip = this.getGzip(path)\n\t\tif (gzip === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tlet identity = this.identity.get(path)\n\t\tif (!identity) {\n\t\t\tidentity = gunzipSync(gzip)\n\t\t\tthis.identity.set(path, identity)\n\t\t}\n\t\treturn identity\n\t}\n\n\t/**\n\t * The map is a plain object literal, so a request for `constructor` or `toString` would otherwise\n\t * resolve an inherited member and blow up further down. The route is unauthenticated.\n\t */\n\tprivate get(path: string): PanelAsset | undefined {\n\t\treturn Object.hasOwn(this.assets, path) ? this.assets[path] : undefined\n\t}\n}\n"],"names":["gunzipSync"],"mappings":";;;;;;AAgBO,MAAM,iBAAiB;AAEvB,MAAM,gBAAgB;AAAA,EAI5B,YAA6B,QAAuB;AAAvB,SAAA,SAAA;AAH7B,kBAAA,MAAiB,4BAAW,IAAA,CAAoB;AAChD,kBAAA,MAAiB,gCAAe,IAAA,CAAoB;AAAA,EAEC;AAAA;AAAA,EAG9C,UAAmB;AACzB,WAAO,KAAK,IAAI,cAAc,MAAM;AAAA,EACrC;AAAA,EAEO,eAAe,MAAkC;AACvD,WAAO,KAAK,IAAI,IAAI,GAAG;AAAA,EACxB;AAAA;AAAA,EAGO,QAAQ,MAAkC;AAChD,UAAM,QAAQ,KAAK,IAAI,IAAI;AAC3B,QAAI,CAAC,OAAO;AACX,aAAO;AAAA,IACR;AACA,QAAI,UAAU,KAAK,KAAK,IAAI,IAAI;AAChC,QAAI,CAAC,SAAS;AACb,gBAAU,OAAO,KAAK,MAAM,MAAM,QAAQ;AAC1C,WAAK,KAAK,IAAI,MAAM,OAAO;AAAA,IAC5B;AACA,WAAO;AAAA,EACR;AAAA;AAAA,EAGO,YAAY,MAAkC;AACpD,UAAM,OAAO,KAAK,QAAQ,IAAI;AAC9B,QAAI,SAAS,QAAW;AACvB,aAAO;AAAA,IACR;AACA,QAAI,WAAW,KAAK,SAAS,IAAI,IAAI;AACrC,QAAI,CAAC,UAAU;AACd,iBAAWA,KAAAA,WAAW,IAAI;AAC1B,WAAK,SAAS,IAAI,MAAM,QAAQ;AAAA,IACjC;AACA,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,IAAI,MAAsC;AACjD,WAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,IAAI,KAAK,OAAO,IAAI,IAAI;AAAA,EAC/D;AACD;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
3
|
+
const zlib = require("node:zlib");
|
|
4
4
|
const PanelAssets = require("./PanelAssets.cjs");
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
6
6
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -82,9 +82,9 @@ class PanelController {
|
|
|
82
82
|
pluginApis: this.args.pluginApis()
|
|
83
83
|
});
|
|
84
84
|
const identity = Buffer.from(
|
|
85
|
-
|
|
85
|
+
zlib.gunzipSync(this.indexSource).toString("utf8").replaceAll(basePlaceholder, () => `${this.args.basePath}/`).replaceAll(configPlaceholder, () => config)
|
|
86
86
|
);
|
|
87
|
-
return { gzip:
|
|
87
|
+
return { gzip: zlib.gzipSync(identity), identity };
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
const headerValue = (header) => Array.isArray(header) ? header.join(",") : header;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PanelController.cjs","sources":["../../../../packages/engine-panel/src/PanelController.ts"],"sourcesContent":["import { gunzipSync, gzipSync } from 'node:zlib'\nimport type { InternalHttpContext, InternalHttpController } from '@contember/engine-http'\nimport { indexAssetPath, PanelAssetStore } from './PanelAssets.js'\n\nexport interface PanelControllerArgs {\n\t/** Mount path without a trailing slash, e.g. `/panel`. */\n\tbasePath: string\n\t/** Prefix the panel prepends to every API path, e.g. `/panel/api`. */\n\tapiBaseUrl: string\n\tassets: PanelAssetStore\n\t/** Plugin APIs mounted under {@link apiBaseUrl}; read on the first request, see {@link PanelController.indexHtml}. */\n\tpluginApis: () => readonly string[]\n}\n\n/** Everything the controller reads from a request — see {@link PanelController.handle}. */\nexport interface PanelRequest {\n\tmethod: string\n\t/** Path relative to the panel root, i.e. the route's wildcard parameter. */\n\tpath: string | undefined\n\tacceptEncoding: string | undefined\n}\n\nexport interface PanelResponse {\n\tstatus: number\n\theaders: Readonly<Record<string, string>>\n\tbody: Buffer\n}\n\nconst basePlaceholder = '__CONTEMBER_PANEL_BASE__'\nconst configPlaceholder = '__CONTEMBER_PANEL_CONFIG__'\n\n/**\n * `style-src` allows inline styles because the component libraries set `style` attributes; nothing\n * else is relaxed, and no external origin is reachable at all.\n */\nconst contentSecurityPolicy = [\n\t`default-src 'self'`,\n\t`script-src 'self'`,\n\t`style-src 'self' 'unsafe-inline'`,\n\t`img-src 'self' data:`,\n\t`font-src 'self' data:`,\n\t`connect-src 'self'`,\n\t`base-uri 'self'`,\n\t`form-action 'self'`,\n\t`frame-ancestors 'none'`,\n].join('; ')\n\n/**\n * Serves the built panel UI out of the bundled asset map.\n *\n * Registered as an *internal* route: static assets must not authenticate, and going through the\n * regular pipeline would resolve a project group and verify an API key against the database on every\n * file request. The panel's API traffic is a separate, regular route.\n */\nexport class PanelController {\n\t/**\n\t * Rendered on the first request rather than here: the plugins that mount their API into the panel\n\t * are not all registered yet while the container is still being built, and the shell carries the\n\t * list. Built once and kept, since nothing in it can change afterwards.\n\t */\n\tprivate indexHtml: { gzip: Buffer; identity: Buffer } | undefined\n\tprivate readonly indexSource: Buffer\n\n\tconstructor(private readonly args: PanelControllerArgs) {\n\t\tconst source = args.assets.getGzip(indexAssetPath)\n\t\tif (source === undefined) {\n\t\t\tthrow new Error('The panel UI was not built into this binary. Run `bun run pre-build` before building the server.')\n\t\t}\n\t\tthis.indexSource = source\n\t}\n\n\tpublic create(): InternalHttpController {\n\t\treturn (ctx: InternalHttpContext) => {\n\t\t\tconst response = this.handle({\n\t\t\t\tmethod: ctx.koa.method,\n\t\t\t\tpath: typeof ctx.params.path === 'string' ? ctx.params.path : undefined,\n\t\t\t\tacceptEncoding: headerValue(ctx.request.headers['accept-encoding']),\n\t\t\t})\n\t\t\tctx.koa.status = response.status\n\t\t\tfor (const [name, value] of Object.entries(response.headers)) {\n\t\t\t\tctx.koa.set(name, value)\n\t\t\t}\n\t\t\tctx.koa.body = response.body\n\t\t}\n\t}\n\n\tpublic handle(request: PanelRequest): PanelResponse {\n\t\tif (request.method !== 'GET' && request.method !== 'HEAD') {\n\t\t\treturn { status: 405, headers: { 'Allow': 'GET, HEAD' }, body: Buffer.alloc(0) }\n\t\t}\n\n\t\tconst path = normalizePath(request.path)\n\t\tconst gzip = path === undefined || path === indexAssetPath ? undefined : this.args.assets.getGzip(path)\n\n\t\tif (path === undefined || gzip === undefined) {\n\t\t\t// Anything that is not a built file is a client-side route — serve the app shell.\n\t\t\tthis.indexHtml ??= this.renderIndex()\n\t\t\treturn this.respond(request, this.indexHtml.gzip, () => this.indexHtml?.identity, {\n\t\t\t\t'Content-Type': 'text/html; charset=utf-8',\n\t\t\t\t'Cache-Control': 'no-store',\n\t\t\t\t'Content-Security-Policy': contentSecurityPolicy,\n\t\t\t\t'X-Robots-Tag': 'noindex, nofollow',\n\t\t\t\t'Referrer-Policy': 'no-referrer',\n\t\t\t})\n\t\t}\n\t\t// Every built file name carries a content hash, so it can never change under the same URL.\n\t\treturn this.respond(request, gzip, () => this.args.assets.getIdentity(path), {\n\t\t\t'Content-Type': this.args.assets.getContentType(path) ?? 'application/octet-stream',\n\t\t\t'Cache-Control': 'public, max-age=31536000, immutable',\n\t\t})\n\t}\n\n\tprivate respond(request: PanelRequest, gzipped: Buffer, identity: () => Buffer | undefined, headers: Record<string, string>): PanelResponse {\n\t\tconst common = {\n\t\t\t...headers,\n\t\t\t'Vary': 'Accept-Encoding',\n\t\t\t'X-Content-Type-Options': 'nosniff',\n\t\t}\n\t\tif (acceptsGzip(request.acceptEncoding)) {\n\t\t\treturn { status: 200, headers: { ...common, 'Content-Encoding': 'gzip' }, body: request.method === 'HEAD' ? Buffer.alloc(0) : gzipped }\n\t\t}\n\t\treturn { status: 200, headers: common, body: request.method === 'HEAD' ? Buffer.alloc(0) : identity() ?? Buffer.alloc(0) }\n\t}\n\n\tprivate renderIndex(): { gzip: Buffer; identity: Buffer } {\n\t\tconst config = JSON.stringify({\n\t\t\tbasePath: `${this.args.basePath}/`,\n\t\t\tapiBaseUrl: this.args.apiBaseUrl,\n\t\t\tpluginApis: this.args.pluginApis(),\n\t\t})\n\t\tconst identity = Buffer.from(\n\t\t\tgunzipSync(this.indexSource)\n\t\t\t\t.toString('utf8')\n\t\t\t\t// An absolute base href keeps the relative asset URLs resolving from the panel root at any\n\t\t\t\t// route depth, which is what lets the mount path stay configurable.\n\t\t\t\t.replaceAll(basePlaceholder, () => `${this.args.basePath}/`)\n\t\t\t\t.replaceAll(configPlaceholder, () => config),\n\t\t)\n\t\treturn { gzip: gzipSync(identity), identity }\n\t}\n}\n\nconst headerValue = (header: string | string[] | undefined): string | undefined => Array.isArray(header) ? header.join(',') : header\n\nconst acceptsGzip = (acceptEncoding: string | undefined): boolean =>\n\tacceptEncoding !== undefined && /(^|,)\\s*(gzip|\\*)\\s*(;|,|$)/.test(acceptEncoding)\n\n/**\n * `undefined` for the panel root, `undefined` for anything that tries to escape the asset map;\n * both fall through to the app shell.\n */\nconst normalizePath = (raw: string | undefined): string | undefined => {\n\tif (raw === undefined || raw === '') {\n\t\treturn undefined\n\t}\n\tlet decoded: string\n\ttry {\n\t\tdecoded = decodeURIComponent(raw)\n\t} catch {\n\t\treturn undefined\n\t}\n\tif (decoded.includes('\\0') || decoded.split('/').includes('..')) {\n\t\treturn undefined\n\t}\n\treturn decoded\n}\n"],"names":["indexAssetPath","gunzipSync","gzipSync"],"mappings":";;;;;;;AA4BA,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;AAM1B,MAAM,wBAAwB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,EAAE,KAAK,IAAI;AASJ,MAAM,gBAAgB;AAAA,EAS5B,YAA6B,MAA2B;AAA3B,SAAA,OAAA;AAH7B,kBAAA,MAAQ,WAAA;AACR,kBAAA,MAAiB,aAAA;AAGhB,UAAM,SAAS,KAAK,OAAO,QAAQA,YAAAA,cAAc;AACjD,QAAI,WAAW,QAAW;AACzB,YAAM,IAAI,MAAM,kGAAkG;AAAA,IACnH;AACA,SAAK,cAAc;AAAA,EACpB;AAAA,EAEO,SAAiC;AACvC,WAAO,CAAC,QAA6B;AACpC,YAAM,WAAW,KAAK,OAAO;AAAA,QAC5B,QAAQ,IAAI,IAAI;AAAA,QAChB,MAAM,OAAO,IAAI,OAAO,SAAS,WAAW,IAAI,OAAO,OAAO;AAAA,QAC9D,gBAAgB,YAAY,IAAI,QAAQ,QAAQ,iBAAiB,CAAC;AAAA,MAAA,CAClE;AACD,UAAI,IAAI,SAAS,SAAS;AAC1B,iBAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,SAAS,OAAO,GAAG;AAC7D,YAAI,IAAI,IAAI,MAAM,KAAK;AAAA,MACxB;AACA,UAAI,IAAI,OAAO,SAAS;AAAA,IACzB;AAAA,EACD;AAAA,EAEO,OAAO,SAAsC;AACnD,QAAI,QAAQ,WAAW,SAAS,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AU;AAAA,MAC7B,UAAU,GAAG,KAAK,KAAK,QAAQ;AAAA,MAC/B,YAAY,KAAK,KAAK;AAAA,MACtB,YAAY,KAAK,KAAK,WAAA;AAAA,IAAW,CACjC;AACD,UAAM,WAAW,OAAO;AAAA,MACvBC,
|
|
1
|
+
{"version":3,"file":"PanelController.cjs","sources":["../../../../packages/engine-panel/src/PanelController.ts"],"sourcesContent":["import { gunzipSync, gzipSync } from 'node:zlib'\nimport type { InternalHttpContext, InternalHttpController } from '@contember/engine-http'\nimport { indexAssetPath, PanelAssetStore } from './PanelAssets.js'\n\nexport interface PanelControllerArgs {\n\t/** Mount path without a trailing slash, e.g. `/panel`. */\n\tbasePath: string\n\t/** Prefix the panel prepends to every API path, e.g. `/panel/api`. */\n\tapiBaseUrl: string\n\tassets: PanelAssetStore\n\t/** Plugin APIs mounted under {@link apiBaseUrl}; read on the first request, see {@link PanelController.indexHtml}. */\n\tpluginApis: () => readonly string[]\n}\n\n/** Everything the controller reads from a request — see {@link PanelController.handle}. */\nexport interface PanelRequest {\n\tmethod: string\n\t/** Path relative to the panel root, i.e. the route's wildcard parameter. */\n\tpath: string | undefined\n\tacceptEncoding: string | undefined\n}\n\nexport interface PanelResponse {\n\tstatus: number\n\theaders: Readonly<Record<string, string>>\n\tbody: Buffer\n}\n\nconst basePlaceholder = '__CONTEMBER_PANEL_BASE__'\nconst configPlaceholder = '__CONTEMBER_PANEL_CONFIG__'\n\n/**\n * `style-src` allows inline styles because the component libraries set `style` attributes; nothing\n * else is relaxed, and no external origin is reachable at all.\n */\nconst contentSecurityPolicy = [\n\t`default-src 'self'`,\n\t`script-src 'self'`,\n\t`style-src 'self' 'unsafe-inline'`,\n\t`img-src 'self' data:`,\n\t`font-src 'self' data:`,\n\t`connect-src 'self'`,\n\t`base-uri 'self'`,\n\t`form-action 'self'`,\n\t`frame-ancestors 'none'`,\n].join('; ')\n\n/**\n * Serves the built panel UI out of the bundled asset map.\n *\n * Registered as an *internal* route: static assets must not authenticate, and going through the\n * regular pipeline would resolve a project group and verify an API key against the database on every\n * file request. The panel's API traffic is a separate, regular route.\n */\nexport class PanelController {\n\t/**\n\t * Rendered on the first request rather than here: the plugins that mount their API into the panel\n\t * are not all registered yet while the container is still being built, and the shell carries the\n\t * list. Built once and kept, since nothing in it can change afterwards.\n\t */\n\tprivate indexHtml: { gzip: Buffer; identity: Buffer } | undefined\n\tprivate readonly indexSource: Buffer\n\n\tconstructor(private readonly args: PanelControllerArgs) {\n\t\tconst source = args.assets.getGzip(indexAssetPath)\n\t\tif (source === undefined) {\n\t\t\tthrow new Error('The panel UI was not built into this binary. Run `bun run pre-build` before building the server.')\n\t\t}\n\t\tthis.indexSource = source\n\t}\n\n\tpublic create(): InternalHttpController {\n\t\treturn (ctx: InternalHttpContext) => {\n\t\t\tconst response = this.handle({\n\t\t\t\tmethod: ctx.koa.method,\n\t\t\t\tpath: typeof ctx.params.path === 'string' ? ctx.params.path : undefined,\n\t\t\t\tacceptEncoding: headerValue(ctx.request.headers['accept-encoding']),\n\t\t\t})\n\t\t\tctx.koa.status = response.status\n\t\t\tfor (const [name, value] of Object.entries(response.headers)) {\n\t\t\t\tctx.koa.set(name, value)\n\t\t\t}\n\t\t\tctx.koa.body = response.body\n\t\t}\n\t}\n\n\tpublic handle(request: PanelRequest): PanelResponse {\n\t\tif (request.method !== 'GET' && request.method !== 'HEAD') {\n\t\t\treturn { status: 405, headers: { 'Allow': 'GET, HEAD' }, body: Buffer.alloc(0) }\n\t\t}\n\n\t\tconst path = normalizePath(request.path)\n\t\tconst gzip = path === undefined || path === indexAssetPath ? undefined : this.args.assets.getGzip(path)\n\n\t\tif (path === undefined || gzip === undefined) {\n\t\t\t// Anything that is not a built file is a client-side route — serve the app shell.\n\t\t\tthis.indexHtml ??= this.renderIndex()\n\t\t\treturn this.respond(request, this.indexHtml.gzip, () => this.indexHtml?.identity, {\n\t\t\t\t'Content-Type': 'text/html; charset=utf-8',\n\t\t\t\t'Cache-Control': 'no-store',\n\t\t\t\t'Content-Security-Policy': contentSecurityPolicy,\n\t\t\t\t'X-Robots-Tag': 'noindex, nofollow',\n\t\t\t\t'Referrer-Policy': 'no-referrer',\n\t\t\t})\n\t\t}\n\t\t// Every built file name carries a content hash, so it can never change under the same URL.\n\t\treturn this.respond(request, gzip, () => this.args.assets.getIdentity(path), {\n\t\t\t'Content-Type': this.args.assets.getContentType(path) ?? 'application/octet-stream',\n\t\t\t'Cache-Control': 'public, max-age=31536000, immutable',\n\t\t})\n\t}\n\n\tprivate respond(request: PanelRequest, gzipped: Buffer, identity: () => Buffer | undefined, headers: Record<string, string>): PanelResponse {\n\t\tconst common = {\n\t\t\t...headers,\n\t\t\t'Vary': 'Accept-Encoding',\n\t\t\t'X-Content-Type-Options': 'nosniff',\n\t\t}\n\t\tif (acceptsGzip(request.acceptEncoding)) {\n\t\t\treturn { status: 200, headers: { ...common, 'Content-Encoding': 'gzip' }, body: request.method === 'HEAD' ? Buffer.alloc(0) : gzipped }\n\t\t}\n\t\treturn { status: 200, headers: common, body: request.method === 'HEAD' ? Buffer.alloc(0) : identity() ?? Buffer.alloc(0) }\n\t}\n\n\tprivate renderIndex(): { gzip: Buffer; identity: Buffer } {\n\t\tconst config = JSON.stringify({\n\t\t\tbasePath: `${this.args.basePath}/`,\n\t\t\tapiBaseUrl: this.args.apiBaseUrl,\n\t\t\tpluginApis: this.args.pluginApis(),\n\t\t})\n\t\tconst identity = Buffer.from(\n\t\t\tgunzipSync(this.indexSource)\n\t\t\t\t.toString('utf8')\n\t\t\t\t// An absolute base href keeps the relative asset URLs resolving from the panel root at any\n\t\t\t\t// route depth, which is what lets the mount path stay configurable.\n\t\t\t\t.replaceAll(basePlaceholder, () => `${this.args.basePath}/`)\n\t\t\t\t.replaceAll(configPlaceholder, () => config),\n\t\t)\n\t\treturn { gzip: gzipSync(identity), identity }\n\t}\n}\n\nconst headerValue = (header: string | string[] | undefined): string | undefined => Array.isArray(header) ? header.join(',') : header\n\nconst acceptsGzip = (acceptEncoding: string | undefined): boolean =>\n\tacceptEncoding !== undefined && /(^|,)\\s*(gzip|\\*)\\s*(;|,|$)/.test(acceptEncoding)\n\n/**\n * `undefined` for the panel root, `undefined` for anything that tries to escape the asset map;\n * both fall through to the app shell.\n */\nconst normalizePath = (raw: string | undefined): string | undefined => {\n\tif (raw === undefined || raw === '') {\n\t\treturn undefined\n\t}\n\tlet decoded: string\n\ttry {\n\t\tdecoded = decodeURIComponent(raw)\n\t} catch {\n\t\treturn undefined\n\t}\n\tif (decoded.includes('\\0') || decoded.split('/').includes('..')) {\n\t\treturn undefined\n\t}\n\treturn decoded\n}\n"],"names":["indexAssetPath","gunzipSync","gzipSync"],"mappings":";;;;;;;AA4BA,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;AAM1B,MAAM,wBAAwB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,EAAE,KAAK,IAAI;AASJ,MAAM,gBAAgB;AAAA,EAS5B,YAA6B,MAA2B;AAA3B,SAAA,OAAA;AAH7B,kBAAA,MAAQ,WAAA;AACR,kBAAA,MAAiB,aAAA;AAGhB,UAAM,SAAS,KAAK,OAAO,QAAQA,YAAAA,cAAc;AACjD,QAAI,WAAW,QAAW;AACzB,YAAM,IAAI,MAAM,kGAAkG;AAAA,IACnH;AACA,SAAK,cAAc;AAAA,EACpB;AAAA,EAEO,SAAiC;AACvC,WAAO,CAAC,QAA6B;AACpC,YAAM,WAAW,KAAK,OAAO;AAAA,QAC5B,QAAQ,IAAI,IAAI;AAAA,QAChB,MAAM,OAAO,IAAI,OAAO,SAAS,WAAW,IAAI,OAAO,OAAO;AAAA,QAC9D,gBAAgB,YAAY,IAAI,QAAQ,QAAQ,iBAAiB,CAAC;AAAA,MAAA,CAClE;AACD,UAAI,IAAI,SAAS,SAAS;AAC1B,iBAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,SAAS,OAAO,G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AAK,SAAS,QAAQ,MAAM,QAAQ,WAAW,SAAS,OAAO,MAAM,CAAC,IAAI,SAAA,KAAc,OAAO,MAAM,CAAC,EAAA;AAAA,EACxH;AAAA,EAEQ,cAAkD;AACzD,UAAM,SAAS,KAAK,UAAU;AAAA,MAC7B,UAAU,GAAG,KAAK,KAAK,QAAQ;AAAA,MAC/B,YAAY,KAAK,KAAK;AAAA,MACtB,YAAY,KAAK,KAAK,WAAA;AAAA,IAAW,CACjC;AACD,UAAM,WAAW,OAAO;AAAA,MACvBC,KAAAA,WAAW,KAAK,WAAW,EACzB,SAAS,MAAM,EAGf,WAAW,iBAAiB,MAAM,GAAG,KAAK,KAAK,QAAQ,GAAG,EAC1D,WAAW,mBAAmB,MAAM,MAAM;AAAA,IAAA;AAE7C,WAAO,EAAE,MAAMC,KAAAA,SAAS,QAAQ,GAAG,SAAA;AAAA,EACpC;AACD;AAEA,MAAM,cAAc,CAAC,WAA8D,MAAM,QAAQ,MAAM,IAAI,OAAO,KAAK,GAAG,IAAI;AAE9H,MAAM,cAAc,CAAC,mBACpB,mBAAmB,UAAa,8BAA8B,KAAK,cAAc;AAMlF,MAAM,gBAAgB,CAAC,QAAgD;AACtE,MAAI,QAAQ,UAAa,QAAQ,IAAI;AACpC,WAAO;AAAA,EACR;AACA,MAAI;AACJ,MAAI;AACH,cAAU,mBAAmB,GAAG;AAAA,EACjC,QAAQ;AACP,WAAO;AAAA,EACR;AACA,MAAI,QAAQ,SAAS,IAAI,KAAK,QAAQ,MAAM,GAAG,EAAE,SAAS,IAAI,GAAG;AAChE,WAAO;AAAA,EACR;AACA,SAAO;AACR;;"}
|
|
@@ -10,8 +10,8 @@ class PanelMount {
|
|
|
10
10
|
this.api = api;
|
|
11
11
|
__publicField(this, "pluginApiNames", /* @__PURE__ */ new Set());
|
|
12
12
|
}
|
|
13
|
-
mount(application, { name, path, controller }) {
|
|
14
|
-
application.addRoute("panel-api", `${this.basePath}/api/${path}`, this.api.create(controller, { allowAnonymous: false }));
|
|
13
|
+
mount(application, { name, path, controller, carriesCredentials }) {
|
|
14
|
+
application.addRoute("panel-api", `${this.basePath}/api/${path}`, this.api.create(controller, { allowAnonymous: false }), { carriesCredentials });
|
|
15
15
|
this.pluginApiNames.add(name);
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PanelMount.cjs","sources":["../../../../packages/engine-panel/src/PanelMount.ts"],"sourcesContent":["import type { PanelApiMount, PanelApiMountArgs, PanelApiMountTarget } from '@contember/engine-http'\nimport type { PanelApiControllerFactory } from './PanelApiController.js'\nimport type { PanelAssetStore } from './PanelAssets.js'\n\n/**\n * Everything needed to serve the panel, resolved once. It exists only when the panel really is\n * served — enabled *and* built into this binary — so a plugin can read \"this resolved\" as \"there is\n * a panel to mount into\" and skip its panel route otherwise.\n */\nexport class PanelMount implements PanelApiMount {\n\tprivate readonly pluginApiNames = new Set<string>()\n\n\tconstructor(\n\t\tpublic readonly basePath: string,\n\t\tpublic readonly assets: PanelAssetStore,\n\t\t/** Shared with the panel's own routes: one factory means one access-check cache for all of them. */\n\t\tpublic readonly api: PanelApiControllerFactory,\n\t) {\n\t}\n\n\tpublic mount(application: PanelApiMountTarget, { name, path, controller }: PanelApiMountArgs): void {\n\t\tapplication.addRoute('panel-api', `${this.basePath}/api/${path}`, this.api.create(controller, { allowAnonymous: false }))\n\t\tthis.pluginApiNames.add(name)\n\t}\n\n\t/**\n\t * APIs plugins have mounted, reported to the UI so a module can hide itself when the plugin that\n\t * backs it is not installed. Read when the shell is rendered, not when it is constructed, so a\n\t * plugin registering after the panel is still counted.\n\t */\n\tpublic get pluginApis(): readonly string[] {\n\t\treturn [...this.pluginApiNames].sort()\n\t}\n}\n"],"names":[],"mappings":";;;;;AASO,MAAM,WAAoC;AAAA,EAGhD,YACiB,UACA,QAEA,KACf;AAJe,SAAA,WAAA;AACA,SAAA,SAAA;AAEA,SAAA,MAAA;AANjB,kBAAA,MAAiB,sCAAqB,IAAA,CAAY;AAAA,EAQlD;AAAA,EAEO,MAAM,aAAkC,EAAE,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"PanelMount.cjs","sources":["../../../../packages/engine-panel/src/PanelMount.ts"],"sourcesContent":["import type { PanelApiMount, PanelApiMountArgs, PanelApiMountTarget } from '@contember/engine-http'\nimport type { PanelApiControllerFactory } from './PanelApiController.js'\nimport type { PanelAssetStore } from './PanelAssets.js'\n\n/**\n * Everything needed to serve the panel, resolved once. It exists only when the panel really is\n * served — enabled *and* built into this binary — so a plugin can read \"this resolved\" as \"there is\n * a panel to mount into\" and skip its panel route otherwise.\n */\nexport class PanelMount implements PanelApiMount {\n\tprivate readonly pluginApiNames = new Set<string>()\n\n\tconstructor(\n\t\tpublic readonly basePath: string,\n\t\tpublic readonly assets: PanelAssetStore,\n\t\t/** Shared with the panel's own routes: one factory means one access-check cache for all of them. */\n\t\tpublic readonly api: PanelApiControllerFactory,\n\t) {\n\t}\n\n\tpublic mount(application: PanelApiMountTarget, { name, path, controller, carriesCredentials }: PanelApiMountArgs): void {\n\t\tapplication.addRoute('panel-api', `${this.basePath}/api/${path}`, this.api.create(controller, { allowAnonymous: false }), { carriesCredentials })\n\t\tthis.pluginApiNames.add(name)\n\t}\n\n\t/**\n\t * APIs plugins have mounted, reported to the UI so a module can hide itself when the plugin that\n\t * backs it is not installed. Read when the shell is rendered, not when it is constructed, so a\n\t * plugin registering after the panel is still counted.\n\t */\n\tpublic get pluginApis(): readonly string[] {\n\t\treturn [...this.pluginApiNames].sort()\n\t}\n}\n"],"names":[],"mappings":";;;;;AASO,MAAM,WAAoC;AAAA,EAGhD,YACiB,UACA,QAEA,KACf;AAJe,SAAA,WAAA;AACA,SAAA,SAAA;AAEA,SAAA,MAAA;AANjB,kBAAA,MAAiB,sCAAqB,IAAA,CAAY;AAAA,EAQlD;AAAA,EAEO,MAAM,aAAkC,EAAE,MAAM,MAAM,YAAY,sBAA+C;AACvH,gBAAY,SAAS,aAAa,GAAG,KAAK,QAAQ,QAAQ,IAAI,IAAI,KAAK,IAAI,OAAO,YAAY,EAAE,gBAAgB,OAAO,GAAG,EAAE,oBAAoB;AAChJ,SAAK,eAAe,IAAI,IAAI;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAW,aAAgC;AAC1C,WAAO,CAAC,GAAG,KAAK,cAAc,EAAE,KAAA;AAAA,EACjC;AACD;;"}
|
|
@@ -8,8 +8,8 @@ class PanelMount {
|
|
|
8
8
|
this.api = api;
|
|
9
9
|
__publicField(this, "pluginApiNames", /* @__PURE__ */ new Set());
|
|
10
10
|
}
|
|
11
|
-
mount(application, { name, path, controller }) {
|
|
12
|
-
application.addRoute("panel-api", `${this.basePath}/api/${path}`, this.api.create(controller, { allowAnonymous: false }));
|
|
11
|
+
mount(application, { name, path, controller, carriesCredentials }) {
|
|
12
|
+
application.addRoute("panel-api", `${this.basePath}/api/${path}`, this.api.create(controller, { allowAnonymous: false }), { carriesCredentials });
|
|
13
13
|
this.pluginApiNames.add(name);
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PanelMount.js","sources":["../../../../packages/engine-panel/src/PanelMount.ts"],"sourcesContent":["import type { PanelApiMount, PanelApiMountArgs, PanelApiMountTarget } from '@contember/engine-http'\nimport type { PanelApiControllerFactory } from './PanelApiController.js'\nimport type { PanelAssetStore } from './PanelAssets.js'\n\n/**\n * Everything needed to serve the panel, resolved once. It exists only when the panel really is\n * served — enabled *and* built into this binary — so a plugin can read \"this resolved\" as \"there is\n * a panel to mount into\" and skip its panel route otherwise.\n */\nexport class PanelMount implements PanelApiMount {\n\tprivate readonly pluginApiNames = new Set<string>()\n\n\tconstructor(\n\t\tpublic readonly basePath: string,\n\t\tpublic readonly assets: PanelAssetStore,\n\t\t/** Shared with the panel's own routes: one factory means one access-check cache for all of them. */\n\t\tpublic readonly api: PanelApiControllerFactory,\n\t) {\n\t}\n\n\tpublic mount(application: PanelApiMountTarget, { name, path, controller }: PanelApiMountArgs): void {\n\t\tapplication.addRoute('panel-api', `${this.basePath}/api/${path}`, this.api.create(controller, { allowAnonymous: false }))\n\t\tthis.pluginApiNames.add(name)\n\t}\n\n\t/**\n\t * APIs plugins have mounted, reported to the UI so a module can hide itself when the plugin that\n\t * backs it is not installed. Read when the shell is rendered, not when it is constructed, so a\n\t * plugin registering after the panel is still counted.\n\t */\n\tpublic get pluginApis(): readonly string[] {\n\t\treturn [...this.pluginApiNames].sort()\n\t}\n}\n"],"names":[],"mappings":";;;AASO,MAAM,WAAoC;AAAA,EAGhD,YACiB,UACA,QAEA,KACf;AAJe,SAAA,WAAA;AACA,SAAA,SAAA;AAEA,SAAA,MAAA;AANjB,kBAAA,MAAiB,sCAAqB,IAAA,CAAY;AAAA,EAQlD;AAAA,EAEO,MAAM,aAAkC,EAAE,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"PanelMount.js","sources":["../../../../packages/engine-panel/src/PanelMount.ts"],"sourcesContent":["import type { PanelApiMount, PanelApiMountArgs, PanelApiMountTarget } from '@contember/engine-http'\nimport type { PanelApiControllerFactory } from './PanelApiController.js'\nimport type { PanelAssetStore } from './PanelAssets.js'\n\n/**\n * Everything needed to serve the panel, resolved once. It exists only when the panel really is\n * served — enabled *and* built into this binary — so a plugin can read \"this resolved\" as \"there is\n * a panel to mount into\" and skip its panel route otherwise.\n */\nexport class PanelMount implements PanelApiMount {\n\tprivate readonly pluginApiNames = new Set<string>()\n\n\tconstructor(\n\t\tpublic readonly basePath: string,\n\t\tpublic readonly assets: PanelAssetStore,\n\t\t/** Shared with the panel's own routes: one factory means one access-check cache for all of them. */\n\t\tpublic readonly api: PanelApiControllerFactory,\n\t) {\n\t}\n\n\tpublic mount(application: PanelApiMountTarget, { name, path, controller, carriesCredentials }: PanelApiMountArgs): void {\n\t\tapplication.addRoute('panel-api', `${this.basePath}/api/${path}`, this.api.create(controller, { allowAnonymous: false }), { carriesCredentials })\n\t\tthis.pluginApiNames.add(name)\n\t}\n\n\t/**\n\t * APIs plugins have mounted, reported to the UI so a module can hide itself when the plugin that\n\t * backs it is not installed. Read when the shell is rendered, not when it is constructed, so a\n\t * plugin registering after the panel is still counted.\n\t */\n\tpublic get pluginApis(): readonly string[] {\n\t\treturn [...this.pluginApiNames].sort()\n\t}\n}\n"],"names":[],"mappings":";;;AASO,MAAM,WAAoC;AAAA,EAGhD,YACiB,UACA,QAEA,KACf;AAJe,SAAA,WAAA;AACA,SAAA,SAAA;AAEA,SAAA,MAAA;AANjB,kBAAA,MAAiB,sCAAqB,IAAA,CAAY;AAAA,EAQlD;AAAA,EAEO,MAAM,aAAkC,EAAE,MAAM,MAAM,YAAY,sBAA+C;AACvH,gBAAY,SAAS,aAAa,GAAG,KAAK,QAAQ,QAAQ,IAAI,IAAI,KAAK,IAAI,OAAO,YAAY,EAAE,gBAAgB,OAAO,GAAG,EAAE,oBAAoB;AAChJ,SAAK,eAAe,IAAI,IAAI;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAW,aAAgC;AAC1C,WAAO,CAAC,GAAG,KAAK,cAAc,EAAE,KAAA;AAAA,EACjC;AACD;"}
|
|
@@ -37,7 +37,9 @@ class PanelPlugin {
|
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
const { basePath, api } = panelApiMount;
|
|
40
|
-
it.addRoute("panel-api", `${basePath}/api/tenant`, api.create(tenantApiMiddlewareFactory.create(), { allowAnonymous: true })
|
|
40
|
+
it.addRoute("panel-api", `${basePath}/api/tenant`, api.create(tenantApiMiddlewareFactory.create(), { allowAnonymous: true }), {
|
|
41
|
+
carriesCredentials: true
|
|
42
|
+
});
|
|
41
43
|
it.addRoute(
|
|
42
44
|
"panel-api",
|
|
43
45
|
`${basePath}/api/content/:projectSlug/:stageSlug`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PanelPlugin.cjs","sources":["../../../../packages/engine-panel/src/PanelPlugin.ts"],"sourcesContent":["import type { MasterContainerBuilder, MasterContainerHook, Plugin } from '@contember/engine-http'\nimport { panelAssets } from './generated/assets.js'\nimport { ConfiguredPanelAccessCheck } from './PanelAccessCheck.js'\nimport { PanelApiControllerFactory } from './PanelApiController.js'\nimport { PanelAssetStore } from './PanelAssets.js'\nimport { PanelController } from './PanelController.js'\nimport { PanelMount } from './PanelMount.js'\n\nconst defaultBasePath = '/panel'\n\nexport class PanelPlugin implements Plugin {\n\tname = 'contember/panel'\n\n\tgetMasterContainerHook(): MasterContainerHook {\n\t\treturn (builder: MasterContainerBuilder) =>\n\t\t\tbuilder\n\t\t\t\t.replaceService('panelApiMount', ({ serverConfig, logger, inner }) => {\n\t\t\t\t\tif (serverConfig.panel?.enabled !== true) {\n\t\t\t\t\t\treturn inner\n\t\t\t\t\t}\n\t\t\t\t\tconst assets = new PanelAssetStore(panelAssets)\n\t\t\t\t\tif (assets.isEmpty()) {\n\t\t\t\t\t\t// Running from source without the build step. A released build cannot get here —\n\t\t\t\t\t\t// `scripts/buildAssets.ts` fails when the panel produced nothing — so this is a\n\t\t\t\t\t\t// developer's checkout, and refusing to start would be a poor trade.\n\t\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t\t'The panel is enabled but this build contains no panel assets — run `bun run --filter=@contember/engine-panel build:assets`. Not serving the panel.',\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn inner\n\t\t\t\t\t}\n\t\t\t\t\tconst basePath = normalizeBasePath(serverConfig.panel.path ?? defaultBasePath)\n\t\t\t\t\treturn new PanelMount(basePath, assets, new PanelApiControllerFactory(new ConfiguredPanelAccessCheck()))\n\t\t\t\t})\n\t\t\t\t.setupService(\n\t\t\t\t\t'application',\n\t\t\t\t\t(it, { panelApiMount, tenantApiMiddlewareFactory, contentApiMiddlewareFactory, systemApiMiddlewareFactory }) => {\n\t\t\t\t\t\tif (!(panelApiMount instanceof PanelMount)) {\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst { basePath, api } = panelApiMount\n\n\t\t\t\t\t\t// The panel's own API mount, mirroring the public paths so the client's existing URL\n\t\t\t\t\t\t// building (`${apiBaseUrl}${path}`) needs no special cases. Only tenant takes anonymous\n\t\t\t\t\t\t// callers — it is the one the sign-in screen talks to before there is a session.\n\t\t\t\t\t\t// Content and system have no pre-sign-in consumer.\n\t\t\t\t\t\tit.addRoute('panel-api', `${basePath}/api/tenant`, api.create(tenantApiMiddlewareFactory.create(), { allowAnonymous: true }))\n\t\t\t\t\t\tit.addRoute(\n\t\t\t\t\t\t\t'panel-api',\n\t\t\t\t\t\t\t`${basePath}/api/content/:projectSlug/:stageSlug`,\n\t\t\t\t\t\t\tapi.create(contentApiMiddlewareFactory.create(), { allowAnonymous: false }),\n\t\t\t\t\t\t)\n\t\t\t\t\t\tit.addRoute('panel-api', `${basePath}/api/system/:projectSlug`, api.create(systemApiMiddlewareFactory.create(), { allowAnonymous: false }))\n\n\t\t\t\t\t\tconst controller = new PanelController({\n\t\t\t\t\t\t\tbasePath,\n\t\t\t\t\t\t\tapiBaseUrl: `${basePath}/api`,\n\t\t\t\t\t\t\tassets: panelApiMount.assets,\n\t\t\t\t\t\t\tpluginApis: () => panelApiMount.pluginApis,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t// Optional trailing group so both `/panel` and `/panel/anything` are served. An API route\n\t\t\t\t\t\t// is a regular route and the shell an internal one, so `/panel/api/...` is matched first\n\t\t\t\t\t\t// however late a plugin registers it.\n\t\t\t\t\t\tit.addInternalRoute('panel', `${basePath}{/*path}`, controller.create())\n\t\t\t\t\t},\n\t\t\t\t)\n\t}\n}\n\nconst normalizeBasePath = (path: string): string => {\n\tconst trimmed = path.trim().replace(/\\/+$/, '')\n\tif (!trimmed.startsWith('/') || trimmed.length < 2) {\n\t\tthrow new Error(`Invalid CONTEMBER_PANEL_PATH ${JSON.stringify(path)}: expecting an absolute path like \"/panel\".`)\n\t}\n\treturn trimmed\n}\n"],"names":["assets","PanelAssetStore","panelAssets","PanelMount","PanelApiControllerFactory","ConfiguredPanelAccessCheck","PanelController"],"mappings":";;;;;;;;;;;AAQA,MAAM,kBAAkB;AAEjB,MAAM,YAA8B;AAAA,EAApC,cAAA;AACN,kBAAA,MAAA,QAAO,iBAAA;AAAA,EAAA;AAAA,EAEP,yBAA8C;AAC7C,WAAO,CAAC,YACP,QACE,eAAe,iBAAiB,CAAC,EAAE,cAAc,QAAQ,YAAY;AACrE,UAAI,aAAa,OAAO,YAAY,MAAM;AACzC,eAAO;AAAA,MACR;AACA,YAAMA,WAAS,IAAIC,YAAAA,gBAAgBC,kBAAW;AAC9C,UAAIF,SAAO,WAAW;AAIrB,eAAO;AAAA,UACN,IAAI;AAAA,YACH;AAAA,UAAA;AAAA,QACD;AAED,eAAO;AAAA,MACR;AACA,YAAM,WAAW,kBAAkB,aAAa,MAAM,QAAQ,eAAe;AAC7E,aAAO,IAAIG,WAAAA,WAAW,UAAUH,UAAQ,IAAII,6CAA0B,IAAIC,iBAAAA,2BAAA,CAA4B,CAAC;AAAA,IACxG,CAAC,EACA;AAAA,MACA;AAAA,MACA,CAAC,IAAI,EAAE,eAAe,4BAA4B,6BAA6B,iCAAiC;AAC/G,YAAI,EAAE,yBAAyBF,WAAAA,aAAa;AAC3C;AAAA,QACD;AACA,cAAM,EAAE,UAAU,IAAA,IAAQ;AAM1B,WAAG,SAAS,aAAa,GAAG,QAAQ,eAAe,IAAI,OAAO,2BAA2B,OAAA,GAAU,EAAE,gBAAgB,KAAA,CAAM,
|
|
1
|
+
{"version":3,"file":"PanelPlugin.cjs","sources":["../../../../packages/engine-panel/src/PanelPlugin.ts"],"sourcesContent":["import type { MasterContainerBuilder, MasterContainerHook, Plugin } from '@contember/engine-http'\nimport { panelAssets } from './generated/assets.js'\nimport { ConfiguredPanelAccessCheck } from './PanelAccessCheck.js'\nimport { PanelApiControllerFactory } from './PanelApiController.js'\nimport { PanelAssetStore } from './PanelAssets.js'\nimport { PanelController } from './PanelController.js'\nimport { PanelMount } from './PanelMount.js'\n\nconst defaultBasePath = '/panel'\n\nexport class PanelPlugin implements Plugin {\n\tname = 'contember/panel'\n\n\tgetMasterContainerHook(): MasterContainerHook {\n\t\treturn (builder: MasterContainerBuilder) =>\n\t\t\tbuilder\n\t\t\t\t.replaceService('panelApiMount', ({ serverConfig, logger, inner }) => {\n\t\t\t\t\tif (serverConfig.panel?.enabled !== true) {\n\t\t\t\t\t\treturn inner\n\t\t\t\t\t}\n\t\t\t\t\tconst assets = new PanelAssetStore(panelAssets)\n\t\t\t\t\tif (assets.isEmpty()) {\n\t\t\t\t\t\t// Running from source without the build step. A released build cannot get here —\n\t\t\t\t\t\t// `scripts/buildAssets.ts` fails when the panel produced nothing — so this is a\n\t\t\t\t\t\t// developer's checkout, and refusing to start would be a poor trade.\n\t\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t\t'The panel is enabled but this build contains no panel assets — run `bun run --filter=@contember/engine-panel build:assets`. Not serving the panel.',\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn inner\n\t\t\t\t\t}\n\t\t\t\t\tconst basePath = normalizeBasePath(serverConfig.panel.path ?? defaultBasePath)\n\t\t\t\t\treturn new PanelMount(basePath, assets, new PanelApiControllerFactory(new ConfiguredPanelAccessCheck()))\n\t\t\t\t})\n\t\t\t\t.setupService(\n\t\t\t\t\t'application',\n\t\t\t\t\t(it, { panelApiMount, tenantApiMiddlewareFactory, contentApiMiddlewareFactory, systemApiMiddlewareFactory }) => {\n\t\t\t\t\t\tif (!(panelApiMount instanceof PanelMount)) {\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst { basePath, api } = panelApiMount\n\n\t\t\t\t\t\t// The panel's own API mount, mirroring the public paths so the client's existing URL\n\t\t\t\t\t\t// building (`${apiBaseUrl}${path}`) needs no special cases. Only tenant takes anonymous\n\t\t\t\t\t\t// callers — it is the one the sign-in screen talks to before there is a session.\n\t\t\t\t\t\t// Content and system have no pre-sign-in consumer.\n\t\t\t\t\t\tit.addRoute('panel-api', `${basePath}/api/tenant`, api.create(tenantApiMiddlewareFactory.create(), { allowAnonymous: true }), {\n\t\t\t\t\t\t\tcarriesCredentials: true,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tit.addRoute(\n\t\t\t\t\t\t\t'panel-api',\n\t\t\t\t\t\t\t`${basePath}/api/content/:projectSlug/:stageSlug`,\n\t\t\t\t\t\t\tapi.create(contentApiMiddlewareFactory.create(), { allowAnonymous: false }),\n\t\t\t\t\t\t)\n\t\t\t\t\t\tit.addRoute('panel-api', `${basePath}/api/system/:projectSlug`, api.create(systemApiMiddlewareFactory.create(), { allowAnonymous: false }))\n\n\t\t\t\t\t\tconst controller = new PanelController({\n\t\t\t\t\t\t\tbasePath,\n\t\t\t\t\t\t\tapiBaseUrl: `${basePath}/api`,\n\t\t\t\t\t\t\tassets: panelApiMount.assets,\n\t\t\t\t\t\t\tpluginApis: () => panelApiMount.pluginApis,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t// Optional trailing group so both `/panel` and `/panel/anything` are served. An API route\n\t\t\t\t\t\t// is a regular route and the shell an internal one, so `/panel/api/...` is matched first\n\t\t\t\t\t\t// however late a plugin registers it.\n\t\t\t\t\t\tit.addInternalRoute('panel', `${basePath}{/*path}`, controller.create())\n\t\t\t\t\t},\n\t\t\t\t)\n\t}\n}\n\nconst normalizeBasePath = (path: string): string => {\n\tconst trimmed = path.trim().replace(/\\/+$/, '')\n\tif (!trimmed.startsWith('/') || trimmed.length < 2) {\n\t\tthrow new Error(`Invalid CONTEMBER_PANEL_PATH ${JSON.stringify(path)}: expecting an absolute path like \"/panel\".`)\n\t}\n\treturn trimmed\n}\n"],"names":["assets","PanelAssetStore","panelAssets","PanelMount","PanelApiControllerFactory","ConfiguredPanelAccessCheck","PanelController"],"m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;AAAA,UACvB,QAAQ,cAAc;AAAA,UACtB,YAAY,MAAM,cAAc;AAAA,QAAA,CAChC;AAID,WAAG,iBAAiB,SAAS,GAAG,QAAQ,YAAY,WAAW,QAAQ;AAAA,MACxE;AAAA,IAAA;AAAA,EAEJ;AACD;AAEA,MAAM,oBAAoB,CAAC,SAAyB;AACnD,QAAM,UAAU,KAAK,KAAA,EAAO,QAAQ,QAAQ,EAAE;AAC9C,MAAI,CAAC,QAAQ,WAAW,GAAG,KAAK,QAAQ,SAAS,GAAG;AACnD,UAAM,IAAI,MAAM,gCAAgC,KAAK,UAAU,IAAI,CAAC,6CAA6C;AAAA,EAClH;AACA,SAAO;AACR;;"}
|
|
@@ -35,7 +35,9 @@ class PanelPlugin {
|
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
37
|
const { basePath, api } = panelApiMount;
|
|
38
|
-
it.addRoute("panel-api", `${basePath}/api/tenant`, api.create(tenantApiMiddlewareFactory.create(), { allowAnonymous: true })
|
|
38
|
+
it.addRoute("panel-api", `${basePath}/api/tenant`, api.create(tenantApiMiddlewareFactory.create(), { allowAnonymous: true }), {
|
|
39
|
+
carriesCredentials: true
|
|
40
|
+
});
|
|
39
41
|
it.addRoute(
|
|
40
42
|
"panel-api",
|
|
41
43
|
`${basePath}/api/content/:projectSlug/:stageSlug`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PanelPlugin.js","sources":["../../../../packages/engine-panel/src/PanelPlugin.ts"],"sourcesContent":["import type { MasterContainerBuilder, MasterContainerHook, Plugin } from '@contember/engine-http'\nimport { panelAssets } from './generated/assets.js'\nimport { ConfiguredPanelAccessCheck } from './PanelAccessCheck.js'\nimport { PanelApiControllerFactory } from './PanelApiController.js'\nimport { PanelAssetStore } from './PanelAssets.js'\nimport { PanelController } from './PanelController.js'\nimport { PanelMount } from './PanelMount.js'\n\nconst defaultBasePath = '/panel'\n\nexport class PanelPlugin implements Plugin {\n\tname = 'contember/panel'\n\n\tgetMasterContainerHook(): MasterContainerHook {\n\t\treturn (builder: MasterContainerBuilder) =>\n\t\t\tbuilder\n\t\t\t\t.replaceService('panelApiMount', ({ serverConfig, logger, inner }) => {\n\t\t\t\t\tif (serverConfig.panel?.enabled !== true) {\n\t\t\t\t\t\treturn inner\n\t\t\t\t\t}\n\t\t\t\t\tconst assets = new PanelAssetStore(panelAssets)\n\t\t\t\t\tif (assets.isEmpty()) {\n\t\t\t\t\t\t// Running from source without the build step. A released build cannot get here —\n\t\t\t\t\t\t// `scripts/buildAssets.ts` fails when the panel produced nothing — so this is a\n\t\t\t\t\t\t// developer's checkout, and refusing to start would be a poor trade.\n\t\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t\t'The panel is enabled but this build contains no panel assets — run `bun run --filter=@contember/engine-panel build:assets`. Not serving the panel.',\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn inner\n\t\t\t\t\t}\n\t\t\t\t\tconst basePath = normalizeBasePath(serverConfig.panel.path ?? defaultBasePath)\n\t\t\t\t\treturn new PanelMount(basePath, assets, new PanelApiControllerFactory(new ConfiguredPanelAccessCheck()))\n\t\t\t\t})\n\t\t\t\t.setupService(\n\t\t\t\t\t'application',\n\t\t\t\t\t(it, { panelApiMount, tenantApiMiddlewareFactory, contentApiMiddlewareFactory, systemApiMiddlewareFactory }) => {\n\t\t\t\t\t\tif (!(panelApiMount instanceof PanelMount)) {\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst { basePath, api } = panelApiMount\n\n\t\t\t\t\t\t// The panel's own API mount, mirroring the public paths so the client's existing URL\n\t\t\t\t\t\t// building (`${apiBaseUrl}${path}`) needs no special cases. Only tenant takes anonymous\n\t\t\t\t\t\t// callers — it is the one the sign-in screen talks to before there is a session.\n\t\t\t\t\t\t// Content and system have no pre-sign-in consumer.\n\t\t\t\t\t\tit.addRoute('panel-api', `${basePath}/api/tenant`, api.create(tenantApiMiddlewareFactory.create(), { allowAnonymous: true }))\n\t\t\t\t\t\tit.addRoute(\n\t\t\t\t\t\t\t'panel-api',\n\t\t\t\t\t\t\t`${basePath}/api/content/:projectSlug/:stageSlug`,\n\t\t\t\t\t\t\tapi.create(contentApiMiddlewareFactory.create(), { allowAnonymous: false }),\n\t\t\t\t\t\t)\n\t\t\t\t\t\tit.addRoute('panel-api', `${basePath}/api/system/:projectSlug`, api.create(systemApiMiddlewareFactory.create(), { allowAnonymous: false }))\n\n\t\t\t\t\t\tconst controller = new PanelController({\n\t\t\t\t\t\t\tbasePath,\n\t\t\t\t\t\t\tapiBaseUrl: `${basePath}/api`,\n\t\t\t\t\t\t\tassets: panelApiMount.assets,\n\t\t\t\t\t\t\tpluginApis: () => panelApiMount.pluginApis,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t// Optional trailing group so both `/panel` and `/panel/anything` are served. An API route\n\t\t\t\t\t\t// is a regular route and the shell an internal one, so `/panel/api/...` is matched first\n\t\t\t\t\t\t// however late a plugin registers it.\n\t\t\t\t\t\tit.addInternalRoute('panel', `${basePath}{/*path}`, controller.create())\n\t\t\t\t\t},\n\t\t\t\t)\n\t}\n}\n\nconst normalizeBasePath = (path: string): string => {\n\tconst trimmed = path.trim().replace(/\\/+$/, '')\n\tif (!trimmed.startsWith('/') || trimmed.length < 2) {\n\t\tthrow new Error(`Invalid CONTEMBER_PANEL_PATH ${JSON.stringify(path)}: expecting an absolute path like \"/panel\".`)\n\t}\n\treturn trimmed\n}\n"],"names":[],"mappings":";;;;;;;;;AAQA,MAAM,kBAAkB;AAEjB,MAAM,YAA8B;AAAA,EAApC,cAAA;AACN,kBAAA,MAAA,QAAO,iBAAA;AAAA,EAAA;AAAA,EAEP,yBAA8C;AAC7C,WAAO,CAAC,YACP,QACE,eAAe,iBAAiB,CAAC,EAAE,cAAc,QAAQ,YAAY;AACrE,UAAI,aAAa,OAAO,YAAY,MAAM;AACzC,eAAO;AAAA,MACR;AACA,YAAM,SAAS,IAAI,gBAAgB,WAAW;AAC9C,UAAI,OAAO,WAAW;AAIrB,eAAO;AAAA,UACN,IAAI;AAAA,YACH;AAAA,UAAA;AAAA,QACD;AAED,eAAO;AAAA,MACR;AACA,YAAM,WAAW,kBAAkB,aAAa,MAAM,QAAQ,eAAe;AAC7E,aAAO,IAAI,WAAW,UAAU,QAAQ,IAAI,0BAA0B,IAAI,2BAAA,CAA4B,CAAC;AAAA,IACxG,CAAC,EACA;AAAA,MACA;AAAA,MACA,CAAC,IAAI,EAAE,eAAe,4BAA4B,6BAA6B,iCAAiC;AAC/G,YAAI,EAAE,yBAAyB,aAAa;AAC3C;AAAA,QACD;AACA,cAAM,EAAE,UAAU,IAAA,IAAQ;AAM1B,WAAG,SAAS,aAAa,GAAG,QAAQ,eAAe,IAAI,OAAO,2BAA2B,OAAA,GAAU,EAAE,gBAAgB,KAAA,CAAM,
|
|
1
|
+
{"version":3,"file":"PanelPlugin.js","sources":["../../../../packages/engine-panel/src/PanelPlugin.ts"],"sourcesContent":["import type { MasterContainerBuilder, MasterContainerHook, Plugin } from '@contember/engine-http'\nimport { panelAssets } from './generated/assets.js'\nimport { ConfiguredPanelAccessCheck } from './PanelAccessCheck.js'\nimport { PanelApiControllerFactory } from './PanelApiController.js'\nimport { PanelAssetStore } from './PanelAssets.js'\nimport { PanelController } from './PanelController.js'\nimport { PanelMount } from './PanelMount.js'\n\nconst defaultBasePath = '/panel'\n\nexport class PanelPlugin implements Plugin {\n\tname = 'contember/panel'\n\n\tgetMasterContainerHook(): MasterContainerHook {\n\t\treturn (builder: MasterContainerBuilder) =>\n\t\t\tbuilder\n\t\t\t\t.replaceService('panelApiMount', ({ serverConfig, logger, inner }) => {\n\t\t\t\t\tif (serverConfig.panel?.enabled !== true) {\n\t\t\t\t\t\treturn inner\n\t\t\t\t\t}\n\t\t\t\t\tconst assets = new PanelAssetStore(panelAssets)\n\t\t\t\t\tif (assets.isEmpty()) {\n\t\t\t\t\t\t// Running from source without the build step. A released build cannot get here —\n\t\t\t\t\t\t// `scripts/buildAssets.ts` fails when the panel produced nothing — so this is a\n\t\t\t\t\t\t// developer's checkout, and refusing to start would be a poor trade.\n\t\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t\t'The panel is enabled but this build contains no panel assets — run `bun run --filter=@contember/engine-panel build:assets`. Not serving the panel.',\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn inner\n\t\t\t\t\t}\n\t\t\t\t\tconst basePath = normalizeBasePath(serverConfig.panel.path ?? defaultBasePath)\n\t\t\t\t\treturn new PanelMount(basePath, assets, new PanelApiControllerFactory(new ConfiguredPanelAccessCheck()))\n\t\t\t\t})\n\t\t\t\t.setupService(\n\t\t\t\t\t'application',\n\t\t\t\t\t(it, { panelApiMount, tenantApiMiddlewareFactory, contentApiMiddlewareFactory, systemApiMiddlewareFactory }) => {\n\t\t\t\t\t\tif (!(panelApiMount instanceof PanelMount)) {\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst { basePath, api } = panelApiMount\n\n\t\t\t\t\t\t// The panel's own API mount, mirroring the public paths so the client's existing URL\n\t\t\t\t\t\t// building (`${apiBaseUrl}${path}`) needs no special cases. Only tenant takes anonymous\n\t\t\t\t\t\t// callers — it is the one the sign-in screen talks to before there is a session.\n\t\t\t\t\t\t// Content and system have no pre-sign-in consumer.\n\t\t\t\t\t\tit.addRoute('panel-api', `${basePath}/api/tenant`, api.create(tenantApiMiddlewareFactory.create(), { allowAnonymous: true }), {\n\t\t\t\t\t\t\tcarriesCredentials: true,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tit.addRoute(\n\t\t\t\t\t\t\t'panel-api',\n\t\t\t\t\t\t\t`${basePath}/api/content/:projectSlug/:stageSlug`,\n\t\t\t\t\t\t\tapi.create(contentApiMiddlewareFactory.create(), { allowAnonymous: false }),\n\t\t\t\t\t\t)\n\t\t\t\t\t\tit.addRoute('panel-api', `${basePath}/api/system/:projectSlug`, api.create(systemApiMiddlewareFactory.create(), { allowAnonymous: false }))\n\n\t\t\t\t\t\tconst controller = new PanelController({\n\t\t\t\t\t\t\tbasePath,\n\t\t\t\t\t\t\tapiBaseUrl: `${basePath}/api`,\n\t\t\t\t\t\t\tassets: panelApiMount.assets,\n\t\t\t\t\t\t\tpluginApis: () => panelApiMount.pluginApis,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t// Optional trailing group so both `/panel` and `/panel/anything` are served. An API route\n\t\t\t\t\t\t// is a regular route and the shell an internal one, so `/panel/api/...` is matched first\n\t\t\t\t\t\t// however late a plugin registers it.\n\t\t\t\t\t\tit.addInternalRoute('panel', `${basePath}{/*path}`, controller.create())\n\t\t\t\t\t},\n\t\t\t\t)\n\t}\n}\n\nconst normalizeBasePath = (path: string): string => {\n\tconst trimmed = path.trim().replace(/\\/+$/, '')\n\tif (!trimmed.startsWith('/') || trimmed.length < 2) {\n\t\tthrow new Error(`Invalid CONTEMBER_PANEL_PATH ${JSON.stringify(path)}: expecting an absolute path like \"/panel\".`)\n\t}\n\treturn trimmed\n}\n"],"names":[],"mappings":";;;;;;;;;AAQA,MAAM,kBAAkB;AAEjB,MAAM,YAA8B;AAAA,EAApC,cAAA;AACN,kBAAA,MAAA,QAAO,iBAAA;AAAA,EAAA;AAAA,EAEP,yBAA8C;AAC7C,WAAO,CAAC,YACP,QACE,eAAe,iBAAiB,CAAC,EAAE,cAAc,QAAQ,YAAY;AACrE,UAAI,aAAa,OAAO,YAAY,MAAM;AACzC,eAAO;AAAA,MACR;AACA,YAAM,SAAS,IAAI,gBAAgB,WAAW;AAC9C,UAAI,OAAO,WAAW;AAIrB,eAAO;AAAA,UACN,IAAI;AAAA,YACH;AAAA,UAAA;AAAA,QACD;AAED,eAAO;AAAA,MACR;AACA,YAAM,WAAW,kBAAkB,aAAa,MAAM,QAAQ,eAAe;AAC7E,aAAO,IAAI,WAAW,UAAU,QAAQ,IAAI,0B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