@useairfoil/effect-vcr 0.4.8 → 0.4.9
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/LICENSE.txt +201 -0
- package/dist/index.mjs +1 -1
- package/dist/{vcr-http-client-5K20k6US.mjs → vcr-http-client-DfDxGM-a.mjs} +4 -3
- package/dist/{vcr-http-client-5K20k6US.mjs.map → vcr-http-client-DfDxGM-a.mjs.map} +1 -1
- package/dist/vcr-http-client.mjs +1 -1
- package/package.json +12 -12
- package/src/vcr-http-client.ts +3 -2
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 GNC Labs Limited
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
193
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
194
|
+
License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
199
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
200
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
201
|
+
specific language governing permissions and limitations under the License.
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CassetteFileSchema, CassetteSchema, VcrEntrySchema, VcrRequestSchema, VcrResponseSchema } from "./types.mjs";
|
|
2
2
|
import { t as cassette_store_exports } from "./cassette-store.mjs";
|
|
3
3
|
import { t as file_system_cassette_store_exports } from "./file-system-cassette-store.mjs";
|
|
4
|
-
import { r as vcr_http_client_exports } from "./vcr-http-client-
|
|
4
|
+
import { r as vcr_http_client_exports } from "./vcr-http-client-DfDxGM-a.mjs";
|
|
5
5
|
export { CassetteFileSchema, CassetteSchema, cassette_store_exports as CassetteStore, file_system_cassette_store_exports as FileSystemCassetteStore, VcrEntrySchema, vcr_http_client_exports as VcrHttpClient, VcrRequestSchema, VcrResponseSchema };
|
|
@@ -348,8 +348,9 @@ const findEntry = (request, cassette, config) => {
|
|
|
348
348
|
}).pipe(Effect.map((key) => cassette.entries[key]));
|
|
349
349
|
};
|
|
350
350
|
const replayResponse = (request, entry) => {
|
|
351
|
-
const
|
|
352
|
-
|
|
351
|
+
const { status, body } = entry.response;
|
|
352
|
+
const web = new Response(status === 204 || status === 205 || status === 304 ? null : body, {
|
|
353
|
+
status,
|
|
353
354
|
headers: entry.response.headers
|
|
354
355
|
});
|
|
355
356
|
return HttpClientResponse.fromWeb(request, web);
|
|
@@ -447,4 +448,4 @@ const layer = (config = {}) => HttpClient.layerMergedContext(makeVcrHttpClient(c
|
|
|
447
448
|
//#endregion
|
|
448
449
|
export { layer as n, vcr_http_client_exports as r, VcrHttpClientError as t };
|
|
449
450
|
|
|
450
|
-
//# sourceMappingURL=vcr-http-client-
|
|
451
|
+
//# sourceMappingURL=vcr-http-client-DfDxGM-a.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vcr-http-client-5K20k6US.mjs","names":["Arr","Arr"],"sources":["../src/sanitize.ts","../src/vcr-http-client.ts"],"sourcesContent":["import { Array as Arr, Effect, Option, Record, Result } from \"effect\";\nimport { Url, UrlParams } from \"effect/http\";\nimport stableStringify from \"json-stable-stringify\";\n\nimport type { VcrRedactedValue, VcrRequest, VcrResponse } from \"./types\";\n\n/**\n * Normalize header names to match HttpClient's lowercase behavior.\n */\nconst normalizeHeaderKey = (key: string) => key.toLowerCase();\n\n/**\n * Canonicalize headers: lowercase keys and stable ordering.\n */\nconst toHeaderRecord = (headers?: Record<string, string>) => {\n if (!headers) return undefined;\n const lowered = Record.mapKeys(headers, normalizeHeaderKey);\n return Record.fromEntries(Record.toEntries(lowered).sort(([a], [b]) => a.localeCompare(b)));\n};\n\n/**\n * Remove specified header names (case-insensitive).\n */\nconst omitHeaderKeys = (\n headers: Record<string, string> | undefined,\n ignore: ReadonlyArray<string> | undefined,\n): Option.Option<Record<string, string>> => {\n if (!headers) return Option.none();\n if (!ignore || ignore.length === 0) return Option.some(headers);\n const ignoreSet = new Set(ignore.map(normalizeHeaderKey));\n return Option.some(Record.filter(headers, (_, key) => !ignoreSet.has(normalizeHeaderKey(key))));\n};\n\n/**\n * Best-effort JSON parse; returns undefined for non-JSON bodies.\n */\nconst tryParseJson = Option.liftThrowable((input: string) => JSON.parse(input));\n\ntype BodyOptions = {\n readonly omit?: ReadonlyArray<string>;\n readonly replacements?: Readonly<Record<string, VcrRedactedValue>>;\n};\n\ntype BodyTransformation<A> = {\n readonly value: A;\n readonly redacted: boolean;\n};\n\n/**\n * Recursively remove or replace keys in JSON values.\n */\nconst transformJsonKeys = (\n value: unknown,\n omit: ReadonlySet<string>,\n replacements: Readonly<Record<string, VcrRedactedValue>>,\n): BodyTransformation<unknown> => {\n if (Array.isArray(value)) {\n let redacted = false;\n const values = value.map((item) => {\n const transformed = transformJsonKeys(item, omit, replacements);\n redacted ||= transformed.redacted;\n return transformed.value;\n });\n return { value: values, redacted };\n }\n if (value && typeof value === \"object\") {\n const record = value as Record<string, unknown>;\n const next: Record<string, unknown> = {};\n let redacted = false;\n for (const [key, entry] of Object.entries(record)) {\n if (omit.has(key)) {\n redacted = true;\n continue;\n }\n if (Record.has(replacements, key)) {\n next[key] = replacements[key];\n redacted = true;\n continue;\n }\n const transformed = transformJsonKeys(entry, omit, replacements);\n next[key] = transformed.value;\n redacted ||= transformed.redacted;\n }\n return { value: next, redacted };\n }\n return { value, redacted: false };\n};\n\nconst headerValue = (\n headers: Readonly<Record<string, string>> | undefined,\n name: string,\n): string | undefined => {\n if (!headers) return undefined;\n const normalizedName = normalizeHeaderKey(name);\n return Object.entries(headers).find(([key]) => normalizeHeaderKey(key) === normalizedName)?.[1];\n};\n\nconst isUrlEncoded = (headers: Readonly<Record<string, string>> | undefined): boolean =>\n headerValue(headers, \"content-type\")?.split(\";\", 1)[0]?.trim().toLowerCase() ===\n \"application/x-www-form-urlencoded\";\n\nconst transformUrlParams = (\n body: string,\n omit: ReadonlySet<string>,\n replacements: Readonly<Record<string, VcrRedactedValue>>,\n): BodyTransformation<string> => {\n let redacted = false;\n const value = UrlParams.fromInput(new URLSearchParams(body)).pipe(\n UrlParams.transform((params) =>\n params.flatMap(([key, value]) => {\n if (omit.has(key)) {\n redacted = true;\n return [];\n }\n if (Record.has(replacements, key)) {\n redacted = true;\n return [[key, String(replacements[key])] as const];\n }\n return [[key, value] as const];\n }),\n ),\n UrlParams.toString,\n );\n return { value, redacted };\n};\n\n/**\n * Remove or replace JSON and URL-encoded body fields when possible.\n */\nconst transformBody = (\n body: string | undefined,\n headers: Readonly<Record<string, string>> | undefined,\n options: BodyOptions,\n): Option.Option<BodyTransformation<string>> => {\n if (!body) return Option.none();\n const omit = new Set(options.omit);\n const replacements = options.replacements ?? {};\n if (isUrlEncoded(headers)) {\n const hasMatch = Array.from(new URLSearchParams(body).keys()).some(\n (key) => omit.has(key) || Record.has(replacements, key),\n );\n if (!hasMatch) {\n return Option.some({ value: body, redacted: false });\n }\n return Option.some(transformUrlParams(body, omit, replacements));\n }\n return Option.some(\n tryParseJson(body).pipe(\n Option.match({\n onNone: () => ({ value: body, redacted: false }),\n onSome: (parsed) => {\n const transformed = transformJsonKeys(parsed, omit, replacements);\n return {\n // stableStringify's return type is `string | undefined` for cyclic input;\n // parsed JSON is never cyclic, but the fallback keeps the types honest.\n value: stableStringify(transformed.value) ?? body,\n redacted: transformed.redacted,\n };\n },\n }),\n ),\n );\n};\n\n// A URL that does not parse is kept as is.\nconst omitQueryParams = (url: string, names: ReadonlyArray<string> | undefined): string =>\n !names || names.length === 0\n ? url\n : Result.match(Url.fromString(url), {\n onFailure: () => url,\n onSuccess: (parsed) =>\n Url.modifyUrlParams(\n parsed,\n UrlParams.transform(Arr.filter(([key]) => !names.includes(key))),\n ).toString(),\n });\n\n/**\n * Normalize request for matching: header canonicalization and structured body filtering.\n */\nexport const sanitizeRequest = (\n request: VcrRequest,\n options: {\n readonly ignoreHeaders?: ReadonlyArray<string>;\n readonly ignoreBodyKeys?: ReadonlyArray<string>;\n readonly ignoreQueryParams?: ReadonlyArray<string>;\n },\n): VcrRequest => {\n const transformedBody = transformBody(request.body, request.headers, {\n omit: options.ignoreBodyKeys,\n });\n const body = Option.getOrUndefined(\n transformedBody.pipe(Option.map((transformed) => transformed.value)),\n );\n const filteredHeaders = omitHeaderKeys(\n request.headers,\n transformedBody.pipe(Option.exists((transformed) => transformed.redacted))\n ? [...(options.ignoreHeaders ?? []), \"content-length\"]\n : options.ignoreHeaders,\n );\n return {\n ...request,\n url: omitQueryParams(request.url, options.ignoreQueryParams),\n headers: toHeaderRecord(Option.getOrUndefined(filteredHeaders)),\n body,\n };\n};\n\n/**\n * Compute the stable request key used for cassette lookups.\n */\nexport const buildRequestKey = (\n request: VcrRequest,\n options: {\n readonly ignoreHeaders?: ReadonlyArray<string>;\n readonly ignoreBodyKeys?: ReadonlyArray<string>;\n readonly ignoreQueryParams?: ReadonlyArray<string>;\n },\n): Effect.Effect<string> =>\n Effect.sync(() => {\n const sanitized = sanitizeRequest(request, {\n ignoreHeaders: options.ignoreHeaders,\n ignoreBodyKeys: options.ignoreBodyKeys,\n ignoreQueryParams: options.ignoreQueryParams,\n });\n // stableStringify only returns undefined for cyclic input; this literal never is,\n // but its declared type is `string | undefined`, so keep the fallback for TS.\n return (\n stableStringify({\n method: sanitized.method.toUpperCase(),\n url: sanitized.url,\n headers: sanitized.headers ?? {},\n body: sanitized.body ?? \"\",\n }) ??\n JSON.stringify({\n method: sanitized.method.toUpperCase(),\n url: sanitized.url,\n headers: sanitized.headers ?? {},\n body: sanitized.body ?? \"\",\n })\n );\n });\n\n/**\n * Remove sensitive request data before persisting to a cassette.\n */\nexport const redactRequest = (\n request: VcrRequest,\n options: {\n readonly redactQueryParams?: ReadonlyArray<string>;\n readonly redactHeaders?: ReadonlyArray<string>;\n readonly redactBodyKeys?: ReadonlyArray<string>;\n readonly bodyReplacements?: Readonly<Record<string, VcrRedactedValue>>;\n },\n): VcrRequest => {\n const transformedBody = transformBody(request.body, request.headers, {\n omit: options.redactBodyKeys,\n replacements: options.bodyReplacements,\n });\n const body = Option.getOrUndefined(\n transformedBody.pipe(Option.map((transformed) => transformed.value)),\n );\n return {\n ...request,\n url: omitQueryParams(request.url, options.redactQueryParams),\n headers: Option.getOrUndefined(\n omitHeaderKeys(\n request.headers,\n transformedBody.pipe(Option.exists((transformed) => transformed.redacted))\n ? [...(options.redactHeaders ?? []), \"content-length\"]\n : options.redactHeaders,\n ),\n ),\n body,\n };\n};\n\n/**\n * Remove sensitive response data before persisting to a cassette.\n */\nexport const redactResponse = (\n response: VcrResponse,\n options: {\n readonly redactHeaders?: ReadonlyArray<string>;\n readonly redactBodyKeys?: ReadonlyArray<string>;\n readonly bodyReplacements?: Readonly<Record<string, VcrRedactedValue>>;\n },\n): VcrResponse => {\n const transformedBody = transformBody(response.body, response.headers, {\n omit: options.redactBodyKeys,\n replacements: options.bodyReplacements,\n });\n const body = Option.getOrElse(\n transformedBody.pipe(Option.map((transformed) => transformed.value)),\n () => response.body,\n );\n return {\n ...response,\n headers: Option.getOrUndefined(\n omitHeaderKeys(\n response.headers,\n transformedBody.pipe(Option.exists((transformed) => transformed.redacted))\n ? [...(options.redactHeaders ?? []), \"content-length\"]\n : options.redactHeaders,\n ),\n ),\n body,\n };\n};\n","import { Array as Arr, Config, Data, Effect, Option, Path, Result, Semaphore } from \"effect\";\nimport {\n HttpClient,\n HttpClientError,\n type HttpClientRequest,\n HttpClientResponse,\n Url,\n} from \"effect/http\";\n\nimport type { Cassette, CassetteFile, VcrConfig, VcrEntry, VcrRequest, VcrResponse } from \"./types\";\n\nimport { CassetteStore, type CassetteStoreService, createEmptyCassette } from \"./cassette-store\";\nimport { buildRequestKey, redactRequest, redactResponse } from \"./sanitize\";\nimport { getVitestState } from \"./vitest-state\";\n\n/**\n * Decoder for Uint8Array request bodies when building cassette keys.\n */\nconst decoder = new TextDecoder();\n\nexport class VcrHttpClientError extends Data.TaggedError(\"VcrHttpClientError\")<{\n readonly message: string;\n readonly cause?: unknown;\n}> {}\n\nconst toCassetteFileName = (name: string): string =>\n name.endsWith(\".cassette\") ? name : `${name}.cassette`;\n\n/**\n * Resolve the cassette file name and export key.\n *\n * If explicit cassetteName are provided, use them and default to\n * the \"default\" export. Otherwise infer from Vitest state:\n * - <file-name>.cassette file name\n * - export key = current test name (describe > test)\n */\nconst resolveCassetteLocation = Effect.fnUntraced(function* (config: VcrConfig) {\n const path = yield* Path.Path;\n if (config.cassetteName) {\n return {\n name: toCassetteFileName(config.cassetteName),\n exportKey: \"default\",\n };\n }\n\n const { testPath, currentTestName } = getVitestState();\n if (!testPath || !currentTestName) {\n return yield* Effect.fail(\n new VcrHttpClientError({\n message:\n \"VCR cassette path could not be inferred. Provide cassetteName when not running in Vitest.\",\n }),\n );\n }\n\n const fileName = path.basename(testPath, \".ts\");\n const cassetteName = `${fileName}.cassette`;\n\n return {\n name: cassetteName,\n exportKey: currentTestName,\n };\n});\n\n/**\n * Apply defaults for common VCR behavior while preserving explicit overrides.\n */\nconst normalizeConfig = (config: VcrConfig): VcrConfig => {\n const redactedRequestBodyKeys = Arr.union(\n config.redact?.requestBodyKeys ?? [],\n Object.keys(config.redact?.requestBodyReplacements ?? {}),\n );\n const redactedRequestHeaders = Arr.union([\"authorization\"], config.redact?.requestHeaders ?? []);\n\n return {\n vcrName: config.vcrName,\n cassetteName: config.cassetteName,\n mode: config.mode ?? \"auto\",\n matchIgnore: {\n requestHeaders: Arr.union(redactedRequestHeaders, config.matchIgnore?.requestHeaders ?? []),\n requestBodyKeys: Arr.union(\n redactedRequestBodyKeys,\n config.matchIgnore?.requestBodyKeys ?? [],\n ),\n },\n redact: {\n ...config.redact,\n requestHeaders: redactedRequestHeaders,\n },\n match: config.match,\n };\n};\n\nconst AckDisableVcrConfig = Config.option(Config.String(\"ACK_DISABLE_VCR\")).pipe(\n Config.map((value) =>\n Option.match(value, {\n onNone: () => new Set<string>(),\n onSome: (raw) =>\n raw === \"*\"\n ? \"*\"\n : new Set(\n raw\n .split(\",\")\n .map((segment) => segment.trim().toLowerCase())\n .filter((segment) => segment.length > 0),\n ),\n }),\n ),\n);\n\nconst shouldDisableVcr = (name: string | undefined, disabled: \"*\" | Set<string>): boolean => {\n if (disabled === \"*\") return true;\n if (!name) return false;\n const normalized = name.trim().toLowerCase();\n return disabled.has(normalized);\n};\n\n/**\n * Convert store or replay failures into HttpClient transport errors.\n */\nconst toRequestError = (\n request: HttpClientRequest.HttpClientRequest,\n cause: unknown,\n description?: string,\n) =>\n new HttpClientError.HttpClientError({\n reason: new HttpClientError.TransportError({\n request,\n cause,\n description,\n }),\n });\n\n/**\n * Best-effort JSON serialization for opaque raw bodies.\n */\nconst tryStringify = Option.liftThrowable((value: unknown) => JSON.stringify(value));\n\n/**\n * Serialize an Effect HttpClientRequest into a cassette request shape.\n *\n * Note: some body variants (Stream, FormData) are not safely serializable\n * without consuming the body, so we store placeholders to avoid breaking\n * live requests.\n */\nconst toVcrRequest = (request: HttpClientRequest.HttpClientRequest): VcrRequest => {\n const headers: Record<string, string> = { ...request.headers };\n const body = (() => {\n switch (request.body._tag) {\n case \"Empty\":\n return \"\";\n case \"Uint8Array\":\n return decoder.decode(request.body.body);\n case \"Raw\": {\n const raw = request.body.body as unknown;\n if (typeof raw === \"string\") return raw;\n if (raw instanceof Uint8Array) return decoder.decode(raw);\n return tryStringify(raw).pipe(Option.getOrElse(() => \"[raw]\"));\n }\n case \"FormData\":\n return \"[form-data]\";\n case \"Stream\":\n return \"[stream]\";\n }\n })();\n\n return {\n method: request.method,\n url: requestUrl(request),\n headers,\n body,\n };\n};\n\n/**\n * The URL with its query params, built like `HttpClient` builds it.\n * `request.url` alone leaves out params set with `setUrlParams`.\n */\nconst requestUrl = (request: HttpClientRequest.HttpClientRequest): string =>\n Result.match(Url.make(request.url, request.urlParams, Option.getOrUndefined(request.hash)), {\n onFailure: () => request.url,\n onSuccess: (url) => url.toString(),\n });\n\n/**\n * Serialize an Effect HttpClientResponse into a cassette response shape.\n */\nconst toVcrResponse = (\n response: HttpClientResponse.HttpClientResponse,\n body: string,\n): VcrResponse => ({\n status: response.status,\n body,\n headers: { ...response.headers },\n});\n\n/**\n * Load a cassette and map store errors into HttpClient errors.\n */\nconst readCassetteFile = (\n store: CassetteStoreService,\n name: string,\n request: HttpClientRequest.HttpClientRequest,\n) => store.load(name).pipe(Effect.mapError((error) => toRequestError(request, error)));\n\n/**\n * Load a cassette or initialize a new one if missing.\n */\nconst loadOrInitCassetteFile = (\n store: CassetteStoreService,\n name: string,\n request: HttpClientRequest.HttpClientRequest,\n) => store.loadOrInit(name).pipe(Effect.mapError((error) => toRequestError(request, error)));\n\n/**\n * Persist the updated cassette.\n */\nconst saveCassetteFile = (\n store: CassetteStoreService,\n name: string,\n cassette: CassetteFile,\n request: HttpClientRequest.HttpClientRequest,\n) => store.save(name, cassette).pipe(Effect.mapError((error) => toRequestError(request, error)));\n\n/**\n * Load a named cassette export from the file, or return a fresh empty cassette.\n */\nconst readCassetteExport = (\n store: CassetteStoreService,\n name: string,\n exportKey: string,\n request: HttpClientRequest.HttpClientRequest,\n) =>\n readCassetteFile(store, name, request).pipe(\n Effect.flatMap((file) => {\n const found = file.exports[exportKey];\n if (found) return Effect.succeed(found);\n return createEmptyCassette();\n }),\n );\n\n/**\n * Locate a cassette entry by custom matcher or stable request key.\n */\nconst findEntry = (\n request: VcrRequest,\n cassette: Cassette,\n config: VcrConfig,\n): Effect.Effect<VcrEntry | undefined> => {\n if (config.match) {\n return Effect.succeed(\n Object.values(cassette.entries).find((entry) => config.match?.(request, entry)),\n );\n }\n return buildRequestKey(request, {\n ignoreHeaders: config.matchIgnore?.requestHeaders,\n ignoreQueryParams: config.redact?.requestQueryParams,\n ignoreBodyKeys: config.matchIgnore?.requestBodyKeys,\n }).pipe(Effect.map((key) => cassette.entries[key]));\n};\n\nconst replayResponse = (\n request: HttpClientRequest.HttpClientRequest,\n entry: VcrEntry,\n): HttpClientResponse.HttpClientResponse => {\n const web = new Response(entry.response.body, {\n status: entry.response.status,\n headers: entry.response.headers,\n });\n return HttpClientResponse.fromWeb(request, web);\n};\n\n/**\n * Replay a response from cassette data using HttpClientResponse.fromWeb.\n */\nconst replay = (\n store: CassetteStoreService,\n request: HttpClientRequest.HttpClientRequest,\n vcrRequest: VcrRequest,\n config: VcrConfig,\n name: string,\n exportKey: string,\n) =>\n readCassetteExport(store, name, exportKey, request).pipe(\n Effect.flatMap((cassette) =>\n findEntry(vcrRequest, cassette, config).pipe(\n Effect.flatMap((entry) => {\n if (!entry) {\n return Effect.fail(\n new HttpClientError.HttpClientError({\n reason: new HttpClientError.TransportError({\n request,\n description: `VCR replay missing entry for ${request.method} ${requestUrl(request)}`,\n }),\n }),\n );\n }\n\n return Effect.succeed(replayResponse(request, entry));\n }),\n ),\n ),\n );\n\n/**\n * Record a live response into the cassette and return the original response.\n */\nconst record = Effect.fnUntraced(function* (\n writeLock: Semaphore.Semaphore,\n store: CassetteStoreService,\n request: HttpClientRequest.HttpClientRequest,\n vcrRequest: VcrRequest,\n effect: Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError>,\n config: VcrConfig,\n name: string,\n exportKey: string,\n): Effect.fn.Return<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError> {\n const response = yield* effect;\n const body = yield* response.text;\n const vcrResponse = toVcrResponse(response, body);\n\n const sanitizedRequest = config.redact\n ? redactRequest(vcrRequest, {\n redactQueryParams: config.redact.requestQueryParams,\n redactHeaders: config.redact.requestHeaders,\n redactBodyKeys: config.redact.requestBodyKeys,\n bodyReplacements: config.redact.requestBodyReplacements,\n })\n : vcrRequest;\n const sanitizedResponse = config.redact\n ? redactResponse(vcrResponse, {\n redactHeaders: config.redact.responseHeaders,\n redactBodyKeys: config.redact.responseBodyKeys,\n bodyReplacements: config.redact.responseBodyReplacements,\n })\n : vcrResponse;\n\n // Concurrent requests record into the same file, so writes take turns.\n yield* writeLock.withPermits(1)(\n Effect.gen(function* () {\n const file = yield* loadOrInitCassetteFile(store, name, request);\n const cassette = file.exports[exportKey] ?? (yield* createEmptyCassette());\n const key = yield* buildRequestKey(vcrRequest, {\n ignoreHeaders: config.matchIgnore?.requestHeaders,\n ignoreQueryParams: config.redact?.requestQueryParams,\n ignoreBodyKeys: config.matchIgnore?.requestBodyKeys,\n });\n const next: Cassette = {\n ...cassette,\n entries: {\n ...cassette.entries,\n [key]: {\n request: sanitizedRequest,\n response: sanitizedResponse,\n },\n },\n };\n const nextFile: CassetteFile = {\n ...file,\n exports: {\n ...file.exports,\n [exportKey]: next,\n },\n };\n yield* saveCassetteFile(store, name, nextFile, request);\n }),\n );\n return response;\n});\n\n/**\n * Build a VCR-aware HttpClient that replays or records per config.\n */\nconst makeVcrHttpClient = Effect.fnUntraced(function* (config: VcrConfig = {}) {\n const live = yield* HttpClient.HttpClient;\n const normalized = normalizeConfig(config);\n\n const isCi = yield* Config.Boolean(\"CI\").pipe(Config.withDefault(false));\n\n const disabledVcrs = yield* AckDisableVcrConfig;\n if (shouldDisableVcr(normalized.vcrName, disabledVcrs)) {\n return live;\n }\n\n const store = yield* CassetteStore;\n const writeLock = yield* Semaphore.make(1);\n\n const { name, exportKey } = yield* resolveCassetteLocation(normalized);\n\n return live.pipe(\n HttpClient.transform(\n Effect.fnUntraced(function* (effect, request) {\n const vcrRequest = toVcrRequest(request);\n if (normalized.mode === \"replay\") {\n return yield* replay(store, request, vcrRequest, normalized, name, exportKey);\n }\n\n if (normalized.mode === \"record\") {\n return yield* record(\n writeLock,\n store,\n request,\n vcrRequest,\n effect,\n normalized,\n name,\n exportKey,\n );\n }\n\n const available = yield* store\n .exists(name)\n .pipe(Effect.mapError((error) => toRequestError(request, error)));\n\n if (!available) {\n if (isCi) {\n return yield* Effect.fail(\n new HttpClientError.HttpClientError({\n reason: new HttpClientError.TransportError({\n request,\n description: \"VCR cassette missing in CI for auto mode\",\n }),\n }),\n );\n }\n\n return yield* record(\n writeLock,\n store,\n request,\n vcrRequest,\n effect,\n normalized,\n name,\n exportKey,\n );\n }\n\n const cassette = yield* readCassetteExport(store, name, exportKey, request);\n const entry = yield* findEntry(vcrRequest, cassette, normalized);\n\n if (entry) {\n return replayResponse(request, entry);\n }\n\n return yield* record(\n writeLock,\n store,\n request,\n vcrRequest,\n effect,\n normalized,\n name,\n exportKey,\n );\n }),\n ),\n );\n});\n\n/**\n * Layer that provides a VCR-wrapped HttpClient.\n */\nexport const layer = (config: VcrConfig = {}) =>\n HttpClient.layerMergedContext(makeVcrHttpClient(config));\n"],"mappings":";;;;;;;;;;AASA,MAAM,sBAAsB,QAAgB,IAAI,YAAY;;;;AAK5D,MAAM,kBAAkB,YAAqC;CAC3D,IAAI,CAAC,SAAS,OAAO,KAAA;CACrB,MAAM,UAAU,OAAO,QAAQ,SAAS,kBAAkB;CAC1D,OAAO,OAAO,YAAY,OAAO,UAAU,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;AAC5F;;;;AAKA,MAAM,kBACJ,SACA,WAC0C;CAC1C,IAAI,CAAC,SAAS,OAAO,OAAO,KAAK;CACjC,IAAI,CAAC,UAAU,OAAO,WAAW,GAAG,OAAO,OAAO,KAAK,OAAO;CAC9D,MAAM,YAAY,IAAI,IAAI,OAAO,IAAI,kBAAkB,CAAC;CACxD,OAAO,OAAO,KAAK,OAAO,OAAO,UAAU,GAAG,QAAQ,CAAC,UAAU,IAAI,mBAAmB,GAAG,CAAC,CAAC,CAAC;AAChG;;;;AAKA,MAAM,eAAe,OAAO,eAAe,UAAkB,KAAK,MAAM,KAAK,CAAC;;;;AAe9E,MAAM,qBACJ,OACA,MACA,iBACgC;CAChC,IAAI,MAAM,QAAQ,KAAK,GAAG;EACxB,IAAI,WAAW;EAMf,OAAO;GAAE,OALM,MAAM,KAAK,SAAS;IACjC,MAAM,cAAc,kBAAkB,MAAM,MAAM,YAAY;IAC9D,aAAa,YAAY;IACzB,OAAO,YAAY;GACrB,CACqB;GAAG;EAAS;CACnC;CACA,IAAI,SAAS,OAAO,UAAU,UAAU;EACtC,MAAM,SAAS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W,WAAW,QAAQ,SAAS;EAC5C,MAAM,aAAa,aAAa,OAAO;EACvC,IAAI,WAAW,SAAS,UACtB,OAAO,OAAO,OAAO,OAAO,SAAS,YAAY,YAAY,MAAM,SAAS;EAG9E,IAAI,WAAW,SAAS,UACtB,OAAO,OAAO,OACZ,WACA,OACA,SACA,YACA,QACA,YACA,MACA,SACF;EAOF,IAAI,EAAC,OAJoB,MACtB,OAAO,IAAI,CAAC,CACZ,KAAK,OAAO,UAAU,UAAU,eAAe,SAAS,KAAK,CAAC,CAAC,IAElD;GACd,IAAI,MACF,OAAO,OAAO,OAAO,KACnB,IAAI,gBAAgB,gBAAgB,EAClC,QAAQ,IAAI,gBAAgB,eAAe;IACzC;IACA,aAAa;GACf,CAAC,EACH,CAAC,CACH;GAGF,OAAO,OAAO,OACZ,WACA,OACA,SACA,YACA,QACA,YACA,MACA,SACF;EACF;EAEA,MAAM,WAAW,OAAO,mBAAmB,OAAO,MAAM,WAAW,OAAO;EAC1E,MAAM,QAAQ,OAAO,UAAU,YAAY,UAAU,UAAU;EAE/D,IAAI,OACF,OAAO,eAAe,SAAS,KAAK;EAGtC,OAAO,OAAO,OACZ,WACA,OACA,SACA,YACA,QACA,YACA,MACA,SACF;CACF,CAAC,CACH,CACF;AACF,CAAC;;;;AAKD,MAAa,SAAS,SAAoB,CAAC,MACzC,WAAW,mBAAmB,kBAAkB,MAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"vcr-http-client-DfDxGM-a.mjs","names":["Arr","Arr"],"sources":["../src/sanitize.ts","../src/vcr-http-client.ts"],"sourcesContent":["import { Array as Arr, Effect, Option, Record, Result } from \"effect\";\nimport { Url, UrlParams } from \"effect/http\";\nimport stableStringify from \"json-stable-stringify\";\n\nimport type { VcrRedactedValue, VcrRequest, VcrResponse } from \"./types\";\n\n/**\n * Normalize header names to match HttpClient's lowercase behavior.\n */\nconst normalizeHeaderKey = (key: string) => key.toLowerCase();\n\n/**\n * Canonicalize headers: lowercase keys and stable ordering.\n */\nconst toHeaderRecord = (headers?: Record<string, string>) => {\n if (!headers) return undefined;\n const lowered = Record.mapKeys(headers, normalizeHeaderKey);\n return Record.fromEntries(Record.toEntries(lowered).sort(([a], [b]) => a.localeCompare(b)));\n};\n\n/**\n * Remove specified header names (case-insensitive).\n */\nconst omitHeaderKeys = (\n headers: Record<string, string> | undefined,\n ignore: ReadonlyArray<string> | undefined,\n): Option.Option<Record<string, string>> => {\n if (!headers) return Option.none();\n if (!ignore || ignore.length === 0) return Option.some(headers);\n const ignoreSet = new Set(ignore.map(normalizeHeaderKey));\n return Option.some(Record.filter(headers, (_, key) => !ignoreSet.has(normalizeHeaderKey(key))));\n};\n\n/**\n * Best-effort JSON parse; returns undefined for non-JSON bodies.\n */\nconst tryParseJson = Option.liftThrowable((input: string) => JSON.parse(input));\n\ntype BodyOptions = {\n readonly omit?: ReadonlyArray<string>;\n readonly replacements?: Readonly<Record<string, VcrRedactedValue>>;\n};\n\ntype BodyTransformation<A> = {\n readonly value: A;\n readonly redacted: boolean;\n};\n\n/**\n * Recursively remove or replace keys in JSON values.\n */\nconst transformJsonKeys = (\n value: unknown,\n omit: ReadonlySet<string>,\n replacements: Readonly<Record<string, VcrRedactedValue>>,\n): BodyTransformation<unknown> => {\n if (Array.isArray(value)) {\n let redacted = false;\n const values = value.map((item) => {\n const transformed = transformJsonKeys(item, omit, replacements);\n redacted ||= transformed.redacted;\n return transformed.value;\n });\n return { value: values, redacted };\n }\n if (value && typeof value === \"object\") {\n const record = value as Record<string, unknown>;\n const next: Record<string, unknown> = {};\n let redacted = false;\n for (const [key, entry] of Object.entries(record)) {\n if (omit.has(key)) {\n redacted = true;\n continue;\n }\n if (Record.has(replacements, key)) {\n next[key] = replacements[key];\n redacted = true;\n continue;\n }\n const transformed = transformJsonKeys(entry, omit, replacements);\n next[key] = transformed.value;\n redacted ||= transformed.redacted;\n }\n return { value: next, redacted };\n }\n return { value, redacted: false };\n};\n\nconst headerValue = (\n headers: Readonly<Record<string, string>> | undefined,\n name: string,\n): string | undefined => {\n if (!headers) return undefined;\n const normalizedName = normalizeHeaderKey(name);\n return Object.entries(headers).find(([key]) => normalizeHeaderKey(key) === normalizedName)?.[1];\n};\n\nconst isUrlEncoded = (headers: Readonly<Record<string, string>> | undefined): boolean =>\n headerValue(headers, \"content-type\")?.split(\";\", 1)[0]?.trim().toLowerCase() ===\n \"application/x-www-form-urlencoded\";\n\nconst transformUrlParams = (\n body: string,\n omit: ReadonlySet<string>,\n replacements: Readonly<Record<string, VcrRedactedValue>>,\n): BodyTransformation<string> => {\n let redacted = false;\n const value = UrlParams.fromInput(new URLSearchParams(body)).pipe(\n UrlParams.transform((params) =>\n params.flatMap(([key, value]) => {\n if (omit.has(key)) {\n redacted = true;\n return [];\n }\n if (Record.has(replacements, key)) {\n redacted = true;\n return [[key, String(replacements[key])] as const];\n }\n return [[key, value] as const];\n }),\n ),\n UrlParams.toString,\n );\n return { value, redacted };\n};\n\n/**\n * Remove or replace JSON and URL-encoded body fields when possible.\n */\nconst transformBody = (\n body: string | undefined,\n headers: Readonly<Record<string, string>> | undefined,\n options: BodyOptions,\n): Option.Option<BodyTransformation<string>> => {\n if (!body) return Option.none();\n const omit = new Set(options.omit);\n const replacements = options.replacements ?? {};\n if (isUrlEncoded(headers)) {\n const hasMatch = Array.from(new URLSearchParams(body).keys()).some(\n (key) => omit.has(key) || Record.has(replacements, key),\n );\n if (!hasMatch) {\n return Option.some({ value: body, redacted: false });\n }\n return Option.some(transformUrlParams(body, omit, replacements));\n }\n return Option.some(\n tryParseJson(body).pipe(\n Option.match({\n onNone: () => ({ value: body, redacted: false }),\n onSome: (parsed) => {\n const transformed = transformJsonKeys(parsed, omit, replacements);\n return {\n // stableStringify's return type is `string | undefined` for cyclic input;\n // parsed JSON is never cyclic, but the fallback keeps the types honest.\n value: stableStringify(transformed.value) ?? body,\n redacted: transformed.redacted,\n };\n },\n }),\n ),\n );\n};\n\n// A URL that does not parse is kept as is.\nconst omitQueryParams = (url: string, names: ReadonlyArray<string> | undefined): string =>\n !names || names.length === 0\n ? url\n : Result.match(Url.fromString(url), {\n onFailure: () => url,\n onSuccess: (parsed) =>\n Url.modifyUrlParams(\n parsed,\n UrlParams.transform(Arr.filter(([key]) => !names.includes(key))),\n ).toString(),\n });\n\n/**\n * Normalize request for matching: header canonicalization and structured body filtering.\n */\nexport const sanitizeRequest = (\n request: VcrRequest,\n options: {\n readonly ignoreHeaders?: ReadonlyArray<string>;\n readonly ignoreBodyKeys?: ReadonlyArray<string>;\n readonly ignoreQueryParams?: ReadonlyArray<string>;\n },\n): VcrRequest => {\n const transformedBody = transformBody(request.body, request.headers, {\n omit: options.ignoreBodyKeys,\n });\n const body = Option.getOrUndefined(\n transformedBody.pipe(Option.map((transformed) => transformed.value)),\n );\n const filteredHeaders = omitHeaderKeys(\n request.headers,\n transformedBody.pipe(Option.exists((transformed) => transformed.redacted))\n ? [...(options.ignoreHeaders ?? []), \"content-length\"]\n : options.ignoreHeaders,\n );\n return {\n ...request,\n url: omitQueryParams(request.url, options.ignoreQueryParams),\n headers: toHeaderRecord(Option.getOrUndefined(filteredHeaders)),\n body,\n };\n};\n\n/**\n * Compute the stable request key used for cassette lookups.\n */\nexport const buildRequestKey = (\n request: VcrRequest,\n options: {\n readonly ignoreHeaders?: ReadonlyArray<string>;\n readonly ignoreBodyKeys?: ReadonlyArray<string>;\n readonly ignoreQueryParams?: ReadonlyArray<string>;\n },\n): Effect.Effect<string> =>\n Effect.sync(() => {\n const sanitized = sanitizeRequest(request, {\n ignoreHeaders: options.ignoreHeaders,\n ignoreBodyKeys: options.ignoreBodyKeys,\n ignoreQueryParams: options.ignoreQueryParams,\n });\n // stableStringify only returns undefined for cyclic input; this literal never is,\n // but its declared type is `string | undefined`, so keep the fallback for TS.\n return (\n stableStringify({\n method: sanitized.method.toUpperCase(),\n url: sanitized.url,\n headers: sanitized.headers ?? {},\n body: sanitized.body ?? \"\",\n }) ??\n JSON.stringify({\n method: sanitized.method.toUpperCase(),\n url: sanitized.url,\n headers: sanitized.headers ?? {},\n body: sanitized.body ?? \"\",\n })\n );\n });\n\n/**\n * Remove sensitive request data before persisting to a cassette.\n */\nexport const redactRequest = (\n request: VcrRequest,\n options: {\n readonly redactQueryParams?: ReadonlyArray<string>;\n readonly redactHeaders?: ReadonlyArray<string>;\n readonly redactBodyKeys?: ReadonlyArray<string>;\n readonly bodyReplacements?: Readonly<Record<string, VcrRedactedValue>>;\n },\n): VcrRequest => {\n const transformedBody = transformBody(request.body, request.headers, {\n omit: options.redactBodyKeys,\n replacements: options.bodyReplacements,\n });\n const body = Option.getOrUndefined(\n transformedBody.pipe(Option.map((transformed) => transformed.value)),\n );\n return {\n ...request,\n url: omitQueryParams(request.url, options.redactQueryParams),\n headers: Option.getOrUndefined(\n omitHeaderKeys(\n request.headers,\n transformedBody.pipe(Option.exists((transformed) => transformed.redacted))\n ? [...(options.redactHeaders ?? []), \"content-length\"]\n : options.redactHeaders,\n ),\n ),\n body,\n };\n};\n\n/**\n * Remove sensitive response data before persisting to a cassette.\n */\nexport const redactResponse = (\n response: VcrResponse,\n options: {\n readonly redactHeaders?: ReadonlyArray<string>;\n readonly redactBodyKeys?: ReadonlyArray<string>;\n readonly bodyReplacements?: Readonly<Record<string, VcrRedactedValue>>;\n },\n): VcrResponse => {\n const transformedBody = transformBody(response.body, response.headers, {\n omit: options.redactBodyKeys,\n replacements: options.bodyReplacements,\n });\n const body = Option.getOrElse(\n transformedBody.pipe(Option.map((transformed) => transformed.value)),\n () => response.body,\n );\n return {\n ...response,\n headers: Option.getOrUndefined(\n omitHeaderKeys(\n response.headers,\n transformedBody.pipe(Option.exists((transformed) => transformed.redacted))\n ? [...(options.redactHeaders ?? []), \"content-length\"]\n : options.redactHeaders,\n ),\n ),\n body,\n };\n};\n","import { Array as Arr, Config, Data, Effect, Option, Path, Result, Semaphore } from \"effect\";\nimport {\n HttpClient,\n HttpClientError,\n type HttpClientRequest,\n HttpClientResponse,\n Url,\n} from \"effect/http\";\n\nimport type { Cassette, CassetteFile, VcrConfig, VcrEntry, VcrRequest, VcrResponse } from \"./types\";\n\nimport { CassetteStore, type CassetteStoreService, createEmptyCassette } from \"./cassette-store\";\nimport { buildRequestKey, redactRequest, redactResponse } from \"./sanitize\";\nimport { getVitestState } from \"./vitest-state\";\n\n/**\n * Decoder for Uint8Array request bodies when building cassette keys.\n */\nconst decoder = new TextDecoder();\n\nexport class VcrHttpClientError extends Data.TaggedError(\"VcrHttpClientError\")<{\n readonly message: string;\n readonly cause?: unknown;\n}> {}\n\nconst toCassetteFileName = (name: string): string =>\n name.endsWith(\".cassette\") ? name : `${name}.cassette`;\n\n/**\n * Resolve the cassette file name and export key.\n *\n * If explicit cassetteName are provided, use them and default to\n * the \"default\" export. Otherwise infer from Vitest state:\n * - <file-name>.cassette file name\n * - export key = current test name (describe > test)\n */\nconst resolveCassetteLocation = Effect.fnUntraced(function* (config: VcrConfig) {\n const path = yield* Path.Path;\n if (config.cassetteName) {\n return {\n name: toCassetteFileName(config.cassetteName),\n exportKey: \"default\",\n };\n }\n\n const { testPath, currentTestName } = getVitestState();\n if (!testPath || !currentTestName) {\n return yield* Effect.fail(\n new VcrHttpClientError({\n message:\n \"VCR cassette path could not be inferred. Provide cassetteName when not running in Vitest.\",\n }),\n );\n }\n\n const fileName = path.basename(testPath, \".ts\");\n const cassetteName = `${fileName}.cassette`;\n\n return {\n name: cassetteName,\n exportKey: currentTestName,\n };\n});\n\n/**\n * Apply defaults for common VCR behavior while preserving explicit overrides.\n */\nconst normalizeConfig = (config: VcrConfig): VcrConfig => {\n const redactedRequestBodyKeys = Arr.union(\n config.redact?.requestBodyKeys ?? [],\n Object.keys(config.redact?.requestBodyReplacements ?? {}),\n );\n const redactedRequestHeaders = Arr.union([\"authorization\"], config.redact?.requestHeaders ?? []);\n\n return {\n vcrName: config.vcrName,\n cassetteName: config.cassetteName,\n mode: config.mode ?? \"auto\",\n matchIgnore: {\n requestHeaders: Arr.union(redactedRequestHeaders, config.matchIgnore?.requestHeaders ?? []),\n requestBodyKeys: Arr.union(\n redactedRequestBodyKeys,\n config.matchIgnore?.requestBodyKeys ?? [],\n ),\n },\n redact: {\n ...config.redact,\n requestHeaders: redactedRequestHeaders,\n },\n match: config.match,\n };\n};\n\nconst AckDisableVcrConfig = Config.option(Config.String(\"ACK_DISABLE_VCR\")).pipe(\n Config.map((value) =>\n Option.match(value, {\n onNone: () => new Set<string>(),\n onSome: (raw) =>\n raw === \"*\"\n ? \"*\"\n : new Set(\n raw\n .split(\",\")\n .map((segment) => segment.trim().toLowerCase())\n .filter((segment) => segment.length > 0),\n ),\n }),\n ),\n);\n\nconst shouldDisableVcr = (name: string | undefined, disabled: \"*\" | Set<string>): boolean => {\n if (disabled === \"*\") return true;\n if (!name) return false;\n const normalized = name.trim().toLowerCase();\n return disabled.has(normalized);\n};\n\n/**\n * Convert store or replay failures into HttpClient transport errors.\n */\nconst toRequestError = (\n request: HttpClientRequest.HttpClientRequest,\n cause: unknown,\n description?: string,\n) =>\n new HttpClientError.HttpClientError({\n reason: new HttpClientError.TransportError({\n request,\n cause,\n description,\n }),\n });\n\n/**\n * Best-effort JSON serialization for opaque raw bodies.\n */\nconst tryStringify = Option.liftThrowable((value: unknown) => JSON.stringify(value));\n\n/**\n * Serialize an Effect HttpClientRequest into a cassette request shape.\n *\n * Note: some body variants (Stream, FormData) are not safely serializable\n * without consuming the body, so we store placeholders to avoid breaking\n * live requests.\n */\nconst toVcrRequest = (request: HttpClientRequest.HttpClientRequest): VcrRequest => {\n const headers: Record<string, string> = { ...request.headers };\n const body = (() => {\n switch (request.body._tag) {\n case \"Empty\":\n return \"\";\n case \"Uint8Array\":\n return decoder.decode(request.body.body);\n case \"Raw\": {\n const raw = request.body.body as unknown;\n if (typeof raw === \"string\") return raw;\n if (raw instanceof Uint8Array) return decoder.decode(raw);\n return tryStringify(raw).pipe(Option.getOrElse(() => \"[raw]\"));\n }\n case \"FormData\":\n return \"[form-data]\";\n case \"Stream\":\n return \"[stream]\";\n }\n })();\n\n return {\n method: request.method,\n url: requestUrl(request),\n headers,\n body,\n };\n};\n\n/**\n * The URL with its query params, built like `HttpClient` builds it.\n * `request.url` alone leaves out params set with `setUrlParams`.\n */\nconst requestUrl = (request: HttpClientRequest.HttpClientRequest): string =>\n Result.match(Url.make(request.url, request.urlParams, Option.getOrUndefined(request.hash)), {\n onFailure: () => request.url,\n onSuccess: (url) => url.toString(),\n });\n\n/**\n * Serialize an Effect HttpClientResponse into a cassette response shape.\n */\nconst toVcrResponse = (\n response: HttpClientResponse.HttpClientResponse,\n body: string,\n): VcrResponse => ({\n status: response.status,\n body,\n headers: { ...response.headers },\n});\n\n/**\n * Load a cassette and map store errors into HttpClient errors.\n */\nconst readCassetteFile = (\n store: CassetteStoreService,\n name: string,\n request: HttpClientRequest.HttpClientRequest,\n) => store.load(name).pipe(Effect.mapError((error) => toRequestError(request, error)));\n\n/**\n * Load a cassette or initialize a new one if missing.\n */\nconst loadOrInitCassetteFile = (\n store: CassetteStoreService,\n name: string,\n request: HttpClientRequest.HttpClientRequest,\n) => store.loadOrInit(name).pipe(Effect.mapError((error) => toRequestError(request, error)));\n\n/**\n * Persist the updated cassette.\n */\nconst saveCassetteFile = (\n store: CassetteStoreService,\n name: string,\n cassette: CassetteFile,\n request: HttpClientRequest.HttpClientRequest,\n) => store.save(name, cassette).pipe(Effect.mapError((error) => toRequestError(request, error)));\n\n/**\n * Load a named cassette export from the file, or return a fresh empty cassette.\n */\nconst readCassetteExport = (\n store: CassetteStoreService,\n name: string,\n exportKey: string,\n request: HttpClientRequest.HttpClientRequest,\n) =>\n readCassetteFile(store, name, request).pipe(\n Effect.flatMap((file) => {\n const found = file.exports[exportKey];\n if (found) return Effect.succeed(found);\n return createEmptyCassette();\n }),\n );\n\n/**\n * Locate a cassette entry by custom matcher or stable request key.\n */\nconst findEntry = (\n request: VcrRequest,\n cassette: Cassette,\n config: VcrConfig,\n): Effect.Effect<VcrEntry | undefined> => {\n if (config.match) {\n return Effect.succeed(\n Object.values(cassette.entries).find((entry) => config.match?.(request, entry)),\n );\n }\n return buildRequestKey(request, {\n ignoreHeaders: config.matchIgnore?.requestHeaders,\n ignoreQueryParams: config.redact?.requestQueryParams,\n ignoreBodyKeys: config.matchIgnore?.requestBodyKeys,\n }).pipe(Effect.map((key) => cassette.entries[key]));\n};\n\nconst replayResponse = (\n request: HttpClientRequest.HttpClientRequest,\n entry: VcrEntry,\n): HttpClientResponse.HttpClientResponse => {\n const { status, body } = entry.response;\n const web = new Response(status === 204 || status === 205 || status === 304 ? null : body, {\n status,\n headers: entry.response.headers,\n });\n return HttpClientResponse.fromWeb(request, web);\n};\n\n/**\n * Replay a response from cassette data using HttpClientResponse.fromWeb.\n */\nconst replay = (\n store: CassetteStoreService,\n request: HttpClientRequest.HttpClientRequest,\n vcrRequest: VcrRequest,\n config: VcrConfig,\n name: string,\n exportKey: string,\n) =>\n readCassetteExport(store, name, exportKey, request).pipe(\n Effect.flatMap((cassette) =>\n findEntry(vcrRequest, cassette, config).pipe(\n Effect.flatMap((entry) => {\n if (!entry) {\n return Effect.fail(\n new HttpClientError.HttpClientError({\n reason: new HttpClientError.TransportError({\n request,\n description: `VCR replay missing entry for ${request.method} ${requestUrl(request)}`,\n }),\n }),\n );\n }\n\n return Effect.succeed(replayResponse(request, entry));\n }),\n ),\n ),\n );\n\n/**\n * Record a live response into the cassette and return the original response.\n */\nconst record = Effect.fnUntraced(function* (\n writeLock: Semaphore.Semaphore,\n store: CassetteStoreService,\n request: HttpClientRequest.HttpClientRequest,\n vcrRequest: VcrRequest,\n effect: Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError>,\n config: VcrConfig,\n name: string,\n exportKey: string,\n): Effect.fn.Return<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError> {\n const response = yield* effect;\n const body = yield* response.text;\n const vcrResponse = toVcrResponse(response, body);\n\n const sanitizedRequest = config.redact\n ? redactRequest(vcrRequest, {\n redactQueryParams: config.redact.requestQueryParams,\n redactHeaders: config.redact.requestHeaders,\n redactBodyKeys: config.redact.requestBodyKeys,\n bodyReplacements: config.redact.requestBodyReplacements,\n })\n : vcrRequest;\n const sanitizedResponse = config.redact\n ? redactResponse(vcrResponse, {\n redactHeaders: config.redact.responseHeaders,\n redactBodyKeys: config.redact.responseBodyKeys,\n bodyReplacements: config.redact.responseBodyReplacements,\n })\n : vcrResponse;\n\n // Concurrent requests record into the same file, so writes take turns.\n yield* writeLock.withPermits(1)(\n Effect.gen(function* () {\n const file = yield* loadOrInitCassetteFile(store, name, request);\n const cassette = file.exports[exportKey] ?? (yield* createEmptyCassette());\n const key = yield* buildRequestKey(vcrRequest, {\n ignoreHeaders: config.matchIgnore?.requestHeaders,\n ignoreQueryParams: config.redact?.requestQueryParams,\n ignoreBodyKeys: config.matchIgnore?.requestBodyKeys,\n });\n const next: Cassette = {\n ...cassette,\n entries: {\n ...cassette.entries,\n [key]: {\n request: sanitizedRequest,\n response: sanitizedResponse,\n },\n },\n };\n const nextFile: CassetteFile = {\n ...file,\n exports: {\n ...file.exports,\n [exportKey]: next,\n },\n };\n yield* saveCassetteFile(store, name, nextFile, request);\n }),\n );\n return response;\n});\n\n/**\n * Build a VCR-aware HttpClient that replays or records per config.\n */\nconst makeVcrHttpClient = Effect.fnUntraced(function* (config: VcrConfig = {}) {\n const live = yield* HttpClient.HttpClient;\n const normalized = normalizeConfig(config);\n\n const isCi = yield* Config.Boolean(\"CI\").pipe(Config.withDefault(false));\n\n const disabledVcrs = yield* AckDisableVcrConfig;\n if (shouldDisableVcr(normalized.vcrName, disabledVcrs)) {\n return live;\n }\n\n const store = yield* CassetteStore;\n const writeLock = yield* Semaphore.make(1);\n\n const { name, exportKey } = yield* resolveCassetteLocation(normalized);\n\n return live.pipe(\n HttpClient.transform(\n Effect.fnUntraced(function* (effect, request) {\n const vcrRequest = toVcrRequest(request);\n if (normalized.mode === \"replay\") {\n return yield* replay(store, request, vcrRequest, normalized, name, exportKey);\n }\n\n if (normalized.mode === \"record\") {\n return yield* record(\n writeLock,\n store,\n request,\n vcrRequest,\n effect,\n normalized,\n name,\n exportKey,\n );\n }\n\n const available = yield* store\n .exists(name)\n .pipe(Effect.mapError((error) => toRequestError(request, error)));\n\n if (!available) {\n if (isCi) {\n return yield* Effect.fail(\n new HttpClientError.HttpClientError({\n reason: new HttpClientError.TransportError({\n request,\n description: \"VCR cassette missing in CI for auto mode\",\n }),\n }),\n );\n }\n\n return yield* record(\n writeLock,\n store,\n request,\n vcrRequest,\n effect,\n normalized,\n name,\n exportKey,\n );\n }\n\n const cassette = yield* readCassetteExport(store, name, exportKey, request);\n const entry = yield* findEntry(vcrRequest, cassette, normalized);\n\n if (entry) {\n return replayResponse(request, entry);\n }\n\n return yield* record(\n writeLock,\n store,\n request,\n vcrRequest,\n effect,\n normalized,\n name,\n exportKey,\n );\n }),\n ),\n );\n});\n\n/**\n * Layer that provides a VCR-wrapped HttpClient.\n */\nexport const layer = (config: VcrConfig = {}) =>\n HttpClient.layerMergedContext(makeVcrHttpClient(config));\n"],"mappings":";;;;;;;;;;AASA,MAAM,sBAAsB,QAAgB,IAAI,YAAY;;;;AAK5D,MAAM,kBAAkB,YAAqC;CAC3D,IAAI,CAAC,SAAS,OAAO,KAAA;CACrB,MAAM,UAAU,OAAO,QAAQ,SAAS,kBAAkB;CAC1D,OAAO,OAAO,YAAY,OAAO,UAAU,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;AAC5F;;;;AAKA,MAAM,kBACJ,SACA,WAC0C;CAC1C,IAAI,CAAC,SAAS,OAAO,OAAO,KAAK;CACjC,IAAI,CAAC,UAAU,OAAO,WAAW,GAAG,OAAO,OAAO,KAAK,OAAO;CAC9D,MAAM,YAAY,IAAI,IAAI,OAAO,IAAI,kBAAkB,CAAC;CACxD,OAAO,OAAO,KAAK,OAAO,OAAO,UAAU,GAAG,QAAQ,CAAC,UAAU,IAAI,mBAAmB,GAAG,CAAC,C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AAa,SAAS,SAAoB,CAAC,MACzC,WAAW,mBAAmB,kBAAkB,MAAM,CAAC"}
|
package/dist/vcr-http-client.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useairfoil/effect-vcr",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.9",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"effect"
|
|
6
6
|
],
|
|
@@ -40,29 +40,29 @@
|
|
|
40
40
|
"default": "./dist/vcr-http-client.mjs"
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
|
-
"scripts": {
|
|
44
|
-
"build": "tsdown",
|
|
45
|
-
"test": "vitest run",
|
|
46
|
-
"test:ci": "vitest run",
|
|
47
|
-
"typecheck": "tsc --noEmit"
|
|
48
|
-
},
|
|
49
43
|
"dependencies": {
|
|
50
44
|
"json-stable-stringify": "^1.3.0"
|
|
51
45
|
},
|
|
52
46
|
"devDependencies": {
|
|
53
|
-
"@effect/platform-node": "^4.0
|
|
54
|
-
"@effect/vitest": "^4.0
|
|
47
|
+
"@effect/platform-node": "^4.1.0",
|
|
48
|
+
"@effect/vitest": "^4.1.0",
|
|
55
49
|
"@types/node": "^24.2.0",
|
|
56
|
-
"effect": "^4.0
|
|
50
|
+
"effect": "^4.1.0",
|
|
57
51
|
"tsdown": "^0.23.0",
|
|
58
52
|
"vitest": "^5.0.3"
|
|
59
53
|
},
|
|
60
54
|
"peerDependencies": {
|
|
61
|
-
"effect": "^4.0
|
|
55
|
+
"effect": "^4.1.0"
|
|
62
56
|
},
|
|
63
57
|
"peerDependenciesMeta": {
|
|
64
58
|
"effect": {
|
|
65
59
|
"optional": false
|
|
66
60
|
}
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "tsdown",
|
|
64
|
+
"test": "vitest run",
|
|
65
|
+
"test:ci": "vitest run",
|
|
66
|
+
"typecheck": "tsc --noEmit"
|
|
67
67
|
}
|
|
68
|
-
}
|
|
68
|
+
}
|
package/src/vcr-http-client.ts
CHANGED
|
@@ -263,8 +263,9 @@ const replayResponse = (
|
|
|
263
263
|
request: HttpClientRequest.HttpClientRequest,
|
|
264
264
|
entry: VcrEntry,
|
|
265
265
|
): HttpClientResponse.HttpClientResponse => {
|
|
266
|
-
const
|
|
267
|
-
|
|
266
|
+
const { status, body } = entry.response;
|
|
267
|
+
const web = new Response(status === 204 || status === 205 || status === 304 ? null : body, {
|
|
268
|
+
status,
|
|
268
269
|
headers: entry.response.headers,
|
|
269
270
|
});
|
|
270
271
|
return HttpClientResponse.fromWeb(request, web);
|