@kissflow/lowcode-client-sdk 1.0.0 → 1.0.2-0.beta.1

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.
@@ -0,0 +1,65 @@
1
+
2
+ declare class Form {
3
+ type: string
4
+ toJSON(): any;
5
+ getField(fieldId: string): any;
6
+ updateField(args: object): any;
7
+ getTable(tableId: string): Table;
8
+ }
9
+ declare class Table {
10
+ toJSON(): any;
11
+ getRows(): TableForm[];
12
+ getRow(rowId: string): TableForm;
13
+ addRow(rowObject: object): any;
14
+ addRows(rows: [object]): any;
15
+ deleteRow(rowId: string): any;
16
+ deleteRows(rows: [string]): any;
17
+ }
18
+ declare class TableForm {
19
+ type: string
20
+ getParent(): Form;
21
+ toJSON(): any;
22
+ getField(fieldId: string): any;
23
+ updateField(args: object): any;
24
+ }
25
+ declare class Client {
26
+ showInfo(message: string): any;
27
+ showConfirm(args: {
28
+ title: string;
29
+ content: string;
30
+ okText: string;
31
+ cancelText: string;
32
+ }): any;
33
+ redirect(url: string): any;
34
+ }
35
+ declare class Formatter {
36
+ toDate(date: string): any;
37
+ toDateTime(date: string): any;
38
+ toNumber(value: string): any;
39
+ toCurrency(value: string, currencyCode: string): any;
40
+ toBoolean(value: string): any;
41
+ }
42
+ declare class kf {
43
+ static context: Form
44
+ static client: Client
45
+ static formatter: Formatter
46
+ static user: userObject
47
+ static account: accountObject
48
+ api(url: string, args?: {
49
+ headers: object;
50
+ }): Promise<any>;
51
+ }
52
+ declare type userObject = {
53
+ _id: string;
54
+ Name: string;
55
+ Email: string;
56
+ Role: string;
57
+ };
58
+
59
+ declare type accountObject = {
60
+ _id: string;
61
+ };
62
+
63
+ declare type environmentObject = {
64
+ isMobile: boolean
65
+ }
@@ -0,0 +1,193 @@
1
+ {
2
+ "lowcode": [
3
+ {
4
+ "label": "get app variable",
5
+ "documentation": "Get value of the global variable",
6
+ "insertText": "let variableName = await kf.app.getVariable(\"${1:variableId}\")"
7
+ },
8
+ {
9
+ "label": "set app variable",
10
+ "documentation": "Sets a new value to the global variable",
11
+ "insertText": "kf.app.setVariable(\"${1:variableId}\", \"${2:newValue}\")"
12
+ },
13
+ {
14
+ "label": "open or navigate page",
15
+ "documentation": "Navigate to another page",
16
+ "insertText": "kf.app.openPage(\"${1:pageId}\", { inputParam1: \"value1\" })"
17
+ },
18
+ {
19
+ "label": "evaluate decision table",
20
+ "documentation": "Evaluates the provided data and returns back the matched output",
21
+ "insertText": "let decisionTableInstance = kf.app.getDecisionTable(\"${1:flowId}\");\n let decisionOutput = await decisionTableInstance.evaluate({ conditionField1: \"value\", conditionField2: \"value\" });"
22
+ },
23
+ {
24
+ "label": "get local variable",
25
+ "documentation": "Get value of the local variable",
26
+ "insertText": "let variableName = await kf.app.page.getVariable(\"${1:variableId}\")"
27
+ },
28
+ {
29
+ "label": "set local variable",
30
+ "documentation": "Sets specified variable to new value in page scope",
31
+ "insertText": "kf.app.page.setVariable(\"${1:variableId}\", \"${2:newValue}\")"
32
+ },
33
+ {
34
+ "label": "get input parameter",
35
+ "documentation": "Get specific input parameter of the page",
36
+ "insertText": "let value = await kf.app.page.getParameter(\"${1:parameterId}\"); "
37
+ },
38
+ {
39
+ "label": "get all input parameters",
40
+ "documentation": "Get all input parameters in the page",
41
+ "insertText": "let allParams = await kf.app.page.getAllParameters();"
42
+ },
43
+ {
44
+ "label": "open a popup",
45
+ "documentation": "Opens a popup in the page",
46
+ "insertText": "kf.app.page.openPopup(\"${1:popupId}\", { popupParam1: \"value\" });"
47
+ },
48
+ {
49
+ "label": "get component in page",
50
+ "documentation": "Get the specified component instance from the current page",
51
+ "insertText": "let componentInstance = await kf.app.page.getComponent(\"${1:componentId}\")"
52
+ },
53
+ {
54
+ "label": "refresh the component",
55
+ "documentation": "Refreshes the component",
56
+ "insertText": "componentInstance.refresh()"
57
+ },
58
+ {
59
+ "label": "hide the component",
60
+ "documentation": "Hides the component from page",
61
+ "insertText": "componentInstance.hide()"
62
+ },
63
+ {
64
+ "label": "show the component",
65
+ "documentation": "Shows the hidden component from page",
66
+ "insertText": "componentInstance.show()"
67
+ },
68
+ {
69
+ "label": "set active tab",
70
+ "documentation": "Sets the specified tab index as active - works only for the tab component",
71
+ "insertText": "// sets 2nd tab as active\ncomponentInstance.setActiveTab(${1:2})"
72
+ },
73
+ {
74
+ "label": "set selected item",
75
+ "documentation": "Sets the specified instance as selected item - works only for master detail component",
76
+ "insertText": "componentInstance.setSelectedItem(\"${1:instanceId}\")"
77
+ },
78
+ {
79
+ "label": "get popup parameter",
80
+ "documentation": "Get specific parameter in the popup",
81
+ "insertText": "let value = await kf.app.page.popup.getParameter(\"${1:parameterId}\"); "
82
+ },
83
+ {
84
+ "label": "get all popup parameters",
85
+ "documentation": "Get all parameters in the popup as object",
86
+ "insertText": "let allParams = await kf.app.page.popup.getAllParameters();"
87
+ },
88
+ {
89
+ "label": "close active popup",
90
+ "documentation": "Closes the active popup in the page",
91
+ "insertText": "kf.app.page.popup.close()"
92
+ },
93
+ {
94
+ "label": "get instance id",
95
+ "documentation": "Get the instance id from event arguments",
96
+ "insertText": "kf.eventParameters._id"
97
+ },
98
+ {
99
+ "label": "get activity instance id",
100
+ "documentation": "Get the activity instance id from event arguments",
101
+ "insertText": "kf.eventParameters._activity_instance_id"
102
+ }
103
+ ],
104
+ "nocode": [
105
+ {
106
+ "label": "get field value",
107
+ "documentation": "Get value of a field in form",
108
+ "insertText": "let fieldValue = await kf.context.getField(\"${1:fieldId}\");"
109
+ },
110
+ {
111
+ "label": "set field value",
112
+ "documentation": "Set value of a field in form",
113
+ "insertText": "kf.context.updateField({\"${1:fieldId}\": \"${2:value}\"});"
114
+ },
115
+ {
116
+ "label": "set field value - bulk",
117
+ "documentation": "Set value of a field in form",
118
+ "insertText": "let payload = { \"fieldId\": \"value\", \"fieldId2\": \"value2\" };\nkf.context.updateField(payload);"
119
+ },
120
+ {
121
+ "label": "get form json",
122
+ "documentation": "Returns whole data of current form in json format",
123
+ "insertText": "let formJSON = await kf.context.getJSON();"
124
+ },
125
+ {
126
+ "label": "get table instance",
127
+ "documentation": "Get instance of table, which can be further used to add or delete rows",
128
+ "insertText": "let tableInstance = kf.context.getTable(\"${1:tableId}\");"
129
+ },
130
+ {
131
+ "label": "add a row in table",
132
+ "documentation": "Appends a row entry to table",
133
+ "insertText": "let rowDetails = { \"columnId1\": \"value1\", \"columnId2\": \"value2\" };\ntableInstance.addRow(rowDetails)"
134
+ },
135
+ {
136
+ "label": "get table row",
137
+ "documentation": "Returns all columns with values in specified row",
138
+ "insertText": "tableInstance.getRow(\"${1:rowId}\")"
139
+ },
140
+ {
141
+ "label": "get table json",
142
+ "documentation": "Returns all rows & columns data inside table in json format",
143
+ "insertText": "let tableJSON = await kf.context.getJSON();"
144
+ }
145
+ ],
146
+ "common": [
147
+ {
148
+ "label": "showinfo",
149
+ "documentation": "Shows toast information",
150
+ "insertText": "kf.client.showInfo(\"${1:message}\")"
151
+ },
152
+ {
153
+ "label": "api call",
154
+ "documentation": "Makes an API call to any kissflow rest api end points",
155
+ "insertText": "kf.api(`/${1:url}`)\n.then((resp) => {${2}})\n.catch((err) => {${3}})"
156
+ },
157
+ {
158
+ "label": "get account id",
159
+ "documentation": "Retrieves the acccount id",
160
+ "insertText": "kf.account._id"
161
+ },
162
+ {
163
+ "label": "get dataform item",
164
+ "documentation": "API call to get dataform item",
165
+ "insertText": "kf.api(`/form/2/${kf.account._id}/${1:formId}/${2:instanceId}`)\n.then((resp) => {${3}})\n.catch((err) => {${4}})"
166
+ },
167
+ {
168
+ "label": "update dataform item",
169
+ "documentation": "API call to update dataform item",
170
+ "insertText": "let payload = {};\nkf.api(`/form/2/${kf.account._id}/${1:formId}/${2:instanceId}`, {\n\tmethod: \"POST\",\n\tbody: JSON.stringify(payload)\n})\n.then((resp) => {${4}})\n.catch((err) => {${5}})"
171
+ },
172
+ {
173
+ "label": "delete dataform item",
174
+ "documentation": "API call to delete dataform item",
175
+ "insertText": "let payload = {};\nkf.api(`/form/2/${kf.account._id}/${1:formId}/${2:instanceId}`, { method: \"DELETE\" })\n.then((resp) => {${3}})\n.catch((err) => {${4}})"
176
+ },
177
+ {
178
+ "label": "create new dataform item",
179
+ "documentation": "API call to create new dataform item",
180
+ "insertText": "let payload = {};\nkf.api(`/form/2/${kf.account._id}/${1:formId}/`,{\n\tmethod: \"POST\",\n\tbody: JSON.stringify(payload)\n})\n.then((resp) => {${2}})\n.catch((err) => {${3}})"
181
+ },
182
+ {
183
+ "label": "create new case item",
184
+ "documentation": "API call to create new case item",
185
+ "insertText": "let payload = {};\nkf.api(`/case/2/${kf.account._id}/${1:caseId}/`, {\n\tmethod: \"POST\",\n\tbody: JSON.stringify(payload)\n})\n.then((resp) => {${2}})\n.catch((err) => {${3}})"
186
+ },
187
+ {
188
+ "label": "create new process item",
189
+ "documentation": "API call to create new process item",
190
+ "insertText": "let payload = {}:\nkf.api(`/process/2/${kf.account._id}/${1:processId}/`, {\n\tmethod: \"POST\",\n\tbody: JSON.stringify(payload)\n})\n.then((resp) => {${2}})\n.catch((err) => {${3}})"
191
+ }
192
+ ]
193
+ }
package/dist/worker.js ADDED
@@ -0,0 +1,40 @@
1
+ import KF_LC_SDK from "./kf.lowcodeworkersdk.es.js";
2
+ import KF_NC_SDK from "./kf.nocodeworkersdk.es.js";
3
+
4
+ const SDK_KIND = {
5
+ LOWCODE: "lowcode",
6
+ NOCODE: "nocode"
7
+ };
8
+
9
+ onmessage = async function (e) {
10
+ if (!self.kf) {
11
+ let { kind = SDK_KIND.LOWCODE } = e.data?.executionContext;
12
+ let lib = KF_LC_SDK;
13
+ if (kind === SDK_KIND.NOCODE) {
14
+ lib = KF_NC_SDK;
15
+ }
16
+ self.kf = lib(e?.data.executionContext);
17
+ }
18
+
19
+ if (e.data?.eventParameters) {
20
+ let { eventParameters } = e.data;
21
+ if (eventParameters) {
22
+ self.kf.eventParameters = { ...eventParameters };
23
+ }
24
+ }
25
+
26
+ if (e.data.command !== "EXECUTE") return;
27
+ const func = new Function(`
28
+ return (async () => {
29
+ ${e.data.code}
30
+ })()`);
31
+
32
+ (async function () {
33
+ await func();
34
+ postMessage({
35
+ _id: Math.floor(Date.now() + 999).toString(36),
36
+ command: "RETURN",
37
+ data: {}
38
+ });
39
+ })();
40
+ };
package/package.json CHANGED
@@ -1,40 +1,45 @@
1
1
  {
2
- "name": "@kissflow/lowcode-client-sdk",
3
- "version": "1.0.0",
4
- "description": "JavaScript SDK for developing over the Kissflow lowcode platform",
5
- "main": "dist/kflowcode.sdk.js",
6
- "types": "dist/index.d.ts",
7
- "scripts": {
8
- "start": "npm run server",
9
- "server": "http-server .",
10
- "customBuild": "node custom.build.js",
11
- "build": "npm run customBuild",
12
- "build:watch": "webpack --watch",
13
- "prepare": "npm run build",
14
- "serve": "webpack serve"
15
- },
16
- "repository": {
17
- "type": "git",
18
- "url": "git+https://github.com/kissflow/lcnc-sdk-js.git"
19
- },
20
- "keywords": [],
21
- "author": "Vivek Madurai<vivek@kissflow.com>",
22
- "license": "MIT",
23
- "bugs": {
24
- "url": "https://github.com/kissflow/lcnc-sdk-js/issues"
25
- },
26
- "homepage": "https://github.com/kissflow/lcnc-sdk-js#readme",
27
- "devDependencies": {
28
- "html-webpack-plugin": "^5.3.1",
29
- "http-server": "^0.12.3",
30
- "ts-loader": "^9.2.5",
31
- "typescript": "^4.3.5",
32
- "webpack": "^5.52.1",
33
- "webpack-cli": "^4.8.0",
34
- "webpack-dev-server": "^3.11.2"
35
- },
36
- "dependencies": {
37
- "nanoid": "^3.1.30",
38
- "ts-file-parser": "0.0.21"
39
- }
40
- }
2
+ "name": "@kissflow/lowcode-client-sdk",
3
+ "version": "1.0.20.beta.1",
4
+ "description": "JavaScript SDK for developing over the Kissflow lowcode platform",
5
+ "types": "dist/index.d.ts",
6
+ "files": [
7
+ "dist/"
8
+ ],
9
+ "main": "./dist/kfsdk.umd.js",
10
+ "module": "./dist/kfsdk.es.js",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/kfsdk.es.js",
14
+ "require": "./dist/kfsdk.umd.js"
15
+ },
16
+ "./lowcode": {
17
+ "import": "./dist/kf.lowcodeworkersdk.es.js"
18
+ }
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/kissflow/lcnc-sdk-js.git"
23
+ },
24
+ "keywords": [],
25
+ "author": "Vivek Madurai<vivek@kissflow.com>",
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/kissflow/lcnc-sdk-js/issues"
29
+ },
30
+ "homepage": "https://github.com/kissflow/lcnc-sdk-js#readme",
31
+ "devDependencies": {
32
+ "ts-file-parser": "0.0.21",
33
+ "typescript": "^4.3.5",
34
+ "vite": "^2.9.8"
35
+ },
36
+ "dependencies": {
37
+ "nanoid": "^3.1.30"
38
+ },
39
+ "scripts": {
40
+ "start": "vite serve",
41
+ "customBuild": "node custom.build.mjs",
42
+ "build": "pnpm run customBuild",
43
+ "serve": "http-server -p 8080"
44
+ }
45
+ }
package/custom.build.js DELETED
@@ -1,77 +0,0 @@
1
- const tsFileStruct = require("ts-file-parser");
2
- const fs = require("fs");
3
- let classMappings = {
4
- Page: { name: "Page" },
5
- Application: { name: "Application" },
6
- Client: { name: "Client" },
7
- Component: { name: "Component" },
8
- Form: { name: "Form" },
9
- Formatter: { name: "Formatter" },
10
- LowcodeSDK: { name: "kf", staticDeclarations: true }
11
- };
12
-
13
- const exec = require("child_process").exec;
14
- runCommand("webpack", () => {
15
- runCommand("tsc", transfromTypings);
16
- });
17
-
18
- function runCommand(command, callBack = null) {
19
- const execCmd = exec(command, () => {
20
- callBack && callBack();
21
- });
22
- execCmd.stdout.on("data", (data) => {
23
- console.log(data);
24
- });
25
- execCmd.stderr.on("data", (data) => {
26
- console.error(data);
27
- });
28
- }
29
-
30
- function transfromTypings() {
31
- const filePath = "./dist/index.d.ts";
32
- let srcFile = fs.readFileSync(filePath).toString();
33
- let srcCode = tsFileStruct.parseStruct(srcFile, {}, filePath);
34
-
35
- let allClasses = srcCode.classes;
36
- let func = "";
37
- let toWrite = ``;
38
-
39
- for (let i = 0; i < allClasses.length; i++) {
40
- if (Object.keys(classMappings).includes(allClasses[i].name)) {
41
- let _class = allClasses[i];
42
- toWrite += `\ndeclare class ${
43
- classMappings[_class.name].name
44
- } { \n`;
45
-
46
- // fields on Class
47
- for (let i = 0; i < _class.fields.length; i++) {
48
- // if (_class.fields[i].type.modulePath) {
49
- let className = _class.fields[i].type.typeName;
50
- let fieldName = _class.fields[i].name;
51
- // console.log(_class.fields[i]);
52
- toWrite += `\t${
53
- classMappings[_class.name].staticDeclarations
54
- ? "static "
55
- : ""
56
- }${fieldName}: ${className} \n`;
57
- // }
58
- }
59
-
60
- //methods of Class
61
- for (j = 0; j < _class.methods.length; j++) {
62
- func = _class.methods[j].text.trim().split("\n\t").join(" ");
63
- toWrite += `\t${func} \n`;
64
- // if (
65
- // typeof _class.methods[j].returnType === "object" &&
66
- // method.returnType.modulePath
67
- // ) {
68
- // childClasses.push(method.returnType.typeName);
69
- // }
70
- }
71
- toWrite += `}`;
72
- }
73
- }
74
- fs.writeFile("./dist/global.types.d.ts", toWrite, function (err) {
75
- if (err) return console.log(err);
76
- });
77
- }
@@ -1,54 +0,0 @@
1
-
2
- declare class Page {
3
- _id: string
4
- getParameter(key: string): string | object;
5
- getVariable(key: string): string | object;
6
- setVariable(key: string, value: any): string | object;
7
- openPopup(pageId: string, inputParams: object, popupProperties: {
8
- w: number;
9
- h: number;
10
- }): string | object;
11
- onClose(callback: Function): void;
12
- }
13
- declare class Application {
14
- page: Page
15
- getVariable(key: string): string | object;
16
- setVariable(key: string | object, value: any): string | object;
17
- openPage(pageId: string, pageParams: object): string | object;
18
- }
19
- declare class Client {
20
- showInfo(message: string): string | object;
21
- showConfirm(args: {
22
- title: string;
23
- content: string;
24
- okText: string;
25
- cancelText: string;
26
- }): string | object;
27
- redirect(url: string): string | object;
28
- }
29
- declare class Component {
30
- id: string
31
- refresh(): string | object;
32
- }
33
- declare class Form {
34
- getField(fieldId: string): string | object;
35
- updateField(args: object): string | object;
36
- addTableRow(tableId: string, rowObject: object): string | object;
37
- }
38
- declare class Formatter {
39
- toKfDate(date: string): string | object;
40
- toKfDateTime(date: string): string | object;
41
- toKfNumber(value: string): string | object;
42
- toKfCurrency(value: string, currencyCode: string): string | object;
43
- toBoolean(value: string): string | object;
44
- }
45
- declare class kf {
46
- static currentForm: Form
47
- static client: Client
48
- static formatter: Formatter
49
- static app: Application
50
- api(url: string, args?: {}): string | object;
51
- watchParams(func: (data: any) => any): void;
52
- getContext(): string | object;
53
- getComponent(componentId: string): Component;
54
- }
package/dist/index.html DELETED
@@ -1,23 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>Kissflow LCNC SDK</title>
7
- </head>
8
- <body>
9
- <h1 id="title">Kissflow SDK Check</h1>
10
- <iframe id="component1" src="http://localhost:8080" width="500px" height="500px">
11
- <p>Your browser does not support iframes.</p>
12
- </iframe>
13
-
14
- <iframe id="component2" src="http://localhost:3000" width="500px" height="500px">
15
- <p>Your browser does not support iframes.</p>
16
- </iframe>
17
- <script defer src="kflowcode.sdk.js"></script></body>
18
- <script type="module">
19
- import MockAPI from './test/mock/api.js';
20
- import LCNCHandler from './test/lcnc-handler.js';
21
- LCNCHandler();
22
- </script>
23
- </html>