@dork-labs/cloud-api 0.83.0 → 0.87.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 +201 -22
- package/dist/billing.d.ts +225 -12
- package/dist/billing.d.ts.map +1 -1
- package/dist/billing.js +159 -36
- package/dist/billing.js.map +1 -1
- package/dist/display.d.ts +172 -0
- package/dist/display.d.ts.map +1 -0
- package/dist/display.js +431 -0
- package/dist/display.js.map +1 -0
- package/dist/primitives.d.ts +63 -0
- package/dist/primitives.d.ts.map +1 -1
- package/dist/primitives.js +78 -1
- package/dist/primitives.js.map +1 -1
- package/dist/problem.d.ts +22 -0
- package/dist/problem.d.ts.map +1 -1
- package/dist/problem.js +26 -2
- package/dist/problem.js.map +1 -1
- package/dist/remote.d.ts +130 -1
- package/dist/remote.d.ts.map +1 -1
- package/dist/remote.js +136 -6
- package/dist/remote.js.map +1 -1
- package/dist/routes.d.ts +12 -1
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +12 -1
- package/dist/routes.js.map +1 -1
- package/dist/seats.d.ts +43 -2
- package/dist/seats.d.ts.map +1 -1
- package/dist/seats.js +29 -3
- package/dist/seats.js.map +1 -1
- package/dist/zzprobeintl.d.ts +2 -0
- package/dist/zzprobeintl.d.ts.map +1 -0
- package/dist/zzprobeintl.js +2 -0
- package/dist/zzprobeintl.js.map +1 -0
- package/fixtures/v1/billing/balance-denominated.json +20 -0
- package/fixtures/v1/billing/entitlements-denominated.json +38 -0
- package/fixtures/v1/billing/nudge-denominated.json +13 -0
- package/fixtures/v1/billing/offers-empty.json +3 -0
- package/fixtures/v1/billing/offers.json +48 -0
- package/fixtures/v1/billing/price-list-cache-rates.json +19 -0
- package/fixtures/v1/billing/statement-itemised.json +35 -0
- package/fixtures/v1/billing/usage-denominated.json +25 -0
- package/fixtures/v1/index.json +20 -0
- package/fixtures/v1/problem/malformed-identifier.json +7 -0
- package/fixtures/v1/problem/malformed-request.json +7 -0
- package/fixtures/v1/remote/credential-with-hosts.json +8 -0
- package/fixtures/v1/remote/designation-current.json +5 -0
- package/fixtures/v1/remote/designation-none.json +5 -0
- package/fixtures/v1/remote/events-batch-spans.json +15 -0
- package/fixtures/v1/remote/events-batch.json +5 -0
- package/fixtures/v1/remote/status-open-with-instance.json +10 -0
- package/fixtures/v1/remote/usage-fresh.json +17 -0
- package/fixtures/v1/remote/usage.json +39 -0
- package/fixtures/v1/seats/agent-approved-claim.json +8 -0
- package/fixtures/v1/seats/agent-pending-claim.json +9 -0
- package/package.json +7 -3
package/dist/billing.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { IdSchema,
|
|
2
|
+
import { CreditMicroSchema, DenominationSchema, IdSchema, MoneyMicroSchema, PositiveMoneyMicroSchema, TimestampSchema, tolerantEnum, } from './primitives.js';
|
|
3
|
+
/**
|
|
4
|
+
* The optional `denomination` every amount-bearing response carries.
|
|
5
|
+
*
|
|
6
|
+
* Optional so a response from an older service still parses. A client that
|
|
7
|
+
* receives none must not guess a unit.
|
|
8
|
+
*/
|
|
9
|
+
const denominationField = DenominationSchema.optional().describe('The unit these amounts are in. Absent from an older service; a client that receives none must not guess one.');
|
|
3
10
|
/**
|
|
4
11
|
* How remote access works for the caller.
|
|
5
12
|
*
|
|
@@ -69,7 +76,7 @@ export const EntitlementLimitsSchema = z
|
|
|
69
76
|
.object({
|
|
70
77
|
personSeatsIncluded: z.number().int().nonnegative(),
|
|
71
78
|
agentSeatsIncluded: z.number().int().nonnegative(),
|
|
72
|
-
includedCreditsMicro:
|
|
79
|
+
includedCreditsMicro: CreditMicroSchema,
|
|
73
80
|
cloudHours: z.number().nonnegative(),
|
|
74
81
|
storageGb: z.number().nonnegative(),
|
|
75
82
|
remoteAccess: RemoteAccessCapabilitySchema,
|
|
@@ -117,6 +124,7 @@ export const EntitlementsSchema = z
|
|
|
117
124
|
canCreateSeat: z.boolean(),
|
|
118
125
|
canInviteMember: z.boolean(),
|
|
119
126
|
staleAt: TimestampSchema.describe('When this snapshot should be refetched.'),
|
|
127
|
+
denomination: denominationField,
|
|
120
128
|
})
|
|
121
129
|
.describe('What the caller is allowed to do. A caller with no subscription gets the free entitlement, never a 404.');
|
|
122
130
|
/**
|
|
@@ -130,12 +138,12 @@ export const EntitlementsSchema = z
|
|
|
130
138
|
export const BalanceSchema = z
|
|
131
139
|
.object({
|
|
132
140
|
allowance: z.object({
|
|
133
|
-
grantedMicro:
|
|
134
|
-
remainingMicro:
|
|
141
|
+
grantedMicro: CreditMicroSchema,
|
|
142
|
+
remainingMicro: CreditMicroSchema,
|
|
135
143
|
resetsAt: TimestampSchema,
|
|
136
144
|
}),
|
|
137
145
|
purchased: z.object({
|
|
138
|
-
remainingMicro:
|
|
146
|
+
remainingMicro: CreditMicroSchema,
|
|
139
147
|
holds: z
|
|
140
148
|
.number()
|
|
141
149
|
.int()
|
|
@@ -143,15 +151,16 @@ export const BalanceSchema = z
|
|
|
143
151
|
.optional()
|
|
144
152
|
.describe('How many first-purchase holds are in force. Absent means the server did not say; zero means none.'),
|
|
145
153
|
}),
|
|
146
|
-
pendingMicro:
|
|
147
|
-
heldMicro:
|
|
148
|
-
owedMicro:
|
|
154
|
+
pendingMicro: CreditMicroSchema.optional().describe('Credit the caller has paid for that is not spendable yet, because a hold is still in force. Absent means the server did not say.'),
|
|
155
|
+
heldMicro: CreditMicroSchema.describe('Reserved against turns currently running.'),
|
|
156
|
+
owedMicro: CreditMicroSchema.describe('Debt from a turn that overran its reservation. May be "0"; when it is not, show it.'),
|
|
149
157
|
autoReload: z.object({
|
|
150
158
|
enabled: z.boolean(),
|
|
151
|
-
ceilingMicro:
|
|
159
|
+
ceilingMicro: MoneyMicroSchema.nullable(),
|
|
152
160
|
}),
|
|
161
|
+
denomination: denominationField,
|
|
153
162
|
})
|
|
154
|
-
.describe('The caller`s credit position. Every amount is an exact integer of micro-units carried as a string.');
|
|
163
|
+
.describe('The caller`s credit position. Every amount is an exact integer of micro-units carried as a string, counted as credits except the auto-reload ceiling, which is money.');
|
|
155
164
|
/**
|
|
156
165
|
* Where a usage line`s price came from.
|
|
157
166
|
*
|
|
@@ -207,8 +216,8 @@ export const UsageRowSchema = z
|
|
|
207
216
|
.nonnegative()
|
|
208
217
|
.describe('How much was used, in the unit the row is measured in.'),
|
|
209
218
|
unit: z.string().describe('What `units` counts, as a server-supplied string.'),
|
|
210
|
-
listPriceMicro:
|
|
211
|
-
dorkosPriceMicro:
|
|
219
|
+
listPriceMicro: MoneyMicroSchema.describe('The upstream list price for this row.'),
|
|
220
|
+
dorkosPriceMicro: CreditMicroSchema.describe('What DorkOS charged for this row.'),
|
|
212
221
|
costBasis: CostBasisSchema,
|
|
213
222
|
})
|
|
214
223
|
.describe('One row of the caller`s own usage, projected. No supplier and no price-list version appear here.');
|
|
@@ -221,9 +230,10 @@ export const UsageResponseSchema = z
|
|
|
221
230
|
state: UsageStateSchema,
|
|
222
231
|
rows: z.array(UsageRowSchema),
|
|
223
232
|
totals: z.object({
|
|
224
|
-
listPriceMicro:
|
|
225
|
-
dorkosPriceMicro:
|
|
233
|
+
listPriceMicro: MoneyMicroSchema,
|
|
234
|
+
dorkosPriceMicro: CreditMicroSchema,
|
|
226
235
|
}),
|
|
236
|
+
denomination: denominationField,
|
|
227
237
|
})
|
|
228
238
|
.describe('The caller`s own usage for a window, grouped as asked.');
|
|
229
239
|
/** One entry of the published price list. */
|
|
@@ -232,8 +242,10 @@ export const PriceListEntrySchema = z
|
|
|
232
242
|
modelId: IdSchema.describe('An opaque model identifier. This list is the only place a price belongs.'),
|
|
233
243
|
displayName: z.string(),
|
|
234
244
|
unit: z.string().describe('What the prices below are per, as a server-supplied string.'),
|
|
235
|
-
inputMicro:
|
|
236
|
-
outputMicro:
|
|
245
|
+
inputMicro: CreditMicroSchema,
|
|
246
|
+
outputMicro: CreditMicroSchema,
|
|
247
|
+
cacheReadMicro: CreditMicroSchema.optional().describe('The rate for reading prompt-cached input, in the entry`s existing unit. Absent means the service did not say.'),
|
|
248
|
+
cacheWriteMicro: CreditMicroSchema.optional().describe('The rate for writing input to the prompt cache, in the entry`s existing unit. Absent means the service did not say.'),
|
|
237
249
|
})
|
|
238
250
|
.describe('One entry of the published price list.');
|
|
239
251
|
/**
|
|
@@ -249,8 +261,9 @@ export const PriceListResponseSchema = z
|
|
|
249
261
|
version: z.string().describe('An opaque version string for this list.'),
|
|
250
262
|
effectiveFrom: TimestampSchema,
|
|
251
263
|
entries: z.array(PriceListEntrySchema),
|
|
264
|
+
denomination: denominationField,
|
|
252
265
|
})
|
|
253
|
-
.describe('The published per-model price list.
|
|
266
|
+
.describe('The published per-model price list.');
|
|
254
267
|
/**
|
|
255
268
|
* `GET /v1/nudge` — one already-computed comparison, delivered reduced.
|
|
256
269
|
*
|
|
@@ -261,25 +274,84 @@ export const PriceListResponseSchema = z
|
|
|
261
274
|
*/
|
|
262
275
|
export const NudgeSchema = z
|
|
263
276
|
.object({
|
|
264
|
-
trailing30Micro:
|
|
277
|
+
trailing30Micro: CreditMicroSchema,
|
|
265
278
|
suggestedPlanId: IdSchema.describe('An opaque identifier. Never switch on this value.'),
|
|
266
279
|
suggestedPlanDisplayName: z.string(),
|
|
267
|
-
suggestedPlanPriceMicro:
|
|
268
|
-
savingMicro:
|
|
280
|
+
suggestedPlanPriceMicro: MoneyMicroSchema,
|
|
281
|
+
savingMicro: MoneyMicroSchema.describe('The subtraction the server already did.'),
|
|
269
282
|
computedAt: TimestampSchema,
|
|
270
283
|
dismissible: z.literal(true),
|
|
284
|
+
denomination: denominationField,
|
|
271
285
|
})
|
|
272
286
|
.describe('One already-computed comparison. 404 from this route means "no nudge", not an error.');
|
|
287
|
+
/**
|
|
288
|
+
* How often an offer recurs.
|
|
289
|
+
*
|
|
290
|
+
* Mechanism, not catalog: it says how a charge repeats, not what is on sale.
|
|
291
|
+
*/
|
|
292
|
+
export const OfferIntervalSchema = z
|
|
293
|
+
.enum(['month', 'year'])
|
|
294
|
+
.describe('How often an offer recurs: every month, or every year.');
|
|
295
|
+
/**
|
|
296
|
+
* One thing the service will sell the caller, as `GET /v1/offers` lists it.
|
|
297
|
+
*
|
|
298
|
+
* It is the only place a client is handed a `skuId`, which is the string
|
|
299
|
+
* `POST /v1/checkout` takes back. `skuId` and `planId` are different identifier
|
|
300
|
+
* spaces and neither can stand in for the other: one subscription has one
|
|
301
|
+
* `planId` and one `skuId` per interval. `planId` is the same opaque token
|
|
302
|
+
* `GET /v1/entitlements` publishes, so a page compares the two to mark what the
|
|
303
|
+
* caller is on; this shape deliberately carries no "current" flag of its own.
|
|
304
|
+
*
|
|
305
|
+
* It carries no "recommended" flag and no badge. Render the offers in the order
|
|
306
|
+
* the service sends them and do not re-sort them; the order carries no meaning
|
|
307
|
+
* beyond that.
|
|
308
|
+
*
|
|
309
|
+
* `interval` is tolerant: an interval added in a later release reads as
|
|
310
|
+
* `unrecognised`, so one new offer cannot fail the whole list. Generate the JSON
|
|
311
|
+
* Schema with `{ io: 'input' }`. `limits` is the published entitlement-limits
|
|
312
|
+
* shape itself, so its own description speaks of an entitlement.
|
|
313
|
+
*/
|
|
314
|
+
export const OfferSchema = z
|
|
315
|
+
.object({
|
|
316
|
+
skuId: IdSchema.describe('The opaque identifier `POST /v1/checkout` takes back. Never constructed, parsed or enumerated by a client.'),
|
|
317
|
+
planId: IdSchema.describe('The opaque identifier `GET /v1/entitlements` publishes for the same subscription. Not interchangeable with `skuId`. Never switch on this value.'),
|
|
318
|
+
displayName: z.string().describe('The server-supplied string to show a person.'),
|
|
319
|
+
interval: tolerantEnum(OfferIntervalSchema).describe('How often the offer recurs. An interval this release does not know reads as unrecognised.'),
|
|
320
|
+
amountMicro: MoneyMicroSchema.describe('The price for one interval, in micro-units of money. Rendered, never computed with.'),
|
|
321
|
+
// The published limits shape itself, by reference: one shape, one place to
|
|
322
|
+
// extend. A `.describe()` here would make a copy.
|
|
323
|
+
limits: EntitlementLimitsSchema,
|
|
324
|
+
})
|
|
325
|
+
.describe('One thing the service will sell the caller.');
|
|
326
|
+
/**
|
|
327
|
+
* `GET /v1/offers` — everything the service will sell the caller right now.
|
|
328
|
+
*
|
|
329
|
+
* A bearer token or the person's own browser session. An account with nothing
|
|
330
|
+
* on sale gets 200 and an empty list, never a 404: nothing on sale is a normal
|
|
331
|
+
* state, and a client that met a 404 would report an outage.
|
|
332
|
+
*/
|
|
333
|
+
export const OffersResponseSchema = z
|
|
334
|
+
.object({
|
|
335
|
+
offers: z.array(OfferSchema),
|
|
336
|
+
denomination: denominationField,
|
|
337
|
+
})
|
|
338
|
+
.describe('Everything the service will sell the caller right now. An empty list is a normal answer, never a 404.');
|
|
273
339
|
/**
|
|
274
340
|
* A request for a hosted page.
|
|
275
341
|
*
|
|
276
|
-
* `skuId` is an identifier the client received from the server
|
|
277
|
-
*
|
|
278
|
-
*
|
|
342
|
+
* `skuId` is an identifier the client received from the server, from
|
|
343
|
+
* `GET /v1/offers` ({@link OffersResponseSchema}). A client never constructs one
|
|
344
|
+
* and never enumerates the set. The amount and its rendering belong to the
|
|
345
|
+
* hosted page, not to this contract.
|
|
346
|
+
*
|
|
347
|
+
* `POST /v1/checkout` and `POST /v1/portal` accept either credential: a bearer
|
|
348
|
+
* token, or the person's own browser session. Their request and response shapes
|
|
349
|
+
* are the same either way. A request authenticated by a browser session must
|
|
350
|
+
* come from an origin the service trusts, or it is refused with `forbidden`.
|
|
279
351
|
*/
|
|
280
352
|
export const HostedPageRequestSchema = z
|
|
281
353
|
.object({
|
|
282
|
-
skuId: IdSchema.optional().describe('An opaque identifier the server supplied earlier
|
|
354
|
+
skuId: IdSchema.optional().describe('An opaque identifier the server supplied earlier, from `GET /v1/offers`. Clients never construct or enumerate one.'),
|
|
283
355
|
returnUrl: z
|
|
284
356
|
.string()
|
|
285
357
|
.url()
|
|
@@ -302,14 +374,48 @@ export const StatementQuerySchema = z
|
|
|
302
374
|
period: z.string().min(1).describe('The billing period to fetch, as the server labels it.'),
|
|
303
375
|
})
|
|
304
376
|
.describe('Which billing period to fetch a statement for.');
|
|
305
|
-
/**
|
|
377
|
+
/**
|
|
378
|
+
* `GET /v1/statement` — the caller`s own statement for one period: a download
|
|
379
|
+
* link, and optionally its lines and totals.
|
|
380
|
+
*
|
|
381
|
+
* `lines` and `totals` are the same projection `GET /v1/usage` publishes, one
|
|
382
|
+
* line per model for the statement's period. They cover inference usage only:
|
|
383
|
+
* any other charge in the period appears in the downloadable statement, not
|
|
384
|
+
* here, so `totals` is not the whole bill when there are other charges.
|
|
385
|
+
*
|
|
386
|
+
* `from` and `to` are the window the period covers. A period is labelled by a
|
|
387
|
+
* month, but it need not be a calendar month, so a client never derives the
|
|
388
|
+
* window from the label.
|
|
389
|
+
*
|
|
390
|
+
* All four are optional, and a service sends `lines` and `totals` together or
|
|
391
|
+
* not at all. A service that predates them answers with the link alone; a client
|
|
392
|
+
* that meets no `lines` but has `from` and `to` can read the same projection
|
|
393
|
+
* from `GET /v1/usage` with `groupBy=model` for that window.
|
|
394
|
+
*
|
|
395
|
+
* `totals` is the exact sum of the lines. Render it from the exact figures, never
|
|
396
|
+
* by adding rounded lines.
|
|
397
|
+
*/
|
|
306
398
|
export const StatementResponseSchema = z
|
|
307
399
|
.object({
|
|
308
400
|
period: z.string(),
|
|
309
401
|
downloadUrl: z.string().url(),
|
|
310
402
|
expiresAt: TimestampSchema.describe('When the download link stops working.'),
|
|
403
|
+
from: TimestampSchema.optional().describe('The start of the window this period covers. Absent from an older service.'),
|
|
404
|
+
to: TimestampSchema.optional().describe('The end of the window this period covers. Absent from an older service.'),
|
|
405
|
+
lines: z
|
|
406
|
+
.array(UsageRowSchema)
|
|
407
|
+
.optional()
|
|
408
|
+
.describe('The statement`s inference usage, one line per model, in the shape `GET /v1/usage` publishes. Other charges are only in the download. Sent together with `totals`, or neither. Absent from an older service.'),
|
|
409
|
+
totals: z
|
|
410
|
+
.object({
|
|
411
|
+
listPriceMicro: MoneyMicroSchema.describe('The upstream list price across every line.'),
|
|
412
|
+
dorkosPriceMicro: CreditMicroSchema.describe('What DorkOS charged across every line.'),
|
|
413
|
+
})
|
|
414
|
+
.optional()
|
|
415
|
+
.describe('The exact totals of the lines, which is inference usage only. Sent together with `lines`, or neither. Absent from an older service.'),
|
|
416
|
+
denomination: denominationField,
|
|
311
417
|
})
|
|
312
|
-
.describe('
|
|
418
|
+
.describe('The caller`s own statement for one period: a short-lived download link, and optionally its lines and totals.');
|
|
313
419
|
/**
|
|
314
420
|
* `POST /v1/topup` — buy credit, answered with {@link HostedPageResponseSchema}.
|
|
315
421
|
*
|
|
@@ -332,7 +438,7 @@ export const StatementResponseSchema = z
|
|
|
332
438
|
*/
|
|
333
439
|
export const TopupRequestSchema = z
|
|
334
440
|
.object({
|
|
335
|
-
amountMicro:
|
|
441
|
+
amountMicro: PositiveMoneyMicroSchema.describe('How much to pay for credit, in micro-units of money.'),
|
|
336
442
|
returnUrl: z
|
|
337
443
|
.string()
|
|
338
444
|
.url()
|
|
@@ -341,25 +447,42 @@ export const TopupRequestSchema = z
|
|
|
341
447
|
})
|
|
342
448
|
.describe('A request to buy credit. Carries an amount and nothing about what an amount is worth.');
|
|
343
449
|
/**
|
|
344
|
-
*
|
|
450
|
+
* Why the two refund shapes below are withdrawn, and why they are still here.
|
|
451
|
+
*
|
|
452
|
+
* DorkOS Cloud does not offer refunds through this API. No release of the
|
|
453
|
+
* service ever served `POST /v1/refunds`; it answers `not_found`.
|
|
454
|
+
*
|
|
455
|
+
* The shapes stay exported because this package is additive within `/v1`:
|
|
456
|
+
* deleting an export would break the build of anyone who imported it from an
|
|
457
|
+
* earlier release, and that is a `/v2` change. They are marked deprecated in the
|
|
458
|
+
* types and in the JSON Schema, and they go when `/v2` does.
|
|
459
|
+
*/
|
|
460
|
+
const REFUNDS_WITHDRAWN = 'Withdrawn: DorkOS Cloud does not offer refunds through this API, and no release of the service answers this route. Kept only so imports from an earlier release keep compiling.';
|
|
461
|
+
/**
|
|
462
|
+
* `POST /v1/refunds` — withdrawn. A request no release of the service accepts.
|
|
345
463
|
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
* published here.
|
|
464
|
+
* @deprecated DorkOS Cloud does not offer refunds through this API, and the
|
|
465
|
+
* route answers `not_found`. Kept only so an import from an earlier release
|
|
466
|
+
* still compiles; it is removed in `/v2`.
|
|
350
467
|
*/
|
|
351
468
|
export const RefundRequestSchema = z
|
|
352
469
|
.object({
|
|
353
470
|
chargeId: IdSchema.describe('The charge to refund, as an opaque identifier the server issued.'),
|
|
354
471
|
})
|
|
355
|
-
.
|
|
356
|
-
/**
|
|
472
|
+
.meta({ description: REFUNDS_WITHDRAWN, deprecated: true });
|
|
473
|
+
/**
|
|
474
|
+
* `POST /v1/refunds` — withdrawn. An answer no release of the service sends.
|
|
475
|
+
*
|
|
476
|
+
* @deprecated DorkOS Cloud does not offer refunds through this API, and the
|
|
477
|
+
* route answers `not_found`. Kept only so an import from an earlier release
|
|
478
|
+
* still compiles; it is removed in `/v2`.
|
|
479
|
+
*/
|
|
357
480
|
export const RefundResponseSchema = z
|
|
358
481
|
.object({
|
|
359
482
|
refundId: IdSchema,
|
|
360
483
|
chargeId: IdSchema,
|
|
361
|
-
refundedMicro:
|
|
484
|
+
refundedMicro: MoneyMicroSchema.describe('How much came back, in micro-units.'),
|
|
362
485
|
refundedAt: TimestampSchema,
|
|
363
486
|
})
|
|
364
|
-
.
|
|
487
|
+
.meta({ description: REFUNDS_WITHDRAWN, deprecated: true });
|
|
365
488
|
//# sourceMappingURL=billing.js.map
|
package/dist/billing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../src/billing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../src/billing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC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;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC;KAChC,MAAM,CAAC;IACN,WAAW,EAAE,wBAAwB,CAAC,QAAQ,CAC5C,sDAAsD,CACvD;IACD,SAAS,EAAE,CAAC;SACT,MAAM,EAAE;SACR,GAAG,EAAE;SACL,QAAQ,EAAE;SACV,QAAQ,CAAC,wDAAwD,CAAC;CACtE,CAAC;KACD,QAAQ,CACP,uFAAuF,CACxF,CAAC;AAKJ;;;;;;;;;;GAUG;AACH,MAAM,iBAAiB,GACrB,iLAAiL,CAAC;AAEpL;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC;KACjC,MAAM,CAAC;IACN,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,kEAAkE,CAAC;CAChG,CAAC;KACD,IAAI,CAAC,EAAE,WAAW,EAAE,iBAAiB,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;AAS9D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC;KAClC,MAAM,CAAC;IACN,QAAQ,EAAE,QAAQ;IAClB,QAAQ,EAAE,QAAQ;IAClB,aAAa,EAAE,gBAAgB,CAAC,QAAQ,CAAC,qCAAqC,CAAC;IAC/E,UAAU,EAAE,eAAe;CAC5B,CAAC;KACD,IAAI,CAAC,EAAE,WAAW,EAAE,iBAAiB,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@dork-labs/cloud-api/display` — one way to render a Cloud amount for a person.
|
|
3
|
+
*
|
|
4
|
+
* Every amount on the wire is an exact integer count of micro-units carried as
|
|
5
|
+
* a string, and a response names its unit in `denomination`: the currency the
|
|
6
|
+
* micro-units are millionths of, and how many micro-units one credit is. This
|
|
7
|
+
* module turns an amount and that denomination into text, by the kind of
|
|
8
|
+
* figure it is:
|
|
9
|
+
*
|
|
10
|
+
* - a **position** (what someone has or may still spend) rounds down to whole
|
|
11
|
+
* credits, so no page shows credit that cannot be spent;
|
|
12
|
+
* - a **charge** (what someone spent, was charged or is held for) rounds half
|
|
13
|
+
* away from zero to whole credits, and a non-zero amount under half a credit
|
|
14
|
+
* reads as less than one credit;
|
|
15
|
+
* - a **rate** (a price per unit of something) is never rounded;
|
|
16
|
+
* - **money** rounds to the currency's minor unit, half away from zero, and a
|
|
17
|
+
* non-zero amount that rounds to zero reads as less than the smallest unit;
|
|
18
|
+
* - a **cap** (a money limit) rounds down, so a limit never reads higher than
|
|
19
|
+
* the one enforced.
|
|
20
|
+
*
|
|
21
|
+
* Rules this module keeps, so two clients can never disagree:
|
|
22
|
+
*
|
|
23
|
+
* - **No scale lives here.** The credit scale comes from the served
|
|
24
|
+
* denomination on every call. A missing or malformed denomination, or a
|
|
25
|
+
* malformed amount, returns `null`: never a guess.
|
|
26
|
+
* - **No amount becomes a JavaScript number.** Every digit is produced with
|
|
27
|
+
* `BigInt`. `Intl.NumberFormat` is asked only for a currency's symbol, where
|
|
28
|
+
* the symbol sits, and how many minor-unit digits the currency has. No
|
|
29
|
+
* amount is ever handed to `Intl`.
|
|
30
|
+
* - **No dependencies**, not even the contract's own schemas, so a renderer
|
|
31
|
+
* can import this without Zod.
|
|
32
|
+
*
|
|
33
|
+
* Numbers are grouped the way `en-US` groups them. Localised formatting is a
|
|
34
|
+
* separate, later change. The package README lists every rule with worked
|
|
35
|
+
* examples.
|
|
36
|
+
*
|
|
37
|
+
* @packageDocumentation
|
|
38
|
+
*/
|
|
39
|
+
/** The part of a response's `denomination` a credit renderer needs. */
|
|
40
|
+
export interface DisplayDenomination {
|
|
41
|
+
/** An ISO 4217 code: what the micro-units are millionths of. */
|
|
42
|
+
currency: string;
|
|
43
|
+
/** How many micro-units one credit is, as a positive integer string. */
|
|
44
|
+
microPerCredit: string;
|
|
45
|
+
}
|
|
46
|
+
/** The part of a response's `denomination` a money renderer needs. */
|
|
47
|
+
export interface DisplayCurrency {
|
|
48
|
+
/** An ISO 4217 code: what the micro-units are millionths of. */
|
|
49
|
+
currency: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* An amount as it came off the wire. Anything but a base-10 integer string
|
|
53
|
+
* renders as `null`.
|
|
54
|
+
*/
|
|
55
|
+
export type AmountInput = string | null | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* A response's `denomination` as it came off the wire. Absent or malformed
|
|
58
|
+
* renders as `null`.
|
|
59
|
+
*/
|
|
60
|
+
export type DenominationInput = DisplayDenomination | null | undefined;
|
|
61
|
+
/** A currency as it came off the wire. Absent or malformed renders as `null`. */
|
|
62
|
+
export type CurrencyInput = DisplayCurrency | null | undefined;
|
|
63
|
+
/** How a credit figure is rounded: see the module overview. */
|
|
64
|
+
export type CreditKind = 'position' | 'charge' | 'rate';
|
|
65
|
+
/** How any figure is rounded: the three credit kinds, plus money and cap. */
|
|
66
|
+
export type AmountDisplayKind = CreditKind | 'money' | 'cap';
|
|
67
|
+
/**
|
|
68
|
+
* Floor division: the quotient rounded toward negative infinity.
|
|
69
|
+
*
|
|
70
|
+
* @param dividend - Any integer.
|
|
71
|
+
* @param divisor - A positive integer.
|
|
72
|
+
*/
|
|
73
|
+
export declare function floorDiv(dividend: bigint, divisor: bigint): bigint;
|
|
74
|
+
/**
|
|
75
|
+
* The quotient rounded to the nearest integer, a tie going away from zero.
|
|
76
|
+
*
|
|
77
|
+
* @param dividend - Any integer.
|
|
78
|
+
* @param divisor - A positive integer.
|
|
79
|
+
*/
|
|
80
|
+
export declare function roundHalfAwayFromZero(dividend: bigint, divisor: bigint): bigint;
|
|
81
|
+
/**
|
|
82
|
+
* Renders what a person has or may still spend: whole credits, rounded toward
|
|
83
|
+
* negative infinity, so it never shows credit that cannot be spent.
|
|
84
|
+
*
|
|
85
|
+
* @param micro - The amount string, in micro-units.
|
|
86
|
+
* @param denomination - The response's `denomination`.
|
|
87
|
+
* @returns The grouped credit count, or `null` for a malformed amount or denomination.
|
|
88
|
+
*/
|
|
89
|
+
export declare function formatPosition(micro: AmountInput, denomination: DenominationInput): string | null;
|
|
90
|
+
/**
|
|
91
|
+
* Renders what a person spent, was charged or is held for: whole credits,
|
|
92
|
+
* rounded half away from zero. Zero reads as zero; a non-zero amount that rounds
|
|
93
|
+
* to zero reads as less than one credit, with a minus sign when negative.
|
|
94
|
+
*
|
|
95
|
+
* @param micro - The amount string, in micro-units.
|
|
96
|
+
* @param denomination - The response's `denomination`.
|
|
97
|
+
* @returns The grouped credit count, or `null` for a malformed amount or denomination.
|
|
98
|
+
*/
|
|
99
|
+
export declare function formatCharge(micro: AmountInput, denomination: DenominationInput): string | null;
|
|
100
|
+
/**
|
|
101
|
+
* Renders a price per unit of something in credits, never rounded: every
|
|
102
|
+
* significant digit, trailing zeros trimmed.
|
|
103
|
+
*
|
|
104
|
+
* A scale with a prime factor other than two or five cannot write every
|
|
105
|
+
* amount as a finite decimal. Such an amount returns `null` rather than a
|
|
106
|
+
* rounded figure.
|
|
107
|
+
*
|
|
108
|
+
* @param micro - The amount string, in micro-units.
|
|
109
|
+
* @param denomination - The response's `denomination`.
|
|
110
|
+
* @returns The exact credit figure, or `null` when it cannot be written exactly or the input is malformed.
|
|
111
|
+
*/
|
|
112
|
+
export declare function formatRate(micro: AmountInput, denomination: DenominationInput): string | null;
|
|
113
|
+
/**
|
|
114
|
+
* Renders money: rounded to the currency's minor unit, half away from zero.
|
|
115
|
+
* An amount that is exactly a whole major unit prints without minor digits;
|
|
116
|
+
* any other prints with all of them. A non-zero amount that rounds to zero
|
|
117
|
+
* reads as less than the smallest unit.
|
|
118
|
+
*
|
|
119
|
+
* Money needs no credit scale, so a bare `{ currency }` is enough.
|
|
120
|
+
*
|
|
121
|
+
* @param micro - The amount string, in micro-units of the currency.
|
|
122
|
+
* @param currency - The response's `denomination`, or just `{ currency }`.
|
|
123
|
+
* @returns The money text, or `null` for a malformed amount or currency.
|
|
124
|
+
*/
|
|
125
|
+
export declare function formatMoney(micro: AmountInput, currency: CurrencyInput): string | null;
|
|
126
|
+
/**
|
|
127
|
+
* Renders a money limit: the money rule, rounded toward negative infinity, so
|
|
128
|
+
* a limit never reads higher than the one enforced.
|
|
129
|
+
*
|
|
130
|
+
* @param micro - The amount string, in micro-units of the currency.
|
|
131
|
+
* @param currency - The response's `denomination`, or just `{ currency }`.
|
|
132
|
+
* @returns The money text, or `null` for a malformed amount or currency.
|
|
133
|
+
*/
|
|
134
|
+
export declare function formatCap(micro: AmountInput, currency: CurrencyInput): string | null;
|
|
135
|
+
/**
|
|
136
|
+
* Renders a price in money, never rounded: the exact amount, with at least the
|
|
137
|
+
* currency's minor digits.
|
|
138
|
+
*
|
|
139
|
+
* @param micro - The amount string, in micro-units of the currency.
|
|
140
|
+
* @param currency - The response's `denomination`, or just `{ currency }`.
|
|
141
|
+
* @returns The money text, or `null` for a malformed amount or currency.
|
|
142
|
+
*/
|
|
143
|
+
export declare function formatMoneyRate(micro: AmountInput, currency: CurrencyInput): string | null;
|
|
144
|
+
/**
|
|
145
|
+
* Renders a credit figure with its money value beside it:
|
|
146
|
+
* `<credits> credits (<money>)`, with the singular for exactly one credit.
|
|
147
|
+
*
|
|
148
|
+
* For a position or a charge the money is worked out from the ROUNDED credit
|
|
149
|
+
* count times the served scale, never separately from the exact amount, so the
|
|
150
|
+
* two figures always agree. A charge under one credit reads as less than one
|
|
151
|
+
* credit, beside less than the money of one credit. A rate is exact on both
|
|
152
|
+
* sides.
|
|
153
|
+
*
|
|
154
|
+
* @param micro - The amount string, in micro-units.
|
|
155
|
+
* @param denomination - The response's `denomination`.
|
|
156
|
+
* @param kind - How the credit figure is rounded.
|
|
157
|
+
* @returns The text, or `null` for a malformed amount or denomination.
|
|
158
|
+
*/
|
|
159
|
+
export declare function formatCreditsWithMoney(micro: AmountInput, denomination: DenominationInput, kind: CreditKind): string | null;
|
|
160
|
+
/**
|
|
161
|
+
* Renders a total the only honest way: the exact sum of the lines, rounded once
|
|
162
|
+
* by the kind of what it totals. Never the sum of rounded lines, so a total may
|
|
163
|
+
* differ from its rounded lines by a credit or two, and it is the total that
|
|
164
|
+
* matches what was charged.
|
|
165
|
+
*
|
|
166
|
+
* @param lines - The exact amount strings being totalled.
|
|
167
|
+
* @param denomination - The response's `denomination` (or `{ currency }` for money and cap).
|
|
168
|
+
* @param kind - How the total is rounded.
|
|
169
|
+
* @returns The total's text, or `null` when any line or the denomination is malformed.
|
|
170
|
+
*/
|
|
171
|
+
export declare function formatTotal(lines: readonly AmountInput[], denomination: DenominationInput | CurrencyInput, kind: AmountDisplayKind): string | null;
|
|
172
|
+
//# sourceMappingURL=display.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display.d.ts","sourceRoot":"","sources":["../src/display.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,uEAAuE;AACvE,MAAM,WAAW,mBAAmB;IAClC,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,sEAAsE;AACtE,MAAM,WAAW,eAAe;IAC9B,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,mBAAmB,GAAG,IAAI,GAAG,SAAS,CAAC;AAEvE,iFAAiF;AACjF,MAAM,MAAM,aAAa,GAAG,eAAe,GAAG,IAAI,GAAG,SAAS,CAAC;AAE/D,+DAA+D;AAC/D,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAC;AAExD,6EAA6E;AAC7E,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG,OAAO,GAAG,KAAK,CAAC;AAc7D;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,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