@kissflow/lowcode-client-sdk 1.0.52 → 1.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +202 -153
- package/dist/kf.lowcodeworkersdk.es.js +231 -262
- package/dist/kf.nocodeworkersdk.es.js +761 -0
- package/dist/kfsdk.es.js +295 -246
- package/dist/kfsdk.umd.js +1 -1
- package/dist/lowcode.d.ts +200 -151
- package/dist/lowcode.types.d.ts +74 -136
- package/dist/nocode.d.ts +139 -90
- package/dist/nocode.types.d.ts +8 -9
- package/package.json +1 -1
|
@@ -423,45 +423,26 @@ class Form extends BaseSDK {
|
|
|
423
423
|
data: args
|
|
424
424
|
});
|
|
425
425
|
}
|
|
426
|
-
getValidationErrors() {
|
|
427
|
-
return this._postMessageAsync(
|
|
428
|
-
LISTENER_CMDS.GET_FORM_VALIDATION_ERRORS,
|
|
429
|
-
{
|
|
430
|
-
storeId: this.storeId,
|
|
431
|
-
instanceId: this.instanceId
|
|
432
|
-
}
|
|
433
|
-
);
|
|
434
|
-
}
|
|
435
|
-
getFormConfiguration() {
|
|
436
|
-
return this._postMessageAsync(LISTENER_CMDS.GET_FORM_CONFIGURATION, {
|
|
437
|
-
storeId: this.storeId,
|
|
438
|
-
instanceId: this.instanceId
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
getFieldState() {
|
|
442
|
-
return this._postMessageAsync(LISTENER_CMDS.GET_FORM_FIELD_STATE, {
|
|
443
|
-
storeId: this.storeId,
|
|
444
|
-
instanceId: this.instanceId
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
426
|
getTable(tableId) {
|
|
448
427
|
return new Table(
|
|
449
428
|
this.storeId,
|
|
450
429
|
this.flowId,
|
|
451
430
|
this.instanceId,
|
|
452
431
|
tableId,
|
|
453
|
-
this.activityInstanceId
|
|
432
|
+
this.activityInstanceId,
|
|
433
|
+
this
|
|
454
434
|
);
|
|
455
435
|
}
|
|
456
436
|
}
|
|
457
437
|
class Table extends BaseSDK {
|
|
458
|
-
constructor(storeId, flowId, instanceId, tableId, activityInstanceId) {
|
|
438
|
+
constructor(storeId, flowId, instanceId, tableId, activityInstanceId, parent) {
|
|
459
439
|
super();
|
|
460
440
|
this.tableId = tableId;
|
|
461
441
|
this.storeId = storeId;
|
|
462
442
|
this.flowId = flowId;
|
|
463
443
|
this.instanceId = instanceId;
|
|
464
444
|
this.activityInstanceId = activityInstanceId;
|
|
445
|
+
this.parent = parent;
|
|
465
446
|
}
|
|
466
447
|
toJSON() {
|
|
467
448
|
return this._postMessageAsync(LISTENER_CMDS.TO_JSON, {
|
|
@@ -494,7 +475,8 @@ class Table extends BaseSDK {
|
|
|
494
475
|
this.instanceId,
|
|
495
476
|
this.tableId,
|
|
496
477
|
row.id,
|
|
497
|
-
this.activityInstanceId
|
|
478
|
+
this.activityInstanceId,
|
|
479
|
+
this.parent
|
|
498
480
|
)
|
|
499
481
|
);
|
|
500
482
|
}
|
|
@@ -507,7 +489,8 @@ class Table extends BaseSDK {
|
|
|
507
489
|
this.instanceId,
|
|
508
490
|
this.tableId,
|
|
509
491
|
rowId,
|
|
510
|
-
this.activityInstanceId
|
|
492
|
+
this.activityInstanceId,
|
|
493
|
+
this.parent
|
|
511
494
|
);
|
|
512
495
|
}
|
|
513
496
|
addRow(rowObject) {
|
|
@@ -544,7 +527,7 @@ class Table extends BaseSDK {
|
|
|
544
527
|
}
|
|
545
528
|
}
|
|
546
529
|
class TableForm extends BaseSDK {
|
|
547
|
-
constructor(storeId, flowId, instanceId, tableId, rowId, activityInstanceId) {
|
|
530
|
+
constructor(storeId, flowId, instanceId, tableId, rowId, activityInstanceId, parent) {
|
|
548
531
|
super();
|
|
549
532
|
this.storeId = storeId;
|
|
550
533
|
this.flowId = flowId;
|
|
@@ -553,8 +536,11 @@ class TableForm extends BaseSDK {
|
|
|
553
536
|
this.tableId = tableId;
|
|
554
537
|
this.rowId = rowId;
|
|
555
538
|
this.activityInstanceId = activityInstanceId;
|
|
539
|
+
this.parent = parent;
|
|
556
540
|
}
|
|
557
541
|
getParent() {
|
|
542
|
+
if (this.parent)
|
|
543
|
+
return this.parent;
|
|
558
544
|
return new Form(
|
|
559
545
|
this.storeId,
|
|
560
546
|
this.flowId,
|
|
@@ -839,187 +825,6 @@ class DecisionTable extends BaseSDK {
|
|
|
839
825
|
});
|
|
840
826
|
}
|
|
841
827
|
}
|
|
842
|
-
const READ_TIMEOUT_MS$1 = 75e3;
|
|
843
|
-
const EXECUTE_TIMEOUT_MS = 6e4;
|
|
844
|
-
const WATCH_ACK_TIMEOUT_MS$1 = 6e4;
|
|
845
|
-
const WATCH_DEADLINE_MS$1 = 42e4;
|
|
846
|
-
const TERMINAL_STATUSES$1 = ["Completed", "Failed"];
|
|
847
|
-
function sdkError$1(errorCode, error) {
|
|
848
|
-
return { isError: true, error, errorCode };
|
|
849
|
-
}
|
|
850
|
-
function notify$1(callback, value) {
|
|
851
|
-
try {
|
|
852
|
-
callback == null ? void 0 : callback(value);
|
|
853
|
-
} catch (error) {
|
|
854
|
-
console.error(error);
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
const NOT_SENT$1 = sdkError$1("AGENT_REQUEST_NOT_SENT", "The request could not be sent to the host.");
|
|
858
|
-
class Agent extends BaseSDK {
|
|
859
|
-
constructor(agentId) {
|
|
860
|
-
super();
|
|
861
|
-
this.activeWatches = 0;
|
|
862
|
-
this.agentId = agentId;
|
|
863
|
-
this._id = generateId("customagent");
|
|
864
|
-
}
|
|
865
|
-
getContract() {
|
|
866
|
-
return this._postMessageBounded(
|
|
867
|
-
LISTENER_CMDS.CUSTOM_AGENT_GET_CONTRACT,
|
|
868
|
-
{ agentId: this.agentId },
|
|
869
|
-
{
|
|
870
|
-
timeoutMs: READ_TIMEOUT_MS$1,
|
|
871
|
-
timeoutError: sdkError$1("AGENT_HOST_TIMEOUT", "The host did not answer the Agent contract request."),
|
|
872
|
-
sendError: NOT_SENT$1
|
|
873
|
-
}
|
|
874
|
-
).promise;
|
|
875
|
-
}
|
|
876
|
-
execute(options) {
|
|
877
|
-
var _a;
|
|
878
|
-
return this._postMessageBounded(
|
|
879
|
-
LISTENER_CMDS.CUSTOM_AGENT_EXECUTE,
|
|
880
|
-
{ agentId: this.agentId, inputData: (_a = options == null ? void 0 : options.inputData) != null ? _a : {} },
|
|
881
|
-
{
|
|
882
|
-
timeoutMs: EXECUTE_TIMEOUT_MS,
|
|
883
|
-
timeoutError: sdkError$1(
|
|
884
|
-
"AGENT_EXECUTE_OUTCOME_UNKNOWN",
|
|
885
|
-
"The host did not confirm the run; it may still have started."
|
|
886
|
-
),
|
|
887
|
-
sendError: sdkError$1("AGENT_EXECUTE_NOT_SENT", "The run request could not be sent to the host.")
|
|
888
|
-
}
|
|
889
|
-
).promise;
|
|
890
|
-
}
|
|
891
|
-
getExecution(executionId) {
|
|
892
|
-
return this._postMessageBounded(
|
|
893
|
-
LISTENER_CMDS.CUSTOM_AGENT_GET_EXECUTION,
|
|
894
|
-
{ agentId: this.agentId, executionId },
|
|
895
|
-
{
|
|
896
|
-
timeoutMs: READ_TIMEOUT_MS$1,
|
|
897
|
-
timeoutError: sdkError$1("AGENT_HOST_TIMEOUT", "The host did not answer the Agent execution request."),
|
|
898
|
-
sendError: NOT_SENT$1
|
|
899
|
-
}
|
|
900
|
-
).promise;
|
|
901
|
-
}
|
|
902
|
-
onExecutionComplete(executionId, onComplete, onWatchError) {
|
|
903
|
-
const watchId = generateId("agentwatch");
|
|
904
|
-
const eventName = `${EVENT_TYPES.CUSTOM_AGENT_EXECUTION_COMPLETE}:${watchId}`;
|
|
905
|
-
let settled = false;
|
|
906
|
-
let deadline = null;
|
|
907
|
-
let registration = null;
|
|
908
|
-
const end = () => {
|
|
909
|
-
settled = true;
|
|
910
|
-
if (deadline)
|
|
911
|
-
clearTimeout(deadline);
|
|
912
|
-
registration == null ? void 0 : registration.cancel();
|
|
913
|
-
this._removeEventListener(eventName);
|
|
914
|
-
this.activeWatches -= 1;
|
|
915
|
-
if (this.activeWatches === 0)
|
|
916
|
-
Reflect.deleteProperty(globalInstances, this._id);
|
|
917
|
-
};
|
|
918
|
-
const tellHostToStop = () => {
|
|
919
|
-
try {
|
|
920
|
-
this._postMessage(LISTENER_CMDS.CUSTOM_AGENT_STOP_WATCH, { id: this._id, watchId, eventName });
|
|
921
|
-
} catch {
|
|
922
|
-
}
|
|
923
|
-
};
|
|
924
|
-
const fail = (error) => {
|
|
925
|
-
if (settled)
|
|
926
|
-
return;
|
|
927
|
-
end();
|
|
928
|
-
tellHostToStop();
|
|
929
|
-
notify$1(onWatchError, error);
|
|
930
|
-
};
|
|
931
|
-
const listener = (params) => {
|
|
932
|
-
if (settled)
|
|
933
|
-
return;
|
|
934
|
-
if (params == null ? void 0 : params.isError) {
|
|
935
|
-
end();
|
|
936
|
-
notify$1(onWatchError, params);
|
|
937
|
-
return;
|
|
938
|
-
}
|
|
939
|
-
const execution = params;
|
|
940
|
-
if ((execution == null ? void 0 : execution.ExecutionId) !== executionId || TERMINAL_STATUSES$1.indexOf(execution == null ? void 0 : execution.Status) === -1) {
|
|
941
|
-
fail(sdkError$1("AGENT_WATCH_INVALID_EVENT", "The host reported something other than a finished run."));
|
|
942
|
-
return;
|
|
943
|
-
}
|
|
944
|
-
end();
|
|
945
|
-
notify$1(onComplete, execution);
|
|
946
|
-
};
|
|
947
|
-
this.activeWatches += 1;
|
|
948
|
-
globalInstances[this._id] = this;
|
|
949
|
-
this._addEventListener(eventName, listener);
|
|
950
|
-
registration = this._postMessageBounded(
|
|
951
|
-
LISTENER_CMDS.CUSTOM_AGENT_WATCH_EXECUTION,
|
|
952
|
-
{ id: this._id, agentId: this.agentId, executionId, watchId, eventName },
|
|
953
|
-
{
|
|
954
|
-
timeoutMs: WATCH_ACK_TIMEOUT_MS$1,
|
|
955
|
-
timeoutError: sdkError$1("AGENT_HOST_UNSUPPORTED", "The host did not start observing the Agent run."),
|
|
956
|
-
sendError: NOT_SENT$1
|
|
957
|
-
}
|
|
958
|
-
);
|
|
959
|
-
registration.promise.then(
|
|
960
|
-
(acknowledged) => {
|
|
961
|
-
if (settled)
|
|
962
|
-
return;
|
|
963
|
-
if (acknowledged !== true) {
|
|
964
|
-
fail(sdkError$1("AGENT_HOST_UNSUPPORTED", "The host did not start observing the Agent run."));
|
|
965
|
-
return;
|
|
966
|
-
}
|
|
967
|
-
deadline = setTimeout(
|
|
968
|
-
() => fail(sdkError$1("AGENT_OBSERVATION_STOPPED", "Stopped checking the Agent run; read it again later.")),
|
|
969
|
-
WATCH_DEADLINE_MS$1
|
|
970
|
-
);
|
|
971
|
-
},
|
|
972
|
-
(error) => fail(error)
|
|
973
|
-
);
|
|
974
|
-
return () => {
|
|
975
|
-
if (settled)
|
|
976
|
-
return;
|
|
977
|
-
end();
|
|
978
|
-
tellHostToStop();
|
|
979
|
-
};
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
const REPORT_FLOW_TYPES = ["Form", "Process", "Case"];
|
|
983
|
-
class Report extends BaseSDK {
|
|
984
|
-
constructor(flowType, flowId, reportId) {
|
|
985
|
-
super();
|
|
986
|
-
this._flowType = flowType;
|
|
987
|
-
this._flowId = flowId;
|
|
988
|
-
this._id = reportId;
|
|
989
|
-
}
|
|
990
|
-
getData(options) {
|
|
991
|
-
return this._send(LISTENER_CMDS.REPORT_GET_DATA, {
|
|
992
|
-
pageNumber: (options == null ? void 0 : options.pageNumber) || 1,
|
|
993
|
-
pageSize: (options == null ? void 0 : options.pageSize) || 50,
|
|
994
|
-
payload: (options == null ? void 0 : options.payload) || {}
|
|
995
|
-
});
|
|
996
|
-
}
|
|
997
|
-
getCount(options) {
|
|
998
|
-
return this._send(LISTENER_CMDS.REPORT_GET_COUNT, { payload: (options == null ? void 0 : options.payload) || {} });
|
|
999
|
-
}
|
|
1000
|
-
getFields() {
|
|
1001
|
-
return this._send(LISTENER_CMDS.REPORT_GET_FIELDS, {});
|
|
1002
|
-
}
|
|
1003
|
-
_send(command, args) {
|
|
1004
|
-
const missing = requireFieldsAsync([
|
|
1005
|
-
{ value: this._flowId, name: "flowId" },
|
|
1006
|
-
{ value: this._id, name: "reportId" }
|
|
1007
|
-
]);
|
|
1008
|
-
if (missing)
|
|
1009
|
-
return missing;
|
|
1010
|
-
if (REPORT_FLOW_TYPES.indexOf(this._flowType) === -1) {
|
|
1011
|
-
return Promise.reject({
|
|
1012
|
-
message: `flowType must be one of ${REPORT_FLOW_TYPES.join(", ")}`
|
|
1013
|
-
});
|
|
1014
|
-
}
|
|
1015
|
-
return this._postMessageAsync(command, {
|
|
1016
|
-
flowType: this._flowType,
|
|
1017
|
-
flowId: this._flowId,
|
|
1018
|
-
reportId: this._id,
|
|
1019
|
-
...args
|
|
1020
|
-
});
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
828
|
class Dataform extends BaseSDK {
|
|
1024
829
|
constructor(flowId) {
|
|
1025
830
|
super();
|
|
@@ -1112,29 +917,25 @@ class Dataform extends BaseSDK {
|
|
|
1112
917
|
viewId: (options == null ? void 0 : options.viewId) || ""
|
|
1113
918
|
});
|
|
1114
919
|
}
|
|
1115
|
-
initForm(instanceId, viewId) {
|
|
1116
|
-
return this._postMessageAsync(LISTENER_CMDS.DATAFORM_INIT_FORM, {
|
|
1117
|
-
flowId: this._id,
|
|
1118
|
-
instanceId: instanceId || "",
|
|
1119
|
-
viewId: viewId || ""
|
|
1120
|
-
}).then((response) => {
|
|
1121
|
-
return new Form(
|
|
1122
|
-
response.storeId || instanceId || "",
|
|
1123
|
-
this._id,
|
|
1124
|
-
response.itemId || instanceId
|
|
1125
|
-
);
|
|
1126
|
-
});
|
|
1127
|
-
}
|
|
1128
920
|
getFieldOptions(options) {
|
|
921
|
+
const error = requireFieldsAsync([
|
|
922
|
+
{ value: options == null ? void 0 : options.instanceId, name: "instanceId" },
|
|
923
|
+
{ value: options == null ? void 0 : options.fieldId, name: "fieldId" }
|
|
924
|
+
]);
|
|
925
|
+
if (error)
|
|
926
|
+
return error;
|
|
1129
927
|
return this._postMessageAsync(
|
|
1130
928
|
LISTENER_CMDS.DATAFORM_GET_FIELD_OPTIONS,
|
|
1131
929
|
{
|
|
1132
930
|
flowId: this._id,
|
|
1133
|
-
instanceId:
|
|
1134
|
-
fieldId:
|
|
1135
|
-
fieldType: options
|
|
1136
|
-
tableId: options
|
|
1137
|
-
tableRowId: options
|
|
931
|
+
instanceId: options.instanceId,
|
|
932
|
+
fieldId: options.fieldId,
|
|
933
|
+
fieldType: options.fieldType,
|
|
934
|
+
tableId: options.tableId,
|
|
935
|
+
tableRowId: options.tableRowId,
|
|
936
|
+
pageNumber: options.pageNumber,
|
|
937
|
+
pageSize: options.pageSize,
|
|
938
|
+
searchValue: options.searchValue
|
|
1138
939
|
}
|
|
1139
940
|
);
|
|
1140
941
|
}
|
|
@@ -1176,7 +977,8 @@ class Board extends BaseSDK {
|
|
|
1176
977
|
return error;
|
|
1177
978
|
return this._postMessageAsync(LISTENER_CMDS.BOARD_GET_ITEM, {
|
|
1178
979
|
flowId: this._id,
|
|
1179
|
-
instanceId: options.instanceId
|
|
980
|
+
instanceId: options.instanceId,
|
|
981
|
+
viewId: options.viewId || ""
|
|
1180
982
|
});
|
|
1181
983
|
}
|
|
1182
984
|
createItem(options) {
|
|
@@ -1228,23 +1030,10 @@ class Board extends BaseSDK {
|
|
|
1228
1030
|
viewId: (options == null ? void 0 : options.viewId) || ""
|
|
1229
1031
|
});
|
|
1230
1032
|
}
|
|
1231
|
-
initForm(instanceId, viewId) {
|
|
1232
|
-
return this._postMessageAsync(LISTENER_CMDS.BOARD_INIT_FORM, {
|
|
1233
|
-
flowId: this._id,
|
|
1234
|
-
instanceId: instanceId || "",
|
|
1235
|
-
viewId: viewId || ""
|
|
1236
|
-
}).then((response) => {
|
|
1237
|
-
return new Form(
|
|
1238
|
-
response.storeId || instanceId || "",
|
|
1239
|
-
this._id,
|
|
1240
|
-
response.itemId || instanceId
|
|
1241
|
-
);
|
|
1242
|
-
});
|
|
1243
|
-
}
|
|
1244
1033
|
getFieldOptions(options) {
|
|
1245
1034
|
const error = requireFieldsAsync([
|
|
1246
|
-
{ value: options.instanceId, name: "instanceId" },
|
|
1247
|
-
{ value: options.fieldId, name: "fieldId" }
|
|
1035
|
+
{ value: options == null ? void 0 : options.instanceId, name: "instanceId" },
|
|
1036
|
+
{ value: options == null ? void 0 : options.fieldId, name: "fieldId" }
|
|
1248
1037
|
]);
|
|
1249
1038
|
if (error)
|
|
1250
1039
|
return error;
|
|
@@ -1254,7 +1043,10 @@ class Board extends BaseSDK {
|
|
|
1254
1043
|
fieldId: options.fieldId,
|
|
1255
1044
|
fieldType: options.fieldType,
|
|
1256
1045
|
tableId: options == null ? void 0 : options.tableId,
|
|
1257
|
-
tableRowId: options == null ? void 0 : options.tableRowId
|
|
1046
|
+
tableRowId: options == null ? void 0 : options.tableRowId,
|
|
1047
|
+
pageNumber: options == null ? void 0 : options.pageNumber,
|
|
1048
|
+
pageSize: options == null ? void 0 : options.pageSize,
|
|
1049
|
+
searchValue: options == null ? void 0 : options.searchValue
|
|
1258
1050
|
});
|
|
1259
1051
|
}
|
|
1260
1052
|
}
|
|
@@ -1541,29 +1333,25 @@ class Process extends BaseSDK {
|
|
|
1541
1333
|
instanceId: options.instanceId
|
|
1542
1334
|
});
|
|
1543
1335
|
}
|
|
1544
|
-
initForm(instanceId, activityInstanceId) {
|
|
1545
|
-
return this._postMessageAsync(LISTENER_CMDS.PROCESS_INIT_FORM, {
|
|
1546
|
-
flowId: this._id,
|
|
1547
|
-
instanceId: instanceId || "",
|
|
1548
|
-
activityInstanceId: activityInstanceId || ""
|
|
1549
|
-
}).then((response) => {
|
|
1550
|
-
return new Form(
|
|
1551
|
-
response.storeId || instanceId || "",
|
|
1552
|
-
this._id,
|
|
1553
|
-
response.itemId || instanceId,
|
|
1554
|
-
response.activityInstanceId || activityInstanceId
|
|
1555
|
-
);
|
|
1556
|
-
});
|
|
1557
|
-
}
|
|
1558
1336
|
getFieldOptions(options) {
|
|
1337
|
+
const error = requireFieldsAsync([
|
|
1338
|
+
{ value: options == null ? void 0 : options.instanceId, name: "instanceId" },
|
|
1339
|
+
{ value: options == null ? void 0 : options.activityInstanceId, name: "activityInstanceId" },
|
|
1340
|
+
{ value: options == null ? void 0 : options.fieldId, name: "fieldId" }
|
|
1341
|
+
]);
|
|
1342
|
+
if (error)
|
|
1343
|
+
return error;
|
|
1559
1344
|
return this._postMessageAsync(LISTENER_CMDS.PROCESS_GET_FIELD_OPTIONS, {
|
|
1560
1345
|
flowId: this._id,
|
|
1561
|
-
instanceId:
|
|
1562
|
-
activityInstanceId:
|
|
1563
|
-
fieldId:
|
|
1564
|
-
fieldType: options
|
|
1565
|
-
tableId: options
|
|
1566
|
-
tableRowId: options
|
|
1346
|
+
instanceId: options.instanceId,
|
|
1347
|
+
activityInstanceId: options.activityInstanceId,
|
|
1348
|
+
fieldId: options.fieldId,
|
|
1349
|
+
fieldType: options.fieldType,
|
|
1350
|
+
tableId: options.tableId,
|
|
1351
|
+
tableRowId: options.tableRowId,
|
|
1352
|
+
pageNumber: options.pageNumber,
|
|
1353
|
+
pageSize: options.pageSize,
|
|
1354
|
+
searchValue: options.searchValue
|
|
1567
1355
|
});
|
|
1568
1356
|
}
|
|
1569
1357
|
parseAttachment(options) {
|
|
@@ -1584,6 +1372,187 @@ class Process extends BaseSDK {
|
|
|
1584
1372
|
});
|
|
1585
1373
|
}
|
|
1586
1374
|
}
|
|
1375
|
+
const READ_TIMEOUT_MS$1 = 75e3;
|
|
1376
|
+
const EXECUTE_TIMEOUT_MS = 6e4;
|
|
1377
|
+
const WATCH_ACK_TIMEOUT_MS$1 = 6e4;
|
|
1378
|
+
const WATCH_DEADLINE_MS$1 = 42e4;
|
|
1379
|
+
const TERMINAL_STATUSES$1 = ["Completed", "Failed"];
|
|
1380
|
+
function sdkError$1(errorCode, error) {
|
|
1381
|
+
return { isError: true, error, errorCode };
|
|
1382
|
+
}
|
|
1383
|
+
function notify$1(callback, value) {
|
|
1384
|
+
try {
|
|
1385
|
+
callback == null ? void 0 : callback(value);
|
|
1386
|
+
} catch (error) {
|
|
1387
|
+
console.error(error);
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
const NOT_SENT$1 = sdkError$1("AGENT_REQUEST_NOT_SENT", "The request could not be sent to the host.");
|
|
1391
|
+
class Agent extends BaseSDK {
|
|
1392
|
+
constructor(agentId) {
|
|
1393
|
+
super();
|
|
1394
|
+
this.activeWatches = 0;
|
|
1395
|
+
this.agentId = agentId;
|
|
1396
|
+
this._id = generateId("customagent");
|
|
1397
|
+
}
|
|
1398
|
+
getContract() {
|
|
1399
|
+
return this._postMessageBounded(
|
|
1400
|
+
LISTENER_CMDS.CUSTOM_AGENT_GET_CONTRACT,
|
|
1401
|
+
{ agentId: this.agentId },
|
|
1402
|
+
{
|
|
1403
|
+
timeoutMs: READ_TIMEOUT_MS$1,
|
|
1404
|
+
timeoutError: sdkError$1("AGENT_HOST_TIMEOUT", "The host did not answer the Agent contract request."),
|
|
1405
|
+
sendError: NOT_SENT$1
|
|
1406
|
+
}
|
|
1407
|
+
).promise;
|
|
1408
|
+
}
|
|
1409
|
+
execute(options) {
|
|
1410
|
+
var _a;
|
|
1411
|
+
return this._postMessageBounded(
|
|
1412
|
+
LISTENER_CMDS.CUSTOM_AGENT_EXECUTE,
|
|
1413
|
+
{ agentId: this.agentId, inputData: (_a = options == null ? void 0 : options.inputData) != null ? _a : {} },
|
|
1414
|
+
{
|
|
1415
|
+
timeoutMs: EXECUTE_TIMEOUT_MS,
|
|
1416
|
+
timeoutError: sdkError$1(
|
|
1417
|
+
"AGENT_EXECUTE_OUTCOME_UNKNOWN",
|
|
1418
|
+
"The host did not confirm the run; it may still have started."
|
|
1419
|
+
),
|
|
1420
|
+
sendError: sdkError$1("AGENT_EXECUTE_NOT_SENT", "The run request could not be sent to the host.")
|
|
1421
|
+
}
|
|
1422
|
+
).promise;
|
|
1423
|
+
}
|
|
1424
|
+
getExecution(executionId) {
|
|
1425
|
+
return this._postMessageBounded(
|
|
1426
|
+
LISTENER_CMDS.CUSTOM_AGENT_GET_EXECUTION,
|
|
1427
|
+
{ agentId: this.agentId, executionId },
|
|
1428
|
+
{
|
|
1429
|
+
timeoutMs: READ_TIMEOUT_MS$1,
|
|
1430
|
+
timeoutError: sdkError$1("AGENT_HOST_TIMEOUT", "The host did not answer the Agent execution request."),
|
|
1431
|
+
sendError: NOT_SENT$1
|
|
1432
|
+
}
|
|
1433
|
+
).promise;
|
|
1434
|
+
}
|
|
1435
|
+
onExecutionComplete(executionId, onComplete, onWatchError) {
|
|
1436
|
+
const watchId = generateId("agentwatch");
|
|
1437
|
+
const eventName = `${EVENT_TYPES.CUSTOM_AGENT_EXECUTION_COMPLETE}:${watchId}`;
|
|
1438
|
+
let settled = false;
|
|
1439
|
+
let deadline = null;
|
|
1440
|
+
let registration = null;
|
|
1441
|
+
const end = () => {
|
|
1442
|
+
settled = true;
|
|
1443
|
+
if (deadline)
|
|
1444
|
+
clearTimeout(deadline);
|
|
1445
|
+
registration == null ? void 0 : registration.cancel();
|
|
1446
|
+
this._removeEventListener(eventName);
|
|
1447
|
+
this.activeWatches -= 1;
|
|
1448
|
+
if (this.activeWatches === 0)
|
|
1449
|
+
Reflect.deleteProperty(globalInstances, this._id);
|
|
1450
|
+
};
|
|
1451
|
+
const tellHostToStop = () => {
|
|
1452
|
+
try {
|
|
1453
|
+
this._postMessage(LISTENER_CMDS.CUSTOM_AGENT_STOP_WATCH, { id: this._id, watchId, eventName });
|
|
1454
|
+
} catch {
|
|
1455
|
+
}
|
|
1456
|
+
};
|
|
1457
|
+
const fail = (error) => {
|
|
1458
|
+
if (settled)
|
|
1459
|
+
return;
|
|
1460
|
+
end();
|
|
1461
|
+
tellHostToStop();
|
|
1462
|
+
notify$1(onWatchError, error);
|
|
1463
|
+
};
|
|
1464
|
+
const listener = (params) => {
|
|
1465
|
+
if (settled)
|
|
1466
|
+
return;
|
|
1467
|
+
if (params == null ? void 0 : params.isError) {
|
|
1468
|
+
end();
|
|
1469
|
+
notify$1(onWatchError, params);
|
|
1470
|
+
return;
|
|
1471
|
+
}
|
|
1472
|
+
const execution = params;
|
|
1473
|
+
if ((execution == null ? void 0 : execution.ExecutionId) !== executionId || TERMINAL_STATUSES$1.indexOf(execution == null ? void 0 : execution.Status) === -1) {
|
|
1474
|
+
fail(sdkError$1("AGENT_WATCH_INVALID_EVENT", "The host reported something other than a finished run."));
|
|
1475
|
+
return;
|
|
1476
|
+
}
|
|
1477
|
+
end();
|
|
1478
|
+
notify$1(onComplete, execution);
|
|
1479
|
+
};
|
|
1480
|
+
this.activeWatches += 1;
|
|
1481
|
+
globalInstances[this._id] = this;
|
|
1482
|
+
this._addEventListener(eventName, listener);
|
|
1483
|
+
registration = this._postMessageBounded(
|
|
1484
|
+
LISTENER_CMDS.CUSTOM_AGENT_WATCH_EXECUTION,
|
|
1485
|
+
{ id: this._id, agentId: this.agentId, executionId, watchId, eventName },
|
|
1486
|
+
{
|
|
1487
|
+
timeoutMs: WATCH_ACK_TIMEOUT_MS$1,
|
|
1488
|
+
timeoutError: sdkError$1("AGENT_HOST_UNSUPPORTED", "The host did not start observing the Agent run."),
|
|
1489
|
+
sendError: NOT_SENT$1
|
|
1490
|
+
}
|
|
1491
|
+
);
|
|
1492
|
+
registration.promise.then(
|
|
1493
|
+
(acknowledged) => {
|
|
1494
|
+
if (settled)
|
|
1495
|
+
return;
|
|
1496
|
+
if (acknowledged !== true) {
|
|
1497
|
+
fail(sdkError$1("AGENT_HOST_UNSUPPORTED", "The host did not start observing the Agent run."));
|
|
1498
|
+
return;
|
|
1499
|
+
}
|
|
1500
|
+
deadline = setTimeout(
|
|
1501
|
+
() => fail(sdkError$1("AGENT_OBSERVATION_STOPPED", "Stopped checking the Agent run; read it again later.")),
|
|
1502
|
+
WATCH_DEADLINE_MS$1
|
|
1503
|
+
);
|
|
1504
|
+
},
|
|
1505
|
+
(error) => fail(error)
|
|
1506
|
+
);
|
|
1507
|
+
return () => {
|
|
1508
|
+
if (settled)
|
|
1509
|
+
return;
|
|
1510
|
+
end();
|
|
1511
|
+
tellHostToStop();
|
|
1512
|
+
};
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
const REPORT_FLOW_TYPES = ["Form", "Process", "Case"];
|
|
1516
|
+
class Report extends BaseSDK {
|
|
1517
|
+
constructor(flowType, flowId, reportId) {
|
|
1518
|
+
super();
|
|
1519
|
+
this._flowType = flowType;
|
|
1520
|
+
this._flowId = flowId;
|
|
1521
|
+
this._id = reportId;
|
|
1522
|
+
}
|
|
1523
|
+
getData(options) {
|
|
1524
|
+
return this._send(LISTENER_CMDS.REPORT_GET_DATA, {
|
|
1525
|
+
pageNumber: (options == null ? void 0 : options.pageNumber) || 1,
|
|
1526
|
+
pageSize: (options == null ? void 0 : options.pageSize) || 50,
|
|
1527
|
+
payload: (options == null ? void 0 : options.payload) || {}
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
getCount(options) {
|
|
1531
|
+
return this._send(LISTENER_CMDS.REPORT_GET_COUNT, { payload: (options == null ? void 0 : options.payload) || {} });
|
|
1532
|
+
}
|
|
1533
|
+
getFields() {
|
|
1534
|
+
return this._send(LISTENER_CMDS.REPORT_GET_FIELDS, {});
|
|
1535
|
+
}
|
|
1536
|
+
_send(command, args) {
|
|
1537
|
+
const missing = requireFieldsAsync([
|
|
1538
|
+
{ value: this._flowId, name: "flowId" },
|
|
1539
|
+
{ value: this._id, name: "reportId" }
|
|
1540
|
+
]);
|
|
1541
|
+
if (missing)
|
|
1542
|
+
return missing;
|
|
1543
|
+
if (REPORT_FLOW_TYPES.indexOf(this._flowType) === -1) {
|
|
1544
|
+
return Promise.reject({
|
|
1545
|
+
message: `flowType must be one of ${REPORT_FLOW_TYPES.join(", ")}`
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
return this._postMessageAsync(command, {
|
|
1549
|
+
flowType: this._flowType,
|
|
1550
|
+
flowId: this._flowId,
|
|
1551
|
+
reportId: this._id,
|
|
1552
|
+
...args
|
|
1553
|
+
});
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1587
1556
|
const READ_TIMEOUT_MS = 3e4;
|
|
1588
1557
|
const RUN_TIMEOUT_MS = 45e3;
|
|
1589
1558
|
const WATCH_ACK_TIMEOUT_MS = 6e4;
|