rystem.repository.client 0.2.3 → 0.2.5

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
@@ -51,12 +51,12 @@ RepositoryServices
51
51
  .addRepository<IperUser, string>(x => {
52
52
  x.name = "test";
53
53
  x.path = "SuperUser";
54
- x.addHeadersEnricher((...args) => {
54
+ x.addHeadersEnricher(async (...args) => {
55
55
  return {
56
56
  "Authorization-UI": "Bearer dsjadjalsdjalsdjalsda"
57
57
  }
58
58
  });
59
- x.addHeadersEnricher((endpoint: RepositoryEndpoint, uri: string, method: string, headers: HeadersInit, body: any) => {
59
+ x.addHeadersEnricher(async (endpoint: RepositoryEndpoint, uri: string, method: string, headers: HeadersInit, body: any) => {
60
60
  return {
61
61
  "Authorization-UI2": "Bearer dsjadjalsdjalsdjalsda"
62
62
  }
@@ -139,7 +139,7 @@ class Repository {
139
139
  while (retry) {
140
140
  response = await fetch(uri, {
141
141
  method: method,
142
- headers: this.settings.enrichHeaders(endpoint, uri, method, headers, body),
142
+ headers: await this.settings.enrichHeaders(endpoint, uri, method, headers, body),
143
143
  body: body == null ? null : JSON.stringify(skipSerialization ? body : this.serializeRequestBody(body, bodyIsKey))
144
144
  })
145
145
  .then(async (res) => {
@@ -148,8 +148,8 @@ class Repository {
148
148
  throw json;
149
149
  return json;
150
150
  })
151
- .catch((err) => {
152
- retry = this.settings.manageError(endpoint, uri, method, headers, body, err);
151
+ .catch(async (err) => {
152
+ retry = await this.settings.manageError(endpoint, uri, method, headers, body, err);
153
153
  return null;
154
154
  })
155
155
  .then(res => {
@@ -166,7 +166,7 @@ class Repository {
166
166
  let response = [];
167
167
  await fetch(uri, {
168
168
  method: method,
169
- headers: this.settings.enrichHeaders(endpoint, uri, method, headers, body),
169
+ headers: await this.settings.enrichHeaders(endpoint, uri, method, headers, body),
170
170
  body: body == null ? null : JSON.stringify(skipSerialization ? body : this.serializeRequestBody(body, bodyIsKey))
171
171
  })
172
172
  .then(async (res) => {
@@ -14,8 +14,8 @@ export declare class RepositorySettings {
14
14
  private headersEnrichers;
15
15
  private errorsHandlers;
16
16
  constructor();
17
- addHeadersEnricher(enricher: (endpoint: RepositoryEndpoint, uri: string, method: string, headers: HeadersInit, body: any) => HeadersInit): this;
18
- addErrorHandler(handler: (endpoint: RepositoryEndpoint, uri: string, method: string, headers: HeadersInit, body: any, err: any) => boolean): this;
19
- enrichHeaders(endpoint: RepositoryEndpoint, uri: string, method: string, headers: HeadersInit | undefined, body: any): HeadersInit;
20
- manageError(endpoint: RepositoryEndpoint, uri: string, method: string, headers: HeadersInit, body: any, err: any): boolean;
17
+ addHeadersEnricher(enricher: (endpoint: RepositoryEndpoint, uri: string, method: string, headers: HeadersInit, body: any) => Promise<HeadersInit>): this;
18
+ addErrorHandler(handler: (endpoint: RepositoryEndpoint, uri: string, method: string, headers: HeadersInit, body: any, err: any) => Promise<boolean>): this;
19
+ enrichHeaders(endpoint: RepositoryEndpoint, uri: string, method: string, headers: HeadersInit | undefined, body: any): Promise<HeadersInit>;
20
+ manageError(endpoint: RepositoryEndpoint, uri: string, method: string, headers: HeadersInit, body: any, err: any): Promise<boolean>;
21
21
  }
@@ -28,7 +28,7 @@ class RepositorySettings {
28
28
  this.errorsHandlers.push(handler);
29
29
  return this;
30
30
  }
31
- enrichHeaders(endpoint, uri, method, headers, body) {
31
+ async enrichHeaders(endpoint, uri, method, headers, body) {
32
32
  const requestHeaders = new Headers();
33
33
  const setHeaders = (currentHeaders) => {
34
34
  let forcedHeaders = currentHeaders;
@@ -42,14 +42,14 @@ class RepositorySettings {
42
42
  setHeaders(headers);
43
43
  }
44
44
  for (let enricher of this.headersEnrichers) {
45
- setHeaders(enricher(endpoint, uri, method, requestHeaders, body));
45
+ setHeaders(await enricher(endpoint, uri, method, requestHeaders, body));
46
46
  }
47
47
  return requestHeaders;
48
48
  }
49
- manageError(endpoint, uri, method, headers, body, err) {
49
+ async manageError(endpoint, uri, method, headers, body, err) {
50
50
  let retry = this.errorsHandlers.length > 0;
51
51
  for (let handler of this.errorsHandlers)
52
- retry &&= handler(endpoint, uri, method, headers, body, err);
52
+ retry &&= await handler(endpoint, uri, method, headers, body, err);
53
53
  return retry;
54
54
  }
55
55
  }
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "rystem.repository.client",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "author": "Alessandro Rapiti <alessandro.rapiti44@gmail.com>",
5
5
  "license": "MIT",
6
6
  "description": "It can simplify the integration with rystem repository server.",
7
7
  "main": "./lib/index.js",
8
8
  "types": "./lib/index.d.ts",
9
9
  "devDependencies": {
10
+ "@types/node": "^22.15.16",
10
11
  "@types/react": "19.0.10",
11
12
  "@types/react-dom": "19.0.4",
12
13
  "@typescript-eslint/parser": "8.24.1",