openadminjs 0.2.0 → 0.3.0-rc.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 (219) hide show
  1. package/README.md +106 -151
  2. package/dist/adapt-package-manager.js +4 -1
  3. package/dist/create-project.d.ts +46 -0
  4. package/dist/create-project.js +417 -150
  5. package/dist/doctor.d.ts +13 -0
  6. package/dist/doctor.js +35 -6
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +257 -39
  9. package/dist/render-schema.d.ts +0 -17
  10. package/dist/render-schema.js +25 -29
  11. package/dist/resource-slug.d.ts +1 -0
  12. package/dist/resource-slug.js +7 -0
  13. package/dist/runtime-mode.d.ts +16 -0
  14. package/dist/runtime-mode.js +138 -0
  15. package/dist/upgrade.d.ts +10 -0
  16. package/dist/upgrade.js +133 -0
  17. package/package.json +14 -11
  18. package/template/.dockerignore +15 -0
  19. package/template/.env.production.example +5 -0
  20. package/template/Dockerfile +12 -0
  21. package/template/README.md +4 -3
  22. package/template/apps/admin/app/api/auth/login/route.ts +9 -9
  23. package/template/apps/admin/app/api/auth/logout/route.ts +11 -3
  24. package/template/apps/admin/app/api/auth/oidc/callback/route.ts +19 -0
  25. package/template/apps/admin/app/api/auth/oidc/start/route.ts +11 -0
  26. package/template/apps/admin/app/api/auth/oidc/status/route.ts +6 -0
  27. package/template/apps/admin/app/api/auth/refresh/route.ts +18 -11
  28. package/template/apps/admin/app/api/backend/[...path]/route.ts +48 -0
  29. package/template/apps/admin/app/api-tokens/page.tsx +39 -39
  30. package/template/apps/admin/app/assistant/page.tsx +11 -0
  31. package/template/apps/admin/app/dashboard/page.tsx +45 -462
  32. package/template/apps/admin/app/globals.css +52 -16
  33. package/template/apps/admin/app/layout.tsx +1 -1
  34. package/template/apps/admin/app/login/page.tsx +13 -145
  35. package/template/apps/admin/app/plugins/page.tsx +16 -402
  36. package/template/apps/admin/app/profile/page.tsx +5 -2
  37. package/template/apps/admin/app/settings/page.tsx +14 -265
  38. package/template/apps/admin/components/ai-assistant-widget.tsx +3 -6
  39. package/template/apps/admin/components/app-shell.tsx +25 -373
  40. package/template/apps/admin/components/auth-guard.tsx +8 -28
  41. package/template/apps/admin/components/logo.tsx +1 -30
  42. package/template/apps/admin/components/resource-form.tsx +3 -3
  43. package/template/apps/admin/components/resource-table.tsx +12 -8
  44. package/template/apps/admin/lib/api.ts +45 -107
  45. package/template/apps/admin/lib/resource-table-prefs.ts +1 -57
  46. package/template/apps/admin/lib/server-api.ts +7 -0
  47. package/template/apps/admin/lib/tokens.ts +9 -81
  48. package/template/apps/admin/middleware.ts +9 -50
  49. package/template/apps/admin/next.config.mjs +4 -0
  50. package/template/apps/admin/package.json +2 -1
  51. package/template/apps/admin/public/brand/favicon.svg +4 -1
  52. package/template/apps/admin/tailwind.config.ts +9 -8
  53. package/template/apps/api/package.json +10 -6
  54. package/template/apps/api/src/access/catalog.ts +4 -0
  55. package/template/apps/api/src/admin/admin-ai.controller.ts +15 -125
  56. package/template/apps/api/src/admin/admin-analytics.service.ts +16 -148
  57. package/template/apps/api/src/admin/admin-logs.controller.ts +4 -1
  58. package/template/apps/api/src/admin/admin-plugins.controller.ts +8 -8
  59. package/template/apps/api/src/admin/admin-plugins.service.ts +15 -259
  60. package/template/apps/api/src/admin/admin-resource.service.ts +105 -254
  61. package/template/apps/api/src/admin/admin.controller.ts +17 -4
  62. package/template/apps/api/src/admin/admin.module.ts +2 -2
  63. package/template/apps/api/src/admin/resource-policy.ts +1 -0
  64. package/template/apps/api/src/admin/resource-query.ts +1 -0
  65. package/template/apps/api/src/admin/safe-ai.service.ts +43 -0
  66. package/template/apps/api/src/admin/validate-resource-payload.ts +2 -0
  67. package/template/apps/api/src/auth/auth.controller.ts +4 -2
  68. package/template/apps/api/src/auth/auth.service.ts +68 -83
  69. package/template/apps/api/src/auth/sso-oidc.controller.ts +12 -74
  70. package/template/apps/api/src/auth/sso-oidc.service.ts +51 -268
  71. package/template/apps/api/src/common/api-exception.filter.ts +1 -0
  72. package/template/apps/api/src/common/auth.guard.ts +66 -39
  73. package/template/apps/api/src/common/json-field-codec.ts +12 -13
  74. package/template/apps/api/src/common/prisma.service.ts +9 -17
  75. package/template/apps/api/src/common/request-logging.interceptor.ts +8 -3
  76. package/template/apps/api/src/graphql/graphql.module.ts +5 -4
  77. package/template/apps/api/src/health/health.controller.ts +6 -0
  78. package/template/apps/api/src/main.ts +11 -2
  79. package/template/apps/api/src/plugins/plugin-loader.ts +5 -3
  80. package/template/apps/api/src/resources/commerce.resource.ts +3 -34
  81. package/template/apps/api/src/resources/operations.resource.ts +1 -0
  82. package/template/apps/api/src/store/payment/payment.controller.ts +15 -92
  83. package/template/apps/api/src/store/payment/payment.module.ts +2 -3
  84. package/template/apps/api/src/store/payment/payment.service.ts +121 -227
  85. package/template/apps/api/webpack.config.cjs +2 -1
  86. package/template/apps/web/next.config.mjs +4 -0
  87. package/template/apps/web/public/brand/favicon.svg +4 -1
  88. package/template/compose.yaml +56 -0
  89. package/template/examples/crm-admin/README.md +31 -0
  90. package/template/examples/crm-admin/package.json +17 -0
  91. package/template/examples/crm-admin/prisma/models.fragment.prisma +50 -0
  92. package/template/examples/crm-admin/src/index.ts +7 -0
  93. package/template/examples/crm-admin/src/resources/activities.resource.ts +29 -0
  94. package/template/examples/crm-admin/src/resources/companies.resource.ts +21 -0
  95. package/template/examples/crm-admin/src/resources/contacts.resource.ts +24 -0
  96. package/template/examples/crm-admin/src/resources/deals.resource.ts +30 -0
  97. package/template/examples/crm-admin/tsconfig.json +7 -0
  98. package/template/package.json +6 -1
  99. package/template/packages/admin-client/package.json +18 -0
  100. package/template/packages/admin-client/src/contracts.ts +29 -0
  101. package/template/packages/admin-client/src/index.ts +2 -0
  102. package/template/packages/admin-client/src/preferences.ts +57 -0
  103. package/template/packages/admin-client/tsconfig.json +12 -0
  104. package/template/packages/auth/package.json +1 -1
  105. package/template/packages/brand/site/assets/brand/favicon.svg +4 -1
  106. package/template/packages/brand/src/generate-assets.mjs +17 -186
  107. package/template/packages/core/package.json +1 -1
  108. package/template/packages/mail/package.json +1 -1
  109. package/template/packages/nest/package.json +22 -0
  110. package/template/packages/nest/src/api-exception.filter.ts +23 -0
  111. package/template/packages/nest/src/index.ts +3 -0
  112. package/template/packages/nest/src/resource-policy.ts +64 -0
  113. package/template/packages/nest/src/resource-query.ts +103 -0
  114. package/template/packages/nest/tsconfig.json +12 -0
  115. package/template/packages/notifications/package.json +1 -1
  116. package/template/packages/payments/package.json +1 -1
  117. package/template/packages/permissions/package.json +1 -1
  118. package/template/packages/permissions/src/index.ts +2 -2
  119. package/template/packages/plugin-sdk/package.json +1 -1
  120. package/template/packages/plugin-sdk/src/index.ts +2 -2
  121. package/template/packages/prisma/package.json +21 -0
  122. package/template/packages/prisma/schema/ai.prisma +36 -0
  123. package/template/packages/prisma/schema/audit.prisma +13 -0
  124. package/template/packages/prisma/schema/commerce.prisma +79 -0
  125. package/template/packages/prisma/schema/content.prisma +27 -0
  126. package/template/packages/prisma/schema/core.prisma +106 -0
  127. package/template/packages/prisma/schema/header.prisma +8 -0
  128. package/template/packages/prisma/schema/jobs.prisma +9 -0
  129. package/template/packages/prisma/schema/media.prisma +9 -0
  130. package/template/packages/prisma/schema/modules.json +47 -0
  131. package/template/packages/prisma/schema/notifications.prisma +9 -0
  132. package/template/packages/prisma/schema/settings.prisma +8 -0
  133. package/template/packages/prisma/schema/tokens.prisma +10 -0
  134. package/template/packages/prisma/src/index.d.ts +12 -0
  135. package/template/packages/prisma/src/index.mjs +138 -0
  136. package/template/packages/queue/package.json +1 -1
  137. package/template/packages/resource/package.json +1 -1
  138. package/template/packages/resource/src/index.ts +1 -0
  139. package/template/packages/storage/package.json +1 -1
  140. package/template/packages/storage/src/index.ts +37 -0
  141. package/template/prisma/migrations/20261126130000_add_sessions/migration.sql +26 -0
  142. package/template/prisma/migrations/20261126140000_api_token_hash/migration.sql +3 -0
  143. package/template/prisma/migrations/20261126150000_payment_idempotency/migration.sql +6 -0
  144. package/template/prisma/schema.prisma +82 -54
  145. package/template/prisma/seed.ts +14 -38
  146. package/template/runtime-versions.json +15 -0
  147. package/template/scripts/db-init.mjs +33 -0
  148. package/template/scripts/install-crm.mjs +50 -0
  149. package/template/scripts/migrate-existing.mjs +65 -0
  150. package/template/scripts/schema.mjs +48 -0
  151. package/template/tsconfig.base.json +23 -5
  152. package/LICENSE +0 -21
  153. package/dist/adapt-package-manager.test.d.ts +0 -1
  154. package/dist/adapt-package-manager.test.js +0 -76
  155. package/dist/cli.e2e.test.d.ts +0 -1
  156. package/dist/cli.e2e.test.js +0 -87
  157. package/dist/create-project.test.d.ts +0 -1
  158. package/dist/create-project.test.js +0 -275
  159. package/dist/database-providers.integration.test.d.ts +0 -1
  160. package/dist/database-providers.integration.test.js +0 -64
  161. package/dist/db-commands.test.d.ts +0 -1
  162. package/dist/db-commands.test.js +0 -27
  163. package/dist/doctor.test.d.ts +0 -1
  164. package/dist/doctor.test.js +0 -102
  165. package/dist/index.test.d.ts +0 -1
  166. package/dist/index.test.js +0 -11
  167. package/dist/render-schema.test.d.ts +0 -1
  168. package/dist/render-schema.test.js +0 -57
  169. package/dist/resource-slug.test.d.ts +0 -1
  170. package/dist/resource-slug.test.js +0 -9
  171. package/dist/secrets.test.d.ts +0 -1
  172. package/dist/secrets.test.js +0 -36
  173. package/dist/security.test.d.ts +0 -1
  174. package/dist/security.test.js +0 -54
  175. package/dist/validate-name.test.d.ts +0 -1
  176. package/dist/validate-name.test.js +0 -63
  177. package/template/apps/admin/.storybook/main.ts +0 -12
  178. package/template/apps/admin/.storybook/preview.ts +0 -10
  179. package/template/apps/admin/app/login/page.test.tsx +0 -18
  180. package/template/apps/admin/components/auth-guard.test.tsx +0 -55
  181. package/template/apps/admin/components/logo.stories.tsx +0 -24
  182. package/template/apps/admin/lib/api.test.ts +0 -118
  183. package/template/apps/admin/lib/auth-flow.e2e.test.ts +0 -79
  184. package/template/apps/admin/vitest.config.ts +0 -7
  185. package/template/apps/api/src/access/derive-permissions.test.ts +0 -26
  186. package/template/apps/api/src/admin/admin-resource.service.test.ts +0 -118
  187. package/template/apps/api/src/admin/validate-resource-payload.test.ts +0 -44
  188. package/template/apps/api/src/app.module.test.ts +0 -12
  189. package/template/apps/api/src/auth/auth.service.test.ts +0 -78
  190. package/template/apps/api/src/auth/sso-oidc.service.test.ts +0 -84
  191. package/template/apps/api/src/common/auth.guard.test.ts +0 -62
  192. package/template/apps/api/src/common/casl-ability.factory.test.ts +0 -33
  193. package/template/apps/api/src/common/json-field-codec.test.ts +0 -76
  194. package/template/apps/api/src/common/prisma.service.test.ts +0 -19
  195. package/template/apps/api/src/common/request-logging.interceptor.test.ts +0 -39
  196. package/template/apps/api/src/graphql/admin-resources.resolver.test.ts +0 -45
  197. package/template/apps/api/src/graphql/ensure-gql-paramtypes.test.ts +0 -44
  198. package/template/apps/api/src/graphql/graphql-apollo-config.test.ts +0 -26
  199. package/template/apps/api/src/graphql/graphql-schema.test.ts +0 -26
  200. package/template/apps/api/src/plugins/manifest.schema.test.ts +0 -36
  201. package/template/apps/api/src/plugins/plugin-runtime.test.ts +0 -24
  202. package/template/apps/api/src/queue/queue.service.test.ts +0 -33
  203. package/template/apps/api/src/resources/resource-hooks.registry.test.ts +0 -72
  204. package/template/apps/api/vitest.config.ts +0 -21
  205. package/template/apps/web/lib/seo.test.ts +0 -41
  206. package/template/apps/web/vitest.config.ts +0 -19
  207. package/template/packages/auth/src/index.test.ts +0 -10
  208. package/template/packages/brand/src/index.test.ts +0 -9
  209. package/template/packages/core/src/index.test.ts +0 -27
  210. package/template/packages/core/vitest.config.ts +0 -9
  211. package/template/packages/mail/src/index.test.ts +0 -23
  212. package/template/packages/notifications/src/index.test.ts +0 -9
  213. package/template/packages/permissions/src/blueprints.test.ts +0 -62
  214. package/template/packages/permissions/src/index.test.ts +0 -34
  215. package/template/packages/plugin-sdk/src/sdk.test.ts +0 -13
  216. package/template/packages/plugin-sdk/vitest.config.ts +0 -5
  217. package/template/packages/queue/src/index.test.ts +0 -12
  218. package/template/packages/resource/src/index.test.ts +0 -196
  219. package/template/packages/storage/src/index.test.ts +0 -10
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openadminjs/mail",
3
- "version": "0.1.0",
3
+ "version": "0.2.0-rc.1",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@openadminjs/nest",
3
+ "version": "0.2.0-rc.1",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "dependencies": {
9
+ "@openadminjs/core": "workspace:*"
10
+ },
11
+ "peerDependencies": {
12
+ "@nestjs/common": "11.1.21"
13
+ },
14
+ "scripts": {
15
+ "build": "tsc -p tsconfig.json",
16
+ "lint": "tsc -p tsconfig.json --noEmit",
17
+ "typecheck": "tsc -p tsconfig.json --noEmit"
18
+ },
19
+ "devDependencies": {
20
+ "typescript": "^5.7.2"
21
+ }
22
+ }
@@ -0,0 +1,23 @@
1
+ import { ArgumentsHost,Catch,ExceptionFilter,HttpException } from "@nestjs/common";
2
+ type Response = { headersSent:boolean; status(code:number):Response; json(body:unknown):void; getHeader(name:string):unknown };
3
+ @Catch()
4
+ export class ApiExceptionFilter implements ExceptionFilter {
5
+ catch(exception:unknown,host:ArgumentsHost) {
6
+ if(host.getType()!=="http") throw exception;
7
+ const res=host.switchToHttp().getResponse<Response>();
8
+ if(res.headersSent) return;
9
+ let status=500,code="INTERNAL_ERROR",message:unknown="Internal request failure";
10
+ let details:unknown;
11
+ if(exception instanceof HttpException){
12
+ status=exception.getStatus();
13
+ const body=exception.getResponse();
14
+ const obj=typeof body==="object"&&body!==null?body as Record<string,unknown>:null;
15
+ if(status<500){code=typeof obj?.code==="string"?obj.code:"HTTP_"+status;message=obj?.message??body;details=obj?.details;}
16
+ }else if(exception&&typeof exception==="object"&&"code" in exception){
17
+ const p=(exception as {code:unknown}).code;
18
+ if(p==="P2002"||p==="P2003"){status=409;code="CONFLICT";message="Record conflicts with existing data";}
19
+ if(p==="P2025"){status=404;code="NOT_FOUND";message="Record not found";}
20
+ }
21
+ res.status(status).json({statusCode:status,code,message,requestId:res.getHeader("x-request-id"),...(details===undefined?{}:{details})});
22
+ }
23
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./resource-policy.js";
2
+ export * from "./resource-query.js";
3
+ export * from "./api-exception.filter.js";
@@ -0,0 +1,64 @@
1
+ import { BadRequestException, ForbiddenException } from "@nestjs/common";
2
+ import { isSensitiveField, shouldApplyListScope, listScopeWhereClause } from "@openadminjs/core";
3
+ import type { ResourceConfig } from "@openadminjs/core";
4
+ export type UserContext = { id: string; email?: string; permissions: string[] };
5
+ export function isOutOfListScope(resource: ResourceConfig, user: UserContext, record: unknown): boolean {
6
+ if (resource.name === "settings" && String((record as Record<string, unknown>).key ?? "").toLowerCase().startsWith("ai.")) return true;
7
+ if (!shouldApplyListScope(resource, user.permissions)) return false;
8
+ const clause = listScopeWhereClause(resource, user.id);
9
+ if (!clause) return false;
10
+ const row = record as Record<string, unknown>;
11
+ for (const [key, expected] of Object.entries(clause)) {
12
+ if (row[key] !== expected) return true;
13
+ }
14
+ return false;
15
+ }
16
+
17
+ export function has(user: UserContext, permission?: string) {
18
+ return Boolean(permission && (user.permissions.includes(permission) || user.permissions.includes("*")));
19
+ }
20
+
21
+ export function systemScope(resource: ResourceConfig) {
22
+ return resource.name === "settings" ? { NOT: { key: { startsWith: "ai." } } } : undefined;
23
+ }
24
+
25
+ export function canReadField(resource: ResourceConfig, name: string, user: UserContext) {
26
+ const field = Object.hasOwn(resource.fields, name) ? resource.fields[name] : undefined;
27
+ return Boolean(field && !isSensitiveField(name, field) && (!field.permissions?.read || has(user, field.permissions.read)));
28
+ }
29
+
30
+ export function safeData(resource: ResourceConfig, data: Record<string, unknown>, mode: "create" | "edit", user: UserContext) {
31
+ for (const name of Object.keys(data)) {
32
+ const field = Object.hasOwn(resource.fields, name) ? resource.fields[name] : undefined;
33
+ if (!field) throw new BadRequestException({ message: "Unknown field", code: "FIELD_UNKNOWN" });
34
+ const permission = field.permissions?.[mode === "create" ? "create" : "update"];
35
+ if (permission && !has(user, permission)) throw new ForbiddenException({ message: "Missing field permission", code: "FIELD_PERMISSION_DENIED" });
36
+ if (field[mode] === false || isSensitiveField(name, field) || field.type === "id" || field.type === "computed") throw new ForbiddenException("Field is not writable");
37
+ }
38
+ if (resource.name === "settings" && "key" in data && String(data.key).toLowerCase().startsWith("ai.")) throw new ForbiddenException("Reserved setting");
39
+ return { ...data };
40
+ }
41
+
42
+ export function redact(value: unknown): unknown {
43
+ if (Array.isArray(value)) return value.map(item => redact(item));
44
+ if (!value || typeof value !== "object" || value instanceof Date) return value;
45
+ return Object.fromEntries(Object.entries(value).filter(([name]) => !isSensitiveField(name)).map(([name, item]) => [name, redact(item)]));
46
+ }
47
+
48
+ export function auditSnapshot(resource: ResourceConfig, record: unknown) {
49
+ if (!record || typeof record !== "object") return {};
50
+ return redact(Object.fromEntries(Object.entries(record).filter(([name]) => {
51
+ const field = resource.fields[name];
52
+ return Object.hasOwn(resource.fields, name) && field && !isSensitiveField(name, field) && field.type !== "json";
53
+ })));
54
+ }
55
+
56
+ export function sanitizeRecord(resource: ResourceConfig, record: unknown, user: UserContext) {
57
+ if (!record || typeof record !== "object") return record;
58
+ const entries = Object.entries(record).filter(([name]) => canReadField(resource, name, user));
59
+ // Historical snapshots may contain secrets and cannot reliably be sanitized retroactively.
60
+ if (resource.name === "audit-logs") return Object.fromEntries(entries.filter(([name]) => name !== "before" && name !== "after"));
61
+ if (resource.name === "settings" && String((record as Record<string, unknown>).key ?? "").toLowerCase().startsWith("ai.")) return {};
62
+ return Object.fromEntries(entries);
63
+ }
64
+
@@ -0,0 +1,103 @@
1
+ import { BadRequestException } from "@nestjs/common";
2
+ import type { ResourceConfig, ResourceField } from "@openadminjs/core";
3
+ import { canReadField, type UserContext } from "./resource-policy.js";
4
+ export function buildWhere(resource: ResourceConfig, query: Record<string, unknown>, user: UserContext) {
5
+ const clauses: Record<string, unknown>[] = [];
6
+ if (query.search) {
7
+ const searchable = Object.entries(resource.fields).filter(([name, field]) => field.searchable && canReadField(resource, name, user));
8
+ clauses.push({ OR: searchable.map(([field]) => ({ [field]: { contains: String(query.search), ...(/^(postgres|postgresql):/.test(process.env.DATABASE_URL ?? "postgresql:") ? { mode: "insensitive" } : {}) } })) });
9
+ }
10
+ for (const [key, value] of Object.entries(query)) {
11
+ const opMatch = key.match(/^filter\[([^\]]+)]\[(\w+)]$/);
12
+ if (opMatch?.[1] && opMatch[2]) {
13
+ const clause = buildOperatorClause(resource, opMatch[1], opMatch[2], value, user);
14
+ if (clause) clauses.push(clause);
15
+ continue;
16
+ }
17
+ const legacy = key.match(/^filter\[([^\]]+)]$/);
18
+ if (legacy?.[1]) {
19
+ const clause = buildOperatorClause(resource, legacy[1], "eq", value, user);
20
+ if (clause) clauses.push(clause);
21
+ }
22
+ }
23
+ return clauses.length ? { AND: clauses } : undefined;
24
+ }
25
+
26
+ export function buildOperatorClause(resource: ResourceConfig, fieldName: string, op: string, raw: unknown, user: UserContext): Record<string, unknown> | null {
27
+ const field = resource.fields[fieldName];
28
+ if (!field?.filterable || !canReadField(resource, fieldName, user)) {
29
+ throw new BadRequestException({ message: `Field "${fieldName}" is not filterable`, code: "FILTER_NOT_ALLOWED" });
30
+ }
31
+ const str = raw == null ? "" : String(raw);
32
+ switch (op) {
33
+ case "eq":
34
+ return { [fieldName]: coerceFilterScalar(field, str) };
35
+ case "ne":
36
+ return { [fieldName]: { not: coerceFilterScalar(field, str) } };
37
+ case "in": {
38
+ const parts = str
39
+ .split(",")
40
+ .map((s) => s.trim())
41
+ .filter(Boolean)
42
+ .map((p) => coerceFilterScalar(field, p));
43
+ return { [fieldName]: { in: parts } };
44
+ }
45
+ case "gt":
46
+ return { [fieldName]: { gt: coerceFilterComparable(field, str) } };
47
+ case "gte":
48
+ return { [fieldName]: { gte: coerceFilterComparable(field, str) } };
49
+ case "lt":
50
+ return { [fieldName]: { lt: coerceFilterComparable(field, str) } };
51
+ case "lte":
52
+ return { [fieldName]: { lte: coerceFilterComparable(field, str) } };
53
+ case "contains": {
54
+ if (!isStringFilterField(field)) {
55
+ throw new BadRequestException({ message: `Operator "contains" is only for string-like fields`, code: "FILTER_OP_INVALID" });
56
+ }
57
+ return { [fieldName]: { contains: str, ...(/^(postgres|postgresql):/.test(process.env.DATABASE_URL ?? "postgresql:") ? { mode: "insensitive" } : {}) } };
58
+ }
59
+ default:
60
+ throw new BadRequestException({ message: `Unknown filter operator "${op}"`, code: "FILTER_OP_UNKNOWN" });
61
+ }
62
+ }
63
+
64
+ export function isStringFilterField(field: ResourceField): boolean {
65
+ return ["text", "textarea", "email", "url", "slug", "markdown", "code", "richtext", "badge", "select"].includes(field.type);
66
+ }
67
+
68
+ export function coerceFilterScalar(field: ResourceField, value: string): string | number | boolean {
69
+ if (field.type === "number" || field.type === "money") {
70
+ const n = Number(value);
71
+ if (!Number.isFinite(n) || !value.trim()) {
72
+ throw new BadRequestException({ message: `Invalid number for filter`, code: "FILTER_VALUE_INVALID" });
73
+ }
74
+ return n;
75
+ }
76
+ if (field.type === "boolean") { if (!["true","false","1","0"].includes(value)) throw new BadRequestException("Invalid boolean"); return value === "true" || value === "1"; }
77
+ return value;
78
+ }
79
+
80
+ export function coerceFilterComparable(field: ResourceField, value: string): Date | number | string | boolean {
81
+ if (field.type === "datetime" || field.type === "date") {
82
+ const d = new Date(value);
83
+ if (Number.isNaN(d.getTime())) {
84
+ throw new BadRequestException({ message: `Invalid date for filter`, code: "FILTER_VALUE_INVALID" });
85
+ }
86
+ return d;
87
+ }
88
+ return coerceFilterScalar(field, value);
89
+ }
90
+
91
+ export function buildOrderBy(resource: ResourceConfig, sort: string, user: UserContext) {
92
+ const [field, dirRaw] = sort.split(":");
93
+ const direction = dirRaw === "asc" ? "asc" : "desc";
94
+ const candidate = field ? resource.fields[field] : undefined;
95
+ if (field && candidate?.sortable && canReadField(resource, field, user)) {
96
+ return { [field]: direction };
97
+ }
98
+ if (resource.fields.createdAt?.sortable && canReadField(resource, "createdAt", user)) {
99
+ return { createdAt: direction };
100
+ }
101
+ return undefined;
102
+ }
103
+
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "declaration": true,
6
+ "experimentalDecorators": true,
7
+ "emitDecoratorMetadata": true
8
+ },
9
+ "include": [
10
+ "src/**/*.ts"
11
+ ]
12
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openadminjs/notifications",
3
- "version": "0.1.0",
3
+ "version": "0.2.0-rc.1",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openadminjs/payments",
3
- "version": "0.1.0",
3
+ "version": "0.2.0-rc.1",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openadminjs/permissions",
3
- "version": "0.1.0",
3
+ "version": "0.2.0-rc.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,13 +1,13 @@
1
1
  export type Permission = `${string}.${string}`;
2
2
 
3
- export type { LocalizedRoleLabel, RoleBlueprint } from "./blueprints";
3
+ export type { LocalizedRoleLabel, RoleBlueprint } from "./blueprints.js";
4
4
  export {
5
5
  DEFAULT_AUTH_REALM,
6
6
  expandRolePermissions,
7
7
  materializeAllRoles,
8
8
  realmOf,
9
9
  roleMatrixKey
10
- } from "./blueprints";
10
+ } from "./blueprints.js";
11
11
 
12
12
  export function can(permissions: readonly string[], permission: string): boolean {
13
13
  return permissions.includes(permission) || permissions.includes("*");
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openadminjs/plugin-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0-rc.1",
4
4
  "description": "Contracts for OpenAdminJS server plugins (hooks, manifest metadata).",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
- import type { PluginCapability, PluginSurfaceRegistry, ResourceLifecycleHooks } from "./hooks";
1
+ import type { PluginCapability, PluginSurfaceRegistry, ResourceLifecycleHooks } from "./hooks.js";
2
2
 
3
- export type * from "./hooks";
3
+ export type * from "./hooks.js";
4
4
 
5
5
  export type PluginRegistrationContext<Config extends Record<string, unknown> = Record<string, unknown>> = {
6
6
  readonly pluginId: string;
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@openadminjs/prisma",
3
+ "version": "0.2.0-rc.1",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "main": "./src/index.mjs",
7
+ "types": "./src/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./src/index.d.ts",
11
+ "import": "./src/index.mjs",
12
+ "default": "./src/index.mjs"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "node --check src/index.mjs",
17
+ "lint": "node --check src/index.mjs",
18
+ "typecheck": "node --check src/index.mjs",
19
+ "test": "node --test test/*.test.mjs"
20
+ }
21
+ }
@@ -0,0 +1,36 @@
1
+ model AiConversation {
2
+ id String @id @default(cuid())
3
+ userId String
4
+ title String?
5
+ createdAt DateTime @default(now())
6
+ updatedAt DateTime @updatedAt
7
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
8
+ messages AiMessage[]
9
+ }
10
+
11
+ model AiMessage {
12
+ id String @id @default(cuid())
13
+ conversationId String
14
+ role String
15
+ content String
16
+ meta Json?
17
+ createdAt DateTime @default(now())
18
+ conversation AiConversation @relation(fields: [conversationId], references: [id], onDelete: Cascade)
19
+
20
+ @@index([conversationId, createdAt])
21
+ }
22
+
23
+ model AiArtifact {
24
+ id String @id @default(cuid())
25
+ userId String
26
+ conversationId String?
27
+ filename String
28
+ mimeType String
29
+ size Int
30
+ contentBase64 String
31
+ meta Json?
32
+ createdAt DateTime @default(now())
33
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
34
+
35
+ @@index([userId, createdAt])
36
+ }
@@ -0,0 +1,13 @@
1
+ model AuditLog {
2
+ id String @id @default(cuid())
3
+ userId String?
4
+ resource String?
5
+ resourceId String?
6
+ action String
7
+ before Json?
8
+ after Json?
9
+ ipAddress String?
10
+ userAgent String?
11
+ createdAt DateTime @default(now())
12
+ user User? @relation(fields: [userId], references: [id])
13
+ }
@@ -0,0 +1,79 @@
1
+ model Product {
2
+ id String @id @default(cuid())
3
+ name String
4
+ slug String @unique
5
+ description String?
6
+ /** Price in smallest currency unit (e.g. cents for USD) */
7
+ price Int
8
+ currency String @default("USD")
9
+ active Boolean @default(true)
10
+ imageUrl String?
11
+ metadata Json?
12
+ createdAt DateTime @default(now())
13
+ updatedAt DateTime @updatedAt
14
+ orderItems OrderItem[]
15
+ }
16
+
17
+ model Order {
18
+ id String @id @default(cuid())
19
+ /** Null for guest checkouts */
20
+ userId String?
21
+ email String?
22
+ /** pending | paid | failed | refunded | cancelled */
23
+ status String @default("pending")
24
+ currency String @default("USD")
25
+ /** Total in smallest currency unit */
26
+ total Int
27
+ notes String?
28
+ checkoutKey String? @unique
29
+ checkoutRequestHash String?
30
+ checkoutSessionId String? @unique
31
+ paymentIntentId String? @unique
32
+ metadata Json?
33
+ createdAt DateTime @default(now())
34
+ updatedAt DateTime @updatedAt
35
+ user User? @relation(fields: [userId], references: [id])
36
+ items OrderItem[]
37
+ transactions Transaction[]
38
+ }
39
+
40
+ model OrderItem {
41
+ id String @id @default(cuid())
42
+ orderId String
43
+ productId String?
44
+ name String
45
+ /** Unit price at time of purchase */
46
+ price Int
47
+ quantity Int @default(1)
48
+ order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
49
+ product Product? @relation(fields: [productId], references: [id], onDelete: SetNull)
50
+ }
51
+
52
+ model Transaction {
53
+ id String @id @default(cuid())
54
+ orderId String
55
+ /** Payment provider slug: stripe | paypal | mock */
56
+ provider String
57
+ /** Provider-side ID (Stripe PaymentIntent ID, etc.) */
58
+ providerTxId String?
59
+ /** pending | succeeded | failed | refunded */
60
+ status String @default("pending")
61
+ /** Amount in smallest currency unit */
62
+ amount Int
63
+ currency String @default("USD")
64
+ metadata Json?
65
+ createdAt DateTime @default(now())
66
+ order Order @relation(fields: [orderId], references: [id])
67
+ }
68
+
69
+ model WebhookLog {
70
+ id String @id @default(cuid())
71
+ provider String
72
+ eventType String
73
+ providerEventId String? @unique
74
+ payload Json
75
+ /** pending | processed | failed */
76
+ status String @default("pending")
77
+ error String?
78
+ createdAt DateTime @default(now())
79
+ }
@@ -0,0 +1,27 @@
1
+ model Category {
2
+ id String @id @default(cuid())
3
+ name String
4
+ slug String @unique
5
+ order Int @default(0)
6
+ createdAt DateTime @default(now())
7
+ updatedAt DateTime @updatedAt
8
+ posts Post[]
9
+
10
+ @@index([order])
11
+ }
12
+
13
+ model Post {
14
+ id String @id @default(cuid())
15
+ title String
16
+ slug String @unique
17
+ status String @default("draft")
18
+ content String?
19
+ categoryId String?
20
+ coverImageId String?
21
+ authorId String?
22
+ createdAt DateTime @default(now())
23
+ updatedAt DateTime @updatedAt
24
+ category Category? @relation(fields: [categoryId], references: [id])
25
+ coverImage FileAsset? @relation(fields: [coverImageId], references: [id])
26
+ author User? @relation(fields: [authorId], references: [id])
27
+ }
@@ -0,0 +1,106 @@
1
+ model User {
2
+ id String @id @default(cuid())
3
+ email String @unique
4
+ passwordHash String
5
+ /** Stable IdP subject, format `issuerNormalized::sub` — set when user signs in via OIDC. */
6
+ oidcKey String? @unique
7
+ /// Legacy refresh hash; invalidated by session migration.
8
+ refreshTokenHash String?
9
+ sessions Session[]
10
+ name String?
11
+ avatarUrl String?
12
+ status String @default("active")
13
+ createdAt DateTime @default(now())
14
+ updatedAt DateTime @updatedAt
15
+ roles UserRole[]
16
+ posts Post[]
17
+ auditLogs AuditLog[]
18
+ apiTokens ApiToken[]
19
+ notifications Notification[]
20
+ orders Order[]
21
+ passwordResetTokens PasswordResetToken[]
22
+ emailVerificationTokens EmailVerificationToken[]
23
+ aiConversations AiConversation[]
24
+ aiArtifacts AiArtifact[]
25
+ }
26
+
27
+ model Role {
28
+ id String @id @default(cuid())
29
+ /** RBAC partition: e.g. "admin" (back-office), "public" (storefront). Add more realms freely. */
30
+ realm String @default("admin")
31
+ name String
32
+ label String
33
+ users UserRole[]
34
+ permissions RolePermission[]
35
+
36
+ @@unique([name, realm])
37
+ }
38
+
39
+ model Permission {
40
+ id String @id @default(cuid())
41
+ name String @unique
42
+ label String
43
+ roles RolePermission[]
44
+ }
45
+
46
+ model UserRole {
47
+ userId String
48
+ roleId String
49
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
50
+ role Role @relation(fields: [roleId], references: [id], onDelete: Cascade)
51
+
52
+ @@id([userId, roleId])
53
+ }
54
+
55
+ model RolePermission {
56
+ roleId String
57
+ permissionId String
58
+ role Role @relation(fields: [roleId], references: [id], onDelete: Cascade)
59
+ permission Permission @relation(fields: [permissionId], references: [id], onDelete: Cascade)
60
+
61
+ @@id([roleId, permissionId])
62
+ }
63
+
64
+ model PasswordResetToken {
65
+ id String @id @default(cuid())
66
+ tokenHash String
67
+ expiresAt DateTime
68
+ usedAt DateTime?
69
+ userId String
70
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
71
+ }
72
+
73
+ model EmailVerificationToken {
74
+ id String @id @default(cuid())
75
+ tokenHash String
76
+ expiresAt DateTime
77
+ usedAt DateTime?
78
+ userId String
79
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
80
+ }
81
+
82
+ model Session {
83
+ id String @id @default(cuid())
84
+ userId String
85
+ realm String
86
+ expiresAt DateTime
87
+ revokedAt DateTime?
88
+ createdAt DateTime @default(now())
89
+ lastUsedAt DateTime @default(now())
90
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
91
+ tokens SessionToken[]
92
+
93
+ @@index([userId, realm])
94
+ @@index([expiresAt])
95
+ }
96
+
97
+ model SessionToken {
98
+ id String @id @default(cuid())
99
+ sessionId String
100
+ tokenHash String @unique
101
+ usedAt DateTime?
102
+ createdAt DateTime @default(now())
103
+ session Session @relation(fields: [sessionId], references: [id], onDelete: Cascade)
104
+
105
+ @@index([sessionId])
106
+ }
@@ -0,0 +1,8 @@
1
+ generator client {
2
+ provider = "prisma-client-js"
3
+ }
4
+
5
+ datasource db {
6
+ provider = "postgresql"
7
+ url = env("DATABASE_URL")
8
+ }
@@ -0,0 +1,9 @@
1
+ model JobLog {
2
+ id String @id @default(cuid())
3
+ name String
4
+ status String
5
+ payload Json?
6
+ error String?
7
+ createdAt DateTime @default(now())
8
+ updatedAt DateTime @updatedAt
9
+ }
@@ -0,0 +1,9 @@
1
+ model FileAsset {
2
+ id String @id @default(cuid())
3
+ filename String
4
+ path String
5
+ mimeType String
6
+ size Int
7
+ createdAt DateTime @default(now())
8
+ posts Post[]
9
+ }