@cloudparse/up-backoffice-sdk 0.0.0-stage → 0.1.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 (38) hide show
  1. package/README.md +59 -2
  2. package/claude-plugin/.claude-plugin/marketplace.json +17 -0
  3. package/claude-plugin/.claude-plugin/plugin.json +21 -0
  4. package/claude-plugin/README.md +44 -0
  5. package/claude-plugin/commands/new-backoffice-plugin.md +18 -0
  6. package/claude-plugin/scripts/scaffold.mjs +186 -0
  7. package/claude-plugin/sdk-version.json +1 -0
  8. package/claude-plugin/skills/up-backoffice-plugin-builder/SKILL.md +40 -0
  9. package/claude-plugin/skills/up-backoffice-plugin-builder/references/plugin-checklist.md +14 -0
  10. package/claude-plugin/skills/up-backoffice-plugin-builder/references/recipes.md +147 -0
  11. package/claude-plugin/skills/up-backoffice-plugin-builder/references/rules-and-pitfalls.md +25 -0
  12. package/claude-plugin/skills/up-backoffice-plugin-builder/references/sdk-api.md +91 -0
  13. package/claude-plugin/templates/plugin/AGENTS.md +9 -0
  14. package/claude-plugin/templates/plugin/CLAUDE.md +1 -0
  15. package/claude-plugin/templates/plugin/biome.json +64 -0
  16. package/claude-plugin/templates/plugin/gitignore +2 -0
  17. package/claude-plugin/templates/plugin/package.json +31 -0
  18. package/claude-plugin/templates/plugin/src/features/__PLUGIN_ID__/components/AdminPage.tsx +143 -0
  19. package/claude-plugin/templates/plugin/src/features/__PLUGIN_ID__/types.ts +17 -0
  20. package/claude-plugin/templates/plugin/src/index.tsx +22 -0
  21. package/claude-plugin/templates/plugin/src/services/__PLUGIN_ID__.ts +26 -0
  22. package/claude-plugin/templates/plugin/src/styles.css +1 -0
  23. package/claude-plugin/templates/plugin/tsconfig.json +18 -0
  24. package/claude-plugin/templates/plugin/vite.config.ts +12 -0
  25. package/dist/chunk-PSBYWSHV.js +17 -0
  26. package/dist/chunk-PSBYWSHV.js.map +1 -0
  27. package/dist/contract-88aU9QZl.d.ts +122 -0
  28. package/dist/host.d.ts +33 -0
  29. package/dist/host.js +140 -0
  30. package/dist/host.js.map +1 -0
  31. package/dist/index.d.ts +564 -0
  32. package/dist/index.js +2549 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/plugin.css +9 -0
  35. package/dist/theme.css +41 -0
  36. package/dist/vite.d.ts +15 -0
  37. package/dist/vite.js +74 -0
  38. package/package.json +96 -4
package/dist/host.js ADDED
@@ -0,0 +1,140 @@
1
+ "use client";
2
+ import {
3
+ PLUGIN_CONTRACT_VERSION,
4
+ SHARED_MODULES_GLOBAL,
5
+ SHARED_MODULE_IDS
6
+ } from "./chunk-PSBYWSHV.js";
7
+
8
+ // src/host/index.ts
9
+ function installSharedModules(modules) {
10
+ globalThis[SHARED_MODULES_GLOBAL] = modules;
11
+ }
12
+ async function sha256Hex(text) {
13
+ const digest = await crypto.subtle.digest(
14
+ "SHA-256",
15
+ new TextEncoder().encode(text)
16
+ );
17
+ return Array.from(
18
+ new Uint8Array(digest),
19
+ (byte) => byte.toString(16).padStart(2, "0")
20
+ ).join("");
21
+ }
22
+ function isPluginModule(value) {
23
+ if (!value || typeof value !== "object") return false;
24
+ const candidate = value;
25
+ return typeof candidate.id === "string" && typeof candidate.name === "string" && typeof candidate.contractVersion === "number" && Array.isArray(candidate.pages) && typeof candidate.renderPage === "function";
26
+ }
27
+ async function loadPluginModule(code, expectedChecksum) {
28
+ const checksum = await sha256Hex(code);
29
+ if (checksum !== expectedChecksum.toLowerCase()) {
30
+ throw new Error("Plugin bundle checksum mismatch: refusing to load it");
31
+ }
32
+ const url = URL.createObjectURL(
33
+ new Blob([code], { type: "text/javascript" })
34
+ );
35
+ let imported;
36
+ try {
37
+ imported = await import(
38
+ /* webpackIgnore: true */
39
+ /* turbopackIgnore: true */
40
+ /* @vite-ignore */
41
+ url
42
+ );
43
+ } finally {
44
+ URL.revokeObjectURL(url);
45
+ }
46
+ const plugin = imported.default;
47
+ if (!isPluginModule(plugin)) {
48
+ throw new Error("Plugin bundle has no valid default export");
49
+ }
50
+ if (!PLUGIN_ID_PATTERN.test(plugin.id)) {
51
+ throw new Error(`Plugin id "${plugin.id}" is invalid`);
52
+ }
53
+ if (plugin.contractVersion !== PLUGIN_CONTRACT_VERSION) {
54
+ throw new Error(
55
+ `Plugin "${plugin.id}" targets contract v${plugin.contractVersion}, this backoffice supports v${PLUGIN_CONTRACT_VERSION}`
56
+ );
57
+ }
58
+ return plugin;
59
+ }
60
+ var PLUGIN_ROOT_ATTRIBUTE = "data-up-backoffice-plugin-root";
61
+ function pluginRootProps(plugin) {
62
+ return { [PLUGIN_ROOT_ATTRIBUTE]: plugin.id };
63
+ }
64
+ var UTILITIES_LAYER = /@layer\s+utilities\s*\{/;
65
+ var PLUGIN_ID_PATTERN = /^[a-z][a-z0-9-]*$/;
66
+ function findBlockEnd(css, start) {
67
+ let depth = 1;
68
+ let index = start;
69
+ while (index < css.length) {
70
+ const char = css[index];
71
+ if (char === "/" && css[index + 1] === "*") {
72
+ const end = css.indexOf("*/", index + 2);
73
+ if (end === -1) return -1;
74
+ index = end + 2;
75
+ continue;
76
+ }
77
+ if (char === '"' || char === "'") {
78
+ index++;
79
+ while (index < css.length && css[index] !== char) {
80
+ if (css[index] === "\\") index++;
81
+ index++;
82
+ }
83
+ } else if (char === "{") {
84
+ depth++;
85
+ } else if (char === "}") {
86
+ depth--;
87
+ if (depth === 0) return index;
88
+ }
89
+ index++;
90
+ }
91
+ return -1;
92
+ }
93
+ function scopePluginStyles(css, pluginId) {
94
+ const masked = css.replace(
95
+ /\/\*[\s\S]*?\*\//g,
96
+ (comment) => " ".repeat(comment.length)
97
+ );
98
+ const match = UTILITIES_LAYER.exec(masked);
99
+ if (!match) {
100
+ throw new Error(
101
+ `Plugin "${pluginId}" styles have no Tailwind utilities layer: refusing to inject unscoped CSS`
102
+ );
103
+ }
104
+ const bodyStart = match.index + match[0].length;
105
+ const bodyEnd = findBlockEnd(css, bodyStart);
106
+ if (bodyEnd === -1) {
107
+ throw new Error(
108
+ `Plugin "${pluginId}" styles have an unclosed utilities layer`
109
+ );
110
+ }
111
+ const scope = `@scope ([${PLUGIN_ROOT_ATTRIBUTE}="${pluginId}"])`;
112
+ return `${css.slice(0, bodyStart)}${scope}{${css.slice(bodyStart, bodyEnd)}}${css.slice(bodyEnd)}`;
113
+ }
114
+ function injectPluginStyles(plugin) {
115
+ if (!plugin.styles || typeof document === "undefined") return () => {
116
+ };
117
+ const css = scopePluginStyles(plugin.styles, plugin.id);
118
+ const selector = `style[data-up-backoffice-plugin="${CSS.escape(plugin.id)}"]`;
119
+ const existing = document.head.querySelector(selector);
120
+ if (existing) {
121
+ existing.textContent = css;
122
+ return () => existing.remove();
123
+ }
124
+ const style = document.createElement("style");
125
+ style.dataset.upBackofficePlugin = plugin.id;
126
+ style.textContent = css;
127
+ document.head.appendChild(style);
128
+ return () => style.remove();
129
+ }
130
+ export {
131
+ PLUGIN_CONTRACT_VERSION,
132
+ PLUGIN_ROOT_ATTRIBUTE,
133
+ SHARED_MODULE_IDS,
134
+ injectPluginStyles,
135
+ installSharedModules,
136
+ loadPluginModule,
137
+ pluginRootProps,
138
+ scopePluginStyles
139
+ };
140
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/host/index.ts"],"sourcesContent":["import {\n type BackofficePluginModule,\n PLUGIN_CONTRACT_VERSION,\n SHARED_MODULES_GLOBAL,\n type SharedModuleId,\n} from \"../plugin/contract\";\n\nexport {\n type BackofficePluginModule,\n PLUGIN_CONTRACT_VERSION,\n type PluginApplication,\n type PluginHost,\n type PluginUser,\n SHARED_MODULE_IDS,\n} from \"../plugin/contract\";\n\ntype SharedRegistry = Record<SharedModuleId, unknown>;\n\n/**\n * Exposes the host's own React instances to plugins. Must run before any plugin\n * is loaded, or the plugin bundle throws on its first shared import.\n */\nexport function installSharedModules(modules: SharedRegistry) {\n (globalThis as Record<string, unknown>)[SHARED_MODULES_GLOBAL] = modules;\n}\n\nasync function sha256Hex(text: string): Promise<string> {\n const digest = await crypto.subtle.digest(\n \"SHA-256\",\n new TextEncoder().encode(text),\n );\n return Array.from(new Uint8Array(digest), (byte) =>\n byte.toString(16).padStart(2, \"0\"),\n ).join(\"\");\n}\n\nfunction isPluginModule(value: unknown): value is BackofficePluginModule {\n if (!value || typeof value !== \"object\") return false;\n const candidate = value as Partial<BackofficePluginModule>;\n return (\n typeof candidate.id === \"string\" &&\n typeof candidate.name === \"string\" &&\n typeof candidate.contractVersion === \"number\" &&\n Array.isArray(candidate.pages) &&\n typeof candidate.renderPage === \"function\"\n );\n}\n\n/**\n * Verifies a plugin bundle against its published checksum, then evaluates it\n * as an ES module and validates its default export.\n */\nexport async function loadPluginModule(\n code: string,\n expectedChecksum: string,\n): Promise<BackofficePluginModule> {\n const checksum = await sha256Hex(code);\n if (checksum !== expectedChecksum.toLowerCase()) {\n throw new Error(\"Plugin bundle checksum mismatch: refusing to load it\");\n }\n\n const url = URL.createObjectURL(\n new Blob([code], { type: \"text/javascript\" }),\n );\n let imported: { default?: unknown };\n try {\n imported = await import(\n /* webpackIgnore: true */ /* turbopackIgnore: true */ /* @vite-ignore */ url\n );\n } finally {\n URL.revokeObjectURL(url);\n }\n\n const plugin = imported.default;\n if (!isPluginModule(plugin)) {\n throw new Error(\"Plugin bundle has no valid default export\");\n }\n if (!PLUGIN_ID_PATTERN.test(plugin.id)) {\n throw new Error(`Plugin id \"${plugin.id}\" is invalid`);\n }\n if (plugin.contractVersion !== PLUGIN_CONTRACT_VERSION) {\n throw new Error(\n `Plugin \"${plugin.id}\" targets contract v${plugin.contractVersion}, this backoffice supports v${PLUGIN_CONTRACT_VERSION}`,\n );\n }\n return plugin;\n}\n\n/** Attribute the host puts on the element wrapping a plugin's pages. */\nexport const PLUGIN_ROOT_ATTRIBUTE = \"data-up-backoffice-plugin-root\";\n\n/** Props to spread on the element wrapping a plugin's pages, so its styles apply there only. */\nexport function pluginRootProps(plugin: Pick<BackofficePluginModule, \"id\">) {\n return { [PLUGIN_ROOT_ATTRIBUTE]: plugin.id };\n}\n\nconst UTILITIES_LAYER = /@layer\\s+utilities\\s*\\{/;\nconst PLUGIN_ID_PATTERN = /^[a-z][a-z0-9-]*$/;\n\n/** Index right after the `}` closing the block opened just before `start`, ignoring strings and comments. */\nfunction findBlockEnd(css: string, start: number): number {\n let depth = 1;\n let index = start;\n while (index < css.length) {\n const char = css[index];\n if (char === \"/\" && css[index + 1] === \"*\") {\n const end = css.indexOf(\"*/\", index + 2);\n if (end === -1) return -1;\n index = end + 2;\n continue;\n }\n if (char === '\"' || char === \"'\") {\n index++;\n while (index < css.length && css[index] !== char) {\n if (css[index] === \"\\\\\") index++;\n index++;\n }\n } else if (char === \"{\") {\n depth++;\n } else if (char === \"}\") {\n depth--;\n if (depth === 0) return index;\n }\n index++;\n }\n return -1;\n}\n\n/**\n * Confines the plugin's Tailwind utilities to its own root with `@scope`. Without\n * it, the plugin's copy of a utility (e.g. `.fixed`) comes later in the cascade\n * than the host's responsive variants (e.g. `lg:sticky`) and breaks the host layout.\n * Theme variables, `@property` and `@keyframes` stay global (same values as the host).\n * Throws when the CSS has no utilities layer: unscoped plugin CSS is never injected.\n */\nexport function scopePluginStyles(css: string, pluginId: string): string {\n // Same length as `css`, comments blanked: a commented-out `@layer utilities {` is ignored.\n const masked = css.replace(/\\/\\*[\\s\\S]*?\\*\\//g, (comment) =>\n \" \".repeat(comment.length),\n );\n const match = UTILITIES_LAYER.exec(masked);\n if (!match) {\n throw new Error(\n `Plugin \"${pluginId}\" styles have no Tailwind utilities layer: refusing to inject unscoped CSS`,\n );\n }\n const bodyStart = match.index + match[0].length;\n const bodyEnd = findBlockEnd(css, bodyStart);\n if (bodyEnd === -1) {\n throw new Error(\n `Plugin \"${pluginId}\" styles have an unclosed utilities layer`,\n );\n }\n const scope = `@scope ([${PLUGIN_ROOT_ATTRIBUTE}=\"${pluginId}\"])`;\n return `${css.slice(0, bodyStart)}${scope}{${css.slice(bodyStart, bodyEnd)}}${css.slice(bodyEnd)}`;\n}\n\n/** Injects the plugin's compiled CSS once, scoped to its root; returns a cleanup removing it. */\nexport function injectPluginStyles(plugin: BackofficePluginModule) {\n if (!plugin.styles || typeof document === \"undefined\") return () => {};\n const css = scopePluginStyles(plugin.styles, plugin.id);\n const selector = `style[data-up-backoffice-plugin=\"${CSS.escape(plugin.id)}\"]`;\n const existing = document.head.querySelector(selector);\n if (existing) {\n existing.textContent = css;\n return () => existing.remove();\n }\n const style = document.createElement(\"style\");\n style.dataset.upBackofficePlugin = plugin.id;\n style.textContent = css;\n document.head.appendChild(style);\n return () => style.remove();\n}\n"],"mappings":";;;;;;;;AAsBO,SAAS,qBAAqB,SAAyB;AAC5D,EAAC,WAAuC,qBAAqB,IAAI;AACnE;AAEA,eAAe,UAAU,MAA+B;AACtD,QAAM,SAAS,MAAM,OAAO,OAAO;AAAA,IACjC;AAAA,IACA,IAAI,YAAY,EAAE,OAAO,IAAI;AAAA,EAC/B;AACA,SAAO,MAAM;AAAA,IAAK,IAAI,WAAW,MAAM;AAAA,IAAG,CAAC,SACzC,KAAK,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AAAA,EACnC,EAAE,KAAK,EAAE;AACX;AAEA,SAAS,eAAe,OAAiD;AACvE,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO;AAChD,QAAM,YAAY;AAClB,SACE,OAAO,UAAU,OAAO,YACxB,OAAO,UAAU,SAAS,YAC1B,OAAO,UAAU,oBAAoB,YACrC,MAAM,QAAQ,UAAU,KAAK,KAC7B,OAAO,UAAU,eAAe;AAEpC;AAMA,eAAsB,iBACpB,MACA,kBACiC;AACjC,QAAM,WAAW,MAAM,UAAU,IAAI;AACrC,MAAI,aAAa,iBAAiB,YAAY,GAAG;AAC/C,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AAEA,QAAM,MAAM,IAAI;AAAA,IACd,IAAI,KAAK,CAAC,IAAI,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAAA,EAC9C;AAC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