@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
package/README.md CHANGED
@@ -1,80 +1,337 @@
1
- # _Kissflow LCNC JavaScript SDK_
2
-
3
- JavaScript SDK for developing over the Kissflow LCNC platform
1
+ # _Kissflow Lowcode JavaScript SDK_
4
2
 
3
+ JavaScript SDK for developing over the Kissflow lowcode platform
5
4
  ### Use as an `npm` module
6
5
 
7
- Install the SDK as a module: `npm i @kissflow/kf-sdk-js` Then import into your project:
8
-
6
+ Install the SDK as a module: `npm i @kissflow/lowcode-client-sdk` Then import into your project:
9
7
  ```js
10
- import KFLowcodeSDK from "@kissflow/lcnc-sdk-js";
11
- const kf = KFLowcodeSDK();
8
+ import KFSDK from "@kissflow/lowcode-client-sdk";
9
+ let kf;
10
+ (async function () {
11
+ kf = await KFSDK.initialize();
12
+ })();
12
13
  ```
13
-
14
+ > Note: Initializing Kf SDK in custom components returns a promise.
14
15
  ### Use as a `<script>` tag directly in HTML
15
16
 
16
17
  SDK can also be loaded directly into HTML by adding:
17
-
18
18
  ```html
19
- <script src="https://cdn.jsdelivr.net/npm/@kissflow/lowcode-client-sdk@1/dist/kflowcode.sdk.js"></script>
20
- <!-- or -->
21
- <script type="module" src="https://cdn.jsdelivr.net/npm/@kissflow/lowcode-client-sdk@1/dist/kflowcode.sdk.module.js"></script>
19
+ <script src="https://unpkg.com/@kissflow/lowcode-client-sdk@latest/dist/kfsdk.umd.js"></script>
22
20
  ```
21
+ Then SDK can be initialized as:
22
+ ```js
23
+ let kf;
24
+ window.onload = async function () {
25
+ kf = await window.kf.initialize();
26
+ };
27
+ ```
28
+
29
+ ### User and Account details
30
+ Details of authenticated user can be accessed as following
31
+ ```js
32
+ const { Name, Email, _id } = kf.user
33
+ ```
34
+ And account id can be accessed as `kf.account._id`
35
+
36
+ ### Fetch Api through sdk
37
+ Fetch any other kissflow api & external api using this method.
38
+ kf.api has header tokens by default for making authenticated kissflow api calls
39
+ > Note: This method has a limit of 10 seconds for an api call
40
+
41
+ ```js
42
+ kf.api(url, config).then((res) => {...})
43
+ // or
44
+ let resp = await kf.api(url, config)
45
+ ```
46
+
47
+ ## Table of contents
48
+ - [1. Context](#1-context)
49
+ - [Custom Components](#custom-component)
50
+ - [Form](#custom-component)
51
+ - [Form Table](#form-table)
52
+ - [Table Row](#table-row)
53
+ - [2. Client](#2-client)
54
+ - [3. Application](#3-application)
55
+ - [4. Page](#4-page)
56
+ - [5. Component](#5-component)
57
+ - [Standard Component methods](#standard-component-methods)
58
+ - [Component Specific methods](#component-specific-methods)
59
+ - [Tab](#521-tab-component)
60
+ - [6. Popup](#6-popup)
61
+ - [7. Formatter](#7-formatter)
62
+
63
+ ## 1) Context
64
+
65
+ Context methods are polymorphic, it has different classes pre-initialized based on execution context.
66
+
67
+ ### Custom component
68
+
69
+ `kf.context` returns a `CustomComponent` class while using inside custom component. Custom component supported methods:
70
+
71
+ ##### a) Watch Params
72
+
73
+ Listens for changes in parameter given to custom components in lowcode application.
23
74
 
24
- > Then SDK can be initialized anywhere by declaring:
25
75
  ```js
26
- const kf = window.KF();
76
+ kf.context.watchParams(function (data) {
77
+ console.log(data);
78
+ });
27
79
  ```
28
80
 
29
- ### 1) Form Functions
81
+ ### Kissflow Forms
30
82
 
31
- > Note: These function can be used only on button and other events inside the kissflow forms
32
- > Use Table:: as a prefix while using TableId
83
+ `kf.context` returns a `Form` class when it is used inside a kissflow's form that could be either Process, case or Dataform & it has following supported methods
33
84
 
34
- ##### Get from field
85
+ ##### a) getField()
86
+
87
+ ###### Description:
88
+ Use this function to get the current value of a form field
89
+
90
+ ###### Syntax:
35
91
  ```js
36
- kf.currentForm.getField(fieldId).then((res) => {...})
92
+ kf.context.getField(fieldId).then((res) => {...})
37
93
  // or
38
- let value = await kf.currentForm.getField(fieldId)
94
+ let value = await kf.context.getField(fieldId)
95
+ ```
96
+
97
+ ##### b) updateField()
98
+
99
+ ###### Description:
100
+ Use this function to get update any field in the form
101
+
102
+ ###### Syntax:
103
+ ```js
104
+ kf.context.updateField({ fieldId_1: fieldValue, fieldId_2: fieldValue });
105
+ ```
106
+
107
+ ##### c) toJSON()
108
+
109
+ ###### Description:
110
+ Use this function to get the JSON data of the current form
111
+
112
+ ###### Syntax:
113
+ ```js
114
+ const json = await kf.context.toJSON();
115
+ ```
116
+
117
+ ###### Output:
118
+ ```
119
+ {
120
+ "Untitled_Field": "testing",
121
+ "_created_at": "2022-03-01T03:04:09Z",
122
+ "_flow_name": "form events",
123
+ "_id": "Pk4_T1WGWuMe",
124
+ "_modified_at": "2022-03-01T03:04:09Z"
125
+ }
126
+ ```
127
+
128
+ ### Form Table
129
+
130
+ `kf.context.getTable(tableId)` returns a `Table` class which has the following methods
131
+
132
+ #### a) addRow()
133
+
134
+ ###### Description:
135
+ Appends row details to the table.
136
+
137
+ ###### Syntax:
138
+ ```js
139
+ const table = kf.context.getTable(tableId);
140
+ table.addRow({ columnId1: value, columnId2: value });
141
+ ```
142
+ > ##### Note: If there are more than one rows to be added to table then use `addRows()` instead for these bulk operations
143
+
144
+ #### b) addRows()
145
+
146
+ ###### Description:
147
+ Appends multiple rows details to the table.
148
+
149
+ ###### Syntax:
150
+ ```js
151
+ const table = kf.context.getTable(tableId);
152
+ let accumulator = [];
153
+ someArrayOfObjects.forEach(function(rowDetail) {
154
+ accumulator.push({
155
+ columnId1: rowDetail[columnId1],
156
+ columnId2: rowDetail[columnId2]
157
+ });
158
+ });
159
+ await table.addRows(accumulator);
160
+ ```
161
+
162
+ #### c) deleteRow()
163
+
164
+ ###### Description:
165
+ Deletes a row from the table based on the row id
166
+
167
+ ###### Syntax:
168
+ ```js
169
+ const table = kf.context.getTable(tableId);
170
+ await table.deleteRow(rowId);
171
+ ```
172
+ > ##### Note: If there are more than one rows to be deleted then use `deleteRows()` instead.
173
+
174
+ #### d) deleteRows()
175
+
176
+ ###### Description:
177
+ Deletes multiple rows from the table based on given array of strings.
178
+
179
+ ###### Syntax:
180
+ ```js
181
+ const table = kf.context.getTable(tableId);
182
+ await table.deleteRows([rowId1, rowId2, rowId3]);
39
183
  ```
40
- ##### Update form field
184
+
185
+ #### e) getRow()
186
+
187
+ ###### Description:
188
+ Use this function to perform form actions on any row inside a child table
189
+
190
+ ###### Syntax:
41
191
  ```js
42
- kf.currentForm.updateField({ fieldId_1: fieldValue, fieldId_2: fieldValue });
192
+ const table = kf.context.getTable(tableId);
193
+ const row = table.getRow(rowId);
43
194
  ```
44
- #### Update tableField
45
- Appends row details to the end of table.
195
+
196
+ ###### Output:
197
+ Returns an instance of `TableForm` class
198
+
199
+ #### f) getRows()
200
+
201
+ ###### Description:
202
+ Gets all the rows of the table
203
+
204
+ ###### Syntax:
46
205
  ```js
47
- kf.currentForm.addTableRow("tableId", { columnId1: value, columnId2: value });
206
+ const rows = await kf.context.getTable(tableId).getRows();
48
207
  ```
208
+
209
+ ###### Output:
210
+ Returns an array of `TableForm` instances
211
+
212
+ ##### g) toJSON()
213
+
214
+ ###### Description:
215
+ Use this function to get the JSON data of the child table
216
+
217
+ ###### Syntax:
218
+ ```js
219
+ const json = await kf.context.getTable(tableId).toJSON();
220
+ ```
221
+
222
+ ###### Output:
223
+ ```
224
+ [{
225
+ "Untitled_Field": "row 1",
226
+ "_created_at": "2022-03-01T03:04:09Z",
227
+ "_flow_name": "form events",
228
+ "_id": "Pk4_T1WGWuMe",
229
+ "_modified_at": "2022-03-01T03:04:09Z"
230
+ },{
231
+ "Untitled_Field": "row 2",
232
+ "_created_at": "2022-03-01T03:04:09Z",
233
+ "_flow_name": "form events",
234
+ "_id": "Pk4_T1WGWuMe",
235
+ "_modified_at": "2022-03-01T03:04:09Z"
236
+ }]
237
+ ```
238
+
239
+ ### Table Row
240
+
241
+ A single row inside a table is known as Table row
242
+ `kf.context` returns a `TableForm` class which has the following methods
243
+
244
+ ##### a) getField()
245
+
246
+ ###### Description:
247
+ Use this function to get the value of the table row
248
+
249
+ ###### Syntax:
250
+ ```js
251
+ kf.context.getField(fieldId).then((res) => {...})
252
+ // or
253
+ let value = await kf.context.getField(fieldId)
254
+ ```
255
+
256
+ ##### b) updateField()
257
+
258
+ ###### Description:
259
+ Use this function to get update any field in the table row
260
+
261
+ ###### Syntax:
262
+ ```js
263
+ kf.context.updateField({ fieldId_1: fieldValue, fieldId_2: fieldValue });
264
+ ```
265
+
266
+ ##### c) getParent()
267
+
268
+ ###### Description:
269
+ Use this function to perform form actions on the main form
270
+
271
+ ###### Syntax:
272
+ ```js
273
+ const mainForm = kf.context.getParent();
274
+ mainForm.updateField({ fieldId_1: fieldValue, fieldId_2: fieldValue });
275
+ ```
276
+
277
+ ###### Output:
278
+ Returns an instance of `Form` class using which we can perform any action on the
279
+ main form
280
+
281
+ ##### d) toJson()
282
+
283
+ ##### Description:
284
+ Get JSON output of table row
285
+
286
+ ##### Syntax:
287
+ ```js
288
+ const json = await kf.context.toJSON();
289
+ ```
290
+
291
+ ###### Output:
292
+ ```
293
+ {
294
+ "Untitled_Field": "testing",
295
+ "_created_at": "2022-03-01T03:04:09Z",
296
+ "_flow_name": "form events",
297
+ "_id": "Pk4_T1WGWuMe",
298
+ "_modified_at": "2022-03-01T03:04:09Z"
299
+ }
300
+ ```
301
+
49
302
  ---
50
303
 
51
- ### 2) Client Functions
304
+ ### 2) Client
305
+
52
306
  ##### Show Toast
53
307
  ```js
54
308
  kf.client.showInfo(message);
55
309
  ```
310
+
56
311
  ##### Show confirm
312
+ Displays the confirmation dialog, and returns users's action as a response
57
313
  ```js
58
- kf.client.showConfirm({ title, content });
314
+ kf.client.showConfirm({ title, content }).then((action) => {
315
+ if(action === "OK") // user clicked ok button
316
+
317
+ else // user clicked cancel button or clicked outside the popup
318
+ })
59
319
  ```
320
+
60
321
  ##### Redirect to URL
61
322
  ```js
62
323
  kf.client.redirect(url);
63
324
  ```
64
- ---
65
- ### 3) Component Functions
66
- #### Refresh a component
67
- ```js
68
- kf.getComponent(componentId).refresh();
69
- ```
70
- ---
71
325
 
72
- ### 4) Lowcode application functions
73
- Application variables has global context to application,
326
+ ### 3) Application
327
+
328
+ `kf.app` represents the active kissflow app and `kf.app._id` returns its id.
329
+
74
330
  ##### Get value to application variable
331
+ ```js
332
+ const appVarible1 = await kf.app.getVariable("variableId");
75
333
  ```
76
- let value = await kf.app.getVariable("variableId");
77
- ```
334
+
78
335
  ##### Set value of application variable
79
336
  ```js
80
337
  let value = await kf.app.setVariable("variableId", value);
@@ -84,111 +341,152 @@ await kf.app.setVariable({
84
341
  variableId_2: 3345
85
342
  });
86
343
  ```
344
+
87
345
  ##### Open a page
88
- > Note: Page Input parameters are optional.
346
+ `openPage(id)` returns [Page](#4-page) class instance
89
347
  ```js
90
- let pageInputParameters = {
348
+ const pageInputParameters = {
91
349
  param1: value,
92
350
  param2: value
93
351
  };
94
352
  kf.app.openPage(pageId, pageInputParameters);
353
+ // Note: Page Input parameters are optional.
95
354
  ```
96
- ##### Get values of page input parameters
355
+
356
+ ### 4) Page
357
+ `kf.app.page` returns the active page opened inside application and `kf.app.page._id` returns its id.
358
+
359
+ ##### Page parameters
97
360
  ```js
98
- let value = await kf.app.page.getParameter();
361
+ let value = await kf.app.page.getParameter("parameterId"); // for retreiving single parameter
362
+ ```
363
+ Get all page parameters
364
+ ```js
365
+ let allParams = await kf.app.page.getAllParameters();
366
+ // returns an object
367
+ {
368
+ parameterName: "Sample value",
369
+ parameterName2: "Sample value 2"
370
+ }
99
371
  ```
100
- ##### Open a popup page
372
+
373
+ ##### Access a Component
374
+ `getComponent` returns a [Component](#5-component) class.
101
375
  ```js
102
- let popupPage = await kf.app.page.openPopup(pageId, { inputParam1: 2 }, { w: 50; h: 50 })
376
+ const componentName = await kf.app.page.getComponent("componentId");
103
377
  ```
104
- > Note: openPopup method returns the popup page class using which we can chain other functions in page, for eg: (cont. from above code snippet)
378
+
379
+ ##### Open a popup
380
+ `openPoup` returns a [Popup](#6-popup) class.
105
381
  ```js
106
- let variableName = await popupPage.getVariable("variableName");
107
- popupPage.onClose(() => {});
382
+ kf.app.page.openPopup("popupId", { inputParam1: "value" });
383
+ // Note: Popup parameters are optional.
108
384
  ```
109
- ##### Page onClose event
385
+
386
+ ### 5) Component
387
+ #### getComponent(id)
388
+ Parameter: Component's Id
389
+ Returns: Component class instance
110
390
  ```js
111
- kf.app.page.onClose(() => {});
112
- // or
113
- let popupPage = await kf.app.page.openPopup(pageId, { inputParam1: 2 }, { w: 50; h: 50 })
114
- popupPage.onClose(() => {
115
- console.log("popup onclose");
116
- // ...
117
- });
391
+ const component = await kf.app.page.getComponent(componentId);
118
392
  ```
119
- ---
393
+ ##### Standard Component Methods
394
+ ```js
395
+ component.refresh(); // Refreshes the component
396
+ component.hide(); // Hides the component
397
+ component.show(); // Shows the component if it's been hidden previously
398
+ ```
399
+ ##### Component Specific Methods
120
400
 
121
- ### 6) Get context
122
- Returns the current account, user, page, and application.
401
+
402
+ ##### 5.2.0) Component onMount
403
+ Component onMount takes in callBack function as argument.
404
+ > ##### Note: Any component specific methods that are used on Page load must be called inside component's onMount event.
405
+ Parameter: function
123
406
  ```js
124
- kf.getContext().then((ctx) => {...})
125
- // or
126
- let ctx = await kf.getContext()
127
- /*
128
- returns the context object like.
129
- ctx = {
130
- app: {_id },
131
- page: { _id },
132
- user: { Name, Email, UserType, _id },
133
- account: { _id }
134
- }
135
- */
407
+ component.onMount(() => {
408
+ // function logic goes here... For eg.
409
+ // component.setActiveTab(2)
410
+ })
411
+ ```
412
+ ##### 5.2.1) Tab component
413
+ ##### 1) setActiveTab
414
+ Sets specified tab as active.
415
+ Parameter: Tabs' Number (Starts from 1 to N)
416
+ ```js
417
+ component.setActiveTab(2) // sets 2nd tab as active one
136
418
  ```
137
- ---
138
419
 
139
- ### 7) Fetch Api through kf sdk
140
420
 
141
- Fetch any external api & other kissflow api using this method.
142
- > Note: This method has a limit of 10 seconds for an api call
421
+ ### 6) Popup
422
+ `kf.app.page.popup` returns the active popup instance opened inside the page and its id can be accessed via `kf.app.page.popup._id`
423
+ And `kf.app.page.getPopup(id)` returns this popup class instance.
424
+
425
+ ##### Popup parameters
143
426
  ```js
144
- kf.api(url, config).then((res) => {...})
145
- // or
146
- let resp = await kf.api(url, config)
427
+ let value = await kf.app.page.popup.getParameter("parameterId"); // for retreiving single popup parameter
428
+ ```
429
+ Get all popup parameters
430
+ ```js
431
+ let allParams = await kf.app.page.popup.getAllParameters();
432
+ // Returns an object
433
+ {
434
+ parameterName: "Sample value",
435
+ parameterName2: "Sample value 2"
436
+ }
147
437
  ```
148
- ---
149
438
 
150
- ### 8) Watch params
151
- Listens for changes in parameter given to custom components in lowcode
152
- application.
439
+ ##### Close popup
153
440
  ```js
154
- kf.watchParams(function (data) {
155
- console.log(data);
156
- });
441
+ kf.app.page.popup.close() // for active popup
442
+ // or if you already have a popup instance...
443
+ greetPopup.close();
157
444
  ```
158
- ---
159
445
 
160
- ### 9) Formatter Functions
446
+ ### 7) Formatter
447
+
161
448
  ##### Format to KF Date
449
+
162
450
  ```js
163
- kf.formatter.toKfDate("08-24-2021").then((res) => {...})
451
+ kf.formatter.toDate("08-24-2021").then((res) => {...})
164
452
  // or
165
- let value = await kf.formatter.toKfDate("08-24-2021");
453
+ let value = await kf.formatter.toDate("08-24-2021");
166
454
  ```
455
+
167
456
  ##### Format to KF Date Time
457
+
168
458
  ```js
169
- kf.formatter.toKfDateTime("2021-08-26T14:30").then((res) => {...})
459
+ kf.formatter.toDateTime("2021-08-26T14:30").then((res) => {...})
170
460
  // or
171
- let value = await kf.formatter.toKfDateTime("2021-08-26T14:30");
461
+ let value = await kf.formatter.toDateTime("2021-08-26T14:30");
172
462
  ```
463
+
173
464
  ##### Format to KF Number
465
+
174
466
  ```js
175
- kf.formatter.toKfNumber("1,00,000.500000").then((res) => {...})
467
+ kf.formatter.toNumber("1,00,000.500000").then((res) => {...})
176
468
  // or
177
- let value = await kf.formatter.toKfNumber("1,00,000.500000");
469
+ let value = await kf.formatter.toNumber("1,00,000.500000");
178
470
  ```
471
+
179
472
  ##### Format to KF Currency
473
+
180
474
  ```js
181
- kf.formatter.toKfCurrency("1,00,000.500000", "USD").then((res) => {...})
475
+ kf.formatter.toCurrency("1,00,000.500000", "USD").then((res) => {...})
182
476
  // or
183
- let value = await kf.formatter.toKfCurrency("1,00,000.500000", "USD");
477
+ let value = await kf.formatter.toCurrency("1,00,000.500000", "USD");
184
478
  ```
479
+
185
480
  ##### Format to KF Boolean
481
+
186
482
  ```js
187
483
  kf.formatter.toBoolean("yes").then((res) => {...})
188
484
  // or
189
485
  let value = await kf.formatter.toBoolean("yes");
190
486
  ```
487
+
191
488
  ##### Other supported Boolean values
489
+
192
490
  ```js
193
491
  let value = await kf.formatter.toBoolean("1");
194
492
  let value = await kf.formatter.toBoolean("true");
@@ -196,4 +494,3 @@ let value = await kf.formatter.toBoolean("no");
196
494
  let value = await kf.formatter.toBoolean("0");
197
495
  let value = await kf.formatter.toBoolean("false");
198
496
  ```
199
- ---