attlaz-client 1.12.3 → 1.13.0

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/dist/Client.d.ts CHANGED
@@ -36,7 +36,6 @@ export declare class Client {
36
36
  private parseConfig;
37
37
  constructor(token?: string | null, config?: Record<string, unknown>);
38
38
  setClientCredentials(clientId: string, clientSecret?: string): void;
39
- private getHeaders;
40
39
  getHttpClient(): OAuthClient;
41
40
  authenticate(): Promise<boolean>;
42
41
  authenticate(username: string, password: string): Promise<boolean>;
package/dist/Client.js CHANGED
@@ -27,7 +27,6 @@ import { TriggerEndpoint } from './Service/TriggerEndpoint.js';
27
27
  import { PlatformEndpoint } from './Service/PlatformEndpoint.js';
28
28
  import { FlowRunStatsEndpoint } from './Service/FlowRunStatsEndpoint.js';
29
29
  import { FirewallEndpoint } from './Service/FirewallEndpoint.js';
30
- import { VERSION } from './version.js';
31
30
  import { CodeSourceStrategiesEndpoint } from './Service/CodeSourceStrategiesEndpoint.js';
32
31
  import { SearchEndpoint } from './Service/SearchEndpoint.js';
33
32
  export class Client {
@@ -72,7 +71,7 @@ export class Client {
72
71
  if (parsedConfig.apiEndpoint !== undefined) {
73
72
  this.apiEndpoint = parsedConfig.apiEndpoint;
74
73
  }
75
- const options = new OAuthClientOptions(this.apiEndpoint, null, null, this.getHeaders());
74
+ const options = new OAuthClientOptions(this.apiEndpoint);
76
75
  this.httpClient = new OAuthClient(options);
77
76
  if (token !== null) {
78
77
  const clientToken = new OAuthClientToken(token, 'Bearer', '', '');
@@ -81,21 +80,9 @@ export class Client {
81
80
  this.endpoints = new Map();
82
81
  }
83
82
  setClientCredentials(clientId, clientSecret = '') {
84
- const options = new OAuthClientOptions(this.apiEndpoint, clientId, clientSecret, this.getHeaders());
83
+ const options = new OAuthClientOptions(this.apiEndpoint, clientId, clientSecret);
85
84
  this.httpClient = new OAuthClient(options);
86
85
  }
87
- getHeaders() {
88
- const userAgentInfo = {
89
- version: VERSION,
90
- language: 'Javascript',
91
- language_version: '',
92
- publisher: 'Attlaz',
93
- };
94
- return {
95
- 'User-Agent': 'Attlaz Javascript Client/' + VERSION,
96
- 'X-Attlaz-Client-User-Agent': JSON.stringify(userAgentInfo),
97
- };
98
- }
99
86
  getHttpClient() {
100
87
  return this.httpClient;
101
88
  }
@@ -115,10 +102,6 @@ export class Client {
115
102
  setToken(token) {
116
103
  this.httpClient.setToken(token);
117
104
  }
118
- //
119
- // public x(accessToken: string, refreshToken: string): Promise<Token> {
120
- // return this.httpClient.refreshToken(accessToken, refreshToken);
121
- // }
122
105
  unsetAccessToken() {
123
106
  this.httpClient.unsetToken();
124
107
  }
@@ -11,7 +11,7 @@ export declare class HttpClient {
11
11
  static HTTP_BAD_GATEWAY: number;
12
12
  static HTTP_UNAVAILABLE: number;
13
13
  static HTTP_TIMEOUT: number;
14
- static request2(request: HttpClientRequest): Promise<HttpClientResponse>;
14
+ static request(request: HttpClientRequest): Promise<HttpClientResponse>;
15
15
  private static getContentType;
16
16
  private static formatContentType;
17
17
  }
@@ -1,6 +1,5 @@
1
1
  import { fetch } from 'popsicle';
2
2
  import { HttpClientResponse } from './HttpClientResponse.js';
3
- import { VERSION } from '../version.js';
4
3
  import { ClientError } from './ClientError.js';
5
4
  export class HttpClient {
6
5
  static HTTP_BAD_REQUEST = 400;
@@ -13,26 +12,7 @@ export class HttpClient {
13
12
  static HTTP_BAD_GATEWAY = 502;
14
13
  static HTTP_UNAVAILABLE = 503;
15
14
  static HTTP_TIMEOUT = 504;
16
- // public static async get(url: string, requestData: any = {}): Promise<any> {
17
- // if (Utils.isNullOrUndefined(requestData)) {
18
- // requestData = {};
19
- // }
20
- // const response: Response = await fetch(url, requestData);
21
- //
22
- // //TODO: validate status
23
- // const error: ClientError | null = ClientError.byStatus(response.status, response.statusText);
24
- // if (!Utils.isNullOrUndefined(error)) {
25
- // throw error;
26
- // }
27
- //
28
- // // TODO: make it possible to do request without parsing the json
29
- // return await response.json();
30
- // }
31
- static async request2(request) {
32
- if (typeof window === 'undefined') {
33
- // Add user agent when running in Node
34
- request.headers['User-Agent'] = 'Attlaz Http/' + VERSION;
35
- }
15
+ static async request(request) {
36
16
  const rawRequest = {
37
17
  url: request.getFullUrl(),
38
18
  method: request.method,
@@ -1,9 +1,10 @@
1
+ import { Headers } from './Data/Header.js';
1
2
  export declare class HttpClientRequest {
2
- static readonly GET = "GET";
3
- static readonly POST = "POST";
4
- static readonly PUT = "PUT";
3
+ static readonly GET: string;
4
+ static readonly POST: string;
5
+ static readonly PUT: string;
5
6
  method: string;
6
- headers: any;
7
+ headers: Headers;
7
8
  body: any;
8
9
  private urlObj;
9
10
  constructor(url: string, method?: string);
@@ -1,16 +1,17 @@
1
1
  import { OAuthClientOptions } from './OAuthClientOptions.js';
2
2
  import { OAuthClientToken } from './OAuthClientToken.js';
3
3
  import { Parameters } from './Data/Parameters.js';
4
+ import { Headers } from './Data/Header.js';
4
5
  export declare class OAuthClient {
5
6
  private readonly options;
6
7
  private debug;
7
8
  private oauthClient;
8
9
  private oauthToken;
9
10
  private oathClientToken;
11
+ private refreshTokenPromise;
10
12
  constructor(options: OAuthClientOptions);
11
13
  authenticate(username: string, password: string): Promise<boolean>;
12
14
  authenticate(): Promise<boolean>;
13
- private refreshTokenPromise;
14
15
  refreshToken(): Promise<void>;
15
16
  isTokenExpires(): boolean;
16
17
  request(action: string, parameters?: Parameters, method?: string, signWithOauthToken?: boolean): Promise<any>;
@@ -26,6 +27,8 @@ export declare class OAuthClient {
26
27
  [key: string]: string | string[];
27
28
  };
28
29
  } | null): string;
30
+ getDefaultHeaders(): Headers;
31
+ private isNodeEnvironment;
29
32
  private tokenToOauthClientToken;
30
33
  private getUri;
31
34
  private createRequestData;
@@ -4,12 +4,14 @@ import { HttpClient } from './HttpClient.js';
4
4
  import { HttpClientRequest } from './HttpClientRequest.js';
5
5
  import { OAuthClientToken } from './OAuthClientToken.js';
6
6
  import { JsonSerializable } from '../Model/JsonSerializable.js';
7
+ import { VERSION } from '../version.js';
7
8
  export class OAuthClient {
8
9
  options;
9
10
  debug = false;
10
11
  oauthClient;
11
12
  oauthToken = null;
12
13
  oathClientToken = null;
14
+ refreshTokenPromise = null;
13
15
  constructor(options) {
14
16
  this.options = options;
15
17
  this.oauthClient = new ClientOAuth2({
@@ -20,7 +22,7 @@ export class OAuthClient {
20
22
  redirectUri: options.redirectUri,
21
23
  scopes: options.scopes,
22
24
  state: options.state,
23
- headers: options.headers,
25
+ headers: this.getDefaultHeaders(),
24
26
  });
25
27
  }
26
28
  async authenticate(username = null, password = null) {
@@ -46,7 +48,6 @@ export class OAuthClient {
46
48
  throw ClientError.fromError(e);
47
49
  }
48
50
  }
49
- refreshTokenPromise = null;
50
51
  async refreshToken() {
51
52
  if (this.debug) {
52
53
  console.debug('[OAuthClient] refresh token');
@@ -98,7 +99,7 @@ export class OAuthClient {
98
99
  console.debug('[OAuthClient] Request: ' + requestData.method.toUpperCase() + ' ' + requestData.getFullUrl());
99
100
  }
100
101
  try {
101
- const response = await HttpClient.request2(requestData);
102
+ const response = await HttpClient.request(requestData);
102
103
  // if (this.debug) {
103
104
  // console.info('[Client response] ', {body: response.body});
104
105
  // }
@@ -159,6 +160,22 @@ export class OAuthClient {
159
160
  getTokenFlowUrl(options = null) {
160
161
  return this.oauthClient.token.getUri(options === null ? undefined : options);
161
162
  }
163
+ getDefaultHeaders() {
164
+ const userAgentInfo = {
165
+ version: VERSION,
166
+ language: 'Javascript',
167
+ language_version: '',
168
+ publisher: 'Attlaz',
169
+ };
170
+ const headers = { 'X-Attlaz-Client': JSON.stringify(userAgentInfo) };
171
+ if (this.isNodeEnvironment()) {
172
+ headers['User-Agent'] = 'Attlaz Http/' + VERSION;
173
+ }
174
+ return headers;
175
+ }
176
+ isNodeEnvironment() {
177
+ return typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
178
+ }
162
179
  tokenToOauthClientToken(oauthToken) {
163
180
  const token = new OAuthClientToken(oauthToken.accessToken, oauthToken.tokenType, oauthToken.refreshToken, oauthToken.data.scopes);
164
181
  const rawTokenExpires = oauthToken.expires;
@@ -176,6 +193,7 @@ export class OAuthClient {
176
193
  createRequestData(action, parameters = null, method = 'GET', signWithOauthToken = true) {
177
194
  const url = this.getUri(action);
178
195
  let requestData = new HttpClientRequest(url, method);
196
+ requestData.headers = this.getDefaultHeaders();
179
197
  if ((method === 'POST' || method === 'DELETE' || method === 'PUT') && parameters !== null && parameters !== undefined) {
180
198
  if (typeof parameters === 'object') {
181
199
  requestData.body = JsonSerializable.stringify(parameters);
@@ -1,13 +1,11 @@
1
- import { Headers } from './Data/Header.js';
2
1
  export declare class OAuthClientOptions {
3
2
  apiEndpoint: string;
4
3
  readonly clientId: string | null;
5
4
  readonly clientSecret: string | null;
6
- headers: Headers;
7
5
  accessTokenUri: string;
8
6
  authorizationUri: string;
9
7
  redirectUri: string;
10
8
  scopes: string[];
11
9
  state: string;
12
- constructor(apiEndpoint: string, clientId: string | null, clientSecret: string | null, headers: Headers);
10
+ constructor(apiEndpoint: string, clientId?: string | null, clientSecret?: string | null);
13
11
  }
@@ -2,16 +2,14 @@ export class OAuthClientOptions {
2
2
  apiEndpoint;
3
3
  clientId;
4
4
  clientSecret;
5
- headers;
6
5
  accessTokenUri = 'oauth/token';
7
6
  authorizationUri = 'oauth/authorize';
8
7
  redirectUri = 'https://example.com/auth/github/callback';
9
8
  scopes = ['all'];
10
9
  state = 'xyz';
11
- constructor(apiEndpoint, clientId, clientSecret, headers) {
10
+ constructor(apiEndpoint, clientId = null, clientSecret = null) {
12
11
  this.apiEndpoint = apiEndpoint;
13
12
  this.clientId = clientId;
14
13
  this.clientSecret = clientSecret;
15
- this.headers = headers;
16
14
  }
17
15
  }
@@ -1,17 +1,16 @@
1
- import { TriggerData } from './TriggerData.js';
2
1
  import { State } from '../State.js';
3
- import { TriggerType } from './TriggerType.js';
4
2
  import { StateAware } from '../StateAware.js';
5
3
  import { MetaDataAware } from '../../Core/MetaDataAware.js';
4
+ import { DataValueCollection } from '../DataValueCollection.js';
6
5
  export declare class Trigger extends MetaDataAware implements StateAware {
7
6
  id: string;
8
- type: TriggerType;
7
+ type: string;
9
8
  projectEnvironmentId: string;
10
9
  flowId: string;
11
10
  arguments: {};
12
- data: TriggerData;
11
+ data: DataValueCollection;
13
12
  state: State;
14
- constructor(id: string, type: TriggerType, projectEnvironmentId: string, flowId: string, data: TriggerData);
13
+ constructor(id: string, type: string, projectEnvironmentId: string, flowId: string, data: DataValueCollection);
15
14
  static parse(rawTrigger: any): Trigger;
16
- getData(): TriggerData;
15
+ getData(): DataValueCollection;
17
16
  }
@@ -1,8 +1,4 @@
1
1
  import { State } from '../State.js';
2
- import { TriggerType } from './TriggerType.js';
3
- import { ScheduleTriggerData } from './ScheduleTriggerData.js';
4
- import { WebhookTriggerData } from './WebhookTriggerData.js';
5
- import { ApiTriggerData } from './ApiTriggerData.js';
6
2
  import { MetaDataAware } from '../../Core/MetaDataAware.js';
7
3
  import { DataValueCollection } from '../DataValueCollection.js';
8
4
  export class Trigger extends MetaDataAware {
@@ -23,24 +19,10 @@ export class Trigger extends MetaDataAware {
23
19
  this.arguments = {};
24
20
  }
25
21
  static parse(rawTrigger) {
26
- const type = TriggerType.fromString(rawTrigger.type);
27
22
  const { data } = rawTrigger;
28
23
  const flowId = rawTrigger.flow;
29
- let triggerData;
30
- switch (type) {
31
- case TriggerType.Webhook:
32
- triggerData = new WebhookTriggerData(data.key);
33
- break;
34
- case TriggerType.Schedule:
35
- triggerData = new ScheduleTriggerData(data.expression);
36
- break;
37
- case TriggerType.Api:
38
- triggerData = new ApiTriggerData();
39
- break;
40
- default:
41
- throw new Error('Unknown trigger type "' + type + '"');
42
- }
43
- const trigger = new Trigger(rawTrigger.id, type, rawTrigger.project_environment, flowId, triggerData);
24
+ const parsedData = DataValueCollection.fromObject(rawTrigger.data);
25
+ const trigger = new Trigger(rawTrigger.id, data.type, data.project_environment, flowId, parsedData);
44
26
  trigger.arguments = rawTrigger.arguments;
45
27
  trigger.state = State.fromString(rawTrigger.state);
46
28
  trigger.metadata = DataValueCollection.fromObject(rawTrigger.metadata);
package/dist/index.d.ts CHANGED
@@ -59,15 +59,7 @@ export { StorageItemInformation } from './Model/Storage/StorageItemInformation.j
59
59
  /** Queue * */
60
60
  export { SearchResult } from './Model/Search/SearchResult.js';
61
61
  /** Trigger * */
62
- export { ApiTrigger } from './Model/Trigger/ApiTrigger.js';
63
- export { ApiTriggerData } from './Model/Trigger/ApiTriggerData.js';
64
- export { ScheduleTrigger } from './Model/Trigger/ScheduleTrigger.js';
65
- export { ScheduleTriggerData } from './Model/Trigger/ScheduleTriggerData.js';
66
62
  export { Trigger } from './Model/Trigger/Trigger.js';
67
- export { TriggerData } from './Model/Trigger/TriggerData.js';
68
- export { TriggerType } from './Model/Trigger/TriggerType.js';
69
- export { WebhookTrigger } from './Model/Trigger/WebhookTrigger.js';
70
- export { WebhookTriggerData } from './Model/Trigger/WebhookTriggerData.js';
71
63
  /** Worker* */
72
64
  export { Platform } from './Model/Worker/Platform.js';
73
65
  export { PlatformImage } from './Model/Worker/PlatformImage.js';
package/dist/index.js CHANGED
@@ -59,15 +59,7 @@ export { StorageItemInformation } from './Model/Storage/StorageItemInformation.j
59
59
  /** Queue * */
60
60
  export { SearchResult } from './Model/Search/SearchResult.js';
61
61
  /** Trigger * */
62
- export { ApiTrigger } from './Model/Trigger/ApiTrigger.js';
63
- export { ApiTriggerData } from './Model/Trigger/ApiTriggerData.js';
64
- export { ScheduleTrigger } from './Model/Trigger/ScheduleTrigger.js';
65
- export { ScheduleTriggerData } from './Model/Trigger/ScheduleTriggerData.js';
66
62
  export { Trigger } from './Model/Trigger/Trigger.js';
67
- export { TriggerData } from './Model/Trigger/TriggerData.js';
68
- export { TriggerType } from './Model/Trigger/TriggerType.js';
69
- export { WebhookTrigger } from './Model/Trigger/WebhookTrigger.js';
70
- export { WebhookTriggerData } from './Model/Trigger/WebhookTriggerData.js';
71
63
  /** Worker* */
72
64
  export { Platform } from './Model/Worker/Platform.js';
73
65
  export { PlatformImage } from './Model/Worker/PlatformImage.js';
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "1.12.2";
1
+ export declare const VERSION = "1.12.3";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.12.2";
1
+ export const VERSION = "1.12.3";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attlaz-client",
3
- "version": "1.12.3",
3
+ "version": "1.13.0",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",
@@ -1,6 +0,0 @@
1
- import { Trigger } from './Trigger.js';
2
- import { ApiTriggerData } from './ApiTriggerData.js';
3
- export declare class ApiTrigger extends Trigger {
4
- constructor(id: string, projectEnvironmentId: string, flowId: string, data: ApiTriggerData);
5
- getData(): ApiTriggerData;
6
- }
@@ -1,10 +0,0 @@
1
- import { Trigger } from './Trigger.js';
2
- import { TriggerType } from './TriggerType.js';
3
- export class ApiTrigger extends Trigger {
4
- constructor(id, projectEnvironmentId, flowId, data) {
5
- super(id, TriggerType.Api, projectEnvironmentId, flowId, data);
6
- }
7
- getData() {
8
- return super.getData();
9
- }
10
- }
@@ -1,4 +0,0 @@
1
- import { TriggerData } from './TriggerData.js';
2
- export declare class ApiTriggerData extends TriggerData {
3
- constructor();
4
- }
@@ -1,6 +0,0 @@
1
- import { TriggerData } from './TriggerData.js';
2
- export class ApiTriggerData extends TriggerData {
3
- constructor() {
4
- super();
5
- }
6
- }
@@ -1,6 +0,0 @@
1
- import { ScheduleTriggerData } from './ScheduleTriggerData.js';
2
- import { Trigger } from './Trigger.js';
3
- export declare class ScheduleTrigger extends Trigger {
4
- constructor(id: string, projectEnvironmentId: string, flowId: string, data: ScheduleTriggerData);
5
- getData(): ScheduleTriggerData;
6
- }
@@ -1,10 +0,0 @@
1
- import { Trigger } from './Trigger.js';
2
- import { TriggerType } from './TriggerType.js';
3
- export class ScheduleTrigger extends Trigger {
4
- constructor(id, projectEnvironmentId, flowId, data) {
5
- super(id, TriggerType.Schedule, projectEnvironmentId, flowId, data);
6
- }
7
- getData() {
8
- return super.getData();
9
- }
10
- }
@@ -1,5 +0,0 @@
1
- import { TriggerData } from './TriggerData.js';
2
- export declare class ScheduleTriggerData extends TriggerData {
3
- expression: string;
4
- constructor(expression: string);
5
- }
@@ -1,8 +0,0 @@
1
- import { TriggerData } from './TriggerData.js';
2
- export class ScheduleTriggerData extends TriggerData {
3
- expression;
4
- constructor(expression) {
5
- super();
6
- this.expression = expression;
7
- }
8
- }
@@ -1,3 +0,0 @@
1
- export declare abstract class TriggerData {
2
- toString(): string;
3
- }
@@ -1,5 +0,0 @@
1
- export class TriggerData {
2
- toString() {
3
- return JSON.stringify(this);
4
- }
5
- }
@@ -1,8 +0,0 @@
1
- export declare enum TriggerType {
2
- Schedule = "schedule",
3
- Webhook = "webhook",
4
- Api = "api"
5
- }
6
- export declare namespace TriggerType {
7
- function fromString(input: string): TriggerType;
8
- }
@@ -1,17 +0,0 @@
1
- import { Utils } from '../../Utils.js';
2
- export var TriggerType;
3
- (function (TriggerType) {
4
- TriggerType["Schedule"] = "schedule";
5
- TriggerType["Webhook"] = "webhook";
6
- TriggerType["Api"] = "api";
7
- })(TriggerType || (TriggerType = {}));
8
- (function (TriggerType) {
9
- function fromString(input) {
10
- const result = Utils.parseEnum(input, TriggerType);
11
- if (result === null) {
12
- throw new Error('Unable to parse TriggerType from string: Unknown TriggerType "' + input + '"');
13
- }
14
- return result;
15
- }
16
- TriggerType.fromString = fromString;
17
- })(TriggerType || (TriggerType = {}));
@@ -1,6 +0,0 @@
1
- import { WebhookTriggerData } from './WebhookTriggerData.js';
2
- import { Trigger } from './Trigger.js';
3
- export declare class WebhookTrigger extends Trigger {
4
- constructor(id: string, projectEnvironmentId: string, flowId: string, data: WebhookTriggerData);
5
- getData(): WebhookTriggerData;
6
- }
@@ -1,10 +0,0 @@
1
- import { Trigger } from './Trigger.js';
2
- import { TriggerType } from './TriggerType.js';
3
- export class WebhookTrigger extends Trigger {
4
- constructor(id, projectEnvironmentId, flowId, data) {
5
- super(id, TriggerType.Webhook, projectEnvironmentId, flowId, data);
6
- }
7
- getData() {
8
- return super.getData();
9
- }
10
- }
@@ -1,5 +0,0 @@
1
- import { TriggerData } from './TriggerData.js';
2
- export declare class WebhookTriggerData extends TriggerData {
3
- key: string;
4
- constructor(key: string);
5
- }
@@ -1,8 +0,0 @@
1
- import { TriggerData } from './TriggerData.js';
2
- export class WebhookTriggerData extends TriggerData {
3
- key;
4
- constructor(key) {
5
- super();
6
- this.key = key;
7
- }
8
- }