@takaro/auth 0.3.2 → 0.4.0
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oryAxiosClient.d.ts","sourceRoot":"","sources":["../../src/lib/oryAxiosClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"oryAxiosClient.d.ts","sourceRoot":"","sources":["../../src/lib/oryAxiosClient.ts"],"names":[],"mappings":"AAGA,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,iCAiChD"}
|
|
@@ -1,45 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { addCounterToAxios, errors, logger } from '@takaro/util';
|
|
3
|
-
const log = logger('ory:http');
|
|
1
|
+
import { addCounterToAxios, errors, logger, createAxios } from '@takaro/util';
|
|
4
2
|
export function createAxiosClient(baseURL) {
|
|
5
|
-
const
|
|
3
|
+
const log = logger('ory:http');
|
|
4
|
+
const client = createAxios({
|
|
6
5
|
baseURL,
|
|
7
6
|
headers: {
|
|
8
7
|
'Content-Type': 'application/json',
|
|
9
8
|
'User-Agent': 'Takaro-Agent',
|
|
10
9
|
},
|
|
10
|
+
}, {
|
|
11
|
+
logger: log,
|
|
11
12
|
});
|
|
12
13
|
addCounterToAxios(client, {
|
|
13
14
|
name: 'ory_api_requests_total',
|
|
14
15
|
help: 'Total number of requests to the Ory API',
|
|
15
16
|
});
|
|
16
|
-
client.interceptors.request.use((request) => {
|
|
17
|
-
log.silly(`➡️ ${request.method?.toUpperCase()} ${request.url}`, {
|
|
18
|
-
method: request.method,
|
|
19
|
-
url: request.url,
|
|
20
|
-
});
|
|
21
|
-
return request;
|
|
22
|
-
});
|
|
23
17
|
client.interceptors.response.use((response) => {
|
|
24
|
-
log.silly(`⬅️ ${response.request.method?.toUpperCase()} ${response.request.path} ${response.status} ${response.statusText}`, {
|
|
25
|
-
status: response.status,
|
|
26
|
-
method: response.request.method,
|
|
27
|
-
url: response.request.url,
|
|
28
|
-
});
|
|
29
18
|
return response;
|
|
30
19
|
}, (error) => {
|
|
31
|
-
let details = {};
|
|
32
|
-
if (error.response?.data) {
|
|
33
|
-
const data = error.response.data;
|
|
34
|
-
details = JSON.stringify(data.error_description);
|
|
35
|
-
}
|
|
36
|
-
log.error(`☠️ Request errored: [${error.response?.status}] ${details}`, {
|
|
37
|
-
status: error.response?.status,
|
|
38
|
-
statusText: error.response?.statusText,
|
|
39
|
-
method: error.config?.method,
|
|
40
|
-
url: error.config?.url,
|
|
41
|
-
response: error.response?.data,
|
|
42
|
-
});
|
|
43
20
|
if (error.response?.status === 409) {
|
|
44
21
|
return Promise.reject(new errors.ConflictError('User with this identifier already exists'));
|
|
45
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oryAxiosClient.js","sourceRoot":"","sources":["../../src/lib/oryAxiosClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"oryAxiosClient.js","sourceRoot":"","sources":["../../src/lib/oryAxiosClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE9E,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IAC/B,MAAM,MAAM,GAAG,WAAW,CACxB;QACE,OAAO;QACP,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,YAAY,EAAE,cAAc;SAC7B;KACF,EACD;QACE,MAAM,EAAE,GAAG;KACZ,CACF,CAAC;IAEF,iBAAiB,CAAC,MAAM,EAAE;QACxB,IAAI,EAAE,wBAAwB;QAC9B,IAAI,EAAE,yCAAyC;KAChD,CAAC,CAAC;IAEH,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAC9B,CAAC,QAAQ,EAAE,EAAE;QACX,OAAO,QAAQ,CAAC;IAClB,CAAC,EACD,CAAC,KAAiB,EAAE,EAAE;QACpB,IAAI,KAAK,CAAC,QAAQ,EAAE,MAAM,KAAK,GAAG,EAAE,CAAC;YACnC,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,aAAa,CAAC,0CAA0C,CAAC,CAAC,CAAC;QAC9F,CAAC;QACD,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC,CACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,65 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { addCounterToAxios, errors, logger } from '@takaro/util';
|
|
3
|
-
|
|
4
|
-
const log = logger('ory:http');
|
|
1
|
+
import { AxiosError } from 'axios';
|
|
2
|
+
import { addCounterToAxios, errors, logger, createAxios } from '@takaro/util';
|
|
5
3
|
|
|
6
4
|
export function createAxiosClient(baseURL: string) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
const log = logger('ory:http');
|
|
6
|
+
const client = createAxios(
|
|
7
|
+
{
|
|
8
|
+
baseURL,
|
|
9
|
+
headers: {
|
|
10
|
+
'Content-Type': 'application/json',
|
|
11
|
+
'User-Agent': 'Takaro-Agent',
|
|
12
|
+
},
|
|
12
13
|
},
|
|
13
|
-
|
|
14
|
+
{
|
|
15
|
+
logger: log,
|
|
16
|
+
},
|
|
17
|
+
);
|
|
14
18
|
|
|
15
19
|
addCounterToAxios(client, {
|
|
16
20
|
name: 'ory_api_requests_total',
|
|
17
21
|
help: 'Total number of requests to the Ory API',
|
|
18
22
|
});
|
|
19
23
|
|
|
20
|
-
client.interceptors.request.use((request) => {
|
|
21
|
-
log.silly(`➡️ ${request.method?.toUpperCase()} ${request.url}`, {
|
|
22
|
-
method: request.method,
|
|
23
|
-
url: request.url,
|
|
24
|
-
});
|
|
25
|
-
return request;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
24
|
client.interceptors.response.use(
|
|
29
25
|
(response) => {
|
|
30
|
-
log.silly(
|
|
31
|
-
`⬅️ ${response.request.method?.toUpperCase()} ${response.request.path} ${response.status} ${
|
|
32
|
-
response.statusText
|
|
33
|
-
}`,
|
|
34
|
-
{
|
|
35
|
-
status: response.status,
|
|
36
|
-
method: response.request.method,
|
|
37
|
-
url: response.request.url,
|
|
38
|
-
},
|
|
39
|
-
);
|
|
40
|
-
|
|
41
26
|
return response;
|
|
42
27
|
},
|
|
43
28
|
(error: AxiosError) => {
|
|
44
|
-
let details = {};
|
|
45
|
-
|
|
46
|
-
if (error.response?.data) {
|
|
47
|
-
const data = error.response.data as Record<string, unknown>;
|
|
48
|
-
details = JSON.stringify(data.error_description);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
log.error(`☠️ Request errored: [${error.response?.status}] ${details}`, {
|
|
52
|
-
status: error.response?.status,
|
|
53
|
-
statusText: error.response?.statusText,
|
|
54
|
-
method: error.config?.method,
|
|
55
|
-
url: error.config?.url,
|
|
56
|
-
response: error.response?.data,
|
|
57
|
-
});
|
|
58
|
-
|
|
59
29
|
if (error.response?.status === 409) {
|
|
60
30
|
return Promise.reject(new errors.ConflictError('User with this identifier already exists'));
|
|
61
31
|
}
|
|
62
|
-
|
|
63
32
|
return Promise.reject(error);
|
|
64
33
|
},
|
|
65
34
|
);
|