@keragon/connector-cli 0.0.1 → 0.0.2

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.
@@ -7,19 +7,19 @@
7
7
  const obj = {
8
8
  id: componentId,
9
9
  title: formatComponentTitle(componentName),
10
- description: desc,
10
+ description: desc ?? "",
11
11
  type: "action",
12
12
  sdkVersion: "0.0.1"
13
13
  };
14
14
 
15
- if (typeof alert !== 'undefined') {
15
+ if (alert) {
16
16
  obj.alerts = [{
17
17
  type: "info",
18
18
  content: `More info in [article](https://go.keragon.com/${componentName})`
19
19
  }];
20
20
  }
21
21
 
22
- if (typeof http !== 'undefined') {
22
+ if (http) {
23
23
  obj.request = {
24
24
  config: {
25
25
  method: "get",
@@ -28,7 +28,7 @@
28
28
  };
29
29
  }
30
30
 
31
- if (typeof pagination !== 'undefined') {
31
+ if (pagination) {
32
32
  obj.pagination = {
33
33
  strategy: pagination,
34
34
  maxItems: "${ .inputs.maxItems // 250 }"
@@ -54,7 +54,7 @@
54
54
  }
55
55
  }
56
56
 
57
- if (typeof errorHandler !== 'undefined') {
57
+ if (errorHandler) {
58
58
  obj.response = {
59
59
  errorHandlers: [{
60
60
  condition: "${ .response.status != 200 }",
@@ -64,7 +64,7 @@
64
64
  };
65
65
  }
66
66
 
67
- if (typeof inputs !== 'undefined') {
67
+ if (inputs) {
68
68
  obj.inputs = {
69
69
  "$schema": "https://json-schema.org/draft/2020-12/schema",
70
70
  type: "object",
@@ -83,7 +83,7 @@
83
83
  }
84
84
  };
85
85
 
86
- if (typeof pagination !== 'undefined') {
86
+ if (pagination) {
87
87
  obj.inputs.properties.maxItems = {
88
88
  type: "number",
89
89
  title: "Max items",
@@ -92,7 +92,7 @@
92
92
  }
93
93
  }
94
94
 
95
- if (typeof outputs !== 'undefined') {
95
+ if (outputs) {
96
96
  obj.outputs = {
97
97
  "$schema": "https://json-schema.org/draft/2020-12/schema",
98
98
  type: "array",
@@ -0,0 +1,36 @@
1
+ import {
2
+ Credentials
3
+ } from '@keragon/connector-sdk';
4
+ import app from '../src';
5
+ import <%= className %> from '../src/components/<%= name %>/<%= name %>';
6
+ const { definition, ctor: <%= firstLetterUpperCase(connectorName) %> } = app;
7
+
8
+ const setupTest = ({
9
+ credentials = {
10
+ authScheme: {
11
+ id: 'com.keragon.<%= connectorName %>.environments.prod.authSchemes.custom',
12
+ },
13
+ }
14
+ }: {
15
+ credentials?: Credentials
16
+ }) => {
17
+ const <%= connectorName %> = new <%= firstLetterUpperCase(connectorName) %>({
18
+ definition, credentials,
19
+ });
20
+ const component = <%= connectorName %>.constructComponent({ componentId: 'com.keragon.<%= connectorName %>.<%= name %>' }) as <%= className %>;
21
+
22
+ return { <%= connectorName %>, component, credentials }
23
+ };
24
+
25
+ describe('Component: <%= className %> should', () => {
26
+ it('implement run', async () => {
27
+ // Arrange
28
+ const { component } = setupTest({});
29
+
30
+ // Act
31
+ const outputs = await component.run({});
32
+
33
+ // Assert
34
+ expect(outputs).toBe({});
35
+ });
36
+ });
@@ -0,0 +1,34 @@
1
+ import {
2
+ <%= isHttp ? 'HttpApp, HttpComponent,' : 'App, Component,' %>
3
+ RunFunctionArgs,
4
+ RunFunctionReturnType,
5
+ } from "@keragon/connector-sdk";
6
+ <%- isHttp ? "import { AxiosRequestConfig } from 'axios';" : '' %>
7
+
8
+ export default class <%= className %> extends <%= isHttp ? 'HttpComponent' : 'Component' %><<%= isHttp ? 'HttpApp' : 'App' %>> {
9
+ <%_ if (isHttp) { _%>
10
+ override async onRequest({
11
+ requestConfig,
12
+ }: {
13
+ requestConfig: AxiosRequestConfig;
14
+ }): Promise<AxiosRequestConfig> {
15
+ const { method, url, headers, data: inputData } = await super.onRequest({ requestConfig });
16
+
17
+ throw new Error('Change default implementation of onRequest() method');
18
+
19
+ return {
20
+ method,
21
+ url,
22
+ headers,
23
+ data: {
24
+ ...inputData,
25
+ },
26
+ };
27
+ }
28
+ <%_ } else { _%>
29
+ override async run({ inputs }: RunFunctionArgs): Promise<RunFunctionReturnType> {
30
+ if (!inputs) throw new Error(`Component ${this.definition.id} run() received no inputs`);
31
+ throw new Error('Change default implementation of run() method');
32
+ }
33
+ <%_ } _%>
34
+ }
@@ -4,7 +4,7 @@
4
4
  "description": "<%= desc %>",
5
5
  "type": "trigger",
6
6
  "sdkVersion": "0.0.1"
7
- <% if (typeof alert !== 'undefined') { %>
7
+ <% if (alert) { %>
8
8
  ,"alerts": [{
9
9
  "type": "info",
10
10
  "content": "Due to vendor limitations you can have only one polling trigger"
@@ -24,7 +24,7 @@
24
24
  "processOutputs": "${ . | sort_by(.created_time) | reverse }"
25
25
  }
26
26
  }
27
- <% if (typeof inputs !== 'undefined') { %>
27
+ <% if (inputs) { %>
28
28
  ,"inputs": {
29
29
  "$schema": "https://json-schema.org/draft/2020-12/schema",
30
30
  "type": "object",
@@ -4,13 +4,13 @@
4
4
  "description": "<%= desc %>",
5
5
  "type": "trigger",
6
6
  "sdkVersion": "0.0.1"
7
- <% if (typeof alert !== 'undefined') { %>
7
+ <% if (alert) { %>
8
8
  ,"alerts": [{
9
9
  "type": "info",
10
10
  "content": "Please follow the [article](https://go.keragon.com/<%= componentName %>) to set up the trigger"
11
11
  }]
12
12
  <% } %>
13
- <% if (typeof http !== 'undefined') { %>
13
+ <% if (http) { %>
14
14
  ,"request": {
15
15
  "config": {
16
16
  "method": "get",
@@ -18,7 +18,7 @@
18
18
  }
19
19
  }
20
20
  <% } %>
21
- <% if (typeof inputs !== 'undefined') { %>
21
+ <% if (inputs) { %>
22
22
  ,"inputs": {
23
23
  "$schema": "https://json-schema.org/draft/2020-12/schema",
24
24
  "type": "object",