@wvdsh/sdk-js 1.3.0 → 1.3.2

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.d.ts CHANGED
@@ -871,9 +871,11 @@ declare class WavedashSDK extends EventTarget {
871
871
  overlayManager: OverlayManager;
872
872
  private gameplayJwt;
873
873
  private gameplayJwtPromise;
874
+ private setupWarningTimeout;
874
875
  ugcHost: string;
875
876
  uploadsHost: string;
876
877
  constructor(sdkConfig: SDKConfig);
878
+ private clearSetupWarning;
877
879
  init(config?: WavedashConfig): boolean;
878
880
  /**
879
881
  * Signal that the game is ready to receive events (LobbyJoined, LobbyMessage, etc).
@@ -1137,8 +1139,12 @@ declare class WavedashSDK extends EventTarget {
1137
1139
  * fetcher wired into `ConvexClient.setAuth` and honors `forceRefresh` so the
1138
1140
  * server can invalidate a stale token.
1139
1141
  *
1142
+ * Same-origin POST to /auth/refresh on the play domain — the
1143
+ * gameplaySession cookie set by the play server during playKey exchange
1144
+ * authenticates the request, so no cross-origin credentials handling needed.
1145
+ *
1140
1146
  * Concurrent callers share a single in-flight fetch to avoid duplicate
1141
- * requests to the parent's gameplay-token endpoint.
1147
+ * refresh round-trips.
1142
1148
  */
1143
1149
  private getAuthToken;
1144
1150
  /**
package/dist/index.js CHANGED
@@ -3033,18 +3033,13 @@ var WavedashLogger = class {
3033
3033
  };
3034
3034
 
3035
3035
  // src/utils/parentOrigin.ts
3036
- function deriveParentOrigin() {
3037
- if (typeof window === "undefined") return "";
3038
- const iframeHost = window.location.host;
3039
- const match = iframeHost.match(/^[\w-]+\.(builds|local)\.(.+)$/);
3040
- if (match) {
3041
- const parentDomain = match[2];
3042
- return `${window.location.protocol}//${parentDomain}`;
3043
- }
3044
- console.error(`Invalid iframe hostname pattern: ${iframeHost}`);
3045
- return "";
3036
+ var _parentOrigin = "";
3037
+ function setParentOrigin(origin) {
3038
+ _parentOrigin = origin;
3039
+ }
3040
+ function getParentOrigin() {
3041
+ return _parentOrigin;
3046
3042
  }
3047
- var parentOrigin = deriveParentOrigin();
3048
3043
 
3049
3044
  // src/utils/iframeMessenger.ts
3050
3045
  var RESPONSE_TIMEOUT_MS = 15e3;
@@ -3052,7 +3047,7 @@ var IFrameMessenger = class {
3052
3047
  constructor() {
3053
3048
  // Arrow function automatically captures 'this' from the class instance
3054
3049
  this.handleMessage = (event) => {
3055
- if (event.origin !== parentOrigin) {
3050
+ if (event.origin !== getParentOrigin()) {
3056
3051
  if (event.source !== window) {
3057
3052
  console.warn(`Ignored message from untrusted origin: ${event.origin}`);
3058
3053
  }
@@ -3097,12 +3092,14 @@ var IFrameMessenger = class {
3097
3092
  this.listeners.get(type)?.delete(listener);
3098
3093
  }
3099
3094
  postToParent(requestType, data) {
3095
+ const parentOrigin = getParentOrigin();
3100
3096
  if (typeof window === "undefined" || !parentOrigin) return false;
3101
3097
  window.parent.postMessage({ type: requestType, ...data }, parentOrigin);
3102
3098
  return true;
3103
3099
  }
3104
3100
  async requestFromParent(requestType, data) {
3105
3101
  return new Promise((resolve, reject) => {
3102
+ const parentOrigin = getParentOrigin();
3106
3103
  if (typeof window === "undefined" || !parentOrigin) {
3107
3104
  reject(new Error("Parent origin not found"));
3108
3105
  return;
@@ -3261,6 +3258,7 @@ var WavedashSDK = class extends EventTarget {
3261
3258
  this.engineInstance = null;
3262
3259
  this.gameplayJwt = null;
3263
3260
  this.gameplayJwtPromise = null;
3261
+ this.setupWarningTimeout = null;
3264
3262
  // ==============
3265
3263
  // Event listening
3266
3264
  // ==============
@@ -3300,6 +3298,12 @@ var WavedashSDK = class extends EventTarget {
3300
3298
  ]);
3301
3299
  this.setupSessionEndListeners();
3302
3300
  this.launchParams = sdkConfig.launchParams ?? {};
3301
+ this.setupWarningTimeout = setTimeout(() => {
3302
+ this.setupWarningTimeout = null;
3303
+ this.logger.warn(
3304
+ "Wavedash.init(), Wavedash.loadComplete(), or Wavedash.updateLoadProgressZeroToOne() not called yet"
3305
+ );
3306
+ }, 1e4);
3303
3307
  }
3304
3308
  get initialized() {
3305
3309
  return this._initialized;
@@ -3307,6 +3311,12 @@ var WavedashSDK = class extends EventTarget {
3307
3311
  get eventsReady() {
3308
3312
  return this._eventsReady;
3309
3313
  }
3314
+ clearSetupWarning() {
3315
+ if (this.setupWarningTimeout !== null) {
3316
+ clearTimeout(this.setupWarningTimeout);
3317
+ this.setupWarningTimeout = null;
3318
+ }
3319
+ }
3310
3320
  // =============
3311
3321
  // Setup methods
3312
3322
  // =============
@@ -3409,11 +3419,13 @@ var WavedashSDK = class extends EventTarget {
3409
3419
  [["progress", vNumber]],
3410
3420
  [progress]
3411
3421
  );
3422
+ this.clearSetupWarning();
3412
3423
  iframeMessenger.postToParent(IFRAME_MESSAGE_TYPE5.PROGRESS_UPDATE, {
3413
3424
  progress
3414
3425
  });
3415
3426
  }
3416
3427
  loadComplete() {
3428
+ this.clearSetupWarning();
3417
3429
  if (this.gameFinishedLoading) return;
3418
3430
  this.gameFinishedLoading = true;
3419
3431
  this.heartbeatManager.start();
@@ -4160,8 +4172,12 @@ var WavedashSDK = class extends EventTarget {
4160
4172
  * fetcher wired into `ConvexClient.setAuth` and honors `forceRefresh` so the
4161
4173
  * server can invalidate a stale token.
4162
4174
  *
4175
+ * Same-origin POST to /auth/refresh on the play domain — the
4176
+ * gameplaySession cookie set by the play server during playKey exchange
4177
+ * authenticates the request, so no cross-origin credentials handling needed.
4178
+ *
4163
4179
  * Concurrent callers share a single in-flight fetch to avoid duplicate
4164
- * requests to the parent's gameplay-token endpoint.
4180
+ * refresh round-trips.
4165
4181
  */
4166
4182
  getAuthToken(forceRefresh = false) {
4167
4183
  if (!forceRefresh && this.gameplayJwt) {
@@ -4171,14 +4187,12 @@ var WavedashSDK = class extends EventTarget {
4171
4187
  return this.gameplayJwtPromise;
4172
4188
  }
4173
4189
  const promise = (async () => {
4174
- const response = await fetch(
4175
- `${parentOrigin}/auth/gameplay_token/${this.gameCloudId}`,
4176
- {
4177
- credentials: "include"
4178
- }
4179
- );
4190
+ const response = await fetch("/auth/refresh", {
4191
+ method: "POST",
4192
+ credentials: "same-origin"
4193
+ });
4180
4194
  if (!response.ok) {
4181
- throw new Error(`Failed to fetch gameplay token: ${response.status}`);
4195
+ throw new Error(`Failed to refresh gameplay token: ${response.status}`);
4182
4196
  }
4183
4197
  this.gameplayJwt = await response.text();
4184
4198
  return this.gameplayJwt;
@@ -4263,6 +4277,7 @@ function setupWavedashSDK() {
4263
4277
  `Wavedash SDK: failed to parse ?${UrlParams.SdkConfig}= as JSON: ${message}`
4264
4278
  );
4265
4279
  }
4280
+ setParentOrigin(sdkConfig.parentOrigin);
4266
4281
  const sdk = new WavedashSDK(sdkConfig);
4267
4282
  window.Wavedash = sdk;
4268
4283
  window.WavedashJS = sdk;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wvdsh/sdk-js",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "type": "module",
5
5
  "description": "Wavedash JavaScript SDK",
6
6
  "main": "./dist/client.js",
@@ -49,7 +49,7 @@
49
49
  "typescript-eslint": "^8.52.0"
50
50
  },
51
51
  "dependencies": {
52
- "@wvdsh/api": "^0.1.3",
52
+ "@wvdsh/api": "^0.1.9",
53
53
  "convex": "^1.34.0",
54
54
  "lodash.debounce": "^4.0.8"
55
55
  }