@solobrand/plugins 0.0.0-stage → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,29 @@
1
- # Temporary Holding Version
1
+ # @solobrand/plugins
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Plugins and themes inside an app (`plugin@1`, `theme@1`): manifests, dependency resolution,
4
+ activation without a rebuild, settings with encrypted secrets, and the provider that gates every
5
+ plugin route and listener on its state.
6
+
7
+ Part of the [SoloBrand framework](../../README.md). Public API: `src/index.ts`. Guide:
8
+ [docs/es/plugins.md](../../docs/es/plugins.md) · [docs/en/plugins.md](../../docs/en/plugins.md).
9
+
10
+ ```ts
11
+ import { pluginsProvider } from '@solobrand/plugins';
12
+ import { plugins } from '../app/plugins.generated.js'; // written by `sb generate`
13
+
14
+ pluginsProvider({ set: plugins, authorize: (ctx) => isAdministrator(ctx.user), adminMiddleware: ['auth'] });
15
+ ```
16
+
17
+ ## Status
18
+
19
+ - **Implemented**: `plugin@1` / `theme@1` manifests (zod, translated issues), semver ranges,
20
+ resolution (target app and version, framework, dependencies, cycles, order), `definePlugins`
21
+ (re-checked at boot, migration names carry the module prefix), the registry over
22
+ `_plugin_states` (activate/deactivate both ways, settings validated, secrets AES-GCM-256 with
23
+ an HKDF key from `APP_KEY`), `pluginsProvider` (`plugin:<id>`, gated routes and listeners,
24
+ `/api/plugins/active`, admin routes only with `authorize`). The generator writes the
25
+ composition; `sb make:plugin` / `sb make:theme` scaffold.
26
+ - **Tested**: 87 tests here (99.7 % lines), end to end through the real kernel, db and
27
+ validator; plus the generator's composition (including importing what it writes) and the CLI.
28
+ - **Left**: the SoloBrand marketplace that installs a plugin into a hosted app (P24-116) and
29
+ updating a modified app with a three-way merge (P24-117) live in SoloBrand, not here.
@@ -0,0 +1,60 @@
1
+ /**
2
+ * The composition: what the generator writes into `app/plugins.generated.ts` from every
3
+ * `plugins/<id>/plugin.json` and `themes/<id>/theme.json`. `definePlugins` checks it again
4
+ * at boot (manifests, fit with the app, dependencies, migration names), so a hand-edited or
5
+ * stale composition fails the boot instead of half-working.
6
+ */
7
+ import { type Application, type Listener } from '@solobrand/core';
8
+ import type { Migration } from '@solobrand/db';
9
+ import type { Router } from '@solobrand/http';
10
+ import { type ManifestIssue, type PluginManifest, type ThemeManifest } from './manifest.js';
11
+ import { type ResolveContext } from './resolve.js';
12
+ /** What a plugin's `app/index.ts` exports by default. */
13
+ export interface AppPluginEntry {
14
+ /** Its routes. They are mounted behind `plugin:<id>`: inactive ⇒ 404, without the plugin doing anything. */
15
+ readonly routes?: (router: Router) => void;
16
+ /** Event → listener. A listener only runs while the plugin is active. */
17
+ readonly listeners?: Readonly<Record<string, Listener<never>>>;
18
+ /** Bindings, always registered. They must not do work by themselves (an inactive plugin still registers). */
19
+ readonly register?: (app: Application) => void;
20
+ }
21
+ /** Identity helper for a plugin's `app/index.ts`: `export default defineAppPlugin({ routes })`. */
22
+ export declare function defineAppPlugin(entry: AppPluginEntry): AppPluginEntry;
23
+ /** A plugin's or theme's `lang/es.json` and `lang/en.json`. */
24
+ export interface PluginMessages {
25
+ readonly es: Readonly<Record<string, string>>;
26
+ readonly en: Readonly<Record<string, string>>;
27
+ }
28
+ export interface PluginInput {
29
+ readonly manifest: unknown;
30
+ readonly app?: AppPluginEntry;
31
+ readonly migrations?: readonly Migration[];
32
+ readonly messages?: PluginMessages;
33
+ }
34
+ export interface ThemeInput {
35
+ readonly manifest: unknown;
36
+ readonly messages?: PluginMessages;
37
+ }
38
+ /**
39
+ * A plugin's (or theme's) messages: both languages, the same keys, none empty, every key under
40
+ * its module (`<module>.…`), so no plugin can overwrite the app's or another plugin's texts.
41
+ */
42
+ export declare function checkPluginMessages(id: string, messages: unknown): ManifestIssue[];
43
+ export interface CompositionInput {
44
+ readonly context: ResolveContext;
45
+ readonly plugins: readonly PluginInput[];
46
+ readonly themes?: readonly ThemeInput[];
47
+ }
48
+ export interface PluginSet {
49
+ readonly context: ResolveContext;
50
+ /** In dependency order. */
51
+ readonly plugins: readonly PluginManifest[];
52
+ readonly themes: readonly ThemeManifest[];
53
+ readonly entries: ReadonlyMap<string, AppPluginEntry>;
54
+ /** `_plugin_states` first, then every plugin's own (the migrator orders by name). */
55
+ readonly migrations: readonly Migration[];
56
+ /** Every plugin's and theme's texts, merged (keys never collide: each lives under its module). */
57
+ readonly messages: PluginMessages;
58
+ }
59
+ export declare function definePlugins(input: CompositionInput): PluginSet;
60
+ //# sourceMappingURL=compose.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../src/compose.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAY,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAA4E,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAEtK,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnE,yDAAyD;AACzD,MAAM,WAAW,cAAc;IAC7B,4GAA4G;IAC5G,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,yEAAyE;IACzE,QAAQ,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC/D,6GAA6G;IAC7G,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,IAAI,CAAC;CAChD;AAED,mGAAmG;AACnG,wBAAgB,eAAe,CAAC,KAAK,EAAE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U,EAAE,SAAS,SAAS,EAAE,CAAC;IAC1C,kGAAkG;IAClG,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;CACnC;AAWD,wBAAgB,aAAa,CAAC,KAAK,EAAE,gBAAgB,GAAG,SAAS,CAiEhE"}
@@ -0,0 +1,123 @@
1
+ /**
2
+ * The composition: what the generator writes into `app/plugins.generated.ts` from every
3
+ * `plugins/<id>/plugin.json` and `themes/<id>/theme.json`. `definePlugins` checks it again
4
+ * at boot (manifests, fit with the app, dependencies, migration names), so a hand-edited or
5
+ * stale composition fails the boot instead of half-working.
6
+ */
7
+ import { AppError } from '@solobrand/core';
8
+ import { parsePluginManifest, parseThemeManifest, pluginModule, pluginTablePrefix } from './manifest.js';
9
+ import { createPluginStatesTable } from './registry.js';
10
+ import { resolvePlugins } from './resolve.js';
11
+ /** Identity helper for a plugin's `app/index.ts`: `export default defineAppPlugin({ routes })`. */
12
+ export function defineAppPlugin(entry) {
13
+ return entry;
14
+ }
15
+ /**
16
+ * A plugin's (or theme's) messages: both languages, the same keys, none empty, every key under
17
+ * its module (`<module>.…`), so no plugin can overwrite the app's or another plugin's texts.
18
+ */
19
+ export function checkPluginMessages(id, messages) {
20
+ const path = `${id}.lang`;
21
+ const module = pluginModule(id);
22
+ const m = messages;
23
+ const catalog = (v) => (typeof v === 'object' && v !== null && !Array.isArray(v) ? v : null);
24
+ const es = catalog(m?.es);
25
+ const en = catalog(m?.en);
26
+ if (es === null || en === null)
27
+ return [{ path, key: 'plugins.lang.incomplete', params: { id } }];
28
+ const issues = [];
29
+ for (const [locale, other, name] of [[es, en, 'en'], [en, es, 'es']]) {
30
+ for (const key of Object.keys(locale))
31
+ if (!(key in other))
32
+ issues.push({ path, key: 'plugins.lang.missing', params: { id, key, locale: name } });
33
+ }
34
+ for (const [locale, c] of [['es', es], ['en', en]]) {
35
+ for (const [key, value] of Object.entries(c)) {
36
+ if (!key.startsWith(`${module}.`))
37
+ issues.push({ path, key: 'plugins.lang.prefix', params: { id, key, module } });
38
+ else if (typeof value !== 'string' || value.trim() === '')
39
+ issues.push({ path, key: 'plugins.lang.empty', params: { id, key, locale } });
40
+ }
41
+ }
42
+ return issues.slice(0, 50);
43
+ }
44
+ const MIGRATION_NAME = /^\d{4}_\d{2}_\d{2}_\d{6}_([a-z0-9]+(?:_[a-z0-9]+)*)$/;
45
+ function fail(issues) {
46
+ const first = issues[0];
47
+ throw new AppError('internal', 'plugins.errors.composition_invalid', {
48
+ params: { count: issues.length, first: first ? `${first.key} ${JSON.stringify(first.params ?? {})}` : '' },
49
+ });
50
+ }
51
+ export function definePlugins(input) {
52
+ const issues = [];
53
+ const parsed = [];
54
+ for (const p of input.plugins) {
55
+ const r = parsePluginManifest(p.manifest);
56
+ if (r.ok)
57
+ parsed.push({ manifest: r.manifest, input: p });
58
+ else
59
+ issues.push(...r.issues);
60
+ }
61
+ const themes = [];
62
+ const messages = { es: {}, en: {} };
63
+ const addMessages = (id, m) => {
64
+ if (m === undefined)
65
+ return;
66
+ const found = checkPluginMessages(id, m);
67
+ if (found.length > 0)
68
+ issues.push(...found);
69
+ else {
70
+ Object.assign(messages.es, m.es);
71
+ Object.assign(messages.en, m.en);
72
+ }
73
+ };
74
+ for (const p of parsed)
75
+ addMessages(p.manifest.id, p.input.messages);
76
+ for (const t of input.themes ?? []) {
77
+ const r = parseThemeManifest(t.manifest);
78
+ if (r.ok) {
79
+ themes.push(r.manifest);
80
+ addMessages(r.manifest.id, t.messages);
81
+ }
82
+ else
83
+ issues.push(...r.issues);
84
+ }
85
+ if (issues.length > 0)
86
+ fail(issues);
87
+ const resolution = resolvePlugins(parsed.map((p) => p.manifest), themes, input.context);
88
+ if (!resolution.ok)
89
+ fail(resolution.issues);
90
+ const byId = new Map(parsed.map((p) => [p.manifest.id, p]));
91
+ const migrations = [createPluginStatesTable];
92
+ const names = new Set([createPluginStatesTable.name]);
93
+ for (const id of resolution.order) {
94
+ const p = byId.get(id);
95
+ const prefix = pluginTablePrefix(id);
96
+ for (const m of p?.input.migrations ?? []) {
97
+ const slug = MIGRATION_NAME.exec(m.name)?.[1];
98
+ if (slug === undefined || !slug.startsWith(`${prefix}_`))
99
+ issues.push({ path: `${id}.migrations`, key: 'plugins.compose.migration_prefix', params: { id, migration: m.name, prefix } });
100
+ if (names.has(m.name))
101
+ issues.push({ path: `${id}.migrations`, key: 'plugins.compose.migration_duplicate', params: { id, migration: m.name } });
102
+ names.add(m.name);
103
+ migrations.push(m);
104
+ }
105
+ }
106
+ if (issues.length > 0)
107
+ fail(issues);
108
+ const entries = new Map();
109
+ for (const id of resolution.order) {
110
+ const app = byId.get(id)?.input.app;
111
+ if (app !== undefined)
112
+ entries.set(id, app);
113
+ }
114
+ return {
115
+ context: input.context,
116
+ plugins: resolution.order.map((id) => byId.get(id)?.manifest).filter((m) => m !== undefined),
117
+ themes,
118
+ entries,
119
+ migrations,
120
+ messages,
121
+ };
122
+ }
123
+ //# sourceMappingURL=compose.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose.js","sourceRoot":"","sources":["../src/compose.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,QAAQ,EAAmC,MAAM,iBAAiB,CAAC;AAG5E,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,YAAY,EAAE,iBAAiB,EAA+D,MAAM,eAAe,CAAC;AACtK,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,cAAc,EAAuB,MAAM,cAAc,CAAC;AAYnE,mGAAmG;AACnG,MAAM,UAAU,eAAe,CAAC,KAAqB;IACnD,OAAO,KAAK,CAAC;AACf,CAAC;AAoBD;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAU,EAAE,QAAiB;IAC/D,MAAM,IAAI,GAAG,GAAG,EAAE,OAAO,CAAC;IAC1B,MAAM,MAAM,GAAG,YAAY,CAAC,EAAE,CAAC,CAAC;IAChC,MAAM,CAAC,GAAG,QAAwD,CAAC;IACnE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,CAAC,CAAC,KAAK,SAAS,CAAC;QACjH,MAAM;QACN,OAAO;QACP,UAAU;QACV,QAAQ;KACT,CAAC;AACJ,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @solobrand/plugins — plugins and themes inside an app (plugin@1, theme@1).
3
+ *
4
+ * A plugin is a whole module of the app (`plugins/<id>/`), installed by copying its folder
5
+ * and rebuilding, and switched on or off at runtime by the app's administrators. The
6
+ * generator writes the composition (`app/plugins.generated.ts`) from the manifests; the
7
+ * provider gates every plugin route and listener on its state. See docs/es/plugins.md.
8
+ */
9
+ export { parsePluginManifest, parseThemeManifest, pluginModule, pluginTablePrefix, settingRule, PLUGIN_ID, PLUGIN_SCHEMA_URL, THEME_SCHEMA_URL, type Localized, type ManifestIssue, type ManifestResult, type PluginManifest, type ThemeManifest, } from './manifest.js';
10
+ export { resolvePlugins, type ResolveContext, type Resolution } from './resolve.js';
11
+ export { satisfies, isRange, isVersion, parseVersion, compareVersions, type Version } from './semver.js';
12
+ export { createSecretBox, isStrongAppKey, type SecretBox } from './secrets.js';
13
+ export { createPluginRegistry, createPluginStatesTable, STATES_TABLE, type PluginRegistry, type PluginState, type PluginSettingsView, type RegistryOptions } from './registry.js';
14
+ export { checkPluginMessages, definePlugins, defineAppPlugin, type AppPluginEntry, type CompositionInput, type PluginInput, type PluginMessages, type PluginSet, type ThemeInput } from './compose.js';
15
+ export { pluginsProvider, pluginGate, pluginsToken, type PluginsProviderOptions } from './provider.js';
16
+ export { pluginsMessages } from './messages.js';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AACpF,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AACzG,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,YAAY,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,KAAK,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAClL,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,eAAe,EAAE,KAAK,cAAc,EAAE,KAAK,gBAAgB,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AACvM,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvG,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @solobrand/plugins — plugins and themes inside an app (plugin@1, theme@1).
3
+ *
4
+ * A plugin is a whole module of the app (`plugins/<id>/`), installed by copying its folder
5
+ * and rebuilding, and switched on or off at runtime by the app's administrators. The
6
+ * generator writes the composition (`app/plugins.generated.ts`) from the manifests; the
7
+ * provider gates every plugin route and listener on its state. See docs/es/plugins.md.
8
+ */
9
+ export { parsePluginManifest, parseThemeManifest, pluginModule, pluginTablePrefix, settingRule, PLUGIN_ID, PLUGIN_SCHEMA_URL, THEME_SCHEMA_URL, } from './manifest.js';
10
+ export { resolvePlugins } from './resolve.js';
11
+ export { satisfies, isRange, isVersion, parseVersion, compareVersions } from './semver.js';
12
+ export { createSecretBox, isStrongAppKey } from './secrets.js';
13
+ export { createPluginRegistry, createPluginStatesTable, STATES_TABLE } from './registry.js';
14
+ export { checkPluginMessages, definePlugins, defineAppPlugin } from './compose.js';
15
+ export { pluginsProvider, pluginGate, pluginsToken } from './provider.js';
16
+ export { pluginsMessages } from './messages.js';
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,gBAAgB,GAMjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAwC,MAAM,cAAc,CAAC;AACpF,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAgB,MAAM,aAAa,CAAC;AACzG,OAAO,EAAE,eAAe,EAAE,cAAc,EAAkB,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,YAAY,EAAwF,MAAM,eAAe,CAAC;AAClL,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,eAAe,EAAsH,MAAM,cAAc,CAAC;AACvM,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAA+B,MAAM,eAAe,CAAC;AACvG,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,65 @@
1
+ export declare const PLUGIN_SCHEMA_URL = "https://solobrand.ai/schemas/plugin@1.json";
2
+ export declare const THEME_SCHEMA_URL = "https://solobrand.ai/schemas/theme@1.json";
3
+ /** `<publisher>.<app>.<module>`: three or more lowercase segments, words joined by `-`. */
4
+ export declare const PLUGIN_ID: RegExp;
5
+ export interface Localized {
6
+ readonly es: string;
7
+ readonly en: string;
8
+ }
9
+ export interface PluginManifest {
10
+ readonly id: string;
11
+ readonly version: string;
12
+ readonly name: Localized;
13
+ readonly description: Localized;
14
+ readonly publisher: string;
15
+ /** App name → semver range of the app base it was built for. */
16
+ readonly targets: Readonly<Record<string, string>>;
17
+ /** Range of `@solobrand/*`. */
18
+ readonly framework: string;
19
+ /** Other plugin id → range. */
20
+ readonly requires: Readonly<Record<string, string>>;
21
+ /** Permission keys, each `<module>.<action>`. */
22
+ readonly permissions: readonly string[];
23
+ /** Setting key → validation rules; the token `secret` marks a secret (stored encrypted, never shown). */
24
+ readonly settings: Readonly<Record<string, string>>;
25
+ /** SoloBrand services it may call (`ai.search`…). */
26
+ readonly services: readonly string[];
27
+ readonly events: {
28
+ readonly emits: readonly string[];
29
+ readonly listens: readonly string[];
30
+ };
31
+ }
32
+ export interface ThemeManifest {
33
+ readonly id: string;
34
+ readonly version: string;
35
+ readonly name: Localized;
36
+ readonly description: Localized;
37
+ readonly publisher: string;
38
+ readonly targets: Readonly<Record<string, string>>;
39
+ readonly framework: string;
40
+ }
41
+ export interface ManifestIssue {
42
+ /** JSON path (`requires.solobrand.x.y`, `permissions.2`…); '' = the whole document. */
43
+ readonly path: string;
44
+ readonly key: string;
45
+ readonly params?: Readonly<Record<string, string | number>>;
46
+ }
47
+ export type ManifestResult<M> = {
48
+ readonly ok: true;
49
+ readonly manifest: M;
50
+ } | {
51
+ readonly ok: false;
52
+ readonly issues: readonly ManifestIssue[];
53
+ };
54
+ /** The module of a plugin: its last id segment (`solobrand.ecommerce.cupones` → `cupones`). */
55
+ export declare function pluginModule(id: string): string;
56
+ /** The snake form of the module, the prefix of its tables and migration slugs. */
57
+ export declare function pluginTablePrefix(id: string): string;
58
+ /** The tokens of a setting's rule string, with `secret` taken out. */
59
+ export declare function settingRule(rule: string): {
60
+ readonly secret: boolean;
61
+ readonly rules: string;
62
+ };
63
+ export declare function parsePluginManifest(json: unknown): ManifestResult<PluginManifest>;
64
+ export declare function parseThemeManifest(json: unknown): ManifestResult<ThemeManifest>;
65
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,iBAAiB,+CAA+C,CAAC;AAC9E,eAAO,MAAM,gBAAgB,8CAA8C,CAAC;AAE5E,2FAA2F;AAC3F,eAAO,MAAM,SAAS,QAAiE,CAAC;AAKxF,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,SAAS,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,gEAAgE;IAChE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD,+BAA+B;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,+BAA+B;IAC/B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACpD,iDAAiD;IACjD,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,yGAAyG;IACzG,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACpD,qDAAqD;IACrD,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE;QAAE,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E,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAI9F;AAUD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,cAAc,CAAC,cAAc,CAAC,CAsBjF;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,GAAG,cAAc,CAAC,aAAa,CAAC,CAK/E"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * `plugin.json` (plugin@1) and `theme.json` (theme@1): what a plugin or a theme declares.
3
+ * Parsing never throws: it returns the manifest or the issues, each with a translation key
4
+ * (messages.ts) and the JSON path it is about.
5
+ */
6
+ import { z } from 'zod';
7
+ import { isRange, isVersion } from './semver.js';
8
+ export const PLUGIN_SCHEMA_URL = 'https://solobrand.ai/schemas/plugin@1.json';
9
+ export const THEME_SCHEMA_URL = 'https://solobrand.ai/schemas/theme@1.json';
10
+ /** `<publisher>.<app>.<module>`: three or more lowercase segments, words joined by `-`. */
11
+ export const PLUGIN_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*(?:\.[a-z0-9]+(?:-[a-z0-9]+)*){2,}$/;
12
+ const SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
13
+ const SETTING_KEY = /^[a-z][a-z0-9_]*$/;
14
+ const DOTTED = /^[a-z0-9_]+(?:\.[a-z0-9_-]+)+$/;
15
+ const localized = z.object({ es: z.string().trim().min(1).max(300), en: z.string().trim().min(1).max(300) }).strict();
16
+ const range = z.string().refine(isRange, { message: 'range' });
17
+ const common = {
18
+ $schema: z.string().optional(),
19
+ id: z.string().max(120).regex(PLUGIN_ID),
20
+ version: z.string().refine(isVersion, { message: 'version' }),
21
+ name: localized,
22
+ description: localized,
23
+ publisher: z.string().max(60).regex(SLUG),
24
+ targets: z.record(z.string().max(60).regex(SLUG), range).refine((t) => Object.keys(t).length > 0, { message: 'targets_empty' }),
25
+ framework: range,
26
+ };
27
+ const pluginSchema = z
28
+ .object({
29
+ ...common,
30
+ requires: z.record(z.string().max(120).regex(PLUGIN_ID), range).default({}),
31
+ permissions: z.array(z.string().max(120)).default([]),
32
+ settings: z.record(z.string().max(60).regex(SETTING_KEY), z.string().trim().min(1).max(500)).default({}),
33
+ services: z.array(z.string().max(80).regex(DOTTED)).default([]),
34
+ events: z
35
+ .object({ emits: z.array(z.string().max(120).regex(DOTTED)).default([]), listens: z.array(z.string().max(120).regex(DOTTED)).default([]) })
36
+ .strict()
37
+ .default({}),
38
+ })
39
+ .strict();
40
+ const themeSchema = z.object(common).strict();
41
+ function zodIssues(error) {
42
+ return error.issues.map((i) => ({ path: i.path.join('.'), key: 'plugins.manifest.invalid_field', params: { path: i.path.join('.') || '/', detail: i.message } }));
43
+ }
44
+ /** The module of a plugin: its last id segment (`solobrand.ecommerce.cupones` → `cupones`). */
45
+ export function pluginModule(id) {
46
+ return id.slice(id.lastIndexOf('.') + 1);
47
+ }
48
+ /** The snake form of the module, the prefix of its tables and migration slugs. */
49
+ export function pluginTablePrefix(id) {
50
+ return pluginModule(id).replace(/-/g, '_');
51
+ }
52
+ /** The tokens of a setting's rule string, with `secret` taken out. */
53
+ export function settingRule(rule) {
54
+ const tokens = rule.split('|').map((t) => t.trim()).filter((t) => t !== '');
55
+ const secret = tokens.includes('secret');
56
+ return { secret, rules: tokens.filter((t) => t !== 'secret').join('|') };
57
+ }
58
+ function unique(list, path, issues) {
59
+ const seen = new Set();
60
+ list.forEach((item, i) => {
61
+ if (seen.has(item))
62
+ issues.push({ path: `${path}.${i}`, key: 'plugins.manifest.duplicate', params: { value: item } });
63
+ seen.add(item);
64
+ });
65
+ }
66
+ export function parsePluginManifest(json) {
67
+ const parsed = pluginSchema.safeParse(json);
68
+ if (!parsed.success)
69
+ return { ok: false, issues: zodIssues(parsed.error) };
70
+ const m = parsed.data;
71
+ const issues = [];
72
+ const module = pluginModule(m.id);
73
+ if (m.requires[m.id] !== undefined)
74
+ issues.push({ path: `requires.${m.id}`, key: 'plugins.manifest.requires_itself', params: { id: m.id } });
75
+ m.permissions.forEach((p, i) => {
76
+ if (!new RegExp(`^${module.replace(/-/g, '\\-')}\\.[a-z0-9_-]+(?:\\.[a-z0-9_-]+)*$`).test(p)) {
77
+ issues.push({ path: `permissions.${i}`, key: 'plugins.manifest.permission_prefix', params: { permission: p, module } });
78
+ }
79
+ });
80
+ unique(m.permissions, 'permissions', issues);
81
+ unique(m.services, 'services', issues);
82
+ unique(m.events.emits, 'events.emits', issues);
83
+ unique(m.events.listens, 'events.listens', issues);
84
+ for (const [key, rule] of Object.entries(m.settings)) {
85
+ if (settingRule(rule).rules === '')
86
+ issues.push({ path: `settings.${key}`, key: 'plugins.manifest.setting_without_rules', params: { setting: key } });
87
+ }
88
+ if (issues.length > 0)
89
+ return { ok: false, issues };
90
+ const { $schema: _s, ...manifest } = m;
91
+ return { ok: true, manifest };
92
+ }
93
+ export function parseThemeManifest(json) {
94
+ const parsed = themeSchema.safeParse(json);
95
+ if (!parsed.success)
96
+ return { ok: false, issues: zodIssues(parsed.error) };
97
+ const { $schema: _s, ...manifest } = parsed.data;
98
+ return { ok: true, manifest };
99
+ }
100
+ //# sourceMappingURL=manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.js","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,CAAC,MAAM,iBAAiB,GAAG,4CAA4C,CAAC;AAC9E,MAAM,CAAC,MAAM,gBAAgB,GAAG,2CAA2C,CAAC;AAE5E,2FAA2F;AAC3F,MAAM,CAAC,MAAM,SAAS,GAAG,8DAA8D,CAAC;AACxF,MAAM,IAAI,GAAG,4BAA4B,CAAC;AAC1C,MAAM,WAAW,GAAG,mBAAmB,CAAC;AACxC,MAAM,MAAM,GAAG,gCAAgC,CAAC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,GAAG,QAAQ,EAAE,GAAG,CAAC,CAAC;IACvC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAa;IAC9C,MAAM,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC3C,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IAC3E,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,QAAQ,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC;IACjD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAChC,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** The messages @solobrand/plugins ships, in es and en. `pluginsProvider()` adds them. */
2
+ export declare const pluginsMessages: Readonly<Record<'es' | 'en', Readonly<Record<string, string>>>>;
3
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAyD3F,CAAC"}
@@ -0,0 +1,60 @@
1
+ /** The messages @solobrand/plugins ships, in es and en. `pluginsProvider()` adds them. */
2
+ export const pluginsMessages = {
3
+ en: {
4
+ 'plugins.manifest.invalid_field': 'Invalid manifest field "{path}": {detail}.',
5
+ 'plugins.manifest.duplicate': '"{value}" is listed twice.',
6
+ 'plugins.manifest.requires_itself': 'Plugin {id} cannot require itself.',
7
+ 'plugins.manifest.permission_prefix': 'Permission "{permission}" must start with "{module}.".',
8
+ 'plugins.manifest.setting_without_rules': 'Setting "{setting}" has no validation rules.',
9
+ 'plugins.manifest.unreadable': 'The manifest is not valid JSON.',
10
+ 'plugins.manifest.folder_mismatch': 'The folder "{folder}" holds the manifest of "{id}": the folder must be named after the id.',
11
+ 'plugins.resolve.wrong_app': '{id} is for {targets}, not for {app}.',
12
+ 'plugins.resolve.app_version': '{id} needs {range} of the app; this app is {version}.',
13
+ 'plugins.resolve.framework_version': '{id} needs @solobrand/* {range}; installed: {version}.',
14
+ 'plugins.resolve.duplicate': '{id} is installed twice.',
15
+ 'plugins.resolve.missing': '{id} requires {requires} ({range}), which is not installed.',
16
+ 'plugins.resolve.version': '{id} requires {requires} {range}; installed: {version}.',
17
+ 'plugins.resolve.cycle': 'These plugins require each other in a cycle: {ids}.',
18
+ 'plugins.compose.migration_prefix': 'Migration {migration} of {id} must be named <date>_{prefix}_…: a plugin only creates its own tables.',
19
+ 'plugins.compose.migration_duplicate': 'Migration {migration} of {id} has the name of another migration.',
20
+ 'plugins.lang.incomplete': '{id} has lang/ in only one language: it needs lang/es.json and lang/en.json.',
21
+ 'plugins.lang.missing': 'Text {key} of {id} is missing in {locale}.',
22
+ 'plugins.lang.prefix': 'Text {key} of {id} must start with {module}.: a plugin only names its own texts.',
23
+ 'plugins.lang.empty': 'Text {key} of {id} is empty in {locale}.',
24
+ 'plugins.errors.composition_invalid': 'The plugin composition is not valid ({count} problems; first: {first}). Run `sb generate`.',
25
+ 'plugins.errors.unknown': 'The plugin {id} is not installed.',
26
+ 'plugins.errors.requires_inactive': '{id} cannot be activated: it needs {missing} active first.',
27
+ 'plugins.errors.required_by': '{id} cannot be deactivated: {dependents} need it.',
28
+ 'plugins.errors.app_key_missing': 'APP_KEY is missing or too weak (at least 32 random characters): plugin secrets cannot be stored.',
29
+ 'plugins.errors.database_missing': 'Plugins need the app database (bind @solobrand/db first).',
30
+ },
31
+ es: {
32
+ 'plugins.manifest.invalid_field': 'Campo del manifiesto no válido «{path}»: {detail}.',
33
+ 'plugins.manifest.duplicate': '«{value}» aparece dos veces.',
34
+ 'plugins.manifest.requires_itself': 'El plugin {id} no puede requerirse a sí mismo.',
35
+ 'plugins.manifest.permission_prefix': 'El permiso «{permission}» debe empezar con «{module}.».',
36
+ 'plugins.manifest.setting_without_rules': 'El ajuste «{setting}» no tiene reglas de validación.',
37
+ 'plugins.manifest.unreadable': 'El manifiesto no es JSON válido.',
38
+ 'plugins.manifest.folder_mismatch': 'La carpeta «{folder}» tiene el manifiesto de «{id}»: la carpeta debe llamarse como el id.',
39
+ 'plugins.resolve.wrong_app': '{id} es para {targets}, no para {app}.',
40
+ 'plugins.resolve.app_version': '{id} necesita {range} de la app; esta app es {version}.',
41
+ 'plugins.resolve.framework_version': '{id} necesita @solobrand/* {range}; instalado: {version}.',
42
+ 'plugins.resolve.duplicate': '{id} está instalado dos veces.',
43
+ 'plugins.resolve.missing': '{id} requiere {requires} ({range}), que no está instalado.',
44
+ 'plugins.resolve.version': '{id} requiere {requires} {range}; instalado: {version}.',
45
+ 'plugins.resolve.cycle': 'Estos plugins se requieren en círculo: {ids}.',
46
+ 'plugins.compose.migration_prefix': 'La migración {migration} de {id} debe llamarse <fecha>_{prefix}_…: un plugin sólo crea sus propias tablas.',
47
+ 'plugins.compose.migration_duplicate': 'La migración {migration} de {id} tiene el nombre de otra migración.',
48
+ 'plugins.lang.incomplete': '{id} tiene lang/ en un solo idioma: necesita lang/es.json y lang/en.json.',
49
+ 'plugins.lang.missing': 'Al texto {key} de {id} le falta {locale}.',
50
+ 'plugins.lang.prefix': 'El texto {key} de {id} debe empezar con {module}.: un plugin sólo nombra sus propios textos.',
51
+ 'plugins.lang.empty': 'El texto {key} de {id} está vacío en {locale}.',
52
+ 'plugins.errors.composition_invalid': 'La composición de plugins no es válida ({count} problemas; el primero: {first}). Corre `sb generate`.',
53
+ 'plugins.errors.unknown': 'El plugin {id} no está instalado.',
54
+ 'plugins.errors.requires_inactive': '{id} no se puede activar: antes necesita activos {missing}.',
55
+ 'plugins.errors.required_by': '{id} no se puede desactivar: lo necesitan {dependents}.',
56
+ 'plugins.errors.app_key_missing': 'Falta APP_KEY o es débil (al menos 32 caracteres aleatorios): no se pueden guardar los secretos de los plugins.',
57
+ 'plugins.errors.database_missing': 'Los plugins necesitan la base de la app (registra @solobrand/db antes).',
58
+ },
59
+ };
60
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,MAAM,CAAC,MAAM,eAAe,GAAoE;IAC9F,EAAE,EAAE;QACF,gCAAgC,EAAE,4CAA4C;QAC9E,4BAA4B,EAAE,4BAA4B;QAC1D,kCAAkC,EAAE,oCAAoC;QACxE,oCAAoC,EAAE,wDAAwD;QAC9F,wCAAwC,EAAE,8CAA8C;QACxF,6BAA6B,EAAE,iCAAiC;QAChE,kCAAkC,EAAE,4FAA4F;QAChI,2BAA2B,EAAE,uCAAuC;QACpE,6BAA6B,EAAE,uDAAuD;QACtF,mCAAmC,EAAE,wDAAwD;QAC7F,2BAA2B,EAAE,0BAA0B;QACvD,yBAAyB,EAAE,6DAA6D;QACxF,yBAAyB,EAAE,yDAAyD;QACpF,uBAAuB,EAAE,qDAAqD;QAC9E,kCAAkC,EAAE,sGAAsG;QAC1I,qCAAqC,EAAE,kEAAkE;QACzG,yBAAyB,EAAE,8EAA8E;QACzG,sBAAsB,EAAE,4CAA4C;QACpE,qBAAqB,EAAE,kFAAkF;QACzG,oBAAoB,EAAE,0CAA0C;QAChE,oCAAoC,EAAE,4FAA4F;QAClI,wBAAwB,EAAE,mCAAmC;QAC7D,kCAAkC,EAAE,4DAA4D;QAChG,4BAA4B,EAAE,mDAAmD;QACjF,gCAAgC,EAAE,kGAAkG;QACpI,iCAAiC,EAAE,2DAA2D;KAC/F;IACD,EAAE,EAAE;QACF,gCAAgC,EAAE,oDAAoD;QACtF,4BAA4B,EAAE,8BAA8B;QAC5D,kCAAkC,EAAE,gDAAgD;QACpF,oCAAoC,EAAE,yDAAyD;QAC/F,wCAAwC,EAAE,sDAAsD;QAChG,6BAA6B,EAAE,kCAAkC;QACjE,kCAAkC,EAAE,2FAA2F;QAC/H,2BAA2B,EAAE,wCAAwC;QACrE,6BAA6B,EAAE,yDAAyD;QACxF,mCAAmC,EAAE,2DAA2D;QAChG,2BAA2B,EAAE,gCAAgC;QAC7D,yBAAyB,EAAE,4DAA4D;QACvF,yBAAyB,EAAE,yDAAyD;QACpF,uBAAuB,EAAE,+CAA+C;QACxE,kCAAkC,EAAE,4GAA4G;QAChJ,qCAAqC,EAAE,qEAAqE;QAC5G,yBAAyB,EAAE,2EAA2E;QACtG,sBAAsB,EAAE,2CAA2C;QACnE,qBAAqB,EAAE,8FAA8F;QACrH,oBAAoB,EAAE,gDAAgD;QACtE,oCAAoC,EAAE,uGAAuG;QAC7I,wBAAwB,EAAE,mCAAmC;QAC7D,kCAAkC,EAAE,6DAA6D;QACjG,4BAA4B,EAAE,yDAAyD;QACvF,gCAAgC,EAAE,iHAAiH;QACnJ,iCAAiC,EAAE,yEAAyE;KAC7G;CACF,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * `pluginsProvider({ set })` wires a composition into the app:
3
+ * - binds the registry (`pluginsToken`);
4
+ * - `plugin:<id>` middleware: an inactive plugin's route is a 404;
5
+ * - mounts every plugin's routes behind its own `plugin:<id>` (a plugin cannot forget it);
6
+ * - subscribes every plugin's listeners, each one gated by the plugin being active;
7
+ * - `GET <prefix>/active` (public: which plugins are on, nothing else);
8
+ * - the administration routes (list, activate, deactivate, settings) ONLY when the app
9
+ * passes `authorize`: closed unless the app says who may configure.
10
+ */
11
+ import { type ServiceProvider, type Token } from '@solobrand/core';
12
+ import { type HttpContext, type Middleware } from '@solobrand/http';
13
+ import type { PluginSet } from './compose.js';
14
+ import { type PluginRegistry } from './registry.js';
15
+ export declare const pluginsToken: Token<PluginRegistry>;
16
+ export interface PluginsProviderOptions {
17
+ readonly set: PluginSet;
18
+ /** Who may list, activate, deactivate and configure plugins (the app's Administración). Absent ⇒ no admin routes. */
19
+ readonly authorize?: (ctx: HttpContext) => boolean | Promise<boolean>;
20
+ /** Named middleware before the admin routes (e.g. `['auth']`). */
21
+ readonly adminMiddleware?: readonly string[];
22
+ /** Where the routes live (default `/api/plugins`). */
23
+ readonly prefix?: string;
24
+ /** Secret binding for settings encryption (default `APP_KEY`). */
25
+ readonly secretBinding?: string;
26
+ }
27
+ export declare function pluginGate(id: string): Middleware;
28
+ export declare function pluginsProvider(options: PluginsProviderOptions): ServiceProvider;
29
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAqC,KAAK,eAAe,EAAE,KAAK,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAEtG,OAAO,EAA2B,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAG1E,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,cAAc,CAA6C,CAAC;AAE7F,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,qHAAqH;IACrH,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACtE,kEAAkE;IAClE,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7C,sDAAsD;IACtD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,kEAAkE;IAClE,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,UAAU,CAMjD;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,eAAe,CAiFhF"}