@hiliosai/sdk 0.2.6 → 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;
@@ -783,6 +787,24 @@ declare const INTEGRATION_CHANNELS: {
783
787
  readonly MESSAGE_CREATED: "processing.message.created";
784
788
  };
785
789
  type IntegrationChannelName = (typeof INTEGRATION_CHANNELS)[keyof typeof INTEGRATION_CHANNELS];
790
+ /**
791
+ * Tenant lifecycle channel names
792
+ */
793
+ declare const TENANT_CHANNELS: {
794
+ readonly TENANT_CREATED: "tenant_created";
795
+ readonly TENANT_UPDATED: "tenant_updated";
796
+ readonly TENANT_DELETED: "tenant_deleted";
797
+ };
798
+ type TenantChannelName = (typeof TENANT_CHANNELS)[keyof typeof TENANT_CHANNELS];
799
+ /**
800
+ * User lifecycle channel names
801
+ */
802
+ declare const USER_CHANNELS: {
803
+ readonly USER_CREATED: "user_created";
804
+ readonly USER_UPDATED: "user_updated";
805
+ readonly USER_DELETED: "user_deleted";
806
+ };
807
+ type UserChannelName = (typeof USER_CHANNELS)[keyof typeof USER_CHANNELS];
786
808
 
787
809
  /**
788
810
  * Channel event payload types for reliable messaging via @moleculer/channels
@@ -994,4 +1016,4 @@ declare class DBTransactionError extends Errors.MoleculerError {
994
1016
  }
995
1017
  declare function prismaErrorHandler(this: ServiceBroker, err: Error, info: BrokerErrorHandlerInfoAction): undefined;
996
1018
 
997
- export { AbstractDatasource, type ActionHandler, type ActionWithPermissions, type AppContext, type AppMeta, type AuditTrailExtension, AuthenticationError, type BaseDatasource, type BaseSpec, CHANNELS, type CarouselItem, type ChannelSendOptions, ContextHelpersMiddleware, CreateHealthCheckMiddleware, DBConnectionError, DBConstraintError, DBError, DBNotFoundError, DBTimeoutError, DBTransactionError, DBValidationError, DEFAULT_DATASOURCE_CACHE_TTL, type DatasourceConstructorRegistry, type DatasourceContext, type DatasourceInstanceRegistry, type DatasourceInstanceTypes, DatasourceMixin, type Env, type GatewayError, HEALTH_CHECK_DEFAULTS, INTEGRATION_CHANNELS, IntegrationCapability, type IntegrationChannelName, type IntegrationConfig, type IntegrationMessageFailedPayload, type IntegrationMessageReceivedPayload, type IntegrationMessageSentPayload, IntegrationPlatform, type IntegrationRegisteredPayload, type IntegrationServiceConfig, type IntegrationServiceSchema, IntegrationStatus, type IntegrationUnregisteredPayload, MemoizeMixin, type MemoizeMixinOptions, type Message, type MessageAttachment, type MessageButton, type MessageContent, MessageContentType, type MessageDirection, type MessageParticipant, type MessageStatus, type MessageType, NAMESPACE, PERMISSIONS, type Permission, PermissionError, type PermissionHelpers, PermissionsMiddleware, type PlatformMessage, type PrismaClientLike, type PrismaClientWithTenant, PrismaDatasource, PrismaPgDatasource, REDIS_URL, ROLE_PERMISSIONS, SERVICE_NAME, SERVICE_VERSION, type SendResult, type SendToChannelMethod, type ServiceActionsSchema, type ServiceConfig, type ServiceSchema, type ServiceWithDatasources, type SoftDeleteExtension, type Tenant, TenantError, type TenantExtension, type User, UserRole, type WebhookEvent, createDatasourceMiddleware, createTenantExtension, defineIntegration, defineService, gatewayErrorHandler, getErrorLogLevel, isDev, isProd, isTest, configs as moleculer, nodeEnv, omit, prismaErrorHandler, retryExtension, sanitizeErrorData, softDeleteExtension };
1019
+ export { AbstractDatasource, type ActionHandler, type ActionWithPermissions, type AppContext, type AppMeta, type AuditTrailExtension, AuthenticationError, type BaseDatasource, type BaseSpec, CHANNELS, type CarouselItem, type ChannelSendOptions, ContextHelpersMiddleware, CreateHealthCheckMiddleware, DBConnectionError, DBConstraintError, DBError, DBNotFoundError, DBTimeoutError, DBTransactionError, DBValidationError, DEFAULT_DATASOURCE_CACHE_TTL, type DatasourceConstructorRegistry, type DatasourceContext, type DatasourceInstanceRegistry, type DatasourceInstanceTypes, DatasourceMixin, type Env, type GatewayError, HEALTH_CHECK_DEFAULTS, INTEGRATION_CHANNELS, IntegrationCapability, type IntegrationChannelName, type IntegrationConfig, type IntegrationMessageFailedPayload, type IntegrationMessageReceivedPayload, type IntegrationMessageSentPayload, IntegrationPlatform, type IntegrationRegisteredPayload, type IntegrationServiceConfig, type IntegrationServiceSchema, IntegrationStatus, type IntegrationUnregisteredPayload, MemoizeMixin, type MemoizeMixinOptions, type Message, type MessageAttachment, type MessageButton, type MessageContent, MessageContentType, type MessageDirection, type MessageParticipant, type MessageStatus, type MessageType, NAMESPACE, PERMISSIONS, type Permission, PermissionError, type PermissionHelpers, PermissionsMiddleware, type PlatformMessage, type PrismaClientLike, type PrismaClientWithTenant, PrismaDatasource, PrismaPgDatasource, REDIS_URL, ROLE_PERMISSIONS, SERVICE_NAME, SERVICE_VERSION, type SendResult, type SendToChannelMethod, type ServiceActionsSchema, type ServiceConfig, type ServiceSchema, type ServiceWithDatasources, type SoftDeleteExtension, TENANT_CHANNELS, type Tenant, type TenantChannelName, TenantError, type TenantExtension, USER_CHANNELS, type User, type UserChannelName, UserRole, type WebhookEvent, createDatasourceMiddleware, createTenantExtension, defineIntegration, defineService, gatewayErrorHandler, getErrorLogLevel, isDev, isProd, isTest, configs as moleculer, nodeEnv, omit, prismaErrorHandler, retryExtension, sanitizeErrorData, softDeleteExtension };
package/dist/index.js CHANGED
@@ -1284,6 +1284,16 @@ var INTEGRATION_CHANNELS = {
1284
1284
  CONVERSATION_CREATED: "processing.conversation.created",
1285
1285
  MESSAGE_CREATED: "processing.message.created"
1286
1286
  };
1287
+ var TENANT_CHANNELS = {
1288
+ TENANT_CREATED: "tenant_created",
1289
+ TENANT_UPDATED: "tenant_updated",
1290
+ TENANT_DELETED: "tenant_deleted"
1291
+ };
1292
+ var USER_CHANNELS = {
1293
+ USER_CREATED: "user_created",
1294
+ USER_UPDATED: "user_updated",
1295
+ USER_DELETED: "user_deleted"
1296
+ };
1287
1297
  var CHANNEL_CONFIG = {
1288
1298
  // Default settings for message channels
1289
1299
  DEFAULTS: {
@@ -1372,16 +1382,37 @@ function defineIntegration(config) {
1372
1382
  path: "/:channelId"
1373
1383
  },
1374
1384
  params: {
1375
- channelId: "string",
1385
+ channelId: { type: "string", optional: true },
1376
1386
  payload: "object",
1377
1387
  headers: "object",
1378
1388
  timestamp: "number"
1379
1389
  },
1380
1390
  async handler(ctx) {
1381
- 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
+ }
1382
1414
  const webhook = {
1383
- tenantId: ctx.meta.tenantId ?? "unknown",
1384
- // Should come from channel lookup
1415
+ tenantId: tenantId ?? "unknown",
1385
1416
  channelId,
1386
1417
  platform: config.spec.platform,
1387
1418
  payload,
@@ -2663,4 +2694,4 @@ var retryExtension = {
2663
2694
  }
2664
2695
  };
2665
2696
 
2666
- export { AbstractDatasource, AuthenticationError, CHANNELS, ContextHelpersMiddleware, CreateHealthCheckMiddleware, DBConnectionError, DBConstraintError, DBError, DBNotFoundError, DBTimeoutError, DBTransactionError, DBValidationError, DEFAULT_DATASOURCE_CACHE_TTL, DatasourceMixin, HEALTH_CHECK_DEFAULTS, INTEGRATION_CHANNELS, IntegrationCapability, IntegrationPlatform, IntegrationStatus, MemoizeMixin, MessageContentType, NAMESPACE, PERMISSIONS, PermissionError, PermissionsMiddleware, PrismaDatasource, PrismaPgDatasource, REDIS_URL, ROLE_PERMISSIONS, SERVICE_NAME, SERVICE_VERSION, TenantError, UserRole, createDatasourceMiddleware, createTenantExtension, defineIntegration, defineService, env_default as env, gatewayErrorHandler, getErrorLogLevel, isDev, isProd, isTest, moleculer_default as moleculer, nodeEnv, omit, prismaErrorHandler, retryExtension, sanitizeErrorData, softDeleteExtension };
2697
+ export { AbstractDatasource, AuthenticationError, CHANNELS, ContextHelpersMiddleware, CreateHealthCheckMiddleware, DBConnectionError, DBConstraintError, DBError, DBNotFoundError, DBTimeoutError, DBTransactionError, DBValidationError, DEFAULT_DATASOURCE_CACHE_TTL, DatasourceMixin, HEALTH_CHECK_DEFAULTS, INTEGRATION_CHANNELS, IntegrationCapability, IntegrationPlatform, IntegrationStatus, MemoizeMixin, MessageContentType, NAMESPACE, PERMISSIONS, PermissionError, PermissionsMiddleware, PrismaDatasource, PrismaPgDatasource, REDIS_URL, ROLE_PERMISSIONS, SERVICE_NAME, SERVICE_VERSION, TENANT_CHANNELS, TenantError, USER_CHANNELS, UserRole, createDatasourceMiddleware, createTenantExtension, defineIntegration, defineService, env_default as env, gatewayErrorHandler, getErrorLogLevel, isDev, isProd, isTest, moleculer_default as moleculer, nodeEnv, omit, prismaErrorHandler, retryExtension, sanitizeErrorData, softDeleteExtension };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hiliosai/sdk",
3
- "version": "0.2.6",
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
+ }