Skip to content

Tenant Isolation

Multi-tenant data isolation by default.

  • Tenant filter on ordinary handlers
  • What breaks if you forget tenancy (and how the framework prevents it)

Feature entry point: src/feature.ts.

Needs a running Postgres and TEST_DATABASE_URL set (e.g. postgres://postgres:[email protected]:5432/postgres, see demo/.env.example).

Terminal window
cd samples/recipes/tenant-isolation
bun test

The feature entry point — embedded straight from the source file, so the code here is exactly what runs. Multi-file samples keep their remaining files next to it on GitHub (link below):

import { createEntity, createTextField, defineFeature } from "@cosmicdrift/kumiko-framework/engine";
export const noteEntity = createEntity({
table: "read_sample_notes",
fields: {
title: createTextField({ personal: false, reason: "is_business_data", required: true }),
content: createTextField({ personal: false, reason: "is_business_data" }),
},
});
const adminWrite = { access: { roles: ["Admin"] } } as const;
const openRead = {
access: {
openToAll: {
reason:
"any signed-in user may list and view notes in their own tenant (tenant " +
"isolation, not per-user); writes are still gated by adminWrite",
},
},
} as const;
export const noteFeature = defineFeature("notes", (r) => {
r.crud("note", noteEntity, {
write: adminWrite,
read: openRead,
verbs: { update: false, delete: false, restore: false },
});
});

📄 On GitHub: samples/recipes/tenant-isolation/src/feature.ts