@sneat/api 0.23.0 → 0.25.0

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.
@@ -1,6 +1,6 @@
1
1
  import { Injectable, inject } from '@angular/core';
2
+ import { SneatApiService } from '@sneat/api-public';
2
3
  import { parseStoreRef } from '@sneat/core';
3
- import { SneatApiService } from './sneat-api-service';
4
4
  import * as i0 from "@angular/core";
5
5
  export const getStoreUrl = (storeId) => {
6
6
  if (storeId === 'firestore') {
@@ -1 +1 @@
1
- {"version":3,"file":"sneat-api-service-factory.js","sourceRoot":"","sources":["../../../../../libs/api/src/lib/sneat-api-service-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;;AAEtD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAAe,EAAU,EAAE;IACrD,IAAI,OAAO,KAAK,WAAW,EAAE,CAAC;QAC5B,MAAM,CAAC,GAAG,0BAA0B,CAAC,CAAC,yCAAyC;QAC/E,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5D,CAAC;IACD,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,CAAC;QAC7C,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC;IAClD,CAAC;IACD,IAAI,OAAO,CAAC,UAAU,CAAC,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OAAO,OAAO,CAAC;YACjB;gBACE,MAAM,IAAI,KAAK,CAAC,sBAAsB,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;8GA7BU,sBAAsB;kHAAtB,sBAAsB,cADT,MAAM;;2FACnB,sBAAsB;kBADlC,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE","sourcesContent":["import { Injectable, inject } from '@angular/core';\nimport { ISneatApiService } from './sneat-api-service.interface';\nimport { parseStoreRef } from '@sneat/core';\nimport { SneatApiService } from './sneat-api-service';\n\nexport const getStoreUrl = (storeId: string): string => {\n if (storeId === 'firestore') {\n const v = 'http://localhost:4300/v0'; //environment.agents.firestoreStoreAgent;\n return v.endsWith('/') ? v.substring(0, v.length - 1) : v;\n }\n if (!storeId || storeId.match(/https?:\\/\\//)) {\n return storeId;\n }\n if (storeId.startsWith('http-')) {\n return storeId.replace('http-', 'http' + '://');\n }\n if (storeId.startsWith('https-')) {\n return storeId.replace('https-', 'https://');\n }\n const a = storeId.split(':');\n storeId = `//${a[0]}:${a[1]}`;\n if (a[2]) {\n storeId += ':' + a[2];\n }\n return storeId;\n};\n\n@Injectable({ providedIn: 'root' })\nexport class SneatApiServiceFactory {\n private services: Record<string, ISneatApiService> = {};\n\n public getSneatApiService(storeId: string): ISneatApiService {\n if (!storeId) {\n throw new Error(\n 'storeRef is a required parameter, got empty: ' + typeof storeId,\n );\n }\n const storeRef = parseStoreRef(storeId);\n if (!storeRef.type) {\n throw new Error(\n 'storeRef.type is a required parameter, got empty: ' +\n typeof storeRef.type,\n );\n }\n const id = `${storeRef.type}:${storeRef.url}`;\n let service = this.services[id];\n if (service) {\n return service;\n }\n // const baseUrl = getStoreUrl(storeRefToId(storeRef));\n switch (storeRef.type) {\n case 'firestore':\n this.services[id] = service = inject(SneatApiService);\n return service;\n default:\n throw new Error('unknown store type: ' + storeRef.type);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"sneat-api-service-factory.js","sourceRoot":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B,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAGF,MAAM,OAAO,sBAAsB;IADnC;QAEU,aAAQ,GAAqC,EAAE,CAAC;KA6BzD;IA3BQ,kBAAkB,CAAC,OAAe;QACvC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CACb,+CAA+C,GAAG,OAAO,OAAO,CACjE,CAAC;QACJ,CAAC;QACD,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CACb,oDAAoD;gBAClD,OAAO,QAAQ,CAAC,IAAI,CACvB,CAAC;QACJ,CAAC;QACD,MAAM,EAAE,GAAG,GAAG,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,GAAG,EAAE,CAAC;QAC9C,IAAI,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAChC,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,uDAAuD;QACvD,QAAQ,QAAQ,CAAC,IAAI,EAAE,CAAC;YACtB,KAAK,WAAW;gBACd,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,OAAO,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;gBACtD,OAAO,OAAO,CAAC;YACjB;gBACE,MAAM,IAAI,KAAK,CAAC,sBAAsB,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;8GA7BU,sBAAsB;kHAAtB,sBAAsB,cADT,MAAM;;2FACnB,sBAAsB;kBADlC,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE","sourcesContent":["import { Injectable, inject } from '@angular/core';\nimport { ISneatApiService, SneatApiService } from '@sneat/api-public';\nimport { parseStoreRef } from '@sneat/core';\n\nexport const getStoreUrl = (storeId: string): string => {\n if (storeId === 'firestore') {\n const v = 'http://localhost:4300/v0'; //environment.agents.firestoreStoreAgent;\n return v.endsWith('/') ? v.substring(0, v.length - 1) : v;\n }\n if (!storeId || storeId.match(/https?:\\/\\//)) {\n return storeId;\n }\n if (storeId.startsWith('http-')) {\n return storeId.replace('http-', 'http' + '://');\n }\n if (storeId.startsWith('https-')) {\n return storeId.replace('https-', 'https://');\n }\n const a = storeId.split(':');\n storeId = `//${a[0]}:${a[1]}`;\n if (a[2]) {\n storeId += ':' + a[2];\n }\n return storeId;\n};\n\n@Injectable({ providedIn: 'root' })\nexport class SneatApiServiceFactory {\n private services: Record<string, ISneatApiService> = {};\n\n public getSneatApiService(storeId: string): ISneatApiService {\n if (!storeId) {\n throw new Error(\n 'storeRef is a required parameter, got empty: ' + typeof storeId,\n );\n }\n const storeRef = parseStoreRef(storeId);\n if (!storeRef.type) {\n throw new Error(\n 'storeRef.type is a required parameter, got empty: ' +\n typeof storeRef.type,\n );\n }\n const id = `${storeRef.type}:${storeRef.url}`;\n let service = this.services[id];\n if (service) {\n return service;\n }\n // const baseUrl = getStoreUrl(storeRefToId(storeRef));\n switch (storeRef.type) {\n case 'firestore':\n this.services[id] = service = inject(SneatApiService);\n return service;\n default:\n throw new Error('unknown store type: ' + storeRef.type);\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"sneat-api-service.interface.js","sourceRoot":"","sources":["../../../../../libs/api/src/lib/sneat-api-service.interface.ts"],"names":[],"mappings":"","sourcesContent":["import { Observable } from 'rxjs';\nimport { HttpHeaders, HttpParams } from '@angular/common/http';\n\nexport interface IHttpRequestOptions {\n headers?: HttpHeaders | Record<string, string | string[]>;\n observe?: 'body';\n params?: HttpParams | Record<string, string | string[]>;\n reportProgress?: boolean;\n responseType?: 'json';\n withCredentials?: boolean;\n}\n\n// const SneatApiService = new InjectionToken('ISneatApiService');\n\nexport interface ISneatApiResponse<T> {\n // TODO: Either use or delete\n data: T;\n}\n\nexport interface ISneatApiService {\n post<I, O>(\n endpoint: string,\n body: I,\n options?: IHttpRequestOptions,\n ): Observable<O>;\n\n put<I, O>(\n endpoint: string,\n body: I,\n options?: IHttpRequestOptions,\n ): Observable<O>;\n\n get<T>(\n endpoint: string,\n params?: HttpParams,\n options?: IHttpRequestOptions,\n ): Observable<T>;\n\n getAsAnonymous<T>(\n endpoint: string,\n params?: HttpParams,\n options?: IHttpRequestOptions,\n ): Observable<T>;\n\n delete<T>(\n endpoint: string,\n params?: HttpParams,\n body?: unknown,\n ): Observable<T>;\n}\n"]}
1
+ {"version":3,"file":"sneat-api-service.interface.js","sourceRoot":"","sources":["../../../../../libs/api/src/lib/sneat-api-service.interface.ts"],"names":[],"mappings":"","sourcesContent":["export type {\n IHttpRequestOptions,\n ISneatApiResponse,\n ISneatApiService,\n} from '@sneat/api-public';\n"]}
@@ -1,116 +1,2 @@
1
- import { HttpClient, HttpHeaders } from '@angular/common/http';
2
- import { Inject, Injectable, InjectionToken, Optional, } from '@angular/core';
3
- import { Auth, onIdTokenChanged } from '@angular/fire/auth';
4
- import { Subject, throwError } from 'rxjs';
5
- import * as i0 from "@angular/core";
6
- import * as i1 from "@angular/common/http";
7
- import * as i2 from "@angular/fire/auth";
8
- const userIsNotAuthenticatedNoFirebaseToken = 'User is not authenticated yet - no Firebase ID token';
9
- export const SneatApiAuthTokenProvider = new InjectionToken('SneatApiAuthTokenProvider');
10
- export const SneatApiBaseUrl = new InjectionToken('SneatApiBaseUrl');
11
- // Ecosystem API base URL. Points at api.sneat.cloud — the dedicated API zone
12
- // (its own Cloudflare zone, so the API's analytics/WAF/rate-limits are decoupled
13
- // from the landings on sneat.co). It fronts the Cloud Run deployment of sneat-go
14
- // (the deploy target that actually ships every backend change — the legacy GAE
15
- // deploy behind api.sneat.ws served a stale binary, missing schoolus and
16
- // everything since the requoter module). A Cloudflare Worker (sneat-api-proxy)
17
- // rewrites Host so Cloud Run routes correctly. All apps using
18
- // getStandardSneatProviders() inherit this, so it is the single repoint seam for
19
- // the whole ecosystem.
20
- export const DefaultSneatAppApiBaseUrl = 'https://api.sneat.cloud/v0/';
21
- export class SneatApiService {
22
- constructor(httpClient, baseUrl, afAuth) {
23
- this.httpClient = httpClient;
24
- this.afAuth = afAuth;
25
- this.destroyed = new Subject();
26
- // TODO: It's made public because we use it in Login page, might be a bad idea consider making private and rely on afAuth.idToken event
27
- this.setApiAuthToken = (token) => {
28
- // console.log('setApiAuthToken()', token);
29
- this.authToken = token;
30
- };
31
- this.baseUrl = baseUrl ?? DefaultSneatAppApiBaseUrl;
32
- // console.log('SneatApiService.constructor()', this.baseUrl);
33
- onIdTokenChanged(this.afAuth, {
34
- next: (user) => {
35
- user
36
- ?.getIdToken()
37
- .then(this.setApiAuthToken)
38
- .catch((err) => console.error('getIdToken() error:', err));
39
- },
40
- error: (error) => {
41
- console.error('onIdTokenChanged() error:', error);
42
- },
43
- complete: () => void 0,
44
- });
45
- }
46
- ngOnDestroy() {
47
- this.destroyed.next();
48
- this.destroyed.complete();
49
- }
50
- post(endpoint, body) {
51
- const url = this.baseUrl + endpoint;
52
- // console.log('post()', endpoint, url, body);
53
- return (this.errorIfNotAuthenticated() ||
54
- this.httpClient.post(url, body, {
55
- headers: this.headers(),
56
- }));
57
- }
58
- put(endpoint, body) {
59
- return (this.errorIfNotAuthenticated() ||
60
- this.httpClient.put(this.baseUrl + endpoint, body, {
61
- headers: this.headers(),
62
- }));
63
- }
64
- get(endpoint, params) {
65
- return (this.errorIfNotAuthenticated() ||
66
- this.httpClient.get(this.baseUrl + endpoint, {
67
- headers: this.headers(),
68
- params,
69
- }));
70
- }
71
- getAsAnonymous(endpoint, params) {
72
- return this.httpClient.get(this.baseUrl + endpoint, {
73
- params,
74
- });
75
- }
76
- postAsAnonymous(endpoint, body) {
77
- const url = this.baseUrl + endpoint;
78
- // alert('postAsAnonymous(), url=' + url);
79
- return this.httpClient.post(url, body);
80
- }
81
- delete(endpoint, params, body) {
82
- // console.log('delete()', endpoint, params);
83
- const url = this.baseUrl + endpoint;
84
- return (this.errorIfNotAuthenticated() ||
85
- this.httpClient.delete(url, {
86
- params,
87
- headers: this.headers(),
88
- body,
89
- }));
90
- }
91
- errorIfNotAuthenticated() {
92
- const result = (!this.authToken &&
93
- throwError(() => userIsNotAuthenticatedNoFirebaseToken)) ||
94
- undefined;
95
- return result;
96
- }
97
- headers() {
98
- let headers = new HttpHeaders();
99
- if (this.authToken) {
100
- headers = headers.append('Authorization', 'Bearer ' + this.authToken);
101
- }
102
- return headers;
103
- }
104
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: SneatApiService, deps: [{ token: i1.HttpClient }, { token: SneatApiBaseUrl, optional: true }, { token: i2.Auth }], target: i0.ɵɵFactoryTarget.Injectable }); }
105
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: SneatApiService, providedIn: 'root' }); }
106
- }
107
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: SneatApiService, decorators: [{
108
- type: Injectable,
109
- args: [{ providedIn: 'root' }]
110
- }], ctorParameters: () => [{ type: i1.HttpClient }, { type: undefined, decorators: [{
111
- type: Inject,
112
- args: [SneatApiBaseUrl]
113
- }, {
114
- type: Optional
115
- }] }, { type: i2.Auth }] });
1
+ export { DefaultSneatAppApiBaseUrl, SneatApiBaseUrl, SneatApiService, SneatApiAuthTokenProvider, SneatApiAuthTokenBridge, SneatApiNotAuthenticatedError, } from '@sneat/api-public';
116
2
  //# sourceMappingURL=sneat-api-service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sneat-api-service.js","sourceRoot":"","sources":["../../../../../libs/api/src/lib/sneat-api-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAc,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EACL,MAAM,EACN,UAAU,EACV,cAAc,EAEd,QAAQ,GACT,MAAM,eAAe,CA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,CAAC;IACL,CAAC;IAEM,eAAe,CAAI,QAAgB,EAAE,IAAa;QACvD,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC;QACpC,0CAA0C;QAC1C,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAI,GAAG,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC;IAEM,MAAM,CACX,QAAgB,EAChB,MAAmB,EACnB,IAAc;QAEd,6CAA6C;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC;QACpC,OAAO,CACL,IAAI,CAAC,uBAAuB,EAAE;YAC9B,IAAI,CAAC,UAAU,CAAC,MAAM,CAAI,GAAG,EAAE;gBAC7B,MAAM;gBACN,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;gBACvB,IAAI;aACL,CAAC,CACH,CAAC;IACJ,CAAC;IAEO,uBAAuB;QAC7B,MAAM,MAAM,GACV,CAAC,CAAC,IAAI,CAAC,SAAS;YACd,UAAU,CAAC,GAAG,EAAE,CAAC,qCAAqC,CAAC,CAAC;YAC1D,SAAS,CAAC;QACZ,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,OAAO;QACb,IAAI,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAChC,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;QACxE,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;8GAlHU,eAAe,4CAQhB,eAAe;kHARd,eAAe,cADF,MAAM;;2FACnB,eAAe;kBAD3B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;0BAS7B,MAAM;2BAAC,eAAe;;0BAAG,QAAQ","sourcesContent":["import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';\nimport {\n Inject,\n Injectable,\n InjectionToken,\n OnDestroy,\n Optional,\n} from '@angular/core';\nimport { Auth, onIdTokenChanged } from '@angular/fire/auth';\nimport { Observable, Subject, throwError } from 'rxjs';\nimport { ISneatApiService } from './sneat-api-service.interface';\n\nconst userIsNotAuthenticatedNoFirebaseToken =\n 'User is not authenticated yet - no Firebase ID token';\n\nexport const SneatApiAuthTokenProvider = new InjectionToken(\n 'SneatApiAuthTokenProvider',\n);\nexport const SneatApiBaseUrl = new InjectionToken('SneatApiBaseUrl');\n// Ecosystem API base URL. Points at api.sneat.cloud — the dedicated API zone\n// (its own Cloudflare zone, so the API's analytics/WAF/rate-limits are decoupled\n// from the landings on sneat.co). It fronts the Cloud Run deployment of sneat-go\n// (the deploy target that actually ships every backend change — the legacy GAE\n// deploy behind api.sneat.ws served a stale binary, missing schoolus and\n// everything since the requoter module). A Cloudflare Worker (sneat-api-proxy)\n// rewrites Host so Cloud Run routes correctly. All apps using\n// getStandardSneatProviders() inherit this, so it is the single repoint seam for\n// the whole ecosystem.\nexport const DefaultSneatAppApiBaseUrl = 'https://api.sneat.cloud/v0/';\n\n@Injectable({ providedIn: 'root' }) // Should it be in root? Probably it is OK.\nexport class SneatApiService implements ISneatApiService, OnDestroy {\n private readonly baseUrl: string;\n\n private readonly destroyed = new Subject<void>();\n private authToken?: string;\n\n constructor(\n private readonly httpClient: HttpClient,\n @Inject(SneatApiBaseUrl) @Optional() baseUrl: string | null,\n private readonly afAuth: Auth,\n ) {\n this.baseUrl = baseUrl ?? DefaultSneatAppApiBaseUrl;\n // console.log('SneatApiService.constructor()', this.baseUrl);\n onIdTokenChanged(this.afAuth, {\n next: (user) => {\n user\n ?.getIdToken()\n .then(this.setApiAuthToken)\n .catch((err) => console.error('getIdToken() error:', err));\n },\n error: (error) => {\n console.error('onIdTokenChanged() error:', error);\n },\n complete: () => void 0,\n });\n }\n\n ngOnDestroy() {\n this.destroyed.next();\n this.destroyed.complete();\n }\n\n // TODO: It's made public because we use it in Login page, might be a bad idea consider making private and rely on afAuth.idToken event\n setApiAuthToken = (token?: string) => {\n // console.log('setApiAuthToken()', token);\n this.authToken = token;\n };\n\n public post<T>(endpoint: string, body: unknown): Observable<T> {\n const url = this.baseUrl + endpoint;\n // console.log('post()', endpoint, url, body);\n return (\n this.errorIfNotAuthenticated() ||\n this.httpClient.post<T>(url, body, {\n headers: this.headers(),\n })\n );\n }\n\n public put<T>(endpoint: string, body: unknown): Observable<T> {\n return (\n this.errorIfNotAuthenticated() ||\n this.httpClient.put<T>(this.baseUrl + endpoint, body, {\n headers: this.headers(),\n })\n );\n }\n\n public get<T>(endpoint: string, params?: HttpParams): Observable<T> {\n return (\n this.errorIfNotAuthenticated() ||\n this.httpClient.get<T>(this.baseUrl + endpoint, {\n headers: this.headers(),\n params,\n })\n );\n }\n\n public getAsAnonymous<T>(\n endpoint: string,\n params?: HttpParams,\n ): Observable<T> {\n return this.httpClient.get<T>(this.baseUrl + endpoint, {\n params,\n });\n }\n\n public postAsAnonymous<T>(endpoint: string, body: unknown): Observable<T> {\n const url = this.baseUrl + endpoint;\n // alert('postAsAnonymous(), url=' + url);\n return this.httpClient.post<T>(url, body);\n }\n\n public delete<T>(\n endpoint: string,\n params?: HttpParams,\n body?: unknown,\n ): Observable<T> {\n // console.log('delete()', endpoint, params);\n const url = this.baseUrl + endpoint;\n return (\n this.errorIfNotAuthenticated() ||\n this.httpClient.delete<T>(url, {\n params,\n headers: this.headers(),\n body,\n })\n );\n }\n\n private errorIfNotAuthenticated(): Observable<never> | undefined {\n const result: Observable<never> | undefined =\n (!this.authToken &&\n throwError(() => userIsNotAuthenticatedNoFirebaseToken)) ||\n undefined;\n return result;\n }\n\n private headers(): HttpHeaders {\n let headers = new HttpHeaders();\n if (this.authToken) {\n headers = headers.append('Authorization', 'Bearer ' + this.authToken);\n }\n return headers;\n }\n}\n"]}
1
+ {"version":3,"file":"sneat-api-service.js","sourceRoot":"","sources":["../../../../../libs/api/src/lib/sneat-api-service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,eAAe,EACf,eAAe,EACf,yBAAyB,EACzB,uBAAuB,EACvB,6BAA6B,GAE9B,MAAM,mBAAmB,CAAC","sourcesContent":["export {\n DefaultSneatAppApiBaseUrl,\n SneatApiBaseUrl,\n SneatApiService,\n SneatApiAuthTokenProvider,\n SneatApiAuthTokenBridge,\n SneatApiNotAuthenticatedError,\n type ISneatApiAuthResolution,\n} from '@sneat/api-public';\n"]}
@@ -1,4 +1,4 @@
1
- import { ISneatApiService } from './sneat-api-service.interface';
1
+ import { ISneatApiService } from '@sneat/api-public';
2
2
  import * as i0 from "@angular/core";
3
3
  export declare const getStoreUrl: (storeId: string) => string;
4
4
  export declare class SneatApiServiceFactory {
@@ -1,29 +1 @@
1
- import { HttpClient, HttpParams } from '@angular/common/http';
2
- import { InjectionToken, OnDestroy } from '@angular/core';
3
- import { Auth } from '@angular/fire/auth';
4
- import { Observable } from 'rxjs';
5
- import { ISneatApiService } from './sneat-api-service.interface';
6
- import * as i0 from "@angular/core";
7
- export declare const SneatApiAuthTokenProvider: InjectionToken<unknown>;
8
- export declare const SneatApiBaseUrl: InjectionToken<unknown>;
9
- export declare const DefaultSneatAppApiBaseUrl = "https://api.sneat.cloud/v0/";
10
- export declare class SneatApiService implements ISneatApiService, OnDestroy {
11
- private readonly httpClient;
12
- private readonly afAuth;
13
- private readonly baseUrl;
14
- private readonly destroyed;
15
- private authToken?;
16
- constructor(httpClient: HttpClient, baseUrl: string | null, afAuth: Auth);
17
- ngOnDestroy(): void;
18
- setApiAuthToken: (token?: string) => void;
19
- post<T>(endpoint: string, body: unknown): Observable<T>;
20
- put<T>(endpoint: string, body: unknown): Observable<T>;
21
- get<T>(endpoint: string, params?: HttpParams): Observable<T>;
22
- getAsAnonymous<T>(endpoint: string, params?: HttpParams): Observable<T>;
23
- postAsAnonymous<T>(endpoint: string, body: unknown): Observable<T>;
24
- delete<T>(endpoint: string, params?: HttpParams, body?: unknown): Observable<T>;
25
- private errorIfNotAuthenticated;
26
- private headers;
27
- static ɵfac: i0.ɵɵFactoryDeclaration<SneatApiService, [null, { optional: true; }, null]>;
28
- static ɵprov: i0.ɵɵInjectableDeclaration<SneatApiService>;
29
- }
1
+ export { DefaultSneatAppApiBaseUrl, SneatApiBaseUrl, SneatApiService, SneatApiAuthTokenProvider, SneatApiAuthTokenBridge, SneatApiNotAuthenticatedError, type ISneatApiAuthResolution, } from '@sneat/api-public';
@@ -1,20 +1 @@
1
- import { Observable } from 'rxjs';
2
- import { HttpHeaders, HttpParams } from '@angular/common/http';
3
- export interface IHttpRequestOptions {
4
- headers?: HttpHeaders | Record<string, string | string[]>;
5
- observe?: 'body';
6
- params?: HttpParams | Record<string, string | string[]>;
7
- reportProgress?: boolean;
8
- responseType?: 'json';
9
- withCredentials?: boolean;
10
- }
11
- export interface ISneatApiResponse<T> {
12
- data: T;
13
- }
14
- export interface ISneatApiService {
15
- post<I, O>(endpoint: string, body: I, options?: IHttpRequestOptions): Observable<O>;
16
- put<I, O>(endpoint: string, body: I, options?: IHttpRequestOptions): Observable<O>;
17
- get<T>(endpoint: string, params?: HttpParams, options?: IHttpRequestOptions): Observable<T>;
18
- getAsAnonymous<T>(endpoint: string, params?: HttpParams, options?: IHttpRequestOptions): Observable<T>;
19
- delete<T>(endpoint: string, params?: HttpParams, body?: unknown): Observable<T>;
20
- }
1
+ export type { IHttpRequestOptions, ISneatApiResponse, ISneatApiService, } from '@sneat/api-public';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sneat/api",
3
- "version": "0.23.0",
3
+ "version": "0.25.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -8,7 +8,10 @@
8
8
  "@angular/common": ">=21.0.0",
9
9
  "@angular/core": ">=21.0.0",
10
10
  "firebase": "*",
11
- "@angular/fire": ">=20"
11
+ "@angular/fire": ">=20",
12
+ "@sneat/api-public": "^0.25.0",
13
+ "@sneat/core": "^0.25.0",
14
+ "rxjs": ">=7.8.0"
12
15
  },
13
16
  "dependencies": {
14
17
  "tslib": "2.8.1"