@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.
@@ -20,7 +20,7 @@ var __privateMethod = (obj, member, method) => {
20
20
  __accessCheck(obj, member, "access private method");
21
21
  return method;
22
22
  };
23
- var _listeners, _registerComponentAPIs, registerComponentAPIs_fn, _csrfToken;
23
+ var _listeners, _textEncoder, _textDecoder, _registerComponentAPIs, registerComponentAPIs_fn, _csrfToken;
24
24
  let nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
25
25
  byte &= 63;
26
26
  if (byte < 36) {
@@ -81,7 +81,8 @@ const LISTENER_CMDS = {
81
81
  WINDOW_NDEF_READER_ADD_EVENT_LISTENER: "WINDOW_NDEF_READER_ADD_EVENT_LISTENER",
82
82
  WINDOW_NDEF_READER_MAKE_READONLY: "WINDOW_NDEF_READER_MAKE_READONLY",
83
83
  WINDOW_NDEF_READER_ABORT_SCAN: "WINDOW_NDEF_READER_ABORT_SCAN",
84
- DECISION_TABLE_EXECUTE: "DECISION_TABLE_EXECUTE"
84
+ DECISION_TABLE_EXECUTE: "DECISION_TABLE_EXECUTE",
85
+ DATAFORM_IMPORT_CSV: "DATAFORM_IMPORT_CSV"
85
86
  };
86
87
  const EVENT_TYPES = {
87
88
  COMPONENT_ON_MOUNT: "componentOnMount",
@@ -94,6 +95,16 @@ function generateId(prefix = "lcncsdk") {
94
95
  return `${prefix}-${nanoid()}`;
95
96
  }
96
97
  const globalInstances = {};
98
+ function processResponse(req, resp) {
99
+ if (resp && Object.keys(resp).length === 1 && req.command !== LISTENER_CMDS.API) {
100
+ let value = Object.values(resp)[0];
101
+ if (value === "undefined")
102
+ return void 0;
103
+ return value;
104
+ } else {
105
+ return resp;
106
+ }
107
+ }
97
108
  function postMessage(args) {
98
109
  if (globalThis.parent && globalThis.parent !== globalThis) {
99
110
  globalThis.parent.postMessage(args, "*");
@@ -153,11 +164,8 @@ class EventBase {
153
164
  if (Array.isArray(__privateGet(this, _listeners)[target])) {
154
165
  __privateGet(this, _listeners)[target].forEach((listener) => {
155
166
  try {
156
- if (resp && Object.keys(resp).length === 1 && req.command !== LISTENER_CMDS.API) {
157
- listener(Object.values(resp)[0]);
158
- } else {
159
- listener(resp);
160
- }
167
+ let processedResp = processResponse(req, resp);
168
+ listener(processedResp);
161
169
  } catch (err) {
162
170
  console.error("Message callback error: ", err);
163
171
  }
@@ -192,7 +200,66 @@ class BaseSDK extends EventBase {
192
200
  this._addEventListener(args.eventName, callBack);
193
201
  }
194
202
  }
203
+ _postMessageSync(command, args) {
204
+ let intialValue = 0;
205
+ const _id = generateId(command.toLowerCase());
206
+ let data = { _id, command, ...args };
207
+ let atomics = new AtomicsHandler();
208
+ atomics.reset();
209
+ atomics.store(0, intialValue);
210
+ atomics.encodeData(1, data);
211
+ postMessage(atomics.sab);
212
+ atomics.wait(0, intialValue, 1e4);
213
+ let decodedData = atomics.decodeData();
214
+ let { _req: req, resp } = decodedData;
215
+ let processedResp = processResponse(req, resp);
216
+ if (processedResp == null ? void 0 : processedResp.isError) {
217
+ throw new Error(`Error: ${JSON.stringify(processedResp, null, 2)}`);
218
+ }
219
+ return processedResp;
220
+ }
221
+ }
222
+ let sharedArrayBufferInstance;
223
+ class AtomicsHandler {
224
+ constructor() {
225
+ __privateAdd(this, _textEncoder, void 0);
226
+ __privateAdd(this, _textDecoder, void 0);
227
+ __privateSet(this, _textEncoder, new TextEncoder());
228
+ __privateSet(this, _textDecoder, new TextDecoder());
229
+ sharedArrayBufferInstance = sharedArrayBufferInstance || new SharedArrayBuffer(1024 * 1024);
230
+ this.sab = sharedArrayBufferInstance;
231
+ this.int32Array = new Int32Array(this.sab);
232
+ }
233
+ load(index = 0) {
234
+ return Atomics.load(this.int32Array, index);
235
+ }
236
+ store(index = 0, data) {
237
+ return Atomics.store(this.int32Array, index, data);
238
+ }
239
+ reset() {
240
+ return this.int32Array.fill(0);
241
+ }
242
+ notify(index = 0, count = 1) {
243
+ return Atomics.notify(this.int32Array, index, count);
244
+ }
245
+ wait(index, value, timeout) {
246
+ return Atomics.wait(this.int32Array, index, value, timeout);
247
+ }
248
+ encodeData(index = 0, data) {
249
+ const replacer = (key, value) => value === void 0 ? "undefined" : value;
250
+ let string = JSON.stringify(data, replacer);
251
+ let encodedData = __privateGet(this, _textEncoder).encode(string);
252
+ this.int32Array.set(encodedData, index);
253
+ return this.int32Array;
254
+ }
255
+ decodeData() {
256
+ let uInt8Array = new Uint8Array(this.int32Array);
257
+ let string = __privateGet(this, _textDecoder).decode(uInt8Array).replaceAll(/\x00/g, "");
258
+ return JSON.parse(string);
259
+ }
195
260
  }
261
+ _textEncoder = new WeakMap();
262
+ _textDecoder = new WeakMap();
196
263
  class Form extends BaseSDK {
197
264
  constructor(instanceId) {
198
265
  super();
@@ -350,6 +417,28 @@ class Formatter extends BaseSDK {
350
417
  });
351
418
  }
352
419
  }
420
+ const isObject = (value) => value !== null && typeof value === "object";
421
+ class CreateProxy {
422
+ constructor(parent, target = {}, path = []) {
423
+ this.parent = parent;
424
+ this.path = path;
425
+ return new Proxy(target, this);
426
+ }
427
+ get(target, property) {
428
+ let value = this.parent.get(property, this.path);
429
+ if (isObject(value)) {
430
+ return new CreateProxy(this.parent, value, [...this.path, property]);
431
+ }
432
+ return value;
433
+ }
434
+ set(target, property, value, reciever) {
435
+ let updatedValue = this.parent.set(property, value, this.path);
436
+ if (isObject(updatedValue)) {
437
+ return new CreateProxy(this.parent, updatedValue, [...this.path, property]);
438
+ }
439
+ return updatedValue;
440
+ }
441
+ }
353
442
  class Component extends BaseSDK {
354
443
  constructor(props) {
355
444
  super();
@@ -448,6 +537,7 @@ class Page extends BaseSDK {
448
537
  this.type = "Page";
449
538
  this.popup = new Popup({});
450
539
  this._id = props.pageId;
540
+ this.variable = new PageVariable();
451
541
  }
452
542
  getParameter(key) {
453
543
  return this._postMessageAsync(LISTENER_CMDS.GET_PAGE_PARAMS, {
@@ -485,6 +575,27 @@ class Page extends BaseSDK {
485
575
  );
486
576
  }
487
577
  }
578
+ class PageVariable extends BaseSDK {
579
+ constructor() {
580
+ super();
581
+ return new CreateProxy(this);
582
+ }
583
+ get(key, path) {
584
+ let args = {
585
+ key,
586
+ path
587
+ };
588
+ return this._postMessageSync(LISTENER_CMDS.GET_PAGE_VARIABLE, args);
589
+ }
590
+ set(key, value, path) {
591
+ let args = {
592
+ key,
593
+ value,
594
+ path
595
+ };
596
+ return this._postMessageSync(LISTENER_CMDS.SET_PAGE_VARIABLE, args);
597
+ }
598
+ }
488
599
  class DecisionTable extends BaseSDK {
489
600
  constructor(flowId) {
490
601
  super();
@@ -497,11 +608,24 @@ class DecisionTable extends BaseSDK {
497
608
  });
498
609
  }
499
610
  }
611
+ class Dataform extends BaseSDK {
612
+ constructor(flowId) {
613
+ super();
614
+ this._id = flowId;
615
+ }
616
+ importCSV(defaultValues) {
617
+ return this._postMessageAsync(LISTENER_CMDS.DATAFORM_IMPORT_CSV, {
618
+ flowId: this._id,
619
+ defaultValues
620
+ });
621
+ }
622
+ }
500
623
  class Application extends BaseSDK {
501
624
  constructor(props) {
502
625
  super();
503
626
  this._id = props.appId;
504
627
  this.page = new Page(props);
628
+ this.variable = new AppVariable();
505
629
  }
506
630
  getVariable(key) {
507
631
  return this._postMessageAsync(LISTENER_CMDS.GET_APP_VARIABLE, {
@@ -523,6 +647,30 @@ class Application extends BaseSDK {
523
647
  getDecisionTable(flowId) {
524
648
  return new DecisionTable(flowId);
525
649
  }
650
+ getDataform(flowId) {
651
+ return new Dataform(flowId);
652
+ }
653
+ }
654
+ class AppVariable extends BaseSDK {
655
+ constructor() {
656
+ super();
657
+ return new CreateProxy(this);
658
+ }
659
+ get(key, path) {
660
+ let args = {
661
+ key,
662
+ path
663
+ };
664
+ return this._postMessageSync(LISTENER_CMDS.GET_APP_VARIABLE, args);
665
+ }
666
+ set(key, value, path) {
667
+ let args = {
668
+ key,
669
+ value,
670
+ path
671
+ };
672
+ return this._postMessageSync(LISTENER_CMDS.SET_APP_VARIABLE, args);
673
+ }
526
674
  }
527
675
  class NDEFReader extends BaseSDK {
528
676
  constructor() {
@@ -16,7 +16,7 @@ var __privateSet = (obj, member, value, setter) => {
16
16
  setter ? setter.call(obj, value) : member.set(obj, value);
17
17
  return value;
18
18
  };
19
- var _listeners, _csrfToken;
19
+ var _listeners, _textEncoder, _textDecoder, _csrfToken;
20
20
  let nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
21
21
  byte &= 63;
22
22
  if (byte < 36) {
@@ -77,12 +77,23 @@ const LISTENER_CMDS = {
77
77
  WINDOW_NDEF_READER_ADD_EVENT_LISTENER: "WINDOW_NDEF_READER_ADD_EVENT_LISTENER",
78
78
  WINDOW_NDEF_READER_MAKE_READONLY: "WINDOW_NDEF_READER_MAKE_READONLY",
79
79
  WINDOW_NDEF_READER_ABORT_SCAN: "WINDOW_NDEF_READER_ABORT_SCAN",
80
- DECISION_TABLE_EXECUTE: "DECISION_TABLE_EXECUTE"
80
+ DECISION_TABLE_EXECUTE: "DECISION_TABLE_EXECUTE",
81
+ DATAFORM_IMPORT_CSV: "DATAFORM_IMPORT_CSV"
81
82
  };
82
83
  function generateId(prefix = "lcncsdk") {
83
84
  return `${prefix}-${nanoid()}`;
84
85
  }
85
86
  const globalInstances = {};
87
+ function processResponse(req, resp) {
88
+ if (resp && Object.keys(resp).length === 1 && req.command !== LISTENER_CMDS.API) {
89
+ let value = Object.values(resp)[0];
90
+ if (value === "undefined")
91
+ return void 0;
92
+ return value;
93
+ } else {
94
+ return resp;
95
+ }
96
+ }
86
97
  function postMessage(args) {
87
98
  if (globalThis.parent && globalThis.parent !== globalThis) {
88
99
  globalThis.parent.postMessage(args, "*");
@@ -142,11 +153,8 @@ class EventBase {
142
153
  if (Array.isArray(__privateGet(this, _listeners)[target])) {
143
154
  __privateGet(this, _listeners)[target].forEach((listener) => {
144
155
  try {
145
- if (resp && Object.keys(resp).length === 1 && req.command !== LISTENER_CMDS.API) {
146
- listener(Object.values(resp)[0]);
147
- } else {
148
- listener(resp);
149
- }
156
+ let processedResp = processResponse(req, resp);
157
+ listener(processedResp);
150
158
  } catch (err) {
151
159
  console.error("Message callback error: ", err);
152
160
  }
@@ -181,7 +189,66 @@ class BaseSDK extends EventBase {
181
189
  this._addEventListener(args.eventName, callBack);
182
190
  }
183
191
  }
192
+ _postMessageSync(command, args) {
193
+ let intialValue = 0;
194
+ const _id = generateId(command.toLowerCase());
195
+ let data = { _id, command, ...args };
196
+ let atomics = new AtomicsHandler();
197
+ atomics.reset();
198
+ atomics.store(0, intialValue);
199
+ atomics.encodeData(1, data);
200
+ postMessage(atomics.sab);
201
+ atomics.wait(0, intialValue, 1e4);
202
+ let decodedData = atomics.decodeData();
203
+ let { _req: req, resp } = decodedData;
204
+ let processedResp = processResponse(req, resp);
205
+ if (processedResp == null ? void 0 : processedResp.isError) {
206
+ throw new Error(`Error: ${JSON.stringify(processedResp, null, 2)}`);
207
+ }
208
+ return processedResp;
209
+ }
210
+ }
211
+ let sharedArrayBufferInstance;
212
+ class AtomicsHandler {
213
+ constructor() {
214
+ __privateAdd(this, _textEncoder, void 0);
215
+ __privateAdd(this, _textDecoder, void 0);
216
+ __privateSet(this, _textEncoder, new TextEncoder());
217
+ __privateSet(this, _textDecoder, new TextDecoder());
218
+ sharedArrayBufferInstance = sharedArrayBufferInstance || new SharedArrayBuffer(1024 * 1024);
219
+ this.sab = sharedArrayBufferInstance;
220
+ this.int32Array = new Int32Array(this.sab);
221
+ }
222
+ load(index = 0) {
223
+ return Atomics.load(this.int32Array, index);
224
+ }
225
+ store(index = 0, data) {
226
+ return Atomics.store(this.int32Array, index, data);
227
+ }
228
+ reset() {
229
+ return this.int32Array.fill(0);
230
+ }
231
+ notify(index = 0, count = 1) {
232
+ return Atomics.notify(this.int32Array, index, count);
233
+ }
234
+ wait(index, value, timeout) {
235
+ return Atomics.wait(this.int32Array, index, value, timeout);
236
+ }
237
+ encodeData(index = 0, data) {
238
+ const replacer = (key, value) => value === void 0 ? "undefined" : value;
239
+ let string = JSON.stringify(data, replacer);
240
+ let encodedData = __privateGet(this, _textEncoder).encode(string);
241
+ this.int32Array.set(encodedData, index);
242
+ return this.int32Array;
243
+ }
244
+ decodeData() {
245
+ let uInt8Array = new Uint8Array(this.int32Array);
246
+ let string = __privateGet(this, _textDecoder).decode(uInt8Array).replaceAll(/\x00/g, "");
247
+ return JSON.parse(string);
248
+ }
184
249
  }
250
+ _textEncoder = new WeakMap();
251
+ _textDecoder = new WeakMap();
185
252
  class Form extends BaseSDK {
186
253
  constructor(instanceId) {
187
254
  super();
package/dist/kfsdk.es.js CHANGED
@@ -20,7 +20,7 @@ var __privateMethod = (obj, member, method) => {
20
20
  __accessCheck(obj, member, "access private method");
21
21
  return method;
22
22
  };
23
- var _listeners, _registerComponentAPIs, registerComponentAPIs_fn;
23
+ var _listeners, _textEncoder, _textDecoder, _registerComponentAPIs, registerComponentAPIs_fn;
24
24
  let nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
25
25
  byte &= 63;
26
26
  if (byte < 36) {
@@ -81,7 +81,8 @@ const LISTENER_CMDS = {
81
81
  WINDOW_NDEF_READER_ADD_EVENT_LISTENER: "WINDOW_NDEF_READER_ADD_EVENT_LISTENER",
82
82
  WINDOW_NDEF_READER_MAKE_READONLY: "WINDOW_NDEF_READER_MAKE_READONLY",
83
83
  WINDOW_NDEF_READER_ABORT_SCAN: "WINDOW_NDEF_READER_ABORT_SCAN",
84
- DECISION_TABLE_EXECUTE: "DECISION_TABLE_EXECUTE"
84
+ DECISION_TABLE_EXECUTE: "DECISION_TABLE_EXECUTE",
85
+ DATAFORM_IMPORT_CSV: "DATAFORM_IMPORT_CSV"
85
86
  };
86
87
  const EVENT_TYPES = {
87
88
  COMPONENT_ON_MOUNT: "componentOnMount",
@@ -94,6 +95,16 @@ function generateId(prefix = "lcncsdk") {
94
95
  return `${prefix}-${nanoid()}`;
95
96
  }
96
97
  const globalInstances = {};
98
+ function processResponse(req, resp) {
99
+ if (resp && Object.keys(resp).length === 1 && req.command !== LISTENER_CMDS.API) {
100
+ let value = Object.values(resp)[0];
101
+ if (value === "undefined")
102
+ return void 0;
103
+ return value;
104
+ } else {
105
+ return resp;
106
+ }
107
+ }
97
108
  function postMessage(args) {
98
109
  if (globalThis.parent && globalThis.parent !== globalThis) {
99
110
  globalThis.parent.postMessage(args, "*");
@@ -153,11 +164,8 @@ class EventBase {
153
164
  if (Array.isArray(__privateGet(this, _listeners)[target])) {
154
165
  __privateGet(this, _listeners)[target].forEach((listener) => {
155
166
  try {
156
- if (resp && Object.keys(resp).length === 1 && req.command !== LISTENER_CMDS.API) {
157
- listener(Object.values(resp)[0]);
158
- } else {
159
- listener(resp);
160
- }
167
+ let processedResp = processResponse(req, resp);
168
+ listener(processedResp);
161
169
  } catch (err) {
162
170
  console.error("Message callback error: ", err);
163
171
  }
@@ -192,6 +200,133 @@ class BaseSDK extends EventBase {
192
200
  this._addEventListener(args.eventName, callBack);
193
201
  }
194
202
  }
203
+ _postMessageSync(command, args) {
204
+ let intialValue = 0;
205
+ const _id = generateId(command.toLowerCase());
206
+ let data = { _id, command, ...args };
207
+ let atomics = new AtomicsHandler();
208
+ atomics.reset();
209
+ atomics.store(0, intialValue);
210
+ atomics.encodeData(1, data);
211
+ postMessage(atomics.sab);
212
+ atomics.wait(0, intialValue, 1e4);
213
+ let decodedData = atomics.decodeData();
214
+ let { _req: req, resp } = decodedData;
215
+ let processedResp = processResponse(req, resp);
216
+ if (processedResp == null ? void 0 : processedResp.isError) {
217
+ throw new Error(`Error: ${JSON.stringify(processedResp, null, 2)}`);
218
+ }
219
+ return processedResp;
220
+ }
221
+ }
222
+ let sharedArrayBufferInstance;
223
+ class AtomicsHandler {
224
+ constructor() {
225
+ __privateAdd(this, _textEncoder, void 0);
226
+ __privateAdd(this, _textDecoder, void 0);
227
+ __privateSet(this, _textEncoder, new TextEncoder());
228
+ __privateSet(this, _textDecoder, new TextDecoder());
229
+ sharedArrayBufferInstance = sharedArrayBufferInstance || new SharedArrayBuffer(1024 * 1024);
230
+ this.sab = sharedArrayBufferInstance;
231
+ this.int32Array = new Int32Array(this.sab);
232
+ }
233
+ load(index2 = 0) {
234
+ return Atomics.load(this.int32Array, index2);
235
+ }
236
+ store(index2 = 0, data) {
237
+ return Atomics.store(this.int32Array, index2, data);
238
+ }
239
+ reset() {
240
+ return this.int32Array.fill(0);
241
+ }
242
+ notify(index2 = 0, count = 1) {
243
+ return Atomics.notify(this.int32Array, index2, count);
244
+ }
245
+ wait(index2, value, timeout) {
246
+ return Atomics.wait(this.int32Array, index2, value, timeout);
247
+ }
248
+ encodeData(index2 = 0, data) {
249
+ const replacer = (key, value) => value === void 0 ? "undefined" : value;
250
+ let string = JSON.stringify(data, replacer);
251
+ let encodedData = __privateGet(this, _textEncoder).encode(string);
252
+ this.int32Array.set(encodedData, index2);
253
+ return this.int32Array;
254
+ }
255
+ decodeData() {
256
+ let uInt8Array = new Uint8Array(this.int32Array);
257
+ let string = __privateGet(this, _textDecoder).decode(uInt8Array).replaceAll(/\x00/g, "");
258
+ return JSON.parse(string);
259
+ }
260
+ }
261
+ _textEncoder = new WeakMap();
262
+ _textDecoder = new WeakMap();
263
+ class Client extends BaseSDK {
264
+ showInfo(message) {
265
+ return super._postMessageAsync(LISTENER_CMDS.MESSAGE, { message });
266
+ }
267
+ showConfirm(args) {
268
+ return super._postMessageAsync(LISTENER_CMDS.CONFIRM, {
269
+ data: {
270
+ title: args.title,
271
+ content: args.content,
272
+ okText: args.okText || "Ok",
273
+ cancelText: args.cancelText || "Cancel"
274
+ }
275
+ });
276
+ }
277
+ redirect(url) {
278
+ return super._postMessageAsync(LISTENER_CMDS.REDIRECT, { url });
279
+ }
280
+ }
281
+ class Formatter extends BaseSDK {
282
+ toDate(date) {
283
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE, {
284
+ date
285
+ });
286
+ }
287
+ toDateTime(date) {
288
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE_TIME, {
289
+ date
290
+ });
291
+ }
292
+ toNumber(value) {
293
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_NUMBER, {
294
+ value
295
+ });
296
+ }
297
+ toCurrency(value, currencyCode) {
298
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_CURRENCY, {
299
+ value,
300
+ currencyCode
301
+ });
302
+ }
303
+ toBoolean(value) {
304
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_BOOLEAN, {
305
+ value
306
+ });
307
+ }
308
+ }
309
+ const isObject = (value) => value !== null && typeof value === "object";
310
+ class CreateProxy {
311
+ constructor(parent, target = {}, path = []) {
312
+ this.parent = parent;
313
+ this.path = path;
314
+ return new Proxy(target, this);
315
+ }
316
+ get(target, property) {
317
+ let value = this.parent.get(property, this.path);
318
+ if (isObject(value)) {
319
+ return new CreateProxy(this.parent, value, [...this.path, property]);
320
+ }
321
+ return value;
322
+ }
323
+ set(target, property, value, reciever) {
324
+ let updatedValue = this.parent.set(property, value, this.path);
325
+ if (isObject(updatedValue)) {
326
+ return new CreateProxy(this.parent, updatedValue, [...this.path, property]);
327
+ }
328
+ return updatedValue;
329
+ }
195
330
  }
196
331
  class Component extends BaseSDK {
197
332
  constructor(props) {
@@ -312,6 +447,7 @@ class Page extends BaseSDK {
312
447
  this.type = "Page";
313
448
  this.popup = new Popup({});
314
449
  this._id = props.pageId;
450
+ this.variable = new PageVariable();
315
451
  }
316
452
  getParameter(key) {
317
453
  return this._postMessageAsync(LISTENER_CMDS.GET_PAGE_PARAMS, {
@@ -349,6 +485,27 @@ class Page extends BaseSDK {
349
485
  );
350
486
  }
351
487
  }
488
+ class PageVariable extends BaseSDK {
489
+ constructor() {
490
+ super();
491
+ return new CreateProxy(this);
492
+ }
493
+ get(key, path) {
494
+ let args = {
495
+ key,
496
+ path
497
+ };
498
+ return this._postMessageSync(LISTENER_CMDS.GET_PAGE_VARIABLE, args);
499
+ }
500
+ set(key, value, path) {
501
+ let args = {
502
+ key,
503
+ value,
504
+ path
505
+ };
506
+ return this._postMessageSync(LISTENER_CMDS.SET_PAGE_VARIABLE, args);
507
+ }
508
+ }
352
509
  class DecisionTable extends BaseSDK {
353
510
  constructor(flowId) {
354
511
  super();
@@ -361,11 +518,24 @@ class DecisionTable extends BaseSDK {
361
518
  });
362
519
  }
363
520
  }
521
+ class Dataform extends BaseSDK {
522
+ constructor(flowId) {
523
+ super();
524
+ this._id = flowId;
525
+ }
526
+ importCSV(defaultValues) {
527
+ return this._postMessageAsync(LISTENER_CMDS.DATAFORM_IMPORT_CSV, {
528
+ flowId: this._id,
529
+ defaultValues
530
+ });
531
+ }
532
+ }
364
533
  class Application extends BaseSDK {
365
534
  constructor(props) {
366
535
  super();
367
536
  this._id = props.appId;
368
537
  this.page = new Page(props);
538
+ this.variable = new AppVariable();
369
539
  }
370
540
  getVariable(key) {
371
541
  return this._postMessageAsync(LISTENER_CMDS.GET_APP_VARIABLE, {
@@ -387,51 +557,29 @@ class Application extends BaseSDK {
387
557
  getDecisionTable(flowId) {
388
558
  return new DecisionTable(flowId);
389
559
  }
390
- }
391
- class Client extends BaseSDK {
392
- showInfo(message) {
393
- return super._postMessageAsync(LISTENER_CMDS.MESSAGE, { message });
394
- }
395
- showConfirm(args) {
396
- return super._postMessageAsync(LISTENER_CMDS.CONFIRM, {
397
- data: {
398
- title: args.title,
399
- content: args.content,
400
- okText: args.okText || "Ok",
401
- cancelText: args.cancelText || "Cancel"
402
- }
403
- });
404
- }
405
- redirect(url) {
406
- return super._postMessageAsync(LISTENER_CMDS.REDIRECT, { url });
560
+ getDataform(flowId) {
561
+ return new Dataform(flowId);
407
562
  }
408
563
  }
409
- class Formatter extends BaseSDK {
410
- toDate(date) {
411
- return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE, {
412
- date
413
- });
414
- }
415
- toDateTime(date) {
416
- return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE_TIME, {
417
- date
418
- });
564
+ class AppVariable extends BaseSDK {
565
+ constructor() {
566
+ super();
567
+ return new CreateProxy(this);
419
568
  }
420
- toNumber(value) {
421
- return this._postMessageAsync(LISTENER_CMDS.FORMAT_NUMBER, {
422
- value
423
- });
569
+ get(key, path) {
570
+ let args = {
571
+ key,
572
+ path
573
+ };
574
+ return this._postMessageSync(LISTENER_CMDS.GET_APP_VARIABLE, args);
424
575
  }
425
- toCurrency(value, currencyCode) {
426
- return this._postMessageAsync(LISTENER_CMDS.FORMAT_CURRENCY, {
576
+ set(key, value, path) {
577
+ let args = {
578
+ key,
427
579
  value,
428
- currencyCode
429
- });
430
- }
431
- toBoolean(value) {
432
- return this._postMessageAsync(LISTENER_CMDS.FORMAT_BOOLEAN, {
433
- value
434
- });
580
+ path
581
+ };
582
+ return this._postMessageSync(LISTENER_CMDS.SET_APP_VARIABLE, args);
435
583
  }
436
584
  }
437
585
  class CustomComponentSDK extends BaseSDK {
@@ -442,6 +590,11 @@ class CustomComponentSDK extends BaseSDK {
442
590
  return this._postMessageAsync(LISTENER_CMDS.API, { url, args });
443
591
  }
444
592
  initialize() {
593
+ if (globalThis.parent && globalThis.parent === globalThis) {
594
+ return Promise.reject(
595
+ "SDK can be initialized only inside the Kissflow platform."
596
+ );
597
+ }
445
598
  return this._postMessageAsync(
446
599
  LISTENER_CMDS.CC_INITIALIZE,
447
600
  {},