@kissflow/lowcode-client-sdk 1.0.1 → 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.
Files changed (48) hide show
  1. package/README.md +392 -95
  2. package/dist/index.d.ts +252 -76
  3. package/dist/kf.lowcodeworkersdk.es.js +649 -0
  4. package/dist/kf.nocodeworkersdk.es.js +454 -0
  5. package/dist/kfsdk.es.js +467 -0
  6. package/dist/kfsdk.umd.js +1 -0
  7. package/dist/lowcode.d.ts +308 -0
  8. package/dist/lowcode.types.d.ts +105 -0
  9. package/dist/nocode.d.ts +305 -0
  10. package/dist/nocode.types.d.ts +65 -0
  11. package/dist/snippets.json +193 -0
  12. package/dist/worker.js +40 -0
  13. package/package.json +44 -39
  14. package/custom.build.js +0 -79
  15. package/dist/app.js +0 -48
  16. package/dist/base.js +0 -171
  17. package/dist/client.js +0 -44
  18. package/dist/component.js +0 -35
  19. package/dist/constants.js +0 -40
  20. package/dist/form.js +0 -44
  21. package/dist/formatter.js +0 -54
  22. package/dist/global.types.d.ts +0 -54
  23. package/dist/index.html +0 -23
  24. package/dist/index.js +0 -7
  25. package/dist/kflowcode.sdk.js +0 -822
  26. package/dist/kflowcode.sdk.js.map +0 -1
  27. package/dist/kflowcode.sdk.module.js +0 -808
  28. package/dist/kflowcode.sdk.module.js.map +0 -1
  29. package/dist/lowcode.sdk.js +0 -56
  30. package/dist/page.js +0 -62
  31. package/id +0 -55
  32. package/index.html +0 -23
  33. package/src/app.ts +0 -31
  34. package/src/base.ts +0 -109
  35. package/src/client.ts +0 -28
  36. package/src/component.ts +0 -15
  37. package/src/constants.ts +0 -45
  38. package/src/form.ts +0 -21
  39. package/src/formatter.ts +0 -35
  40. package/src/index.ts +0 -7
  41. package/src/lowcode.sdk.ts +0 -41
  42. package/src/page.ts +0 -51
  43. package/test/lcnc-handler.js +0 -45
  44. package/test/mock/api.js +0 -16
  45. package/test/mock/id.js +0 -55
  46. package/tsconfig.json +0 -7
  47. package/tsconfig.types.json +0 -18
  48. package/webpack.config.js +0 -63
@@ -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.1",
4
- "description": "JavaScript SDK for developing over the Kissflow lowcode platform",
5
- "main": "dist/index.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,79 +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", () => {
16
- runCommand("tsc -p tsconfig.types.json", transfromTypings);
17
- });
18
- });
19
-
20
- function runCommand(command, callBack = null) {
21
- const execCmd = exec(command, () => {
22
- callBack && callBack();
23
- });
24
- execCmd.stdout.on("data", (data) => {
25
- console.log(data);
26
- });
27
- execCmd.stderr.on("data", (data) => {
28
- console.error(data);
29
- });
30
- }
31
-
32
- function transfromTypings() {
33
- const filePath = "./dist/index.d.ts";
34
- let srcFile = fs.readFileSync(filePath).toString();
35
- let srcCode = tsFileStruct.parseStruct(srcFile, {}, filePath);
36
-
37
- let allClasses = srcCode.classes;
38
- let func = "";
39
- let toWrite = ``;
40
-
41
- for (let i = 0; i < allClasses.length; i++) {
42
- if (Object.keys(classMappings).includes(allClasses[i].name)) {
43
- let _class = allClasses[i];
44
- toWrite += `\ndeclare class ${
45
- classMappings[_class.name].name
46
- } { \n`;
47
-
48
- // fields on Class
49
- for (let i = 0; i < _class.fields.length; i++) {
50
- // if (_class.fields[i].type.modulePath) {
51
- let className = _class.fields[i].type.typeName;
52
- let fieldName = _class.fields[i].name;
53
- // console.log(_class.fields[i]);
54
- toWrite += `\t${
55
- classMappings[_class.name].staticDeclarations
56
- ? "static "
57
- : ""
58
- }${fieldName}: ${className} \n`;
59
- // }
60
- }
61
-
62
- //methods of Class
63
- for (j = 0; j < _class.methods.length; j++) {
64
- func = _class.methods[j].text.trim().split("\n\t").join(" ");
65
- toWrite += `\t${func} \n`;
66
- // if (
67
- // typeof _class.methods[j].returnType === "object" &&
68
- // method.returnType.modulePath
69
- // ) {
70
- // childClasses.push(method.returnType.typeName);
71
- // }
72
- }
73
- toWrite += `}`;
74
- }
75
- }
76
- fs.writeFile("./dist/global.types.d.ts", toWrite, function (err) {
77
- if (err) return console.log(err);
78
- });
79
- }
package/dist/app.js DELETED
@@ -1,48 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- exports.__esModule = true;
18
- exports.Application = void 0;
19
- var base_1 = require("./base");
20
- var page_1 = require("./page");
21
- var constants_1 = require("./constants");
22
- var Application = /** @class */ (function (_super) {
23
- __extends(Application, _super);
24
- function Application(props) {
25
- var _this = _super.call(this, {}) || this;
26
- _this.page = new page_1.Page({});
27
- return _this;
28
- }
29
- Application.prototype.getVariable = function (key) {
30
- return this._postMessageAsync(constants_1.LISTENER_CMDS.GET_APP_VARIABLE, {
31
- key: key
32
- });
33
- };
34
- Application.prototype.setVariable = function (key, value) {
35
- return this._postMessageAsync(constants_1.LISTENER_CMDS.SET_APP_VARIABLE, {
36
- key: key,
37
- value: value
38
- });
39
- };
40
- Application.prototype.openPage = function (pageId, pageParams) {
41
- return _super.prototype._postMessageAsync.call(this, constants_1.LISTENER_CMDS.OPEN_PAGE, {
42
- pageId: pageId,
43
- pageParams: pageParams
44
- });
45
- };
46
- return Application;
47
- }(base_1.BaseSDK));
48
- exports.Application = Application;