@o3r/apis-manager 11.0.0-prerelease.9 → 11.0.0-rc.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/README.md
CHANGED
|
@@ -39,6 +39,7 @@ The **ApiManager** requires the default API Client, which will be used across al
|
|
|
39
39
|
|
|
40
40
|
In the example that follows, we define the default base configuration that API classes will use, as well as a custom configuration for the 'ExampleApi'.
|
|
41
41
|
The plugins and fetch client come from the ``@ama-sdk/core`` module, but custom ones can be created if needed as long as they follow the ``ApiClient`` interface from ``@ama-sdk/core``. More details on ``@ama-sdk/core`` [here](https://www.npmjs.com/package/@ama-sdk/core).
|
|
42
|
+
|
|
42
43
|
```typescript
|
|
43
44
|
import { ApiFetchClient, ApiKeyRequest, JsonTokenReply, JsonTokenRequest, ReviverReply, ExceptionReply } from '@ama-sdk/core';
|
|
44
45
|
import { ApiManager, ApiManagerModule } from '@o3r/apis-manager';
|
|
@@ -113,15 +114,13 @@ The API instances can be retrieved via the injection of the ``ApiFactoryService`
|
|
|
113
114
|
import { ExampleApi } from '@shared/sdk';
|
|
114
115
|
import { ApiFactoryService } from '@o3r/apis-manager';
|
|
115
116
|
|
|
116
|
-
@
|
|
117
|
+
@Injectable()
|
|
117
118
|
class MyClass {
|
|
118
119
|
|
|
119
|
-
|
|
120
|
-
}
|
|
120
|
+
private exampleApi = inject(ApiFactoryService).getApi(ExampleApi); // <- retrieve example API instantiated with set configuration
|
|
121
121
|
|
|
122
122
|
doSomething() {
|
|
123
|
-
const
|
|
124
|
-
const call = exampleApi.doSomething({ ... });
|
|
123
|
+
const call = this.exampleApi.doSomething({ ... });
|
|
125
124
|
}
|
|
126
125
|
|
|
127
126
|
}
|
|
@@ -155,12 +154,10 @@ import { ApiFactoryService } from '@o3r/apis-manager';
|
|
|
155
154
|
@Injectable()
|
|
156
155
|
class MyClass {
|
|
157
156
|
|
|
158
|
-
|
|
159
|
-
}
|
|
157
|
+
private exampleApi = inject(ApiFactoryService).getApi(ExampleApi); // <- retrieve example API instantiated in @custom/sdk
|
|
160
158
|
|
|
161
159
|
doSomething() {
|
|
162
|
-
const
|
|
163
|
-
const call = exampleApi.doSomething({ ... });
|
|
160
|
+
const call = this.exampleApi.doSomething({ ... });
|
|
164
161
|
}
|
|
165
162
|
|
|
166
163
|
}
|
|
@@ -175,18 +172,18 @@ The configuration can be overridden after the instantiation of the API.
|
|
|
175
172
|
|
|
176
173
|
```typescript
|
|
177
174
|
import { ExampleApi } from '@shared/sdk';
|
|
178
|
-
import { ApiFactoryService
|
|
175
|
+
import { ApiFactoryService } from '@o3r/apis-manager';
|
|
179
176
|
import { ApiFetchClient } from '@ama-sdk/core';
|
|
180
177
|
|
|
181
178
|
@Injectable()
|
|
182
179
|
class MyClass {
|
|
183
180
|
|
|
184
|
-
constructor(
|
|
181
|
+
constructor(private apiManager: ApiManager, private apiFactoryService: ApiFactoryService) {
|
|
185
182
|
}
|
|
186
183
|
|
|
187
184
|
doSomething() {
|
|
188
185
|
this.apiManager.setConfiguration(new ApiFetchClient(), ExampleApi); // <- override configuration of Example API
|
|
189
|
-
const exampleApi = apiFactoryService.getApi(ExampleApi, true); // <- retrieve example API with the new configuration (and refresh the cache)
|
|
186
|
+
const exampleApi = this.apiFactoryService.getApi(ExampleApi, true); // <- retrieve example API with the new configuration (and refresh the cache)
|
|
190
187
|
}
|
|
191
188
|
|
|
192
189
|
}
|
|
@@ -78,10 +78,10 @@ export class ApiFactoryService {
|
|
|
78
78
|
getConfigFor(apiClass) {
|
|
79
79
|
return this.apiManager.getConfiguration(apiClass.apiName);
|
|
80
80
|
}
|
|
81
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
82
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
81
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: ApiFactoryService, deps: [{ token: API_TOKEN }, { token: INITIAL_APIS_TOKEN, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
82
|
+
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: ApiFactoryService }); }
|
|
83
83
|
}
|
|
84
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
84
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: ApiFactoryService, decorators: [{
|
|
85
85
|
type: Injectable
|
|
86
86
|
}], ctorParameters: () => [{ type: i1.ApiManager, decorators: [{
|
|
87
87
|
type: Inject,
|
|
@@ -92,4 +92,4 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.10", ngImpo
|
|
|
92
92
|
type: Inject,
|
|
93
93
|
args: [INITIAL_APIS_TOKEN]
|
|
94
94
|
}] }] });
|
|
95
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
95
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBpLWZhY3Rvcnkuc2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9hcGlzLW1hbmFnZXIvYXBpLWZhY3Rvcnkuc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsTUFBTSxFQUFFLFVBQVUsRUFBRSxjQUFjLEVBQUUsUUFBUSxFQUFFLE1BQU0sZUFBZSxDQUFDO0FBQzdFLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFDM0MsT0FBTyxFQUFFLFNBQVMsRUFBRSxNQUFNLHFCQUFxQixDQUFDOzs7QUFLaEQ7O0dBRUc7QUFDSCxNQUFNLENBQ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Bpc1thcGkuYXBpTmFtZV0pO1xuICAgIH0gZWxzZSB7XG4gICAgICB0aGlzLmxvYWRlZEFwaXMgPSB7fTtcbiAgICB9XG4gIH1cblxuICAvKipcbiAgICogUmV0cmlldmUgdGhlIGNvbmZpZ3VyYXRpb24gZm9yIGEgc3BlY2lmaWMgQVBJXG4gICAqIEBwYXJhbSBhcGlDbGFzcyBjbGFzcyBvZiB0aGUgQVBJIGZvciB3aGljaCByZXRyaWV2aW5nIHRoZSBjb25maWd1cmF0aW9uXG4gICAqL1xuICBwdWJsaWMgZ2V0Q29uZmlnRm9yKGFwaUNsYXNzOiBBcGlOYW1lKTogQXBpQ2xpZW50IHtcbiAgICByZXR1cm4gdGhpcy5hcGlNYW5hZ2VyLmdldENvbmZpZ3VyYXRpb24oYXBpQ2xhc3MuYXBpTmFtZSk7XG4gIH1cbn1cbiJdfQ==
|
|
@@ -17,13 +17,13 @@ export class ApiManagerModule {
|
|
|
17
17
|
]
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
21
|
-
/** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "
|
|
22
|
-
/** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "
|
|
20
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: ApiManagerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
21
|
+
/** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.0.4", ngImport: i0, type: ApiManagerModule }); }
|
|
22
|
+
/** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: ApiManagerModule, providers: [
|
|
23
23
|
ApiFactoryService
|
|
24
24
|
] }); }
|
|
25
25
|
}
|
|
26
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
26
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: ApiManagerModule, decorators: [{
|
|
27
27
|
type: NgModule,
|
|
28
28
|
args: [{
|
|
29
29
|
providers: [
|
|
@@ -31,4 +31,4 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.10", ngImpo
|
|
|
31
31
|
]
|
|
32
32
|
}]
|
|
33
33
|
}] });
|
|
34
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
34
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBpLW1hbmFnZXIubW9kdWxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2FwaXMtbWFuYWdlci9hcGktbWFuYWdlci5tb2R1bGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUF1QixRQUFRLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFDOUQsT0FBTyxFQUFFLGlCQUFpQixFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFFMUQsT0FBTyxFQUFFLFNBQVMsRUFBRSxNQUFNLHFCQUFxQixDQUFDOztBQUVoRCwyRkFBMkY7QUFNM0YsTUFBTSxPQUFPLGdCQUFnQjtJQUMzQjs7OztPQUlHO0lBQ0ksTUFBTSxDQUFDLE9BQU8sQ0FBQyxVQUFzQjtRQUMxQyxPQUFPO1lBQ0wsUUFBUSxFQUFFLGdCQUFnQjtZQUMxQixTQUFTLEVBQUU7Z0JBQ1QsRUFBRSxPQUFPLEVBQUUsU0FBUyxFQUFFLFFBQVEsRUFBRSxVQUFVLEVBQUU7YUFDN0M7U0FDRixDQUFDO0lBQ0osQ0FBQztpSUFiVSxnQkFB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iB7XG4gICAgcmV0dXJuIHtcbiAgICAgIG5nTW9kdWxlOiBBcGlNYW5hZ2VyTW9kdWxlLFxuICAgICAgcHJvdmlkZXJzOiBbXG4gICAgICAgIHsgcHJvdmlkZTogQVBJX1RPS0VOLCB1c2VWYWx1ZTogYXBpTWFuYWdlciB9XG4gICAgICBdXG4gICAgfTtcbiAgfVxufVxuIl19
|
|
@@ -125,10 +125,10 @@ class ApiFactoryService {
|
|
|
125
125
|
getConfigFor(apiClass) {
|
|
126
126
|
return this.apiManager.getConfiguration(apiClass.apiName);
|
|
127
127
|
}
|
|
128
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
129
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
128
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: ApiFactoryService, deps: [{ token: API_TOKEN }, { token: INITIAL_APIS_TOKEN, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
129
|
+
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: ApiFactoryService }); }
|
|
130
130
|
}
|
|
131
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
131
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: ApiFactoryService, decorators: [{
|
|
132
132
|
type: Injectable
|
|
133
133
|
}], ctorParameters: () => [{ type: ApiManager, decorators: [{
|
|
134
134
|
type: Inject,
|
|
@@ -155,13 +155,13 @@ class ApiManagerModule {
|
|
|
155
155
|
]
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
159
|
-
/** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "
|
|
160
|
-
/** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "
|
|
158
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: ApiManagerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
159
|
+
/** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.0.4", ngImport: i0, type: ApiManagerModule }); }
|
|
160
|
+
/** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: ApiManagerModule, providers: [
|
|
161
161
|
ApiFactoryService
|
|
162
162
|
] }); }
|
|
163
163
|
}
|
|
164
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
164
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: ApiManagerModule, decorators: [{
|
|
165
165
|
type: NgModule,
|
|
166
166
|
args: [{
|
|
167
167
|
providers: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o3r-apis-manager.mjs","sources":["../../src/apis-manager/api-manager.ts","../../src/apis-manager/api-manager.token.ts","../../src/apis-manager/api-factory.service.ts","../../src/apis-manager/api-manager.module.ts","../../src/apis-manager/api-manager.helpers.ts","../../src/o3r-apis-manager.ts"],"sourcesContent":["import type { ApiClient } from '@ama-sdk/core';\n\n/**\n * Api manager is responsible to provide an api configuration to a service factory, so that it could instantiate an API\n * with the right parameters. It contains a default configuration and a map of specific configurations for API / set of\n * API. Configurations are only exposed through the method getConfiguration, which will merge the default configuration\n * and the requested one.\n */\nexport class ApiManager {\n private defaultConfiguration: ApiClient;\n private apiConfigurations: { [key: string]: ApiClient };\n\n /**\n * Map of registered Api Client associated to specific API\n * @warning This should not be used to get the ApiClient for an API, the function getConfiguration() should be used instead\n */\n public get registeredApiConfigurations() {\n return {...this.apiConfigurations} as const;\n }\n\n /**\n * Create an API manager using a custom ApiClient\n * @param defaultConfiguration\n */\n constructor(defaultConfiguration: ApiClient, apiConfigurations: { [key: string]: ApiClient } = {}) {\n this.defaultConfiguration = defaultConfiguration;\n this.apiConfigurations = apiConfigurations;\n }\n\n /**\n * Retrieve a configuration for a specific API\n * @param api API to get the configuration for\n */\n public getConfiguration(api?: string): ApiClient {\n return api && this.apiConfigurations[api] || this.defaultConfiguration;\n }\n\n /**\n * Set or override API configuration\n * @param apiClient API configuration to override to the given api\n * @param api API name to override, the default configuration will be used if not specified\n */\n public setConfiguration(apiClient: ApiClient, api?: string): void {\n if (api) {\n this.apiConfigurations[api] = apiClient;\n } else {\n this.defaultConfiguration = apiClient;\n }\n }\n}\n","import { InjectionToken } from '@angular/core';\nimport { ApiManager } from './api-manager';\n\n/**\n * Token used by the core library to provide an Api manager to services. It can be provided in the app.\n */\nexport const API_TOKEN = new InjectionToken<ApiManager>('Custom API manager token');\n","import type { Api, ApiClient, ApiName } from '@ama-sdk/core';\nimport { Inject, Injectable, InjectionToken, Optional } from '@angular/core';\nimport { ApiManager } from './api-manager';\nimport { API_TOKEN } from './api-manager.token';\n\n/** Type of the Class of an SDK Api */\nexport type ApiClassType<T extends Api = Api> = (new (client: ApiClient) => T) & ApiName;\n\n/**\n * Initial APIs instantiations\n */\nexport const INITIAL_APIS_TOKEN = new InjectionToken<(Api | ApiClassType)[]>('Initial APIs token');\n\n@Injectable()\nexport class ApiFactoryService {\n\n /** Map of loaded APIs */\n private loadedApis: Record<string, Api> = {};\n\n constructor(@Inject(API_TOKEN) private readonly apiManager: ApiManager, @Optional() @Inject(INITIAL_APIS_TOKEN) apis?: (Api | ApiClassType)[]) {\n if (apis) {\n this.updateApiMapping(apis);\n }\n }\n\n /**\n * Determine if the given parameter is a API class\n * @param apiClass object to check\n */\n private isApiClass<T extends Api = Api>(apiClass: any): apiClass is ApiClassType<T> {\n return !!apiClass.apiName && typeof apiClass === 'function';\n }\n\n /**\n * Retrieve a specific API with loaded configuration\n * @param apiClass class of the API to retrieve\n * @param refreshCache Ignore cached API instance and refresh it\n */\n public getApi<T extends Api>(apiClass: (new (client: ApiClient) => T) & ApiName, refreshCache = false): T {\n const cache = this.loadedApis[apiClass.apiName];\n if (!refreshCache && cache) {\n return cache as T;\n }\n\n // eslint-disable-next-line new-cap\n const instance = new apiClass(this.getConfigFor(apiClass));\n this.loadedApis[apiClass.apiName] = instance;\n return instance;\n }\n\n /**\n * Update the Map of loaded APIs.\n * Note: Can be used to override the a specific API\n * @param map Map of loaded APIs to update\n */\n public updateApiMapping(map: (Api | ApiClassType)[] | Record<string, (Api | ApiClassType)>) {\n const newItems: Record<string, (Api | ApiClassType)> = Array.isArray(map) ? map\n .reduce<Record<string, Api | ApiClassType<Api>>>((acc, curr) => {\n acc[curr.apiName] = curr;\n return acc;\n }, {}) : map;\n\n this.loadedApis = {\n ...this.loadedApis,\n ...Object.entries(newItems)\n .reduce<Record<string, Api>>((acc, [apiName, api]) => {\n // eslint-disable-next-line new-cap\n acc[apiName] = this.isApiClass(api) ? new api(this.getConfigFor(api)) : api;\n return acc;\n }, {})\n };\n }\n\n /**\n * Clear the cache of loaded APIs\n * @param apis Whitelist of APIs to clear from the cache, if specified only these apis will be removed from the cache\n */\n public clearCache(apis?: ApiName[]) {\n if (apis) {\n apis.forEach((api) => delete this.loadedApis[api.apiName]);\n } else {\n this.loadedApis = {};\n }\n }\n\n /**\n * Retrieve the configuration for a specific API\n * @param apiClass class of the API for which retrieving the configuration\n */\n public getConfigFor(apiClass: ApiName): ApiClient {\n return this.apiManager.getConfiguration(apiClass.apiName);\n }\n}\n","import { ModuleWithProviders, NgModule } from '@angular/core';\nimport { ApiFactoryService } from './api-factory.service';\nimport { ApiManager } from './api-manager';\nimport { API_TOKEN } from './api-manager.token';\n\n// Module that needs to be imported by the application to instantiate an SDK configuration.\n@NgModule({\n providers: [\n ApiFactoryService\n ]\n})\nexport class ApiManagerModule {\n /**\n * Provide a custom apiManager\n * A factory can be provided via injection to the token API_TOKEN\n * @param apiManager\n */\n public static forRoot(apiManager: ApiManager): ModuleWithProviders<ApiManagerModule> {\n return {\n ngModule: ApiManagerModule,\n providers: [\n { provide: API_TOKEN, useValue: apiManager }\n ]\n };\n }\n}\n","/**\n * Add a preconnect `<link>` element to the DOM\n * @param baseUrl the origin href\n * @param supportCrossOrigin add crossorigin attribute to the link element\n */\nexport function appendPreconnect(baseUrl: string, supportCrossOrigin = true): void {\n const preConnectLink = document.createElement('link');\n preConnectLink.setAttribute('rel', 'preconnect');\n preConnectLink.setAttribute('href', baseUrl);\n if (supportCrossOrigin) {\n preConnectLink.setAttribute('crossorigin', '');\n }\n document.head.appendChild(preConnectLink);\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;AAEA;;;;;AAKG;MACU,UAAU,CAAA;AAIrB;;;AAGG;AACH,IAAA,IAAW,2BAA2B,GAAA;AACpC,QAAA,OAAO,EAAC,GAAG,IAAI,CAAC,iBAAiB,EAAU,CAAC;KAC7C;AAED;;;AAGG;IACH,WAAY,CAAA,oBAA+B,EAAE,iBAAA,GAAkD,EAAE,EAAA;AAC/F,QAAA,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;AACjD,QAAA,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;KAC5C;AAED;;;AAGG;AACI,IAAA,gBAAgB,CAAC,GAAY,EAAA;AAClC,QAAA,OAAO,GAAG,IAAI,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,oBAAoB,CAAC;KACxE;AAED;;;;AAIG;IACI,gBAAgB,CAAC,SAAoB,EAAE,GAAY,EAAA;QACxD,IAAI,GAAG,EAAE;AACP,YAAA,IAAI,CAAC,iBAAiB,CAAC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AC;IAC7C,IAAI,kBAAkB,EAAE;AACtB,QAAA,cAAc,CAAC,YAAY,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;KAChD;AACD,IAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;AAC5C;;ACbA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"o3r-apis-manager.mjs","sources":["../../src/apis-manager/api-manager.ts","../../src/apis-manager/api-manager.token.ts","../../src/apis-manager/api-factory.service.ts","../../src/apis-manager/api-manager.module.ts","../../src/apis-manager/api-manager.helpers.ts","../../src/o3r-apis-manager.ts"],"sourcesContent":["import type { ApiClient } from '@ama-sdk/core';\n\n/**\n * Api manager is responsible to provide an api configuration to a service factory, so that it could instantiate an API\n * with the right parameters. It contains a default configuration and a map of specific configurations for API / set of\n * API. Configurations are only exposed through the method getConfiguration, which will merge the default configuration\n * and the requested one.\n */\nexport class ApiManager {\n private defaultConfiguration: ApiClient;\n private apiConfigurations: { [key: string]: ApiClient };\n\n /**\n * Map of registered Api Client associated to specific API\n * @warning This should not be used to get the ApiClient for an API, the function getConfiguration() should be used instead\n */\n public get registeredApiConfigurations() {\n return {...this.apiConfigurations} as const;\n }\n\n /**\n * Create an API manager using a custom ApiClient\n * @param defaultConfiguration\n */\n constructor(defaultConfiguration: ApiClient, apiConfigurations: { [key: string]: ApiClient } = {}) {\n this.defaultConfiguration = defaultConfiguration;\n this.apiConfigurations = apiConfigurations;\n }\n\n /**\n * Retrieve a configuration for a specific API\n * @param api API to get the configuration for\n */\n public getConfiguration(api?: string): ApiClient {\n return api && this.apiConfigurations[api] || this.defaultConfiguration;\n }\n\n /**\n * Set or override API configuration\n * @param apiClient API configuration to override to the given api\n * @param api API name to override, the default configuration will be used if not specified\n */\n public setConfiguration(apiClient: ApiClient, api?: string): void {\n if (api) {\n this.apiConfigurations[api] = apiClient;\n } else {\n this.defaultConfiguration = apiClient;\n }\n }\n}\n","import { InjectionToken } from '@angular/core';\nimport { ApiManager } from './api-manager';\n\n/**\n * Token used by the core library to provide an Api manager to services. It can be provided in the app.\n */\nexport const API_TOKEN = new InjectionToken<ApiManager>('Custom API manager token');\n","import type { Api, ApiClient, ApiName } from '@ama-sdk/core';\nimport { Inject, Injectable, InjectionToken, Optional } from '@angular/core';\nimport { ApiManager } from './api-manager';\nimport { API_TOKEN } from './api-manager.token';\n\n/** Type of the Class of an SDK Api */\nexport type ApiClassType<T extends Api = Api> = (new (client: ApiClient) => T) & ApiName;\n\n/**\n * Initial APIs instantiations\n */\nexport const INITIAL_APIS_TOKEN = new InjectionToken<(Api | ApiClassType)[]>('Initial APIs token');\n\n@Injectable()\nexport class ApiFactoryService {\n\n /** Map of loaded APIs */\n private loadedApis: Record<string, Api> = {};\n\n constructor(@Inject(API_TOKEN) private readonly apiManager: ApiManager, @Optional() @Inject(INITIAL_APIS_TOKEN) apis?: (Api | ApiClassType)[]) {\n if (apis) {\n this.updateApiMapping(apis);\n }\n }\n\n /**\n * Determine if the given parameter is a API class\n * @param apiClass object to check\n */\n private isApiClass<T extends Api = Api>(apiClass: any): apiClass is ApiClassType<T> {\n return !!apiClass.apiName && typeof apiClass === 'function';\n }\n\n /**\n * Retrieve a specific API with loaded configuration\n * @param apiClass class of the API to retrieve\n * @param refreshCache Ignore cached API instance and refresh it\n */\n public getApi<T extends Api>(apiClass: (new (client: ApiClient) => T) & ApiName, refreshCache = false): T {\n const cache = this.loadedApis[apiClass.apiName];\n if (!refreshCache && cache) {\n return cache as T;\n }\n\n // eslint-disable-next-line new-cap\n const instance = new apiClass(this.getConfigFor(apiClass));\n this.loadedApis[apiClass.apiName] = instance;\n return instance;\n }\n\n /**\n * Update the Map of loaded APIs.\n * Note: Can be used to override the a specific API\n * @param map Map of loaded APIs to update\n */\n public updateApiMapping(map: (Api | ApiClassType)[] | Record<string, (Api | ApiClassType)>) {\n const newItems: Record<string, (Api | ApiClassType)> = Array.isArray(map) ? map\n .reduce<Record<string, Api | ApiClassType<Api>>>((acc, curr) => {\n acc[curr.apiName] = curr;\n return acc;\n }, {}) : map;\n\n this.loadedApis = {\n ...this.loadedApis,\n ...Object.entries(newItems)\n .reduce<Record<string, Api>>((acc, [apiName, api]) => {\n // eslint-disable-next-line new-cap\n acc[apiName] = this.isApiClass(api) ? new api(this.getConfigFor(api)) : api;\n return acc;\n }, {})\n };\n }\n\n /**\n * Clear the cache of loaded APIs\n * @param apis Whitelist of APIs to clear from the cache, if specified only these apis will be removed from the cache\n */\n public clearCache(apis?: ApiName[]) {\n if (apis) {\n apis.forEach((api) => delete this.loadedApis[api.apiName]);\n } else {\n this.loadedApis = {};\n }\n }\n\n /**\n * Retrieve the configuration for a specific API\n * @param apiClass class of the API for which retrieving the configuration\n */\n public getConfigFor(apiClass: ApiName): ApiClient {\n return this.apiManager.getConfiguration(apiClass.apiName);\n }\n}\n","import { ModuleWithProviders, NgModule } from '@angular/core';\nimport { ApiFactoryService } from './api-factory.service';\nimport { ApiManager } from './api-manager';\nimport { API_TOKEN } from './api-manager.token';\n\n// Module that needs to be imported by the application to instantiate an SDK configuration.\n@NgModule({\n providers: [\n ApiFactoryService\n ]\n})\nexport class ApiManagerModule {\n /**\n * Provide a custom apiManager\n * A factory can be provided via injection to the token API_TOKEN\n * @param apiManager\n */\n public static forRoot(apiManager: ApiManager): ModuleWithProviders<ApiManagerModule> {\n return {\n ngModule: ApiManagerModule,\n providers: [\n { provide: API_TOKEN, useValue: apiManager }\n ]\n };\n }\n}\n","/**\n * Add a preconnect `<link>` element to the DOM\n * @param baseUrl the origin href\n * @param supportCrossOrigin add crossorigin attribute to the link element\n */\nexport function appendPreconnect(baseUrl: string, supportCrossOrigin = true): void {\n const preConnectLink = document.createElement('link');\n preConnectLink.setAttribute('rel', 'preconnect');\n preConnectLink.setAttribute('href', baseUrl);\n if (supportCrossOrigin) {\n preConnectLink.setAttribute('crossorigin', '');\n }\n document.head.appendChild(preConnectLink);\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"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A,GAAA,EAAA,CAAA,mBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,gBAAgB,EAJhB,SAAA,EAAA;YACT,iBAAiB;AAClB,SAAA,EAAA,CAAA,CAAA,EAAA;;2FAEU,gBAAgB,EAAA,UAAA,EAAA,CAAA;kBAL5B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,SAAS,EAAE;wBACT,iBAAiB;AAClB,qBAAA;AACF,iBAAA,CAAA;;;ACVD;;;;AAIG;SACa,gBAAgB,CAAC,OAAe,EAAE,kBAAkB,GAAG,IAAI,EAAA;IACzE,MAAM,cAAc,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;AACtD,IAAA,cAAc,CAAC,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;AACjD,IAAA,cAAc,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,IAAI,kBAAkB,EAAE;AACtB,QAAA,cAAc,CAAC,YAAY,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;KAChD;AACD,IAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;AAC5C;;ACbA;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@o3r/apis-manager",
|
|
3
|
-
"version": "11.0.0-
|
|
3
|
+
"version": "11.0.0-rc.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
"otter-module"
|
|
12
12
|
],
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"@ama-sdk/core": "^11.0.0-
|
|
15
|
-
"@angular-devkit/schematics": "~
|
|
16
|
-
"@angular/common": "~
|
|
17
|
-
"@angular/core": "~
|
|
18
|
-
"@o3r/schematics": "^11.0.0-
|
|
19
|
-
"@schematics/angular": "~
|
|
14
|
+
"@ama-sdk/core": "^11.0.0-rc.2",
|
|
15
|
+
"@angular-devkit/schematics": "~18.0.0",
|
|
16
|
+
"@angular/common": "~18.0.0",
|
|
17
|
+
"@angular/core": "~18.0.0",
|
|
18
|
+
"@o3r/schematics": "^11.0.0-rc.2",
|
|
19
|
+
"@schematics/angular": "~18.0.0",
|
|
20
20
|
"rxjs": "^7.8.1",
|
|
21
21
|
"typescript": "~5.4.2"
|
|
22
22
|
},
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"schematics": "./collection.json",
|
|
38
38
|
"engines": {
|
|
39
|
-
"node": "
|
|
39
|
+
"node": "^18.19.1 || ^20.11.1 || >=22.0.0"
|
|
40
40
|
},
|
|
41
41
|
"module": "fesm2022/o3r-apis-manager.mjs",
|
|
42
42
|
"typings": "index.d.ts",
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
},
|
|
81
81
|
{
|
|
82
82
|
"name": "Stephane Dalle",
|
|
83
|
+
"url": "https://github.com/sdalle-1A",
|
|
83
84
|
"email": "sdalle-1A@users.noreply.github.com"
|
|
84
85
|
},
|
|
85
86
|
{
|
|
@@ -114,7 +115,10 @@
|
|
|
114
115
|
}
|
|
115
116
|
],
|
|
116
117
|
"bugs": "https://github.com/AmadeusITGroup/otter/issues",
|
|
117
|
-
"repository":
|
|
118
|
+
"repository": {
|
|
119
|
+
"type": "git",
|
|
120
|
+
"url": "git+https://github.com/AmadeusITGroup/otter.git"
|
|
121
|
+
},
|
|
118
122
|
"license": "BSD-3-Clause",
|
|
119
123
|
"homepage": "https://amadeusitgroup.github.io/otter/"
|
|
120
124
|
}
|