@kissflow/lowcode-client-sdk 1.0.51 → 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,1856 @@
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 __privateMethod = (obj, member, method) => {
20
+ __accessCheck(obj, member, "access private method");
21
+ return method;
22
+ };
23
+ var _listeners, _textEncoder, _textDecoder, _registerComponentAPIs, registerComponentAPIs_fn, _csrfToken;
24
+ let nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
25
+ byte &= 63;
26
+ if (byte < 36) {
27
+ id += byte.toString(36);
28
+ } else if (byte < 62) {
29
+ id += (byte - 26).toString(36).toUpperCase();
30
+ } else if (byte > 62) {
31
+ id += "-";
32
+ } else {
33
+ id += "_";
34
+ }
35
+ return id;
36
+ }, "");
37
+ const LISTENER_CMDS = {
38
+ API: "API",
39
+ GET_CONTEXT: "GET_CONTEXT",
40
+ RETURN: "RETURN",
41
+ GET_FORM_FIELD: "GET_FORM_FIELD",
42
+ UPDATE_FORM: "UPDATE_FORM",
43
+ GET_FORM_VALIDATION_ERRORS: "GET_FORM_VALIDATION_ERRORS",
44
+ GET_FORM_CONFIGURATION: "GET_FORM_CONFIGURATION",
45
+ GET_FORM_FIELD_STATE: "GET_FORM_FIELD_STATE",
46
+ GET_TABLE: "GET_TABLE",
47
+ GET_TABLE_ROW: "GET_TABLE_ROW",
48
+ ADD_TABLE_ROW: "ADD_TABLE_ROW",
49
+ ADD_TABLE_ROWS: "ADD_TABLE_ROWS",
50
+ DELETE_TABLE_ROW: "DELETE_TABLE_ROW",
51
+ TO_JSON: "TO_JSON",
52
+ GET_TABLE_ROWS: "GET_TABLE_ROWS",
53
+ GET_SELECTED_TABLE_ROWS: "GET_SELECTED_TABLE_ROWS",
54
+ MESSAGE: "MESSAGE",
55
+ CONFIRM: "CONFIRM",
56
+ ALERT: "ALERT",
57
+ REDIRECT: "REDIRECT",
58
+ OPEN_PAGE: "OPEN_PAGE",
59
+ GET_IMAGE_URL: "GET_IMAGE_URL",
60
+ FILEPICKER_OPEN: "FILEPICKER_OPEN",
61
+ FILEPREVIEW_OPEN: "FILEPREVIEW_OPEN",
62
+ FILE_UPLOAD: "FILE_UPLOAD",
63
+ SCANNER_OPEN: "SCANNER_OPEN",
64
+ GEOLOCATION_OPEN: "GEOLOCATION_OPEN",
65
+ GET_ROLES: "GET_ROLES",
66
+ SWITCH_ROLE: "SWITCH_ROLE",
67
+ FORMAT_DATE: "FORMAT_DATE",
68
+ FORMAT_DATE_TIME: "FORMAT_DATE_TIME",
69
+ FORMAT_NUMBER: "FORMAT_NUMBER",
70
+ FORMAT_CURRENCY: "FORMAT_CURRENCY",
71
+ FORMAT_BOOLEAN: "FORMAT_BOOLEAN",
72
+ GET_APP_VARIABLE: "GET_APP_VARIABLE",
73
+ SET_APP_VARIABLE: "SET_APP_VARIABLE",
74
+ GET_PAGE_VARIABLE: "GET_PAGE_VARIABLE",
75
+ SET_PAGE_VARIABLE: "SET_PAGE_VARIABLE",
76
+ GET_PAGE_PARAMS: "GET_PAGE_PARAMS",
77
+ GET_ALL_PAGE_PARAMS: "GET_ALL_PAGE_PARAMS",
78
+ PAGE_ON_CLOSE: "PAGE_ON_CLOSE",
79
+ OPEN_POPUP: "OPEN_POPUP",
80
+ GET_POPUP_PARAMS: "GET_POPUP_PARAMS",
81
+ GET_ALL_POPUP_PARAMS: "GET_ALL_POPUP_PARAMS",
82
+ CLOSE_POPUP: "CLOSE_POPUP",
83
+ COMPONENT_GET: "COMPONENT_GET",
84
+ COMPONENT_REFRESH: "COMPONENT_REFRESH",
85
+ COMPONENT_SHOW: "COMPONENT_SHOW",
86
+ COMPONENT_HIDE: "COMPONENT_HIDE",
87
+ COMPONENT_ADD_EVENT_LISTENER: "COMPONENT_ADD_EVENT_LISTENER",
88
+ CC_INITIALIZE: "CC_INITIALIZE",
89
+ CC_WATCH_PARAMS: "CC_WATCH_PARAMS",
90
+ CC_SET_ROUTE: "CC_SET_ROUTE",
91
+ CC_WATCH_ROUTE: "CC_WATCH_ROUTE",
92
+ WINDOW_NDEF_READER_NEW: "WINDOW_NDEF_READER_NEW",
93
+ WINDOW_NDEF_READER_SCAN: "WINDOW_NDEF_READER_SCAN",
94
+ WINDOW_NDEF_READER_WRITE: "WINDOW_NDEF_READER_WRITE",
95
+ WINDOW_NDEF_READER_ADD_EVENT_LISTENER: "WINDOW_NDEF_READER_ADD_EVENT_LISTENER",
96
+ WINDOW_NDEF_READER_MAKE_READONLY: "WINDOW_NDEF_READER_MAKE_READONLY",
97
+ WINDOW_NDEF_READER_ABORT_SCAN: "WINDOW_NDEF_READER_ABORT_SCAN",
98
+ CUSTOM_AGENT_GET_CONTRACT: "CUSTOM_AGENT_GET_CONTRACT",
99
+ CUSTOM_AGENT_EXECUTE: "CUSTOM_AGENT_EXECUTE",
100
+ CUSTOM_AGENT_GET_EXECUTION: "CUSTOM_AGENT_GET_EXECUTION",
101
+ CUSTOM_AGENT_WATCH_EXECUTION: "CUSTOM_AGENT_WATCH_EXECUTION",
102
+ CUSTOM_AGENT_STOP_WATCH: "CUSTOM_AGENT_STOP_WATCH",
103
+ CUSTOM_FUNCTION_RUN: "CUSTOM_FUNCTION_RUN",
104
+ CUSTOM_FUNCTION_GET_RUN: "CUSTOM_FUNCTION_GET_RUN",
105
+ CUSTOM_FUNCTION_ON_RUN_COMPLETE: "CUSTOM_FUNCTION_ON_RUN_COMPLETE",
106
+ CUSTOM_FUNCTION_STOP_WATCH: "CUSTOM_FUNCTION_STOP_WATCH",
107
+ DECISION_TABLE_EXECUTE: "DECISION_TABLE_EXECUTE",
108
+ REPORT_GET_DATA: "REPORT_GET_DATA",
109
+ REPORT_GET_COUNT: "REPORT_GET_COUNT",
110
+ REPORT_GET_FIELDS: "REPORT_GET_FIELDS",
111
+ DATAFORM_IMPORT_CSV: "DATAFORM_IMPORT_CSV",
112
+ DATAFORM_OPEN_FORM: "DATAFORM_OPEN_FORM",
113
+ DATAFORM_GET_FIELDS: "DATAFORM_GET_FIELDS",
114
+ DATAFORM_GET_ITEMS: "DATAFORM_GET_ITEMS",
115
+ DATAFORM_CREATE_ITEM: "DATAFORM_CREATE_ITEM",
116
+ DATAFORM_UPDATE_ITEM: "DATAFORM_UPDATE_ITEM",
117
+ DATAFORM_GET_ITEM: "DATAFORM_GET_ITEM",
118
+ DATAFORM_DELETE_ITEM: "DATAFORM_DELETE_ITEM",
119
+ DATAFORM_DISCARD_ITEM: "DATAFORM_DISCARD_ITEM",
120
+ DATAFORM_SUBMIT_ITEM: "DATAFORM_SUBMIT_ITEM",
121
+ DATAFORM_INIT_FORM: "DATAFORM_INIT_FORM",
122
+ DATAFORM_GET_FIELD_OPTIONS: "DATAFORM_GET_FIELD_OPTIONS",
123
+ PROCESS_OPEN_FORM: "PROCESS_OPEN_FORM",
124
+ PROCESS_GET_FIELDS: "PROCESS_GET_FIELDS",
125
+ PROCESS_GET_MYTASK_FIELDS: "PROCESS_GET_MYTASK_FIELDS",
126
+ PROCESS_GET_PARTICIPATED_FIELDS: "PROCESS_GET_PARTICIPATED_FIELDS",
127
+ PROCESS_GET_MY_ITEMS_FIELDS: "PROCESS_GET_MY_ITEMS_FIELDS",
128
+ PROCESS_GET_MY_ITEMS: "PROCESS_GET_MY_ITEMS",
129
+ PROCESS_GET_MY_TASKS_ITEMS: "PROCESS_GET_MY_TASKS_ITEMS",
130
+ PROCESS_GET_PARTICIPATED_ITEMS: "PROCESS_GET_PARTICIPATED_ITEMS",
131
+ PROCESS_GET_ADMIN_ITEMS: "PROCESS_GET_ADMIN_ITEMS",
132
+ PROCESS_CREATE_ITEM: "PROCESS_CREATE_ITEM",
133
+ PROCESS_UPDATE_ITEM: "PROCESS_UPDATE_ITEM",
134
+ PROCESS_GET_ITEM: "PROCESS_GET_ITEM",
135
+ PROCESS_DELETE_ITEM: "PROCESS_DELETE_ITEM",
136
+ PROCESS_GET_ADMIN_ITEM: "PROCESS_GET_ADMIN_ITEM",
137
+ PROCESS_UPDATE_ADMIN_ITEM: "PROCESS_UPDATE_ADMIN_ITEM",
138
+ PROCESS_SUBMIT_ITEM: "PROCESS_SUBMIT_ITEM",
139
+ PROCESS_REJECT_ITEM: "PROCESS_REJECT_ITEM",
140
+ PROCESS_WITHDRAW_ITEM: "PROCESS_WITHDRAW_ITEM",
141
+ PROCESS_SENDBACK_ITEM: "PROCESS_SENDBACK_ITEM",
142
+ PROCESS_REASSIGN_ITEM: "PROCESS_REASSIGN_ITEM",
143
+ PROCESS_GET_REASSIGNEES: "PROCESS_GET_REASSIGNEES",
144
+ PROCESS_RESTART_ITEM: "PROCESS_RESTART_ITEM",
145
+ PROCESS_DISCARD_ITEM: "PROCESS_DISCARD_ITEM",
146
+ PROCESS_GET_PROGRESS: "PROCESS_GET_PROGRESS",
147
+ PROCESS_INIT_FORM: "PROCESS_INIT_FORM",
148
+ PROCESS_GET_FIELD_OPTIONS: "PROCESS_GET_FIELD_OPTIONS",
149
+ PROCESS_PARSE_ATTACHMENT: "PROCESS_PARSE_ATTACHMENT",
150
+ BOARD_IMPORT_CSV: "BOARD_IMPORT_CSV",
151
+ BOARD_OPEN_FORM: "BOARD_OPEN_FORM",
152
+ BOARD_GET_FIELDS: "BOARD_GET_FIELDS",
153
+ BOARD_GET_ITEMS: "BOARD_GET_ITEMS",
154
+ BOARD_CREATE_ITEM: "BOARD_CREATE_ITEM",
155
+ BOARD_UPDATE_ITEM: "BOARD_UPDATE_ITEM",
156
+ BOARD_GET_ITEM: "BOARD_GET_ITEM",
157
+ BOARD_DELETE_ITEM: "BOARD_DELETE_ITEM",
158
+ BOARD_SUBMIT_ITEM: "BOARD_SUBMIT_ITEM",
159
+ BOARD_DISCARD_ITEM: "BOARD_DISCARD_ITEM",
160
+ BOARD_INIT_FORM: "BOARD_INIT_FORM",
161
+ BOARD_GET_FIELD_OPTIONS: "BOARD_GET_FIELD_OPTIONS"
162
+ };
163
+ const EVENT_TYPES = {
164
+ COMPONENT_ON_MOUNT: "componentOnMount",
165
+ CC_ON_PARAMS_CHANGE: "onCustomComponentParamsChange",
166
+ CC_ON_ROUTE_CHANGE: "onCustomComponentRouteChange",
167
+ CUSTOM_AGENT_EXECUTION_COMPLETE: "onCustomAgentExecutionComplete",
168
+ CUSTOM_FUNCTION_RUN_COMPLETE: "onCustomFunctionRunComplete"
169
+ };
170
+ const DEFAULTS = {
171
+ POPUP_ID: "ACTIVE_POP_UP"
172
+ };
173
+ function generateId(prefix = "lcncsdk") {
174
+ return `${prefix}-${nanoid()}`;
175
+ }
176
+ const globalInstances = {};
177
+ const pendingRequestIds = /* @__PURE__ */ new Set();
178
+ const ENVELOPE_COMMANDS = /* @__PURE__ */ new Set([
179
+ LISTENER_CMDS.API,
180
+ LISTENER_CMDS.CUSTOM_FUNCTION_RUN,
181
+ LISTENER_CMDS.CUSTOM_FUNCTION_GET_RUN
182
+ ]);
183
+ function processResponse(req, resp) {
184
+ if (resp && Object.keys(resp).length === 1 && !ENVELOPE_COMMANDS.has(req.command)) {
185
+ let value = Object.values(resp)[0];
186
+ if (value === "undefined")
187
+ return void 0;
188
+ return value;
189
+ } else {
190
+ return resp;
191
+ }
192
+ }
193
+ function postMessage(args) {
194
+ if (globalThis.parent && globalThis.parent !== globalThis) {
195
+ globalThis.parent.postMessage(args, "*");
196
+ } else {
197
+ globalThis.postMessage(args);
198
+ }
199
+ }
200
+ function onMessage(event) {
201
+ if (event.origin !== globalThis.location.origin) {
202
+ const data = event.data;
203
+ if (data == null ? void 0 : data.isEvent) {
204
+ const { target, eventParams, eventName, eventConfig = {} } = data;
205
+ let targetInstance = globalInstances[target];
206
+ if (!targetInstance)
207
+ return;
208
+ targetInstance._dispatchEvent(eventName, eventParams);
209
+ if (eventConfig.once) {
210
+ targetInstance._removeEventListener(eventName);
211
+ }
212
+ return;
213
+ }
214
+ let { _req: req, resp } = data;
215
+ if (req == null ? void 0 : req._id) {
216
+ let targetInstance = globalInstances[req._id];
217
+ if (targetInstance) {
218
+ targetInstance._dispatchMessageEvents(req, resp);
219
+ if (pendingRequestIds.delete(req._id)) {
220
+ Reflect.deleteProperty(globalInstances, req._id);
221
+ }
222
+ }
223
+ }
224
+ }
225
+ }
226
+ globalThis.addEventListener("message", onMessage);
227
+ class EventBase {
228
+ constructor() {
229
+ __privateAdd(this, _listeners, void 0);
230
+ __privateSet(this, _listeners, {});
231
+ }
232
+ _addEventListener(eventName, callBack) {
233
+ var _a;
234
+ __privateGet(this, _listeners)[eventName] = ((_a = __privateGet(this, _listeners)) == null ? void 0 : _a[eventName]) || [];
235
+ __privateGet(this, _listeners)[eventName].push(callBack);
236
+ }
237
+ _removeEventListener(eventName, callBack) {
238
+ if (callBack) {
239
+ const listeners = __privateGet(this, _listeners)[eventName] || [];
240
+ const index = listeners.indexOf(callBack);
241
+ index > -1 && listeners.splice(index, 1);
242
+ return;
243
+ }
244
+ Reflect.deleteProperty(__privateGet(this, _listeners), eventName);
245
+ }
246
+ _dispatchEvent(eventName, eventParams) {
247
+ if (Array.isArray(__privateGet(this, _listeners)[eventName])) {
248
+ __privateGet(this, _listeners)[eventName].forEach(
249
+ (callBack) => callBack(eventParams)
250
+ );
251
+ return true;
252
+ }
253
+ return false;
254
+ }
255
+ _dispatchMessageEvents(req, resp) {
256
+ let target = req._id;
257
+ if (Array.isArray(__privateGet(this, _listeners)[target])) {
258
+ __privateGet(this, _listeners)[target].forEach((listener) => {
259
+ try {
260
+ let processedResp = processResponse(req, resp);
261
+ listener(processedResp);
262
+ } catch (err) {
263
+ console.error("Message callback error: ", err);
264
+ }
265
+ });
266
+ this._removeEventListener(target);
267
+ }
268
+ }
269
+ }
270
+ _listeners = new WeakMap();
271
+ class BaseSDK extends EventBase {
272
+ _postMessageAsync(command, args, hasCallBack, callBack) {
273
+ return new Promise((resolve, reject) => {
274
+ const _id = generateId(command.toLowerCase());
275
+ postMessage({ _id, command, ...args });
276
+ globalInstances[_id] = this;
277
+ pendingRequestIds.add(_id);
278
+ this._addEventListener(_id, async (data) => {
279
+ if ((data == null ? void 0 : data.errorMessage) || (data == null ? void 0 : data.isError)) {
280
+ reject(data);
281
+ } else {
282
+ if (hasCallBack && callBack) {
283
+ data = await callBack(data);
284
+ }
285
+ resolve(data);
286
+ }
287
+ });
288
+ });
289
+ }
290
+ _postMessageBounded(command, args, options) {
291
+ const _id = generateId(command.toLowerCase());
292
+ let timer;
293
+ let settled = false;
294
+ const release = () => {
295
+ settled = true;
296
+ clearTimeout(timer);
297
+ this._removeEventListener(_id);
298
+ pendingRequestIds.delete(_id);
299
+ Reflect.deleteProperty(globalInstances, _id);
300
+ };
301
+ const promise = new Promise((resolve, reject) => {
302
+ timer = setTimeout(() => {
303
+ release();
304
+ reject(options.timeoutError);
305
+ }, options.timeoutMs);
306
+ globalInstances[_id] = this;
307
+ pendingRequestIds.add(_id);
308
+ this._addEventListener(_id, (data) => {
309
+ release();
310
+ if ((data == null ? void 0 : data.errorMessage) || (data == null ? void 0 : data.isError))
311
+ reject(data);
312
+ else
313
+ resolve(data);
314
+ });
315
+ try {
316
+ postMessage({ _id, command, ...args });
317
+ } catch (error) {
318
+ release();
319
+ reject(options.sendError);
320
+ }
321
+ });
322
+ return {
323
+ promise,
324
+ cancel: () => {
325
+ if (!settled)
326
+ release();
327
+ }
328
+ };
329
+ }
330
+ _postMessage(command, args, callBack) {
331
+ const _id = generateId(command.toLowerCase());
332
+ postMessage({ _id, command, ...args });
333
+ if (callBack) {
334
+ this._addEventListener(args.eventName, callBack);
335
+ }
336
+ }
337
+ _postMessageSync(command, args) {
338
+ let intialValue = 0;
339
+ const _id = generateId(command.toLowerCase());
340
+ let data = { _id, command, ...args };
341
+ let atomics = new AtomicsHandler();
342
+ atomics.reset();
343
+ atomics.store(0, intialValue);
344
+ atomics.encodeData(1, data);
345
+ postMessage(atomics.sab);
346
+ atomics.wait(0, intialValue, 1e4);
347
+ let decodedData = atomics.decodeData();
348
+ let { _req: req, resp } = decodedData;
349
+ let processedResp = processResponse(req, resp);
350
+ if (processedResp == null ? void 0 : processedResp.isError) {
351
+ throw new Error(`Error: ${JSON.stringify(processedResp, null, 2)}`);
352
+ }
353
+ return processedResp;
354
+ }
355
+ }
356
+ let sharedArrayBufferInstance;
357
+ class AtomicsHandler {
358
+ constructor() {
359
+ __privateAdd(this, _textEncoder, void 0);
360
+ __privateAdd(this, _textDecoder, void 0);
361
+ __privateSet(this, _textEncoder, new TextEncoder());
362
+ __privateSet(this, _textDecoder, new TextDecoder());
363
+ sharedArrayBufferInstance = sharedArrayBufferInstance || new SharedArrayBuffer(1024 * 1024);
364
+ this.sab = sharedArrayBufferInstance;
365
+ this.int32Array = new Int32Array(this.sab);
366
+ }
367
+ load(index = 0) {
368
+ return Atomics.load(this.int32Array, index);
369
+ }
370
+ store(index = 0, data) {
371
+ return Atomics.store(this.int32Array, index, data);
372
+ }
373
+ reset() {
374
+ return this.int32Array.fill(0);
375
+ }
376
+ notify(index = 0, count = 1) {
377
+ return Atomics.notify(this.int32Array, index, count);
378
+ }
379
+ wait(index, value, timeout) {
380
+ return Atomics.wait(this.int32Array, index, value, timeout);
381
+ }
382
+ encodeData(index = 0, data) {
383
+ const replacer = (key, value) => value === void 0 ? "undefined" : value;
384
+ let string = JSON.stringify(data, replacer);
385
+ let encodedData = __privateGet(this, _textEncoder).encode(string);
386
+ this.int32Array.set(encodedData, index);
387
+ return this.int32Array;
388
+ }
389
+ decodeData() {
390
+ let uInt8Array = new Uint8Array(this.int32Array);
391
+ let string = __privateGet(this, _textDecoder).decode(uInt8Array).replaceAll(/\x00/g, "");
392
+ return JSON.parse(string);
393
+ }
394
+ }
395
+ _textEncoder = new WeakMap();
396
+ _textDecoder = new WeakMap();
397
+ class Form extends BaseSDK {
398
+ constructor(storeId, flowId, instanceId, activityInstanceId) {
399
+ super();
400
+ this.type = "Form";
401
+ this.storeId = storeId;
402
+ this.flowId = flowId;
403
+ this.instanceId = instanceId;
404
+ this.activityInstanceId = activityInstanceId;
405
+ }
406
+ toJSON() {
407
+ return this._postMessageAsync(LISTENER_CMDS.TO_JSON, {
408
+ storeId: this.storeId,
409
+ instanceId: this.instanceId
410
+ });
411
+ }
412
+ getField(fieldId) {
413
+ return this._postMessageAsync(LISTENER_CMDS.GET_FORM_FIELD, {
414
+ storeId: this.storeId,
415
+ instanceId: this.instanceId,
416
+ fieldId
417
+ });
418
+ }
419
+ updateField(args) {
420
+ return this._postMessageAsync(LISTENER_CMDS.UPDATE_FORM, {
421
+ storeId: this.storeId,
422
+ instanceId: this.instanceId,
423
+ data: args
424
+ });
425
+ }
426
+ getTable(tableId) {
427
+ return new Table(
428
+ this.storeId,
429
+ this.flowId,
430
+ this.instanceId,
431
+ tableId,
432
+ this.activityInstanceId,
433
+ this
434
+ );
435
+ }
436
+ }
437
+ class Table extends BaseSDK {
438
+ constructor(storeId, flowId, instanceId, tableId, activityInstanceId, parent) {
439
+ super();
440
+ this.tableId = tableId;
441
+ this.storeId = storeId;
442
+ this.flowId = flowId;
443
+ this.instanceId = instanceId;
444
+ this.activityInstanceId = activityInstanceId;
445
+ this.parent = parent;
446
+ }
447
+ toJSON() {
448
+ return this._postMessageAsync(LISTENER_CMDS.TO_JSON, {
449
+ storeId: this.storeId,
450
+ instanceId: this.instanceId,
451
+ tableId: this.tableId
452
+ });
453
+ }
454
+ getSelectedRows() {
455
+ return this._postMessageAsync(LISTENER_CMDS.GET_SELECTED_TABLE_ROWS, {
456
+ storeId: this.storeId,
457
+ instanceId: this.instanceId,
458
+ tableId: this.tableId
459
+ });
460
+ }
461
+ getRows() {
462
+ return this._postMessageAsync(
463
+ LISTENER_CMDS.GET_TABLE_ROWS,
464
+ {
465
+ storeId: this.storeId,
466
+ instanceId: this.instanceId,
467
+ tableId: this.tableId
468
+ },
469
+ true,
470
+ (data) => {
471
+ return data.map(
472
+ (row) => new TableForm(
473
+ this.storeId,
474
+ this.flowId,
475
+ this.instanceId,
476
+ this.tableId,
477
+ row.id,
478
+ this.activityInstanceId,
479
+ this.parent
480
+ )
481
+ );
482
+ }
483
+ );
484
+ }
485
+ getRow(rowId) {
486
+ return new TableForm(
487
+ this.storeId,
488
+ this.flowId,
489
+ this.instanceId,
490
+ this.tableId,
491
+ rowId,
492
+ this.activityInstanceId,
493
+ this.parent
494
+ );
495
+ }
496
+ addRow(rowObject) {
497
+ return this._postMessageAsync(LISTENER_CMDS.ADD_TABLE_ROW, {
498
+ storeId: this.storeId,
499
+ instanceId: this.instanceId,
500
+ tableId: this.tableId,
501
+ rowObject
502
+ });
503
+ }
504
+ addRows(rows) {
505
+ return this._postMessageAsync(LISTENER_CMDS.ADD_TABLE_ROWS, {
506
+ storeId: this.storeId,
507
+ instanceId: this.instanceId,
508
+ tableId: this.tableId,
509
+ rows
510
+ });
511
+ }
512
+ deleteRow(rowId) {
513
+ return this._postMessageAsync(LISTENER_CMDS.DELETE_TABLE_ROW, {
514
+ storeId: this.storeId,
515
+ instanceId: this.instanceId,
516
+ tableId: this.tableId,
517
+ rows: [rowId]
518
+ });
519
+ }
520
+ deleteRows(rows) {
521
+ return this._postMessageAsync(LISTENER_CMDS.DELETE_TABLE_ROW, {
522
+ storeId: this.storeId,
523
+ instanceId: this.instanceId,
524
+ tableId: this.tableId,
525
+ rows
526
+ });
527
+ }
528
+ }
529
+ class TableForm extends BaseSDK {
530
+ constructor(storeId, flowId, instanceId, tableId, rowId, activityInstanceId, parent) {
531
+ super();
532
+ this.storeId = storeId;
533
+ this.flowId = flowId;
534
+ this.instanceId = instanceId;
535
+ this.type = "TabelForm";
536
+ this.tableId = tableId;
537
+ this.rowId = rowId;
538
+ this.activityInstanceId = activityInstanceId;
539
+ this.parent = parent;
540
+ }
541
+ getParent() {
542
+ if (this.parent)
543
+ return this.parent;
544
+ return new Form(
545
+ this.storeId,
546
+ this.flowId,
547
+ this.instanceId,
548
+ this.activityInstanceId
549
+ );
550
+ }
551
+ toJSON() {
552
+ return this._postMessageAsync(LISTENER_CMDS.TO_JSON, {
553
+ storeId: this.storeId,
554
+ instanceId: this.instanceId,
555
+ tableId: this.tableId,
556
+ rowId: this.rowId
557
+ });
558
+ }
559
+ getField(fieldId) {
560
+ return this._postMessageAsync(LISTENER_CMDS.GET_FORM_FIELD, {
561
+ storeId: this.storeId,
562
+ instanceId: this.instanceId,
563
+ tableId: this.tableId,
564
+ rowId: this.rowId,
565
+ fieldId
566
+ });
567
+ }
568
+ updateField(args) {
569
+ return this._postMessageAsync(LISTENER_CMDS.UPDATE_FORM, {
570
+ storeId: this.storeId,
571
+ instanceId: this.instanceId,
572
+ tableId: this.tableId,
573
+ rowId: this.rowId,
574
+ data: args
575
+ });
576
+ }
577
+ }
578
+ class Client extends BaseSDK {
579
+ showInfo(message) {
580
+ return super._postMessageAsync(LISTENER_CMDS.MESSAGE, { message });
581
+ }
582
+ showConfirm(args) {
583
+ return super._postMessageAsync(LISTENER_CMDS.CONFIRM, {
584
+ data: {
585
+ title: args.title,
586
+ content: args.content,
587
+ okText: args.okText || "Ok",
588
+ cancelText: args.cancelText || "Cancel"
589
+ }
590
+ });
591
+ }
592
+ redirect(url) {
593
+ return super._postMessageAsync(LISTENER_CMDS.REDIRECT, { url });
594
+ }
595
+ getImageUrl(imageValue) {
596
+ return this._postMessageAsync(LISTENER_CMDS.GET_IMAGE_URL, {
597
+ imageValue
598
+ });
599
+ }
600
+ openFilePicker(options) {
601
+ return this._postMessageAsync(LISTENER_CMDS.FILEPICKER_OPEN, {
602
+ options
603
+ });
604
+ }
605
+ openScanner(options = {}) {
606
+ return this._postMessageAsync(LISTENER_CMDS.SCANNER_OPEN, {
607
+ options
608
+ });
609
+ }
610
+ pickLocation(value) {
611
+ return this._postMessageAsync(LISTENER_CMDS.GEOLOCATION_OPEN, {
612
+ value
613
+ });
614
+ }
615
+ uploadFile(file, fileName) {
616
+ return this._postMessageAsync(LISTENER_CMDS.FILE_UPLOAD, {
617
+ file,
618
+ fileName: fileName != null ? fileName : file.name
619
+ });
620
+ }
621
+ openFilePreview(args) {
622
+ var _a;
623
+ return this._postMessageAsync(LISTENER_CMDS.FILEPREVIEW_OPEN, {
624
+ files: args.files,
625
+ indexOfFile: (_a = args.indexOfFile) != null ? _a : 0
626
+ });
627
+ }
628
+ }
629
+ class Formatter extends BaseSDK {
630
+ toDate(date) {
631
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE, {
632
+ date
633
+ });
634
+ }
635
+ toDateTime(date) {
636
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE_TIME, {
637
+ date
638
+ });
639
+ }
640
+ toNumber(value) {
641
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_NUMBER, {
642
+ value
643
+ });
644
+ }
645
+ toCurrency(value, currencyCode) {
646
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_CURRENCY, {
647
+ value,
648
+ currencyCode
649
+ });
650
+ }
651
+ toBoolean(value) {
652
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_BOOLEAN, {
653
+ value
654
+ });
655
+ }
656
+ }
657
+ function requireFieldAsync(value, fieldName) {
658
+ if (!value) {
659
+ return Promise.reject({ message: `${fieldName} is required` });
660
+ }
661
+ return null;
662
+ }
663
+ function requireFieldsAsync(fields) {
664
+ const missingFields = fields.filter((f) => !f.value).map((f) => f.name);
665
+ if (missingFields.length > 0) {
666
+ return Promise.reject({
667
+ message: `${missingFields.join(" and ")} ${missingFields.length > 1 ? "are" : "is"} required`
668
+ });
669
+ }
670
+ return null;
671
+ }
672
+ class Component extends BaseSDK {
673
+ constructor(props) {
674
+ super();
675
+ __privateAdd(this, _registerComponentAPIs);
676
+ this._id = props.componentId;
677
+ this.type = "Component";
678
+ globalInstances[this._id] = this;
679
+ __privateMethod(this, _registerComponentAPIs, registerComponentAPIs_fn).call(this, props.componentMethods);
680
+ }
681
+ onMount(callback) {
682
+ this._postMessage(
683
+ LISTENER_CMDS.COMPONENT_ADD_EVENT_LISTENER,
684
+ {
685
+ id: this._id,
686
+ eventName: EVENT_TYPES.COMPONENT_ON_MOUNT,
687
+ eventConfig: {
688
+ once: true
689
+ }
690
+ },
691
+ callback
692
+ );
693
+ }
694
+ refresh() {
695
+ return this._postMessageAsync(LISTENER_CMDS.COMPONENT_REFRESH, {
696
+ id: this._id
697
+ });
698
+ }
699
+ show() {
700
+ return this._postMessageAsync(LISTENER_CMDS.COMPONENT_SHOW, {
701
+ id: this._id
702
+ });
703
+ }
704
+ hide() {
705
+ return this._postMessageAsync(LISTENER_CMDS.COMPONENT_HIDE, {
706
+ id: this._id
707
+ });
708
+ }
709
+ }
710
+ _registerComponentAPIs = new WeakSet();
711
+ registerComponentAPIs_fn = function(componentAPIs) {
712
+ componentAPIs == null ? void 0 : componentAPIs.forEach((Api) => {
713
+ this[Api.name] = (...args) => {
714
+ if (Api.type === "method") {
715
+ return this._postMessageAsync(`COMPONENT_${Api.name}`, {
716
+ id: this._id,
717
+ parameters: args
718
+ });
719
+ } else if (Api.type === "event") {
720
+ this._postMessage(
721
+ LISTENER_CMDS.COMPONENT_ADD_EVENT_LISTENER,
722
+ {
723
+ id: this._id,
724
+ eventName: Api.name,
725
+ eventConfig: args[1]
726
+ },
727
+ args[0]
728
+ );
729
+ }
730
+ };
731
+ });
732
+ };
733
+ class Popup extends BaseSDK {
734
+ constructor(props) {
735
+ super();
736
+ this.type = "Popup";
737
+ this._id = props.popupId || DEFAULTS.POPUP_ID;
738
+ }
739
+ getParameter(key) {
740
+ return this._postMessageAsync(LISTENER_CMDS.GET_POPUP_PARAMS, {
741
+ key,
742
+ popupId: this._id
743
+ });
744
+ }
745
+ getAllParameters() {
746
+ return this._postMessageAsync(LISTENER_CMDS.GET_ALL_POPUP_PARAMS, {
747
+ popupId: this._id
748
+ });
749
+ }
750
+ close() {
751
+ return this._postMessageAsync(LISTENER_CMDS.CLOSE_POPUP, {});
752
+ }
753
+ getComponent(componentId) {
754
+ return this._postMessageAsync(
755
+ LISTENER_CMDS.COMPONENT_GET,
756
+ { componentId },
757
+ true,
758
+ (data) => {
759
+ return new Component(data);
760
+ }
761
+ );
762
+ }
763
+ }
764
+ class Page extends BaseSDK {
765
+ constructor(props, isCustomComponent = false) {
766
+ var _a;
767
+ super();
768
+ this.type = "Page";
769
+ this.popup = new Popup({});
770
+ this._id = props.pageId;
771
+ this._route = (_a = props.initialRoute) != null ? _a : "";
772
+ }
773
+ getParameter(key) {
774
+ return this._postMessageAsync(LISTENER_CMDS.GET_PAGE_PARAMS, {
775
+ key
776
+ });
777
+ }
778
+ getAllParameters() {
779
+ return this._postMessageAsync(LISTENER_CMDS.GET_ALL_PAGE_PARAMS, {
780
+ pageId: this._id
781
+ });
782
+ }
783
+ getVariable(key) {
784
+ return this._postMessageAsync(LISTENER_CMDS.GET_PAGE_VARIABLE, {
785
+ key
786
+ });
787
+ }
788
+ setVariable(key, value) {
789
+ return this._postMessageAsync(LISTENER_CMDS.SET_PAGE_VARIABLE, {
790
+ key,
791
+ value
792
+ });
793
+ }
794
+ openPopup(popupId, popupParams) {
795
+ return this._postMessageAsync(LISTENER_CMDS.OPEN_POPUP, {
796
+ popupId,
797
+ popupParams
798
+ });
799
+ }
800
+ getComponent(componentId) {
801
+ return this._postMessageAsync(
802
+ LISTENER_CMDS.COMPONENT_GET,
803
+ { componentId },
804
+ true,
805
+ (data) => new Component(data)
806
+ );
807
+ }
808
+ setRoute(path) {
809
+ this._route = path;
810
+ return this._postMessage(LISTENER_CMDS.CC_SET_ROUTE, { route: path });
811
+ }
812
+ getRoute() {
813
+ return this._route;
814
+ }
815
+ }
816
+ class DecisionTable extends BaseSDK {
817
+ constructor(flowId) {
818
+ super();
819
+ this.flowId = flowId;
820
+ }
821
+ evaluate(payload) {
822
+ return this._postMessageAsync(LISTENER_CMDS.DECISION_TABLE_EXECUTE, {
823
+ flowId: this.flowId,
824
+ payload
825
+ });
826
+ }
827
+ }
828
+ class Dataform extends BaseSDK {
829
+ constructor(flowId) {
830
+ super();
831
+ this._id = flowId;
832
+ }
833
+ getItems(options) {
834
+ return this._postMessageAsync(LISTENER_CMDS.DATAFORM_GET_ITEMS, {
835
+ flowId: this._id,
836
+ viewId: (options == null ? void 0 : options.viewId) || "",
837
+ searchValue: (options == null ? void 0 : options.searchValue) || "",
838
+ pageNumber: (options == null ? void 0 : options.pageNumber) || 1,
839
+ pageSize: (options == null ? void 0 : options.pageSize) || 50,
840
+ payload: (options == null ? void 0 : options.payload) || {}
841
+ });
842
+ }
843
+ getItem(options) {
844
+ const error = requireFieldAsync(options.itemId, "itemId");
845
+ if (error)
846
+ return error;
847
+ return this._postMessageAsync(LISTENER_CMDS.DATAFORM_GET_ITEM, {
848
+ flowId: this._id,
849
+ itemId: options.itemId,
850
+ viewId: options.viewId || ""
851
+ });
852
+ }
853
+ createItem(options) {
854
+ return this._postMessageAsync(LISTENER_CMDS.DATAFORM_CREATE_ITEM, {
855
+ flowId: this._id,
856
+ data: (options == null ? void 0 : options.data) || {},
857
+ viewId: (options == null ? void 0 : options.viewId) || ""
858
+ });
859
+ }
860
+ updateItem(options) {
861
+ const error = requireFieldAsync(options.itemId, "itemId");
862
+ if (error)
863
+ return error;
864
+ return this._postMessageAsync(LISTENER_CMDS.DATAFORM_UPDATE_ITEM, {
865
+ flowId: this._id,
866
+ itemId: options.itemId,
867
+ data: options.data,
868
+ viewId: options.viewId || ""
869
+ });
870
+ }
871
+ importCSV(defaultValues) {
872
+ return this._postMessageAsync(LISTENER_CMDS.DATAFORM_IMPORT_CSV, {
873
+ flowId: this._id,
874
+ defaultValues
875
+ });
876
+ }
877
+ openForm(item) {
878
+ const error = requireFieldAsync(item._id, "Instance Id (_id)");
879
+ if (error)
880
+ return error;
881
+ return this._postMessageAsync(LISTENER_CMDS.DATAFORM_OPEN_FORM, {
882
+ flowId: this._id,
883
+ itemId: item._id,
884
+ viewId: item._view_id || ""
885
+ });
886
+ }
887
+ deleteItem(options) {
888
+ const error = requireFieldAsync(options.itemId, "itemId");
889
+ if (error)
890
+ return error;
891
+ return this._postMessageAsync(LISTENER_CMDS.DATAFORM_DELETE_ITEM, {
892
+ flowId: this._id,
893
+ itemId: options.itemId,
894
+ viewId: options.viewId || ""
895
+ });
896
+ }
897
+ discardItem(options) {
898
+ return this._postMessageAsync(LISTENER_CMDS.DATAFORM_DISCARD_ITEM, {
899
+ flowId: this._id,
900
+ viewId: (options == null ? void 0 : options.viewId) || ""
901
+ });
902
+ }
903
+ submitItem(options) {
904
+ const error = requireFieldAsync(options.itemId, "itemId");
905
+ if (error)
906
+ return error;
907
+ return this._postMessageAsync(LISTENER_CMDS.DATAFORM_SUBMIT_ITEM, {
908
+ flowId: this._id,
909
+ itemId: options.itemId,
910
+ data: options.data || {},
911
+ viewId: options.viewId || ""
912
+ });
913
+ }
914
+ getFields(options) {
915
+ return this._postMessageAsync(LISTENER_CMDS.DATAFORM_GET_FIELDS, {
916
+ flowId: this._id,
917
+ viewId: (options == null ? void 0 : options.viewId) || ""
918
+ });
919
+ }
920
+ getFieldOptions(options) {
921
+ const error = requireFieldsAsync([
922
+ { value: options == null ? void 0 : options.instanceId, name: "instanceId" },
923
+ { value: options == null ? void 0 : options.fieldId, name: "fieldId" }
924
+ ]);
925
+ if (error)
926
+ return error;
927
+ return this._postMessageAsync(
928
+ LISTENER_CMDS.DATAFORM_GET_FIELD_OPTIONS,
929
+ {
930
+ flowId: this._id,
931
+ instanceId: options.instanceId,
932
+ fieldId: options.fieldId,
933
+ fieldType: options.fieldType,
934
+ tableId: options.tableId,
935
+ tableRowId: options.tableRowId,
936
+ pageNumber: options.pageNumber,
937
+ pageSize: options.pageSize,
938
+ searchValue: options.searchValue
939
+ }
940
+ );
941
+ }
942
+ }
943
+ class Board extends BaseSDK {
944
+ constructor(flowId) {
945
+ super();
946
+ this._id = flowId;
947
+ }
948
+ importCSV(defaultValues) {
949
+ return this._postMessageAsync(LISTENER_CMDS.BOARD_IMPORT_CSV, {
950
+ flowId: this._id,
951
+ defaultValues
952
+ });
953
+ }
954
+ openForm(item) {
955
+ const error = requireFieldAsync(item._id, "Instance Id (_id)");
956
+ if (error)
957
+ return error;
958
+ return this._postMessageAsync(LISTENER_CMDS.BOARD_OPEN_FORM, {
959
+ flowId: this._id,
960
+ itemId: item._id,
961
+ viewId: item._view_id
962
+ });
963
+ }
964
+ getItems(options) {
965
+ return this._postMessageAsync(LISTENER_CMDS.BOARD_GET_ITEMS, {
966
+ flowId: this._id,
967
+ viewId: (options == null ? void 0 : options.viewId) || "",
968
+ searchValue: (options == null ? void 0 : options.searchValue) || "",
969
+ pageNumber: (options == null ? void 0 : options.pageNumber) || 1,
970
+ pageSize: (options == null ? void 0 : options.pageSize) || 50,
971
+ payload: (options == null ? void 0 : options.payload) || {}
972
+ });
973
+ }
974
+ getItem(options) {
975
+ const error = requireFieldAsync(options.instanceId, "instanceId");
976
+ if (error)
977
+ return error;
978
+ return this._postMessageAsync(LISTENER_CMDS.BOARD_GET_ITEM, {
979
+ flowId: this._id,
980
+ instanceId: options.instanceId,
981
+ viewId: options.viewId || ""
982
+ });
983
+ }
984
+ createItem(options) {
985
+ return this._postMessageAsync(LISTENER_CMDS.BOARD_CREATE_ITEM, {
986
+ flowId: this._id,
987
+ data: (options == null ? void 0 : options.data) || {}
988
+ });
989
+ }
990
+ updateItem(options) {
991
+ const error = requireFieldAsync(options.instanceId, "instanceId");
992
+ if (error)
993
+ return error;
994
+ return this._postMessageAsync(LISTENER_CMDS.BOARD_UPDATE_ITEM, {
995
+ flowId: this._id,
996
+ instanceId: options.instanceId,
997
+ data: options.data
998
+ });
999
+ }
1000
+ deleteItem(options) {
1001
+ const error = requireFieldAsync(options.instanceId, "instanceId");
1002
+ if (error)
1003
+ return error;
1004
+ return this._postMessageAsync(LISTENER_CMDS.BOARD_DELETE_ITEM, {
1005
+ flowId: this._id,
1006
+ instanceId: options.instanceId
1007
+ });
1008
+ }
1009
+ submitItem(options) {
1010
+ const error = requireFieldAsync(options.instanceId, "instanceId");
1011
+ if (error)
1012
+ return error;
1013
+ return this._postMessageAsync(LISTENER_CMDS.BOARD_SUBMIT_ITEM, {
1014
+ flowId: this._id,
1015
+ instanceId: options.instanceId
1016
+ });
1017
+ }
1018
+ discardItem(options) {
1019
+ const error = requireFieldAsync(options.instanceId, "instanceId");
1020
+ if (error)
1021
+ return error;
1022
+ return this._postMessageAsync(LISTENER_CMDS.BOARD_DISCARD_ITEM, {
1023
+ flowId: this._id,
1024
+ instanceId: options.instanceId
1025
+ });
1026
+ }
1027
+ getFields(options) {
1028
+ return this._postMessageAsync(LISTENER_CMDS.BOARD_GET_FIELDS, {
1029
+ flowId: this._id,
1030
+ viewId: (options == null ? void 0 : options.viewId) || ""
1031
+ });
1032
+ }
1033
+ getFieldOptions(options) {
1034
+ const error = requireFieldsAsync([
1035
+ { value: options == null ? void 0 : options.instanceId, name: "instanceId" },
1036
+ { value: options == null ? void 0 : options.fieldId, name: "fieldId" }
1037
+ ]);
1038
+ if (error)
1039
+ return error;
1040
+ return this._postMessageAsync(LISTENER_CMDS.BOARD_GET_FIELD_OPTIONS, {
1041
+ flowId: this._id,
1042
+ instanceId: options.instanceId,
1043
+ fieldId: options.fieldId,
1044
+ fieldType: options.fieldType,
1045
+ tableId: options == null ? void 0 : options.tableId,
1046
+ tableRowId: options == null ? void 0 : options.tableRowId,
1047
+ pageNumber: options == null ? void 0 : options.pageNumber,
1048
+ pageSize: options == null ? void 0 : options.pageSize,
1049
+ searchValue: options == null ? void 0 : options.searchValue
1050
+ });
1051
+ }
1052
+ }
1053
+ class Process extends BaseSDK {
1054
+ constructor(flowId) {
1055
+ super();
1056
+ this._id = flowId;
1057
+ }
1058
+ getMyItems(options) {
1059
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_GET_MY_ITEMS, {
1060
+ flowId: this._id,
1061
+ status: (options == null ? void 0 : options.status) || "all",
1062
+ searchValue: (options == null ? void 0 : options.searchValue) || "",
1063
+ pageNumber: (options == null ? void 0 : options.pageNumber) || 1,
1064
+ pageSize: (options == null ? void 0 : options.pageSize) || 50,
1065
+ payload: (options == null ? void 0 : options.payload) || {}
1066
+ });
1067
+ }
1068
+ getMyTasksItems(options) {
1069
+ return this._postMessageAsync(
1070
+ LISTENER_CMDS.PROCESS_GET_MY_TASKS_ITEMS,
1071
+ {
1072
+ flowId: this._id,
1073
+ activityId: (options == null ? void 0 : options.activityId) || "",
1074
+ searchValue: (options == null ? void 0 : options.searchValue) || "",
1075
+ pageNumber: (options == null ? void 0 : options.pageNumber) || 1,
1076
+ pageSize: (options == null ? void 0 : options.pageSize) || 50,
1077
+ payload: (options == null ? void 0 : options.payload) || {}
1078
+ }
1079
+ );
1080
+ }
1081
+ getParticipatedItems(options) {
1082
+ return this._postMessageAsync(
1083
+ LISTENER_CMDS.PROCESS_GET_PARTICIPATED_ITEMS,
1084
+ {
1085
+ flowId: this._id,
1086
+ activityId: (options == null ? void 0 : options.activityId) || "",
1087
+ searchValue: (options == null ? void 0 : options.searchValue) || "",
1088
+ pageNumber: (options == null ? void 0 : options.pageNumber) || 1,
1089
+ pageSize: (options == null ? void 0 : options.pageSize) || 50,
1090
+ payload: (options == null ? void 0 : options.payload) || {}
1091
+ }
1092
+ );
1093
+ }
1094
+ getAdminItems(options) {
1095
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_GET_ADMIN_ITEMS, {
1096
+ flowId: this._id,
1097
+ searchValue: (options == null ? void 0 : options.searchValue) || "",
1098
+ pageNumber: (options == null ? void 0 : options.pageNumber) || 1,
1099
+ pageSize: (options == null ? void 0 : options.pageSize) || 50,
1100
+ payload: (options == null ? void 0 : options.payload) || {}
1101
+ });
1102
+ }
1103
+ getItem(options) {
1104
+ const error = requireFieldsAsync([
1105
+ { value: options.instanceId, name: "instanceId" },
1106
+ { value: options.activityInstanceId, name: "activityInstanceId" }
1107
+ ]);
1108
+ if (error)
1109
+ return error;
1110
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_GET_ITEM, {
1111
+ flowId: this._id,
1112
+ instanceId: options.instanceId,
1113
+ activityInstanceId: options.activityInstanceId
1114
+ });
1115
+ }
1116
+ createItem(options) {
1117
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_CREATE_ITEM, {
1118
+ flowId: this._id,
1119
+ data: (options == null ? void 0 : options.data) || {}
1120
+ });
1121
+ }
1122
+ updateItem(options) {
1123
+ const error = requireFieldsAsync([
1124
+ { value: options.instanceId, name: "instanceId" },
1125
+ { value: options.activityInstanceId, name: "activityInstanceId" }
1126
+ ]);
1127
+ if (error)
1128
+ return error;
1129
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_UPDATE_ITEM, {
1130
+ flowId: this._id,
1131
+ instanceId: options.instanceId,
1132
+ activityInstanceId: options.activityInstanceId,
1133
+ data: options.data
1134
+ });
1135
+ }
1136
+ deleteItem(options) {
1137
+ const error = requireFieldAsync(options.instanceId, "instanceId");
1138
+ if (error)
1139
+ return error;
1140
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_DELETE_ITEM, {
1141
+ flowId: this._id,
1142
+ instanceId: options.instanceId
1143
+ });
1144
+ }
1145
+ getAdminItem(options) {
1146
+ const error = requireFieldAsync(options.instanceId, "instanceId");
1147
+ if (error)
1148
+ return error;
1149
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_GET_ADMIN_ITEM, {
1150
+ flowId: this._id,
1151
+ instanceId: options.instanceId
1152
+ });
1153
+ }
1154
+ updateAdminItem(options) {
1155
+ const error = requireFieldsAsync([
1156
+ { value: options.instanceId, name: "instanceId" },
1157
+ { value: options.data, name: "data" }
1158
+ ]);
1159
+ if (error)
1160
+ return error;
1161
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_UPDATE_ADMIN_ITEM, {
1162
+ flowId: this._id,
1163
+ instanceId: options.instanceId,
1164
+ data: options.data
1165
+ });
1166
+ }
1167
+ openForm(item) {
1168
+ const error = requireFieldsAsync([
1169
+ { value: item._id, name: "Instance Id (_id)" },
1170
+ {
1171
+ value: item._activity_instance_id,
1172
+ name: "Activity Instance Id (_activity_instance_id)"
1173
+ }
1174
+ ]);
1175
+ if (error)
1176
+ return error;
1177
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_OPEN_FORM, {
1178
+ flowId: this._id,
1179
+ instanceId: item._id,
1180
+ activityInstanceId: item._activity_instance_id
1181
+ });
1182
+ }
1183
+ submitItem(options) {
1184
+ const error = requireFieldsAsync([
1185
+ { value: options.instanceId, name: "instanceId" },
1186
+ { value: options.activityInstanceId, name: "activityInstanceId" }
1187
+ ]);
1188
+ if (error)
1189
+ return error;
1190
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_SUBMIT_ITEM, {
1191
+ flowId: this._id,
1192
+ instanceId: options.instanceId,
1193
+ activityInstanceId: options.activityInstanceId,
1194
+ comment: options.comment || ""
1195
+ });
1196
+ }
1197
+ rejectItem(options) {
1198
+ const error = requireFieldsAsync([
1199
+ { value: options.instanceId, name: "instanceId" },
1200
+ { value: options.activityInstanceId, name: "activityInstanceId" },
1201
+ { value: options.comment, name: "comment" }
1202
+ ]);
1203
+ if (error)
1204
+ return error;
1205
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_REJECT_ITEM, {
1206
+ flowId: this._id,
1207
+ instanceId: options.instanceId,
1208
+ activityInstanceId: options.activityInstanceId,
1209
+ comment: options.comment
1210
+ });
1211
+ }
1212
+ withdrawItem(options) {
1213
+ const error = requireFieldAsync(options.instanceId, "instanceId");
1214
+ if (error)
1215
+ return error;
1216
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_WITHDRAW_ITEM, {
1217
+ flowId: this._id,
1218
+ instanceId: options.instanceId,
1219
+ comment: options.comment || ""
1220
+ });
1221
+ }
1222
+ sendbackItem(options) {
1223
+ const error = requireFieldsAsync([
1224
+ { value: options.instanceId, name: "instanceId" },
1225
+ { value: options.activityInstanceId, name: "activityInstanceId" },
1226
+ { value: options.stepId, name: "stepId" },
1227
+ { value: options.comment, name: "comment" }
1228
+ ]);
1229
+ if (error)
1230
+ return error;
1231
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_SENDBACK_ITEM, {
1232
+ flowId: this._id,
1233
+ instanceId: options.instanceId,
1234
+ activityInstanceId: options.activityInstanceId,
1235
+ stepId: options.stepId,
1236
+ comment: options.comment
1237
+ });
1238
+ }
1239
+ reassignItem(options) {
1240
+ const error = requireFieldsAsync([
1241
+ { value: options.instanceId, name: "instanceId" },
1242
+ { value: options.activityInstanceId, name: "activityInstanceId" },
1243
+ { value: options.reassignTo, name: "reassignTo" },
1244
+ { value: options.comment, name: "comment" }
1245
+ ]);
1246
+ if (error)
1247
+ return error;
1248
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_REASSIGN_ITEM, {
1249
+ flowId: this._id,
1250
+ instanceId: options.instanceId,
1251
+ activityInstanceId: options.activityInstanceId,
1252
+ reassignTo: options.reassignTo,
1253
+ comment: options.comment,
1254
+ reassignType: options.reassignType || "approver",
1255
+ reassignedFrom: options.reassignedFrom || []
1256
+ });
1257
+ }
1258
+ getReassignees(options) {
1259
+ const error = requireFieldsAsync([
1260
+ { value: options.instanceId, name: "instanceId" },
1261
+ { value: options.activityInstanceId, name: "activityInstanceId" }
1262
+ ]);
1263
+ if (error)
1264
+ return error;
1265
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_GET_REASSIGNEES, {
1266
+ flowId: this._id,
1267
+ instanceId: options.instanceId,
1268
+ activityInstanceId: options.activityInstanceId,
1269
+ pageNumber: options.pageNumber || 1,
1270
+ pageSize: options.pageSize || 50,
1271
+ query: options.query
1272
+ });
1273
+ }
1274
+ restartItem(options) {
1275
+ const error = requireFieldsAsync([
1276
+ { value: options.instanceId, name: "instanceId" },
1277
+ { value: options.activityInstanceId, name: "activityInstanceId" }
1278
+ ]);
1279
+ if (error)
1280
+ return error;
1281
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_RESTART_ITEM, {
1282
+ flowId: this._id,
1283
+ instanceId: options.instanceId,
1284
+ activityInstanceId: options.activityInstanceId
1285
+ });
1286
+ }
1287
+ discardItem(options) {
1288
+ const error = requireFieldAsync(options.instanceId, "instanceId");
1289
+ if (error)
1290
+ return error;
1291
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_DISCARD_ITEM, {
1292
+ flowId: this._id,
1293
+ instanceId: options.instanceId
1294
+ });
1295
+ }
1296
+ getFields() {
1297
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_GET_FIELDS, {
1298
+ flowId: this._id
1299
+ });
1300
+ }
1301
+ getMyTaskFields(options) {
1302
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_GET_MYTASK_FIELDS, {
1303
+ flowId: this._id,
1304
+ activityId: options.activityId,
1305
+ isParticipated: false
1306
+ });
1307
+ }
1308
+ getParticipatedFields(options) {
1309
+ return this._postMessageAsync(
1310
+ LISTENER_CMDS.PROCESS_GET_PARTICIPATED_FIELDS,
1311
+ {
1312
+ flowId: this._id,
1313
+ activityId: options.activityId,
1314
+ isParticipated: true
1315
+ }
1316
+ );
1317
+ }
1318
+ getMyItemsFields(options) {
1319
+ return this._postMessageAsync(
1320
+ LISTENER_CMDS.PROCESS_GET_MY_ITEMS_FIELDS,
1321
+ {
1322
+ flowId: this._id,
1323
+ status: options.status
1324
+ }
1325
+ );
1326
+ }
1327
+ getProgress(options) {
1328
+ const error = requireFieldAsync(options.instanceId, "instanceId");
1329
+ if (error)
1330
+ return error;
1331
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_GET_PROGRESS, {
1332
+ flowId: this._id,
1333
+ instanceId: options.instanceId
1334
+ });
1335
+ }
1336
+ getFieldOptions(options) {
1337
+ const error = requireFieldsAsync([
1338
+ { value: options == null ? void 0 : options.instanceId, name: "instanceId" },
1339
+ { value: options == null ? void 0 : options.activityInstanceId, name: "activityInstanceId" },
1340
+ { value: options == null ? void 0 : options.fieldId, name: "fieldId" }
1341
+ ]);
1342
+ if (error)
1343
+ return error;
1344
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_GET_FIELD_OPTIONS, {
1345
+ flowId: this._id,
1346
+ instanceId: options.instanceId,
1347
+ activityInstanceId: options.activityInstanceId,
1348
+ fieldId: options.fieldId,
1349
+ fieldType: options.fieldType,
1350
+ tableId: options.tableId,
1351
+ tableRowId: options.tableRowId,
1352
+ pageNumber: options.pageNumber,
1353
+ pageSize: options.pageSize,
1354
+ searchValue: options.searchValue
1355
+ });
1356
+ }
1357
+ parseAttachment(options) {
1358
+ const error = requireFieldsAsync([
1359
+ { value: options.instanceId, name: "instanceId" },
1360
+ { value: options.activityInstanceId, name: "activityInstanceId" },
1361
+ { value: options.fieldId, name: "fieldId" },
1362
+ { value: options.file, name: "file" }
1363
+ ]);
1364
+ if (error)
1365
+ return error;
1366
+ return this._postMessageAsync(LISTENER_CMDS.PROCESS_PARSE_ATTACHMENT, {
1367
+ flowId: this._id,
1368
+ instanceId: options.instanceId,
1369
+ activityInstanceId: options.activityInstanceId,
1370
+ fieldId: options.fieldId,
1371
+ file: options.file
1372
+ });
1373
+ }
1374
+ }
1375
+ const READ_TIMEOUT_MS$1 = 75e3;
1376
+ const EXECUTE_TIMEOUT_MS = 6e4;
1377
+ const WATCH_ACK_TIMEOUT_MS$1 = 6e4;
1378
+ const WATCH_DEADLINE_MS$1 = 42e4;
1379
+ const TERMINAL_STATUSES$1 = ["Completed", "Failed"];
1380
+ function sdkError$1(errorCode, error) {
1381
+ return { isError: true, error, errorCode };
1382
+ }
1383
+ function notify$1(callback, value) {
1384
+ try {
1385
+ callback == null ? void 0 : callback(value);
1386
+ } catch (error) {
1387
+ console.error(error);
1388
+ }
1389
+ }
1390
+ const NOT_SENT$1 = sdkError$1("AGENT_REQUEST_NOT_SENT", "The request could not be sent to the host.");
1391
+ class Agent extends BaseSDK {
1392
+ constructor(agentId) {
1393
+ super();
1394
+ this.activeWatches = 0;
1395
+ this.agentId = agentId;
1396
+ this._id = generateId("customagent");
1397
+ }
1398
+ getContract() {
1399
+ return this._postMessageBounded(
1400
+ LISTENER_CMDS.CUSTOM_AGENT_GET_CONTRACT,
1401
+ { agentId: this.agentId },
1402
+ {
1403
+ timeoutMs: READ_TIMEOUT_MS$1,
1404
+ timeoutError: sdkError$1("AGENT_HOST_TIMEOUT", "The host did not answer the Agent contract request."),
1405
+ sendError: NOT_SENT$1
1406
+ }
1407
+ ).promise;
1408
+ }
1409
+ execute(options) {
1410
+ var _a;
1411
+ return this._postMessageBounded(
1412
+ LISTENER_CMDS.CUSTOM_AGENT_EXECUTE,
1413
+ { agentId: this.agentId, inputData: (_a = options == null ? void 0 : options.inputData) != null ? _a : {} },
1414
+ {
1415
+ timeoutMs: EXECUTE_TIMEOUT_MS,
1416
+ timeoutError: sdkError$1(
1417
+ "AGENT_EXECUTE_OUTCOME_UNKNOWN",
1418
+ "The host did not confirm the run; it may still have started."
1419
+ ),
1420
+ sendError: sdkError$1("AGENT_EXECUTE_NOT_SENT", "The run request could not be sent to the host.")
1421
+ }
1422
+ ).promise;
1423
+ }
1424
+ getExecution(executionId) {
1425
+ return this._postMessageBounded(
1426
+ LISTENER_CMDS.CUSTOM_AGENT_GET_EXECUTION,
1427
+ { agentId: this.agentId, executionId },
1428
+ {
1429
+ timeoutMs: READ_TIMEOUT_MS$1,
1430
+ timeoutError: sdkError$1("AGENT_HOST_TIMEOUT", "The host did not answer the Agent execution request."),
1431
+ sendError: NOT_SENT$1
1432
+ }
1433
+ ).promise;
1434
+ }
1435
+ onExecutionComplete(executionId, onComplete, onWatchError) {
1436
+ const watchId = generateId("agentwatch");
1437
+ const eventName = `${EVENT_TYPES.CUSTOM_AGENT_EXECUTION_COMPLETE}:${watchId}`;
1438
+ let settled = false;
1439
+ let deadline = null;
1440
+ let registration = null;
1441
+ const end = () => {
1442
+ settled = true;
1443
+ if (deadline)
1444
+ clearTimeout(deadline);
1445
+ registration == null ? void 0 : registration.cancel();
1446
+ this._removeEventListener(eventName);
1447
+ this.activeWatches -= 1;
1448
+ if (this.activeWatches === 0)
1449
+ Reflect.deleteProperty(globalInstances, this._id);
1450
+ };
1451
+ const tellHostToStop = () => {
1452
+ try {
1453
+ this._postMessage(LISTENER_CMDS.CUSTOM_AGENT_STOP_WATCH, { id: this._id, watchId, eventName });
1454
+ } catch {
1455
+ }
1456
+ };
1457
+ const fail = (error) => {
1458
+ if (settled)
1459
+ return;
1460
+ end();
1461
+ tellHostToStop();
1462
+ notify$1(onWatchError, error);
1463
+ };
1464
+ const listener = (params) => {
1465
+ if (settled)
1466
+ return;
1467
+ if (params == null ? void 0 : params.isError) {
1468
+ end();
1469
+ notify$1(onWatchError, params);
1470
+ return;
1471
+ }
1472
+ const execution = params;
1473
+ if ((execution == null ? void 0 : execution.ExecutionId) !== executionId || TERMINAL_STATUSES$1.indexOf(execution == null ? void 0 : execution.Status) === -1) {
1474
+ fail(sdkError$1("AGENT_WATCH_INVALID_EVENT", "The host reported something other than a finished run."));
1475
+ return;
1476
+ }
1477
+ end();
1478
+ notify$1(onComplete, execution);
1479
+ };
1480
+ this.activeWatches += 1;
1481
+ globalInstances[this._id] = this;
1482
+ this._addEventListener(eventName, listener);
1483
+ registration = this._postMessageBounded(
1484
+ LISTENER_CMDS.CUSTOM_AGENT_WATCH_EXECUTION,
1485
+ { id: this._id, agentId: this.agentId, executionId, watchId, eventName },
1486
+ {
1487
+ timeoutMs: WATCH_ACK_TIMEOUT_MS$1,
1488
+ timeoutError: sdkError$1("AGENT_HOST_UNSUPPORTED", "The host did not start observing the Agent run."),
1489
+ sendError: NOT_SENT$1
1490
+ }
1491
+ );
1492
+ registration.promise.then(
1493
+ (acknowledged) => {
1494
+ if (settled)
1495
+ return;
1496
+ if (acknowledged !== true) {
1497
+ fail(sdkError$1("AGENT_HOST_UNSUPPORTED", "The host did not start observing the Agent run."));
1498
+ return;
1499
+ }
1500
+ deadline = setTimeout(
1501
+ () => fail(sdkError$1("AGENT_OBSERVATION_STOPPED", "Stopped checking the Agent run; read it again later.")),
1502
+ WATCH_DEADLINE_MS$1
1503
+ );
1504
+ },
1505
+ (error) => fail(error)
1506
+ );
1507
+ return () => {
1508
+ if (settled)
1509
+ return;
1510
+ end();
1511
+ tellHostToStop();
1512
+ };
1513
+ }
1514
+ }
1515
+ const REPORT_FLOW_TYPES = ["Form", "Process", "Case"];
1516
+ class Report extends BaseSDK {
1517
+ constructor(flowType, flowId, reportId) {
1518
+ super();
1519
+ this._flowType = flowType;
1520
+ this._flowId = flowId;
1521
+ this._id = reportId;
1522
+ }
1523
+ getData(options) {
1524
+ return this._send(LISTENER_CMDS.REPORT_GET_DATA, {
1525
+ pageNumber: (options == null ? void 0 : options.pageNumber) || 1,
1526
+ pageSize: (options == null ? void 0 : options.pageSize) || 50,
1527
+ payload: (options == null ? void 0 : options.payload) || {}
1528
+ });
1529
+ }
1530
+ getCount(options) {
1531
+ return this._send(LISTENER_CMDS.REPORT_GET_COUNT, { payload: (options == null ? void 0 : options.payload) || {} });
1532
+ }
1533
+ getFields() {
1534
+ return this._send(LISTENER_CMDS.REPORT_GET_FIELDS, {});
1535
+ }
1536
+ _send(command, args) {
1537
+ const missing = requireFieldsAsync([
1538
+ { value: this._flowId, name: "flowId" },
1539
+ { value: this._id, name: "reportId" }
1540
+ ]);
1541
+ if (missing)
1542
+ return missing;
1543
+ if (REPORT_FLOW_TYPES.indexOf(this._flowType) === -1) {
1544
+ return Promise.reject({
1545
+ message: `flowType must be one of ${REPORT_FLOW_TYPES.join(", ")}`
1546
+ });
1547
+ }
1548
+ return this._postMessageAsync(command, {
1549
+ flowType: this._flowType,
1550
+ flowId: this._flowId,
1551
+ reportId: this._id,
1552
+ ...args
1553
+ });
1554
+ }
1555
+ }
1556
+ const READ_TIMEOUT_MS = 3e4;
1557
+ const RUN_TIMEOUT_MS = 45e3;
1558
+ const WATCH_ACK_TIMEOUT_MS = 6e4;
1559
+ const WATCH_DEADLINE_MS = 69e4;
1560
+ function sdkError(errorCode, error) {
1561
+ return { isError: true, error, errorCode };
1562
+ }
1563
+ function notify(callback, value) {
1564
+ try {
1565
+ callback == null ? void 0 : callback(value);
1566
+ } catch (error) {
1567
+ console.error(error);
1568
+ }
1569
+ }
1570
+ const NOT_SENT = sdkError("FUNCTION_REQUEST_NOT_SENT", "The request could not be sent to the host.");
1571
+ const TERMINAL_STATUSES = ["Success", "Failed", "TimedOut"];
1572
+ class Application extends BaseSDK {
1573
+ constructor(props, isCustomComponent = false) {
1574
+ super();
1575
+ this.activeWatches = 0;
1576
+ this._id = props.appId;
1577
+ this.page = new Page(props);
1578
+ }
1579
+ getVariable(key) {
1580
+ return this._postMessageAsync(LISTENER_CMDS.GET_APP_VARIABLE, {
1581
+ key
1582
+ });
1583
+ }
1584
+ setVariable(key, value) {
1585
+ return this._postMessageAsync(LISTENER_CMDS.SET_APP_VARIABLE, {
1586
+ key,
1587
+ value
1588
+ });
1589
+ }
1590
+ openPage(pageId, pageParams) {
1591
+ return this._postMessageAsync(LISTENER_CMDS.OPEN_PAGE, {
1592
+ pageId,
1593
+ pageParams
1594
+ });
1595
+ }
1596
+ runFunction(name, parameters) {
1597
+ return this._postMessageBounded(
1598
+ LISTENER_CMDS.CUSTOM_FUNCTION_RUN,
1599
+ { name, parameters: parameters != null ? parameters : {} },
1600
+ {
1601
+ timeoutMs: RUN_TIMEOUT_MS,
1602
+ timeoutError: sdkError(
1603
+ "FUNCTION_RUN_OUTCOME_UNKNOWN",
1604
+ "The host did not answer the run; it may still have started."
1605
+ ),
1606
+ sendError: sdkError("FUNCTION_RUN_NOT_SENT", "The run request could not be sent to the host.")
1607
+ }
1608
+ ).promise;
1609
+ }
1610
+ getFunctionRun(runId) {
1611
+ return this._postMessageBounded(
1612
+ LISTENER_CMDS.CUSTOM_FUNCTION_GET_RUN,
1613
+ { runId },
1614
+ {
1615
+ timeoutMs: READ_TIMEOUT_MS,
1616
+ timeoutError: sdkError("FUNCTION_HOST_TIMEOUT", "The host did not answer the run request."),
1617
+ sendError: NOT_SENT
1618
+ }
1619
+ ).promise;
1620
+ }
1621
+ onFunctionRunComplete(runId, callBack, onError) {
1622
+ const watchId = generateId("functionwatch");
1623
+ const eventName = `${EVENT_TYPES.CUSTOM_FUNCTION_RUN_COMPLETE}:${watchId}`;
1624
+ let settled = false;
1625
+ let deadline = null;
1626
+ let registration = null;
1627
+ const end = () => {
1628
+ settled = true;
1629
+ if (deadline)
1630
+ clearTimeout(deadline);
1631
+ registration == null ? void 0 : registration.cancel();
1632
+ this._removeEventListener(eventName);
1633
+ this.activeWatches -= 1;
1634
+ if (this.activeWatches === 0)
1635
+ Reflect.deleteProperty(globalInstances, this._id);
1636
+ };
1637
+ const tellHostToStop = () => {
1638
+ try {
1639
+ this._postMessage(LISTENER_CMDS.CUSTOM_FUNCTION_STOP_WATCH, { id: this._id, runId, watchId, eventName });
1640
+ } catch {
1641
+ }
1642
+ };
1643
+ const fail = (error) => {
1644
+ if (settled)
1645
+ return;
1646
+ end();
1647
+ tellHostToStop();
1648
+ notify(onError, error);
1649
+ };
1650
+ const listener = (params) => {
1651
+ if (settled)
1652
+ return;
1653
+ if (params == null ? void 0 : params.isError) {
1654
+ end();
1655
+ notify(onError, params);
1656
+ return;
1657
+ }
1658
+ const run = params;
1659
+ if ((run == null ? void 0 : run.RunId) !== runId || TERMINAL_STATUSES.indexOf(run == null ? void 0 : run.Status) === -1) {
1660
+ fail(sdkError("FUNCTION_WATCH_INVALID_EVENT", "The host reported something other than a finished run."));
1661
+ return;
1662
+ }
1663
+ end();
1664
+ notify(callBack, run);
1665
+ };
1666
+ this.activeWatches += 1;
1667
+ globalInstances[this._id] = this;
1668
+ this._addEventListener(eventName, listener);
1669
+ registration = this._postMessageBounded(
1670
+ LISTENER_CMDS.CUSTOM_FUNCTION_ON_RUN_COMPLETE,
1671
+ { id: this._id, runId, watchId, eventName },
1672
+ {
1673
+ timeoutMs: WATCH_ACK_TIMEOUT_MS,
1674
+ timeoutError: sdkError("FUNCTION_HOST_UNSUPPORTED", "The host did not start watching the run."),
1675
+ sendError: NOT_SENT
1676
+ }
1677
+ );
1678
+ registration.promise.then(
1679
+ (acknowledged) => {
1680
+ if (settled)
1681
+ return;
1682
+ if (acknowledged !== true) {
1683
+ fail(sdkError("FUNCTION_HOST_UNSUPPORTED", "The host did not start watching the run."));
1684
+ return;
1685
+ }
1686
+ deadline = setTimeout(
1687
+ () => fail(sdkError("FUNCTION_OBSERVATION_STOPPED", "Stopped checking the run; read it again later.")),
1688
+ WATCH_DEADLINE_MS
1689
+ );
1690
+ },
1691
+ (error) => fail(error)
1692
+ );
1693
+ return () => {
1694
+ if (settled)
1695
+ return;
1696
+ end();
1697
+ tellHostToStop();
1698
+ };
1699
+ }
1700
+ getDecisionTable(flowId) {
1701
+ return new DecisionTable(flowId);
1702
+ }
1703
+ getAgent(agentId) {
1704
+ return new Agent(agentId);
1705
+ }
1706
+ getReport(flowType, flowId, reportId) {
1707
+ return new Report(flowType, flowId, reportId);
1708
+ }
1709
+ getDataform(flowId) {
1710
+ return new Dataform(flowId);
1711
+ }
1712
+ getBoard(flowId) {
1713
+ return new Board(flowId);
1714
+ }
1715
+ getProcess(flowId) {
1716
+ return new Process(flowId);
1717
+ }
1718
+ getRoles() {
1719
+ return this._postMessageAsync(LISTENER_CMDS.GET_ROLES, {});
1720
+ }
1721
+ switchRole(args) {
1722
+ return this._postMessageAsync(LISTENER_CMDS.SWITCH_ROLE, {
1723
+ roleId: args.roleId,
1724
+ roleName: args.roleName
1725
+ });
1726
+ }
1727
+ }
1728
+ class NDEFReader extends BaseSDK {
1729
+ constructor() {
1730
+ super();
1731
+ this.id = generateId(LISTENER_CMDS.WINDOW_NDEF_READER_NEW);
1732
+ globalInstances[this.id] = this;
1733
+ this._postMessage(
1734
+ LISTENER_CMDS.WINDOW_NDEF_READER_NEW,
1735
+ {
1736
+ id: this.id,
1737
+ operation: "new"
1738
+ },
1739
+ (data) => {
1740
+ }
1741
+ );
1742
+ }
1743
+ scan() {
1744
+ return new Promise((resolve, reject) => {
1745
+ this._postMessage(
1746
+ LISTENER_CMDS.WINDOW_NDEF_READER_SCAN,
1747
+ { id: this.id, operation: "scan" },
1748
+ ({ data, err }) => {
1749
+ console.log("scan data from main window ", data);
1750
+ resolve(data);
1751
+ }
1752
+ );
1753
+ });
1754
+ }
1755
+ write(data) {
1756
+ return new Promise((resolve, reject) => {
1757
+ this._postMessage(
1758
+ LISTENER_CMDS.WINDOW_NDEF_READER_WRITE,
1759
+ { id: this.id, operation: "write", data },
1760
+ ({ data: data2, err }) => {
1761
+ }
1762
+ );
1763
+ });
1764
+ }
1765
+ addEventListener(eventName, cb) {
1766
+ this._postMessage(
1767
+ LISTENER_CMDS.WINDOW_NDEF_READER_ADD_EVENT_LISTENER,
1768
+ {
1769
+ id: this.id,
1770
+ operation: "addEventListener",
1771
+ eventName
1772
+ },
1773
+ () => {
1774
+ }
1775
+ );
1776
+ }
1777
+ makeReadOnly() {
1778
+ return new Promise((resolve, reject) => {
1779
+ this._postMessage(
1780
+ LISTENER_CMDS.WINDOW_NDEF_READER_MAKE_READONLY,
1781
+ { id: this.id, operation: "makeReadOnly" },
1782
+ ({ data, err }) => {
1783
+ }
1784
+ );
1785
+ });
1786
+ }
1787
+ abortScan() {
1788
+ return new Promise((resolve, reject) => {
1789
+ this._postMessage(
1790
+ LISTENER_CMDS.WINDOW_NDEF_READER_ABORT_SCAN,
1791
+ { id: this.id, operation: "abortScan" },
1792
+ ({ data, err }) => {
1793
+ }
1794
+ );
1795
+ });
1796
+ }
1797
+ }
1798
+ const window = {
1799
+ NDEFReader
1800
+ };
1801
+ class LowcodeSDK extends BaseSDK {
1802
+ constructor(props) {
1803
+ super();
1804
+ __privateAdd(this, _csrfToken, void 0);
1805
+ if (props.tableId && props.tableRowId) {
1806
+ this.context = new TableForm(
1807
+ props.formInstanceId,
1808
+ props.flowId,
1809
+ props.formInstanceId,
1810
+ props.tableId,
1811
+ props.tableRowId
1812
+ );
1813
+ } else if (props.formInstanceId) {
1814
+ this.context = new Form(
1815
+ props.formInstanceId,
1816
+ props.flowId,
1817
+ props.formInstanceId
1818
+ );
1819
+ } else if (props.popupId) {
1820
+ this.context = new Popup(props);
1821
+ } else if (props.pageId && !props.componentId) {
1822
+ this.context = new Page(props);
1823
+ } else if (props.componentId) {
1824
+ this.context = new Component(props);
1825
+ }
1826
+ this.client = new Client();
1827
+ this.formatter = new Formatter();
1828
+ if (props.appId) {
1829
+ this.app = new Application(props);
1830
+ }
1831
+ this.user = props.user;
1832
+ this.env = props.envDetails;
1833
+ this.account = props.account;
1834
+ __privateSet(this, _csrfToken, props.csrfToken);
1835
+ }
1836
+ async api(url, args) {
1837
+ const response = await globalThis.fetch(url, {
1838
+ ...args,
1839
+ headers: {
1840
+ ...(args == null ? void 0 : args.headers) || {},
1841
+ "X-Csrf-Token": __privateGet(this, _csrfToken)
1842
+ }
1843
+ });
1844
+ const contentType = response.headers.get("content-type");
1845
+ if (contentType && contentType.includes("application/json")) {
1846
+ return await response.json();
1847
+ } else {
1848
+ return response;
1849
+ }
1850
+ }
1851
+ }
1852
+ _csrfToken = new WeakMap();
1853
+ function initSDK(config) {
1854
+ return new LowcodeSDK(config);
1855
+ }
1856
+ export { initSDK as default, window };