@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.
package/dist/index.cjs CHANGED
@@ -184,17 +184,57 @@ var mapAction = (_slate, a) => {
184
184
  ...base,
185
185
  type: "action.trigger",
186
186
  capabilities: {},
187
- invocation: a.source === "polling" ? {
188
- type: "polling",
189
- intervalSeconds: a.polling.intervalInSeconds ?? import_provider.SlateDefaultPollingIntervalSeconds
190
- } : {
191
- type: "webhook",
192
- autoRegistration: !!a.autoRegisterWebhook,
193
- autoUnregistration: !!a.autoUnregisterWebhook,
194
- http: a.http
195
- }
187
+ triggerGroupId: a.triggerGroup.key
196
188
  };
197
189
  };
190
+ var getTriggerGroup = (slate, triggerGroupId) => {
191
+ let group = slate.triggerGroups.find((g) => g.key === triggerGroupId);
192
+ if (!group) {
193
+ throw new import_error2.ServiceError((0, import_error2.notFoundError)(`trigger_group`, triggerGroupId));
194
+ }
195
+ return group;
196
+ };
197
+ var getTriggersForGroup = (slate, triggerGroupId) => slate.actions.filter(
198
+ (action) => action.type === "trigger" && action.triggerGroup.key === triggerGroupId
199
+ );
200
+ var evaluateTriggerMatches = (slate, triggerGroupId, payload) => getTriggersForGroup(slate, triggerGroupId).filter((trigger) => trigger.matches(payload)).map((trigger) => trigger.key);
201
+ var getWebhookAutoRegistration = (group) => {
202
+ if (group.source !== "webhook" || !group.webhook?.autoRegistration) {
203
+ throw new import_error2.ServiceError(
204
+ (0, import_error2.badRequestError)({
205
+ message: `Trigger group does not support webhook auto-registration: ${group.key}`
206
+ })
207
+ );
208
+ }
209
+ return group.webhook.autoRegistration;
210
+ };
211
+ var getWebhookManualRegistration = (group) => {
212
+ if (group.source !== "webhook" || !group.webhook?.manualRegistration) {
213
+ throw new import_error2.ServiceError(
214
+ (0, import_error2.badRequestError)({
215
+ message: `Trigger group does not support manual webhook registration: ${group.key}`
216
+ })
217
+ );
218
+ }
219
+ return group.webhook.manualRegistration;
220
+ };
221
+ var mapTriggerGroup = (group) => ({
222
+ id: group.key,
223
+ name: group.name,
224
+ description: group.description,
225
+ metadata: group.metadata,
226
+ invocation: group.source === "polling" ? {
227
+ type: "polling",
228
+ intervalSeconds: group.polling?.intervalSeconds ?? import_provider.SlateDefaultPollingIntervalSeconds
229
+ } : {
230
+ type: "webhook",
231
+ registration: group.webhook?.manualRegistration ? {
232
+ mode: "manual",
233
+ userConfigSchema: toJsonSchema(group.webhook.manualRegistration.userConfigSchema),
234
+ fullConfigSchema: toJsonSchema(group.webhook.manualRegistration.fullConfigSchema)
235
+ } : { mode: "auto" }
236
+ }
237
+ });
198
238
 
199
239
  // src/state.ts
200
240
  var State = class {
@@ -374,6 +414,7 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
374
414
  maxAttachmentSizeBytes: directUpload.maxAttachmentSizeBytes ?? DEFAULT_MAX_ATTACHMENT_SIZE_BYTES
375
415
  };
376
416
  };
417
+ let supportsTriggerGroups = () => !!hubCapabilities.get()?.triggers;
377
418
  let logger = new import_provider2.SlateLogger(listeners);
378
419
  let providerTrace = {
379
420
  providerId: slate.spec.key,
@@ -514,6 +555,9 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
514
555
  hub: {
515
556
  capabilitiesNotification: true,
516
557
  liveInvocation: true
558
+ },
559
+ provider: {
560
+ triggerGroups: true
517
561
  }
518
562
  }
519
563
  }));
@@ -925,6 +969,9 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
925
969
  manager.onRequest("slates/actions.list", async ({ params }) => {
926
970
  getContextBasic();
927
971
  let actions = params.includeAdapterActions ? slate.actions : slate.actions.filter((action) => !action.adapter);
972
+ if (!supportsTriggerGroups()) {
973
+ actions = actions.filter((action) => action.type !== "trigger");
974
+ }
928
975
  return {
929
976
  actions: actions.map((a) => mapAction(slate, a))
930
977
  };
@@ -949,6 +996,19 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
949
996
  action: mapAction(slate, action)
950
997
  };
951
998
  });
999
+ manager.onRequest("slates/trigger_groups.list", async () => {
1000
+ getContextBasic();
1001
+ return {
1002
+ triggerGroups: slate.triggerGroups.map(mapTriggerGroup)
1003
+ };
1004
+ });
1005
+ manager.onRequest("slates/trigger_group.get", async ({ params }) => {
1006
+ getContextBasic();
1007
+ let triggerGroup = getTriggerGroup(slate, params.triggerGroupId);
1008
+ return {
1009
+ triggerGroup: mapTriggerGroup(triggerGroup)
1010
+ };
1011
+ });
952
1012
  manager.onRequest("slates/action.tool.invoke", async ({ params }) => {
953
1013
  let action = getActionWithType(slate, "tool", params.actionId);
954
1014
  let input = validate(
@@ -1045,23 +1105,61 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
1045
1105
  outputKeyCount: getObjectKeyCount(result.output)
1046
1106
  })
1047
1107
  },
1048
- () => (0, import_provider2.runWithContext)(context, () => action.handleEvent(context))
1108
+ () => (0, import_provider2.runWithContext)(context, () => action.map(context))
1049
1109
  );
1050
1110
  return withRequestTraces(context, { id: res.id, type: res.type, output: res.output });
1051
1111
  });
1052
1112
  manager.onRequest("slates/action.trigger.poll_events", async ({ params }) => {
1053
- let ctx = getContextFull();
1054
- let action = getActionWithType(slate, "trigger", params.actionId);
1055
- if (!action.pollEvents) {
1113
+ getContextBasic();
1114
+ if (supportsTriggerGroups()) {
1115
+ throw new import_error4.ServiceError(
1116
+ (0, import_error4.badRequestError)({
1117
+ message: `Legacy trigger polling is disabled once trigger_group support is announced: ${params.actionId}`
1118
+ })
1119
+ );
1120
+ }
1121
+ return { inputs: [], updatedState: params.state };
1122
+ });
1123
+ manager.onRequest("slates/action.trigger.webhook_handle", async ({ params }) => {
1124
+ getContextBasic();
1125
+ if (supportsTriggerGroups()) {
1126
+ throw new import_error4.ServiceError(
1127
+ (0, import_error4.badRequestError)({
1128
+ message: `Legacy trigger webhook handling is disabled once trigger_group support is announced: ${params.actionId}`
1129
+ })
1130
+ );
1131
+ }
1132
+ return { inputs: [], updatedState: params.state, response: null };
1133
+ });
1134
+ manager.onRequest("slates/action.trigger.webhook_register", async ({ params }) => {
1135
+ getContextBasic();
1136
+ if (supportsTriggerGroups()) {
1056
1137
  throw new import_error4.ServiceError(
1057
1138
  (0, import_error4.badRequestError)({
1058
- message: `Trigger action does not support polling: ${params.actionId}`
1139
+ message: `Legacy trigger webhook registration is disabled once trigger_group support is announced: ${params.actionId}`
1059
1140
  })
1060
1141
  );
1061
1142
  }
1143
+ return { registrationDetails: null };
1144
+ });
1145
+ manager.onRequest("slates/action.trigger.webhook_unregister", async ({ params }) => {
1146
+ getContextBasic();
1147
+ if (supportsTriggerGroups()) {
1148
+ throw new import_error4.ServiceError(
1149
+ (0, import_error4.badRequestError)({
1150
+ message: `Legacy trigger webhook unregistration is disabled once trigger_group support is announced: ${params.actionId}`
1151
+ })
1152
+ );
1153
+ }
1154
+ return {};
1155
+ });
1156
+ manager.onRequest("slates/trigger_group.webhook.targets_list", async ({ params }) => {
1157
+ let ctx = getContextFull();
1158
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1159
+ let autoRegistration = getWebhookAutoRegistration(group);
1062
1160
  let context = new import_provider2.SlateContext(
1063
1161
  ctx.config,
1064
- { state: params.state },
1162
+ { pageToken: params.pageToken ?? null },
1065
1163
  ctx.auth?.output,
1066
1164
  slate.spec,
1067
1165
  logger
@@ -1069,35 +1167,168 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
1069
1167
  let res = await traceProviderCall(
1070
1168
  {
1071
1169
  component: "action",
1072
- functionName: "pollEvents",
1073
- message: `Polling events for trigger ${formatEntityLabel(action.name, action.key)}`,
1074
- successMessage: (result) => `Polled ${result.inputs.length} event(s) for trigger ${formatEntityLabel(action.name, action.key)}`,
1075
- errorMessage: `Trigger ${formatEntityLabel(action.name, action.key)} failed while polling events`,
1170
+ functionName: "webhookTargetList",
1171
+ message: `Listing webhook targets for trigger group ${formatEntityLabel(group.name, group.key)}`,
1172
+ successMessage: (result) => `Listed ${result.targets.length} webhook target(s) for trigger group ${formatEntityLabel(group.name, group.key)}`,
1173
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while listing webhook targets`,
1076
1174
  metadata: {
1077
- actionId: action.key,
1078
- actionName: action.name,
1079
- actionType: action.type,
1080
- hasPreviousState: params.state !== null
1175
+ triggerGroupId: group.key,
1176
+ triggerGroupName: group.name
1081
1177
  },
1082
1178
  onSuccess: (result) => ({
1083
- inputCount: result.inputs.length,
1084
- hasUpdatedState: result.updatedState !== void 0
1179
+ targetCount: result.targets.length,
1180
+ hasNextPageToken: result.nextPageToken !== null
1085
1181
  })
1086
1182
  },
1087
- () => (0, import_provider2.runWithContext)(context, () => action.pollEvents(context))
1183
+ () => (0, import_provider2.runWithContext)(context, () => autoRegistration.webhookTargetList(context))
1088
1184
  );
1089
1185
  return withRequestTraces(context, {
1090
- inputs: res.inputs,
1091
- updatedState: res.updatedState
1186
+ targets: res.targets,
1187
+ nextPageToken: res.nextPageToken ?? null
1092
1188
  });
1093
1189
  });
1094
- manager.onRequest("slates/action.trigger.webhook_handle", async ({ params }) => {
1190
+ manager.onRequest("slates/trigger_group.webhook.register", async ({ params }) => {
1095
1191
  let ctx = getContextFull();
1096
- let action = getActionWithType(slate, "trigger", params.actionId);
1097
- if (!action.handleRequest) {
1192
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1193
+ let autoRegistration = getWebhookAutoRegistration(group);
1194
+ let context = new import_provider2.SlateContext(
1195
+ ctx.config,
1196
+ {
1197
+ webhookTargetIdentifier: params.webhookTargetIdentifier,
1198
+ webhookTargetPayload: params.webhookTargetPayload,
1199
+ webhookUrl: params.webhookUrl
1200
+ },
1201
+ ctx.auth?.output,
1202
+ slate.spec,
1203
+ logger
1204
+ );
1205
+ let res = await traceProviderCall(
1206
+ {
1207
+ component: "action",
1208
+ functionName: "webhookRegister",
1209
+ message: `Registering webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
1210
+ successMessage: `Registered webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
1211
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while registering a webhook`,
1212
+ metadata: {
1213
+ triggerGroupId: group.key,
1214
+ triggerGroupName: group.name,
1215
+ webhookTargetIdentifier: params.webhookTargetIdentifier
1216
+ }
1217
+ },
1218
+ () => (0, import_provider2.runWithContext)(context, () => autoRegistration.webhookRegister(context))
1219
+ );
1220
+ return withRequestTraces(context, {
1221
+ webhookRegistrationIdentifier: res.webhookRegistrationIdentifier,
1222
+ webhookRegistrationPayload: res.webhookRegistrationPayload
1223
+ });
1224
+ });
1225
+ manager.onRequest("slates/trigger_group.webhook.unregister", async ({ params }) => {
1226
+ let ctx = getContextFull();
1227
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1228
+ let autoRegistration = getWebhookAutoRegistration(group);
1229
+ let context = new import_provider2.SlateContext(
1230
+ ctx.config,
1231
+ {
1232
+ webhookRegistrationIdentifier: params.webhookRegistrationIdentifier,
1233
+ webhookRegistrationPayload: params.webhookRegistrationPayload
1234
+ },
1235
+ ctx.auth?.output,
1236
+ slate.spec,
1237
+ logger
1238
+ );
1239
+ await traceProviderCall(
1240
+ {
1241
+ component: "action",
1242
+ functionName: "webhookUnregister",
1243
+ message: `Unregistering webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
1244
+ successMessage: `Unregistered webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
1245
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while unregistering a webhook`,
1246
+ metadata: {
1247
+ triggerGroupId: group.key,
1248
+ triggerGroupName: group.name,
1249
+ webhookRegistrationIdentifier: params.webhookRegistrationIdentifier
1250
+ }
1251
+ },
1252
+ () => (0, import_provider2.runWithContext)(context, () => autoRegistration.webhookUnregister(context))
1253
+ );
1254
+ return withRequestTraces(context, {});
1255
+ });
1256
+ manager.onRequest("slates/trigger_group.webhook.manual_setup", async ({ params }) => {
1257
+ getContextBasic();
1258
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1259
+ let manualRegistration = getWebhookManualRegistration(group);
1260
+ let context = new import_provider2.SlateContext(
1261
+ {},
1262
+ { webhookUrl: params.webhookUrl },
1263
+ {},
1264
+ slate.spec,
1265
+ logger
1266
+ );
1267
+ let res = await traceProviderCall(
1268
+ {
1269
+ component: "action",
1270
+ functionName: "webhookManualSetup",
1271
+ message: `Building manual webhook setup for trigger group ${formatEntityLabel(group.name, group.key)}`,
1272
+ successMessage: `Built manual webhook setup for trigger group ${formatEntityLabel(group.name, group.key)}`,
1273
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while building a manual webhook setup`,
1274
+ metadata: {
1275
+ triggerGroupId: group.key,
1276
+ triggerGroupName: group.name
1277
+ }
1278
+ },
1279
+ () => (0, import_provider2.runWithContext)(context, () => manualRegistration.setup(context))
1280
+ );
1281
+ return {
1282
+ webhookSetupDocument: res.webhookSetupDocument,
1283
+ partialWebhookRegistrationPayload: res.partialWebhookRegistrationPayload
1284
+ };
1285
+ });
1286
+ manager.onRequest("slates/trigger_group.webhook.manual_finish", async ({ params }) => {
1287
+ getContextBasic();
1288
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1289
+ let manualRegistration = getWebhookManualRegistration(group);
1290
+ if (!manualRegistration.finish) {
1098
1291
  throw new import_error4.ServiceError(
1099
1292
  (0, import_error4.badRequestError)({
1100
- message: `Trigger action does not support webhook requests: ${params.actionId}`
1293
+ message: `Trigger group does not support manual webhook finish: ${params.triggerGroupId}`
1294
+ })
1295
+ );
1296
+ }
1297
+ let context = new import_provider2.SlateContext(
1298
+ {},
1299
+ {
1300
+ webhookUrl: params.webhookUrl,
1301
+ partialWebhookRegistrationPayload: params.partialWebhookRegistrationPayload,
1302
+ userWebhookRegistrationPayload: params.userWebhookRegistrationPayload
1303
+ },
1304
+ {},
1305
+ slate.spec,
1306
+ logger
1307
+ );
1308
+ let res = await traceProviderCall(
1309
+ {
1310
+ component: "action",
1311
+ functionName: "webhookManualFinish",
1312
+ message: `Finishing manual webhook setup for trigger group ${formatEntityLabel(group.name, group.key)}`,
1313
+ successMessage: `Finished manual webhook setup for trigger group ${formatEntityLabel(group.name, group.key)}`,
1314
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while finishing a manual webhook setup`,
1315
+ metadata: {
1316
+ triggerGroupId: group.key,
1317
+ triggerGroupName: group.name
1318
+ }
1319
+ },
1320
+ () => (0, import_provider2.runWithContext)(context, () => manualRegistration.finish(context))
1321
+ );
1322
+ return withRequestTraces(context, {
1323
+ webhookRegistrationPayload: res.webhookRegistrationPayload
1324
+ });
1325
+ });
1326
+ manager.onRequest("slates/trigger_group.webhook.process", async ({ params }) => {
1327
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1328
+ if (group.source !== "webhook" || !group.webhook) {
1329
+ throw new import_error4.ServiceError(
1330
+ (0, import_error4.badRequestError)({
1331
+ message: `Trigger group does not support webhook processing: ${params.triggerGroupId}`
1101
1332
  })
1102
1333
  );
1103
1334
  }
@@ -1107,126 +1338,122 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
1107
1338
  body: params.body ? Uint8Array.from(atob(params.body.content), (c) => c.charCodeAt(0)) : null
1108
1339
  });
1109
1340
  let context = new import_provider2.SlateContext(
1110
- ctx.config,
1341
+ {},
1111
1342
  {
1112
1343
  request: req,
1113
- state: params.state,
1114
- registrationDetails: params.registrationDetails ?? null
1344
+ webhookRegistrationPayload: params.webhookRegistrationPayload
1115
1345
  },
1116
- ctx.auth?.output,
1346
+ {},
1117
1347
  slate.spec,
1118
1348
  logger
1119
1349
  );
1120
1350
  let res = await traceProviderCall(
1121
1351
  {
1122
1352
  component: "action",
1123
- functionName: "handleRequest",
1124
- message: `Handling webhook request for trigger ${formatEntityLabel(action.name, action.key)}`,
1125
- successMessage: (result) => `Received ${result.inputs.length} webhook event(s) for trigger ${formatEntityLabel(action.name, action.key)}`,
1126
- errorMessage: `Trigger ${formatEntityLabel(action.name, action.key)} failed while handling a webhook request`,
1353
+ functionName: "webhookProcess",
1354
+ message: `Processing webhook request for trigger group ${formatEntityLabel(group.name, group.key)}`,
1355
+ successMessage: (result) => `Extracted ${result.events.length} event(s) from webhook request for trigger group ${formatEntityLabel(group.name, group.key)}`,
1356
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while processing a webhook request`,
1127
1357
  metadata: {
1128
- actionId: action.key,
1129
- actionName: action.name,
1130
- actionType: action.type,
1358
+ triggerGroupId: group.key,
1359
+ triggerGroupName: group.name,
1131
1360
  requestMethod: params.method,
1132
- hasRequestBody: !!params.body,
1133
- hasPreviousState: params.state !== null
1361
+ hasRequestBody: !!params.body
1134
1362
  },
1135
1363
  onSuccess: (result) => ({
1136
- inputCount: result.inputs.length,
1137
- hasUpdatedState: result.updatedState !== void 0,
1364
+ eventCount: result.events.length,
1138
1365
  hasResponse: result.response !== void 0
1139
1366
  })
1140
1367
  },
1141
- () => (0, import_provider2.runWithContext)(context, () => action.handleRequest(context))
1368
+ () => (0, import_provider2.runWithContext)(context, () => group.webhook.process(context))
1142
1369
  );
1370
+ for (let event of res.events) {
1371
+ if (!event.matchers) {
1372
+ throw new import_error4.ServiceError(
1373
+ (0, import_error4.preconditionFailedError)({
1374
+ message: `Trigger group "${group.key}" process handler must return matchers for every event (return [] if there is nothing to assert)`
1375
+ })
1376
+ );
1377
+ }
1378
+ }
1143
1379
  let response = res.response === void 0 ? void 0 : await serializeWebhookHttpResponse(res.response);
1144
1380
  return withRequestTraces(context, {
1145
- inputs: res.inputs,
1146
- updatedState: res.updatedState,
1381
+ events: res.events.map((event) => ({
1382
+ matchers: event.matchers,
1383
+ payload: event.payload,
1384
+ idempotencyKey: event.idempotencyKey,
1385
+ triggerIds: evaluateTriggerMatches(slate, group.key, event.payload)
1386
+ })),
1147
1387
  response
1148
1388
  });
1149
1389
  });
1150
- manager.onRequest("slates/action.trigger.webhook_register", async ({ params }) => {
1390
+ manager.onRequest("slates/trigger_group.routing_matchers.get", async ({ params }) => {
1151
1391
  let ctx = getContextFull();
1152
- let action = getActionWithType(slate, "trigger", params.actionId);
1153
- if (!action.autoRegisterWebhook) {
1154
- throw new import_error4.ServiceError(
1155
- (0, import_error4.badRequestError)({
1156
- message: `Trigger action does not support webhook auto-registration: ${params.actionId}`
1157
- })
1158
- );
1159
- }
1160
- let context = new import_provider2.SlateContext(
1161
- ctx.config,
1162
- { webhookBaseUrl: params.webhookBaseUrl },
1163
- ctx.auth?.output,
1164
- slate.spec,
1165
- logger
1166
- );
1167
- let res = await traceProviderCall(
1392
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1393
+ let context = new import_provider2.SlateContext(ctx.config, {}, ctx.auth?.output, slate.spec, logger);
1394
+ let matchers = await traceProviderCall(
1168
1395
  {
1169
1396
  component: "action",
1170
- functionName: "autoRegisterWebhook",
1171
- message: `Registering webhook for trigger ${formatEntityLabel(action.name, action.key)}`,
1172
- successMessage: `Registered webhook for trigger ${formatEntityLabel(action.name, action.key)}`,
1173
- errorMessage: `Trigger ${formatEntityLabel(action.name, action.key)} failed while registering a webhook`,
1397
+ functionName: "routingMatchers",
1398
+ message: `Getting routing matchers for trigger group ${formatEntityLabel(group.name, group.key)}`,
1399
+ successMessage: (result) => `Retrieved ${result.length} routing matcher(s) for trigger group ${formatEntityLabel(group.name, group.key)}`,
1400
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while getting routing matchers`,
1174
1401
  metadata: {
1175
- actionId: action.key,
1176
- actionName: action.name,
1177
- actionType: action.type
1402
+ triggerGroupId: group.key,
1403
+ triggerGroupName: group.name
1178
1404
  },
1179
1405
  onSuccess: (result) => ({
1180
- hasRegistrationDetails: result.registrationDetails !== void 0,
1181
- hasState: result.state !== void 0
1406
+ matcherCount: result.length
1182
1407
  })
1183
1408
  },
1184
- () => (0, import_provider2.runWithContext)(context, () => action.autoRegisterWebhook(context))
1409
+ () => (0, import_provider2.runWithContext)(context, () => group.routingMatchers(context))
1185
1410
  );
1186
- return withRequestTraces(context, {
1187
- registrationDetails: res.registrationDetails,
1188
- state: res.state
1189
- });
1411
+ return withRequestTraces(context, { matchers });
1190
1412
  });
1191
- manager.onRequest("slates/action.trigger.webhook_unregister", async ({ params }) => {
1413
+ manager.onRequest("slates/trigger_group.polling.poll", async ({ params }) => {
1192
1414
  let ctx = getContextFull();
1193
- let action = getActionWithType(slate, "trigger", params.actionId);
1194
- if (!action.autoUnregisterWebhook) {
1415
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1416
+ if (group.source !== "polling" || !group.polling) {
1195
1417
  throw new import_error4.ServiceError(
1196
1418
  (0, import_error4.badRequestError)({
1197
- message: `Trigger action does not support webhook auto-unregistration: ${params.actionId}`
1419
+ message: `Trigger group does not support polling: ${params.triggerGroupId}`
1198
1420
  })
1199
1421
  );
1200
1422
  }
1201
1423
  let context = new import_provider2.SlateContext(
1202
1424
  ctx.config,
1203
- {
1204
- webhookBaseUrl: params.webhookBaseUrl,
1205
- registrationDetails: params.registrationDetails,
1206
- state: params.state
1207
- },
1425
+ { state: params.state },
1208
1426
  ctx.auth?.output,
1209
1427
  slate.spec,
1210
1428
  logger
1211
1429
  );
1212
- await traceProviderCall(
1430
+ let res = await traceProviderCall(
1213
1431
  {
1214
1432
  component: "action",
1215
- functionName: "autoUnregisterWebhook",
1216
- message: `Unregistering webhook for trigger ${formatEntityLabel(action.name, action.key)}`,
1217
- successMessage: `Unregistered webhook for trigger ${formatEntityLabel(action.name, action.key)}`,
1218
- errorMessage: `Trigger ${formatEntityLabel(action.name, action.key)} failed while unregistering a webhook`,
1433
+ functionName: "pollEvents",
1434
+ message: `Polling events for trigger group ${formatEntityLabel(group.name, group.key)}`,
1435
+ successMessage: (result) => `Polled ${result.events.length} event(s) for trigger group ${formatEntityLabel(group.name, group.key)}`,
1436
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while polling events`,
1219
1437
  metadata: {
1220
- actionId: action.key,
1221
- actionName: action.name,
1222
- actionType: action.type,
1223
- hasRegistrationDetails: params.registrationDetails !== null,
1438
+ triggerGroupId: group.key,
1439
+ triggerGroupName: group.name,
1224
1440
  hasPreviousState: params.state !== null
1225
- }
1441
+ },
1442
+ onSuccess: (result) => ({
1443
+ eventCount: result.events.length,
1444
+ hasUpdatedState: result.updatedState !== void 0
1445
+ })
1226
1446
  },
1227
- () => (0, import_provider2.runWithContext)(context, () => action.autoUnregisterWebhook(context))
1447
+ () => (0, import_provider2.runWithContext)(context, () => group.polling.pollEvents(context))
1228
1448
  );
1229
- return withRequestTraces(context, {});
1449
+ return withRequestTraces(context, {
1450
+ updatedState: res.updatedState,
1451
+ events: res.events.map((event) => ({
1452
+ payload: event.payload,
1453
+ idempotencyKey: event.idempotencyKey,
1454
+ triggerIds: evaluateTriggerMatches(slate, group.key, event.payload)
1455
+ }))
1456
+ });
1230
1457
  });
1231
1458
  });
1232
1459
  // Annotate the CommonJS export names for ESM import in node: