@qodalis/cli-server-plugin-portal 0.0.0-stage → 1.0.0-beta.30
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/LICENSE +21 -0
- package/README.md +77 -2
- package/dist/cli-portal-builder.d.ts +67 -0
- package/dist/cli-portal-builder.d.ts.map +1 -0
- package/dist/cli-portal-builder.js +227 -0
- package/dist/cli-portal-builder.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/package-info.d.ts +8 -0
- package/dist/package-info.d.ts.map +1 -0
- package/dist/package-info.js +12 -0
- package/dist/package-info.js.map +1 -0
- package/dist/portal-options.d.ts +39 -0
- package/dist/portal-options.d.ts.map +1 -0
- package/dist/portal-options.js +123 -0
- package/dist/portal-options.js.map +1 -0
- package/dist/site-dir.d.ts +9 -0
- package/dist/site-dir.d.ts.map +1 -0
- package/dist/site-dir.js +70 -0
- package/dist/site-dir.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +47 -5
- package/site/assets/highlight-gcHIXmUK.js +6 -0
- package/site/assets/index-CpTSYSRr.css +1 -0
- package/site/assets/index-GC-2svOH.js +33 -0
- package/site/assets/markdown-DTqQ0Eb-.js +34 -0
- package/site/assets/react-8wdwZ3-9.js +51 -0
- package/site/favicon.svg +5 -0
- package/site/index.html +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Qodalis Solutions
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,78 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @qodalis/cli-server-plugin-portal
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Portal plugin for [Qodalis CLI Server (Node.js)](https://github.com/qodalis-solutions/cli-server-node): your documentation site at one mount. It serves the prebuilt portal site (`@qodalis/cli-server-portal`), which shows the guides of the [docs plugin](../docs/README.md) and the API reference (code samples, "try it") of the [public-api plugin](../public-api/README.md), in one navigation; each section also works alone. Implements the same contract as the .NET (`Qodalis.Cli.Plugin.Portal`) and Python servers.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @qodalis/cli-server-plugin-portal
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { CliDocsBuilder } from '@qodalis/cli-server-plugin-docs';
|
|
15
|
+
import { CliPublicApiBuilder } from '@qodalis/cli-server-plugin-public-api';
|
|
16
|
+
import { CliPortalBuilder } from '@qodalis/cli-server-plugin-portal';
|
|
17
|
+
|
|
18
|
+
const docs = new CliDocsBuilder().addFolder('docs').build();
|
|
19
|
+
const publicApi = new CliPublicApiBuilder().setUsers(users).setOpenApi('openapi.json').build();
|
|
20
|
+
const portal = new CliPortalBuilder()
|
|
21
|
+
.setName('RateBell API')
|
|
22
|
+
.setLogoUrl('/logo.svg')
|
|
23
|
+
.setTheme({ mode: 'system', light: { primary: '#0a7' } })
|
|
24
|
+
.addFooterLink({ label: 'Terms', url: 'https://example.com/terms' })
|
|
25
|
+
.addSection(docs)
|
|
26
|
+
.addSection(publicApi)
|
|
27
|
+
.build();
|
|
28
|
+
|
|
29
|
+
cli.mountPlugin(docs);
|
|
30
|
+
cli.mountPlugin(publicApi);
|
|
31
|
+
cli.mountPlugin(portal); // http://host/qcli/portal
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Routes
|
|
35
|
+
|
|
36
|
+
The portal answers these paths under its mount (GET and HEAD). Away from `/` it also answers every other path under `assets/`, `guides/` and `reference/` with its own 404 `{ "error": "not found" }`; anything else under the mount falls through to your routes. At a root mount (`setPath('/')`) only the paths below are the portal's, and an unknown or missing one falls through, so `GET /v1/rates` or `GET /health` are never shadowed, whatever the order they are registered in.
|
|
37
|
+
|
|
38
|
+
| Path | Answer |
|
|
39
|
+
|---|---|
|
|
40
|
+
| the mount, `/`, `/guides/<slug>`, `/reference`, `/reference/<tag>` | The site's `index.html` (`Cache-Control: no-cache`), its `<base href="/" />` rewritten to the mount |
|
|
41
|
+
| `/portal.json` | Which sections exist, with the name, logo, theme and footer links (below) |
|
|
42
|
+
| `/assets/<file>`, `/favicon.svg` | The site's files (`/assets/` cached for a year: their names change with each build). A missing asset: the portal's 404 `{ "error": "not found" }` away from `/`, falls through to your routes at a root mount; a missing `favicon.svg` always falls through |
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"name": "Documentation",
|
|
47
|
+
"logo": null,
|
|
48
|
+
"theme": { "mode": "system", "dark": {}, "light": {} },
|
|
49
|
+
"footerLinks": [{ "label": "Terms", "url": "https://example.com/terms" }],
|
|
50
|
+
"docs": { "title": "Guides", "pages": "/qcli/docs/pages" },
|
|
51
|
+
"api": { "title": "API reference", "openapi": "/qcli/api/openapi.json", "swagger": "/qcli/api/swagger" }
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`docs` and `api` are `null` when that plugin's section was not added (with neither, the site shows "Nothing published yet"). No sign-in is needed, on a protected server too, under `/api` as well: the portal declares its pages, `portal.json`, `/assets/*`, `/guides/*` and `/reference/*` as public routes. The server hands such requests to the portal alone, never to one of your routes or a CLI route, and every path under those prefixes the portal does not serve is its own 404 `{ "error": "not found" }` (at a root mount, unknown paths still fall through to your routes).
|
|
56
|
+
|
|
57
|
+
On a protected server, a request to a public route of the portal, docs or public-api plugin under `/api` is answered inside the server's auth gate, which runs first. Middleware you add to the app after `createCliServer` (a rate limiter, request logging, compression) does not run for it; add such middleware before the CLI server's app, for example on a parent app (`outer.use(limiter); outer.use(cli.app)`).
|
|
58
|
+
|
|
59
|
+
**The mount must be a path your app does not use for its own routes.** A mount holding the CLI's routes or inside them (`/api`, `/ws`, `/api/v1`, `/api/v1/qcli/...`) is refused with `invalid portal path: <path>`.
|
|
60
|
+
|
|
61
|
+
When your app is mounted under a path (a parent Express app's `app.use('/prefix', cli.app)`), that prefix is added to the `portal.json` URLs and to `<base href>`. A prefix starting with `//` or `/\`, or holding whitespace or control characters (it would point them at another host) answers 400 `{ "error": "invalid path base" }` on the pages and `portal.json`.
|
|
62
|
+
|
|
63
|
+
## The site
|
|
64
|
+
|
|
65
|
+
The site is found as on the .NET server: `setSiteDir(dir)` alone when given (no other location is tried); otherwise the installed `@qodalis/cli-server-portal` package, then the sibling `cli-server-dashboard/portal/dist` (only when this package is inside a git checkout of cli-server-node, never next to an installed package), then the copy bundled into this package (`site/`, made by `npm run build`; `prepublishOnly` fails when there is no site to bundle). Without one, `[qcli] portal site not found; the portal is not served` is logged once and nothing is served, `portal.json` included.
|
|
66
|
+
|
|
67
|
+
## Builder
|
|
68
|
+
|
|
69
|
+
| Method | Default | Description |
|
|
70
|
+
|---|---|---|
|
|
71
|
+
| `setPath(path)` | `/qcli/portal` | The mount: `/` or `/segment[/segment]` (`invalid portal path: <path>`) |
|
|
72
|
+
| `setName(name)` | `Documentation` | 1-80 characters without control characters |
|
|
73
|
+
| `setLogoUrl(url)` | none | An http(s) URL, a root-relative path or a base64 `data:image/…` URL (up to 200 000 characters) |
|
|
74
|
+
| `setTheme({ mode, dark, light })` | `system`, no colours | The admin dashboard's 21 colour tokens (`primary`, `background`, `text`, …), as the admin theme accepts them |
|
|
75
|
+
| `addFooterLink({ label, url })` | | At most 20; `label` 1-80 characters, `url` http(s) or root-relative |
|
|
76
|
+
| `addSection(plugin)` | | The docs or public-api plugin (its `portalSection`); one of each kind (`portal section already registered: <kind>`) |
|
|
77
|
+
| `setSiteDir(dir)` | resolved | The site's directory |
|
|
78
|
+
| `build()` | | `{ prefix, router, cliRoutes: false, publicRoutes, installedPlugin }`; throws on invalid options |
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import type { CliInstalledPlugin } from '@qodalis/cli-server-abstractions';
|
|
3
|
+
import { PortalLink, PortalSection, PortalTheme } from './portal-options';
|
|
4
|
+
export declare const DEFAULT_PORTAL_PATH = "/qcli/portal";
|
|
5
|
+
export declare const DEFAULT_PORTAL_NAME = "Documentation";
|
|
6
|
+
export declare const PORTAL_SITE_NOT_FOUND = "[qcli] portal site not found; the portal is not served";
|
|
7
|
+
/** The answer for a path base that would make `portal.json` URLs and `<base href>` point at another host. */
|
|
8
|
+
export declare const INVALID_PATH_BASE = "invalid path base";
|
|
9
|
+
/**
|
|
10
|
+
* False for a path base (the path an app is mounted under) starting with `//` or `/\\`, or
|
|
11
|
+
* holding whitespace or control characters: each could point URLs at another host.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isSafePathPrefix(prefix: string): boolean;
|
|
14
|
+
export interface PortalPluginResult {
|
|
15
|
+
/** The mount (default `/qcli/portal`; `/` serves the portal at the root). */
|
|
16
|
+
prefix: string;
|
|
17
|
+
/** Only the portal's fixed paths; anything else falls through to the host. */
|
|
18
|
+
router: Router;
|
|
19
|
+
/** Host routes: its prefix is not a CLI route. */
|
|
20
|
+
cliRoutes: false;
|
|
21
|
+
/** The portal's fixed paths stay public on a protected server (`mountPlugin` reads them). */
|
|
22
|
+
publicRoutes: string[];
|
|
23
|
+
installedPlugin: CliInstalledPlugin;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Fluent builder for the portal plugin: the prebuilt portal site (`@qodalis/cli-server-portal`)
|
|
27
|
+
* at one mount, showing the guides of the docs plugin and the API reference of the
|
|
28
|
+
* public-api plugin, with `portal.json` telling the site which sections exist.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const portal = new CliPortalBuilder()
|
|
33
|
+
* .setName('RateBell API')
|
|
34
|
+
* .addSection(docs)
|
|
35
|
+
* .addSection(publicApi)
|
|
36
|
+
* .build();
|
|
37
|
+
* mountPlugin(portal); // http://host/qcli/portal
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare class CliPortalBuilder {
|
|
41
|
+
private path;
|
|
42
|
+
private name;
|
|
43
|
+
private logo?;
|
|
44
|
+
private theme?;
|
|
45
|
+
private readonly footerLinks;
|
|
46
|
+
private readonly sections;
|
|
47
|
+
private siteDir?;
|
|
48
|
+
/** The mount (default `/qcli/portal`); `/` mounts the portal at the root, next to the host's routes. */
|
|
49
|
+
setPath(path: string): this;
|
|
50
|
+
/** The site's name (default `Documentation`), 1-80 characters. */
|
|
51
|
+
setName(name: string): this;
|
|
52
|
+
/** An http(s) URL, a root-relative path or a base64 `data:image/…` URL. */
|
|
53
|
+
setLogoUrl(url: string): this;
|
|
54
|
+
/** Mode (default `system`) and colours, with the admin dashboard's tokens. */
|
|
55
|
+
setTheme(theme: PortalTheme): this;
|
|
56
|
+
/** A footer link (at most 20): an http(s) URL or a root-relative path. */
|
|
57
|
+
addFooterLink(link: PortalLink): this;
|
|
58
|
+
/** The section of the docs or public-api plugin (its `portalSection`); one of each kind. */
|
|
59
|
+
addSection(plugin: {
|
|
60
|
+
portalSection: PortalSection;
|
|
61
|
+
}): this;
|
|
62
|
+
/** The site's directory (the one holding `index.html`), instead of the resolved one. */
|
|
63
|
+
setSiteDir(dir: string): this;
|
|
64
|
+
/** Validates the options (startup errors are thrown here) and reads the site once. */
|
|
65
|
+
build(): PortalPluginResult;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=cli-portal-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-portal-builder.d.ts","sourceRoot":"","sources":["../cli-portal-builder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAmC,MAAM,SAAS,CAAC;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EACH,UAAU,EACV,aAAa,EACb,WAAW,EAMd,MAAM,kBAAkB,CAAC;AAI1B,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AAClD,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AACnD,eAAO,MAAM,qBAAqB,2DAA2D,CAAC;AAM9F,6GAA6G;AAC7G,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AAErD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAGxD;AAeD,MAAM,WAAW,kBAAkB;IAC/B,6EAA6E;IAC7E,MAAM,EAAE,MAAM,CAAC;IACf,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;IACf,kDAAkD;IAClD,SAAS,EAAE,KAAK,CAAC;IACjB,6FAA6F;IAC7F,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,eAAe,EAAE,kBAAkB,CAAC;CACvC;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,gBAAgB;IACzB,OAAO,CAAC,IAAI,CAAuB;IACnC,OAAO,CAAC,IAAI,CAAuB;IACnC,OAAO,CAAC,IAAI,CAAC,CAAS;IACtB,OAAO,CAAC,KAAK,CAAC,CAAc;IAC5B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuB;IAChD,OAAO,CAAC,OAAO,CAAC,CAAS;IAEzB,wGAAwG;IACxG,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK3B,kEAAkE;IAClE,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK3B,2EAA2E;IAC3E,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAK7B,8EAA8E;IAC9E,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAKlC,0EAA0E;IAC1E,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAKrC,4FAA4F;IAC5F,UAAU,CAAC,MAAM,EAAE;QAAE,aAAa,EAAE,aAAa,CAAA;KAAE,GAAG,IAAI;IAK1D,wFAAwF;IACxF,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAK7B,sFAAsF;IACtF,KAAK,IAAI,kBAAkB;CAgI9B"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CliPortalBuilder = exports.INVALID_PATH_BASE = exports.PORTAL_SITE_NOT_FOUND = exports.DEFAULT_PORTAL_NAME = exports.DEFAULT_PORTAL_PATH = void 0;
|
|
4
|
+
exports.isSafePathPrefix = isSafePathPrefix;
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const express_1 = require("express");
|
|
8
|
+
const portal_options_1 = require("./portal-options");
|
|
9
|
+
const site_dir_1 = require("./site-dir");
|
|
10
|
+
const package_info_1 = require("./package-info");
|
|
11
|
+
exports.DEFAULT_PORTAL_PATH = '/qcli/portal';
|
|
12
|
+
exports.DEFAULT_PORTAL_NAME = 'Documentation';
|
|
13
|
+
exports.PORTAL_SITE_NOT_FOUND = '[qcli] portal site not found; the portal is not served';
|
|
14
|
+
/** The site's own routes (relative to the mount): each answers the site's `index.html`. */
|
|
15
|
+
const SITE_ROUTES = ['/', '/guides/:slug', '/reference', '/reference/:tag'];
|
|
16
|
+
const BASE_TAG = /<base href="\/"\s*\/?>/;
|
|
17
|
+
/** The answer for a path base that would make `portal.json` URLs and `<base href>` point at another host. */
|
|
18
|
+
exports.INVALID_PATH_BASE = 'invalid path base';
|
|
19
|
+
/**
|
|
20
|
+
* False for a path base (the path an app is mounted under) starting with `//` or `/\\`, or
|
|
21
|
+
* holding whitespace or control characters: each could point URLs at another host.
|
|
22
|
+
*/
|
|
23
|
+
function isSafePathPrefix(prefix) {
|
|
24
|
+
// whitespace and control characters too: browsers drop them, so `/\t/host` reads as `//host`
|
|
25
|
+
return !prefix.startsWith('//') && !prefix.startsWith('/\\') && !/[\s\u0000-\u001f\u007f]/.test(prefix);
|
|
26
|
+
}
|
|
27
|
+
/** The CLI's own route prefixes (core's); a portal mount must neither hold nor sit inside one. */
|
|
28
|
+
const CLI_PREFIXES = ['/api/qcli', '/api/v1/qcli', '/api/v2/qcli', '/api/cli', '/ws/qcli', '/ws/v1/qcli'];
|
|
29
|
+
/** True for a mount (other than `/`) that holds CLI routes (`/api`, `/ws`) or lies inside them. */
|
|
30
|
+
function holdsCliRoutes(path) {
|
|
31
|
+
if (path === '/')
|
|
32
|
+
return false;
|
|
33
|
+
const mount = path.toLowerCase();
|
|
34
|
+
return CLI_PREFIXES.some((cli) => cli === mount || cli.startsWith(`${mount}/`) || mount.startsWith(`${cli}/`));
|
|
35
|
+
}
|
|
36
|
+
const escapeAttribute = (value) => value.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
|
37
|
+
/**
|
|
38
|
+
* Fluent builder for the portal plugin: the prebuilt portal site (`@qodalis/cli-server-portal`)
|
|
39
|
+
* at one mount, showing the guides of the docs plugin and the API reference of the
|
|
40
|
+
* public-api plugin, with `portal.json` telling the site which sections exist.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const portal = new CliPortalBuilder()
|
|
45
|
+
* .setName('RateBell API')
|
|
46
|
+
* .addSection(docs)
|
|
47
|
+
* .addSection(publicApi)
|
|
48
|
+
* .build();
|
|
49
|
+
* mountPlugin(portal); // http://host/qcli/portal
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
class CliPortalBuilder {
|
|
53
|
+
path = exports.DEFAULT_PORTAL_PATH;
|
|
54
|
+
name = exports.DEFAULT_PORTAL_NAME;
|
|
55
|
+
logo;
|
|
56
|
+
theme;
|
|
57
|
+
footerLinks = [];
|
|
58
|
+
sections = [];
|
|
59
|
+
siteDir;
|
|
60
|
+
/** The mount (default `/qcli/portal`); `/` mounts the portal at the root, next to the host's routes. */
|
|
61
|
+
setPath(path) {
|
|
62
|
+
this.path = path;
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
/** The site's name (default `Documentation`), 1-80 characters. */
|
|
66
|
+
setName(name) {
|
|
67
|
+
this.name = name;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
/** An http(s) URL, a root-relative path or a base64 `data:image/…` URL. */
|
|
71
|
+
setLogoUrl(url) {
|
|
72
|
+
this.logo = url;
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
/** Mode (default `system`) and colours, with the admin dashboard's tokens. */
|
|
76
|
+
setTheme(theme) {
|
|
77
|
+
this.theme = theme;
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
/** A footer link (at most 20): an http(s) URL or a root-relative path. */
|
|
81
|
+
addFooterLink(link) {
|
|
82
|
+
this.footerLinks.push(link);
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
/** The section of the docs or public-api plugin (its `portalSection`); one of each kind. */
|
|
86
|
+
addSection(plugin) {
|
|
87
|
+
this.sections.push(plugin.portalSection);
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
/** The site's directory (the one holding `index.html`), instead of the resolved one. */
|
|
91
|
+
setSiteDir(dir) {
|
|
92
|
+
this.siteDir = dir;
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
/** Validates the options (startup errors are thrown here) and reads the site once. */
|
|
96
|
+
build() {
|
|
97
|
+
if (!(0, portal_options_1.isValidPortalPath)(this.path) || holdsCliRoutes(this.path)) {
|
|
98
|
+
throw new Error(`invalid portal path: ${this.path}`);
|
|
99
|
+
}
|
|
100
|
+
const mount = this.path;
|
|
101
|
+
const document = {
|
|
102
|
+
name: (0, portal_options_1.validateName)(this.name),
|
|
103
|
+
logo: (0, portal_options_1.validateLogo)(this.logo),
|
|
104
|
+
theme: (0, portal_options_1.validateTheme)(this.theme),
|
|
105
|
+
footerLinks: (0, portal_options_1.validateFooterLinks)(this.footerLinks),
|
|
106
|
+
docs: null,
|
|
107
|
+
api: null,
|
|
108
|
+
};
|
|
109
|
+
const seen = new Set();
|
|
110
|
+
for (const section of this.sections) {
|
|
111
|
+
if (seen.has(section.kind))
|
|
112
|
+
throw new Error(`portal section already registered: ${section.kind}`);
|
|
113
|
+
seen.add(section.kind);
|
|
114
|
+
if (section.kind === 'docs') {
|
|
115
|
+
document.docs = { title: section.title, pages: `${section.basePath}/pages` };
|
|
116
|
+
}
|
|
117
|
+
else if (section.kind === 'api') {
|
|
118
|
+
document.api = {
|
|
119
|
+
title: section.title,
|
|
120
|
+
openapi: `${section.basePath}/openapi.json`,
|
|
121
|
+
swagger: `${section.basePath}/swagger`,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
throw new Error(`unknown portal section: ${String(section.kind)}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// `portal.json` per path prefix (the app mounted under a parent path); usually only ''
|
|
129
|
+
const portalJson = new Map();
|
|
130
|
+
const portalJsonFor = (prefix) => {
|
|
131
|
+
let json = portalJson.get(prefix);
|
|
132
|
+
if (json === undefined) {
|
|
133
|
+
json = JSON.stringify({
|
|
134
|
+
...document,
|
|
135
|
+
docs: document.docs && { ...document.docs, pages: prefix + document.docs.pages },
|
|
136
|
+
api: document.api && {
|
|
137
|
+
...document.api,
|
|
138
|
+
openapi: prefix + document.api.openapi,
|
|
139
|
+
swagger: prefix + document.api.swagger,
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
if (portalJson.size < 16)
|
|
143
|
+
portalJson.set(prefix, json);
|
|
144
|
+
}
|
|
145
|
+
return json;
|
|
146
|
+
};
|
|
147
|
+
// Only the portal's own paths, GET and HEAD; anything else falls through (the host's routes, a 404)
|
|
148
|
+
const router = (0, express_1.Router)({ caseSensitive: true });
|
|
149
|
+
const result = {
|
|
150
|
+
prefix: mount,
|
|
151
|
+
router,
|
|
152
|
+
cliRoutes: false,
|
|
153
|
+
publicRoutes: [],
|
|
154
|
+
installedPlugin: package_info_1.portalInstalledPlugin,
|
|
155
|
+
};
|
|
156
|
+
const siteDir = (0, site_dir_1.resolvePortalSiteDir)(this.siteDir);
|
|
157
|
+
if (!siteDir) {
|
|
158
|
+
console.warn(exports.PORTAL_SITE_NOT_FOUND);
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
// The site's single `<base href="/" />` points at the mount (and the app's path prefix)
|
|
162
|
+
const [htmlBefore, htmlAfter] = (() => {
|
|
163
|
+
const source = (0, fs_1.readFileSync)((0, path_1.join)(siteDir, 'index.html'), 'utf8');
|
|
164
|
+
const match = BASE_TAG.exec(source);
|
|
165
|
+
return match ? [source.slice(0, match.index), source.slice(match.index + match[0].length)] : [source, undefined];
|
|
166
|
+
})();
|
|
167
|
+
const mountHref = mount === '/' ? '/' : `${mount}/`;
|
|
168
|
+
const htmlFor = (prefix) => htmlAfter === undefined ? htmlBefore : `${htmlBefore}<base href="${escapeAttribute(prefix + mountHref)}" />${htmlAfter}`;
|
|
169
|
+
// The path the app itself is mounted under (`req.baseUrl` holds it before the portal's mount)
|
|
170
|
+
const pathPrefix = (req) => (mount === '/' ? req.baseUrl : req.baseUrl.slice(0, req.baseUrl.length - mount.length));
|
|
171
|
+
const assetsDir = (0, path_1.resolve)(siteDir, 'assets');
|
|
172
|
+
const isFileIn = (dir, name) => {
|
|
173
|
+
if (!name || name.startsWith('.') || name.includes('/') || name.includes('\\'))
|
|
174
|
+
return false;
|
|
175
|
+
const file = (0, path_1.join)(dir, name);
|
|
176
|
+
return (0, fs_1.existsSync)(file) && (0, fs_1.statSync)(file).isFile();
|
|
177
|
+
};
|
|
178
|
+
router.get(SITE_ROUTES, (req, res) => {
|
|
179
|
+
const prefix = pathPrefix(req);
|
|
180
|
+
if (!isSafePathPrefix(prefix))
|
|
181
|
+
return void res.setHeader('Cache-Control', 'no-cache').status(400).json({ error: exports.INVALID_PATH_BASE });
|
|
182
|
+
res.setHeader('Cache-Control', 'no-cache');
|
|
183
|
+
res.type('html').send(htmlFor(prefix));
|
|
184
|
+
});
|
|
185
|
+
router.get('/portal.json', (req, res) => {
|
|
186
|
+
const prefix = pathPrefix(req);
|
|
187
|
+
if (!isSafePathPrefix(prefix))
|
|
188
|
+
return void res.setHeader('Cache-Control', 'no-cache').status(400).json({ error: exports.INVALID_PATH_BASE });
|
|
189
|
+
res.setHeader('Cache-Control', 'no-cache');
|
|
190
|
+
res.type('json').send(portalJsonFor(prefix));
|
|
191
|
+
});
|
|
192
|
+
router.get('/favicon.svg', (req, res, next) => {
|
|
193
|
+
if (!isFileIn(siteDir, 'favicon.svg')) {
|
|
194
|
+
next();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
res.sendFile((0, path_1.join)(siteDir, 'favicon.svg'), (err) => err && !res.headersSent && next());
|
|
198
|
+
});
|
|
199
|
+
router.get('/assets/:file', (req, res, next) => {
|
|
200
|
+
const file = req.params.file;
|
|
201
|
+
if (!isFileIn(assetsDir, file)) {
|
|
202
|
+
next();
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
|
|
206
|
+
res.sendFile((0, path_1.join)(assetsDir, file), (err) => err && !res.headersSent && next());
|
|
207
|
+
});
|
|
208
|
+
// Every path under a prefix the gate opens is the portal's: its own 404, never a host
|
|
209
|
+
// route behind it. At the root mount (never under /api, so nothing is opened there)
|
|
210
|
+
// unknown paths keep falling through to the host.
|
|
211
|
+
if (mount !== '/') {
|
|
212
|
+
router.get(['/assets', '/assets/*', '/guides', '/guides/*', '/reference/*'], (_req, res) => {
|
|
213
|
+
res.setHeader('Cache-Control', 'no-cache').status(404).json({ error: 'not found' });
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
const at = (p) => (mount === '/' ? p : `${mount}${p}`);
|
|
217
|
+
const fixed = ['', '/', '/reference', '/portal.json', '/favicon.svg'].map((p) => (p === '' ? mount : at(p)));
|
|
218
|
+
// public on a protected server, under /api too (the gate never opens a CLI route this way)
|
|
219
|
+
result.publicRoutes = [
|
|
220
|
+
...fixed.flatMap((p) => [`GET ${p}`, `HEAD ${p}`]),
|
|
221
|
+
...['/assets/*', '/guides/*', '/reference/*'].map((p) => `GET ${at(p)}`),
|
|
222
|
+
];
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
exports.CliPortalBuilder = CliPortalBuilder;
|
|
227
|
+
//# sourceMappingURL=cli-portal-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-portal-builder.js","sourceRoot":"","sources":["../cli-portal-builder.ts"],"names":[],"mappings":";;;AAgCA,4CAGC;AAnCD,2BAAwD;AACxD,+BAAqC;AACrC,qCAAkE;AAElE,qDAS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E,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC3E,CAAC;QACF,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AApLD,4CAoLC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { CliPortalBuilder, PortalPluginResult, DEFAULT_PORTAL_PATH, DEFAULT_PORTAL_NAME, PORTAL_SITE_NOT_FOUND, isSafePathPrefix, INVALID_PATH_BASE, } from './cli-portal-builder';
|
|
2
|
+
export { PortalTheme, PortalThemeColors, PortalThemeMode, PortalThemeToken, PortalLink, PortalSection, PORTAL_THEME_TOKENS, MAX_FOOTER_LINKS, isPortalColor, isValidPortalPath, } from './portal-options';
|
|
3
|
+
export { resolvePortalSiteDir } from './site-dir';
|
|
4
|
+
export { portalInstalledPlugin, PORTAL_PLUGIN_ID } from './package-info';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,GACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACH,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,iBAAiB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PORTAL_PLUGIN_ID = exports.portalInstalledPlugin = exports.resolvePortalSiteDir = exports.isValidPortalPath = exports.isPortalColor = exports.MAX_FOOTER_LINKS = exports.PORTAL_THEME_TOKENS = exports.INVALID_PATH_BASE = exports.isSafePathPrefix = exports.PORTAL_SITE_NOT_FOUND = exports.DEFAULT_PORTAL_NAME = exports.DEFAULT_PORTAL_PATH = exports.CliPortalBuilder = void 0;
|
|
4
|
+
var cli_portal_builder_1 = require("./cli-portal-builder");
|
|
5
|
+
Object.defineProperty(exports, "CliPortalBuilder", { enumerable: true, get: function () { return cli_portal_builder_1.CliPortalBuilder; } });
|
|
6
|
+
Object.defineProperty(exports, "DEFAULT_PORTAL_PATH", { enumerable: true, get: function () { return cli_portal_builder_1.DEFAULT_PORTAL_PATH; } });
|
|
7
|
+
Object.defineProperty(exports, "DEFAULT_PORTAL_NAME", { enumerable: true, get: function () { return cli_portal_builder_1.DEFAULT_PORTAL_NAME; } });
|
|
8
|
+
Object.defineProperty(exports, "PORTAL_SITE_NOT_FOUND", { enumerable: true, get: function () { return cli_portal_builder_1.PORTAL_SITE_NOT_FOUND; } });
|
|
9
|
+
Object.defineProperty(exports, "isSafePathPrefix", { enumerable: true, get: function () { return cli_portal_builder_1.isSafePathPrefix; } });
|
|
10
|
+
Object.defineProperty(exports, "INVALID_PATH_BASE", { enumerable: true, get: function () { return cli_portal_builder_1.INVALID_PATH_BASE; } });
|
|
11
|
+
var portal_options_1 = require("./portal-options");
|
|
12
|
+
Object.defineProperty(exports, "PORTAL_THEME_TOKENS", { enumerable: true, get: function () { return portal_options_1.PORTAL_THEME_TOKENS; } });
|
|
13
|
+
Object.defineProperty(exports, "MAX_FOOTER_LINKS", { enumerable: true, get: function () { return portal_options_1.MAX_FOOTER_LINKS; } });
|
|
14
|
+
Object.defineProperty(exports, "isPortalColor", { enumerable: true, get: function () { return portal_options_1.isPortalColor; } });
|
|
15
|
+
Object.defineProperty(exports, "isValidPortalPath", { enumerable: true, get: function () { return portal_options_1.isValidPortalPath; } });
|
|
16
|
+
var site_dir_1 = require("./site-dir");
|
|
17
|
+
Object.defineProperty(exports, "resolvePortalSiteDir", { enumerable: true, get: function () { return site_dir_1.resolvePortalSiteDir; } });
|
|
18
|
+
var package_info_1 = require("./package-info");
|
|
19
|
+
Object.defineProperty(exports, "portalInstalledPlugin", { enumerable: true, get: function () { return package_info_1.portalInstalledPlugin; } });
|
|
20
|
+
Object.defineProperty(exports, "PORTAL_PLUGIN_ID", { enumerable: true, get: function () { return package_info_1.PORTAL_PLUGIN_ID; } });
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,2DAQ8B;AAP1B,sHAAA,gBAAgB,OAAA;AAEhB,yHAAA,mBAAmB,OAAA;AACnB,yHAAA,mBAAmB,OAAA;AACnB,2HAAA,qBAAqB,OAAA;AACrB,sHAAA,gBAAgB,OAAA;AAChB,uHAAA,iBAAiB,OAAA;AAErB,mDAW0B;AAJtB,qHAAA,mBAAmB,OAAA;AACnB,kHAAA,gBAAgB,OAAA;AAChB,+GAAA,aAAa,OAAA;AACb,mHAAA,iBAAiB,OAAA;AAErB,uCAAkD;AAAzC,gHAAA,oBAAoB,OAAA;AAC7B,+CAAyE;AAAhE,qHAAA,qBAAqB,OAAA;AAAE,gHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CliInstalledPlugin } from '@qodalis/cli-server-abstractions';
|
|
2
|
+
/** This package's id (npm name). */
|
|
3
|
+
export declare const PORTAL_PLUGIN_ID = "@qodalis/cli-server-plugin-portal";
|
|
4
|
+
/** This package, as listed among the server's installed plugins. */
|
|
5
|
+
export declare const portalInstalledPlugin: CliInstalledPlugin & {
|
|
6
|
+
icon?: string;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=package-info.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-info.d.ts","sourceRoot":"","sources":["../package-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAuB,MAAM,kCAAkC,CAAC;AAE3F,oCAAoC;AACpC,eAAO,MAAM,gBAAgB,sCAAsC,CAAC;AAEpE,oEAAoE;AACpE,eAAO,MAAM,qBAAqB,EAAE,kBAAkB,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAGvE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.portalInstalledPlugin = exports.PORTAL_PLUGIN_ID = void 0;
|
|
4
|
+
const cli_server_abstractions_1 = require("@qodalis/cli-server-abstractions");
|
|
5
|
+
/** This package's id (npm name). */
|
|
6
|
+
exports.PORTAL_PLUGIN_ID = '@qodalis/cli-server-plugin-portal';
|
|
7
|
+
/** This package, as listed among the server's installed plugins. */
|
|
8
|
+
exports.portalInstalledPlugin = {
|
|
9
|
+
...((0, cli_server_abstractions_1.readInstalledPlugin)(__dirname, exports.PORTAL_PLUGIN_ID, 'Portal') ?? { id: exports.PORTAL_PLUGIN_ID, name: 'Portal' }),
|
|
10
|
+
icon: '🧭',
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=package-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-info.js","sourceRoot":"","sources":["../package-info.ts"],"names":[],"mappings":";;;AAAA,8EAA2F;AAE3F,oCAAoC;AACvB,QAAA,gBAAgB,GAAG,mCAAmC,CAAC;AAEpE,oEAAoE;AACvD,QAAA,qBAAqB,GAA2C;IACzE,GAAG,CAAC,IAAA,6CAAmB,EAAC,SAAS,EAAE,wBAAgB,EAAE,QAAQ,CAAC,IAAI,EAAE,EAAE,EAAE,wBAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC3G,IAAI,EAAE,IAAI;CACb,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The portal's options and their validation (the admin plugin's rules): name, logo,
|
|
3
|
+
* theme colours, footer links and the mount path.
|
|
4
|
+
*/
|
|
5
|
+
/** Colour tokens of the portal, the dashboard's (the same names on every server). */
|
|
6
|
+
export declare const PORTAL_THEME_TOKENS: readonly ["primary", "primaryHover", "onPrimary", "accent", "background", "backgroundAccent", "sidebar", "surface", "popover", "control", "controlHover", "border", "overlay", "heading", "text", "muted", "subtle", "success", "warning", "error", "info"];
|
|
7
|
+
export type PortalThemeToken = (typeof PORTAL_THEME_TOKENS)[number];
|
|
8
|
+
export type PortalThemeColors = Partial<Record<PortalThemeToken, string>>;
|
|
9
|
+
export type PortalThemeMode = 'dark' | 'light' | 'system';
|
|
10
|
+
export interface PortalTheme {
|
|
11
|
+
/** Default `system`. */
|
|
12
|
+
mode?: PortalThemeMode;
|
|
13
|
+
dark?: PortalThemeColors;
|
|
14
|
+
light?: PortalThemeColors;
|
|
15
|
+
}
|
|
16
|
+
export interface PortalLink {
|
|
17
|
+
label: string;
|
|
18
|
+
/** An http(s) URL or a root-relative path. */
|
|
19
|
+
url: string;
|
|
20
|
+
}
|
|
21
|
+
/** A plugin's section (the docs and public-api plugins' `portalSection`). */
|
|
22
|
+
export interface PortalSection {
|
|
23
|
+
kind: 'docs' | 'api';
|
|
24
|
+
title: string;
|
|
25
|
+
basePath: string;
|
|
26
|
+
}
|
|
27
|
+
export declare const MAX_FOOTER_LINKS = 20;
|
|
28
|
+
export declare function isPortalColor(value: unknown): value is string;
|
|
29
|
+
/** True for `/`, or `/segment[/segment...]` without a trailing `/`. */
|
|
30
|
+
export declare function isValidPortalPath(path: unknown): path is string;
|
|
31
|
+
export declare function validateName(name: unknown): string;
|
|
32
|
+
export declare function validateLogo(logo: unknown): string | null;
|
|
33
|
+
export declare function validateTheme(theme: PortalTheme | undefined): {
|
|
34
|
+
mode: PortalThemeMode;
|
|
35
|
+
dark: PortalThemeColors;
|
|
36
|
+
light: PortalThemeColors;
|
|
37
|
+
};
|
|
38
|
+
export declare function validateFooterLinks(links: PortalLink[]): PortalLink[];
|
|
39
|
+
//# sourceMappingURL=portal-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal-options.d.ts","sourceRoot":"","sources":["../portal-options.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qFAAqF;AACrF,eAAO,MAAM,mBAAmB,6PAsBtB,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AACpE,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC,CAAC;AAC1E,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE1D,MAAM,WAAW,WAAW;IACxB,wBAAwB;IACxB,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB,KAAK,CAAC,EAAE,iBAAiB,CAAC;CAC7B;AAED,MAAM,WAAW,UAAU;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,8CAA8C;IAC9C,GAAG,EAAE,MAAM,CAAC;CACf;AAED,6EAA6E;AAC7E,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAiBnC,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAI7D;AAED,uEAAuE;AACvE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAE/D;AAiBD,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,MAA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