@pagopa/io-wallet-utils 0.4.2 → 0.5.0
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { JsonParseError, ValidationError } from '@openid4vc/utils';
|
|
1
|
+
export { Fetch, JsonParseError, ValidationError, addSecondsToDate, dateToSeconds, decodeUtf8String, encodeToBase64Url, parseWithErrorHandling } from '@openid4vc/utils';
|
|
2
2
|
|
|
3
3
|
type GenericErrorReason = Record<string, unknown> | string;
|
|
4
4
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { JsonParseError, ValidationError } from '@openid4vc/utils';
|
|
1
|
+
export { Fetch, JsonParseError, ValidationError, addSecondsToDate, dateToSeconds, decodeUtf8String, encodeToBase64Url, parseWithErrorHandling } from '@openid4vc/utils';
|
|
2
2
|
|
|
3
3
|
type GenericErrorReason = Record<string, unknown> | string;
|
|
4
4
|
/**
|
package/dist/index.js
CHANGED
|
@@ -23,8 +23,13 @@ __export(index_exports, {
|
|
|
23
23
|
JsonParseError: () => import_utils.JsonParseError,
|
|
24
24
|
UnexpectedStatusCodeError: () => UnexpectedStatusCodeError,
|
|
25
25
|
ValidationError: () => import_utils.ValidationError,
|
|
26
|
+
addSecondsToDate: () => import_utils.addSecondsToDate,
|
|
27
|
+
dateToSeconds: () => import_utils.dateToSeconds,
|
|
28
|
+
decodeUtf8String: () => import_utils.decodeUtf8String,
|
|
29
|
+
encodeToBase64Url: () => import_utils.encodeToBase64Url,
|
|
26
30
|
hasStatusOrThrow: () => hasStatusOrThrow,
|
|
27
31
|
parseRawHttpResponse: () => parseRawHttpResponse,
|
|
32
|
+
parseWithErrorHandling: () => import_utils.parseWithErrorHandling,
|
|
28
33
|
serializeAttrs: () => serializeAttrs
|
|
29
34
|
});
|
|
30
35
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -72,8 +77,13 @@ var import_utils = require("@openid4vc/utils");
|
|
|
72
77
|
JsonParseError,
|
|
73
78
|
UnexpectedStatusCodeError,
|
|
74
79
|
ValidationError,
|
|
80
|
+
addSecondsToDate,
|
|
81
|
+
dateToSeconds,
|
|
82
|
+
decodeUtf8String,
|
|
83
|
+
encodeToBase64Url,
|
|
75
84
|
hasStatusOrThrow,
|
|
76
85
|
parseRawHttpResponse,
|
|
86
|
+
parseWithErrorHandling,
|
|
77
87
|
serializeAttrs
|
|
78
88
|
});
|
|
79
89
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/fetcher.ts"],"sourcesContent":["export * from \"./errors\";\nexport * from \"./fetcher\";\n\nexport { JsonParseError
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/fetcher.ts"],"sourcesContent":["export * 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","// 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;;;ACaO,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;;;ACtCO,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;;;AF5BpB,mBASO;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -35,13 +35,26 @@ var hasStatusOrThrow = (status, customError) => async (res) => {
|
|
|
35
35
|
var parseRawHttpResponse = (response) => response.headers.get("content-type")?.includes("application/json") ? response.json() : response.text();
|
|
36
36
|
|
|
37
37
|
// src/index.ts
|
|
38
|
-
import {
|
|
38
|
+
import {
|
|
39
|
+
JsonParseError,
|
|
40
|
+
ValidationError,
|
|
41
|
+
addSecondsToDate,
|
|
42
|
+
dateToSeconds,
|
|
43
|
+
decodeUtf8String,
|
|
44
|
+
encodeToBase64Url,
|
|
45
|
+
parseWithErrorHandling
|
|
46
|
+
} from "@openid4vc/utils";
|
|
39
47
|
export {
|
|
40
48
|
JsonParseError,
|
|
41
49
|
UnexpectedStatusCodeError,
|
|
42
50
|
ValidationError,
|
|
51
|
+
addSecondsToDate,
|
|
52
|
+
dateToSeconds,
|
|
53
|
+
decodeUtf8String,
|
|
54
|
+
encodeToBase64Url,
|
|
43
55
|
hasStatusOrThrow,
|
|
44
56
|
parseRawHttpResponse,
|
|
57
|
+
parseWithErrorHandling,
|
|
45
58
|
serializeAttrs
|
|
46
59
|
};
|
|
47
60
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/fetcher.ts","../src/index.ts"],"sourcesContent":["// 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 \"./errors\";\nexport * from \"./fetcher\";\n\nexport { JsonParseError
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/fetcher.ts","../src/index.ts"],"sourcesContent":["// 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 \"./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":";AAaO,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,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+29,7 @@
|
|
|
29
29
|
"@openid4vc/utils": "0.3.0-alpha-20250714110838"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
|
-
"build": "tsup src/index.ts --format cjs,esm --dts --
|
|
32
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --sourcemap",
|
|
33
33
|
"test": "vitest"
|
|
34
34
|
}
|
|
35
35
|
}
|