@objectstack/plugin-approvals 9.11.0 → 10.2.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 +75 -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.js
CHANGED
|
@@ -1153,8 +1153,8 @@ var _ApprovalService = class _ApprovalService {
|
|
|
1153
1153
|
*
|
|
1154
1154
|
* **Graph semantics:**
|
|
1155
1155
|
* - `team` → flat members of `sys_team` (better-auth; no BFS)
|
|
1156
|
-
* - `department` → recursive BFS of `
|
|
1157
|
-
* → members of every descendant via `
|
|
1156
|
+
* - `department` → recursive BFS of `sys_business_unit.parent_business_unit_id`
|
|
1157
|
+
* → members of every descendant via `sys_business_unit_member`
|
|
1158
1158
|
* - `role` → users with `sys_member.role = value` in tenant
|
|
1159
1159
|
* - `manager` → `sys_user.manager_id` of `record[value] ?? record.owner_id`
|
|
1160
1160
|
* - `field` → literal user id stored in `record[value]`
|
|
@@ -1180,8 +1180,8 @@ var _ApprovalService = class _ApprovalService {
|
|
|
1180
1180
|
for (const u of users) out.push(u);
|
|
1181
1181
|
continue;
|
|
1182
1182
|
}
|
|
1183
|
-
} else if (a.type === "
|
|
1184
|
-
const users = await this.
|
|
1183
|
+
} else if (a.type === "business_unit" || a.type === "bu") {
|
|
1184
|
+
const users = await this.expandBusinessUnitUsers(String(a.value), organizationId);
|
|
1185
1185
|
if (users.length) {
|
|
1186
1186
|
for (const u of users) out.push(u);
|
|
1187
1187
|
continue;
|
|
@@ -1224,12 +1224,12 @@ var _ApprovalService = class _ApprovalService {
|
|
|
1224
1224
|
}
|
|
1225
1225
|
return Array.from(new Set((rows ?? []).map((r) => String(r.user_id ?? "")).filter(Boolean)));
|
|
1226
1226
|
}
|
|
1227
|
-
/** Recursive department — walks `
|
|
1228
|
-
async
|
|
1229
|
-
if (!
|
|
1227
|
+
/** Recursive department — walks `sys_business_unit.parent_business_unit_id`. */
|
|
1228
|
+
async expandBusinessUnitUsers(businessUnitId, organizationId) {
|
|
1229
|
+
if (!businessUnitId) return [];
|
|
1230
1230
|
try {
|
|
1231
|
-
const seed = await this.engine.find("
|
|
1232
|
-
filter: organizationId ? { id:
|
|
1231
|
+
const seed = await this.engine.find("sys_business_unit", {
|
|
1232
|
+
filter: organizationId ? { id: businessUnitId, organization_id: organizationId } : { id: businessUnitId },
|
|
1233
1233
|
fields: ["id", "active"],
|
|
1234
1234
|
limit: 1,
|
|
1235
1235
|
context: SYSTEM_CTX
|
|
@@ -1239,15 +1239,15 @@ var _ApprovalService = class _ApprovalService {
|
|
|
1239
1239
|
} catch {
|
|
1240
1240
|
return [];
|
|
1241
1241
|
}
|
|
1242
|
-
const seen = /* @__PURE__ */ new Set([
|
|
1243
|
-
const queue = [
|
|
1242
|
+
const seen = /* @__PURE__ */ new Set([businessUnitId]);
|
|
1243
|
+
const queue = [businessUnitId];
|
|
1244
1244
|
while (queue.length) {
|
|
1245
1245
|
const parent = queue.shift();
|
|
1246
1246
|
let kids = [];
|
|
1247
1247
|
try {
|
|
1248
|
-
const filter = {
|
|
1248
|
+
const filter = { parent_business_unit_id: parent, active: { $ne: false } };
|
|
1249
1249
|
if (organizationId) filter.organization_id = organizationId;
|
|
1250
|
-
kids = await this.engine.find("
|
|
1250
|
+
kids = await this.engine.find("sys_business_unit", { filter, fields: ["id"], limit: 1e3, context: SYSTEM_CTX });
|
|
1251
1251
|
} catch {
|
|
1252
1252
|
kids = [];
|
|
1253
1253
|
}
|
|
@@ -1261,8 +1261,8 @@ var _ApprovalService = class _ApprovalService {
|
|
|
1261
1261
|
}
|
|
1262
1262
|
let rows = [];
|
|
1263
1263
|
try {
|
|
1264
|
-
rows = await this.engine.find("
|
|
1265
|
-
filter: {
|
|
1264
|
+
rows = await this.engine.find("sys_business_unit_member", {
|
|
1265
|
+
filter: { business_unit_id: { $in: Array.from(seen) } },
|
|
1266
1266
|
fields: ["user_id"],
|
|
1267
1267
|
limit: 1e4,
|
|
1268
1268
|
context: SYSTEM_CTX
|