attlaz-client 1.9.15 → 1.9.16

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.
@@ -0,0 +1,3 @@
1
+ export type Headers = {
2
+ [key: string]: string | string[];
3
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export type Parameters = {
2
+ [key: string]: string | number;
3
+ } | object | null;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,6 @@
1
1
  import { OAuthClientOptions } from './OAuthClientOptions';
2
2
  import { OAuthClientToken } from './OAuthClientToken';
3
+ import { Parameters } from './Data/Parameters';
3
4
  export declare class OAuthClient {
4
5
  private readonly options;
5
6
  private debug;
@@ -12,7 +13,7 @@ export declare class OAuthClient {
12
13
  private refreshTokenPromise;
13
14
  refreshToken(): Promise<void>;
14
15
  isTokenExpires(): boolean;
15
- request(action: string, parameters?: any, method?: string, signWithOauthToken?: boolean): Promise<any>;
16
+ request(action: string, parameters?: Parameters, method?: string, signWithOauthToken?: boolean): Promise<any>;
16
17
  isAuthenticated(): boolean;
17
18
  getToken(): OAuthClientToken | null;
18
19
  setToken(token: OAuthClientToken): void;
@@ -179,18 +179,19 @@ class OAuthClient {
179
179
  let requestData = new HttpClientRequest_1.HttpClientRequest(url, method);
180
180
  if ((method === 'POST' || method === 'DELETE' || method === 'PUT') && parameters !== null && parameters !== undefined) {
181
181
  if (typeof parameters === 'object') {
182
- parameters = JsonSerializable_1.JsonSerializable.stringify(parameters);
182
+ requestData.body = JsonSerializable_1.JsonSerializable.stringify(parameters);
183
183
  }
184
184
  else if (typeof parameters === 'string') {
185
+ requestData.body = parameters;
185
186
  }
186
187
  else {
187
188
  console.error('Unknown parameter type: ' + typeof parameters);
188
189
  }
189
- requestData.body = parameters;
190
190
  requestData.setJsonHeader();
191
191
  }
192
192
  if (method === 'GET' && parameters !== null && parameters !== undefined) {
193
193
  Object.keys(parameters).forEach((key, index) => {
194
+ // @ts-ignore
194
195
  const value = parameters[key];
195
196
  requestData.addQueryParam(key, value);
196
197
  });
@@ -1,3 +1,4 @@
1
+ import { Headers } from './Data/Header';
1
2
  export declare class OAuthClientOptions {
2
3
  apiEndpoint: string;
3
4
  clientId: string;
@@ -7,10 +8,6 @@ export declare class OAuthClientOptions {
7
8
  redirectUri: string;
8
9
  scopes: string[];
9
10
  state: string;
10
- headers: {
11
- [key: string]: string | string[];
12
- };
13
- constructor(apiEndpoint: string, clientId: string, clientSecret: string, headers: {
14
- [key: string]: string | string[];
15
- });
11
+ headers: Headers;
12
+ constructor(apiEndpoint: string, clientId: string, clientSecret: string, headers: Headers);
16
13
  }
@@ -8,5 +8,5 @@ export declare class ChannelEndpoint extends Endpoint {
8
8
  getByOwner(): Promise<CollectionResult<Channel>>;
9
9
  getMessages(channelId: string): Promise<CollectionResult<ChannelHistory>>;
10
10
  save(subscriberChannel: Channel): Promise<Channel>;
11
- testChannel(subscriberChannel: Channel): Promise<any>;
11
+ testChannel(subscriberChannel: Channel): Promise<boolean>;
12
12
  }
@@ -106,7 +106,7 @@ class ChannelEndpoint extends Endpoint_1.Endpoint {
106
106
  console.log('testChannel wrong data', { result, parsed: re });
107
107
  throw new Error('Something went wrong');
108
108
  }
109
- return result;
109
+ return re.tested;
110
110
  }
111
111
  catch (ex) {
112
112
  if (this.httpClient.isDebugEnabled()) {
@@ -1,12 +1,13 @@
1
1
  import { OAuthClient } from '../Http/OAuthClient';
2
2
  import { CollectionResult } from '../Model/Result/CollectionResult';
3
3
  import { ObjectResult } from '../Model/Result/ObjectResult';
4
+ import { Parameters } from '../Http/Data/Parameters';
4
5
  export declare abstract class Endpoint {
5
6
  protected httpClient: OAuthClient;
6
7
  constructor(httpClient: OAuthClient);
7
8
  private formatParameters;
8
9
  private formatKey;
9
- requestCollection<T>(action: string, parameters: any, parser: (input: any) => T, method?: string, signWithOauthToken?: boolean): Promise<CollectionResult<T>>;
10
- requestObject<T>(action: string, parameters: any, parser: (input: any) => T, method?: string, signWithOauthToken?: boolean): Promise<ObjectResult<T>>;
10
+ requestCollection<T>(action: string, parameters: Parameters | undefined, parser: (input: any) => T, method?: string, signWithOauthToken?: boolean): Promise<CollectionResult<T>>;
11
+ requestObject<T>(action: string, parameters: Parameters | undefined, parser: (input: any) => T, method?: string, signWithOauthToken?: boolean): Promise<ObjectResult<T>>;
11
12
  parseCollection<T>(rawData: object[], parser: (input: any) => T): T[];
12
13
  }
@@ -16,28 +16,27 @@ class FlowRunEndpoint extends Endpoint_1.Endpoint {
16
16
  async getFlowRunSummaries(flowId, from = null, to = null, flowRunStatuses = null, projectEnvironmentId = null) {
17
17
  try {
18
18
  let params = null;
19
- if (from !== null && from !== undefined) {
20
- params = {};
21
- params.from = from.toISOString();
22
- }
23
- if (to !== null && to !== undefined) {
24
- if (params === null || params === undefined) {
25
- params = {};
26
- }
27
- params.to = to.toISOString();
28
- }
19
+ // if (from !== null && from !== undefined) {
20
+ //
21
+ // params = {};
22
+ //
23
+ // params.from = from.toISOString();
24
+ // }
25
+ // if (to !== null && to !== undefined) {
26
+ // if (params === null || params === undefined) {
27
+ // params = {};
28
+ // }
29
+ // params.to = to.toISOString();
30
+ // }
29
31
  if (!Utils_1.Utils.isNullOrUndefined(projectEnvironmentId)) {
30
- if (params === null || params === undefined) {
31
- params = {};
32
- }
33
- params.environment = projectEnvironmentId;
34
- }
35
- if (flowRunStatuses !== null && flowRunStatuses.length > 0) {
36
- if (params === null || params === undefined) {
37
- params = {};
38
- }
39
- params.statuses = flowRunStatuses;
32
+ params = { project_environment: projectEnvironmentId };
40
33
  }
34
+ // if (flowRunStatuses !== null && flowRunStatuses.length > 0) {
35
+ // if (params === null || params === undefined) {
36
+ // params = {};
37
+ // }
38
+ // params.statuses = flowRunStatuses;
39
+ // }
41
40
  const result = await this.requestCollection('/flows/' + flowId + '/runsummaries', params, FlowRunSummary_1.FlowRunSummary.parse);
42
41
  return result;
43
42
  }
@@ -51,7 +50,7 @@ class FlowRunEndpoint extends Endpoint_1.Endpoint {
51
50
  async getFlowRunSummary(flowRunId) {
52
51
  try {
53
52
  const result = await this.requestObject('/flowruns/' + flowRunId + '/summaries', null, FlowRunSummary_1.FlowRunSummary.parse);
54
- return result;
53
+ return result.getData();
55
54
  }
56
55
  catch (error) {
57
56
  if (error instanceof ClientError_1.ClientError && error.code === HttpClient_1.HttpClient.HTTP_NOTFOUND) {
@@ -72,10 +71,10 @@ class FlowRunEndpoint extends Endpoint_1.Endpoint {
72
71
  throw new Error('Task execution id cannot be empty');
73
72
  }
74
73
  let params = {};
75
- if (!Utils_1.Utils.isNullOrUndefined(status)) {
74
+ if (status !== null && status !== undefined) {
76
75
  params.status = status;
77
76
  }
78
- if (!Utils_1.Utils.isNullOrUndefined(time)) {
77
+ if (time !== null && time !== undefined) {
79
78
  params.time = time;
80
79
  }
81
80
  const result = await this.requestObject('/flowruns/' + taskExecutionId + '', params, FlowRun_1.FlowRun.parse, 'POST');
@@ -1,5 +1,6 @@
1
1
  import { Endpoint } from './Endpoint';
2
2
  import { FlowRunResponse } from '../Model/Flow/FlowRunResponse';
3
+ import { Parameters } from '../Http/Data/Parameters';
3
4
  export declare class FlowRunRequestEndpoint extends Endpoint {
4
- postFlowRunRequest(taskId: string, params: any, wait?: boolean): Promise<FlowRunResponse>;
5
+ postFlowRunRequest(taskId: string, params: Parameters, wait?: boolean): Promise<FlowRunResponse>;
5
6
  }
@@ -3,5 +3,5 @@ import { Notification } from '../Model/Notification';
3
3
  import { CollectionResult } from '../Model/Result/CollectionResult';
4
4
  export declare class NotificationsEndpoint extends Endpoint {
5
5
  getAll(unacknowledgedOnly?: boolean): Promise<CollectionResult<Notification>>;
6
- save(notification: Notification): Promise<any>;
6
+ save(notification: Notification): Promise<Notification>;
7
7
  }
@@ -24,7 +24,11 @@ class NotificationsEndpoint extends Endpoint_1.Endpoint {
24
24
  return raw;
25
25
  };
26
26
  const result = await this.requestObject('/notifications', notification, parser, 'POST');
27
- return result.getData();
27
+ const savedNotification = result.getData();
28
+ if (savedNotification === null) {
29
+ throw new Error('Something went wrong');
30
+ }
31
+ return savedNotification;
28
32
  }
29
33
  }
30
34
  exports.NotificationsEndpoint = NotificationsEndpoint;
@@ -31,7 +31,7 @@ class ProjectEndpoint extends Endpoint_1.Endpoint {
31
31
  async getById(projectId) {
32
32
  try {
33
33
  const result = await this.requestObject('projects/' + projectId + '', null, Project_1.Project.parse);
34
- return result;
34
+ return result.getData();
35
35
  }
36
36
  catch (error) {
37
37
  if (this.httpClient.isDebugEnabled()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attlaz-client",
3
- "version": "1.9.15",
3
+ "version": "1.9.16",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",