@hiliosai/sdk 0.2.4 → 0.2.6

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
@@ -778,6 +778,9 @@ declare const INTEGRATION_CHANNELS: {
778
778
  readonly MESSAGE_RECEIVED: "processing.message.received";
779
779
  readonly MESSAGE_SENT: "processing.message.sent";
780
780
  readonly MESSAGE_FAILED: "processing.message.failed";
781
+ readonly CONTACT_CREATED: "processing.contact.created";
782
+ readonly CONVERSATION_CREATED: "processing.conversation.created";
783
+ readonly MESSAGE_CREATED: "processing.message.created";
781
784
  };
782
785
  type IntegrationChannelName = (typeof INTEGRATION_CHANNELS)[keyof typeof INTEGRATION_CHANNELS];
783
786
 
@@ -873,6 +876,8 @@ declare const isTest: boolean;
873
876
  declare const isProd: boolean;
874
877
  declare const REDIS_URL: string | undefined;
875
878
  declare const DEFAULT_DATASOURCE_CACHE_TTL: number;
879
+ declare const SERVICE_NAME: string;
880
+ declare const SERVICE_VERSION: string;
876
881
 
877
882
  type Env = typeof env;
878
883
 
@@ -989,4 +994,4 @@ declare class DBTransactionError extends Errors.MoleculerError {
989
994
  }
990
995
  declare function prismaErrorHandler(this: ServiceBroker, err: Error, info: BrokerErrorHandlerInfoAction): undefined;
991
996
 
992
- 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, 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 };
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 };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import env4 from '@ltv/env';
1
+ import env2 from '@ltv/env';
2
2
  import http from 'http';
3
3
  import { PrismaClientValidationError, PrismaClientInitializationError, PrismaClientUnknownRequestError, PrismaClientRustPanicError, PrismaClientKnownRequestError } from '@prisma/client/runtime/client';
4
4
  import { Errors } from 'moleculer';
@@ -55,12 +55,12 @@ function MemoizeMixin(options) {
55
55
  }
56
56
  };
57
57
  }
58
- var HEALTH_CHECK_PORT = env4.int("HEALTH_CHECK_PORT", 3301);
59
- var HEALTH_CHECK_READINESS_PATH = env4.string(
58
+ var HEALTH_CHECK_PORT = env2.int("HEALTH_CHECK_PORT", 3301);
59
+ var HEALTH_CHECK_READINESS_PATH = env2.string(
60
60
  "HEALTH_CHECK_READINESS_PATH",
61
61
  "/readyz"
62
62
  );
63
- var HEALTH_CHECK_LIVENESS_PATH = env4.string(
63
+ var HEALTH_CHECK_LIVENESS_PATH = env2.string(
64
64
  "HEALTH_CHECK_LIVENESS_PATH",
65
65
  "/livez"
66
66
  );
@@ -247,17 +247,19 @@ var ROLE_PERMISSIONS = {
247
247
  PERMISSIONS["config.read"]
248
248
  ]
249
249
  };
250
- var nodeEnv = env4.string("NODE_ENV", "development");
250
+ var nodeEnv = env2.string("NODE_ENV", "development");
251
251
  var isDev = nodeEnv === "development";
252
252
  var isTest = nodeEnv === "test";
253
253
  var isProd = nodeEnv === "production";
254
- var REDIS_URL = env4.string("REDIS_URL");
255
- var DEFAULT_DATASOURCE_CACHE_TTL = env4.number(
254
+ var REDIS_URL = env2.string("REDIS_URL");
255
+ var DEFAULT_DATASOURCE_CACHE_TTL = env2.number(
256
256
  "DEFAULT_DATASOURCE_CACHE_TTL",
257
257
  60
258
258
  // 60 seconds
259
259
  );
260
- var env_default = env4;
260
+ var SERVICE_NAME = env2.string("SERVICE_NAME", "hilios");
261
+ var SERVICE_VERSION = env2.string("SERVICE_VERSION", "1.0.0");
262
+ var env_default = env2;
261
263
 
262
264
  // src/errors/permission.error.ts
263
265
  var PermissionError = class _PermissionError extends Error {
@@ -1222,7 +1224,7 @@ function defineService(config) {
1222
1224
  ]
1223
1225
  };
1224
1226
  }
1225
- var NAMESPACE = env4.string("NAMESPACE", "hios").toLowerCase();
1227
+ var NAMESPACE = env2.string("NAMESPACE", "hios").toLowerCase();
1226
1228
  var CHANNELS = {
1227
1229
  // Webhook processing channels
1228
1230
  WEBHOOK: {
@@ -1277,7 +1279,10 @@ var INTEGRATION_CHANNELS = {
1277
1279
  // Message events
1278
1280
  MESSAGE_RECEIVED: "processing.message.received",
1279
1281
  MESSAGE_SENT: "processing.message.sent",
1280
- MESSAGE_FAILED: "processing.message.failed"
1282
+ MESSAGE_FAILED: "processing.message.failed",
1283
+ CONTACT_CREATED: "processing.contact.created",
1284
+ CONVERSATION_CREATED: "processing.conversation.created",
1285
+ MESSAGE_CREATED: "processing.message.created"
1281
1286
  };
1282
1287
  var CHANNEL_CONFIG = {
1283
1288
  // Default settings for message channels
@@ -1742,7 +1747,7 @@ var middleware = Middleware({
1742
1747
  type: "NATS",
1743
1748
  options: {
1744
1749
  nats: {
1745
- url: env4.string("NATS_URL", "nats://localhost:4222"),
1750
+ url: env2.string("NATS_URL", "nats://localhost:4222"),
1746
1751
  /** Connection options for reliability */
1747
1752
  connectionOptions: {
1748
1753
  name: "hios",
@@ -1775,17 +1780,17 @@ var middleware = Middleware({
1775
1780
  SUBJECTS.INTEGRATION_ALL
1776
1781
  ].map((subject) => `${NAMESPACE2.toLowerCase()}.${subject}`),
1777
1782
  retention: "limits",
1778
- max_msgs: env4.int("NATS_MAX_MESSAGES", 1e5),
1783
+ max_msgs: env2.int("NATS_MAX_MESSAGES", 1e5),
1779
1784
  // 100K for dev, 10M+ for prod
1780
- max_bytes: env4.int("NATS_MAX_BYTES_GB", 1) * 1024 * 1024 * 1024,
1785
+ max_bytes: env2.int("NATS_MAX_BYTES_GB", 1) * 1024 * 1024 * 1024,
1781
1786
  // 1GB for dev, 100GB+ for prod
1782
- max_age: env4.int("NATS_MAX_AGE_DAYS", 7) * 24 * 60 * 60 * 1e9,
1787
+ max_age: env2.int("NATS_MAX_AGE_DAYS", 7) * 24 * 60 * 60 * 1e9,
1783
1788
  // 7 days dev, 30+ days prod
1784
- max_msg_size: env4.int("NATS_MAX_MSG_SIZE_MB", 1) * 1024 * 1024,
1789
+ max_msg_size: env2.int("NATS_MAX_MSG_SIZE_MB", 1) * 1024 * 1024,
1785
1790
  // 1MB dev, 5MB prod
1786
1791
  storage: "file",
1787
1792
  // Persistent storage
1788
- num_replicas: env4.int("NATS_REPLICAS", 1),
1793
+ num_replicas: env2.int("NATS_REPLICAS", 1),
1789
1794
  // 1 for dev, 3 for prod
1790
1795
  discard: "old",
1791
1796
  // Remove old messages when limits hit
@@ -1869,14 +1874,16 @@ var loggerConfig = {
1869
1874
  var logger_default = loggerConfig;
1870
1875
 
1871
1876
  // src/configs/moleculer/metrics.ts
1877
+ var metricsEnabled = env_default.bool("METRICS_ENABLED", false);
1878
+ var metricsPort = env_default.number("METRICS_PORT", 3030);
1872
1879
  var metricsConfig = {
1873
- enabled: false,
1880
+ enabled: metricsEnabled,
1874
1881
  // Available built-in reporters: "Console", "CSV", "Event", "Prometheus", "Datadog", "StatsD"
1875
1882
  reporter: {
1876
1883
  type: "Prometheus",
1877
1884
  options: {
1878
1885
  // HTTP port
1879
- port: 3030,
1886
+ port: metricsPort,
1880
1887
  // HTTP URL path
1881
1888
  path: "/metrics",
1882
1889
  // Default labels which are appended to all metrics labels
@@ -1912,11 +1919,62 @@ var retryPolicyConfig = {
1912
1919
  // A function to check failed requests.
1913
1920
  check: (err) => !!err.retryable
1914
1921
  };
1915
-
1916
- // src/configs/moleculer/tracing.ts
1922
+ var tracingEnabled = env_default.bool("TRACING_ENABLED", true);
1923
+ var tracingConsoleDisabled = env_default.bool("TRACING_CONSOLE_DISABLED", false);
1924
+ var tracingJaegerEndpoint = env_default.string("JAEGER_ENDPOINT");
1925
+ var tracingJaegerEnabled = !!tracingJaegerEndpoint;
1926
+ var exporter = [];
1927
+ var jaegerTracer = {
1928
+ type: "Jaeger",
1929
+ options: {
1930
+ // HTTP Reporter endpoint. If set, HTTP Reporter will be used.
1931
+ endpoint: tracingJaegerEndpoint,
1932
+ // UDP Sender host option. Only used when endpoint is not set.
1933
+ host: tracingJaegerEndpoint ? void 0 : env_default.string("JAEGER_AGENT_HOST", "localhost"),
1934
+ // UDP Sender port option. Only used when endpoint is not set.
1935
+ port: tracingJaegerEndpoint ? void 0 : env_default.int("JAEGER_AGENT_PORT", 6832),
1936
+ // Jaeger Sampler configuration.
1937
+ sampler: {
1938
+ // Sampler type. More info: https://www.jaegertracing.io/docs/1.14/sampling/#client-sampling-configuration
1939
+ type: env_default.string("JAEGER_SAMPLER_TYPE", "Const"),
1940
+ // Sampler specific options.
1941
+ options: {
1942
+ param: env_default.float("JAEGER_SAMPLER_PARAM", 1)
1943
+ }
1944
+ },
1945
+ // Additional options for `Jaeger.Tracer`
1946
+ tracerOptions: {
1947
+ // Service name
1948
+ serviceName: SERVICE_NAME,
1949
+ // Disable Jaeger client metrics to reduce overhead
1950
+ metrics: false,
1951
+ // Max buffer size for UDP sender
1952
+ bufferFlushInterval: 1e4
1953
+ },
1954
+ // Default tags. They will be added into all span tags.
1955
+ defaultTags: {
1956
+ environment: nodeEnv,
1957
+ version: SERVICE_VERSION,
1958
+ hostname: os.hostname()
1959
+ }
1960
+ }
1961
+ };
1962
+ if (!tracingConsoleDisabled) {
1963
+ exporter.push({
1964
+ type: "Console",
1965
+ options: {
1966
+ colors: true,
1967
+ width: 100,
1968
+ gaugeWidth: 40
1969
+ }
1970
+ });
1971
+ }
1972
+ if (tracingJaegerEnabled) {
1973
+ exporter.push(jaegerTracer);
1974
+ }
1917
1975
  var tracingConfig = {
1918
- enabled: true,
1919
- exporter: "Console",
1976
+ enabled: tracingEnabled,
1977
+ exporter,
1920
1978
  events: true,
1921
1979
  stackTrace: true
1922
1980
  };
@@ -1930,8 +1988,8 @@ var trackingConfig = {
1930
1988
  };
1931
1989
 
1932
1990
  // src/configs/moleculer/index.ts
1933
- var pkgNm = env4.string("NAMESPACE", "hios");
1934
- var nodeID = env4.string("NODE_ID") ?? `${pkgNm}-${os.hostname()}-${process.pid}`;
1991
+ var pkgNm = env2.string("NAMESPACE", "hios");
1992
+ var nodeID = env2.string("NODE_ID") ?? `${pkgNm}-${os.hostname()}-${process.pid}`;
1935
1993
  var configs = {
1936
1994
  namespace: pkgNm,
1937
1995
  nodeID,
@@ -1940,7 +1998,7 @@ var configs = {
1940
1998
  // Default log level for built-in console logger. It can be overwritten in logger options above.
1941
1999
  // Available values: trace, debug, info, warn, error, fatal
1942
2000
  logLevel: "info",
1943
- cacher: env4.string("REDIS_URL", "Memory"),
2001
+ cacher: env2.string("REDIS_URL", "Memory"),
1944
2002
  // Define a serializer.
1945
2003
  // Available values: "JSON", "Avro", "ProtoBuf", "MsgPack", "Notepack", "Thrift".
1946
2004
  // More info: https://moleculer.services/docs/0.14/networking.html#Serialization
@@ -1970,7 +2028,7 @@ var configs = {
1970
2028
  // Enable action & event parameter validation. More info: https://moleculer.services/docs/0.14/validating.html
1971
2029
  validator: "Fastest",
1972
2030
  // errorHandler: null,
1973
- transporter: env4.string("TRANSPORTER_URL"),
2031
+ transporter: env2.string("TRANSPORTER_URL"),
1974
2032
  // Enable/disable built-in metrics function. More info: https://moleculer.services/docs/0.14/metrics.html
1975
2033
  metrics: metricsConfig,
1976
2034
  // Enable built-in tracing function. More info: https://moleculer.services/docs/0.14/tracing.html
@@ -2605,4 +2663,4 @@ var retryExtension = {
2605
2663
  }
2606
2664
  };
2607
2665
 
2608
- 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, 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 };
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hiliosai/sdk",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/index.js",