@kissflow/lowcode-client-sdk 1.0.50 → 1.0.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +91 -1
- package/dist/kfsdk.es.js +159 -28
- package/dist/kfsdk.umd.js +1 -1
- package/dist/lowcode.d.ts +91 -1
- package/dist/lowcode.types.d.ts +80 -0
- package/dist/nocode.d.ts +91 -1
- package/dist/nocode.types.d.ts +27 -0
- package/dist/snippets.json +16 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -65,6 +65,10 @@ declare module "core/constants" {
|
|
|
65
65
|
CUSTOM_AGENT_GET_EXECUTION: string;
|
|
66
66
|
CUSTOM_AGENT_WATCH_EXECUTION: string;
|
|
67
67
|
CUSTOM_AGENT_STOP_WATCH: string;
|
|
68
|
+
CUSTOM_FUNCTION_RUN: string;
|
|
69
|
+
CUSTOM_FUNCTION_GET_RUN: string;
|
|
70
|
+
CUSTOM_FUNCTION_ON_RUN_COMPLETE: string;
|
|
71
|
+
CUSTOM_FUNCTION_STOP_WATCH: string;
|
|
68
72
|
DECISION_TABLE_EXECUTE: string;
|
|
69
73
|
DATAFORM_IMPORT_CSV: string;
|
|
70
74
|
DATAFORM_OPEN_FORM: string;
|
|
@@ -123,6 +127,7 @@ declare module "core/constants" {
|
|
|
123
127
|
CC_ON_PARAMS_CHANGE: string;
|
|
124
128
|
CC_ON_ROUTE_CHANGE: string;
|
|
125
129
|
CUSTOM_AGENT_EXECUTION_COMPLETE: string;
|
|
130
|
+
CUSTOM_FUNCTION_RUN_COMPLETE: string;
|
|
126
131
|
};
|
|
127
132
|
export const DEFAULTS: {
|
|
128
133
|
POPUP_ID: string;
|
|
@@ -411,6 +416,37 @@ declare module "types/external" {
|
|
|
411
416
|
tableId?: string;
|
|
412
417
|
tableRowId?: string;
|
|
413
418
|
};
|
|
419
|
+
/** The terminal states a Custom Function run ends in, plus the two it passes through. */
|
|
420
|
+
export type RunStatus = "Queued" | "Running" | "Success" | "Failed" | "TimedOut";
|
|
421
|
+
/**
|
|
422
|
+
* What a Custom Function run looks like from the SDK.
|
|
423
|
+
*
|
|
424
|
+
* An Interactive function resolves with the terminal envelope directly. A
|
|
425
|
+
* Background function resolves with `Queued` and only `RunId`; fetch the rest
|
|
426
|
+
* with `getFunctionRun`, or wait for it with `onFunctionRunComplete`.
|
|
427
|
+
*/
|
|
428
|
+
export type RunEnvelope = {
|
|
429
|
+
RunId: string;
|
|
430
|
+
Status: RunStatus;
|
|
431
|
+
/** Whatever the function returned. Only constrained when its output contract names properties. */
|
|
432
|
+
Result?: unknown;
|
|
433
|
+
Error?: {
|
|
434
|
+
Code?: string;
|
|
435
|
+
Message: string;
|
|
436
|
+
};
|
|
437
|
+
};
|
|
438
|
+
/**
|
|
439
|
+
* How a Custom Function call fails: `error` is the message text and `errorCode` either the platform
|
|
440
|
+
* code (`KISSFLOW_ERROR_…`) or a `FUNCTION_…` code, including `FUNCTION_HOST_TIMEOUT`,
|
|
441
|
+
* `FUNCTION_REQUEST_NOT_SENT`, `FUNCTION_RUN_OUTCOME_UNKNOWN` (a run may have started),
|
|
442
|
+
* `FUNCTION_RUN_NOT_SENT` (no run started), `FUNCTION_HOST_UNSUPPORTED`, `FUNCTION_WATCH_INVALID_EVENT`
|
|
443
|
+
* and `FUNCTION_OBSERVATION_STOPPED`. The list may grow; fall back to `error` for an unknown code.
|
|
444
|
+
*/
|
|
445
|
+
export type RunWatchError = {
|
|
446
|
+
isError: true;
|
|
447
|
+
error?: string;
|
|
448
|
+
errorCode?: string;
|
|
449
|
+
};
|
|
414
450
|
export type AgentInputDataType = "Text" | "Number" | "Boolean" | "Attachment";
|
|
415
451
|
export type AgentOutputDataType = "string" | "number" | "boolean";
|
|
416
452
|
export type AgentInputField = {
|
|
@@ -1454,7 +1490,7 @@ declare module "app/index" {
|
|
|
1454
1490
|
import { BaseSDK } from "core/index";
|
|
1455
1491
|
import { Page } from "app/page";
|
|
1456
1492
|
import { AppContext } from "types/internal";
|
|
1457
|
-
import { rolesObject } from "types/external";
|
|
1493
|
+
import { rolesObject, RunEnvelope, RunWatchError } from "types/external";
|
|
1458
1494
|
import { DecisionTable } from "app/decisiontable";
|
|
1459
1495
|
import { Agent } from "app/agent";
|
|
1460
1496
|
import { Dataform } from "dataform/index";
|
|
@@ -1463,10 +1499,64 @@ declare module "app/index" {
|
|
|
1463
1499
|
export class Application extends BaseSDK {
|
|
1464
1500
|
page: Page;
|
|
1465
1501
|
_id: string;
|
|
1502
|
+
private activeWatches;
|
|
1466
1503
|
constructor(props: AppContext, isCustomComponent?: boolean);
|
|
1467
1504
|
getVariable(key: string): any;
|
|
1468
1505
|
setVariable(key: string | object, value?: any): any;
|
|
1469
1506
|
openPage(pageId: string, pageParams?: object): any;
|
|
1507
|
+
/**
|
|
1508
|
+
* Run a published Custom Function by name.
|
|
1509
|
+
*
|
|
1510
|
+
* An Interactive function resolves with its terminal envelope. A Background
|
|
1511
|
+
* function resolves as soon as it is queued, with `Status: "Queued"` and a
|
|
1512
|
+
* `RunId`; use {@link getFunctionRun} or {@link onFunctionRunComplete} for its result.
|
|
1513
|
+
*
|
|
1514
|
+
* A refused run rejects with the platform's SDK error shape: the message
|
|
1515
|
+
* text is in `error` and the code (`KISSFLOW_ERROR_…`) in `errorCode`.
|
|
1516
|
+
* A host that does not answer within 45 s rejects with
|
|
1517
|
+
* `FUNCTION_RUN_OUTCOME_UNKNOWN`: the run may still have started, so tell
|
|
1518
|
+
* the user instead of starting another.
|
|
1519
|
+
*
|
|
1520
|
+
* Custom Functions are application-scoped: this is reachable from page,
|
|
1521
|
+
* component and flow event scripts that run inside an application, where
|
|
1522
|
+
* `kf.app` exists. There is no `kf.app` outside one.
|
|
1523
|
+
*
|
|
1524
|
+
* @example
|
|
1525
|
+
* const run = await kf.app.runFunction("review_expense_claim", { claimId });
|
|
1526
|
+
*/
|
|
1527
|
+
runFunction(name: string, parameters?: Record<string, unknown>): Promise<RunEnvelope>;
|
|
1528
|
+
/**
|
|
1529
|
+
* Fetch a run's current state, including its `Result` once it has one.
|
|
1530
|
+
*
|
|
1531
|
+
* @example
|
|
1532
|
+
* const run = await kf.app.getFunctionRun(runId);
|
|
1533
|
+
* if (run.Status === "Success") use(run.Result);
|
|
1534
|
+
*/
|
|
1535
|
+
getFunctionRun(runId: string): Promise<RunEnvelope>;
|
|
1536
|
+
/**
|
|
1537
|
+
* Be told when a Background run reaches a terminal state.
|
|
1538
|
+
*
|
|
1539
|
+
* Fires `callBack` once with the run's envelope. "Complete" means the run
|
|
1540
|
+
* stopped, not that it worked: it fires on `Failed` and `TimedOut` just as
|
|
1541
|
+
* it does on `Success`, so read `Status` before trusting `Result`. If the
|
|
1542
|
+
* host cannot watch the run at all, `onError` is called instead of
|
|
1543
|
+
* `callBack` ever firing: an older host (`FUNCTION_HOST_UNSUPPORTED`), a
|
|
1544
|
+
* refusal, or the watch limit (`FUNCTION_OBSERVATION_STOPPED`, after about
|
|
1545
|
+
* ten minutes; the run may still finish, so read it later with
|
|
1546
|
+
* {@link getFunctionRun}). At most one of the two is called, at most once.
|
|
1547
|
+
*
|
|
1548
|
+
* Returns a function that unsubscribes. The callback lives only as long as
|
|
1549
|
+
* the script that registered it: form events end their script after 60 s
|
|
1550
|
+
* and a page event ends the previous one when it fires again, while a
|
|
1551
|
+
* Background run may take up to 600 s. Prefer polling {@link getFunctionRun} from a
|
|
1552
|
+
* script that outlives the run, or re-attach after the script restarts.
|
|
1553
|
+
*
|
|
1554
|
+
* @example
|
|
1555
|
+
* const stop = kf.app.onFunctionRunComplete(run.RunId, (done) => show(done), (err) => warn(err));
|
|
1556
|
+
* // later, e.g. on unmount — the host stops watching the run too
|
|
1557
|
+
* stop();
|
|
1558
|
+
*/
|
|
1559
|
+
onFunctionRunComplete(runId: string, callBack: (run: RunEnvelope) => void, onError?: (error: RunWatchError) => void): () => void;
|
|
1470
1560
|
getDecisionTable(flowId: string): DecisionTable;
|
|
1471
1561
|
/**
|
|
1472
1562
|
* Get a published Custom Agent of this app by its id. The handle sends no request until you call one
|
package/dist/kfsdk.es.js
CHANGED
|
@@ -100,6 +100,10 @@ const LISTENER_CMDS = {
|
|
|
100
100
|
CUSTOM_AGENT_GET_EXECUTION: "CUSTOM_AGENT_GET_EXECUTION",
|
|
101
101
|
CUSTOM_AGENT_WATCH_EXECUTION: "CUSTOM_AGENT_WATCH_EXECUTION",
|
|
102
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",
|
|
103
107
|
DECISION_TABLE_EXECUTE: "DECISION_TABLE_EXECUTE",
|
|
104
108
|
DATAFORM_IMPORT_CSV: "DATAFORM_IMPORT_CSV",
|
|
105
109
|
DATAFORM_OPEN_FORM: "DATAFORM_OPEN_FORM",
|
|
@@ -157,7 +161,8 @@ const EVENT_TYPES = {
|
|
|
157
161
|
COMPONENT_ON_MOUNT: "componentOnMount",
|
|
158
162
|
CC_ON_PARAMS_CHANGE: "onCustomComponentParamsChange",
|
|
159
163
|
CC_ON_ROUTE_CHANGE: "onCustomComponentRouteChange",
|
|
160
|
-
CUSTOM_AGENT_EXECUTION_COMPLETE: "onCustomAgentExecutionComplete"
|
|
164
|
+
CUSTOM_AGENT_EXECUTION_COMPLETE: "onCustomAgentExecutionComplete",
|
|
165
|
+
CUSTOM_FUNCTION_RUN_COMPLETE: "onCustomFunctionRunComplete"
|
|
161
166
|
};
|
|
162
167
|
const DEFAULTS = {
|
|
163
168
|
POPUP_ID: "ACTIVE_POP_UP"
|
|
@@ -167,8 +172,13 @@ function generateId(prefix = "lcncsdk") {
|
|
|
167
172
|
}
|
|
168
173
|
const globalInstances = {};
|
|
169
174
|
const pendingRequestIds = /* @__PURE__ */ new Set();
|
|
175
|
+
const ENVELOPE_COMMANDS = /* @__PURE__ */ new Set([
|
|
176
|
+
LISTENER_CMDS.API,
|
|
177
|
+
LISTENER_CMDS.CUSTOM_FUNCTION_RUN,
|
|
178
|
+
LISTENER_CMDS.CUSTOM_FUNCTION_GET_RUN
|
|
179
|
+
]);
|
|
170
180
|
function processResponse(req, resp) {
|
|
171
|
-
if (resp && Object.keys(resp).length === 1 && req.command
|
|
181
|
+
if (resp && Object.keys(resp).length === 1 && !ENVELOPE_COMMANDS.has(req.command)) {
|
|
172
182
|
let value = Object.values(resp)[0];
|
|
173
183
|
if (value === "undefined")
|
|
174
184
|
return void 0;
|
|
@@ -665,22 +675,22 @@ class DecisionTable extends BaseSDK {
|
|
|
665
675
|
});
|
|
666
676
|
}
|
|
667
677
|
}
|
|
668
|
-
const READ_TIMEOUT_MS = 75e3;
|
|
678
|
+
const READ_TIMEOUT_MS$1 = 75e3;
|
|
669
679
|
const EXECUTE_TIMEOUT_MS = 6e4;
|
|
670
|
-
const WATCH_ACK_TIMEOUT_MS = 6e4;
|
|
671
|
-
const WATCH_DEADLINE_MS = 42e4;
|
|
672
|
-
const TERMINAL_STATUSES = ["Completed", "Failed"];
|
|
673
|
-
function sdkError(errorCode, error) {
|
|
680
|
+
const WATCH_ACK_TIMEOUT_MS$1 = 6e4;
|
|
681
|
+
const WATCH_DEADLINE_MS$1 = 42e4;
|
|
682
|
+
const TERMINAL_STATUSES$1 = ["Completed", "Failed"];
|
|
683
|
+
function sdkError$1(errorCode, error) {
|
|
674
684
|
return { isError: true, error, errorCode };
|
|
675
685
|
}
|
|
676
|
-
function notify(callback, value) {
|
|
686
|
+
function notify$1(callback, value) {
|
|
677
687
|
try {
|
|
678
688
|
callback == null ? void 0 : callback(value);
|
|
679
689
|
} catch (error) {
|
|
680
690
|
console.error(error);
|
|
681
691
|
}
|
|
682
692
|
}
|
|
683
|
-
const NOT_SENT = sdkError("AGENT_REQUEST_NOT_SENT", "The request could not be sent to the host.");
|
|
693
|
+
const NOT_SENT$1 = sdkError$1("AGENT_REQUEST_NOT_SENT", "The request could not be sent to the host.");
|
|
684
694
|
class Agent extends BaseSDK {
|
|
685
695
|
constructor(agentId) {
|
|
686
696
|
super();
|
|
@@ -693,9 +703,9 @@ class Agent extends BaseSDK {
|
|
|
693
703
|
LISTENER_CMDS.CUSTOM_AGENT_GET_CONTRACT,
|
|
694
704
|
{ agentId: this.agentId },
|
|
695
705
|
{
|
|
696
|
-
timeoutMs: READ_TIMEOUT_MS,
|
|
697
|
-
timeoutError: sdkError("AGENT_HOST_TIMEOUT", "The host did not answer the Agent contract request."),
|
|
698
|
-
sendError: NOT_SENT
|
|
706
|
+
timeoutMs: READ_TIMEOUT_MS$1,
|
|
707
|
+
timeoutError: sdkError$1("AGENT_HOST_TIMEOUT", "The host did not answer the Agent contract request."),
|
|
708
|
+
sendError: NOT_SENT$1
|
|
699
709
|
}
|
|
700
710
|
).promise;
|
|
701
711
|
}
|
|
@@ -706,11 +716,11 @@ class Agent extends BaseSDK {
|
|
|
706
716
|
{ agentId: this.agentId, inputData: (_a = options == null ? void 0 : options.inputData) != null ? _a : {} },
|
|
707
717
|
{
|
|
708
718
|
timeoutMs: EXECUTE_TIMEOUT_MS,
|
|
709
|
-
timeoutError: sdkError(
|
|
719
|
+
timeoutError: sdkError$1(
|
|
710
720
|
"AGENT_EXECUTE_OUTCOME_UNKNOWN",
|
|
711
721
|
"The host did not confirm the run; it may still have started."
|
|
712
722
|
),
|
|
713
|
-
sendError: sdkError("AGENT_EXECUTE_NOT_SENT", "The run request could not be sent to the host.")
|
|
723
|
+
sendError: sdkError$1("AGENT_EXECUTE_NOT_SENT", "The run request could not be sent to the host.")
|
|
714
724
|
}
|
|
715
725
|
).promise;
|
|
716
726
|
}
|
|
@@ -719,9 +729,9 @@ class Agent extends BaseSDK {
|
|
|
719
729
|
LISTENER_CMDS.CUSTOM_AGENT_GET_EXECUTION,
|
|
720
730
|
{ agentId: this.agentId, executionId },
|
|
721
731
|
{
|
|
722
|
-
timeoutMs: READ_TIMEOUT_MS,
|
|
723
|
-
timeoutError: sdkError("AGENT_HOST_TIMEOUT", "The host did not answer the Agent execution request."),
|
|
724
|
-
sendError: NOT_SENT
|
|
732
|
+
timeoutMs: READ_TIMEOUT_MS$1,
|
|
733
|
+
timeoutError: sdkError$1("AGENT_HOST_TIMEOUT", "The host did not answer the Agent execution request."),
|
|
734
|
+
sendError: NOT_SENT$1
|
|
725
735
|
}
|
|
726
736
|
).promise;
|
|
727
737
|
}
|
|
@@ -752,23 +762,23 @@ class Agent extends BaseSDK {
|
|
|
752
762
|
return;
|
|
753
763
|
end();
|
|
754
764
|
tellHostToStop();
|
|
755
|
-
notify(onWatchError, error);
|
|
765
|
+
notify$1(onWatchError, error);
|
|
756
766
|
};
|
|
757
767
|
const listener = (params) => {
|
|
758
768
|
if (settled)
|
|
759
769
|
return;
|
|
760
770
|
if (params == null ? void 0 : params.isError) {
|
|
761
771
|
end();
|
|
762
|
-
notify(onWatchError, params);
|
|
772
|
+
notify$1(onWatchError, params);
|
|
763
773
|
return;
|
|
764
774
|
}
|
|
765
775
|
const execution = params;
|
|
766
|
-
if ((execution == null ? void 0 : execution.ExecutionId) !== executionId || TERMINAL_STATUSES.indexOf(execution == null ? void 0 : execution.Status) === -1) {
|
|
767
|
-
fail(sdkError("AGENT_WATCH_INVALID_EVENT", "The host reported something other than a finished run."));
|
|
776
|
+
if ((execution == null ? void 0 : execution.ExecutionId) !== executionId || TERMINAL_STATUSES$1.indexOf(execution == null ? void 0 : execution.Status) === -1) {
|
|
777
|
+
fail(sdkError$1("AGENT_WATCH_INVALID_EVENT", "The host reported something other than a finished run."));
|
|
768
778
|
return;
|
|
769
779
|
}
|
|
770
780
|
end();
|
|
771
|
-
notify(onComplete, execution);
|
|
781
|
+
notify$1(onComplete, execution);
|
|
772
782
|
};
|
|
773
783
|
this.activeWatches += 1;
|
|
774
784
|
globalInstances[this._id] = this;
|
|
@@ -777,9 +787,9 @@ class Agent extends BaseSDK {
|
|
|
777
787
|
LISTENER_CMDS.CUSTOM_AGENT_WATCH_EXECUTION,
|
|
778
788
|
{ id: this._id, agentId: this.agentId, executionId, watchId, eventName },
|
|
779
789
|
{
|
|
780
|
-
timeoutMs: WATCH_ACK_TIMEOUT_MS,
|
|
781
|
-
timeoutError: sdkError("AGENT_HOST_UNSUPPORTED", "The host did not start observing the Agent run."),
|
|
782
|
-
sendError: NOT_SENT
|
|
790
|
+
timeoutMs: WATCH_ACK_TIMEOUT_MS$1,
|
|
791
|
+
timeoutError: sdkError$1("AGENT_HOST_UNSUPPORTED", "The host did not start observing the Agent run."),
|
|
792
|
+
sendError: NOT_SENT$1
|
|
783
793
|
}
|
|
784
794
|
);
|
|
785
795
|
registration.promise.then(
|
|
@@ -787,12 +797,12 @@ class Agent extends BaseSDK {
|
|
|
787
797
|
if (settled)
|
|
788
798
|
return;
|
|
789
799
|
if (acknowledged !== true) {
|
|
790
|
-
fail(sdkError("AGENT_HOST_UNSUPPORTED", "The host did not start observing the Agent run."));
|
|
800
|
+
fail(sdkError$1("AGENT_HOST_UNSUPPORTED", "The host did not start observing the Agent run."));
|
|
791
801
|
return;
|
|
792
802
|
}
|
|
793
803
|
deadline = setTimeout(
|
|
794
|
-
() => fail(sdkError("AGENT_OBSERVATION_STOPPED", "Stopped checking the Agent run; read it again later.")),
|
|
795
|
-
WATCH_DEADLINE_MS
|
|
804
|
+
() => fail(sdkError$1("AGENT_OBSERVATION_STOPPED", "Stopped checking the Agent run; read it again later.")),
|
|
805
|
+
WATCH_DEADLINE_MS$1
|
|
796
806
|
);
|
|
797
807
|
},
|
|
798
808
|
(error) => fail(error)
|
|
@@ -1564,9 +1574,26 @@ class Process extends BaseSDK {
|
|
|
1564
1574
|
});
|
|
1565
1575
|
}
|
|
1566
1576
|
}
|
|
1577
|
+
const READ_TIMEOUT_MS = 3e4;
|
|
1578
|
+
const RUN_TIMEOUT_MS = 45e3;
|
|
1579
|
+
const WATCH_ACK_TIMEOUT_MS = 6e4;
|
|
1580
|
+
const WATCH_DEADLINE_MS = 69e4;
|
|
1581
|
+
function sdkError(errorCode, error) {
|
|
1582
|
+
return { isError: true, error, errorCode };
|
|
1583
|
+
}
|
|
1584
|
+
function notify(callback, value) {
|
|
1585
|
+
try {
|
|
1586
|
+
callback == null ? void 0 : callback(value);
|
|
1587
|
+
} catch (error) {
|
|
1588
|
+
console.error(error);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
const NOT_SENT = sdkError("FUNCTION_REQUEST_NOT_SENT", "The request could not be sent to the host.");
|
|
1592
|
+
const TERMINAL_STATUSES = ["Success", "Failed", "TimedOut"];
|
|
1567
1593
|
class Application extends BaseSDK {
|
|
1568
1594
|
constructor(props, isCustomComponent = false) {
|
|
1569
1595
|
super();
|
|
1596
|
+
this.activeWatches = 0;
|
|
1570
1597
|
this._id = props.appId;
|
|
1571
1598
|
this.page = new Page(props);
|
|
1572
1599
|
}
|
|
@@ -1587,6 +1614,110 @@ class Application extends BaseSDK {
|
|
|
1587
1614
|
pageParams
|
|
1588
1615
|
});
|
|
1589
1616
|
}
|
|
1617
|
+
runFunction(name, parameters) {
|
|
1618
|
+
return this._postMessageBounded(
|
|
1619
|
+
LISTENER_CMDS.CUSTOM_FUNCTION_RUN,
|
|
1620
|
+
{ name, parameters: parameters != null ? parameters : {} },
|
|
1621
|
+
{
|
|
1622
|
+
timeoutMs: RUN_TIMEOUT_MS,
|
|
1623
|
+
timeoutError: sdkError(
|
|
1624
|
+
"FUNCTION_RUN_OUTCOME_UNKNOWN",
|
|
1625
|
+
"The host did not answer the run; it may still have started."
|
|
1626
|
+
),
|
|
1627
|
+
sendError: sdkError("FUNCTION_RUN_NOT_SENT", "The run request could not be sent to the host.")
|
|
1628
|
+
}
|
|
1629
|
+
).promise;
|
|
1630
|
+
}
|
|
1631
|
+
getFunctionRun(runId) {
|
|
1632
|
+
return this._postMessageBounded(
|
|
1633
|
+
LISTENER_CMDS.CUSTOM_FUNCTION_GET_RUN,
|
|
1634
|
+
{ runId },
|
|
1635
|
+
{
|
|
1636
|
+
timeoutMs: READ_TIMEOUT_MS,
|
|
1637
|
+
timeoutError: sdkError("FUNCTION_HOST_TIMEOUT", "The host did not answer the run request."),
|
|
1638
|
+
sendError: NOT_SENT
|
|
1639
|
+
}
|
|
1640
|
+
).promise;
|
|
1641
|
+
}
|
|
1642
|
+
onFunctionRunComplete(runId, callBack, onError) {
|
|
1643
|
+
const watchId = generateId("functionwatch");
|
|
1644
|
+
const eventName = `${EVENT_TYPES.CUSTOM_FUNCTION_RUN_COMPLETE}:${watchId}`;
|
|
1645
|
+
let settled = false;
|
|
1646
|
+
let deadline = null;
|
|
1647
|
+
let registration = null;
|
|
1648
|
+
const end = () => {
|
|
1649
|
+
settled = true;
|
|
1650
|
+
if (deadline)
|
|
1651
|
+
clearTimeout(deadline);
|
|
1652
|
+
registration == null ? void 0 : registration.cancel();
|
|
1653
|
+
this._removeEventListener(eventName);
|
|
1654
|
+
this.activeWatches -= 1;
|
|
1655
|
+
if (this.activeWatches === 0)
|
|
1656
|
+
Reflect.deleteProperty(globalInstances, this._id);
|
|
1657
|
+
};
|
|
1658
|
+
const tellHostToStop = () => {
|
|
1659
|
+
try {
|
|
1660
|
+
this._postMessage(LISTENER_CMDS.CUSTOM_FUNCTION_STOP_WATCH, { id: this._id, runId, watchId, eventName });
|
|
1661
|
+
} catch {
|
|
1662
|
+
}
|
|
1663
|
+
};
|
|
1664
|
+
const fail = (error) => {
|
|
1665
|
+
if (settled)
|
|
1666
|
+
return;
|
|
1667
|
+
end();
|
|
1668
|
+
tellHostToStop();
|
|
1669
|
+
notify(onError, error);
|
|
1670
|
+
};
|
|
1671
|
+
const listener = (params) => {
|
|
1672
|
+
if (settled)
|
|
1673
|
+
return;
|
|
1674
|
+
if (params == null ? void 0 : params.isError) {
|
|
1675
|
+
end();
|
|
1676
|
+
notify(onError, params);
|
|
1677
|
+
return;
|
|
1678
|
+
}
|
|
1679
|
+
const run = params;
|
|
1680
|
+
if ((run == null ? void 0 : run.RunId) !== runId || TERMINAL_STATUSES.indexOf(run == null ? void 0 : run.Status) === -1) {
|
|
1681
|
+
fail(sdkError("FUNCTION_WATCH_INVALID_EVENT", "The host reported something other than a finished run."));
|
|
1682
|
+
return;
|
|
1683
|
+
}
|
|
1684
|
+
end();
|
|
1685
|
+
notify(callBack, run);
|
|
1686
|
+
};
|
|
1687
|
+
this.activeWatches += 1;
|
|
1688
|
+
globalInstances[this._id] = this;
|
|
1689
|
+
this._addEventListener(eventName, listener);
|
|
1690
|
+
registration = this._postMessageBounded(
|
|
1691
|
+
LISTENER_CMDS.CUSTOM_FUNCTION_ON_RUN_COMPLETE,
|
|
1692
|
+
{ id: this._id, runId, watchId, eventName },
|
|
1693
|
+
{
|
|
1694
|
+
timeoutMs: WATCH_ACK_TIMEOUT_MS,
|
|
1695
|
+
timeoutError: sdkError("FUNCTION_HOST_UNSUPPORTED", "The host did not start watching the run."),
|
|
1696
|
+
sendError: NOT_SENT
|
|
1697
|
+
}
|
|
1698
|
+
);
|
|
1699
|
+
registration.promise.then(
|
|
1700
|
+
(acknowledged) => {
|
|
1701
|
+
if (settled)
|
|
1702
|
+
return;
|
|
1703
|
+
if (acknowledged !== true) {
|
|
1704
|
+
fail(sdkError("FUNCTION_HOST_UNSUPPORTED", "The host did not start watching the run."));
|
|
1705
|
+
return;
|
|
1706
|
+
}
|
|
1707
|
+
deadline = setTimeout(
|
|
1708
|
+
() => fail(sdkError("FUNCTION_OBSERVATION_STOPPED", "Stopped checking the run; read it again later.")),
|
|
1709
|
+
WATCH_DEADLINE_MS
|
|
1710
|
+
);
|
|
1711
|
+
},
|
|
1712
|
+
(error) => fail(error)
|
|
1713
|
+
);
|
|
1714
|
+
return () => {
|
|
1715
|
+
if (settled)
|
|
1716
|
+
return;
|
|
1717
|
+
end();
|
|
1718
|
+
tellHostToStop();
|
|
1719
|
+
};
|
|
1720
|
+
}
|
|
1590
1721
|
getDecisionTable(flowId) {
|
|
1591
1722
|
return new DecisionTable(flowId);
|
|
1592
1723
|
}
|
package/dist/kfsdk.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var W=(i,s,T)=>{if(!s.has(i))throw TypeError("Cannot "+T)};var h=(i,s,T)=>(W(i,s,"read from private field"),T?T.call(i):s.get(i)),m=(i,s,T)=>{if(s.has(i))throw TypeError("Cannot add the same private member more than once");s instanceof WeakSet?s.add(i):s.set(i,T)},w=(i,s,T,f)=>(W(i,s,"write to private field"),f?f.call(i,T):s.set(i,T),T);var X=(i,s,T)=>(W(i,s,"access private method"),T);(function(i,s){typeof exports=="object"&&typeof module!="undefined"?module.exports=s():typeof define=="function"&&define.amd?define(s):(i=typeof globalThis!="undefined"?globalThis:i||self,i.kf=s())})(this,function(){var R,g,y,v,Y;"use strict";let i=(r=21)=>crypto.getRandomValues(new Uint8Array(r)).reduce((e,t)=>(t&=63,t<36?e+=t.toString(36):t<62?e+=(t-26).toString(36).toUpperCase():t>62?e+="-":e+="_",e),"");const s={API:"API",GET_CONTEXT:"GET_CONTEXT",RETURN:"RETURN",GET_FORM_FIELD:"GET_FORM_FIELD",UPDATE_FORM:"UPDATE_FORM",GET_FORM_VALIDATION_ERRORS:"GET_FORM_VALIDATION_ERRORS",GET_FORM_CONFIGURATION:"GET_FORM_CONFIGURATION",GET_FORM_FIELD_STATE:"GET_FORM_FIELD_STATE",GET_TABLE:"GET_TABLE",GET_TABLE_ROW:"GET_TABLE_ROW",ADD_TABLE_ROW:"ADD_TABLE_ROW",ADD_TABLE_ROWS:"ADD_TABLE_ROWS",DELETE_TABLE_ROW:"DELETE_TABLE_ROW",TO_JSON:"TO_JSON",GET_TABLE_ROWS:"GET_TABLE_ROWS",GET_SELECTED_TABLE_ROWS:"GET_SELECTED_TABLE_ROWS",MESSAGE:"MESSAGE",CONFIRM:"CONFIRM",ALERT:"ALERT",REDIRECT:"REDIRECT",OPEN_PAGE:"OPEN_PAGE",GET_IMAGE_URL:"GET_IMAGE_URL",FILEPICKER_OPEN:"FILEPICKER_OPEN",FILEPREVIEW_OPEN:"FILEPREVIEW_OPEN",FILE_UPLOAD:"FILE_UPLOAD",SCANNER_OPEN:"SCANNER_OPEN",GEOLOCATION_OPEN:"GEOLOCATION_OPEN",GET_ROLES:"GET_ROLES",SWITCH_ROLE:"SWITCH_ROLE",FORMAT_DATE:"FORMAT_DATE",FORMAT_DATE_TIME:"FORMAT_DATE_TIME",FORMAT_NUMBER:"FORMAT_NUMBER",FORMAT_CURRENCY:"FORMAT_CURRENCY",FORMAT_BOOLEAN:"FORMAT_BOOLEAN",GET_APP_VARIABLE:"GET_APP_VARIABLE",SET_APP_VARIABLE:"SET_APP_VARIABLE",GET_PAGE_VARIABLE:"GET_PAGE_VARIABLE",SET_PAGE_VARIABLE:"SET_PAGE_VARIABLE",GET_PAGE_PARAMS:"GET_PAGE_PARAMS",GET_ALL_PAGE_PARAMS:"GET_ALL_PAGE_PARAMS",PAGE_ON_CLOSE:"PAGE_ON_CLOSE",OPEN_POPUP:"OPEN_POPUP",GET_POPUP_PARAMS:"GET_POPUP_PARAMS",GET_ALL_POPUP_PARAMS:"GET_ALL_POPUP_PARAMS",CLOSE_POPUP:"CLOSE_POPUP",COMPONENT_GET:"COMPONENT_GET",COMPONENT_REFRESH:"COMPONENT_REFRESH",COMPONENT_SHOW:"COMPONENT_SHOW",COMPONENT_HIDE:"COMPONENT_HIDE",COMPONENT_ADD_EVENT_LISTENER:"COMPONENT_ADD_EVENT_LISTENER",CC_INITIALIZE:"CC_INITIALIZE",CC_WATCH_PARAMS:"CC_WATCH_PARAMS",CC_SET_ROUTE:"CC_SET_ROUTE",CC_WATCH_ROUTE:"CC_WATCH_ROUTE",WINDOW_NDEF_READER_NEW:"WINDOW_NDEF_READER_NEW",WINDOW_NDEF_READER_SCAN:"WINDOW_NDEF_READER_SCAN",WINDOW_NDEF_READER_WRITE:"WINDOW_NDEF_READER_WRITE",WINDOW_NDEF_READER_ADD_EVENT_LISTENER:"WINDOW_NDEF_READER_ADD_EVENT_LISTENER",WINDOW_NDEF_READER_MAKE_READONLY:"WINDOW_NDEF_READER_MAKE_READONLY",WINDOW_NDEF_READER_ABORT_SCAN:"WINDOW_NDEF_READER_ABORT_SCAN",CUSTOM_AGENT_GET_CONTRACT:"CUSTOM_AGENT_GET_CONTRACT",CUSTOM_AGENT_EXECUTE:"CUSTOM_AGENT_EXECUTE",CUSTOM_AGENT_GET_EXECUTION:"CUSTOM_AGENT_GET_EXECUTION",CUSTOM_AGENT_WATCH_EXECUTION:"CUSTOM_AGENT_WATCH_EXECUTION",CUSTOM_AGENT_STOP_WATCH:"CUSTOM_AGENT_STOP_WATCH",DECISION_TABLE_EXECUTE:"DECISION_TABLE_EXECUTE",DATAFORM_IMPORT_CSV:"DATAFORM_IMPORT_CSV",DATAFORM_OPEN_FORM:"DATAFORM_OPEN_FORM",DATAFORM_GET_FIELDS:"DATAFORM_GET_FIELDS",DATAFORM_GET_ITEMS:"DATAFORM_GET_ITEMS",DATAFORM_CREATE_ITEM:"DATAFORM_CREATE_ITEM",DATAFORM_UPDATE_ITEM:"DATAFORM_UPDATE_ITEM",DATAFORM_GET_ITEM:"DATAFORM_GET_ITEM",DATAFORM_DELETE_ITEM:"DATAFORM_DELETE_ITEM",DATAFORM_DISCARD_ITEM:"DATAFORM_DISCARD_ITEM",DATAFORM_SUBMIT_ITEM:"DATAFORM_SUBMIT_ITEM",DATAFORM_INIT_FORM:"DATAFORM_INIT_FORM",DATAFORM_GET_FIELD_OPTIONS:"DATAFORM_GET_FIELD_OPTIONS",PROCESS_OPEN_FORM:"PROCESS_OPEN_FORM",PROCESS_GET_FIELDS:"PROCESS_GET_FIELDS",PROCESS_GET_MYTASK_FIELDS:"PROCESS_GET_MYTASK_FIELDS",PROCESS_GET_PARTICIPATED_FIELDS:"PROCESS_GET_PARTICIPATED_FIELDS",PROCESS_GET_MY_ITEMS_FIELDS:"PROCESS_GET_MY_ITEMS_FIELDS",PROCESS_GET_MY_ITEMS:"PROCESS_GET_MY_ITEMS",PROCESS_GET_MY_TASKS_ITEMS:"PROCESS_GET_MY_TASKS_ITEMS",PROCESS_GET_PARTICIPATED_ITEMS:"PROCESS_GET_PARTICIPATED_ITEMS",PROCESS_GET_ADMIN_ITEMS:"PROCESS_GET_ADMIN_ITEMS",PROCESS_CREATE_ITEM:"PROCESS_CREATE_ITEM",PROCESS_UPDATE_ITEM:"PROCESS_UPDATE_ITEM",PROCESS_GET_ITEM:"PROCESS_GET_ITEM",PROCESS_DELETE_ITEM:"PROCESS_DELETE_ITEM",PROCESS_GET_ADMIN_ITEM:"PROCESS_GET_ADMIN_ITEM",PROCESS_UPDATE_ADMIN_ITEM:"PROCESS_UPDATE_ADMIN_ITEM",PROCESS_SUBMIT_ITEM:"PROCESS_SUBMIT_ITEM",PROCESS_REJECT_ITEM:"PROCESS_REJECT_ITEM",PROCESS_WITHDRAW_ITEM:"PROCESS_WITHDRAW_ITEM",PROCESS_SENDBACK_ITEM:"PROCESS_SENDBACK_ITEM",PROCESS_REASSIGN_ITEM:"PROCESS_REASSIGN_ITEM",PROCESS_GET_REASSIGNEES:"PROCESS_GET_REASSIGNEES",PROCESS_RESTART_ITEM:"PROCESS_RESTART_ITEM",PROCESS_DISCARD_ITEM:"PROCESS_DISCARD_ITEM",PROCESS_GET_PROGRESS:"PROCESS_GET_PROGRESS",PROCESS_INIT_FORM:"PROCESS_INIT_FORM",PROCESS_GET_FIELD_OPTIONS:"PROCESS_GET_FIELD_OPTIONS",PROCESS_PARSE_ATTACHMENT:"PROCESS_PARSE_ATTACHMENT",BOARD_IMPORT_CSV:"BOARD_IMPORT_CSV",BOARD_OPEN_FORM:"BOARD_OPEN_FORM",BOARD_GET_FIELDS:"BOARD_GET_FIELDS",BOARD_GET_ITEMS:"BOARD_GET_ITEMS",BOARD_CREATE_ITEM:"BOARD_CREATE_ITEM",BOARD_UPDATE_ITEM:"BOARD_UPDATE_ITEM",BOARD_GET_ITEM:"BOARD_GET_ITEM",BOARD_DELETE_ITEM:"BOARD_DELETE_ITEM",BOARD_SUBMIT_ITEM:"BOARD_SUBMIT_ITEM",BOARD_DISCARD_ITEM:"BOARD_DISCARD_ITEM",BOARD_INIT_FORM:"BOARD_INIT_FORM",BOARD_GET_FIELD_OPTIONS:"BOARD_GET_FIELD_OPTIONS"},T={COMPONENT_ON_MOUNT:"componentOnMount",CC_ON_PARAMS_CHANGE:"onCustomComponentParamsChange",CC_ON_ROUTE_CHANGE:"onCustomComponentRouteChange",CUSTOM_AGENT_EXECUTION_COMPLETE:"onCustomAgentExecutionComplete"},f={POPUP_ID:"ACTIVE_POP_UP"};function N(r="lcncsdk"){return`${r}-${i()}`}const l={},G=new Set;function b(r,e){if(e&&Object.keys(e).length===1&&r.command!==s.API){let t=Object.values(e)[0];return t==="undefined"?void 0:t}else return e}function F(r){globalThis.parent&&globalThis.parent!==globalThis?globalThis.parent.postMessage(r,"*"):globalThis.postMessage(r)}function z(r){if(r.origin!==globalThis.location.origin){const e=r.data;if(e!=null&&e.isEvent){const{target:E,eventParams:I,eventName:n,eventConfig:d={}}=e;let a=l[E];if(!a)return;a._dispatchEvent(n,I),d.once&&a._removeEventListener(n);return}let{_req:t,resp:_}=e;if(t!=null&&t._id){let E=l[t._id];E&&(E._dispatchMessageEvents(t,_),G.delete(t._id)&&Reflect.deleteProperty(l,t._id))}}}globalThis.addEventListener("message",z);class J{constructor(){m(this,R,void 0);w(this,R,{})}_addEventListener(e,t){var _;h(this,R)[e]=((_=h(this,R))==null?void 0:_[e])||[],h(this,R)[e].push(t)}_removeEventListener(e,t){if(t){const _=h(this,R)[e]||[],E=_.indexOf(t);E>-1&&_.splice(E,1);return}Reflect.deleteProperty(h(this,R),e)}_dispatchEvent(e,t){return Array.isArray(h(this,R)[e])?(h(this,R)[e].forEach(_=>_(t)),!0):!1}_dispatchMessageEvents(e,t){let _=e._id;Array.isArray(h(this,R)[_])&&(h(this,R)[_].forEach(E=>{try{let I=b(e,t);E(I)}catch(I){console.error("Message callback error: ",I)}}),this._removeEventListener(_))}}R=new WeakMap;class c extends J{_postMessageAsync(e,t,_,E){return new Promise((I,n)=>{const d=N(e.toLowerCase());F({_id:d,command:e,...t}),l[d]=this,G.add(d),this._addEventListener(d,async a=>{(a==null?void 0:a.errorMessage)||(a==null?void 0:a.isError)?n(a):(_&&E&&(a=await E(a)),I(a))})})}_postMessageBounded(e,t,_){const E=N(e.toLowerCase());let I,n=!1;const d=()=>{n=!0,clearTimeout(I),this._removeEventListener(E),G.delete(E),Reflect.deleteProperty(l,E)};return{promise:new Promise((P,S)=>{I=setTimeout(()=>{d(),S(_.timeoutError)},_.timeoutMs),l[E]=this,G.add(E),this._addEventListener(E,O=>{d(),(O==null?void 0:O.errorMessage)||(O==null?void 0:O.isError)?S(O):P(O)});try{F({_id:E,command:e,...t})}catch{d(),S(_.sendError)}}),cancel:()=>{n||d()}}}_postMessage(e,t,_){const E=N(e.toLowerCase());F({_id:E,command:e,...t}),_&&this._addEventListener(t.eventName,_)}_postMessageSync(e,t){let _=0,I={_id:N(e.toLowerCase()),command:e,...t},n=new q;n.reset(),n.store(0,_),n.encodeData(1,I),F(n.sab),n.wait(0,_,1e4);let d=n.decodeData(),{_req:a,resp:P}=d,S=b(a,P);if(S!=null&&S.isError)throw new Error(`Error: ${JSON.stringify(S,null,2)}`);return S}}let U;class q{constructor(){m(this,g,void 0);m(this,y,void 0);w(this,g,new TextEncoder),w(this,y,new TextDecoder),U=U||new SharedArrayBuffer(1024*1024),this.sab=U,this.int32Array=new Int32Array(this.sab)}load(e=0){return Atomics.load(this.int32Array,e)}store(e=0,t){return Atomics.store(this.int32Array,e,t)}reset(){return this.int32Array.fill(0)}notify(e=0,t=1){return Atomics.notify(this.int32Array,e,t)}wait(e,t,_){return Atomics.wait(this.int32Array,e,t,_)}encodeData(e=0,t){const _=(n,d)=>d===void 0?"undefined":d;let E=JSON.stringify(t,_),I=h(this,g).encode(E);return this.int32Array.set(I,e),this.int32Array}decodeData(){let e=new Uint8Array(this.int32Array),t=h(this,y).decode(e).replaceAll(/\x00/g,"");return JSON.parse(t)}}g=new WeakMap,y=new WeakMap;class $ extends c{showInfo(e){return super._postMessageAsync(s.MESSAGE,{message:e})}showConfirm(e){return super._postMessageAsync(s.CONFIRM,{data:{title:e.title,content:e.content,okText:e.okText||"Ok",cancelText:e.cancelText||"Cancel"}})}redirect(e){return super._postMessageAsync(s.REDIRECT,{url:e})}getImageUrl(e){return this._postMessageAsync(s.GET_IMAGE_URL,{imageValue:e})}openFilePicker(e){return this._postMessageAsync(s.FILEPICKER_OPEN,{options:e})}openScanner(e={}){return this._postMessageAsync(s.SCANNER_OPEN,{options:e})}pickLocation(e){return this._postMessageAsync(s.GEOLOCATION_OPEN,{value:e})}uploadFile(e,t){return this._postMessageAsync(s.FILE_UPLOAD,{file:e,fileName:t!=null?t:e.name})}openFilePreview(e){var t;return this._postMessageAsync(s.FILEPREVIEW_OPEN,{files:e.files,indexOfFile:(t=e.indexOfFile)!=null?t:0})}}class k extends c{toDate(e){return this._postMessageAsync(s.FORMAT_DATE,{date:e})}toDateTime(e){return this._postMessageAsync(s.FORMAT_DATE_TIME,{date:e})}toNumber(e){return this._postMessageAsync(s.FORMAT_NUMBER,{value:e})}toCurrency(e,t){return this._postMessageAsync(s.FORMAT_CURRENCY,{value:e,currencyCode:t})}toBoolean(e){return this._postMessageAsync(s.FORMAT_BOOLEAN,{value:e})}}function A(r,e){return r?null:Promise.reject({message:`${e} is required`})}function M(r){const e=r.filter(t=>!t.value).map(t=>t.name);return e.length>0?Promise.reject({message:`${e.join(" and ")} ${e.length>1?"are":"is"} required`}):null}class V extends c{constructor(t){super();m(this,v);this._id=t.componentId,this.type="Component",l[this._id]=this,X(this,v,Y).call(this,t.componentMethods)}onMount(t){this._postMessage(s.COMPONENT_ADD_EVENT_LISTENER,{id:this._id,eventName:T.COMPONENT_ON_MOUNT,eventConfig:{once:!0}},t)}refresh(){return this._postMessageAsync(s.COMPONENT_REFRESH,{id:this._id})}show(){return this._postMessageAsync(s.COMPONENT_SHOW,{id:this._id})}hide(){return this._postMessageAsync(s.COMPONENT_HIDE,{id:this._id})}}v=new WeakSet,Y=function(t){t==null||t.forEach(_=>{this[_.name]=(...E)=>{if(_.type==="method")return this._postMessageAsync(`COMPONENT_${_.name}`,{id:this._id,parameters:E});_.type==="event"&&this._postMessage(s.COMPONENT_ADD_EVENT_LISTENER,{id:this._id,eventName:_.name,eventConfig:E[1]},E[0])}})};class j extends c{constructor(e){super(),this._id=e,this.type="CustomComponent",l[this._id]=this}watchParams(e){this._postMessage(s.CC_WATCH_PARAMS,{id:this._id,eventName:T.CC_ON_PARAMS_CHANGE,eventConfig:{once:!1}},e)}watchRoute(e){this._postMessage(s.CC_WATCH_ROUTE,{id:this._id,eventName:T.CC_ON_ROUTE_CHANGE,eventConfig:{once:!1}},e)}}class Z extends c{constructor(e){super(),this.type="Popup",this._id=e.popupId||f.POPUP_ID}getParameter(e){return this._postMessageAsync(s.GET_POPUP_PARAMS,{key:e,popupId:this._id})}getAllParameters(){return this._postMessageAsync(s.GET_ALL_POPUP_PARAMS,{popupId:this._id})}close(){return this._postMessageAsync(s.CLOSE_POPUP,{})}getComponent(e){return this._postMessageAsync(s.COMPONENT_GET,{componentId:e},!0,t=>new V(t))}}class H extends c{constructor(e,t=!1){var _;super(),this.type="Page",this.popup=new Z({}),this._id=e.pageId,this._route=(_=e.initialRoute)!=null?_:""}getParameter(e){return this._postMessageAsync(s.GET_PAGE_PARAMS,{key:e})}getAllParameters(){return this._postMessageAsync(s.GET_ALL_PAGE_PARAMS,{pageId:this._id})}getVariable(e){return this._postMessageAsync(s.GET_PAGE_VARIABLE,{key:e})}setVariable(e,t){return this._postMessageAsync(s.SET_PAGE_VARIABLE,{key:e,value:t})}openPopup(e,t){return this._postMessageAsync(s.OPEN_POPUP,{popupId:e,popupParams:t})}getComponent(e){return this._postMessageAsync(s.COMPONENT_GET,{componentId:e},!0,t=>new V(t))}setRoute(e){return this._route=e,this._postMessage(s.CC_SET_ROUTE,{route:e})}getRoute(){return this._route}}class Q extends c{constructor(e){super(),this.flowId=e}evaluate(e){return this._postMessageAsync(s.DECISION_TABLE_EXECUTE,{flowId:this.flowId,payload:e})}}const x=75e3,p=6e4,ee=6e4,te=42e4,se=["Completed","Failed"];function C(r,e){return{isError:!0,error:e,errorCode:r}}function B(r,e){try{r==null||r(e)}catch(t){console.error(t)}}const o=C("AGENT_REQUEST_NOT_SENT","The request could not be sent to the host.");class _e extends c{constructor(e){super(),this.activeWatches=0,this.agentId=e,this._id=N("customagent")}getContract(){return this._postMessageBounded(s.CUSTOM_AGENT_GET_CONTRACT,{agentId:this.agentId},{timeoutMs:x,timeoutError:C("AGENT_HOST_TIMEOUT","The host did not answer the Agent contract request."),sendError:o}).promise}execute(e){var t;return this._postMessageBounded(s.CUSTOM_AGENT_EXECUTE,{agentId:this.agentId,inputData:(t=e==null?void 0:e.inputData)!=null?t:{}},{timeoutMs:p,timeoutError:C("AGENT_EXECUTE_OUTCOME_UNKNOWN","The host did not confirm the run; it may still have started."),sendError:C("AGENT_EXECUTE_NOT_SENT","The run request could not be sent to the host.")}).promise}getExecution(e){return this._postMessageBounded(s.CUSTOM_AGENT_GET_EXECUTION,{agentId:this.agentId,executionId:e},{timeoutMs:x,timeoutError:C("AGENT_HOST_TIMEOUT","The host did not answer the Agent execution request."),sendError:o}).promise}onExecutionComplete(e,t,_){const E=N("agentwatch"),I=`${T.CUSTOM_AGENT_EXECUTION_COMPLETE}:${E}`;let n=!1,d=null,a=null;const P=()=>{n=!0,d&&clearTimeout(d),a==null||a.cancel(),this._removeEventListener(I),this.activeWatches-=1,this.activeWatches===0&&Reflect.deleteProperty(l,this._id)},S=()=>{try{this._postMessage(s.CUSTOM_AGENT_STOP_WATCH,{id:this._id,watchId:E,eventName:I})}catch{}},O=u=>{n||(P(),S(),B(_,u))},Te=u=>{if(n)return;if(u!=null&&u.isError){P(),B(_,u);return}const D=u;if((D==null?void 0:D.ExecutionId)!==e||se.indexOf(D==null?void 0:D.Status)===-1){O(C("AGENT_WATCH_INVALID_EVENT","The host reported something other than a finished run."));return}P(),B(t,D)};return this.activeWatches+=1,l[this._id]=this,this._addEventListener(I,Te),a=this._postMessageBounded(s.CUSTOM_AGENT_WATCH_EXECUTION,{id:this._id,agentId:this.agentId,executionId:e,watchId:E,eventName:I},{timeoutMs:ee,timeoutError:C("AGENT_HOST_UNSUPPORTED","The host did not start observing the Agent run."),sendError:o}),a.promise.then(u=>{if(!n){if(u!==!0){O(C("AGENT_HOST_UNSUPPORTED","The host did not start observing the Agent run."));return}d=setTimeout(()=>O(C("AGENT_OBSERVATION_STOPPED","Stopped checking the Agent run; read it again later.")),te)}},u=>O(u)),()=>{n||(P(),S())}}}class L extends c{constructor(e,t,_,E){super(),this.type="Form",this.storeId=e,this.flowId=t,this.instanceId=_,this.activityInstanceId=E}toJSON(){return this._postMessageAsync(s.TO_JSON,{storeId:this.storeId,instanceId:this.instanceId})}getField(e){return this._postMessageAsync(s.GET_FORM_FIELD,{storeId:this.storeId,instanceId:this.instanceId,fieldId:e})}updateField(e){return this._postMessageAsync(s.UPDATE_FORM,{storeId:this.storeId,instanceId:this.instanceId,data:e})}getValidationErrors(){return this._postMessageAsync(s.GET_FORM_VALIDATION_ERRORS,{storeId:this.storeId,instanceId:this.instanceId})}getFormConfiguration(){return this._postMessageAsync(s.GET_FORM_CONFIGURATION,{storeId:this.storeId,instanceId:this.instanceId})}getFieldState(){return this._postMessageAsync(s.GET_FORM_FIELD_STATE,{storeId:this.storeId,instanceId:this.instanceId})}getTable(e){return new re(this.storeId,this.flowId,this.instanceId,e,this.activityInstanceId)}}class re extends c{constructor(e,t,_,E,I){super(),this.tableId=E,this.storeId=e,this.flowId=t,this.instanceId=_,this.activityInstanceId=I}toJSON(){return this._postMessageAsync(s.TO_JSON,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId})}getSelectedRows(){return this._postMessageAsync(s.GET_SELECTED_TABLE_ROWS,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId})}getRows(){return this._postMessageAsync(s.GET_TABLE_ROWS,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId},!0,e=>e.map(t=>new K(this.storeId,this.flowId,this.instanceId,this.tableId,t.id,this.activityInstanceId)))}getRow(e){return new K(this.storeId,this.flowId,this.instanceId,this.tableId,e,this.activityInstanceId)}addRow(e){return this._postMessageAsync(s.ADD_TABLE_ROW,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId,rowObject:e})}addRows(e){return this._postMessageAsync(s.ADD_TABLE_ROWS,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId,rows:e})}deleteRow(e){return this._postMessageAsync(s.DELETE_TABLE_ROW,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId,rows:[e]})}deleteRows(e){return this._postMessageAsync(s.DELETE_TABLE_ROW,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId,rows:e})}}class K extends c{constructor(e,t,_,E,I,n){super(),this.storeId=e,this.flowId=t,this.instanceId=_,this.type="TabelForm",this.tableId=E,this.rowId=I,this.activityInstanceId=n}getParent(){return new L(this.storeId,this.flowId,this.instanceId,this.activityInstanceId)}toJSON(){return this._postMessageAsync(s.TO_JSON,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId,rowId:this.rowId})}getField(e){return this._postMessageAsync(s.GET_FORM_FIELD,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId,rowId:this.rowId,fieldId:e})}updateField(e){return this._postMessageAsync(s.UPDATE_FORM,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId,rowId:this.rowId,data:e})}}class Ee extends c{constructor(e){super(),this._id=e}getItems(e){return this._postMessageAsync(s.DATAFORM_GET_ITEMS,{flowId:this._id,viewId:(e==null?void 0:e.viewId)||"",searchValue:(e==null?void 0:e.searchValue)||"",pageNumber:(e==null?void 0:e.pageNumber)||1,pageSize:(e==null?void 0:e.pageSize)||50,payload:(e==null?void 0:e.payload)||{}})}getItem(e){const t=A(e.itemId,"itemId");return t||this._postMessageAsync(s.DATAFORM_GET_ITEM,{flowId:this._id,itemId:e.itemId,viewId:e.viewId||""})}createItem(e){return this._postMessageAsync(s.DATAFORM_CREATE_ITEM,{flowId:this._id,data:(e==null?void 0:e.data)||{},viewId:(e==null?void 0:e.viewId)||""})}updateItem(e){const t=A(e.itemId,"itemId");return t||this._postMessageAsync(s.DATAFORM_UPDATE_ITEM,{flowId:this._id,itemId:e.itemId,data:e.data,viewId:e.viewId||""})}importCSV(e){return this._postMessageAsync(s.DATAFORM_IMPORT_CSV,{flowId:this._id,defaultValues:e})}openForm(e){const t=A(e._id,"Instance Id (_id)");return t||this._postMessageAsync(s.DATAFORM_OPEN_FORM,{flowId:this._id,itemId:e._id,viewId:e._view_id||""})}deleteItem(e){const t=A(e.itemId,"itemId");return t||this._postMessageAsync(s.DATAFORM_DELETE_ITEM,{flowId:this._id,itemId:e.itemId,viewId:e.viewId||""})}discardItem(e){return this._postMessageAsync(s.DATAFORM_DISCARD_ITEM,{flowId:this._id,viewId:(e==null?void 0:e.viewId)||""})}submitItem(e){const t=A(e.itemId,"itemId");return t||this._postMessageAsync(s.DATAFORM_SUBMIT_ITEM,{flowId:this._id,itemId:e.itemId,data:e.data||{},viewId:e.viewId||""})}getFields(e){return this._postMessageAsync(s.DATAFORM_GET_FIELDS,{flowId:this._id,viewId:(e==null?void 0:e.viewId)||""})}initForm(e,t){return this._postMessageAsync(s.DATAFORM_INIT_FORM,{flowId:this._id,instanceId:e||"",viewId:t||""}).then(_=>new L(_.storeId||e||"",this._id,_.itemId||e))}getFieldOptions(e){return this._postMessageAsync(s.DATAFORM_GET_FIELD_OPTIONS,{flowId:this._id,instanceId:(e==null?void 0:e.instanceId)||"",fieldId:(e==null?void 0:e.fieldId)||"",fieldType:e==null?void 0:e.fieldType,tableId:e==null?void 0:e.tableId,tableRowId:e==null?void 0:e.tableRowId})}}class Ie extends c{constructor(e){super(),this._id=e}importCSV(e){return this._postMessageAsync(s.BOARD_IMPORT_CSV,{flowId:this._id,defaultValues:e})}openForm(e){const t=A(e._id,"Instance Id (_id)");return t||this._postMessageAsync(s.BOARD_OPEN_FORM,{flowId:this._id,itemId:e._id,viewId:e._view_id})}getItems(e){return this._postMessageAsync(s.BOARD_GET_ITEMS,{flowId:this._id,viewId:(e==null?void 0:e.viewId)||"",searchValue:(e==null?void 0:e.searchValue)||"",pageNumber:(e==null?void 0:e.pageNumber)||1,pageSize:(e==null?void 0:e.pageSize)||50,payload:(e==null?void 0:e.payload)||{}})}getItem(e){const t=A(e.instanceId,"instanceId");return t||this._postMessageAsync(s.BOARD_GET_ITEM,{flowId:this._id,instanceId:e.instanceId})}createItem(e){return this._postMessageAsync(s.BOARD_CREATE_ITEM,{flowId:this._id,data:(e==null?void 0:e.data)||{}})}updateItem(e){const t=A(e.instanceId,"instanceId");return t||this._postMessageAsync(s.BOARD_UPDATE_ITEM,{flowId:this._id,instanceId:e.instanceId,data:e.data})}deleteItem(e){const t=A(e.instanceId,"instanceId");return t||this._postMessageAsync(s.BOARD_DELETE_ITEM,{flowId:this._id,instanceId:e.instanceId})}submitItem(e){const t=A(e.instanceId,"instanceId");return t||this._postMessageAsync(s.BOARD_SUBMIT_ITEM,{flowId:this._id,instanceId:e.instanceId})}discardItem(e){const t=A(e.instanceId,"instanceId");return t||this._postMessageAsync(s.BOARD_DISCARD_ITEM,{flowId:this._id,instanceId:e.instanceId})}getFields(e){return this._postMessageAsync(s.BOARD_GET_FIELDS,{flowId:this._id,viewId:(e==null?void 0:e.viewId)||""})}initForm(e,t){return this._postMessageAsync(s.BOARD_INIT_FORM,{flowId:this._id,instanceId:e||"",viewId:t||""}).then(_=>new L(_.storeId||e||"",this._id,_.itemId||e))}getFieldOptions(e){const t=M([{value:e.instanceId,name:"instanceId"},{value:e.fieldId,name:"fieldId"}]);return t||this._postMessageAsync(s.BOARD_GET_FIELD_OPTIONS,{flowId:this._id,instanceId:e.instanceId,fieldId:e.fieldId,fieldType:e.fieldType,tableId:e==null?void 0:e.tableId,tableRowId:e==null?void 0:e.tableRowId})}}class ne extends c{constructor(e){super(),this._id=e}getMyItems(e){return this._postMessageAsync(s.PROCESS_GET_MY_ITEMS,{flowId:this._id,status:(e==null?void 0:e.status)||"all",searchValue:(e==null?void 0:e.searchValue)||"",pageNumber:(e==null?void 0:e.pageNumber)||1,pageSize:(e==null?void 0:e.pageSize)||50,payload:(e==null?void 0:e.payload)||{}})}getMyTasksItems(e){return this._postMessageAsync(s.PROCESS_GET_MY_TASKS_ITEMS,{flowId:this._id,activityId:(e==null?void 0:e.activityId)||"",searchValue:(e==null?void 0:e.searchValue)||"",pageNumber:(e==null?void 0:e.pageNumber)||1,pageSize:(e==null?void 0:e.pageSize)||50,payload:(e==null?void 0:e.payload)||{}})}getParticipatedItems(e){return this._postMessageAsync(s.PROCESS_GET_PARTICIPATED_ITEMS,{flowId:this._id,activityId:(e==null?void 0:e.activityId)||"",searchValue:(e==null?void 0:e.searchValue)||"",pageNumber:(e==null?void 0:e.pageNumber)||1,pageSize:(e==null?void 0:e.pageSize)||50,payload:(e==null?void 0:e.payload)||{}})}getAdminItems(e){return this._postMessageAsync(s.PROCESS_GET_ADMIN_ITEMS,{flowId:this._id,searchValue:(e==null?void 0:e.searchValue)||"",pageNumber:(e==null?void 0:e.pageNumber)||1,pageSize:(e==null?void 0:e.pageSize)||50,payload:(e==null?void 0:e.payload)||{}})}getItem(e){const t=M([{value:e.instanceId,name:"instanceId"},{value:e.activityInstanceId,name:"activityInstanceId"}]);return t||this._postMessageAsync(s.PROCESS_GET_ITEM,{flowId:this._id,instanceId:e.instanceId,activityInstanceId:e.activityInstanceId})}createItem(e){return this._postMessageAsync(s.PROCESS_CREATE_ITEM,{flowId:this._id,data:(e==null?void 0:e.data)||{}})}updateItem(e){const t=M([{value:e.instanceId,name:"instanceId"},{value:e.activityInstanceId,name:"activityInstanceId"}]);return t||this._postMessageAsync(s.PROCESS_UPDATE_ITEM,{flowId:this._id,instanceId:e.instanceId,activityInstanceId:e.activityInstanceId,data:e.data})}deleteItem(e){const t=A(e.instanceId,"instanceId");return t||this._postMessageAsync(s.PROCESS_DELETE_ITEM,{flowId:this._id,instanceId:e.instanceId})}getAdminItem(e){const t=A(e.instanceId,"instanceId");return t||this._postMessageAsync(s.PROCESS_GET_ADMIN_ITEM,{flowId:this._id,instanceId:e.instanceId})}updateAdminItem(e){const t=M([{value:e.instanceId,name:"instanceId"},{value:e.data,name:"data"}]);return t||this._postMessageAsync(s.PROCESS_UPDATE_ADMIN_ITEM,{flowId:this._id,instanceId:e.instanceId,data:e.data})}openForm(e){const t=M([{value:e._id,name:"Instance Id (_id)"},{value:e._activity_instance_id,name:"Activity Instance Id (_activity_instance_id)"}]);return t||this._postMessageAsync(s.PROCESS_OPEN_FORM,{flowId:this._id,instanceId:e._id,activityInstanceId:e._activity_instance_id})}submitItem(e){const t=M([{value:e.instanceId,name:"instanceId"},{value:e.activityInstanceId,name:"activityInstanceId"}]);return t||this._postMessageAsync(s.PROCESS_SUBMIT_ITEM,{flowId:this._id,instanceId:e.instanceId,activityInstanceId:e.activityInstanceId,comment:e.comment||""})}rejectItem(e){const t=M([{value:e.instanceId,name:"instanceId"},{value:e.activityInstanceId,name:"activityInstanceId"},{value:e.comment,name:"comment"}]);return t||this._postMessageAsync(s.PROCESS_REJECT_ITEM,{flowId:this._id,instanceId:e.instanceId,activityInstanceId:e.activityInstanceId,comment:e.comment})}withdrawItem(e){const t=A(e.instanceId,"instanceId");return t||this._postMessageAsync(s.PROCESS_WITHDRAW_ITEM,{flowId:this._id,instanceId:e.instanceId,comment:e.comment||""})}sendbackItem(e){const t=M([{value:e.instanceId,name:"instanceId"},{value:e.activityInstanceId,name:"activityInstanceId"},{value:e.stepId,name:"stepId"},{value:e.comment,name:"comment"}]);return t||this._postMessageAsync(s.PROCESS_SENDBACK_ITEM,{flowId:this._id,instanceId:e.instanceId,activityInstanceId:e.activityInstanceId,stepId:e.stepId,comment:e.comment})}reassignItem(e){const t=M([{value:e.instanceId,name:"instanceId"},{value:e.activityInstanceId,name:"activityInstanceId"},{value:e.reassignTo,name:"reassignTo"},{value:e.comment,name:"comment"}]);return t||this._postMessageAsync(s.PROCESS_REASSIGN_ITEM,{flowId:this._id,instanceId:e.instanceId,activityInstanceId:e.activityInstanceId,reassignTo:e.reassignTo,comment:e.comment,reassignType:e.reassignType||"approver",reassignedFrom:e.reassignedFrom||[]})}getReassignees(e){const t=M([{value:e.instanceId,name:"instanceId"},{value:e.activityInstanceId,name:"activityInstanceId"}]);return t||this._postMessageAsync(s.PROCESS_GET_REASSIGNEES,{flowId:this._id,instanceId:e.instanceId,activityInstanceId:e.activityInstanceId,pageNumber:e.pageNumber||1,pageSize:e.pageSize||50,query:e.query})}restartItem(e){const t=M([{value:e.instanceId,name:"instanceId"},{value:e.activityInstanceId,name:"activityInstanceId"}]);return t||this._postMessageAsync(s.PROCESS_RESTART_ITEM,{flowId:this._id,instanceId:e.instanceId,activityInstanceId:e.activityInstanceId})}discardItem(e){const t=A(e.instanceId,"instanceId");return t||this._postMessageAsync(s.PROCESS_DISCARD_ITEM,{flowId:this._id,instanceId:e.instanceId})}getFields(){return this._postMessageAsync(s.PROCESS_GET_FIELDS,{flowId:this._id})}getMyTaskFields(e){return this._postMessageAsync(s.PROCESS_GET_MYTASK_FIELDS,{flowId:this._id,activityId:e.activityId,isParticipated:!1})}getParticipatedFields(e){return this._postMessageAsync(s.PROCESS_GET_PARTICIPATED_FIELDS,{flowId:this._id,activityId:e.activityId,isParticipated:!0})}getMyItemsFields(e){return this._postMessageAsync(s.PROCESS_GET_MY_ITEMS_FIELDS,{flowId:this._id,status:e.status})}getProgress(e){const t=A(e.instanceId,"instanceId");return t||this._postMessageAsync(s.PROCESS_GET_PROGRESS,{flowId:this._id,instanceId:e.instanceId})}initForm(e,t){return this._postMessageAsync(s.PROCESS_INIT_FORM,{flowId:this._id,instanceId:e||"",activityInstanceId:t||""}).then(_=>new L(_.storeId||e||"",this._id,_.itemId||e,_.activityInstanceId||t))}getFieldOptions(e){return this._postMessageAsync(s.PROCESS_GET_FIELD_OPTIONS,{flowId:this._id,instanceId:(e==null?void 0:e.instanceId)||"",activityInstanceId:(e==null?void 0:e.activityInstanceId)||"",fieldId:(e==null?void 0:e.fieldId)||"",fieldType:e==null?void 0:e.fieldType,tableId:e==null?void 0:e.tableId,tableRowId:e==null?void 0:e.tableRowId})}parseAttachment(e){const t=M([{value:e.instanceId,name:"instanceId"},{value:e.activityInstanceId,name:"activityInstanceId"},{value:e.fieldId,name:"fieldId"},{value:e.file,name:"file"}]);return t||this._postMessageAsync(s.PROCESS_PARSE_ATTACHMENT,{flowId:this._id,instanceId:e.instanceId,activityInstanceId:e.activityInstanceId,fieldId:e.fieldId,file:e.file})}}class ae extends c{constructor(e,t=!1){super(),this._id=e.appId,this.page=new H(e)}getVariable(e){return this._postMessageAsync(s.GET_APP_VARIABLE,{key:e})}setVariable(e,t){return this._postMessageAsync(s.SET_APP_VARIABLE,{key:e,value:t})}openPage(e,t){return this._postMessageAsync(s.OPEN_PAGE,{pageId:e,pageParams:t})}getDecisionTable(e){return new Q(e)}getAgent(e){return new _e(e)}getDataform(e){return new Ee(e)}getBoard(e){return new Ie(e)}getProcess(e){return new ne(e)}getRoles(){return this._postMessageAsync(s.GET_ROLES,{})}switchRole(e){return this._postMessageAsync(s.SWITCH_ROLE,{roleId:e.roleId,roleName:e.roleName})}}class ie extends c{constructor(){super()}api(e,t){return this._postMessageAsync(s.API,{url:e,args:t||{}})}initialize(){return globalThis.parent&&globalThis.parent===globalThis?Promise.reject("SDK can be initialized only inside the Kissflow platform."):this._postMessageAsync(s.CC_INITIALIZE,{},!0,e=>(this.app=new ae(e,!0),this.page=new H(e,!0),this.context=new j(e.componentId),this.client=new $,this.formatter=new k,this.user=e.user,this.account=e.account,this.env=e.envDetails,this))}initialise(){return this.initialize()}}var de=new ie;return de});
|
|
1
|
+
var H=(T,s,A)=>{if(!s.has(T))throw TypeError("Cannot "+A)};var N=(T,s,A)=>(H(T,s,"read from private field"),A?A.call(T):s.get(T)),f=(T,s,A)=>{if(s.has(T))throw TypeError("Cannot add the same private member more than once");s instanceof WeakSet?s.add(T):s.set(T,A)},w=(T,s,A,F)=>(H(T,s,"write to private field"),F?F.call(T,A):s.set(T,A),A);var q=(T,s,A)=>(H(T,s,"access private method"),A);(function(T,s){typeof exports=="object"&&typeof module!="undefined"?module.exports=s():typeof define=="function"&&define.amd?define(s):(T=typeof globalThis!="undefined"?globalThis:T||self,T.kf=s())})(this,function(){var R,m,y,v,J;"use strict";let T=(r=21)=>crypto.getRandomValues(new Uint8Array(r)).reduce((e,t)=>(t&=63,t<36?e+=t.toString(36):t<62?e+=(t-26).toString(36).toUpperCase():t>62?e+="-":e+="_",e),"");const s={API:"API",GET_CONTEXT:"GET_CONTEXT",RETURN:"RETURN",GET_FORM_FIELD:"GET_FORM_FIELD",UPDATE_FORM:"UPDATE_FORM",GET_FORM_VALIDATION_ERRORS:"GET_FORM_VALIDATION_ERRORS",GET_FORM_CONFIGURATION:"GET_FORM_CONFIGURATION",GET_FORM_FIELD_STATE:"GET_FORM_FIELD_STATE",GET_TABLE:"GET_TABLE",GET_TABLE_ROW:"GET_TABLE_ROW",ADD_TABLE_ROW:"ADD_TABLE_ROW",ADD_TABLE_ROWS:"ADD_TABLE_ROWS",DELETE_TABLE_ROW:"DELETE_TABLE_ROW",TO_JSON:"TO_JSON",GET_TABLE_ROWS:"GET_TABLE_ROWS",GET_SELECTED_TABLE_ROWS:"GET_SELECTED_TABLE_ROWS",MESSAGE:"MESSAGE",CONFIRM:"CONFIRM",ALERT:"ALERT",REDIRECT:"REDIRECT",OPEN_PAGE:"OPEN_PAGE",GET_IMAGE_URL:"GET_IMAGE_URL",FILEPICKER_OPEN:"FILEPICKER_OPEN",FILEPREVIEW_OPEN:"FILEPREVIEW_OPEN",FILE_UPLOAD:"FILE_UPLOAD",SCANNER_OPEN:"SCANNER_OPEN",GEOLOCATION_OPEN:"GEOLOCATION_OPEN",GET_ROLES:"GET_ROLES",SWITCH_ROLE:"SWITCH_ROLE",FORMAT_DATE:"FORMAT_DATE",FORMAT_DATE_TIME:"FORMAT_DATE_TIME",FORMAT_NUMBER:"FORMAT_NUMBER",FORMAT_CURRENCY:"FORMAT_CURRENCY",FORMAT_BOOLEAN:"FORMAT_BOOLEAN",GET_APP_VARIABLE:"GET_APP_VARIABLE",SET_APP_VARIABLE:"SET_APP_VARIABLE",GET_PAGE_VARIABLE:"GET_PAGE_VARIABLE",SET_PAGE_VARIABLE:"SET_PAGE_VARIABLE",GET_PAGE_PARAMS:"GET_PAGE_PARAMS",GET_ALL_PAGE_PARAMS:"GET_ALL_PAGE_PARAMS",PAGE_ON_CLOSE:"PAGE_ON_CLOSE",OPEN_POPUP:"OPEN_POPUP",GET_POPUP_PARAMS:"GET_POPUP_PARAMS",GET_ALL_POPUP_PARAMS:"GET_ALL_POPUP_PARAMS",CLOSE_POPUP:"CLOSE_POPUP",COMPONENT_GET:"COMPONENT_GET",COMPONENT_REFRESH:"COMPONENT_REFRESH",COMPONENT_SHOW:"COMPONENT_SHOW",COMPONENT_HIDE:"COMPONENT_HIDE",COMPONENT_ADD_EVENT_LISTENER:"COMPONENT_ADD_EVENT_LISTENER",CC_INITIALIZE:"CC_INITIALIZE",CC_WATCH_PARAMS:"CC_WATCH_PARAMS",CC_SET_ROUTE:"CC_SET_ROUTE",CC_WATCH_ROUTE:"CC_WATCH_ROUTE",WINDOW_NDEF_READER_NEW:"WINDOW_NDEF_READER_NEW",WINDOW_NDEF_READER_SCAN:"WINDOW_NDEF_READER_SCAN",WINDOW_NDEF_READER_WRITE:"WINDOW_NDEF_READER_WRITE",WINDOW_NDEF_READER_ADD_EVENT_LISTENER:"WINDOW_NDEF_READER_ADD_EVENT_LISTENER",WINDOW_NDEF_READER_MAKE_READONLY:"WINDOW_NDEF_READER_MAKE_READONLY",WINDOW_NDEF_READER_ABORT_SCAN:"WINDOW_NDEF_READER_ABORT_SCAN",CUSTOM_AGENT_GET_CONTRACT:"CUSTOM_AGENT_GET_CONTRACT",CUSTOM_AGENT_EXECUTE:"CUSTOM_AGENT_EXECUTE",CUSTOM_AGENT_GET_EXECUTION:"CUSTOM_AGENT_GET_EXECUTION",CUSTOM_AGENT_WATCH_EXECUTION:"CUSTOM_AGENT_WATCH_EXECUTION",CUSTOM_AGENT_STOP_WATCH:"CUSTOM_AGENT_STOP_WATCH",CUSTOM_FUNCTION_RUN:"CUSTOM_FUNCTION_RUN",CUSTOM_FUNCTION_GET_RUN:"CUSTOM_FUNCTION_GET_RUN",CUSTOM_FUNCTION_ON_RUN_COMPLETE:"CUSTOM_FUNCTION_ON_RUN_COMPLETE",CUSTOM_FUNCTION_STOP_WATCH:"CUSTOM_FUNCTION_STOP_WATCH",DECISION_TABLE_EXECUTE:"DECISION_TABLE_EXECUTE",DATAFORM_IMPORT_CSV:"DATAFORM_IMPORT_CSV",DATAFORM_OPEN_FORM:"DATAFORM_OPEN_FORM",DATAFORM_GET_FIELDS:"DATAFORM_GET_FIELDS",DATAFORM_GET_ITEMS:"DATAFORM_GET_ITEMS",DATAFORM_CREATE_ITEM:"DATAFORM_CREATE_ITEM",DATAFORM_UPDATE_ITEM:"DATAFORM_UPDATE_ITEM",DATAFORM_GET_ITEM:"DATAFORM_GET_ITEM",DATAFORM_DELETE_ITEM:"DATAFORM_DELETE_ITEM",DATAFORM_DISCARD_ITEM:"DATAFORM_DISCARD_ITEM",DATAFORM_SUBMIT_ITEM:"DATAFORM_SUBMIT_ITEM",DATAFORM_INIT_FORM:"DATAFORM_INIT_FORM",DATAFORM_GET_FIELD_OPTIONS:"DATAFORM_GET_FIELD_OPTIONS",PROCESS_OPEN_FORM:"PROCESS_OPEN_FORM",PROCESS_GET_FIELDS:"PROCESS_GET_FIELDS",PROCESS_GET_MYTASK_FIELDS:"PROCESS_GET_MYTASK_FIELDS",PROCESS_GET_PARTICIPATED_FIELDS:"PROCESS_GET_PARTICIPATED_FIELDS",PROCESS_GET_MY_ITEMS_FIELDS:"PROCESS_GET_MY_ITEMS_FIELDS",PROCESS_GET_MY_ITEMS:"PROCESS_GET_MY_ITEMS",PROCESS_GET_MY_TASKS_ITEMS:"PROCESS_GET_MY_TASKS_ITEMS",PROCESS_GET_PARTICIPATED_ITEMS:"PROCESS_GET_PARTICIPATED_ITEMS",PROCESS_GET_ADMIN_ITEMS:"PROCESS_GET_ADMIN_ITEMS",PROCESS_CREATE_ITEM:"PROCESS_CREATE_ITEM",PROCESS_UPDATE_ITEM:"PROCESS_UPDATE_ITEM",PROCESS_GET_ITEM:"PROCESS_GET_ITEM",PROCESS_DELETE_ITEM:"PROCESS_DELETE_ITEM",PROCESS_GET_ADMIN_ITEM:"PROCESS_GET_ADMIN_ITEM",PROCESS_UPDATE_ADMIN_ITEM:"PROCESS_UPDATE_ADMIN_ITEM",PROCESS_SUBMIT_ITEM:"PROCESS_SUBMIT_ITEM",PROCESS_REJECT_ITEM:"PROCESS_REJECT_ITEM",PROCESS_WITHDRAW_ITEM:"PROCESS_WITHDRAW_ITEM",PROCESS_SENDBACK_ITEM:"PROCESS_SENDBACK_ITEM",PROCESS_REASSIGN_ITEM:"PROCESS_REASSIGN_ITEM",PROCESS_GET_REASSIGNEES:"PROCESS_GET_REASSIGNEES",PROCESS_RESTART_ITEM:"PROCESS_RESTART_ITEM",PROCESS_DISCARD_ITEM:"PROCESS_DISCARD_ITEM",PROCESS_GET_PROGRESS:"PROCESS_GET_PROGRESS",PROCESS_INIT_FORM:"PROCESS_INIT_FORM",PROCESS_GET_FIELD_OPTIONS:"PROCESS_GET_FIELD_OPTIONS",PROCESS_PARSE_ATTACHMENT:"PROCESS_PARSE_ATTACHMENT",BOARD_IMPORT_CSV:"BOARD_IMPORT_CSV",BOARD_OPEN_FORM:"BOARD_OPEN_FORM",BOARD_GET_FIELDS:"BOARD_GET_FIELDS",BOARD_GET_ITEMS:"BOARD_GET_ITEMS",BOARD_CREATE_ITEM:"BOARD_CREATE_ITEM",BOARD_UPDATE_ITEM:"BOARD_UPDATE_ITEM",BOARD_GET_ITEM:"BOARD_GET_ITEM",BOARD_DELETE_ITEM:"BOARD_DELETE_ITEM",BOARD_SUBMIT_ITEM:"BOARD_SUBMIT_ITEM",BOARD_DISCARD_ITEM:"BOARD_DISCARD_ITEM",BOARD_INIT_FORM:"BOARD_INIT_FORM",BOARD_GET_FIELD_OPTIONS:"BOARD_GET_FIELD_OPTIONS"},A={COMPONENT_ON_MOUNT:"componentOnMount",CC_ON_PARAMS_CHANGE:"onCustomComponentParamsChange",CC_ON_ROUTE_CHANGE:"onCustomComponentRouteChange",CUSTOM_AGENT_EXECUTION_COMPLETE:"onCustomAgentExecutionComplete",CUSTOM_FUNCTION_RUN_COMPLETE:"onCustomFunctionRunComplete"},F={POPUP_ID:"ACTIVE_POP_UP"};function g(r="lcncsdk"){return`${r}-${T()}`}const l={},G=new Set,j=new Set([s.API,s.CUSTOM_FUNCTION_RUN,s.CUSTOM_FUNCTION_GET_RUN]);function x(r,e){if(e&&Object.keys(e).length===1&&!j.has(r.command)){let t=Object.values(e)[0];return t==="undefined"?void 0:t}else return e}function U(r){globalThis.parent&&globalThis.parent!==globalThis?globalThis.parent.postMessage(r,"*"):globalThis.postMessage(r)}function k(r){if(r.origin!==globalThis.location.origin){const e=r.data;if(e!=null&&e.isEvent){const{target:E,eventParams:I,eventName:n,eventConfig:a={}}=e;let i=l[E];if(!i)return;i._dispatchEvent(n,I),a.once&&i._removeEventListener(n);return}let{_req:t,resp:_}=e;if(t!=null&&t._id){let E=l[t._id];E&&(E._dispatchMessageEvents(t,_),G.delete(t._id)&&Reflect.deleteProperty(l,t._id))}}}globalThis.addEventListener("message",k);class Z{constructor(){f(this,R,void 0);w(this,R,{})}_addEventListener(e,t){var _;N(this,R)[e]=((_=N(this,R))==null?void 0:_[e])||[],N(this,R)[e].push(t)}_removeEventListener(e,t){if(t){const _=N(this,R)[e]||[],E=_.indexOf(t);E>-1&&_.splice(E,1);return}Reflect.deleteProperty(N(this,R),e)}_dispatchEvent(e,t){return Array.isArray(N(this,R)[e])?(N(this,R)[e].forEach(_=>_(t)),!0):!1}_dispatchMessageEvents(e,t){let _=e._id;Array.isArray(N(this,R)[_])&&(N(this,R)[_].forEach(E=>{try{let I=x(e,t);E(I)}catch(I){console.error("Message callback error: ",I)}}),this._removeEventListener(_))}}R=new WeakMap;class O extends Z{_postMessageAsync(e,t,_,E){return new Promise((I,n)=>{const a=g(e.toLowerCase());U({_id:a,command:e,...t}),l[a]=this,G.add(a),this._addEventListener(a,async i=>{(i==null?void 0:i.errorMessage)||(i==null?void 0:i.isError)?n(i):(_&&E&&(i=await E(i)),I(i))})})}_postMessageBounded(e,t,_){const E=g(e.toLowerCase());let I,n=!1;const a=()=>{n=!0,clearTimeout(I),this._removeEventListener(E),G.delete(E),Reflect.deleteProperty(l,E)};return{promise:new Promise((u,M)=>{I=setTimeout(()=>{a(),M(_.timeoutError)},_.timeoutMs),l[E]=this,G.add(E),this._addEventListener(E,c=>{a(),(c==null?void 0:c.errorMessage)||(c==null?void 0:c.isError)?M(c):u(c)});try{U({_id:E,command:e,...t})}catch{a(),M(_.sendError)}}),cancel:()=>{n||a()}}}_postMessage(e,t,_){const E=g(e.toLowerCase());U({_id:E,command:e,...t}),_&&this._addEventListener(t.eventName,_)}_postMessageSync(e,t){let _=0,I={_id:g(e.toLowerCase()),command:e,...t},n=new Q;n.reset(),n.store(0,_),n.encodeData(1,I),U(n.sab),n.wait(0,_,1e4);let a=n.decodeData(),{_req:i,resp:u}=a,M=x(i,u);if(M!=null&&M.isError)throw new Error(`Error: ${JSON.stringify(M,null,2)}`);return M}}let o;class Q{constructor(){f(this,m,void 0);f(this,y,void 0);w(this,m,new TextEncoder),w(this,y,new TextDecoder),o=o||new SharedArrayBuffer(1024*1024),this.sab=o,this.int32Array=new Int32Array(this.sab)}load(e=0){return Atomics.load(this.int32Array,e)}store(e=0,t){return Atomics.store(this.int32Array,e,t)}reset(){return this.int32Array.fill(0)}notify(e=0,t=1){return Atomics.notify(this.int32Array,e,t)}wait(e,t,_){return Atomics.wait(this.int32Array,e,t,_)}encodeData(e=0,t){const _=(n,a)=>a===void 0?"undefined":a;let E=JSON.stringify(t,_),I=N(this,m).encode(E);return this.int32Array.set(I,e),this.int32Array}decodeData(){let e=new Uint8Array(this.int32Array),t=N(this,y).decode(e).replaceAll(/\x00/g,"");return JSON.parse(t)}}m=new WeakMap,y=new WeakMap;class p extends O{showInfo(e){return super._postMessageAsync(s.MESSAGE,{message:e})}showConfirm(e){return super._postMessageAsync(s.CONFIRM,{data:{title:e.title,content:e.content,okText:e.okText||"Ok",cancelText:e.cancelText||"Cancel"}})}redirect(e){return super._postMessageAsync(s.REDIRECT,{url:e})}getImageUrl(e){return this._postMessageAsync(s.GET_IMAGE_URL,{imageValue:e})}openFilePicker(e){return this._postMessageAsync(s.FILEPICKER_OPEN,{options:e})}openScanner(e={}){return this._postMessageAsync(s.SCANNER_OPEN,{options:e})}pickLocation(e){return this._postMessageAsync(s.GEOLOCATION_OPEN,{value:e})}uploadFile(e,t){return this._postMessageAsync(s.FILE_UPLOAD,{file:e,fileName:t!=null?t:e.name})}openFilePreview(e){var t;return this._postMessageAsync(s.FILEPREVIEW_OPEN,{files:e.files,indexOfFile:(t=e.indexOfFile)!=null?t:0})}}class ee extends O{toDate(e){return this._postMessageAsync(s.FORMAT_DATE,{date:e})}toDateTime(e){return this._postMessageAsync(s.FORMAT_DATE_TIME,{date:e})}toNumber(e){return this._postMessageAsync(s.FORMAT_NUMBER,{value:e})}toCurrency(e,t){return this._postMessageAsync(s.FORMAT_CURRENCY,{value:e,currencyCode:t})}toBoolean(e){return this._postMessageAsync(s.FORMAT_BOOLEAN,{value:e})}}function h(r,e){return r?null:Promise.reject({message:`${e} is required`})}function C(r){const e=r.filter(t=>!t.value).map(t=>t.name);return e.length>0?Promise.reject({message:`${e.join(" and ")} ${e.length>1?"are":"is"} required`}):null}class K extends O{constructor(t){super();f(this,v);this._id=t.componentId,this.type="Component",l[this._id]=this,q(this,v,J).call(this,t.componentMethods)}onMount(t){this._postMessage(s.COMPONENT_ADD_EVENT_LISTENER,{id:this._id,eventName:A.COMPONENT_ON_MOUNT,eventConfig:{once:!0}},t)}refresh(){return this._postMessageAsync(s.COMPONENT_REFRESH,{id:this._id})}show(){return this._postMessageAsync(s.COMPONENT_SHOW,{id:this._id})}hide(){return this._postMessageAsync(s.COMPONENT_HIDE,{id:this._id})}}v=new WeakSet,J=function(t){t==null||t.forEach(_=>{this[_.name]=(...E)=>{if(_.type==="method")return this._postMessageAsync(`COMPONENT_${_.name}`,{id:this._id,parameters:E});_.type==="event"&&this._postMessage(s.COMPONENT_ADD_EVENT_LISTENER,{id:this._id,eventName:_.name,eventConfig:E[1]},E[0])}})};class te extends O{constructor(e){super(),this._id=e,this.type="CustomComponent",l[this._id]=this}watchParams(e){this._postMessage(s.CC_WATCH_PARAMS,{id:this._id,eventName:A.CC_ON_PARAMS_CHANGE,eventConfig:{once:!1}},e)}watchRoute(e){this._postMessage(s.CC_WATCH_ROUTE,{id:this._id,eventName:A.CC_ON_ROUTE_CHANGE,eventConfig:{once:!1}},e)}}class se extends O{constructor(e){super(),this.type="Popup",this._id=e.popupId||F.POPUP_ID}getParameter(e){return this._postMessageAsync(s.GET_POPUP_PARAMS,{key:e,popupId:this._id})}getAllParameters(){return this._postMessageAsync(s.GET_ALL_POPUP_PARAMS,{popupId:this._id})}close(){return this._postMessageAsync(s.CLOSE_POPUP,{})}getComponent(e){return this._postMessageAsync(s.COMPONENT_GET,{componentId:e},!0,t=>new K(t))}}class X extends O{constructor(e,t=!1){var _;super(),this.type="Page",this.popup=new se({}),this._id=e.pageId,this._route=(_=e.initialRoute)!=null?_:""}getParameter(e){return this._postMessageAsync(s.GET_PAGE_PARAMS,{key:e})}getAllParameters(){return this._postMessageAsync(s.GET_ALL_PAGE_PARAMS,{pageId:this._id})}getVariable(e){return this._postMessageAsync(s.GET_PAGE_VARIABLE,{key:e})}setVariable(e,t){return this._postMessageAsync(s.SET_PAGE_VARIABLE,{key:e,value:t})}openPopup(e,t){return this._postMessageAsync(s.OPEN_POPUP,{popupId:e,popupParams:t})}getComponent(e){return this._postMessageAsync(s.COMPONENT_GET,{componentId:e},!0,t=>new K(t))}setRoute(e){return this._route=e,this._postMessage(s.CC_SET_ROUTE,{route:e})}getRoute(){return this._route}}class _e extends O{constructor(e){super(),this.flowId=e}evaluate(e){return this._postMessageAsync(s.DECISION_TABLE_EXECUTE,{flowId:this.flowId,payload:e})}}const Y=75e3,re=6e4,Ee=6e4,ne=42e4,ie=["Completed","Failed"];function P(r,e){return{isError:!0,error:e,errorCode:r}}function B(r,e){try{r==null||r(e)}catch(t){console.error(t)}}const W=P("AGENT_REQUEST_NOT_SENT","The request could not be sent to the host.");class Ie extends O{constructor(e){super(),this.activeWatches=0,this.agentId=e,this._id=g("customagent")}getContract(){return this._postMessageBounded(s.CUSTOM_AGENT_GET_CONTRACT,{agentId:this.agentId},{timeoutMs:Y,timeoutError:P("AGENT_HOST_TIMEOUT","The host did not answer the Agent contract request."),sendError:W}).promise}execute(e){var t;return this._postMessageBounded(s.CUSTOM_AGENT_EXECUTE,{agentId:this.agentId,inputData:(t=e==null?void 0:e.inputData)!=null?t:{}},{timeoutMs:re,timeoutError:P("AGENT_EXECUTE_OUTCOME_UNKNOWN","The host did not confirm the run; it may still have started."),sendError:P("AGENT_EXECUTE_NOT_SENT","The run request could not be sent to the host.")}).promise}getExecution(e){return this._postMessageBounded(s.CUSTOM_AGENT_GET_EXECUTION,{agentId:this.agentId,executionId:e},{timeoutMs:Y,timeoutError:P("AGENT_HOST_TIMEOUT","The host did not answer the Agent execution request."),sendError:W}).promise}onExecutionComplete(e,t,_){const E=g("agentwatch"),I=`${A.CUSTOM_AGENT_EXECUTION_COMPLETE}:${E}`;let n=!1,a=null,i=null;const u=()=>{n=!0,a&&clearTimeout(a),i==null||i.cancel(),this._removeEventListener(I),this.activeWatches-=1,this.activeWatches===0&&Reflect.deleteProperty(l,this._id)},M=()=>{try{this._postMessage(s.CUSTOM_AGENT_STOP_WATCH,{id:this._id,watchId:E,eventName:I})}catch{}},c=d=>{n||(u(),M(),B(_,d))},V=d=>{if(n)return;if(d!=null&&d.isError){u(),B(_,d);return}const S=d;if((S==null?void 0:S.ExecutionId)!==e||ie.indexOf(S==null?void 0:S.Status)===-1){c(P("AGENT_WATCH_INVALID_EVENT","The host reported something other than a finished run."));return}u(),B(t,S)};return this.activeWatches+=1,l[this._id]=this,this._addEventListener(I,V),i=this._postMessageBounded(s.CUSTOM_AGENT_WATCH_EXECUTION,{id:this._id,agentId:this.agentId,executionId:e,watchId:E,eventName:I},{timeoutMs:Ee,timeoutError:P("AGENT_HOST_UNSUPPORTED","The host did not start observing the Agent run."),sendError:W}),i.promise.then(d=>{if(!n){if(d!==!0){c(P("AGENT_HOST_UNSUPPORTED","The host did not start observing the Agent run."));return}a=setTimeout(()=>c(P("AGENT_OBSERVATION_STOPPED","Stopped checking the Agent run; read it again later.")),ne)}},d=>c(d)),()=>{n||(u(),M())}}}class L extends O{constructor(e,t,_,E){super(),this.type="Form",this.storeId=e,this.flowId=t,this.instanceId=_,this.activityInstanceId=E}toJSON(){return this._postMessageAsync(s.TO_JSON,{storeId:this.storeId,instanceId:this.instanceId})}getField(e){return this._postMessageAsync(s.GET_FORM_FIELD,{storeId:this.storeId,instanceId:this.instanceId,fieldId:e})}updateField(e){return this._postMessageAsync(s.UPDATE_FORM,{storeId:this.storeId,instanceId:this.instanceId,data:e})}getValidationErrors(){return this._postMessageAsync(s.GET_FORM_VALIDATION_ERRORS,{storeId:this.storeId,instanceId:this.instanceId})}getFormConfiguration(){return this._postMessageAsync(s.GET_FORM_CONFIGURATION,{storeId:this.storeId,instanceId:this.instanceId})}getFieldState(){return this._postMessageAsync(s.GET_FORM_FIELD_STATE,{storeId:this.storeId,instanceId:this.instanceId})}getTable(e){return new ae(this.storeId,this.flowId,this.instanceId,e,this.activityInstanceId)}}class ae extends O{constructor(e,t,_,E,I){super(),this.tableId=E,this.storeId=e,this.flowId=t,this.instanceId=_,this.activityInstanceId=I}toJSON(){return this._postMessageAsync(s.TO_JSON,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId})}getSelectedRows(){return this._postMessageAsync(s.GET_SELECTED_TABLE_ROWS,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId})}getRows(){return this._postMessageAsync(s.GET_TABLE_ROWS,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId},!0,e=>e.map(t=>new $(this.storeId,this.flowId,this.instanceId,this.tableId,t.id,this.activityInstanceId)))}getRow(e){return new $(this.storeId,this.flowId,this.instanceId,this.tableId,e,this.activityInstanceId)}addRow(e){return this._postMessageAsync(s.ADD_TABLE_ROW,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId,rowObject:e})}addRows(e){return this._postMessageAsync(s.ADD_TABLE_ROWS,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId,rows:e})}deleteRow(e){return this._postMessageAsync(s.DELETE_TABLE_ROW,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId,rows:[e]})}deleteRows(e){return this._postMessageAsync(s.DELETE_TABLE_ROW,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId,rows:e})}}class $ extends O{constructor(e,t,_,E,I,n){super(),this.storeId=e,this.flowId=t,this.instanceId=_,this.type="TabelForm",this.tableId=E,this.rowId=I,this.activityInstanceId=n}getParent(){return new L(this.storeId,this.flowId,this.instanceId,this.activityInstanceId)}toJSON(){return this._postMessageAsync(s.TO_JSON,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId,rowId:this.rowId})}getField(e){return this._postMessageAsync(s.GET_FORM_FIELD,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId,rowId:this.rowId,fieldId:e})}updateField(e){return this._postMessageAsync(s.UPDATE_FORM,{storeId:this.storeId,instanceId:this.instanceId,tableId:this.tableId,rowId:this.rowId,data:e})}}class de extends O{constructor(e){super(),this._id=e}getItems(e){return this._postMessageAsync(s.DATAFORM_GET_ITEMS,{flowId:this._id,viewId:(e==null?void 0:e.viewId)||"",searchValue:(e==null?void 0:e.searchValue)||"",pageNumber:(e==null?void 0:e.pageNumber)||1,pageSize:(e==null?void 0:e.pageSize)||50,payload:(e==null?void 0:e.payload)||{}})}getItem(e){const t=h(e.itemId,"itemId");return t||this._postMessageAsync(s.DATAFORM_GET_ITEM,{flowId:this._id,itemId:e.itemId,viewId:e.viewId||""})}createItem(e){return this._postMessageAsync(s.DATAFORM_CREATE_ITEM,{flowId:this._id,data:(e==null?void 0:e.data)||{},viewId:(e==null?void 0:e.viewId)||""})}updateItem(e){const t=h(e.itemId,"itemId");return t||this._postMessageAsync(s.DATAFORM_UPDATE_ITEM,{flowId:this._id,itemId:e.itemId,data:e.data,viewId:e.viewId||""})}importCSV(e){return this._postMessageAsync(s.DATAFORM_IMPORT_CSV,{flowId:this._id,defaultValues:e})}openForm(e){const t=h(e._id,"Instance Id (_id)");return t||this._postMessageAsync(s.DATAFORM_OPEN_FORM,{flowId:this._id,itemId:e._id,viewId:e._view_id||""})}deleteItem(e){const t=h(e.itemId,"itemId");return t||this._postMessageAsync(s.DATAFORM_DELETE_ITEM,{flowId:this._id,itemId:e.itemId,viewId:e.viewId||""})}discardItem(e){return this._postMessageAsync(s.DATAFORM_DISCARD_ITEM,{flowId:this._id,viewId:(e==null?void 0:e.viewId)||""})}submitItem(e){const t=h(e.itemId,"itemId");return t||this._postMessageAsync(s.DATAFORM_SUBMIT_ITEM,{flowId:this._id,itemId:e.itemId,data:e.data||{},viewId:e.viewId||""})}getFields(e){return this._postMessageAsync(s.DATAFORM_GET_FIELDS,{flowId:this._id,viewId:(e==null?void 0:e.viewId)||""})}initForm(e,t){return this._postMessageAsync(s.DATAFORM_INIT_FORM,{flowId:this._id,instanceId:e||"",viewId:t||""}).then(_=>new L(_.storeId||e||"",this._id,_.itemId||e))}getFieldOptions(e){return this._postMessageAsync(s.DATAFORM_GET_FIELD_OPTIONS,{flowId:this._id,instanceId:(e==null?void 0:e.instanceId)||"",fieldId:(e==null?void 0:e.fieldId)||"",fieldType:e==null?void 0:e.fieldType,tableId:e==null?void 0:e.tableId,tableRowId:e==null?void 0:e.tableRowId})}}class Te extends O{constructor(e){super(),this._id=e}importCSV(e){return this._postMessageAsync(s.BOARD_IMPORT_CSV,{flowId:this._id,defaultValues:e})}openForm(e){const t=h(e._id,"Instance Id (_id)");return t||this._postMessageAsync(s.BOARD_OPEN_FORM,{flowId:this._id,itemId:e._id,viewId:e._view_id})}getItems(e){return this._postMessageAsync(s.BOARD_GET_ITEMS,{flowId:this._id,viewId:(e==null?void 0:e.viewId)||"",searchValue:(e==null?void 0:e.searchValue)||"",pageNumber:(e==null?void 0:e.pageNumber)||1,pageSize:(e==null?void 0:e.pageSize)||50,payload:(e==null?void 0:e.payload)||{}})}getItem(e){const t=h(e.instanceId,"instanceId");return t||this._postMessageAsync(s.BOARD_GET_ITEM,{flowId:this._id,instanceId:e.instanceId})}createItem(e){return this._postMessageAsync(s.BOARD_CREATE_ITEM,{flowId:this._id,data:(e==null?void 0:e.data)||{}})}updateItem(e){const t=h(e.instanceId,"instanceId");return t||this._postMessageAsync(s.BOARD_UPDATE_ITEM,{flowId:this._id,instanceId:e.instanceId,data:e.data})}deleteItem(e){const t=h(e.instanceId,"instanceId");return t||this._postMessageAsync(s.BOARD_DELETE_ITEM,{flowId:this._id,instanceId:e.instanceId})}submitItem(e){const t=h(e.instanceId,"instanceId");return t||this._postMessageAsync(s.BOARD_SUBMIT_ITEM,{flowId:this._id,instanceId:e.instanceId})}discardItem(e){const t=h(e.instanceId,"instanceId");return t||this._postMessageAsync(s.BOARD_DISCARD_ITEM,{flowId:this._id,instanceId:e.instanceId})}getFields(e){return this._postMessageAsync(s.BOARD_GET_FIELDS,{flowId:this._id,viewId:(e==null?void 0:e.viewId)||""})}initForm(e,t){return this._postMessageAsync(s.BOARD_INIT_FORM,{flowId:this._id,instanceId:e||"",viewId:t||""}).then(_=>new L(_.storeId||e||"",this._id,_.itemId||e))}getFieldOptions(e){const t=C([{value:e.instanceId,name:"instanceId"},{value:e.fieldId,name:"fieldId"}]);return t||this._postMessageAsync(s.BOARD_GET_FIELD_OPTIONS,{flowId:this._id,instanceId:e.instanceId,fieldId:e.fieldId,fieldType:e.fieldType,tableId:e==null?void 0:e.tableId,tableRowId:e==null?void 0:e.tableRowId})}}class ce extends O{constructor(e){super(),this._id=e}getMyItems(e){return this._postMessageAsync(s.PROCESS_GET_MY_ITEMS,{flowId:this._id,status:(e==null?void 0:e.status)||"all",searchValue:(e==null?void 0:e.searchValue)||"",pageNumber:(e==null?void 0:e.pageNumber)||1,pageSize:(e==null?void 0:e.pageSize)||50,payload:(e==null?void 0:e.payload)||{}})}getMyTasksItems(e){return this._postMessageAsync(s.PROCESS_GET_MY_TASKS_ITEMS,{flowId:this._id,activityId:(e==null?void 0:e.activityId)||"",searchValue:(e==null?void 0:e.searchValue)||"",pageNumber:(e==null?void 0:e.pageNumber)||1,pageSize:(e==null?void 0:e.pageSize)||50,payload:(e==null?void 0:e.payload)||{}})}getParticipatedItems(e){return this._postMessageAsync(s.PROCESS_GET_PARTICIPATED_ITEMS,{flowId:this._id,activityId:(e==null?void 0:e.activityId)||"",searchValue:(e==null?void 0:e.searchValue)||"",pageNumber:(e==null?void 0:e.pageNumber)||1,pageSize:(e==null?void 0:e.pageSize)||50,payload:(e==null?void 0:e.payload)||{}})}getAdminItems(e){return this._postMessageAsync(s.PROCESS_GET_ADMIN_ITEMS,{flowId:this._id,searchValue:(e==null?void 0:e.searchValue)||"",pageNumber:(e==null?void 0:e.pageNumber)||1,pageSize:(e==null?void 0:e.pageSize)||50,payload:(e==null?void 0:e.payload)||{}})}getItem(e){const t=C([{value:e.instanceId,name:"instanceId"},{value:e.activityInstanceId,name:"activityInstanceId"}]);return t||this._postMessageAsync(s.PROCESS_GET_ITEM,{flowId:this._id,instanceId:e.instanceId,activityInstanceId:e.activityInstanceId})}createItem(e){return this._postMessageAsync(s.PROCESS_CREATE_ITEM,{flowId:this._id,data:(e==null?void 0:e.data)||{}})}updateItem(e){const t=C([{value:e.instanceId,name:"instanceId"},{value:e.activityInstanceId,name:"activityInstanceId"}]);return t||this._postMessageAsync(s.PROCESS_UPDATE_ITEM,{flowId:this._id,instanceId:e.instanceId,activityInstanceId:e.activityInstanceId,data:e.data})}deleteItem(e){const t=h(e.instanceId,"instanceId");return t||this._postMessageAsync(s.PROCESS_DELETE_ITEM,{flowId:this._id,instanceId:e.instanceId})}getAdminItem(e){const t=h(e.instanceId,"instanceId");return t||this._postMessageAsync(s.PROCESS_GET_ADMIN_ITEM,{flowId:this._id,instanceId:e.instanceId})}updateAdminItem(e){const t=C([{value:e.instanceId,name:"instanceId"},{value:e.data,name:"data"}]);return t||this._postMessageAsync(s.PROCESS_UPDATE_ADMIN_ITEM,{flowId:this._id,instanceId:e.instanceId,data:e.data})}openForm(e){const t=C([{value:e._id,name:"Instance Id (_id)"},{value:e._activity_instance_id,name:"Activity Instance Id (_activity_instance_id)"}]);return t||this._postMessageAsync(s.PROCESS_OPEN_FORM,{flowId:this._id,instanceId:e._id,activityInstanceId:e._activity_instance_id})}submitItem(e){const t=C([{value:e.instanceId,name:"instanceId"},{value:e.activityInstanceId,name:"activityInstanceId"}]);return t||this._postMessageAsync(s.PROCESS_SUBMIT_ITEM,{flowId:this._id,instanceId:e.instanceId,activityInstanceId:e.activityInstanceId,comment:e.comment||""})}rejectItem(e){const t=C([{value:e.instanceId,name:"instanceId"},{value:e.activityInstanceId,name:"activityInstanceId"},{value:e.comment,name:"comment"}]);return t||this._postMessageAsync(s.PROCESS_REJECT_ITEM,{flowId:this._id,instanceId:e.instanceId,activityInstanceId:e.activityInstanceId,comment:e.comment})}withdrawItem(e){const t=h(e.instanceId,"instanceId");return t||this._postMessageAsync(s.PROCESS_WITHDRAW_ITEM,{flowId:this._id,instanceId:e.instanceId,comment:e.comment||""})}sendbackItem(e){const t=C([{value:e.instanceId,name:"instanceId"},{value:e.activityInstanceId,name:"activityInstanceId"},{value:e.stepId,name:"stepId"},{value:e.comment,name:"comment"}]);return t||this._postMessageAsync(s.PROCESS_SENDBACK_ITEM,{flowId:this._id,instanceId:e.instanceId,activityInstanceId:e.activityInstanceId,stepId:e.stepId,comment:e.comment})}reassignItem(e){const t=C([{value:e.instanceId,name:"instanceId"},{value:e.activityInstanceId,name:"activityInstanceId"},{value:e.reassignTo,name:"reassignTo"},{value:e.comment,name:"comment"}]);return t||this._postMessageAsync(s.PROCESS_REASSIGN_ITEM,{flowId:this._id,instanceId:e.instanceId,activityInstanceId:e.activityInstanceId,reassignTo:e.reassignTo,comment:e.comment,reassignType:e.reassignType||"approver",reassignedFrom:e.reassignedFrom||[]})}getReassignees(e){const t=C([{value:e.instanceId,name:"instanceId"},{value:e.activityInstanceId,name:"activityInstanceId"}]);return t||this._postMessageAsync(s.PROCESS_GET_REASSIGNEES,{flowId:this._id,instanceId:e.instanceId,activityInstanceId:e.activityInstanceId,pageNumber:e.pageNumber||1,pageSize:e.pageSize||50,query:e.query})}restartItem(e){const t=C([{value:e.instanceId,name:"instanceId"},{value:e.activityInstanceId,name:"activityInstanceId"}]);return t||this._postMessageAsync(s.PROCESS_RESTART_ITEM,{flowId:this._id,instanceId:e.instanceId,activityInstanceId:e.activityInstanceId})}discardItem(e){const t=h(e.instanceId,"instanceId");return t||this._postMessageAsync(s.PROCESS_DISCARD_ITEM,{flowId:this._id,instanceId:e.instanceId})}getFields(){return this._postMessageAsync(s.PROCESS_GET_FIELDS,{flowId:this._id})}getMyTaskFields(e){return this._postMessageAsync(s.PROCESS_GET_MYTASK_FIELDS,{flowId:this._id,activityId:e.activityId,isParticipated:!1})}getParticipatedFields(e){return this._postMessageAsync(s.PROCESS_GET_PARTICIPATED_FIELDS,{flowId:this._id,activityId:e.activityId,isParticipated:!0})}getMyItemsFields(e){return this._postMessageAsync(s.PROCESS_GET_MY_ITEMS_FIELDS,{flowId:this._id,status:e.status})}getProgress(e){const t=h(e.instanceId,"instanceId");return t||this._postMessageAsync(s.PROCESS_GET_PROGRESS,{flowId:this._id,instanceId:e.instanceId})}initForm(e,t){return this._postMessageAsync(s.PROCESS_INIT_FORM,{flowId:this._id,instanceId:e||"",activityInstanceId:t||""}).then(_=>new L(_.storeId||e||"",this._id,_.itemId||e,_.activityInstanceId||t))}getFieldOptions(e){return this._postMessageAsync(s.PROCESS_GET_FIELD_OPTIONS,{flowId:this._id,instanceId:(e==null?void 0:e.instanceId)||"",activityInstanceId:(e==null?void 0:e.activityInstanceId)||"",fieldId:(e==null?void 0:e.fieldId)||"",fieldType:e==null?void 0:e.fieldType,tableId:e==null?void 0:e.tableId,tableRowId:e==null?void 0:e.tableRowId})}parseAttachment(e){const t=C([{value:e.instanceId,name:"instanceId"},{value:e.activityInstanceId,name:"activityInstanceId"},{value:e.fieldId,name:"fieldId"},{value:e.file,name:"file"}]);return t||this._postMessageAsync(s.PROCESS_PARSE_ATTACHMENT,{flowId:this._id,instanceId:e.instanceId,activityInstanceId:e.activityInstanceId,fieldId:e.fieldId,file:e.file})}}const Ae=3e4,Oe=45e3,he=6e4,Me=69e4;function D(r,e){return{isError:!0,error:e,errorCode:r}}function b(r,e){try{r==null||r(e)}catch(t){console.error(t)}}const z=D("FUNCTION_REQUEST_NOT_SENT","The request could not be sent to the host."),Se=["Success","Failed","TimedOut"];class Re extends O{constructor(e,t=!1){super(),this.activeWatches=0,this._id=e.appId,this.page=new X(e)}getVariable(e){return this._postMessageAsync(s.GET_APP_VARIABLE,{key:e})}setVariable(e,t){return this._postMessageAsync(s.SET_APP_VARIABLE,{key:e,value:t})}openPage(e,t){return this._postMessageAsync(s.OPEN_PAGE,{pageId:e,pageParams:t})}runFunction(e,t){return this._postMessageBounded(s.CUSTOM_FUNCTION_RUN,{name:e,parameters:t!=null?t:{}},{timeoutMs:Oe,timeoutError:D("FUNCTION_RUN_OUTCOME_UNKNOWN","The host did not answer the run; it may still have started."),sendError:D("FUNCTION_RUN_NOT_SENT","The run request could not be sent to the host.")}).promise}getFunctionRun(e){return this._postMessageBounded(s.CUSTOM_FUNCTION_GET_RUN,{runId:e},{timeoutMs:Ae,timeoutError:D("FUNCTION_HOST_TIMEOUT","The host did not answer the run request."),sendError:z}).promise}onFunctionRunComplete(e,t,_){const E=g("functionwatch"),I=`${A.CUSTOM_FUNCTION_RUN_COMPLETE}:${E}`;let n=!1,a=null,i=null;const u=()=>{n=!0,a&&clearTimeout(a),i==null||i.cancel(),this._removeEventListener(I),this.activeWatches-=1,this.activeWatches===0&&Reflect.deleteProperty(l,this._id)},M=()=>{try{this._postMessage(s.CUSTOM_FUNCTION_STOP_WATCH,{id:this._id,runId:e,watchId:E,eventName:I})}catch{}},c=d=>{n||(u(),M(),b(_,d))},V=d=>{if(n)return;if(d!=null&&d.isError){u(),b(_,d);return}const S=d;if((S==null?void 0:S.RunId)!==e||Se.indexOf(S==null?void 0:S.Status)===-1){c(D("FUNCTION_WATCH_INVALID_EVENT","The host reported something other than a finished run."));return}u(),b(t,S)};return this.activeWatches+=1,l[this._id]=this,this._addEventListener(I,V),i=this._postMessageBounded(s.CUSTOM_FUNCTION_ON_RUN_COMPLETE,{id:this._id,runId:e,watchId:E,eventName:I},{timeoutMs:he,timeoutError:D("FUNCTION_HOST_UNSUPPORTED","The host did not start watching the run."),sendError:z}),i.promise.then(d=>{if(!n){if(d!==!0){c(D("FUNCTION_HOST_UNSUPPORTED","The host did not start watching the run."));return}a=setTimeout(()=>c(D("FUNCTION_OBSERVATION_STOPPED","Stopped checking the run; read it again later.")),Me)}},d=>c(d)),()=>{n||(u(),M())}}getDecisionTable(e){return new _e(e)}getAgent(e){return new Ie(e)}getDataform(e){return new de(e)}getBoard(e){return new Te(e)}getProcess(e){return new ce(e)}getRoles(){return this._postMessageAsync(s.GET_ROLES,{})}switchRole(e){return this._postMessageAsync(s.SWITCH_ROLE,{roleId:e.roleId,roleName:e.roleName})}}class ue extends O{constructor(){super()}api(e,t){return this._postMessageAsync(s.API,{url:e,args:t||{}})}initialize(){return globalThis.parent&&globalThis.parent===globalThis?Promise.reject("SDK can be initialized only inside the Kissflow platform."):this._postMessageAsync(s.CC_INITIALIZE,{},!0,e=>(this.app=new Re(e,!0),this.page=new X(e,!0),this.context=new te(e.componentId),this.client=new p,this.formatter=new ee,this.user=e.user,this.account=e.account,this.env=e.envDetails,this))}initialise(){return this.initialize()}}var le=new ue;return le});
|
package/dist/lowcode.d.ts
CHANGED
|
@@ -65,6 +65,10 @@ declare module "core/constants" {
|
|
|
65
65
|
CUSTOM_AGENT_GET_EXECUTION: string;
|
|
66
66
|
CUSTOM_AGENT_WATCH_EXECUTION: string;
|
|
67
67
|
CUSTOM_AGENT_STOP_WATCH: string;
|
|
68
|
+
CUSTOM_FUNCTION_RUN: string;
|
|
69
|
+
CUSTOM_FUNCTION_GET_RUN: string;
|
|
70
|
+
CUSTOM_FUNCTION_ON_RUN_COMPLETE: string;
|
|
71
|
+
CUSTOM_FUNCTION_STOP_WATCH: string;
|
|
68
72
|
DECISION_TABLE_EXECUTE: string;
|
|
69
73
|
DATAFORM_IMPORT_CSV: string;
|
|
70
74
|
DATAFORM_OPEN_FORM: string;
|
|
@@ -123,6 +127,7 @@ declare module "core/constants" {
|
|
|
123
127
|
CC_ON_PARAMS_CHANGE: string;
|
|
124
128
|
CC_ON_ROUTE_CHANGE: string;
|
|
125
129
|
CUSTOM_AGENT_EXECUTION_COMPLETE: string;
|
|
130
|
+
CUSTOM_FUNCTION_RUN_COMPLETE: string;
|
|
126
131
|
};
|
|
127
132
|
export const DEFAULTS: {
|
|
128
133
|
POPUP_ID: string;
|
|
@@ -459,6 +464,37 @@ declare module "types/external" {
|
|
|
459
464
|
tableId?: string;
|
|
460
465
|
tableRowId?: string;
|
|
461
466
|
};
|
|
467
|
+
/** The terminal states a Custom Function run ends in, plus the two it passes through. */
|
|
468
|
+
export type RunStatus = "Queued" | "Running" | "Success" | "Failed" | "TimedOut";
|
|
469
|
+
/**
|
|
470
|
+
* What a Custom Function run looks like from the SDK.
|
|
471
|
+
*
|
|
472
|
+
* An Interactive function resolves with the terminal envelope directly. A
|
|
473
|
+
* Background function resolves with `Queued` and only `RunId`; fetch the rest
|
|
474
|
+
* with `getFunctionRun`, or wait for it with `onFunctionRunComplete`.
|
|
475
|
+
*/
|
|
476
|
+
export type RunEnvelope = {
|
|
477
|
+
RunId: string;
|
|
478
|
+
Status: RunStatus;
|
|
479
|
+
/** Whatever the function returned. Only constrained when its output contract names properties. */
|
|
480
|
+
Result?: unknown;
|
|
481
|
+
Error?: {
|
|
482
|
+
Code?: string;
|
|
483
|
+
Message: string;
|
|
484
|
+
};
|
|
485
|
+
};
|
|
486
|
+
/**
|
|
487
|
+
* How a Custom Function call fails: `error` is the message text and `errorCode` either the platform
|
|
488
|
+
* code (`KISSFLOW_ERROR_…`) or a `FUNCTION_…` code, including `FUNCTION_HOST_TIMEOUT`,
|
|
489
|
+
* `FUNCTION_REQUEST_NOT_SENT`, `FUNCTION_RUN_OUTCOME_UNKNOWN` (a run may have started),
|
|
490
|
+
* `FUNCTION_RUN_NOT_SENT` (no run started), `FUNCTION_HOST_UNSUPPORTED`, `FUNCTION_WATCH_INVALID_EVENT`
|
|
491
|
+
* and `FUNCTION_OBSERVATION_STOPPED`. The list may grow; fall back to `error` for an unknown code.
|
|
492
|
+
*/
|
|
493
|
+
export type RunWatchError = {
|
|
494
|
+
isError: true;
|
|
495
|
+
error?: string;
|
|
496
|
+
errorCode?: string;
|
|
497
|
+
};
|
|
462
498
|
export type AgentInputDataType = "Text" | "Number" | "Boolean" | "Attachment";
|
|
463
499
|
export type AgentOutputDataType = "string" | "number" | "boolean";
|
|
464
500
|
export type AgentInputField = {
|
|
@@ -1454,7 +1490,7 @@ declare module "app/index" {
|
|
|
1454
1490
|
import { BaseSDK } from "core/index";
|
|
1455
1491
|
import { Page } from "app/page";
|
|
1456
1492
|
import { AppContext } from "types/internal";
|
|
1457
|
-
import { rolesObject } from "types/external";
|
|
1493
|
+
import { rolesObject, RunEnvelope, RunWatchError } from "types/external";
|
|
1458
1494
|
import { DecisionTable } from "app/decisiontable";
|
|
1459
1495
|
import { Agent } from "app/agent";
|
|
1460
1496
|
import { Dataform } from "dataform/index";
|
|
@@ -1463,10 +1499,64 @@ declare module "app/index" {
|
|
|
1463
1499
|
export class Application extends BaseSDK {
|
|
1464
1500
|
page: Page;
|
|
1465
1501
|
_id: string;
|
|
1502
|
+
private activeWatches;
|
|
1466
1503
|
constructor(props: AppContext, isCustomComponent?: boolean);
|
|
1467
1504
|
getVariable(key: string): any;
|
|
1468
1505
|
setVariable(key: string | object, value?: any): any;
|
|
1469
1506
|
openPage(pageId: string, pageParams?: object): any;
|
|
1507
|
+
/**
|
|
1508
|
+
* Run a published Custom Function by name.
|
|
1509
|
+
*
|
|
1510
|
+
* An Interactive function resolves with its terminal envelope. A Background
|
|
1511
|
+
* function resolves as soon as it is queued, with `Status: "Queued"` and a
|
|
1512
|
+
* `RunId`; use {@link getFunctionRun} or {@link onFunctionRunComplete} for its result.
|
|
1513
|
+
*
|
|
1514
|
+
* A refused run rejects with the platform's SDK error shape: the message
|
|
1515
|
+
* text is in `error` and the code (`KISSFLOW_ERROR_…`) in `errorCode`.
|
|
1516
|
+
* A host that does not answer within 45 s rejects with
|
|
1517
|
+
* `FUNCTION_RUN_OUTCOME_UNKNOWN`: the run may still have started, so tell
|
|
1518
|
+
* the user instead of starting another.
|
|
1519
|
+
*
|
|
1520
|
+
* Custom Functions are application-scoped: this is reachable from page,
|
|
1521
|
+
* component and flow event scripts that run inside an application, where
|
|
1522
|
+
* `kf.app` exists. There is no `kf.app` outside one.
|
|
1523
|
+
*
|
|
1524
|
+
* @example
|
|
1525
|
+
* const run = await kf.app.runFunction("review_expense_claim", { claimId });
|
|
1526
|
+
*/
|
|
1527
|
+
runFunction(name: string, parameters?: Record<string, unknown>): Promise<RunEnvelope>;
|
|
1528
|
+
/**
|
|
1529
|
+
* Fetch a run's current state, including its `Result` once it has one.
|
|
1530
|
+
*
|
|
1531
|
+
* @example
|
|
1532
|
+
* const run = await kf.app.getFunctionRun(runId);
|
|
1533
|
+
* if (run.Status === "Success") use(run.Result);
|
|
1534
|
+
*/
|
|
1535
|
+
getFunctionRun(runId: string): Promise<RunEnvelope>;
|
|
1536
|
+
/**
|
|
1537
|
+
* Be told when a Background run reaches a terminal state.
|
|
1538
|
+
*
|
|
1539
|
+
* Fires `callBack` once with the run's envelope. "Complete" means the run
|
|
1540
|
+
* stopped, not that it worked: it fires on `Failed` and `TimedOut` just as
|
|
1541
|
+
* it does on `Success`, so read `Status` before trusting `Result`. If the
|
|
1542
|
+
* host cannot watch the run at all, `onError` is called instead of
|
|
1543
|
+
* `callBack` ever firing: an older host (`FUNCTION_HOST_UNSUPPORTED`), a
|
|
1544
|
+
* refusal, or the watch limit (`FUNCTION_OBSERVATION_STOPPED`, after about
|
|
1545
|
+
* ten minutes; the run may still finish, so read it later with
|
|
1546
|
+
* {@link getFunctionRun}). At most one of the two is called, at most once.
|
|
1547
|
+
*
|
|
1548
|
+
* Returns a function that unsubscribes. The callback lives only as long as
|
|
1549
|
+
* the script that registered it: form events end their script after 60 s
|
|
1550
|
+
* and a page event ends the previous one when it fires again, while a
|
|
1551
|
+
* Background run may take up to 600 s. Prefer polling {@link getFunctionRun} from a
|
|
1552
|
+
* script that outlives the run, or re-attach after the script restarts.
|
|
1553
|
+
*
|
|
1554
|
+
* @example
|
|
1555
|
+
* const stop = kf.app.onFunctionRunComplete(run.RunId, (done) => show(done), (err) => warn(err));
|
|
1556
|
+
* // later, e.g. on unmount — the host stops watching the run too
|
|
1557
|
+
* stop();
|
|
1558
|
+
*/
|
|
1559
|
+
onFunctionRunComplete(runId: string, callBack: (run: RunEnvelope) => void, onError?: (error: RunWatchError) => void): () => void;
|
|
1470
1560
|
getDecisionTable(flowId: string): DecisionTable;
|
|
1471
1561
|
/**
|
|
1472
1562
|
* Get a published Custom Agent of this app by its id. The handle sends no request until you call one
|
package/dist/lowcode.types.d.ts
CHANGED
|
@@ -752,6 +752,59 @@ declare class Application {
|
|
|
752
752
|
getVariable(key: string): any;
|
|
753
753
|
setVariable(key: string | object, value?: any): any;
|
|
754
754
|
openPage(pageId: string, pageParams?: object): any;
|
|
755
|
+
/**
|
|
756
|
+
* Run a published Custom Function by name.
|
|
757
|
+
*
|
|
758
|
+
* An Interactive function resolves with its terminal envelope. A Background
|
|
759
|
+
* function resolves as soon as it is queued, with `Status: "Queued"` and a
|
|
760
|
+
* `RunId`; use {@link getFunctionRun} or {@link onFunctionRunComplete} for its result.
|
|
761
|
+
*
|
|
762
|
+
* A refused run rejects with the platform's SDK error shape: the message
|
|
763
|
+
* text is in `error` and the code (`KISSFLOW_ERROR_…`) in `errorCode`.
|
|
764
|
+
* A host that does not answer within 45 s rejects with
|
|
765
|
+
* `FUNCTION_RUN_OUTCOME_UNKNOWN`: the run may still have started, so tell
|
|
766
|
+
* the user instead of starting another.
|
|
767
|
+
*
|
|
768
|
+
* Custom Functions are application-scoped: this is reachable from page,
|
|
769
|
+
* component and flow event scripts that run inside an application, where
|
|
770
|
+
* `kf.app` exists. There is no `kf.app` outside one.
|
|
771
|
+
*
|
|
772
|
+
* @example
|
|
773
|
+
* const run = await kf.app.runFunction("review_expense_claim", { claimId });
|
|
774
|
+
*/
|
|
775
|
+
runFunction(name: string, parameters?: Record<string, unknown>): Promise<RunEnvelope>;
|
|
776
|
+
/**
|
|
777
|
+
* Fetch a run's current state, including its `Result` once it has one.
|
|
778
|
+
*
|
|
779
|
+
* @example
|
|
780
|
+
* const run = await kf.app.getFunctionRun(runId);
|
|
781
|
+
* if (run.Status === "Success") use(run.Result);
|
|
782
|
+
*/
|
|
783
|
+
getFunctionRun(runId: string): Promise<RunEnvelope>;
|
|
784
|
+
/**
|
|
785
|
+
* Be told when a Background run reaches a terminal state.
|
|
786
|
+
*
|
|
787
|
+
* Fires `callBack` once with the run's envelope. "Complete" means the run
|
|
788
|
+
* stopped, not that it worked: it fires on `Failed` and `TimedOut` just as
|
|
789
|
+
* it does on `Success`, so read `Status` before trusting `Result`. If the
|
|
790
|
+
* host cannot watch the run at all, `onError` is called instead of
|
|
791
|
+
* `callBack` ever firing: an older host (`FUNCTION_HOST_UNSUPPORTED`), a
|
|
792
|
+
* refusal, or the watch limit (`FUNCTION_OBSERVATION_STOPPED`, after about
|
|
793
|
+
* ten minutes; the run may still finish, so read it later with
|
|
794
|
+
* {@link getFunctionRun}). At most one of the two is called, at most once.
|
|
795
|
+
*
|
|
796
|
+
* Returns a function that unsubscribes. The callback lives only as long as
|
|
797
|
+
* the script that registered it: form events end their script after 60 s
|
|
798
|
+
* and a page event ends the previous one when it fires again, while a
|
|
799
|
+
* Background run may take up to 600 s. Prefer polling {@link getFunctionRun} from a
|
|
800
|
+
* script that outlives the run, or re-attach after the script restarts.
|
|
801
|
+
*
|
|
802
|
+
* @example
|
|
803
|
+
* const stop = kf.app.onFunctionRunComplete(run.RunId, (done) => show(done), (err) => warn(err));
|
|
804
|
+
* // later, e.g. on unmount — the host stops watching the run too
|
|
805
|
+
* stop();
|
|
806
|
+
*/
|
|
807
|
+
onFunctionRunComplete(runId: string, callBack: (run: RunEnvelope) => void, onError?: (error: RunWatchError) => void): () => void;
|
|
755
808
|
getDecisionTable(flowId: string): DecisionTable;
|
|
756
809
|
/**
|
|
757
810
|
* Get a published Custom Agent of this app by its id. The handle sends no request until you call one
|
|
@@ -1151,6 +1204,33 @@ declare type BoardFieldOptions = {
|
|
|
1151
1204
|
tableRowId?: string;
|
|
1152
1205
|
};
|
|
1153
1206
|
|
|
1207
|
+
/** The terminal states a Custom Function run ends in, plus the two it passes through. */
|
|
1208
|
+
declare type RunStatus = "Queued" | "Running" | "Success" | "Failed" | "TimedOut";
|
|
1209
|
+
|
|
1210
|
+
/**
|
|
1211
|
+
* What a Custom Function run looks like from the SDK.
|
|
1212
|
+
*
|
|
1213
|
+
* An Interactive function resolves with the terminal envelope directly. A
|
|
1214
|
+
* Background function resolves with `Queued` and only `RunId`; fetch the rest
|
|
1215
|
+
* with `getFunctionRun`, or wait for it with `onFunctionRunComplete`.
|
|
1216
|
+
*/
|
|
1217
|
+
declare type RunEnvelope = {
|
|
1218
|
+
RunId: string;
|
|
1219
|
+
Status: RunStatus;
|
|
1220
|
+
/** Whatever the function returned. Only constrained when its output contract names properties. */
|
|
1221
|
+
Result?: unknown;
|
|
1222
|
+
Error?: { Code?: string; Message: string };
|
|
1223
|
+
};
|
|
1224
|
+
|
|
1225
|
+
/**
|
|
1226
|
+
* How a Custom Function call fails: `error` is the message text and `errorCode` either the platform
|
|
1227
|
+
* code (`KISSFLOW_ERROR_…`) or a `FUNCTION_…` code, including `FUNCTION_HOST_TIMEOUT`,
|
|
1228
|
+
* `FUNCTION_REQUEST_NOT_SENT`, `FUNCTION_RUN_OUTCOME_UNKNOWN` (a run may have started),
|
|
1229
|
+
* `FUNCTION_RUN_NOT_SENT` (no run started), `FUNCTION_HOST_UNSUPPORTED`, `FUNCTION_WATCH_INVALID_EVENT`
|
|
1230
|
+
* and `FUNCTION_OBSERVATION_STOPPED`. The list may grow; fall back to `error` for an unknown code.
|
|
1231
|
+
*/
|
|
1232
|
+
declare type RunWatchError = { isError: true; error?: string; errorCode?: string };
|
|
1233
|
+
|
|
1154
1234
|
// ============================================
|
|
1155
1235
|
// Custom Agent Types
|
|
1156
1236
|
// ============================================
|
package/dist/nocode.d.ts
CHANGED
|
@@ -65,6 +65,10 @@ declare module "core/constants" {
|
|
|
65
65
|
CUSTOM_AGENT_GET_EXECUTION: string;
|
|
66
66
|
CUSTOM_AGENT_WATCH_EXECUTION: string;
|
|
67
67
|
CUSTOM_AGENT_STOP_WATCH: string;
|
|
68
|
+
CUSTOM_FUNCTION_RUN: string;
|
|
69
|
+
CUSTOM_FUNCTION_GET_RUN: string;
|
|
70
|
+
CUSTOM_FUNCTION_ON_RUN_COMPLETE: string;
|
|
71
|
+
CUSTOM_FUNCTION_STOP_WATCH: string;
|
|
68
72
|
DECISION_TABLE_EXECUTE: string;
|
|
69
73
|
DATAFORM_IMPORT_CSV: string;
|
|
70
74
|
DATAFORM_OPEN_FORM: string;
|
|
@@ -123,6 +127,7 @@ declare module "core/constants" {
|
|
|
123
127
|
CC_ON_PARAMS_CHANGE: string;
|
|
124
128
|
CC_ON_ROUTE_CHANGE: string;
|
|
125
129
|
CUSTOM_AGENT_EXECUTION_COMPLETE: string;
|
|
130
|
+
CUSTOM_FUNCTION_RUN_COMPLETE: string;
|
|
126
131
|
};
|
|
127
132
|
export const DEFAULTS: {
|
|
128
133
|
POPUP_ID: string;
|
|
@@ -459,6 +464,37 @@ declare module "types/external" {
|
|
|
459
464
|
tableId?: string;
|
|
460
465
|
tableRowId?: string;
|
|
461
466
|
};
|
|
467
|
+
/** The terminal states a Custom Function run ends in, plus the two it passes through. */
|
|
468
|
+
export type RunStatus = "Queued" | "Running" | "Success" | "Failed" | "TimedOut";
|
|
469
|
+
/**
|
|
470
|
+
* What a Custom Function run looks like from the SDK.
|
|
471
|
+
*
|
|
472
|
+
* An Interactive function resolves with the terminal envelope directly. A
|
|
473
|
+
* Background function resolves with `Queued` and only `RunId`; fetch the rest
|
|
474
|
+
* with `getFunctionRun`, or wait for it with `onFunctionRunComplete`.
|
|
475
|
+
*/
|
|
476
|
+
export type RunEnvelope = {
|
|
477
|
+
RunId: string;
|
|
478
|
+
Status: RunStatus;
|
|
479
|
+
/** Whatever the function returned. Only constrained when its output contract names properties. */
|
|
480
|
+
Result?: unknown;
|
|
481
|
+
Error?: {
|
|
482
|
+
Code?: string;
|
|
483
|
+
Message: string;
|
|
484
|
+
};
|
|
485
|
+
};
|
|
486
|
+
/**
|
|
487
|
+
* How a Custom Function call fails: `error` is the message text and `errorCode` either the platform
|
|
488
|
+
* code (`KISSFLOW_ERROR_…`) or a `FUNCTION_…` code, including `FUNCTION_HOST_TIMEOUT`,
|
|
489
|
+
* `FUNCTION_REQUEST_NOT_SENT`, `FUNCTION_RUN_OUTCOME_UNKNOWN` (a run may have started),
|
|
490
|
+
* `FUNCTION_RUN_NOT_SENT` (no run started), `FUNCTION_HOST_UNSUPPORTED`, `FUNCTION_WATCH_INVALID_EVENT`
|
|
491
|
+
* and `FUNCTION_OBSERVATION_STOPPED`. The list may grow; fall back to `error` for an unknown code.
|
|
492
|
+
*/
|
|
493
|
+
export type RunWatchError = {
|
|
494
|
+
isError: true;
|
|
495
|
+
error?: string;
|
|
496
|
+
errorCode?: string;
|
|
497
|
+
};
|
|
462
498
|
export type AgentInputDataType = "Text" | "Number" | "Boolean" | "Attachment";
|
|
463
499
|
export type AgentOutputDataType = "string" | "number" | "boolean";
|
|
464
500
|
export type AgentInputField = {
|
|
@@ -1493,7 +1529,7 @@ declare module "app/index" {
|
|
|
1493
1529
|
import { BaseSDK } from "core/index";
|
|
1494
1530
|
import { Page } from "app/page";
|
|
1495
1531
|
import { AppContext } from "types/internal";
|
|
1496
|
-
import { rolesObject } from "types/external";
|
|
1532
|
+
import { rolesObject, RunEnvelope, RunWatchError } from "types/external";
|
|
1497
1533
|
import { DecisionTable } from "app/decisiontable";
|
|
1498
1534
|
import { Agent } from "app/agent";
|
|
1499
1535
|
import { Dataform } from "dataform/index";
|
|
@@ -1502,10 +1538,64 @@ declare module "app/index" {
|
|
|
1502
1538
|
export class Application extends BaseSDK {
|
|
1503
1539
|
page: Page;
|
|
1504
1540
|
_id: string;
|
|
1541
|
+
private activeWatches;
|
|
1505
1542
|
constructor(props: AppContext, isCustomComponent?: boolean);
|
|
1506
1543
|
getVariable(key: string): any;
|
|
1507
1544
|
setVariable(key: string | object, value?: any): any;
|
|
1508
1545
|
openPage(pageId: string, pageParams?: object): any;
|
|
1546
|
+
/**
|
|
1547
|
+
* Run a published Custom Function by name.
|
|
1548
|
+
*
|
|
1549
|
+
* An Interactive function resolves with its terminal envelope. A Background
|
|
1550
|
+
* function resolves as soon as it is queued, with `Status: "Queued"` and a
|
|
1551
|
+
* `RunId`; use {@link getFunctionRun} or {@link onFunctionRunComplete} for its result.
|
|
1552
|
+
*
|
|
1553
|
+
* A refused run rejects with the platform's SDK error shape: the message
|
|
1554
|
+
* text is in `error` and the code (`KISSFLOW_ERROR_…`) in `errorCode`.
|
|
1555
|
+
* A host that does not answer within 45 s rejects with
|
|
1556
|
+
* `FUNCTION_RUN_OUTCOME_UNKNOWN`: the run may still have started, so tell
|
|
1557
|
+
* the user instead of starting another.
|
|
1558
|
+
*
|
|
1559
|
+
* Custom Functions are application-scoped: this is reachable from page,
|
|
1560
|
+
* component and flow event scripts that run inside an application, where
|
|
1561
|
+
* `kf.app` exists. There is no `kf.app` outside one.
|
|
1562
|
+
*
|
|
1563
|
+
* @example
|
|
1564
|
+
* const run = await kf.app.runFunction("review_expense_claim", { claimId });
|
|
1565
|
+
*/
|
|
1566
|
+
runFunction(name: string, parameters?: Record<string, unknown>): Promise<RunEnvelope>;
|
|
1567
|
+
/**
|
|
1568
|
+
* Fetch a run's current state, including its `Result` once it has one.
|
|
1569
|
+
*
|
|
1570
|
+
* @example
|
|
1571
|
+
* const run = await kf.app.getFunctionRun(runId);
|
|
1572
|
+
* if (run.Status === "Success") use(run.Result);
|
|
1573
|
+
*/
|
|
1574
|
+
getFunctionRun(runId: string): Promise<RunEnvelope>;
|
|
1575
|
+
/**
|
|
1576
|
+
* Be told when a Background run reaches a terminal state.
|
|
1577
|
+
*
|
|
1578
|
+
* Fires `callBack` once with the run's envelope. "Complete" means the run
|
|
1579
|
+
* stopped, not that it worked: it fires on `Failed` and `TimedOut` just as
|
|
1580
|
+
* it does on `Success`, so read `Status` before trusting `Result`. If the
|
|
1581
|
+
* host cannot watch the run at all, `onError` is called instead of
|
|
1582
|
+
* `callBack` ever firing: an older host (`FUNCTION_HOST_UNSUPPORTED`), a
|
|
1583
|
+
* refusal, or the watch limit (`FUNCTION_OBSERVATION_STOPPED`, after about
|
|
1584
|
+
* ten minutes; the run may still finish, so read it later with
|
|
1585
|
+
* {@link getFunctionRun}). At most one of the two is called, at most once.
|
|
1586
|
+
*
|
|
1587
|
+
* Returns a function that unsubscribes. The callback lives only as long as
|
|
1588
|
+
* the script that registered it: form events end their script after 60 s
|
|
1589
|
+
* and a page event ends the previous one when it fires again, while a
|
|
1590
|
+
* Background run may take up to 600 s. Prefer polling {@link getFunctionRun} from a
|
|
1591
|
+
* script that outlives the run, or re-attach after the script restarts.
|
|
1592
|
+
*
|
|
1593
|
+
* @example
|
|
1594
|
+
* const stop = kf.app.onFunctionRunComplete(run.RunId, (done) => show(done), (err) => warn(err));
|
|
1595
|
+
* // later, e.g. on unmount — the host stops watching the run too
|
|
1596
|
+
* stop();
|
|
1597
|
+
*/
|
|
1598
|
+
onFunctionRunComplete(runId: string, callBack: (run: RunEnvelope) => void, onError?: (error: RunWatchError) => void): () => void;
|
|
1509
1599
|
getDecisionTable(flowId: string): DecisionTable;
|
|
1510
1600
|
/**
|
|
1511
1601
|
* Get a published Custom Agent of this app by its id. The handle sends no request until you call one
|
package/dist/nocode.types.d.ts
CHANGED
|
@@ -561,6 +561,33 @@ declare type BoardFieldOptions = {
|
|
|
561
561
|
tableRowId?: string;
|
|
562
562
|
};
|
|
563
563
|
|
|
564
|
+
/** The terminal states a Custom Function run ends in, plus the two it passes through. */
|
|
565
|
+
declare type RunStatus = "Queued" | "Running" | "Success" | "Failed" | "TimedOut";
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* What a Custom Function run looks like from the SDK.
|
|
569
|
+
*
|
|
570
|
+
* An Interactive function resolves with the terminal envelope directly. A
|
|
571
|
+
* Background function resolves with `Queued` and only `RunId`; fetch the rest
|
|
572
|
+
* with `getFunctionRun`, or wait for it with `onFunctionRunComplete`.
|
|
573
|
+
*/
|
|
574
|
+
declare type RunEnvelope = {
|
|
575
|
+
RunId: string;
|
|
576
|
+
Status: RunStatus;
|
|
577
|
+
/** Whatever the function returned. Only constrained when its output contract names properties. */
|
|
578
|
+
Result?: unknown;
|
|
579
|
+
Error?: { Code?: string; Message: string };
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* How a Custom Function call fails: `error` is the message text and `errorCode` either the platform
|
|
584
|
+
* code (`KISSFLOW_ERROR_…`) or a `FUNCTION_…` code, including `FUNCTION_HOST_TIMEOUT`,
|
|
585
|
+
* `FUNCTION_REQUEST_NOT_SENT`, `FUNCTION_RUN_OUTCOME_UNKNOWN` (a run may have started),
|
|
586
|
+
* `FUNCTION_RUN_NOT_SENT` (no run started), `FUNCTION_HOST_UNSUPPORTED`, `FUNCTION_WATCH_INVALID_EVENT`
|
|
587
|
+
* and `FUNCTION_OBSERVATION_STOPPED`. The list may grow; fall back to `error` for an unknown code.
|
|
588
|
+
*/
|
|
589
|
+
declare type RunWatchError = { isError: true; error?: string; errorCode?: string };
|
|
590
|
+
|
|
564
591
|
// ============================================
|
|
565
592
|
// Custom Agent Types
|
|
566
593
|
// ============================================
|
package/dist/snippets.json
CHANGED
|
@@ -20,6 +20,21 @@
|
|
|
20
20
|
"documentation": "Evaluates the provided data and returns back the matched output",
|
|
21
21
|
"insertText": "let decisionTableInstance = kf.app.getDecisionTable(\"${1:flowId}\");\n let decisionOutput = await decisionTableInstance.evaluate({ conditionField1: \"value\", conditionField2: \"value\" });"
|
|
22
22
|
},
|
|
23
|
+
{
|
|
24
|
+
"label": "run custom function",
|
|
25
|
+
"documentation": "Run a Custom Function; a Background function returns only RunId and Status: \"Queued\"",
|
|
26
|
+
"insertText": "let run = await kf.app.runFunction(\"${1:functionName}\", { ${2:key}: \"${3:value}\" });"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"label": "get custom function run",
|
|
30
|
+
"documentation": "Fetch a Custom Function run's status, and its Result once it has one",
|
|
31
|
+
"insertText": "let run = await kf.app.getFunctionRun(\"${1:runId}\");"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"label": "on custom function run complete",
|
|
35
|
+
"documentation": "Called once when a Background run reaches Success, Failed or TimedOut; the returned function unsubscribes",
|
|
36
|
+
"insertText": "let stop = kf.app.onFunctionRunComplete(\"${1:runId}\", (run) => {\n\t${2:// run.Status, run.Result}\n}, (err) => {\n\t${3:// err.error}\n});"
|
|
37
|
+
},
|
|
23
38
|
{
|
|
24
39
|
"label": "run custom agent",
|
|
25
40
|
"documentation": "Runs a published Custom Agent of this app and handles its result when it finishes",
|
|
@@ -195,4 +210,4 @@
|
|
|
195
210
|
"insertText": "let payload = {}:\nkf.api(`/process/2/${kf.account._id}/${1:processId}/`, {\n\tmethod: \"POST\",\n\tbody: JSON.stringify(payload)\n})\n.then((resp) => {${2}})\n.catch((err) => {${3}})"
|
|
196
211
|
}
|
|
197
212
|
]
|
|
198
|
-
}
|
|
213
|
+
}
|