effect 4.1.5 → 4.1.6
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.
- package/ai-docs/package.json +2 -2
- package/dist/Channel.d.ts +104 -7
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +73 -4
- package/dist/Channel.js.map +1 -1
- package/dist/Codegen.d.ts +7 -2
- package/dist/Codegen.d.ts.map +1 -1
- package/dist/Codegen.js +7 -2
- package/dist/Codegen.js.map +1 -1
- package/dist/Effect.d.ts +139 -18
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +10 -2
- package/dist/Effect.js.map +1 -1
- package/dist/Equal.d.ts +4 -4
- package/dist/Equal.d.ts.map +1 -1
- package/dist/Equal.js +78 -65
- package/dist/Equal.js.map +1 -1
- package/dist/Hash.d.ts.map +1 -1
- package/dist/Hash.js +24 -17
- package/dist/Hash.js.map +1 -1
- package/dist/LayerRef.d.ts +1 -1
- package/dist/LayerRef.d.ts.map +1 -1
- package/dist/LayerRef.js +3 -3
- package/dist/LayerRef.js.map +1 -1
- package/dist/Logger.d.ts +37 -13
- package/dist/Logger.d.ts.map +1 -1
- package/dist/Logger.js +39 -10
- package/dist/Logger.js.map +1 -1
- package/dist/Match.d.ts +23 -23
- package/dist/Match.d.ts.map +1 -1
- package/dist/Match.js.map +1 -1
- package/dist/Order.js +1 -1
- package/dist/Order.js.map +1 -1
- package/dist/Schema.d.ts +41 -0
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +51 -390
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +0 -3
- package/dist/SchemaAST.js.map +1 -1
- package/dist/ScopedCache.d.ts.map +1 -1
- package/dist/ScopedCache.js +6 -4
- package/dist/ScopedCache.js.map +1 -1
- package/dist/Stream.d.ts +128 -5
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +124 -29
- package/dist/Stream.js.map +1 -1
- package/dist/String.js +1 -1
- package/dist/String.js.map +1 -1
- package/dist/Tracer.d.ts +10 -0
- package/dist/Tracer.d.ts.map +1 -1
- package/dist/Tracer.js +2 -0
- package/dist/Tracer.js.map +1 -1
- package/dist/ai/McpSchema.d.ts +88 -88
- package/dist/ai/McpSchema.d.ts.map +1 -1
- package/dist/ai/McpServer.d.ts +152 -2
- package/dist/ai/McpServer.d.ts.map +1 -1
- package/dist/ai/McpServer.js +8 -2
- package/dist/ai/McpServer.js.map +1 -1
- package/dist/ai/Prompt.d.ts +3 -1
- package/dist/ai/Prompt.d.ts.map +1 -1
- package/dist/ai/Prompt.js +17 -3
- package/dist/ai/Prompt.js.map +1 -1
- package/dist/ai/Skill.d.ts +172 -0
- package/dist/ai/Skill.d.ts.map +1 -0
- package/dist/ai/Skill.js +209 -0
- package/dist/ai/Skill.js.map +1 -0
- package/dist/ai/index.d.ts +5 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +5 -0
- package/dist/ai/index.js.map +1 -1
- package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/cluster/ClusterWorkflowEngine.js +155 -83
- package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/cluster/MessageStorage.d.ts +56 -0
- package/dist/cluster/MessageStorage.d.ts.map +1 -1
- package/dist/cluster/MessageStorage.js +18 -2
- package/dist/cluster/MessageStorage.js.map +1 -1
- package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/cluster/SqlMessageStorage.js +45 -22
- package/dist/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/cluster/internal/entityActivation.js +2 -0
- package/dist/cluster/internal/entityActivation.js.map +1 -1
- package/dist/cluster/internal/entityManager.js +8 -5
- package/dist/cluster/internal/entityManager.js.map +1 -1
- package/dist/encoding/Base64.js +5 -1
- package/dist/encoding/Base64.js.map +1 -1
- package/dist/encoding/Base64Url.d.ts.map +1 -1
- package/dist/encoding/Base64Url.js +6 -1
- package/dist/encoding/Base64Url.js.map +1 -1
- package/dist/encoding/Xml.d.ts +38 -9
- package/dist/encoding/Xml.d.ts.map +1 -1
- package/dist/encoding/Xml.js +63 -31
- package/dist/encoding/Xml.js.map +1 -1
- package/dist/http/FetchHttpClient.d.ts +2 -1
- package/dist/http/FetchHttpClient.d.ts.map +1 -1
- package/dist/http/FetchHttpClient.js +14 -10
- package/dist/http/FetchHttpClient.js.map +1 -1
- package/dist/http/Headers.d.ts +201 -3
- package/dist/http/Headers.d.ts.map +1 -1
- package/dist/http/Headers.js +205 -3
- package/dist/http/Headers.js.map +1 -1
- package/dist/http/HttpClient.d.ts.map +1 -1
- package/dist/http/HttpClient.js +11 -7
- package/dist/http/HttpClient.js.map +1 -1
- package/dist/http/HttpClientError.d.ts +1 -0
- package/dist/http/HttpClientError.d.ts.map +1 -1
- package/dist/http/HttpClientError.js +32 -9
- package/dist/http/HttpClientError.js.map +1 -1
- package/dist/http/HttpClientRequest.d.ts +46 -0
- package/dist/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/http/HttpClientRequest.js +15 -0
- package/dist/http/HttpClientRequest.js.map +1 -1
- package/dist/http/HttpClientResponse.d.ts +132 -0
- package/dist/http/HttpClientResponse.d.ts.map +1 -1
- package/dist/http/HttpClientResponse.js +83 -0
- package/dist/http/HttpClientResponse.js.map +1 -1
- package/dist/http/HttpMiddleware.js +1 -1
- package/dist/http/HttpMiddleware.js.map +1 -1
- package/dist/http/HttpServerResponse.d.ts +118 -0
- package/dist/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/http/HttpServerResponse.js +43 -0
- package/dist/http/HttpServerResponse.js.map +1 -1
- package/dist/http/Multipart.d.ts.map +1 -1
- package/dist/http/Multipart.js +0 -5
- package/dist/http/Multipart.js.map +1 -1
- package/dist/http/MultipartParser/internal/contentType.d.ts +6 -0
- package/dist/http/MultipartParser/internal/contentType.d.ts.map +1 -1
- package/dist/http/MultipartParser/internal/contentType.js +1 -1
- package/dist/http/MultipartParser/internal/contentType.js.map +1 -1
- package/dist/http/internal/clientPath.d.ts +2 -0
- package/dist/http/internal/clientPath.d.ts.map +1 -0
- package/dist/http/internal/clientPath.js +24 -0
- package/dist/http/internal/clientPath.js.map +1 -0
- package/dist/http/internal/redactedPath.js +2 -0
- package/dist/http/internal/redactedPath.js.map +1 -1
- package/dist/http/internal/tracing.js +5 -3
- package/dist/http/internal/tracing.js.map +1 -1
- package/dist/http-api/HttpApi.d.ts +2 -2
- package/dist/http-api/HttpApi.d.ts.map +1 -1
- package/dist/http-api/HttpApi.js +30 -7
- package/dist/http-api/HttpApi.js.map +1 -1
- package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
- package/dist/http-api/HttpApiBuilder.js +5 -2
- package/dist/http-api/HttpApiBuilder.js.map +1 -1
- package/dist/http-api/HttpApiClient.d.ts.map +1 -1
- package/dist/http-api/HttpApiClient.js +23 -6
- package/dist/http-api/HttpApiClient.js.map +1 -1
- package/dist/http-api/internal/redactedKeys.d.ts +2 -0
- package/dist/http-api/internal/redactedKeys.d.ts.map +1 -0
- package/dist/http-api/internal/redactedKeys.js +37 -0
- package/dist/http-api/internal/redactedKeys.js.map +1 -0
- package/dist/internal/base64.js +34 -2
- package/dist/internal/base64.js.map +1 -1
- package/dist/internal/dateTime.js +35 -17
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/effect.js +9 -1
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/equal.js +14 -13
- package/dist/internal/equal.js.map +1 -1
- package/dist/internal/hash.js +4 -1
- package/dist/internal/hash.js.map +1 -1
- package/dist/internal/matcher.js +17 -17
- package/dist/internal/matcher.js.map +1 -1
- package/dist/internal/schema/schemaCodegen.js +3 -2
- package/dist/internal/schema/schemaCodegen.js.map +1 -1
- package/dist/internal/schema/schemaCodegenBuiltIns.d.ts +2 -0
- package/dist/internal/schema/schemaCodegenBuiltIns.d.ts.map +1 -0
- package/dist/internal/schema/schemaCodegenBuiltIns.js +425 -0
- package/dist/internal/schema/schemaCodegenBuiltIns.js.map +1 -0
- package/dist/internal/schema/toEquivalence.js +3 -4
- package/dist/internal/schema/toEquivalence.js.map +1 -1
- package/dist/internal/version.js +1 -1
- package/dist/jose/JoseError.d.ts +51 -1
- package/dist/jose/JoseError.d.ts.map +1 -1
- package/dist/jose/JoseError.js +25 -18
- package/dist/jose/JoseError.js.map +1 -1
- package/dist/jose/internal/compact.js +10 -5
- package/dist/jose/internal/compact.js.map +1 -1
- package/dist/observability/Otlp.d.ts +19 -0
- package/dist/observability/Otlp.d.ts.map +1 -1
- package/dist/observability/Otlp.js +10 -0
- package/dist/observability/Otlp.js.map +1 -1
- package/dist/observability/OtlpExporter.d.ts +49 -13
- package/dist/observability/OtlpExporter.d.ts.map +1 -1
- package/dist/observability/OtlpExporter.js +135 -54
- package/dist/observability/OtlpExporter.js.map +1 -1
- package/dist/observability/OtlpLogger.d.ts +14 -0
- package/dist/observability/OtlpLogger.d.ts.map +1 -1
- package/dist/observability/OtlpLogger.js +10 -2
- package/dist/observability/OtlpLogger.js.map +1 -1
- package/dist/observability/OtlpMetrics.d.ts.map +1 -1
- package/dist/observability/OtlpMetrics.js +2 -0
- package/dist/observability/OtlpMetrics.js.map +1 -1
- package/dist/observability/OtlpTracer.d.ts +14 -0
- package/dist/observability/OtlpTracer.d.ts.map +1 -1
- package/dist/observability/OtlpTracer.js +10 -2
- package/dist/observability/OtlpTracer.js.map +1 -1
- package/dist/persistence/KeyValueStore.d.ts.map +1 -1
- package/dist/persistence/KeyValueStore.js +6 -4
- package/dist/persistence/KeyValueStore.js.map +1 -1
- package/dist/reactivity/Atom.d.ts.map +1 -1
- package/dist/reactivity/Atom.js +10 -9
- package/dist/reactivity/Atom.js.map +1 -1
- package/dist/rpc/RpcClient.d.ts.map +1 -1
- package/dist/rpc/RpcClient.js +32 -1
- package/dist/rpc/RpcClient.js.map +1 -1
- package/dist/rpc/RpcGroup.d.ts +1 -1
- package/dist/rpc/RpcGroup.d.ts.map +1 -1
- package/dist/rpc/RpcGroup.js +4 -0
- package/dist/rpc/RpcGroup.js.map +1 -1
- package/dist/sql/Migrator.d.ts.map +1 -1
- package/dist/sql/Migrator.js +2 -5
- package/dist/sql/Migrator.js.map +1 -1
- package/dist/sql/SqlClient.d.ts.map +1 -1
- package/dist/sql/SqlClient.js +5 -1
- package/dist/sql/SqlClient.js.map +1 -1
- package/dist/workflow/Activity.d.ts +18 -0
- package/dist/workflow/Activity.d.ts.map +1 -1
- package/dist/workflow/Activity.js +13 -4
- package/dist/workflow/Activity.js.map +1 -1
- package/dist/workflow/Workflow.d.ts +10 -9
- package/dist/workflow/Workflow.d.ts.map +1 -1
- package/dist/workflow/Workflow.js +33 -22
- package/dist/workflow/Workflow.js.map +1 -1
- package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
- package/dist/workflow/WorkflowEngine.js +26 -12
- package/dist/workflow/WorkflowEngine.js.map +1 -1
- package/dist/workflow/internal/retry.d.ts +2 -0
- package/dist/workflow/internal/retry.d.ts.map +1 -0
- package/dist/workflow/internal/retry.js +11 -0
- package/dist/workflow/internal/retry.js.map +1 -0
- package/dist/workflow/internal/scope.d.ts +2 -0
- package/dist/workflow/internal/scope.d.ts.map +1 -0
- package/dist/workflow/internal/scope.js +26 -0
- package/dist/workflow/internal/scope.js.map +1 -0
- package/package.json +3 -3
- package/src/Channel.ts +105 -8
- package/src/Codegen.ts +7 -2
- package/src/Effect.ts +224 -48
- package/src/Equal.ts +85 -79
- package/src/Hash.ts +30 -22
- package/src/LayerRef.ts +6 -4
- package/src/Logger.ts +68 -25
- package/src/Match.ts +78 -50
- package/src/Order.ts +1 -1
- package/src/Schema.ts +79 -296
- package/src/SchemaAST.ts +0 -1
- package/src/ScopedCache.ts +6 -4
- package/src/Stream.ts +167 -33
- package/src/String.ts +1 -1
- package/src/Tracer.ts +10 -0
- package/src/ai/McpServer.ts +161 -4
- package/src/ai/Prompt.ts +20 -3
- package/src/ai/Skill.ts +236 -0
- package/src/ai/index.ts +6 -0
- package/src/cluster/ClusterWorkflowEngine.ts +172 -96
- package/src/cluster/MessageStorage.ts +51 -2
- package/src/cluster/SqlMessageStorage.ts +81 -34
- package/src/cluster/internal/entityActivation.ts +6 -0
- package/src/cluster/internal/entityManager.ts +8 -4
- package/src/encoding/Base64.ts +5 -1
- package/src/encoding/Base64Url.ts +6 -1
- package/src/encoding/Xml.ts +96 -26
- package/src/http/FetchHttpClient.ts +8 -5
- package/src/http/Headers.ts +309 -3
- package/src/http/HttpClient.ts +19 -7
- package/src/http/HttpClientError.ts +42 -9
- package/src/http/HttpClientRequest.ts +51 -0
- package/src/http/HttpClientResponse.ts +156 -0
- package/src/http/HttpMiddleware.ts +1 -1
- package/src/http/HttpServerResponse.ts +126 -0
- package/src/http/Multipart.ts +0 -5
- package/src/http/MultipartParser/internal/contentType.ts +1 -1
- package/src/http/internal/clientPath.ts +39 -0
- package/src/http/internal/redactedPath.ts +4 -0
- package/src/http/internal/tracing.ts +6 -3
- package/src/http-api/HttpApi.ts +29 -8
- package/src/http-api/HttpApiBuilder.ts +7 -2
- package/src/http-api/HttpApiClient.ts +30 -7
- package/src/http-api/internal/redactedKeys.ts +40 -0
- package/src/internal/base64.ts +57 -2
- package/src/internal/dateTime.ts +43 -24
- package/src/internal/effect.ts +31 -102
- package/src/internal/equal.ts +37 -17
- package/src/internal/hash.ts +5 -1
- package/src/internal/matcher.ts +34 -113
- package/src/internal/schema/schemaCodegen.ts +5 -4
- package/src/internal/schema/schemaCodegenBuiltIns.ts +343 -0
- package/src/internal/schema/toEquivalence.ts +3 -5
- package/src/internal/version.ts +1 -1
- package/src/jose/JoseError.ts +34 -0
- package/src/jose/internal/compact.ts +14 -5
- package/src/observability/Otlp.ts +29 -0
- package/src/observability/OtlpExporter.ts +206 -75
- package/src/observability/OtlpLogger.ts +24 -2
- package/src/observability/OtlpMetrics.ts +2 -0
- package/src/observability/OtlpTracer.ts +24 -3
- package/src/persistence/KeyValueStore.ts +17 -14
- package/src/reactivity/Atom.ts +12 -18
- package/src/rpc/RpcClient.ts +26 -1
- package/src/rpc/RpcGroup.ts +4 -1
- package/src/sql/Migrator.ts +2 -11
- package/src/sql/SqlClient.ts +14 -8
- package/src/workflow/Activity.ts +28 -4
- package/src/workflow/Workflow.ts +68 -44
- package/src/workflow/WorkflowEngine.ts +38 -15
- package/src/workflow/internal/retry.ts +12 -0
- package/src/workflow/internal/scope.ts +36 -0
|
@@ -346,6 +346,162 @@ export const filterStatusOk = (self: HttpClientResponse): Effect.Effect<HttpClie
|
|
|
346
346
|
})
|
|
347
347
|
)
|
|
348
348
|
|
|
349
|
+
/**
|
|
350
|
+
* Returns the links of the response's `Link` header with absolute targets.
|
|
351
|
+
*
|
|
352
|
+
* **Details**
|
|
353
|
+
*
|
|
354
|
+
* Each target is resolved against the response URL, which is the final URL
|
|
355
|
+
* after redirects, so `target` holds an absolute href. Links whose target does
|
|
356
|
+
* not resolve are dropped. A response without a `Link` header gives `[]`.
|
|
357
|
+
*
|
|
358
|
+
* **Gotchas**
|
|
359
|
+
*
|
|
360
|
+
* Links with an `anchor` parameter are dropped, because they describe a
|
|
361
|
+
* resource other than this response (RFC 8288 section 3.2). Parse the raw header
|
|
362
|
+
* with `Headers.parseLink` to read them.
|
|
363
|
+
*
|
|
364
|
+
* @see {@link link} to look up a single link by relation type
|
|
365
|
+
*
|
|
366
|
+
* @stability unstable
|
|
367
|
+
* @category accessors
|
|
368
|
+
* @since 4.1.6
|
|
369
|
+
*/
|
|
370
|
+
export const links = (self: HttpClientResponse): Array<Headers.Link> => {
|
|
371
|
+
const header = self.headers.link
|
|
372
|
+
if (header === undefined) return []
|
|
373
|
+
const base = self.url || undefined
|
|
374
|
+
const out: Array<Headers.Link> = []
|
|
375
|
+
for (const link of Headers.parseLink(header)) {
|
|
376
|
+
if (Object.hasOwn(link.params, "anchor")) continue
|
|
377
|
+
const url = resolveUrl(link.target, base)
|
|
378
|
+
if (url !== undefined) out.push({ ...link, target: url.href })
|
|
379
|
+
}
|
|
380
|
+
return out
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const resolveUrl = (target: string, base: string | undefined): URL | undefined => {
|
|
384
|
+
try {
|
|
385
|
+
return new URL(target, base)
|
|
386
|
+
} catch {
|
|
387
|
+
return undefined
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Returns the URL of the first link in the response's `Link` header with the
|
|
393
|
+
* given relation type.
|
|
394
|
+
*
|
|
395
|
+
* **When to use**
|
|
396
|
+
*
|
|
397
|
+
* Use to follow pagination links such as `next` with `Stream.paginate`.
|
|
398
|
+
*
|
|
399
|
+
* **Details**
|
|
400
|
+
*
|
|
401
|
+
* The relation type is compared case-insensitively, and the URL is resolved
|
|
402
|
+
* against the response URL. Returns `Option.none()` when no link matches.
|
|
403
|
+
* Links are read as by {@link links}, so links with an `anchor` parameter
|
|
404
|
+
* never match.
|
|
405
|
+
*
|
|
406
|
+
* **Example** (Reading the next page link)
|
|
407
|
+
*
|
|
408
|
+
* ```ts import.meta.vitest
|
|
409
|
+
* import { Option } from "effect"
|
|
410
|
+
* import { HttpClientRequest, HttpClientResponse } from "effect/http"
|
|
411
|
+
*
|
|
412
|
+
* const response = HttpClientResponse.fromWeb(
|
|
413
|
+
* HttpClientRequest.get("https://example.com/items"),
|
|
414
|
+
* new Response(null, { headers: { link: '</items?page=2>; rel="next"' } })
|
|
415
|
+
* )
|
|
416
|
+
*
|
|
417
|
+
* Option.map(HttpClientResponse.link(response, "next"), (url) => url.href) // => Option.some("https://example.com/items?page=2")
|
|
418
|
+
* ```
|
|
419
|
+
*
|
|
420
|
+
* @see {@link links} to read every link
|
|
421
|
+
*
|
|
422
|
+
* @stability unstable
|
|
423
|
+
* @category accessors
|
|
424
|
+
* @since 4.1.6
|
|
425
|
+
*/
|
|
426
|
+
export const link: {
|
|
427
|
+
/**
|
|
428
|
+
* Returns the URL of the first link in the response's `Link` header with the
|
|
429
|
+
* given relation type.
|
|
430
|
+
*
|
|
431
|
+
* **When to use**
|
|
432
|
+
*
|
|
433
|
+
* Use to follow pagination links such as `next` with `Stream.paginate`.
|
|
434
|
+
*
|
|
435
|
+
* **Details**
|
|
436
|
+
*
|
|
437
|
+
* The relation type is compared case-insensitively, and the URL is resolved
|
|
438
|
+
* against the response URL. Returns `Option.none()` when no link matches.
|
|
439
|
+
* Links are read as by {@link links}, so links with an `anchor` parameter
|
|
440
|
+
* never match.
|
|
441
|
+
*
|
|
442
|
+
* **Example** (Reading the next page link)
|
|
443
|
+
*
|
|
444
|
+
* ```ts import.meta.vitest
|
|
445
|
+
* import { Option } from "effect"
|
|
446
|
+
* import { HttpClientRequest, HttpClientResponse } from "effect/http"
|
|
447
|
+
*
|
|
448
|
+
* const response = HttpClientResponse.fromWeb(
|
|
449
|
+
* HttpClientRequest.get("https://example.com/items"),
|
|
450
|
+
* new Response(null, { headers: { link: '</items?page=2>; rel="next"' } })
|
|
451
|
+
* )
|
|
452
|
+
*
|
|
453
|
+
* Option.map(HttpClientResponse.link(response, "next"), (url) => url.href) // => Option.some("https://example.com/items?page=2")
|
|
454
|
+
* ```
|
|
455
|
+
*
|
|
456
|
+
* @see {@link links} to read every link
|
|
457
|
+
*
|
|
458
|
+
* @stability unstable
|
|
459
|
+
* @category accessors
|
|
460
|
+
* @since 4.1.6
|
|
461
|
+
*/
|
|
462
|
+
(rel: string): (self: HttpClientResponse) => Option.Option<URL>
|
|
463
|
+
/**
|
|
464
|
+
* Returns the URL of the first link in the response's `Link` header with the
|
|
465
|
+
* given relation type.
|
|
466
|
+
*
|
|
467
|
+
* **When to use**
|
|
468
|
+
*
|
|
469
|
+
* Use to follow pagination links such as `next` with `Stream.paginate`.
|
|
470
|
+
*
|
|
471
|
+
* **Details**
|
|
472
|
+
*
|
|
473
|
+
* The relation type is compared case-insensitively, and the URL is resolved
|
|
474
|
+
* against the response URL. Returns `Option.none()` when no link matches.
|
|
475
|
+
* Links are read as by {@link links}, so links with an `anchor` parameter
|
|
476
|
+
* never match.
|
|
477
|
+
*
|
|
478
|
+
* **Example** (Reading the next page link)
|
|
479
|
+
*
|
|
480
|
+
* ```ts import.meta.vitest
|
|
481
|
+
* import { Option } from "effect"
|
|
482
|
+
* import { HttpClientRequest, HttpClientResponse } from "effect/http"
|
|
483
|
+
*
|
|
484
|
+
* const response = HttpClientResponse.fromWeb(
|
|
485
|
+
* HttpClientRequest.get("https://example.com/items"),
|
|
486
|
+
* new Response(null, { headers: { link: '</items?page=2>; rel="next"' } })
|
|
487
|
+
* )
|
|
488
|
+
*
|
|
489
|
+
* Option.map(HttpClientResponse.link(response, "next"), (url) => url.href) // => Option.some("https://example.com/items?page=2")
|
|
490
|
+
* ```
|
|
491
|
+
*
|
|
492
|
+
* @see {@link links} to read every link
|
|
493
|
+
*
|
|
494
|
+
* @stability unstable
|
|
495
|
+
* @category accessors
|
|
496
|
+
* @since 4.1.6
|
|
497
|
+
*/
|
|
498
|
+
(self: HttpClientResponse, rel: string): Option.Option<URL>
|
|
499
|
+
} = dual(2, (self: HttpClientResponse, rel: string): Option.Option<URL> => {
|
|
500
|
+
const type = rel.toLowerCase()
|
|
501
|
+
const found = links(self).find((link) => link.rel.includes(type))
|
|
502
|
+
return found === undefined ? Option.none() : Option.some(new URL(found.target))
|
|
503
|
+
})
|
|
504
|
+
|
|
349
505
|
// -----------------------------------------------------------------------------
|
|
350
506
|
// internal
|
|
351
507
|
// -----------------------------------------------------------------------------
|
|
@@ -608,7 +608,7 @@ export const cors = (options?: {
|
|
|
608
608
|
? { "access-control-expose-headers": opts.exposedHeaders.join(",") }
|
|
609
609
|
: undefined
|
|
610
610
|
|
|
611
|
-
const maxAge = opts.maxAge
|
|
611
|
+
const maxAge = opts.maxAge === 0 || opts.maxAge
|
|
612
612
|
? { "access-control-max-age": opts.maxAge.toString() }
|
|
613
613
|
: undefined
|
|
614
614
|
|
|
@@ -597,6 +597,132 @@ export const setHeader: {
|
|
|
597
597
|
makeResponse(self, Headers.set(self.headers, key, value))
|
|
598
598
|
)
|
|
599
599
|
|
|
600
|
+
/**
|
|
601
|
+
* Returns a response with the value added to the specified header, keeping any
|
|
602
|
+
* existing value.
|
|
603
|
+
*
|
|
604
|
+
* **When to use**
|
|
605
|
+
*
|
|
606
|
+
* Use when several parts of an application each add to a list-valued header,
|
|
607
|
+
* such as `Link` or `Vary`.
|
|
608
|
+
*
|
|
609
|
+
* **Details**
|
|
610
|
+
*
|
|
611
|
+
* An existing value is joined with the new one by `", "`, and an empty value
|
|
612
|
+
* leaves the response unchanged, so formatting an empty list of links is safe.
|
|
613
|
+
*
|
|
614
|
+
* **Gotchas**
|
|
615
|
+
*
|
|
616
|
+
* Do not append `Set-Cookie` this way; use the cookie APIs instead.
|
|
617
|
+
*
|
|
618
|
+
* **Example** (Adding canonical and alternate links)
|
|
619
|
+
*
|
|
620
|
+
* ```ts
|
|
621
|
+
* import { Headers, HttpServerResponse } from "effect/http"
|
|
622
|
+
*
|
|
623
|
+
* const withLinks = HttpServerResponse.appendHeader(
|
|
624
|
+
* "Link",
|
|
625
|
+
* Headers.formatLink([
|
|
626
|
+
* { target: "https://example.com/en", rel: ["canonical"] },
|
|
627
|
+
* { target: "https://example.com/de", rel: ["alternate"], params: { hreflang: "de" } }
|
|
628
|
+
* ])
|
|
629
|
+
* )
|
|
630
|
+
* ```
|
|
631
|
+
*
|
|
632
|
+
* @see {@link setHeader} to replace a header value
|
|
633
|
+
*
|
|
634
|
+
* @stability unstable
|
|
635
|
+
* @category combinators
|
|
636
|
+
* @since 4.1.6
|
|
637
|
+
*/
|
|
638
|
+
export const appendHeader: {
|
|
639
|
+
/**
|
|
640
|
+
* Returns a response with the value added to the specified header, keeping any
|
|
641
|
+
* existing value.
|
|
642
|
+
*
|
|
643
|
+
* **When to use**
|
|
644
|
+
*
|
|
645
|
+
* Use when several parts of an application each add to a list-valued header,
|
|
646
|
+
* such as `Link` or `Vary`.
|
|
647
|
+
*
|
|
648
|
+
* **Details**
|
|
649
|
+
*
|
|
650
|
+
* An existing value is joined with the new one by `", "`, and an empty value
|
|
651
|
+
* leaves the response unchanged, so formatting an empty list of links is safe.
|
|
652
|
+
*
|
|
653
|
+
* **Gotchas**
|
|
654
|
+
*
|
|
655
|
+
* Do not append `Set-Cookie` this way; use the cookie APIs instead.
|
|
656
|
+
*
|
|
657
|
+
* **Example** (Adding canonical and alternate links)
|
|
658
|
+
*
|
|
659
|
+
* ```ts
|
|
660
|
+
* import { Headers, HttpServerResponse } from "effect/http"
|
|
661
|
+
*
|
|
662
|
+
* const withLinks = HttpServerResponse.appendHeader(
|
|
663
|
+
* "Link",
|
|
664
|
+
* Headers.formatLink([
|
|
665
|
+
* { target: "https://example.com/en", rel: ["canonical"] },
|
|
666
|
+
* { target: "https://example.com/de", rel: ["alternate"], params: { hreflang: "de" } }
|
|
667
|
+
* ])
|
|
668
|
+
* )
|
|
669
|
+
* ```
|
|
670
|
+
*
|
|
671
|
+
* @see {@link setHeader} to replace a header value
|
|
672
|
+
*
|
|
673
|
+
* @stability unstable
|
|
674
|
+
* @category combinators
|
|
675
|
+
* @since 4.1.6
|
|
676
|
+
*/
|
|
677
|
+
(key: string, value: string): (self: HttpServerResponse) => HttpServerResponse
|
|
678
|
+
/**
|
|
679
|
+
* Returns a response with the value added to the specified header, keeping any
|
|
680
|
+
* existing value.
|
|
681
|
+
*
|
|
682
|
+
* **When to use**
|
|
683
|
+
*
|
|
684
|
+
* Use when several parts of an application each add to a list-valued header,
|
|
685
|
+
* such as `Link` or `Vary`.
|
|
686
|
+
*
|
|
687
|
+
* **Details**
|
|
688
|
+
*
|
|
689
|
+
* An existing value is joined with the new one by `", "`, and an empty value
|
|
690
|
+
* leaves the response unchanged, so formatting an empty list of links is safe.
|
|
691
|
+
*
|
|
692
|
+
* **Gotchas**
|
|
693
|
+
*
|
|
694
|
+
* Do not append `Set-Cookie` this way; use the cookie APIs instead.
|
|
695
|
+
*
|
|
696
|
+
* **Example** (Adding canonical and alternate links)
|
|
697
|
+
*
|
|
698
|
+
* ```ts
|
|
699
|
+
* import { Headers, HttpServerResponse } from "effect/http"
|
|
700
|
+
*
|
|
701
|
+
* const withLinks = HttpServerResponse.appendHeader(
|
|
702
|
+
* "Link",
|
|
703
|
+
* Headers.formatLink([
|
|
704
|
+
* { target: "https://example.com/en", rel: ["canonical"] },
|
|
705
|
+
* { target: "https://example.com/de", rel: ["alternate"], params: { hreflang: "de" } }
|
|
706
|
+
* ])
|
|
707
|
+
* )
|
|
708
|
+
* ```
|
|
709
|
+
*
|
|
710
|
+
* @see {@link setHeader} to replace a header value
|
|
711
|
+
*
|
|
712
|
+
* @stability unstable
|
|
713
|
+
* @category combinators
|
|
714
|
+
* @since 4.1.6
|
|
715
|
+
*/
|
|
716
|
+
(self: HttpServerResponse, key: string, value: string): HttpServerResponse
|
|
717
|
+
} = dual(
|
|
718
|
+
3,
|
|
719
|
+
(self: HttpServerResponse, key: string, value: string): HttpServerResponse => {
|
|
720
|
+
const headers = Headers.append(self.headers, key, value)
|
|
721
|
+
// makeResponse mutates the headers map in place, so never pass self.headers
|
|
722
|
+
return headers === self.headers ? self : makeResponse(self, headers)
|
|
723
|
+
}
|
|
724
|
+
)
|
|
725
|
+
|
|
600
726
|
/**
|
|
601
727
|
* Returns a response with the specified header removed.
|
|
602
728
|
*
|
package/src/http/Multipart.ts
CHANGED
|
@@ -350,11 +350,6 @@ export const PersistedFileSchema: PersistedFileSchema = Schema.declare(
|
|
|
350
350
|
id: "effect/http/PersistedFile",
|
|
351
351
|
payload: null
|
|
352
352
|
},
|
|
353
|
-
toCode: () => ({
|
|
354
|
-
runtime: "Multipart.PersistedFileSchema",
|
|
355
|
-
Type: "Multipart.PersistedFile",
|
|
356
|
-
importDeclarations: [`import * as Multipart from "effect/http/Multipart"`]
|
|
357
|
-
}),
|
|
358
353
|
expected: "PersistedFile",
|
|
359
354
|
toCodecJson: () =>
|
|
360
355
|
Schema.link<PersistedFile>()(
|
|
@@ -116,7 +116,7 @@ const pctEncodedRE = /%([0-9a-f]{2})/gi
|
|
|
116
116
|
* ISO-8859-1 is decoded byte by byte because `TextDecoder` treats it as
|
|
117
117
|
* windows-1252.
|
|
118
118
|
*/
|
|
119
|
-
function decodeExtValue(value: string): string | undefined {
|
|
119
|
+
export function decodeExtValue(value: string): string | undefined {
|
|
120
120
|
const match = extValueRE.exec(value)
|
|
121
121
|
if (match === null) {
|
|
122
122
|
return undefined
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as Context from "../../Context.ts"
|
|
2
|
+
import * as Redactable from "../../Redactable.ts"
|
|
3
|
+
import { stripSearchAndHash } from "./urlParams.ts"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The path of the request a client executes, as sent and as recorded in spans
|
|
7
|
+
* and errors.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export interface ClientPath {
|
|
12
|
+
readonly sent: string
|
|
13
|
+
readonly redacted: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** @internal */
|
|
17
|
+
export const CurrentClientPath = Context.Reference<ClientPath | undefined>(
|
|
18
|
+
"effect/http/internal/clientPath/CurrentClientPath",
|
|
19
|
+
{ defaultValue: () => undefined }
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
/** @internal */
|
|
23
|
+
export const currentClientPath = (): ClientPath | undefined =>
|
|
24
|
+
Context.get((globalThis as any)[Redactable.currentFiberTypeId]?.context ?? Context.empty(), CurrentClientPath)
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Replaces the path of a URL with its redacted form. A pathname that does not
|
|
28
|
+
* match the expected sent pathname is replaced by `/REDACTED`.
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export const redactClientPath = (url: string, path: ClientPath): string => {
|
|
33
|
+
const head = stripSearchAndHash(url)
|
|
34
|
+
const origin = /^[a-z][a-z\d+.-]*:\/\/[^/]*/i.exec(head)?.[0] ?? ""
|
|
35
|
+
const pathname = head.slice(origin.length)
|
|
36
|
+
if (pathname === path.redacted) return url
|
|
37
|
+
const tail = url.slice(head.length)
|
|
38
|
+
return origin + (pathname === path.sent ? path.redacted : "/REDACTED") + tail
|
|
39
|
+
}
|
|
@@ -60,6 +60,10 @@ export const compile = (path: string, redactedParams: ReadonlyArray<string>): Te
|
|
|
60
60
|
return ambiguous ? parts.map((part) => typeof part === "string" ? part : { name: part.name, redacted: true }) : parts
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/** @internal */
|
|
64
|
+
export const allParamNames = (path: string): ReadonlyArray<string> =>
|
|
65
|
+
compile(path, []).flatMap((part) => typeof part === "string" ? [] : [part.name])
|
|
66
|
+
|
|
63
67
|
const countCaptures = (regex: string): number => {
|
|
64
68
|
try {
|
|
65
69
|
return new RegExp(regex + "|").exec("")!.length - 1
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type * as Tracer from "../../Tracer.ts"
|
|
2
2
|
import * as Headers from "../Headers.ts"
|
|
3
3
|
import * as UrlParams from "../UrlParams.ts"
|
|
4
|
+
import { type ClientPath, redactClientPath } from "./clientPath.ts"
|
|
4
5
|
|
|
5
6
|
const defaultPorts: Record<string, number> = {
|
|
6
7
|
"http:": 80,
|
|
@@ -17,11 +18,13 @@ const defaultPorts: Record<string, number> = {
|
|
|
17
18
|
export const addUrlAttributes = (
|
|
18
19
|
span: Tracer.Span,
|
|
19
20
|
url: URL,
|
|
20
|
-
redactedNames: ReadonlyArray<string | RegExp
|
|
21
|
+
redactedNames: ReadonlyArray<string | RegExp>,
|
|
22
|
+
path?: ClientPath | undefined
|
|
21
23
|
): void => {
|
|
24
|
+
const redactPath = (url: string) => path === undefined ? url : redactClientPath(url, path)
|
|
22
25
|
const query = UrlParams.redactUrl(url.search, redactedNames).slice(1)
|
|
23
|
-
span.attribute("url.full", UrlParams.redactUrl(url.href, redactedNames))
|
|
24
|
-
span.attribute("url.path", url.pathname)
|
|
26
|
+
span.attribute("url.full", redactPath(UrlParams.redactUrl(url.href, redactedNames)))
|
|
27
|
+
span.attribute("url.path", redactPath(url.pathname))
|
|
25
28
|
if (query !== "") {
|
|
26
29
|
span.attribute("url.query", query)
|
|
27
30
|
}
|
package/src/http-api/HttpApi.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import type { NonEmptyReadonlyArray } from "../Array.ts"
|
|
13
13
|
import * as Context from "../Context.ts"
|
|
14
|
+
import * as HttpMethod from "../http/HttpMethod.ts"
|
|
14
15
|
import type { PathInput } from "../http/HttpRouter.ts"
|
|
15
16
|
import * as InternalRecord from "../internal/record.ts"
|
|
16
17
|
import { type Pipeable, pipeArguments } from "../Pipeable.ts"
|
|
@@ -23,6 +24,7 @@ import * as HttpApiEndpoint from "./HttpApiEndpoint.ts"
|
|
|
23
24
|
import type * as HttpApiGroup from "./HttpApiGroup.ts"
|
|
24
25
|
import type * as HttpApiMiddleware from "./HttpApiMiddleware.ts"
|
|
25
26
|
import * as HttpApiSchema from "./HttpApiSchema.ts"
|
|
27
|
+
import { getRedactedKeys } from "./internal/redactedKeys.ts"
|
|
26
28
|
|
|
27
29
|
const TypeId = "~effect/http-api/HttpApi"
|
|
28
30
|
|
|
@@ -512,8 +514,8 @@ export class ErrorParseOptions extends Context.Service<
|
|
|
512
514
|
* the names on the group to keep both.
|
|
513
515
|
* - Only URL and header attributes use these names. `user_agent.original` and
|
|
514
516
|
* the messages of span errors are recorded as is.
|
|
515
|
-
* - `params` apply to
|
|
516
|
-
*
|
|
517
|
+
* - `params` apply to client spans and error messages as well as server spans
|
|
518
|
+
* and `HttpMiddleware.logger` entries.
|
|
517
519
|
* - `HttpApiBuilder.endpoint` returns a handler without a route, so set
|
|
518
520
|
* `redactedParams` on the route it is mounted with.
|
|
519
521
|
*
|
|
@@ -590,26 +592,45 @@ export const getEndpointRedactedNames = (
|
|
|
590
592
|
): EndpointRedactedNames | undefined => {
|
|
591
593
|
const query: Array<string | RegExp> = []
|
|
592
594
|
const headers: Array<string | RegExp> = []
|
|
595
|
+
const addQuery = (name: string | RegExp) => {
|
|
596
|
+
query.push(name)
|
|
597
|
+
if (typeof name === "string") query.push(new RegExp(`^${RegExp_.escape(name)}\\[`, "i"))
|
|
598
|
+
}
|
|
593
599
|
for (const annotations of [api.annotations, group.annotations, endpoint.annotations]) {
|
|
594
600
|
const options = Context.getOrUndefined(annotations, RedactedNames)
|
|
595
601
|
if (options === undefined) continue
|
|
596
|
-
|
|
597
|
-
query.push(name)
|
|
598
|
-
if (typeof name === "string") query.push(new RegExp(`^${RegExp_.escape(name)}\\[`, "i"))
|
|
599
|
-
}
|
|
602
|
+
options.query?.forEach(addQuery)
|
|
600
603
|
if (options.headers !== undefined) headers.push(...options.headers)
|
|
601
604
|
}
|
|
605
|
+
// Fields whose schema holds a `Redacted` are redacted without being listed.
|
|
606
|
+
// Payloads of methods without a body are sent as query parameters.
|
|
607
|
+
const querySchemas = HttpMethod.hasBody(endpoint.method)
|
|
608
|
+
? [endpoint.query]
|
|
609
|
+
: [endpoint.query, ...HttpApiEndpoint.getPayloadSchemas(endpoint)]
|
|
610
|
+
for (const schema of querySchemas) (getRedactedKeys(schema) ?? redactAll).forEach(addQuery)
|
|
611
|
+
headers.push(...(getRedactedKeys(endpoint.headers) ?? redactAll))
|
|
602
612
|
return query.length === 0 && headers.length === 0 ? undefined : { query, headers }
|
|
603
613
|
}
|
|
604
614
|
|
|
605
615
|
/**
|
|
616
|
+
* Returns the path param names to redact and whether to redact every param in
|
|
617
|
+
* the endpoint path (when the schema holds a `Redacted` under unknown wire names).
|
|
618
|
+
*
|
|
606
619
|
* @internal
|
|
607
620
|
*/
|
|
608
621
|
export const getEndpointRedactedParams = (
|
|
609
622
|
api: Pick<Top, "annotations">,
|
|
610
623
|
group: HttpApiGroup.Top,
|
|
611
624
|
endpoint: HttpApiEndpoint.Top
|
|
612
|
-
): ReadonlyArray<string
|
|
613
|
-
[api.annotations, group.annotations, endpoint.annotations].flatMap((annotations) =>
|
|
625
|
+
): { readonly names: ReadonlyArray<string>; readonly all: boolean } => {
|
|
626
|
+
const explicit = [api.annotations, group.annotations, endpoint.annotations].flatMap((annotations) =>
|
|
614
627
|
Context.getOrUndefined(annotations, RedactedNames)?.params ?? []
|
|
615
628
|
)
|
|
629
|
+
const keys = getRedactedKeys(endpoint.params)
|
|
630
|
+
return keys === undefined
|
|
631
|
+
? { names: explicit, all: true }
|
|
632
|
+
: { names: [...explicit, ...keys], all: false }
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// Matches every name, for a schema whose wire names are unknown.
|
|
636
|
+
const redactAll: ReadonlyArray<RegExp> = [/^/]
|
|
@@ -32,6 +32,7 @@ import * as Respondable from "../http/HttpServerRespondable.ts"
|
|
|
32
32
|
import * as Response from "../http/HttpServerResponse.ts"
|
|
33
33
|
import type { HttpServerResponse } from "../http/HttpServerResponse.ts"
|
|
34
34
|
import * as MediaType from "../http/internal/mediaType.ts"
|
|
35
|
+
import * as RedactedPath from "../http/internal/redactedPath.ts"
|
|
35
36
|
import { addRedactedNamesUnsafe } from "../http/internal/requestState.ts"
|
|
36
37
|
import * as Multipart from "../http/Multipart.ts"
|
|
37
38
|
import * as UrlParams from "../http/UrlParams.ts"
|
|
@@ -1077,13 +1078,17 @@ export function handlerToRoute(
|
|
|
1077
1078
|
context: Context.Context<any>
|
|
1078
1079
|
): HttpRouter.Route<any, any> {
|
|
1079
1080
|
const endpoint = handler.endpoint
|
|
1081
|
+
const path = HttpApiPath.toRouterPath(endpoint.path, endpoint.params)
|
|
1082
|
+
const redactedParams = HttpApi.getEndpointRedactedParams(api, group, endpoint)
|
|
1080
1083
|
return HttpRouter.route(
|
|
1081
1084
|
endpoint.method,
|
|
1082
|
-
|
|
1085
|
+
path as HttpRouter.PathInput,
|
|
1083
1086
|
handlerToHttpEffect(api, group, endpoint, context, handler.handler, handler.isRaw),
|
|
1084
1087
|
{
|
|
1085
1088
|
uninterruptible: handler.uninterruptible,
|
|
1086
|
-
redactedParams:
|
|
1089
|
+
redactedParams: redactedParams.all
|
|
1090
|
+
? [...redactedParams.names, ...RedactedPath.allParamNames(path)]
|
|
1091
|
+
: redactedParams.names
|
|
1087
1092
|
}
|
|
1088
1093
|
)
|
|
1089
1094
|
}
|
|
@@ -26,6 +26,7 @@ import * as HttpClientError from "../http/HttpClientError.ts"
|
|
|
26
26
|
import * as HttpClientRequest from "../http/HttpClientRequest.ts"
|
|
27
27
|
import type * as HttpClientResponse from "../http/HttpClientResponse.ts"
|
|
28
28
|
import * as HttpMethod from "../http/HttpMethod.ts"
|
|
29
|
+
import { type ClientPath, CurrentClientPath } from "../http/internal/clientPath.ts"
|
|
29
30
|
import * as MediaType from "../http/internal/mediaType.ts"
|
|
30
31
|
import * as internalUrlParams from "../http/internal/urlParams.ts"
|
|
31
32
|
import * as UrlParams from "../http/UrlParams.ts"
|
|
@@ -421,11 +422,16 @@ export const makeClient = <ApiId extends string, Groups extends HttpApiGroup.Con
|
|
|
421
422
|
Effect.gen(function*() {
|
|
422
423
|
const services = yield* Effect.context()
|
|
423
424
|
|
|
425
|
+
const baseUrl = options?.baseUrl?.toString()
|
|
426
|
+
const fullPath = (path: string) =>
|
|
427
|
+
baseUrl === undefined
|
|
428
|
+
? path
|
|
429
|
+
: internalUrlParams.toPath(HttpClientRequest.prependUrl(HttpClientRequest.get(path), baseUrl).url)
|
|
424
430
|
const httpClient = options.httpClient.pipe(
|
|
425
|
-
|
|
431
|
+
baseUrl === undefined
|
|
426
432
|
? identity
|
|
427
433
|
: HttpClient.mapRequest(
|
|
428
|
-
HttpClientRequest.prependUrl(
|
|
434
|
+
HttpClientRequest.prependUrl(baseUrl)
|
|
429
435
|
)
|
|
430
436
|
)
|
|
431
437
|
|
|
@@ -508,6 +514,10 @@ export const makeClient = <ApiId extends string, Groups extends HttpApiGroup.Con
|
|
|
508
514
|
|
|
509
515
|
const middlewareKeys = Array.from(onEndpointOptions.middleware, (tag) => `${tag.key}/Client`)
|
|
510
516
|
const redactedNames = HttpApi.getEndpointRedactedNames(api, group, endpoint)
|
|
517
|
+
const redactedParams = HttpApi.getEndpointRedactedParams(api, group, endpoint)
|
|
518
|
+
// Names declared on the API or group may belong to other endpoints.
|
|
519
|
+
const redactsPath = redactedParams.all ||
|
|
520
|
+
redactedParams.names.some((name) => endpoint.path.includes(`:${name}`))
|
|
511
521
|
|
|
512
522
|
const endpointFn = Effect.fnUntraced(function*(
|
|
513
523
|
request: {
|
|
@@ -520,12 +530,20 @@ export const makeClient = <ApiId extends string, Groups extends HttpApiGroup.Con
|
|
|
520
530
|
} | undefined
|
|
521
531
|
) {
|
|
522
532
|
let httpRequest = HttpClientRequest.make(endpoint.method)(endpoint.path)
|
|
533
|
+
let redactedPath: ClientPath | undefined
|
|
523
534
|
|
|
524
535
|
if (request !== undefined) {
|
|
525
536
|
// params
|
|
526
537
|
if (encodeParams !== undefined) {
|
|
527
538
|
const params = (yield* encodeParams(request.params)) as Record<string, string>
|
|
528
|
-
|
|
539
|
+
const sent = makeUrl(params)
|
|
540
|
+
httpRequest = HttpClientRequest.setUrl(httpRequest, sent)
|
|
541
|
+
if (redactsPath) {
|
|
542
|
+
redactedPath = {
|
|
543
|
+
sent: fullPath(sent),
|
|
544
|
+
redacted: fullPath(makeUrl(params, redactedParams.all ? "*" : redactedParams.names))
|
|
545
|
+
}
|
|
546
|
+
}
|
|
529
547
|
}
|
|
530
548
|
|
|
531
549
|
// payload
|
|
@@ -583,7 +601,10 @@ export const makeClient = <ApiId extends string, Groups extends HttpApiGroup.Con
|
|
|
583
601
|
middlewareKeys,
|
|
584
602
|
middlewareKeys.length - 1
|
|
585
603
|
)
|
|
586
|
-
const
|
|
604
|
+
const named = redactedNames === undefined ? execute : withRedactedNames(execute, redactedNames)
|
|
605
|
+
const response = yield* (redactedPath === undefined
|
|
606
|
+
? named
|
|
607
|
+
: Effect.provideService(named, CurrentClientPath, redactedPath))
|
|
587
608
|
|
|
588
609
|
if (request?.responseMode === "response-only") {
|
|
589
610
|
return response
|
|
@@ -972,17 +993,19 @@ export const urlBuilder = <Api extends HttpApi.Constraint>(api: Api, options?: {
|
|
|
972
993
|
|
|
973
994
|
const compilePath = (path: string, schema: Schema.Top | undefined) => {
|
|
974
995
|
if (schema === undefined || !path.includes(":")) {
|
|
975
|
-
return (_: any) => path
|
|
996
|
+
return (_: any, _redacted?: ReadonlyArray<string> | "*") => path
|
|
976
997
|
}
|
|
977
998
|
const paramNames = HttpApiPath.getParamNames(schema)
|
|
978
|
-
return (params: Record<string, string | undefined>) =>
|
|
999
|
+
return (params: Record<string, string | undefined>, redacted?: ReadonlyArray<string> | "*") =>
|
|
979
1000
|
HttpApiPath.replaceParams(path, paramNames, (key, optional) => {
|
|
980
1001
|
const value = params[key]
|
|
981
1002
|
if (value === "." || value === "..") {
|
|
982
1003
|
// dot segments survive encoding and would be resolved by URL normalization
|
|
983
1004
|
throw new Error(`Invalid path parameter: ${key}`)
|
|
984
1005
|
}
|
|
985
|
-
if (value !== undefined)
|
|
1006
|
+
if (value !== undefined) {
|
|
1007
|
+
return redacted === "*" || redacted?.includes(key) ? "REDACTED" : encodeURIComponent(value)
|
|
1008
|
+
}
|
|
986
1009
|
if (optional) return undefined
|
|
987
1010
|
throw new Error(`Missing path parameter: ${key}`)
|
|
988
1011
|
})
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type * as Schema from "../../Schema.ts"
|
|
2
|
+
import * as SchemaAST from "../../SchemaAST.ts"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the wire keys of a params, query or headers schema whose values hold
|
|
6
|
+
* a `Redacted`, or `undefined` when a `Redacted` is present but the wire keys
|
|
7
|
+
* are unknown, so the caller redacts everything.
|
|
8
|
+
*
|
|
9
|
+
* Keys are only known for a struct whose keys are encoded as is.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export const getRedactedKeys = (schema: Schema.Top | undefined): ReadonlyArray<string> | undefined => {
|
|
14
|
+
if (schema === undefined) return []
|
|
15
|
+
const ast = schema.ast
|
|
16
|
+
if (!SchemaAST.isObjects(ast) || ast.encoding !== undefined) return hasRedacted(ast, new Set()) ? undefined : []
|
|
17
|
+
if (ast.indexSignatures.some((is) => hasRedacted(is.type, new Set()))) return undefined
|
|
18
|
+
return ast.propertySignatures.filter((ps) => hasRedacted(ps.type, new Set())).map((ps) => String(ps.name))
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const hasRedacted = (ast: SchemaAST.AST, seen: Set<SchemaAST.AST>): boolean => {
|
|
22
|
+
const go = (ast: SchemaAST.AST) => hasRedacted(ast, seen)
|
|
23
|
+
switch (ast._tag) {
|
|
24
|
+
case "Declaration":
|
|
25
|
+
return (ast.annotations as Schema.Annotations.Declaration<unknown, readonly []> | undefined)?.representation
|
|
26
|
+
?.id === "effect/schema/Redacted" || ast.typeParameters.some(go)
|
|
27
|
+
case "Objects":
|
|
28
|
+
return ast.propertySignatures.some((ps) => go(ps.type)) || ast.indexSignatures.some((is) => go(is.type))
|
|
29
|
+
case "Union":
|
|
30
|
+
return ast.types.some(go)
|
|
31
|
+
case "Arrays":
|
|
32
|
+
return ast.elements.some(go) || ast.rest.some(go)
|
|
33
|
+
case "Suspend":
|
|
34
|
+
if (seen.has(ast)) return false
|
|
35
|
+
seen.add(ast)
|
|
36
|
+
return go(ast.thunk())
|
|
37
|
+
default:
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
40
|
+
}
|