@carecard/common-util 1.0.1 → 2.0.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/index.js +5 -0
- package/lib/appErrorHandlers.js +297 -0
- package/{dist/esm → lib}/responseStatus.js +18 -7
- package/lib/untilityFunctions.js +18 -0
- package/package.json +13 -45
- package/readme.md +6 -2
- package/dist/cjs/appErrorHandlers.cjs +0 -179
- package/dist/cjs/appErrorHandlers.d.ts +0 -128
- package/dist/cjs/index.cjs +0 -19
- package/dist/cjs/index.d.ts +0 -3
- package/dist/cjs/responseStatus.cjs +0 -71
- package/dist/cjs/responseStatus.d.ts +0 -65
- package/dist/cjs/utilityFunctions.cjs +0 -30
- package/dist/cjs/utilityFunctions.d.ts +0 -9
- package/dist/esm/appErrorHandlers.d.ts +0 -128
- package/dist/esm/appErrorHandlers.js +0 -156
- package/dist/esm/index.d.ts +0 -3
- package/dist/esm/index.js +0 -3
- package/dist/esm/responseStatus.d.ts +0 -65
- package/dist/esm/utilityFunctions.d.ts +0 -9
- package/dist/esm/utilityFunctions.js +0 -27
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The ETag (or entity tag) HTTP response header is an identifier for a specific version of a resource.
|
|
3
|
-
* It lets caches be more efficient and save bandwidth, as a web server does not need to resend a full
|
|
4
|
-
* response if the content was not changed. Additionally, etags help to prevent simultaneous updates of
|
|
5
|
-
* a resource from overwriting each other ("mid-air collisions").
|
|
6
|
-
*
|
|
7
|
-
* If the resource at a given URL changes, a new Etag value must be generated. A comparison of them can
|
|
8
|
-
* determine whether two representations of a resource are the same. Etags are therefore similar to fingerprints, a
|
|
9
|
-
* nd might also be used for tracking purposes by some servers. They might also be set to persist indefinitely
|
|
10
|
-
* by a tracking server.
|
|
11
|
-
*
|
|
12
|
-
* For example, when editing a wiki, the current wiki content may be hashed and put into an Etag header
|
|
13
|
-
* in the response:
|
|
14
|
-
*
|
|
15
|
-
* ETag: "33a64df551425fcc55e4d42a148795d9f25f89d4"
|
|
16
|
-
*
|
|
17
|
-
* When saving changes to a wiki page (posting data), the POST request will contain the If-Match header containing
|
|
18
|
-
* the ETag values to check freshness against.
|
|
19
|
-
*
|
|
20
|
-
* If-Match: "33a64df551425fcc55e4d42a148795d9f25f89d4"
|
|
21
|
-
*
|
|
22
|
-
* If the hashes don't match, it means that the document has been edited in-between and a 412 Precondition Failed
|
|
23
|
-
* error is thrown.
|
|
24
|
-
*
|
|
25
|
-
* @param res
|
|
26
|
-
* @param ETag
|
|
27
|
-
* @returns {*}
|
|
28
|
-
*/
|
|
29
|
-
export declare function setOk200(res: {
|
|
30
|
-
set: (arg0: {
|
|
31
|
-
ETag: any;
|
|
32
|
-
}) => void;
|
|
33
|
-
status: (arg0: number) => void;
|
|
34
|
-
}, ETag: any): any;
|
|
35
|
-
/**
|
|
36
|
-
* The 201 (Created) status code indicates that the request has been
|
|
37
|
-
* fulfilled and has resulted in one or more new resources being
|
|
38
|
-
* created. The primary resource created by the request is identified
|
|
39
|
-
* by either a Location header field in the response or, if no Location
|
|
40
|
-
* field is received, by the effective request URI.
|
|
41
|
-
*
|
|
42
|
-
* The 201 response payload typically describes and links to the
|
|
43
|
-
* resource(s) created. See
|
|
44
|
-
* https://datatracker.ietf.org/doc/html/rfc7231#section-7.2
|
|
45
|
-
* for a discussion of the meaning and purpose of validator header
|
|
46
|
-
* fields, such as ETag and Last-Modified, in a 201 response.
|
|
47
|
-
*
|
|
48
|
-
* @param res
|
|
49
|
-
* @returns {*}
|
|
50
|
-
*/
|
|
51
|
-
export declare function setCreated201(res: {
|
|
52
|
-
status: (arg0: number) => void;
|
|
53
|
-
}): any;
|
|
54
|
-
/**
|
|
55
|
-
* The 400 (Bad Request) status code indicates that the server cannot or
|
|
56
|
-
* will not process the request due to something that is perceived to be
|
|
57
|
-
* a client error (e.g., malformed request syntax, invalid request
|
|
58
|
-
* message framing, or deceptive request routing).
|
|
59
|
-
*
|
|
60
|
-
* @param res
|
|
61
|
-
* @returns {*}
|
|
62
|
-
*/
|
|
63
|
-
export declare function setBadRequest400ClientError(res: {
|
|
64
|
-
status: (arg0: number) => void;
|
|
65
|
-
}): any;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Create a new object containing only the properties listed in `arrayOfProperties`.
|
|
3
|
-
* Keeps the original behavior: only copies properties whose values are truthy.
|
|
4
|
-
*
|
|
5
|
-
* Example:
|
|
6
|
-
* extractObjectWithProperties({ a: 1, b: 0, c: 'x' }, ['a', 'b', 'c'])
|
|
7
|
-
* -> { a: 1, c: 'x' } // 'b' is omitted because 0 is falsy
|
|
8
|
-
*/
|
|
9
|
-
export declare function extractObjectWithProperties<T extends Record<string, unknown>, K extends keyof T>(obj: T | null | undefined, arrayOfProperties: ReadonlyArray<K>): Partial<Pick<T, K>>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// src/utilityFunctions.ts
|
|
2
|
-
/**
|
|
3
|
-
* Create a new object containing only the properties listed in `arrayOfProperties`.
|
|
4
|
-
* Keeps the original behavior: only copies properties whose values are truthy.
|
|
5
|
-
*
|
|
6
|
-
* Example:
|
|
7
|
-
* extractObjectWithProperties({ a: 1, b: 0, c: 'x' }, ['a', 'b', 'c'])
|
|
8
|
-
* -> { a: 1, c: 'x' } // 'b' is omitted because 0 is falsy
|
|
9
|
-
*/
|
|
10
|
-
export function extractObjectWithProperties(obj, arrayOfProperties) {
|
|
11
|
-
// Initialize with the correct type to avoid "element implicitly has an 'any' type"
|
|
12
|
-
const returnObj = {};
|
|
13
|
-
// If obj is null/undefined, return an empty object
|
|
14
|
-
if (!obj) {
|
|
15
|
-
return returnObj;
|
|
16
|
-
}
|
|
17
|
-
// Iterate using `for...of` to avoid lib/target issues with Array.prototype.find for older configs
|
|
18
|
-
for (const nameOfProperty of arrayOfProperties) {
|
|
19
|
-
const value = obj[nameOfProperty];
|
|
20
|
-
// Preserve original "truthy" filter: only copy if value is truthy
|
|
21
|
-
if (value) {
|
|
22
|
-
// Assign with proper typing
|
|
23
|
-
returnObj[nameOfProperty] = value;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return returnObj;
|
|
27
|
-
}
|