attlaz-client 1.9.14 → 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
  }
@@ -20,6 +20,7 @@ class Trigger extends MetaDataAware_1.MetaDataAware {
20
20
  this.arguments = {};
21
21
  }
22
22
  static parse(rawTrigger) {
23
+ console.log(rawTrigger);
23
24
  const type = TriggerType_1.TriggerType.fromString(rawTrigger.type);
24
25
  const data = rawTrigger.data;
25
26
  const flowId = rawTrigger.flow;
@@ -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
- import { DataResult } from '../Model/Result/DataResult';
3
2
  import { CollectionResult } from '../Model/Result/CollectionResult';
4
3
  import { ObjectResult } from '../Model/Result/ObjectResult';
4
+ import { Parameters } from '../Http/Data/Parameters';
5
5
  export declare abstract class Endpoint {
6
6
  protected httpClient: OAuthClient;
7
7
  constructor(httpClient: OAuthClient);
8
- requestCollection<T>(action: string, parameters: any, parser: (input: any) => T, method?: string, signWithOauthToken?: boolean): Promise<CollectionResult<T>>;
9
- requestObject<T>(action: string, parameters: any, parser: (input: any) => T, method?: string, signWithOauthToken?: boolean): Promise<ObjectResult<T>>;
10
- request<T>(action: string, parameters?: any, method?: string, signWithOauthToken?: boolean): Promise<DataResult<T>>;
8
+ private formatParameters;
9
+ private formatKey;
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
  }
@@ -1,17 +1,68 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Endpoint = void 0;
4
- const DataResult_1 = require("../Model/Result/DataResult");
5
4
  const CollectionResult_1 = require("../Model/Result/CollectionResult");
6
5
  const ObjectResult_1 = require("../Model/Result/ObjectResult");
7
6
  const HttpClient_1 = require("../Http/HttpClient");
8
7
  const Utils_1 = require("../Utils");
9
8
  const ObjectWrapper_1 = require("../Model/Result/ObjectWrapper");
9
+ const DataValueCollection_1 = require("../Model/DataValueCollection");
10
+ const JsonSerializable_1 = require("../Model/JsonSerializable");
10
11
  class Endpoint {
11
12
  constructor(httpClient) {
12
13
  this.httpClient = httpClient;
13
14
  }
15
+ formatParameters(data = null) {
16
+ if (data === null || data === undefined) {
17
+ return null;
18
+ }
19
+ if (Array.isArray(data)) {
20
+ const result = [];
21
+ for (const value of data) {
22
+ result.push(this.formatParameters(value));
23
+ }
24
+ return result;
25
+ }
26
+ // if (DateHelper.isDate(data)) {
27
+ // return DateHelper.toString(data);
28
+ // }
29
+ // tODo: this does not seem to work correclty
30
+ if (data instanceof JsonSerializable_1.JsonSerializable && 'jsonSerialize' in data) {
31
+ return data.jsonSerialize();
32
+ }
33
+ if (typeof data === 'object') {
34
+ if (
35
+ // data instanceof WorkspaceId ||
36
+ // data instanceof ProjectEnvironmentId ||
37
+ // data instanceof ProjectId ||
38
+ // data instanceof OrganisationId ||
39
+ // data instanceof FlowId ||
40
+ // data instanceof FlowRunId ||
41
+ // data instanceof UserId ||
42
+ // data instanceof DataCollectionResult ||
43
+ // data instanceof SuccessResult ||
44
+ data instanceof DataValueCollection_1.DataValueCollection) {
45
+ return this.formatParameters(data.jsonSerialize());
46
+ }
47
+ const result = {};
48
+ for (const [key, value] of Object.entries(data)) {
49
+ const formattedKey = this.formatKey(key);
50
+ result[formattedKey] = this.formatParameters(value);
51
+ }
52
+ return result;
53
+ }
54
+ return data;
55
+ }
56
+ formatKey(key) {
57
+ let formattedKey = key.replace(/([A-Z])/g, ' $1');
58
+ formattedKey = formattedKey.split(' ').join('_').toLowerCase();
59
+ if (formattedKey.endsWith('_id')) {
60
+ formattedKey = formattedKey.substring(0, formattedKey.length - '_id'.length);
61
+ }
62
+ return formattedKey;
63
+ }
14
64
  async requestCollection(action, parameters = null, parser, method = 'GET', signWithOauthToken = true) {
65
+ parameters = this.formatParameters(parameters);
15
66
  const requestResponse = await this.httpClient.request(action, parameters, method, signWithOauthToken);
16
67
  const result = new CollectionResult_1.CollectionResult();
17
68
  /**
@@ -32,6 +83,7 @@ class Endpoint {
32
83
  return result;
33
84
  }
34
85
  async requestObject(action, parameters = null, parser, method = 'GET', signWithOauthToken = true) {
86
+ parameters = this.formatParameters(parameters);
35
87
  const result = new ObjectResult_1.ObjectResult();
36
88
  try {
37
89
  let requestResponse = await this.httpClient.request(action, parameters, method, signWithOauthToken);
@@ -39,8 +91,8 @@ class Endpoint {
39
91
  /**
40
92
  * Parse errors
41
93
  */
42
- // TODO: temporary check untill we know the API is fully upgraded
43
- if (requestResponse.hasOwnProperty('data') && requestResponse.data !== undefined) {
94
+ // TODO: temporary check until we know the API is fully upgraded
95
+ if ((requestResponse.hasOwnProperty('data') && !requestResponse.hasOwnProperty('id')) && requestResponse.data !== undefined) {
44
96
  console.error('Response for object "' + action + '" seem to still use old "data" property', { requestResponse });
45
97
  requestResponse = requestResponse.data;
46
98
  }
@@ -57,10 +109,11 @@ class Endpoint {
57
109
  return result;
58
110
  }
59
111
  ;
60
- async request(action, parameters = null, method = 'GET', signWithOauthToken = true) {
61
- const result = await this.httpClient.request(action, parameters, method, signWithOauthToken);
62
- return DataResult_1.DataResult.parse(result);
63
- }
112
+ // public async request<T>(action: string, parameters: any | null = null, method: string = 'GET', signWithOauthToken: boolean = true): Promise<DataResult<T>> {
113
+ // const result: any = await this.httpClient.request(action, parameters, method, signWithOauthToken);
114
+ //
115
+ // return DataResult.parse<T>(result);
116
+ // }
64
117
  parseCollection(rawData, parser) {
65
118
  const data = [];
66
119
  if (!Array.isArray(rawData)) {
@@ -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
  }
@@ -50,8 +49,8 @@ class FlowRunEndpoint extends Endpoint_1.Endpoint {
50
49
  }
51
50
  async getFlowRunSummary(flowRunId) {
52
51
  try {
53
- const result = await this.requestObject('/taskexecutions/' + flowRunId + '/summaries', null, FlowRunSummary_1.FlowRunSummary.parse);
54
- return result;
52
+ const result = await this.requestObject('/flowruns/' + flowRunId + '/summaries', null, FlowRunSummary_1.FlowRunSummary.parse);
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()) {
@@ -25,7 +25,7 @@ class StorageEndpoint extends Endpoint_1.Endpoint {
25
25
  let cmd = '/projectenvironments/' + projectEnvironmentId + '/storage/' + storageType + '/' + poolKey;
26
26
  try {
27
27
  const parser = (raw) => {
28
- return raw.cleared;
28
+ return raw.deleted;
29
29
  };
30
30
  const result = await this.requestObject(cmd, null, parser, 'DELETE');
31
31
  const re = result.getData();
@@ -33,7 +33,7 @@ class StorageEndpoint extends Endpoint_1.Endpoint {
33
33
  console.log('clearpool wrong data', { result, parsed: re });
34
34
  throw new Error('Something went wrong');
35
35
  }
36
- return re.cleared;
36
+ return re.deleted;
37
37
  }
38
38
  catch (ex) {
39
39
  if (this.httpClient.isDebugEnabled()) {
@@ -90,7 +90,7 @@ class WorkspaceMemberEndpoint extends Endpoint_1.Endpoint {
90
90
  userAction.userId = rawUserEvent.user;
91
91
  userAction.workspaceId = rawUserEvent.workspace;
92
92
  userAction.action = rawUserEvent.action;
93
- userAction.resourceId = rawUserEvent.resource_id;
93
+ userAction.resourceId = rawUserEvent.resource;
94
94
  userAction.resourceType = rawUserEvent.resource_type;
95
95
  userAction.description = rawUserEvent.description;
96
96
  userAction.ip = rawUserEvent.ip;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attlaz-client",
3
- "version": "1.9.14",
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",