hierarchical-approval 3.0.0 → 3.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/{ApprovalEngine-CCOwhMrs.d.ts → ApprovalEngine-Cslh4Goz.d.ts} +6 -6
  3. package/dist/{ApprovalEngine-Bfs5BnMm.d.cts → ApprovalEngine-zAgvH_aO.d.cts} +6 -6
  4. package/dist/{IAuditAdapter-DxdK4UVt.d.cts → IAuditAdapter-BkxGx6TI.d.cts} +1 -1
  5. package/dist/{IAuditAdapter-B33n15YP.d.ts → IAuditAdapter-udkAnnmu.d.ts} +1 -1
  6. package/dist/{IAuthorizationPolicy-BzGVzkLJ.d.cts → IAuthorizationPolicy-YQlSwj-8.d.cts} +1 -1
  7. package/dist/{IAuthorizationPolicy-DOm6KCwI.d.ts → IAuthorizationPolicy-Z4nkX-bu.d.ts} +1 -1
  8. package/dist/{INotificationAdapter-DMvA4R-c.d.ts → INotificationAdapter-C-PL3Pvp.d.ts} +1 -1
  9. package/dist/{INotificationAdapter-DFKvGpOp.d.cts → INotificationAdapter-D3PBQE1B.d.cts} +1 -1
  10. package/dist/{IOperationMiddleware-Nk8Q1Z8o.d.ts → IOperationMiddleware-Cbd05rje.d.ts} +1 -1
  11. package/dist/{IOperationMiddleware-C8i06wq4.d.cts → IOperationMiddleware-tgJcKzTP.d.cts} +1 -1
  12. package/dist/{IStorageAdapter-C2QxUwbX.d.ts → IStorageAdapter-CEKfu-U8.d.ts} +1 -1
  13. package/dist/{IStorageAdapter-C0qeZgs4.d.cts → IStorageAdapter-DUrmnJUs.d.cts} +1 -1
  14. package/dist/adapters/MemoryAdapter.cjs +3 -3
  15. package/dist/adapters/MemoryAdapter.cjs.map +1 -1
  16. package/dist/adapters/MemoryAdapter.d.cts +2 -2
  17. package/dist/adapters/MemoryAdapter.d.ts +2 -2
  18. package/dist/adapters/MemoryAdapter.js +3 -3
  19. package/dist/adapters/MemoryAdapter.js.map +1 -1
  20. package/dist/adapters/PostgresAdapter.cjs +18 -0
  21. package/dist/adapters/PostgresAdapter.cjs.map +1 -1
  22. package/dist/adapters/PostgresAdapter.d.cts +2 -2
  23. package/dist/adapters/PostgresAdapter.d.ts +2 -2
  24. package/dist/adapters/PostgresAdapter.js +18 -0
  25. package/dist/adapters/PostgresAdapter.js.map +1 -1
  26. package/dist/index.cjs +6 -3
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +8 -8
  29. package/dist/index.d.ts +8 -8
  30. package/dist/index.js +6 -3
  31. package/dist/index.js.map +1 -1
  32. package/dist/{instance-BvOyT00S.d.cts → instance-BXHxvTLE.d.cts} +10 -0
  33. package/dist/{instance-BvOyT00S.d.ts → instance-BXHxvTLE.d.ts} +10 -0
  34. package/dist/nestjs.cjs +6 -3
  35. package/dist/nestjs.cjs.map +1 -1
  36. package/dist/nestjs.d.cts +7 -7
  37. package/dist/nestjs.d.ts +7 -7
  38. package/dist/nestjs.js +6 -3
  39. package/dist/nestjs.js.map +1 -1
  40. package/dist/plugins/audit.d.cts +2 -2
  41. package/dist/plugins/audit.d.ts +2 -2
  42. package/dist/plugins/notify.d.cts +2 -2
  43. package/dist/plugins/notify.d.ts +2 -2
  44. package/dist/plugins/resilience.d.cts +3 -3
  45. package/dist/plugins/resilience.d.ts +3 -3
  46. package/dist/plugins/tracing.d.cts +2 -2
  47. package/dist/plugins/tracing.d.ts +2 -2
  48. package/dist/plugins/webhook.d.cts +2 -2
  49. package/dist/plugins/webhook.d.ts +2 -2
  50. package/dist/testing.cjs +6 -3
  51. package/dist/testing.cjs.map +1 -1
  52. package/dist/testing.d.cts +7 -7
  53. package/dist/testing.d.ts +7 -7
  54. package/dist/testing.js +6 -3
  55. package/dist/testing.js.map +1 -1
  56. package/package.json +1 -1
package/dist/index.d.cts CHANGED
@@ -1,18 +1,18 @@
1
- export { A as AddCommentOptions, a as ApprovalEngine, b as ApprovalEngineOptions, c as ApprovalStatistics, d as ApproveOptions, e as ApproverResolverFn, f as ApproverWorkload, B as BulkResult, g as BusinessCalendar, h as BusinessHoursCalendarOptions, C as CanApproveResult, i as CancelOptions, j as ChainExplanation, k as ConditionOperatorFn, l as CycleTimeStats, D as DelegateOptions, E as EscalateOptions, m as ExplainedLevel, n as ExplainedRule, o as ExplainedSkip, H as HealthResult, I as IdGeneratorFn, p as IdempotencyKeyFn, q as ImportResult, O as OrgProvider, r as OutOfOfficeProvider, s as OverrideOptions, P as PreviewChainLevel, t as PreviewResult, u as ProvideInfoOptions, v as PurgeResult, R as ReassignOptions, w as RejectOptions, x as RequestInfoOptions, y as ResubmitOptions, z as RetryPolicy, S as SimulatedDecision, F as SimulationResult, G as SimulationStep, J as SubmitOptions, T as TEMPLATE_BUNDLE_VERSION, K as TemplateBundle, L as TransferResult, U as UpdateDataOptions, V as ValidationResult, W as WeekendCalendarOptions, M as businessHoursCalendar, N as defaultIdGenerator, Q as toComparableNumber, X as validateConditionExpression, Y as weekendCalendar } from './ApprovalEngine-Bfs5BnMm.cjs';
2
- import { I as IStorageAdapter } from './IStorageAdapter-C0qeZgs4.cjs';
3
- export { c as CursorPaginatedResult, C as CursorPaginationOpts, b as InstanceFilter, a as PaginatedResult, P as PaginationOpts } from './IStorageAdapter-C0qeZgs4.cjs';
1
+ export { A as AddCommentOptions, a as ApprovalEngine, b as ApprovalEngineOptions, c as ApprovalStatistics, d as ApproveOptions, e as ApproverResolverFn, f as ApproverWorkload, B as BulkResult, g as BusinessCalendar, h as BusinessHoursCalendarOptions, C as CanApproveResult, i as CancelOptions, j as ChainExplanation, k as ConditionOperatorFn, l as CycleTimeStats, D as DelegateOptions, E as EscalateOptions, m as ExplainedLevel, n as ExplainedRule, o as ExplainedSkip, H as HealthResult, I as IdGeneratorFn, p as IdempotencyKeyFn, q as ImportResult, O as OrgProvider, r as OutOfOfficeProvider, s as OverrideOptions, P as PreviewChainLevel, t as PreviewResult, u as ProvideInfoOptions, v as PurgeResult, R as ReassignOptions, w as RejectOptions, x as RequestInfoOptions, y as ResubmitOptions, z as RetryPolicy, S as SimulatedDecision, F as SimulationResult, G as SimulationStep, J as SubmitOptions, T as TEMPLATE_BUNDLE_VERSION, K as TemplateBundle, L as TransferResult, U as UpdateDataOptions, V as ValidationResult, W as WeekendCalendarOptions, M as businessHoursCalendar, N as defaultIdGenerator, Q as toComparableNumber, X as validateConditionExpression, Y as weekendCalendar } from './ApprovalEngine-zAgvH_aO.cjs';
2
+ import { I as IStorageAdapter } from './IStorageAdapter-DUrmnJUs.cjs';
3
+ export { c as CursorPaginatedResult, C as CursorPaginationOpts, b as InstanceFilter, a as PaginatedResult, P as PaginationOpts } from './IStorageAdapter-DUrmnJUs.cjs';
4
4
  import { L as Logger } from './Logger-BplhlU7l.cjs';
5
5
  export { n as noopLogger } from './Logger-BplhlU7l.cjs';
6
6
  import { C as Clock } from './Clock-3FnOczFJ.cjs';
7
7
  export { s as systemClock } from './Clock-3FnOczFJ.cjs';
8
- export { A as AuthorizationContext, I as IAuthorizationPolicy } from './IAuthorizationPolicy-BzGVzkLJ.cjs';
9
- export { A as ApprovalConflictError, a as ApprovalError, b as ApprovalForbiddenError, c as ApprovalNotFoundError, d as ApprovalTemplateNotFoundError, e as ApprovalValidationError, I as IOperationMiddleware, O as OperationContext } from './IOperationMiddleware-C8i06wq4.cjs';
8
+ export { A as AuthorizationContext, I as IAuthorizationPolicy } from './IAuthorizationPolicy-YQlSwj-8.cjs';
9
+ export { A as ApprovalConflictError, a as ApprovalError, b as ApprovalForbiddenError, c as ApprovalNotFoundError, d as ApprovalTemplateNotFoundError, e as ApprovalValidationError, I as IOperationMiddleware, O as OperationContext } from './IOperationMiddleware-tgJcKzTP.cjs';
10
10
  export { MemoryAdapter } from './adapters/MemoryAdapter.cjs';
11
- export { A as ApprovalEvent, a as ApprovalEventMap, b as ApprovalEventName, c as ApprovedEvent, d as AttachmentEvent, C as CancelledEvent, e as CommentedEvent, D as DataUpdatedEvent, f as DelegatedEvent, E as EscalatedEvent, g as ExpiredEvent, H as HistoryEntry, I as INotificationAdapter, h as InfoProvidedEvent, i as InfoRequestedEvent, L as LevelAdvancedEvent, N as NotificationEvent, O as OverriddenEvent, R as ReassignedEvent, j as RejectedEvent, k as ReminderEvent, l as ResubmittedEvent, S as SlaBreachedEvent, m as SubWorkflowEvent, n as SubmittedEvent } from './INotificationAdapter-DFKvGpOp.cjs';
12
- export { I as IAuditAdapter } from './IAuditAdapter-DxdK4UVt.cjs';
11
+ export { A as ApprovalEvent, a as ApprovalEventMap, b as ApprovalEventName, c as ApprovedEvent, d as AttachmentEvent, C as CancelledEvent, e as CommentedEvent, D as DataUpdatedEvent, f as DelegatedEvent, E as EscalatedEvent, g as ExpiredEvent, H as HistoryEntry, I as INotificationAdapter, h as InfoProvidedEvent, i as InfoRequestedEvent, L as LevelAdvancedEvent, N as NotificationEvent, O as OverriddenEvent, R as ReassignedEvent, j as RejectedEvent, k as ReminderEvent, l as ResubmittedEvent, S as SlaBreachedEvent, m as SubWorkflowEvent, n as SubmittedEvent } from './INotificationAdapter-D3PBQE1B.cjs';
12
+ export { I as IAuditAdapter } from './IAuditAdapter-BkxGx6TI.cjs';
13
13
  export { I as IMetricsAdapter, M as MetricName } from './IMetricsAdapter-DWq8IFaf.cjs';
14
14
  export { I as ISchedulerAdapter } from './ISchedulerAdapter-DKv_QjVN.cjs';
15
- export { a as ApprovalInstance, c as ApprovalLevelConfig, d as ApprovalLevelInstance, e as ApprovalMode, f as ApprovalStatus, A as ApprovalTemplate, g as ApprovalTemplateConfig, h as ApproverConfig, i as Attachment, j as AuditAction, k as AuditContext, b as AuditEntry, C as Comment, l as Condition, m as ConditionExpression, n as ConditionGroup, o as ConditionOperator, p as ConditionRule, E as EscalationConfig, q as EscalationStep, I as InfoRequest, L as LevelStatus, R as ResolvedApprover, r as ResolverFn, S as SubWorkflowConfig, T as TemplateSnapshot } from './instance-BvOyT00S.cjs';
15
+ export { a as ApprovalInstance, c as ApprovalLevelConfig, d as ApprovalLevelInstance, e as ApprovalMode, f as ApprovalStatus, A as ApprovalTemplate, g as ApprovalTemplateConfig, h as ApproverConfig, i as Attachment, j as AuditAction, k as AuditContext, b as AuditEntry, C as Comment, l as Condition, m as ConditionExpression, n as ConditionGroup, o as ConditionOperator, p as ConditionRule, E as EscalationConfig, q as EscalationStep, I as InfoRequest, L as LevelStatus, R as ResolvedApprover, r as ResolverFn, S as SubWorkflowConfig, T as TemplateSnapshot } from './instance-BXHxvTLE.cjs';
16
16
  import 'zod';
17
17
 
18
18
  interface EscalationSchedulerOpts {
package/dist/index.d.ts CHANGED
@@ -1,18 +1,18 @@
1
- export { A as AddCommentOptions, a as ApprovalEngine, b as ApprovalEngineOptions, c as ApprovalStatistics, d as ApproveOptions, e as ApproverResolverFn, f as ApproverWorkload, B as BulkResult, g as BusinessCalendar, h as BusinessHoursCalendarOptions, C as CanApproveResult, i as CancelOptions, j as ChainExplanation, k as ConditionOperatorFn, l as CycleTimeStats, D as DelegateOptions, E as EscalateOptions, m as ExplainedLevel, n as ExplainedRule, o as ExplainedSkip, H as HealthResult, I as IdGeneratorFn, p as IdempotencyKeyFn, q as ImportResult, O as OrgProvider, r as OutOfOfficeProvider, s as OverrideOptions, P as PreviewChainLevel, t as PreviewResult, u as ProvideInfoOptions, v as PurgeResult, R as ReassignOptions, w as RejectOptions, x as RequestInfoOptions, y as ResubmitOptions, z as RetryPolicy, S as SimulatedDecision, F as SimulationResult, G as SimulationStep, J as SubmitOptions, T as TEMPLATE_BUNDLE_VERSION, K as TemplateBundle, L as TransferResult, U as UpdateDataOptions, V as ValidationResult, W as WeekendCalendarOptions, M as businessHoursCalendar, N as defaultIdGenerator, Q as toComparableNumber, X as validateConditionExpression, Y as weekendCalendar } from './ApprovalEngine-CCOwhMrs.js';
2
- import { I as IStorageAdapter } from './IStorageAdapter-C2QxUwbX.js';
3
- export { c as CursorPaginatedResult, C as CursorPaginationOpts, b as InstanceFilter, a as PaginatedResult, P as PaginationOpts } from './IStorageAdapter-C2QxUwbX.js';
1
+ export { A as AddCommentOptions, a as ApprovalEngine, b as ApprovalEngineOptions, c as ApprovalStatistics, d as ApproveOptions, e as ApproverResolverFn, f as ApproverWorkload, B as BulkResult, g as BusinessCalendar, h as BusinessHoursCalendarOptions, C as CanApproveResult, i as CancelOptions, j as ChainExplanation, k as ConditionOperatorFn, l as CycleTimeStats, D as DelegateOptions, E as EscalateOptions, m as ExplainedLevel, n as ExplainedRule, o as ExplainedSkip, H as HealthResult, I as IdGeneratorFn, p as IdempotencyKeyFn, q as ImportResult, O as OrgProvider, r as OutOfOfficeProvider, s as OverrideOptions, P as PreviewChainLevel, t as PreviewResult, u as ProvideInfoOptions, v as PurgeResult, R as ReassignOptions, w as RejectOptions, x as RequestInfoOptions, y as ResubmitOptions, z as RetryPolicy, S as SimulatedDecision, F as SimulationResult, G as SimulationStep, J as SubmitOptions, T as TEMPLATE_BUNDLE_VERSION, K as TemplateBundle, L as TransferResult, U as UpdateDataOptions, V as ValidationResult, W as WeekendCalendarOptions, M as businessHoursCalendar, N as defaultIdGenerator, Q as toComparableNumber, X as validateConditionExpression, Y as weekendCalendar } from './ApprovalEngine-Cslh4Goz.js';
2
+ import { I as IStorageAdapter } from './IStorageAdapter-CEKfu-U8.js';
3
+ export { c as CursorPaginatedResult, C as CursorPaginationOpts, b as InstanceFilter, a as PaginatedResult, P as PaginationOpts } from './IStorageAdapter-CEKfu-U8.js';
4
4
  import { L as Logger } from './Logger-BplhlU7l.js';
5
5
  export { n as noopLogger } from './Logger-BplhlU7l.js';
6
6
  import { C as Clock } from './Clock-3FnOczFJ.js';
7
7
  export { s as systemClock } from './Clock-3FnOczFJ.js';
8
- export { A as AuthorizationContext, I as IAuthorizationPolicy } from './IAuthorizationPolicy-DOm6KCwI.js';
9
- export { A as ApprovalConflictError, a as ApprovalError, b as ApprovalForbiddenError, c as ApprovalNotFoundError, d as ApprovalTemplateNotFoundError, e as ApprovalValidationError, I as IOperationMiddleware, O as OperationContext } from './IOperationMiddleware-Nk8Q1Z8o.js';
8
+ export { A as AuthorizationContext, I as IAuthorizationPolicy } from './IAuthorizationPolicy-Z4nkX-bu.js';
9
+ export { A as ApprovalConflictError, a as ApprovalError, b as ApprovalForbiddenError, c as ApprovalNotFoundError, d as ApprovalTemplateNotFoundError, e as ApprovalValidationError, I as IOperationMiddleware, O as OperationContext } from './IOperationMiddleware-Cbd05rje.js';
10
10
  export { MemoryAdapter } from './adapters/MemoryAdapter.js';
11
- export { A as ApprovalEvent, a as ApprovalEventMap, b as ApprovalEventName, c as ApprovedEvent, d as AttachmentEvent, C as CancelledEvent, e as CommentedEvent, D as DataUpdatedEvent, f as DelegatedEvent, E as EscalatedEvent, g as ExpiredEvent, H as HistoryEntry, I as INotificationAdapter, h as InfoProvidedEvent, i as InfoRequestedEvent, L as LevelAdvancedEvent, N as NotificationEvent, O as OverriddenEvent, R as ReassignedEvent, j as RejectedEvent, k as ReminderEvent, l as ResubmittedEvent, S as SlaBreachedEvent, m as SubWorkflowEvent, n as SubmittedEvent } from './INotificationAdapter-DMvA4R-c.js';
12
- export { I as IAuditAdapter } from './IAuditAdapter-B33n15YP.js';
11
+ export { A as ApprovalEvent, a as ApprovalEventMap, b as ApprovalEventName, c as ApprovedEvent, d as AttachmentEvent, C as CancelledEvent, e as CommentedEvent, D as DataUpdatedEvent, f as DelegatedEvent, E as EscalatedEvent, g as ExpiredEvent, H as HistoryEntry, I as INotificationAdapter, h as InfoProvidedEvent, i as InfoRequestedEvent, L as LevelAdvancedEvent, N as NotificationEvent, O as OverriddenEvent, R as ReassignedEvent, j as RejectedEvent, k as ReminderEvent, l as ResubmittedEvent, S as SlaBreachedEvent, m as SubWorkflowEvent, n as SubmittedEvent } from './INotificationAdapter-C-PL3Pvp.js';
12
+ export { I as IAuditAdapter } from './IAuditAdapter-udkAnnmu.js';
13
13
  export { I as IMetricsAdapter, M as MetricName } from './IMetricsAdapter-DWq8IFaf.js';
14
14
  export { I as ISchedulerAdapter } from './ISchedulerAdapter-DKv_QjVN.js';
15
- export { a as ApprovalInstance, c as ApprovalLevelConfig, d as ApprovalLevelInstance, e as ApprovalMode, f as ApprovalStatus, A as ApprovalTemplate, g as ApprovalTemplateConfig, h as ApproverConfig, i as Attachment, j as AuditAction, k as AuditContext, b as AuditEntry, C as Comment, l as Condition, m as ConditionExpression, n as ConditionGroup, o as ConditionOperator, p as ConditionRule, E as EscalationConfig, q as EscalationStep, I as InfoRequest, L as LevelStatus, R as ResolvedApprover, r as ResolverFn, S as SubWorkflowConfig, T as TemplateSnapshot } from './instance-BvOyT00S.js';
15
+ export { a as ApprovalInstance, c as ApprovalLevelConfig, d as ApprovalLevelInstance, e as ApprovalMode, f as ApprovalStatus, A as ApprovalTemplate, g as ApprovalTemplateConfig, h as ApproverConfig, i as Attachment, j as AuditAction, k as AuditContext, b as AuditEntry, C as Comment, l as Condition, m as ConditionExpression, n as ConditionGroup, o as ConditionOperator, p as ConditionRule, E as EscalationConfig, q as EscalationStep, I as InfoRequest, L as LevelStatus, R as ResolvedApprover, r as ResolverFn, S as SubWorkflowConfig, T as TemplateSnapshot } from './instance-BXHxvTLE.js';
16
16
  import 'zod';
17
17
 
18
18
  interface EscalationSchedulerOpts {
package/dist/index.js CHANGED
@@ -194,6 +194,7 @@ function reviveDates(instance) {
194
194
  if (l.escalationDueAt) level.escalationDueAt = new Date(l.escalationDueAt);
195
195
  if (l.delegatedUntil) level.delegatedUntil = new Date(l.delegatedUntil);
196
196
  if (l.reminderDueAt) level.reminderDueAt = new Date(l.reminderDueAt);
197
+ if (l.openedAt) level.openedAt = new Date(l.openedAt);
197
198
  return level;
198
199
  })
199
200
  };
@@ -296,9 +297,8 @@ var MemoryAdapter = class {
296
297
  }
297
298
  async getOverdueInstances(tenantId, asOf, filter = {}) {
298
299
  return [...this.instances.values()].filter((i) => {
299
- if (i.tenantId !== tenantId || i.status !== "pending") return false;
300
- if (filter.documentType && i.documentType !== filter.documentType) return false;
301
- if (filter.submittedBy && i.submittedBy !== filter.submittedBy) return false;
300
+ if (i.tenantId !== tenantId) return false;
301
+ if (!applyFilter(i, { ...filter, status: "pending" })) return false;
302
302
  const hasOverdueEscalation = i.levels.some(
303
303
  (l) => l.escalationDueAt != null && new Date(l.escalationDueAt) <= asOf
304
304
  );
@@ -4064,6 +4064,7 @@ var ApprovalEngine = class _ApprovalEngine {
4064
4064
  remindersSent: 0
4065
4065
  };
4066
4066
  if (opts.open) {
4067
+ level.openedAt = opts.now;
4067
4068
  level.escalationDueAt = this.levelEscalationDue(opts.now, cfg, opts.firstRung);
4068
4069
  this.scheduleReminder(level, opts.now);
4069
4070
  }
@@ -4106,6 +4107,7 @@ var ApprovalEngine = class _ApprovalEngine {
4106
4107
  * the ladder no worse off than the single-step behaviour it replaces.
4107
4108
  */
4108
4109
  levelOpenedAt(instance, level, fallback) {
4110
+ if (level.openedAt) return new Date(level.openedAt);
4109
4111
  for (let i = instance.auditLog.length - 1; i >= 0; i--) {
4110
4112
  const entry = instance.auditLog[i];
4111
4113
  if (!entry) continue;
@@ -4226,6 +4228,7 @@ var ApprovalEngine = class _ApprovalEngine {
4226
4228
  now
4227
4229
  );
4228
4230
  }
4231
+ lvl.openedAt = now;
4229
4232
  lvl.escalationDueAt = this.levelEscalationDue(now, lvl, firstRung);
4230
4233
  lvl.escalationStep = 0;
4231
4234
  this.scheduleReminder(lvl, now);