@pagopa/io-wallet-utils 0.4.1 → 0.4.2
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 +42 -0
- package/dist/index.d.ts +42 -0
- package/package.json +7 -7
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export { JsonParseError, ValidationError } from '@openid4vc/utils';
|
|
2
|
+
|
|
3
|
+
type GenericErrorReason = Record<string, unknown> | string;
|
|
4
|
+
/**
|
|
5
|
+
* utility to format a set of attributes into an error message string
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* // returns "foo=value bar=(list, item)"
|
|
9
|
+
* serializeAttrs({ foo: "value", bar: ["list", "item"] })
|
|
10
|
+
*
|
|
11
|
+
* @param attrs A key value record set
|
|
12
|
+
* @returns a human-readable serialization of the set
|
|
13
|
+
*/
|
|
14
|
+
declare const serializeAttrs: (attrs: Record<string, GenericErrorReason | number | string[] | undefined>) => string;
|
|
15
|
+
/**
|
|
16
|
+
* An error subclass thrown when an HTTP request has a status code different from the one expected.
|
|
17
|
+
*/
|
|
18
|
+
declare class UnexpectedStatusCodeError extends Error {
|
|
19
|
+
code: string;
|
|
20
|
+
reason: GenericErrorReason;
|
|
21
|
+
statusCode: number;
|
|
22
|
+
constructor({ message, reason, statusCode, }: {
|
|
23
|
+
message: string;
|
|
24
|
+
reason: GenericErrorReason;
|
|
25
|
+
statusCode: number;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Check if a response is in the expected status, otherwise throw an error
|
|
31
|
+
* @param status - The expected status
|
|
32
|
+
* @param customError - A custom error compatible with {@link UnexpectedStatusCodeError}
|
|
33
|
+
* @throws UnexpectedStatusCodeError if the status is different from the one expected
|
|
34
|
+
* @returns The given response object
|
|
35
|
+
*/
|
|
36
|
+
declare const hasStatusOrThrow: (status: number, customError?: typeof UnexpectedStatusCodeError) => (res: Response) => Promise<Response>;
|
|
37
|
+
/**
|
|
38
|
+
* Utility function to parse a raw HTTP response as JSON if supported, otherwise as text.
|
|
39
|
+
*/
|
|
40
|
+
declare const parseRawHttpResponse: <T extends Record<string, unknown>>(response: Response) => Promise<T> | Promise<string>;
|
|
41
|
+
|
|
42
|
+
export { UnexpectedStatusCodeError, hasStatusOrThrow, parseRawHttpResponse, serializeAttrs };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export { JsonParseError, ValidationError } from '@openid4vc/utils';
|
|
2
|
+
|
|
3
|
+
type GenericErrorReason = Record<string, unknown> | string;
|
|
4
|
+
/**
|
|
5
|
+
* utility to format a set of attributes into an error message string
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* // returns "foo=value bar=(list, item)"
|
|
9
|
+
* serializeAttrs({ foo: "value", bar: ["list", "item"] })
|
|
10
|
+
*
|
|
11
|
+
* @param attrs A key value record set
|
|
12
|
+
* @returns a human-readable serialization of the set
|
|
13
|
+
*/
|
|
14
|
+
declare const serializeAttrs: (attrs: Record<string, GenericErrorReason | number | string[] | undefined>) => string;
|
|
15
|
+
/**
|
|
16
|
+
* An error subclass thrown when an HTTP request has a status code different from the one expected.
|
|
17
|
+
*/
|
|
18
|
+
declare class UnexpectedStatusCodeError extends Error {
|
|
19
|
+
code: string;
|
|
20
|
+
reason: GenericErrorReason;
|
|
21
|
+
statusCode: number;
|
|
22
|
+
constructor({ message, reason, statusCode, }: {
|
|
23
|
+
message: string;
|
|
24
|
+
reason: GenericErrorReason;
|
|
25
|
+
statusCode: number;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Check if a response is in the expected status, otherwise throw an error
|
|
31
|
+
* @param status - The expected status
|
|
32
|
+
* @param customError - A custom error compatible with {@link UnexpectedStatusCodeError}
|
|
33
|
+
* @throws UnexpectedStatusCodeError if the status is different from the one expected
|
|
34
|
+
* @returns The given response object
|
|
35
|
+
*/
|
|
36
|
+
declare const hasStatusOrThrow: (status: number, customError?: typeof UnexpectedStatusCodeError) => (res: Response) => Promise<Response>;
|
|
37
|
+
/**
|
|
38
|
+
* Utility function to parse a raw HTTP response as JSON if supported, otherwise as text.
|
|
39
|
+
*/
|
|
40
|
+
declare const parseRawHttpResponse: <T extends Record<string, unknown>>(response: Response) => Promise<T> | Promise<string>;
|
|
41
|
+
|
|
42
|
+
export { UnexpectedStatusCodeError, hasStatusOrThrow, parseRawHttpResponse, serializeAttrs };
|
package/package.json
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagopa/io-wallet-utils",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist"
|
|
6
6
|
],
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/index.mjs",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
8
11
|
"exports": {
|
|
9
12
|
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
10
14
|
"import": "./dist/index.mjs",
|
|
11
|
-
"require": "./dist/index.js"
|
|
12
|
-
"types": "./dist/index.d.ts"
|
|
15
|
+
"require": "./dist/index.js"
|
|
13
16
|
},
|
|
14
17
|
"./package.json": "./package.json"
|
|
15
18
|
},
|
|
@@ -28,8 +31,5 @@
|
|
|
28
31
|
"scripts": {
|
|
29
32
|
"build": "tsup src/index.ts --format cjs,esm --dts --clean --sourcemap",
|
|
30
33
|
"test": "vitest"
|
|
31
|
-
}
|
|
32
|
-
"main": "./dist/index.js",
|
|
33
|
-
"module": "./dist/index.mjs",
|
|
34
|
-
"types": "./dist/index.d.ts"
|
|
34
|
+
}
|
|
35
35
|
}
|