@slates/provider-handler 1.0.0-rc.43 → 1.0.0-rc.44

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
@@ -77,7 +77,8 @@ var validate = (schema, data, entity, message) => {
77
77
  }
78
78
  return result.data;
79
79
  };
80
- var toJsonSchema = (schema) => schema.toJSONSchema({
80
+ var toJsonSchema = (schema, io = "output") => schema.toJSONSchema({
81
+ io,
81
82
  unrepresentable: "any",
82
83
  override: (ctx) => {
83
84
  let def = ctx.zodSchema._zod.def;
@@ -240,15 +241,30 @@ var getWebhookAutoRegistration = (group) => {
240
241
  return group.webhook.autoRegistration;
241
242
  };
242
243
  var getWebhookManualRegistration = (group) => {
243
- if (group.source !== "webhook" || !group.webhook?.manualRegistration) {
244
+ let registration = group.source === "webhook" ? group.webhook?.manualRegistration ?? group.webhook?.deliveryConfig : void 0;
245
+ if (!registration) {
244
246
  throw new import_error2.ServiceError(
245
247
  (0, import_error2.badRequestError)({
246
248
  message: `Trigger group does not support manual webhook registration: ${group.key}`
247
249
  })
248
250
  );
249
251
  }
250
- return group.webhook.manualRegistration;
252
+ return registration;
251
253
  };
254
+ var getWebhookDeliveryConfig = (group) => {
255
+ if (group.source !== "webhook" || !group.webhook?.deliveryConfig) {
256
+ throw new import_error2.ServiceError(
257
+ (0, import_error2.badRequestError)({
258
+ message: `Trigger group does not support webhook delivery authentication: ${group.key}`
259
+ })
260
+ );
261
+ }
262
+ return group.webhook.deliveryConfig;
263
+ };
264
+ var mapWebhookConfigSchemas = (config) => ({
265
+ userConfigSchema: toJsonSchema(config.userConfigSchema),
266
+ fullConfigSchema: toJsonSchema(config.fullConfigSchema)
267
+ });
252
268
  var mapToolCategory = (category) => ({
253
269
  id: category.key,
254
270
  name: category.name,
@@ -268,20 +284,24 @@ var mapTriggerGroup = (group) => ({
268
284
  name: group.name,
269
285
  description: group.description,
270
286
  metadata: group.metadata,
287
+ ...group.selectionSchema ? { selectionSchema: toJsonSchema(group.selectionSchema, "input") } : {},
271
288
  invocation: group.source === "polling" ? {
272
289
  type: "polling",
273
290
  intervalSeconds: group.polling?.intervalSeconds ?? import_provider.SlateDefaultPollingIntervalSeconds
274
291
  } : group.source === "gateway" ? { type: "gateway" } : {
275
292
  type: "webhook",
293
+ ...group.webhook?.expandWebhook ? { supportsExpansion: true } : {},
294
+ ...group.webhook?.autoRegistration?.webhookRenew ? { supportsRenewal: true } : {},
295
+ ...group.webhook?.reconcileIntervalSeconds !== void 0 ? { reconcileIntervalSeconds: group.webhook.reconcileIntervalSeconds } : {},
276
296
  registration: group.webhook?.manualRegistration ? {
277
297
  mode: "manual",
278
- userConfigSchema: toJsonSchema(
279
- group.webhook.manualRegistration.userConfigSchema
280
- ),
281
- fullConfigSchema: toJsonSchema(
282
- group.webhook.manualRegistration.fullConfigSchema
283
- )
284
- } : { mode: "auto" }
298
+ ...mapWebhookConfigSchemas(group.webhook.manualRegistration)
299
+ } : {
300
+ mode: "auto",
301
+ ...group.webhook?.deliveryConfig ? {
302
+ deliveryConfig: mapWebhookConfigSchemas(group.webhook.deliveryConfig)
303
+ } : {}
304
+ }
285
305
  }
286
306
  });
287
307
 
@@ -358,6 +378,23 @@ var serializeWebhookHttpResponse = async (response) => {
358
378
 
359
379
  // src/index.ts
360
380
  var DEFAULT_MAX_ATTACHMENT_SIZE_BYTES = 1e8;
381
+ var validateTriggerGroupSelection = (group, selection) => group.selectionSchema ? validate(
382
+ group.selectionSchema,
383
+ selection === void 0 ? {} : selection,
384
+ "trigger_group.selection",
385
+ `Invalid selection for trigger group "${group.key}"`
386
+ ) : selection ?? {};
387
+ var validateWebhookRegistration = (result) => validate(
388
+ import_proto.slatesTriggerGroupWebhookRegistrationResult,
389
+ result,
390
+ "trigger_group.webhook.registration",
391
+ "Webhook registration returned an invalid result"
392
+ );
393
+ var toWebhookRequest = (params) => new Request(params.url, {
394
+ method: params.method,
395
+ headers: params.headers,
396
+ body: params.body ? Uint8Array.from(atob(params.body.content), (c) => c.charCodeAt(0)) : null
397
+ });
361
398
  var routeAttachmentsThroughDirectUpload = async (attachments, live) => {
362
399
  if (!attachments || attachments.length === 0 || !live) return attachments;
363
400
  let contentEntries = attachments.map((attachment, index) => ({ attachment, index })).filter((entry) => entry.attachment.content.type === "content");
@@ -1324,7 +1361,10 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
1324
1361
  let autoRegistration = getWebhookAutoRegistration(group);
1325
1362
  let context = createContext(
1326
1363
  ctx.config,
1327
- { pageToken: params.pageToken ?? null },
1364
+ {
1365
+ pageToken: params.pageToken ?? null,
1366
+ selection: validateTriggerGroupSelection(group, params.selection)
1367
+ },
1328
1368
  ctx.auth?.output
1329
1369
  );
1330
1370
  let res = await traceProviderCall(
@@ -1360,7 +1400,10 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
1360
1400
  {
1361
1401
  webhookTargetIdentifier: params.webhookTargetIdentifier,
1362
1402
  webhookTargetPayload: params.webhookTargetPayload,
1363
- webhookUrl: params.webhookUrl
1403
+ webhookUrl: params.webhookUrl,
1404
+ operationId: params.operationId,
1405
+ selection: validateTriggerGroupSelection(group, params.selection),
1406
+ deliveryConfig: params.deliveryConfig
1364
1407
  },
1365
1408
  ctx.auth?.output
1366
1409
  );
@@ -1377,12 +1420,54 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
1377
1420
  webhookTargetIdentifier: params.webhookTargetIdentifier
1378
1421
  }
1379
1422
  },
1380
- () => (0, import_provider2.runWithContext)(context, () => autoRegistration.webhookRegister(context))
1423
+ () => (0, import_provider2.runWithContext)(
1424
+ context,
1425
+ async () => validateWebhookRegistration(await autoRegistration.webhookRegister(context))
1426
+ )
1381
1427
  );
1382
- return withRequestTraces(context, {
1383
- webhookRegistrationIdentifier: res.webhookRegistrationIdentifier,
1384
- webhookRegistrationPayload: res.webhookRegistrationPayload
1385
- });
1428
+ return withRequestTraces(context, res);
1429
+ });
1430
+ manager.onRequest("slates/trigger_group.webhook.renew", async ({ params }) => {
1431
+ let ctx = getContextFull();
1432
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1433
+ let autoRegistration = getWebhookAutoRegistration(group);
1434
+ let renew = autoRegistration.webhookRenew;
1435
+ if (!renew) {
1436
+ throw new import_error4.ServiceError(
1437
+ (0, import_error4.badRequestError)({
1438
+ message: `Trigger group does not support webhook renewal: ${params.triggerGroupId}`
1439
+ })
1440
+ );
1441
+ }
1442
+ let context = createContext(
1443
+ ctx.config,
1444
+ {
1445
+ webhookRegistrationIdentifier: params.webhookRegistrationIdentifier,
1446
+ webhookRegistrationPayload: params.webhookRegistrationPayload,
1447
+ webhookUrl: params.webhookUrl,
1448
+ webhookTargetIdentifier: params.webhookTargetIdentifier,
1449
+ webhookTargetPayload: params.webhookTargetPayload,
1450
+ operationId: params.operationId,
1451
+ selection: validateTriggerGroupSelection(group, params.selection),
1452
+ deliveryConfig: params.deliveryConfig
1453
+ },
1454
+ ctx.auth?.output
1455
+ );
1456
+ let res = await traceProviderCall(
1457
+ {
1458
+ component: "action",
1459
+ functionName: "webhookRenew",
1460
+ message: `Renewing webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
1461
+ successMessage: `Renewed webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
1462
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while renewing a webhook`,
1463
+ metadata: { triggerGroupId: group.key, triggerGroupName: group.name }
1464
+ },
1465
+ () => (0, import_provider2.runWithContext)(
1466
+ context,
1467
+ async () => validateWebhookRegistration(await renew(context))
1468
+ )
1469
+ );
1470
+ return withRequestTraces(context, res);
1386
1471
  });
1387
1472
  manager.onRequest("slates/trigger_group.webhook.unregister", async ({ params }) => {
1388
1473
  let ctx = getContextFull();
@@ -1484,15 +1569,10 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
1484
1569
  })
1485
1570
  );
1486
1571
  }
1487
- let req = new Request(params.url, {
1488
- method: params.method,
1489
- headers: params.headers,
1490
- body: params.body ? Uint8Array.from(atob(params.body.content), (c) => c.charCodeAt(0)) : null
1491
- });
1492
1572
  let context = createContext(
1493
1573
  {},
1494
1574
  {
1495
- request: req,
1575
+ request: toWebhookRequest(params),
1496
1576
  webhookRegistrationPayload: params.webhookRegistrationPayload
1497
1577
  },
1498
1578
  {}
@@ -1533,12 +1613,106 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
1533
1613
  matchers: event.matchers,
1534
1614
  payload: event.payload,
1535
1615
  idempotencyKey: event.idempotencyKey,
1536
- triggerIds: evaluateTriggerMatches(slate, group.key, event.payload)
1616
+ triggerIds: group.webhook?.expandWebhook ? [] : evaluateTriggerMatches(slate, group.key, event.payload)
1537
1617
  })),
1618
+ ...group.webhook?.expandWebhook ? { requiresExpansion: true } : {},
1538
1619
  response,
1539
1620
  skipped: res.skipped ?? null
1540
1621
  });
1541
1622
  });
1623
+ manager.onRequest(
1624
+ "slates/trigger_group.webhook.delivery_authenticate",
1625
+ async ({ params }) => {
1626
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1627
+ let deliveryConfig = getWebhookDeliveryConfig(group);
1628
+ let context = createContext(
1629
+ {},
1630
+ {
1631
+ request: toWebhookRequest(params),
1632
+ deliveryConfig: params.deliveryConfig
1633
+ },
1634
+ {}
1635
+ );
1636
+ let res = await traceProviderCall(
1637
+ {
1638
+ component: "action",
1639
+ functionName: "webhookDeliveryAuthenticate",
1640
+ message: `Authenticating a delivery for trigger group ${formatEntityLabel(group.name, group.key)}`,
1641
+ successMessage: (result) => result.rejected ? `Rejected a delivery with status ${result.rejected.status} for trigger group ${formatEntityLabel(group.name, group.key)}` : `Authenticated a delivery for ${result.routingKeys.length} routing key(s) for trigger group ${formatEntityLabel(group.name, group.key)}`,
1642
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while authenticating a delivery`,
1643
+ metadata: {
1644
+ triggerGroupId: group.key,
1645
+ triggerGroupName: group.name,
1646
+ requestMethod: params.method,
1647
+ hasRequestBody: !!params.body
1648
+ },
1649
+ onSuccess: (result) => ({
1650
+ routingKeyCount: result.routingKeys.length,
1651
+ rejectedStatus: result.rejected?.status ?? null
1652
+ })
1653
+ },
1654
+ () => (0, import_provider2.runWithContext)(context, async () => {
1655
+ let authentication = await deliveryConfig.authenticate(context);
1656
+ return validate(
1657
+ import_proto.slatesTriggerGroupWebhookDeliveryAuthentication,
1658
+ authentication.rejected ? { routingKeys: [], rejected: authentication.rejected } : { routingKeys: authentication.routingKeys, rejected: null },
1659
+ "trigger_group.webhook.delivery_authentication",
1660
+ "Webhook delivery authentication returned an invalid result"
1661
+ );
1662
+ })
1663
+ );
1664
+ return withRequestTraces(context, res);
1665
+ }
1666
+ );
1667
+ manager.onRequest("slates/trigger_group.webhook.expand", async ({ params }) => {
1668
+ let ctx = getContextFull();
1669
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1670
+ let expand = group.source === "webhook" ? group.webhook?.expandWebhook : void 0;
1671
+ if (!expand) {
1672
+ throw new import_error4.ServiceError(
1673
+ (0, import_error4.badRequestError)({
1674
+ message: `Trigger group does not support webhook expansion: ${params.triggerGroupId}`
1675
+ })
1676
+ );
1677
+ }
1678
+ let context = createContext(
1679
+ ctx.config,
1680
+ {
1681
+ payload: params.payload,
1682
+ state: params.state ?? null,
1683
+ selection: validateTriggerGroupSelection(group, params.selection),
1684
+ deliveryId: params.deliveryId,
1685
+ webhookRegistrationPayload: params.webhookRegistrationPayload
1686
+ },
1687
+ ctx.auth?.output
1688
+ );
1689
+ let res = await traceProviderCall(
1690
+ {
1691
+ component: "action",
1692
+ functionName: "expandWebhook",
1693
+ message: `Expanding webhook delivery for trigger group ${formatEntityLabel(group.name, group.key)}`,
1694
+ successMessage: `Expanded webhook delivery for trigger group ${formatEntityLabel(group.name, group.key)}`,
1695
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while expanding a webhook delivery`,
1696
+ metadata: { triggerGroupId: group.key, triggerGroupName: group.name }
1697
+ },
1698
+ () => (0, import_provider2.runWithContext)(
1699
+ context,
1700
+ async () => validate(
1701
+ import_proto.slatesTriggerGroupWebhookExpansionResult,
1702
+ await expand(context),
1703
+ "trigger_group.webhook.expansion",
1704
+ "Webhook expansion returned an invalid result"
1705
+ )
1706
+ )
1707
+ );
1708
+ return withRequestTraces(context, {
1709
+ ...res.updatedState !== void 0 ? { updatedState: res.updatedState } : {},
1710
+ events: res.events.map((event) => ({
1711
+ ...event,
1712
+ triggerIds: evaluateTriggerMatches(slate, group.key, event.payload)
1713
+ }))
1714
+ });
1715
+ });
1542
1716
  manager.onRequest("slates/trigger_group.routing_matchers.get", async ({ params }) => {
1543
1717
  let ctx = getContextFull();
1544
1718
  let group = getTriggerGroup(slate, params.triggerGroupId);
@@ -1572,7 +1746,14 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
1572
1746
  })
1573
1747
  );
1574
1748
  }
1575
- let context = createContext(ctx.config, { state: params.state }, ctx.auth?.output);
1749
+ let context = createContext(
1750
+ ctx.config,
1751
+ {
1752
+ state: params.state,
1753
+ selection: validateTriggerGroupSelection(group, params.selection)
1754
+ },
1755
+ ctx.auth?.output
1756
+ );
1576
1757
  let res = await traceProviderCall(
1577
1758
  {
1578
1759
  component: "action",
@@ -7,7 +7,10 @@ import {
7
7
  } from "@lowerdeck/error";
8
8
  import {
9
9
  createSlatesProviderProtoHandler,
10
- SLATES_PROTOCOL_VERSION
10
+ SLATES_PROTOCOL_VERSION,
11
+ slatesTriggerGroupWebhookDeliveryAuthentication,
12
+ slatesTriggerGroupWebhookExpansionResult,
13
+ slatesTriggerGroupWebhookRegistrationResult
11
14
  } from "@slates/proto";
12
15
  import {
13
16
  AuthConfigSecretRedactor,
@@ -61,7 +64,8 @@ var validate = (schema, data, entity, message) => {
61
64
  }
62
65
  return result.data;
63
66
  };
64
- var toJsonSchema = (schema) => schema.toJSONSchema({
67
+ var toJsonSchema = (schema, io = "output") => schema.toJSONSchema({
68
+ io,
65
69
  unrepresentable: "any",
66
70
  override: (ctx) => {
67
71
  let def = ctx.zodSchema._zod.def;
@@ -224,15 +228,30 @@ var getWebhookAutoRegistration = (group) => {
224
228
  return group.webhook.autoRegistration;
225
229
  };
226
230
  var getWebhookManualRegistration = (group) => {
227
- if (group.source !== "webhook" || !group.webhook?.manualRegistration) {
231
+ let registration = group.source === "webhook" ? group.webhook?.manualRegistration ?? group.webhook?.deliveryConfig : void 0;
232
+ if (!registration) {
228
233
  throw new ServiceError2(
229
234
  badRequestError({
230
235
  message: `Trigger group does not support manual webhook registration: ${group.key}`
231
236
  })
232
237
  );
233
238
  }
234
- return group.webhook.manualRegistration;
239
+ return registration;
235
240
  };
241
+ var getWebhookDeliveryConfig = (group) => {
242
+ if (group.source !== "webhook" || !group.webhook?.deliveryConfig) {
243
+ throw new ServiceError2(
244
+ badRequestError({
245
+ message: `Trigger group does not support webhook delivery authentication: ${group.key}`
246
+ })
247
+ );
248
+ }
249
+ return group.webhook.deliveryConfig;
250
+ };
251
+ var mapWebhookConfigSchemas = (config) => ({
252
+ userConfigSchema: toJsonSchema(config.userConfigSchema),
253
+ fullConfigSchema: toJsonSchema(config.fullConfigSchema)
254
+ });
236
255
  var mapToolCategory = (category) => ({
237
256
  id: category.key,
238
257
  name: category.name,
@@ -252,20 +271,24 @@ var mapTriggerGroup = (group) => ({
252
271
  name: group.name,
253
272
  description: group.description,
254
273
  metadata: group.metadata,
274
+ ...group.selectionSchema ? { selectionSchema: toJsonSchema(group.selectionSchema, "input") } : {},
255
275
  invocation: group.source === "polling" ? {
256
276
  type: "polling",
257
277
  intervalSeconds: group.polling?.intervalSeconds ?? SlateDefaultPollingIntervalSeconds
258
278
  } : group.source === "gateway" ? { type: "gateway" } : {
259
279
  type: "webhook",
280
+ ...group.webhook?.expandWebhook ? { supportsExpansion: true } : {},
281
+ ...group.webhook?.autoRegistration?.webhookRenew ? { supportsRenewal: true } : {},
282
+ ...group.webhook?.reconcileIntervalSeconds !== void 0 ? { reconcileIntervalSeconds: group.webhook.reconcileIntervalSeconds } : {},
260
283
  registration: group.webhook?.manualRegistration ? {
261
284
  mode: "manual",
262
- userConfigSchema: toJsonSchema(
263
- group.webhook.manualRegistration.userConfigSchema
264
- ),
265
- fullConfigSchema: toJsonSchema(
266
- group.webhook.manualRegistration.fullConfigSchema
267
- )
268
- } : { mode: "auto" }
285
+ ...mapWebhookConfigSchemas(group.webhook.manualRegistration)
286
+ } : {
287
+ mode: "auto",
288
+ ...group.webhook?.deliveryConfig ? {
289
+ deliveryConfig: mapWebhookConfigSchemas(group.webhook.deliveryConfig)
290
+ } : {}
291
+ }
269
292
  }
270
293
  });
271
294
 
@@ -342,6 +365,23 @@ var serializeWebhookHttpResponse = async (response) => {
342
365
 
343
366
  // src/index.ts
344
367
  var DEFAULT_MAX_ATTACHMENT_SIZE_BYTES = 1e8;
368
+ var validateTriggerGroupSelection = (group, selection) => group.selectionSchema ? validate(
369
+ group.selectionSchema,
370
+ selection === void 0 ? {} : selection,
371
+ "trigger_group.selection",
372
+ `Invalid selection for trigger group "${group.key}"`
373
+ ) : selection ?? {};
374
+ var validateWebhookRegistration = (result) => validate(
375
+ slatesTriggerGroupWebhookRegistrationResult,
376
+ result,
377
+ "trigger_group.webhook.registration",
378
+ "Webhook registration returned an invalid result"
379
+ );
380
+ var toWebhookRequest = (params) => new Request(params.url, {
381
+ method: params.method,
382
+ headers: params.headers,
383
+ body: params.body ? Uint8Array.from(atob(params.body.content), (c) => c.charCodeAt(0)) : null
384
+ });
345
385
  var routeAttachmentsThroughDirectUpload = async (attachments, live) => {
346
386
  if (!attachments || attachments.length === 0 || !live) return attachments;
347
387
  let contentEntries = attachments.map((attachment, index) => ({ attachment, index })).filter((entry) => entry.attachment.content.type === "content");
@@ -1308,7 +1348,10 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
1308
1348
  let autoRegistration = getWebhookAutoRegistration(group);
1309
1349
  let context = createContext(
1310
1350
  ctx.config,
1311
- { pageToken: params.pageToken ?? null },
1351
+ {
1352
+ pageToken: params.pageToken ?? null,
1353
+ selection: validateTriggerGroupSelection(group, params.selection)
1354
+ },
1312
1355
  ctx.auth?.output
1313
1356
  );
1314
1357
  let res = await traceProviderCall(
@@ -1344,7 +1387,10 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
1344
1387
  {
1345
1388
  webhookTargetIdentifier: params.webhookTargetIdentifier,
1346
1389
  webhookTargetPayload: params.webhookTargetPayload,
1347
- webhookUrl: params.webhookUrl
1390
+ webhookUrl: params.webhookUrl,
1391
+ operationId: params.operationId,
1392
+ selection: validateTriggerGroupSelection(group, params.selection),
1393
+ deliveryConfig: params.deliveryConfig
1348
1394
  },
1349
1395
  ctx.auth?.output
1350
1396
  );
@@ -1361,12 +1407,54 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
1361
1407
  webhookTargetIdentifier: params.webhookTargetIdentifier
1362
1408
  }
1363
1409
  },
1364
- () => runWithContext(context, () => autoRegistration.webhookRegister(context))
1410
+ () => runWithContext(
1411
+ context,
1412
+ async () => validateWebhookRegistration(await autoRegistration.webhookRegister(context))
1413
+ )
1365
1414
  );
1366
- return withRequestTraces(context, {
1367
- webhookRegistrationIdentifier: res.webhookRegistrationIdentifier,
1368
- webhookRegistrationPayload: res.webhookRegistrationPayload
1369
- });
1415
+ return withRequestTraces(context, res);
1416
+ });
1417
+ manager.onRequest("slates/trigger_group.webhook.renew", async ({ params }) => {
1418
+ let ctx = getContextFull();
1419
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1420
+ let autoRegistration = getWebhookAutoRegistration(group);
1421
+ let renew = autoRegistration.webhookRenew;
1422
+ if (!renew) {
1423
+ throw new ServiceError4(
1424
+ badRequestError3({
1425
+ message: `Trigger group does not support webhook renewal: ${params.triggerGroupId}`
1426
+ })
1427
+ );
1428
+ }
1429
+ let context = createContext(
1430
+ ctx.config,
1431
+ {
1432
+ webhookRegistrationIdentifier: params.webhookRegistrationIdentifier,
1433
+ webhookRegistrationPayload: params.webhookRegistrationPayload,
1434
+ webhookUrl: params.webhookUrl,
1435
+ webhookTargetIdentifier: params.webhookTargetIdentifier,
1436
+ webhookTargetPayload: params.webhookTargetPayload,
1437
+ operationId: params.operationId,
1438
+ selection: validateTriggerGroupSelection(group, params.selection),
1439
+ deliveryConfig: params.deliveryConfig
1440
+ },
1441
+ ctx.auth?.output
1442
+ );
1443
+ let res = await traceProviderCall(
1444
+ {
1445
+ component: "action",
1446
+ functionName: "webhookRenew",
1447
+ message: `Renewing webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
1448
+ successMessage: `Renewed webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
1449
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while renewing a webhook`,
1450
+ metadata: { triggerGroupId: group.key, triggerGroupName: group.name }
1451
+ },
1452
+ () => runWithContext(
1453
+ context,
1454
+ async () => validateWebhookRegistration(await renew(context))
1455
+ )
1456
+ );
1457
+ return withRequestTraces(context, res);
1370
1458
  });
1371
1459
  manager.onRequest("slates/trigger_group.webhook.unregister", async ({ params }) => {
1372
1460
  let ctx = getContextFull();
@@ -1468,15 +1556,10 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
1468
1556
  })
1469
1557
  );
1470
1558
  }
1471
- let req = new Request(params.url, {
1472
- method: params.method,
1473
- headers: params.headers,
1474
- body: params.body ? Uint8Array.from(atob(params.body.content), (c) => c.charCodeAt(0)) : null
1475
- });
1476
1559
  let context = createContext(
1477
1560
  {},
1478
1561
  {
1479
- request: req,
1562
+ request: toWebhookRequest(params),
1480
1563
  webhookRegistrationPayload: params.webhookRegistrationPayload
1481
1564
  },
1482
1565
  {}
@@ -1517,12 +1600,106 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
1517
1600
  matchers: event.matchers,
1518
1601
  payload: event.payload,
1519
1602
  idempotencyKey: event.idempotencyKey,
1520
- triggerIds: evaluateTriggerMatches(slate, group.key, event.payload)
1603
+ triggerIds: group.webhook?.expandWebhook ? [] : evaluateTriggerMatches(slate, group.key, event.payload)
1521
1604
  })),
1605
+ ...group.webhook?.expandWebhook ? { requiresExpansion: true } : {},
1522
1606
  response,
1523
1607
  skipped: res.skipped ?? null
1524
1608
  });
1525
1609
  });
1610
+ manager.onRequest(
1611
+ "slates/trigger_group.webhook.delivery_authenticate",
1612
+ async ({ params }) => {
1613
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1614
+ let deliveryConfig = getWebhookDeliveryConfig(group);
1615
+ let context = createContext(
1616
+ {},
1617
+ {
1618
+ request: toWebhookRequest(params),
1619
+ deliveryConfig: params.deliveryConfig
1620
+ },
1621
+ {}
1622
+ );
1623
+ let res = await traceProviderCall(
1624
+ {
1625
+ component: "action",
1626
+ functionName: "webhookDeliveryAuthenticate",
1627
+ message: `Authenticating a delivery for trigger group ${formatEntityLabel(group.name, group.key)}`,
1628
+ successMessage: (result) => result.rejected ? `Rejected a delivery with status ${result.rejected.status} for trigger group ${formatEntityLabel(group.name, group.key)}` : `Authenticated a delivery for ${result.routingKeys.length} routing key(s) for trigger group ${formatEntityLabel(group.name, group.key)}`,
1629
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while authenticating a delivery`,
1630
+ metadata: {
1631
+ triggerGroupId: group.key,
1632
+ triggerGroupName: group.name,
1633
+ requestMethod: params.method,
1634
+ hasRequestBody: !!params.body
1635
+ },
1636
+ onSuccess: (result) => ({
1637
+ routingKeyCount: result.routingKeys.length,
1638
+ rejectedStatus: result.rejected?.status ?? null
1639
+ })
1640
+ },
1641
+ () => runWithContext(context, async () => {
1642
+ let authentication = await deliveryConfig.authenticate(context);
1643
+ return validate(
1644
+ slatesTriggerGroupWebhookDeliveryAuthentication,
1645
+ authentication.rejected ? { routingKeys: [], rejected: authentication.rejected } : { routingKeys: authentication.routingKeys, rejected: null },
1646
+ "trigger_group.webhook.delivery_authentication",
1647
+ "Webhook delivery authentication returned an invalid result"
1648
+ );
1649
+ })
1650
+ );
1651
+ return withRequestTraces(context, res);
1652
+ }
1653
+ );
1654
+ manager.onRequest("slates/trigger_group.webhook.expand", async ({ params }) => {
1655
+ let ctx = getContextFull();
1656
+ let group = getTriggerGroup(slate, params.triggerGroupId);
1657
+ let expand = group.source === "webhook" ? group.webhook?.expandWebhook : void 0;
1658
+ if (!expand) {
1659
+ throw new ServiceError4(
1660
+ badRequestError3({
1661
+ message: `Trigger group does not support webhook expansion: ${params.triggerGroupId}`
1662
+ })
1663
+ );
1664
+ }
1665
+ let context = createContext(
1666
+ ctx.config,
1667
+ {
1668
+ payload: params.payload,
1669
+ state: params.state ?? null,
1670
+ selection: validateTriggerGroupSelection(group, params.selection),
1671
+ deliveryId: params.deliveryId,
1672
+ webhookRegistrationPayload: params.webhookRegistrationPayload
1673
+ },
1674
+ ctx.auth?.output
1675
+ );
1676
+ let res = await traceProviderCall(
1677
+ {
1678
+ component: "action",
1679
+ functionName: "expandWebhook",
1680
+ message: `Expanding webhook delivery for trigger group ${formatEntityLabel(group.name, group.key)}`,
1681
+ successMessage: `Expanded webhook delivery for trigger group ${formatEntityLabel(group.name, group.key)}`,
1682
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while expanding a webhook delivery`,
1683
+ metadata: { triggerGroupId: group.key, triggerGroupName: group.name }
1684
+ },
1685
+ () => runWithContext(
1686
+ context,
1687
+ async () => validate(
1688
+ slatesTriggerGroupWebhookExpansionResult,
1689
+ await expand(context),
1690
+ "trigger_group.webhook.expansion",
1691
+ "Webhook expansion returned an invalid result"
1692
+ )
1693
+ )
1694
+ );
1695
+ return withRequestTraces(context, {
1696
+ ...res.updatedState !== void 0 ? { updatedState: res.updatedState } : {},
1697
+ events: res.events.map((event) => ({
1698
+ ...event,
1699
+ triggerIds: evaluateTriggerMatches(slate, group.key, event.payload)
1700
+ }))
1701
+ });
1702
+ });
1526
1703
  manager.onRequest("slates/trigger_group.routing_matchers.get", async ({ params }) => {
1527
1704
  let ctx = getContextFull();
1528
1705
  let group = getTriggerGroup(slate, params.triggerGroupId);
@@ -1556,7 +1733,14 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
1556
1733
  })
1557
1734
  );
1558
1735
  }
1559
- let context = createContext(ctx.config, { state: params.state }, ctx.auth?.output);
1736
+ let context = createContext(
1737
+ ctx.config,
1738
+ {
1739
+ state: params.state,
1740
+ selection: validateTriggerGroupSelection(group, params.selection)
1741
+ },
1742
+ ctx.auth?.output
1743
+ );
1560
1744
  let res = await traceProviderCall(
1561
1745
  {
1562
1746
  component: "action",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slates/provider-handler",
3
- "version": "1.0.0-rc.43",
3
+ "version": "1.0.0-rc.44",
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.28",
36
- "@slates/provider": "1.0.0-rc.33",
35
+ "@slates/proto": "1.0.0-rc.29",
36
+ "@slates/provider": "1.0.0-rc.34",
37
37
  "p-queue": "^6.6.2",
38
38
  "zod": "^4.2.1"
39
39
  },