@acryldev/blends-frame 0.2.5 → 0.2.7

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/contract.d.ts CHANGED
@@ -154,6 +154,24 @@ export declare const FRAME_APP_ICON_PATH = "/api/acryl-blends-frame/app/icon";
154
154
  export interface AppShareRequest {
155
155
  readonly owner?: string;
156
156
  readonly visibility?: 'private' | 'public';
157
+ /** List it in the Blends store; a part not given is the app's own (its earlier place, else its starter's category; MIT). */
158
+ readonly list?: {
159
+ readonly category?: string;
160
+ readonly subcategory?: string;
161
+ readonly license?: string;
162
+ };
163
+ }
164
+ /** The Blends store's categories (published by acrylblends.github.io; @acryldev/app-persistence CATEGORIES_URL names the same list). */
165
+ export declare const STORE_CATEGORIES_URL = "https://acrylblends.github.io/categories.json";
166
+ /** How the Blends store will list the app (the save plugin's StoreListing): its id, place (category slugs), licence and the tag people start from. */
167
+ export interface AppStoreListingView {
168
+ readonly id: string;
169
+ readonly placement: {
170
+ readonly category: string;
171
+ readonly subcategory?: string;
172
+ };
173
+ readonly license: string;
174
+ readonly tag: string;
157
175
  }
158
176
  /** What sharing the app sends: the save plugin's plan, shown before anything leaves the computer. */
159
177
  export interface AppSharePlanView {
@@ -163,11 +181,17 @@ export interface AppSharePlanView {
163
181
  readonly visibility: 'private' | 'public';
164
182
  /** Files changed since the last save; the share saves them first. */
165
183
  readonly changes: number;
184
+ readonly listing?: AppStoreListingView;
166
185
  }
167
186
  /** Where the app went. */
168
187
  export interface AppSharedView {
169
188
  readonly remote: string;
170
189
  readonly created: boolean;
190
+ /** The tag the store lists, and whether this share made it (an existing tag is kept). */
191
+ readonly listed?: {
192
+ readonly tag: string;
193
+ readonly created: boolean;
194
+ };
171
195
  }
172
196
  export declare function parseAppSharePlan(value: unknown): AppSharePlanView;
173
197
  export declare function parseAppShared(value: unknown): AppSharedView;
@@ -223,6 +247,11 @@ export interface SharePlan {
223
247
  readonly license?: string;
224
248
  /** The public registry (cordisplugins.github.io) lists it: the share sets the `cordis-plugin` topic. Only a public share can be listed. */
225
249
  readonly registry?: boolean;
250
+ /** Where the registry lists it (category slugs of acrylblends.github.io/blends): the app's own store place, written as package.json keywords. */
251
+ readonly placement?: {
252
+ readonly category: string;
253
+ readonly subcategory?: string;
254
+ };
226
255
  }
227
256
  /** @throws when the value is not a share plan. */
228
257
  export declare function parseSharePlan(value: unknown): SharePlan;
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";
@@ -113,27 +113,69 @@ const FRAME_APP_SHARE_PLAN_PATH = `${FRAME_API_PREFIX}/app/share-plan`;
113
113
  const FRAME_APP_SHARE_PATH = `${FRAME_API_PREFIX}/app/share`;
114
114
  /** POST `{ png: base64 }`: the app's own icon (assets/icon.png), drawn by the page at 512 px. */
115
115
  const FRAME_APP_ICON_PATH = `${FRAME_API_PREFIX}/app/icon`;
116
+ const SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
117
+ const LICENSE = /^[A-Za-z0-9][A-Za-z0-9.+-]*$/u;
118
+ function parseListing(value) {
119
+ if (value === void 0) return void 0;
120
+ if (!isRecord$2(value) || !isRecord$2(value.placement)) throw new Error("app share plan: listing");
121
+ const { id, license, tag } = value;
122
+ const { category, subcategory } = value.placement;
123
+ if (typeof id !== "string" || typeof license !== "string" || typeof tag !== "string" || typeof category !== "string") throw new Error("app share plan: listing");
124
+ if (subcategory !== void 0 && typeof subcategory !== "string") throw new Error("app share plan: listing subcategory");
125
+ return {
126
+ id,
127
+ placement: {
128
+ category,
129
+ ...subcategory === void 0 ? {} : { subcategory }
130
+ },
131
+ license,
132
+ tag
133
+ };
134
+ }
116
135
  function parseAppSharePlan(value) {
117
136
  if (!isRecord$2(value)) throw new Error("app share plan: not a plan");
118
137
  const { repository, create, visibility, changes } = value;
119
138
  if (typeof repository !== "string" || repository === "" || typeof create !== "boolean") throw new Error("app share plan: repository");
120
139
  if (visibility !== "private" && visibility !== "public") throw new Error("app share plan: visibility");
121
140
  if (typeof changes !== "number" || !Number.isSafeInteger(changes) || changes < 0) throw new Error("app share plan: changes");
141
+ const listing = parseListing(value.listing);
122
142
  return {
123
143
  repository,
124
144
  create,
125
145
  visibility,
126
- changes
146
+ changes,
147
+ ...listing === void 0 ? {} : { listing }
148
+ };
149
+ }
150
+ function parseAppShared(value) {
151
+ if (!isRecord$2(value) || typeof value.remote !== "string" || typeof value.created !== "boolean") throw new Error("app share: where it went");
152
+ const listed = isRecord$2(value.listed) && typeof value.listed.tag === "string" && typeof value.listed.created === "boolean" ? {
153
+ tag: value.listed.tag,
154
+ created: value.listed.created
155
+ } : void 0;
156
+ return {
157
+ remote: value.remote,
158
+ created: value.created,
159
+ ...listed === void 0 ? {} : { listed }
127
160
  };
128
161
  }
129
162
  function parseAppShareRequest(value) {
130
163
  if (!isRecord$2(value)) return void 0;
131
- const { owner, visibility } = value;
164
+ const { owner, visibility, list } = value;
132
165
  if (owner !== void 0 && (typeof owner !== "string" || !GITHUB_NAME.test(owner))) return void 0;
133
166
  if (visibility !== void 0 && visibility !== "private" && visibility !== "public") return void 0;
167
+ if (list !== void 0 && !isRecord$2(list)) return void 0;
168
+ const asked = list === void 0 ? void 0 : {
169
+ category: list.category,
170
+ subcategory: list.subcategory,
171
+ license: list.license
172
+ };
173
+ if (asked !== void 0 && ([asked.category, asked.subcategory].some((slug) => slug !== void 0 && (typeof slug !== "string" || !SLUG.test(slug))) || asked.license !== void 0 && (typeof asked.license !== "string" || !LICENSE.test(asked.license)))) return void 0;
174
+ if (asked !== void 0 && asked.category === void 0 && asked.subcategory !== void 0) return void 0;
134
175
  return {
135
176
  ...owner === void 0 ? {} : { owner },
136
- ...visibility === void 0 ? {} : { visibility }
177
+ ...visibility === void 0 ? {} : { visibility },
178
+ ...asked === void 0 ? {} : { list: Object.fromEntries(Object.entries(asked).filter(([, v]) => v !== void 0)) }
137
179
  };
138
180
  }
139
181
  const FRAME_PLUGINS_SHARE_PLAN_PATH = `${FRAME_API_PREFIX}/plugins/share-plan`;
@@ -153,13 +195,18 @@ const GITHUB_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/u;
153
195
  /** @throws when the value is not a share plan. */
154
196
  function parseSharePlan(value) {
155
197
  if (!isRecord$2(value)) throw new Error("share plan: not a plan");
156
- const { owner, repo, version, visibility, createsRepository, released, license, registry } = value;
198
+ const { owner, repo, version, visibility, createsRepository, released, license, registry, placement } = value;
157
199
  if (typeof owner !== "string" || !GITHUB_NAME.test(owner) || typeof repo !== "string" || !GITHUB_NAME.test(repo)) throw new Error("share plan: repository");
158
200
  if (typeof version !== "string" || version === "" || released !== void 0 && (typeof released !== "string" || released === "")) throw new Error("share plan: version");
159
201
  if (visibility !== "private" && visibility !== "public" || typeof createsRepository !== "boolean") throw new Error("share plan: visibility");
160
202
  if (license !== void 0 && (typeof license !== "string" || !/^[A-Za-z0-9.+-]+$/u.test(license))) throw new Error("share plan: license");
161
203
  if (registry !== void 0 && typeof registry !== "boolean") throw new Error("share plan: registry");
162
204
  if (registry === true && visibility !== "public") throw new Error("share plan: only a public share can be listed in the registry");
205
+ const place = placement === void 0 ? void 0 : isRecord$2(placement) && typeof placement.category === "string" && (placement.subcategory === void 0 || typeof placement.subcategory === "string") ? {
206
+ category: placement.category,
207
+ ...typeof placement.subcategory === "string" ? { subcategory: placement.subcategory } : {}
208
+ } : null;
209
+ if (place === null) throw new Error("share plan: placement");
163
210
  return {
164
211
  owner,
165
212
  repo,
@@ -168,12 +215,13 @@ function parseSharePlan(value) {
168
215
  createsRepository,
169
216
  ...released === void 0 ? {} : { released },
170
217
  ...license === void 0 ? {} : { license },
171
- ...registry === true ? { registry } : {}
218
+ ...registry === true ? { registry } : {},
219
+ ...place === void 0 ? {} : { placement: place }
172
220
  };
173
221
  }
174
222
  /** The same plan: what the person confirmed is what would be published now. */
175
223
  function samePlan(a, b) {
176
- 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);
224
+ 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;
177
225
  }
178
226
  const FRAME_FEEDBACK_PATH = `${FRAME_API_PREFIX}/feedback`;
179
227
  const FRAME_FEEDBACK_SEEN_PATH = `${FRAME_API_PREFIX}/feedback/seen`;
@@ -582,7 +630,7 @@ async function readFramePlugins(root, rows) {
582
630
  }
583
631
  /** The package.json a local plugin is shared with: the fields the builder's package_plugin writes (plugins/builder/index.ts), plus the Loader
584
632
  * patch the plugin-hub's share requires so the package can also be installed as a row. */
585
- function pluginPackageManifest(name, description, version = "0.1.0", license) {
633
+ function pluginPackageManifest(name, description, version = "0.1.0", license, placement) {
586
634
  return {
587
635
  name,
588
636
  version,
@@ -600,11 +648,11 @@ function pluginPackageManifest(name, description, version = "0.1.0", license) {
600
648
  "cordis.patch.yml"
601
649
  ],
602
650
  peerDependencies: { "@deepseek-ai/cordis": "4.0.4" },
603
- keywords: [
651
+ keywords: withPlacement([
604
652
  "cordis",
605
653
  "cordis-plugin",
606
654
  "acrylblends"
607
- ],
655
+ ], placement),
608
656
  dsh: { bundle: { patch: "./cordis.patch.yml" } }
609
657
  };
610
658
  }
@@ -645,7 +693,7 @@ async function recordShare(file, name, shared) {
645
693
  /** 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. */
646
694
  const pluginPackagesOf = (home) => join(home, "plugin-packages");
647
695
  /** Copy one local plugin into its package folder under `packages`, the way the builder's package_plugin does; answers the folder. */
648
- async function packageAppPlugin(root, name, packages, license) {
696
+ async function packageAppPlugin(root, name, packages, license, placement) {
649
697
  if (!(await madePlugins(root)).includes(name)) throw new Error(`plugins/ has no local plugin "${name}"`);
650
698
  const source = join(root, "plugins", name);
651
699
  const target = join(packages, name);
@@ -664,7 +712,7 @@ async function packageAppPlugin(root, name, packages, license) {
664
712
  filter: (path) => !/(^|[\\/])(node_modules|\.git)([\\/]|$)/u.test(path.slice(source.length))
665
713
  });
666
714
  const description = await packageDescription(source);
667
- writeFileSync(join(target, "package.json"), `${JSON.stringify(pluginPackageManifest(name, description, version, license), null, 2)}\n`);
715
+ writeFileSync(join(target, "package.json"), `${JSON.stringify(pluginPackageManifest(name, description, version, license, placement), null, 2)}\n`);
668
716
  writeFileSync(join(target, "cordis.patch.yml"), `- insert:\n - id: ${name}\n name: ./index.ts\n`);
669
717
  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`);
670
718
  return target;
@@ -734,7 +782,8 @@ async function planAppPluginShare(root, home, name, options, ports) {
734
782
  const registry = options.registry === true;
735
783
  const visibility = registry ? "public" : options.visibility ?? "private";
736
784
  const license = visibility === "public" ? options.license ?? "MIT" : void 0;
737
- const dir = await packageAppPlugin(root, name, pluginPackagesOf(home), license);
785
+ const placement = registry ? appPlacement(root) : void 0;
786
+ const dir = await packageAppPlugin(root, name, pluginPackagesOf(home), license, placement);
738
787
  const manifest = JSON.parse(await readFile(join(dir, "package.json"), "utf8"));
739
788
  const current = typeof manifest.version === "string" && parseVersion(manifest.version) !== void 0 ? manifest.version : void 0;
740
789
  if (current === void 0) throw new Error(`${name}: its package has no semantic version`);
@@ -750,9 +799,17 @@ async function planAppPluginShare(root, home, name, options, ports) {
750
799
  createsRepository: existing === void 0,
751
800
  ...released ? { released: current } : {},
752
801
  ...license === void 0 ? {} : { license },
753
- ...registry ? { registry } : {}
802
+ ...registry ? { registry } : {},
803
+ ...placement === void 0 ? {} : { placement }
754
804
  };
755
805
  }
806
+ function appPlacement(root) {
807
+ try {
808
+ return placementOf(JSON.parse(readFileSync(join(root, "package.json"), "utf8")).keywords);
809
+ } catch {
810
+ return;
811
+ }
812
+ }
756
813
  /**
757
814
  * 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
758
815
  * (another account signed in, the repository made meanwhile, a version released) nothing is sent and the error says to look again. The hub then
@@ -884,7 +941,14 @@ function lastJson(text) {
884
941
  if (value !== null && typeof value === "object" && !Array.isArray(value)) return value;
885
942
  } catch {}
886
943
  }
887
- const requestArgs = (request) => [...request.owner === void 0 ? [] : ["--owner", request.owner], ...request.visibility === void 0 ? [] : ["--visibility", request.visibility]];
944
+ const requestArgs = (request) => [
945
+ ...request.owner === void 0 ? [] : ["--owner", request.owner],
946
+ ...request.visibility === void 0 ? [] : ["--visibility", request.visibility],
947
+ ...request.list === void 0 ? [] : ["--list"],
948
+ ...request.list?.category === void 0 ? [] : ["--category", request.list.category],
949
+ ...request.list?.subcategory === void 0 ? [] : ["--subcategory", request.list.subcategory],
950
+ ...request.list?.license === void 0 ? [] : ["--license", request.list.license]
951
+ ];
888
952
  function appShareCommand(root, env = process.env, run = runCommand(root, env)) {
889
953
  const ask = async (args) => {
890
954
  if (!existsSync(join(root, SHARE_COMMAND))) throw new AppShareRefused("This app was made before apps could share themselves. Update it (npx acrylblends@latest update), then try again.");
@@ -908,10 +972,7 @@ function appShareCommand(root, env = process.env, run = runCommand(root, env)) {
908
972
  Buffer.from(JSON.stringify(confirmed), "utf8").toString("base64url")
909
973
  ]);
910
974
  if (answer.ok !== true || typeof answer.remote !== "string") throw new Error("the app did not say where it was shared");
911
- return {
912
- remote: answer.remote,
913
- created: answer.created === true
914
- };
975
+ return parseAppShared(answer);
915
976
  }
916
977
  };
917
978
  }
@@ -3562,7 +3623,8 @@ function frameRoutes({ state, report = () => {}, plugins, graph, feedback, branc
3562
3623
  const fields = body === INVALID_JSON || body === null || typeof body !== "object" ? void 0 : body;
3563
3624
  const request = fields === void 0 ? void 0 : parseAppShareRequest({
3564
3625
  owner: fields.owner,
3565
- visibility: fields.visibility
3626
+ visibility: fields.visibility,
3627
+ list: fields.list
3566
3628
  });
3567
3629
  if (request === void 0) return c.json(error("invalid share request"), 400);
3568
3630
  let confirmed;