Эта страница пока недоступна на выбранном языке (Русский), поэтому показана на английском.
Data access and security rules
pluginStore or an additive schema fragment, Prisma only, minor-unit money, and the nine security rules every plugin follows.
Two ways to store data
import { pluginStore } from "@/lib/plugins/sdk";
const store = pluginStore("site-visits"); // keys are namespaced as plugin:site-visits:<key>
const cursor = await store.get<string | null>("digest-cursor", null);
await store.set("digest-cursor", new Date().toISOString());
await store.set("migrated:2", true); // record a one-off migration
const keys = await store.keys();enum SiteVisitStatus {
PLANNED
DONE
CANCELLED
}
model SiteVisit {
id String @id @default(cuid())
quotationId String?
customerName String
plannedAt DateTime
slot String @default("morning")
status SiteVisitStatus @default(PLANNED)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([plannedAt, status])
}- A fragment may add models and enums only — never touch an existing model, declare a
datasource/generator, or add relations to core models. Store core ids (invoiceId,customerId) as plain strings. - Renaming or dropping a column later is not supported: add a new column with a default and migrate lazily or in a one-off job.
- Prisma only, through
import { prisma } from "@/lib/prisma". No raw SQL — the app runs on PostgreSQL and MariaDB. - Money: integer minor units +
currency. Dates: UTCDateTime. - Do not cache per-user (or per-workspace) data in module-level variables; use React
cache()per request.
Security rules
Permission check on every page (
requireAdminPage), action (requirePermission) and route (currentUser+can).Validate every input with zod; look ids up instead of trusting them; limit string lengths.
Never log or return secrets; no keys in code,
module.jsonor README.Outbound HTTP:
assertFetchableUrl(url)from@/lib/security/safe-fetchfirst, plusAbortSignal.timeout.Add your own counters in
pluginStorefor expensive endpoints.No
dangerouslySetInnerHTMLwith user content.Files only through the media library or
safeJoin; never write outsidemodules/<id>or the app's own data folder.Keep
register()free of side effects.Log mutations with
logActivityand keep “drop data” honest.
Marketplace plugins: SDK only
- Imports only from
@/lib/plugins/sdk,@/lib/plugins/types,@/components/admin/ui,@/lib/auth/guards,react,zod,lucide-react,next/navigationand files inside the package. - No
process/ environment,globalThis,eval/Function,require/ dynamicimport(), network (fetch,WebSocket…),prismaor raw SQL, file system, raw HTML injection, cookies or browser storage,atob/fromCharCodeobfuscation. - Data lives in
pluginStore()— no schema fragment. Every SDK call takes your own plugin id as a string literal, so a plugin can never read another plugin's data. marketplace.jsondeclares the capabilities the code uses (undeclared → refused; unused → warning);networkandenvstay empty;dataUseexplains honestly what the plugin keeps.
{
"capabilities": ["hooks", "store", "settings", "widgets", "admin-pages", "messages"],
"dataUse": "Receives the appointment.booked event and stores only a counter per weekday and booking source (web / staff) in its own store. No personal data is read or kept.",
"network": [],
"env": []
}Written from: docs/PLUGIN-DEVELOPER-GUIDE.md, docs/PLUGINS.md, src/lib/plugins/sdk.ts, src/lib/plugins/installer.ts, modules/_templates/schema.prisma, docs/DEVELOPERS/PLUGIN-SDK.md, src/lib/marketplace/plugin-scan.ts, examples/marketplace/plugin-booking-pulse/marketplace.json