attlaz-client 1.13.49 → 1.13.51

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.
@@ -2,6 +2,7 @@ export declare class ClientError implements Error {
2
2
  code: number | null;
3
3
  name: string;
4
4
  message: string;
5
+ stack: string | undefined;
5
6
  constructor(name: string, code?: number | null);
6
7
  static fromError(error: Error | any): ClientError;
7
8
  static byStatus(statusCode: number, statusText: string): ClientError | null;
@@ -4,7 +4,7 @@ export class ClientError {
4
4
  name;
5
5
  message;
6
6
  // description: string | null;
7
- // stack: string;
7
+ stack = undefined;
8
8
  // body: string | null = null;
9
9
  constructor(name, code = null) {
10
10
  this.name = name;
@@ -49,7 +49,8 @@ export class ClientError {
49
49
  }
50
50
  }
51
51
  clientError.name = error.name;
52
- // clientError.stack = error.stack;
52
+ // TODO: only in debug mode
53
+ clientError.stack = error.stack;
53
54
  return clientError;
54
55
  }
55
56
  static byStatus(statusCode, statusText) {
@@ -31,9 +31,7 @@ export class HttpClient {
31
31
  jsonData = JSON.parse(rawData);
32
32
  }
33
33
  catch (e) {
34
- console.error('Unable to parse response data to JSON', {
35
- statusText: httpResponse.statusText, error: e,
36
- });
34
+ console.error('Unable to parse response data to JSON', { statusText: httpResponse.statusText, error: e });
37
35
  }
38
36
  }
39
37
  httpResponse.body = jsonData;
@@ -55,17 +55,15 @@ export class OAuthClient {
55
55
  if (this.oauthToken === null) {
56
56
  throw new Error('unable to refresh token, auth token not set');
57
57
  }
58
- if (this.oauthToken.refreshToken !== undefined && this.oauthToken.refreshToken !== null && this.oauthToken.refreshToken !== '') {
59
- try {
60
- this.oauthToken = await this.oauthToken.refresh();
61
- this.oathClientToken = this.tokenToOauthClientToken(this.oauthToken);
62
- }
63
- catch (e) {
64
- throw ClientError.fromError(e);
65
- }
58
+ if (this.oauthToken.refreshToken === undefined || this.oauthToken.refreshToken === null || this.oauthToken.refreshToken === '') {
59
+ throw new Error('unable to refresh token, refresh token not set');
66
60
  }
67
- else {
68
- await this.authenticate();
61
+ try {
62
+ this.oauthToken = await this.oauthToken.refresh();
63
+ this.oathClientToken = this.tokenToOauthClientToken(this.oauthToken);
64
+ }
65
+ catch (e) {
66
+ throw ClientError.fromError(e);
69
67
  }
70
68
  }
71
69
  isTokenExpires() {
@@ -9,5 +9,7 @@ export declare class Adapter {
9
9
  categoryIds: string[];
10
10
  docs: string;
11
11
  website: string;
12
- static parse(rawAdapter: any): Adapter;
12
+ static parse(rawAdapter: {
13
+ [k: string]: any;
14
+ }): Adapter;
13
15
  }
@@ -5,6 +5,5 @@ export declare class AdapterConnection {
5
5
  name: string;
6
6
  projectId: string;
7
7
  status: string;
8
- constructor();
9
8
  static parse(rawAdapterConnection: any): AdapterConnection;
10
9
  }
@@ -5,8 +5,6 @@ export class AdapterConnection {
5
5
  name;
6
6
  projectId;
7
7
  status;
8
- constructor() {
9
- }
10
8
  static parse(rawAdapterConnection) {
11
9
  const adapterConnection = new AdapterConnection();
12
10
  adapterConnection.id = rawAdapterConnection.id;
@@ -10,5 +10,7 @@ export declare class Config {
10
10
  inheritable: boolean;
11
11
  sensitive: boolean;
12
12
  state: State;
13
- static parse(rawConfig: any): Config;
13
+ static parse(rawConfig: {
14
+ [k: string]: any;
15
+ }): Config;
14
16
  }
@@ -1,4 +1,6 @@
1
1
  export declare abstract class JsonSerializable {
2
- static stringify(object: any): string;
2
+ static stringify(object: {
3
+ [k: string]: any;
4
+ }): string;
3
5
  abstract jsonSerialize(): any;
4
6
  }
@@ -19,9 +19,7 @@ export class AccessTokenEndpoint extends Endpoint {
19
19
  async create(name, scopes) {
20
20
  try {
21
21
  const url = '/access-tokens';
22
- const result = await this.requestObject(url, {
23
- name, scopes,
24
- }, UserAccessToken.parse, 'POST');
22
+ const result = await this.requestObject(url, { name, scopes }, UserAccessToken.parse, 'POST');
25
23
  const createdToken = result.getData();
26
24
  if (createdToken === null) {
27
25
  throw new Error('Unable to create token: wrong response from API');
@@ -38,9 +36,7 @@ export class AccessTokenEndpoint extends Endpoint {
38
36
  async update(tokenId, name, scopes) {
39
37
  try {
40
38
  const url = '/access-tokens/' + tokenId;
41
- const result = await this.requestObject(url, {
42
- name, scopes,
43
- }, UserAccessToken.parse, 'POST');
39
+ const result = await this.requestObject(url, { name, scopes }, UserAccessToken.parse, 'POST');
44
40
  const updatedToken = result.getData();
45
41
  if (updatedToken === null) {
46
42
  throw new Error('Unable to create token: wrong response from API');
@@ -9,7 +9,9 @@ export declare abstract class Endpoint {
9
9
  private formatParameters;
10
10
  private formatKey;
11
11
  requestCollection<T>(action: string | QueryString, parser: (input: any) => T, parameters?: Parameters, method?: string, signWithOauthToken?: boolean): Promise<CollectionResult<T>>;
12
- requestObject<T>(action: string | QueryString, parameters: Parameters | undefined, parser: (input: any) => T, method?: string, signWithOauthToken?: boolean): Promise<ObjectResult<T>>;
12
+ requestObject<T>(action: string | QueryString, parameters: Parameters | undefined, parser: (input: {
13
+ [k: string]: any;
14
+ }) => T, method?: string, signWithOauthToken?: boolean): Promise<ObjectResult<T>>;
13
15
  parseCollection<T>(rawData: object[], parser: (input: any) => T): T[];
14
16
  private parseObject;
15
17
  }
@@ -38,9 +38,7 @@ export class FirewallEndpoint extends Endpoint {
38
38
  const cmd = '/system/firewall/ip_rules';
39
39
  try {
40
40
  const parser = (raw) => raw.success;
41
- const result = await this.requestObject(cmd, {
42
- ip, action, description,
43
- }, parser, 'PUT');
41
+ const result = await this.requestObject(cmd, { ip, action, description }, parser, 'PUT');
44
42
  const re = result.getData();
45
43
  if (re === null) {
46
44
  console.log('createIPRule wrong result', { result, parsed: re });
@@ -114,7 +114,7 @@ export class UserEndpoint extends Endpoint {
114
114
  async createWebPush(subscription, session) {
115
115
  try {
116
116
  const url = '/webpush';
117
- const parser = (raw) => ({ created: raw.requested });
117
+ const parser = (raw) => ({ created: raw.created });
118
118
  const result = await this.requestObject(url, { subscription, session }, parser, 'POST', true);
119
119
  const re = result.getData();
120
120
  if (re === null) {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "1.13.39";
1
+ export declare const VERSION = "1.13.50";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.13.39";
1
+ export const VERSION = "1.13.50";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attlaz-client",
3
- "version": "1.13.49",
3
+ "version": "1.13.51",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",