@takaro/auth 0.3.3 → 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":"AAKA,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,iCA8DhD"}
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 axios from 'axios';
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 client = axios.create({
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":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEjE,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAE/B,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC1B,OAAO;QACP,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,YAAY,EAAE,cAAc;SAC7B;KACF,CAAC,CAAC;IAEH,iBAAiB,CAAC,MAAM,EAAE;QACxB,IAAI,EAAE,wBAAwB;QAC9B,IAAI,EAAE,yCAAyC;KAChD,CAAC,CAAC;IAEH,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QAC1C,GAAG,CAAC,KAAK,CAAC,MAAM,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE;YAC9D,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,GAAG,EAAE,OAAO,CAAC,GAAG;SACjB,CAAC,CAAC;QACH,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAC9B,CAAC,QAAQ,EAAE,EAAE;QACX,GAAG,CAAC,KAAK,CACP,MAAM,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,QAAQ,CAAC,OAAO,CAAC,IAA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AxiosClient.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@takaro/auth",
3
- "version": "0.3.3",
3
+ "version": "0.4.0",
4
4
  "description": "An opinionated auth handler",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
@@ -21,7 +21,7 @@ describe('Ory', () => {
21
21
 
22
22
  // Make sure they're gone
23
23
  await expect(ory.getIdentity(identities[0].id)).to.eventually.be.rejectedWith(
24
- 'Request failed with status code 404',
24
+ 'Request failed with status 404 Not Found',
25
25
  );
26
26
  });
27
27
  });
@@ -1,65 +1,34 @@
1
- import axios, { AxiosError } from 'axios';
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 client = axios.create({
8
- baseURL,
9
- headers: {
10
- 'Content-Type': 'application/json',
11
- 'User-Agent': 'Takaro-Agent',
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
  );