@hiliosai/sdk 0.1.12 → 0.1.15
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 +904 -0
- package/dist/index.js +1809 -0
- package/package.json +10 -2
- package/src/configs/constants.ts +0 -135
- package/src/configs/index.ts +0 -2
- package/src/configs/moleculer/bulkhead.ts +0 -8
- package/src/configs/moleculer/channels.ts +0 -102
- package/src/configs/moleculer/circuit-breaker.ts +0 -17
- package/src/configs/moleculer/index.ts +0 -98
- package/src/configs/moleculer/logger.ts +0 -17
- package/src/configs/moleculer/metrics.ts +0 -20
- package/src/configs/moleculer/registry.ts +0 -7
- package/src/configs/moleculer/retry-policy.ts +0 -17
- package/src/configs/moleculer/tracing.ts +0 -6
- package/src/configs/moleculer/tracking.ts +0 -6
- package/src/configs/permissions.ts +0 -109
- package/src/datasources/base.datasource.ts +0 -111
- package/src/datasources/extensions/index.ts +0 -11
- package/src/datasources/extensions/retry.extension.ts +0 -91
- package/src/datasources/extensions/soft-delete.extension.ts +0 -114
- package/src/datasources/extensions/tenant.extension.ts +0 -105
- package/src/datasources/index.ts +0 -3
- package/src/datasources/prisma.datasource.ts +0 -317
- package/src/env.ts +0 -12
- package/src/errors/auth.error.ts +0 -33
- package/src/errors/index.ts +0 -2
- package/src/errors/permission.error.ts +0 -17
- package/src/index.ts +0 -10
- package/src/middlewares/context-helpers.middleware.ts +0 -162
- package/src/middlewares/datasource.middleware.ts +0 -73
- package/src/middlewares/health.middleware.ts +0 -134
- package/src/middlewares/index.ts +0 -5
- package/src/middlewares/memoize.middleware.ts +0 -33
- package/src/middlewares/permissions.middleware.ts +0 -162
- package/src/mixins/datasource.mixin.ts +0 -111
- package/src/mixins/index.ts +0 -1
- package/src/service/define-integration.ts +0 -404
- package/src/service/define-service.ts +0 -58
- package/src/types/channels.ts +0 -60
- package/src/types/context.ts +0 -64
- package/src/types/datasource.ts +0 -23
- package/src/types/index.ts +0 -9
- package/src/types/integration.ts +0 -28
- package/src/types/message.ts +0 -128
- package/src/types/platform.ts +0 -39
- package/src/types/service.ts +0 -209
- package/src/types/tenant.ts +0 -4
- package/src/types/user.ts +0 -16
- package/src/utils/context-cache.ts +0 -70
- package/src/utils/index.ts +0 -8
- package/src/utils/permission-calculator.ts +0 -62
- package/tsconfig.json +0 -13
- package/tsup.config.ts +0 -5
package/package.json
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hiliosai/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
5
7
|
"exports": {
|
|
6
|
-
".":
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
7
12
|
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
8
16
|
"scripts": {
|
|
9
17
|
"build": "tsup",
|
|
10
18
|
"format": "bunx prettier --write ./**/*.{ts,json}",
|
package/src/configs/constants.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import env from '@ltv/env';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Base namespace for all channels
|
|
5
|
-
*/
|
|
6
|
-
export const NAMESPACE = env.string('NAMESPACE', 'hios').toLowerCase();
|
|
7
|
-
|
|
8
|
-
export const CHANNELS = {
|
|
9
|
-
// Webhook processing channels
|
|
10
|
-
WEBHOOK: {
|
|
11
|
-
// Pattern: hios.webhook.{tenantId}.{platform}
|
|
12
|
-
PATTERN: `${NAMESPACE}.webhook.*.*`,
|
|
13
|
-
PREFIX: `${NAMESPACE}.webhook`,
|
|
14
|
-
build: (tenantId: string, platform: string) =>
|
|
15
|
-
`${NAMESPACE}.webhook.${tenantId}.${platform}`,
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
// Message processing channels
|
|
19
|
-
PROCESSING: {
|
|
20
|
-
// Pattern: hios.processing.{tenantId}.{messageType}
|
|
21
|
-
PATTERN: `${NAMESPACE}.processing.*.*`,
|
|
22
|
-
PREFIX: `${NAMESPACE}.processing`,
|
|
23
|
-
build: (tenantId: string, messageType: string) =>
|
|
24
|
-
`${NAMESPACE}.processing.${tenantId}.${messageType}`,
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
// Response/outbound message channels
|
|
28
|
-
RESPONSE: {
|
|
29
|
-
// Pattern: hios.response.{tenantId}.{platform}
|
|
30
|
-
PATTERN: `${NAMESPACE}.response.*.*`,
|
|
31
|
-
PREFIX: `${NAMESPACE}.response`,
|
|
32
|
-
build: (tenantId: string, platform: string) =>
|
|
33
|
-
`${NAMESPACE}.response.${tenantId}.${platform}`,
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
// System channels
|
|
37
|
-
SYSTEM: {
|
|
38
|
-
// Error handling
|
|
39
|
-
ERRORS: `${NAMESPACE}.system.errors`,
|
|
40
|
-
|
|
41
|
-
// Metrics and monitoring
|
|
42
|
-
METRICS: `${NAMESPACE}.system.metrics`,
|
|
43
|
-
|
|
44
|
-
// Health checks
|
|
45
|
-
HEALTH: `${NAMESPACE}.system.health`,
|
|
46
|
-
|
|
47
|
-
// Integration lifecycle events
|
|
48
|
-
INTEGRATION_REGISTERED: `${NAMESPACE}.system.integration.registered`,
|
|
49
|
-
INTEGRATION_UNREGISTERED: `${NAMESPACE}.system.integration.unregistered`,
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
// Dead letter queues
|
|
53
|
-
DLQ: {
|
|
54
|
-
// Failed webhook processing
|
|
55
|
-
WEBHOOK_FAILED: `${NAMESPACE}.dlq.webhook.failed`,
|
|
56
|
-
|
|
57
|
-
// Failed message sends
|
|
58
|
-
SEND_FAILED: `${NAMESPACE}.dlq.send.failed`,
|
|
59
|
-
|
|
60
|
-
// Failed processing
|
|
61
|
-
PROCESSING_FAILED: `${NAMESPACE}.dlq.processing.failed`,
|
|
62
|
-
|
|
63
|
-
// Build DLQ name for specific integration
|
|
64
|
-
buildSendFailed: (platform: string) =>
|
|
65
|
-
`${NAMESPACE}.dlq.send.${platform}.failed`,
|
|
66
|
-
},
|
|
67
|
-
} as const;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Integration-specific channel names
|
|
71
|
-
*/
|
|
72
|
-
export const INTEGRATION_CHANNELS = {
|
|
73
|
-
// Message events
|
|
74
|
-
MESSAGE_RECEIVED: `${NAMESPACE}.processing.message.received`,
|
|
75
|
-
MESSAGE_SENT: `${NAMESPACE}.processing.message.sent`,
|
|
76
|
-
MESSAGE_FAILED: `${NAMESPACE}.processing.message.failed`,
|
|
77
|
-
} as const;
|
|
78
|
-
|
|
79
|
-
export type IntegrationChannelName =
|
|
80
|
-
(typeof INTEGRATION_CHANNELS)[keyof typeof INTEGRATION_CHANNELS];
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Channel Configuration Constants
|
|
84
|
-
*/
|
|
85
|
-
export const CHANNEL_CONFIG = {
|
|
86
|
-
// Default settings for message channels
|
|
87
|
-
DEFAULTS: {
|
|
88
|
-
maxInFlight: 10,
|
|
89
|
-
maxRetries: 3,
|
|
90
|
-
deadLettering: {
|
|
91
|
-
enabled: true,
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
// High-priority channels (webhooks)
|
|
96
|
-
HIGH_PRIORITY: {
|
|
97
|
-
maxInFlight: 50,
|
|
98
|
-
maxRetries: 5,
|
|
99
|
-
deadLettering: {
|
|
100
|
-
enabled: true,
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
// Low-priority channels (metrics, logs)
|
|
105
|
-
LOW_PRIORITY: {
|
|
106
|
-
maxInFlight: 5,
|
|
107
|
-
maxRetries: 1,
|
|
108
|
-
deadLettering: {
|
|
109
|
-
enabled: false,
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
} as const;
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Subject patterns for NATS JetStream
|
|
116
|
-
*/
|
|
117
|
-
export const SUBJECTS = {
|
|
118
|
-
// All webhook subjects
|
|
119
|
-
WEBHOOK_ALL: `${NAMESPACE}.webhook.>`,
|
|
120
|
-
|
|
121
|
-
// All processing subjects
|
|
122
|
-
PROCESSING_ALL: `${NAMESPACE}.processing.>`,
|
|
123
|
-
|
|
124
|
-
// All response subjects
|
|
125
|
-
RESPONSE_ALL: `${NAMESPACE}.response.>`,
|
|
126
|
-
|
|
127
|
-
// All system subjects
|
|
128
|
-
SYSTEM_ALL: `${NAMESPACE}.system.>`,
|
|
129
|
-
|
|
130
|
-
// All DLQ subjects
|
|
131
|
-
DLQ_ALL: `${NAMESPACE}.dlq.>`,
|
|
132
|
-
|
|
133
|
-
// Wildcard for all HIOS subjects
|
|
134
|
-
ALL: `${NAMESPACE}.>`,
|
|
135
|
-
} as const;
|
package/src/configs/index.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import env from '@ltv/env';
|
|
2
|
-
import {Middleware as createChannelsMiddleware} from '@moleculer/channels';
|
|
3
|
-
import {type Middleware} from 'moleculer';
|
|
4
|
-
|
|
5
|
-
import {SUBJECTS, NAMESPACE as cfgNamespace} from '../constants';
|
|
6
|
-
|
|
7
|
-
const NAMESPACE = cfgNamespace.toUpperCase();
|
|
8
|
-
|
|
9
|
-
const middleware = createChannelsMiddleware({
|
|
10
|
-
adapter: {
|
|
11
|
-
type: 'NATS',
|
|
12
|
-
options: {
|
|
13
|
-
nats: {
|
|
14
|
-
url: env.string('NATS_URL', 'nats://localhost:4222'),
|
|
15
|
-
|
|
16
|
-
/** Connection options for reliability */
|
|
17
|
-
connectionOptions: {
|
|
18
|
-
name: 'hios',
|
|
19
|
-
timeout: 10000,
|
|
20
|
-
reconnect: true,
|
|
21
|
-
maxReconnectAttempts: 10,
|
|
22
|
-
reconnectTimeWait: 2000,
|
|
23
|
-
maxReconnectTimeWait: 30000,
|
|
24
|
-
pingInterval: 20000,
|
|
25
|
-
maxPingOut: 2,
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Stream configuration for multi-tenant messaging
|
|
30
|
-
*
|
|
31
|
-
* Environment variables for production:
|
|
32
|
-
* - NATS_MAX_MESSAGES: Default 100K (dev) -> 10M+ (prod)
|
|
33
|
-
* - NATS_MAX_BYTES_GB: Default 1GB (dev) -> 100GB+ (prod)
|
|
34
|
-
* - NATS_MAX_AGE_DAYS: Default 7 (dev) -> 30+ (prod)
|
|
35
|
-
* - NATS_MAX_MSG_SIZE_MB: Default 1MB (dev) -> 5MB (prod)
|
|
36
|
-
* - NATS_REPLICAS: Default 1 (dev) -> 3 (prod)
|
|
37
|
-
*/
|
|
38
|
-
streamConfig: {
|
|
39
|
-
name: `${NAMESPACE}_MESSAGES`,
|
|
40
|
-
subjects: [
|
|
41
|
-
SUBJECTS.WEBHOOK_ALL,
|
|
42
|
-
SUBJECTS.PROCESSING_ALL,
|
|
43
|
-
SUBJECTS.RESPONSE_ALL,
|
|
44
|
-
SUBJECTS.SYSTEM_ALL,
|
|
45
|
-
SUBJECTS.DLQ_ALL,
|
|
46
|
-
],
|
|
47
|
-
retention: 'limits',
|
|
48
|
-
max_msgs: env.int('NATS_MAX_MESSAGES', 100_000), // 100K for dev, 10M+ for prod
|
|
49
|
-
max_bytes: env.int('NATS_MAX_BYTES_GB', 1) * 1024 * 1024 * 1024, // 1GB for dev, 100GB+ for prod
|
|
50
|
-
max_age: env.int('NATS_MAX_AGE_DAYS', 7) * 24 * 60 * 60 * 1000000000, // 7 days dev, 30+ days prod
|
|
51
|
-
max_msg_size: env.int('NATS_MAX_MSG_SIZE_MB', 1) * 1024 * 1024, // 1MB dev, 5MB prod
|
|
52
|
-
storage: 'file', // Persistent storage
|
|
53
|
-
num_replicas: env.int('NATS_REPLICAS', 1), // 1 for dev, 3 for prod
|
|
54
|
-
discard: 'old', // Remove old messages when limits hit
|
|
55
|
-
duplicate_window: 2 * 60 * 1000000000, // 2 minutes dedup window
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
/** Consumer options optimized for LLM processing */
|
|
59
|
-
consumerOptions: {
|
|
60
|
-
config: {
|
|
61
|
-
// Start with new messages (don't replay old ones on restart)
|
|
62
|
-
deliver_policy: 'new',
|
|
63
|
-
|
|
64
|
-
// Explicit acknowledgment required (critical for LLM processing)
|
|
65
|
-
ack_policy: 'explicit',
|
|
66
|
-
|
|
67
|
-
// Allow 5 unacknowledged messages per consumer (rate limiting)
|
|
68
|
-
max_ack_pending: 5,
|
|
69
|
-
|
|
70
|
-
// Acknowledgment timeout for LLM processing (2 minutes)
|
|
71
|
-
ack_wait: 120 * 1000000000, // 2 minutes in nanoseconds
|
|
72
|
-
|
|
73
|
-
// Maximum delivery attempts before dead letter
|
|
74
|
-
max_deliver: 3,
|
|
75
|
-
|
|
76
|
-
// Backoff for failed message retries
|
|
77
|
-
backoff: [
|
|
78
|
-
1000000000, // 1 second
|
|
79
|
-
5000000000, // 5 seconds
|
|
80
|
-
30000000000, // 30 seconds
|
|
81
|
-
],
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
/** Application-level flow control */
|
|
87
|
-
maxInFlight: 5, // Limit concurrent LLM requests per service
|
|
88
|
-
maxRetries: 2, // App-level retries (NATS handles delivery retries)
|
|
89
|
-
|
|
90
|
-
/** Dead letter queue for failed messages */
|
|
91
|
-
deadLettering: {
|
|
92
|
-
enabled: true,
|
|
93
|
-
queueName: 'FAILED_MESSAGES',
|
|
94
|
-
// Send to dead letter after NATS max_deliver attempts
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
}) as unknown as Middleware;
|
|
99
|
-
|
|
100
|
-
export const ChannelsMiddleware: Middleware = {
|
|
101
|
-
...middleware,
|
|
102
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type {Errors} from 'moleculer';
|
|
2
|
-
|
|
3
|
-
export const circuitBreakerConfig = {
|
|
4
|
-
// Enable feature
|
|
5
|
-
enabled: false,
|
|
6
|
-
// Threshold value. 0.5 means that 50% should be failed for tripping.
|
|
7
|
-
threshold: 0.5,
|
|
8
|
-
// Minimum request count. Below it, CB does not trip.
|
|
9
|
-
minRequestCount: 20,
|
|
10
|
-
// Number of seconds for time window.
|
|
11
|
-
windowTime: 60,
|
|
12
|
-
// Number of milliseconds to switch from open to half-open state
|
|
13
|
-
halfOpenTime: 10 * 1000,
|
|
14
|
-
// A function to check failed requests.
|
|
15
|
-
check: (err: Errors.MoleculerError | Error) =>
|
|
16
|
-
(err as Errors.MoleculerError).code >= 500,
|
|
17
|
-
};
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import env from '@ltv/env';
|
|
2
|
-
import type {BrokerOptions, Middleware} from 'moleculer';
|
|
3
|
-
import os from 'os';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
ContextHelpersMiddleware,
|
|
7
|
-
PermissionsMiddleware,
|
|
8
|
-
} from '../../middlewares';
|
|
9
|
-
import {bulkheadConfig} from './bulkhead';
|
|
10
|
-
import {ChannelsMiddleware} from './channels';
|
|
11
|
-
import {circuitBreakerConfig} from './circuit-breaker';
|
|
12
|
-
import logger from './logger';
|
|
13
|
-
import {metricsConfig} from './metrics';
|
|
14
|
-
import {registryConfig} from './registry';
|
|
15
|
-
import {retryPolicyConfig} from './retry-policy';
|
|
16
|
-
import {tracingConfig} from './tracing';
|
|
17
|
-
import {trackingConfig} from './tracking';
|
|
18
|
-
|
|
19
|
-
const pkgNm = env.string('NAMESPACE', 'hios');
|
|
20
|
-
|
|
21
|
-
const nodeID =
|
|
22
|
-
env.string('NODE_ID') ?? `${pkgNm}-${os.hostname()}-${process.pid}`;
|
|
23
|
-
|
|
24
|
-
// Export default config for backward compatibility
|
|
25
|
-
const configs: BrokerOptions = {
|
|
26
|
-
namespace: pkgNm,
|
|
27
|
-
nodeID,
|
|
28
|
-
metadata: {},
|
|
29
|
-
logger,
|
|
30
|
-
// Default log level for built-in console logger. It can be overwritten in logger options above.
|
|
31
|
-
// Available values: trace, debug, info, warn, error, fatal
|
|
32
|
-
logLevel: 'info',
|
|
33
|
-
|
|
34
|
-
cacher: env.string('REDIS_URL', 'Memory'),
|
|
35
|
-
|
|
36
|
-
// Define a serializer.
|
|
37
|
-
// Available values: "JSON", "Avro", "ProtoBuf", "MsgPack", "Notepack", "Thrift".
|
|
38
|
-
// More info: https://moleculer.services/docs/0.14/networking.html#Serialization
|
|
39
|
-
serializer: 'JSON',
|
|
40
|
-
|
|
41
|
-
// Number of milliseconds to wait before reject a request with a RequestTimeout error. Disabled: 0
|
|
42
|
-
requestTimeout: 10 * 1000,
|
|
43
|
-
|
|
44
|
-
// Retry policy settings. More info: https://moleculer.services/docs/0.14/fault-tolerance.html#Retry
|
|
45
|
-
retryPolicy: retryPolicyConfig,
|
|
46
|
-
|
|
47
|
-
// Limit of calling level. If it reaches the limit, broker will throw an MaxCallLevelError error. (Infinite loop protection)
|
|
48
|
-
maxCallLevel: 100,
|
|
49
|
-
|
|
50
|
-
// Number of seconds to send heartbeat packet to other nodes.
|
|
51
|
-
heartbeatInterval: 10,
|
|
52
|
-
// Number of seconds to wait before setting node to unavailable status.
|
|
53
|
-
heartbeatTimeout: 30,
|
|
54
|
-
|
|
55
|
-
// Cloning the params of context if enabled. High performance impact, use it with caution!
|
|
56
|
-
contextParamsCloning: false,
|
|
57
|
-
|
|
58
|
-
// Tracking requests and waiting for running requests before shuting down. More info: https://moleculer.services/docs/0.14/context.html#Context-tracking
|
|
59
|
-
tracking: trackingConfig,
|
|
60
|
-
|
|
61
|
-
// Disable built-in request & emit balancer. (Transporter must support it, as well.). More info: https://moleculer.services/docs/0.14/networking.html#Disabled-balancer
|
|
62
|
-
disableBalancer: false,
|
|
63
|
-
|
|
64
|
-
// Settings of Service Registry. More info: https://moleculer.services/docs/0.14/registry.html
|
|
65
|
-
registry: registryConfig,
|
|
66
|
-
|
|
67
|
-
// Settings of Circuit Breaker. More info: https://moleculer.services/docs/0.14/fault-tolerance.html#Circuit-Breaker
|
|
68
|
-
circuitBreaker: circuitBreakerConfig,
|
|
69
|
-
|
|
70
|
-
// Settings of bulkhead feature. More info: https://moleculer.services/docs/0.14/fault-tolerance.html#Bulkhead
|
|
71
|
-
bulkhead: bulkheadConfig,
|
|
72
|
-
|
|
73
|
-
// Enable action & event parameter validation. More info: https://moleculer.services/docs/0.14/validating.html
|
|
74
|
-
validator: 'Fastest',
|
|
75
|
-
|
|
76
|
-
// errorHandler: null,
|
|
77
|
-
|
|
78
|
-
transporter: env.string('TRANSPORTER_URL'),
|
|
79
|
-
|
|
80
|
-
// Enable/disable built-in metrics function. More info: https://moleculer.services/docs/0.14/metrics.html
|
|
81
|
-
metrics: metricsConfig,
|
|
82
|
-
|
|
83
|
-
// Enable built-in tracing function. More info: https://moleculer.services/docs/0.14/tracing.html
|
|
84
|
-
tracing: tracingConfig,
|
|
85
|
-
|
|
86
|
-
middlewares: [
|
|
87
|
-
ChannelsMiddleware,
|
|
88
|
-
PermissionsMiddleware as Middleware,
|
|
89
|
-
ContextHelpersMiddleware as Middleware,
|
|
90
|
-
],
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export const createConfig = (customConfig: BrokerOptions) => ({
|
|
94
|
-
...configs,
|
|
95
|
-
...customConfig,
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
export default configs;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const loggerConfig = {
|
|
2
|
-
type: 'Console',
|
|
3
|
-
options: {
|
|
4
|
-
// Using colors on the output
|
|
5
|
-
colors: true,
|
|
6
|
-
// Print module names with different colors (like docker-compose for containers)
|
|
7
|
-
moduleColors: false,
|
|
8
|
-
// Line formatter. It can be "json", "short", "simple", "full", a `Function` or a template string like "{timestamp} {level} {nodeID}/{mod}: {msg}"
|
|
9
|
-
formatter: 'full',
|
|
10
|
-
// Custom object printer. If not defined, it uses the `util.inspect` method.
|
|
11
|
-
objectPrinter: null,
|
|
12
|
-
// Auto-padding the module name in order to messages begin at the same column.
|
|
13
|
-
autoPadding: false,
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export default loggerConfig;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type {MetricRegistry} from 'moleculer';
|
|
2
|
-
|
|
3
|
-
export const metricsConfig = {
|
|
4
|
-
enabled: false,
|
|
5
|
-
// Available built-in reporters: "Console", "CSV", "Event", "Prometheus", "Datadog", "StatsD"
|
|
6
|
-
reporter: {
|
|
7
|
-
type: 'Prometheus',
|
|
8
|
-
options: {
|
|
9
|
-
// HTTP port
|
|
10
|
-
port: 3030,
|
|
11
|
-
// HTTP URL path
|
|
12
|
-
path: '/metrics',
|
|
13
|
-
// Default labels which are appended to all metrics labels
|
|
14
|
-
defaultLabels: (registry: MetricRegistry) => ({
|
|
15
|
-
namespace: registry.broker.namespace,
|
|
16
|
-
nodeID: registry.broker.nodeID,
|
|
17
|
-
}),
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export const registryConfig = {
|
|
2
|
-
// Define balancing strategy. More info: https://moleculer.services/docs/0.14/balancing.html
|
|
3
|
-
// Available values: "RoundRobin", "Random", "CpuUsage", "Latency", "Shard"
|
|
4
|
-
strategy: 'RoundRobin',
|
|
5
|
-
// Enable local action call preferring. Always call the local action instance if available.
|
|
6
|
-
preferLocal: true,
|
|
7
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type {Errors} from 'moleculer';
|
|
2
|
-
|
|
3
|
-
export const retryPolicyConfig = {
|
|
4
|
-
// Enable feature
|
|
5
|
-
enabled: false,
|
|
6
|
-
// Count of retries
|
|
7
|
-
retries: 5,
|
|
8
|
-
// First delay in milliseconds.
|
|
9
|
-
delay: 100,
|
|
10
|
-
// Maximum delay in milliseconds.
|
|
11
|
-
maxDelay: 1000,
|
|
12
|
-
// Backoff factor for delay. 2 means exponential backoff.
|
|
13
|
-
factor: 2,
|
|
14
|
-
// A function to check failed requests.
|
|
15
|
-
check: (err: Errors.MoleculerError | Error) =>
|
|
16
|
-
!!(err as Errors.MoleculerError).retryable,
|
|
17
|
-
};
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
// Permission constants
|
|
2
|
-
export const PERMISSIONS = {
|
|
3
|
-
// Authentication required
|
|
4
|
-
AUTHENTICATED: 'authenticated',
|
|
5
|
-
|
|
6
|
-
// Role-based permissions
|
|
7
|
-
OWNER: 'OWNER',
|
|
8
|
-
ADMIN: 'ADMIN',
|
|
9
|
-
MANAGER: 'MANAGER',
|
|
10
|
-
AGENT: 'AGENT',
|
|
11
|
-
VIEWER: 'VIEWER',
|
|
12
|
-
DEVELOPER: 'DEVELOPER',
|
|
13
|
-
|
|
14
|
-
// Entity-specific permissions
|
|
15
|
-
TENANT_OWNER: 'tenant.owner',
|
|
16
|
-
TENANT_MEMBER: 'tenant.member',
|
|
17
|
-
|
|
18
|
-
// Resource permissions
|
|
19
|
-
'users.read': 'users.read',
|
|
20
|
-
'users.write': 'users.write',
|
|
21
|
-
'users.delete': 'users.delete',
|
|
22
|
-
'tenants.read': 'tenants.read',
|
|
23
|
-
'tenants.write': 'tenants.write',
|
|
24
|
-
'tenants.delete': 'tenants.delete',
|
|
25
|
-
'conversations.read': 'conversations.read',
|
|
26
|
-
'conversations.write': 'conversations.write',
|
|
27
|
-
'conversations.delete': 'conversations.delete',
|
|
28
|
-
'messages.read': 'messages.read',
|
|
29
|
-
'messages.write': 'messages.write',
|
|
30
|
-
'settings.read': 'settings.read',
|
|
31
|
-
'settings.write': 'settings.write',
|
|
32
|
-
'config.read': 'config.read',
|
|
33
|
-
'config.write': 'config.write',
|
|
34
|
-
'billing.read': 'billing.read',
|
|
35
|
-
'billing.write': 'billing.write',
|
|
36
|
-
} as const;
|
|
37
|
-
|
|
38
|
-
// Role hierarchy and permissions mapping
|
|
39
|
-
export const ROLE_PERMISSIONS: Record<string, string[]> = {
|
|
40
|
-
[PERMISSIONS.OWNER]: [
|
|
41
|
-
PERMISSIONS.AUTHENTICATED,
|
|
42
|
-
PERMISSIONS['users.read'],
|
|
43
|
-
PERMISSIONS['users.write'],
|
|
44
|
-
PERMISSIONS['users.delete'],
|
|
45
|
-
PERMISSIONS['tenants.read'],
|
|
46
|
-
PERMISSIONS['tenants.write'],
|
|
47
|
-
PERMISSIONS['tenants.delete'],
|
|
48
|
-
PERMISSIONS['conversations.read'],
|
|
49
|
-
PERMISSIONS['conversations.write'],
|
|
50
|
-
PERMISSIONS['conversations.delete'],
|
|
51
|
-
PERMISSIONS['messages.read'],
|
|
52
|
-
PERMISSIONS['messages.write'],
|
|
53
|
-
PERMISSIONS['settings.read'],
|
|
54
|
-
PERMISSIONS['settings.write'],
|
|
55
|
-
PERMISSIONS['config.read'],
|
|
56
|
-
PERMISSIONS['config.write'],
|
|
57
|
-
PERMISSIONS['billing.read'],
|
|
58
|
-
PERMISSIONS['billing.write'],
|
|
59
|
-
],
|
|
60
|
-
[PERMISSIONS.ADMIN]: [
|
|
61
|
-
PERMISSIONS.AUTHENTICATED,
|
|
62
|
-
PERMISSIONS['users.read'],
|
|
63
|
-
PERMISSIONS['users.write'],
|
|
64
|
-
PERMISSIONS['users.delete'],
|
|
65
|
-
PERMISSIONS['tenants.read'],
|
|
66
|
-
PERMISSIONS['tenants.write'],
|
|
67
|
-
PERMISSIONS['tenants.delete'],
|
|
68
|
-
PERMISSIONS['conversations.read'],
|
|
69
|
-
PERMISSIONS['conversations.write'],
|
|
70
|
-
PERMISSIONS['conversations.delete'],
|
|
71
|
-
PERMISSIONS['messages.read'],
|
|
72
|
-
PERMISSIONS['messages.write'],
|
|
73
|
-
PERMISSIONS['settings.read'],
|
|
74
|
-
PERMISSIONS['settings.write'],
|
|
75
|
-
PERMISSIONS['config.read'],
|
|
76
|
-
PERMISSIONS['config.write'],
|
|
77
|
-
PERMISSIONS['billing.read'],
|
|
78
|
-
],
|
|
79
|
-
[PERMISSIONS.MANAGER]: [
|
|
80
|
-
PERMISSIONS.AUTHENTICATED,
|
|
81
|
-
PERMISSIONS['users.read'],
|
|
82
|
-
PERMISSIONS['users.write'],
|
|
83
|
-
PERMISSIONS['conversations.read'],
|
|
84
|
-
PERMISSIONS['conversations.write'],
|
|
85
|
-
PERMISSIONS['messages.read'],
|
|
86
|
-
PERMISSIONS['messages.write'],
|
|
87
|
-
PERMISSIONS['settings.read'],
|
|
88
|
-
PERMISSIONS['settings.write'],
|
|
89
|
-
],
|
|
90
|
-
[PERMISSIONS.AGENT]: [
|
|
91
|
-
PERMISSIONS.AUTHENTICATED,
|
|
92
|
-
PERMISSIONS['conversations.read'],
|
|
93
|
-
PERMISSIONS['conversations.write'],
|
|
94
|
-
PERMISSIONS['messages.read'],
|
|
95
|
-
PERMISSIONS['messages.write'],
|
|
96
|
-
],
|
|
97
|
-
[PERMISSIONS.VIEWER]: [
|
|
98
|
-
PERMISSIONS.AUTHENTICATED,
|
|
99
|
-
PERMISSIONS['conversations.read'],
|
|
100
|
-
PERMISSIONS['messages.read'],
|
|
101
|
-
],
|
|
102
|
-
[PERMISSIONS.DEVELOPER]: [
|
|
103
|
-
PERMISSIONS.AUTHENTICATED,
|
|
104
|
-
// Only specific debug/development permissions, not full access
|
|
105
|
-
'system.debug',
|
|
106
|
-
'health.check',
|
|
107
|
-
PERMISSIONS['config.read'],
|
|
108
|
-
],
|
|
109
|
-
};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import type {ServiceBroker} from 'moleculer';
|
|
2
|
-
|
|
3
|
-
import type {AppContext} from '../types/context';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Base datasource interface that all datasources should implement
|
|
7
|
-
* Provides common structure and optional lifecycle methods
|
|
8
|
-
*/
|
|
9
|
-
export interface BaseDatasource<TContext = AppContext> {
|
|
10
|
-
/**
|
|
11
|
-
* Datasource name for identification and logging
|
|
12
|
-
*/
|
|
13
|
-
readonly name: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Service broker instance for logging, events, and service calls
|
|
17
|
-
* Always available after datasource initialization
|
|
18
|
-
*/
|
|
19
|
-
broker: ServiceBroker;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Current service context (only available during action execution)
|
|
23
|
-
* Will be undefined in lifecycle hooks or background tasks
|
|
24
|
-
*/
|
|
25
|
-
context?: TContext;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Optional initialization method
|
|
29
|
-
* Called when datasource is instantiated
|
|
30
|
-
*/
|
|
31
|
-
init?(): Promise<void> | void;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Optional connection method
|
|
35
|
-
* Called when service starts if implemented
|
|
36
|
-
*/
|
|
37
|
-
connect?(): Promise<void> | void;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Optional disconnection method
|
|
41
|
-
* Called when service stops if implemented
|
|
42
|
-
*/
|
|
43
|
-
disconnect?(): Promise<void> | void;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Optional health check method
|
|
47
|
-
* Can be used to verify datasource is working correctly
|
|
48
|
-
*/
|
|
49
|
-
healthCheck?(): Promise<boolean> | boolean;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Optional method to clear/reset the datasource
|
|
53
|
-
*/
|
|
54
|
-
clear?(): Promise<void> | void;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Abstract base class for datasources that provides default implementations
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* export class UserDatasource extends AbstractDatasource {
|
|
62
|
-
* readonly name = 'users';
|
|
63
|
-
*
|
|
64
|
-
* private users: User[] = [];
|
|
65
|
-
*
|
|
66
|
-
* async findById(id: string): Promise<User | undefined> {
|
|
67
|
-
* this.broker?.logger.info('Finding user by ID:', id);
|
|
68
|
-
* return this.users.find(u => u.id === id);
|
|
69
|
-
* }
|
|
70
|
-
*
|
|
71
|
-
* async healthCheck(): Promise<boolean> {
|
|
72
|
-
* this.broker?.logger.info('Health check for datasource', this.name);
|
|
73
|
-
* return true;
|
|
74
|
-
* }
|
|
75
|
-
* }
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
export abstract class AbstractDatasource<TContext = AppContext>
|
|
79
|
-
implements BaseDatasource<TContext>
|
|
80
|
-
{
|
|
81
|
-
abstract readonly name: string;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Service broker instance - injected by mixin
|
|
85
|
-
* Always available after initialization
|
|
86
|
-
*/
|
|
87
|
-
broker!: ServiceBroker; // Using definite assignment assertion since it's injected
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Current service context - injected per action
|
|
91
|
-
* Only available during action execution
|
|
92
|
-
*/
|
|
93
|
-
context?: TContext;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Default health check - always returns true
|
|
97
|
-
* Override for custom health check logic
|
|
98
|
-
*/
|
|
99
|
-
async healthCheck(): Promise<boolean> {
|
|
100
|
-
this.broker.logger.info(`Health check for datasource - ${this.name}`);
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Default clear method - does nothing
|
|
106
|
-
* Override to implement clearing logic
|
|
107
|
-
*/
|
|
108
|
-
async clear(): Promise<void> {
|
|
109
|
-
// Default implementation - does nothing
|
|
110
|
-
}
|
|
111
|
-
}
|