@hiliosai/sdk 0.2.7 → 0.2.8

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.d.ts CHANGED
@@ -711,6 +711,10 @@ interface IntegrationServiceConfig<TSettings = unknown, TDatasourceConstructors
711
711
  }>;
712
712
  validateCredentials?(credentials: Record<string, string>): Promise<boolean>;
713
713
  validateSignature?<TPayload = any>(webhook: WebhookEvent<TPayload>): boolean;
714
+ resolveChannel?<TPayload = any>(ctx: TContext, payload: TPayload): Promise<{
715
+ channelId: string;
716
+ tenantId: string;
717
+ }>;
714
718
  }
715
719
  interface IntegrationServiceSchema<TSettings = unknown> extends ServiceSchema$1<TSettings> {
716
720
  spec: BaseSpec;
package/dist/index.js CHANGED
@@ -1382,16 +1382,37 @@ function defineIntegration(config) {
1382
1382
  path: "/:channelId"
1383
1383
  },
1384
1384
  params: {
1385
- channelId: "string",
1385
+ channelId: { type: "string", optional: true },
1386
1386
  payload: "object",
1387
1387
  headers: "object",
1388
1388
  timestamp: "number"
1389
1389
  },
1390
1390
  async handler(ctx) {
1391
- const { channelId, payload, headers, timestamp } = ctx.params;
1391
+ let channelId = ctx.params.channelId;
1392
+ let tenantId = ctx.meta.tenantId;
1393
+ const { payload, headers, timestamp } = ctx.params;
1394
+ ctx.broker.logger.info("[i_receiveWebhook] Received webhook", {
1395
+ platform: config.spec.platform,
1396
+ channelId,
1397
+ hasResolveChannel: !!config.resolveChannel,
1398
+ payload
1399
+ });
1400
+ if (channelId === "receive" && config.resolveChannel) {
1401
+ const resolved = await config.resolveChannel(ctx, payload);
1402
+ channelId = resolved.channelId;
1403
+ tenantId = resolved.tenantId;
1404
+ ctx.broker.logger.info("[i_receiveWebhook] Channel resolved", {
1405
+ channelId,
1406
+ tenantId
1407
+ });
1408
+ }
1409
+ if (!channelId) {
1410
+ throw new Error(
1411
+ "channelId is required but not provided and could not be resolved from payload"
1412
+ );
1413
+ }
1392
1414
  const webhook = {
1393
- tenantId: ctx.meta.tenantId ?? "unknown",
1394
- // Should come from channel lookup
1415
+ tenantId: tenantId ?? "unknown",
1395
1416
  channelId,
1396
1417
  platform: config.spec.platform,
1397
1418
  payload,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hiliosai/sdk",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/index.js",
@@ -34,4 +34,4 @@
34
34
  "nats": "2.29.3"
35
35
  },
36
36
  "prettier": "@hiliosai/prettier"
37
- }
37
+ }