@sess.si/sdk 0.1.0-rc.7 → 0.1.0-rc.9
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 +91 -0
- package/NOTICE +1 -1
- package/README.md +105 -9
- package/dist/ask.d.ts +20 -9
- package/dist/ask.js +43 -9
- package/dist/cli/main.d.ts +0 -1
- package/dist/cli/main.js +0 -1
- package/dist/cli/verify.d.ts +1 -2
- package/dist/cli/verify.js +49 -4
- 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 +18 -1
- package/dist/errors.js +27 -2
- package/dist/generated/openapi.d.ts +496 -50
- 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 +46 -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 +4 -4
- package/dist/polling.js +64 -19
- 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 +3 -2
- package/dist/receipts/index.js +2 -2
- 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 +57 -0
- package/dist/receipts/renderers.js +153 -0
- package/dist/receipts/resource.d.ts +0 -1
- package/dist/receipts/resource.js +27 -1
- package/dist/receipts/verify.d.ts +24 -2
- package/dist/receipts/verify.js +63 -18
- package/dist/sessions.d.ts +0 -1
- package/dist/sessions.js +0 -1
- package/dist/transport.d.ts +0 -1
- package/dist/transport.js +51 -5
- package/dist/types.d.ts +132 -9
- 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 +3 -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/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 -636
- package/src/cli/main.ts +0 -8
- package/src/cli/verify.ts +0 -291
- package/src/client.ts +0 -55
- package/src/errors.ts +0 -96
- package/src/generated/openapi.ts +0 -8139
- package/src/index.ts +0 -5
- package/src/internal/decode.ts +0 -319
- package/src/internal/json.ts +0 -64
- package/src/internal/time.ts +0 -85
- package/src/polling.ts +0 -121
- 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 -27
- package/src/receipts/json.ts +0 -168
- package/src/receipts/key-cache.ts +0 -143
- package/src/receipts/resource.ts +0 -227
- package/src/receipts/verify.ts +0 -468
- package/src/sessions.ts +0 -238
- package/src/transport.ts +0 -533
- package/src/types.ts +0 -148
- package/src/webhook-resource.ts +0 -81
- package/src/webhooks/index.ts +0 -246
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,96 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.0-rc.9 — 2026-10-28 (prepared, unpublished)
|
|
4
|
+
|
|
5
|
+
- Commerce: bills as ordinary Surfaces, for Sess's `items` component. Sess takes no payment.
|
|
6
|
+
`money(amount, currency)` checks a whole number of minor units (cents for USD, yen for JPY, fils
|
|
7
|
+
for BHD) and an ISO 4217 code Sess accepts; it never rounds or converts. `items()` builds the
|
|
8
|
+
component with its subtotal, total and amount due computed exactly from the rows, lines and
|
|
9
|
+
payments, so Sess's arithmetic check passes. `invoice()`, `receipt()`, `quote()`, `refund()` and
|
|
10
|
+
`purchaseOrder()` return an `interaction` for `sessions.create()`: the card, the document's
|
|
11
|
+
reference in a record under a plain name, and the buttons Sess requires (Request changes
|
|
12
|
+
whenever a quantity is editable). `refund()` states positive amounts under "Refund total" and
|
|
13
|
+
never a negative total. `lintText()` finds Markdown pipe tables in text and says whether to send
|
|
14
|
+
an items component or a record. Limits match Sess's and reject, never truncate: row name 80,
|
|
15
|
+
detail 160, totals label 40, caption 200, rows 100, totals lines 8 (`ITEMS_LIMITS`); a refusal is
|
|
16
|
+
a `SessError` with code `INVALID_SCHEMA`, outcome `not_sent`, and the value's JSON pointer in
|
|
17
|
+
`field`. A `record` key `__proto__`, `constructor` or `prototype` is refused. New types
|
|
18
|
+
`ItemsComponent` and `ItemTotalRole` (`SurfaceComponent` includes items) and the Advanced
|
|
19
|
+
`locale` on an interactive interaction. Session reads now accept an items component, and a 400
|
|
20
|
+
for too many rows or totals lines carries Sess's sentence.
|
|
21
|
+
- Every request names the SDK in its `User-Agent` header: `sess-sdk/<version> node/<version>`.
|
|
22
|
+
The new client option `userAgent` puts a wrapping client's product tokens first, for example
|
|
23
|
+
`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
|
|
24
|
+
not product tokens separated by single spaces (at most 256 characters) is a `configuration`
|
|
25
|
+
error before anything is sent.
|
|
26
|
+
- A plan limit is a refusal, not an uncertain outcome. Sess answers a create over the workspace's
|
|
27
|
+
plan with HTTP 429 `PLAN_LIMIT_REACHED`, and nothing is created. The SDK now reports it as
|
|
28
|
+
`kind: 'api'`, `outcome: 'rejected'`, with `code`, `reason` (`monthly_allowance` or
|
|
29
|
+
`active_sessions`), `status: 429` and, for `monthly_allowance`, `retryAfterMs` from
|
|
30
|
+
`Retry-After` (time until the period resets); it is never retried. Before, it was
|
|
31
|
+
`unknown_outcome` ("may have succeeded"). Any other 429 (no code, or `RATE_LIMITED`) is unchanged:
|
|
32
|
+
transient, retried where retries are allowed, and uncertain for a write.
|
|
33
|
+
- The package ships compiled output only: no source maps (`*.js.map`, `*.d.ts.map`) or
|
|
34
|
+
`sourceMappingURL` comments, and no `src/` TypeScript sources (every export and types path is in
|
|
35
|
+
`dist/`). The generated wire types' JSDoc names Sess specifications instead of runtime-repository
|
|
36
|
+
document paths. Every published package's packed bytes now pass a hygiene check (no maps,
|
|
37
|
+
fixtures, non-public hosts, credential-shaped strings or internal references).
|
|
38
|
+
|
|
39
|
+
## 0.1.0-rc.8 — 2026-10-22 (prepared, unpublished)
|
|
40
|
+
|
|
41
|
+
- Link timing (Decision 0009 Amendment 10). On an interactive Sess link of 20 hours or less the
|
|
42
|
+
person may ask for more time, up to ten times, never past a fixed horizon. Session reads carry
|
|
43
|
+
`link_state` (`live`, `lapsed` or `expired`), `action_expires_horizon`, `extensions_used` and the
|
|
44
|
+
`extensions` history; the Session log (`listEvents()`) lists the same records as
|
|
45
|
+
`link_extensions`, beside the Events, whose shape is unchanged. New types `LinkState` and
|
|
46
|
+
`LinkExtension`. These fields are checked when present; a runtime without link timing omits them
|
|
47
|
+
and is read as before.
|
|
48
|
+
- `waitForResponse()` and `answer()` treat a lapsed link as still open: they keep waiting until the
|
|
49
|
+
horizon and end with `wait_ended` `LINK_EXPIRED` only once a read shows the link expired (two
|
|
50
|
+
seconds past its end on the runtime clock, or, when the end cannot be placed, such as a
|
|
51
|
+
revocation, a later read at least the grace after the first expired read; a short `intervalMs`
|
|
52
|
+
reads again sooner but never ends the wait inside the grace). A live read never ends the wait. Without `link_state` the
|
|
53
|
+
deadline stays final, as in rc.7.
|
|
54
|
+
- Contract snapshot from Sess runtime commit `2f8500e` (see `contract/contract-lock.json`). Besides link timing it carries what Sess master already
|
|
55
|
+
describes: the interactive text limits with `field`, `limit` and `length` on a length error,
|
|
56
|
+
`progress`, the receipt `format` and the renderer identities list. The generated wire types gain
|
|
57
|
+
them; the SDK's public types and behavior in this change are link timing only.
|
|
58
|
+
- Renderer identities (Decision 0009 Amendment 13). A receipt's `surface.renderer_version` now
|
|
59
|
+
verifies when it is an identity this release bundles (`sess-html-form-1`, `sess-html-form-2`;
|
|
60
|
+
`BUNDLED_RENDERER_IDENTITIES`) or one on the issuer's renderer list whose signature verifies
|
|
61
|
+
under the same trusted keys and issuer, so a later Sess page change needs no SDK update. Every
|
|
62
|
+
receipt that verified before still verifies, offline, with no list.
|
|
63
|
+
- `verifyResponse()` (and so `sess.ask()`'s `answer()`) fetch the list from the API origin
|
|
64
|
+
(`/.well-known/sess-renderer-identities.json`) only for an identity this release does not
|
|
65
|
+
bundle. `verifyDecisionReceipt` takes it as `rendererIdentities`; `verifyRendererIdentities`
|
|
66
|
+
verifies a list on its own. A forged, unsigned, re-typed, foreign or malformed list fails with
|
|
67
|
+
`INVALID_RENDERER_LIST`; an identity on no verified list fails with `UNSUPPORTED_RENDERER`, as
|
|
68
|
+
before. New types `RendererIdentitiesDocument`, `RendererIdentity` and `RendererList`.
|
|
69
|
+
`ReceiptClaims`' `surface.renderer_version` is now `string`.
|
|
70
|
+
- Renderer list editions. A list carries a signed `seq` (its edition, higher in every later
|
|
71
|
+
published edition) and `iat` (when that copy was signed); `verifyRendererIdentities` returns
|
|
72
|
+
`{ seq, iat, identities }`. `newerRendererList` orders two authentic lists by `seq`, with
|
|
73
|
+
containment as the cross-check, and refuses lists that disagree (`INVALID_RENDERER_LIST`);
|
|
74
|
+
`BUNDLED_RENDERER_LIST` is the bundled edition 1, and a verified list must agree with it. An
|
|
75
|
+
older list proves the identities it holds, never their absence: an identity it does not hold is
|
|
76
|
+
`UNSUPPORTED_RENDERER`, never accepted by fallback. Each online verification fetches the list
|
|
77
|
+
afresh (the endpoint is served `no-store`); nothing is cached.
|
|
78
|
+
- `sess verify --renderers <file>`: with the issuer's signed list (verified under `--keys` and
|
|
79
|
+
`--issuer`; a list that does not verify exits 2), the bundle's renderer identity must be known
|
|
80
|
+
or listed (otherwise invalid, exit 1). Without it, bundle verification is unchanged.
|
|
81
|
+
- The receipt-v1 specification copy is from Sess commit `a60ca69` (§10, renderer identities with
|
|
82
|
+
`seq` and `iat`).
|
|
83
|
+
- Sess's length limits, in Unicode code points and never truncated: title 80, description 280,
|
|
84
|
+
heading 60, field and option labels 60, field description 160, action label 24, record caption
|
|
85
|
+
200, record key 40 and string value 200, text 4,000; at most 5 actions. The types' JSDoc gives each field its
|
|
86
|
+
purpose, style and limit.
|
|
87
|
+
- `sess.ask()` checks them before anything is sent: `question` 80, `submit_label` 24, field
|
|
88
|
+
labels and options 60 (were 200).
|
|
89
|
+
- A length error carries `field` (a JSON pointer), `limit` and `length` on `SessError`, from
|
|
90
|
+
`sess.ask()` (`INVALID_QUESTION`) and from Sess (400 `INVALID_SCHEMA`), and its message is
|
|
91
|
+
Sess's own fix. The README and the quickstart show catching it, shortening the value and asking again.
|
|
92
|
+
Surfaces stored before these limits still read as before.
|
|
93
|
+
|
|
3
94
|
## 0.1.0-rc.7 — 2026-10-18 (prepared, unpublished)
|
|
4
95
|
|
|
5
96
|
Includes everything in the unpublished 0.1.0-rc.6 below, which is not published on its own.
|
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@next 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.
|
|
13
|
+
|
|
14
|
+
**Install** the SDK in your own server project:
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
```sh
|
|
17
|
+
npm install --save-exact @sess.si/sdk@next
|
|
18
|
+
```
|
|
18
19
|
|
|
19
20
|
## Ask a person
|
|
20
21
|
|
|
@@ -55,11 +56,106 @@ 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
|
+
## Keep it short
|
|
60
|
+
|
|
61
|
+
A person reads the page on a phone, so Sess keeps every piece of it short. Lengths count
|
|
62
|
+
characters (Unicode code points), and Sess never truncates:
|
|
63
|
+
|
|
64
|
+
| What | Style | At most |
|
|
65
|
+
| --------------------------- | ------------------------------ | -------- |
|
|
66
|
+
| Title (`question`) | A question or a task, about 40 | 80 |
|
|
67
|
+
| Button (`submit_label`) | A verb, 1–3 words | 24 |
|
|
68
|
+
| Field label, option | Short | 60 |
|
|
69
|
+
| Help (field `description`) | One hint | 160 |
|
|
70
|
+
| Description under the title | One or two sentences | 280 |
|
|
71
|
+
| Heading | Short | 60 |
|
|
72
|
+
| Record caption | A few words | 200 |
|
|
73
|
+
| Record key / string value | As written | 40 / 200 |
|
|
74
|
+
| Text (`details`) | Plain text | 4,000 |
|
|
75
|
+
|
|
76
|
+
There are at most 5 buttons. A value over its limit fails with a `SessError` that names it:
|
|
77
|
+
`field` is a JSON pointer such as `/question`, `limit` is the most it may have and `length` is
|
|
78
|
+
what it has. The message says how to fix it: "The title can be at most 80 characters. Keep it
|
|
79
|
+
to a short heading, about 40." for the title, and for anything else, for example
|
|
80
|
+
"/fields/0/label is 72 characters; the limit is 60. Shorten it to at most 60 characters." Nothing
|
|
81
|
+
was created (`outcome` is `not_sent` or `rejected`), so shorten the value and ask again:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { Sess, SessError } from '@sess.si/sdk';
|
|
85
|
+
declare function shorten(text: string, max: number): Promise<string>; // e.g. your model rewrites it
|
|
86
|
+
|
|
87
|
+
const sess = new Sess({ apiKey: process.env.SESS_API_KEY });
|
|
88
|
+
const fields = [{ name: 'approved', label: 'Approve it', type: 'boolean' }] as const;
|
|
89
|
+
async function askShort(question: string) {
|
|
90
|
+
try {
|
|
91
|
+
return await sess.ask({ question, fields });
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (!(error instanceof SessError) || error.field !== '/question' || error.limit === undefined)
|
|
94
|
+
throw error;
|
|
95
|
+
return sess.ask({ question: await shorten(question, error.limit), fields });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
58
100
|
**Release status:** every SDK release so far is a `0.1.0` release candidate, served under the `next`
|
|
59
101
|
dist-tag. There is no stable release yet: do not install the bare name, whose `latest` tag points at a
|
|
60
102
|
deprecated `0.0.0-stage` placeholder. The [changelog](CHANGELOG.md) describes each version;
|
|
61
103
|
`npm view @sess.si/sdk dist-tags` shows what the registry serves now.
|
|
62
104
|
|
|
105
|
+
## Commerce
|
|
106
|
+
|
|
107
|
+
Sess takes no payment: the person approves a bill on a Sess page, and moving the money stays with
|
|
108
|
+
you and your payment processor.
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import { Sess, invoice } from '@sess.si/sdk';
|
|
112
|
+
const sess = new Sess({ apiKey: process.env.SESS_API_KEY });
|
|
113
|
+
const created = await sess.sessions.create({
|
|
114
|
+
interaction: invoice({
|
|
115
|
+
currency: 'CAD', // whole cents: 420000 is $4,200.00
|
|
116
|
+
reference: 'INV-2041',
|
|
117
|
+
rows: [{ name: 'Design retainer, October', amount: 420000 }],
|
|
118
|
+
lines: [{ label: 'GST 5%', amount: 21000, role: 'tax' }],
|
|
119
|
+
}),
|
|
120
|
+
});
|
|
121
|
+
console.log(`Send this Sess link to the person: ${created.data.human_url}`);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Three things you will meet first:
|
|
125
|
+
|
|
126
|
+
- **Short rows.** A row name has at most 80 characters and its detail at most 160. A longer value
|
|
127
|
+
is refused, never trimmed: the `SessError` names it by its pointer, such as
|
|
128
|
+
`/interaction/source/components/1/rows/0/name`, with `limit` and `length`.
|
|
129
|
+
- **Whole minor units.** Amounts are integers in the currency's smallest unit: cents for USD, yen
|
|
130
|
+
for JPY, fils for BHD. `money(1250, 'USD')` is $12.50; `money(12.5, 'USD')` throws, because Sess
|
|
131
|
+
never rounds or converts.
|
|
132
|
+
- **Exact totals.** The builders compute the subtotal, total and amount due from your rows and
|
|
133
|
+
lines. An items component you write by hand whose subtotal is not the sum of its rows is refused
|
|
134
|
+
with HTTP 400:
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{
|
|
138
|
+
"error": {
|
|
139
|
+
"code": "INVALID_SCHEMA",
|
|
140
|
+
"field": "/interaction/source/components/0/totals/0/amount",
|
|
141
|
+
"expected": 441250,
|
|
142
|
+
"actual": 451248
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
`invoice()`, `receipt()`, `quote()`, `refund()` and `purchaseOrder()` each return an ordinary
|
|
148
|
+
interactive Surface for `sess.sessions.create({ interaction })`: the bill as an `items` card, the
|
|
149
|
+
document's `reference` under a plain name, and the buttons the person needs (Approve and Decline;
|
|
150
|
+
Continue on a receipt; Accept on a quote). `refund()` states positive amounts under "Refund total".
|
|
151
|
+
A row `quantity` lets the person change it and adds a Request changes button; your agent replies
|
|
152
|
+
with a new revision and updated amounts. `items()` builds just the card, and `lintText()` finds a
|
|
153
|
+
Markdown table in text, which the person would see as pipes. See the
|
|
154
|
+
[API reference](docs/api.md#commerce).
|
|
155
|
+
|
|
156
|
+
What Sess does not do: take or move payment, convert currencies, compute tax or prices, show your
|
|
157
|
+
logo or branding, or let another site frame the page (`frame-ancestors 'none'`).
|
|
158
|
+
|
|
63
159
|
## Advanced: the full Surface API
|
|
64
160
|
|
|
65
161
|
<!-- example:quickstart -->
|
package/dist/ask.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { InteractiveInteraction, RequestOptions } from './types.js';
|
|
|
4
4
|
interface AskFieldBase {
|
|
5
5
|
/** Key of this field in the answer: `^[a-z][a-z0-9_]{0,63}$`. */
|
|
6
6
|
readonly name: string;
|
|
7
|
-
/**
|
|
7
|
+
/** What the field asks for: short, a few words; at most 60. Example: `Refund amount` */
|
|
8
8
|
readonly label: string;
|
|
9
9
|
/** Default `true`, except boolean fields (default `false`). */
|
|
10
10
|
readonly required?: boolean;
|
|
@@ -28,20 +28,29 @@ export type AskField = (AskFieldBase & {
|
|
|
28
28
|
readonly default?: boolean;
|
|
29
29
|
}) | (AskFieldBase & {
|
|
30
30
|
readonly type: 'choice';
|
|
31
|
+
/** 1–100 choices. The words shown for one choice: short; at most 60. Example: `Next Monday` */
|
|
31
32
|
readonly options: readonly [string, ...string[]];
|
|
32
33
|
readonly default?: string;
|
|
33
34
|
}) | (AskFieldBase & {
|
|
34
35
|
readonly type: 'multi_choice';
|
|
36
|
+
/** 1–100 choices. The words shown for one choice: short; at most 60. Example: `Next Monday` */
|
|
35
37
|
readonly options: readonly [string, ...string[]];
|
|
36
38
|
readonly default?: readonly string[];
|
|
37
39
|
});
|
|
38
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* A question plus typed fields: the same shape as the MCP `sess_ask` tool input. Lengths are in
|
|
42
|
+
* Unicode code points and are never truncated: a value over its limit throws a `SessError` whose
|
|
43
|
+
* `field`, `limit` and `length` say which value to shorten and to what.
|
|
44
|
+
*/
|
|
39
45
|
export interface AskInput<F extends readonly AskField[] = readonly AskField[]> {
|
|
40
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* The page's heading: a question or a task, about 40 characters; at most 80.
|
|
48
|
+
* Examples: `Approve the refund?`, `Pick a delivery date`
|
|
49
|
+
*/
|
|
41
50
|
readonly question: string;
|
|
42
|
-
/** Optional plain-text context shown above the fields,
|
|
51
|
+
/** Optional plain-text context shown above the fields, at most 4,000 characters. */
|
|
43
52
|
readonly details?: string;
|
|
44
|
-
/**
|
|
53
|
+
/** A button: a verb, 1–3 words; at most 24. Default `Send`. Examples: `Approve`, `Send refund` */
|
|
45
54
|
readonly submit_label?: string;
|
|
46
55
|
/** One to twelve fields with unique names. */
|
|
47
56
|
readonly fields: F;
|
|
@@ -103,9 +112,12 @@ export interface AskHandle<T> {
|
|
|
103
112
|
/** The Surface revision of the question, for recovery through the advanced API. */
|
|
104
113
|
readonly revision: number;
|
|
105
114
|
/**
|
|
106
|
-
* When the link stops taking answers (`action_expires_at`, ISO 8601).
|
|
107
|
-
*
|
|
108
|
-
*
|
|
115
|
+
* When the link stops taking answers (`action_expires_at`, ISO 8601), as created. On a link of
|
|
116
|
+
* 20 hours or less the person may ask for more time, which moves it forward up to a fixed
|
|
117
|
+
* horizon; while the link is lapsed (past it, still extendable) `answer()` keeps waiting. An
|
|
118
|
+
* answer accepted before the end is still returned after it; with none, `answer()` ends with
|
|
119
|
+
* `wait_ended` code `LINK_EXPIRED` once the link has expired. Null only from a runtime that
|
|
120
|
+
* does not report it.
|
|
109
121
|
*/
|
|
110
122
|
readonly expiresAt: string | null;
|
|
111
123
|
/**
|
|
@@ -147,4 +159,3 @@ export declare function checkAnswer(fields: readonly CompiledField[], data: unkn
|
|
|
147
159
|
/** Validates locally, creates once (the link is available before any wait) and returns the handle. */
|
|
148
160
|
export declare function ask<T>(sessions: Sessions, receipts: ReceiptResource, input: unknown, options?: AskOptions): Promise<AskHandle<T>>;
|
|
149
161
|
export {};
|
|
150
|
-
//# sourceMappingURL=ask.d.ts.map
|
package/dist/ask.js
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { inspect } from 'node:util';
|
|
3
|
-
import { SessError } from './errors.js';
|
|
3
|
+
import { SessError, lengthMessage } from './errors.js';
|
|
4
4
|
import { canonicalJson } from './receipts/json.js';
|
|
5
5
|
import { isInteractiveSession } from './types.js';
|
|
6
6
|
import { withSignal } from './internal/time.js';
|
|
7
7
|
/** The runtime byte limit for one stored interaction. */
|
|
8
8
|
const SURFACE_LIMIT_BYTES = 131_072;
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Sess's limits, in Unicode code points (the runtime checks the same numbers; nothing is ever
|
|
11
|
+
* truncated): the question (title) 80, details (a text component) 4,000, the submit button 24,
|
|
12
|
+
* field labels and options 60.
|
|
13
|
+
*/
|
|
14
|
+
const LIMITS = Object.freeze({
|
|
15
|
+
fields: 12,
|
|
16
|
+
options: 100,
|
|
17
|
+
depth: 8,
|
|
18
|
+
textMax: 4000,
|
|
19
|
+
question: 80,
|
|
20
|
+
details: 4000,
|
|
21
|
+
submitLabel: 24,
|
|
22
|
+
label: 60,
|
|
23
|
+
option: 60,
|
|
24
|
+
});
|
|
10
25
|
const TYPES = ['text', 'number', 'integer', 'boolean', 'choice', 'multi_choice'];
|
|
11
26
|
const FIELD_NAME = /^[a-z][a-z0-9_]{0,63}$/;
|
|
12
27
|
const RESERVED = new Set(['__proto__', 'constructor', 'prototype']);
|
|
@@ -21,6 +36,24 @@ function invalid(path, problem) {
|
|
|
21
36
|
outcome: 'not_sent',
|
|
22
37
|
});
|
|
23
38
|
}
|
|
39
|
+
/** `fields[0].label` → `/fields/0/label`: the JSON pointer of an input path. */
|
|
40
|
+
function pointer(path) {
|
|
41
|
+
return `/${path
|
|
42
|
+
.replace(/\[(\d+)\]/g, '.$1')
|
|
43
|
+
.split('.')
|
|
44
|
+
.join('/')}`;
|
|
45
|
+
}
|
|
46
|
+
function tooLong(path, limit, length) {
|
|
47
|
+
// The value itself never enters the message: only its pointer, the limit and its length, in
|
|
48
|
+
// Sess's own sentences.
|
|
49
|
+
throw new SessError('configuration', lengthMessage(pointer(path), limit, length), {
|
|
50
|
+
code: 'INVALID_QUESTION',
|
|
51
|
+
outcome: 'not_sent',
|
|
52
|
+
field: pointer(path),
|
|
53
|
+
limit,
|
|
54
|
+
length,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
24
57
|
function safeKey(key) {
|
|
25
58
|
return /^[A-Za-z0-9_]{1,40}$/.test(key) ? key : '?';
|
|
26
59
|
}
|
|
@@ -88,7 +121,9 @@ function text(value, path, max) {
|
|
|
88
121
|
if (!value.isWellFormed())
|
|
89
122
|
invalid(path, 'must be well-formed Unicode');
|
|
90
123
|
const length = codePoints(value);
|
|
91
|
-
if (length
|
|
124
|
+
if (length > max)
|
|
125
|
+
tooLong(path, max, length);
|
|
126
|
+
if (length < 1)
|
|
92
127
|
invalid(path, `must be 1–${max} characters`);
|
|
93
128
|
if (!/\S/.test(value))
|
|
94
129
|
invalid(path, 'must not be blank');
|
|
@@ -133,7 +168,7 @@ function compileField(raw, path, names) {
|
|
|
133
168
|
if (names.has(name))
|
|
134
169
|
invalid(`${path}.name`, 'duplicates another field name');
|
|
135
170
|
names.add(name);
|
|
136
|
-
const label = text(f.label, `${path}.label`,
|
|
171
|
+
const label = text(f.label, `${path}.label`, LIMITS.label);
|
|
137
172
|
const type = f.type;
|
|
138
173
|
if (!TYPES.includes(type))
|
|
139
174
|
invalid(`${path}.type`, `must be one of ${TYPES.join(', ')}`);
|
|
@@ -179,7 +214,7 @@ function compileField(raw, path, names) {
|
|
|
179
214
|
const options = f.options;
|
|
180
215
|
if (!Array.isArray(options) || options.length < 1 || options.length > LIMITS.options)
|
|
181
216
|
invalid(`${path}.options`, `must list 1–${LIMITS.options} options`);
|
|
182
|
-
const values = options.map((option, i) => text(option, `${path}.options[${i}]`,
|
|
217
|
+
const values = options.map((option, i) => text(option, `${path}.options[${i}]`, LIMITS.option));
|
|
183
218
|
if (new Set(values).size !== values.length)
|
|
184
219
|
invalid(`${path}.options`, 'must be unique');
|
|
185
220
|
compiled.options = Object.freeze([...values]);
|
|
@@ -216,9 +251,9 @@ export function compileAsk(input) {
|
|
|
216
251
|
!Number.isSafeInteger(expiresIn) ||
|
|
217
252
|
expiresIn < LINK_LIFETIME_FLOOR_SECONDS))
|
|
218
253
|
invalid('expires_in', `must be a whole number of seconds, at least ${LINK_LIFETIME_FLOOR_SECONDS}`);
|
|
219
|
-
const title = text(a.question, 'question',
|
|
220
|
-
const details = a.details === undefined ? undefined : text(a.details, 'details',
|
|
221
|
-
const submit = a.submit_label === undefined ? 'Send' : text(a.submit_label, 'submit_label',
|
|
254
|
+
const title = text(a.question, 'question', LIMITS.question);
|
|
255
|
+
const details = a.details === undefined ? undefined : text(a.details, 'details', LIMITS.details);
|
|
256
|
+
const submit = a.submit_label === undefined ? 'Send' : text(a.submit_label, 'submit_label', LIMITS.submitLabel);
|
|
222
257
|
const fields = a.fields;
|
|
223
258
|
if (!Array.isArray(fields) || fields.length < 1 || fields.length > LIMITS.fields)
|
|
224
259
|
invalid('fields', `must contain 1–${LIMITS.fields} fields`);
|
|
@@ -462,4 +497,3 @@ export async function ask(sessions, receipts, input, options = {}) {
|
|
|
462
497
|
compiled,
|
|
463
498
|
});
|
|
464
499
|
}
|
|
465
|
-
//# sourceMappingURL=ask.js.map
|
package/dist/cli/main.d.ts
CHANGED
package/dist/cli/main.js
CHANGED
package/dist/cli/verify.d.ts
CHANGED
|
@@ -8,7 +8,6 @@ export interface CliIo {
|
|
|
8
8
|
stdout: (text: string) => void;
|
|
9
9
|
stderr: (text: string) => void;
|
|
10
10
|
}
|
|
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\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";
|
|
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
|
@@ -5,12 +5,14 @@
|
|
|
5
5
|
import { readFile, stat } from 'node:fs/promises';
|
|
6
6
|
import { parseArgs } from 'node:util';
|
|
7
7
|
import { verifyDecisionBundle, } from '../receipts/bundle.js';
|
|
8
|
-
import {
|
|
8
|
+
import { BUNDLED_RENDERER_IDENTITIES } from '../receipts/renderers.js';
|
|
9
|
+
import { validateKeySet, verifyRendererIdentities } from '../receipts/verify.js';
|
|
9
10
|
/** Exit codes: valid, invalid bundle, usage or file error. */
|
|
10
11
|
export const EXIT = Object.freeze({ valid: 0, invalid: 1, usage: 2 });
|
|
11
12
|
/** A bundle file larger than this is not read (the bundle bound itself is 1 MiB canonical). */
|
|
12
13
|
const MAX_BUNDLE_FILE_BYTES = 16 * 1024 * 1024;
|
|
13
14
|
const MAX_KEYS_FILE_BYTES = 1024 * 1024;
|
|
15
|
+
const MAX_RENDERERS_FILE_BYTES = 64 * 1024;
|
|
14
16
|
export const USAGE = `Usage: sess verify <bundle.json> --issuer <url> --keys <jwks.json> [options]
|
|
15
17
|
|
|
16
18
|
Checks a Sess decision bundle on this computer against the issuer and keys you trust.
|
|
@@ -28,6 +30,11 @@ Expected context (optional; only what you pass is checked):
|
|
|
28
30
|
--revision <n> the Surface revision
|
|
29
31
|
--action <id> the action ID
|
|
30
32
|
|
|
33
|
+
Renderer identity (optional):
|
|
34
|
+
--renderers <file> the issuer's signed renderer list you obtained yourself
|
|
35
|
+
(<issuer>/.well-known/sess-renderer-identities.json); also checks that the
|
|
36
|
+
receipt's renderer identity is one this release knows or one on that list
|
|
37
|
+
|
|
31
38
|
Other:
|
|
32
39
|
--now <time> check at this RFC 3339 time instead of now
|
|
33
40
|
--json print the full result as JSON
|
|
@@ -47,6 +54,7 @@ const STRING_OPTIONS = [
|
|
|
47
54
|
'revision',
|
|
48
55
|
'action',
|
|
49
56
|
'now',
|
|
57
|
+
'renderers',
|
|
50
58
|
];
|
|
51
59
|
const RFC3339 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
52
60
|
/** Escapes characters a terminal could interpret (controls, bidi overrides, line separators). */
|
|
@@ -167,6 +175,7 @@ function parse(argv) {
|
|
|
167
175
|
file,
|
|
168
176
|
issuer,
|
|
169
177
|
keysPath,
|
|
178
|
+
renderersPath: str('renderers'),
|
|
170
179
|
context: Object.keys(context).length > 0 ? context : undefined,
|
|
171
180
|
now,
|
|
172
181
|
json: values.json === true,
|
|
@@ -190,8 +199,9 @@ const REASON_TEXT = {
|
|
|
190
199
|
surface_mismatch: 'the disclosed Surface is not the one the receipt signed',
|
|
191
200
|
input_mismatch: 'the disclosed input is not the one the receipt signed',
|
|
192
201
|
context_mismatch: 'the decision is not the one you expected',
|
|
202
|
+
renderer: 'the receipt names a renderer identity that is neither known nor on the signed list',
|
|
193
203
|
};
|
|
194
|
-
function summary(r) {
|
|
204
|
+
function summary(r, renderer) {
|
|
195
205
|
const lines = [];
|
|
196
206
|
const row = (label, value) => lines.push(` ${label.padEnd(11)} ${value}`);
|
|
197
207
|
const context = r.context.status === 'mismatch'
|
|
@@ -212,12 +222,16 @@ function summary(r) {
|
|
|
212
222
|
row('Context', context);
|
|
213
223
|
row('Purpose', r.application_purpose);
|
|
214
224
|
row('Expires', safe(c.expires_at));
|
|
225
|
+
if (renderer)
|
|
226
|
+
row('Renderer', `${safe(c.surface.renderer_version)} (listed)`);
|
|
215
227
|
}
|
|
216
228
|
else {
|
|
217
229
|
lines.push(`Invalid decision bundle: ${r.reason}`);
|
|
218
230
|
lines.push(` ${REASON_TEXT[r.reason ?? ''] ?? ''}`);
|
|
219
231
|
row('Content', r.content);
|
|
220
232
|
row('Context', context);
|
|
233
|
+
if (renderer?.identity)
|
|
234
|
+
row('Renderer', `${safe(renderer.identity)} (${renderer.status})`);
|
|
221
235
|
}
|
|
222
236
|
row('Checked at', r.checked_at);
|
|
223
237
|
return `${lines.join('\n')}\n`;
|
|
@@ -250,6 +264,23 @@ export async function runCli(argv, io) {
|
|
|
250
264
|
catch {
|
|
251
265
|
throw new UsageError('the --keys file must be a JWK Set of public Ed25519 keys with unique kids (private keys are refused)');
|
|
252
266
|
}
|
|
267
|
+
// Decision 0009 Amendment 13: the issuer's signed renderer list, trusted only through its
|
|
268
|
+
// signature under the keys above.
|
|
269
|
+
let listed;
|
|
270
|
+
if (parsed.renderersPath !== undefined) {
|
|
271
|
+
const listJson = parseJson(await readBounded(parsed.renderersPath, MAX_RENDERERS_FILE_BYTES, 'the --renderers file'));
|
|
272
|
+
try {
|
|
273
|
+
if (!listJson.ok)
|
|
274
|
+
throw new Error('not JSON');
|
|
275
|
+
listed = (await verifyRendererIdentities(listJson.value, {
|
|
276
|
+
issuer: parsed.issuer,
|
|
277
|
+
keys: trustedKeys,
|
|
278
|
+
})).identities.map((i) => i.renderer_version);
|
|
279
|
+
}
|
|
280
|
+
catch {
|
|
281
|
+
throw new UsageError("the --renderers file must be the issuer's renderer list, signed with the keys you trust");
|
|
282
|
+
}
|
|
283
|
+
}
|
|
253
284
|
const bundleBytes = await readBounded(parsed.file, MAX_BUNDLE_FILE_BYTES, 'the bundle file');
|
|
254
285
|
const bundleJson = parseJson(bundleBytes);
|
|
255
286
|
let result;
|
|
@@ -265,7 +296,22 @@ export async function runCli(argv, io) {
|
|
|
265
296
|
catch {
|
|
266
297
|
throw new UsageError('invalid verification options');
|
|
267
298
|
}
|
|
268
|
-
|
|
299
|
+
let renderer;
|
|
300
|
+
if (listed !== undefined) {
|
|
301
|
+
const identity = result.receipt?.surface.renderer_version ?? null;
|
|
302
|
+
renderer =
|
|
303
|
+
identity === null
|
|
304
|
+
? { identity, status: 'not_checked' }
|
|
305
|
+
: {
|
|
306
|
+
identity,
|
|
307
|
+
status: BUNDLED_RENDERER_IDENTITIES.includes(identity) || listed.includes(identity)
|
|
308
|
+
? 'listed'
|
|
309
|
+
: 'unlisted',
|
|
310
|
+
};
|
|
311
|
+
if (renderer.status === 'unlisted')
|
|
312
|
+
result = { ...result, valid: false, reason: 'renderer' };
|
|
313
|
+
}
|
|
314
|
+
io.stdout(parsed.json ? safeJson(renderer ? { ...result, renderer } : result) : summary(result, renderer));
|
|
269
315
|
return result.valid ? EXIT.valid : EXIT.invalid;
|
|
270
316
|
}
|
|
271
317
|
catch (e) {
|
|
@@ -274,4 +320,3 @@ export async function runCli(argv, io) {
|
|
|
274
320
|
return EXIT.usage;
|
|
275
321
|
}
|
|
276
322
|
}
|
|
277
|
-
//# sourceMappingURL=verify.js.map
|
package/dist/client.d.ts
CHANGED
package/dist/client.js
CHANGED