@goplus123/core-api 1.0.7 → 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.
package/dist/index.cjs CHANGED
@@ -6182,176 +6182,6 @@ var apiMap = {
6182
6182
  userEngagement: userEngagementEndpoints
6183
6183
  };
6184
6184
 
6185
- // src/routing/router.ts
6186
- var serviceInstances = {};
6187
- var rpcClient;
6188
- var unifiedClient;
6189
- var endpointRegistry = /* @__PURE__ */ new Map();
6190
- var endpointDefaultTransports = /* @__PURE__ */ new Map();
6191
- var defaultTransport = "auto";
6192
- var transportState = {
6193
- hasHttp: false,
6194
- hasWs: false,
6195
- hasGrpc: false
6196
- };
6197
- function resetRoutingState() {
6198
- serviceInstances = {};
6199
- rpcClient = void 0;
6200
- unifiedClient = void 0;
6201
- endpointRegistry.clear();
6202
- endpointDefaultTransports.clear();
6203
- defaultTransport = "auto";
6204
- transportState = { hasHttp: false, hasWs: false, hasGrpc: false };
6205
- }
6206
- function setServiceInstances(instances) {
6207
- serviceInstances = instances;
6208
- }
6209
- function setRpcClient(client) {
6210
- rpcClient = client;
6211
- }
6212
- function setUnifiedClient(client) {
6213
- unifiedClient = client;
6214
- }
6215
- function setTransportState(state) {
6216
- transportState = state;
6217
- }
6218
- function setDefaultTransport(transport) {
6219
- defaultTransport = transport;
6220
- }
6221
- function makeEndpointKey(service, functionName) {
6222
- return `${service}:${functionName}`;
6223
- }
6224
- function isEndpointSpec(value) {
6225
- return !!value && typeof value === "object" && "transport" in value;
6226
- }
6227
- function isEndpointGroup(value) {
6228
- return !!value && typeof value === "object" && "transports" in value;
6229
- }
6230
- function registerEndpointVariant(service, functionName, endpoint) {
6231
- const key = makeEndpointKey(service, functionName);
6232
- let byTransport = endpointRegistry.get(key);
6233
- if (!byTransport) {
6234
- byTransport = /* @__PURE__ */ new Map();
6235
- endpointRegistry.set(key, byTransport);
6236
- }
6237
- byTransport.set(endpoint.transport, endpoint);
6238
- }
6239
- function rebuildEndpointRegistry() {
6240
- endpointRegistry = /* @__PURE__ */ new Map();
6241
- endpointDefaultTransports = /* @__PURE__ */ new Map();
6242
- for (const [serviceName, service] of Object.entries(apiMap)) {
6243
- for (const [functionName, endpoint] of Object.entries(service)) {
6244
- if (isEndpointSpec(endpoint)) {
6245
- registerEndpointVariant(serviceName, functionName, endpoint);
6246
- continue;
6247
- }
6248
- if (isEndpointGroup(endpoint)) {
6249
- if (endpoint.defaultTransport) {
6250
- endpointDefaultTransports.set(
6251
- makeEndpointKey(serviceName, functionName),
6252
- endpoint.defaultTransport
6253
- );
6254
- }
6255
- for (const [transport, config] of Object.entries(endpoint.transports ?? {})) {
6256
- if (!config) continue;
6257
- if (transport === "http") {
6258
- registerEndpointVariant(serviceName, functionName, {
6259
- id: endpoint.id,
6260
- transport: "http",
6261
- http: config,
6262
- request: endpoint.request,
6263
- response: endpoint.response
6264
- });
6265
- } else if (transport === "ws") {
6266
- registerEndpointVariant(serviceName, functionName, {
6267
- id: endpoint.id,
6268
- transport: "ws",
6269
- ws: config,
6270
- request: endpoint.request,
6271
- response: endpoint.response
6272
- });
6273
- } else if (transport === "grpc") {
6274
- registerEndpointVariant(serviceName, functionName, {
6275
- id: endpoint.id,
6276
- transport: "grpc",
6277
- grpc: config,
6278
- request: endpoint.request,
6279
- response: endpoint.response
6280
- });
6281
- }
6282
- }
6283
- continue;
6284
- }
6285
- }
6286
- }
6287
- }
6288
- function requestApi(args) {
6289
- const key = makeEndpointKey(args.service, args.functionName);
6290
- const endpointVariants = endpointRegistry.get(key);
6291
- if (endpointVariants) {
6292
- if (!unifiedClient) {
6293
- throw new Error("SDK not initialized. Please call initSDK first.");
6294
- }
6295
- const specDefaultTransport = endpointDefaultTransports.get(key);
6296
- const endpoint = pickEndpoint(
6297
- endpointVariants,
6298
- args.transport,
6299
- specDefaultTransport,
6300
- args.service,
6301
- args.functionName
6302
- );
6303
- if (endpoint.transport === "grpc" && !transportState.hasGrpc) {
6304
- throw new Error("SDK not initialized. Please call initSDK with grpc config.");
6305
- }
6306
- if (endpoint.transport === "ws" && !transportState.hasWs) {
6307
- throw new Error("SDK not initialized. Please call initSDK with ws config.");
6308
- }
6309
- if (endpoint.transport === "http" && !transportState.hasHttp) {
6310
- throw new Error("SDK not initialized. Please call initSDK with http config.");
6311
- }
6312
- const meta = args.callOptions || args.wsOptions ? {
6313
- ...args.meta ?? {},
6314
- ...args.callOptions ? { callOptions: args.callOptions } : {},
6315
- ...args.wsOptions ? { wsOptions: args.wsOptions } : {}
6316
- } : args.meta;
6317
- return unifiedClient.call(endpoint, args.requestParam, meta);
6318
- }
6319
- const serviceInstance = serviceInstances[args.service];
6320
- const method = serviceInstance?.[args.functionName];
6321
- if (typeof method === "function") {
6322
- if (args.callOptions !== void 0) {
6323
- return method(args.requestParam, args.callOptions);
6324
- }
6325
- return method(args.requestParam);
6326
- }
6327
- if (!rpcClient) {
6328
- throw new Error("SDK not initialized. Please call initSDK first.");
6329
- }
6330
- return rpcClient.call(args.functionName, args.service, args.requestParam, args.wsOptions);
6331
- }
6332
- function pickEndpoint(variants, transport, specDefaultTransport, service, functionName) {
6333
- const resolvedTransport = transport ?? specDefaultTransport ?? defaultTransport;
6334
- if (resolvedTransport !== "auto") {
6335
- const found = variants.get(resolvedTransport);
6336
- if (!found) {
6337
- throw new Error(
6338
- `Endpoint transport not found: ${service}.${functionName} (${resolvedTransport}). Available: ${Array.from(
6339
- variants.keys()
6340
- ).join(", ")}`
6341
- );
6342
- }
6343
- return found;
6344
- }
6345
- if (transportState.hasGrpc && variants.has("grpc")) return variants.get("grpc");
6346
- if (transportState.hasWs && variants.has("ws")) return variants.get("ws");
6347
- if (transportState.hasHttp && variants.has("http")) return variants.get("http");
6348
- const fallback = variants.values().next().value;
6349
- if (!fallback) {
6350
- throw new Error(`Endpoint not found: ${service}.${functionName}`);
6351
- }
6352
- return fallback;
6353
- }
6354
-
6355
6185
  // src/utils/adapters/web.ts
6356
6186
  var webStorage = {
6357
6187
  get(key) {
@@ -6554,6 +6384,176 @@ var setUniqueKeyStorage = (adapter) => {
6554
6384
  };
6555
6385
  var fetchGuid = () => fetchGuidImpl();
6556
6386
 
6387
+ // src/routing/router.ts
6388
+ var serviceInstances = {};
6389
+ var rpcClient;
6390
+ var unifiedClient;
6391
+ var endpointRegistry = /* @__PURE__ */ new Map();
6392
+ var endpointDefaultTransports = /* @__PURE__ */ new Map();
6393
+ var defaultTransport = "auto";
6394
+ var transportState = {
6395
+ hasHttp: false,
6396
+ hasWs: false,
6397
+ hasGrpc: false
6398
+ };
6399
+ function resetRoutingState() {
6400
+ serviceInstances = {};
6401
+ rpcClient = void 0;
6402
+ unifiedClient = void 0;
6403
+ endpointRegistry.clear();
6404
+ endpointDefaultTransports.clear();
6405
+ defaultTransport = "auto";
6406
+ transportState = { hasHttp: false, hasWs: false, hasGrpc: false };
6407
+ }
6408
+ function setServiceInstances(instances) {
6409
+ serviceInstances = instances;
6410
+ }
6411
+ function setRpcClient(client) {
6412
+ rpcClient = client;
6413
+ }
6414
+ function setUnifiedClient(client) {
6415
+ unifiedClient = client;
6416
+ }
6417
+ function setTransportState(state) {
6418
+ transportState = state;
6419
+ }
6420
+ function setDefaultTransport(transport) {
6421
+ defaultTransport = transport;
6422
+ }
6423
+ function makeEndpointKey(service, functionName) {
6424
+ return `${service}:${functionName}`;
6425
+ }
6426
+ function isEndpointSpec(value) {
6427
+ return !!value && typeof value === "object" && "transport" in value;
6428
+ }
6429
+ function isEndpointGroup(value) {
6430
+ return !!value && typeof value === "object" && "transports" in value;
6431
+ }
6432
+ function registerEndpointVariant(service, functionName, endpoint) {
6433
+ const key = makeEndpointKey(service, functionName);
6434
+ let byTransport = endpointRegistry.get(key);
6435
+ if (!byTransport) {
6436
+ byTransport = /* @__PURE__ */ new Map();
6437
+ endpointRegistry.set(key, byTransport);
6438
+ }
6439
+ byTransport.set(endpoint.transport, endpoint);
6440
+ }
6441
+ function rebuildEndpointRegistry() {
6442
+ endpointRegistry = /* @__PURE__ */ new Map();
6443
+ endpointDefaultTransports = /* @__PURE__ */ new Map();
6444
+ for (const [serviceName, service] of Object.entries(apiMap)) {
6445
+ for (const [functionName, endpoint] of Object.entries(service)) {
6446
+ if (isEndpointSpec(endpoint)) {
6447
+ registerEndpointVariant(serviceName, functionName, endpoint);
6448
+ continue;
6449
+ }
6450
+ if (isEndpointGroup(endpoint)) {
6451
+ if (endpoint.defaultTransport) {
6452
+ endpointDefaultTransports.set(
6453
+ makeEndpointKey(serviceName, functionName),
6454
+ endpoint.defaultTransport
6455
+ );
6456
+ }
6457
+ for (const [transport, config] of Object.entries(endpoint.transports ?? {})) {
6458
+ if (!config) continue;
6459
+ if (transport === "http") {
6460
+ registerEndpointVariant(serviceName, functionName, {
6461
+ id: endpoint.id,
6462
+ transport: "http",
6463
+ http: config,
6464
+ request: endpoint.request,
6465
+ response: endpoint.response
6466
+ });
6467
+ } else if (transport === "ws") {
6468
+ registerEndpointVariant(serviceName, functionName, {
6469
+ id: endpoint.id,
6470
+ transport: "ws",
6471
+ ws: config,
6472
+ request: endpoint.request,
6473
+ response: endpoint.response
6474
+ });
6475
+ } else if (transport === "grpc") {
6476
+ registerEndpointVariant(serviceName, functionName, {
6477
+ id: endpoint.id,
6478
+ transport: "grpc",
6479
+ grpc: config,
6480
+ request: endpoint.request,
6481
+ response: endpoint.response
6482
+ });
6483
+ }
6484
+ }
6485
+ continue;
6486
+ }
6487
+ }
6488
+ }
6489
+ }
6490
+ function requestApi(args) {
6491
+ const key = makeEndpointKey(args.service, args.functionName);
6492
+ const endpointVariants = endpointRegistry.get(key);
6493
+ if (endpointVariants) {
6494
+ if (!unifiedClient) {
6495
+ throw new Error("SDK not initialized. Please call initSDK first.");
6496
+ }
6497
+ const specDefaultTransport = endpointDefaultTransports.get(key);
6498
+ const endpoint = pickEndpoint(
6499
+ endpointVariants,
6500
+ args.transport,
6501
+ specDefaultTransport,
6502
+ args.service,
6503
+ args.functionName
6504
+ );
6505
+ if (endpoint.transport === "grpc" && !transportState.hasGrpc) {
6506
+ throw new Error("SDK not initialized. Please call initSDK with grpc config.");
6507
+ }
6508
+ if (endpoint.transport === "ws" && !transportState.hasWs) {
6509
+ throw new Error("SDK not initialized. Please call initSDK with ws config.");
6510
+ }
6511
+ if (endpoint.transport === "http" && !transportState.hasHttp) {
6512
+ throw new Error("SDK not initialized. Please call initSDK with http config.");
6513
+ }
6514
+ const meta = args.callOptions || args.wsOptions ? {
6515
+ ...args.meta ?? {},
6516
+ ...args.callOptions ? { callOptions: args.callOptions } : {},
6517
+ ...args.wsOptions ? { wsOptions: args.wsOptions } : {}
6518
+ } : args.meta;
6519
+ return unifiedClient.call(endpoint, args.requestParam, meta);
6520
+ }
6521
+ const serviceInstance = serviceInstances[args.service];
6522
+ const method = serviceInstance?.[args.functionName];
6523
+ if (typeof method === "function") {
6524
+ if (args.callOptions !== void 0) {
6525
+ return method(args.requestParam, args.callOptions);
6526
+ }
6527
+ return method(args.requestParam);
6528
+ }
6529
+ if (!rpcClient) {
6530
+ throw new Error("SDK not initialized. Please call initSDK first.");
6531
+ }
6532
+ return rpcClient.call(args.functionName, args.service, args.requestParam, args.wsOptions);
6533
+ }
6534
+ function pickEndpoint(variants, transport, specDefaultTransport, service, functionName) {
6535
+ const resolvedTransport = transport ?? specDefaultTransport ?? defaultTransport;
6536
+ if (resolvedTransport !== "auto") {
6537
+ const found = variants.get(resolvedTransport);
6538
+ if (!found) {
6539
+ throw new Error(
6540
+ `Endpoint transport not found: ${service}.${functionName} (${resolvedTransport}). Available: ${Array.from(
6541
+ variants.keys()
6542
+ ).join(", ")}`
6543
+ );
6544
+ }
6545
+ return found;
6546
+ }
6547
+ if (transportState.hasGrpc && variants.has("grpc")) return variants.get("grpc");
6548
+ if (transportState.hasWs && variants.has("ws")) return variants.get("ws");
6549
+ if (transportState.hasHttp && variants.has("http")) return variants.get("http");
6550
+ const fallback = variants.values().next().value;
6551
+ if (!fallback) {
6552
+ throw new Error(`Endpoint not found: ${service}.${functionName}`);
6553
+ }
6554
+ return fallback;
6555
+ }
6556
+
6557
6557
  // src/index.ts
6558
6558
  var api;
6559
6559
  var apiErrorCenter;
@@ -6734,6 +6734,9 @@ function destroySDK() {
6734
6734
  function initSDK(config) {
6735
6735
  clearWsStatusBridge();
6736
6736
  wsStatusSnapshot = void 0;
6737
+ if ("uniqueKeyStorage" in config) {
6738
+ setUniqueKeyStorage(config.uniqueKeyStorage);
6739
+ }
6737
6740
  api = new RequestApi({
6738
6741
  ...config
6739
6742
  });