@deliverd/sdk 0.7.0 → 0.8.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 +48 -1
- package/dist/dev.d.ts +12 -1
- package/dist/dev.d.ts.map +1 -1
- package/dist/dev.js +100 -0
- package/dist/gates.d.ts +94 -0
- package/dist/gates.d.ts.map +1 -0
- package/dist/gates.js +188 -0
- package/dist/http.js +15 -2
- package/dist/index.d.ts +37 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +56 -0
- package/dist/released.d.ts +37 -0
- package/dist/released.d.ts.map +1 -1
- package/dist/released.js +838 -0
- package/dist/types.d.ts +78 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/dev.ts +125 -1
- package/src/gates.ts +230 -0
- package/src/http.ts +15 -2
- package/src/index.ts +59 -0
- package/src/released.ts +841 -1
- package/src/types.ts +90 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HttpClient } from "./http.js";
|
|
2
2
|
import { Approvals, FAST_POLL_SCHEDULE } from "./approvals.js";
|
|
3
|
+
import { Gates } from "./gates.js";
|
|
3
4
|
import { Comments, Reports, Schedules } from "./reports.js";
|
|
4
5
|
import { Reviews } from "./reviews.js";
|
|
5
6
|
import { Collections } from "./collections.js";
|
|
@@ -8,6 +9,7 @@ import { Webhooks } from "./webhooks.js";
|
|
|
8
9
|
import { developmentFetch } from "./dev.js";
|
|
9
10
|
import { durationMs } from "./duration.js";
|
|
10
11
|
export { Approval, Approvals, POLL_SCHEDULE } from "./approvals.js";
|
|
12
|
+
export { Gate, Gates } from "./gates.js";
|
|
11
13
|
export { Comments, Reports, Schedules } from "./reports.js";
|
|
12
14
|
export { Review, Reviews } from "./reviews.js";
|
|
13
15
|
export { Collection, Collections } from "./collections.js";
|
|
@@ -39,6 +41,7 @@ export const DEFAULT_EXPIRY = "24h";
|
|
|
39
41
|
*/
|
|
40
42
|
export class Deliverd {
|
|
41
43
|
approvals;
|
|
44
|
+
gates;
|
|
42
45
|
reviews;
|
|
43
46
|
collections;
|
|
44
47
|
flows;
|
|
@@ -60,6 +63,7 @@ export class Deliverd {
|
|
|
60
63
|
fetch: this.development ? developmentFetch(options.development) : options.fetch,
|
|
61
64
|
});
|
|
62
65
|
this.approvals = new Approvals(this.http);
|
|
66
|
+
this.gates = new Gates(this.http);
|
|
63
67
|
this.reviews = new Reviews(this.http);
|
|
64
68
|
this.collections = new Collections(this.http);
|
|
65
69
|
/*
|
|
@@ -120,6 +124,58 @@ export class Deliverd {
|
|
|
120
124
|
});
|
|
121
125
|
return settled.toDecision();
|
|
122
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Ask whether to act, and wait if a person has to decide.
|
|
129
|
+
*
|
|
130
|
+
* The other primitives ask a person to look at work already done. This one
|
|
131
|
+
* asks first, and the answer comes from **policy the developer does not
|
|
132
|
+
* own** — which is the whole point: what needs a human is an organisation's
|
|
133
|
+
* decision, not a line in your code. Most calls never reach a person at all,
|
|
134
|
+
* because a rule already settles them.
|
|
135
|
+
*
|
|
136
|
+
* ```ts
|
|
137
|
+
* const decision = await deliverd.gate({
|
|
138
|
+
* action: "finance.refund",
|
|
139
|
+
* externalId: `refund:${order.id}`,
|
|
140
|
+
* input: { customer_id: order.customerId, amount: 1240, currency: "GBP" },
|
|
141
|
+
* });
|
|
142
|
+
* if (!decision.allowed) return;
|
|
143
|
+
* await stripe.refunds.create(decision.input);
|
|
144
|
+
* ```
|
|
145
|
+
*
|
|
146
|
+
* **Execute with `decision.input`, not your own object.** It is what the
|
|
147
|
+
* action's schema validated and what an approver actually saw. Passing the
|
|
148
|
+
* original works right up until somebody edits a value before approving, and
|
|
149
|
+
* then it spends an approval for £1200 on a refund of £1240.
|
|
150
|
+
*
|
|
151
|
+
* It does not throw on a refusal — a no is an answer, and `if
|
|
152
|
+
* (decision.allowed)` is the line that follows. It throws when the action is
|
|
153
|
+
* not registered, when the input does not match its schema, or when the wait
|
|
154
|
+
* itself failed.
|
|
155
|
+
*
|
|
156
|
+
* `wait: false` returns a pending decision immediately; `deliverd.gates`
|
|
157
|
+
* is the same thing with the handle exposed.
|
|
158
|
+
*/
|
|
159
|
+
async gate(options) {
|
|
160
|
+
const { action, timeout, onPoll, signal, wait, pollIntervals, ...rest } = options;
|
|
161
|
+
const gate = await this.gates.create({ actionId: action, ...rest }, signal);
|
|
162
|
+
/*
|
|
163
|
+
* No wait when the caller said not to, and none when there is nothing to
|
|
164
|
+
* wait for — a rule that allowed or denied it has already answered, which
|
|
165
|
+
* is the common case and must not cost a poll.
|
|
166
|
+
*/
|
|
167
|
+
if (wait === false || !gate.pending)
|
|
168
|
+
return gate.toDecision();
|
|
169
|
+
const settled = await gate.wait({
|
|
170
|
+
onPoll,
|
|
171
|
+
signal,
|
|
172
|
+
/* The same reasoning as `approve()`: an imaginary approver is instant, so
|
|
173
|
+
* a wait still running after a moment is one that never settles. */
|
|
174
|
+
timeout: durationOrUndefined(timeout) ?? (this.development ? 2_000 : undefined),
|
|
175
|
+
...(pollIntervals ? { pollIntervals } : this.development ? { pollIntervals: FAST_POLL_SCHEDULE } : {}),
|
|
176
|
+
});
|
|
177
|
+
return settled.toDecision();
|
|
178
|
+
}
|
|
123
179
|
/**
|
|
124
180
|
* A yes or no on something small: same mechanism, lower ceremony.
|
|
125
181
|
*
|
package/dist/released.d.ts
CHANGED
|
@@ -25,5 +25,42 @@
|
|
|
25
25
|
* them would mean asserting a surface nobody checked at the time, which is the
|
|
26
26
|
* kind of entry that reads like a fact and is a guess.
|
|
27
27
|
*/
|
|
28
|
+
/**
|
|
29
|
+
* Every version of this package npm has served.
|
|
30
|
+
*
|
|
31
|
+
* Written down because a test cannot reach the registry, and kept *here*
|
|
32
|
+
* rather than in a test because it was in two tests and went stale in both.
|
|
33
|
+
* `version.test.ts` used it to refuse a republish and had stopped at 0.6.2
|
|
34
|
+
* after 0.7.0 shipped, so a behaviour change sat under a published number.
|
|
35
|
+
* `release.test.ts` used the newest entry as a floor and said "0.6.1" — three
|
|
36
|
+
* releases low, which is not false but had stopped refusing 0.6.5, the exact
|
|
37
|
+
* 403 it was written to prevent.
|
|
38
|
+
*
|
|
39
|
+
* Two copies of one fact, drifting apart at different speeds. This is the
|
|
40
|
+
* fact; both read it, and `version.test.ts` holds it against CHANGELOG.md so
|
|
41
|
+
* a release that updates one and not the other fails rather than rots.
|
|
42
|
+
*
|
|
43
|
+
* **Add the version here when you publish it, not before.** An entry is a
|
|
44
|
+
* claim that `npm install @deliverd/sdk@x` works today.
|
|
45
|
+
*/
|
|
46
|
+
export declare const PUBLISHED_TO_NPM: readonly ["0.1.0", "0.2.0", "0.3.0", "0.4.0", "0.5.0", "0.6.0", "0.6.1", "0.6.2", "0.7.0", "0.7.1"];
|
|
47
|
+
/**
|
|
48
|
+
* A fingerprint of what each *published* version recorded.
|
|
49
|
+
*
|
|
50
|
+
* The entry beside this one is a claim about a tarball that exists on a
|
|
51
|
+
* registry and can never change, and the guard that was supposed to hold it
|
|
52
|
+
* still said so in a comment — "a change to an old entry fails here" — while
|
|
53
|
+
* asserting only that the list has no duplicates and more than fifty items.
|
|
54
|
+
* Removing a name from 0.7.0 passed. The comment described a guard nobody had
|
|
55
|
+
* written, which is the most expensive kind of comment.
|
|
56
|
+
*
|
|
57
|
+
* So: sha256 over the entry's items joined by newlines. Editing a published
|
|
58
|
+
* list now means editing this too, which is not something done by accident.
|
|
59
|
+
*
|
|
60
|
+
* Only published versions appear. The working version's surface is *supposed*
|
|
61
|
+
* to move — freezing it would fail on the first honest addition, and a guard
|
|
62
|
+
* that fires on correct work is one somebody deletes.
|
|
63
|
+
*/
|
|
64
|
+
export declare const FROZEN: Record<string, string>;
|
|
28
65
|
export declare const RELEASED: Record<string, readonly string[]>;
|
|
29
66
|
//# sourceMappingURL=released.d.ts.map
|
package/dist/released.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"released.d.ts","sourceRoot":"","sources":["../src/released.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"released.d.ts","sourceRoot":"","sources":["../src/released.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,gBAAgB,qGAWnB,CAAC;AAEX;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAIzC,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAwoCtD,CAAC"}
|