@jango-blockchained/hoox-shared 1.0.8 → 1.1.0
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/README.md +17 -0
- package/dist/analytics.d.ts +23 -2
- package/dist/analytics.d.ts.map +1 -1
- package/dist/analytics.js +14 -3
- package/dist/api-client.d.ts +12 -2
- package/dist/api-client.d.ts.map +1 -1
- package/dist/api-client.js +74 -7
- package/dist/colors.d.ts +63 -25
- package/dist/colors.d.ts.map +1 -1
- package/dist/colors.js +60 -20
- package/dist/config.d.ts +34 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +61 -6
- package/dist/cron-handler.d.ts +34 -0
- package/dist/cron-handler.d.ts.map +1 -0
- package/dist/cron-handler.js +48 -0
- package/dist/d1/index.js +50 -6
- package/dist/d1/repository.d.ts +5 -0
- package/dist/d1/repository.d.ts.map +1 -1
- package/dist/d1/repository.js +297 -0
- package/dist/d1/schemas.js +81 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +48 -5
- package/dist/exchanges/base-exchange-client.d.ts +68 -0
- package/dist/exchanges/base-exchange-client.d.ts.map +1 -0
- package/dist/exchanges/base-exchange-client.js +120 -0
- package/dist/exchanges/index.d.ts +3 -0
- package/dist/exchanges/index.d.ts.map +1 -0
- package/dist/exchanges/index.js +120 -0
- package/dist/exchanges/types.d.ts +19 -0
- package/dist/exchanges/types.d.ts.map +1 -0
- package/dist/exchanges/types.js +1 -0
- package/dist/health.js +48 -5
- package/dist/index.d.ts +30 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1058 -73
- package/dist/kvUtils.js +48 -5
- package/dist/middleware/auth.d.ts +46 -7
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +151 -0
- package/dist/middleware/cors.d.ts +28 -2
- package/dist/middleware/cors.d.ts.map +1 -1
- package/dist/middleware/cors.js +77 -0
- package/dist/middleware/index.d.ts +2 -2
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/middleware/index.js +361 -101
- package/dist/middleware/logger.d.ts +2 -1
- package/dist/middleware/logger.d.ts.map +1 -1
- package/dist/middleware/logger.js +202 -0
- package/dist/middleware/rate-limit.d.ts +3 -1
- package/dist/middleware/rate-limit.d.ts.map +1 -1
- package/dist/middleware/rate-limit.js +181 -0
- package/dist/middleware/security-headers.js +58 -0
- package/dist/middleware/validate.js +56 -0
- package/dist/operator-transport.d.ts +61 -0
- package/dist/operator-transport.d.ts.map +1 -0
- package/dist/operator-transport.js +87 -0
- package/dist/path-utils.d.ts +205 -0
- package/dist/path-utils.d.ts.map +1 -0
- package/dist/path-utils.js +188 -0
- package/dist/queue-handler.d.ts +43 -0
- package/dist/queue-handler.d.ts.map +1 -0
- package/dist/queue-handler.js +46 -0
- package/dist/router.d.ts +2 -2
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +15 -8
- package/dist/schemas/index.js +7 -4
- package/dist/schemas/registry.js +387 -0
- package/dist/schemas/types.js +1 -0
- package/dist/schemas/validators.d.ts.map +1 -1
- package/dist/schemas/validators.js +290 -0
- package/dist/service-bindings.d.ts +68 -26
- package/dist/service-bindings.d.ts.map +1 -1
- package/dist/service-bindings.js +219 -2
- package/dist/session.d.ts +9 -5
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +179 -4
- package/dist/sse.d.ts +12 -3
- package/dist/sse.d.ts.map +1 -1
- package/dist/sse.js +70 -7
- package/dist/stores/config-store.d.ts.map +1 -1
- package/dist/stores/config-store.js +129 -6
- package/dist/stores/service-store.d.ts +50 -1
- package/dist/stores/service-store.d.ts.map +1 -1
- package/dist/stores/service-store.js +162 -27
- package/dist/test-utils.d.ts +132 -0
- package/dist/test-utils.d.ts.map +1 -0
- package/dist/test-utils.js +128 -0
- package/dist/types/router.d.ts +18 -8
- package/dist/types/router.d.ts.map +1 -1
- package/dist/types.d.ts +124 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +11 -0
- package/dist/wizard/engine.d.ts.map +1 -1
- package/dist/wizard/engine.js +501 -0
- package/dist/wizard/index.js +2 -1
- package/dist/wizard/persistence.js +31 -0
- package/dist/wizard/presets.js +199 -0
- package/dist/wizard/provisioner.js +1 -0
- package/dist/wizard/types.js +1 -0
- package/package.json +46 -12
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __returnValue = (v) => v;
|
|
4
|
+
function __exportSetter(name, newValue) {
|
|
5
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
+
}
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
set: __exportSetter.bind(all, name)
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
17
|
+
|
|
18
|
+
// src/cron-handler.ts
|
|
19
|
+
function createCronHandler(options) {
|
|
20
|
+
const { name, handler, logger } = options;
|
|
21
|
+
return async (event, env, ctx) => {
|
|
22
|
+
const startTime = Date.now();
|
|
23
|
+
logger?.info(`${name} cron triggered`, {
|
|
24
|
+
cron: event.cron,
|
|
25
|
+
scheduledTime: event.scheduledTime
|
|
26
|
+
});
|
|
27
|
+
try {
|
|
28
|
+
await handler(event, env, ctx);
|
|
29
|
+
const durationMs = Date.now() - startTime;
|
|
30
|
+
logger?.info(`${name} cron handler completed successfully`, {
|
|
31
|
+
cron: event.cron,
|
|
32
|
+
durationMs
|
|
33
|
+
});
|
|
34
|
+
} catch (error) {
|
|
35
|
+
const durationMs = Date.now() - startTime;
|
|
36
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
37
|
+
logger?.error(`${name} cron handler failed`, {
|
|
38
|
+
cron: event.cron,
|
|
39
|
+
durationMs,
|
|
40
|
+
error: errorMsg
|
|
41
|
+
});
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
createCronHandler
|
|
48
|
+
};
|
package/dist/d1/index.js
CHANGED
|
@@ -32,22 +32,65 @@ function toError(err, fallback = "Unknown error") {
|
|
|
32
32
|
return fallback;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
+
var SENSITIVE_FIELDS = new Set([
|
|
36
|
+
"password",
|
|
37
|
+
"token",
|
|
38
|
+
"secret",
|
|
39
|
+
"api_key",
|
|
40
|
+
"apiKey",
|
|
41
|
+
"authorization"
|
|
42
|
+
]);
|
|
43
|
+
function hasSensitiveFields(obj) {
|
|
44
|
+
for (const key of Object.keys(obj)) {
|
|
45
|
+
if (SENSITIVE_FIELDS.has(key))
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
function hasErrorValues(obj) {
|
|
51
|
+
for (const v of Object.values(obj)) {
|
|
52
|
+
if (v instanceof Error)
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
35
57
|
function sanitizeOutput(data) {
|
|
58
|
+
if (data === null || data === undefined)
|
|
59
|
+
return data;
|
|
60
|
+
const t = typeof data;
|
|
61
|
+
if (t === "string" || t === "number" || t === "boolean")
|
|
62
|
+
return data;
|
|
36
63
|
if (data instanceof Error) {
|
|
37
64
|
return { name: data.name, message: data.message };
|
|
38
65
|
}
|
|
39
|
-
if (
|
|
66
|
+
if (Array.isArray(data)) {
|
|
67
|
+
return data.map(sanitizeOutput);
|
|
68
|
+
}
|
|
69
|
+
if (t === "object") {
|
|
70
|
+
const obj = data;
|
|
71
|
+
const keys = Object.keys(obj);
|
|
72
|
+
if (keys.length < 10) {
|
|
73
|
+
const sanitized2 = {};
|
|
74
|
+
for (const k of keys) {
|
|
75
|
+
if (k === "stack" || k === "cause")
|
|
76
|
+
continue;
|
|
77
|
+
const v = obj[k];
|
|
78
|
+
sanitized2[k] = v instanceof Error ? { name: v.name, message: v.message } : sanitizeOutput(v);
|
|
79
|
+
}
|
|
80
|
+
return sanitized2;
|
|
81
|
+
}
|
|
82
|
+
if (!hasSensitiveFields(obj) && !hasErrorValues(obj)) {
|
|
83
|
+
return obj;
|
|
84
|
+
}
|
|
40
85
|
const sanitized = {};
|
|
41
|
-
for (const
|
|
86
|
+
for (const k of keys) {
|
|
42
87
|
if (k === "stack" || k === "cause")
|
|
43
88
|
continue;
|
|
89
|
+
const v = obj[k];
|
|
44
90
|
sanitized[k] = v instanceof Error ? { name: v.name, message: v.message } : sanitizeOutput(v);
|
|
45
91
|
}
|
|
46
92
|
return sanitized;
|
|
47
93
|
}
|
|
48
|
-
if (Array.isArray(data)) {
|
|
49
|
-
return data.map(sanitizeOutput);
|
|
50
|
-
}
|
|
51
94
|
return data;
|
|
52
95
|
}
|
|
53
96
|
function createJsonResponse(data, status = 200) {
|
|
@@ -143,7 +186,7 @@ class D1Repository {
|
|
|
143
186
|
async batch(statements) {
|
|
144
187
|
try {
|
|
145
188
|
const prepared = statements.map((s) => s.params && s.params.length > 0 ? this.db.prepare(s.query).bind(...s.params) : this.db.prepare(s.query));
|
|
146
|
-
const results = await this.db.batch(
|
|
189
|
+
const results = await this.db.batch(prepared);
|
|
147
190
|
return results.map((r) => ({
|
|
148
191
|
success: r.success,
|
|
149
192
|
meta: r.meta ? { last_row_id: r.meta.last_row_id, changes: r.meta.changes } : undefined,
|
|
@@ -249,6 +292,7 @@ class D1Repository {
|
|
|
249
292
|
}
|
|
250
293
|
}
|
|
251
294
|
}
|
|
295
|
+
|
|
252
296
|
// src/d1/schemas.ts
|
|
253
297
|
import { z } from "zod";
|
|
254
298
|
var TradeRecordSchema = z.object({
|
package/dist/d1/repository.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated D1Repository is no longer used by any worker.
|
|
3
|
+
* All D1 operations are now handled directly via route handlers in workers/d1-worker.
|
|
4
|
+
* This file is kept for reference but will be removed in a future cleanup pass.
|
|
5
|
+
*/
|
|
1
6
|
import type { D1Database, D1PreparedStatement } from "@cloudflare/workers-types";
|
|
2
7
|
import type { TradeRecord, PositionRecord, BalanceRecord, SystemLogRecord, TradeSignalRecord, D1QueryResult } from "./schemas";
|
|
3
8
|
export interface BatchStatement {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../src/d1/repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAEV,mBAAmB,EACpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,aAAa,EACd,MAAM,WAAW,CAAC;AAGnB,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;CACpB;AAED;;;;GAIG;AACH,qBAAa,YAAY;IACX,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAAF,EAAE,EAAE,UAAU;IAE3C;;OAEG;IACG,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,OAAO,EAAO,GACrB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAiB5B;;OAEG;IACG,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,aAAa,CAAC;IAqB1E;;OAEG;IACG,KAAK,CAAC,UAAU,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAuBnE;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB;IAMzC;;OAEG;IACG,SAAS,CACb,KAAK,GAAE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,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAqBtE;;OAEG;IACG,eAAe,CACnB,KAAK,GAAE,MAAW,GACjB,OAAO,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAU5C;;OAEG;IACG,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,aAAa,CAAC;IAe1E;;OAEG;IACG,aAAa,CACjB,KAAK,GAAE,MAAW,GACjB,OAAO,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;IAO1C;;OAEG;IACG,eAAe,CACnB,GAAG,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC,GAAG;QAC5D,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACxB,EAAE,CAAC,EAAE,MAAM,CAAC;KACb,GACA,OAAO,CAAC,aAAa,CAAC;IAazB;;OAEG;IACG,iBAAiB,IAAI,OAAO,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;IAYhE;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAQtC"}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __returnValue = (v) => v;
|
|
4
|
+
function __exportSetter(name, newValue) {
|
|
5
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
+
}
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
set: __exportSetter.bind(all, name)
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
17
|
+
|
|
18
|
+
// src/errors.ts
|
|
19
|
+
function toError(err, fallback = "Unknown error") {
|
|
20
|
+
if (err instanceof Error)
|
|
21
|
+
return err.message;
|
|
22
|
+
if (typeof err === "string")
|
|
23
|
+
return err;
|
|
24
|
+
if (err && typeof err === "object" && "message" in err && typeof err.message === "string") {
|
|
25
|
+
return err.message;
|
|
26
|
+
}
|
|
27
|
+
if (err === null || err === undefined)
|
|
28
|
+
return fallback;
|
|
29
|
+
try {
|
|
30
|
+
return JSON.stringify(err) || fallback;
|
|
31
|
+
} catch {
|
|
32
|
+
return fallback;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
var SENSITIVE_FIELDS = new Set([
|
|
36
|
+
"password",
|
|
37
|
+
"token",
|
|
38
|
+
"secret",
|
|
39
|
+
"api_key",
|
|
40
|
+
"apiKey",
|
|
41
|
+
"authorization"
|
|
42
|
+
]);
|
|
43
|
+
function hasSensitiveFields(obj) {
|
|
44
|
+
for (const key of Object.keys(obj)) {
|
|
45
|
+
if (SENSITIVE_FIELDS.has(key))
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
function hasErrorValues(obj) {
|
|
51
|
+
for (const v of Object.values(obj)) {
|
|
52
|
+
if (v instanceof Error)
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
function sanitizeOutput(data) {
|
|
58
|
+
if (data === null || data === undefined)
|
|
59
|
+
return data;
|
|
60
|
+
const t = typeof data;
|
|
61
|
+
if (t === "string" || t === "number" || t === "boolean")
|
|
62
|
+
return data;
|
|
63
|
+
if (data instanceof Error) {
|
|
64
|
+
return { name: data.name, message: data.message };
|
|
65
|
+
}
|
|
66
|
+
if (Array.isArray(data)) {
|
|
67
|
+
return data.map(sanitizeOutput);
|
|
68
|
+
}
|
|
69
|
+
if (t === "object") {
|
|
70
|
+
const obj = data;
|
|
71
|
+
const keys = Object.keys(obj);
|
|
72
|
+
if (keys.length < 10) {
|
|
73
|
+
const sanitized2 = {};
|
|
74
|
+
for (const k of keys) {
|
|
75
|
+
if (k === "stack" || k === "cause")
|
|
76
|
+
continue;
|
|
77
|
+
const v = obj[k];
|
|
78
|
+
sanitized2[k] = v instanceof Error ? { name: v.name, message: v.message } : sanitizeOutput(v);
|
|
79
|
+
}
|
|
80
|
+
return sanitized2;
|
|
81
|
+
}
|
|
82
|
+
if (!hasSensitiveFields(obj) && !hasErrorValues(obj)) {
|
|
83
|
+
return obj;
|
|
84
|
+
}
|
|
85
|
+
const sanitized = {};
|
|
86
|
+
for (const k of keys) {
|
|
87
|
+
if (k === "stack" || k === "cause")
|
|
88
|
+
continue;
|
|
89
|
+
const v = obj[k];
|
|
90
|
+
sanitized[k] = v instanceof Error ? { name: v.name, message: v.message } : sanitizeOutput(v);
|
|
91
|
+
}
|
|
92
|
+
return sanitized;
|
|
93
|
+
}
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
function createJsonResponse(data, status = 200) {
|
|
97
|
+
return new Response(JSON.stringify(sanitizeOutput(data)), {
|
|
98
|
+
status,
|
|
99
|
+
headers: { "Content-Type": "application/json" }
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function createSuccessResponse(result) {
|
|
103
|
+
return createJsonResponse({ success: true, result }, 200);
|
|
104
|
+
}
|
|
105
|
+
function createErrorResponse(error, status) {
|
|
106
|
+
const message = typeof error === "string" ? error : error.message;
|
|
107
|
+
const statusCode = typeof error === "string" ? status ?? 500 : error.status ?? 500;
|
|
108
|
+
const body = { success: false, error: message };
|
|
109
|
+
if (typeof error !== "string" && error.code)
|
|
110
|
+
body.code = error.code;
|
|
111
|
+
if (typeof error !== "string" && error.details !== undefined)
|
|
112
|
+
body.details = error.details;
|
|
113
|
+
return new Response(JSON.stringify(body), {
|
|
114
|
+
status: statusCode,
|
|
115
|
+
headers: { "Content-Type": "application/json" }
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
var Errors = {
|
|
119
|
+
badRequest: (message) => createErrorResponse({ message, status: 400, code: "BAD_REQUEST" }),
|
|
120
|
+
unauthorized: (message = "Unauthorized") => createErrorResponse({ message, status: 401, code: "UNAUTHORIZED" }),
|
|
121
|
+
forbidden: (message = "Forbidden") => createErrorResponse({ message, status: 403, code: "FORBIDDEN" }),
|
|
122
|
+
notFound: (message = "Not found") => createErrorResponse({ message, status: 404, code: "NOT_FOUND" }),
|
|
123
|
+
methodNotAllowed: (message = "Method not allowed") => createErrorResponse({ message, status: 405, code: "METHOD_NOT_ALLOWED" }),
|
|
124
|
+
rateLimited: (retryAfter) => {
|
|
125
|
+
const res = createErrorResponse({
|
|
126
|
+
message: "Rate limit exceeded",
|
|
127
|
+
status: 429,
|
|
128
|
+
code: "RATE_LIMITED"
|
|
129
|
+
});
|
|
130
|
+
if (retryAfter)
|
|
131
|
+
res.headers.set("Retry-After", String(retryAfter));
|
|
132
|
+
return res;
|
|
133
|
+
},
|
|
134
|
+
internal: (err) => {
|
|
135
|
+
const message = err ? toError(err, "Internal server error") : "Internal server error";
|
|
136
|
+
return createErrorResponse({
|
|
137
|
+
message,
|
|
138
|
+
status: 500,
|
|
139
|
+
code: "INTERNAL_ERROR"
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// src/d1/repository.ts
|
|
145
|
+
class D1Repository {
|
|
146
|
+
db;
|
|
147
|
+
constructor(db) {
|
|
148
|
+
this.db = db;
|
|
149
|
+
}
|
|
150
|
+
async query(sql, params = []) {
|
|
151
|
+
try {
|
|
152
|
+
const stmt = this.db.prepare(sql).bind(...params);
|
|
153
|
+
const result = await stmt.all();
|
|
154
|
+
return {
|
|
155
|
+
success: result.success,
|
|
156
|
+
results: result.results,
|
|
157
|
+
error: result.error
|
|
158
|
+
};
|
|
159
|
+
} catch (error) {
|
|
160
|
+
return {
|
|
161
|
+
success: false,
|
|
162
|
+
error: toError(error)
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async execute(sql, params = []) {
|
|
167
|
+
try {
|
|
168
|
+
const stmt = this.db.prepare(sql).bind(...params);
|
|
169
|
+
const result = await stmt.run();
|
|
170
|
+
return {
|
|
171
|
+
success: result.success,
|
|
172
|
+
meta: {
|
|
173
|
+
last_row_id: result.meta?.last_row_id,
|
|
174
|
+
changes: result.meta?.changes,
|
|
175
|
+
duration: result.meta?.duration
|
|
176
|
+
},
|
|
177
|
+
error: result.error
|
|
178
|
+
};
|
|
179
|
+
} catch (error) {
|
|
180
|
+
return {
|
|
181
|
+
success: false,
|
|
182
|
+
error: toError(error)
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async batch(statements) {
|
|
187
|
+
try {
|
|
188
|
+
const prepared = statements.map((s) => s.params && s.params.length > 0 ? this.db.prepare(s.query).bind(...s.params) : this.db.prepare(s.query));
|
|
189
|
+
const results = await this.db.batch(prepared);
|
|
190
|
+
return results.map((r) => ({
|
|
191
|
+
success: r.success,
|
|
192
|
+
meta: r.meta ? { last_row_id: r.meta.last_row_id, changes: r.meta.changes } : undefined,
|
|
193
|
+
error: r.error
|
|
194
|
+
}));
|
|
195
|
+
} catch (error) {
|
|
196
|
+
return statements.map(() => ({
|
|
197
|
+
success: false,
|
|
198
|
+
error: toError(error)
|
|
199
|
+
}));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
prepare(sql) {
|
|
203
|
+
return this.db.prepare(sql);
|
|
204
|
+
}
|
|
205
|
+
async getTrades(limit = 50, offset = 0) {
|
|
206
|
+
return this.query("SELECT * FROM trades ORDER BY timestamp DESC LIMIT ? OFFSET ?", [limit, offset]);
|
|
207
|
+
}
|
|
208
|
+
async insertTrade(trade) {
|
|
209
|
+
return this.execute(`INSERT INTO trades (id, timestamp, exchange, symbol, action, quantity, price, leverage, status, raw_response)
|
|
210
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
211
|
+
trade.id || crypto.randomUUID(),
|
|
212
|
+
trade.timestamp,
|
|
213
|
+
trade.exchange,
|
|
214
|
+
trade.symbol,
|
|
215
|
+
trade.action,
|
|
216
|
+
trade.quantity ?? null,
|
|
217
|
+
trade.price ?? null,
|
|
218
|
+
trade.leverage ?? null,
|
|
219
|
+
trade.status,
|
|
220
|
+
trade.raw_response ?? null
|
|
221
|
+
]);
|
|
222
|
+
}
|
|
223
|
+
async getPositions(status) {
|
|
224
|
+
if (status) {
|
|
225
|
+
return this.query("SELECT * FROM positions WHERE status = ? ORDER BY updated_at DESC", [status]);
|
|
226
|
+
}
|
|
227
|
+
return this.query("SELECT * FROM positions ORDER BY updated_at DESC");
|
|
228
|
+
}
|
|
229
|
+
async upsertPosition(position) {
|
|
230
|
+
return this.execute(`REPLACE INTO positions (id, exchange, symbol, side, entry_price, mark_price, liquidation_price, leverage, size, unrealized_pnl, status, updated_at)
|
|
231
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
232
|
+
position.id,
|
|
233
|
+
position.exchange,
|
|
234
|
+
position.symbol,
|
|
235
|
+
position.side,
|
|
236
|
+
position.entry_price ?? null,
|
|
237
|
+
position.mark_price ?? null,
|
|
238
|
+
position.liquidation_price ?? null,
|
|
239
|
+
position.leverage ?? null,
|
|
240
|
+
position.size,
|
|
241
|
+
position.unrealized_pnl ?? null,
|
|
242
|
+
position.status,
|
|
243
|
+
position.updated_at
|
|
244
|
+
]);
|
|
245
|
+
}
|
|
246
|
+
async getTradeSignals(limit = 10) {
|
|
247
|
+
return this.query(`SELECT signal_id, timestamp, symbol, signal_type, source, processed_at
|
|
248
|
+
FROM trade_signals
|
|
249
|
+
ORDER BY processed_at DESC
|
|
250
|
+
LIMIT ?`, [limit]);
|
|
251
|
+
}
|
|
252
|
+
async insertTradeSignal(signal) {
|
|
253
|
+
return this.execute(`INSERT INTO trade_signals (signal_id, timestamp, symbol, signal_type, source, raw_data)
|
|
254
|
+
VALUES (?, ?, ?, ?, ?, ?)`, [
|
|
255
|
+
signal.signal_id,
|
|
256
|
+
signal.timestamp,
|
|
257
|
+
signal.symbol,
|
|
258
|
+
signal.signal_type,
|
|
259
|
+
signal.source ?? null,
|
|
260
|
+
signal.raw_data ?? null
|
|
261
|
+
]);
|
|
262
|
+
}
|
|
263
|
+
async getSystemLogs(limit = 50) {
|
|
264
|
+
return this.query("SELECT * FROM system_logs ORDER BY timestamp DESC LIMIT ?", [limit]);
|
|
265
|
+
}
|
|
266
|
+
async insertSystemLog(log) {
|
|
267
|
+
return this.execute(`INSERT INTO system_logs (id, level, service, message, details) VALUES (?, ?, ?, ?, ?)`, [
|
|
268
|
+
log.id || crypto.randomUUID(),
|
|
269
|
+
log.level,
|
|
270
|
+
log.service,
|
|
271
|
+
log.message,
|
|
272
|
+
log.details ?? null
|
|
273
|
+
]);
|
|
274
|
+
}
|
|
275
|
+
async getLatestBalances() {
|
|
276
|
+
return this.query(`
|
|
277
|
+
SELECT b.id, b.exchange, b.asset, b.total, b.free, b.used, b.timestamp
|
|
278
|
+
FROM balances b
|
|
279
|
+
INNER JOIN (
|
|
280
|
+
SELECT exchange, asset, MAX(timestamp) as max_time
|
|
281
|
+
FROM balances
|
|
282
|
+
GROUP BY exchange, asset
|
|
283
|
+
) latest ON b.exchange = latest.exchange AND b.asset = latest.asset AND b.timestamp = latest.max_time
|
|
284
|
+
`);
|
|
285
|
+
}
|
|
286
|
+
async healthCheck() {
|
|
287
|
+
try {
|
|
288
|
+
await this.db.prepare("SELECT 1").first();
|
|
289
|
+
return true;
|
|
290
|
+
} catch {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
export {
|
|
296
|
+
D1Repository
|
|
297
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __returnValue = (v) => v;
|
|
4
|
+
function __exportSetter(name, newValue) {
|
|
5
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
+
}
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
set: __exportSetter.bind(all, name)
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
17
|
+
|
|
18
|
+
// src/d1/schemas.ts
|
|
19
|
+
import { z } from "zod";
|
|
20
|
+
var TradeRecordSchema = z.object({
|
|
21
|
+
id: z.string(),
|
|
22
|
+
signal_id: z.string().nullable().optional(),
|
|
23
|
+
timestamp: z.number().int().positive(),
|
|
24
|
+
exchange: z.string().min(1),
|
|
25
|
+
symbol: z.string().min(1),
|
|
26
|
+
action: z.string().min(1),
|
|
27
|
+
quantity: z.number().nullable(),
|
|
28
|
+
price: z.number().nullable(),
|
|
29
|
+
leverage: z.number().nullable(),
|
|
30
|
+
status: z.string().min(1),
|
|
31
|
+
error_message: z.string().nullable().optional(),
|
|
32
|
+
raw_response: z.string().nullable().optional(),
|
|
33
|
+
created_at: z.number().int().optional()
|
|
34
|
+
}).strict();
|
|
35
|
+
var PositionRecordSchema = z.object({
|
|
36
|
+
id: z.string(),
|
|
37
|
+
exchange: z.string().min(1),
|
|
38
|
+
symbol: z.string().min(1),
|
|
39
|
+
side: z.enum(["LONG", "SHORT"]),
|
|
40
|
+
entry_price: z.number().nullable().optional(),
|
|
41
|
+
mark_price: z.number().nullable().optional(),
|
|
42
|
+
liquidation_price: z.number().nullable().optional(),
|
|
43
|
+
leverage: z.number().nullable().optional(),
|
|
44
|
+
size: z.number().nullable(),
|
|
45
|
+
unrealized_pnl: z.number().nullable().optional(),
|
|
46
|
+
status: z.enum(["OPEN", "CLOSED"]),
|
|
47
|
+
updated_at: z.number().int()
|
|
48
|
+
}).strict();
|
|
49
|
+
var BalanceRecordSchema = z.object({
|
|
50
|
+
id: z.string(),
|
|
51
|
+
exchange: z.string().min(1),
|
|
52
|
+
asset: z.string().min(1),
|
|
53
|
+
free: z.number().nullable(),
|
|
54
|
+
used: z.number().nullable(),
|
|
55
|
+
total: z.number().nullable(),
|
|
56
|
+
timestamp: z.number().int().positive()
|
|
57
|
+
}).strict();
|
|
58
|
+
var SystemLogRecordSchema = z.object({
|
|
59
|
+
id: z.string(),
|
|
60
|
+
timestamp: z.number().int().optional(),
|
|
61
|
+
level: z.string().min(1),
|
|
62
|
+
service: z.string().min(1),
|
|
63
|
+
message: z.string().min(1),
|
|
64
|
+
details: z.string().nullable().optional()
|
|
65
|
+
}).strict();
|
|
66
|
+
var TradeSignalRecordSchema = z.object({
|
|
67
|
+
signal_id: z.string(),
|
|
68
|
+
timestamp: z.number().int().positive(),
|
|
69
|
+
symbol: z.string().min(1),
|
|
70
|
+
signal_type: z.string().min(1),
|
|
71
|
+
source: z.string().nullable().optional(),
|
|
72
|
+
raw_data: z.string().nullable().optional(),
|
|
73
|
+
processed_at: z.number().int().optional()
|
|
74
|
+
}).strict();
|
|
75
|
+
export {
|
|
76
|
+
TradeSignalRecordSchema,
|
|
77
|
+
TradeRecordSchema,
|
|
78
|
+
SystemLogRecordSchema,
|
|
79
|
+
PositionRecordSchema,
|
|
80
|
+
BalanceRecordSchema
|
|
81
|
+
};
|
package/dist/errors.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Centralizes error response creation across the monorepo
|
|
4
4
|
*/
|
|
5
5
|
import type { AppError } from "./types/errors";
|
|
6
|
+
export type { AppError };
|
|
6
7
|
/**
|
|
7
8
|
* Safely extract an error message from any caught value.
|
|
8
9
|
* Eliminates the duplicated `error instanceof Error ? error.message : String(error)`
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,YAAY,EAAE,QAAQ,EAAE,CAAC;AAEzB;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,SAAkB,GAAG,MAAM,CAkBxE;AA4FD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,SAAM,GAAG,QAAQ,CAKxE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,QAAQ,CAEhE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,QAAQ,GAAG,MAAM,EACxB,MAAM,CAAC,EAAE,MAAM,GACd,QAAQ,CAcV;AAED;;GAEG;AACH,eAAO,MAAM,MAAM;0BACK,MAAM;;;;;+BAUD,MAAM;qBAShB,OAAO;CAUzB,CAAC"}
|
package/dist/errors.js
CHANGED
|
@@ -32,22 +32,65 @@ function toError(err, fallback = "Unknown error") {
|
|
|
32
32
|
return fallback;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
+
var SENSITIVE_FIELDS = new Set([
|
|
36
|
+
"password",
|
|
37
|
+
"token",
|
|
38
|
+
"secret",
|
|
39
|
+
"api_key",
|
|
40
|
+
"apiKey",
|
|
41
|
+
"authorization"
|
|
42
|
+
]);
|
|
43
|
+
function hasSensitiveFields(obj) {
|
|
44
|
+
for (const key of Object.keys(obj)) {
|
|
45
|
+
if (SENSITIVE_FIELDS.has(key))
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
function hasErrorValues(obj) {
|
|
51
|
+
for (const v of Object.values(obj)) {
|
|
52
|
+
if (v instanceof Error)
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
35
57
|
function sanitizeOutput(data) {
|
|
58
|
+
if (data === null || data === undefined)
|
|
59
|
+
return data;
|
|
60
|
+
const t = typeof data;
|
|
61
|
+
if (t === "string" || t === "number" || t === "boolean")
|
|
62
|
+
return data;
|
|
36
63
|
if (data instanceof Error) {
|
|
37
64
|
return { name: data.name, message: data.message };
|
|
38
65
|
}
|
|
39
|
-
if (
|
|
66
|
+
if (Array.isArray(data)) {
|
|
67
|
+
return data.map(sanitizeOutput);
|
|
68
|
+
}
|
|
69
|
+
if (t === "object") {
|
|
70
|
+
const obj = data;
|
|
71
|
+
const keys = Object.keys(obj);
|
|
72
|
+
if (keys.length < 10) {
|
|
73
|
+
const sanitized2 = {};
|
|
74
|
+
for (const k of keys) {
|
|
75
|
+
if (k === "stack" || k === "cause")
|
|
76
|
+
continue;
|
|
77
|
+
const v = obj[k];
|
|
78
|
+
sanitized2[k] = v instanceof Error ? { name: v.name, message: v.message } : sanitizeOutput(v);
|
|
79
|
+
}
|
|
80
|
+
return sanitized2;
|
|
81
|
+
}
|
|
82
|
+
if (!hasSensitiveFields(obj) && !hasErrorValues(obj)) {
|
|
83
|
+
return obj;
|
|
84
|
+
}
|
|
40
85
|
const sanitized = {};
|
|
41
|
-
for (const
|
|
86
|
+
for (const k of keys) {
|
|
42
87
|
if (k === "stack" || k === "cause")
|
|
43
88
|
continue;
|
|
89
|
+
const v = obj[k];
|
|
44
90
|
sanitized[k] = v instanceof Error ? { name: v.name, message: v.message } : sanitizeOutput(v);
|
|
45
91
|
}
|
|
46
92
|
return sanitized;
|
|
47
93
|
}
|
|
48
|
-
if (Array.isArray(data)) {
|
|
49
|
-
return data.map(sanitizeOutput);
|
|
50
|
-
}
|
|
51
94
|
return data;
|
|
52
95
|
}
|
|
53
96
|
function createJsonResponse(data, status = 200) {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export interface ExchangeConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
apiSecret: string;
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
testnet?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface TradeParams {
|
|
8
|
+
symbol: string;
|
|
9
|
+
side: string;
|
|
10
|
+
orderType?: string;
|
|
11
|
+
quantity: number;
|
|
12
|
+
price?: number;
|
|
13
|
+
reduceOnly?: boolean;
|
|
14
|
+
leverage?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface OrderResponse {
|
|
17
|
+
orderId: string;
|
|
18
|
+
symbol: string;
|
|
19
|
+
status: string;
|
|
20
|
+
executedQty?: string;
|
|
21
|
+
price?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface Position {
|
|
24
|
+
symbol: string;
|
|
25
|
+
side: "long" | "short";
|
|
26
|
+
quantity: number;
|
|
27
|
+
entryPrice: number;
|
|
28
|
+
unrealizedPnl?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Base class for exchange clients. All exchange implementations must extend this.
|
|
32
|
+
* Provides common functionality for exchange API clients including signature generation,
|
|
33
|
+
* HTTP requests, and trade execution helpers.
|
|
34
|
+
*/
|
|
35
|
+
export declare abstract class BaseExchangeClient {
|
|
36
|
+
protected readonly apiKey: string;
|
|
37
|
+
protected readonly apiSecret: string;
|
|
38
|
+
protected readonly baseUrl: string;
|
|
39
|
+
protected readonly isTestnet: boolean;
|
|
40
|
+
protected readonly importedKeyPromise: Promise<CryptoKey>;
|
|
41
|
+
constructor(apiKey: string, apiSecret: string);
|
|
42
|
+
/**
|
|
43
|
+
* Returns the error message prefix for this client.
|
|
44
|
+
* Subclasses can override to customize error messages.
|
|
45
|
+
*/
|
|
46
|
+
protected getErrorMessagePrefix(): string;
|
|
47
|
+
protected abstract getDefaultBaseUrl(): string;
|
|
48
|
+
protected generateSignature(_params: Record<string, string | number | boolean>): Promise<string>;
|
|
49
|
+
protected buildHeaders(_method: string, _path: string, _params?: Record<string, string | number | boolean>): Headers;
|
|
50
|
+
/**
|
|
51
|
+
* Imports the API secret as a CryptoKey for HMAC-SHA256 signing.
|
|
52
|
+
*/
|
|
53
|
+
private importKey;
|
|
54
|
+
/**
|
|
55
|
+
* Signs data using HMAC-SHA256 with the API secret.
|
|
56
|
+
*/
|
|
57
|
+
protected cryptoSign(data: string): Promise<string>;
|
|
58
|
+
protected fetch<T>(method: string, path: string, params?: Record<string, string | number | boolean>): Promise<T>;
|
|
59
|
+
setLeverage(_symbol: string, _leverage: number): Promise<void>;
|
|
60
|
+
executeTrade(_params: TradeParams): Promise<OrderResponse>;
|
|
61
|
+
getAccountInfo(): Promise<Record<string, unknown>>;
|
|
62
|
+
getPositions(_symbol?: string): Promise<Position[]>;
|
|
63
|
+
openLong(symbol: string, quantity: number, price?: number, orderType?: string): Promise<OrderResponse>;
|
|
64
|
+
openShort(symbol: string, quantity: number, price?: number, orderType?: string): Promise<OrderResponse>;
|
|
65
|
+
closeLong(symbol: string, quantity: number): Promise<OrderResponse>;
|
|
66
|
+
closeShort(symbol: string, quantity: number): Promise<OrderResponse>;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=base-exchange-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-exchange-client.d.ts","sourceRoot":"","sources":["../../src/exchanges/base-exchange-client.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IA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