@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.
- package/esm2022/lib/sneat-api-service-factory.js +1 -1
- package/esm2022/lib/sneat-api-service-factory.js.map +1 -1
- package/esm2022/lib/sneat-api-service.interface.js.map +1 -1
- package/esm2022/lib/sneat-api-service.js +1 -115
- package/esm2022/lib/sneat-api-service.js.map +1 -1
- package/lib/sneat-api-service-factory.d.ts +1 -1
- package/lib/sneat-api-service.d.ts +1 -29
- package/lib/sneat-api-service.interface.d.ts +1 -20
- package/package.json +5 -2
- package/tsconfig.lib.prod.tsbuildinfo +1 -1
|
@@ -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;
|
|
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;AACnD,OAAO,EAAoB,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;;AAE5C,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAAe,EAAU,EAAE;IACrD,IAAI,OAAO,KAAK,WAAW,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AAC,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":["
|
|
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
|
-
|
|
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,
|
|
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 '
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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"
|