@digitraffic/common 2026.3.17-1 → 2026.3.26-1-beta
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/README.md +18 -1
- package/dist/__test__/asserter.d.ts +13 -0
- package/dist/__test__/asserter.js +39 -0
- package/dist/__test__/db-testutils.d.ts +3 -0
- package/dist/__test__/db-testutils.js +38 -0
- package/dist/__test__/dependencies.test.d.ts +1 -0
- package/dist/__test__/dependencies.test.js +21 -0
- package/dist/__test__/imports.test.d.ts +1 -0
- package/dist/__test__/imports.test.js +318 -0
- package/dist/__test__/infra/acl-builder.test.d.ts +1 -0
- package/dist/__test__/infra/acl-builder.test.js +72 -0
- package/dist/__test__/infra/api/handler-factory.test.d.ts +1 -0
- package/dist/__test__/infra/api/handler-factory.test.js +42 -0
- package/dist/__test__/infra/api/integration.test.d.ts +1 -0
- package/dist/__test__/infra/api/integration.test.js +162 -0
- package/dist/__test__/infra/api/response.test.d.ts +1 -0
- package/dist/__test__/infra/api/response.test.js +77 -0
- package/dist/__test__/infra/api/static-integration.test.d.ts +1 -0
- package/dist/__test__/infra/api/static-integration.test.js +35 -0
- package/dist/__test__/infra/documentation.test.d.ts +1 -0
- package/dist/__test__/infra/documentation.test.js +38 -0
- package/dist/__test__/infra/scheduler.test.d.ts +1 -0
- package/dist/__test__/infra/scheduler.test.js +23 -0
- package/dist/__test__/infra/security-rule.test.d.ts +1 -0
- package/dist/__test__/infra/security-rule.test.js +21 -0
- package/dist/__test__/infra/stack/rest-apis.test.d.ts +1 -0
- package/dist/__test__/infra/stack/rest-apis.test.js +47 -0
- package/dist/__test__/marine/id_utils.test.d.ts +1 -0
- package/dist/__test__/marine/id_utils.test.js +45 -0
- package/dist/__test__/mock-ky.d.ts +2 -0
- package/dist/__test__/mock-ky.js +15 -0
- package/dist/__test__/promise/promise.test.d.ts +1 -0
- package/dist/__test__/promise/promise.test.js +126 -0
- package/dist/__test__/runtime/dt-logger.test.d.ts +1 -0
- package/dist/__test__/runtime/dt-logger.test.js +193 -0
- package/dist/__test__/secrets/secret-holder.test.d.ts +1 -0
- package/dist/__test__/secrets/secret-holder.test.js +96 -0
- package/dist/__test__/secrets/secret.test.d.ts +1 -0
- package/dist/__test__/secrets/secret.test.js +57 -0
- package/dist/__test__/stack/dt-function.test.d.ts +1 -0
- package/dist/__test__/stack/dt-function.test.js +340 -0
- package/dist/__test__/stack/rest-apis.test.d.ts +1 -0
- package/dist/__test__/stack/rest-apis.test.js +45 -0
- package/dist/__test__/test/mock-ky.test.d.ts +1 -0
- package/dist/__test__/test/mock-ky.test.js +46 -0
- package/dist/__test__/testutils.d.ts +12 -0
- package/dist/__test__/testutils.js +32 -0
- package/dist/__test__/types/lambda-proxy-types.test.d.ts +8 -0
- package/dist/__test__/types/lambda-proxy-types.test.js +155 -0
- package/dist/__test__/types/lambda-response-builder.test.d.ts +1 -0
- package/dist/__test__/types/lambda-response-builder.test.js +81 -0
- package/dist/__test__/types/lambda-response.test.d.ts +9 -0
- package/dist/__test__/types/lambda-response.test.js +73 -0
- package/dist/__test__/utils/base64.test.d.ts +1 -0
- package/dist/__test__/utils/base64.test.js +38 -0
- package/dist/__test__/utils/date-utils.test.d.ts +1 -0
- package/dist/__test__/utils/date-utils.test.js +32 -0
- package/dist/__test__/utils/geometry.test.d.ts +1 -0
- package/dist/__test__/utils/geometry.test.js +25 -0
- package/dist/__test__/utils/lambda-proxy-event.test.d.ts +1 -0
- package/dist/__test__/utils/lambda-proxy-event.test.js +45 -0
- package/dist/__test__/utils/logging.test.d.ts +1 -0
- package/dist/__test__/utils/logging.test.js +75 -0
- package/dist/__test__/utils/stop-watch.test.d.ts +1 -0
- package/dist/__test__/utils/stop-watch.test.js +118 -0
- package/dist/__test__/utils/utils.test.d.ts +1 -0
- package/dist/__test__/utils/utils.test.js +48 -0
- package/dist/aws/infra/acl-builder.d.ts +53 -0
- package/dist/aws/infra/acl-builder.js +407 -0
- package/dist/aws/infra/api/handler-factory.d.ts +22 -0
- package/dist/aws/infra/api/handler-factory.js +68 -0
- package/dist/aws/infra/api/integration.d.ts +49 -0
- package/dist/aws/infra/api/integration.js +162 -0
- package/dist/aws/infra/api/response.d.ts +62 -0
- package/dist/aws/infra/api/response.js +132 -0
- package/dist/aws/infra/api/responses.d.ts +60 -0
- package/dist/aws/infra/api/responses.js +90 -0
- package/dist/aws/infra/api/static-integration.d.ts +16 -0
- package/dist/aws/infra/api/static-integration.js +76 -0
- package/dist/aws/infra/bucket-policy.d.ts +38 -0
- package/dist/aws/infra/bucket-policy.js +30 -0
- package/dist/aws/infra/canaries/canary-alarm.d.ts +6 -0
- package/dist/aws/infra/canaries/canary-alarm.js +20 -0
- package/dist/aws/infra/canaries/canary-keys.d.ts +3 -0
- package/dist/aws/infra/canaries/canary-keys.js +4 -0
- package/dist/aws/infra/canaries/canary-parameters.d.ts +19 -0
- package/dist/aws/infra/canaries/canary-parameters.js +2 -0
- package/dist/aws/infra/canaries/canary-role.d.ts +14 -0
- package/dist/aws/infra/canaries/canary-role.js +51 -0
- package/dist/aws/infra/canaries/canary.d.ts +8 -0
- package/dist/aws/infra/canaries/canary.js +26 -0
- package/dist/aws/infra/canaries/database-canary.d.ts +17 -0
- package/dist/aws/infra/canaries/database-canary.js +65 -0
- package/dist/aws/infra/canaries/database-checker.d.ts +33 -0
- package/dist/aws/infra/canaries/database-checker.js +119 -0
- package/dist/aws/infra/canaries/url-canary.d.ts +16 -0
- package/dist/aws/infra/canaries/url-canary.js +55 -0
- package/dist/aws/infra/canaries/url-checker.d.ts +45 -0
- package/dist/aws/infra/canaries/url-checker.js +256 -0
- package/dist/aws/infra/documentation.d.ts +56 -0
- package/dist/aws/infra/documentation.js +90 -0
- package/dist/aws/infra/import-util.d.ts +17 -0
- package/dist/aws/infra/import-util.js +41 -0
- package/dist/aws/infra/scheduler.d.ts +12 -0
- package/dist/aws/infra/scheduler.js +27 -0
- package/dist/aws/infra/security-rule.d.ts +12 -0
- package/dist/aws/infra/security-rule.js +35 -0
- package/dist/aws/infra/sqs-integration.d.ts +4 -0
- package/dist/aws/infra/sqs-integration.js +85 -0
- package/dist/aws/infra/sqs-queue.d.ts +19 -0
- package/dist/aws/infra/sqs-queue.js +145 -0
- package/dist/aws/infra/stack/dt-function-alarms.d.ts +29 -0
- package/dist/aws/infra/stack/dt-function-alarms.js +54 -0
- package/dist/aws/infra/stack/dt-function.d.ts +124 -0
- package/dist/aws/infra/stack/dt-function.js +315 -0
- package/dist/aws/infra/stack/lambda-configs.d.ts +44 -0
- package/dist/aws/infra/stack/lambda-configs.js +71 -0
- package/dist/aws/infra/stack/lambda-log-group.d.ts +15 -0
- package/dist/aws/infra/stack/lambda-log-group.js +24 -0
- package/dist/aws/infra/stack/monitoredfunction.d.ts +85 -0
- package/dist/aws/infra/stack/monitoredfunction.js +147 -0
- package/dist/aws/infra/stack/parameters.d.ts +40 -0
- package/dist/aws/infra/stack/parameters.js +50 -0
- package/dist/aws/infra/stack/rest-api.d.ts +74 -0
- package/dist/aws/infra/stack/rest-api.js +235 -0
- package/dist/aws/infra/stack/stack-checking-aspect.d.ts +20 -0
- package/dist/aws/infra/stack/stack-checking-aspect.js +183 -0
- package/dist/aws/infra/stack/stack.d.ts +56 -0
- package/dist/aws/infra/stack/stack.js +71 -0
- package/dist/aws/infra/stack/subscription.d.ts +17 -0
- package/dist/aws/infra/stack/subscription.js +37 -0
- package/dist/aws/infra/stacks/db-dns-stack.d.ts +13 -0
- package/dist/aws/infra/stacks/db-dns-stack.js +60 -0
- package/dist/aws/infra/stacks/db-proxy-stack.d.ts +24 -0
- package/dist/aws/infra/stacks/db-proxy-stack.js +74 -0
- package/dist/aws/infra/stacks/db-stack.d.ts +65 -0
- package/dist/aws/infra/stacks/db-stack.js +189 -0
- package/dist/aws/infra/stacks/intra-stack-configuration.d.ts +5 -0
- package/dist/aws/infra/stacks/intra-stack-configuration.js +2 -0
- package/dist/aws/infra/stacks/network-stack.d.ts +14 -0
- package/dist/aws/infra/stacks/network-stack.js +45 -0
- package/dist/aws/infra/usage-plans.d.ts +16 -0
- package/dist/aws/infra/usage-plans.js +38 -0
- package/dist/aws/runtime/apikey.d.ts +2 -0
- package/dist/aws/runtime/apikey.js +13 -0
- package/dist/aws/runtime/digitraffic-integration-response.d.ts +8 -0
- package/dist/aws/runtime/digitraffic-integration-response.js +25 -0
- package/dist/aws/runtime/dt-logger-default.d.ts +9 -0
- package/dist/aws/runtime/dt-logger-default.js +6 -0
- package/dist/aws/runtime/dt-logger.d.ts +117 -0
- package/dist/aws/runtime/dt-logger.js +159 -0
- package/dist/aws/runtime/environment.d.ts +5 -0
- package/dist/aws/runtime/environment.js +7 -0
- package/dist/aws/runtime/s3.d.ts +3 -0
- package/dist/aws/runtime/s3.js +21 -0
- package/dist/aws/runtime/secrets/dbsecret.d.ts +16 -0
- package/dist/aws/runtime/secrets/dbsecret.js +26 -0
- package/dist/aws/runtime/secrets/proxy-holder.d.ts +9 -0
- package/dist/aws/runtime/secrets/proxy-holder.js +25 -0
- package/dist/aws/runtime/secrets/rds-holder.d.ts +9 -0
- package/dist/aws/runtime/secrets/rds-holder.js +25 -0
- package/dist/aws/runtime/secrets/secret-holder.d.ts +30 -0
- package/dist/aws/runtime/secrets/secret-holder.js +81 -0
- package/dist/aws/runtime/secrets/secret.d.ts +8 -0
- package/dist/aws/runtime/secrets/secret.js +61 -0
- package/dist/aws/types/errors.d.ts +8 -0
- package/dist/aws/types/errors.js +13 -0
- package/dist/aws/types/lambda-proxy-types.d.ts +59 -0
- package/dist/aws/types/lambda-proxy-types.js +210 -0
- package/dist/aws/types/lambda-response.d.ts +89 -0
- package/dist/aws/types/lambda-response.js +204 -0
- package/dist/aws/types/mediatypes.d.ts +11 -0
- package/dist/aws/types/mediatypes.js +14 -0
- package/dist/aws/types/model-with-reference.d.ts +7 -0
- package/dist/aws/types/model-with-reference.js +2 -0
- package/dist/aws/types/tags.d.ts +2 -0
- package/dist/aws/types/tags.js +4 -0
- package/dist/database/database.d.ts +27 -0
- package/dist/database/database.js +95 -0
- package/dist/database/last-updated.d.ts +15 -0
- package/dist/database/last-updated.js +46 -0
- package/dist/database/models.d.ts +6 -0
- package/dist/database/models.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/marine/id_utils.d.ts +3 -0
- package/dist/marine/id_utils.js +36 -0
- package/dist/marine/rtz.d.ts +48 -0
- package/dist/marine/rtz.js +2 -0
- package/dist/types/async-timeout-error.d.ts +3 -0
- package/dist/types/async-timeout-error.js +6 -0
- package/dist/types/either.d.ts +9 -0
- package/dist/types/either.js +2 -0
- package/dist/types/geojson.d.ts +47 -0
- package/dist/types/geojson.js +51 -0
- package/dist/types/http-error.d.ts +4 -0
- package/dist/types/http-error.js +8 -0
- package/dist/types/input-error.d.ts +2 -0
- package/dist/types/input-error.js +3 -0
- package/dist/types/language.d.ts +5 -0
- package/dist/types/language.js +7 -0
- package/dist/types/nullable.d.ts +24 -0
- package/dist/types/nullable.js +2 -0
- package/dist/types/openapi-schema.d.ts +932 -0
- package/dist/types/openapi-schema.js +151 -0
- package/dist/types/traffictype.d.ts +11 -0
- package/dist/types/traffictype.js +13 -0
- package/dist/types/urn.d.ts +1 -0
- package/dist/types/urn.js +2 -0
- package/dist/types/util-types.d.ts +11 -0
- package/dist/types/util-types.js +2 -0
- package/dist/types/validator.d.ts +4 -0
- package/dist/types/validator.js +9 -0
- package/dist/utils/api-model.d.ts +51 -0
- package/dist/utils/api-model.js +118 -0
- package/dist/utils/base64.d.ts +34 -0
- package/dist/utils/base64.js +53 -0
- package/dist/utils/date-utils.d.ts +27 -0
- package/dist/utils/date-utils.js +45 -0
- package/dist/utils/geojson-types.d.ts +14 -0
- package/dist/utils/geojson-types.js +15 -0
- package/dist/utils/geometry.d.ts +44 -0
- package/dist/utils/geometry.js +154 -0
- package/dist/utils/lambda-proxy-event.d.ts +9 -0
- package/dist/utils/lambda-proxy-event.js +31 -0
- package/dist/utils/logging.d.ts +40 -0
- package/dist/utils/logging.js +88 -0
- package/dist/utils/retry.d.ts +33 -0
- package/dist/utils/retry.js +135 -0
- package/dist/utils/slack.d.ts +5 -0
- package/dist/utils/slack.js +24 -0
- package/dist/utils/stop-watch.d.ts +46 -0
- package/dist/utils/stop-watch.js +114 -0
- package/dist/utils/utils.d.ts +95 -0
- package/dist/utils/utils.js +178 -0
- package/dist/utils/zod-utils.d.ts +27 -0
- package/dist/utils/zod-utils.js +57 -0
- package/package.json +30 -28
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { Either } from "../types/either.js";
|
|
2
|
+
/**
|
|
3
|
+
* Check if arrays have only elements that also exists also in other array.
|
|
4
|
+
* Individual element count doesn't matter.
|
|
5
|
+
* Function works only for primitive types and for other it just checks the reference to object.
|
|
6
|
+
*
|
|
7
|
+
* Some examples
|
|
8
|
+
* bothArraysHasSameValues( [a, b], [b, a] ) => true
|
|
9
|
+
* bothArraysHasSameValues( [a, a], [a, a, a] ) => true
|
|
10
|
+
* bothArraysHasSameValues( [a, b], [a] ) => false
|
|
11
|
+
*
|
|
12
|
+
* Object references:
|
|
13
|
+
* const o1 = { a: 1, b: 2};
|
|
14
|
+
* const o2 = { a: 1, b: 2};
|
|
15
|
+
* // Arrays has references to same objects
|
|
16
|
+
* bothArraysHasSameValues([o1], [o1])) => true
|
|
17
|
+
* Arrays have references to different objects
|
|
18
|
+
* bothArraysHasSameValues([o1], [o2])) => false
|
|
19
|
+
*
|
|
20
|
+
* @param a first array to compare
|
|
21
|
+
* @param b second array to compare
|
|
22
|
+
*/
|
|
23
|
+
export declare function bothArraysHasSameValues(a: null | undefined | unknown[], b: null | undefined | unknown[]): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the last item on the array. If the array is empty, throws an error!
|
|
26
|
+
*/
|
|
27
|
+
export declare function getLast<T>(array: T[], sortFunction?: (a: T) => number): T;
|
|
28
|
+
/**
|
|
29
|
+
* Returns the first item on the array. If the array is empty, throws an error!
|
|
30
|
+
*/
|
|
31
|
+
export declare function getFirst<T>(array: T[], sortFunction?: (a: T) => number): T;
|
|
32
|
+
/**
|
|
33
|
+
* Gets environment variable. Throws error if variable is not found.
|
|
34
|
+
*
|
|
35
|
+
* @param key Environment key
|
|
36
|
+
* @return string
|
|
37
|
+
*/
|
|
38
|
+
export declare function getEnvVariable(key: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Gets environment variable. Safe version returns object with either ok or error status.
|
|
41
|
+
* Easier to use for recovery than catching an error.
|
|
42
|
+
*
|
|
43
|
+
* @param key Environment key
|
|
44
|
+
* @return Either<string>
|
|
45
|
+
*/
|
|
46
|
+
export declare function getEnvVariableSafe(key: string): Either<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Sets environment variable.
|
|
49
|
+
*
|
|
50
|
+
* @param key Environment key
|
|
51
|
+
* @param value Environment variable value
|
|
52
|
+
*/
|
|
53
|
+
export declare function setEnvVariable(key: string, value: string): void;
|
|
54
|
+
export declare function setEnvVariableAwsRegion(value: string): void;
|
|
55
|
+
/**
|
|
56
|
+
* Gets environment variable. If environment variable is undefined, returns value of given function.
|
|
57
|
+
*
|
|
58
|
+
* @param key Environment key
|
|
59
|
+
* @param fn Alternative function
|
|
60
|
+
*/
|
|
61
|
+
export declare function getEnvVariableOr<T>(key: string, fn: () => T): string | T;
|
|
62
|
+
/**
|
|
63
|
+
* Gets environment variable. If environment variable is undefined, returns given value.
|
|
64
|
+
* Use to return an explicit alternative value e.g. in cases where environment variable may be undefined.
|
|
65
|
+
*
|
|
66
|
+
* @param key Environment key
|
|
67
|
+
* @param orElse Alternative value
|
|
68
|
+
*/
|
|
69
|
+
export declare function getEnvVariableOrElse<T>(key: string, orElse: T): string | T;
|
|
70
|
+
export declare function setSecretOverideAwsRegionEnv(region: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* ESLint won't allow to call Object.prototype builtin methods.
|
|
73
|
+
* To call hasOwnProperty we must use Object.prototype.hasOwnProperty.call()
|
|
74
|
+
* @param object to test for property
|
|
75
|
+
* @param propertyName property name to check
|
|
76
|
+
* @see https://eslint.org/docs/latest/rules/no-prototype-builtins
|
|
77
|
+
*/
|
|
78
|
+
export declare function hasOwnPropertySafe(object: object, propertyName: string): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Return an error message from the given object hat might be an Error object.
|
|
81
|
+
* @param maybeError
|
|
82
|
+
*/
|
|
83
|
+
export declare function getErrorMessage(maybeError: unknown): string;
|
|
84
|
+
/**
|
|
85
|
+
* @param value
|
|
86
|
+
*/
|
|
87
|
+
export declare function isDefined<T>(value: T | undefined | null): value is T;
|
|
88
|
+
/**
|
|
89
|
+
* Omits a key from an object deeply (also in nested objects). Creates and returns new object.
|
|
90
|
+
*
|
|
91
|
+
* @param obj Object to omit from
|
|
92
|
+
* @param keysToOmit Keys to omit
|
|
93
|
+
* @returns New same type of object as that was given as input but with the keys omitted.
|
|
94
|
+
*/
|
|
95
|
+
export declare function omitDeep<T>(obj: T, ...keysToOmit: readonly string[]): T;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { forIn, isObject } from "es-toolkit/compat";
|
|
2
|
+
import { EnvKeys } from "../aws/runtime/environment.js";
|
|
3
|
+
/**
|
|
4
|
+
* Check if arrays have only elements that also exists also in other array.
|
|
5
|
+
* Individual element count doesn't matter.
|
|
6
|
+
* Function works only for primitive types and for other it just checks the reference to object.
|
|
7
|
+
*
|
|
8
|
+
* Some examples
|
|
9
|
+
* bothArraysHasSameValues( [a, b], [b, a] ) => true
|
|
10
|
+
* bothArraysHasSameValues( [a, a], [a, a, a] ) => true
|
|
11
|
+
* bothArraysHasSameValues( [a, b], [a] ) => false
|
|
12
|
+
*
|
|
13
|
+
* Object references:
|
|
14
|
+
* const o1 = { a: 1, b: 2};
|
|
15
|
+
* const o2 = { a: 1, b: 2};
|
|
16
|
+
* // Arrays has references to same objects
|
|
17
|
+
* bothArraysHasSameValues([o1], [o1])) => true
|
|
18
|
+
* Arrays have references to different objects
|
|
19
|
+
* bothArraysHasSameValues([o1], [o2])) => false
|
|
20
|
+
*
|
|
21
|
+
* @param a first array to compare
|
|
22
|
+
* @param b second array to compare
|
|
23
|
+
*/
|
|
24
|
+
export function bothArraysHasSameValues(a, b) {
|
|
25
|
+
if ((a && !b) || (!a && b)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
else if (!a && !b) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
const aSet = new Set(a);
|
|
32
|
+
const bSet = new Set(b);
|
|
33
|
+
if (aSet.size !== bSet.size) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return Array.from(aSet).every((value) => bSet.has(value));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns the last item on the array. If the array is empty, throws an error!
|
|
40
|
+
*/
|
|
41
|
+
export function getLast(array, sortFunction) {
|
|
42
|
+
return getFirstOrLast(false, array, sortFunction);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Returns the first item on the array. If the array is empty, throws an error!
|
|
46
|
+
*/
|
|
47
|
+
export function getFirst(array, sortFunction) {
|
|
48
|
+
return getFirstOrLast(true, array, sortFunction);
|
|
49
|
+
}
|
|
50
|
+
function getFirstOrLast(getFirst, array, sortFunction) {
|
|
51
|
+
if (array.length === 0) {
|
|
52
|
+
throw new Error(`can't get ${getFirst ? "first" : "last"} from empty array!`);
|
|
53
|
+
}
|
|
54
|
+
const index = getFirst ? 0 : array.length - 1;
|
|
55
|
+
if (sortFunction) {
|
|
56
|
+
return array.sort(sortFunction)[index];
|
|
57
|
+
}
|
|
58
|
+
return array[index];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Gets environment variable. Throws error if variable is not found.
|
|
62
|
+
*
|
|
63
|
+
* @param key Environment key
|
|
64
|
+
* @return string
|
|
65
|
+
*/
|
|
66
|
+
export function getEnvVariable(key) {
|
|
67
|
+
const either = getEnvVariableSafe(key);
|
|
68
|
+
if (either.result === "error") {
|
|
69
|
+
throw new Error(either.message);
|
|
70
|
+
}
|
|
71
|
+
return either.value;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Gets environment variable. Safe version returns object with either ok or error status.
|
|
75
|
+
* Easier to use for recovery than catching an error.
|
|
76
|
+
*
|
|
77
|
+
* @param key Environment key
|
|
78
|
+
* @return Either<string>
|
|
79
|
+
*/
|
|
80
|
+
export function getEnvVariableSafe(key) {
|
|
81
|
+
const value = process.env[key];
|
|
82
|
+
if (value === undefined) {
|
|
83
|
+
return {
|
|
84
|
+
result: "error",
|
|
85
|
+
message: `Error: environment variable "${key}" is undefined.`,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return { result: "ok", value };
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Sets environment variable.
|
|
92
|
+
*
|
|
93
|
+
* @param key Environment key
|
|
94
|
+
* @param value Environment variable value
|
|
95
|
+
*/
|
|
96
|
+
export function setEnvVariable(key, value) {
|
|
97
|
+
process.env[key] = value;
|
|
98
|
+
}
|
|
99
|
+
export function setEnvVariableAwsRegion(value) {
|
|
100
|
+
setEnvVariable(EnvKeys.AWS_REGION, value);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Gets environment variable. If environment variable is undefined, returns value of given function.
|
|
104
|
+
*
|
|
105
|
+
* @param key Environment key
|
|
106
|
+
* @param fn Alternative function
|
|
107
|
+
*/
|
|
108
|
+
export function getEnvVariableOr(key, fn) {
|
|
109
|
+
const either = getEnvVariableSafe(key);
|
|
110
|
+
if (either.result === "ok") {
|
|
111
|
+
return either.value;
|
|
112
|
+
}
|
|
113
|
+
return fn();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Gets environment variable. If environment variable is undefined, returns given value.
|
|
117
|
+
* Use to return an explicit alternative value e.g. in cases where environment variable may be undefined.
|
|
118
|
+
*
|
|
119
|
+
* @param key Environment key
|
|
120
|
+
* @param orElse Alternative value
|
|
121
|
+
*/
|
|
122
|
+
export function getEnvVariableOrElse(key, orElse) {
|
|
123
|
+
return getEnvVariableOr(key, () => orElse);
|
|
124
|
+
}
|
|
125
|
+
export function setSecretOverideAwsRegionEnv(region) {
|
|
126
|
+
setEnvVariable(EnvKeys.SECRET_OVERRIDE_AWS_REGION, region);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* ESLint won't allow to call Object.prototype builtin methods.
|
|
130
|
+
* To call hasOwnProperty we must use Object.prototype.hasOwnProperty.call()
|
|
131
|
+
* @param object to test for property
|
|
132
|
+
* @param propertyName property name to check
|
|
133
|
+
* @see https://eslint.org/docs/latest/rules/no-prototype-builtins
|
|
134
|
+
*/
|
|
135
|
+
export function hasOwnPropertySafe(object, propertyName) {
|
|
136
|
+
return Object.hasOwn(object, propertyName);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Return an error message from the given object hat might be an Error object.
|
|
140
|
+
* @param maybeError
|
|
141
|
+
*/
|
|
142
|
+
export function getErrorMessage(maybeError) {
|
|
143
|
+
if (maybeError instanceof Error) {
|
|
144
|
+
return `${maybeError.name}: ${maybeError.message}`;
|
|
145
|
+
}
|
|
146
|
+
return String(maybeError);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* @param value
|
|
150
|
+
*/
|
|
151
|
+
export function isDefined(value) {
|
|
152
|
+
return value !== undefined && value !== null;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Omits a key from an object deeply (also in nested objects). Creates and returns new object.
|
|
156
|
+
*
|
|
157
|
+
* @param obj Object to omit from
|
|
158
|
+
* @param keysToOmit Keys to omit
|
|
159
|
+
* @returns New same type of object as that was given as input but with the keys omitted.
|
|
160
|
+
*/
|
|
161
|
+
export function omitDeep(obj, ...keysToOmit) {
|
|
162
|
+
if (!isObject(obj)) {
|
|
163
|
+
// primitive values are returned as-is
|
|
164
|
+
return obj;
|
|
165
|
+
}
|
|
166
|
+
if (Array.isArray(obj)) {
|
|
167
|
+
// recursively process arrays
|
|
168
|
+
return obj.map((item) => omitDeep(item, ...keysToOmit));
|
|
169
|
+
}
|
|
170
|
+
const result = {};
|
|
171
|
+
forIn(obj, (value, key) => {
|
|
172
|
+
if (!keysToOmit.includes(key)) {
|
|
173
|
+
result[key] = omitDeep(value, ...keysToOmit);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Functions for validating and parsing e.g. path and query parameters with zod.
|
|
4
|
+
* The value of the message parameter will appear in the zod error object resulting from failed validation.
|
|
5
|
+
* Empty strings are treated as undefined.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* const mySchema = z
|
|
9
|
+
* .object({
|
|
10
|
+
* requiredParam: zStringToDate("Invalid value of myParameter"),
|
|
11
|
+
* optionalParam: zStringToDate().optional(),
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Parses a string to a number. Empty strings are treated as undefined.
|
|
17
|
+
*/
|
|
18
|
+
export declare function zStringToNumber(message?: string): z.ZodPipe<z.ZodString, z.ZodTransform<number | undefined, string>>;
|
|
19
|
+
/**
|
|
20
|
+
* Parses a string to a Date. Empty strings are treated as undefined.
|
|
21
|
+
*/
|
|
22
|
+
export declare function zStringToDate(message?: string): z.ZodPipe<z.ZodString, z.ZodTransform<Date | undefined, string>>;
|
|
23
|
+
/**
|
|
24
|
+
* A non-empty string. Empty strings produce a validation error.
|
|
25
|
+
* Chain with .optional() to also accept undefined.
|
|
26
|
+
*/
|
|
27
|
+
export declare function zNonEmptyString(message?: string): z.ZodString;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Functions for validating and parsing e.g. path and query parameters with zod.
|
|
4
|
+
* The value of the message parameter will appear in the zod error object resulting from failed validation.
|
|
5
|
+
* Empty strings are treated as undefined.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* const mySchema = z
|
|
9
|
+
* .object({
|
|
10
|
+
* requiredParam: zStringToDate("Invalid value of myParameter"),
|
|
11
|
+
* optionalParam: zStringToDate().optional(),
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Parses a string to a number. Empty strings are treated as undefined.
|
|
17
|
+
*/
|
|
18
|
+
export function zStringToNumber(message) {
|
|
19
|
+
return z.string().transform((val, ctx) => {
|
|
20
|
+
if (!val)
|
|
21
|
+
return undefined;
|
|
22
|
+
const num = Number(val);
|
|
23
|
+
if (Number.isNaN(num)) {
|
|
24
|
+
ctx.addIssue({ code: "custom", message: message ?? "Not a number" });
|
|
25
|
+
return z.NEVER;
|
|
26
|
+
}
|
|
27
|
+
return num;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Parses a string to a Date. Empty strings are treated as undefined.
|
|
32
|
+
*/
|
|
33
|
+
export function zStringToDate(message) {
|
|
34
|
+
return z.string().transform((val, ctx) => {
|
|
35
|
+
if (!val)
|
|
36
|
+
return undefined;
|
|
37
|
+
const date = new Date(val);
|
|
38
|
+
if (Number.isNaN(date.getTime())) {
|
|
39
|
+
ctx.addIssue({
|
|
40
|
+
code: "custom",
|
|
41
|
+
message: message ?? "Invalid date format",
|
|
42
|
+
});
|
|
43
|
+
return z.NEVER;
|
|
44
|
+
}
|
|
45
|
+
return date;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A non-empty string. Empty strings produce a validation error.
|
|
50
|
+
* Chain with .optional() to also accept undefined.
|
|
51
|
+
*/
|
|
52
|
+
export function zNonEmptyString(message) {
|
|
53
|
+
return z.string().refine((val) => val !== "", {
|
|
54
|
+
message: message ?? "String must not be empty",
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=zod-utils.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitraffic/common",
|
|
3
|
-
"version": "2026.3.
|
|
3
|
+
"version": "2026.3.26-1-beta",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"repository": {
|
|
@@ -108,39 +108,40 @@
|
|
|
108
108
|
"dist/**/*.d.ts"
|
|
109
109
|
],
|
|
110
110
|
"devDependencies": {
|
|
111
|
-
"@aws-sdk/client-api-gateway": "3.
|
|
112
|
-
"@aws-sdk/client-s3": "3.
|
|
113
|
-
"@aws-sdk/client-secrets-manager": "3.
|
|
114
|
-
"@aws-sdk/client-sns": "3.
|
|
115
|
-
"@aws-sdk/lib-storage": "3.
|
|
116
|
-
"@biomejs/biome": "2.4.
|
|
111
|
+
"@aws-sdk/client-api-gateway": "3.1004.0",
|
|
112
|
+
"@aws-sdk/client-s3": "3.1003.0",
|
|
113
|
+
"@aws-sdk/client-secrets-manager": "3.1003.0",
|
|
114
|
+
"@aws-sdk/client-sns": "3.1003.0",
|
|
115
|
+
"@aws-sdk/lib-storage": "3.1003.0",
|
|
116
|
+
"@biomejs/biome": "2.4.6",
|
|
117
117
|
"@date-fns/tz": "1.4.1",
|
|
118
118
|
"@rushstack/heft": "1.2.6",
|
|
119
119
|
"@rushstack/heft-typescript-plugin": "1.3.1",
|
|
120
|
-
"@smithy/fetch-http-handler": "5.3.
|
|
120
|
+
"@smithy/fetch-http-handler": "5.3.13",
|
|
121
|
+
"@smithy/node-http-handler": "4.4.14",
|
|
121
122
|
"@smithy/types": "4.13.0",
|
|
122
|
-
"@types/aws-lambda": "8.10.
|
|
123
|
+
"@types/aws-lambda": "8.10.161",
|
|
123
124
|
"@types/etag": "1.8.4",
|
|
124
125
|
"@types/geojson": "7946.0.16",
|
|
125
126
|
"@types/geojson-validation": "1.0.3",
|
|
126
127
|
"@types/lodash-es": "4.17.12",
|
|
127
128
|
"@types/madge": "5.0.3",
|
|
128
|
-
"@types/node": "25.3.
|
|
129
|
+
"@types/node": "25.3.5",
|
|
129
130
|
"@vitest/coverage-v8": "4.0.18",
|
|
130
|
-
"aws-cdk-lib": "2.
|
|
131
|
+
"aws-cdk-lib": "2.241.0",
|
|
131
132
|
"change-case": "5.4.4",
|
|
132
133
|
"constructs": "10.5.1",
|
|
133
134
|
"date-fns": "4.1.0",
|
|
134
|
-
"es-toolkit": "1.
|
|
135
|
+
"es-toolkit": "1.45.1",
|
|
135
136
|
"etag": "1.8.1",
|
|
136
137
|
"geojson-validation": "1.0.2",
|
|
137
138
|
"ky": "1.14.3",
|
|
138
|
-
"lefthook": "2.1.
|
|
139
|
+
"lefthook": "2.1.2",
|
|
139
140
|
"lodash-es": "4.17.23",
|
|
140
141
|
"madge": "8.0.0",
|
|
141
|
-
"pg-native": "3.
|
|
142
|
-
"pg-promise": "12.6.
|
|
143
|
-
"pg-query-stream": "4.
|
|
142
|
+
"pg-native": "3.7.0",
|
|
143
|
+
"pg-promise": "12.6.2",
|
|
144
|
+
"pg-query-stream": "4.14.0",
|
|
144
145
|
"rimraf": "6.1.3",
|
|
145
146
|
"sort-package-json": "3.6.1",
|
|
146
147
|
"typescript": "5.9.3",
|
|
@@ -149,24 +150,24 @@
|
|
|
149
150
|
"zod": "4.3.6"
|
|
150
151
|
},
|
|
151
152
|
"peerDependencies": {
|
|
152
|
-
"@aws-sdk/client-api-gateway": "3.
|
|
153
|
-
"@aws-sdk/client-s3": "3.
|
|
154
|
-
"@aws-sdk/client-secrets-manager": "3.
|
|
155
|
-
"@aws-sdk/client-sns": "3.
|
|
156
|
-
"@aws-sdk/lib-storage": "3.
|
|
153
|
+
"@aws-sdk/client-api-gateway": "3.1004.0",
|
|
154
|
+
"@aws-sdk/client-s3": "3.1003.0",
|
|
155
|
+
"@aws-sdk/client-secrets-manager": "3.1003.0",
|
|
156
|
+
"@aws-sdk/client-sns": "3.1003.0",
|
|
157
|
+
"@aws-sdk/lib-storage": "3.1003.0",
|
|
157
158
|
"@date-fns/tz": "1.4.1",
|
|
158
|
-
"@smithy/fetch-http-handler": "5.3.
|
|
159
|
-
"@smithy/node-http-handler": "4.4.
|
|
160
|
-
"aws-cdk-lib": "2.
|
|
159
|
+
"@smithy/fetch-http-handler": "5.3.13",
|
|
160
|
+
"@smithy/node-http-handler": "4.4.14",
|
|
161
|
+
"aws-cdk-lib": "2.241.0",
|
|
161
162
|
"change-case": "5.4.4",
|
|
162
|
-
"constructs": "10.
|
|
163
|
+
"constructs": "10.5.1",
|
|
163
164
|
"date-fns": "4.1.0",
|
|
164
|
-
"es-toolkit": "1.
|
|
165
|
+
"es-toolkit": "1.45.1",
|
|
165
166
|
"geojson-validation": "1.0.2",
|
|
166
167
|
"ky": "1.14.3",
|
|
167
168
|
"lodash-es": "4.17.23",
|
|
168
|
-
"pg-native": "3.
|
|
169
|
-
"pg-promise": "12.
|
|
169
|
+
"pg-native": "3.7.0",
|
|
170
|
+
"pg-promise": "12.6.2",
|
|
170
171
|
"zod": "4.3.6"
|
|
171
172
|
},
|
|
172
173
|
"engines": {
|
|
@@ -176,6 +177,7 @@
|
|
|
176
177
|
"build": "heft build --clean",
|
|
177
178
|
"build:watch": "heft build-watch",
|
|
178
179
|
"ci:test": "vitest run --coverage --reporter=junit --outputFile=junit.xml",
|
|
180
|
+
"deps:update-all": "node --experimental-strip-types scripts/update-deps-and-peers.ts",
|
|
179
181
|
"format:check": "biome check ",
|
|
180
182
|
"format:check-staged": "biome check --staged",
|
|
181
183
|
"format:fix": "biome check --write",
|