@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
package/dist/redact.js ADDED
@@ -0,0 +1,134 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * Sensitive-field redaction for logging.
5
+ *
6
+ * The dev server logs RPC request/response bodies to help debug cross-stack
7
+ * wire-format mismatches. Those bodies carry credentials (sign-in passwords,
8
+ * new-password challenge responses) and bearer-style secrets (Cognito challenge
9
+ * `session` tokens, MFA shared secrets, OTP codes). Logging them verbatim puts
10
+ * plaintext passwords and reusable tokens in the log stream. This module masks
11
+ * those fields before anything is logged, without mutating the value that
12
+ * actually flows over the wire.
13
+ *
14
+ * Two complementary rules, because auth payloads hide secrets two ways:
15
+ *
16
+ * 1. **Direct keys** — `{ password: '...', session: '...' }`. Redacted by
17
+ * field NAME, matched case-insensitively (substring).
18
+ *
19
+ * 2. **Form-field descriptors** — the auth state machine ships secrets as
20
+ * `{ name: 'session', defaultValue: '<token>' }` (see
21
+ * `@aws-blocks/auth-common` AuthField). Here the secret sits under the
22
+ * innocuous key `defaultValue`; the sensitive word is the *value* of a
23
+ * sibling `name`. Rule 1 alone would walk straight past it. So when an
24
+ * object carries a sensitive `name`, its `defaultValue` is redacted too.
25
+ *
26
+ * The wire payload is never altered — only the logged copy is scrubbed.
27
+ */
28
+ /** The string substituted for any sensitive value. */
29
+ export const REDACTED = '[REDACTED]';
30
+ /**
31
+ * Field-name fragments whose values must never be logged. Matched
32
+ * case-insensitively as a SUBSTRING, so prefixed/suffixed variants
33
+ * (`accessToken`, `refreshToken`, `idToken`, `apiKey`, `clientSecret`) all
34
+ * match without enumerating every spelling. Keep aligned with the auth action
35
+ * payloads in `@aws-blocks/auth-common` plus the generic credential vocabulary.
36
+ */
37
+ const SENSITIVE_KEY_PARTS = [
38
+ 'password',
39
+ 'session',
40
+ 'token',
41
+ 'secret',
42
+ 'credential',
43
+ 'apikey',
44
+ 'authorization',
45
+ ];
46
+ /**
47
+ * Field names that are sensitive only as an EXACT match. The OTP / verification
48
+ * code the auth state machine sends is literally named `code` (see
49
+ * `@aws-blocks/auth-common` confirmSignIn payloads). Matching it as a substring
50
+ * would mask innocuous fields like `statusCode`, `errorCode`, `countryCode`,
51
+ * `zipCode`, `qrCode` — log noise that defeats the debugging purpose of these
52
+ * logs without protecting anything. So `code` is exact-match only.
53
+ */
54
+ const SENSITIVE_KEY_EXACT = new Set(['code']);
55
+ /**
56
+ * Whether a field name should be redacted: an exact-match against
57
+ * {@link SENSITIVE_KEY_EXACT}, or a case-insensitive substring match against
58
+ * {@link SENSITIVE_KEY_PARTS}.
59
+ */
60
+ function isSensitiveKey(key) {
61
+ const lower = key.toLowerCase();
62
+ if (SENSITIVE_KEY_EXACT.has(lower))
63
+ return true;
64
+ return SENSITIVE_KEY_PARTS.some((part) => lower.includes(part));
65
+ }
66
+ /**
67
+ * Return a deep copy of `value` with the value of every sensitive field
68
+ * replaced by {@link REDACTED}. Arrays and nested objects are walked; the
69
+ * input is never mutated. Circular references are emitted as `'[Circular]'`.
70
+ *
71
+ * Primitives are returned unchanged — only object/array *fields* are matched
72
+ * against the sensitive-key list, since a bare string has no field name to
73
+ * key off.
74
+ *
75
+ * `seen` tracks the current ancestor PATH, not every node ever visited: each
76
+ * node is added before its children are walked and removed afterwards. A
77
+ * plain visited-set would flag the second appearance of a *shared* (non-cyclic)
78
+ * reference as `'[Circular]'` — e.g. `{ a: shared, b: shared }` — silently
79
+ * dropping real data from the log. Only a reference still open on the stack is
80
+ * a genuine cycle.
81
+ */
82
+ export function redactForLogging(value, seen = new WeakSet()) {
83
+ if (value === null || typeof value !== 'object') {
84
+ return value;
85
+ }
86
+ if (seen.has(value)) {
87
+ return '[Circular]';
88
+ }
89
+ seen.add(value);
90
+ let out;
91
+ if (Array.isArray(value)) {
92
+ out = value.map((item) => redactForLogging(item, seen));
93
+ }
94
+ else {
95
+ const obj = value;
96
+ // Rule 2: form-field descriptor `{ name: <sensitive>, defaultValue: <secret> }`.
97
+ // The secret hides under `defaultValue` while the sensitive word is the value
98
+ // of `name` — so the direct-key pass below never sees it. Detect the shape and
99
+ // redact `defaultValue` explicitly.
100
+ const masksDefaultValue = typeof obj.name === 'string'
101
+ && isSensitiveKey(obj.name)
102
+ && 'defaultValue' in obj;
103
+ const result = {};
104
+ for (const [key, val] of Object.entries(obj)) {
105
+ if (isSensitiveKey(key) || (key === 'defaultValue' && masksDefaultValue)) {
106
+ // Preserve presence/absence so logs still show the field was sent,
107
+ // without revealing it. Skip masking explicit null/undefined so an
108
+ // absent secret doesn't look like a populated one.
109
+ result[key] = val === null || val === undefined ? val : REDACTED;
110
+ }
111
+ else {
112
+ result[key] = redactForLogging(val, seen);
113
+ }
114
+ }
115
+ out = result;
116
+ }
117
+ // Pop this node off the ancestor path now that its subtree is fully walked,
118
+ // so sibling branches can reference the same object without false `[Circular]`.
119
+ seen.delete(value);
120
+ return out;
121
+ }
122
+ /**
123
+ * Convenience for log call sites: redact `value` and serialize it to a JSON
124
+ * string. Returns a safe placeholder instead of throwing if serialization
125
+ * fails (e.g. a BigInt slips through), so logging can never crash a request.
126
+ */
127
+ export function redactToJson(value) {
128
+ try {
129
+ return JSON.stringify(redactForLogging(value));
130
+ }
131
+ catch {
132
+ return '[unserializable]';
133
+ }
134
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=redact.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redact.test.d.ts","sourceRoot":"","sources":["../src/redact.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,199 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { describe, it } from 'node:test';
4
+ import assert from 'node:assert';
5
+ import { redactForLogging, redactToJson, REDACTED } from './redact.js';
6
+ describe('redactForLogging', () => {
7
+ it('redacts a top-level password field', () => {
8
+ const out = redactForLogging({ username: 'alice', password: 'hunter2' });
9
+ assert.deepEqual(out, { username: 'alice', password: REDACTED });
10
+ });
11
+ it('redacts every sensitive credential/token field name', () => {
12
+ const out = redactForLogging({
13
+ password: 'p',
14
+ newPassword: 'np',
15
+ session: 's',
16
+ accessToken: 'at',
17
+ refreshToken: 'rt',
18
+ idToken: 'it',
19
+ sharedSecret: 'ss',
20
+ clientSecret: 'cs',
21
+ apiKey: 'ak',
22
+ authorization: 'Bearer x',
23
+ code: '123456',
24
+ credentials: 'c',
25
+ });
26
+ for (const v of Object.values(out)) {
27
+ assert.equal(v, REDACTED);
28
+ }
29
+ });
30
+ it('matches field names case-insensitively', () => {
31
+ const out = redactForLogging({ PassWord: 'x', SESSION: 'y' });
32
+ assert.equal(out.PassWord, REDACTED);
33
+ assert.equal(out.SESSION, REDACTED);
34
+ });
35
+ it('leaves non-sensitive fields untouched', () => {
36
+ const input = { username: 'bob', email: 'b@example.com', count: 3, ok: true };
37
+ assert.deepEqual(redactForLogging(input), input);
38
+ });
39
+ it('walks nested objects', () => {
40
+ const out = redactForLogging({
41
+ action: 'confirmSignIn',
42
+ payload: { session: 'tok', code: '999' },
43
+ });
44
+ assert.deepEqual(out, {
45
+ action: 'confirmSignIn',
46
+ payload: { session: REDACTED, code: REDACTED },
47
+ });
48
+ });
49
+ it('walks arrays (e.g. positional RPC args)', () => {
50
+ const out = redactForLogging([
51
+ { action: 'signIn', username: 'a', password: 'secret' },
52
+ { action: 'confirmSignIn', session: 'tok', code: '111' },
53
+ ]);
54
+ assert.deepEqual(out, [
55
+ { action: 'signIn', username: 'a', password: REDACTED },
56
+ { action: 'confirmSignIn', session: REDACTED, code: REDACTED },
57
+ ]);
58
+ });
59
+ it('preserves null/undefined sensitive fields without masking', () => {
60
+ const out = redactForLogging({ password: null, session: undefined });
61
+ assert.equal(out.password, null);
62
+ assert.equal(out.session, undefined);
63
+ });
64
+ it('returns primitives unchanged', () => {
65
+ assert.equal(redactForLogging('just a string'), 'just a string');
66
+ assert.equal(redactForLogging(42), 42);
67
+ assert.equal(redactForLogging(null), null);
68
+ });
69
+ it('does not mutate the input object', () => {
70
+ const input = { password: 'keep-me', username: 'alice' };
71
+ redactForLogging(input);
72
+ assert.equal(input.password, 'keep-me');
73
+ });
74
+ // Regression: the auth state machine ships secrets as form-field
75
+ // descriptors `{ name: 'session', defaultValue: '<token>' }`. The secret
76
+ // sits under `defaultValue`, NOT under a key literally named `session`, so
77
+ // plain key-name redaction walks past it. These guard the descriptor branch.
78
+ it('redacts defaultValue of a sensitive AuthField descriptor', () => {
79
+ const out = redactForLogging({
80
+ name: 'session',
81
+ label: 'Session',
82
+ type: 'hidden',
83
+ defaultValue: 'COGNITO_SESSION_TOKEN',
84
+ });
85
+ assert.equal(out.name, 'session');
86
+ assert.equal(out.defaultValue, REDACTED);
87
+ });
88
+ it('redacts session + sharedSecret in a full confirmingSignIn AuthState', () => {
89
+ const authState = {
90
+ state: 'confirmingSignIn',
91
+ actions: [{
92
+ name: 'confirmSignIn',
93
+ label: 'Set Up Authenticator',
94
+ fields: [
95
+ { name: 'session', label: 'Session', type: 'hidden', required: true, defaultValue: 'SESSION_TOKEN_abc' },
96
+ { name: 'sharedSecret', label: 'Shared Secret', type: 'hidden', required: true, defaultValue: 'JBSWY3DPEHPK3PXP' },
97
+ { name: 'code', label: 'Code', type: 'text', required: true },
98
+ ],
99
+ }],
100
+ };
101
+ const json = JSON.stringify(redactForLogging(authState));
102
+ assert.ok(!json.includes('SESSION_TOKEN_abc'), 'session token must not leak');
103
+ assert.ok(!json.includes('JBSWY3DPEHPK3PXP'), 'TOTP shared secret must not leak');
104
+ // Non-secret descriptor fields are preserved for debuggability.
105
+ assert.ok(json.includes('confirmSignIn'));
106
+ assert.ok(json.includes('Set Up Authenticator'));
107
+ });
108
+ it('leaves defaultValue untouched for a non-sensitive field (e.g. echoed username)', () => {
109
+ const out = redactForLogging({
110
+ name: 'username',
111
+ type: 'hidden',
112
+ defaultValue: 'alice',
113
+ });
114
+ assert.equal(out.defaultValue, 'alice');
115
+ });
116
+ it('handles circular references', () => {
117
+ const a = { username: 'alice' };
118
+ a.self = a;
119
+ const out = redactForLogging(a);
120
+ assert.equal(out.username, 'alice');
121
+ assert.equal(out.self, '[Circular]');
122
+ });
123
+ it('detects cycles nested deeper than the root', () => {
124
+ const root = { level: 1 };
125
+ const child = { level: 2, parent: root };
126
+ root.child = child;
127
+ const out = redactForLogging(root);
128
+ assert.equal(out.child.level, 2);
129
+ assert.equal(out.child.parent, '[Circular]');
130
+ });
131
+ // Regression: `seen` must track the ancestor PATH, not every node ever
132
+ // visited. A shared (non-cyclic) reference reached twice via sibling
133
+ // branches must be emitted in full both times — a visited-set would wrongly
134
+ // flag the second one as '[Circular]' and drop real data from the log.
135
+ it('does not flag shared (non-circular) references as circular', () => {
136
+ const shared = { region: 'us-east-1', count: 2 };
137
+ const out = redactForLogging({ a: shared, b: shared });
138
+ assert.deepEqual(out.a, shared);
139
+ assert.deepEqual(out.b, shared);
140
+ });
141
+ it('emits a shared reference repeated in an array, not [Circular]', () => {
142
+ const shared = { id: 'x' };
143
+ const out = redactForLogging([shared, shared, shared]);
144
+ assert.deepEqual(out, [shared, shared, shared]);
145
+ });
146
+ it('still redacts secrets inside a shared reference each time', () => {
147
+ const shared = { username: 'u', password: 'secret' };
148
+ const out = redactForLogging({ first: shared, second: shared });
149
+ assert.equal(out.first.password, REDACTED);
150
+ assert.equal(out.second.password, REDACTED);
151
+ assert.equal(out.second.username, 'u');
152
+ });
153
+ // Regression: `code` is exact-match only, so substring siblings like
154
+ // statusCode/errorCode stay visible — they carry no secret and masking them
155
+ // defeats the debugging purpose of the logs.
156
+ it('redacts an exact `code` field but not `code`-substring fields', () => {
157
+ const out = redactForLogging({
158
+ code: '123456',
159
+ statusCode: 200,
160
+ errorCode: 'E_BAD',
161
+ countryCode: 'US',
162
+ zipCode: '98101',
163
+ qrCode: 'data:image/png',
164
+ });
165
+ assert.equal(out.code, REDACTED);
166
+ assert.equal(out.statusCode, 200);
167
+ assert.equal(out.errorCode, 'E_BAD');
168
+ assert.equal(out.countryCode, 'US');
169
+ assert.equal(out.zipCode, '98101');
170
+ assert.equal(out.qrCode, 'data:image/png');
171
+ });
172
+ });
173
+ describe('redactToJson', () => {
174
+ it('serializes a redacted copy', () => {
175
+ const json = redactToJson({ username: 'alice', password: 'hunter2' });
176
+ assert.equal(json, JSON.stringify({ username: 'alice', password: REDACTED }));
177
+ });
178
+ it('returns a safe placeholder on serialization failure', () => {
179
+ // BigInt is not JSON-serializable and survives redaction (not a sensitive key).
180
+ assert.equal(redactToJson({ big: 10n }), '[unserializable]');
181
+ });
182
+ it('does not leak secrets even when truncation would apply downstream', () => {
183
+ const json = redactToJson([{ action: 'signIn', username: 'u', password: 'p'.repeat(50) }]);
184
+ assert.ok(!json.includes('pppp'));
185
+ assert.ok(json.includes(REDACTED));
186
+ });
187
+ it('redacts secrets in a real JSON-RPC request body shape', () => {
188
+ const body = {
189
+ jsonrpc: '2.0',
190
+ method: 'authApi.setAuthState',
191
+ params: [{ action: 'signIn', username: 'a', password: 'hunter2' }],
192
+ id: 1,
193
+ };
194
+ const json = redactToJson(body);
195
+ assert.ok(!json.includes('hunter2'));
196
+ assert.ok(json.includes(REDACTED));
197
+ assert.ok(json.includes('setAuthState'), 'method name preserved for debugging');
198
+ });
199
+ });
package/dist/rpc.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ /** The pieces every server-side handler needs after parsing a request. */
2
+ export interface RpcParsedRequest {
3
+ apiNamespace: string;
4
+ method: string;
5
+ /** Positional args — from array params directly, or Object.values() of named params. */
6
+ args: unknown[];
7
+ id: string | number | null;
8
+ }
9
+ /** Discriminated union returned by `parseRpcRequest`. */
10
+ export type RpcParseResult = {
11
+ ok: true;
12
+ request: RpcParsedRequest;
13
+ } | {
14
+ ok: false;
15
+ response: string;
16
+ };
17
+ /** Reserved JSON-RPC error codes. */
18
+ export declare const RpcErrorCode: {
19
+ readonly ParseError: -32700;
20
+ readonly InvalidRequest: -32600;
21
+ readonly MethodNotFound: -32601;
22
+ readonly InvalidParams: -32602;
23
+ readonly InternalError: -32603;
24
+ };
25
+ /** Build a JSON-RPC 2.0 request body string ready to POST. */
26
+ export declare function encodeRpcRequest(apiNamespace: string, method: string, args: unknown[]): string;
27
+ /**
28
+ * Decode a JSON-RPC 2.0 response body.
29
+ *
30
+ * Returns the `result` on success, or throws an `ApiError` on error.
31
+ */
32
+ export declare function decodeRpcResponse(body: unknown): unknown;
33
+ /**
34
+ * Parse a raw body string into a validated `RpcParsedRequest`.
35
+ *
36
+ * Returns `{ ok: false, response }` with a ready-to-send JSON string when
37
+ * the request is malformed, so callers can short-circuit without knowing
38
+ * anything about the JSON-RPC spec.
39
+ */
40
+ export declare function parseRpcRequest(bodyText: string): RpcParseResult;
41
+ /** Encode a successful result as a JSON-RPC 2.0 response string. */
42
+ export declare function successResponse(result: unknown, id: string | number | null): string;
43
+ /**
44
+ * Encode an error as a JSON-RPC 2.0 response string.
45
+ *
46
+ * For `ApiError` instances the HTTP status becomes the error code (positive
47
+ * integers never collide with the reserved -32xxx range). Generic errors
48
+ * use code 500.
49
+ */
50
+ export declare function errorResponseFromCatch(error: unknown, id: string | number | null): string;
51
+ /** Encode a "method not found" error. */
52
+ export declare function methodNotFoundResponse(detail: string, id: string | number | null): string;
53
+ export declare function errorResponse(code: number, message: string, id: string | number | null, data?: Record<string, unknown>): string;
54
+ //# sourceMappingURL=rpc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AAgBA,0EAA0E;AAC1E,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,wFAAwF;IACxF,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,yDAAyD;AACzD,MAAM,MAAM,cAAc,GACtB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,gBAAgB,CAAA;CAAE,GACvC;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAMpC,qCAAqC;AACrC,eAAO,MAAM,YAAY;;;;;;CAMf,CAAC;AAMX,8DAA8D;AAC9D,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAO9F;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAiBxD;AAID;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CA0ChE;AAED,oEAAoE;AACpE,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,CAEnF;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,CAOzF;AAED,yCAAyC;AACzC,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,CAEzF;AAID,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAC1B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,MAAM,CAMR"}
package/dist/rpc.js ADDED
@@ -0,0 +1,127 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * JSON-RPC 2.0 wire format — single source of truth.
5
+ *
6
+ * All encoding/decoding of the Blocks RPC protocol lives here so that the
7
+ * client, Lambda handler, and dev server never deal with the spec directly.
8
+ *
9
+ * @see https://www.jsonrpc.org/specification
10
+ */
11
+ import { ApiError } from './errors.js';
12
+ // ── Constants ───────────────────────────────────────────────────────────────
13
+ const VERSION = '2.0';
14
+ /** Reserved JSON-RPC error codes. */
15
+ export const RpcErrorCode = {
16
+ ParseError: -32700,
17
+ InvalidRequest: -32600,
18
+ MethodNotFound: -32601,
19
+ InvalidParams: -32602,
20
+ InternalError: -32603,
21
+ };
22
+ // ── Client helpers (encode request, decode response) ────────────────────────
23
+ let _nextId = 1;
24
+ /** Build a JSON-RPC 2.0 request body string ready to POST. */
25
+ export function encodeRpcRequest(apiNamespace, method, args) {
26
+ return JSON.stringify({
27
+ jsonrpc: VERSION,
28
+ method: `${apiNamespace}.${method}`,
29
+ params: args,
30
+ id: _nextId++,
31
+ });
32
+ }
33
+ /**
34
+ * Decode a JSON-RPC 2.0 response body.
35
+ *
36
+ * Returns the `result` on success, or throws an `ApiError` on error.
37
+ */
38
+ export function decodeRpcResponse(body) {
39
+ const rpc = body;
40
+ if (rpc.error) {
41
+ const { code, message, data } = rpc.error;
42
+ // Application error codes use the HTTP status directly (e.g. 409).
43
+ // Reserved JSON-RPC codes (-32xxx) map to 500.
44
+ const status = code > 0 ? code : 500;
45
+ throw new ApiError(message, status, {
46
+ ...(data?.name ? { name: data.name } : {}),
47
+ ...(data?.retriable === true ? { retriable: true } : {}),
48
+ });
49
+ }
50
+ return rpc.result;
51
+ }
52
+ // ── Server helpers (parse request, encode response) ─────────────────────────
53
+ /**
54
+ * Parse a raw body string into a validated `RpcParsedRequest`.
55
+ *
56
+ * Returns `{ ok: false, response }` with a ready-to-send JSON string when
57
+ * the request is malformed, so callers can short-circuit without knowing
58
+ * anything about the JSON-RPC spec.
59
+ */
60
+ export function parseRpcRequest(bodyText) {
61
+ let parsed;
62
+ try {
63
+ parsed = JSON.parse(bodyText || '{}');
64
+ }
65
+ catch {
66
+ return { ok: false, response: errorResponse(RpcErrorCode.ParseError, 'Parse error', null) };
67
+ }
68
+ const id = parsed.id ?? null;
69
+ if (parsed.jsonrpc !== VERSION || typeof parsed.method !== 'string') {
70
+ return {
71
+ ok: false,
72
+ response: errorResponse(RpcErrorCode.InvalidRequest, 'Invalid Request: expected JSON-RPC 2.0 — {"jsonrpc":"2.0","method":"namespace.method","params":[...],"id":1}', id, { name: 'InvalidRequest' }),
73
+ };
74
+ }
75
+ const dotIndex = parsed.method.indexOf('.');
76
+ if (dotIndex === -1) {
77
+ return {
78
+ ok: false,
79
+ response: errorResponse(RpcErrorCode.InvalidRequest, 'Invalid Request: method must be "namespace.method"', id, { name: 'InvalidRequest' }),
80
+ };
81
+ }
82
+ return {
83
+ ok: true,
84
+ request: {
85
+ apiNamespace: parsed.method.substring(0, dotIndex),
86
+ method: parsed.method.substring(dotIndex + 1),
87
+ // JSON-RPC 2.0 §4.2: params may be an array (positional) or object (named).
88
+ args: Array.isArray(parsed.params)
89
+ ? parsed.params
90
+ : Object.values(parsed.params ?? {}),
91
+ id,
92
+ },
93
+ };
94
+ }
95
+ /** Encode a successful result as a JSON-RPC 2.0 response string. */
96
+ export function successResponse(result, id) {
97
+ return JSON.stringify({ jsonrpc: VERSION, result, id });
98
+ }
99
+ /**
100
+ * Encode an error as a JSON-RPC 2.0 response string.
101
+ *
102
+ * For `ApiError` instances the HTTP status becomes the error code (positive
103
+ * integers never collide with the reserved -32xxx range). Generic errors
104
+ * use code 500.
105
+ */
106
+ export function errorResponseFromCatch(error, id) {
107
+ const code = error instanceof ApiError ? error.status : 500;
108
+ const message = error instanceof Error ? error.message : String(error);
109
+ const data = {};
110
+ if (error instanceof Error && error.name && error.name !== 'Error')
111
+ data.name = error.name;
112
+ if (error instanceof ApiError && error.retriable)
113
+ data.retriable = true;
114
+ return errorResponse(code, message, id, Object.keys(data).length > 0 ? data : undefined);
115
+ }
116
+ /** Encode a "method not found" error. */
117
+ export function methodNotFoundResponse(detail, id) {
118
+ return errorResponse(RpcErrorCode.MethodNotFound, `Method not found: ${detail}`, id);
119
+ }
120
+ // ── Internal ────────────────────────────────────────────────────────────────
121
+ export function errorResponse(code, message, id, data) {
122
+ return JSON.stringify({
123
+ jsonrpc: VERSION,
124
+ error: { code, message, ...(data ? { data } : {}) },
125
+ id,
126
+ });
127
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=rpc.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc.test.d.ts","sourceRoot":"","sources":["../src/rpc.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,60 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { describe, it } from 'node:test';
4
+ import assert from 'node:assert';
5
+ import { parseRpcRequest, RpcErrorCode } from './rpc.js';
6
+ describe('-32600 Invalid Request error shape', () => {
7
+ it('returns proper JSON-RPC 2.0 envelope with error code', () => {
8
+ const result = parseRpcRequest(JSON.stringify({ method: 'ns.method', id: 1 }));
9
+ assert.strictEqual(result.ok, false);
10
+ if (!result.ok) {
11
+ const parsed = JSON.parse(result.response);
12
+ assert.strictEqual(parsed.jsonrpc, '2.0');
13
+ assert.strictEqual(parsed.error.code, RpcErrorCode.InvalidRequest);
14
+ assert.strictEqual(parsed.id, 1);
15
+ }
16
+ });
17
+ it('includes descriptive message with expected JSON-RPC 2.0 shape', () => {
18
+ const result = parseRpcRequest(JSON.stringify({ method: 'test', id: 1 }));
19
+ assert.strictEqual(result.ok, false);
20
+ if (!result.ok) {
21
+ const parsed = JSON.parse(result.response);
22
+ assert.ok(parsed.error.message.includes('expected JSON-RPC 2.0'), `message should describe the expected format, got: ${parsed.error.message}`);
23
+ assert.ok(parsed.error.message.includes('"jsonrpc":"2.0"'), `message should echo the expected envelope shape`);
24
+ }
25
+ });
26
+ it('includes data.name per D-003 convention', () => {
27
+ const result = parseRpcRequest(JSON.stringify({ method: 'test', id: 1 }));
28
+ assert.strictEqual(result.ok, false);
29
+ if (!result.ok) {
30
+ const parsed = JSON.parse(result.response);
31
+ assert.strictEqual(parsed.error.data.name, 'InvalidRequest');
32
+ }
33
+ });
34
+ it('preserves the caller id in the error response', () => {
35
+ const result = parseRpcRequest(JSON.stringify({ id: 'abc-123' }));
36
+ assert.strictEqual(result.ok, false);
37
+ if (!result.ok) {
38
+ const parsed = JSON.parse(result.response);
39
+ assert.strictEqual(parsed.id, 'abc-123');
40
+ }
41
+ });
42
+ it('uses null id when request omits id', () => {
43
+ const result = parseRpcRequest(JSON.stringify({ jsonrpc: '1.0', method: 123 }));
44
+ assert.strictEqual(result.ok, false);
45
+ if (!result.ok) {
46
+ const parsed = JSON.parse(result.response);
47
+ assert.strictEqual(parsed.id, null);
48
+ }
49
+ });
50
+ it('includes data.name when method lacks namespace dot separator', () => {
51
+ const result = parseRpcRequest(JSON.stringify({ jsonrpc: '2.0', method: 'noNamespace', id: 7 }));
52
+ assert.strictEqual(result.ok, false);
53
+ if (!result.ok) {
54
+ const parsed = JSON.parse(result.response);
55
+ assert.strictEqual(parsed.error.code, RpcErrorCode.InvalidRequest);
56
+ assert.strictEqual(parsed.error.data.name, 'InvalidRequest');
57
+ assert.strictEqual(parsed.id, 7);
58
+ }
59
+ });
60
+ });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Build CDK CLI telemetry-related environment variables.
3
+ *
4
+ * When Blocks telemetry is enabled, sets `CDK_CLI_USERAGENT` so the CDK CLI
5
+ * attributes usage back to Blocks. When telemetry is disabled (user opted out),
6
+ * sets `CDK_DISABLE_CLI_TELEMETRY=1` to suppress CDK's own telemetry collection
7
+ * and omits the user-agent string.
8
+ *
9
+ * @param command - The Blocks command context (e.g. "sandbox", "production")
10
+ * @returns An object to spread into the child process `env`
11
+ */
12
+ export declare function getCdkTelemetryEnv(command: string): Record<string, string>;
13
+ //# sourceMappingURL=cdk-telemetry-env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cdk-telemetry-env.d.ts","sourceRoot":"","sources":["../../src/scripts/cdk-telemetry-env.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAK1E"}
@@ -0,0 +1,21 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { isTelemetryEnabled } from '../telemetry/consent.js';
4
+ import { CORE_VERSION } from '../version.js';
5
+ /**
6
+ * Build CDK CLI telemetry-related environment variables.
7
+ *
8
+ * When Blocks telemetry is enabled, sets `CDK_CLI_USERAGENT` so the CDK CLI
9
+ * attributes usage back to Blocks. When telemetry is disabled (user opted out),
10
+ * sets `CDK_DISABLE_CLI_TELEMETRY=1` to suppress CDK's own telemetry collection
11
+ * and omits the user-agent string.
12
+ *
13
+ * @param command - The Blocks command context (e.g. "sandbox", "production")
14
+ * @returns An object to spread into the child process `env`
15
+ */
16
+ export function getCdkTelemetryEnv(command) {
17
+ if (!isTelemetryEnabled()) {
18
+ return { CDK_DISABLE_CLI_TELEMETRY: '1' };
19
+ }
20
+ return { CDK_CLI_USERAGENT: `aws-blocks/${CORE_VERSION}/${command}` };
21
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=cdk-telemetry-env.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cdk-telemetry-env.test.d.ts","sourceRoot":"","sources":["../../src/scripts/cdk-telemetry-env.test.ts"],"names":[],"mappings":""}