@distilled.cloud/core 1.0.0-rc.17 → 1.0.0-rc.19

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 (314) hide show
  1. package/lib/_bundle/base.js +2 -2
  2. package/lib/_bundle/base.js.map +1 -1
  3. package/lib/_bundle/graphql.js +2 -2
  4. package/lib/_bundle/graphql.js.map +1 -1
  5. package/lib/_bundle/grpc.js +2 -0
  6. package/lib/_bundle/grpc.js.map +1 -0
  7. package/lib/_bundle/rest.js +1 -1
  8. package/lib/_bundle/rest.js.map +1 -1
  9. package/lib/_bundle/xml.js +1 -1
  10. package/lib/_bundle/xml.js.map +1 -1
  11. package/lib/annotations.d.ts +17 -0
  12. package/lib/annotations.d.ts.map +1 -0
  13. package/lib/annotations.js +2 -0
  14. package/lib/annotations.js.map +1 -0
  15. package/lib/api.d.ts +52 -1
  16. package/lib/api.d.ts.map +1 -1
  17. package/lib/api.js +1 -1
  18. package/lib/category.d.ts.map +1 -1
  19. package/lib/config.d.ts +54 -13
  20. package/lib/config.d.ts.map +1 -1
  21. package/lib/config.js +1 -1
  22. package/lib/error-category.d.ts.map +1 -1
  23. package/lib/errors.d.ts +3 -13
  24. package/lib/errors.d.ts.map +1 -1
  25. package/lib/errors.js +1 -1
  26. package/lib/graphql.d.ts +26 -5
  27. package/lib/graphql.d.ts.map +1 -1
  28. package/lib/graphql.types.d.ts.map +1 -1
  29. package/lib/grpc-transport-cloudflare-http2.d.ts +7 -0
  30. package/lib/grpc-transport-cloudflare-http2.d.ts.map +1 -0
  31. package/lib/grpc-transport-cloudflare-http2.js +6 -0
  32. package/lib/grpc-transport-cloudflare-http2.js.map +1 -0
  33. package/lib/grpc-transport-cloudflare-sockets.d.ts +7 -0
  34. package/lib/grpc-transport-cloudflare-sockets.d.ts.map +1 -0
  35. package/lib/grpc-transport-cloudflare-sockets.js +5 -0
  36. package/lib/grpc-transport-cloudflare-sockets.js.map +1 -0
  37. package/lib/grpc-transport-node-http2.d.ts +19 -0
  38. package/lib/grpc-transport-node-http2.d.ts.map +1 -0
  39. package/lib/grpc-transport-node-http2.js +2 -0
  40. package/lib/grpc-transport-node-http2.js.map +1 -0
  41. package/lib/grpc-transport.d.ts +76 -0
  42. package/lib/grpc-transport.d.ts.map +1 -0
  43. package/lib/grpc-transport.js +1 -0
  44. package/lib/hpack.d.ts +34 -0
  45. package/lib/hpack.d.ts.map +1 -0
  46. package/lib/hpack.js +2 -0
  47. package/lib/hpack.js.map +1 -0
  48. package/lib/index.d.ts +6 -2
  49. package/lib/index.d.ts.map +1 -1
  50. package/lib/index.js +4 -0
  51. package/lib/pagination.d.ts +55 -3
  52. package/lib/pagination.d.ts.map +1 -1
  53. package/lib/pagination.js +1 -1
  54. package/lib/protobuf.d.ts +92 -0
  55. package/lib/protobuf.d.ts.map +1 -0
  56. package/lib/protobuf.js +1 -0
  57. package/lib/protocol-grpc.d.ts +86 -0
  58. package/lib/protocol-grpc.d.ts.map +1 -0
  59. package/lib/protocol-grpc.js +1 -0
  60. package/lib/protocol-http.d.ts +38 -9
  61. package/lib/protocol-http.d.ts.map +1 -1
  62. package/lib/protocol-http.js +1 -1
  63. package/lib/protocol-rest.d.ts +60 -42
  64. package/lib/protocol-rest.d.ts.map +1 -1
  65. package/lib/protocol-rest.js +1 -1
  66. package/lib/response-validation.d.ts +5 -4
  67. package/lib/response-validation.d.ts.map +1 -1
  68. package/lib/schema-lite-typed.js +1 -2
  69. package/lib/sdk-error.d.ts +27 -0
  70. package/lib/sdk-error.d.ts.map +1 -0
  71. package/lib/sdk-error.js +1 -0
  72. package/lib/sensitive.d.ts +28 -0
  73. package/lib/sensitive.d.ts.map +1 -0
  74. package/lib/sensitive.js +2 -0
  75. package/lib/sensitive.js.map +1 -0
  76. package/lib/telemetry-debug.d.ts +6 -0
  77. package/lib/telemetry-debug.d.ts.map +1 -0
  78. package/lib/telemetry-debug.js +2 -0
  79. package/lib/telemetry-debug.js.map +1 -0
  80. package/lib/telemetry-hooks.d.ts +32 -0
  81. package/lib/telemetry-hooks.d.ts.map +1 -0
  82. package/lib/telemetry-hooks.js +2 -0
  83. package/lib/telemetry-hooks.js.map +1 -0
  84. package/lib/telemetry-host-rules.d.ts +23 -0
  85. package/lib/telemetry-host-rules.d.ts.map +1 -0
  86. package/lib/telemetry-host-rules.js +2 -0
  87. package/lib/telemetry-host-rules.js.map +1 -0
  88. package/lib/telemetry-lambda-context.d.ts +17 -0
  89. package/lib/telemetry-lambda-context.d.ts.map +1 -0
  90. package/lib/telemetry-lambda-context.js +2 -0
  91. package/lib/telemetry-lambda-context.js.map +1 -0
  92. package/lib/telemetry-message-context.d.ts +52 -0
  93. package/lib/telemetry-message-context.d.ts.map +1 -0
  94. package/lib/telemetry-message-context.js +2 -0
  95. package/lib/telemetry-message-context.js.map +1 -0
  96. package/lib/telemetry-metrics.d.ts +6 -0
  97. package/lib/telemetry-metrics.d.ts.map +1 -0
  98. package/lib/telemetry-metrics.js +2 -0
  99. package/lib/telemetry-metrics.js.map +1 -0
  100. package/lib/telemetry-name-template.d.ts +13 -0
  101. package/lib/telemetry-name-template.d.ts.map +1 -0
  102. package/lib/telemetry-name-template.js +2 -0
  103. package/lib/telemetry-name-template.js.map +1 -0
  104. package/lib/telemetry-stream.d.ts +11 -0
  105. package/lib/telemetry-stream.d.ts.map +1 -0
  106. package/lib/telemetry-stream.js +2 -0
  107. package/lib/telemetry-stream.js.map +1 -0
  108. package/lib/telemetry-xray.d.ts +28 -0
  109. package/lib/telemetry-xray.d.ts.map +1 -0
  110. package/lib/telemetry-xray.js +2 -0
  111. package/lib/telemetry-xray.js.map +1 -0
  112. package/lib/telemetry.d.ts +288 -0
  113. package/lib/telemetry.d.ts.map +1 -0
  114. package/lib/telemetry.js +3 -0
  115. package/lib/telemetry.js.map +1 -0
  116. package/lib/trait.d.ts +7 -0
  117. package/lib/trait.d.ts.map +1 -1
  118. package/lib/trait.js +1 -1
  119. package/lib/xml.d.ts.map +1 -1
  120. package/package.json +3 -5
  121. package/src/annotations.ts +53 -0
  122. package/src/api.ts +316 -43
  123. package/src/category.ts +21 -22
  124. package/src/config.ts +58 -29
  125. package/src/error-category.ts +12 -14
  126. package/src/errors.ts +11 -7
  127. package/src/graphql.ts +191 -63
  128. package/src/graphql.types.ts +5 -1
  129. package/src/grpc-transport-cloudflare-http2.ts +494 -0
  130. package/src/grpc-transport-cloudflare-sockets.ts +299 -0
  131. package/src/grpc-transport-node-http2.ts +234 -0
  132. package/src/grpc-transport.ts +118 -0
  133. package/src/hpack.ts +331 -0
  134. package/src/index.ts +6 -2
  135. package/src/pagination.ts +193 -8
  136. package/src/protobuf.ts +1332 -0
  137. package/src/protocol-grpc.ts +641 -0
  138. package/src/protocol-http.ts +87 -67
  139. package/src/protocol-rest.ts +183 -191
  140. package/src/response-validation.ts +8 -5
  141. package/src/sdk-error.ts +33 -0
  142. package/src/sensitive.ts +154 -0
  143. package/src/telemetry-debug.ts +179 -0
  144. package/src/telemetry-hooks.ts +33 -0
  145. package/src/telemetry-host-rules.ts +39 -0
  146. package/src/telemetry-lambda-context.ts +46 -0
  147. package/src/telemetry-message-context.ts +170 -0
  148. package/src/telemetry-metrics.ts +69 -0
  149. package/src/telemetry-name-template.ts +26 -0
  150. package/src/telemetry-stream.ts +100 -0
  151. package/src/telemetry-xray.ts +66 -0
  152. package/src/telemetry.ts +832 -0
  153. package/src/trait.ts +10 -0
  154. package/src/xml.ts +10 -1
  155. package/lib/codegen/boolean-string-enums.d.ts +0 -36
  156. package/lib/codegen/boolean-string-enums.d.ts.map +0 -1
  157. package/lib/codegen/boolean-string-enums.js +0 -147
  158. package/lib/codegen/boolean-string-enums.js.map +0 -1
  159. package/lib/codegen/chunk.d.ts +0 -7
  160. package/lib/codegen/chunk.d.ts.map +0 -1
  161. package/lib/codegen/chunk.js +0 -139
  162. package/lib/codegen/chunk.js.map +0 -1
  163. package/lib/codegen/cli.d.ts +0 -80
  164. package/lib/codegen/cli.d.ts.map +0 -1
  165. package/lib/codegen/cli.js +0 -166
  166. package/lib/codegen/cli.js.map +0 -1
  167. package/lib/codegen/datafy.d.ts +0 -14
  168. package/lib/codegen/datafy.d.ts.map +0 -1
  169. package/lib/codegen/datafy.js +0 -853
  170. package/lib/codegen/datafy.js.map +0 -1
  171. package/lib/codegen/dedupe.d.ts +0 -5
  172. package/lib/codegen/dedupe.d.ts.map +0 -1
  173. package/lib/codegen/dedupe.js +0 -153
  174. package/lib/codegen/dedupe.js.map +0 -1
  175. package/lib/codegen/emit.d.ts +0 -125
  176. package/lib/codegen/emit.d.ts.map +0 -1
  177. package/lib/codegen/emit.js +0 -99
  178. package/lib/codegen/emit.js.map +0 -1
  179. package/lib/codegen/format.d.ts +0 -11
  180. package/lib/codegen/format.d.ts.map +0 -1
  181. package/lib/codegen/format.js +0 -32
  182. package/lib/codegen/format.js.map +0 -1
  183. package/lib/codegen/generated-at.d.ts +0 -29
  184. package/lib/codegen/generated-at.d.ts.map +0 -1
  185. package/lib/codegen/generated-at.js +0 -78
  186. package/lib/codegen/generated-at.js.map +0 -1
  187. package/lib/codegen/generator.d.ts +0 -353
  188. package/lib/codegen/generator.d.ts.map +0 -1
  189. package/lib/codegen/generator.js +0 -810
  190. package/lib/codegen/generator.js.map +0 -1
  191. package/lib/codegen/graph.d.ts +0 -36
  192. package/lib/codegen/graph.d.ts.map +0 -1
  193. package/lib/codegen/graph.js +0 -136
  194. package/lib/codegen/graph.js.map +0 -1
  195. package/lib/codegen/graphql-client.d.ts +0 -70
  196. package/lib/codegen/graphql-client.d.ts.map +0 -1
  197. package/lib/codegen/graphql-client.js +0 -439
  198. package/lib/codegen/graphql-client.js.map +0 -1
  199. package/lib/codegen/graphql.d.ts +0 -207
  200. package/lib/codegen/graphql.d.ts.map +0 -1
  201. package/lib/codegen/graphql.js +0 -786
  202. package/lib/codegen/graphql.js.map +0 -1
  203. package/lib/codegen/latin1.d.ts +0 -3
  204. package/lib/codegen/latin1.d.ts.map +0 -1
  205. package/lib/codegen/latin1.js +0 -126
  206. package/lib/codegen/latin1.js.map +0 -1
  207. package/lib/codegen/members.d.ts +0 -32
  208. package/lib/codegen/members.d.ts.map +0 -1
  209. package/lib/codegen/members.js +0 -62
  210. package/lib/codegen/members.js.map +0 -1
  211. package/lib/codegen/model-diff.d.ts +0 -10
  212. package/lib/codegen/model-diff.d.ts.map +0 -1
  213. package/lib/codegen/model-diff.js +0 -67
  214. package/lib/codegen/model-diff.js.map +0 -1
  215. package/lib/codegen/naming.d.ts +0 -29
  216. package/lib/codegen/naming.d.ts.map +0 -1
  217. package/lib/codegen/naming.js +0 -74
  218. package/lib/codegen/naming.js.map +0 -1
  219. package/lib/codegen/openapi-cli.d.ts +0 -52
  220. package/lib/codegen/openapi-cli.d.ts.map +0 -1
  221. package/lib/codegen/openapi-cli.js +0 -84
  222. package/lib/codegen/openapi-cli.js.map +0 -1
  223. package/lib/codegen/openapi.d.ts +0 -209
  224. package/lib/codegen/openapi.d.ts.map +0 -1
  225. package/lib/codegen/openapi.js +0 -1548
  226. package/lib/codegen/openapi.js.map +0 -1
  227. package/lib/codegen/operations.d.ts +0 -24
  228. package/lib/codegen/operations.d.ts.map +0 -1
  229. package/lib/codegen/operations.js +0 -56
  230. package/lib/codegen/operations.js.map +0 -1
  231. package/lib/codegen/pagination.d.ts +0 -39
  232. package/lib/codegen/pagination.d.ts.map +0 -1
  233. package/lib/codegen/pagination.js +0 -31
  234. package/lib/codegen/pagination.js.map +0 -1
  235. package/lib/codegen/patch-audit.d.ts +0 -84
  236. package/lib/codegen/patch-audit.d.ts.map +0 -1
  237. package/lib/codegen/patch-audit.js +0 -366
  238. package/lib/codegen/patch-audit.js.map +0 -1
  239. package/lib/codegen/patches.d.ts +0 -129
  240. package/lib/codegen/patches.d.ts.map +0 -1
  241. package/lib/codegen/patches.js +0 -472
  242. package/lib/codegen/patches.js.map +0 -1
  243. package/lib/codegen/prelude.d.ts +0 -15
  244. package/lib/codegen/prelude.d.ts.map +0 -1
  245. package/lib/codegen/prelude.js +0 -60
  246. package/lib/codegen/prelude.js.map +0 -1
  247. package/lib/codegen/privatize.d.ts +0 -21
  248. package/lib/codegen/privatize.d.ts.map +0 -1
  249. package/lib/codegen/privatize.js +0 -176
  250. package/lib/codegen/privatize.js.map +0 -1
  251. package/lib/codegen/proto.d.ts +0 -121
  252. package/lib/codegen/proto.d.ts.map +0 -1
  253. package/lib/codegen/proto.js +0 -960
  254. package/lib/codegen/proto.js.map +0 -1
  255. package/lib/codegen/pure.d.ts +0 -6
  256. package/lib/codegen/pure.d.ts.map +0 -1
  257. package/lib/codegen/pure.js +0 -91
  258. package/lib/codegen/pure.js.map +0 -1
  259. package/lib/codegen/rewrite-operation-ids.d.ts +0 -154
  260. package/lib/codegen/rewrite-operation-ids.d.ts.map +0 -1
  261. package/lib/codegen/rewrite-operation-ids.js +0 -1117
  262. package/lib/codegen/rewrite-operation-ids.js.map +0 -1
  263. package/lib/codegen/spec-path.d.ts +0 -16
  264. package/lib/codegen/spec-path.d.ts.map +0 -1
  265. package/lib/codegen/spec-path.js +0 -101
  266. package/lib/codegen/spec-path.js.map +0 -1
  267. package/lib/codegen/table.d.ts +0 -5
  268. package/lib/codegen/table.d.ts.map +0 -1
  269. package/lib/codegen/table.js +0 -249
  270. package/lib/codegen/table.js.map +0 -1
  271. package/lib/debug.d.ts +0 -2
  272. package/lib/debug.d.ts.map +0 -1
  273. package/lib/debug.js +0 -1
  274. package/lib/json-patch.d.ts +0 -58
  275. package/lib/json-patch.d.ts.map +0 -1
  276. package/lib/json-patch.js +0 -2
  277. package/lib/json-patch.js.map +0 -1
  278. package/lib/schema-lite-typed.js.map +0 -1
  279. package/lib/testing.d.ts +0 -40
  280. package/lib/testing.d.ts.map +0 -1
  281. package/lib/testing.js +0 -2
  282. package/lib/testing.js.map +0 -1
  283. package/src/codegen/boolean-string-enums.ts +0 -155
  284. package/src/codegen/chunk.ts +0 -147
  285. package/src/codegen/cli.ts +0 -293
  286. package/src/codegen/datafy.ts +0 -874
  287. package/src/codegen/dedupe.ts +0 -173
  288. package/src/codegen/emit.ts +0 -200
  289. package/src/codegen/format.ts +0 -49
  290. package/src/codegen/generated-at.ts +0 -88
  291. package/src/codegen/generator.ts +0 -1229
  292. package/src/codegen/graph.ts +0 -151
  293. package/src/codegen/graphql-client.ts +0 -545
  294. package/src/codegen/graphql.ts +0 -1145
  295. package/src/codegen/latin1.ts +0 -131
  296. package/src/codegen/members.ts +0 -79
  297. package/src/codegen/model-diff.ts +0 -67
  298. package/src/codegen/naming.ts +0 -85
  299. package/src/codegen/openapi-cli.ts +0 -141
  300. package/src/codegen/openapi.ts +0 -1845
  301. package/src/codegen/operations.ts +0 -73
  302. package/src/codegen/pagination.ts +0 -64
  303. package/src/codegen/patch-audit.ts +0 -480
  304. package/src/codegen/patches.ts +0 -581
  305. package/src/codegen/prelude.ts +0 -70
  306. package/src/codegen/privatize.ts +0 -200
  307. package/src/codegen/proto.ts +0 -1092
  308. package/src/codegen/pure.ts +0 -94
  309. package/src/codegen/rewrite-operation-ids.ts +0 -1219
  310. package/src/codegen/spec-path.ts +0 -112
  311. package/src/codegen/table.ts +0 -254
  312. package/src/debug.ts +0 -8
  313. package/src/json-patch.ts +0 -273
  314. package/src/testing.ts +0 -74
@@ -1,3 +1,30 @@
1
+ import * as Context from "effect/Context";
2
+ import * as Effect from "effect/Effect";
3
+ import * as HttpClient from "effect/http/HttpClient";
4
+ import type * as HttpClientRequest from "effect/http/HttpClientRequest";
5
+ import type * as HttpClientResponse from "effect/http/HttpClientResponse";
6
+ import * as Layer from "effect/Layer";
7
+ import type * as AST from "effect/SchemaAST";
8
+ import { rawResponseRootSymbol, resolveNode } from "./annotations.ts";
9
+ import * as API from "./api.ts";
10
+ import { HTTP_STATUS_MAP, InternalServerError } from "./errors.ts";
11
+ import { recordPageHeaders } from "./pagination.ts";
12
+ import { unwrapRedactedDeep } from "./plain-values.ts";
13
+ import {
14
+ buildRequest,
15
+ getAnn,
16
+ getProps,
17
+ hasPropAnn,
18
+ mapKeys,
19
+ mapsVerbatim,
20
+ matchTypedError,
21
+ responseHeaderMembers,
22
+ withResponseHeaders,
23
+ type ResponseHeaderMember,
24
+ } from "./protocol-http.ts";
25
+ import { checkResponse, withholdActual } from "./response-validation.ts";
26
+ import { parseRetryAfterForStatus } from "./retry-after.ts";
27
+ import { holdsSensitive, sensitiveValueSymbol, wrapSensitive } from "./sensitive.ts";
1
28
  /**
2
29
  * Generic REST protocol factory for simple bearer/header-auth JSON APIs
3
30
  * (Neon, Fly.io, PlanetScale, Supabase, Turso, ...).
@@ -16,7 +43,8 @@
16
43
  * failing with the provider's `parseError` (see
17
44
  * `core/response-validation`) -> `Redacted` wrapping of members
18
45
  * marked with {@link SensitiveValue}; non-2xx -> typed error:
19
- * per-op matcher classes (`matchTypedError`), then the status
46
+ * the provider's `classifyError`, then per-op matcher
47
+ * classes (`matchTypedError`), then the status
20
48
  * map (default `HTTP_STATUS_MAP`), then an `InternalServerError`
21
49
  * for unmapped 5xx, then the provider's `unknownError` fallback
22
50
  * -- with `retryAfter` durations stamped from the standard hint
@@ -25,45 +53,18 @@
25
53
  * Anything provider-specific (envelope quirks, bespoke error codes) belongs
26
54
  * in the provider package -- via these options or a hand-written protocol.
27
55
  */
28
- import * as Context from "effect/Context";
29
- import * as Effect from "effect/Effect";
30
- import * as HttpClient from "effect/http/HttpClient";
31
- import type * as HttpClientRequest from "effect/http/HttpClientRequest";
32
- import type * as HttpClientResponse from "effect/http/HttpClientResponse";
33
- import * as Layer from "effect/Layer";
34
- import * as Redacted from "effect/Redacted";
35
- import type * as AST from "effect/SchemaAST";
36
- import * as API from "./api.ts";
37
- import { debugHttp } from "./debug.ts";
38
- import { HTTP_STATUS_MAP, InternalServerError } from "./errors.ts";
39
- import { isOpaqueValue, unwrapRedactedDeep } from "./plain-values.ts";
40
- import {
41
- buildRequest,
42
- getAnn,
43
- getPropAnn,
44
- getProps,
45
- mapKeys,
46
- mapsVerbatim,
47
- matchTypedError,
48
- resolveNode,
49
- responseHeaderMembers,
50
- withResponseHeaders,
51
- type ResponseHeaderMember,
52
- } from "./protocol-http.ts";
53
- import { checkResponse, withholdActual } from "./response-validation.ts";
54
- import { parseRetryAfterForStatus } from "./retry-after.ts";
56
+ import * as Telemetry from "./telemetry.ts";
55
57
  import { httpSymbol, makeAnnotation, type HttpTrait } from "./trait.ts";
56
58
 
57
59
  // =============================================================================
58
60
  // Traits
59
61
  // =============================================================================
60
62
 
61
- export const sensitiveValueSymbol = /*@__PURE__*/ Symbol.for(
62
- "@distilled.cloud/core/sensitive-value",
63
- );
63
+ export { sensitiveValueSymbol };
64
64
  /**
65
- * Marks a string member as sensitive (mirrors `smithy.api#sensitive`).
66
- * The REST protocol wraps decoded values in `Redacted` on the way out and
65
+ * Marks a string member, map value or list element as sensitive (mirrors
66
+ * `smithy.api#sensitive`). The REST protocol wraps decoded values in
67
+ * `Redacted` on the way out (an untyped `S.Unknown` value whole) and
67
68
  * accepts `string | Redacted<string>` on the way in (unwrapped before
68
69
  * serialization). Takes an ignored argument so generators can inline the
69
70
  * smithy trait value (`T.SensitiveValue({})`).
@@ -77,15 +78,13 @@ export const rawResponseSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core
77
78
  */
78
79
  export const RawResponse = (_value?: unknown) => makeAnnotation(rawResponseSymbol, true);
79
80
 
80
- export const rawResponseRootSymbol = /*@__PURE__*/ Symbol.for(
81
- "@distilled.cloud/core/raw-response-root",
82
- );
83
81
  /**
84
82
  * Marks a response schema whose ENTIRE value is the response body (the
85
83
  * generator's `rootPipe` for synthesized bare-payload wrappers): the emitted
86
84
  * response type IS the payload type and the protocol returns the mapped body
87
85
  * directly.
88
86
  */
87
+ export { rawResponseRootSymbol };
89
88
  export const RawResponseRoot = () => makeAnnotation(rawResponseRootSymbol, true);
90
89
 
91
90
  export const binaryResponseSymbol = /*@__PURE__*/ Symbol.for(
@@ -101,76 +100,15 @@ export const BinaryResponse = () => makeAnnotation(binaryResponseSymbol, true);
101
100
 
102
101
  export { unwrapRedactedDeep };
103
102
 
104
- /**
105
- * Walk a decoded (TS-named) value alongside its schema AST, wrapping members
106
- * marked {@link SensitiveValue} in `Redacted`. Keys the schema doesn't model
107
- * pass through verbatim.
108
- */
109
- export const wrapSensitive = (ast: AST.AST, value: unknown): unknown => {
110
- if (value === null || typeof value !== "object" || isOpaqueValue(value)) {
111
- return value;
112
- }
113
- const node = resolveNode(ast);
114
- if (node._tag === "Union") {
115
- // Redact every possible sensitive member, including in partial responses.
116
- return node.types.reduce<unknown>((redacted, arm) => wrapSensitive(arm, redacted), value);
117
- }
118
- if (node._tag === "Arrays") {
119
- if (!Array.isArray(value)) return value;
120
- const elem = (node as any).rest?.[0] as AST.AST | undefined;
121
- return elem ? value.map((v) => wrapSensitive(elem, v)) : value;
122
- }
123
- if (node._tag === "Objects" && !Array.isArray(value)) {
124
- const props = getProps(node);
125
- if (props.length === 0) return value;
126
- const byName = new Map(props.map((p) => [String(p.name), p]));
127
- const out: Record<string, unknown> = {};
128
- for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
129
- if (v === undefined) continue;
130
- const prop = byName.get(k);
131
- if (!prop) {
132
- out[k] = v;
133
- } else if (getPropAnn(prop, sensitiveValueSymbol) !== undefined && typeof v === "string") {
134
- out[k] = Redacted.make(v);
135
- } else {
136
- out[k] = wrapSensitive(prop.type, v);
137
- }
138
- }
139
- return out;
140
- }
141
- return value;
142
- };
143
-
144
- const sensitiveOutputs = /*@__PURE__*/ new WeakMap<AST.AST, boolean>();
103
+ export { wrapSensitive };
145
104
 
146
105
  /**
147
- * Whether any member reachable from `ast` is marked {@link SensitiveValue}.
148
- * Parse errors for such an output withhold the response body (see
149
- * {@link RestParseErrorInfo}); hand-written protocols use this to do the same.
106
+ * Whether any member, map value or list element reachable from `ast` is
107
+ * marked {@link SensitiveValue}. Such an output is decoded through
108
+ * {@link wrapSensitive}, and its parse errors withhold the response body (see
109
+ * {@link checkSuccess}, which every REST-style protocol's success path uses).
150
110
  */
151
- export const hasSensitiveMember = (ast: AST.AST): boolean => {
152
- const cached = sensitiveOutputs.get(ast);
153
- if (cached !== undefined) return cached;
154
- const seen = new Set<AST.AST>();
155
- const visit = (node: AST.AST): boolean => {
156
- node = resolveNode(node);
157
- if (seen.has(node)) return false;
158
- seen.add(node);
159
- if (node._tag === "Union") return node.types.some(visit);
160
- if (node._tag === "Arrays") {
161
- return [...node.elements, ...node.rest].some(
162
- (e) => getAnn(e, sensitiveValueSymbol) !== undefined || visit(e),
163
- );
164
- }
165
- if (node._tag !== "Objects") return false;
166
- return [...node.propertySignatures, ...node.indexSignatures].some(
167
- (member) => getAnn(member.type, sensitiveValueSymbol) !== undefined || visit(member.type),
168
- );
169
- };
170
- const result = visit(ast);
171
- sensitiveOutputs.set(ast, result);
172
- return result;
173
- };
111
+ export const hasSensitiveMember: (ast: AST.AST) => boolean = holdsSensitive;
174
112
 
175
113
  // =============================================================================
176
114
  // Protocol factory
@@ -243,6 +181,13 @@ export interface RestProtocolOptions<C> {
243
181
  * else to {@link unknownError}.
244
182
  */
245
183
  readonly statusMap?: Readonly<Record<number, new (args: any) => any>>;
184
+ /**
185
+ * The provider's own reading of a failure, consulted before per-op typed
186
+ * matching and the status map: return the error to fail with, or
187
+ * `undefined` to decode the failure as usual. For rules a status alone
188
+ * can't express, e.g. a 403 that is a rate limit because of its headers.
189
+ */
190
+ readonly classifyError?: (info: RestErrorInfo) => unknown;
246
191
  /** Fallback error for failures nothing else matched. */
247
192
  readonly unknownError: (info: RestErrorInfo) => unknown;
248
193
  /**
@@ -261,6 +206,8 @@ export interface RestProtocolOptions<C> {
261
206
  readonly mapMemberHeader?: (name: string, value: string) => string;
262
207
  /** Passed through to `buildRequest` (wire names for unmodeled input keys). */
263
208
  readonly unknownKeyToWire?: (key: string) => string;
209
+ /** Passed through to `buildRequest`: send `{}` when a bodied call has no body members. */
210
+ readonly emptyJsonBody?: boolean;
264
211
  }
265
212
 
266
213
  const defaultErrorEnvelope = (body: unknown): RestErrorEnvelope | undefined => {
@@ -278,45 +225,88 @@ const defaultErrorEnvelope = (body: unknown): RestErrorEnvelope | undefined => {
278
225
  // here; the generated operation annotations reintroduce it for callers.
279
226
  const fail = (e: unknown): Effect.Effect<never> => Effect.fail(e) as Effect.Effect<never>;
280
227
 
281
- /** Whether {@link wrapSensitive} can change any value of `root`. Cached per schema. */
282
- export const hasSensitive = (root: AST.AST): boolean => {
283
- let result = sensitiveCache.get(root);
284
- if (result !== undefined) return result;
285
- result = false;
286
- const seen = new Set<AST.AST>();
287
- const stack: AST.AST[] = [root];
288
- walk: while (stack.length > 0) {
289
- const ast = stack.pop()!;
290
- if (seen.has(ast)) continue;
291
- seen.add(ast);
292
- const node = resolveNode(ast);
293
- if (node._tag === "Union") {
294
- for (const t of (node as AST.Union).types) stack.push(t);
295
- } else if (node._tag === "Arrays") {
296
- const elem = (node as any).rest?.[0] as AST.AST | undefined;
297
- if (elem) stack.push(elem);
298
- } else if (node._tag === "Objects") {
299
- for (const p of getProps(node)) {
300
- if (getPropAnn(p, sensitiveValueSymbol) !== undefined) {
301
- result = true;
302
- break walk;
303
- }
304
- stack.push(p.type);
305
- }
306
- }
228
+ // =============================================================================
229
+ // 2xx bodies
230
+ // =============================================================================
231
+
232
+ /** A 2xx body a protocol read, for {@link checkSuccess}. */
233
+ export interface SuccessBody {
234
+ /** The value to check and return: the body mapped onto the output's TS names. */
235
+ readonly value: unknown;
236
+ /** What a parse error reports as `body` for an output without sensitive members. */
237
+ readonly body: unknown;
238
+ /** Whether the body was not JSON. */
239
+ readonly nonJson: boolean;
240
+ }
241
+
242
+ /** The outcome of {@link checkSuccess}: the value, or the parse error's fields. */
243
+ export type SuccessCheck =
244
+ | { readonly ok: true; readonly value: unknown }
245
+ | { readonly ok: false; readonly error: RestParseErrorInfo };
246
+
247
+ /**
248
+ * Check a 2xx body against the operation's output schema and deliver its
249
+ * sensitive values as `Redacted`. Every REST-style protocol ends its success
250
+ * path here, so all of them treat a body that can hold a secret alike:
251
+ *
252
+ * - The checked value comes back through {@link wrapSensitive}.
253
+ * - A mismatch (validating modes, see `core/response-validation`) reports
254
+ * `read.body` and the schema error.
255
+ * - For an output with sensitive members ({@link hasSensitiveMember}), a
256
+ * non-JSON body fails in every mode with `"Invalid JSON response"`, and a
257
+ * mismatch reports `body: "[REDACTED]"` and the schema error without the
258
+ * value it found (`withholdActual`).
259
+ *
260
+ * Synchronous, for protocols that already hold the calling fiber's context;
261
+ * {@link validateSuccess} is the `Effect` form.
262
+ */
263
+ export const checkSuccess = (
264
+ context: Context.Context<any>,
265
+ outputAst: AST.AST,
266
+ read: SuccessBody,
267
+ ): SuccessCheck => {
268
+ const sensitive = hasSensitiveMember(outputAst);
269
+ if (read.nonJson && sensitive) {
270
+ return { ok: false, error: { body: "[REDACTED]", cause: "Invalid JSON response" } };
271
+ }
272
+ const invalid = checkResponse(context, outputAst, read.value);
273
+ if (invalid !== undefined) {
274
+ return {
275
+ ok: false,
276
+ error: sensitive
277
+ ? { body: "[REDACTED]", cause: withholdActual(invalid) }
278
+ : { body: read.body, cause: invalid },
279
+ };
307
280
  }
308
- sensitiveCache.set(root, result);
309
- return result;
281
+ return { ok: true, value: sensitive ? wrapSensitive(outputAst, read.value) : read.value };
310
282
  };
311
- const sensitiveCache = /*@__PURE__*/ new WeakMap<AST.AST, boolean>();
283
+
284
+ /**
285
+ * {@link checkSuccess} on the calling fiber, failing with `parseError` (the
286
+ * SDK's `<Sdk>ParseError`) built from the withheld-or-not fields.
287
+ */
288
+ export const validateSuccess = <E>(
289
+ outputAst: AST.AST,
290
+ read: SuccessBody,
291
+ parseError: (info: RestParseErrorInfo) => E,
292
+ ): Effect.Effect<unknown, E> =>
293
+ Effect.withFiber((fiber) => {
294
+ const checked = checkSuccess(fiber.context as Context.Context<any>, outputAst, read);
295
+ return checked.ok ? Effect.succeed(checked.value) : Effect.fail(parseError(checked.error));
296
+ });
312
297
 
313
298
  /** Per-operation decode facts, read from the output schema once. */
314
299
  interface DecodePlan {
315
300
  readonly binary: boolean;
316
301
  readonly verbatim: boolean;
317
- readonly sensitive: boolean;
318
- /** Parse errors withhold the body (see {@link hasSensitiveMember}). */
319
- readonly withholdBody: boolean;
302
+ /**
303
+ * A member of a structure output that receives the whole body
304
+ * (`T.RawResponse()` next to header members), e.g. a bare JSON array with
305
+ * its next-page token in a response header.
306
+ */
307
+ readonly bodyMember: AST.PropertySignature | undefined;
308
+ /** The output is a bare string, so an empty body decodes to `""`. */
309
+ readonly text: boolean;
320
310
  /** Members read from response headers (`T.Header`). */
321
311
  readonly headers: ReadonlyArray<ResponseHeaderMember>;
322
312
  }
@@ -328,9 +318,9 @@ const decodePlanFor = (outputAst: AST.AST): DecodePlan => {
328
318
  plan = {
329
319
  binary: getAnn(outputAst, binaryResponseSymbol) !== undefined,
330
320
  verbatim: mapsVerbatim(outputAst, "decode"),
331
- sensitive: hasSensitive(outputAst),
332
- withholdBody: hasSensitiveMember(outputAst),
321
+ text: resolveNode(outputAst)._tag === "String",
333
322
  headers: responseHeaderMembers(outputAst),
323
+ bodyMember: getProps(outputAst).find((prop) => hasPropAnn(prop, rawResponseSymbol)),
334
324
  };
335
325
  decodePlans.set(outputAst, plan);
336
326
  }
@@ -369,12 +359,15 @@ export const makeRestProtocol = <C>(options: RestProtocolOptions<C>): Layer.Laye
369
359
  f,
370
360
  );
371
361
 
372
- /** The request, or the error a refusing `baseUrl` threw. */
362
+ /**
363
+ * The request; fails with the error a refusing `baseUrl` threw, or with
364
+ * `InvalidInput` for a label that would address another resource.
365
+ */
373
366
  const requestFor = (
374
367
  creds: C,
375
368
  input: unknown,
376
369
  inputAst: AST.AST,
377
- ): HttpClientRequest.HttpClientRequest | { readonly refused: unknown } => {
370
+ ): Effect.Effect<HttpClientRequest.HttpClientRequest> => {
378
371
  const http = getAnn(inputAst, httpSymbol) as HttpTrait | undefined;
379
372
  let baseUrl: string;
380
373
  try {
@@ -386,7 +379,7 @@ export const makeRestProtocol = <C>(options: RestProtocolOptions<C>): Layer.Laye
386
379
  // A baseUrl that refuses the route (missing scope in the
387
380
  // credentials) fails the call with that error, typed for callers by
388
381
  // the operation's declared error channel.
389
- return { refused: e };
382
+ return fail(e);
390
383
  }
391
384
  return buildRequest({
392
385
  input: unwrapRedactedDeep(input),
@@ -395,7 +388,8 @@ export const makeRestProtocol = <C>(options: RestProtocolOptions<C>): Layer.Laye
395
388
  headers: options.headers(creds),
396
389
  mapMemberHeader: options.mapMemberHeader,
397
390
  unknownKeyToWire: options.unknownKeyToWire,
398
- });
391
+ emptyJsonBody: options.emptyJsonBody,
392
+ }) as Effect.Effect<HttpClientRequest.HttpClientRequest>;
399
393
  };
400
394
 
401
395
  /** Map a read response body to the call's outcome. */
@@ -408,9 +402,6 @@ export const makeRestProtocol = <C>(options: RestProtocolOptions<C>): Layer.Laye
408
402
  errorClasses: ReadonlyArray<unknown>,
409
403
  ): Decoded => {
410
404
  // Read as text and parse tolerantly -- error pages are often non-JSON.
411
- if (debugHttp()) {
412
- console.error(`[distilled] <- ${status}`);
413
- }
414
405
  let json: unknown;
415
406
  let nonJson = false;
416
407
  if (text.trim().length > 0) {
@@ -425,6 +416,18 @@ export const makeRestProtocol = <C>(options: RestProtocolOptions<C>): Layer.Laye
425
416
  const env = (nonJson ? undefined : errorEnvelope(json)) ?? {};
426
417
  const message = env.message ?? (nonJson && text.trim() ? text.trim() : `HTTP ${status}`);
427
418
 
419
+ // 0. The provider's own reading of the failure.
420
+ if (options.classifyError) {
421
+ const classified = options.classifyError({
422
+ status,
423
+ code: env.code,
424
+ message,
425
+ body: nonJson ? text : json,
426
+ headers,
427
+ });
428
+ if (classified !== undefined) return { ok: false, error: classified };
429
+ }
430
+
428
431
  // 1. Per-operation typed error (matcher metadata on the class).
429
432
  const typed = matchTypedError(
430
433
  errorClasses,
@@ -486,30 +489,20 @@ export const makeRestProtocol = <C>(options: RestProtocolOptions<C>): Layer.Laye
486
489
  // with sensitive members, a non-JSON body fails in every mode and parse
487
490
  // errors withhold the body.
488
491
  const plan = decodePlanFor(outputAst);
489
- if (nonJson && plan.withholdBody) {
490
- return {
491
- ok: false,
492
- error: options.parseError({ body: "[REDACTED]", cause: "Invalid JSON response" }),
493
- };
494
- }
495
- let body: unknown = nonJson ? text : (json ?? {});
492
+ let body: unknown = nonJson ? text : (json ?? (plan.text ? "" : {}));
496
493
  if (options.transformResponse) body = options.transformResponse(body);
497
- const mapped = withResponseHeaders(
498
- plan.headers,
499
- plan.verbatim ? body : mapKeys(outputAst, body, "decode"),
500
- headers,
501
- );
502
- const invalid = checkResponse(context, outputAst, mapped);
503
- if (invalid !== undefined) {
504
- return {
505
- ok: false,
506
- error: options.parseError({
507
- body: plan.withholdBody ? "[REDACTED]" : nonJson ? text : json,
508
- cause: plan.withholdBody ? withholdActual(invalid) : invalid,
509
- }),
510
- };
511
- }
512
- return { ok: true, value: plan.sensitive ? wrapSensitive(outputAst, mapped) : mapped };
494
+ const mapped =
495
+ plan.bodyMember !== undefined
496
+ ? { [plan.bodyMember.name]: mapKeys(plan.bodyMember.type, body, "decode") }
497
+ : plan.verbatim
498
+ ? body
499
+ : mapKeys(outputAst, body, "decode");
500
+ const checked = checkSuccess(context, outputAst, {
501
+ value: withResponseHeaders(plan.headers, mapped, headers),
502
+ body: nonJson ? text : json,
503
+ nonJson,
504
+ });
505
+ return checked.ok ? checked : { ok: false, error: options.parseError(checked.error) };
513
506
  };
514
507
 
515
508
  const decodeResponse = (
@@ -518,32 +511,32 @@ export const makeRestProtocol = <C>(options: RestProtocolOptions<C>): Layer.Laye
518
511
  outputAst: AST.AST,
519
512
  errorClasses: ReadonlyArray<unknown>,
520
513
  ): Effect.Effect<unknown> =>
521
- response.status >= 200 && response.status < 300 && decodePlanFor(outputAst).binary
522
- ? Effect.map(Effect.orDie(response.arrayBuffer), (bytes) => new Uint8Array(bytes))
523
- : Effect.matchEffect(response.text, {
524
- onFailure: Effect.die,
525
- onSuccess: (text) => {
526
- const decoded = decodeText(
527
- context,
528
- response.status,
529
- response.headers as Record<string, string | undefined>,
530
- text ?? "",
531
- outputAst,
532
- errorClasses,
533
- );
534
- return decoded.ok ? Effect.succeed(decoded.value) : fail(decoded.error);
535
- },
536
- });
514
+ // A body read that fails (reset or abort mid-body) fails the call with
515
+ // its `HttpClientError`, which every operation's error channel declares.
516
+ (response.status >= 200 && response.status < 300 && decodePlanFor(outputAst).binary
517
+ ? Effect.map(response.arrayBuffer, (bytes) => new Uint8Array(bytes))
518
+ : Effect.flatMap(response.text, (text) => {
519
+ recordPageHeaders(context, response.headers);
520
+ const decoded = decodeText(
521
+ context,
522
+ response.status,
523
+ response.headers as Record<string, string | undefined>,
524
+ text ?? "",
525
+ outputAst,
526
+ errorClasses,
527
+ );
528
+ return decoded.ok ? Effect.succeed(decoded.value) : fail(decoded.error);
529
+ })) as Effect.Effect<unknown>;
537
530
 
538
531
  const call = (op: API.PreparedOperation, input: unknown): Effect.Effect<unknown> =>
539
532
  Effect.withFiber((fiber) => {
540
533
  const context = fiber.context as Context.Context<any>;
541
534
  return withCredentials(context, (creds) => {
542
- const request = requestFor(creds, input, op.inputAst);
543
- if ("refused" in request) return fail(request.refused);
544
535
  const client = Context.get(context, HttpClient.HttpClient);
545
- return Effect.flatMap(client.execute(request), (response) =>
546
- decodeResponse(context, response, op.outputAst, op.errors),
536
+ return Effect.flatMap(requestFor(creds, input, op.inputAst), (request) =>
537
+ Effect.flatMap(Telemetry.execute(context, client, request), (response) =>
538
+ decodeResponse(context, response, op.outputAst, op.errors),
539
+ ),
547
540
  );
548
541
  });
549
542
  }) as Effect.Effect<unknown>;
@@ -555,10 +548,9 @@ export const makeRestProtocol = <C>(options: RestProtocolOptions<C>): Layer.Laye
555
548
  // fiber; see RestProtocolOptions.credentials).
556
549
  encode: ({ input, inputAst }) =>
557
550
  Effect.withFiber((fiber) =>
558
- withCredentials(fiber.context as Context.Context<any>, (creds) => {
559
- const request = requestFor(creds, input, inputAst);
560
- return "refused" in request ? fail(request.refused) : Effect.succeed(request);
561
- }),
551
+ withCredentials(fiber.context as Context.Context<any>, (creds) =>
552
+ requestFor(creds, input, inputAst),
553
+ ),
562
554
  ) as Effect.Effect<HttpClientRequest.HttpClientRequest>,
563
555
  decode: ({ response, outputAst, errors }) =>
564
556
  Effect.withFiber((fiber) =>
@@ -7,9 +7,10 @@
7
7
  * lenient (default): the response is returned as the protocol read it.
8
8
  * A body that does not match the declared output type
9
9
  * (a missing member, a wrong primitive, a non-JSON
10
- * body) still succeeds, except that core's REST
11
- * protocol, Stripe and Fly.io fail a non-JSON body for
12
- * an output with sensitive members in every mode.
10
+ * body) still succeeds, except that a non-JSON body for
11
+ * an output with sensitive members fails in every mode
12
+ * (REST-style protocols through core's `checkSuccess`
13
+ * in `protocol-rest`, plus ZeroSSL and AWS).
13
14
  * additionalProperties: the response is checked against the output
14
15
  * schema, and a mismatch fails the call with the SDK's
15
16
  * `<Sdk>ParseError` (AWS: `ParseError`). Keys the
@@ -40,7 +41,7 @@ import * as Context from "effect/Context";
40
41
  import * as Effect from "effect/Effect";
41
42
  import * as Layer from "effect/Layer";
42
43
  import type * as AST from "effect/SchemaAST";
43
- import { type Decode, decoderFor, type SchemaMismatch } from "./response-validation-strict.ts";
44
+ import { type Decode, decoderFor, SchemaMismatch } from "./response-validation-strict.ts";
44
45
 
45
46
  export { SchemaMismatch, withholdActual } from "./response-validation-strict.ts";
46
47
 
@@ -142,7 +143,9 @@ export const checkResponse = (
142
143
  if (mode === "lenient") return undefined;
143
144
  const decoderOf = Context.get(context, StrictDecoder);
144
145
  if (!decoderOf) {
145
- throw new Error(`${mode} response validation needs the ResponseValidation.${mode} layer`);
146
+ // The mode was set without the layer that brings its decoder: the
147
+ // response can't be checked, so the call fails as a mismatch.
148
+ return new SchemaMismatch([], `the ResponseValidation.${mode} layer`, mode);
146
149
  }
147
150
  return decoderOf(outputAst, mode === "strict")(value);
148
151
  };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The error an operation fails with when the SDK itself cannot make the
3
+ * call: its generated config or a core module is broken (a paginated
4
+ * operation without the fields its strategy reads, a gRPC operation
5
+ * without a descriptor, ...), or one of its own modules fails to load. No
6
+ * input or response causes it; the generator refuses the configs that
7
+ * would. It is typed, so it fails the call instead of crashing the fiber,
8
+ * and it is never retried.
9
+ *
10
+ * Defined on its own, in core's `base` bundle group, so pagination and
11
+ * the protocols fail with it without importing the REST modules.
12
+ */
13
+ import * as Effect from "effect/Effect";
14
+ import * as Schema from "./schema-lite-typed.ts";
15
+
16
+ export class SdkError
17
+ extends /*@__PURE__*/ Schema.TaggedError<SdkError>()("SdkError", {
18
+ message: Schema.String,
19
+ }) {}
20
+
21
+ /**
22
+ * Load one of the SDK's own modules on first use (`() => import("./x.ts")`).
23
+ * A rejected import -- a chunk missing from a bundle, a browser chunk that
24
+ * fails to download -- fails with {@link SdkError}.
25
+ */
26
+ export const loadModule = <A>(load: () => PromiseLike<A>): Effect.Effect<A, SdkError> =>
27
+ Effect.tryPromise({
28
+ try: () => load(),
29
+ catch: (cause) =>
30
+ new SdkError({
31
+ message: `an SDK module failed to load: ${cause instanceof Error ? cause.message : String(cause)}`,
32
+ }),
33
+ });