@acryldev/blends-frame 0.2.6 → 0.2.8
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/lib/app-plugins.d.ts +3 -3
- package/lib/client.js +39 -18
- package/lib/client.js.map +1 -1
- package/lib/contract.d.ts +10 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +46 -15
- package/lib/index.js.map +1 -1
- package/lib/types/client/plugins-navigator.d.ts +5 -4
- package/lib/types/contract.d.ts +10 -0
- package/package.json +3 -3
package/lib/contract.d.ts
CHANGED
|
@@ -195,6 +195,11 @@ export interface AppSharedView {
|
|
|
195
195
|
}
|
|
196
196
|
export declare function parseAppSharePlan(value: unknown): AppSharePlanView;
|
|
197
197
|
export declare function parseAppShared(value: unknown): AppSharedView;
|
|
198
|
+
/**
|
|
199
|
+
* The GitHub account or organization a person typed to share a plugin to (blank: theirs). `undefined` when none was asked, `null` when what came is not a GitHub name
|
|
200
|
+
* (it goes to a command line: only a name that cannot start with a dash or hold a space or a slash).
|
|
201
|
+
*/
|
|
202
|
+
export declare function parseShareOwner(value: unknown): string | undefined | null;
|
|
198
203
|
export declare function parseAppShareRequest(value: unknown): AppShareRequest | undefined;
|
|
199
204
|
export declare const FRAME_PLUGINS_SHARE_PLAN_PATH = "/api/acryl-blends-frame/plugins/share-plan";
|
|
200
205
|
/** POST `{ name, confirm }`: publish it, only when `confirm` is the plan the person said yes to and it still holds. */
|
|
@@ -247,6 +252,11 @@ export interface SharePlan {
|
|
|
247
252
|
readonly license?: string;
|
|
248
253
|
/** The public registry (cordisplugins.github.io) lists it: the share sets the `cordis-plugin` topic. Only a public share can be listed. */
|
|
249
254
|
readonly registry?: boolean;
|
|
255
|
+
/** Where the registry lists it (category slugs of acrylblends.github.io/blends): the app's own store place, written as package.json keywords. */
|
|
256
|
+
readonly placement?: {
|
|
257
|
+
readonly category: string;
|
|
258
|
+
readonly subcategory?: string;
|
|
259
|
+
};
|
|
250
260
|
}
|
|
251
261
|
/** @throws when the value is not a share plan. */
|
|
252
262
|
export declare function parseSharePlan(value: unknown): SharePlan;
|
package/lib/index.d.ts
CHANGED
|
@@ -62,9 +62,9 @@ export interface PluginsPort {
|
|
|
62
62
|
read(): Promise<AppPluginsView>;
|
|
63
63
|
switch(kind: AppPluginKind, name: string, on: boolean): Promise<void>;
|
|
64
64
|
/** What sharing one local plugin would do (repository, version, visibility); nothing is sent. */
|
|
65
|
-
planShare(name: string, visibility?: ShareVisibility, registry?: boolean): Promise<SharePlan>;
|
|
65
|
+
planShare(name: string, visibility?: ShareVisibility, registry?: boolean, owner?: string): Promise<SharePlan>;
|
|
66
66
|
/** Publish one local plugin to its GitHub repository and release, through the plugin-hub path: only the plan the person confirmed. */
|
|
67
|
-
share(name: string, confirmed: SharePlan): Promise<ShareAppPluginResult>;
|
|
67
|
+
share(name: string, confirmed: SharePlan, owner?: string): Promise<ShareAppPluginResult>;
|
|
68
68
|
/** Keep a packed copy of one local plugin on this machine (the app's plugin store); nothing leaves the machine. */
|
|
69
69
|
save(name: string): Promise<SavedPluginResult>;
|
|
70
70
|
/** The public registry (cordisplugins.github.io), each entry marked with what this app has. Unreadable is an answer, not a failure. */
|
package/lib/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "nod
|
|
|
7
7
|
import { Acryl } from "@acryldev/blends";
|
|
8
8
|
import { error } from "@acryldev/loopback-http";
|
|
9
9
|
import { INVALID_JSON, jsonBody, ownPage, privateApi, readJson } from "@acryldev/loopback-http/router";
|
|
10
|
-
import { PluginStore, StoreConflictError, bumpVersion, gitCli, githubCli, parseVersion, savePlugin, sharePlugin, storeRootOf } from "@acryldev/plugin-hub-core";
|
|
10
|
+
import { PluginStore, StoreConflictError, bumpVersion, gitCli, githubCli, parseVersion, placementOf, savePlugin, sharePlugin, storeRootOf, withPlacement } from "@acryldev/plugin-hub-core";
|
|
11
11
|
import { GitRunner, Versions } from "@acryldev/versions";
|
|
12
12
|
import * as workspaceHost from "@acryldev/workspace";
|
|
13
13
|
import { promisify } from "node:util";
|
|
@@ -159,6 +159,14 @@ function parseAppShared(value) {
|
|
|
159
159
|
...listed === void 0 ? {} : { listed }
|
|
160
160
|
};
|
|
161
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* The GitHub account or organization a person typed to share a plugin to (blank: theirs). `undefined` when none was asked, `null` when what came is not a GitHub name
|
|
164
|
+
* (it goes to a command line: only a name that cannot start with a dash or hold a space or a slash).
|
|
165
|
+
*/
|
|
166
|
+
function parseShareOwner(value) {
|
|
167
|
+
if (value === void 0 || value === "") return void 0;
|
|
168
|
+
return typeof value === "string" && GITHUB_NAME.test(value) ? value : null;
|
|
169
|
+
}
|
|
162
170
|
function parseAppShareRequest(value) {
|
|
163
171
|
if (!isRecord$2(value)) return void 0;
|
|
164
172
|
const { owner, visibility, list } = value;
|
|
@@ -195,13 +203,18 @@ const GITHUB_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/u;
|
|
|
195
203
|
/** @throws when the value is not a share plan. */
|
|
196
204
|
function parseSharePlan(value) {
|
|
197
205
|
if (!isRecord$2(value)) throw new Error("share plan: not a plan");
|
|
198
|
-
const { owner, repo, version, visibility, createsRepository, released, license, registry } = value;
|
|
206
|
+
const { owner, repo, version, visibility, createsRepository, released, license, registry, placement } = value;
|
|
199
207
|
if (typeof owner !== "string" || !GITHUB_NAME.test(owner) || typeof repo !== "string" || !GITHUB_NAME.test(repo)) throw new Error("share plan: repository");
|
|
200
208
|
if (typeof version !== "string" || version === "" || released !== void 0 && (typeof released !== "string" || released === "")) throw new Error("share plan: version");
|
|
201
209
|
if (visibility !== "private" && visibility !== "public" || typeof createsRepository !== "boolean") throw new Error("share plan: visibility");
|
|
202
210
|
if (license !== void 0 && (typeof license !== "string" || !/^[A-Za-z0-9.+-]+$/u.test(license))) throw new Error("share plan: license");
|
|
203
211
|
if (registry !== void 0 && typeof registry !== "boolean") throw new Error("share plan: registry");
|
|
204
212
|
if (registry === true && visibility !== "public") throw new Error("share plan: only a public share can be listed in the registry");
|
|
213
|
+
const place = placement === void 0 ? void 0 : isRecord$2(placement) && typeof placement.category === "string" && (placement.subcategory === void 0 || typeof placement.subcategory === "string") ? {
|
|
214
|
+
category: placement.category,
|
|
215
|
+
...typeof placement.subcategory === "string" ? { subcategory: placement.subcategory } : {}
|
|
216
|
+
} : null;
|
|
217
|
+
if (place === null) throw new Error("share plan: placement");
|
|
205
218
|
return {
|
|
206
219
|
owner,
|
|
207
220
|
repo,
|
|
@@ -210,12 +223,13 @@ function parseSharePlan(value) {
|
|
|
210
223
|
createsRepository,
|
|
211
224
|
...released === void 0 ? {} : { released },
|
|
212
225
|
...license === void 0 ? {} : { license },
|
|
213
|
-
...registry === true ? { registry } : {}
|
|
226
|
+
...registry === true ? { registry } : {},
|
|
227
|
+
...place === void 0 ? {} : { placement: place }
|
|
214
228
|
};
|
|
215
229
|
}
|
|
216
230
|
/** The same plan: what the person confirmed is what would be published now. */
|
|
217
231
|
function samePlan(a, b) {
|
|
218
|
-
return a.owner === b.owner && a.repo === b.repo && a.version === b.version && a.visibility === b.visibility && a.createsRepository === b.createsRepository && a.released === b.released && a.license === b.license && a.registry === true === (b.registry === true);
|
|
232
|
+
return a.owner === b.owner && a.repo === b.repo && a.version === b.version && a.visibility === b.visibility && a.createsRepository === b.createsRepository && a.released === b.released && a.license === b.license && a.registry === true === (b.registry === true) && a.placement?.category === b.placement?.category && a.placement?.subcategory === b.placement?.subcategory;
|
|
219
233
|
}
|
|
220
234
|
const FRAME_FEEDBACK_PATH = `${FRAME_API_PREFIX}/feedback`;
|
|
221
235
|
const FRAME_FEEDBACK_SEEN_PATH = `${FRAME_API_PREFIX}/feedback/seen`;
|
|
@@ -624,7 +638,7 @@ async function readFramePlugins(root, rows) {
|
|
|
624
638
|
}
|
|
625
639
|
/** The package.json a local plugin is shared with: the fields the builder's package_plugin writes (plugins/builder/index.ts), plus the Loader
|
|
626
640
|
* patch the plugin-hub's share requires so the package can also be installed as a row. */
|
|
627
|
-
function pluginPackageManifest(name, description, version = "0.1.0", license) {
|
|
641
|
+
function pluginPackageManifest(name, description, version = "0.1.0", license, placement) {
|
|
628
642
|
return {
|
|
629
643
|
name,
|
|
630
644
|
version,
|
|
@@ -642,11 +656,11 @@ function pluginPackageManifest(name, description, version = "0.1.0", license) {
|
|
|
642
656
|
"cordis.patch.yml"
|
|
643
657
|
],
|
|
644
658
|
peerDependencies: { "@deepseek-ai/cordis": "4.0.4" },
|
|
645
|
-
keywords: [
|
|
659
|
+
keywords: withPlacement([
|
|
646
660
|
"cordis",
|
|
647
661
|
"cordis-plugin",
|
|
648
662
|
"acrylblends"
|
|
649
|
-
],
|
|
663
|
+
], placement),
|
|
650
664
|
dsh: { bundle: { patch: "./cordis.patch.yml" } }
|
|
651
665
|
};
|
|
652
666
|
}
|
|
@@ -687,7 +701,7 @@ async function recordShare(file, name, shared) {
|
|
|
687
701
|
/** Where the frame packages the plugins it shares: under the app's home, never in the app's folder, so a share leaves no file to save. */
|
|
688
702
|
const pluginPackagesOf = (home) => join(home, "plugin-packages");
|
|
689
703
|
/** Copy one local plugin into its package folder under `packages`, the way the builder's package_plugin does; answers the folder. */
|
|
690
|
-
async function packageAppPlugin(root, name, packages, license) {
|
|
704
|
+
async function packageAppPlugin(root, name, packages, license, placement) {
|
|
691
705
|
if (!(await madePlugins(root)).includes(name)) throw new Error(`plugins/ has no local plugin "${name}"`);
|
|
692
706
|
const source = join(root, "plugins", name);
|
|
693
707
|
const target = join(packages, name);
|
|
@@ -706,7 +720,7 @@ async function packageAppPlugin(root, name, packages, license) {
|
|
|
706
720
|
filter: (path) => !/(^|[\\/])(node_modules|\.git)([\\/]|$)/u.test(path.slice(source.length))
|
|
707
721
|
});
|
|
708
722
|
const description = await packageDescription(source);
|
|
709
|
-
writeFileSync(join(target, "package.json"), `${JSON.stringify(pluginPackageManifest(name, description, version, license), null, 2)}\n`);
|
|
723
|
+
writeFileSync(join(target, "package.json"), `${JSON.stringify(pluginPackageManifest(name, description, version, license, placement), null, 2)}\n`);
|
|
710
724
|
writeFileSync(join(target, "cordis.patch.yml"), `- insert:\n - id: ${name}\n name: ./index.ts\n`);
|
|
711
725
|
if (!existsSync(join(target, "README.md"))) writeFileSync(join(target, "README.md"), `# ${name}\n\n${description}\n\nA Cordis plugin. In an ACRYLBLENDS app: \`acrylblends add <this folder>\`.\n`);
|
|
712
726
|
return target;
|
|
@@ -776,7 +790,8 @@ async function planAppPluginShare(root, home, name, options, ports) {
|
|
|
776
790
|
const registry = options.registry === true;
|
|
777
791
|
const visibility = registry ? "public" : options.visibility ?? "private";
|
|
778
792
|
const license = visibility === "public" ? options.license ?? "MIT" : void 0;
|
|
779
|
-
const
|
|
793
|
+
const placement = registry ? appPlacement(root) : void 0;
|
|
794
|
+
const dir = await packageAppPlugin(root, name, pluginPackagesOf(home), license, placement);
|
|
780
795
|
const manifest = JSON.parse(await readFile(join(dir, "package.json"), "utf8"));
|
|
781
796
|
const current = typeof manifest.version === "string" && parseVersion(manifest.version) !== void 0 ? manifest.version : void 0;
|
|
782
797
|
if (current === void 0) throw new Error(`${name}: its package has no semantic version`);
|
|
@@ -792,9 +807,17 @@ async function planAppPluginShare(root, home, name, options, ports) {
|
|
|
792
807
|
createsRepository: existing === void 0,
|
|
793
808
|
...released ? { released: current } : {},
|
|
794
809
|
...license === void 0 ? {} : { license },
|
|
795
|
-
...registry ? { registry } : {}
|
|
810
|
+
...registry ? { registry } : {},
|
|
811
|
+
...placement === void 0 ? {} : { placement }
|
|
796
812
|
};
|
|
797
813
|
}
|
|
814
|
+
function appPlacement(root) {
|
|
815
|
+
try {
|
|
816
|
+
return placementOf(JSON.parse(readFileSync(join(root, "package.json"), "utf8")).keywords);
|
|
817
|
+
} catch {
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
798
821
|
/**
|
|
799
822
|
* Share one local plugin through the plugin-hub path, exactly as the person confirmed it: the plan is read again, and when it no longer matches
|
|
800
823
|
* (another account signed in, the repository made meanwhile, a version released) nothing is sent and the error says to look again. The hub then
|
|
@@ -3839,7 +3862,9 @@ function frameRoutes({ state, report = () => {}, plugins, graph, feedback, branc
|
|
|
3839
3862
|
try {
|
|
3840
3863
|
const asked = body.visibility;
|
|
3841
3864
|
const listed = body.registry === true;
|
|
3842
|
-
|
|
3865
|
+
const owner = parseShareOwner(body.owner);
|
|
3866
|
+
if (owner === null) return c.json(error("the GitHub account or organization is not a GitHub name"), 400);
|
|
3867
|
+
return c.json(await plugins.planShare(name, listed ? "public" : asked === "public" || asked === "private" ? asked : void 0, listed, owner));
|
|
3843
3868
|
} catch (cause) {
|
|
3844
3869
|
report(cause);
|
|
3845
3870
|
return c.json(plainBody(plainShareProblem(cause)), 409);
|
|
@@ -3870,8 +3895,10 @@ function frameRoutes({ state, report = () => {}, plugins, graph, feedback, branc
|
|
|
3870
3895
|
} catch {
|
|
3871
3896
|
return c.json(error("a share is published only after the person confirms its plan"), 400);
|
|
3872
3897
|
}
|
|
3898
|
+
const owner = parseShareOwner(fields?.owner);
|
|
3899
|
+
if (owner === null) return c.json(error("the GitHub account or organization is not a GitHub name"), 400);
|
|
3873
3900
|
try {
|
|
3874
|
-
return c.json(await plugins.share(name, confirmed));
|
|
3901
|
+
return c.json(await plugins.share(name, confirmed, owner));
|
|
3875
3902
|
} catch (cause) {
|
|
3876
3903
|
report(cause);
|
|
3877
3904
|
return c.json(plainBody(plainShareProblem(cause)), 409);
|
|
@@ -4130,12 +4157,16 @@ function apply(ctx, config = {}) {
|
|
|
4130
4157
|
const entry = loader === void 0 ? void 0 : [...loader.entries()].find((row) => row.options.id === APP_PLUGINS_ROW);
|
|
4131
4158
|
if (entry?.fiber !== void 0) await entry.fiber.restart();
|
|
4132
4159
|
},
|
|
4133
|
-
planShare: async (name, visibility, registry) => planAppPluginShare(root, ctx.appInstance.home, name, {
|
|
4160
|
+
planShare: async (name, visibility, registry, owner) => planAppPluginShare(root, ctx.appInstance.home, name, {
|
|
4134
4161
|
...shareTo,
|
|
4162
|
+
...owner === void 0 ? {} : { owner },
|
|
4135
4163
|
...visibility === void 0 ? {} : { visibility },
|
|
4136
4164
|
...registry === true ? { registry } : {}
|
|
4137
4165
|
}, githubSharePorts()),
|
|
4138
|
-
share: async (name, confirmed) => shareAppPlugin(root, ctx.appInstance.home, name, confirmed,
|
|
4166
|
+
share: async (name, confirmed, owner) => shareAppPlugin(root, ctx.appInstance.home, name, confirmed, {
|
|
4167
|
+
...shareTo,
|
|
4168
|
+
...owner === void 0 ? {} : { owner }
|
|
4169
|
+
}, githubSharePorts()),
|
|
4139
4170
|
save: async (name) => saveAppPlugin(root, ctx.appInstance.home, name),
|
|
4140
4171
|
github: async () => githubReadiness(() => githubSharePorts().host.login()),
|
|
4141
4172
|
connect: githubConnect,
|