@sess.si/sdk 0.1.0-rc.8 → 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/CHANGELOG.md +66 -9
- package/NOTICE +1 -1
- package/README.md +92 -16
- package/dist/ask.d.ts +0 -1
- package/dist/ask.js +0 -1
- package/dist/cli/main.d.ts +0 -1
- package/dist/cli/main.js +0 -1
- package/dist/cli/verify.d.ts +0 -1
- package/dist/cli/verify.js +0 -1
- package/dist/client.d.ts +0 -1
- package/dist/client.js +0 -1
- package/dist/commerce/builders.d.ts +99 -0
- package/dist/commerce/builders.js +208 -0
- package/dist/commerce/currency.d.ts +4 -0
- package/dist/commerce/currency.js +25 -0
- package/dist/commerce/items.d.ts +119 -0
- package/dist/commerce/items.js +280 -0
- package/dist/commerce/lint.d.ts +16 -0
- package/dist/commerce/lint.js +56 -0
- package/dist/errors.d.ts +5 -2
- package/dist/errors.js +15 -25
- package/dist/generated/openapi.d.ts +12 -13
- package/dist/generated/openapi.js +0 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +3 -1
- package/dist/internal/decode.d.ts +0 -1
- package/dist/internal/decode.js +9 -2
- package/dist/internal/json.d.ts +0 -1
- package/dist/internal/json.js +0 -1
- package/dist/internal/time.d.ts +0 -1
- package/dist/internal/time.js +0 -1
- package/dist/internal/version.d.ts +2 -0
- package/dist/internal/version.js +2 -0
- package/dist/polling.d.ts +0 -1
- package/dist/polling.js +0 -1
- package/dist/qr/encoder.d.ts +0 -1
- package/dist/qr/encoder.js +0 -1
- package/dist/qr/index.d.ts +0 -1
- package/dist/qr/index.js +0 -1
- package/dist/receipts/bundle.d.ts +0 -1
- package/dist/receipts/bundle.js +0 -1
- package/dist/receipts/index.d.ts +0 -1
- package/dist/receipts/index.js +0 -1
- package/dist/receipts/json.d.ts +0 -1
- package/dist/receipts/json.js +0 -1
- package/dist/receipts/key-cache.d.ts +0 -1
- package/dist/receipts/key-cache.js +0 -1
- package/dist/receipts/renderers.d.ts +0 -1
- package/dist/receipts/renderers.js +1 -2
- package/dist/receipts/resource.d.ts +0 -1
- package/dist/receipts/resource.js +0 -1
- package/dist/receipts/verify.d.ts +0 -1
- package/dist/receipts/verify.js +0 -1
- package/dist/sessions.d.ts +0 -1
- package/dist/sessions.js +0 -1
- package/dist/transport.d.ts +0 -1
- package/dist/transport.js +35 -5
- package/dist/types.d.ts +56 -2
- package/dist/types.js +0 -1
- package/dist/webhook-resource.d.ts +0 -1
- package/dist/webhook-resource.js +0 -1
- package/dist/webhooks/index.d.ts +0 -1
- package/dist/webhooks/index.js +0 -1
- package/package.json +8 -3
- package/dist/ask.d.ts.map +0 -1
- package/dist/ask.js.map +0 -1
- package/dist/cli/main.d.ts.map +0 -1
- package/dist/cli/main.js.map +0 -1
- package/dist/cli/verify.d.ts.map +0 -1
- package/dist/cli/verify.js.map +0 -1
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/generated/openapi.d.ts.map +0 -1
- package/dist/generated/openapi.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/internal/decode.d.ts.map +0 -1
- package/dist/internal/decode.js.map +0 -1
- package/dist/internal/json.d.ts.map +0 -1
- package/dist/internal/json.js.map +0 -1
- package/dist/internal/time.d.ts.map +0 -1
- package/dist/internal/time.js.map +0 -1
- package/dist/polling.d.ts.map +0 -1
- package/dist/polling.js.map +0 -1
- package/dist/qr/encoder.d.ts.map +0 -1
- package/dist/qr/encoder.js.map +0 -1
- package/dist/qr/index.d.ts.map +0 -1
- package/dist/qr/index.js.map +0 -1
- package/dist/receipts/bundle.d.ts.map +0 -1
- package/dist/receipts/bundle.js.map +0 -1
- package/dist/receipts/index.d.ts.map +0 -1
- package/dist/receipts/index.js.map +0 -1
- package/dist/receipts/json.d.ts.map +0 -1
- package/dist/receipts/json.js.map +0 -1
- package/dist/receipts/key-cache.d.ts.map +0 -1
- package/dist/receipts/key-cache.js.map +0 -1
- package/dist/receipts/renderers.d.ts.map +0 -1
- package/dist/receipts/renderers.js.map +0 -1
- package/dist/receipts/resource.d.ts.map +0 -1
- package/dist/receipts/resource.js.map +0 -1
- package/dist/receipts/verify.d.ts.map +0 -1
- package/dist/receipts/verify.js.map +0 -1
- package/dist/sessions.d.ts.map +0 -1
- package/dist/sessions.js.map +0 -1
- package/dist/transport.d.ts.map +0 -1
- package/dist/transport.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/webhook-resource.d.ts.map +0 -1
- package/dist/webhook-resource.js.map +0 -1
- package/dist/webhooks/index.d.ts.map +0 -1
- package/dist/webhooks/index.js.map +0 -1
- package/src/ask.ts +0 -683
- package/src/cli/main.ts +0 -8
- package/src/cli/verify.ts +0 -349
- package/src/client.ts +0 -55
- package/src/errors.ts +0 -127
- package/src/generated/openapi.ts +0 -8586
- package/src/index.ts +0 -5
- package/src/internal/decode.ts +0 -348
- package/src/internal/json.ts +0 -64
- package/src/internal/time.ts +0 -85
- package/src/polling.ts +0 -173
- package/src/qr/encoder.ts +0 -345
- package/src/qr/index.ts +0 -203
- package/src/receipts/bundle.ts +0 -547
- package/src/receipts/index.ts +0 -29
- package/src/receipts/json.ts +0 -168
- package/src/receipts/key-cache.ts +0 -143
- package/src/receipts/renderers.ts +0 -220
- package/src/receipts/resource.ts +0 -264
- package/src/receipts/verify.ts +0 -554
- package/src/sessions.ts +0 -238
- package/src/transport.ts +0 -566
- package/src/types.ts +0 -219
- package/src/webhook-resource.ts +0 -81
- package/src/webhooks/index.ts +0 -246
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,66 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.1.0
|
|
4
|
-
|
|
5
|
-
-
|
|
3
|
+
## 0.1.0 — 2026-10-31
|
|
4
|
+
|
|
5
|
+
- The first stable release, published to the `latest` dist-tag. The API is that of
|
|
6
|
+
0.1.0-rc.10, unchanged.
|
|
7
|
+
- Development dependency only: the contract generator's `@redocly/openapi-core` now resolves
|
|
8
|
+
`minimatch` 11.0.1 (advisory GHSA-g3hv-75wg-m249), through a scoped `overrides` entry. No
|
|
9
|
+
runtime dependency changes; the generated types are byte-identical.
|
|
10
|
+
|
|
11
|
+
## 0.1.0-rc.10 — 2026-10-28
|
|
12
|
+
|
|
13
|
+
- Short human links: a request identifier holding a run of 22 or more base64url characters (a
|
|
14
|
+
short-link token is 22, as in `/n/<token>`; a `/s/` token 43; either may be glued to more) is
|
|
15
|
+
withheld from `SessError.requestId` and request events. Sess's own `req_<uuid>` ids are kept.
|
|
16
|
+
- A key Sess does not accept (HTTP 401 `UNAUTHORIZED`) now says so: the `SessError` message is
|
|
17
|
+
"Sess did not accept your API key. Check SESS_API_KEY and the portal you made it on." instead of
|
|
18
|
+
the generic "The Sess API returned an error. See the status and code fields." Other messages
|
|
19
|
+
are unchanged. `code`, `status` and `requestId` are still on the error.
|
|
20
|
+
- A `SessError` has an own property only for a field with a value. Printing one (an uncaught
|
|
21
|
+
error, `console.log`, `util.inspect`, `JSON.stringify`) no longer lists absent fields as
|
|
22
|
+
`undefined`; reading an absent field still gives `undefined`. The Node quickstart and the
|
|
23
|
+
README print the message first, then a `Details:` line with the code and request ID.
|
|
24
|
+
|
|
25
|
+
## 0.1.0-rc.9 — 2026-10-28
|
|
26
|
+
|
|
27
|
+
- Commerce: bills as ordinary Surfaces, for Sess's `items` component. Sess takes no payment.
|
|
28
|
+
`money(amount, currency)` checks a whole number of minor units (cents for USD, yen for JPY, fils
|
|
29
|
+
for BHD) and an ISO 4217 code Sess accepts; it never rounds or converts. `items()` builds the
|
|
30
|
+
component with its subtotal, total and amount due computed exactly from the rows, lines and
|
|
31
|
+
payments, so Sess's arithmetic check passes. `invoice()`, `receipt()`, `quote()`, `refund()` and
|
|
32
|
+
`purchaseOrder()` return an `interaction` for `sessions.create()`: the card, the document's
|
|
33
|
+
reference in a record under a plain name, and the buttons Sess requires (Request changes
|
|
34
|
+
whenever a quantity is editable). `refund()` states positive amounts under "Refund total" and
|
|
35
|
+
never a negative total. `lintText()` finds Markdown pipe tables in text and says whether to send
|
|
36
|
+
an items component or a record. Limits match Sess's and reject, never truncate: row name 80,
|
|
37
|
+
detail 160, totals label 40, caption 200, rows 100, totals lines 8 (`ITEMS_LIMITS`); a refusal is
|
|
38
|
+
a `SessError` with code `INVALID_SCHEMA`, outcome `not_sent`, and the value's JSON pointer in
|
|
39
|
+
`field`. A `record` key `__proto__`, `constructor` or `prototype` is refused. New types
|
|
40
|
+
`ItemsComponent` and `ItemTotalRole` (`SurfaceComponent` includes items) and the Advanced
|
|
41
|
+
`locale` on an interactive interaction. Session reads now accept an items component, and a 400
|
|
42
|
+
for too many rows or totals lines carries Sess's sentence.
|
|
43
|
+
- Every request names the SDK in its `User-Agent` header: `sess-sdk/<version> node/<version>`.
|
|
44
|
+
The new client option `userAgent` puts a wrapping client's product tokens first, for example
|
|
45
|
+
`userAgent: 'my-app/1.2.0'` sends `my-app/1.2.0 sess-sdk/0.1.0-rc.9 node/24.21.0`. A value that is
|
|
46
|
+
not product tokens separated by single spaces (at most 256 characters) is a `configuration`
|
|
47
|
+
error before anything is sent.
|
|
48
|
+
- A plan limit is a refusal, not an uncertain outcome. Sess answers a create over the workspace's
|
|
49
|
+
plan with HTTP 429 `PLAN_LIMIT_REACHED`, and nothing is created. The SDK now reports it as
|
|
50
|
+
`kind: 'api'`, `outcome: 'rejected'`, with `code`, `reason` (`monthly_allowance` or
|
|
51
|
+
`active_sessions`), `status: 429` and, for `monthly_allowance`, `retryAfterMs` from
|
|
52
|
+
`Retry-After` (time until the period resets); it is never retried. Before, it was
|
|
53
|
+
`unknown_outcome` ("may have succeeded"). Any other 429 (no code, or `RATE_LIMITED`) is unchanged:
|
|
54
|
+
transient, retried where retries are allowed, and uncertain for a write.
|
|
55
|
+
- The package ships compiled output only: no source maps (`*.js.map`, `*.d.ts.map`) or
|
|
56
|
+
`sourceMappingURL` comments, and no `src/` TypeScript sources (every export and types path is in
|
|
57
|
+
`dist/`). The generated wire types' JSDoc names Sess specifications instead of runtime-repository
|
|
58
|
+
document paths. Every published package's packed bytes now pass a hygiene check (no maps,
|
|
59
|
+
fixtures, non-public hosts, credential-shaped strings or internal references).
|
|
60
|
+
|
|
61
|
+
## 0.1.0-rc.8 — 2026-10-22
|
|
62
|
+
|
|
63
|
+
- Link timing. On an interactive Sess link of 20 hours or less the
|
|
6
64
|
person may ask for more time, up to ten times, never past a fixed horizon. Session reads carry
|
|
7
65
|
`link_state` (`live`, `lapsed` or `expired`), `action_expires_horizon`, `extensions_used` and the
|
|
8
66
|
`extensions` history; the Session log (`listEvents()`) lists the same records as
|
|
@@ -15,12 +73,11 @@
|
|
|
15
73
|
revocation, a later read at least the grace after the first expired read; a short `intervalMs`
|
|
16
74
|
reads again sooner but never ends the wait inside the grace). A live read never ends the wait. Without `link_state` the
|
|
17
75
|
deadline stays final, as in rc.7.
|
|
18
|
-
- Contract snapshot from Sess runtime commit `2f8500e` (
|
|
19
|
-
see `contract/contract-lock.json`). Besides link timing it carries what Sess master already
|
|
76
|
+
- Contract snapshot from Sess runtime commit `2f8500e` (see `contract/contract-lock.json`). Besides link timing it carries what Sess master already
|
|
20
77
|
describes: the interactive text limits with `field`, `limit` and `length` on a length error,
|
|
21
78
|
`progress`, the receipt `format` and the renderer identities list. The generated wire types gain
|
|
22
79
|
them; the SDK's public types and behavior in this change are link timing only.
|
|
23
|
-
- Renderer identities
|
|
80
|
+
- Renderer identities. A receipt's `surface.renderer_version` now
|
|
24
81
|
verifies when it is an identity this release bundles (`sess-html-form-1`, `sess-html-form-2`;
|
|
25
82
|
`BUNDLED_RENDERER_IDENTITIES`) or one on the issuer's renderer list whose signature verifies
|
|
26
83
|
under the same trusted keys and issuer, so a later Sess page change needs no SDK update. Every
|
|
@@ -44,7 +101,7 @@
|
|
|
44
101
|
`--issuer`; a list that does not verify exits 2), the bundle's renderer identity must be known
|
|
45
102
|
or listed (otherwise invalid, exit 1). Without it, bundle verification is unchanged.
|
|
46
103
|
- The receipt-v1 specification copy is from Sess commit `a60ca69` (§10, renderer identities with
|
|
47
|
-
`seq` and `iat
|
|
104
|
+
`seq` and `iat`).
|
|
48
105
|
- Sess's length limits, in Unicode code points and never truncated: title 80, description 280,
|
|
49
106
|
heading 60, field and option labels 60, field description 160, action label 24, record caption
|
|
50
107
|
200, record key 40 and string value 200, text 4,000; at most 5 actions. The types' JSDoc gives each field its
|
|
@@ -56,7 +113,7 @@
|
|
|
56
113
|
Sess's own fix. The README and the quickstart show catching it, shortening the value and asking again.
|
|
57
114
|
Surfaces stored before these limits still read as before.
|
|
58
115
|
|
|
59
|
-
## 0.1.0-rc.7 — 2026-10-18
|
|
116
|
+
## 0.1.0-rc.7 — 2026-10-18
|
|
60
117
|
|
|
61
118
|
Includes everything in the unpublished 0.1.0-rc.6 below, which is not published on its own.
|
|
62
119
|
|
|
@@ -73,7 +130,7 @@ Includes everything in the unpublished 0.1.0-rc.6 below, which is not published
|
|
|
73
130
|
- `ResponseMeta.serverDate`: the response's HTTP `Date`, when the runtime sends one.
|
|
74
131
|
- Contract snapshot from Sess runtime commit `b48e8e7` (see `contract/contract-lock.json`), with
|
|
75
132
|
`expires_in`, `action_expires_at` on create and the target's `default_expires_in`.
|
|
76
|
-
- `@sess.si/sdk/qr
|
|
133
|
+
- `@sess.si/sdk/qr`: `qr(url, { format: 'svg' | 'png' | 'terminal' })` draws a Sess link as a
|
|
77
134
|
QR code locally (error correction level M, 4-module quiet zone, deterministic, no network call), and
|
|
78
135
|
`printQr(url)` prints "Scan to answer on your phone" and the code on an interactive terminal only:
|
|
79
136
|
never without a TTY, in CI or with `NODE_ENV=production`; `--no-qr` or `{ qr: false }` turn it off
|
package/NOTICE
CHANGED
package/README.md
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
# Sess SDK
|
|
2
2
|
|
|
3
|
-
Ask a person a question from your server and continue with their verified answer.
|
|
4
|
-
creates a hosted Sess page, waits for the answer, checks its signed receipt and continues the same
|
|
5
|
-
Session.
|
|
3
|
+
Ask a person a question from your server and continue with their verified answer.
|
|
6
4
|
|
|
7
|
-
**
|
|
5
|
+
**Create and run** a small agent:
|
|
8
6
|
|
|
9
7
|
```sh
|
|
10
|
-
npm
|
|
8
|
+
npm create @sess.si/agent@latest my-agent
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
**
|
|
14
|
-
|
|
11
|
+
**What you'll see:** a Sess link. Answer two questions on your phone and your plan prints in the
|
|
12
|
+
terminal with a verified receipt.
|
|
15
13
|
|
|
16
|
-
**
|
|
17
|
-
|
|
14
|
+
**Install** the SDK in your own server project:
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npm install --save-exact @sess.si/sdk@0.1.0
|
|
18
|
+
```
|
|
18
19
|
|
|
19
20
|
## Ask a person
|
|
20
21
|
|
|
@@ -55,6 +56,29 @@ confirmed; calling `answer()` again replays the same completion. The handle live
|
|
|
55
56
|
resume after a restart, persist `sessionId` and `revision` and continue with the API below
|
|
56
57
|
([Integration](docs/integration.md#one-question-with-sessask)).
|
|
57
58
|
|
|
59
|
+
If Sess refuses a call, the error says what happened and what to do. A key Sess does not accept
|
|
60
|
+
prints: "Sess did not accept your API key. Check SESS_API_KEY and the portal you made it on." The
|
|
61
|
+
message comes first; the code and request ID follow it:
|
|
62
|
+
|
|
63
|
+
<!-- example:ask-error -->
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
try {
|
|
67
|
+
const question = await sess.ask({
|
|
68
|
+
question: 'Approve the synthetic refund?',
|
|
69
|
+
fields: [{ name: 'approved', label: 'Approve it', type: 'boolean' }],
|
|
70
|
+
});
|
|
71
|
+
console.log(`Send this Sess link to the person: ${question.link}`);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error(error.message); // what happened and what to do
|
|
74
|
+
const request = error.requestId ? `, request ${error.requestId}` : '';
|
|
75
|
+
console.error(`Details: ${error.code ?? error.kind}${request}`);
|
|
76
|
+
process.exitCode = 1;
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
<!-- /example:ask-error -->
|
|
81
|
+
|
|
58
82
|
## Keep it short
|
|
59
83
|
|
|
60
84
|
A person reads the page on a phone, so Sess keeps every piece of it short. Lengths count
|
|
@@ -96,10 +120,63 @@ async function askShort(question: string) {
|
|
|
96
120
|
}
|
|
97
121
|
```
|
|
98
122
|
|
|
99
|
-
**Release status:**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
123
|
+
**Release status:** `0.1.0` is the first stable release, served under the `latest` dist-tag.
|
|
124
|
+
`next` stays at the last release candidate, `0.1.0-rc.10`. The [changelog](CHANGELOG.md) describes
|
|
125
|
+
each version; `npm view @sess.si/sdk dist-tags` shows what the registry serves now.
|
|
126
|
+
|
|
127
|
+
## Commerce
|
|
128
|
+
|
|
129
|
+
Sess takes no payment: the person approves a bill on a Sess page, and moving the money stays with
|
|
130
|
+
you and your payment processor.
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
import { Sess, invoice } from '@sess.si/sdk';
|
|
134
|
+
const sess = new Sess({ apiKey: process.env.SESS_API_KEY });
|
|
135
|
+
const created = await sess.sessions.create({
|
|
136
|
+
interaction: invoice({
|
|
137
|
+
currency: 'CAD', // whole cents: 420000 is $4,200.00
|
|
138
|
+
reference: 'INV-2041',
|
|
139
|
+
rows: [{ name: 'Design retainer, October', amount: 420000 }],
|
|
140
|
+
lines: [{ label: 'GST 5%', amount: 21000, role: 'tax' }],
|
|
141
|
+
}),
|
|
142
|
+
});
|
|
143
|
+
console.log(`Send this Sess link to the person: ${created.data.human_url}`);
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Three things you will meet first:
|
|
147
|
+
|
|
148
|
+
- **Short rows.** A row name has at most 80 characters and its detail at most 160. A longer value
|
|
149
|
+
is refused, never trimmed: the `SessError` names it by its pointer, such as
|
|
150
|
+
`/interaction/source/components/1/rows/0/name`, with `limit` and `length`.
|
|
151
|
+
- **Whole minor units.** Amounts are integers in the currency's smallest unit: cents for USD, yen
|
|
152
|
+
for JPY, fils for BHD. `money(1250, 'USD')` is $12.50; `money(12.5, 'USD')` throws, because Sess
|
|
153
|
+
never rounds or converts.
|
|
154
|
+
- **Exact totals.** The builders compute the subtotal, total and amount due from your rows and
|
|
155
|
+
lines. An items component you write by hand whose subtotal is not the sum of its rows is refused
|
|
156
|
+
with HTTP 400:
|
|
157
|
+
|
|
158
|
+
```json
|
|
159
|
+
{
|
|
160
|
+
"error": {
|
|
161
|
+
"code": "INVALID_SCHEMA",
|
|
162
|
+
"field": "/interaction/source/components/0/totals/0/amount",
|
|
163
|
+
"expected": 441250,
|
|
164
|
+
"actual": 451248
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
`invoice()`, `receipt()`, `quote()`, `refund()` and `purchaseOrder()` each return an ordinary
|
|
170
|
+
interactive Surface for `sess.sessions.create({ interaction })`: the bill as an `items` card, the
|
|
171
|
+
document's `reference` under a plain name, and the buttons the person needs (Approve and Decline;
|
|
172
|
+
Continue on a receipt; Accept on a quote). `refund()` states positive amounts under "Refund total".
|
|
173
|
+
A row `quantity` lets the person change it and adds a Request changes button; your agent replies
|
|
174
|
+
with a new revision and updated amounts. `items()` builds just the card, and `lintText()` finds a
|
|
175
|
+
Markdown table in text, which the person would see as pipes. See the
|
|
176
|
+
[API reference](docs/api.md#commerce).
|
|
177
|
+
|
|
178
|
+
What Sess does not do: take or move payment, convert currencies, compute tax or prices, show your
|
|
179
|
+
logo or branding, or let another site frame the page (`frame-ancestors 'none'`).
|
|
103
180
|
|
|
104
181
|
## Advanced: the full Surface API
|
|
105
182
|
|
|
@@ -165,11 +242,10 @@ exact Surface and input, and the issuer's public keys. Check it on your own comp
|
|
|
165
242
|
trust (never the keys inside the bundle):
|
|
166
243
|
|
|
167
244
|
```sh
|
|
168
|
-
npx -p @sess.si/sdk@0.1.0
|
|
245
|
+
npx -p @sess.si/sdk@0.1.0 sess verify bundle.json --issuer https://api.sess.si --keys sess-receipt-keys.json
|
|
169
246
|
```
|
|
170
247
|
|
|
171
|
-
The `sess` command first ships in `0.1.0-rc.5`;
|
|
172
|
-
the bare package name resolves to the `latest` placeholder, which has no command.
|
|
248
|
+
The `sess` command first ships in `0.1.0-rc.5`; any later version, `0.1.0` included, has it.
|
|
173
249
|
|
|
174
250
|
You'll see `Valid decision bundle.` and what was accepted, when, on which revision; or `Invalid`
|
|
175
251
|
and the first reason. Exit status is 0 valid, 1 invalid, 2 usage error; add `--json` for the full
|
package/dist/ask.d.ts
CHANGED
|
@@ -159,4 +159,3 @@ export declare function checkAnswer(fields: readonly CompiledField[], data: unkn
|
|
|
159
159
|
/** Validates locally, creates once (the link is available before any wait) and returns the handle. */
|
|
160
160
|
export declare function ask<T>(sessions: Sessions, receipts: ReceiptResource, input: unknown, options?: AskOptions): Promise<AskHandle<T>>;
|
|
161
161
|
export {};
|
|
162
|
-
//# sourceMappingURL=ask.d.ts.map
|
package/dist/ask.js
CHANGED
package/dist/cli/main.d.ts
CHANGED
package/dist/cli/main.js
CHANGED
package/dist/cli/verify.d.ts
CHANGED
|
@@ -11,4 +11,3 @@ export interface CliIo {
|
|
|
11
11
|
export declare const USAGE = "Usage: sess verify <bundle.json> --issuer <url> --keys <jwks.json> [options]\n\nChecks a Sess decision bundle on this computer against the issuer and keys you trust.\nNothing is sent anywhere. Keys inside the bundle are never trusted.\n\nRequired:\n --issuer <url> the receipt issuer you trust, for example https://api.sess.si\n --keys <file> that issuer's public keys (a JWK Set) you obtained yourself\n\nExpected context (optional; only what you pass is checked):\n --audience <id> the workspace the decision must belong to\n --workspace <id> the workspace ID\n --session <id> the Session ID\n --event <id> the Event ID\n --revision <n> the Surface revision\n --action <id> the action ID\n\nRenderer identity (optional):\n --renderers <file> the issuer's signed renderer list you obtained yourself\n (<issuer>/.well-known/sess-renderer-identities.json); also checks that the\n receipt's renderer identity is one this release knows or one on that list\n\nOther:\n --now <time> check at this RFC 3339 time instead of now\n --json print the full result as JSON\n -h, --help show this help\n\nExit status: 0 valid, 1 invalid, 2 usage or file error.\n";
|
|
12
12
|
/** Runs `sess <argv>`; resolves to the exit code. Never throws. */
|
|
13
13
|
export declare function runCli(argv: readonly string[], io: CliIo): Promise<number>;
|
|
14
|
-
//# sourceMappingURL=verify.d.ts.map
|
package/dist/cli/verify.js
CHANGED
package/dist/client.d.ts
CHANGED
package/dist/client.js
CHANGED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { InteractiveInteraction } from '../types.js';
|
|
2
|
+
import { type ItemsInput } from './items.js';
|
|
3
|
+
type Action = InteractiveInteraction['actions'][number];
|
|
4
|
+
type RecordValue = string | number | boolean | null;
|
|
5
|
+
/** Common input of the five builders: the items input plus the page around it. */
|
|
6
|
+
export interface BillInput extends ItemsInput {
|
|
7
|
+
/** The page's heading, about 40 characters; at most 80. Each builder has a default. */
|
|
8
|
+
readonly title?: string;
|
|
9
|
+
/** Optional context under the title, one or two sentences; at most 280. */
|
|
10
|
+
readonly description?: string;
|
|
11
|
+
/** Advanced: the BCP 47 locale the page formats amounts in (default: the page's language). */
|
|
12
|
+
readonly locale?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The document's number (invoice, receipt, quote, refund or purchase order number), shown in a
|
|
15
|
+
* record under its plain name, such as `Invoice` → `INV-2041`; at most 200.
|
|
16
|
+
*/
|
|
17
|
+
readonly reference?: string;
|
|
18
|
+
/** Other facts beside the bill, shown verbatim in the same record (`Due`, `Valid until` …). */
|
|
19
|
+
readonly record?: Readonly<Record<string, RecordValue>>;
|
|
20
|
+
/**
|
|
21
|
+
* Advanced: the buttons, replacing the builder's (1–5). A bill with editable quantities needs
|
|
22
|
+
* one with `intent: 'request_change'`.
|
|
23
|
+
*/
|
|
24
|
+
readonly actions?: readonly Action[];
|
|
25
|
+
}
|
|
26
|
+
/** A refund: positive amounts under refund labels, never a negative total. No payments. */
|
|
27
|
+
export type RefundInput = Omit<BillInput, 'payments'>;
|
|
28
|
+
/**
|
|
29
|
+
* The words a builder puts on the page when you give none (proposed copy; `Request changes` is
|
|
30
|
+
* Sess's signed label for a change request). Every one can be replaced through the input.
|
|
31
|
+
*/
|
|
32
|
+
export declare const COMMERCE_DEFAULTS: Readonly<{
|
|
33
|
+
titles: Readonly<{
|
|
34
|
+
invoice: "Approve this invoice?";
|
|
35
|
+
receipt: "Your receipt";
|
|
36
|
+
quote: "Accept this quote?";
|
|
37
|
+
refund: "Approve the refund?";
|
|
38
|
+
purchaseOrder: "Approve the order?";
|
|
39
|
+
}>;
|
|
40
|
+
references: Readonly<{
|
|
41
|
+
invoice: "Invoice";
|
|
42
|
+
receipt: "Receipt";
|
|
43
|
+
quote: "Quote";
|
|
44
|
+
refund: "Refund";
|
|
45
|
+
purchaseOrder: "Purchase order";
|
|
46
|
+
}>;
|
|
47
|
+
actions: Readonly<{
|
|
48
|
+
approve: Readonly<{
|
|
49
|
+
id: "approve";
|
|
50
|
+
label: "Approve";
|
|
51
|
+
intent: "approve";
|
|
52
|
+
}>;
|
|
53
|
+
accept: Readonly<{
|
|
54
|
+
id: "accept";
|
|
55
|
+
label: "Accept";
|
|
56
|
+
intent: "approve";
|
|
57
|
+
}>;
|
|
58
|
+
continue: Readonly<{
|
|
59
|
+
id: "continue";
|
|
60
|
+
label: "Continue";
|
|
61
|
+
intent: "continue";
|
|
62
|
+
}>;
|
|
63
|
+
decline: Readonly<{
|
|
64
|
+
id: "decline";
|
|
65
|
+
label: "Decline";
|
|
66
|
+
intent: "reject";
|
|
67
|
+
}>;
|
|
68
|
+
change: Readonly<{
|
|
69
|
+
id: "change";
|
|
70
|
+
label: "Request changes";
|
|
71
|
+
intent: "request_change";
|
|
72
|
+
}>;
|
|
73
|
+
}>;
|
|
74
|
+
refundTotal: "Refund total";
|
|
75
|
+
}>;
|
|
76
|
+
/**
|
|
77
|
+
* An invoice to approve: the items card with its totals, `Decline` and `Approve` (and
|
|
78
|
+
* `Request changes` when a row has an editable quantity). Returns an `interaction` for
|
|
79
|
+
* `sess.sessions.create({ interaction })`. Sess takes no payment: approval is the person's
|
|
80
|
+
* decision and its signed receipt; collecting the money stays with your payment processor.
|
|
81
|
+
*/
|
|
82
|
+
export declare function invoice(input: BillInput): InteractiveInteraction;
|
|
83
|
+
/** A receipt or order confirmation for the person to check, with one `Continue` button. */
|
|
84
|
+
export declare function receipt(input: BillInput): InteractiveInteraction;
|
|
85
|
+
/** A quote or estimate to accept: `Decline` and `Accept`. Put its validity in `record`. */
|
|
86
|
+
export declare function quote(input: BillInput): InteractiveInteraction;
|
|
87
|
+
/**
|
|
88
|
+
* A refund to approve, stated in positive amounts: every row is zero or more and the total,
|
|
89
|
+
* labelled `Refund total`, is never negative. A deduction (such as a restocking fee) is a
|
|
90
|
+
* negative line. With `select: 'many'` the person chooses the rows to refund.
|
|
91
|
+
*/
|
|
92
|
+
export declare function refund(input: RefundInput): InteractiveInteraction;
|
|
93
|
+
/**
|
|
94
|
+
* A purchase order to approve. A row with a `quantity` lets the person change it; the order
|
|
95
|
+
* always offers `Request changes` (a changed quantity is sent only with it, and your agent replies
|
|
96
|
+
* with a new revision and updated amounts) beside `Decline` and `Approve`.
|
|
97
|
+
*/
|
|
98
|
+
export declare function purchaseOrder(input: BillInput): InteractiveInteraction;
|
|
99
|
+
export {};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { buildItems, refuse, text, token, tooLong } from './items.js';
|
|
2
|
+
import { lintText } from './lint.js';
|
|
3
|
+
const LIMITS = Object.freeze({
|
|
4
|
+
title: 80,
|
|
5
|
+
description: 280,
|
|
6
|
+
recordKey: 40,
|
|
7
|
+
recordValue: 200,
|
|
8
|
+
recordFields: 50,
|
|
9
|
+
actions: 5,
|
|
10
|
+
actionLabel: 24,
|
|
11
|
+
});
|
|
12
|
+
const ACTION_ID = /^[a-z][a-z0-9_]{0,31}$/;
|
|
13
|
+
const INTENTS = ['submit', 'continue', 'approve', 'reject', 'request_change'];
|
|
14
|
+
const LOCALE = /^[A-Za-z]{2,3}(-[A-Za-z0-9]{1,8}){0,4}$/;
|
|
15
|
+
const COMPONENTS = '/interaction/source/components';
|
|
16
|
+
// Keys an ordinary object does not hold as plain data (the same set ask() refuses): copied with
|
|
17
|
+
// `fields[key] = value`, "__proto__" would run the prototype setter and the row would vanish.
|
|
18
|
+
const RESERVED_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
19
|
+
/**
|
|
20
|
+
* The words a builder puts on the page when you give none (proposed copy; `Request changes` is
|
|
21
|
+
* Sess's signed label for a change request). Every one can be replaced through the input.
|
|
22
|
+
*/
|
|
23
|
+
export const COMMERCE_DEFAULTS = Object.freeze({
|
|
24
|
+
titles: Object.freeze({
|
|
25
|
+
invoice: 'Approve this invoice?',
|
|
26
|
+
receipt: 'Your receipt',
|
|
27
|
+
quote: 'Accept this quote?',
|
|
28
|
+
refund: 'Approve the refund?',
|
|
29
|
+
purchaseOrder: 'Approve the order?',
|
|
30
|
+
}),
|
|
31
|
+
references: Object.freeze({
|
|
32
|
+
invoice: 'Invoice',
|
|
33
|
+
receipt: 'Receipt',
|
|
34
|
+
quote: 'Quote',
|
|
35
|
+
refund: 'Refund',
|
|
36
|
+
purchaseOrder: 'Purchase order',
|
|
37
|
+
}),
|
|
38
|
+
actions: Object.freeze({
|
|
39
|
+
approve: Object.freeze({ id: 'approve', label: 'Approve', intent: 'approve' }),
|
|
40
|
+
accept: Object.freeze({ id: 'accept', label: 'Accept', intent: 'approve' }),
|
|
41
|
+
continue: Object.freeze({ id: 'continue', label: 'Continue', intent: 'continue' }),
|
|
42
|
+
decline: Object.freeze({ id: 'decline', label: 'Decline', intent: 'reject' }),
|
|
43
|
+
change: Object.freeze({ id: 'change', label: 'Request changes', intent: 'request_change' }),
|
|
44
|
+
}),
|
|
45
|
+
refundTotal: 'Refund total',
|
|
46
|
+
});
|
|
47
|
+
const D = COMMERCE_DEFAULTS.actions;
|
|
48
|
+
const SHAPES = {
|
|
49
|
+
invoice: { name: 'invoice', accept: D.approve, decline: true, change: false },
|
|
50
|
+
receipt: { name: 'receipt', accept: D.continue, decline: false, change: false },
|
|
51
|
+
quote: { name: 'quote', accept: D.accept, decline: true, change: false },
|
|
52
|
+
refund: { name: 'refund', accept: D.approve, decline: true, change: false },
|
|
53
|
+
purchaseOrder: { name: 'order', accept: D.approve, decline: true, change: true },
|
|
54
|
+
};
|
|
55
|
+
function recordComponent(kind, input, at) {
|
|
56
|
+
const fields = {};
|
|
57
|
+
if (input.reference !== undefined)
|
|
58
|
+
fields[COMMERCE_DEFAULTS.references[kind]] = text(input.reference, `${at}/fields/${token(COMMERCE_DEFAULTS.references[kind])}`, LIMITS.recordValue);
|
|
59
|
+
const extra = input.record ?? {};
|
|
60
|
+
if (extra === null || typeof extra !== 'object' || Array.isArray(extra))
|
|
61
|
+
refuse(`${at}/fields`, 'must be object');
|
|
62
|
+
for (const [key, value] of Object.entries(extra)) {
|
|
63
|
+
const p = `${at}/fields/${token(key)}`;
|
|
64
|
+
const keyLength = [...key].length;
|
|
65
|
+
if (keyLength > LIMITS.recordKey)
|
|
66
|
+
tooLong(p, LIMITS.recordKey, keyLength);
|
|
67
|
+
if (RESERVED_KEYS.has(key))
|
|
68
|
+
refuse(p, 'is a reserved name; give the fact another name');
|
|
69
|
+
if (Object.hasOwn(fields, key))
|
|
70
|
+
refuse(p, 'repeats the reference row; give the reference once');
|
|
71
|
+
if (typeof value === 'string') {
|
|
72
|
+
const length = [...value].length;
|
|
73
|
+
if (length > LIMITS.recordValue)
|
|
74
|
+
tooLong(p, LIMITS.recordValue, length);
|
|
75
|
+
if (!value.isWellFormed())
|
|
76
|
+
refuse(p, 'must be well-formed Unicode');
|
|
77
|
+
}
|
|
78
|
+
else if (!(value === null ||
|
|
79
|
+
typeof value === 'boolean' ||
|
|
80
|
+
(typeof value === 'number' && Number.isFinite(value))))
|
|
81
|
+
refuse(p, 'must be a string, number, boolean or null');
|
|
82
|
+
fields[key] = value;
|
|
83
|
+
}
|
|
84
|
+
const count = Object.keys(fields).length;
|
|
85
|
+
if (count > LIMITS.recordFields)
|
|
86
|
+
refuse(`${at}/fields`, `must NOT have more than ${LIMITS.recordFields} properties`);
|
|
87
|
+
return count ? { type: 'record', fields } : undefined;
|
|
88
|
+
}
|
|
89
|
+
function checkActions(actions, editable, editableAt) {
|
|
90
|
+
const at = '/interaction/actions';
|
|
91
|
+
if (!Array.isArray(actions) || actions.length < 1 || actions.length > LIMITS.actions)
|
|
92
|
+
refuse(at, `must have 1–${LIMITS.actions} actions`);
|
|
93
|
+
const ids = new Set();
|
|
94
|
+
const out = actions.map((a, i) => {
|
|
95
|
+
const p = `${at}/${i}`;
|
|
96
|
+
if (a === null || typeof a !== 'object')
|
|
97
|
+
return refuse(p, 'must be object');
|
|
98
|
+
if (typeof a.id !== 'string' || !ACTION_ID.test(a.id))
|
|
99
|
+
refuse(`${p}/id`, `must match pattern "${ACTION_ID.source}"`);
|
|
100
|
+
if (ids.has(a.id))
|
|
101
|
+
refuse(at, 'action ids must be unique');
|
|
102
|
+
ids.add(a.id);
|
|
103
|
+
const label = text(a.label, `${p}/label`, LIMITS.actionLabel);
|
|
104
|
+
if (a.intent !== undefined && !INTENTS.includes(a.intent))
|
|
105
|
+
refuse(`${p}/intent`, `must be one of ${INTENTS.join(', ')}`);
|
|
106
|
+
return a.intent === undefined ? { id: a.id, label } : { id: a.id, label, intent: a.intent };
|
|
107
|
+
});
|
|
108
|
+
// Sess refuses editable quantities without a way to send the edit (signed rule, 2026-10-23).
|
|
109
|
+
if (editable && !out.some((a) => a.intent === 'request_change'))
|
|
110
|
+
refuse(`${editableAt}/editable`, 'needs an action with intent request_change in interaction.actions, such as "Request changes", so the person can send a changed quantity');
|
|
111
|
+
return out;
|
|
112
|
+
}
|
|
113
|
+
function bill(kind, input, adjust) {
|
|
114
|
+
if (input === null || typeof input !== 'object')
|
|
115
|
+
return refuse('/interaction', 'must be object');
|
|
116
|
+
const shape = SHAPES[kind];
|
|
117
|
+
const title = text(input.title ?? COMMERCE_DEFAULTS.titles[kind], '/interaction/title', LIMITS.title);
|
|
118
|
+
let description;
|
|
119
|
+
if (input.description !== undefined) {
|
|
120
|
+
if (typeof input.description !== 'string' || !input.description.isWellFormed())
|
|
121
|
+
refuse('/interaction/description', 'must be a well-formed string');
|
|
122
|
+
const length = [...input.description].length;
|
|
123
|
+
if (length > LIMITS.description)
|
|
124
|
+
tooLong('/interaction/description', LIMITS.description, length);
|
|
125
|
+
// A table drawn in the description reaches the person as pipes: the bill is the items card.
|
|
126
|
+
const table = lintText(input.description)[0];
|
|
127
|
+
if (table !== undefined)
|
|
128
|
+
refuse('/interaction/description', table.use === 'items'
|
|
129
|
+
? 'contains a Markdown table, which the person would see as pipes; put prices in the rows'
|
|
130
|
+
: 'contains a Markdown table, which the person would see as pipes; put the rows in record');
|
|
131
|
+
description = input.description;
|
|
132
|
+
}
|
|
133
|
+
if (input.locale !== undefined &&
|
|
134
|
+
(typeof input.locale !== 'string' || input.locale.length > 35 || !LOCALE.test(input.locale)))
|
|
135
|
+
refuse('/interaction/locale', 'is not a locale Sess can format; use a BCP 47 tag such as en-CA, or leave it out');
|
|
136
|
+
const record = recordComponent(kind, input, `${COMPONENTS}/0`);
|
|
137
|
+
const at = `${COMPONENTS}/${record ? 1 : 0}`;
|
|
138
|
+
// The answer's name, when the person answers (a choice of rows or a quantity), is the builder's.
|
|
139
|
+
const wantsName = input.select !== undefined ||
|
|
140
|
+
(Array.isArray(input.rows) &&
|
|
141
|
+
input.rows.some((r) => r !== null && typeof r === 'object' && r.quantity !== undefined));
|
|
142
|
+
const items = buildItems({
|
|
143
|
+
...input,
|
|
144
|
+
...(input.name === undefined && wantsName ? { name: shape.name } : {}),
|
|
145
|
+
}, at);
|
|
146
|
+
adjust?.(items, at);
|
|
147
|
+
const editable = items.editable !== undefined;
|
|
148
|
+
const actions = checkActions(input.actions ?? [
|
|
149
|
+
...(shape.decline ? [D.decline] : []),
|
|
150
|
+
...(shape.change || editable ? [D.change] : []),
|
|
151
|
+
shape.accept,
|
|
152
|
+
], editable, at);
|
|
153
|
+
return {
|
|
154
|
+
mode: 'interactive',
|
|
155
|
+
title,
|
|
156
|
+
...(description === undefined ? {} : { description }),
|
|
157
|
+
...(input.locale === undefined ? {} : { locale: input.locale }),
|
|
158
|
+
source: { kind: 'sess_surface', components: [...(record ? [record] : []), items] },
|
|
159
|
+
actions,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* An invoice to approve: the items card with its totals, `Decline` and `Approve` (and
|
|
164
|
+
* `Request changes` when a row has an editable quantity). Returns an `interaction` for
|
|
165
|
+
* `sess.sessions.create({ interaction })`. Sess takes no payment: approval is the person's
|
|
166
|
+
* decision and its signed receipt; collecting the money stays with your payment processor.
|
|
167
|
+
*/
|
|
168
|
+
export function invoice(input) {
|
|
169
|
+
return bill('invoice', input);
|
|
170
|
+
}
|
|
171
|
+
/** A receipt or order confirmation for the person to check, with one `Continue` button. */
|
|
172
|
+
export function receipt(input) {
|
|
173
|
+
return bill('receipt', input);
|
|
174
|
+
}
|
|
175
|
+
/** A quote or estimate to accept: `Decline` and `Accept`. Put its validity in `record`. */
|
|
176
|
+
export function quote(input) {
|
|
177
|
+
return bill('quote', input);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* A refund to approve, stated in positive amounts: every row is zero or more and the total,
|
|
181
|
+
* labelled `Refund total`, is never negative. A deduction (such as a restocking fee) is a
|
|
182
|
+
* negative line. With `select: 'many'` the person chooses the rows to refund.
|
|
183
|
+
*/
|
|
184
|
+
export function refund(input) {
|
|
185
|
+
if (input === null || typeof input !== 'object')
|
|
186
|
+
return refuse('/interaction', 'must be object');
|
|
187
|
+
if (input.payments !== undefined)
|
|
188
|
+
refuse('/interaction', 'is a refund, which has no payments; state what is refunded');
|
|
189
|
+
return bill('refund', {
|
|
190
|
+
...input,
|
|
191
|
+
labels: { ...input.labels, total: input.labels?.total ?? COMMERCE_DEFAULTS.refundTotal },
|
|
192
|
+
}, (items, at) => {
|
|
193
|
+
for (const [i, row] of items.rows.entries())
|
|
194
|
+
if (row.amount !== null && row.amount < 0)
|
|
195
|
+
refuse(`${at}/rows/${i}/amount`, 'is negative; a refund states what is refunded as a positive amount (a deduction is a negative line)');
|
|
196
|
+
const total = items.totals?.find((t) => t.role === 'total');
|
|
197
|
+
if (total !== undefined && total.amount < 0)
|
|
198
|
+
refuse(`${at}/totals/${items.totals.indexOf(total)}/amount`, 'is a negative refund total; a refund total is zero or more');
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* A purchase order to approve. A row with a `quantity` lets the person change it; the order
|
|
203
|
+
* always offers `Request changes` (a changed quantity is sent only with it, and your agent replies
|
|
204
|
+
* with a new revision and updated amounts) beside `Decline` and `Approve`.
|
|
205
|
+
*/
|
|
206
|
+
export function purchaseOrder(input) {
|
|
207
|
+
return bill('purchaseOrder', input);
|
|
208
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Every ISO 4217 code Sess accepts and its minor-unit exponent (JPY 0, USD 2, BHD 3, CLF 4). */
|
|
2
|
+
export declare const CURRENCY_MINOR_UNITS: ReadonlyMap<string, 0 | 2 | 3 | 4>;
|
|
3
|
+
/** The minor-unit exponent of a currency Sess accepts, else undefined. */
|
|
4
|
+
export declare function minorUnits(currency: string): 0 | 2 | 3 | 4 | undefined;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// ISO 4217 minor units: the currencies an items component may state and the exponent of each
|
|
2
|
+
// one's minor unit. A copy of the Sess runtime's table (packages/core/src/currency.ts, transcribed
|
|
3
|
+
// by Sess from ISO 4217 List One, "Minor unit" column). Codes with no minor unit (XAU, XDR, XXX …)
|
|
4
|
+
// are not listed and are refused, as Sess refuses them. tests/unit/commerce-contract.test.ts pins
|
|
5
|
+
// this table to the runtime's, extracted at a recorded runtime commit.
|
|
6
|
+
const BY_EXPONENT = [
|
|
7
|
+
[0, 'BIF CLP DJF GNF ISK JPY KMF KRW PYG RWF UGX UYI VND VUV XAF XOF XPF'],
|
|
8
|
+
[
|
|
9
|
+
2,
|
|
10
|
+
'AED AFN ALL AMD ANG AOA ARS AUD AWG AZN BAM BBD BDT BGN BMD BND BOB BOV BRL BSD BTN BWP BYN BZD ' +
|
|
11
|
+
'CAD CDF CHE CHF CHW CNY COP COU CRC CUP CVE CZK DKK DOP DZD EGP ERN ETB EUR FJD FKP GBP GEL GHS ' +
|
|
12
|
+
'GIP GMD GTQ GYD HKD HNL HTG HUF IDR ILS INR IRR JMD KES KGS KHR KPW KYD KZT LAK LBP LKR LRD LSL ' +
|
|
13
|
+
'MAD MDL MGA MKD MMK MNT MOP MRU MUR MVR MWK MXN MXV MYR MZN NAD NGN NIO NOK NPR NZD PAB PEN PGK ' +
|
|
14
|
+
'PHP PKR PLN QAR RON RSD RUB SAR SBD SCR SDG SEK SGD SHP SLE SLL SOS SRD SSP STN SVC SYP SZL THB ' +
|
|
15
|
+
'TJS TMT TOP TRY TTD TWD TZS UAH USD USN UYU UZS VED VES WST XCD XCG YER ZAR ZMW ZWG ZWL',
|
|
16
|
+
],
|
|
17
|
+
[3, 'BHD IQD JOD KWD LYD OMR TND'],
|
|
18
|
+
[4, 'CLF UYW'],
|
|
19
|
+
];
|
|
20
|
+
/** Every ISO 4217 code Sess accepts and its minor-unit exponent (JPY 0, USD 2, BHD 3, CLF 4). */
|
|
21
|
+
export const CURRENCY_MINOR_UNITS = new Map(BY_EXPONENT.flatMap(([exponent, codes]) => codes.split(' ').map((code) => [code, exponent])));
|
|
22
|
+
/** The minor-unit exponent of a currency Sess accepts, else undefined. */
|
|
23
|
+
export function minorUnits(currency) {
|
|
24
|
+
return CURRENCY_MINOR_UNITS.get(currency);
|
|
25
|
+
}
|