@pagopa/io-wallet-utils 0.7.7 → 1.0.0-20260210102725
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 +89 -2
- package/dist/index.d.ts +89 -2
- package/dist/index.js +57 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,61 @@
|
|
|
1
|
-
|
|
1
|
+
import { HttpMethod } from '@openid4vc/utils';
|
|
2
|
+
export { ContentType, Fetch, JsonParseError, ValidationError, addSecondsToDate, createFetcher, dateToSeconds, decodeUtf8String, encodeToBase64Url, formatZodError, parseWithErrorHandling, zHttpsUrl } from '@openid4vc/utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Supported versions of the Italian Wallet technical specifications
|
|
6
|
+
*/
|
|
7
|
+
declare enum ItWalletSpecsVersion {
|
|
8
|
+
V1_0 = "V1_0",
|
|
9
|
+
V1_3 = "V1_3"
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Configuration options for the IO Wallet SDK
|
|
13
|
+
*/
|
|
14
|
+
interface IoWalletSdkConfigOptions {
|
|
15
|
+
/**
|
|
16
|
+
* The version of the Italian Wallet specification to use.
|
|
17
|
+
* REQUIRED - must be explicitly set by the user.
|
|
18
|
+
*
|
|
19
|
+
* Version differences:
|
|
20
|
+
* - V1_0: Uses singular `proof` object with explicit `proof_type` field
|
|
21
|
+
* - V1_3: Uses plural `proofs` object with JWT array and requires key attestation
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_3 });
|
|
25
|
+
*/
|
|
26
|
+
itWalletSpecsVersion: ItWalletSpecsVersion;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Configuration class for the IO Wallet SDK
|
|
30
|
+
*
|
|
31
|
+
* This class manages the version of the Italian Wallet technical specifications
|
|
32
|
+
* to use throughout the SDK. The version determines the format of credential
|
|
33
|
+
* requests and responses.
|
|
34
|
+
*
|
|
35
|
+
* @example Basic usage
|
|
36
|
+
* const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_0 });
|
|
37
|
+
* console.log(config.itWalletSpecsVersion); // ItWalletSpecsVersion.V1_0
|
|
38
|
+
*
|
|
39
|
+
* @example Type guard usage
|
|
40
|
+
* if (config.isVersion(ItWalletSpecsVersion.V1_3)) {
|
|
41
|
+
* // TypeScript narrows config.itWalletSpecsVersion to ItWalletSpecsVersion.V1_3
|
|
42
|
+
* }
|
|
43
|
+
*/
|
|
44
|
+
declare class IoWalletSdkConfig {
|
|
45
|
+
readonly itWalletSpecsVersion: ItWalletSpecsVersion;
|
|
46
|
+
constructor(options: IoWalletSdkConfigOptions);
|
|
47
|
+
/**
|
|
48
|
+
* Type guard for version checking
|
|
49
|
+
*
|
|
50
|
+
* @param version - The version to check against
|
|
51
|
+
* @returns True if the config's version matches the provided version
|
|
52
|
+
*
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
isVersion<V extends ItWalletSpecsVersion>(version: V): this is {
|
|
56
|
+
itWalletSpecsVersion: V;
|
|
57
|
+
} & IoWalletSdkConfig;
|
|
58
|
+
}
|
|
2
59
|
|
|
3
60
|
/**
|
|
4
61
|
* HTTP Content-Type constants for OAuth2 requests
|
|
@@ -43,6 +100,29 @@ declare class UnexpectedStatusCodeError extends Error {
|
|
|
43
100
|
statusCode: number;
|
|
44
101
|
});
|
|
45
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* An error subclass thrown when an unsupported Italian Wallet specification version is requested.
|
|
105
|
+
*
|
|
106
|
+
* This error is thrown when:
|
|
107
|
+
* - A feature or method is called with a version that it doesn't support
|
|
108
|
+
* - An invalid version identifier is provided
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* throw new ItWalletSpecsVersionError(
|
|
112
|
+
* 'createCredentialRequest',
|
|
113
|
+
* '2.0.0',
|
|
114
|
+
* [ItWalletSpecsVersion.V1_0, ItWalletSpecsVersion.V1_3]
|
|
115
|
+
* );
|
|
116
|
+
* // Error: Feature "createCredentialRequest" does not support version 2.0.0.
|
|
117
|
+
* // Supported versions: V1_0, V1_3
|
|
118
|
+
*/
|
|
119
|
+
declare class ItWalletSpecsVersionError extends Error {
|
|
120
|
+
readonly feature: string;
|
|
121
|
+
readonly requestedVersion: string;
|
|
122
|
+
readonly supportedVersions: readonly string[];
|
|
123
|
+
readonly code = "IT_WALLET_SPECS_VERSION_ERROR";
|
|
124
|
+
constructor(feature: string, requestedVersion: string, supportedVersions: readonly string[]);
|
|
125
|
+
}
|
|
46
126
|
|
|
47
127
|
/**
|
|
48
128
|
* Check if a response is in the expected status, otherwise throw an error
|
|
@@ -57,4 +137,11 @@ declare const hasStatusOrThrow: (status: number, customError?: typeof Unexpected
|
|
|
57
137
|
*/
|
|
58
138
|
declare const parseRawHttpResponse: <T extends Record<string, unknown>>(response: Response) => Promise<T> | Promise<string>;
|
|
59
139
|
|
|
60
|
-
|
|
140
|
+
type FetchHeaders = globalThis.Headers;
|
|
141
|
+
interface RequestLike {
|
|
142
|
+
headers: FetchHeaders;
|
|
143
|
+
method: HttpMethod;
|
|
144
|
+
url: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export { CONTENT_TYPES, type FetchHeaders, HEADERS, IoWalletSdkConfig, type IoWalletSdkConfigOptions, ItWalletSpecsVersion, ItWalletSpecsVersionError, type RequestLike, UnexpectedStatusCodeError, hasStatusOrThrow, parseRawHttpResponse, serializeAttrs };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,61 @@
|
|
|
1
|
-
|
|
1
|
+
import { HttpMethod } from '@openid4vc/utils';
|
|
2
|
+
export { ContentType, Fetch, JsonParseError, ValidationError, addSecondsToDate, createFetcher, dateToSeconds, decodeUtf8String, encodeToBase64Url, formatZodError, parseWithErrorHandling, zHttpsUrl } from '@openid4vc/utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Supported versions of the Italian Wallet technical specifications
|
|
6
|
+
*/
|
|
7
|
+
declare enum ItWalletSpecsVersion {
|
|
8
|
+
V1_0 = "V1_0",
|
|
9
|
+
V1_3 = "V1_3"
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Configuration options for the IO Wallet SDK
|
|
13
|
+
*/
|
|
14
|
+
interface IoWalletSdkConfigOptions {
|
|
15
|
+
/**
|
|
16
|
+
* The version of the Italian Wallet specification to use.
|
|
17
|
+
* REQUIRED - must be explicitly set by the user.
|
|
18
|
+
*
|
|
19
|
+
* Version differences:
|
|
20
|
+
* - V1_0: Uses singular `proof` object with explicit `proof_type` field
|
|
21
|
+
* - V1_3: Uses plural `proofs` object with JWT array and requires key attestation
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_3 });
|
|
25
|
+
*/
|
|
26
|
+
itWalletSpecsVersion: ItWalletSpecsVersion;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Configuration class for the IO Wallet SDK
|
|
30
|
+
*
|
|
31
|
+
* This class manages the version of the Italian Wallet technical specifications
|
|
32
|
+
* to use throughout the SDK. The version determines the format of credential
|
|
33
|
+
* requests and responses.
|
|
34
|
+
*
|
|
35
|
+
* @example Basic usage
|
|
36
|
+
* const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_0 });
|
|
37
|
+
* console.log(config.itWalletSpecsVersion); // ItWalletSpecsVersion.V1_0
|
|
38
|
+
*
|
|
39
|
+
* @example Type guard usage
|
|
40
|
+
* if (config.isVersion(ItWalletSpecsVersion.V1_3)) {
|
|
41
|
+
* // TypeScript narrows config.itWalletSpecsVersion to ItWalletSpecsVersion.V1_3
|
|
42
|
+
* }
|
|
43
|
+
*/
|
|
44
|
+
declare class IoWalletSdkConfig {
|
|
45
|
+
readonly itWalletSpecsVersion: ItWalletSpecsVersion;
|
|
46
|
+
constructor(options: IoWalletSdkConfigOptions);
|
|
47
|
+
/**
|
|
48
|
+
* Type guard for version checking
|
|
49
|
+
*
|
|
50
|
+
* @param version - The version to check against
|
|
51
|
+
* @returns True if the config's version matches the provided version
|
|
52
|
+
*
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
isVersion<V extends ItWalletSpecsVersion>(version: V): this is {
|
|
56
|
+
itWalletSpecsVersion: V;
|
|
57
|
+
} & IoWalletSdkConfig;
|
|
58
|
+
}
|
|
2
59
|
|
|
3
60
|
/**
|
|
4
61
|
* HTTP Content-Type constants for OAuth2 requests
|
|
@@ -43,6 +100,29 @@ declare class UnexpectedStatusCodeError extends Error {
|
|
|
43
100
|
statusCode: number;
|
|
44
101
|
});
|
|
45
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* An error subclass thrown when an unsupported Italian Wallet specification version is requested.
|
|
105
|
+
*
|
|
106
|
+
* This error is thrown when:
|
|
107
|
+
* - A feature or method is called with a version that it doesn't support
|
|
108
|
+
* - An invalid version identifier is provided
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* throw new ItWalletSpecsVersionError(
|
|
112
|
+
* 'createCredentialRequest',
|
|
113
|
+
* '2.0.0',
|
|
114
|
+
* [ItWalletSpecsVersion.V1_0, ItWalletSpecsVersion.V1_3]
|
|
115
|
+
* );
|
|
116
|
+
* // Error: Feature "createCredentialRequest" does not support version 2.0.0.
|
|
117
|
+
* // Supported versions: V1_0, V1_3
|
|
118
|
+
*/
|
|
119
|
+
declare class ItWalletSpecsVersionError extends Error {
|
|
120
|
+
readonly feature: string;
|
|
121
|
+
readonly requestedVersion: string;
|
|
122
|
+
readonly supportedVersions: readonly string[];
|
|
123
|
+
readonly code = "IT_WALLET_SPECS_VERSION_ERROR";
|
|
124
|
+
constructor(feature: string, requestedVersion: string, supportedVersions: readonly string[]);
|
|
125
|
+
}
|
|
46
126
|
|
|
47
127
|
/**
|
|
48
128
|
* Check if a response is in the expected status, otherwise throw an error
|
|
@@ -57,4 +137,11 @@ declare const hasStatusOrThrow: (status: number, customError?: typeof Unexpected
|
|
|
57
137
|
*/
|
|
58
138
|
declare const parseRawHttpResponse: <T extends Record<string, unknown>>(response: Response) => Promise<T> | Promise<string>;
|
|
59
139
|
|
|
60
|
-
|
|
140
|
+
type FetchHeaders = globalThis.Headers;
|
|
141
|
+
interface RequestLike {
|
|
142
|
+
headers: FetchHeaders;
|
|
143
|
+
method: HttpMethod;
|
|
144
|
+
url: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export { CONTENT_TYPES, type FetchHeaders, HEADERS, IoWalletSdkConfig, type IoWalletSdkConfigOptions, ItWalletSpecsVersion, ItWalletSpecsVersionError, type RequestLike, UnexpectedStatusCodeError, hasStatusOrThrow, parseRawHttpResponse, serializeAttrs };
|
package/dist/index.js
CHANGED
|
@@ -21,21 +21,52 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
CONTENT_TYPES: () => CONTENT_TYPES,
|
|
24
|
+
ContentType: () => import_utils.ContentType,
|
|
24
25
|
HEADERS: () => HEADERS,
|
|
26
|
+
IoWalletSdkConfig: () => IoWalletSdkConfig,
|
|
27
|
+
ItWalletSpecsVersion: () => ItWalletSpecsVersion,
|
|
28
|
+
ItWalletSpecsVersionError: () => ItWalletSpecsVersionError,
|
|
25
29
|
JsonParseError: () => import_utils.JsonParseError,
|
|
26
30
|
UnexpectedStatusCodeError: () => UnexpectedStatusCodeError,
|
|
27
31
|
ValidationError: () => import_utils.ValidationError,
|
|
28
32
|
addSecondsToDate: () => import_utils.addSecondsToDate,
|
|
33
|
+
createFetcher: () => import_utils.createFetcher,
|
|
29
34
|
dateToSeconds: () => import_utils.dateToSeconds,
|
|
30
35
|
decodeUtf8String: () => import_utils.decodeUtf8String,
|
|
31
36
|
encodeToBase64Url: () => import_utils.encodeToBase64Url,
|
|
37
|
+
formatZodError: () => import_utils.formatZodError,
|
|
32
38
|
hasStatusOrThrow: () => hasStatusOrThrow,
|
|
33
39
|
parseRawHttpResponse: () => parseRawHttpResponse,
|
|
34
40
|
parseWithErrorHandling: () => import_utils.parseWithErrorHandling,
|
|
35
|
-
serializeAttrs: () => serializeAttrs
|
|
41
|
+
serializeAttrs: () => serializeAttrs,
|
|
42
|
+
zHttpsUrl: () => import_utils.zHttpsUrl
|
|
36
43
|
});
|
|
37
44
|
module.exports = __toCommonJS(index_exports);
|
|
38
45
|
|
|
46
|
+
// src/config.ts
|
|
47
|
+
var ItWalletSpecsVersion = /* @__PURE__ */ ((ItWalletSpecsVersion2) => {
|
|
48
|
+
ItWalletSpecsVersion2["V1_0"] = "V1_0";
|
|
49
|
+
ItWalletSpecsVersion2["V1_3"] = "V1_3";
|
|
50
|
+
return ItWalletSpecsVersion2;
|
|
51
|
+
})(ItWalletSpecsVersion || {});
|
|
52
|
+
var IoWalletSdkConfig = class {
|
|
53
|
+
itWalletSpecsVersion;
|
|
54
|
+
constructor(options) {
|
|
55
|
+
this.itWalletSpecsVersion = options.itWalletSpecsVersion;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Type guard for version checking
|
|
59
|
+
*
|
|
60
|
+
* @param version - The version to check against
|
|
61
|
+
* @returns True if the config's version matches the provided version
|
|
62
|
+
*
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
isVersion(version) {
|
|
66
|
+
return this.itWalletSpecsVersion === version;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
39
70
|
// src/constants.ts
|
|
40
71
|
var CONTENT_TYPES = {
|
|
41
72
|
FORM_URLENCODED: "application/x-www-form-urlencoded",
|
|
@@ -69,6 +100,23 @@ var UnexpectedStatusCodeError = class extends Error {
|
|
|
69
100
|
this.statusCode = statusCode;
|
|
70
101
|
}
|
|
71
102
|
};
|
|
103
|
+
var ItWalletSpecsVersionError = class _ItWalletSpecsVersionError extends Error {
|
|
104
|
+
constructor(feature, requestedVersion, supportedVersions) {
|
|
105
|
+
super(
|
|
106
|
+
`Feature "${feature}" does not support version ${requestedVersion}.
|
|
107
|
+
Supported versions: ${supportedVersions.join(", ")}`
|
|
108
|
+
);
|
|
109
|
+
this.feature = feature;
|
|
110
|
+
this.requestedVersion = requestedVersion;
|
|
111
|
+
this.supportedVersions = supportedVersions;
|
|
112
|
+
this.name = "ItWalletSpecsVersionError";
|
|
113
|
+
const ErrorConstructor = Error;
|
|
114
|
+
if (typeof ErrorConstructor.captureStackTrace === "function") {
|
|
115
|
+
ErrorConstructor.captureStackTrace(this, _ItWalletSpecsVersionError);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
code = "IT_WALLET_SPECS_VERSION_ERROR";
|
|
119
|
+
};
|
|
72
120
|
|
|
73
121
|
// src/fetcher.ts
|
|
74
122
|
var hasStatusOrThrow = (status, customError) => async (res) => {
|
|
@@ -90,17 +138,24 @@ var import_utils = require("@openid4vc/utils");
|
|
|
90
138
|
// Annotate the CommonJS export names for ESM import in node:
|
|
91
139
|
0 && (module.exports = {
|
|
92
140
|
CONTENT_TYPES,
|
|
141
|
+
ContentType,
|
|
93
142
|
HEADERS,
|
|
143
|
+
IoWalletSdkConfig,
|
|
144
|
+
ItWalletSpecsVersion,
|
|
145
|
+
ItWalletSpecsVersionError,
|
|
94
146
|
JsonParseError,
|
|
95
147
|
UnexpectedStatusCodeError,
|
|
96
148
|
ValidationError,
|
|
97
149
|
addSecondsToDate,
|
|
150
|
+
createFetcher,
|
|
98
151
|
dateToSeconds,
|
|
99
152
|
decodeUtf8String,
|
|
100
153
|
encodeToBase64Url,
|
|
154
|
+
formatZodError,
|
|
101
155
|
hasStatusOrThrow,
|
|
102
156
|
parseRawHttpResponse,
|
|
103
157
|
parseWithErrorHandling,
|
|
104
|
-
serializeAttrs
|
|
158
|
+
serializeAttrs,
|
|
159
|
+
zHttpsUrl
|
|
105
160
|
});
|
|
106
161
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/constants.ts","../src/errors.ts","../src/fetcher.ts"],"sourcesContent":["export * from \"./constants\";\nexport * from \"./errors\";\nexport * from \"./fetcher\";\n\nexport {\n type Fetch,\n JsonParseError,\n ValidationError,\n addSecondsToDate,\n dateToSeconds,\n decodeUtf8String,\n encodeToBase64Url,\n parseWithErrorHandling,\n} from \"@openid4vc/utils\";\n","/**\n * HTTP Content-Type constants for OAuth2 requests\n */\nexport const CONTENT_TYPES = {\n FORM_URLENCODED: \"application/x-www-form-urlencoded\",\n JSON: \"application/json\",\n} as const;\n\n/**\n * HTTP Header constants\n */\nexport const HEADERS = {\n AUTHORIZATION: \"Authorization\",\n CONTENT_TYPE: \"Content-Type\",\n DPOP: \"DPoP\",\n OAUTH_CLIENT_ATTESTATION: \"OAuth-Client-Attestation\",\n OAUTH_CLIENT_ATTESTATION_POP: \"OAuth-Client-Attestation-PoP\",\n} as const;\n","// An error reason that supports both a string and a generic JSON object\ntype GenericErrorReason = Record<string, unknown> | string;\n\n/**\n * utility to format a set of attributes into an error message string\n *\n * @example\n * // returns \"foo=value bar=(list, item)\"\n * serializeAttrs({ foo: \"value\", bar: [\"list\", \"item\"] })\n *\n * @param attrs A key value record set\n * @returns a human-readable serialization of the set\n */\nexport const serializeAttrs = (\n attrs: Record<string, GenericErrorReason | number | string[] | undefined>,\n): string =>\n Object.entries(attrs)\n .filter(([, v]) => v !== undefined)\n .map(([k, v]) => {\n if (Array.isArray(v)) return [k, `(${v.join(\", \")})`];\n if (typeof v !== \"string\") return [k, JSON.stringify(v)];\n return [k, v];\n })\n .map((_) => _.join(\"=\"))\n .join(\" \");\n\n/**\n * An error subclass thrown when an HTTP request has a status code different from the one expected.\n */\nexport class UnexpectedStatusCodeError extends Error {\n code = \"ERR_UNEXPECTED_STATUS_CODE\";\n reason: GenericErrorReason;\n statusCode: number;\n\n constructor({\n message,\n reason,\n statusCode,\n }: {\n message: string;\n reason: GenericErrorReason;\n statusCode: number;\n }) {\n super(serializeAttrs({ message, reason, statusCode }));\n this.reason = reason;\n this.statusCode = statusCode;\n }\n}\n","import { UnexpectedStatusCodeError } from \"./errors\";\n\n/**\n * Check if a response is in the expected status, otherwise throw an error\n * @param status - The expected status\n * @param customError - A custom error compatible with {@link UnexpectedStatusCodeError}\n * @throws UnexpectedStatusCodeError if the status is different from the one expected\n * @returns The given response object\n */\nexport const hasStatusOrThrow =\n (status: number, customError?: typeof UnexpectedStatusCodeError) =>\n async (res: Response): Promise<Response> => {\n if (res.status !== status) {\n const ErrorClass = customError ?? UnexpectedStatusCodeError;\n throw new ErrorClass({\n message: `Http request failed. Expected ${status}, got ${res.status}, url: ${res.url}`,\n reason: await parseRawHttpResponse(res), // Pass the response body as reason so the original error can surface\n statusCode: res.status,\n });\n }\n return res;\n };\n\n/**\n * Utility function to parse a raw HTTP response as JSON if supported, otherwise as text.\n */\nexport const parseRawHttpResponse = <T extends Record<string, unknown>>(\n response: Response,\n) =>\n response.headers.get(\"content-type\")?.includes(\"application/json\")\n ? (response.json() as Promise<T>)\n : response.text();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,gBAAgB;AAAA,EAC3B,iBAAiB;AAAA,EACjB,MAAM;AACR;AAKO,IAAM,UAAU;AAAA,EACrB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,MAAM;AAAA,EACN,0BAA0B;AAAA,EAC1B,8BAA8B;AAChC;;;ACJO,IAAM,iBAAiB,CAC5B,UAEA,OAAO,QAAQ,KAAK,EACjB,OAAO,CAAC,CAAC,EAAE,CAAC,MAAM,MAAM,MAAS,EACjC,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM;AACf,MAAI,MAAM,QAAQ,CAAC,EAAG,QAAO,CAAC,GAAG,IAAI,EAAE,KAAK,IAAI,CAAC,GAAG;AACpD,MAAI,OAAO,MAAM,SAAU,QAAO,CAAC,GAAG,KAAK,UAAU,CAAC,CAAC;AACvD,SAAO,CAAC,GAAG,CAAC;AACd,CAAC,EACA,IAAI,CAAC,MAAM,EAAE,KAAK,GAAG,CAAC,EACtB,KAAK,GAAG;AAKN,IAAM,4BAAN,cAAwC,MAAM;AAAA,EACnD,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EAEA,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAIG;AACD,UAAM,eAAe,EAAE,SAAS,QAAQ,WAAW,CAAC,CAAC;AACrD,SAAK,SAAS;AACd,SAAK,aAAa;AAAA,EACpB;AACF;;;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/config.ts","../src/constants.ts","../src/errors.ts","../src/fetcher.ts"],"sourcesContent":["export * from \"./config\";\nexport * from \"./constants\";\nexport * from \"./errors\";\nexport * from \"./fetcher\";\nexport type * from \"./globals\";\n\nexport {\n ContentType,\n type Fetch,\n JsonParseError,\n ValidationError,\n addSecondsToDate,\n createFetcher,\n dateToSeconds,\n decodeUtf8String,\n encodeToBase64Url,\n formatZodError,\n parseWithErrorHandling,\n zHttpsUrl,\n} from \"@openid4vc/utils\";\n","/**\n * Supported versions of the Italian Wallet technical specifications\n */\nexport enum ItWalletSpecsVersion {\n V1_0 = \"V1_0\",\n V1_3 = \"V1_3\",\n}\n\n/**\n * Configuration options for the IO Wallet SDK\n */\nexport interface IoWalletSdkConfigOptions {\n /**\n * The version of the Italian Wallet specification to use.\n * REQUIRED - must be explicitly set by the user.\n *\n * Version differences:\n * - V1_0: Uses singular `proof` object with explicit `proof_type` field\n * - V1_3: Uses plural `proofs` object with JWT array and requires key attestation\n *\n * @example\n * const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_3 });\n */\n itWalletSpecsVersion: ItWalletSpecsVersion;\n}\n\n/**\n * Configuration class for the IO Wallet SDK\n *\n * This class manages the version of the Italian Wallet technical specifications\n * to use throughout the SDK. The version determines the format of credential\n * requests and responses.\n *\n * @example Basic usage\n * const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_0 });\n * console.log(config.itWalletSpecsVersion); // ItWalletSpecsVersion.V1_0\n *\n * @example Type guard usage\n * if (config.isVersion(ItWalletSpecsVersion.V1_3)) {\n * // TypeScript narrows config.itWalletSpecsVersion to ItWalletSpecsVersion.V1_3\n * }\n */\nexport class IoWalletSdkConfig {\n public readonly itWalletSpecsVersion: ItWalletSpecsVersion;\n\n constructor(options: IoWalletSdkConfigOptions) {\n this.itWalletSpecsVersion = options.itWalletSpecsVersion;\n }\n\n /**\n * Type guard for version checking\n *\n * @param version - The version to check against\n * @returns True if the config's version matches the provided version\n *\n * @internal\n */\n isVersion<V extends ItWalletSpecsVersion>(\n version: V,\n ): this is { itWalletSpecsVersion: V } & IoWalletSdkConfig {\n return this.itWalletSpecsVersion === version;\n }\n}\n","/**\n * HTTP Content-Type constants for OAuth2 requests\n */\nexport const CONTENT_TYPES = {\n FORM_URLENCODED: \"application/x-www-form-urlencoded\",\n JSON: \"application/json\",\n} as const;\n\n/**\n * HTTP Header constants\n */\nexport const HEADERS = {\n AUTHORIZATION: \"Authorization\",\n CONTENT_TYPE: \"Content-Type\",\n DPOP: \"DPoP\",\n OAUTH_CLIENT_ATTESTATION: \"OAuth-Client-Attestation\",\n OAUTH_CLIENT_ATTESTATION_POP: \"OAuth-Client-Attestation-PoP\",\n} as const;\n","// An error reason that supports both a string and a generic JSON object\ntype GenericErrorReason = Record<string, unknown> | string;\n\n/**\n * utility to format a set of attributes into an error message string\n *\n * @example\n * // returns \"foo=value bar=(list, item)\"\n * serializeAttrs({ foo: \"value\", bar: [\"list\", \"item\"] })\n *\n * @param attrs A key value record set\n * @returns a human-readable serialization of the set\n */\nexport const serializeAttrs = (\n attrs: Record<string, GenericErrorReason | number | string[] | undefined>,\n): string =>\n Object.entries(attrs)\n .filter(([, v]) => v !== undefined)\n .map(([k, v]) => {\n if (Array.isArray(v)) return [k, `(${v.join(\", \")})`];\n if (typeof v !== \"string\") return [k, JSON.stringify(v)];\n return [k, v];\n })\n .map((_) => _.join(\"=\"))\n .join(\" \");\n\n/**\n * An error subclass thrown when an HTTP request has a status code different from the one expected.\n */\nexport class UnexpectedStatusCodeError extends Error {\n code = \"ERR_UNEXPECTED_STATUS_CODE\";\n reason: GenericErrorReason;\n statusCode: number;\n\n constructor({\n message,\n reason,\n statusCode,\n }: {\n message: string;\n reason: GenericErrorReason;\n statusCode: number;\n }) {\n super(serializeAttrs({ message, reason, statusCode }));\n this.reason = reason;\n this.statusCode = statusCode;\n }\n}\n\n/**\n * An error subclass thrown when an unsupported Italian Wallet specification version is requested.\n *\n * This error is thrown when:\n * - A feature or method is called with a version that it doesn't support\n * - An invalid version identifier is provided\n *\n * @example\n * throw new ItWalletSpecsVersionError(\n * 'createCredentialRequest',\n * '2.0.0',\n * [ItWalletSpecsVersion.V1_0, ItWalletSpecsVersion.V1_3]\n * );\n * // Error: Feature \"createCredentialRequest\" does not support version 2.0.0.\n * // Supported versions: V1_0, V1_3\n */\nexport class ItWalletSpecsVersionError extends Error {\n public readonly code = \"IT_WALLET_SPECS_VERSION_ERROR\";\n\n constructor(\n public readonly feature: string,\n public readonly requestedVersion: string,\n public readonly supportedVersions: readonly string[],\n ) {\n super(\n `Feature \"${feature}\" does not support version ${requestedVersion}.\\n` +\n `Supported versions: ${supportedVersions.join(\", \")}`,\n );\n this.name = \"ItWalletSpecsVersionError\";\n\n // Maintain proper stack trace for V8 engines (Node.js, Chrome)\n const ErrorConstructor = Error as {\n captureStackTrace?: (target: object, constructor: unknown) => void;\n };\n if (typeof ErrorConstructor.captureStackTrace === \"function\") {\n ErrorConstructor.captureStackTrace(this, ItWalletSpecsVersionError);\n }\n }\n}\n","import { UnexpectedStatusCodeError } from \"./errors\";\n\n/**\n * Check if a response is in the expected status, otherwise throw an error\n * @param status - The expected status\n * @param customError - A custom error compatible with {@link UnexpectedStatusCodeError}\n * @throws UnexpectedStatusCodeError if the status is different from the one expected\n * @returns The given response object\n */\nexport const hasStatusOrThrow =\n (status: number, customError?: typeof UnexpectedStatusCodeError) =>\n async (res: Response): Promise<Response> => {\n if (res.status !== status) {\n const ErrorClass = customError ?? UnexpectedStatusCodeError;\n throw new ErrorClass({\n message: `Http request failed. Expected ${status}, got ${res.status}, url: ${res.url}`,\n reason: await parseRawHttpResponse(res), // Pass the response body as reason so the original error can surface\n statusCode: res.status,\n });\n }\n return res;\n };\n\n/**\n * Utility function to parse a raw HTTP response as JSON if supported, otherwise as text.\n */\nexport const parseRawHttpResponse = <T extends Record<string, unknown>>(\n response: Response,\n) =>\n response.headers.get(\"content-type\")?.includes(\"application/json\")\n ? (response.json() as Promise<T>)\n : response.text();\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;;;ACGO,IAAK,uBAAL,kBAAKA,0BAAL;AACL,EAAAA,sBAAA,UAAO;AACP,EAAAA,sBAAA,UAAO;AAFG,SAAAA;AAAA,GAAA;AAuCL,IAAM,oBAAN,MAAwB;AAAA,EACb;AAAA,EAEhB,YAAY,SAAmC;AAC7C,SAAK,uBAAuB,QAAQ;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,UACE,SACyD;AACzD,WAAO,KAAK,yBAAyB;AAAA,EACvC;AACF;;;AC3DO,IAAM,gBAAgB;AAAA,EAC3B,iBAAiB;AAAA,EACjB,MAAM;AACR;AAKO,IAAM,UAAU;AAAA,EACrB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,MAAM;AAAA,EACN,0BAA0B;AAAA,EAC1B,8BAA8B;AAChC;;;ACJO,IAAM,iBAAiB,CAC5B,UAEA,OAAO,QAAQ,KAAK,EACjB,OAAO,CAAC,CAAC,EAAE,CAAC,MAAM,MAAM,MAAS,EACjC,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM;AACf,MAAI,MAAM,QAAQ,CAAC,EAAG,QAAO,CAAC,GAAG,IAAI,EAAE,KAAK,IAAI,CAAC,GAAG;AACpD,MAAI,OAAO,MAAM,SAAU,QAAO,CAAC,GAAG,KAAK,UAAU,CAAC,CAAC;AACvD,SAAO,CAAC,GAAG,CAAC;AACd,CAAC,EACA,IAAI,CAAC,MAAM,EAAE,KAAK,GAAG,CAAC,EACtB,KAAK,GAAG;AAKN,IAAM,4BAAN,cAAwC,MAAM;AAAA,EACnD,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EAEA,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAIG;AACD,UAAM,eAAe,EAAE,SAAS,QAAQ,WAAW,CAAC,CAAC;AACrD,SAAK,SAAS;AACd,SAAK,aAAa;AAAA,EACpB;AACF;AAkBO,IAAM,4BAAN,MAAM,mCAAkC,MAAM;AAAA,EAGnD,YACkB,SACA,kBACA,mBAChB;AACA;AAAA,MACE,YAAY,OAAO,8BAA8B,gBAAgB;AAAA,sBACxC,kBAAkB,KAAK,IAAI,CAAC;AAAA,IACvD;AAPgB;AACA;AACA;AAMhB,SAAK,OAAO;AAGZ,UAAM,mBAAmB;AAGzB,QAAI,OAAO,iBAAiB,sBAAsB,YAAY;AAC5D,uBAAiB,kBAAkB,MAAM,0BAAyB;AAAA,IACpE;AAAA,EACF;AAAA,EApBgB,OAAO;AAqBzB;;;AC9EO,IAAM,mBACX,CAAC,QAAgB,gBACjB,OAAO,QAAqC;AAC1C,MAAI,IAAI,WAAW,QAAQ;AACzB,UAAM,aAAa,eAAe;AAClC,UAAM,IAAI,WAAW;AAAA,MACnB,SAAS,iCAAiC,MAAM,SAAS,IAAI,MAAM,UAAU,IAAI,GAAG;AAAA,MACpF,QAAQ,MAAM,qBAAqB,GAAG;AAAA;AAAA,MACtC,YAAY,IAAI;AAAA,IAClB,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAKK,IAAM,uBAAuB,CAClC,aAEA,SAAS,QAAQ,IAAI,cAAc,GAAG,SAAS,kBAAkB,IAC5D,SAAS,KAAK,IACf,SAAS,KAAK;;;AJzBpB,mBAaO;","names":["ItWalletSpecsVersion"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
// src/config.ts
|
|
2
|
+
var ItWalletSpecsVersion = /* @__PURE__ */ ((ItWalletSpecsVersion2) => {
|
|
3
|
+
ItWalletSpecsVersion2["V1_0"] = "V1_0";
|
|
4
|
+
ItWalletSpecsVersion2["V1_3"] = "V1_3";
|
|
5
|
+
return ItWalletSpecsVersion2;
|
|
6
|
+
})(ItWalletSpecsVersion || {});
|
|
7
|
+
var IoWalletSdkConfig = class {
|
|
8
|
+
itWalletSpecsVersion;
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.itWalletSpecsVersion = options.itWalletSpecsVersion;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Type guard for version checking
|
|
14
|
+
*
|
|
15
|
+
* @param version - The version to check against
|
|
16
|
+
* @returns True if the config's version matches the provided version
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
isVersion(version) {
|
|
21
|
+
return this.itWalletSpecsVersion === version;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
1
25
|
// src/constants.ts
|
|
2
26
|
var CONTENT_TYPES = {
|
|
3
27
|
FORM_URLENCODED: "application/x-www-form-urlencoded",
|
|
@@ -31,6 +55,23 @@ var UnexpectedStatusCodeError = class extends Error {
|
|
|
31
55
|
this.statusCode = statusCode;
|
|
32
56
|
}
|
|
33
57
|
};
|
|
58
|
+
var ItWalletSpecsVersionError = class _ItWalletSpecsVersionError extends Error {
|
|
59
|
+
constructor(feature, requestedVersion, supportedVersions) {
|
|
60
|
+
super(
|
|
61
|
+
`Feature "${feature}" does not support version ${requestedVersion}.
|
|
62
|
+
Supported versions: ${supportedVersions.join(", ")}`
|
|
63
|
+
);
|
|
64
|
+
this.feature = feature;
|
|
65
|
+
this.requestedVersion = requestedVersion;
|
|
66
|
+
this.supportedVersions = supportedVersions;
|
|
67
|
+
this.name = "ItWalletSpecsVersionError";
|
|
68
|
+
const ErrorConstructor = Error;
|
|
69
|
+
if (typeof ErrorConstructor.captureStackTrace === "function") {
|
|
70
|
+
ErrorConstructor.captureStackTrace(this, _ItWalletSpecsVersionError);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
code = "IT_WALLET_SPECS_VERSION_ERROR";
|
|
74
|
+
};
|
|
34
75
|
|
|
35
76
|
// src/fetcher.ts
|
|
36
77
|
var hasStatusOrThrow = (status, customError) => async (res) => {
|
|
@@ -49,27 +90,38 @@ var parseRawHttpResponse = (response) => response.headers.get("content-type")?.i
|
|
|
49
90
|
|
|
50
91
|
// src/index.ts
|
|
51
92
|
import {
|
|
93
|
+
ContentType,
|
|
52
94
|
JsonParseError,
|
|
53
95
|
ValidationError,
|
|
54
96
|
addSecondsToDate,
|
|
97
|
+
createFetcher,
|
|
55
98
|
dateToSeconds,
|
|
56
99
|
decodeUtf8String,
|
|
57
100
|
encodeToBase64Url,
|
|
58
|
-
|
|
101
|
+
formatZodError,
|
|
102
|
+
parseWithErrorHandling,
|
|
103
|
+
zHttpsUrl
|
|
59
104
|
} from "@openid4vc/utils";
|
|
60
105
|
export {
|
|
61
106
|
CONTENT_TYPES,
|
|
107
|
+
ContentType,
|
|
62
108
|
HEADERS,
|
|
109
|
+
IoWalletSdkConfig,
|
|
110
|
+
ItWalletSpecsVersion,
|
|
111
|
+
ItWalletSpecsVersionError,
|
|
63
112
|
JsonParseError,
|
|
64
113
|
UnexpectedStatusCodeError,
|
|
65
114
|
ValidationError,
|
|
66
115
|
addSecondsToDate,
|
|
116
|
+
createFetcher,
|
|
67
117
|
dateToSeconds,
|
|
68
118
|
decodeUtf8String,
|
|
69
119
|
encodeToBase64Url,
|
|
120
|
+
formatZodError,
|
|
70
121
|
hasStatusOrThrow,
|
|
71
122
|
parseRawHttpResponse,
|
|
72
123
|
parseWithErrorHandling,
|
|
73
|
-
serializeAttrs
|
|
124
|
+
serializeAttrs,
|
|
125
|
+
zHttpsUrl
|
|
74
126
|
};
|
|
75
127
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts","../src/errors.ts","../src/fetcher.ts","../src/index.ts"],"sourcesContent":["/**\n * HTTP Content-Type constants for OAuth2 requests\n */\nexport const CONTENT_TYPES = {\n FORM_URLENCODED: \"application/x-www-form-urlencoded\",\n JSON: \"application/json\",\n} as const;\n\n/**\n * HTTP Header constants\n */\nexport const HEADERS = {\n AUTHORIZATION: \"Authorization\",\n CONTENT_TYPE: \"Content-Type\",\n DPOP: \"DPoP\",\n OAUTH_CLIENT_ATTESTATION: \"OAuth-Client-Attestation\",\n OAUTH_CLIENT_ATTESTATION_POP: \"OAuth-Client-Attestation-PoP\",\n} as const;\n","// An error reason that supports both a string and a generic JSON object\ntype GenericErrorReason = Record<string, unknown> | string;\n\n/**\n * utility to format a set of attributes into an error message string\n *\n * @example\n * // returns \"foo=value bar=(list, item)\"\n * serializeAttrs({ foo: \"value\", bar: [\"list\", \"item\"] })\n *\n * @param attrs A key value record set\n * @returns a human-readable serialization of the set\n */\nexport const serializeAttrs = (\n attrs: Record<string, GenericErrorReason | number | string[] | undefined>,\n): string =>\n Object.entries(attrs)\n .filter(([, v]) => v !== undefined)\n .map(([k, v]) => {\n if (Array.isArray(v)) return [k, `(${v.join(\", \")})`];\n if (typeof v !== \"string\") return [k, JSON.stringify(v)];\n return [k, v];\n })\n .map((_) => _.join(\"=\"))\n .join(\" \");\n\n/**\n * An error subclass thrown when an HTTP request has a status code different from the one expected.\n */\nexport class UnexpectedStatusCodeError extends Error {\n code = \"ERR_UNEXPECTED_STATUS_CODE\";\n reason: GenericErrorReason;\n statusCode: number;\n\n constructor({\n message,\n reason,\n statusCode,\n }: {\n message: string;\n reason: GenericErrorReason;\n statusCode: number;\n }) {\n super(serializeAttrs({ message, reason, statusCode }));\n this.reason = reason;\n this.statusCode = statusCode;\n }\n}\n","import { UnexpectedStatusCodeError } from \"./errors\";\n\n/**\n * Check if a response is in the expected status, otherwise throw an error\n * @param status - The expected status\n * @param customError - A custom error compatible with {@link UnexpectedStatusCodeError}\n * @throws UnexpectedStatusCodeError if the status is different from the one expected\n * @returns The given response object\n */\nexport const hasStatusOrThrow =\n (status: number, customError?: typeof UnexpectedStatusCodeError) =>\n async (res: Response): Promise<Response> => {\n if (res.status !== status) {\n const ErrorClass = customError ?? UnexpectedStatusCodeError;\n throw new ErrorClass({\n message: `Http request failed. Expected ${status}, got ${res.status}, url: ${res.url}`,\n reason: await parseRawHttpResponse(res), // Pass the response body as reason so the original error can surface\n statusCode: res.status,\n });\n }\n return res;\n };\n\n/**\n * Utility function to parse a raw HTTP response as JSON if supported, otherwise as text.\n */\nexport const parseRawHttpResponse = <T extends Record<string, unknown>>(\n response: Response,\n) =>\n response.headers.get(\"content-type\")?.includes(\"application/json\")\n ? (response.json() as Promise<T>)\n : response.text();\n","export * from \"./constants\";\nexport * from \"./errors\";\nexport * from \"./fetcher\";\n\nexport {\n type Fetch,\n JsonParseError,\n ValidationError,\n addSecondsToDate,\n dateToSeconds,\n decodeUtf8String,\n encodeToBase64Url,\n parseWithErrorHandling,\n} from \"@openid4vc/utils\";\n"],"mappings":";AAGO,IAAM,gBAAgB;AAAA,EAC3B,iBAAiB;AAAA,EACjB,MAAM;AACR;AAKO,IAAM,UAAU;AAAA,EACrB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,MAAM;AAAA,EACN,0BAA0B;AAAA,EAC1B,8BAA8B;AAChC;;;ACJO,IAAM,iBAAiB,CAC5B,UAEA,OAAO,QAAQ,KAAK,EACjB,OAAO,CAAC,CAAC,EAAE,CAAC,MAAM,MAAM,MAAS,EACjC,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM;AACf,MAAI,MAAM,QAAQ,CAAC,EAAG,QAAO,CAAC,GAAG,IAAI,EAAE,KAAK,IAAI,CAAC,GAAG;AACpD,MAAI,OAAO,MAAM,SAAU,QAAO,CAAC,GAAG,KAAK,UAAU,CAAC,CAAC;AACvD,SAAO,CAAC,GAAG,CAAC;AACd,CAAC,EACA,IAAI,CAAC,MAAM,EAAE,KAAK,GAAG,CAAC,EACtB,KAAK,GAAG;AAKN,IAAM,4BAAN,cAAwC,MAAM;AAAA,EACnD,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EAEA,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAIG;AACD,UAAM,eAAe,EAAE,SAAS,QAAQ,WAAW,CAAC,CAAC;AACrD,SAAK,SAAS;AACd,SAAK,aAAa;AAAA,EACpB;AACF;;;
|
|
1
|
+
{"version":3,"sources":["../src/config.ts","../src/constants.ts","../src/errors.ts","../src/fetcher.ts","../src/index.ts"],"sourcesContent":["/**\n * Supported versions of the Italian Wallet technical specifications\n */\nexport enum ItWalletSpecsVersion {\n V1_0 = \"V1_0\",\n V1_3 = \"V1_3\",\n}\n\n/**\n * Configuration options for the IO Wallet SDK\n */\nexport interface IoWalletSdkConfigOptions {\n /**\n * The version of the Italian Wallet specification to use.\n * REQUIRED - must be explicitly set by the user.\n *\n * Version differences:\n * - V1_0: Uses singular `proof` object with explicit `proof_type` field\n * - V1_3: Uses plural `proofs` object with JWT array and requires key attestation\n *\n * @example\n * const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_3 });\n */\n itWalletSpecsVersion: ItWalletSpecsVersion;\n}\n\n/**\n * Configuration class for the IO Wallet SDK\n *\n * This class manages the version of the Italian Wallet technical specifications\n * to use throughout the SDK. The version determines the format of credential\n * requests and responses.\n *\n * @example Basic usage\n * const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_0 });\n * console.log(config.itWalletSpecsVersion); // ItWalletSpecsVersion.V1_0\n *\n * @example Type guard usage\n * if (config.isVersion(ItWalletSpecsVersion.V1_3)) {\n * // TypeScript narrows config.itWalletSpecsVersion to ItWalletSpecsVersion.V1_3\n * }\n */\nexport class IoWalletSdkConfig {\n public readonly itWalletSpecsVersion: ItWalletSpecsVersion;\n\n constructor(options: IoWalletSdkConfigOptions) {\n this.itWalletSpecsVersion = options.itWalletSpecsVersion;\n }\n\n /**\n * Type guard for version checking\n *\n * @param version - The version to check against\n * @returns True if the config's version matches the provided version\n *\n * @internal\n */\n isVersion<V extends ItWalletSpecsVersion>(\n version: V,\n ): this is { itWalletSpecsVersion: V } & IoWalletSdkConfig {\n return this.itWalletSpecsVersion === version;\n }\n}\n","/**\n * HTTP Content-Type constants for OAuth2 requests\n */\nexport const CONTENT_TYPES = {\n FORM_URLENCODED: \"application/x-www-form-urlencoded\",\n JSON: \"application/json\",\n} as const;\n\n/**\n * HTTP Header constants\n */\nexport const HEADERS = {\n AUTHORIZATION: \"Authorization\",\n CONTENT_TYPE: \"Content-Type\",\n DPOP: \"DPoP\",\n OAUTH_CLIENT_ATTESTATION: \"OAuth-Client-Attestation\",\n OAUTH_CLIENT_ATTESTATION_POP: \"OAuth-Client-Attestation-PoP\",\n} as const;\n","// An error reason that supports both a string and a generic JSON object\ntype GenericErrorReason = Record<string, unknown> | string;\n\n/**\n * utility to format a set of attributes into an error message string\n *\n * @example\n * // returns \"foo=value bar=(list, item)\"\n * serializeAttrs({ foo: \"value\", bar: [\"list\", \"item\"] })\n *\n * @param attrs A key value record set\n * @returns a human-readable serialization of the set\n */\nexport const serializeAttrs = (\n attrs: Record<string, GenericErrorReason | number | string[] | undefined>,\n): string =>\n Object.entries(attrs)\n .filter(([, v]) => v !== undefined)\n .map(([k, v]) => {\n if (Array.isArray(v)) return [k, `(${v.join(\", \")})`];\n if (typeof v !== \"string\") return [k, JSON.stringify(v)];\n return [k, v];\n })\n .map((_) => _.join(\"=\"))\n .join(\" \");\n\n/**\n * An error subclass thrown when an HTTP request has a status code different from the one expected.\n */\nexport class UnexpectedStatusCodeError extends Error {\n code = \"ERR_UNEXPECTED_STATUS_CODE\";\n reason: GenericErrorReason;\n statusCode: number;\n\n constructor({\n message,\n reason,\n statusCode,\n }: {\n message: string;\n reason: GenericErrorReason;\n statusCode: number;\n }) {\n super(serializeAttrs({ message, reason, statusCode }));\n this.reason = reason;\n this.statusCode = statusCode;\n }\n}\n\n/**\n * An error subclass thrown when an unsupported Italian Wallet specification version is requested.\n *\n * This error is thrown when:\n * - A feature or method is called with a version that it doesn't support\n * - An invalid version identifier is provided\n *\n * @example\n * throw new ItWalletSpecsVersionError(\n * 'createCredentialRequest',\n * '2.0.0',\n * [ItWalletSpecsVersion.V1_0, ItWalletSpecsVersion.V1_3]\n * );\n * // Error: Feature \"createCredentialRequest\" does not support version 2.0.0.\n * // Supported versions: V1_0, V1_3\n */\nexport class ItWalletSpecsVersionError extends Error {\n public readonly code = \"IT_WALLET_SPECS_VERSION_ERROR\";\n\n constructor(\n public readonly feature: string,\n public readonly requestedVersion: string,\n public readonly supportedVersions: readonly string[],\n ) {\n super(\n `Feature \"${feature}\" does not support version ${requestedVersion}.\\n` +\n `Supported versions: ${supportedVersions.join(\", \")}`,\n );\n this.name = \"ItWalletSpecsVersionError\";\n\n // Maintain proper stack trace for V8 engines (Node.js, Chrome)\n const ErrorConstructor = Error as {\n captureStackTrace?: (target: object, constructor: unknown) => void;\n };\n if (typeof ErrorConstructor.captureStackTrace === \"function\") {\n ErrorConstructor.captureStackTrace(this, ItWalletSpecsVersionError);\n }\n }\n}\n","import { UnexpectedStatusCodeError } from \"./errors\";\n\n/**\n * Check if a response is in the expected status, otherwise throw an error\n * @param status - The expected status\n * @param customError - A custom error compatible with {@link UnexpectedStatusCodeError}\n * @throws UnexpectedStatusCodeError if the status is different from the one expected\n * @returns The given response object\n */\nexport const hasStatusOrThrow =\n (status: number, customError?: typeof UnexpectedStatusCodeError) =>\n async (res: Response): Promise<Response> => {\n if (res.status !== status) {\n const ErrorClass = customError ?? UnexpectedStatusCodeError;\n throw new ErrorClass({\n message: `Http request failed. Expected ${status}, got ${res.status}, url: ${res.url}`,\n reason: await parseRawHttpResponse(res), // Pass the response body as reason so the original error can surface\n statusCode: res.status,\n });\n }\n return res;\n };\n\n/**\n * Utility function to parse a raw HTTP response as JSON if supported, otherwise as text.\n */\nexport const parseRawHttpResponse = <T extends Record<string, unknown>>(\n response: Response,\n) =>\n response.headers.get(\"content-type\")?.includes(\"application/json\")\n ? (response.json() as Promise<T>)\n : response.text();\n","export * from \"./config\";\nexport * from \"./constants\";\nexport * from \"./errors\";\nexport * from \"./fetcher\";\nexport type * from \"./globals\";\n\nexport {\n ContentType,\n type Fetch,\n JsonParseError,\n ValidationError,\n addSecondsToDate,\n createFetcher,\n dateToSeconds,\n decodeUtf8String,\n encodeToBase64Url,\n formatZodError,\n parseWithErrorHandling,\n zHttpsUrl,\n} from \"@openid4vc/utils\";\n"],"mappings":";AAGO,IAAK,uBAAL,kBAAKA,0BAAL;AACL,EAAAA,sBAAA,UAAO;AACP,EAAAA,sBAAA,UAAO;AAFG,SAAAA;AAAA,GAAA;AAuCL,IAAM,oBAAN,MAAwB;AAAA,EACb;AAAA,EAEhB,YAAY,SAAmC;AAC7C,SAAK,uBAAuB,QAAQ;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,UACE,SACyD;AACzD,WAAO,KAAK,yBAAyB;AAAA,EACvC;AACF;;;AC3DO,IAAM,gBAAgB;AAAA,EAC3B,iBAAiB;AAAA,EACjB,MAAM;AACR;AAKO,IAAM,UAAU;AAAA,EACrB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,MAAM;AAAA,EACN,0BAA0B;AAAA,EAC1B,8BAA8B;AAChC;;;ACJO,IAAM,iBAAiB,CAC5B,UAEA,OAAO,QAAQ,KAAK,EACjB,OAAO,CAAC,CAAC,EAAE,CAAC,MAAM,MAAM,MAAS,EACjC,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM;AACf,MAAI,MAAM,QAAQ,CAAC,EAAG,QAAO,CAAC,GAAG,IAAI,EAAE,KAAK,IAAI,CAAC,GAAG;AACpD,MAAI,OAAO,MAAM,SAAU,QAAO,CAAC,GAAG,KAAK,UAAU,CAAC,CAAC;AACvD,SAAO,CAAC,GAAG,CAAC;AACd,CAAC,EACA,IAAI,CAAC,MAAM,EAAE,KAAK,GAAG,CAAC,EACtB,KAAK,GAAG;AAKN,IAAM,4BAAN,cAAwC,MAAM;AAAA,EACnD,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EAEA,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAIG;AACD,UAAM,eAAe,EAAE,SAAS,QAAQ,WAAW,CAAC,CAAC;AACrD,SAAK,SAAS;AACd,SAAK,aAAa;AAAA,EACpB;AACF;AAkBO,IAAM,4BAAN,MAAM,mCAAkC,MAAM;AAAA,EAGnD,YACkB,SACA,kBACA,mBAChB;AACA;AAAA,MACE,YAAY,OAAO,8BAA8B,gBAAgB;AAAA,sBACxC,kBAAkB,KAAK,IAAI,CAAC;AAAA,IACvD;AAPgB;AACA;AACA;AAMhB,SAAK,OAAO;AAGZ,UAAM,mBAAmB;AAGzB,QAAI,OAAO,iBAAiB,sBAAsB,YAAY;AAC5D,uBAAiB,kBAAkB,MAAM,0BAAyB;AAAA,IACpE;AAAA,EACF;AAAA,EApBgB,OAAO;AAqBzB;;;AC9EO,IAAM,mBACX,CAAC,QAAgB,gBACjB,OAAO,QAAqC;AAC1C,MAAI,IAAI,WAAW,QAAQ;AACzB,UAAM,aAAa,eAAe;AAClC,UAAM,IAAI,WAAW;AAAA,MACnB,SAAS,iCAAiC,MAAM,SAAS,IAAI,MAAM,UAAU,IAAI,GAAG;AAAA,MACpF,QAAQ,MAAM,qBAAqB,GAAG;AAAA;AAAA,MACtC,YAAY,IAAI;AAAA,IAClB,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAKK,IAAM,uBAAuB,CAClC,aAEA,SAAS,QAAQ,IAAI,cAAc,GAAG,SAAS,kBAAkB,IAC5D,SAAS,KAAK,IACf,SAAS,KAAK;;;ACzBpB;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":["ItWalletSpecsVersion"]}
|