openadminjs 0.1.7 → 0.1.8

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 (216) hide show
  1. package/dist/create-project.js +27 -4
  2. package/dist/create-project.test.js +57 -41
  3. package/dist/index.js +16 -5
  4. package/package.json +4 -2
  5. package/template/.env.example +2 -2
  6. package/template/README.md +24 -3
  7. package/template/apps/admin/app/api/auth/login/route.ts +51 -0
  8. package/template/apps/admin/app/api/auth/logout/route.ts +11 -0
  9. package/template/apps/admin/app/api/auth/refresh/route.ts +46 -0
  10. package/template/apps/admin/app/api-tokens/page.tsx +253 -0
  11. package/template/apps/admin/app/audit-logs/page.tsx +5 -0
  12. package/template/apps/admin/app/dashboard/page.tsx +392 -0
  13. package/template/apps/admin/app/files/page.tsx +5 -0
  14. package/template/apps/admin/app/globals.css +206 -0
  15. package/template/apps/admin/app/jobs/page.tsx +19 -0
  16. package/template/apps/admin/app/layout.tsx +57 -0
  17. package/template/apps/admin/app/login/page.test.tsx +18 -0
  18. package/template/apps/admin/app/login/page.tsx +161 -0
  19. package/template/apps/admin/app/login/safe-next-param.ts +4 -0
  20. package/template/apps/admin/app/notifications/page.tsx +146 -0
  21. package/template/apps/admin/app/page.tsx +5 -0
  22. package/template/apps/admin/app/plugins/page.tsx +407 -0
  23. package/template/apps/admin/app/profile/page.tsx +116 -0
  24. package/template/apps/admin/app/resources/[resource]/[id]/edit/page.tsx +45 -0
  25. package/template/apps/admin/app/resources/[resource]/[id]/page.tsx +449 -0
  26. package/template/apps/admin/app/resources/[resource]/create/page.tsx +34 -0
  27. package/template/apps/admin/app/resources/[resource]/page.tsx +100 -0
  28. package/template/apps/admin/app/settings/page.tsx +233 -0
  29. package/template/apps/admin/components/ai-assistant-widget.tsx +684 -0
  30. package/template/apps/admin/components/app-shell.tsx +305 -0
  31. package/template/apps/admin/components/auth-guard.test.tsx +55 -0
  32. package/template/apps/admin/components/auth-guard.tsx +39 -0
  33. package/template/apps/admin/components/jobs-panel.tsx +103 -0
  34. package/template/apps/admin/components/logo.tsx +30 -0
  35. package/template/apps/admin/components/resource-form.tsx +349 -0
  36. package/template/apps/admin/components/resource-table.tsx +277 -0
  37. package/template/apps/admin/lib/ai-events.ts +23 -0
  38. package/template/apps/admin/lib/api.test.ts +118 -0
  39. package/template/apps/admin/lib/api.ts +135 -0
  40. package/template/apps/admin/lib/auth-flow.e2e.test.ts +79 -0
  41. package/template/apps/admin/lib/brand.ts +14 -0
  42. package/template/apps/admin/lib/locale.ts +49 -0
  43. package/template/apps/admin/lib/tokens.ts +93 -0
  44. package/template/apps/admin/middleware.ts +58 -0
  45. package/template/apps/admin/next-env.d.ts +6 -0
  46. package/template/apps/admin/next.config.mjs +7 -0
  47. package/template/apps/admin/package.json +44 -0
  48. package/template/apps/admin/postcss.config.mjs +6 -0
  49. package/template/apps/admin/public/brand/apple-touch-icon.png +0 -0
  50. package/template/apps/admin/public/brand/favicon.svg +1 -0
  51. package/template/apps/admin/public/brand/og-image.png +0 -0
  52. package/template/apps/admin/public/brand/openadminjs-icon-new.png +0 -0
  53. package/template/apps/admin/public/brand/openadminjs-logo-monochrome.png +0 -0
  54. package/template/apps/admin/public/brand/openadminjs-logo-new.png +0 -0
  55. package/template/apps/admin/tailwind.config.ts +37 -0
  56. package/template/apps/admin/tsconfig.json +23 -0
  57. package/template/apps/admin/vitest.config.ts +7 -0
  58. package/template/apps/api/package.json +56 -0
  59. package/template/apps/api/plugins.manifest.example.json +34 -0
  60. package/template/apps/api/plugins.manifest.json +4 -0
  61. package/template/apps/api/src/access/catalog.ts +112 -0
  62. package/template/apps/api/src/access/derive-permissions.test.ts +26 -0
  63. package/template/apps/api/src/access/derive-permissions.ts +36 -0
  64. package/template/apps/api/src/access/public-catalog.ts +28 -0
  65. package/template/apps/api/src/admin/admin-ai.controller.ts +125 -0
  66. package/template/apps/api/src/admin/admin-ai.events.ts +23 -0
  67. package/template/apps/api/src/admin/admin-ai.service.ts +1271 -0
  68. package/template/apps/api/src/admin/admin-analytics.service.ts +164 -0
  69. package/template/apps/api/src/admin/admin-plugins.controller.ts +32 -0
  70. package/template/apps/api/src/admin/admin-plugins.service.ts +267 -0
  71. package/template/apps/api/src/admin/admin-resource.service.test.ts +118 -0
  72. package/template/apps/api/src/admin/admin-resource.service.ts +375 -0
  73. package/template/apps/api/src/admin/admin.controller.ts +72 -0
  74. package/template/apps/api/src/admin/admin.module.ts +30 -0
  75. package/template/apps/api/src/admin/dto/plugins.dto.ts +55 -0
  76. package/template/apps/api/src/admin/validate-resource-payload.test.ts +44 -0
  77. package/template/apps/api/src/admin/validate-resource-payload.ts +103 -0
  78. package/template/apps/api/src/app.module.ts +45 -0
  79. package/template/apps/api/src/auth/auth.controller.ts +70 -0
  80. package/template/apps/api/src/auth/auth.dto.ts +49 -0
  81. package/template/apps/api/src/auth/auth.module.ts +30 -0
  82. package/template/apps/api/src/auth/auth.service.test.ts +75 -0
  83. package/template/apps/api/src/auth/auth.service.ts +231 -0
  84. package/template/apps/api/src/common/auth-realm.decorator.ts +6 -0
  85. package/template/apps/api/src/common/auth.guard.test.ts +61 -0
  86. package/template/apps/api/src/common/auth.guard.ts +78 -0
  87. package/template/apps/api/src/common/casl-ability.factory.test.ts +33 -0
  88. package/template/apps/api/src/common/casl-ability.factory.ts +41 -0
  89. package/template/apps/api/src/common/current-user.decorator.ts +6 -0
  90. package/template/apps/api/src/common/permission.decorator.ts +7 -0
  91. package/template/apps/api/src/common/permissions.guard.ts +31 -0
  92. package/template/apps/api/src/common/prisma.service.ts +13 -0
  93. package/template/apps/api/src/health/health.controller.ts +25 -0
  94. package/template/apps/api/src/mail/mail.module.ts +9 -0
  95. package/template/apps/api/src/mail/mail.service.ts +115 -0
  96. package/template/apps/api/src/main.ts +37 -0
  97. package/template/apps/api/src/plugins/bootstrap.ts +4 -0
  98. package/template/apps/api/src/plugins/bundled/admin-widget.plugin.ts +25 -0
  99. package/template/apps/api/src/plugins/bundled/hello.plugin.ts +19 -0
  100. package/template/apps/api/src/plugins/bundled/image-optimizer.plugin.ts +22 -0
  101. package/template/apps/api/src/plugins/bundled/registry.ts +13 -0
  102. package/template/apps/api/src/plugins/bundled/seo.plugin.ts +25 -0
  103. package/template/apps/api/src/plugins/manifest-path.ts +35 -0
  104. package/template/apps/api/src/plugins/manifest.schema.test.ts +36 -0
  105. package/template/apps/api/src/plugins/manifest.schema.ts +58 -0
  106. package/template/apps/api/src/plugins/plugin-api.interceptor.ts +47 -0
  107. package/template/apps/api/src/plugins/plugin-loader.ts +134 -0
  108. package/template/apps/api/src/plugins/plugin-runtime.test.ts +24 -0
  109. package/template/apps/api/src/plugins/plugin-runtime.ts +85 -0
  110. package/template/apps/api/src/queue/queue.controller.ts +28 -0
  111. package/template/apps/api/src/queue/queue.module.ts +23 -0
  112. package/template/apps/api/src/queue/queue.processor.ts +47 -0
  113. package/template/apps/api/src/queue/queue.service.ts +50 -0
  114. package/template/apps/api/src/resources/categories.resource.ts +21 -0
  115. package/template/apps/api/src/resources/commerce.resource.ts +157 -0
  116. package/template/apps/api/src/resources/operations.resource.ts +111 -0
  117. package/template/apps/api/src/resources/posts.resource.ts +88 -0
  118. package/template/apps/api/src/resources/registry.ts +27 -0
  119. package/template/apps/api/src/resources/resource-hooks.install.ts +18 -0
  120. package/template/apps/api/src/resources/resource-hooks.registry.test.ts +72 -0
  121. package/template/apps/api/src/resources/resource-hooks.registry.ts +66 -0
  122. package/template/apps/api/src/resources/resource-hooks.runner.ts +93 -0
  123. package/template/apps/api/src/resources/system.resource.ts +51 -0
  124. package/template/apps/api/src/resources/users.resource.ts +19 -0
  125. package/template/apps/api/src/store/payment/payment.controller.ts +98 -0
  126. package/template/apps/api/src/store/payment/payment.module.ts +14 -0
  127. package/template/apps/api/src/store/payment/payment.provider.ts +38 -0
  128. package/template/apps/api/src/store/payment/payment.service.ts +235 -0
  129. package/template/apps/api/src/store/store.controller.ts +26 -0
  130. package/template/apps/api/src/store/store.module.ts +12 -0
  131. package/template/apps/api/src/test-setup.ts +1 -0
  132. package/template/apps/api/tsconfig.json +11 -0
  133. package/template/apps/api/vitest.config.ts +21 -0
  134. package/template/apps/web/lib/openadmin-client.ts +11 -0
  135. package/template/apps/web/lib/seo.test.ts +41 -0
  136. package/template/apps/web/lib/seo.ts +24 -13
  137. package/template/apps/web/next-env.d.ts +4 -0
  138. package/template/apps/web/package.json +2 -1
  139. package/template/apps/web/test/next-stub.ts +7 -0
  140. package/template/apps/web/vitest.config.ts +19 -0
  141. package/template/package.json +18 -11
  142. package/template/packages/auth/package.json +17 -0
  143. package/template/packages/auth/src/index.test.ts +10 -0
  144. package/template/packages/auth/src/index.ts +17 -0
  145. package/template/packages/auth/tsconfig.json +8 -0
  146. package/template/packages/brand/apps/admin/public/brand/apple-touch-icon.png +0 -0
  147. package/template/packages/brand/apps/admin/public/brand/favicon.svg +1 -0
  148. package/template/packages/brand/apps/admin/public/brand/og-image.png +0 -0
  149. package/template/packages/brand/apps/admin/public/brand/openadminjs-icon-new.png +0 -0
  150. package/template/packages/brand/apps/admin/public/brand/openadminjs-logo-monochrome.png +0 -0
  151. package/template/packages/brand/apps/admin/public/brand/openadminjs-logo-new.png +0 -0
  152. package/template/packages/brand/apps/web/public/brand/apple-touch-icon.png +0 -0
  153. package/template/packages/brand/apps/web/public/brand/favicon.svg +1 -0
  154. package/template/packages/brand/apps/web/public/brand/og-image.png +0 -0
  155. package/template/packages/brand/apps/web/public/brand/openadminjs-icon-new.png +0 -0
  156. package/template/packages/brand/apps/web/public/brand/openadminjs-logo-monochrome.png +0 -0
  157. package/template/packages/brand/apps/web/public/brand/openadminjs-logo-new.png +0 -0
  158. package/template/packages/brand/package.json +19 -0
  159. package/template/packages/brand/site/assets/brand/favicon.svg +1 -0
  160. package/template/packages/brand/site/assets/brand/og-image.svg +1 -0
  161. package/template/packages/brand/site/assets/brand/openadminjs-icon.svg +1 -0
  162. package/template/packages/brand/site/assets/brand/openadminjs-logo-dark.svg +1 -0
  163. package/template/packages/brand/site/assets/brand/openadminjs-logo-horizontal.svg +1 -0
  164. package/template/packages/brand/site/assets/brand/openadminjs-logo-monochrome.svg +1 -0
  165. package/template/packages/brand/site/assets/brand/openadminjs-logo.svg +1 -0
  166. package/template/packages/brand/src/generate-assets.mjs +182 -0
  167. package/template/packages/brand/src/index.test.ts +9 -0
  168. package/template/packages/brand/src/index.ts +7 -0
  169. package/template/packages/brand/tsconfig.json +7 -0
  170. package/template/packages/core/package.json +20 -0
  171. package/template/packages/core/src/index.js +1 -0
  172. package/template/packages/core/src/index.test.ts +27 -0
  173. package/template/packages/core/src/index.ts +61 -0
  174. package/template/packages/core/tsconfig.json +8 -0
  175. package/template/packages/mail/package.json +18 -0
  176. package/template/packages/mail/src/index.test.ts +23 -0
  177. package/template/packages/mail/src/index.ts +246 -0
  178. package/template/packages/mail/tsconfig.json +5 -0
  179. package/template/packages/notifications/package.json +16 -0
  180. package/template/packages/notifications/src/index.test.ts +9 -0
  181. package/template/packages/notifications/src/index.ts +5 -0
  182. package/template/packages/notifications/tsconfig.json +5 -0
  183. package/template/packages/payments/package.json +15 -0
  184. package/template/packages/payments/src/index.ts +256 -0
  185. package/template/packages/payments/tsconfig.json +9 -0
  186. package/template/packages/permissions/package.json +17 -0
  187. package/template/packages/permissions/src/blueprints.js +57 -0
  188. package/template/packages/permissions/src/blueprints.test.ts +62 -0
  189. package/template/packages/permissions/src/blueprints.ts +89 -0
  190. package/template/packages/permissions/src/index.js +11 -0
  191. package/template/packages/permissions/src/index.test.ts +34 -0
  192. package/template/packages/permissions/src/index.ts +22 -0
  193. package/template/packages/permissions/tsconfig.json +8 -0
  194. package/template/packages/plugin-sdk/package.json +26 -0
  195. package/template/packages/plugin-sdk/src/hooks.ts +135 -0
  196. package/template/packages/plugin-sdk/src/index.ts +42 -0
  197. package/template/packages/plugin-sdk/src/sdk.test.ts +13 -0
  198. package/template/packages/plugin-sdk/tsconfig.json +8 -0
  199. package/template/packages/plugin-sdk/vitest.config.ts +5 -0
  200. package/template/packages/queue/package.json +16 -0
  201. package/template/packages/queue/src/index.test.ts +12 -0
  202. package/template/packages/queue/src/index.ts +6 -0
  203. package/template/packages/queue/tsconfig.json +5 -0
  204. package/template/packages/resource/package.json +17 -0
  205. package/template/packages/resource/src/index.js +177 -0
  206. package/template/packages/resource/src/index.test.ts +151 -0
  207. package/template/packages/resource/src/index.ts +344 -0
  208. package/template/packages/resource/tsconfig.json +8 -0
  209. package/template/packages/storage/package.json +16 -0
  210. package/template/packages/storage/src/index.test.ts +10 -0
  211. package/template/packages/storage/src/index.ts +23 -0
  212. package/template/packages/storage/tsconfig.json +5 -0
  213. package/template/prisma/migrations/20260505151751_baseline_init_all_tables/migration.sql +371 -0
  214. package/template/prisma/migrations/migration_lock.toml +3 -0
  215. package/template/prisma/schema.prisma +291 -0
  216. package/template/prisma/seed.ts +217 -0
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@openadminjs/brand",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "src/index.ts",
6
+ "scripts": {
7
+ "build": "node src/generate-assets.mjs",
8
+ "lint": "node src/generate-assets.mjs --check",
9
+ "typecheck": "node src/generate-assets.mjs --check",
10
+ "test": "vitest run"
11
+ },
12
+ "devDependencies": {
13
+ "typescript": "^5.7.2",
14
+ "vitest": "^2.1.8"
15
+ },
16
+ "dependencies": {
17
+ "sharp": "0.33.5"
18
+ }
19
+ }
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="OpenAdminJS icon"><rect width="64" height="64" rx="14" fill="#059669"/><path d="M17 21h30v22H17z" fill="#ECFDF5"/><path d="M23 27h8v4h-8zm12 0h6v4h-6zM23 35h18v4H23z" fill="#059669"/><path d="M47 21 32 12 17 21" fill="none" stroke="#A7F3D0" stroke-width="4" stroke-linejoin="round"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 630"><rect width="1200" height="630" fill="#0f172a"/><circle cx="980" cy="120" r="180" fill="#059669" opacity=".22"/><g transform="translate(120 150) scale(2)"><rect width="64" height="64" rx="14" fill="#059669"/><path d="M17 21h30v22H17z" fill="#ECFDF5"/><path d="M23 27h8v4h-8zm12 0h6v4h-6zM23 35h18v4H23z" fill="#059669"/><path d="M47 21 32 12 17 21" fill="none" stroke="#A7F3D0" stroke-width="4" stroke-linejoin="round"/></g><text x="120" y="350" fill="#f8fafc" font-family="Inter, ui-sans-serif, system-ui" font-size="76" font-weight="800">OpenAdminJS</text><text x="124" y="420" fill="#A7F3D0" font-family="Inter, ui-sans-serif, system-ui" font-size="34">Resource-driven admin platform</text></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="OpenAdminJS icon"><rect width="64" height="64" rx="14" fill="#059669"/><path d="M17 21h30v22H17z" fill="#ECFDF5"/><path d="M23 27h8v4h-8zm12 0h6v4h-6zM23 35h18v4H23z" fill="#059669"/><path d="M47 21 32 12 17 21" fill="none" stroke="#A7F3D0" stroke-width="4" stroke-linejoin="round"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 280 64" role="img" aria-label="OpenAdminJS"><rect x="0" y="0" width="64" height="64" rx="14" fill="#059669"/><path d="M17 21h30v22H17z" fill="#ECFDF5"/><path d="M23 27h8v4h-8zm12 0h6v4h-6zM23 35h18v4H23z" fill="#059669"/><path d="M47 21 32 12 17 21" fill="none" stroke="#A7F3D0" stroke-width="4" stroke-linejoin="round"/><text x="80" y="40" fill="#f8fafc" font-family="Inter, ui-sans-serif, system-ui" font-size="28" font-weight="700">OpenAdminJS</text></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 280 64" role="img" aria-label="OpenAdminJS"><rect x="0" y="0" width="64" height="64" rx="14" fill="#059669"/><path d="M17 21h30v22H17z" fill="#ECFDF5"/><path d="M23 27h8v4h-8zm12 0h6v4h-6zM23 35h18v4H23z" fill="#059669"/><path d="M47 21 32 12 17 21" fill="none" stroke="#A7F3D0" stroke-width="4" stroke-linejoin="round"/><text x="80" y="40" fill="#0f172a" font-family="Inter, ui-sans-serif, system-ui" font-size="28" font-weight="700">OpenAdminJS</text></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 280 64" role="img" aria-label="OpenAdminJS"><rect x="0" y="0" width="64" height="64" rx="14" fill="#18181b"/><path d="M17 21h30v22H17z" fill="#ECFDF5"/><path d="M23 27h8v4h-8zm12 0h6v4h-6zM23 35h18v4H23z" fill="#18181b"/><path d="M47 21 32 12 17 21" fill="none" stroke="#d4d4d8" stroke-width="4" stroke-linejoin="round"/><text x="80" y="40" fill="#0f172a" font-family="Inter, ui-sans-serif, system-ui" font-size="28" font-weight="700">OpenAdminJS</text></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 280 64" role="img" aria-label="OpenAdminJS"><rect x="0" y="0" width="64" height="64" rx="14" fill="#059669"/><path d="M17 21h30v22H17z" fill="#ECFDF5"/><path d="M23 27h8v4h-8zm12 0h6v4h-6zM23 35h18v4H23z" fill="#059669"/><path d="M47 21 32 12 17 21" fill="none" stroke="#A7F3D0" stroke-width="4" stroke-linejoin="round"/><text x="80" y="40" fill="#0f172a" font-family="Inter, ui-sans-serif, system-ui" font-size="28" font-weight="700">OpenAdminJS</text></svg>
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Generates brand assets from raster masters in `site/assets/brand/`:
3
+ * - openadminjs-logo-new.png (required) — full wordmark / horizontal logo
4
+ * - openadminjs-icon-new.png (optional) — square mark for favicon / app icon; falls back to logo if missing
5
+ *
6
+ * Outputs PNG + thin SVG wrappers (`<image href="…"/>`) for each target directory.
7
+ */
8
+ import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
9
+ import { join, dirname } from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+ import sharp from "sharp";
12
+
13
+ const __dirname = dirname(fileURLToPath(import.meta.url));
14
+ /** `packages/brand/src` → monorepo root */
15
+ const repoRoot = join(__dirname, "../../..");
16
+
17
+ const LOGO_SRC = join(repoRoot, "site/assets/brand/openadminjs-logo-new.png");
18
+ const targets = [
19
+ "apps/admin/public/brand",
20
+ "apps/web/public/brand",
21
+ "packages/cli/template/apps/web/public/brand",
22
+ "packages/create-openadminjs/template/apps/web/public/brand",
23
+ "packages/brand/apps/web/public/brand",
24
+ "packages/brand/apps/admin/public/brand",
25
+ "site/assets/brand"
26
+ ];
27
+
28
+ const UNUSED_BRAND_FILES = [
29
+ "openadminjs-logo-horizontal.svg",
30
+ "openadminjs-logo.svg",
31
+ "openadminjs-logo-dark.svg",
32
+ "openadminjs-logo-monochrome.svg",
33
+ "openadminjs-icon.png",
34
+ "openadminjs-icon.svg",
35
+ "og-image.svg",
36
+ "favicon.png"
37
+ ];
38
+
39
+ /** SVG shell so browsers can scale; raster lives alongside as `href`. */
40
+ function svgRasterImage(href, w, h, label) {
41
+ const safe = String(label).replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
42
+ return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 ${w} ${h}" role="img" aria-label="${safe}"><image xlink:href="${href}" href="${href}" width="${w}" height="${h}" preserveAspectRatio="xMidYMid meet"/></svg>`;
43
+ }
44
+
45
+ async function extractLogoMark(logoBuf) {
46
+ const { data, info } = await sharp(logoBuf).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
47
+ const { width, height, channels } = info;
48
+ const alphaIndex = channels - 1;
49
+
50
+ const activeCols = new Array(width).fill(false);
51
+ for (let x = 0; x < width; x += 1) {
52
+ for (let y = 0; y < height; y += 1) {
53
+ const idx = (y * width + x) * channels + alphaIndex;
54
+ if (data[idx] > 18) {
55
+ activeCols[x] = true;
56
+ break;
57
+ }
58
+ }
59
+ }
60
+
61
+ let symbolStart = activeCols.findIndex(Boolean);
62
+ if (symbolStart < 0) symbolStart = 0;
63
+
64
+ let symbolEnd = width - 1;
65
+ let gap = 0;
66
+ for (let x = symbolStart; x < width; x += 1) {
67
+ if (activeCols[x]) {
68
+ gap = 0;
69
+ symbolEnd = x;
70
+ continue;
71
+ }
72
+ gap += 1;
73
+ if (gap >= 10) break;
74
+ }
75
+
76
+ const activeRows = new Array(height).fill(false);
77
+ for (let y = 0; y < height; y += 1) {
78
+ for (let x = symbolStart; x <= symbolEnd; x += 1) {
79
+ const idx = (y * width + x) * channels + alphaIndex;
80
+ if (data[idx] > 18) {
81
+ activeRows[y] = true;
82
+ break;
83
+ }
84
+ }
85
+ }
86
+
87
+ let top = activeRows.findIndex(Boolean);
88
+ if (top < 0) top = 0;
89
+ let bottom = height - 1;
90
+ for (let y = height - 1; y >= 0; y -= 1) {
91
+ if (activeRows[y]) {
92
+ bottom = y;
93
+ break;
94
+ }
95
+ }
96
+
97
+ const markW = Math.max(1, symbolEnd - symbolStart + 1);
98
+ const markH = Math.max(1, bottom - top + 1);
99
+ const side = Math.max(markW, markH);
100
+ const cx = symbolStart + markW / 2;
101
+ const cy = top + markH / 2;
102
+
103
+ let left = Math.floor(cx - side / 2);
104
+ let cropTop = Math.floor(cy - side / 2);
105
+ if (left < 0) left = 0;
106
+ if (cropTop < 0) cropTop = 0;
107
+ if (left + side > width) left = width - side;
108
+ if (cropTop + side > height) cropTop = height - side;
109
+
110
+ return sharp(logoBuf)
111
+ .extract({ left: Math.max(0, left), top: Math.max(0, cropTop), width: Math.min(side, width), height: Math.min(side, height) })
112
+ .resize(512, 512, { fit: "cover" })
113
+ .png()
114
+ .toBuffer();
115
+ }
116
+
117
+ async function writeBrandToDir(targetDir) {
118
+ mkdirSync(targetDir, { recursive: true });
119
+
120
+ const logoBuf = readFileSync(LOGO_SRC);
121
+ const logoMeta = await sharp(logoBuf).metadata();
122
+ const lw = logoMeta.width ?? 800;
123
+ const lh = logoMeta.height ?? 200;
124
+
125
+ writeFileSync(join(targetDir, "openadminjs-logo-new.png"), logoBuf);
126
+
127
+ const monoPng = await sharp(logoBuf).grayscale().png().toBuffer();
128
+ writeFileSync(join(targetDir, "openadminjs-logo-monochrome.png"), monoPng);
129
+
130
+ const iconBuf = await extractLogoMark(logoBuf);
131
+ writeFileSync(join(targetDir, "openadminjs-icon-new.png"), iconBuf);
132
+
133
+ writeFileSync(join(targetDir, "favicon.svg"), svgRasterImage("openadminjs-icon-new.png", 512, 512, "OpenAdminJS"));
134
+
135
+ const apple = await sharp(iconBuf).resize(180, 180, { fit: "cover" }).png().toBuffer();
136
+ writeFileSync(join(targetDir, "apple-touch-icon.png"), apple);
137
+
138
+ const ogW = 1200;
139
+ const ogH = 630;
140
+ const logoForOg = await sharp(logoBuf).resize(560, null, { fit: "inside" }).png().toBuffer();
141
+ const ogLm = await sharp(logoForOg).metadata();
142
+ const logoH = ogLm.height ?? 0;
143
+ const top = Math.max(0, Math.round((ogH - logoH) / 2));
144
+ const ogPng = await sharp({
145
+ create: { width: ogW, height: ogH, channels: 4, background: { r: 248, g: 251, b: 255, alpha: 1 } }
146
+ })
147
+ .composite([{ input: logoForOg, left: 72, top }])
148
+ .png()
149
+ .toBuffer();
150
+ writeFileSync(join(targetDir, "og-image.png"), ogPng);
151
+
152
+ for (const filename of UNUSED_BRAND_FILES) {
153
+ const full = join(targetDir, filename);
154
+ if (existsSync(full)) unlinkSync(full);
155
+ }
156
+ }
157
+
158
+ async function main() {
159
+ if (process.argv.includes("--check")) {
160
+ if (!existsSync(LOGO_SRC)) {
161
+ console.error(`Missing required source: ${LOGO_SRC}`);
162
+ process.exit(1);
163
+ }
164
+ process.exit(0);
165
+ }
166
+
167
+ if (!existsSync(LOGO_SRC)) {
168
+ throw new Error(`Missing required source logo: ${LOGO_SRC}`);
169
+ }
170
+
171
+ for (const rel of targets) {
172
+ const dir = join(repoRoot, rel);
173
+ await writeBrandToDir(dir);
174
+ console.log("Wrote", rel);
175
+ }
176
+ console.log("Brand assets generated from openadminjs-logo-new.png");
177
+ }
178
+
179
+ main().catch((e) => {
180
+ console.error(e);
181
+ process.exit(1);
182
+ });
@@ -0,0 +1,9 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { brandColors } from "./index";
3
+
4
+ describe("brandColors", () => {
5
+ it("uses hex palette", () => {
6
+ expect(brandColors.primary).toMatch(/^#/);
7
+ expect(brandColors.accent).toMatch(/^#/);
8
+ });
9
+ });
@@ -0,0 +1,7 @@
1
+ export const brandColors = {
2
+ primary: "#059669",
3
+ primaryHover: "#047857",
4
+ primarySoft: "#ECFDF5",
5
+ primaryBorder: "#A7F3D0",
6
+ accent: "#34D399"
7
+ } as const;
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "noEmit": true
5
+ },
6
+ "include": ["src/**/*.ts"]
7
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@openadminjs/core",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc -p tsconfig.json",
9
+ "lint": "tsc -p tsconfig.json --noEmit",
10
+ "typecheck": "tsc -p tsconfig.json --noEmit",
11
+ "test": "vitest run"
12
+ },
13
+ "dependencies": {
14
+ "@openadminjs/resource": "workspace:*"
15
+ },
16
+ "devDependencies": {
17
+ "typescript": "^5.7.2",
18
+ "vitest": "^2.1.8"
19
+ }
20
+ }
@@ -0,0 +1 @@
1
+ export { buildSeoPagePayload, defineResource, effectiveLocale, isSensitiveField, listScopeWhereClause, mergeWhereClauses, pickLocalizedLabel, resolveResourceForLocale, sensitiveFieldPatterns, shouldApplyListScope, validateResource, visibleFields, withSafeFields } from "@openadminjs/resource";
@@ -0,0 +1,27 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { defineResource, validateResource } from "./index";
3
+
4
+ describe("@openadminjs/core", () => {
5
+ it("re-exports defineResource from resource layer", () => {
6
+ const r = defineResource({
7
+ name: "items",
8
+ label: "Items",
9
+ model: "Item",
10
+ permissions: { read: "items.read" },
11
+ fields: { id: { type: "id" } }
12
+ });
13
+ expect(r.name).toBe("items");
14
+ });
15
+
16
+ it("re-exports validateResource", () => {
17
+ expect(() =>
18
+ validateResource({
19
+ name: "bad name",
20
+ label: "X",
21
+ model: "X",
22
+ permissions: { read: "x.read" },
23
+ fields: { id: { type: "id" } }
24
+ })
25
+ ).toThrow("Invalid resource name");
26
+ });
27
+ });
@@ -0,0 +1,61 @@
1
+ export {
2
+ buildSeoPagePayload,
3
+ defineResource,
4
+ effectiveLocale,
5
+ isSensitiveField,
6
+ listScopeWhereClause,
7
+ mergeWhereClauses,
8
+ pickLocalizedLabel,
9
+ resolveResourceForLocale,
10
+ sensitiveFieldPatterns,
11
+ shouldApplyListScope,
12
+ validateResource,
13
+ visibleFields,
14
+ withSafeFields
15
+ } from "@openadminjs/resource";
16
+ export type {
17
+ FieldPermission,
18
+ FieldType,
19
+ ListScopeConfig,
20
+ LocalizedLabel,
21
+ PermissionMap,
22
+ ResourceAction,
23
+ ResourceActionContext,
24
+ ResourceConfig,
25
+ ResourceField,
26
+ ResourceI18nConfig,
27
+ ResourceSeoConfig,
28
+ SeoPagePayload
29
+ } from "@openadminjs/resource";
30
+
31
+ export type OpenAdminUser = {
32
+ id: string;
33
+ email: string;
34
+ name?: string | null;
35
+ roles: string[];
36
+ permissions: string[];
37
+ };
38
+
39
+ export type AdminListQuery = {
40
+ page?: number;
41
+ limit?: number;
42
+ search?: string;
43
+ sort?: string;
44
+ filter?: Record<string, string | string[]>;
45
+ };
46
+
47
+ export type PaginatedResult<T> = {
48
+ data: T[];
49
+ meta: {
50
+ page: number;
51
+ limit: number;
52
+ total: number;
53
+ pages: number;
54
+ };
55
+ };
56
+
57
+ export type OpenAdminError = {
58
+ message: string;
59
+ code?: string;
60
+ details?: unknown;
61
+ };
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "declaration": true
6
+ },
7
+ "include": ["src/**/*.ts"]
8
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@openadminjs/mail",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "src/index.ts",
6
+ "scripts": {
7
+ "build": "tsc -p tsconfig.json",
8
+ "lint": "tsc -p tsconfig.json --noEmit",
9
+ "typecheck": "tsc -p tsconfig.json --noEmit",
10
+ "test": "vitest run"
11
+ },
12
+ "devDependencies": {
13
+ "@types/nodemailer": "^6.4.17",
14
+ "nodemailer": "^6.9.16",
15
+ "typescript": "^5.7.2",
16
+ "vitest": "^2.1.8"
17
+ }
18
+ }
@@ -0,0 +1,23 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import type { MailDriver, MailMessage, SentInfo } from "./index";
3
+
4
+ describe("mail types", () => {
5
+ it("allows a driver implementation to send messages", async () => {
6
+ const sent: MailMessage[] = [];
7
+ const driver: MailDriver = {
8
+ send: vi.fn(async (message: MailMessage) => {
9
+ sent.push(message);
10
+ const accepted = Array.isArray(message.to) ? message.to : [message.to];
11
+ return {
12
+ messageId: "test-message-id",
13
+ accepted
14
+ } satisfies SentInfo;
15
+ })
16
+ };
17
+
18
+ await driver.send({ to: "a@b.com", subject: "Hi", template: "welcome", data: { name: "x" } });
19
+
20
+ expect(sent).toHaveLength(1);
21
+ expect(sent[0]?.to).toBe("a@b.com");
22
+ });
23
+ });
@@ -0,0 +1,246 @@
1
+ // ──────────────────────────────────────────────────────────────────────────────
2
+ // @openadminjs/mail — email abstraction layer with template engine
3
+ //
4
+ // Usage (with SMTP):
5
+ // const mailer = new SmtpMailDriver({ host: "smtp.gmail.com", port: 587, ... });
6
+ //
7
+ // Usage (with mock for dev/tests):
8
+ // const mailer = new MockMailDriver();
9
+ // ──────────────────────────────────────────────────────────────────────────────
10
+
11
+ export type MailAddress = string | { name: string; address: string };
12
+
13
+ export type MailAttachment = {
14
+ filename: string;
15
+ content: string | Buffer;
16
+ contentType?: string;
17
+ };
18
+
19
+ export type MailMessage = {
20
+ to: MailAddress | MailAddress[];
21
+ from?: MailAddress;
22
+ replyTo?: MailAddress;
23
+ subject: string;
24
+ /** Plain text body */
25
+ text?: string;
26
+ /** HTML body — use renderTemplate() to build from a template */
27
+ html?: string;
28
+ /** Template name (resolved by the registered template engine) */
29
+ template?: string;
30
+ /** Data passed to the template engine */
31
+ data?: Record<string, unknown>;
32
+ attachments?: MailAttachment[];
33
+ };
34
+
35
+ export type SentInfo = {
36
+ messageId: string;
37
+ accepted: MailAddress[];
38
+ };
39
+
40
+ export interface MailDriver {
41
+ send(message: MailMessage): Promise<SentInfo>;
42
+ }
43
+
44
+ // ──────────────────────────────────────────────
45
+ // Minimal built-in template engine
46
+ // ──────────────────────────────────────────────
47
+
48
+ /**
49
+ * Renders a template string with `{{variable}}` placeholders.
50
+ * Supports nested keys via dot notation: `{{user.name}}`.
51
+ */
52
+ export function renderTemplate(template: string, data: Record<string, unknown> = {}): string {
53
+ return template.replace(/\{\{([\w.]+)}}/g, (_, key: string) => {
54
+ const value = key.split(".").reduce<unknown>((obj, k) => {
55
+ if (obj != null && typeof obj === "object") return (obj as Record<string, unknown>)[k];
56
+ return undefined;
57
+ }, data);
58
+ return value != null ? String(value) : "";
59
+ });
60
+ }
61
+
62
+ // ──────────────────────────────────────────────
63
+ // Built-in HTML email templates
64
+ // ──────────────────────────────────────────────
65
+
66
+ const BASE_LAYOUT = `<!DOCTYPE html>
67
+ <html lang="en">
68
+ <head>
69
+ <meta charset="UTF-8" />
70
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
71
+ <title>{{subject}}</title>
72
+ <style>
73
+ body{margin:0;padding:0;background:#f1f5f9;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif}
74
+ .wrap{max-width:560px;margin:40px auto;background:#fff;border-radius:16px;overflow:hidden;box-shadow:0 4px 24px rgba(0,0,0,.06)}
75
+ .header{background:linear-gradient(135deg,#2454ff,#0ea5a4);padding:32px 40px}
76
+ .header h1{color:#fff;margin:0;font-size:22px;font-weight:700}
77
+ .body{padding:32px 40px}
78
+ .body p{color:#475569;line-height:1.7;margin:0 0 16px}
79
+ .btn{display:inline-block;padding:12px 28px;background:#2454ff;color:#fff;border-radius:10px;text-decoration:none;font-weight:600;font-size:14px}
80
+ .footer{padding:20px 40px;background:#f8fafc;text-align:center}
81
+ .footer p{color:#94a3b8;font-size:12px;margin:0}
82
+ .divider{height:1px;background:#e2e8f0;margin:20px 0}
83
+ .highlight{background:#eef3ff;border-radius:8px;padding:16px;font-family:monospace;word-break:break-all;color:#2454ff;font-size:14px}
84
+ </style>
85
+ </head>
86
+ <body>
87
+ <div class="wrap">
88
+ <div class="header"><h1>{{appName}}</h1></div>
89
+ <div class="body">{{bodyContent}}</div>
90
+ <div class="footer"><p>© {{year}} {{appName}}. This email was sent automatically.</p></div>
91
+ </div>
92
+ </body>
93
+ </html>`;
94
+
95
+ export const EMAIL_TEMPLATES: Record<string, string> = {
96
+ welcome: BASE_LAYOUT.replace(
97
+ "{{bodyContent}}",
98
+ `<p>Hi <strong>{{name}}</strong>,</p>
99
+ <p>Welcome to <strong>{{appName}}</strong>! Your account has been created successfully.</p>
100
+ <p><a href="{{loginUrl}}" class="btn">Sign in to your account</a></p>
101
+ <div class="divider"></div>
102
+ <p>If you didn't create this account, you can safely ignore this email.</p>`
103
+ ),
104
+
105
+ "password-reset": BASE_LAYOUT.replace(
106
+ "{{bodyContent}}",
107
+ `<p>Hi {{name}},</p>
108
+ <p>You requested a password reset. Click the button below to set a new password:</p>
109
+ <p><a href="{{resetUrl}}" class="btn">Reset password</a></p>
110
+ <div class="divider"></div>
111
+ <p>This link expires in <strong>{{expiresIn}}</strong>. If you didn't request a reset, ignore this email.</p>`
112
+ ),
113
+
114
+ "email-verification": BASE_LAYOUT.replace(
115
+ "{{bodyContent}}",
116
+ `<p>Hi {{name}},</p>
117
+ <p>Please verify your email address to complete your registration:</p>
118
+ <p><a href="{{verifyUrl}}" class="btn">Verify email address</a></p>
119
+ <div class="divider"></div>
120
+ <p>This link expires in <strong>{{expiresIn}}</strong>.</p>`
121
+ ),
122
+
123
+ "order-confirmation": BASE_LAYOUT.replace(
124
+ "{{bodyContent}}",
125
+ `<p>Hi {{customerName}},</p>
126
+ <p>Thank you for your order! Here's a summary:</p>
127
+ <div class="highlight">Order #{{orderId}} — {{currency}} {{totalDisplay}}</div>
128
+ <p style="margin-top:16px">You can check your order status at any time:</p>
129
+ <p><a href="{{orderUrl}}" class="btn">View order</a></p>`
130
+ ),
131
+
132
+ "order-refunded": BASE_LAYOUT.replace(
133
+ "{{bodyContent}}",
134
+ `<p>Hi {{customerName}},</p>
135
+ <p>Your refund for order <strong>#{{orderId}}</strong> has been processed.</p>
136
+ <div class="highlight">Refund amount: {{currency}} {{totalDisplay}}</div>
137
+ <p>The funds will be returned to your original payment method within 5–10 business days.</p>`
138
+ )
139
+ };
140
+
141
+ // ──────────────────────────────────────────────
142
+ // Mock driver (dev / testing)
143
+ // ──────────────────────────────────────────────
144
+
145
+ export type SentMailRecord = MailMessage & { sentAt: Date };
146
+
147
+ export class MockMailDriver implements MailDriver {
148
+ readonly sent: SentMailRecord[] = [];
149
+
150
+ async send(message: MailMessage): Promise<SentInfo> {
151
+ const resolved = this.resolve(message);
152
+ this.sent.push({ ...resolved, sentAt: new Date() });
153
+ return {
154
+ messageId: `mock_${Date.now()}@localhost`,
155
+ accepted: Array.isArray(message.to) ? message.to : [message.to]
156
+ };
157
+ }
158
+
159
+ private resolve(message: MailMessage): MailMessage {
160
+ if (message.template && EMAIL_TEMPLATES[message.template]) {
161
+ const data = { year: new Date().getFullYear(), ...(message.data ?? {}) };
162
+ return { ...message, html: renderTemplate(EMAIL_TEMPLATES[message.template]!, data) };
163
+ }
164
+ return message;
165
+ }
166
+
167
+ last(): SentMailRecord | undefined {
168
+ return this.sent[this.sent.length - 1];
169
+ }
170
+
171
+ clear() {
172
+ this.sent.length = 0;
173
+ }
174
+ }
175
+
176
+ // ──────────────────────────────────────────────
177
+ // SMTP driver (nodemailer-based)
178
+ // ──────────────────────────────────────────────
179
+
180
+ export type SmtpConfig = {
181
+ host: string;
182
+ port: number;
183
+ secure?: boolean;
184
+ auth?: { user: string; pass: string };
185
+ from?: MailAddress;
186
+ appName?: string;
187
+ };
188
+
189
+ export class SmtpMailDriver implements MailDriver {
190
+ private readonly config: SmtpConfig;
191
+ // Transporter is created lazily so nodemailer is not required unless used
192
+ private transporter: unknown = null;
193
+
194
+ constructor(config: SmtpConfig) {
195
+ this.config = config;
196
+ }
197
+
198
+ private async getTransporter() {
199
+ if (!this.transporter) {
200
+ const nodemailer = (await import("nodemailer")) as typeof import("nodemailer");
201
+ this.transporter = nodemailer.createTransport({
202
+ host: this.config.host,
203
+ port: this.config.port,
204
+ secure: this.config.secure ?? this.config.port === 465,
205
+ auth: this.config.auth
206
+ });
207
+ }
208
+ return this.transporter as Awaited<ReturnType<typeof import("nodemailer").createTransport>>;
209
+ }
210
+
211
+ async send(message: MailMessage): Promise<SentInfo> {
212
+ const transporter = await this.getTransporter();
213
+ const resolved = this.resolve(message);
214
+ const info = await transporter.sendMail({
215
+ from: resolved.from ?? this.config.from ?? `noreply@${this.config.host}`,
216
+ to: Array.isArray(resolved.to) ? resolved.to.join(", ") : resolved.to,
217
+ replyTo: resolved.replyTo as string | undefined,
218
+ subject: resolved.subject,
219
+ text: resolved.text,
220
+ html: resolved.html,
221
+ attachments: resolved.attachments
222
+ });
223
+ return { messageId: info.messageId as string, accepted: info.accepted as MailAddress[] };
224
+ }
225
+
226
+ private resolve(message: MailMessage): MailMessage {
227
+ if (message.template && EMAIL_TEMPLATES[message.template]) {
228
+ const data: Record<string, unknown> = {
229
+ appName: this.config.appName ?? "OpenAdminJS",
230
+ year: new Date().getFullYear(),
231
+ ...(message.data ?? {})
232
+ };
233
+ return { ...message, html: renderTemplate(EMAIL_TEMPLATES[message.template]!, data) };
234
+ }
235
+ return message;
236
+ }
237
+ }
238
+
239
+ // ──────────────────────────────────────────────
240
+ // Factory
241
+ // ──────────────────────────────────────────────
242
+
243
+ export function createMailDriver(config?: SmtpConfig): MailDriver {
244
+ if (config?.host) return new SmtpMailDriver(config);
245
+ return new MockMailDriver();
246
+ }