@sess.si/sdk 0.0.0-stage → 0.1.0-rc.10
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 +185 -0
- package/LICENSE +201 -0
- package/NOTICE +27 -0
- package/README.md +327 -2
- package/dist/ask.d.ts +161 -0
- package/dist/ask.js +499 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +7 -0
- package/dist/cli/verify.d.ts +13 -0
- package/dist/cli/verify.js +322 -0
- package/dist/client.d.ts +19 -0
- package/dist/client.js +43 -0
- 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 +61 -0
- package/dist/errors.js +63 -0
- package/dist/generated/openapi.d.ts +8360 -0
- package/dist/generated/openapi.js +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +6 -0
- package/dist/internal/decode.d.ts +20 -0
- package/dist/internal/decode.js +380 -0
- package/dist/internal/json.d.ts +3 -0
- package/dist/internal/json.js +74 -0
- package/dist/internal/time.d.ts +10 -0
- package/dist/internal/time.js +70 -0
- package/dist/internal/version.d.ts +2 -0
- package/dist/internal/version.js +2 -0
- package/dist/polling.d.ts +11 -0
- package/dist/polling.js +137 -0
- package/dist/qr/encoder.d.ts +10 -0
- package/dist/qr/encoder.js +343 -0
- package/dist/qr/index.d.ts +55 -0
- package/dist/qr/index.js +150 -0
- package/dist/receipts/bundle.d.ts +123 -0
- package/dist/receipts/bundle.js +423 -0
- package/dist/receipts/index.d.ts +8 -0
- package/dist/receipts/index.js +3 -0
- package/dist/receipts/json.d.ts +21 -0
- package/dist/receipts/json.js +151 -0
- package/dist/receipts/key-cache.d.ts +27 -0
- package/dist/receipts/key-cache.js +109 -0
- package/dist/receipts/renderers.d.ts +57 -0
- package/dist/receipts/renderers.js +153 -0
- package/dist/receipts/resource.d.ts +38 -0
- package/dist/receipts/resource.js +145 -0
- package/dist/receipts/verify.d.ts +112 -0
- package/dist/receipts/verify.js +339 -0
- package/dist/sessions.d.ts +18 -0
- package/dist/sessions.js +151 -0
- package/dist/transport.d.ts +30 -0
- package/dist/transport.js +511 -0
- package/dist/types.d.ts +283 -0
- package/dist/types.js +8 -0
- package/dist/webhook-resource.d.ts +12 -0
- package/dist/webhook-resource.js +51 -0
- package/dist/webhooks/index.d.ts +21 -0
- package/dist/webhooks/index.js +183 -0
- package/package.json +82 -4
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Commerce: a text lint for Markdown pipe tables. Sess shows text exactly as written (plain text,
|
|
2
|
+
// never markup), so a table drawn with pipes reaches the person as a wall of `|` and `---`. Prices
|
|
3
|
+
// belong in an items component; other rows of facts in a record. Pure: no I/O.
|
|
4
|
+
// A GFM delimiter row: `| --- | :---: |`, `---|---`, `| --- |`.
|
|
5
|
+
const DELIMITER = /^\s*\|?\s*:?-+:?\s*(?:\|\s*:?-+:?\s*)*\|?\s*$/;
|
|
6
|
+
// Amount-like content: a currency symbol, an ISO-style code beside a number, a two- or three-place
|
|
7
|
+
// decimal, or a price word in the header.
|
|
8
|
+
const MONEY = /[$€£¥₹₩₽₺₪₫฿]|\b[A-Z]{3}\s?-?\d|\d\s?[A-Z]{3}\b|\d[.,]\d{2,3}\b/;
|
|
9
|
+
const PRICE_WORDS = /\b(?:price|amount|total|subtotal|cost|tax|vat|fee|qty|quantity)\b/i;
|
|
10
|
+
/** The cells of a line split on unescaped pipes, or null when it has no pipe. */
|
|
11
|
+
function cells(line) {
|
|
12
|
+
const parts = line.split(/(?<!\\)\|/);
|
|
13
|
+
return parts.length > 1 ? parts : null;
|
|
14
|
+
}
|
|
15
|
+
const bordered = (line) => /^\s*\|.*\|\s*$/.test(line) && (cells(line)?.length ?? 0) >= 3;
|
|
16
|
+
/**
|
|
17
|
+
* Finds Markdown pipe tables in a text: a header row with pipes followed by a delimiter row
|
|
18
|
+
* (`|---|---|`), or two or more consecutive rows drawn between pipes (`| a | b |`). Each finding
|
|
19
|
+
* says where the table starts and what to send instead: an items component for prices, or a
|
|
20
|
+
* record for other rows. Returns an empty list for ordinary text.
|
|
21
|
+
*/
|
|
22
|
+
export function lintText(text) {
|
|
23
|
+
if (typeof text !== 'string')
|
|
24
|
+
return [];
|
|
25
|
+
const lines = text.split(/\r\n|\r|\n/);
|
|
26
|
+
const findings = [];
|
|
27
|
+
let i = 0;
|
|
28
|
+
while (i < lines.length) {
|
|
29
|
+
const line = lines[i];
|
|
30
|
+
const next = lines[i + 1];
|
|
31
|
+
const headed = cells(line) !== null &&
|
|
32
|
+
next !== undefined &&
|
|
33
|
+
next.includes('-') &&
|
|
34
|
+
DELIMITER.test(next) &&
|
|
35
|
+
next.includes('|');
|
|
36
|
+
const drawn = bordered(line) && next !== undefined && bordered(next);
|
|
37
|
+
if (!headed && !drawn) {
|
|
38
|
+
i += 1;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
let end = i + (headed ? 2 : 1);
|
|
42
|
+
while (end < lines.length && cells(lines[end]) !== null && /\S/.test(lines[end]))
|
|
43
|
+
end += 1;
|
|
44
|
+
const use = lines.slice(i, end).some((l) => MONEY.test(l) || PRICE_WORDS.test(l)) ? 'items' : 'record';
|
|
45
|
+
findings.push({
|
|
46
|
+
rule: 'pipe-table',
|
|
47
|
+
line: i + 1,
|
|
48
|
+
use,
|
|
49
|
+
message: use === 'items'
|
|
50
|
+
? `Line ${i + 1} starts a Markdown table. Sess shows text as written, so the person would see the pipes. For prices, send an items component instead.`
|
|
51
|
+
: `Line ${i + 1} starts a Markdown table. Sess shows text as written, so the person would see the pipes. For rows of facts, send a record component instead.`,
|
|
52
|
+
});
|
|
53
|
+
i = end;
|
|
54
|
+
}
|
|
55
|
+
return findings;
|
|
56
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
import type { CreateSessionResponse } from './types.js';
|
|
3
|
+
export type SessErrorKind = 'configuration' | 'api' | 'transport' | 'timeout' | 'aborted' | 'protocol' | 'unknown_outcome' | 'receipt_verification' | 'wait_ended';
|
|
4
|
+
export type WriteOutcome = 'not_sent' | 'rejected' | 'unknown';
|
|
5
|
+
export interface SessErrorDetails {
|
|
6
|
+
code?: string;
|
|
7
|
+
reason?: string;
|
|
8
|
+
status?: number;
|
|
9
|
+
requestId?: string;
|
|
10
|
+
operation?: string;
|
|
11
|
+
attempts?: number;
|
|
12
|
+
outcome?: WriteOutcome;
|
|
13
|
+
idempotencyKey?: string;
|
|
14
|
+
retryAfterMs?: number;
|
|
15
|
+
sessionId?: string;
|
|
16
|
+
revision?: number;
|
|
17
|
+
/** With a length error: a JSON pointer to the value that is too long, e.g. `/interaction/title`. */
|
|
18
|
+
field?: string;
|
|
19
|
+
/** With a length error: the most the value may have, in Unicode code points. */
|
|
20
|
+
limit?: number;
|
|
21
|
+
/** With a length error: the value's actual length, in Unicode code points. */
|
|
22
|
+
length?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Stable error fields; messages never include response bodies or request secrets. An optional
|
|
26
|
+
* field is an own property only when it has a value, so printing an error lists no empty fields.
|
|
27
|
+
*/
|
|
28
|
+
export declare class SessError extends Error {
|
|
29
|
+
readonly kind: SessErrorKind;
|
|
30
|
+
readonly code?: string;
|
|
31
|
+
readonly reason?: string;
|
|
32
|
+
readonly status?: number;
|
|
33
|
+
readonly requestId?: string;
|
|
34
|
+
readonly operation?: string;
|
|
35
|
+
readonly attempts?: number;
|
|
36
|
+
readonly outcome?: WriteOutcome;
|
|
37
|
+
readonly idempotencyKey?: string;
|
|
38
|
+
readonly retryAfterMs?: number;
|
|
39
|
+
readonly sessionId?: string;
|
|
40
|
+
readonly revision?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Set only when a value is too long (a 400 INVALID_SCHEMA from Sess, or INVALID_QUESTION from
|
|
43
|
+
* `ask`): a JSON pointer to it, e.g. `/interaction/title`. Nothing is ever truncated: shorten
|
|
44
|
+
* the value to at most `limit` characters and send again.
|
|
45
|
+
*/
|
|
46
|
+
readonly field?: string;
|
|
47
|
+
/** With `field`: the most the value may have, in Unicode code points (e.g. title 80). */
|
|
48
|
+
readonly limit?: number;
|
|
49
|
+
/** With `field`: the value's actual length, in Unicode code points. */
|
|
50
|
+
readonly length?: number;
|
|
51
|
+
constructor(kind: SessErrorKind, message: string, details?: SessErrorDetails);
|
|
52
|
+
/** Explicit access only. A usable create body may accompany a defective header. */
|
|
53
|
+
getRecoveryResult(): Readonly<CreateSessionResponse> | undefined;
|
|
54
|
+
toJSON(): object;
|
|
55
|
+
/** `util.inspect` and `console.log`: the same fields as JSON, without the absent ones. */
|
|
56
|
+
[inspect.custom](): object;
|
|
57
|
+
}
|
|
58
|
+
/** Internal: the one-line fix every length error carries (field, limit, actual length, fix). */
|
|
59
|
+
export declare function lengthMessage(field: string, limit: number, length: number): string;
|
|
60
|
+
/** Internal: keep private creation capabilities out of inspection and serialization. */
|
|
61
|
+
export declare function attachRecovery(error: SessError, value: CreateSessionResponse): void;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
const recovery = new WeakMap();
|
|
3
|
+
/**
|
|
4
|
+
* Stable error fields; messages never include response bodies or request secrets. An optional
|
|
5
|
+
* field is an own property only when it has a value, so printing an error lists no empty fields.
|
|
6
|
+
*/
|
|
7
|
+
export class SessError extends Error {
|
|
8
|
+
kind;
|
|
9
|
+
constructor(kind, message, details = {}) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = 'SessError';
|
|
12
|
+
this.kind = kind;
|
|
13
|
+
for (const [name, value] of Object.entries(details))
|
|
14
|
+
if (value !== undefined)
|
|
15
|
+
Object.assign(this, { [name]: value });
|
|
16
|
+
}
|
|
17
|
+
/** Explicit access only. A usable create body may accompany a defective header. */
|
|
18
|
+
getRecoveryResult() {
|
|
19
|
+
return recovery.get(this);
|
|
20
|
+
}
|
|
21
|
+
toJSON() {
|
|
22
|
+
const { name, kind, message, code, reason, status, requestId, operation, attempts, outcome, idempotencyKey, retryAfterMs, field, limit, length, } = this;
|
|
23
|
+
const fields = {
|
|
24
|
+
name,
|
|
25
|
+
kind,
|
|
26
|
+
message,
|
|
27
|
+
code,
|
|
28
|
+
reason,
|
|
29
|
+
status,
|
|
30
|
+
requestId,
|
|
31
|
+
operation,
|
|
32
|
+
attempts,
|
|
33
|
+
outcome,
|
|
34
|
+
idempotencyKey,
|
|
35
|
+
retryAfterMs,
|
|
36
|
+
field,
|
|
37
|
+
limit,
|
|
38
|
+
length,
|
|
39
|
+
};
|
|
40
|
+
return Object.fromEntries(Object.entries(fields).filter(([, value]) => value !== undefined));
|
|
41
|
+
}
|
|
42
|
+
/** `util.inspect` and `console.log`: the same fields as JSON, without the absent ones. */
|
|
43
|
+
[inspect.custom]() {
|
|
44
|
+
return this.toJSON();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Internal: the one-line fix every length error carries (field, limit, actual length, fix). */
|
|
48
|
+
export function lengthMessage(field, limit, length) {
|
|
49
|
+
// The same sentences as Sess's 400 INVALID_SCHEMA (`field` is a JSON pointer); the title (the
|
|
50
|
+
// `sess.ask()` question) has its own.
|
|
51
|
+
if (field === '/interaction/title' || field === '/question')
|
|
52
|
+
return `The title can be at most ${limit} characters. Keep it to a short heading, about 40.`;
|
|
53
|
+
// Commerce: an items component's rows and totals lines are counted, never truncated.
|
|
54
|
+
if (/\/rows$/.test(field))
|
|
55
|
+
return `${field} has ${length} rows; the limit is ${limit}. Send at most ${limit}, in more than one items component if you need more.`;
|
|
56
|
+
if (/\/totals$/.test(field))
|
|
57
|
+
return `${field} has ${length} totals lines; the limit is ${limit}. Send at most ${limit}.`;
|
|
58
|
+
return `${field} is ${length} characters; the limit is ${limit}. Shorten it to at most ${limit} characters.`;
|
|
59
|
+
}
|
|
60
|
+
/** Internal: keep private creation capabilities out of inspection and serialization. */
|
|
61
|
+
export function attachRecovery(error, value) {
|
|
62
|
+
recovery.set(error, Object.freeze({ ...value }));
|
|
63
|
+
}
|