@axxel/event-bus 1.0.2 → 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.
- package/dist/config/kafka.d.ts +3 -0
- package/dist/config/kafka.d.ts.map +1 -0
- package/dist/config/kafka.js +15 -0
- package/dist/consumers/index.d.ts +3 -0
- package/dist/consumers/index.d.ts.map +1 -0
- package/dist/consumers/index.js +18 -0
- package/dist/consumers/tokenPriceConsumer.d.ts +8 -0
- package/dist/consumers/tokenPriceConsumer.d.ts.map +1 -0
- package/dist/consumers/tokenPriceConsumer.js +27 -0
- package/dist/consumers/walletTransactionConsumer.d.ts +8 -0
- package/dist/consumers/walletTransactionConsumer.d.ts.map +1 -0
- package/dist/consumers/walletTransactionConsumer.js +27 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/producers/index.d.ts +3 -0
- package/dist/producers/index.d.ts.map +1 -0
- package/dist/producers/index.js +18 -0
- package/dist/producers/tokenPriceProducer.d.ts +3 -0
- package/dist/producers/tokenPriceProducer.d.ts.map +1 -0
- package/dist/producers/tokenPriceProducer.js +31 -0
- package/dist/producers/walletTransactionProducer.d.ts +3 -0
- package/dist/producers/walletTransactionProducer.d.ts.map +1 -0
- package/dist/producers/walletTransactionProducer.js +21 -0
- package/dist/topics.d.ts +6 -0
- package/dist/topics.d.ts.map +1 -0
- package/dist/topics.js +7 -0
- package/dist/types/TokenPriceEvent.d.ts +15 -0
- package/dist/types/TokenPriceEvent.d.ts.map +1 -0
- package/dist/types/TokenPriceEvent.js +2 -0
- package/dist/types/WalletTransactionEvent.d.ts +18 -0
- package/dist/types/WalletTransactionEvent.d.ts.map +1 -0
- package/dist/types/WalletTransactionEvent.js +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +18 -0
- package/dist/validation/common.d.ts +5 -0
- package/dist/validation/common.d.ts.map +1 -0
- package/dist/validation/common.js +24 -0
- package/dist/validation/tokenPriceEvent.schema.d.ts +17 -0
- package/dist/validation/tokenPriceEvent.schema.d.ts.map +1 -0
- package/dist/validation/tokenPriceEvent.schema.js +47 -0
- package/dist/validation/walletTransactionEvent.schema.d.ts +21 -0
- package/dist/validation/walletTransactionEvent.schema.d.ts.map +1 -0
- package/dist/validation/walletTransactionEvent.schema.js +26 -0
- package/package.json +4 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kafka.d.ts","sourceRoot":"","sources":["../../src/config/kafka.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAKhC,eAAO,MAAM,KAAK,OAIhB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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.kafka = void 0;
|
|
7
|
+
const kafkajs_1 = require("kafkajs");
|
|
8
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
9
|
+
dotenv_1.default.config();
|
|
10
|
+
exports.kafka = new kafkajs_1.Kafka({
|
|
11
|
+
clientId: process.env.KAFKA_CLIENT_ID || 'axxel-event-bus',
|
|
12
|
+
brokers: process.env.KAFKA_BROKERS?.split(',') || [],
|
|
13
|
+
ssl: false,
|
|
14
|
+
});
|
|
15
|
+
console.log('Kafka brokers:', process.env.KAFKA_BROKERS);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/consumers/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./tokenPriceConsumer"), exports);
|
|
18
|
+
__exportStar(require("./walletTransactionConsumer"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TokenPriceEvent } from '../types/TokenPriceEvent';
|
|
2
|
+
/**
|
|
3
|
+
* Start consuming token price updates.
|
|
4
|
+
* @param groupId - unique consumer group ID (e.g., 'limit-orders' or 'ai-engine')
|
|
5
|
+
* @param handler - function that processes each TokenPriceEvent
|
|
6
|
+
*/
|
|
7
|
+
export declare function startTokenPriceConsumer(groupId: string, handler: (event: TokenPriceEvent) => Promise<void> | void): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=tokenPriceConsumer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenPriceConsumer.d.ts","sourceRoot":"","sources":["../../src/consumers/tokenPriceConsumer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAEhE;;;;GAIG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,iBAkB1D"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startTokenPriceConsumer = startTokenPriceConsumer;
|
|
4
|
+
const kafka_1 = require("../config/kafka");
|
|
5
|
+
const topics_1 = require("../topics");
|
|
6
|
+
/**
|
|
7
|
+
* Start consuming token price updates.
|
|
8
|
+
* @param groupId - unique consumer group ID (e.g., 'limit-orders' or 'ai-engine')
|
|
9
|
+
* @param handler - function that processes each TokenPriceEvent
|
|
10
|
+
*/
|
|
11
|
+
async function startTokenPriceConsumer(groupId, handler) {
|
|
12
|
+
const consumer = kafka_1.kafka.consumer({ groupId });
|
|
13
|
+
await consumer.connect();
|
|
14
|
+
await consumer.subscribe({
|
|
15
|
+
topic: topics_1.TOPICS.TOKEN_PRICES,
|
|
16
|
+
fromBeginning: false,
|
|
17
|
+
});
|
|
18
|
+
await consumer.run({
|
|
19
|
+
eachMessage: async ({ message }) => {
|
|
20
|
+
if (!message.value)
|
|
21
|
+
return;
|
|
22
|
+
const event = JSON.parse(message.value.toString());
|
|
23
|
+
await handler(event);
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
console.log(`📡 Listening for token price updates (group: ${groupId})`);
|
|
27
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { WalletTransactionEvent } from '../types/WalletTransactionEvent';
|
|
2
|
+
/**
|
|
3
|
+
* Start consuming wallet transaction events.
|
|
4
|
+
* @param groupId - unique consumer group ID (e.g., 'analytics' or 'wallet-tracker')
|
|
5
|
+
* @param handler - function that processes each WalletTransactionEvent
|
|
6
|
+
*/
|
|
7
|
+
export declare function startWalletTransactionConsumer(groupId: string, handler: (event: WalletTransactionEvent) => Promise<void> | void): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=walletTransactionConsumer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walletTransactionConsumer.d.ts","sourceRoot":"","sources":["../../src/consumers/walletTransactionConsumer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAE9E;;;;GAIG;AACH,wBAAsB,8BAA8B,CAClD,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,iBAoBjE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startWalletTransactionConsumer = startWalletTransactionConsumer;
|
|
4
|
+
const kafka_1 = require("../config/kafka");
|
|
5
|
+
const topics_1 = require("../topics");
|
|
6
|
+
/**
|
|
7
|
+
* Start consuming wallet transaction events.
|
|
8
|
+
* @param groupId - unique consumer group ID (e.g., 'analytics' or 'wallet-tracker')
|
|
9
|
+
* @param handler - function that processes each WalletTransactionEvent
|
|
10
|
+
*/
|
|
11
|
+
async function startWalletTransactionConsumer(groupId, handler) {
|
|
12
|
+
const consumer = kafka_1.kafka.consumer({ groupId });
|
|
13
|
+
await consumer.connect();
|
|
14
|
+
await consumer.subscribe({
|
|
15
|
+
topic: topics_1.TOPICS.WALLET_TRANSACTIONS,
|
|
16
|
+
fromBeginning: false,
|
|
17
|
+
});
|
|
18
|
+
await consumer.run({
|
|
19
|
+
eachMessage: async ({ message }) => {
|
|
20
|
+
if (!message.value)
|
|
21
|
+
return;
|
|
22
|
+
const event = JSON.parse(message.value.toString());
|
|
23
|
+
await handler(event);
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
console.log(`📡 Listening for wallet transactions (group: ${groupId})`);
|
|
27
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './config/kafka';
|
|
2
|
+
export * from './topics';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export * from './validation/tokenPriceEvent.schema';
|
|
5
|
+
export * from './validation/walletTransactionEvent.schema';
|
|
6
|
+
export * from './producers/tokenPriceProducer';
|
|
7
|
+
export * from './producers/walletTransactionProducer';
|
|
8
|
+
export * from './consumers/tokenPriceConsumer';
|
|
9
|
+
export * from './consumers/walletTransactionConsumer';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,qCAAqC,CAAC;AACpD,cAAc,4CAA4C,CAAC;AAE3D,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uCAAuC,CAAC;AAEtD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uCAAuC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./config/kafka"), exports);
|
|
18
|
+
__exportStar(require("./topics"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
20
|
+
__exportStar(require("./validation/tokenPriceEvent.schema"), exports);
|
|
21
|
+
__exportStar(require("./validation/walletTransactionEvent.schema"), exports);
|
|
22
|
+
__exportStar(require("./producers/tokenPriceProducer"), exports);
|
|
23
|
+
__exportStar(require("./producers/walletTransactionProducer"), exports);
|
|
24
|
+
__exportStar(require("./consumers/tokenPriceConsumer"), exports);
|
|
25
|
+
__exportStar(require("./consumers/walletTransactionConsumer"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/producers/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./tokenPriceProducer"), exports);
|
|
18
|
+
__exportStar(require("./walletTransactionProducer"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenPriceProducer.d.ts","sourceRoot":"","sources":["../../src/producers/tokenPriceProducer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAWlC,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,eAAe,iBAwB7D"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.produceTokenPrice = produceTokenPrice;
|
|
4
|
+
const kafka_1 = require("../config/kafka");
|
|
5
|
+
const topics_1 = require("../topics");
|
|
6
|
+
function normalizePriceMap(price) {
|
|
7
|
+
if (price instanceof Map) {
|
|
8
|
+
return Object.fromEntries(price.entries());
|
|
9
|
+
}
|
|
10
|
+
return price;
|
|
11
|
+
}
|
|
12
|
+
async function produceTokenPrice(event) {
|
|
13
|
+
const producer = kafka_1.kafka.producer();
|
|
14
|
+
await producer.connect();
|
|
15
|
+
const key = `${event.chainId}:${event.tokenAddress}`;
|
|
16
|
+
const serializedEvent = {
|
|
17
|
+
...event,
|
|
18
|
+
price: normalizePriceMap(event.price),
|
|
19
|
+
};
|
|
20
|
+
await producer.send({
|
|
21
|
+
topic: topics_1.TOPICS.TOKEN_PRICES,
|
|
22
|
+
messages: [
|
|
23
|
+
{
|
|
24
|
+
key,
|
|
25
|
+
value: JSON.stringify(serializedEvent),
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
await producer.disconnect();
|
|
30
|
+
console.log(`✅ Sent token price update for ${event.symbol ?? event.tokenAddress} (chain ${event.chainId})`);
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walletTransactionProducer.d.ts","sourceRoot":"","sources":["../../src/producers/walletTransactionProducer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAE9E,wBAAsB,wBAAwB,CAAC,KAAK,EAAE,sBAAsB,iBAoB3E"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.produceWalletTransaction = produceWalletTransaction;
|
|
4
|
+
const kafka_1 = require("../config/kafka");
|
|
5
|
+
const topics_1 = require("../topics");
|
|
6
|
+
async function produceWalletTransaction(event) {
|
|
7
|
+
const producer = kafka_1.kafka.producer();
|
|
8
|
+
await producer.connect();
|
|
9
|
+
const key = `${event.chainId}:${event.walletAddress}`;
|
|
10
|
+
await producer.send({
|
|
11
|
+
topic: topics_1.TOPICS.WALLET_TRANSACTIONS,
|
|
12
|
+
messages: [
|
|
13
|
+
{
|
|
14
|
+
key,
|
|
15
|
+
value: JSON.stringify(event),
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
await producer.disconnect();
|
|
20
|
+
console.log(`✅ Sent wallet transaction for ${event.walletAddress} (${event.type})`);
|
|
21
|
+
}
|
package/dist/topics.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"topics.d.ts","sourceRoot":"","sources":["../src/topics.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;CAGT,CAAC;AAEX,MAAM,MAAM,KAAK,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC"}
|
package/dist/topics.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type PriceInfo = {
|
|
2
|
+
price: number;
|
|
3
|
+
exchange: string;
|
|
4
|
+
liquidity: number;
|
|
5
|
+
};
|
|
6
|
+
export interface TokenPriceEvent {
|
|
7
|
+
chainId: number;
|
|
8
|
+
tokenAddress: string;
|
|
9
|
+
blockNumber: number;
|
|
10
|
+
price: Record<string, PriceInfo> | Map<string, PriceInfo>;
|
|
11
|
+
marketcap?: number | null;
|
|
12
|
+
symbol?: string | null;
|
|
13
|
+
updatedAt?: number;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=TokenPriceEvent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenPriceEvent.d.ts","sourceRoot":"","sources":["../../src/types/TokenPriceEvent.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IAEpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC1D,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface WalletTransactionEvent {
|
|
2
|
+
chainId: number;
|
|
3
|
+
walletAddress: string;
|
|
4
|
+
type: string;
|
|
5
|
+
pool?: string | null;
|
|
6
|
+
txHash: string;
|
|
7
|
+
baseAmount: string;
|
|
8
|
+
quoteAmount: string;
|
|
9
|
+
baseTokenAddress: string;
|
|
10
|
+
baseTokenSymbol: string;
|
|
11
|
+
quoteTokenAddress: string;
|
|
12
|
+
quoteTokenSymbol: string;
|
|
13
|
+
blockTimestamp: number;
|
|
14
|
+
liquidity?: number | null;
|
|
15
|
+
marketcap?: number | null;
|
|
16
|
+
totalSupply?: number | null;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=WalletTransactionEvent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WalletTransactionEvent.d.ts","sourceRoot":"","sources":["../../src/types/WalletTransactionEvent.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IAEf,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IAEvB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./TokenPriceEvent"), exports);
|
|
18
|
+
__exportStar(require("./WalletTransactionEvent"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const chainIdSchema: z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>]>, z.ZodTransform<number, number>>, z.ZodNumber>;
|
|
3
|
+
export declare const addressSchema: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
4
|
+
export declare const txHashSchema: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
5
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/validation/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,eAAO,MAAM,aAAa,+JAEM,CAAC;AAEjC,eAAO,MAAM,aAAa,wDAGkB,CAAC;AAE7C,eAAO,MAAM,YAAY,wDAGmB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.txHashSchema = exports.addressSchema = exports.chainIdSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const HEX_ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/;
|
|
6
|
+
const TX_HASH_REGEX = /^0x[a-fA-F0-9]{64}$/;
|
|
7
|
+
const numericChainIdInput = zod_1.z.union([
|
|
8
|
+
zod_1.z.number().int(),
|
|
9
|
+
zod_1.z
|
|
10
|
+
.string()
|
|
11
|
+
.regex(/^-?\d+$/)
|
|
12
|
+
.transform((value) => Number(value)),
|
|
13
|
+
]);
|
|
14
|
+
exports.chainIdSchema = numericChainIdInput
|
|
15
|
+
.transform((value) => (typeof value === 'number' ? value : Number(value)))
|
|
16
|
+
.pipe(zod_1.z.number().int().min(0));
|
|
17
|
+
exports.addressSchema = zod_1.z
|
|
18
|
+
.string()
|
|
19
|
+
.refine((value) => HEX_ADDRESS_REGEX.test(value), { message: 'invalid_address' })
|
|
20
|
+
.transform((value) => value.toLowerCase());
|
|
21
|
+
exports.txHashSchema = zod_1.z
|
|
22
|
+
.string()
|
|
23
|
+
.refine((value) => TX_HASH_REGEX.test(value), { message: 'invalid_tx_hash' })
|
|
24
|
+
.transform((value) => value.toLowerCase());
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const tokenPriceEventSchema: z.ZodObject<{
|
|
3
|
+
chainId: z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>]>, z.ZodTransform<number, number>>, z.ZodNumber>;
|
|
4
|
+
tokenAddress: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
5
|
+
blockNumber: z.ZodNumber;
|
|
6
|
+
price: z.ZodPipe<z.ZodTransform<{}, unknown>, z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
7
|
+
price: z.ZodNumber;
|
|
8
|
+
exchange: z.ZodString;
|
|
9
|
+
liquidity: z.ZodNumber;
|
|
10
|
+
}, z.core.$strip>>>>;
|
|
11
|
+
marketcap: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
12
|
+
symbol: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
13
|
+
updatedAt: z.ZodOptional<z.ZodNumber>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
export type TokenPriceEventSchema = z.infer<typeof tokenPriceEventSchema>;
|
|
16
|
+
export declare function ensureTokenPriceEvent(input: unknown): TokenPriceEventSchema;
|
|
17
|
+
//# sourceMappingURL=tokenPriceEvent.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenPriceEvent.schema.d.ts","sourceRoot":"","sources":["../../src/validation/tokenPriceEvent.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAuCxB,eAAO,MAAM,qBAAqB;;;;;;;;;;;;iBAQhC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAE1E,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,qBAAqB,CAE3E"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tokenPriceEventSchema = void 0;
|
|
4
|
+
exports.ensureTokenPriceEvent = ensureTokenPriceEvent;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const common_1 = require("./common");
|
|
7
|
+
const priceEntrySchema = zod_1.z.object({
|
|
8
|
+
price: zod_1.z.number().finite(),
|
|
9
|
+
exchange: zod_1.z.string().min(1),
|
|
10
|
+
liquidity: zod_1.z.number().finite(),
|
|
11
|
+
});
|
|
12
|
+
const priceRecordSchema = zod_1.z.preprocess((value) => {
|
|
13
|
+
if (value instanceof Map) {
|
|
14
|
+
const normalized = {};
|
|
15
|
+
for (const [key, entry] of value.entries()) {
|
|
16
|
+
if (typeof key !== 'string') {
|
|
17
|
+
throw new Error(`Invalid price key type: expected string, got ${typeof key}`);
|
|
18
|
+
}
|
|
19
|
+
if (typeof entry === 'object' && entry !== null && 'price' in entry && 'exchange' in entry && 'liquidity' in entry) {
|
|
20
|
+
normalized[key] = {
|
|
21
|
+
price: Number(entry.price),
|
|
22
|
+
exchange: String(entry.exchange),
|
|
23
|
+
liquidity: Number(entry.liquidity),
|
|
24
|
+
};
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`Invalid price entry for key "${key}": expected { price, exchange, liquidity }`);
|
|
28
|
+
}
|
|
29
|
+
return normalized;
|
|
30
|
+
}
|
|
31
|
+
if (value === undefined || value === null) {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
}, zod_1.z.record(zod_1.z.string(), priceEntrySchema).default({}));
|
|
36
|
+
exports.tokenPriceEventSchema = zod_1.z.object({
|
|
37
|
+
chainId: common_1.chainIdSchema,
|
|
38
|
+
tokenAddress: common_1.addressSchema,
|
|
39
|
+
blockNumber: zod_1.z.number().int().min(0),
|
|
40
|
+
price: priceRecordSchema,
|
|
41
|
+
marketcap: zod_1.z.number().nullable().optional(),
|
|
42
|
+
symbol: zod_1.z.string().nullable().optional(),
|
|
43
|
+
updatedAt: zod_1.z.number().int().min(0).optional(),
|
|
44
|
+
});
|
|
45
|
+
function ensureTokenPriceEvent(input) {
|
|
46
|
+
return exports.tokenPriceEventSchema.parse(input);
|
|
47
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const walletTransactionEventSchema: z.ZodObject<{
|
|
3
|
+
chainId: z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>]>, z.ZodTransform<number, number>>, z.ZodNumber>;
|
|
4
|
+
walletAddress: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
5
|
+
type: z.ZodString;
|
|
6
|
+
pool: z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>>;
|
|
7
|
+
txHash: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
8
|
+
baseAmount: z.ZodString;
|
|
9
|
+
quoteAmount: z.ZodString;
|
|
10
|
+
baseTokenAddress: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
11
|
+
baseTokenSymbol: z.ZodString;
|
|
12
|
+
quoteTokenAddress: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
13
|
+
quoteTokenSymbol: z.ZodString;
|
|
14
|
+
blockTimestamp: z.ZodNumber;
|
|
15
|
+
liquidity: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
16
|
+
marketcap: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
17
|
+
totalSupply: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
export type WalletTransactionEventSchema = z.infer<typeof walletTransactionEventSchema>;
|
|
20
|
+
export declare function ensureWalletTransactionEvent(input: unknown): WalletTransactionEventSchema;
|
|
21
|
+
//# sourceMappingURL=walletTransactionEvent.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walletTransactionEvent.schema.d.ts","sourceRoot":"","sources":["../../src/validation/walletTransactionEvent.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;iBAkBvC,CAAC;AAEH,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAExF,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,OAAO,GAAG,4BAA4B,CAEzF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.walletTransactionEventSchema = void 0;
|
|
4
|
+
exports.ensureWalletTransactionEvent = ensureWalletTransactionEvent;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const common_1 = require("./common");
|
|
7
|
+
exports.walletTransactionEventSchema = zod_1.z.object({
|
|
8
|
+
chainId: common_1.chainIdSchema,
|
|
9
|
+
walletAddress: common_1.addressSchema,
|
|
10
|
+
type: zod_1.z.string().min(1),
|
|
11
|
+
pool: common_1.addressSchema.nullable().optional(),
|
|
12
|
+
txHash: common_1.txHashSchema,
|
|
13
|
+
baseAmount: zod_1.z.string(),
|
|
14
|
+
quoteAmount: zod_1.z.string(),
|
|
15
|
+
baseTokenAddress: common_1.addressSchema,
|
|
16
|
+
baseTokenSymbol: zod_1.z.string(),
|
|
17
|
+
quoteTokenAddress: common_1.addressSchema,
|
|
18
|
+
quoteTokenSymbol: zod_1.z.string(),
|
|
19
|
+
blockTimestamp: zod_1.z.number().int().positive(),
|
|
20
|
+
liquidity: zod_1.z.number().nullable().optional(),
|
|
21
|
+
marketcap: zod_1.z.number().nullable().optional(),
|
|
22
|
+
totalSupply: zod_1.z.number().nullable().optional(),
|
|
23
|
+
});
|
|
24
|
+
function ensureWalletTransactionEvent(input) {
|
|
25
|
+
return exports.walletTransactionEventSchema.parse(input);
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axxel/event-bus",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Axxel Kafka Event Bus SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
14
|
"dev": "tsx example/demo.ts",
|
|
15
|
-
"build": "tsc",
|
|
15
|
+
"build": "tsc -p tsconfig.build.json",
|
|
16
16
|
"start": "node dist/index.js",
|
|
17
17
|
"lint": "eslint . --ext .ts",
|
|
18
18
|
"format": "prettier --write .",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"license": "ISC",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"dotenv": "^17.2.3",
|
|
30
|
-
"kafkajs": "^2.2.4"
|
|
30
|
+
"kafkajs": "^2.2.4",
|
|
31
|
+
"zod": "^4.1.12"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"@types/node": "^24.9.2",
|