@openid4vc/utils 0.3.1-alpha-20251124151046 → 0.4.0-alpha-20251127093634

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 CHANGED
@@ -1,16 +1,12 @@
1
1
  {
2
2
  "name": "@openid4vc/utils",
3
- "version": "0.3.1-alpha-20251124151046",
3
+ "version": "0.4.0-alpha-20251127093634",
4
4
  "files": [
5
5
  "dist"
6
6
  ],
7
7
  "license": "Apache-2.0",
8
8
  "exports": {
9
- ".": {
10
- "import": "./dist/index.mjs",
11
- "require": "./dist/index.cjs",
12
- "types": "./dist/index.d.mts"
13
- },
9
+ ".": "./dist/index.mjs",
14
10
  "./package.json": "./package.json"
15
11
  },
16
12
  "homepage": "https://github.com/openwallet-foundation-labs/oid4vc-ts/tree/main/packages/utils",
@@ -24,9 +20,8 @@
24
20
  "zod": "^4.1.13"
25
21
  },
26
22
  "scripts": {
27
- "build": "tsdown src/index.ts --format cjs,esm --dts --sourcemap"
23
+ "build": "tsdown src/index.ts --format esm --dts --sourcemap"
28
24
  },
29
- "main": "./dist/index.cjs",
30
25
  "module": "./dist/index.mjs",
31
26
  "types": "./dist/index.d.mts"
32
27
  }
package/dist/index.cjs DELETED
@@ -1,434 +0,0 @@
1
- //#region rolldown:runtime
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) {
13
- __defProp(to, key, {
14
- get: ((k) => from[k]).bind(null, key),
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- }
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
- value: mod,
24
- enumerable: true
25
- }) : target, mod));
26
-
27
- //#endregion
28
- let buffer = require("buffer");
29
- let zod = require("zod");
30
- zod = __toESM(zod);
31
-
32
- //#region src/array.ts
33
- /**
34
- * Only primitive types allowed
35
- * Must have not duplicate entries (will always return false in this case)
36
- */
37
- function arrayEqualsIgnoreOrder(a, b) {
38
- if (new Set(a).size !== new Set(b).size) return false;
39
- if (a.length !== b.length) return false;
40
- return a.every((k) => b.includes(k));
41
- }
42
-
43
- //#endregion
44
- //#region src/config.ts
45
- let GLOBAL_CONFIG = { allowInsecureUrls: false };
46
- function setGlobalConfig(config) {
47
- GLOBAL_CONFIG = config;
48
- }
49
- function getGlobalConfig() {
50
- return GLOBAL_CONFIG;
51
- }
52
-
53
- //#endregion
54
- //#region src/content-type.ts
55
- let ContentType = /* @__PURE__ */ function(ContentType$1) {
56
- ContentType$1["XWwwFormUrlencoded"] = "application/x-www-form-urlencoded";
57
- ContentType$1["Json"] = "application/json";
58
- ContentType$1["JwkSet"] = "application/jwk-set+json";
59
- ContentType$1["OAuthAuthorizationRequestJwt"] = "application/oauth-authz-req+jwt";
60
- ContentType$1["Jwt"] = "application/jwt";
61
- ContentType$1["Html"] = "text/html";
62
- return ContentType$1;
63
- }({});
64
- function isContentType(contentType, value) {
65
- return value.toLowerCase().includes(contentType);
66
- }
67
- function isResponseContentType(contentType, response) {
68
- const contentTypeArray = Array.isArray(contentType) ? contentType : [contentType];
69
- const header = response.headers.get("Content-Type");
70
- if (!header) return false;
71
- return contentTypeArray.some((contentTypeEntry) => isContentType(contentTypeEntry, header));
72
- }
73
-
74
- //#endregion
75
- //#region src/date.ts
76
- /**
77
- * Get the time in seconds since epoch for a date.
78
- * If date is not provided the current time will be used.
79
- */
80
- function dateToSeconds(date) {
81
- const milliseconds = date?.getTime() ?? Date.now();
82
- return Math.floor(milliseconds / 1e3);
83
- }
84
- function addSecondsToDate(date, seconds) {
85
- return new Date(date.getTime() + seconds * 1e3);
86
- }
87
-
88
- //#endregion
89
- //#region src/encoding.ts
90
- function decodeUtf8String(string) {
91
- return new Uint8Array(buffer.Buffer.from(string, "utf-8"));
92
- }
93
- function encodeToUtf8String(data) {
94
- return buffer.Buffer.from(data).toString("utf-8");
95
- }
96
- /**
97
- * Also supports base64 url
98
- */
99
- function decodeBase64(base64) {
100
- return new Uint8Array(buffer.Buffer.from(base64, "base64"));
101
- }
102
- function encodeToBase64(data) {
103
- if (typeof data === "string") return buffer.Buffer.from(data).toString("base64");
104
- return buffer.Buffer.from(data).toString("base64");
105
- }
106
- function encodeToBase64Url(data) {
107
- return base64ToBase64Url(encodeToBase64(data));
108
- }
109
- /**
110
- * The 'buffer' npm library does not support base64url.
111
- */
112
- function base64ToBase64Url(base64) {
113
- return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
114
- }
115
-
116
- //#endregion
117
- //#region src/error/InvalidFetchResponseError.ts
118
- var InvalidFetchResponseError = class extends Error {
119
- constructor(message, textResponse, response) {
120
- const textResponseMessage = isResponseContentType(ContentType.Html, response) ? void 0 : textResponse.substring(0, 1e3);
121
- super(textResponseMessage ? `${message}\n${textResponseMessage}` : message);
122
- this.textResponse = textResponse;
123
- this.response = response.clone();
124
- }
125
- };
126
-
127
- //#endregion
128
- //#region src/error/JsonParseError.ts
129
- var JsonParseError = class extends Error {
130
- constructor(message, jsonString) {
131
- super(`${message}\n${jsonString}`);
132
- }
133
- };
134
-
135
- //#endregion
136
- //#region src/error/ValidationError.ts
137
- var ValidationError = class extends Error {
138
- constructor(message, zodError) {
139
- super(message);
140
- this.message = `${message}\n${zodError ? zod.default.prettifyError(zodError) : ""}`;
141
- Object.defineProperty(this, "zodError", {
142
- value: zodError,
143
- writable: false,
144
- enumerable: false
145
- });
146
- }
147
- };
148
-
149
- //#endregion
150
- //#region src/error/FetchError.ts
151
- var FetchError = class extends Error {
152
- constructor(message, { cause } = {}) {
153
- super(`${message}\nCause: ${cause?.message}`);
154
- this.cause = cause;
155
- }
156
- };
157
-
158
- //#endregion
159
- //#region src/globals.ts
160
- const _URL = URL;
161
- const _URLSearchParams = URLSearchParams;
162
- const _Headers = Headers;
163
-
164
- //#endregion
165
- //#region src/fetcher.ts
166
- /**
167
- * The default fetcher used by createZodFetcher when no
168
- * fetcher is provided.
169
- */
170
- const defaultFetcher = fetch;
171
- function createFetcher(fetcher = defaultFetcher) {
172
- return (input, init, ...args) => {
173
- return fetcher(input, init ? {
174
- ...init,
175
- body: init.body instanceof _URLSearchParams ? init.body.toString() : init.body
176
- } : void 0, ...args).catch((error) => {
177
- throw new FetchError(`Unknown error occurred during fetch to '${input}'`, { cause: error });
178
- });
179
- };
180
- }
181
- /**
182
- * Creates a `fetchWithZod` function that takes in a schema of
183
- * the expected response, and the arguments to the fetcher
184
- * you provided.
185
- *
186
- * @example
187
- *
188
- * const fetchWithZod = createZodFetcher((url) => {
189
- * return fetch(url).then((res) => res.json());
190
- * });
191
- *
192
- * const response = await fetchWithZod(
193
- * z.object({
194
- * hello: z.string(),
195
- * }),
196
- * "https://example.com",
197
- * );
198
- */
199
- function createZodFetcher(fetcher) {
200
- return async (schema, expectedContentType, ...args) => {
201
- const response = await createFetcher(fetcher)(...args);
202
- const expectedContentTypeArray = Array.isArray(expectedContentType) ? expectedContentType : [expectedContentType];
203
- if (response.ok && !isResponseContentType(expectedContentTypeArray, response)) throw new InvalidFetchResponseError(`Expected response to match content type ${expectedContentTypeArray.join(" | ")}, but received '${response.headers.get("Content-Type")}'`, await response.clone().text(), response);
204
- if (isResponseContentType([ContentType.OAuthAuthorizationRequestJwt, ContentType.Jwt], response)) return {
205
- response,
206
- result: response.ok ? schema.safeParse(await response.text()) : void 0
207
- };
208
- return {
209
- response,
210
- result: response.ok ? schema.safeParse(await response.json()) : void 0
211
- };
212
- };
213
- }
214
-
215
- //#endregion
216
- //#region src/object.ts
217
- function isObject(item) {
218
- return item != null && typeof item === "object" && !Array.isArray(item);
219
- }
220
- /**
221
- * Deep merge two objects.
222
- * @param target
223
- * @param ...sources
224
- */
225
- function mergeDeep(target, ...sources) {
226
- if (!sources.length) return target;
227
- const source = sources.shift();
228
- if (isObject(target) && isObject(source)) for (const key in source) if (isObject(source[key])) {
229
- if (!target[key]) Object.assign(target, { [key]: {} });
230
- mergeDeep(target[key], source[key]);
231
- } else Object.assign(target, { [key]: source[key] });
232
- return mergeDeep(target, ...sources);
233
- }
234
-
235
- //#endregion
236
- //#region src/parse.ts
237
- function stringToJsonWithErrorHandling(string, errorMessage) {
238
- try {
239
- return JSON.parse(string);
240
- } catch (_error) {
241
- throw new JsonParseError(errorMessage ?? "Unable to parse string to JSON.", string);
242
- }
243
- }
244
- function parseIfJson(data) {
245
- if (typeof data !== "string") return data;
246
- try {
247
- return JSON.parse(data);
248
- } catch (_error) {}
249
- return data;
250
- }
251
- function parseWithErrorHandling(schema, data, customErrorMessage) {
252
- const parseResult = schema.safeParse(data);
253
- if (!parseResult.success) throw new ValidationError(customErrorMessage ?? `Error validating schema with data ${JSON.stringify(data)}`, parseResult.error);
254
- return parseResult.data;
255
- }
256
-
257
- //#endregion
258
- //#region src/path.ts
259
- /**
260
- * Combine multiple uri parts into a single uri taking into account slashes.
261
- *
262
- * @param parts the parts to combine
263
- * @returns the combined url
264
- */
265
- function joinUriParts(base, parts) {
266
- if (parts.length === 0) return base;
267
- let combined = base.trim();
268
- combined = base.endsWith("/") ? base.slice(0, base.length - 1) : base;
269
- for (const part of parts) {
270
- let strippedPart = part.trim();
271
- strippedPart = strippedPart.startsWith("/") ? strippedPart.slice(1) : strippedPart;
272
- strippedPart = strippedPart.endsWith("/") ? strippedPart.slice(0, strippedPart.length - 1) : strippedPart;
273
- if (strippedPart === "") continue;
274
- combined += `/${strippedPart}`;
275
- }
276
- return combined;
277
- }
278
-
279
- //#endregion
280
- //#region src/url.ts
281
- function getQueryParams(url) {
282
- const searchParams = new _URLSearchParams(new _URL(url).search);
283
- const params = {};
284
- searchParams.forEach((value, key) => {
285
- params[key] = value;
286
- });
287
- return params;
288
- }
289
- function objectToQueryParams(object) {
290
- const params = new _URLSearchParams();
291
- for (const [key, value] of Object.entries(object)) if (value != null) params.append(key, typeof value === "object" ? JSON.stringify(value) : String(value));
292
- return params;
293
- }
294
-
295
- //#endregion
296
- //#region src/validation.ts
297
- const zHttpsUrl = zod.default.url().refine((url) => {
298
- const { allowInsecureUrls } = getGlobalConfig();
299
- return allowInsecureUrls ? url.startsWith("http://") || url.startsWith("https://") : url.startsWith("https://");
300
- }, { message: "url must be an https:// url" });
301
- const zDataUrl = zod.default.string().regex(/data:[\w/\-.]+;\w+,.*/, "url must be a data URL");
302
- const zInteger = zod.default.number().int();
303
- const zHttpMethod = zod.default.enum([
304
- "GET",
305
- "POST",
306
- "PUT",
307
- "DELETE",
308
- "HEAD",
309
- "OPTIONS",
310
- "TRACE",
311
- "CONNECT",
312
- "PATCH"
313
- ]);
314
- const zStringToJson = zod.default.string().transform((string, ctx) => {
315
- try {
316
- return JSON.parse(string);
317
- } catch (_error) {
318
- ctx.addIssue({
319
- code: "custom",
320
- message: "Expected a JSON string, but could not parse the string to JSON"
321
- });
322
- return zod.default.NEVER;
323
- }
324
- });
325
- const zIs = (schema, data) => schema.safeParse(data).success;
326
-
327
- //#endregion
328
- //#region src/www-authenticate.ts
329
- const unquote = (value) => value.substring(1, value.length - 1).replace(/\\"/g, "\"");
330
- const sanitize = (value) => value.charAt(0) === "\"" ? unquote(value) : value.trim();
331
- const body = /((?:[a-zA-Z0-9._~+/-]+=*(?:\s+|$))|[^\u0000-\u001F\u007F()<>@,;:\\"/?={}[\]\u0020\u0009]+)(?:=([^\\"=\s,]+|"(?:[^"\\]|\\.)*"))?/g;
332
- const parsePayload = (scheme, string) => {
333
- const payload = {};
334
- while (true) {
335
- const res = body.exec(string);
336
- if (!res) break;
337
- const [, key, newValue] = res;
338
- const payloadValue = payload[key];
339
- if (newValue) {
340
- const sanitizedValue = sanitize(newValue);
341
- payload[key] = payloadValue ? Array.isArray(payloadValue) ? [...payloadValue, sanitizedValue] : [payloadValue, sanitizedValue] : sanitizedValue;
342
- } else if (!payloadValue) payload[key] = null;
343
- }
344
- return {
345
- scheme,
346
- payload
347
- };
348
- };
349
- function parseWwwAuthenticateHeader(str) {
350
- const start = str.indexOf(" ");
351
- let scheme = str.substring(0, start);
352
- let value = str.substring(start);
353
- const challenges = [];
354
- const endsWithSchemeTest = /, ?(Bearer|DPoP|Basic)$/.exec(value);
355
- let endsWithScheme;
356
- if (endsWithSchemeTest) {
357
- value = value.substring(0, value.length - endsWithSchemeTest[0].length);
358
- endsWithScheme = endsWithSchemeTest[1];
359
- }
360
- const additionalSchemesRegex = /(.*?)(, ?)(Bearer|DPoP|Basic)[, ]/;
361
- let match = additionalSchemesRegex.exec(value);
362
- while (match) {
363
- challenges.push(parsePayload(scheme, match[1]));
364
- value = value.substring(match[0].length - 1);
365
- scheme = match[3];
366
- match = additionalSchemesRegex.exec(value);
367
- }
368
- challenges.push(parsePayload(scheme, value));
369
- if (endsWithScheme) challenges.push({
370
- scheme: endsWithScheme,
371
- payload: {}
372
- });
373
- return challenges;
374
- }
375
- function encodeWwwAuthenticateHeader(challenges) {
376
- const entries = [];
377
- for (const challenge of challenges) {
378
- const encodedParams = Object.entries(challenge.payload).flatMap(([key, value]) => {
379
- const encode = (s) => s.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
380
- if (Array.isArray(value)) return value.map((v) => `${key}="${encode(v)}"`);
381
- return value ? `${key}="${encode(value)}"` : key;
382
- });
383
- entries.push(encodedParams.length === 0 ? challenge.scheme : `${challenge.scheme} ${encodedParams.join(", ")}`);
384
- }
385
- return entries.join(", ");
386
- }
387
-
388
- //#endregion
389
- //#region src/zod-error.ts
390
- function formatZodError(error) {
391
- if (!error) return "";
392
- return zod.default.prettifyError(error);
393
- }
394
-
395
- //#endregion
396
- exports.ContentType = ContentType;
397
- exports.Headers = _Headers;
398
- exports.InvalidFetchResponseError = InvalidFetchResponseError;
399
- exports.JsonParseError = JsonParseError;
400
- exports.URL = _URL;
401
- exports.URLSearchParams = _URLSearchParams;
402
- exports.ValidationError = ValidationError;
403
- exports.addSecondsToDate = addSecondsToDate;
404
- exports.arrayEqualsIgnoreOrder = arrayEqualsIgnoreOrder;
405
- exports.createFetcher = createFetcher;
406
- exports.createZodFetcher = createZodFetcher;
407
- exports.dateToSeconds = dateToSeconds;
408
- exports.decodeBase64 = decodeBase64;
409
- exports.decodeUtf8String = decodeUtf8String;
410
- exports.encodeToBase64 = encodeToBase64;
411
- exports.encodeToBase64Url = encodeToBase64Url;
412
- exports.encodeToUtf8String = encodeToUtf8String;
413
- exports.encodeWwwAuthenticateHeader = encodeWwwAuthenticateHeader;
414
- exports.formatZodError = formatZodError;
415
- exports.getGlobalConfig = getGlobalConfig;
416
- exports.getQueryParams = getQueryParams;
417
- exports.isContentType = isContentType;
418
- exports.isObject = isObject;
419
- exports.isResponseContentType = isResponseContentType;
420
- exports.joinUriParts = joinUriParts;
421
- exports.mergeDeep = mergeDeep;
422
- exports.objectToQueryParams = objectToQueryParams;
423
- exports.parseIfJson = parseIfJson;
424
- exports.parseWithErrorHandling = parseWithErrorHandling;
425
- exports.parseWwwAuthenticateHeader = parseWwwAuthenticateHeader;
426
- exports.setGlobalConfig = setGlobalConfig;
427
- exports.stringToJsonWithErrorHandling = stringToJsonWithErrorHandling;
428
- exports.zDataUrl = zDataUrl;
429
- exports.zHttpMethod = zHttpMethod;
430
- exports.zHttpsUrl = zHttpsUrl;
431
- exports.zInteger = zInteger;
432
- exports.zIs = zIs;
433
- exports.zStringToJson = zStringToJson;
434
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","names":["GLOBAL_CONFIG: Oid4vcTsConfig","Buffer","textResponse: string","z","URLSearchParams","URLSearchParams","URL","params: Record<string, string>","z","payload: Record<string, string | string[] | null>","challenges: WwwAuthenticateHeaderChallenge[]","endsWithScheme: string | undefined","entries: string[]","z"],"sources":["../src/array.ts","../src/config.ts","../src/content-type.ts","../src/date.ts","../src/encoding.ts","../src/error/InvalidFetchResponseError.ts","../src/error/JsonParseError.ts","../src/error/ValidationError.ts","../src/error/FetchError.ts","../src/globals.ts","../src/fetcher.ts","../src/object.ts","../src/parse.ts","../src/path.ts","../src/url.ts","../src/validation.ts","../src/www-authenticate.ts","../src/zod-error.ts"],"sourcesContent":["/**\n * Only primitive types allowed\n * Must have not duplicate entries (will always return false in this case)\n */\nexport function arrayEqualsIgnoreOrder<Item extends string | number | boolean>(\n a: Array<Item>,\n b: Array<Item>\n): boolean {\n if (new Set(a).size !== new Set(b).size) return false\n if (a.length !== b.length) return false\n\n return a.every((k) => b.includes(k))\n}\n","export interface Oid4vcTsConfig {\n /**\n * Whether to allow insecure http urls.\n *\n * @default false\n */\n allowInsecureUrls: boolean\n}\n\nlet GLOBAL_CONFIG: Oid4vcTsConfig = {\n allowInsecureUrls: false,\n}\n\nexport function setGlobalConfig(config: Oid4vcTsConfig) {\n GLOBAL_CONFIG = config\n}\n\nexport function getGlobalConfig(): Oid4vcTsConfig {\n return GLOBAL_CONFIG\n}\n","import type { FetchResponse } from './globals'\n\nexport enum ContentType {\n XWwwFormUrlencoded = 'application/x-www-form-urlencoded',\n Json = 'application/json',\n JwkSet = 'application/jwk-set+json',\n OAuthAuthorizationRequestJwt = 'application/oauth-authz-req+jwt',\n Jwt = 'application/jwt',\n Html = 'text/html',\n}\n\nexport function isContentType(contentType: ContentType, value: string) {\n return value.toLowerCase().includes(contentType)\n}\n\nexport function isResponseContentType(contentType: ContentType | ContentType[], response: FetchResponse) {\n const contentTypeArray = Array.isArray(contentType) ? contentType : [contentType]\n\n const header = response.headers.get('Content-Type')\n if (!header) return false\n return contentTypeArray.some((contentTypeEntry) => isContentType(contentTypeEntry, header))\n}\n","/**\n * Get the time in seconds since epoch for a date.\n * If date is not provided the current time will be used.\n */\nexport function dateToSeconds(date?: Date) {\n const milliseconds = date?.getTime() ?? Date.now()\n\n return Math.floor(milliseconds / 1000)\n}\n\nexport function addSecondsToDate(date: Date, seconds: number) {\n return new Date(date.getTime() + seconds * 1000)\n}\n","import { Buffer } from 'buffer'\n\nexport function decodeUtf8String(string: string): Uint8Array {\n return new Uint8Array(Buffer.from(string, 'utf-8'))\n}\n\nexport function encodeToUtf8String(data: Uint8Array) {\n return Buffer.from(data).toString('utf-8')\n}\n\n/**\n * Also supports base64 url\n */\nexport function decodeBase64(base64: string): Uint8Array {\n return new Uint8Array(Buffer.from(base64, 'base64'))\n}\n\nexport function encodeToBase64(data: Uint8Array | string) {\n // To make ts happy. Somehow Uint8Array or string is no bueno\n if (typeof data === 'string') {\n return Buffer.from(data).toString('base64')\n }\n\n return Buffer.from(data).toString('base64')\n}\n\nexport function encodeToBase64Url(data: Uint8Array | string) {\n return base64ToBase64Url(encodeToBase64(data))\n}\n\n/**\n * The 'buffer' npm library does not support base64url.\n */\nfunction base64ToBase64Url(base64: string) {\n return base64.replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=/g, '')\n}\n","import { ContentType, isResponseContentType } from '../content-type'\nimport type { FetchResponse } from '../globals'\n\nexport class InvalidFetchResponseError extends Error {\n public readonly response: FetchResponse\n\n public constructor(\n message: string,\n public readonly textResponse: string,\n response: FetchResponse\n ) {\n // We don't want to put html content in pages. For other content we take the first 1000 characters\n // to prevent ridiculously long errors.\n const textResponseMessage = isResponseContentType(ContentType.Html, response)\n ? undefined\n : textResponse.substring(0, 1000)\n\n super(textResponseMessage ? `${message}\\n${textResponseMessage}` : message)\n\n this.response = response.clone()\n }\n}\n","export class JsonParseError extends Error {\n public constructor(message: string, jsonString: string) {\n super(`${message}\\n${jsonString}`)\n }\n}\n","import z, { type ZodError } from 'zod'\n\nexport class ValidationError extends Error {\n public zodError: ZodError | undefined\n\n constructor(message: string, zodError?: ZodError) {\n super(message)\n\n const formattedError = zodError ? z.prettifyError(zodError) : ''\n this.message = `${message}\\n${formattedError}`\n\n Object.defineProperty(this, 'zodError', {\n value: zodError,\n writable: false,\n enumerable: false,\n })\n }\n}\n","export class FetchError extends Error {\n public readonly cause?: Error\n\n public constructor(message: string, { cause }: { cause?: Error } = {}) {\n super(`${message}\\nCause: ${cause?.message}`)\n this.cause = cause\n }\n}\n","// Theses types are provided by the platform (so @types/node, @types/react-native, DOM)\n\n// biome-ignore lint/style/noRestrictedGlobals: no explanation\nconst _URL = URL\n\n// biome-ignore lint/style/noRestrictedGlobals: no explanation\nconst _URLSearchParams = URLSearchParams\n\n// biome-ignore lint/style/noRestrictedGlobals: no explanation\nexport type Fetch = typeof fetch\n// biome-ignore lint/style/noRestrictedGlobals: no explanation\nexport type FetchResponse = Response\n// biome-ignore lint/style/noRestrictedGlobals: no explanation\nconst _Headers = Headers as typeof globalThis.Headers\nexport type FetchHeaders = globalThis.Headers\nexport type FetchRequestInit = RequestInit\n\nexport { _URLSearchParams as URLSearchParams, _URL as URL, _Headers as Headers }\n","import type z from 'zod'\nimport { ContentType, isResponseContentType } from './content-type'\nimport { FetchError } from './error/FetchError'\nimport { InvalidFetchResponseError } from './error/InvalidFetchResponseError'\nimport { type Fetch, URLSearchParams } from './globals'\n\n/**\n * A type utility which represents the function returned\n * from createZodFetcher\n */\nexport type ZodFetcher = <Schema extends z.ZodTypeAny>(\n schema: Schema,\n expectedContentType: ContentType | ContentType[],\n ...args: Parameters<Fetch>\n) => Promise<{ response: Awaited<ReturnType<Fetch>>; result?: z.ZodSafeParseResult<z.infer<Schema>> }>\n\n/**\n * The default fetcher used by createZodFetcher when no\n * fetcher is provided.\n */\n// biome-ignore lint/style/noRestrictedGlobals: this is the only place where we use the global\nconst defaultFetcher = fetch\n\nexport function createFetcher(fetcher = defaultFetcher): Fetch {\n return (input, init, ...args) => {\n return fetcher(\n input,\n init\n ? {\n ...init,\n // React Native does not seem to handle the toString(). This is hard to catch when running\n // tests in Node.JS where this does work correctly. so we handle it here.\n body: init.body instanceof URLSearchParams ? init.body.toString() : init.body,\n }\n : undefined,\n ...args\n ).catch((error) => {\n throw new FetchError(`Unknown error occurred during fetch to '${input}'`, { cause: error })\n })\n }\n}\n\n/**\n * Creates a `fetchWithZod` function that takes in a schema of\n * the expected response, and the arguments to the fetcher\n * you provided.\n *\n * @example\n *\n * const fetchWithZod = createZodFetcher((url) => {\n * return fetch(url).then((res) => res.json());\n * });\n *\n * const response = await fetchWithZod(\n * z.object({\n * hello: z.string(),\n * }),\n * \"https://example.com\",\n * );\n */\nexport function createZodFetcher(fetcher?: Fetch): ZodFetcher {\n return async (schema, expectedContentType, ...args) => {\n const response = await createFetcher(fetcher)(...args)\n\n const expectedContentTypeArray = Array.isArray(expectedContentType) ? expectedContentType : [expectedContentType]\n\n if (response.ok && !isResponseContentType(expectedContentTypeArray, response)) {\n throw new InvalidFetchResponseError(\n `Expected response to match content type ${expectedContentTypeArray.join(' | ')}, but received '${response.headers.get('Content-Type')}'`,\n await response.clone().text(),\n response\n )\n }\n\n if (isResponseContentType([ContentType.OAuthAuthorizationRequestJwt, ContentType.Jwt], response)) {\n return {\n response,\n result: response.ok ? schema.safeParse(await response.text()) : undefined,\n }\n }\n\n return {\n response,\n result: response.ok ? schema.safeParse(await response.json()) : undefined,\n }\n }\n}\n","export function isObject(item: unknown): item is Record<string, unknown> {\n return item != null && typeof item === 'object' && !Array.isArray(item)\n}\n\n/**\n * Deep merge two objects.\n * @param target\n * @param ...sources\n */\nexport function mergeDeep(target: unknown, ...sources: Array<unknown>): unknown {\n if (!sources.length) return target\n const source = sources.shift()\n\n if (isObject(target) && isObject(source)) {\n for (const key in source) {\n if (isObject(source[key])) {\n if (!target[key]) Object.assign(target, { [key]: {} })\n mergeDeep(target[key], source[key])\n } else {\n Object.assign(target, { [key]: source[key] })\n }\n }\n }\n\n return mergeDeep(target, ...sources)\n}\n","import type z from 'zod'\nimport { JsonParseError } from './error/JsonParseError'\nimport { ValidationError } from './error/ValidationError'\n\nexport type BaseSchema = z.ZodTypeAny\n// biome-ignore lint/suspicious/noExplicitAny: no explanation\nexport type InferOutputUnion<T extends readonly any[]> = {\n [K in keyof T]: z.infer<T[K]>\n}[number]\n\nexport function stringToJsonWithErrorHandling(string: string, errorMessage?: string) {\n try {\n return JSON.parse(string)\n } catch (_error) {\n throw new JsonParseError(errorMessage ?? 'Unable to parse string to JSON.', string)\n }\n}\n\nexport function parseIfJson<T>(data: T): T | Record<string, unknown> {\n if (typeof data !== 'string') {\n return data\n }\n\n try {\n // Try to parse the string as JSON\n return JSON.parse(data)\n } catch (_error) {}\n\n return data\n}\n\nexport function parseWithErrorHandling<Schema extends BaseSchema>(\n schema: Schema,\n data: unknown,\n customErrorMessage?: string\n): z.infer<Schema> {\n const parseResult = schema.safeParse(data)\n\n if (!parseResult.success) {\n throw new ValidationError(\n customErrorMessage ?? `Error validating schema with data ${JSON.stringify(data)}`,\n parseResult.error\n )\n }\n\n return parseResult.data\n}\n","/**\n * Combine multiple uri parts into a single uri taking into account slashes.\n *\n * @param parts the parts to combine\n * @returns the combined url\n */\nexport function joinUriParts(base: string, parts: string[]) {\n if (parts.length === 0) return base\n\n // take base without trailing /\n let combined = base.trim()\n combined = base.endsWith('/') ? base.slice(0, base.length - 1) : base\n\n for (const part of parts) {\n // Remove leading and trailing /\n let strippedPart = part.trim()\n strippedPart = strippedPart.startsWith('/') ? strippedPart.slice(1) : strippedPart\n strippedPart = strippedPart.endsWith('/') ? strippedPart.slice(0, strippedPart.length - 1) : strippedPart\n\n // Don't want to add if empty\n if (strippedPart === '') continue\n\n combined += `/${strippedPart}`\n }\n\n return combined\n}\n","import { URL, URLSearchParams } from './globals'\n\nexport function getQueryParams(url: string) {\n const parsedUrl = new URL(url)\n const searchParams = new URLSearchParams(parsedUrl.search)\n const params: Record<string, string> = {}\n\n searchParams.forEach((value, key) => {\n params[key] = value\n })\n\n return params\n}\n\nexport function objectToQueryParams(object: Record<string, unknown>): InstanceType<typeof URLSearchParams> {\n const params = new URLSearchParams()\n\n for (const [key, value] of Object.entries(object)) {\n if (value != null) {\n params.append(key, typeof value === 'object' ? JSON.stringify(value) : String(value))\n }\n }\n\n return params\n}\n","import z from 'zod'\nimport { getGlobalConfig } from './config'\n\nexport const zHttpsUrl = z.url().refine(\n (url) => {\n const { allowInsecureUrls } = getGlobalConfig()\n return allowInsecureUrls ? url.startsWith('http://') || url.startsWith('https://') : url.startsWith('https://')\n },\n { message: 'url must be an https:// url' }\n)\n\nexport const zDataUrl = z.string().regex(/data:[\\w/\\-.]+;\\w+,.*/, 'url must be a data URL')\n\nexport const zInteger = z.number().int()\n\nexport const zHttpMethod = z.enum(['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS', 'TRACE', 'CONNECT', 'PATCH'])\nexport type HttpMethod = z.infer<typeof zHttpMethod>\n\nexport const zStringToJson = z.string().transform((string, ctx) => {\n try {\n return JSON.parse(string)\n } catch (_error) {\n ctx.addIssue({\n code: 'custom',\n message: 'Expected a JSON string, but could not parse the string to JSON',\n })\n return z.NEVER\n }\n})\n\nexport const zIs = <Schema extends z.ZodSchema>(schema: Schema, data: unknown): data is z.infer<typeof schema> =>\n schema.safeParse(data).success\n","const unquote = (value: string) => value.substring(1, value.length - 1).replace(/\\\\\"/g, '\"')\n// Fixup quoted strings and tokens with spaces around them\nconst sanitize = (value: string) => (value.charAt(0) === '\"' ? unquote(value) : value.trim())\n\n// lol dis\nconst body =\n // biome-ignore lint/suspicious/noControlCharactersInRegex: no explanation\n /((?:[a-zA-Z0-9._~+/-]+=*(?:\\s+|$))|[^\\u0000-\\u001F\\u007F()<>@,;:\\\\\"/?={}[\\]\\u0020\\u0009]+)(?:=([^\\\\\"=\\s,]+|\"(?:[^\"\\\\]|\\\\.)*\"))?/g\n\nexport interface WwwAuthenticateHeaderChallenge {\n scheme: string\n\n /**\n * Record where the keys are the names, and the value can be 0 (null), 1 (string) or multiple (string[])\n * entries\n */\n payload: Record<string, string | string[] | null>\n}\n\nconst parsePayload = (scheme: string, string: string): WwwAuthenticateHeaderChallenge => {\n const payload: Record<string, string | string[] | null> = {}\n\n while (true) {\n const res = body.exec(string)\n if (!res) break\n\n const [, key, newValue] = res\n\n const payloadValue = payload[key]\n if (newValue) {\n const sanitizedValue = sanitize(newValue)\n payload[key] = payloadValue\n ? Array.isArray(payloadValue)\n ? [...payloadValue, sanitizedValue]\n : [payloadValue, sanitizedValue]\n : sanitizedValue\n } else if (!payloadValue) {\n payload[key] = null\n }\n }\n\n return { scheme, payload }\n}\n\nexport function parseWwwAuthenticateHeader(str: string): WwwAuthenticateHeaderChallenge[] {\n const start = str.indexOf(' ')\n let scheme = str.substring(0, start)\n let value = str.substring(start)\n\n const challenges: WwwAuthenticateHeaderChallenge[] = []\n\n // Some well-known schemes to support-multi parsing\n const endsWithSchemeRegex = /, ?(Bearer|DPoP|Basic)$/\n const endsWithSchemeTest = endsWithSchemeRegex.exec(value)\n let endsWithScheme: string | undefined\n if (endsWithSchemeTest) {\n value = value.substring(0, value.length - endsWithSchemeTest[0].length)\n endsWithScheme = endsWithSchemeTest[1]\n }\n\n const additionalSchemesRegex = /(.*?)(, ?)(Bearer|DPoP|Basic)[, ]/\n let match = additionalSchemesRegex.exec(value)\n while (match) {\n challenges.push(parsePayload(scheme, match[1]))\n value = value.substring(match[0].length - 1)\n scheme = match[3]\n\n match = additionalSchemesRegex.exec(value)\n }\n challenges.push(parsePayload(scheme, value))\n if (endsWithScheme) {\n challenges.push({ scheme: endsWithScheme, payload: {} })\n }\n return challenges\n}\n\nexport function encodeWwwAuthenticateHeader(challenges: WwwAuthenticateHeaderChallenge[]) {\n const entries: string[] = []\n\n for (const challenge of challenges) {\n // Encode each parameter according to RFC 7235\n const encodedParams = Object.entries(challenge.payload).flatMap(([key, value]) => {\n const encode = (s: string) => s.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"')\n // Convert value to string and escape special characters\n if (Array.isArray(value)) {\n return value.map((v) => `${key}=\"${encode(v)}\"`)\n }\n\n return value ? `${key}=\"${encode(value)}\"` : key\n })\n\n entries.push(encodedParams.length === 0 ? challenge.scheme : `${challenge.scheme} ${encodedParams.join(', ')}`)\n }\n\n return entries.join(', ')\n}\n","import z from 'zod'\n\nexport function formatZodError(error?: z.ZodError): string {\n if (!error) return ''\n\n return z.prettifyError(error)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,SAAgB,uBACd,GACA,GACS;AACT,KAAI,IAAI,IAAI,EAAE,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC,KAAM,QAAO;AAChD,KAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAElC,QAAO,EAAE,OAAO,MAAM,EAAE,SAAS,EAAE,CAAC;;;;;ACFtC,IAAIA,gBAAgC,EAClC,mBAAmB,OACpB;AAED,SAAgB,gBAAgB,QAAwB;AACtD,iBAAgB;;AAGlB,SAAgB,kBAAkC;AAChD,QAAO;;;;;AChBT,IAAY,sDAAL;AACL;AACA;AACA;AACA;AACA;AACA;;;AAGF,SAAgB,cAAc,aAA0B,OAAe;AACrE,QAAO,MAAM,aAAa,CAAC,SAAS,YAAY;;AAGlD,SAAgB,sBAAsB,aAA0C,UAAyB;CACvG,MAAM,mBAAmB,MAAM,QAAQ,YAAY,GAAG,cAAc,CAAC,YAAY;CAEjF,MAAM,SAAS,SAAS,QAAQ,IAAI,eAAe;AACnD,KAAI,CAAC,OAAQ,QAAO;AACpB,QAAO,iBAAiB,MAAM,qBAAqB,cAAc,kBAAkB,OAAO,CAAC;;;;;;;;;AChB7F,SAAgB,cAAc,MAAa;CACzC,MAAM,eAAe,MAAM,SAAS,IAAI,KAAK,KAAK;AAElD,QAAO,KAAK,MAAM,eAAe,IAAK;;AAGxC,SAAgB,iBAAiB,MAAY,SAAiB;AAC5D,QAAO,IAAI,KAAK,KAAK,SAAS,GAAG,UAAU,IAAK;;;;;ACTlD,SAAgB,iBAAiB,QA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;AAE5C,YAAW,KAAK,aAAa,QAAQ,MAAM,CAAC;AAC5C,KAAI,eACF,YAAW,KAAK;EAAE,QAAQ;EAAgB,SAAS,EAAE;EAAE,CAAC;AAE1D,QAAO;;AAGT,SAAgB,4BAA4B,YAA8C;CACxF,MAAMC,UAAoB,EAAE;AAE5B,MAAK,MAAM,aAAa,YAAY;EAElC,MAAM,gBAAgB,OAAO,QAAQ,UAAU,QAAQ,CAAC,SAAS,CAAC,KAAK,WAAW;GAChF,MAAM,UAAU,MAAc,EAAE,QAAQ,OAAO,OAAO,CAAC,QAAQ,MAAM,OAAM;AAE3E,OAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,MAAM,KAAK,MAAM,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC,GAAG;AAGlD,UAAO,QAAQ,GAAG,IAAI,IAAI,OAAO,MAAM,CAAC,KAAK;IAC7C;AAEF,UAAQ,KAAK,cAAc,WAAW,IAAI,UAAU,SAAS,GAAG,UAAU,OAAO,GAAG,cAAc,KAAK,KAAK,GAAG;;AAGjH,QAAO,QAAQ,KAAK,KAAK;;;;;AC5F3B,SAAgB,eAAe,OAA4B;AACzD,KAAI,CAAC,MAAO,QAAO;AAEnB,QAAOC,YAAE,cAAc,MAAM"}
package/dist/index.d.cts DELETED
@@ -1,191 +0,0 @@
1
- import z, { ZodError } from "zod";
2
-
3
- //#region src/array.d.ts
4
-
5
- /**
6
- * Only primitive types allowed
7
- * Must have not duplicate entries (will always return false in this case)
8
- */
9
- declare function arrayEqualsIgnoreOrder<Item extends string | number | boolean>(a: Array<Item>, b: Array<Item>): boolean;
10
- //#endregion
11
- //#region src/config.d.ts
12
- interface Oid4vcTsConfig {
13
- /**
14
- * Whether to allow insecure http urls.
15
- *
16
- * @default false
17
- */
18
- allowInsecureUrls: boolean;
19
- }
20
- declare function setGlobalConfig(config: Oid4vcTsConfig): void;
21
- declare function getGlobalConfig(): Oid4vcTsConfig;
22
- //#endregion
23
- //#region src/globals.d.ts
24
- declare const _URL: {
25
- new (url: string | URL, base?: string | URL): URL;
26
- prototype: URL;
27
- canParse(url: string | URL, base?: string | URL): boolean;
28
- createObjectURL(obj: Blob | MediaSource): string;
29
- parse(url: string | URL, base?: string | URL): URL | null;
30
- revokeObjectURL(url: string): void;
31
- };
32
- declare const _URLSearchParams: {
33
- new (init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
34
- prototype: URLSearchParams;
35
- };
36
- type Fetch = typeof fetch;
37
- type FetchResponse = Response;
38
- declare const _Headers: typeof globalThis.Headers;
39
- type FetchHeaders = globalThis.Headers;
40
- type FetchRequestInit = RequestInit;
41
- //#endregion
42
- //#region src/content-type.d.ts
43
- declare enum ContentType {
44
- XWwwFormUrlencoded = "application/x-www-form-urlencoded",
45
- Json = "application/json",
46
- JwkSet = "application/jwk-set+json",
47
- OAuthAuthorizationRequestJwt = "application/oauth-authz-req+jwt",
48
- Jwt = "application/jwt",
49
- Html = "text/html",
50
- }
51
- declare function isContentType(contentType: ContentType, value: string): boolean;
52
- declare function isResponseContentType(contentType: ContentType | ContentType[], response: FetchResponse): boolean;
53
- //#endregion
54
- //#region src/date.d.ts
55
- /**
56
- * Get the time in seconds since epoch for a date.
57
- * If date is not provided the current time will be used.
58
- */
59
- declare function dateToSeconds(date?: Date): number;
60
- declare function addSecondsToDate(date: Date, seconds: number): Date;
61
- //#endregion
62
- //#region src/encoding.d.ts
63
- declare function decodeUtf8String(string: string): Uint8Array;
64
- declare function encodeToUtf8String(data: Uint8Array): string;
65
- /**
66
- * Also supports base64 url
67
- */
68
- declare function decodeBase64(base64: string): Uint8Array;
69
- declare function encodeToBase64(data: Uint8Array | string): string;
70
- declare function encodeToBase64Url(data: Uint8Array | string): string;
71
- //#endregion
72
- //#region src/error/InvalidFetchResponseError.d.ts
73
- declare class InvalidFetchResponseError extends Error {
74
- readonly textResponse: string;
75
- readonly response: FetchResponse;
76
- constructor(message: string, textResponse: string, response: FetchResponse);
77
- }
78
- //#endregion
79
- //#region src/error/JsonParseError.d.ts
80
- declare class JsonParseError extends Error {
81
- constructor(message: string, jsonString: string);
82
- }
83
- //#endregion
84
- //#region src/error/ValidationError.d.ts
85
- declare class ValidationError extends Error {
86
- zodError: ZodError | undefined;
87
- constructor(message: string, zodError?: ZodError);
88
- }
89
- //#endregion
90
- //#region src/fetcher.d.ts
91
- /**
92
- * A type utility which represents the function returned
93
- * from createZodFetcher
94
- */
95
- type ZodFetcher = <Schema extends z.ZodTypeAny>(schema: Schema, expectedContentType: ContentType | ContentType[], ...args: Parameters<Fetch>) => Promise<{
96
- response: Awaited<ReturnType<Fetch>>;
97
- result?: z.ZodSafeParseResult<z.infer<Schema>>;
98
- }>;
99
- declare function createFetcher(fetcher?: typeof fetch): Fetch;
100
- /**
101
- * Creates a `fetchWithZod` function that takes in a schema of
102
- * the expected response, and the arguments to the fetcher
103
- * you provided.
104
- *
105
- * @example
106
- *
107
- * const fetchWithZod = createZodFetcher((url) => {
108
- * return fetch(url).then((res) => res.json());
109
- * });
110
- *
111
- * const response = await fetchWithZod(
112
- * z.object({
113
- * hello: z.string(),
114
- * }),
115
- * "https://example.com",
116
- * );
117
- */
118
- declare function createZodFetcher(fetcher?: Fetch): ZodFetcher;
119
- //#endregion
120
- //#region src/object.d.ts
121
- declare function isObject(item: unknown): item is Record<string, unknown>;
122
- /**
123
- * Deep merge two objects.
124
- * @param target
125
- * @param ...sources
126
- */
127
- declare function mergeDeep(target: unknown, ...sources: Array<unknown>): unknown;
128
- //#endregion
129
- //#region src/parse.d.ts
130
- type BaseSchema = z.ZodTypeAny;
131
- type InferOutputUnion<T extends readonly any[]> = { [K in keyof T]: z.infer<T[K]> }[number];
132
- declare function stringToJsonWithErrorHandling(string: string, errorMessage?: string): any;
133
- declare function parseIfJson<T>(data: T): T | Record<string, unknown>;
134
- declare function parseWithErrorHandling<Schema extends BaseSchema>(schema: Schema, data: unknown, customErrorMessage?: string): z.infer<Schema>;
135
- //#endregion
136
- //#region src/path.d.ts
137
- /**
138
- * Combine multiple uri parts into a single uri taking into account slashes.
139
- *
140
- * @param parts the parts to combine
141
- * @returns the combined url
142
- */
143
- declare function joinUriParts(base: string, parts: string[]): string;
144
- //#endregion
145
- //#region src/type.d.ts
146
- type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
147
- type Optional<T, K$1 extends keyof T> = Omit<T, K$1> & Partial<Pick<T, K$1>>;
148
- type StringWithAutoCompletion<T extends string> = T | (string & {});
149
- type OrPromise<T> = T | Promise<T>;
150
- type NonEmptyArray<T> = [T, ...T[]];
151
- //#endregion
152
- //#region src/url.d.ts
153
- declare function getQueryParams(url: string): Record<string, string>;
154
- declare function objectToQueryParams(object: Record<string, unknown>): InstanceType<typeof _URLSearchParams>;
155
- //#endregion
156
- //#region src/validation.d.ts
157
- declare const zHttpsUrl: z.ZodURL;
158
- declare const zDataUrl: z.ZodString;
159
- declare const zInteger: z.ZodNumber;
160
- declare const zHttpMethod: z.ZodEnum<{
161
- GET: "GET";
162
- POST: "POST";
163
- PUT: "PUT";
164
- DELETE: "DELETE";
165
- HEAD: "HEAD";
166
- OPTIONS: "OPTIONS";
167
- TRACE: "TRACE";
168
- CONNECT: "CONNECT";
169
- PATCH: "PATCH";
170
- }>;
171
- type HttpMethod = z.infer<typeof zHttpMethod>;
172
- declare const zStringToJson: z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>;
173
- declare const zIs: <Schema extends z.ZodSchema>(schema: Schema, data: unknown) => data is z.infer<typeof schema>;
174
- //#endregion
175
- //#region src/www-authenticate.d.ts
176
- interface WwwAuthenticateHeaderChallenge {
177
- scheme: string;
178
- /**
179
- * Record where the keys are the names, and the value can be 0 (null), 1 (string) or multiple (string[])
180
- * entries
181
- */
182
- payload: Record<string, string | string[] | null>;
183
- }
184
- declare function parseWwwAuthenticateHeader(str: string): WwwAuthenticateHeaderChallenge[];
185
- declare function encodeWwwAuthenticateHeader(challenges: WwwAuthenticateHeaderChallenge[]): string;
186
- //#endregion
187
- //#region src/zod-error.d.ts
188
- declare function formatZodError(error?: z.ZodError): string;
189
- //#endregion
190
- export { type BaseSchema, ContentType, type Fetch, type FetchHeaders, type FetchRequestInit, type FetchResponse, _Headers as Headers, type HttpMethod, type InferOutputUnion, InvalidFetchResponseError, JsonParseError, type NonEmptyArray, type Oid4vcTsConfig, type Optional, type OrPromise, type Simplify, type StringWithAutoCompletion, _URL as URL, _URLSearchParams as URLSearchParams, ValidationError, type WwwAuthenticateHeaderChallenge, type ZodFetcher, addSecondsToDate, arrayEqualsIgnoreOrder, createFetcher, createZodFetcher, dateToSeconds, decodeBase64, decodeUtf8String, encodeToBase64, encodeToBase64Url, encodeToUtf8String, encodeWwwAuthenticateHeader, formatZodError, getGlobalConfig, getQueryParams, isContentType, isObject, isResponseContentType, joinUriParts, mergeDeep, objectToQueryParams, parseIfJson, parseWithErrorHandling, parseWwwAuthenticateHeader, setGlobalConfig, stringToJsonWithErrorHandling, zDataUrl, zHttpMethod, zHttpsUrl, zInteger, zIs, zStringToJson };
191
- //# sourceMappingURL=index.d.cts.map