@deliverd/sdk 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +654 -654
- package/dist/dev.d.ts.map +1 -1
- package/dist/dev.js +84 -0
- package/dist/gates.d.ts +49 -1
- package/dist/gates.d.ts.map +1 -1
- package/dist/gates.js +110 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +48 -0
- package/dist/released.d.ts +1 -1
- package/dist/released.d.ts.map +1 -1
- package/dist/released.js +993 -0
- package/dist/types.d.ts +182 -9
- package/dist/types.d.ts.map +1 -1
- package/package.json +59 -59
- package/src/adapters/ai-sdk.ts +59 -59
- package/src/adapters/claude-agent-sdk.ts +90 -90
- package/src/adapters/index.ts +23 -23
- package/src/adapters/langgraph.ts +202 -202
- package/src/adapters/openai-agents.ts +112 -112
- package/src/adapters/shared.ts +179 -179
- package/src/approvals.ts +342 -342
- package/src/collections.ts +247 -247
- package/src/dev.ts +868 -780
- package/src/duration.ts +21 -21
- package/src/errors.ts +62 -62
- package/src/flows.ts +222 -222
- package/src/gates.ts +366 -231
- package/src/http.ts +217 -217
- package/src/index.ts +444 -444
- package/src/messages.ts +209 -161
- package/src/paging.ts +64 -64
- package/src/released.ts +3516 -2523
- package/src/reports.ts +490 -490
- package/src/reviews.ts +236 -236
- package/src/types.ts +1107 -921
- package/src/webhooks.ts +117 -117
package/src/dev.ts
CHANGED
|
@@ -1,780 +1,868 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ApprovalData,
|
|
3
|
-
CollectionData,
|
|
4
|
-
EvidencePack,
|
|
5
|
-
FlowData,
|
|
6
|
-
GateData,
|
|
7
|
-
ReviewData,
|
|
8
|
-
} from "./types.js";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Development mode: the whole loop, on your machine, with nobody in it.
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* const deliverd = new Deliverd({ mode: "development" });
|
|
15
|
-
* const decision = await deliverd.approve({ title: "Deploy production" });
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* No key, no network, no colleague to interrupt — and the four things that
|
|
19
|
-
* can happen to a real request all reachable before you have an account:
|
|
20
|
-
* approved, rejected, nobody answered, and somebody asked you a question.
|
|
21
|
-
* That last one is the path people forget to write, which is exactly why it
|
|
22
|
-
* should be one line to try.
|
|
23
|
-
*
|
|
24
|
-
* Implemented as a stand-in `fetch` rather than a branch inside the client,
|
|
25
|
-
* so development mode runs the *same* code as production — the same retries,
|
|
26
|
-
* the same error mapping, the same polling in `wait()`. A simulator that
|
|
27
|
-
* bypassed all that would prove your integration works against the simulator.
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* What development mode makes happen.
|
|
32
|
-
*
|
|
33
|
-
* Four for the primitives that ask a person, and a fifth for the gate:
|
|
34
|
-
* `denied` is a **policy** refusal, which nothing else can have — an approval
|
|
35
|
-
* cannot be refused without somebody refusing it. It is the outcome an agent
|
|
36
|
-
* must handle by not retrying, and rehearsing that offline is worth a word of
|
|
37
|
-
* its own. The four that involve a person mean the same thing everywhere;
|
|
38
|
-
* `denied` on an approval is treated as `rejected`, because a request nobody
|
|
39
|
-
* was asked about is not a thing that surface can represent.
|
|
40
|
-
*/
|
|
41
|
-
export type DevelopmentOutcome = "approved" | "rejected" | "denied" | "timeout" | "question";
|
|
42
|
-
|
|
43
|
-
export interface DevelopmentOptions {
|
|
44
|
-
/**
|
|
45
|
-
* What the imaginary approver does. Default `approved`, or the value of
|
|
46
|
-
* `DELIVERD_DEV_OUTCOME`, so a whole test suite can be flipped from the
|
|
47
|
-
* command line without touching the code.
|
|
48
|
-
*/
|
|
49
|
-
outcome?: DevelopmentOutcome | ((request: ApprovalData) => DevelopmentOutcome);
|
|
50
|
-
/** How long they take to do it, in milliseconds. Default 0. */
|
|
51
|
-
delay?: number;
|
|
52
|
-
/** What they say. Defaults suit the outcome. */
|
|
53
|
-
note?: string;
|
|
54
|
-
/**
|
|
55
|
-
* Corrections the imaginary approver makes when approving a request that
|
|
56
|
-
* sent an `input`, so the approve-with-changes path can be run offline.
|
|
57
|
-
* Only fields you named in `editableFields` are applied, as in production.
|
|
58
|
-
*/
|
|
59
|
-
edits?: Record<string, unknown>;
|
|
60
|
-
/** What they ask, when the outcome is `question`. */
|
|
61
|
-
question?: string;
|
|
62
|
-
/** Print what the approver would have seen. Default true. */
|
|
63
|
-
log?: boolean;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const DEFAULT_QUESTION = "Has this been through staging?";
|
|
67
|
-
|
|
68
|
-
let counter = 0;
|
|
69
|
-
|
|
70
|
-
interface Stored {
|
|
71
|
-
data: ApprovalData;
|
|
72
|
-
/** When the imaginary approver acts. */
|
|
73
|
-
decideAt: number;
|
|
74
|
-
outcome: DevelopmentOutcome;
|
|
75
|
-
options: DevelopmentOptions;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* A `fetch` that serves the approvals, reviews and collections APIs from memory.
|
|
80
|
-
*
|
|
81
|
-
* Deliberately narrow: it answers the calls the primitives make and 501s the
|
|
82
|
-
* rest, with a message saying so, rather than pretending to be the whole API
|
|
83
|
-
* and quietly returning something plausible.
|
|
84
|
-
*/
|
|
85
|
-
export function developmentFetch(options: DevelopmentOptions = {}): typeof globalThis.fetch {
|
|
86
|
-
const store = new Map<string, Stored>();
|
|
87
|
-
const reviewStore = new Map<string, StoredReview>();
|
|
88
|
-
const gateStore = new Map<string, StoredGate>();
|
|
89
|
-
const collectionStore = new Map<string, StoredCollection>();
|
|
90
|
-
const flowStore = new Map<string, FlowData>();
|
|
91
|
-
|
|
92
|
-
return (async (input: string | URL | Request, init?: RequestInit) => {
|
|
93
|
-
const url = new URL(String(input));
|
|
94
|
-
const path = url.pathname.replace(/^\/api\/v1/, "");
|
|
95
|
-
const method = (init?.method ?? "GET").toUpperCase();
|
|
96
|
-
const body = init?.body ? (JSON.parse(String(init.body)) as Record<string, unknown>) : {};
|
|
97
|
-
|
|
98
|
-
const json = (payload: unknown, status = 200) =>
|
|
99
|
-
new Response(JSON.stringify(payload), {
|
|
100
|
-
status,
|
|
101
|
-
headers: { "content-type": "application/json" },
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
if (method === "POST" && path === "/approvals") {
|
|
105
|
-
const id = `apr_dev_${++counter}`;
|
|
106
|
-
const outcome = resolveOutcome(options.outcome, body);
|
|
107
|
-
const data: ApprovalData = {
|
|
108
|
-
id,
|
|
109
|
-
status: "pending",
|
|
110
|
-
url: `https://deliverd.dev/approve/${id}`,
|
|
111
|
-
title: String(body.title ?? "Untitled"),
|
|
112
|
-
description: (body.description as string | undefined) ?? null,
|
|
113
|
-
risk: (body.risk as ApprovalData["risk"] | undefined) ?? "medium",
|
|
114
|
-
factors: (body.factors as ApprovalData["factors"]) ?? [],
|
|
115
|
-
links: (body.links as ApprovalData["links"]) ?? [],
|
|
116
|
-
reportId: (body.reportId as string | undefined) ?? null,
|
|
117
|
-
externalId: (body.externalId as string | undefined) ?? null,
|
|
118
|
-
metadata: (body.metadata as Record<string, unknown>) ?? {},
|
|
119
|
-
input: (body.input as Record<string, unknown> | undefined) ?? null,
|
|
120
|
-
editableFields: (body.editableFields as string[] | undefined) ?? [],
|
|
121
|
-
approvedInput: null,
|
|
122
|
-
changes: [],
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
question.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
stored.
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
*
|
|
196
|
-
* a
|
|
197
|
-
*
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
const
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
)
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
stored.data.
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
` │
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
1
|
+
import type {
|
|
2
|
+
ApprovalData,
|
|
3
|
+
CollectionData,
|
|
4
|
+
EvidencePack,
|
|
5
|
+
FlowData,
|
|
6
|
+
GateData,
|
|
7
|
+
ReviewData,
|
|
8
|
+
} from "./types.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Development mode: the whole loop, on your machine, with nobody in it.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* const deliverd = new Deliverd({ mode: "development" });
|
|
15
|
+
* const decision = await deliverd.approve({ title: "Deploy production" });
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* No key, no network, no colleague to interrupt — and the four things that
|
|
19
|
+
* can happen to a real request all reachable before you have an account:
|
|
20
|
+
* approved, rejected, nobody answered, and somebody asked you a question.
|
|
21
|
+
* That last one is the path people forget to write, which is exactly why it
|
|
22
|
+
* should be one line to try.
|
|
23
|
+
*
|
|
24
|
+
* Implemented as a stand-in `fetch` rather than a branch inside the client,
|
|
25
|
+
* so development mode runs the *same* code as production — the same retries,
|
|
26
|
+
* the same error mapping, the same polling in `wait()`. A simulator that
|
|
27
|
+
* bypassed all that would prove your integration works against the simulator.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* What development mode makes happen.
|
|
32
|
+
*
|
|
33
|
+
* Four for the primitives that ask a person, and a fifth for the gate:
|
|
34
|
+
* `denied` is a **policy** refusal, which nothing else can have — an approval
|
|
35
|
+
* cannot be refused without somebody refusing it. It is the outcome an agent
|
|
36
|
+
* must handle by not retrying, and rehearsing that offline is worth a word of
|
|
37
|
+
* its own. The four that involve a person mean the same thing everywhere;
|
|
38
|
+
* `denied` on an approval is treated as `rejected`, because a request nobody
|
|
39
|
+
* was asked about is not a thing that surface can represent.
|
|
40
|
+
*/
|
|
41
|
+
export type DevelopmentOutcome = "approved" | "rejected" | "denied" | "timeout" | "question";
|
|
42
|
+
|
|
43
|
+
export interface DevelopmentOptions {
|
|
44
|
+
/**
|
|
45
|
+
* What the imaginary approver does. Default `approved`, or the value of
|
|
46
|
+
* `DELIVERD_DEV_OUTCOME`, so a whole test suite can be flipped from the
|
|
47
|
+
* command line without touching the code.
|
|
48
|
+
*/
|
|
49
|
+
outcome?: DevelopmentOutcome | ((request: ApprovalData) => DevelopmentOutcome);
|
|
50
|
+
/** How long they take to do it, in milliseconds. Default 0. */
|
|
51
|
+
delay?: number;
|
|
52
|
+
/** What they say. Defaults suit the outcome. */
|
|
53
|
+
note?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Corrections the imaginary approver makes when approving a request that
|
|
56
|
+
* sent an `input`, so the approve-with-changes path can be run offline.
|
|
57
|
+
* Only fields you named in `editableFields` are applied, as in production.
|
|
58
|
+
*/
|
|
59
|
+
edits?: Record<string, unknown>;
|
|
60
|
+
/** What they ask, when the outcome is `question`. */
|
|
61
|
+
question?: string;
|
|
62
|
+
/** Print what the approver would have seen. Default true. */
|
|
63
|
+
log?: boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const DEFAULT_QUESTION = "Has this been through staging?";
|
|
67
|
+
|
|
68
|
+
let counter = 0;
|
|
69
|
+
|
|
70
|
+
interface Stored {
|
|
71
|
+
data: ApprovalData;
|
|
72
|
+
/** When the imaginary approver acts. */
|
|
73
|
+
decideAt: number;
|
|
74
|
+
outcome: DevelopmentOutcome;
|
|
75
|
+
options: DevelopmentOptions;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A `fetch` that serves the approvals, reviews and collections APIs from memory.
|
|
80
|
+
*
|
|
81
|
+
* Deliberately narrow: it answers the calls the primitives make and 501s the
|
|
82
|
+
* rest, with a message saying so, rather than pretending to be the whole API
|
|
83
|
+
* and quietly returning something plausible.
|
|
84
|
+
*/
|
|
85
|
+
export function developmentFetch(options: DevelopmentOptions = {}): typeof globalThis.fetch {
|
|
86
|
+
const store = new Map<string, Stored>();
|
|
87
|
+
const reviewStore = new Map<string, StoredReview>();
|
|
88
|
+
const gateStore = new Map<string, StoredGate>();
|
|
89
|
+
const collectionStore = new Map<string, StoredCollection>();
|
|
90
|
+
const flowStore = new Map<string, FlowData>();
|
|
91
|
+
|
|
92
|
+
return (async (input: string | URL | Request, init?: RequestInit) => {
|
|
93
|
+
const url = new URL(String(input));
|
|
94
|
+
const path = url.pathname.replace(/^\/api\/v1/, "");
|
|
95
|
+
const method = (init?.method ?? "GET").toUpperCase();
|
|
96
|
+
const body = init?.body ? (JSON.parse(String(init.body)) as Record<string, unknown>) : {};
|
|
97
|
+
|
|
98
|
+
const json = (payload: unknown, status = 200) =>
|
|
99
|
+
new Response(JSON.stringify(payload), {
|
|
100
|
+
status,
|
|
101
|
+
headers: { "content-type": "application/json" },
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
if (method === "POST" && path === "/approvals") {
|
|
105
|
+
const id = `apr_dev_${++counter}`;
|
|
106
|
+
const outcome = resolveOutcome(options.outcome, body);
|
|
107
|
+
const data: ApprovalData = {
|
|
108
|
+
id,
|
|
109
|
+
status: "pending",
|
|
110
|
+
url: `https://deliverd.dev/approve/${id}`,
|
|
111
|
+
title: String(body.title ?? "Untitled"),
|
|
112
|
+
description: (body.description as string | undefined) ?? null,
|
|
113
|
+
risk: (body.risk as ApprovalData["risk"] | undefined) ?? "medium",
|
|
114
|
+
factors: (body.factors as ApprovalData["factors"]) ?? [],
|
|
115
|
+
links: (body.links as ApprovalData["links"]) ?? [],
|
|
116
|
+
reportId: (body.reportId as string | undefined) ?? null,
|
|
117
|
+
externalId: (body.externalId as string | undefined) ?? null,
|
|
118
|
+
metadata: (body.metadata as Record<string, unknown>) ?? {},
|
|
119
|
+
input: (body.input as Record<string, unknown> | undefined) ?? null,
|
|
120
|
+
editableFields: (body.editableFields as string[] | undefined) ?? [],
|
|
121
|
+
approvedInput: null,
|
|
122
|
+
changes: [],
|
|
123
|
+
concerns: [],
|
|
124
|
+
requestedBy: "You (development mode)",
|
|
125
|
+
approvers: (body.approvers as string[] | undefined) ?? [],
|
|
126
|
+
/*
|
|
127
|
+
* One, always. A standing rule could raise it on a real organisation,
|
|
128
|
+
* but development mode has no rules to read and an imaginary approver
|
|
129
|
+
* cannot be two people — pretending otherwise would let a caller test
|
|
130
|
+
* an escalation that never happened.
|
|
131
|
+
*/
|
|
132
|
+
requiredApprovals: 1,
|
|
133
|
+
approvalsSoFar: 0,
|
|
134
|
+
decidedBy: null,
|
|
135
|
+
decidedById: null,
|
|
136
|
+
decidedAt: null,
|
|
137
|
+
note: null,
|
|
138
|
+
expiresAt: (body.expiresAt as string | undefined) ?? null,
|
|
139
|
+
questions:
|
|
140
|
+
outcome === "question"
|
|
141
|
+
? [
|
|
142
|
+
{
|
|
143
|
+
id: `q_dev_${counter}`,
|
|
144
|
+
question: options.question ?? DEFAULT_QUESTION,
|
|
145
|
+
answer: null,
|
|
146
|
+
askedAt: new Date().toISOString(),
|
|
147
|
+
answeredAt: null,
|
|
148
|
+
},
|
|
149
|
+
]
|
|
150
|
+
: [],
|
|
151
|
+
createdAt: new Date().toISOString(),
|
|
152
|
+
};
|
|
153
|
+
store.set(id, {
|
|
154
|
+
data,
|
|
155
|
+
decideAt: Date.now() + (options.delay ?? 0),
|
|
156
|
+
outcome,
|
|
157
|
+
options,
|
|
158
|
+
});
|
|
159
|
+
if (options.log !== false) announce(data, outcome);
|
|
160
|
+
return json(data, 201);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const match = /^\/approvals\/([^/]+)(\/answers|\/cancel)?$/.exec(path);
|
|
164
|
+
if (match) {
|
|
165
|
+
const stored = store.get(match[1]!);
|
|
166
|
+
if (!stored) {
|
|
167
|
+
return json({ error: { code: "not_found", message: "No such approval in this development session." } }, 404);
|
|
168
|
+
}
|
|
169
|
+
if (match[2] === "/answers") {
|
|
170
|
+
const question = stored.data.questions.find((q) => q.id === body.questionId);
|
|
171
|
+
if (!question) {
|
|
172
|
+
return json({ error: { code: "question_not_found", message: "No such question." } }, 404);
|
|
173
|
+
}
|
|
174
|
+
question.answer = String(body.answer);
|
|
175
|
+
question.answeredAt = new Date().toISOString();
|
|
176
|
+
// Answered: the imaginary approver is satisfied and approves.
|
|
177
|
+
stored.outcome = "approved";
|
|
178
|
+
stored.decideAt = Date.now() + (stored.options.delay ?? 0);
|
|
179
|
+
if (stored.options.log !== false) {
|
|
180
|
+
console.log(` ↳ answered: ${question.answer}\n`);
|
|
181
|
+
}
|
|
182
|
+
return json(stored.data);
|
|
183
|
+
}
|
|
184
|
+
if (match[2] === "/cancel") {
|
|
185
|
+
stored.data.status = "cancelled";
|
|
186
|
+
return json(stored.data);
|
|
187
|
+
}
|
|
188
|
+
settle(stored);
|
|
189
|
+
return json(stored.data);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (method === "POST" && path === "/reviews") {
|
|
193
|
+
const id = `rev_dev_${++counter}`;
|
|
194
|
+
/*
|
|
195
|
+
* The same outcome switch as approvals, mapped onto a review's endings:
|
|
196
|
+
* a rejection is "changes requested", because that is what saying no to
|
|
197
|
+
* a piece of work means. A simulated question has nothing to ask about
|
|
198
|
+
* here — there is no question mechanism on a review — so it approves.
|
|
199
|
+
*/
|
|
200
|
+
const outcome = resolveOutcome(options.outcome, body);
|
|
201
|
+
const verdict = outcome === "rejected" ? "changes_requested" : "approved";
|
|
202
|
+
const reviewers = ((body.reviewers as string[] | undefined) ?? []).map((email, i) => ({
|
|
203
|
+
kind: "user" as const,
|
|
204
|
+
id: `usr_dev_${i + 1}`,
|
|
205
|
+
label: email,
|
|
206
|
+
}));
|
|
207
|
+
const data: ReviewData = {
|
|
208
|
+
id,
|
|
209
|
+
status: "pending",
|
|
210
|
+
url: `https://deliverd.dev/reviews/${id}`,
|
|
211
|
+
title: String(body.title ?? "Untitled"),
|
|
212
|
+
instructions: (body.instructions as string | undefined) ?? null,
|
|
213
|
+
reportId: (body.reportId as string | undefined) ?? null,
|
|
214
|
+
versionId: (body.versionId as string | undefined) ?? null,
|
|
215
|
+
externalId: (body.externalId as string | undefined) ?? null,
|
|
216
|
+
metadata: (body.metadata as Record<string, unknown>) ?? {},
|
|
217
|
+
requestedBy: "You (development mode)",
|
|
218
|
+
requiredApprovals: (body.requiredApprovals as number | undefined) ?? 1,
|
|
219
|
+
reviewers,
|
|
220
|
+
verdicts: [],
|
|
221
|
+
/*
|
|
222
|
+
* A review that asks for changes has something to read, and the count
|
|
223
|
+
* is what the caller acts on. Zero made the one path that matters read
|
|
224
|
+
* as "changes requested — 0 threads", which tells somebody running
|
|
225
|
+
* this for the first time that the feature does not work.
|
|
226
|
+
*/
|
|
227
|
+
threadCount: verdict === "changes_requested" ? 2 : 0,
|
|
228
|
+
settledAt: null,
|
|
229
|
+
expiresAt: (body.expiresAt as string | undefined) ?? null,
|
|
230
|
+
createdAt: new Date().toISOString(),
|
|
231
|
+
};
|
|
232
|
+
reviewStore.set(id, {
|
|
233
|
+
data,
|
|
234
|
+
settleAt: Date.now() + (options.delay ?? 0),
|
|
235
|
+
verdict,
|
|
236
|
+
timeout: outcome === "timeout",
|
|
237
|
+
});
|
|
238
|
+
if (options.log !== false) announceReview(data, verdict, outcome === "timeout");
|
|
239
|
+
return json(data, 201);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/*
|
|
243
|
+
* The gate, offline.
|
|
244
|
+
*
|
|
245
|
+
* `DELIVERD_DEV_OUTCOME` means the same thing here as everywhere else, with
|
|
246
|
+
* one addition: `denied` is a *policy* refusal, which has no equivalent on
|
|
247
|
+
* the other primitives because nothing else can be refused without a person
|
|
248
|
+
* being asked. The default stays `approved`, so `gate()` runs green out of
|
|
249
|
+
* the box and the interesting cases are the ones you opt into.
|
|
250
|
+
*
|
|
251
|
+
* `allowed` and `denied` settle instantly, as a real rule does. `approved`
|
|
252
|
+
* and `rejected` go through `pending` first, because that is the path with
|
|
253
|
+
* a `wait()` in it and the one worth being able to rehearse.
|
|
254
|
+
*/
|
|
255
|
+
if (method === "POST" && path === "/gates") {
|
|
256
|
+
const id = `gat_dev_${++counter}`;
|
|
257
|
+
const externalId = String(body.externalId ?? "");
|
|
258
|
+
|
|
259
|
+
/*
|
|
260
|
+
* Server-side reuse, which the real endpoint enforces in the database.
|
|
261
|
+
* Offline it is a map lookup, and it is here rather than left out
|
|
262
|
+
* because the one thing `gate()` promises over `approve()` is that a
|
|
263
|
+
* retry re-reads its decision — testing that without an account is the
|
|
264
|
+
* whole point of this file.
|
|
265
|
+
*/
|
|
266
|
+
for (const stored of gateStore.values()) {
|
|
267
|
+
if (stored.data.externalId === externalId) {
|
|
268
|
+
settleGate(stored);
|
|
269
|
+
return json({ ...stored.data.gate, reused: true });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const outcome = resolveOutcome(options.outcome, body);
|
|
274
|
+
/*
|
|
275
|
+
* `denied` is settled by a rule and reaches nobody; everything else goes
|
|
276
|
+
* through a person, which is where `wait()` earns its place. The default
|
|
277
|
+
* `approved` therefore rehearses the escalation path rather than the
|
|
278
|
+
* auto-allow — the opposite of production's common case, and the right
|
|
279
|
+
* default here, because the path with a wait in it is the one worth
|
|
280
|
+
* being able to run before you have an account.
|
|
281
|
+
*/
|
|
282
|
+
const byRule = outcome === "denied";
|
|
283
|
+
const gate: GateData = {
|
|
284
|
+
id,
|
|
285
|
+
status: byRule ? "denied" : "pending",
|
|
286
|
+
allowed: false,
|
|
287
|
+
input: (body.input as Record<string, unknown>) ?? {},
|
|
288
|
+
changes: [],
|
|
289
|
+
concerns: [],
|
|
290
|
+
basis: byRule ? "policy" : "human",
|
|
291
|
+
reason: byRule
|
|
292
|
+
? "Development mode refused it. A real rule would say which one and why."
|
|
293
|
+
: "No rule covers this action yet, so it needs a person.",
|
|
294
|
+
rule: byRule ? "Development mode" : null,
|
|
295
|
+
policyVersionId: null,
|
|
296
|
+
approvalId: byRule ? null : `apr_dev_${id}`,
|
|
297
|
+
approvalUrl: byRule ? null : `https://deliverd.dev/approve/apr_dev_${id}`,
|
|
298
|
+
outcome: null,
|
|
299
|
+
settledAt: null,
|
|
300
|
+
reused: false,
|
|
301
|
+
decision: byRule ? "DENY" : "APPROVAL_REQUIRED",
|
|
302
|
+
canExecute: false,
|
|
303
|
+
blockedBecause: byRule ? "Policy does not allow this action." : "Waiting for a person to decide.",
|
|
304
|
+
scope: {
|
|
305
|
+
destination: (body.destination as GateData["scope"]["destination"]) ?? null,
|
|
306
|
+
// Offline there is no directory to consult, so nothing is known to be internal.
|
|
307
|
+
recipientScope: body.destination ? "external" : null,
|
|
308
|
+
classification: (body.classification as GateData["scope"]["classification"]) ?? null,
|
|
309
|
+
risk: (body.risk as GateData["scope"]["risk"]) ?? null,
|
|
310
|
+
artifact: body.artifact
|
|
311
|
+
? {
|
|
312
|
+
kind: (body.artifact as { versionId?: string }).versionId ? "report_version" : "external",
|
|
313
|
+
reportId: (body.artifact as { reportId?: string }).reportId ?? null,
|
|
314
|
+
versionId: (body.artifact as { versionId?: string }).versionId ?? null,
|
|
315
|
+
versionNumber: null,
|
|
316
|
+
sha256: ((body.artifact as { sha256?: string }).sha256 ?? null)?.toLowerCase() ?? null,
|
|
317
|
+
name: (body.artifact as { name?: string }).name ?? null,
|
|
318
|
+
mimeType: null,
|
|
319
|
+
size: null,
|
|
320
|
+
uri: null,
|
|
321
|
+
verified: false,
|
|
322
|
+
}
|
|
323
|
+
: null,
|
|
324
|
+
digest: null,
|
|
325
|
+
},
|
|
326
|
+
authorisation: { validUntil: null, maxUses: 1, usesRemaining: 1 },
|
|
327
|
+
actionId: String(body.actionId ?? ""),
|
|
328
|
+
agentId: null,
|
|
329
|
+
flowId: (body.flowId as string | undefined) ?? null,
|
|
330
|
+
supersedesGateId: (body.supersedesGateId as string | undefined) ?? null,
|
|
331
|
+
description: ((body.description ?? body.reason) as string | undefined) ?? null,
|
|
332
|
+
requestedBy: "Development agent",
|
|
333
|
+
createdAt: new Date().toISOString(),
|
|
334
|
+
};
|
|
335
|
+
gateStore.set(id, {
|
|
336
|
+
data: { gate, externalId },
|
|
337
|
+
outcome,
|
|
338
|
+
decideAt: Date.now() + (options.delay ?? 0),
|
|
339
|
+
});
|
|
340
|
+
return json(gate, 201);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/*
|
|
344
|
+
* What was done with a permission, offline: one use, spent by the first
|
|
345
|
+
* claim, and a hash that has to match the one asked about — the two
|
|
346
|
+
* refusals worth rehearsing before there is an account to be refused by.
|
|
347
|
+
*/
|
|
348
|
+
const executionMatch = /^\/gates\/([^/]+)\/(execution|cancel)$/.exec(path);
|
|
349
|
+
if (executionMatch && method === "POST") {
|
|
350
|
+
const stored = gateStore.get(executionMatch[1]!);
|
|
351
|
+
if (!stored) {
|
|
352
|
+
return json({ error: { code: "not_found", message: "No such gate in this development session." } }, 404);
|
|
353
|
+
}
|
|
354
|
+
settleGate(stored);
|
|
355
|
+
const gate = stored.data.gate;
|
|
356
|
+
if (executionMatch[2] === "cancel") {
|
|
357
|
+
gate.status = "cancelled";
|
|
358
|
+
gate.canExecute = false;
|
|
359
|
+
gate.blockedBecause = "This request was withdrawn.";
|
|
360
|
+
return json(gate);
|
|
361
|
+
}
|
|
362
|
+
if (!gate.canExecute) {
|
|
363
|
+
const code = gate.status === "used" ? "gate_used" : "not_authorised";
|
|
364
|
+
return json({ error: { code, message: gate.blockedBecause ?? "Not authorised." } }, code === "gate_used" ? 409 : 403);
|
|
365
|
+
}
|
|
366
|
+
const sha = typeof body.artifactSha256 === "string" ? body.artifactSha256.toLowerCase() : null;
|
|
367
|
+
if (gate.scope.artifact?.sha256 && sha !== gate.scope.artifact.sha256) {
|
|
368
|
+
return json(
|
|
369
|
+
{ error: { code: sha ? "approval_invalidated" : "artifact_missing", message: "The artifact is not the one that was approved." } },
|
|
370
|
+
sha ? 409 : 400
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
gate.status = "used";
|
|
374
|
+
gate.canExecute = false;
|
|
375
|
+
gate.blockedBecause = "This permission has been used. A further action needs a new request.";
|
|
376
|
+
gate.authorisation = { ...gate.authorisation, usesRemaining: 0 };
|
|
377
|
+
const receipt = {
|
|
378
|
+
id: `exe_dev_${++counter}`,
|
|
379
|
+
gateId: gate.id,
|
|
380
|
+
phase: (body.phase as string | undefined) ?? "completed",
|
|
381
|
+
claimId: null,
|
|
382
|
+
executedAt: new Date().toISOString(),
|
|
383
|
+
artifactSha256: sha,
|
|
384
|
+
destination: (body.destination as GateData["scope"]["destination"]) ?? null,
|
|
385
|
+
result: (body.result as Record<string, unknown> | undefined) ?? {},
|
|
386
|
+
verification: gate.scope.artifact?.sha256 ? "hash_matched" : "reported",
|
|
387
|
+
detail: (body.detail as string | undefined) ?? null,
|
|
388
|
+
reportedBy: "Development agent",
|
|
389
|
+
createdAt: new Date().toISOString(),
|
|
390
|
+
};
|
|
391
|
+
return json({ receipt, gate }, 201);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const gateMatch = /^\/gates\/([^/]+)$/.exec(path);
|
|
395
|
+
if (gateMatch && method === "GET") {
|
|
396
|
+
const stored = gateStore.get(gateMatch[1]!);
|
|
397
|
+
if (!stored) {
|
|
398
|
+
return json(
|
|
399
|
+
{ error: { code: "not_found", message: "No such gate in this development session." } },
|
|
400
|
+
404
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
settleGate(stored);
|
|
404
|
+
return json(stored.data.gate);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const reviewMatch = /^\/reviews\/([^/]+)(\/cancel)?$/.exec(path);
|
|
408
|
+
if (reviewMatch) {
|
|
409
|
+
const stored = reviewStore.get(reviewMatch[1]!);
|
|
410
|
+
if (!stored) {
|
|
411
|
+
return json(
|
|
412
|
+
{ error: { code: "not_found", message: "No such review in this development session." } },
|
|
413
|
+
404
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
if (reviewMatch[2] === "/cancel") {
|
|
417
|
+
stored.data.status = "cancelled";
|
|
418
|
+
return json(stored.data);
|
|
419
|
+
}
|
|
420
|
+
settleReview(stored);
|
|
421
|
+
return json(stored.data);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/*
|
|
425
|
+
* Listing approvals, which `findByExternalId` needs.
|
|
426
|
+
*
|
|
427
|
+
* Missing until an example used `externalId` for retry safety and got a
|
|
428
|
+
* 501 instead. Reviews, collections and flows all had their list route
|
|
429
|
+
* from the start; approvals — the primitive the feature is most documented
|
|
430
|
+
* on — did not, so the one thing that stops a restarted agent asking twice
|
|
431
|
+
* was the one thing you could not try without an account.
|
|
432
|
+
*/
|
|
433
|
+
if (method === "GET" && path === "/approvals") {
|
|
434
|
+
const externalId = url.searchParams.get("externalId");
|
|
435
|
+
const status = url.searchParams.get("status");
|
|
436
|
+
// Settle first: a caller listing before polling should see the same
|
|
437
|
+
// state a poll would have shown it, not a stale `pending`.
|
|
438
|
+
for (const stored of store.values()) settle(stored);
|
|
439
|
+
let all = [...store.values()].map((a) => a.data);
|
|
440
|
+
if (externalId) all = all.filter((a) => a.externalId === externalId);
|
|
441
|
+
if (status) all = all.filter((a) => a.status === status);
|
|
442
|
+
return json({ approvals: all });
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (method === "GET" && path === "/reviews") {
|
|
446
|
+
const externalId = url.searchParams.get("externalId");
|
|
447
|
+
const all = [...reviewStore.values()].map((r) => r.data);
|
|
448
|
+
return json({
|
|
449
|
+
reviews: externalId ? all.filter((r) => r.externalId === externalId) : all,
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
if (method === "POST" && path === "/collections") {
|
|
454
|
+
const id = `col_dev_${++counter}`;
|
|
455
|
+
const outcome = resolveOutcome(options.outcome, body);
|
|
456
|
+
const asked = ((body.respondents as string[] | undefined) ?? []).map(String);
|
|
457
|
+
const questions = ((body.questions as Record<string, unknown>[] | undefined) ?? []).map(
|
|
458
|
+
(q, i) => ({
|
|
459
|
+
id: `q_dev_${i + 1}`,
|
|
460
|
+
prompt: String(q.prompt ?? "Question"),
|
|
461
|
+
help: (q.help as string | undefined) ?? null,
|
|
462
|
+
kind: (q.kind as CollectionData["questions"][number]["kind"]) ?? "text",
|
|
463
|
+
required: q.required !== false,
|
|
464
|
+
options: (q.options as string[] | undefined) ?? [],
|
|
465
|
+
})
|
|
466
|
+
);
|
|
467
|
+
const data: CollectionData = {
|
|
468
|
+
id,
|
|
469
|
+
status: "pending",
|
|
470
|
+
url: `https://deliverd.dev/collect/${id}`,
|
|
471
|
+
title: String(body.title ?? "Untitled"),
|
|
472
|
+
instructions: (body.instructions as string | undefined) ?? null,
|
|
473
|
+
reportId: (body.reportId as string | undefined) ?? null,
|
|
474
|
+
externalId: (body.externalId as string | undefined) ?? null,
|
|
475
|
+
metadata: (body.metadata as Record<string, unknown>) ?? {},
|
|
476
|
+
requestedBy: "You (development mode)",
|
|
477
|
+
requiredResponses: (body.requiredResponses as number | undefined) ?? (asked.length || 1),
|
|
478
|
+
questions,
|
|
479
|
+
responses: asked.map((who) => ({
|
|
480
|
+
respondent: who,
|
|
481
|
+
status: "pending" as const,
|
|
482
|
+
submittedAt: null,
|
|
483
|
+
answers: [],
|
|
484
|
+
})),
|
|
485
|
+
submittedCount: 0,
|
|
486
|
+
askedCount: asked.length,
|
|
487
|
+
settledAt: null,
|
|
488
|
+
dueAt: (body.dueAt as string | undefined) ?? null,
|
|
489
|
+
expiresAt: (body.expiresAt as string | undefined) ?? null,
|
|
490
|
+
createdAt: new Date().toISOString(),
|
|
491
|
+
};
|
|
492
|
+
collectionStore.set(id, {
|
|
493
|
+
data,
|
|
494
|
+
settleAt: Date.now() + (options.delay ?? 0),
|
|
495
|
+
/*
|
|
496
|
+
* A simulated rejection becomes an expiry here: there is no way to
|
|
497
|
+
* say no to a question, only to leave it unanswered, and that is the
|
|
498
|
+
* ending a caller most needs to have thought about.
|
|
499
|
+
*/
|
|
500
|
+
expire: outcome === "rejected",
|
|
501
|
+
timeout: outcome === "timeout",
|
|
502
|
+
});
|
|
503
|
+
if (options.log !== false) announceCollection(data, outcome);
|
|
504
|
+
return json(data, 201);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
const collectionMatch = /^\/collections\/([^/]+)(\/cancel)?$/.exec(path);
|
|
508
|
+
if (collectionMatch) {
|
|
509
|
+
const stored = collectionStore.get(collectionMatch[1]!);
|
|
510
|
+
if (!stored) {
|
|
511
|
+
return json(
|
|
512
|
+
{ error: { code: "not_found", message: "No such request in this development session." } },
|
|
513
|
+
404
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
if (collectionMatch[2] === "/cancel") {
|
|
517
|
+
stored.data.status = "cancelled";
|
|
518
|
+
return json(stored.data);
|
|
519
|
+
}
|
|
520
|
+
settleCollection(stored);
|
|
521
|
+
return json(stored.data);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
if (method === "GET" && path === "/collections") {
|
|
525
|
+
const externalId = url.searchParams.get("externalId");
|
|
526
|
+
const all = [...collectionStore.values()].map((c) => c.data);
|
|
527
|
+
return json({
|
|
528
|
+
collections: externalId ? all.filter((c) => c.externalId === externalId) : all,
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/*
|
|
533
|
+
* Flows in development are real objects with no simulation attached:
|
|
534
|
+
* there is nobody to imagine, and the thing worth exercising offline is
|
|
535
|
+
* that `flow.approve()` reaches the same code as `deliverd.approve()`.
|
|
536
|
+
* Members are not tracked here — the server derives them from rows this
|
|
537
|
+
* store does not keep — so a development flow reports what it knows and
|
|
538
|
+
* does not invent a membership.
|
|
539
|
+
*/
|
|
540
|
+
if (method === "POST" && path === "/flows") {
|
|
541
|
+
const id = `flw_dev_${++counter}`;
|
|
542
|
+
const data: FlowData = {
|
|
543
|
+
id,
|
|
544
|
+
status: "open",
|
|
545
|
+
url: `https://deliverd.dev/flows/${id}`,
|
|
546
|
+
title: String(body.title ?? "Untitled"),
|
|
547
|
+
description: (body.description as string | undefined) ?? null,
|
|
548
|
+
externalId: (body.externalId as string | undefined) ?? null,
|
|
549
|
+
metadata: (body.metadata as Record<string, unknown>) ?? {},
|
|
550
|
+
startedBy: "You (development mode)",
|
|
551
|
+
members: [],
|
|
552
|
+
memberCount: 0,
|
|
553
|
+
openCount: 0,
|
|
554
|
+
allSettled: false,
|
|
555
|
+
timeline: [],
|
|
556
|
+
settledAt: null,
|
|
557
|
+
createdAt: new Date().toISOString(),
|
|
558
|
+
};
|
|
559
|
+
flowStore.set(id, data);
|
|
560
|
+
if (options.log !== false) {
|
|
561
|
+
console.log(`\n \u25B8 Flow started: ${data.title}\n ${data.url}\n`);
|
|
562
|
+
}
|
|
563
|
+
return json(data, 201);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/*
|
|
567
|
+
* Evidence in development is the shape and not the substance: this store
|
|
568
|
+
* holds no audit rows, so the pack comes back with the subject and an
|
|
569
|
+
* empty record rather than an invented one. What it proves is that
|
|
570
|
+
* `flow.evidence()` reaches the right path and returns something a caller
|
|
571
|
+
* can destructure — an imaginary approval trail would be worse than none.
|
|
572
|
+
*/
|
|
573
|
+
const evidenceMatch = /^\/(flows|reports)\/([^/]+)\/evidence$/.exec(path);
|
|
574
|
+
if (evidenceMatch && method === "GET") {
|
|
575
|
+
const kind = evidenceMatch[1] === "flows" ? "flow" : "report";
|
|
576
|
+
const id = evidenceMatch[2]!;
|
|
577
|
+
const title = kind === "flow" ? (flowStore.get(id)?.title ?? "A flow") : "A report";
|
|
578
|
+
const now = new Date().toISOString();
|
|
579
|
+
const pack: EvidencePack = {
|
|
580
|
+
packVersion: 2,
|
|
581
|
+
generatedAt: now,
|
|
582
|
+
generatedBy: "You (development mode)",
|
|
583
|
+
organisation: { id: "org_dev", name: "Development" },
|
|
584
|
+
subject: {
|
|
585
|
+
kind,
|
|
586
|
+
id,
|
|
587
|
+
title,
|
|
588
|
+
url: `https://deliverd.dev/${evidenceMatch[1]}/${id}`,
|
|
589
|
+
status: "open",
|
|
590
|
+
startedBy: "You (development mode)",
|
|
591
|
+
startedAt: now,
|
|
592
|
+
},
|
|
593
|
+
summary: { steps: 0, events: 0, firstEventAt: null, lastEventAt: null },
|
|
594
|
+
steps: [],
|
|
595
|
+
timeline: [],
|
|
596
|
+
integrity: {
|
|
597
|
+
algorithm: "sha256",
|
|
598
|
+
digest: "development",
|
|
599
|
+
covers: "Nothing: this pack was produced in development mode and holds no records.",
|
|
600
|
+
doesNotCover: "Everything. Do not hand this to anybody.",
|
|
601
|
+
recordsAreInsertOnly: true,
|
|
602
|
+
},
|
|
603
|
+
};
|
|
604
|
+
return json(pack);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
const flowMatch = /^\/flows\/([^/]+)(\/complete|\/cancel)?$/.exec(path);
|
|
608
|
+
if (flowMatch) {
|
|
609
|
+
const flow = flowStore.get(flowMatch[1]!);
|
|
610
|
+
if (!flow) {
|
|
611
|
+
return json(
|
|
612
|
+
{ error: { code: "not_found", message: "No such flow in this development session." } },
|
|
613
|
+
404
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
if (flowMatch[2] === "/complete" || flowMatch[2] === "/cancel") {
|
|
617
|
+
if (flow.status !== "open") {
|
|
618
|
+
return json(
|
|
619
|
+
{ error: { code: "not_open", message: `This flow is already ${flow.status}.` } },
|
|
620
|
+
409
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
flow.status = flowMatch[2] === "/complete" ? "complete" : "cancelled";
|
|
624
|
+
flow.settledAt = new Date().toISOString();
|
|
625
|
+
}
|
|
626
|
+
return json(flow);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
if (method === "GET" && path === "/flows") {
|
|
630
|
+
const externalId = url.searchParams.get("externalId");
|
|
631
|
+
const all = [...flowStore.values()];
|
|
632
|
+
return json({ flows: externalId ? all.filter((f) => f.externalId === externalId) : all });
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
return json(
|
|
636
|
+
{
|
|
637
|
+
error: {
|
|
638
|
+
code: "not_in_development_mode",
|
|
639
|
+
message: `Development mode simulates approvals, reviews and collections only, and something called ${method} ${path}. Use a real API key for the rest of the API.`,
|
|
640
|
+
},
|
|
641
|
+
},
|
|
642
|
+
501
|
|
643
|
+
);
|
|
644
|
+
}) as typeof globalThis.fetch;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
function resolveOutcome(
|
|
648
|
+
outcome: DevelopmentOptions["outcome"],
|
|
649
|
+
body: Record<string, unknown>
|
|
650
|
+
): DevelopmentOutcome {
|
|
651
|
+
const fromEnv = process.env.DELIVERD_DEV_OUTCOME as DevelopmentOutcome | undefined;
|
|
652
|
+
const chosen = outcome ?? fromEnv ?? "approved";
|
|
653
|
+
return typeof chosen === "function" ? chosen(body as unknown as ApprovalData) : chosen;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/** Move a pending request to its outcome once the imaginary approver has had time. */
|
|
657
|
+
function settle(stored: Stored): void {
|
|
658
|
+
if (stored.data.status !== "pending") return;
|
|
659
|
+
if (Date.now() < stored.decideAt) return;
|
|
660
|
+
if (stored.outcome === "timeout") return;
|
|
661
|
+
if (stored.outcome === "question" && stored.data.questions.some((q) => !q.answer)) return;
|
|
662
|
+
|
|
663
|
+
stored.data.status = stored.outcome === "rejected" ? "rejected" : "approved";
|
|
664
|
+
/*
|
|
665
|
+
* The same shape production sends: a person's name in `decidedBy` and the
|
|
666
|
+
* key in `decidedById`. It used to be an email-shaped string alone, so the
|
|
667
|
+
* offline loop taught a shape a real organisation never delivers.
|
|
668
|
+
*/
|
|
669
|
+
stored.data.decidedBy = "Development approver";
|
|
670
|
+
stored.data.decidedById = "00000000-0000-0000-0000-00000000dev0";
|
|
671
|
+
stored.data.decidedAt = new Date().toISOString();
|
|
672
|
+
stored.data.note =
|
|
673
|
+
stored.options.note ??
|
|
674
|
+
(stored.data.status === "rejected" ? "Not yet — development mode says no." : null);
|
|
675
|
+
if (stored.data.status === "approved" && stored.data.input) {
|
|
676
|
+
const proposed = stored.data.input;
|
|
677
|
+
const edits = Object.entries(stored.options.edits ?? {}).filter(
|
|
678
|
+
([field, value]) => stored.data.editableFields.includes(field) && !Object.is(proposed[field], value)
|
|
679
|
+
);
|
|
680
|
+
stored.data.approvedInput = { ...proposed, ...Object.fromEntries(edits) };
|
|
681
|
+
stored.data.changes = edits.map(([field, to]) => ({ field, from: proposed[field] ?? null, to }));
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* What the approver would have seen, in the terminal.
|
|
687
|
+
*
|
|
688
|
+
* The reason this is worth the lines: the title and the factors are copy
|
|
689
|
+
* somebody has to read on a phone at nine at night, and the only way to know
|
|
690
|
+
* whether it reads well is to see it written out.
|
|
691
|
+
*/
|
|
692
|
+
function announce(data: ApprovalData, outcome: DevelopmentOutcome): void {
|
|
693
|
+
const lines = [
|
|
694
|
+
"",
|
|
695
|
+
" ┌─ Deliverd · development mode ─────────────────────────",
|
|
696
|
+
` │ ${data.title}`,
|
|
697
|
+
];
|
|
698
|
+
if (data.description) lines.push(` │ ${data.description}`);
|
|
699
|
+
lines.push(` │ Risk: ${data.risk}`);
|
|
700
|
+
for (const factor of data.factors) {
|
|
701
|
+
const mark = factor.status === "ok" ? "✓" : factor.status === "warning" ? "⚠" : "·";
|
|
702
|
+
lines.push(` │ ${mark} ${factor.label}`);
|
|
703
|
+
}
|
|
704
|
+
if (data.approvers.length > 0) lines.push(` │ To: ${data.approvers.join(", ")}`);
|
|
705
|
+
lines.push(
|
|
706
|
+
" │",
|
|
707
|
+
` │ Simulating: ${outcome}${outcome === "question" ? " (needs an onQuestion handler)" : ""}`,
|
|
708
|
+
" └───────────────────────────────────────────────────────",
|
|
709
|
+
""
|
|
710
|
+
);
|
|
711
|
+
console.log(lines.join("\n"));
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
interface StoredGate {
|
|
716
|
+
/** The decision, plus the caller's id kept beside it for the reuse lookup. */
|
|
717
|
+
data: { gate: GateData; externalId: string };
|
|
718
|
+
outcome: DevelopmentOutcome;
|
|
719
|
+
decideAt: number;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* A gate that went to a person, once that person has answered.
|
|
724
|
+
*
|
|
725
|
+
* Only the two outcomes that involve one. `allowed` and `denied` were settled
|
|
726
|
+
* by a rule at creation and have nothing to wait for — which is the honest
|
|
727
|
+
* shape, because in production most gated calls never reach a human either.
|
|
728
|
+
*/
|
|
729
|
+
function settleGate(stored: StoredGate): void {
|
|
730
|
+
const gate = stored.data.gate;
|
|
731
|
+
if (gate.status !== "pending") return;
|
|
732
|
+
if (Date.now() < stored.decideAt) return;
|
|
733
|
+
if (stored.outcome === "timeout" || stored.outcome === "question") return;
|
|
734
|
+
if (stored.outcome === "denied") return;
|
|
735
|
+
|
|
736
|
+
const approved = stored.outcome === "approved";
|
|
737
|
+
gate.status = approved ? "approved" : "rejected";
|
|
738
|
+
gate.allowed = approved;
|
|
739
|
+
gate.canExecute = approved;
|
|
740
|
+
gate.blockedBecause = approved ? null : "A person rejected this action.";
|
|
741
|
+
gate.outcome = approved ? "approved" : "rejected";
|
|
742
|
+
gate.settledAt = new Date().toISOString();
|
|
743
|
+
gate.basis = "human";
|
|
744
|
+
gate.reason = approved
|
|
745
|
+
? "A development approver agreed to it."
|
|
746
|
+
: "A development approver refused it.";
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
interface StoredReview {
|
|
750
|
+
data: ReviewData;
|
|
751
|
+
settleAt: number;
|
|
752
|
+
verdict: "approved" | "changes_requested";
|
|
753
|
+
timeout: boolean;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
/** Settle it once its moment has passed, unless it is meant to hang. */
|
|
757
|
+
function settleReview(stored: StoredReview): void {
|
|
758
|
+
if (stored.timeout || stored.data.status !== "pending") return;
|
|
759
|
+
if (Date.now() < stored.settleAt) return;
|
|
760
|
+
stored.data.verdicts = [
|
|
761
|
+
{
|
|
762
|
+
verdict: stored.verdict,
|
|
763
|
+
by: stored.data.reviewers[0]?.label ?? "A reviewer (development mode)",
|
|
764
|
+
note:
|
|
765
|
+
stored.verdict === "changes_requested"
|
|
766
|
+
? "Simulated: the figures on page two do not tie back."
|
|
767
|
+
: null,
|
|
768
|
+
at: new Date().toISOString(),
|
|
769
|
+
},
|
|
770
|
+
];
|
|
771
|
+
stored.data.status = stored.verdict;
|
|
772
|
+
stored.data.settledAt = new Date().toISOString();
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
function announceReview(
|
|
776
|
+
data: ReviewData,
|
|
777
|
+
verdict: "approved" | "changes_requested",
|
|
778
|
+
willHang: boolean
|
|
779
|
+
): void {
|
|
780
|
+
const lines = [
|
|
781
|
+
` ┌─ Deliverd · development mode ─────────────────────────`,
|
|
782
|
+
` │ ${data.title}`,
|
|
783
|
+
...(data.instructions ? [` │ Check: ${data.instructions}`] : []),
|
|
784
|
+
` │ Reviewers: ${data.reviewers.map((r) => r.label).join(", ") || "nobody named"}`,
|
|
785
|
+
` │`,
|
|
786
|
+
` │ Simulating: ${willHang ? "nobody reviews it" : verdict.replace("_", " ")}`,
|
|
787
|
+
` └───────────────────────────────────────────────────────`,
|
|
788
|
+
"",
|
|
789
|
+
];
|
|
790
|
+
console.log(lines.join("\n"));
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
interface StoredCollection {
|
|
795
|
+
data: CollectionData;
|
|
796
|
+
settleAt: number;
|
|
797
|
+
expire: boolean;
|
|
798
|
+
timeout: boolean;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* Everyone answers, at the same moment, with a plausible value for the kind
|
|
803
|
+
* of question asked. Plausible rather than empty, because a caller writing
|
|
804
|
+
* `answers["Headcount at 30 September"] + 1` should find out here that it is
|
|
805
|
+
* a number, not in production.
|
|
806
|
+
*/
|
|
807
|
+
function settleCollection(stored: StoredCollection): void {
|
|
808
|
+
if (stored.timeout || stored.data.status !== "pending") return;
|
|
809
|
+
if (Date.now() < stored.settleAt) return;
|
|
810
|
+
if (stored.expire) {
|
|
811
|
+
stored.data.status = "expired";
|
|
812
|
+
stored.data.settledAt = new Date().toISOString();
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
const at = new Date().toISOString();
|
|
816
|
+
stored.data.responses = stored.data.responses.map((r) => ({
|
|
817
|
+
...r,
|
|
818
|
+
status: "submitted" as const,
|
|
819
|
+
submittedAt: at,
|
|
820
|
+
answers: stored.data.questions.map((q) => ({
|
|
821
|
+
question: q.prompt,
|
|
822
|
+
kind: q.kind,
|
|
823
|
+
value: sampleAnswer(q),
|
|
824
|
+
})),
|
|
825
|
+
}));
|
|
826
|
+
stored.data.submittedCount = stored.data.responses.length;
|
|
827
|
+
stored.data.status = "complete";
|
|
828
|
+
stored.data.settledAt = at;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
function sampleAnswer(q: CollectionData["questions"][number]): string | number | boolean | string[] {
|
|
832
|
+
switch (q.kind) {
|
|
833
|
+
case "number":
|
|
834
|
+
return 42;
|
|
835
|
+
case "boolean":
|
|
836
|
+
return true;
|
|
837
|
+
case "date":
|
|
838
|
+
return new Date().toISOString().slice(0, 10);
|
|
839
|
+
case "choice":
|
|
840
|
+
return q.options[0] ?? "";
|
|
841
|
+
case "multi_choice":
|
|
842
|
+
return q.options.slice(0, 1);
|
|
843
|
+
case "long_text":
|
|
844
|
+
return "Simulated: a longer answer than a line.";
|
|
845
|
+
default:
|
|
846
|
+
return "Simulated answer";
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
function announceCollection(data: CollectionData, outcome: string): void {
|
|
851
|
+
const lines = [
|
|
852
|
+
` ┌─ Deliverd · development mode ─────────────────────────`,
|
|
853
|
+
` │ ${data.title}`,
|
|
854
|
+
` │ Asking: ${data.questions.map((q) => q.prompt).join(" · ") || "nothing"}`,
|
|
855
|
+
` │ Of: ${data.responses.map((r) => r.respondent).join(", ") || "nobody named"}`,
|
|
856
|
+
` │`,
|
|
857
|
+
` │ Simulating: ${
|
|
858
|
+
outcome === "timeout"
|
|
859
|
+
? "nobody answers"
|
|
860
|
+
: outcome === "rejected"
|
|
861
|
+
? "it expires unanswered"
|
|
862
|
+
: "everyone answers"
|
|
863
|
+
}`,
|
|
864
|
+
` └───────────────────────────────────────────────────────`,
|
|
865
|
+
"",
|
|
866
|
+
];
|
|
867
|
+
console.log(lines.join("\n"));
|
|
868
|
+
}
|