@agentpost-tools/resourceshark-sdk 0.0.0-stage → 0.1.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.md +25 -0
- package/README.md +28 -2
- package/dist/client-C-4s_6Qp.d.ts +1592 -0
- package/dist/client-D2ya4ahY.js +288 -0
- package/dist/commit-B_gOf0Ji.js +384 -0
- package/dist/commit-BxtiTSez.d.ts +171 -0
- package/dist/helpers/index.d.ts +108 -0
- package/dist/helpers/index.js +299 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +3 -0
- package/dist/refusals-D39vDFy2.js +27 -0
- package/dist/server.d.ts +101 -0
- package/dist/server.js +250 -0
- package/dist/workflows/index.d.ts +103 -0
- package/dist/workflows/index.js +519 -0
- package/package.json +36 -4
|
@@ -0,0 +1,1592 @@
|
|
|
1
|
+
/** The portion of one scope's balance that belongs to a batch. */
|
|
2
|
+
interface BalanceBatch<T = string> {
|
|
3
|
+
batchId: BatchId;
|
|
4
|
+
code: string;
|
|
5
|
+
onHand: Quantity;
|
|
6
|
+
held: Quantity;
|
|
7
|
+
available: Quantity;
|
|
8
|
+
expiresAt?: T;
|
|
9
|
+
}
|
|
10
|
+
/** The quantities and freshness of one scope's balance. */
|
|
11
|
+
interface Balance<T = string> {
|
|
12
|
+
resourceId: ResourceId;
|
|
13
|
+
/** The scope read. */
|
|
14
|
+
scope: Scope;
|
|
15
|
+
onHand: Quantity;
|
|
16
|
+
held: Quantity;
|
|
17
|
+
expected: Quantity;
|
|
18
|
+
/** On hand less held, plus expected for backorders. A shortage caused by holds reads as zero. */
|
|
19
|
+
available: Quantity;
|
|
20
|
+
/** Moves with every change to the balance; 0 for a scope that has never had one. */
|
|
21
|
+
version: number;
|
|
22
|
+
/** When the answer was true. */
|
|
23
|
+
asOf: T;
|
|
24
|
+
/** Each batch's share of the balance, included when asked for by batch. */
|
|
25
|
+
batches?: BalanceBatch<T>[];
|
|
26
|
+
}
|
|
27
|
+
/** A balance as returned by a scope read. */
|
|
28
|
+
interface BalanceResponse<T = string> {
|
|
29
|
+
balance: Balance<T>;
|
|
30
|
+
}
|
|
31
|
+
/** The scope and optional breakdown to read. */
|
|
32
|
+
type BalanceQuery = {
|
|
33
|
+
placeId?: string | undefined;
|
|
34
|
+
condition?: string | undefined;
|
|
35
|
+
holderRef?: string | undefined;
|
|
36
|
+
instanceId?: string | undefined;
|
|
37
|
+
by?: 'batch' | undefined;
|
|
38
|
+
};
|
|
39
|
+
type AvailabilityRequest = {
|
|
40
|
+
lines: {
|
|
41
|
+
resourceId: string;
|
|
42
|
+
quantity: number;
|
|
43
|
+
scope?: {
|
|
44
|
+
placeId?: string | undefined;
|
|
45
|
+
condition?: string | undefined;
|
|
46
|
+
holderRef?: string | undefined;
|
|
47
|
+
instanceId?: string | undefined;
|
|
48
|
+
} | undefined;
|
|
49
|
+
from?: {
|
|
50
|
+
batchId?: string | undefined;
|
|
51
|
+
supplyId?: string | undefined;
|
|
52
|
+
} | undefined;
|
|
53
|
+
span?: {
|
|
54
|
+
start: string;
|
|
55
|
+
end: string;
|
|
56
|
+
} | undefined;
|
|
57
|
+
}[];
|
|
58
|
+
};
|
|
59
|
+
interface AvailabilityLine<T = string> {
|
|
60
|
+
resourceId: ResourceId;
|
|
61
|
+
scope: Scope;
|
|
62
|
+
/** The quantity asked about. */
|
|
63
|
+
quantity: Quantity;
|
|
64
|
+
available: Quantity;
|
|
65
|
+
expected: Quantity;
|
|
66
|
+
version: number;
|
|
67
|
+
asOf: T;
|
|
68
|
+
}
|
|
69
|
+
interface AvailabilityResponse<T = string> {
|
|
70
|
+
/** One per line asked about, in the same order. */
|
|
71
|
+
lines: AvailabilityLine<T>[];
|
|
72
|
+
}
|
|
73
|
+
/** The batch a resource's supply can name. */
|
|
74
|
+
interface Batch<T = string> {
|
|
75
|
+
id: BatchId;
|
|
76
|
+
resourceId: ResourceId;
|
|
77
|
+
code: string;
|
|
78
|
+
expiresAt?: T;
|
|
79
|
+
attributes?: Attributes;
|
|
80
|
+
version: number;
|
|
81
|
+
createdAt: T;
|
|
82
|
+
updatedAt: T;
|
|
83
|
+
}
|
|
84
|
+
/** What a caller sends to create a batch. */
|
|
85
|
+
type BatchCreate = {
|
|
86
|
+
resourceId: string;
|
|
87
|
+
code: string;
|
|
88
|
+
expiresAt?: string | undefined;
|
|
89
|
+
attributes?: Record<string, string> | undefined;
|
|
90
|
+
};
|
|
91
|
+
/** What a caller sends to edit a batch. */
|
|
92
|
+
type BatchPatch = {
|
|
93
|
+
resourceId?: string | undefined;
|
|
94
|
+
code?: string | undefined;
|
|
95
|
+
expiresAt?: string | null | undefined;
|
|
96
|
+
attributes?: Record<string, string> | null | undefined;
|
|
97
|
+
};
|
|
98
|
+
/** The filters and page size the batches list uses. */
|
|
99
|
+
type BatchesQuery = {
|
|
100
|
+
limit: number;
|
|
101
|
+
resourceId?: string | undefined;
|
|
102
|
+
after?: string | undefined;
|
|
103
|
+
};
|
|
104
|
+
/** A batch read or returned from a write. */
|
|
105
|
+
interface BatchResponse<T = string> {
|
|
106
|
+
batch: Batch<T>;
|
|
107
|
+
}
|
|
108
|
+
/** One page of batches, with the cursor for the next page when there is one. */
|
|
109
|
+
interface BatchesPage<T = string> {
|
|
110
|
+
batches: Batch<T>[];
|
|
111
|
+
next?: string;
|
|
112
|
+
}
|
|
113
|
+
/** The kind a principal may declare. A principal that declared none has no `kind`. */
|
|
114
|
+
type PrincipalKind = 'human' | 'agent' | 'service';
|
|
115
|
+
/** A principal that acted. Its kind is a label it declared, and ResourceShark decides nothing by it. */
|
|
116
|
+
interface PrincipalRef {
|
|
117
|
+
kind?: PrincipalKind;
|
|
118
|
+
id: string;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Who made a change and for whom, as a change-feed event carries it: the
|
|
122
|
+
* actor, and the delegator when the actor acted under a delegation.
|
|
123
|
+
* ResourceShark's own changes, such as a sweep's, name the `service`
|
|
124
|
+
* principal `resourceshark`.
|
|
125
|
+
*/
|
|
126
|
+
interface ActingContext {
|
|
127
|
+
/** The principal that made the request with its own credential. Your project's secret key is `key:` and the key's name, with no `kind`. */
|
|
128
|
+
actor: PrincipalRef;
|
|
129
|
+
/** The delegator, when the actor acted under a delegation. */
|
|
130
|
+
onBehalfOf?: PrincipalRef;
|
|
131
|
+
}
|
|
132
|
+
/** What one line held or took from a resource. */
|
|
133
|
+
interface Claim<T = string> {
|
|
134
|
+
id: ClaimId;
|
|
135
|
+
resourceId: ResourceId;
|
|
136
|
+
/** The scope it takes from. */
|
|
137
|
+
scope: Scope;
|
|
138
|
+
/**
|
|
139
|
+
* Half-open, UTC. A consumption starts when it was taken and never ends;
|
|
140
|
+
* so does a hold's claim, from when it was placed. A claim on a resource
|
|
141
|
+
* counted in buckets has the span its line asked for, with an end.
|
|
142
|
+
*/
|
|
143
|
+
span: Span<T>;
|
|
144
|
+
/** What it takes. For a hold's claim, what it holds, or held until its hold was resolved. */
|
|
145
|
+
quantity: Quantity;
|
|
146
|
+
/**
|
|
147
|
+
* A claim with a span that ends, on a resource counted in buckets, is a
|
|
148
|
+
* `booking` once it is taken: a consumption there, or a hold's line once
|
|
149
|
+
* its hold is committed. A hold's line is `hold` until then.
|
|
150
|
+
*/
|
|
151
|
+
kind: 'hold' | 'consumption' | 'booking';
|
|
152
|
+
status: 'held' | 'committed' | 'released' | 'expired' | 'cancelled';
|
|
153
|
+
/** The hold it is a line of, for a claim of kind `hold`. */
|
|
154
|
+
holdId?: HoldId;
|
|
155
|
+
/** What its hold's commit took for good; the rest of `quantity` was released. */
|
|
156
|
+
committed?: Quantity;
|
|
157
|
+
/** The entries it drew from, when the resource keeps its supply apart. */
|
|
158
|
+
pegs?: Peg[];
|
|
159
|
+
/** The conversion that took this claim's quantity. */
|
|
160
|
+
transformationId?: TransformationId;
|
|
161
|
+
/** What an estimate first took, kept once it is settled; `quantity` is then the real quantity. */
|
|
162
|
+
estimate?: Quantity;
|
|
163
|
+
/** The real quantity an estimate was settled at. Set once, by the settle. */
|
|
164
|
+
settled?: Quantity;
|
|
165
|
+
holderRef?: Ref;
|
|
166
|
+
/** What it was taken for. A claim taken by a hold commit carries the commit's evidence. */
|
|
167
|
+
evidence?: Evidence;
|
|
168
|
+
/** For a consume or hold commit, kept on the first claim that takes from each resource. */
|
|
169
|
+
sourceKey?: string;
|
|
170
|
+
actor: PrincipalRef;
|
|
171
|
+
onBehalfOf?: PrincipalRef;
|
|
172
|
+
createdAt: T;
|
|
173
|
+
updatedAt: T;
|
|
174
|
+
}
|
|
175
|
+
/** What one line asks to take or check. */
|
|
176
|
+
type ClaimLine = {
|
|
177
|
+
resourceId: string;
|
|
178
|
+
quantity: number;
|
|
179
|
+
scope?: {
|
|
180
|
+
placeId?: string | undefined;
|
|
181
|
+
condition?: string | undefined;
|
|
182
|
+
holderRef?: string | undefined;
|
|
183
|
+
instanceId?: string | undefined;
|
|
184
|
+
} | undefined;
|
|
185
|
+
from?: {
|
|
186
|
+
batchId?: string | undefined;
|
|
187
|
+
supplyId?: string | undefined;
|
|
188
|
+
} | undefined;
|
|
189
|
+
span?: {
|
|
190
|
+
start: string;
|
|
191
|
+
end: string;
|
|
192
|
+
} | undefined;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* One line a take, a hold, or a move couldn't cover, as `insufficient_supply`,
|
|
196
|
+
* `exhausted_until_supply`, and `assignment_infeasible` name it in
|
|
197
|
+
* `details.lines`.
|
|
198
|
+
*/
|
|
199
|
+
interface ShortLine<T = string> {
|
|
200
|
+
/** The line's index in the request. */
|
|
201
|
+
line: number;
|
|
202
|
+
resourceId: ResourceId;
|
|
203
|
+
/** The scope it asked for; on a resource with `identity: instance`, its `instanceId` names the unit. */
|
|
204
|
+
scope: Scope;
|
|
205
|
+
quantity: Quantity;
|
|
206
|
+
/** What the line could take now: on a unit, 0 when it isn't free. */
|
|
207
|
+
available: Quantity;
|
|
208
|
+
/** When the next supply on its scope that starts later starts, when there is some. */
|
|
209
|
+
nextSupplyAt?: T;
|
|
210
|
+
/** On a settle, the claim the line settles. */
|
|
211
|
+
claimId?: ClaimId;
|
|
212
|
+
}
|
|
213
|
+
/** What `insufficient_supply` carries in `details`: each short line and what it has available. */
|
|
214
|
+
interface InsufficientSupplyDetails<T = string> {
|
|
215
|
+
lines: ShortLine<T>[];
|
|
216
|
+
}
|
|
217
|
+
/** What `exhausted_until_supply` carries in `details`: each short line, and when the earliest of their next supply starts. */
|
|
218
|
+
interface ExhaustedUntilSupplyDetails<T = string> {
|
|
219
|
+
lines: ShortLine<T>[];
|
|
220
|
+
nextSupplyAt: T;
|
|
221
|
+
}
|
|
222
|
+
/** What `assignment_infeasible` carries in `details`: each short line, among them every line whose named unit isn't free. */
|
|
223
|
+
interface AssignmentInfeasibleDetails<T = string> {
|
|
224
|
+
lines: ShortLine<T>[];
|
|
225
|
+
}
|
|
226
|
+
type ConsumeRequest = {
|
|
227
|
+
lines: {
|
|
228
|
+
resourceId: string;
|
|
229
|
+
quantity: number;
|
|
230
|
+
scope?: {
|
|
231
|
+
placeId?: string | undefined;
|
|
232
|
+
condition?: string | undefined;
|
|
233
|
+
holderRef?: string | undefined;
|
|
234
|
+
instanceId?: string | undefined;
|
|
235
|
+
} | undefined;
|
|
236
|
+
from?: {
|
|
237
|
+
batchId?: string | undefined;
|
|
238
|
+
supplyId?: string | undefined;
|
|
239
|
+
} | undefined;
|
|
240
|
+
span?: {
|
|
241
|
+
start: string;
|
|
242
|
+
end: string;
|
|
243
|
+
} | undefined;
|
|
244
|
+
}[];
|
|
245
|
+
evidence: {
|
|
246
|
+
kind: string;
|
|
247
|
+
ref: string;
|
|
248
|
+
};
|
|
249
|
+
sourceKey: string;
|
|
250
|
+
estimate?: boolean | undefined;
|
|
251
|
+
};
|
|
252
|
+
interface ConsumeResponse<T = string> {
|
|
253
|
+
/** One per line, in the order of the lines. */
|
|
254
|
+
claims: Claim<T>[];
|
|
255
|
+
/** One per line in the same order. On a bucketed resource, this is the first bucket's movement. */
|
|
256
|
+
movements: Movement<T>[];
|
|
257
|
+
/** Set when the `sourceKey` already named this request: nothing was taken again. */
|
|
258
|
+
duplicate?: true;
|
|
259
|
+
}
|
|
260
|
+
/** The request that settles estimated consumptions. */
|
|
261
|
+
type SettleRequest = {
|
|
262
|
+
lines: {
|
|
263
|
+
claimId: string;
|
|
264
|
+
quantity: number;
|
|
265
|
+
}[];
|
|
266
|
+
sourceKey: string;
|
|
267
|
+
evidence?: {
|
|
268
|
+
kind: string;
|
|
269
|
+
ref: string;
|
|
270
|
+
} | undefined;
|
|
271
|
+
};
|
|
272
|
+
/** What a settle wrote. */
|
|
273
|
+
interface SettleResponse<T = string> {
|
|
274
|
+
/** One per line, settled, in the order of the lines. */
|
|
275
|
+
claims: Claim<T>[];
|
|
276
|
+
/** The `settle` movements, in the order of the lines, one for each claim whose real quantity differs from its estimate. Each names its claim. */
|
|
277
|
+
movements: Movement<T>[];
|
|
278
|
+
/** Set when the `sourceKey` already named this request: nothing was settled again. */
|
|
279
|
+
duplicate?: true;
|
|
280
|
+
}
|
|
281
|
+
/** The filters and page size the claims list uses. */
|
|
282
|
+
type ClaimsQuery = {
|
|
283
|
+
limit: number;
|
|
284
|
+
resourceId?: string | undefined;
|
|
285
|
+
holderRef?: string | undefined;
|
|
286
|
+
status?: 'held' | 'committed' | 'released' | 'expired' | 'cancelled' | undefined;
|
|
287
|
+
kind?: 'hold' | 'consumption' | 'booking' | undefined;
|
|
288
|
+
from?: string | undefined;
|
|
289
|
+
to?: string | undefined;
|
|
290
|
+
after?: string | undefined;
|
|
291
|
+
};
|
|
292
|
+
/** One page of claims, with the cursor for the next page when there is one. */
|
|
293
|
+
interface ClaimsPage<T = string> {
|
|
294
|
+
claims: Claim<T>[];
|
|
295
|
+
next?: string;
|
|
296
|
+
}
|
|
297
|
+
/** The claim read by ID. */
|
|
298
|
+
interface ClaimResponse<T = string> {
|
|
299
|
+
claim: Claim<T>;
|
|
300
|
+
}
|
|
301
|
+
type ResourcesharkConfig = {
|
|
302
|
+
retention: {
|
|
303
|
+
events: string;
|
|
304
|
+
resolvedHolds: string;
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
interface ConfigRecord<T = string> extends ResourcesharkConfig {
|
|
308
|
+
version: number;
|
|
309
|
+
updatedAt: T;
|
|
310
|
+
updatedBy: string;
|
|
311
|
+
}
|
|
312
|
+
interface ConfigResponse<T = string> {
|
|
313
|
+
config: ConfigRecord<T>;
|
|
314
|
+
}
|
|
315
|
+
type Duration = string;
|
|
316
|
+
type ErrorClass = 'retry_later' | 'exhausted' | 'change_the_request';
|
|
317
|
+
type ErrorCode = 'invalid_request' | 'payload_too_large' | 'idempotency_mismatch' | 'conflict' | 'unauthenticated' | 'forbidden' | 'not_found' | 'key_in_use' | 'stale_version' | 'settings_locked' | 'duplicate_source' | 'invalid_quantity' | 'insufficient_supply' | 'exhausted_until_supply' | 'assignment_infeasible' | 'hold_expired' | 'hold_resolved' | 'internal_error';
|
|
318
|
+
interface ErrorBody {
|
|
319
|
+
error: {
|
|
320
|
+
code: ErrorCode;
|
|
321
|
+
class: ErrorClass;
|
|
322
|
+
message: string;
|
|
323
|
+
details?: unknown;
|
|
324
|
+
docs: string;
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
/** One change-feed record: CloudEvents 1.0, structured JSON. */
|
|
328
|
+
interface ChangeEvent<T = string> {
|
|
329
|
+
id: string;
|
|
330
|
+
seq: number;
|
|
331
|
+
specversion: '1.0';
|
|
332
|
+
type: string;
|
|
333
|
+
/** `EVENT_SOURCE`, written out so the SDK's generated types need no value. */
|
|
334
|
+
source: '/resourceshark';
|
|
335
|
+
/** The record the event is about. */
|
|
336
|
+
subject?: string;
|
|
337
|
+
time: T;
|
|
338
|
+
datacontenttype: 'application/json';
|
|
339
|
+
data: {
|
|
340
|
+
/** Who made the change, and for whom. */
|
|
341
|
+
context: ActingContext;
|
|
342
|
+
[k: string]: unknown;
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
type EventsQuery = {
|
|
346
|
+
after: number;
|
|
347
|
+
limit: number;
|
|
348
|
+
types?: string | undefined;
|
|
349
|
+
};
|
|
350
|
+
interface EventsPage<T = string> {
|
|
351
|
+
events: ChangeEvent<T>[];
|
|
352
|
+
/** Pass as `after` to continue. The last event's `seq`, or `after` when the page is empty. */
|
|
353
|
+
next: number;
|
|
354
|
+
}
|
|
355
|
+
/** What one holder has on one resource. */
|
|
356
|
+
interface HolderBalance<T = string> {
|
|
357
|
+
resourceId: ResourceId;
|
|
358
|
+
holderRef: Ref;
|
|
359
|
+
onHand: Quantity;
|
|
360
|
+
held: Quantity;
|
|
361
|
+
available: Quantity;
|
|
362
|
+
/** Moves with every change to the balance; 0 for one that has never had one. */
|
|
363
|
+
version: number;
|
|
364
|
+
/** The holder's supply on hand, such as added entries and outputs, in the order a take draws from them. */
|
|
365
|
+
supply: SupplyEntry<T>[];
|
|
366
|
+
/** When the next of the holder's supply that starts later starts, when it has some. */
|
|
367
|
+
nextSupplyAt?: T;
|
|
368
|
+
}
|
|
369
|
+
/** A holder's balance on one resource. */
|
|
370
|
+
interface HolderBalanceResponse<T = string> {
|
|
371
|
+
balance: HolderBalance<T>;
|
|
372
|
+
}
|
|
373
|
+
/** One page of a holder's balances, with the cursor for the next page when there is one. */
|
|
374
|
+
interface HolderBalancesPage<T = string> {
|
|
375
|
+
balances: HolderBalance<T>[];
|
|
376
|
+
next?: string;
|
|
377
|
+
}
|
|
378
|
+
/** The place, condition, cursor, and page size the list of a holder's balances uses. */
|
|
379
|
+
type HolderBalancesQuery = {
|
|
380
|
+
limit: number;
|
|
381
|
+
placeId?: string | undefined;
|
|
382
|
+
condition?: string | undefined;
|
|
383
|
+
after?: string | undefined;
|
|
384
|
+
};
|
|
385
|
+
type HoldStatus = 'committed' | 'released' | 'expired' | 'cancelled' | 'open' | 'partially_committed';
|
|
386
|
+
/** One line of a hold, as its claim stands. */
|
|
387
|
+
interface HoldLine<T = string> {
|
|
388
|
+
claimId: ClaimId;
|
|
389
|
+
resourceId: ResourceId;
|
|
390
|
+
/** The scope it holds from. */
|
|
391
|
+
scope: Scope;
|
|
392
|
+
/** On a resource counted in buckets: the time the line holds, `[start, end)`. */
|
|
393
|
+
span?: FiniteSpan<T>;
|
|
394
|
+
/** What the line holds, or held until the hold was resolved. */
|
|
395
|
+
quantity: Quantity;
|
|
396
|
+
/** `cancelled` once a cancel gave back what its commit took. */
|
|
397
|
+
status: 'held' | 'committed' | 'released' | 'expired' | 'cancelled';
|
|
398
|
+
/** What the commit took for good; the rest of `quantity` was released. */
|
|
399
|
+
committed?: Quantity;
|
|
400
|
+
/** The supply entries the line holds from, or took from once committed, on a resource whose supply is told apart. */
|
|
401
|
+
pegs?: Peg[];
|
|
402
|
+
}
|
|
403
|
+
/** One cancel of a committed hold: the lines it gave back. */
|
|
404
|
+
interface HoldCancellation<T = string> {
|
|
405
|
+
at: T;
|
|
406
|
+
claimIds: ClaimId[];
|
|
407
|
+
evidence?: Evidence;
|
|
408
|
+
sourceKey: string;
|
|
409
|
+
}
|
|
410
|
+
/** How a hold ended. */
|
|
411
|
+
interface HoldResolution<T = string> {
|
|
412
|
+
/** When: the commit or the release, or, for an expiry, the `expiresAt` it ran out at. */
|
|
413
|
+
at: T;
|
|
414
|
+
/** What a commit was made for, such as the order. */
|
|
415
|
+
evidence?: Evidence;
|
|
416
|
+
/** The commit's `sourceKey`. */
|
|
417
|
+
sourceKey?: string;
|
|
418
|
+
}
|
|
419
|
+
interface Hold<T = string> {
|
|
420
|
+
id: HoldId;
|
|
421
|
+
/** A label supplied by the app for grouping holds. */
|
|
422
|
+
label?: Ref;
|
|
423
|
+
/** When it runs out, set by the server. */
|
|
424
|
+
expiresAt: T;
|
|
425
|
+
/** Whom it holds for. */
|
|
426
|
+
holderRef?: Ref;
|
|
427
|
+
/** What it was placed for, such as the checkout or the order. */
|
|
428
|
+
reference?: Evidence;
|
|
429
|
+
/** One per line asked for, in the same order. */
|
|
430
|
+
lines: HoldLine<T>[];
|
|
431
|
+
/** `expired` from `expiresAt` on if the hold was still open. */
|
|
432
|
+
status: HoldStatus;
|
|
433
|
+
/** Set once the hold is no longer open. */
|
|
434
|
+
resolution?: HoldResolution<T>;
|
|
435
|
+
/** Each cancel of the committed hold, in order. */
|
|
436
|
+
cancellations?: HoldCancellation<T>[];
|
|
437
|
+
sourceKey: string;
|
|
438
|
+
/** The principal that placed it with its own credential. */
|
|
439
|
+
actor: PrincipalRef;
|
|
440
|
+
onBehalfOf?: PrincipalRef;
|
|
441
|
+
createdAt: T;
|
|
442
|
+
updatedAt: T;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* A resolved hold once retention has removed its detail: what its
|
|
446
|
+
* `sourceKey` and its commit's still answer with. Its lines are the ones a
|
|
447
|
+
* commit took from, which stay as the record of what was taken.
|
|
448
|
+
*/
|
|
449
|
+
interface RetainedHold<T = string> {
|
|
450
|
+
id: HoldId;
|
|
451
|
+
/** How it ended. */
|
|
452
|
+
status: Exclude<HoldStatus, 'open'>;
|
|
453
|
+
resolution: HoldResolution<T>;
|
|
454
|
+
sourceKey: string;
|
|
455
|
+
lines: HoldLine<T>[];
|
|
456
|
+
/** When retention removed the rest, including the label, holder, and lines that took nothing. */
|
|
457
|
+
retainedAt: T;
|
|
458
|
+
}
|
|
459
|
+
type HoldCreate = {
|
|
460
|
+
lines: {
|
|
461
|
+
resourceId: string;
|
|
462
|
+
quantity: number;
|
|
463
|
+
scope?: {
|
|
464
|
+
placeId?: string | undefined;
|
|
465
|
+
condition?: string | undefined;
|
|
466
|
+
holderRef?: string | undefined;
|
|
467
|
+
instanceId?: string | undefined;
|
|
468
|
+
} | undefined;
|
|
469
|
+
from?: {
|
|
470
|
+
batchId?: string | undefined;
|
|
471
|
+
supplyId?: string | undefined;
|
|
472
|
+
} | undefined;
|
|
473
|
+
span?: {
|
|
474
|
+
start: string;
|
|
475
|
+
end: string;
|
|
476
|
+
} | undefined;
|
|
477
|
+
}[];
|
|
478
|
+
ttl: string;
|
|
479
|
+
sourceKey: string;
|
|
480
|
+
label?: string | undefined;
|
|
481
|
+
holderRef?: string | undefined;
|
|
482
|
+
reference?: {
|
|
483
|
+
kind: string;
|
|
484
|
+
ref: string;
|
|
485
|
+
} | undefined;
|
|
486
|
+
};
|
|
487
|
+
type HoldExtend = {
|
|
488
|
+
ttl: string;
|
|
489
|
+
};
|
|
490
|
+
type HoldCommit = {
|
|
491
|
+
evidence: {
|
|
492
|
+
kind: string;
|
|
493
|
+
ref: string;
|
|
494
|
+
};
|
|
495
|
+
sourceKey: string;
|
|
496
|
+
lines?: {
|
|
497
|
+
claimId: string;
|
|
498
|
+
quantity: number;
|
|
499
|
+
}[] | undefined;
|
|
500
|
+
};
|
|
501
|
+
type HoldCancel = {
|
|
502
|
+
sourceKey: string;
|
|
503
|
+
lines?: string[] | undefined;
|
|
504
|
+
evidence?: {
|
|
505
|
+
kind: string;
|
|
506
|
+
ref: string;
|
|
507
|
+
} | undefined;
|
|
508
|
+
};
|
|
509
|
+
type HoldReschedule = {
|
|
510
|
+
lines: {
|
|
511
|
+
claimId: string;
|
|
512
|
+
resourceId?: string | undefined;
|
|
513
|
+
scope?: {
|
|
514
|
+
placeId?: string | undefined;
|
|
515
|
+
condition?: string | undefined;
|
|
516
|
+
holderRef?: string | undefined;
|
|
517
|
+
instanceId?: string | undefined;
|
|
518
|
+
} | undefined;
|
|
519
|
+
span?: {
|
|
520
|
+
start: string;
|
|
521
|
+
end: string;
|
|
522
|
+
} | undefined;
|
|
523
|
+
}[];
|
|
524
|
+
sourceKey: string;
|
|
525
|
+
evidence?: {
|
|
526
|
+
kind: string;
|
|
527
|
+
ref: string;
|
|
528
|
+
} | undefined;
|
|
529
|
+
};
|
|
530
|
+
/** The query as a client writes it, before defaults apply. */
|
|
531
|
+
type HoldsQueryInput = {
|
|
532
|
+
holderRef?: string | undefined;
|
|
533
|
+
label?: string | undefined;
|
|
534
|
+
status?: 'committed' | 'released' | 'expired' | 'cancelled' | 'open' | 'partially_committed' | undefined;
|
|
535
|
+
after?: string | undefined;
|
|
536
|
+
limit?: unknown;
|
|
537
|
+
};
|
|
538
|
+
interface HoldResponse<T = string> {
|
|
539
|
+
/** A `RetainedHold`, with `retainedAt`, once retention has removed the hold's detail. */
|
|
540
|
+
hold: Hold<T> | RetainedHold<T>;
|
|
541
|
+
/** Set when the `sourceKey` already named this request: nothing was held again. */
|
|
542
|
+
duplicate?: true;
|
|
543
|
+
}
|
|
544
|
+
interface HoldCommitResponse<T = string> {
|
|
545
|
+
/** A `RetainedHold`, with `retainedAt`, when the commit is repeated after retention has removed the hold's detail. */
|
|
546
|
+
hold: Hold<T> | RetainedHold<T>;
|
|
547
|
+
/** What the commit moved, in the order of the lines: one for each line it took from or let go. */
|
|
548
|
+
movements: Movement<T>[];
|
|
549
|
+
/** Set when the `sourceKey` already named this commit: nothing was taken again. */
|
|
550
|
+
duplicate?: true;
|
|
551
|
+
}
|
|
552
|
+
interface HoldCancelResponse<T = string> {
|
|
553
|
+
/** A `RetainedHold`, with `retainedAt`, when the cancel is repeated after retention has removed the hold's detail. */
|
|
554
|
+
hold: Hold<T> | RetainedHold<T>;
|
|
555
|
+
/** What the cancel gave back, one for each line, in the order the hold lists them: on buckets, its first bucket's. */
|
|
556
|
+
movements: Movement<T>[];
|
|
557
|
+
/** Set when the `sourceKey` already named this cancel: nothing was given back again. */
|
|
558
|
+
duplicate?: true;
|
|
559
|
+
}
|
|
560
|
+
/** Where a hold line sits: its resource, its scope there, and its span. */
|
|
561
|
+
interface LinePosition<T = string> {
|
|
562
|
+
resourceId: ResourceId;
|
|
563
|
+
scope: Scope;
|
|
564
|
+
span: FiniteSpan<T>;
|
|
565
|
+
}
|
|
566
|
+
/** One line a reschedule moved: its hold, and where it sat before and after. */
|
|
567
|
+
interface RescheduledLine<T = string> {
|
|
568
|
+
claimId: ClaimId;
|
|
569
|
+
holdId: HoldId;
|
|
570
|
+
before: LinePosition<T>;
|
|
571
|
+
after: LinePosition<T>;
|
|
572
|
+
}
|
|
573
|
+
interface HoldRescheduleResponse<T = string> {
|
|
574
|
+
/**
|
|
575
|
+
* Each hold a line belongs to, in the order first named, in full and as
|
|
576
|
+
* it now is, which the caller is asked to be allowed to reschedule as a
|
|
577
|
+
* whole. A repeat under the `sourceKey` shows each as it is at the
|
|
578
|
+
* repeat, after any later change, and a `RetainedHold` once retention has
|
|
579
|
+
* removed its detail.
|
|
580
|
+
*/
|
|
581
|
+
holds: (Hold<T> | RetainedHold<T>)[];
|
|
582
|
+
/** The lines that moved, in request order, as they moved then, a repeat included; a line already where it was asked to be isn't listed. */
|
|
583
|
+
lines: RescheduledLine<T>[];
|
|
584
|
+
/** Set when the `sourceKey` already named this reschedule: nothing moved again. */
|
|
585
|
+
duplicate?: true;
|
|
586
|
+
}
|
|
587
|
+
interface HoldsPage<T = string> {
|
|
588
|
+
holds: Hold<T>[];
|
|
589
|
+
next?: string;
|
|
590
|
+
}
|
|
591
|
+
/** What `hold_resolved` carries in `details`: how the hold first ended. */
|
|
592
|
+
interface HoldResolvedDetails<T = string> {
|
|
593
|
+
holdId: HoldId;
|
|
594
|
+
status: Exclude<HoldStatus, 'open'>;
|
|
595
|
+
resolution: HoldResolution<T>;
|
|
596
|
+
}
|
|
597
|
+
/** What `hold_expired` carries in `details`, including availability for a commit while the hold's lines are still kept. */
|
|
598
|
+
interface HoldExpiredDetails<T = string> {
|
|
599
|
+
holdId: HoldId;
|
|
600
|
+
expiresAt: T;
|
|
601
|
+
lines?: {
|
|
602
|
+
claimId: ClaimId;
|
|
603
|
+
resourceId: ResourceId;
|
|
604
|
+
scope: Scope;
|
|
605
|
+
/** What the commit asked to take. */
|
|
606
|
+
quantity: Quantity;
|
|
607
|
+
available: Quantity;
|
|
608
|
+
}[];
|
|
609
|
+
}
|
|
610
|
+
type PlaceId = string;
|
|
611
|
+
type InstanceId = string;
|
|
612
|
+
type ResourceId = string;
|
|
613
|
+
type SupplyId = string;
|
|
614
|
+
type ClaimId = string;
|
|
615
|
+
type MovementId = string;
|
|
616
|
+
type TransferId = string;
|
|
617
|
+
type HoldId = string;
|
|
618
|
+
/** Identifies a batch that supply can name. */
|
|
619
|
+
type BatchId = string;
|
|
620
|
+
/** Identifies the conversion that links its inputs and outputs. */
|
|
621
|
+
type TransformationId = string;
|
|
622
|
+
/** Identifies a dated change to a bucketed resource's capacity. */
|
|
623
|
+
type ExceptionId = string;
|
|
624
|
+
type MovementReason = 'hold' | 'capacity' | 'count' | 'expected' | 'add' | 'release' | 'expire_hold' | 'commit' | 'use' | 'settle' | 'transfer' | 'adjustment' | 'reversal' | 'convert_in' | 'convert_out' | 'expire_supply' | 'cancel';
|
|
625
|
+
/** How one of a balance's quantities moved: signed, with the value before and after. */
|
|
626
|
+
interface QuantityChange {
|
|
627
|
+
quantity: Quantity;
|
|
628
|
+
before: Quantity;
|
|
629
|
+
after: Quantity;
|
|
630
|
+
}
|
|
631
|
+
/** The history of one change to a balance. */
|
|
632
|
+
interface Movement<T = string> extends QuantityChange {
|
|
633
|
+
id: MovementId;
|
|
634
|
+
/** The project's movement sequence: every movement in the project, in the order they committed. */
|
|
635
|
+
seq: number;
|
|
636
|
+
resourceId: ResourceId;
|
|
637
|
+
scope: Scope;
|
|
638
|
+
/** The bucket it moved, for a resource whose time is counted in buckets. */
|
|
639
|
+
bucketStart?: T;
|
|
640
|
+
/** How held moved, when it did. */
|
|
641
|
+
held?: QuantityChange;
|
|
642
|
+
expected?: QuantityChange;
|
|
643
|
+
reason: MovementReason;
|
|
644
|
+
supplyId?: SupplyId;
|
|
645
|
+
/** The supply entries it drew from or returned to. */
|
|
646
|
+
pegs?: Peg[];
|
|
647
|
+
/** Set when everything it moved was from or for the same batch. */
|
|
648
|
+
batchId?: BatchId;
|
|
649
|
+
/** The conversion this movement was part of. */
|
|
650
|
+
transformationId?: TransformationId;
|
|
651
|
+
claimId?: ClaimId;
|
|
652
|
+
holdId?: HoldId;
|
|
653
|
+
transferId?: TransferId;
|
|
654
|
+
reversesId?: MovementId;
|
|
655
|
+
evidence?: Evidence;
|
|
656
|
+
note?: string;
|
|
657
|
+
/** The principal that made the change with its own credential. Your project's secret key is `key:` and the key's name, with no `kind`; ResourceShark's own changes are the `service` principal `resourceshark`. */
|
|
658
|
+
actor: PrincipalRef;
|
|
659
|
+
/** The delegator, when the actor acted under a delegation. */
|
|
660
|
+
onBehalfOf?: PrincipalRef;
|
|
661
|
+
at: T;
|
|
662
|
+
}
|
|
663
|
+
/** The filters and cursor the movement list uses. */
|
|
664
|
+
type MovementsQuery = {
|
|
665
|
+
after: number;
|
|
666
|
+
limit: number;
|
|
667
|
+
resourceId?: string | undefined;
|
|
668
|
+
placeId?: string | undefined;
|
|
669
|
+
holderRef?: string | undefined;
|
|
670
|
+
batchId?: string | undefined;
|
|
671
|
+
instanceId?: string | undefined;
|
|
672
|
+
};
|
|
673
|
+
interface MovementResponse<T = string> {
|
|
674
|
+
movement: Movement<T>;
|
|
675
|
+
}
|
|
676
|
+
interface MovementsPage<T = string> {
|
|
677
|
+
movements: Movement<T>[];
|
|
678
|
+
/** Pass as `after` to continue. The last movement's seq, or `after` on an empty page. */
|
|
679
|
+
next: number;
|
|
680
|
+
}
|
|
681
|
+
/** The selection, period, grouping, and holder a totals read reads. */
|
|
682
|
+
type TotalsQuery = {
|
|
683
|
+
resourceId?: string | undefined;
|
|
684
|
+
tag?: string | undefined;
|
|
685
|
+
from?: string | undefined;
|
|
686
|
+
to?: string | undefined;
|
|
687
|
+
groupBy?: string | undefined;
|
|
688
|
+
holderRef?: string | undefined;
|
|
689
|
+
};
|
|
690
|
+
/** A balance summed over scopes, each scope counted as a balance read counts it: an expired hold holds nothing, and supply past its expiry is not on hand. */
|
|
691
|
+
interface TotalsBalance {
|
|
692
|
+
onHand: Quantity;
|
|
693
|
+
held: Quantity;
|
|
694
|
+
available: Quantity;
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* Movements summed by reason: for each reason that occurred, the sum of
|
|
698
|
+
* what those movements changed on hand, signed, such as `{ add: 500, use:
|
|
699
|
+
* -150, reversal: -10 }`. A reason that moves only what is held or
|
|
700
|
+
* expected, such as `hold`, sums to 0. On a resource counted in buckets
|
|
701
|
+
* each movement moves one bucket, so a sum counts units times buckets,
|
|
702
|
+
* such as a room for three nights as 3.
|
|
703
|
+
*/
|
|
704
|
+
type MovementSums = Partial<Record<MovementReason, Quantity>>;
|
|
705
|
+
/** The totals of one value of the grouping attribute, or of the entries without it. */
|
|
706
|
+
interface TotalsGroup {
|
|
707
|
+
/** The attribute's value on these entries, or null for the entries that don't carry it. */
|
|
708
|
+
value: string | null;
|
|
709
|
+
/** What these entries have, as the resource's balance counts it. */
|
|
710
|
+
balance: TotalsBalance;
|
|
711
|
+
/** When a period was asked for: what movements in it changed on these entries, by reason. */
|
|
712
|
+
movements?: MovementSums;
|
|
713
|
+
}
|
|
714
|
+
/** One resource's totals. */
|
|
715
|
+
interface ResourceTotals {
|
|
716
|
+
resourceId: ResourceId;
|
|
717
|
+
key: string;
|
|
718
|
+
name: string;
|
|
719
|
+
unit: Unit;
|
|
720
|
+
/**
|
|
721
|
+
* The resource's balance over its scopes, or one holder's. Null on a
|
|
722
|
+
* resource counted in buckets: it has a balance for each bucket of
|
|
723
|
+
* time, and buckets of different times are never added together.
|
|
724
|
+
*/
|
|
725
|
+
balance: TotalsBalance | null;
|
|
726
|
+
/** When a period was asked for: the resource's movements in it, by reason. */
|
|
727
|
+
movements?: MovementSums;
|
|
728
|
+
/**
|
|
729
|
+
* When `groupBy` was asked for: the totals for each value of that
|
|
730
|
+
* attribute on the resource's supply entries, by value and the entries
|
|
731
|
+
* without it last. A unit counts in the group of the entry it sits on,
|
|
732
|
+
* and a movement in the groups of the entries it drew from or added to,
|
|
733
|
+
* so the groups add up to the resource's totals. Null on a resource that
|
|
734
|
+
* keeps one running balance or counts in buckets: it keeps no supply
|
|
735
|
+
* entries apart, so there is nothing to group by.
|
|
736
|
+
*/
|
|
737
|
+
groups?: TotalsGroup[] | null;
|
|
738
|
+
}
|
|
739
|
+
/** Sums for each selected resource. */
|
|
740
|
+
interface TotalsReport<T = string> {
|
|
741
|
+
/** When the totals were read. A balance counts what had expired by then; a write that landed while the read ran may or may not be counted. */
|
|
742
|
+
asOf: T;
|
|
743
|
+
/** The period, when one was asked for. `from` is in it and `to` is not. */
|
|
744
|
+
from?: T;
|
|
745
|
+
to?: T;
|
|
746
|
+
groupBy?: string;
|
|
747
|
+
holderRef?: Ref;
|
|
748
|
+
/** The resources the selection matched, in the order they were created. */
|
|
749
|
+
resources: ResourceTotals[];
|
|
750
|
+
}
|
|
751
|
+
type ResourceCreate = {
|
|
752
|
+
key: string;
|
|
753
|
+
name: string;
|
|
754
|
+
unit: {
|
|
755
|
+
code: string;
|
|
756
|
+
singular: string;
|
|
757
|
+
plural: string;
|
|
758
|
+
precision: number;
|
|
759
|
+
};
|
|
760
|
+
settings: {
|
|
761
|
+
time: 'none' | 'buckets';
|
|
762
|
+
identity: 'count' | 'instance';
|
|
763
|
+
supplyExpiry: 'none' | 'expiring';
|
|
764
|
+
bucket?: {
|
|
765
|
+
size: 'step';
|
|
766
|
+
stepMinutes: number;
|
|
767
|
+
timeZone: string;
|
|
768
|
+
} | {
|
|
769
|
+
size: 'day' | 'month';
|
|
770
|
+
timeZone: string;
|
|
771
|
+
stepMinutes?: number | undefined;
|
|
772
|
+
} | undefined;
|
|
773
|
+
};
|
|
774
|
+
scope: {
|
|
775
|
+
places: boolean;
|
|
776
|
+
holders: boolean;
|
|
777
|
+
};
|
|
778
|
+
tracking: 'batch' | 'none';
|
|
779
|
+
shortage: 'deny' | 'backorder' | 'negative';
|
|
780
|
+
capacity?: number | undefined;
|
|
781
|
+
tags?: string[] | undefined;
|
|
782
|
+
attributes?: Record<string, string> | undefined;
|
|
783
|
+
contentRef?: string | undefined;
|
|
784
|
+
externalRef?: string | undefined;
|
|
785
|
+
};
|
|
786
|
+
type ResourcePatch = {
|
|
787
|
+
key?: string | undefined;
|
|
788
|
+
name?: string | undefined;
|
|
789
|
+
tracking?: 'batch' | 'none' | undefined;
|
|
790
|
+
shortage?: 'deny' | 'backorder' | 'negative' | undefined;
|
|
791
|
+
settings?: {
|
|
792
|
+
time?: 'none' | 'buckets' | undefined;
|
|
793
|
+
identity?: 'count' | 'instance' | undefined;
|
|
794
|
+
supplyExpiry?: 'none' | 'expiring' | undefined;
|
|
795
|
+
bucket?: {
|
|
796
|
+
size: 'step';
|
|
797
|
+
stepMinutes: number;
|
|
798
|
+
timeZone: string;
|
|
799
|
+
} | {
|
|
800
|
+
size: 'day' | 'month';
|
|
801
|
+
timeZone: string;
|
|
802
|
+
stepMinutes?: number | undefined;
|
|
803
|
+
} | null | undefined;
|
|
804
|
+
} | undefined;
|
|
805
|
+
scope?: {
|
|
806
|
+
places?: boolean | undefined;
|
|
807
|
+
holders?: boolean | undefined;
|
|
808
|
+
} | undefined;
|
|
809
|
+
unit?: {
|
|
810
|
+
code?: string | undefined;
|
|
811
|
+
singular?: string | undefined;
|
|
812
|
+
plural?: string | undefined;
|
|
813
|
+
precision?: number | undefined;
|
|
814
|
+
} | undefined;
|
|
815
|
+
capacity?: number | null | undefined;
|
|
816
|
+
attributes?: Record<string, string> | null | undefined;
|
|
817
|
+
contentRef?: string | null | undefined;
|
|
818
|
+
externalRef?: string | null | undefined;
|
|
819
|
+
tags?: string[] | undefined;
|
|
820
|
+
};
|
|
821
|
+
type ResourceDefinition = {
|
|
822
|
+
key: string;
|
|
823
|
+
name: string;
|
|
824
|
+
unit: {
|
|
825
|
+
code: string;
|
|
826
|
+
singular: string;
|
|
827
|
+
plural: string;
|
|
828
|
+
precision: number;
|
|
829
|
+
};
|
|
830
|
+
settings: {
|
|
831
|
+
time: 'none' | 'buckets';
|
|
832
|
+
identity: 'count' | 'instance';
|
|
833
|
+
supplyExpiry: 'none' | 'expiring';
|
|
834
|
+
bucket?: {
|
|
835
|
+
size: 'step';
|
|
836
|
+
stepMinutes: number;
|
|
837
|
+
timeZone: string;
|
|
838
|
+
} | {
|
|
839
|
+
size: 'day' | 'month';
|
|
840
|
+
timeZone: string;
|
|
841
|
+
stepMinutes?: number | undefined;
|
|
842
|
+
} | undefined;
|
|
843
|
+
};
|
|
844
|
+
scope: {
|
|
845
|
+
places: boolean;
|
|
846
|
+
holders: boolean;
|
|
847
|
+
};
|
|
848
|
+
tracking: 'batch' | 'none';
|
|
849
|
+
shortage: 'deny' | 'backorder' | 'negative';
|
|
850
|
+
tags: string[];
|
|
851
|
+
capacity?: number | undefined;
|
|
852
|
+
attributes?: Record<string, string> | undefined;
|
|
853
|
+
contentRef?: string | undefined;
|
|
854
|
+
externalRef?: string | undefined;
|
|
855
|
+
};
|
|
856
|
+
interface Resource<T = string> extends Omit<ResourceDefinition, 'capacity'> {
|
|
857
|
+
id: ResourceId;
|
|
858
|
+
capacity?: Quantity;
|
|
859
|
+
version: number;
|
|
860
|
+
archivedAt?: T;
|
|
861
|
+
}
|
|
862
|
+
type PlacesQuery = {
|
|
863
|
+
limit: number;
|
|
864
|
+
after?: string | undefined;
|
|
865
|
+
};
|
|
866
|
+
type ResourcesQuery = {
|
|
867
|
+
limit: number;
|
|
868
|
+
after?: string | undefined;
|
|
869
|
+
key?: string | undefined;
|
|
870
|
+
tag?: string | undefined;
|
|
871
|
+
};
|
|
872
|
+
type InstancesQuery = {
|
|
873
|
+
limit: number;
|
|
874
|
+
after?: string | undefined;
|
|
875
|
+
code?: string | undefined;
|
|
876
|
+
};
|
|
877
|
+
type FreeInstancesQuery = {
|
|
878
|
+
limit: number;
|
|
879
|
+
after?: string | undefined;
|
|
880
|
+
placeId?: string | undefined;
|
|
881
|
+
condition?: string | undefined;
|
|
882
|
+
holderRef?: string | undefined;
|
|
883
|
+
from?: string | undefined;
|
|
884
|
+
to?: string | undefined;
|
|
885
|
+
};
|
|
886
|
+
interface ResourceResponse<T = string> {
|
|
887
|
+
resource: Resource<T>;
|
|
888
|
+
/** With a change to a bucketed resource's `capacity`: the buckets now over it. */
|
|
889
|
+
overCapacity?: OverCapacity<T>;
|
|
890
|
+
}
|
|
891
|
+
interface ResourcesPage<T = string> {
|
|
892
|
+
resources: Resource<T>[];
|
|
893
|
+
next?: string;
|
|
894
|
+
}
|
|
895
|
+
type PlaceCreate = {
|
|
896
|
+
key: string;
|
|
897
|
+
name: string;
|
|
898
|
+
attributes?: Record<string, string> | undefined;
|
|
899
|
+
};
|
|
900
|
+
type PlacePatch = {
|
|
901
|
+
key?: string | undefined;
|
|
902
|
+
name?: string | undefined;
|
|
903
|
+
attributes?: Record<string, string> | null | undefined;
|
|
904
|
+
};
|
|
905
|
+
interface Place extends PlaceCreate {
|
|
906
|
+
id: PlaceId;
|
|
907
|
+
}
|
|
908
|
+
interface PlaceResponse {
|
|
909
|
+
place: Place;
|
|
910
|
+
}
|
|
911
|
+
interface PlacesPage {
|
|
912
|
+
places: Place[];
|
|
913
|
+
next?: string;
|
|
914
|
+
}
|
|
915
|
+
/** A period an instance is unavailable and counts toward no capacity. Half-open, with a finite end. */
|
|
916
|
+
interface UnavailableSpan<T = string> {
|
|
917
|
+
start: T;
|
|
918
|
+
end: T;
|
|
919
|
+
}
|
|
920
|
+
type InstanceCreate = {
|
|
921
|
+
code: string;
|
|
922
|
+
status: 'active' | 'retired';
|
|
923
|
+
unavailable?: {
|
|
924
|
+
start: string;
|
|
925
|
+
end: string;
|
|
926
|
+
}[] | undefined;
|
|
927
|
+
attributes?: Record<string, string> | undefined;
|
|
928
|
+
};
|
|
929
|
+
type InstancePatch = {
|
|
930
|
+
code?: string | undefined;
|
|
931
|
+
status?: 'active' | 'retired' | undefined;
|
|
932
|
+
unavailable?: {
|
|
933
|
+
start: string;
|
|
934
|
+
end: string;
|
|
935
|
+
}[] | null | undefined;
|
|
936
|
+
attributes?: Record<string, string> | null | undefined;
|
|
937
|
+
};
|
|
938
|
+
interface Instance<T = string> extends Omit<InstanceCreate, 'unavailable'> {
|
|
939
|
+
id: InstanceId;
|
|
940
|
+
resourceId: ResourceId;
|
|
941
|
+
unavailable?: UnavailableSpan<T>[];
|
|
942
|
+
}
|
|
943
|
+
interface InstanceResponse<T = string> {
|
|
944
|
+
instance: Instance<T>;
|
|
945
|
+
/** With a change to the status or unavailable spans of an instance of a bucketed resource: the buckets now over capacity. */
|
|
946
|
+
overCapacity?: OverCapacity<T>;
|
|
947
|
+
}
|
|
948
|
+
/** A page of instances. A page of free units reads at most `MAX_FREE_SCAN` units, so it can hold fewer than `limit`, even none, and still give `next`. */
|
|
949
|
+
interface InstancesPage<T = string> {
|
|
950
|
+
instances: Instance<T>[];
|
|
951
|
+
next?: string;
|
|
952
|
+
}
|
|
953
|
+
type SchedulePut = {
|
|
954
|
+
patterns: {
|
|
955
|
+
weekly: {
|
|
956
|
+
day: number;
|
|
957
|
+
start: string;
|
|
958
|
+
end: string;
|
|
959
|
+
capacity?: number | undefined;
|
|
960
|
+
}[];
|
|
961
|
+
from?: string | undefined;
|
|
962
|
+
}[];
|
|
963
|
+
timeZone?: string | undefined;
|
|
964
|
+
};
|
|
965
|
+
/** One weekly window, in the schedule's time zone. */
|
|
966
|
+
interface WeeklyWindow {
|
|
967
|
+
day: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
968
|
+
/** `HH:MM`. */
|
|
969
|
+
start: string;
|
|
970
|
+
/** `HH:MM`, or `24:00` for the end of the day. */
|
|
971
|
+
end: string;
|
|
972
|
+
capacity?: Quantity;
|
|
973
|
+
}
|
|
974
|
+
/** A normal week, in effect from `from` until the next pattern starts. */
|
|
975
|
+
interface WeeklyPattern {
|
|
976
|
+
/** `YYYY-MM-DD` in the schedule's time zone. Missing on the first pattern. */
|
|
977
|
+
from?: string;
|
|
978
|
+
weekly: WeeklyWindow[];
|
|
979
|
+
}
|
|
980
|
+
/**
|
|
981
|
+
* A resource's normal week. A bucket takes the pattern in effect on the
|
|
982
|
+
* local date it starts on, in the schedule's time zone. Inside that
|
|
983
|
+
* pattern's hours a bucket holds its window's `capacity`, else the
|
|
984
|
+
* resource's `capacity`, else as many of the resource's active instances
|
|
985
|
+
* as are not unavailable for any part of it, else 0; outside them it holds
|
|
986
|
+
* nothing. A pattern with no windows puts no limit on the hours. A step
|
|
987
|
+
* bucket is inside the hours when one window holds all of it. A day is
|
|
988
|
+
* inside them when a window falls on its weekday, and holds the largest
|
|
989
|
+
* capacity that day's windows give. A month is longer than any window, so
|
|
990
|
+
* patterns don't apply to it: it holds the resource's own capacity. An
|
|
991
|
+
* exception then replaces what the pattern gives (`ScheduleException`).
|
|
992
|
+
*
|
|
993
|
+
* A pattern that has taken effect, `from` today or earlier, stays as it
|
|
994
|
+
* is: a save changes, adds, or removes only patterns from tomorrow on.
|
|
995
|
+
*/
|
|
996
|
+
interface Schedule<T = string> {
|
|
997
|
+
resourceId: ResourceId;
|
|
998
|
+
timeZone: string;
|
|
999
|
+
patterns: WeeklyPattern[];
|
|
1000
|
+
/** Moves with every save; send it in `If-Match` to save again. */
|
|
1001
|
+
version: number;
|
|
1002
|
+
updatedAt: T;
|
|
1003
|
+
}
|
|
1004
|
+
/** One claim in a bucket over capacity. */
|
|
1005
|
+
interface OverCapacityClaim {
|
|
1006
|
+
id: ClaimId;
|
|
1007
|
+
kind: 'hold' | 'consumption' | 'booking';
|
|
1008
|
+
/** `held` or `committed`. */
|
|
1009
|
+
status: 'held' | 'committed' | 'released' | 'expired' | 'cancelled';
|
|
1010
|
+
/** What it holds, or what it took. */
|
|
1011
|
+
quantity: Quantity;
|
|
1012
|
+
holdId?: HoldId;
|
|
1013
|
+
holderRef?: Ref;
|
|
1014
|
+
}
|
|
1015
|
+
/** A bucket where what is held and taken is more than its capacity. */
|
|
1016
|
+
interface OverCapacityBucket<T = string> {
|
|
1017
|
+
span: FiniteSpan<T>;
|
|
1018
|
+
scope: Scope;
|
|
1019
|
+
capacity: Quantity;
|
|
1020
|
+
/** What bookings took. */
|
|
1021
|
+
taken: Quantity;
|
|
1022
|
+
/** What holds not past their expiry hold. */
|
|
1023
|
+
held: Quantity;
|
|
1024
|
+
/** Every claim in it: the service can't say which one is too many, so the app chooses. */
|
|
1025
|
+
claims: OverCapacityClaim[];
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* What a change that moves capacity leaves over it, in buckets that have
|
|
1029
|
+
* not ended, nearest first. `more` is true when there may be more than the
|
|
1030
|
+
* answer lists: past `MAX_OVER_CAPACITY_BUCKETS` buckets or
|
|
1031
|
+
* `MAX_OVER_CAPACITY_CLAIMS` claims, or past the nearest 1,000 buckets a
|
|
1032
|
+
* claim has touched. `GET /slots` and `GET /claims` over a range read the
|
|
1033
|
+
* rest.
|
|
1034
|
+
*/
|
|
1035
|
+
interface OverCapacity<T = string> {
|
|
1036
|
+
buckets: OverCapacityBucket<T>[];
|
|
1037
|
+
more: boolean;
|
|
1038
|
+
}
|
|
1039
|
+
interface ScheduleResponse<T = string> {
|
|
1040
|
+
schedule: Schedule<T>;
|
|
1041
|
+
}
|
|
1042
|
+
interface ScheduleSaveResponse<T = string> extends ScheduleResponse<T> {
|
|
1043
|
+
overCapacity: OverCapacity<T>;
|
|
1044
|
+
}
|
|
1045
|
+
type ExceptionCreate = {
|
|
1046
|
+
span: {
|
|
1047
|
+
start: string;
|
|
1048
|
+
end: string;
|
|
1049
|
+
};
|
|
1050
|
+
capacity: number;
|
|
1051
|
+
sourceKey: string;
|
|
1052
|
+
reason?: string | undefined;
|
|
1053
|
+
};
|
|
1054
|
+
type ExceptionPatch = {
|
|
1055
|
+
span?: {
|
|
1056
|
+
start: string;
|
|
1057
|
+
end: string;
|
|
1058
|
+
} | undefined;
|
|
1059
|
+
capacity?: number | undefined;
|
|
1060
|
+
reason?: string | null | undefined;
|
|
1061
|
+
};
|
|
1062
|
+
interface ScheduleException<T = string> {
|
|
1063
|
+
id: ExceptionId;
|
|
1064
|
+
resourceId: ResourceId;
|
|
1065
|
+
span: FiniteSpan<T>;
|
|
1066
|
+
capacity: Quantity;
|
|
1067
|
+
reason?: string;
|
|
1068
|
+
/** Moves with every change; send it in `If-Match` to change it. */
|
|
1069
|
+
version: number;
|
|
1070
|
+
createdAt: T;
|
|
1071
|
+
updatedAt: T;
|
|
1072
|
+
}
|
|
1073
|
+
interface ExceptionResponse<T = string> {
|
|
1074
|
+
exception: ScheduleException<T>;
|
|
1075
|
+
overCapacity: OverCapacity<T>;
|
|
1076
|
+
}
|
|
1077
|
+
interface ExceptionCreateResponse<T = string> extends ExceptionResponse<T> {
|
|
1078
|
+
/** Set when the source key already named this request. */
|
|
1079
|
+
duplicate?: true;
|
|
1080
|
+
}
|
|
1081
|
+
interface ExceptionDeleteResponse<T = string> {
|
|
1082
|
+
overCapacity: OverCapacity<T>;
|
|
1083
|
+
}
|
|
1084
|
+
type ExceptionsQuery = {
|
|
1085
|
+
from?: string | undefined;
|
|
1086
|
+
to?: string | undefined;
|
|
1087
|
+
};
|
|
1088
|
+
/** At most `MAX_EXCEPTIONS`, so one answer holds them all, by start. */
|
|
1089
|
+
interface ExceptionsList<T = string> {
|
|
1090
|
+
exceptions: ScheduleException<T>[];
|
|
1091
|
+
}
|
|
1092
|
+
type SlotsQuery = {
|
|
1093
|
+
resourceId: string;
|
|
1094
|
+
from: string;
|
|
1095
|
+
to: string;
|
|
1096
|
+
placeId?: string | undefined;
|
|
1097
|
+
condition?: string | undefined;
|
|
1098
|
+
instanceId?: string | undefined;
|
|
1099
|
+
};
|
|
1100
|
+
/**
|
|
1101
|
+
* One bucket a claim can take, or one over capacity, with what it holds
|
|
1102
|
+
* and what is free. A bucket with no capacity is not a slot unless claims
|
|
1103
|
+
* are still in it. Where a daylight-saving change repeats an hour, both of
|
|
1104
|
+
* its buckets are slots with the same local time.
|
|
1105
|
+
*/
|
|
1106
|
+
interface Slot<T = string> {
|
|
1107
|
+
start: T;
|
|
1108
|
+
end: T;
|
|
1109
|
+
/** The resource's bucket time zone. */
|
|
1110
|
+
timeZone: string;
|
|
1111
|
+
/** Where the slot starts, on the local calendar and clock. */
|
|
1112
|
+
local: {
|
|
1113
|
+
date: string;
|
|
1114
|
+
time: string;
|
|
1115
|
+
};
|
|
1116
|
+
/** What the schedule gives the bucket. */
|
|
1117
|
+
capacity: Quantity;
|
|
1118
|
+
/** What bookings took. */
|
|
1119
|
+
taken: Quantity;
|
|
1120
|
+
/** What holds not past their expiry hold. */
|
|
1121
|
+
held: Quantity;
|
|
1122
|
+
/** Capacity less what is held and taken, and never below 0: the bucket is over capacity when `taken` and `held` come to more than `capacity`. */
|
|
1123
|
+
available: Quantity;
|
|
1124
|
+
}
|
|
1125
|
+
interface SlotsResponse<T = string> {
|
|
1126
|
+
slots: Slot<T>[];
|
|
1127
|
+
}
|
|
1128
|
+
/**
|
|
1129
|
+
* An integer in the resource's base unit at its precision, as money is in
|
|
1130
|
+
* cents: grams at precision 0, meters at precision 2, so 1 is 1 cm. A
|
|
1131
|
+
* quantity with a fraction is refused with `invalid_quantity`.
|
|
1132
|
+
*/
|
|
1133
|
+
type Quantity = number;
|
|
1134
|
+
/** How much a claim or movement drew from one supply entry. */
|
|
1135
|
+
interface Peg {
|
|
1136
|
+
supplyId: SupplyId;
|
|
1137
|
+
quantity: Quantity;
|
|
1138
|
+
}
|
|
1139
|
+
/** An opaque reference to another system's record, such as `ord_01J…`. ResourceShark never dereferences one. */
|
|
1140
|
+
type Ref = string;
|
|
1141
|
+
/** What a change was made for, such as `{ kind: "order", ref: "ord_…" }`. */
|
|
1142
|
+
interface Evidence {
|
|
1143
|
+
kind: string;
|
|
1144
|
+
ref: Ref;
|
|
1145
|
+
}
|
|
1146
|
+
/** Half-open, `[start, end)`, in UTC. A null `end` is open-ended. */
|
|
1147
|
+
interface Span<T = string> {
|
|
1148
|
+
start: T;
|
|
1149
|
+
end: T | null;
|
|
1150
|
+
}
|
|
1151
|
+
/**
|
|
1152
|
+
* Where a quantity sits. Each resource says which dimensions apply: stock
|
|
1153
|
+
* has places, prepaid credits have holders, and a resource with
|
|
1154
|
+
* `identity: instance` has units. A resource kept by place requires a
|
|
1155
|
+
* `placeId` and can carry a free-form condition label. Omitting the
|
|
1156
|
+
* condition selects the unlabeled balance. A resource that tells its units
|
|
1157
|
+
* apart requires an `instanceId`: each unit has a balance of its own, in
|
|
1158
|
+
* one place and under one label at a time, and a line on it moves one unit.
|
|
1159
|
+
*/
|
|
1160
|
+
interface Scope {
|
|
1161
|
+
placeId?: PlaceId;
|
|
1162
|
+
condition?: string;
|
|
1163
|
+
holderRef?: Ref;
|
|
1164
|
+
instanceId?: InstanceId;
|
|
1165
|
+
}
|
|
1166
|
+
/** A resource's base unit, with its labels and its precision: the number of decimal places one unit of `Quantity` stands for. */
|
|
1167
|
+
interface Unit {
|
|
1168
|
+
code: string;
|
|
1169
|
+
singular: string;
|
|
1170
|
+
plural: string;
|
|
1171
|
+
precision: number;
|
|
1172
|
+
}
|
|
1173
|
+
/**
|
|
1174
|
+
* The business's own labels. ResourceShark stores them, answers with them, and
|
|
1175
|
+
* never reads meaning into them.
|
|
1176
|
+
*/
|
|
1177
|
+
type Attributes = Record<string, string>;
|
|
1178
|
+
/** Half-open, `[start, end)`, in UTC, with an end. */
|
|
1179
|
+
interface FiniteSpan<T = string> {
|
|
1180
|
+
start: T;
|
|
1181
|
+
end: T;
|
|
1182
|
+
}
|
|
1183
|
+
/** What a caller sends to move stock between scopes. */
|
|
1184
|
+
type TransferCreate = {
|
|
1185
|
+
resourceId: string;
|
|
1186
|
+
from: {
|
|
1187
|
+
placeId?: string | undefined;
|
|
1188
|
+
condition?: string | undefined;
|
|
1189
|
+
holderRef?: string | undefined;
|
|
1190
|
+
instanceId?: string | undefined;
|
|
1191
|
+
batchId?: string | undefined;
|
|
1192
|
+
supplyId?: string | undefined;
|
|
1193
|
+
};
|
|
1194
|
+
to: {
|
|
1195
|
+
placeId?: string | undefined;
|
|
1196
|
+
condition?: string | undefined;
|
|
1197
|
+
holderRef?: string | undefined;
|
|
1198
|
+
instanceId?: string | undefined;
|
|
1199
|
+
};
|
|
1200
|
+
quantity: number;
|
|
1201
|
+
sourceKey: string;
|
|
1202
|
+
evidence?: {
|
|
1203
|
+
kind: string;
|
|
1204
|
+
ref: string;
|
|
1205
|
+
} | undefined;
|
|
1206
|
+
note?: string | undefined;
|
|
1207
|
+
};
|
|
1208
|
+
/** What a caller sends to record a count. */
|
|
1209
|
+
type CountCreate = {
|
|
1210
|
+
version: number;
|
|
1211
|
+
resourceId: string;
|
|
1212
|
+
scope: {
|
|
1213
|
+
placeId?: string | undefined;
|
|
1214
|
+
condition?: string | undefined;
|
|
1215
|
+
holderRef?: string | undefined;
|
|
1216
|
+
instanceId?: string | undefined;
|
|
1217
|
+
};
|
|
1218
|
+
quantity: number;
|
|
1219
|
+
evidence?: {
|
|
1220
|
+
kind: string;
|
|
1221
|
+
ref: string;
|
|
1222
|
+
} | undefined;
|
|
1223
|
+
note?: string | undefined;
|
|
1224
|
+
from?: {
|
|
1225
|
+
batchId?: string | undefined;
|
|
1226
|
+
supplyId?: string | undefined;
|
|
1227
|
+
} | undefined;
|
|
1228
|
+
};
|
|
1229
|
+
/** What a caller sends to adjust or reverse stock. */
|
|
1230
|
+
type AdjustmentCreate = {
|
|
1231
|
+
note: string;
|
|
1232
|
+
sourceKey: string;
|
|
1233
|
+
resourceId: string;
|
|
1234
|
+
scope: {
|
|
1235
|
+
placeId?: string | undefined;
|
|
1236
|
+
condition?: string | undefined;
|
|
1237
|
+
holderRef?: string | undefined;
|
|
1238
|
+
instanceId?: string | undefined;
|
|
1239
|
+
};
|
|
1240
|
+
quantity: number;
|
|
1241
|
+
evidence?: {
|
|
1242
|
+
kind: string;
|
|
1243
|
+
ref: string;
|
|
1244
|
+
} | undefined;
|
|
1245
|
+
from?: {
|
|
1246
|
+
batchId?: string | undefined;
|
|
1247
|
+
supplyId?: string | undefined;
|
|
1248
|
+
} | undefined;
|
|
1249
|
+
} | {
|
|
1250
|
+
reverses: string;
|
|
1251
|
+
sourceKey: string;
|
|
1252
|
+
evidence?: {
|
|
1253
|
+
kind: string;
|
|
1254
|
+
ref: string;
|
|
1255
|
+
} | undefined;
|
|
1256
|
+
note?: string | undefined;
|
|
1257
|
+
};
|
|
1258
|
+
/** What a caller sends to record a conversion. */
|
|
1259
|
+
type TransformationCreate = {
|
|
1260
|
+
takes: {
|
|
1261
|
+
resourceId: string;
|
|
1262
|
+
quantity: number;
|
|
1263
|
+
scope?: {
|
|
1264
|
+
placeId?: string | undefined;
|
|
1265
|
+
condition?: string | undefined;
|
|
1266
|
+
holderRef?: string | undefined;
|
|
1267
|
+
instanceId?: string | undefined;
|
|
1268
|
+
} | undefined;
|
|
1269
|
+
from?: {
|
|
1270
|
+
batchId?: string | undefined;
|
|
1271
|
+
supplyId?: string | undefined;
|
|
1272
|
+
} | undefined;
|
|
1273
|
+
span?: {
|
|
1274
|
+
start: string;
|
|
1275
|
+
end: string;
|
|
1276
|
+
} | undefined;
|
|
1277
|
+
}[];
|
|
1278
|
+
adds: {
|
|
1279
|
+
resourceId: string;
|
|
1280
|
+
quantity: number;
|
|
1281
|
+
scope?: {
|
|
1282
|
+
placeId?: string | undefined;
|
|
1283
|
+
condition?: string | undefined;
|
|
1284
|
+
holderRef?: string | undefined;
|
|
1285
|
+
instanceId?: string | undefined;
|
|
1286
|
+
} | undefined;
|
|
1287
|
+
batchId?: string | undefined;
|
|
1288
|
+
batch?: {
|
|
1289
|
+
code: string;
|
|
1290
|
+
expiresAt?: string | undefined;
|
|
1291
|
+
attributes?: Record<string, string> | undefined;
|
|
1292
|
+
} | undefined;
|
|
1293
|
+
expiresAt?: string | undefined;
|
|
1294
|
+
attributes?: Record<string, string> | undefined;
|
|
1295
|
+
}[];
|
|
1296
|
+
evidence: {
|
|
1297
|
+
kind: string;
|
|
1298
|
+
ref: string;
|
|
1299
|
+
};
|
|
1300
|
+
sourceKey: string;
|
|
1301
|
+
};
|
|
1302
|
+
/** The record that links a conversion's inputs, outputs, and evidence. */
|
|
1303
|
+
interface Transformation<T = string> {
|
|
1304
|
+
id: TransformationId;
|
|
1305
|
+
takes: {
|
|
1306
|
+
claimId: ClaimId;
|
|
1307
|
+
movementId: MovementId;
|
|
1308
|
+
}[];
|
|
1309
|
+
adds: {
|
|
1310
|
+
supplyId: SupplyId;
|
|
1311
|
+
movementId: MovementId;
|
|
1312
|
+
}[];
|
|
1313
|
+
evidence: Evidence;
|
|
1314
|
+
sourceKey: string;
|
|
1315
|
+
actor: PrincipalRef;
|
|
1316
|
+
onBehalfOf?: PrincipalRef;
|
|
1317
|
+
createdAt: T;
|
|
1318
|
+
}
|
|
1319
|
+
/** A conversion with the movements and the supply it added. */
|
|
1320
|
+
interface TransformationResponse<T = string> {
|
|
1321
|
+
transformation: Transformation<T>;
|
|
1322
|
+
movements: Movement<T>[];
|
|
1323
|
+
supply: SupplyEntry<T>[];
|
|
1324
|
+
/** Set when the source key already named this request. */
|
|
1325
|
+
duplicate?: true;
|
|
1326
|
+
}
|
|
1327
|
+
interface TransferResponse<T = string> {
|
|
1328
|
+
transferId: TransferId;
|
|
1329
|
+
/** The movement out, then the movement in. */
|
|
1330
|
+
movements: [Movement<T>, Movement<T>];
|
|
1331
|
+
/** Set when the source key already named this request. */
|
|
1332
|
+
duplicate?: true;
|
|
1333
|
+
}
|
|
1334
|
+
interface CountResponse<T = string> {
|
|
1335
|
+
onHand: Quantity;
|
|
1336
|
+
version: number;
|
|
1337
|
+
movement?: Movement<T>;
|
|
1338
|
+
}
|
|
1339
|
+
interface AdjustmentResponse<T = string> {
|
|
1340
|
+
movement: Movement<T>;
|
|
1341
|
+
duplicate?: true;
|
|
1342
|
+
}
|
|
1343
|
+
type SupplyKind = 'output' | 'added' | 'expected';
|
|
1344
|
+
/** What arrived or is expected, and what remains of it. */
|
|
1345
|
+
interface SupplyEntry<T = string> {
|
|
1346
|
+
id: SupplyId;
|
|
1347
|
+
resourceId: ResourceId;
|
|
1348
|
+
/** The scope it was added to. */
|
|
1349
|
+
scope: Scope;
|
|
1350
|
+
kind: SupplyKind;
|
|
1351
|
+
quantity: Quantity;
|
|
1352
|
+
/**
|
|
1353
|
+
* What is free to take when pegging applies. Together with held, it is
|
|
1354
|
+
* what the entry still has. For expected supply it is what is still
|
|
1355
|
+
* due; for added supply that has not started, what will be on hand
|
|
1356
|
+
* when it does; and otherwise it is the quantity the entry was made
|
|
1357
|
+
* with.
|
|
1358
|
+
*/
|
|
1359
|
+
remaining: Quantity;
|
|
1360
|
+
/** What open holds have pegged here, or zero when pegging does not apply. */
|
|
1361
|
+
held: Quantity;
|
|
1362
|
+
/** The expected entry this added entry fulfils. */
|
|
1363
|
+
fulfils?: SupplyId;
|
|
1364
|
+
/** For expected supply, when it is due. For added supply, when it starts: set when it was added to start later than it landed. */
|
|
1365
|
+
validFrom?: T;
|
|
1366
|
+
/** When what it has left stops being on hand. */
|
|
1367
|
+
expiresAt?: T;
|
|
1368
|
+
batchId?: BatchId;
|
|
1369
|
+
/** The business's own labels for this entry; ResourceShark stores them and never reads meaning into them. */
|
|
1370
|
+
attributes?: Attributes;
|
|
1371
|
+
/** Lower numbers are drawn first; a missing value counts as 0. */
|
|
1372
|
+
drawOrder?: number;
|
|
1373
|
+
evidence: Evidence;
|
|
1374
|
+
sourceKey: string;
|
|
1375
|
+
actor: PrincipalRef;
|
|
1376
|
+
onBehalfOf?: PrincipalRef;
|
|
1377
|
+
status: 'expired' | 'exhausted' | 'active' | 'pending' | 'reversed';
|
|
1378
|
+
createdAt: T;
|
|
1379
|
+
}
|
|
1380
|
+
/** The request as a client writes it, before defaults apply. */
|
|
1381
|
+
type SupplyCreateInput = {
|
|
1382
|
+
resourceId: string;
|
|
1383
|
+
kind: 'added' | 'expected';
|
|
1384
|
+
quantity: number;
|
|
1385
|
+
evidence: {
|
|
1386
|
+
kind: string;
|
|
1387
|
+
ref: string;
|
|
1388
|
+
};
|
|
1389
|
+
sourceKey: string;
|
|
1390
|
+
scope?: {
|
|
1391
|
+
placeId?: string | undefined;
|
|
1392
|
+
condition?: string | undefined;
|
|
1393
|
+
holderRef?: string | undefined;
|
|
1394
|
+
instanceId?: string | undefined;
|
|
1395
|
+
} | undefined;
|
|
1396
|
+
validFrom?: string | undefined;
|
|
1397
|
+
expiresAt?: string | undefined;
|
|
1398
|
+
drawOrder?: number | undefined;
|
|
1399
|
+
batchId?: string | undefined;
|
|
1400
|
+
fulfils?: string | undefined;
|
|
1401
|
+
attributes?: Record<string, string> | undefined;
|
|
1402
|
+
batch?: {
|
|
1403
|
+
code: string;
|
|
1404
|
+
expiresAt?: string | undefined;
|
|
1405
|
+
attributes?: Record<string, string> | undefined;
|
|
1406
|
+
} | undefined;
|
|
1407
|
+
};
|
|
1408
|
+
/** What a supply write recorded, with its movement when there is one. */
|
|
1409
|
+
interface SupplyResponse<T = string> {
|
|
1410
|
+
supply: SupplyEntry<T>;
|
|
1411
|
+
/** The movement that recorded what arrived or is expected. */
|
|
1412
|
+
movement?: Movement<T>;
|
|
1413
|
+
/** Set when the `sourceKey` already named this request: nothing was added again. */
|
|
1414
|
+
duplicate?: true;
|
|
1415
|
+
}
|
|
1416
|
+
/** The filters and page size the supply list uses. */
|
|
1417
|
+
type SupplyQuery = {
|
|
1418
|
+
limit: number;
|
|
1419
|
+
resourceId?: string | undefined;
|
|
1420
|
+
holderRef?: string | undefined;
|
|
1421
|
+
batchId?: string | undefined;
|
|
1422
|
+
status?: 'expired' | 'exhausted' | 'active' | 'pending' | 'reversed' | undefined;
|
|
1423
|
+
after?: string | undefined;
|
|
1424
|
+
};
|
|
1425
|
+
/** One page of supply, with the cursor for the next page when there is one. */
|
|
1426
|
+
interface SupplyPage<T = string> {
|
|
1427
|
+
supply: SupplyEntry<T>[];
|
|
1428
|
+
next?: string;
|
|
1429
|
+
}
|
|
1430
|
+
/** The supply entry read by ID. */
|
|
1431
|
+
interface SupplyGetResponse<T = string> {
|
|
1432
|
+
supply: SupplyEntry<T>;
|
|
1433
|
+
}
|
|
1434
|
+
/** The request that takes back a quantity from a supply entry. */
|
|
1435
|
+
type SupplyReverse = {
|
|
1436
|
+
quantity: number;
|
|
1437
|
+
evidence: {
|
|
1438
|
+
kind: string;
|
|
1439
|
+
ref: string;
|
|
1440
|
+
};
|
|
1441
|
+
sourceKey: string;
|
|
1442
|
+
};
|
|
1443
|
+
/** What a supply reversal took back. */
|
|
1444
|
+
interface SupplyReverseResponse<T = string> {
|
|
1445
|
+
supply: SupplyEntry<T>;
|
|
1446
|
+
/** The `reversal` movement, absent when the entry had not started. */
|
|
1447
|
+
movement?: Movement<T>;
|
|
1448
|
+
/** What was taken back. */
|
|
1449
|
+
taken: Quantity;
|
|
1450
|
+
/** Set when the `sourceKey` already named this request: nothing was taken again. */
|
|
1451
|
+
duplicate?: true;
|
|
1452
|
+
}
|
|
1453
|
+
declare const HOSTED_BASE_URL = "https://api.agentpost.tools/v1/resources";
|
|
1454
|
+
interface ClientOptions {
|
|
1455
|
+
/** The API root. Defaults to {@link HOSTED_BASE_URL}. Set it to send requests through your own proxy, or to a stand-in during a test. */
|
|
1456
|
+
baseUrl?: string;
|
|
1457
|
+
/** A project's secret key on a server, or a user token for holder reads. */
|
|
1458
|
+
token?: string;
|
|
1459
|
+
fetch?: typeof fetch;
|
|
1460
|
+
headers?: Record<string, string>;
|
|
1461
|
+
}
|
|
1462
|
+
interface CallOptions {
|
|
1463
|
+
/** Overrides the client's token for this call. */
|
|
1464
|
+
token?: string;
|
|
1465
|
+
}
|
|
1466
|
+
interface WriteOptions extends CallOptions {
|
|
1467
|
+
/** The caller supplies the key. Retry the same write with the same key. */
|
|
1468
|
+
idempotencyKey: string;
|
|
1469
|
+
}
|
|
1470
|
+
interface VersionedOptions extends CallOptions {
|
|
1471
|
+
/** The record version the caller read. */
|
|
1472
|
+
ifMatch: number;
|
|
1473
|
+
idempotencyKey?: string;
|
|
1474
|
+
}
|
|
1475
|
+
declare class ResourcesharkApiError extends Error {
|
|
1476
|
+
readonly status: number;
|
|
1477
|
+
readonly code: ErrorCode | 'unknown' | (string & {});
|
|
1478
|
+
readonly errorClass?: ErrorClass;
|
|
1479
|
+
readonly details?: unknown;
|
|
1480
|
+
readonly docs?: string;
|
|
1481
|
+
constructor(status: number, code: ResourcesharkApiError['code'], message: string, details?: unknown, docs?: string, errorClass?: ErrorClass);
|
|
1482
|
+
}
|
|
1483
|
+
/** True when a response has the service's standard error body. */
|
|
1484
|
+
declare function isErrorBody(value: unknown): value is ErrorBody;
|
|
1485
|
+
/** Filters and pagination for a resource list, before server defaults apply. */
|
|
1486
|
+
type ResourcesQueryInput = Partial<ResourcesQuery>;
|
|
1487
|
+
interface ResourcesharkClient {
|
|
1488
|
+
config: {
|
|
1489
|
+
get(opts?: CallOptions): Promise<ConfigResponse>;
|
|
1490
|
+
put(body: ResourcesharkConfig, opts: VersionedOptions): Promise<ConfigResponse>;
|
|
1491
|
+
};
|
|
1492
|
+
resources: {
|
|
1493
|
+
create(body: ResourceCreate, opts?: CallOptions): Promise<ResourceResponse>;
|
|
1494
|
+
list(query?: ResourcesQueryInput): Promise<ResourcesPage>;
|
|
1495
|
+
get(id: ResourceId): Promise<ResourceResponse>;
|
|
1496
|
+
patch(id: ResourceId, body: ResourcePatch, opts: VersionedOptions): Promise<ResourceResponse>;
|
|
1497
|
+
archive(id: ResourceId, opts?: CallOptions): Promise<ResourceResponse>;
|
|
1498
|
+
};
|
|
1499
|
+
places: {
|
|
1500
|
+
create(body: PlaceCreate): Promise<PlaceResponse>;
|
|
1501
|
+
list(query?: Partial<PlacesQuery>): Promise<PlacesPage>;
|
|
1502
|
+
patch(id: PlaceId, body: PlacePatch): Promise<PlaceResponse>;
|
|
1503
|
+
};
|
|
1504
|
+
instances: {
|
|
1505
|
+
create(resourceId: ResourceId, body: InstanceCreate): Promise<InstanceResponse>;
|
|
1506
|
+
list(resourceId: ResourceId, query?: Partial<InstancesQuery>): Promise<InstancesPage>;
|
|
1507
|
+
patch(resourceId: ResourceId, iid: InstanceId, body: InstancePatch): Promise<InstanceResponse>;
|
|
1508
|
+
};
|
|
1509
|
+
freeInstances: {
|
|
1510
|
+
list(resourceId: ResourceId, query?: Partial<FreeInstancesQuery>): Promise<InstancesPage>;
|
|
1511
|
+
};
|
|
1512
|
+
supply: {
|
|
1513
|
+
create(body: SupplyCreateInput, opts: WriteOptions): Promise<SupplyResponse>;
|
|
1514
|
+
list(query?: Partial<SupplyQuery>): Promise<SupplyPage>;
|
|
1515
|
+
get(id: SupplyId): Promise<SupplyGetResponse>;
|
|
1516
|
+
reverse(id: SupplyId, body: SupplyReverse, opts: WriteOptions): Promise<SupplyReverseResponse>;
|
|
1517
|
+
};
|
|
1518
|
+
batches: {
|
|
1519
|
+
create(body: BatchCreate): Promise<BatchResponse>;
|
|
1520
|
+
list(query?: Partial<BatchesQuery>): Promise<BatchesPage>;
|
|
1521
|
+
get(id: BatchId): Promise<BatchResponse>;
|
|
1522
|
+
patch(id: BatchId, body: BatchPatch, opts: VersionedOptions): Promise<BatchResponse>;
|
|
1523
|
+
};
|
|
1524
|
+
claims: {
|
|
1525
|
+
consume(body: ConsumeRequest, opts: WriteOptions): Promise<ConsumeResponse>;
|
|
1526
|
+
settle(body: SettleRequest, opts: WriteOptions): Promise<SettleResponse>;
|
|
1527
|
+
list(query?: Partial<ClaimsQuery>): Promise<ClaimsPage>;
|
|
1528
|
+
get(id: ClaimId): Promise<ClaimResponse>;
|
|
1529
|
+
};
|
|
1530
|
+
holds: {
|
|
1531
|
+
create(body: HoldCreate, opts: WriteOptions): Promise<HoldResponse>;
|
|
1532
|
+
list(query?: HoldsQueryInput): Promise<HoldsPage>;
|
|
1533
|
+
get(id: HoldId): Promise<HoldResponse>;
|
|
1534
|
+
extend(id: HoldId, body: HoldExtend, opts: WriteOptions): Promise<HoldResponse>;
|
|
1535
|
+
commit(id: HoldId, body: HoldCommit, opts: WriteOptions): Promise<HoldCommitResponse>;
|
|
1536
|
+
release(id: HoldId, opts: WriteOptions): Promise<HoldResponse>;
|
|
1537
|
+
cancel(id: HoldId, body: HoldCancel, opts: WriteOptions): Promise<HoldCancelResponse>;
|
|
1538
|
+
reschedule(body: HoldReschedule, opts: WriteOptions): Promise<HoldRescheduleResponse>;
|
|
1539
|
+
};
|
|
1540
|
+
availability: {
|
|
1541
|
+
query(body: AvailabilityRequest): Promise<AvailabilityResponse>;
|
|
1542
|
+
};
|
|
1543
|
+
balances: {
|
|
1544
|
+
get(resourceId: ResourceId, query?: BalanceQuery): Promise<BalanceResponse>;
|
|
1545
|
+
};
|
|
1546
|
+
holderBalances: {
|
|
1547
|
+
list(holderRef: Ref, query?: Partial<HolderBalancesQuery>): Promise<HolderBalancesPage>;
|
|
1548
|
+
get(holderRef: Ref, resourceId: ResourceId, query?: Pick<HolderBalancesQuery, 'placeId' | 'condition'>): Promise<HolderBalanceResponse>;
|
|
1549
|
+
};
|
|
1550
|
+
schedules: {
|
|
1551
|
+
put(resourceId: ResourceId, body: SchedulePut, opts?: {
|
|
1552
|
+
ifMatch?: number;
|
|
1553
|
+
}): Promise<ScheduleSaveResponse>;
|
|
1554
|
+
get(resourceId: ResourceId): Promise<ScheduleResponse>;
|
|
1555
|
+
};
|
|
1556
|
+
exceptions: {
|
|
1557
|
+
create(resourceId: ResourceId, body: ExceptionCreate, opts: WriteOptions): Promise<ExceptionCreateResponse>;
|
|
1558
|
+
list(resourceId: ResourceId, query?: ExceptionsQuery): Promise<ExceptionsList>;
|
|
1559
|
+
patch(resourceId: ResourceId, eid: ExceptionId, body: ExceptionPatch, opts: VersionedOptions): Promise<ExceptionResponse>;
|
|
1560
|
+
delete(resourceId: ResourceId, eid: ExceptionId, opts?: CallOptions): Promise<ExceptionDeleteResponse>;
|
|
1561
|
+
};
|
|
1562
|
+
slots: {
|
|
1563
|
+
list(query: SlotsQuery): Promise<SlotsResponse>;
|
|
1564
|
+
};
|
|
1565
|
+
transfers: {
|
|
1566
|
+
create(body: TransferCreate, opts: WriteOptions): Promise<TransferResponse>;
|
|
1567
|
+
};
|
|
1568
|
+
counts: {
|
|
1569
|
+
create(body: CountCreate, opts: WriteOptions): Promise<CountResponse>;
|
|
1570
|
+
};
|
|
1571
|
+
adjustments: {
|
|
1572
|
+
create(body: AdjustmentCreate, opts: WriteOptions): Promise<AdjustmentResponse>;
|
|
1573
|
+
};
|
|
1574
|
+
transformations: {
|
|
1575
|
+
create(body: TransformationCreate, opts: WriteOptions): Promise<TransformationResponse>;
|
|
1576
|
+
get(id: TransformationId): Promise<TransformationResponse>;
|
|
1577
|
+
};
|
|
1578
|
+
movements: {
|
|
1579
|
+
list(query?: Partial<MovementsQuery>): Promise<MovementsPage>;
|
|
1580
|
+
get(id: MovementId): Promise<MovementResponse>;
|
|
1581
|
+
};
|
|
1582
|
+
reports: {
|
|
1583
|
+
totals(query: TotalsQuery & {
|
|
1584
|
+
attributes?: Record<string, string>;
|
|
1585
|
+
}): Promise<TotalsReport>;
|
|
1586
|
+
};
|
|
1587
|
+
events: {
|
|
1588
|
+
read(query?: EventsQuery): Promise<EventsPage>;
|
|
1589
|
+
};
|
|
1590
|
+
}
|
|
1591
|
+
declare function createClient(options?: ClientOptions): ResourcesharkClient;
|
|
1592
|
+
export { ExhaustedUntilSupplyDetails as $, SchedulePut as $t, ClaimResponse as A, MovementReason as At, ErrorClass as B, PlacesPage as Bt, BatchResponse as C, TransformationCreate as Cn, InstancePatch as Ct, Claim as D, InsufficientSupplyDetails as Dt, ChangeEvent as E, Unit as En, InstancesQuery as Et, ConsumeResponse as F, Place as Ft, ExceptionCreate as G, ResourceCreate as Gt, EventsPage as H, Quantity as Ht, CountCreate as I, PlaceCreate as It, ExceptionId as J, ResourceResponse as Jt, ExceptionCreateResponse as K, ResourceId as Kt, CountResponse as L, PlaceId as Lt, ClaimsQuery as M, MovementSums as Mt, ConfigResponse as N, MovementsPage as Nt, ClaimId as O, Movement as Ot, ConsumeRequest as P, MovementsQuery as Pt, ExceptionsQuery as Q, RetainedHold as Qt, Duration as R, PlacePatch as Rt, BatchPatch as S, TransferResponse as Sn, InstanceId as St, BatchesQuery as T, TransformationResponse as Tn, InstancesPage as Tt, EventsQuery as U, Ref as Ut, ErrorCode as V, PlacesQuery as Vt, Evidence as W, Resource as Wt, ExceptionResponse as X, ResourcesQuery as Xt, ExceptionPatch as Y, ResourcesPage as Yt, ExceptionsList as Z, ResourcesharkConfig as Zt, BalanceQuery as _, SupplyReverseResponse as _n, HolderBalancesQuery as _t, ResourcesharkApiError as a, ShortLine as an, HoldCommit as at, BatchCreate as b, TotalsReport as bn, Instance as bt, WriteOptions as c, SlotsResponse as cn, HoldExpiredDetails as ct, AdjustmentCreate as d, SupplyGetResponse as dn, HoldReschedule as dt, ScheduleResponse as en, FiniteSpan as et, AdjustmentResponse as f, SupplyId as fn, HoldRescheduleResponse as ft, AvailabilityResponse as g, SupplyReverse as gn, HolderBalancesPage as gt, AvailabilityRequest as h, SupplyResponse as hn, HolderBalanceResponse as ht, ResourcesQueryInput as i, SettleResponse as in, HoldCancelResponse as it, ClaimsPage as j, MovementResponse as jt, ClaimLine as k, MovementId as kt, createClient as l, SupplyCreateInput as ln, HoldExtend as lt, Attributes as m, SupplyQuery as mn, HoldResponse as mt, ClientOptions as n, Scope as nn, Hold as nt, ResourcesharkClient as o, Slot as on, HoldCommitResponse as ot, AssignmentInfeasibleDetails as p, SupplyPage as pn, HoldResolvedDetails as pt, ExceptionDeleteResponse as q, ResourcePatch as qt, HOSTED_BASE_URL as r, SettleRequest as rn, HoldCancel as rt, VersionedOptions as s, SlotsQuery as sn, HoldCreate as st, CallOptions as t, ScheduleSaveResponse as tn, FreeInstancesQuery as tt, isErrorBody as u, SupplyEntry as un, HoldId as ut, BalanceResponse as v, TotalsBalance as vn, HoldsPage as vt, BatchesPage as w, TransformationId as wn, InstanceResponse as wt, BatchId as x, TransferCreate as xn, InstanceCreate as xt, Batch as y, TotalsQuery as yn, HoldsQueryInput as yt, ErrorBody as z, PlaceResponse as zt };
|