@levrbet/shared 0.3.17 → 0.3.18
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/core/config/urls.js +9 -9
- package/dist/core/config/urls.js.map +1 -1
- package/dist/server/config/kms.js +1 -1
- package/dist/server/config/redis.d.ts +22 -17
- package/dist/server/config/redis.js +30 -33
- package/dist/server/config/redis.js.map +1 -1
- package/dist/server/middleware/rateLimit.middleware.d.ts +2 -1
- package/dist/server/middleware/rateLimit.middleware.js +19 -9
- package/dist/server/middleware/rateLimit.middleware.js.map +1 -1
- package/package.json +5 -6
package/dist/core/config/urls.js
CHANGED
|
@@ -57,15 +57,15 @@ exports.allUrls = {
|
|
|
57
57
|
},
|
|
58
58
|
},
|
|
59
59
|
[types_1.LevrEnv.PROD]: {
|
|
60
|
-
auth: "https://auth
|
|
61
|
-
oracleCore: "https://oracle-core.levr.bet",
|
|
62
|
-
oraclePeriphery: "https://oracle-periphery.levr.bet",
|
|
63
|
-
oracleProcessors: "https://oracle-processor.levr.bet",
|
|
64
|
-
relayer: "https://relayers.levr.bet",
|
|
65
|
-
referrals: "https://referrals.levr.bet",
|
|
66
|
-
lambda: "https://lambda.levr.bet",
|
|
67
|
-
liquidationEngine: "https://liquidation-engine.levr.bet",
|
|
68
|
-
leaderboard: "https://leaderboard.levr.bet",
|
|
60
|
+
auth: "https://auth.api.levr.bet",
|
|
61
|
+
oracleCore: "https://oracle-core.api.levr.bet",
|
|
62
|
+
oraclePeriphery: "https://oracle-periphery.api.levr.bet",
|
|
63
|
+
oracleProcessors: "https://oracle-processor.api.levr.bet",
|
|
64
|
+
relayer: "https://relayers.api.levr.bet",
|
|
65
|
+
referrals: "https://referrals.api.levr.bet",
|
|
66
|
+
lambda: "https://lambda.api.levr.bet",
|
|
67
|
+
liquidationEngine: "https://liquidation-engine.api.levr.bet",
|
|
68
|
+
leaderboard: "https://leaderboard.api.levr.bet",
|
|
69
69
|
indexers: {
|
|
70
70
|
[types_1.LevrChain.MONAD_TESTNET]: [
|
|
71
71
|
{ type: indexers_types_1.LevrIndexer.ENVIO, url: "https://indexer.levr.app" },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urls.js","sourceRoot":"","sources":["../../../src/core/config/urls.ts"],"names":[],"mappings":";;;AAAA,oCAA6C;AAC7C,4DAAqD;AAErD,sBAAsB;AAET,QAAA,OAAO,GAAG;IACnB,CAAC,eAAO,CAAC,KAAK,CAAC,EAAE;QACb,IAAI,EAAE,+BAA+B;QACrC,UAAU,EAAE,kCAAkC;QAC9C,eAAe,EAAE,uCAAuC;QACxD,gBAAgB,EAAE,uCAAuC;QACzD,OAAO,EAAE,+BAA+B;QACxC,SAAS,EAAE,gCAAgC;QAC3C,MAAM,EAAE,6BAA6B;QACrC,iBAAiB,EAAE,yCAAyC;QAC5D,WAAW,EAAE,kCAAkC;QAC/C,QAAQ,EAAE;YACN,CAAC,iBAAS,CAAC,aAAa,CAAC,EAAE;gBACvB,EAAE,IAAI,EAAE,4BAAW,CAAC,KAAK,EAAE,GAAG,EAAE,uDAAuD,EAAE;gBACzF,EAAE,IAAI,EAAE,4BAAW,CAAC,QAAQ,EAAE,GAAG,EAAE,wDAAwD,EAAE;aAChG;SACJ;KACJ;IACD,CAAC,eAAO,CAAC,GAAG,CAAC,EAAE;QACX,IAAI,EAAE,+BAA+B;QACrC,UAAU,EAAE,kCAAkC;QAC9C,eAAe,EAAE,uCAAuC;QACxD,gBAAgB,EAAE,uCAAuC;QACzD,OAAO,EAAE,+BAA+B,EAAE,wEAAwE;QAClH,SAAS,EAAE,gCAAgC;QAC3C,MAAM,EAAE,6BAA6B;QACrC,iBAAiB,EAAE,yCAAyC;QAC5D,WAAW,EAAE,kCAAkC;QAC/C,QAAQ,EAAE;YACN,CAAC,iBAAS,CAAC,aAAa,CAAC,EAAE;gBACvB,EAAE,IAAI,EAAE,4BAAW,CAAC,KAAK,EAAE,GAAG,EAAE,uDAAuD,EAAE;gB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AC,EAAE;QACZ,IAAI,EAAE,2BAA2B;QACjC,UAAU,EAAE,kCAAkC;QAC9C,eAAe,EAAE,uCAAuC;QACxD,gBAAgB,EAAE,uCAAuC;QACzD,OAAO,EAAE,+BAA+B;QACxC,SAAS,EAAE,gCAAgC;QAC3C,MAAM,EAAE,6BAA6B;QACrC,iBAAiB,EAAE,yCAAyC;QAC5D,WAAW,EAAE,kCAAkC;QAC/C,QAAQ,EAAE;YACN,CAAC,iBAAS,CAAC,aAAa,CAAC,EAAE;gBACvB,EAAE,IAAI,EAAE,4BAAW,CAAC,KAAK,EAAE,GAAG,EAAE,0BAA0B,EAAE;gBAC5D,EAAE,IAAI,EAAE,4BAAW,CAAC,QAAQ,EAAE,GAAG,EAAE,0BAA0B,EAAE;aAClE;SACJ;KACJ;CACJ,CAAA"}
|
|
@@ -16,7 +16,7 @@ class KmsClientManager {
|
|
|
16
16
|
[core_1.LevrEnv.LOCAL]: "b6050d0f-be5b-418c-9056-c53c1d982dec",
|
|
17
17
|
[core_1.LevrEnv.DEV]: "b6050d0f-be5b-418c-9056-c53c1d982dec",
|
|
18
18
|
[core_1.LevrEnv.STAGING]: "28bef5bc-1af9-464c-9192-f31c80de0951",
|
|
19
|
-
[core_1.LevrEnv.PROD]: "
|
|
19
|
+
[core_1.LevrEnv.PROD]: "d6d7a6ff-7245-4aeb-b9df-87cdf01bcf15",
|
|
20
20
|
};
|
|
21
21
|
this.KeyId = this.kmsKeyIds[dotenv_1.LEVR_ENV];
|
|
22
22
|
}
|
|
@@ -5,30 +5,39 @@ import Redis, { type RedisOptions } from "ioredis";
|
|
|
5
5
|
* Use this type when accepting a Redis client as a parameter in functions.
|
|
6
6
|
*/
|
|
7
7
|
export type RedisClient = Redis;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Redis namespace prefixes for different services.
|
|
10
|
+
* Used to isolate keys in a single Redis database (required for Redis Cloud which only supports DB 0).
|
|
11
|
+
*/
|
|
12
|
+
export declare enum RedisNamespace {
|
|
13
|
+
ORACLE = "oracle:",
|
|
14
|
+
ORDERBOOK = "orderbook:",
|
|
15
|
+
AUTH = "auth:",
|
|
16
|
+
LIQUIDATION_ENGINE = "liquidation:",
|
|
17
|
+
LEADERBOARD = "leaderboard:",
|
|
18
|
+
LAB = "lab:"
|
|
19
|
+
}
|
|
20
|
+
export interface RedisClientManagerOptions extends RedisOptions {
|
|
21
|
+
/** Key prefix namespace for this service */
|
|
22
|
+
namespace?: RedisNamespace;
|
|
15
23
|
}
|
|
16
24
|
/**
|
|
17
25
|
* Manages Redis client connections including a primary client and optional replica clients.
|
|
18
26
|
*
|
|
19
27
|
* This manager provides a singleton-like pattern for initializing and accessing Redis clients.
|
|
20
28
|
* It supports both primary and replica connections for load balancing read operations.
|
|
29
|
+
* Uses key prefixes (namespaces) to isolate data between services.
|
|
21
30
|
*
|
|
22
31
|
* **Note:** Not all services that use this package require Redis, so initialization is opt-in.
|
|
23
32
|
* Call `init()` explicitly before using any Redis clients.
|
|
24
33
|
*
|
|
25
34
|
* @example
|
|
26
35
|
* ```typescript
|
|
27
|
-
* redisClientManager.init({
|
|
36
|
+
* redisClientManager.init({ namespace: RedisNamespace.ORACLE });
|
|
28
37
|
*
|
|
29
38
|
* // Get primary client for write operations
|
|
30
39
|
* const primary = redisClientManager.primaryClient;
|
|
31
|
-
* await primary.set('key', 'value');
|
|
40
|
+
* await primary.set('key', 'value'); // Stored as 'oracle:key'
|
|
32
41
|
*
|
|
33
42
|
* // Get replica client for read operations (load balanced)
|
|
34
43
|
* const replica = redisClientManager.replicaClient;
|
|
@@ -39,21 +48,17 @@ declare class RedisClientManager {
|
|
|
39
48
|
private _primaryClient;
|
|
40
49
|
private replicaClients;
|
|
41
50
|
private initialized;
|
|
42
|
-
private
|
|
51
|
+
private keyPrefix;
|
|
43
52
|
/**
|
|
44
53
|
* Initializes the Redis client manager with primary and optional replica clients.
|
|
45
54
|
*
|
|
46
|
-
*
|
|
47
|
-
* Call this method explicitly before using any Redis clients to avoid initialization errors.
|
|
48
|
-
*
|
|
49
|
-
* @param options - Optional Redis configuration options including database index selection
|
|
55
|
+
* @param options - Configuration options including namespace for key prefixing
|
|
50
56
|
* @example
|
|
51
57
|
* ```typescript
|
|
52
|
-
*
|
|
53
|
-
* redisClientManager.init({ db: RedisDb.AUTH });
|
|
58
|
+
* redisClientManager.init({ namespace: RedisNamespace.AUTH });
|
|
54
59
|
* ```
|
|
55
60
|
*/
|
|
56
|
-
init(options?:
|
|
61
|
+
init(options?: RedisClientManagerOptions): void;
|
|
57
62
|
get primaryClient(): Redis;
|
|
58
63
|
get replicaClient(): Redis;
|
|
59
64
|
duplicateClient: (clientName: string) => Redis;
|
|
@@ -3,38 +3,43 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.redisClientManager = exports.
|
|
6
|
+
exports.redisClientManager = exports.RedisNamespace = void 0;
|
|
7
7
|
require("dotenv/config");
|
|
8
8
|
const ioredis_1 = __importDefault(require("ioredis"));
|
|
9
|
-
const core_1 = require("../../core");
|
|
10
9
|
const _1 = require(".");
|
|
10
|
+
const core_1 = require("../../core");
|
|
11
11
|
const dotenv_1 = require("./dotenv");
|
|
12
12
|
const winston_1 = __importDefault(require("./winston"));
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Redis namespace prefixes for different services.
|
|
15
|
+
* Used to isolate keys in a single Redis database (required for Redis Cloud which only supports DB 0).
|
|
16
|
+
*/
|
|
17
|
+
var RedisNamespace;
|
|
18
|
+
(function (RedisNamespace) {
|
|
19
|
+
RedisNamespace["ORACLE"] = "oracle:";
|
|
20
|
+
RedisNamespace["ORDERBOOK"] = "orderbook:";
|
|
21
|
+
RedisNamespace["AUTH"] = "auth:";
|
|
22
|
+
RedisNamespace["LIQUIDATION_ENGINE"] = "liquidation:";
|
|
23
|
+
RedisNamespace["LEADERBOARD"] = "leaderboard:";
|
|
24
|
+
RedisNamespace["LAB"] = "lab:";
|
|
25
|
+
})(RedisNamespace || (exports.RedisNamespace = RedisNamespace = {}));
|
|
22
26
|
/**
|
|
23
27
|
* Manages Redis client connections including a primary client and optional replica clients.
|
|
24
28
|
*
|
|
25
29
|
* This manager provides a singleton-like pattern for initializing and accessing Redis clients.
|
|
26
30
|
* It supports both primary and replica connections for load balancing read operations.
|
|
31
|
+
* Uses key prefixes (namespaces) to isolate data between services.
|
|
27
32
|
*
|
|
28
33
|
* **Note:** Not all services that use this package require Redis, so initialization is opt-in.
|
|
29
34
|
* Call `init()` explicitly before using any Redis clients.
|
|
30
35
|
*
|
|
31
36
|
* @example
|
|
32
37
|
* ```typescript
|
|
33
|
-
* redisClientManager.init({
|
|
38
|
+
* redisClientManager.init({ namespace: RedisNamespace.ORACLE });
|
|
34
39
|
*
|
|
35
40
|
* // Get primary client for write operations
|
|
36
41
|
* const primary = redisClientManager.primaryClient;
|
|
37
|
-
* await primary.set('key', 'value');
|
|
42
|
+
* await primary.set('key', 'value'); // Stored as 'oracle:key'
|
|
38
43
|
*
|
|
39
44
|
* // Get replica client for read operations (load balanced)
|
|
40
45
|
* const replica = redisClientManager.replicaClient;
|
|
@@ -46,10 +51,9 @@ class RedisClientManager {
|
|
|
46
51
|
this._primaryClient = null;
|
|
47
52
|
this.replicaClients = [];
|
|
48
53
|
this.initialized = false;
|
|
49
|
-
this.
|
|
54
|
+
this.keyPrefix = "";
|
|
50
55
|
this.duplicateClient = (clientName) => {
|
|
51
56
|
const client = this.primaryClient.duplicate();
|
|
52
|
-
void client.select(this.dbIndex);
|
|
53
57
|
client.on("error", (err) => {
|
|
54
58
|
winston_1.default.error(`Redis ${clientName} client error:`, err);
|
|
55
59
|
});
|
|
@@ -62,14 +66,10 @@ class RedisClientManager {
|
|
|
62
66
|
/**
|
|
63
67
|
* Initializes the Redis client manager with primary and optional replica clients.
|
|
64
68
|
*
|
|
65
|
-
*
|
|
66
|
-
* Call this method explicitly before using any Redis clients to avoid initialization errors.
|
|
67
|
-
*
|
|
68
|
-
* @param options - Optional Redis configuration options including database index selection
|
|
69
|
+
* @param options - Configuration options including namespace for key prefixing
|
|
69
70
|
* @example
|
|
70
71
|
* ```typescript
|
|
71
|
-
*
|
|
72
|
-
* redisClientManager.init({ db: RedisDb.AUTH });
|
|
72
|
+
* redisClientManager.init({ namespace: RedisNamespace.AUTH });
|
|
73
73
|
* ```
|
|
74
74
|
*/
|
|
75
75
|
init(options) {
|
|
@@ -79,31 +79,30 @@ class RedisClientManager {
|
|
|
79
79
|
}
|
|
80
80
|
this.initialized = true;
|
|
81
81
|
const { REDIS_URL, REDIS_REPLICA_ENDPOINTS } = core_1.Config.init(_1.redisSchema);
|
|
82
|
-
|
|
82
|
+
if (options?.namespace) {
|
|
83
|
+
this.keyPrefix = options.namespace;
|
|
84
|
+
}
|
|
85
|
+
// Enable TLS for non-dev/local environments, but skip for local Redis URLs
|
|
83
86
|
const isLocalRedis = REDIS_URL.includes("localhost") || REDIS_URL.includes("redis://redis:");
|
|
84
87
|
const shouldUseTls = !isLocalRedis && dotenv_1.LEVR_ENV !== core_1.LevrEnv.DEV && dotenv_1.LEVR_ENV !== core_1.LevrEnv.LOCAL;
|
|
88
|
+
const { namespace: _ns, ...restOptions } = options || {};
|
|
85
89
|
const redisOptions = {
|
|
86
|
-
...
|
|
90
|
+
...restOptions,
|
|
91
|
+
keyPrefix: this.keyPrefix,
|
|
87
92
|
...(shouldUseTls && {
|
|
88
93
|
tls: {},
|
|
89
94
|
}),
|
|
90
95
|
};
|
|
91
|
-
if (options?.db)
|
|
92
|
-
this.dbIndex = options.db;
|
|
93
96
|
this._primaryClient = new ioredis_1.default(REDIS_URL, redisOptions);
|
|
94
|
-
if (options?.db)
|
|
95
|
-
void this._primaryClient.select(options.db);
|
|
96
97
|
this._primaryClient.on("error", (err) => {
|
|
97
98
|
winston_1.default.error("Redis primary client error:", err);
|
|
98
99
|
});
|
|
99
100
|
this._primaryClient.on("connect", () => {
|
|
100
|
-
winston_1.default.info(
|
|
101
|
+
winston_1.default.info(`Connected to Redis primary${this.keyPrefix ? ` with prefix '${this.keyPrefix}'` : ""}`);
|
|
101
102
|
});
|
|
102
103
|
const replicaEndpoints = REDIS_REPLICA_ENDPOINTS.split(",").filter(Boolean); // Comma-separated list of replica endpoints
|
|
103
104
|
this.replicaClients = replicaEndpoints.map((url) => {
|
|
104
105
|
const client = new ioredis_1.default(url, redisOptions);
|
|
105
|
-
if (options?.db)
|
|
106
|
-
void client.select(options.db);
|
|
107
106
|
client.on("error", (err) => {
|
|
108
107
|
winston_1.default.error(`Redis replica client error for ${client.options.host}:${client.options.port}:`, err);
|
|
109
108
|
});
|
|
@@ -122,9 +121,7 @@ class RedisClientManager {
|
|
|
122
121
|
if (!this.replicaClients.length)
|
|
123
122
|
return this.primaryClient;
|
|
124
123
|
const index = Math.floor(Math.random() * this.replicaClients.length);
|
|
125
|
-
|
|
126
|
-
client.select(this.dbIndex);
|
|
127
|
-
return client;
|
|
124
|
+
return this.replicaClients[index];
|
|
128
125
|
}
|
|
129
126
|
}
|
|
130
127
|
exports.redisClientManager = new RedisClientManager();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis.js","sourceRoot":"","sources":["../../../src/server/config/redis.ts"],"names":[],"mappings":";;;;;;AAAA,yBAAsB;AACtB,sDAAkD;AAClD,
|
|
1
|
+
{"version":3,"file":"redis.js","sourceRoot":"","sources":["../../../src/server/config/redis.ts"],"names":[],"mappings":";;;;;;AAAA,yBAAsB;AACtB,sDAAkD;AAClD,wBAA+B;AAC/B,qCAA4C;AAC5C,qCAAmC;AACnC,wDAA8B;AAQ9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vD,MAAM,MAAM,GAAG,IAAI,iBAAK,CAAC,GAAG,EAAE,YAAY,CAAC,CAAA;YAE3C,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;gBACvB,iBAAM,CAAC,KAAK,CAAC,kCAAkC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,GAAG,CAAC,CAAA;YACtG,CAAC,CAAC,CAAA;YACF,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;gBACtB,iBAAM,CAAC,IAAI,CAAC,iCAAiC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;YAC9F,CAAC,CAAC,CAAA;YAEF,OAAO,MAAM,CAAA;QACjB,CAAC,CAAC,CAAA;IACN,CAAC;IAED,IAAI,aAAa;QACb,IAAI,CAAC,IAAI,CAAC,cAAc;YAAE,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;QACtG,OAAO,IAAI,CAAC,cAAc,CAAA;IAC9B,CAAC;IAED,IAAI,aAAa;QACb,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC,aAAa,CAAA;QAE1D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;QACpE,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAE,CAAA;IACtC,CAAC;CAcJ;AAEY,QAAA,kBAAkB,GAAG,IAAI,kBAAkB,EAAE,CAAA"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { NextFunction, Request, Response } from "express";
|
|
2
|
+
export declare const rateLimiter: (requestsWindow: number, maxRequests: number) => (req: Request, res: Response, next: NextFunction) => unknown;
|
|
@@ -4,16 +4,26 @@ exports.rateLimiter = void 0;
|
|
|
4
4
|
const express_rate_limit_1 = require("express-rate-limit");
|
|
5
5
|
const rate_limit_redis_1 = require("rate-limit-redis");
|
|
6
6
|
const config_1 = require("../config");
|
|
7
|
+
let cachedLimiter = null;
|
|
8
|
+
let cachedConfig = null;
|
|
7
9
|
const rateLimiter = (requestsWindow, maxRequests) => {
|
|
8
|
-
return (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
return (req, res, next) => {
|
|
11
|
+
if (!cachedLimiter || cachedConfig?.requestsWindow !== requestsWindow || cachedConfig?.maxRequests !== maxRequests) {
|
|
12
|
+
cachedConfig = { requestsWindow, maxRequests };
|
|
13
|
+
cachedLimiter = (0, express_rate_limit_1.rateLimit)({
|
|
14
|
+
windowMs: requestsWindow,
|
|
15
|
+
max: maxRequests,
|
|
16
|
+
standardHeaders: true,
|
|
17
|
+
legacyHeaders: false,
|
|
18
|
+
store: new rate_limit_redis_1.RedisStore({
|
|
19
|
+
sendCommand: (command, ...args) => {
|
|
20
|
+
return config_1.redisClientManager.primaryClient.call(command, ...args);
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return cachedLimiter(req, res, next);
|
|
26
|
+
};
|
|
17
27
|
};
|
|
18
28
|
exports.rateLimiter = rateLimiter;
|
|
19
29
|
//# sourceMappingURL=rateLimit.middleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rateLimit.middleware.js","sourceRoot":"","sources":["../../../src/server/middleware/rateLimit.middleware.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"rateLimit.middleware.js","sourceRoot":"","sources":["../../../src/server/middleware/rateLimit.middleware.ts"],"names":[],"mappings":";;;AACA,2DAAuE;AACvE,uDAAyD;AACzD,sCAA8C;AAE9C,IAAI,aAAa,GAAmC,IAAI,CAAA;AACxD,IAAI,YAAY,GAA2D,IAAI,CAAA;AAExE,MAAM,WAAW,GAAG,CAAC,cAAsB,EAAE,WAAmB,EAAE,EAAE;IACvE,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QACvD,IAAI,CAAC,aAAa,IAAI,YAAY,EAAE,cAAc,KAAK,cAAc,IAAI,YAAY,EAAE,WAAW,KAAK,WAAW,EAAE,CAAC;YACjH,YAAY,GAAG,EAAE,cAAc,EAAE,WAAW,EAAE,CAAA;YAC9C,aAAa,GAAG,IAAA,8BAAS,EAAC;gBACtB,QAAQ,EAAE,cAAc;gBACxB,GAAG,EAAE,WAAW;gBAChB,eAAe,EAAE,IAAI;gBACrB,aAAa,EAAE,KAAK;gBACpB,KAAK,EAAE,IAAI,6BAAU,CAAC;oBAClB,WAAW,EAAE,CAAC,OAAe,EAAE,GAAG,IAAc,EAAE,EAAE;wBAChD,OAAO,2BAAkB,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAwB,CAAA;oBACzF,CAAC;iBACJ,CAAC;aACL,CAAC,CAAA;QACN,CAAC;QACD,OAAO,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;IACxC,CAAC,CAAA;AACL,CAAC,CAAA;AAlBY,QAAA,WAAW,eAkBvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@levrbet/shared",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.18",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"scripts"
|
|
32
32
|
],
|
|
33
33
|
"bin": {
|
|
34
|
-
"levrbet-prisma-setup": "scripts/setup-prisma.js"
|
|
34
|
+
"levrbet-prisma-setup": "./scripts/setup-prisma.js"
|
|
35
35
|
},
|
|
36
36
|
"sideEffects": false,
|
|
37
37
|
"scripts": {
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@biomejs/biome": "2.3.10",
|
|
69
|
-
"@prisma/client": "^6.
|
|
69
|
+
"@prisma/client": "^6.0.0",
|
|
70
70
|
"@privy-io/react-auth": ">=3.0.0",
|
|
71
71
|
"@swc-node/register": "^1.11.1",
|
|
72
72
|
"@tanstack/react-query": ">=5.0.0",
|
|
@@ -89,7 +89,6 @@
|
|
|
89
89
|
"@aws-sdk/client-s3": "^3.926.0",
|
|
90
90
|
"@aws-sdk/client-sts": "^3.913.0",
|
|
91
91
|
"@aws-sdk/s3-request-presigner": "^3.926.0",
|
|
92
|
-
"@levrbet/shared": "^0.2.77",
|
|
93
92
|
"@opentelemetry/api": "^1.9.0",
|
|
94
93
|
"@opentelemetry/auto-instrumentations-node": "0.65.0",
|
|
95
94
|
"@opentelemetry/exporter-metrics-otlp-http": "^0.206.0",
|
|
@@ -98,6 +97,7 @@
|
|
|
98
97
|
"@opentelemetry/sdk-metrics": "^2.1.0",
|
|
99
98
|
"@opentelemetry/sdk-node": "^0.206.0",
|
|
100
99
|
"@openzeppelin/relayer-sdk": "^1.6.0",
|
|
100
|
+
"@prisma/client": "^6.0.0",
|
|
101
101
|
"@privy-io/node": "^0.3.0",
|
|
102
102
|
"@types/amqplib": "^0.10.7",
|
|
103
103
|
"amqplib": "^0.10.9",
|
|
@@ -121,8 +121,7 @@
|
|
|
121
121
|
"typescript-memoize": "^1.1.1",
|
|
122
122
|
"viem": "2.38.3",
|
|
123
123
|
"winston": "3.18.3",
|
|
124
|
-
"zod": "^4.1.12"
|
|
125
|
-
"@prisma/client": "^6.0.0"
|
|
124
|
+
"zod": "^4.1.12"
|
|
126
125
|
},
|
|
127
126
|
"publishConfig": {
|
|
128
127
|
"access": "public"
|