@pagopa/io-wallet-utils 1.0.0 → 1.1.0-alpha-20260306102244

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import z$1, { ZodError, z } from 'zod';
2
- export { ContentType, Fetch, JsonParseError, addSecondsToDate, createFetcher, dateToSeconds, decodeBase64, decodeUtf8String, encodeToBase64Url, encodeToUtf8String, setGlobalConfig, stringToJsonWithErrorHandling } from '@openid4vc/utils';
2
+ export { ContentType, Fetch, JsonParseError, addSecondsToDate, createFetcher, dateToSeconds, decodeBase64, decodeUtf8String, encodeToBase64Url, encodeToUtf8String, objectToQueryParams, setGlobalConfig, stringToJsonWithErrorHandling } from '@openid4vc/utils';
3
3
 
4
4
  /**
5
5
  * Supported versions of the Italian Wallet technical specifications
@@ -11,20 +11,30 @@ declare enum ItWalletSpecsVersion {
11
11
  /**
12
12
  * Configuration options for the IO Wallet SDK
13
13
  */
14
- interface IoWalletSdkConfigOptions {
14
+ interface IoWalletSdkConfigOptions<V extends ItWalletSpecsVersion = ItWalletSpecsVersion> {
15
15
  /**
16
16
  * The version of the Italian Wallet specification to use.
17
17
  * REQUIRED - must be explicitly set by the user.
18
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
19
  * @example
24
20
  * const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_3 });
25
21
  */
26
- itWalletSpecsVersion: ItWalletSpecsVersion;
22
+ itWalletSpecsVersion: V;
23
+ }
24
+ interface WithConfig {
25
+ config: IoWalletSdkConfig;
27
26
  }
27
+ type WithConfigVersion<T extends WithConfig, V extends ItWalletSpecsVersion> = T extends {
28
+ config: IoWalletSdkConfig<V>;
29
+ } ? T : never;
30
+ /**
31
+ * Type guard to check if the provided options have a specific config version
32
+ *
33
+ * @param options - The options object containing the config to check
34
+ * @param version - The version to check against
35
+ * @returns True if the options' config version matches the provided version
36
+ */
37
+ declare function hasConfigVersion<T extends WithConfig, V extends ItWalletSpecsVersion>(options: T, version: V): options is WithConfigVersion<T, V>;
28
38
  /**
29
39
  * Configuration class for the IO Wallet SDK
30
40
  *
@@ -41,9 +51,9 @@ interface IoWalletSdkConfigOptions {
41
51
  * // TypeScript narrows config.itWalletSpecsVersion to ItWalletSpecsVersion.V1_3
42
52
  * }
43
53
  */
44
- declare class IoWalletSdkConfig {
45
- readonly itWalletSpecsVersion: ItWalletSpecsVersion;
46
- constructor(options: IoWalletSdkConfigOptions);
54
+ declare class IoWalletSdkConfig<V extends ItWalletSpecsVersion = ItWalletSpecsVersion> {
55
+ readonly itWalletSpecsVersion: V;
56
+ constructor(options: IoWalletSdkConfigOptions<V>);
47
57
  /**
48
58
  * Type guard for version checking
49
59
  *
@@ -52,9 +62,7 @@ declare class IoWalletSdkConfig {
52
62
  *
53
63
  * @internal
54
64
  */
55
- isVersion<V extends ItWalletSpecsVersion>(version: V): this is {
56
- itWalletSpecsVersion: V;
57
- } & IoWalletSdkConfig;
65
+ isVersion<W extends ItWalletSpecsVersion>(version: W): this is IoWalletSdkConfig<W>;
58
66
  }
59
67
 
60
68
  /**
@@ -156,4 +164,4 @@ interface RequestLike {
156
164
  type BaseSchema = z.ZodTypeAny;
157
165
  declare function parseWithErrorHandling<Schema extends BaseSchema>(schema: Schema, data: unknown, customErrorMessage?: string): z.infer<Schema>;
158
166
 
159
- export { type BaseSchema, CONTENT_TYPES, type FetchHeaders, HEADERS, type HttpMethod, IoWalletSdkConfig, type IoWalletSdkConfigOptions, ItWalletSpecsVersion, ItWalletSpecsVersionError, type RequestLike, UnexpectedStatusCodeError, ValidationError, formatZodError, hasStatusOrThrow, parseRawHttpResponse, parseWithErrorHandling, serializeAttrs, zHttpMethod };
167
+ export { type BaseSchema, CONTENT_TYPES, type FetchHeaders, HEADERS, type HttpMethod, IoWalletSdkConfig, type IoWalletSdkConfigOptions, ItWalletSpecsVersion, ItWalletSpecsVersionError, type RequestLike, UnexpectedStatusCodeError, ValidationError, formatZodError, hasConfigVersion, hasStatusOrThrow, parseRawHttpResponse, parseWithErrorHandling, serializeAttrs, zHttpMethod };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import z$1, { ZodError, z } from 'zod';
2
- export { ContentType, Fetch, JsonParseError, addSecondsToDate, createFetcher, dateToSeconds, decodeBase64, decodeUtf8String, encodeToBase64Url, encodeToUtf8String, setGlobalConfig, stringToJsonWithErrorHandling } from '@openid4vc/utils';
2
+ export { ContentType, Fetch, JsonParseError, addSecondsToDate, createFetcher, dateToSeconds, decodeBase64, decodeUtf8String, encodeToBase64Url, encodeToUtf8String, objectToQueryParams, setGlobalConfig, stringToJsonWithErrorHandling } from '@openid4vc/utils';
3
3
 
4
4
  /**
5
5
  * Supported versions of the Italian Wallet technical specifications
@@ -11,20 +11,30 @@ declare enum ItWalletSpecsVersion {
11
11
  /**
12
12
  * Configuration options for the IO Wallet SDK
13
13
  */
14
- interface IoWalletSdkConfigOptions {
14
+ interface IoWalletSdkConfigOptions<V extends ItWalletSpecsVersion = ItWalletSpecsVersion> {
15
15
  /**
16
16
  * The version of the Italian Wallet specification to use.
17
17
  * REQUIRED - must be explicitly set by the user.
18
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
19
  * @example
24
20
  * const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_3 });
25
21
  */
26
- itWalletSpecsVersion: ItWalletSpecsVersion;
22
+ itWalletSpecsVersion: V;
23
+ }
24
+ interface WithConfig {
25
+ config: IoWalletSdkConfig;
27
26
  }
27
+ type WithConfigVersion<T extends WithConfig, V extends ItWalletSpecsVersion> = T extends {
28
+ config: IoWalletSdkConfig<V>;
29
+ } ? T : never;
30
+ /**
31
+ * Type guard to check if the provided options have a specific config version
32
+ *
33
+ * @param options - The options object containing the config to check
34
+ * @param version - The version to check against
35
+ * @returns True if the options' config version matches the provided version
36
+ */
37
+ declare function hasConfigVersion<T extends WithConfig, V extends ItWalletSpecsVersion>(options: T, version: V): options is WithConfigVersion<T, V>;
28
38
  /**
29
39
  * Configuration class for the IO Wallet SDK
30
40
  *
@@ -41,9 +51,9 @@ interface IoWalletSdkConfigOptions {
41
51
  * // TypeScript narrows config.itWalletSpecsVersion to ItWalletSpecsVersion.V1_3
42
52
  * }
43
53
  */
44
- declare class IoWalletSdkConfig {
45
- readonly itWalletSpecsVersion: ItWalletSpecsVersion;
46
- constructor(options: IoWalletSdkConfigOptions);
54
+ declare class IoWalletSdkConfig<V extends ItWalletSpecsVersion = ItWalletSpecsVersion> {
55
+ readonly itWalletSpecsVersion: V;
56
+ constructor(options: IoWalletSdkConfigOptions<V>);
47
57
  /**
48
58
  * Type guard for version checking
49
59
  *
@@ -52,9 +62,7 @@ declare class IoWalletSdkConfig {
52
62
  *
53
63
  * @internal
54
64
  */
55
- isVersion<V extends ItWalletSpecsVersion>(version: V): this is {
56
- itWalletSpecsVersion: V;
57
- } & IoWalletSdkConfig;
65
+ isVersion<W extends ItWalletSpecsVersion>(version: W): this is IoWalletSdkConfig<W>;
58
66
  }
59
67
 
60
68
  /**
@@ -156,4 +164,4 @@ interface RequestLike {
156
164
  type BaseSchema = z.ZodTypeAny;
157
165
  declare function parseWithErrorHandling<Schema extends BaseSchema>(schema: Schema, data: unknown, customErrorMessage?: string): z.infer<Schema>;
158
166
 
159
- export { type BaseSchema, CONTENT_TYPES, type FetchHeaders, HEADERS, type HttpMethod, IoWalletSdkConfig, type IoWalletSdkConfigOptions, ItWalletSpecsVersion, ItWalletSpecsVersionError, type RequestLike, UnexpectedStatusCodeError, ValidationError, formatZodError, hasStatusOrThrow, parseRawHttpResponse, parseWithErrorHandling, serializeAttrs, zHttpMethod };
167
+ export { type BaseSchema, CONTENT_TYPES, type FetchHeaders, HEADERS, type HttpMethod, IoWalletSdkConfig, type IoWalletSdkConfigOptions, ItWalletSpecsVersion, ItWalletSpecsVersionError, type RequestLike, UnexpectedStatusCodeError, ValidationError, formatZodError, hasConfigVersion, hasStatusOrThrow, parseRawHttpResponse, parseWithErrorHandling, serializeAttrs, zHttpMethod };
package/dist/index.js CHANGED
@@ -47,7 +47,9 @@ __export(index_exports, {
47
47
  encodeToBase64Url: () => import_utils.encodeToBase64Url,
48
48
  encodeToUtf8String: () => import_utils.encodeToUtf8String,
49
49
  formatZodError: () => formatZodError,
50
+ hasConfigVersion: () => hasConfigVersion,
50
51
  hasStatusOrThrow: () => hasStatusOrThrow,
52
+ objectToQueryParams: () => import_utils.objectToQueryParams,
51
53
  parseRawHttpResponse: () => parseRawHttpResponse,
52
54
  parseWithErrorHandling: () => parseWithErrorHandling,
53
55
  serializeAttrs: () => serializeAttrs,
@@ -63,6 +65,9 @@ var ItWalletSpecsVersion = /* @__PURE__ */ ((ItWalletSpecsVersion2) => {
63
65
  ItWalletSpecsVersion2["V1_3"] = "V1_3";
64
66
  return ItWalletSpecsVersion2;
65
67
  })(ItWalletSpecsVersion || {});
68
+ function hasConfigVersion(options, version) {
69
+ return options.config.itWalletSpecsVersion === version;
70
+ }
66
71
  var IoWalletSdkConfig = class {
67
72
  itWalletSpecsVersion;
68
73
  constructor(options) {
@@ -77,7 +82,8 @@ var IoWalletSdkConfig = class {
77
82
  * @internal
78
83
  */
79
84
  isVersion(version) {
80
- return this.itWalletSpecsVersion === version;
85
+ const currentVersion = this.itWalletSpecsVersion;
86
+ return currentVersion === version;
81
87
  }
82
88
  };
83
89
 
@@ -295,7 +301,9 @@ var import_utils = require("@openid4vc/utils");
295
301
  encodeToBase64Url,
296
302
  encodeToUtf8String,
297
303
  formatZodError,
304
+ hasConfigVersion,
298
305
  hasStatusOrThrow,
306
+ objectToQueryParams,
299
307
  parseRawHttpResponse,
300
308
  parseWithErrorHandling,
301
309
  serializeAttrs,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/config.ts","../src/constants.ts","../src/errors/parse.ts","../src/errors/errors.ts","../src/fetcher.ts","../src/parse.ts","../src/validation.ts"],"sourcesContent":["export * from \"./config\";\nexport * from \"./constants\";\nexport * from \"./errors\";\nexport * from \"./fetcher\";\nexport type * from \"./globals\";\nexport * from \"./parse\";\nexport * from \"./validation\";\n\nexport {\n ContentType,\n type Fetch,\n JsonParseError,\n addSecondsToDate,\n createFetcher,\n dateToSeconds,\n decodeBase64,\n decodeUtf8String,\n encodeToBase64Url,\n encodeToUtf8String,\n setGlobalConfig,\n stringToJsonWithErrorHandling,\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","import type z from \"zod\";\n\nimport { type ZodIssue, ZodIssueCode } from \"zod\";\n\n/**\n * Some code comes from `zod-validation-error` package (MIT License) and\n * was slightly simplified to fit our needs.\n */\nconst constants = {\n // biome-ignore lint/suspicious/noMisleadingCharacterClass: expected\n identifierRegex: /[$_\\p{ID_Start}][$\\u200c\\u200d\\p{ID_Continue}]*/u,\n issueSeparator: \"\\n\\t- \",\n unionSeparator: \", or \",\n};\n\nfunction escapeQuotes(str: string): string {\n return str.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"');\n}\n\nfunction joinPath(path: (number | string)[]): string {\n if (path.length === 1 && path[0] !== undefined) {\n return path[0].toString();\n }\n\n return path.reduce<string>((acc, item) => {\n // handle numeric indices\n if (typeof item === \"number\") {\n return `${acc}[${item.toString()}]`;\n }\n\n // handle quoted values\n if (item.includes('\"')) {\n return `${acc}[\"${escapeQuotes(item)}\"]`;\n }\n\n // handle special characters\n if (!constants.identifierRegex.test(item)) {\n return `${acc}[\"${item}\"]`;\n }\n\n // handle normal values\n const separator = acc.length === 0 ? \"\" : \".\";\n return acc + separator + item;\n }, \"\");\n}\nfunction getMessageFromZodIssue(issue: ZodIssue): string {\n if (issue.code === ZodIssueCode.invalid_union) {\n return getMessageFromUnionErrors(issue.unionErrors);\n }\n\n if (issue.code === ZodIssueCode.invalid_arguments) {\n return [\n issue.message,\n ...issue.argumentsError.issues.map((issue) =>\n getMessageFromZodIssue(issue),\n ),\n ].join(constants.issueSeparator);\n }\n\n if (issue.code === ZodIssueCode.invalid_return_type) {\n return [\n issue.message,\n ...issue.returnTypeError.issues.map((issue) =>\n getMessageFromZodIssue(issue),\n ),\n ].join(constants.issueSeparator);\n }\n\n if (issue.path.length !== 0) {\n // handle array indices\n if (issue.path.length === 1) {\n const identifier = issue.path[0];\n\n if (typeof identifier === \"number\") {\n return `${issue.message} at index ${identifier}`;\n }\n }\n\n return `${issue.message} at \"${joinPath(issue.path)}\"`;\n }\n\n return issue.message;\n}\n\nfunction getMessageFromUnionErrors(unionErrors: z.ZodError[]): string {\n return unionErrors\n .reduce<string[]>((acc, zodError) => {\n const newIssues = zodError.issues\n .map((issue) => getMessageFromZodIssue(issue))\n .join(constants.issueSeparator);\n\n if (!acc.includes(newIssues)) acc.push(newIssues);\n\n return acc;\n }, [])\n .join(constants.unionSeparator);\n}\n\nexport function formatZodError(error?: z.ZodError): string {\n if (!error) return \"\";\n\n return `\\t- ${error?.issues.map((issue) => getMessageFromZodIssue(issue)).join(constants.issueSeparator)}`;\n}\n","import type { ZodError, z } from \"zod\";\n\nimport { formatZodError } from \"./parse\";\n\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\nexport class ValidationError extends Error {\n public zodError: ZodError | undefined;\n\n constructor(message: string, zodError?: z.ZodError) {\n super(message);\n\n const formattedError = formatZodError(zodError);\n this.message = `${message}\\n${formattedError}`;\n\n Object.defineProperty(this, \"zodError\", {\n enumerable: false,\n value: zodError,\n writable: false,\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 | number[], customError?: typeof UnexpectedStatusCodeError) =>\n async (res: Response): Promise<Response> => {\n if (\n Array.isArray(status)\n ? !status.includes(res.status)\n : res.status !== status\n ) {\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","import { z } from \"zod\";\n\nimport { ValidationError } from \"./errors/errors\";\n\nexport type BaseSchema = z.ZodTypeAny;\n\nconst SAFE_STRINGIFY_MAX_LENGTH = 200;\n\nfunction safeStringify(value: unknown): string {\n try {\n const result = JSON.stringify(value, (_key, val) =>\n typeof val === \"bigint\" ? `[BigInt: ${val}]` : val,\n );\n if (result === undefined) {\n return String(value);\n }\n return result.length > SAFE_STRINGIFY_MAX_LENGTH\n ? `${result.slice(0, SAFE_STRINGIFY_MAX_LENGTH)}…`\n : result;\n } catch {\n return \"[unserializable]\";\n }\n}\n\nexport function parseWithErrorHandling<Schema extends BaseSchema>(\n schema: Schema,\n data: unknown,\n customErrorMessage?: string,\n): z.infer<Schema> {\n const parseResult = schema.safeParse(data);\n\n if (!parseResult.success) {\n throw new ValidationError(\n customErrorMessage ??\n `Error validating schema with data ${safeStringify(data)}`,\n parseResult.error,\n );\n }\n\n return parseResult.data;\n}\n","import z from \"zod\";\n\nexport const zHttpMethod = z.enum([\n \"GET\",\n \"POST\",\n \"PUT\",\n \"DELETE\",\n \"HEAD\",\n \"OPTIONS\",\n \"TRACE\",\n \"CONNECT\",\n \"PATCH\",\n]);\nexport type HttpMethod = z.infer<typeof zHttpMethod>;\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;;;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;;;ACfA,iBAA4C;AAM5C,IAAM,YAAY;AAAA;AAAA,EAEhB,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,gBAAgB;AAClB;AAEA,SAAS,aAAa,KAAqB;AACzC,SAAO,IAAI,QAAQ,OAAO,MAAM,EAAE,QAAQ,MAA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;AAElC,SAAS,cAAc,OAAwB;AAC7C,MAAI;AACF,UAAM,SAAS,KAAK;AAAA,MAAU;AAAA,MAAO,CAAC,MAAM,QAC1C,OAAO,QAAQ,WAAW,YAAY,GAAG,MAAM;AAAA,IACjD;AACA,QAAI,WAAW,QAAW;AACxB,aAAO,OAAO,KAAK;AAAA,IACrB;AACA,WAAO,OAAO,SAAS,4BACnB,GAAG,OAAO,MAAM,GAAG,yBAAyB,CAAC,WAC7C;AAAA,EACN,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,uBACd,QACA,MACA,oBACiB;AACjB,QAAM,cAAc,OAAO,UAAU,IAAI;AAEzC,MAAI,CAAC,YAAY,SAAS;AACxB,UAAM,IAAI;AAAA,MACR,sBACE,qCAAqC,cAAc,IAAI,CAAC;AAAA,MAC1D,YAAY;AAAA,IACd;AAAA,EACF;AAEA,SAAO,YAAY;AACrB;;;ACxCA,IAAAC,cAAc;AAEP,IAAM,cAAc,YAAAC,QAAE,KAAK;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;;;APJD,mBAaO;","names":["ItWalletSpecsVersion","issue","import_zod","z"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/config.ts","../src/constants.ts","../src/errors/parse.ts","../src/errors/errors.ts","../src/fetcher.ts","../src/parse.ts","../src/validation.ts"],"sourcesContent":["export * from \"./config\";\nexport * from \"./constants\";\nexport * from \"./errors\";\nexport * from \"./fetcher\";\nexport type * from \"./globals\";\nexport * from \"./parse\";\nexport * from \"./validation\";\n\nexport {\n ContentType,\n type Fetch,\n JsonParseError,\n addSecondsToDate,\n createFetcher,\n dateToSeconds,\n decodeBase64,\n decodeUtf8String,\n encodeToBase64Url,\n encodeToUtf8String,\n objectToQueryParams,\n setGlobalConfig,\n stringToJsonWithErrorHandling,\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 V extends ItWalletSpecsVersion = ItWalletSpecsVersion,\n> {\n /**\n * The version of the Italian Wallet specification to use.\n * REQUIRED - must be explicitly set by the user.\n *\n * @example\n * const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_3 });\n */\n itWalletSpecsVersion: V;\n}\n\ninterface WithConfig {\n config: IoWalletSdkConfig;\n}\n\ntype WithConfigVersion<\n T extends WithConfig,\n V extends ItWalletSpecsVersion,\n> = T extends { config: IoWalletSdkConfig<V> } ? T : never;\n\n/**\n * Type guard to check if the provided options have a specific config version\n *\n * @param options - The options object containing the config to check\n * @param version - The version to check against\n * @returns True if the options' config version matches the provided version\n */\nexport function hasConfigVersion<\n T extends WithConfig,\n V extends ItWalletSpecsVersion,\n>(options: T, version: V): options is WithConfigVersion<T, V> {\n return options.config.itWalletSpecsVersion === version;\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 V extends ItWalletSpecsVersion = ItWalletSpecsVersion,\n> {\n public readonly itWalletSpecsVersion: V;\n\n constructor(options: IoWalletSdkConfigOptions<V>) {\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<W extends ItWalletSpecsVersion>(\n version: W,\n ): this is IoWalletSdkConfig<W> {\n const currentVersion: ItWalletSpecsVersion = this.itWalletSpecsVersion;\n return currentVersion === 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","import type z from \"zod\";\n\nimport { type ZodIssue, ZodIssueCode } from \"zod\";\n\n/**\n * Some code comes from `zod-validation-error` package (MIT License) and\n * was slightly simplified to fit our needs.\n */\nconst constants = {\n // biome-ignore lint/suspicious/noMisleadingCharacterClass: expected\n identifierRegex: /[$_\\p{ID_Start}][$\\u200c\\u200d\\p{ID_Continue}]*/u,\n issueSeparator: \"\\n\\t- \",\n unionSeparator: \", or \",\n};\n\nfunction escapeQuotes(str: string): string {\n return str.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"');\n}\n\nfunction joinPath(path: (number | string)[]): string {\n if (path.length === 1 && path[0] !== undefined) {\n return path[0].toString();\n }\n\n return path.reduce<string>((acc, item) => {\n // handle numeric indices\n if (typeof item === \"number\") {\n return `${acc}[${item.toString()}]`;\n }\n\n // handle quoted values\n if (item.includes('\"')) {\n return `${acc}[\"${escapeQuotes(item)}\"]`;\n }\n\n // handle special characters\n if (!constants.identifierRegex.test(item)) {\n return `${acc}[\"${item}\"]`;\n }\n\n // handle normal values\n const separator = acc.length === 0 ? \"\" : \".\";\n return acc + separator + item;\n }, \"\");\n}\nfunction getMessageFromZodIssue(issue: ZodIssue): string {\n if (issue.code === ZodIssueCode.invalid_union) {\n return getMessageFromUnionErrors(issue.unionErrors);\n }\n\n if (issue.code === ZodIssueCode.invalid_arguments) {\n return [\n issue.message,\n ...issue.argumentsError.issues.map((issue) =>\n getMessageFromZodIssue(issue),\n ),\n ].join(constants.issueSeparator);\n }\n\n if (issue.code === ZodIssueCode.invalid_return_type) {\n return [\n issue.message,\n ...issue.returnTypeError.issues.map((issue) =>\n getMessageFromZodIssue(issue),\n ),\n ].join(constants.issueSeparator);\n }\n\n if (issue.path.length !== 0) {\n // handle array indices\n if (issue.path.length === 1) {\n const identifier = issue.path[0];\n\n if (typeof identifier === \"number\") {\n return `${issue.message} at index ${identifier}`;\n }\n }\n\n return `${issue.message} at \"${joinPath(issue.path)}\"`;\n }\n\n return issue.message;\n}\n\nfunction getMessageFromUnionErrors(unionErrors: z.ZodError[]): string {\n return unionErrors\n .reduce<string[]>((acc, zodError) => {\n const newIssues = zodError.issues\n .map((issue) => getMessageFromZodIssue(issue))\n .join(constants.issueSeparator);\n\n if (!acc.includes(newIssues)) acc.push(newIssues);\n\n return acc;\n }, [])\n .join(constants.unionSeparator);\n}\n\nexport function formatZodError(error?: z.ZodError): string {\n if (!error) return \"\";\n\n return `\\t- ${error?.issues.map((issue) => getMessageFromZodIssue(issue)).join(constants.issueSeparator)}`;\n}\n","import type { ZodError, z } from \"zod\";\n\nimport { formatZodError } from \"./parse\";\n\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\nexport class ValidationError extends Error {\n public zodError: ZodError | undefined;\n\n constructor(message: string, zodError?: z.ZodError) {\n super(message);\n\n const formattedError = formatZodError(zodError);\n this.message = `${message}\\n${formattedError}`;\n\n Object.defineProperty(this, \"zodError\", {\n enumerable: false,\n value: zodError,\n writable: false,\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 | number[], customError?: typeof UnexpectedStatusCodeError) =>\n async (res: Response): Promise<Response> => {\n if (\n Array.isArray(status)\n ? !status.includes(res.status)\n : res.status !== status\n ) {\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","import { z } from \"zod\";\n\nimport { ValidationError } from \"./errors/errors\";\n\nexport type BaseSchema = z.ZodTypeAny;\n\nconst SAFE_STRINGIFY_MAX_LENGTH = 200;\n\nfunction safeStringify(value: unknown): string {\n try {\n const result = JSON.stringify(value, (_key, val) =>\n typeof val === \"bigint\" ? `[BigInt: ${val}]` : val,\n );\n if (result === undefined) {\n return String(value);\n }\n return result.length > SAFE_STRINGIFY_MAX_LENGTH\n ? `${result.slice(0, SAFE_STRINGIFY_MAX_LENGTH)}…`\n : result;\n } catch {\n return \"[unserializable]\";\n }\n}\n\nexport function parseWithErrorHandling<Schema extends BaseSchema>(\n schema: Schema,\n data: unknown,\n customErrorMessage?: string,\n): z.infer<Schema> {\n const parseResult = schema.safeParse(data);\n\n if (!parseResult.success) {\n throw new ValidationError(\n customErrorMessage ??\n `Error validating schema with data ${safeStringify(data)}`,\n parseResult.error,\n );\n }\n\n return parseResult.data;\n}\n","import z from \"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B;AAC7C,MAAI;AACF,UAAM,SAAS,KAAK;AAAA,MAAU;AAAA,MAAO,CAAC,MAAM,QAC1C,OAAO,QAAQ,WAAW,YAAY,GAAG,MAAM;AAAA,IACjD;AACA,QAAI,WAAW,QAAW;AACxB,aAAO,OAAO,KAAK;AAAA,IACrB;AACA,WAAO,OAAO,SAAS,4BACnB,GAAG,OAAO,MAAM,GAAG,yBAAyB,CAAC,WAC7C;AAAA,EACN,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,uBACd,QACA,MACA,oBACiB;AACjB,QAAM,cAAc,OAAO,UAAU,IAAI;AAEzC,MAAI,CAAC,YAAY,SAAS;AACxB,UAAM,IAAI;AAAA,MACR,sBACE,qCAAqC,cAAc,IAAI,CAAC;AAAA,MAC1D,YAAY;AAAA,IACd;AAAA,EACF;AAEA,SAAO,YAAY;AACrB;;;ACxCA,IAAAC,cAAc;AAEP,IAAM,cAAc,YAAAC,QAAE,KAAK;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;;;APJD,mBAcO;","names":["ItWalletSpecsVersion","issue","import_zod","z"]}
package/dist/index.mjs CHANGED
@@ -4,6 +4,9 @@ var ItWalletSpecsVersion = /* @__PURE__ */ ((ItWalletSpecsVersion2) => {
4
4
  ItWalletSpecsVersion2["V1_3"] = "V1_3";
5
5
  return ItWalletSpecsVersion2;
6
6
  })(ItWalletSpecsVersion || {});
7
+ function hasConfigVersion(options, version) {
8
+ return options.config.itWalletSpecsVersion === version;
9
+ }
7
10
  var IoWalletSdkConfig = class {
8
11
  itWalletSpecsVersion;
9
12
  constructor(options) {
@@ -18,7 +21,8 @@ var IoWalletSdkConfig = class {
18
21
  * @internal
19
22
  */
20
23
  isVersion(version) {
21
- return this.itWalletSpecsVersion === version;
24
+ const currentVersion = this.itWalletSpecsVersion;
25
+ return currentVersion === version;
22
26
  }
23
27
  };
24
28
 
@@ -226,6 +230,7 @@ import {
226
230
  decodeUtf8String,
227
231
  encodeToBase64Url,
228
232
  encodeToUtf8String,
233
+ objectToQueryParams,
229
234
  setGlobalConfig,
230
235
  stringToJsonWithErrorHandling
231
236
  } from "@openid4vc/utils";
@@ -247,7 +252,9 @@ export {
247
252
  encodeToBase64Url,
248
253
  encodeToUtf8String,
249
254
  formatZodError,
255
+ hasConfigVersion,
250
256
  hasStatusOrThrow,
257
+ objectToQueryParams,
251
258
  parseRawHttpResponse,
252
259
  parseWithErrorHandling,
253
260
  serializeAttrs,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/config.ts","../src/constants.ts","../src/errors/parse.ts","../src/errors/errors.ts","../src/fetcher.ts","../src/parse.ts","../src/validation.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","import type z from \"zod\";\n\nimport { type ZodIssue, ZodIssueCode } from \"zod\";\n\n/**\n * Some code comes from `zod-validation-error` package (MIT License) and\n * was slightly simplified to fit our needs.\n */\nconst constants = {\n // biome-ignore lint/suspicious/noMisleadingCharacterClass: expected\n identifierRegex: /[$_\\p{ID_Start}][$\\u200c\\u200d\\p{ID_Continue}]*/u,\n issueSeparator: \"\\n\\t- \",\n unionSeparator: \", or \",\n};\n\nfunction escapeQuotes(str: string): string {\n return str.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"');\n}\n\nfunction joinPath(path: (number | string)[]): string {\n if (path.length === 1 && path[0] !== undefined) {\n return path[0].toString();\n }\n\n return path.reduce<string>((acc, item) => {\n // handle numeric indices\n if (typeof item === \"number\") {\n return `${acc}[${item.toString()}]`;\n }\n\n // handle quoted values\n if (item.includes('\"')) {\n return `${acc}[\"${escapeQuotes(item)}\"]`;\n }\n\n // handle special characters\n if (!constants.identifierRegex.test(item)) {\n return `${acc}[\"${item}\"]`;\n }\n\n // handle normal values\n const separator = acc.length === 0 ? \"\" : \".\";\n return acc + separator + item;\n }, \"\");\n}\nfunction getMessageFromZodIssue(issue: ZodIssue): string {\n if (issue.code === ZodIssueCode.invalid_union) {\n return getMessageFromUnionErrors(issue.unionErrors);\n }\n\n if (issue.code === ZodIssueCode.invalid_arguments) {\n return [\n issue.message,\n ...issue.argumentsError.issues.map((issue) =>\n getMessageFromZodIssue(issue),\n ),\n ].join(constants.issueSeparator);\n }\n\n if (issue.code === ZodIssueCode.invalid_return_type) {\n return [\n issue.message,\n ...issue.returnTypeError.issues.map((issue) =>\n getMessageFromZodIssue(issue),\n ),\n ].join(constants.issueSeparator);\n }\n\n if (issue.path.length !== 0) {\n // handle array indices\n if (issue.path.length === 1) {\n const identifier = issue.path[0];\n\n if (typeof identifier === \"number\") {\n return `${issue.message} at index ${identifier}`;\n }\n }\n\n return `${issue.message} at \"${joinPath(issue.path)}\"`;\n }\n\n return issue.message;\n}\n\nfunction getMessageFromUnionErrors(unionErrors: z.ZodError[]): string {\n return unionErrors\n .reduce<string[]>((acc, zodError) => {\n const newIssues = zodError.issues\n .map((issue) => getMessageFromZodIssue(issue))\n .join(constants.issueSeparator);\n\n if (!acc.includes(newIssues)) acc.push(newIssues);\n\n return acc;\n }, [])\n .join(constants.unionSeparator);\n}\n\nexport function formatZodError(error?: z.ZodError): string {\n if (!error) return \"\";\n\n return `\\t- ${error?.issues.map((issue) => getMessageFromZodIssue(issue)).join(constants.issueSeparator)}`;\n}\n","import type { ZodError, z } from \"zod\";\n\nimport { formatZodError } from \"./parse\";\n\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\nexport class ValidationError extends Error {\n public zodError: ZodError | undefined;\n\n constructor(message: string, zodError?: z.ZodError) {\n super(message);\n\n const formattedError = formatZodError(zodError);\n this.message = `${message}\\n${formattedError}`;\n\n Object.defineProperty(this, \"zodError\", {\n enumerable: false,\n value: zodError,\n writable: false,\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 | number[], customError?: typeof UnexpectedStatusCodeError) =>\n async (res: Response): Promise<Response> => {\n if (\n Array.isArray(status)\n ? !status.includes(res.status)\n : res.status !== status\n ) {\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","import { z } from \"zod\";\n\nimport { ValidationError } from \"./errors/errors\";\n\nexport type BaseSchema = z.ZodTypeAny;\n\nconst SAFE_STRINGIFY_MAX_LENGTH = 200;\n\nfunction safeStringify(value: unknown): string {\n try {\n const result = JSON.stringify(value, (_key, val) =>\n typeof val === \"bigint\" ? `[BigInt: ${val}]` : val,\n );\n if (result === undefined) {\n return String(value);\n }\n return result.length > SAFE_STRINGIFY_MAX_LENGTH\n ? `${result.slice(0, SAFE_STRINGIFY_MAX_LENGTH)}…`\n : result;\n } catch {\n return \"[unserializable]\";\n }\n}\n\nexport function parseWithErrorHandling<Schema extends BaseSchema>(\n schema: Schema,\n data: unknown,\n customErrorMessage?: string,\n): z.infer<Schema> {\n const parseResult = schema.safeParse(data);\n\n if (!parseResult.success) {\n throw new ValidationError(\n customErrorMessage ??\n `Error validating schema with data ${safeStringify(data)}`,\n parseResult.error,\n );\n }\n\n return parseResult.data;\n}\n","import z from \"zod\";\n\nexport const zHttpMethod = z.enum([\n \"GET\",\n \"POST\",\n \"PUT\",\n \"DELETE\",\n \"HEAD\",\n \"OPTIONS\",\n \"TRACE\",\n \"CONNECT\",\n \"PATCH\",\n]);\nexport type HttpMethod = z.infer<typeof zHttpMethod>;\n","export * from \"./config\";\nexport * from \"./constants\";\nexport * from \"./errors\";\nexport * from \"./fetcher\";\nexport type * from \"./globals\";\nexport * from \"./parse\";\nexport * from \"./validation\";\n\nexport {\n ContentType,\n type Fetch,\n JsonParseError,\n addSecondsToDate,\n createFetcher,\n dateToSeconds,\n decodeBase64,\n decodeUtf8String,\n encodeToBase64Url,\n encodeToUtf8String,\n setGlobalConfig,\n stringToJsonWithErrorHandling,\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;;;ACfA,SAAwB,oBAAoB;AAM5C,IAAM,YAAY;AAAA;AAAA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;AAKK,IAAM,uBAAuB,CAClC,aAEA,SAAS,QAAQ,IAAI,cAAc,GAAG,SAAS,kBAAkB,IAC5D,SAAS,KAAK,IACf,SAAS,KAAK;;;AC7BpB,IAAM,4BAA4B;AAElC,SAAS,cAAc,OAAwB;AAC7C,MAAI;AACF,UAAM,SAAS,KAAK;AAAA,MAAU;AAAA,MAAO,CAAC,MAAM,QAC1C,OAAO,QAAQ,WAAW,YAAY,GAAG,MAAM;AAAA,IACjD;AACA,QAAI,WAAW,QAAW;AACxB,aAAO,OAAO,KAAK;AAAA,IACrB;AACA,WAAO,OAAO,SAAS,4BACnB,GAAG,OAAO,MAAM,GAAG,yBAAyB,CAAC,WAC7C;AAAA,EACN,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,uBACd,QACA,MACA,oBACiB;AACjB,QAAM,cAAc,OAAO,UAAU,IAAI;AAEzC,MAAI,CAAC,YAAY,SAAS;AACxB,UAAM,IAAI;AAAA,MACR,sBACE,qCAAqC,cAAc,IAAI,CAAC;AAAA,MAC1D,YAAY;AAAA,IACd;AAAA,EACF;AAEA,SAAO,YAAY;AACrB;;;ACxCA,OAAO,OAAO;AAEP,IAAM,cAAc,EAAE,KAAK;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;;;ACJD;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","issue"]}
1
+ {"version":3,"sources":["../src/config.ts","../src/constants.ts","../src/errors/parse.ts","../src/errors/errors.ts","../src/fetcher.ts","../src/parse.ts","../src/validation.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 V extends ItWalletSpecsVersion = ItWalletSpecsVersion,\n> {\n /**\n * The version of the Italian Wallet specification to use.\n * REQUIRED - must be explicitly set by the user.\n *\n * @example\n * const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_3 });\n */\n itWalletSpecsVersion: V;\n}\n\ninterface WithConfig {\n config: IoWalletSdkConfig;\n}\n\ntype WithConfigVersion<\n T extends WithConfig,\n V extends ItWalletSpecsVersion,\n> = T extends { config: IoWalletSdkConfig<V> } ? T : never;\n\n/**\n * Type guard to check if the provided options have a specific config version\n *\n * @param options - The options object containing the config to check\n * @param version - The version to check against\n * @returns True if the options' config version matches the provided version\n */\nexport function hasConfigVersion<\n T extends WithConfig,\n V extends ItWalletSpecsVersion,\n>(options: T, version: V): options is WithConfigVersion<T, V> {\n return options.config.itWalletSpecsVersion === version;\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 V extends ItWalletSpecsVersion = ItWalletSpecsVersion,\n> {\n public readonly itWalletSpecsVersion: V;\n\n constructor(options: IoWalletSdkConfigOptions<V>) {\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<W extends ItWalletSpecsVersion>(\n version: W,\n ): this is IoWalletSdkConfig<W> {\n const currentVersion: ItWalletSpecsVersion = this.itWalletSpecsVersion;\n return currentVersion === 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","import type z from \"zod\";\n\nimport { type ZodIssue, ZodIssueCode } from \"zod\";\n\n/**\n * Some code comes from `zod-validation-error` package (MIT License) and\n * was slightly simplified to fit our needs.\n */\nconst constants = {\n // biome-ignore lint/suspicious/noMisleadingCharacterClass: expected\n identifierRegex: /[$_\\p{ID_Start}][$\\u200c\\u200d\\p{ID_Continue}]*/u,\n issueSeparator: \"\\n\\t- \",\n unionSeparator: \", or \",\n};\n\nfunction escapeQuotes(str: string): string {\n return str.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"');\n}\n\nfunction joinPath(path: (number | string)[]): string {\n if (path.length === 1 && path[0] !== undefined) {\n return path[0].toString();\n }\n\n return path.reduce<string>((acc, item) => {\n // handle numeric indices\n if (typeof item === \"number\") {\n return `${acc}[${item.toString()}]`;\n }\n\n // handle quoted values\n if (item.includes('\"')) {\n return `${acc}[\"${escapeQuotes(item)}\"]`;\n }\n\n // handle special characters\n if (!constants.identifierRegex.test(item)) {\n return `${acc}[\"${item}\"]`;\n }\n\n // handle normal values\n const separator = acc.length === 0 ? \"\" : \".\";\n return acc + separator + item;\n }, \"\");\n}\nfunction getMessageFromZodIssue(issue: ZodIssue): string {\n if (issue.code === ZodIssueCode.invalid_union) {\n return getMessageFromUnionErrors(issue.unionErrors);\n }\n\n if (issue.code === ZodIssueCode.invalid_arguments) {\n return [\n issue.message,\n ...issue.argumentsError.issues.map((issue) =>\n getMessageFromZodIssue(issue),\n ),\n ].join(constants.issueSeparator);\n }\n\n if (issue.code === ZodIssueCode.invalid_return_type) {\n return [\n issue.message,\n ...issue.returnTypeError.issues.map((issue) =>\n getMessageFromZodIssue(issue),\n ),\n ].join(constants.issueSeparator);\n }\n\n if (issue.path.length !== 0) {\n // handle array indices\n if (issue.path.length === 1) {\n const identifier = issue.path[0];\n\n if (typeof identifier === \"number\") {\n return `${issue.message} at index ${identifier}`;\n }\n }\n\n return `${issue.message} at \"${joinPath(issue.path)}\"`;\n }\n\n return issue.message;\n}\n\nfunction getMessageFromUnionErrors(unionErrors: z.ZodError[]): string {\n return unionErrors\n .reduce<string[]>((acc, zodError) => {\n const newIssues = zodError.issues\n .map((issue) => getMessageFromZodIssue(issue))\n .join(constants.issueSeparator);\n\n if (!acc.includes(newIssues)) acc.push(newIssues);\n\n return acc;\n }, [])\n .join(constants.unionSeparator);\n}\n\nexport function formatZodError(error?: z.ZodError): string {\n if (!error) return \"\";\n\n return `\\t- ${error?.issues.map((issue) => getMessageFromZodIssue(issue)).join(constants.issueSeparator)}`;\n}\n","import type { ZodError, z } from \"zod\";\n\nimport { formatZodError } from \"./parse\";\n\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\nexport class ValidationError extends Error {\n public zodError: ZodError | undefined;\n\n constructor(message: string, zodError?: z.ZodError) {\n super(message);\n\n const formattedError = formatZodError(zodError);\n this.message = `${message}\\n${formattedError}`;\n\n Object.defineProperty(this, \"zodError\", {\n enumerable: false,\n value: zodError,\n writable: false,\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 | number[], customError?: typeof UnexpectedStatusCodeError) =>\n async (res: Response): Promise<Response> => {\n if (\n Array.isArray(status)\n ? !status.includes(res.status)\n : res.status !== status\n ) {\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","import { z } from \"zod\";\n\nimport { ValidationError } from \"./errors/errors\";\n\nexport type BaseSchema = z.ZodTypeAny;\n\nconst SAFE_STRINGIFY_MAX_LENGTH = 200;\n\nfunction safeStringify(value: unknown): string {\n try {\n const result = JSON.stringify(value, (_key, val) =>\n typeof val === \"bigint\" ? `[BigInt: ${val}]` : val,\n );\n if (result === undefined) {\n return String(value);\n }\n return result.length > SAFE_STRINGIFY_MAX_LENGTH\n ? `${result.slice(0, SAFE_STRINGIFY_MAX_LENGTH)}…`\n : result;\n } catch {\n return \"[unserializable]\";\n }\n}\n\nexport function parseWithErrorHandling<Schema extends BaseSchema>(\n schema: Schema,\n data: unknown,\n customErrorMessage?: string,\n): z.infer<Schema> {\n const parseResult = schema.safeParse(data);\n\n if (!parseResult.success) {\n throw new ValidationError(\n customErrorMessage ??\n `Error validating schema with data ${safeStringify(data)}`,\n parseResult.error,\n );\n }\n\n return parseResult.data;\n}\n","import z from \"zod\";\n\nexport const zHttpMethod = z.enum([\n \"GET\",\n \"POST\",\n \"PUT\",\n \"DELETE\",\n \"HEAD\",\n \"OPTIONS\",\n \"TRACE\",\n \"CONNECT\",\n \"PATCH\",\n]);\nexport type HttpMethod = z.infer<typeof zHttpMethod>;\n","export * from \"./config\";\nexport * from \"./constants\";\nexport * from \"./errors\";\nexport * from \"./fetcher\";\nexport type * from \"./globals\";\nexport * from \"./parse\";\nexport * from \"./validation\";\n\nexport {\n ContentType,\n type Fetch,\n JsonParseError,\n addSecondsToDate,\n createFetcher,\n dateToSeconds,\n decodeBase64,\n decodeUtf8String,\n encodeToBase64Url,\n encodeToUtf8String,\n objectToQueryParams,\n setGlobalConfig,\n stringToJsonWithErrorHandling,\n} from \"@openid4vc/utils\";\n"],"mappings":";AAGO,IAAK,uBAAL,kBAAKA,0BAAL;AACL,EAAAA,sBAAA,UAAO;AACP,EAAAA,sBAAA,UAAO;AAFG,SAAAA;AAAA,GAAA;AAqCL,SAAS,iBAGd,SAAY,SAAgD;AAC5D,SAAO,QAAQ,OAAO,yBAAyB;AACjD;AAkBO,IAAM,oBAAN,MAEL;AAAA,EACgB;AAAA,EAEhB,YAAY,SAAsC;AAChD,SAAK,uBAAuB,QAAQ;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,UACE,SAC8B;AAC9B,UAAM,iBAAuC,KAAK;AAClD,WAAO,mBAAmB;AAAA,EAC5B;AACF;;;ACnFO,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;;;ACfA,SAAwB,oBAAoB;AAM5C,IAAM,YAAY;AAAA;AAAA,EAEhB,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,gBAAgB;AAClB;AAEA,SAAS,aAAa,KAAqB;AACzC,SAAO,IAAI,QAAQ,OAAO,MAAM,EAA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M,4BAA4B;AAElC,SAAS,cAAc,OAAwB;AAC7C,MAAI;AACF,UAAM,SAAS,KAAK;AAAA,MAAU;AAAA,MAAO,CAAC,MAAM,QAC1C,OAAO,QAAQ,WAAW,YAAY,GAAG,MAAM;AAAA,IACjD;AACA,QAAI,WAAW,QAAW;AACxB,aAAO,OAAO,KAAK;AAAA,IACrB;AACA,WAAO,OAAO,SAAS,4BACnB,GAAG,OAAO,MAAM,GAAG,yBAAyB,CAAC,WAC7C;AAAA,EACN,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,uBACd,QACA,MACA,oBACiB;AACjB,QAAM,cAAc,OAAO,UAAU,IAAI;AAEzC,MAAI,CAAC,YAAY,SAAS;AACxB,UAAM,IAAI;AAAA,MACR,sBACE,qCAAqC,cAAc,IAAI,CAAC;AAAA,MAC1D,YAAY;AAAA,IACd;AAAA,EACF;AAEA,SAAO,YAAY;AACrB;;;ACxCA,OAAO,OAAO;AAEP,IAAM,cAAc,EAAE,KAAK;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;;;ACJD;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":["ItWalletSpecsVersion","issue"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/io-wallet-utils",
3
- "version": "1.0.0",
3
+ "version": "1.1.0-alpha-20260306102244",
4
4
  "files": [
5
5
  "dist"
6
6
  ],