@acryldev/blends-frame 0.2.10 → 0.2.11

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
@@ -252,6 +252,12 @@ export interface SharePlan {
252
252
  readonly license?: string;
253
253
  /** The public registry (cordisplugins.github.io) lists it: the share sets the `cordis-plugin` topic. Only a public share can be listed. */
254
254
  readonly registry?: boolean;
255
+ /** npm, not GitHub: the package, the registry and the digest of the bytes that were planned. `owner` is the package's scope and `repo` the plugin's name. */
256
+ readonly npm?: {
257
+ readonly package: string;
258
+ readonly registry: string;
259
+ readonly digest: string;
260
+ };
255
261
  /** Where the registry lists it (category slugs of acrylblends.github.io/blends): the app's own store place, written as package.json keywords. */
256
262
  readonly placement?: {
257
263
  readonly category: string;
@@ -415,6 +421,8 @@ export interface RegistryEntryView {
415
421
  readonly installed: boolean;
416
422
  /** The account the person is signed in to GitHub with (or shares to) released it. */
417
423
  readonly mine: boolean;
424
+ /** The version the app pulled it at, when the registry lists a newer one: the row offers the update. */
425
+ readonly updateFrom?: string;
418
426
  /** Bytes it downloads besides itself for this computer (a native package, plugin-share/native.ts), when the index says. */
419
427
  readonly download?: number;
420
428
  }
package/lib/index.d.ts CHANGED
@@ -62,7 +62,7 @@ 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, owner?: string): Promise<SharePlan>;
65
+ planShare(name: string, visibility?: ShareVisibility, registry?: boolean, owner?: string, npm?: boolean): 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
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. */
package/lib/index.js CHANGED
@@ -204,13 +204,19 @@ const GITHUB_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/u;
204
204
  /** @throws when the value is not a share plan. */
205
205
  function parseSharePlan(value) {
206
206
  if (!isRecord$2(value)) throw new Error("share plan: not a plan");
207
- const { owner, repo, version, visibility, createsRepository, released, license, registry, placement } = value;
207
+ const { owner, repo, version, visibility, createsRepository, released, license, registry, placement, npm } = value;
208
208
  if (typeof owner !== "string" || !GITHUB_NAME.test(owner) || typeof repo !== "string" || !GITHUB_NAME.test(repo)) throw new Error("share plan: repository");
209
209
  if (typeof version !== "string" || version === "" || released !== void 0 && (typeof released !== "string" || released === "")) throw new Error("share plan: version");
210
210
  if (visibility !== "private" && visibility !== "public" || typeof createsRepository !== "boolean") throw new Error("share plan: visibility");
211
211
  if (license !== void 0 && (typeof license !== "string" || !/^[A-Za-z0-9.+-]+$/u.test(license))) throw new Error("share plan: license");
212
212
  if (registry !== void 0 && typeof registry !== "boolean") throw new Error("share plan: registry");
213
213
  if (registry === true && visibility !== "public") throw new Error("share plan: only a public share can be listed in the registry");
214
+ const onNpm = npm === void 0 ? void 0 : isRecord$2(npm) && typeof npm.package === "string" && npm.package !== "" && typeof npm.registry === "string" && /^https?:\/\//u.test(npm.registry) && typeof npm.digest === "string" && /^[0-9a-f]{64}$/u.test(npm.digest) ? {
215
+ package: npm.package,
216
+ registry: npm.registry,
217
+ digest: npm.digest
218
+ } : null;
219
+ if (onNpm === null) throw new Error("share plan: npm");
214
220
  const place = placement === void 0 ? void 0 : isRecord$2(placement) && typeof placement.category === "string" && (placement.subcategory === void 0 || typeof placement.subcategory === "string") ? {
215
221
  category: placement.category,
216
222
  ...typeof placement.subcategory === "string" ? { subcategory: placement.subcategory } : {}
@@ -225,12 +231,13 @@ function parseSharePlan(value) {
225
231
  ...released === void 0 ? {} : { released },
226
232
  ...license === void 0 ? {} : { license },
227
233
  ...registry === true ? { registry } : {},
234
+ ...onNpm === void 0 ? {} : { npm: onNpm },
228
235
  ...place === void 0 ? {} : { placement: place }
229
236
  };
230
237
  }
231
238
  /** The same plan: what the person confirmed is what would be published now. */
232
239
  function samePlan(a, b) {
233
- 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;
240
+ 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.npm?.package === b.npm?.package && a.npm?.registry === b.npm?.registry && a.npm?.digest === b.npm?.digest && a.placement?.category === b.placement?.category && a.placement?.subcategory === b.placement?.subcategory;
234
241
  }
235
242
  const FRAME_FEEDBACK_PATH = `${FRAME_API_PREFIX}/feedback`;
236
243
  const FRAME_FEEDBACK_SEEN_PATH = `${FRAME_API_PREFIX}/feedback/seen`;
@@ -1472,6 +1479,57 @@ function createGraphPort(ctx, appRoot) {
1472
1479
  }
1473
1480
  };
1474
1481
  }
1482
+ // src/npm-share.ts
1483
+ /** The running app's service, read at each call; undefined when the app has none (an app made before plugin-share, or one that left the row out). */
1484
+ function npmShareOf(service) {
1485
+ const share = service();
1486
+ return typeof share?.planPublish === "function" && typeof share.publish === "function" ? share : void 0;
1487
+ }
1488
+ const asked = (scope) => ({
1489
+ to: "npm",
1490
+ ...scope === void 0 ? {} : { scope }
1491
+ });
1492
+ const refusedBy = (answer) => typeof answer === "object" && answer !== null && answer.ok === false;
1493
+ const sentence = (refused) => `${refused.reason}. ${refused.next}.`;
1494
+ const planOf = (plan) => ({
1495
+ owner: plan.owner,
1496
+ repo: plan.repo,
1497
+ version: plan.version,
1498
+ visibility: "public",
1499
+ createsRepository: false,
1500
+ ...plan.released === void 0 ? {} : { released: plan.released },
1501
+ license: plan.license,
1502
+ npm: {
1503
+ package: plan.package ?? `@${plan.owner}/${plan.repo}`,
1504
+ registry: plan.registry ?? "https://registry.npmjs.org/",
1505
+ digest: plan.digest
1506
+ }
1507
+ });
1508
+ /** @throws with the service's reason when the plan is refused (not signed in to npm, a secret in the plugin, ...). */
1509
+ async function planNpmShare(service, name, scope) {
1510
+ if (service === void 0) throw new Error("this app has no plugin-share service, which publishing to npm needs");
1511
+ const plan = await service.planPublish(name, asked(scope));
1512
+ if (refusedBy(plan)) throw new Error(sentence(plan));
1513
+ return planOf(plan);
1514
+ }
1515
+ /** Publish the plan the person confirmed: a plan made again must be the same, and then the service publishes it. @throws when it changed or was refused. */
1516
+ async function shareNpm(service, name, confirmed, scope) {
1517
+ if (service === void 0 || confirmed.npm === void 0) throw new Error("this app has no plugin-share service, which publishing to npm needs");
1518
+ const plan = await service.planPublish(name, asked(scope));
1519
+ if (refusedBy(plan)) throw new Error(sentence(plan));
1520
+ const now = planOf(plan);
1521
+ if (now.npm?.package !== confirmed.npm.package || now.npm?.registry !== confirmed.npm.registry || now.npm?.digest !== confirmed.npm.digest || now.version !== confirmed.version || now.license !== confirmed.license) throw new Error(`The share changed since you confirmed it (${confirmed.npm.package} v${now.version}); nothing was sent. Look at it again.`);
1522
+ const result = await service.publish(name, plan, asked(scope));
1523
+ if (refusedBy(result)) throw new Error(sentence(result));
1524
+ const published = result;
1525
+ return {
1526
+ url: published.url,
1527
+ version: published.version,
1528
+ owner: plan.owner,
1529
+ repo: plan.repo,
1530
+ tag: `v${published.version}`
1531
+ };
1532
+ }
1475
1533
  // src/registry.ts
1476
1534
  const REGISTRY_INDEX_URL = "https://cordisplugins.github.io/registry/index.json";
1477
1535
  /** What the person is told when the registry cannot be read. */
@@ -1481,6 +1539,17 @@ const CHANGED = "The registry answered in a way this app does not understand. Tr
1481
1539
  const SOURCE = /\bgithub:([A-Za-z0-9][A-Za-z0-9-]*)\/([A-Za-z0-9][A-Za-z0-9._-]*)@([0-9][0-9A-Za-z.+-]*)/u;
1482
1540
  /** A plugin's folder name: the name without its scope, lower case (`@owner/notes` is `notes`). */
1483
1541
  const bareName = (name) => (name.includes("/") ? name.slice(name.lastIndexOf("/") + 1) : name).toLowerCase();
1542
+ /** Whether dotted version `a` is newer than `b` (numbers, left to right; a pre-release suffix is ignored): `1.10.0` is newer than `1.9.0`. */
1543
+ function newerVersion(a, b) {
1544
+ const parts = (version) => version.split(/[-+]/u)[0]?.split(".").map(Number) ?? [];
1545
+ const [x, y] = [parts(a), parts(b)];
1546
+ for (let i = 0; i < Math.max(x.length, y.length); i++) {
1547
+ const [p, q] = [x[i] ?? 0, y[i] ?? 0];
1548
+ if (Number.isNaN(p) || Number.isNaN(q)) return false;
1549
+ if (p !== q) return p > q;
1550
+ }
1551
+ return false;
1552
+ }
1484
1553
  /** `owner/repo` of a `github:` source, lower case; undefined for any other source. */
1485
1554
  function repoOfSource(source) {
1486
1555
  const match = SOURCE.exec(source);
@@ -1513,6 +1582,7 @@ function registryEntries(index, marks) {
1513
1582
  const owner = where[1] ?? "";
1514
1583
  const repository = repoOfSource(source);
1515
1584
  const download = downloadFor(native);
1585
+ const pulledAt = repository === void 0 ? void 0 : marks.pulled?.get(repository);
1516
1586
  entries.push({
1517
1587
  name,
1518
1588
  description: typeof description === "string" ? description : "",
@@ -1525,6 +1595,7 @@ function registryEntries(index, marks) {
1525
1595
  source,
1526
1596
  installed: marks.names.has(bareName(name)) || repository !== void 0 && marks.repos.has(repository),
1527
1597
  mine: marks.accounts.has(owner.toLowerCase()),
1598
+ ...pulledAt !== void 0 && newerVersion(version, pulledAt) ? { updateFrom: pulledAt } : {},
1528
1599
  ...download === void 0 ? {} : { download }
1529
1600
  });
1530
1601
  }
@@ -3851,7 +3922,8 @@ function frameRoutes({ state, report = () => {}, plugins, graph, feedback, branc
3851
3922
  const listed = body.registry === true;
3852
3923
  const owner = parseShareOwner(body.owner);
3853
3924
  if (owner === null) return c.json(error("the GitHub account or organization is not a GitHub name"), 400);
3854
- return c.json(await plugins.planShare(name, listed ? "public" : asked === "public" || asked === "private" ? asked : void 0, listed, owner));
3925
+ const onNpm = body.npm === true;
3926
+ return c.json(await plugins.planShare(name, listed || onNpm ? "public" : asked === "public" || asked === "private" ? asked : void 0, listed, owner, onNpm));
3855
3927
  } catch (cause) {
3856
3928
  report(cause);
3857
3929
  return c.json(plainBody(plainShareProblem(cause)), 409);
@@ -4165,13 +4237,13 @@ function apply(ctx, config = {}) {
4165
4237
  const entry = loader === void 0 ? void 0 : [...loader.entries()].find((row) => row.options.id === APP_PLUGINS_ROW);
4166
4238
  if (entry?.fiber !== void 0) await entry.fiber.restart();
4167
4239
  },
4168
- planShare: async (name, visibility, registry, owner) => planAppPluginShare(root, ctx.appInstance.home, name, {
4240
+ planShare: async (name, visibility, registry, owner, npm) => npm === true ? planNpmShare(npmShareOf(() => ctx.get("pluginShare")), name, owner) : planAppPluginShare(root, ctx.appInstance.home, name, {
4169
4241
  ...shareTo,
4170
4242
  ...owner === void 0 ? {} : { owner },
4171
4243
  ...visibility === void 0 ? {} : { visibility },
4172
4244
  ...registry === true ? { registry } : {}
4173
4245
  }, githubSharePorts()),
4174
- share: async (name, confirmed, owner) => shareAppPlugin(root, ctx.appInstance.home, name, confirmed, {
4246
+ share: async (name, confirmed, owner) => confirmed.npm !== void 0 ? shareNpm(npmShareOf(() => ctx.get("pluginShare")), name, confirmed, owner) : shareAppPlugin(root, ctx.appInstance.home, name, confirmed, {
4175
4247
  ...shareTo,
4176
4248
  ...owner === void 0 ? {} : { owner }
4177
4249
  }, githubSharePorts()),
@@ -4208,6 +4280,11 @@ function apply(ctx, config = {}) {
4208
4280
  const listed = pluginShareOf(() => ctx.get("pluginShare"))?.list() ?? [];
4209
4281
  const names = /* @__PURE__ */ new Set([...frameRows().map((row) => bareName(row.name)), ...listed.map((info) => bareName(info.name))]);
4210
4282
  const repos = new Set(listed.flatMap((info) => info.pulledFrom === void 0 ? [] : [repoOfSource(info.pulledFrom) ?? ""]).filter((repo) => repo !== ""));
4283
+ const pulled = new Map(listed.flatMap((info) => {
4284
+ const repo = info.pulledFrom === void 0 ? void 0 : repoOfSource(info.pulledFrom);
4285
+ const version = info.pulledFrom === void 0 ? void 0 : /@([0-9][0-9A-Za-z.+-]*)$/u.exec(info.pulledFrom)?.[1];
4286
+ return repo === void 0 || version === void 0 ? [] : [[repo, version]];
4287
+ }));
4211
4288
  if (signedIn === void 0 || Date.now() - signedIn.at > 6e4) {
4212
4289
  const ready = await githubNow();
4213
4290
  signedIn = {
@@ -4218,6 +4295,7 @@ function apply(ctx, config = {}) {
4218
4295
  return {
4219
4296
  names,
4220
4297
  repos,
4298
+ pulled,
4221
4299
  accounts: /* @__PURE__ */ new Set([...shareOwner === void 0 ? [] : [shareOwner.toLowerCase()], ...signedIn.account === void 0 ? [] : [signedIn.account.toLowerCase()]])
4222
4300
  };
4223
4301
  };