@openid4vc/utils 0.2.0 → 0.3.0-alpha-20250202020720
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/dist/index.d.mts +35 -30
- package/dist/index.d.ts +35 -30
- package/dist/index.js +139 -85
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +134 -80
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import z, { ZodError } from 'zod';
|
|
2
2
|
|
|
3
3
|
declare const _URL: {
|
|
4
4
|
new (url: string | URL, base?: string | URL): URL;
|
|
@@ -22,9 +22,14 @@ declare class JsonParseError extends Error {
|
|
|
22
22
|
constructor(message: string, jsonString: string);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
declare class ValidationError
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
declare class ValidationError extends Error {
|
|
26
|
+
zodError: ZodError | undefined;
|
|
27
|
+
private escapeQuotes;
|
|
28
|
+
private joinPath;
|
|
29
|
+
private getMessageFromUnionErrors;
|
|
30
|
+
private getMessageFromZodIssue;
|
|
31
|
+
private formatError;
|
|
32
|
+
constructor(message: string, zodError?: z.ZodError);
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
declare class InvalidFetchResponseError extends Error {
|
|
@@ -49,13 +54,12 @@ declare function decodeBase64(base64: string): Uint8Array;
|
|
|
49
54
|
declare function encodeToBase64(data: Uint8Array | string): string;
|
|
50
55
|
declare function encodeToBase64Url(data: Uint8Array | string): string;
|
|
51
56
|
|
|
52
|
-
type BaseSchema =
|
|
57
|
+
type BaseSchema = z.ZodTypeAny;
|
|
53
58
|
type InferOutputUnion<T extends readonly any[]> = {
|
|
54
|
-
[K in keyof T]:
|
|
59
|
+
[K in keyof T]: z.infer<T[K]>;
|
|
55
60
|
}[number];
|
|
56
61
|
declare function stringToJsonWithErrorHandling(string: string, errorMessage?: string): any;
|
|
57
|
-
declare function parseWithErrorHandling<Schema extends BaseSchema>(schema: Schema, data: unknown, customErrorMessage?: string):
|
|
58
|
-
declare function valibotRecursiveFlattenIssues(issues: v.BaseIssue<unknown>[]): Record<string, unknown>;
|
|
62
|
+
declare function parseWithErrorHandling<Schema extends BaseSchema>(schema: Schema, data: unknown, customErrorMessage?: string): z.infer<Schema>;
|
|
59
63
|
|
|
60
64
|
/**
|
|
61
65
|
* Combine multiple uri parts into a single uri taking into account slashes.
|
|
@@ -83,43 +87,44 @@ declare enum ContentType {
|
|
|
83
87
|
declare function isContentType(contentType: ContentType, value: string): boolean;
|
|
84
88
|
declare function isResponseContentType(contentType: ContentType, response: FetchResponse): boolean;
|
|
85
89
|
|
|
86
|
-
|
|
90
|
+
/**
|
|
91
|
+
* A type utility which represents the function returned
|
|
92
|
+
* from createZodFetcher
|
|
93
|
+
*/
|
|
94
|
+
type ZodFetcher = <Schema extends z.ZodTypeAny>(schema: Schema, expectedContentType: ContentType, ...args: Parameters<Fetch>) => Promise<{
|
|
87
95
|
response: Awaited<ReturnType<Fetch>>;
|
|
88
|
-
result?:
|
|
96
|
+
result?: z.SafeParseReturnType<Schema, z.infer<Schema>>;
|
|
89
97
|
}>;
|
|
90
98
|
/**
|
|
91
|
-
* The default fetcher used when no
|
|
99
|
+
* The default fetcher used by createZodFetcher when no
|
|
92
100
|
* fetcher is provided.
|
|
93
101
|
*/
|
|
94
102
|
declare const defaultFetcher: typeof fetch;
|
|
95
103
|
/**
|
|
96
|
-
* Creates a `
|
|
97
|
-
* the expected response, and the arguments to
|
|
98
|
-
*
|
|
99
|
-
* If you don't provide a fetcher in `createValibotFetcher()`,
|
|
100
|
-
* we're falling back to the default fetcher.
|
|
104
|
+
* Creates a `fetchWithZod` function that takes in a schema of
|
|
105
|
+
* the expected response, and the arguments to the fetcher
|
|
106
|
+
* you provided.
|
|
101
107
|
*
|
|
102
108
|
* @example
|
|
103
109
|
*
|
|
104
|
-
* const
|
|
110
|
+
* const fetchWithZod = createZodFetcher((url) => {
|
|
111
|
+
* return fetch(url).then((res) => res.json());
|
|
112
|
+
* });
|
|
105
113
|
*
|
|
106
|
-
* const
|
|
107
|
-
*
|
|
108
|
-
*
|
|
114
|
+
* const response = await fetchWithZod(
|
|
115
|
+
* z.object({
|
|
116
|
+
* hello: z.string(),
|
|
109
117
|
* }),
|
|
110
118
|
* "https://example.com",
|
|
111
119
|
* );
|
|
112
120
|
*/
|
|
113
|
-
declare function
|
|
114
|
-
/**
|
|
115
|
-
* A fetcher function that returns a response, from which the data can be parsed
|
|
116
|
-
*/
|
|
117
|
-
fetcher?: typeof fetch): ValibotFetcher;
|
|
121
|
+
declare function createZodFetcher(fetcher?: typeof fetch): ZodFetcher;
|
|
118
122
|
|
|
119
|
-
declare const
|
|
120
|
-
declare const
|
|
121
|
-
declare const
|
|
122
|
-
type HttpMethod =
|
|
123
|
+
declare const zHttpsUrl: z.ZodEffects<z.ZodString, string, string>;
|
|
124
|
+
declare const zInteger: z.ZodNumber;
|
|
125
|
+
declare const zHttpMethod: z.ZodEnum<["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "TRACE", "CONNECT", "PATCH"]>;
|
|
126
|
+
type HttpMethod = z.infer<typeof zHttpMethod>;
|
|
127
|
+
declare const zIs: <Schema extends z.ZodSchema>(schema: Schema, data: unknown) => data is z.infer<typeof schema>;
|
|
123
128
|
|
|
124
129
|
/**
|
|
125
130
|
* Deep merge two objects.
|
|
@@ -156,4 +161,4 @@ interface Oid4vcTsConfig {
|
|
|
156
161
|
declare function setGlobalConfig(config: Oid4vcTsConfig): void;
|
|
157
162
|
declare function getGlobalConfig(): Oid4vcTsConfig;
|
|
158
163
|
|
|
159
|
-
export { type BaseSchema, ContentType, type Fetch, type FetchHeaders, type FetchRequestInit, type FetchResponse, _Headers as Headers, type HttpMethod, type InferOutputUnion, InvalidFetchResponseError, JsonParseError, type Oid4vcTsConfig, type Optional, type OrPromise, type Simplify, type StringWithAutoCompletion, _URL as URL, _URLSearchParams as URLSearchParams,
|
|
164
|
+
export { type BaseSchema, ContentType, type Fetch, type FetchHeaders, type FetchRequestInit, type FetchResponse, _Headers as Headers, type HttpMethod, type InferOutputUnion, InvalidFetchResponseError, JsonParseError, type Oid4vcTsConfig, type Optional, type OrPromise, type Simplify, type StringWithAutoCompletion, _URL as URL, _URLSearchParams as URLSearchParams, ValidationError, type WwwAuthenticateHeaderChallenge, type ZodFetcher, addSecondsToDate, arrayEqualsIgnoreOrder, createZodFetcher, dateToSeconds, decodeBase64, decodeUtf8String, defaultFetcher, encodeToBase64, encodeToBase64Url, encodeToUtf8String, encodeWwwAuthenticateHeader, getGlobalConfig, getQueryParams, isContentType, isResponseContentType, joinUriParts, mergeDeep, objectToQueryParams, parseWithErrorHandling, parseWwwAuthenticateHeader, setGlobalConfig, stringToJsonWithErrorHandling, zHttpMethod, zHttpsUrl, zInteger, zIs };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import z, { ZodError } from 'zod';
|
|
2
2
|
|
|
3
3
|
declare const _URL: {
|
|
4
4
|
new (url: string | URL, base?: string | URL): URL;
|
|
@@ -22,9 +22,14 @@ declare class JsonParseError extends Error {
|
|
|
22
22
|
constructor(message: string, jsonString: string);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
declare class ValidationError
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
declare class ValidationError extends Error {
|
|
26
|
+
zodError: ZodError | undefined;
|
|
27
|
+
private escapeQuotes;
|
|
28
|
+
private joinPath;
|
|
29
|
+
private getMessageFromUnionErrors;
|
|
30
|
+
private getMessageFromZodIssue;
|
|
31
|
+
private formatError;
|
|
32
|
+
constructor(message: string, zodError?: z.ZodError);
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
declare class InvalidFetchResponseError extends Error {
|
|
@@ -49,13 +54,12 @@ declare function decodeBase64(base64: string): Uint8Array;
|
|
|
49
54
|
declare function encodeToBase64(data: Uint8Array | string): string;
|
|
50
55
|
declare function encodeToBase64Url(data: Uint8Array | string): string;
|
|
51
56
|
|
|
52
|
-
type BaseSchema =
|
|
57
|
+
type BaseSchema = z.ZodTypeAny;
|
|
53
58
|
type InferOutputUnion<T extends readonly any[]> = {
|
|
54
|
-
[K in keyof T]:
|
|
59
|
+
[K in keyof T]: z.infer<T[K]>;
|
|
55
60
|
}[number];
|
|
56
61
|
declare function stringToJsonWithErrorHandling(string: string, errorMessage?: string): any;
|
|
57
|
-
declare function parseWithErrorHandling<Schema extends BaseSchema>(schema: Schema, data: unknown, customErrorMessage?: string):
|
|
58
|
-
declare function valibotRecursiveFlattenIssues(issues: v.BaseIssue<unknown>[]): Record<string, unknown>;
|
|
62
|
+
declare function parseWithErrorHandling<Schema extends BaseSchema>(schema: Schema, data: unknown, customErrorMessage?: string): z.infer<Schema>;
|
|
59
63
|
|
|
60
64
|
/**
|
|
61
65
|
* Combine multiple uri parts into a single uri taking into account slashes.
|
|
@@ -83,43 +87,44 @@ declare enum ContentType {
|
|
|
83
87
|
declare function isContentType(contentType: ContentType, value: string): boolean;
|
|
84
88
|
declare function isResponseContentType(contentType: ContentType, response: FetchResponse): boolean;
|
|
85
89
|
|
|
86
|
-
|
|
90
|
+
/**
|
|
91
|
+
* A type utility which represents the function returned
|
|
92
|
+
* from createZodFetcher
|
|
93
|
+
*/
|
|
94
|
+
type ZodFetcher = <Schema extends z.ZodTypeAny>(schema: Schema, expectedContentType: ContentType, ...args: Parameters<Fetch>) => Promise<{
|
|
87
95
|
response: Awaited<ReturnType<Fetch>>;
|
|
88
|
-
result?:
|
|
96
|
+
result?: z.SafeParseReturnType<Schema, z.infer<Schema>>;
|
|
89
97
|
}>;
|
|
90
98
|
/**
|
|
91
|
-
* The default fetcher used when no
|
|
99
|
+
* The default fetcher used by createZodFetcher when no
|
|
92
100
|
* fetcher is provided.
|
|
93
101
|
*/
|
|
94
102
|
declare const defaultFetcher: typeof fetch;
|
|
95
103
|
/**
|
|
96
|
-
* Creates a `
|
|
97
|
-
* the expected response, and the arguments to
|
|
98
|
-
*
|
|
99
|
-
* If you don't provide a fetcher in `createValibotFetcher()`,
|
|
100
|
-
* we're falling back to the default fetcher.
|
|
104
|
+
* Creates a `fetchWithZod` function that takes in a schema of
|
|
105
|
+
* the expected response, and the arguments to the fetcher
|
|
106
|
+
* you provided.
|
|
101
107
|
*
|
|
102
108
|
* @example
|
|
103
109
|
*
|
|
104
|
-
* const
|
|
110
|
+
* const fetchWithZod = createZodFetcher((url) => {
|
|
111
|
+
* return fetch(url).then((res) => res.json());
|
|
112
|
+
* });
|
|
105
113
|
*
|
|
106
|
-
* const
|
|
107
|
-
*
|
|
108
|
-
*
|
|
114
|
+
* const response = await fetchWithZod(
|
|
115
|
+
* z.object({
|
|
116
|
+
* hello: z.string(),
|
|
109
117
|
* }),
|
|
110
118
|
* "https://example.com",
|
|
111
119
|
* );
|
|
112
120
|
*/
|
|
113
|
-
declare function
|
|
114
|
-
/**
|
|
115
|
-
* A fetcher function that returns a response, from which the data can be parsed
|
|
116
|
-
*/
|
|
117
|
-
fetcher?: typeof fetch): ValibotFetcher;
|
|
121
|
+
declare function createZodFetcher(fetcher?: typeof fetch): ZodFetcher;
|
|
118
122
|
|
|
119
|
-
declare const
|
|
120
|
-
declare const
|
|
121
|
-
declare const
|
|
122
|
-
type HttpMethod =
|
|
123
|
+
declare const zHttpsUrl: z.ZodEffects<z.ZodString, string, string>;
|
|
124
|
+
declare const zInteger: z.ZodNumber;
|
|
125
|
+
declare const zHttpMethod: z.ZodEnum<["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "TRACE", "CONNECT", "PATCH"]>;
|
|
126
|
+
type HttpMethod = z.infer<typeof zHttpMethod>;
|
|
127
|
+
declare const zIs: <Schema extends z.ZodSchema>(schema: Schema, data: unknown) => data is z.infer<typeof schema>;
|
|
123
128
|
|
|
124
129
|
/**
|
|
125
130
|
* Deep merge two objects.
|
|
@@ -156,4 +161,4 @@ interface Oid4vcTsConfig {
|
|
|
156
161
|
declare function setGlobalConfig(config: Oid4vcTsConfig): void;
|
|
157
162
|
declare function getGlobalConfig(): Oid4vcTsConfig;
|
|
158
163
|
|
|
159
|
-
export { type BaseSchema, ContentType, type Fetch, type FetchHeaders, type FetchRequestInit, type FetchResponse, _Headers as Headers, type HttpMethod, type InferOutputUnion, InvalidFetchResponseError, JsonParseError, type Oid4vcTsConfig, type Optional, type OrPromise, type Simplify, type StringWithAutoCompletion, _URL as URL, _URLSearchParams as URLSearchParams,
|
|
164
|
+
export { type BaseSchema, ContentType, type Fetch, type FetchHeaders, type FetchRequestInit, type FetchResponse, _Headers as Headers, type HttpMethod, type InferOutputUnion, InvalidFetchResponseError, JsonParseError, type Oid4vcTsConfig, type Optional, type OrPromise, type Simplify, type StringWithAutoCompletion, _URL as URL, _URLSearchParams as URLSearchParams, ValidationError, type WwwAuthenticateHeaderChallenge, type ZodFetcher, addSecondsToDate, arrayEqualsIgnoreOrder, createZodFetcher, dateToSeconds, decodeBase64, decodeUtf8String, defaultFetcher, encodeToBase64, encodeToBase64Url, encodeToUtf8String, encodeWwwAuthenticateHeader, getGlobalConfig, getQueryParams, isContentType, isResponseContentType, joinUriParts, mergeDeep, objectToQueryParams, parseWithErrorHandling, parseWwwAuthenticateHeader, setGlobalConfig, stringToJsonWithErrorHandling, zHttpMethod, zHttpsUrl, zInteger, zIs };
|
package/dist/index.js
CHANGED
|
@@ -39,7 +39,7 @@ __export(src_exports, {
|
|
|
39
39
|
ValidationError: () => ValidationError,
|
|
40
40
|
addSecondsToDate: () => addSecondsToDate,
|
|
41
41
|
arrayEqualsIgnoreOrder: () => arrayEqualsIgnoreOrder,
|
|
42
|
-
|
|
42
|
+
createZodFetcher: () => createZodFetcher,
|
|
43
43
|
dateToSeconds: () => dateToSeconds,
|
|
44
44
|
decodeBase64: () => decodeBase64,
|
|
45
45
|
decodeUtf8String: () => decodeUtf8String,
|
|
@@ -59,10 +59,10 @@ __export(src_exports, {
|
|
|
59
59
|
parseWwwAuthenticateHeader: () => parseWwwAuthenticateHeader,
|
|
60
60
|
setGlobalConfig: () => setGlobalConfig,
|
|
61
61
|
stringToJsonWithErrorHandling: () => stringToJsonWithErrorHandling,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
zHttpMethod: () => zHttpMethod,
|
|
63
|
+
zHttpsUrl: () => zHttpsUrl,
|
|
64
|
+
zInteger: () => zInteger,
|
|
65
|
+
zIs: () => zIs
|
|
66
66
|
});
|
|
67
67
|
module.exports = __toCommonJS(src_exports);
|
|
68
68
|
|
|
@@ -79,64 +79,82 @@ ${jsonString}`);
|
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
-
// src/
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
for (const key in source) {
|
|
94
|
-
if (isObject(source[key])) {
|
|
95
|
-
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
96
|
-
mergeDeep(target[key], source[key]);
|
|
97
|
-
} else {
|
|
98
|
-
Object.assign(target, { [key]: source[key] });
|
|
99
|
-
}
|
|
100
|
-
}
|
|
82
|
+
// src/error/ValidationError.ts
|
|
83
|
+
var import_zod = require("zod");
|
|
84
|
+
var constants = {
|
|
85
|
+
// biome-ignore lint/suspicious/noMisleadingCharacterClass: expected
|
|
86
|
+
identifierRegex: /[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*/u,
|
|
87
|
+
unionSeparator: ", or ",
|
|
88
|
+
issueSeparator: "\n - "
|
|
89
|
+
};
|
|
90
|
+
var ValidationError = class extends Error {
|
|
91
|
+
escapeQuotes(str) {
|
|
92
|
+
return str.replace(/"/g, '\\"');
|
|
101
93
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
94
|
+
joinPath(path) {
|
|
95
|
+
if (path.length === 1) {
|
|
96
|
+
return path[0].toString();
|
|
97
|
+
}
|
|
98
|
+
return path.reduce((acc, item) => {
|
|
99
|
+
if (typeof item === "number") {
|
|
100
|
+
return `${acc}[${item.toString()}]`;
|
|
101
|
+
}
|
|
102
|
+
if (item.includes('"')) {
|
|
103
|
+
return `${acc}["${this.escapeQuotes(item)}"]`;
|
|
104
|
+
}
|
|
105
|
+
if (!constants.identifierRegex.test(item)) {
|
|
106
|
+
return `${acc}["${item}"]`;
|
|
107
|
+
}
|
|
108
|
+
const separator = acc.length === 0 ? "" : ".";
|
|
109
|
+
return acc + separator + item;
|
|
110
|
+
}, "");
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
parseResult.issues
|
|
119
|
-
);
|
|
112
|
+
getMessageFromUnionErrors(unionErrors) {
|
|
113
|
+
return unionErrors.reduce((acc, zodError) => {
|
|
114
|
+
const newIssues = zodError.issues.map((issue) => this.getMessageFromZodIssue(issue)).join(constants.issueSeparator);
|
|
115
|
+
if (!acc.includes(newIssues)) acc.push(newIssues);
|
|
116
|
+
return acc;
|
|
117
|
+
}, []).join(constants.unionSeparator);
|
|
120
118
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
let flattened = v.flatten(issues);
|
|
125
|
-
for (const issue of issues) {
|
|
126
|
-
if (issue.issues) {
|
|
127
|
-
flattened = mergeDeep(flattened, valibotRecursiveFlattenIssues(issue.issues));
|
|
119
|
+
getMessageFromZodIssue(issue) {
|
|
120
|
+
if (issue.code === import_zod.ZodIssueCode.invalid_union) {
|
|
121
|
+
return this.getMessageFromUnionErrors(issue.unionErrors);
|
|
128
122
|
}
|
|
123
|
+
if (issue.code === import_zod.ZodIssueCode.invalid_arguments) {
|
|
124
|
+
return [issue.message, ...issue.argumentsError.issues.map((issue2) => this.getMessageFromZodIssue(issue2))].join(
|
|
125
|
+
constants.issueSeparator
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
if (issue.code === import_zod.ZodIssueCode.invalid_return_type) {
|
|
129
|
+
return [issue.message, ...issue.returnTypeError.issues.map((issue2) => this.getMessageFromZodIssue(issue2))].join(
|
|
130
|
+
constants.issueSeparator
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
if (issue.path.length !== 0) {
|
|
134
|
+
if (issue.path.length === 1) {
|
|
135
|
+
const identifier = issue.path[0];
|
|
136
|
+
if (typeof identifier === "number") {
|
|
137
|
+
return `${issue.message} at index ${identifier}`;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return `${issue.message} at "${this.joinPath(issue.path)}"`;
|
|
141
|
+
}
|
|
142
|
+
return issue.message;
|
|
129
143
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
${
|
|
139
|
-
this
|
|
144
|
+
formatError(error) {
|
|
145
|
+
if (!error) return "";
|
|
146
|
+
return error?.issues.map((issue) => this.getMessageFromZodIssue(issue)).join(constants.issueSeparator);
|
|
147
|
+
}
|
|
148
|
+
constructor(message, zodError) {
|
|
149
|
+
super(message);
|
|
150
|
+
const formattedError = this.formatError(zodError);
|
|
151
|
+
this.message = `${message}
|
|
152
|
+
- ${formattedError}`;
|
|
153
|
+
Object.defineProperty(this, "zodError", {
|
|
154
|
+
value: zodError,
|
|
155
|
+
writable: false,
|
|
156
|
+
enumerable: false
|
|
157
|
+
});
|
|
140
158
|
}
|
|
141
159
|
};
|
|
142
160
|
|
|
@@ -161,8 +179,8 @@ function addSecondsToDate(date, seconds) {
|
|
|
161
179
|
|
|
162
180
|
// src/encoding.ts
|
|
163
181
|
var import_buffer = require("buffer");
|
|
164
|
-
function decodeUtf8String(
|
|
165
|
-
return new Uint8Array(import_buffer.Buffer.from(
|
|
182
|
+
function decodeUtf8String(string) {
|
|
183
|
+
return new Uint8Array(import_buffer.Buffer.from(string, "utf-8"));
|
|
166
184
|
}
|
|
167
185
|
function encodeToUtf8String(data) {
|
|
168
186
|
return import_buffer.Buffer.from(data).toString("utf-8");
|
|
@@ -183,6 +201,25 @@ function base64ToBase64Url(base64) {
|
|
|
183
201
|
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
184
202
|
}
|
|
185
203
|
|
|
204
|
+
// src/parse.ts
|
|
205
|
+
function stringToJsonWithErrorHandling(string, errorMessage) {
|
|
206
|
+
try {
|
|
207
|
+
return JSON.parse(string);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
throw new JsonParseError(errorMessage ?? "Unable to parse string to JSON.", string);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function parseWithErrorHandling(schema, data, customErrorMessage) {
|
|
213
|
+
const parseResult = schema.safeParse(data);
|
|
214
|
+
if (!parseResult.success) {
|
|
215
|
+
throw new ValidationError(
|
|
216
|
+
customErrorMessage ?? `Error validating schema with data ${JSON.stringify(data)}`,
|
|
217
|
+
parseResult.error
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
return parseResult.data;
|
|
221
|
+
}
|
|
222
|
+
|
|
186
223
|
// src/path.ts
|
|
187
224
|
function joinUriParts(base, parts) {
|
|
188
225
|
if (parts.length === 0) return base;
|
|
@@ -199,8 +236,8 @@ function joinUriParts(base, parts) {
|
|
|
199
236
|
}
|
|
200
237
|
|
|
201
238
|
// src/url.ts
|
|
202
|
-
function getQueryParams(
|
|
203
|
-
const parsedUrl = new _URL(
|
|
239
|
+
function getQueryParams(url) {
|
|
240
|
+
const parsedUrl = new _URL(url);
|
|
204
241
|
const searchParams = new _URLSearchParams(parsedUrl.search);
|
|
205
242
|
const params = {};
|
|
206
243
|
searchParams.forEach((value, key) => {
|
|
@@ -218,9 +255,6 @@ function objectToQueryParams(object) {
|
|
|
218
255
|
return params;
|
|
219
256
|
}
|
|
220
257
|
|
|
221
|
-
// src/valibot-fetcher.ts
|
|
222
|
-
var v2 = __toESM(require("valibot"));
|
|
223
|
-
|
|
224
258
|
// src/content-type.ts
|
|
225
259
|
var ContentType = /* @__PURE__ */ ((ContentType2) => {
|
|
226
260
|
ContentType2["XWwwFormUrlencoded"] = "application/x-www-form-urlencoded";
|
|
@@ -237,9 +271,9 @@ function isResponseContentType(contentType, response) {
|
|
|
237
271
|
return isContentType(contentType, header);
|
|
238
272
|
}
|
|
239
273
|
|
|
240
|
-
// src/
|
|
274
|
+
// src/zod-fetcher.ts
|
|
241
275
|
var defaultFetcher = fetch;
|
|
242
|
-
function
|
|
276
|
+
function createZodFetcher(fetcher = defaultFetcher) {
|
|
243
277
|
return async (schema, expectedContentType, ...args) => {
|
|
244
278
|
const response = await fetcher(...args);
|
|
245
279
|
if (response.ok && !isResponseContentType(expectedContentType, response)) {
|
|
@@ -251,13 +285,13 @@ function createValibotFetcher(fetcher = defaultFetcher) {
|
|
|
251
285
|
}
|
|
252
286
|
return {
|
|
253
287
|
response,
|
|
254
|
-
result: response.ok ?
|
|
288
|
+
result: response.ok ? schema.safeParse(await response.json()) : void 0
|
|
255
289
|
};
|
|
256
290
|
};
|
|
257
291
|
}
|
|
258
292
|
|
|
259
293
|
// src/validation.ts
|
|
260
|
-
var
|
|
294
|
+
var import_zod2 = __toESM(require("zod"));
|
|
261
295
|
|
|
262
296
|
// src/config.ts
|
|
263
297
|
var GLOBAL_CONFIG = {
|
|
@@ -271,16 +305,36 @@ function getGlobalConfig() {
|
|
|
271
305
|
}
|
|
272
306
|
|
|
273
307
|
// src/validation.ts
|
|
274
|
-
var
|
|
275
|
-
|
|
276
|
-
v3.url(),
|
|
277
|
-
v3.check((url2) => {
|
|
308
|
+
var zHttpsUrl = import_zod2.default.string().url().refine(
|
|
309
|
+
(url) => {
|
|
278
310
|
const { allowInsecureUrls } = getGlobalConfig();
|
|
279
|
-
return allowInsecureUrls ?
|
|
280
|
-
},
|
|
311
|
+
return allowInsecureUrls ? url.startsWith("http://") || url.startsWith("https://") : url.startsWith("https://");
|
|
312
|
+
},
|
|
313
|
+
{ message: "url must be an https:// url" }
|
|
281
314
|
);
|
|
282
|
-
var
|
|
283
|
-
var
|
|
315
|
+
var zInteger = import_zod2.default.number().int();
|
|
316
|
+
var zHttpMethod = import_zod2.default.enum(["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "TRACE", "CONNECT", "PATCH"]);
|
|
317
|
+
var zIs = (schema, data) => schema.safeParse(data).success;
|
|
318
|
+
|
|
319
|
+
// src/object.ts
|
|
320
|
+
function isObject(item) {
|
|
321
|
+
return item != null && typeof item === "object" && !Array.isArray(item);
|
|
322
|
+
}
|
|
323
|
+
function mergeDeep(target, ...sources) {
|
|
324
|
+
if (!sources.length) return target;
|
|
325
|
+
const source = sources.shift();
|
|
326
|
+
if (isObject(target) && isObject(source)) {
|
|
327
|
+
for (const key in source) {
|
|
328
|
+
if (isObject(source[key])) {
|
|
329
|
+
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
330
|
+
mergeDeep(target[key], source[key]);
|
|
331
|
+
} else {
|
|
332
|
+
Object.assign(target, { [key]: source[key] });
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return mergeDeep(target, ...sources);
|
|
337
|
+
}
|
|
284
338
|
|
|
285
339
|
// src/array.ts
|
|
286
340
|
function arrayEqualsIgnoreOrder(a, b) {
|
|
@@ -296,10 +350,10 @@ var body = (
|
|
|
296
350
|
// biome-ignore lint/suspicious/noControlCharactersInRegex: <explanation>
|
|
297
351
|
/((?:[a-zA-Z0-9._~+\/-]+=*(?:\s+|$))|[^\u0000-\u001F\u007F()<>@,;:\\"/?={}\[\]\u0020\u0009]+)(?:=([^\\"=\s,]+|"(?:[^"\\]|\\.)*"))?/g
|
|
298
352
|
);
|
|
299
|
-
var parsePayload = (scheme,
|
|
353
|
+
var parsePayload = (scheme, string) => {
|
|
300
354
|
const payload = {};
|
|
301
355
|
while (true) {
|
|
302
|
-
const res = body.exec(
|
|
356
|
+
const res = body.exec(string);
|
|
303
357
|
if (!res) break;
|
|
304
358
|
const [, key, newValue] = res;
|
|
305
359
|
const payloadValue = payload[key];
|
|
@@ -344,7 +398,7 @@ function encodeWwwAuthenticateHeader(challenges) {
|
|
|
344
398
|
const encodedParams = Object.entries(challenge.payload).flatMap(([key, value]) => {
|
|
345
399
|
const encode = (s) => s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
346
400
|
if (Array.isArray(value)) {
|
|
347
|
-
return value.map((
|
|
401
|
+
return value.map((v) => `${key}="${encode(v)}"`);
|
|
348
402
|
}
|
|
349
403
|
return value ? `${key}="${encode(value)}"` : key;
|
|
350
404
|
});
|
|
@@ -363,7 +417,7 @@ function encodeWwwAuthenticateHeader(challenges) {
|
|
|
363
417
|
ValidationError,
|
|
364
418
|
addSecondsToDate,
|
|
365
419
|
arrayEqualsIgnoreOrder,
|
|
366
|
-
|
|
420
|
+
createZodFetcher,
|
|
367
421
|
dateToSeconds,
|
|
368
422
|
decodeBase64,
|
|
369
423
|
decodeUtf8String,
|
|
@@ -383,9 +437,9 @@ function encodeWwwAuthenticateHeader(challenges) {
|
|
|
383
437
|
parseWwwAuthenticateHeader,
|
|
384
438
|
setGlobalConfig,
|
|
385
439
|
stringToJsonWithErrorHandling,
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
440
|
+
zHttpMethod,
|
|
441
|
+
zHttpsUrl,
|
|
442
|
+
zInteger,
|
|
443
|
+
zIs
|
|
390
444
|
});
|
|
391
445
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/globals.ts","../src/error/JsonParseError.ts","../src/parse.ts","../src/object.ts","../src/error/ValidationError.ts","../src/error/InvalidFetchResponseError.ts","../src/date.ts","../src/encoding.ts","../src/path.ts","../src/url.ts","../src/valibot-fetcher.ts","../src/content-type.ts","../src/validation.ts","../src/config.ts","../src/array.ts","../src/www-authenticate.ts"],"sourcesContent":["export {\n type Fetch,\n Headers,\n type FetchRequestInit,\n type FetchHeaders,\n type FetchResponse,\n URL,\n URLSearchParams,\n} from './globals'\n\nexport { JsonParseError } from './error/JsonParseError'\nexport { ValidationError } from './error/ValidationError'\nexport { InvalidFetchResponseError } from './error/InvalidFetchResponseError'\n\nexport { addSecondsToDate, dateToSeconds } from './date'\nexport { decodeBase64, decodeUtf8String, encodeToBase64, encodeToBase64Url, encodeToUtf8String } from './encoding'\nexport {\n parseWithErrorHandling,\n stringToJsonWithErrorHandling,\n type BaseSchema,\n type InferOutputUnion,\n valibotRecursiveFlattenIssues,\n} from './parse'\nexport { joinUriParts } from './path'\nexport type { Optional, Simplify, StringWithAutoCompletion, OrPromise } from './type'\nexport { getQueryParams, objectToQueryParams } from './url'\nexport { type ValibotFetcher, createValibotFetcher, defaultFetcher } from './valibot-fetcher'\nexport { type HttpMethod, vHttpMethod, vHttpsUrl, vInteger } from './validation'\nexport { mergeDeep } from './object'\nexport { arrayEqualsIgnoreOrder } from './array'\nexport {\n parseWwwAuthenticateHeader,\n type WwwAuthenticateHeaderChallenge,\n encodeWwwAuthenticateHeader,\n} from './www-authenticate'\nexport { ContentType, isContentType, isResponseContentType } from './content-type'\nexport { setGlobalConfig, type Oid4vcTsConfig, getGlobalConfig } from './config'\n","// Theses types are provided by the platform (so @types/node, @types/react-native, DOM)\n\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nconst _URL = URL\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nconst _URLSearchParams = URLSearchParams\n\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nexport type Fetch = typeof fetch\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nexport type FetchResponse = Response\n// biome-ignore lint/style/noRestrictedGlobals: <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","export class JsonParseError extends Error {\n public constructor(message: string, jsonString: string) {\n super(`${message}\\n${jsonString}`)\n }\n}\n","import * as v from 'valibot'\nimport { JsonParseError } from './error/JsonParseError'\nimport { ValidationError } from './error/ValidationError'\nimport { mergeDeep } from './object'\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\nexport type BaseSchema = v.BaseSchema<any, any, any>\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\nexport type InferOutputUnion<T extends readonly any[]> = {\n [K in keyof T]: v.InferOutput<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 parseWithErrorHandling<Schema extends BaseSchema>(\n schema: Schema,\n data: unknown,\n customErrorMessage?: string\n): v.InferOutput<Schema> {\n const parseResult = v.safeParse(schema, data)\n\n if (!parseResult.success) {\n throw new ValidationError(\n customErrorMessage ?? `Error validating schema with data ${JSON.stringify(data)}`,\n parseResult.issues\n )\n }\n\n return parseResult.output\n}\n\nexport function valibotRecursiveFlattenIssues(issues: v.BaseIssue<unknown>[]): Record<string, unknown> {\n let flattened: unknown = v.flatten(issues as [v.BaseIssue<unknown>])\n\n for (const issue of issues) {\n if (issue.issues) {\n flattened = mergeDeep(flattened, valibotRecursiveFlattenIssues(issue.issues))\n }\n }\n\n return flattened as Record<string, unknown>\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 * as v from 'valibot'\nimport { valibotRecursiveFlattenIssues } from '../parse'\n\nexport class ValidationError<\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n Schema extends v.BaseSchema<any, any, any> = v.BaseSchema<any, any, any>,\n> extends Error {\n public constructor(\n message: string,\n public readonly valibotIssues: Array<v.InferIssue<Schema>> = []\n ) {\n const errorDetails =\n valibotIssues.length > 0\n ? JSON.stringify(valibotRecursiveFlattenIssues(valibotIssues), null, 2)\n : 'No details provided'\n super(`${message}\\n${errorDetails}`)\n }\n}\n","import 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 super(`${message}\\n${textResponse}`)\n this.response = response.clone()\n }\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","// biome-ignore lint/style/useNodejsImportProtocol: also imported in other environments\nimport { 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","/**\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 * as v from 'valibot'\nimport { type ContentType, isResponseContentType } from './content-type'\nimport { InvalidFetchResponseError } from './error/InvalidFetchResponseError'\nimport type { Fetch } from './globals'\n\n// biome-ignore lint/suspicious/noExplicitAny: any type needed for generic\nexport type ValibotFetcher = <Schema extends v.BaseSchema<any, any, any>>(\n schema: Schema,\n expectedContentType: ContentType,\n ...args: Parameters<Fetch>\n) => Promise<{ response: Awaited<ReturnType<Fetch>>; result?: v.SafeParseResult<Schema> }>\n\n/**\n * The default fetcher used when no\n * fetcher is provided.\n */\n// @ts-ignore\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nexport const defaultFetcher = fetch\n\n/**\n * Creates a `fetchWithValibot` function that takes in a schema of\n * the expected response, and the arguments to fetch.\n *\n * If you don't provide a fetcher in `createValibotFetcher()`,\n * we're falling back to the default fetcher.\n *\n * @example\n *\n * const fetchWithValibot = createValibotFetcher();\n *\n * const { response, data } = await fetchWithValibot(\n * v.looseObject({\n * format: v.string()\n * }),\n * \"https://example.com\",\n * );\n */\nexport function createValibotFetcher(\n /**\n * A fetcher function that returns a response, from which the data can be parsed\n */\n fetcher = defaultFetcher\n): ValibotFetcher {\n return async (schema, expectedContentType, ...args) => {\n const response = await fetcher(...args)\n\n if (response.ok && !isResponseContentType(expectedContentType, response)) {\n throw new InvalidFetchResponseError(\n `Expected response to match content type '${expectedContentType}', but received '${response.headers.get('Content-Type')}'`,\n await response.clone().text(),\n response\n )\n }\n\n return {\n response,\n result: response.ok ? v.safeParse(schema, await response.json()) : undefined,\n }\n }\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}\n\nexport function isContentType(contentType: ContentType, value: string) {\n return value.toLowerCase().trim().split(';')[0] === contentType\n}\n\nexport function isResponseContentType(contentType: ContentType, response: FetchResponse) {\n const header = response.headers.get('Content-Type')\n if (!header) return false\n return isContentType(contentType, header)\n}\n","import * as v from 'valibot'\nimport { getGlobalConfig } from './config'\n\nexport const vHttpsUrl = v.pipe(\n v.string(),\n v.url(),\n v.check((url) => {\n const { allowInsecureUrls } = getGlobalConfig()\n return allowInsecureUrls ? url.startsWith('http://') || url.startsWith('https://') : url.startsWith('https://')\n }, 'url must be an https:// url')\n)\nexport const vInteger = v.pipe(v.number(), v.integer())\n\nexport const vHttpMethod = v.picklist(['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS', 'TRACE', 'CONNECT', 'PATCH'])\nexport type HttpMethod = v.InferOutput<typeof vHttpMethod>\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","/**\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","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: <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 = 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA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AAQ,KAAK,GAAG;AACxB,eAAO,MAAM,IAAI,CAACC,OAAM,GAAG,GAAG,KAAK,OAAOA,EAAC,CAAC,GAAG;AAAA,MACjD;AAEA,aAAO,QAAQ,GAAG,GAAG,KAAK,OAAO,KAAK,CAAC,MAAM;AAAA,IAC/C,CAAC;AAED,YAAQ,KAAK,cAAc,WAAW,IAAI,UAAU,SAAS,GAAG,UAAU,MAAM,IAAI,cAAc,KAAK,IAAI,CAAC,EAAE;AAAA,EAChH;AAEA,SAAO,QAAQ,KAAK,IAAI;AAC1B;","names":["string","string","url","v","ContentType","v","url","string","v"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/globals.ts","../src/error/JsonParseError.ts","../src/error/ValidationError.ts","../src/error/InvalidFetchResponseError.ts","../src/date.ts","../src/encoding.ts","../src/parse.ts","../src/path.ts","../src/url.ts","../src/content-type.ts","../src/zod-fetcher.ts","../src/validation.ts","../src/config.ts","../src/object.ts","../src/array.ts","../src/www-authenticate.ts"],"sourcesContent":["export {\n type Fetch,\n Headers,\n type FetchRequestInit,\n type FetchHeaders,\n type FetchResponse,\n URL,\n URLSearchParams,\n} from './globals'\n\nexport { JsonParseError } from './error/JsonParseError'\nexport { ValidationError } from './error/ValidationError'\nexport { InvalidFetchResponseError } from './error/InvalidFetchResponseError'\n\nexport { addSecondsToDate, dateToSeconds } from './date'\nexport { decodeBase64, decodeUtf8String, encodeToBase64, encodeToBase64Url, encodeToUtf8String } from './encoding'\nexport {\n parseWithErrorHandling,\n stringToJsonWithErrorHandling,\n type BaseSchema,\n type InferOutputUnion,\n} from './parse'\nexport { joinUriParts } from './path'\nexport type { Optional, Simplify, StringWithAutoCompletion, OrPromise } from './type'\nexport { getQueryParams, objectToQueryParams } from './url'\nexport { type ZodFetcher, createZodFetcher, defaultFetcher } from './zod-fetcher'\nexport {\n type HttpMethod,\n zHttpMethod,\n zHttpsUrl,\n zInteger,\n zIs,\n} from './validation'\nexport { mergeDeep } from './object'\nexport { arrayEqualsIgnoreOrder } from './array'\nexport {\n parseWwwAuthenticateHeader,\n type WwwAuthenticateHeaderChallenge,\n encodeWwwAuthenticateHeader,\n} from './www-authenticate'\nexport { ContentType, isContentType, isResponseContentType } from './content-type'\nexport { setGlobalConfig, type Oid4vcTsConfig, getGlobalConfig } from './config'\n","// Theses types are provided by the platform (so @types/node, @types/react-native, DOM)\n\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nconst _URL = URL\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nconst _URLSearchParams = URLSearchParams\n\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nexport type Fetch = typeof fetch\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nexport type FetchResponse = Response\n// biome-ignore lint/style/noRestrictedGlobals: <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","export class JsonParseError extends Error {\n public constructor(message: string, jsonString: string) {\n super(`${message}\\n${jsonString}`)\n }\n}\n","import type z from 'zod'\nimport { type ZodError, type ZodIssue, ZodIssueCode } from 'zod'\n\n/**\n * Some code comes from `zod-validation-error` package (MIT License) and\n * was slightly simplified to fit our needs.\n */\nconst constants = {\n // biome-ignore lint/suspicious/noMisleadingCharacterClass: expected\n identifierRegex: /[$_\\p{ID_Start}][$\\u200c\\u200d\\p{ID_Continue}]*/u,\n unionSeparator: ', or ',\n issueSeparator: '\\n\\t- ',\n}\n\nexport class ValidationError extends Error {\n public zodError: ZodError | undefined\n\n private escapeQuotes(str: string): string {\n return str.replace(/\"/g, '\\\\\"')\n }\n\n private joinPath(path: Array<string | number>): string {\n if (path.length === 1) {\n return path[0].toString()\n }\n\n return path.reduce<string>((acc, item) => {\n // handle numeric indices\n if (typeof item === 'number') {\n return `${acc}[${item.toString()}]`\n }\n\n // handle quoted values\n if (item.includes('\"')) {\n return `${acc}[\"${this.escapeQuotes(item)}\"]`\n }\n\n // handle special characters\n if (!constants.identifierRegex.test(item)) {\n return `${acc}[\"${item}\"]`\n }\n\n // handle normal values\n const separator = acc.length === 0 ? '' : '.'\n return acc + separator + item\n }, '')\n }\n\n private getMessageFromUnionErrors(unionErrors: z.ZodError[]): string {\n return unionErrors\n .reduce<string[]>((acc, zodError) => {\n const newIssues = zodError.issues\n .map((issue) => this.getMessageFromZodIssue(issue))\n .join(constants.issueSeparator)\n\n if (!acc.includes(newIssues)) acc.push(newIssues)\n\n return acc\n }, [])\n .join(constants.unionSeparator)\n }\n\n private getMessageFromZodIssue(issue: ZodIssue): string {\n if (issue.code === ZodIssueCode.invalid_union) {\n return this.getMessageFromUnionErrors(issue.unionErrors)\n }\n\n if (issue.code === ZodIssueCode.invalid_arguments) {\n return [issue.message, ...issue.argumentsError.issues.map((issue) => this.getMessageFromZodIssue(issue))].join(\n constants.issueSeparator\n )\n }\n\n if (issue.code === ZodIssueCode.invalid_return_type) {\n return [issue.message, ...issue.returnTypeError.issues.map((issue) => this.getMessageFromZodIssue(issue))].join(\n constants.issueSeparator\n )\n }\n\n if (issue.path.length !== 0) {\n // handle array indices\n if (issue.path.length === 1) {\n const identifier = issue.path[0]\n\n if (typeof identifier === 'number') {\n return `${issue.message} at index ${identifier}`\n }\n }\n\n return `${issue.message} at \"${this.joinPath(issue.path)}\"`\n }\n\n return issue.message\n }\n\n private formatError(error?: z.ZodError): string {\n if (!error) return ''\n\n return error?.issues.map((issue) => this.getMessageFromZodIssue(issue)).join(constants.issueSeparator)\n }\n\n constructor(message: string, zodError?: z.ZodError) {\n super(message)\n\n const formattedError = this.formatError(zodError)\n this.message = `${message}\\n\\t- ${formattedError}`\n\n Object.defineProperty(this, 'zodError', {\n value: zodError,\n writable: false,\n enumerable: false,\n })\n }\n}\n","import 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 super(`${message}\\n${textResponse}`)\n this.response = response.clone()\n }\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","// biome-ignore lint/style/useNodejsImportProtocol: also imported in other environments\nimport { 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 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: <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 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 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}\n\nexport function isContentType(contentType: ContentType, value: string) {\n return value.toLowerCase().trim().split(';')[0] === contentType\n}\n\nexport function isResponseContentType(contentType: ContentType, response: FetchResponse) {\n const header = response.headers.get('Content-Type')\n if (!header) return false\n return isContentType(contentType, header)\n}\n","import type z from 'zod'\nimport { type ContentType, isResponseContentType } from './content-type'\nimport { InvalidFetchResponseError } from './error/InvalidFetchResponseError'\nimport type { Fetch } 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,\n ...args: Parameters<Fetch>\n) => Promise<{ response: Awaited<ReturnType<Fetch>>; result?: z.SafeParseReturnType<Schema, z.infer<Schema>> }>\n\n/**\n * The default fetcher used by createZodFetcher when no\n * fetcher is provided.\n */\n\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nexport const defaultFetcher = fetch\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 = defaultFetcher): ZodFetcher {\n return async (schema, expectedContentType, ...args) => {\n const response = await fetcher(...args)\n\n if (response.ok && !isResponseContentType(expectedContentType, response)) {\n throw new InvalidFetchResponseError(\n `Expected response to match content type '${expectedContentType}', but received '${response.headers.get('Content-Type')}'`,\n await response.clone().text(),\n response\n )\n }\n\n return {\n response,\n result: response.ok ? schema.safeParse(await response.json()) : undefined,\n }\n }\n}\n","import z from 'zod'\nimport { getGlobalConfig } from './config'\n\nexport const zHttpsUrl = z\n .string()\n .url()\n .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 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 zIs = <Schema extends z.ZodSchema>(schema: Schema, data: unknown): data is z.infer<typeof schema> =>\n schema.safeParse(data).success\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","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","/**\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","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: <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 = 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,IAAM,OAAO;AAEb,IAAM,mBAAmB;AAOzB,IAAM,WAAW;;;ACZV,IAAM,iBAAN,cAA6B,MAAM;AAAA,EACjC,YAAY,SAAiB,YAAoB;AACtD,UAAM,GAAG,OAAO;AAAA,EAAK,UAAU,EAAE;AAAA,EACnC;AACF;;;ACHA,iBAA2D;AAM3D,IAAM,YAAY;AAAA;AAAA,EAEhB,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,gBAAgB;AAClB;AAEO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAGjC,aAAa,KAAqB;AACxC,WAAO,IAAI,QAAQ,MAAM,KAAK;AAAA,EAChC;AAAA,EAEQ,SAAS,MAAsC;AACrD,QAAI,KAAK,WAAW,GAAG;AACrB,aAAO,KAAK,CAAC,EAAE,SAAS;AAAA,IAC1B;AAEA,WAAO,KAAK,OAAe,CAAC,KAAK,SAAS;AAExC,UAAI,OAAO,SAAS,UAAU;AAC5B,eAAO,GAAG,GAAG,IAAI,KAAK,SAAS,CAAC;AAAA,MAClC;AAGA,UAAI,KAAK,SAAS,GAAG,GAAG;AACtB,eAAO,GAAG,GAAG,KAAK,KAAK,aAAa,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,UAAU,MAAM,IAAI,cAAc,KAAK,IAAI,CAAC,EAAE;AAAA,EAChH;AAEA,SAAO,QAAQ,KAAK,IAAI;AAC1B;","names":["issue","ContentType","import_zod","z"]}
|
package/dist/index.mjs
CHANGED
|
@@ -11,64 +11,82 @@ ${jsonString}`);
|
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
// src/
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
for (const key in source) {
|
|
26
|
-
if (isObject(source[key])) {
|
|
27
|
-
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
28
|
-
mergeDeep(target[key], source[key]);
|
|
29
|
-
} else {
|
|
30
|
-
Object.assign(target, { [key]: source[key] });
|
|
31
|
-
}
|
|
32
|
-
}
|
|
14
|
+
// src/error/ValidationError.ts
|
|
15
|
+
import { ZodIssueCode } from "zod";
|
|
16
|
+
var constants = {
|
|
17
|
+
// biome-ignore lint/suspicious/noMisleadingCharacterClass: expected
|
|
18
|
+
identifierRegex: /[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*/u,
|
|
19
|
+
unionSeparator: ", or ",
|
|
20
|
+
issueSeparator: "\n - "
|
|
21
|
+
};
|
|
22
|
+
var ValidationError = class extends Error {
|
|
23
|
+
escapeQuotes(str) {
|
|
24
|
+
return str.replace(/"/g, '\\"');
|
|
33
25
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
26
|
+
joinPath(path) {
|
|
27
|
+
if (path.length === 1) {
|
|
28
|
+
return path[0].toString();
|
|
29
|
+
}
|
|
30
|
+
return path.reduce((acc, item) => {
|
|
31
|
+
if (typeof item === "number") {
|
|
32
|
+
return `${acc}[${item.toString()}]`;
|
|
33
|
+
}
|
|
34
|
+
if (item.includes('"')) {
|
|
35
|
+
return `${acc}["${this.escapeQuotes(item)}"]`;
|
|
36
|
+
}
|
|
37
|
+
if (!constants.identifierRegex.test(item)) {
|
|
38
|
+
return `${acc}["${item}"]`;
|
|
39
|
+
}
|
|
40
|
+
const separator = acc.length === 0 ? "" : ".";
|
|
41
|
+
return acc + separator + item;
|
|
42
|
+
}, "");
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
parseResult.issues
|
|
51
|
-
);
|
|
44
|
+
getMessageFromUnionErrors(unionErrors) {
|
|
45
|
+
return unionErrors.reduce((acc, zodError) => {
|
|
46
|
+
const newIssues = zodError.issues.map((issue) => this.getMessageFromZodIssue(issue)).join(constants.issueSeparator);
|
|
47
|
+
if (!acc.includes(newIssues)) acc.push(newIssues);
|
|
48
|
+
return acc;
|
|
49
|
+
}, []).join(constants.unionSeparator);
|
|
52
50
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
let flattened = v.flatten(issues);
|
|
57
|
-
for (const issue of issues) {
|
|
58
|
-
if (issue.issues) {
|
|
59
|
-
flattened = mergeDeep(flattened, valibotRecursiveFlattenIssues(issue.issues));
|
|
51
|
+
getMessageFromZodIssue(issue) {
|
|
52
|
+
if (issue.code === ZodIssueCode.invalid_union) {
|
|
53
|
+
return this.getMessageFromUnionErrors(issue.unionErrors);
|
|
60
54
|
}
|
|
55
|
+
if (issue.code === ZodIssueCode.invalid_arguments) {
|
|
56
|
+
return [issue.message, ...issue.argumentsError.issues.map((issue2) => this.getMessageFromZodIssue(issue2))].join(
|
|
57
|
+
constants.issueSeparator
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
if (issue.code === ZodIssueCode.invalid_return_type) {
|
|
61
|
+
return [issue.message, ...issue.returnTypeError.issues.map((issue2) => this.getMessageFromZodIssue(issue2))].join(
|
|
62
|
+
constants.issueSeparator
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
if (issue.path.length !== 0) {
|
|
66
|
+
if (issue.path.length === 1) {
|
|
67
|
+
const identifier = issue.path[0];
|
|
68
|
+
if (typeof identifier === "number") {
|
|
69
|
+
return `${issue.message} at index ${identifier}`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return `${issue.message} at "${this.joinPath(issue.path)}"`;
|
|
73
|
+
}
|
|
74
|
+
return issue.message;
|
|
61
75
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
${
|
|
71
|
-
this
|
|
76
|
+
formatError(error) {
|
|
77
|
+
if (!error) return "";
|
|
78
|
+
return error?.issues.map((issue) => this.getMessageFromZodIssue(issue)).join(constants.issueSeparator);
|
|
79
|
+
}
|
|
80
|
+
constructor(message, zodError) {
|
|
81
|
+
super(message);
|
|
82
|
+
const formattedError = this.formatError(zodError);
|
|
83
|
+
this.message = `${message}
|
|
84
|
+
- ${formattedError}`;
|
|
85
|
+
Object.defineProperty(this, "zodError", {
|
|
86
|
+
value: zodError,
|
|
87
|
+
writable: false,
|
|
88
|
+
enumerable: false
|
|
89
|
+
});
|
|
72
90
|
}
|
|
73
91
|
};
|
|
74
92
|
|
|
@@ -93,8 +111,8 @@ function addSecondsToDate(date, seconds) {
|
|
|
93
111
|
|
|
94
112
|
// src/encoding.ts
|
|
95
113
|
import { Buffer } from "buffer";
|
|
96
|
-
function decodeUtf8String(
|
|
97
|
-
return new Uint8Array(Buffer.from(
|
|
114
|
+
function decodeUtf8String(string) {
|
|
115
|
+
return new Uint8Array(Buffer.from(string, "utf-8"));
|
|
98
116
|
}
|
|
99
117
|
function encodeToUtf8String(data) {
|
|
100
118
|
return Buffer.from(data).toString("utf-8");
|
|
@@ -115,6 +133,25 @@ function base64ToBase64Url(base64) {
|
|
|
115
133
|
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
116
134
|
}
|
|
117
135
|
|
|
136
|
+
// src/parse.ts
|
|
137
|
+
function stringToJsonWithErrorHandling(string, errorMessage) {
|
|
138
|
+
try {
|
|
139
|
+
return JSON.parse(string);
|
|
140
|
+
} catch (error) {
|
|
141
|
+
throw new JsonParseError(errorMessage ?? "Unable to parse string to JSON.", string);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function parseWithErrorHandling(schema, data, customErrorMessage) {
|
|
145
|
+
const parseResult = schema.safeParse(data);
|
|
146
|
+
if (!parseResult.success) {
|
|
147
|
+
throw new ValidationError(
|
|
148
|
+
customErrorMessage ?? `Error validating schema with data ${JSON.stringify(data)}`,
|
|
149
|
+
parseResult.error
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
return parseResult.data;
|
|
153
|
+
}
|
|
154
|
+
|
|
118
155
|
// src/path.ts
|
|
119
156
|
function joinUriParts(base, parts) {
|
|
120
157
|
if (parts.length === 0) return base;
|
|
@@ -131,8 +168,8 @@ function joinUriParts(base, parts) {
|
|
|
131
168
|
}
|
|
132
169
|
|
|
133
170
|
// src/url.ts
|
|
134
|
-
function getQueryParams(
|
|
135
|
-
const parsedUrl = new _URL(
|
|
171
|
+
function getQueryParams(url) {
|
|
172
|
+
const parsedUrl = new _URL(url);
|
|
136
173
|
const searchParams = new _URLSearchParams(parsedUrl.search);
|
|
137
174
|
const params = {};
|
|
138
175
|
searchParams.forEach((value, key) => {
|
|
@@ -150,9 +187,6 @@ function objectToQueryParams(object) {
|
|
|
150
187
|
return params;
|
|
151
188
|
}
|
|
152
189
|
|
|
153
|
-
// src/valibot-fetcher.ts
|
|
154
|
-
import * as v2 from "valibot";
|
|
155
|
-
|
|
156
190
|
// src/content-type.ts
|
|
157
191
|
var ContentType = /* @__PURE__ */ ((ContentType2) => {
|
|
158
192
|
ContentType2["XWwwFormUrlencoded"] = "application/x-www-form-urlencoded";
|
|
@@ -169,9 +203,9 @@ function isResponseContentType(contentType, response) {
|
|
|
169
203
|
return isContentType(contentType, header);
|
|
170
204
|
}
|
|
171
205
|
|
|
172
|
-
// src/
|
|
206
|
+
// src/zod-fetcher.ts
|
|
173
207
|
var defaultFetcher = fetch;
|
|
174
|
-
function
|
|
208
|
+
function createZodFetcher(fetcher = defaultFetcher) {
|
|
175
209
|
return async (schema, expectedContentType, ...args) => {
|
|
176
210
|
const response = await fetcher(...args);
|
|
177
211
|
if (response.ok && !isResponseContentType(expectedContentType, response)) {
|
|
@@ -183,13 +217,13 @@ function createValibotFetcher(fetcher = defaultFetcher) {
|
|
|
183
217
|
}
|
|
184
218
|
return {
|
|
185
219
|
response,
|
|
186
|
-
result: response.ok ?
|
|
220
|
+
result: response.ok ? schema.safeParse(await response.json()) : void 0
|
|
187
221
|
};
|
|
188
222
|
};
|
|
189
223
|
}
|
|
190
224
|
|
|
191
225
|
// src/validation.ts
|
|
192
|
-
import
|
|
226
|
+
import z from "zod";
|
|
193
227
|
|
|
194
228
|
// src/config.ts
|
|
195
229
|
var GLOBAL_CONFIG = {
|
|
@@ -203,16 +237,36 @@ function getGlobalConfig() {
|
|
|
203
237
|
}
|
|
204
238
|
|
|
205
239
|
// src/validation.ts
|
|
206
|
-
var
|
|
207
|
-
|
|
208
|
-
v3.url(),
|
|
209
|
-
v3.check((url2) => {
|
|
240
|
+
var zHttpsUrl = z.string().url().refine(
|
|
241
|
+
(url) => {
|
|
210
242
|
const { allowInsecureUrls } = getGlobalConfig();
|
|
211
|
-
return allowInsecureUrls ?
|
|
212
|
-
},
|
|
243
|
+
return allowInsecureUrls ? url.startsWith("http://") || url.startsWith("https://") : url.startsWith("https://");
|
|
244
|
+
},
|
|
245
|
+
{ message: "url must be an https:// url" }
|
|
213
246
|
);
|
|
214
|
-
var
|
|
215
|
-
var
|
|
247
|
+
var zInteger = z.number().int();
|
|
248
|
+
var zHttpMethod = z.enum(["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "TRACE", "CONNECT", "PATCH"]);
|
|
249
|
+
var zIs = (schema, data) => schema.safeParse(data).success;
|
|
250
|
+
|
|
251
|
+
// src/object.ts
|
|
252
|
+
function isObject(item) {
|
|
253
|
+
return item != null && typeof item === "object" && !Array.isArray(item);
|
|
254
|
+
}
|
|
255
|
+
function mergeDeep(target, ...sources) {
|
|
256
|
+
if (!sources.length) return target;
|
|
257
|
+
const source = sources.shift();
|
|
258
|
+
if (isObject(target) && isObject(source)) {
|
|
259
|
+
for (const key in source) {
|
|
260
|
+
if (isObject(source[key])) {
|
|
261
|
+
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
262
|
+
mergeDeep(target[key], source[key]);
|
|
263
|
+
} else {
|
|
264
|
+
Object.assign(target, { [key]: source[key] });
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return mergeDeep(target, ...sources);
|
|
269
|
+
}
|
|
216
270
|
|
|
217
271
|
// src/array.ts
|
|
218
272
|
function arrayEqualsIgnoreOrder(a, b) {
|
|
@@ -228,10 +282,10 @@ var body = (
|
|
|
228
282
|
// biome-ignore lint/suspicious/noControlCharactersInRegex: <explanation>
|
|
229
283
|
/((?:[a-zA-Z0-9._~+\/-]+=*(?:\s+|$))|[^\u0000-\u001F\u007F()<>@,;:\\"/?={}\[\]\u0020\u0009]+)(?:=([^\\"=\s,]+|"(?:[^"\\]|\\.)*"))?/g
|
|
230
284
|
);
|
|
231
|
-
var parsePayload = (scheme,
|
|
285
|
+
var parsePayload = (scheme, string) => {
|
|
232
286
|
const payload = {};
|
|
233
287
|
while (true) {
|
|
234
|
-
const res = body.exec(
|
|
288
|
+
const res = body.exec(string);
|
|
235
289
|
if (!res) break;
|
|
236
290
|
const [, key, newValue] = res;
|
|
237
291
|
const payloadValue = payload[key];
|
|
@@ -276,7 +330,7 @@ function encodeWwwAuthenticateHeader(challenges) {
|
|
|
276
330
|
const encodedParams = Object.entries(challenge.payload).flatMap(([key, value]) => {
|
|
277
331
|
const encode = (s) => s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
278
332
|
if (Array.isArray(value)) {
|
|
279
|
-
return value.map((
|
|
333
|
+
return value.map((v) => `${key}="${encode(v)}"`);
|
|
280
334
|
}
|
|
281
335
|
return value ? `${key}="${encode(value)}"` : key;
|
|
282
336
|
});
|
|
@@ -294,7 +348,7 @@ export {
|
|
|
294
348
|
ValidationError,
|
|
295
349
|
addSecondsToDate,
|
|
296
350
|
arrayEqualsIgnoreOrder,
|
|
297
|
-
|
|
351
|
+
createZodFetcher,
|
|
298
352
|
dateToSeconds,
|
|
299
353
|
decodeBase64,
|
|
300
354
|
decodeUtf8String,
|
|
@@ -314,9 +368,9 @@ export {
|
|
|
314
368
|
parseWwwAuthenticateHeader,
|
|
315
369
|
setGlobalConfig,
|
|
316
370
|
stringToJsonWithErrorHandling,
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
371
|
+
zHttpMethod,
|
|
372
|
+
zHttpsUrl,
|
|
373
|
+
zInteger,
|
|
374
|
+
zIs
|
|
321
375
|
};
|
|
322
376
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/globals.ts","../src/error/JsonParseError.ts","../src/parse.ts","../src/object.ts","../src/error/ValidationError.ts","../src/error/InvalidFetchResponseError.ts","../src/date.ts","../src/encoding.ts","../src/path.ts","../src/url.ts","../src/valibot-fetcher.ts","../src/content-type.ts","../src/validation.ts","../src/config.ts","../src/array.ts","../src/www-authenticate.ts"],"sourcesContent":["// Theses types are provided by the platform (so @types/node, @types/react-native, DOM)\n\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nconst _URL = URL\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nconst _URLSearchParams = URLSearchParams\n\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nexport type Fetch = typeof fetch\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nexport type FetchResponse = Response\n// biome-ignore lint/style/noRestrictedGlobals: <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","export class JsonParseError extends Error {\n public constructor(message: string, jsonString: string) {\n super(`${message}\\n${jsonString}`)\n }\n}\n","import * as v from 'valibot'\nimport { JsonParseError } from './error/JsonParseError'\nimport { ValidationError } from './error/ValidationError'\nimport { mergeDeep } from './object'\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\nexport type BaseSchema = v.BaseSchema<any, any, any>\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\nexport type InferOutputUnion<T extends readonly any[]> = {\n [K in keyof T]: v.InferOutput<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 parseWithErrorHandling<Schema extends BaseSchema>(\n schema: Schema,\n data: unknown,\n customErrorMessage?: string\n): v.InferOutput<Schema> {\n const parseResult = v.safeParse(schema, data)\n\n if (!parseResult.success) {\n throw new ValidationError(\n customErrorMessage ?? `Error validating schema with data ${JSON.stringify(data)}`,\n parseResult.issues\n )\n }\n\n return parseResult.output\n}\n\nexport function valibotRecursiveFlattenIssues(issues: v.BaseIssue<unknown>[]): Record<string, unknown> {\n let flattened: unknown = v.flatten(issues as [v.BaseIssue<unknown>])\n\n for (const issue of issues) {\n if (issue.issues) {\n flattened = mergeDeep(flattened, valibotRecursiveFlattenIssues(issue.issues))\n }\n }\n\n return flattened as Record<string, unknown>\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 * as v from 'valibot'\nimport { valibotRecursiveFlattenIssues } from '../parse'\n\nexport class ValidationError<\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n Schema extends v.BaseSchema<any, any, any> = v.BaseSchema<any, any, any>,\n> extends Error {\n public constructor(\n message: string,\n public readonly valibotIssues: Array<v.InferIssue<Schema>> = []\n ) {\n const errorDetails =\n valibotIssues.length > 0\n ? JSON.stringify(valibotRecursiveFlattenIssues(valibotIssues), null, 2)\n : 'No details provided'\n super(`${message}\\n${errorDetails}`)\n }\n}\n","import 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 super(`${message}\\n${textResponse}`)\n this.response = response.clone()\n }\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","// biome-ignore lint/style/useNodejsImportProtocol: also imported in other environments\nimport { 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","/**\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 * as v from 'valibot'\nimport { type ContentType, isResponseContentType } from './content-type'\nimport { InvalidFetchResponseError } from './error/InvalidFetchResponseError'\nimport type { Fetch } from './globals'\n\n// biome-ignore lint/suspicious/noExplicitAny: any type needed for generic\nexport type ValibotFetcher = <Schema extends v.BaseSchema<any, any, any>>(\n schema: Schema,\n expectedContentType: ContentType,\n ...args: Parameters<Fetch>\n) => Promise<{ response: Awaited<ReturnType<Fetch>>; result?: v.SafeParseResult<Schema> }>\n\n/**\n * The default fetcher used when no\n * fetcher is provided.\n */\n// @ts-ignore\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nexport const defaultFetcher = fetch\n\n/**\n * Creates a `fetchWithValibot` function that takes in a schema of\n * the expected response, and the arguments to fetch.\n *\n * If you don't provide a fetcher in `createValibotFetcher()`,\n * we're falling back to the default fetcher.\n *\n * @example\n *\n * const fetchWithValibot = createValibotFetcher();\n *\n * const { response, data } = await fetchWithValibot(\n * v.looseObject({\n * format: v.string()\n * }),\n * \"https://example.com\",\n * );\n */\nexport function createValibotFetcher(\n /**\n * A fetcher function that returns a response, from which the data can be parsed\n */\n fetcher = defaultFetcher\n): ValibotFetcher {\n return async (schema, expectedContentType, ...args) => {\n const response = await fetcher(...args)\n\n if (response.ok && !isResponseContentType(expectedContentType, response)) {\n throw new InvalidFetchResponseError(\n `Expected response to match content type '${expectedContentType}', but received '${response.headers.get('Content-Type')}'`,\n await response.clone().text(),\n response\n )\n }\n\n return {\n response,\n result: response.ok ? v.safeParse(schema, await response.json()) : undefined,\n }\n }\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}\n\nexport function isContentType(contentType: ContentType, value: string) {\n return value.toLowerCase().trim().split(';')[0] === contentType\n}\n\nexport function isResponseContentType(contentType: ContentType, response: FetchResponse) {\n const header = response.headers.get('Content-Type')\n if (!header) return false\n return isContentType(contentType, header)\n}\n","import * as v from 'valibot'\nimport { getGlobalConfig } from './config'\n\nexport const vHttpsUrl = v.pipe(\n v.string(),\n v.url(),\n v.check((url) => {\n const { allowInsecureUrls } = getGlobalConfig()\n return allowInsecureUrls ? url.startsWith('http://') || url.startsWith('https://') : url.startsWith('https://')\n }, 'url must be an https:// url')\n)\nexport const vInteger = v.pipe(v.number(), v.integer())\n\nexport const vHttpMethod = v.picklist(['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS', 'TRACE', 'CONNECT', 'PATCH'])\nexport type HttpMethod = v.InferOutput<typeof vHttpMethod>\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","/**\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","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: <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 = 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"],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;AAED,YAAQ,KAAK,cAAc,WAAW,IAAI,UAAU,SAAS,GAAG,UAAU,MAAM,IAAI,cAAc,KAAK,IAAI,CAAC,EAAE;AAAA,EAChH;AAEA,SAAO,QAAQ,KAAK,IAAI;AAC1B;","names":["string","string","url","v","ContentType","v","url","string","v"]}
|
|
1
|
+
{"version":3,"sources":["../src/globals.ts","../src/error/JsonParseError.ts","../src/error/ValidationError.ts","../src/error/InvalidFetchResponseError.ts","../src/date.ts","../src/encoding.ts","../src/parse.ts","../src/path.ts","../src/url.ts","../src/content-type.ts","../src/zod-fetcher.ts","../src/validation.ts","../src/config.ts","../src/object.ts","../src/array.ts","../src/www-authenticate.ts"],"sourcesContent":["// Theses types are provided by the platform (so @types/node, @types/react-native, DOM)\n\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nconst _URL = URL\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nconst _URLSearchParams = URLSearchParams\n\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nexport type Fetch = typeof fetch\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nexport type FetchResponse = Response\n// biome-ignore lint/style/noRestrictedGlobals: <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","export class JsonParseError extends Error {\n public constructor(message: string, jsonString: string) {\n super(`${message}\\n${jsonString}`)\n }\n}\n","import type z from 'zod'\nimport { type ZodError, type ZodIssue, ZodIssueCode } from 'zod'\n\n/**\n * Some code comes from `zod-validation-error` package (MIT License) and\n * was slightly simplified to fit our needs.\n */\nconst constants = {\n // biome-ignore lint/suspicious/noMisleadingCharacterClass: expected\n identifierRegex: /[$_\\p{ID_Start}][$\\u200c\\u200d\\p{ID_Continue}]*/u,\n unionSeparator: ', or ',\n issueSeparator: '\\n\\t- ',\n}\n\nexport class ValidationError extends Error {\n public zodError: ZodError | undefined\n\n private escapeQuotes(str: string): string {\n return str.replace(/\"/g, '\\\\\"')\n }\n\n private joinPath(path: Array<string | number>): string {\n if (path.length === 1) {\n return path[0].toString()\n }\n\n return path.reduce<string>((acc, item) => {\n // handle numeric indices\n if (typeof item === 'number') {\n return `${acc}[${item.toString()}]`\n }\n\n // handle quoted values\n if (item.includes('\"')) {\n return `${acc}[\"${this.escapeQuotes(item)}\"]`\n }\n\n // handle special characters\n if (!constants.identifierRegex.test(item)) {\n return `${acc}[\"${item}\"]`\n }\n\n // handle normal values\n const separator = acc.length === 0 ? '' : '.'\n return acc + separator + item\n }, '')\n }\n\n private getMessageFromUnionErrors(unionErrors: z.ZodError[]): string {\n return unionErrors\n .reduce<string[]>((acc, zodError) => {\n const newIssues = zodError.issues\n .map((issue) => this.getMessageFromZodIssue(issue))\n .join(constants.issueSeparator)\n\n if (!acc.includes(newIssues)) acc.push(newIssues)\n\n return acc\n }, [])\n .join(constants.unionSeparator)\n }\n\n private getMessageFromZodIssue(issue: ZodIssue): string {\n if (issue.code === ZodIssueCode.invalid_union) {\n return this.getMessageFromUnionErrors(issue.unionErrors)\n }\n\n if (issue.code === ZodIssueCode.invalid_arguments) {\n return [issue.message, ...issue.argumentsError.issues.map((issue) => this.getMessageFromZodIssue(issue))].join(\n constants.issueSeparator\n )\n }\n\n if (issue.code === ZodIssueCode.invalid_return_type) {\n return [issue.message, ...issue.returnTypeError.issues.map((issue) => this.getMessageFromZodIssue(issue))].join(\n constants.issueSeparator\n )\n }\n\n if (issue.path.length !== 0) {\n // handle array indices\n if (issue.path.length === 1) {\n const identifier = issue.path[0]\n\n if (typeof identifier === 'number') {\n return `${issue.message} at index ${identifier}`\n }\n }\n\n return `${issue.message} at \"${this.joinPath(issue.path)}\"`\n }\n\n return issue.message\n }\n\n private formatError(error?: z.ZodError): string {\n if (!error) return ''\n\n return error?.issues.map((issue) => this.getMessageFromZodIssue(issue)).join(constants.issueSeparator)\n }\n\n constructor(message: string, zodError?: z.ZodError) {\n super(message)\n\n const formattedError = this.formatError(zodError)\n this.message = `${message}\\n\\t- ${formattedError}`\n\n Object.defineProperty(this, 'zodError', {\n value: zodError,\n writable: false,\n enumerable: false,\n })\n }\n}\n","import 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 super(`${message}\\n${textResponse}`)\n this.response = response.clone()\n }\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","// biome-ignore lint/style/useNodejsImportProtocol: also imported in other environments\nimport { 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 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: <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 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 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}\n\nexport function isContentType(contentType: ContentType, value: string) {\n return value.toLowerCase().trim().split(';')[0] === contentType\n}\n\nexport function isResponseContentType(contentType: ContentType, response: FetchResponse) {\n const header = response.headers.get('Content-Type')\n if (!header) return false\n return isContentType(contentType, header)\n}\n","import type z from 'zod'\nimport { type ContentType, isResponseContentType } from './content-type'\nimport { InvalidFetchResponseError } from './error/InvalidFetchResponseError'\nimport type { Fetch } 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,\n ...args: Parameters<Fetch>\n) => Promise<{ response: Awaited<ReturnType<Fetch>>; result?: z.SafeParseReturnType<Schema, z.infer<Schema>> }>\n\n/**\n * The default fetcher used by createZodFetcher when no\n * fetcher is provided.\n */\n\n// biome-ignore lint/style/noRestrictedGlobals: <explanation>\nexport const defaultFetcher = fetch\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 = defaultFetcher): ZodFetcher {\n return async (schema, expectedContentType, ...args) => {\n const response = await fetcher(...args)\n\n if (response.ok && !isResponseContentType(expectedContentType, response)) {\n throw new InvalidFetchResponseError(\n `Expected response to match content type '${expectedContentType}', but received '${response.headers.get('Content-Type')}'`,\n await response.clone().text(),\n response\n )\n }\n\n return {\n response,\n result: response.ok ? schema.safeParse(await response.json()) : undefined,\n }\n }\n}\n","import z from 'zod'\nimport { getGlobalConfig } from './config'\n\nexport const zHttpsUrl = z\n .string()\n .url()\n .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 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 zIs = <Schema extends z.ZodSchema>(schema: Schema, data: unknown): data is z.infer<typeof schema> =>\n schema.safeParse(data).success\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","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","/**\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","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: <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 = 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"],"mappings":";AAGA,IAAM,OAAO;AAEb,IAAM,mBAAmB;AAOzB,IAAM,WAAW;;;ACZV,IAAM,iBAAN,cAA6B,MAAM;AAAA,EACjC,YAAY,SAAiB,YAAoB;AACtD,UAAM,GAAG,OAAO;AAAA,EAAK,UAAU,EAAE;AAAA,EACnC;AACF;;;ACHA,SAAuC,oBAAoB;AAM3D,IAAM,YAAY;AAAA;AAAA,EAEhB,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,gBAAgB;AAClB;AAEO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAGjC,aAAa,KAAqB;AACxC,WAAO,IAAI,QAAQ,MAAM,KAAK;AAAA,EAChC;AAAA,EAEQ,SAAS,MAAsC;AACrD,QAAI,KAAK,WAAW,GAAG;AACrB,aAAO,KAAK,CAAC,EAAE,SAAS;AAAA,IAC1B;AAEA,WAAO,KAAK,OAAe,CAAC,KAAK,SAAS;AAExC,UAAI,OAAO,SAAS,UAAU;AAC5B,eAAO,GAAG,GAAG,IAAI,KAAK,SAAS,CAAC;AAAA,MAClC;AAGA,UAAI,KAAK,SAAS,GAAG,GAAG;AACtB,eAAO,GAAG,GAAG,KAAK,KAAK,aAAa,IAAI,CAAC;A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,EAAE;AAAA,EAChH;AAEA,SAAO,QAAQ,KAAK,IAAI;AAC1B;","names":["issue","ContentType"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openid4vc/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-alpha-20250202020720",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
6
|
"import": "./dist/index.mjs",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"buffer": "^6.0.3",
|
|
24
|
-
"
|
|
24
|
+
"zod": "^3.24.1"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"build": "tsup src/index.ts --format cjs,esm --dts --clean --sourcemap"
|