@o3r/apis-manager 12.1.0 → 12.1.7

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.
@@ -22,8 +22,11 @@ export declare class ApiFactoryService {
22
22
  * Retrieve a specific API with loaded configuration
23
23
  * @param apiClass class of the API to retrieve
24
24
  * @param refreshCache Ignore cached API instance and refresh it
25
+ * @param customApiName override the `apiName` set in the `apiClass`
26
+ * @note When passing `customApiName` the configuration is expecting to exist else an error is thrown
27
+ * @note When passing an Api instance that does not match a registered configuration without `customApiName`, the default one will be returned
25
28
  */
26
- getApi<T extends Api>(apiClass: (new (client: ApiClient) => T) & ApiName, refreshCache?: boolean): T;
29
+ getApi<T extends Api>(apiClass: (new (client: ApiClient) => T) & ApiName, refreshCache?: boolean, customApiName?: string): T;
27
30
  /**
28
31
  * Update the Map of loaded APIs.
29
32
  * Note: Can be used to override the a specific API
@@ -34,12 +37,12 @@ export declare class ApiFactoryService {
34
37
  * Clear the cache of loaded APIs
35
38
  * @param apis Whitelist of APIs to clear from the cache, if specified only these apis will be removed from the cache
36
39
  */
37
- clearCache(apis?: ApiName[]): void;
40
+ clearCache(apis?: (ApiName | string)[]): void;
38
41
  /**
39
42
  * Retrieve the configuration for a specific API
40
- * @param apiClass class of the API for which retrieving the configuration
43
+ * @param api API for which retrieving the configuration
41
44
  */
42
- getConfigFor(apiClass: ApiName): ApiClient;
45
+ getConfigFor(api: string | ApiName): ApiClient;
43
46
  static ɵfac: i0.ɵɵFactoryDeclaration<ApiFactoryService, [null, { optional: true; }]>;
44
47
  static ɵprov: i0.ɵɵInjectableDeclaration<ApiFactoryService>;
45
48
  }
@@ -1 +1 @@
1
- {"version":3,"file":"api-factory.service.d.ts","sourceRoot":"","sources":["../../src/apis-manager/api-factory.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,GAAG,EACH,SAAS,EACT,OAAO,EACR,MAAM,eAAe,CAAC;AACvB,OAAO,EAGL,cAAc,EAEf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CAAC;;AAKvB,sCAAsC;AACtC,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,GAAG,GAAG,GAAG,IAAI,CAAC,KAAK,MAAM,EAAE,SAAS,KAAK,CAAC,CAAC,GAAG,OAAO,CAAC;AAEzF;;GAEG;AACH,eAAO,MAAM,kBAAkB,6CAAmE,CAAC;AAEnG,qBACa,iBAAiB;IAIG,OAAO,CAAC,QAAQ,CAAC,UAAU;IAH1D,yBAAyB;IACzB,OAAO,CAAC,UAAU,CAA2B;gBAEG,UAAU,EAAE,UAAU,EAA0C,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,YAAY,CAAC,EAAE;IAM7I;;;OAGG;IACH,OAAO,CAAC,UAAU;IAIlB;;;;;;;OAOG;IACI,MAAM,CAAC,CAAC,SAAS,GAAG,EAAE,QAAQ,EAAE,CAAC,KAAK,MAAM,EAAE,SAAS,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,YAAY,UAAQ,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,CAAC;IAYjI;;;;OAIG;IACI,gBAAgB,CAAC,GAAG,EAAE,CAAC,GAAG,GAAG,YAAY,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,GAAG,YAAY,CAAC,CAAC;IAmB1F;;;OAGG;IACI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,GAAG,MAAM,CAAC,EAAE;IAQ7C;;;OAGG;IACI,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;yCA9E1C,iBAAiB;6CAAjB,iBAAiB;CAiF7B"}
@@ -1,4 +1,4 @@
1
- import type { Api, ApiClient } from '@ama-sdk/core';
1
+ import type { ApiClient, ApiName } from '@ama-sdk/core';
2
2
  /**
3
3
  * Api manager is responsible to provide an api configuration to a service factory, so that it could instantiate an API
4
4
  * with the right parameters. It contains a default configuration and a map of specific configurations for API / set of
@@ -25,13 +25,15 @@ export declare class ApiManager {
25
25
  /**
26
26
  * Retrieve a configuration for a specific API
27
27
  * @param api API to get the configuration for
28
+ * @note When passing a string the configuration is expecting to exist else an error is thrown
29
+ * @note when passing an Api instance that does not match a registered configuration, the default one will be returned
28
30
  */
29
- getConfiguration(api?: string | Api): ApiClient;
31
+ getConfiguration(api?: string | ApiName): ApiClient;
30
32
  /**
31
33
  * Set or override API configuration
32
34
  * @param apiClient API configuration to override to the given api
33
35
  * @param api API name to override, the default configuration will be used if not specified
34
36
  */
35
- setConfiguration(apiClient: ApiClient, api?: string | Api): void;
37
+ setConfiguration(apiClient: ApiClient, api?: string | ApiName): void;
36
38
  }
37
39
  //# sourceMappingURL=api-manager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api-manager.d.ts","sourceRoot":"","sources":["../../src/apis-manager/api-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,GAAG,EACH,SAAS,EACV,MAAM,eAAe,CAAC;AAEvB;;;;;GAKG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,oBAAoB,CAAY;IACxC,OAAO,CAAC,iBAAiB,CAA+B;IAExD;;;OAGG;IACH,IAAW,2BAA2B;;MAErC;IAED;;;OAGG;gBACS,oBAAoB,EAAE,SAAS,EAAE,iBAAiB,GAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;KAAO;IAKjG;;;OAGG;IACI,gBAAgB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS;IAItD;;;;OAIG;IACI,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI;CAOxE"}
1
+ {"version":3,"file":"api-manager.d.ts","sourceRoot":"","sources":["../../src/apis-manager/api-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,OAAO,EACR,MAAM,eAAe,CAAC;AAEvB;;;;;GAKG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,oBAAoB,CAAY;IACxC,OAAO,CAAC,iBAAiB,CAA+B;IAExD;;;OAGG;IACH,IAAW,2BAA2B;;MAErC;IAED;;;OAGG;gBACS,oBAAoB,EAAE,SAAS,EAAE,iBAAiB,GAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;KAAO;IAKjG;;;;;OAKG;IACI,gBAAgB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAW1D;;;;OAIG;IACI,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;CAO5E"}
@@ -26,9 +26,19 @@ class ApiManager {
26
26
  /**
27
27
  * Retrieve a configuration for a specific API
28
28
  * @param api API to get the configuration for
29
+ * @note When passing a string the configuration is expecting to exist else an error is thrown
30
+ * @note when passing an Api instance that does not match a registered configuration, the default one will be returned
29
31
  */
30
32
  getConfiguration(api) {
31
- return (api && this.apiConfigurations[typeof api === 'string' ? api : api.apiName]) || this.defaultConfiguration;
33
+ if (typeof api === 'string') {
34
+ if (this.apiConfigurations[api]) {
35
+ return this.apiConfigurations[api];
36
+ }
37
+ else {
38
+ throw new Error(`Unknown API configuration: ${api}\nKnown API configurations: ${Object.keys(this.apiConfigurations).join(', ')}`);
39
+ }
40
+ }
41
+ return (api && this.apiConfigurations[api.apiName]) || this.defaultConfiguration;
32
42
  }
33
43
  /**
34
44
  * Set or override API configuration
@@ -74,14 +84,18 @@ class ApiFactoryService {
74
84
  * Retrieve a specific API with loaded configuration
75
85
  * @param apiClass class of the API to retrieve
76
86
  * @param refreshCache Ignore cached API instance and refresh it
87
+ * @param customApiName override the `apiName` set in the `apiClass`
88
+ * @note When passing `customApiName` the configuration is expecting to exist else an error is thrown
89
+ * @note When passing an Api instance that does not match a registered configuration without `customApiName`, the default one will be returned
77
90
  */
78
- getApi(apiClass, refreshCache = false) {
79
- const cache = this.loadedApis[apiClass.apiName];
91
+ getApi(apiClass, refreshCache = false, customApiName) {
92
+ const apiName = customApiName ?? apiClass.apiName;
93
+ const cache = this.loadedApis[apiName];
80
94
  if (!refreshCache && cache) {
81
95
  return cache;
82
96
  }
83
- const instance = new apiClass(this.getConfigFor(apiClass));
84
- this.loadedApis[apiClass.apiName] = instance;
97
+ const instance = new apiClass(this.getConfigFor(customApiName ?? apiClass));
98
+ this.loadedApis[apiName] = instance;
85
99
  return instance;
86
100
  }
87
101
  /**
@@ -112,7 +126,7 @@ class ApiFactoryService {
112
126
  */
113
127
  clearCache(apis) {
114
128
  if (apis) {
115
- apis.forEach((api) => delete this.loadedApis[api.apiName]);
129
+ apis.forEach((api) => delete this.loadedApis[typeof api === 'string' ? api : api.apiName]);
116
130
  }
117
131
  else {
118
132
  this.loadedApis = {};
@@ -120,10 +134,10 @@ class ApiFactoryService {
120
134
  }
121
135
  /**
122
136
  * Retrieve the configuration for a specific API
123
- * @param apiClass class of the API for which retrieving the configuration
137
+ * @param api API for which retrieving the configuration
124
138
  */
125
- getConfigFor(apiClass) {
126
- return this.apiManager.getConfiguration(apiClass.apiName);
139
+ getConfigFor(api) {
140
+ return this.apiManager.getConfiguration(api);
127
141
  }
128
142
  /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: ApiFactoryService, deps: [{ token: API_TOKEN }, { token: INITIAL_APIS_TOKEN, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
129
143
  /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: ApiFactoryService }); }
@@ -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.helpers.ts","../../src/apis-manager/api-manager.module.ts","../../src/o3r-apis-manager.ts"],"sourcesContent":["import type {\n Api,\n ApiClient,\n} 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 | Api): ApiClient {\n return (api && this.apiConfigurations[typeof api === 'string' ? api : api.apiName]) || 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 | Api): void {\n if (api) {\n this.apiConfigurations[typeof api === 'string' ? api : api.apiName] = apiClient;\n } else {\n this.defaultConfiguration = apiClient;\n }\n }\n}\n","import {\n InjectionToken,\n} from '@angular/core';\nimport {\n ApiManager,\n} 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 {\n Api,\n ApiClient,\n ApiName,\n} from '@ama-sdk/core';\nimport {\n Inject,\n Injectable,\n InjectionToken,\n Optional,\n} from '@angular/core';\nimport {\n ApiManager,\n} from './api-manager';\nimport {\n API_TOKEN,\n} 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 /** 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 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)\n ? map\n .reduce<Record<string, Api | ApiClassType<Api>>>((acc, curr) => {\n acc[curr.apiName] = curr;\n return acc;\n }, {})\n : map;\n\n this.loadedApis = {\n ...this.loadedApis,\n ...Object.entries(newItems)\n .reduce<Record<string, Api>>((acc, [apiName, api]) => {\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","/**\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.append(preConnectLink);\n}\n","import {\n ModuleWithProviders,\n NgModule,\n} from '@angular/core';\nimport {\n ApiFactoryService,\n} from './api-factory.service';\nimport {\n ApiManager,\n} from './api-manager';\nimport {\n API_TOKEN,\n} 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 * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;AAKA;;;;;AAKG;MACU,UAAU,CAAA;AAIrB;;;AAGG;AACH,IAAA,IAAW,2BAA2B,GAAA;AACpC,QAAA,OAAO,EAAE,GAAG,IAAI,CAAC,iBAAiB,EAAW;;AAG/C;;;AAGG;IACH,WAAY,CAAA,oBAA+B,EAAE,iBAAA,GAAkD,EAAE,EAAA;AAC/F,QAAA,IAAI,CAAC,oBAAoB,GAAG,oBAAoB;AAChD,QAAA,IAAI,CAAC,iBAAiB,GAAG,iB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AAA,EAAA,EAAA,IAAA,EAAA,gBAAgB,EAJhB,SAAA,EAAA;YACT;AACD,SAAA,EAAA,CAAA,CAAA;;2FAEU,gBAAgB,EAAA,UAAA,EAAA,CAAA;kBAL5B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,SAAS,EAAE;wBACT;AACD;AACF,iBAAA;;;ACnBD;;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.helpers.ts","../../src/apis-manager/api-manager.module.ts","../../src/o3r-apis-manager.ts"],"sourcesContent":["import type {\n ApiClient,\n ApiName,\n} 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 * @note When passing a string the configuration is expecting to exist else an error is thrown\n * @note when passing an Api instance that does not match a registered configuration, the default one will be returned\n */\n public getConfiguration(api?: string | ApiName): ApiClient {\n if (typeof api === 'string') {\n if (this.apiConfigurations[api]) {\n return this.apiConfigurations[api];\n } else {\n throw new Error(`Unknown API configuration: ${api}\\nKnown API configurations: ${Object.keys(this.apiConfigurations).join(', ')}`);\n }\n }\n return (api && this.apiConfigurations[api.apiName]) || 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 | ApiName): void {\n if (api) {\n this.apiConfigurations[typeof api === 'string' ? api : api.apiName] = apiClient;\n } else {\n this.defaultConfiguration = apiClient;\n }\n }\n}\n","import {\n InjectionToken,\n} from '@angular/core';\nimport {\n ApiManager,\n} 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 {\n Api,\n ApiClient,\n ApiName,\n} from '@ama-sdk/core';\nimport {\n Inject,\n Injectable,\n InjectionToken,\n Optional,\n} from '@angular/core';\nimport {\n ApiManager,\n} from './api-manager';\nimport {\n API_TOKEN,\n} 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 /** 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 * @param customApiName override the `apiName` set in the `apiClass`\n * @note When passing `customApiName` the configuration is expecting to exist else an error is thrown\n * @note When passing an Api instance that does not match a registered configuration without `customApiName`, the default one will be returned\n */\n public getApi<T extends Api>(apiClass: (new (client: ApiClient) => T) & ApiName, refreshCache = false, customApiName?: string): T {\n const apiName = customApiName ?? apiClass.apiName;\n const cache = this.loadedApis[apiName];\n if (!refreshCache && cache) {\n return cache as T;\n }\n\n const instance = new apiClass(this.getConfigFor(customApiName ?? apiClass));\n this.loadedApis[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)\n ? map\n .reduce<Record<string, Api | ApiClassType<Api>>>((acc, curr) => {\n acc[curr.apiName] = curr;\n return acc;\n }, {})\n : map;\n\n this.loadedApis = {\n ...this.loadedApis,\n ...Object.entries(newItems)\n .reduce<Record<string, Api>>((acc, [apiName, api]) => {\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 | string)[]) {\n if (apis) {\n apis.forEach((api) => delete this.loadedApis[typeof api === 'string' ? api : api.apiName]);\n } else {\n this.loadedApis = {};\n }\n }\n\n /**\n * Retrieve the configuration for a specific API\n * @param api API for which retrieving the configuration\n */\n public getConfigFor(api: string | ApiName): ApiClient {\n return this.apiManager.getConfiguration(api);\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.append(preConnectLink);\n}\n","import {\n ModuleWithProviders,\n NgModule,\n} from '@angular/core';\nimport {\n ApiFactoryService,\n} from './api-factory.service';\nimport {\n ApiManager,\n} from './api-manager';\nimport {\n API_TOKEN,\n} 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 * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;AAKA;;;;;AAKG;MACU,UAAU,CAAA;AAIrB;;;AAGG;AACH,IAAA,IAAW,2BAA2B,GAAA;AACpC,QAAA,OAAO,EAAE,GAAG,IAAI,CAAC,iBAAiB,EAAW;;AAG/C;;;AAGG;IACH,WAAY,CAAA,oBAA+B,EAAE,iBAAA,GAAkD,EAAE,EAAA;AAC/F,QAAA,IAAI,CAAC,oBAAoB,GAAG,oBAAoB;AAChD,QAAA,IAAI,CAAC,iBAAiB,GAAG,iBAAiB;;AAG5C;;;;;AAKG;AACI,IAAA,gBAAgB,CAAC,GAAsB,EAAA;AAC5C,QAAA,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;AAC3B,YAAA,IAAI,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE;AAC/B,gBAAA,OAAO,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC;;iBAC7B;gBACL,MAAM,IAAI,KAAK,CAAC,CAAA,2BAAA,EAA8B,GAAG,CAA+B,4BAAA,EAAA,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAE,CAAA,CAAC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AA,EAAA,EAAA,EAAA,IAAA,EAAA,gBAAgB,EAJhB,SAAA,EAAA;YACT;AACD,SAAA,EAAA,CAAA,CAAA;;2FAEU,gBAAgB,EAAA,UAAA,EAAA,CAAA;kBAL5B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,SAAS,EAAE;wBACT;AACD;AACF,iBAAA;;;ACnBD;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o3r/apis-manager",
3
- "version": "12.1.0",
3
+ "version": "12.1.7",
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/client-fetch": "^12.1.0",
15
- "@ama-sdk/core": "^12.1.0",
14
+ "@ama-sdk/client-fetch": "^12.1.7",
15
+ "@ama-sdk/core": "^12.1.7",
16
16
  "@angular-devkit/schematics": "^19.0.0",
17
17
  "@angular/common": "^19.0.0",
18
18
  "@angular/core": "^19.0.0",
19
- "@o3r/schematics": "^12.1.0",
19
+ "@o3r/schematics": "^12.1.7",
20
20
  "@schematics/angular": "^19.0.0",
21
21
  "rxjs": "^7.8.1",
22
22
  "ts-node": "~10.9.2",