@softtynet/zplus-worker 1.0.0 → 1.0.4

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.
Files changed (35) hide show
  1. package/README.md +27 -55
  2. package/dist/cli.js +1 -1408
  3. package/package.json +3 -3
  4. package/dist/automation/HeadlessAutomationEngine.d.ts +0 -12
  5. package/dist/automation/HeadlessAutomationEngine.js +0 -34
  6. package/dist/channels/ChannelRunnerRegistry.d.ts +0 -14
  7. package/dist/channels/ChannelRunnerRegistry.js +0 -65
  8. package/dist/channels/IChannelRunner.d.ts +0 -10
  9. package/dist/channels/IChannelRunner.js +0 -2
  10. package/dist/channels/index.d.ts +0 -6
  11. package/dist/channels/index.js +0 -22
  12. package/dist/channels/runners/FacebookChannelRunner.d.ts +0 -19
  13. package/dist/channels/runners/FacebookChannelRunner.js +0 -47
  14. package/dist/channels/runners/TelegramChannelRunner.d.ts +0 -19
  15. package/dist/channels/runners/TelegramChannelRunner.js +0 -47
  16. package/dist/channels/runners/WhatsAppChannelRunner.d.ts +0 -19
  17. package/dist/channels/runners/WhatsAppChannelRunner.js +0 -47
  18. package/dist/channels/runners/ZaloChannelRunner.d.ts +0 -22
  19. package/dist/channels/runners/ZaloChannelRunner.js +0 -50
  20. package/dist/cli.d.ts +0 -6
  21. package/dist/config/WorkerConfig.d.ts +0 -16
  22. package/dist/config/WorkerConfig.js +0 -21
  23. package/dist/engine/WorkerEngine.d.ts +0 -38
  24. package/dist/engine/WorkerEngine.js +0 -157
  25. package/dist/index.d.ts +0 -9
  26. package/dist/lock/DistributedLockManager.d.ts +0 -40
  27. package/dist/lock/DistributedLockManager.js +0 -113
  28. package/dist/notifications/PushNotificationDispatcher.d.ts +0 -14
  29. package/dist/notifications/PushNotificationDispatcher.js +0 -31
  30. package/dist/server/WorkerHttpServer.d.ts +0 -25
  31. package/dist/server/WorkerHttpServer.js +0 -205
  32. package/dist/sync/CloudPendingMessageQueue.d.ts +0 -27
  33. package/dist/sync/CloudPendingMessageQueue.js +0 -69
  34. package/dist/sync/CloudSyncWorker.d.ts +0 -19
  35. package/dist/sync/CloudSyncWorker.js +0 -53
@@ -1,69 +0,0 @@
1
- "use strict";
2
- /**
3
- * 📥 Cloud Pending Message Queue
4
- * Hàng đợi lưu tạm thời các tin nhắn khách hàng gửi đến trong lúc tắt máy tính (ca đêm)
5
- * để cung cấp cho API GET /api/v1/sync/delta khi Desktop khởi động lại.
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.CloudPendingMessageQueue = void 0;
9
- const core_1 = require("@zplus/core");
10
- class CloudPendingMessageQueue {
11
- logger;
12
- queue = [];
13
- maxCapacity;
14
- constructor(maxCapacity = 10000, logger) {
15
- this.maxCapacity = maxCapacity;
16
- this.logger = logger || (0, core_1.createLogger)("CloudPendingMessageQueue");
17
- }
18
- /**
19
- * Đưa tin nhắn mới nhận được trong lúc gác đền vào hàng đợi
20
- */
21
- enqueue(message) {
22
- if (this.queue.length >= this.maxCapacity) {
23
- const removed = this.queue.shift();
24
- this.logger.warn(`Queue capacity reached (${this.maxCapacity}). Dropped oldest message: ${removed?.id}`);
25
- }
26
- this.queue.push(message);
27
- this.logger.debug(`Enqueued pending message ${message.id} for account ${message.accountId} (Total pending: ${this.queue.length})`);
28
- }
29
- /**
30
- * Lấy danh sách tin nhắn phát sinh kể từ mốc thời gian sinceTimestamp
31
- */
32
- getDeltas(accountId, sinceTimestamp = 0) {
33
- return this.queue.filter((msg) => {
34
- const matchAccount = !accountId || msg.accountId === accountId;
35
- const matchTime = msg.timestamp >= sinceTimestamp;
36
- return matchAccount && matchTime;
37
- });
38
- }
39
- /**
40
- * Đánh dấu đã đồng bộ và dọn dẹp các tin nhắn cũ hơn upToTimestamp
41
- */
42
- purgeSynced(upToTimestamp, accountId) {
43
- const initialLen = this.queue.length;
44
- const removeIndices = [];
45
- for (let i = 0; i < this.queue.length; i++) {
46
- const msg = this.queue[i];
47
- if (msg.timestamp <= upToTimestamp &&
48
- (!accountId || msg.accountId === accountId)) {
49
- removeIndices.push(i);
50
- }
51
- }
52
- // Xóa từ cuối về đầu
53
- for (let i = removeIndices.length - 1; i >= 0; i--) {
54
- this.queue.splice(removeIndices[i], 1);
55
- }
56
- const removedCount = initialLen - this.queue.length;
57
- if (removedCount > 0) {
58
- this.logger.info(`Purged ${removedCount} synced delta messages from queue.`);
59
- }
60
- return removedCount;
61
- }
62
- getCount() {
63
- return this.queue.length;
64
- }
65
- clear() {
66
- this.queue.length = 0;
67
- }
68
- }
69
- exports.CloudPendingMessageQueue = CloudPendingMessageQueue;
@@ -1,19 +0,0 @@
1
- import { ILogger } from "@zplus/core";
2
- import { SyncOutboxRecord } from "@zplus/contracts";
3
- export interface CloudSyncWorkerConfig {
4
- endpoint: string;
5
- projectId: string;
6
- pollIntervalMs?: number;
7
- }
8
- export declare class CloudSyncWorker {
9
- private readonly config;
10
- private readonly logger;
11
- private isRunning;
12
- private timer;
13
- constructor(config: CloudSyncWorkerConfig, logger?: ILogger);
14
- start(): Promise<void>;
15
- stop(): Promise<void>;
16
- pushOutboxRecord(record: SyncOutboxRecord): Promise<boolean>;
17
- private scheduleNextPoll;
18
- private syncPendingDeltas;
19
- }
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CloudSyncWorker = void 0;
4
- const core_1 = require("@zplus/core");
5
- class CloudSyncWorker {
6
- config;
7
- logger;
8
- isRunning = false;
9
- timer = null;
10
- constructor(config, logger) {
11
- this.config = config;
12
- this.logger = logger || (0, core_1.createLogger)("CloudSyncWorker");
13
- }
14
- async start() {
15
- if (this.isRunning)
16
- return;
17
- this.isRunning = true;
18
- this.logger.info(`Starting 24/7 Cloud Sync Worker (Endpoint: ${this.config.endpoint})...`);
19
- this.scheduleNextPoll();
20
- }
21
- async stop() {
22
- this.isRunning = false;
23
- if (this.timer) {
24
- clearTimeout(this.timer);
25
- this.timer = null;
26
- }
27
- this.logger.info("Cloud Sync Worker stopped.");
28
- }
29
- async pushOutboxRecord(record) {
30
- this.logger.debug(`Queued outbox record for sync: ${record.id} (${record.tableName})`);
31
- return true;
32
- }
33
- scheduleNextPoll() {
34
- if (!this.isRunning)
35
- return;
36
- const interval = this.config.pollIntervalMs || 10000;
37
- this.timer = setTimeout(async () => {
38
- try {
39
- await this.syncPendingDeltas();
40
- }
41
- catch (err) {
42
- this.logger.error("Error during delta sync poll:", err);
43
- }
44
- finally {
45
- this.scheduleNextPoll();
46
- }
47
- }, interval);
48
- }
49
- async syncPendingDeltas() {
50
- // Polls or checks incoming cloud delta changes
51
- }
52
- }
53
- exports.CloudSyncWorker = CloudSyncWorker;