@objectstack/plugin-approvals 13.0.0 → 14.5.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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @objectstack/plugin-approvals@13.0.0 build /home/runner/work/framework/framework/packages/plugins/plugin-approvals
2
+ > @objectstack/plugin-approvals@14.5.0 build /home/runner/work/framework/framework/packages/plugins/plugin-approvals
3
3
  > tsup --config ../../../tsup.config.ts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -10,13 +10,13 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  CJS Build start
13
- ESM dist/index.mjs 120.30 KB
14
- ESM dist/index.mjs.map 215.93 KB
15
- ESM ⚡️ Build success in 318ms
16
- CJS dist/index.js 121.97 KB
17
- CJS dist/index.js.map 217.13 KB
18
- CJS ⚡️ Build success in 321ms
13
+ CJS dist/index.js 123.99 KB
14
+ CJS dist/index.js.map 220.47 KB
15
+ CJS ⚡️ Build success in 267ms
16
+ ESM dist/index.mjs 122.33 KB
17
+ ESM dist/index.mjs.map 219.27 KB
18
+ ESM ⚡️ Build success in 274ms
19
19
  DTS Build start
20
- DTS ⚡️ Build success in 17165ms
21
- DTS dist/index.d.mts 381.76 KB
22
- DTS dist/index.d.ts 381.76 KB
20
+ DTS ⚡️ Build success in 25609ms
21
+ DTS dist/index.d.mts 384.81 KB
22
+ DTS dist/index.d.ts 384.81 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,135 @@
1
1
  # @objectstack/plugin-approvals
2
2
 
3
+ ## 14.5.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [526805e]
8
+ - Updated dependencies [d79ca07]
9
+ - Updated dependencies [33ebd34]
10
+ - Updated dependencies [c044f08]
11
+ - Updated dependencies [01274eb]
12
+ - Updated dependencies [8f23746]
13
+ - Updated dependencies [b97af7e]
14
+ - Updated dependencies [6da03ee]
15
+ - @objectstack/spec@14.5.0
16
+ - @objectstack/platform-objects@14.5.0
17
+ - @objectstack/core@14.5.0
18
+ - @objectstack/formula@14.5.0
19
+ - @objectstack/metadata-core@14.5.0
20
+
21
+ ## 14.4.0
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [7953832]
26
+ - Updated dependencies [82e745e]
27
+ - Updated dependencies [f3035bd]
28
+ - Updated dependencies [82c0d94]
29
+ - Updated dependencies [7449476]
30
+ - @objectstack/spec@14.4.0
31
+ - @objectstack/platform-objects@14.4.0
32
+ - @objectstack/metadata-core@14.4.0
33
+ - @objectstack/core@14.4.0
34
+ - @objectstack/formula@14.4.0
35
+
36
+ ## 14.3.0
37
+
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies [2a71f48]
41
+ - Updated dependencies [02f6af4]
42
+ - Updated dependencies [c1064f1]
43
+ - @objectstack/platform-objects@14.3.0
44
+ - @objectstack/spec@14.3.0
45
+ - @objectstack/core@14.3.0
46
+ - @objectstack/formula@14.3.0
47
+ - @objectstack/metadata-core@14.3.0
48
+
49
+ ## 14.2.0
50
+
51
+ ### Patch Changes
52
+
53
+ - Updated dependencies [ac8f029]
54
+ - Updated dependencies [4ab9958]
55
+ - @objectstack/spec@14.2.0
56
+ - @objectstack/platform-objects@14.2.0
57
+ - @objectstack/core@14.2.0
58
+ - @objectstack/formula@14.2.0
59
+ - @objectstack/metadata-core@14.2.0
60
+
61
+ ## 14.1.0
62
+
63
+ ### Minor Changes
64
+
65
+ - 5a8465f: SLA escalation `escalateTo` is position-first (ADR-0090 D3 follow-up to the `position` approver type).
66
+
67
+ - **spec**: `ApprovalEscalationSchema.escalateTo` is documented as a position machine name or a
68
+ specific user id (was "User id, role, or manager level" — the same pre-D3 'role' trap the
69
+ `position` approver type fixed); the Studio xRef picker kind moves `role` → `position`.
70
+ - **plugin-approvals**: on escalation, `escalateTo` now expands position holders via
71
+ `sys_user_position` ∪ the `sys_member.role` transition source (ADR-0057 D4) for both the
72
+ `reassign` approver hand-off and the `notify` audience. An empty expansion falls back to
73
+ treating the value as a literal user id, so configs naming a specific user keep working
74
+ unchanged. The audit trail keeps the authored target.
75
+ - **lint**: new `approval-escalation-reassign-no-target` warning — `escalation.action: 'reassign'`
76
+ with no `escalateTo` silently degrades to a notify at runtime; the fix-it prescribes a position
77
+ or user id target (or `action: 'notify'`).
78
+
79
+ ### Patch Changes
80
+
81
+ - Updated dependencies [5a8465f]
82
+ - Updated dependencies [7f8620b]
83
+ - Updated dependencies [82ba3a6]
84
+ - @objectstack/spec@14.1.0
85
+ - @objectstack/core@14.1.0
86
+ - @objectstack/formula@14.1.0
87
+ - @objectstack/metadata-core@14.1.0
88
+ - @objectstack/platform-objects@14.1.0
89
+
90
+ ## 14.0.0
91
+
92
+ ### Minor Changes
93
+
94
+ - 216fa9a: Add a `position` approver type so approvals can route to org positions (ADR-0090 D3 fallout).
95
+
96
+ Post ADR-0090 D3 the `role` approver type resolves against the better-auth org-membership
97
+ tier (`sys_member.role`: `owner`/`admin`/`member`) — it was never a position. Downstream
98
+ apps that authored `{ type: 'role', value: 'sales_manager' }` silently routed approvals to
99
+ nobody. Now:
100
+
101
+ - **spec**: `ApproverType` gains `'position'` — `value` is the position machine name; the
102
+ approver expands to its holders via `sys_user_position`. Authoring guidance: keep
103
+ `type: 'role'` ONLY for membership tiers; for org positions use
104
+ `{ type: 'position', value: '<position_name>' }` (one-line fix for the mismatch above).
105
+ - **plugin-approvals**: the engine resolves `position` approvers via `sys_user_position` ∪
106
+ the `sys_member.role` transition source (same semantics as `PositionGraphService` in
107
+ plugin-sharing). The `department` approver type is now honored by its spec spelling
108
+ (previously only the off-spec `business_unit`/`bu` dialect matched).
109
+ - **lint**: new `validateApprovalApprovers` rule — `approval-role-not-membership-tier`
110
+ warns when a `role` approver's value is not a membership tier and prescribes the
111
+ `position` rewrite; `approval-approver-type-unknown` flags off-spec approver types
112
+ (with a `business_unit` → `department` fix-it). Wired into `os lint`.
113
+
114
+ ### Patch Changes
115
+
116
+ - Updated dependencies [0a8e685]
117
+ - Updated dependencies [afa8115]
118
+ - Updated dependencies [80f12ca]
119
+ - Updated dependencies [332b711]
120
+ - Updated dependencies [e2fa074]
121
+ - Updated dependencies [23c8668]
122
+ - Updated dependencies [29f017d]
123
+ - Updated dependencies [216fa9a]
124
+ - Updated dependencies [6c22b12]
125
+ - Updated dependencies [d0531c4]
126
+ - Updated dependencies [cff5aac]
127
+ - @objectstack/spec@14.0.0
128
+ - @objectstack/platform-objects@14.0.0
129
+ - @objectstack/core@14.0.0
130
+ - @objectstack/formula@14.0.0
131
+ - @objectstack/metadata-core@14.0.0
132
+
3
133
  ## 13.0.0
4
134
 
5
135
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -337,6 +337,30 @@ declare const SysApprovalRequest: Omit<{
337
337
  versionField: string;
338
338
  retentionDays?: number | undefined;
339
339
  } | undefined;
340
+ lifecycle?: {
341
+ class: "audit" | "record" | "telemetry" | "transient" | "event";
342
+ retention?: {
343
+ maxAge: string;
344
+ onlyWhen?: Record<string, string | number | boolean | {
345
+ $in: (string | number)[];
346
+ }> | undefined;
347
+ } | undefined;
348
+ ttl?: {
349
+ field: string;
350
+ expireAfter: string;
351
+ } | undefined;
352
+ storage?: {
353
+ strategy: "rotation";
354
+ shards: number;
355
+ unit: "day" | "week" | "month";
356
+ } | undefined;
357
+ archive?: {
358
+ after: string;
359
+ to: string;
360
+ keep?: string | undefined;
361
+ } | undefined;
362
+ reclaim?: boolean | undefined;
363
+ } | undefined;
340
364
  validations?: _objectstack_spec_data.BaseValidationRuleShape[] | undefined;
341
365
  activityMilestones?: {
342
366
  field: string;
@@ -494,7 +518,7 @@ declare const SysApprovalRequest: Omit<{
494
518
  timeline?: {
495
519
  startDateField: string;
496
520
  titleField: string;
497
- scale: "hour" | "day" | "week" | "month" | "quarter" | "year";
521
+ scale: "day" | "week" | "month" | "hour" | "quarter" | "year";
498
522
  endDateField?: string | undefined;
499
523
  groupByField?: string | undefined;
500
524
  colorField?: string | undefined;
@@ -4530,6 +4554,30 @@ declare const SysApprovalAction: Omit<{
4530
4554
  versionField: string;
4531
4555
  retentionDays?: number | undefined;
4532
4556
  } | undefined;
4557
+ lifecycle?: {
4558
+ class: "audit" | "record" | "telemetry" | "transient" | "event";
4559
+ retention?: {
4560
+ maxAge: string;
4561
+ onlyWhen?: Record<string, string | number | boolean | {
4562
+ $in: (string | number)[];
4563
+ }> | undefined;
4564
+ } | undefined;
4565
+ ttl?: {
4566
+ field: string;
4567
+ expireAfter: string;
4568
+ } | undefined;
4569
+ storage?: {
4570
+ strategy: "rotation";
4571
+ shards: number;
4572
+ unit: "day" | "week" | "month";
4573
+ } | undefined;
4574
+ archive?: {
4575
+ after: string;
4576
+ to: string;
4577
+ keep?: string | undefined;
4578
+ } | undefined;
4579
+ reclaim?: boolean | undefined;
4580
+ } | undefined;
4533
4581
  validations?: _objectstack_spec_data.BaseValidationRuleShape[] | undefined;
4534
4582
  activityMilestones?: {
4535
4583
  field: string;
@@ -4687,7 +4735,7 @@ declare const SysApprovalAction: Omit<{
4687
4735
  timeline?: {
4688
4736
  startDateField: string;
4689
4737
  titleField: string;
4690
- scale: "hour" | "day" | "week" | "month" | "quarter" | "year";
4738
+ scale: "day" | "week" | "month" | "hour" | "quarter" | "year";
4691
4739
  endDateField?: string | undefined;
4692
4740
  groupByField?: string | undefined;
4693
4741
  colorField?: string | undefined;
@@ -7057,6 +7105,30 @@ declare const SysApprovalApprover: Omit<{
7057
7105
  versionField: string;
7058
7106
  retentionDays?: number | undefined;
7059
7107
  } | undefined;
7108
+ lifecycle?: {
7109
+ class: "audit" | "record" | "telemetry" | "transient" | "event";
7110
+ retention?: {
7111
+ maxAge: string;
7112
+ onlyWhen?: Record<string, string | number | boolean | {
7113
+ $in: (string | number)[];
7114
+ }> | undefined;
7115
+ } | undefined;
7116
+ ttl?: {
7117
+ field: string;
7118
+ expireAfter: string;
7119
+ } | undefined;
7120
+ storage?: {
7121
+ strategy: "rotation";
7122
+ shards: number;
7123
+ unit: "day" | "week" | "month";
7124
+ } | undefined;
7125
+ archive?: {
7126
+ after: string;
7127
+ to: string;
7128
+ keep?: string | undefined;
7129
+ } | undefined;
7130
+ reclaim?: boolean | undefined;
7131
+ } | undefined;
7060
7132
  validations?: _objectstack_spec_data.BaseValidationRuleShape[] | undefined;
7061
7133
  activityMilestones?: {
7062
7134
  field: string;
@@ -7214,7 +7286,7 @@ declare const SysApprovalApprover: Omit<{
7214
7286
  timeline?: {
7215
7287
  startDateField: string;
7216
7288
  titleField: string;
7217
- scale: "hour" | "day" | "week" | "month" | "quarter" | "year";
7289
+ scale: "day" | "week" | "month" | "hour" | "quarter" | "year";
7218
7290
  endDateField?: string | undefined;
7219
7291
  groupByField?: string | undefined;
7220
7292
  colorField?: string | undefined;
@@ -8460,8 +8532,8 @@ declare const SysApprovalApprover: Omit<{
8460
8532
  * `approve` / `reject` edge.
8461
8533
  *
8462
8534
  * This service owns the durable approval *state* — `sys_approval_request` /
8463
- * `sys_approval_action`, approver resolution (team / department / role /
8464
- * manager graph), and the optional status-field mirror — plus the decision
8535
+ * `sys_approval_action`, approver resolution (team / department / position /
8536
+ * role / manager graph), and the optional status-field mirror — plus the decision
8465
8537
  * API. It does not author processes, submit, or walk multi-step machinery
8466
8538
  * anymore; that orchestration lives on the one automation engine.
8467
8539
  */
@@ -8566,16 +8638,20 @@ declare class ApprovalService implements IApprovalService {
8566
8638
  private loadPendingRow;
8567
8639
  /**
8568
8640
  * Expand the approvers on an Approval node into user IDs by querying the
8569
- * graph tables for `team:` / `department:` / `role:` / `manager:` approver
8570
- * types. Falls back to a prefixed literal (`type:value`) when graph lookups
8571
- * produce nothing — so existing fixtures and flows that rely on substring
8572
- * matching keep working.
8641
+ * graph tables for `team:` / `department:` / `position:` / `role:` /
8642
+ * `manager:` approver types. Falls back to a prefixed literal
8643
+ * (`type:value`) when graph lookups produce nothing — so existing fixtures
8644
+ * and flows that rely on substring matching keep working.
8573
8645
  *
8574
8646
  * **Graph semantics:**
8575
8647
  * - `team` → flat members of `sys_team` (better-auth; no BFS)
8576
8648
  * - `department` → recursive BFS of `sys_business_unit.parent_business_unit_id`
8577
8649
  * → members of every descendant via `sys_business_unit_member`
8578
- * - `role` users with `sys_member.role = value` in tenant
8650
+ * - `position` holders via `sys_user_position` ∪ `sys_member.role`
8651
+ * transition source (ADR-0090 D3 / ADR-0057 D4)
8652
+ * - `role` → users with `sys_member.role = value` in tenant — the
8653
+ * better-auth MEMBERSHIP TIER (owner/admin/member), not a
8654
+ * position; author `position` for org positions
8579
8655
  * - `manager` → `sys_user.manager_id` of `record[value] ?? record.owner_id`
8580
8656
  * - `field` → literal user id stored in `record[value]`
8581
8657
  * - `user` → literal value
@@ -8585,6 +8661,16 @@ declare class ApprovalService implements IApprovalService {
8585
8661
  private expandTeamUsers;
8586
8662
  /** Recursive department — walks `sys_business_unit.parent_business_unit_id`. */
8587
8663
  private expandBusinessUnitUsers;
8664
+ /**
8665
+ * Position holders (ADR-0090 D3): `sys_user_position` is the platform-owned
8666
+ * assignment table, keyed by the position's machine name (ADR-0057 D4),
8667
+ * unioned with the better-auth membership string (`sys_member.role`) as a
8668
+ * transition source — the same semantics as `PositionGraphService` in
8669
+ * `plugin-sharing`, so an approval routes to exactly the users the sharing
8670
+ * engine would expand for the same position.
8671
+ */
8672
+ private expandPositionUsers;
8673
+ /** better-auth org-membership tier (`sys_member.role`) — NOT positions. */
8588
8674
  private expandRoleUsers;
8589
8675
  private lookupManager;
8590
8676
  /** Mirror a request status onto a business-object field, if configured. */
package/dist/index.d.ts CHANGED
@@ -337,6 +337,30 @@ declare const SysApprovalRequest: Omit<{
337
337
  versionField: string;
338
338
  retentionDays?: number | undefined;
339
339
  } | undefined;
340
+ lifecycle?: {
341
+ class: "audit" | "record" | "telemetry" | "transient" | "event";
342
+ retention?: {
343
+ maxAge: string;
344
+ onlyWhen?: Record<string, string | number | boolean | {
345
+ $in: (string | number)[];
346
+ }> | undefined;
347
+ } | undefined;
348
+ ttl?: {
349
+ field: string;
350
+ expireAfter: string;
351
+ } | undefined;
352
+ storage?: {
353
+ strategy: "rotation";
354
+ shards: number;
355
+ unit: "day" | "week" | "month";
356
+ } | undefined;
357
+ archive?: {
358
+ after: string;
359
+ to: string;
360
+ keep?: string | undefined;
361
+ } | undefined;
362
+ reclaim?: boolean | undefined;
363
+ } | undefined;
340
364
  validations?: _objectstack_spec_data.BaseValidationRuleShape[] | undefined;
341
365
  activityMilestones?: {
342
366
  field: string;
@@ -494,7 +518,7 @@ declare const SysApprovalRequest: Omit<{
494
518
  timeline?: {
495
519
  startDateField: string;
496
520
  titleField: string;
497
- scale: "hour" | "day" | "week" | "month" | "quarter" | "year";
521
+ scale: "day" | "week" | "month" | "hour" | "quarter" | "year";
498
522
  endDateField?: string | undefined;
499
523
  groupByField?: string | undefined;
500
524
  colorField?: string | undefined;
@@ -4530,6 +4554,30 @@ declare const SysApprovalAction: Omit<{
4530
4554
  versionField: string;
4531
4555
  retentionDays?: number | undefined;
4532
4556
  } | undefined;
4557
+ lifecycle?: {
4558
+ class: "audit" | "record" | "telemetry" | "transient" | "event";
4559
+ retention?: {
4560
+ maxAge: string;
4561
+ onlyWhen?: Record<string, string | number | boolean | {
4562
+ $in: (string | number)[];
4563
+ }> | undefined;
4564
+ } | undefined;
4565
+ ttl?: {
4566
+ field: string;
4567
+ expireAfter: string;
4568
+ } | undefined;
4569
+ storage?: {
4570
+ strategy: "rotation";
4571
+ shards: number;
4572
+ unit: "day" | "week" | "month";
4573
+ } | undefined;
4574
+ archive?: {
4575
+ after: string;
4576
+ to: string;
4577
+ keep?: string | undefined;
4578
+ } | undefined;
4579
+ reclaim?: boolean | undefined;
4580
+ } | undefined;
4533
4581
  validations?: _objectstack_spec_data.BaseValidationRuleShape[] | undefined;
4534
4582
  activityMilestones?: {
4535
4583
  field: string;
@@ -4687,7 +4735,7 @@ declare const SysApprovalAction: Omit<{
4687
4735
  timeline?: {
4688
4736
  startDateField: string;
4689
4737
  titleField: string;
4690
- scale: "hour" | "day" | "week" | "month" | "quarter" | "year";
4738
+ scale: "day" | "week" | "month" | "hour" | "quarter" | "year";
4691
4739
  endDateField?: string | undefined;
4692
4740
  groupByField?: string | undefined;
4693
4741
  colorField?: string | undefined;
@@ -7057,6 +7105,30 @@ declare const SysApprovalApprover: Omit<{
7057
7105
  versionField: string;
7058
7106
  retentionDays?: number | undefined;
7059
7107
  } | undefined;
7108
+ lifecycle?: {
7109
+ class: "audit" | "record" | "telemetry" | "transient" | "event";
7110
+ retention?: {
7111
+ maxAge: string;
7112
+ onlyWhen?: Record<string, string | number | boolean | {
7113
+ $in: (string | number)[];
7114
+ }> | undefined;
7115
+ } | undefined;
7116
+ ttl?: {
7117
+ field: string;
7118
+ expireAfter: string;
7119
+ } | undefined;
7120
+ storage?: {
7121
+ strategy: "rotation";
7122
+ shards: number;
7123
+ unit: "day" | "week" | "month";
7124
+ } | undefined;
7125
+ archive?: {
7126
+ after: string;
7127
+ to: string;
7128
+ keep?: string | undefined;
7129
+ } | undefined;
7130
+ reclaim?: boolean | undefined;
7131
+ } | undefined;
7060
7132
  validations?: _objectstack_spec_data.BaseValidationRuleShape[] | undefined;
7061
7133
  activityMilestones?: {
7062
7134
  field: string;
@@ -7214,7 +7286,7 @@ declare const SysApprovalApprover: Omit<{
7214
7286
  timeline?: {
7215
7287
  startDateField: string;
7216
7288
  titleField: string;
7217
- scale: "hour" | "day" | "week" | "month" | "quarter" | "year";
7289
+ scale: "day" | "week" | "month" | "hour" | "quarter" | "year";
7218
7290
  endDateField?: string | undefined;
7219
7291
  groupByField?: string | undefined;
7220
7292
  colorField?: string | undefined;
@@ -8460,8 +8532,8 @@ declare const SysApprovalApprover: Omit<{
8460
8532
  * `approve` / `reject` edge.
8461
8533
  *
8462
8534
  * This service owns the durable approval *state* — `sys_approval_request` /
8463
- * `sys_approval_action`, approver resolution (team / department / role /
8464
- * manager graph), and the optional status-field mirror — plus the decision
8535
+ * `sys_approval_action`, approver resolution (team / department / position /
8536
+ * role / manager graph), and the optional status-field mirror — plus the decision
8465
8537
  * API. It does not author processes, submit, or walk multi-step machinery
8466
8538
  * anymore; that orchestration lives on the one automation engine.
8467
8539
  */
@@ -8566,16 +8638,20 @@ declare class ApprovalService implements IApprovalService {
8566
8638
  private loadPendingRow;
8567
8639
  /**
8568
8640
  * Expand the approvers on an Approval node into user IDs by querying the
8569
- * graph tables for `team:` / `department:` / `role:` / `manager:` approver
8570
- * types. Falls back to a prefixed literal (`type:value`) when graph lookups
8571
- * produce nothing — so existing fixtures and flows that rely on substring
8572
- * matching keep working.
8641
+ * graph tables for `team:` / `department:` / `position:` / `role:` /
8642
+ * `manager:` approver types. Falls back to a prefixed literal
8643
+ * (`type:value`) when graph lookups produce nothing — so existing fixtures
8644
+ * and flows that rely on substring matching keep working.
8573
8645
  *
8574
8646
  * **Graph semantics:**
8575
8647
  * - `team` → flat members of `sys_team` (better-auth; no BFS)
8576
8648
  * - `department` → recursive BFS of `sys_business_unit.parent_business_unit_id`
8577
8649
  * → members of every descendant via `sys_business_unit_member`
8578
- * - `role` users with `sys_member.role = value` in tenant
8650
+ * - `position` holders via `sys_user_position` ∪ `sys_member.role`
8651
+ * transition source (ADR-0090 D3 / ADR-0057 D4)
8652
+ * - `role` → users with `sys_member.role = value` in tenant — the
8653
+ * better-auth MEMBERSHIP TIER (owner/admin/member), not a
8654
+ * position; author `position` for org positions
8579
8655
  * - `manager` → `sys_user.manager_id` of `record[value] ?? record.owner_id`
8580
8656
  * - `field` → literal user id stored in `record[value]`
8581
8657
  * - `user` → literal value
@@ -8585,6 +8661,16 @@ declare class ApprovalService implements IApprovalService {
8585
8661
  private expandTeamUsers;
8586
8662
  /** Recursive department — walks `sys_business_unit.parent_business_unit_id`. */
8587
8663
  private expandBusinessUnitUsers;
8664
+ /**
8665
+ * Position holders (ADR-0090 D3): `sys_user_position` is the platform-owned
8666
+ * assignment table, keyed by the position's machine name (ADR-0057 D4),
8667
+ * unioned with the better-auth membership string (`sys_member.role`) as a
8668
+ * transition source — the same semantics as `PositionGraphService` in
8669
+ * `plugin-sharing`, so an approval routes to exactly the users the sharing
8670
+ * engine would expand for the same position.
8671
+ */
8672
+ private expandPositionUsers;
8673
+ /** better-auth org-membership tier (`sys_member.role`) — NOT positions. */
8588
8674
  private expandRoleUsers;
8589
8675
  private lookupManager;
8590
8676
  /** Mirror a request status onto a business-object field, if configured. */
package/dist/index.js CHANGED
@@ -1152,16 +1152,20 @@ var _ApprovalService = class _ApprovalService {
1152
1152
  }
1153
1153
  /**
1154
1154
  * Expand the approvers on an Approval node into user IDs by querying the
1155
- * graph tables for `team:` / `department:` / `role:` / `manager:` approver
1156
- * types. Falls back to a prefixed literal (`type:value`) when graph lookups
1157
- * produce nothing — so existing fixtures and flows that rely on substring
1158
- * matching keep working.
1155
+ * graph tables for `team:` / `department:` / `position:` / `role:` /
1156
+ * `manager:` approver types. Falls back to a prefixed literal
1157
+ * (`type:value`) when graph lookups produce nothing — so existing fixtures
1158
+ * and flows that rely on substring matching keep working.
1159
1159
  *
1160
1160
  * **Graph semantics:**
1161
1161
  * - `team` → flat members of `sys_team` (better-auth; no BFS)
1162
1162
  * - `department` → recursive BFS of `sys_business_unit.parent_business_unit_id`
1163
1163
  * → members of every descendant via `sys_business_unit_member`
1164
- * - `role` users with `sys_member.role = value` in tenant
1164
+ * - `position` holders via `sys_user_position` ∪ `sys_member.role`
1165
+ * transition source (ADR-0090 D3 / ADR-0057 D4)
1166
+ * - `role` → users with `sys_member.role = value` in tenant — the
1167
+ * better-auth MEMBERSHIP TIER (owner/admin/member), not a
1168
+ * position; author `position` for org positions
1165
1169
  * - `manager` → `sys_user.manager_id` of `record[value] ?? record.owner_id`
1166
1170
  * - `field` → literal user id stored in `record[value]`
1167
1171
  * - `user` → literal value
@@ -1186,12 +1190,18 @@ var _ApprovalService = class _ApprovalService {
1186
1190
  for (const u of users) out.push(u);
1187
1191
  continue;
1188
1192
  }
1189
- } else if (a.type === "business_unit" || a.type === "bu") {
1193
+ } else if (a.type === "department" || a.type === "business_unit" || a.type === "bu") {
1190
1194
  const users = await this.expandBusinessUnitUsers(String(a.value), organizationId);
1191
1195
  if (users.length) {
1192
1196
  for (const u of users) out.push(u);
1193
1197
  continue;
1194
1198
  }
1199
+ } else if (a.type === "position") {
1200
+ const users = await this.expandPositionUsers(String(a.value), organizationId);
1201
+ if (users.length) {
1202
+ for (const u of users) out.push(u);
1203
+ continue;
1204
+ }
1195
1205
  } else if (a.type === "role") {
1196
1206
  const users = await this.expandRoleUsers(String(a.value), organizationId);
1197
1207
  if (users.length) {
@@ -1278,6 +1288,36 @@ var _ApprovalService = class _ApprovalService {
1278
1288
  }
1279
1289
  return Array.from(new Set((rows ?? []).map((r) => String(r.user_id ?? "")).filter(Boolean)));
1280
1290
  }
1291
+ /**
1292
+ * Position holders (ADR-0090 D3): `sys_user_position` is the platform-owned
1293
+ * assignment table, keyed by the position's machine name (ADR-0057 D4),
1294
+ * unioned with the better-auth membership string (`sys_member.role`) as a
1295
+ * transition source — the same semantics as `PositionGraphService` in
1296
+ * `plugin-sharing`, so an approval routes to exactly the users the sharing
1297
+ * engine would expand for the same position.
1298
+ */
1299
+ async expandPositionUsers(positionName, organizationId) {
1300
+ if (!positionName) return [];
1301
+ const users = /* @__PURE__ */ new Set();
1302
+ const filter = { position: positionName };
1303
+ if (organizationId) filter.organization_id = organizationId;
1304
+ try {
1305
+ const rows = await this.engine.find("sys_user_position", {
1306
+ filter,
1307
+ fields: ["user_id"],
1308
+ limit: 1e4,
1309
+ context: SYSTEM_CTX
1310
+ });
1311
+ for (const r of rows ?? []) {
1312
+ const uid2 = String(r.user_id ?? "");
1313
+ if (uid2) users.add(uid2);
1314
+ }
1315
+ } catch {
1316
+ }
1317
+ for (const uid2 of await this.expandRoleUsers(positionName, organizationId)) users.add(uid2);
1318
+ return Array.from(users);
1319
+ }
1320
+ /** better-auth org-membership tier (`sys_member.role`) — NOT positions. */
1281
1321
  async expandRoleUsers(roleName, organizationId) {
1282
1322
  if (!roleName) return [];
1283
1323
  const filter = { role: roleName };
@@ -2199,6 +2239,15 @@ var _ApprovalService = class _ApprovalService {
2199
2239
  const escalateTo = typeof esc2.escalateTo === "string" && esc2.escalateTo.trim() ? esc2.escalateTo.trim() : void 0;
2200
2240
  const now = this.clock.now().toISOString();
2201
2241
  const pending = csvSplit(raw.pending_approvers);
2242
+ let escalatees = [];
2243
+ if (escalateTo) {
2244
+ try {
2245
+ escalatees = await this.expandPositionUsers(escalateTo, raw.organization_id ?? null);
2246
+ } catch {
2247
+ escalatees = [];
2248
+ }
2249
+ if (!escalatees.length) escalatees = [escalateTo];
2250
+ }
2202
2251
  await this.engine.insert("sys_approval_action", {
2203
2252
  id: uid("aact"),
2204
2253
  request_id: raw.id,
@@ -2210,16 +2259,16 @@ var _ApprovalService = class _ApprovalService {
2210
2259
  comment: `${action}${escalateTo ? ` \u2192 ${escalateTo}` : ""}`,
2211
2260
  created_at: now
2212
2261
  }, { context: SYSTEM_CTX });
2213
- if (action === "reassign" && escalateTo) {
2262
+ if (action === "reassign" && escalatees.length) {
2214
2263
  await this.engine.update("sys_approval_request", {
2215
2264
  id: raw.id,
2216
- pending_approvers: escalateTo,
2265
+ pending_approvers: escalatees.join(","),
2217
2266
  updated_at: now
2218
2267
  }, { context: SYSTEM_CTX });
2219
- await this.syncApproverIndex(raw.id, [escalateTo], raw.organization_id ?? null, now);
2268
+ await this.syncApproverIndex(raw.id, escalatees, raw.organization_id ?? null, now);
2220
2269
  await this.notify({
2221
2270
  topic: "approval.escalated",
2222
- audience: [escalateTo],
2271
+ audience: escalatees,
2223
2272
  actorId: SLA_ACTOR_ID,
2224
2273
  source: { object: "sys_approval_request", id: raw.id },
2225
2274
  payload: {
@@ -2237,7 +2286,7 @@ var _ApprovalService = class _ApprovalService {
2237
2286
  } else {
2238
2287
  await this.notify({
2239
2288
  topic: "approval.sla_breached",
2240
- audience: [...pending, ...escalateTo ? [escalateTo] : []],
2289
+ audience: [...pending, ...escalatees],
2241
2290
  actorId: SLA_ACTOR_ID,
2242
2291
  source: { object: "sys_approval_request", id: raw.id },
2243
2292
  payload: {