@slates/provider 1.0.0-rc.22 → 1.0.0-rc.24
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 +180 -63
- package/dist/index.d.cts +160 -96
- package/dist/index.d.ts +160 -96
- package/dist/index.module.js +177 -63
- 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 +332 -0
- package/src/adapter/index.test.ts +35 -14
- package/src/auth/types.ts +8 -0
- package/src/module/resolveDefaultExport.test.ts +3 -3
- package/src/specification/slate.test.ts +105 -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,126 @@ 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 import_zod2 = require("zod");
|
|
1252
|
+
var SlateDefaultPollingIntervalSeconds = 60 * 10;
|
|
1253
|
+
var SlateTriggerGroup = class _SlateTriggerGroup {
|
|
1254
|
+
constructor(_spec, _params) {
|
|
1255
|
+
this._spec = _spec;
|
|
1256
|
+
this._params = _params;
|
|
1257
|
+
}
|
|
1258
|
+
_spec;
|
|
1259
|
+
_params;
|
|
1260
|
+
static create(spec2, params) {
|
|
1261
|
+
return new SlateTriggerGroupBuilder(spec2, params, (p) => new _SlateTriggerGroup(spec2, p));
|
|
1262
|
+
}
|
|
1263
|
+
get spec() {
|
|
1264
|
+
return this._spec;
|
|
1265
|
+
}
|
|
1266
|
+
get key() {
|
|
1267
|
+
return this._params.key;
|
|
1268
|
+
}
|
|
1269
|
+
get name() {
|
|
1270
|
+
return this._params.name;
|
|
1271
|
+
}
|
|
1272
|
+
get description() {
|
|
1273
|
+
return this._params.description;
|
|
1274
|
+
}
|
|
1275
|
+
get metadata() {
|
|
1276
|
+
return this._params.metadata;
|
|
1277
|
+
}
|
|
1278
|
+
get eventSchema() {
|
|
1279
|
+
return this._params.eventSchema ?? import_zod2.z.object({}).passthrough();
|
|
1243
1280
|
}
|
|
1244
1281
|
get source() {
|
|
1245
|
-
return this
|
|
1282
|
+
return this._params.source;
|
|
1246
1283
|
}
|
|
1247
|
-
get
|
|
1248
|
-
return this
|
|
1284
|
+
get polling() {
|
|
1285
|
+
return this._params.polling;
|
|
1249
1286
|
}
|
|
1250
|
-
get
|
|
1251
|
-
return this
|
|
1287
|
+
get webhook() {
|
|
1288
|
+
return this._params.webhook;
|
|
1252
1289
|
}
|
|
1253
|
-
get
|
|
1254
|
-
return this
|
|
1290
|
+
get routingMatchers() {
|
|
1291
|
+
return this._params.routingMatchers;
|
|
1255
1292
|
}
|
|
1256
|
-
|
|
1257
|
-
|
|
1293
|
+
};
|
|
1294
|
+
var SlateTriggerGroupBuilder = class {
|
|
1295
|
+
constructor(spec2, params, factory) {
|
|
1296
|
+
this.spec = spec2;
|
|
1297
|
+
this.params = params;
|
|
1298
|
+
this.factory = factory;
|
|
1299
|
+
}
|
|
1300
|
+
spec;
|
|
1301
|
+
params;
|
|
1302
|
+
factory;
|
|
1303
|
+
#source = null;
|
|
1304
|
+
#polling = null;
|
|
1305
|
+
#webhook = null;
|
|
1306
|
+
#routingMatchers = null;
|
|
1307
|
+
polling(props) {
|
|
1308
|
+
if (this.#source) {
|
|
1309
|
+
throw new SlateDeclarationError("Trigger group invocation is already defined");
|
|
1310
|
+
}
|
|
1311
|
+
this.#source = "polling";
|
|
1312
|
+
this.#polling = {
|
|
1313
|
+
intervalSeconds: props.intervalSeconds ?? SlateDefaultPollingIntervalSeconds,
|
|
1314
|
+
pollEvents: props.pollEvents
|
|
1315
|
+
};
|
|
1316
|
+
return this;
|
|
1317
|
+
}
|
|
1318
|
+
webhook(props) {
|
|
1319
|
+
if (this.#source) {
|
|
1320
|
+
throw new SlateDeclarationError("Trigger group invocation is already defined");
|
|
1321
|
+
}
|
|
1322
|
+
if (!!props.autoRegistration === !!props.manualRegistration) {
|
|
1323
|
+
throw new SlateDeclarationError(
|
|
1324
|
+
"Webhook trigger groups require exactly one of autoRegistration or manualRegistration"
|
|
1325
|
+
);
|
|
1326
|
+
}
|
|
1327
|
+
this.#source = "webhook";
|
|
1328
|
+
this.#webhook = {
|
|
1329
|
+
autoRegistration: props.autoRegistration,
|
|
1330
|
+
manualRegistration: props.manualRegistration,
|
|
1331
|
+
process: props.process
|
|
1332
|
+
};
|
|
1333
|
+
return this;
|
|
1258
1334
|
}
|
|
1259
|
-
|
|
1260
|
-
|
|
1335
|
+
routingMatchers(handler) {
|
|
1336
|
+
this.#routingMatchers = handler;
|
|
1337
|
+
return this;
|
|
1261
1338
|
}
|
|
1262
|
-
|
|
1263
|
-
|
|
1339
|
+
build() {
|
|
1340
|
+
if (!this.#source) {
|
|
1341
|
+
throw new SlateDeclarationError(
|
|
1342
|
+
"Trigger group invocation (polling or webhook) is not defined"
|
|
1343
|
+
);
|
|
1344
|
+
}
|
|
1345
|
+
if (!this.#routingMatchers) {
|
|
1346
|
+
throw new SlateDeclarationError("Trigger group routing matchers handler is not defined");
|
|
1347
|
+
}
|
|
1348
|
+
return this.factory({
|
|
1349
|
+
...this.params,
|
|
1350
|
+
source: this.#source,
|
|
1351
|
+
polling: this.#polling ?? void 0,
|
|
1352
|
+
webhook: this.#webhook ?? void 0,
|
|
1353
|
+
routingMatchers: this.#routingMatchers
|
|
1354
|
+
});
|
|
1264
1355
|
}
|
|
1265
1356
|
};
|
|
1266
|
-
var
|
|
1357
|
+
var triggerGroup = (spec2, params) => SlateTriggerGroup.create(spec2, params);
|
|
1267
1358
|
|
|
1268
1359
|
// src/action/attachment.ts
|
|
1269
1360
|
var createUrlAttachment = (url, opts = {}) => {
|
|
@@ -2690,14 +2781,16 @@ var setIfDefined = (target, key, value) => {
|
|
|
2690
2781
|
|
|
2691
2782
|
// src/specification/slate.ts
|
|
2692
2783
|
var Slate = class _Slate {
|
|
2693
|
-
constructor(_spec, _actions, _adapters) {
|
|
2784
|
+
constructor(_spec, _actions, _adapters, _triggerGroups) {
|
|
2694
2785
|
this._spec = _spec;
|
|
2695
2786
|
this._actions = _actions;
|
|
2696
2787
|
this._adapters = _adapters;
|
|
2788
|
+
this._triggerGroups = _triggerGroups;
|
|
2697
2789
|
}
|
|
2698
2790
|
_spec;
|
|
2699
2791
|
_actions;
|
|
2700
2792
|
_adapters;
|
|
2793
|
+
_triggerGroups;
|
|
2701
2794
|
static create(params) {
|
|
2702
2795
|
let adapters = params.adapters ?? [];
|
|
2703
2796
|
let actions = [...params.triggers, ...params.tools];
|
|
@@ -2723,7 +2816,25 @@ var Slate = class _Slate {
|
|
|
2723
2816
|
}
|
|
2724
2817
|
}
|
|
2725
2818
|
}
|
|
2726
|
-
|
|
2819
|
+
let triggerGroups = params.triggerGroups ?? [];
|
|
2820
|
+
let seenTriggerGroupKeys = /* @__PURE__ */ new Set();
|
|
2821
|
+
for (let group of triggerGroups) {
|
|
2822
|
+
if (seenTriggerGroupKeys.has(group.key)) {
|
|
2823
|
+
throw new SlateDeclarationError(
|
|
2824
|
+
`Trigger group "${group.key}" is registered more than once`
|
|
2825
|
+
);
|
|
2826
|
+
}
|
|
2827
|
+
seenTriggerGroupKeys.add(group.key);
|
|
2828
|
+
}
|
|
2829
|
+
let manualWebhookTriggerGroups = triggerGroups.filter(
|
|
2830
|
+
(group) => group.source === "webhook" && group.webhook?.manualRegistration
|
|
2831
|
+
);
|
|
2832
|
+
if (manualWebhookTriggerGroups.length > 1) {
|
|
2833
|
+
throw new SlateDeclarationError(
|
|
2834
|
+
`Only one trigger group may use manual webhook registration, but found: ${manualWebhookTriggerGroups.map((group) => group.key).join(", ")}`
|
|
2835
|
+
);
|
|
2836
|
+
}
|
|
2837
|
+
return new _Slate(params.spec, actions, adapters, triggerGroups);
|
|
2727
2838
|
}
|
|
2728
2839
|
get spec() {
|
|
2729
2840
|
return this._spec;
|
|
@@ -2734,10 +2845,13 @@ var Slate = class _Slate {
|
|
|
2734
2845
|
get adapters() {
|
|
2735
2846
|
return this._adapters;
|
|
2736
2847
|
}
|
|
2848
|
+
get triggerGroups() {
|
|
2849
|
+
return this._triggerGroups;
|
|
2850
|
+
}
|
|
2737
2851
|
};
|
|
2738
2852
|
|
|
2739
2853
|
// src/specification/specification.ts
|
|
2740
|
-
var
|
|
2854
|
+
var import_zod3 = __toESM(require("zod"), 1);
|
|
2741
2855
|
var SlateSpecification = class _SlateSpecification {
|
|
2742
2856
|
constructor(_config, _auth, _params) {
|
|
2743
2857
|
this._config = _config;
|
|
@@ -2754,7 +2868,7 @@ var SlateSpecification = class _SlateSpecification {
|
|
|
2754
2868
|
return this._config.configSchema;
|
|
2755
2869
|
}
|
|
2756
2870
|
get authSchema() {
|
|
2757
|
-
return "outputSchema" in this._auth ? this._auth.outputSchema :
|
|
2871
|
+
return "outputSchema" in this._auth ? this._auth.outputSchema : import_zod3.default.object({});
|
|
2758
2872
|
}
|
|
2759
2873
|
get config() {
|
|
2760
2874
|
return this._config;
|
|
@@ -2854,6 +2968,8 @@ var getMetaWebhookVerificationResponse = (request, expectedVerifyToken) => {
|
|
|
2854
2968
|
SlateSpecification,
|
|
2855
2969
|
SlateTool,
|
|
2856
2970
|
SlateTrigger,
|
|
2971
|
+
SlateTriggerGroup,
|
|
2972
|
+
SlateTriggerGroupBuilder,
|
|
2857
2973
|
adapterSpec,
|
|
2858
2974
|
allOf,
|
|
2859
2975
|
anyOf,
|
|
@@ -2905,6 +3021,7 @@ var getMetaWebhookVerificationResponse = (request, expectedVerifyToken) => {
|
|
|
2905
3021
|
statusLabelForApiError,
|
|
2906
3022
|
tool,
|
|
2907
3023
|
trigger,
|
|
3024
|
+
triggerGroup,
|
|
2908
3025
|
uploadAttachmentDirect,
|
|
2909
3026
|
validateScopes,
|
|
2910
3027
|
verifyHmacSignature
|