@slates/provider-handler 1.0.0-rc.29 → 1.0.0-rc.31

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.
@@ -162,17 +162,57 @@ var mapAction = (_slate, a) => {
162
162
  ...base,
163
163
  type: "action.trigger",
164
164
  capabilities: {},
165
- invocation: a.source === "polling" ? {
166
- type: "polling",
167
- intervalSeconds: a.polling.intervalInSeconds ?? SlateDefaultPollingIntervalSeconds
168
- } : {
169
- type: "webhook",
170
- autoRegistration: !!a.autoRegisterWebhook,
171
- autoUnregistration: !!a.autoUnregisterWebhook,
172
- http: a.http
173
- }
165
+ triggerGroupId: a.triggerGroup.key
174
166
  };
175
167
  };
168
+ var getTriggerGroup = (slate, triggerGroupId) => {
169
+ let group = slate.triggerGroups.find((g) => g.key === triggerGroupId);
170
+ if (!group) {
171
+ throw new ServiceError2(notFoundError(`trigger_group`, triggerGroupId));
172
+ }
173
+ return group;
174
+ };
175
+ var getTriggersForGroup = (slate, triggerGroupId) => slate.actions.filter(
176
+ (action) => action.type === "trigger" && action.triggerGroup.key === triggerGroupId
177
+ );
178
+ var evaluateTriggerMatches = (slate, triggerGroupId, payload) => getTriggersForGroup(slate, triggerGroupId).filter((trigger) => trigger.matches(payload)).map((trigger) => trigger.key);
179
+ var getWebhookAutoRegistration = (group) => {
180
+ if (group.source !== "webhook" || !group.webhook?.autoRegistration) {
181
+ throw new ServiceError2(
182
+ badRequestError({
183
+ message: `Trigger group does not support webhook auto-registration: ${group.key}`
184
+ })
185
+ );
186
+ }
187
+ return group.webhook.autoRegistration;
188
+ };
189
+ var getWebhookManualRegistration = (group) => {
190
+ if (group.source !== "webhook" || !group.webhook?.manualRegistration) {
191
+ throw new ServiceError2(
192
+ badRequestError({
193
+ message: `Trigger group does not support manual webhook registration: ${group.key}`
194
+ })
195
+ );
196
+ }
197
+ return group.webhook.manualRegistration;
198
+ };
199
+ var mapTriggerGroup = (group) => ({
200
+ id: group.key,
201
+ name: group.name,
202
+ description: group.description,
203
+ metadata: group.metadata,
204
+ invocation: group.source === "polling" ? {
205
+ type: "polling",
206
+ intervalSeconds: group.polling?.intervalSeconds ?? SlateDefaultPollingIntervalSeconds
207
+ } : {
208
+ type: "webhook",
209
+ registration: group.webhook?.manualRegistration ? {
210
+ mode: "manual",
211
+ userConfigSchema: toJsonSchema(group.webhook.manualRegistration.userConfigSchema),
212
+ fullConfigSchema: toJsonSchema(group.webhook.manualRegistration.fullConfigSchema)
213
+ } : { mode: "auto" }
214
+ }
215
+ });
176
216
 
177
217
  // src/state.ts
178
218
  var State = class {
@@ -352,6 +392,7 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
352
392
  maxAttachmentSizeBytes: directUpload.maxAttachmentSizeBytes ?? DEFAULT_MAX_ATTACHMENT_SIZE_BYTES
353
393
  };
354
394
  };
395
+ let supportsTriggerGroups = () => !!hubCapabilities.get()?.triggers;
355
396
  let logger = new SlateLogger(listeners);
356
397
  let providerTrace = {
357
398
  providerId: slate.spec.key,
@@ -492,6 +533,9 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
492
533
  hub: {
493
534
  capabilitiesNotification: true,
494
535
  liveInvocation: true
536
+ },
537
+ provider: {
538
+ triggerGroups: true
495
539
  }
496
540
  }
497
541
  }));
@@ -903,6 +947,9 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
903
947
  manager.onRequest("slates/actions.list", async ({ params }) => {
904
948
  getContextBasic();
905
949
  let actions = params.includeAdapterActions ? slate.actions : slate.actions.filter((action) => !action.adapter);
950
+ if (!supportsTriggerGroups()) {
951
+ actions = actions.filter((action) => action.type !== "trigger");
952
+ }
906
953
  return {
907
954
  actions: actions.map((a) => mapAction(slate, a))
908
955
  };
@@ -927,6 +974,19 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
927
974
  action: mapAction(slate, action)
928
975
  };
929
976
  });
977
+ manager.onRequest("slates/trigger_groups.list", async () => {
978
+ getContextBasic();
979
+ return {
980
+ triggerGroups: slate.triggerGroups.map(mapTriggerGroup)
981
+ };
982
+ });
983
+ manager.onRequest("slates/trigger_group.get", async ({ params }) => {
984
+ getContextBasic();
985
+ let triggerGroup = getTriggerGroup(slate, params.triggerGroupId);
986
+ return {
987
+ triggerGroup: mapTriggerGroup(triggerGroup)
988
+ };
989
+ });
930
990
  manager.onRequest("slates/action.tool.invoke", async ({ params }) => {
931
991
  let action = getActionWithType(slate, "tool", params.actionId);
932
992
  let input = validate(
@@ -1023,23 +1083,61 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
1023
1083
  outputKeyCount: getObjectKeyCount(result.output)
1024
1084
  })
1025
1085
  },
1026
- () => runWithContext(context, () => action.handleEvent(context))
1086
+ () => runWithContext(context, () => action.map(context))
1027
1087
  );
1028
1088
  return withRequestTraces(context, { id: res.id, type: res.type, output: res.output });
1029
1089
  });
1030
1090
  manager.onRequest("slates/action.trigger.poll_events", async ({ params }) => {
1031
- let ctx = getContextFull();
1032
- let action = getActionWithType(slate, "trigger", params.actionId);
1033
- if (!action.pollEvents) {
1091
+ getContextBasic();
1092
+ if (supportsTriggerGroups()) {
1093
+ throw new ServiceError4(
1094
+ badRequestError3({
1095
+ message: `Legacy trigger polling is disabled once trigger_group support is announced: ${params.actionId}`
1096
+ })
1097
+ );
1098
+ }
1099
+ return { inputs: [], updatedState: params.state };
1100
+ });
1101
+ manager.onRequest("slates/action.trigger.webhook_handle", async ({ params }) => {
1102
+ getContextBasic();
1103
+ if (supportsTriggerGroups()) {
1104
+ throw new ServiceError4(
1105
+ badRequestError3({
1106
+ message: `Legacy trigger webhook handling is disabled once trigger_group support is announced: ${params.actionId}`
1107
+ })
1108
+ );
1109
+ }
1110
+ return { inputs: [], updatedState: params.state, response: null };
1111
+ });
1112
+ manager.onRequest("slates/action.trigger.webhook_register", async ({ params }) => {
1113
+ getContextBasic();
1114
+ if (supportsTriggerGroups()) {
1034
1115
  throw new ServiceError4(
1035
1116
  badRequestError3({
1036
- message: `Trigger action does not support polling: ${params.actionId}`
1117
+ message: `Legacy trigger webhook registration is disabled once trigger_group support is announced: ${params.actionId}`
1037
1118
  })
1038
1119
  );
1039
1120
  }
1121
+ return { registrationDetails: null };
1122
+ });
1123
+ manager.onRequest("slates/action.trigger.webhook_unregister", async ({ params }) => {
1124
+ getContextBasic();
1125
+ if (supportsTriggerGroups()) {
1126
+ throw new ServiceError4(
1127
+ badRequestError3({
1128
+ message: `Legacy trigger webhook unregistration is disabled once trigger_group support is announced: ${params.actionId}`
1129
+ })
1130
+ );
1131
+ }
1132
+ return {};
1133
+ });
1134
+ manager.onRequest("slates/trigger_group.webhook.targets_list", async ({ params }) => {
1135
+ let ctx = getContextFull();
1136
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1137
+ let autoRegistration = getWebhookAutoRegistration(group);
1040
1138
  let context = new SlateContext(
1041
1139
  ctx.config,
1042
- { state: params.state },
1140
+ { pageToken: params.pageToken ?? null },
1043
1141
  ctx.auth?.output,
1044
1142
  slate.spec,
1045
1143
  logger
@@ -1047,35 +1145,168 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
1047
1145
  let res = await traceProviderCall(
1048
1146
  {
1049
1147
  component: "action",
1050
- functionName: "pollEvents",
1051
- message: `Polling events for trigger ${formatEntityLabel(action.name, action.key)}`,
1052
- successMessage: (result) => `Polled ${result.inputs.length} event(s) for trigger ${formatEntityLabel(action.name, action.key)}`,
1053
- errorMessage: `Trigger ${formatEntityLabel(action.name, action.key)} failed while polling events`,
1148
+ functionName: "webhookTargetList",
1149
+ message: `Listing webhook targets for trigger group ${formatEntityLabel(group.name, group.key)}`,
1150
+ successMessage: (result) => `Listed ${result.targets.length} webhook target(s) for trigger group ${formatEntityLabel(group.name, group.key)}`,
1151
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while listing webhook targets`,
1054
1152
  metadata: {
1055
- actionId: action.key,
1056
- actionName: action.name,
1057
- actionType: action.type,
1058
- hasPreviousState: params.state !== null
1153
+ triggerGroupId: group.key,
1154
+ triggerGroupName: group.name
1059
1155
  },
1060
1156
  onSuccess: (result) => ({
1061
- inputCount: result.inputs.length,
1062
- hasUpdatedState: result.updatedState !== void 0
1157
+ targetCount: result.targets.length,
1158
+ hasNextPageToken: result.nextPageToken !== null
1063
1159
  })
1064
1160
  },
1065
- () => runWithContext(context, () => action.pollEvents(context))
1161
+ () => runWithContext(context, () => autoRegistration.webhookTargetList(context))
1066
1162
  );
1067
1163
  return withRequestTraces(context, {
1068
- inputs: res.inputs,
1069
- updatedState: res.updatedState
1164
+ targets: res.targets,
1165
+ nextPageToken: res.nextPageToken ?? null
1070
1166
  });
1071
1167
  });
1072
- manager.onRequest("slates/action.trigger.webhook_handle", async ({ params }) => {
1168
+ manager.onRequest("slates/trigger_group.webhook.register", async ({ params }) => {
1073
1169
  let ctx = getContextFull();
1074
- let action = getActionWithType(slate, "trigger", params.actionId);
1075
- if (!action.handleRequest) {
1170
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1171
+ let autoRegistration = getWebhookAutoRegistration(group);
1172
+ let context = new SlateContext(
1173
+ ctx.config,
1174
+ {
1175
+ webhookTargetIdentifier: params.webhookTargetIdentifier,
1176
+ webhookTargetPayload: params.webhookTargetPayload,
1177
+ webhookUrl: params.webhookUrl
1178
+ },
1179
+ ctx.auth?.output,
1180
+ slate.spec,
1181
+ logger
1182
+ );
1183
+ let res = await traceProviderCall(
1184
+ {
1185
+ component: "action",
1186
+ functionName: "webhookRegister",
1187
+ message: `Registering webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
1188
+ successMessage: `Registered webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
1189
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while registering a webhook`,
1190
+ metadata: {
1191
+ triggerGroupId: group.key,
1192
+ triggerGroupName: group.name,
1193
+ webhookTargetIdentifier: params.webhookTargetIdentifier
1194
+ }
1195
+ },
1196
+ () => runWithContext(context, () => autoRegistration.webhookRegister(context))
1197
+ );
1198
+ return withRequestTraces(context, {
1199
+ webhookRegistrationIdentifier: res.webhookRegistrationIdentifier,
1200
+ webhookRegistrationPayload: res.webhookRegistrationPayload
1201
+ });
1202
+ });
1203
+ manager.onRequest("slates/trigger_group.webhook.unregister", async ({ params }) => {
1204
+ let ctx = getContextFull();
1205
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1206
+ let autoRegistration = getWebhookAutoRegistration(group);
1207
+ let context = new SlateContext(
1208
+ ctx.config,
1209
+ {
1210
+ webhookRegistrationIdentifier: params.webhookRegistrationIdentifier,
1211
+ webhookRegistrationPayload: params.webhookRegistrationPayload
1212
+ },
1213
+ ctx.auth?.output,
1214
+ slate.spec,
1215
+ logger
1216
+ );
1217
+ await traceProviderCall(
1218
+ {
1219
+ component: "action",
1220
+ functionName: "webhookUnregister",
1221
+ message: `Unregistering webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
1222
+ successMessage: `Unregistered webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
1223
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while unregistering a webhook`,
1224
+ metadata: {
1225
+ triggerGroupId: group.key,
1226
+ triggerGroupName: group.name,
1227
+ webhookRegistrationIdentifier: params.webhookRegistrationIdentifier
1228
+ }
1229
+ },
1230
+ () => runWithContext(context, () => autoRegistration.webhookUnregister(context))
1231
+ );
1232
+ return withRequestTraces(context, {});
1233
+ });
1234
+ manager.onRequest("slates/trigger_group.webhook.manual_setup", async ({ params }) => {
1235
+ getContextBasic();
1236
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1237
+ let manualRegistration = getWebhookManualRegistration(group);
1238
+ let context = new SlateContext(
1239
+ {},
1240
+ { webhookUrl: params.webhookUrl },
1241
+ {},
1242
+ slate.spec,
1243
+ logger
1244
+ );
1245
+ let res = await traceProviderCall(
1246
+ {
1247
+ component: "action",
1248
+ functionName: "webhookManualSetup",
1249
+ message: `Building manual webhook setup for trigger group ${formatEntityLabel(group.name, group.key)}`,
1250
+ successMessage: `Built manual webhook setup for trigger group ${formatEntityLabel(group.name, group.key)}`,
1251
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while building a manual webhook setup`,
1252
+ metadata: {
1253
+ triggerGroupId: group.key,
1254
+ triggerGroupName: group.name
1255
+ }
1256
+ },
1257
+ () => runWithContext(context, () => manualRegistration.setup(context))
1258
+ );
1259
+ return {
1260
+ webhookSetupDocument: res.webhookSetupDocument,
1261
+ partialWebhookRegistrationPayload: res.partialWebhookRegistrationPayload
1262
+ };
1263
+ });
1264
+ manager.onRequest("slates/trigger_group.webhook.manual_finish", async ({ params }) => {
1265
+ getContextBasic();
1266
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1267
+ let manualRegistration = getWebhookManualRegistration(group);
1268
+ if (!manualRegistration.finish) {
1076
1269
  throw new ServiceError4(
1077
1270
  badRequestError3({
1078
- message: `Trigger action does not support webhook requests: ${params.actionId}`
1271
+ message: `Trigger group does not support manual webhook finish: ${params.triggerGroupId}`
1272
+ })
1273
+ );
1274
+ }
1275
+ let context = new SlateContext(
1276
+ {},
1277
+ {
1278
+ webhookUrl: params.webhookUrl,
1279
+ partialWebhookRegistrationPayload: params.partialWebhookRegistrationPayload,
1280
+ userWebhookRegistrationPayload: params.userWebhookRegistrationPayload
1281
+ },
1282
+ {},
1283
+ slate.spec,
1284
+ logger
1285
+ );
1286
+ let res = await traceProviderCall(
1287
+ {
1288
+ component: "action",
1289
+ functionName: "webhookManualFinish",
1290
+ message: `Finishing manual webhook setup for trigger group ${formatEntityLabel(group.name, group.key)}`,
1291
+ successMessage: `Finished manual webhook setup for trigger group ${formatEntityLabel(group.name, group.key)}`,
1292
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while finishing a manual webhook setup`,
1293
+ metadata: {
1294
+ triggerGroupId: group.key,
1295
+ triggerGroupName: group.name
1296
+ }
1297
+ },
1298
+ () => runWithContext(context, () => manualRegistration.finish(context))
1299
+ );
1300
+ return withRequestTraces(context, {
1301
+ webhookRegistrationPayload: res.webhookRegistrationPayload
1302
+ });
1303
+ });
1304
+ manager.onRequest("slates/trigger_group.webhook.process", async ({ params }) => {
1305
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1306
+ if (group.source !== "webhook" || !group.webhook) {
1307
+ throw new ServiceError4(
1308
+ badRequestError3({
1309
+ message: `Trigger group does not support webhook processing: ${params.triggerGroupId}`
1079
1310
  })
1080
1311
  );
1081
1312
  }
@@ -1085,126 +1316,122 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
1085
1316
  body: params.body ? Uint8Array.from(atob(params.body.content), (c) => c.charCodeAt(0)) : null
1086
1317
  });
1087
1318
  let context = new SlateContext(
1088
- ctx.config,
1319
+ {},
1089
1320
  {
1090
1321
  request: req,
1091
- state: params.state,
1092
- registrationDetails: params.registrationDetails ?? null
1322
+ webhookRegistrationPayload: params.webhookRegistrationPayload
1093
1323
  },
1094
- ctx.auth?.output,
1324
+ {},
1095
1325
  slate.spec,
1096
1326
  logger
1097
1327
  );
1098
1328
  let res = await traceProviderCall(
1099
1329
  {
1100
1330
  component: "action",
1101
- functionName: "handleRequest",
1102
- message: `Handling webhook request for trigger ${formatEntityLabel(action.name, action.key)}`,
1103
- successMessage: (result) => `Received ${result.inputs.length} webhook event(s) for trigger ${formatEntityLabel(action.name, action.key)}`,
1104
- errorMessage: `Trigger ${formatEntityLabel(action.name, action.key)} failed while handling a webhook request`,
1331
+ functionName: "webhookProcess",
1332
+ message: `Processing webhook request for trigger group ${formatEntityLabel(group.name, group.key)}`,
1333
+ successMessage: (result) => `Extracted ${result.events.length} event(s) from webhook request for trigger group ${formatEntityLabel(group.name, group.key)}`,
1334
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while processing a webhook request`,
1105
1335
  metadata: {
1106
- actionId: action.key,
1107
- actionName: action.name,
1108
- actionType: action.type,
1336
+ triggerGroupId: group.key,
1337
+ triggerGroupName: group.name,
1109
1338
  requestMethod: params.method,
1110
- hasRequestBody: !!params.body,
1111
- hasPreviousState: params.state !== null
1339
+ hasRequestBody: !!params.body
1112
1340
  },
1113
1341
  onSuccess: (result) => ({
1114
- inputCount: result.inputs.length,
1115
- hasUpdatedState: result.updatedState !== void 0,
1342
+ eventCount: result.events.length,
1116
1343
  hasResponse: result.response !== void 0
1117
1344
  })
1118
1345
  },
1119
- () => runWithContext(context, () => action.handleRequest(context))
1346
+ () => runWithContext(context, () => group.webhook.process(context))
1120
1347
  );
1348
+ for (let event of res.events) {
1349
+ if (!event.matchers) {
1350
+ throw new ServiceError4(
1351
+ preconditionFailedError({
1352
+ message: `Trigger group "${group.key}" process handler must return matchers for every event (return [] if there is nothing to assert)`
1353
+ })
1354
+ );
1355
+ }
1356
+ }
1121
1357
  let response = res.response === void 0 ? void 0 : await serializeWebhookHttpResponse(res.response);
1122
1358
  return withRequestTraces(context, {
1123
- inputs: res.inputs,
1124
- updatedState: res.updatedState,
1359
+ events: res.events.map((event) => ({
1360
+ matchers: event.matchers,
1361
+ payload: event.payload,
1362
+ idempotencyKey: event.idempotencyKey,
1363
+ triggerIds: evaluateTriggerMatches(slate, group.key, event.payload)
1364
+ })),
1125
1365
  response
1126
1366
  });
1127
1367
  });
1128
- manager.onRequest("slates/action.trigger.webhook_register", async ({ params }) => {
1368
+ manager.onRequest("slates/trigger_group.routing_matchers.get", async ({ params }) => {
1129
1369
  let ctx = getContextFull();
1130
- let action = getActionWithType(slate, "trigger", params.actionId);
1131
- if (!action.autoRegisterWebhook) {
1132
- throw new ServiceError4(
1133
- badRequestError3({
1134
- message: `Trigger action does not support webhook auto-registration: ${params.actionId}`
1135
- })
1136
- );
1137
- }
1138
- let context = new SlateContext(
1139
- ctx.config,
1140
- { webhookBaseUrl: params.webhookBaseUrl },
1141
- ctx.auth?.output,
1142
- slate.spec,
1143
- logger
1144
- );
1145
- let res = await traceProviderCall(
1370
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1371
+ let context = new SlateContext(ctx.config, {}, ctx.auth?.output, slate.spec, logger);
1372
+ let matchers = await traceProviderCall(
1146
1373
  {
1147
1374
  component: "action",
1148
- functionName: "autoRegisterWebhook",
1149
- message: `Registering webhook for trigger ${formatEntityLabel(action.name, action.key)}`,
1150
- successMessage: `Registered webhook for trigger ${formatEntityLabel(action.name, action.key)}`,
1151
- errorMessage: `Trigger ${formatEntityLabel(action.name, action.key)} failed while registering a webhook`,
1375
+ functionName: "routingMatchers",
1376
+ message: `Getting routing matchers for trigger group ${formatEntityLabel(group.name, group.key)}`,
1377
+ successMessage: (result) => `Retrieved ${result.length} routing matcher(s) for trigger group ${formatEntityLabel(group.name, group.key)}`,
1378
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while getting routing matchers`,
1152
1379
  metadata: {
1153
- actionId: action.key,
1154
- actionName: action.name,
1155
- actionType: action.type
1380
+ triggerGroupId: group.key,
1381
+ triggerGroupName: group.name
1156
1382
  },
1157
1383
  onSuccess: (result) => ({
1158
- hasRegistrationDetails: result.registrationDetails !== void 0,
1159
- hasState: result.state !== void 0
1384
+ matcherCount: result.length
1160
1385
  })
1161
1386
  },
1162
- () => runWithContext(context, () => action.autoRegisterWebhook(context))
1387
+ () => runWithContext(context, () => group.routingMatchers(context))
1163
1388
  );
1164
- return withRequestTraces(context, {
1165
- registrationDetails: res.registrationDetails,
1166
- state: res.state
1167
- });
1389
+ return withRequestTraces(context, { matchers });
1168
1390
  });
1169
- manager.onRequest("slates/action.trigger.webhook_unregister", async ({ params }) => {
1391
+ manager.onRequest("slates/trigger_group.polling.poll", async ({ params }) => {
1170
1392
  let ctx = getContextFull();
1171
- let action = getActionWithType(slate, "trigger", params.actionId);
1172
- if (!action.autoUnregisterWebhook) {
1393
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1394
+ if (group.source !== "polling" || !group.polling) {
1173
1395
  throw new ServiceError4(
1174
1396
  badRequestError3({
1175
- message: `Trigger action does not support webhook auto-unregistration: ${params.actionId}`
1397
+ message: `Trigger group does not support polling: ${params.triggerGroupId}`
1176
1398
  })
1177
1399
  );
1178
1400
  }
1179
1401
  let context = new SlateContext(
1180
1402
  ctx.config,
1181
- {
1182
- webhookBaseUrl: params.webhookBaseUrl,
1183
- registrationDetails: params.registrationDetails,
1184
- state: params.state
1185
- },
1403
+ { state: params.state },
1186
1404
  ctx.auth?.output,
1187
1405
  slate.spec,
1188
1406
  logger
1189
1407
  );
1190
- await traceProviderCall(
1408
+ let res = await traceProviderCall(
1191
1409
  {
1192
1410
  component: "action",
1193
- functionName: "autoUnregisterWebhook",
1194
- message: `Unregistering webhook for trigger ${formatEntityLabel(action.name, action.key)}`,
1195
- successMessage: `Unregistered webhook for trigger ${formatEntityLabel(action.name, action.key)}`,
1196
- errorMessage: `Trigger ${formatEntityLabel(action.name, action.key)} failed while unregistering a webhook`,
1411
+ functionName: "pollEvents",
1412
+ message: `Polling events for trigger group ${formatEntityLabel(group.name, group.key)}`,
1413
+ successMessage: (result) => `Polled ${result.events.length} event(s) for trigger group ${formatEntityLabel(group.name, group.key)}`,
1414
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while polling events`,
1197
1415
  metadata: {
1198
- actionId: action.key,
1199
- actionName: action.name,
1200
- actionType: action.type,
1201
- hasRegistrationDetails: params.registrationDetails !== null,
1416
+ triggerGroupId: group.key,
1417
+ triggerGroupName: group.name,
1202
1418
  hasPreviousState: params.state !== null
1203
- }
1419
+ },
1420
+ onSuccess: (result) => ({
1421
+ eventCount: result.events.length,
1422
+ hasUpdatedState: result.updatedState !== void 0
1423
+ })
1204
1424
  },
1205
- () => runWithContext(context, () => action.autoUnregisterWebhook(context))
1425
+ () => runWithContext(context, () => group.polling.pollEvents(context))
1206
1426
  );
1207
- return withRequestTraces(context, {});
1427
+ return withRequestTraces(context, {
1428
+ updatedState: res.updatedState,
1429
+ events: res.events.map((event) => ({
1430
+ payload: event.payload,
1431
+ idempotencyKey: event.idempotencyKey,
1432
+ triggerIds: evaluateTriggerMatches(slate, group.key, event.payload)
1433
+ }))
1434
+ });
1208
1435
  });
1209
1436
  });
1210
1437
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slates/provider-handler",
3
- "version": "1.0.0-rc.29",
3
+ "version": "1.0.0-rc.31",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -32,8 +32,8 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@lowerdeck/error": "^1.1.0",
35
- "@slates/proto": "1.0.0-rc.18",
36
- "@slates/provider": "1.0.0-rc.22",
35
+ "@slates/proto": "1.0.0-rc.19",
36
+ "@slates/provider": "1.0.0-rc.23",
37
37
  "p-queue": "^6.6.2",
38
38
  "zod": "^4.2.1"
39
39
  },