@slates/provider-handler 1.0.0-rc.36 → 1.0.0-rc.38

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
@@ -113,6 +113,7 @@ var mapAuthMethod = (slate, m) => ({
113
113
  description: s.description
114
114
  })) : void 0,
115
115
  adapters: "adapters" in m ? m.adapters : void 0,
116
+ ..."syncTokensAcrossConnections" in m && m.syncTokensAcrossConnections ? { syncTokensAcrossConnections: true } : {},
116
117
  inputSchema: toJsonSchema(m.inputSchema ?? import_zod.default.object({})),
117
118
  outputSchema: toJsonSchema(slate.spec.auth.outputSchema),
118
119
  capabilities: {
@@ -253,7 +254,7 @@ var mapTriggerGroup = (group) => ({
253
254
  invocation: group.source === "polling" ? {
254
255
  type: "polling",
255
256
  intervalSeconds: group.polling?.intervalSeconds ?? import_provider.SlateDefaultPollingIntervalSeconds
256
- } : {
257
+ } : group.source === "gateway" ? { type: "gateway" } : {
257
258
  type: "webhook",
258
259
  registration: group.webhook?.manualRegistration ? {
259
260
  mode: "manual",
@@ -1496,6 +1497,91 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
1496
1497
  }))
1497
1498
  });
1498
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
+ });
1499
1585
  });
1500
1586
  // Annotate the CommonJS export names for ESM import in node:
1501
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,
@@ -96,6 +97,7 @@ var mapAuthMethod = (slate, m) => ({
96
97
  description: s.description
97
98
  })) : void 0,
98
99
  adapters: "adapters" in m ? m.adapters : void 0,
100
+ ..."syncTokensAcrossConnections" in m && m.syncTokensAcrossConnections ? { syncTokensAcrossConnections: true } : {},
99
101
  inputSchema: toJsonSchema(m.inputSchema ?? z.object({})),
100
102
  outputSchema: toJsonSchema(slate.spec.auth.outputSchema),
101
103
  capabilities: {
@@ -236,7 +238,7 @@ var mapTriggerGroup = (group) => ({
236
238
  invocation: group.source === "polling" ? {
237
239
  type: "polling",
238
240
  intervalSeconds: group.polling?.intervalSeconds ?? SlateDefaultPollingIntervalSeconds
239
- } : {
241
+ } : group.source === "gateway" ? { type: "gateway" } : {
240
242
  type: "webhook",
241
243
  registration: group.webhook?.manualRegistration ? {
242
244
  mode: "manual",
@@ -1479,6 +1481,91 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
1479
1481
  }))
1480
1482
  });
1481
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
+ });
1482
1569
  });
1483
1570
  export {
1484
1571
  createProviderHandler
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slates/provider-handler",
3
- "version": "1.0.0-rc.36",
3
+ "version": "1.0.0-rc.38",
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.22",
36
- "@slates/provider": "1.0.0-rc.26",
35
+ "@slates/proto": "1.0.0-rc.24",
36
+ "@slates/provider": "1.0.0-rc.28",
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.test.ts CHANGED
@@ -9,7 +9,8 @@ import {
9
9
  getTriggersForGroup,
10
10
  isMappableTrigger,
11
11
  mapAction,
12
- mapAdapter
12
+ mapAdapter,
13
+ mapAuthMethod
13
14
  } from './spec';
14
15
 
15
16
  let baseAction = {
@@ -145,3 +146,25 @@ describe('adapter exposure', () => {
145
146
  });
146
147
  });
147
148
  });
149
+
150
+ describe('mapAuthMethod', () => {
151
+ let slate: any = { spec: { auth: { outputSchema: z.object({ token: z.string() }) } } };
152
+ let oauthMethod: any = {
153
+ type: 'auth.oauth',
154
+ key: 'oauth',
155
+ name: 'OAuth',
156
+ scopes: [],
157
+ getAuthorizationUrl: async () => ({ url: '' }),
158
+ handleCallback: async () => ({ output: { token: '' } })
159
+ };
160
+
161
+ it('emits syncTokensAcrossConnections only when the method opts in', () => {
162
+ expect(
163
+ mapAuthMethod(slate, { ...oauthMethod, syncTokensAcrossConnections: true })
164
+ ).toMatchObject({ syncTokensAcrossConnections: true });
165
+
166
+ for (let method of [oauthMethod, { ...oauthMethod, syncTokensAcrossConnections: false }]) {
167
+ expect(mapAuthMethod(slate, method)).not.toHaveProperty('syncTokensAcrossConnections');
168
+ }
169
+ });
170
+ });
package/src/spec.ts CHANGED
@@ -49,6 +49,10 @@ export let mapAuthMethod = <ConfigType extends {}, AuthType extends {}>(
49
49
 
50
50
  adapters: 'adapters' in m ? m.adapters : undefined,
51
51
 
52
+ ...('syncTokensAcrossConnections' in m && m.syncTokensAcrossConnections
53
+ ? { syncTokensAcrossConnections: true }
54
+ : {}),
55
+
52
56
  inputSchema: toJsonSchema(m.inputSchema ?? z.object({})),
53
57
  outputSchema: toJsonSchema(slate.spec.auth.outputSchema),
54
58
 
@@ -278,18 +282,20 @@ export let mapTriggerGroup = <ConfigType extends {}, AuthType extends {}>(
278
282
  type: 'polling',
279
283
  intervalSeconds: group.polling?.intervalSeconds ?? SlateDefaultPollingIntervalSeconds
280
284
  }
281
- : {
282
- type: 'webhook',
283
- registration: group.webhook?.manualRegistration
284
- ? {
285
- mode: 'manual',
286
- userConfigSchema: toJsonSchema(
287
- group.webhook.manualRegistration.userConfigSchema
288
- ),
289
- fullConfigSchema: toJsonSchema(
290
- group.webhook.manualRegistration.fullConfigSchema
291
- )
292
- }
293
- : { mode: 'auto' }
294
- }
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
+ }
295
301
  });