@hiliosai/sdk 0.1.15 → 0.1.17

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
@@ -1,4 +1,4 @@
1
- import { Context, ServiceBroker, ServiceSchema as ServiceSchema$1, ServiceSettingSchema, Service, BrokerOptions, ActionSchema, ServiceEvents, ServiceMethods, ServiceHooks } from 'moleculer';
1
+ import { Context, ServiceBroker, ServiceSchema as ServiceSchema$1, ServiceSettingSchema, Service, ActionSchema, ServiceEvents, ServiceMethods, ServiceHooks, Middleware, BrokerOptions } from 'moleculer';
2
2
  import env from '@ltv/env';
3
3
  export { default as env } from '@ltv/env';
4
4
 
@@ -57,7 +57,7 @@ interface PermissionHelpers {
57
57
  auditLog(action: string, resource?: unknown, metadata?: Record<string, unknown>): void;
58
58
  createError(message: string, code: string, statusCode?: number): Error;
59
59
  }
60
- type AppContext<TDatasources = unknown, TParams = unknown, TMeta extends AppMeta = AppMeta, TLocals = unknown> = Context<TParams, TMeta, TLocals> & PermissionHelpers & {
60
+ type AppContext<TDatasources = unknown, TParams = unknown, TMeta extends AppMeta = AppMeta, TLocals = Record<string, unknown>> = Context<TParams, TMeta, TLocals> & PermissionHelpers & {
61
61
  datasources: TDatasources;
62
62
  broker: Context['broker'] & {
63
63
  sendToChannel: SendToChannelMethod;
@@ -466,8 +466,6 @@ declare const PERMISSIONS: {
466
466
  };
467
467
  declare const ROLE_PERMISSIONS: Record<string, string[]>;
468
468
 
469
- declare const configs: BrokerOptions;
470
-
471
469
  declare enum IntegrationPlatform {
472
470
  WHATSAPP = "whatsapp",
473
471
  TELEGRAM = "telegram",
@@ -823,13 +821,9 @@ type Permission = keyof typeof PERMISSIONS | string | ((ctx: AppContext, action:
823
821
  interface ActionWithPermissions extends ActionSchema {
824
822
  permissions?: Permission | Permission[];
825
823
  }
826
- declare const PermissionsMiddleware: {
827
- localAction(handler: (...args: unknown[]) => unknown, action: ActionWithPermissions): ((...args: unknown[]) => unknown) | ((this: Service, ctx: AppContext) => Promise<unknown>);
828
- };
824
+ declare const PermissionsMiddleware: Middleware;
829
825
 
830
- declare const ContextHelpersMiddleware: {
831
- localAction(handler: (...args: unknown[]) => unknown): (this: unknown, ctx: AppContext) => unknown;
832
- };
826
+ declare const ContextHelpersMiddleware: Middleware;
833
827
 
834
828
  /**
835
829
  * Define a service
@@ -864,6 +858,8 @@ declare function defineService<TSettings = unknown, TDatasourceConstructors exte
864
858
 
865
859
  declare function defineIntegration<TSettings = unknown, TDatasourceConstructors extends DatasourceConstructorRegistry = DatasourceConstructorRegistry>(config: IntegrationServiceConfig<TSettings, TDatasourceConstructors>): IntegrationServiceSchema<TSettings>;
866
860
 
861
+ declare const configs: BrokerOptions;
862
+
867
863
  declare const nodeEnv: string;
868
864
  declare const isDev: boolean;
869
865
  declare const isTest: boolean;
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import env3 from '@ltv/env';
1
+ import env4 from '@ltv/env';
2
2
  import http from 'http';
3
+ import crypto from 'crypto';
3
4
  import os from 'os';
4
5
  import { Middleware } from '@moleculer/channels';
5
- import crypto from 'crypto';
6
6
 
7
7
  // src/middlewares/datasource.middleware.ts
8
8
  function initializeDatasources(constructorRegistry) {
@@ -52,12 +52,12 @@ function MemoizeMixin(options) {
52
52
  }
53
53
  };
54
54
  }
55
- var HEALTH_CHECK_PORT = env3.int("HEALTH_CHECK_PORT", 3301);
56
- var HEALTH_CHECK_READINESS_PATH = env3.string(
55
+ var HEALTH_CHECK_PORT = env4.int("HEALTH_CHECK_PORT", 3301);
56
+ var HEALTH_CHECK_READINESS_PATH = env4.string(
57
57
  "HEALTH_CHECK_READINESS_PATH",
58
58
  "/readyz"
59
59
  );
60
- var HEALTH_CHECK_LIVENESS_PATH = env3.string(
60
+ var HEALTH_CHECK_LIVENESS_PATH = env4.string(
61
61
  "HEALTH_CHECK_LIVENESS_PATH",
62
62
  "/livez"
63
63
  );
@@ -244,361 +244,12 @@ var ROLE_PERMISSIONS = {
244
244
  PERMISSIONS["config.read"]
245
245
  ]
246
246
  };
247
-
248
- // src/configs/moleculer/bulkhead.ts
249
- var bulkheadConfig = {
250
- // Enable feature.
251
- enabled: false,
252
- // Maximum concurrent executions.
253
- concurrency: 10,
254
- // Maximum size of queue
255
- maxQueueSize: 100
256
- };
257
- var NAMESPACE = env3.string("NAMESPACE", "hios").toLowerCase();
258
- var CHANNELS = {
259
- // Webhook processing channels
260
- WEBHOOK: {
261
- // Pattern: hios.webhook.{tenantId}.{platform}
262
- PATTERN: `${NAMESPACE}.webhook.*.*`,
263
- PREFIX: `${NAMESPACE}.webhook`,
264
- build: (tenantId, platform) => `${NAMESPACE}.webhook.${tenantId}.${platform}`
265
- },
266
- // Message processing channels
267
- PROCESSING: {
268
- // Pattern: hios.processing.{tenantId}.{messageType}
269
- PATTERN: `${NAMESPACE}.processing.*.*`,
270
- PREFIX: `${NAMESPACE}.processing`,
271
- build: (tenantId, messageType) => `${NAMESPACE}.processing.${tenantId}.${messageType}`
272
- },
273
- // Response/outbound message channels
274
- RESPONSE: {
275
- // Pattern: hios.response.{tenantId}.{platform}
276
- PATTERN: `${NAMESPACE}.response.*.*`,
277
- PREFIX: `${NAMESPACE}.response`,
278
- build: (tenantId, platform) => `${NAMESPACE}.response.${tenantId}.${platform}`
279
- },
280
- // System channels
281
- SYSTEM: {
282
- // Error handling
283
- ERRORS: `${NAMESPACE}.system.errors`,
284
- // Metrics and monitoring
285
- METRICS: `${NAMESPACE}.system.metrics`,
286
- // Health checks
287
- HEALTH: `${NAMESPACE}.system.health`,
288
- // Integration lifecycle events
289
- INTEGRATION_REGISTERED: `${NAMESPACE}.system.integration.registered`,
290
- INTEGRATION_UNREGISTERED: `${NAMESPACE}.system.integration.unregistered`
291
- },
292
- // Dead letter queues
293
- DLQ: {
294
- // Failed webhook processing
295
- WEBHOOK_FAILED: `${NAMESPACE}.dlq.webhook.failed`,
296
- // Failed message sends
297
- SEND_FAILED: `${NAMESPACE}.dlq.send.failed`,
298
- // Failed processing
299
- PROCESSING_FAILED: `${NAMESPACE}.dlq.processing.failed`,
300
- // Build DLQ name for specific integration
301
- buildSendFailed: (platform) => `${NAMESPACE}.dlq.send.${platform}.failed`
302
- }
303
- };
304
- var INTEGRATION_CHANNELS = {
305
- // Message events
306
- MESSAGE_RECEIVED: `${NAMESPACE}.processing.message.received`,
307
- MESSAGE_SENT: `${NAMESPACE}.processing.message.sent`,
308
- MESSAGE_FAILED: `${NAMESPACE}.processing.message.failed`
309
- };
310
- var CHANNEL_CONFIG = {
311
- // Default settings for message channels
312
- DEFAULTS: {
313
- maxInFlight: 10,
314
- maxRetries: 3,
315
- deadLettering: {
316
- enabled: true
317
- }
318
- },
319
- // High-priority channels (webhooks)
320
- HIGH_PRIORITY: {
321
- maxInFlight: 50,
322
- maxRetries: 5,
323
- deadLettering: {
324
- enabled: true
325
- }
326
- },
327
- // Low-priority channels (metrics, logs)
328
- LOW_PRIORITY: {
329
- maxInFlight: 5,
330
- maxRetries: 1,
331
- deadLettering: {
332
- enabled: false
333
- }
334
- }
335
- };
336
- var SUBJECTS = {
337
- // All webhook subjects
338
- WEBHOOK_ALL: `${NAMESPACE}.webhook.>`,
339
- // All processing subjects
340
- PROCESSING_ALL: `${NAMESPACE}.processing.>`,
341
- // All response subjects
342
- RESPONSE_ALL: `${NAMESPACE}.response.>`,
343
- // All system subjects
344
- SYSTEM_ALL: `${NAMESPACE}.system.>`,
345
- // All DLQ subjects
346
- DLQ_ALL: `${NAMESPACE}.dlq.>`};
347
-
348
- // src/configs/moleculer/channels.ts
349
- var NAMESPACE2 = NAMESPACE.toUpperCase();
350
- var middleware = Middleware({
351
- adapter: {
352
- type: "NATS",
353
- options: {
354
- nats: {
355
- url: env3.string("NATS_URL", "nats://localhost:4222"),
356
- /** Connection options for reliability */
357
- connectionOptions: {
358
- name: "hios",
359
- timeout: 1e4,
360
- reconnect: true,
361
- maxReconnectAttempts: 10,
362
- reconnectTimeWait: 2e3,
363
- maxReconnectTimeWait: 3e4,
364
- pingInterval: 2e4,
365
- maxPingOut: 2
366
- },
367
- /**
368
- * Stream configuration for multi-tenant messaging
369
- *
370
- * Environment variables for production:
371
- * - NATS_MAX_MESSAGES: Default 100K (dev) -> 10M+ (prod)
372
- * - NATS_MAX_BYTES_GB: Default 1GB (dev) -> 100GB+ (prod)
373
- * - NATS_MAX_AGE_DAYS: Default 7 (dev) -> 30+ (prod)
374
- * - NATS_MAX_MSG_SIZE_MB: Default 1MB (dev) -> 5MB (prod)
375
- * - NATS_REPLICAS: Default 1 (dev) -> 3 (prod)
376
- */
377
- streamConfig: {
378
- name: `${NAMESPACE2}_MESSAGES`,
379
- subjects: [
380
- SUBJECTS.WEBHOOK_ALL,
381
- SUBJECTS.PROCESSING_ALL,
382
- SUBJECTS.RESPONSE_ALL,
383
- SUBJECTS.SYSTEM_ALL,
384
- SUBJECTS.DLQ_ALL
385
- ],
386
- retention: "limits",
387
- max_msgs: env3.int("NATS_MAX_MESSAGES", 1e5),
388
- // 100K for dev, 10M+ for prod
389
- max_bytes: env3.int("NATS_MAX_BYTES_GB", 1) * 1024 * 1024 * 1024,
390
- // 1GB for dev, 100GB+ for prod
391
- max_age: env3.int("NATS_MAX_AGE_DAYS", 7) * 24 * 60 * 60 * 1e9,
392
- // 7 days dev, 30+ days prod
393
- max_msg_size: env3.int("NATS_MAX_MSG_SIZE_MB", 1) * 1024 * 1024,
394
- // 1MB dev, 5MB prod
395
- storage: "file",
396
- // Persistent storage
397
- num_replicas: env3.int("NATS_REPLICAS", 1),
398
- // 1 for dev, 3 for prod
399
- discard: "old",
400
- // Remove old messages when limits hit
401
- duplicate_window: 2 * 60 * 1e9
402
- // 2 minutes dedup window
403
- },
404
- /** Consumer options optimized for LLM processing */
405
- consumerOptions: {
406
- config: {
407
- // Start with new messages (don't replay old ones on restart)
408
- deliver_policy: "new",
409
- // Explicit acknowledgment required (critical for LLM processing)
410
- ack_policy: "explicit",
411
- // Allow 5 unacknowledged messages per consumer (rate limiting)
412
- max_ack_pending: 5,
413
- // Acknowledgment timeout for LLM processing (2 minutes)
414
- ack_wait: 120 * 1e9,
415
- // 2 minutes in nanoseconds
416
- // Maximum delivery attempts before dead letter
417
- max_deliver: 3,
418
- // Backoff for failed message retries
419
- backoff: [
420
- 1e9,
421
- // 1 second
422
- 5e9,
423
- // 5 seconds
424
- 3e10
425
- // 30 seconds
426
- ]
427
- }
428
- }
429
- },
430
- /** Application-level flow control */
431
- maxInFlight: 5,
432
- // Limit concurrent LLM requests per service
433
- maxRetries: 2,
434
- // App-level retries (NATS handles delivery retries)
435
- /** Dead letter queue for failed messages */
436
- deadLettering: {
437
- enabled: true,
438
- queueName: "FAILED_MESSAGES"
439
- // Send to dead letter after NATS max_deliver attempts
440
- }
441
- }
442
- }
443
- });
444
- var ChannelsMiddleware = {
445
- ...middleware
446
- };
447
-
448
- // src/configs/moleculer/circuit-breaker.ts
449
- var circuitBreakerConfig = {
450
- // Enable feature
451
- enabled: false,
452
- // Threshold value. 0.5 means that 50% should be failed for tripping.
453
- threshold: 0.5,
454
- // Minimum request count. Below it, CB does not trip.
455
- minRequestCount: 20,
456
- // Number of seconds for time window.
457
- windowTime: 60,
458
- // Number of milliseconds to switch from open to half-open state
459
- halfOpenTime: 10 * 1e3,
460
- // A function to check failed requests.
461
- check: (err) => err.code >= 500
462
- };
463
-
464
- // src/configs/moleculer/logger.ts
465
- var loggerConfig = {
466
- type: "Console",
467
- options: {
468
- // Using colors on the output
469
- colors: true,
470
- // Print module names with different colors (like docker-compose for containers)
471
- moduleColors: false,
472
- // Line formatter. It can be "json", "short", "simple", "full", a `Function` or a template string like "{timestamp} {level} {nodeID}/{mod}: {msg}"
473
- formatter: "full",
474
- // Custom object printer. If not defined, it uses the `util.inspect` method.
475
- objectPrinter: null,
476
- // Auto-padding the module name in order to messages begin at the same column.
477
- autoPadding: false
478
- }
479
- };
480
- var logger_default = loggerConfig;
481
-
482
- // src/configs/moleculer/metrics.ts
483
- var metricsConfig = {
484
- enabled: false,
485
- // Available built-in reporters: "Console", "CSV", "Event", "Prometheus", "Datadog", "StatsD"
486
- reporter: {
487
- type: "Prometheus",
488
- options: {
489
- // HTTP port
490
- port: 3030,
491
- // HTTP URL path
492
- path: "/metrics",
493
- // Default labels which are appended to all metrics labels
494
- defaultLabels: (registry) => ({
495
- namespace: registry.broker.namespace,
496
- nodeID: registry.broker.nodeID
497
- })
498
- }
499
- }
500
- };
501
-
502
- // src/configs/moleculer/registry.ts
503
- var registryConfig = {
504
- // Define balancing strategy. More info: https://moleculer.services/docs/0.14/balancing.html
505
- // Available values: "RoundRobin", "Random", "CpuUsage", "Latency", "Shard"
506
- strategy: "RoundRobin",
507
- // Enable local action call preferring. Always call the local action instance if available.
508
- preferLocal: true
509
- };
510
-
511
- // src/configs/moleculer/retry-policy.ts
512
- var retryPolicyConfig = {
513
- // Enable feature
514
- enabled: false,
515
- // Count of retries
516
- retries: 5,
517
- // First delay in milliseconds.
518
- delay: 100,
519
- // Maximum delay in milliseconds.
520
- maxDelay: 1e3,
521
- // Backoff factor for delay. 2 means exponential backoff.
522
- factor: 2,
523
- // A function to check failed requests.
524
- check: (err) => !!err.retryable
525
- };
526
-
527
- // src/configs/moleculer/tracing.ts
528
- var tracingConfig = {
529
- enabled: true,
530
- exporter: "Console",
531
- events: true,
532
- stackTrace: true
533
- };
534
-
535
- // src/configs/moleculer/tracking.ts
536
- var trackingConfig = {
537
- // Enable feature
538
- enabled: false,
539
- // Number of milliseconds to wait before shuting down the process.
540
- shutdownTimeout: 5e3
541
- };
542
-
543
- // src/configs/moleculer/index.ts
544
- var pkgNm = env3.string("NAMESPACE", "hios");
545
- var nodeID = env3.string("NODE_ID") ?? `${pkgNm}-${os.hostname()}-${process.pid}`;
546
- var configs = {
547
- namespace: pkgNm,
548
- nodeID,
549
- metadata: {},
550
- logger: logger_default,
551
- // Default log level for built-in console logger. It can be overwritten in logger options above.
552
- // Available values: trace, debug, info, warn, error, fatal
553
- logLevel: "info",
554
- cacher: env3.string("REDIS_URL", "Memory"),
555
- // Define a serializer.
556
- // Available values: "JSON", "Avro", "ProtoBuf", "MsgPack", "Notepack", "Thrift".
557
- // More info: https://moleculer.services/docs/0.14/networking.html#Serialization
558
- serializer: "JSON",
559
- // Number of milliseconds to wait before reject a request with a RequestTimeout error. Disabled: 0
560
- requestTimeout: 10 * 1e3,
561
- // Retry policy settings. More info: https://moleculer.services/docs/0.14/fault-tolerance.html#Retry
562
- retryPolicy: retryPolicyConfig,
563
- // Limit of calling level. If it reaches the limit, broker will throw an MaxCallLevelError error. (Infinite loop protection)
564
- maxCallLevel: 100,
565
- // Number of seconds to send heartbeat packet to other nodes.
566
- heartbeatInterval: 10,
567
- // Number of seconds to wait before setting node to unavailable status.
568
- heartbeatTimeout: 30,
569
- // Cloning the params of context if enabled. High performance impact, use it with caution!
570
- contextParamsCloning: false,
571
- // Tracking requests and waiting for running requests before shuting down. More info: https://moleculer.services/docs/0.14/context.html#Context-tracking
572
- tracking: trackingConfig,
573
- // Disable built-in request & emit balancer. (Transporter must support it, as well.). More info: https://moleculer.services/docs/0.14/networking.html#Disabled-balancer
574
- disableBalancer: false,
575
- // Settings of Service Registry. More info: https://moleculer.services/docs/0.14/registry.html
576
- registry: registryConfig,
577
- // Settings of Circuit Breaker. More info: https://moleculer.services/docs/0.14/fault-tolerance.html#Circuit-Breaker
578
- circuitBreaker: circuitBreakerConfig,
579
- // Settings of bulkhead feature. More info: https://moleculer.services/docs/0.14/fault-tolerance.html#Bulkhead
580
- bulkhead: bulkheadConfig,
581
- // Enable action & event parameter validation. More info: https://moleculer.services/docs/0.14/validating.html
582
- validator: "Fastest",
583
- // errorHandler: null,
584
- transporter: env3.string("TRANSPORTER_URL"),
585
- // Enable/disable built-in metrics function. More info: https://moleculer.services/docs/0.14/metrics.html
586
- metrics: metricsConfig,
587
- // Enable built-in tracing function. More info: https://moleculer.services/docs/0.14/tracing.html
588
- tracing: tracingConfig,
589
- middlewares: [
590
- ChannelsMiddleware,
591
- PermissionsMiddleware,
592
- ContextHelpersMiddleware
593
- ]
594
- };
595
- var moleculer_default = configs;
596
- var nodeEnv = env3.string("NODE_ENV", "development");
247
+ var nodeEnv = env4.string("NODE_ENV", "development");
597
248
  var isDev = nodeEnv === "development";
598
249
  var isTest = nodeEnv === "test";
599
250
  var isProd = nodeEnv === "production";
600
- var REDIS_URL = env3.string("REDIS_URL");
601
- var env_default = env3;
251
+ var REDIS_URL = env4.string("REDIS_URL");
252
+ var env_default = env4;
602
253
 
603
254
  // src/errors/permission.error.ts
604
255
  var PermissionError = class _PermissionError extends Error {
@@ -1020,6 +671,98 @@ function defineService(config) {
1020
671
  ]
1021
672
  };
1022
673
  }
674
+ var NAMESPACE = env4.string("NAMESPACE", "hios").toLowerCase();
675
+ var CHANNELS = {
676
+ // Webhook processing channels
677
+ WEBHOOK: {
678
+ // Pattern: hios.webhook.{tenantId}.{platform}
679
+ PATTERN: `${NAMESPACE}.webhook.*.*`,
680
+ PREFIX: `${NAMESPACE}.webhook`,
681
+ build: (tenantId, platform) => `${NAMESPACE}.webhook.${tenantId}.${platform}`
682
+ },
683
+ // Message processing channels
684
+ PROCESSING: {
685
+ // Pattern: hios.processing.{tenantId}.{messageType}
686
+ PATTERN: `${NAMESPACE}.processing.*.*`,
687
+ PREFIX: `${NAMESPACE}.processing`,
688
+ build: (tenantId, messageType) => `${NAMESPACE}.processing.${tenantId}.${messageType}`
689
+ },
690
+ // Response/outbound message channels
691
+ RESPONSE: {
692
+ // Pattern: hios.response.{tenantId}.{platform}
693
+ PATTERN: `${NAMESPACE}.response.*.*`,
694
+ PREFIX: `${NAMESPACE}.response`,
695
+ build: (tenantId, platform) => `${NAMESPACE}.response.${tenantId}.${platform}`
696
+ },
697
+ // System channels
698
+ SYSTEM: {
699
+ // Error handling
700
+ ERRORS: `${NAMESPACE}.system.errors`,
701
+ // Metrics and monitoring
702
+ METRICS: `${NAMESPACE}.system.metrics`,
703
+ // Health checks
704
+ HEALTH: `${NAMESPACE}.system.health`,
705
+ // Integration lifecycle events
706
+ INTEGRATION_REGISTERED: `${NAMESPACE}.system.integration.registered`,
707
+ INTEGRATION_UNREGISTERED: `${NAMESPACE}.system.integration.unregistered`
708
+ },
709
+ // Dead letter queues
710
+ DLQ: {
711
+ // Failed webhook processing
712
+ WEBHOOK_FAILED: `${NAMESPACE}.dlq.webhook.failed`,
713
+ // Failed message sends
714
+ SEND_FAILED: `${NAMESPACE}.dlq.send.failed`,
715
+ // Failed processing
716
+ PROCESSING_FAILED: `${NAMESPACE}.dlq.processing.failed`,
717
+ // Build DLQ name for specific integration
718
+ buildSendFailed: (platform) => `${NAMESPACE}.dlq.send.${platform}.failed`
719
+ }
720
+ };
721
+ var INTEGRATION_CHANNELS = {
722
+ // Message events
723
+ MESSAGE_RECEIVED: `${NAMESPACE}.processing.message.received`,
724
+ MESSAGE_SENT: `${NAMESPACE}.processing.message.sent`,
725
+ MESSAGE_FAILED: `${NAMESPACE}.processing.message.failed`
726
+ };
727
+ var CHANNEL_CONFIG = {
728
+ // Default settings for message channels
729
+ DEFAULTS: {
730
+ maxInFlight: 10,
731
+ maxRetries: 3,
732
+ deadLettering: {
733
+ enabled: true
734
+ }
735
+ },
736
+ // High-priority channels (webhooks)
737
+ HIGH_PRIORITY: {
738
+ maxInFlight: 50,
739
+ maxRetries: 5,
740
+ deadLettering: {
741
+ enabled: true
742
+ }
743
+ },
744
+ // Low-priority channels (metrics, logs)
745
+ LOW_PRIORITY: {
746
+ maxInFlight: 5,
747
+ maxRetries: 1,
748
+ deadLettering: {
749
+ enabled: false
750
+ }
751
+ }
752
+ };
753
+ var SUBJECTS = {
754
+ // All webhook subjects
755
+ WEBHOOK_ALL: `${NAMESPACE}.webhook.>`,
756
+ // All processing subjects
757
+ PROCESSING_ALL: `${NAMESPACE}.processing.>`,
758
+ // All response subjects
759
+ RESPONSE_ALL: `${NAMESPACE}.response.>`,
760
+ // All system subjects
761
+ SYSTEM_ALL: `${NAMESPACE}.system.>`,
762
+ // All DLQ subjects
763
+ DLQ_ALL: `${NAMESPACE}.dlq.>`};
764
+
765
+ // src/service/define-integration.ts
1023
766
  var SecurityHelpers = {
1024
767
  /**
1025
768
  * Secure comparison using Node.js crypto.timingSafeEqual
@@ -1236,10 +979,10 @@ function defineIntegration(config) {
1236
979
  i_verifyWebhook: {
1237
980
  rest: {
1238
981
  method: "GET",
1239
- path: "/:tenantId"
982
+ path: "/:channelId"
1240
983
  },
1241
984
  params: {
1242
- tenantId: "string",
985
+ channelId: "string",
1243
986
  mode: "string",
1244
987
  token: "string",
1245
988
  challenge: "string"
@@ -1373,6 +1116,263 @@ var UserRole = {
1373
1116
  VIEWER: "VIEWER"
1374
1117
  };
1375
1118
 
1119
+ // src/configs/moleculer/bulkhead.ts
1120
+ var bulkheadConfig = {
1121
+ // Enable feature.
1122
+ enabled: false,
1123
+ // Maximum concurrent executions.
1124
+ concurrency: 10,
1125
+ // Maximum size of queue
1126
+ maxQueueSize: 100
1127
+ };
1128
+ var NAMESPACE2 = NAMESPACE.toUpperCase();
1129
+ var middleware = Middleware({
1130
+ adapter: {
1131
+ type: "NATS",
1132
+ options: {
1133
+ nats: {
1134
+ url: env4.string("NATS_URL", "nats://localhost:4222"),
1135
+ /** Connection options for reliability */
1136
+ connectionOptions: {
1137
+ name: "hios",
1138
+ timeout: 1e4,
1139
+ reconnect: true,
1140
+ maxReconnectAttempts: 10,
1141
+ reconnectTimeWait: 2e3,
1142
+ maxReconnectTimeWait: 3e4,
1143
+ pingInterval: 2e4,
1144
+ maxPingOut: 2
1145
+ },
1146
+ /**
1147
+ * Stream configuration for multi-tenant messaging
1148
+ *
1149
+ * Environment variables for production:
1150
+ * - NATS_MAX_MESSAGES: Default 100K (dev) -> 10M+ (prod)
1151
+ * - NATS_MAX_BYTES_GB: Default 1GB (dev) -> 100GB+ (prod)
1152
+ * - NATS_MAX_AGE_DAYS: Default 7 (dev) -> 30+ (prod)
1153
+ * - NATS_MAX_MSG_SIZE_MB: Default 1MB (dev) -> 5MB (prod)
1154
+ * - NATS_REPLICAS: Default 1 (dev) -> 3 (prod)
1155
+ */
1156
+ streamConfig: {
1157
+ name: `${NAMESPACE2}_MESSAGES`,
1158
+ subjects: [
1159
+ SUBJECTS.WEBHOOK_ALL,
1160
+ SUBJECTS.PROCESSING_ALL,
1161
+ SUBJECTS.RESPONSE_ALL,
1162
+ SUBJECTS.SYSTEM_ALL,
1163
+ SUBJECTS.DLQ_ALL
1164
+ ],
1165
+ retention: "limits",
1166
+ max_msgs: env4.int("NATS_MAX_MESSAGES", 1e5),
1167
+ // 100K for dev, 10M+ for prod
1168
+ max_bytes: env4.int("NATS_MAX_BYTES_GB", 1) * 1024 * 1024 * 1024,
1169
+ // 1GB for dev, 100GB+ for prod
1170
+ max_age: env4.int("NATS_MAX_AGE_DAYS", 7) * 24 * 60 * 60 * 1e9,
1171
+ // 7 days dev, 30+ days prod
1172
+ max_msg_size: env4.int("NATS_MAX_MSG_SIZE_MB", 1) * 1024 * 1024,
1173
+ // 1MB dev, 5MB prod
1174
+ storage: "file",
1175
+ // Persistent storage
1176
+ num_replicas: env4.int("NATS_REPLICAS", 1),
1177
+ // 1 for dev, 3 for prod
1178
+ discard: "old",
1179
+ // Remove old messages when limits hit
1180
+ duplicate_window: 2 * 60 * 1e9
1181
+ // 2 minutes dedup window
1182
+ },
1183
+ /** Consumer options optimized for LLM processing */
1184
+ consumerOptions: {
1185
+ config: {
1186
+ // Start with new messages (don't replay old ones on restart)
1187
+ deliver_policy: "new",
1188
+ // Explicit acknowledgment required (critical for LLM processing)
1189
+ ack_policy: "explicit",
1190
+ // Allow 5 unacknowledged messages per consumer (rate limiting)
1191
+ max_ack_pending: 5,
1192
+ // Acknowledgment timeout for LLM processing (2 minutes)
1193
+ ack_wait: 120 * 1e9,
1194
+ // 2 minutes in nanoseconds
1195
+ // Maximum delivery attempts before dead letter
1196
+ max_deliver: 3,
1197
+ // Backoff for failed message retries
1198
+ backoff: [
1199
+ 1e9,
1200
+ // 1 second
1201
+ 5e9,
1202
+ // 5 seconds
1203
+ 3e10
1204
+ // 30 seconds
1205
+ ]
1206
+ }
1207
+ }
1208
+ },
1209
+ /** Application-level flow control */
1210
+ maxInFlight: 5,
1211
+ // Limit concurrent LLM requests per service
1212
+ maxRetries: 2,
1213
+ // App-level retries (NATS handles delivery retries)
1214
+ /** Dead letter queue for failed messages */
1215
+ deadLettering: {
1216
+ enabled: true,
1217
+ queueName: "FAILED_MESSAGES"
1218
+ // Send to dead letter after NATS max_deliver attempts
1219
+ }
1220
+ }
1221
+ }
1222
+ });
1223
+ var ChannelsMiddleware = {
1224
+ ...middleware
1225
+ };
1226
+
1227
+ // src/configs/moleculer/circuit-breaker.ts
1228
+ var circuitBreakerConfig = {
1229
+ // Enable feature
1230
+ enabled: false,
1231
+ // Threshold value. 0.5 means that 50% should be failed for tripping.
1232
+ threshold: 0.5,
1233
+ // Minimum request count. Below it, CB does not trip.
1234
+ minRequestCount: 20,
1235
+ // Number of seconds for time window.
1236
+ windowTime: 60,
1237
+ // Number of milliseconds to switch from open to half-open state
1238
+ halfOpenTime: 10 * 1e3,
1239
+ // A function to check failed requests.
1240
+ check: (err) => err.code >= 500
1241
+ };
1242
+
1243
+ // src/configs/moleculer/logger.ts
1244
+ var loggerConfig = {
1245
+ type: "Console",
1246
+ options: {
1247
+ // Using colors on the output
1248
+ colors: true,
1249
+ // Print module names with different colors (like docker-compose for containers)
1250
+ moduleColors: false,
1251
+ // Line formatter. It can be "json", "short", "simple", "full", a `Function` or a template string like "{timestamp} {level} {nodeID}/{mod}: {msg}"
1252
+ formatter: "full",
1253
+ // Custom object printer. If not defined, it uses the `util.inspect` method.
1254
+ objectPrinter: null,
1255
+ // Auto-padding the module name in order to messages begin at the same column.
1256
+ autoPadding: false
1257
+ }
1258
+ };
1259
+ var logger_default = loggerConfig;
1260
+
1261
+ // src/configs/moleculer/metrics.ts
1262
+ var metricsConfig = {
1263
+ enabled: false,
1264
+ // Available built-in reporters: "Console", "CSV", "Event", "Prometheus", "Datadog", "StatsD"
1265
+ reporter: {
1266
+ type: "Prometheus",
1267
+ options: {
1268
+ // HTTP port
1269
+ port: 3030,
1270
+ // HTTP URL path
1271
+ path: "/metrics",
1272
+ // Default labels which are appended to all metrics labels
1273
+ defaultLabels: (registry) => ({
1274
+ namespace: registry.broker.namespace,
1275
+ nodeID: registry.broker.nodeID
1276
+ })
1277
+ }
1278
+ }
1279
+ };
1280
+
1281
+ // src/configs/moleculer/registry.ts
1282
+ var registryConfig = {
1283
+ // Define balancing strategy. More info: https://moleculer.services/docs/0.14/balancing.html
1284
+ // Available values: "RoundRobin", "Random", "CpuUsage", "Latency", "Shard"
1285
+ strategy: "RoundRobin",
1286
+ // Enable local action call preferring. Always call the local action instance if available.
1287
+ preferLocal: true
1288
+ };
1289
+
1290
+ // src/configs/moleculer/retry-policy.ts
1291
+ var retryPolicyConfig = {
1292
+ // Enable feature
1293
+ enabled: false,
1294
+ // Count of retries
1295
+ retries: 5,
1296
+ // First delay in milliseconds.
1297
+ delay: 100,
1298
+ // Maximum delay in milliseconds.
1299
+ maxDelay: 1e3,
1300
+ // Backoff factor for delay. 2 means exponential backoff.
1301
+ factor: 2,
1302
+ // A function to check failed requests.
1303
+ check: (err) => !!err.retryable
1304
+ };
1305
+
1306
+ // src/configs/moleculer/tracing.ts
1307
+ var tracingConfig = {
1308
+ enabled: true,
1309
+ exporter: "Console",
1310
+ events: true,
1311
+ stackTrace: true
1312
+ };
1313
+
1314
+ // src/configs/moleculer/tracking.ts
1315
+ var trackingConfig = {
1316
+ // Enable feature
1317
+ enabled: false,
1318
+ // Number of milliseconds to wait before shuting down the process.
1319
+ shutdownTimeout: 5e3
1320
+ };
1321
+
1322
+ // src/configs/moleculer/index.ts
1323
+ var pkgNm = env4.string("NAMESPACE", "hios");
1324
+ var nodeID = env4.string("NODE_ID") ?? `${pkgNm}-${os.hostname()}-${process.pid}`;
1325
+ var configs = {
1326
+ namespace: pkgNm,
1327
+ nodeID,
1328
+ metadata: {},
1329
+ logger: logger_default,
1330
+ // Default log level for built-in console logger. It can be overwritten in logger options above.
1331
+ // Available values: trace, debug, info, warn, error, fatal
1332
+ logLevel: "info",
1333
+ cacher: env4.string("REDIS_URL", "Memory"),
1334
+ // Define a serializer.
1335
+ // Available values: "JSON", "Avro", "ProtoBuf", "MsgPack", "Notepack", "Thrift".
1336
+ // More info: https://moleculer.services/docs/0.14/networking.html#Serialization
1337
+ serializer: "JSON",
1338
+ // Number of milliseconds to wait before reject a request with a RequestTimeout error. Disabled: 0
1339
+ requestTimeout: 10 * 1e3,
1340
+ // Retry policy settings. More info: https://moleculer.services/docs/0.14/fault-tolerance.html#Retry
1341
+ retryPolicy: retryPolicyConfig,
1342
+ // Limit of calling level. If it reaches the limit, broker will throw an MaxCallLevelError error. (Infinite loop protection)
1343
+ maxCallLevel: 100,
1344
+ // Number of seconds to send heartbeat packet to other nodes.
1345
+ heartbeatInterval: 10,
1346
+ // Number of seconds to wait before setting node to unavailable status.
1347
+ heartbeatTimeout: 30,
1348
+ // Cloning the params of context if enabled. High performance impact, use it with caution!
1349
+ contextParamsCloning: false,
1350
+ // Tracking requests and waiting for running requests before shuting down. More info: https://moleculer.services/docs/0.14/context.html#Context-tracking
1351
+ tracking: trackingConfig,
1352
+ // Disable built-in request & emit balancer. (Transporter must support it, as well.). More info: https://moleculer.services/docs/0.14/networking.html#Disabled-balancer
1353
+ disableBalancer: false,
1354
+ // Settings of Service Registry. More info: https://moleculer.services/docs/0.14/registry.html
1355
+ registry: registryConfig,
1356
+ // Settings of Circuit Breaker. More info: https://moleculer.services/docs/0.14/fault-tolerance.html#Circuit-Breaker
1357
+ circuitBreaker: circuitBreakerConfig,
1358
+ // Settings of bulkhead feature. More info: https://moleculer.services/docs/0.14/fault-tolerance.html#Bulkhead
1359
+ bulkhead: bulkheadConfig,
1360
+ // Enable action & event parameter validation. More info: https://moleculer.services/docs/0.14/validating.html
1361
+ validator: "Fastest",
1362
+ // errorHandler: null,
1363
+ transporter: env4.string("TRANSPORTER_URL"),
1364
+ // Enable/disable built-in metrics function. More info: https://moleculer.services/docs/0.14/metrics.html
1365
+ metrics: metricsConfig,
1366
+ // Enable built-in tracing function. More info: https://moleculer.services/docs/0.14/tracing.html
1367
+ tracing: tracingConfig,
1368
+ middlewares: [
1369
+ ChannelsMiddleware,
1370
+ PermissionsMiddleware,
1371
+ ContextHelpersMiddleware
1372
+ ]
1373
+ };
1374
+ var moleculer_default = configs;
1375
+
1376
1376
  // src/datasources/base.datasource.ts
1377
1377
  var AbstractDatasource = class {
1378
1378
  /**
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@hiliosai/sdk",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "type": "module",
5
+ "license": "UNLICENSED",
5
6
  "main": "./dist/index.js",
6
7
  "types": "./dist/index.d.ts",
7
8
  "exports": {