@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,203 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { describe, it, beforeEach, afterEach } from 'node:test';
4
+ import assert from 'node:assert';
5
+ import { spawnSync } from 'node:child_process';
6
+ import { mkdirSync, writeFileSync, readFileSync, rmSync, existsSync } from 'node:fs';
7
+ import { join } from 'node:path';
8
+ import { tmpdir } from 'node:os';
9
+ import { fileURLToPath } from 'node:url';
10
+ import { dirname } from 'node:path';
11
+ const __dirname = dirname(fileURLToPath(import.meta.url));
12
+ const CLI_SCRIPT = join(__dirname, 'telemetry-cli.js');
13
+ /** Env overrides that clear CI detection so tests see "default enabled" state. */
14
+ const NO_CI_ENV = {
15
+ CI: '',
16
+ CONTINUOUS_INTEGRATION: '',
17
+ BUILD_NUMBER: '',
18
+ CODEBUILD_BUILD_ID: '',
19
+ GITHUB_ACTIONS: '',
20
+ GITLAB_CI: '',
21
+ CIRCLECI: '',
22
+ JENKINS_URL: '',
23
+ TF_BUILD: '',
24
+ BITBUCKET_BUILD_NUMBER: '',
25
+ BUILDKITE: '',
26
+ AWS_BLOCKS_DISABLE_TELEMETRY: '',
27
+ };
28
+ function createTmpDir() {
29
+ const dir = join(tmpdir(), `blocks-telemetry-test-${Date.now()}-${Math.random().toString(36).slice(2)}`);
30
+ mkdirSync(dir, { recursive: true });
31
+ return dir;
32
+ }
33
+ function runCli(args, options) {
34
+ const result = spawnSync('node', [CLI_SCRIPT, ...args], {
35
+ cwd: options?.cwd ?? process.cwd(),
36
+ encoding: 'utf-8',
37
+ env: { ...process.env, ...options?.env },
38
+ stdio: ['pipe', 'pipe', 'pipe'],
39
+ });
40
+ return {
41
+ stdout: result.stdout || '',
42
+ stderr: result.stderr || '',
43
+ exitCode: result.status ?? 1,
44
+ };
45
+ }
46
+ describe('telemetry CLI', () => {
47
+ let tmpHome;
48
+ let tmpProject;
49
+ beforeEach(() => {
50
+ tmpHome = createTmpDir();
51
+ tmpProject = createTmpDir();
52
+ });
53
+ afterEach(() => {
54
+ rmSync(tmpHome, { recursive: true, force: true });
55
+ rmSync(tmpProject, { recursive: true, force: true });
56
+ });
57
+ describe('help', () => {
58
+ it('--help shows usage', () => {
59
+ const result = runCli(['--help'], { cwd: tmpProject, env: { HOME: tmpHome } });
60
+ assert.strictEqual(result.exitCode, 0);
61
+ assert.ok(result.stdout.includes('--enable'));
62
+ assert.ok(result.stdout.includes('--disable'));
63
+ assert.ok(result.stdout.includes('--global'));
64
+ });
65
+ it('-h shows usage', () => {
66
+ const result = runCli(['-h'], { cwd: tmpProject, env: { HOME: tmpHome } });
67
+ assert.strictEqual(result.exitCode, 0);
68
+ assert.ok(result.stdout.includes('--enable'));
69
+ });
70
+ });
71
+ describe('bare command (shows help)', () => {
72
+ it('shows usage when invoked with no arguments', () => {
73
+ const result = runCli([], { cwd: tmpProject, env: { HOME: tmpHome, ...NO_CI_ENV } });
74
+ assert.strictEqual(result.exitCode, 0);
75
+ assert.ok(result.stdout.includes('Usage:'));
76
+ assert.ok(result.stdout.includes('--enable'));
77
+ assert.ok(result.stdout.includes('--disable'));
78
+ assert.ok(result.stdout.includes('--status'));
79
+ });
80
+ });
81
+ describe('--enable (project-level default)', () => {
82
+ it('creates .blocks/config.json with telemetry.enabled=true', () => {
83
+ const result = runCli(['--enable'], { cwd: tmpProject, env: { HOME: tmpHome } });
84
+ assert.strictEqual(result.exitCode, 0);
85
+ assert.ok(result.stdout.includes('enabled for this project'));
86
+ const configPath = join(tmpProject, '.blocks', 'config.json');
87
+ assert.ok(existsSync(configPath));
88
+ const config = JSON.parse(readFileSync(configPath, 'utf-8'));
89
+ assert.strictEqual(config.telemetry.enabled, true);
90
+ });
91
+ });
92
+ describe('--disable (project-level default)', () => {
93
+ it('creates .blocks/config.json with telemetry.enabled=false', () => {
94
+ const result = runCli(['--disable'], { cwd: tmpProject, env: { HOME: tmpHome } });
95
+ assert.strictEqual(result.exitCode, 0);
96
+ assert.ok(result.stdout.includes('disabled for this project'));
97
+ const configPath = join(tmpProject, '.blocks', 'config.json');
98
+ assert.ok(existsSync(configPath));
99
+ const config = JSON.parse(readFileSync(configPath, 'utf-8'));
100
+ assert.strictEqual(config.telemetry.enabled, false);
101
+ });
102
+ });
103
+ describe('--enable --global', () => {
104
+ it('creates ~/.blocks/config.json with telemetry.enabled=true', () => {
105
+ const result = runCli(['--enable', '--global'], { cwd: tmpProject, env: { HOME: tmpHome } });
106
+ assert.strictEqual(result.exitCode, 0);
107
+ assert.ok(result.stdout.includes('enabled globally'));
108
+ const configPath = join(tmpHome, '.blocks', 'config.json');
109
+ assert.ok(existsSync(configPath));
110
+ const config = JSON.parse(readFileSync(configPath, 'utf-8'));
111
+ assert.strictEqual(config.telemetry.enabled, true);
112
+ });
113
+ it('preserves existing keys in global config', () => {
114
+ const configDir = join(tmpHome, '.blocks');
115
+ mkdirSync(configDir, { recursive: true });
116
+ writeFileSync(join(configDir, 'config.json'), JSON.stringify({ telemetry: { projectId: 'xyz' }, someKey: 'value' }, null, 2));
117
+ const result = runCli(['--enable', '--global'], { cwd: tmpProject, env: { HOME: tmpHome } });
118
+ assert.strictEqual(result.exitCode, 0);
119
+ const config = JSON.parse(readFileSync(join(configDir, 'config.json'), 'utf-8'));
120
+ assert.strictEqual(config.telemetry.enabled, true);
121
+ assert.strictEqual(config.telemetry.projectId, 'xyz');
122
+ assert.strictEqual(config.someKey, 'value');
123
+ });
124
+ });
125
+ describe('--disable --global', () => {
126
+ it('creates ~/.blocks/config.json with telemetry.enabled=false', () => {
127
+ const result = runCli(['--disable', '--global'], { cwd: tmpProject, env: { HOME: tmpHome } });
128
+ assert.strictEqual(result.exitCode, 0);
129
+ assert.ok(result.stdout.includes('disabled globally'));
130
+ const configPath = join(tmpHome, '.blocks', 'config.json');
131
+ assert.ok(existsSync(configPath));
132
+ const config = JSON.parse(readFileSync(configPath, 'utf-8'));
133
+ assert.strictEqual(config.telemetry.enabled, false);
134
+ });
135
+ });
136
+ describe('--status (shows status)', () => {
137
+ it('shows enabled by default when no config exists', () => {
138
+ const result = runCli(['--status'], { cwd: tmpProject, env: { HOME: tmpHome, ...NO_CI_ENV } });
139
+ assert.strictEqual(result.exitCode, 0);
140
+ assert.ok(result.stdout.includes('Telemetry:'));
141
+ assert.ok(result.stdout.includes('Enabled'));
142
+ });
143
+ it('shows disabled when global config disables telemetry', () => {
144
+ const configDir = join(tmpHome, '.blocks');
145
+ mkdirSync(configDir, { recursive: true });
146
+ writeFileSync(join(configDir, 'config.json'), JSON.stringify({ telemetry: { enabled: false } }));
147
+ const result = runCli(['--status'], { cwd: tmpProject, env: { HOME: tmpHome, ...NO_CI_ENV } });
148
+ assert.strictEqual(result.exitCode, 0);
149
+ assert.ok(result.stdout.includes('Disabled'));
150
+ assert.ok(result.stdout.includes('Global config'));
151
+ });
152
+ it('shows disabled when env var is set to 1', () => {
153
+ const result = runCli(['--status'], { cwd: tmpProject, env: { HOME: tmpHome, ...NO_CI_ENV, AWS_BLOCKS_DISABLE_TELEMETRY: '1' } });
154
+ assert.strictEqual(result.exitCode, 0);
155
+ assert.ok(result.stdout.includes('Disabled'));
156
+ assert.ok(result.stdout.includes('AWS_BLOCKS_DISABLE_TELEMETRY'));
157
+ });
158
+ it('any disable wins — project disabled even if global enabled', () => {
159
+ const globalConfigDir = join(tmpHome, '.blocks');
160
+ mkdirSync(globalConfigDir, { recursive: true });
161
+ writeFileSync(join(globalConfigDir, 'config.json'), JSON.stringify({ telemetry: { enabled: true } }));
162
+ const projectConfigDir = join(tmpProject, '.blocks');
163
+ mkdirSync(projectConfigDir, { recursive: true });
164
+ writeFileSync(join(projectConfigDir, 'config.json'), JSON.stringify({ telemetry: { enabled: false } }));
165
+ const result = runCli(['--status'], { cwd: tmpProject, env: { HOME: tmpHome, ...NO_CI_ENV } });
166
+ assert.strictEqual(result.exitCode, 0);
167
+ assert.ok(result.stdout.includes('Disabled'));
168
+ });
169
+ it('any disable wins — global disabled even if project enabled', () => {
170
+ const globalConfigDir = join(tmpHome, '.blocks');
171
+ mkdirSync(globalConfigDir, { recursive: true });
172
+ writeFileSync(join(globalConfigDir, 'config.json'), JSON.stringify({ telemetry: { enabled: false } }));
173
+ const projectConfigDir = join(tmpProject, '.blocks');
174
+ mkdirSync(projectConfigDir, { recursive: true });
175
+ writeFileSync(join(projectConfigDir, 'config.json'), JSON.stringify({ telemetry: { enabled: true } }));
176
+ const result = runCli(['--status'], { cwd: tmpProject, env: { HOME: tmpHome, ...NO_CI_ENV } });
177
+ assert.strictEqual(result.exitCode, 0);
178
+ assert.ok(result.stdout.includes('Disabled'));
179
+ });
180
+ });
181
+ describe('error handling', () => {
182
+ it('--enable and --disable together exits with error', () => {
183
+ const result = runCli(['--enable', '--disable'], { cwd: tmpProject, env: { HOME: tmpHome } });
184
+ assert.notStrictEqual(result.exitCode, 0);
185
+ assert.ok(result.stderr.includes('mutually exclusive'));
186
+ });
187
+ });
188
+ describe('unknown flags', () => {
189
+ it('warns about unrecognized flags but still exits 0', () => {
190
+ const result = runCli(['--statu'], { cwd: tmpProject, env: { HOME: tmpHome, ...NO_CI_ENV } });
191
+ assert.strictEqual(result.exitCode, 0);
192
+ assert.ok(result.stderr.includes('Unknown option') || result.stdout.includes('Unknown option'));
193
+ assert.ok(result.stderr.includes('--statu') || result.stdout.includes('--statu'));
194
+ });
195
+ it('recognized action still runs when unknown flags are present', () => {
196
+ const result = runCli(['--enable', '--typo'], { cwd: tmpProject, env: { HOME: tmpHome, ...NO_CI_ENV } });
197
+ assert.strictEqual(result.exitCode, 0);
198
+ assert.ok(result.stderr.includes('Unknown option') || result.stdout.includes('Unknown option'));
199
+ assert.ok(result.stderr.includes('--typo') || result.stdout.includes('--typo'));
200
+ assert.ok(result.stdout.includes('enabled for this project'));
201
+ });
202
+ });
203
+ });
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Validate a generated OpenRPC document for structural conformance.
3
+ *
4
+ * Checks:
5
+ * - Required top-level fields (openrpc, info, methods)
6
+ * - OpenRPC version format
7
+ * - Method structure (name, params, result)
8
+ * - Param structure (name, required, schema)
9
+ * - Result structure (name, schema)
10
+ * - All $ref pointers resolve to entries in components.schemas
11
+ * - No `nullable` field (should use oneOf with null instead)
12
+ * - Method names are namespace-qualified (contain a dot)
13
+ * - Result names are descriptive (not just "result")
14
+ *
15
+ * Returns an array of error messages. Empty array = valid.
16
+ */
17
+ export interface SpecValidationError {
18
+ path: string;
19
+ message: string;
20
+ }
21
+ export declare function validateSpec(doc: any): SpecValidationError[];
22
+ //# sourceMappingURL=validate-spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-spec.d.ts","sourceRoot":"","sources":["../../src/scripts/validate-spec.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,mBAAmB,EAAE,CA4J5D"}
@@ -0,0 +1,159 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export function validateSpec(doc) {
4
+ const errors = [];
5
+ // Top-level required fields
6
+ if (!doc || typeof doc !== 'object') {
7
+ return [{ path: '', message: 'Document must be an object' }];
8
+ }
9
+ if (typeof doc.openrpc !== 'string') {
10
+ errors.push({ path: 'openrpc', message: 'Missing or invalid "openrpc" version string' });
11
+ }
12
+ else if (!/^\d+\.\d+\.\d+$/.test(doc.openrpc)) {
13
+ errors.push({ path: 'openrpc', message: `Invalid version format: "${doc.openrpc}"` });
14
+ }
15
+ if (!doc.info || typeof doc.info !== 'object') {
16
+ errors.push({ path: 'info', message: 'Missing "info" object' });
17
+ }
18
+ else {
19
+ if (typeof doc.info.title !== 'string') {
20
+ errors.push({ path: 'info.title', message: 'Missing "info.title" string' });
21
+ }
22
+ if (typeof doc.info.version !== 'string') {
23
+ errors.push({ path: 'info.version', message: 'Missing "info.version" string' });
24
+ }
25
+ }
26
+ if (!Array.isArray(doc.methods)) {
27
+ errors.push({ path: 'methods', message: 'Missing "methods" array' });
28
+ return errors;
29
+ }
30
+ // Collect known schema names for $ref resolution
31
+ const knownSchemas = new Set(Object.keys(doc.components?.schemas || {}));
32
+ // Scan entire document for $ref pointers and nullable fields
33
+ const docStr = JSON.stringify(doc);
34
+ if (docStr.includes('"nullable"')) {
35
+ errors.push({
36
+ path: '',
37
+ message: 'Document contains "nullable" field — use oneOf with { type: "null" } instead',
38
+ });
39
+ }
40
+ // Validate each method
41
+ for (let i = 0; i < doc.methods.length; i++) {
42
+ const method = doc.methods[i];
43
+ const mp = `methods[${i}]`;
44
+ if (typeof method.name !== 'string') {
45
+ errors.push({ path: `${mp}.name`, message: 'Missing method name' });
46
+ continue;
47
+ }
48
+ const mpath = `methods["${method.name}"]`;
49
+ // Namespace-qualified check
50
+ if (!method.name.includes('.')) {
51
+ errors.push({ path: `${mpath}.name`, message: `Method name "${method.name}" is not namespace-qualified (expected "namespace.method")` });
52
+ }
53
+ // Params
54
+ if (!Array.isArray(method.params)) {
55
+ errors.push({ path: `${mpath}.params`, message: 'Missing "params" array' });
56
+ }
57
+ else {
58
+ for (let j = 0; j < method.params.length; j++) {
59
+ const param = method.params[j];
60
+ const pp = `${mpath}.params[${j}]`;
61
+ if (typeof param.name !== 'string') {
62
+ errors.push({ path: pp, message: 'Missing param name' });
63
+ }
64
+ if (typeof param.required !== 'boolean') {
65
+ errors.push({ path: `${pp}.required`, message: 'Missing or non-boolean "required"' });
66
+ }
67
+ if (!param.schema || typeof param.schema !== 'object') {
68
+ errors.push({ path: `${pp}.schema`, message: 'Missing param schema' });
69
+ }
70
+ // Check $ref resolution
71
+ if (param.schema?.$ref) {
72
+ validateRef(param.schema.$ref, `${pp}.schema.$ref`, knownSchemas, errors);
73
+ }
74
+ }
75
+ }
76
+ // Result
77
+ if (!method.result || typeof method.result !== 'object') {
78
+ errors.push({ path: `${mpath}.result`, message: 'Missing "result" object' });
79
+ }
80
+ else {
81
+ if (typeof method.result.name !== 'string') {
82
+ errors.push({ path: `${mpath}.result.name`, message: 'Missing result name' });
83
+ }
84
+ else if (method.result.name === 'result') {
85
+ errors.push({ path: `${mpath}.result.name`, message: 'Result name should be descriptive, not "result"' });
86
+ }
87
+ if (!method.result.schema || typeof method.result.schema !== 'object') {
88
+ errors.push({ path: `${mpath}.result.schema`, message: 'Missing result schema' });
89
+ }
90
+ // Check $ref resolution
91
+ if (method.result.schema?.$ref) {
92
+ validateRef(method.result.schema.$ref, `${mpath}.result.schema.$ref`, knownSchemas, errors);
93
+ }
94
+ // Check oneOf members for $refs
95
+ if (Array.isArray(method.result.schema?.oneOf)) {
96
+ for (let k = 0; k < method.result.schema.oneOf.length; k++) {
97
+ const member = method.result.schema.oneOf[k];
98
+ if (member.$ref) {
99
+ validateRef(member.$ref, `${mpath}.result.schema.oneOf[${k}].$ref`, knownSchemas, errors);
100
+ }
101
+ }
102
+ }
103
+ // Validate x-blocks-transferable extension field
104
+ if ('x-blocks-transferable' in (method.result.schema ?? {})) {
105
+ const blocksTag = method.result.schema['x-blocks-transferable'];
106
+ if (typeof blocksTag !== 'string' || blocksTag.length === 0) {
107
+ errors.push({
108
+ path: `${mpath}.result.schema.x-blocks-transferable`,
109
+ message: 'x-blocks-transferable must be a non-empty string',
110
+ });
111
+ }
112
+ }
113
+ // Validate x-blocks-type-args extension field
114
+ if ('x-blocks-type-args' in (method.result.schema ?? {})) {
115
+ const typeArgs = method.result.schema['x-blocks-type-args'];
116
+ if (!Array.isArray(typeArgs)) {
117
+ errors.push({
118
+ path: `${mpath}.result.schema.x-blocks-type-args`,
119
+ message: 'x-blocks-type-args must be an array of JSON Schema objects',
120
+ });
121
+ }
122
+ else {
123
+ for (let k = 0; k < typeArgs.length; k++) {
124
+ const arg = typeArgs[k];
125
+ if (!arg || typeof arg !== 'object' || Array.isArray(arg)) {
126
+ errors.push({
127
+ path: `${mpath}.result.schema.x-blocks-type-args[${k}]`,
128
+ message: 'Each entry in x-blocks-type-args must be a valid JSON Schema object',
129
+ });
130
+ }
131
+ else if (arg.$ref) {
132
+ validateRef(arg.$ref, `${mpath}.result.schema.x-blocks-type-args[${k}].$ref`, knownSchemas, errors);
133
+ }
134
+ }
135
+ }
136
+ }
137
+ }
138
+ }
139
+ // Validate components.schemas entries are well-formed
140
+ if (doc.components?.schemas) {
141
+ for (const [name, schema] of Object.entries(doc.components.schemas)) {
142
+ if (!schema || typeof schema !== 'object') {
143
+ errors.push({ path: `components.schemas.${name}`, message: 'Schema must be an object' });
144
+ }
145
+ }
146
+ }
147
+ return errors;
148
+ }
149
+ function validateRef(ref, path, knownSchemas, errors) {
150
+ const prefix = '#/components/schemas/';
151
+ if (!ref.startsWith(prefix)) {
152
+ errors.push({ path, message: `$ref "${ref}" must start with "${prefix}"` });
153
+ return;
154
+ }
155
+ const schemaName = ref.slice(prefix.length);
156
+ if (!knownSchemas.has(schemaName)) {
157
+ errors.push({ path, message: `$ref "${ref}" does not resolve — "${schemaName}" not found in components.schemas` });
158
+ }
159
+ }
@@ -0,0 +1,3 @@
1
+ export { withAuth, registerCookieProvider, clearCookieProviders } from './withAuth.js';
2
+ export type { CookieProvider } from './withAuth.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACvF,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,3 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export { withAuth, registerCookieProvider, clearCookieProviders } from './withAuth.js';
@@ -0,0 +1,142 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+ declare global {
3
+ var __BLOCKS_REQUEST_COOKIES_STORE__: AsyncLocalStorage<string> | undefined;
4
+ }
5
+ /**
6
+ * A function that attempts to detect cookies from a specific framework's
7
+ * request context. Returns the cookie string if available, or `undefined`
8
+ * if the framework is not active or no cookies are present.
9
+ */
10
+ export type CookieProvider = () => Promise<string | undefined>;
11
+ /**
12
+ * Register a framework-specific cookie provider for `withAuth()`.
13
+ *
14
+ * Providers are tried in registration order when `withAuth()` is called
15
+ * without explicit cookies. The first provider that returns a non-undefined
16
+ * value wins.
17
+ *
18
+ * Two providers are registered by default:
19
+ *
20
+ * - **Next.js** — reads cookies from `next/headers`. Works out of the box.
21
+ * - **Nuxt/Nitro** — reads cookies from the active Nitro request event
22
+ * (via the `unctx` `'nitro-app'` async context). Requires
23
+ * `nitro.experimental.asyncContext: true` in `nuxt.config.ts` so Nitro
24
+ * wraps each request in an `AsyncLocalStorage` context. Without that
25
+ * flag the provider returns `undefined` and a warning is emitted on
26
+ * first miss to point at the missing config (see `withAuth` for the
27
+ * no-cookies error path).
28
+ *
29
+ * Use this to add support for additional frameworks (SvelteKit, Astro, etc.)
30
+ * or custom cookie sources.
31
+ *
32
+ * @param name - Human-readable provider name (for debugging).
33
+ * @param detect - Async function that returns a cookie string or `undefined`.
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * import { registerCookieProvider } from '@aws-blocks/blocks/server';
38
+ *
39
+ * // SvelteKit provider
40
+ * registerCookieProvider('sveltekit', async () => {
41
+ * try {
42
+ * const { getRequestEvent } = await import('$app/server');
43
+ * const event = getRequestEvent();
44
+ * return event?.request.headers.get('cookie') ?? undefined;
45
+ * } catch {
46
+ * return undefined;
47
+ * }
48
+ * });
49
+ * ```
50
+ */
51
+ export declare function registerCookieProvider(name: string, detect: CookieProvider): void;
52
+ /**
53
+ * Clear all registered cookie providers, including the built-in Next.js one.
54
+ *
55
+ * Primarily useful for testing. After calling this, you must re-register any
56
+ * providers you need (including Next.js if desired).
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * import { clearCookieProviders, registerCookieProvider } from '@aws-blocks/blocks/server';
61
+ *
62
+ * // In test setup
63
+ * clearCookieProviders();
64
+ * registerCookieProvider('test', async () => 'session=test');
65
+ * ```
66
+ */
67
+ export declare function clearCookieProviders(): void;
68
+ /** @internal Read-only view of registered providers (for testing). */
69
+ export declare function _getProviders(): ReadonlyArray<{
70
+ name: string;
71
+ detect: CookieProvider;
72
+ }>;
73
+ /**
74
+ * Wraps an async function with authenticated cookie forwarding for SSR.
75
+ *
76
+ * In SSR server components, browser cookies aren't automatically forwarded
77
+ * to API calls. This wrapper reads cookies and makes them available to
78
+ * all Blocks API calls within the callback via `AsyncLocalStorage`.
79
+ *
80
+ * **Resolution order:**
81
+ * 1. Explicit `cookies` parameter (framework-agnostic)
82
+ * 2. Existing request context (Lambda handler already set it up)
83
+ * 3. Registered cookie providers — Next.js and Nuxt are built-in, plus any
84
+ * you've added via `registerCookieProvider`
85
+ * 4. Throws if no cookies found
86
+ *
87
+ * **Built-in providers:**
88
+ *
89
+ * | Framework | Source | Notes |
90
+ * |-----------|--------|-------|
91
+ * | Next.js | `next/headers` | Works out of the box. |
92
+ * | Nuxt/Nitro | Nitro async context (via `unctx`) | Requires `nitro: { experimental: { asyncContext: true } }` in `nuxt.config.ts`. With the flag off the provider returns `undefined` and emits a one-time warning naming the missing config. |
93
+ *
94
+ * @param fn - Async function containing Blocks API calls that need auth.
95
+ * @param cookies - Optional explicit cookie string. If omitted, auto-detects
96
+ * from the request context or registered providers. Pass this for frameworks
97
+ * without a registered provider (or use `registerCookieProvider` to add one).
98
+ * @returns The return value of `fn`.
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * // Next.js — auto-detects cookies from next/headers (built-in provider)
103
+ * import { withAuth } from '@aws-blocks/blocks/server';
104
+ *
105
+ * const posts = await withAuth(() => api.listMyPosts());
106
+ *
107
+ * // Multiple calls in one scope
108
+ * const data = await withAuth(async () => {
109
+ * const posts = await api.listMyPosts();
110
+ * const profile = await api.getProfile();
111
+ * return { posts, profile };
112
+ * });
113
+ *
114
+ * // Explicit cookies for any framework
115
+ * const posts = await withAuth(
116
+ * () => api.listMyPosts(),
117
+ * request.headers.get('cookie'),
118
+ * );
119
+ * ```
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * // Nuxt — auto-detects cookies via the active Nitro request event
124
+ * // (built-in provider). Requires the experimental.asyncContext flag.
125
+ * //
126
+ * // nuxt.config.ts
127
+ * // export default defineNuxtConfig({
128
+ * // nitro: { experimental: { asyncContext: true } },
129
+ * // });
130
+ * //
131
+ * // server/api/posts.get.ts
132
+ * import { withAuth } from '@aws-blocks/blocks/server';
133
+ *
134
+ * export default defineEventHandler(async () => {
135
+ * return withAuth(() => api.listMyPosts());
136
+ * });
137
+ * ```
138
+ *
139
+ * @throws {Error} If no cookies are found and no provider detected them.
140
+ */
141
+ export declare function withAuth<T>(fn: () => Promise<T>, cookies?: string | null): Promise<T>;
142
+ //# sourceMappingURL=withAuth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withAuth.d.ts","sourceRoot":"","sources":["../../src/server/withAuth.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAIrD,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,gCAAgC,EAAE,iBAAiB,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;CAC7E;AA+BD;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;AAI/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI,CAOjF;AA0GD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAED,sEAAsE;AACtE,wBAAgB,aAAa,IAAI,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,cAAc,CAAA;CAAE,CAAC,CAEvF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAC9B,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACtB,OAAO,CAAC,CAAC,CAAC,CAyBZ"}