attlaz-client 1.10.15 → 1.10.18

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,11 +1,9 @@
1
- import { DataValueCollection } from '../DataValueCollection.js';
2
1
  export declare class AdapterConnection {
3
2
  id: string;
4
3
  key: string;
5
4
  adapter: string;
6
5
  name: string;
7
6
  projectId: string;
8
- configuration: DataValueCollection;
9
7
  constructor();
10
8
  static parse(rawAdapterConnection: any): AdapterConnection;
11
9
  }
@@ -1,13 +1,11 @@
1
- import { DataValueCollection } from '../DataValueCollection.js';
2
1
  export class AdapterConnection {
3
2
  id;
4
3
  key;
5
4
  adapter;
6
5
  name;
7
6
  projectId;
8
- configuration;
7
+ // configuration: DataValueCollection;
9
8
  constructor() {
10
- this.configuration = new DataValueCollection();
11
9
  }
12
10
  static parse(rawAdapterConnection) {
13
11
  const adapterConnection = new AdapterConnection();
@@ -16,7 +14,7 @@ export class AdapterConnection {
16
14
  adapterConnection.adapter = rawAdapterConnection.adapter;
17
15
  adapterConnection.name = rawAdapterConnection.name;
18
16
  adapterConnection.projectId = rawAdapterConnection.project;
19
- adapterConnection.configuration = DataValueCollection.fromObject(rawAdapterConnection.configuration);
17
+ // adapterConnection.configuration = DataValueCollection.fromObject(rawAdapterConnection.configuration);
20
18
  return adapterConnection;
21
19
  // adapter.id = rawAdapter.id;
22
20
  // adapter.name = rawAdapter.name;
@@ -8,6 +8,7 @@ export declare class DataValueCollection extends JsonSerializable implements Ite
8
8
  value: DataValueValue;
9
9
  }[]): DataValueCollection;
10
10
  set(key: string, value: DataValueValue): void;
11
+ has(key: string): boolean;
11
12
  get(key: string): DataValueValue | null;
12
13
  unset(key: string): void;
13
14
  serialize(): string | null;
@@ -24,6 +24,14 @@ export class DataValueCollection extends JsonSerializable {
24
24
  }
25
25
  this._values.push(new DataValue(key, value));
26
26
  }
27
+ has(key) {
28
+ for (const tag of this._values) {
29
+ if (tag.key === key) {
30
+ return true;
31
+ }
32
+ }
33
+ return false;
34
+ }
27
35
  get(key) {
28
36
  for (const tag of this._values) {
29
37
  if (tag.key === key) {
@@ -3,11 +3,15 @@ import { Adapter } from '../Model/Adapter/Adapter.js';
3
3
  import { AdapterConnection } from '../Model/Adapter/AdapterConnection.js';
4
4
  import { AdapterConfiguration } from '../Model/Adapter/AdapterConfiguration.js';
5
5
  import { CollectionResult } from '../Model/Result/CollectionResult.js';
6
+ import { DataValueCollection } from '../Model/DataValueCollection.js';
6
7
  export declare class AdapterEndpoint extends Endpoint {
7
8
  getAdapters(): Promise<CollectionResult<Adapter>>;
8
9
  getAdapter(adapterId: string): Promise<Adapter | null>;
9
10
  getAdapterConfiguration(adapterId: string): Promise<CollectionResult<AdapterConfiguration>>;
10
11
  getConnections(projectId: string): Promise<CollectionResult<AdapterConnection>>;
11
- getConnectionByKey(connectionKey: string): Promise<AdapterConnection | null>;
12
- saveConnection(projectId: string, adapter: AdapterConnection): Promise<AdapterConnection>;
12
+ getConnectionById(connectionId: string): Promise<AdapterConnection | null>;
13
+ getConnectionByKey(projectId: string, connectionKey: string): Promise<AdapterConnection | null>;
14
+ getConnectionConfiguration(connectionId: string): Promise<DataValueCollection | null>;
15
+ saveConnection(projectId: string, connection: AdapterConnection): Promise<AdapterConnection>;
16
+ saveConnectionConfiguration(connectionId: string, configuration: DataValueCollection): Promise<boolean>;
13
17
  }
@@ -2,6 +2,7 @@ import { Endpoint } from './Endpoint.js';
2
2
  import { Adapter } from '../Model/Adapter/Adapter.js';
3
3
  import { AdapterConnection } from '../Model/Adapter/AdapterConnection.js';
4
4
  import { AdapterConfiguration } from '../Model/Adapter/AdapterConfiguration.js';
5
+ import { DataValueCollection } from '../Model/DataValueCollection.js';
5
6
  export class AdapterEndpoint extends Endpoint {
6
7
  async getAdapters() {
7
8
  try {
@@ -52,9 +53,9 @@ export class AdapterEndpoint extends Endpoint {
52
53
  throw error;
53
54
  }
54
55
  }
55
- async getConnectionByKey(connectionKey) {
56
+ async getConnectionById(connectionId) {
56
57
  try {
57
- const url = '/connections/' + connectionKey;
58
+ const url = '/connections/' + connectionId;
58
59
  const result = await this.requestObject(url, null, AdapterConnection.parse);
59
60
  return result.getData();
60
61
  }
@@ -65,10 +66,41 @@ export class AdapterEndpoint extends Endpoint {
65
66
  throw error;
66
67
  }
67
68
  }
68
- async saveConnection(projectId, adapter) {
69
+ async getConnectionByKey(projectId, connectionKey) {
70
+ try {
71
+ const url = '/project/' + projectId + '/connections/' + connectionKey;
72
+ const result = await this.requestObject(url, null, AdapterConnection.parse);
73
+ return result.getData();
74
+ }
75
+ catch (error) {
76
+ if (this.httpClient.isDebugEnabled()) {
77
+ console.error('Failed to load connection: ', error);
78
+ }
79
+ throw error;
80
+ }
81
+ }
82
+ async getConnectionConfiguration(connectionId) {
83
+ try {
84
+ const url = '/connections/' + connectionId + '/configuration';
85
+ const parser = (raw) => (DataValueCollection.fromObject(raw.configuration));
86
+ const result = await this.requestObject(url, null, parser);
87
+ const configuration = result.getData();
88
+ if (configuration === null) {
89
+ throw new Error('Adapter configuration loaded');
90
+ }
91
+ return configuration;
92
+ }
93
+ catch (error) {
94
+ if (this.httpClient.isDebugEnabled()) {
95
+ console.error('Failed to load connection: ', error);
96
+ }
97
+ throw error;
98
+ }
99
+ }
100
+ async saveConnection(projectId, connection) {
69
101
  try {
70
102
  const url = '/projects/' + projectId + '/connections';
71
- const result = await this.requestObject(url, adapter, AdapterConnection.parse, 'POST');
103
+ const result = await this.requestObject(url, connection, AdapterConnection.parse, 'POST');
72
104
  const updatedAdapterConnection = result.getData();
73
105
  if (updatedAdapterConnection === null) {
74
106
  throw new Error('AdapterConnection not updated');
@@ -82,4 +114,22 @@ export class AdapterEndpoint extends Endpoint {
82
114
  throw error;
83
115
  }
84
116
  }
117
+ async saveConnectionConfiguration(connectionId, configuration) {
118
+ try {
119
+ const url = '/connections/' + connectionId + '/configuration';
120
+ const parser = (raw) => ({ saved: raw.saved });
121
+ const result = await this.requestObject(url, { configuration: configuration }, parser, 'POST');
122
+ const x = result.getData();
123
+ if (x === null) {
124
+ throw new Error('Unable to save connection configuration: wrong response from API');
125
+ }
126
+ return x.saved;
127
+ }
128
+ catch (error) {
129
+ if (this.httpClient.isDebugEnabled()) {
130
+ console.error('Failed to save connection: ', error);
131
+ }
132
+ throw error;
133
+ }
134
+ }
85
135
  }
@@ -38,9 +38,15 @@ export class UserEndpoint extends Endpoint {
38
38
  async createAuthProvider(providerType, data) {
39
39
  try {
40
40
  const parser = (raw) => raw;
41
- const result = await this.requestObject('/users/auth/providers', { provider_type: providerType, code: data.code, state: data.state }, parser, 'POST');
42
- // TODO validation
43
- return true;
41
+ const result = await this.requestObject('/users/auth/providers', {
42
+ provider_type: providerType, code: data.code, state: data.state
43
+ }, parser, 'POST');
44
+ const re = result.getData();
45
+ if (re === null) {
46
+ console.log('create auth provider wrong data', { result, parsed: re });
47
+ throw new Error('Unable to create auth provider: wrong response from API');
48
+ }
49
+ return re.created;
44
50
  }
45
51
  catch (e) {
46
52
  if (this.httpClient.isDebugEnabled()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attlaz-client",
3
- "version": "1.10.15",
3
+ "version": "1.10.18",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",