@kissflow/lowcode-client-sdk 1.0.8 → 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 -126
- package/dist/global.types.d.ts +99 -0
- package/dist/index.d.ts +254 -0
- 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 +258 -0
- package/package.json +52 -53
package/README.md
CHANGED
|
@@ -1,54 +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
|
-
|
|
16
|
-
kf = await KFSDK.initialise();
|
|
11
|
+
kf = await KFSDK.initialize();
|
|
17
12
|
})();
|
|
18
13
|
```
|
|
19
|
-
|
|
14
|
+
> Note: Initializing Kf SDK in custom components returns a promise.
|
|
20
15
|
### Use as a `<script>` tag directly in HTML
|
|
21
16
|
|
|
22
17
|
SDK can also be loaded directly into HTML by adding:
|
|
23
|
-
|
|
24
18
|
```html
|
|
25
|
-
<script src="https://
|
|
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
|
+
};
|
|
26
27
|
```
|
|
27
28
|
|
|
28
|
-
|
|
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
|
|
29
40
|
|
|
30
41
|
```js
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
})();
|
|
42
|
+
kf.api(url, config).then((res) => {...})
|
|
43
|
+
// or
|
|
44
|
+
let resp = await kf.api(url, config)
|
|
35
45
|
```
|
|
36
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)
|
|
37
59
|
|
|
38
|
-
## 1) Context
|
|
60
|
+
## 1) Context
|
|
39
61
|
|
|
40
|
-
Context
|
|
41
|
-
context.
|
|
62
|
+
Context methods are polymorphic, it has different classes pre-initialized based on execution context.
|
|
42
63
|
|
|
43
|
-
### Custom component
|
|
64
|
+
### Custom component
|
|
44
65
|
|
|
45
|
-
`kf.context` returns a `CustomComponent` class while using inside custom
|
|
46
|
-
component. Custom component supported functions:
|
|
66
|
+
`kf.context` returns a `CustomComponent` class while using inside custom component. Custom component supported methods:
|
|
47
67
|
|
|
48
68
|
##### a) Watch Params
|
|
49
69
|
|
|
50
|
-
Listens for changes in parameter given to custom components in lowcode
|
|
51
|
-
application.
|
|
70
|
+
Listens for changes in parameter given to custom components in lowcode application.
|
|
52
71
|
|
|
53
72
|
```js
|
|
54
73
|
kf.context.watchParams(function (data) {
|
|
@@ -56,20 +75,16 @@ kf.context.watchParams(function (data) {
|
|
|
56
75
|
});
|
|
57
76
|
```
|
|
58
77
|
|
|
59
|
-
###
|
|
78
|
+
### Kissflow Forms
|
|
60
79
|
|
|
61
|
-
`kf.context` returns a `Form` class when it is used inside a kissflow's form
|
|
62
|
-
that could be either Process, case or Dataform & it has following supported
|
|
63
|
-
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
|
|
64
81
|
|
|
65
82
|
##### a) getField()
|
|
66
83
|
|
|
67
84
|
###### Description:
|
|
68
|
-
|
|
69
85
|
Use this function to get the current value of a form field
|
|
70
86
|
|
|
71
87
|
###### Syntax:
|
|
72
|
-
|
|
73
88
|
```js
|
|
74
89
|
kf.context.getField(fieldId).then((res) => {...})
|
|
75
90
|
// or
|
|
@@ -79,11 +94,9 @@ let value = await kf.context.getField(fieldId)
|
|
|
79
94
|
##### b) updateField()
|
|
80
95
|
|
|
81
96
|
###### Description:
|
|
82
|
-
|
|
83
97
|
Use this function to get update any field in the form
|
|
84
98
|
|
|
85
99
|
###### Syntax:
|
|
86
|
-
|
|
87
100
|
```js
|
|
88
101
|
kf.context.updateField({ fieldId_1: fieldValue, fieldId_2: fieldValue });
|
|
89
102
|
```
|
|
@@ -91,17 +104,14 @@ kf.context.updateField({ fieldId_1: fieldValue, fieldId_2: fieldValue });
|
|
|
91
104
|
##### c) toJSON()
|
|
92
105
|
|
|
93
106
|
###### Description:
|
|
94
|
-
|
|
95
107
|
Use this function to get the JSON data of the current form
|
|
96
108
|
|
|
97
109
|
###### Syntax:
|
|
98
|
-
|
|
99
110
|
```js
|
|
100
111
|
const json = await kf.context.toJSON();
|
|
101
112
|
```
|
|
102
113
|
|
|
103
114
|
###### Output:
|
|
104
|
-
|
|
105
115
|
```
|
|
106
116
|
{
|
|
107
117
|
"Untitled_Field": "testing",
|
|
@@ -112,21 +122,16 @@ const json = await kf.context.toJSON();
|
|
|
112
122
|
}
|
|
113
123
|
```
|
|
114
124
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
### Table functions
|
|
125
|
+
### Form Table
|
|
118
126
|
|
|
119
|
-
`kf.
|
|
120
|
-
following functions
|
|
127
|
+
`kf.context.getTable(tableId)` returns a `Table` class which has the following methods
|
|
121
128
|
|
|
122
129
|
#### a) addRow()
|
|
123
130
|
|
|
124
131
|
###### Description:
|
|
125
|
-
|
|
126
132
|
Appends row details to the end of table.
|
|
127
133
|
|
|
128
134
|
###### Syntax:
|
|
129
|
-
|
|
130
135
|
```js
|
|
131
136
|
const table = kf.context.getTable(tableId);
|
|
132
137
|
table.addRow({ columnId1: value, columnId2: value });
|
|
@@ -135,11 +140,9 @@ table.addRow({ columnId1: value, columnId2: value });
|
|
|
135
140
|
#### b) deleteRow()
|
|
136
141
|
|
|
137
142
|
###### Description:
|
|
138
|
-
|
|
139
143
|
Deletes a row from the table based on the row id
|
|
140
144
|
|
|
141
145
|
###### Syntax:
|
|
142
|
-
|
|
143
146
|
```js
|
|
144
147
|
const table = kf.context.getTable(tableId);
|
|
145
148
|
table.deleteRow(rowId);
|
|
@@ -148,50 +151,41 @@ table.deleteRow(rowId);
|
|
|
148
151
|
#### c) getRow()
|
|
149
152
|
|
|
150
153
|
###### Description:
|
|
151
|
-
|
|
152
154
|
Use this function to perform form actions on any row inside a child table
|
|
153
155
|
|
|
154
156
|
###### Syntax:
|
|
155
|
-
|
|
156
157
|
```js
|
|
157
158
|
const table = kf.context.getTable(tableId);
|
|
158
159
|
const row = table.getRow(rowId);
|
|
159
160
|
```
|
|
160
161
|
|
|
161
162
|
###### Output:
|
|
162
|
-
|
|
163
163
|
Returns an instance of `TableForm` class
|
|
164
164
|
|
|
165
165
|
#### d) getRows()
|
|
166
166
|
|
|
167
167
|
###### Description:
|
|
168
|
-
|
|
169
168
|
Gets all the rows of the table
|
|
170
169
|
|
|
171
170
|
###### Syntax:
|
|
172
|
-
|
|
173
171
|
```js
|
|
174
172
|
const rows = await kf.context.getTable(tableId).getRows();
|
|
175
173
|
```
|
|
176
174
|
|
|
177
175
|
###### Output:
|
|
178
|
-
|
|
179
176
|
Returns an array of `TableForm` instances
|
|
180
177
|
|
|
181
178
|
##### e) toJSON()
|
|
182
179
|
|
|
183
180
|
###### Description:
|
|
184
|
-
|
|
185
181
|
Use this function to get the JSON data of the child table
|
|
186
182
|
|
|
187
183
|
###### Syntax:
|
|
188
|
-
|
|
189
184
|
```js
|
|
190
185
|
const json = await kf.context.getTable(tableId).toJSON();
|
|
191
186
|
```
|
|
192
187
|
|
|
193
188
|
###### Output:
|
|
194
|
-
|
|
195
189
|
```
|
|
196
190
|
[{
|
|
197
191
|
"Untitled_Field": "row 1",
|
|
@@ -208,20 +202,17 @@ const json = await kf.context.getTable(tableId).toJSON();
|
|
|
208
202
|
}]
|
|
209
203
|
```
|
|
210
204
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
### Table Row functions
|
|
205
|
+
### Table Row
|
|
214
206
|
|
|
215
|
-
|
|
207
|
+
A single row inside a table is known as Table row
|
|
208
|
+
`kf.context` returns a `TableForm` class which has the following methods
|
|
216
209
|
|
|
217
210
|
##### a) getField()
|
|
218
211
|
|
|
219
212
|
###### Description:
|
|
220
|
-
|
|
221
213
|
Use this function to get the value of the table row
|
|
222
214
|
|
|
223
215
|
###### Syntax:
|
|
224
|
-
|
|
225
216
|
```js
|
|
226
217
|
kf.context.getField(fieldId).then((res) => {...})
|
|
227
218
|
// or
|
|
@@ -231,47 +222,39 @@ let value = await kf.context.getField(fieldId)
|
|
|
231
222
|
##### b) updateField()
|
|
232
223
|
|
|
233
224
|
###### Description:
|
|
234
|
-
|
|
235
225
|
Use this function to get update any field in the table row
|
|
236
226
|
|
|
237
227
|
###### Syntax:
|
|
238
|
-
|
|
239
228
|
```js
|
|
240
|
-
kf.
|
|
229
|
+
kf.context.updateField({ fieldId_1: fieldValue, fieldId_2: fieldValue });
|
|
241
230
|
```
|
|
242
231
|
|
|
243
232
|
##### c) getParent()
|
|
244
233
|
|
|
245
234
|
###### Description:
|
|
246
|
-
|
|
247
235
|
Use this function to perform form actions on the main form
|
|
248
236
|
|
|
249
237
|
###### Syntax:
|
|
250
|
-
|
|
251
238
|
```js
|
|
252
239
|
const mainForm = kf.context.getParent();
|
|
253
240
|
mainForm.updateField({ fieldId_1: fieldValue, fieldId_2: fieldValue });
|
|
254
241
|
```
|
|
255
242
|
|
|
256
243
|
###### Output:
|
|
257
|
-
|
|
258
244
|
Returns an instance of `Form` class using which we can perform any action on the
|
|
259
245
|
main form
|
|
260
246
|
|
|
261
247
|
##### d) toJson()
|
|
262
248
|
|
|
263
249
|
##### Description:
|
|
264
|
-
|
|
265
250
|
Get JSON output of table row
|
|
266
251
|
|
|
267
252
|
##### Syntax:
|
|
268
|
-
|
|
269
253
|
```js
|
|
270
254
|
const json = await kf.context.toJSON();
|
|
271
255
|
```
|
|
272
256
|
|
|
273
257
|
###### Output:
|
|
274
|
-
|
|
275
258
|
```
|
|
276
259
|
{
|
|
277
260
|
"Untitled_Field": "testing",
|
|
@@ -284,68 +267,33 @@ const json = await kf.context.toJSON();
|
|
|
284
267
|
|
|
285
268
|
---
|
|
286
269
|
|
|
287
|
-
### 2) Client
|
|
270
|
+
### 2) Client
|
|
288
271
|
|
|
289
272
|
##### Show Toast
|
|
290
|
-
|
|
291
273
|
```js
|
|
292
274
|
kf.client.showInfo(message);
|
|
293
275
|
```
|
|
294
276
|
|
|
295
277
|
##### Show confirm
|
|
296
|
-
|
|
297
278
|
```js
|
|
298
279
|
kf.client.showConfirm({ title, content });
|
|
299
280
|
```
|
|
300
281
|
|
|
301
282
|
##### Redirect to URL
|
|
302
|
-
|
|
303
283
|
```js
|
|
304
284
|
kf.client.redirect(url);
|
|
305
285
|
```
|
|
306
286
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
### 3) Component Functions
|
|
310
|
-
|
|
311
|
-
getComponent(id) inside page returns component class instance.
|
|
312
|
-
|
|
313
|
-
```js
|
|
314
|
-
const componentName = await kf.app.page.getComponent(componentId);
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
By using component instance we can invoke following methods.
|
|
287
|
+
### 3) Application
|
|
318
288
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
```js
|
|
322
|
-
componentName.refresh();
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
#### Show a component
|
|
326
|
-
|
|
327
|
-
```js
|
|
328
|
-
componentName.show();
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
#### Hide a component
|
|
332
|
-
|
|
333
|
-
```js
|
|
334
|
-
componentName.hide();
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
### 4) Lowcode application functions
|
|
338
|
-
|
|
339
|
-
Application variables has global context to application,
|
|
289
|
+
`kf.app` represents the active kissflow app and `kf.app._id` returns its id.
|
|
340
290
|
|
|
341
291
|
##### Get value to application variable
|
|
342
|
-
|
|
343
292
|
```js
|
|
344
293
|
const appVarible1 = await kf.app.getVariable("variableId");
|
|
345
294
|
```
|
|
346
295
|
|
|
347
296
|
##### Set value of application variable
|
|
348
|
-
|
|
349
297
|
```js
|
|
350
298
|
let value = await kf.app.setVariable("variableId", value);
|
|
351
299
|
// or
|
|
@@ -356,52 +304,93 @@ await kf.app.setVariable({
|
|
|
356
304
|
```
|
|
357
305
|
|
|
358
306
|
##### Open a page
|
|
359
|
-
|
|
360
|
-
> Note: Page Input parameters are optional.
|
|
361
|
-
|
|
307
|
+
`openPage(id)` returns [Page](#4-page) class instance
|
|
362
308
|
```js
|
|
363
|
-
|
|
309
|
+
const pageInputParameters = {
|
|
364
310
|
param1: value,
|
|
365
311
|
param2: value
|
|
366
312
|
};
|
|
367
313
|
kf.app.openPage(pageId, pageInputParameters);
|
|
314
|
+
// Note: Page Input parameters are optional.
|
|
368
315
|
```
|
|
369
316
|
|
|
370
|
-
|
|
317
|
+
### 4) Page
|
|
318
|
+
`kf.app.page` returns the active page opened inside application and `kf.app.page._id` returns its id.
|
|
371
319
|
|
|
320
|
+
##### Page parameters
|
|
372
321
|
```js
|
|
373
|
-
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
|
+
}
|
|
374
332
|
```
|
|
375
333
|
|
|
376
|
-
#####
|
|
377
|
-
|
|
334
|
+
##### Access a Component
|
|
335
|
+
`getComponent` returns a [Component](#5-component) class.
|
|
378
336
|
```js
|
|
379
|
-
kf.app.page.
|
|
337
|
+
const componentName = await kf.app.page.getComponent("componentId");
|
|
380
338
|
```
|
|
381
339
|
|
|
382
|
-
#####
|
|
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
|
+
```
|
|
383
346
|
|
|
384
|
-
|
|
347
|
+
### 5) Component
|
|
385
348
|
|
|
386
349
|
```js
|
|
387
|
-
kf.app.page.
|
|
350
|
+
const component = await kf.app.page.getComponent(componentId);
|
|
388
351
|
```
|
|
352
|
+
By using component instance we can invoke following methods.
|
|
389
353
|
|
|
390
|
-
|
|
354
|
+
##### Refresh a component
|
|
355
|
+
```js
|
|
356
|
+
component.refresh();
|
|
357
|
+
```
|
|
391
358
|
|
|
392
|
-
|
|
359
|
+
##### Show a component
|
|
360
|
+
```js
|
|
361
|
+
componentName.show();
|
|
362
|
+
```
|
|
393
363
|
|
|
394
|
-
|
|
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.
|
|
395
371
|
|
|
372
|
+
##### Popup parameters
|
|
396
373
|
```js
|
|
397
|
-
kf.
|
|
398
|
-
|
|
399
|
-
|
|
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
|
+
}
|
|
400
384
|
```
|
|
401
385
|
|
|
402
|
-
|
|
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
|
+
```
|
|
403
392
|
|
|
404
|
-
###
|
|
393
|
+
### 7) Formatter
|
|
405
394
|
|
|
406
395
|
##### Format to KF Date
|
|
407
396
|
|
|
@@ -453,4 +442,3 @@ let value = await kf.formatter.toBoolean("0");
|
|
|
453
442
|
let value = await kf.formatter.toBoolean("false");
|
|
454
443
|
```
|
|
455
444
|
|
|
456
|
-
---
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
|
|
2
|
+
declare class Component {
|
|
3
|
+
_id: string
|
|
4
|
+
type: string
|
|
5
|
+
refresh(): any;
|
|
6
|
+
show(): any;
|
|
7
|
+
hide(): any;
|
|
8
|
+
}
|
|
9
|
+
declare class Popup {
|
|
10
|
+
_id: string
|
|
11
|
+
type: string
|
|
12
|
+
getParameter(key: string): any;
|
|
13
|
+
getAllParameters(): any;
|
|
14
|
+
close(): any;
|
|
15
|
+
getComponent(componentId: string): Component;
|
|
16
|
+
}
|
|
17
|
+
declare class Page {
|
|
18
|
+
_id: string
|
|
19
|
+
popup: Popup
|
|
20
|
+
type: string
|
|
21
|
+
getParameter(key: string): any;
|
|
22
|
+
getAllParameters(): any;
|
|
23
|
+
getVariable(key: string): any;
|
|
24
|
+
setVariable(key: string, value: any): any;
|
|
25
|
+
openPopup(popupId: string, popupParams: object): any;
|
|
26
|
+
getComponent(componentId: string): Component;
|
|
27
|
+
}
|
|
28
|
+
declare class Application {
|
|
29
|
+
page: Page
|
|
30
|
+
_id: string
|
|
31
|
+
getVariable(key: string): any;
|
|
32
|
+
setVariable(key: string | object, value: any): any;
|
|
33
|
+
openPage(pageId: string, pageParams: object): any;
|
|
34
|
+
}
|
|
35
|
+
declare class Client {
|
|
36
|
+
showInfo(message: string): any;
|
|
37
|
+
showConfirm(args: {
|
|
38
|
+
title: string;
|
|
39
|
+
content: string;
|
|
40
|
+
okText: string;
|
|
41
|
+
cancelText: string;
|
|
42
|
+
}): any;
|
|
43
|
+
redirect(url: string): any;
|
|
44
|
+
}
|
|
45
|
+
declare class Form {
|
|
46
|
+
type: string
|
|
47
|
+
toJSON(): any;
|
|
48
|
+
getField(fieldId: string): any;
|
|
49
|
+
updateField(args: object): any;
|
|
50
|
+
getTable(tableId: string): Table;
|
|
51
|
+
}
|
|
52
|
+
declare class Table {
|
|
53
|
+
toJSON(): any;
|
|
54
|
+
getRows(): TableForm[];
|
|
55
|
+
getRow(rowId: string): TableForm;
|
|
56
|
+
addRow(rowObject: object): any;
|
|
57
|
+
deleteRow(rowId: string): any;
|
|
58
|
+
}
|
|
59
|
+
declare class TableForm {
|
|
60
|
+
type: string
|
|
61
|
+
getParent(): Form;
|
|
62
|
+
toJSON(): any;
|
|
63
|
+
getField(fieldId: string): any;
|
|
64
|
+
updateField(args: object): any;
|
|
65
|
+
}
|
|
66
|
+
declare class Formatter {
|
|
67
|
+
toDate(date: string): any;
|
|
68
|
+
toDateTime(date: string): any;
|
|
69
|
+
toNumber(value: string): any;
|
|
70
|
+
toCurrency(value: string, currencyCode: string): any;
|
|
71
|
+
toBoolean(value: string): any;
|
|
72
|
+
}
|
|
73
|
+
declare class kf {
|
|
74
|
+
static context: Component
|
|
75
|
+
static client: Client
|
|
76
|
+
static formatter: Formatter
|
|
77
|
+
static app: Application
|
|
78
|
+
static user: userObject
|
|
79
|
+
static env: environmentObject
|
|
80
|
+
static account: accountObject
|
|
81
|
+
api(url: string, args?: {
|
|
82
|
+
headers: object;
|
|
83
|
+
}): Promise<any>;
|
|
84
|
+
}
|
|
85
|
+
declare type userObject = {
|
|
86
|
+
_id: string;
|
|
87
|
+
Name: string;
|
|
88
|
+
Email: string;
|
|
89
|
+
UserType: string;
|
|
90
|
+
Role: string;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
declare type accountObject = {
|
|
94
|
+
_id: string;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
declare type environmentObject = {
|
|
98
|
+
isMobile: boolean
|
|
99
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
declare module "constants" {
|
|
2
|
+
export const LISTENER_CMDS: {
|
|
3
|
+
API: string;
|
|
4
|
+
PARAMS: string;
|
|
5
|
+
GET_CONTEXT: string;
|
|
6
|
+
RETURN: string;
|
|
7
|
+
GET_FORM_FIELD: string;
|
|
8
|
+
UPDATE_FORM: string;
|
|
9
|
+
GET_TABLE: string;
|
|
10
|
+
GET_TABLE_ROW: string;
|
|
11
|
+
ADD_TABLE_ROW: string;
|
|
12
|
+
DELETE_TABLE_ROW: string;
|
|
13
|
+
TO_JSON: string;
|
|
14
|
+
GET_TABLE_ROWS: string;
|
|
15
|
+
MESSAGE: string;
|
|
16
|
+
CONFIRM: string;
|
|
17
|
+
ALERT: string;
|
|
18
|
+
REDIRECT: string;
|
|
19
|
+
OPEN_PAGE: string;
|
|
20
|
+
FORMAT_DATE: string;
|
|
21
|
+
FORMAT_DATE_TIME: string;
|
|
22
|
+
FORMAT_NUMBER: string;
|
|
23
|
+
FORMAT_CURRENCY: string;
|
|
24
|
+
FORMAT_BOOLEAN: string;
|
|
25
|
+
GET_APP_VARIABLE: string;
|
|
26
|
+
SET_APP_VARIABLE: string;
|
|
27
|
+
GET_PAGE_VARIABLE: string;
|
|
28
|
+
SET_PAGE_VARIABLE: string;
|
|
29
|
+
GET_PAGE_PARAMS: string;
|
|
30
|
+
GET_ALL_PAGE_PARAMS: string;
|
|
31
|
+
PAGE_ON_CLOSE: string;
|
|
32
|
+
OPEN_POPUP: string;
|
|
33
|
+
GET_POPUP_PARAMS: string;
|
|
34
|
+
GET_ALL_POPUP_PARAMS: string;
|
|
35
|
+
CLOSE_POPUP: string;
|
|
36
|
+
GET_COMPONENT: string;
|
|
37
|
+
COMPONENT_REFRESH: string;
|
|
38
|
+
COMPONENT_SHOW: string;
|
|
39
|
+
COMPONENT_HIDE: string;
|
|
40
|
+
INITIALIZE_CUST_COMP: string;
|
|
41
|
+
};
|
|
42
|
+
export const EVENT_TYPES: {
|
|
43
|
+
ON_CLOSE: string;
|
|
44
|
+
POPUP_ON_CLOSE: string;
|
|
45
|
+
ON_CHANGE: string;
|
|
46
|
+
ON_LOAD: string;
|
|
47
|
+
};
|
|
48
|
+
export const DEFAULTS: {
|
|
49
|
+
POPUP_ID: string;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
declare module "base" {
|
|
53
|
+
export class BaseSDK {
|
|
54
|
+
#private;
|
|
55
|
+
constructor(props: any);
|
|
56
|
+
_postMessageAsync(command: string, args: any, hasCallBack?: boolean, callBack?: (data: any) => {}): object | string | any;
|
|
57
|
+
_postMessage(command: string, func: (data: any) => {}, args?: {}): void;
|
|
58
|
+
_registerEventListener(_id: string, eventType: string, callback: any): void;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
declare module "types/external" {
|
|
62
|
+
export type userObject = {
|
|
63
|
+
_id: string;
|
|
64
|
+
Name: string;
|
|
65
|
+
Email: string;
|
|
66
|
+
UserType: string;
|
|
67
|
+
Role: string;
|
|
68
|
+
};
|
|
69
|
+
export type accountObject = {
|
|
70
|
+
_id: string;
|
|
71
|
+
};
|
|
72
|
+
export type environmentObject = {
|
|
73
|
+
isMobile: boolean;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
declare module "types/internal" {
|
|
77
|
+
import { userObject, accountObject, environmentObject } from "types/external";
|
|
78
|
+
export interface SDKContext {
|
|
79
|
+
formInstanceId: string;
|
|
80
|
+
tableId: string;
|
|
81
|
+
tableRowId: string;
|
|
82
|
+
componentId: string;
|
|
83
|
+
manifestMethods?: manifestMethodsType[];
|
|
84
|
+
appId: string;
|
|
85
|
+
pageId: string;
|
|
86
|
+
popupId: string;
|
|
87
|
+
user: userObject;
|
|
88
|
+
account: accountObject;
|
|
89
|
+
csrfToken: string;
|
|
90
|
+
envDetails: environmentObject;
|
|
91
|
+
}
|
|
92
|
+
export interface manifestMethodsType {
|
|
93
|
+
name: string;
|
|
94
|
+
returnType?: string;
|
|
95
|
+
parameters?: string[];
|
|
96
|
+
}
|
|
97
|
+
export interface ComponentProps {
|
|
98
|
+
componentId: string;
|
|
99
|
+
manifestMethods?: manifestMethodsType[];
|
|
100
|
+
}
|
|
101
|
+
export interface AppContext {
|
|
102
|
+
appId: string;
|
|
103
|
+
pageId: string;
|
|
104
|
+
}
|
|
105
|
+
export interface PageContext {
|
|
106
|
+
pageId: string;
|
|
107
|
+
}
|
|
108
|
+
export interface PopupContext {
|
|
109
|
+
popupId?: string;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
declare module "component" {
|
|
113
|
+
import { BaseSDK } from "base";
|
|
114
|
+
import { ComponentProps } from "types/internal";
|
|
115
|
+
export class Component extends BaseSDK {
|
|
116
|
+
_id: string;
|
|
117
|
+
type: string;
|
|
118
|
+
constructor(props: ComponentProps);
|
|
119
|
+
refresh(): any;
|
|
120
|
+
show(): any;
|
|
121
|
+
hide(): any;
|
|
122
|
+
}
|
|
123
|
+
export class CustomComponent extends BaseSDK {
|
|
124
|
+
type: string;
|
|
125
|
+
constructor();
|
|
126
|
+
watchParams(func: (data: any) => any): void;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
declare module "popup" {
|
|
130
|
+
import { Component } from "component";
|
|
131
|
+
import { BaseSDK } from "base";
|
|
132
|
+
import { PopupContext } from "types/internal";
|
|
133
|
+
export class Popup extends BaseSDK {
|
|
134
|
+
_id: string;
|
|
135
|
+
type: string;
|
|
136
|
+
constructor(props: PopupContext);
|
|
137
|
+
getParameter(key: string): any;
|
|
138
|
+
getAllParameters(): any;
|
|
139
|
+
close(): any;
|
|
140
|
+
getComponent(componentId: string): Component;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
declare module "page" {
|
|
144
|
+
import { Component } from "component";
|
|
145
|
+
import { BaseSDK } from "base";
|
|
146
|
+
import { Popup } from "popup";
|
|
147
|
+
import { PageContext } from "types/internal";
|
|
148
|
+
export class Page extends BaseSDK {
|
|
149
|
+
_id: string;
|
|
150
|
+
popup: Popup;
|
|
151
|
+
type: string;
|
|
152
|
+
constructor(props: PageContext);
|
|
153
|
+
getParameter(key: string): any;
|
|
154
|
+
getAllParameters(): any;
|
|
155
|
+
getVariable(key: string): any;
|
|
156
|
+
setVariable(key: string, value: any): any;
|
|
157
|
+
openPopup(popupId: string, popupParams: object): any;
|
|
158
|
+
getComponent(componentId: string): Component;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
declare module "app" {
|
|
162
|
+
import { BaseSDK } from "base";
|
|
163
|
+
import { Page } from "page";
|
|
164
|
+
import { AppContext } from "types/internal";
|
|
165
|
+
export class Application extends BaseSDK {
|
|
166
|
+
page: Page;
|
|
167
|
+
_id: string;
|
|
168
|
+
constructor(props: AppContext);
|
|
169
|
+
getVariable(key: string): any;
|
|
170
|
+
setVariable(key: string | object, value: any): any;
|
|
171
|
+
openPage(pageId: string, pageParams: object): any;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
declare module "client" {
|
|
175
|
+
import { BaseSDK } from "base";
|
|
176
|
+
export class Client extends BaseSDK {
|
|
177
|
+
showInfo(message: string): any;
|
|
178
|
+
showConfirm(args: {
|
|
179
|
+
title: string;
|
|
180
|
+
content: string;
|
|
181
|
+
okText: string;
|
|
182
|
+
cancelText: string;
|
|
183
|
+
}): any;
|
|
184
|
+
redirect(url: string): any;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
declare module "form" {
|
|
188
|
+
import { BaseSDK } from "base";
|
|
189
|
+
export class Form extends BaseSDK {
|
|
190
|
+
private instanceId;
|
|
191
|
+
type: string;
|
|
192
|
+
constructor(instanceId: string);
|
|
193
|
+
toJSON(): any;
|
|
194
|
+
getField(fieldId: string): any;
|
|
195
|
+
updateField(args: object): any;
|
|
196
|
+
getTable(tableId: string): Table;
|
|
197
|
+
}
|
|
198
|
+
class Table extends BaseSDK {
|
|
199
|
+
private tableId;
|
|
200
|
+
private instanceId;
|
|
201
|
+
constructor(instanceId: string, tableId: string);
|
|
202
|
+
toJSON(): any;
|
|
203
|
+
getRows(): TableForm[];
|
|
204
|
+
getRow(rowId: string): TableForm;
|
|
205
|
+
addRow(rowObject: object): any;
|
|
206
|
+
deleteRow(rowId: string): any;
|
|
207
|
+
}
|
|
208
|
+
export class TableForm extends BaseSDK {
|
|
209
|
+
private instanceId;
|
|
210
|
+
private tableId;
|
|
211
|
+
private rowId;
|
|
212
|
+
type: string;
|
|
213
|
+
constructor(instanceId: string, tableId: string, rowId: string);
|
|
214
|
+
getParent(): Form;
|
|
215
|
+
toJSON(): any;
|
|
216
|
+
getField(fieldId: string): any;
|
|
217
|
+
updateField(args: object): any;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
declare module "formatter" {
|
|
221
|
+
import { BaseSDK } from "base";
|
|
222
|
+
export class Formatter extends BaseSDK {
|
|
223
|
+
toDate(date: string): any;
|
|
224
|
+
toDateTime(date: string): any;
|
|
225
|
+
toNumber(value: string): any;
|
|
226
|
+
toCurrency(value: string, currencyCode: string): any;
|
|
227
|
+
toBoolean(value: string): any;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
declare module "index" {
|
|
231
|
+
import { BaseSDK } from "base";
|
|
232
|
+
import { Client } from "client";
|
|
233
|
+
import { Formatter } from "formatter";
|
|
234
|
+
import { Application } from "app";
|
|
235
|
+
import { Page } from "page";
|
|
236
|
+
import { CustomComponent } from "component";
|
|
237
|
+
import { userObject, accountObject, environmentObject } from "types/external";
|
|
238
|
+
class CustomComponentSDK extends BaseSDK {
|
|
239
|
+
app: Application;
|
|
240
|
+
page: Page;
|
|
241
|
+
user: userObject;
|
|
242
|
+
account: accountObject;
|
|
243
|
+
context: CustomComponent;
|
|
244
|
+
client: Client;
|
|
245
|
+
formatter: Formatter;
|
|
246
|
+
env: environmentObject;
|
|
247
|
+
constructor();
|
|
248
|
+
api(url: string, args?: {}): string | object;
|
|
249
|
+
initialize(): any;
|
|
250
|
+
initialise(): any;
|
|
251
|
+
}
|
|
252
|
+
const _default: CustomComponentSDK;
|
|
253
|
+
export default _default;
|
|
254
|
+
}
|
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
|
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
declare module "constants" {
|
|
2
|
+
export const LISTENER_CMDS: {
|
|
3
|
+
API: string;
|
|
4
|
+
PARAMS: string;
|
|
5
|
+
GET_CONTEXT: string;
|
|
6
|
+
RETURN: string;
|
|
7
|
+
GET_FORM_FIELD: string;
|
|
8
|
+
UPDATE_FORM: string;
|
|
9
|
+
GET_TABLE: string;
|
|
10
|
+
GET_TABLE_ROW: string;
|
|
11
|
+
ADD_TABLE_ROW: string;
|
|
12
|
+
DELETE_TABLE_ROW: string;
|
|
13
|
+
TO_JSON: string;
|
|
14
|
+
GET_TABLE_ROWS: string;
|
|
15
|
+
MESSAGE: string;
|
|
16
|
+
CONFIRM: string;
|
|
17
|
+
ALERT: string;
|
|
18
|
+
REDIRECT: string;
|
|
19
|
+
OPEN_PAGE: string;
|
|
20
|
+
FORMAT_DATE: string;
|
|
21
|
+
FORMAT_DATE_TIME: string;
|
|
22
|
+
FORMAT_NUMBER: string;
|
|
23
|
+
FORMAT_CURRENCY: string;
|
|
24
|
+
FORMAT_BOOLEAN: string;
|
|
25
|
+
GET_APP_VARIABLE: string;
|
|
26
|
+
SET_APP_VARIABLE: string;
|
|
27
|
+
GET_PAGE_VARIABLE: string;
|
|
28
|
+
SET_PAGE_VARIABLE: string;
|
|
29
|
+
GET_PAGE_PARAMS: string;
|
|
30
|
+
GET_ALL_PAGE_PARAMS: string;
|
|
31
|
+
PAGE_ON_CLOSE: string;
|
|
32
|
+
OPEN_POPUP: string;
|
|
33
|
+
GET_POPUP_PARAMS: string;
|
|
34
|
+
GET_ALL_POPUP_PARAMS: string;
|
|
35
|
+
CLOSE_POPUP: string;
|
|
36
|
+
GET_COMPONENT: string;
|
|
37
|
+
COMPONENT_REFRESH: string;
|
|
38
|
+
COMPONENT_SHOW: string;
|
|
39
|
+
COMPONENT_HIDE: string;
|
|
40
|
+
INITIALIZE_CUST_COMP: string;
|
|
41
|
+
};
|
|
42
|
+
export const EVENT_TYPES: {
|
|
43
|
+
ON_CLOSE: string;
|
|
44
|
+
POPUP_ON_CLOSE: string;
|
|
45
|
+
ON_CHANGE: string;
|
|
46
|
+
ON_LOAD: string;
|
|
47
|
+
};
|
|
48
|
+
export const DEFAULTS: {
|
|
49
|
+
POPUP_ID: string;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
declare module "base" {
|
|
53
|
+
export class BaseSDK {
|
|
54
|
+
#private;
|
|
55
|
+
constructor(props: any);
|
|
56
|
+
_postMessageAsync(command: string, args: any, hasCallBack?: boolean, callBack?: (data: any) => {}): object | string | any;
|
|
57
|
+
_postMessage(command: string, func: (data: any) => {}, args?: {}): void;
|
|
58
|
+
_registerEventListener(_id: string, eventType: string, callback: any): void;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
declare module "types/external" {
|
|
62
|
+
export type userObject = {
|
|
63
|
+
_id: string;
|
|
64
|
+
Name: string;
|
|
65
|
+
Email: string;
|
|
66
|
+
UserType: string;
|
|
67
|
+
Role: string;
|
|
68
|
+
};
|
|
69
|
+
export type accountObject = {
|
|
70
|
+
_id: string;
|
|
71
|
+
};
|
|
72
|
+
export type environmentObject = {
|
|
73
|
+
isMobile: boolean;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
declare module "types/internal" {
|
|
77
|
+
import { userObject, accountObject, environmentObject } from "types/external";
|
|
78
|
+
export interface SDKContext {
|
|
79
|
+
formInstanceId: string;
|
|
80
|
+
tableId: string;
|
|
81
|
+
tableRowId: string;
|
|
82
|
+
componentId: string;
|
|
83
|
+
manifestMethods?: manifestMethodsType[];
|
|
84
|
+
appId: string;
|
|
85
|
+
pageId: string;
|
|
86
|
+
popupId: string;
|
|
87
|
+
user: userObject;
|
|
88
|
+
account: accountObject;
|
|
89
|
+
csrfToken: string;
|
|
90
|
+
envDetails: environmentObject;
|
|
91
|
+
}
|
|
92
|
+
export interface manifestMethodsType {
|
|
93
|
+
name: string;
|
|
94
|
+
returnType?: string;
|
|
95
|
+
parameters?: string[];
|
|
96
|
+
}
|
|
97
|
+
export interface ComponentProps {
|
|
98
|
+
componentId: string;
|
|
99
|
+
manifestMethods?: manifestMethodsType[];
|
|
100
|
+
}
|
|
101
|
+
export interface AppContext {
|
|
102
|
+
appId: string;
|
|
103
|
+
pageId: string;
|
|
104
|
+
}
|
|
105
|
+
export interface PageContext {
|
|
106
|
+
pageId: string;
|
|
107
|
+
}
|
|
108
|
+
export interface PopupContext {
|
|
109
|
+
popupId?: string;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
declare module "component" {
|
|
113
|
+
import { BaseSDK } from "base";
|
|
114
|
+
import { ComponentProps } from "types/internal";
|
|
115
|
+
export class Component extends BaseSDK {
|
|
116
|
+
_id: string;
|
|
117
|
+
type: string;
|
|
118
|
+
constructor(props: ComponentProps);
|
|
119
|
+
refresh(): any;
|
|
120
|
+
show(): any;
|
|
121
|
+
hide(): any;
|
|
122
|
+
}
|
|
123
|
+
export class CustomComponent extends BaseSDK {
|
|
124
|
+
type: string;
|
|
125
|
+
constructor();
|
|
126
|
+
watchParams(func: (data: any) => any): void;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
declare module "popup" {
|
|
130
|
+
import { Component } from "component";
|
|
131
|
+
import { BaseSDK } from "base";
|
|
132
|
+
import { PopupContext } from "types/internal";
|
|
133
|
+
export class Popup extends BaseSDK {
|
|
134
|
+
_id: string;
|
|
135
|
+
type: string;
|
|
136
|
+
constructor(props: PopupContext);
|
|
137
|
+
getParameter(key: string): any;
|
|
138
|
+
getAllParameters(): any;
|
|
139
|
+
close(): any;
|
|
140
|
+
getComponent(componentId: string): Component;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
declare module "page" {
|
|
144
|
+
import { Component } from "component";
|
|
145
|
+
import { BaseSDK } from "base";
|
|
146
|
+
import { Popup } from "popup";
|
|
147
|
+
import { PageContext } from "types/internal";
|
|
148
|
+
export class Page extends BaseSDK {
|
|
149
|
+
_id: string;
|
|
150
|
+
popup: Popup;
|
|
151
|
+
type: string;
|
|
152
|
+
constructor(props: PageContext);
|
|
153
|
+
getParameter(key: string): any;
|
|
154
|
+
getAllParameters(): any;
|
|
155
|
+
getVariable(key: string): any;
|
|
156
|
+
setVariable(key: string, value: any): any;
|
|
157
|
+
openPopup(popupId: string, popupParams: object): any;
|
|
158
|
+
getComponent(componentId: string): Component;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
declare module "app" {
|
|
162
|
+
import { BaseSDK } from "base";
|
|
163
|
+
import { Page } from "page";
|
|
164
|
+
import { AppContext } from "types/internal";
|
|
165
|
+
export class Application extends BaseSDK {
|
|
166
|
+
page: Page;
|
|
167
|
+
_id: string;
|
|
168
|
+
constructor(props: AppContext);
|
|
169
|
+
getVariable(key: string): any;
|
|
170
|
+
setVariable(key: string | object, value: any): any;
|
|
171
|
+
openPage(pageId: string, pageParams: object): any;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
declare module "client" {
|
|
175
|
+
import { BaseSDK } from "base";
|
|
176
|
+
export class Client extends BaseSDK {
|
|
177
|
+
showInfo(message: string): any;
|
|
178
|
+
showConfirm(args: {
|
|
179
|
+
title: string;
|
|
180
|
+
content: string;
|
|
181
|
+
okText: string;
|
|
182
|
+
cancelText: string;
|
|
183
|
+
}): any;
|
|
184
|
+
redirect(url: string): any;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
declare module "form" {
|
|
188
|
+
import { BaseSDK } from "base";
|
|
189
|
+
export class Form extends BaseSDK {
|
|
190
|
+
private instanceId;
|
|
191
|
+
type: string;
|
|
192
|
+
constructor(instanceId: string);
|
|
193
|
+
toJSON(): any;
|
|
194
|
+
getField(fieldId: string): any;
|
|
195
|
+
updateField(args: object): any;
|
|
196
|
+
getTable(tableId: string): Table;
|
|
197
|
+
}
|
|
198
|
+
class Table extends BaseSDK {
|
|
199
|
+
private tableId;
|
|
200
|
+
private instanceId;
|
|
201
|
+
constructor(instanceId: string, tableId: string);
|
|
202
|
+
toJSON(): any;
|
|
203
|
+
getRows(): TableForm[];
|
|
204
|
+
getRow(rowId: string): TableForm;
|
|
205
|
+
addRow(rowObject: object): any;
|
|
206
|
+
deleteRow(rowId: string): any;
|
|
207
|
+
}
|
|
208
|
+
export class TableForm extends BaseSDK {
|
|
209
|
+
private instanceId;
|
|
210
|
+
private tableId;
|
|
211
|
+
private rowId;
|
|
212
|
+
type: string;
|
|
213
|
+
constructor(instanceId: string, tableId: string, rowId: string);
|
|
214
|
+
getParent(): Form;
|
|
215
|
+
toJSON(): any;
|
|
216
|
+
getField(fieldId: string): any;
|
|
217
|
+
updateField(args: object): any;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
declare module "formatter" {
|
|
221
|
+
import { BaseSDK } from "base";
|
|
222
|
+
export class Formatter extends BaseSDK {
|
|
223
|
+
toDate(date: string): any;
|
|
224
|
+
toDateTime(date: string): any;
|
|
225
|
+
toNumber(value: string): any;
|
|
226
|
+
toCurrency(value: string, currencyCode: string): any;
|
|
227
|
+
toBoolean(value: string): any;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
declare module "lowcode" {
|
|
231
|
+
import { BaseSDK } from "base";
|
|
232
|
+
import { Form } from "form";
|
|
233
|
+
import { TableForm } from "form";
|
|
234
|
+
import { Client } from "client";
|
|
235
|
+
import { Formatter } from "formatter";
|
|
236
|
+
import { Application } from "app";
|
|
237
|
+
import { Page } from "page";
|
|
238
|
+
import { Component } from "component";
|
|
239
|
+
import { Popup } from "popup";
|
|
240
|
+
import { SDKContext } from "types/internal";
|
|
241
|
+
import { userObject, accountObject, environmentObject } from "types/external";
|
|
242
|
+
class LowcodeSDK extends BaseSDK {
|
|
243
|
+
#private;
|
|
244
|
+
context: Component | Form | TableForm | Page | Popup;
|
|
245
|
+
client: Client;
|
|
246
|
+
formatter: Formatter;
|
|
247
|
+
app: Application;
|
|
248
|
+
user: userObject;
|
|
249
|
+
env: environmentObject;
|
|
250
|
+
account: accountObject;
|
|
251
|
+
constructor(props: SDKContext);
|
|
252
|
+
api(url: string, args?: {
|
|
253
|
+
headers: object;
|
|
254
|
+
}): Promise<any>;
|
|
255
|
+
}
|
|
256
|
+
function initSDK(config: SDKContext): LowcodeSDK;
|
|
257
|
+
export default initSDK;
|
|
258
|
+
}
|
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
|
+
}
|