@openstax/ts-utils 1.33.0 → 1.34.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/.cfnlintrc +2 -0
- package/.github/CODEOWNERS +1 -0
- package/.github/workflows/ci.yml +36 -0
- package/.github/workflows/lint.yml +55 -0
- package/.nvmrc +1 -0
- package/.syncignore +4 -0
- package/.syncpackrc +18 -0
- package/CONTRIBUTING.md +96 -0
- package/LICENSE +661 -0
- package/Procfile +1 -0
- package/README.md +62 -90
- package/app.json +23 -0
- package/cspell.json +32 -0
- package/deploy/constants.env +21 -0
- package/deploy/deploy.bash +157 -0
- package/deploy/deployment-alt-region.cfn.yml +70 -0
- package/deploy/deployment.cfn.yml +650 -0
- package/deploy/destroy-deployment.bash +23 -0
- package/deploy/shared.cfn.yml +94 -0
- package/docs/lambda-build.md +35 -0
- package/package.json +12 -228
- package/packages/frontend/README.md +46 -0
- package/packages/frontend/package.json +101 -0
- package/packages/frontend/public/favicon.ico +0 -0
- package/packages/frontend/public/index.html +107 -0
- package/packages/frontend/public/maintenance.html +59 -0
- package/packages/frontend/public/manifest.json +15 -0
- package/packages/frontend/public/robots.txt +3 -0
- package/packages/frontend/script/make-certificate.bash +49 -0
- package/packages/frontend/script/server/cli.js +11 -0
- package/packages/frontend/script/server/index.js +47 -0
- package/packages/frontend/script/start.bash +22 -0
- package/packages/frontend/script/trust-localhost.bash +7 -0
- package/packages/frontend/src/auth/authProvider.ts +10 -0
- package/packages/frontend/src/auth/useAuth.ts +33 -0
- package/packages/frontend/src/components/Pagination.tsx +26 -0
- package/packages/frontend/src/configProvider/index.ts +53 -0
- package/packages/frontend/src/configProvider/use.ts +41 -0
- package/packages/frontend/src/core/context/services.spec.tsx +39 -0
- package/packages/frontend/src/core/context/services.tsx +16 -0
- package/packages/frontend/src/core/index.spec.ts +7 -0
- package/packages/frontend/src/core/index.ts +20 -0
- package/packages/frontend/src/core/services.tsx +14 -0
- package/packages/frontend/src/core/types.ts +3 -0
- package/packages/frontend/src/example/api.ts +28 -0
- package/packages/frontend/src/example/components/Layout.tsx +23 -0
- package/packages/frontend/src/example/screens/Home.spec.tsx +68 -0
- package/packages/frontend/src/example/screens/Home.tsx +78 -0
- package/packages/frontend/src/example/screens/ThingList.spec.tsx +60 -0
- package/packages/frontend/src/example/screens/ThingList.tsx +75 -0
- package/packages/frontend/src/example/screens/ThingView.spec.tsx +71 -0
- package/packages/frontend/src/example/screens/ThingView.tsx +47 -0
- package/packages/frontend/src/example/screens/index.ts +9 -0
- package/packages/frontend/src/index.css +159 -0
- package/packages/frontend/src/index.tsx +67 -0
- package/packages/frontend/src/react-app-env.d.ts +1 -0
- package/packages/frontend/src/routing/components/RouteLink.spec.tsx +55 -0
- package/packages/frontend/src/routing/components/RouteLink.tsx +35 -0
- package/packages/frontend/src/routing/middleware.ts +6 -0
- package/packages/frontend/src/routing/useQuery.ts +14 -0
- package/packages/frontend/src/setupProxy.js +19 -0
- package/packages/frontend/src/setupTests.ts +9 -0
- package/packages/frontend/src/tests/testServices.tsx +23 -0
- package/packages/frontend/tsconfig.json +27 -0
- package/packages/lambda/.eslintrc.js +64 -0
- package/packages/lambda/jest-global-setup.js +3 -0
- package/packages/lambda/jest-setup-after-env.js +1 -0
- package/packages/lambda/jest.config.js +31 -0
- package/packages/lambda/jest.resolver.js +17 -0
- package/packages/lambda/package.json +68 -0
- package/packages/lambda/script/build.bash +19 -0
- package/packages/lambda/script/bundle-functions.bash +10 -0
- package/packages/lambda/script/lambdaLocalProxy.js +16 -0
- package/packages/lambda/script/lambdaLocalProxy.spec.ts +147 -0
- package/packages/lambda/script/utils/getRouteData.ts +7 -0
- package/packages/lambda/script/utils/routeDataLoader.js +8 -0
- package/packages/lambda/script/utils/routeDataLoader.spec.ts +8 -0
- package/packages/lambda/src/functions/serviceApi/core/index.ts +7 -0
- package/packages/lambda/src/functions/serviceApi/core/request.spec.ts +38 -0
- package/packages/lambda/src/functions/serviceApi/core/request.ts +42 -0
- package/packages/lambda/src/functions/serviceApi/core/routes.spec.ts +7 -0
- package/packages/lambda/src/functions/serviceApi/core/routes.ts +10 -0
- package/packages/lambda/src/functions/serviceApi/core/services.ts +9 -0
- package/packages/lambda/src/functions/serviceApi/core/types.ts +13 -0
- package/packages/lambda/src/functions/serviceApi/entry/lambda/https-xray.ts +4 -0
- package/packages/lambda/src/functions/serviceApi/entry/lambda/index.spec.ts +48 -0
- package/packages/lambda/src/functions/serviceApi/entry/lambda/index.ts +58 -0
- package/packages/lambda/src/functions/serviceApi/entry/lambda/services.ts +36 -0
- package/packages/lambda/src/functions/serviceApi/entry/local.ts +71 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/example/documentSearchMiddleware.spec.ts +16 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/example/documentSearchMiddleware.ts +41 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/example/documentStoreMiddleware.spec.ts +78 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/example/documentStoreMiddleware.ts +70 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/example/routes.spec.ts +306 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/example/routes.ts +176 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/index.spec.ts +263 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/index.ts +134 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/authMiddleware.spec.ts +23 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/authMiddleware.ts +32 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/configMiddleware.spec.ts +10 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/configMiddleware.ts +7 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/frontendFileServerMiddleware.spec.ts +13 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/frontendFileServerMiddleware.ts +23 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/paginationMiddleware.spec.ts +9 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/paginationMiddleware.ts +9 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/searchMiddleware.spec.ts +12 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/searchMiddleware.ts +21 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/userRoleValidatorMiddleware.spec.ts +21 -0
- package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/userRoleValidatorMiddleware.ts +18 -0
- package/packages/lambda/tsconfig.json +30 -0
- package/packages/lambda/webpack.config.js +97 -0
- package/packages/utils/.eslintrc.js +64 -0
- package/packages/utils/README.md +118 -0
- package/packages/utils/jest-global-setup.js +3 -0
- package/packages/utils/jest.config.js +25 -0
- package/packages/utils/jest.resolver.js +17 -0
- package/packages/utils/package.json +238 -0
- package/packages/utils/src/assertions/index.spec.ts +126 -0
- package/{dist/esm/assertions/index.js → packages/utils/src/assertions/index.ts} +64 -49
- package/packages/utils/src/aws/ssmService.ts +7 -0
- package/packages/utils/src/config/awsParameterConfig.ts +24 -0
- package/packages/utils/src/config/envConfig.ts +58 -0
- package/packages/utils/src/config/index.spec.ts +165 -0
- package/{dist/esm/config/index.d.ts → packages/utils/src/config/index.ts} +29 -13
- package/packages/utils/src/config/lambdaParameterConfig.ts +49 -0
- package/{dist/esm/config/replaceConfig.js → packages/utils/src/config/replaceConfig.ts} +16 -6
- package/packages/utils/src/config/resolveConfigValue.ts +10 -0
- package/packages/utils/src/errors/index.spec.ts +35 -0
- package/{dist/esm/errors/index.js → packages/utils/src/errors/index.ts} +57 -41
- package/packages/utils/src/fetch/fetchStatusRetry.spec.ts +197 -0
- package/packages/utils/src/fetch/fetchStatusRetry.ts +33 -0
- package/packages/utils/src/fetch/index.spec.ts +34 -0
- package/packages/utils/src/fetch/index.ts +87 -0
- package/packages/utils/src/guards/index.spec.ts +58 -0
- package/{dist/esm/guards/index.d.ts → packages/utils/src/guards/index.ts} +10 -7
- package/packages/utils/src/index.spec.ts +471 -0
- package/packages/utils/src/middleware/apiErrorHandler.spec.ts +65 -0
- package/packages/utils/src/middleware/apiErrorHandler.ts +67 -0
- package/packages/utils/src/middleware/apiSlowResponseMiddleware.spec.ts +184 -0
- package/packages/utils/src/middleware/apiSlowResponseMiddleware.ts +71 -0
- package/packages/utils/src/middleware/index.spec.ts +99 -0
- package/{dist/cjs/middleware/index.d.ts → packages/utils/src/middleware/index.ts} +53 -5
- package/packages/utils/src/middleware/lambdaCorsResponseMiddleware.spec.ts +103 -0
- package/packages/utils/src/middleware/lambdaCorsResponseMiddleware.ts +52 -0
- package/packages/utils/src/middleware/throwNotFoundMiddleware.spec.ts +20 -0
- package/packages/utils/src/middleware/throwNotFoundMiddleware.ts +11 -0
- package/packages/utils/src/misc/hashValue.ts +18 -0
- package/packages/utils/src/misc/helpers.ts +259 -0
- package/packages/utils/src/misc/merge.ts +48 -0
- package/{dist/esm/misc/partitionSequence.js → packages/utils/src/misc/partitionSequence.ts} +23 -15
- package/packages/utils/src/pagination/index.spec.ts +150 -0
- package/packages/utils/src/pagination/index.ts +117 -0
- package/{dist/esm/routing/helpers.js → packages/utils/src/routing/helpers.ts} +42 -30
- package/packages/utils/src/routing/index.spec.ts +553 -0
- package/packages/utils/src/routing/index.ts +424 -0
- package/packages/utils/src/routing/validators/zod.spec.ts +16 -0
- package/packages/utils/src/routing/validators/zod.ts +14 -0
- package/packages/utils/src/services/accountsGateway/README.md +3 -0
- package/packages/utils/src/services/accountsGateway/index.spec.ts +518 -0
- package/packages/utils/src/services/accountsGateway/index.ts +251 -0
- package/packages/utils/src/services/apiGateway/README.md +93 -0
- package/packages/utils/src/services/apiGateway/index.spec.ts +254 -0
- package/packages/utils/src/services/apiGateway/index.ts +189 -0
- package/packages/utils/src/services/authProvider/README.md +21 -0
- package/packages/utils/src/services/authProvider/browser.spec.ts +391 -0
- package/packages/utils/src/services/authProvider/browser.ts +209 -0
- package/packages/utils/src/services/authProvider/decryption.spec.ts +337 -0
- package/packages/utils/src/services/authProvider/decryption.ts +98 -0
- package/packages/utils/src/services/authProvider/index.ts +93 -0
- package/packages/utils/src/services/authProvider/stub.spec.ts +29 -0
- package/packages/utils/src/services/authProvider/subrequest.spec.ts +105 -0
- package/packages/utils/src/services/authProvider/subrequest.ts +68 -0
- package/packages/utils/src/services/authProvider/utils/decryptAndVerify.spec.ts +128 -0
- package/packages/utils/src/services/authProvider/utils/decryptAndVerify.ts +106 -0
- package/packages/utils/src/services/authProvider/utils/embeddedAuthProvider.spec.ts +26 -0
- package/packages/utils/src/services/authProvider/utils/embeddedAuthProvider.ts +57 -0
- package/packages/utils/src/services/authProvider/utils/userRoleValidator.spec.ts +135 -0
- package/packages/utils/src/services/authProvider/utils/userRoleValidator.ts +49 -0
- package/packages/utils/src/services/authProvider/utils/userSubrequest.spec.ts +26 -0
- package/packages/utils/src/services/authProvider/utils/userSubrequest.ts +10 -0
- package/packages/utils/src/services/documentStore/dynamoEncoding.ts +57 -0
- package/packages/utils/src/services/documentStore/fileSystemAssert.spec.ts +43 -0
- package/packages/utils/src/services/documentStore/fileSystemAssert.ts +10 -0
- package/{dist/cjs/services/documentStore/index.d.ts → packages/utils/src/services/documentStore/index.ts} +8 -8
- package/packages/utils/src/services/documentStore/unversioned/README.md +13 -0
- package/packages/utils/src/services/documentStore/unversioned/dynamodb.spec.ts +859 -0
- package/packages/utils/src/services/documentStore/unversioned/dynamodb.ts +243 -0
- package/packages/utils/src/services/documentStore/unversioned/file-system.spec.ts +629 -0
- package/packages/utils/src/services/documentStore/unversioned/file-system.ts +194 -0
- package/{dist/cjs/services/documentStore/unversioned/index.d.ts → packages/utils/src/services/documentStore/unversioned/index.ts} +2 -0
- package/packages/utils/src/services/documentStore/versioned/README.md +13 -0
- package/packages/utils/src/services/documentStore/versioned/dynamodb.spec.ts +376 -0
- package/packages/utils/src/services/documentStore/versioned/dynamodb.ts +167 -0
- package/packages/utils/src/services/documentStore/versioned/file-system.spec.ts +262 -0
- package/packages/utils/src/services/documentStore/versioned/file-system.ts +90 -0
- package/packages/utils/src/services/documentStore/versioned/index.ts +25 -0
- package/packages/utils/src/services/exercisesGateway/README.md +5 -0
- package/packages/utils/src/services/exercisesGateway/index.spec.ts +326 -0
- package/packages/utils/src/services/exercisesGateway/index.ts +163 -0
- package/packages/utils/src/services/fileServer/index.spec.ts +88 -0
- package/packages/utils/src/services/fileServer/index.ts +43 -0
- package/packages/utils/src/services/fileServer/localFileServer.spec.ts +182 -0
- package/packages/utils/src/services/fileServer/localFileServer.ts +159 -0
- package/packages/utils/src/services/fileServer/s3FileServer.spec.ts +266 -0
- package/packages/utils/src/services/fileServer/s3FileServer.ts +155 -0
- package/packages/utils/src/services/launchParams/index.spec.ts +366 -0
- package/packages/utils/src/services/launchParams/signer.ts +73 -0
- package/packages/utils/src/services/launchParams/verifier.ts +120 -0
- package/packages/utils/src/services/logger/console.spec.ts +29 -0
- package/{dist/esm/services/logger/console.js → packages/utils/src/services/logger/console.ts} +5 -2
- package/packages/utils/src/services/logger/index.spec.ts +65 -0
- package/{dist/esm/services/logger/index.d.ts → packages/utils/src/services/logger/index.ts} +23 -9
- package/packages/utils/src/services/lrsGateway/README.md +5 -0
- package/packages/utils/src/services/lrsGateway/addStatementDefaultFields.ts +22 -0
- package/packages/utils/src/services/lrsGateway/attempt-utils.spec.ts +847 -0
- package/packages/utils/src/services/lrsGateway/attempt-utils.ts +358 -0
- package/packages/utils/src/services/lrsGateway/file-system.spec.ts +363 -0
- package/packages/utils/src/services/lrsGateway/file-system.ts +165 -0
- package/packages/utils/src/services/lrsGateway/index.spec.ts +194 -0
- package/packages/utils/src/services/lrsGateway/index.ts +257 -0
- package/packages/utils/src/services/lrsGateway/xapiUtils.spec.ts +887 -0
- package/packages/utils/src/services/lrsGateway/xapiUtils.ts +262 -0
- package/packages/utils/src/services/postgresConnection/index.spec.ts +170 -0
- package/packages/utils/src/services/postgresConnection/index.ts +84 -0
- package/packages/utils/src/services/searchProvider/README.md +3 -0
- package/packages/utils/src/services/searchProvider/index.ts +59 -0
- package/packages/utils/src/services/searchProvider/memorySearchTheBadWay.spec.ts +526 -0
- package/packages/utils/src/services/searchProvider/memorySearchTheBadWay.ts +223 -0
- package/packages/utils/src/services/searchProvider/openSearch.spec.ts +926 -0
- package/packages/utils/src/services/searchProvider/openSearch.ts +195 -0
- package/{dist/esm/types.d.ts → packages/utils/src/types.ts} +34 -6
- package/packages/utils/tsconfig.json +31 -0
- package/packages/utils/tsconfig.without-specs.cjs.json +7 -0
- package/packages/utils/tsconfig.without-specs.esm.json +7 -0
- package/packages/utils/tsconfig.without-specs.json +6 -0
- package/scripts/build.bash +24 -0
- package/scripts/ci.bash +10 -0
- package/scripts/start.bash +29 -0
- package/dist/cjs/assertions/index.d.ts +0 -89
- package/dist/cjs/assertions/index.js +0 -157
- package/dist/cjs/aws/ssmService.d.ts +0 -5
- package/dist/cjs/aws/ssmService.js +0 -9
- package/dist/cjs/config/awsParameterConfig.d.ts +0 -10
- package/dist/cjs/config/awsParameterConfig.js +0 -26
- package/dist/cjs/config/envConfig.d.ts +0 -24
- package/dist/cjs/config/envConfig.js +0 -57
- package/dist/cjs/config/index.d.ts +0 -48
- package/dist/cjs/config/index.js +0 -35
- package/dist/cjs/config/lambdaParameterConfig.d.ts +0 -12
- package/dist/cjs/config/lambdaParameterConfig.js +0 -45
- package/dist/cjs/config/replaceConfig.d.ts +0 -14
- package/dist/cjs/config/replaceConfig.js +0 -22
- package/dist/cjs/config/resolveConfigValue.d.ts +0 -5
- package/dist/cjs/config/resolveConfigValue.js +0 -12
- package/dist/cjs/errors/index.d.ts +0 -88
- package/dist/cjs/errors/index.js +0 -123
- package/dist/cjs/fetch/fetchStatusRetry.d.ts +0 -8
- package/dist/cjs/fetch/fetchStatusRetry.js +0 -27
- package/dist/cjs/fetch/index.d.ts +0 -64
- package/dist/cjs/fetch/index.js +0 -55
- package/dist/cjs/guards/index.d.ts +0 -38
- package/dist/cjs/guards/index.js +0 -44
- package/dist/cjs/index.js +0 -20
- package/dist/cjs/middleware/apiErrorHandler.d.ts +0 -24
- package/dist/cjs/middleware/apiErrorHandler.js +0 -42
- package/dist/cjs/middleware/apiSlowResponseMiddleware.d.ts +0 -23
- package/dist/cjs/middleware/apiSlowResponseMiddleware.js +0 -54
- package/dist/cjs/middleware/index.js +0 -48
- package/dist/cjs/middleware/lambdaCorsResponseMiddleware.d.ts +0 -20
- package/dist/cjs/middleware/lambdaCorsResponseMiddleware.js +0 -44
- package/dist/cjs/middleware/throwNotFoundMiddleware.d.ts +0 -4
- package/dist/cjs/middleware/throwNotFoundMiddleware.js +0 -14
- package/dist/cjs/misc/hashValue.d.ts +0 -10
- package/dist/cjs/misc/hashValue.js +0 -17
- package/dist/cjs/misc/helpers.d.ts +0 -124
- package/dist/cjs/misc/helpers.js +0 -214
- package/dist/cjs/misc/merge.d.ts +0 -21
- package/dist/cjs/misc/merge.js +0 -45
- package/dist/cjs/misc/partitionSequence.d.ts +0 -35
- package/dist/cjs/misc/partitionSequence.js +0 -55
- package/dist/cjs/pagination/index.d.ts +0 -91
- package/dist/cjs/pagination/index.js +0 -83
- package/dist/cjs/routing/helpers.d.ts +0 -57
- package/dist/cjs/routing/helpers.js +0 -90
- package/dist/cjs/routing/index.d.ts +0 -290
- package/dist/cjs/routing/index.js +0 -295
- package/dist/cjs/routing/validators/zod.d.ts +0 -4
- package/dist/cjs/routing/validators/zod.js +0 -14
- package/dist/cjs/services/accountsGateway/index.d.ts +0 -92
- package/dist/cjs/services/accountsGateway/index.js +0 -138
- package/dist/cjs/services/apiGateway/index.d.ts +0 -68
- package/dist/cjs/services/apiGateway/index.js +0 -118
- package/dist/cjs/services/authProvider/browser.d.ts +0 -40
- package/dist/cjs/services/authProvider/browser.js +0 -155
- package/dist/cjs/services/authProvider/decryption.d.ts +0 -19
- package/dist/cjs/services/authProvider/decryption.js +0 -73
- package/dist/cjs/services/authProvider/index.d.ts +0 -63
- package/dist/cjs/services/authProvider/index.js +0 -34
- package/dist/cjs/services/authProvider/subrequest.d.ts +0 -13
- package/dist/cjs/services/authProvider/subrequest.js +0 -49
- package/dist/cjs/services/authProvider/utils/decryptAndVerify.d.ts +0 -28
- package/dist/cjs/services/authProvider/utils/decryptAndVerify.js +0 -91
- package/dist/cjs/services/authProvider/utils/embeddedAuthProvider.d.ts +0 -26
- package/dist/cjs/services/authProvider/utils/embeddedAuthProvider.js +0 -47
- package/dist/cjs/services/authProvider/utils/userRoleValidator.d.ts +0 -13
- package/dist/cjs/services/authProvider/utils/userRoleValidator.js +0 -37
- package/dist/cjs/services/authProvider/utils/userSubrequest.d.ts +0 -3
- package/dist/cjs/services/authProvider/utils/userSubrequest.js +0 -13
- package/dist/cjs/services/documentStore/dynamoEncoding.d.ts +0 -10
- package/dist/cjs/services/documentStore/dynamoEncoding.js +0 -52
- package/dist/cjs/services/documentStore/fileSystemAssert.d.ts +0 -1
- package/dist/cjs/services/documentStore/fileSystemAssert.js +0 -14
- package/dist/cjs/services/documentStore/index.js +0 -2
- package/dist/cjs/services/documentStore/unversioned/dynamodb.d.ts +0 -31
- package/dist/cjs/services/documentStore/unversioned/dynamodb.js +0 -233
- package/dist/cjs/services/documentStore/unversioned/file-system.d.ts +0 -32
- package/dist/cjs/services/documentStore/unversioned/file-system.js +0 -214
- package/dist/cjs/services/documentStore/unversioned/index.js +0 -2
- package/dist/cjs/services/documentStore/versioned/dynamodb.d.ts +0 -25
- package/dist/cjs/services/documentStore/versioned/dynamodb.js +0 -143
- package/dist/cjs/services/documentStore/versioned/file-system.d.ts +0 -25
- package/dist/cjs/services/documentStore/versioned/file-system.js +0 -73
- package/dist/cjs/services/documentStore/versioned/index.d.ts +0 -17
- package/dist/cjs/services/documentStore/versioned/index.js +0 -2
- package/dist/cjs/services/exercisesGateway/index.d.ts +0 -67
- package/dist/cjs/services/exercisesGateway/index.js +0 -107
- package/dist/cjs/services/fileServer/index.d.ts +0 -30
- package/dist/cjs/services/fileServer/index.js +0 -19
- package/dist/cjs/services/fileServer/localFileServer.d.ts +0 -13
- package/dist/cjs/services/fileServer/localFileServer.js +0 -132
- package/dist/cjs/services/fileServer/s3FileServer.d.ts +0 -14
- package/dist/cjs/services/fileServer/s3FileServer.js +0 -131
- package/dist/cjs/services/launchParams/index.js +0 -7
- package/dist/cjs/services/launchParams/signer.d.ts +0 -23
- package/dist/cjs/services/launchParams/signer.js +0 -58
- package/dist/cjs/services/launchParams/verifier.d.ts +0 -21
- package/dist/cjs/services/launchParams/verifier.js +0 -129
- package/dist/cjs/services/logger/console.d.ts +0 -4
- package/dist/cjs/services/logger/console.js +0 -12
- package/dist/cjs/services/logger/index.d.ts +0 -39
- package/dist/cjs/services/logger/index.js +0 -31
- package/dist/cjs/services/lrsGateway/addStatementDefaultFields.d.ts +0 -5
- package/dist/cjs/services/lrsGateway/addStatementDefaultFields.js +0 -21
- package/dist/cjs/services/lrsGateway/attempt-utils.d.ts +0 -70
- package/dist/cjs/services/lrsGateway/attempt-utils.js +0 -258
- package/dist/cjs/services/lrsGateway/file-system.d.ts +0 -15
- package/dist/cjs/services/lrsGateway/file-system.js +0 -150
- package/dist/cjs/services/lrsGateway/index.d.ts +0 -122
- package/dist/cjs/services/lrsGateway/index.js +0 -148
- package/dist/cjs/services/lrsGateway/xapiUtils.d.ts +0 -68
- package/dist/cjs/services/lrsGateway/xapiUtils.js +0 -109
- package/dist/cjs/services/postgresConnection/index.d.ts +0 -28
- package/dist/cjs/services/postgresConnection/index.js +0 -65
- package/dist/cjs/services/searchProvider/index.d.ts +0 -67
- package/dist/cjs/services/searchProvider/index.js +0 -2
- package/dist/cjs/services/searchProvider/memorySearchTheBadWay.d.ts +0 -20
- package/dist/cjs/services/searchProvider/memorySearchTheBadWay.js +0 -191
- package/dist/cjs/services/searchProvider/openSearch.d.ts +0 -28
- package/dist/cjs/services/searchProvider/openSearch.js +0 -154
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +0 -1
- package/dist/cjs/types.d.ts +0 -31
- package/dist/cjs/types.js +0 -2
- package/dist/esm/assertions/index.d.ts +0 -89
- package/dist/esm/aws/ssmService.d.ts +0 -5
- package/dist/esm/aws/ssmService.js +0 -6
- package/dist/esm/config/awsParameterConfig.d.ts +0 -10
- package/dist/esm/config/awsParameterConfig.js +0 -22
- package/dist/esm/config/envConfig.d.ts +0 -24
- package/dist/esm/config/envConfig.js +0 -53
- package/dist/esm/config/index.js +0 -17
- package/dist/esm/config/lambdaParameterConfig.d.ts +0 -12
- package/dist/esm/config/lambdaParameterConfig.js +0 -38
- package/dist/esm/config/replaceConfig.d.ts +0 -14
- package/dist/esm/config/resolveConfigValue.d.ts +0 -5
- package/dist/esm/config/resolveConfigValue.js +0 -8
- package/dist/esm/errors/index.d.ts +0 -88
- package/dist/esm/fetch/fetchStatusRetry.d.ts +0 -8
- package/dist/esm/fetch/fetchStatusRetry.js +0 -23
- package/dist/esm/fetch/index.d.ts +0 -64
- package/dist/esm/fetch/index.js +0 -46
- package/dist/esm/guards/index.js +0 -36
- package/dist/esm/index.d.ts +0 -4
- package/dist/esm/index.js +0 -4
- package/dist/esm/middleware/apiErrorHandler.d.ts +0 -24
- package/dist/esm/middleware/apiErrorHandler.js +0 -38
- package/dist/esm/middleware/apiSlowResponseMiddleware.d.ts +0 -23
- package/dist/esm/middleware/apiSlowResponseMiddleware.js +0 -50
- package/dist/esm/middleware/index.d.ts +0 -47
- package/dist/esm/middleware/index.js +0 -44
- package/dist/esm/middleware/lambdaCorsResponseMiddleware.d.ts +0 -20
- package/dist/esm/middleware/lambdaCorsResponseMiddleware.js +0 -40
- package/dist/esm/middleware/throwNotFoundMiddleware.d.ts +0 -4
- package/dist/esm/middleware/throwNotFoundMiddleware.js +0 -10
- package/dist/esm/misc/hashValue.d.ts +0 -10
- package/dist/esm/misc/hashValue.js +0 -13
- package/dist/esm/misc/helpers.d.ts +0 -124
- package/dist/esm/misc/helpers.js +0 -199
- package/dist/esm/misc/merge.d.ts +0 -21
- package/dist/esm/misc/merge.js +0 -40
- package/dist/esm/misc/partitionSequence.d.ts +0 -35
- package/dist/esm/pagination/index.d.ts +0 -91
- package/dist/esm/pagination/index.js +0 -77
- package/dist/esm/routing/helpers.d.ts +0 -57
- package/dist/esm/routing/index.d.ts +0 -290
- package/dist/esm/routing/index.js +0 -246
- package/dist/esm/routing/validators/zod.d.ts +0 -4
- package/dist/esm/routing/validators/zod.js +0 -10
- package/dist/esm/services/accountsGateway/index.d.ts +0 -92
- package/dist/esm/services/accountsGateway/index.js +0 -131
- package/dist/esm/services/apiGateway/index.d.ts +0 -68
- package/dist/esm/services/apiGateway/index.js +0 -77
- package/dist/esm/services/authProvider/browser.d.ts +0 -40
- package/dist/esm/services/authProvider/browser.js +0 -151
- package/dist/esm/services/authProvider/decryption.d.ts +0 -19
- package/dist/esm/services/authProvider/decryption.js +0 -69
- package/dist/esm/services/authProvider/index.d.ts +0 -63
- package/dist/esm/services/authProvider/index.js +0 -26
- package/dist/esm/services/authProvider/subrequest.d.ts +0 -13
- package/dist/esm/services/authProvider/subrequest.js +0 -45
- package/dist/esm/services/authProvider/utils/decryptAndVerify.d.ts +0 -28
- package/dist/esm/services/authProvider/utils/decryptAndVerify.js +0 -85
- package/dist/esm/services/authProvider/utils/embeddedAuthProvider.d.ts +0 -26
- package/dist/esm/services/authProvider/utils/embeddedAuthProvider.js +0 -40
- package/dist/esm/services/authProvider/utils/userRoleValidator.d.ts +0 -13
- package/dist/esm/services/authProvider/utils/userRoleValidator.js +0 -33
- package/dist/esm/services/authProvider/utils/userSubrequest.d.ts +0 -3
- package/dist/esm/services/authProvider/utils/userSubrequest.js +0 -6
- package/dist/esm/services/documentStore/dynamoEncoding.d.ts +0 -10
- package/dist/esm/services/documentStore/dynamoEncoding.js +0 -45
- package/dist/esm/services/documentStore/fileSystemAssert.d.ts +0 -1
- package/dist/esm/services/documentStore/fileSystemAssert.js +0 -10
- package/dist/esm/services/documentStore/index.d.ts +0 -14
- package/dist/esm/services/documentStore/index.js +0 -1
- package/dist/esm/services/documentStore/unversioned/dynamodb.d.ts +0 -31
- package/dist/esm/services/documentStore/unversioned/dynamodb.js +0 -226
- package/dist/esm/services/documentStore/unversioned/file-system.d.ts +0 -32
- package/dist/esm/services/documentStore/unversioned/file-system.js +0 -174
- package/dist/esm/services/documentStore/unversioned/index.d.ts +0 -2
- package/dist/esm/services/documentStore/unversioned/index.js +0 -1
- package/dist/esm/services/documentStore/versioned/dynamodb.d.ts +0 -25
- package/dist/esm/services/documentStore/versioned/dynamodb.js +0 -139
- package/dist/esm/services/documentStore/versioned/file-system.d.ts +0 -25
- package/dist/esm/services/documentStore/versioned/file-system.js +0 -69
- package/dist/esm/services/documentStore/versioned/index.d.ts +0 -17
- package/dist/esm/services/documentStore/versioned/index.js +0 -1
- package/dist/esm/services/exercisesGateway/index.d.ts +0 -67
- package/dist/esm/services/exercisesGateway/index.js +0 -70
- package/dist/esm/services/fileServer/index.d.ts +0 -30
- package/dist/esm/services/fileServer/index.js +0 -13
- package/dist/esm/services/fileServer/localFileServer.d.ts +0 -13
- package/dist/esm/services/fileServer/localFileServer.js +0 -125
- package/dist/esm/services/fileServer/s3FileServer.d.ts +0 -14
- package/dist/esm/services/fileServer/s3FileServer.js +0 -124
- package/dist/esm/services/launchParams/index.d.ts +0 -2
- package/dist/esm/services/launchParams/index.js +0 -2
- package/dist/esm/services/launchParams/signer.d.ts +0 -23
- package/dist/esm/services/launchParams/signer.js +0 -51
- package/dist/esm/services/launchParams/verifier.d.ts +0 -21
- package/dist/esm/services/launchParams/verifier.js +0 -92
- package/dist/esm/services/logger/console.d.ts +0 -4
- package/dist/esm/services/logger/index.js +0 -27
- package/dist/esm/services/lrsGateway/addStatementDefaultFields.d.ts +0 -5
- package/dist/esm/services/lrsGateway/addStatementDefaultFields.js +0 -14
- package/dist/esm/services/lrsGateway/attempt-utils.d.ts +0 -70
- package/dist/esm/services/lrsGateway/attempt-utils.js +0 -236
- package/dist/esm/services/lrsGateway/file-system.d.ts +0 -15
- package/dist/esm/services/lrsGateway/file-system.js +0 -110
- package/dist/esm/services/lrsGateway/index.d.ts +0 -122
- package/dist/esm/services/lrsGateway/index.js +0 -111
- package/dist/esm/services/lrsGateway/xapiUtils.d.ts +0 -68
- package/dist/esm/services/lrsGateway/xapiUtils.js +0 -99
- package/dist/esm/services/postgresConnection/index.d.ts +0 -28
- package/dist/esm/services/postgresConnection/index.js +0 -58
- package/dist/esm/services/searchProvider/index.d.ts +0 -67
- package/dist/esm/services/searchProvider/index.js +0 -1
- package/dist/esm/services/searchProvider/memorySearchTheBadWay.d.ts +0 -20
- package/dist/esm/services/searchProvider/memorySearchTheBadWay.js +0 -187
- package/dist/esm/services/searchProvider/openSearch.d.ts +0 -28
- package/dist/esm/services/searchProvider/openSearch.js +0 -150
- package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +0 -1
- package/dist/esm/types.js +0 -1
- /package/{script → packages/utils/script}/bin/copy-from-template.bash +0 -0
- /package/{script → packages/utils/script}/bin/delete-stack.bash +0 -0
- /package/{script → packages/utils/script}/bin/deploy.bash +0 -0
- /package/{script → packages/utils/script}/bin/destroy-deployment.bash +0 -0
- /package/{script → packages/utils/script}/bin/empty-bucket.bash +0 -0
- /package/{script → packages/utils/script}/bin/get-arg.bash +0 -0
- /package/{script → packages/utils/script}/bin/get-deployed-environments.bash +0 -0
- /package/{script → packages/utils/script}/bin/get-env-param.bash +0 -0
- /package/{script → packages/utils/script}/bin/get-kwarg.bash +0 -0
- /package/{script → packages/utils/script}/bin/get-stack-param.bash +0 -0
- /package/{script → packages/utils/script}/bin/has-flag.bash +0 -0
- /package/{script → packages/utils/script}/bin/init-constants-script.bash +0 -0
- /package/{script → packages/utils/script}/bin/init-params-script.bash +0 -0
- /package/{script → packages/utils/script}/bin/stack-exists.bash +0 -0
- /package/{script → packages/utils/script}/bin/update-utils.bash +0 -0
- /package/{script → packages/utils/script}/bin/upload-pager-duty-endpoints.bash +0 -0
- /package/{script → packages/utils/script}/bin/upload-params.bash +0 -0
- /package/{script → packages/utils/script}/bin/which.bash +0 -0
- /package/{script → packages/utils/script}/bin-entry.bash +0 -0
- /package/{script → packages/utils/script}/build.bash +0 -0
- /package/{dist/cjs/index.d.ts → packages/utils/src/index.ts} +0 -0
- /package/{dist/cjs/services/launchParams/index.d.ts → packages/utils/src/services/launchParams/index.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,118 +1,90 @@
|
|
|
1
|
-
|
|
1
|
+
<!-- spell-checker: ignore creds lastsync -->
|
|
2
|
+
## Project Template
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
SPA React frontend with a serverless lambda backend, supported by aws data stores. fullstack typescript.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
features:
|
|
7
|
+
- monorepo for frontend, lambda functions, deployment scripts
|
|
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
|
|
7
16
|
|
|
8
|
-
|
|
9
|
-
utility types, no javascript functionality in here. A dumping ground for commonly used utility types or sorcery copied of stack overflow.
|
|
17
|
+
## Design Goals
|
|
10
18
|
|
|
11
|
-
###
|
|
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.
|
|
19
|
+
### Easy and Full Featured
|
|
13
20
|
|
|
14
|
-
|
|
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.
|
|
21
|
+
Setting up a new project or microservice using raw libraries or tools like SAM is pretty easy, but leaves a lot of problems unsolved. developers end up having to solve a lot of problems over and over again, or cutting corners. There are, surprisingly, not a lot of software frameworks designed to work in a serverless environment, so every time you need to figure out how do error logging, or routing. maybe there is a lot of copy/paste there once you've done it a few times, but not everyone has done it a few times, and its still a project if you have. Sometimes you think you can quickly bang out a service that does xyz, and it doesn't need any frills, but then it turns out it sure would have been nice to have a data store, or an admin interface, and it doesn't send any alerts when it has errors, and that takes the project into a whole new problem space.
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
basic array/object access/manipulation utilities
|
|
23
|
+
This project aims to provide a baseline level of production-readiness, in addition to easily accessible prebuilt functionality for common problems.
|
|
19
24
|
|
|
20
|
-
###
|
|
21
|
-
a set of common application errors for the other libraries to use
|
|
25
|
+
### Cohesive
|
|
22
26
|
|
|
23
|
-
|
|
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.
|
|
27
|
+
A big problem in the javascript world is lack of cohesive systems. for any given problem there are a thousand npm modules that could help you, but given a set of problems, finding solutions that can work well together is a challenge.
|
|
25
28
|
|
|
26
|
-
|
|
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.
|
|
29
|
+
This project aims to provide a full stack developer experience using similar tools and patterns across the project, and typescript support as strong as we can make it.
|
|
28
30
|
|
|
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
|
-
|
|
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.
|
|
32
|
+
## Getting Started with the Project Template
|
|
34
33
|
|
|
35
|
-
###
|
|
36
|
-
|
|
34
|
+
### Set up your repo
|
|
35
|
+
- clone this repo
|
|
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
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
### Get into the Code
|
|
42
|
+
- start checking out the api code from the [routes file](./packages/lambda/src/functions/serviceApi/versions/v0/example/routes.ts). this example provides basic entity data storage, there are lots of comments in there.
|
|
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)
|
|
40
45
|
|
|
41
|
-
###
|
|
42
|
-
|
|
46
|
+
### your first deployment
|
|
47
|
+
- change the `APPLICATION` in [the deployment constants file](./deploy/constants.env). the first time you run the deployment it'll
|
|
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`
|
|
43
51
|
|
|
44
|
-
|
|
45
|
-
integrates with openstax.org/accounts, includes several implementations for both browser and server side integrations.
|
|
52
|
+
## Development
|
|
46
53
|
|
|
47
|
-
|
|
48
|
-
handles authentication and payload formatting for interacting with the LRS
|
|
54
|
+
install [nvm](https://github.com/creationix/nvm#installation)
|
|
49
55
|
|
|
50
|
-
|
|
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.
|
|
52
|
-
|
|
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.
|
|
55
|
-
|
|
56
|
-
## Notes
|
|
57
|
-
|
|
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.
|
|
60
|
-
|
|
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.
|
|
62
|
-
|
|
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`.
|
|
56
|
+
```
|
|
64
57
|
|
|
65
|
-
|
|
58
|
+
# use the right version of node
|
|
59
|
+
nvm install
|
|
66
60
|
|
|
67
|
-
|
|
61
|
+
# install yarn, skip if you have it already
|
|
62
|
+
npm install -g yarn
|
|
68
63
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
export const lambdaServices = {
|
|
72
|
-
// in this entry we provide the dynamo driver
|
|
73
|
-
versionedDocumentStore: dynamoVersionedDocumentStore({configSpace: 'dynamodb'}),
|
|
74
|
-
};
|
|
64
|
+
# install dependencies
|
|
65
|
+
yarn install
|
|
75
66
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
67
|
+
# start
|
|
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
|
+
```
|
|
81
73
|
|
|
82
|
-
|
|
74
|
+
### to fix scary untrusted cert warning in chrome
|
|
83
75
|
|
|
84
|
-
|
|
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;
|
|
76
|
+
*note:* you must do this for login to work
|
|
88
77
|
|
|
89
|
-
|
|
78
|
+
#### trust the certificate
|
|
79
|
+
- run `./packages/frontend/script/trust-localhost.bash` after starting the server
|
|
90
80
|
|
|
91
|
-
|
|
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
|
-
};
|
|
81
|
+
## Deployment
|
|
102
82
|
|
|
103
|
-
|
|
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);
|
|
83
|
+
dependencies: aws-sdk, jq
|
|
109
84
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
coolDocumentStore: makeCoolDocumentStore('id'),
|
|
116
|
-
})
|
|
117
|
-
};
|
|
85
|
+
```
|
|
86
|
+
# if you don't have https://github.com/openstax/ox-bin set up you can call this directly from
|
|
87
|
+
# your local https://github.com/openstax/aws-access/blob/main/scripts/set_aws_creds
|
|
88
|
+
. ox set_aws_creds -i assume-role -r sandbox:full-admin
|
|
89
|
+
yarn -s ts-utils deploy my-cool-environment
|
|
118
90
|
```
|
package/app.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "project-template",
|
|
3
|
+
"scripts": {
|
|
4
|
+
},
|
|
5
|
+
"env": {
|
|
6
|
+
"NODE_ENV": "development",
|
|
7
|
+
"REACT_APP_API_BASE_URL": "/"
|
|
8
|
+
},
|
|
9
|
+
"formation": {
|
|
10
|
+
"web": {
|
|
11
|
+
"size": "hobby"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"addons": [
|
|
15
|
+
|
|
16
|
+
],
|
|
17
|
+
"buildpacks": [
|
|
18
|
+
{
|
|
19
|
+
"url": "heroku/nodejs"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"stack": "heroku-22"
|
|
23
|
+
}
|
package/cspell.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.2",
|
|
3
|
+
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json",
|
|
4
|
+
"language": "en",
|
|
5
|
+
"words": [
|
|
6
|
+
"buildpacks",
|
|
7
|
+
"cloudformation",
|
|
8
|
+
"cookieyes",
|
|
9
|
+
"herokuapp",
|
|
10
|
+
"Jwks",
|
|
11
|
+
"jwks",
|
|
12
|
+
"ltijs",
|
|
13
|
+
"openstax",
|
|
14
|
+
"signup",
|
|
15
|
+
"stax",
|
|
16
|
+
"subcontent",
|
|
17
|
+
"subrequest",
|
|
18
|
+
"subrequests",
|
|
19
|
+
"systemsmanager",
|
|
20
|
+
"unversioned",
|
|
21
|
+
"Xapi"
|
|
22
|
+
],
|
|
23
|
+
"flagWords": [],
|
|
24
|
+
"ignorePaths": [
|
|
25
|
+
"*.spec.ts.snap",
|
|
26
|
+
"coverage",
|
|
27
|
+
"package.json",
|
|
28
|
+
"yarn.lock",
|
|
29
|
+
"node_modules/**",
|
|
30
|
+
"*.svg"
|
|
31
|
+
]
|
|
32
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
# These constants also get applied as tags to CloudFormation stacks and SSM parameters
|
|
6
|
+
# APPLICATION should probably be lower-case, dash-separated, since it's used to create stack names
|
|
7
|
+
export APPLICATION=project-template
|
|
8
|
+
export OWNER=tom
|
|
9
|
+
export PROJECT=DISCO
|
|
10
|
+
|
|
11
|
+
# List all parameter names to upload here
|
|
12
|
+
PARAMS=(
|
|
13
|
+
AccountsBase
|
|
14
|
+
CookieName # for decrypt authorization
|
|
15
|
+
EncryptionPrivateKey # for decrypt authorization
|
|
16
|
+
SignaturePublicKey # for decrypt authorization
|
|
17
|
+
)
|
|
18
|
+
export PARAMS
|
|
19
|
+
|
|
20
|
+
export AWS_DEFAULT_REGION=us-east-1
|
|
21
|
+
export AWS_ALT_REGION=us-east-2
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|
6
|
+
|
|
7
|
+
if [ -z "${ENVIRONMENT:-}" ]; then echo "run this command with 'yarn -s ts-utils deploy' instead of executing it directly" > /dev/stderr; exit 1; fi
|
|
8
|
+
|
|
9
|
+
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
|
10
|
+
gitVersion=$(git rev-parse HEAD)
|
|
11
|
+
stackName="$ENVIRONMENT-$APPLICATION"
|
|
12
|
+
|
|
13
|
+
# =======
|
|
14
|
+
# shared setup is one per aws account for this project, currently only used for
|
|
15
|
+
# lambda code zip archives and SNS topics for PagerDuty notifications
|
|
16
|
+
# =======
|
|
17
|
+
if ! yarn -s ts-utils stack-exists "subdomain-$APPLICATION-dns"; then
|
|
18
|
+
echo 'DNS stack not found. create one by following the instructions here: https://github.com/openstax/subdomains' > /dev/stderr
|
|
19
|
+
exit 1
|
|
20
|
+
fi
|
|
21
|
+
if ! yarn -s ts-utils stack-exists "subdomain-$APPLICATION-cert"; then
|
|
22
|
+
echo 'SSL cert stack not found. create one by following the instructions here: https://github.com/openstax/subdomains' > /dev/stderr
|
|
23
|
+
exit 1
|
|
24
|
+
fi
|
|
25
|
+
|
|
26
|
+
pagerDutyAnytimeEndpoint=$(aws ssm get-parameter --name "/external/pager_duty/$APPLICATION/anytime_endpoint" \
|
|
27
|
+
--with-decryption --query 'Parameter.Value' --output text 2>/dev/null || true)
|
|
28
|
+
pagerDutyWorkdayEndpoint=$(aws ssm get-parameter --name "/external/pager_duty/$APPLICATION/workday_endpoint" \
|
|
29
|
+
--with-decryption --query 'Parameter.Value' --output text 2>/dev/null || true)
|
|
30
|
+
|
|
31
|
+
if [ -z "$pagerDutyAnytimeEndpoint" ] || [ -z "$pagerDutyWorkdayEndpoint" ]; then
|
|
32
|
+
echo "Warning: PagerDuty endpoint(s) not set. You can set them by running: 'yarn -s ts-utils upload-pager-duty-endpoints'" > /dev/stderr
|
|
33
|
+
fi
|
|
34
|
+
|
|
35
|
+
yarn --check-files
|
|
36
|
+
|
|
37
|
+
if [ -n "$(git status --porcelain=v1 2>/dev/null)" ]; then
|
|
38
|
+
echo "please stash, commit, gitignore, or reset your changes before deploying" > /dev/stderr
|
|
39
|
+
exit 1
|
|
40
|
+
fi
|
|
41
|
+
|
|
42
|
+
bucketPrefix=
|
|
43
|
+
if [ "$AWS_ACCOUNT" != "openstax" ]; then
|
|
44
|
+
bucketPrefix="$AWS_ACCOUNT-"
|
|
45
|
+
fi
|
|
46
|
+
|
|
47
|
+
aws cloudformation deploy \
|
|
48
|
+
--region "$AWS_DEFAULT_REGION" \
|
|
49
|
+
--no-fail-on-empty-changeset \
|
|
50
|
+
--template-file "$SCRIPT_DIR/shared.cfn.yml" \
|
|
51
|
+
--stack-name "$APPLICATION-shared" \
|
|
52
|
+
--parameter-overrides "BucketPrefix=$bucketPrefix" \
|
|
53
|
+
"PagerDutyAnytimeEndpoint=$pagerDutyAnytimeEndpoint" \
|
|
54
|
+
"PagerDutyWorkdayEndpoint=$pagerDutyWorkdayEndpoint" \
|
|
55
|
+
--tags "Project=$PROJECT" "Application=$APPLICATION" 'Environment=shared' "Owner=$OWNER"
|
|
56
|
+
|
|
57
|
+
codeBucket=$(yarn -s ts-utils get-stack-param "$APPLICATION-shared" BucketName)
|
|
58
|
+
|
|
59
|
+
# =======
|
|
60
|
+
# build utils code if the package exists in this repo
|
|
61
|
+
# =======
|
|
62
|
+
if [ -d "$SCRIPT_DIR"/../packages/utils ]; then
|
|
63
|
+
cd "$SCRIPT_DIR"/../packages/utils
|
|
64
|
+
yarn build:clean
|
|
65
|
+
fi
|
|
66
|
+
|
|
67
|
+
# =======
|
|
68
|
+
# build api code and upload to code bucket
|
|
69
|
+
# =======
|
|
70
|
+
cd "$SCRIPT_DIR"/../packages/lambda
|
|
71
|
+
|
|
72
|
+
export CODE_VERSION="$gitVersion"
|
|
73
|
+
export APPLICATION;
|
|
74
|
+
|
|
75
|
+
yarn archive:clean
|
|
76
|
+
|
|
77
|
+
apiCodeKey="api-$timestamp.zip"
|
|
78
|
+
aws s3 cp "dist/serviceApi.zip" "s3://$codeBucket/$apiCodeKey"
|
|
79
|
+
|
|
80
|
+
# =======
|
|
81
|
+
# build frontend and upload to static site bucket
|
|
82
|
+
# =======
|
|
83
|
+
cd "$SCRIPT_DIR"/../packages/frontend
|
|
84
|
+
|
|
85
|
+
export REACT_APP_CODE_VERSION="$CODE_VERSION"
|
|
86
|
+
export REACT_APP_NAME="$APPLICATION"
|
|
87
|
+
export PUBLIC_URL="/build"
|
|
88
|
+
|
|
89
|
+
# =======
|
|
90
|
+
# try to read domainName from the stack
|
|
91
|
+
# =======
|
|
92
|
+
if yarn -s ts-utils stack-exists "$stackName"; then
|
|
93
|
+
previouslyDeployed=1
|
|
94
|
+
bucketName=$(yarn -s ts-utils get-stack-param "$stackName" StaticBucketName)
|
|
95
|
+
domainName=$(yarn -s ts-utils get-stack-param "$stackName" DistributionDomainName)
|
|
96
|
+
export REACT_APP_API_BASE_URL="https://${domainName}"
|
|
97
|
+
yarn build:clean
|
|
98
|
+
aws s3 sync build "s3://${bucketName}${PUBLIC_URL}" --region "$AWS_DEFAULT_REGION"
|
|
99
|
+
else
|
|
100
|
+
previouslyDeployed=0
|
|
101
|
+
fi
|
|
102
|
+
|
|
103
|
+
cd "$SCRIPT_DIR"
|
|
104
|
+
|
|
105
|
+
# Get values from SSM parameters
|
|
106
|
+
cookieName=$(yarn -s ts-utils get-env-param "$ENVIRONMENT" "CookieName")
|
|
107
|
+
accountsBase=$(yarn -s ts-utils get-env-param "$ENVIRONMENT" "AccountsBase")
|
|
108
|
+
signaturePublicKey=$(yarn -s ts-utils get-env-param "$ENVIRONMENT" "SignaturePublicKey")
|
|
109
|
+
|
|
110
|
+
cd "$SCRIPT_DIR"/../packages/lambda
|
|
111
|
+
|
|
112
|
+
# =======
|
|
113
|
+
# main deployment includes alt region for fail over
|
|
114
|
+
# =======
|
|
115
|
+
aws cloudformation deploy \
|
|
116
|
+
--region "$AWS_ALT_REGION" \
|
|
117
|
+
--no-fail-on-empty-changeset \
|
|
118
|
+
--template-file "$SCRIPT_DIR/deployment-alt-region.cfn.yml" \
|
|
119
|
+
--stack-name "$stackName" \
|
|
120
|
+
--parameter-overrides "BucketPrefix=$bucketPrefix" \
|
|
121
|
+
--tags "Project=$PROJECT" "Application=$APPLICATION" "Environment=$ENVIRONMENT" "Owner=$OWNER"
|
|
122
|
+
|
|
123
|
+
# cloudformation cannot reference exports across regions, so these are applied like this
|
|
124
|
+
replicaBucketWebsiteURL=$(AWS_DEFAULT_REGION="$AWS_ALT_REGION" yarn -s ts-utils get-stack-param "$stackName" ReplicaBucketWebsiteURL)
|
|
125
|
+
|
|
126
|
+
aws cloudformation deploy \
|
|
127
|
+
--region "$AWS_DEFAULT_REGION" \
|
|
128
|
+
--template-file "$SCRIPT_DIR/deployment.cfn.yml" \
|
|
129
|
+
--stack-name "$stackName" \
|
|
130
|
+
--capabilities CAPABILITY_NAMED_IAM \
|
|
131
|
+
--parameter-overrides "BucketPrefix=$bucketPrefix" "CodeBucket=$codeBucket" \
|
|
132
|
+
"EnvName=$ENVIRONMENT" "Application=$APPLICATION" "ReplicaBucketWebsiteURL=$replicaBucketWebsiteURL" \
|
|
133
|
+
"ApiCodeKey=$apiCodeKey" \
|
|
134
|
+
"AccountsBase=$accountsBase" "CookieName=$cookieName" "SignaturePublicKey=$signaturePublicKey" \
|
|
135
|
+
--tags "Project=$PROJECT" "Application=$APPLICATION" "Environment=$ENVIRONMENT" "Owner=$OWNER"
|
|
136
|
+
|
|
137
|
+
bucketName=$(yarn -s ts-utils get-stack-param "$stackName" StaticBucketName)
|
|
138
|
+
domainName=$(yarn -s ts-utils get-stack-param "$stackName" DistributionDomainName)
|
|
139
|
+
distributionId=$(yarn -s ts-utils get-stack-param "$stackName" DistributionId)
|
|
140
|
+
|
|
141
|
+
# =======
|
|
142
|
+
# build frontend and upload to static site bucket
|
|
143
|
+
# =======
|
|
144
|
+
export REACT_APP_API_BASE_URL="https://${domainName}"
|
|
145
|
+
|
|
146
|
+
cd "$SCRIPT_DIR"/../packages/frontend
|
|
147
|
+
if [ $previouslyDeployed -eq 0 ]; then
|
|
148
|
+
yarn build:clean
|
|
149
|
+
fi
|
|
150
|
+
aws s3 sync build "s3://${bucketName}${PUBLIC_URL}" --delete --region "$AWS_DEFAULT_REGION"
|
|
151
|
+
|
|
152
|
+
aws cloudfront create-invalidation --distribution-id "$distributionId" --paths "/*" --output text --query "Invalidation.Status"
|
|
153
|
+
|
|
154
|
+
# =======
|
|
155
|
+
# done
|
|
156
|
+
# =======
|
|
157
|
+
echo "deployed: $domainName";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata:
|
|
2
|
+
cfn-lint:
|
|
3
|
+
config:
|
|
4
|
+
ignore_checks:
|
|
5
|
+
- W6001
|
|
6
|
+
- E3031 # we do this on purpose
|
|
7
|
+
- E3033 # we do this on purpose
|
|
8
|
+
|
|
9
|
+
Parameters:
|
|
10
|
+
BucketPrefix:
|
|
11
|
+
Description: A prefix to prevent collisions between buckets in different accounts, e.g. sandbox-
|
|
12
|
+
Type: String
|
|
13
|
+
|
|
14
|
+
Conditions:
|
|
15
|
+
# Lambda@Edge functions need to be created in us-east-1; in order for this to be redundant it must be somewhere else
|
|
16
|
+
WrongRegion: !Equals [!Ref 'AWS::Region', us-east-1]
|
|
17
|
+
|
|
18
|
+
Resources:
|
|
19
|
+
# ==============
|
|
20
|
+
# Region validation
|
|
21
|
+
# ==============
|
|
22
|
+
YouAreInTheWrongRegion:
|
|
23
|
+
Type: "AWS::SSM::Parameter"
|
|
24
|
+
Condition: WrongRegion
|
|
25
|
+
Properties:
|
|
26
|
+
Name: '' # Leave name empty to force a fail
|
|
27
|
+
Type: String
|
|
28
|
+
Value: ''
|
|
29
|
+
# ==============
|
|
30
|
+
# static frontend S3 / Cloudfront
|
|
31
|
+
# ==============
|
|
32
|
+
ReplicaBucket:
|
|
33
|
+
Type: "AWS::S3::Bucket"
|
|
34
|
+
Properties:
|
|
35
|
+
BucketName: !Sub ${BucketPrefix}${AWS::StackName}-ui-replica-bucket
|
|
36
|
+
VersioningConfiguration:
|
|
37
|
+
Status: "Enabled"
|
|
38
|
+
LifecycleConfiguration:
|
|
39
|
+
Rules:
|
|
40
|
+
- Id: MustHaveVersioningButDoNotWantOldVersions
|
|
41
|
+
NoncurrentVersionExpirationInDays: 1
|
|
42
|
+
Status: "Enabled"
|
|
43
|
+
PublicAccessBlockConfiguration:
|
|
44
|
+
BlockPublicPolicy: false
|
|
45
|
+
WebsiteConfiguration:
|
|
46
|
+
IndexDocument: "does-not-exist.html"
|
|
47
|
+
OwnershipControls:
|
|
48
|
+
Rules:
|
|
49
|
+
- ObjectOwnership: BucketOwnerEnforced
|
|
50
|
+
|
|
51
|
+
ReplicaBucketPolicy:
|
|
52
|
+
Type: AWS::S3::BucketPolicy
|
|
53
|
+
Properties:
|
|
54
|
+
PolicyDocument:
|
|
55
|
+
Version: "2012-10-17"
|
|
56
|
+
Statement:
|
|
57
|
+
- Sid: PublicReadForGetBucketObjects
|
|
58
|
+
Effect: Allow
|
|
59
|
+
Principal: '*'
|
|
60
|
+
Action: s3:GetObject
|
|
61
|
+
Resource: !Sub ${ReplicaBucket.Arn}/*
|
|
62
|
+
|
|
63
|
+
Bucket: !Ref ReplicaBucket
|
|
64
|
+
|
|
65
|
+
Outputs:
|
|
66
|
+
ReplicaBucketName:
|
|
67
|
+
Value: !Ref ReplicaBucket
|
|
68
|
+
|
|
69
|
+
ReplicaBucketWebsiteURL:
|
|
70
|
+
Value: !GetAtt ReplicaBucket.WebsiteURL
|