@slates/provider-handler 1.0.0-rc.37 → 1.0.0-rc.39

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
@@ -254,7 +254,7 @@ var mapTriggerGroup = (group) => ({
254
254
  invocation: group.source === "polling" ? {
255
255
  type: "polling",
256
256
  intervalSeconds: group.polling?.intervalSeconds ?? import_provider.SlateDefaultPollingIntervalSeconds
257
- } : {
257
+ } : group.source === "gateway" ? { type: "gateway" } : {
258
258
  type: "webhook",
259
259
  registration: group.webhook?.manualRegistration ? {
260
260
  mode: "manual",
@@ -1497,6 +1497,91 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
1497
1497
  }))
1498
1498
  });
1499
1499
  });
1500
+ let getGatewayTriggerGroup = (triggerGroupId) => {
1501
+ let group = getTriggerGroup(slate, triggerGroupId);
1502
+ if (group.source !== "gateway" || !group.gateway) {
1503
+ throw new import_error4.ServiceError(
1504
+ (0, import_error4.badRequestError)({
1505
+ message: `Trigger group does not support gateway connections: ${triggerGroupId}`
1506
+ })
1507
+ );
1508
+ }
1509
+ return { group, gateway: group.gateway };
1510
+ };
1511
+ manager.onRequest("slates/trigger_group.gateway.connect", async ({ params }) => {
1512
+ let ctx = getContextFull();
1513
+ let { group, gateway } = getGatewayTriggerGroup(params.triggerGroupId);
1514
+ let context = new import_provider2.SlateContext(
1515
+ ctx.config,
1516
+ { state: params.state },
1517
+ ctx.auth?.output,
1518
+ slate.spec,
1519
+ logger
1520
+ );
1521
+ let res = await traceProviderCall(
1522
+ {
1523
+ component: "action",
1524
+ functionName: "gatewayConnect",
1525
+ message: `Preparing gateway connection for trigger group ${formatEntityLabel(group.name, group.key)}`,
1526
+ successMessage: () => `Prepared gateway connection for trigger group ${formatEntityLabel(group.name, group.key)}`,
1527
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while preparing a gateway connection`,
1528
+ metadata: {
1529
+ triggerGroupId: group.key,
1530
+ triggerGroupName: group.name,
1531
+ hasPreviousState: params.state !== null
1532
+ }
1533
+ },
1534
+ () => (0, import_provider2.runWithContext)(context, () => gateway.connect(context))
1535
+ );
1536
+ return withRequestTraces(context, { url: res.url, state: res.state });
1537
+ });
1538
+ manager.onRequest("slates/trigger_group.gateway.receive", async ({ params }) => {
1539
+ let ctx = getContextFull();
1540
+ let { group, gateway } = getGatewayTriggerGroup(params.triggerGroupId);
1541
+ let context = new import_provider2.SlateContext(
1542
+ ctx.config,
1543
+ { state: params.state, frames: params.frames, closed: params.closed ?? null },
1544
+ ctx.auth?.output,
1545
+ slate.spec,
1546
+ logger
1547
+ );
1548
+ let res = await traceProviderCall(
1549
+ {
1550
+ component: "action",
1551
+ functionName: "gatewayReceive",
1552
+ message: `Handling ${params.frames.length} gateway frame(s) for trigger group ${formatEntityLabel(group.name, group.key)}`,
1553
+ successMessage: (result) => `Handled gateway frames for trigger group ${formatEntityLabel(group.name, group.key)} (${result.events?.length ?? 0} event(s))`,
1554
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while handling gateway frames`,
1555
+ metadata: {
1556
+ triggerGroupId: group.key,
1557
+ triggerGroupName: group.name,
1558
+ frameCount: params.frames.length,
1559
+ closed: params.closed ?? null
1560
+ },
1561
+ onSuccess: (result) => ({
1562
+ eventCount: result.events?.length ?? 0,
1563
+ sendCount: result.send?.length ?? 0,
1564
+ close: result.close ?? null
1565
+ })
1566
+ },
1567
+ () => (0, import_provider2.runWithContext)(context, () => gateway.receive(context))
1568
+ );
1569
+ return withRequestTraces(context, {
1570
+ state: res.state,
1571
+ // Outbound frames (e.g. IDENTIFY) embed credentials; the hub restores them at the socket.
1572
+ send: new import_provider2.AuthConfigSecretRedactor(
1573
+ context._getAuthConfigForRedaction()
1574
+ ).redactEmbedded(res.send ?? []),
1575
+ heartbeat: res.heartbeat ?? null,
1576
+ heartbeatAcked: res.heartbeatAcked,
1577
+ close: res.close ?? null,
1578
+ events: (res.events ?? []).map((event) => ({
1579
+ payload: event.payload,
1580
+ idempotencyKey: event.idempotencyKey,
1581
+ triggerIds: evaluateTriggerMatches(slate, group.key, event.payload)
1582
+ }))
1583
+ });
1584
+ });
1500
1585
  });
1501
1586
  // Annotate the CommonJS export names for ESM import in node:
1502
1587
  0 && (module.exports = {
@@ -10,6 +10,7 @@ import {
10
10
  SLATES_PROTOCOL_VERSION
11
11
  } from "@slates/proto";
12
12
  import {
13
+ AuthConfigSecretRedactor,
13
14
  redactUrlAttachmentSecrets,
14
15
  runWithContext,
15
16
  SlateContext,
@@ -237,7 +238,7 @@ var mapTriggerGroup = (group) => ({
237
238
  invocation: group.source === "polling" ? {
238
239
  type: "polling",
239
240
  intervalSeconds: group.polling?.intervalSeconds ?? SlateDefaultPollingIntervalSeconds
240
- } : {
241
+ } : group.source === "gateway" ? { type: "gateway" } : {
241
242
  type: "webhook",
242
243
  registration: group.webhook?.manualRegistration ? {
243
244
  mode: "manual",
@@ -1480,6 +1481,91 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
1480
1481
  }))
1481
1482
  });
1482
1483
  });
1484
+ let getGatewayTriggerGroup = (triggerGroupId) => {
1485
+ let group = getTriggerGroup(slate, triggerGroupId);
1486
+ if (group.source !== "gateway" || !group.gateway) {
1487
+ throw new ServiceError4(
1488
+ badRequestError3({
1489
+ message: `Trigger group does not support gateway connections: ${triggerGroupId}`
1490
+ })
1491
+ );
1492
+ }
1493
+ return { group, gateway: group.gateway };
1494
+ };
1495
+ manager.onRequest("slates/trigger_group.gateway.connect", async ({ params }) => {
1496
+ let ctx = getContextFull();
1497
+ let { group, gateway } = getGatewayTriggerGroup(params.triggerGroupId);
1498
+ let context = new SlateContext(
1499
+ ctx.config,
1500
+ { state: params.state },
1501
+ ctx.auth?.output,
1502
+ slate.spec,
1503
+ logger
1504
+ );
1505
+ let res = await traceProviderCall(
1506
+ {
1507
+ component: "action",
1508
+ functionName: "gatewayConnect",
1509
+ message: `Preparing gateway connection for trigger group ${formatEntityLabel(group.name, group.key)}`,
1510
+ successMessage: () => `Prepared gateway connection for trigger group ${formatEntityLabel(group.name, group.key)}`,
1511
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while preparing a gateway connection`,
1512
+ metadata: {
1513
+ triggerGroupId: group.key,
1514
+ triggerGroupName: group.name,
1515
+ hasPreviousState: params.state !== null
1516
+ }
1517
+ },
1518
+ () => runWithContext(context, () => gateway.connect(context))
1519
+ );
1520
+ return withRequestTraces(context, { url: res.url, state: res.state });
1521
+ });
1522
+ manager.onRequest("slates/trigger_group.gateway.receive", async ({ params }) => {
1523
+ let ctx = getContextFull();
1524
+ let { group, gateway } = getGatewayTriggerGroup(params.triggerGroupId);
1525
+ let context = new SlateContext(
1526
+ ctx.config,
1527
+ { state: params.state, frames: params.frames, closed: params.closed ?? null },
1528
+ ctx.auth?.output,
1529
+ slate.spec,
1530
+ logger
1531
+ );
1532
+ let res = await traceProviderCall(
1533
+ {
1534
+ component: "action",
1535
+ functionName: "gatewayReceive",
1536
+ message: `Handling ${params.frames.length} gateway frame(s) for trigger group ${formatEntityLabel(group.name, group.key)}`,
1537
+ successMessage: (result) => `Handled gateway frames for trigger group ${formatEntityLabel(group.name, group.key)} (${result.events?.length ?? 0} event(s))`,
1538
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while handling gateway frames`,
1539
+ metadata: {
1540
+ triggerGroupId: group.key,
1541
+ triggerGroupName: group.name,
1542
+ frameCount: params.frames.length,
1543
+ closed: params.closed ?? null
1544
+ },
1545
+ onSuccess: (result) => ({
1546
+ eventCount: result.events?.length ?? 0,
1547
+ sendCount: result.send?.length ?? 0,
1548
+ close: result.close ?? null
1549
+ })
1550
+ },
1551
+ () => runWithContext(context, () => gateway.receive(context))
1552
+ );
1553
+ return withRequestTraces(context, {
1554
+ state: res.state,
1555
+ // Outbound frames (e.g. IDENTIFY) embed credentials; the hub restores them at the socket.
1556
+ send: new AuthConfigSecretRedactor(
1557
+ context._getAuthConfigForRedaction()
1558
+ ).redactEmbedded(res.send ?? []),
1559
+ heartbeat: res.heartbeat ?? null,
1560
+ heartbeatAcked: res.heartbeatAcked,
1561
+ close: res.close ?? null,
1562
+ events: (res.events ?? []).map((event) => ({
1563
+ payload: event.payload,
1564
+ idempotencyKey: event.idempotencyKey,
1565
+ triggerIds: evaluateTriggerMatches(slate, group.key, event.payload)
1566
+ }))
1567
+ });
1568
+ });
1483
1569
  });
1484
1570
  export {
1485
1571
  createProviderHandler
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slates/provider-handler",
3
- "version": "1.0.0-rc.37",
3
+ "version": "1.0.0-rc.39",
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.23",
36
- "@slates/provider": "1.0.0-rc.27",
35
+ "@slates/proto": "1.0.0-rc.24",
36
+ "@slates/provider": "1.0.0-rc.29",
37
37
  "p-queue": "^6.6.2",
38
38
  "zod": "^4.2.1"
39
39
  },
package/src/index.ts CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  type SlatesParticipant
11
11
  } from '@slates/proto';
12
12
  import {
13
+ AuthConfigSecretRedactor,
13
14
  redactUrlAttachmentSecrets,
14
15
  runWithContext,
15
16
  type Slate,
@@ -1446,4 +1447,98 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
1446
1447
  }))
1447
1448
  });
1448
1449
  });
1450
+
1451
+ let getGatewayTriggerGroup = (triggerGroupId: string) => {
1452
+ let group = getTriggerGroup(slate, triggerGroupId);
1453
+ if (group.source !== 'gateway' || !group.gateway) {
1454
+ throw new ServiceError(
1455
+ badRequestError({
1456
+ message: `Trigger group does not support gateway connections: ${triggerGroupId}`
1457
+ })
1458
+ );
1459
+ }
1460
+ return { group, gateway: group.gateway };
1461
+ };
1462
+
1463
+ manager.onRequest('slates/trigger_group.gateway.connect', async ({ params }) => {
1464
+ let ctx = getContextFull();
1465
+ let { group, gateway } = getGatewayTriggerGroup(params.triggerGroupId);
1466
+
1467
+ let context = new SlateContext(
1468
+ ctx.config,
1469
+ { state: params.state },
1470
+ ctx.auth?.output!,
1471
+ slate.spec,
1472
+ logger
1473
+ );
1474
+ let res = await traceProviderCall(
1475
+ {
1476
+ component: 'action',
1477
+ functionName: 'gatewayConnect',
1478
+ message: `Preparing gateway connection for trigger group ${formatEntityLabel(group.name, group.key)}`,
1479
+ successMessage: () =>
1480
+ `Prepared gateway connection for trigger group ${formatEntityLabel(group.name, group.key)}`,
1481
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while preparing a gateway connection`,
1482
+ metadata: {
1483
+ triggerGroupId: group.key,
1484
+ triggerGroupName: group.name,
1485
+ hasPreviousState: params.state !== null
1486
+ }
1487
+ },
1488
+ () => runWithContext(context, () => gateway.connect(context))
1489
+ );
1490
+
1491
+ return withRequestTraces(context, { url: res.url, state: res.state });
1492
+ });
1493
+
1494
+ manager.onRequest('slates/trigger_group.gateway.receive', async ({ params }) => {
1495
+ let ctx = getContextFull();
1496
+ let { group, gateway } = getGatewayTriggerGroup(params.triggerGroupId);
1497
+
1498
+ let context = new SlateContext(
1499
+ ctx.config,
1500
+ { state: params.state, frames: params.frames, closed: params.closed ?? null },
1501
+ ctx.auth?.output!,
1502
+ slate.spec,
1503
+ logger
1504
+ );
1505
+ let res = await traceProviderCall(
1506
+ {
1507
+ component: 'action',
1508
+ functionName: 'gatewayReceive',
1509
+ message: `Handling ${params.frames.length} gateway frame(s) for trigger group ${formatEntityLabel(group.name, group.key)}`,
1510
+ successMessage: result =>
1511
+ `Handled gateway frames for trigger group ${formatEntityLabel(group.name, group.key)} (${result.events?.length ?? 0} event(s))`,
1512
+ errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while handling gateway frames`,
1513
+ metadata: {
1514
+ triggerGroupId: group.key,
1515
+ triggerGroupName: group.name,
1516
+ frameCount: params.frames.length,
1517
+ closed: params.closed ?? null
1518
+ },
1519
+ onSuccess: result => ({
1520
+ eventCount: result.events?.length ?? 0,
1521
+ sendCount: result.send?.length ?? 0,
1522
+ close: result.close ?? null
1523
+ })
1524
+ },
1525
+ () => runWithContext(context, () => gateway.receive(context))
1526
+ );
1527
+
1528
+ return withRequestTraces(context, {
1529
+ state: res.state,
1530
+ // Outbound frames (e.g. IDENTIFY) embed credentials; the hub restores them at the socket.
1531
+ send: new AuthConfigSecretRedactor(
1532
+ context._getAuthConfigForRedaction()
1533
+ ).redactEmbedded(res.send ?? []),
1534
+ heartbeat: res.heartbeat ?? null,
1535
+ heartbeatAcked: res.heartbeatAcked,
1536
+ close: res.close ?? null,
1537
+ events: (res.events ?? []).map(event => ({
1538
+ payload: event.payload,
1539
+ idempotencyKey: event.idempotencyKey,
1540
+ triggerIds: evaluateTriggerMatches(slate, group.key, event.payload)
1541
+ }))
1542
+ });
1543
+ });
1449
1544
  });
package/src/spec.ts CHANGED
@@ -282,18 +282,20 @@ export let mapTriggerGroup = <ConfigType extends {}, AuthType extends {}>(
282
282
  type: 'polling',
283
283
  intervalSeconds: group.polling?.intervalSeconds ?? SlateDefaultPollingIntervalSeconds
284
284
  }
285
- : {
286
- type: 'webhook',
287
- registration: group.webhook?.manualRegistration
288
- ? {
289
- mode: 'manual',
290
- userConfigSchema: toJsonSchema(
291
- group.webhook.manualRegistration.userConfigSchema
292
- ),
293
- fullConfigSchema: toJsonSchema(
294
- group.webhook.manualRegistration.fullConfigSchema
295
- )
296
- }
297
- : { mode: 'auto' }
298
- }
285
+ : group.source === 'gateway'
286
+ ? { type: 'gateway' }
287
+ : {
288
+ type: 'webhook',
289
+ registration: group.webhook?.manualRegistration
290
+ ? {
291
+ mode: 'manual',
292
+ userConfigSchema: toJsonSchema(
293
+ group.webhook.manualRegistration.userConfigSchema
294
+ ),
295
+ fullConfigSchema: toJsonSchema(
296
+ group.webhook.manualRegistration.fullConfigSchema
297
+ )
298
+ }
299
+ : { mode: 'auto' }
300
+ }
299
301
  });