@wtfalch/authz-store 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.
- package/LICENSE +21 -0
- package/README.md +79 -0
- package/dist/credential-secret.d.ts +70 -0
- package/dist/credential-secret.js +89 -0
- package/dist/grants.d.ts +395 -0
- package/dist/grants.js +68 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/migrate.d.ts +9 -0
- package/dist/migrate.js +41 -0
- package/dist/owners.d.ts +23 -0
- package/dist/owners.js +40 -0
- package/dist/policy-schema.d.ts +812 -0
- package/dist/policy-schema.js +57 -0
- package/dist/resource-schema.d.ts +188 -0
- package/dist/resource-schema.js +22 -0
- package/dist/schema.d.ts +1821 -0
- package/dist/schema.js +193 -0
- package/dist/scoped.d.ts +140 -0
- package/dist/scoped.js +176 -0
- package/migrations/0001_baseline.sql +571 -0
- package/migrations/0002_grants.sql +27 -0
- package/package.json +44 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { boolean, index, integer, jsonb, pgTable, text, timestamp, uniqueIndex, uuid, } from 'drizzle-orm/pg-core';
|
|
3
|
+
/** The only role definitions: built-in and custom, across every application module. */
|
|
4
|
+
export const policyRoles = pgTable('authz_roles', {
|
|
5
|
+
id: uuid('id').primaryKey().defaultRandom(),
|
|
6
|
+
tenantId: uuid('tenant_id').notNull(),
|
|
7
|
+
applicationId: text('application_id').notNull(),
|
|
8
|
+
platformId: text('platform_id').notNull(),
|
|
9
|
+
key: text('key').notNull(),
|
|
10
|
+
name: text('name').notNull(),
|
|
11
|
+
description: text('description').notNull().default(''),
|
|
12
|
+
builtIn: boolean('built_in').notNull().default(false),
|
|
13
|
+
revision: integer('revision').notNull().default(1),
|
|
14
|
+
entries: jsonb('entries').$type().notNull(),
|
|
15
|
+
guards: text('guards').array().notNull().default(sql `'{}'`),
|
|
16
|
+
createdBy: text('created_by'),
|
|
17
|
+
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
|
18
|
+
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
|
19
|
+
updatedBy: text('updated_by'),
|
|
20
|
+
}, (t) => [
|
|
21
|
+
uniqueIndex('authz_roles_tenant_app_key').on(t.tenantId, t.applicationId, t.key),
|
|
22
|
+
uniqueIndex('authz_roles_boundary_id').on(t.tenantId, t.applicationId, t.platformId, t.id),
|
|
23
|
+
]);
|
|
24
|
+
/** Participation is stored in memberships; all authority comes from these assignments. */
|
|
25
|
+
export const policyAssignments = pgTable('authz_assignments', {
|
|
26
|
+
id: uuid('id').primaryKey().defaultRandom(),
|
|
27
|
+
tenantId: uuid('tenant_id').notNull(),
|
|
28
|
+
applicationId: text('application_id').notNull(),
|
|
29
|
+
platformId: text('platform_id').notNull(),
|
|
30
|
+
roleId: uuid('role_id').notNull(),
|
|
31
|
+
principalId: text('principal_id'),
|
|
32
|
+
principalClass: text('principal_class'),
|
|
33
|
+
teamId: uuid('team_id'),
|
|
34
|
+
recipientDescendants: boolean('recipient_descendants').notNull().default(false),
|
|
35
|
+
boundary: jsonb('boundary').$type().notNull(),
|
|
36
|
+
scope: jsonb('scope').$type().notNull(),
|
|
37
|
+
source: text('source').notNull().default('direct'),
|
|
38
|
+
viaTenantId: uuid('via_tenant_id'),
|
|
39
|
+
/** One explicit assignment supplies the membership shortcut shown in the people picker. */
|
|
40
|
+
primary: boolean('primary_assignment').notNull().default(false),
|
|
41
|
+
expiresAt: timestamp('expires_at', { withTimezone: true }),
|
|
42
|
+
createdBy: text('created_by'),
|
|
43
|
+
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
|
44
|
+
}, (t) => [
|
|
45
|
+
index('authz_assignments_principal_idx').on(t.tenantId, t.principalClass, t.principalId),
|
|
46
|
+
index('authz_assignments_role_idx').on(t.tenantId, t.roleId),
|
|
47
|
+
index('authz_assignments_team_idx').on(t.tenantId, t.teamId),
|
|
48
|
+
]);
|
|
49
|
+
export const policyVersion = pgTable('authz_policy_version', {
|
|
50
|
+
id: integer('id').primaryKey(),
|
|
51
|
+
version: integer('version').notNull(),
|
|
52
|
+
applicationId: text('application_id').notNull(),
|
|
53
|
+
platformId: text('platform_id').notNull(),
|
|
54
|
+
mappingRevision: text('mapping_revision').notNull(),
|
|
55
|
+
sourceDigest: text('source_digest').notNull(),
|
|
56
|
+
migratedAt: timestamp('migrated_at', { withTimezone: true }).notNull().defaultNow(),
|
|
57
|
+
});
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
export interface AppRolePermission {
|
|
2
|
+
permission: string;
|
|
3
|
+
relation: 'any' | 'owner' | 'actor' | 'subject';
|
|
4
|
+
}
|
|
5
|
+
export declare const accessTeams: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
6
|
+
name: "access_teams";
|
|
7
|
+
schema: undefined;
|
|
8
|
+
columns: {
|
|
9
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
10
|
+
name: "id";
|
|
11
|
+
tableName: "access_teams";
|
|
12
|
+
dataType: "string";
|
|
13
|
+
columnType: "PgUUID";
|
|
14
|
+
data: string;
|
|
15
|
+
driverParam: string;
|
|
16
|
+
notNull: true;
|
|
17
|
+
hasDefault: true;
|
|
18
|
+
isPrimaryKey: true;
|
|
19
|
+
isAutoincrement: false;
|
|
20
|
+
hasRuntimeDefault: false;
|
|
21
|
+
enumValues: undefined;
|
|
22
|
+
baseColumn: never;
|
|
23
|
+
identity: undefined;
|
|
24
|
+
generated: undefined;
|
|
25
|
+
}, {}, {}>;
|
|
26
|
+
tenantId: import("drizzle-orm/pg-core").PgColumn<{
|
|
27
|
+
name: "tenant_id";
|
|
28
|
+
tableName: "access_teams";
|
|
29
|
+
dataType: "string";
|
|
30
|
+
columnType: "PgUUID";
|
|
31
|
+
data: string;
|
|
32
|
+
driverParam: string;
|
|
33
|
+
notNull: true;
|
|
34
|
+
hasDefault: false;
|
|
35
|
+
isPrimaryKey: false;
|
|
36
|
+
isAutoincrement: false;
|
|
37
|
+
hasRuntimeDefault: false;
|
|
38
|
+
enumValues: undefined;
|
|
39
|
+
baseColumn: never;
|
|
40
|
+
identity: undefined;
|
|
41
|
+
generated: undefined;
|
|
42
|
+
}, {}, {}>;
|
|
43
|
+
parentId: import("drizzle-orm/pg-core").PgColumn<{
|
|
44
|
+
name: "parent_id";
|
|
45
|
+
tableName: "access_teams";
|
|
46
|
+
dataType: "string";
|
|
47
|
+
columnType: "PgUUID";
|
|
48
|
+
data: string;
|
|
49
|
+
driverParam: string;
|
|
50
|
+
notNull: false;
|
|
51
|
+
hasDefault: false;
|
|
52
|
+
isPrimaryKey: false;
|
|
53
|
+
isAutoincrement: false;
|
|
54
|
+
hasRuntimeDefault: false;
|
|
55
|
+
enumValues: undefined;
|
|
56
|
+
baseColumn: never;
|
|
57
|
+
identity: undefined;
|
|
58
|
+
generated: undefined;
|
|
59
|
+
}, {}, {}>;
|
|
60
|
+
name: import("drizzle-orm/pg-core").PgColumn<{
|
|
61
|
+
name: "name";
|
|
62
|
+
tableName: "access_teams";
|
|
63
|
+
dataType: "string";
|
|
64
|
+
columnType: "PgText";
|
|
65
|
+
data: string;
|
|
66
|
+
driverParam: string;
|
|
67
|
+
notNull: true;
|
|
68
|
+
hasDefault: false;
|
|
69
|
+
isPrimaryKey: false;
|
|
70
|
+
isAutoincrement: false;
|
|
71
|
+
hasRuntimeDefault: false;
|
|
72
|
+
enumValues: [string, ...string[]];
|
|
73
|
+
baseColumn: never;
|
|
74
|
+
identity: undefined;
|
|
75
|
+
generated: undefined;
|
|
76
|
+
}, {}, {}>;
|
|
77
|
+
archivedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
78
|
+
name: "archived_at";
|
|
79
|
+
tableName: "access_teams";
|
|
80
|
+
dataType: "date";
|
|
81
|
+
columnType: "PgTimestamp";
|
|
82
|
+
data: Date;
|
|
83
|
+
driverParam: string;
|
|
84
|
+
notNull: false;
|
|
85
|
+
hasDefault: false;
|
|
86
|
+
isPrimaryKey: false;
|
|
87
|
+
isAutoincrement: false;
|
|
88
|
+
hasRuntimeDefault: false;
|
|
89
|
+
enumValues: undefined;
|
|
90
|
+
baseColumn: never;
|
|
91
|
+
identity: undefined;
|
|
92
|
+
generated: undefined;
|
|
93
|
+
}, {}, {}>;
|
|
94
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
95
|
+
name: "created_at";
|
|
96
|
+
tableName: "access_teams";
|
|
97
|
+
dataType: "date";
|
|
98
|
+
columnType: "PgTimestamp";
|
|
99
|
+
data: Date;
|
|
100
|
+
driverParam: string;
|
|
101
|
+
notNull: true;
|
|
102
|
+
hasDefault: true;
|
|
103
|
+
isPrimaryKey: false;
|
|
104
|
+
isAutoincrement: false;
|
|
105
|
+
hasRuntimeDefault: false;
|
|
106
|
+
enumValues: undefined;
|
|
107
|
+
baseColumn: never;
|
|
108
|
+
identity: undefined;
|
|
109
|
+
generated: undefined;
|
|
110
|
+
}, {}, {}>;
|
|
111
|
+
};
|
|
112
|
+
dialect: "pg";
|
|
113
|
+
}>;
|
|
114
|
+
export declare const accessTeamMembers: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
115
|
+
name: "access_team_members";
|
|
116
|
+
schema: undefined;
|
|
117
|
+
columns: {
|
|
118
|
+
tenantId: import("drizzle-orm/pg-core").PgColumn<{
|
|
119
|
+
name: "tenant_id";
|
|
120
|
+
tableName: "access_team_members";
|
|
121
|
+
dataType: "string";
|
|
122
|
+
columnType: "PgUUID";
|
|
123
|
+
data: string;
|
|
124
|
+
driverParam: string;
|
|
125
|
+
notNull: true;
|
|
126
|
+
hasDefault: false;
|
|
127
|
+
isPrimaryKey: false;
|
|
128
|
+
isAutoincrement: false;
|
|
129
|
+
hasRuntimeDefault: false;
|
|
130
|
+
enumValues: undefined;
|
|
131
|
+
baseColumn: never;
|
|
132
|
+
identity: undefined;
|
|
133
|
+
generated: undefined;
|
|
134
|
+
}, {}, {}>;
|
|
135
|
+
teamId: import("drizzle-orm/pg-core").PgColumn<{
|
|
136
|
+
name: "team_id";
|
|
137
|
+
tableName: "access_team_members";
|
|
138
|
+
dataType: "string";
|
|
139
|
+
columnType: "PgUUID";
|
|
140
|
+
data: string;
|
|
141
|
+
driverParam: string;
|
|
142
|
+
notNull: true;
|
|
143
|
+
hasDefault: false;
|
|
144
|
+
isPrimaryKey: false;
|
|
145
|
+
isAutoincrement: false;
|
|
146
|
+
hasRuntimeDefault: false;
|
|
147
|
+
enumValues: undefined;
|
|
148
|
+
baseColumn: never;
|
|
149
|
+
identity: undefined;
|
|
150
|
+
generated: undefined;
|
|
151
|
+
}, {}, {}>;
|
|
152
|
+
principalId: import("drizzle-orm/pg-core").PgColumn<{
|
|
153
|
+
name: "principal_id";
|
|
154
|
+
tableName: "access_team_members";
|
|
155
|
+
dataType: "string";
|
|
156
|
+
columnType: "PgText";
|
|
157
|
+
data: string;
|
|
158
|
+
driverParam: string;
|
|
159
|
+
notNull: true;
|
|
160
|
+
hasDefault: false;
|
|
161
|
+
isPrimaryKey: false;
|
|
162
|
+
isAutoincrement: false;
|
|
163
|
+
hasRuntimeDefault: false;
|
|
164
|
+
enumValues: [string, ...string[]];
|
|
165
|
+
baseColumn: never;
|
|
166
|
+
identity: undefined;
|
|
167
|
+
generated: undefined;
|
|
168
|
+
}, {}, {}>;
|
|
169
|
+
principalClass: import("drizzle-orm/pg-core").PgColumn<{
|
|
170
|
+
name: "principal_class";
|
|
171
|
+
tableName: "access_team_members";
|
|
172
|
+
dataType: "string";
|
|
173
|
+
columnType: "PgText";
|
|
174
|
+
data: string;
|
|
175
|
+
driverParam: string;
|
|
176
|
+
notNull: true;
|
|
177
|
+
hasDefault: false;
|
|
178
|
+
isPrimaryKey: false;
|
|
179
|
+
isAutoincrement: false;
|
|
180
|
+
hasRuntimeDefault: false;
|
|
181
|
+
enumValues: [string, ...string[]];
|
|
182
|
+
baseColumn: never;
|
|
183
|
+
identity: undefined;
|
|
184
|
+
generated: undefined;
|
|
185
|
+
}, {}, {}>;
|
|
186
|
+
};
|
|
187
|
+
dialect: "pg";
|
|
188
|
+
}>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { index, pgTable, primaryKey, text, timestamp, uniqueIndex, uuid, } from 'drizzle-orm/pg-core';
|
|
3
|
+
export const accessTeams = pgTable('access_teams', {
|
|
4
|
+
id: uuid('id').primaryKey().defaultRandom(),
|
|
5
|
+
tenantId: uuid('tenant_id').notNull(),
|
|
6
|
+
parentId: uuid('parent_id'),
|
|
7
|
+
name: text('name').notNull(),
|
|
8
|
+
archivedAt: timestamp('archived_at', { withTimezone: true }),
|
|
9
|
+
createdAt: timestamp('created_at', { withTimezone: true }).notNull().default(sql `now()`),
|
|
10
|
+
}, (t) => [
|
|
11
|
+
uniqueIndex('access_teams_tenant_id_id_key').on(t.tenantId, t.id),
|
|
12
|
+
index('access_teams_parent_idx').on(t.tenantId, t.parentId),
|
|
13
|
+
]);
|
|
14
|
+
export const accessTeamMembers = pgTable('access_team_members', {
|
|
15
|
+
tenantId: uuid('tenant_id').notNull(),
|
|
16
|
+
teamId: uuid('team_id').notNull(),
|
|
17
|
+
principalId: text('principal_id').notNull(),
|
|
18
|
+
principalClass: text('principal_class').notNull(),
|
|
19
|
+
}, (t) => [
|
|
20
|
+
primaryKey({ columns: [t.teamId, t.principalClass, t.principalId] }),
|
|
21
|
+
index('access_team_members_principal_idx').on(t.tenantId, t.principalId),
|
|
22
|
+
]);
|