@openid4vc/utils 0.2.0-alpha-20250109205223
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/README.md +9 -0
- package/dist/index.d.mts +159 -0
- package/dist/index.d.ts +159 -0
- package/dist/index.js +391 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +322 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<h1 align="center" ><b>OpenID for Verifiable Credentials - OAuth2 Utils</b></h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://typescriptlang.org">
|
|
5
|
+
<img src="https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg" />
|
|
6
|
+
</a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
Check out the documentation in the [Github repository](https://github.com/openwallet-foundation-labs/oid4vc-ts).
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
|
|
3
|
+
declare const _URL: {
|
|
4
|
+
new (url: string | URL, base?: string | URL): URL;
|
|
5
|
+
prototype: URL;
|
|
6
|
+
canParse(url: string | URL, base?: string | URL): boolean;
|
|
7
|
+
createObjectURL(obj: Blob | MediaSource): string;
|
|
8
|
+
parse(url: string | URL, base?: string | URL): URL | null;
|
|
9
|
+
revokeObjectURL(url: string): void;
|
|
10
|
+
};
|
|
11
|
+
declare const _URLSearchParams: {
|
|
12
|
+
new (init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
|
|
13
|
+
prototype: URLSearchParams;
|
|
14
|
+
};
|
|
15
|
+
type Fetch = typeof fetch;
|
|
16
|
+
type FetchResponse = Response;
|
|
17
|
+
declare const _Headers: typeof globalThis.Headers;
|
|
18
|
+
type FetchHeaders = globalThis.Headers;
|
|
19
|
+
type FetchRequestInit = RequestInit;
|
|
20
|
+
|
|
21
|
+
declare class JsonParseError extends Error {
|
|
22
|
+
constructor(message: string, jsonString: string);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare class ValidationError<Schema extends v.BaseSchema<any, any, any> = v.BaseSchema<any, any, any>> extends Error {
|
|
26
|
+
readonly valibotIssues: Array<v.InferIssue<Schema>>;
|
|
27
|
+
constructor(message: string, valibotIssues?: Array<v.InferIssue<Schema>>);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare class InvalidFetchResponseError extends Error {
|
|
31
|
+
readonly textResponse: string;
|
|
32
|
+
readonly response: FetchResponse;
|
|
33
|
+
constructor(message: string, textResponse: string, response: FetchResponse);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Get the time in seconds since epoch for a date.
|
|
38
|
+
* If date is not provided the current time will be used.
|
|
39
|
+
*/
|
|
40
|
+
declare function dateToSeconds(date?: Date): number;
|
|
41
|
+
declare function addSecondsToDate(date: Date, seconds: number): Date;
|
|
42
|
+
|
|
43
|
+
declare function decodeUtf8String(string: string): Uint8Array;
|
|
44
|
+
declare function encodeToUtf8String(data: Uint8Array): string;
|
|
45
|
+
/**
|
|
46
|
+
* Also supports base64 url
|
|
47
|
+
*/
|
|
48
|
+
declare function decodeBase64(base64: string): Uint8Array;
|
|
49
|
+
declare function encodeToBase64(data: Uint8Array | string): string;
|
|
50
|
+
declare function encodeToBase64Url(data: Uint8Array | string): string;
|
|
51
|
+
|
|
52
|
+
type BaseSchema = v.BaseSchema<any, any, any>;
|
|
53
|
+
type InferOutputUnion<T extends readonly any[]> = {
|
|
54
|
+
[K in keyof T]: v.InferOutput<T[K]>;
|
|
55
|
+
}[number];
|
|
56
|
+
declare function stringToJsonWithErrorHandling(string: string, errorMessage?: string): any;
|
|
57
|
+
declare function parseWithErrorHandling<Schema extends BaseSchema>(schema: Schema, data: unknown, customErrorMessage?: string): v.InferOutput<Schema>;
|
|
58
|
+
declare function valibotRecursiveFlattenIssues(issues: v.BaseIssue<unknown>[]): Record<string, unknown>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Combine multiple uri parts into a single uri taking into account slashes.
|
|
62
|
+
*
|
|
63
|
+
* @param parts the parts to combine
|
|
64
|
+
* @returns the combined url
|
|
65
|
+
*/
|
|
66
|
+
declare function joinUriParts(base: string, parts: string[]): string;
|
|
67
|
+
|
|
68
|
+
type Simplify<T> = {
|
|
69
|
+
[KeyType in keyof T]: T[KeyType];
|
|
70
|
+
} & {};
|
|
71
|
+
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
72
|
+
type StringWithAutoCompletion<T extends string> = T | (string & {});
|
|
73
|
+
type OrPromise<T> = T | Promise<T>;
|
|
74
|
+
|
|
75
|
+
declare function getQueryParams(url: string): Record<string, string>;
|
|
76
|
+
declare function objectToQueryParams(object: Record<string, unknown>): InstanceType<typeof _URLSearchParams>;
|
|
77
|
+
|
|
78
|
+
declare enum ContentType {
|
|
79
|
+
XWwwFormUrlencoded = "application/x-www-form-urlencoded",
|
|
80
|
+
Json = "application/json",
|
|
81
|
+
JwkSet = "application/jwk-set+json"
|
|
82
|
+
}
|
|
83
|
+
declare function isContentType(contentType: ContentType, value: string): boolean;
|
|
84
|
+
declare function isResponseContentType(contentType: ContentType, response: FetchResponse): boolean;
|
|
85
|
+
|
|
86
|
+
type ValibotFetcher = <Schema extends v.BaseSchema<any, any, any>>(schema: Schema, expectedContentType: ContentType, ...args: Parameters<Fetch>) => Promise<{
|
|
87
|
+
response: Awaited<ReturnType<Fetch>>;
|
|
88
|
+
result?: v.SafeParseResult<Schema>;
|
|
89
|
+
}>;
|
|
90
|
+
/**
|
|
91
|
+
* The default fetcher used when no
|
|
92
|
+
* fetcher is provided.
|
|
93
|
+
*/
|
|
94
|
+
declare const defaultFetcher: typeof fetch;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a `fetchWithValibot` function that takes in a schema of
|
|
97
|
+
* the expected response, and the arguments to fetch.
|
|
98
|
+
*
|
|
99
|
+
* If you don't provide a fetcher in `createValibotFetcher()`,
|
|
100
|
+
* we're falling back to the default fetcher.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
*
|
|
104
|
+
* const fetchWithValibot = createValibotFetcher();
|
|
105
|
+
*
|
|
106
|
+
* const { response, data } = await fetchWithValibot(
|
|
107
|
+
* v.looseObject({
|
|
108
|
+
* format: v.string()
|
|
109
|
+
* }),
|
|
110
|
+
* "https://example.com",
|
|
111
|
+
* );
|
|
112
|
+
*/
|
|
113
|
+
declare function createValibotFetcher(
|
|
114
|
+
/**
|
|
115
|
+
* A fetcher function that returns a response, from which the data can be parsed
|
|
116
|
+
*/
|
|
117
|
+
fetcher?: typeof fetch): ValibotFetcher;
|
|
118
|
+
|
|
119
|
+
declare const vHttpsUrl: v.SchemaWithPipe<[v.StringSchema<undefined>, v.UrlAction<string, undefined>, v.CheckAction<string, "url must be an https:// url">]>;
|
|
120
|
+
declare const vInteger: v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>;
|
|
121
|
+
declare const vHttpMethod: v.PicklistSchema<["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "TRACE", "CONNECT", "PATCH"], undefined>;
|
|
122
|
+
type HttpMethod = v.InferOutput<typeof vHttpMethod>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Deep merge two objects.
|
|
126
|
+
* @param target
|
|
127
|
+
* @param ...sources
|
|
128
|
+
*/
|
|
129
|
+
declare function mergeDeep(target: unknown, ...sources: Array<unknown>): unknown;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Only primitive types allowed
|
|
133
|
+
* Must have not duplicate entries (will always return false in this case)
|
|
134
|
+
*/
|
|
135
|
+
declare function arrayEqualsIgnoreOrder<Item extends string | number | boolean>(a: Array<Item>, b: Array<Item>): boolean;
|
|
136
|
+
|
|
137
|
+
interface WwwAuthenticateHeaderChallenge {
|
|
138
|
+
scheme: string;
|
|
139
|
+
/**
|
|
140
|
+
* Record where the keys are the names, and the value can be 0 (null), 1 (string) or multiple (string[])
|
|
141
|
+
* entries
|
|
142
|
+
*/
|
|
143
|
+
payload: Record<string, string | string[] | null>;
|
|
144
|
+
}
|
|
145
|
+
declare function parseWwwAuthenticateHeader(str: string): WwwAuthenticateHeaderChallenge[];
|
|
146
|
+
declare function encodeWwwAuthenticateHeader(challenges: WwwAuthenticateHeaderChallenge[]): string;
|
|
147
|
+
|
|
148
|
+
interface Oid4vcTsConfig {
|
|
149
|
+
/**
|
|
150
|
+
* Whether to allow insecure http urls.
|
|
151
|
+
*
|
|
152
|
+
* @default false
|
|
153
|
+
*/
|
|
154
|
+
allowInsecureUrls: boolean;
|
|
155
|
+
}
|
|
156
|
+
declare function setGlobalConfig(config: Oid4vcTsConfig): void;
|
|
157
|
+
declare function getGlobalConfig(): Oid4vcTsConfig;
|
|
158
|
+
|
|
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, type ValibotFetcher, ValidationError, type WwwAuthenticateHeaderChallenge, addSecondsToDate, arrayEqualsIgnoreOrder, createValibotFetcher, dateToSeconds, decodeBase64, decodeUtf8String, defaultFetcher, encodeToBase64, encodeToBase64Url, encodeToUtf8String, encodeWwwAuthenticateHeader, getGlobalConfig, getQueryParams, isContentType, isResponseContentType, joinUriParts, mergeDeep, objectToQueryParams, parseWithErrorHandling, parseWwwAuthenticateHeader, setGlobalConfig, stringToJsonWithErrorHandling, vHttpMethod, vHttpsUrl, vInteger, valibotRecursiveFlattenIssues };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
|
|
3
|
+
declare const _URL: {
|
|
4
|
+
new (url: string | URL, base?: string | URL): URL;
|
|
5
|
+
prototype: URL;
|
|
6
|
+
canParse(url: string | URL, base?: string | URL): boolean;
|
|
7
|
+
createObjectURL(obj: Blob | MediaSource): string;
|
|
8
|
+
parse(url: string | URL, base?: string | URL): URL | null;
|
|
9
|
+
revokeObjectURL(url: string): void;
|
|
10
|
+
};
|
|
11
|
+
declare const _URLSearchParams: {
|
|
12
|
+
new (init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
|
|
13
|
+
prototype: URLSearchParams;
|
|
14
|
+
};
|
|
15
|
+
type Fetch = typeof fetch;
|
|
16
|
+
type FetchResponse = Response;
|
|
17
|
+
declare const _Headers: typeof globalThis.Headers;
|
|
18
|
+
type FetchHeaders = globalThis.Headers;
|
|
19
|
+
type FetchRequestInit = RequestInit;
|
|
20
|
+
|
|
21
|
+
declare class JsonParseError extends Error {
|
|
22
|
+
constructor(message: string, jsonString: string);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare class ValidationError<Schema extends v.BaseSchema<any, any, any> = v.BaseSchema<any, any, any>> extends Error {
|
|
26
|
+
readonly valibotIssues: Array<v.InferIssue<Schema>>;
|
|
27
|
+
constructor(message: string, valibotIssues?: Array<v.InferIssue<Schema>>);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare class InvalidFetchResponseError extends Error {
|
|
31
|
+
readonly textResponse: string;
|
|
32
|
+
readonly response: FetchResponse;
|
|
33
|
+
constructor(message: string, textResponse: string, response: FetchResponse);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Get the time in seconds since epoch for a date.
|
|
38
|
+
* If date is not provided the current time will be used.
|
|
39
|
+
*/
|
|
40
|
+
declare function dateToSeconds(date?: Date): number;
|
|
41
|
+
declare function addSecondsToDate(date: Date, seconds: number): Date;
|
|
42
|
+
|
|
43
|
+
declare function decodeUtf8String(string: string): Uint8Array;
|
|
44
|
+
declare function encodeToUtf8String(data: Uint8Array): string;
|
|
45
|
+
/**
|
|
46
|
+
* Also supports base64 url
|
|
47
|
+
*/
|
|
48
|
+
declare function decodeBase64(base64: string): Uint8Array;
|
|
49
|
+
declare function encodeToBase64(data: Uint8Array | string): string;
|
|
50
|
+
declare function encodeToBase64Url(data: Uint8Array | string): string;
|
|
51
|
+
|
|
52
|
+
type BaseSchema = v.BaseSchema<any, any, any>;
|
|
53
|
+
type InferOutputUnion<T extends readonly any[]> = {
|
|
54
|
+
[K in keyof T]: v.InferOutput<T[K]>;
|
|
55
|
+
}[number];
|
|
56
|
+
declare function stringToJsonWithErrorHandling(string: string, errorMessage?: string): any;
|
|
57
|
+
declare function parseWithErrorHandling<Schema extends BaseSchema>(schema: Schema, data: unknown, customErrorMessage?: string): v.InferOutput<Schema>;
|
|
58
|
+
declare function valibotRecursiveFlattenIssues(issues: v.BaseIssue<unknown>[]): Record<string, unknown>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Combine multiple uri parts into a single uri taking into account slashes.
|
|
62
|
+
*
|
|
63
|
+
* @param parts the parts to combine
|
|
64
|
+
* @returns the combined url
|
|
65
|
+
*/
|
|
66
|
+
declare function joinUriParts(base: string, parts: string[]): string;
|
|
67
|
+
|
|
68
|
+
type Simplify<T> = {
|
|
69
|
+
[KeyType in keyof T]: T[KeyType];
|
|
70
|
+
} & {};
|
|
71
|
+
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
72
|
+
type StringWithAutoCompletion<T extends string> = T | (string & {});
|
|
73
|
+
type OrPromise<T> = T | Promise<T>;
|
|
74
|
+
|
|
75
|
+
declare function getQueryParams(url: string): Record<string, string>;
|
|
76
|
+
declare function objectToQueryParams(object: Record<string, unknown>): InstanceType<typeof _URLSearchParams>;
|
|
77
|
+
|
|
78
|
+
declare enum ContentType {
|
|
79
|
+
XWwwFormUrlencoded = "application/x-www-form-urlencoded",
|
|
80
|
+
Json = "application/json",
|
|
81
|
+
JwkSet = "application/jwk-set+json"
|
|
82
|
+
}
|
|
83
|
+
declare function isContentType(contentType: ContentType, value: string): boolean;
|
|
84
|
+
declare function isResponseContentType(contentType: ContentType, response: FetchResponse): boolean;
|
|
85
|
+
|
|
86
|
+
type ValibotFetcher = <Schema extends v.BaseSchema<any, any, any>>(schema: Schema, expectedContentType: ContentType, ...args: Parameters<Fetch>) => Promise<{
|
|
87
|
+
response: Awaited<ReturnType<Fetch>>;
|
|
88
|
+
result?: v.SafeParseResult<Schema>;
|
|
89
|
+
}>;
|
|
90
|
+
/**
|
|
91
|
+
* The default fetcher used when no
|
|
92
|
+
* fetcher is provided.
|
|
93
|
+
*/
|
|
94
|
+
declare const defaultFetcher: typeof fetch;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a `fetchWithValibot` function that takes in a schema of
|
|
97
|
+
* the expected response, and the arguments to fetch.
|
|
98
|
+
*
|
|
99
|
+
* If you don't provide a fetcher in `createValibotFetcher()`,
|
|
100
|
+
* we're falling back to the default fetcher.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
*
|
|
104
|
+
* const fetchWithValibot = createValibotFetcher();
|
|
105
|
+
*
|
|
106
|
+
* const { response, data } = await fetchWithValibot(
|
|
107
|
+
* v.looseObject({
|
|
108
|
+
* format: v.string()
|
|
109
|
+
* }),
|
|
110
|
+
* "https://example.com",
|
|
111
|
+
* );
|
|
112
|
+
*/
|
|
113
|
+
declare function createValibotFetcher(
|
|
114
|
+
/**
|
|
115
|
+
* A fetcher function that returns a response, from which the data can be parsed
|
|
116
|
+
*/
|
|
117
|
+
fetcher?: typeof fetch): ValibotFetcher;
|
|
118
|
+
|
|
119
|
+
declare const vHttpsUrl: v.SchemaWithPipe<[v.StringSchema<undefined>, v.UrlAction<string, undefined>, v.CheckAction<string, "url must be an https:// url">]>;
|
|
120
|
+
declare const vInteger: v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>;
|
|
121
|
+
declare const vHttpMethod: v.PicklistSchema<["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "TRACE", "CONNECT", "PATCH"], undefined>;
|
|
122
|
+
type HttpMethod = v.InferOutput<typeof vHttpMethod>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Deep merge two objects.
|
|
126
|
+
* @param target
|
|
127
|
+
* @param ...sources
|
|
128
|
+
*/
|
|
129
|
+
declare function mergeDeep(target: unknown, ...sources: Array<unknown>): unknown;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Only primitive types allowed
|
|
133
|
+
* Must have not duplicate entries (will always return false in this case)
|
|
134
|
+
*/
|
|
135
|
+
declare function arrayEqualsIgnoreOrder<Item extends string | number | boolean>(a: Array<Item>, b: Array<Item>): boolean;
|
|
136
|
+
|
|
137
|
+
interface WwwAuthenticateHeaderChallenge {
|
|
138
|
+
scheme: string;
|
|
139
|
+
/**
|
|
140
|
+
* Record where the keys are the names, and the value can be 0 (null), 1 (string) or multiple (string[])
|
|
141
|
+
* entries
|
|
142
|
+
*/
|
|
143
|
+
payload: Record<string, string | string[] | null>;
|
|
144
|
+
}
|
|
145
|
+
declare function parseWwwAuthenticateHeader(str: string): WwwAuthenticateHeaderChallenge[];
|
|
146
|
+
declare function encodeWwwAuthenticateHeader(challenges: WwwAuthenticateHeaderChallenge[]): string;
|
|
147
|
+
|
|
148
|
+
interface Oid4vcTsConfig {
|
|
149
|
+
/**
|
|
150
|
+
* Whether to allow insecure http urls.
|
|
151
|
+
*
|
|
152
|
+
* @default false
|
|
153
|
+
*/
|
|
154
|
+
allowInsecureUrls: boolean;
|
|
155
|
+
}
|
|
156
|
+
declare function setGlobalConfig(config: Oid4vcTsConfig): void;
|
|
157
|
+
declare function getGlobalConfig(): Oid4vcTsConfig;
|
|
158
|
+
|
|
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, type ValibotFetcher, ValidationError, type WwwAuthenticateHeaderChallenge, addSecondsToDate, arrayEqualsIgnoreOrder, createValibotFetcher, dateToSeconds, decodeBase64, decodeUtf8String, defaultFetcher, encodeToBase64, encodeToBase64Url, encodeToUtf8String, encodeWwwAuthenticateHeader, getGlobalConfig, getQueryParams, isContentType, isResponseContentType, joinUriParts, mergeDeep, objectToQueryParams, parseWithErrorHandling, parseWwwAuthenticateHeader, setGlobalConfig, stringToJsonWithErrorHandling, vHttpMethod, vHttpsUrl, vInteger, valibotRecursiveFlattenIssues };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
ContentType: () => ContentType,
|
|
34
|
+
Headers: () => _Headers,
|
|
35
|
+
InvalidFetchResponseError: () => InvalidFetchResponseError,
|
|
36
|
+
JsonParseError: () => JsonParseError,
|
|
37
|
+
URL: () => _URL,
|
|
38
|
+
URLSearchParams: () => _URLSearchParams,
|
|
39
|
+
ValidationError: () => ValidationError,
|
|
40
|
+
addSecondsToDate: () => addSecondsToDate,
|
|
41
|
+
arrayEqualsIgnoreOrder: () => arrayEqualsIgnoreOrder,
|
|
42
|
+
createValibotFetcher: () => createValibotFetcher,
|
|
43
|
+
dateToSeconds: () => dateToSeconds,
|
|
44
|
+
decodeBase64: () => decodeBase64,
|
|
45
|
+
decodeUtf8String: () => decodeUtf8String,
|
|
46
|
+
defaultFetcher: () => defaultFetcher,
|
|
47
|
+
encodeToBase64: () => encodeToBase64,
|
|
48
|
+
encodeToBase64Url: () => encodeToBase64Url,
|
|
49
|
+
encodeToUtf8String: () => encodeToUtf8String,
|
|
50
|
+
encodeWwwAuthenticateHeader: () => encodeWwwAuthenticateHeader,
|
|
51
|
+
getGlobalConfig: () => getGlobalConfig,
|
|
52
|
+
getQueryParams: () => getQueryParams,
|
|
53
|
+
isContentType: () => isContentType,
|
|
54
|
+
isResponseContentType: () => isResponseContentType,
|
|
55
|
+
joinUriParts: () => joinUriParts,
|
|
56
|
+
mergeDeep: () => mergeDeep,
|
|
57
|
+
objectToQueryParams: () => objectToQueryParams,
|
|
58
|
+
parseWithErrorHandling: () => parseWithErrorHandling,
|
|
59
|
+
parseWwwAuthenticateHeader: () => parseWwwAuthenticateHeader,
|
|
60
|
+
setGlobalConfig: () => setGlobalConfig,
|
|
61
|
+
stringToJsonWithErrorHandling: () => stringToJsonWithErrorHandling,
|
|
62
|
+
vHttpMethod: () => vHttpMethod,
|
|
63
|
+
vHttpsUrl: () => vHttpsUrl,
|
|
64
|
+
vInteger: () => vInteger,
|
|
65
|
+
valibotRecursiveFlattenIssues: () => valibotRecursiveFlattenIssues
|
|
66
|
+
});
|
|
67
|
+
module.exports = __toCommonJS(src_exports);
|
|
68
|
+
|
|
69
|
+
// src/globals.ts
|
|
70
|
+
var _URL = URL;
|
|
71
|
+
var _URLSearchParams = URLSearchParams;
|
|
72
|
+
var _Headers = Headers;
|
|
73
|
+
|
|
74
|
+
// src/error/JsonParseError.ts
|
|
75
|
+
var JsonParseError = class extends Error {
|
|
76
|
+
constructor(message, jsonString) {
|
|
77
|
+
super(`${message}
|
|
78
|
+
${jsonString}`);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// src/parse.ts
|
|
83
|
+
var v = __toESM(require("valibot"));
|
|
84
|
+
|
|
85
|
+
// src/object.ts
|
|
86
|
+
function isObject(item) {
|
|
87
|
+
return item != null && typeof item === "object" && !Array.isArray(item);
|
|
88
|
+
}
|
|
89
|
+
function mergeDeep(target, ...sources) {
|
|
90
|
+
if (!sources.length) return target;
|
|
91
|
+
const source = sources.shift();
|
|
92
|
+
if (isObject(target) && isObject(source)) {
|
|
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
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return mergeDeep(target, ...sources);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/parse.ts
|
|
106
|
+
function stringToJsonWithErrorHandling(string2, errorMessage) {
|
|
107
|
+
try {
|
|
108
|
+
return JSON.parse(string2);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
throw new JsonParseError(errorMessage ?? "Unable to parse string to JSON.", string2);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function parseWithErrorHandling(schema, data, customErrorMessage) {
|
|
114
|
+
const parseResult = v.safeParse(schema, data);
|
|
115
|
+
if (!parseResult.success) {
|
|
116
|
+
throw new ValidationError(
|
|
117
|
+
customErrorMessage ?? `Error validating schema with data ${JSON.stringify(data)}`,
|
|
118
|
+
parseResult.issues
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
return parseResult.output;
|
|
122
|
+
}
|
|
123
|
+
function valibotRecursiveFlattenIssues(issues) {
|
|
124
|
+
let flattened = v.flatten(issues);
|
|
125
|
+
for (const issue of issues) {
|
|
126
|
+
if (issue.issues) {
|
|
127
|
+
flattened = mergeDeep(flattened, valibotRecursiveFlattenIssues(issue.issues));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return flattened;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/error/ValidationError.ts
|
|
134
|
+
var ValidationError = class extends Error {
|
|
135
|
+
constructor(message, valibotIssues = []) {
|
|
136
|
+
const errorDetails = valibotIssues.length > 0 ? JSON.stringify(valibotRecursiveFlattenIssues(valibotIssues), null, 2) : "No details provided";
|
|
137
|
+
super(`${message}
|
|
138
|
+
${errorDetails}`);
|
|
139
|
+
this.valibotIssues = valibotIssues;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// src/error/InvalidFetchResponseError.ts
|
|
144
|
+
var InvalidFetchResponseError = class extends Error {
|
|
145
|
+
constructor(message, textResponse, response) {
|
|
146
|
+
super(`${message}
|
|
147
|
+
${textResponse}`);
|
|
148
|
+
this.textResponse = textResponse;
|
|
149
|
+
this.response = response.clone();
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// src/date.ts
|
|
154
|
+
function dateToSeconds(date) {
|
|
155
|
+
const milliseconds = date?.getTime() ?? Date.now();
|
|
156
|
+
return Math.floor(milliseconds / 1e3);
|
|
157
|
+
}
|
|
158
|
+
function addSecondsToDate(date, seconds) {
|
|
159
|
+
return new Date(date.getTime() + seconds * 1e3);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/encoding.ts
|
|
163
|
+
var import_buffer = require("buffer");
|
|
164
|
+
function decodeUtf8String(string2) {
|
|
165
|
+
return new Uint8Array(import_buffer.Buffer.from(string2, "utf-8"));
|
|
166
|
+
}
|
|
167
|
+
function encodeToUtf8String(data) {
|
|
168
|
+
return import_buffer.Buffer.from(data).toString("utf-8");
|
|
169
|
+
}
|
|
170
|
+
function decodeBase64(base64) {
|
|
171
|
+
return new Uint8Array(import_buffer.Buffer.from(base64, "base64"));
|
|
172
|
+
}
|
|
173
|
+
function encodeToBase64(data) {
|
|
174
|
+
if (typeof data === "string") {
|
|
175
|
+
return import_buffer.Buffer.from(data).toString("base64");
|
|
176
|
+
}
|
|
177
|
+
return import_buffer.Buffer.from(data).toString("base64");
|
|
178
|
+
}
|
|
179
|
+
function encodeToBase64Url(data) {
|
|
180
|
+
return base64ToBase64Url(encodeToBase64(data));
|
|
181
|
+
}
|
|
182
|
+
function base64ToBase64Url(base64) {
|
|
183
|
+
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// src/path.ts
|
|
187
|
+
function joinUriParts(base, parts) {
|
|
188
|
+
if (parts.length === 0) return base;
|
|
189
|
+
let combined = base.trim();
|
|
190
|
+
combined = base.endsWith("/") ? base.slice(0, base.length - 1) : base;
|
|
191
|
+
for (const part of parts) {
|
|
192
|
+
let strippedPart = part.trim();
|
|
193
|
+
strippedPart = strippedPart.startsWith("/") ? strippedPart.slice(1) : strippedPart;
|
|
194
|
+
strippedPart = strippedPart.endsWith("/") ? strippedPart.slice(0, strippedPart.length - 1) : strippedPart;
|
|
195
|
+
if (strippedPart === "") continue;
|
|
196
|
+
combined += `/${strippedPart}`;
|
|
197
|
+
}
|
|
198
|
+
return combined;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// src/url.ts
|
|
202
|
+
function getQueryParams(url2) {
|
|
203
|
+
const parsedUrl = new _URL(url2);
|
|
204
|
+
const searchParams = new _URLSearchParams(parsedUrl.search);
|
|
205
|
+
const params = {};
|
|
206
|
+
searchParams.forEach((value, key) => {
|
|
207
|
+
params[key] = value;
|
|
208
|
+
});
|
|
209
|
+
return params;
|
|
210
|
+
}
|
|
211
|
+
function objectToQueryParams(object) {
|
|
212
|
+
const params = new _URLSearchParams();
|
|
213
|
+
for (const [key, value] of Object.entries(object)) {
|
|
214
|
+
if (value != null) {
|
|
215
|
+
params.append(key, typeof value === "object" ? JSON.stringify(value) : String(value));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return params;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/valibot-fetcher.ts
|
|
222
|
+
var v2 = __toESM(require("valibot"));
|
|
223
|
+
|
|
224
|
+
// src/content-type.ts
|
|
225
|
+
var ContentType = /* @__PURE__ */ ((ContentType2) => {
|
|
226
|
+
ContentType2["XWwwFormUrlencoded"] = "application/x-www-form-urlencoded";
|
|
227
|
+
ContentType2["Json"] = "application/json";
|
|
228
|
+
ContentType2["JwkSet"] = "application/jwk-set+json";
|
|
229
|
+
return ContentType2;
|
|
230
|
+
})(ContentType || {});
|
|
231
|
+
function isContentType(contentType, value) {
|
|
232
|
+
return value.toLowerCase().trim().split(";")[0] === contentType;
|
|
233
|
+
}
|
|
234
|
+
function isResponseContentType(contentType, response) {
|
|
235
|
+
const header = response.headers.get("Content-Type");
|
|
236
|
+
if (!header) return false;
|
|
237
|
+
return isContentType(contentType, header);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// src/valibot-fetcher.ts
|
|
241
|
+
var defaultFetcher = fetch;
|
|
242
|
+
function createValibotFetcher(fetcher = defaultFetcher) {
|
|
243
|
+
return async (schema, expectedContentType, ...args) => {
|
|
244
|
+
const response = await fetcher(...args);
|
|
245
|
+
if (response.ok && !isResponseContentType(expectedContentType, response)) {
|
|
246
|
+
throw new InvalidFetchResponseError(
|
|
247
|
+
`Expected response to match content type '${expectedContentType}', but received '${response.headers.get("Content-Type")}'`,
|
|
248
|
+
await response.clone().text(),
|
|
249
|
+
response
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
response,
|
|
254
|
+
result: response.ok ? v2.safeParse(schema, await response.json()) : void 0
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// src/validation.ts
|
|
260
|
+
var v3 = __toESM(require("valibot"));
|
|
261
|
+
|
|
262
|
+
// src/config.ts
|
|
263
|
+
var GLOBAL_CONFIG = {
|
|
264
|
+
allowInsecureUrls: false
|
|
265
|
+
};
|
|
266
|
+
function setGlobalConfig(config) {
|
|
267
|
+
GLOBAL_CONFIG = config;
|
|
268
|
+
}
|
|
269
|
+
function getGlobalConfig() {
|
|
270
|
+
return GLOBAL_CONFIG;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// src/validation.ts
|
|
274
|
+
var vHttpsUrl = v3.pipe(
|
|
275
|
+
v3.string(),
|
|
276
|
+
v3.url(),
|
|
277
|
+
v3.check((url2) => {
|
|
278
|
+
const { allowInsecureUrls } = getGlobalConfig();
|
|
279
|
+
return allowInsecureUrls ? url2.startsWith("http://") || url2.startsWith("https://") : url2.startsWith("https://");
|
|
280
|
+
}, "url must be an https:// url")
|
|
281
|
+
);
|
|
282
|
+
var vInteger = v3.pipe(v3.number(), v3.integer());
|
|
283
|
+
var vHttpMethod = v3.picklist(["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "TRACE", "CONNECT", "PATCH"]);
|
|
284
|
+
|
|
285
|
+
// src/array.ts
|
|
286
|
+
function arrayEqualsIgnoreOrder(a, b) {
|
|
287
|
+
if (new Set(a).size !== new Set(b).size) return false;
|
|
288
|
+
if (a.length !== b.length) return false;
|
|
289
|
+
return a.every((k) => b.includes(k));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// src/www-authenticate.ts
|
|
293
|
+
var unquote = (value) => value.substring(1, value.length - 1).replace(/\\"/g, '"');
|
|
294
|
+
var sanitize = (value) => value.charAt(0) === '"' ? unquote(value) : value.trim();
|
|
295
|
+
var body = (
|
|
296
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: <explanation>
|
|
297
|
+
/((?:[a-zA-Z0-9._~+\/-]+=*(?:\s+|$))|[^\u0000-\u001F\u007F()<>@,;:\\"/?={}\[\]\u0020\u0009]+)(?:=([^\\"=\s,]+|"(?:[^"\\]|\\.)*"))?/g
|
|
298
|
+
);
|
|
299
|
+
var parsePayload = (scheme, string2) => {
|
|
300
|
+
const payload = {};
|
|
301
|
+
while (true) {
|
|
302
|
+
const res = body.exec(string2);
|
|
303
|
+
if (!res) break;
|
|
304
|
+
const [, key, newValue] = res;
|
|
305
|
+
const payloadValue = payload[key];
|
|
306
|
+
if (newValue) {
|
|
307
|
+
const sanitizedValue = sanitize(newValue);
|
|
308
|
+
payload[key] = payloadValue ? Array.isArray(payloadValue) ? [...payloadValue, sanitizedValue] : [payloadValue, sanitizedValue] : sanitizedValue;
|
|
309
|
+
} else if (!payloadValue) {
|
|
310
|
+
payload[key] = null;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return { scheme, payload };
|
|
314
|
+
};
|
|
315
|
+
function parseWwwAuthenticateHeader(str) {
|
|
316
|
+
const start = str.indexOf(" ");
|
|
317
|
+
let scheme = str.substring(0, start);
|
|
318
|
+
let value = str.substring(start);
|
|
319
|
+
const challenges = [];
|
|
320
|
+
const endsWithSchemeRegex = /, ?(Bearer|DPoP|Basic)$/;
|
|
321
|
+
const endsWithSchemeTest = endsWithSchemeRegex.exec(value);
|
|
322
|
+
let endsWithScheme = void 0;
|
|
323
|
+
if (endsWithSchemeTest) {
|
|
324
|
+
value = value.substring(0, value.length - endsWithSchemeTest[0].length);
|
|
325
|
+
endsWithScheme = endsWithSchemeTest[1];
|
|
326
|
+
}
|
|
327
|
+
const additionalSchemesRegex = /(.*?)(, ?)(Bearer|DPoP|Basic)[, ]/;
|
|
328
|
+
let match = additionalSchemesRegex.exec(value);
|
|
329
|
+
while (match) {
|
|
330
|
+
challenges.push(parsePayload(scheme, match[1]));
|
|
331
|
+
value = value.substring(match[0].length - 1);
|
|
332
|
+
scheme = match[3];
|
|
333
|
+
match = additionalSchemesRegex.exec(value);
|
|
334
|
+
}
|
|
335
|
+
challenges.push(parsePayload(scheme, value));
|
|
336
|
+
if (endsWithScheme) {
|
|
337
|
+
challenges.push({ scheme: endsWithScheme, payload: {} });
|
|
338
|
+
}
|
|
339
|
+
return challenges;
|
|
340
|
+
}
|
|
341
|
+
function encodeWwwAuthenticateHeader(challenges) {
|
|
342
|
+
const entries = [];
|
|
343
|
+
for (const challenge of challenges) {
|
|
344
|
+
const encodedParams = Object.entries(challenge.payload).flatMap(([key, value]) => {
|
|
345
|
+
const encode = (s) => s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
346
|
+
if (Array.isArray(value)) {
|
|
347
|
+
return value.map((v4) => `${key}="${encode(v4)}"`);
|
|
348
|
+
}
|
|
349
|
+
return value ? `${key}="${encode(value)}"` : key;
|
|
350
|
+
});
|
|
351
|
+
entries.push(encodedParams.length === 0 ? challenge.scheme : `${challenge.scheme} ${encodedParams.join(", ")}`);
|
|
352
|
+
}
|
|
353
|
+
return entries.join(", ");
|
|
354
|
+
}
|
|
355
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
356
|
+
0 && (module.exports = {
|
|
357
|
+
ContentType,
|
|
358
|
+
Headers,
|
|
359
|
+
InvalidFetchResponseError,
|
|
360
|
+
JsonParseError,
|
|
361
|
+
URL,
|
|
362
|
+
URLSearchParams,
|
|
363
|
+
ValidationError,
|
|
364
|
+
addSecondsToDate,
|
|
365
|
+
arrayEqualsIgnoreOrder,
|
|
366
|
+
createValibotFetcher,
|
|
367
|
+
dateToSeconds,
|
|
368
|
+
decodeBase64,
|
|
369
|
+
decodeUtf8String,
|
|
370
|
+
defaultFetcher,
|
|
371
|
+
encodeToBase64,
|
|
372
|
+
encodeToBase64Url,
|
|
373
|
+
encodeToUtf8String,
|
|
374
|
+
encodeWwwAuthenticateHeader,
|
|
375
|
+
getGlobalConfig,
|
|
376
|
+
getQueryParams,
|
|
377
|
+
isContentType,
|
|
378
|
+
isResponseContentType,
|
|
379
|
+
joinUriParts,
|
|
380
|
+
mergeDeep,
|
|
381
|
+
objectToQueryParams,
|
|
382
|
+
parseWithErrorHandling,
|
|
383
|
+
parseWwwAuthenticateHeader,
|
|
384
|
+
setGlobalConfig,
|
|
385
|
+
stringToJsonWithErrorHandling,
|
|
386
|
+
vHttpMethod,
|
|
387
|
+
vHttpsUrl,
|
|
388
|
+
vInteger,
|
|
389
|
+
valibotRecursiveFlattenIssues
|
|
390
|
+
});
|
|
391
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;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,EACj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EAChH;AAEA,SAAO,QAAQ,KAAK,IAAI;AAC1B;","names":["string","string","url","v","ContentType","v","url","string","v"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
// src/globals.ts
|
|
2
|
+
var _URL = URL;
|
|
3
|
+
var _URLSearchParams = URLSearchParams;
|
|
4
|
+
var _Headers = Headers;
|
|
5
|
+
|
|
6
|
+
// src/error/JsonParseError.ts
|
|
7
|
+
var JsonParseError = class extends Error {
|
|
8
|
+
constructor(message, jsonString) {
|
|
9
|
+
super(`${message}
|
|
10
|
+
${jsonString}`);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/parse.ts
|
|
15
|
+
import * as v from "valibot";
|
|
16
|
+
|
|
17
|
+
// src/object.ts
|
|
18
|
+
function isObject(item) {
|
|
19
|
+
return item != null && typeof item === "object" && !Array.isArray(item);
|
|
20
|
+
}
|
|
21
|
+
function mergeDeep(target, ...sources) {
|
|
22
|
+
if (!sources.length) return target;
|
|
23
|
+
const source = sources.shift();
|
|
24
|
+
if (isObject(target) && isObject(source)) {
|
|
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
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return mergeDeep(target, ...sources);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/parse.ts
|
|
38
|
+
function stringToJsonWithErrorHandling(string2, errorMessage) {
|
|
39
|
+
try {
|
|
40
|
+
return JSON.parse(string2);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw new JsonParseError(errorMessage ?? "Unable to parse string to JSON.", string2);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function parseWithErrorHandling(schema, data, customErrorMessage) {
|
|
46
|
+
const parseResult = v.safeParse(schema, data);
|
|
47
|
+
if (!parseResult.success) {
|
|
48
|
+
throw new ValidationError(
|
|
49
|
+
customErrorMessage ?? `Error validating schema with data ${JSON.stringify(data)}`,
|
|
50
|
+
parseResult.issues
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return parseResult.output;
|
|
54
|
+
}
|
|
55
|
+
function valibotRecursiveFlattenIssues(issues) {
|
|
56
|
+
let flattened = v.flatten(issues);
|
|
57
|
+
for (const issue of issues) {
|
|
58
|
+
if (issue.issues) {
|
|
59
|
+
flattened = mergeDeep(flattened, valibotRecursiveFlattenIssues(issue.issues));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return flattened;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/error/ValidationError.ts
|
|
66
|
+
var ValidationError = class extends Error {
|
|
67
|
+
constructor(message, valibotIssues = []) {
|
|
68
|
+
const errorDetails = valibotIssues.length > 0 ? JSON.stringify(valibotRecursiveFlattenIssues(valibotIssues), null, 2) : "No details provided";
|
|
69
|
+
super(`${message}
|
|
70
|
+
${errorDetails}`);
|
|
71
|
+
this.valibotIssues = valibotIssues;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// src/error/InvalidFetchResponseError.ts
|
|
76
|
+
var InvalidFetchResponseError = class extends Error {
|
|
77
|
+
constructor(message, textResponse, response) {
|
|
78
|
+
super(`${message}
|
|
79
|
+
${textResponse}`);
|
|
80
|
+
this.textResponse = textResponse;
|
|
81
|
+
this.response = response.clone();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// src/date.ts
|
|
86
|
+
function dateToSeconds(date) {
|
|
87
|
+
const milliseconds = date?.getTime() ?? Date.now();
|
|
88
|
+
return Math.floor(milliseconds / 1e3);
|
|
89
|
+
}
|
|
90
|
+
function addSecondsToDate(date, seconds) {
|
|
91
|
+
return new Date(date.getTime() + seconds * 1e3);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// src/encoding.ts
|
|
95
|
+
import { Buffer } from "buffer";
|
|
96
|
+
function decodeUtf8String(string2) {
|
|
97
|
+
return new Uint8Array(Buffer.from(string2, "utf-8"));
|
|
98
|
+
}
|
|
99
|
+
function encodeToUtf8String(data) {
|
|
100
|
+
return Buffer.from(data).toString("utf-8");
|
|
101
|
+
}
|
|
102
|
+
function decodeBase64(base64) {
|
|
103
|
+
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
104
|
+
}
|
|
105
|
+
function encodeToBase64(data) {
|
|
106
|
+
if (typeof data === "string") {
|
|
107
|
+
return Buffer.from(data).toString("base64");
|
|
108
|
+
}
|
|
109
|
+
return Buffer.from(data).toString("base64");
|
|
110
|
+
}
|
|
111
|
+
function encodeToBase64Url(data) {
|
|
112
|
+
return base64ToBase64Url(encodeToBase64(data));
|
|
113
|
+
}
|
|
114
|
+
function base64ToBase64Url(base64) {
|
|
115
|
+
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/path.ts
|
|
119
|
+
function joinUriParts(base, parts) {
|
|
120
|
+
if (parts.length === 0) return base;
|
|
121
|
+
let combined = base.trim();
|
|
122
|
+
combined = base.endsWith("/") ? base.slice(0, base.length - 1) : base;
|
|
123
|
+
for (const part of parts) {
|
|
124
|
+
let strippedPart = part.trim();
|
|
125
|
+
strippedPart = strippedPart.startsWith("/") ? strippedPart.slice(1) : strippedPart;
|
|
126
|
+
strippedPart = strippedPart.endsWith("/") ? strippedPart.slice(0, strippedPart.length - 1) : strippedPart;
|
|
127
|
+
if (strippedPart === "") continue;
|
|
128
|
+
combined += `/${strippedPart}`;
|
|
129
|
+
}
|
|
130
|
+
return combined;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/url.ts
|
|
134
|
+
function getQueryParams(url2) {
|
|
135
|
+
const parsedUrl = new _URL(url2);
|
|
136
|
+
const searchParams = new _URLSearchParams(parsedUrl.search);
|
|
137
|
+
const params = {};
|
|
138
|
+
searchParams.forEach((value, key) => {
|
|
139
|
+
params[key] = value;
|
|
140
|
+
});
|
|
141
|
+
return params;
|
|
142
|
+
}
|
|
143
|
+
function objectToQueryParams(object) {
|
|
144
|
+
const params = new _URLSearchParams();
|
|
145
|
+
for (const [key, value] of Object.entries(object)) {
|
|
146
|
+
if (value != null) {
|
|
147
|
+
params.append(key, typeof value === "object" ? JSON.stringify(value) : String(value));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return params;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/valibot-fetcher.ts
|
|
154
|
+
import * as v2 from "valibot";
|
|
155
|
+
|
|
156
|
+
// src/content-type.ts
|
|
157
|
+
var ContentType = /* @__PURE__ */ ((ContentType2) => {
|
|
158
|
+
ContentType2["XWwwFormUrlencoded"] = "application/x-www-form-urlencoded";
|
|
159
|
+
ContentType2["Json"] = "application/json";
|
|
160
|
+
ContentType2["JwkSet"] = "application/jwk-set+json";
|
|
161
|
+
return ContentType2;
|
|
162
|
+
})(ContentType || {});
|
|
163
|
+
function isContentType(contentType, value) {
|
|
164
|
+
return value.toLowerCase().trim().split(";")[0] === contentType;
|
|
165
|
+
}
|
|
166
|
+
function isResponseContentType(contentType, response) {
|
|
167
|
+
const header = response.headers.get("Content-Type");
|
|
168
|
+
if (!header) return false;
|
|
169
|
+
return isContentType(contentType, header);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// src/valibot-fetcher.ts
|
|
173
|
+
var defaultFetcher = fetch;
|
|
174
|
+
function createValibotFetcher(fetcher = defaultFetcher) {
|
|
175
|
+
return async (schema, expectedContentType, ...args) => {
|
|
176
|
+
const response = await fetcher(...args);
|
|
177
|
+
if (response.ok && !isResponseContentType(expectedContentType, response)) {
|
|
178
|
+
throw new InvalidFetchResponseError(
|
|
179
|
+
`Expected response to match content type '${expectedContentType}', but received '${response.headers.get("Content-Type")}'`,
|
|
180
|
+
await response.clone().text(),
|
|
181
|
+
response
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
response,
|
|
186
|
+
result: response.ok ? v2.safeParse(schema, await response.json()) : void 0
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/validation.ts
|
|
192
|
+
import * as v3 from "valibot";
|
|
193
|
+
|
|
194
|
+
// src/config.ts
|
|
195
|
+
var GLOBAL_CONFIG = {
|
|
196
|
+
allowInsecureUrls: false
|
|
197
|
+
};
|
|
198
|
+
function setGlobalConfig(config) {
|
|
199
|
+
GLOBAL_CONFIG = config;
|
|
200
|
+
}
|
|
201
|
+
function getGlobalConfig() {
|
|
202
|
+
return GLOBAL_CONFIG;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// src/validation.ts
|
|
206
|
+
var vHttpsUrl = v3.pipe(
|
|
207
|
+
v3.string(),
|
|
208
|
+
v3.url(),
|
|
209
|
+
v3.check((url2) => {
|
|
210
|
+
const { allowInsecureUrls } = getGlobalConfig();
|
|
211
|
+
return allowInsecureUrls ? url2.startsWith("http://") || url2.startsWith("https://") : url2.startsWith("https://");
|
|
212
|
+
}, "url must be an https:// url")
|
|
213
|
+
);
|
|
214
|
+
var vInteger = v3.pipe(v3.number(), v3.integer());
|
|
215
|
+
var vHttpMethod = v3.picklist(["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "TRACE", "CONNECT", "PATCH"]);
|
|
216
|
+
|
|
217
|
+
// src/array.ts
|
|
218
|
+
function arrayEqualsIgnoreOrder(a, b) {
|
|
219
|
+
if (new Set(a).size !== new Set(b).size) return false;
|
|
220
|
+
if (a.length !== b.length) return false;
|
|
221
|
+
return a.every((k) => b.includes(k));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// src/www-authenticate.ts
|
|
225
|
+
var unquote = (value) => value.substring(1, value.length - 1).replace(/\\"/g, '"');
|
|
226
|
+
var sanitize = (value) => value.charAt(0) === '"' ? unquote(value) : value.trim();
|
|
227
|
+
var body = (
|
|
228
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: <explanation>
|
|
229
|
+
/((?:[a-zA-Z0-9._~+\/-]+=*(?:\s+|$))|[^\u0000-\u001F\u007F()<>@,;:\\"/?={}\[\]\u0020\u0009]+)(?:=([^\\"=\s,]+|"(?:[^"\\]|\\.)*"))?/g
|
|
230
|
+
);
|
|
231
|
+
var parsePayload = (scheme, string2) => {
|
|
232
|
+
const payload = {};
|
|
233
|
+
while (true) {
|
|
234
|
+
const res = body.exec(string2);
|
|
235
|
+
if (!res) break;
|
|
236
|
+
const [, key, newValue] = res;
|
|
237
|
+
const payloadValue = payload[key];
|
|
238
|
+
if (newValue) {
|
|
239
|
+
const sanitizedValue = sanitize(newValue);
|
|
240
|
+
payload[key] = payloadValue ? Array.isArray(payloadValue) ? [...payloadValue, sanitizedValue] : [payloadValue, sanitizedValue] : sanitizedValue;
|
|
241
|
+
} else if (!payloadValue) {
|
|
242
|
+
payload[key] = null;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return { scheme, payload };
|
|
246
|
+
};
|
|
247
|
+
function parseWwwAuthenticateHeader(str) {
|
|
248
|
+
const start = str.indexOf(" ");
|
|
249
|
+
let scheme = str.substring(0, start);
|
|
250
|
+
let value = str.substring(start);
|
|
251
|
+
const challenges = [];
|
|
252
|
+
const endsWithSchemeRegex = /, ?(Bearer|DPoP|Basic)$/;
|
|
253
|
+
const endsWithSchemeTest = endsWithSchemeRegex.exec(value);
|
|
254
|
+
let endsWithScheme = void 0;
|
|
255
|
+
if (endsWithSchemeTest) {
|
|
256
|
+
value = value.substring(0, value.length - endsWithSchemeTest[0].length);
|
|
257
|
+
endsWithScheme = endsWithSchemeTest[1];
|
|
258
|
+
}
|
|
259
|
+
const additionalSchemesRegex = /(.*?)(, ?)(Bearer|DPoP|Basic)[, ]/;
|
|
260
|
+
let match = additionalSchemesRegex.exec(value);
|
|
261
|
+
while (match) {
|
|
262
|
+
challenges.push(parsePayload(scheme, match[1]));
|
|
263
|
+
value = value.substring(match[0].length - 1);
|
|
264
|
+
scheme = match[3];
|
|
265
|
+
match = additionalSchemesRegex.exec(value);
|
|
266
|
+
}
|
|
267
|
+
challenges.push(parsePayload(scheme, value));
|
|
268
|
+
if (endsWithScheme) {
|
|
269
|
+
challenges.push({ scheme: endsWithScheme, payload: {} });
|
|
270
|
+
}
|
|
271
|
+
return challenges;
|
|
272
|
+
}
|
|
273
|
+
function encodeWwwAuthenticateHeader(challenges) {
|
|
274
|
+
const entries = [];
|
|
275
|
+
for (const challenge of challenges) {
|
|
276
|
+
const encodedParams = Object.entries(challenge.payload).flatMap(([key, value]) => {
|
|
277
|
+
const encode = (s) => s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
278
|
+
if (Array.isArray(value)) {
|
|
279
|
+
return value.map((v4) => `${key}="${encode(v4)}"`);
|
|
280
|
+
}
|
|
281
|
+
return value ? `${key}="${encode(value)}"` : key;
|
|
282
|
+
});
|
|
283
|
+
entries.push(encodedParams.length === 0 ? challenge.scheme : `${challenge.scheme} ${encodedParams.join(", ")}`);
|
|
284
|
+
}
|
|
285
|
+
return entries.join(", ");
|
|
286
|
+
}
|
|
287
|
+
export {
|
|
288
|
+
ContentType,
|
|
289
|
+
_Headers as Headers,
|
|
290
|
+
InvalidFetchResponseError,
|
|
291
|
+
JsonParseError,
|
|
292
|
+
_URL as URL,
|
|
293
|
+
_URLSearchParams as URLSearchParams,
|
|
294
|
+
ValidationError,
|
|
295
|
+
addSecondsToDate,
|
|
296
|
+
arrayEqualsIgnoreOrder,
|
|
297
|
+
createValibotFetcher,
|
|
298
|
+
dateToSeconds,
|
|
299
|
+
decodeBase64,
|
|
300
|
+
decodeUtf8String,
|
|
301
|
+
defaultFetcher,
|
|
302
|
+
encodeToBase64,
|
|
303
|
+
encodeToBase64Url,
|
|
304
|
+
encodeToUtf8String,
|
|
305
|
+
encodeWwwAuthenticateHeader,
|
|
306
|
+
getGlobalConfig,
|
|
307
|
+
getQueryParams,
|
|
308
|
+
isContentType,
|
|
309
|
+
isResponseContentType,
|
|
310
|
+
joinUriParts,
|
|
311
|
+
mergeDeep,
|
|
312
|
+
objectToQueryParams,
|
|
313
|
+
parseWithErrorHandling,
|
|
314
|
+
parseWwwAuthenticateHeader,
|
|
315
|
+
setGlobalConfig,
|
|
316
|
+
stringToJsonWithErrorHandling,
|
|
317
|
+
vHttpMethod,
|
|
318
|
+
vHttpsUrl,
|
|
319
|
+
vInteger,
|
|
320
|
+
valibotRecursiveFlattenIssues
|
|
321
|
+
};
|
|
322
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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"],"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;;;ACJA,YAAY,OAAO;;;ACAZ,SAAS,SAAS,MAAgD;AACvE,SAAO,QAAQ,QAAQ,OAAO,SAAS,YAAY,CAAC,MAA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20250109205223",
|
|
4
|
+
"exports": {
|
|
5
|
+
".": {
|
|
6
|
+
"import": "./dist/index.mjs",
|
|
7
|
+
"require": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts"
|
|
9
|
+
},
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"homepage": "https://github.com/openwallet-foundation-labs/oid4vc-ts/tree/main/packages/utils",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/openwallet-foundation-labs/oid4vc-ts",
|
|
20
|
+
"directory": "packages/utils"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"buffer": "^6.0.3",
|
|
24
|
+
"valibot": "^0.42.1"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean --sourcemap"
|
|
28
|
+
},
|
|
29
|
+
"main": "./dist/index.js",
|
|
30
|
+
"module": "./dist/index.mjs",
|
|
31
|
+
"types": "./dist/index.d.ts"
|
|
32
|
+
}
|