@schmock/angular 1.3.2 → 1.5.1
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/index.d.ts.map +1 -1
- package/dist/index.js +27 -23
- package/package.json +10 -10
- package/dist/index.test.d.ts +0 -1
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,eAAe,EACf,WAAW,EACZ,MAAM,sBAAsB,CAAC;AAQ9B,OAAO,KAAK,EACV,oBAAoB,EAGrB,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,eAAe,EACf,WAAW,EACZ,MAAM,sBAAsB,CAAC;AAQ9B,OAAO,KAAK,EACV,oBAAoB,EAGrB,MAAM,eAAe,CAAC;AA6BvB;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC;IAElE;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,KAAK;QAChD,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,EAAE,GAAG,CAAC;QACX,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAChC,C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AAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAEtD;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAE1C;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,KAAK,EAAE,CAAC,EAAE,EACV,OAAO,GAAE,eAAoB,GAC5B,iBAAiB,CAAC,CAAC,CAAC,CAgBtB"}
|
package/dist/index.js
CHANGED
|
@@ -11,27 +11,18 @@ var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
|
11
11
|
|
|
12
12
|
// src/index.ts
|
|
13
13
|
import {
|
|
14
|
+
HTTP_INTERCEPTORS,
|
|
14
15
|
HttpErrorResponse,
|
|
15
16
|
HttpHeaders,
|
|
16
17
|
HttpResponse
|
|
17
18
|
} from "@angular/common/http";
|
|
18
19
|
import { Injectable } from "@angular/core";
|
|
20
|
+
import { isHttpMethod, ROUTE_NOT_FOUND_CODE } from "@schmock/core";
|
|
19
21
|
import { Observable } from "rxjs";
|
|
20
|
-
var HTTP_METHODS = [
|
|
21
|
-
"GET",
|
|
22
|
-
"POST",
|
|
23
|
-
"PUT",
|
|
24
|
-
"DELETE",
|
|
25
|
-
"PATCH",
|
|
26
|
-
"HEAD",
|
|
27
|
-
"OPTIONS"
|
|
28
|
-
];
|
|
29
|
-
function isHttpMethod(method) {
|
|
30
|
-
return HTTP_METHODS.includes(method);
|
|
31
|
-
}
|
|
32
22
|
function toHttpMethod(method) {
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
const upper = method.toUpperCase();
|
|
24
|
+
if (isHttpMethod(upper)) {
|
|
25
|
+
return upper;
|
|
35
26
|
}
|
|
36
27
|
return "GET";
|
|
37
28
|
}
|
|
@@ -86,7 +77,7 @@ function headersToObject(request) {
|
|
|
86
77
|
const headers = {};
|
|
87
78
|
request.headers.keys().forEach((key) => {
|
|
88
79
|
const value = request.headers.get(key);
|
|
89
|
-
if (value) {
|
|
80
|
+
if (value !== null) {
|
|
90
81
|
headers[key] = value;
|
|
91
82
|
}
|
|
92
83
|
});
|
|
@@ -124,15 +115,20 @@ function createSchmockInterceptor(mock, options = {}) {
|
|
|
124
115
|
};
|
|
125
116
|
}
|
|
126
117
|
return new Observable((observer) => {
|
|
118
|
+
let innerSub;
|
|
119
|
+
let aborted = false;
|
|
127
120
|
mock.handle(requestData.method, requestData.path, {
|
|
128
121
|
headers: requestData.headers,
|
|
129
122
|
body: requestData.body,
|
|
130
123
|
query: requestData.query
|
|
131
124
|
}).then((schmockResponse) => {
|
|
132
|
-
|
|
125
|
+
if (aborted)
|
|
126
|
+
return;
|
|
127
|
+
const body = schmockResponse.body;
|
|
128
|
+
const isRouteNotFound = schmockResponse.status === 404 && body !== null && typeof body === "object" && "code" in body && body.code === ROUTE_NOT_FOUND_CODE;
|
|
133
129
|
if (isRouteNotFound && passthrough) {
|
|
134
|
-
next.handle(req).subscribe(observer);
|
|
135
|
-
} else if (isRouteNotFound
|
|
130
|
+
innerSub = next.handle(req).subscribe(observer);
|
|
131
|
+
} else if (isRouteNotFound) {
|
|
136
132
|
observer.error(new HttpErrorResponse({
|
|
137
133
|
error: { message: "No matching mock route found" },
|
|
138
134
|
status: 404,
|
|
@@ -147,8 +143,10 @@ function createSchmockInterceptor(mock, options = {}) {
|
|
|
147
143
|
const status = response.status || 200;
|
|
148
144
|
if (status >= 400) {
|
|
149
145
|
let errorBody = response.body;
|
|
150
|
-
|
|
151
|
-
|
|
146
|
+
const respBody = response.body;
|
|
147
|
+
if (status === 500 && errorFormatter && respBody !== null && typeof respBody === "object" && "error" in respBody && "code" in respBody) {
|
|
148
|
+
const errMsg = typeof respBody.error === "string" ? respBody.error : "Unknown error";
|
|
149
|
+
const error = new Error(errMsg);
|
|
152
150
|
errorBody = errorFormatter(error, req);
|
|
153
151
|
}
|
|
154
152
|
observer.error(new HttpErrorResponse({
|
|
@@ -171,14 +169,16 @@ function createSchmockInterceptor(mock, options = {}) {
|
|
|
171
169
|
}
|
|
172
170
|
}
|
|
173
171
|
}).catch((error) => {
|
|
172
|
+
if (aborted)
|
|
173
|
+
return;
|
|
174
174
|
let errorBody;
|
|
175
175
|
if (errorFormatter) {
|
|
176
176
|
errorBody = errorFormatter(error instanceof Error ? error : new Error(String(error)), req);
|
|
177
177
|
} else {
|
|
178
|
-
const
|
|
178
|
+
const hasCode = error !== null && typeof error === "object" && "code" in error && typeof error.code === "string";
|
|
179
179
|
errorBody = {
|
|
180
180
|
error: error instanceof Error ? error.message : "Internal Server Error",
|
|
181
|
-
code:
|
|
181
|
+
code: hasCode ? error.code : "INTERNAL_ERROR"
|
|
182
182
|
};
|
|
183
183
|
}
|
|
184
184
|
observer.error(new HttpErrorResponse({
|
|
@@ -188,6 +188,10 @@ function createSchmockInterceptor(mock, options = {}) {
|
|
|
188
188
|
url: req.url
|
|
189
189
|
}));
|
|
190
190
|
});
|
|
191
|
+
return () => {
|
|
192
|
+
aborted = true;
|
|
193
|
+
innerSub?.unsubscribe();
|
|
194
|
+
};
|
|
191
195
|
});
|
|
192
196
|
}
|
|
193
197
|
}
|
|
@@ -198,7 +202,7 @@ function createSchmockInterceptor(mock, options = {}) {
|
|
|
198
202
|
}
|
|
199
203
|
function provideSchmockInterceptor(mock, options) {
|
|
200
204
|
return {
|
|
201
|
-
provide:
|
|
205
|
+
provide: HTTP_INTERCEPTORS,
|
|
202
206
|
useClass: createSchmockInterceptor(mock, options),
|
|
203
207
|
multi: true
|
|
204
208
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schmock/angular",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Angular HTTP interceptor adapter for Schmock",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
@@ -34,15 +34,15 @@
|
|
|
34
34
|
"rxjs": "^7.0.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@angular/common": "^21.1.
|
|
38
|
-
"@angular/compiler": "^21.
|
|
39
|
-
"@angular/core": "^21.1.
|
|
40
|
-
"@angular/platform-browser": "^21.
|
|
41
|
-
"@angular/platform-browser-dynamic": "^21.
|
|
42
|
-
"@types/node": "^25.1
|
|
37
|
+
"@angular/common": "^21.1.3",
|
|
38
|
+
"@angular/compiler": "^21.1.3",
|
|
39
|
+
"@angular/core": "^21.1.3",
|
|
40
|
+
"@angular/platform-browser": "^21.1.3",
|
|
41
|
+
"@angular/platform-browser-dynamic": "^21.1.3",
|
|
42
|
+
"@types/node": "^25.2.1",
|
|
43
43
|
"jsdom": "^27.4.0",
|
|
44
44
|
"typescript": "^5.9.3",
|
|
45
|
-
"vitest": "^4.0.
|
|
45
|
+
"vitest": "^4.0.18",
|
|
46
46
|
"zone.js": "^0.16.0"
|
|
47
47
|
}
|
|
48
48
|
}
|
package/dist/index.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "@angular/compiler";
|