openadminjs 0.1.24 → 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.
- package/README.md +117 -81
- package/dist/adapt-package-manager.d.ts +3 -0
- package/dist/adapt-package-manager.js +118 -0
- package/dist/create-project.d.ts +77 -2
- package/dist/create-project.js +685 -224
- package/dist/db-commands.d.ts +20 -0
- package/dist/db-commands.js +75 -0
- package/dist/detect-package-manager.d.ts +8 -0
- package/dist/detect-package-manager.js +37 -0
- package/dist/doctor.d.ts +26 -0
- package/dist/doctor.js +232 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +476 -166
- package/dist/render-schema.d.ts +3 -0
- package/dist/render-schema.js +33 -0
- package/dist/resource-slug.d.ts +1 -0
- package/dist/resource-slug.js +7 -0
- package/dist/runtime-mode.d.ts +16 -0
- package/dist/runtime-mode.js +138 -0
- package/dist/secrets.d.ts +24 -0
- package/dist/secrets.js +93 -0
- package/dist/security.d.ts +13 -0
- package/dist/security.js +168 -0
- package/dist/upgrade.d.ts +10 -0
- package/dist/upgrade.js +133 -0
- package/dist/validate-name.d.ts +33 -0
- package/dist/validate-name.js +206 -0
- package/package.json +39 -11
- package/template/.dockerignore +15 -0
- package/template/.env.production.example +5 -0
- package/template/Dockerfile +12 -0
- package/template/README.md +23 -3
- package/template/apps/admin/app/api/auth/login/route.ts +9 -9
- package/template/apps/admin/app/api/auth/logout/route.ts +11 -3
- package/template/apps/admin/app/api/auth/oidc/callback/route.ts +19 -0
- package/template/apps/admin/app/api/auth/oidc/start/route.ts +11 -0
- package/template/apps/admin/app/api/auth/oidc/status/route.ts +6 -0
- package/template/apps/admin/app/api/auth/refresh/route.ts +18 -11
- package/template/apps/admin/app/api/backend/[...path]/route.ts +48 -0
- package/template/apps/admin/app/api-tokens/page.tsx +39 -39
- package/template/apps/admin/app/assistant/page.tsx +11 -0
- package/template/apps/admin/app/dashboard/page.tsx +45 -462
- package/template/apps/admin/app/globals.css +52 -16
- package/template/apps/admin/app/layout.tsx +1 -1
- package/template/apps/admin/app/login/page.tsx +13 -145
- package/template/apps/admin/app/plugins/page.tsx +16 -402
- package/template/apps/admin/app/profile/page.tsx +5 -2
- package/template/apps/admin/app/settings/page.tsx +14 -265
- package/template/apps/admin/components/ai-assistant-widget.tsx +3 -6
- package/template/apps/admin/components/app-shell.tsx +25 -373
- package/template/apps/admin/components/auth-guard.tsx +8 -28
- package/template/apps/admin/components/logo.tsx +1 -30
- package/template/apps/admin/components/resource-form.tsx +3 -3
- package/template/apps/admin/components/resource-table.tsx +12 -8
- package/template/apps/admin/lib/api.ts +45 -107
- package/template/apps/admin/lib/resource-table-prefs.ts +1 -57
- package/template/apps/admin/lib/server-api.ts +7 -0
- package/template/apps/admin/lib/tokens.ts +9 -81
- package/template/apps/admin/middleware.ts +9 -50
- package/template/apps/admin/next.config.mjs +4 -0
- package/template/apps/admin/package.json +2 -1
- package/template/apps/admin/public/brand/favicon.svg +4 -1
- package/template/apps/admin/tailwind.config.ts +9 -8
- package/template/apps/api/package.json +13 -6
- package/template/apps/api/src/access/catalog.ts +4 -0
- package/template/apps/api/src/admin/admin-ai.controller.ts +15 -125
- package/template/apps/api/src/admin/admin-analytics.service.ts +16 -148
- package/template/apps/api/src/admin/admin-logs.controller.ts +4 -1
- package/template/apps/api/src/admin/admin-plugins.controller.ts +8 -8
- package/template/apps/api/src/admin/admin-plugins.service.ts +15 -259
- package/template/apps/api/src/admin/admin-resource.service.ts +105 -254
- package/template/apps/api/src/admin/admin.controller.ts +17 -4
- package/template/apps/api/src/admin/admin.module.ts +2 -2
- package/template/apps/api/src/admin/resource-policy.ts +1 -0
- package/template/apps/api/src/admin/resource-query.ts +1 -0
- package/template/apps/api/src/admin/safe-ai.service.ts +43 -0
- package/template/apps/api/src/admin/validate-resource-payload.ts +2 -0
- package/template/apps/api/src/auth/auth.controller.ts +4 -2
- package/template/apps/api/src/auth/auth.service.ts +68 -83
- package/template/apps/api/src/auth/sso-oidc.controller.ts +12 -74
- package/template/apps/api/src/auth/sso-oidc.service.ts +51 -268
- package/template/apps/api/src/common/api-exception.filter.ts +1 -0
- package/template/apps/api/src/common/auth.guard.ts +66 -39
- package/template/apps/api/src/common/json-field-codec.ts +138 -0
- package/template/apps/api/src/common/prisma.service.ts +12 -7
- package/template/apps/api/src/common/request-logging.interceptor.ts +8 -3
- package/template/apps/api/src/graphql/graphql.module.ts +14 -1
- package/template/apps/api/src/health/health.controller.ts +6 -0
- package/template/apps/api/src/main.ts +11 -2
- package/template/apps/api/src/plugins/plugin-loader.ts +5 -3
- package/template/apps/api/src/resources/commerce.resource.ts +3 -34
- package/template/apps/api/src/resources/operations.resource.ts +1 -0
- package/template/apps/api/src/store/payment/payment.controller.ts +15 -92
- package/template/apps/api/src/store/payment/payment.module.ts +2 -3
- package/template/apps/api/src/store/payment/payment.service.ts +121 -227
- package/template/apps/api/webpack.config.cjs +2 -1
- package/template/apps/web/next.config.mjs +4 -0
- package/template/apps/web/public/brand/favicon.svg +4 -1
- package/template/compose.yaml +56 -0
- package/template/examples/crm-admin/README.md +31 -0
- package/template/examples/crm-admin/package.json +17 -0
- package/template/examples/crm-admin/prisma/models.fragment.prisma +50 -0
- package/template/examples/crm-admin/src/index.ts +7 -0
- package/template/examples/crm-admin/src/resources/activities.resource.ts +29 -0
- package/template/examples/crm-admin/src/resources/companies.resource.ts +21 -0
- package/template/examples/crm-admin/src/resources/contacts.resource.ts +24 -0
- package/template/examples/crm-admin/src/resources/deals.resource.ts +30 -0
- package/template/examples/crm-admin/tsconfig.json +7 -0
- package/template/package.json +8 -1
- package/template/packages/admin-client/package.json +18 -0
- package/template/packages/admin-client/src/contracts.ts +29 -0
- package/template/packages/admin-client/src/index.ts +2 -0
- package/template/packages/admin-client/src/preferences.ts +57 -0
- package/template/packages/admin-client/tsconfig.json +12 -0
- package/template/packages/auth/package.json +1 -1
- package/template/packages/brand/site/assets/brand/favicon.svg +4 -1
- package/template/packages/brand/src/generate-assets.mjs +17 -186
- package/template/packages/core/package.json +1 -1
- package/template/packages/mail/package.json +1 -1
- package/template/packages/nest/package.json +22 -0
- package/template/packages/nest/src/api-exception.filter.ts +23 -0
- package/template/packages/nest/src/index.ts +3 -0
- package/template/packages/nest/src/resource-policy.ts +64 -0
- package/template/packages/nest/src/resource-query.ts +103 -0
- package/template/packages/nest/tsconfig.json +12 -0
- package/template/packages/notifications/package.json +1 -1
- package/template/packages/payments/package.json +1 -1
- package/template/packages/permissions/package.json +1 -1
- package/template/packages/permissions/src/index.ts +2 -2
- package/template/packages/plugin-sdk/package.json +1 -1
- package/template/packages/plugin-sdk/src/index.ts +2 -2
- package/template/packages/prisma/package.json +21 -0
- package/template/packages/prisma/schema/ai.prisma +36 -0
- package/template/packages/prisma/schema/audit.prisma +13 -0
- package/template/packages/prisma/schema/commerce.prisma +79 -0
- package/template/packages/prisma/schema/content.prisma +27 -0
- package/template/packages/prisma/schema/core.prisma +106 -0
- package/template/packages/prisma/schema/header.prisma +8 -0
- package/template/packages/prisma/schema/jobs.prisma +9 -0
- package/template/packages/prisma/schema/media.prisma +9 -0
- package/template/packages/prisma/schema/modules.json +47 -0
- package/template/packages/prisma/schema/notifications.prisma +9 -0
- package/template/packages/prisma/schema/settings.prisma +8 -0
- package/template/packages/prisma/schema/tokens.prisma +10 -0
- package/template/packages/prisma/src/index.d.ts +12 -0
- package/template/packages/prisma/src/index.mjs +138 -0
- package/template/packages/queue/package.json +1 -1
- package/template/packages/resource/package.json +1 -1
- package/template/packages/resource/src/index.ts +1 -0
- package/template/packages/storage/package.json +1 -1
- package/template/packages/storage/src/index.ts +37 -0
- package/template/prisma/migrations/20260713120000_add_user_oidc_key_and_category_order/migration.sql +11 -0
- package/template/prisma/migrations/20261126130000_add_sessions/migration.sql +26 -0
- package/template/prisma/migrations/20261126140000_api_token_hash/migration.sql +3 -0
- package/template/prisma/migrations/20261126150000_payment_idempotency/migration.sql +6 -0
- package/template/prisma/schema.prisma +82 -54
- package/template/prisma/seed.ts +14 -38
- package/template/runtime-versions.json +15 -0
- package/template/scripts/db-init.mjs +33 -0
- package/template/scripts/install-crm.mjs +50 -0
- package/template/scripts/migrate-existing.mjs +65 -0
- package/template/scripts/schema.mjs +48 -0
- package/template/tsconfig.base.json +23 -5
- package/LICENSE +0 -21
- package/dist/create-project.test.d.ts +0 -1
- package/dist/create-project.test.js +0 -99
- package/dist/index.test.d.ts +0 -1
- package/dist/index.test.js +0 -7
- package/dist/resource-slug.test.d.ts +0 -1
- package/dist/resource-slug.test.js +0 -9
- package/template/apps/admin/.storybook/main.ts +0 -12
- package/template/apps/admin/.storybook/preview.ts +0 -10
- package/template/apps/admin/app/login/page.test.tsx +0 -18
- package/template/apps/admin/components/auth-guard.test.tsx +0 -55
- package/template/apps/admin/components/logo.stories.tsx +0 -24
- package/template/apps/admin/lib/api.test.ts +0 -118
- package/template/apps/admin/lib/auth-flow.e2e.test.ts +0 -79
- package/template/apps/admin/vitest.config.ts +0 -7
- package/template/apps/api/src/access/derive-permissions.test.ts +0 -26
- package/template/apps/api/src/admin/admin-resource.service.test.ts +0 -118
- package/template/apps/api/src/admin/validate-resource-payload.test.ts +0 -44
- package/template/apps/api/src/app.module.test.ts +0 -12
- package/template/apps/api/src/auth/auth.service.test.ts +0 -78
- package/template/apps/api/src/auth/sso-oidc.service.test.ts +0 -84
- package/template/apps/api/src/common/auth.guard.test.ts +0 -62
- package/template/apps/api/src/common/casl-ability.factory.test.ts +0 -33
- package/template/apps/api/src/common/request-logging.interceptor.test.ts +0 -39
- package/template/apps/api/src/graphql/admin-resources.resolver.test.ts +0 -45
- package/template/apps/api/src/graphql/ensure-gql-paramtypes.test.ts +0 -44
- package/template/apps/api/src/graphql/graphql-schema.test.ts +0 -26
- package/template/apps/api/src/plugins/manifest.schema.test.ts +0 -36
- package/template/apps/api/src/plugins/plugin-runtime.test.ts +0 -24
- package/template/apps/api/src/queue/queue.service.test.ts +0 -33
- package/template/apps/api/src/resources/resource-hooks.registry.test.ts +0 -72
- package/template/apps/api/vitest.config.ts +0 -21
- package/template/apps/web/lib/seo.test.ts +0 -41
- package/template/apps/web/vitest.config.ts +0 -19
- package/template/packages/auth/src/index.test.ts +0 -10
- package/template/packages/brand/src/index.test.ts +0 -9
- package/template/packages/core/src/index.test.ts +0 -27
- package/template/packages/core/vitest.config.ts +0 -9
- package/template/packages/mail/src/index.test.ts +0 -23
- package/template/packages/notifications/src/index.test.ts +0 -9
- package/template/packages/permissions/src/blueprints.test.ts +0 -62
- package/template/packages/permissions/src/index.test.ts +0 -34
- package/template/packages/plugin-sdk/src/sdk.test.ts +0 -13
- package/template/packages/plugin-sdk/vitest.config.ts +0 -5
- package/template/packages/queue/src/index.test.ts +0 -12
- package/template/packages/resource/src/index.test.ts +0 -196
- package/template/packages/storage/src/index.test.ts +0 -10
|
@@ -1,235 +1,129 @@
|
|
|
1
|
-
import { BadRequestException, Inject, Injectable, NotFoundException } from "@nestjs/common";
|
|
1
|
+
import { BadRequestException, ConflictException, ForbiddenException, Inject, Injectable, NotFoundException, ServiceUnavailableException } from "@nestjs/common";
|
|
2
|
+
import { Prisma } from "@prisma/client";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import Stripe from "stripe";
|
|
2
5
|
import { PrismaService } from "../../common/prisma.service";
|
|
3
|
-
import { PaymentProviderService } from "./payment.provider";
|
|
4
|
-
|
|
5
|
-
export type CreateOrderInput = {
|
|
6
|
-
items: Array<{
|
|
7
|
-
productId?: string;
|
|
8
|
-
name: string;
|
|
9
|
-
price: number;
|
|
10
|
-
quantity: number;
|
|
11
|
-
}>;
|
|
12
|
-
currency?: string;
|
|
13
|
-
email?: string;
|
|
14
|
-
userId?: string;
|
|
15
|
-
notes?: string;
|
|
16
|
-
successUrl: string;
|
|
17
|
-
cancelUrl: string;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export type OrderStatusResponse = {
|
|
21
|
-
id: string;
|
|
22
|
-
status: string;
|
|
23
|
-
total: number;
|
|
24
|
-
currency: string;
|
|
25
|
-
items: Array<{ name: string; price: number; quantity: number }>;
|
|
26
|
-
createdAt: Date;
|
|
27
|
-
};
|
|
28
6
|
|
|
7
|
+
const hash=(x:string)=>createHash("sha256").update(x).digest("hex");
|
|
8
|
+
type Buyer={id:string;email?:string};
|
|
9
|
+
type Line={productId:string;quantity:number};
|
|
10
|
+
|
|
11
|
+
export function parseCheckout(body:unknown):{items:Line[];key:string}{
|
|
12
|
+
if(!body||typeof body!=="object"||Array.isArray(body))throw new BadRequestException("Invalid checkout");
|
|
13
|
+
const data=body as Record<string,unknown>;
|
|
14
|
+
if(Object.keys(data).some(k=>!["items","idempotencyKey"].includes(k))||typeof data.idempotencyKey!=="string"||!/^[a-zA-Z0-9_-]{16,80}$/.test(data.idempotencyKey)||!Array.isArray(data.items)||!data.items.length||data.items.length>50)throw new BadRequestException("Invalid checkout items or idempotency key");
|
|
15
|
+
const seen=new Set<string>();const items:Line[]=[];
|
|
16
|
+
for(const item of data.items){
|
|
17
|
+
if(!item||typeof item!=="object"||Object.keys(item).some(k=>!["productId","quantity"].includes(k))||typeof item.productId!=="string"||!item.productId||item.productId.length>128||seen.has(item.productId)||!Number.isSafeInteger(item.quantity)||item.quantity<1||item.quantity>100)throw new BadRequestException("Invalid product or quantity");
|
|
18
|
+
seen.add(item.productId);items.push({productId:item.productId,quantity:item.quantity});
|
|
19
|
+
}
|
|
20
|
+
return {items:items.sort((a,b)=>a.productId.localeCompare(b.productId)),key:data.idempotencyKey};
|
|
21
|
+
}
|
|
29
22
|
@Injectable()
|
|
30
23
|
export class PaymentService {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
name: item.name,
|
|
61
|
-
price: item.price,
|
|
62
|
-
quantity: item.quantity
|
|
63
|
-
}))
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
return created;
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
const provider = this.paymentProvider.get();
|
|
70
|
-
const checkout = await provider.createCheckout({
|
|
71
|
-
orderId: order.id,
|
|
72
|
-
lineItems: items.map((item) => ({
|
|
73
|
-
name: item.name,
|
|
74
|
-
unitAmount: item.price,
|
|
75
|
-
quantity: item.quantity
|
|
76
|
-
})),
|
|
77
|
-
currency,
|
|
78
|
-
successUrl,
|
|
79
|
-
cancelUrl,
|
|
80
|
-
customerEmail: email
|
|
24
|
+
constructor(@Inject(PrismaService) private readonly prisma:PrismaService){}
|
|
25
|
+
private stripe(){
|
|
26
|
+
// Test-mode only until provider reconciliation has passed end-to-end acceptance.
|
|
27
|
+
const key=process.env.STRIPE_SECRET_KEY;
|
|
28
|
+
if(process.env.OPENADMIN_COMMERCE_ENABLED!=="1"||!key?.startsWith("sk_test_")||!process.env.STRIPE_WEBHOOK_SECRET)throw new ForbiddenException("Commerce test profile is disabled");
|
|
29
|
+
return new Stripe(key,{apiVersion:"2025-02-24.acacia",timeout:15000,maxNetworkRetries:1});
|
|
30
|
+
}
|
|
31
|
+
private redirectUrl(name:string){
|
|
32
|
+
let url:URL;
|
|
33
|
+
try{url=new URL(process.env[name]??"");}catch{throw new ServiceUnavailableException("Checkout redirect is not configured");}
|
|
34
|
+
if(url.protocol!=="https:"||url.username||url.password)throw new ServiceUnavailableException("Checkout redirect must use HTTPS");
|
|
35
|
+
return url.toString();
|
|
36
|
+
}
|
|
37
|
+
async createCheckout(body:unknown,buyer:Buyer){
|
|
38
|
+
const stripe=this.stripe(),success_url=this.redirectUrl("CHECKOUT_SUCCESS_URL"),cancel_url=this.redirectUrl("CHECKOUT_CANCEL_URL");
|
|
39
|
+
const {items,key}=parseCheckout(body);
|
|
40
|
+
const checkoutKey=hash(buyer.id+":"+key),requestHash=hash(JSON.stringify(items));
|
|
41
|
+
let order=await this.prisma.order.findUnique({where:{checkoutKey},include:{items:true}});
|
|
42
|
+
if(!order){
|
|
43
|
+
try{
|
|
44
|
+
order=await this.prisma.$transaction(async tx=>{
|
|
45
|
+
const products=await tx.product.findMany({where:{id:{in:items.map(i=>i.productId)},active:true}});
|
|
46
|
+
if(products.length!==items.length)throw new BadRequestException("Product unavailable");
|
|
47
|
+
const currency=products[0]!.currency.toUpperCase();
|
|
48
|
+
if(!/^[A-Z]{3}$/.test(currency)||products.some(p=>p.currency.toUpperCase()!==currency||!Number.isSafeInteger(p.price)||p.price<=0))throw new BadRequestException("Incompatible price or currency");
|
|
49
|
+
const lines=items.map(i=>{const p=products.find(p=>p.id===i.productId)!;return {productId:p.id,name:p.name,price:p.price,quantity:i.quantity};});
|
|
50
|
+
const total=lines.reduce((s,x)=>s+x.price*x.quantity,0);
|
|
51
|
+
if(!Number.isSafeInteger(total)||total>2147483647)throw new BadRequestException("Order total too large");
|
|
52
|
+
return tx.order.create({data:{userId:buyer.id,email:buyer.email,currency,total,checkoutKey,checkoutRequestHash:requestHash,items:{create:lines}},include:{items:true}});
|
|
81
53
|
});
|
|
82
|
-
|
|
83
|
-
// Log the initial transaction attempt
|
|
84
|
-
await this.prisma.transaction.create({
|
|
85
|
-
data: {
|
|
86
|
-
orderId: order.id,
|
|
87
|
-
provider: this.paymentProvider.name,
|
|
88
|
-
providerTxId: checkout.providerSessionId,
|
|
89
|
-
status: "pending",
|
|
90
|
-
amount: total,
|
|
91
|
-
currency,
|
|
92
|
-
metadata: { sessionId: checkout.providerSessionId }
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
return { orderId: order.id, checkoutUrl: checkout.checkoutUrl };
|
|
54
|
+
}catch(e){if(!(e instanceof Prisma.PrismaClientKnownRequestError)||e.code!=="P2002")throw e;order=await this.prisma.order.findUnique({where:{checkoutKey},include:{items:true}});}
|
|
97
55
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
const event = await this.paymentProvider.get().verifyWebhook(rawBody, signature);
|
|
107
|
-
|
|
108
|
-
await this.prisma.webhookLog.update({
|
|
109
|
-
where: { id: logEntry.id },
|
|
110
|
-
data: { eventType: event.type, payload: event.raw as object, status: "processed" }
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
if (event.orderId) {
|
|
114
|
-
await this.applyWebhookEvent(event.orderId, event.type, event.providerEventId, event.amount, event.currency);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return { received: true, type: event.type };
|
|
118
|
-
} catch (error) {
|
|
119
|
-
await this.prisma.webhookLog.update({
|
|
120
|
-
where: { id: logEntry.id },
|
|
121
|
-
data: { status: "failed", error: error instanceof Error ? error.message : "unknown" }
|
|
122
|
-
});
|
|
123
|
-
throw error;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
private async applyWebhookEvent(
|
|
128
|
-
orderId: string,
|
|
129
|
-
type: string,
|
|
130
|
-
providerEventId: string,
|
|
131
|
-
amount?: number,
|
|
132
|
-
currency?: string
|
|
133
|
-
) {
|
|
134
|
-
const statusMap: Record<string, string> = {
|
|
135
|
-
"payment.succeeded": "paid",
|
|
136
|
-
"payment.failed": "failed",
|
|
137
|
-
"payment.refunded": "refunded",
|
|
138
|
-
"checkout.expired": "cancelled"
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const newStatus = statusMap[type];
|
|
142
|
-
if (!newStatus) return;
|
|
143
|
-
|
|
144
|
-
await this.prisma.$transaction(async (tx) => {
|
|
145
|
-
await tx.order.update({ where: { id: orderId }, data: { status: newStatus } });
|
|
146
|
-
await tx.transaction.updateMany({
|
|
147
|
-
where: { orderId, providerTxId: providerEventId },
|
|
148
|
-
data: {
|
|
149
|
-
status: newStatus === "paid" ? "succeeded" : newStatus === "refunded" ? "refunded" : "failed",
|
|
150
|
-
...(amount ? { amount } : {}),
|
|
151
|
-
...(currency ? { currency } : {})
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/** Get order status (public — by orderId only, no auth needed). */
|
|
158
|
-
async getOrderStatus(orderId: string): Promise<OrderStatusResponse> {
|
|
159
|
-
const order = await this.prisma.order.findUnique({
|
|
160
|
-
where: { id: orderId },
|
|
161
|
-
include: { items: true }
|
|
162
|
-
});
|
|
163
|
-
if (!order) throw new NotFoundException({ message: "Order not found", code: "ORDER_NOT_FOUND" });
|
|
164
|
-
|
|
165
|
-
return {
|
|
166
|
-
id: order.id,
|
|
167
|
-
status: order.status,
|
|
168
|
-
total: order.total,
|
|
169
|
-
currency: order.currency,
|
|
170
|
-
items: order.items.map((item) => ({ name: item.name, price: item.price, quantity: item.quantity })),
|
|
171
|
-
createdAt: order.createdAt
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/** List orders for the authenticated user. */
|
|
176
|
-
async getUserOrders(userId: string, page = 1, limit = 20) {
|
|
177
|
-
const [data, total] = await Promise.all([
|
|
178
|
-
this.prisma.order.findMany({
|
|
179
|
-
where: { userId },
|
|
180
|
-
include: { items: true },
|
|
181
|
-
orderBy: { createdAt: "desc" },
|
|
182
|
-
skip: (page - 1) * limit,
|
|
183
|
-
take: limit
|
|
184
|
-
}),
|
|
185
|
-
this.prisma.order.count({ where: { userId } })
|
|
186
|
-
]);
|
|
187
|
-
return { data, meta: { page, limit, total, pages: Math.ceil(total / limit) || 1 } };
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/** Refund an order (admin only). */
|
|
191
|
-
async refundOrder(orderId: string) {
|
|
192
|
-
const order = await this.prisma.order.findUnique({
|
|
193
|
-
where: { id: orderId },
|
|
194
|
-
include: { transactions: true }
|
|
195
|
-
});
|
|
196
|
-
if (!order) throw new NotFoundException({ message: "Order not found", code: "ORDER_NOT_FOUND" });
|
|
197
|
-
if (order.status !== "paid") {
|
|
198
|
-
throw new BadRequestException({ message: `Cannot refund order with status "${order.status}"`, code: "INVALID_ORDER_STATUS" });
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const successTx = order.transactions.find((tx) => tx.status === "succeeded");
|
|
202
|
-
if (!successTx?.providerTxId) {
|
|
203
|
-
throw new BadRequestException({ message: "No successful transaction found for this order", code: "NO_TRANSACTION" });
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const refund = await this.paymentProvider.get().refund({
|
|
207
|
-
providerTransactionId: successTx.providerTxId,
|
|
208
|
-
amount: order.total
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
await this.prisma.$transaction(async (tx) => {
|
|
212
|
-
await tx.order.update({ where: { id: orderId }, data: { status: "refunded" } });
|
|
213
|
-
await tx.transaction.create({
|
|
214
|
-
data: {
|
|
215
|
-
orderId,
|
|
216
|
-
provider: this.paymentProvider.name,
|
|
217
|
-
providerTxId: refund.providerRefundId,
|
|
218
|
-
status: "refunded",
|
|
219
|
-
amount: refund.amount,
|
|
220
|
-
currency: order.currency
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
return { ok: true, refundId: refund.providerRefundId };
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/** List products. */
|
|
229
|
-
async listProducts(onlyActive = true) {
|
|
230
|
-
return this.prisma.product.findMany({
|
|
231
|
-
where: onlyActive ? { active: true } : undefined,
|
|
232
|
-
orderBy: { createdAt: "desc" }
|
|
233
|
-
});
|
|
56
|
+
if(!order||order.checkoutRequestHash!==requestHash)throw new ConflictException("Idempotency key was used for another cart");
|
|
57
|
+
if(order.status!=="pending")throw new ConflictException("Order is not pending");
|
|
58
|
+
// Never create another provider session after one has been persisted.
|
|
59
|
+
if(order.checkoutSessionId){
|
|
60
|
+
const existing=await stripe.checkout.sessions.retrieve(order.checkoutSessionId);
|
|
61
|
+
if(existing.status!=="open"||!existing.url)throw new ConflictException("Checkout is no longer open");
|
|
62
|
+
return {orderId:order.id,checkoutUrl:existing.url};
|
|
234
63
|
}
|
|
64
|
+
// Stripe retains idempotency keys for at least 24h. Do not retry ambiguous old requests.
|
|
65
|
+
if(Date.now()-order.createdAt.getTime()>3600000)throw new ConflictException("Checkout requires reconciliation");
|
|
66
|
+
const session=await stripe.checkout.sessions.create({mode:"payment",payment_method_types:["card"],line_items:order.items.map(i=>({quantity:i.quantity,price_data:{currency:order!.currency.toLowerCase(),unit_amount:i.price,product_data:{name:i.name}}})),success_url,cancel_url,customer_email:order.email??undefined,metadata:{orderId:order.id},payment_intent_data:{metadata:{orderId:order.id}}},{idempotencyKey:"checkout-"+order.id});
|
|
67
|
+
if(!session.url)throw new ServiceUnavailableException("Payment session unavailable");
|
|
68
|
+
await this.prisma.order.updateMany({where:{id:order.id,status:"pending",checkoutSessionId:null},data:{checkoutSessionId:session.id}});
|
|
69
|
+
return {orderId:order.id,checkoutUrl:session.url};
|
|
70
|
+
}
|
|
71
|
+
async handleWebhook(provider:string,raw:Buffer,signature:string){
|
|
72
|
+
const stripe=this.stripe();if(provider!=="stripe"||!signature||!raw.length)throw new BadRequestException("Invalid webhook");
|
|
73
|
+
let event:Stripe.Event;try{event=stripe.webhooks.constructEvent(raw,signature,process.env.STRIPE_WEBHOOK_SECRET!);}catch{throw new BadRequestException("Invalid webhook signature");}
|
|
74
|
+
if(event.livemode)throw new BadRequestException("Live payments disabled");
|
|
75
|
+
try{await this.prisma.$transaction(async tx=>{
|
|
76
|
+
await tx.webhookLog.create({data:{provider:"stripe",providerEventId:event.id,eventType:event.type,payload:{id:event.id},status:"processed"}});
|
|
77
|
+
if(event.type==="checkout.session.completed"||event.type==="checkout.session.expired"){
|
|
78
|
+
const session=event.data.object;
|
|
79
|
+
const orderId=session.metadata?.orderId;if(!orderId)throw new BadRequestException("Missing order reference");
|
|
80
|
+
const order=await tx.order.findUnique({where:{id:orderId}});
|
|
81
|
+
if(!order||!order.checkoutSessionId)throw new ServiceUnavailableException("Checkout not reconciled yet");
|
|
82
|
+
if(order.checkoutSessionId!==session.id||session.amount_total!==order.total||session.currency?.toUpperCase()!==order.currency)throw new BadRequestException("Payment details mismatch");
|
|
83
|
+
if(event.type==="checkout.session.expired"){await tx.order.updateMany({where:{id:order.id,status:"pending"},data:{status:"cancelled"}});return;}
|
|
84
|
+
if(session.payment_status!=="paid"||typeof session.payment_intent!=="string")throw new BadRequestException("Payment not completed");
|
|
85
|
+
const changed=await tx.order.updateMany({where:{id:order.id,status:"pending"},data:{status:"paid",paymentIntentId:session.payment_intent}});
|
|
86
|
+
if(changed.count)await tx.transaction.create({data:{orderId:order.id,provider:"stripe",providerTxId:session.payment_intent,status:"succeeded",amount:order.total,currency:order.currency}});
|
|
87
|
+
}else if(event.type==="charge.refunded"){
|
|
88
|
+
const charge=event.data.object;if(typeof charge.payment_intent!=="string")return;
|
|
89
|
+
const order=await tx.order.findUnique({where:{paymentIntentId:charge.payment_intent}});
|
|
90
|
+
if(!order)return;
|
|
91
|
+
if(charge.amount_refunded!==order.total||charge.currency.toUpperCase()!==order.currency)return;
|
|
92
|
+
const updated=await tx.order.updateMany({where:{id:order.id,status:{in:["paid","refund_pending"]}},data:{status:"refunded"}});
|
|
93
|
+
if(updated.count)await tx.transaction.create({data:{orderId:order.id,provider:"stripe",providerTxId:charge.id,status:"refunded",amount:order.total,currency:order.currency}});
|
|
94
|
+
}
|
|
95
|
+
});}catch(e){if(e instanceof Prisma.PrismaClientKnownRequestError&&e.code==="P2002"&&await this.prisma.webhookLog.findUnique({where:{providerEventId:event.id}}))return {received:true,duplicate:true};throw e;}
|
|
96
|
+
return {received:true};
|
|
97
|
+
}
|
|
98
|
+
async getOrderStatus(id:string,userId:string){
|
|
99
|
+
const order=await this.prisma.order.findFirst({where:{id,userId},select:{id:true,status:true,total:true,currency:true,createdAt:true,items:{select:{name:true,price:true,quantity:true}}}});
|
|
100
|
+
if(!order)throw new NotFoundException("Order not found");return order;
|
|
101
|
+
}
|
|
102
|
+
async getUserOrders(userId:string,page=1,limit=20){
|
|
103
|
+
if(!Number.isSafeInteger(page)||page<1||page>100000||!Number.isSafeInteger(limit)||limit<1)throw new BadRequestException("Invalid pagination");limit=Math.min(limit,100);
|
|
104
|
+
const [data,total]=await Promise.all([this.prisma.order.findMany({where:{userId},orderBy:{createdAt:"desc"},skip:(page-1)*limit,take:limit,select:{id:true,status:true,total:true,currency:true,createdAt:true}}),this.prisma.order.count({where:{userId}})]);
|
|
105
|
+
return {data,meta:{page,limit,total,pages:Math.ceil(total/limit)||1}};
|
|
106
|
+
}
|
|
107
|
+
async refundOrder(id:string,actorId:string){
|
|
108
|
+
const stripe=this.stripe();
|
|
109
|
+
const order=await this.prisma.order.findUnique({where:{id}});
|
|
110
|
+
if(!order||!order.paymentIntentId)throw new NotFoundException("Payment not found");
|
|
111
|
+
if(order.status==="refunded")return {ok:true,status:"refunded"};
|
|
112
|
+
if(order.status==="refund_pending")return {ok:true,status:"refund_pending"}; // reconciliation via signed webhook; no second submission
|
|
113
|
+
const claimed=await this.prisma.$transaction(async tx=>{
|
|
114
|
+
const change=await tx.order.updateMany({where:{id,status:"paid"},data:{status:"refund_pending"}});
|
|
115
|
+
if(change.count)await tx.auditLog.create({data:{userId:actorId,resource:"orders",resourceId:id,action:"refund.requested"}});
|
|
116
|
+
return change.count;
|
|
117
|
+
});
|
|
118
|
+
if(!claimed)throw new ConflictException("Order not refundable");
|
|
119
|
+
try{
|
|
120
|
+
const refund=await stripe.refunds.create({payment_intent:order.paymentIntentId,amount:order.total},{idempotencyKey:"refund-"+id});
|
|
121
|
+
// Keep pending until signed full-refund confirmation. A failed or ambiguous provider
|
|
122
|
+
// response requires operator reconciliation and cannot trigger another refund automatically.
|
|
123
|
+
return {ok:true,status:"refund_pending",refundId:refund.id,providerStatus:refund.status};
|
|
124
|
+
}catch{throw new ServiceUnavailableException("Refund pending reconciliation; do not submit another refund");}
|
|
125
|
+
}
|
|
126
|
+
async listProducts(active=true){
|
|
127
|
+
return this.prisma.product.findMany({where:active?{active:true}:undefined,take:100,orderBy:{createdAt:"desc"},select:{id:true,name:true,slug:true,description:true,price:true,currency:true,imageUrl:true}});
|
|
128
|
+
}
|
|
235
129
|
}
|
|
@@ -4,9 +4,10 @@ const nodeExternals = require("webpack-node-externals");
|
|
|
4
4
|
module.exports = function configureWebpack(options) {
|
|
5
5
|
return {
|
|
6
6
|
...options,
|
|
7
|
+
resolve: {...options.resolve, extensionAlias: {...options.resolve?.extensionAlias, ".js": [".js", ".ts", ".tsx"]}},
|
|
7
8
|
externals: [
|
|
8
9
|
nodeExternals({
|
|
9
|
-
allowlist: [/^@openadminjs
|
|
10
|
+
allowlist: [/^@openadminjs\//, /^openid-client(?:\/|$)/, /^oauth4webapi(?:\/|$)/, /^jose(?:\/|$)/],
|
|
10
11
|
}),
|
|
11
12
|
],
|
|
12
13
|
};
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg"
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="OpenAdminJS">
|
|
2
|
+
<rect width="64" height="64" rx="13" fill="#101820"/>
|
|
3
|
+
<path fill="#B9F56D" d="M29 13a19 19 0 1 0 0 38h9l11-23 7 15H45l-4 8h18L42 13h-8L21 42a11 11 0 1 1 8-21l3-7z"/>
|
|
4
|
+
</svg>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
services:
|
|
2
|
+
db:
|
|
3
|
+
image: postgres:16
|
|
4
|
+
environment:
|
|
5
|
+
POSTGRES_DB: openadmin
|
|
6
|
+
POSTGRES_USER: openadmin
|
|
7
|
+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD}
|
|
8
|
+
volumes: ["db:/var/lib/postgresql/data"]
|
|
9
|
+
healthcheck:
|
|
10
|
+
test: ["CMD-SHELL", "pg_isready -U openadmin -d openadmin"]
|
|
11
|
+
interval: 5s
|
|
12
|
+
timeout: 5s
|
|
13
|
+
retries: 20
|
|
14
|
+
restart: unless-stopped
|
|
15
|
+
migrate:
|
|
16
|
+
build: .
|
|
17
|
+
command: ["pnpm","exec","prisma","migrate","deploy","--schema","prisma/schema.prisma"]
|
|
18
|
+
environment:
|
|
19
|
+
DATABASE_URL: ${DATABASE_URL:?Set DATABASE_URL}
|
|
20
|
+
depends_on:
|
|
21
|
+
db:
|
|
22
|
+
condition: service_healthy
|
|
23
|
+
api:
|
|
24
|
+
build: .
|
|
25
|
+
environment:
|
|
26
|
+
DATABASE_URL: ${DATABASE_URL:?Set DATABASE_URL}
|
|
27
|
+
JWT_SECRET: ${JWT_SECRET:?Set JWT_SECRET}
|
|
28
|
+
ADMIN_ORIGIN: ${ADMIN_ORIGIN:?Set ADMIN_ORIGIN}
|
|
29
|
+
API_PORT: "4000"
|
|
30
|
+
UPLOADS_ROOT: /app/storage
|
|
31
|
+
NODE_ENV: production
|
|
32
|
+
volumes: ["storage:/app/storage"]
|
|
33
|
+
depends_on:
|
|
34
|
+
migrate:
|
|
35
|
+
condition: service_completed_successfully
|
|
36
|
+
healthcheck:
|
|
37
|
+
test: ["CMD","node","-e","fetch('http://127.0.0.1:4000/health/ready').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"]
|
|
38
|
+
interval: 15s
|
|
39
|
+
timeout: 5s
|
|
40
|
+
retries: 8
|
|
41
|
+
restart: unless-stopped
|
|
42
|
+
admin:
|
|
43
|
+
build: .
|
|
44
|
+
command: ["pnpm","--filter","@openadminjs/admin","start"]
|
|
45
|
+
environment:
|
|
46
|
+
NODE_ENV: production
|
|
47
|
+
API_INTERNAL_URL: http://api:4000
|
|
48
|
+
ADMIN_ORIGIN: ${ADMIN_ORIGIN:?Set ADMIN_ORIGIN}
|
|
49
|
+
ports: ["127.0.0.1:3000:3000"]
|
|
50
|
+
depends_on:
|
|
51
|
+
api:
|
|
52
|
+
condition: service_healthy
|
|
53
|
+
restart: unless-stopped
|
|
54
|
+
volumes:
|
|
55
|
+
db:
|
|
56
|
+
storage:
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# CRM Admin
|
|
2
|
+
|
|
3
|
+
CRM-focused example for contacts, companies, deals and activity logs. Suitable for B2B sales and account management.
|
|
4
|
+
|
|
5
|
+
**Suggested resources:** `Contact`, `Company`, `Deal`, `Activity`, `Pipeline`, `Owner` (user relation).
|
|
6
|
+
|
|
7
|
+
## Code in this folder
|
|
8
|
+
|
|
9
|
+
| Path | Purpose |
|
|
10
|
+
|------|---------|
|
|
11
|
+
| `prisma/models.fragment.prisma` | `Contact`, `Company`, `Deal`, `Activity` models. |
|
|
12
|
+
| `src/resources/*.resource.ts` | Four resource modules. |
|
|
13
|
+
| `src/index.ts` | `crmExampleResources` — merge into `registry.ts`. |
|
|
14
|
+
|
|
15
|
+
### Merge into your app
|
|
16
|
+
|
|
17
|
+
See [basic-admin](../basic-admin/README.md#merge-into-your-app). Add permissions such as `contacts.read`, `companies.read`, `deals.read`, `activities.read` (and create/update/delete) to your permission seed.
|
|
18
|
+
|
|
19
|
+
## Run in a generated project
|
|
20
|
+
|
|
21
|
+
From a **new, disposable** OpenAdminJS project root:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
node scripts/install-crm.mjs --dry-run
|
|
25
|
+
node scripts/install-crm.mjs --apply
|
|
26
|
+
pnpm db:migrate
|
|
27
|
+
pnpm db:seed
|
|
28
|
+
pnpm dev
|
|
29
|
+
````
|
|
30
|
+
|
|
31
|
+
Review the migration before applying it. For SQLite/MySQL fresh projects follow the provider-specific instructions, rather than copying PostgreSQL migrations. The installer does not connect to the database or overwrite existing resource files. The admin role's wildcard includes the registered CRM permissions; grant explicit permissions to other roles. Open Companies, Contacts, Deals and Activities in the resource navigation.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openadminjs/example-crm",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Reference code: contacts, companies, deals, activities for a sales CRM slice.",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
9
|
+
"lint": "tsc -p tsconfig.json --noEmit",
|
|
10
|
+
"test": "vitest run"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@openadminjs/core": "workspace:*",
|
|
14
|
+
"typescript": "^5.7.2",
|
|
15
|
+
"vitest": "^3.2.0"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Append to schema.prisma, then migrate.
|
|
2
|
+
|
|
3
|
+
model Contact {
|
|
4
|
+
id String @id @default(cuid())
|
|
5
|
+
email String?
|
|
6
|
+
firstName String
|
|
7
|
+
lastName String?
|
|
8
|
+
phone String?
|
|
9
|
+
companyId String?
|
|
10
|
+
company Company? @relation(fields: [companyId], references: [id])
|
|
11
|
+
deals Deal[]
|
|
12
|
+
activities Activity[]
|
|
13
|
+
createdAt DateTime @default(now())
|
|
14
|
+
updatedAt DateTime @updatedAt
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
model Company {
|
|
18
|
+
id String @id @default(cuid())
|
|
19
|
+
name String
|
|
20
|
+
website String?
|
|
21
|
+
contacts Contact[]
|
|
22
|
+
deals Deal[]
|
|
23
|
+
createdAt DateTime @default(now())
|
|
24
|
+
updatedAt DateTime @updatedAt
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
model Deal {
|
|
28
|
+
id String @id @default(cuid())
|
|
29
|
+
title String
|
|
30
|
+
stage String @default("lead")
|
|
31
|
+
amount Int @default(0)
|
|
32
|
+
companyId String?
|
|
33
|
+
company Company? @relation(fields: [companyId], references: [id])
|
|
34
|
+
contactId String?
|
|
35
|
+
contact Contact? @relation(fields: [contactId], references: [id])
|
|
36
|
+
activities Activity[]
|
|
37
|
+
createdAt DateTime @default(now())
|
|
38
|
+
updatedAt DateTime @updatedAt
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
model Activity {
|
|
42
|
+
id String @id @default(cuid())
|
|
43
|
+
type String
|
|
44
|
+
body String?
|
|
45
|
+
dealId String?
|
|
46
|
+
deal Deal? @relation(fields: [dealId], references: [id], onDelete: SetNull)
|
|
47
|
+
contactId String?
|
|
48
|
+
contact Contact? @relation(fields: [contactId], references: [id], onDelete: SetNull)
|
|
49
|
+
createdAt DateTime @default(now())
|
|
50
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ResourceConfig } from "@openadminjs/core";
|
|
2
|
+
import activities from "./resources/activities.resource";
|
|
3
|
+
import companies from "./resources/companies.resource";
|
|
4
|
+
import contacts from "./resources/contacts.resource";
|
|
5
|
+
import deals from "./resources/deals.resource";
|
|
6
|
+
|
|
7
|
+
export const crmExampleResources = [companies, contacts, deals, activities] satisfies ResourceConfig[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { defineResource } from "@openadminjs/core";
|
|
2
|
+
|
|
3
|
+
export default defineResource({
|
|
4
|
+
name: "activities",
|
|
5
|
+
label: "Activities",
|
|
6
|
+
model: "activity",
|
|
7
|
+
titleField: "type",
|
|
8
|
+
icon: "ListTodo",
|
|
9
|
+
permissions: {
|
|
10
|
+
read: "activities.read",
|
|
11
|
+
create: "activities.create",
|
|
12
|
+
update: "activities.update",
|
|
13
|
+
delete: "activities.delete"
|
|
14
|
+
},
|
|
15
|
+
fields: {
|
|
16
|
+
id: { type: "id", label: "ID", create: false, edit: false, list: false },
|
|
17
|
+
type: {
|
|
18
|
+
type: "select",
|
|
19
|
+
label: "Type",
|
|
20
|
+
options: ["call", "email", "meeting", "note"],
|
|
21
|
+
filterable: true,
|
|
22
|
+
sortable: true
|
|
23
|
+
},
|
|
24
|
+
body: { type: "textarea", label: "Details", list: false },
|
|
25
|
+
dealId: { type: "relation", label: "Deal", resource: "deals", displayField: "title", filterable: true },
|
|
26
|
+
contactId: { type: "relation", label: "Contact", resource: "contacts", displayField: "email", filterable: true },
|
|
27
|
+
createdAt: { type: "datetime", label: "When", create: false, edit: false, sortable: true }
|
|
28
|
+
}
|
|
29
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineResource } from "@openadminjs/core";
|
|
2
|
+
|
|
3
|
+
export default defineResource({
|
|
4
|
+
name: "companies",
|
|
5
|
+
label: "Companies",
|
|
6
|
+
model: "company",
|
|
7
|
+
titleField: "name",
|
|
8
|
+
icon: "Building2",
|
|
9
|
+
permissions: {
|
|
10
|
+
read: "companies.read",
|
|
11
|
+
create: "companies.create",
|
|
12
|
+
update: "companies.update",
|
|
13
|
+
delete: "companies.delete"
|
|
14
|
+
},
|
|
15
|
+
fields: {
|
|
16
|
+
id: { type: "id", label: "ID", create: false, edit: false, list: false },
|
|
17
|
+
name: { type: "text", label: "Name", required: true, searchable: true, sortable: true },
|
|
18
|
+
website: { type: "url", label: "Website", list: false },
|
|
19
|
+
createdAt: { type: "datetime", label: "Created", create: false, edit: false, sortable: true }
|
|
20
|
+
}
|
|
21
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineResource } from "@openadminjs/core";
|
|
2
|
+
|
|
3
|
+
export default defineResource({
|
|
4
|
+
name: "contacts",
|
|
5
|
+
label: "Contacts",
|
|
6
|
+
model: "contact",
|
|
7
|
+
titleField: "firstName",
|
|
8
|
+
icon: "Users",
|
|
9
|
+
permissions: {
|
|
10
|
+
read: "contacts.read",
|
|
11
|
+
create: "contacts.create",
|
|
12
|
+
update: "contacts.update",
|
|
13
|
+
delete: "contacts.delete"
|
|
14
|
+
},
|
|
15
|
+
fields: {
|
|
16
|
+
id: { type: "id", label: "ID", create: false, edit: false, list: false },
|
|
17
|
+
firstName: { type: "text", label: "First name", required: true, searchable: true, sortable: true },
|
|
18
|
+
lastName: { type: "text", label: "Last name", searchable: true, sortable: true },
|
|
19
|
+
email: { type: "email", label: "Email", searchable: true },
|
|
20
|
+
phone: { type: "text", label: "Phone", searchable: true },
|
|
21
|
+
companyId: { type: "relation", label: "Company", resource: "companies", displayField: "name", filterable: true },
|
|
22
|
+
createdAt: { type: "datetime", label: "Created", create: false, edit: false, sortable: true }
|
|
23
|
+
}
|
|
24
|
+
});
|