@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.module.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
group.webhook.
|
|
267
|
-
|
|
268
|
-
}
|
|
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");
|
|
@@ -438,6 +478,7 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
438
478
|
let liveInvocation = new State(
|
|
439
479
|
null
|
|
440
480
|
);
|
|
481
|
+
let runtimeInfo = new State(null);
|
|
441
482
|
let getLiveInvocation = () => {
|
|
442
483
|
let directUpload = hubCapabilities.get()?.attachments?.directUpload;
|
|
443
484
|
let live = liveInvocation.get();
|
|
@@ -527,8 +568,17 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
527
568
|
};
|
|
528
569
|
};
|
|
529
570
|
let getAuthConfig = () => config.get()?.value ?? {};
|
|
530
|
-
let
|
|
531
|
-
|
|
571
|
+
let createContext = (config2, input, auth2, liveInvocationInfo = null) => new SlateContext(
|
|
572
|
+
config2,
|
|
573
|
+
input,
|
|
574
|
+
auth2,
|
|
575
|
+
slate.spec,
|
|
576
|
+
logger,
|
|
577
|
+
liveInvocationInfo,
|
|
578
|
+
runtimeInfo.get()
|
|
579
|
+
);
|
|
580
|
+
let getEmptyContext = () => createContext({}, {}, {});
|
|
581
|
+
let getAuthContext = () => createContext(getAuthConfig(), {}, {});
|
|
532
582
|
let withRequestTraces = (context, result) => {
|
|
533
583
|
let requestTraces = context.getHttpTraces();
|
|
534
584
|
return requestTraces.length > 0 ? { ...result, requestTraces } : result;
|
|
@@ -635,11 +685,15 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
635
685
|
baseUrl: params.baseUrl
|
|
636
686
|
});
|
|
637
687
|
});
|
|
688
|
+
manager.onNotification("slates/hub.runtime_info.set", async ({ params }) => {
|
|
689
|
+
runtimeInfo.set(params.runtimeInfo);
|
|
690
|
+
});
|
|
638
691
|
manager.onRequest("slates/provider.capabilities.get", async () => ({
|
|
639
692
|
capabilities: {
|
|
640
693
|
hub: {
|
|
641
694
|
capabilitiesNotification: true,
|
|
642
|
-
liveInvocation: true
|
|
695
|
+
liveInvocation: true,
|
|
696
|
+
runtimeInfo: true
|
|
643
697
|
},
|
|
644
698
|
provider: {
|
|
645
699
|
triggerGroups: (slate.triggerGroups?.length ?? 0) > 0 && (slate.actions ?? []).every(isMappableTrigger),
|
|
@@ -1198,19 +1252,18 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1198
1252
|
};
|
|
1199
1253
|
if (action.isPublic) {
|
|
1200
1254
|
getContextBasic();
|
|
1201
|
-
return invoke(
|
|
1255
|
+
return invoke(
|
|
1256
|
+
new SlatePublicContext(
|
|
1257
|
+
input,
|
|
1258
|
+
slate.spec,
|
|
1259
|
+
logger,
|
|
1260
|
+
getLiveInvocation(),
|
|
1261
|
+
runtimeInfo.get()
|
|
1262
|
+
)
|
|
1263
|
+
);
|
|
1202
1264
|
}
|
|
1203
1265
|
let ctx = getContextFull();
|
|
1204
|
-
return invoke(
|
|
1205
|
-
new SlateContext(
|
|
1206
|
-
ctx.config,
|
|
1207
|
-
input,
|
|
1208
|
-
ctx.auth?.output,
|
|
1209
|
-
slate.spec,
|
|
1210
|
-
logger,
|
|
1211
|
-
getLiveInvocation()
|
|
1212
|
-
)
|
|
1213
|
-
);
|
|
1266
|
+
return invoke(createContext(ctx.config, input, ctx.auth?.output, getLiveInvocation()));
|
|
1214
1267
|
});
|
|
1215
1268
|
manager.onRequest("slates/action.trigger.map_event", async ({ params }) => {
|
|
1216
1269
|
let ctx = getContextFull();
|
|
@@ -1221,7 +1274,7 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1221
1274
|
"input",
|
|
1222
1275
|
`Invalid event for trigger ID: ${params.actionId}`
|
|
1223
1276
|
);
|
|
1224
|
-
let context =
|
|
1277
|
+
let context = createContext(ctx.config, input, ctx.auth?.output);
|
|
1225
1278
|
let res = await traceProviderCall(
|
|
1226
1279
|
{
|
|
1227
1280
|
component: "action",
|
|
@@ -1293,12 +1346,13 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1293
1346
|
let ctx = getContextFull();
|
|
1294
1347
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1295
1348
|
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1296
|
-
let context =
|
|
1349
|
+
let context = createContext(
|
|
1297
1350
|
ctx.config,
|
|
1298
|
-
{
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1351
|
+
{
|
|
1352
|
+
pageToken: params.pageToken ?? null,
|
|
1353
|
+
selection: validateTriggerGroupSelection(group, params.selection)
|
|
1354
|
+
},
|
|
1355
|
+
ctx.auth?.output
|
|
1302
1356
|
);
|
|
1303
1357
|
let res = await traceProviderCall(
|
|
1304
1358
|
{
|
|
@@ -1328,16 +1382,17 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1328
1382
|
let ctx = getContextFull();
|
|
1329
1383
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1330
1384
|
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1331
|
-
let context =
|
|
1385
|
+
let context = createContext(
|
|
1332
1386
|
ctx.config,
|
|
1333
1387
|
{
|
|
1334
1388
|
webhookTargetIdentifier: params.webhookTargetIdentifier,
|
|
1335
1389
|
webhookTargetPayload: params.webhookTargetPayload,
|
|
1336
|
-
webhookUrl: params.webhookUrl
|
|
1390
|
+
webhookUrl: params.webhookUrl,
|
|
1391
|
+
operationId: params.operationId,
|
|
1392
|
+
selection: validateTriggerGroupSelection(group, params.selection),
|
|
1393
|
+
deliveryConfig: params.deliveryConfig
|
|
1337
1394
|
},
|
|
1338
|
-
ctx.auth?.output
|
|
1339
|
-
slate.spec,
|
|
1340
|
-
logger
|
|
1395
|
+
ctx.auth?.output
|
|
1341
1396
|
);
|
|
1342
1397
|
let res = await traceProviderCall(
|
|
1343
1398
|
{
|
|
@@ -1352,26 +1407,66 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1352
1407
|
webhookTargetIdentifier: params.webhookTargetIdentifier
|
|
1353
1408
|
}
|
|
1354
1409
|
},
|
|
1355
|
-
() => runWithContext(
|
|
1410
|
+
() => runWithContext(
|
|
1411
|
+
context,
|
|
1412
|
+
async () => validateWebhookRegistration(await autoRegistration.webhookRegister(context))
|
|
1413
|
+
)
|
|
1356
1414
|
);
|
|
1357
|
-
return withRequestTraces(context,
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
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);
|
|
1361
1458
|
});
|
|
1362
1459
|
manager.onRequest("slates/trigger_group.webhook.unregister", async ({ params }) => {
|
|
1363
1460
|
let ctx = getContextFull();
|
|
1364
1461
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1365
1462
|
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1366
|
-
let context =
|
|
1463
|
+
let context = createContext(
|
|
1367
1464
|
ctx.config,
|
|
1368
1465
|
{
|
|
1369
1466
|
webhookRegistrationIdentifier: params.webhookRegistrationIdentifier,
|
|
1370
1467
|
webhookRegistrationPayload: params.webhookRegistrationPayload
|
|
1371
1468
|
},
|
|
1372
|
-
ctx.auth?.output
|
|
1373
|
-
slate.spec,
|
|
1374
|
-
logger
|
|
1469
|
+
ctx.auth?.output
|
|
1375
1470
|
);
|
|
1376
1471
|
await traceProviderCall(
|
|
1377
1472
|
{
|
|
@@ -1394,13 +1489,7 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1394
1489
|
getContextBasic();
|
|
1395
1490
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1396
1491
|
let manualRegistration = getWebhookManualRegistration(group);
|
|
1397
|
-
let context =
|
|
1398
|
-
{},
|
|
1399
|
-
{ webhookUrl: params.webhookUrl },
|
|
1400
|
-
{},
|
|
1401
|
-
slate.spec,
|
|
1402
|
-
logger
|
|
1403
|
-
);
|
|
1492
|
+
let context = createContext({}, { webhookUrl: params.webhookUrl }, {});
|
|
1404
1493
|
let res = await traceProviderCall(
|
|
1405
1494
|
{
|
|
1406
1495
|
component: "action",
|
|
@@ -1431,16 +1520,14 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1431
1520
|
})
|
|
1432
1521
|
);
|
|
1433
1522
|
}
|
|
1434
|
-
let context =
|
|
1523
|
+
let context = createContext(
|
|
1435
1524
|
{},
|
|
1436
1525
|
{
|
|
1437
1526
|
webhookUrl: params.webhookUrl,
|
|
1438
1527
|
partialWebhookRegistrationPayload: params.partialWebhookRegistrationPayload,
|
|
1439
1528
|
userWebhookRegistrationPayload: params.userWebhookRegistrationPayload
|
|
1440
1529
|
},
|
|
1441
|
-
{}
|
|
1442
|
-
slate.spec,
|
|
1443
|
-
logger
|
|
1530
|
+
{}
|
|
1444
1531
|
);
|
|
1445
1532
|
let res = await traceProviderCall(
|
|
1446
1533
|
{
|
|
@@ -1469,20 +1556,13 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1469
1556
|
})
|
|
1470
1557
|
);
|
|
1471
1558
|
}
|
|
1472
|
-
let
|
|
1473
|
-
method: params.method,
|
|
1474
|
-
headers: params.headers,
|
|
1475
|
-
body: params.body ? Uint8Array.from(atob(params.body.content), (c) => c.charCodeAt(0)) : null
|
|
1476
|
-
});
|
|
1477
|
-
let context = new SlateContext(
|
|
1559
|
+
let context = createContext(
|
|
1478
1560
|
{},
|
|
1479
1561
|
{
|
|
1480
|
-
request:
|
|
1562
|
+
request: toWebhookRequest(params),
|
|
1481
1563
|
webhookRegistrationPayload: params.webhookRegistrationPayload
|
|
1482
1564
|
},
|
|
1483
|
-
{}
|
|
1484
|
-
slate.spec,
|
|
1485
|
-
logger
|
|
1565
|
+
{}
|
|
1486
1566
|
);
|
|
1487
1567
|
let res = await traceProviderCall(
|
|
1488
1568
|
{
|
|
@@ -1520,16 +1600,110 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1520
1600
|
matchers: event.matchers,
|
|
1521
1601
|
payload: event.payload,
|
|
1522
1602
|
idempotencyKey: event.idempotencyKey,
|
|
1523
|
-
triggerIds: evaluateTriggerMatches(slate, group.key, event.payload)
|
|
1603
|
+
triggerIds: group.webhook?.expandWebhook ? [] : evaluateTriggerMatches(slate, group.key, event.payload)
|
|
1524
1604
|
})),
|
|
1605
|
+
...group.webhook?.expandWebhook ? { requiresExpansion: true } : {},
|
|
1525
1606
|
response,
|
|
1526
1607
|
skipped: res.skipped ?? null
|
|
1527
1608
|
});
|
|
1528
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
|
+
});
|
|
1529
1703
|
manager.onRequest("slates/trigger_group.routing_matchers.get", async ({ params }) => {
|
|
1530
1704
|
let ctx = getContextFull();
|
|
1531
1705
|
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1532
|
-
let context =
|
|
1706
|
+
let context = createContext(ctx.config, {}, ctx.auth?.output);
|
|
1533
1707
|
let matchers = await traceProviderCall(
|
|
1534
1708
|
{
|
|
1535
1709
|
component: "action",
|
|
@@ -1559,12 +1733,13 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1559
1733
|
})
|
|
1560
1734
|
);
|
|
1561
1735
|
}
|
|
1562
|
-
let context =
|
|
1736
|
+
let context = createContext(
|
|
1563
1737
|
ctx.config,
|
|
1564
|
-
{
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1738
|
+
{
|
|
1739
|
+
state: params.state,
|
|
1740
|
+
selection: validateTriggerGroupSelection(group, params.selection)
|
|
1741
|
+
},
|
|
1742
|
+
ctx.auth?.output
|
|
1568
1743
|
);
|
|
1569
1744
|
let res = await traceProviderCall(
|
|
1570
1745
|
{
|
|
@@ -1608,13 +1783,7 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1608
1783
|
manager.onRequest("slates/trigger_group.gateway.connect", async ({ params }) => {
|
|
1609
1784
|
let ctx = getContextFull();
|
|
1610
1785
|
let { group, gateway } = getGatewayTriggerGroup(params.triggerGroupId);
|
|
1611
|
-
let context =
|
|
1612
|
-
ctx.config,
|
|
1613
|
-
{ state: params.state },
|
|
1614
|
-
ctx.auth?.output,
|
|
1615
|
-
slate.spec,
|
|
1616
|
-
logger
|
|
1617
|
-
);
|
|
1786
|
+
let context = createContext(ctx.config, { state: params.state }, ctx.auth?.output);
|
|
1618
1787
|
let res = await traceProviderCall(
|
|
1619
1788
|
{
|
|
1620
1789
|
component: "action",
|
|
@@ -1635,12 +1804,10 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
1635
1804
|
manager.onRequest("slates/trigger_group.gateway.receive", async ({ params }) => {
|
|
1636
1805
|
let ctx = getContextFull();
|
|
1637
1806
|
let { group, gateway } = getGatewayTriggerGroup(params.triggerGroupId);
|
|
1638
|
-
let context =
|
|
1807
|
+
let context = createContext(
|
|
1639
1808
|
ctx.config,
|
|
1640
1809
|
{ state: params.state, frames: params.frames, closed: params.closed ?? null },
|
|
1641
|
-
ctx.auth?.output
|
|
1642
|
-
slate.spec,
|
|
1643
|
-
logger
|
|
1810
|
+
ctx.auth?.output
|
|
1644
1811
|
);
|
|
1645
1812
|
let res = await traceProviderCall(
|
|
1646
1813
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slates/provider-handler",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
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.
|
|
36
|
-
"@slates/provider": "1.0.0-rc.
|
|
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
|
},
|