@o3r/apis-manager 10.3.0-prerelease.4 → 10.3.0-prerelease.41

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
@@ -12,10 +12,12 @@ This package is an [Otter Framework Module](https://github.com/AmadeusITGroup/ot
12
12
  [![Stable Version](https://img.shields.io/npm/v/@o3r/apis-manager?style=for-the-badge)](https://www.npmjs.com/package/@o3r/apis-manager)
13
13
  [![Bundle Size](https://img.shields.io/bundlephobia/min/@o3r/apis-manager?color=green&style=for-the-badge)](https://www.npmjs.com/package/@o3r/apis-manager)
14
14
 
15
- This module provides services to help you communicate with your APIs. Its responsibility is to provide an API configuration to a service factory so that it could instantiate an API with the right configurations.
15
+ This module links the SDK generated from your APIs using the [Otter generator](https://www.npmjs.com/package/@ama-sdk/schematics) to your application.
16
+ In simpler terms, it offers services to facilitate communication with your APIs.
17
+ Its responsibility is to provide an API configuration to a service factory. This enables the factory to create an API instance with the right configurations.
16
18
 
17
- It contains a default configuration and a map of specific configurations for API / set of API.
18
- Configurations are only exposed through the method `getConfiguration`, which will merge the default configuration and the requested
19
+ It contains a default configuration and a map of specific configurations for an API or a set of APIs.
20
+ Configurations are only exposed through the `getConfiguration` method, which will merge the default configuration and the requested
19
21
  one.
20
22
 
21
23
  ## How to install
@@ -29,13 +31,19 @@ ng add @o3r/apis-manager
29
31
 
30
32
  ## Usage
31
33
 
32
- The API Manager Module will need to be imported and configured in the **application module** which will then be used by the **ApiFactory**.
34
+ The API Manager Module (`ApiManagerModule`) needs to be imported and configured at **application level**, which will then be used by the **ApiFactory** service.
33
35
 
34
36
  ### Application side configuration
35
37
 
36
- The **ApiManager** requires the default Api Client which will be used in all the APIs and support a second parameter that allows the user to define specific Api Client per APIs.
38
+ The **ApiManager** requires the default API Client, which will be used across all APIs. It supports a second parameter that allows to define specific API Client configurations to set or override per API.
37
39
 
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
+ 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).
38
42
  ```typescript
43
+ import { ApiFetchClient, ApiKeyRequest, JsonTokenReply, JsonTokenRequest, ReviverReply, ExceptionReply } from '@ama-sdk/core';
44
+ import { ApiManager, ApiManagerModule } from '@o3r/apis-manager';
45
+
46
+ const PROXY_SERVER = "https://your-enpoint-base-path";
39
47
  export const apiManager = new ApiManager(
40
48
  new ApiFetchClient({
41
49
  basePath: PROXY_SERVER,
@@ -43,7 +51,7 @@ export const apiManager = new ApiManager(
43
51
  }),
44
52
 
45
53
  {
46
- ExampleApi: // <--custom config for ExampleApi, using jsonToken plugins. If fields are not provided, the default ones will be taken.
54
+ ExampleApi: // <-- custom config for ExampleApi, using jsonToken plugins. If fields are not provided, the default ones (previously defined for all APIs via the ApiFetchClient, as first argument of ApiManager constructor) will be used.
47
55
  new ApiFetchClient({
48
56
  requestPlugins: [new JsonTokenRequest()],
49
57
  replyPlugins: [new ReviverReply(), new ExceptionReply(), new JsonTokenReply()]
@@ -54,14 +62,20 @@ export const apiManager = new ApiManager(
54
62
  @NgModule({
55
63
  imports: [
56
64
  ...,
57
- ApiManagerModule.forRoot(apiManager);
65
+ ApiManagerModule.forRoot(apiManager)
58
66
  ]
59
67
  })
60
68
  ```
61
69
 
62
- The **ApiManager** instance can be customized via *factory* provided to `API_TOKEN`:
70
+ The **ApiManager** instance can be customized via a *factory* function provided to the `API_TOKEN`:
63
71
 
64
72
  ```typescript
73
+ import { ApiClient, ApiFetchClient, ApiKeyRequest, Mark, PerformanceMetricPlugin } from '@ama-sdk/core';
74
+ import { ApiManager, ApiManagerModule, API_TOKEN } from '@o3r/apis-manager';
75
+ import { EventTrackService } from '@o3r/analytics';
76
+
77
+ const PROXY_SERVER = "https://your-enpoint-base-path";
78
+
65
79
  export function apiFactory(eventTrackService: EventTrackService): ApiManager {
66
80
 
67
81
  const apiConfig: ApiClient = new ApiFetchClient(
@@ -93,10 +107,11 @@ export function apiFactory(eventTrackService: EventTrackService): ApiManager {
93
107
 
94
108
  ### Retrieve API instance with configuration
95
109
 
96
- The API instances can be retrieved via the injection of the **ApiFactory** provided by the **ApiManagerModule**.
110
+ The API instances can be retrieved via the injection of the ``ApiFactoryService`` provided by the ``ApiManagerModule`` (imported at app level).
97
111
 
98
112
  ```typescript
99
113
  import { ExampleApi } from '@shared/sdk';
114
+ import { ApiFactoryService } from '@o3r/apis-manager';
100
115
 
101
116
  @Inject()
102
117
  class MyClass {
@@ -112,13 +127,10 @@ class MyClass {
112
127
  }
113
128
  ```
114
129
 
115
- > [!WARNING]
116
- > Do not forget to import the **ApiManagerModule** in you component module
117
-
118
130
  ### Enforce custom API usage
119
131
 
120
- Some users may want to enforce existing components or services to use a specific Sdk instead of default API SDK.
121
- To do so the **INITIAL_APIS_TOKEN** will allow to indicate to the **ApiFactory** the class they will need to use (instead of default ones).
132
+ Some users may want to enforce existing components or services to use a specific SDK instead of the default API SDK.
133
+ To do so, the ``INITIAL_APIS_TOKEN`` will allow to indicate to the ``ApiFactory`` which class it must use (instead of default ones).
122
134
 
123
135
  In the AppModule:
124
136
 
@@ -127,14 +139,14 @@ import { ExampleApi, AnotherExampleApi } from '@custom/sdk';
127
139
  import { INITIAL_APIS_TOKEN } from '@o3r/apis-manager';
128
140
 
129
141
  @NgModule({
130
- providers: {
142
+ providers: [
131
143
  { provide: INITIAL_APIS_TOKEN, useValue: [ExampleApi, AnotherExampleApi] }
132
- }
144
+ ]
133
145
  })
134
146
  class AppModule {};
135
147
  ```
136
148
 
137
- Then the following code (from an existing component) will use the custom Api:
149
+ Then the following code (from an existing component) will use the custom API:
138
150
 
139
151
  ```typescript
140
152
  import { ExampleApi } from '@shared/sdk';
@@ -147,7 +159,7 @@ class MyClass {
147
159
  }
148
160
 
149
161
  doSomething() {
150
- const exampleApi = apiFactoryService.getApi(ExampleApi); // <- retrieve example API instantiated from the @custom/sdk
162
+ const exampleApi = apiFactoryService.getApi(ExampleApi); // <- retrieve example API instantiated in @custom/sdk
151
163
  const call = exampleApi.doSomething({ ... });
152
164
  }
153
165
 
@@ -155,7 +167,7 @@ class MyClass {
155
167
  ```
156
168
 
157
169
  > [!NOTE]
158
- > Even though the components that you reuse from a library are importing @shared/sdk, the ApiFactoryService will provide at runtime the one that you provided in your app module
170
+ > Even though the components that you reuse from a library are importing @shared/sdk, the ApiFactoryService will provide at runtime the one that you provided in your app module.
159
171
 
160
172
  ### Override configuration after instantiation
161
173
 
@@ -164,6 +176,7 @@ The configuration can be overridden after the instantiation of the API.
164
176
  ```typescript
165
177
  import { ExampleApi } from '@shared/sdk';
166
178
  import { ApiFactoryService, INTERNAL_API_TOKEN } from '@o3r/apis-manager';
179
+ import { ApiFetchClient } from '@ama-sdk/core';
167
180
 
168
181
  @Injectable()
169
182
  class MyClass {
@@ -172,8 +185,8 @@ class MyClass {
172
185
  }
173
186
 
174
187
  doSomething() {
175
- this.apiManager.setConfiguration(new ApiFetchClient(), ExampleApi); // <- override configuration for Example API
176
- const exampleApi = apiFactoryService.getApi(ExampleApi, true); // <- retrieve example API with the new configuration (and update the cache)
188
+ 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)
177
190
  }
178
191
 
179
192
  }
@@ -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: "17.3.1", 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: "17.3.1", ngImport: i0, type: ApiFactoryService }); }
81
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", 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: "17.3.3", ngImport: i0, type: ApiFactoryService }); }
83
83
  }
84
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: ApiFactoryService, decorators: [{
84
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApiFactoryService, decorators: [{
85
85
  type: Injectable
86
86
  }], ctorParameters: () => [{ type: i1.ApiManager, decorators: [{
87
87
  type: Inject,
@@ -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: "17.3.1", ngImport: i0, type: ApiManagerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
21
- /** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.1", ngImport: i0, type: ApiManagerModule }); }
22
- /** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: ApiManagerModule, providers: [
20
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApiManagerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
21
+ /** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.3", ngImport: i0, type: ApiManagerModule }); }
22
+ /** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApiManagerModule, providers: [
23
23
  ApiFactoryService
24
24
  ] }); }
25
25
  }
26
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: ApiManagerModule, decorators: [{
26
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApiManagerModule, decorators: [{
27
27
  type: NgModule,
28
28
  args: [{
29
29
  providers: [
@@ -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: "17.3.1", 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: "17.3.1", ngImport: i0, type: ApiFactoryService }); }
128
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", 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: "17.3.3", ngImport: i0, type: ApiFactoryService }); }
130
130
  }
131
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: ApiFactoryService, decorators: [{
131
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", 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: "17.3.1", ngImport: i0, type: ApiManagerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
159
- /** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.1", ngImport: i0, type: ApiManagerModule }); }
160
- /** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: ApiManagerModule, providers: [
158
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApiManagerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
159
+ /** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.3", ngImport: i0, type: ApiManagerModule }); }
160
+ /** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApiManagerModule, providers: [
161
161
  ApiFactoryService
162
162
  ] }); }
163
163
  }
164
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: ApiManagerModule, decorators: [{
164
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApiManagerModule, decorators: [{
165
165
  type: NgModule,
166
166
  args: [{
167
167
  providers: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o3r/apis-manager",
3
- "version": "10.3.0-prerelease.4",
3
+ "version": "10.3.0-prerelease.41",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -11,11 +11,11 @@
11
11
  "otter-module"
12
12
  ],
13
13
  "peerDependencies": {
14
- "@ama-sdk/core": "^10.3.0-prerelease.4",
14
+ "@ama-sdk/core": "^10.3.0-prerelease.41",
15
15
  "@angular-devkit/schematics": "~17.3.0",
16
16
  "@angular/common": "~17.3.0",
17
17
  "@angular/core": "~17.3.0",
18
- "@o3r/schematics": "^10.3.0-prerelease.4",
18
+ "@o3r/schematics": "^10.3.0-prerelease.41",
19
19
  "@schematics/angular": "~17.3.0",
20
20
  "rxjs": "^7.8.1",
21
21
  "typescript": "~5.4.2"