initiative-plugin-sdk 2.0.0

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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +656 -0
  3. package/dist/build.d.ts +52 -0
  4. package/dist/build.js +229 -0
  5. package/dist/build.js.map +1 -0
  6. package/dist/cli.d.ts +24 -0
  7. package/dist/cli.js +160 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/client.d.ts +288 -0
  10. package/dist/client.js +539 -0
  11. package/dist/client.js.map +1 -0
  12. package/dist/contract.d.ts +1247 -0
  13. package/dist/contract.js +167 -0
  14. package/dist/contract.js.map +1 -0
  15. package/dist/define.d.ts +336 -0
  16. package/dist/define.js +120 -0
  17. package/dist/define.js.map +1 -0
  18. package/dist/dev.d.ts +28 -0
  19. package/dist/dev.js +147 -0
  20. package/dist/dev.js.map +1 -0
  21. package/dist/expression.d.ts +28 -0
  22. package/dist/expression.js +67 -0
  23. package/dist/expression.js.map +1 -0
  24. package/dist/init.d.ts +14 -0
  25. package/dist/init.js +52 -0
  26. package/dist/init.js.map +1 -0
  27. package/dist/keys.d.ts +85 -0
  28. package/dist/keys.js +109 -0
  29. package/dist/keys.js.map +1 -0
  30. package/dist/manifest.d.ts +8 -0
  31. package/dist/manifest.js +8 -0
  32. package/dist/manifest.js.map +1 -0
  33. package/dist/pack.d.ts +35 -0
  34. package/dist/pack.js +84 -0
  35. package/dist/pack.js.map +1 -0
  36. package/dist/plugin-api.generated.d.ts +4263 -0
  37. package/dist/plugin-api.generated.js +1019 -0
  38. package/dist/plugin-api.generated.js.map +1 -0
  39. package/dist/server.d.ts +75 -0
  40. package/dist/server.js +408 -0
  41. package/dist/server.js.map +1 -0
  42. package/dist/testing.d.ts +116 -0
  43. package/dist/testing.js +386 -0
  44. package/dist/testing.js.map +1 -0
  45. package/dist/tokens.d.ts +161 -0
  46. package/dist/tokens.js +215 -0
  47. package/dist/tokens.js.map +1 -0
  48. package/dist/validate.d.ts +86 -0
  49. package/dist/validate.js +997 -0
  50. package/dist/validate.js.map +1 -0
  51. package/dist/widget.d.ts +235 -0
  52. package/dist/widget.js +26 -0
  53. package/dist/widget.js.map +1 -0
  54. package/examples/minimal/README.md +48 -0
  55. package/examples/minimal/assets/avatar.png +0 -0
  56. package/examples/minimal/package.json +22 -0
  57. package/examples/minimal/src/plugin.ts +77 -0
  58. package/examples/minimal/src/widgets/open-issues.ts +11 -0
  59. package/examples/minimal/test/fixtures/issues-statistics.json +9 -0
  60. package/examples/minimal/test/issue-counts.test.ts +48 -0
  61. package/examples/minimal/tsconfig.json +14 -0
  62. package/manifest.contract.json +1886 -0
  63. package/package.json +92 -0
  64. package/schemas/plugin-manifest.json +1747 -0
package/dist/pack.js ADDED
@@ -0,0 +1,84 @@
1
+ /**
2
+ * `initiative-plugin pack`: the plug-in as one listing file, the file a self-hosted
3
+ * deployment publishes as its own plug-in.
4
+ *
5
+ * The listing file is the shape a deployment's listing upload
6
+ * (`POST /api/v1/marketplace/local/upload`, as `{"manifest": <file>}`) and its
7
+ * catalog directory (`MARKETPLACE_EXTRA_CATALOG_DIR`) read: what the catalogue
8
+ * shows, this version's manifest as its `definition`, and its registration.
9
+ * The manifest is the one `build` makes, checked the same way.
10
+ *
11
+ * The listing's picture is named by the path the deployment keeps it under,
12
+ * which is the SHA-256 of its bytes, so it is uploaded beside the file
13
+ * (`POST /api/v1/marketplace/local/media`). A deployment keeps PNG, JPEG, GIF
14
+ * and WebP; any other picture is left out, and the listing shows the
15
+ * deployment's default mark.
16
+ */
17
+ import { createHash } from "node:crypto";
18
+ import { readFileSync, writeFileSync } from "node:fs";
19
+ import { relative, resolve } from "node:path";
20
+ import { bundler, compile, registrationOf } from "./build.js";
21
+ /** Where a deployment serves the pictures uploaded for its listings. */
22
+ const MEDIA_PATH = "/api/v1/marketplace/media/";
23
+ const KEPT_PICTURES = /\.(png|jpe?g|gif|webp)$/i;
24
+ /** The listing file for a plug-in whose manifest `compile` made. */
25
+ export function listingFile(plugin, manifest, root) {
26
+ const listing = plugin.listing;
27
+ if (!listing)
28
+ throw new Error("pack needs the plug-in's listing: declare `listing` in its definition");
29
+ const avatar = KEPT_PICTURES.test(listing.avatar) ? readFileSync(resolve(root, listing.avatar)) : null;
30
+ // A deployment honours reference sectors only from a registry.
31
+ const { reference_sectors: _sectors, ...registration } = registrationOf(plugin);
32
+ return {
33
+ avatar,
34
+ listing: {
35
+ uid: plugin.uid,
36
+ public_id: plugin.publicId,
37
+ kind: "plugin",
38
+ name: plugin.name,
39
+ publisher: listing.publisher,
40
+ description: listing.summary,
41
+ ...(listing.description !== undefined ? { long_description: listing.description } : {}),
42
+ ...(avatar ? { avatar_url: `${MEDIA_PATH}${createHash("sha256").update(avatar).digest("hex")}` } : {}),
43
+ version: listing.version,
44
+ ...(listing.minAppVersion !== undefined ? { min_app_version: listing.minAppVersion } : {}),
45
+ ...(listing.releaseNotes !== undefined ? { release_notes: listing.releaseNotes } : {}),
46
+ definition: manifest,
47
+ registration,
48
+ },
49
+ };
50
+ }
51
+ /** Write the plug-in's listing file. Answers the process's exit code. */
52
+ export async function pack(options) {
53
+ const esbuild = await bundler("pack");
54
+ if (!esbuild)
55
+ return 1;
56
+ const root = resolve(options.root);
57
+ const compiled = await compile(esbuild, root, options.plugin);
58
+ if (compiled.problems) {
59
+ for (const problem of compiled.problems)
60
+ process.stderr.write(`${problem}\n`);
61
+ return 1;
62
+ }
63
+ const { plugin } = compiled;
64
+ let packed;
65
+ try {
66
+ packed = listingFile(plugin, compiled.manifest, root);
67
+ }
68
+ catch (error) {
69
+ process.stderr.write(`${error.message}\n`);
70
+ return 1;
71
+ }
72
+ const { avatar: picture, version } = plugin.listing;
73
+ const path = resolve(root, options.out ?? `${plugin.publicId}-${version}.json`);
74
+ writeFileSync(path, `${JSON.stringify(packed.listing, null, 2)}\n`);
75
+ process.stdout.write([
76
+ `wrote ${relative(process.cwd(), path)}: ${plugin.publicId} ${version}, uid ${plugin.uid}`,
77
+ packed.avatar
78
+ ? `upload it with its picture, ${picture}, or run initiative-plugin dev --initiative <url> to do both`
79
+ : `${picture} is not PNG, JPEG, GIF or WebP, so the listing shows the deployment's default mark`,
80
+ "",
81
+ ].join("\n"));
82
+ return 0;
83
+ }
84
+ //# sourceMappingURL=pack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack.js","sourceRoot":"","sources":["../src/pack.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAa9D,wEAAwE;AACxE,MAAM,UAAU,GAAG,4BAA4B,CAAC;AAChD,MAAM,aAAa,GAAG,0BAA0B,CAAC;AAQjD,oEAAoE;AACpE,MAAM,UAAU,WAAW,CAAC,MAAiB,EAAE,QAAkB,EAAE,IAAY;IAC7E,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IAC/B,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAC;IACvG,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACvG,+DAA+D;IAC/D,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,GAAG,YAAY,EAAE,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IAChF,OAAO;QACL,MAAM;QACN,OAAO,EAAE;YACP,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,SAA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