@usherlabs/cex-broker 0.2.11 → 0.2.12

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.
@@ -311020,19 +311020,38 @@ var SubscriptionType = {
311020
311020
  BALANCE: 5,
311021
311021
  ORDERS: 6
311022
311022
  };
311023
+ function resolveEnumValue(enumValues, value) {
311024
+ if (typeof value === "number") {
311025
+ return Object.values(enumValues).includes(value) ? value : undefined;
311026
+ }
311027
+ if (typeof value === "string" && Object.hasOwn(enumValues, value)) {
311028
+ return enumValues[value];
311029
+ }
311030
+ return;
311031
+ }
311023
311032
  function createEnumNameMap(enumValues) {
311024
311033
  return Object.fromEntries(Object.entries(enumValues).map(([name, value]) => [value, name]));
311025
311034
  }
311026
311035
  var actionNames = createEnumNameMap(Action);
311027
311036
  var subscriptionTypeNames = createEnumNameMap(SubscriptionType);
311028
311037
  function getActionName(action) {
311038
+ if (typeof action === "string" && Object.hasOwn(Action, action)) {
311039
+ return action;
311040
+ }
311029
311041
  return typeof action === "number" ? actionNames[action] ?? `unknown_${action}` : `unknown_${action ?? "undefined"}`;
311030
311042
  }
311031
311043
  function getSubscriptionTypeName(subscriptionType) {
311032
- return subscriptionTypeNames[subscriptionType] ?? `unknown_${subscriptionType}`;
311044
+ if (typeof subscriptionType === "string" && Object.hasOwn(SubscriptionType, subscriptionType)) {
311045
+ return subscriptionType;
311046
+ }
311047
+ return typeof subscriptionType === "number" ? subscriptionTypeNames[subscriptionType] ?? `unknown_${subscriptionType}` : `unknown_${subscriptionType ?? "undefined"}`;
311048
+ }
311049
+ function resolveAction(action) {
311050
+ return resolveEnumValue(Action, action);
311033
311051
  }
311034
311052
  function resolveSubscriptionType(type2) {
311035
- return type2 === undefined || type2 === SubscriptionType.NO_ACTION ? SubscriptionType.ORDERBOOK : type2;
311053
+ const resolvedType = resolveEnumValue(SubscriptionType, type2);
311054
+ return resolvedType === undefined || resolvedType === SubscriptionType.NO_ACTION ? SubscriptionType.ORDERBOOK : resolvedType;
311036
311055
  }
311037
311056
 
311038
311057
  // node_modules/@loglayer/plugin-opentelemetry/dist/index.mjs
@@ -314377,9 +314396,148 @@ function createOtelLogsFromEnv() {
314377
314396
 
314378
314397
  // src/server.ts
314379
314398
  var grpc = __toESM(require_src3(), 1);
314399
+
314400
+ // src/proto-package-definition.ts
314380
314401
  var protoLoader = __toESM(require_src2(), 1);
314381
- import path from "path";
314382
- import { fileURLToPath } from "url";
314402
+
314403
+ // src/proto/node.descriptor.ts
314404
+ var descriptor = {
314405
+ nested: {
314406
+ cex_broker: {
314407
+ nested: {
314408
+ ActionRequest: {
314409
+ fields: {
314410
+ action: {
314411
+ type: "Action",
314412
+ id: 1
314413
+ },
314414
+ payload: {
314415
+ keyType: "string",
314416
+ type: "string",
314417
+ id: 2
314418
+ },
314419
+ cex: {
314420
+ type: "string",
314421
+ id: 3
314422
+ },
314423
+ symbol: {
314424
+ type: "string",
314425
+ id: 4
314426
+ }
314427
+ }
314428
+ },
314429
+ ActionResponse: {
314430
+ fields: {
314431
+ result: {
314432
+ type: "string",
314433
+ id: 1
314434
+ },
314435
+ proof: {
314436
+ type: "string",
314437
+ id: 2
314438
+ }
314439
+ }
314440
+ },
314441
+ SubscribeRequest: {
314442
+ fields: {
314443
+ cex: {
314444
+ type: "string",
314445
+ id: 1
314446
+ },
314447
+ symbol: {
314448
+ type: "string",
314449
+ id: 2
314450
+ },
314451
+ type: {
314452
+ type: "SubscriptionType",
314453
+ id: 3
314454
+ },
314455
+ options: {
314456
+ keyType: "string",
314457
+ type: "string",
314458
+ id: 4
314459
+ }
314460
+ }
314461
+ },
314462
+ SubscribeResponse: {
314463
+ fields: {
314464
+ data: {
314465
+ type: "string",
314466
+ id: 1
314467
+ },
314468
+ timestamp: {
314469
+ type: "int64",
314470
+ id: 2
314471
+ },
314472
+ symbol: {
314473
+ type: "string",
314474
+ id: 3
314475
+ },
314476
+ type: {
314477
+ type: "SubscriptionType",
314478
+ id: 4
314479
+ }
314480
+ }
314481
+ },
314482
+ SubscriptionType: {
314483
+ values: {
314484
+ NO_ACTION: 0,
314485
+ ORDERBOOK: 1,
314486
+ TRADES: 2,
314487
+ TICKER: 3,
314488
+ OHLCV: 4,
314489
+ BALANCE: 5,
314490
+ ORDERS: 6
314491
+ }
314492
+ },
314493
+ cex_service: {
314494
+ methods: {
314495
+ ExecuteAction: {
314496
+ requestType: "ActionRequest",
314497
+ responseType: "ActionResponse"
314498
+ },
314499
+ Subscribe: {
314500
+ requestType: "SubscribeRequest",
314501
+ responseType: "SubscribeResponse",
314502
+ responseStream: true
314503
+ }
314504
+ }
314505
+ },
314506
+ Action: {
314507
+ values: {
314508
+ NoAction: 0,
314509
+ Deposit: 1,
314510
+ Withdraw: 2,
314511
+ CreateOrder: 3,
314512
+ GetOrderDetails: 4,
314513
+ CancelOrder: 5,
314514
+ FetchBalances: 6,
314515
+ FetchDepositAddresses: 7,
314516
+ FetchTicker: 8,
314517
+ FetchCurrency: 9,
314518
+ Call: 10,
314519
+ FetchAccountId: 11,
314520
+ FetchFees: 12,
314521
+ InternalTransfer: 13
314522
+ }
314523
+ }
314524
+ }
314525
+ }
314526
+ }
314527
+ };
314528
+ var node_descriptor_default = descriptor;
314529
+
314530
+ // src/proto-loader-options.ts
314531
+ var PROTO_LOADER_OPTIONS = {
314532
+ keepCase: true,
314533
+ longs: String,
314534
+ enums: String,
314535
+ defaults: true,
314536
+ oneofs: true
314537
+ };
314538
+
314539
+ // src/proto-package-definition.ts
314540
+ var CEX_BROKER_PACKAGE_DEFINITION = protoLoader.fromJSON(node_descriptor_default, PROTO_LOADER_OPTIONS);
314383
314541
 
314384
314542
  // node_modules/zod/v4/classic/external.js
314385
314543
  var exports_external = {};
@@ -315322,9 +315480,9 @@ function createTransparentProxy(getter) {
315322
315480
  target ?? (target = getter());
315323
315481
  return Reflect.getOwnPropertyDescriptor(target, prop3);
315324
315482
  },
315325
- defineProperty(_, prop3, descriptor) {
315483
+ defineProperty(_, prop3, descriptor2) {
315326
315484
  target ?? (target = getter());
315327
- return Reflect.defineProperty(target, prop3, descriptor);
315485
+ return Reflect.defineProperty(target, prop3, descriptor2);
315328
315486
  }
315329
315487
  });
315330
315488
  }
@@ -327987,16 +328145,7 @@ var FetchFeesPayloadSchema = exports_external.object({
327987
328145
  });
327988
328146
 
327989
328147
  // src/server.ts
327990
- var __filename2 = fileURLToPath(import.meta.url);
327991
- var __dirname2 = path.dirname(__filename2);
327992
- var protoPath = path.join(__dirname2, "proto", "node.proto");
327993
- var packageDef = protoLoader.loadSync(protoPath, {
327994
- keepCase: true,
327995
- longs: String,
327996
- defaults: true,
327997
- oneofs: true
327998
- });
327999
- var grpcObj = grpc.loadPackageDefinition(packageDef);
328148
+ var grpcObj = grpc.loadPackageDefinition(CEX_BROKER_PACKAGE_DEFINITION);
328000
328149
  var cexNode = grpcObj.cex_broker;
328001
328150
  function parsePayload(schema, rawPayload) {
328002
328151
  const parsed = schema.safeParse(rawPayload ?? {});
@@ -328004,10 +328153,10 @@ function parsePayload(schema, rawPayload) {
328004
328153
  return { success: true, data: parsed.data };
328005
328154
  }
328006
328155
  const firstIssue = parsed.error.issues[0];
328007
- const path2 = firstIssue && firstIssue.path.length > 0 ? `${firstIssue.path.join(".")}: ` : "";
328156
+ const path = firstIssue && firstIssue.path.length > 0 ? `${firstIssue.path.join(".")}: ` : "";
328008
328157
  return {
328009
328158
  success: false,
328010
- message: `ValidationError: ${path2}${firstIssue?.message ?? "Invalid payload"}`
328159
+ message: `ValidationError: ${path}${firstIssue?.message ?? "Invalid payload"}`
328011
328160
  };
328012
328161
  }
328013
328162
  function getErrorMessage(error48) {
@@ -328050,7 +328199,8 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
328050
328199
  server.addService(cexNode.cex_service.service, {
328051
328200
  ExecuteAction: async (call, callback) => {
328052
328201
  const startTime = Date.now();
328053
- const { action, cex: cex3, symbol: symbol2 } = call.request;
328202
+ const { action: rawAction, cex: cex3, symbol: symbol2 } = call.request;
328203
+ const action = resolveAction(rawAction);
328054
328204
  let actionCompleted = false;
328055
328205
  const wrappedCallback = (error48, value) => {
328056
328206
  if (!actionCompleted) {
@@ -25,7 +25,10 @@ export declare const SubscriptionType: {
25
25
  readonly ORDERS: 6;
26
26
  };
27
27
  export type Action = (typeof Action)[keyof typeof Action];
28
+ export type ActionName = keyof typeof Action;
28
29
  export type SubscriptionType = (typeof SubscriptionType)[keyof typeof SubscriptionType];
30
+ export type SubscriptionTypeName = keyof typeof SubscriptionType;
29
31
  export declare function getActionName(action: unknown): string;
30
- export declare function getSubscriptionTypeName(subscriptionType: number): string;
31
- export declare function resolveSubscriptionType(type: SubscriptionType | undefined): SubscriptionType;
32
+ export declare function getSubscriptionTypeName(subscriptionType: unknown): string;
33
+ export declare function resolveAction(action: Action | ActionName | undefined): Action | undefined;
34
+ export declare function resolveSubscriptionType(type: SubscriptionType | SubscriptionTypeName | undefined): SubscriptionType;
package/dist/index.js CHANGED
@@ -270143,19 +270143,38 @@ var SubscriptionType = {
270143
270143
  BALANCE: 5,
270144
270144
  ORDERS: 6
270145
270145
  };
270146
+ function resolveEnumValue(enumValues, value) {
270147
+ if (typeof value === "number") {
270148
+ return Object.values(enumValues).includes(value) ? value : undefined;
270149
+ }
270150
+ if (typeof value === "string" && Object.hasOwn(enumValues, value)) {
270151
+ return enumValues[value];
270152
+ }
270153
+ return;
270154
+ }
270146
270155
  function createEnumNameMap(enumValues) {
270147
270156
  return Object.fromEntries(Object.entries(enumValues).map(([name, value]) => [value, name]));
270148
270157
  }
270149
270158
  var actionNames = createEnumNameMap(Action);
270150
270159
  var subscriptionTypeNames = createEnumNameMap(SubscriptionType);
270151
270160
  function getActionName(action) {
270161
+ if (typeof action === "string" && Object.hasOwn(Action, action)) {
270162
+ return action;
270163
+ }
270152
270164
  return typeof action === "number" ? actionNames[action] ?? `unknown_${action}` : `unknown_${action ?? "undefined"}`;
270153
270165
  }
270154
270166
  function getSubscriptionTypeName(subscriptionType) {
270155
- return subscriptionTypeNames[subscriptionType] ?? `unknown_${subscriptionType}`;
270167
+ if (typeof subscriptionType === "string" && Object.hasOwn(SubscriptionType, subscriptionType)) {
270168
+ return subscriptionType;
270169
+ }
270170
+ return typeof subscriptionType === "number" ? subscriptionTypeNames[subscriptionType] ?? `unknown_${subscriptionType}` : `unknown_${subscriptionType ?? "undefined"}`;
270171
+ }
270172
+ function resolveAction(action) {
270173
+ return resolveEnumValue(Action, action);
270156
270174
  }
270157
270175
  function resolveSubscriptionType(type2) {
270158
- return type2 === undefined || type2 === SubscriptionType.NO_ACTION ? SubscriptionType.ORDERBOOK : type2;
270176
+ const resolvedType = resolveEnumValue(SubscriptionType, type2);
270177
+ return resolvedType === undefined || resolvedType === SubscriptionType.NO_ACTION ? SubscriptionType.ORDERBOOK : resolvedType;
270159
270178
  }
270160
270179
 
270161
270180
  // node_modules/@loglayer/plugin-opentelemetry/dist/index.mjs
@@ -277330,9 +277349,148 @@ function createOtelLogsFromEnv() {
277330
277349
 
277331
277350
  // src/server.ts
277332
277351
  import * as grpc from "@grpc/grpc-js";
277352
+
277353
+ // src/proto-package-definition.ts
277333
277354
  import * as protoLoader from "@grpc/proto-loader";
277334
- import path from "path";
277335
- import { fileURLToPath } from "url";
277355
+
277356
+ // src/proto/node.descriptor.ts
277357
+ var descriptor = {
277358
+ nested: {
277359
+ cex_broker: {
277360
+ nested: {
277361
+ ActionRequest: {
277362
+ fields: {
277363
+ action: {
277364
+ type: "Action",
277365
+ id: 1
277366
+ },
277367
+ payload: {
277368
+ keyType: "string",
277369
+ type: "string",
277370
+ id: 2
277371
+ },
277372
+ cex: {
277373
+ type: "string",
277374
+ id: 3
277375
+ },
277376
+ symbol: {
277377
+ type: "string",
277378
+ id: 4
277379
+ }
277380
+ }
277381
+ },
277382
+ ActionResponse: {
277383
+ fields: {
277384
+ result: {
277385
+ type: "string",
277386
+ id: 1
277387
+ },
277388
+ proof: {
277389
+ type: "string",
277390
+ id: 2
277391
+ }
277392
+ }
277393
+ },
277394
+ SubscribeRequest: {
277395
+ fields: {
277396
+ cex: {
277397
+ type: "string",
277398
+ id: 1
277399
+ },
277400
+ symbol: {
277401
+ type: "string",
277402
+ id: 2
277403
+ },
277404
+ type: {
277405
+ type: "SubscriptionType",
277406
+ id: 3
277407
+ },
277408
+ options: {
277409
+ keyType: "string",
277410
+ type: "string",
277411
+ id: 4
277412
+ }
277413
+ }
277414
+ },
277415
+ SubscribeResponse: {
277416
+ fields: {
277417
+ data: {
277418
+ type: "string",
277419
+ id: 1
277420
+ },
277421
+ timestamp: {
277422
+ type: "int64",
277423
+ id: 2
277424
+ },
277425
+ symbol: {
277426
+ type: "string",
277427
+ id: 3
277428
+ },
277429
+ type: {
277430
+ type: "SubscriptionType",
277431
+ id: 4
277432
+ }
277433
+ }
277434
+ },
277435
+ SubscriptionType: {
277436
+ values: {
277437
+ NO_ACTION: 0,
277438
+ ORDERBOOK: 1,
277439
+ TRADES: 2,
277440
+ TICKER: 3,
277441
+ OHLCV: 4,
277442
+ BALANCE: 5,
277443
+ ORDERS: 6
277444
+ }
277445
+ },
277446
+ cex_service: {
277447
+ methods: {
277448
+ ExecuteAction: {
277449
+ requestType: "ActionRequest",
277450
+ responseType: "ActionResponse"
277451
+ },
277452
+ Subscribe: {
277453
+ requestType: "SubscribeRequest",
277454
+ responseType: "SubscribeResponse",
277455
+ responseStream: true
277456
+ }
277457
+ }
277458
+ },
277459
+ Action: {
277460
+ values: {
277461
+ NoAction: 0,
277462
+ Deposit: 1,
277463
+ Withdraw: 2,
277464
+ CreateOrder: 3,
277465
+ GetOrderDetails: 4,
277466
+ CancelOrder: 5,
277467
+ FetchBalances: 6,
277468
+ FetchDepositAddresses: 7,
277469
+ FetchTicker: 8,
277470
+ FetchCurrency: 9,
277471
+ Call: 10,
277472
+ FetchAccountId: 11,
277473
+ FetchFees: 12,
277474
+ InternalTransfer: 13
277475
+ }
277476
+ }
277477
+ }
277478
+ }
277479
+ }
277480
+ };
277481
+ var node_descriptor_default = descriptor;
277482
+
277483
+ // src/proto-loader-options.ts
277484
+ var PROTO_LOADER_OPTIONS = {
277485
+ keepCase: true,
277486
+ longs: String,
277487
+ enums: String,
277488
+ defaults: true,
277489
+ oneofs: true
277490
+ };
277491
+
277492
+ // src/proto-package-definition.ts
277493
+ var CEX_BROKER_PACKAGE_DEFINITION = protoLoader.fromJSON(node_descriptor_default, PROTO_LOADER_OPTIONS);
277336
277494
 
277337
277495
  // node_modules/zod/v4/classic/external.js
277338
277496
  var exports_external = {};
@@ -278275,9 +278433,9 @@ function createTransparentProxy(getter) {
278275
278433
  target ?? (target = getter());
278276
278434
  return Reflect.getOwnPropertyDescriptor(target, prop3);
278277
278435
  },
278278
- defineProperty(_, prop3, descriptor) {
278436
+ defineProperty(_, prop3, descriptor2) {
278279
278437
  target ?? (target = getter());
278280
- return Reflect.defineProperty(target, prop3, descriptor);
278438
+ return Reflect.defineProperty(target, prop3, descriptor2);
278281
278439
  }
278282
278440
  });
278283
278441
  }
@@ -290940,16 +291098,7 @@ var FetchFeesPayloadSchema = exports_external.object({
290940
291098
  });
290941
291099
 
290942
291100
  // src/server.ts
290943
- var __filename2 = fileURLToPath(import.meta.url);
290944
- var __dirname2 = path.dirname(__filename2);
290945
- var protoPath = path.join(__dirname2, "proto", "node.proto");
290946
- var packageDef = protoLoader.loadSync(protoPath, {
290947
- keepCase: true,
290948
- longs: String,
290949
- defaults: true,
290950
- oneofs: true
290951
- });
290952
- var grpcObj = grpc.loadPackageDefinition(packageDef);
291101
+ var grpcObj = grpc.loadPackageDefinition(CEX_BROKER_PACKAGE_DEFINITION);
290953
291102
  var cexNode = grpcObj.cex_broker;
290954
291103
  function parsePayload(schema, rawPayload) {
290955
291104
  const parsed = schema.safeParse(rawPayload ?? {});
@@ -290957,10 +291106,10 @@ function parsePayload(schema, rawPayload) {
290957
291106
  return { success: true, data: parsed.data };
290958
291107
  }
290959
291108
  const firstIssue = parsed.error.issues[0];
290960
- const path2 = firstIssue && firstIssue.path.length > 0 ? `${firstIssue.path.join(".")}: ` : "";
291109
+ const path = firstIssue && firstIssue.path.length > 0 ? `${firstIssue.path.join(".")}: ` : "";
290961
291110
  return {
290962
291111
  success: false,
290963
- message: `ValidationError: ${path2}${firstIssue?.message ?? "Invalid payload"}`
291112
+ message: `ValidationError: ${path}${firstIssue?.message ?? "Invalid payload"}`
290964
291113
  };
290965
291114
  }
290966
291115
  function getErrorMessage(error48) {
@@ -291003,7 +291152,8 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
291003
291152
  server.addService(cexNode.cex_service.service, {
291004
291153
  ExecuteAction: async (call, callback) => {
291005
291154
  const startTime = Date.now();
291006
- const { action, cex: cex3, symbol: symbol2 } = call.request;
291155
+ const { action: rawAction, cex: cex3, symbol: symbol2 } = call.request;
291156
+ const action = resolveAction(rawAction);
291007
291157
  let actionCompleted = false;
291008
291158
  const wrappedCallback = (error48, value) => {
291009
291159
  if (!actionCompleted) {
@@ -292210,4 +292360,4 @@ export {
292210
292360
  CEXBroker as default
292211
292361
  };
292212
292362
 
292213
- //# debugId=EC06775BC83A508D64756E2164756E21
292363
+ //# debugId=F5D3244110461CF964756E2164756E21