@vdatacloud/cx-commons 0.1.6 → 0.1.7
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/package.json +1 -1
- package/src/sdk/api-error-notice.ts +28 -4
- package/src/sdk/api-error.ts +7 -0
package/package.json
CHANGED
|
@@ -32,7 +32,7 @@ const TONE = {
|
|
|
32
32
|
const CHIP_BASE = 'inline-flex items-center rounded-full border px-2 py-0.5 font-mono text-[10px] font-black tracking-widest uppercase';
|
|
33
33
|
const NEUTRAL_CHIP = 'text-slate-600 bg-slate-100 border-slate-200 dark:text-slate-300 dark:bg-slate-800 dark:border-slate-700';
|
|
34
34
|
const MONO = 'font-mono text-xs break-all text-slate-700 dark:text-slate-200';
|
|
35
|
-
const LABEL = 'text-[
|
|
35
|
+
const LABEL = 'text-[11px] font-semibold text-slate-500 dark:text-slate-400';
|
|
36
36
|
const BUTTON = 'rounded-md border border-slate-200 px-2 py-0.5 text-[10px] font-bold uppercase tracking-widest text-slate-600 hover:bg-slate-100 dark:border-slate-700 dark:text-slate-300 dark:hover:bg-slate-800';
|
|
37
37
|
|
|
38
38
|
function el<K extends keyof HTMLElementTagNameMap>(tag: K, className = '', text?: string): HTMLElementTagNameMap[K] {
|
|
@@ -72,6 +72,30 @@ function row(label: string, value: string, asId = true): HTMLElement {
|
|
|
72
72
|
return r;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
// Known detail keys read as words a person recognizes; any other key is
|
|
76
|
+
// split from camelCase ("publicKeyFingerprint" -> "Public key fingerprint").
|
|
77
|
+
const DETAIL_LABELS: Record<string, string> = {
|
|
78
|
+
party: 'Account (party)',
|
|
79
|
+
partyFingerprint: 'Account key fingerprint',
|
|
80
|
+
publicKeyFingerprint: 'Your key fingerprint',
|
|
81
|
+
signatureReceived: 'Signature received',
|
|
82
|
+
signedBy: 'Signed by key',
|
|
83
|
+
signedMessage: 'What was signed',
|
|
84
|
+
expectedHash: 'Expected transaction hash',
|
|
85
|
+
computedHash: 'Computed transaction hash',
|
|
86
|
+
ledgerUser: 'Ledger user',
|
|
87
|
+
actAs: 'Acting as',
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/** A readable label for a details key. */
|
|
91
|
+
export function detailLabel(key: string): string {
|
|
92
|
+
const m = /^(.*)\[(\d+)\]$/.exec(key);
|
|
93
|
+
const base = m ? m[1] : key;
|
|
94
|
+
const label = DETAIL_LABELS[base] ??
|
|
95
|
+
base.replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/^./, (c) => c.toUpperCase()).replace(/ ([A-Z])(?=[a-z])/g, (_, c) => ' ' + c.toLowerCase());
|
|
96
|
+
return m ? `${label} ${Number(m[2]) + 1}` : label;
|
|
97
|
+
}
|
|
98
|
+
|
|
75
99
|
function detailValue(v: unknown): string {
|
|
76
100
|
if (typeof v === 'string') return v;
|
|
77
101
|
if (Array.isArray(v)) return v.map(detailValue).join(', ');
|
|
@@ -125,13 +149,13 @@ export function renderApiErrorNotice(e: ApiError, opts: ApiErrorNoticeOptions =
|
|
|
125
149
|
const det = el('details', 'rounded-lg border border-slate-200 p-2 dark:border-slate-700');
|
|
126
150
|
det.append(el('summary', `${LABEL} cursor-pointer select-none`, 'Details'));
|
|
127
151
|
const dl = el('dl', 'mt-2 space-y-1');
|
|
128
|
-
if (shown.upstream?.cause) dl.append(row(`${shown.upstream.service}
|
|
152
|
+
if (shown.upstream?.cause) dl.append(row(`${shown.upstream.service.charAt(0).toUpperCase()}${shown.upstream.service.slice(1)} says`, shown.upstream.cause, false));
|
|
129
153
|
for (const k of Object.keys(shown.details ?? {}).sort()) {
|
|
130
154
|
const v = shown.details![k];
|
|
131
155
|
if (Array.isArray(v) && v.every((x) => typeof x === 'string')) {
|
|
132
|
-
v.forEach((x, i) => dl.append(row(v.length > 1 ? `${k}[${i}]` : k, x)));
|
|
156
|
+
v.forEach((x, i) => dl.append(row(detailLabel(v.length > 1 ? `${k}[${i}]` : k), x)));
|
|
133
157
|
} else {
|
|
134
|
-
dl.append(row(k, detailValue(v), typeof v === 'string'));
|
|
158
|
+
dl.append(row(detailLabel(k), detailValue(v), typeof v === 'string'));
|
|
135
159
|
}
|
|
136
160
|
}
|
|
137
161
|
det.append(dl);
|
package/src/sdk/api-error.ts
CHANGED
|
@@ -17,6 +17,13 @@
|
|
|
17
17
|
|
|
18
18
|
import { shortCantonId, isFingerprint } from './canton-id';
|
|
19
19
|
|
|
20
|
+
// Disclosure (same rules as Go apierror's package doc, "What an error may
|
|
21
|
+
// disclose"): errors a UI builds itself -- e.g. from a direct Canton or
|
|
22
|
+
// wallet call -- may carry what the user sent, values derived from their
|
|
23
|
+
// own credentials, and facts about their own verified account; never
|
|
24
|
+
// another party's data, identity data, secrets, or raw internal error text.
|
|
25
|
+
// Use 'summary' when an error leaves the user's own screen (support
|
|
26
|
+
// tickets, shared links).
|
|
20
27
|
export type ApiErrorDetail = 'full' | 'summary';
|
|
21
28
|
|
|
22
29
|
export interface ApiErrorUpstream {
|