@openstax/ts-utils 1.21.11 → 1.23.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/cjs/assertions/index.d.ts +85 -0
- package/dist/cjs/assertions/index.js +157 -0
- package/dist/cjs/aws/ssmService.d.ts +5 -0
- package/dist/cjs/aws/ssmService.js +9 -0
- package/dist/cjs/config/awsParameterConfig.d.ts +10 -0
- package/dist/cjs/config/awsParameterConfig.js +26 -0
- package/dist/cjs/config/envConfig.d.ts +24 -0
- package/dist/cjs/config/envConfig.js +57 -0
- package/dist/cjs/config/index.d.ts +48 -0
- package/dist/cjs/config/index.js +35 -0
- package/dist/cjs/config/lambdaParameterConfig.d.ts +12 -0
- package/dist/cjs/config/lambdaParameterConfig.js +45 -0
- package/dist/cjs/config/replaceConfig.d.ts +14 -0
- package/dist/cjs/config/replaceConfig.js +22 -0
- package/dist/cjs/config/resolveConfigValue.d.ts +5 -0
- package/dist/cjs/config/resolveConfigValue.js +12 -0
- package/dist/cjs/errors/index.d.ts +77 -0
- package/dist/cjs/errors/index.js +109 -0
- package/dist/cjs/fetch/fetchStatusRetry.d.ts +7 -0
- package/dist/cjs/fetch/fetchStatusRetry.js +16 -0
- package/dist/cjs/fetch/index.d.ts +64 -0
- package/dist/cjs/fetch/index.js +55 -0
- package/dist/cjs/guards/index.d.ts +30 -0
- package/dist/cjs/guards/index.js +35 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +20 -0
- package/dist/cjs/middleware/apiErrorHandler.d.ts +24 -0
- package/dist/cjs/middleware/apiErrorHandler.js +41 -0
- package/dist/cjs/middleware/apiSlowResponseMiddleware.d.ts +23 -0
- package/dist/cjs/middleware/apiSlowResponseMiddleware.js +54 -0
- package/dist/cjs/middleware/index.d.ts +47 -0
- package/dist/cjs/middleware/index.js +48 -0
- package/dist/cjs/middleware/lambdaCorsResponseMiddleware.d.ts +20 -0
- package/dist/cjs/middleware/lambdaCorsResponseMiddleware.js +42 -0
- package/dist/cjs/middleware/throwNotFoundMiddleware.d.ts +4 -0
- package/dist/cjs/middleware/throwNotFoundMiddleware.js +14 -0
- package/dist/cjs/misc/hashValue.d.ts +10 -0
- package/dist/cjs/misc/hashValue.js +17 -0
- package/dist/cjs/misc/helpers.d.ts +124 -0
- package/dist/cjs/misc/helpers.js +214 -0
- package/dist/cjs/misc/merge.d.ts +21 -0
- package/dist/cjs/misc/merge.js +45 -0
- package/dist/cjs/misc/partitionSequence.d.ts +35 -0
- package/dist/cjs/misc/partitionSequence.js +55 -0
- package/dist/cjs/pagination/index.d.ts +91 -0
- package/dist/cjs/pagination/index.js +83 -0
- package/dist/cjs/routing/helpers.d.ts +57 -0
- package/dist/cjs/routing/helpers.js +90 -0
- package/dist/cjs/routing/index.d.ts +272 -0
- package/dist/cjs/routing/index.js +270 -0
- package/dist/cjs/routing/validators/zod.d.ts +4 -0
- package/dist/cjs/routing/validators/zod.js +12 -0
- package/dist/cjs/services/accountsGateway/index.d.ts +85 -0
- package/dist/cjs/services/accountsGateway/index.js +118 -0
- package/dist/cjs/services/apiGateway/index.d.ts +63 -0
- package/dist/cjs/services/apiGateway/index.js +108 -0
- package/dist/cjs/services/authProvider/browser.d.ts +74 -0
- package/dist/cjs/services/authProvider/browser.js +154 -0
- package/dist/cjs/services/authProvider/decryption.d.ts +19 -0
- package/dist/cjs/services/authProvider/decryption.js +61 -0
- package/dist/cjs/services/authProvider/index.d.ts +61 -0
- package/dist/cjs/services/authProvider/index.js +26 -0
- package/dist/cjs/services/authProvider/subrequest.d.ts +16 -0
- package/dist/cjs/services/authProvider/subrequest.js +50 -0
- package/dist/cjs/services/authProvider/utils/decryptAndVerify.d.ts +29 -0
- package/dist/cjs/services/authProvider/utils/decryptAndVerify.js +91 -0
- package/dist/cjs/services/authProvider/utils/embeddedAuthProvider.d.ts +26 -0
- package/dist/cjs/services/authProvider/utils/embeddedAuthProvider.js +47 -0
- package/dist/cjs/services/authProvider/utils/userRoleValidator.d.ts +13 -0
- package/dist/cjs/services/authProvider/utils/userRoleValidator.js +37 -0
- package/dist/cjs/services/documentStore/dynamoEncoding.d.ts +10 -0
- package/dist/cjs/services/documentStore/dynamoEncoding.js +52 -0
- package/dist/cjs/services/documentStore/index.d.ts +14 -0
- package/dist/cjs/services/documentStore/index.js +2 -0
- package/dist/cjs/services/documentStore/unversioned/dynamodb.d.ts +16 -0
- package/dist/cjs/services/documentStore/unversioned/dynamodb.js +122 -0
- package/dist/cjs/services/documentStore/unversioned/file-system.d.ts +18 -0
- package/dist/cjs/services/documentStore/unversioned/file-system.js +121 -0
- package/dist/cjs/services/documentStore/unversioned/index.d.ts +2 -0
- package/dist/cjs/services/documentStore/unversioned/index.js +2 -0
- package/dist/cjs/services/documentStore/versioned/dynamodb.d.ts +22 -0
- package/dist/cjs/services/documentStore/versioned/dynamodb.js +135 -0
- package/dist/cjs/services/documentStore/versioned/file-system.d.ts +24 -0
- package/dist/cjs/services/documentStore/versioned/file-system.js +62 -0
- package/dist/cjs/services/documentStore/versioned/index.d.ts +17 -0
- package/dist/cjs/services/documentStore/versioned/index.js +2 -0
- package/dist/cjs/services/exercisesGateway/index.d.ts +71 -0
- package/dist/cjs/services/exercisesGateway/index.js +97 -0
- package/dist/cjs/services/fileServer/index.d.ts +17 -0
- package/dist/cjs/services/fileServer/index.js +19 -0
- package/dist/cjs/services/fileServer/localFileServer.d.ts +13 -0
- package/dist/cjs/services/fileServer/localFileServer.js +23 -0
- package/dist/cjs/services/fileServer/s3FileServer.d.ts +16 -0
- package/dist/cjs/services/fileServer/s3FileServer.js +25 -0
- package/dist/cjs/services/launchParams/index.d.ts +2 -0
- package/dist/cjs/services/launchParams/index.js +7 -0
- package/dist/cjs/services/launchParams/signer.d.ts +27 -0
- package/dist/cjs/services/launchParams/signer.js +58 -0
- package/dist/cjs/services/launchParams/verifier.d.ts +22 -0
- package/dist/cjs/services/launchParams/verifier.js +94 -0
- package/dist/cjs/services/logger/console.d.ts +4 -0
- package/dist/cjs/services/logger/console.js +12 -0
- package/dist/cjs/services/logger/index.d.ts +39 -0
- package/dist/cjs/services/logger/index.js +31 -0
- package/dist/cjs/services/lrsGateway/addStatementDefaultFields.d.ts +5 -0
- package/dist/cjs/services/lrsGateway/addStatementDefaultFields.js +21 -0
- package/dist/cjs/services/lrsGateway/attempt-utils.d.ts +70 -0
- package/dist/cjs/services/lrsGateway/attempt-utils.js +258 -0
- package/dist/cjs/services/lrsGateway/file-system.d.ts +17 -0
- package/dist/cjs/services/lrsGateway/file-system.js +140 -0
- package/dist/cjs/services/lrsGateway/index.d.ts +125 -0
- package/dist/cjs/services/lrsGateway/index.js +138 -0
- package/dist/cjs/services/lrsGateway/xapiUtils.d.ts +61 -0
- package/dist/cjs/services/lrsGateway/xapiUtils.js +94 -0
- package/dist/cjs/services/postgresConnection/index.d.ts +35 -0
- package/dist/cjs/services/postgresConnection/index.js +63 -0
- package/dist/cjs/services/searchProvider/index.d.ts +31 -0
- package/dist/cjs/services/searchProvider/index.js +2 -0
- package/dist/cjs/services/searchProvider/memorySearchTheBadWay.d.ts +14 -0
- package/dist/cjs/services/searchProvider/memorySearchTheBadWay.js +89 -0
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -0
- package/dist/cjs/types.d.ts +31 -0
- package/dist/cjs/types.js +2 -0
- package/dist/esm/assertions/index.d.ts +85 -0
- package/dist/esm/assertions/index.js +146 -0
- package/dist/esm/aws/ssmService.d.ts +5 -0
- package/dist/esm/aws/ssmService.js +6 -0
- package/dist/esm/config/awsParameterConfig.d.ts +10 -0
- package/dist/esm/config/awsParameterConfig.js +22 -0
- package/dist/esm/config/envConfig.d.ts +24 -0
- package/dist/esm/config/envConfig.js +53 -0
- package/dist/esm/config/index.d.ts +48 -0
- package/dist/esm/config/index.js +17 -0
- package/dist/esm/config/lambdaParameterConfig.d.ts +12 -0
- package/dist/esm/config/lambdaParameterConfig.js +38 -0
- package/dist/esm/config/replaceConfig.d.ts +14 -0
- package/dist/esm/config/replaceConfig.js +18 -0
- package/dist/esm/config/resolveConfigValue.d.ts +5 -0
- package/dist/esm/config/resolveConfigValue.js +8 -0
- package/dist/esm/errors/index.d.ts +77 -0
- package/dist/esm/errors/index.js +99 -0
- package/dist/esm/fetch/fetchStatusRetry.d.ts +7 -0
- package/dist/esm/fetch/fetchStatusRetry.js +12 -0
- package/dist/esm/fetch/index.d.ts +64 -0
- package/dist/esm/fetch/index.js +46 -0
- package/dist/esm/guards/index.d.ts +30 -0
- package/dist/esm/guards/index.js +28 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/middleware/apiErrorHandler.d.ts +24 -0
- package/dist/esm/middleware/apiErrorHandler.js +37 -0
- package/dist/esm/middleware/apiSlowResponseMiddleware.d.ts +23 -0
- package/dist/esm/middleware/apiSlowResponseMiddleware.js +50 -0
- package/dist/esm/middleware/index.d.ts +47 -0
- package/dist/esm/middleware/index.js +44 -0
- package/dist/esm/middleware/lambdaCorsResponseMiddleware.d.ts +20 -0
- package/dist/esm/middleware/lambdaCorsResponseMiddleware.js +38 -0
- package/dist/esm/middleware/throwNotFoundMiddleware.d.ts +4 -0
- package/dist/esm/middleware/throwNotFoundMiddleware.js +10 -0
- package/dist/esm/misc/hashValue.d.ts +10 -0
- package/dist/esm/misc/hashValue.js +13 -0
- package/dist/esm/misc/helpers.d.ts +124 -0
- package/dist/esm/misc/helpers.js +199 -0
- package/dist/esm/misc/merge.d.ts +21 -0
- package/dist/esm/misc/merge.js +40 -0
- package/dist/esm/misc/partitionSequence.d.ts +35 -0
- package/dist/esm/misc/partitionSequence.js +48 -0
- package/dist/esm/pagination/index.d.ts +91 -0
- package/dist/esm/pagination/index.js +77 -0
- package/dist/esm/routing/helpers.d.ts +57 -0
- package/dist/esm/routing/helpers.js +83 -0
- package/dist/esm/routing/index.d.ts +272 -0
- package/dist/esm/routing/index.js +232 -0
- package/dist/esm/routing/validators/zod.d.ts +4 -0
- package/dist/esm/routing/validators/zod.js +8 -0
- package/dist/esm/services/accountsGateway/index.d.ts +85 -0
- package/dist/esm/services/accountsGateway/index.js +111 -0
- package/dist/esm/services/apiGateway/index.d.ts +63 -0
- package/dist/esm/services/apiGateway/index.js +77 -0
- package/dist/esm/services/authProvider/browser.d.ts +74 -0
- package/dist/esm/services/authProvider/browser.js +150 -0
- package/dist/esm/services/authProvider/decryption.d.ts +19 -0
- package/dist/esm/services/authProvider/decryption.js +57 -0
- package/dist/esm/services/authProvider/index.d.ts +61 -0
- package/dist/esm/services/authProvider/index.js +18 -0
- package/dist/esm/services/authProvider/subrequest.d.ts +16 -0
- package/dist/esm/services/authProvider/subrequest.js +43 -0
- package/dist/esm/services/authProvider/utils/decryptAndVerify.d.ts +29 -0
- package/dist/esm/services/authProvider/utils/decryptAndVerify.js +85 -0
- package/dist/esm/services/authProvider/utils/embeddedAuthProvider.d.ts +26 -0
- package/dist/esm/services/authProvider/utils/embeddedAuthProvider.js +40 -0
- package/dist/esm/services/authProvider/utils/userRoleValidator.d.ts +13 -0
- package/dist/esm/services/authProvider/utils/userRoleValidator.js +33 -0
- package/dist/esm/services/documentStore/dynamoEncoding.d.ts +10 -0
- package/dist/esm/services/documentStore/dynamoEncoding.js +45 -0
- package/dist/esm/services/documentStore/index.d.ts +14 -0
- package/dist/esm/services/documentStore/index.js +1 -0
- package/dist/esm/services/documentStore/unversioned/dynamodb.d.ts +16 -0
- package/dist/esm/services/documentStore/unversioned/dynamodb.js +118 -0
- package/dist/esm/services/documentStore/unversioned/file-system.d.ts +18 -0
- package/dist/esm/services/documentStore/unversioned/file-system.js +91 -0
- package/dist/esm/services/documentStore/unversioned/index.d.ts +2 -0
- package/dist/esm/services/documentStore/unversioned/index.js +1 -0
- package/dist/esm/services/documentStore/versioned/dynamodb.d.ts +22 -0
- package/dist/esm/services/documentStore/versioned/dynamodb.js +131 -0
- package/dist/esm/services/documentStore/versioned/file-system.d.ts +24 -0
- package/dist/esm/services/documentStore/versioned/file-system.js +58 -0
- package/dist/esm/services/documentStore/versioned/index.d.ts +17 -0
- package/dist/esm/services/documentStore/versioned/index.js +1 -0
- package/dist/esm/services/exercisesGateway/index.d.ts +71 -0
- package/dist/esm/services/exercisesGateway/index.js +70 -0
- package/dist/esm/services/fileServer/index.d.ts +17 -0
- package/dist/esm/services/fileServer/index.js +13 -0
- package/dist/esm/services/fileServer/localFileServer.d.ts +13 -0
- package/dist/esm/services/fileServer/localFileServer.js +16 -0
- package/dist/esm/services/fileServer/s3FileServer.d.ts +16 -0
- package/dist/esm/services/fileServer/s3FileServer.js +21 -0
- package/dist/esm/services/launchParams/index.d.ts +2 -0
- package/dist/esm/services/launchParams/index.js +2 -0
- package/dist/esm/services/launchParams/signer.d.ts +27 -0
- package/dist/esm/services/launchParams/signer.js +51 -0
- package/dist/esm/services/launchParams/verifier.d.ts +22 -0
- package/dist/esm/services/launchParams/verifier.js +67 -0
- package/dist/esm/services/logger/console.d.ts +4 -0
- package/dist/esm/services/logger/console.js +8 -0
- package/dist/esm/services/logger/index.d.ts +39 -0
- package/dist/esm/services/logger/index.js +27 -0
- package/dist/esm/services/lrsGateway/addStatementDefaultFields.d.ts +5 -0
- package/dist/esm/services/lrsGateway/addStatementDefaultFields.js +14 -0
- package/dist/esm/services/lrsGateway/attempt-utils.d.ts +70 -0
- package/dist/esm/services/lrsGateway/attempt-utils.js +236 -0
- package/dist/esm/services/lrsGateway/file-system.d.ts +17 -0
- package/dist/esm/services/lrsGateway/file-system.js +110 -0
- package/dist/esm/services/lrsGateway/index.d.ts +125 -0
- package/dist/esm/services/lrsGateway/index.js +111 -0
- package/dist/esm/services/lrsGateway/xapiUtils.d.ts +61 -0
- package/dist/esm/services/lrsGateway/xapiUtils.js +84 -0
- package/dist/esm/services/postgresConnection/index.d.ts +35 -0
- package/dist/esm/services/postgresConnection/index.js +56 -0
- package/dist/esm/services/searchProvider/index.d.ts +31 -0
- package/dist/esm/services/searchProvider/index.js +1 -0
- package/dist/esm/services/searchProvider/memorySearchTheBadWay.d.ts +14 -0
- package/dist/esm/services/searchProvider/memorySearchTheBadWay.js +85 -0
- package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -0
- package/dist/esm/types.d.ts +31 -0
- package/dist/esm/types.js +1 -0
- package/package.json +16 -16
- package/script/bin/deploy.bash +8 -0
- package/script/bin/get-env-param.bash +3 -3
- package/script/bin/init-params-script.bash +10 -1
- package/script/bin/upload-params.bash +3 -3
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export declare type AssertionFailed = string | Error | (() => never) | undefined;
|
|
2
|
+
export declare const doThrow: (failed: AssertionFailed) => never;
|
|
3
|
+
/**
|
|
4
|
+
* Asserts that the given value is true.
|
|
5
|
+
*
|
|
6
|
+
* @param x The value to assert.
|
|
7
|
+
* @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
|
|
8
|
+
* to provide some value for this for traceability. Passing an Error instead of a string
|
|
9
|
+
* makes the stack trace more useful and allows you to handle assertion failures differently.
|
|
10
|
+
* @example const definitelyTrue = assertTrue(randomThing, new Error('thing was not true'));
|
|
11
|
+
* @returns the value that was asserted
|
|
12
|
+
*/
|
|
13
|
+
export declare const assertTrue: <X>(x: X, failed?: AssertionFailed) => X & true;
|
|
14
|
+
/**
|
|
15
|
+
* Asserts that the given value is false.
|
|
16
|
+
*
|
|
17
|
+
* @param x The value to assert.
|
|
18
|
+
* @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
|
|
19
|
+
* to provide some value for this for traceability. Passing an Error instead of a string
|
|
20
|
+
* makes the stack trace more useful and allows you to handle assertion failures differently.
|
|
21
|
+
* @example const definitelyFalse = assertFalse(randomThing, new Error('thing was not false'));
|
|
22
|
+
* @returns the value that was asserted
|
|
23
|
+
*/
|
|
24
|
+
export declare const assertFalse: <X>(x: X, failed?: AssertionFailed) => X & false;
|
|
25
|
+
/**
|
|
26
|
+
* Asserts that the given value is defined.
|
|
27
|
+
*
|
|
28
|
+
* @param x The value to assert.
|
|
29
|
+
* @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
|
|
30
|
+
* to provide some value for this for traceability. Passing an Error instead of a string
|
|
31
|
+
* makes the stack trace more useful and allows you to handle assertion failures differently.
|
|
32
|
+
* @example const definitelyDefined = assertDefined(randomThing, new Error('thing was undefined'));
|
|
33
|
+
* @returns the value that was asserted, with a type that excludes undefined
|
|
34
|
+
*/
|
|
35
|
+
export declare const assertDefined: <X>(x: X, failed?: AssertionFailed) => Exclude<X, undefined>;
|
|
36
|
+
/**
|
|
37
|
+
* Asserts that the given value is a string.
|
|
38
|
+
*
|
|
39
|
+
* @param x The value to assert.
|
|
40
|
+
* @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
|
|
41
|
+
* to provide some value for this for traceability. Passing an Error instead of a string
|
|
42
|
+
* makes the stack trace more useful and allows you to handle assertion failures differently.
|
|
43
|
+
* @example const definitelyAString = assertString(randomThing, new Error('thing is not a string'));
|
|
44
|
+
* @returns the value that was asserted
|
|
45
|
+
*/
|
|
46
|
+
export declare const assertString: <X>(x: X, failed?: AssertionFailed) => string;
|
|
47
|
+
/**
|
|
48
|
+
* Asserts that the given value is not `NaN`. Does not assert that the value is a number.
|
|
49
|
+
*
|
|
50
|
+
* @param thing The value to assert.
|
|
51
|
+
* @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
|
|
52
|
+
* to provide some value for this for traceability. Passing an Error instead of a string
|
|
53
|
+
* makes the stack trace more useful and allows you to handle assertion failures differently.
|
|
54
|
+
* @example const definitelyNotNotANumber = assertNotNaN(randomThing, new Error('thing was NaN'));
|
|
55
|
+
* @returns the value that was asserted
|
|
56
|
+
*/
|
|
57
|
+
export declare const assertNotNaN: <T>(thing: T, failed?: AssertionFailed) => T;
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated use assertNotNaN instead
|
|
60
|
+
*/
|
|
61
|
+
export declare const notNaN: <T>(thing: T, failed?: AssertionFailed) => T;
|
|
62
|
+
/**
|
|
63
|
+
* Asserts that the first argument is an instance of the second.
|
|
64
|
+
*
|
|
65
|
+
* @param thing The value to assert.
|
|
66
|
+
* @param constructable The class to check against.
|
|
67
|
+
* @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
|
|
68
|
+
* to provide some value for this for traceability. Passing an Error instead of a string
|
|
69
|
+
* makes the stack trace more useful and allows you to handle assertion failures differently.
|
|
70
|
+
* @example const definitelySyntaxError = assertInstanceOf(error, SyntaxError, new Error('argument was not a SyntaxError'));
|
|
71
|
+
* @returns the value that was asserted
|
|
72
|
+
*/
|
|
73
|
+
export declare const assertInstanceOf: <T>(thing: any, constructable: Function & (new (...args: any[]) => T), failed?: AssertionFailed) => T;
|
|
74
|
+
/**
|
|
75
|
+
* Asserts that the error in the first argument is an instance of the error given as the
|
|
76
|
+
* second argument
|
|
77
|
+
*
|
|
78
|
+
* @param thing The value to assert.
|
|
79
|
+
* @param constructable The error class to check against.
|
|
80
|
+
* @example const definitelySyntaxError = assertInstanceOf(error, SyntaxError);
|
|
81
|
+
* @returns the value that was asserted
|
|
82
|
+
* @throws the original error if the check fails
|
|
83
|
+
* @see assertInstanceOf
|
|
84
|
+
*/
|
|
85
|
+
export declare const assertErrorInstanceOf: <T extends Error>(thing: unknown, constructable: Function & (new (...args: any[]) => T)) => T;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* all of these assertions take either a string, throw function, or nothing
|
|
4
|
+
* for the second argument. its STRONGLY encouraged to provide some error
|
|
5
|
+
* or message that explains the reason for the assertion
|
|
6
|
+
*
|
|
7
|
+
* eg:
|
|
8
|
+
* assertDefined(user, new UnauthorizedException())
|
|
9
|
+
* assertDefined(thing.otherThing, 'otherThing should be guaranteed to exist, but is missing')
|
|
10
|
+
*
|
|
11
|
+
* passing an Error instead of a string makes the first element of the resulting
|
|
12
|
+
* stack trace more useful, and allows you to use specific error types
|
|
13
|
+
* that might be handled differently.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.assertErrorInstanceOf = exports.assertInstanceOf = exports.notNaN = exports.assertNotNaN = exports.assertString = exports.assertDefined = exports.assertFalse = exports.assertTrue = exports.doThrow = void 0;
|
|
17
|
+
const doThrow = (failed) => {
|
|
18
|
+
if (typeof failed === 'string') {
|
|
19
|
+
throw new Error(failed);
|
|
20
|
+
}
|
|
21
|
+
if (failed instanceof Error) {
|
|
22
|
+
throw failed;
|
|
23
|
+
}
|
|
24
|
+
if (!failed) {
|
|
25
|
+
throw new Error();
|
|
26
|
+
}
|
|
27
|
+
return failed();
|
|
28
|
+
};
|
|
29
|
+
exports.doThrow = doThrow;
|
|
30
|
+
/**
|
|
31
|
+
* Asserts that the given value is true.
|
|
32
|
+
*
|
|
33
|
+
* @param x The value to assert.
|
|
34
|
+
* @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
|
|
35
|
+
* to provide some value for this for traceability. Passing an Error instead of a string
|
|
36
|
+
* makes the stack trace more useful and allows you to handle assertion failures differently.
|
|
37
|
+
* @example const definitelyTrue = assertTrue(randomThing, new Error('thing was not true'));
|
|
38
|
+
* @returns the value that was asserted
|
|
39
|
+
*/
|
|
40
|
+
const assertTrue = (x, failed) => {
|
|
41
|
+
if (typeof x !== 'boolean' || x !== true) {
|
|
42
|
+
return (0, exports.doThrow)(failed);
|
|
43
|
+
}
|
|
44
|
+
return x;
|
|
45
|
+
};
|
|
46
|
+
exports.assertTrue = assertTrue;
|
|
47
|
+
/**
|
|
48
|
+
* Asserts that the given value is false.
|
|
49
|
+
*
|
|
50
|
+
* @param x The value to assert.
|
|
51
|
+
* @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
|
|
52
|
+
* to provide some value for this for traceability. Passing an Error instead of a string
|
|
53
|
+
* makes the stack trace more useful and allows you to handle assertion failures differently.
|
|
54
|
+
* @example const definitelyFalse = assertFalse(randomThing, new Error('thing was not false'));
|
|
55
|
+
* @returns the value that was asserted
|
|
56
|
+
*/
|
|
57
|
+
const assertFalse = (x, failed) => {
|
|
58
|
+
if (typeof x !== 'boolean' || x !== false) {
|
|
59
|
+
return (0, exports.doThrow)(failed);
|
|
60
|
+
}
|
|
61
|
+
return x;
|
|
62
|
+
};
|
|
63
|
+
exports.assertFalse = assertFalse;
|
|
64
|
+
/**
|
|
65
|
+
* Asserts that the given value is defined.
|
|
66
|
+
*
|
|
67
|
+
* @param x The value to assert.
|
|
68
|
+
* @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
|
|
69
|
+
* to provide some value for this for traceability. Passing an Error instead of a string
|
|
70
|
+
* makes the stack trace more useful and allows you to handle assertion failures differently.
|
|
71
|
+
* @example const definitelyDefined = assertDefined(randomThing, new Error('thing was undefined'));
|
|
72
|
+
* @returns the value that was asserted, with a type that excludes undefined
|
|
73
|
+
*/
|
|
74
|
+
const assertDefined = (x, failed) => {
|
|
75
|
+
if (x === undefined) {
|
|
76
|
+
return (0, exports.doThrow)(failed);
|
|
77
|
+
}
|
|
78
|
+
return x;
|
|
79
|
+
};
|
|
80
|
+
exports.assertDefined = assertDefined;
|
|
81
|
+
/**
|
|
82
|
+
* Asserts that the given value is a string.
|
|
83
|
+
*
|
|
84
|
+
* @param x The value to assert.
|
|
85
|
+
* @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
|
|
86
|
+
* to provide some value for this for traceability. Passing an Error instead of a string
|
|
87
|
+
* makes the stack trace more useful and allows you to handle assertion failures differently.
|
|
88
|
+
* @example const definitelyAString = assertString(randomThing, new Error('thing is not a string'));
|
|
89
|
+
* @returns the value that was asserted
|
|
90
|
+
*/
|
|
91
|
+
const assertString = (x, failed) => {
|
|
92
|
+
if (typeof x !== 'string') {
|
|
93
|
+
return (0, exports.doThrow)(failed);
|
|
94
|
+
}
|
|
95
|
+
return x;
|
|
96
|
+
};
|
|
97
|
+
exports.assertString = assertString;
|
|
98
|
+
/**
|
|
99
|
+
* Asserts that the given value is not `NaN`. Does not assert that the value is a number.
|
|
100
|
+
*
|
|
101
|
+
* @param thing The value to assert.
|
|
102
|
+
* @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
|
|
103
|
+
* to provide some value for this for traceability. Passing an Error instead of a string
|
|
104
|
+
* makes the stack trace more useful and allows you to handle assertion failures differently.
|
|
105
|
+
* @example const definitelyNotNotANumber = assertNotNaN(randomThing, new Error('thing was NaN'));
|
|
106
|
+
* @returns the value that was asserted
|
|
107
|
+
*/
|
|
108
|
+
const assertNotNaN = (thing, failed) => {
|
|
109
|
+
if (typeof thing === 'number' && isNaN(thing)) {
|
|
110
|
+
return (0, exports.doThrow)(failed);
|
|
111
|
+
}
|
|
112
|
+
return thing;
|
|
113
|
+
};
|
|
114
|
+
exports.assertNotNaN = assertNotNaN;
|
|
115
|
+
/**
|
|
116
|
+
* @deprecated use assertNotNaN instead
|
|
117
|
+
*/
|
|
118
|
+
exports.notNaN = exports.assertNotNaN;
|
|
119
|
+
/**
|
|
120
|
+
* Asserts that the first argument is an instance of the second.
|
|
121
|
+
*
|
|
122
|
+
* @param thing The value to assert.
|
|
123
|
+
* @param constructable The class to check against.
|
|
124
|
+
* @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
|
|
125
|
+
* to provide some value for this for traceability. Passing an Error instead of a string
|
|
126
|
+
* makes the stack trace more useful and allows you to handle assertion failures differently.
|
|
127
|
+
* @example const definitelySyntaxError = assertInstanceOf(error, SyntaxError, new Error('argument was not a SyntaxError'));
|
|
128
|
+
* @returns the value that was asserted
|
|
129
|
+
*/
|
|
130
|
+
const assertInstanceOf = (thing, constructable, failed) => {
|
|
131
|
+
if (thing instanceof constructable) {
|
|
132
|
+
return thing;
|
|
133
|
+
}
|
|
134
|
+
return (0, exports.doThrow)(failed);
|
|
135
|
+
};
|
|
136
|
+
exports.assertInstanceOf = assertInstanceOf;
|
|
137
|
+
/**
|
|
138
|
+
* Asserts that the error in the first argument is an instance of the error given as the
|
|
139
|
+
* second argument
|
|
140
|
+
*
|
|
141
|
+
* @param thing The value to assert.
|
|
142
|
+
* @param constructable The error class to check against.
|
|
143
|
+
* @example const definitelySyntaxError = assertInstanceOf(error, SyntaxError);
|
|
144
|
+
* @returns the value that was asserted
|
|
145
|
+
* @throws the original error if the check fails
|
|
146
|
+
* @see assertInstanceOf
|
|
147
|
+
*/
|
|
148
|
+
const assertErrorInstanceOf = (thing, constructable) => {
|
|
149
|
+
if (thing instanceof Error) {
|
|
150
|
+
return (0, exports.assertInstanceOf)(thing, constructable, thing);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
// this separate branch prevents an unknown non-Error thing from being passed to the assertion as an AssertionFailed
|
|
154
|
+
throw new Error(`assertErrorInstanceOf received non-Error argument of type "${typeof thing}" and string representation "${thing}"`);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
exports.assertErrorInstanceOf = assertErrorInstanceOf;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ssmService = void 0;
|
|
4
|
+
const client_ssm_1 = require("@aws-sdk/client-ssm");
|
|
5
|
+
const __1 = require("..");
|
|
6
|
+
/**
|
|
7
|
+
* A memoized instance of the AWS SSM client.
|
|
8
|
+
*/
|
|
9
|
+
exports.ssmService = (0, __1.once)(() => new client_ssm_1.SSM({ apiVersion: '2012-08-10' }));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ConfigValueProvider } from '.';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a value from the AWS Parameter Store.
|
|
4
|
+
*
|
|
5
|
+
* @param parameterName the name of the parameter; can be a literal name (string) or can itself
|
|
6
|
+
* be accessed via another parameter by giving a configuration value provider.
|
|
7
|
+
* @example const someValue = resolveConfig(awsParameterConfig('some-parameter-name'));
|
|
8
|
+
* @returns the configuration value provider for the value
|
|
9
|
+
*/
|
|
10
|
+
export declare const awsParameterConfig: (parameterName: ConfigValueProvider<string>) => ConfigValueProvider<string>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.awsParameterConfig = void 0;
|
|
4
|
+
const client_ssm_1 = require("@aws-sdk/client-ssm");
|
|
5
|
+
const assertions_1 = require("../assertions");
|
|
6
|
+
const ssmService_1 = require("../aws/ssmService");
|
|
7
|
+
const resolveConfigValue_1 = require("./resolveConfigValue");
|
|
8
|
+
/**
|
|
9
|
+
* Returns a value from the AWS Parameter Store.
|
|
10
|
+
*
|
|
11
|
+
* @param parameterName the name of the parameter; can be a literal name (string) or can itself
|
|
12
|
+
* be accessed via another parameter by giving a configuration value provider.
|
|
13
|
+
* @example const someValue = resolveConfig(awsParameterConfig('some-parameter-name'));
|
|
14
|
+
* @returns the configuration value provider for the value
|
|
15
|
+
*/
|
|
16
|
+
const awsParameterConfig = (parameterName) => {
|
|
17
|
+
return async () => {
|
|
18
|
+
const command = new client_ssm_1.GetParameterCommand({ Name: await (0, resolveConfigValue_1.resolveConfigValue)(parameterName), WithDecryption: true });
|
|
19
|
+
// send() throws ParameterNotFound if the parameter is missing,
|
|
20
|
+
// so it's not clear what missing Parameter or Value mean
|
|
21
|
+
const response = await (0, ssmService_1.ssmService)().send(command);
|
|
22
|
+
const parameter = (0, assertions_1.assertDefined)(response.Parameter, `aws GetParameter response missing Parameter key for ${parameterName}"`);
|
|
23
|
+
return (0, assertions_1.assertDefined)(parameter.Value, `aws GetParameter response missing Parameter.Value key for ${parameterName}"`);
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
exports.awsParameterConfig = awsParameterConfig;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ConfigValueProvider } from '.';
|
|
2
|
+
/**
|
|
3
|
+
* A list of environment variables that were requested at build time. Used by webpack to
|
|
4
|
+
* capture build-time environment variables values.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ENV_BUILD_CONFIGS: string[];
|
|
7
|
+
/**
|
|
8
|
+
* Returns an environment variable from the process environment. Depending on the `type` in the
|
|
9
|
+
* call to get the variable, the variable's value may be what it was at build time, not at runtime.
|
|
10
|
+
* The return value is not the variable value itself, but rather a provider that has to be called
|
|
11
|
+
* to read the variable value (meaning, this is safe to call even if the variable doesn't exist,
|
|
12
|
+
* because someone else later needs to call the provider to get the value -- that call may explode,
|
|
13
|
+
* but this one won't).
|
|
14
|
+
*
|
|
15
|
+
* @param name The name of the environment variable to retrieve.
|
|
16
|
+
* @param type The mode for accessing the variable. Defaults to `'build'`, i.e. getting the
|
|
17
|
+
* variable as it was set at build time (webpack is connected here to make this possible). This
|
|
18
|
+
* argument can also be `'runtime'` in which case the value at build time is ignored and the
|
|
19
|
+
* variable is pulled live from `process.env`.
|
|
20
|
+
* @param [defaultValue] The default value to use if the variable is not found.
|
|
21
|
+
*
|
|
22
|
+
* @example const config = { configValue: envConfig('environment_variable_name') };
|
|
23
|
+
*/
|
|
24
|
+
export declare const envConfig: (name: string, type?: "build" | "runtime" | undefined, defaultValue?: ConfigValueProvider<string> | undefined) => ConfigValueProvider<string>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.envConfig = exports.ENV_BUILD_CONFIGS = void 0;
|
|
4
|
+
const resolveConfigValue_1 = require("./resolveConfigValue");
|
|
5
|
+
/**
|
|
6
|
+
* A list of environment variables that were requested at build time. Used by webpack to
|
|
7
|
+
* capture build-time environment variables values.
|
|
8
|
+
*/
|
|
9
|
+
exports.ENV_BUILD_CONFIGS = [];
|
|
10
|
+
/**
|
|
11
|
+
* Returns an environment variable from the process environment. Depending on the `type` in the
|
|
12
|
+
* call to get the variable, the variable's value may be what it was at build time, not at runtime.
|
|
13
|
+
* The return value is not the variable value itself, but rather a provider that has to be called
|
|
14
|
+
* to read the variable value (meaning, this is safe to call even if the variable doesn't exist,
|
|
15
|
+
* because someone else later needs to call the provider to get the value -- that call may explode,
|
|
16
|
+
* but this one won't).
|
|
17
|
+
*
|
|
18
|
+
* @param name The name of the environment variable to retrieve.
|
|
19
|
+
* @param type The mode for accessing the variable. Defaults to `'build'`, i.e. getting the
|
|
20
|
+
* variable as it was set at build time (webpack is connected here to make this possible). This
|
|
21
|
+
* argument can also be `'runtime'` in which case the value at build time is ignored and the
|
|
22
|
+
* variable is pulled live from `process.env`.
|
|
23
|
+
* @param [defaultValue] The default value to use if the variable is not found.
|
|
24
|
+
*
|
|
25
|
+
* @example const config = { configValue: envConfig('environment_variable_name') };
|
|
26
|
+
*/
|
|
27
|
+
const envConfig = (name, type, defaultValue) => {
|
|
28
|
+
// this doesn't use a default parameter value because of a:
|
|
29
|
+
// "Regular parameters should not come after default parameters."
|
|
30
|
+
// error that occurs when the defaultValue optional default of `undefined`
|
|
31
|
+
// gets optimized out, causing a problem in cloudfront functions.
|
|
32
|
+
type !== null && type !== void 0 ? type : (type = 'build');
|
|
33
|
+
if (type === 'build') {
|
|
34
|
+
exports.ENV_BUILD_CONFIGS.push(name);
|
|
35
|
+
}
|
|
36
|
+
return () => {
|
|
37
|
+
/*global __PROCESS_ENV*/
|
|
38
|
+
// @ts-ignore - hack to get around the way webpack/define works
|
|
39
|
+
// - https://github.com/webpack/webpack/issues/14800
|
|
40
|
+
// - https://github.com/webpack/webpack/issues/5392
|
|
41
|
+
// also, spread operator not supported in cloudfront functions
|
|
42
|
+
const envs = Object.assign({}, process.env, typeof __PROCESS_ENV !== 'undefined' ? __PROCESS_ENV : {});
|
|
43
|
+
const value = envs[name];
|
|
44
|
+
if (value === undefined) {
|
|
45
|
+
if (defaultValue === undefined) {
|
|
46
|
+
throw new Error(`expected to find environment variable with name: ${name}`);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return (0, resolveConfigValue_1.resolveConfigValue)(defaultValue);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
exports.envConfig = envConfig;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A simple type alias for a string that represents a configuration value. Currently only string values are supported to maintain compatibility with environment variables, but this type is future proofing against allowing other types like `number` as possible config values.
|
|
3
|
+
*/
|
|
4
|
+
export declare type ConfigValue = string;
|
|
5
|
+
/**
|
|
6
|
+
* A configuration object that may contain nested configuration objects or configuration values.
|
|
7
|
+
*/
|
|
8
|
+
export declare type Config = {
|
|
9
|
+
[key: string]: Config | ConfigValue;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Either a function that returns a `ConfigValue` or a `Promise` that resolves to a `ConfigValue`,
|
|
13
|
+
* or just a `ConfigValue`.
|
|
14
|
+
*/
|
|
15
|
+
export declare type ConfigValueProvider<V extends ConfigValue = ConfigValue> = (() => Promise<V> | V) | V;
|
|
16
|
+
/**
|
|
17
|
+
* A configuration object that may contain nested configuration objects or configuration value providers.
|
|
18
|
+
*/
|
|
19
|
+
export declare type ConfigProvider = {
|
|
20
|
+
[key: string]: ConfigProvider | ConfigValueProvider;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Conditional type that resolves to the type of configuration object for the given configuration
|
|
24
|
+
* provider. Also resolves to a config value type if the given type is a config value.
|
|
25
|
+
*/
|
|
26
|
+
export declare type ConfigForConfigProvider<T> = T extends ConfigValue ? T : T extends ConfigProvider ? {
|
|
27
|
+
[key in keyof T]: ConfigForConfigProvider<T[key]>;
|
|
28
|
+
} : T extends ConfigValueProvider<infer R> ? R : never;
|
|
29
|
+
/**
|
|
30
|
+
* Conditional type that resolves to the `ConfigProvider` type for the given configuration
|
|
31
|
+
* type (`ConfigValue` or `Config`). The resulting type is either a `ConfigValueProvider` or
|
|
32
|
+
* a `ConfigProvider`.
|
|
33
|
+
*/
|
|
34
|
+
export declare type ConfigProviderForConfig<T> = T extends ConfigValue ? ConfigValueProvider<T> : T extends Config ? {
|
|
35
|
+
[key in keyof T]: ConfigProviderForConfig<T[key]>;
|
|
36
|
+
} : never;
|
|
37
|
+
export * from './resolveConfigValue';
|
|
38
|
+
/**
|
|
39
|
+
* stub, mostly for testing. sometimes it helps please typescript to use this if you have
|
|
40
|
+
* two configs you want to have the same type but one is a fixed string and one is a complicated provider
|
|
41
|
+
*
|
|
42
|
+
* @example const config = { configValue: stubConfig('just-a-string') };
|
|
43
|
+
*/
|
|
44
|
+
export declare const stubConfig: <V extends string>(configValue: V) => ConfigValueProvider<V>;
|
|
45
|
+
export * from './envConfig';
|
|
46
|
+
export * from './replaceConfig';
|
|
47
|
+
export * from './awsParameterConfig';
|
|
48
|
+
export * from './lambdaParameterConfig';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.stubConfig = void 0;
|
|
18
|
+
__exportStar(require("./resolveConfigValue"), exports);
|
|
19
|
+
/*
|
|
20
|
+
* ===========
|
|
21
|
+
* re-usable config providers
|
|
22
|
+
* ===========
|
|
23
|
+
* */
|
|
24
|
+
/**
|
|
25
|
+
* stub, mostly for testing. sometimes it helps please typescript to use this if you have
|
|
26
|
+
* two configs you want to have the same type but one is a fixed string and one is a complicated provider
|
|
27
|
+
*
|
|
28
|
+
* @example const config = { configValue: stubConfig('just-a-string') };
|
|
29
|
+
*/
|
|
30
|
+
const stubConfig = (configValue) => configValue;
|
|
31
|
+
exports.stubConfig = stubConfig;
|
|
32
|
+
__exportStar(require("./envConfig"), exports);
|
|
33
|
+
__exportStar(require("./replaceConfig"), exports);
|
|
34
|
+
__exportStar(require("./awsParameterConfig"), exports);
|
|
35
|
+
__exportStar(require("./lambdaParameterConfig"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ConfigValueProvider } from '.';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a value from the AWS Parameter Store. Can only be used during in AWS Lambda, and
|
|
4
|
+
* requires that the AWS Parameters and Secrets Lambda Extension Layer be included in the Lambda.
|
|
5
|
+
* This extension has built-in caching for requested parameters.
|
|
6
|
+
*
|
|
7
|
+
* @param parameterName the name of the parameter; can be a literal name (string) or can itself
|
|
8
|
+
* be accessed via another parameter by giving a configuration value provider.
|
|
9
|
+
* @example const someValue = resolveConfig(lambdaParameterConfig('some-parameter-name'));
|
|
10
|
+
* @returns the configuration value provider for the value
|
|
11
|
+
*/
|
|
12
|
+
export declare const lambdaParameterConfig: (parameterName: ConfigValueProvider<string>) => ConfigValueProvider<string>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.lambdaParameterConfig = void 0;
|
|
7
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
8
|
+
const assertions_1 = require("../assertions");
|
|
9
|
+
const helpers_1 = require("../misc/helpers");
|
|
10
|
+
const envConfig_1 = require("./envConfig");
|
|
11
|
+
const _1 = require(".");
|
|
12
|
+
const lambdaExtensionUrl = 'http://localhost:2773';
|
|
13
|
+
let lambdaExtensionReadyPromise;
|
|
14
|
+
/**
|
|
15
|
+
* Returns a value from the AWS Parameter Store. Can only be used during in AWS Lambda, and
|
|
16
|
+
* requires that the AWS Parameters and Secrets Lambda Extension Layer be included in the Lambda.
|
|
17
|
+
* This extension has built-in caching for requested parameters.
|
|
18
|
+
*
|
|
19
|
+
* @param parameterName the name of the parameter; can be a literal name (string) or can itself
|
|
20
|
+
* be accessed via another parameter by giving a configuration value provider.
|
|
21
|
+
* @example const someValue = resolveConfig(lambdaParameterConfig('some-parameter-name'));
|
|
22
|
+
* @returns the configuration value provider for the value
|
|
23
|
+
*/
|
|
24
|
+
const lambdaParameterConfig = (parameterName) => async () => {
|
|
25
|
+
const token = await (0, _1.resolveConfigValue)((0, envConfig_1.envConfig)('AWS_SESSION_TOKEN', 'runtime'));
|
|
26
|
+
const name = await (0, _1.resolveConfigValue)(parameterName);
|
|
27
|
+
if (!lambdaExtensionReadyPromise) {
|
|
28
|
+
// This request will return 400 Bad Request,
|
|
29
|
+
// but we only care that it'll block until the extension is ready
|
|
30
|
+
lambdaExtensionReadyPromise = (0, helpers_1.retryWithDelay)(() => (0, node_fetch_1.default)(lambdaExtensionUrl));
|
|
31
|
+
}
|
|
32
|
+
await lambdaExtensionReadyPromise;
|
|
33
|
+
const resp = await (0, helpers_1.retryWithDelay)(() => (0, node_fetch_1.default)(
|
|
34
|
+
// Port 2773 is the default port for the extension
|
|
35
|
+
`${lambdaExtensionUrl}/systemsmanager/parameters/get?name=${name}&withDecryption=true`, { headers: { 'X-Aws-Parameters-Secrets-Token': token } }));
|
|
36
|
+
if (resp.ok) {
|
|
37
|
+
const response = await resp.json();
|
|
38
|
+
const parameter = (0, assertions_1.assertDefined)(response.Parameter, `aws GetParameter response missing Parameter key for ${name}"`);
|
|
39
|
+
return (0, assertions_1.assertDefined)(parameter.Value, `aws GetParameter response missing Parameter.Value key for ${name}"`);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
throw new Error(`HTTP Error Response ${resp.status} ${resp.statusText} while fetching parameter ${name}`);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.lambdaParameterConfig = lambdaParameterConfig;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ConfigValueProvider } from '.';
|
|
2
|
+
/**
|
|
3
|
+
* Substitutes configuration values into a provided string.
|
|
4
|
+
* Performs a string substitution using configuration values
|
|
5
|
+
* @param base The string into which substitutions will be made; contains tokens that are
|
|
6
|
+
* referenced in the `replacements` argument.
|
|
7
|
+
* @param replacements A map of tokens to configuration value providers. The providers are
|
|
8
|
+
* resolved and the values are substituted into the `base` string, replacing the tokens.
|
|
9
|
+
* @example replaceConfig('https://[host]', { '[host]': envConfig('HOST') })
|
|
10
|
+
* @returns the string after substitution is complete
|
|
11
|
+
*/
|
|
12
|
+
export declare const replaceConfig: (base: ConfigValueProvider<string>, replacements: {
|
|
13
|
+
[token: string]: ConfigValueProvider<string>;
|
|
14
|
+
}) => ConfigValueProvider<string>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.replaceConfig = void 0;
|
|
4
|
+
const resolveConfigValue_1 = require("./resolveConfigValue");
|
|
5
|
+
/**
|
|
6
|
+
* Substitutes configuration values into a provided string.
|
|
7
|
+
* Performs a string substitution using configuration values
|
|
8
|
+
* @param base The string into which substitutions will be made; contains tokens that are
|
|
9
|
+
* referenced in the `replacements` argument.
|
|
10
|
+
* @param replacements A map of tokens to configuration value providers. The providers are
|
|
11
|
+
* resolved and the values are substituted into the `base` string, replacing the tokens.
|
|
12
|
+
* @example replaceConfig('https://[host]', { '[host]': envConfig('HOST') })
|
|
13
|
+
* @returns the string after substitution is complete
|
|
14
|
+
*/
|
|
15
|
+
const replaceConfig = (base, replacements) => {
|
|
16
|
+
return async () => {
|
|
17
|
+
const resolved = await Promise.all(Object.entries(replacements)
|
|
18
|
+
.map(async ([token, replacement]) => [token, await (0, resolveConfigValue_1.resolveConfigValue)(replacement)]));
|
|
19
|
+
return resolved.reduce((result, [token, replacement]) => result.replace(token, replacement), await (0, resolveConfigValue_1.resolveConfigValue)(base));
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.replaceConfig = replaceConfig;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveConfigValue = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* resolves a config value into a string, to be used inside of things that are provided configurations
|
|
6
|
+
*/
|
|
7
|
+
const resolveConfigValue = async (provider) => {
|
|
8
|
+
return typeof provider === 'function'
|
|
9
|
+
? await provider()
|
|
10
|
+
: provider;
|
|
11
|
+
};
|
|
12
|
+
exports.resolveConfigValue = resolveConfigValue;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { JsonCompatibleStruct } from '../routing';
|
|
2
|
+
/**
|
|
3
|
+
* Returns true if the error is defined in this library
|
|
4
|
+
*/
|
|
5
|
+
export declare const isAppError: (e: any) => e is Error & {
|
|
6
|
+
constructor: {
|
|
7
|
+
TYPE: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Invalid request error
|
|
12
|
+
*
|
|
13
|
+
* `InvalidRequestError.matches(error)` is a reliable way to check if an error is an
|
|
14
|
+
* `InvalidRequestError`; `instanceof` checks may not work if code is split into multiple bundles
|
|
15
|
+
*/
|
|
16
|
+
export declare class InvalidRequestError extends Error {
|
|
17
|
+
static readonly TYPE = "InvalidRequestError";
|
|
18
|
+
static matches: (e: any) => e is typeof InvalidRequestError;
|
|
19
|
+
constructor(message?: string);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Validation Error
|
|
23
|
+
*
|
|
24
|
+
* `ValidationError.matches(error)` is a reliable way to check if an error is an
|
|
25
|
+
* `ValidationError`; `instanceof` checks may not work if code is split into multiple bundles
|
|
26
|
+
*/
|
|
27
|
+
export declare class ValidationError extends Error {
|
|
28
|
+
static readonly TYPE = "ValidationError";
|
|
29
|
+
static matches: (e: any) => e is typeof ValidationError;
|
|
30
|
+
private data;
|
|
31
|
+
constructor(data: JsonCompatibleStruct);
|
|
32
|
+
getData(): JsonCompatibleStruct;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Unauthorized error
|
|
36
|
+
*
|
|
37
|
+
* `UnauthorizedError.matches(error)` is a reliable way to check if an error is an
|
|
38
|
+
* `UnauthorizedError`; `instanceof` checks may not work if code is split into multiple bundles
|
|
39
|
+
*/
|
|
40
|
+
export declare class UnauthorizedError extends Error {
|
|
41
|
+
static readonly TYPE = "UnauthorizedError";
|
|
42
|
+
static matches: (e: any) => e is typeof UnauthorizedError;
|
|
43
|
+
constructor(message?: string);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Forbidden error
|
|
47
|
+
*
|
|
48
|
+
* `ForbiddenError.matches(error)` is a reliable way to check if an error is a
|
|
49
|
+
* `ForbiddenError`; `instanceof` checks may not work if code is split into multiple bundles
|
|
50
|
+
*/
|
|
51
|
+
export declare class ForbiddenError extends Error {
|
|
52
|
+
static readonly TYPE = "ForbiddenError";
|
|
53
|
+
static matches: (e: any) => e is typeof ForbiddenError;
|
|
54
|
+
constructor(message?: string);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Not found error
|
|
58
|
+
*
|
|
59
|
+
* `NotFoundError.matches(error)` is a reliable way to check if an error is a
|
|
60
|
+
* `NotFoundError`; `instanceof` checks may not work if code is split into multiple bundles
|
|
61
|
+
*/
|
|
62
|
+
export declare class NotFoundError extends Error {
|
|
63
|
+
static readonly TYPE = "NotFoundError";
|
|
64
|
+
static matches: (e: any) => e is typeof NotFoundError;
|
|
65
|
+
constructor(message?: string);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Session expired error
|
|
69
|
+
*
|
|
70
|
+
* `SessionExpiredError.matches(error)` is a reliable way to check if an error is a
|
|
71
|
+
* `SessionExpiredError`; `instanceof` checks may not work if code is split into multiple bundles
|
|
72
|
+
*/
|
|
73
|
+
export declare class SessionExpiredError extends Error {
|
|
74
|
+
static readonly TYPE = "SessionExpiredError";
|
|
75
|
+
static matches: (e: any) => e is typeof SessionExpiredError;
|
|
76
|
+
constructor(message?: string);
|
|
77
|
+
}
|