@aws-blocks/core 0.1.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 (394) hide show
  1. package/LICENSE +174 -0
  2. package/dist/api.d.ts +147 -0
  3. package/dist/api.d.ts.map +1 -0
  4. package/dist/api.js +10 -0
  5. package/dist/api.test.d.ts +2 -0
  6. package/dist/api.test.d.ts.map +1 -0
  7. package/dist/api.test.js +19 -0
  8. package/dist/bb-utils.d.ts +11 -0
  9. package/dist/bb-utils.d.ts.map +1 -0
  10. package/dist/bb-utils.js +12 -0
  11. package/dist/builtin-routes.d.ts +6 -0
  12. package/dist/builtin-routes.d.ts.map +1 -0
  13. package/dist/builtin-routes.js +57 -0
  14. package/dist/cdk/__fixtures__/factory-backend.d.ts +3 -0
  15. package/dist/cdk/__fixtures__/factory-backend.d.ts.map +1 -0
  16. package/dist/cdk/__fixtures__/factory-backend.js +6 -0
  17. package/dist/cdk/__fixtures__/fullid-construct-backend.d.ts +2 -0
  18. package/dist/cdk/__fixtures__/fullid-construct-backend.d.ts.map +1 -0
  19. package/dist/cdk/__fixtures__/fullid-construct-backend.js +37 -0
  20. package/dist/cdk/__fixtures__/handler.d.ts +5 -0
  21. package/dist/cdk/__fixtures__/handler.d.ts.map +1 -0
  22. package/dist/cdk/__fixtures__/handler.js +3 -0
  23. package/dist/cdk/__fixtures__/side-effect-backend.d.ts +2 -0
  24. package/dist/cdk/__fixtures__/side-effect-backend.d.ts.map +1 -0
  25. package/dist/cdk/__fixtures__/side-effect-backend.js +5 -0
  26. package/dist/cdk/blocks-backend.d.ts +68 -0
  27. package/dist/cdk/blocks-backend.d.ts.map +1 -0
  28. package/dist/cdk/blocks-backend.js +214 -0
  29. package/dist/cdk/blocks-backend.test.d.ts +2 -0
  30. package/dist/cdk/blocks-backend.test.d.ts.map +1 -0
  31. package/dist/cdk/blocks-backend.test.js +151 -0
  32. package/dist/cdk/blocks-stack.test.d.ts +2 -0
  33. package/dist/cdk/blocks-stack.test.d.ts.map +1 -0
  34. package/dist/cdk/blocks-stack.test.js +78 -0
  35. package/dist/cdk/config-registry.d.ts +26 -0
  36. package/dist/cdk/config-registry.d.ts.map +1 -0
  37. package/dist/cdk/config-registry.js +80 -0
  38. package/dist/cdk/index.d.ts +35 -0
  39. package/dist/cdk/index.d.ts.map +1 -0
  40. package/dist/cdk/index.js +90 -0
  41. package/dist/cdk/mixins.d.ts +28 -0
  42. package/dist/cdk/mixins.d.ts.map +1 -0
  43. package/dist/cdk/mixins.js +37 -0
  44. package/dist/cdk/mixins.test.d.ts +2 -0
  45. package/dist/cdk/mixins.test.d.ts.map +1 -0
  46. package/dist/cdk/mixins.test.js +108 -0
  47. package/dist/cdk/node-version.d.ts +14 -0
  48. package/dist/cdk/node-version.d.ts.map +1 -0
  49. package/dist/cdk/node-version.js +15 -0
  50. package/dist/cdk/stack-metadata.d.ts +12 -0
  51. package/dist/cdk/stack-metadata.d.ts.map +1 -0
  52. package/dist/cdk/stack-metadata.js +22 -0
  53. package/dist/cdk/stack-metadata.test.d.ts +2 -0
  54. package/dist/cdk/stack-metadata.test.d.ts.map +1 -0
  55. package/dist/cdk/stack-metadata.test.js +56 -0
  56. package/dist/cdk/synth-guard.d.ts +14 -0
  57. package/dist/cdk/synth-guard.d.ts.map +1 -0
  58. package/dist/cdk/synth-guard.js +20 -0
  59. package/dist/cdk/synth-guard.test.d.ts +2 -0
  60. package/dist/cdk/synth-guard.test.d.ts.map +1 -0
  61. package/dist/cdk/synth-guard.test.js +15 -0
  62. package/dist/client/index.d.ts +97 -0
  63. package/dist/client/index.d.ts.map +1 -0
  64. package/dist/client/index.js +238 -0
  65. package/dist/client/index.test.d.ts +2 -0
  66. package/dist/client/index.test.d.ts.map +1 -0
  67. package/dist/client/index.test.js +113 -0
  68. package/dist/common/config.d.ts +45 -0
  69. package/dist/common/config.d.ts.map +1 -0
  70. package/dist/common/config.js +154 -0
  71. package/dist/common/config.test.d.ts +2 -0
  72. package/dist/common/config.test.d.ts.map +1 -0
  73. package/dist/common/config.test.js +173 -0
  74. package/dist/common/constants.d.ts +11 -0
  75. package/dist/common/constants.d.ts.map +1 -0
  76. package/dist/common/constants.js +12 -0
  77. package/dist/common/crypto.d.ts +6 -0
  78. package/dist/common/crypto.d.ts.map +1 -0
  79. package/dist/common/crypto.js +14 -0
  80. package/dist/common/index.d.ts +220 -0
  81. package/dist/common/index.d.ts.map +1 -0
  82. package/dist/common/index.js +180 -0
  83. package/dist/common/index.test.d.ts +2 -0
  84. package/dist/common/index.test.d.ts.map +1 -0
  85. package/dist/common/index.test.js +195 -0
  86. package/dist/common/mock-data.d.ts +40 -0
  87. package/dist/common/mock-data.d.ts.map +1 -0
  88. package/dist/common/mock-data.js +39 -0
  89. package/dist/common/official-bb-names.generated.d.ts +7 -0
  90. package/dist/common/official-bb-names.generated.d.ts.map +1 -0
  91. package/dist/common/official-bb-names.generated.js +28 -0
  92. package/dist/common/sdk-registry.d.ts +136 -0
  93. package/dist/common/sdk-registry.d.ts.map +1 -0
  94. package/dist/common/sdk-registry.js +125 -0
  95. package/dist/constants.d.ts +27 -0
  96. package/dist/constants.d.ts.map +1 -0
  97. package/dist/constants.js +28 -0
  98. package/dist/cors.d.ts +39 -0
  99. package/dist/cors.d.ts.map +1 -0
  100. package/dist/cors.js +85 -0
  101. package/dist/cors.test.d.ts +2 -0
  102. package/dist/cors.test.d.ts.map +1 -0
  103. package/dist/cors.test.js +241 -0
  104. package/dist/db-naming.d.ts +21 -0
  105. package/dist/db-naming.d.ts.map +1 -0
  106. package/dist/db-naming.js +38 -0
  107. package/dist/db-naming.test.d.ts +2 -0
  108. package/dist/db-naming.test.d.ts.map +1 -0
  109. package/dist/db-naming.test.js +29 -0
  110. package/dist/errors.d.ts +67 -0
  111. package/dist/errors.d.ts.map +1 -0
  112. package/dist/errors.js +69 -0
  113. package/dist/hosting.d.ts +258 -0
  114. package/dist/hosting.d.ts.map +1 -0
  115. package/dist/hosting.js +340 -0
  116. package/dist/hosting.test.d.ts +2 -0
  117. package/dist/hosting.test.d.ts.map +1 -0
  118. package/dist/hosting.test.js +1077 -0
  119. package/dist/index.cdk.d.ts +13 -0
  120. package/dist/index.cdk.d.ts.map +1 -0
  121. package/dist/index.cdk.js +13 -0
  122. package/dist/index.d.ts +9 -0
  123. package/dist/index.d.ts.map +1 -0
  124. package/dist/index.js +10 -0
  125. package/dist/lambda-handler.d.ts +131 -0
  126. package/dist/lambda-handler.d.ts.map +1 -0
  127. package/dist/lambda-handler.js +610 -0
  128. package/dist/lambda-handler.test.d.ts +2 -0
  129. package/dist/lambda-handler.test.d.ts.map +1 -0
  130. package/dist/lambda-handler.test.js +835 -0
  131. package/dist/pipeline/index.d.ts +4 -0
  132. package/dist/pipeline/index.d.ts.map +1 -0
  133. package/dist/pipeline/index.js +3 -0
  134. package/dist/pipeline/pipeline-construct.d.ts +130 -0
  135. package/dist/pipeline/pipeline-construct.d.ts.map +1 -0
  136. package/dist/pipeline/pipeline-construct.js +484 -0
  137. package/dist/pipeline/pipeline.test.d.ts +2 -0
  138. package/dist/pipeline/pipeline.test.d.ts.map +1 -0
  139. package/dist/pipeline/pipeline.test.js +1231 -0
  140. package/dist/pipeline/types.d.ts +351 -0
  141. package/dist/pipeline/types.d.ts.map +1 -0
  142. package/dist/pipeline/types.js +3 -0
  143. package/dist/raw-route.cdk.d.ts +47 -0
  144. package/dist/raw-route.cdk.d.ts.map +1 -0
  145. package/dist/raw-route.cdk.js +51 -0
  146. package/dist/raw-route.d.ts +119 -0
  147. package/dist/raw-route.d.ts.map +1 -0
  148. package/dist/raw-route.js +239 -0
  149. package/dist/raw-route.mock.d.ts +47 -0
  150. package/dist/raw-route.mock.d.ts.map +1 -0
  151. package/dist/raw-route.mock.js +51 -0
  152. package/dist/raw-route.test.d.ts +2 -0
  153. package/dist/raw-route.test.d.ts.map +1 -0
  154. package/dist/raw-route.test.js +597 -0
  155. package/dist/redact.d.ts +51 -0
  156. package/dist/redact.d.ts.map +1 -0
  157. package/dist/redact.js +134 -0
  158. package/dist/redact.test.d.ts +2 -0
  159. package/dist/redact.test.d.ts.map +1 -0
  160. package/dist/redact.test.js +199 -0
  161. package/dist/rpc.d.ts +54 -0
  162. package/dist/rpc.d.ts.map +1 -0
  163. package/dist/rpc.js +127 -0
  164. package/dist/rpc.test.d.ts +2 -0
  165. package/dist/rpc.test.d.ts.map +1 -0
  166. package/dist/rpc.test.js +60 -0
  167. package/dist/scripts/cdk-telemetry-env.d.ts +13 -0
  168. package/dist/scripts/cdk-telemetry-env.d.ts.map +1 -0
  169. package/dist/scripts/cdk-telemetry-env.js +21 -0
  170. package/dist/scripts/cdk-telemetry-env.test.d.ts +2 -0
  171. package/dist/scripts/cdk-telemetry-env.test.d.ts.map +1 -0
  172. package/dist/scripts/cdk-telemetry-env.test.js +56 -0
  173. package/dist/scripts/cleanup.d.ts +3 -0
  174. package/dist/scripts/cleanup.d.ts.map +1 -0
  175. package/dist/scripts/cleanup.js +35 -0
  176. package/dist/scripts/console.d.ts +6 -0
  177. package/dist/scripts/console.d.ts.map +1 -0
  178. package/dist/scripts/console.js +25 -0
  179. package/dist/scripts/deploy.d.ts +6 -0
  180. package/dist/scripts/deploy.d.ts.map +1 -0
  181. package/dist/scripts/deploy.js +82 -0
  182. package/dist/scripts/destroy.d.ts +6 -0
  183. package/dist/scripts/destroy.d.ts.map +1 -0
  184. package/dist/scripts/destroy.js +30 -0
  185. package/dist/scripts/dev-server-cors.test.d.ts +2 -0
  186. package/dist/scripts/dev-server-cors.test.d.ts.map +1 -0
  187. package/dist/scripts/dev-server-cors.test.js +23 -0
  188. package/dist/scripts/dev-server-telemetry.test.d.ts +2 -0
  189. package/dist/scripts/dev-server-telemetry.test.d.ts.map +1 -0
  190. package/dist/scripts/dev-server-telemetry.test.js +113 -0
  191. package/dist/scripts/dev-server.d.ts +21 -0
  192. package/dist/scripts/dev-server.d.ts.map +1 -0
  193. package/dist/scripts/dev-server.js +456 -0
  194. package/dist/scripts/ensure-secrets.d.ts +31 -0
  195. package/dist/scripts/ensure-secrets.d.ts.map +1 -0
  196. package/dist/scripts/ensure-secrets.js +100 -0
  197. package/dist/scripts/ensure-secrets.test.d.ts +2 -0
  198. package/dist/scripts/ensure-secrets.test.d.ts.map +1 -0
  199. package/dist/scripts/ensure-secrets.test.js +44 -0
  200. package/dist/scripts/external-migrations-step.d.ts +62 -0
  201. package/dist/scripts/external-migrations-step.d.ts.map +1 -0
  202. package/dist/scripts/external-migrations-step.js +243 -0
  203. package/dist/scripts/external-migrations-step.test.d.ts +2 -0
  204. package/dist/scripts/external-migrations-step.test.d.ts.map +1 -0
  205. package/dist/scripts/external-migrations-step.test.js +47 -0
  206. package/dist/scripts/extract-ts-types.d.ts +65 -0
  207. package/dist/scripts/extract-ts-types.d.ts.map +1 -0
  208. package/dist/scripts/extract-ts-types.js +664 -0
  209. package/dist/scripts/extract-ts-types.test.d.ts +2 -0
  210. package/dist/scripts/extract-ts-types.test.d.ts.map +1 -0
  211. package/dist/scripts/extract-ts-types.test.js +497 -0
  212. package/dist/scripts/generate-client-worker.d.ts +2 -0
  213. package/dist/scripts/generate-client-worker.d.ts.map +1 -0
  214. package/dist/scripts/generate-client-worker.js +13 -0
  215. package/dist/scripts/generate-client.d.ts +14 -0
  216. package/dist/scripts/generate-client.d.ts.map +1 -0
  217. package/dist/scripts/generate-client.js +73 -0
  218. package/dist/scripts/generate-client.test.d.ts +2 -0
  219. package/dist/scripts/generate-client.test.d.ts.map +1 -0
  220. package/dist/scripts/generate-client.test.js +48 -0
  221. package/dist/scripts/generate-spec-cli.d.ts +3 -0
  222. package/dist/scripts/generate-spec-cli.d.ts.map +1 -0
  223. package/dist/scripts/generate-spec-cli.js +77 -0
  224. package/dist/scripts/generate-spec-cli.test.d.ts +14 -0
  225. package/dist/scripts/generate-spec-cli.test.d.ts.map +1 -0
  226. package/dist/scripts/generate-spec-cli.test.js +90 -0
  227. package/dist/scripts/generate-spec.d.ts +61 -0
  228. package/dist/scripts/generate-spec.d.ts.map +1 -0
  229. package/dist/scripts/generate-spec.js +746 -0
  230. package/dist/scripts/generate-spec.test.d.ts +12 -0
  231. package/dist/scripts/generate-spec.test.d.ts.map +1 -0
  232. package/dist/scripts/generate-spec.test.js +88 -0
  233. package/dist/scripts/index.d.ts +12 -0
  234. package/dist/scripts/index.d.ts.map +1 -0
  235. package/dist/scripts/index.js +13 -0
  236. package/dist/scripts/sandbox.d.ts +11 -0
  237. package/dist/scripts/sandbox.d.ts.map +1 -0
  238. package/dist/scripts/sandbox.js +200 -0
  239. package/dist/scripts/telemetry-cli.d.ts +3 -0
  240. package/dist/scripts/telemetry-cli.d.ts.map +1 -0
  241. package/dist/scripts/telemetry-cli.js +8 -0
  242. package/dist/scripts/telemetry.d.ts +17 -0
  243. package/dist/scripts/telemetry.d.ts.map +1 -0
  244. package/dist/scripts/telemetry.js +150 -0
  245. package/dist/scripts/telemetry.test.d.ts +2 -0
  246. package/dist/scripts/telemetry.test.d.ts.map +1 -0
  247. package/dist/scripts/telemetry.test.js +203 -0
  248. package/dist/scripts/validate-spec.d.ts +22 -0
  249. package/dist/scripts/validate-spec.d.ts.map +1 -0
  250. package/dist/scripts/validate-spec.js +159 -0
  251. package/dist/server/index.d.ts +3 -0
  252. package/dist/server/index.d.ts.map +1 -0
  253. package/dist/server/index.js +3 -0
  254. package/dist/server/withAuth.d.ts +142 -0
  255. package/dist/server/withAuth.d.ts.map +1 -0
  256. package/dist/server/withAuth.js +261 -0
  257. package/dist/server/withAuth.test.d.ts +2 -0
  258. package/dist/server/withAuth.test.d.ts.map +1 -0
  259. package/dist/server/withAuth.test.js +278 -0
  260. package/dist/telemetry/client.d.ts +59 -0
  261. package/dist/telemetry/client.d.ts.map +1 -0
  262. package/dist/telemetry/client.js +215 -0
  263. package/dist/telemetry/config-writer.d.ts +16 -0
  264. package/dist/telemetry/config-writer.d.ts.map +1 -0
  265. package/dist/telemetry/config-writer.js +36 -0
  266. package/dist/telemetry/consent-commands.test.d.ts +2 -0
  267. package/dist/telemetry/consent-commands.test.d.ts.map +1 -0
  268. package/dist/telemetry/consent-commands.test.js +161 -0
  269. package/dist/telemetry/consent.d.ts +60 -0
  270. package/dist/telemetry/consent.d.ts.map +1 -0
  271. package/dist/telemetry/consent.js +122 -0
  272. package/dist/telemetry/environment.d.ts +33 -0
  273. package/dist/telemetry/environment.d.ts.map +1 -0
  274. package/dist/telemetry/environment.js +87 -0
  275. package/dist/telemetry/identifiers.d.ts +20 -0
  276. package/dist/telemetry/identifiers.d.ts.map +1 -0
  277. package/dist/telemetry/identifiers.js +86 -0
  278. package/dist/telemetry/index.d.ts +6 -0
  279. package/dist/telemetry/index.d.ts.map +1 -0
  280. package/dist/telemetry/index.js +4 -0
  281. package/dist/telemetry/telemetry.test.d.ts +2 -0
  282. package/dist/telemetry/telemetry.test.d.ts.map +1 -0
  283. package/dist/telemetry/telemetry.test.js +1131 -0
  284. package/dist/telemetry/trackCommand.d.ts +32 -0
  285. package/dist/telemetry/trackCommand.d.ts.map +1 -0
  286. package/dist/telemetry/trackCommand.js +102 -0
  287. package/dist/telemetry/types.d.ts +92 -0
  288. package/dist/telemetry/types.d.ts.map +1 -0
  289. package/dist/telemetry/types.js +1 -0
  290. package/dist/types.d.ts +24 -0
  291. package/dist/types.d.ts.map +1 -0
  292. package/dist/types.js +3 -0
  293. package/dist/version.d.ts +2 -0
  294. package/dist/version.d.ts.map +1 -0
  295. package/dist/version.js +2 -0
  296. package/package.json +83 -0
  297. package/src/api.test.ts +25 -0
  298. package/src/api.ts +163 -0
  299. package/src/bb-utils.ts +13 -0
  300. package/src/builtin-routes.ts +62 -0
  301. package/src/cdk/__fixtures__/factory-backend.ts +8 -0
  302. package/src/cdk/__fixtures__/fullid-construct-backend.ts +42 -0
  303. package/src/cdk/__fixtures__/handler.ts +4 -0
  304. package/src/cdk/__fixtures__/side-effect-backend.ts +7 -0
  305. package/src/cdk/blocks-backend.test.ts +207 -0
  306. package/src/cdk/blocks-backend.ts +249 -0
  307. package/src/cdk/blocks-stack.test.ts +106 -0
  308. package/src/cdk/config-registry.ts +106 -0
  309. package/src/cdk/index.ts +115 -0
  310. package/src/cdk/mixins.test.ts +129 -0
  311. package/src/cdk/mixins.ts +41 -0
  312. package/src/cdk/node-version.ts +17 -0
  313. package/src/cdk/stack-metadata.test.ts +71 -0
  314. package/src/cdk/stack-metadata.ts +29 -0
  315. package/src/cdk/synth-guard.test.ts +21 -0
  316. package/src/cdk/synth-guard.ts +23 -0
  317. package/src/client/index.test.ts +118 -0
  318. package/src/client/index.ts +320 -0
  319. package/src/common/config.test.ts +236 -0
  320. package/src/common/config.ts +169 -0
  321. package/src/common/constants.ts +15 -0
  322. package/src/common/crypto.ts +15 -0
  323. package/src/common/index.test.ts +242 -0
  324. package/src/common/index.ts +335 -0
  325. package/src/common/mock-data.ts +52 -0
  326. package/src/common/official-bb-names.generated.ts +29 -0
  327. package/src/common/sdk-registry.ts +150 -0
  328. package/src/constants.ts +31 -0
  329. package/src/cors.test.ts +279 -0
  330. package/src/cors.ts +91 -0
  331. package/src/db-naming.test.ts +48 -0
  332. package/src/db-naming.ts +41 -0
  333. package/src/errors.ts +72 -0
  334. package/src/hosting.test.ts +1431 -0
  335. package/src/hosting.ts +626 -0
  336. package/src/index.cdk.ts +45 -0
  337. package/src/index.ts +22 -0
  338. package/src/lambda-handler.test.ts +1005 -0
  339. package/src/lambda-handler.ts +706 -0
  340. package/src/pipeline/index.ts +12 -0
  341. package/src/pipeline/pipeline-construct.ts +662 -0
  342. package/src/pipeline/pipeline.test.ts +1565 -0
  343. package/src/pipeline/types.ts +384 -0
  344. package/src/raw-route.cdk.ts +56 -0
  345. package/src/raw-route.mock.ts +56 -0
  346. package/src/raw-route.test.ts +819 -0
  347. package/src/raw-route.ts +316 -0
  348. package/src/redact.test.ts +222 -0
  349. package/src/redact.ts +143 -0
  350. package/src/rpc.test.ts +73 -0
  351. package/src/rpc.ts +174 -0
  352. package/src/scripts/cdk-telemetry-env.test.ts +75 -0
  353. package/src/scripts/cdk-telemetry-env.ts +23 -0
  354. package/src/scripts/cleanup.ts +39 -0
  355. package/src/scripts/console.ts +34 -0
  356. package/src/scripts/deploy.ts +106 -0
  357. package/src/scripts/destroy.ts +42 -0
  358. package/src/scripts/dev-server-cors.test.ts +28 -0
  359. package/src/scripts/dev-server-telemetry.test.ts +127 -0
  360. package/src/scripts/dev-server.ts +515 -0
  361. package/src/scripts/ensure-secrets.test.ts +50 -0
  362. package/src/scripts/ensure-secrets.ts +113 -0
  363. package/src/scripts/external-migrations-step.test.ts +64 -0
  364. package/src/scripts/external-migrations-step.ts +269 -0
  365. package/src/scripts/extract-ts-types.test.ts +516 -0
  366. package/src/scripts/extract-ts-types.ts +773 -0
  367. package/src/scripts/generate-client-worker.ts +15 -0
  368. package/src/scripts/generate-client.test.ts +69 -0
  369. package/src/scripts/generate-client.ts +86 -0
  370. package/src/scripts/generate-spec-cli.test.ts +106 -0
  371. package/src/scripts/generate-spec-cli.ts +92 -0
  372. package/src/scripts/generate-spec.test.ts +99 -0
  373. package/src/scripts/generate-spec.ts +833 -0
  374. package/src/scripts/index.ts +21 -0
  375. package/src/scripts/sandbox.ts +230 -0
  376. package/src/scripts/telemetry-cli.ts +10 -0
  377. package/src/scripts/telemetry.test.ts +239 -0
  378. package/src/scripts/telemetry.ts +173 -0
  379. package/src/scripts/validate-spec.ts +199 -0
  380. package/src/server/index.ts +5 -0
  381. package/src/server/withAuth.test.ts +348 -0
  382. package/src/server/withAuth.ts +323 -0
  383. package/src/telemetry/client.ts +226 -0
  384. package/src/telemetry/config-writer.ts +52 -0
  385. package/src/telemetry/consent-commands.test.ts +196 -0
  386. package/src/telemetry/consent.ts +154 -0
  387. package/src/telemetry/environment.ts +100 -0
  388. package/src/telemetry/identifiers.ts +94 -0
  389. package/src/telemetry/index.ts +11 -0
  390. package/src/telemetry/telemetry.test.ts +1343 -0
  391. package/src/telemetry/trackCommand.ts +110 -0
  392. package/src/telemetry/types.ts +92 -0
  393. package/src/types.ts +33 -0
  394. package/src/version.ts +2 -0
@@ -0,0 +1,199 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * Validate a generated OpenRPC document for structural conformance.
6
+ *
7
+ * Checks:
8
+ * - Required top-level fields (openrpc, info, methods)
9
+ * - OpenRPC version format
10
+ * - Method structure (name, params, result)
11
+ * - Param structure (name, required, schema)
12
+ * - Result structure (name, schema)
13
+ * - All $ref pointers resolve to entries in components.schemas
14
+ * - No `nullable` field (should use oneOf with null instead)
15
+ * - Method names are namespace-qualified (contain a dot)
16
+ * - Result names are descriptive (not just "result")
17
+ *
18
+ * Returns an array of error messages. Empty array = valid.
19
+ */
20
+
21
+ export interface SpecValidationError {
22
+ path: string;
23
+ message: string;
24
+ }
25
+
26
+ export function validateSpec(doc: any): SpecValidationError[] {
27
+ const errors: SpecValidationError[] = [];
28
+
29
+ // Top-level required fields
30
+ if (!doc || typeof doc !== 'object') {
31
+ return [{ path: '', message: 'Document must be an object' }];
32
+ }
33
+
34
+ if (typeof doc.openrpc !== 'string') {
35
+ errors.push({ path: 'openrpc', message: 'Missing or invalid "openrpc" version string' });
36
+ } else if (!/^\d+\.\d+\.\d+$/.test(doc.openrpc)) {
37
+ errors.push({ path: 'openrpc', message: `Invalid version format: "${doc.openrpc}"` });
38
+ }
39
+
40
+ if (!doc.info || typeof doc.info !== 'object') {
41
+ errors.push({ path: 'info', message: 'Missing "info" object' });
42
+ } else {
43
+ if (typeof doc.info.title !== 'string') {
44
+ errors.push({ path: 'info.title', message: 'Missing "info.title" string' });
45
+ }
46
+ if (typeof doc.info.version !== 'string') {
47
+ errors.push({ path: 'info.version', message: 'Missing "info.version" string' });
48
+ }
49
+ }
50
+
51
+ if (!Array.isArray(doc.methods)) {
52
+ errors.push({ path: 'methods', message: 'Missing "methods" array' });
53
+ return errors;
54
+ }
55
+
56
+ // Collect known schema names for $ref resolution
57
+ const knownSchemas = new Set<string>(
58
+ Object.keys(doc.components?.schemas || {})
59
+ );
60
+
61
+ // Scan entire document for $ref pointers and nullable fields
62
+ const docStr = JSON.stringify(doc);
63
+ if (docStr.includes('"nullable"')) {
64
+ errors.push({
65
+ path: '',
66
+ message: 'Document contains "nullable" field — use oneOf with { type: "null" } instead',
67
+ });
68
+ }
69
+
70
+ // Validate each method
71
+ for (let i = 0; i < doc.methods.length; i++) {
72
+ const method = doc.methods[i];
73
+ const mp = `methods[${i}]`;
74
+
75
+ if (typeof method.name !== 'string') {
76
+ errors.push({ path: `${mp}.name`, message: 'Missing method name' });
77
+ continue;
78
+ }
79
+
80
+ const mpath = `methods["${method.name}"]`;
81
+
82
+ // Namespace-qualified check
83
+ if (!method.name.includes('.')) {
84
+ errors.push({ path: `${mpath}.name`, message: `Method name "${method.name}" is not namespace-qualified (expected "namespace.method")` });
85
+ }
86
+
87
+ // Params
88
+ if (!Array.isArray(method.params)) {
89
+ errors.push({ path: `${mpath}.params`, message: 'Missing "params" array' });
90
+ } else {
91
+ for (let j = 0; j < method.params.length; j++) {
92
+ const param = method.params[j];
93
+ const pp = `${mpath}.params[${j}]`;
94
+ if (typeof param.name !== 'string') {
95
+ errors.push({ path: pp, message: 'Missing param name' });
96
+ }
97
+ if (typeof param.required !== 'boolean') {
98
+ errors.push({ path: `${pp}.required`, message: 'Missing or non-boolean "required"' });
99
+ }
100
+ if (!param.schema || typeof param.schema !== 'object') {
101
+ errors.push({ path: `${pp}.schema`, message: 'Missing param schema' });
102
+ }
103
+ // Check $ref resolution
104
+ if (param.schema?.$ref) {
105
+ validateRef(param.schema.$ref, `${pp}.schema.$ref`, knownSchemas, errors);
106
+ }
107
+ }
108
+ }
109
+
110
+ // Result
111
+ if (!method.result || typeof method.result !== 'object') {
112
+ errors.push({ path: `${mpath}.result`, message: 'Missing "result" object' });
113
+ } else {
114
+ if (typeof method.result.name !== 'string') {
115
+ errors.push({ path: `${mpath}.result.name`, message: 'Missing result name' });
116
+ } else if (method.result.name === 'result') {
117
+ errors.push({ path: `${mpath}.result.name`, message: 'Result name should be descriptive, not "result"' });
118
+ }
119
+ if (!method.result.schema || typeof method.result.schema !== 'object') {
120
+ errors.push({ path: `${mpath}.result.schema`, message: 'Missing result schema' });
121
+ }
122
+ // Check $ref resolution
123
+ if (method.result.schema?.$ref) {
124
+ validateRef(method.result.schema.$ref, `${mpath}.result.schema.$ref`, knownSchemas, errors);
125
+ }
126
+ // Check oneOf members for $refs
127
+ if (Array.isArray(method.result.schema?.oneOf)) {
128
+ for (let k = 0; k < method.result.schema.oneOf.length; k++) {
129
+ const member = method.result.schema.oneOf[k];
130
+ if (member.$ref) {
131
+ validateRef(member.$ref, `${mpath}.result.schema.oneOf[${k}].$ref`, knownSchemas, errors);
132
+ }
133
+ }
134
+ }
135
+
136
+ // Validate x-blocks-transferable extension field
137
+ if ('x-blocks-transferable' in (method.result.schema ?? {})) {
138
+ const blocksTag = method.result.schema['x-blocks-transferable'];
139
+ if (typeof blocksTag !== 'string' || blocksTag.length === 0) {
140
+ errors.push({
141
+ path: `${mpath}.result.schema.x-blocks-transferable`,
142
+ message: 'x-blocks-transferable must be a non-empty string',
143
+ });
144
+ }
145
+ }
146
+
147
+ // Validate x-blocks-type-args extension field
148
+ if ('x-blocks-type-args' in (method.result.schema ?? {})) {
149
+ const typeArgs = method.result.schema['x-blocks-type-args'];
150
+ if (!Array.isArray(typeArgs)) {
151
+ errors.push({
152
+ path: `${mpath}.result.schema.x-blocks-type-args`,
153
+ message: 'x-blocks-type-args must be an array of JSON Schema objects',
154
+ });
155
+ } else {
156
+ for (let k = 0; k < typeArgs.length; k++) {
157
+ const arg = typeArgs[k];
158
+ if (!arg || typeof arg !== 'object' || Array.isArray(arg)) {
159
+ errors.push({
160
+ path: `${mpath}.result.schema.x-blocks-type-args[${k}]`,
161
+ message: 'Each entry in x-blocks-type-args must be a valid JSON Schema object',
162
+ });
163
+ } else if (arg.$ref) {
164
+ validateRef(arg.$ref, `${mpath}.result.schema.x-blocks-type-args[${k}].$ref`, knownSchemas, errors);
165
+ }
166
+ }
167
+ }
168
+ }
169
+ }
170
+ }
171
+
172
+ // Validate components.schemas entries are well-formed
173
+ if (doc.components?.schemas) {
174
+ for (const [name, schema] of Object.entries(doc.components.schemas)) {
175
+ if (!schema || typeof schema !== 'object') {
176
+ errors.push({ path: `components.schemas.${name}`, message: 'Schema must be an object' });
177
+ }
178
+ }
179
+ }
180
+
181
+ return errors;
182
+ }
183
+
184
+ function validateRef(
185
+ ref: string,
186
+ path: string,
187
+ knownSchemas: Set<string>,
188
+ errors: SpecValidationError[],
189
+ ): void {
190
+ const prefix = '#/components/schemas/';
191
+ if (!ref.startsWith(prefix)) {
192
+ errors.push({ path, message: `$ref "${ref}" must start with "${prefix}"` });
193
+ return;
194
+ }
195
+ const schemaName = ref.slice(prefix.length);
196
+ if (!knownSchemas.has(schemaName)) {
197
+ errors.push({ path, message: `$ref "${ref}" does not resolve — "${schemaName}" not found in components.schemas` });
198
+ }
199
+ }
@@ -0,0 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export { withAuth, registerCookieProvider, clearCookieProviders } from './withAuth.js';
5
+ export type { CookieProvider } from './withAuth.js';
@@ -0,0 +1,348 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { test, describe, beforeEach, afterEach } from 'node:test';
5
+ import assert from 'node:assert';
6
+ import { AsyncLocalStorage } from 'node:async_hooks';
7
+ import { getContext } from 'unctx';
8
+ import { withAuth, registerCookieProvider, clearCookieProviders } from './index.js';
9
+ import { _getProviders } from './withAuth.js';
10
+ import { ApiError } from '../errors.js';
11
+
12
+ // Seed the `nitro-app` unctx context with `asyncContext: true` at module load,
13
+ // mirroring Nitro's `experimental.asyncContext: true`. unctx caches the context
14
+ // instance on first `getContext()` call (first-write-wins), so this MUST run
15
+ // before any test triggers the provider — otherwise a non-async instance gets
16
+ // cached and `.use()` cannot survive the provider's internal `await import`.
17
+ getContext('nitro-app', { asyncContext: true, AsyncLocalStorage });
18
+
19
+ describe('withAuth', () => {
20
+ let originalStore: any;
21
+
22
+ beforeEach(() => {
23
+ originalStore = (globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__;
24
+ });
25
+
26
+ afterEach(() => {
27
+ if (originalStore === undefined) {
28
+ delete (globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__;
29
+ } else {
30
+ (globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__ = originalStore;
31
+ }
32
+ });
33
+
34
+ test('forwards explicit cookies via AsyncLocalStorage', async () => {
35
+ const store = new AsyncLocalStorage<string>();
36
+ (globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__ = store;
37
+
38
+ let captured: string | undefined;
39
+ await withAuth(async () => {
40
+ captured = store.getStore();
41
+ return 'result';
42
+ }, 'session=abc123; token=xyz');
43
+
44
+ assert.strictEqual(captured, 'session=abc123; token=xyz');
45
+ });
46
+
47
+ test('returns the value from fn when explicit cookies provided', async () => {
48
+ const store = new AsyncLocalStorage<string>();
49
+ (globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__ = store;
50
+
51
+ const result = await withAuth(async () => {
52
+ return { data: 42 };
53
+ }, 'session=abc');
54
+
55
+ assert.deepStrictEqual(result, { data: 42 });
56
+ });
57
+
58
+ test('uses existing AsyncLocalStorage context when already set', async () => {
59
+ const store = new AsyncLocalStorage<string>();
60
+ (globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__ = store;
61
+
62
+ let innerCookies: string | undefined;
63
+
64
+ await store.run('existing-cookies', async () => {
65
+ const result = await withAuth(async () => {
66
+ innerCookies = store.getStore();
67
+ return 'ok';
68
+ });
69
+ assert.strictEqual(result, 'ok');
70
+ });
71
+
72
+ assert.strictEqual(innerCookies, 'existing-cookies');
73
+ });
74
+
75
+ test('throws when no cookies found and no framework detected', async () => {
76
+ const store = new AsyncLocalStorage<string>();
77
+ (globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__ = store;
78
+
79
+ const saved = _getProviders().slice();
80
+ clearCookieProviders();
81
+
82
+ try {
83
+ await assert.rejects(
84
+ () => withAuth(async () => 'should not reach'),
85
+ (err: ApiError) => {
86
+ assert.ok(err instanceof ApiError);
87
+ assert.ok(err.message.includes('withAuth: No authentication cookies found'));
88
+ assert.strictEqual(err.status, 401);
89
+ return true;
90
+ },
91
+ );
92
+ } finally {
93
+ for (const p of saved) registerCookieProvider(p.name, p.detect);
94
+ }
95
+ });
96
+
97
+ test('creates AsyncLocalStorage lazily if globalThis store is missing', async () => {
98
+ delete (globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__;
99
+
100
+ let storeExistedDuringCall = false;
101
+ const result = await withAuth(async () => {
102
+ storeExistedDuringCall = !!(globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__;
103
+ return 'created';
104
+ }, 'lazy-cookies');
105
+
106
+ assert.strictEqual(result, 'created');
107
+ assert.ok(storeExistedDuringCall, 'Store should be created lazily');
108
+ assert.ok((globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__, 'Store should persist on globalThis');
109
+ });
110
+
111
+ test('propagates errors from fn', async () => {
112
+ const store = new AsyncLocalStorage<string>();
113
+ (globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__ = store;
114
+
115
+ await assert.rejects(
116
+ () => withAuth(async () => {
117
+ throw new Error('inner error');
118
+ }, 'some-cookies'),
119
+ { message: 'inner error' },
120
+ );
121
+ });
122
+
123
+ test('multiple nested API calls share the same cookie context', async () => {
124
+ const store = new AsyncLocalStorage<string>();
125
+ (globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__ = store;
126
+
127
+ const captured: string[] = [];
128
+
129
+ await withAuth(async () => {
130
+ captured.push(store.getStore() ?? 'none');
131
+ await Promise.resolve();
132
+ captured.push(store.getStore() ?? 'none');
133
+ return captured;
134
+ }, 'shared-session=1');
135
+
136
+ assert.deepStrictEqual(captured, ['shared-session=1', 'shared-session=1']);
137
+ });
138
+ });
139
+
140
+ describe('Cookie Provider Registry', () => {
141
+ let originalStore: any;
142
+ let savedProviders: Array<{ name: string; detect: () => Promise<string | undefined> }>;
143
+
144
+ beforeEach(() => {
145
+ originalStore = (globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__;
146
+ savedProviders = _getProviders().slice();
147
+ clearCookieProviders();
148
+ });
149
+
150
+ afterEach(() => {
151
+ clearCookieProviders();
152
+ for (const p of savedProviders) registerCookieProvider(p.name, p.detect);
153
+
154
+ if (originalStore === undefined) {
155
+ delete (globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__;
156
+ } else {
157
+ (globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__ = originalStore;
158
+ }
159
+ });
160
+
161
+ test('default Next.js provider is registered on module load', () => {
162
+ const providers = savedProviders;
163
+ const nextProvider = providers.find(p => p.name === 'nextjs');
164
+ assert.ok(nextProvider, 'Next.js provider should be registered by default');
165
+ });
166
+
167
+ test('Next.js provider returns undefined when next/headers is not available', async () => {
168
+ const nextProvider = savedProviders.find(p => p.name === 'nextjs');
169
+ assert.ok(nextProvider);
170
+
171
+ const result = await nextProvider.detect();
172
+ assert.strictEqual(result, undefined);
173
+ });
174
+
175
+ test('default Nuxt provider is registered on module load', () => {
176
+ const providers = savedProviders;
177
+ const nuxtProvider = providers.find(p => p.name === 'nuxt');
178
+ assert.ok(nuxtProvider, 'Nuxt provider should be registered by default');
179
+ });
180
+
181
+ test('Nuxt provider returns undefined cleanly when no Nitro context is bound', async () => {
182
+ // When the test runs in a plain node env (no Nitro), either `unctx`
183
+ // isn't installed (import fails) or it is, but `getContext('nitro-app').use()`
184
+ // throws because no async context is bound. Both paths must return
185
+ // undefined, and neither should leak the underlying error to the caller.
186
+ const nuxtProvider = savedProviders.find(p => p.name === 'nuxt');
187
+ assert.ok(nuxtProvider);
188
+
189
+ // Suppress the one-time console.warn on the asyncContext-disabled path so
190
+ // it doesn't contaminate test output.
191
+ process.env.BLOCKS_SUPPRESS_NUXT_ASYNC_CONTEXT_WARN = '1';
192
+ try {
193
+ const result = await nuxtProvider.detect();
194
+ assert.strictEqual(result, undefined);
195
+ } finally {
196
+ delete process.env.BLOCKS_SUPPRESS_NUXT_ASYNC_CONTEXT_WARN;
197
+ }
198
+ });
199
+
200
+ test('Nuxt provider reads cookie from the h3 `{ event }` shape (Nitro v2)', async () => {
201
+ const nuxtProvider = savedProviders.find(p => p.name === 'nuxt');
202
+ assert.ok(nuxtProvider);
203
+
204
+ // The `nitro-app` context is seeded with asyncContext at module load, so
205
+ // the binding survives the provider's internal `await import('unctx')`.
206
+ // Nitro v2 (h3): `{ event }` carrying the cookie on the Node request headers.
207
+ const bound = { event: { node: { req: { headers: { cookie: 'session=h3' } } } } };
208
+ const result = await getContext('nitro-app').callAsync(bound, () => nuxtProvider.detect());
209
+ assert.strictEqual(result, 'session=h3');
210
+ });
211
+
212
+ test('Nuxt provider reads cookie from the srvx `{ request }` shape (Nitro v3 / Nuxt 5)', async () => {
213
+ const nuxtProvider = savedProviders.find(p => p.name === 'nuxt');
214
+ assert.ok(nuxtProvider);
215
+
216
+ // Nitro v3 (srvx): `{ request }` carrying the cookie on a standard Web
217
+ // `Request`. This is the forward-compat path guarded by the TODO in
218
+ // withAuth.ts.
219
+ const bound = { request: new Request('https://example.com', { headers: { cookie: 'session=srvx' } }) };
220
+ const result = await getContext('nitro-app').callAsync(bound, () => nuxtProvider.detect());
221
+ assert.strictEqual(result, 'session=srvx');
222
+ });
223
+
224
+ test('custom provider registration works', async () => {
225
+ const store = new AsyncLocalStorage<string>();
226
+ (globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__ = store;
227
+
228
+ registerCookieProvider('custom', async () => 'custom-cookie=hello');
229
+
230
+ let captured: string | undefined;
231
+ await withAuth(async () => {
232
+ captured = store.getStore();
233
+ return 'ok';
234
+ });
235
+
236
+ assert.strictEqual(captured, 'custom-cookie=hello');
237
+ });
238
+
239
+ test('multiple providers tried in registration order — first match wins', async () => {
240
+ const store = new AsyncLocalStorage<string>();
241
+ (globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__ = store;
242
+
243
+ const callOrder: string[] = [];
244
+
245
+ registerCookieProvider('first', async () => {
246
+ callOrder.push('first');
247
+ return undefined;
248
+ });
249
+
250
+ registerCookieProvider('second', async () => {
251
+ callOrder.push('second');
252
+ return 'winner=second';
253
+ });
254
+
255
+ registerCookieProvider('third', async () => {
256
+ callOrder.push('third');
257
+ return 'should-not-reach=true';
258
+ });
259
+
260
+ let captured: string | undefined;
261
+ await withAuth(async () => {
262
+ captured = store.getStore();
263
+ return 'ok';
264
+ });
265
+
266
+ assert.strictEqual(captured, 'winner=second');
267
+ assert.deepStrictEqual(callOrder, ['first', 'second']);
268
+ });
269
+
270
+ test('explicit cookies take priority over providers', async () => {
271
+ const store = new AsyncLocalStorage<string>();
272
+ (globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__ = store;
273
+
274
+ let providerCalled = false;
275
+ registerCookieProvider('should-not-run', async () => {
276
+ providerCalled = true;
277
+ return 'provider-cookie=value';
278
+ });
279
+
280
+ let captured: string | undefined;
281
+ await withAuth(async () => {
282
+ captured = store.getStore();
283
+ return 'ok';
284
+ }, 'explicit-cookie=priority');
285
+
286
+ assert.strictEqual(captured, 'explicit-cookie=priority');
287
+ assert.strictEqual(providerCalled, false, 'Provider should not be called when explicit cookies given');
288
+ });
289
+
290
+ test('existing ALS context takes priority over providers', async () => {
291
+ const store = new AsyncLocalStorage<string>();
292
+ (globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__ = store;
293
+
294
+ let providerCalled = false;
295
+ registerCookieProvider('should-not-run', async () => {
296
+ providerCalled = true;
297
+ return 'provider-cookie=value';
298
+ });
299
+
300
+ let captured: string | undefined;
301
+ await store.run('als-cookies', async () => {
302
+ await withAuth(async () => {
303
+ captured = store.getStore();
304
+ return 'ok';
305
+ });
306
+ });
307
+
308
+ assert.strictEqual(captured, 'als-cookies');
309
+ assert.strictEqual(providerCalled, false, 'Provider should not be called when ALS context exists');
310
+ });
311
+
312
+ test('throws when all providers return undefined', async () => {
313
+ const store = new AsyncLocalStorage<string>();
314
+ (globalThis as any).__BLOCKS_REQUEST_COOKIES_STORE__ = store;
315
+
316
+ registerCookieProvider('nope1', async () => undefined);
317
+ registerCookieProvider('nope2', async () => undefined);
318
+
319
+ await assert.rejects(
320
+ () => withAuth(async () => 'should not reach'),
321
+ (err: ApiError) => {
322
+ assert.ok(err instanceof ApiError);
323
+ assert.ok(err.message.includes('withAuth: No authentication cookies found'));
324
+ assert.strictEqual(err.status, 401);
325
+ return true;
326
+ },
327
+ );
328
+ });
329
+
330
+ test('registerCookieProvider appends to existing providers', () => {
331
+ registerCookieProvider('a', async () => undefined);
332
+ registerCookieProvider('b', async () => undefined);
333
+
334
+ const providers = _getProviders();
335
+ assert.strictEqual(providers.length, 2);
336
+ assert.strictEqual(providers[0].name, 'a');
337
+ assert.strictEqual(providers[1].name, 'b');
338
+ });
339
+
340
+ test('clearCookieProviders removes all registered providers', () => {
341
+ registerCookieProvider('a', async () => undefined);
342
+ registerCookieProvider('b', async () => undefined);
343
+ assert.strictEqual(_getProviders().length, 2);
344
+
345
+ clearCookieProviders();
346
+ assert.strictEqual(_getProviders().length, 0);
347
+ });
348
+ });