@awsmbiz/inbis-access-control 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,52 @@
1
+ -- @inbis/access-control 0001_access_control_initial
2
+ -- Roles and permissions (plan Q40-Q42). Timestamps are
3
+ -- epoch milliseconds. Applied after @inbis/auth: user_role references `user`,
4
+ -- so deleting a user (any path) removes its role assignments.
5
+
6
+ -- The permission catalogue, seeded from the app's code (defineAccessControl).
7
+ CREATE TABLE `permission` (
8
+ `name` text PRIMARY KEY NOT NULL,
9
+ `description` text NOT NULL
10
+ );
11
+
12
+ -- System roles (seeded from code, immutable through the API) and custom roles (created by admins).
13
+ CREATE TABLE `role` (
14
+ `id` text PRIMARY KEY NOT NULL,
15
+ `name` text NOT NULL,
16
+ `description` text,
17
+ `system` integer DEFAULT 0 NOT NULL,
18
+ `created_at` integer NOT NULL,
19
+ `updated_at` integer NOT NULL
20
+ );
21
+ CREATE UNIQUE INDEX `role_name_idx` ON `role` (`name`);
22
+
23
+ CREATE TABLE `role_permission` (
24
+ `role_id` text NOT NULL REFERENCES `role`(`id`) ON DELETE CASCADE,
25
+ `permission` text NOT NULL REFERENCES `permission`(`name`) ON DELETE CASCADE,
26
+ PRIMARY KEY (`role_id`, `permission`)
27
+ );
28
+ CREATE INDEX `role_permission_permission_idx` ON `role_permission` (`permission`);
29
+
30
+ -- Explicit inheritance only: `role_id` includes every permission of `inherits_role_id`.
31
+ CREATE TABLE `role_inheritance` (
32
+ `role_id` text NOT NULL REFERENCES `role`(`id`) ON DELETE CASCADE,
33
+ `inherits_role_id` text NOT NULL REFERENCES `role`(`id`) ON DELETE CASCADE,
34
+ PRIMARY KEY (`role_id`, `inherits_role_id`)
35
+ );
36
+
37
+ -- Many roles per user.
38
+ CREATE TABLE `user_role` (
39
+ `user_id` text NOT NULL REFERENCES `user`(`id`) ON DELETE CASCADE,
40
+ `role_id` text NOT NULL REFERENCES `role`(`id`) ON DELETE CASCADE,
41
+ `assigned_at` integer NOT NULL,
42
+ `assigned_by` text,
43
+ PRIMARY KEY (`user_id`, `role_id`)
44
+ );
45
+ CREATE INDEX `user_role_role_id_idx` ON `user_role` (`role_id`);
46
+
47
+ -- Fingerprint of the last seeded catalogue: seeding skips its writes when unchanged.
48
+ CREATE TABLE `access_control_seed` (
49
+ `id` integer PRIMARY KEY NOT NULL CHECK (`id` = 1),
50
+ `fingerprint` text NOT NULL,
51
+ `seeded_at` integer NOT NULL
52
+ );
@@ -0,0 +1,3 @@
1
+ {
2
+ "0001_access_control_initial.sql": "sha256:f24813c304b02d09d726dbed3145e8d13bd426d47a1d46280aaf2ccd34b9119a"
3
+ }
package/package.json CHANGED
@@ -1,6 +1,69 @@
1
1
  {
2
2
  "name": "@awsmbiz/inbis-access-control",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Access control for Inbis applications: a typed permission catalogue declared in code, roles in D1, authorize() and requirePermission(), and package-owned D1 migrations.",
5
+ "license": "UNLICENSED",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/awsmbiz/inbis-platform.git",
9
+ "directory": "packages/access-control"
10
+ },
11
+ "publishConfig": {
12
+ "registry": "https://registry.npmjs.org/",
13
+ "access": "public"
14
+ },
15
+ "type": "module",
16
+ "sideEffects": false,
17
+ "files": [
18
+ "dist",
19
+ "migrations"
20
+ ],
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "default": "./dist/index.js"
25
+ },
26
+ "./hono": {
27
+ "types": "./dist/hono.d.ts",
28
+ "default": "./dist/hono.js"
29
+ },
30
+ "./package.json": "./package.json"
31
+ },
32
+ "dependencies": {
33
+ "@awsmbiz/inbis-core": "0.1.0",
34
+ "@awsmbiz/inbis-db": "0.1.0"
35
+ },
36
+ "peerDependencies": {
37
+ "drizzle-orm": "^0.45.4",
38
+ "hono": "^4.13.14"
39
+ },
40
+ "peerDependenciesMeta": {
41
+ "hono": {
42
+ "optional": true
43
+ }
44
+ },
45
+ "devDependencies": {
46
+ "@arethetypeswrong/cli": "0.18.5",
47
+ "@cloudflare/vitest-plugin": "1.4.11",
48
+ "@cloudflare/workers-types": "5.20261030.1",
49
+ "@awsmbiz/inbis-auth": "0.1.0",
50
+ "@awsmbiz/inbis-eslint-config": "0.1.0",
51
+ "@awsmbiz/inbis-tsconfig": "0.1.0",
52
+ "drizzle-orm": "0.45.4",
53
+ "eslint": "10.14.0",
54
+ "hono": "4.13.14",
55
+ "publint": "0.3.25",
56
+ "tsdown": "0.23.4",
57
+ "typescript": "6.0.3",
58
+ "vitest": "5.0.5",
59
+ "wrangler": "4.156.0"
60
+ },
61
+ "scripts": {
62
+ "build": "tsdown",
63
+ "typecheck": "tsc",
64
+ "lint": "eslint . --max-warnings 0",
65
+ "test": "vitest run",
66
+ "check:exports": "publint --strict && attw --pack . --profile esm-only",
67
+ "check:migrations": "inbis-db check-lock migrations --base \"${MIGRATIONS_BASE_REF:-origin/main}\""
68
+ }
6
69
  }