Skip to content

Commit bd847e2

Browse files
Merge branch 'dev'
2 parents 5c39907 + 3d7e7d1 commit bd847e2

11 files changed

+145
-2
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.1.0-alpha.3 (2020-10-21)
2+
3+
### New Features & Enhancements
4+
- feat(\*) Implement "AtLeast" utility type
5+
- feat(\*) Implement "DataConnectors" API and types
6+
17
## 0.1.0-alpha.2 (2020-10-11)
28

39
### New Features & Enhancements

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@connio/js-sdk",
3-
"version": "0.1.0-alpha.2",
3+
"version": "0.1.0-alpha.3",
44
"description": "Connio JavaScript SDK",
55
"main": "./src/index.ts",
66
"repository": {
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { IDataConnector } from '../entities';
2+
import {
3+
IDeleteResponse,
4+
IPaginatedResponse,
5+
IRestClient,
6+
} from '../rest-client';
7+
import type { AtLeast } from '../utility-types';
8+
9+
export interface IDataConnectors {
10+
list<T extends IDataConnector>(appRef: string): Promise<T[]>;
11+
delete(connectorId: string, appRef: string): Promise<IDeleteResponse>;
12+
read<T extends IDataConnector>(
13+
connectorId: string,
14+
appRef: string,
15+
): Promise<T>;
16+
create<T extends IDataConnector>(
17+
newConnector: Partial<T>,
18+
appRef: string,
19+
): Promise<T>;
20+
update<T extends IDataConnector>(
21+
entity: AtLeast<T, 'id'>,
22+
appRef: string,
23+
): Promise<T>;
24+
}
25+
export interface IDataConnectorsOptions {
26+
client: IRestClient;
27+
}
28+
29+
export class DataConnectors implements IDataConnectors {
30+
private readonly _client: IRestClient;
31+
32+
private readonly APPS_URL = '/apps';
33+
private readonly DATA_CONNECTORS_URL = '/dataconnectors';
34+
35+
constructor(options: IDataConnectorsOptions) {
36+
this._client = options.client;
37+
}
38+
39+
private _makeBaseUrl(appRef: string) {
40+
return `${this.APPS_URL}/${appRef}${this.DATA_CONNECTORS_URL}`;
41+
}
42+
43+
private _makeEntityUrl(connectorId: string, appRef: string) {
44+
return `${this._makeBaseUrl(appRef)}/${connectorId}`;
45+
}
46+
47+
public async create<T extends IDataConnector>(
48+
newConnector: Partial<T>,
49+
appRef: string,
50+
): Promise<T> {
51+
return await this._client.post(this._makeBaseUrl(appRef), newConnector);
52+
}
53+
54+
public async read<T extends IDataConnector>(
55+
connectorId: string,
56+
appRef: string,
57+
): Promise<T> {
58+
return await this._client.get<T>(this._makeEntityUrl(connectorId, appRef));
59+
}
60+
61+
public async list<T extends IDataConnector>(appRef: string): Promise<T[]> {
62+
let response = await this._client.get<IPaginatedResponse<T>>(
63+
this._makeBaseUrl(appRef),
64+
);
65+
66+
return response.results;
67+
}
68+
69+
public async update<T extends IDataConnector>(
70+
payload: AtLeast<T, 'id'>,
71+
appRef: string,
72+
): Promise<T> {
73+
return await this._client.put(
74+
this._makeEntityUrl(payload.id, appRef),
75+
payload,
76+
);
77+
}
78+
79+
public async delete(
80+
connectorId: string,
81+
appRef: string,
82+
): Promise<IDeleteResponse> {
83+
let response: IDeleteResponse = await this._client.delete(
84+
this._makeEntityUrl(connectorId, appRef),
85+
);
86+
87+
if (response.nrOfItems === 0) {
88+
return Promise.reject(response);
89+
}
90+
91+
return response;
92+
}
93+
}

src/data-connectors/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { DataConnectors, IDataConnectors } from './data-connectors';

src/entities/data-connector-type.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export enum DataConnectorType {
2+
Kafka = 'kafka',
3+
}

src/entities/data-connector.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { DataConnectorType } from './data-connector-type';
2+
3+
export interface IDataConnector {
4+
type: DataConnectorType;
5+
id: string;
6+
dataProcessingMethod?: string;
7+
disabled: boolean;
8+
}
9+
10+
export interface IKafkaDataConnector extends IDataConnector {
11+
server: string;
12+
port: number;
13+
ssl: boolean;
14+
sslConfig?: IDataConnectorSSLConfig;
15+
topic: string;
16+
}
17+
18+
export interface IDataConnectorSSLConfig {
19+
server: {
20+
certificate: string;
21+
};
22+
client: {
23+
certificate: string;
24+
key: string;
25+
password?: string;
26+
};
27+
}

src/entities/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export { IAppProfile } from './app-profile';
1212
export { IAuthData } from './auth-data';
1313
export { ConnectionStatus } from './connection-status';
1414
export { ICredentials } from './credentials';
15+
export {
16+
IDataConnector,
17+
IDataConnectorSSLConfig,
18+
IKafkaDataConnector,
19+
} from './data-connector';
20+
export { DataConnectorType } from './data-connector-type';
1521
export { IDevice } from './device';
1622
export { IDeviceProfile } from './device-profile';
1723
export { EntityStatus } from './entity-status';

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export { AppProfiles, IAppProfiles } from './app-profiles';
33
export { Apps, IApps } from './apps';
44
export { Auth, IAuth } from './auth';
55
export { ICredentialsStore } from './credentials';
6+
export { DataConnectors, IDataConnectors } from './data-connectors';
67
export { DeviceProfiles, IDeviceProfiles } from './device-profiles';
78
export { Devices, IDevices } from './devices';
89
export { IDisposable } from './disposable';

src/instance.ts

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AppProfiles, IAppProfiles } from './app-profiles';
33
import { Apps, IApps } from './apps';
44
import { Auth, IAuth } from './auth';
55
import { CredentialsStore, ICredentialsStore } from './credentials';
6+
import { DataConnectors, IDataConnectors } from './data-connectors';
67
import { DeviceProfiles, IDeviceProfiles } from './device-profiles';
78
import { Devices, IDevices } from './devices';
89
import { IEnvConfig } from './entities';
@@ -20,6 +21,7 @@ export interface IPlatform {
2021
apps: IApps;
2122
appProfiles: IAppProfiles;
2223
apiClients: IApiClients;
24+
dataConnectors: IDataConnectors;
2325
}
2426

2527
let platform: IPlatform;
@@ -61,6 +63,9 @@ export async function bootstrap(env: IEnvConfig): Promise<IPlatform> {
6163
apiClients: new ApiClients({
6264
client: restClient,
6365
}),
66+
dataConnectors: new DataConnectors({
67+
client: restClient,
68+
}),
6469
};
6570

6671
return platform;

src/utility-types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type AtLeast<T, K extends keyof T> = Partial<T> & Pick<T, K>;

0 commit comments

Comments
 (0)