@metarisc/metarisc-js 0.0.1-alpha.19 → 0.0.1-alpha.20
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/lib/client.d.ts +4 -0
- package/lib/client.js +23 -0
- package/package.json +3 -2
- package/src/client.ts +30 -1
package/lib/client.d.ts
CHANGED
|
@@ -25,5 +25,9 @@ export declare class Client {
|
|
|
25
25
|
getClientCredentials(options: OAuth2Options): Promise<GrantResponse>;
|
|
26
26
|
setAccessToken(access_token: string): void;
|
|
27
27
|
getAccessToken(): string;
|
|
28
|
+
/**
|
|
29
|
+
* Retourne les headers HTTP par défauts devant être présents dans toutes les requêtes Metarisc.
|
|
30
|
+
*/
|
|
31
|
+
private getDefaultHeaders;
|
|
28
32
|
}
|
|
29
33
|
export {};
|
package/lib/client.js
CHANGED
|
@@ -8,6 +8,7 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
8
8
|
const axios_retry_1 = __importDefault(require("axios-retry"));
|
|
9
9
|
const axios_oauth_client_1 = __importDefault(require("axios-oauth-client"));
|
|
10
10
|
const oauth2_1 = require("./auth/oauth2");
|
|
11
|
+
const axios_cache_interceptor_1 = require("axios-cache-interceptor");
|
|
11
12
|
var AuthMethod;
|
|
12
13
|
(function (AuthMethod) {
|
|
13
14
|
AuthMethod[AuthMethod["CLIENT_CREDENTIALS"] = 0] = "CLIENT_CREDENTIALS";
|
|
@@ -17,7 +18,17 @@ class Client {
|
|
|
17
18
|
constructor(config) {
|
|
18
19
|
this.axios = axios_1.default.create({
|
|
19
20
|
baseURL: config.metarisc_url ?? 'https://api.metarisc.fr/',
|
|
21
|
+
'headers': {
|
|
22
|
+
'common': this.getDefaultHeaders()
|
|
23
|
+
}
|
|
20
24
|
});
|
|
25
|
+
// Axios Interceptors
|
|
26
|
+
// Request interceptors are FILO (First In Last Out)
|
|
27
|
+
// Response interceptors are FIFO (First In First Out)
|
|
28
|
+
// Axios interceptor : Enable HTTP Caching
|
|
29
|
+
// When combining axios-cache-interceptors with other interceptors, you may encounter some inconsistences.
|
|
30
|
+
// See : https://github.com/arthurfiorette/axios-cache-interceptor/issues/449#issuecomment-1370327566
|
|
31
|
+
this.axios = (0, axios_cache_interceptor_1.setupCache)(this.axios);
|
|
21
32
|
// Axios interceptor : Retry strategy
|
|
22
33
|
(0, axios_retry_1.default)(this.axios, {
|
|
23
34
|
retries: 3,
|
|
@@ -70,5 +81,17 @@ class Client {
|
|
|
70
81
|
getAccessToken() {
|
|
71
82
|
return this.access_token;
|
|
72
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Retourne les headers HTTP par défauts devant être présents dans toutes les requêtes Metarisc.
|
|
86
|
+
*/
|
|
87
|
+
getDefaultHeaders() {
|
|
88
|
+
const headers = {};
|
|
89
|
+
// UA Headers
|
|
90
|
+
headers['User-Agent'] = 'MetariscJs/dev'; // Format User-Agent (https://www.rfc-editor.org/rfc/rfc9110#name-user-agent)
|
|
91
|
+
headers['Metarisc-User-Agent'] = JSON.stringify({
|
|
92
|
+
'lang': 'js'
|
|
93
|
+
});
|
|
94
|
+
return headers;
|
|
95
|
+
}
|
|
73
96
|
}
|
|
74
97
|
exports.Client = Client;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@metarisc/metarisc-js",
|
|
3
3
|
"main": "lib/index.js",
|
|
4
4
|
"types": "lib/index.d.ts",
|
|
5
|
-
"version": "0.0.1-alpha.
|
|
5
|
+
"version": "0.0.1-alpha.20",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"lint": "eslint . --ext .ts --fix",
|
|
8
8
|
"compile": "tsc",
|
|
@@ -19,8 +19,9 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"axios": "^1.4.0",
|
|
22
|
-
"axios-
|
|
22
|
+
"axios-cache-interceptor": "^1.3.2",
|
|
23
23
|
"axios-oauth-client": "^2.0.4",
|
|
24
|
+
"axios-retry": "^3.5.0",
|
|
24
25
|
"tus-js-client": "^3.1.1"
|
|
25
26
|
}
|
|
26
27
|
}
|
package/src/client.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import axios, { AxiosInstance, AxiosResponse } from "axios";
|
|
1
|
+
import axios, { AxiosInstance, AxiosResponse, RawAxiosRequestHeaders } from "axios";
|
|
2
2
|
import axiosRetry from "axios-retry";
|
|
3
3
|
import oauth from "axios-oauth-client";
|
|
4
4
|
import { GrantResponse, MetariscConfig, OAuth2Options } from './core';
|
|
5
5
|
import { OAuth2 } from "./auth/oauth2";
|
|
6
|
+
import { setupCache } from 'axios-cache-interceptor';
|
|
6
7
|
|
|
7
8
|
interface RequestConfig {
|
|
8
9
|
body?: any;
|
|
@@ -26,8 +27,20 @@ export class Client {
|
|
|
26
27
|
constructor(config : MetariscConfig) {
|
|
27
28
|
this.axios = axios.create({
|
|
28
29
|
baseURL: config.metarisc_url ?? 'https://api.metarisc.fr/',
|
|
30
|
+
'headers': {
|
|
31
|
+
'common': this.getDefaultHeaders()
|
|
32
|
+
}
|
|
29
33
|
});
|
|
30
34
|
|
|
35
|
+
// Axios Interceptors
|
|
36
|
+
// Request interceptors are FILO (First In Last Out)
|
|
37
|
+
// Response interceptors are FIFO (First In First Out)
|
|
38
|
+
|
|
39
|
+
// Axios interceptor : Enable HTTP Caching
|
|
40
|
+
// When combining axios-cache-interceptors with other interceptors, you may encounter some inconsistences.
|
|
41
|
+
// See : https://github.com/arthurfiorette/axios-cache-interceptor/issues/449#issuecomment-1370327566
|
|
42
|
+
this.axios = setupCache(this.axios);
|
|
43
|
+
|
|
31
44
|
// Axios interceptor : Retry strategy
|
|
32
45
|
axiosRetry(this.axios, {
|
|
33
46
|
retries: 3,
|
|
@@ -101,4 +114,20 @@ export class Client {
|
|
|
101
114
|
getAccessToken(): string {
|
|
102
115
|
return this.access_token;
|
|
103
116
|
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Retourne les headers HTTP par défauts devant être présents dans toutes les requêtes Metarisc.
|
|
120
|
+
*/
|
|
121
|
+
private getDefaultHeaders() : RawAxiosRequestHeaders
|
|
122
|
+
{
|
|
123
|
+
const headers : RawAxiosRequestHeaders = {};
|
|
124
|
+
|
|
125
|
+
// UA Headers
|
|
126
|
+
headers['User-Agent'] = 'MetariscJs/dev'; // Format User-Agent (https://www.rfc-editor.org/rfc/rfc9110#name-user-agent)
|
|
127
|
+
headers['Metarisc-User-Agent'] = JSON.stringify({
|
|
128
|
+
'lang': 'js'
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
return headers;
|
|
132
|
+
}
|
|
104
133
|
}
|