cvx-kit 0.0.1
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 +21 -0
- package/README.md +200 -0
- package/dist/_virtual/_rolldown/runtime.mjs +1 -0
- package/dist/auth.d.mts +353 -0
- package/dist/auth.mjs +2 -0
- package/dist/auth.mjs.map +1 -0
- package/dist/components/approvals/_generated/api.d.mts +47 -0
- package/dist/components/approvals/_generated/api.mjs +2 -0
- package/dist/components/approvals/_generated/api.mjs.map +1 -0
- package/dist/components/approvals/_generated/component.d.mts +297 -0
- package/dist/components/approvals/_generated/component.mjs +1 -0
- package/dist/components/approvals/_generated/dataModel.d.mts +41 -0
- package/dist/components/approvals/_generated/dataModel.mjs +1 -0
- package/dist/components/approvals/_generated/server.d.mts +116 -0
- package/dist/components/approvals/_generated/server.mjs +2 -0
- package/dist/components/approvals/_generated/server.mjs.map +1 -0
- package/dist/components/approvals/audit.d.mts +40 -0
- package/dist/components/approvals/audit.mjs +2 -0
- package/dist/components/approvals/audit.mjs.map +1 -0
- package/dist/components/approvals/client.d.mts +98 -0
- package/dist/components/approvals/client.mjs +2 -0
- package/dist/components/approvals/client.mjs.map +1 -0
- package/dist/components/approvals/constants.d.mts +31 -0
- package/dist/components/approvals/constants.mjs +2 -0
- package/dist/components/approvals/constants.mjs.map +1 -0
- package/dist/components/approvals/convex.config.d.mts +5 -0
- package/dist/components/approvals/convex.config.mjs +2 -0
- package/dist/components/approvals/convex.config.mjs.map +1 -0
- package/dist/components/approvals/decisions.d.mts +61 -0
- package/dist/components/approvals/decisions.mjs +2 -0
- package/dist/components/approvals/decisions.mjs.map +1 -0
- package/dist/components/approvals/functions.d.mts +9 -0
- package/dist/components/approvals/functions.mjs +2 -0
- package/dist/components/approvals/functions.mjs.map +1 -0
- package/dist/components/approvals/requests.d.mts +323 -0
- package/dist/components/approvals/requests.mjs +2 -0
- package/dist/components/approvals/requests.mjs.map +1 -0
- package/dist/components/approvals/schema.d.mts +376 -0
- package/dist/components/approvals/schema.mjs +2 -0
- package/dist/components/approvals/schema.mjs.map +1 -0
- package/dist/components/approvals/validators.d.mts +302 -0
- package/dist/components/approvals/validators.mjs +2 -0
- package/dist/components/approvals/validators.mjs.map +1 -0
- package/dist/components/approvals/workflow.d.mts +11 -0
- package/dist/components/approvals/workflow.mjs +2 -0
- package/dist/components/approvals/workflow.mjs.map +1 -0
- package/dist/components/approvals/workflow_steps.d.mts +83 -0
- package/dist/components/approvals/workflow_steps.mjs +2 -0
- package/dist/components/approvals/workflow_steps.mjs.map +1 -0
- package/dist/components/foundation/_generated/api.d.mts +40 -0
- package/dist/components/foundation/_generated/api.mjs +2 -0
- package/dist/components/foundation/_generated/api.mjs.map +1 -0
- package/dist/components/foundation/_generated/component.d.mts +21 -0
- package/dist/components/foundation/_generated/component.mjs +1 -0
- package/dist/components/foundation/_generated/dataModel.d.mts +41 -0
- package/dist/components/foundation/_generated/dataModel.mjs +1 -0
- package/dist/components/foundation/_generated/server.d.mts +116 -0
- package/dist/components/foundation/_generated/server.mjs +2 -0
- package/dist/components/foundation/_generated/server.mjs.map +1 -0
- package/dist/components/foundation/client.d.mts +93 -0
- package/dist/components/foundation/client.mjs +2 -0
- package/dist/components/foundation/client.mjs.map +1 -0
- package/dist/components/foundation/convex.config.d.mts +5 -0
- package/dist/components/foundation/convex.config.mjs +2 -0
- package/dist/components/foundation/convex.config.mjs.map +1 -0
- package/dist/components/foundation/functions.d.mts +8 -0
- package/dist/components/foundation/functions.mjs +2 -0
- package/dist/components/foundation/functions.mjs.map +1 -0
- package/dist/components/foundation/modules/command/command.d.mts +47 -0
- package/dist/components/foundation/modules/command/command.mjs +2 -0
- package/dist/components/foundation/modules/command/command.mjs.map +1 -0
- package/dist/components/foundation/modules/observability/observability.d.mts +31 -0
- package/dist/components/foundation/modules/observability/observability.mjs +2 -0
- package/dist/components/foundation/modules/observability/observability.mjs.map +1 -0
- package/dist/components/foundation/modules/query/query.d.mts +24 -0
- package/dist/components/foundation/modules/query/query.mjs +2 -0
- package/dist/components/foundation/modules/query/query.mjs.map +1 -0
- package/dist/components/foundation/result.d.mts +27 -0
- package/dist/components/foundation/result.mjs +2 -0
- package/dist/components/foundation/result.mjs.map +1 -0
- package/dist/components/foundation/schema.d.mts +6 -0
- package/dist/components/foundation/schema.mjs +2 -0
- package/dist/components/foundation/schema.mjs.map +1 -0
- package/dist/components/foundation/telemetry.d.mts +9 -0
- package/dist/components/foundation/telemetry.mjs +2 -0
- package/dist/components/foundation/telemetry.mjs.map +1 -0
- package/dist/errors.d.mts +24 -0
- package/dist/errors.mjs +2 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +1 -0
- package/dist/triggers.d.mts +27 -0
- package/dist/triggers.mjs +2 -0
- package/dist/triggers.mjs.map +1 -0
- package/dist/zod-table.d.mts +124 -0
- package/dist/zod-table.mjs +2 -0
- package/dist/zod-table.mjs.map +1 -0
- package/package.json +108 -0
- package/src/auth.ts +360 -0
- package/src/components/approvals/_generated/api.ts +69 -0
- package/src/components/approvals/_generated/component.ts +335 -0
- package/src/components/approvals/_generated/dataModel.ts +60 -0
- package/src/components/approvals/_generated/server.ts +156 -0
- package/src/components/approvals/audit.ts +148 -0
- package/src/components/approvals/client.ts +321 -0
- package/src/components/approvals/constants.ts +51 -0
- package/src/components/approvals/convex.config.ts +10 -0
- package/src/components/approvals/decisions.ts +376 -0
- package/src/components/approvals/functions.ts +27 -0
- package/src/components/approvals/requests.ts +240 -0
- package/src/components/approvals/schema.ts +23 -0
- package/src/components/approvals/validators.ts +272 -0
- package/src/components/approvals/workflow.ts +204 -0
- package/src/components/approvals/workflow_steps.ts +189 -0
- package/src/components/foundation/_generated/api.ts +62 -0
- package/src/components/foundation/_generated/component.ts +29 -0
- package/src/components/foundation/_generated/dataModel.ts +60 -0
- package/src/components/foundation/_generated/server.ts +156 -0
- package/src/components/foundation/client.ts +190 -0
- package/src/components/foundation/convex.config.ts +3 -0
- package/src/components/foundation/functions.ts +10 -0
- package/src/components/foundation/modules/command/__tests__/command.test.ts +106 -0
- package/src/components/foundation/modules/command/command.ts +154 -0
- package/src/components/foundation/modules/observability/__tests__/observability.test.ts +79 -0
- package/src/components/foundation/modules/observability/observability.ts +95 -0
- package/src/components/foundation/modules/query/__tests__/query.test.ts +25 -0
- package/src/components/foundation/modules/query/query.ts +47 -0
- package/src/components/foundation/result.ts +77 -0
- package/src/components/foundation/schema.ts +4 -0
- package/src/components/foundation/telemetry.ts +23 -0
- package/src/errors.ts +25 -0
- package/src/index.ts +41 -0
- package/src/test.ts +36 -0
- package/src/triggers.ts +90 -0
- package/src/zod-table.ts +197 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
declare namespace requests_d_exports {
|
|
2
|
+
export { cancel, getForWorkflow, list, recordExecutionTerminal, restart, start, status };
|
|
3
|
+
}
|
|
4
|
+
declare const start: import("convex/server").RegisteredMutation<"public", {
|
|
5
|
+
metadata?: Record<string, string> | undefined;
|
|
6
|
+
requester: {
|
|
7
|
+
actorRef: string;
|
|
8
|
+
capabilities: string[];
|
|
9
|
+
metadata?: {
|
|
10
|
+
[x: string]: string;
|
|
11
|
+
} | undefined;
|
|
12
|
+
};
|
|
13
|
+
resourceRef: string;
|
|
14
|
+
resourceType: string;
|
|
15
|
+
scopeRef: string;
|
|
16
|
+
workflow: {
|
|
17
|
+
schemaVersion: 1;
|
|
18
|
+
compatibilityKey: string;
|
|
19
|
+
name: string;
|
|
20
|
+
steps: ({
|
|
21
|
+
kind: "mutation";
|
|
22
|
+
key: string;
|
|
23
|
+
callback: {
|
|
24
|
+
kind: "mutation";
|
|
25
|
+
handle: string;
|
|
26
|
+
retry: boolean;
|
|
27
|
+
};
|
|
28
|
+
} | {
|
|
29
|
+
kind: "action";
|
|
30
|
+
key: string;
|
|
31
|
+
callback: {
|
|
32
|
+
kind: "action";
|
|
33
|
+
handle: string;
|
|
34
|
+
retry: boolean;
|
|
35
|
+
};
|
|
36
|
+
} | {
|
|
37
|
+
kind: "notify";
|
|
38
|
+
key: string;
|
|
39
|
+
callback: {
|
|
40
|
+
kind: "action";
|
|
41
|
+
handle: string;
|
|
42
|
+
retry: boolean;
|
|
43
|
+
};
|
|
44
|
+
} | {
|
|
45
|
+
kind: "decision";
|
|
46
|
+
key: string;
|
|
47
|
+
decisions: ("approved" | "rejected")[];
|
|
48
|
+
quorum: {
|
|
49
|
+
kind: "count";
|
|
50
|
+
approvals: number;
|
|
51
|
+
};
|
|
52
|
+
makerChecker: boolean;
|
|
53
|
+
expiresAfterMs?: number | undefined;
|
|
54
|
+
} | {
|
|
55
|
+
kind: "branch";
|
|
56
|
+
key: string;
|
|
57
|
+
approvedStepKey: string;
|
|
58
|
+
rejectedStepKey: string;
|
|
59
|
+
})[];
|
|
60
|
+
};
|
|
61
|
+
}, Promise<{
|
|
62
|
+
runId: import("convex/values").GenericId<"approvalRuns">;
|
|
63
|
+
}>>;
|
|
64
|
+
declare const cancel: import("convex/server").RegisteredMutation<"public", {
|
|
65
|
+
actor: {
|
|
66
|
+
actorRef: string;
|
|
67
|
+
capabilities: string[];
|
|
68
|
+
metadata?: {
|
|
69
|
+
[x: string]: string;
|
|
70
|
+
} | undefined;
|
|
71
|
+
};
|
|
72
|
+
compatibilityKey: string;
|
|
73
|
+
runId: import("convex/values").GenericId<"approvalRuns">;
|
|
74
|
+
}, Promise<{
|
|
75
|
+
state: 'canceled';
|
|
76
|
+
}>>;
|
|
77
|
+
declare const restart: import("convex/server").RegisteredMutation<"public", {
|
|
78
|
+
compatibilityKey: string;
|
|
79
|
+
runId: import("convex/values").GenericId<"approvalRuns">;
|
|
80
|
+
}, Promise<null>>;
|
|
81
|
+
declare const status: import("convex/server").RegisteredQuery<"public", {
|
|
82
|
+
compatibilityKey: string;
|
|
83
|
+
runId: import("convex/values").GenericId<"approvalRuns">;
|
|
84
|
+
}, Promise<{
|
|
85
|
+
run: {
|
|
86
|
+
_creationTime: number;
|
|
87
|
+
_id: import("convex/values").GenericId<"approvalRuns">;
|
|
88
|
+
scopeRef: string;
|
|
89
|
+
resourceType: string;
|
|
90
|
+
resourceRef: string;
|
|
91
|
+
requester: {
|
|
92
|
+
actorRef: string;
|
|
93
|
+
capabilities: string[];
|
|
94
|
+
metadata?: {
|
|
95
|
+
[x: string]: string;
|
|
96
|
+
} | undefined;
|
|
97
|
+
};
|
|
98
|
+
metadata?: {
|
|
99
|
+
[x: string]: string;
|
|
100
|
+
} | undefined;
|
|
101
|
+
workflow: {
|
|
102
|
+
schemaVersion: 1;
|
|
103
|
+
compatibilityKey: string;
|
|
104
|
+
name: string;
|
|
105
|
+
steps: ({
|
|
106
|
+
kind: "mutation";
|
|
107
|
+
key: string;
|
|
108
|
+
callback: {
|
|
109
|
+
kind: "mutation";
|
|
110
|
+
handle: string;
|
|
111
|
+
retry: boolean;
|
|
112
|
+
};
|
|
113
|
+
} | {
|
|
114
|
+
kind: "action";
|
|
115
|
+
key: string;
|
|
116
|
+
callback: {
|
|
117
|
+
kind: "action";
|
|
118
|
+
handle: string;
|
|
119
|
+
retry: boolean;
|
|
120
|
+
};
|
|
121
|
+
} | {
|
|
122
|
+
kind: "notify";
|
|
123
|
+
key: string;
|
|
124
|
+
callback: {
|
|
125
|
+
kind: "action";
|
|
126
|
+
handle: string;
|
|
127
|
+
retry: boolean;
|
|
128
|
+
};
|
|
129
|
+
} | {
|
|
130
|
+
kind: "decision";
|
|
131
|
+
key: string;
|
|
132
|
+
decisions: ("approved" | "rejected")[];
|
|
133
|
+
quorum: {
|
|
134
|
+
kind: "count";
|
|
135
|
+
approvals: number;
|
|
136
|
+
};
|
|
137
|
+
makerChecker: boolean;
|
|
138
|
+
expiresAfterMs?: number | undefined;
|
|
139
|
+
} | {
|
|
140
|
+
kind: "branch";
|
|
141
|
+
key: string;
|
|
142
|
+
approvedStepKey: string;
|
|
143
|
+
rejectedStepKey: string;
|
|
144
|
+
})[];
|
|
145
|
+
};
|
|
146
|
+
state: "approved" | "canceled" | "expired" | "pending" | "rejected";
|
|
147
|
+
currentStepKey?: string | undefined;
|
|
148
|
+
executionFailedStepKey?: string | undefined;
|
|
149
|
+
expiresAt?: number | undefined;
|
|
150
|
+
workflowId?: string | undefined;
|
|
151
|
+
createdAt: number;
|
|
152
|
+
updatedAt: number;
|
|
153
|
+
terminalAt?: number | undefined;
|
|
154
|
+
};
|
|
155
|
+
execution: {
|
|
156
|
+
type: 'failed';
|
|
157
|
+
error: string;
|
|
158
|
+
} | {
|
|
159
|
+
error?: undefined;
|
|
160
|
+
type: "canceled" | "completed" | "inProgress";
|
|
161
|
+
} | null;
|
|
162
|
+
} | null>>;
|
|
163
|
+
declare const list: import("convex/server").RegisteredQuery<"public", {
|
|
164
|
+
paginationOpts: {
|
|
165
|
+
id?: number;
|
|
166
|
+
endCursor?: string | null;
|
|
167
|
+
maximumRowsRead?: number;
|
|
168
|
+
maximumBytesRead?: number;
|
|
169
|
+
numItems: number;
|
|
170
|
+
cursor: string | null;
|
|
171
|
+
};
|
|
172
|
+
scopeRef: string;
|
|
173
|
+
state?: "approved" | "canceled" | "expired" | "pending" | "rejected" | undefined;
|
|
174
|
+
}, Promise<import("convex/server").PaginationResult<{
|
|
175
|
+
_creationTime: number;
|
|
176
|
+
_id: import("convex/values").GenericId<"approvalRuns">;
|
|
177
|
+
scopeRef: string;
|
|
178
|
+
resourceType: string;
|
|
179
|
+
resourceRef: string;
|
|
180
|
+
requester: {
|
|
181
|
+
actorRef: string;
|
|
182
|
+
capabilities: string[];
|
|
183
|
+
metadata?: {
|
|
184
|
+
[x: string]: string;
|
|
185
|
+
} | undefined;
|
|
186
|
+
};
|
|
187
|
+
metadata?: {
|
|
188
|
+
[x: string]: string;
|
|
189
|
+
} | undefined;
|
|
190
|
+
workflow: {
|
|
191
|
+
schemaVersion: 1;
|
|
192
|
+
compatibilityKey: string;
|
|
193
|
+
name: string;
|
|
194
|
+
steps: ({
|
|
195
|
+
kind: "mutation";
|
|
196
|
+
key: string;
|
|
197
|
+
callback: {
|
|
198
|
+
kind: "mutation";
|
|
199
|
+
handle: string;
|
|
200
|
+
retry: boolean;
|
|
201
|
+
};
|
|
202
|
+
} | {
|
|
203
|
+
kind: "action";
|
|
204
|
+
key: string;
|
|
205
|
+
callback: {
|
|
206
|
+
kind: "action";
|
|
207
|
+
handle: string;
|
|
208
|
+
retry: boolean;
|
|
209
|
+
};
|
|
210
|
+
} | {
|
|
211
|
+
kind: "notify";
|
|
212
|
+
key: string;
|
|
213
|
+
callback: {
|
|
214
|
+
kind: "action";
|
|
215
|
+
handle: string;
|
|
216
|
+
retry: boolean;
|
|
217
|
+
};
|
|
218
|
+
} | {
|
|
219
|
+
kind: "decision";
|
|
220
|
+
key: string;
|
|
221
|
+
decisions: ("approved" | "rejected")[];
|
|
222
|
+
quorum: {
|
|
223
|
+
kind: "count";
|
|
224
|
+
approvals: number;
|
|
225
|
+
};
|
|
226
|
+
makerChecker: boolean;
|
|
227
|
+
expiresAfterMs?: number | undefined;
|
|
228
|
+
} | {
|
|
229
|
+
kind: "branch";
|
|
230
|
+
key: string;
|
|
231
|
+
approvedStepKey: string;
|
|
232
|
+
rejectedStepKey: string;
|
|
233
|
+
})[];
|
|
234
|
+
};
|
|
235
|
+
state: "approved" | "canceled" | "expired" | "pending" | "rejected";
|
|
236
|
+
currentStepKey?: string | undefined;
|
|
237
|
+
executionFailedStepKey?: string | undefined;
|
|
238
|
+
expiresAt?: number | undefined;
|
|
239
|
+
workflowId?: string | undefined;
|
|
240
|
+
createdAt: number;
|
|
241
|
+
updatedAt: number;
|
|
242
|
+
terminalAt?: number | undefined;
|
|
243
|
+
}>>>;
|
|
244
|
+
declare const getForWorkflow: import("convex/server").RegisteredQuery<"internal", {
|
|
245
|
+
runId: import("convex/values").GenericId<"approvalRuns">;
|
|
246
|
+
}, Promise<{
|
|
247
|
+
_creationTime: number;
|
|
248
|
+
_id: import("convex/values").GenericId<"approvalRuns">;
|
|
249
|
+
scopeRef: string;
|
|
250
|
+
resourceType: string;
|
|
251
|
+
resourceRef: string;
|
|
252
|
+
requester: {
|
|
253
|
+
actorRef: string;
|
|
254
|
+
capabilities: string[];
|
|
255
|
+
metadata?: {
|
|
256
|
+
[x: string]: string;
|
|
257
|
+
} | undefined;
|
|
258
|
+
};
|
|
259
|
+
metadata?: {
|
|
260
|
+
[x: string]: string;
|
|
261
|
+
} | undefined;
|
|
262
|
+
workflow: {
|
|
263
|
+
schemaVersion: 1;
|
|
264
|
+
compatibilityKey: string;
|
|
265
|
+
name: string;
|
|
266
|
+
steps: ({
|
|
267
|
+
kind: "mutation";
|
|
268
|
+
key: string;
|
|
269
|
+
callback: {
|
|
270
|
+
kind: "mutation";
|
|
271
|
+
handle: string;
|
|
272
|
+
retry: boolean;
|
|
273
|
+
};
|
|
274
|
+
} | {
|
|
275
|
+
kind: "action";
|
|
276
|
+
key: string;
|
|
277
|
+
callback: {
|
|
278
|
+
kind: "action";
|
|
279
|
+
handle: string;
|
|
280
|
+
retry: boolean;
|
|
281
|
+
};
|
|
282
|
+
} | {
|
|
283
|
+
kind: "notify";
|
|
284
|
+
key: string;
|
|
285
|
+
callback: {
|
|
286
|
+
kind: "action";
|
|
287
|
+
handle: string;
|
|
288
|
+
retry: boolean;
|
|
289
|
+
};
|
|
290
|
+
} | {
|
|
291
|
+
kind: "decision";
|
|
292
|
+
key: string;
|
|
293
|
+
decisions: ("approved" | "rejected")[];
|
|
294
|
+
quorum: {
|
|
295
|
+
kind: "count";
|
|
296
|
+
approvals: number;
|
|
297
|
+
};
|
|
298
|
+
makerChecker: boolean;
|
|
299
|
+
expiresAfterMs?: number | undefined;
|
|
300
|
+
} | {
|
|
301
|
+
kind: "branch";
|
|
302
|
+
key: string;
|
|
303
|
+
approvedStepKey: string;
|
|
304
|
+
rejectedStepKey: string;
|
|
305
|
+
})[];
|
|
306
|
+
};
|
|
307
|
+
state: "approved" | "canceled" | "expired" | "pending" | "rejected";
|
|
308
|
+
currentStepKey?: string | undefined;
|
|
309
|
+
executionFailedStepKey?: string | undefined;
|
|
310
|
+
expiresAt?: number | undefined;
|
|
311
|
+
workflowId?: string | undefined;
|
|
312
|
+
createdAt: number;
|
|
313
|
+
updatedAt: number;
|
|
314
|
+
terminalAt?: number | undefined;
|
|
315
|
+
} | null>>;
|
|
316
|
+
declare const recordExecutionTerminal: import("convex/server").RegisteredMutation<"internal", {
|
|
317
|
+
failedStepKey?: string | undefined;
|
|
318
|
+
outcome: "completed" | "failed";
|
|
319
|
+
runId: import("convex/values").GenericId<"approvalRuns">;
|
|
320
|
+
}, Promise<null>>;
|
|
321
|
+
//#endregion
|
|
322
|
+
export { cancel, getForWorkflow, list, recordExecutionTerminal, requests_d_exports, restart, start, status };
|
|
323
|
+
//# sourceMappingURL=requests.d.mts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{components as e,internal as t}from"./_generated/api.mjs";import{internalMutation as n,internalQuery as r,mutation as i,query as a}from"./_generated/server.mjs";import{APPROVAL_EXECUTION_STATES as o,APPROVAL_RUN_STATES as s}from"./constants.mjs";import{logApprovalTransition as c}from"./audit.mjs";import{approvalActor as l,approvalMetadata as u,approvalName as d,approvalReference as f,approvalRunDocument as p,approvalRunState as m,approvalWorkflowDescriptor as h}from"./validators.mjs";import{canTransitionApprovalRun as g}from"./functions.mjs";import{zodToConvex as _}from"convex-helpers/server/zod4";import{paginationOptsValidator as v,paginationResultValidator as y}from"convex/server";import{v as b}from"convex/values";import{WorkflowManager as x}from"@convex-dev/workflow";const S=i({args:{scopeRef:_(f),resourceType:_(f),resourceRef:_(f),requester:_(l),metadata:b.optional(_(u)),workflow:_(h)},returns:b.object({runId:b.id(`approvalRuns`)}),handler:async(e,n)=>{let r=Date.now(),i=await e.db.insert(`approvalRuns`,{...n,state:`pending`,createdAt:r,updatedAt:r}),a=await k.start(e,t.workflow.run,{runId:i},{startAsync:!0});return await e.db.patch(i,{workflowId:a,updatedAt:Date.now()}),await c(e,{action:`approval.requested`,actorRef:n.requester.actorRef,runId:i,resourceType:n.resourceType,resourceRef:n.resourceRef,transition:`requested`}),{runId:i}}}),C=i({args:{runId:b.id(`approvalRuns`),actor:_(l),compatibilityKey:b.string()},returns:b.object({state:b.literal(s[4])}),handler:async(e,t)=>{let n=await e.db.get(t.runId);if(!n)throw Error(`Approval request not found`);if(P(n.workflow.compatibilityKey,t.compatibilityKey),n.state!==`pending`){if(n.state===`canceled`)return{state:`canceled`};throw Error(`Approval request is already ${n.state}`)}if(!n.workflowId)throw Error(`Approval workflow is not linked`);if(await k.cancel(e,n.workflowId),!g(n.state,`canceled`))throw Error(`Approval request cannot transition from ${n.state}`);let r=Date.now();return await e.db.patch(n._id,{state:`canceled`,expiresAt:void 0,updatedAt:r,terminalAt:r}),await c(e,{action:`approval.canceled`,actorRef:t.actor.actorRef,runId:n._id,resourceType:n.resourceType,resourceRef:n.resourceRef,transition:`canceled`}),{state:`canceled`}}}),w=i({args:{runId:b.id(`approvalRuns`),compatibilityKey:b.string()},returns:b.null(),handler:async(e,t)=>{let n=await e.db.get(t.runId);if(!n)throw Error(`Approval request not found`);if(P(n.workflow.compatibilityKey,t.compatibilityKey),!n.workflowId)throw Error(`Approval workflow is not linked`);if(!n.executionFailedStepKey)throw Error(`Approval workflow has no failed step to restart`);return await k.restart(e,n.workflowId,{from:n.executionFailedStepKey,startAsync:!0}),null}}),T=a({args:{runId:b.id(`approvalRuns`),compatibilityKey:b.string()},returns:b.union(b.null(),N()),handler:async(e,t)=>{let n=await e.db.get(t.runId);return n?(P(n.workflow.compatibilityKey,t.compatibilityKey),{run:n,execution:A(n.workflowId?await k.status(e,n.workflowId):null)}):null}}),E=a({args:{scopeRef:_(f),state:b.optional(_(m)),paginationOpts:v},returns:y(j()),handler:(e,t)=>e.db.query(`approvalRuns`).withIndex(`by_scopeRef_and_state`,e=>t.state===void 0?e.eq(`scopeRef`,t.scopeRef):e.eq(`scopeRef`,t.scopeRef).eq(`state`,t.state)).order(`desc`).paginate(t.paginationOpts)}),D=r({args:{runId:b.id(`approvalRuns`)},returns:b.union(b.null(),j()),handler:(e,t)=>e.db.get(t.runId)}),O=n({args:{runId:b.id(`approvalRuns`),outcome:b.union(b.literal(o[1]),b.literal(o[3])),failedStepKey:b.optional(_(d))},returns:b.null(),handler:async(e,t)=>{let n=await e.db.get(t.runId);if(!n)throw Error(`Approval request not found`);return await e.db.patch(n._id,{executionFailedStepKey:t.outcome===`failed`?t.failedStepKey:void 0,updatedAt:Date.now()}),await c(e,{action:`approval.execution.${t.outcome}`,runId:n._id,resourceType:n.resourceType,resourceRef:n.resourceRef,transition:`execution:${t.outcome}`,severity:t.outcome===`failed`?`error`:`info`}),null}}),k=new x(e.workflow);function A(e){if(!e)return null;switch(e.type){case`failed`:return{type:`failed`,error:e.error};case`inProgress`:case`completed`:case`canceled`:return{type:e.type}}}function j(){return b.object({_id:b.id(`approvalRuns`),_creationTime:b.number(),..._(p).fields})}function M(){return b.union(b.object({type:b.literal(o[0])}),b.object({type:b.literal(o[1])}),b.object({type:b.literal(o[2])}),b.object({type:b.literal(o[3]),error:b.string()}))}function N(){return b.object({run:j(),execution:b.union(b.null(),M())})}function P(e,t){if(e!==t)throw Error(`Approval workflow compatibility mismatch: expected ${t}, received ${e}`)}export{C as cancel,D as getForWorkflow,E as list,O as recordExecutionTerminal,w as restart,S as start,T as status};
|
|
2
|
+
//# sourceMappingURL=requests.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requests.mjs","names":[],"sources":["../../../src/components/approvals/requests.ts"],"sourcesContent":["import { WorkflowManager, type WorkflowId } from '@convex-dev/workflow'\nimport { zodToConvex } from 'convex-helpers/server/zod4'\nimport {\n\tpaginationOptsValidator,\n\tpaginationResultValidator,\n} from 'convex/server'\nimport { v } from 'convex/values'\n\nimport { components, internal } from './_generated/api'\nimport {\n\tinternalMutation,\n\tinternalQuery,\n\tmutation,\n\tquery,\n} from './_generated/server'\nimport { logApprovalTransition } from './audit'\nimport { APPROVAL_EXECUTION_STATES, APPROVAL_RUN_STATES } from './constants'\nimport { canTransitionApprovalRun } from './functions'\nimport {\n\tapprovalActor,\n\tapprovalMetadata,\n\tapprovalName,\n\tapprovalReference,\n\tapprovalRunDocument,\n\tapprovalRunState,\n\tapprovalWorkflowDescriptor,\n} from './validators'\n\nexport const start = mutation({\n\targs: {\n\t\tscopeRef: zodToConvex(approvalReference),\n\t\tresourceType: zodToConvex(approvalReference),\n\t\tresourceRef: zodToConvex(approvalReference),\n\t\trequester: zodToConvex(approvalActor),\n\t\tmetadata: v.optional(zodToConvex(approvalMetadata)),\n\t\tworkflow: zodToConvex(approvalWorkflowDescriptor),\n\t},\n\treturns: v.object({ runId: v.id('approvalRuns') }),\n\thandler: async (ctx, input) => {\n\t\tconst now = Date.now()\n\t\tconst runId = await ctx.db.insert('approvalRuns', {\n\t\t\t...input,\n\t\t\tstate: 'pending',\n\t\t\tcreatedAt: now,\n\t\t\tupdatedAt: now,\n\t\t})\n\t\tconst workflowId: WorkflowId = await approvalWorkflow.start(\n\t\t\tctx,\n\t\t\tinternal.workflow.run,\n\t\t\t{ runId },\n\t\t\t{ startAsync: true },\n\t\t)\n\t\tawait ctx.db.patch(runId, { workflowId, updatedAt: Date.now() })\n\t\tawait logApprovalTransition(ctx, {\n\t\t\taction: 'approval.requested',\n\t\t\tactorRef: input.requester.actorRef,\n\t\t\trunId,\n\t\t\tresourceType: input.resourceType,\n\t\t\tresourceRef: input.resourceRef,\n\t\t\ttransition: 'requested',\n\t\t})\n\t\treturn { runId }\n\t},\n})\n\nexport const cancel = mutation({\n\targs: {\n\t\trunId: v.id('approvalRuns'),\n\t\tactor: zodToConvex(approvalActor),\n\t\tcompatibilityKey: v.string(),\n\t},\n\treturns: v.object({ state: v.literal(APPROVAL_RUN_STATES[4]) }),\n\thandler: async (ctx, input) => {\n\t\tconst run = await ctx.db.get(input.runId)\n\t\tif (!run) throw new Error('Approval request not found')\n\t\tassertCompatible(run.workflow.compatibilityKey, input.compatibilityKey)\n\t\tif (run.state !== 'pending') {\n\t\t\tif (run.state === 'canceled') return { state: 'canceled' as const }\n\t\t\tthrow new Error(`Approval request is already ${run.state}`)\n\t\t}\n\t\tif (!run.workflowId) throw new Error('Approval workflow is not linked')\n\t\tawait approvalWorkflow.cancel(ctx, run.workflowId as WorkflowId)\n\t\tif (!canTransitionApprovalRun(run.state, 'canceled'))\n\t\t\tthrow new Error(`Approval request cannot transition from ${run.state}`)\n\t\tconst now = Date.now()\n\t\tawait ctx.db.patch(run._id, {\n\t\t\tstate: 'canceled',\n\t\t\texpiresAt: undefined,\n\t\t\tupdatedAt: now,\n\t\t\tterminalAt: now,\n\t\t})\n\t\tawait logApprovalTransition(ctx, {\n\t\t\taction: 'approval.canceled',\n\t\t\tactorRef: input.actor.actorRef,\n\t\t\trunId: run._id,\n\t\t\tresourceType: run.resourceType,\n\t\t\tresourceRef: run.resourceRef,\n\t\t\ttransition: 'canceled',\n\t\t})\n\t\treturn { state: 'canceled' as const }\n\t},\n})\n\nexport const restart = mutation({\n\targs: { runId: v.id('approvalRuns'), compatibilityKey: v.string() },\n\treturns: v.null(),\n\thandler: async (ctx, input) => {\n\t\tconst run = await ctx.db.get(input.runId)\n\t\tif (!run) throw new Error('Approval request not found')\n\t\tassertCompatible(run.workflow.compatibilityKey, input.compatibilityKey)\n\t\tif (!run.workflowId) throw new Error('Approval workflow is not linked')\n\t\tif (!run.executionFailedStepKey)\n\t\t\tthrow new Error('Approval workflow has no failed step to restart')\n\t\tawait approvalWorkflow.restart(ctx, run.workflowId as WorkflowId, {\n\t\t\tfrom: run.executionFailedStepKey,\n\t\t\tstartAsync: true,\n\t\t})\n\t\treturn null\n\t},\n})\n\nexport const status = query({\n\targs: { runId: v.id('approvalRuns'), compatibilityKey: v.string() },\n\treturns: v.union(v.null(), approvalStatusValidator()),\n\thandler: async (ctx, input) => {\n\t\tconst run = await ctx.db.get(input.runId)\n\t\tif (!run) return null\n\t\tassertCompatible(run.workflow.compatibilityKey, input.compatibilityKey)\n\t\tconst workflowStatus = run.workflowId\n\t\t\t? await approvalWorkflow.status(ctx, run.workflowId as WorkflowId)\n\t\t\t: null\n\t\tconst execution = normalizeWorkflowStatus(workflowStatus)\n\t\treturn { run, execution }\n\t},\n})\n\nexport const list = query({\n\targs: {\n\t\tscopeRef: zodToConvex(approvalReference),\n\t\tstate: v.optional(zodToConvex(approvalRunState)),\n\t\tpaginationOpts: paginationOptsValidator,\n\t},\n\treturns: paginationResultValidator(approvalRunValidator()),\n\thandler: (ctx, input) =>\n\t\tctx.db\n\t\t\t.query('approvalRuns')\n\t\t\t.withIndex('by_scopeRef_and_state', (query) =>\n\t\t\t\tinput.state === undefined\n\t\t\t\t\t? query.eq('scopeRef', input.scopeRef)\n\t\t\t\t\t: query.eq('scopeRef', input.scopeRef).eq('state', input.state),\n\t\t\t)\n\t\t\t.order('desc')\n\t\t\t.paginate(input.paginationOpts),\n})\n\nexport const getForWorkflow = internalQuery({\n\targs: { runId: v.id('approvalRuns') },\n\treturns: v.union(v.null(), approvalRunValidator()),\n\thandler: (ctx, input) => ctx.db.get(input.runId),\n})\n\nexport const recordExecutionTerminal = internalMutation({\n\targs: {\n\t\trunId: v.id('approvalRuns'),\n\t\toutcome: v.union(\n\t\t\tv.literal(APPROVAL_EXECUTION_STATES[1]),\n\t\t\tv.literal(APPROVAL_EXECUTION_STATES[3]),\n\t\t),\n\t\tfailedStepKey: v.optional(zodToConvex(approvalName)),\n\t},\n\treturns: v.null(),\n\thandler: async (ctx, input) => {\n\t\tconst run = await ctx.db.get(input.runId)\n\t\tif (!run) throw new Error('Approval request not found')\n\t\tawait ctx.db.patch(run._id, {\n\t\t\texecutionFailedStepKey:\n\t\t\t\tinput.outcome === 'failed' ? input.failedStepKey : undefined,\n\t\t\tupdatedAt: Date.now(),\n\t\t})\n\t\tawait logApprovalTransition(ctx, {\n\t\t\taction: `approval.execution.${input.outcome}`,\n\t\t\trunId: run._id,\n\t\t\tresourceType: run.resourceType,\n\t\t\tresourceRef: run.resourceRef,\n\t\t\ttransition: `execution:${input.outcome}`,\n\t\t\tseverity: input.outcome === 'failed' ? 'error' : 'info',\n\t\t})\n\t\treturn null\n\t},\n})\n\nconst approvalWorkflow = new WorkflowManager(components.workflow)\n\nfunction normalizeWorkflowStatus(\n\tstatus: Awaited<ReturnType<typeof approvalWorkflow.status>> | null,\n) {\n\tif (!status) return null\n\tswitch (status.type) {\n\t\tcase 'failed':\n\t\t\treturn { type: 'failed' as const, error: status.error }\n\t\tcase 'inProgress':\n\t\tcase 'completed':\n\t\tcase 'canceled':\n\t\t\treturn { type: status.type }\n\t}\n}\n\nfunction approvalRunValidator() {\n\treturn v.object({\n\t\t_id: v.id('approvalRuns'),\n\t\t_creationTime: v.number(),\n\t\t...zodToConvex(approvalRunDocument).fields,\n\t})\n}\n\nfunction workflowStatusValidator() {\n\treturn v.union(\n\t\tv.object({ type: v.literal(APPROVAL_EXECUTION_STATES[0]) }),\n\t\tv.object({ type: v.literal(APPROVAL_EXECUTION_STATES[1]) }),\n\t\tv.object({ type: v.literal(APPROVAL_EXECUTION_STATES[2]) }),\n\t\tv.object({\n\t\t\ttype: v.literal(APPROVAL_EXECUTION_STATES[3]),\n\t\t\terror: v.string(),\n\t\t}),\n\t)\n}\n\nfunction approvalStatusValidator() {\n\treturn v.object({\n\t\trun: approvalRunValidator(),\n\t\texecution: v.union(v.null(), workflowStatusValidator()),\n\t})\n}\n\nfunction assertCompatible(actual: string, expected: string): void {\n\tif (actual !== expected)\n\t\tthrow new Error(\n\t\t\t`Approval workflow compatibility mismatch: expected ${expected}, received ${actual}`,\n\t\t)\n}\n"],"mappings":"mxBA4BA,MAAa,EAAQ,EAAS,CAC7B,KAAM,CACL,SAAU,EAAY,CAAiB,EACvC,aAAc,EAAY,CAAiB,EAC3C,YAAa,EAAY,CAAiB,EAC1C,UAAW,EAAY,CAAa,EACpC,SAAU,EAAE,SAAS,EAAY,CAAgB,CAAC,EAClD,SAAU,EAAY,CAA0B,CACjD,EACA,QAAS,EAAE,OAAO,CAAE,MAAO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