@intellegens/cornerstone-client-angular 0.0.9999-alpha-6 → 0.0.9999-alpha-8
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/README.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import { fromEvent, switchMap, throwError, race, firstValueFrom } from 'rxjs';
|
|
1
|
+
import { fromEvent, switchMap, throwError, race, firstValueFrom, from, tap, combineLatest } from 'rxjs';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
import { signal, Injectable } from '@angular/core';
|
|
4
|
+
import { AuthService, PolicyBase } from '@intellegens/cornerstone-client';
|
|
2
5
|
export * from '@intellegens/cornerstone-client';
|
|
6
|
+
import { toObservable } from '@angular/core/rxjs-interop';
|
|
7
|
+
import { map } from 'rxjs/operators';
|
|
3
8
|
|
|
4
9
|
// Ignore eslint any error in this file
|
|
5
10
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
@@ -14,7 +19,7 @@ class AngularHttpService {
|
|
|
14
19
|
}
|
|
15
20
|
this.httpClient = httpClient;
|
|
16
21
|
}
|
|
17
|
-
async
|
|
22
|
+
async request(url, config) {
|
|
18
23
|
try {
|
|
19
24
|
const method = config?.method || 'GET';
|
|
20
25
|
const headers = config?.headers || {};
|
|
@@ -98,6 +103,228 @@ class AngularHttpService {
|
|
|
98
103
|
}
|
|
99
104
|
}
|
|
100
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Angular Service wrapping the base AuthService from @intellegens/cornerstone-client
|
|
108
|
+
*
|
|
109
|
+
* @template TKey Type parameter for the UserDto
|
|
110
|
+
* @template TUser Type parameter for the UserDto, defaults to UserDto<TKey>
|
|
111
|
+
*/
|
|
112
|
+
class AngularAuthService {
|
|
113
|
+
/**
|
|
114
|
+
* Private instance of the base AuthService
|
|
115
|
+
*/
|
|
116
|
+
_auth = new AuthService();
|
|
117
|
+
/**
|
|
118
|
+
* Private writable signal for the current user
|
|
119
|
+
*/
|
|
120
|
+
_currentUser = signal(undefined, ...(ngDevMode ? [{ debugName: "_currentUser" }] : []));
|
|
121
|
+
/**
|
|
122
|
+
* Current user signal
|
|
123
|
+
*/
|
|
124
|
+
currentUser = this._currentUser.asReadonly();
|
|
125
|
+
/**
|
|
126
|
+
* Observable of the current user
|
|
127
|
+
*/
|
|
128
|
+
currentUser$ = toObservable(this.currentUser);
|
|
129
|
+
whoAmI() {
|
|
130
|
+
return from(this._auth.whoAmI()).pipe(tap(res => {
|
|
131
|
+
if (res.ok) {
|
|
132
|
+
this.setUser(res.result.user);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
console.error(res.error);
|
|
136
|
+
}
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
signIn(username, password) {
|
|
140
|
+
return from(this._auth.signIn(username, password)).pipe(tap(() => {
|
|
141
|
+
this.setUser(this._auth.user);
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
signOut() {
|
|
145
|
+
return from(this._auth.signOut()).pipe(tap(res => {
|
|
146
|
+
if (res.ok) {
|
|
147
|
+
this.setUser(undefined);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
console.error(res.error);
|
|
151
|
+
}
|
|
152
|
+
}));
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* A signal that emits the current user
|
|
156
|
+
* Updates the current user and emits the change to subscribers.
|
|
157
|
+
*/
|
|
158
|
+
setUser(user) {
|
|
159
|
+
this._currentUser.set(user);
|
|
160
|
+
}
|
|
161
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.3", ngImport: i0, type: AngularAuthService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
162
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.3", ngImport: i0, type: AngularAuthService, providedIn: 'root' });
|
|
163
|
+
}
|
|
164
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.3", ngImport: i0, type: AngularAuthService, decorators: [{
|
|
165
|
+
type: Injectable,
|
|
166
|
+
args: [{
|
|
167
|
+
providedIn: 'root',
|
|
168
|
+
}]
|
|
169
|
+
}] });
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Base class for policies. It implements the IPolicy interface.
|
|
173
|
+
*
|
|
174
|
+
* @class PolicyBase
|
|
175
|
+
* @template TParams - The type of the parameters that will be passed to the policy check function.
|
|
176
|
+
*/
|
|
177
|
+
class PolicyBase$ {
|
|
178
|
+
_verificationFn;
|
|
179
|
+
/**
|
|
180
|
+
* Creates a new policy.
|
|
181
|
+
*
|
|
182
|
+
* @param verificationFn - The function that will be used to verify the policy.
|
|
183
|
+
*/
|
|
184
|
+
constructor(verificationFn) {
|
|
185
|
+
this._verificationFn = verificationFn;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Checks if the policy is valid for the given parameters.
|
|
189
|
+
*
|
|
190
|
+
* @return A promise that resolves if the policy is valid, rejects otherwise.
|
|
191
|
+
* @throws {Error} Error if not implemented.
|
|
192
|
+
*/
|
|
193
|
+
async check() {
|
|
194
|
+
throw new Error('Not implemented');
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Checks if the policy is valid for the given parameters.
|
|
198
|
+
*
|
|
199
|
+
* @return An observable that emits a boolean indicating whether the policy is valid.
|
|
200
|
+
* @throws {Error} Error if not implemented.
|
|
201
|
+
*/
|
|
202
|
+
check$() {
|
|
203
|
+
throw new Error('Not implemented');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Class for policies that can be checked.
|
|
208
|
+
*
|
|
209
|
+
* @class Policy
|
|
210
|
+
* @template TParams - The type of the parameters that will be passed to the policy check function.
|
|
211
|
+
*/
|
|
212
|
+
class Policy$ extends PolicyBase$ {
|
|
213
|
+
/**
|
|
214
|
+
* Creates a new policy.
|
|
215
|
+
*
|
|
216
|
+
* @param verificationFn - The function that will be used to verify the policy.
|
|
217
|
+
*/
|
|
218
|
+
constructor(verificationFn) {
|
|
219
|
+
super(verificationFn);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Checks if the policy is valid for the given parameters.
|
|
223
|
+
*
|
|
224
|
+
* @param params - Parameters to pass to the policy check function.
|
|
225
|
+
* @return A promise that resolves if the policy is valid, rejects otherwise.
|
|
226
|
+
*/
|
|
227
|
+
async check(...params) {
|
|
228
|
+
return firstValueFrom(this._verificationFn(...params));
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Checks if the policy is valid for the given parameters.
|
|
232
|
+
*
|
|
233
|
+
* @param params - Parameters to pass to the policy check function.
|
|
234
|
+
* @return An observable that emits a boolean indicating whether the policy is valid.
|
|
235
|
+
*/
|
|
236
|
+
check$(...params) {
|
|
237
|
+
return this._verificationFn(...params);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Checks if a policy is valid for the given parameters.
|
|
243
|
+
*
|
|
244
|
+
* @param policy Policy to check, either an instance or a class (can be IPolicy or IPolicy$).
|
|
245
|
+
* @param params Parameters to pass to the policy check function.
|
|
246
|
+
* @returns An observable that emits a boolean indicating whether the policy is valid.
|
|
247
|
+
*/
|
|
248
|
+
function check$(policy, ...params) {
|
|
249
|
+
let policyInstance;
|
|
250
|
+
// If passed an instance of a policy
|
|
251
|
+
if (policy instanceof PolicyBase || policy instanceof PolicyBase$) {
|
|
252
|
+
policyInstance = policy;
|
|
253
|
+
}
|
|
254
|
+
// If passed a policy class
|
|
255
|
+
else {
|
|
256
|
+
policyInstance = new policy();
|
|
257
|
+
}
|
|
258
|
+
// Check if it's an observable policy (has check$ method)
|
|
259
|
+
if ('check$' in policyInstance && typeof policyInstance.check$ === 'function') {
|
|
260
|
+
return policyInstance.check$(...params);
|
|
261
|
+
}
|
|
262
|
+
// Otherwise, it's a promise-based policy
|
|
263
|
+
else {
|
|
264
|
+
return from(policyInstance.check(...params));
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Composes multiple policies into a single policy.
|
|
269
|
+
*
|
|
270
|
+
* @param composition Composition method, either 'AND' or 'OR'.
|
|
271
|
+
* @param policies Policies to compose (can be IPolicy or IPolicy$).
|
|
272
|
+
* @returns A new IPolicy$ that represents the composition of the policies.
|
|
273
|
+
*/
|
|
274
|
+
function compose$(composition, ...policies) {
|
|
275
|
+
return {
|
|
276
|
+
check: async (...params) => {
|
|
277
|
+
// Convert all policies to observables and get their results
|
|
278
|
+
const observables = policies.map(policy => {
|
|
279
|
+
if ('check$' in policy && typeof policy.check$ === 'function') {
|
|
280
|
+
return policy.check$(...params);
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
return from(policy.check(...params));
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
// Wait for all observables to complete
|
|
287
|
+
return new Promise((resolve, reject) => {
|
|
288
|
+
combineLatest(observables).subscribe({
|
|
289
|
+
next: (results) => {
|
|
290
|
+
if (composition === 'AND') {
|
|
291
|
+
resolve(results.every(result => result === true));
|
|
292
|
+
}
|
|
293
|
+
else if (composition === 'OR') {
|
|
294
|
+
resolve(results.some(result => result === true));
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
reject(new Error('Invalid composition'));
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
error: (err) => reject(err),
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
},
|
|
304
|
+
check$: (...params) => {
|
|
305
|
+
// Convert all policies to observables
|
|
306
|
+
const observables = policies.map(policy => {
|
|
307
|
+
if ('check$' in policy && typeof policy.check$ === 'function') {
|
|
308
|
+
return policy.check$(...params);
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
return from(policy.check(...params));
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
// Combine all observables based on composition
|
|
315
|
+
if (composition === 'AND') {
|
|
316
|
+
return combineLatest(observables).pipe(map(results => results.every(result => result === true)));
|
|
317
|
+
}
|
|
318
|
+
else if (composition === 'OR') {
|
|
319
|
+
return combineLatest(observables).pipe(map(results => results.some(result => result === true)));
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
throw new Error('Invalid composition');
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
101
328
|
/*
|
|
102
329
|
* Public API Surface of cornerstone-client-angular
|
|
103
330
|
*/
|
|
@@ -106,5 +333,5 @@ class AngularHttpService {
|
|
|
106
333
|
* Generated bundle index. Do not edit.
|
|
107
334
|
*/
|
|
108
335
|
|
|
109
|
-
export { AngularHttpService };
|
|
336
|
+
export { AngularAuthService, AngularHttpService, Policy$, PolicyBase$, check$, compose$ };
|
|
110
337
|
//# sourceMappingURL=intellegens-cornerstone-client-angular.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intellegens-cornerstone-client-angular.mjs","sources":["../../../../projects/intellegens/cornerstone-client-angular/src/lib/services/AngularHttpService/index.ts","../../../../projects/intellegens/cornerstone-client-angular/src/public-api.ts","../../../../projects/intellegens/cornerstone-client-angular/src/intellegens-cornerstone-client-angular.ts"],"sourcesContent":["// Ignore eslint any error in this file\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { IHttpService, HttpRequestConfig, HttpResponse } from '@intellegens/cornerstone-client';\nimport { HttpClient } from '@angular/common/http';\nimport { firstValueFrom, fromEvent, throwError, switchMap, race } from 'rxjs';\n\n/**\n * Angular HttpClient-based HTTP service implementation\n */\nexport class AngularHttpService implements IHttpService {\n private httpClient: HttpClient;\n\n constructor(httpClient: HttpClient) {\n if (!httpClient) {\n throw new Error('Angular HttpClient instance is required');\n }\n this.httpClient = httpClient;\n }\n\n public async requestAsync<T = any>(url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>> {\n try {\n const method = config?.method || 'GET';\n const headers = config?.headers || {};\n const body = config?.body;\n const withCredentials = config?.credentials === 'include';\n\n const options = {\n headers,\n withCredentials,\n observe: 'response' as const,\n responseType: 'json' as const,\n };\n\n let request: any;\n\n switch (method.toUpperCase()) {\n case 'GET':\n request = this.httpClient.get(url, options);\n break;\n case 'POST':\n request = this.httpClient.post(url, body ? JSON.parse(body) : null, options);\n break;\n case 'PUT':\n request = this.httpClient.put(url, body ? JSON.parse(body) : null, options);\n break;\n case 'DELETE':\n request = this.httpClient.delete(url, options);\n break;\n case 'PATCH':\n request = this.httpClient.patch(url, body ? JSON.parse(body) : null, options);\n break;\n default:\n throw new Error(`Unsupported HTTP method: ${method}`);\n }\n\n // Handle cancellation using AbortSignal\n if (config?.signal) {\n // Check if signal is already aborted\n if (config.signal.aborted) {\n throw new Error('Request was aborted');\n }\n\n const abort$ = fromEvent(config.signal, 'abort').pipe(switchMap(() => throwError(() => new Error('Request was aborted'))));\n\n request = race(request, abort$);\n }\n\n const response = (await firstValueFrom(request)) as any;\n\n // Convert Angular HttpResponse headers to plain object\n const responseHeaders: Record<string, string> = {};\n if (response.headers) {\n response.headers.keys().forEach((key: string) => {\n responseHeaders[key] = response.headers.get(key);\n });\n }\n\n return {\n ok: response.status >= 200 && response.status < 300,\n status: response.status,\n statusText: response.statusText || 'OK',\n headers: responseHeaders,\n json: async () => response.body,\n text: async () => (typeof response.body === 'string' ? response.body : JSON.stringify(response.body)),\n };\n } catch (error: any) {\n if (error.status !== undefined) {\n // Angular HttpErrorResponse\n const errorHeaders: Record<string, string> = {};\n if (error.headers) {\n error.headers.keys().forEach((key: string) => {\n errorHeaders[key] = error.headers.get(key);\n });\n }\n\n return {\n ok: false,\n status: error.status,\n statusText: error.statusText || 'Error',\n headers: errorHeaders,\n json: async () => error.error,\n text: async () => (typeof error.error === 'string' ? error.error : JSON.stringify(error.error)),\n };\n } else {\n // Other errors\n throw error;\n }\n }\n }\n}\n","/*\n * Public API Surface of cornerstone-client-angular\n */\n\nexport * from './lib/';\nexport * from '@intellegens/cornerstone-client';\n","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ornerstone-client-angular.mjs","sources":["../../../../projects/intellegens/cornerstone-client-angular/src/lib/services/AngularHttpService/index.ts","../../../../projects/intellegens/cornerstone-client-angular/src/lib/services/AngularAuthService/index.ts","../../../../projects/intellegens/cornerstone-client-angular/src/lib/data/auth/policy.ts","../../../../projects/intellegens/cornerstone-client-angular/src/lib/utils/authorization/index.ts","../../../../projects/intellegens/cornerstone-client-angular/src/public-api.ts","../../../../projects/intellegens/cornerstone-client-angular/src/intellegens-cornerstone-client-angular.ts"],"sourcesContent":["// Ignore eslint any error in this file\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { IHttpService, HttpRequestConfig, HttpResponse } from '@intellegens/cornerstone-client';\nimport { HttpClient } from '@angular/common/http';\nimport { firstValueFrom, fromEvent, throwError, switchMap, race } from 'rxjs';\n\n/**\n * Angular HttpClient-based HTTP service implementation\n */\nexport class AngularHttpService implements IHttpService {\n private httpClient: HttpClient;\n\n constructor(httpClient: HttpClient) {\n if (!httpClient) {\n throw new Error('Angular HttpClient instance is required');\n }\n this.httpClient = httpClient;\n }\n\n public async request<T = any>(url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>> {\n try {\n const method = config?.method || 'GET';\n const headers = config?.headers || {};\n const body = config?.body;\n const withCredentials = config?.credentials === 'include';\n\n const options = {\n headers,\n withCredentials,\n observe: 'response' as const,\n responseType: 'json' as const,\n };\n\n let request: any;\n\n switch (method.toUpperCase()) {\n case 'GET':\n request = this.httpClient.get(url, options);\n break;\n case 'POST':\n request = this.httpClient.post(url, body ? JSON.parse(body) : null, options);\n break;\n case 'PUT':\n request = this.httpClient.put(url, body ? JSON.parse(body) : null, options);\n break;\n case 'DELETE':\n request = this.httpClient.delete(url, options);\n break;\n case 'PATCH':\n request = this.httpClient.patch(url, body ? JSON.parse(body) : null, options);\n break;\n default:\n throw new Error(`Unsupported HTTP method: ${method}`);\n }\n\n // Handle cancellation using AbortSignal\n if (config?.signal) {\n // Check if signal is already aborted\n if (config.signal.aborted) {\n throw new Error('Request was aborted');\n }\n\n const abort$ = fromEvent(config.signal, 'abort').pipe(switchMap(() => throwError(() => new Error('Request was aborted'))));\n\n request = race(request, abort$);\n }\n\n const response = (await firstValueFrom(request)) as any;\n\n // Convert Angular HttpResponse headers to plain object\n const responseHeaders: Record<string, string> = {};\n if (response.headers) {\n response.headers.keys().forEach((key: string) => {\n responseHeaders[key] = response.headers.get(key);\n });\n }\n\n return {\n ok: response.status >= 200 && response.status < 300,\n status: response.status,\n statusText: response.statusText || 'OK',\n headers: responseHeaders,\n json: async () => response.body,\n text: async () => (typeof response.body === 'string' ? response.body : JSON.stringify(response.body)),\n };\n } catch (error: any) {\n if (error.status !== undefined) {\n // Angular HttpErrorResponse\n const errorHeaders: Record<string, string> = {};\n if (error.headers) {\n error.headers.keys().forEach((key: string) => {\n errorHeaders[key] = error.headers.get(key);\n });\n }\n\n return {\n ok: false,\n status: error.status,\n statusText: error.statusText || 'Error',\n headers: errorHeaders,\n json: async () => error.error,\n text: async () => (typeof error.error === 'string' ? error.error : JSON.stringify(error.error)),\n };\n } else {\n // Other errors\n throw error;\n }\n }\n }\n}\n","/**\n * Angular Service wrapping the base AuthService from @intellegens/cornerstone-client\n *\n * @template TKey Type parameter for the UserDto\n * @template TUser Type parameter for the UserDto, defaults to UserDto<TKey>\n */\nimport { Injectable, Signal, signal, WritableSignal } from '@angular/core';\nimport { AuthService as BaseAuthService, UserDto } from '@intellegens/cornerstone-client';\nimport { from, tap } from 'rxjs';\nimport { toObservable } from '@angular/core/rxjs-interop';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class AngularAuthService<TKey, TUser extends UserDto<TKey> = UserDto<TKey>> {\n /**\n * Private instance of the base AuthService\n */\n private _auth = new BaseAuthService<TKey, TUser>();\n\n /**\n * Private writable signal for the current user\n */\n protected _currentUser: WritableSignal<TUser | undefined> = signal(undefined);\n /**\n * Current user signal\n */\n public currentUser: Signal<TUser | undefined> = this._currentUser.asReadonly();\n\n /**\n * Observable of the current user\n */\n public currentUser$ = toObservable(this.currentUser);\n\n public whoAmI() {\n return from(this._auth.whoAmI()).pipe(\n tap(res => {\n if (res.ok) {\n this.setUser(res.result.user);\n } else {\n console.error(res.error);\n }\n }),\n );\n }\n\n public signIn(username: string, password: string) {\n return from(this._auth.signIn(username, password)).pipe(\n tap(() => {\n this.setUser(this._auth.user);\n }),\n );\n }\n\n public signOut() {\n return from(this._auth.signOut()).pipe(\n tap(res => {\n if (res.ok) {\n this.setUser(undefined);\n } else {\n console.error(res.error);\n }\n }),\n );\n }\n\n /**\n * A signal that emits the current user\n * Updates the current user and emits the change to subscribers.\n */\n protected setUser(user: TUser | undefined) {\n this._currentUser.set(user);\n }\n}\n","import { IPolicy } from '@intellegens/cornerstone-client';\nimport { firstValueFrom, Observable } from 'rxjs';\n\n/**\n * Interface for policies that can be checked.\n *\n * @interface IPolicy<TParams extends unknown[]>\n * @template TParams - The type of the parameters that will be passed to the policy check function.\n */\nexport interface IPolicy$<TParams extends unknown[]> extends IPolicy<TParams> {\n /**\n * Checks if the policy is valid for the given parameters.\n *\n * @param params - Parameters to pass to the policy check function.\n * @return A promise that resolves if the policy is valid, rejects otherwise.\n */\n check$(...params: TParams): Observable<boolean>;\n}\n\n/**\n * Base class for policies. It implements the IPolicy interface.\n *\n * @class PolicyBase\n * @template TParams - The type of the parameters that will be passed to the policy check function.\n */\nexport class PolicyBase$<TParams extends unknown[]> implements IPolicy$<TParams> {\n protected readonly _verificationFn: (...params: TParams) => Observable<boolean>;\n\n /**\n * Creates a new policy.\n *\n * @param verificationFn - The function that will be used to verify the policy.\n */\n constructor(verificationFn: (...params: TParams) => Observable<boolean>) {\n this._verificationFn = verificationFn;\n }\n\n /**\n * Checks if the policy is valid for the given parameters.\n *\n * @return A promise that resolves if the policy is valid, rejects otherwise.\n * @throws {Error} Error if not implemented.\n */\n public async check(): Promise<boolean> {\n throw new Error('Not implemented');\n }\n\n /**\n * Checks if the policy is valid for the given parameters.\n *\n * @return An observable that emits a boolean indicating whether the policy is valid.\n * @throws {Error} Error if not implemented.\n */\n public check$(): Observable<boolean> {\n throw new Error('Not implemented');\n }\n}\n\n/**\n * Class for policies that can be checked.\n *\n * @class Policy\n * @template TParams - The type of the parameters that will be passed to the policy check function.\n */\nexport class Policy$<TParams extends unknown[]> extends PolicyBase$<TParams> {\n /**\n * Creates a new policy.\n *\n * @param verificationFn - The function that will be used to verify the policy.\n */\n constructor(verificationFn: (...params: TParams) => Observable<boolean>) {\n super(verificationFn);\n }\n\n /**\n * Checks if the policy is valid for the given parameters.\n *\n * @param params - Parameters to pass to the policy check function.\n * @return A promise that resolves if the policy is valid, rejects otherwise.\n */\n public override async check(...params: TParams): Promise<boolean> {\n return firstValueFrom(this._verificationFn(...params));\n }\n\n /**\n * Checks if the policy is valid for the given parameters.\n *\n * @param params - Parameters to pass to the policy check function.\n * @return An observable that emits a boolean indicating whether the policy is valid.\n */\n public override check$(...params: TParams): Observable<boolean> {\n return this._verificationFn(...params);\n }\n}\n","import { IPolicy, PolicyBase } from '@intellegens/cornerstone-client';\nimport { IPolicy$, PolicyBase$ } from '../../data/auth/policy';\nimport { combineLatest, from, Observable } from 'rxjs';\nimport { map } from 'rxjs/operators';\n\n/**\n * Checks if a policy is valid for the given parameters.\n *\n * @param policy Policy to check, either an instance or a class (can be IPolicy or IPolicy$).\n * @param params Parameters to pass to the policy check function.\n * @returns An observable that emits a boolean indicating whether the policy is valid.\n */\nexport function check$<TParams extends unknown[]>(\n policy: IPolicy<TParams> | IPolicy$<TParams> | (new () => IPolicy<TParams>) | (new () => IPolicy$<TParams>),\n ...params: TParams\n): Observable<boolean> {\n let policyInstance: IPolicy<TParams> | IPolicy$<TParams>;\n\n // If passed an instance of a policy\n if (policy instanceof PolicyBase || policy instanceof PolicyBase$) {\n policyInstance = policy as IPolicy<TParams> | IPolicy$<TParams>;\n }\n // If passed a policy class\n else {\n policyInstance = new (policy as new () => IPolicy<TParams> | IPolicy$<TParams>)();\n }\n\n // Check if it's an observable policy (has check$ method)\n if ('check$' in policyInstance && typeof policyInstance.check$ === 'function') {\n return (policyInstance as IPolicy$<TParams>).check$(...params);\n }\n // Otherwise, it's a promise-based policy\n else {\n return from((policyInstance as IPolicy<TParams>).check(...params));\n }\n}\n\n/**\n * Composes multiple policies into a single policy.\n *\n * @param composition Composition method, either 'AND' or 'OR'.\n * @param policies Policies to compose (can be IPolicy or IPolicy$).\n * @returns A new IPolicy$ that represents the composition of the policies.\n */\nexport function compose$<TParams extends unknown[]>(\n composition: 'AND' | 'OR',\n ...policies: (IPolicy<TParams> | IPolicy$<TParams>)[]\n): IPolicy$<TParams> {\n return {\n check: async (...params: TParams): Promise<boolean> => {\n // Convert all policies to observables and get their results\n const observables = policies.map(policy => {\n if ('check$' in policy && typeof policy.check$ === 'function') {\n return (policy as IPolicy$<TParams>).check$(...params);\n } else {\n return from((policy as IPolicy<TParams>).check(...params));\n }\n });\n\n // Wait for all observables to complete\n return new Promise((resolve, reject) => {\n combineLatest(observables).subscribe({\n next: (results) => {\n if (composition === 'AND') {\n resolve(results.every(result => result === true));\n } else if (composition === 'OR') {\n resolve(results.some(result => result === true));\n } else {\n reject(new Error('Invalid composition'));\n }\n },\n error: (err) => reject(err),\n });\n });\n },\n check$: (...params: TParams): Observable<boolean> => {\n // Convert all policies to observables\n const observables = policies.map(policy => {\n if ('check$' in policy && typeof policy.check$ === 'function') {\n return (policy as IPolicy$<TParams>).check$(...params);\n } else {\n return from((policy as IPolicy<TParams>).check(...params));\n }\n });\n\n // Combine all observables based on composition\n if (composition === 'AND') {\n return combineLatest(observables).pipe(\n map(results => results.every(result => result === true))\n );\n } else if (composition === 'OR') {\n return combineLatest(observables).pipe(\n map(results => results.some(result => result === true))\n );\n } else {\n throw new Error('Invalid composition');\n }\n },\n };\n}\n","/*\n * Public API Surface of cornerstone-client-angular\n */\n\nexport * from './lib/';\nexport * from '@intellegens/cornerstone-client';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["BaseAuthService"],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ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _intellegens_cornerstone_client from '@intellegens/cornerstone-client';
|
|
2
|
+
import { IHttpService, HttpRequestConfig, HttpResponse, UserDto, IPolicy } from '@intellegens/cornerstone-client';
|
|
2
3
|
export * from '@intellegens/cornerstone-client';
|
|
3
4
|
import { HttpClient } from '@angular/common/http';
|
|
5
|
+
import * as rxjs from 'rxjs';
|
|
6
|
+
import { Observable } from 'rxjs';
|
|
7
|
+
import * as i0 from '@angular/core';
|
|
8
|
+
import { WritableSignal, Signal } from '@angular/core';
|
|
4
9
|
|
|
5
10
|
/**
|
|
6
11
|
* Angular HttpClient-based HTTP service implementation
|
|
@@ -8,7 +13,127 @@ import { HttpClient } from '@angular/common/http';
|
|
|
8
13
|
declare class AngularHttpService implements IHttpService {
|
|
9
14
|
private httpClient;
|
|
10
15
|
constructor(httpClient: HttpClient);
|
|
11
|
-
|
|
16
|
+
request<T = any>(url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
|
|
12
17
|
}
|
|
13
18
|
|
|
14
|
-
|
|
19
|
+
declare class AngularAuthService<TKey, TUser extends UserDto<TKey> = UserDto<TKey>> {
|
|
20
|
+
/**
|
|
21
|
+
* Private instance of the base AuthService
|
|
22
|
+
*/
|
|
23
|
+
private _auth;
|
|
24
|
+
/**
|
|
25
|
+
* Private writable signal for the current user
|
|
26
|
+
*/
|
|
27
|
+
protected _currentUser: WritableSignal<TUser | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Current user signal
|
|
30
|
+
*/
|
|
31
|
+
currentUser: Signal<TUser | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* Observable of the current user
|
|
34
|
+
*/
|
|
35
|
+
currentUser$: rxjs.Observable<TUser | undefined>;
|
|
36
|
+
whoAmI(): rxjs.Observable<_intellegens_cornerstone_client.ApiResponseDto<_intellegens_cornerstone_client.UserInfoDto<TKey, TUser>, _intellegens_cornerstone_client.EmptyMetadataDto>>;
|
|
37
|
+
signIn(username: string, password: string): rxjs.Observable<_intellegens_cornerstone_client.ApiResponseDto<TUser, _intellegens_cornerstone_client.EmptyMetadataDto>>;
|
|
38
|
+
signOut(): rxjs.Observable<_intellegens_cornerstone_client.ApiResponseDto<undefined, _intellegens_cornerstone_client.EmptyMetadataDto>>;
|
|
39
|
+
/**
|
|
40
|
+
* A signal that emits the current user
|
|
41
|
+
* Updates the current user and emits the change to subscribers.
|
|
42
|
+
*/
|
|
43
|
+
protected setUser(user: TUser | undefined): void;
|
|
44
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<AngularAuthService<any, any>, never>;
|
|
45
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<AngularAuthService<any, any>>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Interface for policies that can be checked.
|
|
50
|
+
*
|
|
51
|
+
* @interface IPolicy<TParams extends unknown[]>
|
|
52
|
+
* @template TParams - The type of the parameters that will be passed to the policy check function.
|
|
53
|
+
*/
|
|
54
|
+
interface IPolicy$<TParams extends unknown[]> extends IPolicy<TParams> {
|
|
55
|
+
/**
|
|
56
|
+
* Checks if the policy is valid for the given parameters.
|
|
57
|
+
*
|
|
58
|
+
* @param params - Parameters to pass to the policy check function.
|
|
59
|
+
* @return A promise that resolves if the policy is valid, rejects otherwise.
|
|
60
|
+
*/
|
|
61
|
+
check$(...params: TParams): Observable<boolean>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Base class for policies. It implements the IPolicy interface.
|
|
65
|
+
*
|
|
66
|
+
* @class PolicyBase
|
|
67
|
+
* @template TParams - The type of the parameters that will be passed to the policy check function.
|
|
68
|
+
*/
|
|
69
|
+
declare class PolicyBase$<TParams extends unknown[]> implements IPolicy$<TParams> {
|
|
70
|
+
protected readonly _verificationFn: (...params: TParams) => Observable<boolean>;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a new policy.
|
|
73
|
+
*
|
|
74
|
+
* @param verificationFn - The function that will be used to verify the policy.
|
|
75
|
+
*/
|
|
76
|
+
constructor(verificationFn: (...params: TParams) => Observable<boolean>);
|
|
77
|
+
/**
|
|
78
|
+
* Checks if the policy is valid for the given parameters.
|
|
79
|
+
*
|
|
80
|
+
* @return A promise that resolves if the policy is valid, rejects otherwise.
|
|
81
|
+
* @throws {Error} Error if not implemented.
|
|
82
|
+
*/
|
|
83
|
+
check(): Promise<boolean>;
|
|
84
|
+
/**
|
|
85
|
+
* Checks if the policy is valid for the given parameters.
|
|
86
|
+
*
|
|
87
|
+
* @return An observable that emits a boolean indicating whether the policy is valid.
|
|
88
|
+
* @throws {Error} Error if not implemented.
|
|
89
|
+
*/
|
|
90
|
+
check$(): Observable<boolean>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Class for policies that can be checked.
|
|
94
|
+
*
|
|
95
|
+
* @class Policy
|
|
96
|
+
* @template TParams - The type of the parameters that will be passed to the policy check function.
|
|
97
|
+
*/
|
|
98
|
+
declare class Policy$<TParams extends unknown[]> extends PolicyBase$<TParams> {
|
|
99
|
+
/**
|
|
100
|
+
* Creates a new policy.
|
|
101
|
+
*
|
|
102
|
+
* @param verificationFn - The function that will be used to verify the policy.
|
|
103
|
+
*/
|
|
104
|
+
constructor(verificationFn: (...params: TParams) => Observable<boolean>);
|
|
105
|
+
/**
|
|
106
|
+
* Checks if the policy is valid for the given parameters.
|
|
107
|
+
*
|
|
108
|
+
* @param params - Parameters to pass to the policy check function.
|
|
109
|
+
* @return A promise that resolves if the policy is valid, rejects otherwise.
|
|
110
|
+
*/
|
|
111
|
+
check(...params: TParams): Promise<boolean>;
|
|
112
|
+
/**
|
|
113
|
+
* Checks if the policy is valid for the given parameters.
|
|
114
|
+
*
|
|
115
|
+
* @param params - Parameters to pass to the policy check function.
|
|
116
|
+
* @return An observable that emits a boolean indicating whether the policy is valid.
|
|
117
|
+
*/
|
|
118
|
+
check$(...params: TParams): Observable<boolean>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Checks if a policy is valid for the given parameters.
|
|
123
|
+
*
|
|
124
|
+
* @param policy Policy to check, either an instance or a class (can be IPolicy or IPolicy$).
|
|
125
|
+
* @param params Parameters to pass to the policy check function.
|
|
126
|
+
* @returns An observable that emits a boolean indicating whether the policy is valid.
|
|
127
|
+
*/
|
|
128
|
+
declare function check$<TParams extends unknown[]>(policy: IPolicy<TParams> | IPolicy$<TParams> | (new () => IPolicy<TParams>) | (new () => IPolicy$<TParams>), ...params: TParams): Observable<boolean>;
|
|
129
|
+
/**
|
|
130
|
+
* Composes multiple policies into a single policy.
|
|
131
|
+
*
|
|
132
|
+
* @param composition Composition method, either 'AND' or 'OR'.
|
|
133
|
+
* @param policies Policies to compose (can be IPolicy or IPolicy$).
|
|
134
|
+
* @returns A new IPolicy$ that represents the composition of the policies.
|
|
135
|
+
*/
|
|
136
|
+
declare function compose$<TParams extends unknown[]>(composition: 'AND' | 'OR', ...policies: (IPolicy<TParams> | IPolicy$<TParams>)[]): IPolicy$<TParams>;
|
|
137
|
+
|
|
138
|
+
export { AngularAuthService, AngularHttpService, Policy$, PolicyBase$, check$, compose$ };
|
|
139
|
+
export type { IPolicy$ };
|
package/package.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intellegens/cornerstone-client-angular",
|
|
3
|
-
"version": "0.0.9999-alpha-
|
|
3
|
+
"version": "0.0.9999-alpha-8",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishable": true,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"peerDependencies": {
|
|
8
|
-
"@angular/common": "
|
|
9
|
-
"@angular/compiler": "
|
|
10
|
-
"@angular/core": "
|
|
11
|
-
"@angular/forms": "
|
|
12
|
-
"@angular/platform-browser": "
|
|
13
|
-
"@angular/router": "
|
|
14
|
-
"rxjs": "
|
|
15
|
-
"@intellegens/cornerstone-client": "
|
|
8
|
+
"@angular/common": "catalog:",
|
|
9
|
+
"@angular/compiler": "catalog:",
|
|
10
|
+
"@angular/core": "catalog:",
|
|
11
|
+
"@angular/forms": "catalog:",
|
|
12
|
+
"@angular/platform-browser": "catalog:",
|
|
13
|
+
"@angular/router": "catalog:",
|
|
14
|
+
"rxjs": "catalog:",
|
|
15
|
+
"@intellegens/cornerstone-client": "workspace:*"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"tslib": "
|
|
18
|
+
"tslib": "catalog:"
|
|
19
19
|
},
|
|
20
20
|
"module": "fesm2022/intellegens-cornerstone-client-angular.mjs",
|
|
21
21
|
"typings": "index.d.ts",
|