@kissflow/lowcode-client-sdk 1.0.9 → 1.0.12
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 +114 -124
- package/dist/global.types.d.ts +8 -1
- package/dist/index.d.ts +9 -2
- package/dist/kfsdk.es.js +5 -1
- package/dist/kfsdk.umd.js +1 -1
- package/dist/kfworkersdk.es.js +21 -4
- package/dist/lowcode.d.ts +12 -3
- package/package.json +52 -53
package/README.md
CHANGED
|
@@ -1,52 +1,73 @@
|
|
|
1
1
|
# _Kissflow Lowcode JavaScript SDK_
|
|
2
2
|
|
|
3
3
|
JavaScript SDK for developing over the Kissflow lowcode platform
|
|
4
|
-
|
|
5
4
|
### Use as an `npm` module
|
|
6
5
|
|
|
7
|
-
Install the SDK as a module: `npm i @kissflow/lowcode-client-sdk` Then import
|
|
8
|
-
into your project: Note: Initializing Kf SDK in custom components returns a
|
|
9
|
-
promise.
|
|
10
|
-
|
|
6
|
+
Install the SDK as a module: `npm i @kissflow/lowcode-client-sdk` Then import into your project:
|
|
11
7
|
```js
|
|
12
8
|
import KFSDK from "@kissflow/lowcode-client-sdk";
|
|
13
9
|
let kf;
|
|
14
10
|
(async function () {
|
|
15
|
-
kf = await KFSDK.
|
|
11
|
+
kf = await KFSDK.initialize();
|
|
16
12
|
})();
|
|
17
13
|
```
|
|
18
|
-
|
|
14
|
+
> Note: Initializing Kf SDK in custom components returns a promise.
|
|
19
15
|
### Use as a `<script>` tag directly in HTML
|
|
20
16
|
|
|
21
17
|
SDK can also be loaded directly into HTML by adding:
|
|
22
|
-
|
|
23
18
|
```html
|
|
24
|
-
<script src="https://unpkg.com/@kissflow/lowcode-client-sdk@latest/dist/kfsdk.umd.js"
|
|
19
|
+
<script src="https://unpkg.com/@kissflow/lowcode-client-sdk@latest/dist/kfsdk.umd.js"></script>
|
|
25
20
|
```
|
|
26
|
-
|
|
27
|
-
> Then SDK can be initialized anywhere by declaring:
|
|
28
|
-
|
|
21
|
+
Then SDK can be initialized as:
|
|
29
22
|
```js
|
|
30
23
|
let kf;
|
|
31
24
|
window.onload = async function () {
|
|
32
|
-
kf = await window.kf.
|
|
25
|
+
kf = await window.kf.initialize();
|
|
33
26
|
};
|
|
34
27
|
```
|
|
35
28
|
|
|
36
|
-
|
|
29
|
+
### User and Account details
|
|
30
|
+
Details of authenticated user can be accessed as following
|
|
31
|
+
```js
|
|
32
|
+
const { Name, Email, UserType, _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
|
+
- [6. Popup](#6-popup)
|
|
58
|
+
- [7. Formatter](#7-formatter)
|
|
59
|
+
|
|
60
|
+
## 1) Context
|
|
37
61
|
|
|
38
|
-
Context
|
|
39
|
-
context.
|
|
62
|
+
Context methods are polymorphic, it has different classes pre-initialized based on execution context.
|
|
40
63
|
|
|
41
|
-
### Custom component
|
|
64
|
+
### Custom component
|
|
42
65
|
|
|
43
|
-
`kf.context` returns a `CustomComponent` class while using inside custom
|
|
44
|
-
component. Custom component supported functions:
|
|
66
|
+
`kf.context` returns a `CustomComponent` class while using inside custom component. Custom component supported methods:
|
|
45
67
|
|
|
46
68
|
##### a) Watch Params
|
|
47
69
|
|
|
48
|
-
Listens for changes in parameter given to custom components in lowcode
|
|
49
|
-
application.
|
|
70
|
+
Listens for changes in parameter given to custom components in lowcode application.
|
|
50
71
|
|
|
51
72
|
```js
|
|
52
73
|
kf.context.watchParams(function (data) {
|
|
@@ -54,20 +75,16 @@ kf.context.watchParams(function (data) {
|
|
|
54
75
|
});
|
|
55
76
|
```
|
|
56
77
|
|
|
57
|
-
###
|
|
78
|
+
### Kissflow Forms
|
|
58
79
|
|
|
59
|
-
`kf.context` returns a `Form` class when it is used inside a kissflow's form
|
|
60
|
-
that could be either Process, case or Dataform & it has following supported
|
|
61
|
-
functions
|
|
80
|
+
`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
|
|
62
81
|
|
|
63
82
|
##### a) getField()
|
|
64
83
|
|
|
65
84
|
###### Description:
|
|
66
|
-
|
|
67
85
|
Use this function to get the current value of a form field
|
|
68
86
|
|
|
69
87
|
###### Syntax:
|
|
70
|
-
|
|
71
88
|
```js
|
|
72
89
|
kf.context.getField(fieldId).then((res) => {...})
|
|
73
90
|
// or
|
|
@@ -77,11 +94,9 @@ let value = await kf.context.getField(fieldId)
|
|
|
77
94
|
##### b) updateField()
|
|
78
95
|
|
|
79
96
|
###### Description:
|
|
80
|
-
|
|
81
97
|
Use this function to get update any field in the form
|
|
82
98
|
|
|
83
99
|
###### Syntax:
|
|
84
|
-
|
|
85
100
|
```js
|
|
86
101
|
kf.context.updateField({ fieldId_1: fieldValue, fieldId_2: fieldValue });
|
|
87
102
|
```
|
|
@@ -89,17 +104,14 @@ kf.context.updateField({ fieldId_1: fieldValue, fieldId_2: fieldValue });
|
|
|
89
104
|
##### c) toJSON()
|
|
90
105
|
|
|
91
106
|
###### Description:
|
|
92
|
-
|
|
93
107
|
Use this function to get the JSON data of the current form
|
|
94
108
|
|
|
95
109
|
###### Syntax:
|
|
96
|
-
|
|
97
110
|
```js
|
|
98
111
|
const json = await kf.context.toJSON();
|
|
99
112
|
```
|
|
100
113
|
|
|
101
114
|
###### Output:
|
|
102
|
-
|
|
103
115
|
```
|
|
104
116
|
{
|
|
105
117
|
"Untitled_Field": "testing",
|
|
@@ -110,21 +122,16 @@ const json = await kf.context.toJSON();
|
|
|
110
122
|
}
|
|
111
123
|
```
|
|
112
124
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
### Table functions
|
|
125
|
+
### Form Table
|
|
116
126
|
|
|
117
|
-
`kf.
|
|
118
|
-
following functions
|
|
127
|
+
`kf.context.getTable(tableId)` returns a `Table` class which has the following methods
|
|
119
128
|
|
|
120
129
|
#### a) addRow()
|
|
121
130
|
|
|
122
131
|
###### Description:
|
|
123
|
-
|
|
124
132
|
Appends row details to the end of table.
|
|
125
133
|
|
|
126
134
|
###### Syntax:
|
|
127
|
-
|
|
128
135
|
```js
|
|
129
136
|
const table = kf.context.getTable(tableId);
|
|
130
137
|
table.addRow({ columnId1: value, columnId2: value });
|
|
@@ -133,11 +140,9 @@ table.addRow({ columnId1: value, columnId2: value });
|
|
|
133
140
|
#### b) deleteRow()
|
|
134
141
|
|
|
135
142
|
###### Description:
|
|
136
|
-
|
|
137
143
|
Deletes a row from the table based on the row id
|
|
138
144
|
|
|
139
145
|
###### Syntax:
|
|
140
|
-
|
|
141
146
|
```js
|
|
142
147
|
const table = kf.context.getTable(tableId);
|
|
143
148
|
table.deleteRow(rowId);
|
|
@@ -146,50 +151,41 @@ table.deleteRow(rowId);
|
|
|
146
151
|
#### c) getRow()
|
|
147
152
|
|
|
148
153
|
###### Description:
|
|
149
|
-
|
|
150
154
|
Use this function to perform form actions on any row inside a child table
|
|
151
155
|
|
|
152
156
|
###### Syntax:
|
|
153
|
-
|
|
154
157
|
```js
|
|
155
158
|
const table = kf.context.getTable(tableId);
|
|
156
159
|
const row = table.getRow(rowId);
|
|
157
160
|
```
|
|
158
161
|
|
|
159
162
|
###### Output:
|
|
160
|
-
|
|
161
163
|
Returns an instance of `TableForm` class
|
|
162
164
|
|
|
163
165
|
#### d) getRows()
|
|
164
166
|
|
|
165
167
|
###### Description:
|
|
166
|
-
|
|
167
168
|
Gets all the rows of the table
|
|
168
169
|
|
|
169
170
|
###### Syntax:
|
|
170
|
-
|
|
171
171
|
```js
|
|
172
172
|
const rows = await kf.context.getTable(tableId).getRows();
|
|
173
173
|
```
|
|
174
174
|
|
|
175
175
|
###### Output:
|
|
176
|
-
|
|
177
176
|
Returns an array of `TableForm` instances
|
|
178
177
|
|
|
179
178
|
##### e) toJSON()
|
|
180
179
|
|
|
181
180
|
###### Description:
|
|
182
|
-
|
|
183
181
|
Use this function to get the JSON data of the child table
|
|
184
182
|
|
|
185
183
|
###### Syntax:
|
|
186
|
-
|
|
187
184
|
```js
|
|
188
185
|
const json = await kf.context.getTable(tableId).toJSON();
|
|
189
186
|
```
|
|
190
187
|
|
|
191
188
|
###### Output:
|
|
192
|
-
|
|
193
189
|
```
|
|
194
190
|
[{
|
|
195
191
|
"Untitled_Field": "row 1",
|
|
@@ -206,20 +202,17 @@ const json = await kf.context.getTable(tableId).toJSON();
|
|
|
206
202
|
}]
|
|
207
203
|
```
|
|
208
204
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
### Table Row functions
|
|
205
|
+
### Table Row
|
|
212
206
|
|
|
213
|
-
|
|
207
|
+
A single row inside a table is known as Table row
|
|
208
|
+
`kf.context` returns a `TableForm` class which has the following methods
|
|
214
209
|
|
|
215
210
|
##### a) getField()
|
|
216
211
|
|
|
217
212
|
###### Description:
|
|
218
|
-
|
|
219
213
|
Use this function to get the value of the table row
|
|
220
214
|
|
|
221
215
|
###### Syntax:
|
|
222
|
-
|
|
223
216
|
```js
|
|
224
217
|
kf.context.getField(fieldId).then((res) => {...})
|
|
225
218
|
// or
|
|
@@ -229,47 +222,39 @@ let value = await kf.context.getField(fieldId)
|
|
|
229
222
|
##### b) updateField()
|
|
230
223
|
|
|
231
224
|
###### Description:
|
|
232
|
-
|
|
233
225
|
Use this function to get update any field in the table row
|
|
234
226
|
|
|
235
227
|
###### Syntax:
|
|
236
|
-
|
|
237
228
|
```js
|
|
238
|
-
kf.
|
|
229
|
+
kf.context.updateField({ fieldId_1: fieldValue, fieldId_2: fieldValue });
|
|
239
230
|
```
|
|
240
231
|
|
|
241
232
|
##### c) getParent()
|
|
242
233
|
|
|
243
234
|
###### Description:
|
|
244
|
-
|
|
245
235
|
Use this function to perform form actions on the main form
|
|
246
236
|
|
|
247
237
|
###### Syntax:
|
|
248
|
-
|
|
249
238
|
```js
|
|
250
239
|
const mainForm = kf.context.getParent();
|
|
251
240
|
mainForm.updateField({ fieldId_1: fieldValue, fieldId_2: fieldValue });
|
|
252
241
|
```
|
|
253
242
|
|
|
254
243
|
###### Output:
|
|
255
|
-
|
|
256
244
|
Returns an instance of `Form` class using which we can perform any action on the
|
|
257
245
|
main form
|
|
258
246
|
|
|
259
247
|
##### d) toJson()
|
|
260
248
|
|
|
261
249
|
##### Description:
|
|
262
|
-
|
|
263
250
|
Get JSON output of table row
|
|
264
251
|
|
|
265
252
|
##### Syntax:
|
|
266
|
-
|
|
267
253
|
```js
|
|
268
254
|
const json = await kf.context.toJSON();
|
|
269
255
|
```
|
|
270
256
|
|
|
271
257
|
###### Output:
|
|
272
|
-
|
|
273
258
|
```
|
|
274
259
|
{
|
|
275
260
|
"Untitled_Field": "testing",
|
|
@@ -282,68 +267,33 @@ const json = await kf.context.toJSON();
|
|
|
282
267
|
|
|
283
268
|
---
|
|
284
269
|
|
|
285
|
-
### 2) Client
|
|
270
|
+
### 2) Client
|
|
286
271
|
|
|
287
272
|
##### Show Toast
|
|
288
|
-
|
|
289
273
|
```js
|
|
290
274
|
kf.client.showInfo(message);
|
|
291
275
|
```
|
|
292
276
|
|
|
293
277
|
##### Show confirm
|
|
294
|
-
|
|
295
278
|
```js
|
|
296
279
|
kf.client.showConfirm({ title, content });
|
|
297
280
|
```
|
|
298
281
|
|
|
299
282
|
##### Redirect to URL
|
|
300
|
-
|
|
301
283
|
```js
|
|
302
284
|
kf.client.redirect(url);
|
|
303
285
|
```
|
|
304
286
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
### 3) Component Functions
|
|
308
|
-
|
|
309
|
-
getComponent(id) inside page returns component class instance.
|
|
310
|
-
|
|
311
|
-
```js
|
|
312
|
-
const componentName = await kf.app.page.getComponent(componentId);
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
By using component instance we can invoke following methods.
|
|
287
|
+
### 3) Application
|
|
316
288
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
```js
|
|
320
|
-
componentName.refresh();
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
#### Show a component
|
|
324
|
-
|
|
325
|
-
```js
|
|
326
|
-
componentName.show();
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
#### Hide a component
|
|
330
|
-
|
|
331
|
-
```js
|
|
332
|
-
componentName.hide();
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
### 4) Lowcode application functions
|
|
336
|
-
|
|
337
|
-
Application variables has global context to application,
|
|
289
|
+
`kf.app` represents the active kissflow app and `kf.app._id` returns its id.
|
|
338
290
|
|
|
339
291
|
##### Get value to application variable
|
|
340
|
-
|
|
341
292
|
```js
|
|
342
293
|
const appVarible1 = await kf.app.getVariable("variableId");
|
|
343
294
|
```
|
|
344
295
|
|
|
345
296
|
##### Set value of application variable
|
|
346
|
-
|
|
347
297
|
```js
|
|
348
298
|
let value = await kf.app.setVariable("variableId", value);
|
|
349
299
|
// or
|
|
@@ -354,52 +304,93 @@ await kf.app.setVariable({
|
|
|
354
304
|
```
|
|
355
305
|
|
|
356
306
|
##### Open a page
|
|
357
|
-
|
|
358
|
-
> Note: Page Input parameters are optional.
|
|
359
|
-
|
|
307
|
+
`openPage(id)` returns [Page](#4-page) class instance
|
|
360
308
|
```js
|
|
361
|
-
|
|
309
|
+
const pageInputParameters = {
|
|
362
310
|
param1: value,
|
|
363
311
|
param2: value
|
|
364
312
|
};
|
|
365
313
|
kf.app.openPage(pageId, pageInputParameters);
|
|
314
|
+
// Note: Page Input parameters are optional.
|
|
366
315
|
```
|
|
367
316
|
|
|
368
|
-
|
|
317
|
+
### 4) Page
|
|
318
|
+
`kf.app.page` returns the active page opened inside application and `kf.app.page._id` returns its id.
|
|
369
319
|
|
|
320
|
+
##### Page parameters
|
|
370
321
|
```js
|
|
371
|
-
let value = await kf.app.page.getParameter();
|
|
322
|
+
let value = await kf.app.page.getParameter("parameterId"); // for retreiving single parameter
|
|
323
|
+
```
|
|
324
|
+
Get all page parameters
|
|
325
|
+
```js
|
|
326
|
+
let allParams = await kf.app.page.getAllParameters();
|
|
327
|
+
// returns an object
|
|
328
|
+
{
|
|
329
|
+
parameterName: "Sample value",
|
|
330
|
+
parameterName2: "Sample value 2"
|
|
331
|
+
}
|
|
372
332
|
```
|
|
373
333
|
|
|
374
|
-
#####
|
|
375
|
-
|
|
334
|
+
##### Access a Component
|
|
335
|
+
`getComponent` returns a [Component](#5-component) class.
|
|
376
336
|
```js
|
|
377
|
-
kf.app.page.
|
|
337
|
+
const componentName = await kf.app.page.getComponent("componentId");
|
|
378
338
|
```
|
|
379
339
|
|
|
380
|
-
#####
|
|
340
|
+
##### Open a popup
|
|
341
|
+
`openPoup` returns a [Popup](#6-popup) class.
|
|
342
|
+
```js
|
|
343
|
+
kf.app.page.openPopup("popupId", { inputParam1: "value" });
|
|
344
|
+
// Note: Popup parameters are optional.
|
|
345
|
+
```
|
|
381
346
|
|
|
382
|
-
|
|
347
|
+
### 5) Component
|
|
383
348
|
|
|
384
349
|
```js
|
|
385
|
-
kf.app.page.
|
|
350
|
+
const component = await kf.app.page.getComponent(componentId);
|
|
386
351
|
```
|
|
352
|
+
By using component instance we can invoke following methods.
|
|
387
353
|
|
|
388
|
-
|
|
354
|
+
##### Refresh a component
|
|
355
|
+
```js
|
|
356
|
+
component.refresh();
|
|
357
|
+
```
|
|
389
358
|
|
|
390
|
-
|
|
359
|
+
##### Show a component
|
|
360
|
+
```js
|
|
361
|
+
componentName.show();
|
|
362
|
+
```
|
|
391
363
|
|
|
392
|
-
|
|
364
|
+
##### Hide a component
|
|
365
|
+
```js
|
|
366
|
+
component.hide();
|
|
367
|
+
```
|
|
368
|
+
### 6) Popup
|
|
369
|
+
`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`
|
|
370
|
+
And `kf.app.page.getPopup(id)` returns this popup class instance.
|
|
393
371
|
|
|
372
|
+
##### Popup parameters
|
|
394
373
|
```js
|
|
395
|
-
kf.
|
|
396
|
-
|
|
397
|
-
|
|
374
|
+
let value = await kf.app.page.popup.getParameter("parameterId"); // for retreiving single popup parameter
|
|
375
|
+
```
|
|
376
|
+
Get all popup parameters
|
|
377
|
+
```js
|
|
378
|
+
let allParams = await kf.app.page.popup.getAllParameters();
|
|
379
|
+
// returns an object
|
|
380
|
+
{
|
|
381
|
+
parameterName: "Sample value",
|
|
382
|
+
parameterName2: "Sample value 2"
|
|
383
|
+
}
|
|
398
384
|
```
|
|
399
385
|
|
|
400
|
-
|
|
386
|
+
##### Close popup
|
|
387
|
+
```js
|
|
388
|
+
kf.app.page.popup.close() // for active popup
|
|
389
|
+
// or if you already have a popup instance...
|
|
390
|
+
greetPopup.close();
|
|
391
|
+
```
|
|
401
392
|
|
|
402
|
-
###
|
|
393
|
+
### 7) Formatter
|
|
403
394
|
|
|
404
395
|
##### Format to KF Date
|
|
405
396
|
|
|
@@ -451,4 +442,3 @@ let value = await kf.formatter.toBoolean("0");
|
|
|
451
442
|
let value = await kf.formatter.toBoolean("false");
|
|
452
443
|
```
|
|
453
444
|
|
|
454
|
-
---
|
package/dist/global.types.d.ts
CHANGED
|
@@ -76,8 +76,11 @@ declare class kf {
|
|
|
76
76
|
static formatter: Formatter
|
|
77
77
|
static app: Application
|
|
78
78
|
static user: userObject
|
|
79
|
+
static env: environmentObject
|
|
79
80
|
static account: accountObject
|
|
80
|
-
api(url: string, args?: {
|
|
81
|
+
api(url: string, args?: {
|
|
82
|
+
headers: object;
|
|
83
|
+
}): Promise<any>;
|
|
81
84
|
}
|
|
82
85
|
declare type userObject = {
|
|
83
86
|
_id: string;
|
|
@@ -90,3 +93,7 @@ declare type userObject = {
|
|
|
90
93
|
declare type accountObject = {
|
|
91
94
|
_id: string;
|
|
92
95
|
};
|
|
96
|
+
|
|
97
|
+
declare type environmentObject = {
|
|
98
|
+
isMobile: boolean
|
|
99
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -69,9 +69,12 @@ declare module "types/external" {
|
|
|
69
69
|
export type accountObject = {
|
|
70
70
|
_id: string;
|
|
71
71
|
};
|
|
72
|
+
export type environmentObject = {
|
|
73
|
+
isMobile: boolean;
|
|
74
|
+
};
|
|
72
75
|
}
|
|
73
76
|
declare module "types/internal" {
|
|
74
|
-
import { userObject, accountObject } from "types/external";
|
|
77
|
+
import { userObject, accountObject, environmentObject } from "types/external";
|
|
75
78
|
export interface SDKContext {
|
|
76
79
|
formInstanceId: string;
|
|
77
80
|
tableId: string;
|
|
@@ -83,6 +86,8 @@ declare module "types/internal" {
|
|
|
83
86
|
popupId: string;
|
|
84
87
|
user: userObject;
|
|
85
88
|
account: accountObject;
|
|
89
|
+
csrfToken: string;
|
|
90
|
+
envDetails: environmentObject;
|
|
86
91
|
}
|
|
87
92
|
export interface manifestMethodsType {
|
|
88
93
|
name: string;
|
|
@@ -229,7 +234,7 @@ declare module "index" {
|
|
|
229
234
|
import { Application } from "app";
|
|
230
235
|
import { Page } from "page";
|
|
231
236
|
import { CustomComponent } from "component";
|
|
232
|
-
import { userObject, accountObject } from "types/external";
|
|
237
|
+
import { userObject, accountObject, environmentObject } from "types/external";
|
|
233
238
|
class CustomComponentSDK extends BaseSDK {
|
|
234
239
|
app: Application;
|
|
235
240
|
page: Page;
|
|
@@ -238,8 +243,10 @@ declare module "index" {
|
|
|
238
243
|
context: CustomComponent;
|
|
239
244
|
client: Client;
|
|
240
245
|
formatter: Formatter;
|
|
246
|
+
env: environmentObject;
|
|
241
247
|
constructor();
|
|
242
248
|
api(url: string, args?: {}): string | object;
|
|
249
|
+
initialize(): any;
|
|
243
250
|
initialise(): any;
|
|
244
251
|
}
|
|
245
252
|
const _default: CustomComponentSDK;
|
package/dist/kfsdk.es.js
CHANGED
|
@@ -362,7 +362,7 @@ class CustomComponentSDK extends BaseSDK {
|
|
|
362
362
|
api(url, args = {}) {
|
|
363
363
|
return this._postMessageAsync(LISTENER_CMDS.API, { url, args });
|
|
364
364
|
}
|
|
365
|
-
|
|
365
|
+
initialize() {
|
|
366
366
|
return this._postMessageAsync(LISTENER_CMDS.INITIALIZE_CUST_COMP, {}, true, (data) => {
|
|
367
367
|
this.app = new Application(data);
|
|
368
368
|
this.page = new Page(data);
|
|
@@ -371,9 +371,13 @@ class CustomComponentSDK extends BaseSDK {
|
|
|
371
371
|
this.formatter = new Formatter({});
|
|
372
372
|
this.user = data.user;
|
|
373
373
|
this.account = data.account;
|
|
374
|
+
this.env = data.envDetails;
|
|
374
375
|
return this;
|
|
375
376
|
});
|
|
376
377
|
}
|
|
378
|
+
initialise() {
|
|
379
|
+
return this.initialize();
|
|
380
|
+
}
|
|
377
381
|
}
|
|
378
382
|
var index = new CustomComponentSDK();
|
|
379
383
|
export { index as default };
|
package/dist/kfsdk.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var k=Object.defineProperty;var y=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var
|
|
1
|
+
var k=Object.defineProperty;var y=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var D=(n,s,_)=>s in n?k(n,s,{enumerable:!0,configurable:!0,writable:!0,value:_}):n[s]=_,C=(n,s)=>{for(var _ in s||(s={}))b.call(s,_)&&D(n,_,s[_]);if(y)for(var _ of y(s))j.call(s,_)&&D(n,_,s[_]);return n};var N=(n,s,_)=>{if(!s.has(n))throw TypeError("Cannot "+_)};var o=(n,s,_)=>(N(n,s,"read from private field"),_?_.call(n):s.get(n)),M=(n,s,_)=>{if(s.has(n))throw TypeError("Cannot add the same private member more than once");s instanceof WeakSet?s.add(n):s.set(n,_)},g=(n,s,_,a)=>(N(n,s,"write to private field"),a?a.call(n,_):s.set(n,_),_);var c=(n,s,_)=>(N(n,s,"access private method"),_);(function(n,s){typeof exports=="object"&&typeof module!="undefined"?module.exports=s():typeof define=="function"&&define.amd?define(s):(n=typeof globalThis!="undefined"?globalThis:n||self,n.kf=s())})(this,function(){var T,O,R,I,u,U,h,B,L,F;"use strict";let n=(r=21)=>crypto.getRandomValues(new Uint8Array(r)).reduce((e,t)=>(t&=63,t<36?e+=t.toString(36):t<62?e+=(t-26).toString(36).toUpperCase():t>62?e+="-":e+="_",e),"");const s={API:"API",PARAMS:"PARAMS",GET_CONTEXT:"GET_CONTEXT",RETURN:"RETURN",GET_FORM_FIELD:"GET_FORM_FIELD",UPDATE_FORM:"UPDATE_FORM",GET_TABLE:"GET_TABLE",GET_TABLE_ROW:"GET_TABLE_ROW",ADD_TABLE_ROW:"ADD_TABLE_ROW",DELETE_TABLE_ROW:"DELETE_TABLE_ROW",TO_JSON:"TO_JSON",GET_TABLE_ROWS:"GET_TABLE_ROWS",MESSAGE:"MESSAGE",CONFIRM:"CONFIRM",ALERT:"ALERT",REDIRECT:"REDIRECT",OPEN_PAGE:"OPEN_PAGE",FORMAT_DATE:"FORMAT_DATE",FORMAT_DATE_TIME:"FORMAT_DATE_TIME",FORMAT_NUMBER:"FORMAT_NUMBER",FORMAT_CURRENCY:"FORMAT_CURRENCY",FORMAT_BOOLEAN:"FORMAT_BOOLEAN",GET_APP_VARIABLE:"GET_APP_VARIABLE",SET_APP_VARIABLE:"SET_APP_VARIABLE",GET_PAGE_VARIABLE:"GET_PAGE_VARIABLE",SET_PAGE_VARIABLE:"SET_PAGE_VARIABLE",GET_PAGE_PARAMS:"GET_PAGE_PARAMS",GET_ALL_PAGE_PARAMS:"GET_ALL_PAGE_PARAMS",PAGE_ON_CLOSE:"PAGE_ON_CLOSE",OPEN_POPUP:"OPEN_POPUP",GET_POPUP_PARAMS:"GET_POPUP_PARAMS",GET_ALL_POPUP_PARAMS:"GET_ALL_POPUP_PARAMS",CLOSE_POPUP:"CLOSE_POPUP",GET_COMPONENT:"GET_COMPONENT",COMPONENT_REFRESH:"COMPONENT_REFRESH",COMPONENT_SHOW:"COMPONENT_SHOW",COMPONENT_HIDE:"COMPONENT_HIDE",INITIALIZE_CUST_COMP:"INITIALIZE_CUST_COMP"},_={POPUP_ID:"ACTIVE_POP_UP"};function a(r="lcncsdk"){return`${r}-${n()}`}function G(r){self.parent&&self.parent!==self?self.parent.postMessage(r,"*"):self.postMessage(r)}class P{constructor(e){M(this,R);M(this,u);M(this,h);M(this,L);M(this,T,void 0);M(this,O,void 0);g(this,T,{}),g(this,O,{}),self.addEventListener("message",c(this,L,F).bind(this),!1)}_postMessageAsync(e,t,E,A){return new Promise((i,l)=>{const d=a(e.toLowerCase());G(C({_id:d,command:e},t)),c(this,R,I).call(this,d,async p=>{p!=null&&p.errorMessage?l(p):(E&&A&&(p=await A(p)),i(p))})})}_postMessage(e,t,E={}){const A=a(e.toLowerCase());G(C({_id:A,command:e},E)),c(this,R,I).call(this,A,i=>t(i))}_registerEventListener(e,t,E){c(this,u,U).call(this,e,t,E)}}T=new WeakMap,O=new WeakMap,R=new WeakSet,I=function(e,t){o(this,T)[e]=o(this,T)[e]||[],o(this,T)[e].push(t)},u=new WeakSet,U=function(e,t,E){o(this,O)[e]||(o(this,O)[e]={}),o(this,O)[e][t]=E},h=new WeakSet,B=function(e){const{_id:t,eventType:E,eventParams:A}=e;if(!t||!E)return;const i=o(this,O)[t]||{};i[E]&&i[E](A||{})},L=new WeakSet,F=function(e){if(e.origin!==self.location.origin){const t=e.data;if(t.isEvent)return c(this,h,B).call(this,t);const E=(t==null?void 0:t._req)||{};let A=o(this,T)[E==null?void 0:E._id]||[];A&&A.forEach(i=>{try{t.resp&&Object.keys(t.resp).length===1&&E.command!==s.API?i(Object.values(t.resp)[0]):i(t.resp)}catch(l){console.error("Message callback error: ",l)}})}};class m extends P{showInfo(e){return super._postMessageAsync(s.MESSAGE,{message:e})}showConfirm(e){return super._postMessageAsync(s.CONFIRM,{data:{title:e.title,content:e.content,okText:e.okText||"Ok",cancelText:e.cancelText||"Cancel"}})}redirect(e){return super._postMessageAsync(s.REDIRECT,{url:e})}}class w extends P{toDate(e){return this._postMessageAsync(s.FORMAT_DATE,{date:e})}toDateTime(e){return this._postMessageAsync(s.FORMAT_DATE_TIME,{date:e})}toNumber(e){return this._postMessageAsync(s.FORMAT_NUMBER,{value:e})}toCurrency(e,t){return this._postMessageAsync(s.FORMAT_CURRENCY,{value:e,currencyCode:t})}toBoolean(e){return this._postMessageAsync(s.FORMAT_BOOLEAN,{value:e})}}class S extends P{constructor(e){super({}),this._id=e.componentId,this.type="Component"}refresh(){return this._postMessageAsync(s.COMPONENT_REFRESH,{id:this._id})}show(){return this._postMessageAsync(s.COMPONENT_SHOW,{id:this._id})}hide(){return this._postMessageAsync(s.COMPONENT_HIDE,{id:this._id})}}class V extends P{constructor(){super({}),this.type="CustomComponent"}watchParams(e){this._postMessage(s.PARAMS,e)}}class x extends P{constructor(e){super({}),this.type="Popup",this._id=e.popupId||_.POPUP_ID}getParameter(e){return this._postMessageAsync(s.GET_POPUP_PARAMS,{key:e,popupId:this._id})}getAllParameters(){return this._postMessageAsync(s.GET_ALL_POPUP_PARAMS,{popupId:this._id})}close(){return this._postMessageAsync(s.CLOSE_POPUP,{})}getComponent(e){return this._postMessageAsync(s.GET_COMPONENT,{componentId:e},!0,t=>new S(t))}}class f extends P{constructor(e){super({}),this.type="Page",this.popup=new x({}),this._id=e.pageId}getParameter(e){return this._postMessageAsync(s.GET_PAGE_PARAMS,{key:e})}getAllParameters(){return this._postMessageAsync(s.GET_ALL_PAGE_PARAMS,{pageId:this._id})}getVariable(e){return this._postMessageAsync(s.GET_PAGE_VARIABLE,{key:e})}setVariable(e,t){return this._postMessageAsync(s.SET_PAGE_VARIABLE,{key:e,value:t})}openPopup(e,t){return this._postMessageAsync(s.OPEN_POPUP,{popupId:e,popupParams:t})}getComponent(e){return this._postMessageAsync(s.GET_COMPONENT,{componentId:e},!0,t=>new S(t))}}class v extends P{constructor(e){super({}),this._id=e.appId,this.page=new f(e)}getVariable(e){return this._postMessageAsync(s.GET_APP_VARIABLE,{key:e})}setVariable(e,t){return this._postMessageAsync(s.SET_APP_VARIABLE,{key:e,value:t})}openPage(e,t){return this._postMessageAsync(s.OPEN_PAGE,{pageId:e,pageParams:t})}}class W extends P{constructor(){super({})}api(e,t={}){return this._postMessageAsync(s.API,{url:e,args:t})}initialize(){return this._postMessageAsync(s.INITIALIZE_CUST_COMP,{},!0,e=>(this.app=new v(e),this.page=new f(e),this.context=new V,this.client=new m({}),this.formatter=new w({}),this.user=e.user,this.account=e.account,this.env=e.envDetails,this))}initialise(){return this.initialize()}}var H=new W;return H});
|
package/dist/kfworkersdk.es.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
2
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -14,6 +16,7 @@ var __spreadValues = (a, b) => {
|
|
|
14
16
|
}
|
|
15
17
|
return a;
|
|
16
18
|
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
17
20
|
var __accessCheck = (obj, member, msg) => {
|
|
18
21
|
if (!member.has(obj))
|
|
19
22
|
throw TypeError("Cannot " + msg);
|
|
@@ -36,7 +39,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
36
39
|
__accessCheck(obj, member, "access private method");
|
|
37
40
|
return method;
|
|
38
41
|
};
|
|
39
|
-
var _listeners, _eventListeners, _addListener, addListener_fn, _appendEventListeners, appendEventListeners_fn, _checkEvents, checkEvents_fn, _onMessage, onMessage_fn;
|
|
42
|
+
var _listeners, _eventListeners, _addListener, addListener_fn, _appendEventListeners, appendEventListeners_fn, _checkEvents, checkEvents_fn, _onMessage, onMessage_fn, _csrfToken;
|
|
40
43
|
let nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
|
|
41
44
|
byte &= 63;
|
|
42
45
|
if (byte < 36) {
|
|
@@ -441,6 +444,7 @@ class Application extends BaseSDK {
|
|
|
441
444
|
class LowcodeSDK extends BaseSDK {
|
|
442
445
|
constructor(props) {
|
|
443
446
|
super({});
|
|
447
|
+
__privateAdd(this, _csrfToken, void 0);
|
|
444
448
|
if (props.tableId && props.tableRowId) {
|
|
445
449
|
this.context = new TableForm(props.formInstanceId, props.tableId, props.tableRowId);
|
|
446
450
|
} else if (props.formInstanceId) {
|
|
@@ -458,12 +462,25 @@ class LowcodeSDK extends BaseSDK {
|
|
|
458
462
|
this.app = new Application(props);
|
|
459
463
|
}
|
|
460
464
|
this.user = props.user;
|
|
465
|
+
this.env = props.envDetails;
|
|
461
466
|
this.account = props.account;
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
467
|
+
__privateSet(this, _csrfToken, props.csrfToken);
|
|
468
|
+
}
|
|
469
|
+
async api(url, args) {
|
|
470
|
+
const response = await globalThis.fetch(url, __spreadProps(__spreadValues({}, args), {
|
|
471
|
+
headers: __spreadProps(__spreadValues({}, (args == null ? void 0 : args.headers) || {}), {
|
|
472
|
+
"X-Csrf-Token": __privateGet(this, _csrfToken)
|
|
473
|
+
})
|
|
474
|
+
}));
|
|
475
|
+
const contentType = response.headers.get("content-type");
|
|
476
|
+
if (contentType && contentType.includes("application/json")) {
|
|
477
|
+
return await response.json();
|
|
478
|
+
} else {
|
|
479
|
+
return response;
|
|
480
|
+
}
|
|
465
481
|
}
|
|
466
482
|
}
|
|
483
|
+
_csrfToken = new WeakMap();
|
|
467
484
|
function initSDK(config) {
|
|
468
485
|
return new LowcodeSDK(config);
|
|
469
486
|
}
|
package/dist/lowcode.d.ts
CHANGED
|
@@ -69,9 +69,12 @@ declare module "types/external" {
|
|
|
69
69
|
export type accountObject = {
|
|
70
70
|
_id: string;
|
|
71
71
|
};
|
|
72
|
+
export type environmentObject = {
|
|
73
|
+
isMobile: boolean;
|
|
74
|
+
};
|
|
72
75
|
}
|
|
73
76
|
declare module "types/internal" {
|
|
74
|
-
import { userObject, accountObject } from "types/external";
|
|
77
|
+
import { userObject, accountObject, environmentObject } from "types/external";
|
|
75
78
|
export interface SDKContext {
|
|
76
79
|
formInstanceId: string;
|
|
77
80
|
tableId: string;
|
|
@@ -83,6 +86,8 @@ declare module "types/internal" {
|
|
|
83
86
|
popupId: string;
|
|
84
87
|
user: userObject;
|
|
85
88
|
account: accountObject;
|
|
89
|
+
csrfToken: string;
|
|
90
|
+
envDetails: environmentObject;
|
|
86
91
|
}
|
|
87
92
|
export interface manifestMethodsType {
|
|
88
93
|
name: string;
|
|
@@ -233,16 +238,20 @@ declare module "lowcode" {
|
|
|
233
238
|
import { Component } from "component";
|
|
234
239
|
import { Popup } from "popup";
|
|
235
240
|
import { SDKContext } from "types/internal";
|
|
236
|
-
import { userObject, accountObject } from "types/external";
|
|
241
|
+
import { userObject, accountObject, environmentObject } from "types/external";
|
|
237
242
|
class LowcodeSDK extends BaseSDK {
|
|
243
|
+
#private;
|
|
238
244
|
context: Component | Form | TableForm | Page | Popup;
|
|
239
245
|
client: Client;
|
|
240
246
|
formatter: Formatter;
|
|
241
247
|
app: Application;
|
|
242
248
|
user: userObject;
|
|
249
|
+
env: environmentObject;
|
|
243
250
|
account: accountObject;
|
|
244
251
|
constructor(props: SDKContext);
|
|
245
|
-
api(url: string, args?: {
|
|
252
|
+
api(url: string, args?: {
|
|
253
|
+
headers: object;
|
|
254
|
+
}): Promise<any>;
|
|
246
255
|
}
|
|
247
256
|
function initSDK(config: SDKContext): LowcodeSDK;
|
|
248
257
|
export default initSDK;
|
package/package.json
CHANGED
|
@@ -1,54 +1,53 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
2
|
+
"name": "@kissflow/lowcode-client-sdk",
|
|
3
|
+
"version": "1.0.12",
|
|
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/kfworkersdk.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
|
+
"html-webpack-plugin": "^5.3.1",
|
|
33
|
+
"http-server": "^0.12.3",
|
|
34
|
+
"ts-loader": "^9.2.5",
|
|
35
|
+
"typescript": "^4.3.5",
|
|
36
|
+
"vite": "^2.9.8",
|
|
37
|
+
"webpack": "^5.52.1",
|
|
38
|
+
"webpack-cli": "^4.8.0",
|
|
39
|
+
"webpack-dev-server": "^3.11.2"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@lingui/cli": "^3.13.3",
|
|
43
|
+
"@lingui/react": "^2",
|
|
44
|
+
"nanoid": "^3.1.30",
|
|
45
|
+
"ts-file-parser": "0.0.21"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"start": "vite serve",
|
|
49
|
+
"customBuild": "node custom.build.mjs",
|
|
50
|
+
"build": "pnpm run customBuild",
|
|
51
|
+
"serve": "http-server -p 8080"
|
|
52
|
+
}
|
|
53
|
+
}
|