@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/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,9 @@ export { SessError } from './errors.js';
|
|
|
3
3
|
export type { SessErrorKind, SessErrorDetails, WriteOutcome } from './errors.js';
|
|
4
4
|
export type { AskAnswer, AskAnswerOptions, AskField, AskHandle, AskInput, AskOptions } from './ask.js';
|
|
5
5
|
export * from './types.js';
|
|
6
|
-
|
|
6
|
+
export { ITEMS_DEFAULT_LABELS, ITEMS_LIMITS, items, money } from './commerce/items.js';
|
|
7
|
+
export type { Amount, ItemLineInput, ItemPaymentInput, ItemRowInput, ItemsInput, Money, } from './commerce/items.js';
|
|
8
|
+
export { COMMERCE_DEFAULTS, invoice, purchaseOrder, quote, receipt, refund } from './commerce/builders.js';
|
|
9
|
+
export type { BillInput, RefundInput } from './commerce/builders.js';
|
|
10
|
+
export { lintText } from './commerce/lint.js';
|
|
11
|
+
export type { TextLintFinding } from './commerce/lint.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { Sess } from './client.js';
|
|
2
2
|
export { SessError } from './errors.js';
|
|
3
3
|
export * from './types.js';
|
|
4
|
-
|
|
4
|
+
export { ITEMS_DEFAULT_LABELS, ITEMS_LIMITS, items, money } from './commerce/items.js';
|
|
5
|
+
export { COMMERCE_DEFAULTS, invoice, purchaseOrder, quote, receipt, refund } from './commerce/builders.js';
|
|
6
|
+
export { lintText } from './commerce/lint.js';
|
|
@@ -18,4 +18,3 @@ export declare function decodeWebhook(value: unknown): WebhookResponse;
|
|
|
18
18
|
export declare function decodeWebhookRotate(value: unknown): WebhookRotateResponse;
|
|
19
19
|
export declare function decodeDeliveries(value: unknown, expectedId: string): Deliveries;
|
|
20
20
|
export declare function decodeRedelivery(value: unknown, expectedEvent: string): RedeliverResponse;
|
|
21
|
-
//# sourceMappingURL=decode.d.ts.map
|
package/dist/internal/decode.js
CHANGED
|
@@ -68,7 +68,7 @@ function interaction(value, mode) {
|
|
|
68
68
|
protocol();
|
|
69
69
|
for (const item of array(source.components)) {
|
|
70
70
|
const c = object(item);
|
|
71
|
-
oneOf(c.type, ['heading', 'text', 'record', 'field']);
|
|
71
|
+
oneOf(c.type, ['heading', 'text', 'record', 'field', 'items']);
|
|
72
72
|
if (c.type === 'heading')
|
|
73
73
|
string(c.text, undefined, 200);
|
|
74
74
|
if (c.type === 'text')
|
|
@@ -80,6 +80,14 @@ function interaction(value, mode) {
|
|
|
80
80
|
string(c.label, undefined, 200);
|
|
81
81
|
oneOf(object(c.schema).type, ['string', 'number', 'integer', 'boolean', 'array']);
|
|
82
82
|
}
|
|
83
|
+
// Commerce: line items in one ISO 4217 currency (Sess checks rows and totals on create).
|
|
84
|
+
if (c.type === 'items') {
|
|
85
|
+
string(c.currency, /^[A-Z]{3}$/, 3);
|
|
86
|
+
if (!array(c.rows).length)
|
|
87
|
+
protocol();
|
|
88
|
+
if (c.totals !== undefined)
|
|
89
|
+
array(c.totals);
|
|
90
|
+
}
|
|
83
91
|
}
|
|
84
92
|
const seen = new Set();
|
|
85
93
|
for (const item of array(v.actions)) {
|
|
@@ -136,11 +144,44 @@ export function decodeCreate(value, allowInsecureLocalhost = false) {
|
|
|
136
144
|
export function isLoopback(host) {
|
|
137
145
|
return host === 'localhost' || host === '[::1]' || /^127\.(?:\d{1,3}\.){2}\d{1,3}$/.test(host);
|
|
138
146
|
}
|
|
147
|
+
/** One accepted extension of the Sess link (Decision 0009 Amendment 10), numbered in order. */
|
|
148
|
+
function linkExtension(value, number) {
|
|
149
|
+
const v = object(value);
|
|
150
|
+
if (integer(v.number) !== number)
|
|
151
|
+
protocol();
|
|
152
|
+
date(v.previous_action_expires_at);
|
|
153
|
+
date(v.action_expires_at);
|
|
154
|
+
if (typeof v.from_lapsed !== 'boolean')
|
|
155
|
+
protocol();
|
|
156
|
+
date(v.extended_at);
|
|
157
|
+
}
|
|
158
|
+
/** The extension history: at most ten records, numbered 1, 2, … in order. */
|
|
159
|
+
function linkExtensions(value) {
|
|
160
|
+
const items = array(value);
|
|
161
|
+
if (items.length > 10)
|
|
162
|
+
protocol();
|
|
163
|
+
items.forEach((item, i) => linkExtension(item, i + 1));
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* A Session read's link timing (Decision 0009 Amendment 10), checked when present. A runtime
|
|
167
|
+
* before link timing omits it; the wait then keeps its earlier rule (the deadline is final).
|
|
168
|
+
*/
|
|
169
|
+
function linkTiming(v) {
|
|
170
|
+
if (v.link_state !== undefined)
|
|
171
|
+
oneOf(v.link_state, ['live', 'lapsed', 'expired']);
|
|
172
|
+
if (v.action_expires_horizon !== undefined)
|
|
173
|
+
nullableDate(v.action_expires_horizon);
|
|
174
|
+
if (v.extensions_used !== undefined && integer(v.extensions_used, 0) > 10)
|
|
175
|
+
protocol();
|
|
176
|
+
if (v.extensions !== undefined)
|
|
177
|
+
linkExtensions(v.extensions);
|
|
178
|
+
}
|
|
139
179
|
export function decodeSession(value, expectedId) {
|
|
140
180
|
const v = object(value);
|
|
141
181
|
if (string(v.id, sessionPattern) !== expectedId)
|
|
142
182
|
protocol();
|
|
143
183
|
const rev = integer(v.revision);
|
|
184
|
+
linkTiming(v);
|
|
144
185
|
const mode = object(v.interaction).mode;
|
|
145
186
|
if (mode === 'display') {
|
|
146
187
|
interaction(v.interaction, 'display');
|
|
@@ -216,6 +257,10 @@ export function decodeEvents(value, expectedId) {
|
|
|
216
257
|
else if (actor !== 'owner')
|
|
217
258
|
protocol();
|
|
218
259
|
}
|
|
260
|
+
// Decision 0009 Amendment 10: the link's extensions are listed beside the Events (never as an
|
|
261
|
+
// Event type), only where the deployment enables them.
|
|
262
|
+
if (v.link_extensions !== undefined)
|
|
263
|
+
linkExtensions(v.link_extensions);
|
|
219
264
|
return value;
|
|
220
265
|
}
|
|
221
266
|
function endpoint(value) {
|
|
@@ -333,4 +378,3 @@ export function decodeRedelivery(value, expectedEvent) {
|
|
|
333
378
|
protocol();
|
|
334
379
|
return value;
|
|
335
380
|
}
|
|
336
|
-
//# sourceMappingURL=decode.js.map
|
package/dist/internal/json.d.ts
CHANGED
package/dist/internal/json.js
CHANGED
package/dist/internal/time.d.ts
CHANGED
|
@@ -8,4 +8,3 @@ export declare function abortError(signal: AbortSignal): SessError;
|
|
|
8
8
|
/** Enforce deadlines even when a custom fetch/provider fails to observe its signal. */
|
|
9
9
|
export declare function withSignal<T>(promise: Promise<T>, signal: AbortSignal): Promise<T>;
|
|
10
10
|
export declare function delay(ms: number, signal: AbortSignal): Promise<void>;
|
|
11
|
-
//# sourceMappingURL=time.d.ts.map
|
package/dist/internal/time.js
CHANGED
package/dist/polling.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { RequestOptions, Session, VersionedResult, WaitOptions, WaitResult } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Once a Session's link has
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* Once a Session's link has reached its end (its deadline, `action_expires_at`, or while the
|
|
4
|
+
* person can still extend it, its horizon), the wait reads it once more when the runtime clock is
|
|
5
|
+
* this far past that end, then ends: an answer accepted before the end is returned; otherwise the
|
|
6
|
+
* wait ends with `LINK_EXPIRED`. Two seconds covers the one-second
|
|
6
7
|
* resolution of the HTTP `Date` header plus an answer accepted just before the expiry whose write
|
|
7
8
|
* is still landing, and keeps the end prompt.
|
|
8
9
|
*/
|
|
9
10
|
export declare const LINK_EXPIRY_GRACE_MS = 2000;
|
|
10
11
|
export declare function waitForResponse(retrieve: (options: RequestOptions) => Promise<VersionedResult<Session>>, id: string, input: WaitOptions, clientOperationTimeoutMs: number): Promise<WaitResult>;
|
|
11
|
-
//# sourceMappingURL=polling.d.ts.map
|
package/dist/polling.js
CHANGED
|
@@ -2,21 +2,36 @@ import { SessError } from './errors.js';
|
|
|
2
2
|
import { abortError, boundedNumber, deadline, delay } from './internal/time.js';
|
|
3
3
|
import { isInteractiveSession } from './types.js';
|
|
4
4
|
/**
|
|
5
|
-
* Once a Session's link has
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Once a Session's link has reached its end (its deadline, `action_expires_at`, or while the
|
|
6
|
+
* person can still extend it, its horizon), the wait reads it once more when the runtime clock is
|
|
7
|
+
* this far past that end, then ends: an answer accepted before the end is returned; otherwise the
|
|
8
|
+
* wait ends with `LINK_EXPIRED`. Two seconds covers the one-second
|
|
8
9
|
* resolution of the HTTP `Date` header plus an answer accepted just before the expiry whose write
|
|
9
10
|
* is still landing, and keeps the end prompt.
|
|
10
11
|
*/
|
|
11
12
|
export const LINK_EXPIRY_GRACE_MS = 2000;
|
|
12
|
-
/**
|
|
13
|
-
function
|
|
14
|
-
const value = session.action_expires_at;
|
|
13
|
+
/** An RFC 3339 UTC instant in milliseconds since the epoch, when the value is a valid one. */
|
|
14
|
+
function instant(value) {
|
|
15
15
|
if (typeof value !== 'string' || !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/.test(value))
|
|
16
16
|
return undefined;
|
|
17
17
|
const ms = Date.parse(value);
|
|
18
18
|
return Number.isFinite(ms) ? ms : undefined;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* The link's state as read and the instant it ends for good as far as this read shows: its
|
|
22
|
+
* horizon while the person can still extend it (an extension left), else its deadline
|
|
23
|
+
* (`action_expires_at`). No state from a runtime before link timing (Decision 0009 Amendment 10).
|
|
24
|
+
*/
|
|
25
|
+
function linkEnd(session) {
|
|
26
|
+
const v = session;
|
|
27
|
+
const deadline = instant(v.action_expires_at);
|
|
28
|
+
const horizon = instant(v.action_expires_horizon);
|
|
29
|
+
const extendable = horizon !== undefined && typeof v.extensions_used === 'number' && v.extensions_used < 10;
|
|
30
|
+
return {
|
|
31
|
+
state: typeof v.link_state === 'string' ? v.link_state : undefined,
|
|
32
|
+
endsAt: extendable && deadline !== undefined ? Math.max(horizon, deadline) : deadline,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
20
35
|
export async function waitForResponse(retrieve, id, input, clientOperationTimeoutMs) {
|
|
21
36
|
if (!input || typeof input !== 'object')
|
|
22
37
|
throw new SessError('configuration', 'waitForResponse requires an exact revision.');
|
|
@@ -32,6 +47,13 @@ export async function waitForResponse(retrieve, id, input, clientOperationTimeou
|
|
|
32
47
|
const operationTimeoutMs = boundedNumber(options.operationTimeoutMs, clientOperationTimeoutMs, 'operationTimeoutMs');
|
|
33
48
|
const budget = deadline(timeoutMs, options.signal);
|
|
34
49
|
const expires = performance.now() + timeoutMs;
|
|
50
|
+
/**
|
|
51
|
+
* The first read in a row that showed the link expired with no answer at an instant the clocks
|
|
52
|
+
* cannot place past its end: its runtime clock, that clock's resolution, and whether the clock
|
|
53
|
+
* was the runtime's (HTTP Date) or this machine's. Such a read is final only once a later one,
|
|
54
|
+
* at least LINK_EXPIRY_GRACE_MS (plus the resolution) after it on the same clock, still shows it.
|
|
55
|
+
*/
|
|
56
|
+
let expiredSince;
|
|
35
57
|
const ended = (code, message) => new SessError('wait_ended', message, { code, sessionId: id, revision });
|
|
36
58
|
try {
|
|
37
59
|
for (;;) {
|
|
@@ -57,20 +79,44 @@ export async function waitForResponse(retrieve, id, input, clientOperationTimeou
|
|
|
57
79
|
throw ended('CLOSED_WITHOUT_RESPONSE', 'Session completed without an accepted response for this revision.');
|
|
58
80
|
if (session.revision > revision)
|
|
59
81
|
throw ended('REVISION_SUPERSEDED', 'The requested unanswered revision was superseded.');
|
|
60
|
-
// The link's
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
//
|
|
82
|
+
// The link's end (Decision 0009 Amendments 7 and 10): an answer accepted while the link
|
|
83
|
+
// was live is in every later read. The runtime clock is the response's HTTP Date (at or
|
|
84
|
+
// before the read), else this machine's. Nothing is completed here.
|
|
85
|
+
// - live or lapsed: the Session is still open (a lapsed link takes no answer, but the
|
|
86
|
+
// person can still ask for more time until the horizon). The wait never ends on the
|
|
87
|
+
// link; it reads again soon after the link could end.
|
|
88
|
+
// - expired: final once a read made at least LINK_EXPIRY_GRACE_MS past the link's end, or a
|
|
89
|
+
// read at least the grace after the first expired read on the same clock (an end the
|
|
90
|
+
// clocks cannot place, such as a revocation), still shows it expired with no answer. A
|
|
91
|
+
// short polling interval reads again sooner but never ends the wait inside the grace.
|
|
92
|
+
// - no link_state (a runtime before link timing): the deadline is final, as before.
|
|
65
93
|
let untilFinalReadMs = Number.POSITIVE_INFINITY;
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
94
|
+
const link = linkEnd(session);
|
|
95
|
+
const observedAt = current.meta.serverDate ?? Date.now();
|
|
96
|
+
// A Date header has whole seconds: one more second puts the next read past the instant.
|
|
97
|
+
const resolutionMs = current.meta.serverDate === undefined ? 0 : 1000;
|
|
98
|
+
const server = current.meta.serverDate !== undefined;
|
|
99
|
+
if (link.state !== 'expired' || (expiredSince !== undefined && expiredSince.server !== server))
|
|
100
|
+
expiredSince = undefined;
|
|
101
|
+
if (link.state === 'live' || link.state === 'lapsed') {
|
|
102
|
+
if (link.endsAt !== undefined && link.endsAt + LINK_EXPIRY_GRACE_MS > observedAt)
|
|
103
|
+
untilFinalReadMs = link.endsAt + LINK_EXPIRY_GRACE_MS - observedAt + resolutionMs;
|
|
104
|
+
}
|
|
105
|
+
else if (link.state === 'expired' || link.endsAt !== undefined) {
|
|
106
|
+
const finalAt = (link.endsAt ?? observedAt) + LINK_EXPIRY_GRACE_MS;
|
|
107
|
+
// Whole-second Date headers: a full grace plus one second between the two headers puts
|
|
108
|
+
// more than the grace between the two reads.
|
|
109
|
+
const graceSeenAt = expiredSince === undefined
|
|
110
|
+
? Number.POSITIVE_INFINITY
|
|
111
|
+
: expiredSince.at + LINK_EXPIRY_GRACE_MS + expiredSince.resolutionMs;
|
|
112
|
+
if (observedAt >= finalAt || observedAt >= graceSeenAt)
|
|
71
113
|
throw ended('LINK_EXPIRED', 'The Sess link expired with no accepted response for this revision. Nothing was completed.');
|
|
72
|
-
|
|
73
|
-
|
|
114
|
+
untilFinalReadMs = finalAt - observedAt + resolutionMs;
|
|
115
|
+
if (link.state === 'expired') {
|
|
116
|
+
expiredSince ??= { at: observedAt, resolutionMs, server };
|
|
117
|
+
const graceEndsAt = expiredSince.at + LINK_EXPIRY_GRACE_MS + expiredSince.resolutionMs;
|
|
118
|
+
untilFinalReadMs = Math.min(untilFinalReadMs, Math.max(1, graceEndsAt - observedAt));
|
|
119
|
+
}
|
|
74
120
|
}
|
|
75
121
|
await delay(Math.min(intervalMs + Math.floor(Math.random() * 150), untilFinalReadMs, Math.max(1, Math.ceil(expires - performance.now()))), budget.signal);
|
|
76
122
|
}
|
|
@@ -89,4 +135,3 @@ export async function waitForResponse(retrieve, id, input, clientOperationTimeou
|
|
|
89
135
|
budget.dispose();
|
|
90
136
|
}
|
|
91
137
|
}
|
|
92
|
-
//# sourceMappingURL=polling.js.map
|
package/dist/qr/encoder.d.ts
CHANGED
|
@@ -8,4 +8,3 @@ export declare function formatBits(mask: number): number;
|
|
|
8
8
|
export declare function maskBit(mask: number, x: number, y: number): boolean;
|
|
9
9
|
/** Encodes `text` (UTF-8, byte mode, level M) at the smallest version 1–10 that holds it. */
|
|
10
10
|
export declare function encodeQr(text: string): QrMatrix;
|
|
11
|
-
//# sourceMappingURL=encoder.d.ts.map
|
package/dist/qr/encoder.js
CHANGED
package/dist/qr/index.d.ts
CHANGED
package/dist/qr/index.js
CHANGED
package/dist/receipts/bundle.js
CHANGED
package/dist/receipts/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { verifyDecisionReceipt } from './verify.js';
|
|
1
|
+
export { verifyDecisionReceipt, verifyRendererIdentities } from './verify.js';
|
|
2
|
+
export { BUNDLED_RENDERER_IDENTITIES, BUNDLED_RENDERER_LIST, newerRendererList } from './renderers.js';
|
|
3
|
+
export type { RendererIdentitiesDocument, RendererIdentity, RendererList } from './renderers.js';
|
|
2
4
|
export type { ReceiptClaims, ReceiptPublicKey, ReceiptKeySet, ReceiptKeyResolver, VerifyDecisionReceiptInput, VerifyDecisionReceiptOptions, } from './verify.js';
|
|
3
5
|
export type { DeepReadonly } from './json.js';
|
|
4
6
|
export { verifyDecisionBundle, BUNDLE_LIMITS } from './bundle.js';
|
|
5
7
|
export type { BundleContextField, BundleJwk, BundleRejection, DecisionBundle, DecisionBundleVerification, ExpectedBundleContext, VerifiedReceiptSummary, VerifyDecisionBundleOptions, } from './bundle.js';
|
|
6
8
|
export type { ReceiptResource, VerifyResponseInput, VerifiedResponse, VerificationRequestOptions, } from './resource.js';
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/receipts/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { verifyDecisionReceipt } from './verify.js';
|
|
1
|
+
export { verifyDecisionReceipt, verifyRendererIdentities } from './verify.js';
|
|
2
|
+
export { BUNDLED_RENDERER_IDENTITIES, BUNDLED_RENDERER_LIST, newerRendererList } from './renderers.js';
|
|
2
3
|
export { verifyDecisionBundle, BUNDLE_LIMITS } from './bundle.js';
|
|
3
|
-
//# sourceMappingURL=index.js.map
|
package/dist/receipts/json.d.ts
CHANGED
|
@@ -19,4 +19,3 @@ export declare function checkedInstant(value: unknown): number | undefined;
|
|
|
19
19
|
export declare function abortError(signal: AbortSignal): SessError;
|
|
20
20
|
/** Race a promise without cancelling shared work; always remove this waiter's listener. */
|
|
21
21
|
export declare function waitWithSignal<T>(promise: Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
22
|
-
//# sourceMappingURL=json.d.ts.map
|
package/dist/receipts/json.js
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ReceiptPublicKey } from './verify.js';
|
|
2
|
+
/** One listed identity and the UTC date it was added. */
|
|
3
|
+
export interface RendererIdentity {
|
|
4
|
+
renderer_version: string;
|
|
5
|
+
since: string;
|
|
6
|
+
}
|
|
7
|
+
/** A verified list: its edition, when that copy was signed, and its identities in order. */
|
|
8
|
+
export interface RendererList {
|
|
9
|
+
seq: number;
|
|
10
|
+
iat: number;
|
|
11
|
+
identities: readonly RendererIdentity[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The issuer's list as published when this SDK was released (edition 1). Its identities are
|
|
15
|
+
* always accepted for their issuer's receipts; a fetched or supplied list is cross-checked
|
|
16
|
+
* against it.
|
|
17
|
+
*/
|
|
18
|
+
export declare const BUNDLED_RENDERER_LIST: Readonly<{
|
|
19
|
+
seq: number;
|
|
20
|
+
identities: readonly RendererIdentity[];
|
|
21
|
+
}>;
|
|
22
|
+
/** The identities known when this SDK was released; always accepted for their issuer's receipts. */
|
|
23
|
+
export declare const BUNDLED_RENDERER_IDENTITIES: readonly string[];
|
|
24
|
+
/** Where an issuer publishes its signed list (application/json). */
|
|
25
|
+
export declare const RENDERER_IDENTITIES_PATH = "/.well-known/sess-renderer-identities.json";
|
|
26
|
+
export declare const MAX_RENDERER_IDENTITIES_BYTES: number;
|
|
27
|
+
/** The published document: the signed list, as a flattened JWS JSON serialization. */
|
|
28
|
+
export interface RendererIdentitiesDocument {
|
|
29
|
+
protected: string;
|
|
30
|
+
payload: string;
|
|
31
|
+
signature: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Verifies a signed renderer-identity list under the issuer's trusted keys. `keyFor` resolves the
|
|
35
|
+
* list's kid to a trusted public key (undefined: not trusted). Returns the verified edition: its
|
|
36
|
+
* seq, its iat and its identities, in order. It must agree with the bundled list
|
|
37
|
+
* (newerRendererList), or it is refused.
|
|
38
|
+
*/
|
|
39
|
+
export declare function verifyRendererList(document: unknown, context: {
|
|
40
|
+
issuer: string;
|
|
41
|
+
keyFor: (kid: string) => Promise<ReceiptPublicKey | undefined>;
|
|
42
|
+
signal?: AbortSignal;
|
|
43
|
+
}): Promise<RendererList>;
|
|
44
|
+
/**
|
|
45
|
+
* Of two authentic lists of one issuer, the newer edition (the higher seq; for one seq, either:
|
|
46
|
+
* they list the same identities). Containment is the cross-check: the newer list must begin with
|
|
47
|
+
* every identity of the older, in order and with the same dates, and two lists of one seq must
|
|
48
|
+
* list the same identities. Lists that disagree are refused with INVALID_RENDERER_LIST, never
|
|
49
|
+
* merged.
|
|
50
|
+
*/
|
|
51
|
+
export declare function newerRendererList<A extends {
|
|
52
|
+
seq: number;
|
|
53
|
+
identities: readonly RendererIdentity[];
|
|
54
|
+
}, B extends {
|
|
55
|
+
seq: number;
|
|
56
|
+
identities: readonly RendererIdentity[];
|
|
57
|
+
}>(a: A, b: B): A | B;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// Decision 0009 Amendment 13: the renderer identities a receipt's `surface.renderer_version` may
|
|
2
|
+
// name. A receipt verifies when its identity is one this release bundles, or is on a list signed
|
|
3
|
+
// with the issuer's trusted receipt keys, so a future Sess page change needs no SDK update.
|
|
4
|
+
//
|
|
5
|
+
// The issuer publishes the list at `<issuer>/.well-known/sess-renderer-identities.json`
|
|
6
|
+
// (receipt-v1 §10, docs/spec/receipt-v1.md in this repository): one JWS in the RFC 7515 flattened JSON serialization
|
|
7
|
+
// {"protected", "payload", "signature"}, protected header {"alg": "EdDSA", "kid",
|
|
8
|
+
// "typ": "sess-renderer-identities+jwt"}, payload the RFC 8785 canonical JSON
|
|
9
|
+
// {"iat", "identities": [{"renderer_version", "since"}, …], "iss", "seq",
|
|
10
|
+
// "sess_renderer_identities": 1}. `seq` is the list's edition (higher in every later published
|
|
11
|
+
// edition; a copy re-signed unchanged keeps it) and `iat` when that copy was signed (NumericDate);
|
|
12
|
+
// the signature covers both. The list only grows; a list is trusted only through its signature,
|
|
13
|
+
// never because it was supplied beside a receipt. Authentic lists are ordered by `seq`, with
|
|
14
|
+
// containment as the cross-check (newerRendererList); an older list proves the identities it
|
|
15
|
+
// holds and never their absence.
|
|
16
|
+
import { compactVerify, importJWK } from 'jose';
|
|
17
|
+
import { abortError, canonicalJson, exactKeys, isRecord, snapshotJson, verificationError, waitWithSignal, } from './json.js';
|
|
18
|
+
/**
|
|
19
|
+
* The issuer's list as published when this SDK was released (edition 1). Its identities are
|
|
20
|
+
* always accepted for their issuer's receipts; a fetched or supplied list is cross-checked
|
|
21
|
+
* against it.
|
|
22
|
+
*/
|
|
23
|
+
export const BUNDLED_RENDERER_LIST = Object.freeze({
|
|
24
|
+
seq: 1,
|
|
25
|
+
identities: Object.freeze([
|
|
26
|
+
Object.freeze({ renderer_version: 'sess-html-form-1', since: '2026-10-09' }),
|
|
27
|
+
Object.freeze({ renderer_version: 'sess-html-form-2', since: '2026-10-18' }),
|
|
28
|
+
]),
|
|
29
|
+
});
|
|
30
|
+
/** The identities known when this SDK was released; always accepted for their issuer's receipts. */
|
|
31
|
+
export const BUNDLED_RENDERER_IDENTITIES = Object.freeze(BUNDLED_RENDERER_LIST.identities.map((i) => i.renderer_version));
|
|
32
|
+
/** Where an issuer publishes its signed list (application/json). */
|
|
33
|
+
export const RENDERER_IDENTITIES_PATH = '/.well-known/sess-renderer-identities.json';
|
|
34
|
+
export const MAX_RENDERER_IDENTITIES_BYTES = 64 * 1024;
|
|
35
|
+
const PART = /^[A-Za-z0-9_-]+$/;
|
|
36
|
+
const KID = /^[A-Za-z0-9._-]{1,64}$/;
|
|
37
|
+
const IDENTITY = /^[a-z0-9][a-z0-9.-]{0,63}$/;
|
|
38
|
+
const DAY = /^\d{4}-\d{2}-\d{2}$/;
|
|
39
|
+
const TYP = 'sess-renderer-identities+jwt';
|
|
40
|
+
const invalid = (message) => verificationError('INVALID_RENDERER_LIST', message);
|
|
41
|
+
function decode(segment) {
|
|
42
|
+
const bytes = Buffer.from(segment, 'base64url');
|
|
43
|
+
if (bytes.toString('base64url') !== segment)
|
|
44
|
+
throw invalid('The renderer list is not canonical base64url.');
|
|
45
|
+
try {
|
|
46
|
+
return new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
throw invalid('The renderer list does not contain valid UTF-8 JSON.');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function json(text) {
|
|
53
|
+
try {
|
|
54
|
+
return JSON.parse(text);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
throw invalid('The renderer list is not JSON.');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Verifies a signed renderer-identity list under the issuer's trusted keys. `keyFor` resolves the
|
|
62
|
+
* list's kid to a trusted public key (undefined: not trusted). Returns the verified edition: its
|
|
63
|
+
* seq, its iat and its identities, in order. It must agree with the bundled list
|
|
64
|
+
* (newerRendererList), or it is refused.
|
|
65
|
+
*/
|
|
66
|
+
export async function verifyRendererList(document, context) {
|
|
67
|
+
const value = snapshotJson(document);
|
|
68
|
+
if (!isRecord(value) ||
|
|
69
|
+
!exactKeys(value, ['protected', 'payload', 'signature']) ||
|
|
70
|
+
![value.protected, value.payload, value.signature].every((p) => typeof p === 'string' && PART.test(p)) ||
|
|
71
|
+
Buffer.byteLength(canonicalJson(value), 'utf8') > MAX_RENDERER_IDENTITIES_BYTES) {
|
|
72
|
+
throw invalid('The renderer list is not a signed renderer-identity document.');
|
|
73
|
+
}
|
|
74
|
+
const { protected: protectedHeader, payload, signature } = value;
|
|
75
|
+
const header = json(decode(protectedHeader));
|
|
76
|
+
if (!isRecord(header) ||
|
|
77
|
+
!exactKeys(header, ['alg', 'kid', 'typ']) ||
|
|
78
|
+
header.alg !== 'EdDSA' ||
|
|
79
|
+
header.typ !== TYP ||
|
|
80
|
+
typeof header.kid !== 'string' ||
|
|
81
|
+
!KID.test(header.kid)) {
|
|
82
|
+
throw invalid('The renderer list has an unsupported protected header.');
|
|
83
|
+
}
|
|
84
|
+
const signal = context.signal;
|
|
85
|
+
const publicKey = await context.keyFor(header.kid);
|
|
86
|
+
if (!publicKey)
|
|
87
|
+
throw invalid('The renderer list is not signed with a trusted key.');
|
|
88
|
+
try {
|
|
89
|
+
const key = await waitWithSignal(importJWK({ ...publicKey, key_ops: ['verify'], ext: false }, 'EdDSA'), signal);
|
|
90
|
+
await waitWithSignal(compactVerify(`${protectedHeader}.${payload}.${signature}`, key, { algorithms: ['EdDSA'] }), signal);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
if (signal?.aborted)
|
|
94
|
+
throw abortError(signal);
|
|
95
|
+
throw invalid('The renderer list signature did not verify with the trusted key.');
|
|
96
|
+
}
|
|
97
|
+
const text = decode(payload);
|
|
98
|
+
const claims = json(text);
|
|
99
|
+
if (canonicalJson(claims) !== text)
|
|
100
|
+
throw invalid('The renderer list payload is not canonical JSON.');
|
|
101
|
+
if (!isRecord(claims) ||
|
|
102
|
+
!exactKeys(claims, ['iat', 'identities', 'iss', 'seq', 'sess_renderer_identities']) ||
|
|
103
|
+
claims.sess_renderer_identities !== 1 ||
|
|
104
|
+
!positiveInteger(claims.seq) ||
|
|
105
|
+
!positiveInteger(claims.iat) ||
|
|
106
|
+
!Array.isArray(claims.identities) ||
|
|
107
|
+
claims.identities.length === 0) {
|
|
108
|
+
throw invalid('The renderer list payload has an unsupported shape.');
|
|
109
|
+
}
|
|
110
|
+
if (claims.iss !== context.issuer)
|
|
111
|
+
throw invalid('The renderer list is from another issuer.');
|
|
112
|
+
const seen = new Set();
|
|
113
|
+
for (const item of claims.identities) {
|
|
114
|
+
if (!isRecord(item) ||
|
|
115
|
+
!exactKeys(item, ['renderer_version', 'since']) ||
|
|
116
|
+
typeof item.renderer_version !== 'string' ||
|
|
117
|
+
!IDENTITY.test(item.renderer_version) ||
|
|
118
|
+
seen.has(item.renderer_version) ||
|
|
119
|
+
typeof item.since !== 'string' ||
|
|
120
|
+
!DAY.test(item.since) ||
|
|
121
|
+
!Number.isFinite(Date.parse(`${item.since}T00:00:00Z`)) ||
|
|
122
|
+
new Date(`${item.since}T00:00:00Z`).toISOString().slice(0, 10) !== item.since) {
|
|
123
|
+
throw invalid('The renderer list has a malformed or repeated identity.');
|
|
124
|
+
}
|
|
125
|
+
seen.add(item.renderer_version);
|
|
126
|
+
}
|
|
127
|
+
const list = Object.freeze({
|
|
128
|
+
seq: claims.seq,
|
|
129
|
+
iat: claims.iat,
|
|
130
|
+
identities: Object.freeze(claims.identities.map((i) => Object.freeze({ renderer_version: i.renderer_version, since: i.since }))),
|
|
131
|
+
});
|
|
132
|
+
// An authentic list that disagrees with the edition this release bundles is refused.
|
|
133
|
+
newerRendererList(BUNDLED_RENDERER_LIST, list);
|
|
134
|
+
return list;
|
|
135
|
+
}
|
|
136
|
+
const positiveInteger = (v) => typeof v === 'number' && Number.isSafeInteger(v) && v >= 1;
|
|
137
|
+
/**
|
|
138
|
+
* Of two authentic lists of one issuer, the newer edition (the higher seq; for one seq, either:
|
|
139
|
+
* they list the same identities). Containment is the cross-check: the newer list must begin with
|
|
140
|
+
* every identity of the older, in order and with the same dates, and two lists of one seq must
|
|
141
|
+
* list the same identities. Lists that disagree are refused with INVALID_RENDERER_LIST, never
|
|
142
|
+
* merged.
|
|
143
|
+
*/
|
|
144
|
+
export function newerRendererList(a, b) {
|
|
145
|
+
const [older, newer] = b.seq < a.seq ? [b, a] : [a, b];
|
|
146
|
+
const prefix = newer.identities.length >= older.identities.length &&
|
|
147
|
+
older.identities.every((o, i) => newer.identities[i]?.renderer_version === o.renderer_version &&
|
|
148
|
+
newer.identities[i]?.since === o.since);
|
|
149
|
+
if (!prefix || (older.seq === newer.seq && newer.identities.length !== older.identities.length)) {
|
|
150
|
+
throw invalid('The renderer lists disagree.');
|
|
151
|
+
}
|
|
152
|
+
return newer;
|
|
153
|
+
}
|
|
@@ -2,7 +2,22 @@ import { SessError } from '../errors.js';
|
|
|
2
2
|
import { isInteractiveSurface } from '../types.js';
|
|
3
3
|
import { ReceiptKeyCache } from './key-cache.js';
|
|
4
4
|
import { abortError, canonicalJson, deepFreeze, snapshotJson, verificationError, waitWithSignal, } from './json.js';
|
|
5
|
+
import { BUNDLED_RENDERER_IDENTITIES, MAX_RENDERER_IDENTITIES_BYTES, RENDERER_IDENTITIES_PATH, } from './renderers.js';
|
|
5
6
|
import { MAX_RECEIPT_KEY_SET_BYTES, verifyDecisionReceipt } from './verify.js';
|
|
7
|
+
/**
|
|
8
|
+
* The renderer identity a receipt names, read without trusting it: only to decide whether the
|
|
9
|
+
* issuer's signed list is needed (the verifier decides). Undefined when it cannot be read.
|
|
10
|
+
*/
|
|
11
|
+
function namedRenderer(receipt) {
|
|
12
|
+
try {
|
|
13
|
+
const claims = JSON.parse(Buffer.from(receipt.split('.')[1] ?? '', 'base64url').toString('utf8'));
|
|
14
|
+
const surface = claims?.surface;
|
|
15
|
+
return typeof surface?.renderer_version === 'string' ? surface.renderer_version : undefined;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
6
21
|
/** Internal bridge: all HTTP is supplied by the client's ordinary bounded transport. */
|
|
7
22
|
export function createReceiptResource(context) {
|
|
8
23
|
// Copy configuration/callbacks; mutation of an application-owned config object has no effect.
|
|
@@ -85,8 +100,20 @@ export function createReceiptResource(context) {
|
|
|
85
100
|
if (!isInteractiveSurface(surface)) {
|
|
86
101
|
throw verificationError('RECORD_BINDING_MISMATCH', 'An accepted response requires an interactive immutable Surface.');
|
|
87
102
|
}
|
|
103
|
+
// Decision 0009 Amendment 13: a renderer identity this release does not bundle is
|
|
104
|
+
// accepted only on the issuer's signed list, fetched from the same API origin as the keys.
|
|
105
|
+
const renderer = namedRenderer(response.receipt);
|
|
106
|
+
let rendererIdentities;
|
|
107
|
+
if (renderer !== undefined && !BUNDLED_RENDERER_IDENTITIES.includes(renderer)) {
|
|
108
|
+
const listed = await waitWithSignal(publicGet(RENDERER_IDENTITIES_PATH, {
|
|
109
|
+
...requestOptions(),
|
|
110
|
+
maxResponseBytes: MAX_RENDERER_IDENTITIES_BYTES,
|
|
111
|
+
}), controller.signal);
|
|
112
|
+
rendererIdentities = listed.data;
|
|
113
|
+
}
|
|
88
114
|
const claims = await verifyDecisionReceipt({
|
|
89
115
|
receipt: response.receipt,
|
|
116
|
+
...(rendererIdentities !== undefined ? { rendererIdentities } : {}),
|
|
90
117
|
issuer,
|
|
91
118
|
audience: trustedWorkspace,
|
|
92
119
|
expected: {
|
|
@@ -116,4 +143,3 @@ export function createReceiptResource(context) {
|
|
|
116
143
|
},
|
|
117
144
|
});
|
|
118
145
|
}
|
|
119
|
-
//# sourceMappingURL=resource.js.map
|