attlaz-client 1.17.0 → 1.17.1

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,9 +1,10 @@
1
1
  import { CursorPagination } from '../../Model/Pagination/CursorPagination.js';
2
2
  import { State } from '../../Model/State.js';
3
3
  export declare class QueryString {
4
- private readonly command;
4
+ private command;
5
5
  private parameters;
6
- constructor(command: string);
6
+ constructor(command?: string);
7
+ setCommand(command: string): void;
7
8
  set(parameter: string, value: string | number | boolean | string[]): void;
8
9
  addPagination(pagination: CursorPagination | null): void;
9
10
  addStateFilter(states: State[] | null): void;
@@ -1,7 +1,10 @@
1
1
  export class QueryString {
2
2
  command;
3
3
  parameters = [];
4
- constructor(command) {
4
+ constructor(command = '') {
5
+ this.command = command;
6
+ }
7
+ setCommand(command) {
5
8
  this.command = command;
6
9
  }
7
10
  set(parameter, value) {
@@ -2,6 +2,7 @@ import { OAuthClientOptions } from './OAuthClientOptions.js';
2
2
  import { OAuthClientToken } from './OAuthClientToken.js';
3
3
  import { Parameters } from './Data/Parameters.js';
4
4
  import { Headers } from './Data/Headers.js';
5
+ import { QueryString } from './Data/QueryString.js';
5
6
  export declare class OAuthClient {
6
7
  private readonly options;
7
8
  private debug;
@@ -22,10 +23,11 @@ export declare class OAuthClient {
22
23
  enableDebug(): void;
23
24
  disableDebug(): void;
24
25
  isDebugEnabled(): boolean;
26
+ getTokenFlowUrl(options?: QueryString | null): string;
25
27
  getDefaultHeaders(): Headers;
26
28
  private isNodeEnvironment;
27
29
  private tokenToOauthClientToken;
28
- private getUri;
30
+ private getApiEndpointUrl;
29
31
  private createRequestData;
30
32
  private signRequest;
31
33
  }
@@ -7,6 +7,7 @@ import { HttpClientRequest } from './HttpClientRequest.js';
7
7
  import { OAuthClientToken } from './OAuthClientToken.js';
8
8
  import { JsonSerializable } from '../Model/JsonSerializable.js';
9
9
  import { VERSION } from '../version.js';
10
+ import { QueryString } from './Data/QueryString.js';
10
11
  export class OAuthClient {
11
12
  options;
12
13
  debug = false;
@@ -33,14 +34,14 @@ export class OAuthClient {
33
34
  try {
34
35
  if (username !== null && username !== undefined && password !== null && password !== undefined) {
35
36
  // Password flow / Owner Credentials grant
36
- const getOwnerCredentials = ownerCredentials(this.getAxiosInstance(), this.getUri(this.options.accessTokenUri), this.options.clientId === null ? undefined : this.options.clientId, this.options.clientSecret === null ? undefined : this.options.clientSecret);
37
+ const getOwnerCredentials = ownerCredentials(this.getAxiosInstance(), this.getApiEndpointUrl(this.options.accessTokenUri), this.options.clientId === null ? undefined : this.options.clientId, this.options.clientSecret === null ? undefined : this.options.clientSecret);
37
38
  const rawAuthToken = await getOwnerCredentials(username, password, 'OPTIONAL_SCOPES');
38
39
  this.oathClientToken = this.tokenToOauthClientToken(rawAuthToken);
39
40
  // accessToken = await this.oauthClient.owner.getToken(username, password);
40
41
  return true;
41
42
  }
42
43
  // Client credentials flow
43
- const getClientCredentials = clientCredentials(this.getAxiosInstance(), this.getUri(this.options.accessTokenUri), this.options.clientId === null ? undefined : this.options.clientId, this.options.clientSecret === null ? undefined : this.options.clientSecret);
44
+ const getClientCredentials = clientCredentials(this.getAxiosInstance(), this.getApiEndpointUrl(this.options.accessTokenUri), this.options.clientId === null ? undefined : this.options.clientId, this.options.clientSecret === null ? undefined : this.options.clientSecret);
44
45
  const rawAuthToken = await getClientCredentials('OPTIONAL_SCOPES');
45
46
  this.oathClientToken = this.tokenToOauthClientToken(rawAuthToken);
46
47
  // accessToken = await this.oauthClient.credentials.getToken();
@@ -67,7 +68,7 @@ export class OAuthClient {
67
68
  throw new Error('unable to refresh token, refresh token not set');
68
69
  }
69
70
  try {
70
- const getRefreshToken = refreshToken(this.getAxiosInstance(), this.getUri(this.options.accessTokenUri), this.options.clientId === null ? undefined : this.options.clientId, this.options.clientSecret === null ? undefined : this.options.clientSecret);
71
+ const getRefreshToken = refreshToken(this.getAxiosInstance(), this.getApiEndpointUrl(this.options.accessTokenUri), this.options.clientId === null ? undefined : this.options.clientId, this.options.clientSecret === null ? undefined : this.options.clientSecret);
71
72
  const auth = await getRefreshToken(this.oathClientToken.refresh_token, 'OPTIONAL_SCOPES');
72
73
  // this.oauthToken = await this.oauthToken.refresh();
73
74
  this.oathClientToken = this.tokenToOauthClientToken(auth);
@@ -170,9 +171,13 @@ export class OAuthClient {
170
171
  isDebugEnabled() {
171
172
  return this.debug;
172
173
  }
173
- // public getTokenFlowUrl(options: { query?: { [key: string]: string | string[] } } | null = null): string {
174
- // return this.oauthClient.token.getUri(options === null ? undefined : options);
175
- // }
174
+ getTokenFlowUrl(options = null) {
175
+ if (options === null) {
176
+ options = new QueryString();
177
+ }
178
+ options.setCommand(this.getApiEndpointUrl(this.options.accessTokenUri));
179
+ return options.build();
180
+ }
176
181
  getDefaultHeaders() {
177
182
  const userAgentInfo = {
178
183
  version: VERSION,
@@ -204,14 +209,14 @@ export class OAuthClient {
204
209
  token.expires = t;
205
210
  return token;
206
211
  }
207
- getUri(uri) {
212
+ getApiEndpointUrl(uri) {
208
213
  if (uri.indexOf('http://') === 0 || uri.indexOf('https://') === 0) {
209
214
  return uri;
210
215
  }
211
216
  return this.options.apiEndpoint.replace(/\/+$/, '') + '/' + uri.replace(/^\/+/g, '');
212
217
  }
213
218
  createRequestData(action, parameters = null, method = 'GET', signWithOauthToken = true) {
214
- const url = this.getUri(action);
219
+ const url = this.getApiEndpointUrl(action);
215
220
  let requestData = new HttpClientRequest(url, method);
216
221
  requestData.headers = this.getDefaultHeaders();
217
222
  if ((method === 'POST' || method === 'DELETE' || method === 'PUT') && parameters !== null && parameters !== undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attlaz-client",
3
- "version": "1.17.0",
3
+ "version": "1.17.1",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",