@arcforges/api-client 1.0.0-ci.284.1 → 1.0.0-ci.287.1
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/NOTICE +5 -5
- package/build-identity.json +37 -17
- package/contracts.binpb +0 -0
- package/dist/gen/http.d.ts +21 -0
- package/dist/gen/http.js +21 -0
- package/dist/shapes/gen/BrowserAuthChallenge.d.ts +35 -0
- package/dist/shapes/gen/BrowserAuthChallenge.js +531 -0
- package/dist/shapes/gen/BrowserBeginAuthenticationRequest.d.ts +28 -0
- package/dist/shapes/gen/BrowserBeginAuthenticationRequest.js +384 -0
- package/dist/shapes/gen/BrowserBeginRecoveryRequest.d.ts +22 -0
- package/dist/shapes/gen/BrowserBeginRecoveryRequest.js +370 -0
- package/dist/shapes/gen/BrowserBeginStepUpRequest.d.ts +20 -0
- package/dist/shapes/gen/BrowserBeginStepUpRequest.js +279 -0
- package/dist/shapes/gen/BrowserBootstrapResponse.d.ts +37 -0
- package/dist/shapes/gen/BrowserBootstrapResponse.js +534 -0
- package/dist/shapes/gen/BrowserCompleteAuthenticationRequest.d.ts +45 -0
- package/dist/shapes/gen/BrowserCompleteAuthenticationRequest.js +564 -0
- package/dist/shapes/gen/BrowserCompleteEnrollmentRequest.d.ts +90 -0
- package/dist/shapes/gen/BrowserCompleteEnrollmentRequest.js +1145 -0
- package/dist/shapes/gen/BrowserCompleteRecoveryRequest.d.ts +22 -0
- package/dist/shapes/gen/BrowserCompleteRecoveryRequest.js +733 -0
- package/dist/shapes/gen/BrowserCompleteStepUpRequest.d.ts +20 -0
- package/dist/shapes/gen/BrowserCompleteStepUpRequest.js +564 -0
- package/dist/shapes/gen/BrowserOidcCallbackFailure.d.ts +20 -0
- package/dist/shapes/gen/BrowserOidcCallbackFailure.js +200 -0
- package/dist/shapes/gen/BrowserOidcCallbackSuccess.d.ts +19 -0
- package/dist/shapes/gen/BrowserOidcCallbackSuccess.js +185 -0
- package/dist/shapes/gen/BrowserReceipt.d.ts +20 -0
- package/dist/shapes/gen/BrowserReceipt.js +285 -0
- package/dist/shapes/gen/BrowserSessionRoutes.d.ts +17 -0
- package/dist/shapes/gen/BrowserSessionRoutes.js +13 -0
- package/dist/shapes/gen/BrowserSessionView.d.ts +25 -0
- package/dist/shapes/gen/BrowserSessionView.js +388 -0
- package/dist/shapes/gen/BrowserStepUpEvidence.d.ts +19 -0
- package/dist/shapes/gen/BrowserStepUpEvidence.js +266 -0
- package/dist/shapes/gen/NativeAuthRoutes.d.ts +17 -0
- package/dist/shapes/gen/NativeAuthRoutes.js +5 -0
- package/dist/shapes/gen/NativeAuthorizeCallbackFailure.d.ts +19 -0
- package/dist/shapes/gen/NativeAuthorizeCallbackFailure.js +185 -0
- package/dist/shapes/gen/NativeAuthorizeCallbackSuccess.d.ts +19 -0
- package/dist/shapes/gen/NativeAuthorizeCallbackSuccess.js +185 -0
- package/dist/shapes/gen/NativeAuthorizeRequest.d.ts +24 -0
- package/dist/shapes/gen/NativeAuthorizeRequest.js +271 -0
- package/dist/shapes/gen/NativeTokenRequest.d.ts +23 -0
- package/dist/shapes/gen/NativeTokenRequest.js +258 -0
- package/dist/shapes/gen/NativeTokenResponse.d.ts +40 -0
- package/dist/shapes/gen/NativeTokenResponse.js +572 -0
- package/package.json +2 -2
- package/sbom.cdx.json +9 -9
- package/schemas/public/http/v1/browser.schema.json +1300 -0
- package/schemas/public/http/v1/native-auth.schema.json +341 -0
- package/schemas/public/proto/arcforges/publicapi/v1/identity.proto +1350 -0
- package/source.json +6 -3
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
export function isBrowserOidcCallbackFailure(value) { return check0(value); }
|
|
2
|
+
/** The schema's declared form-urlencoded document bound in bytes. */
|
|
3
|
+
export const browserOidcCallbackFailureFormMaxBytes = 16384;
|
|
4
|
+
/** Parses one strict BrowserOidcCallbackFailure form; refusal kinds match the C# codec. */
|
|
5
|
+
export function tryParseBrowserOidcCallbackFailureForm(input) {
|
|
6
|
+
let bytes;
|
|
7
|
+
if (typeof input === "string") {
|
|
8
|
+
if (!validText(input))
|
|
9
|
+
return { ok: false, failure: "malformed" };
|
|
10
|
+
bytes = new TextEncoder().encode(input);
|
|
11
|
+
}
|
|
12
|
+
else
|
|
13
|
+
bytes = input;
|
|
14
|
+
if (bytes.byteLength > 16384)
|
|
15
|
+
return { ok: false, failure: "tooLarge" };
|
|
16
|
+
const decoded = decodeForm(bytes);
|
|
17
|
+
if (decoded === undefined)
|
|
18
|
+
return { ok: false, failure: "malformed" };
|
|
19
|
+
return isBrowserOidcCallbackFailure(decoded) ? { ok: true, value: decoded } : { ok: false, failure: "invalid" };
|
|
20
|
+
}
|
|
21
|
+
/** Parses one strict BrowserOidcCallbackFailure form or throws an error carrying the refusal kind. */
|
|
22
|
+
export function parseBrowserOidcCallbackFailureForm(input) {
|
|
23
|
+
const result = tryParseBrowserOidcCallbackFailureForm(input);
|
|
24
|
+
if (!result.ok)
|
|
25
|
+
throw Object.assign(new Error(`BrowserOidcCallbackFailure form refused: ${result.failure}.`), { failure: result.failure });
|
|
26
|
+
return result.value;
|
|
27
|
+
}
|
|
28
|
+
/** Writes schema-order name=value pairs with only RFC 3986 unreserved characters unescaped and refuses output the schema rejects. */
|
|
29
|
+
export function serializeBrowserOidcCallbackFailureForm(value) {
|
|
30
|
+
const out = [];
|
|
31
|
+
for (const name of ["error", "error_description", "state"]) {
|
|
32
|
+
const item = value[name];
|
|
33
|
+
if (item === undefined)
|
|
34
|
+
continue;
|
|
35
|
+
if (!validText(item))
|
|
36
|
+
throw Object.assign(new Error("BrowserOidcCallbackFailure form refused: invalid."), { failure: "invalid" });
|
|
37
|
+
if (out.length !== 0)
|
|
38
|
+
out.push("&");
|
|
39
|
+
encodeFormComponent(name, out);
|
|
40
|
+
out.push("=");
|
|
41
|
+
encodeFormComponent(item, out);
|
|
42
|
+
}
|
|
43
|
+
const bytes = new TextEncoder().encode(out.join(""));
|
|
44
|
+
const result = tryParseBrowserOidcCallbackFailureForm(bytes);
|
|
45
|
+
if (!result.ok)
|
|
46
|
+
throw Object.assign(new Error(`BrowserOidcCallbackFailure form refused: ${result.failure}.`), { failure: result.failure });
|
|
47
|
+
return bytes;
|
|
48
|
+
}
|
|
49
|
+
function check0(value) {
|
|
50
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
51
|
+
return false;
|
|
52
|
+
const object = value;
|
|
53
|
+
for (const key of Object.keys(object)) {
|
|
54
|
+
switch (key) {
|
|
55
|
+
case "error":
|
|
56
|
+
if (!check1(object[key]))
|
|
57
|
+
return false;
|
|
58
|
+
break;
|
|
59
|
+
case "error_description":
|
|
60
|
+
if (!check2(object[key]))
|
|
61
|
+
return false;
|
|
62
|
+
break;
|
|
63
|
+
case "state":
|
|
64
|
+
if (!check3(object[key]))
|
|
65
|
+
return false;
|
|
66
|
+
break;
|
|
67
|
+
default: return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (!Object.prototype.hasOwnProperty.call(object, "error"))
|
|
71
|
+
return false;
|
|
72
|
+
if (!Object.prototype.hasOwnProperty.call(object, "state"))
|
|
73
|
+
return false;
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
function check1(value) {
|
|
77
|
+
if (typeof value !== 'string' || !validText(value))
|
|
78
|
+
return false;
|
|
79
|
+
if ([...value].length < 1)
|
|
80
|
+
return false;
|
|
81
|
+
if ([...value].length > 64)
|
|
82
|
+
return false;
|
|
83
|
+
if ((new RegExp("^[a-z][a-z_]*$", 'u')).exec(value)?.[0] !== value)
|
|
84
|
+
return false;
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
function check2(value) {
|
|
88
|
+
if (typeof value !== 'string' || !validText(value))
|
|
89
|
+
return false;
|
|
90
|
+
if ([...value].length < 1)
|
|
91
|
+
return false;
|
|
92
|
+
if ([...value].length > 512)
|
|
93
|
+
return false;
|
|
94
|
+
if ((new RegExp("^[\\x20-\\x7E]+$", 'u')).exec(value)?.[0] !== value)
|
|
95
|
+
return false;
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
function check3(value) {
|
|
99
|
+
if (typeof value !== 'string' || !validText(value))
|
|
100
|
+
return false;
|
|
101
|
+
if ([...value].length < 1)
|
|
102
|
+
return false;
|
|
103
|
+
if ([...value].length > 128)
|
|
104
|
+
return false;
|
|
105
|
+
if ((new RegExp("^[\\x21-\\x7E]+$", 'u')).exec(value)?.[0] !== value)
|
|
106
|
+
return false;
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
function validText(value) {
|
|
110
|
+
for (const scalar of value) {
|
|
111
|
+
const point = scalar.codePointAt(0);
|
|
112
|
+
if (point >= 0xd800 && point <= 0xdfff)
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
function hexValue(byte) {
|
|
118
|
+
if (byte >= 0x30 && byte <= 0x39)
|
|
119
|
+
return byte - 0x30;
|
|
120
|
+
if (byte >= 0x61 && byte <= 0x66)
|
|
121
|
+
return byte - 0x61 + 10;
|
|
122
|
+
if (byte >= 0x41 && byte <= 0x46)
|
|
123
|
+
return byte - 0x41 + 10;
|
|
124
|
+
return -1;
|
|
125
|
+
}
|
|
126
|
+
function decodeFormComponent(input) {
|
|
127
|
+
const bytes = [];
|
|
128
|
+
for (let i = 0; i < input.length; i++) {
|
|
129
|
+
const byte = input[i];
|
|
130
|
+
if (byte === 0x2b) {
|
|
131
|
+
bytes.push(0x20);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (byte === 0x25) {
|
|
135
|
+
if (i + 2 >= input.length)
|
|
136
|
+
return undefined;
|
|
137
|
+
const high = hexValue(input[i + 1]);
|
|
138
|
+
const low = hexValue(input[i + 2]);
|
|
139
|
+
if (high < 0 || low < 0)
|
|
140
|
+
return undefined;
|
|
141
|
+
bytes.push(high * 16 + low);
|
|
142
|
+
i += 2;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (byte < 0x21 || byte > 0x7e)
|
|
146
|
+
return undefined;
|
|
147
|
+
bytes.push(byte);
|
|
148
|
+
}
|
|
149
|
+
let text;
|
|
150
|
+
try {
|
|
151
|
+
text = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(Uint8Array.from(bytes));
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
for (const char of text) {
|
|
157
|
+
const point = char.codePointAt(0);
|
|
158
|
+
if (point < 0x20 || point === 0x7f)
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
return text;
|
|
162
|
+
}
|
|
163
|
+
/** Strict form syntax: printable ASCII, name=value pairs, percent escapes, UTF-8 text and no duplicate or empty names. */
|
|
164
|
+
function decodeForm(input) {
|
|
165
|
+
if (input.length === 0)
|
|
166
|
+
return undefined;
|
|
167
|
+
const out = {};
|
|
168
|
+
const names = new Set();
|
|
169
|
+
let start = 0;
|
|
170
|
+
for (;;) {
|
|
171
|
+
let end = input.indexOf(0x26, start);
|
|
172
|
+
const last = end < 0;
|
|
173
|
+
if (last)
|
|
174
|
+
end = input.length;
|
|
175
|
+
const segment = input.subarray(start, end);
|
|
176
|
+
const equals = segment.indexOf(0x3d);
|
|
177
|
+
if (equals <= 0)
|
|
178
|
+
return undefined;
|
|
179
|
+
const name = decodeFormComponent(segment.subarray(0, equals));
|
|
180
|
+
const value = decodeFormComponent(segment.subarray(equals + 1));
|
|
181
|
+
if (name === undefined || value === undefined || names.has(name))
|
|
182
|
+
return undefined;
|
|
183
|
+
names.add(name);
|
|
184
|
+
// defineProperty keeps names such as __proto__ as ordinary own properties.
|
|
185
|
+
Object.defineProperty(out, name, { value, enumerable: true, writable: true, configurable: true });
|
|
186
|
+
if (last)
|
|
187
|
+
return out;
|
|
188
|
+
start = end + 1;
|
|
189
|
+
if (start === input.length)
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function encodeFormComponent(value, out) {
|
|
194
|
+
for (const byte of new TextEncoder().encode(value)) {
|
|
195
|
+
if ((byte >= 0x41 && byte <= 0x5a) || (byte >= 0x61 && byte <= 0x7a) || (byte >= 0x30 && byte <= 0x39) || byte === 0x2d || byte === 0x2e || byte === 0x5f || byte === 0x7e)
|
|
196
|
+
out.push(String.fromCharCode(byte));
|
|
197
|
+
else
|
|
198
|
+
out.push("%" + byte.toString(16).toUpperCase().padStart(2, "0"));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface BrowserOidcCallbackSuccess {
|
|
2
|
+
code: string;
|
|
3
|
+
state: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function isBrowserOidcCallbackSuccess(value: unknown): value is BrowserOidcCallbackSuccess;
|
|
6
|
+
/** The schema's declared form-urlencoded document bound in bytes. */
|
|
7
|
+
export declare const browserOidcCallbackSuccessFormMaxBytes = 16384;
|
|
8
|
+
/** Parses one strict BrowserOidcCallbackSuccess form; refusal kinds match the C# codec. */
|
|
9
|
+
export declare function tryParseBrowserOidcCallbackSuccessForm(input: Uint8Array | string): {
|
|
10
|
+
ok: true;
|
|
11
|
+
value: BrowserOidcCallbackSuccess;
|
|
12
|
+
} | {
|
|
13
|
+
ok: false;
|
|
14
|
+
failure: "tooLarge" | "malformed" | "invalid";
|
|
15
|
+
};
|
|
16
|
+
/** Parses one strict BrowserOidcCallbackSuccess form or throws an error carrying the refusal kind. */
|
|
17
|
+
export declare function parseBrowserOidcCallbackSuccessForm(input: Uint8Array | string): BrowserOidcCallbackSuccess;
|
|
18
|
+
/** Writes schema-order name=value pairs with only RFC 3986 unreserved characters unescaped and refuses output the schema rejects. */
|
|
19
|
+
export declare function serializeBrowserOidcCallbackSuccessForm(value: BrowserOidcCallbackSuccess): Uint8Array;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
export function isBrowserOidcCallbackSuccess(value) { return check0(value); }
|
|
2
|
+
/** The schema's declared form-urlencoded document bound in bytes. */
|
|
3
|
+
export const browserOidcCallbackSuccessFormMaxBytes = 16384;
|
|
4
|
+
/** Parses one strict BrowserOidcCallbackSuccess form; refusal kinds match the C# codec. */
|
|
5
|
+
export function tryParseBrowserOidcCallbackSuccessForm(input) {
|
|
6
|
+
let bytes;
|
|
7
|
+
if (typeof input === "string") {
|
|
8
|
+
if (!validText(input))
|
|
9
|
+
return { ok: false, failure: "malformed" };
|
|
10
|
+
bytes = new TextEncoder().encode(input);
|
|
11
|
+
}
|
|
12
|
+
else
|
|
13
|
+
bytes = input;
|
|
14
|
+
if (bytes.byteLength > 16384)
|
|
15
|
+
return { ok: false, failure: "tooLarge" };
|
|
16
|
+
const decoded = decodeForm(bytes);
|
|
17
|
+
if (decoded === undefined)
|
|
18
|
+
return { ok: false, failure: "malformed" };
|
|
19
|
+
return isBrowserOidcCallbackSuccess(decoded) ? { ok: true, value: decoded } : { ok: false, failure: "invalid" };
|
|
20
|
+
}
|
|
21
|
+
/** Parses one strict BrowserOidcCallbackSuccess form or throws an error carrying the refusal kind. */
|
|
22
|
+
export function parseBrowserOidcCallbackSuccessForm(input) {
|
|
23
|
+
const result = tryParseBrowserOidcCallbackSuccessForm(input);
|
|
24
|
+
if (!result.ok)
|
|
25
|
+
throw Object.assign(new Error(`BrowserOidcCallbackSuccess form refused: ${result.failure}.`), { failure: result.failure });
|
|
26
|
+
return result.value;
|
|
27
|
+
}
|
|
28
|
+
/** Writes schema-order name=value pairs with only RFC 3986 unreserved characters unescaped and refuses output the schema rejects. */
|
|
29
|
+
export function serializeBrowserOidcCallbackSuccessForm(value) {
|
|
30
|
+
const out = [];
|
|
31
|
+
for (const name of ["code", "state"]) {
|
|
32
|
+
const item = value[name];
|
|
33
|
+
if (item === undefined)
|
|
34
|
+
continue;
|
|
35
|
+
if (!validText(item))
|
|
36
|
+
throw Object.assign(new Error("BrowserOidcCallbackSuccess form refused: invalid."), { failure: "invalid" });
|
|
37
|
+
if (out.length !== 0)
|
|
38
|
+
out.push("&");
|
|
39
|
+
encodeFormComponent(name, out);
|
|
40
|
+
out.push("=");
|
|
41
|
+
encodeFormComponent(item, out);
|
|
42
|
+
}
|
|
43
|
+
const bytes = new TextEncoder().encode(out.join(""));
|
|
44
|
+
const result = tryParseBrowserOidcCallbackSuccessForm(bytes);
|
|
45
|
+
if (!result.ok)
|
|
46
|
+
throw Object.assign(new Error(`BrowserOidcCallbackSuccess form refused: ${result.failure}.`), { failure: result.failure });
|
|
47
|
+
return bytes;
|
|
48
|
+
}
|
|
49
|
+
function check0(value) {
|
|
50
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
51
|
+
return false;
|
|
52
|
+
const object = value;
|
|
53
|
+
for (const key of Object.keys(object)) {
|
|
54
|
+
switch (key) {
|
|
55
|
+
case "code":
|
|
56
|
+
if (!check1(object[key]))
|
|
57
|
+
return false;
|
|
58
|
+
break;
|
|
59
|
+
case "state":
|
|
60
|
+
if (!check2(object[key]))
|
|
61
|
+
return false;
|
|
62
|
+
break;
|
|
63
|
+
default: return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!Object.prototype.hasOwnProperty.call(object, "code"))
|
|
67
|
+
return false;
|
|
68
|
+
if (!Object.prototype.hasOwnProperty.call(object, "state"))
|
|
69
|
+
return false;
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
function check1(value) {
|
|
73
|
+
if (typeof value !== 'string' || !validText(value))
|
|
74
|
+
return false;
|
|
75
|
+
if ([...value].length < 1)
|
|
76
|
+
return false;
|
|
77
|
+
if ([...value].length > 2048)
|
|
78
|
+
return false;
|
|
79
|
+
if ((new RegExp("^[\\x21-\\x7E]+$", 'u')).exec(value)?.[0] !== value)
|
|
80
|
+
return false;
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
function check2(value) {
|
|
84
|
+
if (typeof value !== 'string' || !validText(value))
|
|
85
|
+
return false;
|
|
86
|
+
if ([...value].length < 1)
|
|
87
|
+
return false;
|
|
88
|
+
if ([...value].length > 128)
|
|
89
|
+
return false;
|
|
90
|
+
if ((new RegExp("^[\\x21-\\x7E]+$", 'u')).exec(value)?.[0] !== value)
|
|
91
|
+
return false;
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
function validText(value) {
|
|
95
|
+
for (const scalar of value) {
|
|
96
|
+
const point = scalar.codePointAt(0);
|
|
97
|
+
if (point >= 0xd800 && point <= 0xdfff)
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
function hexValue(byte) {
|
|
103
|
+
if (byte >= 0x30 && byte <= 0x39)
|
|
104
|
+
return byte - 0x30;
|
|
105
|
+
if (byte >= 0x61 && byte <= 0x66)
|
|
106
|
+
return byte - 0x61 + 10;
|
|
107
|
+
if (byte >= 0x41 && byte <= 0x46)
|
|
108
|
+
return byte - 0x41 + 10;
|
|
109
|
+
return -1;
|
|
110
|
+
}
|
|
111
|
+
function decodeFormComponent(input) {
|
|
112
|
+
const bytes = [];
|
|
113
|
+
for (let i = 0; i < input.length; i++) {
|
|
114
|
+
const byte = input[i];
|
|
115
|
+
if (byte === 0x2b) {
|
|
116
|
+
bytes.push(0x20);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (byte === 0x25) {
|
|
120
|
+
if (i + 2 >= input.length)
|
|
121
|
+
return undefined;
|
|
122
|
+
const high = hexValue(input[i + 1]);
|
|
123
|
+
const low = hexValue(input[i + 2]);
|
|
124
|
+
if (high < 0 || low < 0)
|
|
125
|
+
return undefined;
|
|
126
|
+
bytes.push(high * 16 + low);
|
|
127
|
+
i += 2;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (byte < 0x21 || byte > 0x7e)
|
|
131
|
+
return undefined;
|
|
132
|
+
bytes.push(byte);
|
|
133
|
+
}
|
|
134
|
+
let text;
|
|
135
|
+
try {
|
|
136
|
+
text = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(Uint8Array.from(bytes));
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
for (const char of text) {
|
|
142
|
+
const point = char.codePointAt(0);
|
|
143
|
+
if (point < 0x20 || point === 0x7f)
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
return text;
|
|
147
|
+
}
|
|
148
|
+
/** Strict form syntax: printable ASCII, name=value pairs, percent escapes, UTF-8 text and no duplicate or empty names. */
|
|
149
|
+
function decodeForm(input) {
|
|
150
|
+
if (input.length === 0)
|
|
151
|
+
return undefined;
|
|
152
|
+
const out = {};
|
|
153
|
+
const names = new Set();
|
|
154
|
+
let start = 0;
|
|
155
|
+
for (;;) {
|
|
156
|
+
let end = input.indexOf(0x26, start);
|
|
157
|
+
const last = end < 0;
|
|
158
|
+
if (last)
|
|
159
|
+
end = input.length;
|
|
160
|
+
const segment = input.subarray(start, end);
|
|
161
|
+
const equals = segment.indexOf(0x3d);
|
|
162
|
+
if (equals <= 0)
|
|
163
|
+
return undefined;
|
|
164
|
+
const name = decodeFormComponent(segment.subarray(0, equals));
|
|
165
|
+
const value = decodeFormComponent(segment.subarray(equals + 1));
|
|
166
|
+
if (name === undefined || value === undefined || names.has(name))
|
|
167
|
+
return undefined;
|
|
168
|
+
names.add(name);
|
|
169
|
+
// defineProperty keeps names such as __proto__ as ordinary own properties.
|
|
170
|
+
Object.defineProperty(out, name, { value, enumerable: true, writable: true, configurable: true });
|
|
171
|
+
if (last)
|
|
172
|
+
return out;
|
|
173
|
+
start = end + 1;
|
|
174
|
+
if (start === input.length)
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function encodeFormComponent(value, out) {
|
|
179
|
+
for (const byte of new TextEncoder().encode(value)) {
|
|
180
|
+
if ((byte >= 0x41 && byte <= 0x5a) || (byte >= 0x61 && byte <= 0x7a) || (byte >= 0x30 && byte <= 0x39) || byte === 0x2d || byte === 0x2e || byte === 0x5f || byte === 0x7e)
|
|
181
|
+
out.push(String.fromCharCode(byte));
|
|
182
|
+
else
|
|
183
|
+
out.push("%" + byte.toString(16).toUpperCase().padStart(2, "0"));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface BrowserReceipt {
|
|
2
|
+
commandId: string;
|
|
3
|
+
resultRevision?: string;
|
|
4
|
+
effect: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function isBrowserReceipt(value: unknown): value is BrowserReceipt;
|
|
7
|
+
/** The schema's declared UTF-8 document bound in bytes. */
|
|
8
|
+
export declare const browserReceiptJsonMaxBytes = 4096;
|
|
9
|
+
/** Parses one strict BrowserReceipt document; refusal kinds match the C# codec. */
|
|
10
|
+
export declare function tryParseBrowserReceiptJson(input: Uint8Array | string): {
|
|
11
|
+
ok: true;
|
|
12
|
+
value: BrowserReceipt;
|
|
13
|
+
} | {
|
|
14
|
+
ok: false;
|
|
15
|
+
failure: "tooLarge" | "malformed" | "invalid";
|
|
16
|
+
};
|
|
17
|
+
/** Parses one strict BrowserReceipt document or throws an error carrying the refusal kind. */
|
|
18
|
+
export declare function parseBrowserReceiptJson(input: Uint8Array | string): BrowserReceipt;
|
|
19
|
+
/** Writes compact UTF-8 in schema property order and refuses output the schema rejects. */
|
|
20
|
+
export declare function serializeBrowserReceiptJson(value: BrowserReceipt): Uint8Array;
|