@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
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.stubConfig = void 0;
18
+ __exportStar(require("./resolveConfigValue"), exports);
19
+ /*
20
+ * ===========
21
+ * re-usable config providers
22
+ * ===========
23
+ * */
24
+ /**
25
+ * stub, mostly for testing. sometimes it helps please typescript to use this if you have
26
+ * two configs you want to have the same type but one is a fixed string and one is a complicated provider
27
+ *
28
+ * @example const config = { configValue: stubConfig('just-a-string') };
29
+ */
30
+ const stubConfig = (configValue) => configValue;
31
+ exports.stubConfig = stubConfig;
32
+ __exportStar(require("./envConfig"), exports);
33
+ __exportStar(require("./replaceConfig"), exports);
34
+ __exportStar(require("./awsParameterConfig"), exports);
35
+ __exportStar(require("./lambdaParameterConfig"), exports);
@@ -0,0 +1,12 @@
1
+ import { ConfigValueProvider } from '.';
2
+ /**
3
+ * Returns a value from the AWS Parameter Store. Can only be used during in AWS Lambda, and
4
+ * requires that the AWS Parameters and Secrets Lambda Extension Layer be included in the Lambda.
5
+ * This extension has built-in caching for requested parameters.
6
+ *
7
+ * @param parameterName the name of the parameter; can be a literal name (string) or can itself
8
+ * be accessed via another parameter by giving a configuration value provider.
9
+ * @example const someValue = resolveConfig(lambdaParameterConfig('some-parameter-name'));
10
+ * @returns the configuration value provider for the value
11
+ */
12
+ export declare const lambdaParameterConfig: (parameterName: ConfigValueProvider<string>) => ConfigValueProvider<string>;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.lambdaParameterConfig = void 0;
7
+ const node_fetch_1 = __importDefault(require("node-fetch"));
8
+ const assertions_1 = require("../assertions");
9
+ const helpers_1 = require("../misc/helpers");
10
+ const envConfig_1 = require("./envConfig");
11
+ const _1 = require(".");
12
+ const lambdaExtensionUrl = 'http://localhost:2773';
13
+ let lambdaExtensionReadyPromise;
14
+ /**
15
+ * Returns a value from the AWS Parameter Store. Can only be used during in AWS Lambda, and
16
+ * requires that the AWS Parameters and Secrets Lambda Extension Layer be included in the Lambda.
17
+ * This extension has built-in caching for requested parameters.
18
+ *
19
+ * @param parameterName the name of the parameter; can be a literal name (string) or can itself
20
+ * be accessed via another parameter by giving a configuration value provider.
21
+ * @example const someValue = resolveConfig(lambdaParameterConfig('some-parameter-name'));
22
+ * @returns the configuration value provider for the value
23
+ */
24
+ const lambdaParameterConfig = (parameterName) => async () => {
25
+ const token = await (0, _1.resolveConfigValue)((0, envConfig_1.envConfig)('AWS_SESSION_TOKEN', 'runtime'));
26
+ const name = await (0, _1.resolveConfigValue)(parameterName);
27
+ if (!lambdaExtensionReadyPromise) {
28
+ // This request will return 400 Bad Request,
29
+ // but we only care that it'll block until the extension is ready
30
+ lambdaExtensionReadyPromise = (0, helpers_1.retryWithDelay)(() => (0, node_fetch_1.default)(lambdaExtensionUrl));
31
+ }
32
+ await lambdaExtensionReadyPromise;
33
+ const resp = await (0, helpers_1.retryWithDelay)(() => (0, node_fetch_1.default)(
34
+ // Port 2773 is the default port for the extension
35
+ `${lambdaExtensionUrl}/systemsmanager/parameters/get?name=${name}&withDecryption=true`, { headers: { 'X-Aws-Parameters-Secrets-Token': token } }));
36
+ if (resp.ok) {
37
+ const response = await resp.json();
38
+ const parameter = (0, assertions_1.assertDefined)(response.Parameter, `aws GetParameter response missing Parameter key for ${name}"`);
39
+ return (0, assertions_1.assertDefined)(parameter.Value, `aws GetParameter response missing Parameter.Value key for ${name}"`);
40
+ }
41
+ else {
42
+ throw new Error(`HTTP Error Response ${resp.status} ${resp.statusText} while fetching parameter ${name}`);
43
+ }
44
+ };
45
+ exports.lambdaParameterConfig = lambdaParameterConfig;
@@ -0,0 +1,14 @@
1
+ import { ConfigValueProvider } from '.';
2
+ /**
3
+ * Substitutes configuration values into a provided string.
4
+ * Performs a string substitution using configuration values
5
+ * @param base The string into which substitutions will be made; contains tokens that are
6
+ * referenced in the `replacements` argument.
7
+ * @param replacements A map of tokens to configuration value providers. The providers are
8
+ * resolved and the values are substituted into the `base` string, replacing the tokens.
9
+ * @example replaceConfig('https://[host]', { '[host]': envConfig('HOST') })
10
+ * @returns the string after substitution is complete
11
+ */
12
+ export declare const replaceConfig: (base: ConfigValueProvider<string>, replacements: {
13
+ [token: string]: ConfigValueProvider<string>;
14
+ }) => ConfigValueProvider<string>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.replaceConfig = void 0;
4
+ const resolveConfigValue_1 = require("./resolveConfigValue");
5
+ /**
6
+ * Substitutes configuration values into a provided string.
7
+ * Performs a string substitution using configuration values
8
+ * @param base The string into which substitutions will be made; contains tokens that are
9
+ * referenced in the `replacements` argument.
10
+ * @param replacements A map of tokens to configuration value providers. The providers are
11
+ * resolved and the values are substituted into the `base` string, replacing the tokens.
12
+ * @example replaceConfig('https://[host]', { '[host]': envConfig('HOST') })
13
+ * @returns the string after substitution is complete
14
+ */
15
+ const replaceConfig = (base, replacements) => {
16
+ return async () => {
17
+ const resolved = await Promise.all(Object.entries(replacements)
18
+ .map(async ([token, replacement]) => [token, await (0, resolveConfigValue_1.resolveConfigValue)(replacement)]));
19
+ return resolved.reduce((result, [token, replacement]) => result.replace(token, replacement), await (0, resolveConfigValue_1.resolveConfigValue)(base));
20
+ };
21
+ };
22
+ exports.replaceConfig = replaceConfig;
@@ -0,0 +1,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,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveConfigValue = void 0;
4
+ /**
5
+ * resolves a config value into a string, to be used inside of things that are provided configurations
6
+ */
7
+ const resolveConfigValue = async (provider) => {
8
+ return typeof provider === 'function'
9
+ ? await provider()
10
+ : provider;
11
+ };
12
+ exports.resolveConfigValue = resolveConfigValue;
@@ -0,0 +1,88 @@
1
+ import type { JsonCompatibleStruct } from '../routing';
2
+ /**
3
+ * Returns true if the error is defined in this library
4
+ */
5
+ export declare const isAppError: (e: any) => e is Error & {
6
+ constructor: {
7
+ TYPE: string;
8
+ };
9
+ };
10
+ /**
11
+ * Invalid request error
12
+ *
13
+ * `InvalidRequestError.matches(error)` is a reliable way to check if an error is an
14
+ * `InvalidRequestError`; `instanceof` checks may not work if code is split into multiple bundles
15
+ */
16
+ export declare class InvalidRequestError extends Error {
17
+ static readonly TYPE = "InvalidRequestError";
18
+ static matches: (e: any) => e is typeof InvalidRequestError;
19
+ constructor(message?: string);
20
+ }
21
+ /**
22
+ * Validation Error
23
+ *
24
+ * `ValidationError.matches(error)` is a reliable way to check if an error is an
25
+ * `ValidationError`; `instanceof` checks may not work if code is split into multiple bundles
26
+ */
27
+ export declare class ValidationError extends Error {
28
+ static readonly TYPE = "ValidationError";
29
+ static matches: (e: any) => e is typeof ValidationError;
30
+ private data;
31
+ constructor(data: JsonCompatibleStruct);
32
+ getData(): JsonCompatibleStruct;
33
+ }
34
+ /**
35
+ * Unauthorized error
36
+ *
37
+ * `UnauthorizedError.matches(error)` is a reliable way to check if an error is an
38
+ * `UnauthorizedError`; `instanceof` checks may not work if code is split into multiple bundles
39
+ */
40
+ export declare class UnauthorizedError extends Error {
41
+ static readonly TYPE = "UnauthorizedError";
42
+ static matches: (e: any) => e is typeof UnauthorizedError;
43
+ constructor(message?: string);
44
+ }
45
+ /**
46
+ * Forbidden error
47
+ *
48
+ * `ForbiddenError.matches(error)` is a reliable way to check if an error is a
49
+ * `ForbiddenError`; `instanceof` checks may not work if code is split into multiple bundles
50
+ */
51
+ export declare class ForbiddenError extends Error {
52
+ static readonly TYPE = "ForbiddenError";
53
+ static matches: (e: any) => e is typeof ForbiddenError;
54
+ constructor(message?: string);
55
+ }
56
+ /**
57
+ * Not found error
58
+ *
59
+ * `NotFoundError.matches(error)` is a reliable way to check if an error is a
60
+ * `NotFoundError`; `instanceof` checks may not work if code is split into multiple bundles
61
+ */
62
+ export declare class NotFoundError extends Error {
63
+ static readonly TYPE = "NotFoundError";
64
+ static matches: (e: any) => e is typeof NotFoundError;
65
+ constructor(message?: string);
66
+ }
67
+ /**
68
+ * Session expired error
69
+ *
70
+ * `SessionExpiredError.matches(error)` is a reliable way to check if an error is a
71
+ * `SessionExpiredError`; `instanceof` checks may not work if code is split into multiple bundles
72
+ */
73
+ export declare class SessionExpiredError extends Error {
74
+ static readonly TYPE = "SessionExpiredError";
75
+ static matches: (e: any) => e is typeof SessionExpiredError;
76
+ constructor(message?: string);
77
+ }
78
+ /**
79
+ * Conflict error
80
+ *
81
+ * `ConflictError.matches(error)` is a reliable way to check if an error is a
82
+ * `ConflictError`; `instanceof` checks may not work if code is split into multiple bundles
83
+ */
84
+ export declare class ConflictError extends Error {
85
+ static readonly TYPE = "ConflictError";
86
+ static matches: (e: any) => e is typeof ConflictError;
87
+ constructor(message?: string);
88
+ }
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConflictError = exports.SessionExpiredError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.ValidationError = exports.InvalidRequestError = exports.isAppError = void 0;
4
+ /*
5
+ * if code is split into multiple bundles, sometimes each bundle
6
+ * will get its own definition of this module and then instanceof checks
7
+ * are unreliable, this provides a way to reliably check the error types
8
+ *
9
+ * eg this will always work:
10
+ * InvalidRequestError.matches(error);
11
+ *
12
+ * eg this might not work if you have code splitting:
13
+ * error instanceof InvalidRequestError
14
+ *
15
+ */
16
+ const errorIsType = (t) => (e) => e instanceof Error
17
+ && e.constructor.TYPE === t.TYPE;
18
+ /**
19
+ * Returns true if the error is defined in this library
20
+ */
21
+ const isAppError = (e) => e instanceof Error
22
+ && typeof e.constructor.TYPE === 'string';
23
+ exports.isAppError = isAppError;
24
+ /**
25
+ * Invalid request error
26
+ *
27
+ * `InvalidRequestError.matches(error)` is a reliable way to check if an error is an
28
+ * `InvalidRequestError`; `instanceof` checks may not work if code is split into multiple bundles
29
+ */
30
+ class InvalidRequestError extends Error {
31
+ constructor(message) {
32
+ super(message || InvalidRequestError.TYPE);
33
+ }
34
+ }
35
+ exports.InvalidRequestError = InvalidRequestError;
36
+ InvalidRequestError.TYPE = 'InvalidRequestError';
37
+ InvalidRequestError.matches = errorIsType(InvalidRequestError);
38
+ /**
39
+ * Validation Error
40
+ *
41
+ * `ValidationError.matches(error)` is a reliable way to check if an error is an
42
+ * `ValidationError`; `instanceof` checks may not work if code is split into multiple bundles
43
+ */
44
+ class ValidationError extends Error {
45
+ constructor(data) {
46
+ super(InvalidRequestError.TYPE);
47
+ this.data = data;
48
+ }
49
+ getData() { return this.data; }
50
+ }
51
+ exports.ValidationError = ValidationError;
52
+ ValidationError.TYPE = 'ValidationError';
53
+ ValidationError.matches = errorIsType(ValidationError);
54
+ /**
55
+ * Unauthorized error
56
+ *
57
+ * `UnauthorizedError.matches(error)` is a reliable way to check if an error is an
58
+ * `UnauthorizedError`; `instanceof` checks may not work if code is split into multiple bundles
59
+ */
60
+ class UnauthorizedError extends Error {
61
+ constructor(message) {
62
+ super(message || UnauthorizedError.TYPE);
63
+ }
64
+ }
65
+ exports.UnauthorizedError = UnauthorizedError;
66
+ UnauthorizedError.TYPE = 'UnauthorizedError';
67
+ UnauthorizedError.matches = errorIsType(UnauthorizedError);
68
+ /**
69
+ * Forbidden error
70
+ *
71
+ * `ForbiddenError.matches(error)` is a reliable way to check if an error is a
72
+ * `ForbiddenError`; `instanceof` checks may not work if code is split into multiple bundles
73
+ */
74
+ class ForbiddenError extends Error {
75
+ constructor(message) {
76
+ super(message || ForbiddenError.TYPE);
77
+ }
78
+ }
79
+ exports.ForbiddenError = ForbiddenError;
80
+ ForbiddenError.TYPE = 'ForbiddenError';
81
+ ForbiddenError.matches = errorIsType(ForbiddenError);
82
+ /**
83
+ * Not found error
84
+ *
85
+ * `NotFoundError.matches(error)` is a reliable way to check if an error is a
86
+ * `NotFoundError`; `instanceof` checks may not work if code is split into multiple bundles
87
+ */
88
+ class NotFoundError extends Error {
89
+ constructor(message) {
90
+ super(message || NotFoundError.TYPE);
91
+ }
92
+ }
93
+ exports.NotFoundError = NotFoundError;
94
+ NotFoundError.TYPE = 'NotFoundError';
95
+ NotFoundError.matches = errorIsType(NotFoundError);
96
+ /**
97
+ * Session expired error
98
+ *
99
+ * `SessionExpiredError.matches(error)` is a reliable way to check if an error is a
100
+ * `SessionExpiredError`; `instanceof` checks may not work if code is split into multiple bundles
101
+ */
102
+ class SessionExpiredError extends Error {
103
+ constructor(message) {
104
+ super(message || SessionExpiredError.TYPE);
105
+ }
106
+ }
107
+ exports.SessionExpiredError = SessionExpiredError;
108
+ SessionExpiredError.TYPE = 'SessionExpiredError';
109
+ SessionExpiredError.matches = errorIsType(SessionExpiredError);
110
+ /**
111
+ * Conflict error
112
+ *
113
+ * `ConflictError.matches(error)` is a reliable way to check if an error is a
114
+ * `ConflictError`; `instanceof` checks may not work if code is split into multiple bundles
115
+ */
116
+ class ConflictError extends Error {
117
+ constructor(message) {
118
+ super(message || ConflictError.TYPE);
119
+ }
120
+ }
121
+ exports.ConflictError = ConflictError;
122
+ ConflictError.TYPE = 'ConflictError';
123
+ ConflictError.matches = errorIsType(ConflictError);
@@ -0,0 +1,8 @@
1
+ import { RetryOptions } from '../misc/helpers';
2
+ import { GenericFetch } from '.';
3
+ interface Options extends RetryOptions {
4
+ status?: number[];
5
+ timeout?: number;
6
+ }
7
+ export declare const fetchStatusRetry: (base: GenericFetch, options: Options) => GenericFetch;
8
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchStatusRetry = void 0;
4
+ const helpers_1 = require("../misc/helpers");
5
+ const fetchStatusRetry = (base, options) => {
6
+ return (...params) => (0, helpers_1.retryWithDelay)(() => {
7
+ const fetchPromise = base(...params).then(r => {
8
+ var _a;
9
+ if ((_a = options.status) === null || _a === void 0 ? void 0 : _a.includes(r.status)) {
10
+ return r.text().then(text => {
11
+ throw new Error(`fetch failed ${params[0]} -- ${r.status}: ${text}`);
12
+ });
13
+ }
14
+ return r;
15
+ });
16
+ if (options.timeout) {
17
+ const timeoutPromise = new Promise((_, reject) => {
18
+ setTimeout(() => {
19
+ reject(new Error(`fetch timeout after ${options.timeout}ms: ${params[0]}`));
20
+ }, options.timeout);
21
+ });
22
+ return Promise.race([fetchPromise, timeoutPromise]);
23
+ }
24
+ return fetchPromise;
25
+ }, options);
26
+ };
27
+ exports.fetchStatusRetry = fetchStatusRetry;
@@ -0,0 +1,64 @@
1
+ import { METHOD } from '../routing';
2
+ export declare enum FetchStateType {
3
+ SUCCESS = "success",
4
+ ERROR = "error",
5
+ LOADING = "loading",
6
+ IDLE = "idle"
7
+ }
8
+ export type FetchState<D, E> = FetchStateLoading<D> | FetchStateError<D, E> | FetchStateSuccess<D> | FetchStateIdle;
9
+ type FetchStateLoading<D> = {
10
+ type: FetchStateType.LOADING;
11
+ data?: D;
12
+ };
13
+ type FetchStateError<D, E> = {
14
+ type: FetchStateType.ERROR;
15
+ data?: D;
16
+ error: E;
17
+ };
18
+ type FetchStateSuccess<D> = {
19
+ type: FetchStateType.SUCCESS;
20
+ data: D;
21
+ };
22
+ type FetchStateIdle = {
23
+ type: FetchStateType.IDLE;
24
+ };
25
+ export declare const fetchLoading: <D, E>(previous?: FetchState<D, E>) => FetchStateLoading<D>;
26
+ export declare const fetchError: <D, E>(error: E, previous?: FetchState<D, E>) => FetchStateError<D, E>;
27
+ export declare const fetchSuccess: <D>(data: D) => FetchStateSuccess<D>;
28
+ export declare const fetchIdle: () => FetchStateIdle;
29
+ export declare const stateHasData: <D, E>(state: {
30
+ type: FetchStateType;
31
+ data?: D;
32
+ error?: E;
33
+ }) => state is {
34
+ type: FetchStateType;
35
+ data: D;
36
+ };
37
+ export declare const stateHasError: <D, E>(state: {
38
+ type: FetchStateType;
39
+ data?: D;
40
+ error?: E;
41
+ }) => state is {
42
+ type: FetchStateType;
43
+ error: E;
44
+ };
45
+ export type FetchConfig = {
46
+ credentials?: 'include' | 'omit' | 'same-origin';
47
+ method?: METHOD;
48
+ body?: string;
49
+ headers?: {
50
+ [key: string]: string;
51
+ };
52
+ };
53
+ type Headers = {
54
+ get: (name: string) => string | null;
55
+ };
56
+ export type Response = {
57
+ status: number;
58
+ headers: Headers;
59
+ json: () => Promise<any>;
60
+ text: () => Promise<string>;
61
+ };
62
+ export type GenericFetch<C extends FetchConfig = FetchConfig, R extends Response = Response> = (url: string, fetchConfig?: C) => Promise<R>;
63
+ export type ConfigForFetch<F> = F extends GenericFetch<infer C, any> ? C : never;
64
+ export {};
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stateHasError = exports.stateHasData = exports.fetchIdle = exports.fetchSuccess = exports.fetchError = exports.fetchLoading = exports.FetchStateType = void 0;
4
+ /*
5
+ * these are just helpers for formatting responses, they don't actually do any loading. especially in UI development they
6
+ * help with continuity over loading, reloading, saving, and errors. this is pretty nice in typescript because you have to deal
7
+ * with the possibility that the result state is in a loading or error state. if you avoid dealing with those states you need
8
+ * to write very clear code to ignore them, which easily presents missing functionality like errors that are not being messaged
9
+ * to the user.
10
+ * */
11
+ var FetchStateType;
12
+ (function (FetchStateType) {
13
+ FetchStateType["SUCCESS"] = "success";
14
+ FetchStateType["ERROR"] = "error";
15
+ FetchStateType["LOADING"] = "loading";
16
+ FetchStateType["IDLE"] = "idle";
17
+ })(FetchStateType || (exports.FetchStateType = FetchStateType = {}));
18
+ /*
19
+ * keeps existing data but sets the new status
20
+ *
21
+ * const state = fetchLoading(previousState)
22
+ * */
23
+ const fetchLoading = (previous) => ({ type: FetchStateType.LOADING, ...(previous && 'data' in previous ? { data: previous.data } : {}) });
24
+ exports.fetchLoading = fetchLoading;
25
+ /*
26
+ * keeps existing data but sets the new status and error value
27
+ *
28
+ * const state = fetchError(error, previousState)
29
+ * */
30
+ const fetchError = (error, previous) => ({ ...previous, type: FetchStateType.ERROR, error });
31
+ exports.fetchError = fetchError;
32
+ /*
33
+ * formats data with success type
34
+ *
35
+ * const state = fetchSuccess(newData)
36
+ * */
37
+ const fetchSuccess = (data) => ({ type: FetchStateType.SUCCESS, data });
38
+ exports.fetchSuccess = fetchSuccess;
39
+ /*
40
+ * formats data with idle type
41
+ *
42
+ * const state = fetchIdle(newData)
43
+ * */
44
+ const fetchIdle = () => ({ type: FetchStateType.IDLE });
45
+ exports.fetchIdle = fetchIdle;
46
+ /*
47
+ * guard for checking if the state has result data, it might be true for any state type.
48
+ * */
49
+ const stateHasData = (state) => 'data' in state;
50
+ exports.stateHasData = stateHasData;
51
+ /*
52
+ * guard for checking if the state has an error, it might be true for error or loading states.
53
+ * */
54
+ const stateHasError = (state) => 'error' in state;
55
+ exports.stateHasError = stateHasError;
@@ -5,8 +5,7 @@
5
5
  *
6
6
  * `const result = (array as Array<string | undefined>).filter(isDefined);`
7
7
  */
8
- export const isDefined = <X>(x: X): x is Exclude<X, undefined> => x !== undefined;
9
-
8
+ export declare const isDefined: <X>(x: X) => x is Exclude<X, undefined>;
10
9
  /**
11
10
  * checks if a thing is not null. while often easy to do with a simple if statement,
12
11
  * in certain situations the guard is required and its nice to have one pre-defined.
@@ -14,8 +13,7 @@ export const isDefined = <X>(x: X): x is Exclude<X, undefined> => x !== undefine
14
13
  *
15
14
  * `const result = (array as Array<string | null>).filter(isNotNull);`
16
15
  */
17
- export const isNotNull = <X>(x: X): x is Exclude<X, null> => x !== null;
18
-
16
+ export declare const isNotNull: <X>(x: X) => x is Exclude<X, null>;
19
17
  /**
20
18
  * checks if a thing is a number. while often easy to do with a simple if statement, in certain
21
19
  * situations the guard is required and its nice to have one pre-defined. E.g. in the following
@@ -23,19 +21,18 @@ export const isNotNull = <X>(x: X): x is Exclude<X, null> => x !== null;
23
21
  *
24
22
  * `const result = (array as Array<number | undefined>).filter(isNumber);`
25
23
  */
26
- export const isNumber = (x: any): x is number => typeof x === 'number';
27
-
24
+ export declare const isNumber: (x: any) => x is number;
28
25
  /**
29
26
  * a guard for plain old javascript objects that are not based on some other prototype,
30
27
  * for example making them safe to JSON stringify and stuff
31
28
  */
32
- export const isPlainObject = (thing: any): thing is {[key: string]: any} =>
33
- thing instanceof Object && thing.__proto__.constructor.name === 'Object';
34
-
29
+ export declare const isPlainObject: (thing: any) => thing is {
30
+ [key: string]: any;
31
+ };
35
32
  /**
36
33
  * if the first thing is defined it uses it, otherwise it returns the second thing. this isn't
37
34
  * really a guard its just a way to provide a default value without creating a coverage branch.
38
35
  *
39
36
  * @example const valueWithDefault = ifDefined(thing, 'default value')
40
37
  */
41
- export const ifDefined = <X, D>(x: X, d: D) => isDefined(x) ? x : d;
38
+ export declare const ifDefined: <X, D>(x: X, d: D) => D | Exclude<X, undefined>;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ifDefined = exports.isPlainObject = exports.isNumber = exports.isNotNull = exports.isDefined = void 0;
4
+ /**
5
+ * checks if a thing is defined. while often easy to do with a simple if statement, in certain
6
+ * situations the guard is required and its nice to have one pre-defined. E.g. in the following
7
+ * example, the result is `Array<string>`.
8
+ *
9
+ * `const result = (array as Array<string | undefined>).filter(isDefined);`
10
+ */
11
+ const isDefined = (x) => x !== undefined;
12
+ exports.isDefined = isDefined;
13
+ /**
14
+ * checks if a thing is not null. while often easy to do with a simple if statement,
15
+ * in certain situations the guard is required and its nice to have one pre-defined.
16
+ * E.g. in the following example, the result is `Array<string>`.
17
+ *
18
+ * `const result = (array as Array<string | null>).filter(isNotNull);`
19
+ */
20
+ const isNotNull = (x) => x !== null;
21
+ exports.isNotNull = isNotNull;
22
+ /**
23
+ * checks if a thing is a number. while often easy to do with a simple if statement, in certain
24
+ * situations the guard is required and its nice to have one pre-defined. E.g. in the following
25
+ * example, the result is `Array<number>`.
26
+ *
27
+ * `const result = (array as Array<number | undefined>).filter(isNumber);`
28
+ */
29
+ const isNumber = (x) => typeof x === 'number';
30
+ exports.isNumber = isNumber;
31
+ /**
32
+ * a guard for plain old javascript objects that are not based on some other prototype,
33
+ * for example making them safe to JSON stringify and stuff
34
+ */
35
+ const isPlainObject = (thing) => thing instanceof Object && thing.__proto__.constructor.name === 'Object';
36
+ exports.isPlainObject = isPlainObject;
37
+ /**
38
+ * if the first thing is defined it uses it, otherwise it returns the second thing. this isn't
39
+ * really a guard its just a way to provide a default value without creating a coverage branch.
40
+ *
41
+ * @example const valueWithDefault = ifDefined(thing, 'default value')
42
+ */
43
+ const ifDefined = (x, d) => (0, exports.isDefined)(x) ? x : d;
44
+ exports.ifDefined = ifDefined;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./misc/partitionSequence"), exports);
18
+ __exportStar(require("./misc/helpers"), exports);
19
+ __exportStar(require("./misc/merge"), exports);
20
+ __exportStar(require("./misc/hashValue"), exports);
@@ -0,0 +1,24 @@
1
+ import { ForbiddenError, InvalidRequestError, NotFoundError, SessionExpiredError, UnauthorizedError, ValidationError } from '../errors';
2
+ import type { ApiResponse } from '../routing';
3
+ import type { Logger } from '../services/logger';
4
+ export type DefaultErrors = {
5
+ InvalidRequestError: InvalidRequestError;
6
+ UnauthorizedError: UnauthorizedError;
7
+ ForbiddenError: ForbiddenError;
8
+ NotFoundError: NotFoundError;
9
+ ValidationError: ValidationError;
10
+ SessionExpiredError: SessionExpiredError;
11
+ };
12
+ export type Handlers<E> = {
13
+ [T in keyof E]?: (e: E[T], logger: Logger) => ApiResponse<number, any>;
14
+ };
15
+ export declare const defaultHandlers: Handlers<DefaultErrors>;
16
+ /**
17
+ * Creates an error handler. Provides default handlers for `UnauthorizedError`,
18
+ * `SessionExpiredError`, `NotFoundError`, and `InvalidRequestError`. User-specified
19
+ * handlers can be added to these. If no handler is found, the error is logged and
20
+ * a 500 text response is returned.
21
+ *
22
+ * @param inputHandlers a map of errors to handler functions
23
+ */
24
+ export declare const createErrorHandler: <Errors = DefaultErrors>(inputHandlers?: Handlers<Errors>) => (e: Error, logger: Logger) => Promise<ApiResponse<number, any>>;