@lyxa.ai/core 1.0.371 → 1.0.372
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/libraries/bullmq/bull-mq-service.d.ts +1 -1
- package/dist/libraries/bullmq/bull-mq-service.js.map +1 -1
- package/dist/libraries/event/decorators/subscribe.js.map +1 -1
- package/dist/libraries/event/index.d.ts +4 -0
- package/dist/libraries/event/index.js +51 -0
- package/dist/libraries/event/index.js.map +1 -1
- package/dist/libraries/mongo/models/ticket.model.d.ts +2 -0
- package/dist/libraries/mongo/models/ticket.model.js +10 -0
- package/dist/libraries/mongo/models/ticket.model.js.map +1 -1
- package/dist/libraries/mongo/models/user.model.d.ts +1 -1
- package/dist/libraries/redis/index.d.ts +4 -0
- package/dist/libraries/redis/index.js +14 -0
- package/dist/libraries/redis/index.js.map +1 -1
- package/dist/libraries/socket/BaseSocketEvent.d.ts +15 -0
- package/dist/libraries/socket/BaseSocketEvent.js +23 -0
- package/dist/libraries/socket/BaseSocketEvent.js.map +1 -0
- package/dist/libraries/socket/LocalSubscriptionRegistry.d.ts +11 -0
- package/dist/libraries/socket/LocalSubscriptionRegistry.js +30 -0
- package/dist/libraries/socket/LocalSubscriptionRegistry.js.map +1 -0
- package/dist/libraries/socket/events/chatroom-message-send-socket.event.d.ts +56 -0
- package/dist/libraries/socket/events/chatroom-message-send-socket.event.js +32 -0
- package/dist/libraries/socket/events/chatroom-message-send-socket.event.js.map +1 -0
- package/dist/libraries/socket/socket-event-registery.d.ts +42 -0
- package/dist/libraries/socket/socket-event-registery.js +25 -0
- package/dist/libraries/socket/socket-event-registery.js.map +1 -0
- package/dist/types/README.md +1 -1
- package/dist/types/package.json +1 -1
- package/dist/types/utilities/enum.d.ts +3 -4
- package/dist/types/utilities/enum.js +6 -7
- package/dist/types/utilities/enum.js.map +1 -1
- package/dist/types/utilities/validation/common-validation.d.ts +78 -2
- package/dist/types/utilities/validation/global-validation.d.ts +38 -14
- package/dist/utilities/enum.d.ts +3 -4
- package/dist/utilities/enum.js +6 -7
- package/dist/utilities/enum.js.map +1 -1
- package/dist/utilities/validation/common-validation.d.ts +78 -2
- package/dist/utilities/validation/global-validation.d.ts +38 -14
- package/package.json +1 -1
- package/dist/libraries/socket/SocketEmitEvent.d.ts +0 -9
- package/dist/libraries/socket/SocketEmitEvent.js +0 -29
- package/dist/libraries/socket/SocketEmitEvent.js.map +0 -1
- package/dist/libraries/socket/index.d.ts +0 -3
- package/dist/libraries/socket/index.js +0 -20
- package/dist/libraries/socket/index.js.map +0 -1
- package/dist/libraries/socket/socket.types.d.ts +0 -31
- package/dist/libraries/socket/socket.types.js +0 -28
- package/dist/libraries/socket/socket.types.js.map +0 -1
- package/dist/libraries/socket/socket.utils.d.ts +0 -19
- package/dist/libraries/socket/socket.utils.js +0 -59
- package/dist/libraries/socket/socket.utils.js.map +0 -1
|
@@ -5,5 +5,5 @@ export declare class BullMQService {
|
|
|
5
5
|
private connection;
|
|
6
6
|
constructor(redisService: RedisService);
|
|
7
7
|
createQueue(queueName: string): Queue;
|
|
8
|
-
createWorker<T
|
|
8
|
+
createWorker<T>(queueName: string, processor: (job: Job<T>) => Promise<void>, options?: WorkerOptions): Worker;
|
|
9
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bull-mq-service.js","sourceRoot":"/","sources":["libraries/bullmq/bull-mq-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,mCAAyC;AACzC,mCAAyE;AACzE,0CAA8C;AAGvC,IAAM,aAAa,GAAnB,MAAM,aAAa;IAGuB;IAFxC,UAAU,CAAe;IAEjC,YAAgD,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;QACzE,IAAI,CAAC,UAAU,GAAG,EAAE,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;IACjE,CAAC;IAKM,WAAW,CAAC,SAAiB;QACnC,OAAO,IAAI,cAAK,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC9C,CAAC;IAKM,YAAY,CAClB,SAAiB,EACjB,
|
|
1
|
+
{"version":3,"file":"bull-mq-service.js","sourceRoot":"/","sources":["libraries/bullmq/bull-mq-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,mCAAyC;AACzC,mCAAyE;AACzE,0CAA8C;AAGvC,IAAM,aAAa,GAAnB,MAAM,aAAa;IAGuB;IAFxC,UAAU,CAAe;IAEjC,YAAgD,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;QACzE,IAAI,CAAC,UAAU,GAAG,EAAE,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;IACjE,CAAC;IAKM,WAAW,CAAC,SAAiB;QACnC,OAAO,IAAI,cAAK,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC9C,CAAC;IAKM,YAAY,CAClB,SAAiB,EACjB,SAAyC,EACzC,OAAuB;QAEvB,OAAO,IAAI,eAAM,CAAC,SAAS,EAAE,SAAS,EAAE;YACvC,GAAG,IAAI,CAAC,UAAU;YAClB,GAAG,OAAO;SACV,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AA3BY,sCAAa;wBAAb,aAAa;IADzB,IAAA,gBAAO,GAAE;IAII,WAAA,IAAA,eAAM,EAAC,GAAG,EAAE,CAAC,oBAAY,CAAC,CAAA;qCAAuB,oBAAY;GAH9D,aAAa,CA2BzB","sourcesContent":["// lyxa-core/libraries/bullmq/BullMQService.ts\n\nimport { Service, Inject } from 'typedi';\nimport { Queue, Worker, Job, QueueOptions, WorkerOptions } from 'bullmq';\nimport { RedisService } from '../redis/index';\n\n@Service()\nexport class BullMQService {\n\tprivate connection: QueueOptions;\n\n\tconstructor(@Inject(() => RedisService) private redisService: RedisService) {\n\t\tthis.connection = { connection: this.redisService.redisClient };\n\t}\n\n\t/**\n\t * Creates a new queue.\n\t */\n\tpublic createQueue(queueName: string): Queue {\n\t\treturn new Queue(queueName, this.connection);\n\t}\n\n\t/**\n\t * Creates a worker to process jobs from a given queue.\n\t */\n\tpublic createWorker<T>(\n\t\tqueueName: string,\n\t\tprocessor: (job: Job<T>) => Promise<void>,\n\t\toptions?: WorkerOptions\n\t): Worker {\n\t\treturn new Worker(queueName, processor, {\n\t\t\t...this.connection,\n\t\t\t...options,\n\t\t});\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribe.js","sourceRoot":"/","sources":["libraries/event/decorators/subscribe.ts"],"names":[],"mappings":";;AAEA,8BAIC;AAND,2EAAwE;AAExE,SAAgB,SAAS,CAAC,OAAe;IACxC,OAAO,UAAU,MAAW,EAAE,WAAmB,EAAE,UAA8B;QAChF,2CAAoB,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IACzE,CAAC,CAAC;AACH,CAAC","sourcesContent":["import { SubscriptionRegistry } from '../registry/SubscriptionRegistry';\n\nexport function Subscribe(eventId: string) {\n\treturn function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {\n\t\tSubscriptionRegistry.register(eventId, target.constructor, propertyKey);\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"subscribe.js","sourceRoot":"/","sources":["libraries/event/decorators/subscribe.ts"],"names":[],"mappings":";;AAEA,8BAIC;AAND,2EAAwE;AAExE,SAAgB,SAAS,CAAC,OAAe;IACxC,OAAO,UAAU,MAAW,EAAE,WAAmB,EAAE,UAA8B;QAChF,2CAAoB,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IACzE,CAAC,CAAC;AACH,CAAC","sourcesContent":["import { SubscriptionRegistry } from '../registry/SubscriptionRegistry';\n\nexport function Subscribe(eventId: string) {\n\treturn function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {\n\t\tSubscriptionRegistry.register(eventId, target.constructor, propertyKey);\n\t};\n}\n\n"]}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import amqp from 'amqplib';
|
|
1
2
|
import { BaseEvent } from './BaseEvent';
|
|
3
|
+
import { BaseSocketEvent } from '../socket/BaseSocketEvent';
|
|
2
4
|
export declare function initEventBus(rabbitUrl: string): Promise<void>;
|
|
3
5
|
export declare function publishEvent<TPayload extends Record<string, unknown>>(event: BaseEvent<TPayload>): Promise<void>;
|
|
4
6
|
export declare function subscribeToEvent(eventId: string, onMessage: (payload: any) => Promise<void>): Promise<void>;
|
|
7
|
+
export declare function subscribeToSocketEvent(eventId: string): Promise<amqp.Channel>;
|
|
5
8
|
export declare function closeEventBus(): Promise<void>;
|
|
9
|
+
export declare function publishSocketEvent(event: BaseSocketEvent<any, any>, recipients: string[]): Promise<void>;
|
|
@@ -6,12 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.initEventBus = initEventBus;
|
|
7
7
|
exports.publishEvent = publishEvent;
|
|
8
8
|
exports.subscribeToEvent = subscribeToEvent;
|
|
9
|
+
exports.subscribeToSocketEvent = subscribeToSocketEvent;
|
|
9
10
|
exports.closeEventBus = closeEventBus;
|
|
11
|
+
exports.publishSocketEvent = publishSocketEvent;
|
|
10
12
|
const amqplib_1 = __importDefault(require("amqplib"));
|
|
11
13
|
const instance_utils_1 = require("../../utilities/instance.utils");
|
|
14
|
+
const index_1 = require("../../index");
|
|
15
|
+
const LocalSubscriptionRegistry_1 = require("../socket/LocalSubscriptionRegistry");
|
|
12
16
|
let connection;
|
|
13
17
|
let channel;
|
|
14
18
|
const EXCHANGE_NAME = 'lyxa.events';
|
|
19
|
+
const INSTANCE_ROUTE_PREFIX = 'instance';
|
|
15
20
|
async function initEventBus(rabbitUrl) {
|
|
16
21
|
connection = await amqplib_1.default.connect(rabbitUrl);
|
|
17
22
|
channel = await connection.createChannel();
|
|
@@ -52,6 +57,25 @@ async function subscribeToEvent(eventId, onMessage) {
|
|
|
52
57
|
}, { noAck: false });
|
|
53
58
|
console.log(`Subscribed to event [${eventId}] on queue [${queueName}] for instance [${(0, instance_utils_1.getInstanceId)()}]`);
|
|
54
59
|
}
|
|
60
|
+
async function subscribeToSocketEvent(eventId) {
|
|
61
|
+
const queueName = `${eventId}-${(0, instance_utils_1.getInstanceId)()}`;
|
|
62
|
+
await channel.assertQueue(queueName, { durable: true });
|
|
63
|
+
await channel.bindQueue(queueName, EXCHANGE_NAME, eventId);
|
|
64
|
+
await channel.consume(queueName, msg => {
|
|
65
|
+
if (!msg)
|
|
66
|
+
return;
|
|
67
|
+
try {
|
|
68
|
+
const { localKey, payload, recipient } = JSON.parse(msg.content.toString('utf8'));
|
|
69
|
+
LocalSubscriptionRegistry_1.LocalSubs.emit(recipient, localKey, payload);
|
|
70
|
+
channel.ack(msg);
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
console.error('Failed to handle instance event', e);
|
|
74
|
+
channel.nack(msg, false, false);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return channel;
|
|
78
|
+
}
|
|
55
79
|
async function closeEventBus() {
|
|
56
80
|
if (channel)
|
|
57
81
|
await channel.close();
|
|
@@ -59,4 +83,31 @@ async function closeEventBus() {
|
|
|
59
83
|
await connection.close();
|
|
60
84
|
console.log(`EventBus closed for instance [${(0, instance_utils_1.getInstanceId)()}]`);
|
|
61
85
|
}
|
|
86
|
+
async function publishSocketEvent(event, recipients) {
|
|
87
|
+
const redisService = (0, index_1.getLibraries)().getRedisService();
|
|
88
|
+
const localKey = event.getIdentifier();
|
|
89
|
+
const payload = event.payload();
|
|
90
|
+
const eventType = event.eventType();
|
|
91
|
+
for (const recipient of recipients) {
|
|
92
|
+
const isSub = await redisService.isMemberOfSet(kEntityEvents(recipient), localKey);
|
|
93
|
+
if (isSub) {
|
|
94
|
+
const instanceNames = await redisService.getSetMembers(kEntityInstances(recipient));
|
|
95
|
+
if (!instanceNames.length) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
for (const instanceName of instanceNames) {
|
|
99
|
+
const routingKey = `${INSTANCE_ROUTE_PREFIX}.${instanceName}.${eventType}`;
|
|
100
|
+
const messageBuffer = Buffer.from(JSON.stringify({ localKey, payload, recipient }), 'utf8');
|
|
101
|
+
channel.publish(EXCHANGE_NAME, routingKey, messageBuffer, {
|
|
102
|
+
contentType: 'application/json',
|
|
103
|
+
persistent: true,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const kEntityEvents = (entityId) => `socket:events:entity:${entityId}`;
|
|
112
|
+
const kEntityInstances = (entityId) => `socket:instances:entity:${entityId}`;
|
|
62
113
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/event/index.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/event/index.ts"],"names":[],"mappings":";;;;;AAYA,oCAKC;AAED,oCASC;AAED,4CA6BC;AAED,wDAqBC;AAED,sCAIC;AAED,gDAuCC;AAjID,sDAA2B;AAE3B,mEAA+D;AAE/D,uCAA2C;AAC3C,mFAAgE;AAEhE,IAAI,UAA6B,CAAC;AAClC,IAAI,OAAqB,CAAC;AAC1B,MAAM,aAAa,GAAG,aAAa,CAAC;AACpC,MAAM,qBAAqB,GAAG,UAAU,CAAC;AAElC,KAAK,UAAU,YAAY,CAAC,SAAiB;IACnD,UAAU,GAAG,MAAM,iBAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC3C,OAAO,GAAG,MAAM,UAAU,CAAC,aAAa,EAAE,CAAC;IAC3C,MAAM,OAAO,CAAC,cAAc,CAAC,aAAa,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACxE,OAAO,CAAC,GAAG,CAAC,0CAA0C,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BAE5F,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE,UAAU,EAAE,aAAa,EAAE;oBACzD,WAAW,EAAE,kBAAkB;oBAC/B,UAAU,EAAE,IAAI;iBAChB,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;aAAM,CAAC;QAGR,CAAC;IACF,CAAC;AACF,CAAC;AAED,MAAM,aAAa,GAAG,CAAC,QAAgB,EAAE,EAAE,CAAC,wBAAwB,QAAQ,EAAE,CAAC;AAC/E,MAAM,gBAAgB,GAAG,CAAC,QAAgB,EAAE,EAAE,CAAC,2BAA2B,QAAQ,EAAE,CAAC","sourcesContent":["import amqp from 'amqplib';\nimport { BaseEvent } from './BaseEvent';\nimport { getInstanceId } from '../../utilities/instance.utils';\nimport { BaseSocketEvent } from '../socket/BaseSocketEvent';\nimport { getLibraries } from '../../index';\nimport { LocalSubs } from '../socket/LocalSubscriptionRegistry';\n\nlet connection: amqp.ChannelModel;\nlet channel: amqp.Channel;\nconst EXCHANGE_NAME = 'lyxa.events';\nconst INSTANCE_ROUTE_PREFIX = 'instance'; // routing key: instance.{instanceName}.{eventType}\n\nexport async function initEventBus(rabbitUrl: string) {\n\tconnection = await amqp.connect(rabbitUrl);\n\tchannel = await connection.createChannel();\n\tawait channel.assertExchange(EXCHANGE_NAME, 'topic', { durable: true });\n\tconsole.log(`EventBus initialized with instance ID: ${getInstanceId()}`);\n}\n\nexport async function publishEvent<TPayload extends Record<string, unknown>>(\n\tevent: BaseEvent<TPayload>\n): Promise<void> {\n\tif (!channel) throw new Error('Channel not initialized. Call initEventBus first.');\n\tconst messageBuffer = Buffer.from(JSON.stringify(event.payload));\n\tchannel.publish(EXCHANGE_NAME, event.eventId, messageBuffer, {\n\t\tcontentType: 'application/json',\n\t});\n\tconsole.log(`Published event [${event.eventId}] with payload`, event.payload);\n}\n\nexport async function subscribeToEvent(\n\teventId: string,\n\tonMessage: (payload: any) => Promise<void>\n): Promise<void> {\n\tif (!channel) throw new Error('Channel not initialized. Call initEventBus first.');\n\tconst queueName = `${eventId}-${getInstanceId()}`;\n\tawait channel.assertQueue(queueName, {\n\t\tdurable: false,\n\t\texclusive: true,\n\t\tautoDelete: true,\n\t});\n\tawait channel.bindQueue(queueName, EXCHANGE_NAME, eventId);\n\tawait channel.consume(\n\t\tqueueName,\n\t\tasync msg => {\n\t\t\tif (msg !== null) {\n\t\t\t\tconst payloadString = msg.content.toString();\n\t\t\t\tconst payload = JSON.parse(payloadString);\n\t\t\t\ttry {\n\t\t\t\t\tawait onMessage(payload);\n\t\t\t\t\tchannel.ack(msg);\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconsole.error(`Error handling event [${eventId}] on instance [${getInstanceId()}]`, err);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t{ noAck: false }\n\t);\n\tconsole.log(`Subscribed to event [${eventId}] on queue [${queueName}] for instance [${getInstanceId()}]`);\n}\n\nexport async function subscribeToSocketEvent(eventId: string) {\n\tconst queueName = `${eventId}-${getInstanceId()}`;\n\tawait channel.assertQueue(queueName, { durable: true });\n\n\tawait channel.bindQueue(queueName, EXCHANGE_NAME, eventId);\n\n\tawait channel.consume(queueName, msg => {\n\t\tif (!msg) return;\n\t\ttry {\n\t\t\tconst { localKey, payload, recipient } = JSON.parse(msg.content.toString('utf8'));\n\n\t\t\tLocalSubs.emit(recipient, localKey, payload);\n\n\t\t\tchannel.ack(msg);\n\t\t} catch (e) {\n\t\t\tconsole.error('Failed to handle instance event', e);\n\t\t\tchannel.nack(msg, false, false);\n\t\t}\n\t});\n\n\treturn channel;\n}\n\nexport async function closeEventBus(): Promise<void> {\n\tif (channel) await channel.close();\n\tif (connection) await connection.close();\n\tconsole.log(`EventBus closed for instance [${getInstanceId()}]`);\n}\n\nexport async function publishSocketEvent(\n\tevent: BaseSocketEvent<any, any>,\n\trecipients: string[]\n): Promise<void> {\n\tconst redisService = getLibraries().getRedisService(); // already returns RedisService\n\n\tconst localKey = event.getIdentifier(); // e.g. \"CHAT_UPSERT_MESSAGE:123123\"\n\tconst payload = event.payload();\n\tconst eventType = event.eventType();\n\n\tfor (const recipient of recipients) {\n\t\t// 1) Is this user subscribed to *this* event key?\n\t\tconst isSub = await redisService.isMemberOfSet(kEntityEvents(recipient), localKey);\n\n\t\tif (isSub) {\n\t\t\t// 2) Get all instances where this user is connected\n\t\t\tconst instanceNames = await redisService.getSetMembers(kEntityInstances(recipient));\n\n\t\t\tif (!instanceNames.length) {\n\t\t\t\t// No active instances → push notification fallback\n\t\t\t\t// TODO: queue push notification for { recipient, eventType, payload }\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// 3) Publish to every instance with routing\n\t\t\tfor (const instanceName of instanceNames) {\n\t\t\t\tconst routingKey = `${INSTANCE_ROUTE_PREFIX}.${instanceName}.${eventType}`;\n\t\t\t\tconst messageBuffer = Buffer.from(JSON.stringify({ localKey, payload, recipient }), 'utf8');\n\n\t\t\t\tchannel.publish(EXCHANGE_NAME, routingKey, messageBuffer, {\n\t\t\t\t\tcontentType: 'application/json',\n\t\t\t\t\tpersistent: true,\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\t// Not subscribed → push notification fallback\n\t\t\t// TODO: queue push notification for { recipient, eventType, payload }\n\t\t}\n\t}\n}\n\nconst kEntityEvents = (entityId: string) => `socket:events:entity:${entityId}`;\nconst kEntityInstances = (entityId: string) => `socket:instances:entity:${entityId}`;\n"]}
|
|
@@ -16,6 +16,8 @@ export declare class Ticket extends TimeStamps {
|
|
|
16
16
|
supportReason?: Ref<SupportReason>;
|
|
17
17
|
client: Ref<User | Shop>;
|
|
18
18
|
clientType: UserRef;
|
|
19
|
+
clientName: string;
|
|
20
|
+
clientPhoto: string;
|
|
19
21
|
order?: Ref<Order>;
|
|
20
22
|
assignedAgent?: Ref<Admin>;
|
|
21
23
|
assignedAt?: Date;
|
|
@@ -26,6 +26,8 @@ let Ticket = class Ticket extends defaultClasses_1.TimeStamps {
|
|
|
26
26
|
supportReason;
|
|
27
27
|
client;
|
|
28
28
|
clientType;
|
|
29
|
+
clientName;
|
|
30
|
+
clientPhoto;
|
|
29
31
|
order;
|
|
30
32
|
assignedAgent;
|
|
31
33
|
assignedAt;
|
|
@@ -67,6 +69,14 @@ __decorate([
|
|
|
67
69
|
(0, typegoose_1.prop)({ required: true, type: String, enum: enum_1.UserRef }),
|
|
68
70
|
__metadata("design:type", String)
|
|
69
71
|
], Ticket.prototype, "clientType", void 0);
|
|
72
|
+
__decorate([
|
|
73
|
+
(0, typegoose_1.prop)({ required: true, type: String }),
|
|
74
|
+
__metadata("design:type", String)
|
|
75
|
+
], Ticket.prototype, "clientName", void 0);
|
|
76
|
+
__decorate([
|
|
77
|
+
(0, typegoose_1.prop)({ required: true, type: String }),
|
|
78
|
+
__metadata("design:type", String)
|
|
79
|
+
], Ticket.prototype, "clientPhoto", void 0);
|
|
70
80
|
__decorate([
|
|
71
81
|
(0, typegoose_1.prop)({ ref: () => order_model_1.Order }),
|
|
72
82
|
__metadata("design:type", Object)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ticket.model.js","sourceRoot":"/","sources":["libraries/mongo/models/ticket.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAsE;AACtE,4EAAqE;AAGrE,+CAAsC;AACtC,+CAAsC;AACtC,kDAA4E;AAC5E,uDAA6C;AAE7C,+DAAqD;AACrD,iEAAuD;AAahD,IAAM,MAAM,GAAZ,MAAM,MAAO,SAAQ,2BAAU;IAE9B,QAAQ,CAAU;IAGlB,IAAI,CAAc;IAGlB,MAAM,CAAgB;IAGtB,KAAK,CAAU;IAGf,aAAa,CAAsB;IAGnC,MAAM,CAAoB;IAG1B,UAAU,CAAW;
|
|
1
|
+
{"version":3,"file":"ticket.model.js","sourceRoot":"/","sources":["libraries/mongo/models/ticket.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAsE;AACtE,4EAAqE;AAGrE,+CAAsC;AACtC,+CAAsC;AACtC,kDAA4E;AAC5E,uDAA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,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;0CACI;AAGpB;IADN,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,kCAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;;sCACjB;iBA3DtB,MAAM;IAXlB,IAAA,wBAAY,EAAC;QACb,aAAa,EAAE;YACd,UAAU,EAAE,SAAS;YACrB,UAAU,EAAE,IAAI;SAChB;KACD,CAAC;IACD,IAAA,iBAAK,EAAC,EAAE,aAAa,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IACtC,IAAA,iBAAK,EAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;IAC1C,IAAA,iBAAK,EAAC,EAAE,MAAM,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IAC9C,IAAA,iBAAK,EAAC,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC;IACxB,IAAA,iBAAK,EAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;GACV,MAAM,CA4DlB","sourcesContent":["import { prop, Ref, index, modelOptions } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { User } from './user.model';\nimport { Shop } from './shop.model';\nimport { Order } from './order.model';\nimport { Admin } from './admin.model';\nimport { TicketType, TicketStatus, UserRef } from '../../../utilities/enum';\nimport { Chatroom } from './chat-room.model';\nimport { DefaultChat } from './default-chat.model';\nimport { TicketAction } from './ticket-action.model';\nimport { SupportReason } from './support-reason.model';\n\n@modelOptions({\n\tschemaOptions: {\n\t\tcollection: 'tickets',\n\t\ttimestamps: true,\n\t},\n})\n@index({ assignedAgent: 1, status: 1 })\n@index({ type: 1, status: 1, priority: 1 })\n@index({ client: 1, clientType: 1, status: 1 })\n@index({ createdAt: -1 })\n@index({ chatroom: 1 })\nexport class Ticket extends TimeStamps {\n\t@prop({ required: true, type: String, unique: true })\n\tpublic ticketId!: string;\n\n\t@prop({ required: true, type: String, enum: TicketType })\n\tpublic type!: TicketType;\n\n\t@prop({ required: true, type: String, enum: TicketStatus, default: TicketStatus.PENDING })\n\tpublic status!: TicketStatus;\n\n\t@prop({ type: String, required: true })\n\tpublic title!: string;\n\n\t@prop({ ref: () => SupportReason, required: false })\n\tpublic supportReason?: Ref<SupportReason>;\n\n\t@prop({ refPath: 'clientType', required: true })\n\tpublic client!: Ref<User | Shop>;\n\n\t@prop({ required: true, type: String, enum: UserRef })\n\tpublic clientType!: UserRef;\n\n\t@prop({ required: true, type: String })\n\tpublic clientName!: string;\n\n\t@prop({ required: true, type: String })\n\tpublic clientPhoto!: string;\n\n\t@prop({ ref: () => Order })\n\tpublic order?: Ref<Order>;\n\n\t@prop({ ref: () => Admin })\n\tpublic assignedAgent?: Ref<Admin>;\n\n\t@prop({ type: Date })\n\tpublic assignedAt?: Date;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic assignmentAttempts?: number;\n\n\t@prop({ ref: () => Chatroom, required: true })\n\tpublic chatroom!: Ref<Chatroom>;\n\n\t@prop({ type: Date })\n\tpublic resolvedAt?: Date;\n\n\t@prop({ type: Date })\n\tpublic closedAt?: Date;\n\n\t@prop({ type: Number })\n\tpublic resolutionTimeMinutes?: number;\n\n\t@prop({ type: Number, min: 1, max: 5 })\n\tpublic customerRating?: number;\n\n\t@prop({ type: Number })\n\tpublic agentScore?: number;\n\n\t@prop({ ref: () => TicketAction, required: false })\n\tpublic action?: Ref<TicketAction>;\n}\n"]}
|
|
@@ -31,7 +31,7 @@ export declare class User extends TimeStamps {
|
|
|
31
31
|
isPhoneVerified?: boolean;
|
|
32
32
|
onlineStatus?: OnlineStatus;
|
|
33
33
|
fcmTokens?: string[];
|
|
34
|
-
static updateWallet(this: ReturnModelType<typeof User>, userId: string, amount: number): Promise<(import("mongoose").Document<unknown, import("@typegoose/typegoose/lib/types").BeAnObject, User, import("@typegoose/typegoose/lib/types").BeAnyObject
|
|
34
|
+
static updateWallet(this: ReturnModelType<typeof User>, userId: string, amount: number): Promise<(import("mongoose").Document<unknown, import("@typegoose/typegoose/lib/types").BeAnObject, User, import("@typegoose/typegoose/lib/types").BeAnyObject> & Omit<User & {
|
|
35
35
|
_id: import("mongoose").Types.ObjectId;
|
|
36
36
|
} & {
|
|
37
37
|
__v: number;
|
|
@@ -10,4 +10,8 @@ export declare class RedisService {
|
|
|
10
10
|
setCachedObjectByGroup<T>(group: string, key: string, object: T): Promise<boolean>;
|
|
11
11
|
deleteCachedObjectByGroup<T>(group: string, key: string): Promise<boolean>;
|
|
12
12
|
sanitizeKey(key: string): string;
|
|
13
|
+
addToSet(group: string, member: string): Promise<boolean>;
|
|
14
|
+
removeFromSet(group: string, member: string): Promise<boolean>;
|
|
15
|
+
isMemberOfSet(group: string, member: string): Promise<boolean>;
|
|
16
|
+
getSetMembers(group: string): Promise<string[]>;
|
|
13
17
|
}
|
|
@@ -68,6 +68,20 @@ let RedisService = class RedisService {
|
|
|
68
68
|
.replace(/\s+/g, '-')
|
|
69
69
|
.toLowerCase();
|
|
70
70
|
}
|
|
71
|
+
async addToSet(group, member) {
|
|
72
|
+
await this._redisClient.sadd(group, member);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
async removeFromSet(group, member) {
|
|
76
|
+
await this._redisClient.srem(group, member);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
async isMemberOfSet(group, member) {
|
|
80
|
+
return (await this._redisClient.sismember(group, member)) === 1;
|
|
81
|
+
}
|
|
82
|
+
async getSetMembers(group) {
|
|
83
|
+
return await this._redisClient.smembers(group);
|
|
84
|
+
}
|
|
71
85
|
};
|
|
72
86
|
exports.RedisService = RedisService;
|
|
73
87
|
exports.RedisService = RedisService = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/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AAC,KAAK,EAAE,GAAG,EAAE,iBAAiB,CAAC,CAAC;QAE5D,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,KAAK,CAAC,yBAAyB,CAAI,KAAa,EAAE,GAAW;QACnE,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,WAAW,CAAC,GAAW;QAC7B,OAAO,GAAG;aACR,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;aACxB,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;aACpB,WAAW,EAAE,CAAC;IACjB,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,KAAa,EAAE,MAAc;QAClD,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,KAAa,EAAE,MAAc;QACvD,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,KAAa,EAAE,MAAc;QACvD,OAAO,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;IACjE,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,KAAa;QACvC,OAAO,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;CACD,CAAA;AAtFY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,gBAAO,GAAE;;GACG,YAAY,CAsFxB","sourcesContent":["import Redis from 'ioredis';\nimport { Service } from 'typedi';\n\n@Service()\nexport class RedisService {\n\tprivate _redisClient!: Redis;\n\n\tconstructor(redisURL: string) {\n\t\tthis._redisClient = new Redis(redisURL, {\n\t\t\tmaxRetriesPerRequest: null,\n\t\t});\n\t}\n\n\tget redisClient(): Redis {\n\t\treturn this._redisClient;\n\t}\n\n\tpublic async getCachedObject<T>(key: string): Promise<T | undefined> {\n\t\tconst usageResponse = await this._redisClient.get(key);\n\n\t\tif (usageResponse != undefined) {\n\t\t\treturn JSON.parse(usageResponse) as T;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tpublic async cacheObject<T>(key: string, object: T, expiry?: number): Promise<boolean> {\n\t\tconst stringifiedObject = JSON.stringify(object);\n\n\t\tif (expiry) {\n\t\t\tawait this._redisClient.setex(key, expiry, stringifiedObject);\n\t\t} else {\n\t\t\tawait this._redisClient.set(key, stringifiedObject);\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tpublic async deleteCachedObject(key: string): Promise<boolean> {\n\t\tawait this._redisClient.del(key);\n\t\treturn true;\n\t}\n\n\tpublic async getCachedObjectByGroup<T>(group: string, key: string): Promise<T | undefined> {\n\t\tconst usageResponse = await this._redisClient.hget(group, key);\n\n\t\tif (usageResponse != undefined) {\n\t\t\treturn JSON.parse(usageResponse) as T;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tpublic async setCachedObjectByGroup<T>(group: string, key: string, object: T): Promise<boolean> {\n\t\tconst stringifiedObject = JSON.stringify(object);\n\t\tawait this._redisClient.hset(group, key, stringifiedObject);\n\n\t\treturn true;\n\t}\n\n\tpublic async deleteCachedObjectByGroup<T>(group: string, key: string): Promise<boolean> {\n\t\tawait this._redisClient.hdel(group, key);\n\t\treturn true;\n\t}\n\n\tpublic sanitizeKey(key: string) {\n\t\treturn key\n\t\t\t.replace(/[^\\w\\s]/gi, '')\n\t\t\t.replace(/\\s+/g, '-')\n\t\t\t.toLowerCase();\n\t}\n\n\tpublic async addToSet(group: string, member: string): Promise<boolean> {\n\t\tawait this._redisClient.sadd(group, member);\n\t\treturn true;\n\t}\n\n\tpublic async removeFromSet(group: string, member: string): Promise<boolean> {\n\t\tawait this._redisClient.srem(group, member);\n\t\treturn true;\n\t}\n\n\tpublic async isMemberOfSet(group: string, member: string): Promise<boolean> {\n\t\treturn (await this._redisClient.sismember(group, member)) === 1;\n\t}\n\n\tpublic async getSetMembers(group: string): Promise<string[]> {\n\t\treturn await this._redisClient.smembers(group);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import z, { ZodTypeAny } from 'zod';
|
|
2
|
+
import { SocketEventType } from '../../utilities/enum';
|
|
3
|
+
export declare abstract class BaseSocketEvent<SIn extends ZodTypeAny, SOut extends ZodTypeAny> {
|
|
4
|
+
protected readonly _eventType: SocketEventType;
|
|
5
|
+
protected readonly inputSchema: SIn;
|
|
6
|
+
protected readonly outputSchema: SOut;
|
|
7
|
+
protected readonly data: z.infer<SOut>;
|
|
8
|
+
abstract getIdentifier(): string;
|
|
9
|
+
protected constructor(eventType: SocketEventType, schemas: {
|
|
10
|
+
input: SIn;
|
|
11
|
+
output: SOut;
|
|
12
|
+
}, data: z.infer<SOut>);
|
|
13
|
+
payload(): z.infer<SOut>;
|
|
14
|
+
eventType(): SocketEventType;
|
|
15
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseSocketEvent = void 0;
|
|
4
|
+
class BaseSocketEvent {
|
|
5
|
+
_eventType;
|
|
6
|
+
inputSchema;
|
|
7
|
+
outputSchema;
|
|
8
|
+
data;
|
|
9
|
+
constructor(eventType, schemas, data) {
|
|
10
|
+
this._eventType = eventType;
|
|
11
|
+
this.inputSchema = schemas.input;
|
|
12
|
+
this.outputSchema = schemas.output;
|
|
13
|
+
this.data = this.outputSchema.parse(data);
|
|
14
|
+
}
|
|
15
|
+
payload() {
|
|
16
|
+
return this.data;
|
|
17
|
+
}
|
|
18
|
+
eventType() {
|
|
19
|
+
return this._eventType;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.BaseSocketEvent = BaseSocketEvent;
|
|
23
|
+
//# sourceMappingURL=BaseSocketEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseSocketEvent.js","sourceRoot":"/","sources":["libraries/socket/BaseSocketEvent.ts"],"names":[],"mappings":";;;AAGA,MAAsB,eAAe;IACjB,UAAU,CAAkB;IAC5B,WAAW,CAAM;IACjB,YAAY,CAAO;IAEnB,IAAI,CAAgB;IAIvC,YACC,SAA0B,EAC1B,OAAqC,EACrC,IAAmB;QAEnB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;QAEnC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;IAEM,OAAO;QACb,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAEM,SAAS;QACf,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;CACD;AA5BD,0CA4BC","sourcesContent":["import z, { ZodTypeAny } from 'zod';\nimport { SocketEventType } from '../../utilities/enum';\n\nexport abstract class BaseSocketEvent<SIn extends ZodTypeAny, SOut extends ZodTypeAny> {\n\tprotected readonly _eventType: SocketEventType;\n\tprotected readonly inputSchema: SIn;\n\tprotected readonly outputSchema: SOut;\n\n\tprotected readonly data: z.infer<SOut>;\n\n\tabstract getIdentifier(): string;\n\n\tprotected constructor(\n\t\teventType: SocketEventType,\n\t\tschemas: { input: SIn; output: SOut },\n\t\tdata: z.infer<SOut>\n\t) {\n\t\tthis._eventType = eventType;\n\t\tthis.inputSchema = schemas.input;\n\t\tthis.outputSchema = schemas.output;\n\n\t\tthis.data = this.outputSchema.parse(data);\n\t}\n\n\tpublic payload(): z.infer<SOut> {\n\t\treturn this.data;\n\t}\n\n\tpublic eventType(): SocketEventType {\n\t\treturn this._eventType;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
type EventKey = string;
|
|
3
|
+
type EntityId = string;
|
|
4
|
+
declare class LocalSubscriptionRegistry {
|
|
5
|
+
private byEntity;
|
|
6
|
+
bind(entityId: EntityId, eventKey: EventKey, ee: EventEmitter): void;
|
|
7
|
+
unbind(entityId: EntityId, eventKey: EventKey): void;
|
|
8
|
+
emit(entityId: EntityId, eventKey: EventKey, payload: unknown): void;
|
|
9
|
+
}
|
|
10
|
+
export declare const LocalSubs: LocalSubscriptionRegistry;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocalSubs = void 0;
|
|
4
|
+
class LocalSubscriptionRegistry {
|
|
5
|
+
byEntity = new Map();
|
|
6
|
+
bind(entityId, eventKey, ee) {
|
|
7
|
+
let m = this.byEntity.get(entityId);
|
|
8
|
+
if (!m) {
|
|
9
|
+
m = new Map();
|
|
10
|
+
this.byEntity.set(entityId, m);
|
|
11
|
+
}
|
|
12
|
+
m.set(eventKey, ee);
|
|
13
|
+
}
|
|
14
|
+
unbind(entityId, eventKey) {
|
|
15
|
+
const m = this.byEntity.get(entityId);
|
|
16
|
+
if (!m)
|
|
17
|
+
return;
|
|
18
|
+
m.delete(eventKey);
|
|
19
|
+
if (m.size === 0)
|
|
20
|
+
this.byEntity.delete(entityId);
|
|
21
|
+
}
|
|
22
|
+
emit(entityId, eventKey, payload) {
|
|
23
|
+
const m = this.byEntity.get(entityId);
|
|
24
|
+
const ee = m?.get(eventKey);
|
|
25
|
+
if (ee)
|
|
26
|
+
ee.emit(eventKey, payload);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.LocalSubs = new LocalSubscriptionRegistry();
|
|
30
|
+
//# sourceMappingURL=LocalSub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yB,EAAE,CAAC","sourcesContent":["import EventEmitter from 'events';\n\ntype EventKey = string; // \"EVENT_TYPE:identifier\"\ntype EntityId = string;\n\nclass LocalSubscriptionRegistry {\n\tprivate byEntity = new Map<EntityId, Map<EventKey, EventEmitter>>();\n\n\tbind(entityId: EntityId, eventKey: EventKey, ee: EventEmitter) {\n\t\tlet m = this.byEntity.get(entityId);\n\t\tif (!m) {\n\t\t\tm = new Map();\n\t\t\tthis.byEntity.set(entityId, m);\n\t\t}\n\t\tm.set(eventKey, ee);\n\t}\n\n\tunbind(entityId: EntityId, eventKey: EventKey) {\n\t\tconst m = this.byEntity.get(entityId);\n\t\tif (!m) return;\n\t\tm.delete(eventKey);\n\t\tif (m.size === 0) this.byEntity.delete(entityId);\n\t}\n\n\temit(entityId: EntityId, eventKey: EventKey, payload: unknown) {\n\t\tconst m = this.byEntity.get(entityId);\n\t\tconst ee = m?.get(eventKey);\n\t\tif (ee) ee.emit(eventKey, payload);\n\t}\n}\n\nexport const LocalSubs = new LocalSubscriptionRegistry();\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
import { BaseSocketEvent } from '../BaseSocketEvent';
|
|
3
|
+
import { DTO } from '../../../utilities/validation';
|
|
4
|
+
export declare const ChatroomMessageSendInput: z.ZodObject<{
|
|
5
|
+
chatId: z.ZodString;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
chatId: string;
|
|
8
|
+
}, {
|
|
9
|
+
chatId: string;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const ChatroomMessageSendOutput: z.ZodObject<{
|
|
12
|
+
chatId: z.ZodString;
|
|
13
|
+
messageId: z.ZodString;
|
|
14
|
+
contents: z.ZodString;
|
|
15
|
+
createdAt: z.ZodDate;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
createdAt: Date;
|
|
18
|
+
contents: string;
|
|
19
|
+
chatId: string;
|
|
20
|
+
messageId: string;
|
|
21
|
+
}, {
|
|
22
|
+
createdAt: Date;
|
|
23
|
+
contents: string;
|
|
24
|
+
chatId: string;
|
|
25
|
+
messageId: string;
|
|
26
|
+
}>;
|
|
27
|
+
export declare class ChatroomMessageSendEvent extends BaseSocketEvent<typeof ChatroomMessageSendInput, typeof ChatroomMessageSendOutput> {
|
|
28
|
+
static readonly schemas: {
|
|
29
|
+
input: z.ZodObject<{
|
|
30
|
+
chatId: z.ZodString;
|
|
31
|
+
}, "strip", z.ZodTypeAny, {
|
|
32
|
+
chatId: string;
|
|
33
|
+
}, {
|
|
34
|
+
chatId: string;
|
|
35
|
+
}>;
|
|
36
|
+
output: z.ZodObject<{
|
|
37
|
+
chatId: z.ZodString;
|
|
38
|
+
messageId: z.ZodString;
|
|
39
|
+
contents: z.ZodString;
|
|
40
|
+
createdAt: z.ZodDate;
|
|
41
|
+
}, "strip", z.ZodTypeAny, {
|
|
42
|
+
createdAt: Date;
|
|
43
|
+
contents: string;
|
|
44
|
+
chatId: string;
|
|
45
|
+
messageId: string;
|
|
46
|
+
}, {
|
|
47
|
+
createdAt: Date;
|
|
48
|
+
contents: string;
|
|
49
|
+
chatId: string;
|
|
50
|
+
messageId: string;
|
|
51
|
+
}>;
|
|
52
|
+
};
|
|
53
|
+
constructor(payload: DTO<typeof ChatroomMessageSendOutput>);
|
|
54
|
+
getIdentifier(): string;
|
|
55
|
+
static identifier(input: z.infer<typeof ChatroomMessageSendInput>): string;
|
|
56
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ChatroomMessageSendEvent = exports.ChatroomMessageSendOutput = exports.ChatroomMessageSendInput = void 0;
|
|
7
|
+
const zod_1 = __importDefault(require("zod"));
|
|
8
|
+
const BaseSocketEvent_1 = require("../BaseSocketEvent");
|
|
9
|
+
const enum_1 = require("../../../utilities/enum");
|
|
10
|
+
exports.ChatroomMessageSendInput = zod_1.default.object({
|
|
11
|
+
chatId: zod_1.default.string(),
|
|
12
|
+
});
|
|
13
|
+
exports.ChatroomMessageSendOutput = zod_1.default.object({
|
|
14
|
+
chatId: zod_1.default.string(),
|
|
15
|
+
messageId: zod_1.default.string(),
|
|
16
|
+
contents: zod_1.default.string(),
|
|
17
|
+
createdAt: zod_1.default.date(),
|
|
18
|
+
});
|
|
19
|
+
class ChatroomMessageSendEvent extends BaseSocketEvent_1.BaseSocketEvent {
|
|
20
|
+
static schemas = { input: exports.ChatroomMessageSendInput, output: exports.ChatroomMessageSendOutput };
|
|
21
|
+
constructor(payload) {
|
|
22
|
+
super(enum_1.SocketEventType.CHATROOM_MESSAGE_SEND, ChatroomMessageSendEvent.schemas, payload);
|
|
23
|
+
}
|
|
24
|
+
getIdentifier() {
|
|
25
|
+
return enum_1.SocketEventType.CHATROOM_MESSAGE_SEND + ChatroomMessageSendEvent.identifier(this.data);
|
|
26
|
+
}
|
|
27
|
+
static identifier(input) {
|
|
28
|
+
return input.chatId;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.ChatroomMessageSendEvent = ChatroomMessageSendEvent;
|
|
32
|
+
//# sourceMappingURL=chatroom-message-send-socket.event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatroom-message-send-socket.event.js","sourceRoot":"/","sources":["libraries/socket/events/chatroom-message-send-socket.event.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAoB;AACpB,wDAAqD;AACrD,kDAA0D;AAG7C,QAAA,wBAAwB,GAAG,aAAC,CAAC,MAAM,CAAC;IAChD,MAAM,EAAE,aAAC,CAAC,MAAM,EAAE;CAClB,CAAC,CAAC;AAEU,QAAA,yBAAyB,GAAG,aAAC,CAAC,MAAM,CAAC;IACjD,MAAM,EAAE,aAAC,CAAC,MAAM,EAAE;IAClB,SAAS,EAAE,aAAC,CAAC,MAAM,EAAE;IACrB,QAAQ,EAAE,aAAC,CAAC,MAAM,EAAE;IACpB,SAAS,EAAE,aAAC,CAAC,IAAI,EAAE;CACnB,CAAC,CAAC;AAEH,MAAa,wBAAyB,SAAQ,iCAG7C;IACA,MAAM,CAAU,OAAO,GAAG,EAAE,KAAK,EAAE,gCAAwB,EAAE,MAAM,EAAE,iCAAyB,EAAE,CAAC;IAEjG,YAAY,OAA8C;QACzD,KAAK,CAAC,sBAAe,CAAC,qBAAqB,EAAE,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzF,CAAC;IAEM,aAAa;QACnB,OAAO,sBAAe,CAAC,qBAAqB,GAAG,wBAAwB,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/F,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,KAA+C;QAChE,OAAO,KAAK,CAAC,MAAM,CAAC;IACrB,CAAC;;AAhBF,4DAiBC","sourcesContent":["import z from 'zod';\nimport { BaseSocketEvent } from '../BaseSocketEvent';\nimport { SocketEventType } from '../../../utilities/enum';\nimport { DTO } from '../../../utilities/validation';\n\nexport const ChatroomMessageSendInput = z.object({\n\tchatId: z.string(),\n});\n\nexport const ChatroomMessageSendOutput = z.object({\n\tchatId: z.string(),\n\tmessageId: z.string(),\n\tcontents: z.string(),\n\tcreatedAt: z.date(),\n});\n\nexport class ChatroomMessageSendEvent extends BaseSocketEvent<\n\ttypeof ChatroomMessageSendInput,\n\ttypeof ChatroomMessageSendOutput\n> {\n\tstatic readonly schemas = { input: ChatroomMessageSendInput, output: ChatroomMessageSendOutput };\n\n\tconstructor(payload: DTO<typeof ChatroomMessageSendOutput>) {\n\t\tsuper(SocketEventType.CHATROOM_MESSAGE_SEND, ChatroomMessageSendEvent.schemas, payload);\n\t}\n\n\tpublic getIdentifier(): string {\n\t\treturn SocketEventType.CHATROOM_MESSAGE_SEND + ChatroomMessageSendEvent.identifier(this.data);\n\t}\n\n\tstatic identifier(input: z.infer<typeof ChatroomMessageSendInput>): string {\n\t\treturn input.chatId;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import z, { ZodTypeAny } from 'zod';
|
|
2
|
+
import { ChatroomMessageSendEvent, ChatroomMessageSendInput, ChatroomMessageSendOutput } from './events/chatroom-message-send-socket.event';
|
|
3
|
+
import { SocketEventType } from '../../utilities/enum';
|
|
4
|
+
import { BaseSocketEvent } from './BaseSocketEvent';
|
|
5
|
+
type EventCtor<SIn extends ZodTypeAny, SOut extends ZodTypeAny, C extends BaseSocketEvent<SIn, SOut>> = new (data: z.input<SOut>) => C;
|
|
6
|
+
declare const REGISTRY: {
|
|
7
|
+
readonly CHATROOM_MESSAGE_SEND: {
|
|
8
|
+
readonly ctor: EventCtor<typeof ChatroomMessageSendInput, typeof ChatroomMessageSendOutput, ChatroomMessageSendEvent>;
|
|
9
|
+
readonly input: z.ZodObject<{
|
|
10
|
+
chatId: z.ZodString;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
chatId: string;
|
|
13
|
+
}, {
|
|
14
|
+
chatId: string;
|
|
15
|
+
}>;
|
|
16
|
+
readonly output: z.ZodObject<{
|
|
17
|
+
chatId: z.ZodString;
|
|
18
|
+
messageId: z.ZodString;
|
|
19
|
+
contents: z.ZodString;
|
|
20
|
+
createdAt: z.ZodDate;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
createdAt: Date;
|
|
23
|
+
contents: string;
|
|
24
|
+
chatId: string;
|
|
25
|
+
messageId: string;
|
|
26
|
+
}, {
|
|
27
|
+
createdAt: Date;
|
|
28
|
+
contents: string;
|
|
29
|
+
chatId: string;
|
|
30
|
+
messageId: string;
|
|
31
|
+
}>;
|
|
32
|
+
readonly identifier: typeof ChatroomMessageSendEvent.identifier;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
type Registry = typeof REGISTRY;
|
|
36
|
+
type PayloadFor<T extends SocketEventType> = z.input<Registry[T]['output']>;
|
|
37
|
+
type EventFor<T extends SocketEventType> = InstanceType<Registry[T]['ctor']>;
|
|
38
|
+
export declare class EventFactory {
|
|
39
|
+
static createEvent<T extends SocketEventType>(SocketEventType: T, data: PayloadFor<T>): EventFor<T>;
|
|
40
|
+
static getSubscriptionKey<T extends SocketEventType>(SocketEventType: T, input: z.infer<(typeof REGISTRY)[T]['input']>): string;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventFactory = void 0;
|
|
4
|
+
const chatroom_message_send_socket_event_1 = require("./events/chatroom-message-send-socket.event");
|
|
5
|
+
const enum_1 = require("../../utilities/enum");
|
|
6
|
+
const REGISTRY = {
|
|
7
|
+
[enum_1.SocketEventType.CHATROOM_MESSAGE_SEND]: {
|
|
8
|
+
ctor: chatroom_message_send_socket_event_1.ChatroomMessageSendEvent,
|
|
9
|
+
input: chatroom_message_send_socket_event_1.ChatroomMessageSendEvent.schemas.input,
|
|
10
|
+
output: chatroom_message_send_socket_event_1.ChatroomMessageSendEvent.schemas.output,
|
|
11
|
+
identifier: chatroom_message_send_socket_event_1.ChatroomMessageSendEvent.identifier,
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
class EventFactory {
|
|
15
|
+
static createEvent(SocketEventType, data) {
|
|
16
|
+
const { ctor } = REGISTRY[SocketEventType];
|
|
17
|
+
return new ctor(data);
|
|
18
|
+
}
|
|
19
|
+
static getSubscriptionKey(SocketEventType, input) {
|
|
20
|
+
const { identifier } = REGISTRY[SocketEventType];
|
|
21
|
+
return `${SocketEventType}:${identifier(input)}`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.EventFactory = EventFactory;
|
|
25
|
+
//# sourceMappingURL=socket-event-registery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket-event-registery.js","sourceRoot":"/","sources":["libraries/socket/socket-event-registery.ts"],"names":[],"mappings":";;;AACA,oGAIqD;AACrD,+CAAuD;AAOvD,MAAM,QAAQ,GAAG;IAChB,CAAC,sBAAe,CAAC,qBAAqB,CAAC,EAAE;QACxC,IAAI,EAAE,6DAIL;QACD,KAAK,EAAE,6DAAwB,CAAC,OAAO,CAAC,KAAK;QAC7C,MAAM,EAAE,6DAAwB,CAAC,OAAO,CAAC,MAAM;QAC/C,UAAU,EAAE,6DAAwB,CAAC,UAAU;KAC/C;CACQ,CAAC;AAOX,MAAa,YAAY;IACjB,MAAM,CAAC,WAAW,CAA4B,eAAkB,EAAE,IAAmB;QAC3F,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC,CAAC;QAC3C,OAAO,IAAI,IAAI,CAAC,IAAI,CAAgB,CAAC;IACtC,CAAC;IAEM,MAAM,CAAC,kBAAkB,CAC/B,eAAkB,EAClB,KAA6C;QAE7C,MAAM,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC,CAAC;QACjD,OAAO,GAAG,eAAe,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;IAClD,CAAC;CACD;AAbD,oCAaC","sourcesContent":["import z, { ZodTypeAny } from 'zod';\nimport {\n\tChatroomMessageSendEvent,\n\tChatroomMessageSendInput,\n\tChatroomMessageSendOutput,\n} from './events/chatroom-message-send-socket.event';\nimport { SocketEventType } from '../../utilities/enum';\nimport { BaseSocketEvent } from './BaseSocketEvent';\n\ntype EventCtor<SIn extends ZodTypeAny, SOut extends ZodTypeAny, C extends BaseSocketEvent<SIn, SOut>> = new (\n\tdata: z.input<SOut>\n) => C;\n\nconst REGISTRY = {\n\t[SocketEventType.CHATROOM_MESSAGE_SEND]: {\n\t\tctor: ChatroomMessageSendEvent as EventCtor<\n\t\t\ttypeof ChatroomMessageSendInput,\n\t\t\ttypeof ChatroomMessageSendOutput,\n\t\t\tChatroomMessageSendEvent\n\t\t>,\n\t\tinput: ChatroomMessageSendEvent.schemas.input,\n\t\toutput: ChatroomMessageSendEvent.schemas.output,\n\t\tidentifier: ChatroomMessageSendEvent.identifier,\n\t},\n} as const;\n\ntype Registry = typeof REGISTRY;\n\ntype PayloadFor<T extends SocketEventType> = z.input<Registry[T]['output']>;\ntype EventFor<T extends SocketEventType> = InstanceType<Registry[T]['ctor']>;\n\nexport class EventFactory {\n\tpublic static createEvent<T extends SocketEventType>(SocketEventType: T, data: PayloadFor<T>): EventFor<T> {\n\t\tconst { ctor } = REGISTRY[SocketEventType];\n\t\treturn new ctor(data) as EventFor<T>;\n\t}\n\n\tpublic static getSubscriptionKey<T extends SocketEventType>(\n\t\tSocketEventType: T,\n\t\tinput: z.infer<(typeof REGISTRY)[T]['input']>\n\t): string {\n\t\tconst { identifier } = REGISTRY[SocketEventType];\n\t\treturn `${SocketEventType}:${identifier(input)}`;\n\t}\n}\n"]}
|
package/dist/types/README.md
CHANGED
package/dist/types/package.json
CHANGED
|
@@ -636,10 +636,6 @@ export declare enum ChatroomType {
|
|
|
636
636
|
TICKET = "ticket",
|
|
637
637
|
DIRECT = "direct"
|
|
638
638
|
}
|
|
639
|
-
export declare enum SocketEventType {
|
|
640
|
-
MESSAGE_RECEIVED = "message.received",
|
|
641
|
-
TICKET_NOTIFICATION = "ticket.notification"
|
|
642
|
-
}
|
|
643
639
|
export declare enum ServiceCartStatus {
|
|
644
640
|
ACTIVE = "active",
|
|
645
641
|
LOCKED = "locked",
|
|
@@ -754,6 +750,9 @@ export declare enum SocketServiceQueue {
|
|
|
754
750
|
NOTIFICATION = "socket.notification.emit",
|
|
755
751
|
ORDER = "socket.order.emit"
|
|
756
752
|
}
|
|
753
|
+
export declare enum SocketEventType {
|
|
754
|
+
CHATROOM_MESSAGE_SEND = "CHATROOM_MESSAGE_SEND"
|
|
755
|
+
}
|
|
757
756
|
export declare enum DeviceType {
|
|
758
757
|
MOBILE = "mobile",
|
|
759
758
|
WEB = "web"
|