@contember/engine-panel 2.2.0-alpha.10

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.
Files changed (116) hide show
  1. package/CLAUDE.md +29 -0
  2. package/dist/development/index.cjs +21 -0
  3. package/dist/development/index.cjs.map +1 -0
  4. package/dist/development/index.js +21 -0
  5. package/dist/development/index.js.map +1 -0
  6. package/dist/development/src/PanelAccessCheck.cjs +21 -0
  7. package/dist/development/src/PanelAccessCheck.cjs.map +1 -0
  8. package/dist/development/src/PanelAccessCheck.js +21 -0
  9. package/dist/development/src/PanelAccessCheck.js.map +1 -0
  10. package/dist/development/src/PanelApiController.cjs +60 -0
  11. package/dist/development/src/PanelApiController.cjs.map +1 -0
  12. package/dist/development/src/PanelApiController.js +60 -0
  13. package/dist/development/src/PanelApiController.js.map +1 -0
  14. package/dist/development/src/PanelAssets.cjs +57 -0
  15. package/dist/development/src/PanelAssets.cjs.map +1 -0
  16. package/dist/development/src/PanelAssets.js +57 -0
  17. package/dist/development/src/PanelAssets.js.map +1 -0
  18. package/dist/development/src/PanelController.cjs +108 -0
  19. package/dist/development/src/PanelController.cjs.map +1 -0
  20. package/dist/development/src/PanelController.js +108 -0
  21. package/dist/development/src/PanelController.js.map +1 -0
  22. package/dist/development/src/PanelMount.cjs +27 -0
  23. package/dist/development/src/PanelMount.cjs.map +1 -0
  24. package/dist/development/src/PanelMount.js +27 -0
  25. package/dist/development/src/PanelMount.js.map +1 -0
  26. package/dist/development/src/PanelPlugin.cjs +66 -0
  27. package/dist/development/src/PanelPlugin.cjs.map +1 -0
  28. package/dist/development/src/PanelPlugin.js +66 -0
  29. package/dist/development/src/PanelPlugin.js.map +1 -0
  30. package/dist/development/src/TtlCache.cjs +47 -0
  31. package/dist/development/src/TtlCache.cjs.map +1 -0
  32. package/dist/development/src/TtlCache.js +47 -0
  33. package/dist/development/src/TtlCache.js.map +1 -0
  34. package/dist/development/src/generated/assets.cjs +46 -0
  35. package/dist/development/src/generated/assets.cjs.map +1 -0
  36. package/dist/development/src/generated/assets.js +46 -0
  37. package/dist/development/src/generated/assets.js.map +1 -0
  38. package/dist/production/index.cjs +21 -0
  39. package/dist/production/index.cjs.map +1 -0
  40. package/dist/production/index.js +21 -0
  41. package/dist/production/index.js.map +1 -0
  42. package/dist/production/src/PanelAccessCheck.cjs +21 -0
  43. package/dist/production/src/PanelAccessCheck.cjs.map +1 -0
  44. package/dist/production/src/PanelAccessCheck.js +21 -0
  45. package/dist/production/src/PanelAccessCheck.js.map +1 -0
  46. package/dist/production/src/PanelApiController.cjs +60 -0
  47. package/dist/production/src/PanelApiController.cjs.map +1 -0
  48. package/dist/production/src/PanelApiController.js +60 -0
  49. package/dist/production/src/PanelApiController.js.map +1 -0
  50. package/dist/production/src/PanelAssets.cjs +57 -0
  51. package/dist/production/src/PanelAssets.cjs.map +1 -0
  52. package/dist/production/src/PanelAssets.js +57 -0
  53. package/dist/production/src/PanelAssets.js.map +1 -0
  54. package/dist/production/src/PanelController.cjs +108 -0
  55. package/dist/production/src/PanelController.cjs.map +1 -0
  56. package/dist/production/src/PanelController.js +108 -0
  57. package/dist/production/src/PanelController.js.map +1 -0
  58. package/dist/production/src/PanelMount.cjs +27 -0
  59. package/dist/production/src/PanelMount.cjs.map +1 -0
  60. package/dist/production/src/PanelMount.js +27 -0
  61. package/dist/production/src/PanelMount.js.map +1 -0
  62. package/dist/production/src/PanelPlugin.cjs +66 -0
  63. package/dist/production/src/PanelPlugin.cjs.map +1 -0
  64. package/dist/production/src/PanelPlugin.js +66 -0
  65. package/dist/production/src/PanelPlugin.js.map +1 -0
  66. package/dist/production/src/TtlCache.cjs +47 -0
  67. package/dist/production/src/TtlCache.cjs.map +1 -0
  68. package/dist/production/src/TtlCache.js +47 -0
  69. package/dist/production/src/TtlCache.js.map +1 -0
  70. package/dist/production/src/generated/assets.cjs +46 -0
  71. package/dist/production/src/generated/assets.cjs.map +1 -0
  72. package/dist/production/src/generated/assets.js +46 -0
  73. package/dist/production/src/generated/assets.js.map +1 -0
  74. package/dist/tests/cases/unit/panelController.test.d.ts +2 -0
  75. package/dist/tests/cases/unit/panelController.test.d.ts.map +1 -0
  76. package/dist/tests/cases/unit/panelMount.test.d.ts +2 -0
  77. package/dist/tests/cases/unit/panelMount.test.d.ts.map +1 -0
  78. package/dist/tests/cases/unit/ttlCache.test.d.ts +2 -0
  79. package/dist/tests/cases/unit/ttlCache.test.d.ts.map +1 -0
  80. package/dist/tests/tsconfig.tsbuildinfo +1 -0
  81. package/dist/types/PanelAccessCheck.d.ts +16 -0
  82. package/dist/types/PanelAccessCheck.d.ts.map +1 -0
  83. package/dist/types/PanelApiController.d.ts +58 -0
  84. package/dist/types/PanelApiController.d.ts.map +1 -0
  85. package/dist/types/PanelAssets.d.ts +32 -0
  86. package/dist/types/PanelAssets.d.ts.map +1 -0
  87. package/dist/types/PanelController.d.ts +46 -0
  88. package/dist/types/PanelController.d.ts.map +1 -0
  89. package/dist/types/PanelMount.d.ts +26 -0
  90. package/dist/types/PanelMount.d.ts.map +1 -0
  91. package/dist/types/PanelPlugin.d.ts +6 -0
  92. package/dist/types/PanelPlugin.d.ts.map +1 -0
  93. package/dist/types/TtlCache.d.ts +16 -0
  94. package/dist/types/TtlCache.d.ts.map +1 -0
  95. package/dist/types/generated/assets.d.ts +3 -0
  96. package/dist/types/generated/assets.d.ts.map +1 -0
  97. package/dist/types/index.d.ts +10 -0
  98. package/dist/types/index.d.ts.map +1 -0
  99. package/dist/types/tsconfig.tsbuildinfo +1 -0
  100. package/package.json +40 -0
  101. package/scripts/buildAssets.ts +79 -0
  102. package/src/PanelAccessCheck.ts +24 -0
  103. package/src/PanelApiController.ts +126 -0
  104. package/src/PanelAssets.ts +69 -0
  105. package/src/PanelController.ts +166 -0
  106. package/src/PanelMount.ts +34 -0
  107. package/src/PanelPlugin.ts +77 -0
  108. package/src/TtlCache.ts +53 -0
  109. package/src/index.ts +11 -0
  110. package/src/tsconfig.json +9 -0
  111. package/tests/cases/unit/panelController.test.ts +159 -0
  112. package/tests/cases/unit/panelMount.test.ts +55 -0
  113. package/tests/cases/unit/ttlCache.test.ts +55 -0
  114. package/tests/tsconfig.json +9 -0
  115. package/tsconfig.json +8 -0
  116. package/tsconfig.settings.json +6 -0
@@ -0,0 +1,108 @@
1
+ import { gunzipSync, gzipSync } from "node:zlib";
2
+ import { indexAssetPath } from "./PanelAssets.js";
3
+ var __defProp = Object.defineProperty;
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
+ const basePlaceholder = "__CONTEMBER_PANEL_BASE__";
7
+ const configPlaceholder = "__CONTEMBER_PANEL_CONFIG__";
8
+ const contentSecurityPolicy = [
9
+ `default-src 'self'`,
10
+ `script-src 'self'`,
11
+ `style-src 'self' 'unsafe-inline'`,
12
+ `img-src 'self' data:`,
13
+ `font-src 'self' data:`,
14
+ `connect-src 'self'`,
15
+ `base-uri 'self'`,
16
+ `form-action 'self'`,
17
+ `frame-ancestors 'none'`
18
+ ].join("; ");
19
+ class PanelController {
20
+ constructor(args) {
21
+ this.args = args;
22
+ __publicField(this, "indexHtml");
23
+ __publicField(this, "indexSource");
24
+ const source = args.assets.getGzip(indexAssetPath);
25
+ if (source === void 0) {
26
+ throw new Error("The panel UI was not built into this binary. Run `bun run pre-build` before building the server.");
27
+ }
28
+ this.indexSource = source;
29
+ }
30
+ create() {
31
+ return (ctx) => {
32
+ const response = this.handle({
33
+ method: ctx.koa.method,
34
+ path: typeof ctx.params.path === "string" ? ctx.params.path : void 0,
35
+ acceptEncoding: headerValue(ctx.request.headers["accept-encoding"])
36
+ });
37
+ ctx.koa.status = response.status;
38
+ for (const [name, value] of Object.entries(response.headers)) {
39
+ ctx.koa.set(name, value);
40
+ }
41
+ ctx.koa.body = response.body;
42
+ };
43
+ }
44
+ handle(request) {
45
+ if (request.method !== "GET" && request.method !== "HEAD") {
46
+ return { status: 405, headers: { "Allow": "GET, HEAD" }, body: Buffer.alloc(0) };
47
+ }
48
+ const path = normalizePath(request.path);
49
+ const gzip = path === void 0 || path === indexAssetPath ? void 0 : this.args.assets.getGzip(path);
50
+ if (path === void 0 || gzip === void 0) {
51
+ this.indexHtml ?? (this.indexHtml = this.renderIndex());
52
+ return this.respond(request, this.indexHtml.gzip, () => this.indexHtml?.identity, {
53
+ "Content-Type": "text/html; charset=utf-8",
54
+ "Cache-Control": "no-store",
55
+ "Content-Security-Policy": contentSecurityPolicy,
56
+ "X-Robots-Tag": "noindex, nofollow",
57
+ "Referrer-Policy": "no-referrer"
58
+ });
59
+ }
60
+ return this.respond(request, gzip, () => this.args.assets.getIdentity(path), {
61
+ "Content-Type": this.args.assets.getContentType(path) ?? "application/octet-stream",
62
+ "Cache-Control": "public, max-age=31536000, immutable"
63
+ });
64
+ }
65
+ respond(request, gzipped, identity, headers) {
66
+ const common = {
67
+ ...headers,
68
+ "Vary": "Accept-Encoding",
69
+ "X-Content-Type-Options": "nosniff"
70
+ };
71
+ if (acceptsGzip(request.acceptEncoding)) {
72
+ return { status: 200, headers: { ...common, "Content-Encoding": "gzip" }, body: request.method === "HEAD" ? Buffer.alloc(0) : gzipped };
73
+ }
74
+ return { status: 200, headers: common, body: request.method === "HEAD" ? Buffer.alloc(0) : identity() ?? Buffer.alloc(0) };
75
+ }
76
+ renderIndex() {
77
+ const config = JSON.stringify({
78
+ basePath: `${this.args.basePath}/`,
79
+ apiBaseUrl: this.args.apiBaseUrl,
80
+ pluginApis: this.args.pluginApis()
81
+ });
82
+ const identity = Buffer.from(
83
+ gunzipSync(this.indexSource).toString("utf8").replaceAll(basePlaceholder, () => `${this.args.basePath}/`).replaceAll(configPlaceholder, () => config)
84
+ );
85
+ return { gzip: gzipSync(identity), identity };
86
+ }
87
+ }
88
+ const headerValue = (header) => Array.isArray(header) ? header.join(",") : header;
89
+ const acceptsGzip = (acceptEncoding) => acceptEncoding !== void 0 && /(^|,)\s*(gzip|\*)\s*(;|,|$)/.test(acceptEncoding);
90
+ const normalizePath = (raw) => {
91
+ if (raw === void 0 || raw === "") {
92
+ return void 0;
93
+ }
94
+ let decoded;
95
+ try {
96
+ decoded = decodeURIComponent(raw);
97
+ } catch {
98
+ return void 0;
99
+ }
100
+ if (decoded.includes("\0") || decoded.split("/").includes("..")) {
101
+ return void 0;
102
+ }
103
+ return decoded;
104
+ };
105
+ export {
106
+ PanelController
107
+ };
108
+ //# sourceMappingURL=PanelController.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PanelController.js","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":[],"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,QAAQ,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,YAA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
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
6
+ class PanelMount {
7
+ constructor(basePath, assets, api) {
8
+ this.basePath = basePath;
9
+ this.assets = assets;
10
+ this.api = api;
11
+ __publicField(this, "pluginApiNames", /* @__PURE__ */ new Set());
12
+ }
13
+ mount(application, { name, path, controller }) {
14
+ application.addRoute("panel-api", `${this.basePath}/api/${path}`, this.api.create(controller, { allowAnonymous: false }));
15
+ this.pluginApiNames.add(name);
16
+ }
17
+ /**
18
+ * APIs plugins have mounted, reported to the UI so a module can hide itself when the plugin that
19
+ * backs it is not installed. Read when the shell is rendered, not when it is constructed, so a
20
+ * plugin registering after the panel is still counted.
21
+ */
22
+ get pluginApis() {
23
+ return [...this.pluginApiNames].sort();
24
+ }
25
+ }
26
+ exports.PanelMount = PanelMount;
27
+ //# sourceMappingURL=PanelMount.cjs.map
@@ -0,0 +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,cAAuC;AACnG,gBAAY,SAAS,aAAa,GAAG,KAAK,QAAQ,QAAQ,IAAI,IAAI,KAAK,IAAI,OAAO,YAAY,EAAE,gBAAgB,MAAA,CAAO,CAAC;AACxH,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;;"}
@@ -0,0 +1,27 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
4
+ class PanelMount {
5
+ constructor(basePath, assets, api) {
6
+ this.basePath = basePath;
7
+ this.assets = assets;
8
+ this.api = api;
9
+ __publicField(this, "pluginApiNames", /* @__PURE__ */ new Set());
10
+ }
11
+ mount(application, { name, path, controller }) {
12
+ application.addRoute("panel-api", `${this.basePath}/api/${path}`, this.api.create(controller, { allowAnonymous: false }));
13
+ this.pluginApiNames.add(name);
14
+ }
15
+ /**
16
+ * APIs plugins have mounted, reported to the UI so a module can hide itself when the plugin that
17
+ * backs it is not installed. Read when the shell is rendered, not when it is constructed, so a
18
+ * plugin registering after the panel is still counted.
19
+ */
20
+ get pluginApis() {
21
+ return [...this.pluginApiNames].sort();
22
+ }
23
+ }
24
+ export {
25
+ PanelMount
26
+ };
27
+ //# sourceMappingURL=PanelMount.js.map
@@ -0,0 +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,cAAuC;AACnG,gBAAY,SAAS,aAAa,GAAG,KAAK,QAAQ,QAAQ,IAAI,IAAI,KAAK,IAAI,OAAO,YAAY,EAAE,gBAAgB,MAAA,CAAO,CAAC;AACxH,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;"}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const assets = require("./generated/assets.cjs");
4
+ const PanelAccessCheck = require("./PanelAccessCheck.cjs");
5
+ const PanelApiController = require("./PanelApiController.cjs");
6
+ const PanelAssets = require("./PanelAssets.cjs");
7
+ const PanelController = require("./PanelController.cjs");
8
+ const PanelMount = require("./PanelMount.cjs");
9
+ var __defProp = Object.defineProperty;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
12
+ const defaultBasePath = "/panel";
13
+ class PanelPlugin {
14
+ constructor() {
15
+ __publicField(this, "name", "contember/panel");
16
+ }
17
+ getMasterContainerHook() {
18
+ return (builder) => builder.replaceService("panelApiMount", ({ serverConfig, logger, inner }) => {
19
+ if (serverConfig.panel?.enabled !== true) {
20
+ return inner;
21
+ }
22
+ const assets$1 = new PanelAssets.PanelAssetStore(assets.panelAssets);
23
+ if (assets$1.isEmpty()) {
24
+ logger.error(
25
+ new Error(
26
+ "The panel is enabled but this build contains no panel assets — run `bun run --filter=@contember/engine-panel build:assets`. Not serving the panel."
27
+ )
28
+ );
29
+ return inner;
30
+ }
31
+ const basePath = normalizeBasePath(serverConfig.panel.path ?? defaultBasePath);
32
+ return new PanelMount.PanelMount(basePath, assets$1, new PanelApiController.PanelApiControllerFactory(new PanelAccessCheck.ConfiguredPanelAccessCheck()));
33
+ }).setupService(
34
+ "application",
35
+ (it, { panelApiMount, tenantApiMiddlewareFactory, contentApiMiddlewareFactory, systemApiMiddlewareFactory }) => {
36
+ if (!(panelApiMount instanceof PanelMount.PanelMount)) {
37
+ return;
38
+ }
39
+ const { basePath, api } = panelApiMount;
40
+ it.addRoute("panel-api", `${basePath}/api/tenant`, api.create(tenantApiMiddlewareFactory.create(), { allowAnonymous: true }));
41
+ it.addRoute(
42
+ "panel-api",
43
+ `${basePath}/api/content/:projectSlug/:stageSlug`,
44
+ api.create(contentApiMiddlewareFactory.create(), { allowAnonymous: false })
45
+ );
46
+ it.addRoute("panel-api", `${basePath}/api/system/:projectSlug`, api.create(systemApiMiddlewareFactory.create(), { allowAnonymous: false }));
47
+ const controller = new PanelController.PanelController({
48
+ basePath,
49
+ apiBaseUrl: `${basePath}/api`,
50
+ assets: panelApiMount.assets,
51
+ pluginApis: () => panelApiMount.pluginApis
52
+ });
53
+ it.addInternalRoute("panel", `${basePath}{/*path}`, controller.create());
54
+ }
55
+ );
56
+ }
57
+ }
58
+ const normalizeBasePath = (path) => {
59
+ const trimmed = path.trim().replace(/\/+$/, "");
60
+ if (!trimmed.startsWith("/") || trimmed.length < 2) {
61
+ throw new Error(`Invalid CONTEMBER_PANEL_PATH ${JSON.stringify(path)}: expecting an absolute path like "/panel".`);
62
+ }
63
+ return trimmed;
64
+ };
65
+ exports.PanelPlugin = PanelPlugin;
66
+ //# sourceMappingURL=PanelPlugin.cjs.map
@@ -0,0 +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":";;;;;;;;;;;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c;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;;"}
@@ -0,0 +1,66 @@
1
+ import { panelAssets } from "./generated/assets.js";
2
+ import { ConfiguredPanelAccessCheck } from "./PanelAccessCheck.js";
3
+ import { PanelApiControllerFactory } from "./PanelApiController.js";
4
+ import { PanelAssetStore } from "./PanelAssets.js";
5
+ import { PanelController } from "./PanelController.js";
6
+ import { PanelMount } from "./PanelMount.js";
7
+ var __defProp = Object.defineProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
10
+ const defaultBasePath = "/panel";
11
+ class PanelPlugin {
12
+ constructor() {
13
+ __publicField(this, "name", "contember/panel");
14
+ }
15
+ getMasterContainerHook() {
16
+ return (builder) => builder.replaceService("panelApiMount", ({ serverConfig, logger, inner }) => {
17
+ if (serverConfig.panel?.enabled !== true) {
18
+ return inner;
19
+ }
20
+ const assets = new PanelAssetStore(panelAssets);
21
+ if (assets.isEmpty()) {
22
+ logger.error(
23
+ new Error(
24
+ "The panel is enabled but this build contains no panel assets — run `bun run --filter=@contember/engine-panel build:assets`. Not serving the panel."
25
+ )
26
+ );
27
+ return inner;
28
+ }
29
+ const basePath = normalizeBasePath(serverConfig.panel.path ?? defaultBasePath);
30
+ return new PanelMount(basePath, assets, new PanelApiControllerFactory(new ConfiguredPanelAccessCheck()));
31
+ }).setupService(
32
+ "application",
33
+ (it, { panelApiMount, tenantApiMiddlewareFactory, contentApiMiddlewareFactory, systemApiMiddlewareFactory }) => {
34
+ if (!(panelApiMount instanceof PanelMount)) {
35
+ return;
36
+ }
37
+ const { basePath, api } = panelApiMount;
38
+ it.addRoute("panel-api", `${basePath}/api/tenant`, api.create(tenantApiMiddlewareFactory.create(), { allowAnonymous: true }));
39
+ it.addRoute(
40
+ "panel-api",
41
+ `${basePath}/api/content/:projectSlug/:stageSlug`,
42
+ api.create(contentApiMiddlewareFactory.create(), { allowAnonymous: false })
43
+ );
44
+ it.addRoute("panel-api", `${basePath}/api/system/:projectSlug`, api.create(systemApiMiddlewareFactory.create(), { allowAnonymous: false }));
45
+ const controller = new PanelController({
46
+ basePath,
47
+ apiBaseUrl: `${basePath}/api`,
48
+ assets: panelApiMount.assets,
49
+ pluginApis: () => panelApiMount.pluginApis
50
+ });
51
+ it.addInternalRoute("panel", `${basePath}{/*path}`, controller.create());
52
+ }
53
+ );
54
+ }
55
+ }
56
+ const normalizeBasePath = (path) => {
57
+ const trimmed = path.trim().replace(/\/+$/, "");
58
+ if (!trimmed.startsWith("/") || trimmed.length < 2) {
59
+ throw new Error(`Invalid CONTEMBER_PANEL_PATH ${JSON.stringify(path)}: expecting an absolute path like "/panel".`);
60
+ }
61
+ return trimmed;
62
+ };
63
+ export {
64
+ PanelPlugin
65
+ };
66
+ //# sourceMappingURL=PanelPlugin.js.map
@@ -0,0 +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;A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W,GAAG,KAAK,QAAQ,SAAS,GAAG;AACnD,UAAM,IAAI,MAAM,gCAAgC,KAAK,UAAU,IAAI,CAAC,6CAA6C;AAAA,EAClH;AACA,SAAO;AACR;"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ var __defProp = Object.defineProperty;
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
6
+ class TtlCache {
7
+ constructor(ttlMs, sweepThreshold = 1e3, now = () => Date.now()) {
8
+ this.ttlMs = ttlMs;
9
+ this.sweepThreshold = sweepThreshold;
10
+ this.now = now;
11
+ __publicField(this, "entries", /* @__PURE__ */ new Map());
12
+ }
13
+ async resolve(key, compute) {
14
+ const cached = this.entries.get(key);
15
+ if (cached && cached.expiresAt > this.now()) {
16
+ return await cached.value;
17
+ }
18
+ const pending = compute();
19
+ this.entries.set(key, { value: pending, expiresAt: this.now() + this.ttlMs });
20
+ try {
21
+ const value = await pending;
22
+ this.entries.set(key, { value: pending, expiresAt: this.now() + this.ttlMs });
23
+ this.sweep(this.now());
24
+ return value;
25
+ } catch (error) {
26
+ if (this.entries.get(key)?.value === pending) {
27
+ this.entries.delete(key);
28
+ }
29
+ throw error;
30
+ }
31
+ }
32
+ get size() {
33
+ return this.entries.size;
34
+ }
35
+ sweep(now) {
36
+ if (this.entries.size < this.sweepThreshold) {
37
+ return;
38
+ }
39
+ for (const [key, entry] of this.entries) {
40
+ if (entry.expiresAt <= now) {
41
+ this.entries.delete(key);
42
+ }
43
+ }
44
+ }
45
+ }
46
+ exports.TtlCache = TtlCache;
47
+ //# sourceMappingURL=TtlCache.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TtlCache.cjs","sources":["../../../../packages/engine-panel/src/TtlCache.ts"],"sourcesContent":["/**\n * A minimal time-boxed memo. Entries are keyed by api key, so the map would otherwise grow with\n * every session the process ever sees — expired entries are swept once the map gets large rather\n * than on a timer.\n */\nexport class TtlCache<T> {\n\tprivate readonly entries = new Map<string, { value: Promise<T>; expiresAt: number }>()\n\n\tconstructor(\n\t\tprivate readonly ttlMs: number,\n\t\tprivate readonly sweepThreshold: number = 1000,\n\t\tprivate readonly now: () => number = () => Date.now(),\n\t) {}\n\n\tpublic async resolve(key: string, compute: () => Promise<T>): Promise<T> {\n\t\tconst cached = this.entries.get(key)\n\t\tif (cached && cached.expiresAt > this.now()) {\n\t\t\treturn await cached.value\n\t\t}\n\t\t// The promise is stored before it settles, so a page's worth of parallel requests shares one\n\t\t// lookup — caching the resolved value instead would let every one of them miss and recompute.\n\t\tconst pending = compute()\n\t\tthis.entries.set(key, { value: pending, expiresAt: this.now() + this.ttlMs })\n\t\ttry {\n\t\t\tconst value = await pending\n\t\t\t// Charge the TTL from when the answer is actually known, not from before the lookup.\n\t\t\tthis.entries.set(key, { value: pending, expiresAt: this.now() + this.ttlMs })\n\t\t\tthis.sweep(this.now())\n\t\t\treturn value\n\t\t} catch (error) {\n\t\t\t// Never memoise a failure — the next caller should try again.\n\t\t\tif (this.entries.get(key)?.value === pending) {\n\t\t\t\tthis.entries.delete(key)\n\t\t\t}\n\t\t\tthrow error\n\t\t}\n\t}\n\n\tpublic get size(): number {\n\t\treturn this.entries.size\n\t}\n\n\tprivate sweep(now: number): void {\n\t\tif (this.entries.size < this.sweepThreshold) {\n\t\t\treturn\n\t\t}\n\t\tfor (const [key, entry] of this.entries) {\n\t\t\tif (entry.expiresAt <= now) {\n\t\t\t\tthis.entries.delete(key)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;AAKO,MAAM,SAAY;AAAA,EAGxB,YACkB,OACA,iBAAyB,KACzB,MAAoB,MAAM,KAAK,OAC/C;AAHgB,SAAA,QAAA;AACA,SAAA,iBAAA;AACA,SAAA,MAAA;AALlB,kBAAA,MAAiB,+BAAc,IAAA,CAAsD;AAAA,EAMlF;AAAA,EAEH,MAAa,QAAQ,KAAa,SAAuC;AACxE,UAAM,SAAS,KAAK,QAAQ,IAAI,GAAG;AACnC,QAAI,UAAU,OAAO,YAAY,KAAK,OAAO;AAC5C,aAAO,MAAM,OAAO;AAAA,IACrB;AAGA,UAAM,UAAU,QAAA;AAChB,SAAK,QAAQ,IAAI,KAAK,EAAE,OAAO,SAAS,WAAW,KAAK,IAAA,IAAQ,KAAK,MAAA,CAAO;AAC5E,QAAI;AACH,YAAM,QAAQ,MAAM;AAEpB,WAAK,QAAQ,IAAI,KAAK,EAAE,OAAO,SAAS,WAAW,KAAK,IAAA,IAAQ,KAAK,MAAA,CAAO;AAC5E,WAAK,MAAM,KAAK,KAAK;AACrB,aAAO;AAAA,IACR,SAAS,OAAO;AAEf,UAAI,KAAK,QAAQ,IAAI,GAAG,GAAG,UAAU,SAAS;AAC7C,aAAK,QAAQ,OAAO,GAAG;AAAA,MACxB;AACA,YAAM;AAAA,IACP;AAAA,EACD;AAAA,EAEA,IAAW,OAAe;AACzB,WAAO,KAAK,QAAQ;AAAA,EACrB;AAAA,EAEQ,MAAM,KAAmB;AAChC,QAAI,KAAK,QAAQ,OAAO,KAAK,gBAAgB;AAC5C;AAAA,IACD;AACA,eAAW,CAAC,KAAK,KAAK,KAAK,KAAK,SAAS;AACxC,UAAI,MAAM,aAAa,KAAK;AAC3B,aAAK,QAAQ,OAAO,GAAG;AAAA,MACxB;AAAA,IACD;AAAA,EACD;AACD;;"}
@@ -0,0 +1,47 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
4
+ class TtlCache {
5
+ constructor(ttlMs, sweepThreshold = 1e3, now = () => Date.now()) {
6
+ this.ttlMs = ttlMs;
7
+ this.sweepThreshold = sweepThreshold;
8
+ this.now = now;
9
+ __publicField(this, "entries", /* @__PURE__ */ new Map());
10
+ }
11
+ async resolve(key, compute) {
12
+ const cached = this.entries.get(key);
13
+ if (cached && cached.expiresAt > this.now()) {
14
+ return await cached.value;
15
+ }
16
+ const pending = compute();
17
+ this.entries.set(key, { value: pending, expiresAt: this.now() + this.ttlMs });
18
+ try {
19
+ const value = await pending;
20
+ this.entries.set(key, { value: pending, expiresAt: this.now() + this.ttlMs });
21
+ this.sweep(this.now());
22
+ return value;
23
+ } catch (error) {
24
+ if (this.entries.get(key)?.value === pending) {
25
+ this.entries.delete(key);
26
+ }
27
+ throw error;
28
+ }
29
+ }
30
+ get size() {
31
+ return this.entries.size;
32
+ }
33
+ sweep(now) {
34
+ if (this.entries.size < this.sweepThreshold) {
35
+ return;
36
+ }
37
+ for (const [key, entry] of this.entries) {
38
+ if (entry.expiresAt <= now) {
39
+ this.entries.delete(key);
40
+ }
41
+ }
42
+ }
43
+ }
44
+ export {
45
+ TtlCache
46
+ };
47
+ //# sourceMappingURL=TtlCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TtlCache.js","sources":["../../../../packages/engine-panel/src/TtlCache.ts"],"sourcesContent":["/**\n * A minimal time-boxed memo. Entries are keyed by api key, so the map would otherwise grow with\n * every session the process ever sees — expired entries are swept once the map gets large rather\n * than on a timer.\n */\nexport class TtlCache<T> {\n\tprivate readonly entries = new Map<string, { value: Promise<T>; expiresAt: number }>()\n\n\tconstructor(\n\t\tprivate readonly ttlMs: number,\n\t\tprivate readonly sweepThreshold: number = 1000,\n\t\tprivate readonly now: () => number = () => Date.now(),\n\t) {}\n\n\tpublic async resolve(key: string, compute: () => Promise<T>): Promise<T> {\n\t\tconst cached = this.entries.get(key)\n\t\tif (cached && cached.expiresAt > this.now()) {\n\t\t\treturn await cached.value\n\t\t}\n\t\t// The promise is stored before it settles, so a page's worth of parallel requests shares one\n\t\t// lookup — caching the resolved value instead would let every one of them miss and recompute.\n\t\tconst pending = compute()\n\t\tthis.entries.set(key, { value: pending, expiresAt: this.now() + this.ttlMs })\n\t\ttry {\n\t\t\tconst value = await pending\n\t\t\t// Charge the TTL from when the answer is actually known, not from before the lookup.\n\t\t\tthis.entries.set(key, { value: pending, expiresAt: this.now() + this.ttlMs })\n\t\t\tthis.sweep(this.now())\n\t\t\treturn value\n\t\t} catch (error) {\n\t\t\t// Never memoise a failure — the next caller should try again.\n\t\t\tif (this.entries.get(key)?.value === pending) {\n\t\t\t\tthis.entries.delete(key)\n\t\t\t}\n\t\t\tthrow error\n\t\t}\n\t}\n\n\tpublic get size(): number {\n\t\treturn this.entries.size\n\t}\n\n\tprivate sweep(now: number): void {\n\t\tif (this.entries.size < this.sweepThreshold) {\n\t\t\treturn\n\t\t}\n\t\tfor (const [key, entry] of this.entries) {\n\t\t\tif (entry.expiresAt <= now) {\n\t\t\t\tthis.entries.delete(key)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;AAKO,MAAM,SAAY;AAAA,EAGxB,YACkB,OACA,iBAAyB,KACzB,MAAoB,MAAM,KAAK,OAC/C;AAHgB,SAAA,QAAA;AACA,SAAA,iBAAA;AACA,SAAA,MAAA;AALlB,kBAAA,MAAiB,+BAAc,IAAA,CAAsD;AAAA,EAMlF;AAAA,EAEH,MAAa,QAAQ,KAAa,SAAuC;AACxE,UAAM,SAAS,KAAK,QAAQ,IAAI,GAAG;AACnC,QAAI,UAAU,OAAO,YAAY,KAAK,OAAO;AAC5C,aAAO,MAAM,OAAO;AAAA,IACrB;AAGA,UAAM,UAAU,QAAA;AAChB,SAAK,QAAQ,IAAI,KAAK,EAAE,OAAO,SAAS,WAAW,KAAK,IAAA,IAAQ,KAAK,MAAA,CAAO;AAC5E,QAAI;AACH,YAAM,QAAQ,MAAM;AAEpB,WAAK,QAAQ,IAAI,KAAK,EAAE,OAAO,SAAS,WAAW,KAAK,IAAA,IAAQ,KAAK,MAAA,CAAO;AAC5E,WAAK,MAAM,KAAK,KAAK;AACrB,aAAO;AAAA,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