@slates/provider 1.0.0-rc.22 → 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 +174 -61
- package/dist/index.d.cts +154 -96
- package/dist/index.d.ts +154 -96
- package/dist/index.module.js +171 -61
- package/package.json +2 -2
- package/src/action/action.ts +6 -88
- package/src/action/builder.ts +50 -46
- 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/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.cjs
CHANGED
|
@@ -50,6 +50,8 @@ __export(index_exports, {
|
|
|
50
50
|
SlateSpecification: () => SlateSpecification,
|
|
51
51
|
SlateTool: () => SlateTool,
|
|
52
52
|
SlateTrigger: () => SlateTrigger,
|
|
53
|
+
SlateTriggerGroup: () => SlateTriggerGroup,
|
|
54
|
+
SlateTriggerGroupBuilder: () => SlateTriggerGroupBuilder,
|
|
53
55
|
adapterSpec: () => adapterSpec,
|
|
54
56
|
allOf: () => allOf,
|
|
55
57
|
anyOf: () => anyOf,
|
|
@@ -101,6 +103,7 @@ __export(index_exports, {
|
|
|
101
103
|
statusLabelForApiError: () => statusLabelForApiError,
|
|
102
104
|
tool: () => tool,
|
|
103
105
|
trigger: () => trigger,
|
|
106
|
+
triggerGroup: () => triggerGroup,
|
|
104
107
|
uploadAttachmentDirect: () => uploadAttachmentDirect,
|
|
105
108
|
validateScopes: () => validateScopes,
|
|
106
109
|
verifyHmacSignature: () => verifyHmacSignature
|
|
@@ -934,7 +937,9 @@ var SlateActionBuilder = class {
|
|
|
934
937
|
#scopes;
|
|
935
938
|
#authMethods;
|
|
936
939
|
#toolParams = null;
|
|
937
|
-
#
|
|
940
|
+
#triggerGroup = null;
|
|
941
|
+
#triggerMatches = null;
|
|
942
|
+
#triggerMap = null;
|
|
938
943
|
#interfaceLocked = false;
|
|
939
944
|
input(schema) {
|
|
940
945
|
if (this.#interfaceLocked) {
|
|
@@ -984,32 +989,25 @@ var SlateActionBuilder = class {
|
|
|
984
989
|
};
|
|
985
990
|
return this;
|
|
986
991
|
}
|
|
987
|
-
|
|
992
|
+
triggerGroup(group) {
|
|
988
993
|
if (this.type !== "trigger") {
|
|
989
|
-
throw new SlateDeclarationError("
|
|
994
|
+
throw new SlateDeclarationError("triggerGroup can only be set for trigger actions");
|
|
990
995
|
}
|
|
991
|
-
this.#
|
|
992
|
-
type: "trigger",
|
|
993
|
-
source: "webhook",
|
|
994
|
-
handleEvent: props.handleEvent,
|
|
995
|
-
handleRequest: props.handleRequest,
|
|
996
|
-
autoRegisterWebhook: props.autoRegisterWebhook,
|
|
997
|
-
autoUnregisterWebhook: props.autoUnregisterWebhook,
|
|
998
|
-
http: props.http
|
|
999
|
-
};
|
|
996
|
+
this.#triggerGroup = group;
|
|
1000
997
|
return this;
|
|
1001
998
|
}
|
|
1002
|
-
|
|
999
|
+
matches(handler) {
|
|
1003
1000
|
if (this.type !== "trigger") {
|
|
1004
|
-
throw new SlateDeclarationError("
|
|
1001
|
+
throw new SlateDeclarationError("matches can only be set for trigger actions");
|
|
1005
1002
|
}
|
|
1006
|
-
this.#
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
}
|
|
1003
|
+
this.#triggerMatches = handler;
|
|
1004
|
+
return this;
|
|
1005
|
+
}
|
|
1006
|
+
map(handler) {
|
|
1007
|
+
if (this.type !== "trigger") {
|
|
1008
|
+
throw new SlateDeclarationError("map can only be set for trigger actions");
|
|
1009
|
+
}
|
|
1010
|
+
this.#triggerMap = handler;
|
|
1013
1011
|
return this;
|
|
1014
1012
|
}
|
|
1015
1013
|
build() {
|
|
@@ -1030,9 +1028,21 @@ var SlateActionBuilder = class {
|
|
|
1030
1028
|
if (this.type === "tool" && !this.#toolParams) {
|
|
1031
1029
|
throw new SlateDeclarationError("Tool invocation handler is not defined");
|
|
1032
1030
|
}
|
|
1033
|
-
if (this.type === "trigger" && !this.#
|
|
1034
|
-
throw new SlateDeclarationError("Trigger
|
|
1031
|
+
if (this.type === "trigger" && !this.#triggerGroup) {
|
|
1032
|
+
throw new SlateDeclarationError("Trigger group is not defined");
|
|
1033
|
+
}
|
|
1034
|
+
if (this.type === "trigger" && !this.#triggerMatches) {
|
|
1035
|
+
throw new SlateDeclarationError("Trigger matches handler is not defined");
|
|
1035
1036
|
}
|
|
1037
|
+
if (this.type === "trigger" && !this.#triggerMap) {
|
|
1038
|
+
throw new SlateDeclarationError("Trigger map handler is not defined");
|
|
1039
|
+
}
|
|
1040
|
+
let triggerParams = this.type === "trigger" ? {
|
|
1041
|
+
type: "trigger",
|
|
1042
|
+
triggerGroup: this.#triggerGroup,
|
|
1043
|
+
matches: this.#triggerMatches,
|
|
1044
|
+
map: this.#triggerMap
|
|
1045
|
+
} : null;
|
|
1036
1046
|
return this.factory({
|
|
1037
1047
|
...this.params,
|
|
1038
1048
|
scopes,
|
|
@@ -1043,7 +1053,7 @@ var SlateActionBuilder = class {
|
|
|
1043
1053
|
inputSchema: this.#inputSchema,
|
|
1044
1054
|
outputSchema: this.#outputSchema,
|
|
1045
1055
|
...this.#toolParams,
|
|
1046
|
-
...
|
|
1056
|
+
...triggerParams
|
|
1047
1057
|
});
|
|
1048
1058
|
}
|
|
1049
1059
|
};
|
|
@@ -1209,28 +1219,15 @@ var SlatePublicTool = class {
|
|
|
1209
1219
|
var publicTool = (spec2, params) => SlatePublicTool.create(spec2, params);
|
|
1210
1220
|
|
|
1211
1221
|
// src/action/trigger.ts
|
|
1212
|
-
var SlateDefaultPollingIntervalSeconds = 60 * 10;
|
|
1213
1222
|
var SlateTrigger = class _SlateTrigger extends SlateAction {
|
|
1214
|
-
#
|
|
1215
|
-
#
|
|
1216
|
-
#
|
|
1217
|
-
#handleRequest;
|
|
1218
|
-
#http;
|
|
1219
|
-
#pollEvents;
|
|
1220
|
-
#autoRegisterWebhook;
|
|
1221
|
-
#autoUnregisterWebhook;
|
|
1223
|
+
#triggerGroup;
|
|
1224
|
+
#matches;
|
|
1225
|
+
#map;
|
|
1222
1226
|
constructor(spec2, inputSchema, outputSchema, params) {
|
|
1223
1227
|
super("trigger", spec2, inputSchema, outputSchema, params);
|
|
1224
|
-
this.#
|
|
1225
|
-
this.#
|
|
1226
|
-
|
|
1227
|
-
};
|
|
1228
|
-
this.#handleEvent = params.handleEvent;
|
|
1229
|
-
this.#handleRequest = params.handleRequest;
|
|
1230
|
-
this.#http = params.http;
|
|
1231
|
-
this.#pollEvents = params.pollEvents;
|
|
1232
|
-
this.#autoRegisterWebhook = params.autoRegisterWebhook;
|
|
1233
|
-
this.#autoUnregisterWebhook = params.autoUnregisterWebhook;
|
|
1228
|
+
this.#triggerGroup = params.triggerGroup;
|
|
1229
|
+
this.#matches = params.matches;
|
|
1230
|
+
this.#map = params.map;
|
|
1234
1231
|
}
|
|
1235
1232
|
static create(spec2, params) {
|
|
1236
1233
|
return new SlateActionBuilder("trigger", spec2, params, (params2) => {
|
|
@@ -1238,32 +1235,122 @@ var SlateTrigger = class _SlateTrigger extends SlateAction {
|
|
|
1238
1235
|
return new _SlateTrigger(spec2, params2.inputSchema, params2.outputSchema, params2);
|
|
1239
1236
|
});
|
|
1240
1237
|
}
|
|
1241
|
-
get
|
|
1242
|
-
return this.#
|
|
1238
|
+
get triggerGroup() {
|
|
1239
|
+
return this.#triggerGroup;
|
|
1240
|
+
}
|
|
1241
|
+
get matches() {
|
|
1242
|
+
return this.#matches;
|
|
1243
|
+
}
|
|
1244
|
+
get map() {
|
|
1245
|
+
return this.#map;
|
|
1246
|
+
}
|
|
1247
|
+
};
|
|
1248
|
+
var trigger = (spec2, params) => SlateTrigger.create(spec2, params);
|
|
1249
|
+
|
|
1250
|
+
// src/action/triggerGroup.ts
|
|
1251
|
+
var SlateDefaultPollingIntervalSeconds = 60 * 10;
|
|
1252
|
+
var SlateTriggerGroup = class _SlateTriggerGroup {
|
|
1253
|
+
constructor(_spec, _params) {
|
|
1254
|
+
this._spec = _spec;
|
|
1255
|
+
this._params = _params;
|
|
1256
|
+
}
|
|
1257
|
+
_spec;
|
|
1258
|
+
_params;
|
|
1259
|
+
static create(spec2, params) {
|
|
1260
|
+
return new SlateTriggerGroupBuilder(spec2, params, (p) => new _SlateTriggerGroup(spec2, p));
|
|
1261
|
+
}
|
|
1262
|
+
get spec() {
|
|
1263
|
+
return this._spec;
|
|
1264
|
+
}
|
|
1265
|
+
get key() {
|
|
1266
|
+
return this._params.key;
|
|
1267
|
+
}
|
|
1268
|
+
get name() {
|
|
1269
|
+
return this._params.name;
|
|
1270
|
+
}
|
|
1271
|
+
get description() {
|
|
1272
|
+
return this._params.description;
|
|
1273
|
+
}
|
|
1274
|
+
get metadata() {
|
|
1275
|
+
return this._params.metadata;
|
|
1243
1276
|
}
|
|
1244
1277
|
get source() {
|
|
1245
|
-
return this
|
|
1278
|
+
return this._params.source;
|
|
1246
1279
|
}
|
|
1247
|
-
get
|
|
1248
|
-
return this
|
|
1280
|
+
get polling() {
|
|
1281
|
+
return this._params.polling;
|
|
1249
1282
|
}
|
|
1250
|
-
get
|
|
1251
|
-
return this
|
|
1283
|
+
get webhook() {
|
|
1284
|
+
return this._params.webhook;
|
|
1252
1285
|
}
|
|
1253
|
-
get
|
|
1254
|
-
return this
|
|
1286
|
+
get routingMatchers() {
|
|
1287
|
+
return this._params.routingMatchers;
|
|
1255
1288
|
}
|
|
1256
|
-
|
|
1257
|
-
|
|
1289
|
+
};
|
|
1290
|
+
var SlateTriggerGroupBuilder = class {
|
|
1291
|
+
constructor(spec2, params, factory) {
|
|
1292
|
+
this.spec = spec2;
|
|
1293
|
+
this.params = params;
|
|
1294
|
+
this.factory = factory;
|
|
1295
|
+
}
|
|
1296
|
+
spec;
|
|
1297
|
+
params;
|
|
1298
|
+
factory;
|
|
1299
|
+
#source = null;
|
|
1300
|
+
#polling = null;
|
|
1301
|
+
#webhook = null;
|
|
1302
|
+
#routingMatchers = null;
|
|
1303
|
+
polling(props) {
|
|
1304
|
+
if (this.#source) {
|
|
1305
|
+
throw new SlateDeclarationError("Trigger group invocation is already defined");
|
|
1306
|
+
}
|
|
1307
|
+
this.#source = "polling";
|
|
1308
|
+
this.#polling = {
|
|
1309
|
+
intervalSeconds: props.intervalSeconds ?? SlateDefaultPollingIntervalSeconds,
|
|
1310
|
+
pollEvents: props.pollEvents
|
|
1311
|
+
};
|
|
1312
|
+
return this;
|
|
1313
|
+
}
|
|
1314
|
+
webhook(props) {
|
|
1315
|
+
if (this.#source) {
|
|
1316
|
+
throw new SlateDeclarationError("Trigger group invocation is already defined");
|
|
1317
|
+
}
|
|
1318
|
+
if (!!props.autoRegistration === !!props.manualRegistration) {
|
|
1319
|
+
throw new SlateDeclarationError(
|
|
1320
|
+
"Webhook trigger groups require exactly one of autoRegistration or manualRegistration"
|
|
1321
|
+
);
|
|
1322
|
+
}
|
|
1323
|
+
this.#source = "webhook";
|
|
1324
|
+
this.#webhook = {
|
|
1325
|
+
autoRegistration: props.autoRegistration,
|
|
1326
|
+
manualRegistration: props.manualRegistration,
|
|
1327
|
+
process: props.process
|
|
1328
|
+
};
|
|
1329
|
+
return this;
|
|
1258
1330
|
}
|
|
1259
|
-
|
|
1260
|
-
|
|
1331
|
+
routingMatchers(handler) {
|
|
1332
|
+
this.#routingMatchers = handler;
|
|
1333
|
+
return this;
|
|
1261
1334
|
}
|
|
1262
|
-
|
|
1263
|
-
|
|
1335
|
+
build() {
|
|
1336
|
+
if (!this.#source) {
|
|
1337
|
+
throw new SlateDeclarationError(
|
|
1338
|
+
"Trigger group invocation (polling or webhook) is not defined"
|
|
1339
|
+
);
|
|
1340
|
+
}
|
|
1341
|
+
if (!this.#routingMatchers) {
|
|
1342
|
+
throw new SlateDeclarationError("Trigger group routing matchers handler is not defined");
|
|
1343
|
+
}
|
|
1344
|
+
return this.factory({
|
|
1345
|
+
...this.params,
|
|
1346
|
+
source: this.#source,
|
|
1347
|
+
polling: this.#polling ?? void 0,
|
|
1348
|
+
webhook: this.#webhook ?? void 0,
|
|
1349
|
+
routingMatchers: this.#routingMatchers
|
|
1350
|
+
});
|
|
1264
1351
|
}
|
|
1265
1352
|
};
|
|
1266
|
-
var
|
|
1353
|
+
var triggerGroup = (spec2, params) => SlateTriggerGroup.create(spec2, params);
|
|
1267
1354
|
|
|
1268
1355
|
// src/action/attachment.ts
|
|
1269
1356
|
var createUrlAttachment = (url, opts = {}) => {
|
|
@@ -2690,14 +2777,16 @@ var setIfDefined = (target, key, value) => {
|
|
|
2690
2777
|
|
|
2691
2778
|
// src/specification/slate.ts
|
|
2692
2779
|
var Slate = class _Slate {
|
|
2693
|
-
constructor(_spec, _actions, _adapters) {
|
|
2780
|
+
constructor(_spec, _actions, _adapters, _triggerGroups) {
|
|
2694
2781
|
this._spec = _spec;
|
|
2695
2782
|
this._actions = _actions;
|
|
2696
2783
|
this._adapters = _adapters;
|
|
2784
|
+
this._triggerGroups = _triggerGroups;
|
|
2697
2785
|
}
|
|
2698
2786
|
_spec;
|
|
2699
2787
|
_actions;
|
|
2700
2788
|
_adapters;
|
|
2789
|
+
_triggerGroups;
|
|
2701
2790
|
static create(params) {
|
|
2702
2791
|
let adapters = params.adapters ?? [];
|
|
2703
2792
|
let actions = [...params.triggers, ...params.tools];
|
|
@@ -2723,7 +2812,25 @@ var Slate = class _Slate {
|
|
|
2723
2812
|
}
|
|
2724
2813
|
}
|
|
2725
2814
|
}
|
|
2726
|
-
|
|
2815
|
+
let triggerGroups = params.triggerGroups ?? [];
|
|
2816
|
+
let seenTriggerGroupKeys = /* @__PURE__ */ new Set();
|
|
2817
|
+
for (let group of triggerGroups) {
|
|
2818
|
+
if (seenTriggerGroupKeys.has(group.key)) {
|
|
2819
|
+
throw new SlateDeclarationError(
|
|
2820
|
+
`Trigger group "${group.key}" is registered more than once`
|
|
2821
|
+
);
|
|
2822
|
+
}
|
|
2823
|
+
seenTriggerGroupKeys.add(group.key);
|
|
2824
|
+
}
|
|
2825
|
+
let manualWebhookTriggerGroups = triggerGroups.filter(
|
|
2826
|
+
(group) => group.source === "webhook" && group.webhook?.manualRegistration
|
|
2827
|
+
);
|
|
2828
|
+
if (manualWebhookTriggerGroups.length > 1) {
|
|
2829
|
+
throw new SlateDeclarationError(
|
|
2830
|
+
`Only one trigger group may use manual webhook registration, but found: ${manualWebhookTriggerGroups.map((group) => group.key).join(", ")}`
|
|
2831
|
+
);
|
|
2832
|
+
}
|
|
2833
|
+
return new _Slate(params.spec, actions, adapters, triggerGroups);
|
|
2727
2834
|
}
|
|
2728
2835
|
get spec() {
|
|
2729
2836
|
return this._spec;
|
|
@@ -2734,6 +2841,9 @@ var Slate = class _Slate {
|
|
|
2734
2841
|
get adapters() {
|
|
2735
2842
|
return this._adapters;
|
|
2736
2843
|
}
|
|
2844
|
+
get triggerGroups() {
|
|
2845
|
+
return this._triggerGroups;
|
|
2846
|
+
}
|
|
2737
2847
|
};
|
|
2738
2848
|
|
|
2739
2849
|
// src/specification/specification.ts
|
|
@@ -2854,6 +2964,8 @@ var getMetaWebhookVerificationResponse = (request, expectedVerifyToken) => {
|
|
|
2854
2964
|
SlateSpecification,
|
|
2855
2965
|
SlateTool,
|
|
2856
2966
|
SlateTrigger,
|
|
2967
|
+
SlateTriggerGroup,
|
|
2968
|
+
SlateTriggerGroupBuilder,
|
|
2857
2969
|
adapterSpec,
|
|
2858
2970
|
allOf,
|
|
2859
2971
|
anyOf,
|
|
@@ -2905,6 +3017,7 @@ var getMetaWebhookVerificationResponse = (request, expectedVerifyToken) => {
|
|
|
2905
3017
|
statusLabelForApiError,
|
|
2906
3018
|
tool,
|
|
2907
3019
|
trigger,
|
|
3020
|
+
triggerGroup,
|
|
2908
3021
|
uploadAttachmentDirect,
|
|
2909
3022
|
validateScopes,
|
|
2910
3023
|
verifyHmacSignature
|