@o3r/apis-manager 12.2.0-prerelease.3 → 12.2.0-prerelease.4
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/apis-manager/api-manager.module.d.ts +12 -2
- package/apis-manager/api-manager.module.d.ts.map +1 -1
- package/apis-manager/api-manager.token.d.ts +1 -1
- package/apis-manager/api-manager.token.d.ts.map +1 -1
- package/fesm2022/o3r-apis-manager.mjs +19 -5
- package/fesm2022/o3r-apis-manager.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
import { ModuleWithProviders } from '@angular/core';
|
|
2
2
|
import { ApiManager } from './api-manager';
|
|
3
3
|
import * as i0 from "@angular/core";
|
|
4
|
+
/**
|
|
5
|
+
* Module that needs to be imported by the application to instantiate an SDK configuration.
|
|
6
|
+
*/
|
|
4
7
|
export declare class ApiManagerModule {
|
|
5
8
|
/**
|
|
6
|
-
* Provide a custom
|
|
7
|
-
* A factory can be provided via injection to the token API_TOKEN
|
|
9
|
+
* Provide a custom {@link ApiManager}
|
|
10
|
+
* A factory can be provided via injection to the token {@link API_TOKEN}
|
|
8
11
|
* @param apiManager
|
|
12
|
+
* @deprecated Please use {@link provideApiManager} instead, will be removed in v14.
|
|
9
13
|
*/
|
|
10
14
|
static forRoot(apiManager: ApiManager): ModuleWithProviders<ApiManagerModule>;
|
|
11
15
|
static ɵfac: i0.ɵɵFactoryDeclaration<ApiManagerModule, never>;
|
|
12
16
|
static ɵmod: i0.ɵɵNgModuleDeclaration<ApiManagerModule, never, never, never>;
|
|
13
17
|
static ɵinj: i0.ɵɵInjectorDeclaration<ApiManagerModule>;
|
|
14
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Provide a custom {@link ApiManager}
|
|
21
|
+
* A factory can be provided via injection to the token {@link API_TOKEN}
|
|
22
|
+
* @param apiManager
|
|
23
|
+
*/
|
|
24
|
+
export declare function provideApiManager(apiManager: ApiManager): import("@angular/core").EnvironmentProviders;
|
|
15
25
|
//# sourceMappingURL=api-manager.module.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-manager.module.d.ts","sourceRoot":"","sources":["../../src/apis-manager/api-manager.module.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"api-manager.module.d.ts","sourceRoot":"","sources":["../../src/apis-manager/api-manager.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EAEpB,MAAM,eAAe,CAAC;AAIvB,OAAO,EACL,UAAU,EACX,MAAM,eAAe,CAAC;;AAKvB;;GAEG;AACH,qBAKa,gBAAgB;IAC3B;;;;;OAKG;WACW,OAAO,CAAC,UAAU,EAAE,UAAU,GAAG,mBAAmB,CAAC,gBAAgB,CAAC;yCAPzE,gBAAgB;0CAAhB,gBAAgB;0CAAhB,gBAAgB;CAe5B;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,gDAKvD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-manager.token.d.ts","sourceRoot":"","sources":["../../src/apis-manager/api-manager.token.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACf,MAAM,eAAe,CAAC;AACvB,OAAO,
|
|
1
|
+
{"version":3,"file":"api-manager.token.d.ts","sourceRoot":"","sources":["../../src/apis-manager/api-manager.token.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACf,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,UAAU,EACX,MAAM,eAAe,CAAC;AAEvB;;GAEG;AACH,eAAO,MAAM,SAAS,4BAA6D,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken, Inject, Optional, Injectable, NgModule } from '@angular/core';
|
|
2
|
+
import { InjectionToken, Inject, Optional, Injectable, NgModule, makeEnvironmentProviders } from '@angular/core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Api manager is responsible to provide an api configuration to a service factory, so that it could instantiate an API
|
|
@@ -155,12 +155,15 @@ function appendPreconnect(baseUrl, supportCrossOrigin = true) {
|
|
|
155
155
|
document.head.append(preConnectLink);
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
/**
|
|
159
|
+
* Module that needs to be imported by the application to instantiate an SDK configuration.
|
|
160
|
+
*/
|
|
159
161
|
class ApiManagerModule {
|
|
160
162
|
/**
|
|
161
|
-
* Provide a custom
|
|
162
|
-
* A factory can be provided via injection to the token API_TOKEN
|
|
163
|
+
* Provide a custom {@link ApiManager}
|
|
164
|
+
* A factory can be provided via injection to the token {@link API_TOKEN}
|
|
163
165
|
* @param apiManager
|
|
166
|
+
* @deprecated Please use {@link provideApiManager} instead, will be removed in v14.
|
|
164
167
|
*/
|
|
165
168
|
static forRoot(apiManager) {
|
|
166
169
|
return {
|
|
@@ -184,10 +187,21 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImpor
|
|
|
184
187
|
]
|
|
185
188
|
}]
|
|
186
189
|
}] });
|
|
190
|
+
/**
|
|
191
|
+
* Provide a custom {@link ApiManager}
|
|
192
|
+
* A factory can be provided via injection to the token {@link API_TOKEN}
|
|
193
|
+
* @param apiManager
|
|
194
|
+
*/
|
|
195
|
+
function provideApiManager(apiManager) {
|
|
196
|
+
return makeEnvironmentProviders([
|
|
197
|
+
ApiFactoryService,
|
|
198
|
+
{ provide: API_TOKEN, useValue: apiManager }
|
|
199
|
+
]);
|
|
200
|
+
}
|
|
187
201
|
|
|
188
202
|
/**
|
|
189
203
|
* Generated bundle index. Do not edit.
|
|
190
204
|
*/
|
|
191
205
|
|
|
192
|
-
export { API_TOKEN, ApiFactoryService, ApiManager, ApiManagerModule, INITIAL_APIS_TOKEN, appendPreconnect };
|
|
206
|
+
export { API_TOKEN, ApiFactoryService, ApiManager, ApiManagerModule, INITIAL_APIS_TOKEN, appendPreconnect, provideApiManager };
|
|
193
207
|
//# sourceMappingURL=o3r-apis-manager.mjs.map
|
|
@@ -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":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,EAAE,QAAQ,EAAE,UAAU;AAC3C;SACF;;iIAZQ,gBAAgB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA,CAAA;kIAAhB,gBAAgB,EAAA,CAAA,CAAA;AAAhB,uBAAA,SAAA,IAAA,CAAA,IAAA,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;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 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 type {\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 makeEnvironmentProviders,\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/**\n * Module that needs to be imported by the application to instantiate an SDK configuration.\n */\n@NgModule({\n providers: [\n ApiFactoryService\n ]\n})\nexport class ApiManagerModule {\n /**\n * Provide a custom {@link ApiManager}\n * A factory can be provided via injection to the token {@link API_TOKEN}\n * @param apiManager\n * @deprecated Please use {@link provideApiManager} instead, will be removed in v14.\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/**\n * Provide a custom {@link ApiManager}\n * A factory can be provided via injection to the token {@link API_TOKEN}\n * @param apiManager\n */\nexport function provideApiManager(apiManager: ApiManager) {\n return makeEnvironmentProviders([\n ApiFactoryService,\n { provide: API_TOKEN, useValue: apiManager }\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;;;AAGG;AACI,IAAA,gBAAgB,CAAC,GAAkB,EAAA;QACxC,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,iBAAiB,CAAC,OAAO,GAAG,KAAK,QAAQ,GAAG,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,oBA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E;wBACT;AACD;AACF,iBAAA;;AAkBD;;;;AAIG;AACG,SAAU,iBAAiB,CAAC,UAAsB,EAAA;AACtD,IAAA,OAAO,wBAAwB,CAAC;QAC9B,iBAAiB;AACjB,QAAA,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU;AAC3C,KAAA,CAAC;AACJ;;AClDA;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@o3r/apis-manager",
|
|
3
|
-
"version": "12.2.0-prerelease.
|
|
3
|
+
"version": "12.2.0-prerelease.4",
|
|
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.2.0-prerelease.
|
|
15
|
-
"@ama-sdk/core": "^12.2.0-prerelease.
|
|
14
|
+
"@ama-sdk/client-fetch": "^12.2.0-prerelease.4",
|
|
15
|
+
"@ama-sdk/core": "^12.2.0-prerelease.4",
|
|
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.2.0-prerelease.
|
|
19
|
+
"@o3r/schematics": "^12.2.0-prerelease.4",
|
|
20
20
|
"@schematics/angular": "^19.0.0",
|
|
21
21
|
"rxjs": "^7.8.1",
|
|
22
22
|
"ts-node": "~10.9.2",
|