Skip to content

Commit fc45ed3

Browse files
committed
Added unit tests; readme modified; changed version in changelog
1 parent 603454e commit fc45ed3

16 files changed

+1008
-23
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.1.7 (August 30, 2021)
2+
* Added `PlatformApiRestClient` and `PlatformApiLogicClient` classes from `IPaaS-core-component`
3+
14
## 1.1.6 (July 29, 2021)
25
* Now `getAttachment` from `AttachmentProcessor` may retrieve items from `Maester`
36

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
- [ApiKeyRestClient](#ApiKeyRestClient)
1010
- [CookieRestClient](#CookieRestClient)
1111
- [OAuth2AuthorizationCodeRestClient](#OAuth2AuthorizationCodeRestClient)
12+
- [PlatformApiRestClient](#PlatformApiRestClient)
13+
- [PlatformApiLogicClient](#PlatformApiLogicClient)
1214
- [JSON Schema Converter](#JSON-Schema-Converter)
1315
- [JSON Transformation](#JSON-Transformation)
1416
- [Attachment Processor](#Attachment-Processor)
@@ -135,6 +137,49 @@ Handles both V1 and V2 of the NTLM Protocol.
135137
const Client = new NtlmRestClient(emitter, cfg);
136138
```
137139

140+
### PlatformApiRestClient
141+
[PlatformApiRestClient](https://github.com/elasticio/component-commons-library/blob/master/lib/authentication/PlatformApiRestClient.ts)
142+
class extends [BasicAuthRestClient](#BasicAuthRestClient) class.
143+
Implements method for checking of response correctness (like containment of status code, correct JSON content type of headers end other expected response fields).
144+
145+
#### constructor(emitter, cfg)
146+
- emitter - EIO emitting context.
147+
- cfg - configuration of EIO component object.
148+
149+
```
150+
const Client = new PlatformApiRestClient(emitter, cfg);
151+
```
152+
153+
### PlatformApiLogicClient
154+
[PlatformApiLogicClient](https://github.com/elasticio/component-commons-library/blob/master/lib/authentication/PlatformApiLogicClient.ts)
155+
class extends [PlatformApiRestClient](#PlatformApiRestClient) class.
156+
Contains useful methods to manipulate flow's state to set it either to active running or to inactive stopped, searching flows, workspaces, credentials and more.
157+
158+
#### constructor(emitter, cfg)
159+
- emitter - EIO emitting context.
160+
- cfg - configuration of EIO component object.
161+
162+
```
163+
const Client = new PlatformApiLogicClient(emitter, cfg);
164+
```
165+
166+
#### List of methods
167+
- fetchAllFlowsForWorkspace(options) - Fetch all flows for a given workspace
168+
- fetchAllCredentialsForWorkspace(options) - Fetch all credentials for a given workspace
169+
- fetchComponentsAccessibleFromContract(options) - Fetch All Components Accessible From a Given Workspace
170+
- splitParallelization(maxParallelization, splitFactor) - Helping method to calculate right number of parallel calls
171+
- fetchFlowList(options) - Fetches a list of flows
172+
- fetchWorkspaceList(options) - Fetch a list of all workspaces across all contracts for a user
173+
- fetchWorkspaceId(workspaceUniqueCriteria) - Given a set of unique criteria, find the workspace that matches
174+
- removeNonWritableProperties(flow, includeDataSamples) - Given a flow, remove the properties of the flow that are regularly changed by the system such as last executed time
175+
- fetchFlowId(flowUniqueCriteria) - Fetch flow bu it's unique criteria
176+
- fetchFlowById(id) - Fetch flow bu it's id
177+
- fetchFlowByNameAndWorkspaceId(flowName, workspaceId) -
178+
- changeFlowState(options) - Given a flow, change the flow to a given state (running, stopped, etc)
179+
- startFlow(flowId, options = {}) - sets the flow to active running state
180+
- stopFlow(flowId, options = {}) - sets the flow to inactive stopped state
181+
- hydrateFlow(options) - Hydrates the flow using removeNonWritableProperties method, but additionally enriches the flow with all data samples, credential names, command and component Id fields.
182+
138183
## JSON Schema Converter
139184
Contains tools for JSON metadata generation
140185

lib/authentication/PlatformApiLogicClient.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
1-
const mapLimit = require('async/mapLimit');
2-
const PlatformApiRestClient = require('./platformApiRestClient');
1+
import { mapLimit } from 'async/mapLimit';
2+
import { PlatformApiRestClient } from './PlatformApiRestClient';
33

44
async function sleep(amount) { await new Promise((r) => setTimeout(r, amount)); }
55

66
const DEFAULT_PARALLEL_PLATFORM_API_CALLS = process.env.PARALLEL_PLATFORM_API_CALLS || 20;
77
const DEFAULT_OBJECTS_PER_PAGE = process.env.DEFAULT_OBJECTS_PER_PAGE || 20;
88

99
interface AllFlowsForWorkspaceOptions {
10-
objectsPerPage?: number,
11-
parallelCalls?: number,
12-
workspaceId?: string,
13-
}
14-
15-
interface FlowListOptions {
16-
parallelCalls?: number,
17-
workspaceId?: string,
10+
objectsPerPage?: number;
11+
parallelCalls?: number;
12+
workspaceId?: string;
1813
}
1914

2015
interface WorkspaceListOptions {
21-
objectsPerPage?: number,
22-
parallelCalls?: number,
16+
objectsPerPage?: number;
17+
parallelCalls?: number;
2318
}
2419

25-
module.exports = class PlatformApiLogicClient extends PlatformApiRestClient {
20+
export class PlatformApiLogicClient extends PlatformApiRestClient {
21+
workspaceList: any;
2622
/**
2723
* Fetch all flows for a given workspace
2824
* @param {string} options.workspaceId Id of the workspace to search
@@ -406,7 +402,7 @@ module.exports = class PlatformApiLogicClient extends PlatformApiRestClient {
406402
const flowsForWS = await this.fetchAllFlowsForWorkspace({ workspaceId });
407403
const matchingFlows = flowsForWS.filter((wsFlow) => wsFlow.attributes.name === flowName);
408404
if (matchingFlows.length !== 1) {
409-
throw new Error(`Found ${matchingFlows.length} matching flow insted of 1`);
405+
throw new Error(`Found ${matchingFlows.length} matching flow instead of 1`);
410406
}
411407
return matchingFlows[0];
412408
}
@@ -582,4 +578,4 @@ module.exports = class PlatformApiLogicClient extends PlatformApiRestClient {
582578

583579
return flow;
584580
}
585-
};
581+
}

lib/authentication/PlatformApiRestClient.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
const { BasicAuthRestClient } = require('./BasicAuthRestClient');
2-
const removeTrailingSlash = require('remove-trailing-slash');
3-
const util = require('util');
1+
import { BasicAuthRestClient } from './BasicAuthRestClient';
2+
import removeTrailingSlash from 'remove-trailing-slash';
3+
import util from 'util';
44

5-
module.exports = class PlatformApiRestClient extends BasicAuthRestClient {
5+
export class PlatformApiRestClient extends BasicAuthRestClient {
6+
usingTaskUser: boolean;
67
constructor(emitter, cfg) {
78
if (!!cfg.email !== !!cfg.apiKey) {
89
throw new Error('Either both Email and API Key need to be provided or neither should be provided.');
@@ -44,4 +45,4 @@ module.exports = class PlatformApiRestClient extends BasicAuthRestClient {
4445
this.emitter.logger.trace(`Response statusCode: ${response.statusCode}, body: %j`, response.body);
4546
return response.body;
4647
}
47-
};
48+
}

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elastic.io/component-commons-library",
3-
"version": "1.1.6",
3+
"version": "1.1.7",
44
"description": "Library for most common component development cases",
55
"author": {
66
"name": "elastic.io GmbH",

0 commit comments

Comments
 (0)