@nauticana/sail 0.9.1 → 0.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nauticana/sail",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
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, payout onboarding.",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -1,7 +1,7 @@
1
1
  import { HttpErrorResponse, HttpParams } from "@angular/common/http";
2
2
  import { inject, Injectable } from "@angular/core";
3
- import { catchError, map, Observable, throwError } from "rxjs";
4
- import { PaginatedList } from "../model/appdata";
3
+ import { catchError, map, Observable, switchMap, take, throwError } from "rxjs";
4
+ import { ApplicationData, PaginatedList } from "../model/appdata";
5
5
  import { RestURL } from "./rest_url";
6
6
  import { BaseAuthService } from "./auth.service";
7
7
  import { BaseRestService } from "./base_rest.service";
@@ -56,28 +56,45 @@ export class BackendService extends BaseRestService {
56
56
  return params;
57
57
  }
58
58
 
59
+ /** Gates a CRUD call on appdata being loaded — `appData$` is a ReplaySubject(1) so this resolves synchronously once the cache is populated, and blocks the call (instead of throwing) when a component fires CRUD before loadAppData() finishes. */
60
+ private appDataReady(): Observable<ApplicationData> {
61
+ return this.auth.getAppData().pipe(take(1));
62
+ }
63
+
59
64
  /** Unwraps `{items, limit, offset, total}` to the items array. Pass `_limit` / `_offset` in `filter` to control paging (defaults: 100 / 0). */
60
65
  list<T>(apiName: string, filter?: {[key: string]: string}) : Observable<T[]> {
61
66
  return this.listPaginated<T>(apiName, filter).pipe(map((page) => page.items));
62
67
  }
63
68
 
64
69
  listPaginated<T>(apiName: string, filter?: {[key: string]: string}) : Observable<PaginatedList<T>> {
65
- return this.http.get<PaginatedList<T>>(
66
- this.crudUrl(apiName, 'list'),
67
- {params: this.toParams(filter)},
68
- ).pipe(catchError(this.handleError));
70
+ return this.appDataReady().pipe(
71
+ switchMap(() => this.http.get<PaginatedList<T>>(
72
+ this.crudUrl(apiName, 'list'),
73
+ {params: this.toParams(filter)},
74
+ )),
75
+ catchError(this.handleError),
76
+ );
69
77
  }
70
78
 
71
79
  get<T>(apiName: string, filter?: {[key: string]: string}) : Observable<T> {
72
- return this.http.get<T>(this.crudUrl(apiName, 'get'), {params: this.toParams(filter)}).pipe(catchError(this.handleError));
80
+ return this.appDataReady().pipe(
81
+ switchMap(() => this.http.get<T>(this.crudUrl(apiName, 'get'), {params: this.toParams(filter)})),
82
+ catchError(this.handleError),
83
+ );
73
84
  }
74
85
 
75
86
  post<T>(apiName: string, items: T | T[]) : Observable<{message: string}> {
76
- return this.http.post<{message: string}>(this.crudUrl(apiName, 'post'), items).pipe(catchError(this.handleError));
87
+ return this.appDataReady().pipe(
88
+ switchMap(() => this.http.post<{message: string}>(this.crudUrl(apiName, 'post'), items)),
89
+ catchError(this.handleError),
90
+ );
77
91
  }
78
92
 
79
93
  delete(apiName: string, filter?: {[key: string]: string}): Observable<{message: string}> {
80
- return this.http.delete<{message: string}>(this.crudUrl(apiName, 'delete'), {params: this.toParams(filter)}).pipe(catchError(this.handleError));
94
+ return this.appDataReady().pipe(
95
+ switchMap(() => this.http.delete<{message: string}>(this.crudUrl(apiName, 'delete'), {params: this.toParams(filter)})),
96
+ catchError(this.handleError),
97
+ );
81
98
  }
82
99
 
83
100
  /**