@voyant-travel/action-ledger 0.104.10
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/LICENSE +201 -0
- package/dist/canary.d.ts +17 -0
- package/dist/canary.d.ts.map +1 -0
- package/dist/canary.js +77 -0
- package/dist/capability.d.ts +73 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/capability.js +206 -0
- package/dist/fingerprint.d.ts +26 -0
- package/dist/fingerprint.d.ts.map +1 -0
- package/dist/fingerprint.js +55 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/request-context.d.ts +136 -0
- package/dist/request-context.d.ts.map +1 -0
- package/dist/request-context.js +237 -0
- package/dist/route-schemas.d.ts +745 -0
- package/dist/route-schemas.d.ts.map +1 -0
- package/dist/route-schemas.js +428 -0
- package/dist/routes.d.ts +1602 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +271 -0
- package/dist/schema.d.ts +1759 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +237 -0
- package/dist/service/approval-status.d.ts +3 -0
- package/dist/service/approval-status.d.ts.map +1 -0
- package/dist/service/approval-status.js +14 -0
- package/dist/service/cursors.d.ts +22 -0
- package/dist/service/cursors.d.ts.map +1 -0
- package/dist/service/cursors.js +48 -0
- package/dist/service/entries.d.ts +9 -0
- package/dist/service/entries.d.ts.map +1 -0
- package/dist/service/entries.js +75 -0
- package/dist/service/errors.d.ts +20 -0
- package/dist/service/errors.d.ts.map +1 -0
- package/dist/service/errors.js +36 -0
- package/dist/service/listing.d.ts +7 -0
- package/dist/service/listing.d.ts.map +1 -0
- package/dist/service/listing.js +77 -0
- package/dist/service/predicates.d.ts +8 -0
- package/dist/service/predicates.d.ts.map +1 -0
- package/dist/service/predicates.js +368 -0
- package/dist/service/records.d.ts +6 -0
- package/dist/service/records.d.ts.map +1 -0
- package/dist/service/records.js +51 -0
- package/dist/service/relay-lifecycle.d.ts +7 -0
- package/dist/service/relay-lifecycle.d.ts.map +1 -0
- package/dist/service/relay-lifecycle.js +78 -0
- package/dist/service/relay-outbox.d.ts +15 -0
- package/dist/service/relay-outbox.d.ts.map +1 -0
- package/dist/service/relay-outbox.js +15 -0
- package/dist/service/types.d.ts +249 -0
- package/dist/service/types.d.ts.map +1 -0
- package/dist/service/types.js +1 -0
- package/dist/service.d.ts +40 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +283 -0
- package/dist/timeline.d.ts +67 -0
- package/dist/timeline.d.ts.map +1 -0
- package/dist/timeline.js +79 -0
- package/package.json +93 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import type { ActionApproval, ActionDelegation, ActionLedgerEntry, ActionLedgerPayload, ActionLedgerRelayOutbox, ActionMutationDetail, ActionSensitiveReadDetail, NewActionLedgerEntry, NewActionLedgerPayload, NewActionMutationDetail, NewActionSensitiveReadDetail } from "../schema.js";
|
|
2
|
+
export interface AppendActionLedgerEntryInput extends Omit<NewActionLedgerEntry, "id" | "createdAt" | "occurredAt"> {
|
|
3
|
+
occurredAt?: Date;
|
|
4
|
+
mutationDetail?: Omit<NewActionMutationDetail, "actionId">;
|
|
5
|
+
sensitiveReadDetail?: Omit<NewActionSensitiveReadDetail, "actionId">;
|
|
6
|
+
payloads?: Omit<NewActionLedgerPayload, "id" | "actionId">[];
|
|
7
|
+
enqueueRelay?: boolean | {
|
|
8
|
+
payloadRef?: string | null;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface AppendActionLedgerEntryResult {
|
|
12
|
+
entry: ActionLedgerEntry;
|
|
13
|
+
replayed: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface RequestActionApprovalInput {
|
|
16
|
+
requestedAction: Omit<AppendActionLedgerEntryInput, "approvalId" | "status">;
|
|
17
|
+
approval: {
|
|
18
|
+
requestedByPrincipalId?: string | null;
|
|
19
|
+
assignedToPrincipalId?: string | null;
|
|
20
|
+
delegatedFromPrincipalId?: string | null;
|
|
21
|
+
policyName: string;
|
|
22
|
+
policyVersion: string;
|
|
23
|
+
targetSnapshotRef?: string | null;
|
|
24
|
+
riskSnapshot?: ActionApproval["riskSnapshot"] | null;
|
|
25
|
+
reasonCode?: string | null;
|
|
26
|
+
expiresAt?: Date | string | null;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface RequestActionApprovalResult {
|
|
30
|
+
requestedAction: ActionLedgerEntry;
|
|
31
|
+
approval: ActionApproval;
|
|
32
|
+
replayed: boolean;
|
|
33
|
+
}
|
|
34
|
+
export type ApprovalDecisionStatus = Exclude<ActionApproval["status"], "pending">;
|
|
35
|
+
export interface DecideActionApprovalInput {
|
|
36
|
+
id: string;
|
|
37
|
+
status: ApprovalDecisionStatus;
|
|
38
|
+
decidedByPrincipalId: string;
|
|
39
|
+
decidedAt?: Date | string | null;
|
|
40
|
+
decisionAction: Omit<AppendActionLedgerEntryInput, "actionKind" | "approvalId" | "causationActionId" | "evaluatedRisk" | "status" | "targetId" | "targetType"> & Partial<Pick<AppendActionLedgerEntryInput, "actionKind" | "evaluatedRisk" | "status" | "targetId" | "targetType">>;
|
|
41
|
+
}
|
|
42
|
+
export interface DecideActionApprovalResult {
|
|
43
|
+
approval: ActionApproval;
|
|
44
|
+
decisionAction: ActionLedgerEntry;
|
|
45
|
+
}
|
|
46
|
+
type ActionLedgerReversalState = NonNullable<ActionMutationDetail["reversalStateProjection"]>;
|
|
47
|
+
type ActionLedgerReversalOutcome = NonNullable<ActionMutationDetail["reversalOutcomeProjection"]>;
|
|
48
|
+
export interface RecordActionLedgerReversalInput {
|
|
49
|
+
originalActionId: string;
|
|
50
|
+
reversalAction: Omit<AppendActionLedgerEntryInput, "causationActionId" | "mutationDetail"> & {
|
|
51
|
+
mutationDetail?: Omit<NewActionMutationDetail, "actionId" | "reversesActionId">;
|
|
52
|
+
};
|
|
53
|
+
projection?: {
|
|
54
|
+
reversalState?: ActionLedgerReversalState | null;
|
|
55
|
+
reversalOutcome?: ActionLedgerReversalOutcome | null;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export interface RecordActionLedgerReversalResult {
|
|
59
|
+
originalAction: ActionLedgerEntry;
|
|
60
|
+
originalMutationDetail: ActionMutationDetail;
|
|
61
|
+
reversalAction: ActionLedgerEntry;
|
|
62
|
+
replayed: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface ActionLedgerListCursor {
|
|
65
|
+
occurredAt: string;
|
|
66
|
+
id: string;
|
|
67
|
+
}
|
|
68
|
+
export interface ActionLedgerRelayOutboxListCursor {
|
|
69
|
+
createdAt: string;
|
|
70
|
+
id: string;
|
|
71
|
+
}
|
|
72
|
+
export interface ActionApprovalListCursor {
|
|
73
|
+
createdAt: string;
|
|
74
|
+
id: string;
|
|
75
|
+
}
|
|
76
|
+
export interface ActionDelegationListCursor {
|
|
77
|
+
createdAt: string;
|
|
78
|
+
id: string;
|
|
79
|
+
}
|
|
80
|
+
export interface ListActionLedgerEntriesInput {
|
|
81
|
+
actionName?: string | null;
|
|
82
|
+
actionKind?: ActionLedgerEntry["actionKind"];
|
|
83
|
+
actorType?: string | null;
|
|
84
|
+
principalType?: ActionLedgerEntry["principalType"];
|
|
85
|
+
principalId?: string | null;
|
|
86
|
+
apiTokenId?: string | null;
|
|
87
|
+
sessionId?: string | null;
|
|
88
|
+
callerType?: string | null;
|
|
89
|
+
organizationId?: string | null;
|
|
90
|
+
targetType?: string | null;
|
|
91
|
+
targetId?: string | null;
|
|
92
|
+
targetIds?: string[] | null;
|
|
93
|
+
routeOrToolName?: string | null;
|
|
94
|
+
workflowRunId?: string | null;
|
|
95
|
+
workflowStepId?: string | null;
|
|
96
|
+
correlationId?: string | null;
|
|
97
|
+
causationActionId?: string | null;
|
|
98
|
+
capabilityId?: string | null;
|
|
99
|
+
capabilityVersion?: string | null;
|
|
100
|
+
authorizationSource?: string | null;
|
|
101
|
+
approvalId?: string | null;
|
|
102
|
+
amendsActionId?: string | null;
|
|
103
|
+
idempotencyScope?: string | null;
|
|
104
|
+
idempotencyKey?: string | null;
|
|
105
|
+
evaluatedRisk?: ActionLedgerEntry["evaluatedRisk"] | ActionLedgerEntry["evaluatedRisk"][];
|
|
106
|
+
status?: ActionLedgerEntry["status"] | ActionLedgerEntry["status"][];
|
|
107
|
+
reversalKind?: ActionMutationDetail["reversalKind"] | ActionMutationDetail["reversalKind"][];
|
|
108
|
+
reversalState?: NonNullable<ActionMutationDetail["reversalStateProjection"]> | NonNullable<ActionMutationDetail["reversalStateProjection"]>[];
|
|
109
|
+
reversalOutcome?: NonNullable<ActionMutationDetail["reversalOutcomeProjection"]> | NonNullable<ActionMutationDetail["reversalOutcomeProjection"]>[];
|
|
110
|
+
reversesActionId?: string | null;
|
|
111
|
+
reversedByActionId?: string | null;
|
|
112
|
+
sensitiveReasonCode?: string | null;
|
|
113
|
+
decisionPolicy?: string | null;
|
|
114
|
+
occurredAtFrom?: Date | string | null;
|
|
115
|
+
occurredAtTo?: Date | string | null;
|
|
116
|
+
cursor?: ActionLedgerListCursor | null;
|
|
117
|
+
sortDir?: "asc" | "desc";
|
|
118
|
+
limit?: number;
|
|
119
|
+
}
|
|
120
|
+
export interface ListActionLedgerEntriesResult {
|
|
121
|
+
entries: ActionLedgerEntry[];
|
|
122
|
+
nextCursor: ActionLedgerListCursor | null;
|
|
123
|
+
}
|
|
124
|
+
export interface ListActionLedgerRelayOutboxInput {
|
|
125
|
+
actionId?: string | null;
|
|
126
|
+
organizationId?: string | null;
|
|
127
|
+
relayStatus?: ActionLedgerRelayOutbox["relayStatus"] | ActionLedgerRelayOutbox["relayStatus"][];
|
|
128
|
+
dueBefore?: Date | string | null;
|
|
129
|
+
createdAtFrom?: Date | string | null;
|
|
130
|
+
createdAtTo?: Date | string | null;
|
|
131
|
+
processedAtFrom?: Date | string | null;
|
|
132
|
+
processedAtTo?: Date | string | null;
|
|
133
|
+
cursor?: ActionLedgerRelayOutboxListCursor | null;
|
|
134
|
+
limit?: number;
|
|
135
|
+
}
|
|
136
|
+
export interface ListActionLedgerRelayOutboxResult {
|
|
137
|
+
rows: ActionLedgerRelayOutbox[];
|
|
138
|
+
nextCursor: ActionLedgerRelayOutboxListCursor | null;
|
|
139
|
+
}
|
|
140
|
+
export interface ListActionApprovalsInput {
|
|
141
|
+
requestedActionId?: string | null;
|
|
142
|
+
status?: ActionApproval["status"] | ActionApproval["status"][];
|
|
143
|
+
requestedByPrincipalId?: string | null;
|
|
144
|
+
assignedToPrincipalId?: string | null;
|
|
145
|
+
decidedByPrincipalId?: string | null;
|
|
146
|
+
delegatedFromPrincipalId?: string | null;
|
|
147
|
+
policyName?: string | null;
|
|
148
|
+
policyVersion?: string | null;
|
|
149
|
+
riskSnapshot?: ActionApproval["riskSnapshot"] | ActionApproval["riskSnapshot"][];
|
|
150
|
+
reasonCode?: string | null;
|
|
151
|
+
expiresAtFrom?: Date | string | null;
|
|
152
|
+
expiresAtTo?: Date | string | null;
|
|
153
|
+
decidedAtFrom?: Date | string | null;
|
|
154
|
+
decidedAtTo?: Date | string | null;
|
|
155
|
+
createdAtFrom?: Date | string | null;
|
|
156
|
+
createdAtTo?: Date | string | null;
|
|
157
|
+
cursor?: ActionApprovalListCursor | null;
|
|
158
|
+
limit?: number;
|
|
159
|
+
}
|
|
160
|
+
export interface ListActionApprovalsResult {
|
|
161
|
+
approvals: ActionApproval[];
|
|
162
|
+
nextCursor: ActionApprovalListCursor | null;
|
|
163
|
+
}
|
|
164
|
+
export interface ListActionDelegationsInput {
|
|
165
|
+
rootPrincipalType?: ActionDelegation["rootPrincipalType"];
|
|
166
|
+
rootPrincipalId?: string | null;
|
|
167
|
+
parentPrincipalType?: ActionDelegation["parentPrincipalType"];
|
|
168
|
+
parentPrincipalId?: string | null;
|
|
169
|
+
childPrincipalType?: ActionDelegation["childPrincipalType"];
|
|
170
|
+
childPrincipalId?: string | null;
|
|
171
|
+
grantSource?: string | null;
|
|
172
|
+
capabilityScopeRef?: string | null;
|
|
173
|
+
budgetScopeRef?: string | null;
|
|
174
|
+
expiresAtFrom?: Date | string | null;
|
|
175
|
+
expiresAtTo?: Date | string | null;
|
|
176
|
+
createdAtFrom?: Date | string | null;
|
|
177
|
+
createdAtTo?: Date | string | null;
|
|
178
|
+
cursor?: ActionDelegationListCursor | null;
|
|
179
|
+
limit?: number;
|
|
180
|
+
}
|
|
181
|
+
export interface ListActionDelegationsResult {
|
|
182
|
+
delegations: ActionDelegation[];
|
|
183
|
+
nextCursor: ActionDelegationListCursor | null;
|
|
184
|
+
}
|
|
185
|
+
export interface ClaimActionLedgerRelayOutboxInput {
|
|
186
|
+
organizationId?: string | null;
|
|
187
|
+
dueAt?: Date | string | null;
|
|
188
|
+
limit?: number;
|
|
189
|
+
}
|
|
190
|
+
export interface ClaimActionLedgerRelayOutboxResult {
|
|
191
|
+
rows: ActionLedgerRelayOutbox[];
|
|
192
|
+
}
|
|
193
|
+
export interface MarkActionLedgerRelayOutboxSucceededInput {
|
|
194
|
+
id: string;
|
|
195
|
+
processedAt?: Date | string | null;
|
|
196
|
+
}
|
|
197
|
+
export interface MarkActionLedgerRelayOutboxFailedInput {
|
|
198
|
+
id: string;
|
|
199
|
+
lastError: string;
|
|
200
|
+
nextRetryAt?: Date | string | null;
|
|
201
|
+
deadLetter?: boolean;
|
|
202
|
+
processedAt?: Date | string | null;
|
|
203
|
+
}
|
|
204
|
+
export interface GetActionLedgerEntryResult {
|
|
205
|
+
entry: ActionLedgerEntry;
|
|
206
|
+
mutationDetail: ActionMutationDetail | null;
|
|
207
|
+
sensitiveReadDetail: ActionSensitiveReadDetail | null;
|
|
208
|
+
payloads: ActionLedgerPayload[];
|
|
209
|
+
relayOutbox: ActionLedgerRelayOutbox[];
|
|
210
|
+
}
|
|
211
|
+
export interface GetActionApprovalResult {
|
|
212
|
+
approval: ActionApproval;
|
|
213
|
+
requestedAction: GetActionLedgerEntryResult | null;
|
|
214
|
+
}
|
|
215
|
+
export type ValidateApprovedActionFailureReason = "not_found" | "not_approved" | "expired" | "mismatched_action" | "already_executed" | "missing_fingerprint" | "fingerprint_mismatch" | "principal_mismatch";
|
|
216
|
+
export interface ValidateApprovedActionInput {
|
|
217
|
+
approvalId: string;
|
|
218
|
+
actionName: string;
|
|
219
|
+
actionVersion: string;
|
|
220
|
+
requestedActionKind?: ActionLedgerEntry["actionKind"] | null;
|
|
221
|
+
requestedActionStatus?: ActionLedgerEntry["status"] | ActionLedgerEntry["status"][] | null;
|
|
222
|
+
targetType: string;
|
|
223
|
+
targetId: string;
|
|
224
|
+
routeOrToolName?: string | null;
|
|
225
|
+
principalType?: ActionLedgerEntry["principalType"] | null;
|
|
226
|
+
principalId?: string | null;
|
|
227
|
+
idempotencyFingerprint: string;
|
|
228
|
+
executionActionKind?: ActionLedgerEntry["actionKind"];
|
|
229
|
+
executionStatus?: ActionLedgerEntry["status"];
|
|
230
|
+
now?: Date | string | null;
|
|
231
|
+
}
|
|
232
|
+
export type ValidateApprovedActionResult = {
|
|
233
|
+
ok: true;
|
|
234
|
+
approval: ActionApproval;
|
|
235
|
+
requestedAction: ActionLedgerEntry;
|
|
236
|
+
idempotencyFingerprint: string;
|
|
237
|
+
} | {
|
|
238
|
+
ok: false;
|
|
239
|
+
reason: ValidateApprovedActionFailureReason;
|
|
240
|
+
approval?: ActionApproval;
|
|
241
|
+
requestedAction?: ActionLedgerEntry;
|
|
242
|
+
status?: ActionApproval["status"];
|
|
243
|
+
existingActionId?: string;
|
|
244
|
+
};
|
|
245
|
+
export interface GetActionDelegationResult {
|
|
246
|
+
delegation: ActionDelegation;
|
|
247
|
+
}
|
|
248
|
+
export {};
|
|
249
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/service/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,uBAAuB,EACvB,oBAAoB,E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A;IACzD,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,sBAAsB,EAAE,MAAM,CAAA;IAC9B,mBAAmB,CAAC,EAAE,iBAAiB,CAAC,YAAY,CAAC,CAAA;IACrD,eAAe,CAAC,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAA;IAC7C,GAAG,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAAA;CAC3B;AAED,MAAM,MAAM,4BAA4B,GACpC;IACE,EAAE,EAAE,IAAI,CAAA;IACR,QAAQ,EAAE,cAAc,CAAA;IACxB,eAAe,EAAE,iBAAiB,CAAA;IAClC,sBAAsB,EAAE,MAAM,CAAA;CAC/B,GACD;IACE,EAAE,EAAE,KAAK,CAAA;IACT,MAAM,EAAE,mCAAmC,CAAA;IAC3C,QAAQ,CAAC,EAAE,cAAc,CAAA;IACzB,eAAe,CAAC,EAAE,iBAAiB,CAAA;IACnC,MAAM,CAAC,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAA;IACjC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B,CAAA;AAEL,MAAM,WAAW,yBAAyB;IACxC,UAAU,EAAE,gBAAgB,CAAA;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { AnyDrizzleDb } from "@voyant-travel/db";
|
|
2
|
+
import { withOptionalTransaction } from "@voyant-travel/db/transaction";
|
|
3
|
+
import { normalizeListLimit, toActionApprovalListCursor, toActionDelegationListCursor, toActionLedgerListCursor, toActionLedgerRelayOutboxListCursor } from "./service/cursors.js";
|
|
4
|
+
import { listApprovals, listDelegations, listEntries, listRelayOutbox } from "./service/listing.js";
|
|
5
|
+
import { buildActionApprovalsPredicate, buildActionDelegationsPredicate, buildActionLedgerEntriesPredicate, buildActionLedgerRelayOutboxPredicate } from "./service/predicates.js";
|
|
6
|
+
import { getApproval, getDelegation, getEntry } from "./service/records.js";
|
|
7
|
+
import { claimRelayOutbox, markRelayOutboxFailed, markRelayOutboxSucceeded } from "./service/relay-lifecycle.js";
|
|
8
|
+
import type { AppendActionLedgerEntryInput, AppendActionLedgerEntryResult, DecideActionApprovalInput, DecideActionApprovalResult, RecordActionLedgerReversalInput, RecordActionLedgerReversalResult, RequestActionApprovalInput, RequestActionApprovalResult, ValidateApprovedActionInput, ValidateApprovedActionResult } from "./service/types.js";
|
|
9
|
+
export { ActionApprovalDecisionConflictError, ActionApprovalDecisionStatusError, ActionLedgerIdempotencyConflictError, ActionLedgerReversalTargetError, } from "./service/errors.js";
|
|
10
|
+
export type { ActionApprovalListCursor, ActionDelegationListCursor, ActionLedgerListCursor, ActionLedgerRelayOutboxListCursor, AppendActionLedgerEntryInput, AppendActionLedgerEntryResult, ClaimActionLedgerRelayOutboxInput, ClaimActionLedgerRelayOutboxResult, DecideActionApprovalInput, DecideActionApprovalResult, GetActionApprovalResult, GetActionDelegationResult, GetActionLedgerEntryResult, ListActionApprovalsInput, ListActionApprovalsResult, ListActionDelegationsInput, ListActionDelegationsResult, ListActionLedgerEntriesInput, ListActionLedgerEntriesResult, ListActionLedgerRelayOutboxInput, ListActionLedgerRelayOutboxResult, MarkActionLedgerRelayOutboxFailedInput, MarkActionLedgerRelayOutboxSucceededInput, RecordActionLedgerReversalInput, RecordActionLedgerReversalResult, RequestActionApprovalInput, RequestActionApprovalResult, ValidateApprovedActionFailureReason, ValidateApprovedActionInput, ValidateApprovedActionResult, } from "./service/types.js";
|
|
11
|
+
export declare const actionLedgerService: {
|
|
12
|
+
appendEntry(db: AnyDrizzleDb, input: AppendActionLedgerEntryInput): Promise<AppendActionLedgerEntryResult>;
|
|
13
|
+
requestApproval(db: AnyDrizzleDb, input: RequestActionApprovalInput): Promise<RequestActionApprovalResult>;
|
|
14
|
+
decideApproval(db: AnyDrizzleDb, input: DecideActionApprovalInput): Promise<DecideActionApprovalResult | null>;
|
|
15
|
+
recordReversal(db: AnyDrizzleDb, input: RecordActionLedgerReversalInput): Promise<RecordActionLedgerReversalResult | null>;
|
|
16
|
+
listEntries: typeof listEntries;
|
|
17
|
+
listRelayOutbox: typeof listRelayOutbox;
|
|
18
|
+
listApprovals: typeof listApprovals;
|
|
19
|
+
listDelegations: typeof listDelegations;
|
|
20
|
+
getApproval: typeof getApproval;
|
|
21
|
+
validateApprovedAction(db: AnyDrizzleDb, input: ValidateApprovedActionInput): Promise<ValidateApprovedActionResult>;
|
|
22
|
+
getDelegation: typeof getDelegation;
|
|
23
|
+
claimRelayOutbox: typeof claimRelayOutbox;
|
|
24
|
+
markRelayOutboxSucceeded: typeof markRelayOutboxSucceeded;
|
|
25
|
+
markRelayOutboxFailed: typeof markRelayOutboxFailed;
|
|
26
|
+
getEntry: typeof getEntry;
|
|
27
|
+
};
|
|
28
|
+
export declare const __test__: {
|
|
29
|
+
buildActionApprovalsPredicate: typeof buildActionApprovalsPredicate;
|
|
30
|
+
buildActionDelegationsPredicate: typeof buildActionDelegationsPredicate;
|
|
31
|
+
buildActionLedgerEntriesPredicate: typeof buildActionLedgerEntriesPredicate;
|
|
32
|
+
buildActionLedgerRelayOutboxPredicate: typeof buildActionLedgerRelayOutboxPredicate;
|
|
33
|
+
withOptionalTransaction: typeof withOptionalTransaction;
|
|
34
|
+
normalizeListLimit: typeof normalizeListLimit;
|
|
35
|
+
toActionApprovalListCursor: typeof toActionApprovalListCursor;
|
|
36
|
+
toActionDelegationListCursor: typeof toActionDelegationListCursor;
|
|
37
|
+
toActionLedgerListCursor: typeof toActionLedgerListCursor;
|
|
38
|
+
toActionLedgerRelayOutboxListCursor: typeof toActionLedgerRelayOutboxListCursor;
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,EA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,EAC3B,4BAA4B,GAC7B,MAAM,oBAAoB,CAAA;AAE3B,eAAO,MAAM,mBAAmB;oBAExB,YAAY,SACT,4BAA4B,GAClC,OAAO,CAAC,6BAA6B,CAAC;wBAoBnC,YAAY,SACT,0BAA0B,GAChC,OAAO,CAAC,2BAA2B,CAAC;uBAuDjC,YAAY,SACT,yBAAyB,GAC/B,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAAC;uBA8CvC,YAAY,SACT,+BAA+B,GACrC,OAAO,CAAC,gCAAgC,GAAG,IAAI,CAAC;;;;;;+BAiE7C,YAAY,SACT,2BAA2B,GACjC,OAAO,CAAC,4BAA4B,CAAC;;;;;;CAoHzC,CAAA;AAED,eAAO,MAAM,QAAQ;;;;;;;;;;;CAWpB,CAAA"}
|
package/dist/service.js
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { newId } from "@voyant-travel/db/lib/typeid";
|
|
2
|
+
import { withOptionalTransaction } from "@voyant-travel/db/transaction";
|
|
3
|
+
import { and, eq } from "drizzle-orm";
|
|
4
|
+
import { actionApprovals, actionMutationDetails } from "./schema.js";
|
|
5
|
+
import { assertApprovalDecisionStatus } from "./service/approval-status.js";
|
|
6
|
+
import { normalizeListLimit, parseCursorDate, toActionApprovalListCursor, toActionDelegationListCursor, toActionLedgerListCursor, toActionLedgerRelayOutboxListCursor, } from "./service/cursors.js";
|
|
7
|
+
import { assertSameFingerprint, findApprovalById, findApprovalForRequestedAction, findExistingIdempotentEntry, insertEntry, } from "./service/entries.js";
|
|
8
|
+
import { ActionApprovalDecisionConflictError, ActionLedgerReversalTargetError, } from "./service/errors.js";
|
|
9
|
+
import { listApprovals, listDelegations, listEntries, listRelayOutbox } from "./service/listing.js";
|
|
10
|
+
import { buildActionApprovalsPredicate, buildActionDelegationsPredicate, buildActionLedgerEntriesPredicate, buildActionLedgerRelayOutboxPredicate, } from "./service/predicates.js";
|
|
11
|
+
import { getApproval, getDelegation, getEntry } from "./service/records.js";
|
|
12
|
+
import { claimRelayOutbox, markRelayOutboxFailed, markRelayOutboxSucceeded, } from "./service/relay-lifecycle.js";
|
|
13
|
+
export { ActionApprovalDecisionConflictError, ActionApprovalDecisionStatusError, ActionLedgerIdempotencyConflictError, ActionLedgerReversalTargetError, } from "./service/errors.js";
|
|
14
|
+
export const actionLedgerService = {
|
|
15
|
+
async appendEntry(db, input) {
|
|
16
|
+
const existing = await findExistingIdempotentEntry(db, input);
|
|
17
|
+
if (existing) {
|
|
18
|
+
assertSameFingerprint(existing, input.idempotencyFingerprint ?? null);
|
|
19
|
+
return { entry: existing, replayed: true };
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
return await withOptionalTransaction(db, (tx) => insertEntry(tx, input));
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
const racedExisting = await findExistingIdempotentEntry(db, input);
|
|
26
|
+
if (racedExisting) {
|
|
27
|
+
assertSameFingerprint(racedExisting, input.idempotencyFingerprint ?? null);
|
|
28
|
+
return { entry: racedExisting, replayed: true };
|
|
29
|
+
}
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
async requestApproval(db, input) {
|
|
34
|
+
return withOptionalTransaction(db, async (tx) => {
|
|
35
|
+
const approvalId = newId("action_approvals");
|
|
36
|
+
const requestedActionResult = await actionLedgerService.appendEntry(tx, {
|
|
37
|
+
...input.requestedAction,
|
|
38
|
+
status: "awaiting_approval",
|
|
39
|
+
approvalId,
|
|
40
|
+
});
|
|
41
|
+
if (!requestedActionResult.entry.approvalId) {
|
|
42
|
+
throw new Error("Action approval requested action is missing its approval id");
|
|
43
|
+
}
|
|
44
|
+
const existingApproval = await findApprovalForRequestedAction(tx, requestedActionResult.entry.id);
|
|
45
|
+
if (existingApproval) {
|
|
46
|
+
return {
|
|
47
|
+
requestedAction: requestedActionResult.entry,
|
|
48
|
+
approval: existingApproval,
|
|
49
|
+
replayed: requestedActionResult.replayed,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const [approval] = await tx
|
|
53
|
+
.insert(actionApprovals)
|
|
54
|
+
.values({
|
|
55
|
+
id: requestedActionResult.entry.approvalId,
|
|
56
|
+
requestedActionId: requestedActionResult.entry.id,
|
|
57
|
+
status: "pending",
|
|
58
|
+
requestedByPrincipalId: input.approval.requestedByPrincipalId ?? requestedActionResult.entry.principalId,
|
|
59
|
+
assignedToPrincipalId: input.approval.assignedToPrincipalId ?? null,
|
|
60
|
+
delegatedFromPrincipalId: input.approval.delegatedFromPrincipalId ?? null,
|
|
61
|
+
policyName: input.approval.policyName,
|
|
62
|
+
policyVersion: input.approval.policyVersion,
|
|
63
|
+
targetSnapshotRef: input.approval.targetSnapshotRef ?? null,
|
|
64
|
+
riskSnapshot: input.approval.riskSnapshot ?? requestedActionResult.entry.evaluatedRisk,
|
|
65
|
+
reasonCode: input.approval.reasonCode ?? null,
|
|
66
|
+
expiresAt: input.approval.expiresAt ? parseCursorDate(input.approval.expiresAt) : null,
|
|
67
|
+
})
|
|
68
|
+
.returning();
|
|
69
|
+
if (!approval) {
|
|
70
|
+
throw new Error("Action approval insert did not return an approval");
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
requestedAction: requestedActionResult.entry,
|
|
74
|
+
approval,
|
|
75
|
+
replayed: requestedActionResult.replayed,
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
async decideApproval(db, input) {
|
|
80
|
+
assertApprovalDecisionStatus(input.status);
|
|
81
|
+
return withOptionalTransaction(db, async (tx) => {
|
|
82
|
+
const approval = await findApprovalById(tx, input.id);
|
|
83
|
+
if (!approval)
|
|
84
|
+
return null;
|
|
85
|
+
if (approval.status !== "pending") {
|
|
86
|
+
throw new ActionApprovalDecisionConflictError(approval.id, approval.status);
|
|
87
|
+
}
|
|
88
|
+
const decidedAt = input.decidedAt ? parseCursorDate(input.decidedAt) : new Date();
|
|
89
|
+
const [updatedApproval] = await tx
|
|
90
|
+
.update(actionApprovals)
|
|
91
|
+
.set({
|
|
92
|
+
status: input.status,
|
|
93
|
+
decidedByPrincipalId: input.decidedByPrincipalId,
|
|
94
|
+
decidedAt,
|
|
95
|
+
})
|
|
96
|
+
.where(and(eq(actionApprovals.id, input.id), eq(actionApprovals.status, "pending")))
|
|
97
|
+
.returning();
|
|
98
|
+
if (!updatedApproval) {
|
|
99
|
+
const current = await findApprovalById(tx, input.id);
|
|
100
|
+
if (!current)
|
|
101
|
+
return null;
|
|
102
|
+
throw new ActionApprovalDecisionConflictError(current.id, current.status);
|
|
103
|
+
}
|
|
104
|
+
const decisionAction = await actionLedgerService.appendEntry(tx, {
|
|
105
|
+
...input.decisionAction,
|
|
106
|
+
actionKind: input.status === "approved" ? "approve" : "reject",
|
|
107
|
+
status: input.status,
|
|
108
|
+
evaluatedRisk: input.decisionAction.evaluatedRisk ?? updatedApproval.riskSnapshot,
|
|
109
|
+
targetType: input.decisionAction.targetType ?? "action_approval",
|
|
110
|
+
targetId: input.decisionAction.targetId ?? updatedApproval.id,
|
|
111
|
+
causationActionId: updatedApproval.requestedActionId,
|
|
112
|
+
approvalId: updatedApproval.id,
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
approval: updatedApproval,
|
|
116
|
+
decisionAction: decisionAction.entry,
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
async recordReversal(db, input) {
|
|
121
|
+
return withOptionalTransaction(db, async (tx) => {
|
|
122
|
+
const original = await actionLedgerService.getEntry(tx, input.originalActionId);
|
|
123
|
+
if (!original)
|
|
124
|
+
return null;
|
|
125
|
+
if (!original.mutationDetail) {
|
|
126
|
+
throw new ActionLedgerReversalTargetError(input.originalActionId, "missing_mutation_detail");
|
|
127
|
+
}
|
|
128
|
+
if (original.mutationDetail.reversalKind === "none") {
|
|
129
|
+
throw new ActionLedgerReversalTargetError(input.originalActionId, "not_reversible");
|
|
130
|
+
}
|
|
131
|
+
const reversalResult = await actionLedgerService.appendEntry(tx, {
|
|
132
|
+
...input.reversalAction,
|
|
133
|
+
causationActionId: original.entry.id,
|
|
134
|
+
mutationDetail: {
|
|
135
|
+
commandInputRef: input.reversalAction.mutationDetail?.commandInputRef ?? null,
|
|
136
|
+
commandResultRef: input.reversalAction.mutationDetail?.commandResultRef ?? null,
|
|
137
|
+
summary: input.reversalAction.mutationDetail?.summary ?? null,
|
|
138
|
+
reversalKind: input.reversalAction.mutationDetail?.reversalKind ?? "none",
|
|
139
|
+
reversalCommandId: input.reversalAction.mutationDetail?.reversalCommandId ?? null,
|
|
140
|
+
reversalCommandVersion: input.reversalAction.mutationDetail?.reversalCommandVersion ?? null,
|
|
141
|
+
reversalArgsRef: input.reversalAction.mutationDetail?.reversalArgsRef ?? null,
|
|
142
|
+
reversalStateProjection: input.reversalAction.mutationDetail?.reversalStateProjection ?? null,
|
|
143
|
+
reversalOutcomeProjection: input.reversalAction.mutationDetail?.reversalOutcomeProjection ?? null,
|
|
144
|
+
reversesActionId: original.entry.id,
|
|
145
|
+
reversedByActionIdProjection: input.reversalAction.mutationDetail?.reversedByActionIdProjection ?? null,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
const defaultProjection = input.reversalAction.status === "failed"
|
|
149
|
+
? { reversalState: "failed", reversalOutcome: "failed" }
|
|
150
|
+
: { reversalState: "completed", reversalOutcome: "full" };
|
|
151
|
+
await tx
|
|
152
|
+
.update(actionMutationDetails)
|
|
153
|
+
.set({
|
|
154
|
+
reversalStateProjection: input.projection?.reversalState ?? defaultProjection.reversalState,
|
|
155
|
+
reversalOutcomeProjection: input.projection?.reversalOutcome ?? defaultProjection.reversalOutcome,
|
|
156
|
+
reversedByActionIdProjection: reversalResult.entry.id,
|
|
157
|
+
})
|
|
158
|
+
.where(eq(actionMutationDetails.actionId, original.entry.id));
|
|
159
|
+
return {
|
|
160
|
+
originalAction: original.entry,
|
|
161
|
+
originalMutationDetail: original.mutationDetail,
|
|
162
|
+
reversalAction: reversalResult.entry,
|
|
163
|
+
replayed: reversalResult.replayed,
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
listEntries,
|
|
168
|
+
listRelayOutbox,
|
|
169
|
+
listApprovals,
|
|
170
|
+
listDelegations,
|
|
171
|
+
getApproval,
|
|
172
|
+
async validateApprovedAction(db, input) {
|
|
173
|
+
const result = await actionLedgerService.getApproval(db, input.approvalId);
|
|
174
|
+
if (!result) {
|
|
175
|
+
return { ok: false, reason: "not_found" };
|
|
176
|
+
}
|
|
177
|
+
if (result.approval.status !== "approved") {
|
|
178
|
+
return {
|
|
179
|
+
ok: false,
|
|
180
|
+
reason: "not_approved",
|
|
181
|
+
approval: result.approval,
|
|
182
|
+
status: result.approval.status,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
const now = input.now ? parseCursorDate(input.now) : new Date();
|
|
186
|
+
if (result.approval.expiresAt && result.approval.expiresAt < now) {
|
|
187
|
+
return {
|
|
188
|
+
ok: false,
|
|
189
|
+
reason: "expired",
|
|
190
|
+
approval: result.approval,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
const requestedAction = result.requestedAction?.entry;
|
|
194
|
+
if (!requestedAction ||
|
|
195
|
+
requestedAction.actionName !== input.actionName ||
|
|
196
|
+
requestedAction.actionVersion !== input.actionVersion ||
|
|
197
|
+
(input.requestedActionKind && requestedAction.actionKind !== input.requestedActionKind) ||
|
|
198
|
+
(input.requestedActionStatus &&
|
|
199
|
+
!(Array.isArray(input.requestedActionStatus)
|
|
200
|
+
? input.requestedActionStatus
|
|
201
|
+
: [input.requestedActionStatus]).includes(requestedAction.status)) ||
|
|
202
|
+
requestedAction.targetType !== input.targetType ||
|
|
203
|
+
requestedAction.targetId !== input.targetId ||
|
|
204
|
+
requestedAction.routeOrToolName !== (input.routeOrToolName ?? null) ||
|
|
205
|
+
requestedAction.approvalId !== result.approval.id) {
|
|
206
|
+
return {
|
|
207
|
+
ok: false,
|
|
208
|
+
reason: "mismatched_action",
|
|
209
|
+
approval: result.approval,
|
|
210
|
+
requestedAction: requestedAction ?? undefined,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const existingExecution = await actionLedgerService.listEntries(db, {
|
|
214
|
+
actionName: input.actionName,
|
|
215
|
+
actionKind: input.executionActionKind,
|
|
216
|
+
targetType: input.targetType,
|
|
217
|
+
targetId: input.targetId,
|
|
218
|
+
causationActionId: requestedAction.id,
|
|
219
|
+
approvalId: result.approval.id,
|
|
220
|
+
status: input.executionStatus ?? "succeeded",
|
|
221
|
+
limit: 1,
|
|
222
|
+
});
|
|
223
|
+
if (existingExecution.entries.length > 0) {
|
|
224
|
+
return {
|
|
225
|
+
ok: false,
|
|
226
|
+
reason: "already_executed",
|
|
227
|
+
approval: result.approval,
|
|
228
|
+
requestedAction,
|
|
229
|
+
existingActionId: existingExecution.entries[0]?.id,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
if (!requestedAction.idempotencyFingerprint) {
|
|
233
|
+
return {
|
|
234
|
+
ok: false,
|
|
235
|
+
reason: "missing_fingerprint",
|
|
236
|
+
approval: result.approval,
|
|
237
|
+
requestedAction,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
if (input.idempotencyFingerprint !== requestedAction.idempotencyFingerprint) {
|
|
241
|
+
return {
|
|
242
|
+
ok: false,
|
|
243
|
+
reason: "fingerprint_mismatch",
|
|
244
|
+
approval: result.approval,
|
|
245
|
+
requestedAction,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
if (input.principalType &&
|
|
249
|
+
input.principalId &&
|
|
250
|
+
(requestedAction.principalType !== input.principalType ||
|
|
251
|
+
requestedAction.principalId !== input.principalId)) {
|
|
252
|
+
return {
|
|
253
|
+
ok: false,
|
|
254
|
+
reason: "principal_mismatch",
|
|
255
|
+
approval: result.approval,
|
|
256
|
+
requestedAction,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
ok: true,
|
|
261
|
+
approval: result.approval,
|
|
262
|
+
requestedAction,
|
|
263
|
+
idempotencyFingerprint: requestedAction.idempotencyFingerprint,
|
|
264
|
+
};
|
|
265
|
+
},
|
|
266
|
+
getDelegation,
|
|
267
|
+
claimRelayOutbox,
|
|
268
|
+
markRelayOutboxSucceeded,
|
|
269
|
+
markRelayOutboxFailed,
|
|
270
|
+
getEntry,
|
|
271
|
+
};
|
|
272
|
+
export const __test__ = {
|
|
273
|
+
buildActionApprovalsPredicate,
|
|
274
|
+
buildActionDelegationsPredicate,
|
|
275
|
+
buildActionLedgerEntriesPredicate,
|
|
276
|
+
buildActionLedgerRelayOutboxPredicate,
|
|
277
|
+
withOptionalTransaction,
|
|
278
|
+
normalizeListLimit,
|
|
279
|
+
toActionApprovalListCursor,
|
|
280
|
+
toActionDelegationListCursor,
|
|
281
|
+
toActionLedgerListCursor,
|
|
282
|
+
toActionLedgerRelayOutboxListCursor,
|
|
283
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ActionLedgerEntry } from "./schema.js";
|
|
3
|
+
export type ActionLedgerTimelineCursor = {
|
|
4
|
+
occurredAt: string;
|
|
5
|
+
id: string;
|
|
6
|
+
};
|
|
7
|
+
export type ActionLedgerSerializedEntry = Omit<ActionLedgerEntry, "occurredAt" | "createdAt"> & {
|
|
8
|
+
occurredAt: string;
|
|
9
|
+
createdAt: string;
|
|
10
|
+
};
|
|
11
|
+
export type ActionLedgerTargetTimelineEntry = ActionLedgerSerializedEntry & {
|
|
12
|
+
mutationSummary: string | null;
|
|
13
|
+
};
|
|
14
|
+
export interface ActionLedgerTargetTimelinePage {
|
|
15
|
+
data: ActionLedgerTargetTimelineEntry[];
|
|
16
|
+
pageInfo: {
|
|
17
|
+
nextCursor: ActionLedgerTimelineCursor | null;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export declare const actionLedgerTargetTimelineQuerySchema: z.ZodPipe<z.ZodObject<{
|
|
21
|
+
cursorOccurredAt: z.ZodOptional<z.ZodString>;
|
|
22
|
+
cursorId: z.ZodOptional<z.ZodString>;
|
|
23
|
+
limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
24
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
25
|
+
cursor: {
|
|
26
|
+
occurredAt: string;
|
|
27
|
+
id: string;
|
|
28
|
+
} | undefined;
|
|
29
|
+
limit?: number | undefined;
|
|
30
|
+
}, {
|
|
31
|
+
cursorOccurredAt?: string | undefined;
|
|
32
|
+
cursorId?: string | undefined;
|
|
33
|
+
limit?: number | undefined;
|
|
34
|
+
}>>;
|
|
35
|
+
export type ActionLedgerTargetTimelineQuery = z.infer<typeof actionLedgerTargetTimelineQuerySchema>;
|
|
36
|
+
export declare function serializeActionLedgerDate(value: Date | string): string;
|
|
37
|
+
export declare function serializeActionLedgerEntry(entry: ActionLedgerEntry): ActionLedgerSerializedEntry;
|
|
38
|
+
export declare function toActionLedgerTimelineCursor(entry: Pick<ActionLedgerEntry, "occurredAt" | "id">): ActionLedgerTimelineCursor;
|
|
39
|
+
export declare function sortActionLedgerTimelineEntries(entries: ActionLedgerEntry[]): ActionLedgerEntry[];
|
|
40
|
+
export declare function buildActionLedgerTargetTimelinePage({ entries, limit, mutationSummariesByActionId, }: {
|
|
41
|
+
entries: ActionLedgerEntry[];
|
|
42
|
+
limit: number;
|
|
43
|
+
mutationSummariesByActionId?: ReadonlyMap<string, string | null>;
|
|
44
|
+
}): ActionLedgerTargetTimelinePage;
|
|
45
|
+
export declare const __test__: {
|
|
46
|
+
actionLedgerTargetTimelineQuerySchema: z.ZodPipe<z.ZodObject<{
|
|
47
|
+
cursorOccurredAt: z.ZodOptional<z.ZodString>;
|
|
48
|
+
cursorId: z.ZodOptional<z.ZodString>;
|
|
49
|
+
limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
50
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
51
|
+
cursor: {
|
|
52
|
+
occurredAt: string;
|
|
53
|
+
id: string;
|
|
54
|
+
} | undefined;
|
|
55
|
+
limit?: number | undefined;
|
|
56
|
+
}, {
|
|
57
|
+
cursorOccurredAt?: string | undefined;
|
|
58
|
+
cursorId?: string | undefined;
|
|
59
|
+
limit?: number | undefined;
|
|
60
|
+
}>>;
|
|
61
|
+
buildActionLedgerTargetTimelinePage: typeof buildActionLedgerTargetTimelinePage;
|
|
62
|
+
serializeActionLedgerDate: typeof serializeActionLedgerDate;
|
|
63
|
+
serializeActionLedgerEntry: typeof serializeActionLedgerEntry;
|
|
64
|
+
sortActionLedgerTimelineEntries: typeof sortActionLedgerTimelineEntries;
|
|
65
|
+
toActionLedgerTimelineCursor: typeof toActionLedgerTimelineCursor;
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=timeline.d.ts.map
|