@objectstack/plugin-approvals 9.11.0 → 10.0.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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +52 -0
- package/dist/index.d.mts +702 -10
- package/dist/index.d.ts +702 -10
- package/dist/index.js +15 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/src/approval-service.ts +16 -16
package/dist/index.mjs
CHANGED
|
@@ -1131,8 +1131,8 @@ var _ApprovalService = class _ApprovalService {
|
|
|
1131
1131
|
*
|
|
1132
1132
|
* **Graph semantics:**
|
|
1133
1133
|
* - `team` → flat members of `sys_team` (better-auth; no BFS)
|
|
1134
|
-
* - `department` → recursive BFS of `
|
|
1135
|
-
* → members of every descendant via `
|
|
1134
|
+
* - `department` → recursive BFS of `sys_business_unit.parent_business_unit_id`
|
|
1135
|
+
* → members of every descendant via `sys_business_unit_member`
|
|
1136
1136
|
* - `role` → users with `sys_member.role = value` in tenant
|
|
1137
1137
|
* - `manager` → `sys_user.manager_id` of `record[value] ?? record.owner_id`
|
|
1138
1138
|
* - `field` → literal user id stored in `record[value]`
|
|
@@ -1158,8 +1158,8 @@ var _ApprovalService = class _ApprovalService {
|
|
|
1158
1158
|
for (const u of users) out.push(u);
|
|
1159
1159
|
continue;
|
|
1160
1160
|
}
|
|
1161
|
-
} else if (a.type === "
|
|
1162
|
-
const users = await this.
|
|
1161
|
+
} else if (a.type === "business_unit" || a.type === "bu") {
|
|
1162
|
+
const users = await this.expandBusinessUnitUsers(String(a.value), organizationId);
|
|
1163
1163
|
if (users.length) {
|
|
1164
1164
|
for (const u of users) out.push(u);
|
|
1165
1165
|
continue;
|
|
@@ -1202,12 +1202,12 @@ var _ApprovalService = class _ApprovalService {
|
|
|
1202
1202
|
}
|
|
1203
1203
|
return Array.from(new Set((rows ?? []).map((r) => String(r.user_id ?? "")).filter(Boolean)));
|
|
1204
1204
|
}
|
|
1205
|
-
/** Recursive department — walks `
|
|
1206
|
-
async
|
|
1207
|
-
if (!
|
|
1205
|
+
/** Recursive department — walks `sys_business_unit.parent_business_unit_id`. */
|
|
1206
|
+
async expandBusinessUnitUsers(businessUnitId, organizationId) {
|
|
1207
|
+
if (!businessUnitId) return [];
|
|
1208
1208
|
try {
|
|
1209
|
-
const seed = await this.engine.find("
|
|
1210
|
-
filter: organizationId ? { id:
|
|
1209
|
+
const seed = await this.engine.find("sys_business_unit", {
|
|
1210
|
+
filter: organizationId ? { id: businessUnitId, organization_id: organizationId } : { id: businessUnitId },
|
|
1211
1211
|
fields: ["id", "active"],
|
|
1212
1212
|
limit: 1,
|
|
1213
1213
|
context: SYSTEM_CTX
|
|
@@ -1217,15 +1217,15 @@ var _ApprovalService = class _ApprovalService {
|
|
|
1217
1217
|
} catch {
|
|
1218
1218
|
return [];
|
|
1219
1219
|
}
|
|
1220
|
-
const seen = /* @__PURE__ */ new Set([
|
|
1221
|
-
const queue = [
|
|
1220
|
+
const seen = /* @__PURE__ */ new Set([businessUnitId]);
|
|
1221
|
+
const queue = [businessUnitId];
|
|
1222
1222
|
while (queue.length) {
|
|
1223
1223
|
const parent = queue.shift();
|
|
1224
1224
|
let kids = [];
|
|
1225
1225
|
try {
|
|
1226
|
-
const filter = {
|
|
1226
|
+
const filter = { parent_business_unit_id: parent, active: { $ne: false } };
|
|
1227
1227
|
if (organizationId) filter.organization_id = organizationId;
|
|
1228
|
-
kids = await this.engine.find("
|
|
1228
|
+
kids = await this.engine.find("sys_business_unit", { filter, fields: ["id"], limit: 1e3, context: SYSTEM_CTX });
|
|
1229
1229
|
} catch {
|
|
1230
1230
|
kids = [];
|
|
1231
1231
|
}
|
|
@@ -1239,8 +1239,8 @@ var _ApprovalService = class _ApprovalService {
|
|
|
1239
1239
|
}
|
|
1240
1240
|
let rows = [];
|
|
1241
1241
|
try {
|
|
1242
|
-
rows = await this.engine.find("
|
|
1243
|
-
filter: {
|
|
1242
|
+
rows = await this.engine.find("sys_business_unit_member", {
|
|
1243
|
+
filter: { business_unit_id: { $in: Array.from(seen) } },
|
|
1244
1244
|
fields: ["user_id"],
|
|
1245
1245
|
limit: 1e4,
|
|
1246
1246
|
context: SYSTEM_CTX
|