@kissflow/lowcode-client-sdk 1.0.52 → 1.0.53

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.
@@ -0,0 +1,761 @@
1
+ var __accessCheck = (obj, member, msg) => {
2
+ if (!member.has(obj))
3
+ throw TypeError("Cannot " + msg);
4
+ };
5
+ var __privateGet = (obj, member, getter) => {
6
+ __accessCheck(obj, member, "read from private field");
7
+ return getter ? getter.call(obj) : member.get(obj);
8
+ };
9
+ var __privateAdd = (obj, member, value) => {
10
+ if (member.has(obj))
11
+ throw TypeError("Cannot add the same private member more than once");
12
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
+ };
14
+ var __privateSet = (obj, member, value, setter) => {
15
+ __accessCheck(obj, member, "write to private field");
16
+ setter ? setter.call(obj, value) : member.set(obj, value);
17
+ return value;
18
+ };
19
+ var _listeners, _textEncoder, _textDecoder, _csrfToken;
20
+ let nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
21
+ byte &= 63;
22
+ if (byte < 36) {
23
+ id += byte.toString(36);
24
+ } else if (byte < 62) {
25
+ id += (byte - 26).toString(36).toUpperCase();
26
+ } else if (byte > 62) {
27
+ id += "-";
28
+ } else {
29
+ id += "_";
30
+ }
31
+ return id;
32
+ }, "");
33
+ const LISTENER_CMDS = {
34
+ API: "API",
35
+ GET_CONTEXT: "GET_CONTEXT",
36
+ RETURN: "RETURN",
37
+ GET_FORM_FIELD: "GET_FORM_FIELD",
38
+ UPDATE_FORM: "UPDATE_FORM",
39
+ GET_FORM_VALIDATION_ERRORS: "GET_FORM_VALIDATION_ERRORS",
40
+ GET_FORM_CONFIGURATION: "GET_FORM_CONFIGURATION",
41
+ GET_FORM_FIELD_STATE: "GET_FORM_FIELD_STATE",
42
+ GET_TABLE: "GET_TABLE",
43
+ GET_TABLE_ROW: "GET_TABLE_ROW",
44
+ ADD_TABLE_ROW: "ADD_TABLE_ROW",
45
+ ADD_TABLE_ROWS: "ADD_TABLE_ROWS",
46
+ DELETE_TABLE_ROW: "DELETE_TABLE_ROW",
47
+ TO_JSON: "TO_JSON",
48
+ GET_TABLE_ROWS: "GET_TABLE_ROWS",
49
+ GET_SELECTED_TABLE_ROWS: "GET_SELECTED_TABLE_ROWS",
50
+ MESSAGE: "MESSAGE",
51
+ CONFIRM: "CONFIRM",
52
+ ALERT: "ALERT",
53
+ REDIRECT: "REDIRECT",
54
+ OPEN_PAGE: "OPEN_PAGE",
55
+ GET_IMAGE_URL: "GET_IMAGE_URL",
56
+ FILEPICKER_OPEN: "FILEPICKER_OPEN",
57
+ FILEPREVIEW_OPEN: "FILEPREVIEW_OPEN",
58
+ FILE_UPLOAD: "FILE_UPLOAD",
59
+ SCANNER_OPEN: "SCANNER_OPEN",
60
+ GEOLOCATION_OPEN: "GEOLOCATION_OPEN",
61
+ GET_ROLES: "GET_ROLES",
62
+ SWITCH_ROLE: "SWITCH_ROLE",
63
+ FORMAT_DATE: "FORMAT_DATE",
64
+ FORMAT_DATE_TIME: "FORMAT_DATE_TIME",
65
+ FORMAT_NUMBER: "FORMAT_NUMBER",
66
+ FORMAT_CURRENCY: "FORMAT_CURRENCY",
67
+ FORMAT_BOOLEAN: "FORMAT_BOOLEAN",
68
+ GET_APP_VARIABLE: "GET_APP_VARIABLE",
69
+ SET_APP_VARIABLE: "SET_APP_VARIABLE",
70
+ GET_PAGE_VARIABLE: "GET_PAGE_VARIABLE",
71
+ SET_PAGE_VARIABLE: "SET_PAGE_VARIABLE",
72
+ GET_PAGE_PARAMS: "GET_PAGE_PARAMS",
73
+ GET_ALL_PAGE_PARAMS: "GET_ALL_PAGE_PARAMS",
74
+ PAGE_ON_CLOSE: "PAGE_ON_CLOSE",
75
+ OPEN_POPUP: "OPEN_POPUP",
76
+ GET_POPUP_PARAMS: "GET_POPUP_PARAMS",
77
+ GET_ALL_POPUP_PARAMS: "GET_ALL_POPUP_PARAMS",
78
+ CLOSE_POPUP: "CLOSE_POPUP",
79
+ COMPONENT_GET: "COMPONENT_GET",
80
+ COMPONENT_REFRESH: "COMPONENT_REFRESH",
81
+ COMPONENT_SHOW: "COMPONENT_SHOW",
82
+ COMPONENT_HIDE: "COMPONENT_HIDE",
83
+ COMPONENT_ADD_EVENT_LISTENER: "COMPONENT_ADD_EVENT_LISTENER",
84
+ CC_INITIALIZE: "CC_INITIALIZE",
85
+ CC_WATCH_PARAMS: "CC_WATCH_PARAMS",
86
+ CC_SET_ROUTE: "CC_SET_ROUTE",
87
+ CC_WATCH_ROUTE: "CC_WATCH_ROUTE",
88
+ WINDOW_NDEF_READER_NEW: "WINDOW_NDEF_READER_NEW",
89
+ WINDOW_NDEF_READER_SCAN: "WINDOW_NDEF_READER_SCAN",
90
+ WINDOW_NDEF_READER_WRITE: "WINDOW_NDEF_READER_WRITE",
91
+ WINDOW_NDEF_READER_ADD_EVENT_LISTENER: "WINDOW_NDEF_READER_ADD_EVENT_LISTENER",
92
+ WINDOW_NDEF_READER_MAKE_READONLY: "WINDOW_NDEF_READER_MAKE_READONLY",
93
+ WINDOW_NDEF_READER_ABORT_SCAN: "WINDOW_NDEF_READER_ABORT_SCAN",
94
+ CUSTOM_AGENT_GET_CONTRACT: "CUSTOM_AGENT_GET_CONTRACT",
95
+ CUSTOM_AGENT_EXECUTE: "CUSTOM_AGENT_EXECUTE",
96
+ CUSTOM_AGENT_GET_EXECUTION: "CUSTOM_AGENT_GET_EXECUTION",
97
+ CUSTOM_AGENT_WATCH_EXECUTION: "CUSTOM_AGENT_WATCH_EXECUTION",
98
+ CUSTOM_AGENT_STOP_WATCH: "CUSTOM_AGENT_STOP_WATCH",
99
+ CUSTOM_FUNCTION_RUN: "CUSTOM_FUNCTION_RUN",
100
+ CUSTOM_FUNCTION_GET_RUN: "CUSTOM_FUNCTION_GET_RUN",
101
+ CUSTOM_FUNCTION_ON_RUN_COMPLETE: "CUSTOM_FUNCTION_ON_RUN_COMPLETE",
102
+ CUSTOM_FUNCTION_STOP_WATCH: "CUSTOM_FUNCTION_STOP_WATCH",
103
+ DECISION_TABLE_EXECUTE: "DECISION_TABLE_EXECUTE",
104
+ REPORT_GET_DATA: "REPORT_GET_DATA",
105
+ REPORT_GET_COUNT: "REPORT_GET_COUNT",
106
+ REPORT_GET_FIELDS: "REPORT_GET_FIELDS",
107
+ DATAFORM_IMPORT_CSV: "DATAFORM_IMPORT_CSV",
108
+ DATAFORM_OPEN_FORM: "DATAFORM_OPEN_FORM",
109
+ DATAFORM_GET_FIELDS: "DATAFORM_GET_FIELDS",
110
+ DATAFORM_GET_ITEMS: "DATAFORM_GET_ITEMS",
111
+ DATAFORM_CREATE_ITEM: "DATAFORM_CREATE_ITEM",
112
+ DATAFORM_UPDATE_ITEM: "DATAFORM_UPDATE_ITEM",
113
+ DATAFORM_GET_ITEM: "DATAFORM_GET_ITEM",
114
+ DATAFORM_DELETE_ITEM: "DATAFORM_DELETE_ITEM",
115
+ DATAFORM_DISCARD_ITEM: "DATAFORM_DISCARD_ITEM",
116
+ DATAFORM_SUBMIT_ITEM: "DATAFORM_SUBMIT_ITEM",
117
+ DATAFORM_INIT_FORM: "DATAFORM_INIT_FORM",
118
+ DATAFORM_GET_FIELD_OPTIONS: "DATAFORM_GET_FIELD_OPTIONS",
119
+ PROCESS_OPEN_FORM: "PROCESS_OPEN_FORM",
120
+ PROCESS_GET_FIELDS: "PROCESS_GET_FIELDS",
121
+ PROCESS_GET_MYTASK_FIELDS: "PROCESS_GET_MYTASK_FIELDS",
122
+ PROCESS_GET_PARTICIPATED_FIELDS: "PROCESS_GET_PARTICIPATED_FIELDS",
123
+ PROCESS_GET_MY_ITEMS_FIELDS: "PROCESS_GET_MY_ITEMS_FIELDS",
124
+ PROCESS_GET_MY_ITEMS: "PROCESS_GET_MY_ITEMS",
125
+ PROCESS_GET_MY_TASKS_ITEMS: "PROCESS_GET_MY_TASKS_ITEMS",
126
+ PROCESS_GET_PARTICIPATED_ITEMS: "PROCESS_GET_PARTICIPATED_ITEMS",
127
+ PROCESS_GET_ADMIN_ITEMS: "PROCESS_GET_ADMIN_ITEMS",
128
+ PROCESS_CREATE_ITEM: "PROCESS_CREATE_ITEM",
129
+ PROCESS_UPDATE_ITEM: "PROCESS_UPDATE_ITEM",
130
+ PROCESS_GET_ITEM: "PROCESS_GET_ITEM",
131
+ PROCESS_DELETE_ITEM: "PROCESS_DELETE_ITEM",
132
+ PROCESS_GET_ADMIN_ITEM: "PROCESS_GET_ADMIN_ITEM",
133
+ PROCESS_UPDATE_ADMIN_ITEM: "PROCESS_UPDATE_ADMIN_ITEM",
134
+ PROCESS_SUBMIT_ITEM: "PROCESS_SUBMIT_ITEM",
135
+ PROCESS_REJECT_ITEM: "PROCESS_REJECT_ITEM",
136
+ PROCESS_WITHDRAW_ITEM: "PROCESS_WITHDRAW_ITEM",
137
+ PROCESS_SENDBACK_ITEM: "PROCESS_SENDBACK_ITEM",
138
+ PROCESS_REASSIGN_ITEM: "PROCESS_REASSIGN_ITEM",
139
+ PROCESS_GET_REASSIGNEES: "PROCESS_GET_REASSIGNEES",
140
+ PROCESS_RESTART_ITEM: "PROCESS_RESTART_ITEM",
141
+ PROCESS_DISCARD_ITEM: "PROCESS_DISCARD_ITEM",
142
+ PROCESS_GET_PROGRESS: "PROCESS_GET_PROGRESS",
143
+ PROCESS_INIT_FORM: "PROCESS_INIT_FORM",
144
+ PROCESS_GET_FIELD_OPTIONS: "PROCESS_GET_FIELD_OPTIONS",
145
+ PROCESS_PARSE_ATTACHMENT: "PROCESS_PARSE_ATTACHMENT",
146
+ BOARD_IMPORT_CSV: "BOARD_IMPORT_CSV",
147
+ BOARD_OPEN_FORM: "BOARD_OPEN_FORM",
148
+ BOARD_GET_FIELDS: "BOARD_GET_FIELDS",
149
+ BOARD_GET_ITEMS: "BOARD_GET_ITEMS",
150
+ BOARD_CREATE_ITEM: "BOARD_CREATE_ITEM",
151
+ BOARD_UPDATE_ITEM: "BOARD_UPDATE_ITEM",
152
+ BOARD_GET_ITEM: "BOARD_GET_ITEM",
153
+ BOARD_DELETE_ITEM: "BOARD_DELETE_ITEM",
154
+ BOARD_SUBMIT_ITEM: "BOARD_SUBMIT_ITEM",
155
+ BOARD_DISCARD_ITEM: "BOARD_DISCARD_ITEM",
156
+ BOARD_INIT_FORM: "BOARD_INIT_FORM",
157
+ BOARD_GET_FIELD_OPTIONS: "BOARD_GET_FIELD_OPTIONS"
158
+ };
159
+ function generateId(prefix = "lcncsdk") {
160
+ return `${prefix}-${nanoid()}`;
161
+ }
162
+ const globalInstances = {};
163
+ const pendingRequestIds = /* @__PURE__ */ new Set();
164
+ const ENVELOPE_COMMANDS = /* @__PURE__ */ new Set([
165
+ LISTENER_CMDS.API,
166
+ LISTENER_CMDS.CUSTOM_FUNCTION_RUN,
167
+ LISTENER_CMDS.CUSTOM_FUNCTION_GET_RUN
168
+ ]);
169
+ function processResponse(req, resp) {
170
+ if (resp && Object.keys(resp).length === 1 && !ENVELOPE_COMMANDS.has(req.command)) {
171
+ let value = Object.values(resp)[0];
172
+ if (value === "undefined")
173
+ return void 0;
174
+ return value;
175
+ } else {
176
+ return resp;
177
+ }
178
+ }
179
+ function postMessage(args) {
180
+ if (globalThis.parent && globalThis.parent !== globalThis) {
181
+ globalThis.parent.postMessage(args, "*");
182
+ } else {
183
+ globalThis.postMessage(args);
184
+ }
185
+ }
186
+ function onMessage(event) {
187
+ if (event.origin !== globalThis.location.origin) {
188
+ const data = event.data;
189
+ if (data == null ? void 0 : data.isEvent) {
190
+ const { target, eventParams, eventName, eventConfig = {} } = data;
191
+ let targetInstance = globalInstances[target];
192
+ if (!targetInstance)
193
+ return;
194
+ targetInstance._dispatchEvent(eventName, eventParams);
195
+ if (eventConfig.once) {
196
+ targetInstance._removeEventListener(eventName);
197
+ }
198
+ return;
199
+ }
200
+ let { _req: req, resp } = data;
201
+ if (req == null ? void 0 : req._id) {
202
+ let targetInstance = globalInstances[req._id];
203
+ if (targetInstance) {
204
+ targetInstance._dispatchMessageEvents(req, resp);
205
+ if (pendingRequestIds.delete(req._id)) {
206
+ Reflect.deleteProperty(globalInstances, req._id);
207
+ }
208
+ }
209
+ }
210
+ }
211
+ }
212
+ globalThis.addEventListener("message", onMessage);
213
+ class EventBase {
214
+ constructor() {
215
+ __privateAdd(this, _listeners, void 0);
216
+ __privateSet(this, _listeners, {});
217
+ }
218
+ _addEventListener(eventName, callBack) {
219
+ var _a;
220
+ __privateGet(this, _listeners)[eventName] = ((_a = __privateGet(this, _listeners)) == null ? void 0 : _a[eventName]) || [];
221
+ __privateGet(this, _listeners)[eventName].push(callBack);
222
+ }
223
+ _removeEventListener(eventName, callBack) {
224
+ if (callBack) {
225
+ const listeners = __privateGet(this, _listeners)[eventName] || [];
226
+ const index = listeners.indexOf(callBack);
227
+ index > -1 && listeners.splice(index, 1);
228
+ return;
229
+ }
230
+ Reflect.deleteProperty(__privateGet(this, _listeners), eventName);
231
+ }
232
+ _dispatchEvent(eventName, eventParams) {
233
+ if (Array.isArray(__privateGet(this, _listeners)[eventName])) {
234
+ __privateGet(this, _listeners)[eventName].forEach(
235
+ (callBack) => callBack(eventParams)
236
+ );
237
+ return true;
238
+ }
239
+ return false;
240
+ }
241
+ _dispatchMessageEvents(req, resp) {
242
+ let target = req._id;
243
+ if (Array.isArray(__privateGet(this, _listeners)[target])) {
244
+ __privateGet(this, _listeners)[target].forEach((listener) => {
245
+ try {
246
+ let processedResp = processResponse(req, resp);
247
+ listener(processedResp);
248
+ } catch (err) {
249
+ console.error("Message callback error: ", err);
250
+ }
251
+ });
252
+ this._removeEventListener(target);
253
+ }
254
+ }
255
+ }
256
+ _listeners = new WeakMap();
257
+ class BaseSDK extends EventBase {
258
+ _postMessageAsync(command, args, hasCallBack, callBack) {
259
+ return new Promise((resolve, reject) => {
260
+ const _id = generateId(command.toLowerCase());
261
+ postMessage({ _id, command, ...args });
262
+ globalInstances[_id] = this;
263
+ pendingRequestIds.add(_id);
264
+ this._addEventListener(_id, async (data) => {
265
+ if ((data == null ? void 0 : data.errorMessage) || (data == null ? void 0 : data.isError)) {
266
+ reject(data);
267
+ } else {
268
+ if (hasCallBack && callBack) {
269
+ data = await callBack(data);
270
+ }
271
+ resolve(data);
272
+ }
273
+ });
274
+ });
275
+ }
276
+ _postMessageBounded(command, args, options) {
277
+ const _id = generateId(command.toLowerCase());
278
+ let timer;
279
+ let settled = false;
280
+ const release = () => {
281
+ settled = true;
282
+ clearTimeout(timer);
283
+ this._removeEventListener(_id);
284
+ pendingRequestIds.delete(_id);
285
+ Reflect.deleteProperty(globalInstances, _id);
286
+ };
287
+ const promise = new Promise((resolve, reject) => {
288
+ timer = setTimeout(() => {
289
+ release();
290
+ reject(options.timeoutError);
291
+ }, options.timeoutMs);
292
+ globalInstances[_id] = this;
293
+ pendingRequestIds.add(_id);
294
+ this._addEventListener(_id, (data) => {
295
+ release();
296
+ if ((data == null ? void 0 : data.errorMessage) || (data == null ? void 0 : data.isError))
297
+ reject(data);
298
+ else
299
+ resolve(data);
300
+ });
301
+ try {
302
+ postMessage({ _id, command, ...args });
303
+ } catch (error) {
304
+ release();
305
+ reject(options.sendError);
306
+ }
307
+ });
308
+ return {
309
+ promise,
310
+ cancel: () => {
311
+ if (!settled)
312
+ release();
313
+ }
314
+ };
315
+ }
316
+ _postMessage(command, args, callBack) {
317
+ const _id = generateId(command.toLowerCase());
318
+ postMessage({ _id, command, ...args });
319
+ if (callBack) {
320
+ this._addEventListener(args.eventName, callBack);
321
+ }
322
+ }
323
+ _postMessageSync(command, args) {
324
+ let intialValue = 0;
325
+ const _id = generateId(command.toLowerCase());
326
+ let data = { _id, command, ...args };
327
+ let atomics = new AtomicsHandler();
328
+ atomics.reset();
329
+ atomics.store(0, intialValue);
330
+ atomics.encodeData(1, data);
331
+ postMessage(atomics.sab);
332
+ atomics.wait(0, intialValue, 1e4);
333
+ let decodedData = atomics.decodeData();
334
+ let { _req: req, resp } = decodedData;
335
+ let processedResp = processResponse(req, resp);
336
+ if (processedResp == null ? void 0 : processedResp.isError) {
337
+ throw new Error(`Error: ${JSON.stringify(processedResp, null, 2)}`);
338
+ }
339
+ return processedResp;
340
+ }
341
+ }
342
+ let sharedArrayBufferInstance;
343
+ class AtomicsHandler {
344
+ constructor() {
345
+ __privateAdd(this, _textEncoder, void 0);
346
+ __privateAdd(this, _textDecoder, void 0);
347
+ __privateSet(this, _textEncoder, new TextEncoder());
348
+ __privateSet(this, _textDecoder, new TextDecoder());
349
+ sharedArrayBufferInstance = sharedArrayBufferInstance || new SharedArrayBuffer(1024 * 1024);
350
+ this.sab = sharedArrayBufferInstance;
351
+ this.int32Array = new Int32Array(this.sab);
352
+ }
353
+ load(index = 0) {
354
+ return Atomics.load(this.int32Array, index);
355
+ }
356
+ store(index = 0, data) {
357
+ return Atomics.store(this.int32Array, index, data);
358
+ }
359
+ reset() {
360
+ return this.int32Array.fill(0);
361
+ }
362
+ notify(index = 0, count = 1) {
363
+ return Atomics.notify(this.int32Array, index, count);
364
+ }
365
+ wait(index, value, timeout) {
366
+ return Atomics.wait(this.int32Array, index, value, timeout);
367
+ }
368
+ encodeData(index = 0, data) {
369
+ const replacer = (key, value) => value === void 0 ? "undefined" : value;
370
+ let string = JSON.stringify(data, replacer);
371
+ let encodedData = __privateGet(this, _textEncoder).encode(string);
372
+ this.int32Array.set(encodedData, index);
373
+ return this.int32Array;
374
+ }
375
+ decodeData() {
376
+ let uInt8Array = new Uint8Array(this.int32Array);
377
+ let string = __privateGet(this, _textDecoder).decode(uInt8Array).replaceAll(/\x00/g, "");
378
+ return JSON.parse(string);
379
+ }
380
+ }
381
+ _textEncoder = new WeakMap();
382
+ _textDecoder = new WeakMap();
383
+ class Form extends BaseSDK {
384
+ constructor(storeId, flowId, instanceId, activityInstanceId) {
385
+ super();
386
+ this.type = "Form";
387
+ this.storeId = storeId;
388
+ this.flowId = flowId;
389
+ this.instanceId = instanceId;
390
+ this.activityInstanceId = activityInstanceId;
391
+ }
392
+ toJSON() {
393
+ return this._postMessageAsync(LISTENER_CMDS.TO_JSON, {
394
+ storeId: this.storeId,
395
+ instanceId: this.instanceId
396
+ });
397
+ }
398
+ getField(fieldId) {
399
+ return this._postMessageAsync(LISTENER_CMDS.GET_FORM_FIELD, {
400
+ storeId: this.storeId,
401
+ instanceId: this.instanceId,
402
+ fieldId
403
+ });
404
+ }
405
+ updateField(args) {
406
+ return this._postMessageAsync(LISTENER_CMDS.UPDATE_FORM, {
407
+ storeId: this.storeId,
408
+ instanceId: this.instanceId,
409
+ data: args
410
+ });
411
+ }
412
+ getTable(tableId) {
413
+ return new Table(
414
+ this.storeId,
415
+ this.flowId,
416
+ this.instanceId,
417
+ tableId,
418
+ this.activityInstanceId,
419
+ this
420
+ );
421
+ }
422
+ }
423
+ class Table extends BaseSDK {
424
+ constructor(storeId, flowId, instanceId, tableId, activityInstanceId, parent) {
425
+ super();
426
+ this.tableId = tableId;
427
+ this.storeId = storeId;
428
+ this.flowId = flowId;
429
+ this.instanceId = instanceId;
430
+ this.activityInstanceId = activityInstanceId;
431
+ this.parent = parent;
432
+ }
433
+ toJSON() {
434
+ return this._postMessageAsync(LISTENER_CMDS.TO_JSON, {
435
+ storeId: this.storeId,
436
+ instanceId: this.instanceId,
437
+ tableId: this.tableId
438
+ });
439
+ }
440
+ getSelectedRows() {
441
+ return this._postMessageAsync(LISTENER_CMDS.GET_SELECTED_TABLE_ROWS, {
442
+ storeId: this.storeId,
443
+ instanceId: this.instanceId,
444
+ tableId: this.tableId
445
+ });
446
+ }
447
+ getRows() {
448
+ return this._postMessageAsync(
449
+ LISTENER_CMDS.GET_TABLE_ROWS,
450
+ {
451
+ storeId: this.storeId,
452
+ instanceId: this.instanceId,
453
+ tableId: this.tableId
454
+ },
455
+ true,
456
+ (data) => {
457
+ return data.map(
458
+ (row) => new TableForm(
459
+ this.storeId,
460
+ this.flowId,
461
+ this.instanceId,
462
+ this.tableId,
463
+ row.id,
464
+ this.activityInstanceId,
465
+ this.parent
466
+ )
467
+ );
468
+ }
469
+ );
470
+ }
471
+ getRow(rowId) {
472
+ return new TableForm(
473
+ this.storeId,
474
+ this.flowId,
475
+ this.instanceId,
476
+ this.tableId,
477
+ rowId,
478
+ this.activityInstanceId,
479
+ this.parent
480
+ );
481
+ }
482
+ addRow(rowObject) {
483
+ return this._postMessageAsync(LISTENER_CMDS.ADD_TABLE_ROW, {
484
+ storeId: this.storeId,
485
+ instanceId: this.instanceId,
486
+ tableId: this.tableId,
487
+ rowObject
488
+ });
489
+ }
490
+ addRows(rows) {
491
+ return this._postMessageAsync(LISTENER_CMDS.ADD_TABLE_ROWS, {
492
+ storeId: this.storeId,
493
+ instanceId: this.instanceId,
494
+ tableId: this.tableId,
495
+ rows
496
+ });
497
+ }
498
+ deleteRow(rowId) {
499
+ return this._postMessageAsync(LISTENER_CMDS.DELETE_TABLE_ROW, {
500
+ storeId: this.storeId,
501
+ instanceId: this.instanceId,
502
+ tableId: this.tableId,
503
+ rows: [rowId]
504
+ });
505
+ }
506
+ deleteRows(rows) {
507
+ return this._postMessageAsync(LISTENER_CMDS.DELETE_TABLE_ROW, {
508
+ storeId: this.storeId,
509
+ instanceId: this.instanceId,
510
+ tableId: this.tableId,
511
+ rows
512
+ });
513
+ }
514
+ }
515
+ class TableForm extends BaseSDK {
516
+ constructor(storeId, flowId, instanceId, tableId, rowId, activityInstanceId, parent) {
517
+ super();
518
+ this.storeId = storeId;
519
+ this.flowId = flowId;
520
+ this.instanceId = instanceId;
521
+ this.type = "TabelForm";
522
+ this.tableId = tableId;
523
+ this.rowId = rowId;
524
+ this.activityInstanceId = activityInstanceId;
525
+ this.parent = parent;
526
+ }
527
+ getParent() {
528
+ if (this.parent)
529
+ return this.parent;
530
+ return new Form(
531
+ this.storeId,
532
+ this.flowId,
533
+ this.instanceId,
534
+ this.activityInstanceId
535
+ );
536
+ }
537
+ toJSON() {
538
+ return this._postMessageAsync(LISTENER_CMDS.TO_JSON, {
539
+ storeId: this.storeId,
540
+ instanceId: this.instanceId,
541
+ tableId: this.tableId,
542
+ rowId: this.rowId
543
+ });
544
+ }
545
+ getField(fieldId) {
546
+ return this._postMessageAsync(LISTENER_CMDS.GET_FORM_FIELD, {
547
+ storeId: this.storeId,
548
+ instanceId: this.instanceId,
549
+ tableId: this.tableId,
550
+ rowId: this.rowId,
551
+ fieldId
552
+ });
553
+ }
554
+ updateField(args) {
555
+ return this._postMessageAsync(LISTENER_CMDS.UPDATE_FORM, {
556
+ storeId: this.storeId,
557
+ instanceId: this.instanceId,
558
+ tableId: this.tableId,
559
+ rowId: this.rowId,
560
+ data: args
561
+ });
562
+ }
563
+ }
564
+ class Client extends BaseSDK {
565
+ showInfo(message) {
566
+ return super._postMessageAsync(LISTENER_CMDS.MESSAGE, { message });
567
+ }
568
+ showConfirm(args) {
569
+ return super._postMessageAsync(LISTENER_CMDS.CONFIRM, {
570
+ data: {
571
+ title: args.title,
572
+ content: args.content,
573
+ okText: args.okText || "Ok",
574
+ cancelText: args.cancelText || "Cancel"
575
+ }
576
+ });
577
+ }
578
+ redirect(url) {
579
+ return super._postMessageAsync(LISTENER_CMDS.REDIRECT, { url });
580
+ }
581
+ getImageUrl(imageValue) {
582
+ return this._postMessageAsync(LISTENER_CMDS.GET_IMAGE_URL, {
583
+ imageValue
584
+ });
585
+ }
586
+ openFilePicker(options) {
587
+ return this._postMessageAsync(LISTENER_CMDS.FILEPICKER_OPEN, {
588
+ options
589
+ });
590
+ }
591
+ openScanner(options = {}) {
592
+ return this._postMessageAsync(LISTENER_CMDS.SCANNER_OPEN, {
593
+ options
594
+ });
595
+ }
596
+ pickLocation(value) {
597
+ return this._postMessageAsync(LISTENER_CMDS.GEOLOCATION_OPEN, {
598
+ value
599
+ });
600
+ }
601
+ uploadFile(file, fileName) {
602
+ return this._postMessageAsync(LISTENER_CMDS.FILE_UPLOAD, {
603
+ file,
604
+ fileName: fileName != null ? fileName : file.name
605
+ });
606
+ }
607
+ openFilePreview(args) {
608
+ var _a;
609
+ return this._postMessageAsync(LISTENER_CMDS.FILEPREVIEW_OPEN, {
610
+ files: args.files,
611
+ indexOfFile: (_a = args.indexOfFile) != null ? _a : 0
612
+ });
613
+ }
614
+ }
615
+ class Formatter extends BaseSDK {
616
+ toDate(date) {
617
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE, {
618
+ date
619
+ });
620
+ }
621
+ toDateTime(date) {
622
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE_TIME, {
623
+ date
624
+ });
625
+ }
626
+ toNumber(value) {
627
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_NUMBER, {
628
+ value
629
+ });
630
+ }
631
+ toCurrency(value, currencyCode) {
632
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_CURRENCY, {
633
+ value,
634
+ currencyCode
635
+ });
636
+ }
637
+ toBoolean(value) {
638
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_BOOLEAN, {
639
+ value
640
+ });
641
+ }
642
+ }
643
+ class NDEFReader extends BaseSDK {
644
+ constructor() {
645
+ super();
646
+ this.id = generateId(LISTENER_CMDS.WINDOW_NDEF_READER_NEW);
647
+ globalInstances[this.id] = this;
648
+ this._postMessage(
649
+ LISTENER_CMDS.WINDOW_NDEF_READER_NEW,
650
+ {
651
+ id: this.id,
652
+ operation: "new"
653
+ },
654
+ (data) => {
655
+ }
656
+ );
657
+ }
658
+ scan() {
659
+ return new Promise((resolve, reject) => {
660
+ this._postMessage(
661
+ LISTENER_CMDS.WINDOW_NDEF_READER_SCAN,
662
+ { id: this.id, operation: "scan" },
663
+ ({ data, err }) => {
664
+ console.log("scan data from main window ", data);
665
+ resolve(data);
666
+ }
667
+ );
668
+ });
669
+ }
670
+ write(data) {
671
+ return new Promise((resolve, reject) => {
672
+ this._postMessage(
673
+ LISTENER_CMDS.WINDOW_NDEF_READER_WRITE,
674
+ { id: this.id, operation: "write", data },
675
+ ({ data: data2, err }) => {
676
+ }
677
+ );
678
+ });
679
+ }
680
+ addEventListener(eventName, cb) {
681
+ this._postMessage(
682
+ LISTENER_CMDS.WINDOW_NDEF_READER_ADD_EVENT_LISTENER,
683
+ {
684
+ id: this.id,
685
+ operation: "addEventListener",
686
+ eventName
687
+ },
688
+ () => {
689
+ }
690
+ );
691
+ }
692
+ makeReadOnly() {
693
+ return new Promise((resolve, reject) => {
694
+ this._postMessage(
695
+ LISTENER_CMDS.WINDOW_NDEF_READER_MAKE_READONLY,
696
+ { id: this.id, operation: "makeReadOnly" },
697
+ ({ data, err }) => {
698
+ }
699
+ );
700
+ });
701
+ }
702
+ abortScan() {
703
+ return new Promise((resolve, reject) => {
704
+ this._postMessage(
705
+ LISTENER_CMDS.WINDOW_NDEF_READER_ABORT_SCAN,
706
+ { id: this.id, operation: "abortScan" },
707
+ ({ data, err }) => {
708
+ }
709
+ );
710
+ });
711
+ }
712
+ }
713
+ const window = {
714
+ NDEFReader
715
+ };
716
+ class NocodeSDK extends BaseSDK {
717
+ constructor(props) {
718
+ super();
719
+ __privateAdd(this, _csrfToken, void 0);
720
+ if (props.tableId && props.tableRowId) {
721
+ this.context = new TableForm(
722
+ props.formInstanceId,
723
+ props.flowId,
724
+ props.formInstanceId,
725
+ props.tableId,
726
+ props.tableRowId
727
+ );
728
+ } else if (props.formInstanceId) {
729
+ this.context = new Form(
730
+ props.formInstanceId,
731
+ props.flowId,
732
+ props.formInstanceId
733
+ );
734
+ }
735
+ this.client = new Client();
736
+ this.formatter = new Formatter();
737
+ this.user = props.user;
738
+ this.account = props.account;
739
+ __privateSet(this, _csrfToken, props.csrfToken);
740
+ }
741
+ async api(url, args) {
742
+ const response = await globalThis.fetch(url, {
743
+ ...args,
744
+ headers: {
745
+ ...(args == null ? void 0 : args.headers) || {},
746
+ "X-Csrf-Token": __privateGet(this, _csrfToken)
747
+ }
748
+ });
749
+ const contentType = response.headers.get("content-type");
750
+ if (contentType && contentType.includes("application/json")) {
751
+ return await response.json();
752
+ } else {
753
+ return response;
754
+ }
755
+ }
756
+ }
757
+ _csrfToken = new WeakMap();
758
+ function initSDK(config) {
759
+ return new NocodeSDK(config);
760
+ }
761
+ export { initSDK as default, window };