@kissflow/lowcode-client-sdk 1.0.21 → 1.0.24-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.
package/README.md CHANGED
@@ -1,496 +1,5 @@
1
1
  # _Kissflow Lowcode JavaScript SDK_
2
2
 
3
3
  JavaScript SDK for developing over the Kissflow lowcode platform
4
- ### Use as an `npm` module
5
4
 
6
- Install the SDK as a module: `npm i @kissflow/lowcode-client-sdk` Then import into your project:
7
- ```js
8
- import KFSDK from "@kissflow/lowcode-client-sdk";
9
- let kf;
10
- (async function () {
11
- kf = await KFSDK.initialize();
12
- })();
13
- ```
14
- > Note: Initializing Kf SDK in custom components returns a promise.
15
- ### Use as a `<script>` tag directly in HTML
16
-
17
- SDK can also be loaded directly into HTML by adding:
18
- ```html
19
- <script src="https://unpkg.com/@kissflow/lowcode-client-sdk@latest/dist/kfsdk.umd.js"></script>
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.
74
-
75
- ```js
76
- kf.context.watchParams(function (data) {
77
- console.log(data);
78
- });
79
- ```
80
-
81
- ### Kissflow Forms
82
-
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
84
-
85
- ##### a) getField()
86
-
87
- ###### Description:
88
- Use this function to get the current value of a form field
89
-
90
- ###### Syntax:
91
- ```js
92
- kf.context.getField(fieldId).then((res) => {...})
93
- // or
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]);
183
- ```
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:
191
- ```js
192
- const table = kf.context.getTable(tableId);
193
- const row = table.getRow(rowId);
194
- ```
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:
205
- ```js
206
- const rows = await kf.context.getTable(tableId).getRows();
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
-
302
- ---
303
-
304
- ### 2) Client
305
-
306
- ##### Show Toast
307
- ```js
308
- kf.client.showInfo(message);
309
- ```
310
-
311
- ##### Show confirm
312
- Displays the confirmation dialog, and returns users's action as a response
313
- ```js
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
- })
319
- ```
320
-
321
- ##### Redirect to URL
322
- ```js
323
- kf.client.redirect(url);
324
- ```
325
-
326
- ### 3) Application
327
-
328
- `kf.app` represents the active kissflow app and `kf.app._id` returns its id.
329
-
330
- ##### Get value to application variable
331
- ```js
332
- const appVarible1 = await kf.app.getVariable("variableId");
333
- ```
334
-
335
- ##### Set value of application variable
336
- ```js
337
- let value = await kf.app.setVariable("variableId", value);
338
- // or
339
- await kf.app.setVariable({
340
- variableId_1: "value_1",
341
- variableId_2: 3345
342
- });
343
- ```
344
-
345
- ##### Open a page
346
- `openPage(id)` returns [Page](#4-page) class instance
347
- ```js
348
- const pageInputParameters = {
349
- param1: value,
350
- param2: value
351
- };
352
- kf.app.openPage(pageId, pageInputParameters);
353
- // Note: Page Input parameters are optional.
354
- ```
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
360
- ```js
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
- }
371
- ```
372
-
373
- ##### Access a Component
374
- `getComponent` returns a [Component](#5-component) class.
375
- ```js
376
- const componentName = await kf.app.page.getComponent("componentId");
377
- ```
378
-
379
- ##### Open a popup
380
- `openPoup` returns a [Popup](#6-popup) class.
381
- ```js
382
- kf.app.page.openPopup("popupId", { inputParam1: "value" });
383
- // Note: Popup parameters are optional.
384
- ```
385
-
386
- ### 5) Component
387
- #### getComponent(id)
388
- Parameter: Component's Id
389
- Returns: Component class instance
390
- ```js
391
- const component = await kf.app.page.getComponent(componentId);
392
- ```
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
400
-
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
406
- ```js
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
418
- ```
419
-
420
-
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
426
- ```js
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
- }
437
- ```
438
-
439
- ##### Close popup
440
- ```js
441
- kf.app.page.popup.close() // for active popup
442
- // or if you already have a popup instance...
443
- greetPopup.close();
444
- ```
445
-
446
- ### 7) Formatter
447
-
448
- ##### Format to KF Date
449
-
450
- ```js
451
- kf.formatter.toDate("08-24-2021").then((res) => {...})
452
- // or
453
- let value = await kf.formatter.toDate("08-24-2021");
454
- ```
455
-
456
- ##### Format to KF Date Time
457
-
458
- ```js
459
- kf.formatter.toDateTime("2021-08-26T14:30").then((res) => {...})
460
- // or
461
- let value = await kf.formatter.toDateTime("2021-08-26T14:30");
462
- ```
463
-
464
- ##### Format to KF Number
465
-
466
- ```js
467
- kf.formatter.toNumber("1,00,000.500000").then((res) => {...})
468
- // or
469
- let value = await kf.formatter.toNumber("1,00,000.500000");
470
- ```
471
-
472
- ##### Format to KF Currency
473
-
474
- ```js
475
- kf.formatter.toCurrency("1,00,000.500000", "USD").then((res) => {...})
476
- // or
477
- let value = await kf.formatter.toCurrency("1,00,000.500000", "USD");
478
- ```
479
-
480
- ##### Format to KF Boolean
481
-
482
- ```js
483
- kf.formatter.toBoolean("yes").then((res) => {...})
484
- // or
485
- let value = await kf.formatter.toBoolean("yes");
486
- ```
487
-
488
- ##### Other supported Boolean values
489
-
490
- ```js
491
- let value = await kf.formatter.toBoolean("1");
492
- let value = await kf.formatter.toBoolean("true");
493
- let value = await kf.formatter.toBoolean("no");
494
- let value = await kf.formatter.toBoolean("0");
495
- let value = await kf.formatter.toBoolean("false");
496
- ```
5
+ Please refer docs [here](https://kissflow.github.io/lcnc-sdk-js/)
package/dist/index.d.ts CHANGED
@@ -47,6 +47,7 @@ declare module "core/constants" {
47
47
  WINDOW_NDEF_READER_MAKE_READONLY: string;
48
48
  WINDOW_NDEF_READER_ABORT_SCAN: string;
49
49
  DECISION_TABLE_EXECUTE: string;
50
+ DATAFORM_IMPORT_CSV: string;
50
51
  };
51
52
  export const EVENT_TYPES: {
52
53
  COMPONENT_ON_MOUNT: string;
@@ -70,9 +71,47 @@ declare module "core/index" {
70
71
  export class BaseSDK extends EventBase {
71
72
  _postMessageAsync(command: string, args: any, hasCallBack?: boolean, callBack?: (data: any) => {}): object | string | any;
72
73
  _postMessage(command: string, args: any, callBack?: any): void;
74
+ _postMessageSync(command: string, args: any): any;
73
75
  }
74
76
  export * from "core/constants";
75
77
  }
78
+ declare module "utils/client" {
79
+ import { BaseSDK } from "core/index";
80
+ export class Client extends BaseSDK {
81
+ showInfo(message: string): any;
82
+ showConfirm(args: {
83
+ title: string;
84
+ content: string;
85
+ okText: string;
86
+ cancelText: string;
87
+ }): any;
88
+ redirect(url: string): any;
89
+ }
90
+ }
91
+ declare module "utils/formatter" {
92
+ import { BaseSDK } from "core/index";
93
+ export class Formatter extends BaseSDK {
94
+ toDate(date: string): any;
95
+ toDateTime(date: string): any;
96
+ toNumber(value: string): any;
97
+ toCurrency(value: string, currencyCode: string): any;
98
+ toBoolean(value: string): any;
99
+ }
100
+ }
101
+ declare module "utils/index" {
102
+ export * from "utils/client";
103
+ export * from "utils/formatter";
104
+ export const isObject: (value: any) => boolean;
105
+ }
106
+ declare module "core/proxy" {
107
+ export class CreateProxy {
108
+ path: string[];
109
+ parent: object;
110
+ constructor(parent: object, target?: {}, path?: any[]);
111
+ get(target: object, property: string): any;
112
+ set(target: object, property: string, value: any, reciever: any): any;
113
+ }
114
+ }
76
115
  declare module "types/external" {
77
116
  export type userObject = {
78
117
  _id: string;
@@ -166,14 +205,20 @@ declare module "app/page" {
166
205
  _id: string;
167
206
  popup: Popup;
168
207
  type: string;
208
+ variable: PageVariable;
169
209
  constructor(props: PageContext);
170
210
  getParameter(key: string): any;
171
211
  getAllParameters(): any;
172
212
  getVariable(key: string): any;
173
- setVariable(key: string, value: any): any;
213
+ setVariable(key: string | object, value: any): any;
174
214
  openPopup(popupId: string, popupParams: object): any;
175
215
  getComponent(componentId: string): Component;
176
216
  }
217
+ class PageVariable extends BaseSDK {
218
+ constructor();
219
+ get(key: any, path: any): any;
220
+ set(key: any, value: any, path: any): any;
221
+ }
177
222
  }
178
223
  declare module "app/decisiontable" {
179
224
  import { BaseSDK } from "core/index";
@@ -183,51 +228,40 @@ declare module "app/decisiontable" {
183
228
  evaluate(payload?: object): any;
184
229
  }
185
230
  }
231
+ declare module "app/dataform" {
232
+ import { BaseSDK } from "core/index";
233
+ export class Dataform extends BaseSDK {
234
+ private _id;
235
+ constructor(flowId: string);
236
+ importCSV(defaultValues: object): any;
237
+ }
238
+ }
186
239
  declare module "app/index" {
187
240
  import { BaseSDK } from "core/index";
188
241
  import { Page } from "app/page";
189
242
  import { AppContext } from "types/internal";
190
243
  import { DecisionTable } from "app/decisiontable";
244
+ import { Dataform } from "app/dataform";
191
245
  export class Application extends BaseSDK {
192
246
  page: Page;
247
+ variable: AppVariable;
193
248
  _id: string;
194
249
  constructor(props: AppContext);
195
250
  getVariable(key: string): any;
196
251
  setVariable(key: string | object, value?: any): any;
197
252
  openPage(pageId: string, pageParams: object): any;
198
253
  getDecisionTable(flowId: string): DecisionTable;
254
+ getDataform(flowId: string): Dataform;
255
+ }
256
+ class AppVariable extends BaseSDK {
257
+ constructor();
258
+ get(key: any, path: any): any;
259
+ set(key: any, value: any, path: any): any;
199
260
  }
200
261
  export * from "app/component";
201
262
  export { Page };
202
263
  export * from "app/popup";
203
264
  }
204
- declare module "utils/client" {
205
- import { BaseSDK } from "core/index";
206
- export class Client extends BaseSDK {
207
- showInfo(message: string): any;
208
- showConfirm(args: {
209
- title: string;
210
- content: string;
211
- okText: string;
212
- cancelText: string;
213
- }): any;
214
- redirect(url: string): any;
215
- }
216
- }
217
- declare module "utils/formatter" {
218
- import { BaseSDK } from "core/index";
219
- export class Formatter extends BaseSDK {
220
- toDate(date: string): any;
221
- toDateTime(date: string): any;
222
- toNumber(value: string): any;
223
- toCurrency(value: string, currencyCode: string): any;
224
- toBoolean(value: string): any;
225
- }
226
- }
227
- declare module "utils/index" {
228
- export * from "utils/client";
229
- export * from "utils/formatter";
230
- }
231
265
  declare module "index" {
232
266
  import { BaseSDK } from "core/index";
233
267
  import { Application, Page, CustomComponent } from "app/index";