@scenarist/msw-adapter 0.3.1 → 0.3.2
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/dist/conversion/response-builder.d.ts.map +1 -1
- package/dist/conversion/response-builder.js +1 -0
- package/dist/handlers/dynamic-handler.d.ts.map +1 -1
- package/dist/handlers/dynamic-handler.js +4 -1
- package/dist/matching/url-matcher.d.ts.map +1 -1
- package/dist/matching/url-matcher.js +12 -4
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-builder.d.ts","sourceRoot":"","sources":["../../src/conversion/response-builder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,eAAO,MAAM,aAAa,GACxB,UAAU,iBAAiB,KAC1B,OAAO,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"response-builder.d.ts","sourceRoot":"","sources":["../../src/conversion/response-builder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,eAAO,MAAM,aAAa,GACxB,UAAU,iBAAiB,KAC1B,OAAO,CAAC,QAAQ,CAelB,CAAC"}
|
|
@@ -8,6 +8,7 @@ export const buildResponse = async (response) => {
|
|
|
8
8
|
// framework-agnostic serialization in core package. The body is guaranteed
|
|
9
9
|
// to be JSON-serializable by ScenaristResponse design contract. We do not
|
|
10
10
|
// perform runtime validation for performance reasons (garbage in, garbage out).
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- MSW API boundary requires cast from unknown to JsonBodyType
|
|
11
12
|
return HttpResponse.json(response.body, {
|
|
12
13
|
status: response.status,
|
|
13
14
|
headers: response.headers,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-handler.d.ts","sourceRoot":"","sources":["../../src/handlers/dynamic-handler.ts"],"names":[],"mappings":"AACA,OAAO,K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Q,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAC5C,QAAQ,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC;IACzC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAqGF,eAAO,MAAM,oBAAoB,GAC/B,SAAS,qBAAqB,KAC7B,WAiIF,CAAC"}
|
|
@@ -33,8 +33,11 @@ const extractHttpRequestContext = async (request) => {
|
|
|
33
33
|
url.searchParams.forEach((value, key) => {
|
|
34
34
|
query[key] = value;
|
|
35
35
|
});
|
|
36
|
+
// HTTP methods from Request.method are uppercase strings matching HttpMethod type
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Request.method is a string, HttpMethod is a string literal union; values align at runtime
|
|
38
|
+
const method = request.method;
|
|
36
39
|
return {
|
|
37
|
-
method
|
|
40
|
+
method,
|
|
38
41
|
url: request.url,
|
|
39
42
|
body,
|
|
40
43
|
headers,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url-matcher.d.ts","sourceRoot":"","sources":["../../src/matching/url-matcher.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;CAC5E,CAAC;
|
|
1
|
+
{"version":3,"file":"url-matcher.d.ts","sourceRoot":"","sources":["../../src/matching/url-matcher.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;CAC5E,CAAC;AAqEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,UAAU,GACrB,SAAS,MAAM,GAAG,MAAM,EACxB,YAAY,MAAM,KACjB,cAuEF,CAAC"}
|
|
@@ -13,6 +13,7 @@ import { match } from "path-to-regexp";
|
|
|
13
13
|
const extractPathnameOrReturnAsIs = (url) => {
|
|
14
14
|
// Match protocol://host pattern to manually extract pathname
|
|
15
15
|
// This preserves path-to-regexp syntax that URL constructor would corrupt
|
|
16
|
+
// eslint-disable-next-line security/detect-unsafe-regex -- This regex is safe: no nested quantifiers or overlapping alternatives
|
|
16
17
|
const urlPattern = /^https?:\/\/[^/]+(\/.*)?$/;
|
|
17
18
|
const match = urlPattern.exec(url);
|
|
18
19
|
if (match) {
|
|
@@ -33,14 +34,21 @@ const extractPathnameOrReturnAsIs = (url) => {
|
|
|
33
34
|
* Returns Record<string, string | string[]> matching MSW's documented types.
|
|
34
35
|
*/
|
|
35
36
|
const extractParams = (params) => {
|
|
36
|
-
|
|
37
|
+
const result = {};
|
|
38
|
+
for (const [key, value] of Object.entries(params)) {
|
|
37
39
|
// Filter out unnamed groups (numeric keys like '0', '1', '2', etc.)
|
|
38
40
|
if (/^\d+$/.test(key)) {
|
|
39
|
-
|
|
41
|
+
continue;
|
|
40
42
|
}
|
|
41
43
|
// Keep strings and arrays (MSW documented: string | string[])
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
if (typeof value === "string") {
|
|
45
|
+
result[key] = value;
|
|
46
|
+
}
|
|
47
|
+
else if (Array.isArray(value)) {
|
|
48
|
+
result[key] = value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
44
52
|
};
|
|
45
53
|
/**
|
|
46
54
|
* Extract hostname from URL, or return undefined if not a full URL.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scenarist/msw-adapter",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Internal: MSW integration layer for Scenarist framework adapters",
|
|
5
5
|
"author": "Paul Hammond (citypaul) <paul@packsoftware.co.uk>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"path-to-regexp": "^6.3.0",
|
|
45
|
-
"@scenarist/core": "0.3.
|
|
45
|
+
"@scenarist/core": "0.3.2"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"msw": "^2.0.0"
|