@hiliosai/sdk 0.2.4 → 0.2.5
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 +3 -1
- package/dist/index.js +81 -26
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -873,6 +873,8 @@ declare const isTest: boolean;
|
|
|
873
873
|
declare const isProd: boolean;
|
|
874
874
|
declare const REDIS_URL: string | undefined;
|
|
875
875
|
declare const DEFAULT_DATASOURCE_CACHE_TTL: number;
|
|
876
|
+
declare const SERVICE_NAME: string;
|
|
877
|
+
declare const SERVICE_VERSION: string;
|
|
876
878
|
|
|
877
879
|
type Env = typeof env;
|
|
878
880
|
|
|
@@ -989,4 +991,4 @@ declare class DBTransactionError extends Errors.MoleculerError {
|
|
|
989
991
|
}
|
|
990
992
|
declare function prismaErrorHandler(this: ServiceBroker, err: Error, info: BrokerErrorHandlerInfoAction): undefined;
|
|
991
993
|
|
|
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 };
|
|
994
|
+
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
|
|
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 =
|
|
59
|
-
var HEALTH_CHECK_READINESS_PATH =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
255
|
-
var DEFAULT_DATASOURCE_CACHE_TTL =
|
|
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
|
|
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 =
|
|
1227
|
+
var NAMESPACE = env2.string("NAMESPACE", "hios").toLowerCase();
|
|
1226
1228
|
var CHANNELS = {
|
|
1227
1229
|
// Webhook processing channels
|
|
1228
1230
|
WEBHOOK: {
|
|
@@ -1742,7 +1744,7 @@ var middleware = Middleware({
|
|
|
1742
1744
|
type: "NATS",
|
|
1743
1745
|
options: {
|
|
1744
1746
|
nats: {
|
|
1745
|
-
url:
|
|
1747
|
+
url: env2.string("NATS_URL", "nats://localhost:4222"),
|
|
1746
1748
|
/** Connection options for reliability */
|
|
1747
1749
|
connectionOptions: {
|
|
1748
1750
|
name: "hios",
|
|
@@ -1775,17 +1777,17 @@ var middleware = Middleware({
|
|
|
1775
1777
|
SUBJECTS.INTEGRATION_ALL
|
|
1776
1778
|
].map((subject) => `${NAMESPACE2.toLowerCase()}.${subject}`),
|
|
1777
1779
|
retention: "limits",
|
|
1778
|
-
max_msgs:
|
|
1780
|
+
max_msgs: env2.int("NATS_MAX_MESSAGES", 1e5),
|
|
1779
1781
|
// 100K for dev, 10M+ for prod
|
|
1780
|
-
max_bytes:
|
|
1782
|
+
max_bytes: env2.int("NATS_MAX_BYTES_GB", 1) * 1024 * 1024 * 1024,
|
|
1781
1783
|
// 1GB for dev, 100GB+ for prod
|
|
1782
|
-
max_age:
|
|
1784
|
+
max_age: env2.int("NATS_MAX_AGE_DAYS", 7) * 24 * 60 * 60 * 1e9,
|
|
1783
1785
|
// 7 days dev, 30+ days prod
|
|
1784
|
-
max_msg_size:
|
|
1786
|
+
max_msg_size: env2.int("NATS_MAX_MSG_SIZE_MB", 1) * 1024 * 1024,
|
|
1785
1787
|
// 1MB dev, 5MB prod
|
|
1786
1788
|
storage: "file",
|
|
1787
1789
|
// Persistent storage
|
|
1788
|
-
num_replicas:
|
|
1790
|
+
num_replicas: env2.int("NATS_REPLICAS", 1),
|
|
1789
1791
|
// 1 for dev, 3 for prod
|
|
1790
1792
|
discard: "old",
|
|
1791
1793
|
// Remove old messages when limits hit
|
|
@@ -1869,14 +1871,16 @@ var loggerConfig = {
|
|
|
1869
1871
|
var logger_default = loggerConfig;
|
|
1870
1872
|
|
|
1871
1873
|
// src/configs/moleculer/metrics.ts
|
|
1874
|
+
var metricsEnabled = env_default.bool("METRICS_ENABLED", false);
|
|
1875
|
+
var metricsPort = env_default.number("METRICS_PORT", 3030);
|
|
1872
1876
|
var metricsConfig = {
|
|
1873
|
-
enabled:
|
|
1877
|
+
enabled: metricsEnabled,
|
|
1874
1878
|
// Available built-in reporters: "Console", "CSV", "Event", "Prometheus", "Datadog", "StatsD"
|
|
1875
1879
|
reporter: {
|
|
1876
1880
|
type: "Prometheus",
|
|
1877
1881
|
options: {
|
|
1878
1882
|
// HTTP port
|
|
1879
|
-
port:
|
|
1883
|
+
port: metricsPort,
|
|
1880
1884
|
// HTTP URL path
|
|
1881
1885
|
path: "/metrics",
|
|
1882
1886
|
// Default labels which are appended to all metrics labels
|
|
@@ -1912,11 +1916,62 @@ var retryPolicyConfig = {
|
|
|
1912
1916
|
// A function to check failed requests.
|
|
1913
1917
|
check: (err) => !!err.retryable
|
|
1914
1918
|
};
|
|
1915
|
-
|
|
1916
|
-
|
|
1919
|
+
var tracingEnabled = env_default.bool("TRACING_ENABLED", true);
|
|
1920
|
+
var tracingConsoleDisabled = env_default.bool("TRACING_CONSOLE_DISABLED", false);
|
|
1921
|
+
var tracingJaegerEndpoint = env_default.string("JAEGER_ENDPOINT");
|
|
1922
|
+
var tracingJaegerEnabled = !!tracingJaegerEndpoint;
|
|
1923
|
+
var exporter = [];
|
|
1924
|
+
var jaegerTracer = {
|
|
1925
|
+
type: "Jaeger",
|
|
1926
|
+
options: {
|
|
1927
|
+
// HTTP Reporter endpoint. If set, HTTP Reporter will be used.
|
|
1928
|
+
endpoint: tracingJaegerEndpoint,
|
|
1929
|
+
// UDP Sender host option. Only used when endpoint is not set.
|
|
1930
|
+
host: tracingJaegerEndpoint ? void 0 : env_default.string("JAEGER_AGENT_HOST", "localhost"),
|
|
1931
|
+
// UDP Sender port option. Only used when endpoint is not set.
|
|
1932
|
+
port: tracingJaegerEndpoint ? void 0 : env_default.int("JAEGER_AGENT_PORT", 6832),
|
|
1933
|
+
// Jaeger Sampler configuration.
|
|
1934
|
+
sampler: {
|
|
1935
|
+
// Sampler type. More info: https://www.jaegertracing.io/docs/1.14/sampling/#client-sampling-configuration
|
|
1936
|
+
type: env_default.string("JAEGER_SAMPLER_TYPE", "Const"),
|
|
1937
|
+
// Sampler specific options.
|
|
1938
|
+
options: {
|
|
1939
|
+
param: env_default.float("JAEGER_SAMPLER_PARAM", 1)
|
|
1940
|
+
}
|
|
1941
|
+
},
|
|
1942
|
+
// Additional options for `Jaeger.Tracer`
|
|
1943
|
+
tracerOptions: {
|
|
1944
|
+
// Service name
|
|
1945
|
+
serviceName: SERVICE_NAME,
|
|
1946
|
+
// Disable Jaeger client metrics to reduce overhead
|
|
1947
|
+
metrics: false,
|
|
1948
|
+
// Max buffer size for UDP sender
|
|
1949
|
+
bufferFlushInterval: 1e4
|
|
1950
|
+
},
|
|
1951
|
+
// Default tags. They will be added into all span tags.
|
|
1952
|
+
defaultTags: {
|
|
1953
|
+
environment: nodeEnv,
|
|
1954
|
+
version: SERVICE_VERSION,
|
|
1955
|
+
hostname: os.hostname()
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
};
|
|
1959
|
+
if (!tracingConsoleDisabled) {
|
|
1960
|
+
exporter.push({
|
|
1961
|
+
type: "Console",
|
|
1962
|
+
options: {
|
|
1963
|
+
colors: true,
|
|
1964
|
+
width: 100,
|
|
1965
|
+
gaugeWidth: 40
|
|
1966
|
+
}
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1969
|
+
if (tracingJaegerEnabled) {
|
|
1970
|
+
exporter.push(jaegerTracer);
|
|
1971
|
+
}
|
|
1917
1972
|
var tracingConfig = {
|
|
1918
|
-
enabled:
|
|
1919
|
-
exporter
|
|
1973
|
+
enabled: tracingEnabled,
|
|
1974
|
+
exporter,
|
|
1920
1975
|
events: true,
|
|
1921
1976
|
stackTrace: true
|
|
1922
1977
|
};
|
|
@@ -1930,8 +1985,8 @@ var trackingConfig = {
|
|
|
1930
1985
|
};
|
|
1931
1986
|
|
|
1932
1987
|
// src/configs/moleculer/index.ts
|
|
1933
|
-
var pkgNm =
|
|
1934
|
-
var nodeID =
|
|
1988
|
+
var pkgNm = env2.string("NAMESPACE", "hios");
|
|
1989
|
+
var nodeID = env2.string("NODE_ID") ?? `${pkgNm}-${os.hostname()}-${process.pid}`;
|
|
1935
1990
|
var configs = {
|
|
1936
1991
|
namespace: pkgNm,
|
|
1937
1992
|
nodeID,
|
|
@@ -1940,7 +1995,7 @@ var configs = {
|
|
|
1940
1995
|
// Default log level for built-in console logger. It can be overwritten in logger options above.
|
|
1941
1996
|
// Available values: trace, debug, info, warn, error, fatal
|
|
1942
1997
|
logLevel: "info",
|
|
1943
|
-
cacher:
|
|
1998
|
+
cacher: env2.string("REDIS_URL", "Memory"),
|
|
1944
1999
|
// Define a serializer.
|
|
1945
2000
|
// Available values: "JSON", "Avro", "ProtoBuf", "MsgPack", "Notepack", "Thrift".
|
|
1946
2001
|
// More info: https://moleculer.services/docs/0.14/networking.html#Serialization
|
|
@@ -1970,7 +2025,7 @@ var configs = {
|
|
|
1970
2025
|
// Enable action & event parameter validation. More info: https://moleculer.services/docs/0.14/validating.html
|
|
1971
2026
|
validator: "Fastest",
|
|
1972
2027
|
// errorHandler: null,
|
|
1973
|
-
transporter:
|
|
2028
|
+
transporter: env2.string("TRANSPORTER_URL"),
|
|
1974
2029
|
// Enable/disable built-in metrics function. More info: https://moleculer.services/docs/0.14/metrics.html
|
|
1975
2030
|
metrics: metricsConfig,
|
|
1976
2031
|
// Enable built-in tracing function. More info: https://moleculer.services/docs/0.14/tracing.html
|
|
@@ -2605,4 +2660,4 @@ var retryExtension = {
|
|
|
2605
2660
|
}
|
|
2606
2661
|
};
|
|
2607
2662
|
|
|
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 };
|
|
2663
|
+
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 };
|