@justflows/sdk 0.0.0-stage → 1.2.1

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 (78) hide show
  1. package/README.md +95 -2
  2. package/dist/api-urls.d.ts +4 -0
  3. package/dist/api-urls.d.ts.map +1 -0
  4. package/dist/api-urls.js +22 -0
  5. package/dist/api-urls.js.map +1 -0
  6. package/dist/cache.d.ts +63 -0
  7. package/dist/cache.d.ts.map +1 -0
  8. package/dist/cache.js +28 -0
  9. package/dist/cache.js.map +1 -0
  10. package/dist/capabilities.d.ts +73 -0
  11. package/dist/capabilities.d.ts.map +1 -0
  12. package/dist/capabilities.js +118 -0
  13. package/dist/capabilities.js.map +1 -0
  14. package/dist/compatibility.d.ts +7 -0
  15. package/dist/compatibility.d.ts.map +1 -0
  16. package/dist/compatibility.js +7 -0
  17. package/dist/compatibility.js.map +1 -0
  18. package/dist/cookies.d.ts +60 -0
  19. package/dist/cookies.d.ts.map +1 -0
  20. package/dist/cookies.js +60 -0
  21. package/dist/cookies.js.map +1 -0
  22. package/dist/hooks.d.ts +1393 -0
  23. package/dist/hooks.d.ts.map +1 -0
  24. package/dist/hooks.js +102 -0
  25. package/dist/hooks.js.map +1 -0
  26. package/dist/index.d.ts +30 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +25 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/license.d.ts +26 -0
  31. package/dist/license.d.ts.map +1 -0
  32. package/dist/license.js +90 -0
  33. package/dist/license.js.map +1 -0
  34. package/dist/media-html.d.ts +85 -0
  35. package/dist/media-html.d.ts.map +1 -0
  36. package/dist/media-html.js +181 -0
  37. package/dist/media-html.js.map +1 -0
  38. package/dist/patterns.d.ts +72 -0
  39. package/dist/patterns.d.ts.map +1 -0
  40. package/dist/patterns.js +86 -0
  41. package/dist/patterns.js.map +1 -0
  42. package/dist/placeholders.d.ts +64 -0
  43. package/dist/placeholders.d.ts.map +1 -0
  44. package/dist/placeholders.js +38 -0
  45. package/dist/placeholders.js.map +1 -0
  46. package/dist/plugin.d.ts +2424 -0
  47. package/dist/plugin.d.ts.map +1 -0
  48. package/dist/plugin.js +724 -0
  49. package/dist/plugin.js.map +1 -0
  50. package/dist/publisher-namespace.d.ts +49 -0
  51. package/dist/publisher-namespace.d.ts.map +1 -0
  52. package/dist/publisher-namespace.js +106 -0
  53. package/dist/publisher-namespace.js.map +1 -0
  54. package/dist/registry.d.ts +64 -0
  55. package/dist/registry.d.ts.map +1 -0
  56. package/dist/registry.js +132 -0
  57. package/dist/registry.js.map +1 -0
  58. package/dist/search.d.ts +25 -0
  59. package/dist/search.d.ts.map +1 -0
  60. package/dist/search.js +2 -0
  61. package/dist/search.js.map +1 -0
  62. package/dist/spam.d.ts +30 -0
  63. package/dist/spam.d.ts.map +1 -0
  64. package/dist/spam.js +3 -0
  65. package/dist/spam.js.map +1 -0
  66. package/dist/templates.d.ts +37 -0
  67. package/dist/templates.d.ts.map +1 -0
  68. package/dist/templates.js +52 -0
  69. package/dist/templates.js.map +1 -0
  70. package/dist/version.d.ts +5 -0
  71. package/dist/version.d.ts.map +1 -0
  72. package/dist/version.js +6 -0
  73. package/dist/version.js.map +1 -0
  74. package/dist/visibility.d.ts +79 -0
  75. package/dist/visibility.d.ts.map +1 -0
  76. package/dist/visibility.js +3 -0
  77. package/dist/visibility.js.map +1 -0
  78. package/package.json +46 -4
package/dist/plugin.js ADDED
@@ -0,0 +1,724 @@
1
+ import { isValidPluginApiNamespace } from "./api-urls.js";
2
+ import { extensionIdNamespaceIssue, isApiNamespaceAllowedForExtension } from "./publisher-namespace.js";
3
+ import { z } from "zod";
4
+ import { gplLicenseValidationMessage, isAcceptedManifestLicense } from "./license.js";
5
+ import { RegistryListingSchema } from "./registry.js";
6
+ import { ExtensionEnginesSchema } from "./compatibility.js";
7
+ // ─── Plugin manifest ──────────────────────────────────────────────────────
8
+ export const PluginPermissionSchema = z.enum([
9
+ "content:read",
10
+ "content:create",
11
+ "content:update",
12
+ "content:delete",
13
+ "content:publish",
14
+ "content:revisions:read",
15
+ "content:revisions:restore",
16
+ "content:revisions:discard",
17
+ "media:read",
18
+ "media:upload",
19
+ "media:delete",
20
+ "users:read",
21
+ "users:manage",
22
+ "settings:read",
23
+ "settings:manage",
24
+ "network:outbound",
25
+ "admin:extend",
26
+ "jobs:register",
27
+ "diagnostics:publish",
28
+ "mail:send",
29
+ "mail:transport",
30
+ "mail:templates",
31
+ "mail:hook",
32
+ "auth:hook",
33
+ "platform:tenancy",
34
+ "platform:network",
35
+ "files:private",
36
+ "cache:store",
37
+ ]);
38
+ export const SENSITIVE_PERMISSIONS = [
39
+ "network:outbound",
40
+ "users:manage",
41
+ "settings:manage",
42
+ "auth:hook",
43
+ "mail:send",
44
+ "mail:transport",
45
+ "mail:templates",
46
+ "mail:hook",
47
+ "platform:tenancy",
48
+ "platform:network",
49
+ "cache:store",
50
+ ];
51
+ // ─── Admin menu contributions ─────────────────────────────────────────────
52
+ /** Sidebar groups an extension may contribute an admin page to. */
53
+ export const ADMIN_MENU_DOMAINS = [
54
+ "content",
55
+ "commerce",
56
+ "appearance",
57
+ "users",
58
+ "plugin",
59
+ "extensions",
60
+ "tools",
61
+ "security",
62
+ "system",
63
+ ];
64
+ /**
65
+ * The admin URL namespace the host reserves for one plugin's own pages:
66
+ * `/admin/plugins/<pluginId>`. Every plugin admin screen lives here, so a URL
67
+ * always says whether it is core or plugin-owned.
68
+ */
69
+ export function pluginAdminBasePath(pluginId) {
70
+ return `/admin/plugins/${pluginId}`;
71
+ }
72
+ const SLASH = "/".charCodeAt(0);
73
+ /**
74
+ * Strip leading and trailing `/` with plain index scans. `/^\/+|\/+$/` looks
75
+ * harmless but is quadratic on a long run of `/` that isn't anchored at the
76
+ * true end of the string (e.g. `"a" + "/".repeat(n) + "a"`): the engine
77
+ * retries the `\/+$` branch, and its backtrack, from every offset inside the
78
+ * run. `relativePath` below comes from plugin code, so treat it as
79
+ * untrusted input rather than relying on the regex engine to stay linear.
80
+ */
81
+ function stripSlashes(input) {
82
+ let start = 0;
83
+ let end = input.length;
84
+ while (start < end && input.charCodeAt(start) === SLASH)
85
+ start++;
86
+ while (end > start && input.charCodeAt(end - 1) === SLASH)
87
+ end--;
88
+ return input.slice(start, end);
89
+ }
90
+ /**
91
+ * Compose a plugin-relative admin path (`""`, `"orders"`, `"orders/refunds"`)
92
+ * into its absolute URL under the plugin's namespace. `""` / nullish is the
93
+ * namespace root.
94
+ */
95
+ export function resolvePluginAdminPath(pluginId, relativePath) {
96
+ const base = pluginAdminBasePath(pluginId);
97
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-conversion -- plain-JavaScript plugins may pass anything
98
+ const rel = stripSlashes(String(relativePath ?? ""));
99
+ return rel ? `${base}/${rel}` : base;
100
+ }
101
+ /**
102
+ * A plugin-relative admin path: the empty string (the plugin's namespace root)
103
+ * or a lowercase `leaf` / `leaf/child` under it. It must **not** start with
104
+ * `/`, name `admin`, contain a `.` (so it can never be an absolute `/admin/…`
105
+ * route or repeat the dot-namespaced plugin id) — the host prepends
106
+ * `/admin/plugins/<pluginId>/`.
107
+ */
108
+ export const RELATIVE_ADMIN_PATH_RE = /^(?:[a-z0-9][a-z0-9-]*(?:\/[a-z0-9][a-z0-9-]*)*)?$/;
109
+ const RelativeAdminPathSchema = z
110
+ .string()
111
+ .max(100)
112
+ .regex(RELATIVE_ADMIN_PATH_RE, 'Admin path is relative to /admin/plugins/<your plugin id>: use "" for the plugin\'s root page or a lowercase leaf like "orders" or "orders/refunds" — never a leading "/", "admin", the plugin id, or a ".".');
113
+ /**
114
+ * One admin navigation entry owned by a plugin. The host renders these only
115
+ * while the plugin is installed, so uninstalling a plugin takes its pages out
116
+ * of the sidebar with it.
117
+ */
118
+ export const AdminMenuItemSchema = z.object({
119
+ /** Unique within the plugin — used as the nav key and for de-duplication. */
120
+ id: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Menu id must be lowercase kebab-case"),
121
+ /** English label, shown when `labelKey` is absent or untranslated. */
122
+ label: z.string().min(1).max(60),
123
+ /**
124
+ * Optional i18n key. The host looks it up in the plugin's own
125
+ * `adminApp.locales` catalogs first, then in core's admin catalogs.
126
+ */
127
+ labelKey: z.string().max(120).optional(),
128
+ /**
129
+ * Per-locale labels, keyed by locale code (for example `{ "nl": "Formulieren" }`).
130
+ * They win over `labelKey`, so a plugin without an admin app can still
131
+ * translate its menu entry.
132
+ */
133
+ labels: z
134
+ .record(z.string().regex(/^[a-z]{2,8}(?:-[A-Za-z0-9]{2,8}){0,2}$/, "Locale code must look like en or nl-NL"), z.string().min(1).max(60))
135
+ .refine((value) => Object.keys(value).length <= 20, "At most 20 menu label locales")
136
+ .optional(),
137
+ /**
138
+ * Where this page mounts, **relative to the plugin's own namespace**
139
+ * `/admin/plugins/<your plugin id>`. Omit (or `""`) for the namespace root;
140
+ * otherwise a lowercase leaf such as `"orders"` or `"orders/refunds"`. The
141
+ * host prepends `/admin/plugins/<id>/` — never write that prefix or the id.
142
+ */
143
+ path: RelativeAdminPathSchema.optional(),
144
+ icon: z.string().min(1).max(8).default("🔌"),
145
+ /**
146
+ * Sidebar group. `plugin` gives the plugin its own section (see
147
+ * `adminSection`). A group this host does not know falls back to
148
+ * `extensions`, so a manifest written for another host still activates.
149
+ */
150
+ domain: z.enum(ADMIN_MENU_DOMAINS).default("extensions").catch("extensions"),
151
+ /** Match the path exactly instead of as a prefix. */
152
+ end: z.boolean().optional(),
153
+ /**
154
+ * When false, the page stays reachable but is left out of the admin nav.
155
+ * Use it for a screen opened by a button on another plugin page.
156
+ */
157
+ listed: z.boolean().optional(),
158
+ /**
159
+ * Roles that may open this page, such as a role this plugin registers.
160
+ * Omit for the default plugin-page rule (administrators and editors).
161
+ */
162
+ roles: z
163
+ .array(z.string().regex(/^[a-z][a-z0-9-]{0,39}$/, "Role ids are lowercase kebab-case"))
164
+ .min(1)
165
+ .max(10)
166
+ .optional(),
167
+ /**
168
+ * A badge on this page's sidebar row, such as "3 new". Name one of this
169
+ * plugin's own GET routes, relative like `ctx.http` paths
170
+ * (`"orders/new-count"`). The admin calls it with the signed-in user's
171
+ * session on each page change, so your route's own checks decide what that
172
+ * user may count. Answer `{ count: number, label?: string }`: the row shows
173
+ * `label` (up to 20 characters, such as "3 new") or the count, and nothing
174
+ * at 0. Keep it fast; answer 403 to people who should see no badge.
175
+ */
176
+ badge: z
177
+ .string()
178
+ .max(100)
179
+ .regex(/^[a-z0-9]+(?:-[a-z0-9]+)*(?:\/[a-z0-9]+(?:-[a-z0-9]+)*)*$/, "Badge must be a relative route path like orders/new-count")
180
+ .optional(),
181
+ /**
182
+ * CMS type slug. When set, the generic plugin host lists every content row
183
+ * of that type on this page (for example a Products page → `product`).
184
+ */
185
+ contentType: z
186
+ .string()
187
+ .regex(/^[a-z][a-z0-9-]{0,59}$/, "Content type slug must be lowercase letters, numbers, and hyphens")
188
+ .optional(),
189
+ });
190
+ const PANEL_LOCALE_RE = /^[a-z]{2,8}(?:-[A-Za-z0-9]{2,8}){0,2}$/;
191
+ /**
192
+ * Text shown in the admin: one string, or `{ "<locale>": "<text>" }`. The editor
193
+ * uses the admin language, then its base language, then `en`, then any entry.
194
+ */
195
+ export const LocalizedTextSchema = z.union([
196
+ z.string().min(1).max(500),
197
+ z
198
+ .record(z.string().regex(PANEL_LOCALE_RE, "Locale code must look like en or nl-NL"), z.string().min(1).max(500))
199
+ .refine((value) => Object.keys(value).length > 0 && Object.keys(value).length <= 20, "1 to 20 locales"),
200
+ ]);
201
+ /**
202
+ * One field of a content editor panel. The value is saved in the entry's
203
+ * `fields` under `key`. In `placeholder`, `{title}`, `{excerpt}`, and `{url}`
204
+ * become the entry's title, excerpt, and public address.
205
+ */
206
+ export const EditorPanelFieldSchema = z.object({
207
+ key: z.string().regex(/^[a-zA-Z][a-zA-Z0-9_]{0,39}$/, "Field key must be letters, digits, or _"),
208
+ type: z.enum(["text", "textarea", "url", "image", "checkbox"]),
209
+ label: LocalizedTextSchema,
210
+ hint: LocalizedTextSchema.optional(),
211
+ placeholder: LocalizedTextSchema.optional(),
212
+ });
213
+ /**
214
+ * A section a plugin adds to the content editor, next to Content, Discussion,
215
+ * and Advanced. Shown while the plugin is active, for every content type.
216
+ */
217
+ export const EditorPanelSchema = z
218
+ .object({
219
+ id: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Panel id must be lowercase kebab-case"),
220
+ title: LocalizedTextSchema,
221
+ /** Show only for entries whose type is included in search engines. */
222
+ indexableOnly: z.boolean().optional(),
223
+ fields: z.array(EditorPanelFieldSchema).max(20).optional(),
224
+ /**
225
+ * Relative admin-app path embedded in this section. The host passes the
226
+ * content id being edited. A panel has fields or this path.
227
+ */
228
+ app: z
229
+ .string()
230
+ .regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)
231
+ .max(40)
232
+ .optional(),
233
+ })
234
+ .superRefine((panel, ctx) => {
235
+ const hasFields = Array.isArray(panel.fields) && panel.fields.length > 0;
236
+ const hasApp = typeof panel.app === "string" && panel.app.length > 0;
237
+ if (hasFields === hasApp) {
238
+ ctx.addIssue({
239
+ code: "custom",
240
+ message: "An editor panel declares fields or an app route.",
241
+ });
242
+ }
243
+ });
244
+ /**
245
+ * The plugin's own sidebar section. Menu items with `domain: "plugin"` are
246
+ * listed there instead of in a shared section.
247
+ */
248
+ export const AdminSectionSchema = z.object({
249
+ /** English label, shown when `labelKey` and `labels` have no translation. */
250
+ label: z.string().min(1).max(60),
251
+ /** Key in the plugin's own `adminApp.locales` catalogs. */
252
+ labelKey: z.string().max(120).optional(),
253
+ labels: z
254
+ .record(z.string().regex(PANEL_LOCALE_RE, "Locale code must look like en or nl-NL"), z.string().min(1).max(60))
255
+ .refine((value) => Object.keys(value).length <= 20, "At most 20 section label locales")
256
+ .optional(),
257
+ /** An emoji, or an image file in the plugin's admin app folder such as `logo.png`. */
258
+ icon: z
259
+ .string()
260
+ .min(1)
261
+ .max(120)
262
+ .refine((value) => value.length <= 8 || /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,110}\.(png|svg|webp)$/.test(value), "Icon must be an emoji or a .png, .svg, or .webp file in the admin app folder")
263
+ .optional(),
264
+ });
265
+ /**
266
+ * A card a plugin adds to Platform → Workspace. The host embeds the relative
267
+ * admin-app path and passes the workspace id being viewed.
268
+ */
269
+ export const WorkspacePanelSchema = z.object({
270
+ id: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Panel id must be lowercase kebab-case"),
271
+ title: LocalizedTextSchema,
272
+ app: z
273
+ .string()
274
+ .regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)
275
+ .max(40),
276
+ });
277
+ /**
278
+ * A card on the admin Home page, filled by the plugin's own admin app
279
+ * (`/ext/<plugin id>/admin/<app>`), like a workspace panel. The card shows to
280
+ * users who may open the plugin's admin pages. Keep it to a summary that
281
+ * links into the plugin, such as today's orders or the next bookings.
282
+ */
283
+ export const DashboardPanelSchema = WorkspacePanelSchema.extend({
284
+ /** `wide` spans the full width of Home; `small` (the default) shares a row. */
285
+ size: z.enum(["small", "wide"]).optional(),
286
+ });
287
+ /**
288
+ * A step this plugin adds to "Finish setting up your site" on the admin Home
289
+ * page, shown to administrators while the plugin is active. `path` is the
290
+ * plugin's admin page that does it (relative like `adminMenu` paths; omit for
291
+ * the plugin's root). `status` is one of the plugin's own GET routes
292
+ * (relative like `ctx.http` paths) that answers `{ done: boolean }`; the
293
+ * admin calls it with the administrator's session.
294
+ */
295
+ const SetupStepSchema = z.object({
296
+ id: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Setup step id must be lowercase kebab-case"),
297
+ label: LocalizedTextSchema,
298
+ path: RelativeAdminPathSchema.optional(),
299
+ status: z
300
+ .string()
301
+ .max(100)
302
+ .regex(/^[a-z0-9]+(?:-[a-z0-9]+)*(?:\/[a-z0-9]+(?:-[a-z0-9]+)*)*$/, "Status must be a relative route path like setup/payments"),
303
+ });
304
+ /**
305
+ * Something a user can do from admin search (⌘K), such as "Add a product".
306
+ * It opens one of the plugin's own admin pages, so a role that cannot open
307
+ * that page never sees the action.
308
+ */
309
+ export const AdminActionSchema = z.object({
310
+ id: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Action id must be lowercase kebab-case"),
311
+ /** What the action does, as a short command: "Add a product". */
312
+ label: LocalizedTextSchema,
313
+ /** Page to open, relative to `/admin/plugins/<your plugin id>` like `adminMenu` paths. */
314
+ path: RelativeAdminPathSchema.optional(),
315
+ /** An admin line-icon name (`"bag"`, `"calendar"`, `"forms"`…) or an emoji. */
316
+ icon: z.string().min(1).max(16).optional(),
317
+ /** Other words people may type to find it, such as "item" or "sku". */
318
+ keywords: z.array(z.string().min(1).max(30)).max(8).optional(),
319
+ });
320
+ /** A plugin asset path: relative, no traversal, `.js`/`.mjs`/`.css` only. */
321
+ const PluginAssetFileSchema = z
322
+ .string()
323
+ .min(1)
324
+ .max(160)
325
+ .regex(/^[a-zA-Z0-9][a-zA-Z0-9._/-]*\.(js|mjs|css)$/, "Asset must be a relative .js/.mjs/.css path")
326
+ .refine((value) => !value.split("/").includes(".."), "Asset path must not contain '..'");
327
+ /** Assets one block type needs, relative to the assets `dir`. */
328
+ export const PluginBlockAssetsSchema = z.object({
329
+ /** `.js` / `.mjs` files added as `<script defer>` at the end of the page. */
330
+ scripts: z.array(PluginAssetFileSchema).max(10).optional(),
331
+ /** `.css` files added as `<link rel="stylesheet">` before the theme stylesheet. */
332
+ styles: z.array(PluginAssetFileSchema).max(10).optional(),
333
+ });
334
+ /**
335
+ * A selector a page must contain for an `assets.markup` rule to apply:
336
+ * `#id`, `.class`, `.class-prefix*` (any class starting with the prefix), or
337
+ * `[attribute]`. Matched against the finished HTML, so it finds markup from
338
+ * any source: content, templates, plugin routes, header and footer.
339
+ */
340
+ export const AssetMarkupSelectorSchema = z
341
+ .string()
342
+ .regex(/^(?:#[A-Za-z][A-Za-z0-9_-]{0,63}|\.[A-Za-z_][A-Za-z0-9_-]{0,63}\*?|\[[a-z][a-z0-9-]{0,63}\])$/, "Use #id, .class, .class-prefix*, or [attribute]");
343
+ /** Assets a page loads when it contains any of `match`. Paths are relative to the assets `dir`. */
344
+ export const PluginMarkupAssetsSchema = z.object({
345
+ match: z.array(AssetMarkupSelectorSchema).min(1).max(20),
346
+ /** `.js` / `.mjs` files added as `<script defer>` at the end of the page. */
347
+ scripts: z.array(PluginAssetFileSchema).max(10).optional(),
348
+ /** `.css` files added as `<link rel="stylesheet">` before the theme stylesheet. */
349
+ styles: z.array(PluginAssetFileSchema).max(10).optional(),
350
+ });
351
+ /**
352
+ * Client-side assets a plugin ships in its package. On activation the host
353
+ * serves `<dir>/**` at `/ext/<pluginId>/**` and auto-enqueues `scripts` /
354
+ * `styles` on every public page — no `ctx.http` route or `html.head` filter.
355
+ * `blocks` maps one of the plugin's own block types, and `markup` a list of
356
+ * selectors, to assets the host adds only to pages that render that block or
357
+ * contain that markup (from content, templates, header, footer, widget areas,
358
+ * or plugin routes), with a content-hashed URL that browsers cache for good.
359
+ * Prefer them to `scripts` / `styles` for anything not every page needs.
360
+ * The static exporter downloads them like any other same-origin asset.
361
+ */
362
+ export const PluginAssetsSchema = z.object({
363
+ /** Package-relative folder holding the assets. Defaults to `public`. */
364
+ dir: z
365
+ .string()
366
+ .max(128)
367
+ .regex(/^[a-zA-Z0-9._-]+(?:\/[a-zA-Z0-9._-]+)*$/, "Assets dir must be a relative folder path (e.g. 'public' or 'dist/public')")
368
+ .refine((v) => !v.split("/").includes(".."), "Assets dir must not contain '..'")
369
+ .optional(),
370
+ /** `.js` / `.mjs` files (relative to `dir`) added as `<script defer>`. */
371
+ scripts: z.array(PluginAssetFileSchema).max(20).optional(),
372
+ /** `.css` files (relative to `dir`) added as `<link rel="stylesheet">`. */
373
+ styles: z.array(PluginAssetFileSchema).max(20).optional(),
374
+ /**
375
+ * Per-block assets, keyed by a block type the plugin registers with
376
+ * `ctx.blocks.register` (its own namespace, e.g. `acme.slider`).
377
+ */
378
+ blocks: z
379
+ .record(z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/, "Block type must be a block id such as 'acme.slider'"), PluginBlockAssetsSchema)
380
+ .refine((value) => Object.keys(value).length <= 50, "At most 50 block types may declare assets")
381
+ .optional(),
382
+ /** Assets for pages that contain markup the plugin's script or styles act on. */
383
+ markup: z.array(PluginMarkupAssetsSchema).max(20).optional(),
384
+ });
385
+ /**
386
+ * Page templates a plugin ships in its package: `<dir>/<slug>.json` block
387
+ * documents (same shape as a theme's `templates/*.json`). While the plugin is
388
+ * active the host resolves them after the site override and the active theme's
389
+ * own file for that slug, so templates for plugin-owned content types (e.g.
390
+ * `single-product`) live with the plugin, and a theme can still override them.
391
+ */
392
+ export const PluginTemplatesSchema = z.object({
393
+ /** Package-relative folder holding the templates. Defaults to `templates`. */
394
+ dir: z
395
+ .string()
396
+ .max(128)
397
+ .regex(/^[a-zA-Z0-9._-]+(?:\/[a-zA-Z0-9._-]+)*$/, "Templates dir must be a relative folder path (e.g. 'templates')")
398
+ .refine((v) => !v.split("/").includes(".."), "Templates dir must not contain '..'")
399
+ .optional(),
400
+ });
401
+ /** An HTML entry file for a plugin admin screen: relative, no traversal. */
402
+ const PluginAdminEntrySchema = z
403
+ .string()
404
+ .min(1)
405
+ .max(160)
406
+ .regex(/^[a-zA-Z0-9][a-zA-Z0-9._/-]*\.html?$/, "Admin entry must be a relative .html file path")
407
+ .refine((value) => !value.split("/").includes(".."), "Admin entry must not contain '..'");
408
+ const PluginAdminRouteSchema = z.object({
409
+ /**
410
+ * Where this screen mounts, relative to the plugin's namespace
411
+ * `/admin/plugins/<your plugin id>` — `""` (omit) for the root, or a leaf
412
+ * like `"submissions"`. Same rules as `AdminMenuItemSchema.path`.
413
+ */
414
+ path: RelativeAdminPathSchema.optional(),
415
+ /** HTML file (relative to `dir`) the admin frame loads for this path. */
416
+ entry: PluginAdminEntrySchema,
417
+ /** Breadcrumb / frame title; falls back to the manifest name. */
418
+ title: z.string().min(1).max(100).optional(),
419
+ });
420
+ /**
421
+ * A self-contained admin app the plugin ships in its own package. The host
422
+ * serves `<dir>/**` at `/ext/<pluginId>/admin/**` and, for each declared
423
+ * route, mounts the `entry` HTML in a same-origin `<iframe>` inside the admin
424
+ * shell — the plugin owns the whole screen and its design, talks only to its
425
+ * own `ctx.http` routes, and reaches the host through `@justflows/admin-bridge`
426
+ * (`postMessage`), never a shared React runtime. Requires `admin:extend`.
427
+ */
428
+ export const PluginAdminAppSchema = z.object({
429
+ /** Package-relative folder holding the admin build. Defaults to `admin`. */
430
+ dir: z
431
+ .string()
432
+ .max(128)
433
+ .regex(/^[a-zA-Z0-9._-]+(?:\/[a-zA-Z0-9._-]+)*$/, "Admin dir must be a relative folder path (e.g. 'admin' or 'dist/admin')")
434
+ .refine((v) => !v.split("/").includes(".."), "Admin dir must not contain '..'")
435
+ .optional(),
436
+ /**
437
+ * One per admin screen. Bounded because manifests come from third-party
438
+ * packages; 40 leaves room for a large plugin such as a store.
439
+ */
440
+ routes: z.array(PluginAdminRouteSchema).min(1).max(40),
441
+ /**
442
+ * Admin UI catalogs, keyed by locale code. Each value is a `.json` file
443
+ * relative to `dir` (for example `locales/nl.json`). The host serves it at
444
+ * `/ext/<pluginId>/admin/<path>` and passes those URLs to the frame as
445
+ * `context.catalogs`.
446
+ */
447
+ locales: z
448
+ .record(z
449
+ .string()
450
+ .regex(/^[a-z]{2,8}(?:-[A-Za-z0-9]{2,8}){0,2}$/, "Locale code must look like en or nl-NL"), z
451
+ .string()
452
+ .min(1)
453
+ .max(160)
454
+ .regex(/^[a-zA-Z0-9][a-zA-Z0-9._/-]*\.json$/, "Locale file must be a relative .json path")
455
+ .refine((value) => !value.split("/").includes(".."), "Locale file must not contain '..'"))
456
+ .refine((value) => Object.keys(value).length <= 20, "At most 20 locale files")
457
+ .optional(),
458
+ }).superRefine((app, ctx) => {
459
+ if (!app.locales?.["en"]) {
460
+ ctx.addIssue({
461
+ code: "custom",
462
+ path: ["locales", "en"],
463
+ message: "An admin app must declare an English catalog at locales.en (for example locales/en.json). It is the fallback for every other locale.",
464
+ });
465
+ }
466
+ });
467
+ /**
468
+ * Every extension id is `<namespace>.<name>`: `justflows.forms` for official
469
+ * extensions, `acme.forms` for a publisher that owns `acme`, and deeper ids
470
+ * such as `justflows.theme.dark`. The admin URL (`/admin/plugins/<id>`) and
471
+ * the asset mount (`/ext/<id>/…`) are built from it, so it stays lowercase
472
+ * letters, digits, single hyphens, and dots. See `publisher-namespace.ts` for
473
+ * reserved namespaces and what the namespace does and does not prove.
474
+ */
475
+ export const PLUGIN_ID_RE = /^(?=.{4,128}$)[a-z][a-z0-9]*(?:-[a-z0-9]+)*(?:\.[a-z0-9]+(?:-[a-z0-9]+)*)+$/;
476
+ /** Shared message for ids that do not match `PLUGIN_ID_RE`. */
477
+ export const PLUGIN_ID_MESSAGE = "ID must be <namespace>.<name> in lowercase, for example acme.forms";
478
+ /**
479
+ * Namespace rules shared by the plugin manifest and the package manifest: the
480
+ * id may not use a reserved namespace other than `justflows`, and a
481
+ * third-party API namespace must stay inside the publisher namespace.
482
+ */
483
+ export function addPublisherNamespaceIssues(manifest, ctx) {
484
+ const issue = extensionIdNamespaceIssue(manifest.id);
485
+ if (issue) {
486
+ ctx.addIssue({ code: "custom", path: ["id"], message: issue });
487
+ return;
488
+ }
489
+ if (manifest.apiNamespace && !isApiNamespaceAllowedForExtension(manifest.id, manifest.apiNamespace)) {
490
+ const namespace = manifest.id.slice(0, manifest.id.indexOf("."));
491
+ ctx.addIssue({
492
+ code: "custom",
493
+ path: ["apiNamespace"],
494
+ message: `API namespace must be "${namespace}" or start with "${namespace}-"`,
495
+ });
496
+ }
497
+ }
498
+ export const PluginManifestSchema = z
499
+ .object({
500
+ id: z
501
+ .string()
502
+ .regex(PLUGIN_ID_RE, PLUGIN_ID_MESSAGE),
503
+ apiNamespace: z.string().refine(isValidPluginApiNamespace, "Invalid or reserved plugin API namespace").optional(),
504
+ name: z.string().min(1).max(100),
505
+ // Anchored at both ends: `.regex()` runs RegExp.test(), which honours only
506
+ // the `^`, so a pattern stopping at the patch number leaves everything after
507
+ // it unconstrained. Nothing joins this value into a path today — the
508
+ // matching field on PackageManifestSchema did, which is how that became a
509
+ // traversal — so keep the two schemas agreeing on what a version is.
510
+ version: z
511
+ .string()
512
+ .max(64)
513
+ .regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/, "Must be semver, e.g. 1.2.3 or 1.2.3-rc.1"),
514
+ description: z.string().max(500).optional(),
515
+ author: z.string().optional(),
516
+ homepage: z.url().optional(),
517
+ license: z.string().min(1, "Plugin license is required"),
518
+ engines: ExtensionEnginesSchema.optional(),
519
+ /** @deprecated Use engines.justflows in new manifests. */
520
+ minJustflowsVersion: z.string().optional(),
521
+ /** @deprecated Use engines.justflows in new manifests. */
522
+ maxJustflowsVersion: z.string().optional(),
523
+ permissions: z.array(PluginPermissionSchema).default([]),
524
+ main: z.string().default("index.js"),
525
+ /**
526
+ * When true, the main site may offer this plugin to other sites. Those
527
+ * sites can activate it and change only their own rows. They cannot
528
+ * install the package or drop its tables. Omit or false to keep the
529
+ * plugin on the main site.
530
+ */
531
+ allowMultisite: z.boolean().optional(),
532
+ /**
533
+ * Other plugins that must already be installed on this site. Install is
534
+ * refused while any of them is missing. Activation is refused until each
535
+ * one is active.
536
+ */
537
+ requires: z
538
+ .array(z.string().regex(PLUGIN_ID_RE, `Required plugin ${PLUGIN_ID_MESSAGE}`))
539
+ .max(10)
540
+ .optional(),
541
+ settingsSchema: z
542
+ .record(z.string(), z.object({
543
+ type: z.enum(["string", "number", "boolean", "text", "select"]),
544
+ label: z.string().min(1),
545
+ description: z.string().optional(),
546
+ default: z.unknown().optional(),
547
+ localized: z.boolean().optional(),
548
+ /** For `select`: fixed choices, shown before any from `optionsSource`. */
549
+ options: z
550
+ .array(z.object({ value: z.string().max(200), label: z.string().min(1).max(200) }))
551
+ .max(200)
552
+ .optional(),
553
+ /**
554
+ * For `select`: choices the host fills in, from the same lists core uses.
555
+ * `timezones`: every IANA time zone, as Settings → General.
556
+ * `countries`: every ISO 3166-1 country, stored as its two-letter code.
557
+ */
558
+ optionsSource: z.enum(["timezones", "countries"]).optional(),
559
+ }))
560
+ .optional(),
561
+ /**
562
+ * Admin pages this plugin adds to the sidebar. Honoured only when the
563
+ * manifest also declares the "admin:extend" permission.
564
+ */
565
+ adminMenu: z.array(AdminMenuItemSchema).max(20).optional(),
566
+ /** Content editor sections this plugin adds. Honoured with `admin:extend`. */
567
+ editorPanels: z.array(EditorPanelSchema).max(5).optional(),
568
+ /** Sidebar section for menu items with `domain: "plugin"`. Honoured with `admin:extend`. */
569
+ adminSection: AdminSectionSchema.optional(),
570
+ /** Platform → Workspace cards this plugin adds. Honoured with `admin:extend`. */
571
+ workspacePanels: z.array(WorkspacePanelSchema).max(5).optional(),
572
+ /** Cards on the admin Home page. Honoured with `admin:extend`. */
573
+ dashboardPanels: z.array(DashboardPanelSchema).max(3).optional(),
574
+ /** Steps on the admin Home setup checklist. Honoured with `admin:extend`. */
575
+ setupSteps: z.array(SetupStepSchema).max(3).optional(),
576
+ /** Actions offered in admin search (⌘K). Honoured with `admin:extend`. */
577
+ adminActions: z.array(AdminActionSchema).max(10).optional(),
578
+ /**
579
+ * Page to open after activation when the plugin still needs a first-run
580
+ * setup (database topology, credentials, store identity). Relative to the
581
+ * plugin's namespace like `adminMenu` paths: `""` is the namespace root.
582
+ * Omit entirely for "no setup wizard".
583
+ */
584
+ setupPath: RelativeAdminPathSchema.optional(),
585
+ /**
586
+ * Plugin registry / Marketplace listing. Commercial flag, publisher
587
+ * visibility, coming-soon, beta, category, tags, screenshots, and free vs
588
+ * paid price. The package file must name every field (`justflows check`,
589
+ * JF-M012). Runtime does not use these; the registry and Admin → Marketplace do.
590
+ */
591
+ registry: RegistryListingSchema.optional(),
592
+ /**
593
+ * CMS type slugs this plugin created. The host deletes those types and
594
+ * every entry on uninstall when `deleteContentOnUninstall` is on.
595
+ */
596
+ contentTypes: z
597
+ .array(z
598
+ .string()
599
+ .regex(/^[a-z][a-z0-9-]{0,59}$/, "Content type slug must be lowercase letters, numbers, and hyphens"))
600
+ .max(20)
601
+ .optional(),
602
+ /**
603
+ * Client-side assets shipped inside the plugin package. On activation the
604
+ * host serves `<dir>/**` at `/ext/<pluginId>/**` and auto-enqueues the
605
+ * `scripts` / `styles` on every public page — no `ctx.http` route or
606
+ * `html.head` filter needed. The static exporter downloads them like any
607
+ * other same-origin asset. `scripts` / `styles` are paths **relative to
608
+ * `dir`**; both must be `.js`/`.mjs` or `.css` and contain no `..`.
609
+ * `blocks` loads assets only on pages that render one of those blocks.
610
+ */
611
+ assets: PluginAssetsSchema.optional(),
612
+ /** Page templates shipped inside the plugin package (see PluginTemplatesSchema). */
613
+ templates: PluginTemplatesSchema.optional(),
614
+ /**
615
+ * A self-contained admin app the plugin ships and the host mounts in a
616
+ * same-origin `<iframe>` for each declared route (see PluginAdminAppSchema).
617
+ * Requires `admin:extend`.
618
+ */
619
+ adminApp: PluginAdminAppSchema.optional(),
620
+ })
621
+ .superRefine((manifest, ctx) => {
622
+ addPublisherNamespaceIssues(manifest, ctx);
623
+ if (manifest.adminMenu?.length && !manifest.permissions.includes("admin:extend")) {
624
+ ctx.addIssue({
625
+ code: "custom",
626
+ path: ["adminMenu"],
627
+ message: 'Contributing admin menu items requires the "admin:extend" permission',
628
+ });
629
+ }
630
+ if (manifest.adminApp && !manifest.permissions.includes("admin:extend")) {
631
+ ctx.addIssue({
632
+ code: "custom",
633
+ path: ["adminApp"],
634
+ message: 'Shipping an admin app requires the "admin:extend" permission',
635
+ });
636
+ }
637
+ if (manifest.setupPath && !manifest.permissions.includes("admin:extend")) {
638
+ ctx.addIssue({
639
+ code: "custom",
640
+ path: ["setupPath"],
641
+ message: 'Declaring setupPath requires the "admin:extend" permission',
642
+ });
643
+ }
644
+ if (manifest.contentTypes?.length && !manifest.permissions.includes("content:delete")) {
645
+ ctx.addIssue({
646
+ code: "custom",
647
+ path: ["contentTypes"],
648
+ message: 'Declaring contentTypes requires the "content:delete" permission',
649
+ });
650
+ }
651
+ if (manifest.requires?.includes(manifest.id)) {
652
+ ctx.addIssue({
653
+ code: "custom",
654
+ path: ["requires"],
655
+ message: "A plugin cannot require itself",
656
+ });
657
+ }
658
+ if (!isAcceptedManifestLicense(manifest.license)) {
659
+ ctx.addIssue({
660
+ code: "custom",
661
+ path: ["license"],
662
+ message: gplLicenseValidationMessage(manifest.license),
663
+ });
664
+ }
665
+ })
666
+ // Author-facing admin paths are relative to the plugin's namespace; the host
667
+ // and everything downstream work in absolute `/admin/plugins/<id>/…` URLs.
668
+ // Resolve them here, once, so a parsed manifest always carries the real path.
669
+ // Keys are only rewritten when present, so `adminMenu` / `adminApp` /
670
+ // `setupPath` / `adminActions` stay optional on the inferred type.
671
+ .transform((manifest) => {
672
+ const out = { ...manifest };
673
+ if (manifest.adminMenu) {
674
+ out.adminMenu = manifest.adminMenu.map((item) => ({
675
+ ...item,
676
+ path: resolvePluginAdminPath(manifest.id, item.path),
677
+ }));
678
+ }
679
+ if (manifest.adminApp) {
680
+ out.adminApp = {
681
+ ...manifest.adminApp,
682
+ routes: manifest.adminApp.routes.map((route) => ({
683
+ ...route,
684
+ path: resolvePluginAdminPath(manifest.id, route.path),
685
+ })),
686
+ };
687
+ }
688
+ if (manifest.setupPath !== undefined) {
689
+ out.setupPath = resolvePluginAdminPath(manifest.id, manifest.setupPath);
690
+ }
691
+ if (manifest.adminActions) {
692
+ out.adminActions = manifest.adminActions.map((action) => ({
693
+ ...action,
694
+ path: resolvePluginAdminPath(manifest.id, action.path),
695
+ }));
696
+ }
697
+ return out;
698
+ });
699
+ /** The Builder 2.0 block contract version this SDK describes (justflows-ce#305). */
700
+ export const BLOCK_API_VERSION = 1;
701
+ /**
702
+ * Setting key for a keep/delete choice on uninstall. When absent, `deleteData`
703
+ * should run its cleanup (silent). When present, honour the stored boolean.
704
+ */
705
+ export const PLUGIN_DELETE_DATA_SETTING = "deleteDataOnUninstall";
706
+ /** Setting key for deleting CMS types and entries the plugin created on uninstall. */
707
+ export const PLUGIN_DELETE_CONTENT_SETTING = "deleteContentOnUninstall";
708
+ async function honourBooleanSetting(ctx, key, silentDefault) {
709
+ const stored = await ctx.settings.get(key);
710
+ if (stored === undefined || stored === null)
711
+ return silentDefault;
712
+ if (stored === false || stored === "false" || stored === 0 || stored === "0")
713
+ return false;
714
+ if (stored === true || stored === "true" || stored === 1 || stored === "1")
715
+ return true;
716
+ return Boolean(stored);
717
+ }
718
+ export async function pluginShouldDeleteData(ctx, silentDefault = true) {
719
+ return honourBooleanSetting(ctx, PLUGIN_DELETE_DATA_SETTING, silentDefault);
720
+ }
721
+ export async function pluginShouldDeleteContent(ctx, silentDefault = true) {
722
+ return honourBooleanSetting(ctx, PLUGIN_DELETE_CONTENT_SETTING, silentDefault);
723
+ }
724
+ //# sourceMappingURL=plugin.js.map