@deliverd/sdk 0.2.0 → 0.4.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/README.md +98 -8
- package/dist/collections.d.ts +78 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +170 -0
- package/dist/dev.d.ts +1 -1
- package/dist/dev.d.ts.map +1 -1
- package/dist/dev.js +195 -2
- package/dist/flows.d.ts +98 -0
- package/dist/flows.d.ts.map +1 -0
- package/dist/flows.js +136 -0
- package/dist/index.d.ts +47 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +62 -0
- package/dist/types.d.ts +174 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/collections.ts +214 -0
- package/src/dev.ts +223 -3
- package/src/flows.ts +185 -0
- package/src/index.ts +89 -0
- package/src/types.ts +200 -1
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,GAAG,WAAW,CAAC;AAC3F,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;AAElE,2DAA2D;AAC3D,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,GAAG,IA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pB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { DeliverdError, DeliverdTimeoutError } from "./errors.js";
|
|
2
|
+
import type { HttpClient } from "./http.js";
|
|
3
|
+
import { POLL_SCHEDULE } from "./approvals.js";
|
|
4
|
+
import type {
|
|
5
|
+
AnswerValue,
|
|
6
|
+
CollectedAnswers,
|
|
7
|
+
CollectionData,
|
|
8
|
+
CreateCollectionInput,
|
|
9
|
+
ListCollectionsInput,
|
|
10
|
+
} from "./types.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Ask people for what you do not have.
|
|
14
|
+
*
|
|
15
|
+
* The third of the three, and the one that goes the other way. `approve()`
|
|
16
|
+
* asks permission, `review()` asks judgement, and this asks for a fact: a
|
|
17
|
+
* figure, a date, a choice between options, the sentence only they can write.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export interface CollectWaitOptions {
|
|
21
|
+
/** Called after every poll, for a progress line in a CLI. */
|
|
22
|
+
onPoll?: (collection: CollectionData) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Give up after this many milliseconds and throw `DeliverdTimeoutError`.
|
|
25
|
+
* Omitted, the wait ends when the request does — which, with no `expiresAt`,
|
|
26
|
+
* may be never. Set one or the other.
|
|
27
|
+
*/
|
|
28
|
+
timeout?: number;
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
pollIntervals?: readonly number[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function pollDelay(poll: number, schedule: readonly number[]): number {
|
|
34
|
+
const base = schedule[Math.min(poll, schedule.length - 1)] ?? 60_000;
|
|
35
|
+
return base * 0.75 + Math.random() * base * 0.5;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A request for answers, and what you can do with it. */
|
|
39
|
+
export class Collection {
|
|
40
|
+
constructor(
|
|
41
|
+
private readonly http: HttpClient,
|
|
42
|
+
private data: CollectionData
|
|
43
|
+
) {}
|
|
44
|
+
|
|
45
|
+
get id(): string { return this.data.id; }
|
|
46
|
+
get status(): CollectionData["status"] { return this.data.status; }
|
|
47
|
+
/** The page the people you asked will fill in. */
|
|
48
|
+
get url(): string { return this.data.url; }
|
|
49
|
+
get title(): string { return this.data.title; }
|
|
50
|
+
get responses(): CollectionData["responses"] { return this.data.responses; }
|
|
51
|
+
get submittedCount(): number { return this.data.submittedCount; }
|
|
52
|
+
get askedCount(): number { return this.data.askedCount; }
|
|
53
|
+
|
|
54
|
+
/** The one to branch on. False for expired and cancelled. */
|
|
55
|
+
get complete(): boolean { return this.data.status === "complete"; }
|
|
56
|
+
get expired(): boolean { return this.data.status === "expired"; }
|
|
57
|
+
get cancelled(): boolean { return this.data.status === "cancelled"; }
|
|
58
|
+
get pending(): boolean { return this.data.status === "pending"; }
|
|
59
|
+
|
|
60
|
+
toJSON(): CollectionData { return this.data; }
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The first submitted answer to each question, keyed by its prompt.
|
|
64
|
+
*
|
|
65
|
+
* The shape most callers want, because most callers asked one person for
|
|
66
|
+
* three facts. When several people answered the same question, later
|
|
67
|
+
* replies do not overwrite the first — use `responses` when you need all of
|
|
68
|
+
* them, and note that this returns the earliest submission rather than a
|
|
69
|
+
* merge, since silently blending two people's answers would be worse than
|
|
70
|
+
* making you choose.
|
|
71
|
+
*/
|
|
72
|
+
get answers(): Record<string, AnswerValue> {
|
|
73
|
+
const out: Record<string, AnswerValue> = {};
|
|
74
|
+
for (const reply of this.data.responses) {
|
|
75
|
+
if (reply.status !== "submitted") continue;
|
|
76
|
+
for (const answer of reply.answers) {
|
|
77
|
+
if (!(answer.question in out)) out[answer.question] = answer.value;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
toCollected(): CollectedAnswers {
|
|
84
|
+
const status = this.data.status === "pending" ? "expired" : this.data.status;
|
|
85
|
+
return {
|
|
86
|
+
complete: this.data.status === "complete",
|
|
87
|
+
status,
|
|
88
|
+
responses: this.data.responses.filter((r) => r.status === "submitted"),
|
|
89
|
+
answers: this.answers,
|
|
90
|
+
id: this.data.id,
|
|
91
|
+
url: this.data.url,
|
|
92
|
+
collection: this.data,
|
|
93
|
+
} as CollectedAnswers;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async refresh(signal?: AbortSignal): Promise<this> {
|
|
97
|
+
this.data = await this.http.request<CollectionData>({
|
|
98
|
+
method: "GET",
|
|
99
|
+
path: `/collections/${this.data.id}`,
|
|
100
|
+
signal,
|
|
101
|
+
});
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Withdraw it. The row stays as evidence of what was asked and dropped. */
|
|
106
|
+
async cancel(signal?: AbortSignal): Promise<this> {
|
|
107
|
+
this.data = await this.http.request<CollectionData>({
|
|
108
|
+
method: "POST",
|
|
109
|
+
path: `/collections/${this.data.id}/cancel`,
|
|
110
|
+
signal,
|
|
111
|
+
});
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Block until enough people have answered, then return.
|
|
117
|
+
*
|
|
118
|
+
* Resolves on every ending, including expiry — which is an answer of a
|
|
119
|
+
* kind, and one you must handle rather than treat as an error, because the
|
|
120
|
+
* thing you do without the figure is usually different from the thing you
|
|
121
|
+
* do with it.
|
|
122
|
+
*/
|
|
123
|
+
async wait(options: CollectWaitOptions = {}): Promise<this> {
|
|
124
|
+
const deadline = options.timeout !== undefined ? Date.now() + options.timeout : undefined;
|
|
125
|
+
let poll = 0;
|
|
126
|
+
if (!this.pending) return this;
|
|
127
|
+
|
|
128
|
+
for (;;) {
|
|
129
|
+
if (options.signal?.aborted) {
|
|
130
|
+
throw new DeliverdError(0, "aborted", "The wait was aborted.", undefined, {
|
|
131
|
+
cause: options.signal.reason,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
if (deadline !== undefined && Date.now() >= deadline) {
|
|
135
|
+
throw new DeliverdTimeoutError(
|
|
136
|
+
`Nobody finished answering "${this.data.title}" within the timeout. It is still open at ${this.data.url}.`
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
const delay = pollDelay(poll++, options.pollIntervals ?? POLL_SCHEDULE);
|
|
140
|
+
const remaining = deadline === undefined ? delay : Math.min(delay, deadline - Date.now());
|
|
141
|
+
await sleep(Math.max(0, remaining), options.signal);
|
|
142
|
+
|
|
143
|
+
await this.refresh(options.signal);
|
|
144
|
+
options.onPoll?.(this.data);
|
|
145
|
+
if (!this.pending) return this;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function sleep(ms: number, signal?: AbortSignal): Promise<void> {
|
|
151
|
+
return new Promise((resolve, reject) => {
|
|
152
|
+
if (signal?.aborted) {
|
|
153
|
+
return reject(new DeliverdError(0, "aborted", "The wait was aborted."));
|
|
154
|
+
}
|
|
155
|
+
const timer = setTimeout(() => {
|
|
156
|
+
signal?.removeEventListener("abort", onAbort);
|
|
157
|
+
resolve();
|
|
158
|
+
}, ms);
|
|
159
|
+
const onAbort = () => {
|
|
160
|
+
clearTimeout(timer);
|
|
161
|
+
reject(new DeliverdError(0, "aborted", "The wait was aborted."));
|
|
162
|
+
};
|
|
163
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export class Collections {
|
|
168
|
+
constructor(private readonly http: HttpClient) {}
|
|
169
|
+
|
|
170
|
+
/** Ask. Returns as soon as the request is filed; call `wait()` next. */
|
|
171
|
+
async create(input: CreateCollectionInput, signal?: AbortSignal): Promise<Collection> {
|
|
172
|
+
const data = await this.http.request<CollectionData>({
|
|
173
|
+
method: "POST",
|
|
174
|
+
path: "/collections",
|
|
175
|
+
body: input,
|
|
176
|
+
signal,
|
|
177
|
+
});
|
|
178
|
+
return new Collection(this.http, data);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async get(id: string, signal?: AbortSignal): Promise<Collection> {
|
|
182
|
+
const data = await this.http.request<CollectionData>({
|
|
183
|
+
method: "GET",
|
|
184
|
+
path: `/collections/${id}`,
|
|
185
|
+
signal,
|
|
186
|
+
});
|
|
187
|
+
return new Collection(this.http, data);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async list(input: ListCollectionsInput = {}, signal?: AbortSignal): Promise<Collection[]> {
|
|
191
|
+
const { collections } = await this.http.request<{ collections: CollectionData[] }>({
|
|
192
|
+
method: "GET",
|
|
193
|
+
path: "/collections",
|
|
194
|
+
query: { status: input.status, externalId: input.externalId, limit: input.limit },
|
|
195
|
+
signal,
|
|
196
|
+
});
|
|
197
|
+
return collections.map((c) => new Collection(this.http, c));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Ask and wait, for the common case where there is nothing to do between. */
|
|
201
|
+
async request(
|
|
202
|
+
input: CreateCollectionInput,
|
|
203
|
+
options: CollectWaitOptions = {}
|
|
204
|
+
): Promise<Collection> {
|
|
205
|
+
const collection = await this.create(input, options.signal);
|
|
206
|
+
return collection.wait(options);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** The same request as before, when there was one — so a restart does not ask twice. */
|
|
210
|
+
async findByExternalId(externalId: string, signal?: AbortSignal): Promise<Collection | null> {
|
|
211
|
+
const found = await this.list({ externalId, limit: 1 }, signal);
|
|
212
|
+
return found[0] ?? null;
|
|
213
|
+
}
|
|
214
|
+
}
|
package/src/dev.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApprovalData, ReviewData } from "./types.js";
|
|
1
|
+
import type { ApprovalData, CollectionData, FlowData, ReviewData } from "./types.js";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Development mode: the whole loop, on your machine, with nobody in it.
|
|
@@ -52,7 +52,7 @@ interface Stored {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
* A `fetch` that serves the approvals and
|
|
55
|
+
* A `fetch` that serves the approvals, reviews and collections APIs from memory.
|
|
56
56
|
*
|
|
57
57
|
* Deliberately narrow: it answers the calls the primitives make and 501s the
|
|
58
58
|
* rest, with a message saying so, rather than pretending to be the whole API
|
|
@@ -61,6 +61,8 @@ interface Stored {
|
|
|
61
61
|
export function developmentFetch(options: DevelopmentOptions = {}): typeof globalThis.fetch {
|
|
62
62
|
const store = new Map<string, Stored>();
|
|
63
63
|
const reviewStore = new Map<string, StoredReview>();
|
|
64
|
+
const collectionStore = new Map<string, StoredCollection>();
|
|
65
|
+
const flowStore = new Map<string, FlowData>();
|
|
64
66
|
|
|
65
67
|
return (async (input: string | URL | Request, init?: RequestInit) => {
|
|
66
68
|
const url = new URL(String(input));
|
|
@@ -217,11 +219,152 @@ export function developmentFetch(options: DevelopmentOptions = {}): typeof globa
|
|
|
217
219
|
});
|
|
218
220
|
}
|
|
219
221
|
|
|
222
|
+
if (method === "POST" && path === "/collections") {
|
|
223
|
+
const id = `col_dev_${++counter}`;
|
|
224
|
+
const outcome = resolveOutcome(options.outcome, body);
|
|
225
|
+
const asked = ((body.respondents as string[] | undefined) ?? []).map(String);
|
|
226
|
+
const questions = ((body.questions as Record<string, unknown>[] | undefined) ?? []).map(
|
|
227
|
+
(q, i) => ({
|
|
228
|
+
id: `q_dev_${i + 1}`,
|
|
229
|
+
prompt: String(q.prompt ?? "Question"),
|
|
230
|
+
help: (q.help as string | undefined) ?? null,
|
|
231
|
+
kind: (q.kind as CollectionData["questions"][number]["kind"]) ?? "text",
|
|
232
|
+
required: q.required !== false,
|
|
233
|
+
options: (q.options as string[] | undefined) ?? [],
|
|
234
|
+
})
|
|
235
|
+
);
|
|
236
|
+
const data: CollectionData = {
|
|
237
|
+
id,
|
|
238
|
+
status: "pending",
|
|
239
|
+
url: `https://deliverd.dev/collect/${id}`,
|
|
240
|
+
title: String(body.title ?? "Untitled"),
|
|
241
|
+
instructions: (body.instructions as string | undefined) ?? null,
|
|
242
|
+
reportId: (body.reportId as string | undefined) ?? null,
|
|
243
|
+
externalId: (body.externalId as string | undefined) ?? null,
|
|
244
|
+
metadata: (body.metadata as Record<string, unknown>) ?? {},
|
|
245
|
+
requestedBy: "You (development mode)",
|
|
246
|
+
requiredResponses: (body.requiredResponses as number | undefined) ?? (asked.length || 1),
|
|
247
|
+
questions,
|
|
248
|
+
responses: asked.map((who) => ({
|
|
249
|
+
respondent: who,
|
|
250
|
+
status: "pending" as const,
|
|
251
|
+
submittedAt: null,
|
|
252
|
+
answers: [],
|
|
253
|
+
})),
|
|
254
|
+
submittedCount: 0,
|
|
255
|
+
askedCount: asked.length,
|
|
256
|
+
settledAt: null,
|
|
257
|
+
dueAt: (body.dueAt as string | undefined) ?? null,
|
|
258
|
+
expiresAt: (body.expiresAt as string | undefined) ?? null,
|
|
259
|
+
createdAt: new Date().toISOString(),
|
|
260
|
+
};
|
|
261
|
+
collectionStore.set(id, {
|
|
262
|
+
data,
|
|
263
|
+
settleAt: Date.now() + (options.delay ?? 0),
|
|
264
|
+
/*
|
|
265
|
+
* A simulated rejection becomes an expiry here: there is no way to
|
|
266
|
+
* say no to a question, only to leave it unanswered, and that is the
|
|
267
|
+
* ending a caller most needs to have thought about.
|
|
268
|
+
*/
|
|
269
|
+
expire: outcome === "rejected",
|
|
270
|
+
timeout: outcome === "timeout",
|
|
271
|
+
});
|
|
272
|
+
if (options.log !== false) announceCollection(data, outcome);
|
|
273
|
+
return json(data, 201);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const collectionMatch = /^\/collections\/([^/]+)(\/cancel)?$/.exec(path);
|
|
277
|
+
if (collectionMatch) {
|
|
278
|
+
const stored = collectionStore.get(collectionMatch[1]!);
|
|
279
|
+
if (!stored) {
|
|
280
|
+
return json(
|
|
281
|
+
{ error: { code: "not_found", message: "No such request in this development session." } },
|
|
282
|
+
404
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
if (collectionMatch[2] === "/cancel") {
|
|
286
|
+
stored.data.status = "cancelled";
|
|
287
|
+
return json(stored.data);
|
|
288
|
+
}
|
|
289
|
+
settleCollection(stored);
|
|
290
|
+
return json(stored.data);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (method === "GET" && path === "/collections") {
|
|
294
|
+
const externalId = url.searchParams.get("externalId");
|
|
295
|
+
const all = [...collectionStore.values()].map((c) => c.data);
|
|
296
|
+
return json({
|
|
297
|
+
collections: externalId ? all.filter((c) => c.externalId === externalId) : all,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/*
|
|
302
|
+
* Flows in development are real objects with no simulation attached:
|
|
303
|
+
* there is nobody to imagine, and the thing worth exercising offline is
|
|
304
|
+
* that `flow.approve()` reaches the same code as `deliverd.approve()`.
|
|
305
|
+
* Members are not tracked here — the server derives them from rows this
|
|
306
|
+
* store does not keep — so a development flow reports what it knows and
|
|
307
|
+
* does not invent a membership.
|
|
308
|
+
*/
|
|
309
|
+
if (method === "POST" && path === "/flows") {
|
|
310
|
+
const id = `flw_dev_${++counter}`;
|
|
311
|
+
const data: FlowData = {
|
|
312
|
+
id,
|
|
313
|
+
status: "open",
|
|
314
|
+
url: `https://deliverd.dev/flows/${id}`,
|
|
315
|
+
title: String(body.title ?? "Untitled"),
|
|
316
|
+
description: (body.description as string | undefined) ?? null,
|
|
317
|
+
externalId: (body.externalId as string | undefined) ?? null,
|
|
318
|
+
metadata: (body.metadata as Record<string, unknown>) ?? {},
|
|
319
|
+
startedBy: "You (development mode)",
|
|
320
|
+
members: [],
|
|
321
|
+
memberCount: 0,
|
|
322
|
+
openCount: 0,
|
|
323
|
+
allSettled: false,
|
|
324
|
+
timeline: [],
|
|
325
|
+
settledAt: null,
|
|
326
|
+
createdAt: new Date().toISOString(),
|
|
327
|
+
};
|
|
328
|
+
flowStore.set(id, data);
|
|
329
|
+
if (options.log !== false) {
|
|
330
|
+
console.log(`\n \u25B8 Flow started: ${data.title}\n ${data.url}\n`);
|
|
331
|
+
}
|
|
332
|
+
return json(data, 201);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const flowMatch = /^\/flows\/([^/]+)(\/complete|\/cancel)?$/.exec(path);
|
|
336
|
+
if (flowMatch) {
|
|
337
|
+
const flow = flowStore.get(flowMatch[1]!);
|
|
338
|
+
if (!flow) {
|
|
339
|
+
return json(
|
|
340
|
+
{ error: { code: "not_found", message: "No such flow in this development session." } },
|
|
341
|
+
404
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
if (flowMatch[2] === "/complete" || flowMatch[2] === "/cancel") {
|
|
345
|
+
if (flow.status !== "open") {
|
|
346
|
+
return json(
|
|
347
|
+
{ error: { code: "not_open", message: `This flow is already ${flow.status}.` } },
|
|
348
|
+
409
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
flow.status = flowMatch[2] === "/complete" ? "complete" : "cancelled";
|
|
352
|
+
flow.settledAt = new Date().toISOString();
|
|
353
|
+
}
|
|
354
|
+
return json(flow);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (method === "GET" && path === "/flows") {
|
|
358
|
+
const externalId = url.searchParams.get("externalId");
|
|
359
|
+
const all = [...flowStore.values()];
|
|
360
|
+
return json({ flows: externalId ? all.filter((f) => f.externalId === externalId) : all });
|
|
361
|
+
}
|
|
362
|
+
|
|
220
363
|
return json(
|
|
221
364
|
{
|
|
222
365
|
error: {
|
|
223
366
|
code: "not_in_development_mode",
|
|
224
|
-
message: `Development mode simulates approvals and
|
|
367
|
+
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.`,
|
|
225
368
|
},
|
|
226
369
|
},
|
|
227
370
|
501
|
|
@@ -326,3 +469,80 @@ function announceReview(
|
|
|
326
469
|
];
|
|
327
470
|
console.log(lines.join("\n"));
|
|
328
471
|
}
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
interface StoredCollection {
|
|
475
|
+
data: CollectionData;
|
|
476
|
+
settleAt: number;
|
|
477
|
+
expire: boolean;
|
|
478
|
+
timeout: boolean;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Everyone answers, at the same moment, with a plausible value for the kind
|
|
483
|
+
* of question asked. Plausible rather than empty, because a caller writing
|
|
484
|
+
* `answers["Headcount at 30 September"] + 1` should find out here that it is
|
|
485
|
+
* a number, not in production.
|
|
486
|
+
*/
|
|
487
|
+
function settleCollection(stored: StoredCollection): void {
|
|
488
|
+
if (stored.timeout || stored.data.status !== "pending") return;
|
|
489
|
+
if (Date.now() < stored.settleAt) return;
|
|
490
|
+
if (stored.expire) {
|
|
491
|
+
stored.data.status = "expired";
|
|
492
|
+
stored.data.settledAt = new Date().toISOString();
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
const at = new Date().toISOString();
|
|
496
|
+
stored.data.responses = stored.data.responses.map((r) => ({
|
|
497
|
+
...r,
|
|
498
|
+
status: "submitted" as const,
|
|
499
|
+
submittedAt: at,
|
|
500
|
+
answers: stored.data.questions.map((q) => ({
|
|
501
|
+
question: q.prompt,
|
|
502
|
+
kind: q.kind,
|
|
503
|
+
value: sampleAnswer(q),
|
|
504
|
+
})),
|
|
505
|
+
}));
|
|
506
|
+
stored.data.submittedCount = stored.data.responses.length;
|
|
507
|
+
stored.data.status = "complete";
|
|
508
|
+
stored.data.settledAt = at;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function sampleAnswer(q: CollectionData["questions"][number]): string | number | boolean | string[] {
|
|
512
|
+
switch (q.kind) {
|
|
513
|
+
case "number":
|
|
514
|
+
return 42;
|
|
515
|
+
case "boolean":
|
|
516
|
+
return true;
|
|
517
|
+
case "date":
|
|
518
|
+
return new Date().toISOString().slice(0, 10);
|
|
519
|
+
case "choice":
|
|
520
|
+
return q.options[0] ?? "";
|
|
521
|
+
case "multi_choice":
|
|
522
|
+
return q.options.slice(0, 1);
|
|
523
|
+
case "long_text":
|
|
524
|
+
return "Simulated: a longer answer than a line.";
|
|
525
|
+
default:
|
|
526
|
+
return "Simulated answer";
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function announceCollection(data: CollectionData, outcome: string): void {
|
|
531
|
+
const lines = [
|
|
532
|
+
` ┌─ Deliverd · development mode ─────────────────────────`,
|
|
533
|
+
` │ ${data.title}`,
|
|
534
|
+
` │ Asking: ${data.questions.map((q) => q.prompt).join(" · ") || "nothing"}`,
|
|
535
|
+
` │ Of: ${data.responses.map((r) => r.respondent).join(", ") || "nobody named"}`,
|
|
536
|
+
` │`,
|
|
537
|
+
` │ Simulating: ${
|
|
538
|
+
outcome === "timeout"
|
|
539
|
+
? "nobody answers"
|
|
540
|
+
: outcome === "rejected"
|
|
541
|
+
? "it expires unanswered"
|
|
542
|
+
: "everyone answers"
|
|
543
|
+
}`,
|
|
544
|
+
` └───────────────────────────────────────────────────────`,
|
|
545
|
+
"",
|
|
546
|
+
];
|
|
547
|
+
console.log(lines.join("\n"));
|
|
548
|
+
}
|