@lyxa.ai/core 1.2.85 → 1.2.87
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/event/index.d.ts +1 -6
- package/dist/libraries/event/index.js +4 -6
- package/dist/libraries/event/index.js.map +1 -1
- package/dist/libraries/mongo/models/providers/core-email-auth-identity.model.js +6 -1
- package/dist/libraries/mongo/models/providers/core-email-auth-identity.model.js.map +1 -1
- package/dist/types/README.md +1 -1
- package/dist/types/package.json +1 -1
- package/package.json +1 -1
|
@@ -5,10 +5,5 @@ export declare const INSTANCE_ROUTE_PREFIX = "instance";
|
|
|
5
5
|
export declare function initEventBus(rabbitUrl: string): Promise<void>;
|
|
6
6
|
export declare function getChannel(): amqp.Channel;
|
|
7
7
|
export declare function publishEvent<TPayload extends Record<string, unknown>>(event: BaseEvent<TPayload>): Promise<void>;
|
|
8
|
-
export
|
|
9
|
-
exclusive?: boolean;
|
|
10
|
-
durable?: boolean;
|
|
11
|
-
autoDelete?: boolean;
|
|
12
|
-
};
|
|
13
|
-
export declare function subscribeToEvent(eventId: string, onMessage: (payload: any) => Promise<void>, options?: RabbitMqOptions): Promise<void>;
|
|
8
|
+
export declare function subscribeToEvent(eventId: string, onMessage: (payload: any) => Promise<void>): Promise<void>;
|
|
14
9
|
export declare function closeEventBus(): Promise<void>;
|
|
@@ -33,16 +33,14 @@ async function publishEvent(event) {
|
|
|
33
33
|
contentType: 'application/json',
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
-
async function subscribeToEvent(eventId, onMessage
|
|
36
|
+
async function subscribeToEvent(eventId, onMessage) {
|
|
37
37
|
const ch = getChannel();
|
|
38
|
-
const queueName =
|
|
39
|
-
|
|
38
|
+
const queueName = `${eventId}`;
|
|
39
|
+
await ch.assertQueue(queueName, {
|
|
40
40
|
durable: true,
|
|
41
41
|
exclusive: false,
|
|
42
42
|
autoDelete: false,
|
|
43
|
-
|
|
44
|
-
};
|
|
45
|
-
await ch.assertQueue(queueName, queueOptions);
|
|
43
|
+
});
|
|
46
44
|
await ch.bindQueue(queueName, exports.EXCHANGE_NAME, eventId);
|
|
47
45
|
await ch.consume(queueName, async (msg) => {
|
|
48
46
|
if (msg !== null) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/event/index.ts"],"names":[],"mappings":";;;;;;AASA,oCAKC;AAED,gCAGC;AAED,oCASC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/event/index.ts"],"names":[],"mappings":";;;;;;AASA,oCAKC;AAED,gCAGC;AAED,oCASC;AAED,4CAiCC;AAED,sCAIC;AAvED,sDAA2B;AAE3B,mEAA+D;AAE/D,IAAI,UAA6B,CAAC;AAClC,IAAI,OAAqB,CAAC;AACb,QAAA,aAAa,GAAG,aAAa,CAAC;AAC9B,QAAA,qBAAqB,GAAG,UAAU,CAAC;AAEzC,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,qBAAa,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACxE,OAAO,CAAC,GAAG,CAAC,0CAA0C,IAAA,8BAAa,GAAE,EAAE,CAAC,CAAC;AAC1E,CAAC;AAED,SAAgB,UAAU;IACzB,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACnF,OAAO,OAAO,CAAC;AAChB,CAAC;AAEM,KAAK,UAAU,YAAY,CACjC,KAA0B;IAE1B,MAAM,EAAE,GAAG,UAAU,EAAE,CAAC;IACxB,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC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C;IACnC,IAAI,UAAU;QAAE,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;IACzC,OAAO,CAAC,GAAG,CAAC,iCAAiC,IAAA,8BAAa,GAAE,GAAG,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import amqp from 'amqplib';\nimport { BaseEvent } from './BaseEvent';\nimport { getInstanceId } from '../../utilities/instance.utils';\n\nlet connection: amqp.ChannelModel;\nlet channel: amqp.Channel;\nexport const EXCHANGE_NAME = 'lyxa.events';\nexport const 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 function getChannel(): amqp.Channel {\n\tif (!channel) throw new Error('Channel not initialized. Call initEventBus first.');\n\treturn channel;\n}\n\nexport async function publishEvent<TPayload extends Record<string, unknown>>(\n\tevent: BaseEvent<TPayload>\n): Promise<void> {\n\tconst ch = getChannel();\n\tconst messageBuffer = Buffer.from(JSON.stringify(event.payload));\n\tch.publish(EXCHANGE_NAME, event.eventId, messageBuffer, {\n\t\tcontentType: 'application/json',\n\t});\n\t// console.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\tconst ch = getChannel();\n\tconst queueName = `${eventId}`;\n\n\tawait ch.assertQueue(queueName, {\n\t\tdurable: true, // survive broker restart\n\t\texclusive: false, // Allow multiple consumers to attach. Only one connection can use it (each pod has own queue). Set to TRUE if each pod needs it's own queue\n\t\tautoDelete: false, // Queue removed when pod disconnects when set to TRUE\n\t});\n\n\tawait ch.bindQueue(queueName, EXCHANGE_NAME, eventId);\n\n\tawait ch.consume(\n\t\tqueueName,\n\t\tasync msg => {\n\t\t\tif (msg !== null) {\n\t\t\t\tconst payload = JSON.parse(msg.content.toString());\n\t\t\t\ttry {\n\t\t\t\t\tawait onMessage(payload);\n\t\t\t\t\tch.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\n\t// console.log(`Subscribed to event [${eventId}] on queue [${queueName}]`);\n\tconsole.log(`Subscribed to event [${eventId}]`);\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}"]}
|
|
@@ -54,10 +54,15 @@ exports.CoreEmailAuthIdentity = CoreEmailAuthIdentity = __decorate([
|
|
|
54
54
|
}),
|
|
55
55
|
(0, typegoose_1.pre)('findOneAndUpdate', async function (next) {
|
|
56
56
|
const update = this.getUpdate();
|
|
57
|
+
if (!update)
|
|
58
|
+
return next();
|
|
57
59
|
if (update?.password) {
|
|
58
60
|
update.password = await hashPassword(update.password);
|
|
59
|
-
this.setUpdate(update);
|
|
60
61
|
}
|
|
62
|
+
if (update.$set?.password) {
|
|
63
|
+
update.$set.password = await hashPassword(update.$set.password);
|
|
64
|
+
}
|
|
65
|
+
this.setUpdate(update);
|
|
61
66
|
next();
|
|
62
67
|
})
|
|
63
68
|
], CoreEmailAuthIdentity);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-email-auth-identity.model.js","sourceRoot":"/","sources":["libraries/mongo/models/providers/core-email-auth-identity.model.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAAoE;AACpE,0EAA+D;AAC/D,mEAAyD;AACzD,wDAA8B;AAE9B,yEAAsE;AAEtE,KAAK,UAAU,YAAY,CAAC,QAAgB;IAC3C,MAAM,IAAI,GAAG,MAAM,kBAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACtC,OAAO,kBAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AACpC,CAAC;
|
|
1
|
+
{"version":3,"file":"core-email-auth-identity.model.js","sourceRoot":"/","sources":["libraries/mongo/models/providers/core-email-auth-identity.model.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAAoE;AACpE,0EAA+D;AAC/D,mEAAyD;AACzD,wDAA8B;AAE9B,yEAAsE;AAEtE,KAAK,UAAU,YAAY,CAAC,QAAgB;IAC3C,MAAM,IAAI,GAAG,MAAM,kBAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACtC,OAAO,kBAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AACpC,CAAC;AAsBM,IAAM,qBAAqB,GAA3B,MAAM,qBAAsB,SAAQ,2CAAgB;IAEnD,KAAK,CAAU;IAGf,QAAQ,CAAU;IAGlB,IAAI,CAAe;IAGnB,aAAa,CAAuB;CAC3C,CAAA;AAZY,sDAAqB;AAE1B;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;oDACjB;AAGf;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;uDACd;AAGlB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,4BAAS,EAAE,CAAC;;mDACA;AAGnB;IADN,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;8BACE,yCAAmB;4DAAC;gCAX/B,qBAAqB;IArBjC,IAAA,eAAG,EAAwB,MAAM,EAAE,KAAK,WAAW,IAAI;QACvD,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YACjC,IAAI,CAAC,QAAQ,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnD,CAAC;QACD,IAAI,EAAE,CAAC;IACR,CAAC,CAAC;IACD,IAAA,eAAG,EAAoC,kBAAkB,EAAE,KAAK,WAAW,IAAI;QAC/E,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAyB,CAAC;QACvD,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,EAAE,CAAC;QAE3B,IAAI,MAAM,EAAE,QAAQ,EAAE,CAAC;YACtB,MAAM,CAAC,QAAQ,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACvD,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC;YAC3B,MAAM,CAAC,IAAI,CAAC,QAAQ,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjE,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACvB,IAAI,EAAE,CAAC;IACR,CAAC,CAAC;GACW,qBAAqB,CAYjC","sourcesContent":["import { modelOptions, prop, pre, Ref } from '@typegoose/typegoose';\nimport { CoreAuthIdentity } from '../core-auth-identity.model';\nimport { OTPFields } from '../embedded/otp-fields.model';\nimport bcrypt from 'bcryptjs';\nimport { Query } from 'mongoose';\nimport { ResetPasswordFields } from '../embedded/rest-password.model';\n\nasync function hashPassword(password: string): Promise<string> {\n\tconst salt = await bcrypt.genSalt(10);\n\treturn bcrypt.hash(password, salt);\n}\n@pre<CoreEmailAuthIdentity>('save', async function (next) {\n\tif (this.isModified('password')) {\n\t\tthis.password = await hashPassword(this.password);\n\t}\n\tnext();\n})\n@pre<Query<any, CoreEmailAuthIdentity>>('findOneAndUpdate', async function (next) {\n\tconst update = this.getUpdate() as Record<string, any>;\n\tif (!update) return next();\n\n\tif (update?.password) {\n\t\tupdate.password = await hashPassword(update.password);\n\t}\n\n\tif (update.$set?.password) {\n\t\tupdate.$set.password = await hashPassword(update.$set.password);\n\t}\n\n\tthis.setUpdate(update);\n\tnext();\n})\nexport class CoreEmailAuthIdentity extends CoreAuthIdentity {\n\t@prop({ required: true, type: String })\n\tpublic email!: string;\n\n\t@prop({ required: true, type: String })\n\tpublic password!: string;\n\n\t@prop({ type: OTPFields })\n\tpublic otps?: OTPFields[];\n\n\t@prop({ _id: false })\n\tpublic resetPassword?: ResetPasswordFields;\n}\n"]}
|
package/dist/types/README.md
CHANGED
package/dist/types/package.json
CHANGED