@nauticana/sail 0.5.0 → 0.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nauticana/sail",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Metadata-driven Angular component library for CRUD admin frontends backed by the keel Go backend. Tables, forms, navigation, OTP/2FA/social auth, billing.",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"files": [
|
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
import { HttpErrorResponse, HttpInterceptorFn, HttpResponse } from '@angular/common/http';
|
|
2
2
|
import { catchError, map, throwError } from 'rxjs';
|
|
3
3
|
|
|
4
|
+
// Detect a final response event by structural shape rather than
|
|
5
|
+
// `event instanceof HttpResponse`. Bundling can produce two distinct
|
|
6
|
+
// HttpResponse class identities — the one captured inside sail's compiled
|
|
7
|
+
// module and the one the host app's HttpClient emits — and instanceof
|
|
8
|
+
// then silently returns false. The structural check (presence of `body`
|
|
9
|
+
// + a callable `clone` + a successful `status`) is robust to that and
|
|
10
|
+
// still correctly skips intermediate events like HttpHeaderResponse and
|
|
11
|
+
// HttpProgressEvent.
|
|
12
|
+
function isFinalResponse(e: unknown): e is HttpResponse<unknown> {
|
|
13
|
+
if (!e || typeof e !== 'object') return false;
|
|
14
|
+
const r = e as { type?: number; body?: unknown; clone?: unknown; status?: number };
|
|
15
|
+
// HttpEventType.Response === 4. Filtering by type is the most reliable
|
|
16
|
+
// gate (HttpResponse and HttpHeaderResponse have different type values
|
|
17
|
+
// and only HttpResponse carries `body`).
|
|
18
|
+
return r.type === 4
|
|
19
|
+
&& 'body' in r
|
|
20
|
+
&& typeof r.clone === 'function'
|
|
21
|
+
&& typeof r.status === 'number';
|
|
22
|
+
}
|
|
23
|
+
|
|
4
24
|
export const apiResponseInterceptor: HttpInterceptorFn = (req, next) => {
|
|
5
25
|
return next(req).pipe(
|
|
6
26
|
map(event => {
|
|
7
|
-
if (event
|
|
27
|
+
if (isFinalResponse(event)) {
|
|
8
28
|
const body = event.body as Record<string, unknown> | null;
|
|
9
|
-
if (body && 'data' in body) {
|
|
29
|
+
if (body && typeof body === 'object' && 'data' in body) {
|
|
10
30
|
return event.clone({ body: body['data'] });
|
|
11
31
|
}
|
|
12
32
|
}
|