@openstax/ts-utils 1.34.0 → 1.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (507) hide show
  1. package/README.md +90 -62
  2. package/dist/cjs/assertions/index.d.ts +89 -0
  3. package/dist/cjs/assertions/index.js +157 -0
  4. package/dist/cjs/aws/ssmService.d.ts +5 -0
  5. package/dist/cjs/aws/ssmService.js +9 -0
  6. package/dist/cjs/config/awsParameterConfig.d.ts +10 -0
  7. package/dist/cjs/config/awsParameterConfig.js +26 -0
  8. package/dist/cjs/config/envConfig.d.ts +24 -0
  9. package/dist/cjs/config/envConfig.js +57 -0
  10. package/{packages/utils/src/config/index.ts → dist/cjs/config/index.d.ts} +13 -29
  11. package/dist/cjs/config/index.js +35 -0
  12. package/dist/cjs/config/lambdaParameterConfig.d.ts +12 -0
  13. package/dist/cjs/config/lambdaParameterConfig.js +45 -0
  14. package/dist/cjs/config/replaceConfig.d.ts +14 -0
  15. package/dist/cjs/config/replaceConfig.js +22 -0
  16. package/dist/cjs/config/resolveConfigValue.d.ts +5 -0
  17. package/dist/cjs/config/resolveConfigValue.js +12 -0
  18. package/dist/cjs/errors/index.d.ts +88 -0
  19. package/dist/cjs/errors/index.js +123 -0
  20. package/dist/cjs/fetch/fetchStatusRetry.d.ts +8 -0
  21. package/dist/cjs/fetch/fetchStatusRetry.js +27 -0
  22. package/dist/cjs/fetch/index.d.ts +64 -0
  23. package/dist/cjs/fetch/index.js +55 -0
  24. package/{packages/utils/src/guards/index.ts → dist/cjs/guards/index.d.ts} +7 -10
  25. package/dist/cjs/guards/index.js +44 -0
  26. package/dist/cjs/index.js +20 -0
  27. package/dist/cjs/middleware/apiErrorHandler.d.ts +24 -0
  28. package/dist/cjs/middleware/apiErrorHandler.js +42 -0
  29. package/dist/cjs/middleware/apiSlowResponseMiddleware.d.ts +23 -0
  30. package/dist/cjs/middleware/apiSlowResponseMiddleware.js +54 -0
  31. package/{packages/utils/src/middleware/index.ts → dist/cjs/middleware/index.d.ts} +5 -53
  32. package/dist/cjs/middleware/index.js +48 -0
  33. package/dist/cjs/middleware/lambdaCorsResponseMiddleware.d.ts +20 -0
  34. package/dist/cjs/middleware/lambdaCorsResponseMiddleware.js +44 -0
  35. package/dist/cjs/middleware/throwNotFoundMiddleware.d.ts +4 -0
  36. package/dist/cjs/middleware/throwNotFoundMiddleware.js +14 -0
  37. package/dist/cjs/misc/hashValue.d.ts +10 -0
  38. package/dist/cjs/misc/hashValue.js +17 -0
  39. package/dist/cjs/misc/helpers.d.ts +124 -0
  40. package/dist/cjs/misc/helpers.js +214 -0
  41. package/dist/cjs/misc/merge.d.ts +21 -0
  42. package/dist/cjs/misc/merge.js +45 -0
  43. package/dist/cjs/misc/partitionSequence.d.ts +35 -0
  44. package/dist/cjs/misc/partitionSequence.js +55 -0
  45. package/dist/cjs/pagination/index.d.ts +91 -0
  46. package/dist/cjs/pagination/index.js +83 -0
  47. package/dist/cjs/routing/helpers.d.ts +57 -0
  48. package/dist/cjs/routing/helpers.js +90 -0
  49. package/dist/cjs/routing/index.d.ts +290 -0
  50. package/dist/cjs/routing/index.js +295 -0
  51. package/dist/cjs/routing/validators/zod.d.ts +4 -0
  52. package/dist/cjs/routing/validators/zod.js +14 -0
  53. package/dist/cjs/services/accountsGateway/index.d.ts +92 -0
  54. package/dist/cjs/services/accountsGateway/index.js +138 -0
  55. package/dist/cjs/services/apiGateway/index.d.ts +68 -0
  56. package/dist/cjs/services/apiGateway/index.js +118 -0
  57. package/dist/cjs/services/authProvider/browser.d.ts +40 -0
  58. package/dist/cjs/services/authProvider/browser.js +155 -0
  59. package/dist/cjs/services/authProvider/decryption.d.ts +19 -0
  60. package/dist/cjs/services/authProvider/decryption.js +73 -0
  61. package/dist/cjs/services/authProvider/index.d.ts +63 -0
  62. package/dist/cjs/services/authProvider/index.js +34 -0
  63. package/dist/cjs/services/authProvider/subrequest.d.ts +13 -0
  64. package/dist/cjs/services/authProvider/subrequest.js +49 -0
  65. package/dist/cjs/services/authProvider/utils/decryptAndVerify.d.ts +28 -0
  66. package/dist/cjs/services/authProvider/utils/decryptAndVerify.js +91 -0
  67. package/dist/cjs/services/authProvider/utils/embeddedAuthProvider.d.ts +26 -0
  68. package/dist/cjs/services/authProvider/utils/embeddedAuthProvider.js +47 -0
  69. package/dist/cjs/services/authProvider/utils/userRoleValidator.d.ts +13 -0
  70. package/dist/cjs/services/authProvider/utils/userRoleValidator.js +37 -0
  71. package/dist/cjs/services/authProvider/utils/userSubrequest.d.ts +3 -0
  72. package/dist/cjs/services/authProvider/utils/userSubrequest.js +13 -0
  73. package/dist/cjs/services/documentStore/dynamoEncoding.d.ts +10 -0
  74. package/dist/cjs/services/documentStore/dynamoEncoding.js +52 -0
  75. package/dist/cjs/services/documentStore/fileSystemAssert.d.ts +1 -0
  76. package/dist/cjs/services/documentStore/fileSystemAssert.js +14 -0
  77. package/{packages/utils/src/services/documentStore/index.ts → dist/cjs/services/documentStore/index.d.ts} +8 -8
  78. package/dist/cjs/services/documentStore/index.js +2 -0
  79. package/dist/cjs/services/documentStore/unversioned/dynamodb.d.ts +31 -0
  80. package/dist/cjs/services/documentStore/unversioned/dynamodb.js +233 -0
  81. package/dist/cjs/services/documentStore/unversioned/file-system.d.ts +32 -0
  82. package/dist/cjs/services/documentStore/unversioned/file-system.js +214 -0
  83. package/{packages/utils/src/services/documentStore/unversioned/index.ts → dist/cjs/services/documentStore/unversioned/index.d.ts} +0 -2
  84. package/dist/cjs/services/documentStore/unversioned/index.js +2 -0
  85. package/dist/cjs/services/documentStore/versioned/dynamodb.d.ts +25 -0
  86. package/dist/cjs/services/documentStore/versioned/dynamodb.js +143 -0
  87. package/dist/cjs/services/documentStore/versioned/file-system.d.ts +25 -0
  88. package/dist/cjs/services/documentStore/versioned/file-system.js +73 -0
  89. package/dist/cjs/services/documentStore/versioned/index.d.ts +17 -0
  90. package/dist/cjs/services/documentStore/versioned/index.js +2 -0
  91. package/dist/cjs/services/exercisesGateway/index.d.ts +67 -0
  92. package/dist/cjs/services/exercisesGateway/index.js +107 -0
  93. package/dist/cjs/services/fileServer/index.d.ts +30 -0
  94. package/dist/cjs/services/fileServer/index.js +19 -0
  95. package/dist/cjs/services/fileServer/localFileServer.d.ts +13 -0
  96. package/dist/cjs/services/fileServer/localFileServer.js +132 -0
  97. package/dist/cjs/services/fileServer/s3FileServer.d.ts +14 -0
  98. package/dist/cjs/services/fileServer/s3FileServer.js +131 -0
  99. package/dist/cjs/services/launchParams/index.js +7 -0
  100. package/dist/cjs/services/launchParams/signer.d.ts +23 -0
  101. package/dist/cjs/services/launchParams/signer.js +58 -0
  102. package/dist/cjs/services/launchParams/verifier.d.ts +21 -0
  103. package/dist/cjs/services/launchParams/verifier.js +129 -0
  104. package/dist/cjs/services/logger/console.d.ts +4 -0
  105. package/dist/cjs/services/logger/console.js +12 -0
  106. package/{packages/utils/src/services/logger/index.ts → dist/cjs/services/logger/index.d.ts} +9 -23
  107. package/dist/cjs/services/logger/index.js +31 -0
  108. package/dist/cjs/services/lrsGateway/addStatementDefaultFields.d.ts +5 -0
  109. package/dist/cjs/services/lrsGateway/addStatementDefaultFields.js +21 -0
  110. package/dist/cjs/services/lrsGateway/attempt-utils.d.ts +72 -0
  111. package/dist/cjs/services/lrsGateway/attempt-utils.js +283 -0
  112. package/dist/cjs/services/lrsGateway/file-system.d.ts +15 -0
  113. package/dist/cjs/services/lrsGateway/file-system.js +150 -0
  114. package/dist/cjs/services/lrsGateway/index.d.ts +122 -0
  115. package/dist/cjs/services/lrsGateway/index.js +148 -0
  116. package/dist/cjs/services/lrsGateway/xapiUtils.d.ts +71 -0
  117. package/dist/cjs/services/lrsGateway/xapiUtils.js +145 -0
  118. package/dist/cjs/services/postgresConnection/index.d.ts +28 -0
  119. package/dist/cjs/services/postgresConnection/index.js +65 -0
  120. package/dist/cjs/services/searchProvider/index.d.ts +69 -0
  121. package/dist/cjs/services/searchProvider/index.js +2 -0
  122. package/dist/cjs/services/searchProvider/memorySearchTheBadWay.d.ts +20 -0
  123. package/dist/cjs/services/searchProvider/memorySearchTheBadWay.js +191 -0
  124. package/dist/cjs/services/searchProvider/openSearch.d.ts +28 -0
  125. package/dist/cjs/services/searchProvider/openSearch.js +162 -0
  126. package/dist/cjs/services/searchProvider/streamIndexer.d.ts +17 -0
  127. package/dist/cjs/services/searchProvider/streamIndexer.js +41 -0
  128. package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -0
  129. package/{packages/utils/src/types.ts → dist/cjs/types.d.ts} +6 -34
  130. package/dist/cjs/types.js +2 -0
  131. package/dist/esm/assertions/index.d.ts +89 -0
  132. package/{packages/utils/src/assertions/index.ts → dist/esm/assertions/index.js} +49 -64
  133. package/dist/esm/aws/ssmService.d.ts +5 -0
  134. package/dist/esm/aws/ssmService.js +6 -0
  135. package/dist/esm/config/awsParameterConfig.d.ts +10 -0
  136. package/dist/esm/config/awsParameterConfig.js +22 -0
  137. package/dist/esm/config/envConfig.d.ts +24 -0
  138. package/dist/esm/config/envConfig.js +53 -0
  139. package/dist/esm/config/index.d.ts +48 -0
  140. package/dist/esm/config/index.js +17 -0
  141. package/dist/esm/config/lambdaParameterConfig.d.ts +12 -0
  142. package/dist/esm/config/lambdaParameterConfig.js +38 -0
  143. package/dist/esm/config/replaceConfig.d.ts +14 -0
  144. package/{packages/utils/src/config/replaceConfig.ts → dist/esm/config/replaceConfig.js} +6 -16
  145. package/dist/esm/config/resolveConfigValue.d.ts +5 -0
  146. package/dist/esm/config/resolveConfigValue.js +8 -0
  147. package/dist/esm/errors/index.d.ts +88 -0
  148. package/{packages/utils/src/errors/index.ts → dist/esm/errors/index.js} +41 -57
  149. package/dist/esm/fetch/fetchStatusRetry.d.ts +8 -0
  150. package/dist/esm/fetch/fetchStatusRetry.js +23 -0
  151. package/dist/esm/fetch/index.d.ts +64 -0
  152. package/dist/esm/fetch/index.js +46 -0
  153. package/dist/esm/guards/index.d.ts +38 -0
  154. package/dist/esm/guards/index.js +36 -0
  155. package/dist/esm/index.d.ts +4 -0
  156. package/dist/esm/index.js +4 -0
  157. package/dist/esm/middleware/apiErrorHandler.d.ts +24 -0
  158. package/dist/esm/middleware/apiErrorHandler.js +38 -0
  159. package/dist/esm/middleware/apiSlowResponseMiddleware.d.ts +23 -0
  160. package/dist/esm/middleware/apiSlowResponseMiddleware.js +50 -0
  161. package/dist/esm/middleware/index.d.ts +47 -0
  162. package/dist/esm/middleware/index.js +44 -0
  163. package/dist/esm/middleware/lambdaCorsResponseMiddleware.d.ts +20 -0
  164. package/dist/esm/middleware/lambdaCorsResponseMiddleware.js +40 -0
  165. package/dist/esm/middleware/throwNotFoundMiddleware.d.ts +4 -0
  166. package/dist/esm/middleware/throwNotFoundMiddleware.js +10 -0
  167. package/dist/esm/misc/hashValue.d.ts +10 -0
  168. package/dist/esm/misc/hashValue.js +13 -0
  169. package/dist/esm/misc/helpers.d.ts +124 -0
  170. package/dist/esm/misc/helpers.js +199 -0
  171. package/dist/esm/misc/merge.d.ts +21 -0
  172. package/dist/esm/misc/merge.js +40 -0
  173. package/dist/esm/misc/partitionSequence.d.ts +35 -0
  174. package/{packages/utils/src/misc/partitionSequence.ts → dist/esm/misc/partitionSequence.js} +15 -23
  175. package/dist/esm/pagination/index.d.ts +91 -0
  176. package/dist/esm/pagination/index.js +77 -0
  177. package/dist/esm/routing/helpers.d.ts +57 -0
  178. package/{packages/utils/src/routing/helpers.ts → dist/esm/routing/helpers.js} +30 -42
  179. package/dist/esm/routing/index.d.ts +290 -0
  180. package/dist/esm/routing/index.js +246 -0
  181. package/dist/esm/routing/validators/zod.d.ts +4 -0
  182. package/dist/esm/routing/validators/zod.js +10 -0
  183. package/dist/esm/services/accountsGateway/index.d.ts +92 -0
  184. package/dist/esm/services/accountsGateway/index.js +131 -0
  185. package/dist/esm/services/apiGateway/index.d.ts +68 -0
  186. package/dist/esm/services/apiGateway/index.js +77 -0
  187. package/dist/esm/services/authProvider/browser.d.ts +40 -0
  188. package/dist/esm/services/authProvider/browser.js +151 -0
  189. package/dist/esm/services/authProvider/decryption.d.ts +19 -0
  190. package/dist/esm/services/authProvider/decryption.js +69 -0
  191. package/dist/esm/services/authProvider/index.d.ts +63 -0
  192. package/dist/esm/services/authProvider/index.js +26 -0
  193. package/dist/esm/services/authProvider/subrequest.d.ts +13 -0
  194. package/dist/esm/services/authProvider/subrequest.js +45 -0
  195. package/dist/esm/services/authProvider/utils/decryptAndVerify.d.ts +28 -0
  196. package/dist/esm/services/authProvider/utils/decryptAndVerify.js +85 -0
  197. package/dist/esm/services/authProvider/utils/embeddedAuthProvider.d.ts +26 -0
  198. package/dist/esm/services/authProvider/utils/embeddedAuthProvider.js +40 -0
  199. package/dist/esm/services/authProvider/utils/userRoleValidator.d.ts +13 -0
  200. package/dist/esm/services/authProvider/utils/userRoleValidator.js +33 -0
  201. package/dist/esm/services/authProvider/utils/userSubrequest.d.ts +3 -0
  202. package/dist/esm/services/authProvider/utils/userSubrequest.js +6 -0
  203. package/dist/esm/services/documentStore/dynamoEncoding.d.ts +10 -0
  204. package/dist/esm/services/documentStore/dynamoEncoding.js +45 -0
  205. package/dist/esm/services/documentStore/fileSystemAssert.d.ts +1 -0
  206. package/dist/esm/services/documentStore/fileSystemAssert.js +10 -0
  207. package/dist/esm/services/documentStore/index.d.ts +14 -0
  208. package/dist/esm/services/documentStore/index.js +1 -0
  209. package/dist/esm/services/documentStore/unversioned/dynamodb.d.ts +31 -0
  210. package/dist/esm/services/documentStore/unversioned/dynamodb.js +226 -0
  211. package/dist/esm/services/documentStore/unversioned/file-system.d.ts +32 -0
  212. package/dist/esm/services/documentStore/unversioned/file-system.js +174 -0
  213. package/dist/esm/services/documentStore/unversioned/index.d.ts +2 -0
  214. package/dist/esm/services/documentStore/unversioned/index.js +1 -0
  215. package/dist/esm/services/documentStore/versioned/dynamodb.d.ts +25 -0
  216. package/dist/esm/services/documentStore/versioned/dynamodb.js +139 -0
  217. package/dist/esm/services/documentStore/versioned/file-system.d.ts +25 -0
  218. package/dist/esm/services/documentStore/versioned/file-system.js +69 -0
  219. package/dist/esm/services/documentStore/versioned/index.d.ts +17 -0
  220. package/dist/esm/services/documentStore/versioned/index.js +1 -0
  221. package/dist/esm/services/exercisesGateway/index.d.ts +67 -0
  222. package/dist/esm/services/exercisesGateway/index.js +70 -0
  223. package/dist/esm/services/fileServer/index.d.ts +30 -0
  224. package/dist/esm/services/fileServer/index.js +13 -0
  225. package/dist/esm/services/fileServer/localFileServer.d.ts +13 -0
  226. package/dist/esm/services/fileServer/localFileServer.js +125 -0
  227. package/dist/esm/services/fileServer/s3FileServer.d.ts +14 -0
  228. package/dist/esm/services/fileServer/s3FileServer.js +124 -0
  229. package/dist/esm/services/launchParams/index.d.ts +2 -0
  230. package/dist/esm/services/launchParams/index.js +2 -0
  231. package/dist/esm/services/launchParams/signer.d.ts +23 -0
  232. package/dist/esm/services/launchParams/signer.js +51 -0
  233. package/dist/esm/services/launchParams/verifier.d.ts +21 -0
  234. package/dist/esm/services/launchParams/verifier.js +92 -0
  235. package/dist/esm/services/logger/console.d.ts +4 -0
  236. package/{packages/utils/src/services/logger/console.ts → dist/esm/services/logger/console.js} +2 -5
  237. package/dist/esm/services/logger/index.d.ts +39 -0
  238. package/dist/esm/services/logger/index.js +27 -0
  239. package/dist/esm/services/lrsGateway/addStatementDefaultFields.d.ts +5 -0
  240. package/dist/esm/services/lrsGateway/addStatementDefaultFields.js +14 -0
  241. package/dist/esm/services/lrsGateway/attempt-utils.d.ts +72 -0
  242. package/dist/esm/services/lrsGateway/attempt-utils.js +261 -0
  243. package/dist/esm/services/lrsGateway/file-system.d.ts +15 -0
  244. package/dist/esm/services/lrsGateway/file-system.js +110 -0
  245. package/dist/esm/services/lrsGateway/index.d.ts +122 -0
  246. package/dist/esm/services/lrsGateway/index.js +111 -0
  247. package/dist/esm/services/lrsGateway/xapiUtils.d.ts +71 -0
  248. package/dist/esm/services/lrsGateway/xapiUtils.js +134 -0
  249. package/dist/esm/services/postgresConnection/index.d.ts +28 -0
  250. package/dist/esm/services/postgresConnection/index.js +58 -0
  251. package/dist/esm/services/searchProvider/index.d.ts +69 -0
  252. package/dist/esm/services/searchProvider/index.js +1 -0
  253. package/dist/esm/services/searchProvider/memorySearchTheBadWay.d.ts +20 -0
  254. package/dist/esm/services/searchProvider/memorySearchTheBadWay.js +187 -0
  255. package/dist/esm/services/searchProvider/openSearch.d.ts +28 -0
  256. package/dist/esm/services/searchProvider/openSearch.js +158 -0
  257. package/dist/esm/services/searchProvider/streamIndexer.d.ts +17 -0
  258. package/dist/esm/services/searchProvider/streamIndexer.js +37 -0
  259. package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -0
  260. package/dist/esm/types.d.ts +31 -0
  261. package/dist/esm/types.js +1 -0
  262. package/package.json +234 -12
  263. package/.cfnlintrc +0 -2
  264. package/.github/CODEOWNERS +0 -1
  265. package/.github/workflows/ci.yml +0 -36
  266. package/.github/workflows/lint.yml +0 -55
  267. package/.nvmrc +0 -1
  268. package/.syncignore +0 -4
  269. package/.syncpackrc +0 -18
  270. package/CONTRIBUTING.md +0 -96
  271. package/LICENSE +0 -661
  272. package/Procfile +0 -1
  273. package/app.json +0 -23
  274. package/cspell.json +0 -32
  275. package/deploy/constants.env +0 -21
  276. package/deploy/deploy.bash +0 -157
  277. package/deploy/deployment-alt-region.cfn.yml +0 -70
  278. package/deploy/deployment.cfn.yml +0 -650
  279. package/deploy/destroy-deployment.bash +0 -23
  280. package/deploy/shared.cfn.yml +0 -94
  281. package/docs/lambda-build.md +0 -35
  282. package/packages/frontend/README.md +0 -46
  283. package/packages/frontend/package.json +0 -101
  284. package/packages/frontend/public/favicon.ico +0 -0
  285. package/packages/frontend/public/index.html +0 -107
  286. package/packages/frontend/public/maintenance.html +0 -59
  287. package/packages/frontend/public/manifest.json +0 -15
  288. package/packages/frontend/public/robots.txt +0 -3
  289. package/packages/frontend/script/make-certificate.bash +0 -49
  290. package/packages/frontend/script/server/cli.js +0 -11
  291. package/packages/frontend/script/server/index.js +0 -47
  292. package/packages/frontend/script/start.bash +0 -22
  293. package/packages/frontend/script/trust-localhost.bash +0 -7
  294. package/packages/frontend/src/auth/authProvider.ts +0 -10
  295. package/packages/frontend/src/auth/useAuth.ts +0 -33
  296. package/packages/frontend/src/components/Pagination.tsx +0 -26
  297. package/packages/frontend/src/configProvider/index.ts +0 -53
  298. package/packages/frontend/src/configProvider/use.ts +0 -41
  299. package/packages/frontend/src/core/context/services.spec.tsx +0 -39
  300. package/packages/frontend/src/core/context/services.tsx +0 -16
  301. package/packages/frontend/src/core/index.spec.ts +0 -7
  302. package/packages/frontend/src/core/index.ts +0 -20
  303. package/packages/frontend/src/core/services.tsx +0 -14
  304. package/packages/frontend/src/core/types.ts +0 -3
  305. package/packages/frontend/src/example/api.ts +0 -28
  306. package/packages/frontend/src/example/components/Layout.tsx +0 -23
  307. package/packages/frontend/src/example/screens/Home.spec.tsx +0 -68
  308. package/packages/frontend/src/example/screens/Home.tsx +0 -78
  309. package/packages/frontend/src/example/screens/ThingList.spec.tsx +0 -60
  310. package/packages/frontend/src/example/screens/ThingList.tsx +0 -75
  311. package/packages/frontend/src/example/screens/ThingView.spec.tsx +0 -71
  312. package/packages/frontend/src/example/screens/ThingView.tsx +0 -47
  313. package/packages/frontend/src/example/screens/index.ts +0 -9
  314. package/packages/frontend/src/index.css +0 -159
  315. package/packages/frontend/src/index.tsx +0 -67
  316. package/packages/frontend/src/react-app-env.d.ts +0 -1
  317. package/packages/frontend/src/routing/components/RouteLink.spec.tsx +0 -55
  318. package/packages/frontend/src/routing/components/RouteLink.tsx +0 -35
  319. package/packages/frontend/src/routing/middleware.ts +0 -6
  320. package/packages/frontend/src/routing/useQuery.ts +0 -14
  321. package/packages/frontend/src/setupProxy.js +0 -19
  322. package/packages/frontend/src/setupTests.ts +0 -9
  323. package/packages/frontend/src/tests/testServices.tsx +0 -23
  324. package/packages/frontend/tsconfig.json +0 -27
  325. package/packages/lambda/.eslintrc.js +0 -64
  326. package/packages/lambda/jest-global-setup.js +0 -3
  327. package/packages/lambda/jest-setup-after-env.js +0 -1
  328. package/packages/lambda/jest.config.js +0 -31
  329. package/packages/lambda/jest.resolver.js +0 -17
  330. package/packages/lambda/package.json +0 -68
  331. package/packages/lambda/script/build.bash +0 -19
  332. package/packages/lambda/script/bundle-functions.bash +0 -10
  333. package/packages/lambda/script/lambdaLocalProxy.js +0 -16
  334. package/packages/lambda/script/lambdaLocalProxy.spec.ts +0 -147
  335. package/packages/lambda/script/utils/getRouteData.ts +0 -7
  336. package/packages/lambda/script/utils/routeDataLoader.js +0 -8
  337. package/packages/lambda/script/utils/routeDataLoader.spec.ts +0 -8
  338. package/packages/lambda/src/functions/serviceApi/core/index.ts +0 -7
  339. package/packages/lambda/src/functions/serviceApi/core/request.spec.ts +0 -38
  340. package/packages/lambda/src/functions/serviceApi/core/request.ts +0 -42
  341. package/packages/lambda/src/functions/serviceApi/core/routes.spec.ts +0 -7
  342. package/packages/lambda/src/functions/serviceApi/core/routes.ts +0 -10
  343. package/packages/lambda/src/functions/serviceApi/core/services.ts +0 -9
  344. package/packages/lambda/src/functions/serviceApi/core/types.ts +0 -13
  345. package/packages/lambda/src/functions/serviceApi/entry/lambda/https-xray.ts +0 -4
  346. package/packages/lambda/src/functions/serviceApi/entry/lambda/index.spec.ts +0 -48
  347. package/packages/lambda/src/functions/serviceApi/entry/lambda/index.ts +0 -58
  348. package/packages/lambda/src/functions/serviceApi/entry/lambda/services.ts +0 -36
  349. package/packages/lambda/src/functions/serviceApi/entry/local.ts +0 -71
  350. package/packages/lambda/src/functions/serviceApi/versions/v0/example/documentSearchMiddleware.spec.ts +0 -16
  351. package/packages/lambda/src/functions/serviceApi/versions/v0/example/documentSearchMiddleware.ts +0 -41
  352. package/packages/lambda/src/functions/serviceApi/versions/v0/example/documentStoreMiddleware.spec.ts +0 -78
  353. package/packages/lambda/src/functions/serviceApi/versions/v0/example/documentStoreMiddleware.ts +0 -70
  354. package/packages/lambda/src/functions/serviceApi/versions/v0/example/routes.spec.ts +0 -306
  355. package/packages/lambda/src/functions/serviceApi/versions/v0/example/routes.ts +0 -176
  356. package/packages/lambda/src/functions/serviceApi/versions/v0/index.spec.ts +0 -263
  357. package/packages/lambda/src/functions/serviceApi/versions/v0/index.ts +0 -134
  358. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/authMiddleware.spec.ts +0 -23
  359. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/authMiddleware.ts +0 -32
  360. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/configMiddleware.spec.ts +0 -10
  361. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/configMiddleware.ts +0 -7
  362. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/frontendFileServerMiddleware.spec.ts +0 -13
  363. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/frontendFileServerMiddleware.ts +0 -23
  364. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/paginationMiddleware.spec.ts +0 -9
  365. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/paginationMiddleware.ts +0 -9
  366. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/searchMiddleware.spec.ts +0 -12
  367. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/searchMiddleware.ts +0 -21
  368. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/userRoleValidatorMiddleware.spec.ts +0 -21
  369. package/packages/lambda/src/functions/serviceApi/versions/v0/middleware/userRoleValidatorMiddleware.ts +0 -18
  370. package/packages/lambda/tsconfig.json +0 -30
  371. package/packages/lambda/webpack.config.js +0 -97
  372. package/packages/utils/.eslintrc.js +0 -64
  373. package/packages/utils/README.md +0 -118
  374. package/packages/utils/jest-global-setup.js +0 -3
  375. package/packages/utils/jest.config.js +0 -25
  376. package/packages/utils/jest.resolver.js +0 -17
  377. package/packages/utils/package.json +0 -238
  378. package/packages/utils/src/assertions/index.spec.ts +0 -126
  379. package/packages/utils/src/aws/ssmService.ts +0 -7
  380. package/packages/utils/src/config/awsParameterConfig.ts +0 -24
  381. package/packages/utils/src/config/envConfig.ts +0 -58
  382. package/packages/utils/src/config/index.spec.ts +0 -165
  383. package/packages/utils/src/config/lambdaParameterConfig.ts +0 -49
  384. package/packages/utils/src/config/resolveConfigValue.ts +0 -10
  385. package/packages/utils/src/errors/index.spec.ts +0 -35
  386. package/packages/utils/src/fetch/fetchStatusRetry.spec.ts +0 -197
  387. package/packages/utils/src/fetch/fetchStatusRetry.ts +0 -33
  388. package/packages/utils/src/fetch/index.spec.ts +0 -34
  389. package/packages/utils/src/fetch/index.ts +0 -87
  390. package/packages/utils/src/guards/index.spec.ts +0 -58
  391. package/packages/utils/src/index.spec.ts +0 -471
  392. package/packages/utils/src/middleware/apiErrorHandler.spec.ts +0 -65
  393. package/packages/utils/src/middleware/apiErrorHandler.ts +0 -67
  394. package/packages/utils/src/middleware/apiSlowResponseMiddleware.spec.ts +0 -184
  395. package/packages/utils/src/middleware/apiSlowResponseMiddleware.ts +0 -71
  396. package/packages/utils/src/middleware/index.spec.ts +0 -99
  397. package/packages/utils/src/middleware/lambdaCorsResponseMiddleware.spec.ts +0 -103
  398. package/packages/utils/src/middleware/lambdaCorsResponseMiddleware.ts +0 -52
  399. package/packages/utils/src/middleware/throwNotFoundMiddleware.spec.ts +0 -20
  400. package/packages/utils/src/middleware/throwNotFoundMiddleware.ts +0 -11
  401. package/packages/utils/src/misc/hashValue.ts +0 -18
  402. package/packages/utils/src/misc/helpers.ts +0 -259
  403. package/packages/utils/src/misc/merge.ts +0 -48
  404. package/packages/utils/src/pagination/index.spec.ts +0 -150
  405. package/packages/utils/src/pagination/index.ts +0 -117
  406. package/packages/utils/src/routing/index.spec.ts +0 -553
  407. package/packages/utils/src/routing/index.ts +0 -424
  408. package/packages/utils/src/routing/validators/zod.spec.ts +0 -16
  409. package/packages/utils/src/routing/validators/zod.ts +0 -14
  410. package/packages/utils/src/services/accountsGateway/README.md +0 -3
  411. package/packages/utils/src/services/accountsGateway/index.spec.ts +0 -518
  412. package/packages/utils/src/services/accountsGateway/index.ts +0 -251
  413. package/packages/utils/src/services/apiGateway/README.md +0 -93
  414. package/packages/utils/src/services/apiGateway/index.spec.ts +0 -254
  415. package/packages/utils/src/services/apiGateway/index.ts +0 -189
  416. package/packages/utils/src/services/authProvider/README.md +0 -21
  417. package/packages/utils/src/services/authProvider/browser.spec.ts +0 -391
  418. package/packages/utils/src/services/authProvider/browser.ts +0 -209
  419. package/packages/utils/src/services/authProvider/decryption.spec.ts +0 -337
  420. package/packages/utils/src/services/authProvider/decryption.ts +0 -98
  421. package/packages/utils/src/services/authProvider/index.ts +0 -93
  422. package/packages/utils/src/services/authProvider/stub.spec.ts +0 -29
  423. package/packages/utils/src/services/authProvider/subrequest.spec.ts +0 -105
  424. package/packages/utils/src/services/authProvider/subrequest.ts +0 -68
  425. package/packages/utils/src/services/authProvider/utils/decryptAndVerify.spec.ts +0 -128
  426. package/packages/utils/src/services/authProvider/utils/decryptAndVerify.ts +0 -106
  427. package/packages/utils/src/services/authProvider/utils/embeddedAuthProvider.spec.ts +0 -26
  428. package/packages/utils/src/services/authProvider/utils/embeddedAuthProvider.ts +0 -57
  429. package/packages/utils/src/services/authProvider/utils/userRoleValidator.spec.ts +0 -135
  430. package/packages/utils/src/services/authProvider/utils/userRoleValidator.ts +0 -49
  431. package/packages/utils/src/services/authProvider/utils/userSubrequest.spec.ts +0 -26
  432. package/packages/utils/src/services/authProvider/utils/userSubrequest.ts +0 -10
  433. package/packages/utils/src/services/documentStore/dynamoEncoding.ts +0 -57
  434. package/packages/utils/src/services/documentStore/fileSystemAssert.spec.ts +0 -43
  435. package/packages/utils/src/services/documentStore/fileSystemAssert.ts +0 -10
  436. package/packages/utils/src/services/documentStore/unversioned/README.md +0 -13
  437. package/packages/utils/src/services/documentStore/unversioned/dynamodb.spec.ts +0 -859
  438. package/packages/utils/src/services/documentStore/unversioned/dynamodb.ts +0 -243
  439. package/packages/utils/src/services/documentStore/unversioned/file-system.spec.ts +0 -629
  440. package/packages/utils/src/services/documentStore/unversioned/file-system.ts +0 -194
  441. package/packages/utils/src/services/documentStore/versioned/README.md +0 -13
  442. package/packages/utils/src/services/documentStore/versioned/dynamodb.spec.ts +0 -376
  443. package/packages/utils/src/services/documentStore/versioned/dynamodb.ts +0 -167
  444. package/packages/utils/src/services/documentStore/versioned/file-system.spec.ts +0 -262
  445. package/packages/utils/src/services/documentStore/versioned/file-system.ts +0 -90
  446. package/packages/utils/src/services/documentStore/versioned/index.ts +0 -25
  447. package/packages/utils/src/services/exercisesGateway/README.md +0 -5
  448. package/packages/utils/src/services/exercisesGateway/index.spec.ts +0 -326
  449. package/packages/utils/src/services/exercisesGateway/index.ts +0 -163
  450. package/packages/utils/src/services/fileServer/index.spec.ts +0 -88
  451. package/packages/utils/src/services/fileServer/index.ts +0 -43
  452. package/packages/utils/src/services/fileServer/localFileServer.spec.ts +0 -182
  453. package/packages/utils/src/services/fileServer/localFileServer.ts +0 -159
  454. package/packages/utils/src/services/fileServer/s3FileServer.spec.ts +0 -266
  455. package/packages/utils/src/services/fileServer/s3FileServer.ts +0 -155
  456. package/packages/utils/src/services/launchParams/index.spec.ts +0 -366
  457. package/packages/utils/src/services/launchParams/signer.ts +0 -73
  458. package/packages/utils/src/services/launchParams/verifier.ts +0 -120
  459. package/packages/utils/src/services/logger/console.spec.ts +0 -29
  460. package/packages/utils/src/services/logger/index.spec.ts +0 -65
  461. package/packages/utils/src/services/lrsGateway/README.md +0 -5
  462. package/packages/utils/src/services/lrsGateway/addStatementDefaultFields.ts +0 -22
  463. package/packages/utils/src/services/lrsGateway/attempt-utils.spec.ts +0 -847
  464. package/packages/utils/src/services/lrsGateway/attempt-utils.ts +0 -358
  465. package/packages/utils/src/services/lrsGateway/file-system.spec.ts +0 -363
  466. package/packages/utils/src/services/lrsGateway/file-system.ts +0 -165
  467. package/packages/utils/src/services/lrsGateway/index.spec.ts +0 -194
  468. package/packages/utils/src/services/lrsGateway/index.ts +0 -257
  469. package/packages/utils/src/services/lrsGateway/xapiUtils.spec.ts +0 -887
  470. package/packages/utils/src/services/lrsGateway/xapiUtils.ts +0 -262
  471. package/packages/utils/src/services/postgresConnection/index.spec.ts +0 -170
  472. package/packages/utils/src/services/postgresConnection/index.ts +0 -84
  473. package/packages/utils/src/services/searchProvider/README.md +0 -3
  474. package/packages/utils/src/services/searchProvider/index.ts +0 -59
  475. package/packages/utils/src/services/searchProvider/memorySearchTheBadWay.spec.ts +0 -526
  476. package/packages/utils/src/services/searchProvider/memorySearchTheBadWay.ts +0 -223
  477. package/packages/utils/src/services/searchProvider/openSearch.spec.ts +0 -926
  478. package/packages/utils/src/services/searchProvider/openSearch.ts +0 -195
  479. package/packages/utils/tsconfig.json +0 -31
  480. package/packages/utils/tsconfig.without-specs.cjs.json +0 -7
  481. package/packages/utils/tsconfig.without-specs.esm.json +0 -7
  482. package/packages/utils/tsconfig.without-specs.json +0 -6
  483. package/scripts/build.bash +0 -24
  484. package/scripts/ci.bash +0 -10
  485. package/scripts/start.bash +0 -29
  486. /package/{packages/utils/src/index.ts → dist/cjs/index.d.ts} +0 -0
  487. /package/{packages/utils/src/services/launchParams/index.ts → dist/cjs/services/launchParams/index.d.ts} +0 -0
  488. /package/{packages/utils/script → script}/bin/copy-from-template.bash +0 -0
  489. /package/{packages/utils/script → script}/bin/delete-stack.bash +0 -0
  490. /package/{packages/utils/script → script}/bin/deploy.bash +0 -0
  491. /package/{packages/utils/script → script}/bin/destroy-deployment.bash +0 -0
  492. /package/{packages/utils/script → script}/bin/empty-bucket.bash +0 -0
  493. /package/{packages/utils/script → script}/bin/get-arg.bash +0 -0
  494. /package/{packages/utils/script → script}/bin/get-deployed-environments.bash +0 -0
  495. /package/{packages/utils/script → script}/bin/get-env-param.bash +0 -0
  496. /package/{packages/utils/script → script}/bin/get-kwarg.bash +0 -0
  497. /package/{packages/utils/script → script}/bin/get-stack-param.bash +0 -0
  498. /package/{packages/utils/script → script}/bin/has-flag.bash +0 -0
  499. /package/{packages/utils/script → script}/bin/init-constants-script.bash +0 -0
  500. /package/{packages/utils/script → script}/bin/init-params-script.bash +0 -0
  501. /package/{packages/utils/script → script}/bin/stack-exists.bash +0 -0
  502. /package/{packages/utils/script → script}/bin/update-utils.bash +0 -0
  503. /package/{packages/utils/script → script}/bin/upload-pager-duty-endpoints.bash +0 -0
  504. /package/{packages/utils/script → script}/bin/upload-params.bash +0 -0
  505. /package/{packages/utils/script → script}/bin/which.bash +0 -0
  506. /package/{packages/utils/script → script}/bin-entry.bash +0 -0
  507. /package/{packages/utils/script → script}/build.bash +0 -0
@@ -6,54 +6,26 @@
6
6
  *
7
7
  * There may be a better way to do this; `T1 extends T2` doesn't work
8
8
  */
9
- export type TupleExtends<T1, T2> = T1 extends [infer T1Head, ...infer T1Tail]
10
- ? T2 extends [infer T2Head, ...infer T2Tail]
11
- ? T1Head extends T2Head
12
- ? TupleExtends<T1Tail, T2Tail> extends 'yes'
13
- ? 'yes'
14
- : 'no'
15
- : 'no'
16
- : T2 extends []
17
- ? 'yes'
18
- : 'no'
19
- : T1 extends []
20
- ? T2 extends []
21
- ? 'yes'
22
- : 'no'
23
- : 'no'
24
- ;
25
-
9
+ export type TupleExtends<T1, T2> = T1 extends [infer T1Head, ...infer T1Tail] ? T2 extends [infer T2Head, ...infer T2Tail] ? T1Head extends T2Head ? TupleExtends<T1Tail, T2Tail> extends 'yes' ? 'yes' : 'no' : 'no' : T2 extends [] ? 'yes' : 'no' : T1 extends [] ? T2 extends [] ? 'yes' : 'no' : 'no';
26
10
  /**
27
11
  * unions each member of the tuple
28
12
  */
29
- export type TupleZip<T1, T2> = T1 extends [infer T1Head, ...infer T1Tail]
30
- ? T2 extends [infer T2Head, ...infer T2Tail]
31
- ? [T1Head & T2Head, ...TupleZip<T1Tail, T2Tail>]
32
- : T2 extends []
33
- ? T1
34
- : never
35
- : T1 extends []
36
- ? T2 extends any[]
37
- ? T2
38
- : never
39
- : never
40
- ;
41
-
13
+ export type TupleZip<T1, T2> = T1 extends [infer T1Head, ...infer T1Tail] ? T2 extends [infer T2Head, ...infer T2Tail] ? [T1Head & T2Head, ...TupleZip<T1Tail, T2Tail>] : T2 extends [] ? T1 : never : T1 extends [] ? T2 extends any[] ? T2 : never : never;
42
14
  /**
43
15
  * If `R` is `Promise<I>`, returns `I`, otherwise returns `R`
44
16
  * @deprecated use TypeScript builtin Awaited instead:
45
17
  * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#the-awaited-type-and-promise-improvements
46
18
  */
47
19
  export type UnwrapPromise<R> = R extends Promise<infer I> ? I : R;
48
-
49
20
  /**
50
21
  * turns `thing | thing2` into `thing & thing2`
51
22
  * @see https://stackoverflow.com/a/50375286/14809536
52
23
  */
53
- export type UnionToIntersection<U> = (U extends any ? (k: U)=>void : never) extends ((k: infer I)=>void) ? I : never;
54
-
24
+ export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
55
25
  /**
56
26
  * make certain fields required
57
27
  * @see https://stackoverflow.com/a/69328045/14809536
58
28
  */
59
- export type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };
29
+ export type WithRequired<T, K extends keyof T> = T & {
30
+ [P in K]-?: T[P];
31
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,89 @@
1
+ export type AssertionFailed = string | Error | (() => never) | undefined;
2
+ export declare const doThrow: (failed: AssertionFailed) => never;
3
+ /**
4
+ * Asserts that the given value is true.
5
+ *
6
+ * @param x The value to assert.
7
+ * @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
8
+ * to provide some value for this for traceability. Passing an Error instead of a string
9
+ * makes the stack trace more useful and allows you to handle assertion failures differently.
10
+ * @example const definitelyTrue = assertTrue(randomThing, new Error('thing was not true'));
11
+ * @returns the value that was asserted
12
+ */
13
+ export declare const assertTrue: <X>(x: X, failed?: AssertionFailed) => X & true;
14
+ /**
15
+ * Asserts that the given value is false.
16
+ *
17
+ * @param x The value to assert.
18
+ * @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
19
+ * to provide some value for this for traceability. Passing an Error instead of a string
20
+ * makes the stack trace more useful and allows you to handle assertion failures differently.
21
+ * @example const definitelyFalse = assertFalse(randomThing, new Error('thing was not false'));
22
+ * @returns the value that was asserted
23
+ */
24
+ export declare const assertFalse: <X>(x: X, failed?: AssertionFailed) => X & false;
25
+ /**
26
+ * Asserts that the given value is defined.
27
+ *
28
+ * @param x The value to assert.
29
+ * @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
30
+ * to provide some value for this for traceability. Passing an Error instead of a string
31
+ * makes the stack trace more useful and allows you to handle assertion failures differently.
32
+ * @example const definitelyDefined = assertDefined(randomThing, new Error('thing was undefined'));
33
+ * @returns the value that was asserted, with a type that excludes undefined
34
+ */
35
+ export declare const assertDefined: <X>(x: X, failed?: AssertionFailed) => Exclude<X, undefined>;
36
+ /**
37
+ * Asserts that the given value is a string.
38
+ *
39
+ * @param x The value to assert.
40
+ * @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
41
+ * to provide some value for this for traceability. Passing an Error instead of a string
42
+ * makes the stack trace more useful and allows you to handle assertion failures differently.
43
+ * @example const definitelyAString = assertString(randomThing, new Error('thing is not a string'));
44
+ * @returns the value that was asserted
45
+ */
46
+ export declare const assertString: <X>(x: X, failed?: AssertionFailed) => string;
47
+ /**
48
+ * Asserts that the given value is not `NaN`. Does not assert that the value is a number.
49
+ *
50
+ * @param thing The value to assert.
51
+ * @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
52
+ * to provide some value for this for traceability. Passing an Error instead of a string
53
+ * makes the stack trace more useful and allows you to handle assertion failures differently.
54
+ * @example const definitelyNotNotANumber = assertNotNaN(randomThing, new Error('thing was NaN'));
55
+ * @returns the value that was asserted
56
+ */
57
+ export declare const assertNotNaN: <T>(thing: T, failed?: AssertionFailed) => T;
58
+ /**
59
+ * @deprecated use assertNotNaN instead
60
+ */
61
+ export declare const notNaN: <T>(thing: T, failed?: AssertionFailed) => T;
62
+ /**
63
+ * Asserts that the first argument is an instance of the second.
64
+ *
65
+ * @param thing The value to assert.
66
+ * @param constructable The class to check against.
67
+ * @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
68
+ * to provide some value for this for traceability. Passing an Error instead of a string
69
+ * makes the stack trace more useful and allows you to handle assertion failures differently.
70
+ * @example const definitelySyntaxError = assertInstanceOf(error, SyntaxError, new Error('argument was not a SyntaxError'));
71
+ * @returns the value that was asserted
72
+ */
73
+ export declare const assertInstanceOf: <T>(thing: any, constructable: Function & {
74
+ new (...args: any[]): T;
75
+ }, failed?: AssertionFailed) => T;
76
+ /**
77
+ * Asserts that the error in the first argument is an instance of the error given as the
78
+ * second argument
79
+ *
80
+ * @param thing The value to assert.
81
+ * @param constructable The error class to check against.
82
+ * @example const definitelySyntaxError = assertInstanceOf(error, SyntaxError);
83
+ * @returns the value that was asserted
84
+ * @throws the original error if the check fails
85
+ * @see assertInstanceOf
86
+ */
87
+ export declare const assertErrorInstanceOf: <T extends Error>(thing: unknown, constructable: Function & {
88
+ new (...args: any[]): T;
89
+ }) => T;
@@ -11,22 +11,18 @@
11
11
  * stack trace more useful, and allows you to use specific error types
12
12
  * that might be handled differently.
13
13
  */
14
-
15
- export type AssertionFailed = string | Error | (() => never) | undefined;
16
-
17
- export const doThrow = (failed: AssertionFailed): never => {
18
- if (typeof failed === 'string') {
19
- throw new Error(failed);
20
- }
21
- if (failed instanceof Error) {
22
- throw failed;
23
- }
24
- if (!failed) {
25
- throw new Error();
26
- }
27
- return failed();
14
+ export const doThrow = (failed) => {
15
+ if (typeof failed === 'string') {
16
+ throw new Error(failed);
17
+ }
18
+ if (failed instanceof Error) {
19
+ throw failed;
20
+ }
21
+ if (!failed) {
22
+ throw new Error();
23
+ }
24
+ return failed();
28
25
  };
29
-
30
26
  /**
31
27
  * Asserts that the given value is true.
32
28
  *
@@ -37,14 +33,12 @@ export const doThrow = (failed: AssertionFailed): never => {
37
33
  * @example const definitelyTrue = assertTrue(randomThing, new Error('thing was not true'));
38
34
  * @returns the value that was asserted
39
35
  */
40
- export const assertTrue = <X>(x: X, failed?: AssertionFailed) => {
41
- if (typeof x !== 'boolean' || x !== true) {
42
- return doThrow(failed);
43
- }
44
-
45
- return x;
36
+ export const assertTrue = (x, failed) => {
37
+ if (typeof x !== 'boolean' || x !== true) {
38
+ return doThrow(failed);
39
+ }
40
+ return x;
46
41
  };
47
-
48
42
  /**
49
43
  * Asserts that the given value is false.
50
44
  *
@@ -55,14 +49,12 @@ export const assertTrue = <X>(x: X, failed?: AssertionFailed) => {
55
49
  * @example const definitelyFalse = assertFalse(randomThing, new Error('thing was not false'));
56
50
  * @returns the value that was asserted
57
51
  */
58
- export const assertFalse = <X>(x: X, failed?: AssertionFailed) => {
59
- if (typeof x !== 'boolean' || x !== false) {
60
- return doThrow(failed);
61
- }
62
-
63
- return x;
52
+ export const assertFalse = (x, failed) => {
53
+ if (typeof x !== 'boolean' || x !== false) {
54
+ return doThrow(failed);
55
+ }
56
+ return x;
64
57
  };
65
-
66
58
  /**
67
59
  * Asserts that the given value is defined.
68
60
  *
@@ -73,14 +65,12 @@ export const assertFalse = <X>(x: X, failed?: AssertionFailed) => {
73
65
  * @example const definitelyDefined = assertDefined(randomThing, new Error('thing was undefined'));
74
66
  * @returns the value that was asserted, with a type that excludes undefined
75
67
  */
76
- export const assertDefined = <X>(x: X, failed?: AssertionFailed) => {
77
- if (x === undefined) {
78
- return doThrow(failed);
79
- }
80
-
81
- return x as Exclude<X, undefined>;
68
+ export const assertDefined = (x, failed) => {
69
+ if (x === undefined) {
70
+ return doThrow(failed);
71
+ }
72
+ return x;
82
73
  };
83
-
84
74
  /**
85
75
  * Asserts that the given value is a string.
86
76
  *
@@ -91,14 +81,12 @@ export const assertDefined = <X>(x: X, failed?: AssertionFailed) => {
91
81
  * @example const definitelyAString = assertString(randomThing, new Error('thing is not a string'));
92
82
  * @returns the value that was asserted
93
83
  */
94
- export const assertString = <X>(x: X, failed?: AssertionFailed): string => {
95
- if (typeof x !== 'string') {
96
- return doThrow(failed);
97
- }
98
-
99
- return x;
84
+ export const assertString = (x, failed) => {
85
+ if (typeof x !== 'string') {
86
+ return doThrow(failed);
87
+ }
88
+ return x;
100
89
  };
101
-
102
90
  /**
103
91
  * Asserts that the given value is not `NaN`. Does not assert that the value is a number.
104
92
  *
@@ -109,18 +97,16 @@ export const assertString = <X>(x: X, failed?: AssertionFailed): string => {
109
97
  * @example const definitelyNotNotANumber = assertNotNaN(randomThing, new Error('thing was NaN'));
110
98
  * @returns the value that was asserted
111
99
  */
112
- export const assertNotNaN = <T>(thing: T, failed?: AssertionFailed): T => {
113
- if (typeof thing === 'number' && isNaN(thing)) {
114
- return doThrow(failed);
115
- }
116
- return thing;
100
+ export const assertNotNaN = (thing, failed) => {
101
+ if (typeof thing === 'number' && isNaN(thing)) {
102
+ return doThrow(failed);
103
+ }
104
+ return thing;
117
105
  };
118
-
119
106
  /**
120
107
  * @deprecated use assertNotNaN instead
121
108
  */
122
109
  export const notNaN = assertNotNaN;
123
-
124
110
  /**
125
111
  * Asserts that the first argument is an instance of the second.
126
112
  *
@@ -132,13 +118,12 @@ export const notNaN = assertNotNaN;
132
118
  * @example const definitelySyntaxError = assertInstanceOf(error, SyntaxError, new Error('argument was not a SyntaxError'));
133
119
  * @returns the value that was asserted
134
120
  */
135
- export const assertInstanceOf = <T>(thing: any, constructable: Function & { new(...args: any[]): T }, failed?: AssertionFailed): T => {
136
- if (thing instanceof constructable) {
137
- return thing;
138
- }
139
- return doThrow(failed);
121
+ export const assertInstanceOf = (thing, constructable, failed) => {
122
+ if (thing instanceof constructable) {
123
+ return thing;
124
+ }
125
+ return doThrow(failed);
140
126
  };
141
-
142
127
  /**
143
128
  * Asserts that the error in the first argument is an instance of the error given as the
144
129
  * second argument
@@ -150,12 +135,12 @@ export const assertInstanceOf = <T>(thing: any, constructable: Function & { new(
150
135
  * @throws the original error if the check fails
151
136
  * @see assertInstanceOf
152
137
  */
153
- export const assertErrorInstanceOf = <T extends Error>(thing: unknown, constructable: Function & { new(...args: any[]): T }): T => {
154
- if (thing instanceof Error) {
155
- return assertInstanceOf(thing, constructable, thing);
156
- } else {
157
- // this separate branch prevents an unknown non-Error thing from being passed to the assertion as an AssertionFailed
158
- throw new Error(`assertErrorInstanceOf received non-Error argument of type "${
159
- typeof thing}" and string representation "${thing}"`);
160
- }
138
+ export const assertErrorInstanceOf = (thing, constructable) => {
139
+ if (thing instanceof Error) {
140
+ return assertInstanceOf(thing, constructable, thing);
141
+ }
142
+ else {
143
+ // this separate branch prevents an unknown non-Error thing from being passed to the assertion as an AssertionFailed
144
+ throw new Error(`assertErrorInstanceOf received non-Error argument of type "${typeof thing}" and string representation "${thing}"`);
145
+ }
161
146
  };
@@ -0,0 +1,5 @@
1
+ import { SSM } from '@aws-sdk/client-ssm';
2
+ /**
3
+ * A memoized instance of the AWS SSM client.
4
+ */
5
+ export declare const ssmService: () => SSM;
@@ -0,0 +1,6 @@
1
+ import { SSM } from '@aws-sdk/client-ssm';
2
+ import { once } from '..';
3
+ /**
4
+ * A memoized instance of the AWS SSM client.
5
+ */
6
+ export const ssmService = once(() => new SSM({ apiVersion: '2012-08-10' }));
@@ -0,0 +1,10 @@
1
+ import { ConfigValueProvider } from '.';
2
+ /**
3
+ * Returns a value from the AWS Parameter Store.
4
+ *
5
+ * @param parameterName the name of the parameter; can be a literal name (string) or can itself
6
+ * be accessed via another parameter by giving a configuration value provider.
7
+ * @example const someValue = resolveConfig(awsParameterConfig('some-parameter-name'));
8
+ * @returns the configuration value provider for the value
9
+ */
10
+ export declare const awsParameterConfig: (parameterName: ConfigValueProvider<string>) => ConfigValueProvider<string>;
@@ -0,0 +1,22 @@
1
+ import { GetParameterCommand } from '@aws-sdk/client-ssm';
2
+ import { assertDefined } from '../assertions';
3
+ import { ssmService } from '../aws/ssmService';
4
+ import { resolveConfigValue } from './resolveConfigValue';
5
+ /**
6
+ * Returns a value from the AWS Parameter Store.
7
+ *
8
+ * @param parameterName the name of the parameter; can be a literal name (string) or can itself
9
+ * be accessed via another parameter by giving a configuration value provider.
10
+ * @example const someValue = resolveConfig(awsParameterConfig('some-parameter-name'));
11
+ * @returns the configuration value provider for the value
12
+ */
13
+ export const awsParameterConfig = (parameterName) => {
14
+ return async () => {
15
+ const command = new GetParameterCommand({ Name: await resolveConfigValue(parameterName), WithDecryption: true });
16
+ // send() throws ParameterNotFound if the parameter is missing,
17
+ // so it's not clear what missing Parameter or Value mean
18
+ const response = await ssmService().send(command);
19
+ const parameter = assertDefined(response.Parameter, `aws GetParameter response missing Parameter key for ${parameterName}"`);
20
+ return assertDefined(parameter.Value, `aws GetParameter response missing Parameter.Value key for ${parameterName}"`);
21
+ };
22
+ };
@@ -0,0 +1,24 @@
1
+ import type { ConfigValueProvider } from '.';
2
+ /**
3
+ * A list of environment variables that were requested at build time. Used by webpack to
4
+ * capture build-time environment variables values.
5
+ */
6
+ export declare const ENV_BUILD_CONFIGS: string[];
7
+ /**
8
+ * Returns an environment variable from the process environment. Depending on the `type` in the
9
+ * call to get the variable, the variable's value may be what it was at build time, not at runtime.
10
+ * The return value is not the variable value itself, but rather a provider that has to be called
11
+ * to read the variable value (meaning, this is safe to call even if the variable doesn't exist,
12
+ * because someone else later needs to call the provider to get the value -- that call may explode,
13
+ * but this one won't).
14
+ *
15
+ * @param name The name of the environment variable to retrieve.
16
+ * @param type The mode for accessing the variable. Defaults to `'build'`, i.e. getting the
17
+ * variable as it was set at build time (webpack is connected here to make this possible). This
18
+ * argument can also be `'runtime'` in which case the value at build time is ignored and the
19
+ * variable is pulled live from `process.env`.
20
+ * @param [defaultValue] The default value to use if the variable is not found.
21
+ *
22
+ * @example const config = { configValue: envConfig('environment_variable_name') };
23
+ */
24
+ export declare const envConfig: (name: string, type?: "build" | "runtime", defaultValue?: ConfigValueProvider<string>) => ConfigValueProvider<string>;
@@ -0,0 +1,53 @@
1
+ import { resolveConfigValue } from './resolveConfigValue';
2
+ /**
3
+ * A list of environment variables that were requested at build time. Used by webpack to
4
+ * capture build-time environment variables values.
5
+ */
6
+ export const ENV_BUILD_CONFIGS = [];
7
+ /**
8
+ * Returns an environment variable from the process environment. Depending on the `type` in the
9
+ * call to get the variable, the variable's value may be what it was at build time, not at runtime.
10
+ * The return value is not the variable value itself, but rather a provider that has to be called
11
+ * to read the variable value (meaning, this is safe to call even if the variable doesn't exist,
12
+ * because someone else later needs to call the provider to get the value -- that call may explode,
13
+ * but this one won't).
14
+ *
15
+ * @param name The name of the environment variable to retrieve.
16
+ * @param type The mode for accessing the variable. Defaults to `'build'`, i.e. getting the
17
+ * variable as it was set at build time (webpack is connected here to make this possible). This
18
+ * argument can also be `'runtime'` in which case the value at build time is ignored and the
19
+ * variable is pulled live from `process.env`.
20
+ * @param [defaultValue] The default value to use if the variable is not found.
21
+ *
22
+ * @example const config = { configValue: envConfig('environment_variable_name') };
23
+ */
24
+ export const envConfig = (name, type, defaultValue) => {
25
+ // this doesn't use a default parameter value because of a:
26
+ // "Regular parameters should not come after default parameters."
27
+ // error that occurs when the defaultValue optional default of `undefined`
28
+ // gets optimized out, causing a problem in cloudfront functions.
29
+ type !== null && type !== void 0 ? type : (type = 'build');
30
+ if (type === 'build') {
31
+ ENV_BUILD_CONFIGS.push(name);
32
+ }
33
+ return () => {
34
+ /*global __PROCESS_ENV*/
35
+ // @ts-ignore - hack to get around the way webpack/define works
36
+ // - https://github.com/webpack/webpack/issues/14800
37
+ // - https://github.com/webpack/webpack/issues/5392
38
+ // also, spread operator not supported in cloudfront functions
39
+ const envs = Object.assign({}, process.env, typeof __PROCESS_ENV !== 'undefined' ? __PROCESS_ENV : {});
40
+ const value = envs[name];
41
+ if (value === undefined) {
42
+ if (defaultValue === undefined) {
43
+ throw new Error(`expected to find environment variable with name: ${name}`);
44
+ }
45
+ else {
46
+ return resolveConfigValue(defaultValue);
47
+ }
48
+ }
49
+ else {
50
+ return value;
51
+ }
52
+ };
53
+ };
@@ -0,0 +1,48 @@
1
+ /**
2
+ * A simple type alias for a string that represents a configuration value. Currently only string values are supported to maintain compatibility with environment variables, but this type is future proofing against allowing other types like `number` as possible config values.
3
+ */
4
+ export type ConfigValue = string;
5
+ /**
6
+ * A configuration object that may contain nested configuration objects or configuration values.
7
+ */
8
+ export type Config = {
9
+ [key: string]: Config | ConfigValue;
10
+ };
11
+ /**
12
+ * Either a function that returns a `ConfigValue` or a `Promise` that resolves to a `ConfigValue`,
13
+ * or just a `ConfigValue`.
14
+ */
15
+ export type ConfigValueProvider<V extends ConfigValue = ConfigValue> = (() => Promise<V> | V) | V;
16
+ /**
17
+ * A configuration object that may contain nested configuration objects or configuration value providers.
18
+ */
19
+ export type ConfigProvider = {
20
+ [key: string]: ConfigProvider | ConfigValueProvider;
21
+ };
22
+ /**
23
+ * Conditional type that resolves to the type of configuration object for the given configuration
24
+ * provider. Also resolves to a config value type if the given type is a config value.
25
+ */
26
+ export type ConfigForConfigProvider<T> = T extends ConfigValue ? T : T extends ConfigProvider ? {
27
+ [key in keyof T]: ConfigForConfigProvider<T[key]>;
28
+ } : T extends ConfigValueProvider<infer R> ? R : never;
29
+ /**
30
+ * Conditional type that resolves to the `ConfigProvider` type for the given configuration
31
+ * type (`ConfigValue` or `Config`). The resulting type is either a `ConfigValueProvider` or
32
+ * a `ConfigProvider`.
33
+ */
34
+ export type ConfigProviderForConfig<T> = T extends ConfigValue ? ConfigValueProvider<T> : T extends Config ? {
35
+ [key in keyof T]: ConfigProviderForConfig<T[key]>;
36
+ } : never;
37
+ export * from './resolveConfigValue';
38
+ /**
39
+ * stub, mostly for testing. sometimes it helps please typescript to use this if you have
40
+ * two configs you want to have the same type but one is a fixed string and one is a complicated provider
41
+ *
42
+ * @example const config = { configValue: stubConfig('just-a-string') };
43
+ */
44
+ export declare const stubConfig: <V extends ConfigValue>(configValue: V) => ConfigValueProvider<V>;
45
+ export * from './envConfig';
46
+ export * from './replaceConfig';
47
+ export * from './awsParameterConfig';
48
+ export * from './lambdaParameterConfig';
@@ -0,0 +1,17 @@
1
+ export * from './resolveConfigValue';
2
+ /*
3
+ * ===========
4
+ * re-usable config providers
5
+ * ===========
6
+ * */
7
+ /**
8
+ * stub, mostly for testing. sometimes it helps please typescript to use this if you have
9
+ * two configs you want to have the same type but one is a fixed string and one is a complicated provider
10
+ *
11
+ * @example const config = { configValue: stubConfig('just-a-string') };
12
+ */
13
+ export const stubConfig = (configValue) => configValue;
14
+ export * from './envConfig';
15
+ export * from './replaceConfig';
16
+ export * from './awsParameterConfig';
17
+ export * from './lambdaParameterConfig';
@@ -0,0 +1,12 @@
1
+ import { ConfigValueProvider } from '.';
2
+ /**
3
+ * Returns a value from the AWS Parameter Store. Can only be used during in AWS Lambda, and
4
+ * requires that the AWS Parameters and Secrets Lambda Extension Layer be included in the Lambda.
5
+ * This extension has built-in caching for requested parameters.
6
+ *
7
+ * @param parameterName the name of the parameter; can be a literal name (string) or can itself
8
+ * be accessed via another parameter by giving a configuration value provider.
9
+ * @example const someValue = resolveConfig(lambdaParameterConfig('some-parameter-name'));
10
+ * @returns the configuration value provider for the value
11
+ */
12
+ export declare const lambdaParameterConfig: (parameterName: ConfigValueProvider<string>) => ConfigValueProvider<string>;
@@ -0,0 +1,38 @@
1
+ import fetch from 'node-fetch';
2
+ import { assertDefined } from '../assertions';
3
+ import { retryWithDelay } from '../misc/helpers';
4
+ import { envConfig } from './envConfig';
5
+ import { resolveConfigValue } from '.';
6
+ const lambdaExtensionUrl = 'http://localhost:2773';
7
+ let lambdaExtensionReadyPromise;
8
+ /**
9
+ * Returns a value from the AWS Parameter Store. Can only be used during in AWS Lambda, and
10
+ * requires that the AWS Parameters and Secrets Lambda Extension Layer be included in the Lambda.
11
+ * This extension has built-in caching for requested parameters.
12
+ *
13
+ * @param parameterName the name of the parameter; can be a literal name (string) or can itself
14
+ * be accessed via another parameter by giving a configuration value provider.
15
+ * @example const someValue = resolveConfig(lambdaParameterConfig('some-parameter-name'));
16
+ * @returns the configuration value provider for the value
17
+ */
18
+ export const lambdaParameterConfig = (parameterName) => async () => {
19
+ const token = await resolveConfigValue(envConfig('AWS_SESSION_TOKEN', 'runtime'));
20
+ const name = await resolveConfigValue(parameterName);
21
+ if (!lambdaExtensionReadyPromise) {
22
+ // This request will return 400 Bad Request,
23
+ // but we only care that it'll block until the extension is ready
24
+ lambdaExtensionReadyPromise = retryWithDelay(() => fetch(lambdaExtensionUrl));
25
+ }
26
+ await lambdaExtensionReadyPromise;
27
+ const resp = await retryWithDelay(() => fetch(
28
+ // Port 2773 is the default port for the extension
29
+ `${lambdaExtensionUrl}/systemsmanager/parameters/get?name=${name}&withDecryption=true`, { headers: { 'X-Aws-Parameters-Secrets-Token': token } }));
30
+ if (resp.ok) {
31
+ const response = await resp.json();
32
+ const parameter = assertDefined(response.Parameter, `aws GetParameter response missing Parameter key for ${name}"`);
33
+ return assertDefined(parameter.Value, `aws GetParameter response missing Parameter.Value key for ${name}"`);
34
+ }
35
+ else {
36
+ throw new Error(`HTTP Error Response ${resp.status} ${resp.statusText} while fetching parameter ${name}`);
37
+ }
38
+ };
@@ -0,0 +1,14 @@
1
+ import { ConfigValueProvider } from '.';
2
+ /**
3
+ * Substitutes configuration values into a provided string.
4
+ * Performs a string substitution using configuration values
5
+ * @param base The string into which substitutions will be made; contains tokens that are
6
+ * referenced in the `replacements` argument.
7
+ * @param replacements A map of tokens to configuration value providers. The providers are
8
+ * resolved and the values are substituted into the `base` string, replacing the tokens.
9
+ * @example replaceConfig('https://[host]', { '[host]': envConfig('HOST') })
10
+ * @returns the string after substitution is complete
11
+ */
12
+ export declare const replaceConfig: (base: ConfigValueProvider<string>, replacements: {
13
+ [token: string]: ConfigValueProvider<string>;
14
+ }) => ConfigValueProvider<string>;
@@ -1,6 +1,4 @@
1
1
  import { resolveConfigValue } from './resolveConfigValue';
2
- import { ConfigValueProvider } from '.';
3
-
4
2
  /**
5
3
  * Substitutes configuration values into a provided string.
6
4
  * Performs a string substitution using configuration values
@@ -11,18 +9,10 @@ import { ConfigValueProvider } from '.';
11
9
  * @example replaceConfig('https://[host]', { '[host]': envConfig('HOST') })
12
10
  * @returns the string after substitution is complete
13
11
  */
14
- export const replaceConfig = (
15
- base: ConfigValueProvider<string>,
16
- replacements: {[token: string]: ConfigValueProvider<string>}
17
- ): ConfigValueProvider<string> => {
18
-
19
- return async() => {
20
- const resolved = await Promise.all(Object.entries(replacements)
21
- .map(async([token, replacement]) => [token, await resolveConfigValue(replacement)] as const)
22
- );
23
-
24
- return resolved.reduce(
25
- (result, [token, replacement]) => result.replace(token, replacement)
26
- , await resolveConfigValue(base));
27
- };
12
+ export const replaceConfig = (base, replacements) => {
13
+ return async () => {
14
+ const resolved = await Promise.all(Object.entries(replacements)
15
+ .map(async ([token, replacement]) => [token, await resolveConfigValue(replacement)]));
16
+ return resolved.reduce((result, [token, replacement]) => result.replace(token, replacement), await resolveConfigValue(base));
17
+ };
28
18
  };
@@ -0,0 +1,5 @@
1
+ import type { ConfigValue, ConfigValueProvider } from '.';
2
+ /**
3
+ * resolves a config value into a string, to be used inside of things that are provided configurations
4
+ */
5
+ export declare const resolveConfigValue: <V extends ConfigValue>(provider: ConfigValueProvider<V>) => Promise<V>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * resolves a config value into a string, to be used inside of things that are provided configurations
3
+ */
4
+ export const resolveConfigValue = async (provider) => {
5
+ return typeof provider === 'function'
6
+ ? await provider()
7
+ : provider;
8
+ };