@slates/provider 1.0.0-rc.21 → 1.0.0-rc.23
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.cjs +277 -138
- package/dist/index.d.cts +158 -100
- package/dist/index.d.ts +158 -100
- package/dist/index.module.js +274 -138
- package/package.json +1 -1
- package/src/action/action.ts +6 -88
- package/src/action/builder.ts +50 -46
- package/src/action/directUpload.test.ts +3 -1
- package/src/action/directUpload.ts +8 -4
- package/src/action/getFileUrlTool.ts +14 -4
- package/src/action/index.ts +1 -0
- package/src/action/trigger.ts +17 -60
- package/src/action/triggerGroup.ts +296 -0
- package/src/adapter/index.test.ts +35 -14
- package/src/auth/redact.test.ts +121 -1
- package/src/auth/redact.ts +30 -6
- package/src/module/resolveDefaultExport.test.ts +3 -3
- package/src/specification/slate.test.ts +102 -0
- package/src/specification/slate.ts +31 -3
- package/src/webhook/graph.ts +2 -2
- package/src/webhook/meta.ts +2 -2
package/dist/index.module.js
CHANGED
|
@@ -825,7 +825,9 @@ var SlateActionBuilder = class {
|
|
|
825
825
|
#scopes;
|
|
826
826
|
#authMethods;
|
|
827
827
|
#toolParams = null;
|
|
828
|
-
#
|
|
828
|
+
#triggerGroup = null;
|
|
829
|
+
#triggerMatches = null;
|
|
830
|
+
#triggerMap = null;
|
|
829
831
|
#interfaceLocked = false;
|
|
830
832
|
input(schema) {
|
|
831
833
|
if (this.#interfaceLocked) {
|
|
@@ -875,32 +877,25 @@ var SlateActionBuilder = class {
|
|
|
875
877
|
};
|
|
876
878
|
return this;
|
|
877
879
|
}
|
|
878
|
-
|
|
880
|
+
triggerGroup(group) {
|
|
879
881
|
if (this.type !== "trigger") {
|
|
880
|
-
throw new SlateDeclarationError("
|
|
882
|
+
throw new SlateDeclarationError("triggerGroup can only be set for trigger actions");
|
|
881
883
|
}
|
|
882
|
-
this.#
|
|
883
|
-
type: "trigger",
|
|
884
|
-
source: "webhook",
|
|
885
|
-
handleEvent: props.handleEvent,
|
|
886
|
-
handleRequest: props.handleRequest,
|
|
887
|
-
autoRegisterWebhook: props.autoRegisterWebhook,
|
|
888
|
-
autoUnregisterWebhook: props.autoUnregisterWebhook,
|
|
889
|
-
http: props.http
|
|
890
|
-
};
|
|
884
|
+
this.#triggerGroup = group;
|
|
891
885
|
return this;
|
|
892
886
|
}
|
|
893
|
-
|
|
887
|
+
matches(handler) {
|
|
894
888
|
if (this.type !== "trigger") {
|
|
895
|
-
throw new SlateDeclarationError("
|
|
889
|
+
throw new SlateDeclarationError("matches can only be set for trigger actions");
|
|
896
890
|
}
|
|
897
|
-
this.#
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
}
|
|
891
|
+
this.#triggerMatches = handler;
|
|
892
|
+
return this;
|
|
893
|
+
}
|
|
894
|
+
map(handler) {
|
|
895
|
+
if (this.type !== "trigger") {
|
|
896
|
+
throw new SlateDeclarationError("map can only be set for trigger actions");
|
|
897
|
+
}
|
|
898
|
+
this.#triggerMap = handler;
|
|
904
899
|
return this;
|
|
905
900
|
}
|
|
906
901
|
build() {
|
|
@@ -921,9 +916,21 @@ var SlateActionBuilder = class {
|
|
|
921
916
|
if (this.type === "tool" && !this.#toolParams) {
|
|
922
917
|
throw new SlateDeclarationError("Tool invocation handler is not defined");
|
|
923
918
|
}
|
|
924
|
-
if (this.type === "trigger" && !this.#
|
|
925
|
-
throw new SlateDeclarationError("Trigger
|
|
919
|
+
if (this.type === "trigger" && !this.#triggerGroup) {
|
|
920
|
+
throw new SlateDeclarationError("Trigger group is not defined");
|
|
921
|
+
}
|
|
922
|
+
if (this.type === "trigger" && !this.#triggerMatches) {
|
|
923
|
+
throw new SlateDeclarationError("Trigger matches handler is not defined");
|
|
924
|
+
}
|
|
925
|
+
if (this.type === "trigger" && !this.#triggerMap) {
|
|
926
|
+
throw new SlateDeclarationError("Trigger map handler is not defined");
|
|
926
927
|
}
|
|
928
|
+
let triggerParams = this.type === "trigger" ? {
|
|
929
|
+
type: "trigger",
|
|
930
|
+
triggerGroup: this.#triggerGroup,
|
|
931
|
+
matches: this.#triggerMatches,
|
|
932
|
+
map: this.#triggerMap
|
|
933
|
+
} : null;
|
|
927
934
|
return this.factory({
|
|
928
935
|
...this.params,
|
|
929
936
|
scopes,
|
|
@@ -934,7 +941,7 @@ var SlateActionBuilder = class {
|
|
|
934
941
|
inputSchema: this.#inputSchema,
|
|
935
942
|
outputSchema: this.#outputSchema,
|
|
936
943
|
...this.#toolParams,
|
|
937
|
-
...
|
|
944
|
+
...triggerParams
|
|
938
945
|
});
|
|
939
946
|
}
|
|
940
947
|
};
|
|
@@ -942,6 +949,91 @@ var SlateActionBuilder = class {
|
|
|
942
949
|
// src/action/getFileUrlTool.ts
|
|
943
950
|
import { z } from "zod";
|
|
944
951
|
|
|
952
|
+
// src/auth/redact.ts
|
|
953
|
+
var AUTH_CONFIG_SECRET_PLACEHOLDER_PREFIX = "$$MT$secret$authConfig$";
|
|
954
|
+
var AuthConfigSecretRedactor = class {
|
|
955
|
+
secretToPlaceholder = /* @__PURE__ */ new Map();
|
|
956
|
+
constructor(authConfig) {
|
|
957
|
+
if (authConfig) this.buildSecretMap(authConfig);
|
|
958
|
+
}
|
|
959
|
+
redact(value) {
|
|
960
|
+
return this.transform(value, (stringValue) => {
|
|
961
|
+
return this.secretToPlaceholder.get(stringValue) ?? stringValue;
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
redactEmbedded(value) {
|
|
965
|
+
if (this.secretToPlaceholder.size === 0) return value;
|
|
966
|
+
let pattern = new RegExp(
|
|
967
|
+
[...this.secretToPlaceholder.keys()].sort((a, b) => b.length - a.length).map((secret) => secret.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"),
|
|
968
|
+
"g"
|
|
969
|
+
);
|
|
970
|
+
return this.transform(value, (stringValue) => {
|
|
971
|
+
let exactPlaceholder = this.secretToPlaceholder.get(stringValue);
|
|
972
|
+
if (exactPlaceholder) return exactPlaceholder;
|
|
973
|
+
return stringValue.replace(
|
|
974
|
+
pattern,
|
|
975
|
+
(secret) => `${this.secretToPlaceholder.get(secret)}$$`
|
|
976
|
+
);
|
|
977
|
+
});
|
|
978
|
+
}
|
|
979
|
+
buildSecretMap(value, path = []) {
|
|
980
|
+
if (typeof value === "string") {
|
|
981
|
+
if (value.length === 0) return;
|
|
982
|
+
this.secretToPlaceholder.set(
|
|
983
|
+
value,
|
|
984
|
+
`${AUTH_CONFIG_SECRET_PLACEHOLDER_PREFIX}${path.join(".")}`
|
|
985
|
+
);
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
if (Array.isArray(value)) {
|
|
989
|
+
value.forEach((item, index) => {
|
|
990
|
+
this.buildSecretMap(item, [...path, String(index)]);
|
|
991
|
+
});
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
if (this.isPlainObject(value)) {
|
|
995
|
+
Object.entries(value).forEach(([key, nestedValue]) => {
|
|
996
|
+
this.buildSecretMap(nestedValue, [...path, key]);
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
transform(value, transformString) {
|
|
1001
|
+
if (typeof value === "string") {
|
|
1002
|
+
return transformString(value);
|
|
1003
|
+
}
|
|
1004
|
+
if (Array.isArray(value)) {
|
|
1005
|
+
return value.map((item) => this.transform(item, transformString));
|
|
1006
|
+
}
|
|
1007
|
+
if (this.isPlainObject(value)) {
|
|
1008
|
+
let result = {};
|
|
1009
|
+
Object.entries(value).forEach(([key, nestedValue]) => {
|
|
1010
|
+
result[key] = this.transform(nestedValue, transformString);
|
|
1011
|
+
});
|
|
1012
|
+
return result;
|
|
1013
|
+
}
|
|
1014
|
+
return value;
|
|
1015
|
+
}
|
|
1016
|
+
isPlainObject(value) {
|
|
1017
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
1020
|
+
var redactUrlAttachmentSecrets = (attachments, authConfig) => {
|
|
1021
|
+
if (!authConfig || !attachments) return attachments;
|
|
1022
|
+
let redactor = new AuthConfigSecretRedactor(authConfig);
|
|
1023
|
+
return attachments.map((attachment) => {
|
|
1024
|
+
if (attachment.content.type !== "url") return attachment;
|
|
1025
|
+
if (!attachment.content.headers && !attachment.content.query) return attachment;
|
|
1026
|
+
return {
|
|
1027
|
+
...attachment,
|
|
1028
|
+
content: {
|
|
1029
|
+
...attachment.content,
|
|
1030
|
+
headers: attachment.content.headers ? redactor.redactEmbedded(attachment.content.headers) : void 0,
|
|
1031
|
+
query: attachment.content.query ? redactor.redactEmbedded(attachment.content.query) : void 0
|
|
1032
|
+
}
|
|
1033
|
+
};
|
|
1034
|
+
});
|
|
1035
|
+
};
|
|
1036
|
+
|
|
945
1037
|
// src/action/tool.ts
|
|
946
1038
|
var SlateTool = class _SlateTool extends SlateAction {
|
|
947
1039
|
#handleInvocation;
|
|
@@ -980,10 +1072,18 @@ var getFileUrlTool = (spec2, handleGetFileUrl) => tool(spec2, {
|
|
|
980
1072
|
key: GET_FILE_URL_TOOL_ID,
|
|
981
1073
|
name: "Get File URL",
|
|
982
1074
|
description: "Reserved: refreshes an expiring attachment download URL. Hub-internal only."
|
|
983
|
-
}).input(getFileUrlToolInputSchema).output(getFileUrlToolOutputSchema).handleInvocation(async (ctx) =>
|
|
984
|
-
output
|
|
985
|
-
|
|
986
|
-
|
|
1075
|
+
}).input(getFileUrlToolInputSchema).output(getFileUrlToolOutputSchema).handleInvocation(async (ctx) => {
|
|
1076
|
+
let output = await handleGetFileUrl(ctx);
|
|
1077
|
+
let redactor = new AuthConfigSecretRedactor(ctx._getAuthConfigForRedaction());
|
|
1078
|
+
return {
|
|
1079
|
+
output: {
|
|
1080
|
+
...output,
|
|
1081
|
+
...output.headers ? { headers: redactor.redactEmbedded(output.headers) } : {},
|
|
1082
|
+
...output.query ? { query: redactor.redactEmbedded(output.query) } : {}
|
|
1083
|
+
},
|
|
1084
|
+
message: "ok"
|
|
1085
|
+
};
|
|
1086
|
+
}).build();
|
|
987
1087
|
|
|
988
1088
|
// src/action/publicTool.ts
|
|
989
1089
|
var SlatePublicTool = class {
|
|
@@ -1007,28 +1107,15 @@ var SlatePublicTool = class {
|
|
|
1007
1107
|
var publicTool = (spec2, params) => SlatePublicTool.create(spec2, params);
|
|
1008
1108
|
|
|
1009
1109
|
// src/action/trigger.ts
|
|
1010
|
-
var SlateDefaultPollingIntervalSeconds = 60 * 10;
|
|
1011
1110
|
var SlateTrigger = class _SlateTrigger extends SlateAction {
|
|
1012
|
-
#
|
|
1013
|
-
#
|
|
1014
|
-
#
|
|
1015
|
-
#handleRequest;
|
|
1016
|
-
#http;
|
|
1017
|
-
#pollEvents;
|
|
1018
|
-
#autoRegisterWebhook;
|
|
1019
|
-
#autoUnregisterWebhook;
|
|
1111
|
+
#triggerGroup;
|
|
1112
|
+
#matches;
|
|
1113
|
+
#map;
|
|
1020
1114
|
constructor(spec2, inputSchema, outputSchema, params) {
|
|
1021
1115
|
super("trigger", spec2, inputSchema, outputSchema, params);
|
|
1022
|
-
this.#
|
|
1023
|
-
this.#
|
|
1024
|
-
|
|
1025
|
-
};
|
|
1026
|
-
this.#handleEvent = params.handleEvent;
|
|
1027
|
-
this.#handleRequest = params.handleRequest;
|
|
1028
|
-
this.#http = params.http;
|
|
1029
|
-
this.#pollEvents = params.pollEvents;
|
|
1030
|
-
this.#autoRegisterWebhook = params.autoRegisterWebhook;
|
|
1031
|
-
this.#autoUnregisterWebhook = params.autoUnregisterWebhook;
|
|
1116
|
+
this.#triggerGroup = params.triggerGroup;
|
|
1117
|
+
this.#matches = params.matches;
|
|
1118
|
+
this.#map = params.map;
|
|
1032
1119
|
}
|
|
1033
1120
|
static create(spec2, params) {
|
|
1034
1121
|
return new SlateActionBuilder("trigger", spec2, params, (params2) => {
|
|
@@ -1036,32 +1123,122 @@ var SlateTrigger = class _SlateTrigger extends SlateAction {
|
|
|
1036
1123
|
return new _SlateTrigger(spec2, params2.inputSchema, params2.outputSchema, params2);
|
|
1037
1124
|
});
|
|
1038
1125
|
}
|
|
1039
|
-
get
|
|
1040
|
-
return this.#
|
|
1126
|
+
get triggerGroup() {
|
|
1127
|
+
return this.#triggerGroup;
|
|
1128
|
+
}
|
|
1129
|
+
get matches() {
|
|
1130
|
+
return this.#matches;
|
|
1131
|
+
}
|
|
1132
|
+
get map() {
|
|
1133
|
+
return this.#map;
|
|
1134
|
+
}
|
|
1135
|
+
};
|
|
1136
|
+
var trigger = (spec2, params) => SlateTrigger.create(spec2, params);
|
|
1137
|
+
|
|
1138
|
+
// src/action/triggerGroup.ts
|
|
1139
|
+
var SlateDefaultPollingIntervalSeconds = 60 * 10;
|
|
1140
|
+
var SlateTriggerGroup = class _SlateTriggerGroup {
|
|
1141
|
+
constructor(_spec, _params) {
|
|
1142
|
+
this._spec = _spec;
|
|
1143
|
+
this._params = _params;
|
|
1144
|
+
}
|
|
1145
|
+
_spec;
|
|
1146
|
+
_params;
|
|
1147
|
+
static create(spec2, params) {
|
|
1148
|
+
return new SlateTriggerGroupBuilder(spec2, params, (p) => new _SlateTriggerGroup(spec2, p));
|
|
1149
|
+
}
|
|
1150
|
+
get spec() {
|
|
1151
|
+
return this._spec;
|
|
1152
|
+
}
|
|
1153
|
+
get key() {
|
|
1154
|
+
return this._params.key;
|
|
1155
|
+
}
|
|
1156
|
+
get name() {
|
|
1157
|
+
return this._params.name;
|
|
1158
|
+
}
|
|
1159
|
+
get description() {
|
|
1160
|
+
return this._params.description;
|
|
1161
|
+
}
|
|
1162
|
+
get metadata() {
|
|
1163
|
+
return this._params.metadata;
|
|
1041
1164
|
}
|
|
1042
1165
|
get source() {
|
|
1043
|
-
return this
|
|
1166
|
+
return this._params.source;
|
|
1044
1167
|
}
|
|
1045
|
-
get
|
|
1046
|
-
return this
|
|
1168
|
+
get polling() {
|
|
1169
|
+
return this._params.polling;
|
|
1047
1170
|
}
|
|
1048
|
-
get
|
|
1049
|
-
return this
|
|
1171
|
+
get webhook() {
|
|
1172
|
+
return this._params.webhook;
|
|
1050
1173
|
}
|
|
1051
|
-
get
|
|
1052
|
-
return this
|
|
1174
|
+
get routingMatchers() {
|
|
1175
|
+
return this._params.routingMatchers;
|
|
1053
1176
|
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1177
|
+
};
|
|
1178
|
+
var SlateTriggerGroupBuilder = class {
|
|
1179
|
+
constructor(spec2, params, factory) {
|
|
1180
|
+
this.spec = spec2;
|
|
1181
|
+
this.params = params;
|
|
1182
|
+
this.factory = factory;
|
|
1056
1183
|
}
|
|
1057
|
-
|
|
1058
|
-
|
|
1184
|
+
spec;
|
|
1185
|
+
params;
|
|
1186
|
+
factory;
|
|
1187
|
+
#source = null;
|
|
1188
|
+
#polling = null;
|
|
1189
|
+
#webhook = null;
|
|
1190
|
+
#routingMatchers = null;
|
|
1191
|
+
polling(props) {
|
|
1192
|
+
if (this.#source) {
|
|
1193
|
+
throw new SlateDeclarationError("Trigger group invocation is already defined");
|
|
1194
|
+
}
|
|
1195
|
+
this.#source = "polling";
|
|
1196
|
+
this.#polling = {
|
|
1197
|
+
intervalSeconds: props.intervalSeconds ?? SlateDefaultPollingIntervalSeconds,
|
|
1198
|
+
pollEvents: props.pollEvents
|
|
1199
|
+
};
|
|
1200
|
+
return this;
|
|
1201
|
+
}
|
|
1202
|
+
webhook(props) {
|
|
1203
|
+
if (this.#source) {
|
|
1204
|
+
throw new SlateDeclarationError("Trigger group invocation is already defined");
|
|
1205
|
+
}
|
|
1206
|
+
if (!!props.autoRegistration === !!props.manualRegistration) {
|
|
1207
|
+
throw new SlateDeclarationError(
|
|
1208
|
+
"Webhook trigger groups require exactly one of autoRegistration or manualRegistration"
|
|
1209
|
+
);
|
|
1210
|
+
}
|
|
1211
|
+
this.#source = "webhook";
|
|
1212
|
+
this.#webhook = {
|
|
1213
|
+
autoRegistration: props.autoRegistration,
|
|
1214
|
+
manualRegistration: props.manualRegistration,
|
|
1215
|
+
process: props.process
|
|
1216
|
+
};
|
|
1217
|
+
return this;
|
|
1059
1218
|
}
|
|
1060
|
-
|
|
1061
|
-
|
|
1219
|
+
routingMatchers(handler) {
|
|
1220
|
+
this.#routingMatchers = handler;
|
|
1221
|
+
return this;
|
|
1222
|
+
}
|
|
1223
|
+
build() {
|
|
1224
|
+
if (!this.#source) {
|
|
1225
|
+
throw new SlateDeclarationError(
|
|
1226
|
+
"Trigger group invocation (polling or webhook) is not defined"
|
|
1227
|
+
);
|
|
1228
|
+
}
|
|
1229
|
+
if (!this.#routingMatchers) {
|
|
1230
|
+
throw new SlateDeclarationError("Trigger group routing matchers handler is not defined");
|
|
1231
|
+
}
|
|
1232
|
+
return this.factory({
|
|
1233
|
+
...this.params,
|
|
1234
|
+
source: this.#source,
|
|
1235
|
+
polling: this.#polling ?? void 0,
|
|
1236
|
+
webhook: this.#webhook ?? void 0,
|
|
1237
|
+
routingMatchers: this.#routingMatchers
|
|
1238
|
+
});
|
|
1062
1239
|
}
|
|
1063
1240
|
};
|
|
1064
|
-
var
|
|
1241
|
+
var triggerGroup = (spec2, params) => SlateTriggerGroup.create(spec2, params);
|
|
1065
1242
|
|
|
1066
1243
|
// src/action/attachment.ts
|
|
1067
1244
|
var createUrlAttachment = (url, opts = {}) => {
|
|
@@ -1106,7 +1283,9 @@ var bufferAttachmentBody = async (body, maxSizeBytes) => {
|
|
|
1106
1283
|
if (body.byteLength > maxSizeBytes) {
|
|
1107
1284
|
throw new Error(`Attachment exceeds the maximum size of ${maxSizeBytes} bytes`);
|
|
1108
1285
|
}
|
|
1109
|
-
|
|
1286
|
+
let buffered2 = new ArrayBuffer(body.byteLength);
|
|
1287
|
+
new Uint8Array(buffered2).set(body);
|
|
1288
|
+
return buffered2;
|
|
1110
1289
|
}
|
|
1111
1290
|
let reader = body.getReader();
|
|
1112
1291
|
let chunks = [];
|
|
@@ -1122,10 +1301,11 @@ var bufferAttachmentBody = async (body, maxSizeBytes) => {
|
|
|
1122
1301
|
}
|
|
1123
1302
|
chunks.push(value);
|
|
1124
1303
|
}
|
|
1125
|
-
let buffered = new
|
|
1304
|
+
let buffered = new ArrayBuffer(sizeBytes);
|
|
1305
|
+
let bufferedView = new Uint8Array(buffered);
|
|
1126
1306
|
let offset = 0;
|
|
1127
1307
|
for (let chunk of chunks) {
|
|
1128
|
-
|
|
1308
|
+
bufferedView.set(chunk, offset);
|
|
1129
1309
|
offset += chunk.byteLength;
|
|
1130
1310
|
}
|
|
1131
1311
|
return buffered;
|
|
@@ -1446,76 +1626,6 @@ var normalizeOAuthTokenResponse = (data, options = {}) => {
|
|
|
1446
1626
|
};
|
|
1447
1627
|
};
|
|
1448
1628
|
|
|
1449
|
-
// src/auth/redact.ts
|
|
1450
|
-
var AUTH_CONFIG_SECRET_PLACEHOLDER_PREFIX = "$$MT$secret$authConfig$";
|
|
1451
|
-
var AuthConfigSecretRedactor = class {
|
|
1452
|
-
secretToPlaceholder = /* @__PURE__ */ new Map();
|
|
1453
|
-
constructor(authConfig) {
|
|
1454
|
-
if (authConfig) this.buildSecretMap(authConfig);
|
|
1455
|
-
}
|
|
1456
|
-
redact(value) {
|
|
1457
|
-
return this.transform(value, (stringValue) => {
|
|
1458
|
-
return this.secretToPlaceholder.get(stringValue) ?? stringValue;
|
|
1459
|
-
});
|
|
1460
|
-
}
|
|
1461
|
-
buildSecretMap(value, path = []) {
|
|
1462
|
-
if (typeof value === "string") {
|
|
1463
|
-
if (value.length === 0) return;
|
|
1464
|
-
this.secretToPlaceholder.set(
|
|
1465
|
-
value,
|
|
1466
|
-
`${AUTH_CONFIG_SECRET_PLACEHOLDER_PREFIX}${path.join(".")}`
|
|
1467
|
-
);
|
|
1468
|
-
return;
|
|
1469
|
-
}
|
|
1470
|
-
if (Array.isArray(value)) {
|
|
1471
|
-
value.forEach((item, index) => {
|
|
1472
|
-
this.buildSecretMap(item, [...path, String(index)]);
|
|
1473
|
-
});
|
|
1474
|
-
return;
|
|
1475
|
-
}
|
|
1476
|
-
if (this.isPlainObject(value)) {
|
|
1477
|
-
Object.entries(value).forEach(([key, nestedValue]) => {
|
|
1478
|
-
this.buildSecretMap(nestedValue, [...path, key]);
|
|
1479
|
-
});
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
transform(value, transformString) {
|
|
1483
|
-
if (typeof value === "string") {
|
|
1484
|
-
return transformString(value);
|
|
1485
|
-
}
|
|
1486
|
-
if (Array.isArray(value)) {
|
|
1487
|
-
return value.map((item) => this.transform(item, transformString));
|
|
1488
|
-
}
|
|
1489
|
-
if (this.isPlainObject(value)) {
|
|
1490
|
-
let result = {};
|
|
1491
|
-
Object.entries(value).forEach(([key, nestedValue]) => {
|
|
1492
|
-
result[key] = this.transform(nestedValue, transformString);
|
|
1493
|
-
});
|
|
1494
|
-
return result;
|
|
1495
|
-
}
|
|
1496
|
-
return value;
|
|
1497
|
-
}
|
|
1498
|
-
isPlainObject(value) {
|
|
1499
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1500
|
-
}
|
|
1501
|
-
};
|
|
1502
|
-
var redactUrlAttachmentSecrets = (attachments, authConfig) => {
|
|
1503
|
-
if (!authConfig || !attachments) return attachments;
|
|
1504
|
-
let redactor = new AuthConfigSecretRedactor(authConfig);
|
|
1505
|
-
return attachments.map((attachment) => {
|
|
1506
|
-
if (attachment.content.type !== "url") return attachment;
|
|
1507
|
-
if (!attachment.content.headers && !attachment.content.query) return attachment;
|
|
1508
|
-
return {
|
|
1509
|
-
...attachment,
|
|
1510
|
-
content: {
|
|
1511
|
-
...attachment.content,
|
|
1512
|
-
headers: attachment.content.headers ? redactor.redact(attachment.content.headers) : void 0,
|
|
1513
|
-
query: attachment.content.query ? redactor.redact(attachment.content.query) : void 0
|
|
1514
|
-
}
|
|
1515
|
-
};
|
|
1516
|
-
});
|
|
1517
|
-
};
|
|
1518
|
-
|
|
1519
1629
|
// src/axios/index.ts
|
|
1520
1630
|
import baseAxios, { getAdapter, isAxiosError as isAxiosError2 } from "axios";
|
|
1521
1631
|
|
|
@@ -2555,14 +2665,16 @@ var setIfDefined = (target, key, value) => {
|
|
|
2555
2665
|
|
|
2556
2666
|
// src/specification/slate.ts
|
|
2557
2667
|
var Slate = class _Slate {
|
|
2558
|
-
constructor(_spec, _actions, _adapters) {
|
|
2668
|
+
constructor(_spec, _actions, _adapters, _triggerGroups) {
|
|
2559
2669
|
this._spec = _spec;
|
|
2560
2670
|
this._actions = _actions;
|
|
2561
2671
|
this._adapters = _adapters;
|
|
2672
|
+
this._triggerGroups = _triggerGroups;
|
|
2562
2673
|
}
|
|
2563
2674
|
_spec;
|
|
2564
2675
|
_actions;
|
|
2565
2676
|
_adapters;
|
|
2677
|
+
_triggerGroups;
|
|
2566
2678
|
static create(params) {
|
|
2567
2679
|
let adapters = params.adapters ?? [];
|
|
2568
2680
|
let actions = [...params.triggers, ...params.tools];
|
|
@@ -2588,7 +2700,25 @@ var Slate = class _Slate {
|
|
|
2588
2700
|
}
|
|
2589
2701
|
}
|
|
2590
2702
|
}
|
|
2591
|
-
|
|
2703
|
+
let triggerGroups = params.triggerGroups ?? [];
|
|
2704
|
+
let seenTriggerGroupKeys = /* @__PURE__ */ new Set();
|
|
2705
|
+
for (let group of triggerGroups) {
|
|
2706
|
+
if (seenTriggerGroupKeys.has(group.key)) {
|
|
2707
|
+
throw new SlateDeclarationError(
|
|
2708
|
+
`Trigger group "${group.key}" is registered more than once`
|
|
2709
|
+
);
|
|
2710
|
+
}
|
|
2711
|
+
seenTriggerGroupKeys.add(group.key);
|
|
2712
|
+
}
|
|
2713
|
+
let manualWebhookTriggerGroups = triggerGroups.filter(
|
|
2714
|
+
(group) => group.source === "webhook" && group.webhook?.manualRegistration
|
|
2715
|
+
);
|
|
2716
|
+
if (manualWebhookTriggerGroups.length > 1) {
|
|
2717
|
+
throw new SlateDeclarationError(
|
|
2718
|
+
`Only one trigger group may use manual webhook registration, but found: ${manualWebhookTriggerGroups.map((group) => group.key).join(", ")}`
|
|
2719
|
+
);
|
|
2720
|
+
}
|
|
2721
|
+
return new _Slate(params.spec, actions, adapters, triggerGroups);
|
|
2592
2722
|
}
|
|
2593
2723
|
get spec() {
|
|
2594
2724
|
return this._spec;
|
|
@@ -2599,6 +2729,9 @@ var Slate = class _Slate {
|
|
|
2599
2729
|
get adapters() {
|
|
2600
2730
|
return this._adapters;
|
|
2601
2731
|
}
|
|
2732
|
+
get triggerGroups() {
|
|
2733
|
+
return this._triggerGroups;
|
|
2734
|
+
}
|
|
2602
2735
|
};
|
|
2603
2736
|
|
|
2604
2737
|
// src/specification/specification.ts
|
|
@@ -2718,6 +2851,8 @@ export {
|
|
|
2718
2851
|
SlateSpecification,
|
|
2719
2852
|
SlateTool,
|
|
2720
2853
|
SlateTrigger,
|
|
2854
|
+
SlateTriggerGroup,
|
|
2855
|
+
SlateTriggerGroupBuilder,
|
|
2721
2856
|
adapterSpec,
|
|
2722
2857
|
allOf,
|
|
2723
2858
|
anyOf,
|
|
@@ -2769,6 +2904,7 @@ export {
|
|
|
2769
2904
|
statusLabelForApiError,
|
|
2770
2905
|
tool,
|
|
2771
2906
|
trigger,
|
|
2907
|
+
triggerGroup,
|
|
2772
2908
|
uploadAttachmentDirect,
|
|
2773
2909
|
validateScopes,
|
|
2774
2910
|
verifyHmacSignature
|
package/package.json
CHANGED
package/src/action/action.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { SlateContext, SlatePublicContext } from '../context';
|
|
|
3
3
|
import type { SlateActionDocsReference } from '../docs';
|
|
4
4
|
import type { SlateSpecification } from '../specification/specification';
|
|
5
5
|
import type { SlateAttachment } from './attachment';
|
|
6
|
+
import type { SlateTriggerGroup } from './triggerGroup';
|
|
6
7
|
|
|
7
8
|
export type SlateActionType = 'tool' | 'trigger';
|
|
8
9
|
|
|
@@ -52,6 +53,8 @@ export type SlatePublicToolInvocationHandler<InputType extends {}, OutputType ex
|
|
|
52
53
|
attachments?: SlateAttachment[];
|
|
53
54
|
}>;
|
|
54
55
|
|
|
56
|
+
export type SlateTriggerMatchesHandler = (payload: unknown) => boolean;
|
|
57
|
+
|
|
55
58
|
export type SlateTriggerMappingHandler<
|
|
56
59
|
ConfigType extends {},
|
|
57
60
|
AuthType extends {},
|
|
@@ -63,88 +66,12 @@ export type SlateTriggerMappingHandler<
|
|
|
63
66
|
output: OutputType;
|
|
64
67
|
}>;
|
|
65
68
|
|
|
66
|
-
export type SlateTriggerPollingHandler<
|
|
67
|
-
ConfigType extends {},
|
|
68
|
-
AuthType extends {},
|
|
69
|
-
InputType extends {}
|
|
70
|
-
> = (context: SlateContext<ConfigType, AuthType, { state: any | null }>) => Promise<{
|
|
71
|
-
inputs: InputType[];
|
|
72
|
-
updatedState?: any;
|
|
73
|
-
}>;
|
|
74
|
-
|
|
75
69
|
export interface SlateWebhookHttpResponseInit {
|
|
76
70
|
status?: number;
|
|
77
71
|
headers?: Record<string, string>;
|
|
78
72
|
body?: string | Uint8Array | null;
|
|
79
73
|
}
|
|
80
74
|
|
|
81
|
-
export type SlateWebhookHttpMethod =
|
|
82
|
-
| 'GET'
|
|
83
|
-
| 'POST'
|
|
84
|
-
| 'PUT'
|
|
85
|
-
| 'PATCH'
|
|
86
|
-
| 'DELETE'
|
|
87
|
-
| 'HEAD'
|
|
88
|
-
| 'OPTIONS';
|
|
89
|
-
|
|
90
|
-
export interface SlateWebhookRequestMatcher {
|
|
91
|
-
method?: string;
|
|
92
|
-
hasQueryParam?: string;
|
|
93
|
-
hasHeader?: string;
|
|
94
|
-
jsonBodyField?: {
|
|
95
|
-
path: string;
|
|
96
|
-
equals?: string;
|
|
97
|
-
};
|
|
98
|
-
formBodyField?: {
|
|
99
|
-
path: string;
|
|
100
|
-
equals?: string;
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export interface SlateWebhookHttpOptions {
|
|
105
|
-
methods?: SlateWebhookHttpMethod[];
|
|
106
|
-
sync?: {
|
|
107
|
-
mode: 'never' | 'match' | 'always';
|
|
108
|
-
match?: SlateWebhookRequestMatcher[];
|
|
109
|
-
timeoutMs?: number;
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export type SlateTriggerWebhookRequestHandler<
|
|
114
|
-
ConfigType extends {},
|
|
115
|
-
AuthType extends {},
|
|
116
|
-
InputType extends {}
|
|
117
|
-
> = (
|
|
118
|
-
context: SlateContext<
|
|
119
|
-
ConfigType,
|
|
120
|
-
AuthType,
|
|
121
|
-
{ request: Request; state: any | null; registrationDetails: any | null }
|
|
122
|
-
>
|
|
123
|
-
) => Promise<{
|
|
124
|
-
inputs: InputType[];
|
|
125
|
-
updatedState?: any;
|
|
126
|
-
response?: Response | SlateWebhookHttpResponseInit;
|
|
127
|
-
}>;
|
|
128
|
-
|
|
129
|
-
export type SlateTriggerWebhookAutoRegistrationHandler<
|
|
130
|
-
ConfigType extends {},
|
|
131
|
-
AuthType extends {}
|
|
132
|
-
> = (context: SlateContext<ConfigType, AuthType, { webhookBaseUrl: string }>) => Promise<{
|
|
133
|
-
registrationDetails: any;
|
|
134
|
-
state?: any;
|
|
135
|
-
}>;
|
|
136
|
-
|
|
137
|
-
export type SlateTriggerWebhookAutoUnregistrationHandler<
|
|
138
|
-
ConfigType extends {},
|
|
139
|
-
AuthType extends {}
|
|
140
|
-
> = (
|
|
141
|
-
context: SlateContext<
|
|
142
|
-
ConfigType,
|
|
143
|
-
AuthType,
|
|
144
|
-
{ webhookBaseUrl: string; registrationDetails: any; state: any | null }
|
|
145
|
-
>
|
|
146
|
-
) => Promise<unknown>;
|
|
147
|
-
|
|
148
75
|
export interface SlateActionParametersTool<
|
|
149
76
|
ConfigType extends {},
|
|
150
77
|
AuthType extends {},
|
|
@@ -155,10 +82,6 @@ export interface SlateActionParametersTool<
|
|
|
155
82
|
handleInvocation: SlateToolInvocationHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
156
83
|
}
|
|
157
84
|
|
|
158
|
-
export interface SlatePollingOptions {
|
|
159
|
-
intervalInSeconds?: number;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
85
|
export interface SlateActionParametersTrigger<
|
|
163
86
|
ConfigType extends {},
|
|
164
87
|
AuthType extends {},
|
|
@@ -166,14 +89,9 @@ export interface SlateActionParametersTrigger<
|
|
|
166
89
|
OutputType extends {}
|
|
167
90
|
> {
|
|
168
91
|
type: 'trigger';
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
handleRequest?: SlateTriggerWebhookRequestHandler<ConfigType, AuthType, InputType>;
|
|
173
|
-
http?: SlateWebhookHttpOptions;
|
|
174
|
-
pollEvents?: SlateTriggerPollingHandler<ConfigType, AuthType, InputType>;
|
|
175
|
-
autoRegisterWebhook?: SlateTriggerWebhookAutoRegistrationHandler<ConfigType, AuthType>;
|
|
176
|
-
autoUnregisterWebhook?: SlateTriggerWebhookAutoUnregistrationHandler<ConfigType, AuthType>;
|
|
92
|
+
triggerGroup: SlateTriggerGroup<ConfigType, AuthType>;
|
|
93
|
+
matches: SlateTriggerMatchesHandler;
|
|
94
|
+
map: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
177
95
|
}
|
|
178
96
|
|
|
179
97
|
export type SlateActionParametersAny<
|