@metarisc/metarisc-js 0.0.1-alpha.25 → 0.0.1-alpha.26

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 CHANGED
@@ -1,5 +1,6 @@
1
1
  import { AxiosResponse } from "axios";
2
2
  import { MetariscConfig, OAuth2Options } from "./core";
3
+ import { GrantResponse } from "./auth/oauth2";
3
4
  interface RequestConfig {
4
5
  body?: any;
5
6
  headers?: {
@@ -21,7 +22,7 @@ export declare class Client {
21
22
  private access_token?;
22
23
  private refresh_token?;
23
24
  constructor(config: MetariscConfig);
24
- authenticate(auth_method: AuthMethod, options: OAuth2Options): Promise<void>;
25
+ authenticate(auth_method: AuthMethod, options: OAuth2Options): Promise<GrantResponse>;
25
26
  /**
26
27
  * Lance une requête (authentifiée si possible) sur l'API Metarisc.
27
28
  */
package/lib/client.js CHANGED
@@ -68,10 +68,12 @@ class Client {
68
68
  const response = await this.oauth2.getAuthorizationCode(options);
69
69
  this.setAccessToken(response.token_type + " " + response.access_token);
70
70
  this.setRefreshToken(response.refresh_token);
71
+ return response;
71
72
  }
72
73
  else if (auth_method === AuthMethod.CLIENT_CREDENTIALS) {
73
74
  const response = await this.oauth2.getClientCredentials(options);
74
75
  this.setAccessToken(response.token_type + " " + response.access_token);
76
+ return response;
75
77
  }
76
78
  else {
77
79
  throw new Error("auth_method inconnue");
package/lib/core.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { AxiosResponse } from "axios";
2
2
  import { AuthMethod, Client } from "./client";
3
3
  import { Collection } from "./collection";
4
+ import { GrantResponse } from "./auth/oauth2";
4
5
  interface RequestConfig {
5
6
  body?: any;
6
7
  headers?: {
@@ -31,7 +32,7 @@ export declare class Core {
31
32
  constructor(config: MetariscConfig, client?: Client);
32
33
  request<T>(config: RequestConfig): Promise<AxiosResponse<T>>;
33
34
  collect<T>(config: RequestConfig): Collection<T>;
34
- authenticate(auth_method: AuthMethod, options: OAuth2Options): Promise<void>;
35
+ authenticate(auth_method: AuthMethod, options: OAuth2Options): Promise<GrantResponse>;
35
36
  setAccessToken(access_token: string): void;
36
37
  setRefreshToken(refresh_token: string): void;
37
38
  }
package/lib/core.js CHANGED
@@ -19,7 +19,7 @@ class Core {
19
19
  });
20
20
  }
21
21
  async authenticate(auth_method, options) {
22
- await this.client.authenticate(auth_method, options);
22
+ return await this.client.authenticate(auth_method, options);
23
23
  }
24
24
  setAccessToken(access_token) {
25
25
  this.client.setAccessToken(access_token);
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.25",
5
+ "version": "0.0.1-alpha.26",
6
6
  "scripts": {
7
7
  "lint": "eslint . --ext .ts --fix",
8
8
  "compile": "tsc",
package/src/client.ts CHANGED
@@ -5,7 +5,7 @@ import axios, {
5
5
  } from "axios";
6
6
  import axiosRetry from "axios-retry";
7
7
  import { MetariscConfig, OAuth2Options } from "./core";
8
- import { OAuth2 } from "./auth/oauth2";
8
+ import { GrantResponse, OAuth2 } from "./auth/oauth2";
9
9
  import { setupCache } from "axios-cache-interceptor";
10
10
  import Utils from "./utils";
11
11
 
@@ -87,15 +87,17 @@ export class Client {
87
87
  async authenticate(
88
88
  auth_method: AuthMethod,
89
89
  options: OAuth2Options
90
- ): Promise<void> {
90
+ ): Promise<GrantResponse> {
91
91
  if(auth_method === AuthMethod.AUTHORIZATION_CODE) {
92
92
  const response = await this.oauth2.getAuthorizationCode(options);
93
93
  this.setAccessToken(response.token_type + " " + response.access_token);
94
94
  this.setRefreshToken(response.refresh_token);
95
+ return response;
95
96
  }
96
97
  else if(auth_method === AuthMethod.CLIENT_CREDENTIALS) {
97
98
  const response = await this.oauth2.getClientCredentials(options);
98
99
  this.setAccessToken(response.token_type + " " + response.access_token);
100
+ return response;
99
101
  }
100
102
  else {
101
103
  throw new Error("auth_method inconnue");
package/src/core.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { AxiosResponse } from "axios";
2
2
  import { AuthMethod, Client } from "./client";
3
3
  import { Collection } from "./collection";
4
+ import { GrantResponse } from "./auth/oauth2";
4
5
 
5
6
  interface RequestConfig {
6
7
  body?: any;
@@ -49,8 +50,8 @@ export class Core {
49
50
  async authenticate(
50
51
  auth_method: AuthMethod,
51
52
  options: OAuth2Options
52
- ): Promise<void> {
53
- await this.client.authenticate(auth_method, options);
53
+ ): Promise<GrantResponse> {
54
+ return await this.client.authenticate(auth_method, options);
54
55
  }
55
56
 
56
57
  setAccessToken(access_token: string): void {