@openstax/ts-utils 1.34.0 → 1.35.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/README.md +90 -62
- package/dist/cjs/assertions/index.d.ts +89 -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/{packages/utils/src/config/index.ts → dist/cjs/config/index.d.ts} +13 -29
- 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 +88 -0
- package/dist/cjs/errors/index.js +123 -0
- package/dist/cjs/fetch/fetchStatusRetry.d.ts +8 -0
- package/dist/cjs/fetch/fetchStatusRetry.js +27 -0
- package/dist/cjs/fetch/index.d.ts +64 -0
- package/dist/cjs/fetch/index.js +55 -0
- package/{packages/utils/src/guards/index.ts → dist/cjs/guards/index.d.ts} +7 -10
- package/dist/cjs/guards/index.js +44 -0
- package/dist/cjs/index.js +20 -0
- package/dist/cjs/middleware/apiErrorHandler.d.ts +24 -0
- package/dist/cjs/middleware/apiErrorHandler.js +42 -0
- package/dist/cjs/middleware/apiSlowResponseMiddleware.d.ts +23 -0
- package/dist/cjs/middleware/apiSlowResponseMiddleware.js +54 -0
- package/{packages/utils/src/middleware/index.ts → dist/cjs/middleware/index.d.ts} +5 -53
- package/dist/cjs/middleware/index.js +48 -0
- package/dist/cjs/middleware/lambdaCorsResponseMiddleware.d.ts +20 -0
- package/dist/cjs/middleware/lambdaCorsResponseMiddleware.js +44 -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 +290 -0
- package/dist/cjs/routing/index.js +295 -0
- package/dist/cjs/routing/validators/zod.d.ts +4 -0
- package/dist/cjs/routing/validators/zod.js +14 -0
- package/dist/cjs/services/accountsGateway/index.d.ts +92 -0
- package/dist/cjs/services/accountsGateway/index.js +138 -0
- package/dist/cjs/services/apiGateway/index.d.ts +68 -0
- package/dist/cjs/services/apiGateway/index.js +118 -0
- package/dist/cjs/services/authProvider/browser.d.ts +40 -0
- package/dist/cjs/services/authProvider/browser.js +155 -0
- package/dist/cjs/services/authProvider/decryption.d.ts +19 -0
- package/dist/cjs/services/authProvider/decryption.js +73 -0
- package/dist/cjs/services/authProvider/index.d.ts +63 -0
- package/dist/cjs/services/authProvider/index.js +34 -0
- package/dist/cjs/services/authProvider/subrequest.d.ts +13 -0
- package/dist/cjs/services/authProvider/subrequest.js +49 -0
- package/dist/cjs/services/authProvider/utils/decryptAndVerify.d.ts +28 -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/authProvider/utils/userSubrequest.d.ts +3 -0
- package/dist/cjs/services/authProvider/utils/userSubrequest.js +13 -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/fileSystemAssert.d.ts +1 -0
- package/dist/cjs/services/documentStore/fileSystemAssert.js +14 -0
- package/{packages/utils/src/services/documentStore/index.ts → dist/cjs/services/documentStore/index.d.ts} +8 -8
- package/dist/cjs/services/documentStore/index.js +2 -0
- package/dist/cjs/services/documentStore/unversioned/dynamodb.d.ts +31 -0
- package/dist/cjs/services/documentStore/unversioned/dynamodb.js +233 -0
- package/dist/cjs/services/documentStore/unversioned/file-system.d.ts +32 -0
- package/dist/cjs/services/documentStore/unversioned/file-system.js +214 -0
- package/{packages/utils/src/services/documentStore/unversioned/index.ts → dist/cjs/services/documentStore/unversioned/index.d.ts} +0 -2
- package/dist/cjs/services/documentStore/unversioned/index.js +2 -0
- package/dist/cjs/services/documentStore/versioned/dynamodb.d.ts +25 -0
- package/dist/cjs/services/documentStore/versioned/dynamodb.js +143 -0
- package/dist/cjs/services/documentStore/versioned/file-system.d.ts +25 -0
- package/dist/cjs/services/documentStore/versioned/file-system.js +73 -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 +67 -0
- package/dist/cjs/services/exercisesGateway/index.js +107 -0
- package/dist/cjs/services/fileServer/index.d.ts +30 -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 +132 -0
- package/dist/cjs/services/fileServer/s3FileServer.d.ts +14 -0
- package/dist/cjs/services/fileServer/s3FileServer.js +131 -0
- package/dist/cjs/services/launchParams/index.js +7 -0
- package/dist/cjs/services/launchParams/signer.d.ts +23 -0
- package/dist/cjs/services/launchParams/signer.js +58 -0
- package/dist/cjs/services/launchParams/verifier.d.ts +21 -0
- package/dist/cjs/services/launchParams/verifier.js +129 -0
- package/dist/cjs/services/logger/console.d.ts +4 -0
- package/dist/cjs/services/logger/console.js +12 -0
- package/{packages/utils/src/services/logger/index.ts → dist/cjs/services/logger/index.d.ts} +9 -23
- 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 +72 -0
- package/dist/cjs/services/lrsGateway/attempt-utils.js +283 -0
- package/dist/cjs/services/lrsGateway/file-system.d.ts +15 -0
- package/dist/cjs/services/lrsGateway/file-system.js +150 -0
- package/dist/cjs/services/lrsGateway/index.d.ts +122 -0
- package/dist/cjs/services/lrsGateway/index.js +148 -0
- package/dist/cjs/services/lrsGateway/xapiUtils.d.ts +71 -0
- package/dist/cjs/services/lrsGateway/xapiUtils.js +145 -0
- package/dist/cjs/services/postgresConnection/index.d.ts +28 -0
- package/dist/cjs/services/postgresConnection/index.js +65 -0
- package/dist/cjs/services/searchProvider/index.d.ts +69 -0
- package/dist/cjs/services/searchProvider/index.js +2 -0
- package/dist/cjs/services/searchProvider/memorySearchTheBadWay.d.ts +20 -0
- package/dist/cjs/services/searchProvider/memorySearchTheBadWay.js +191 -0
- package/dist/cjs/services/searchProvider/openSearch.d.ts +28 -0
- package/dist/cjs/services/searchProvider/openSearch.js +162 -0
- package/dist/cjs/services/searchProvider/streamIndexer.d.ts +17 -0
- package/dist/cjs/services/searchProvider/streamIndexer.js +41 -0
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -0
- package/{packages/utils/src/types.ts → dist/cjs/types.d.ts} +6 -34
- package/dist/cjs/types.js +2 -0
- package/dist/esm/assertions/index.d.ts +89 -0
- package/{packages/utils/src/assertions/index.ts → dist/esm/assertions/index.js} +49 -64
- 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/{packages/utils/src/config/replaceConfig.ts → dist/esm/config/replaceConfig.js} +6 -16
- package/dist/esm/config/resolveConfigValue.d.ts +5 -0
- package/dist/esm/config/resolveConfigValue.js +8 -0
- package/dist/esm/errors/index.d.ts +88 -0
- package/{packages/utils/src/errors/index.ts → dist/esm/errors/index.js} +41 -57
- package/dist/esm/fetch/fetchStatusRetry.d.ts +8 -0
- package/dist/esm/fetch/fetchStatusRetry.js +23 -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 +38 -0
- package/dist/esm/guards/index.js +36 -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 +38 -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 +40 -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/{packages/utils/src/misc/partitionSequence.ts → dist/esm/misc/partitionSequence.js} +15 -23
- 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/{packages/utils/src/routing/helpers.ts → dist/esm/routing/helpers.js} +30 -42
- package/dist/esm/routing/index.d.ts +290 -0
- package/dist/esm/routing/index.js +246 -0
- package/dist/esm/routing/validators/zod.d.ts +4 -0
- package/dist/esm/routing/validators/zod.js +10 -0
- package/dist/esm/services/accountsGateway/index.d.ts +92 -0
- package/dist/esm/services/accountsGateway/index.js +131 -0
- package/dist/esm/services/apiGateway/index.d.ts +68 -0
- package/dist/esm/services/apiGateway/index.js +77 -0
- package/dist/esm/services/authProvider/browser.d.ts +40 -0
- package/dist/esm/services/authProvider/browser.js +151 -0
- package/dist/esm/services/authProvider/decryption.d.ts +19 -0
- package/dist/esm/services/authProvider/decryption.js +69 -0
- package/dist/esm/services/authProvider/index.d.ts +63 -0
- package/dist/esm/services/authProvider/index.js +26 -0
- package/dist/esm/services/authProvider/subrequest.d.ts +13 -0
- package/dist/esm/services/authProvider/subrequest.js +45 -0
- package/dist/esm/services/authProvider/utils/decryptAndVerify.d.ts +28 -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/authProvider/utils/userSubrequest.d.ts +3 -0
- package/dist/esm/services/authProvider/utils/userSubrequest.js +6 -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/fileSystemAssert.d.ts +1 -0
- package/dist/esm/services/documentStore/fileSystemAssert.js +10 -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 +31 -0
- package/dist/esm/services/documentStore/unversioned/dynamodb.js +226 -0
- package/dist/esm/services/documentStore/unversioned/file-system.d.ts +32 -0
- package/dist/esm/services/documentStore/unversioned/file-system.js +174 -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 +25 -0
- package/dist/esm/services/documentStore/versioned/dynamodb.js +139 -0
- package/dist/esm/services/documentStore/versioned/file-system.d.ts +25 -0
- package/dist/esm/services/documentStore/versioned/file-system.js +69 -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 +67 -0
- package/dist/esm/services/exercisesGateway/index.js +70 -0
- package/dist/esm/services/fileServer/index.d.ts +30 -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 +125 -0
- package/dist/esm/services/fileServer/s3FileServer.d.ts +14 -0
- package/dist/esm/services/fileServer/s3FileServer.js +124 -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 +23 -0
- package/dist/esm/services/launchParams/signer.js +51 -0
- package/dist/esm/services/launchParams/verifier.d.ts +21 -0
- package/dist/esm/services/launchParams/verifier.js +92 -0
- package/dist/esm/services/logger/console.d.ts +4 -0
- package/{packages/utils/src/services/logger/console.ts → dist/esm/services/logger/console.js} +2 -5
- 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 +72 -0
- package/dist/esm/services/lrsGateway/attempt-utils.js +261 -0
- package/dist/esm/services/lrsGateway/file-system.d.ts +15 -0
- package/dist/esm/services/lrsGateway/file-system.js +110 -0
- package/dist/esm/services/lrsGateway/index.d.ts +122 -0
- package/dist/esm/services/lrsGateway/index.js +111 -0
- package/dist/esm/services/lrsGateway/xapiUtils.d.ts +71 -0
- package/dist/esm/services/lrsGateway/xapiUtils.js +134 -0
- package/dist/esm/services/postgresConnection/index.d.ts +28 -0
- package/dist/esm/services/postgresConnection/index.js +58 -0
- package/dist/esm/services/searchProvider/index.d.ts +69 -0
- package/dist/esm/services/searchProvider/index.js +1 -0
- package/dist/esm/services/searchProvider/memorySearchTheBadWay.d.ts +20 -0
- package/dist/esm/services/searchProvider/memorySearchTheBadWay.js +187 -0
- package/dist/esm/services/searchProvider/openSearch.d.ts +28 -0
- package/dist/esm/services/searchProvider/openSearch.js +158 -0
- package/dist/esm/services/searchProvider/streamIndexer.d.ts +17 -0
- package/dist/esm/services/searchProvider/streamIndexer.js +37 -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 +234 -12
- package/.cfnlintrc +0 -2
- package/.github/CODEOWNERS +0 -1
- package/.github/workflows/ci.yml +0 -36
- package/.github/workflows/lint.yml +0 -55
- package/.nvmrc +0 -1
- package/.syncignore +0 -4
- package/.syncpackrc +0 -18
- package/CONTRIBUTING.md +0 -96
- package/LICENSE +0 -661
- package/Procfile +0 -1
- package/app.json +0 -23
- package/cspell.json +0 -32
- package/deploy/constants.env +0 -21
- package/deploy/deploy.bash +0 -157
- package/deploy/deployment-alt-region.cfn.yml +0 -70
- package/deploy/deployment.cfn.yml +0 -650
- package/deploy/destroy-deployment.bash +0 -23
- package/deploy/shared.cfn.yml +0 -94
- package/docs/lambda-build.md +0 -35
- package/packages/frontend/README.md +0 -46
- package/packages/frontend/package.json +0 -101
- package/packages/frontend/public/favicon.ico +0 -0
- package/packages/frontend/public/index.html +0 -107
- package/packages/frontend/public/maintenance.html +0 -59
- package/packages/frontend/public/manifest.json +0 -15
- package/packages/frontend/public/robots.txt +0 -3
- package/packages/frontend/script/make-certificate.bash +0 -49
- package/packages/frontend/script/server/cli.js +0 -11
- package/packages/frontend/script/server/index.js +0 -47
- package/packages/frontend/script/start.bash +0 -22
- package/packages/frontend/script/trust-localhost.bash +0 -7
- package/packages/frontend/src/auth/authProvider.ts +0 -10
- package/packages/frontend/src/auth/useAuth.ts +0 -33
- package/packages/frontend/src/components/Pagination.tsx +0 -26
- package/packages/frontend/src/configProvider/index.ts +0 -53
- package/packages/frontend/src/configProvider/use.ts +0 -41
- package/packages/frontend/src/core/context/services.spec.tsx +0 -39
- package/packages/frontend/src/core/context/services.tsx +0 -16
- package/packages/frontend/src/core/index.spec.ts +0 -7
- package/packages/frontend/src/core/index.ts +0 -20
- package/packages/frontend/src/core/services.tsx +0 -14
- package/packages/frontend/src/core/types.ts +0 -3
- package/packages/frontend/src/example/api.ts +0 -28
- package/packages/frontend/src/example/components/Layout.tsx +0 -23
- package/packages/frontend/src/example/screens/Home.spec.tsx +0 -68
- package/packages/frontend/src/example/screens/Home.tsx +0 -78
- package/packages/frontend/src/example/screens/ThingList.spec.tsx +0 -60
- package/packages/frontend/src/example/screens/ThingList.tsx +0 -75
- package/packages/frontend/src/example/screens/ThingView.spec.tsx +0 -71
- package/packages/frontend/src/example/screens/ThingView.tsx +0 -47
- package/packages/frontend/src/example/screens/index.ts +0 -9
- package/packages/frontend/src/index.css +0 -159
- package/packages/frontend/src/index.tsx +0 -67
- package/packages/frontend/src/react-app-env.d.ts +0 -1
- package/packages/frontend/src/routing/components/RouteLink.spec.tsx +0 -55
- package/packages/frontend/src/routing/components/RouteLink.tsx +0 -35
- package/packages/frontend/src/routing/middleware.ts +0 -6
- package/packages/frontend/src/routing/useQuery.ts +0 -14
- package/packages/frontend/src/setupProxy.js +0 -19
- package/packages/frontend/src/setupTests.ts +0 -9
- package/packages/frontend/src/tests/testServices.tsx +0 -23
- package/packages/frontend/tsconfig.json +0 -27
- package/packages/lambda/.eslintrc.js +0 -64
- package/packages/lambda/jest-global-setup.js +0 -3
- package/packages/lambda/jest-setup-after-env.js +0 -1
- package/packages/lambda/jest.config.js +0 -31
- package/packages/lambda/jest.resolver.js +0 -17
- package/packages/lambda/package.json +0 -68
- package/packages/lambda/script/build.bash +0 -19
- package/packages/lambda/script/bundle-functions.bash +0 -10
- package/packages/lambda/script/lambdaLocalProxy.js +0 -16
- package/packages/lambda/script/lambdaLocalProxy.spec.ts +0 -147
- package/packages/lambda/script/utils/getRouteData.ts +0 -7
- package/packages/lambda/script/utils/routeDataLoader.js +0 -8
- package/packages/lambda/script/utils/routeDataLoader.spec.ts +0 -8
- package/packages/lambda/src/functions/serviceApi/core/index.ts +0 -7
- package/packages/lambda/src/functions/serviceApi/core/request.spec.ts +0 -38
- package/packages/lambda/src/functions/serviceApi/core/request.ts +0 -42
- package/packages/lambda/src/functions/serviceApi/core/routes.spec.ts +0 -7
- package/packages/lambda/src/functions/serviceApi/core/routes.ts +0 -10
- package/packages/lambda/src/functions/serviceApi/core/services.ts +0 -9
- package/packages/lambda/src/functions/serviceApi/core/types.ts +0 -13
- package/packages/lambda/src/functions/serviceApi/entry/lambda/https-xray.ts +0 -4
- package/packages/lambda/src/functions/serviceApi/entry/lambda/index.spec.ts +0 -48
- package/packages/lambda/src/functions/serviceApi/entry/lambda/index.ts +0 -58
- package/packages/lambda/src/functions/serviceApi/entry/lambda/services.ts +0 -36
- package/packages/lambda/src/functions/serviceApi/entry/local.ts +0 -71
- package/packages/lambda/src/functions/serviceApi/versions/v0/example/documentSearchMiddleware.spec.ts +0 -16
- package/packages/lambda/src/functions/serviceApi/versions/v0/example/documentSearchMiddleware.ts +0 -41
- package/packages/lambda/src/functions/serviceApi/versions/v0/example/documentStoreMiddleware.spec.ts +0 -78
- package/packages/lambda/src/functions/serviceApi/versions/v0/example/documentStoreMiddleware.ts +0 -70
- package/packages/lambda/src/functions/serviceApi/versions/v0/example/routes.spec.ts +0 -306
- package/packages/lambda/src/functions/serviceApi/versions/v0/example/routes.ts +0 -176
- package/packages/lambda/src/functions/serviceApi/versions/v0/index.spec.ts +0 -263
- package/packages/lambda/src/functions/serviceApi/versions/v0/index.ts +0 -134
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/authMiddleware.spec.ts +0 -23
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/authMiddleware.ts +0 -32
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/configMiddleware.spec.ts +0 -10
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/configMiddleware.ts +0 -7
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/frontendFileServerMiddleware.spec.ts +0 -13
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/frontendFileServerMiddleware.ts +0 -23
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/paginationMiddleware.spec.ts +0 -9
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/paginationMiddleware.ts +0 -9
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/searchMiddleware.spec.ts +0 -12
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/searchMiddleware.ts +0 -21
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/userRoleValidatorMiddleware.spec.ts +0 -21
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/userRoleValidatorMiddleware.ts +0 -18
- package/packages/lambda/tsconfig.json +0 -30
- package/packages/lambda/webpack.config.js +0 -97
- package/packages/utils/.eslintrc.js +0 -64
- package/packages/utils/README.md +0 -118
- package/packages/utils/jest-global-setup.js +0 -3
- package/packages/utils/jest.config.js +0 -25
- package/packages/utils/jest.resolver.js +0 -17
- package/packages/utils/package.json +0 -238
- package/packages/utils/src/assertions/index.spec.ts +0 -126
- package/packages/utils/src/aws/ssmService.ts +0 -7
- package/packages/utils/src/config/awsParameterConfig.ts +0 -24
- package/packages/utils/src/config/envConfig.ts +0 -58
- package/packages/utils/src/config/index.spec.ts +0 -165
- package/packages/utils/src/config/lambdaParameterConfig.ts +0 -49
- package/packages/utils/src/config/resolveConfigValue.ts +0 -10
- package/packages/utils/src/errors/index.spec.ts +0 -35
- package/packages/utils/src/fetch/fetchStatusRetry.spec.ts +0 -197
- package/packages/utils/src/fetch/fetchStatusRetry.ts +0 -33
- package/packages/utils/src/fetch/index.spec.ts +0 -34
- package/packages/utils/src/fetch/index.ts +0 -87
- package/packages/utils/src/guards/index.spec.ts +0 -58
- package/packages/utils/src/index.spec.ts +0 -471
- package/packages/utils/src/middleware/apiErrorHandler.spec.ts +0 -65
- package/packages/utils/src/middleware/apiErrorHandler.ts +0 -67
- package/packages/utils/src/middleware/apiSlowResponseMiddleware.spec.ts +0 -184
- package/packages/utils/src/middleware/apiSlowResponseMiddleware.ts +0 -71
- package/packages/utils/src/middleware/index.spec.ts +0 -99
- package/packages/utils/src/middleware/lambdaCorsResponseMiddleware.spec.ts +0 -103
- package/packages/utils/src/middleware/lambdaCorsResponseMiddleware.ts +0 -52
- package/packages/utils/src/middleware/throwNotFoundMiddleware.spec.ts +0 -20
- package/packages/utils/src/middleware/throwNotFoundMiddleware.ts +0 -11
- package/packages/utils/src/misc/hashValue.ts +0 -18
- package/packages/utils/src/misc/helpers.ts +0 -259
- package/packages/utils/src/misc/merge.ts +0 -48
- package/packages/utils/src/pagination/index.spec.ts +0 -150
- package/packages/utils/src/pagination/index.ts +0 -117
- package/packages/utils/src/routing/index.spec.ts +0 -553
- package/packages/utils/src/routing/index.ts +0 -424
- package/packages/utils/src/routing/validators/zod.spec.ts +0 -16
- package/packages/utils/src/routing/validators/zod.ts +0 -14
- package/packages/utils/src/services/accountsGateway/README.md +0 -3
- package/packages/utils/src/services/accountsGateway/index.spec.ts +0 -518
- package/packages/utils/src/services/accountsGateway/index.ts +0 -251
- package/packages/utils/src/services/apiGateway/README.md +0 -93
- package/packages/utils/src/services/apiGateway/index.spec.ts +0 -254
- package/packages/utils/src/services/apiGateway/index.ts +0 -189
- package/packages/utils/src/services/authProvider/README.md +0 -21
- package/packages/utils/src/services/authProvider/browser.spec.ts +0 -391
- package/packages/utils/src/services/authProvider/browser.ts +0 -209
- package/packages/utils/src/services/authProvider/decryption.spec.ts +0 -337
- package/packages/utils/src/services/authProvider/decryption.ts +0 -98
- package/packages/utils/src/services/authProvider/index.ts +0 -93
- package/packages/utils/src/services/authProvider/stub.spec.ts +0 -29
- package/packages/utils/src/services/authProvider/subrequest.spec.ts +0 -105
- package/packages/utils/src/services/authProvider/subrequest.ts +0 -68
- package/packages/utils/src/services/authProvider/utils/decryptAndVerify.spec.ts +0 -128
- package/packages/utils/src/services/authProvider/utils/decryptAndVerify.ts +0 -106
- package/packages/utils/src/services/authProvider/utils/embeddedAuthProvider.spec.ts +0 -26
- package/packages/utils/src/services/authProvider/utils/embeddedAuthProvider.ts +0 -57
- package/packages/utils/src/services/authProvider/utils/userRoleValidator.spec.ts +0 -135
- package/packages/utils/src/services/authProvider/utils/userRoleValidator.ts +0 -49
- package/packages/utils/src/services/authProvider/utils/userSubrequest.spec.ts +0 -26
- package/packages/utils/src/services/authProvider/utils/userSubrequest.ts +0 -10
- package/packages/utils/src/services/documentStore/dynamoEncoding.ts +0 -57
- package/packages/utils/src/services/documentStore/fileSystemAssert.spec.ts +0 -43
- package/packages/utils/src/services/documentStore/fileSystemAssert.ts +0 -10
- package/packages/utils/src/services/documentStore/unversioned/README.md +0 -13
- package/packages/utils/src/services/documentStore/unversioned/dynamodb.spec.ts +0 -859
- package/packages/utils/src/services/documentStore/unversioned/dynamodb.ts +0 -243
- package/packages/utils/src/services/documentStore/unversioned/file-system.spec.ts +0 -629
- package/packages/utils/src/services/documentStore/unversioned/file-system.ts +0 -194
- package/packages/utils/src/services/documentStore/versioned/README.md +0 -13
- package/packages/utils/src/services/documentStore/versioned/dynamodb.spec.ts +0 -376
- package/packages/utils/src/services/documentStore/versioned/dynamodb.ts +0 -167
- package/packages/utils/src/services/documentStore/versioned/file-system.spec.ts +0 -262
- package/packages/utils/src/services/documentStore/versioned/file-system.ts +0 -90
- package/packages/utils/src/services/documentStore/versioned/index.ts +0 -25
- package/packages/utils/src/services/exercisesGateway/README.md +0 -5
- package/packages/utils/src/services/exercisesGateway/index.spec.ts +0 -326
- package/packages/utils/src/services/exercisesGateway/index.ts +0 -163
- package/packages/utils/src/services/fileServer/index.spec.ts +0 -88
- package/packages/utils/src/services/fileServer/index.ts +0 -43
- package/packages/utils/src/services/fileServer/localFileServer.spec.ts +0 -182
- package/packages/utils/src/services/fileServer/localFileServer.ts +0 -159
- package/packages/utils/src/services/fileServer/s3FileServer.spec.ts +0 -266
- package/packages/utils/src/services/fileServer/s3FileServer.ts +0 -155
- package/packages/utils/src/services/launchParams/index.spec.ts +0 -366
- package/packages/utils/src/services/launchParams/signer.ts +0 -73
- package/packages/utils/src/services/launchParams/verifier.ts +0 -120
- package/packages/utils/src/services/logger/console.spec.ts +0 -29
- package/packages/utils/src/services/logger/index.spec.ts +0 -65
- package/packages/utils/src/services/lrsGateway/README.md +0 -5
- package/packages/utils/src/services/lrsGateway/addStatementDefaultFields.ts +0 -22
- package/packages/utils/src/services/lrsGateway/attempt-utils.spec.ts +0 -847
- package/packages/utils/src/services/lrsGateway/attempt-utils.ts +0 -358
- package/packages/utils/src/services/lrsGateway/file-system.spec.ts +0 -363
- package/packages/utils/src/services/lrsGateway/file-system.ts +0 -165
- package/packages/utils/src/services/lrsGateway/index.spec.ts +0 -194
- package/packages/utils/src/services/lrsGateway/index.ts +0 -257
- package/packages/utils/src/services/lrsGateway/xapiUtils.spec.ts +0 -887
- package/packages/utils/src/services/lrsGateway/xapiUtils.ts +0 -262
- package/packages/utils/src/services/postgresConnection/index.spec.ts +0 -170
- package/packages/utils/src/services/postgresConnection/index.ts +0 -84
- package/packages/utils/src/services/searchProvider/README.md +0 -3
- package/packages/utils/src/services/searchProvider/index.ts +0 -59
- package/packages/utils/src/services/searchProvider/memorySearchTheBadWay.spec.ts +0 -526
- package/packages/utils/src/services/searchProvider/memorySearchTheBadWay.ts +0 -223
- package/packages/utils/src/services/searchProvider/openSearch.spec.ts +0 -926
- package/packages/utils/src/services/searchProvider/openSearch.ts +0 -195
- package/packages/utils/tsconfig.json +0 -31
- package/packages/utils/tsconfig.without-specs.cjs.json +0 -7
- package/packages/utils/tsconfig.without-specs.esm.json +0 -7
- package/packages/utils/tsconfig.without-specs.json +0 -6
- package/scripts/build.bash +0 -24
- package/scripts/ci.bash +0 -10
- package/scripts/start.bash +0 -29
- /package/{packages/utils/src/index.ts → dist/cjs/index.d.ts} +0 -0
- /package/{packages/utils/src/services/launchParams/index.ts → dist/cjs/services/launchParams/index.d.ts} +0 -0
- /package/{packages/utils/script → script}/bin/copy-from-template.bash +0 -0
- /package/{packages/utils/script → script}/bin/delete-stack.bash +0 -0
- /package/{packages/utils/script → script}/bin/deploy.bash +0 -0
- /package/{packages/utils/script → script}/bin/destroy-deployment.bash +0 -0
- /package/{packages/utils/script → script}/bin/empty-bucket.bash +0 -0
- /package/{packages/utils/script → script}/bin/get-arg.bash +0 -0
- /package/{packages/utils/script → script}/bin/get-deployed-environments.bash +0 -0
- /package/{packages/utils/script → script}/bin/get-env-param.bash +0 -0
- /package/{packages/utils/script → script}/bin/get-kwarg.bash +0 -0
- /package/{packages/utils/script → script}/bin/get-stack-param.bash +0 -0
- /package/{packages/utils/script → script}/bin/has-flag.bash +0 -0
- /package/{packages/utils/script → script}/bin/init-constants-script.bash +0 -0
- /package/{packages/utils/script → script}/bin/init-params-script.bash +0 -0
- /package/{packages/utils/script → script}/bin/stack-exists.bash +0 -0
- /package/{packages/utils/script → script}/bin/update-utils.bash +0 -0
- /package/{packages/utils/script → script}/bin/upload-pager-duty-endpoints.bash +0 -0
- /package/{packages/utils/script → script}/bin/upload-params.bash +0 -0
- /package/{packages/utils/script → script}/bin/which.bash +0 -0
- /package/{packages/utils/script → script}/bin-entry.bash +0 -0
- /package/{packages/utils/script → script}/build.bash +0 -0
package/README.md
CHANGED
|
@@ -1,90 +1,118 @@
|
|
|
1
|
-
|
|
2
|
-
## Project Template
|
|
1
|
+
# @openstax/ts-utils
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
A collection of utilities typescript applications. browser and server support.
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
- strong fullstack typescript support even across api calls
|
|
9
|
-
- one command development server script
|
|
10
|
-
- one command deployment script
|
|
11
|
-
- production ready with error handling, logging, alerting
|
|
12
|
-
- established paradigms for common issues like routing, middleware, pagination, configs, dependency injection, plug-able service drivers per environment
|
|
13
|
-
- service providers for versioned document storage, file storage, document search, openstax accounts auth
|
|
14
|
-
- 100% test coverage using jest in both frontend and lambda modules
|
|
15
|
-
- CI checks for unit tests, spell checking, code linting, code coverage
|
|
5
|
+
## Libraries
|
|
6
|
+
overviews of the libraries provided and their purposes, for more specific information check out the comments in the source code.
|
|
16
7
|
|
|
17
|
-
|
|
8
|
+
### [types.ts](./types.ts)
|
|
9
|
+
utility types, no javascript functionality in here. A dumping ground for commonly used utility types or sorcery copied of stack overflow.
|
|
18
10
|
|
|
19
|
-
###
|
|
11
|
+
### [guards.ts](./guards.ts)
|
|
12
|
+
generic [type guards](https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards). most of this isn't super interesting its just annoying to have to re-define these in every project.
|
|
20
13
|
|
|
21
|
-
|
|
14
|
+
### [assertions.ts](./assertions.ts)
|
|
15
|
+
like a guard but throws if the condition fails. you can use an assertion if you're extra sure that something is true but typescript isn't so sure, its possible that a bug might exist but normally your expected case should always be the case. these assertions allow you to have useful errors/messages for the exceptional bug, without generating conditional logic in your application code. this is almost entirely driven by not wanting to create code branches that will then need unit tests.
|
|
22
16
|
|
|
23
|
-
|
|
17
|
+
### [index.ts](./index.ts)
|
|
18
|
+
basic array/object access/manipulation utilities
|
|
24
19
|
|
|
25
|
-
###
|
|
20
|
+
### [errors.ts](./errors.ts)
|
|
21
|
+
a set of common application errors for the other libraries to use
|
|
26
22
|
|
|
27
|
-
|
|
23
|
+
### [fetch.ts](./fetch.ts)
|
|
24
|
+
utilities for working with `fetch` and fetching data. mostly there are constructors and guards for working with response objects that capture both a request status and associated data. the actual fetch api only throws if there is a connection errors, so most data access utilities need a way to communicate application layer failures back to the client in a discernible way. you can _almost_ do this with regular response objects, but then you're forcing all of the response processing down into user-land, and this system provides an additional loading state for UIs.
|
|
28
25
|
|
|
29
|
-
|
|
26
|
+
### [config.ts](./config.ts)
|
|
27
|
+
defines ConfigProvider as an arbitrarily nested object where leaves must be ConfigValueProviders. ConfigValueProviders are strings, promises of strings, functions without arguments that return strings, or promises of strings. the library has a utility to resolve a ConfigValueProvider to a string, and a few re-usable providers.
|
|
30
28
|
|
|
29
|
+
### [middleware.ts](./middleware.ts)
|
|
30
|
+
middleware are chains of functions, with shared access to a parent application or services, that modify or decorate a result. middleware chains are used to pre-process requests before they reach routing, post-process results after routing, and compose service providers for the routes to use.
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
### [routing.ts](./routing.ts)
|
|
33
|
+
a flexible routing library with utils for defining routes, matching requests to routes, and rendering urls for routes. strong typing for route params, request bodies, response bodies. reverse routing asserts not only that the correct route and params are given, but that the route is composed in the application. built to be implementation agnostic and support both browser SPA routing and server side API routing.
|
|
33
34
|
|
|
34
|
-
###
|
|
35
|
-
|
|
36
|
-
- delete packages/utils (it'll pull it from npm)
|
|
37
|
-
- run `git rev-parse head > .lastsync` so that future updates can be patched in
|
|
38
|
-
- reset the git history (delete .git and run `git init; git commit -am "initial commit"` again)
|
|
39
|
-
- follow the [development](#development) instructions to start your local environment
|
|
35
|
+
### [pagination.ts](./pagination.ts)
|
|
36
|
+
utilities for interpreting pagination requests and generating pagination responses for both 'load more' and 'page number' style pagination. included middleware for working with the routing library.
|
|
40
37
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
- start checking out the frontend code from the [homepage](./packages/frontend/src/example/screens/Home.tsx), there are a few pages that integrate with the example api routes.
|
|
44
|
-
- more info about the libraries and utils used in the [utils module](./packages/utils/README.md)
|
|
38
|
+
## Services
|
|
39
|
+
Services differ from the rest of the libraries in that they have a single discrete interface and support multiple implementations of that interface.
|
|
45
40
|
|
|
46
|
-
###
|
|
47
|
-
|
|
48
|
-
walk you through some one-time setup stuff. it'll output the deployed url when it finishes.
|
|
49
|
-
- upload some secrets to the parameter store with `AccountsBase=SOMETHING CookieName=SOMETHING EncryptionPrivateKey=SOMETHING SignaturePublicKey=SOMETHING yarn ts-utils upload-params <environment-name>`.
|
|
50
|
-
- (optional) set PagerDuty params with `yarn -s ts-utils upload-pager-duty-endpoints`
|
|
41
|
+
### [apiGateway](./services/apiGateway/index.ts)
|
|
42
|
+
dynamically generates an api client from route configuration. if you're using the routing library in the api, this allows you to import your route types directly into your client and have very strong typing on your api calls for free. includes error handling, filtering responses by status code, and narrowing the expected data type by given status code.
|
|
51
43
|
|
|
52
|
-
|
|
44
|
+
### [authProvider](./services/authProvider)
|
|
45
|
+
integrates with openstax.org/accounts, includes several implementations for both browser and server side integrations.
|
|
53
46
|
|
|
54
|
-
|
|
47
|
+
### [lrsGateway](./services/lrsGateway/index.ts)
|
|
48
|
+
handles authentication and payload formatting for interacting with the LRS
|
|
55
49
|
|
|
56
|
-
|
|
50
|
+
### [versionedDocumentStore](./services/versionedDocumentStore)
|
|
51
|
+
a key/value document store with integrated audit logging. all writes are done as new versions of documents and version history can be fetched. includes implementations for dynamodb and local file system.
|
|
57
52
|
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
### [searchProvider](./services/searchProvider/index.ts)
|
|
54
|
+
allows filtering and open text search for documents. has strong typing for filterable values based on the document type definition. interface is based on elasticsearch options, but currently we only have an in memory filtering implementation. works out of the box with versionedDocumentStore.
|
|
60
55
|
|
|
61
|
-
|
|
62
|
-
npm install -g yarn
|
|
56
|
+
## Notes
|
|
63
57
|
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
### Service drivers and configuration
|
|
59
|
+
Service providers are defined in a little bit of a weird nested way, this is supposed to help separate driver specific and instance specific configurations, and let you swap drivers in different application entry points without too many application dependencies.
|
|
66
60
|
|
|
67
|
-
|
|
68
|
-
# run this from the project root, it builds the utils and lambda packages,
|
|
69
|
-
# sets up build watchers for them, and then starts the react app.
|
|
70
|
-
# changes in any package are built and visible in the app immediately.
|
|
71
|
-
yarn start
|
|
72
|
-
```
|
|
61
|
+
an entry point is the file you point to when you build or run the application. the idea is that you make a different entry point files for different environments or contexts. so you have one for launching local development and one for launching an all-in-one stack on a testing server and another one for launching a production environment. in order to reduce environment specific issues you reduce your entry point to be as small as possible and just assemble the required bits for that environment to work. in the recommended setup, one of the main things the entry point does is choose which service provider drivers to use. there are two main benefits of using entry points, its more declarative than using downstream conditional logic with some kind of `driver: fs` flag in the config, and it allows bundled javascript to only include the dependencies relevant for the drivers that are being used in that build.
|
|
73
62
|
|
|
74
|
-
|
|
63
|
+
the idea is that you may have some entities you're putting in a VersionedDocumentStore and maybe some others in a RelationalEntityStore but you're for sure not putting some versioned entities in dynamo and some in a local json file. so in your development environment entry point you provide your config for `versionedDocumentStore: fileSystemVersionedDocumentStore` and in the deployed environment entry point you put `versionedDocumentStore: dynamoVersionedDocumentStore`.
|
|
75
64
|
|
|
76
|
-
|
|
65
|
+
there are two levels the drivers are configured at, one is the driver level and the other is the instance level. for the VersionedDocumentStore the fileSystem driver takes a path to the directory to store the files in. the instance level may vary based on the usage of that driver, for example if you're storing 4 different entities in VersionedDocumentStores, you need to provide different table names to the driver to configure each store to create separate instances of that store. it just happens that for VersionedDocumentStore the fileSystem and dynamo implementations use the same instance config, this isn't always the case. once you get into your application logic you won't know which entry point was used to bootstrap your application, so you'll just know the driver is _one of_ the possible versions, typescript will recognize this and throw an error unless you provide a config that would work for any of the possible drivers. in order to make this more legible (and separate key collisions), most of the services can be set up in the entry point with a config prefix, so when you get into application-land it looks more like you're providing two discrete configs.
|
|
77
66
|
|
|
78
|
-
|
|
79
|
-
- run `./packages/frontend/script/trust-localhost.bash` after starting the server
|
|
67
|
+
for example:
|
|
80
68
|
|
|
81
|
-
|
|
69
|
+
```typescript
|
|
70
|
+
// entry/anEntryPoint.ts
|
|
71
|
+
export const lambdaServices = {
|
|
72
|
+
// in this entry we provide the dynamo driver
|
|
73
|
+
versionedDocumentStore: dynamoVersionedDocumentStore({configSpace: 'dynamodb'}),
|
|
74
|
+
};
|
|
82
75
|
|
|
83
|
-
|
|
76
|
+
// entry/anotherEntryPoint.ts
|
|
77
|
+
export const localServices = {
|
|
78
|
+
// in this entry we provide the fileSystem driver, it has a different config prefix
|
|
79
|
+
versionedDocumentStore: fileSystemVersionedDocumentStore({dataDir, configSpace: 'fileSystem'}),
|
|
80
|
+
};
|
|
84
81
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
// core/types.ts
|
|
83
|
+
|
|
84
|
+
// there is other wiring up that happens with the app services on the request responder, if
|
|
85
|
+
// you made a new entrypoint and tried to use a different format of services without registering it
|
|
86
|
+
// here it would yell at you.
|
|
87
|
+
export type AppServices = LambdaServices | LocalServices;
|
|
88
|
+
|
|
89
|
+
// myCoolDocumentStoreMiddleware.ts
|
|
90
|
+
|
|
91
|
+
// this config satisfies both config drivers with separate sections for each one.
|
|
92
|
+
// the envConfig is defined here, but it wouldn't try to actually resolve that value
|
|
93
|
+
// unless it was being used.
|
|
94
|
+
const config = {
|
|
95
|
+
fileSystem: {
|
|
96
|
+
tableName: 'coolDocument'
|
|
97
|
+
},
|
|
98
|
+
dynamodb: {
|
|
99
|
+
tableName: envConfig('TestDocumentTableName', 'runtime'),
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const myCoolDocumentStoreMiddleware = <M extends {}>(app: AppServices) => {
|
|
104
|
+
// providing the document interface and the config prepares the driver to work for this entity in particular.
|
|
105
|
+
// the extra function call in this line is to work around some typescript quirkiness with generic type inference.
|
|
106
|
+
// this line is only run once when the app is wired up, doing this call here allows the driver to do internal memory caching
|
|
107
|
+
// if it wants to.
|
|
108
|
+
const makeCoolDocumentStore = app.versionedDocumentStore<CoolDocument>()(config);
|
|
109
|
+
|
|
110
|
+
return (middleware: M) => ({
|
|
111
|
+
...middleware,
|
|
112
|
+
// this part is run for every api request processed. in this case there it could have been combined with the call above,
|
|
113
|
+
// but most of the time you'll want to pull in the authProvider and hook up automatic audit logging, and that will be different on
|
|
114
|
+
// each request. look at the VersionedDocumentStore documentation for details.
|
|
115
|
+
coolDocumentStore: makeCoolDocumentStore('id'),
|
|
116
|
+
})
|
|
117
|
+
};
|
|
90
118
|
```
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export 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 & {
|
|
74
|
+
new (...args: any[]): T;
|
|
75
|
+
}, failed?: AssertionFailed) => T;
|
|
76
|
+
/**
|
|
77
|
+
* Asserts that the error in the first argument is an instance of the error given as the
|
|
78
|
+
* second argument
|
|
79
|
+
*
|
|
80
|
+
* @param thing The value to assert.
|
|
81
|
+
* @param constructable The error class to check against.
|
|
82
|
+
* @example const definitelySyntaxError = assertInstanceOf(error, SyntaxError);
|
|
83
|
+
* @returns the value that was asserted
|
|
84
|
+
* @throws the original error if the check fails
|
|
85
|
+
* @see assertInstanceOf
|
|
86
|
+
*/
|
|
87
|
+
export declare const assertErrorInstanceOf: <T extends Error>(thing: unknown, constructable: Function & {
|
|
88
|
+
new (...args: any[]): T;
|
|
89
|
+
}) => 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", defaultValue?: ConfigValueProvider<string>) => 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;
|
|
@@ -2,62 +2,46 @@
|
|
|
2
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
3
|
*/
|
|
4
4
|
export type ConfigValue = string;
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* A configuration object that may contain nested configuration objects or configuration values.
|
|
8
7
|
*/
|
|
9
|
-
export type Config = {
|
|
10
|
-
|
|
8
|
+
export type Config = {
|
|
9
|
+
[key: string]: Config | ConfigValue;
|
|
10
|
+
};
|
|
11
11
|
/**
|
|
12
12
|
* Either a function that returns a `ConfigValue` or a `Promise` that resolves to a `ConfigValue`,
|
|
13
13
|
* or just a `ConfigValue`.
|
|
14
14
|
*/
|
|
15
15
|
export type ConfigValueProvider<V extends ConfigValue = ConfigValue> = (() => Promise<V> | V) | V;
|
|
16
|
-
|
|
17
16
|
/**
|
|
18
17
|
* A configuration object that may contain nested configuration objects or configuration value providers.
|
|
19
18
|
*/
|
|
20
|
-
export type ConfigProvider = {
|
|
21
|
-
|
|
19
|
+
export type ConfigProvider = {
|
|
20
|
+
[key: string]: ConfigProvider | ConfigValueProvider;
|
|
21
|
+
};
|
|
22
22
|
/**
|
|
23
23
|
* Conditional type that resolves to the type of configuration object for the given configuration
|
|
24
24
|
* provider. Also resolves to a config value type if the given type is a config value.
|
|
25
25
|
*/
|
|
26
|
-
export type ConfigForConfigProvider<T> = T extends ConfigValue
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
? {[key in keyof T]: ConfigForConfigProvider<T[key]>}
|
|
30
|
-
: T extends ConfigValueProvider<infer R>
|
|
31
|
-
? R
|
|
32
|
-
: never;
|
|
33
|
-
|
|
26
|
+
export 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;
|
|
34
29
|
/**
|
|
35
30
|
* Conditional type that resolves to the `ConfigProvider` type for the given configuration
|
|
36
31
|
* type (`ConfigValue` or `Config`). The resulting type is either a `ConfigValueProvider` or
|
|
37
32
|
* a `ConfigProvider`.
|
|
38
33
|
*/
|
|
39
|
-
export type ConfigProviderForConfig<T> = T extends ConfigValue
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
? {[key in keyof T]: ConfigProviderForConfig<T[key]>}
|
|
43
|
-
: never;
|
|
44
|
-
|
|
34
|
+
export type ConfigProviderForConfig<T> = T extends ConfigValue ? ConfigValueProvider<T> : T extends Config ? {
|
|
35
|
+
[key in keyof T]: ConfigProviderForConfig<T[key]>;
|
|
36
|
+
} : never;
|
|
45
37
|
export * from './resolveConfigValue';
|
|
46
|
-
|
|
47
|
-
/*
|
|
48
|
-
* ===========
|
|
49
|
-
* re-usable config providers
|
|
50
|
-
* ===========
|
|
51
|
-
* */
|
|
52
|
-
|
|
53
38
|
/**
|
|
54
39
|
* stub, mostly for testing. sometimes it helps please typescript to use this if you have
|
|
55
40
|
* two configs you want to have the same type but one is a fixed string and one is a complicated provider
|
|
56
41
|
*
|
|
57
42
|
* @example const config = { configValue: stubConfig('just-a-string') };
|
|
58
43
|
*/
|
|
59
|
-
export const stubConfig
|
|
60
|
-
|
|
44
|
+
export declare const stubConfig: <V extends ConfigValue>(configValue: V) => ConfigValueProvider<V>;
|
|
61
45
|
export * from './envConfig';
|
|
62
46
|
export * from './replaceConfig';
|
|
63
47
|
export * from './awsParameterConfig';
|