@happyvertical/smrt-users 0.69.0 → 0.70.1
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/README.md +7 -0
- package/agents/oauth-authorization.md +13 -3
- package/agents/permissions.md +17 -0
- package/dist/chunks/{PasswordCredentialService-Dec3bz4G.js → PasswordCredentialService-BjobA5uG.js} +22 -731
- package/dist/chunks/PasswordCredentialService-BjobA5uG.js.map +1 -0
- package/dist/chunks/PermissionCatalogService-DcmTn38P.js +716 -0
- package/dist/chunks/PermissionCatalogService-DcmTn38P.js.map +1 -0
- package/dist/chunks/PostgresPermissionPolicies-RzCLuARk.js +314 -0
- package/dist/chunks/PostgresPermissionPolicies-RzCLuARk.js.map +1 -0
- package/dist/chunks/{TerminalAuthService-Bf90h-rh.js → TerminalAuthService-CIdx-ed9.js} +48 -30
- package/dist/chunks/TerminalAuthService-CIdx-ed9.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +43 -289
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +1 -1
- package/dist/operator.js +1 -1
- package/dist/postgres-policies.d.ts +8 -0
- package/dist/postgres-policies.d.ts.map +1 -0
- package/dist/postgres-policies.js +2 -0
- package/dist/postgres-settings.d.ts +26 -0
- package/dist/postgres-settings.d.ts.map +1 -0
- package/dist/postgres-settings.js +18 -0
- package/dist/postgres-settings.js.map +1 -0
- package/dist/services/OAuthAuthorizationService.d.ts +27 -1
- package/dist/services/OAuthAuthorizationService.d.ts.map +1 -1
- package/dist/services/OperationPermissionService.d.ts +7 -2
- package/dist/services/OperationPermissionService.d.ts.map +1 -1
- package/dist/services/PostgresPermissionPolicies.d.ts +40 -1
- package/dist/services/PostgresPermissionPolicies.d.ts.map +1 -1
- package/dist/services/SessionPermissionContext.d.ts +2 -8
- package/dist/services/SessionPermissionContext.d.ts.map +1 -1
- package/dist/services/index.d.ts +2 -2
- package/dist/services/index.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +9 -7
- package/dist/smrt-knowledge.okf.md +4 -2
- package/dist/sveltekit/oauth-handlers.d.ts +1 -1
- package/dist/sveltekit/oauth-handlers.d.ts.map +1 -1
- package/dist/sveltekit.js +10 -4
- package/dist/sveltekit.js.map +1 -1
- package/package.json +17 -9
- package/dist/chunks/PasswordCredentialService-Dec3bz4G.js.map +0 -1
- package/dist/chunks/TerminalAuthService-Bf90h-rh.js.map +0 -1
package/dist/chunks/{PasswordCredentialService-Dec3bz4G.js → PasswordCredentialService-BjobA5uG.js}
RENAMED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { a as MembershipStatus, c as TenantPermissionEffect, l as TenantStatus, n as DEFAULT_ROLES, o as OverrideEffect, r as DEFAULT_ROLE_SLUGS, s as SessionStatus, u as UserStatus } from "./types-DqUZxluX.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { c as PermissionCollection, i as normalizeOperationPermissionAction, o as writeInSeedingBatches, s as withoutListBounds, t as PermissionCatalogService } from "./PermissionCatalogService-DcmTn38P.js";
|
|
3
|
+
import { t as registerPermissionDefinitions } from "./permission-registry-PhcdZvKe.js";
|
|
4
|
+
import { IN_LIST_CHUNK_SIZE, SmrtCollection, SmrtObject, bumpChangeFeed, chunkArray, crossPackageRef, field, foreignKey, isEmbeddedDatabase, isPostgresDatabase, smrt, withEmbeddedWriteTransaction } from "@happyvertical/smrt-core";
|
|
4
5
|
import { getCurrentTenant, runTenantHierarchyReadScope, withSystemContext } from "@happyvertical/smrt-tenancy";
|
|
5
6
|
import { AmbiguousOidcIdentityError, CanonicalPersonProfileError, OidcIdentity, OidcIdentityCollection, ProfileCollection, normalizeIdentityEmail } from "@happyvertical/smrt-profiles";
|
|
6
7
|
import { createHash, randomBytes, randomUUID, scrypt, timingSafeEqual } from "node:crypto";
|
|
@@ -9,33 +10,33 @@ import { createLogger } from "@happyvertical/logger";
|
|
|
9
10
|
import { BackfillTracker } from "@happyvertical/smrt-core/migrations";
|
|
10
11
|
import { coordinateOidcProvisioning, createOidcProvisioningPerson, insertOidcProvisioningIdentity, isOidcProvisioningRaceConflict, saveOidcRaceArbiter } from "@happyvertical/smrt-profiles/internal/oidc-provisioning";
|
|
11
12
|
//#region \0rolldown/runtime.js
|
|
12
|
-
var __defProp$
|
|
13
|
+
var __defProp$14 = Object.defineProperty;
|
|
13
14
|
var __exportAll = (all, no_symbols) => {
|
|
14
15
|
let target = {};
|
|
15
|
-
for (var name in all) __defProp$
|
|
16
|
+
for (var name in all) __defProp$14(target, name, {
|
|
16
17
|
get: all[name],
|
|
17
18
|
enumerable: true
|
|
18
19
|
});
|
|
19
|
-
if (!no_symbols) __defProp$
|
|
20
|
+
if (!no_symbols) __defProp$14(target, Symbol.toStringTag, { value: "Module" });
|
|
20
21
|
return target;
|
|
21
22
|
};
|
|
22
23
|
//#endregion
|
|
23
24
|
//#region src/models/Membership.ts
|
|
24
|
-
var __defProp$
|
|
25
|
-
var __getOwnPropDesc$
|
|
26
|
-
var __defNormalProp$
|
|
25
|
+
var __defProp$13 = Object.defineProperty;
|
|
26
|
+
var __getOwnPropDesc$13 = Object.getOwnPropertyDescriptor;
|
|
27
|
+
var __defNormalProp$13 = (obj, key, value) => key in obj ? __defProp$13(obj, key, {
|
|
27
28
|
enumerable: true,
|
|
28
29
|
configurable: true,
|
|
29
30
|
writable: true,
|
|
30
31
|
value
|
|
31
32
|
}) : obj[key] = value;
|
|
32
|
-
var __decorateClass$
|
|
33
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
33
|
+
var __decorateClass$13 = (decorators, target, key, kind) => {
|
|
34
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$13(target, key) : target;
|
|
34
35
|
for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
35
|
-
if (kind && result) __defProp$
|
|
36
|
+
if (kind && result) __defProp$13(target, key, result);
|
|
36
37
|
return result;
|
|
37
38
|
};
|
|
38
|
-
var __publicField$
|
|
39
|
+
var __publicField$13 = (obj, key, value) => __defNormalProp$13(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
39
40
|
var Membership = class extends SmrtObject {
|
|
40
41
|
userId;
|
|
41
42
|
tenantId;
|
|
@@ -63,29 +64,29 @@ var Membership = class extends SmrtObject {
|
|
|
63
64
|
return this.status === MembershipStatus.PENDING;
|
|
64
65
|
}
|
|
65
66
|
};
|
|
66
|
-
__publicField$
|
|
67
|
-
__decorateClass$
|
|
67
|
+
__publicField$13(Membership, "__smrtPackage__", "@happyvertical/smrt-users");
|
|
68
|
+
__decorateClass$13([foreignKey("User", {
|
|
68
69
|
required: true,
|
|
69
70
|
requiredFor: "identity"
|
|
70
71
|
}), field({ description: "The person who belongs to this organization." })], Membership.prototype, "userId", 2);
|
|
71
|
-
__decorateClass$
|
|
72
|
+
__decorateClass$13([foreignKey("Tenant", {
|
|
72
73
|
required: true,
|
|
73
74
|
requiredFor: "tenant-scope"
|
|
74
75
|
})], Membership.prototype, "tenantId", 2);
|
|
75
|
-
__decorateClass$
|
|
76
|
+
__decorateClass$13([foreignKey("Role", {
|
|
76
77
|
required: true,
|
|
77
78
|
requiredFor: "identity"
|
|
78
79
|
}), field({ description: "The role that determines this member's permissions." })], Membership.prototype, "roleId", 2);
|
|
79
|
-
__decorateClass$
|
|
80
|
+
__decorateClass$13([field({
|
|
80
81
|
description: "Whether this membership is active, pending, or inactive.",
|
|
81
82
|
type: "text"
|
|
82
83
|
})], Membership.prototype, "status", 2);
|
|
83
|
-
__decorateClass$
|
|
84
|
+
__decorateClass$13([field({
|
|
84
85
|
description: "When this person last switched into this organization, used to resume it at sign-in.",
|
|
85
86
|
type: "datetime",
|
|
86
87
|
nullable: true
|
|
87
88
|
})], Membership.prototype, "lastSelectedAt", 2);
|
|
88
|
-
Membership = __decorateClass$
|
|
89
|
+
Membership = __decorateClass$13([smrt({
|
|
89
90
|
api: { include: ["list", "get"] },
|
|
90
91
|
mcp: { include: ["list", "get"] },
|
|
91
92
|
cli: { include: ["list", "get"] },
|
|
@@ -95,86 +96,6 @@ Membership = __decorateClass$14([smrt({
|
|
|
95
96
|
}]
|
|
96
97
|
})], Membership);
|
|
97
98
|
//#endregion
|
|
98
|
-
//#region src/models/Permission.ts
|
|
99
|
-
var __defProp$13 = Object.defineProperty;
|
|
100
|
-
var __getOwnPropDesc$13 = Object.getOwnPropertyDescriptor;
|
|
101
|
-
var __defNormalProp$13 = (obj, key, value) => key in obj ? __defProp$13(obj, key, {
|
|
102
|
-
enumerable: true,
|
|
103
|
-
configurable: true,
|
|
104
|
-
writable: true,
|
|
105
|
-
value
|
|
106
|
-
}) : obj[key] = value;
|
|
107
|
-
var __decorateClass$13 = (decorators, target, key, kind) => {
|
|
108
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$13(target, key) : target;
|
|
109
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
110
|
-
if (kind && result) __defProp$13(target, key, result);
|
|
111
|
-
return result;
|
|
112
|
-
};
|
|
113
|
-
var __publicField$13 = (obj, key, value) => __defNormalProp$13(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
114
|
-
function parsePermissionSlug(slug) {
|
|
115
|
-
const parts = slug.split(".");
|
|
116
|
-
if (parts.length >= 2 && parts.every(Boolean)) return {
|
|
117
|
-
resource: parts[0],
|
|
118
|
-
action: parts.slice(1).join("."),
|
|
119
|
-
isValid: true
|
|
120
|
-
};
|
|
121
|
-
return {
|
|
122
|
-
resource: slug,
|
|
123
|
-
action: "",
|
|
124
|
-
isValid: false
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
function isValidPermissionSlug(slug) {
|
|
128
|
-
return parsePermissionSlug(slug).isValid;
|
|
129
|
-
}
|
|
130
|
-
var Permission = class extends SmrtObject {
|
|
131
|
-
name = "";
|
|
132
|
-
description = "";
|
|
133
|
-
category = "";
|
|
134
|
-
constructor(options = {}) {
|
|
135
|
-
super(options);
|
|
136
|
-
if (options.name !== void 0) this.name = options.name;
|
|
137
|
-
if (options.description !== void 0) this.description = options.description;
|
|
138
|
-
if (options.category !== void 0) this.category = options.category;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Parse the permission slug into resource and action components.
|
|
142
|
-
* @returns Parsed slug with resource, action, and validation status
|
|
143
|
-
*/
|
|
144
|
-
parseSlug() {
|
|
145
|
-
return parsePermissionSlug(this.slug ?? "");
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Get the resource part of the permission slug
|
|
149
|
-
* e.g., 'articles.create' -> 'articles'
|
|
150
|
-
*/
|
|
151
|
-
getResource() {
|
|
152
|
-
return this.parseSlug().resource;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Get the action part of the permission slug
|
|
156
|
-
* e.g., 'articles.create' -> 'create'
|
|
157
|
-
*/
|
|
158
|
-
getAction() {
|
|
159
|
-
return this.parseSlug().action;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Check if the permission slug is valid (follows 'resource.action' pattern)
|
|
163
|
-
*/
|
|
164
|
-
isValidSlug() {
|
|
165
|
-
return this.parseSlug().isValid;
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
__publicField$13(Permission, "__smrtPackage__", "@happyvertical/smrt-users");
|
|
169
|
-
__decorateClass$13([field({ description: "The name of an action people can be allowed to perform." })], Permission.prototype, "name", 2);
|
|
170
|
-
__decorateClass$13([field({ description: "What this permission allows someone to do." })], Permission.prototype, "description", 2);
|
|
171
|
-
__decorateClass$13([field({ description: "The area of the application this permission belongs to." })], Permission.prototype, "category", 2);
|
|
172
|
-
Permission = __decorateClass$13([smrt({
|
|
173
|
-
api: { include: ["list", "get"] },
|
|
174
|
-
mcp: { include: ["list", "get"] },
|
|
175
|
-
cli: { include: ["list", "get"] }
|
|
176
|
-
})], Permission);
|
|
177
|
-
//#endregion
|
|
178
99
|
//#region src/models/Role.ts
|
|
179
100
|
var __defProp$12 = Object.defineProperty;
|
|
180
101
|
var __getOwnPropDesc$12 = Object.getOwnPropertyDescriptor;
|
|
@@ -2163,62 +2084,6 @@ var UsersPasswordCredentialCollection = class extends SmrtCollection {
|
|
|
2163
2084
|
}
|
|
2164
2085
|
};
|
|
2165
2086
|
//#endregion
|
|
2166
|
-
//#region src/collections/PermissionCollection.ts
|
|
2167
|
-
var PermissionCollection = class extends SmrtCollection {
|
|
2168
|
-
static _itemClass = Permission;
|
|
2169
|
-
/**
|
|
2170
|
-
* Find permissions by category
|
|
2171
|
-
*/
|
|
2172
|
-
async findByCategory(category) {
|
|
2173
|
-
return await this.list({
|
|
2174
|
-
where: { category },
|
|
2175
|
-
orderBy: "slug ASC"
|
|
2176
|
-
});
|
|
2177
|
-
}
|
|
2178
|
-
/**
|
|
2179
|
-
* Find permission by slug
|
|
2180
|
-
*/
|
|
2181
|
-
async findBySlug(slug) {
|
|
2182
|
-
const results = await this.list({
|
|
2183
|
-
where: { slug },
|
|
2184
|
-
limit: 1
|
|
2185
|
-
});
|
|
2186
|
-
return results.length > 0 ? results[0] : null;
|
|
2187
|
-
}
|
|
2188
|
-
/**
|
|
2189
|
-
* Batch fetch permissions by IDs
|
|
2190
|
-
* Returns a Map of id -> Permission for efficient lookup
|
|
2191
|
-
*/
|
|
2192
|
-
async findByIds(ids) {
|
|
2193
|
-
if (ids.length === 0) return /* @__PURE__ */ new Map();
|
|
2194
|
-
const uniqueIds = [...new Set(ids)];
|
|
2195
|
-
const placeholders = uniqueIds.map(() => "?").join(", ");
|
|
2196
|
-
const results = await this.query(`SELECT * FROM ${this.tableName} WHERE id IN (${placeholders})`, uniqueIds);
|
|
2197
|
-
const map = /* @__PURE__ */ new Map();
|
|
2198
|
-
for (const perm of results) if (perm.id) map.set(perm.id, perm);
|
|
2199
|
-
return map;
|
|
2200
|
-
}
|
|
2201
|
-
/**
|
|
2202
|
-
* Get all unique categories
|
|
2203
|
-
*/
|
|
2204
|
-
async getCategories() {
|
|
2205
|
-
return (await this.query(`SELECT DISTINCT category FROM ${this.tableName} WHERE category != '' ORDER BY category ASC`)).map((r) => r.category);
|
|
2206
|
-
}
|
|
2207
|
-
/**
|
|
2208
|
-
* Find or create a permission by slug
|
|
2209
|
-
*/
|
|
2210
|
-
async findOrCreate(slug, defaults = {}) {
|
|
2211
|
-
const existing = await this.findBySlug(slug);
|
|
2212
|
-
if (existing) return existing;
|
|
2213
|
-
return await this.create({
|
|
2214
|
-
slug,
|
|
2215
|
-
name: defaults.name ?? slug,
|
|
2216
|
-
description: defaults.description ?? "",
|
|
2217
|
-
category: defaults.category ?? slug.split(".")[0]
|
|
2218
|
-
});
|
|
2219
|
-
}
|
|
2220
|
-
};
|
|
2221
|
-
//#endregion
|
|
2222
2087
|
//#region src/collections/RoleCollection.ts
|
|
2223
2088
|
var RoleCollection = class RoleCollection extends SmrtCollection {
|
|
2224
2089
|
static _itemClass = Role;
|
|
@@ -2387,580 +2252,6 @@ RolePermission = __decorateClass$2([smrt({
|
|
|
2387
2252
|
conflictColumns: ["role_id", "permission_id"]
|
|
2388
2253
|
})], RolePermission);
|
|
2389
2254
|
//#endregion
|
|
2390
|
-
//#region src/services/authorization-read-options.ts
|
|
2391
|
-
function withoutListBounds(options) {
|
|
2392
|
-
return {
|
|
2393
|
-
...options,
|
|
2394
|
-
defaultListLimit: void 0,
|
|
2395
|
-
maxListLimit: void 0
|
|
2396
|
-
};
|
|
2397
|
-
}
|
|
2398
|
-
async function writeInSeedingBatches(db, items, write) {
|
|
2399
|
-
for (let start = 0; start < items.length; start += 50) {
|
|
2400
|
-
const batch = items.slice(start, start + 50);
|
|
2401
|
-
if (typeof db.transaction !== "function") {
|
|
2402
|
-
await write(db, batch);
|
|
2403
|
-
continue;
|
|
2404
|
-
}
|
|
2405
|
-
await withEmbeddedWriteTransaction(db, isEmbeddedDatabase(db), (database) => write(database, batch), true);
|
|
2406
|
-
}
|
|
2407
|
-
}
|
|
2408
|
-
//#endregion
|
|
2409
|
-
//#region src/services/PermissionCatalogService.ts
|
|
2410
|
-
function toSnakeCase(value) {
|
|
2411
|
-
return value.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[-\s]+/g, "_").toLowerCase();
|
|
2412
|
-
}
|
|
2413
|
-
function pluralize(word) {
|
|
2414
|
-
if (word.endsWith("y") && !/[aeiou]y$/i.test(word)) return `${word.slice(0, -1)}ies`;
|
|
2415
|
-
if (word.endsWith("s") || word.endsWith("x") || word.endsWith("z") || word.endsWith("ch") || word.endsWith("sh")) return `${word}es`;
|
|
2416
|
-
return `${word}s`;
|
|
2417
|
-
}
|
|
2418
|
-
function deriveCollectionName(className) {
|
|
2419
|
-
return pluralize(toSnakeCase(className));
|
|
2420
|
-
}
|
|
2421
|
-
function humanizeResource(resource) {
|
|
2422
|
-
return resource.replace(/[._-]+/g, " ").replace(/\b\w/g, (char) => char.toUpperCase());
|
|
2423
|
-
}
|
|
2424
|
-
function capitalize(value) {
|
|
2425
|
-
return `${value[0]?.toUpperCase() ?? ""}${value.slice(1)}`;
|
|
2426
|
-
}
|
|
2427
|
-
function defaultPermissionName(slug) {
|
|
2428
|
-
const parsed = parsePermissionSlug(slug);
|
|
2429
|
-
if (!parsed.isValid) return humanizeResource(slug);
|
|
2430
|
-
return `${humanizeResource(parsed.action)} ${humanizeResource(parsed.resource)}`;
|
|
2431
|
-
}
|
|
2432
|
-
function defaultPermissionDescription(slug) {
|
|
2433
|
-
const parsed = parsePermissionSlug(slug);
|
|
2434
|
-
if (!parsed.isValid) return `Allows ${slug}`;
|
|
2435
|
-
return `Allows ${humanizeResource(parsed.action).toLowerCase()} access for ${humanizeResource(parsed.resource).toLowerCase()}`;
|
|
2436
|
-
}
|
|
2437
|
-
function normalizeOperationPermissionAction(action) {
|
|
2438
|
-
const trimmed = action.trim();
|
|
2439
|
-
const lower = trimmed.toLowerCase();
|
|
2440
|
-
if (lower === "list" || lower === "get") return "read";
|
|
2441
|
-
if (lower === "read" || lower === "create" || lower === "update" || lower === "delete") return lower;
|
|
2442
|
-
return trimmed;
|
|
2443
|
-
}
|
|
2444
|
-
function isConstructorLike(value) {
|
|
2445
|
-
return typeof value === "function";
|
|
2446
|
-
}
|
|
2447
|
-
function isCollectionLike(value) {
|
|
2448
|
-
return typeof value === "object" && value !== null && typeof value.getItemClass === "function";
|
|
2449
|
-
}
|
|
2450
|
-
function resolveConstructor(value) {
|
|
2451
|
-
if (isConstructorLike(value)) return value;
|
|
2452
|
-
if (isCollectionLike(value)) return value.getItemClass?.();
|
|
2453
|
-
if (typeof value === "object" && value !== null) {
|
|
2454
|
-
const ctor = value.constructor;
|
|
2455
|
-
if (typeof ctor === "function" && ctor.name && ctor.name !== "Object") return ctor;
|
|
2456
|
-
}
|
|
2457
|
-
}
|
|
2458
|
-
function deriveOperationPermissionCollectionName(input) {
|
|
2459
|
-
if (typeof input === "string") {
|
|
2460
|
-
const collection = input.trim();
|
|
2461
|
-
if (!collection) throw new Error("Operation permission collection must not be empty.");
|
|
2462
|
-
return collection;
|
|
2463
|
-
}
|
|
2464
|
-
const ctor = resolveConstructor(input);
|
|
2465
|
-
if (!ctor?.name) throw new Error("Operation permission collection must be a collection slug, model class, model instance, or collection instance.");
|
|
2466
|
-
const registered = ObjectRegistry.getClassByConstructor(ctor) ?? ObjectRegistry.getClass(ctor.name);
|
|
2467
|
-
if (!registered) return deriveCollectionName(ctor.name);
|
|
2468
|
-
return resolveCollectionName(registered, manifestEntryFor(registered), (target) => target.collection ?? deriveCollectionName(target.name));
|
|
2469
|
-
}
|
|
2470
|
-
function deriveOperationPermissionSlug(collection, action) {
|
|
2471
|
-
const collectionName = deriveOperationPermissionCollectionName(collection);
|
|
2472
|
-
const standard = normalizeOperationPermissionAction(action);
|
|
2473
|
-
if ([
|
|
2474
|
-
"read",
|
|
2475
|
-
"create",
|
|
2476
|
-
"update",
|
|
2477
|
-
"delete"
|
|
2478
|
-
].includes(standard)) return `${collectionName}.${standard}`;
|
|
2479
|
-
const ctor = typeof collection === "string" ? void 0 : resolveConstructor(collection);
|
|
2480
|
-
const registered = ctor ? ObjectRegistry.getClassByConstructor(ctor) ?? ObjectRegistry.getClass(ctor.name ?? "") : void 0;
|
|
2481
|
-
if (registered) {
|
|
2482
|
-
const normalizedAction2 = normalizeOperationPermissionAction(resolveOperationPermissionAlias(manifestEntryFor(registered)?.decoratorConfig ?? registered.config, action)?.action ?? action);
|
|
2483
|
-
if (!normalizedAction2) throw new Error("Operation permission action must not be empty.");
|
|
2484
|
-
return `${collectionName}.${normalizedAction2}`;
|
|
2485
|
-
}
|
|
2486
|
-
const actions = /* @__PURE__ */ new Set();
|
|
2487
|
-
for (const registered2 of new Set(ObjectRegistry.getAllClasses().values())) {
|
|
2488
|
-
const entry = manifestEntryFor(registered2);
|
|
2489
|
-
const owner = entry && isCollectionClass(registered2, entry) ? resolveCollectionItemRegistration(registered2, entry) : registered2;
|
|
2490
|
-
if (!owner || resolveCatalogCollectionName(owner, manifestEntryFor(owner)) !== collectionName) continue;
|
|
2491
|
-
const alias = resolveOperationPermissionAlias(entry?.decoratorConfig ?? registered2.config, action);
|
|
2492
|
-
if (alias) {
|
|
2493
|
-
actions.add(alias.action);
|
|
2494
|
-
continue;
|
|
2495
|
-
}
|
|
2496
|
-
if (getPublicCustomMethodNames(entry?.methods ? Object.values(entry.methods) : Array.from(registered2.methods.entries()), [
|
|
2497
|
-
"list",
|
|
2498
|
-
"get",
|
|
2499
|
-
"create",
|
|
2500
|
-
"update",
|
|
2501
|
-
"delete"
|
|
2502
|
-
]).includes(action)) actions.add(action);
|
|
2503
|
-
}
|
|
2504
|
-
if (actions.size > 1) throw new Error("Ambiguous operation permission alias");
|
|
2505
|
-
const normalizedAction = normalizeOperationPermissionAction([...actions][0] ?? action);
|
|
2506
|
-
if (!normalizedAction) throw new Error("Operation permission action must not be empty.");
|
|
2507
|
-
return `${collectionName}.${normalizedAction}`;
|
|
2508
|
-
}
|
|
2509
|
-
function manifestEntryFor(registered) {
|
|
2510
|
-
return registered.qualifiedName ? findManifestEntryByQualifiedName(registered.qualifiedName) : void 0;
|
|
2511
|
-
}
|
|
2512
|
-
function registeredStiBase(registered) {
|
|
2513
|
-
let base;
|
|
2514
|
-
for (let parent = Object.getPrototypeOf(registered.constructor); parent && parent !== Function.prototype; parent = Object.getPrototypeOf(parent)) {
|
|
2515
|
-
const ancestor = ObjectRegistry.getClassByConstructor(parent);
|
|
2516
|
-
if (ancestor?.config?.tableStrategy === "sti") base = ancestor;
|
|
2517
|
-
}
|
|
2518
|
-
return base === registered ? void 0 : base;
|
|
2519
|
-
}
|
|
2520
|
-
function resolveCollectionName(registered, manifestEntry, fallback) {
|
|
2521
|
-
const rawCollection = (manifestEntry?.decoratorConfig ?? registered.config)?.collection;
|
|
2522
|
-
if (typeof rawCollection === "string" && rawCollection.length > 0) return rawCollection;
|
|
2523
|
-
if (manifestEntry?.collection) return manifestEntry.collection;
|
|
2524
|
-
const stiBase = registeredStiBase(registered);
|
|
2525
|
-
return stiBase ? resolveCollectionName(stiBase, manifestEntryFor(stiBase), fallback) : fallback(registered);
|
|
2526
|
-
}
|
|
2527
|
-
function resolveCatalogCollectionName(registered, manifestEntry) {
|
|
2528
|
-
return resolveCollectionName(registered, manifestEntry, (target) => deriveCollectionName(target.name));
|
|
2529
|
-
}
|
|
2530
|
-
function packagePrefix(qualifiedName) {
|
|
2531
|
-
const separator = qualifiedName?.lastIndexOf(":") ?? -1;
|
|
2532
|
-
return qualifiedName && separator > 0 ? qualifiedName.slice(0, separator) : void 0;
|
|
2533
|
-
}
|
|
2534
|
-
function findCatalogClass(name, nearQualifiedName) {
|
|
2535
|
-
if (name.includes(":")) return ObjectRegistry.getClassByQualifiedName(name);
|
|
2536
|
-
const prefix = packagePrefix(nearQualifiedName);
|
|
2537
|
-
return (prefix ? ObjectRegistry.getClassByQualifiedName(`${prefix}:${name}`) : void 0) ?? ObjectRegistry.getClass(name);
|
|
2538
|
-
}
|
|
2539
|
-
function collectCatalogAncestry(registered, manifestEntry) {
|
|
2540
|
-
const chain = [];
|
|
2541
|
-
const seen = /* @__PURE__ */ new Set();
|
|
2542
|
-
let current = manifestEntry ? {
|
|
2543
|
-
entry: manifestEntry,
|
|
2544
|
-
registered
|
|
2545
|
-
} : void 0;
|
|
2546
|
-
while (current && chain.length < 32) {
|
|
2547
|
-
const key = current.registered.qualifiedName ?? current.registered.name;
|
|
2548
|
-
if (seen.has(key)) break;
|
|
2549
|
-
seen.add(key);
|
|
2550
|
-
chain.push(current);
|
|
2551
|
-
const parentName = current.entry.extendsQualified || current.entry.extends || void 0;
|
|
2552
|
-
if (!parentName || parentName === "SmrtCollection") break;
|
|
2553
|
-
const parent = findCatalogClass(parentName, current.registered.qualifiedName);
|
|
2554
|
-
const parentEntry = parent?.qualifiedName ? findManifestEntryByQualifiedName(parent.qualifiedName) : void 0;
|
|
2555
|
-
current = parent && parentEntry ? {
|
|
2556
|
-
entry: parentEntry,
|
|
2557
|
-
registered: parent
|
|
2558
|
-
} : void 0;
|
|
2559
|
-
}
|
|
2560
|
-
return chain;
|
|
2561
|
-
}
|
|
2562
|
-
function isCollectionClass(registered, manifestEntry) {
|
|
2563
|
-
return collectCatalogAncestry(registered, manifestEntry).some(({ entry }) => isCollectionManifestEntry(entry));
|
|
2564
|
-
}
|
|
2565
|
-
function resolveCollectionItemRegistration(registered, manifestEntry) {
|
|
2566
|
-
const ancestry = collectCatalogAncestry(registered, manifestEntry);
|
|
2567
|
-
for (const { entry, registered: ancestor } of ancestry) {
|
|
2568
|
-
const typeArg = entry.extendsTypeArg;
|
|
2569
|
-
if (typeof typeArg === "string" && typeArg.length > 0) return findCatalogClass(typeArg, ancestor.qualifiedName);
|
|
2570
|
-
}
|
|
2571
|
-
for (const { registered: ancestor } of ancestry) {
|
|
2572
|
-
if (!ancestor.name.endsWith("Collection")) continue;
|
|
2573
|
-
const item = findCatalogClass(ancestor.name.slice(0, -10), ancestor.qualifiedName);
|
|
2574
|
-
if (item) return item;
|
|
2575
|
-
}
|
|
2576
|
-
}
|
|
2577
|
-
function getCollectionClassActionDefinitions(registered, manifestEntry, standardActions) {
|
|
2578
|
-
if (!manifestEntry) return [];
|
|
2579
|
-
const item = resolveCollectionItemRegistration(registered, manifestEntry);
|
|
2580
|
-
if (!item) return [];
|
|
2581
|
-
const itemEntry = item.qualifiedName ? findManifestEntryByQualifiedName(item.qualifiedName) : void 0;
|
|
2582
|
-
if (isCollectionClass(item, itemEntry)) return [];
|
|
2583
|
-
const collection = resolveCatalogCollectionName(item, itemEntry);
|
|
2584
|
-
const objectConfig = manifestEntry.decoratorConfig ?? registered.config;
|
|
2585
|
-
const methodEntries = manifestEntry.methods ? Object.values(manifestEntry.methods) : Array.from(registered.methods.entries());
|
|
2586
|
-
const catalogApi = ownCollectionApiConfig(objectConfig?.api, manifestEntry, itemEntry);
|
|
2587
|
-
return getPublicCustomMethodNames(methodEntries, standardActions).filter((methodName) => isOperationEnabled(catalogApi, methodName)).map((methodName) => {
|
|
2588
|
-
const alias = resolveOperationPermissionAlias(objectConfig, methodName);
|
|
2589
|
-
const action = alias?.action ?? methodName;
|
|
2590
|
-
const definition = {
|
|
2591
|
-
className: item.name,
|
|
2592
|
-
collection,
|
|
2593
|
-
description: `Allows ${action} on ${humanizeResource(collection).toLowerCase()}`,
|
|
2594
|
-
name: `${capitalize(action)} ${humanizeResource(collection)}`,
|
|
2595
|
-
qualifiedName: item.qualifiedName,
|
|
2596
|
-
slug: `${collection}.${action}`
|
|
2597
|
-
};
|
|
2598
|
-
addAliasDatabaseBindings(definition, alias, item, itemEntry);
|
|
2599
|
-
return definition;
|
|
2600
|
-
});
|
|
2601
|
-
}
|
|
2602
|
-
function ownCollectionApiConfig(apiConfig, collectionEntry, itemEntry) {
|
|
2603
|
-
if (apiConfig === void 0 || apiConfig === false || !itemEntry) return apiConfig;
|
|
2604
|
-
const inherited = inheritedCollectionSurface("api", itemEntry.decoratorConfig ?? {}, {
|
|
2605
|
-
collection: new Set(Object.keys(collectionEntry.methods ?? {})),
|
|
2606
|
-
item: new Set(Object.keys(itemEntry.methods ?? {}))
|
|
2607
|
-
});
|
|
2608
|
-
return inherited !== void 0 && inherited !== false && JSON.stringify(inherited) === JSON.stringify(apiConfig) ? void 0 : apiConfig;
|
|
2609
|
-
}
|
|
2610
|
-
function addAliasDatabaseBindings(definition, alias, registered, manifestEntry) {
|
|
2611
|
-
if (!alias?.databaseActions?.length) return;
|
|
2612
|
-
const tableName = manifestEntry?.schema?.tableName ?? registered.schema?.tableName ?? registered.config.tableName;
|
|
2613
|
-
if (!tableName) throw new Error("Permission SQL binding requires a table name");
|
|
2614
|
-
mergeBindings(definition, {
|
|
2615
|
-
slug: definition.slug,
|
|
2616
|
-
postgres: { bindings: alias.databaseActions.map((action) => ({
|
|
2617
|
-
action,
|
|
2618
|
-
tableName,
|
|
2619
|
-
...registered.tenantScopedConfig?.field ? { tenantField: toSnakeCase(registered.tenantScopedConfig.field) } : {}
|
|
2620
|
-
})) }
|
|
2621
|
-
});
|
|
2622
|
-
}
|
|
2623
|
-
function isCollectionManifestEntry(objectDef) {
|
|
2624
|
-
return objectDef?.extends === "SmrtCollection" || objectDef?.extendsTypeArg !== void 0;
|
|
2625
|
-
}
|
|
2626
|
-
function isMethodEntryTuple(method) {
|
|
2627
|
-
return Array.isArray(method);
|
|
2628
|
-
}
|
|
2629
|
-
function normalizeMethodCandidate(method) {
|
|
2630
|
-
if (isMethodEntryTuple(method)) {
|
|
2631
|
-
const [name, definition] = method;
|
|
2632
|
-
return {
|
|
2633
|
-
...definition,
|
|
2634
|
-
name: definition.name ?? name
|
|
2635
|
-
};
|
|
2636
|
-
}
|
|
2637
|
-
return method;
|
|
2638
|
-
}
|
|
2639
|
-
function getPublicCustomMethodNames(methodEntries, standardActions) {
|
|
2640
|
-
return Array.from(new Set(methodEntries.flatMap((method) => {
|
|
2641
|
-
const { isPublic, name } = normalizeMethodCandidate(method);
|
|
2642
|
-
if (!name || isPublic !== true || standardActions.includes(name)) return [];
|
|
2643
|
-
return [name];
|
|
2644
|
-
})));
|
|
2645
|
-
}
|
|
2646
|
-
function getCustomMethodExposureNames(config, availableCustomMethods) {
|
|
2647
|
-
if (!config || config === false) return /* @__PURE__ */ new Set();
|
|
2648
|
-
if (config === true || typeof config !== "object") return new Set(availableCustomMethods);
|
|
2649
|
-
const rawInclude = config.include;
|
|
2650
|
-
const include = Array.isArray(rawInclude) ? [...rawInclude] : void 0;
|
|
2651
|
-
const rawExclude = config.exclude;
|
|
2652
|
-
const exclude = Array.isArray(rawExclude) ? [...rawExclude] : [];
|
|
2653
|
-
if (!include) return new Set(availableCustomMethods.filter((methodName) => !exclude.includes(methodName)));
|
|
2654
|
-
const baseMethods = include.filter((methodName) => availableCustomMethods.includes(methodName));
|
|
2655
|
-
return new Set(baseMethods.filter((methodName) => !exclude.includes(methodName)));
|
|
2656
|
-
}
|
|
2657
|
-
var USERS_AUTHORITY_CATALOG_MODELS = new Set([
|
|
2658
|
-
"Group",
|
|
2659
|
-
"GroupMember",
|
|
2660
|
-
"GroupRole",
|
|
2661
|
-
"Membership",
|
|
2662
|
-
"MembershipOverride",
|
|
2663
|
-
"Permission",
|
|
2664
|
-
"ResourceGrant",
|
|
2665
|
-
"Role",
|
|
2666
|
-
"RolePermission",
|
|
2667
|
-
"Session",
|
|
2668
|
-
"Tenant",
|
|
2669
|
-
"TenantIntegration",
|
|
2670
|
-
"TenantPermissionOverride",
|
|
2671
|
-
"User",
|
|
2672
|
-
"UsersMagicLinkToken"
|
|
2673
|
-
].map((className) => `@happyvertical/smrt-users:${className}`));
|
|
2674
|
-
function isOperationEnabled(config, action) {
|
|
2675
|
-
if (config === false) return false;
|
|
2676
|
-
if (config && typeof config === "object") {
|
|
2677
|
-
const include = Array.isArray(config.include) ? config.include : void 0;
|
|
2678
|
-
const rawExclude = config.exclude;
|
|
2679
|
-
const exclude = Array.isArray(rawExclude) ? [...rawExclude] : [];
|
|
2680
|
-
if (include && !include.includes(action)) return false;
|
|
2681
|
-
if (exclude.includes(action)) return false;
|
|
2682
|
-
}
|
|
2683
|
-
return true;
|
|
2684
|
-
}
|
|
2685
|
-
function normalizePostgresAction(action) {
|
|
2686
|
-
const normalized = action.toUpperCase();
|
|
2687
|
-
if (normalized === "SELECT" || normalized === "INSERT" || normalized === "UPDATE" || normalized === "DELETE") return normalized;
|
|
2688
|
-
throw new Error(`Unsupported Postgres permission action '${action}'. Expected SELECT, INSERT, UPDATE, or DELETE.`);
|
|
2689
|
-
}
|
|
2690
|
-
function normalizeBinding(binding, fallbackPermission) {
|
|
2691
|
-
return {
|
|
2692
|
-
action: normalizePostgresAction(binding.action),
|
|
2693
|
-
permission: binding.permission || fallbackPermission,
|
|
2694
|
-
schemaName: binding.schemaName,
|
|
2695
|
-
tableName: binding.tableName,
|
|
2696
|
-
tenantField: binding.tenantField
|
|
2697
|
-
};
|
|
2698
|
-
}
|
|
2699
|
-
function mergeStringField(fieldName, existing, incoming, slug) {
|
|
2700
|
-
const existingValue = existing[fieldName];
|
|
2701
|
-
const incomingValue = incoming[fieldName];
|
|
2702
|
-
if (!incomingValue) return;
|
|
2703
|
-
if (!existingValue) {
|
|
2704
|
-
existing[fieldName] = incomingValue;
|
|
2705
|
-
return;
|
|
2706
|
-
}
|
|
2707
|
-
if (existingValue !== incomingValue) throw new Error(`Conflicting permission metadata for '${slug}' field '${fieldName}': '${existingValue}' !== '${incomingValue}'`);
|
|
2708
|
-
}
|
|
2709
|
-
function mergeBindings(existing, incoming) {
|
|
2710
|
-
const existingBindings = existing.postgres?.bindings ?? [];
|
|
2711
|
-
const incomingBindings = incoming.postgres?.bindings ?? [];
|
|
2712
|
-
if (incomingBindings.length === 0) return;
|
|
2713
|
-
const seen = new Set(existingBindings.map((binding) => [
|
|
2714
|
-
binding.permission,
|
|
2715
|
-
binding.action,
|
|
2716
|
-
binding.schemaName ?? "",
|
|
2717
|
-
binding.tableName,
|
|
2718
|
-
binding.tenantField ?? ""
|
|
2719
|
-
].join("|")));
|
|
2720
|
-
const mergedBindings = [...existingBindings];
|
|
2721
|
-
for (const binding of incomingBindings) {
|
|
2722
|
-
const normalized = normalizeBinding(binding, incoming.slug);
|
|
2723
|
-
const key = [
|
|
2724
|
-
normalized.permission,
|
|
2725
|
-
normalized.action,
|
|
2726
|
-
normalized.schemaName ?? "",
|
|
2727
|
-
normalized.tableName,
|
|
2728
|
-
normalized.tenantField ?? ""
|
|
2729
|
-
].join("|");
|
|
2730
|
-
if (!seen.has(key)) {
|
|
2731
|
-
seen.add(key);
|
|
2732
|
-
mergedBindings.push(normalized);
|
|
2733
|
-
}
|
|
2734
|
-
}
|
|
2735
|
-
existing.postgres = { bindings: mergedBindings };
|
|
2736
|
-
}
|
|
2737
|
-
function normalizeDefinition(definition, source) {
|
|
2738
|
-
if (!definition.slug || !isValidPermissionSlug(definition.slug.trim())) throw new Error(`Invalid permission slug '${definition.slug}'. Expected 'resource.action[.scope...]'.`);
|
|
2739
|
-
const slug = definition.slug.trim();
|
|
2740
|
-
return {
|
|
2741
|
-
category: definition.category ?? parsePermissionSlug(slug).resource,
|
|
2742
|
-
className: definition.className,
|
|
2743
|
-
collection: definition.collection,
|
|
2744
|
-
description: definition.description ?? defaultPermissionDescription(slug),
|
|
2745
|
-
name: definition.name ?? defaultPermissionName(slug),
|
|
2746
|
-
postgres: definition.postgres?.bindings ? { bindings: definition.postgres.bindings.map((binding) => normalizeBinding(binding, slug)) } : void 0,
|
|
2747
|
-
qualifiedName: definition.qualifiedName,
|
|
2748
|
-
slug,
|
|
2749
|
-
source
|
|
2750
|
-
};
|
|
2751
|
-
}
|
|
2752
|
-
function mergeDefinitionSet(current, incomingDefinitions, source) {
|
|
2753
|
-
for (const rawDefinition of incomingDefinitions) {
|
|
2754
|
-
const definition = normalizeDefinition(rawDefinition, source);
|
|
2755
|
-
const existing = current.get(definition.slug);
|
|
2756
|
-
if (!existing) {
|
|
2757
|
-
current.set(definition.slug, definition);
|
|
2758
|
-
continue;
|
|
2759
|
-
}
|
|
2760
|
-
mergeStringField("category", existing, definition, definition.slug);
|
|
2761
|
-
mergeStringField("className", existing, definition, definition.slug);
|
|
2762
|
-
mergeStringField("collection", existing, definition, definition.slug);
|
|
2763
|
-
mergeStringField("description", existing, definition, definition.slug);
|
|
2764
|
-
mergeStringField("name", existing, definition, definition.slug);
|
|
2765
|
-
mergeStringField("qualifiedName", existing, definition, definition.slug);
|
|
2766
|
-
mergeBindings(existing, definition);
|
|
2767
|
-
}
|
|
2768
|
-
}
|
|
2769
|
-
function definitionChangesPermission(existing, definition) {
|
|
2770
|
-
return (definition.name ?? existing.name) !== existing.name || (definition.description ?? existing.description) !== existing.description || (definition.category ?? existing.category) !== existing.category;
|
|
2771
|
-
}
|
|
2772
|
-
var PermissionCatalogService = class PermissionCatalogService {
|
|
2773
|
-
constructor(options = {}) {
|
|
2774
|
-
this.options = options;
|
|
2775
|
-
}
|
|
2776
|
-
options;
|
|
2777
|
-
getUsersConfig() {
|
|
2778
|
-
return getPackageConfig("users", {});
|
|
2779
|
-
}
|
|
2780
|
-
getRuntimePermissionDefinitions() {
|
|
2781
|
-
return Array.from(getRuntimePermissionRegistrations().values()).flat();
|
|
2782
|
-
}
|
|
2783
|
-
getCustomPermissionDefinitions() {
|
|
2784
|
-
return this.getUsersConfig().permissions?.custom ?? [];
|
|
2785
|
-
}
|
|
2786
|
-
getCatalog() {
|
|
2787
|
-
const manifestPermissions = this.getManifestPermissionDefinitions();
|
|
2788
|
-
const customPermissions = this.getCustomPermissionDefinitions();
|
|
2789
|
-
const runtimePermissions = this.getRuntimePermissionDefinitions();
|
|
2790
|
-
const merged = /* @__PURE__ */ new Map();
|
|
2791
|
-
mergeDefinitionSet(merged, manifestPermissions, "manifest");
|
|
2792
|
-
mergeDefinitionSet(merged, customPermissions, "config");
|
|
2793
|
-
mergeDefinitionSet(merged, runtimePermissions, "runtime");
|
|
2794
|
-
return {
|
|
2795
|
-
customPermissions: customPermissions.map((definition) => normalizeDefinition(definition, "config")),
|
|
2796
|
-
manifestPermissions: manifestPermissions.map((definition) => normalizeDefinition(definition, "manifest")),
|
|
2797
|
-
permissions: Array.from(merged.values()).sort((left, right) => left.slug.localeCompare(right.slug)),
|
|
2798
|
-
runtimePermissions: runtimePermissions.map((definition) => normalizeDefinition(definition, "runtime"))
|
|
2799
|
-
};
|
|
2800
|
-
}
|
|
2801
|
-
deriveOperationPermissionSlug(collection, action) {
|
|
2802
|
-
return deriveOperationPermissionSlug(collection, action);
|
|
2803
|
-
}
|
|
2804
|
-
hasPermissionSlug(slug) {
|
|
2805
|
-
return this.getCatalog().permissions.some((permission) => permission.slug === slug);
|
|
2806
|
-
}
|
|
2807
|
-
async syncPermissionCatalog() {
|
|
2808
|
-
const catalog = this.getCatalog();
|
|
2809
|
-
const permissions = await PermissionCollection.create(withoutListBounds(this.options));
|
|
2810
|
-
const created = [];
|
|
2811
|
-
const unchanged = [];
|
|
2812
|
-
const updated = [];
|
|
2813
|
-
const existingBySlug = /* @__PURE__ */ new Map();
|
|
2814
|
-
for (const permission of await permissions.list({})) if (typeof permission.slug === "string" && permission.slug.length > 0) existingBySlug.set(permission.slug, permission);
|
|
2815
|
-
const pending = catalog.permissions.filter((definition) => {
|
|
2816
|
-
const existing = existingBySlug.get(definition.slug);
|
|
2817
|
-
if (existing && !definitionChangesPermission(existing, definition)) {
|
|
2818
|
-
unchanged.push(definition.slug);
|
|
2819
|
-
return false;
|
|
2820
|
-
}
|
|
2821
|
-
return true;
|
|
2822
|
-
});
|
|
2823
|
-
await writeInSeedingBatches(permissions.db, pending, async (database, batch) => {
|
|
2824
|
-
const batchPermissions = await PermissionCollection.create({
|
|
2825
|
-
...this.options,
|
|
2826
|
-
db: database
|
|
2827
|
-
});
|
|
2828
|
-
for (const definition of batch) {
|
|
2829
|
-
const existing = existingBySlug.get(definition.slug) ?? null;
|
|
2830
|
-
if (!existing) {
|
|
2831
|
-
const permission = await batchPermissions.create({
|
|
2832
|
-
category: definition.category ?? parsePermissionSlug(definition.slug).resource,
|
|
2833
|
-
description: definition.description ?? "",
|
|
2834
|
-
name: definition.name ?? definition.slug,
|
|
2835
|
-
slug: definition.slug
|
|
2836
|
-
});
|
|
2837
|
-
existingBySlug.set(definition.slug, permission);
|
|
2838
|
-
created.push(definition.slug);
|
|
2839
|
-
continue;
|
|
2840
|
-
}
|
|
2841
|
-
if (!definitionChangesPermission(existing, definition)) {
|
|
2842
|
-
unchanged.push(definition.slug);
|
|
2843
|
-
continue;
|
|
2844
|
-
}
|
|
2845
|
-
existing.name = definition.name ?? existing.name;
|
|
2846
|
-
existing.description = definition.description ?? existing.description;
|
|
2847
|
-
existing.category = definition.category ?? existing.category;
|
|
2848
|
-
await existing.withDatabase(database, (row) => row.save());
|
|
2849
|
-
updated.push(definition.slug);
|
|
2850
|
-
}
|
|
2851
|
-
});
|
|
2852
|
-
return {
|
|
2853
|
-
catalog,
|
|
2854
|
-
created,
|
|
2855
|
-
unchanged,
|
|
2856
|
-
updated
|
|
2857
|
-
};
|
|
2858
|
-
}
|
|
2859
|
-
getManifestPermissionDefinitions() {
|
|
2860
|
-
const standardActions = [
|
|
2861
|
-
"list",
|
|
2862
|
-
"get",
|
|
2863
|
-
"create",
|
|
2864
|
-
"update",
|
|
2865
|
-
"delete"
|
|
2866
|
-
];
|
|
2867
|
-
const definitions = /* @__PURE__ */ new Map();
|
|
2868
|
-
const seenRegistrations = /* @__PURE__ */ new Set();
|
|
2869
|
-
for (const [, registered] of ObjectRegistry.getAllClasses()) {
|
|
2870
|
-
if (seenRegistrations.has(registered)) continue;
|
|
2871
|
-
seenRegistrations.add(registered);
|
|
2872
|
-
const manifestEntry = registered?.qualifiedName ? findManifestEntryByQualifiedName(registered.qualifiedName) : void 0;
|
|
2873
|
-
if (isCollectionClass(registered, manifestEntry)) {
|
|
2874
|
-
for (const definition of getCollectionClassActionDefinitions(registered, manifestEntry, standardActions)) {
|
|
2875
|
-
const existing = definitions.get(definition.slug);
|
|
2876
|
-
if (existing) mergeBindings(existing, definition);
|
|
2877
|
-
else definitions.set(definition.slug, definition);
|
|
2878
|
-
}
|
|
2879
|
-
continue;
|
|
2880
|
-
}
|
|
2881
|
-
const className = registered.name;
|
|
2882
|
-
const qualifiedName = registered.qualifiedName;
|
|
2883
|
-
const objectConfig = manifestEntry?.decoratorConfig ?? registered.config;
|
|
2884
|
-
const collection = resolveCatalogCollectionName(registered, manifestEntry);
|
|
2885
|
-
const registryKey = qualifiedName ?? className;
|
|
2886
|
-
const ownsCrud = !ObjectRegistry.getSTIBase(registryKey) || !ObjectRegistry.getInheritanceChain(registryKey).some((ancestor) => {
|
|
2887
|
-
const parent = ObjectRegistry.getClass(ancestor);
|
|
2888
|
-
return parent && parent !== registered && resolveCatalogCollectionName(parent, manifestEntryFor(parent)) === collection;
|
|
2889
|
-
});
|
|
2890
|
-
const catalogCliConfig = qualifiedName && USERS_AUTHORITY_CATALOG_MODELS.has(qualifiedName) ? true : objectConfig.cli;
|
|
2891
|
-
const readExposed = isOperationEnabled(objectConfig.api, "list") || isOperationEnabled(objectConfig.api, "get") || isOperationEnabled(catalogCliConfig, "list") || isOperationEnabled(catalogCliConfig, "get") || isOperationEnabled(objectConfig.mcp, "list") || isOperationEnabled(objectConfig.mcp, "get");
|
|
2892
|
-
if (ownsCrud && readExposed) definitions.set(`${collection}.read`, {
|
|
2893
|
-
...definitions.get(`${collection}.read`),
|
|
2894
|
-
className,
|
|
2895
|
-
collection,
|
|
2896
|
-
qualifiedName,
|
|
2897
|
-
slug: `${collection}.read`
|
|
2898
|
-
});
|
|
2899
|
-
const fieldEntries = manifestEntry?.fields ? Object.entries(manifestEntry.fields) : Array.from((registered.inheritedFields ?? registered.fields).entries());
|
|
2900
|
-
for (const [fieldName, fieldDef] of fieldEntries) {
|
|
2901
|
-
const field = fieldDef;
|
|
2902
|
-
const readPermission = typeof field.readPermission === "string" ? field.readPermission : typeof field._meta?.readPermission === "string" ? field._meta.readPermission : void 0;
|
|
2903
|
-
if (!readPermission || definitions.has(readPermission)) continue;
|
|
2904
|
-
definitions.set(readPermission, {
|
|
2905
|
-
className,
|
|
2906
|
-
collection,
|
|
2907
|
-
description: `Allows reading ${fieldName} on ${humanizeResource(collection).toLowerCase()}`,
|
|
2908
|
-
name: `Read ${humanizeResource(fieldName)} on ${humanizeResource(collection)}`,
|
|
2909
|
-
qualifiedName,
|
|
2910
|
-
slug: readPermission
|
|
2911
|
-
});
|
|
2912
|
-
}
|
|
2913
|
-
for (const action of [
|
|
2914
|
-
"create",
|
|
2915
|
-
"update",
|
|
2916
|
-
"delete"
|
|
2917
|
-
]) {
|
|
2918
|
-
const exposed = isOperationEnabled(objectConfig.api, action) || isOperationEnabled(catalogCliConfig, action) || isOperationEnabled(objectConfig.mcp, action);
|
|
2919
|
-
if (!ownsCrud || !exposed) continue;
|
|
2920
|
-
definitions.set(`${collection}.${action}`, {
|
|
2921
|
-
...definitions.get(`${collection}.${action}`),
|
|
2922
|
-
className,
|
|
2923
|
-
collection,
|
|
2924
|
-
qualifiedName,
|
|
2925
|
-
slug: `${collection}.${action}`
|
|
2926
|
-
});
|
|
2927
|
-
}
|
|
2928
|
-
const publicCustomMethodNames = getPublicCustomMethodNames(manifestEntry?.methods ? Object.values(manifestEntry.methods) : Array.from(registered.methods.entries()), standardActions);
|
|
2929
|
-
const customApiMethods = /* @__PURE__ */ new Set();
|
|
2930
|
-
const customCliMethods = getCustomMethodExposureNames(catalogCliConfig, publicCustomMethodNames);
|
|
2931
|
-
const customMcpMethods = getCustomMethodExposureNames(objectConfig.mcp, publicCustomMethodNames);
|
|
2932
|
-
for (const methodName of publicCustomMethodNames) if (isOperationEnabled(objectConfig.api, methodName)) customApiMethods.add(methodName);
|
|
2933
|
-
const customMethods = /* @__PURE__ */ new Set([
|
|
2934
|
-
...customApiMethods,
|
|
2935
|
-
...customCliMethods,
|
|
2936
|
-
...customMcpMethods
|
|
2937
|
-
]);
|
|
2938
|
-
for (const methodName of customMethods) {
|
|
2939
|
-
const alias = resolveOperationPermissionAlias(objectConfig, methodName);
|
|
2940
|
-
const permissionAction = alias?.action ?? methodName;
|
|
2941
|
-
const slug = `${collection}.${permissionAction}`;
|
|
2942
|
-
const definition = definitions.get(slug) ?? {
|
|
2943
|
-
className,
|
|
2944
|
-
collection,
|
|
2945
|
-
qualifiedName,
|
|
2946
|
-
slug,
|
|
2947
|
-
description: `Allows ${permissionAction} on ${humanizeResource(collection).toLowerCase()}`,
|
|
2948
|
-
name: `${capitalize(permissionAction)} ${humanizeResource(collection)}`
|
|
2949
|
-
};
|
|
2950
|
-
addAliasDatabaseBindings(definition, alias, registered, manifestEntry);
|
|
2951
|
-
definitions.set(slug, definition);
|
|
2952
|
-
}
|
|
2953
|
-
}
|
|
2954
|
-
return Array.from(definitions.values()).sort((left, right) => left.slug.localeCompare(right.slug));
|
|
2955
|
-
}
|
|
2956
|
-
static create(options = {}) {
|
|
2957
|
-
return new PermissionCatalogService(options);
|
|
2958
|
-
}
|
|
2959
|
-
};
|
|
2960
|
-
async function syncPermissionCatalog(options = {}) {
|
|
2961
|
-
return PermissionCatalogService.create(options).syncPermissionCatalog();
|
|
2962
|
-
}
|
|
2963
|
-
//#endregion
|
|
2964
2255
|
//#region src/collections/RolePermissionCollection.ts
|
|
2965
2256
|
var RolePermissionCollection_exports = /* @__PURE__ */ __exportAll({
|
|
2966
2257
|
DEFAULT_ROLE_PERMISSION_PATTERNS: () => DEFAULT_ROLE_PERMISSION_PATTERNS,
|
|
@@ -6563,6 +5854,6 @@ var PasswordCredentialService = class PasswordCredentialService {
|
|
|
6563
5854
|
}
|
|
6564
5855
|
};
|
|
6565
5856
|
//#endregion
|
|
6566
|
-
export {
|
|
5857
|
+
export { RolePermission as $, InvalidCredentialsError as A, Role as At, backfillUserEmailKeys as B, DEFAULT_LOGIN_ATTEMPT_WINDOW_SECONDS as C, normalizeEmail as Ct, DEFAULT_LOGIN_MAX_ATTEMPTS as D, STEP_UP_SIGN_IN_AUTH_METHODS as Dt, DEFAULT_LOGIN_LOCKOUT_MAX_SECONDS as E, SESSION_DATA_KEYS as Et, OidcProvisioningError as F, MAX_TENANT_HIERARCHY_DEPTH as G, TenantPermissionOverride as H, UserCollection as I, assertTenantTableName as J, TenantHierarchyError as K, requireExistingOwnedPerson as L, LoginRateLimitError as M, __exportAll as Mt, hashSecret as N, DEFAULT_SOURCE_LOCKOUT_AUDIT_SECONDS as O, Session as Ot, verifySecretHash as P, RolePermissionCollection as Q, USER_EMAIL_KEY_BACKFILL_NAME as R, normalizeAncestorReadPolicy as S, isValidEmail as St, DEFAULT_LOGIN_LOCKOUT_FACTOR as T, DEFAULT_SESSION_TTL as Tt, TenantCollection as U, TenantPermissionOverrideCollection as V, Tenant as W, recordTenantHierarchyChanges as X, planTenantHierarchy as Y, DEFAULT_ROLE_PERMISSION_PATTERNS as Z, PermissionResolver as _, isSessionlessPrincipalUser as _t, DEFAULT_PASSWORD_RECOVERY_MAX_AGE_SECONDS as a, MembershipCollection as at, getConfiguredAncestorReadPolicy as b, User as bt, PASSWORD_PERMISSION_DEFINITIONS as c, GroupMemberCollection as ct, PasswordCredentialForbiddenError as d, Group as dt, RoleCollection as et, PasswordCredentialService as f, UsersLoginAuditEventCollection as ft, SessionService as g, SessionCollection as gt, outOfBandProofSessionData as h, UsersLoginAttempt as ht, DEFAULT_PASSWORD_MIN_LENGTH as i, MembershipOverride as it, LoginAttemptLimiter as j, Membership as jt, DurableLoginAuditSink as k, generateSessionId as kt, PASSWORD_RECOVERY_MAX_AGE_CEILING_SECONDS as l, GroupMember as lt, ensurePasswordPermissionsRegistered as m, UsersLoginAttemptCollection as mt, DEFAULT_PASSWORD_MANAGE_PERMISSION as n, UsersPasswordCredential as nt, PASSWORD_LOGIN_KIND as o, GroupRoleCollection as ot, PasswordPolicyError as p, UsersLoginAuditEvent as pt, applyTenantHierarchyUpdates as q, DEFAULT_PASSWORD_MAX_LENGTH as r, MembershipOverrideCollection as rt, PASSWORD_MAX_LENGTH_CEILING as s, GroupRole as st, DEFAULT_PASSWORD_DENYLIST as t, UsersPasswordCredentialCollection as tt, PasswordCredentialError as u, GroupCollection as ut, ANCESTOR_READ_ACTION as v, SERVICE_PRINCIPAL_KIND as vt, DEFAULT_LOGIN_LOCKOUT_BASE_SECONDS as w, normalizeUsername as wt, isAncestorReadableSlug as x, isServicePrincipalKind as xt, DEFAULT_ANCESTOR_READ_MAX_DEPTH as y, ServicePrincipalError as yt, UserEmailKeyBackfillError as z };
|
|
6567
5858
|
|
|
6568
|
-
//# sourceMappingURL=PasswordCredentialService-
|
|
5859
|
+
//# sourceMappingURL=PasswordCredentialService-BjobA5uG.js.map
|