@slates/provider-handler 1.0.0-rc.42 → 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 +247 -83
- package/dist/index.module.js +251 -84
- package/package.json +3 -3
- package/src/index.ts +275 -78
- package/src/runtimeInfo.test.ts +129 -0
- package/src/spec.test.ts +91 -1
- package/src/spec.ts +47 -9
- package/src/validation.ts +2 -1
- package/src/webhookDeliveryAuthenticate.test.ts +179 -0
- package/src/webhookSetup.test.ts +179 -0
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
|
-
|
|
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
|
|
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
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
group.webhook.
|
|
283
|
-
|
|
284
|
-
}
|
|
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");
|
|
@@ -454,6 +491,7 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
454
491
|
let liveInvocation = new State(
|
|
455
492
|
null
|
|
456
493
|
);
|
|
494
|
+
let runtimeInfo = new State(null);
|
|
457
495
|
let getLiveInvocation = () => {
|
|
458
496
|
let directUpload = hubCapabilities.get()?.attachments?.directUpload;
|
|
459
497
|
let live = liveInvocation.get();
|
|
@@ -543,8 +581,17 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
543
581
|
};
|
|
544
582
|
};
|
|
545
583
|
let getAuthConfig = () => config.get()?.value ?? {};
|
|
546
|
-
let
|
|
547
|
-
|
|
584
|
+
let createContext = (config2, input, auth2, liveInvocationInfo = null) => new import_provider2.SlateContext(
|
|
585
|
+
config2,
|
|
586
|
+
input,
|
|
587
|
+
auth2,
|
|
588
|
+
slate.spec,
|
|
589
|
+
logger,
|
|
590
|
+
liveInvocationInfo,
|
|
591
|
+
runtimeInfo.get()
|
|
592
|
+
);
|
|
593
|
+
let getEmptyContext = () => createContext({}, {}, {});
|
|
594
|
+
let getAuthContext = () => createContext(getAuthConfig(), {}, {});
|
|
548
595
|
let withRequestTraces = (context, result) => {
|
|
549
596
|
let requestTraces = context.getHttpTraces();
|
|
550
597
|
return requestTraces.length > 0 ? { ...result, requestTraces } : result;
|
|
@@ -651,11 +698,15 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
651
698
|
baseUrl: params.baseUrl
|
|
652
699
|
});
|
|
653
700
|
});
|
|
701
|
+
manager.onNotification("slates/hub.runtime_info.set", async ({ params }) => {
|
|
702
|
+
runtimeInfo.set(params.runtimeInfo);
|
|
703
|
+
});
|
|
654
704
|
manager.onRequest("slates/provider.capabilities.get", async () => ({
|
|
655
705
|
capabilities: {
|
|
656
706
|
hub: {
|
|
657
707
|
capabilitiesNotification: true,
|
|
658
|
-
liveInvocation: true
|
|
708
|
+
liveInvocation: true,
|
|
709
|
+
runtimeInfo: true
|
|
659
710
|
},
|
|
660
711
|
provider: {
|
|
661
712
|
triggerGroups: (slate.triggerGroups?.length ?? 0) > 0 && (slate.actions ?? []).every(isMappableTrigger),
|
|
@@ -1214,19 +1265,18 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1214
1265
|
};
|
|
1215
1266
|
if (action.isPublic) {
|
|
1216
1267
|
getContextBasic();
|
|
1217
|
-
return invoke(
|
|
1268
|
+
return invoke(
|
|
1269
|
+
new import_provider2.SlatePublicContext(
|
|
1270
|
+
input,
|
|
1271
|
+
slate.spec,
|
|
1272
|
+
logger,
|
|
1273
|
+
getLiveInvocation(),
|
|
1274
|
+
runtimeInfo.get()
|
|
1275
|
+
)
|
|
1276
|
+
);
|
|
1218
1277
|
}
|
|
1219
1278
|
let ctx = getContextFull();
|
|
1220
|
-
return invoke(
|
|
1221
|
-
new import_provider2.SlateContext(
|
|
1222
|
-
ctx.config,
|
|
1223
|
-
input,
|
|
1224
|
-
ctx.auth?.output,
|
|
1225
|
-
slate.spec,
|
|
1226
|
-
logger,
|
|
1227
|
-
getLiveInvocation()
|
|
1228
|
-
)
|
|
1229
|
-
);
|
|
1279
|
+
return invoke(createContext(ctx.config, input, ctx.auth?.output, getLiveInvocation()));
|
|
1230
1280
|
});
|
|
1231
1281
|
manager.onRequest("slates/action.trigger.map_event", async ({ params }) => {
|
|
1232
1282
|
let ctx = getContextFull();
|
|
@@ -1237,7 +1287,7 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1237
1287
|
"input",
|
|
1238
1288
|
`Invalid event for trigger ID: ${params.actionId}`
|
|
1239
1289
|
);
|
|
1240
|
-
let context =
|
|
1290
|
+
let context = createContext(ctx.config, input, ctx.auth?.output);
|
|
1241
1291
|
let res = await traceProviderCall(
|
|
1242
1292
|
{
|
|
1243
1293
|
component: "action",
|
|
@@ -1309,12 +1359,13 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1309
1359
|
let ctx = getContextFull();
|
|
1310
1360
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1311
1361
|
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1312
|
-
let context =
|
|
1362
|
+
let context = createContext(
|
|
1313
1363
|
ctx.config,
|
|
1314
|
-
{
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1364
|
+
{
|
|
1365
|
+
pageToken: params.pageToken ?? null,
|
|
1366
|
+
selection: validateTriggerGroupSelection(group, params.selection)
|
|
1367
|
+
},
|
|
1368
|
+
ctx.auth?.output
|
|
1318
1369
|
);
|
|
1319
1370
|
let res = await traceProviderCall(
|
|
1320
1371
|
{
|
|
@@ -1344,16 +1395,17 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1344
1395
|
let ctx = getContextFull();
|
|
1345
1396
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1346
1397
|
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1347
|
-
let context =
|
|
1398
|
+
let context = createContext(
|
|
1348
1399
|
ctx.config,
|
|
1349
1400
|
{
|
|
1350
1401
|
webhookTargetIdentifier: params.webhookTargetIdentifier,
|
|
1351
1402
|
webhookTargetPayload: params.webhookTargetPayload,
|
|
1352
|
-
webhookUrl: params.webhookUrl
|
|
1403
|
+
webhookUrl: params.webhookUrl,
|
|
1404
|
+
operationId: params.operationId,
|
|
1405
|
+
selection: validateTriggerGroupSelection(group, params.selection),
|
|
1406
|
+
deliveryConfig: params.deliveryConfig
|
|
1353
1407
|
},
|
|
1354
|
-
ctx.auth?.output
|
|
1355
|
-
slate.spec,
|
|
1356
|
-
logger
|
|
1408
|
+
ctx.auth?.output
|
|
1357
1409
|
);
|
|
1358
1410
|
let res = await traceProviderCall(
|
|
1359
1411
|
{
|
|
@@ -1368,26 +1420,66 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1368
1420
|
webhookTargetIdentifier: params.webhookTargetIdentifier
|
|
1369
1421
|
}
|
|
1370
1422
|
},
|
|
1371
|
-
() => (0, import_provider2.runWithContext)(
|
|
1423
|
+
() => (0, import_provider2.runWithContext)(
|
|
1424
|
+
context,
|
|
1425
|
+
async () => validateWebhookRegistration(await autoRegistration.webhookRegister(context))
|
|
1426
|
+
)
|
|
1372
1427
|
);
|
|
1373
|
-
return withRequestTraces(context,
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
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);
|
|
1377
1471
|
});
|
|
1378
1472
|
manager.onRequest("slates/trigger_group.webhook.unregister", async ({ params }) => {
|
|
1379
1473
|
let ctx = getContextFull();
|
|
1380
1474
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1381
1475
|
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1382
|
-
let context =
|
|
1476
|
+
let context = createContext(
|
|
1383
1477
|
ctx.config,
|
|
1384
1478
|
{
|
|
1385
1479
|
webhookRegistrationIdentifier: params.webhookRegistrationIdentifier,
|
|
1386
1480
|
webhookRegistrationPayload: params.webhookRegistrationPayload
|
|
1387
1481
|
},
|
|
1388
|
-
ctx.auth?.output
|
|
1389
|
-
slate.spec,
|
|
1390
|
-
logger
|
|
1482
|
+
ctx.auth?.output
|
|
1391
1483
|
);
|
|
1392
1484
|
await traceProviderCall(
|
|
1393
1485
|
{
|
|
@@ -1410,13 +1502,7 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1410
1502
|
getContextBasic();
|
|
1411
1503
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1412
1504
|
let manualRegistration = getWebhookManualRegistration(group);
|
|
1413
|
-
let context =
|
|
1414
|
-
{},
|
|
1415
|
-
{ webhookUrl: params.webhookUrl },
|
|
1416
|
-
{},
|
|
1417
|
-
slate.spec,
|
|
1418
|
-
logger
|
|
1419
|
-
);
|
|
1505
|
+
let context = createContext({}, { webhookUrl: params.webhookUrl }, {});
|
|
1420
1506
|
let res = await traceProviderCall(
|
|
1421
1507
|
{
|
|
1422
1508
|
component: "action",
|
|
@@ -1447,16 +1533,14 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1447
1533
|
})
|
|
1448
1534
|
);
|
|
1449
1535
|
}
|
|
1450
|
-
let context =
|
|
1536
|
+
let context = createContext(
|
|
1451
1537
|
{},
|
|
1452
1538
|
{
|
|
1453
1539
|
webhookUrl: params.webhookUrl,
|
|
1454
1540
|
partialWebhookRegistrationPayload: params.partialWebhookRegistrationPayload,
|
|
1455
1541
|
userWebhookRegistrationPayload: params.userWebhookRegistrationPayload
|
|
1456
1542
|
},
|
|
1457
|
-
{}
|
|
1458
|
-
slate.spec,
|
|
1459
|
-
logger
|
|
1543
|
+
{}
|
|
1460
1544
|
);
|
|
1461
1545
|
let res = await traceProviderCall(
|
|
1462
1546
|
{
|
|
@@ -1485,20 +1569,13 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1485
1569
|
})
|
|
1486
1570
|
);
|
|
1487
1571
|
}
|
|
1488
|
-
let
|
|
1489
|
-
method: params.method,
|
|
1490
|
-
headers: params.headers,
|
|
1491
|
-
body: params.body ? Uint8Array.from(atob(params.body.content), (c) => c.charCodeAt(0)) : null
|
|
1492
|
-
});
|
|
1493
|
-
let context = new import_provider2.SlateContext(
|
|
1572
|
+
let context = createContext(
|
|
1494
1573
|
{},
|
|
1495
1574
|
{
|
|
1496
|
-
request:
|
|
1575
|
+
request: toWebhookRequest(params),
|
|
1497
1576
|
webhookRegistrationPayload: params.webhookRegistrationPayload
|
|
1498
1577
|
},
|
|
1499
|
-
{}
|
|
1500
|
-
slate.spec,
|
|
1501
|
-
logger
|
|
1578
|
+
{}
|
|
1502
1579
|
);
|
|
1503
1580
|
let res = await traceProviderCall(
|
|
1504
1581
|
{
|
|
@@ -1536,16 +1613,110 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1536
1613
|
matchers: event.matchers,
|
|
1537
1614
|
payload: event.payload,
|
|
1538
1615
|
idempotencyKey: event.idempotencyKey,
|
|
1539
|
-
triggerIds: evaluateTriggerMatches(slate, group.key, event.payload)
|
|
1616
|
+
triggerIds: group.webhook?.expandWebhook ? [] : evaluateTriggerMatches(slate, group.key, event.payload)
|
|
1540
1617
|
})),
|
|
1618
|
+
...group.webhook?.expandWebhook ? { requiresExpansion: true } : {},
|
|
1541
1619
|
response,
|
|
1542
1620
|
skipped: res.skipped ?? null
|
|
1543
1621
|
});
|
|
1544
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
|
+
});
|
|
1545
1716
|
manager.onRequest("slates/trigger_group.routing_matchers.get", async ({ params }) => {
|
|
1546
1717
|
let ctx = getContextFull();
|
|
1547
1718
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1548
|
-
let context =
|
|
1719
|
+
let context = createContext(ctx.config, {}, ctx.auth?.output);
|
|
1549
1720
|
let matchers = await traceProviderCall(
|
|
1550
1721
|
{
|
|
1551
1722
|
component: "action",
|
|
@@ -1575,12 +1746,13 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1575
1746
|
})
|
|
1576
1747
|
);
|
|
1577
1748
|
}
|
|
1578
|
-
let context =
|
|
1749
|
+
let context = createContext(
|
|
1579
1750
|
ctx.config,
|
|
1580
|
-
{
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1751
|
+
{
|
|
1752
|
+
state: params.state,
|
|
1753
|
+
selection: validateTriggerGroupSelection(group, params.selection)
|
|
1754
|
+
},
|
|
1755
|
+
ctx.auth?.output
|
|
1584
1756
|
);
|
|
1585
1757
|
let res = await traceProviderCall(
|
|
1586
1758
|
{
|
|
@@ -1624,13 +1796,7 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1624
1796
|
manager.onRequest("slates/trigger_group.gateway.connect", async ({ params }) => {
|
|
1625
1797
|
let ctx = getContextFull();
|
|
1626
1798
|
let { group, gateway } = getGatewayTriggerGroup(params.triggerGroupId);
|
|
1627
|
-
let context =
|
|
1628
|
-
ctx.config,
|
|
1629
|
-
{ state: params.state },
|
|
1630
|
-
ctx.auth?.output,
|
|
1631
|
-
slate.spec,
|
|
1632
|
-
logger
|
|
1633
|
-
);
|
|
1799
|
+
let context = createContext(ctx.config, { state: params.state }, ctx.auth?.output);
|
|
1634
1800
|
let res = await traceProviderCall(
|
|
1635
1801
|
{
|
|
1636
1802
|
component: "action",
|
|
@@ -1651,12 +1817,10 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
1651
1817
|
manager.onRequest("slates/trigger_group.gateway.receive", async ({ params }) => {
|
|
1652
1818
|
let ctx = getContextFull();
|
|
1653
1819
|
let { group, gateway } = getGatewayTriggerGroup(params.triggerGroupId);
|
|
1654
|
-
let context =
|
|
1820
|
+
let context = createContext(
|
|
1655
1821
|
ctx.config,
|
|
1656
1822
|
{ state: params.state, frames: params.frames, closed: params.closed ?? null },
|
|
1657
|
-
ctx.auth?.output
|
|
1658
|
-
slate.spec,
|
|
1659
|
-
logger
|
|
1823
|
+
ctx.auth?.output
|
|
1660
1824
|
);
|
|
1661
1825
|
let res = await traceProviderCall(
|
|
1662
1826
|
{
|