@series-inc/venus-sdk 3.2.0 → 3.2.1-beta.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.
@@ -820,7 +820,6 @@ interface LoggingApi {
820
820
 
821
821
  interface SharedAssetsApi {
822
822
  loadAssetsBundle(game: string, bundleKey: string): Promise<ArrayBuffer>;
823
- loadLibraryCode(libraryKey: string): Promise<string>;
824
823
  }
825
824
 
826
825
  declare class RpcSharedAssetsApi implements SharedAssetsApi {
@@ -828,7 +827,6 @@ declare class RpcSharedAssetsApi implements SharedAssetsApi {
828
827
  private readonly rpcClient;
829
828
  constructor(rpcClient: RpcClient, venusApi: VenusAPI);
830
829
  loadAssetsBundle(game: string, bundleKey: string, fileType?: string): Promise<ArrayBuffer>;
831
- loadLibraryCode(libraryKey: string): Promise<string>;
832
830
  }
833
831
  interface LoadEmbeddedAssetsRequest {
834
832
  assetKey: string;
@@ -820,7 +820,6 @@ interface LoggingApi {
820
820
 
821
821
  interface SharedAssetsApi {
822
822
  loadAssetsBundle(game: string, bundleKey: string): Promise<ArrayBuffer>;
823
- loadLibraryCode(libraryKey: string): Promise<string>;
824
823
  }
825
824
 
826
825
  declare class RpcSharedAssetsApi implements SharedAssetsApi {
@@ -828,7 +827,6 @@ declare class RpcSharedAssetsApi implements SharedAssetsApi {
828
827
  private readonly rpcClient;
829
828
  constructor(rpcClient: RpcClient, venusApi: VenusAPI);
830
829
  loadAssetsBundle(game: string, bundleKey: string, fileType?: string): Promise<ArrayBuffer>;
831
- loadLibraryCode(libraryKey: string): Promise<string>;
832
830
  }
833
831
  interface LoadEmbeddedAssetsRequest {
834
832
  assetKey: string;
@@ -2632,21 +2632,23 @@ function initializeRoomsApi(venusApi, host) {
2632
2632
  }
2633
2633
 
2634
2634
  // src/storage/MockStorageApi.ts
2635
+ var STORAGE_PREFIXES = {
2636
+ globalStorage: "venus:global",
2637
+ deviceCache: "venus:deviceCache",
2638
+ appStorage: "venus:appStorage"
2639
+ };
2635
2640
  function createMockStorageApi(storageType, appUrl) {
2636
2641
  const appIdentifier = appUrl ? generateAppIdentifier(appUrl) : null;
2637
- let prefix;
2642
+ let prefix = STORAGE_PREFIXES[storageType];
2638
2643
  let syncDelay = 0;
2639
2644
  switch (storageType) {
2640
2645
  case "deviceCache":
2641
- prefix = "venus:app";
2642
2646
  syncDelay = 0;
2643
2647
  break;
2644
2648
  case "appStorage":
2645
- prefix = "venus:app";
2646
2649
  syncDelay = 100;
2647
2650
  break;
2648
2651
  case "globalStorage":
2649
- prefix = "venus:global";
2650
2652
  syncDelay = 100;
2651
2653
  break;
2652
2654
  default:
@@ -2659,29 +2661,38 @@ var MockStorageApi = class {
2659
2661
  constructor(prefix, syncDelay) {
2660
2662
  __publicField(this, "prefix");
2661
2663
  __publicField(this, "syncDelay");
2664
+ __publicField(this, "orderStorageKey");
2662
2665
  this.prefix = prefix;
2663
2666
  this.syncDelay = syncDelay;
2667
+ this.orderStorageKey = `${prefix}__order__`;
2664
2668
  }
2665
2669
  async clear() {
2670
+ const keysToRemove = [];
2666
2671
  const fullLength = localStorage.length;
2667
2672
  for (let i = 0; i < fullLength; i++) {
2668
2673
  const fullKey = localStorage.key(i);
2669
- if (fullKey && fullKey.startsWith(this.prefix)) {
2670
- localStorage.removeItem(fullKey);
2674
+ if (!fullKey || fullKey === this.orderStorageKey) {
2675
+ continue;
2671
2676
  }
2677
+ if (fullKey.startsWith(this.prefix)) {
2678
+ keysToRemove.push(fullKey);
2679
+ }
2680
+ }
2681
+ for (const key of keysToRemove) {
2682
+ localStorage.removeItem(key);
2672
2683
  }
2684
+ this.clearOrder();
2673
2685
  await this.simulateSyncDelay();
2674
2686
  }
2675
2687
  async getAllItems() {
2676
2688
  const items = new Array();
2677
- const fullLength = localStorage.length;
2678
- for (let i = 0; i < fullLength; i++) {
2679
- const fullKey = localStorage.key(i);
2680
- if (fullKey && fullKey.startsWith(this.prefix)) {
2681
- const item = localStorage.getItem(fullKey);
2682
- if (item) {
2683
- items.push(item);
2684
- }
2689
+ const orderedKeys = this.keys();
2690
+ for (const key of orderedKeys) {
2691
+ const value = localStorage.getItem(this.buildKey(key));
2692
+ if (value !== null) {
2693
+ items.push(value);
2694
+ } else {
2695
+ this.removeFromOrder(key);
2685
2696
  }
2686
2697
  }
2687
2698
  return items;
@@ -2706,11 +2717,13 @@ var MockStorageApi = class {
2706
2717
  const fullKey = this.buildKey(key);
2707
2718
  await this.simulateSyncDelay();
2708
2719
  localStorage.removeItem(fullKey);
2720
+ this.removeFromOrder(key);
2709
2721
  }
2710
2722
  async setItem(key, item) {
2711
2723
  const fullKey = this.buildKey(key);
2712
2724
  await this.simulateSyncDelay();
2713
2725
  localStorage.setItem(fullKey, item);
2726
+ this.upsertOrder(key);
2714
2727
  }
2715
2728
  async setMultipleItems(entries) {
2716
2729
  for (const entry of entries) {
@@ -2718,6 +2731,7 @@ var MockStorageApi = class {
2718
2731
  localStorage.setItem(fullKey, entry.value);
2719
2732
  }
2720
2733
  await this.simulateSyncDelay();
2734
+ this.bulkUpsertOrder(entries.map((entry) => entry.key));
2721
2735
  }
2722
2736
  async removeMultipleItems(keys) {
2723
2737
  for (const key of keys) {
@@ -2725,6 +2739,7 @@ var MockStorageApi = class {
2725
2739
  localStorage.removeItem(fullKey);
2726
2740
  }
2727
2741
  await this.simulateSyncDelay();
2742
+ this.bulkRemoveFromOrder(keys);
2728
2743
  }
2729
2744
  buildKey(key) {
2730
2745
  const prefix = this.prefix;
@@ -2735,17 +2750,8 @@ var MockStorageApi = class {
2735
2750
  return fullKey.substring(prefix.length);
2736
2751
  }
2737
2752
  keys() {
2738
- const keys = new Array();
2739
- let length = localStorage.length;
2740
- for (let i = 0; i < length; i++) {
2741
- const fullKey = localStorage.key(i);
2742
- if (fullKey && fullKey.startsWith(this.prefix)) {
2743
- length++;
2744
- const key = this.extractKey(fullKey);
2745
- keys.push(key);
2746
- }
2747
- }
2748
- return keys;
2753
+ const order = this.readOrder();
2754
+ return [...order];
2749
2755
  }
2750
2756
  async simulateSyncDelay() {
2751
2757
  const syncDelay = this.syncDelay;
@@ -2753,6 +2759,127 @@ var MockStorageApi = class {
2753
2759
  await new Promise((resolve) => setTimeout(resolve, syncDelay));
2754
2760
  }
2755
2761
  }
2762
+ readOrder() {
2763
+ const raw = localStorage.getItem(this.orderStorageKey);
2764
+ if (!raw) {
2765
+ return this.rebuildOrderFromStorage();
2766
+ }
2767
+ try {
2768
+ const parsed = JSON.parse(raw);
2769
+ if (Array.isArray(parsed)) {
2770
+ return this.normalizeOrder(parsed);
2771
+ }
2772
+ } catch {
2773
+ }
2774
+ return this.rebuildOrderFromStorage();
2775
+ }
2776
+ normalizeOrder(order) {
2777
+ const seen = /* @__PURE__ */ new Set();
2778
+ const normalized = [];
2779
+ let changed = false;
2780
+ for (const entry of order) {
2781
+ if (typeof entry !== "string") {
2782
+ changed = true;
2783
+ continue;
2784
+ }
2785
+ if (seen.has(entry)) {
2786
+ changed = true;
2787
+ continue;
2788
+ }
2789
+ const fullKey = this.buildKey(entry);
2790
+ if (localStorage.getItem(fullKey) === null) {
2791
+ changed = true;
2792
+ continue;
2793
+ }
2794
+ seen.add(entry);
2795
+ normalized.push(entry);
2796
+ }
2797
+ if (changed) {
2798
+ this.writeOrder(normalized);
2799
+ }
2800
+ return normalized;
2801
+ }
2802
+ rebuildOrderFromStorage() {
2803
+ const keys = [];
2804
+ const total = localStorage.length;
2805
+ for (let i = 0; i < total; i++) {
2806
+ const fullKey = localStorage.key(i);
2807
+ if (!fullKey) continue;
2808
+ if (fullKey === this.orderStorageKey) continue;
2809
+ if (fullKey.startsWith(this.prefix)) {
2810
+ keys.push(this.extractKey(fullKey));
2811
+ }
2812
+ }
2813
+ this.writeOrder(keys);
2814
+ return keys;
2815
+ }
2816
+ upsertOrder(key) {
2817
+ const order = this.readOrder();
2818
+ const index = order.indexOf(key);
2819
+ if (index !== -1) {
2820
+ order.splice(index, 1);
2821
+ }
2822
+ order.push(key);
2823
+ this.writeOrder(order);
2824
+ }
2825
+ bulkUpsertOrder(keys) {
2826
+ const dedupedKeys = this.dedupeKeys(keys);
2827
+ if (dedupedKeys.length === 0) {
2828
+ return;
2829
+ }
2830
+ const order = this.readOrder();
2831
+ const keysSet = new Set(dedupedKeys);
2832
+ const filtered = order.filter((entry) => !keysSet.has(entry));
2833
+ for (const key of dedupedKeys) {
2834
+ filtered.push(key);
2835
+ }
2836
+ this.writeOrder(filtered);
2837
+ }
2838
+ removeFromOrder(key) {
2839
+ const order = this.readOrder();
2840
+ const index = order.indexOf(key);
2841
+ if (index !== -1) {
2842
+ order.splice(index, 1);
2843
+ this.writeOrder(order);
2844
+ }
2845
+ }
2846
+ bulkRemoveFromOrder(keys) {
2847
+ const dedupedKeys = this.dedupeKeys(keys);
2848
+ if (dedupedKeys.length === 0) {
2849
+ return;
2850
+ }
2851
+ const order = this.readOrder();
2852
+ const keysSet = new Set(dedupedKeys);
2853
+ const filtered = order.filter((entry) => !keysSet.has(entry));
2854
+ if (filtered.length !== order.length) {
2855
+ this.writeOrder(filtered);
2856
+ }
2857
+ }
2858
+ writeOrder(order) {
2859
+ if (order.length === 0) {
2860
+ localStorage.removeItem(this.orderStorageKey);
2861
+ return;
2862
+ }
2863
+ localStorage.setItem(this.orderStorageKey, JSON.stringify(order));
2864
+ }
2865
+ clearOrder() {
2866
+ localStorage.removeItem(this.orderStorageKey);
2867
+ }
2868
+ dedupeKeys(keys) {
2869
+ const result = [];
2870
+ const seen = /* @__PURE__ */ new Set();
2871
+ for (const key of keys) {
2872
+ if (typeof key !== "string") {
2873
+ continue;
2874
+ }
2875
+ if (seen.has(key)) {
2876
+ continue;
2877
+ }
2878
+ seen.add(key);
2879
+ result.push(key);
2880
+ }
2881
+ return result;
2882
+ }
2756
2883
  };
2757
2884
  function generateAppIdentifier(appUrl) {
2758
2885
  if (!appUrl) appUrl = "";
@@ -3423,7 +3550,72 @@ function initializeTime(venusApi, host) {
3423
3550
  }
3424
3551
 
3425
3552
  // src/version.ts
3426
- var SDK_VERSION = "3.2.0";
3553
+ var SDK_VERSION = "3.2.1-beta.0";
3554
+
3555
+ // src/shared-assets/base64Utils.ts
3556
+ function base64ToArrayBuffer(base64) {
3557
+ const binaryString = atob(base64);
3558
+ const len = binaryString.length;
3559
+ const bytes = new Uint8Array(len);
3560
+ for (let i = 0; i < len; i++) {
3561
+ bytes[i] = binaryString.charCodeAt(i);
3562
+ }
3563
+ return bytes.buffer;
3564
+ }
3565
+ function base64ToUtf8(base64) {
3566
+ if (typeof TextDecoder !== "undefined") {
3567
+ const decoder = new TextDecoder("utf-8");
3568
+ const buffer = base64ToArrayBuffer(base64);
3569
+ return decoder.decode(new Uint8Array(buffer));
3570
+ }
3571
+ if (typeof globalThis !== "undefined" && typeof globalThis.Buffer !== "undefined") {
3572
+ const BufferCtor = globalThis.Buffer;
3573
+ return BufferCtor.from(base64, "base64").toString("utf-8");
3574
+ }
3575
+ const binaryString = atob(base64);
3576
+ let result = "";
3577
+ for (let i = 0; i < binaryString.length; i++) {
3578
+ result += String.fromCharCode(binaryString.charCodeAt(i));
3579
+ }
3580
+ return decodeURIComponent(escape(result));
3581
+ }
3582
+
3583
+ // src/shared-assets/RpcSharedAssetsApi.ts
3584
+ var RpcSharedAssetsApi = class {
3585
+ constructor(rpcClient, venusApi) {
3586
+ __publicField(this, "venusApi");
3587
+ __publicField(this, "rpcClient");
3588
+ this.rpcClient = rpcClient;
3589
+ this.venusApi = venusApi;
3590
+ }
3591
+ async loadAssetsBundle(game, bundleKey, fileType = "stow") {
3592
+ try {
3593
+ const response = await this.rpcClient.callT("H5_LOAD_EMBEDDED_ASSET" /* H5_LOAD_EMBEDDED_ASSET */, {
3594
+ assetKey: bundleKey
3595
+ });
3596
+ return base64ToArrayBuffer(response.base64Data);
3597
+ } catch (err) {
3598
+ try {
3599
+ const blob = await this.venusApi.cdn.fetchBlob(`${game}/${bundleKey}.${fileType}`);
3600
+ return await blob.arrayBuffer();
3601
+ } catch (e) {
3602
+ throw new Error(`Failed to load ${bundleKey}`);
3603
+ }
3604
+ }
3605
+ }
3606
+ };
3607
+
3608
+ // src/shared-assets/MockSharedAssetsApi.ts
3609
+ var MockSharedAssetsApi = class {
3610
+ constructor(venusApi) {
3611
+ __publicField(this, "venusApi");
3612
+ this.venusApi = venusApi;
3613
+ }
3614
+ async loadAssetsBundle(game, bundleKey, fileType = "stow") {
3615
+ const blob = await this.venusApi.cdn.fetchBlob(`${game}/${bundleKey}.${fileType}`);
3616
+ return await blob.arrayBuffer();
3617
+ }
3618
+ };
3427
3619
 
3428
3620
  // src/shared-assets/embeddedLibrariesManifest.ts
3429
3621
  var DEFAULT_SHARED_LIB_CDN_BASE = "https://venus-static-01293ak.web.app/libs";
@@ -3566,103 +3758,6 @@ function getLibraryDefinition(libraryKey) {
3566
3758
  return definition;
3567
3759
  }
3568
3760
 
3569
- // src/shared-assets/base64Utils.ts
3570
- function base64ToArrayBuffer(base64) {
3571
- const binaryString = atob(base64);
3572
- const len = binaryString.length;
3573
- const bytes = new Uint8Array(len);
3574
- for (let i = 0; i < len; i++) {
3575
- bytes[i] = binaryString.charCodeAt(i);
3576
- }
3577
- return bytes.buffer;
3578
- }
3579
- function base64ToUtf8(base64) {
3580
- if (typeof TextDecoder !== "undefined") {
3581
- const decoder = new TextDecoder("utf-8");
3582
- const buffer = base64ToArrayBuffer(base64);
3583
- return decoder.decode(new Uint8Array(buffer));
3584
- }
3585
- if (typeof globalThis !== "undefined" && typeof globalThis.Buffer !== "undefined") {
3586
- const BufferCtor = globalThis.Buffer;
3587
- return BufferCtor.from(base64, "base64").toString("utf-8");
3588
- }
3589
- const binaryString = atob(base64);
3590
- let result = "";
3591
- for (let i = 0; i < binaryString.length; i++) {
3592
- result += String.fromCharCode(binaryString.charCodeAt(i));
3593
- }
3594
- return decodeURIComponent(escape(result));
3595
- }
3596
-
3597
- // src/shared-assets/RpcSharedAssetsApi.ts
3598
- var RpcSharedAssetsApi = class {
3599
- constructor(rpcClient, venusApi) {
3600
- __publicField(this, "venusApi");
3601
- __publicField(this, "rpcClient");
3602
- this.rpcClient = rpcClient;
3603
- this.venusApi = venusApi;
3604
- }
3605
- async loadAssetsBundle(game, bundleKey, fileType = "stow") {
3606
- try {
3607
- const response = await this.rpcClient.callT("H5_LOAD_EMBEDDED_ASSET" /* H5_LOAD_EMBEDDED_ASSET */, {
3608
- assetKey: bundleKey
3609
- });
3610
- return base64ToArrayBuffer(response.base64Data);
3611
- } catch (err) {
3612
- try {
3613
- const blob = await this.venusApi.cdn.fetchBlob(`${game}/${bundleKey}.${fileType}`);
3614
- return await blob.arrayBuffer();
3615
- } catch (e) {
3616
- throw new Error(`Failed to load ${bundleKey}`);
3617
- }
3618
- }
3619
- }
3620
- async loadLibraryCode(libraryKey) {
3621
- const definition = getLibraryDefinition(libraryKey);
3622
- try {
3623
- const response = await this.rpcClient.callT("H5_LOAD_EMBEDDED_ASSET" /* H5_LOAD_EMBEDDED_ASSET */, {
3624
- assetKey: definition.assetKey
3625
- });
3626
- return base64ToUtf8(response.base64Data);
3627
- } catch (err) {
3628
- console.error(
3629
- `[Venus Libraries] Failed to load ${libraryKey} from host via RPC:`,
3630
- err
3631
- );
3632
- console.warn(
3633
- `[Venus Libraries] Falling back to CDN for ${libraryKey}. This may indicate an asset packaging issue.`
3634
- );
3635
- try {
3636
- const cdnUrl = this.venusApi.cdn.resolveSharedLibUrl(definition.cdnPath);
3637
- const response = await this.venusApi.cdn.fetchFromCdn(cdnUrl);
3638
- return await response.text();
3639
- } catch (cdnError) {
3640
- throw new Error(
3641
- `Failed to load embedded library ${libraryKey}: RPC failed, CDN fallback failed: ${cdnError.message}`
3642
- );
3643
- }
3644
- }
3645
- }
3646
- };
3647
-
3648
- // src/shared-assets/MockSharedAssetsApi.ts
3649
- var MockSharedAssetsApi = class {
3650
- constructor(venusApi) {
3651
- __publicField(this, "venusApi");
3652
- this.venusApi = venusApi;
3653
- }
3654
- async loadAssetsBundle(game, bundleKey, fileType = "stow") {
3655
- const blob = await this.venusApi.cdn.fetchBlob(`${game}/${bundleKey}.${fileType}`);
3656
- return await blob.arrayBuffer();
3657
- }
3658
- async loadLibraryCode(libraryKey) {
3659
- const definition = getLibraryDefinition(libraryKey);
3660
- const url = this.venusApi.cdn.resolveSharedLibUrl(definition.cdnPath);
3661
- const response = await this.venusApi.cdn.fetchFromCdn(url);
3662
- return await response.text();
3663
- }
3664
- };
3665
-
3666
3761
  // src/leaderboard/utils.ts
3667
3762
  var HASH_ALGORITHM_WEB_CRYPTO = "SHA-256";
3668
3763
  var HASH_ALGORITHM_NODE = "sha256";
@@ -4462,7 +4557,7 @@ var RemoteHost = class {
4462
4557
  5e3
4463
4558
  );
4464
4559
  transport.instanceId = response.instanceId;
4465
- this.log(`Remote Host Initialized with id: ${transport.instanceId}`);
4560
+ this.log(`Remote Host Initialized with id: ${transport.instanceId}, response: ${JSON.stringify(response)}`);
4466
4561
  const profile = response.profile;
4467
4562
  const sanitizedProfile = {
4468
4563
  id: profile.id,
@@ -5146,5 +5241,5 @@ function initializeSocial(venusApi, host) {
5146
5241
  }
5147
5242
 
5148
5243
  export { DEFAULT_SHARED_LIB_CDN_BASE, EMBEDDED_LIBRARIES, EMBEDDED_LIBRARY_BY_KEY, HASH_ALGORITHM_NODE, HASH_ALGORITHM_WEB_CRYPTO, HapticFeedbackStyle, HostCdnApi, HostDeviceApi, HostEnvironmentApi, HostProfileApi, HostSystemApi, HostTimeApi, MODULE_TO_LIBRARY_SPECIFIERS, MockAdsApi, MockAiApi, MockAnalyticsApi, MockAvatarApi, MockCdnApi, MockDeviceApi, MockEnvironmentApi, MockFeaturesApi, MockHapticsApi, MockIapApi, MockLeaderboardApi, MockLifecycleApi, MockLoggingApi, MockNavigationApi, MockNotificationsApi, MockPopupsApi, MockPreloaderApi, MockProfileApi, MockSharedAssetsApi, MockSocialApi, MockStorageApi, MockSystemApi, MockTimeApi, RemoteHost, RpcAdsApi, RpcAiApi, RpcAnalyticsApi, RpcAvatarApi, RpcClient, RpcFeaturesApi, RpcHapticsApi, RpcIapApi, RpcLeaderboardApi, RpcLifecycleApi, RpcLoggingApi, RpcNavigationApi, RpcNotificationsApi, RpcPopupsApi, RpcPreloaderApi, RpcRoomsApi, RpcSharedAssetsApi, RpcSimulationApi, RpcSocialApi, RpcStorageApi, SDK_VERSION, VenusMessageId, VenusRoom, base64ToArrayBuffer, base64ToUtf8, computeScoreHash, createHost, createMockStorageApi, getLibraryDefinition, initializeAds, initializeAi, initializeAnalytics, initializeAvatar3d, initializeCdn, initializeFeaturesApi, initializeHaptics, initializeIap, initializeLeaderboard, initializeLifecycleApi, initializeLocalNotifications, initializeLoggingApi, initializePopups, initializePreloader, initializeProfile, initializeRoomsApi, initializeSimulation, initializeSocial, initializeStackNavigation, initializeStorage, initializeSystem, initializeTime, isPacificDaylightTime, setupRoomNotifications };
5149
- //# sourceMappingURL=chunk-AGXMORDL.mjs.map
5150
- //# sourceMappingURL=chunk-AGXMORDL.mjs.map
5244
+ //# sourceMappingURL=chunk-YOBDYPKZ.mjs.map
5245
+ //# sourceMappingURL=chunk-YOBDYPKZ.mjs.map