@openstax/ts-utils 1.33.1 → 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.
Files changed (504) hide show
  1. package/.cfnlintrc +2 -0
  2. package/.github/CODEOWNERS +1 -0
  3. package/.github/workflows/ci.yml +36 -0
  4. package/.github/workflows/lint.yml +55 -0
  5. package/.nvmrc +1 -0
  6. package/.syncignore +4 -0
  7. package/.syncpackrc +18 -0
  8. package/CONTRIBUTING.md +96 -0
  9. package/LICENSE +661 -0
  10. package/Procfile +1 -0
  11. package/README.md +62 -90
  12. package/app.json +23 -0
  13. package/cspell.json +32 -0
  14. package/deploy/constants.env +21 -0
  15. package/deploy/deploy.bash +157 -0
  16. package/deploy/deployment-alt-region.cfn.yml +70 -0
  17. package/deploy/deployment.cfn.yml +650 -0
  18. package/deploy/destroy-deployment.bash +23 -0
  19. package/deploy/shared.cfn.yml +94 -0
  20. package/docs/lambda-build.md +35 -0
  21. package/package.json +12 -228
  22. package/packages/frontend/README.md +46 -0
  23. package/packages/frontend/package.json +101 -0
  24. package/packages/frontend/public/favicon.ico +0 -0
  25. package/packages/frontend/public/index.html +107 -0
  26. package/packages/frontend/public/maintenance.html +59 -0
  27. package/packages/frontend/public/manifest.json +15 -0
  28. package/packages/frontend/public/robots.txt +3 -0
  29. package/packages/frontend/script/make-certificate.bash +49 -0
  30. package/packages/frontend/script/server/cli.js +11 -0
  31. package/packages/frontend/script/server/index.js +47 -0
  32. package/packages/frontend/script/start.bash +22 -0
  33. package/packages/frontend/script/trust-localhost.bash +7 -0
  34. package/packages/frontend/src/auth/authProvider.ts +10 -0
  35. package/packages/frontend/src/auth/useAuth.ts +33 -0
  36. package/packages/frontend/src/components/Pagination.tsx +26 -0
  37. package/packages/frontend/src/configProvider/index.ts +53 -0
  38. package/packages/frontend/src/configProvider/use.ts +41 -0
  39. package/packages/frontend/src/core/context/services.spec.tsx +39 -0
  40. package/packages/frontend/src/core/context/services.tsx +16 -0
  41. package/packages/frontend/src/core/index.spec.ts +7 -0
  42. package/packages/frontend/src/core/index.ts +20 -0
  43. package/packages/frontend/src/core/services.tsx +14 -0
  44. package/packages/frontend/src/core/types.ts +3 -0
  45. package/packages/frontend/src/example/api.ts +28 -0
  46. package/packages/frontend/src/example/components/Layout.tsx +23 -0
  47. package/packages/frontend/src/example/screens/Home.spec.tsx +68 -0
  48. package/packages/frontend/src/example/screens/Home.tsx +78 -0
  49. package/packages/frontend/src/example/screens/ThingList.spec.tsx +60 -0
  50. package/packages/frontend/src/example/screens/ThingList.tsx +75 -0
  51. package/packages/frontend/src/example/screens/ThingView.spec.tsx +71 -0
  52. package/packages/frontend/src/example/screens/ThingView.tsx +47 -0
  53. package/packages/frontend/src/example/screens/index.ts +9 -0
  54. package/packages/frontend/src/index.css +159 -0
  55. package/packages/frontend/src/index.tsx +67 -0
  56. package/packages/frontend/src/react-app-env.d.ts +1 -0
  57. package/packages/frontend/src/routing/components/RouteLink.spec.tsx +55 -0
  58. package/packages/frontend/src/routing/components/RouteLink.tsx +35 -0
  59. package/packages/frontend/src/routing/middleware.ts +6 -0
  60. package/packages/frontend/src/routing/useQuery.ts +14 -0
  61. package/packages/frontend/src/setupProxy.js +19 -0
  62. package/packages/frontend/src/setupTests.ts +9 -0
  63. package/packages/frontend/src/tests/testServices.tsx +23 -0
  64. package/packages/frontend/tsconfig.json +27 -0
  65. package/packages/lambda/.eslintrc.js +64 -0
  66. package/packages/lambda/jest-global-setup.js +3 -0
  67. package/packages/lambda/jest-setup-after-env.js +1 -0
  68. package/packages/lambda/jest.config.js +31 -0
  69. package/packages/lambda/jest.resolver.js +17 -0
  70. package/packages/lambda/package.json +68 -0
  71. package/packages/lambda/script/build.bash +19 -0
  72. package/packages/lambda/script/bundle-functions.bash +10 -0
  73. package/packages/lambda/script/lambdaLocalProxy.js +16 -0
  74. package/packages/lambda/script/lambdaLocalProxy.spec.ts +147 -0
  75. package/packages/lambda/script/utils/getRouteData.ts +7 -0
  76. package/packages/lambda/script/utils/routeDataLoader.js +8 -0
  77. package/packages/lambda/script/utils/routeDataLoader.spec.ts +8 -0
  78. package/packages/lambda/src/functions/serviceApi/core/index.ts +7 -0
  79. package/packages/lambda/src/functions/serviceApi/core/request.spec.ts +38 -0
  80. package/packages/lambda/src/functions/serviceApi/core/request.ts +42 -0
  81. package/packages/lambda/src/functions/serviceApi/core/routes.spec.ts +7 -0
  82. package/packages/lambda/src/functions/serviceApi/core/routes.ts +10 -0
  83. package/packages/lambda/src/functions/serviceApi/core/services.ts +9 -0
  84. package/packages/lambda/src/functions/serviceApi/core/types.ts +13 -0
  85. package/packages/lambda/src/functions/serviceApi/entry/lambda/https-xray.ts +4 -0
  86. package/packages/lambda/src/functions/serviceApi/entry/lambda/index.spec.ts +48 -0
  87. package/packages/lambda/src/functions/serviceApi/entry/lambda/index.ts +58 -0
  88. package/packages/lambda/src/functions/serviceApi/entry/lambda/services.ts +36 -0
  89. package/packages/lambda/src/functions/serviceApi/entry/local.ts +71 -0
  90. package/packages/lambda/src/functions/serviceApi/versions/v0/example/documentSearchMiddleware.spec.ts +16 -0
  91. package/packages/lambda/src/functions/serviceApi/versions/v0/example/documentSearchMiddleware.ts +41 -0
  92. package/packages/lambda/src/functions/serviceApi/versions/v0/example/documentStoreMiddleware.spec.ts +78 -0
  93. package/packages/lambda/src/functions/serviceApi/versions/v0/example/documentStoreMiddleware.ts +70 -0
  94. package/packages/lambda/src/functions/serviceApi/versions/v0/example/routes.spec.ts +306 -0
  95. package/packages/lambda/src/functions/serviceApi/versions/v0/example/routes.ts +176 -0
  96. package/packages/lambda/src/functions/serviceApi/versions/v0/index.spec.ts +263 -0
  97. package/packages/lambda/src/functions/serviceApi/versions/v0/index.ts +134 -0
  98. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/authMiddleware.spec.ts +23 -0
  99. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/authMiddleware.ts +32 -0
  100. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/configMiddleware.spec.ts +10 -0
  101. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/configMiddleware.ts +7 -0
  102. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/frontendFileServerMiddleware.spec.ts +13 -0
  103. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/frontendFileServerMiddleware.ts +23 -0
  104. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/paginationMiddleware.spec.ts +9 -0
  105. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/paginationMiddleware.ts +9 -0
  106. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/searchMiddleware.spec.ts +12 -0
  107. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/searchMiddleware.ts +21 -0
  108. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/userRoleValidatorMiddleware.spec.ts +21 -0
  109. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/userRoleValidatorMiddleware.ts +18 -0
  110. package/packages/lambda/tsconfig.json +30 -0
  111. package/packages/lambda/webpack.config.js +97 -0
  112. package/packages/utils/.eslintrc.js +64 -0
  113. package/packages/utils/README.md +118 -0
  114. package/packages/utils/jest-global-setup.js +3 -0
  115. package/packages/utils/jest.config.js +25 -0
  116. package/packages/utils/jest.resolver.js +17 -0
  117. package/packages/utils/package.json +238 -0
  118. package/packages/utils/src/assertions/index.spec.ts +126 -0
  119. package/{dist/esm/assertions/index.js → packages/utils/src/assertions/index.ts} +64 -49
  120. package/packages/utils/src/aws/ssmService.ts +7 -0
  121. package/packages/utils/src/config/awsParameterConfig.ts +24 -0
  122. package/packages/utils/src/config/envConfig.ts +58 -0
  123. package/packages/utils/src/config/index.spec.ts +165 -0
  124. package/{dist/esm/config/index.d.ts → packages/utils/src/config/index.ts} +29 -13
  125. package/packages/utils/src/config/lambdaParameterConfig.ts +49 -0
  126. package/{dist/esm/config/replaceConfig.js → packages/utils/src/config/replaceConfig.ts} +16 -6
  127. package/packages/utils/src/config/resolveConfigValue.ts +10 -0
  128. package/packages/utils/src/errors/index.spec.ts +35 -0
  129. package/{dist/esm/errors/index.js → packages/utils/src/errors/index.ts} +57 -41
  130. package/packages/utils/src/fetch/fetchStatusRetry.spec.ts +197 -0
  131. package/packages/utils/src/fetch/fetchStatusRetry.ts +33 -0
  132. package/packages/utils/src/fetch/index.spec.ts +34 -0
  133. package/packages/utils/src/fetch/index.ts +87 -0
  134. package/packages/utils/src/guards/index.spec.ts +58 -0
  135. package/{dist/esm/guards/index.d.ts → packages/utils/src/guards/index.ts} +10 -7
  136. package/packages/utils/src/index.spec.ts +471 -0
  137. package/packages/utils/src/middleware/apiErrorHandler.spec.ts +65 -0
  138. package/packages/utils/src/middleware/apiErrorHandler.ts +67 -0
  139. package/packages/utils/src/middleware/apiSlowResponseMiddleware.spec.ts +184 -0
  140. package/packages/utils/src/middleware/apiSlowResponseMiddleware.ts +71 -0
  141. package/packages/utils/src/middleware/index.spec.ts +99 -0
  142. package/{dist/cjs/middleware/index.d.ts → packages/utils/src/middleware/index.ts} +53 -5
  143. package/packages/utils/src/middleware/lambdaCorsResponseMiddleware.spec.ts +103 -0
  144. package/packages/utils/src/middleware/lambdaCorsResponseMiddleware.ts +52 -0
  145. package/packages/utils/src/middleware/throwNotFoundMiddleware.spec.ts +20 -0
  146. package/packages/utils/src/middleware/throwNotFoundMiddleware.ts +11 -0
  147. package/packages/utils/src/misc/hashValue.ts +18 -0
  148. package/packages/utils/src/misc/helpers.ts +259 -0
  149. package/packages/utils/src/misc/merge.ts +48 -0
  150. package/{dist/esm/misc/partitionSequence.js → packages/utils/src/misc/partitionSequence.ts} +23 -15
  151. package/packages/utils/src/pagination/index.spec.ts +150 -0
  152. package/packages/utils/src/pagination/index.ts +117 -0
  153. package/{dist/esm/routing/helpers.js → packages/utils/src/routing/helpers.ts} +42 -30
  154. package/packages/utils/src/routing/index.spec.ts +553 -0
  155. package/packages/utils/src/routing/index.ts +424 -0
  156. package/packages/utils/src/routing/validators/zod.spec.ts +16 -0
  157. package/packages/utils/src/routing/validators/zod.ts +14 -0
  158. package/packages/utils/src/services/accountsGateway/README.md +3 -0
  159. package/packages/utils/src/services/accountsGateway/index.spec.ts +518 -0
  160. package/packages/utils/src/services/accountsGateway/index.ts +251 -0
  161. package/packages/utils/src/services/apiGateway/README.md +93 -0
  162. package/packages/utils/src/services/apiGateway/index.spec.ts +254 -0
  163. package/packages/utils/src/services/apiGateway/index.ts +189 -0
  164. package/packages/utils/src/services/authProvider/README.md +21 -0
  165. package/packages/utils/src/services/authProvider/browser.spec.ts +391 -0
  166. package/packages/utils/src/services/authProvider/browser.ts +209 -0
  167. package/packages/utils/src/services/authProvider/decryption.spec.ts +337 -0
  168. package/packages/utils/src/services/authProvider/decryption.ts +98 -0
  169. package/packages/utils/src/services/authProvider/index.ts +93 -0
  170. package/packages/utils/src/services/authProvider/stub.spec.ts +29 -0
  171. package/packages/utils/src/services/authProvider/subrequest.spec.ts +105 -0
  172. package/packages/utils/src/services/authProvider/subrequest.ts +68 -0
  173. package/packages/utils/src/services/authProvider/utils/decryptAndVerify.spec.ts +128 -0
  174. package/packages/utils/src/services/authProvider/utils/decryptAndVerify.ts +106 -0
  175. package/packages/utils/src/services/authProvider/utils/embeddedAuthProvider.spec.ts +26 -0
  176. package/packages/utils/src/services/authProvider/utils/embeddedAuthProvider.ts +57 -0
  177. package/packages/utils/src/services/authProvider/utils/userRoleValidator.spec.ts +135 -0
  178. package/packages/utils/src/services/authProvider/utils/userRoleValidator.ts +49 -0
  179. package/packages/utils/src/services/authProvider/utils/userSubrequest.spec.ts +26 -0
  180. package/packages/utils/src/services/authProvider/utils/userSubrequest.ts +10 -0
  181. package/packages/utils/src/services/documentStore/dynamoEncoding.ts +57 -0
  182. package/packages/utils/src/services/documentStore/fileSystemAssert.spec.ts +43 -0
  183. package/packages/utils/src/services/documentStore/fileSystemAssert.ts +10 -0
  184. package/{dist/cjs/services/documentStore/index.d.ts → packages/utils/src/services/documentStore/index.ts} +8 -8
  185. package/packages/utils/src/services/documentStore/unversioned/README.md +13 -0
  186. package/packages/utils/src/services/documentStore/unversioned/dynamodb.spec.ts +859 -0
  187. package/packages/utils/src/services/documentStore/unversioned/dynamodb.ts +243 -0
  188. package/packages/utils/src/services/documentStore/unversioned/file-system.spec.ts +629 -0
  189. package/packages/utils/src/services/documentStore/unversioned/file-system.ts +194 -0
  190. package/{dist/cjs/services/documentStore/unversioned/index.d.ts → packages/utils/src/services/documentStore/unversioned/index.ts} +2 -0
  191. package/packages/utils/src/services/documentStore/versioned/README.md +13 -0
  192. package/packages/utils/src/services/documentStore/versioned/dynamodb.spec.ts +376 -0
  193. package/packages/utils/src/services/documentStore/versioned/dynamodb.ts +167 -0
  194. package/packages/utils/src/services/documentStore/versioned/file-system.spec.ts +262 -0
  195. package/packages/utils/src/services/documentStore/versioned/file-system.ts +90 -0
  196. package/packages/utils/src/services/documentStore/versioned/index.ts +25 -0
  197. package/packages/utils/src/services/exercisesGateway/README.md +5 -0
  198. package/packages/utils/src/services/exercisesGateway/index.spec.ts +326 -0
  199. package/packages/utils/src/services/exercisesGateway/index.ts +163 -0
  200. package/packages/utils/src/services/fileServer/index.spec.ts +88 -0
  201. package/packages/utils/src/services/fileServer/index.ts +43 -0
  202. package/packages/utils/src/services/fileServer/localFileServer.spec.ts +182 -0
  203. package/packages/utils/src/services/fileServer/localFileServer.ts +159 -0
  204. package/packages/utils/src/services/fileServer/s3FileServer.spec.ts +266 -0
  205. package/packages/utils/src/services/fileServer/s3FileServer.ts +155 -0
  206. package/packages/utils/src/services/launchParams/index.spec.ts +366 -0
  207. package/packages/utils/src/services/launchParams/signer.ts +73 -0
  208. package/packages/utils/src/services/launchParams/verifier.ts +120 -0
  209. package/packages/utils/src/services/logger/console.spec.ts +29 -0
  210. package/{dist/esm/services/logger/console.js → packages/utils/src/services/logger/console.ts} +5 -2
  211. package/packages/utils/src/services/logger/index.spec.ts +65 -0
  212. package/{dist/esm/services/logger/index.d.ts → packages/utils/src/services/logger/index.ts} +23 -9
  213. package/packages/utils/src/services/lrsGateway/README.md +5 -0
  214. package/packages/utils/src/services/lrsGateway/addStatementDefaultFields.ts +22 -0
  215. package/packages/utils/src/services/lrsGateway/attempt-utils.spec.ts +847 -0
  216. package/packages/utils/src/services/lrsGateway/attempt-utils.ts +358 -0
  217. package/packages/utils/src/services/lrsGateway/file-system.spec.ts +363 -0
  218. package/packages/utils/src/services/lrsGateway/file-system.ts +165 -0
  219. package/packages/utils/src/services/lrsGateway/index.spec.ts +194 -0
  220. package/packages/utils/src/services/lrsGateway/index.ts +257 -0
  221. package/packages/utils/src/services/lrsGateway/xapiUtils.spec.ts +887 -0
  222. package/packages/utils/src/services/lrsGateway/xapiUtils.ts +262 -0
  223. package/packages/utils/src/services/postgresConnection/index.spec.ts +170 -0
  224. package/packages/utils/src/services/postgresConnection/index.ts +84 -0
  225. package/packages/utils/src/services/searchProvider/README.md +3 -0
  226. package/packages/utils/src/services/searchProvider/index.ts +59 -0
  227. package/packages/utils/src/services/searchProvider/memorySearchTheBadWay.spec.ts +526 -0
  228. package/packages/utils/src/services/searchProvider/memorySearchTheBadWay.ts +223 -0
  229. package/packages/utils/src/services/searchProvider/openSearch.spec.ts +926 -0
  230. package/packages/utils/src/services/searchProvider/openSearch.ts +195 -0
  231. package/{dist/esm/types.d.ts → packages/utils/src/types.ts} +34 -6
  232. package/packages/utils/tsconfig.json +31 -0
  233. package/packages/utils/tsconfig.without-specs.cjs.json +7 -0
  234. package/packages/utils/tsconfig.without-specs.esm.json +7 -0
  235. package/packages/utils/tsconfig.without-specs.json +6 -0
  236. package/scripts/build.bash +24 -0
  237. package/scripts/ci.bash +10 -0
  238. package/scripts/start.bash +29 -0
  239. package/dist/cjs/assertions/index.d.ts +0 -89
  240. package/dist/cjs/assertions/index.js +0 -157
  241. package/dist/cjs/aws/ssmService.d.ts +0 -5
  242. package/dist/cjs/aws/ssmService.js +0 -9
  243. package/dist/cjs/config/awsParameterConfig.d.ts +0 -10
  244. package/dist/cjs/config/awsParameterConfig.js +0 -26
  245. package/dist/cjs/config/envConfig.d.ts +0 -24
  246. package/dist/cjs/config/envConfig.js +0 -57
  247. package/dist/cjs/config/index.d.ts +0 -48
  248. package/dist/cjs/config/index.js +0 -35
  249. package/dist/cjs/config/lambdaParameterConfig.d.ts +0 -12
  250. package/dist/cjs/config/lambdaParameterConfig.js +0 -45
  251. package/dist/cjs/config/replaceConfig.d.ts +0 -14
  252. package/dist/cjs/config/replaceConfig.js +0 -22
  253. package/dist/cjs/config/resolveConfigValue.d.ts +0 -5
  254. package/dist/cjs/config/resolveConfigValue.js +0 -12
  255. package/dist/cjs/errors/index.d.ts +0 -88
  256. package/dist/cjs/errors/index.js +0 -123
  257. package/dist/cjs/fetch/fetchStatusRetry.d.ts +0 -8
  258. package/dist/cjs/fetch/fetchStatusRetry.js +0 -27
  259. package/dist/cjs/fetch/index.d.ts +0 -64
  260. package/dist/cjs/fetch/index.js +0 -55
  261. package/dist/cjs/guards/index.d.ts +0 -38
  262. package/dist/cjs/guards/index.js +0 -44
  263. package/dist/cjs/index.js +0 -20
  264. package/dist/cjs/middleware/apiErrorHandler.d.ts +0 -24
  265. package/dist/cjs/middleware/apiErrorHandler.js +0 -42
  266. package/dist/cjs/middleware/apiSlowResponseMiddleware.d.ts +0 -23
  267. package/dist/cjs/middleware/apiSlowResponseMiddleware.js +0 -54
  268. package/dist/cjs/middleware/index.js +0 -48
  269. package/dist/cjs/middleware/lambdaCorsResponseMiddleware.d.ts +0 -20
  270. package/dist/cjs/middleware/lambdaCorsResponseMiddleware.js +0 -44
  271. package/dist/cjs/middleware/throwNotFoundMiddleware.d.ts +0 -4
  272. package/dist/cjs/middleware/throwNotFoundMiddleware.js +0 -14
  273. package/dist/cjs/misc/hashValue.d.ts +0 -10
  274. package/dist/cjs/misc/hashValue.js +0 -17
  275. package/dist/cjs/misc/helpers.d.ts +0 -124
  276. package/dist/cjs/misc/helpers.js +0 -214
  277. package/dist/cjs/misc/merge.d.ts +0 -21
  278. package/dist/cjs/misc/merge.js +0 -45
  279. package/dist/cjs/misc/partitionSequence.d.ts +0 -35
  280. package/dist/cjs/misc/partitionSequence.js +0 -55
  281. package/dist/cjs/pagination/index.d.ts +0 -91
  282. package/dist/cjs/pagination/index.js +0 -83
  283. package/dist/cjs/routing/helpers.d.ts +0 -57
  284. package/dist/cjs/routing/helpers.js +0 -90
  285. package/dist/cjs/routing/index.d.ts +0 -290
  286. package/dist/cjs/routing/index.js +0 -295
  287. package/dist/cjs/routing/validators/zod.d.ts +0 -4
  288. package/dist/cjs/routing/validators/zod.js +0 -14
  289. package/dist/cjs/services/accountsGateway/index.d.ts +0 -92
  290. package/dist/cjs/services/accountsGateway/index.js +0 -138
  291. package/dist/cjs/services/apiGateway/index.d.ts +0 -68
  292. package/dist/cjs/services/apiGateway/index.js +0 -118
  293. package/dist/cjs/services/authProvider/browser.d.ts +0 -40
  294. package/dist/cjs/services/authProvider/browser.js +0 -155
  295. package/dist/cjs/services/authProvider/decryption.d.ts +0 -19
  296. package/dist/cjs/services/authProvider/decryption.js +0 -73
  297. package/dist/cjs/services/authProvider/index.d.ts +0 -63
  298. package/dist/cjs/services/authProvider/index.js +0 -34
  299. package/dist/cjs/services/authProvider/subrequest.d.ts +0 -13
  300. package/dist/cjs/services/authProvider/subrequest.js +0 -49
  301. package/dist/cjs/services/authProvider/utils/decryptAndVerify.d.ts +0 -28
  302. package/dist/cjs/services/authProvider/utils/decryptAndVerify.js +0 -91
  303. package/dist/cjs/services/authProvider/utils/embeddedAuthProvider.d.ts +0 -26
  304. package/dist/cjs/services/authProvider/utils/embeddedAuthProvider.js +0 -47
  305. package/dist/cjs/services/authProvider/utils/userRoleValidator.d.ts +0 -13
  306. package/dist/cjs/services/authProvider/utils/userRoleValidator.js +0 -37
  307. package/dist/cjs/services/authProvider/utils/userSubrequest.d.ts +0 -3
  308. package/dist/cjs/services/authProvider/utils/userSubrequest.js +0 -13
  309. package/dist/cjs/services/documentStore/dynamoEncoding.d.ts +0 -10
  310. package/dist/cjs/services/documentStore/dynamoEncoding.js +0 -52
  311. package/dist/cjs/services/documentStore/fileSystemAssert.d.ts +0 -1
  312. package/dist/cjs/services/documentStore/fileSystemAssert.js +0 -14
  313. package/dist/cjs/services/documentStore/index.js +0 -2
  314. package/dist/cjs/services/documentStore/unversioned/dynamodb.d.ts +0 -31
  315. package/dist/cjs/services/documentStore/unversioned/dynamodb.js +0 -233
  316. package/dist/cjs/services/documentStore/unversioned/file-system.d.ts +0 -32
  317. package/dist/cjs/services/documentStore/unversioned/file-system.js +0 -214
  318. package/dist/cjs/services/documentStore/unversioned/index.js +0 -2
  319. package/dist/cjs/services/documentStore/versioned/dynamodb.d.ts +0 -25
  320. package/dist/cjs/services/documentStore/versioned/dynamodb.js +0 -143
  321. package/dist/cjs/services/documentStore/versioned/file-system.d.ts +0 -25
  322. package/dist/cjs/services/documentStore/versioned/file-system.js +0 -73
  323. package/dist/cjs/services/documentStore/versioned/index.d.ts +0 -17
  324. package/dist/cjs/services/documentStore/versioned/index.js +0 -2
  325. package/dist/cjs/services/exercisesGateway/index.d.ts +0 -67
  326. package/dist/cjs/services/exercisesGateway/index.js +0 -107
  327. package/dist/cjs/services/fileServer/index.d.ts +0 -30
  328. package/dist/cjs/services/fileServer/index.js +0 -19
  329. package/dist/cjs/services/fileServer/localFileServer.d.ts +0 -13
  330. package/dist/cjs/services/fileServer/localFileServer.js +0 -132
  331. package/dist/cjs/services/fileServer/s3FileServer.d.ts +0 -14
  332. package/dist/cjs/services/fileServer/s3FileServer.js +0 -132
  333. package/dist/cjs/services/launchParams/index.js +0 -7
  334. package/dist/cjs/services/launchParams/signer.d.ts +0 -23
  335. package/dist/cjs/services/launchParams/signer.js +0 -58
  336. package/dist/cjs/services/launchParams/verifier.d.ts +0 -21
  337. package/dist/cjs/services/launchParams/verifier.js +0 -129
  338. package/dist/cjs/services/logger/console.d.ts +0 -4
  339. package/dist/cjs/services/logger/console.js +0 -12
  340. package/dist/cjs/services/logger/index.d.ts +0 -39
  341. package/dist/cjs/services/logger/index.js +0 -31
  342. package/dist/cjs/services/lrsGateway/addStatementDefaultFields.d.ts +0 -5
  343. package/dist/cjs/services/lrsGateway/addStatementDefaultFields.js +0 -21
  344. package/dist/cjs/services/lrsGateway/attempt-utils.d.ts +0 -70
  345. package/dist/cjs/services/lrsGateway/attempt-utils.js +0 -258
  346. package/dist/cjs/services/lrsGateway/file-system.d.ts +0 -15
  347. package/dist/cjs/services/lrsGateway/file-system.js +0 -150
  348. package/dist/cjs/services/lrsGateway/index.d.ts +0 -122
  349. package/dist/cjs/services/lrsGateway/index.js +0 -148
  350. package/dist/cjs/services/lrsGateway/xapiUtils.d.ts +0 -68
  351. package/dist/cjs/services/lrsGateway/xapiUtils.js +0 -109
  352. package/dist/cjs/services/postgresConnection/index.d.ts +0 -28
  353. package/dist/cjs/services/postgresConnection/index.js +0 -65
  354. package/dist/cjs/services/searchProvider/index.d.ts +0 -67
  355. package/dist/cjs/services/searchProvider/index.js +0 -2
  356. package/dist/cjs/services/searchProvider/memorySearchTheBadWay.d.ts +0 -20
  357. package/dist/cjs/services/searchProvider/memorySearchTheBadWay.js +0 -191
  358. package/dist/cjs/services/searchProvider/openSearch.d.ts +0 -28
  359. package/dist/cjs/services/searchProvider/openSearch.js +0 -154
  360. package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +0 -1
  361. package/dist/cjs/types.d.ts +0 -31
  362. package/dist/cjs/types.js +0 -2
  363. package/dist/esm/assertions/index.d.ts +0 -89
  364. package/dist/esm/aws/ssmService.d.ts +0 -5
  365. package/dist/esm/aws/ssmService.js +0 -6
  366. package/dist/esm/config/awsParameterConfig.d.ts +0 -10
  367. package/dist/esm/config/awsParameterConfig.js +0 -22
  368. package/dist/esm/config/envConfig.d.ts +0 -24
  369. package/dist/esm/config/envConfig.js +0 -53
  370. package/dist/esm/config/index.js +0 -17
  371. package/dist/esm/config/lambdaParameterConfig.d.ts +0 -12
  372. package/dist/esm/config/lambdaParameterConfig.js +0 -38
  373. package/dist/esm/config/replaceConfig.d.ts +0 -14
  374. package/dist/esm/config/resolveConfigValue.d.ts +0 -5
  375. package/dist/esm/config/resolveConfigValue.js +0 -8
  376. package/dist/esm/errors/index.d.ts +0 -88
  377. package/dist/esm/fetch/fetchStatusRetry.d.ts +0 -8
  378. package/dist/esm/fetch/fetchStatusRetry.js +0 -23
  379. package/dist/esm/fetch/index.d.ts +0 -64
  380. package/dist/esm/fetch/index.js +0 -46
  381. package/dist/esm/guards/index.js +0 -36
  382. package/dist/esm/index.d.ts +0 -4
  383. package/dist/esm/index.js +0 -4
  384. package/dist/esm/middleware/apiErrorHandler.d.ts +0 -24
  385. package/dist/esm/middleware/apiErrorHandler.js +0 -38
  386. package/dist/esm/middleware/apiSlowResponseMiddleware.d.ts +0 -23
  387. package/dist/esm/middleware/apiSlowResponseMiddleware.js +0 -50
  388. package/dist/esm/middleware/index.d.ts +0 -47
  389. package/dist/esm/middleware/index.js +0 -44
  390. package/dist/esm/middleware/lambdaCorsResponseMiddleware.d.ts +0 -20
  391. package/dist/esm/middleware/lambdaCorsResponseMiddleware.js +0 -40
  392. package/dist/esm/middleware/throwNotFoundMiddleware.d.ts +0 -4
  393. package/dist/esm/middleware/throwNotFoundMiddleware.js +0 -10
  394. package/dist/esm/misc/hashValue.d.ts +0 -10
  395. package/dist/esm/misc/hashValue.js +0 -13
  396. package/dist/esm/misc/helpers.d.ts +0 -124
  397. package/dist/esm/misc/helpers.js +0 -199
  398. package/dist/esm/misc/merge.d.ts +0 -21
  399. package/dist/esm/misc/merge.js +0 -40
  400. package/dist/esm/misc/partitionSequence.d.ts +0 -35
  401. package/dist/esm/pagination/index.d.ts +0 -91
  402. package/dist/esm/pagination/index.js +0 -77
  403. package/dist/esm/routing/helpers.d.ts +0 -57
  404. package/dist/esm/routing/index.d.ts +0 -290
  405. package/dist/esm/routing/index.js +0 -246
  406. package/dist/esm/routing/validators/zod.d.ts +0 -4
  407. package/dist/esm/routing/validators/zod.js +0 -10
  408. package/dist/esm/services/accountsGateway/index.d.ts +0 -92
  409. package/dist/esm/services/accountsGateway/index.js +0 -131
  410. package/dist/esm/services/apiGateway/index.d.ts +0 -68
  411. package/dist/esm/services/apiGateway/index.js +0 -77
  412. package/dist/esm/services/authProvider/browser.d.ts +0 -40
  413. package/dist/esm/services/authProvider/browser.js +0 -151
  414. package/dist/esm/services/authProvider/decryption.d.ts +0 -19
  415. package/dist/esm/services/authProvider/decryption.js +0 -69
  416. package/dist/esm/services/authProvider/index.d.ts +0 -63
  417. package/dist/esm/services/authProvider/index.js +0 -26
  418. package/dist/esm/services/authProvider/subrequest.d.ts +0 -13
  419. package/dist/esm/services/authProvider/subrequest.js +0 -45
  420. package/dist/esm/services/authProvider/utils/decryptAndVerify.d.ts +0 -28
  421. package/dist/esm/services/authProvider/utils/decryptAndVerify.js +0 -85
  422. package/dist/esm/services/authProvider/utils/embeddedAuthProvider.d.ts +0 -26
  423. package/dist/esm/services/authProvider/utils/embeddedAuthProvider.js +0 -40
  424. package/dist/esm/services/authProvider/utils/userRoleValidator.d.ts +0 -13
  425. package/dist/esm/services/authProvider/utils/userRoleValidator.js +0 -33
  426. package/dist/esm/services/authProvider/utils/userSubrequest.d.ts +0 -3
  427. package/dist/esm/services/authProvider/utils/userSubrequest.js +0 -6
  428. package/dist/esm/services/documentStore/dynamoEncoding.d.ts +0 -10
  429. package/dist/esm/services/documentStore/dynamoEncoding.js +0 -45
  430. package/dist/esm/services/documentStore/fileSystemAssert.d.ts +0 -1
  431. package/dist/esm/services/documentStore/fileSystemAssert.js +0 -10
  432. package/dist/esm/services/documentStore/index.d.ts +0 -14
  433. package/dist/esm/services/documentStore/index.js +0 -1
  434. package/dist/esm/services/documentStore/unversioned/dynamodb.d.ts +0 -31
  435. package/dist/esm/services/documentStore/unversioned/dynamodb.js +0 -226
  436. package/dist/esm/services/documentStore/unversioned/file-system.d.ts +0 -32
  437. package/dist/esm/services/documentStore/unversioned/file-system.js +0 -174
  438. package/dist/esm/services/documentStore/unversioned/index.d.ts +0 -2
  439. package/dist/esm/services/documentStore/unversioned/index.js +0 -1
  440. package/dist/esm/services/documentStore/versioned/dynamodb.d.ts +0 -25
  441. package/dist/esm/services/documentStore/versioned/dynamodb.js +0 -139
  442. package/dist/esm/services/documentStore/versioned/file-system.d.ts +0 -25
  443. package/dist/esm/services/documentStore/versioned/file-system.js +0 -69
  444. package/dist/esm/services/documentStore/versioned/index.d.ts +0 -17
  445. package/dist/esm/services/documentStore/versioned/index.js +0 -1
  446. package/dist/esm/services/exercisesGateway/index.d.ts +0 -67
  447. package/dist/esm/services/exercisesGateway/index.js +0 -70
  448. package/dist/esm/services/fileServer/index.d.ts +0 -30
  449. package/dist/esm/services/fileServer/index.js +0 -13
  450. package/dist/esm/services/fileServer/localFileServer.d.ts +0 -13
  451. package/dist/esm/services/fileServer/localFileServer.js +0 -125
  452. package/dist/esm/services/fileServer/s3FileServer.d.ts +0 -14
  453. package/dist/esm/services/fileServer/s3FileServer.js +0 -125
  454. package/dist/esm/services/launchParams/index.d.ts +0 -2
  455. package/dist/esm/services/launchParams/index.js +0 -2
  456. package/dist/esm/services/launchParams/signer.d.ts +0 -23
  457. package/dist/esm/services/launchParams/signer.js +0 -51
  458. package/dist/esm/services/launchParams/verifier.d.ts +0 -21
  459. package/dist/esm/services/launchParams/verifier.js +0 -92
  460. package/dist/esm/services/logger/console.d.ts +0 -4
  461. package/dist/esm/services/logger/index.js +0 -27
  462. package/dist/esm/services/lrsGateway/addStatementDefaultFields.d.ts +0 -5
  463. package/dist/esm/services/lrsGateway/addStatementDefaultFields.js +0 -14
  464. package/dist/esm/services/lrsGateway/attempt-utils.d.ts +0 -70
  465. package/dist/esm/services/lrsGateway/attempt-utils.js +0 -236
  466. package/dist/esm/services/lrsGateway/file-system.d.ts +0 -15
  467. package/dist/esm/services/lrsGateway/file-system.js +0 -110
  468. package/dist/esm/services/lrsGateway/index.d.ts +0 -122
  469. package/dist/esm/services/lrsGateway/index.js +0 -111
  470. package/dist/esm/services/lrsGateway/xapiUtils.d.ts +0 -68
  471. package/dist/esm/services/lrsGateway/xapiUtils.js +0 -99
  472. package/dist/esm/services/postgresConnection/index.d.ts +0 -28
  473. package/dist/esm/services/postgresConnection/index.js +0 -58
  474. package/dist/esm/services/searchProvider/index.d.ts +0 -67
  475. package/dist/esm/services/searchProvider/index.js +0 -1
  476. package/dist/esm/services/searchProvider/memorySearchTheBadWay.d.ts +0 -20
  477. package/dist/esm/services/searchProvider/memorySearchTheBadWay.js +0 -187
  478. package/dist/esm/services/searchProvider/openSearch.d.ts +0 -28
  479. package/dist/esm/services/searchProvider/openSearch.js +0 -150
  480. package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +0 -1
  481. package/dist/esm/types.js +0 -1
  482. package/script/bin/.init-params-script.bash.swp +0 -0
  483. /package/{script → packages/utils/script}/bin/copy-from-template.bash +0 -0
  484. /package/{script → packages/utils/script}/bin/delete-stack.bash +0 -0
  485. /package/{script → packages/utils/script}/bin/deploy.bash +0 -0
  486. /package/{script → packages/utils/script}/bin/destroy-deployment.bash +0 -0
  487. /package/{script → packages/utils/script}/bin/empty-bucket.bash +0 -0
  488. /package/{script → packages/utils/script}/bin/get-arg.bash +0 -0
  489. /package/{script → packages/utils/script}/bin/get-deployed-environments.bash +0 -0
  490. /package/{script → packages/utils/script}/bin/get-env-param.bash +0 -0
  491. /package/{script → packages/utils/script}/bin/get-kwarg.bash +0 -0
  492. /package/{script → packages/utils/script}/bin/get-stack-param.bash +0 -0
  493. /package/{script → packages/utils/script}/bin/has-flag.bash +0 -0
  494. /package/{script → packages/utils/script}/bin/init-constants-script.bash +0 -0
  495. /package/{script → packages/utils/script}/bin/init-params-script.bash +0 -0
  496. /package/{script → packages/utils/script}/bin/stack-exists.bash +0 -0
  497. /package/{script → packages/utils/script}/bin/update-utils.bash +0 -0
  498. /package/{script → packages/utils/script}/bin/upload-pager-duty-endpoints.bash +0 -0
  499. /package/{script → packages/utils/script}/bin/upload-params.bash +0 -0
  500. /package/{script → packages/utils/script}/bin/which.bash +0 -0
  501. /package/{script → packages/utils/script}/bin-entry.bash +0 -0
  502. /package/{script → packages/utils/script}/build.bash +0 -0
  503. /package/{dist/cjs/index.d.ts → packages/utils/src/index.ts} +0 -0
  504. /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
- # @openstax/ts-utils
1
+ <!-- spell-checker: ignore creds lastsync -->
2
+ ## Project Template
2
3
 
3
- A collection of utilities typescript applications. browser and server support.
4
+ SPA React frontend with a serverless lambda backend, supported by aws data stores. fullstack typescript.
4
5
 
5
- ## Libraries
6
- overviews of the libraries provided and their purposes, for more specific information check out the comments in the source code.
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
- ### [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.
17
+ ## Design Goals
10
18
 
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.
19
+ ### Easy and Full Featured
13
20
 
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.
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
- ### [index.ts](./index.ts)
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
- ### [errors.ts](./errors.ts)
21
- a set of common application errors for the other libraries to use
25
+ ### Cohesive
22
26
 
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.
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
- ### [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.
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
- ### [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.
32
+ ## Getting Started with the Project Template
34
33
 
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.
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
- ## 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.
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
- ### [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.
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
- ### [authProvider](./services/authProvider)
45
- integrates with openstax.org/accounts, includes several implementations for both browser and server side integrations.
52
+ ## Development
46
53
 
47
- ### [lrsGateway](./services/lrsGateway/index.ts)
48
- handles authentication and payload formatting for interacting with the LRS
54
+ install [nvm](https://github.com/creationix/nvm#installation)
49
55
 
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.
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
- 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.
58
+ # use the right version of node
59
+ nvm install
66
60
 
67
- for example:
61
+ # install yarn, skip if you have it already
62
+ npm install -g yarn
68
63
 
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
- };
64
+ # install dependencies
65
+ yarn install
75
66
 
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
- };
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
- // core/types.ts
74
+ ### to fix scary untrusted cert warning in chrome
83
75
 
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;
76
+ *note:* you must do this for login to work
88
77
 
89
- // myCoolDocumentStoreMiddleware.ts
78
+ #### trust the certificate
79
+ - run `./packages/frontend/script/trust-localhost.bash` after starting the server
90
80
 
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
- };
81
+ ## Deployment
102
82
 
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);
83
+ dependencies: aws-sdk, jq
109
84
 
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
- };
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