انتقل إلى المحتوى
تجربة مجانية 14 يومًا، بلا بطاقة9 لغات176 نوع عمل · 50 تطبيقًا
AR· USD
جرّب عرضًا حيًاابدأ التجربة المجانية

هذه الصفحة غير متاحة بلغة العربية بعد، لذا تُعرض بالإنجليزية.

Data access and security rules

pluginStore or an additive schema fragment, Prisma only, minor-unit money, and the nine security rules every plugin follows.

  • about 9 min

Two ways to store data

pluginStore — key/value on Setting rows, no schema change
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();
schema.prisma — additive fragment (models prefixed with the plugin name)
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: UTC DateTime.
  • Do not cache per-user (or per-workspace) data in module-level variables; use React cache() per request.

Security rules

  1. Permission check on every page (requireAdminPage), action (requirePermission) and route (currentUser + can).

  2. Validate every input with zod; look ids up instead of trusting them; limit string lengths.

  3. Never log or return secrets; no keys in code, module.json or README.

  4. Outbound HTTP: assertFetchableUrl(url) from @/lib/security/safe-fetch first, plus AbortSignal.timeout.

  5. Add your own counters in pluginStore for expensive endpoints.

  6. No dangerouslySetInnerHTML with user content.

  7. Files only through the media library or safeJoin; never write outside modules/<id> or the app's own data folder.

  8. Keep register() free of side effects.

  9. Log mutations with logActivity and 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/navigation and files inside the package.
  • No process / environment, globalThis, eval / Function, require / dynamic import(), network (fetch, WebSocket …), prisma or raw SQL, file system, raw HTML injection, cookies or browser storage, atob / fromCharCode obfuscation.
  • 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.json declares the capabilities the code uses (undeclared → refused; unused → warning); network and env stay empty; dataUse explains honestly what the plugin keeps.
examples/marketplace/plugin-booking-pulse/marketplace.json
{
  "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": []
}
The scan is a first filter: a person reads every line before the release is signed. Need network access or your own server? Build an integration instead.

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