@tradejs/infra 1.0.5 → 1.0.8

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.
@@ -0,0 +1,70 @@
1
+ import {
2
+ getData,
3
+ redisKeys,
4
+ setData
5
+ } from "./chunk-DSTV67R5.mjs";
6
+ import {
7
+ DEFAULT_AI_RESPONSE_LANGUAGE,
8
+ normalizeAiResponseLanguage
9
+ } from "./chunk-CCC7DX2T.mjs";
10
+ import {
11
+ normalizeAiModel
12
+ } from "./chunk-DTCLZIBM.mjs";
13
+ import {
14
+ normalizeAiEndpoint
15
+ } from "./chunk-XQ3YBULV.mjs";
16
+
17
+ // src/userSettings.ts
18
+ var readString = (value) => typeof value === "string" ? value.trim() : "";
19
+ var readUserString = (record, key) => readString(record?.[key]);
20
+ var getUserRecord = async (userName) => {
21
+ const user = await getData(redisKeys.user(userName), null);
22
+ if (!user || typeof user !== "object") {
23
+ return null;
24
+ }
25
+ return user;
26
+ };
27
+ var getUserSettings = async (userName) => {
28
+ const record = await getUserRecord(userName);
29
+ const aiApiEndpoint = normalizeAiEndpoint(
30
+ readUserString(record, "AI_API_ENDPOINT")
31
+ );
32
+ return {
33
+ userName,
34
+ BYBIT_API_KEY: readUserString(record, "BYBIT_API_KEY"),
35
+ BYBIT_API_SECRET: readUserString(record, "BYBIT_API_SECRET"),
36
+ COINALYZE_API_KEY: readUserString(record, "COINALYZE_API_KEY"),
37
+ AI_API_KEY: readUserString(record, "AI_API_KEY"),
38
+ AI_API_ENDPOINT: aiApiEndpoint,
39
+ AI_MODEL: normalizeAiModel(
40
+ readUserString(record, "AI_MODEL"),
41
+ aiApiEndpoint
42
+ ),
43
+ AI_RESPONSE_LANGUAGE: normalizeAiResponseLanguage(
44
+ readUserString(record, "AI_RESPONSE_LANGUAGE")
45
+ ) || DEFAULT_AI_RESPONSE_LANGUAGE,
46
+ TG_BOT_TOKEN: readUserString(record, "TG_BOT_TOKEN"),
47
+ TG_CHAT_ID: readUserString(record, "TG_CHAT_ID")
48
+ };
49
+ };
50
+ var updateUserRecord = async (userName, patch) => {
51
+ const existing = await getUserRecord(userName) ?? {};
52
+ const merged = {
53
+ ...existing,
54
+ ...patch,
55
+ userName,
56
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
57
+ };
58
+ const next = Object.fromEntries(
59
+ Object.entries(merged).filter(([, value]) => value !== void 0)
60
+ );
61
+ await setData(redisKeys.user(userName), next, {
62
+ expire: 0
63
+ });
64
+ return next;
65
+ };
66
+ export {
67
+ getUserRecord,
68
+ getUserSettings,
69
+ updateUserRecord
70
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tradejs/infra",
3
- "version": "1.0.5",
3
+ "version": "1.0.8",
4
4
  "description": "Server-only infrastructure adapters for the TradeJS open-source framework: Redis, Timescale, ML, logging, and IO.",
5
5
  "keywords": [
6
6
  "tradejs",
@@ -24,6 +24,26 @@
24
24
  "proto"
25
25
  ],
26
26
  "exports": {
27
+ "./ai": {
28
+ "types": "./dist/ai.d.ts",
29
+ "import": "./dist/ai.mjs",
30
+ "require": "./dist/ai.js"
31
+ },
32
+ "./aiEndpoints": {
33
+ "types": "./dist/aiEndpoints.d.ts",
34
+ "import": "./dist/aiEndpoints.mjs",
35
+ "require": "./dist/aiEndpoints.js"
36
+ },
37
+ "./aiLanguages": {
38
+ "types": "./dist/aiLanguages.d.ts",
39
+ "import": "./dist/aiLanguages.mjs",
40
+ "require": "./dist/aiLanguages.js"
41
+ },
42
+ "./aiModels": {
43
+ "types": "./dist/aiModels.d.ts",
44
+ "import": "./dist/aiModels.mjs",
45
+ "require": "./dist/aiModels.js"
46
+ },
27
47
  "./files": {
28
48
  "types": "./dist/files.d.ts",
29
49
  "import": "./dist/files.mjs",
@@ -49,6 +69,11 @@
49
69
  "import": "./dist/redis.mjs",
50
70
  "require": "./dist/redis.js"
51
71
  },
72
+ "./userSettings": {
73
+ "types": "./dist/userSettings.d.ts",
74
+ "import": "./dist/userSettings.mjs",
75
+ "require": "./dist/userSettings.js"
76
+ },
52
77
  "./timescale": {
53
78
  "types": "./dist/timescale.d.ts",
54
79
  "import": "./dist/timescale.mjs",
@@ -57,8 +82,8 @@
57
82
  },
58
83
  "dependencies": {
59
84
  "@grpc/grpc-js": "^1.10.7",
60
- "@grpc/proto-loader": "^0.7.13",
61
- "@tradejs/types": "^1.0.5",
85
+ "@grpc/proto-loader": "^0.8.0",
86
+ "@tradejs/types": "^1.0.8",
62
87
  "chalk": "4.1.2",
63
88
  "ioredis": "5.8.0",
64
89
  "pg": "8.16.3",