@playruo/embed 1.6.0 → 1.7.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/dist/index.cjs CHANGED
@@ -37,6 +37,7 @@ __export(index_exports, {
37
37
  buildEmbedUrl: () => buildEmbedUrl,
38
38
  isPlayruoEmbedMessage: () => isPlayruoEmbedMessage,
39
39
  isPlayruoInternalMessage: () => isPlayruoInternalMessage,
40
+ normalizePlayruoError: () => normalizePlayruoError,
40
41
  resolveVisitorUuid: () => resolveVisitorUuid
41
42
  });
42
43
  module.exports = __toCommonJS(index_exports);
@@ -47,6 +48,37 @@ var PLAYRUO_IFRAME_ALLOW = "cross-origin-isolated; fullscreen *; autoplay *; gam
47
48
  // src/react/playruo-embed.tsx
48
49
  var import_react = require("react");
49
50
 
51
+ // src/post-message-types.ts
52
+ var normalizePlayruoError = (data) => {
53
+ if (typeof data === "string") {
54
+ return { message: data || "Unknown error" };
55
+ }
56
+ if (!data || typeof data !== "object") {
57
+ return { message: "Unknown error" };
58
+ }
59
+ const record = data;
60
+ const message = typeof record.message === "string" && record.message ? record.message : "Unknown error";
61
+ const details = { message };
62
+ if (typeof record.code === "string") {
63
+ details.code = record.code;
64
+ }
65
+ if (typeof record.event === "string") {
66
+ details.event = record.event;
67
+ }
68
+ return details;
69
+ };
70
+ var isPlayruoEmbedMessage = (data) => {
71
+ if (!data || typeof data !== "object") return false;
72
+ const msg = data;
73
+ if (typeof msg.type !== "string") return false;
74
+ return msg.type === "playruo_ready" || msg.type === "playruo_state_update" || msg.type === "playruo_purchase_request" || msg.type === "playruo_demo_completed" || msg.type === "playruo_error" || msg.type === "playruo_session_over" || msg.type === "playruo_stream_start" || msg.type === "playruo_stream_stop" || msg.type === "REQUEST_EXIT_FULLSCREEN" || msg.type === "playruo_event" || msg.type === "playruo_password_required" || msg.type === "playruo_password_not_required" || msg.type === "playruo_password_result";
75
+ };
76
+ var isPlayruoInternalMessage = (data) => {
77
+ if (!data || typeof data !== "object") return false;
78
+ const msg = data;
79
+ return msg.type === "playruo" && typeof msg.action === "string" && (msg.action === "tryNowClick" || msg.action === "exitFullscreen" || msg.action === "mute" || msg.action === "unmute" || msg.action === "submitPassword" || msg.action === "requestPassword") && msg.fromEmbed === true;
80
+ };
81
+
50
82
  // src/url.ts
51
83
  var PLAYRUO_ORIGIN = "https://playruo.live";
52
84
  var normalizeOperation = (operation) => {
@@ -449,7 +481,7 @@ var PlayruoEmbed = ({
449
481
  console.error("[PlayruoEmbed] Failed to start game:", error);
450
482
  setShowGameIframe(false);
451
483
  setErrorMessage("Failed to start game");
452
- onError?.("Failed to start game");
484
+ onError?.("Failed to start game", { message: "Failed to start game" });
453
485
  }
454
486
  }, [
455
487
  enableWindowedLaunch,
@@ -506,8 +538,9 @@ var PlayruoEmbed = ({
506
538
  console.log("\u{1F537} [Embed] playruo_demo_completed received:", data);
507
539
  cleanupEmbedSession({ payload: data });
508
540
  } else if (type === "playruo_error") {
509
- const errorMessage2 = typeof data === "string" ? data : data?.message || "Unknown error";
510
- console.log("\u{1F537} [Embed] playruo_error received:", errorMessage2);
541
+ const details = normalizePlayruoError(data);
542
+ const errorMessage2 = details.message;
543
+ console.log("\u{1F537} [Embed] playruo_error received:", errorMessage2, details);
511
544
  setErrorMessage(errorMessage2);
512
545
  const errorState = {
513
546
  hasPlayedOnce,
@@ -522,7 +555,7 @@ var PlayruoEmbed = ({
522
555
  };
523
556
  setIframeState(errorState);
524
557
  onStateChange?.(errorState);
525
- onError?.(errorMessage2);
558
+ onError?.(errorMessage2, details);
526
559
  } else if (type === "playruo_session_over" && data) {
527
560
  console.log("\u{1F537} [Embed] playruo_session_over received:", data);
528
561
  void exitEmbedFullscreen({ reason: "playruo_session_over" });
@@ -860,7 +893,7 @@ var PlayruoEmbed = ({
860
893
  onError: () => {
861
894
  console.error("[PlayruoEmbed] Iframe failed to load");
862
895
  setErrorMessage("Failed to load game");
863
- onError?.("Failed to load game");
896
+ onError?.("Failed to load game", { message: "Failed to load game" });
864
897
  }
865
898
  }
866
899
  )
@@ -2133,19 +2166,6 @@ var EmbedTester = (props = {}) => {
2133
2166
  }
2134
2167
  );
2135
2168
  };
2136
-
2137
- // src/post-message-types.ts
2138
- var isPlayruoEmbedMessage = (data) => {
2139
- if (!data || typeof data !== "object") return false;
2140
- const msg = data;
2141
- if (typeof msg.type !== "string") return false;
2142
- return msg.type === "playruo_ready" || msg.type === "playruo_state_update" || msg.type === "playruo_purchase_request" || msg.type === "playruo_demo_completed" || msg.type === "playruo_error" || msg.type === "playruo_session_over" || msg.type === "playruo_stream_start" || msg.type === "playruo_stream_stop" || msg.type === "REQUEST_EXIT_FULLSCREEN" || msg.type === "playruo_event" || msg.type === "playruo_password_required" || msg.type === "playruo_password_not_required" || msg.type === "playruo_password_result";
2143
- };
2144
- var isPlayruoInternalMessage = (data) => {
2145
- if (!data || typeof data !== "object") return false;
2146
- const msg = data;
2147
- return msg.type === "playruo" && typeof msg.action === "string" && (msg.action === "tryNowClick" || msg.action === "exitFullscreen" || msg.action === "mute" || msg.action === "unmute" || msg.action === "submitPassword" || msg.action === "requestPassword") && msg.fromEmbed === true;
2148
- };
2149
2169
  // Annotate the CommonJS export names for ESM import in node:
2150
2170
  0 && (module.exports = {
2151
2171
  EmbedTester,
@@ -2155,5 +2175,6 @@ var isPlayruoInternalMessage = (data) => {
2155
2175
  buildEmbedUrl,
2156
2176
  isPlayruoEmbedMessage,
2157
2177
  isPlayruoInternalMessage,
2178
+ normalizePlayruoError,
2158
2179
  resolveVisitorUuid
2159
2180
  });
package/dist/index.d.cts CHANGED
@@ -49,12 +49,35 @@ interface PlayruoDemoCompletedMessage {
49
49
  type: "playruo_demo_completed";
50
50
  data: DemoCompletedPayload;
51
51
  }
52
+ /**
53
+ * What React `onError` sees after normalisation. `code` and `event` come from
54
+ * structured hard errors; extras such as `visibility` are dropped on purpose.
55
+ */
56
+ type PlayruoErrorDetails = {
57
+ message: string;
58
+ code?: string;
59
+ event?: string;
60
+ };
52
61
  interface PlayruoErrorMessage {
53
62
  type: "playruo_error";
63
+ /**
64
+ * Production hard errors carry `code` and `event`. Soft capacity blocks and
65
+ * legacy paths may send only `{ message }` or a bare string. Extra keys may
66
+ * appear on the wire; hosts that go through `normalizePlayruoError` never see
67
+ * them.
68
+ */
54
69
  data: {
55
70
  message: string;
71
+ code?: string;
72
+ event?: string;
56
73
  } | string;
57
74
  }
75
+ /**
76
+ * Reduce a `playruo_error.data` value (or a host-local string) to the shape
77
+ * React `onError` receives. Only string `code` / `event` survive; everything
78
+ * else is dropped so a host cannot grow a dependency on accidental extras.
79
+ */
80
+ declare const normalizePlayruoError: (data: unknown) => PlayruoErrorDetails;
58
81
  interface PlayruoSessionOverMessage {
59
82
  type: "playruo_session_over";
60
83
  data: PlayruoEmbedState;
@@ -204,7 +227,7 @@ interface PlayruoEmbedProps {
204
227
  onPurchaseRequest?: (data: {
205
228
  storeUrl: string;
206
229
  }) => void;
207
- onError?: (error: string) => void;
230
+ onError?: (error: string, details: PlayruoErrorDetails) => void;
208
231
  /** The operation is password protected and waits for one. */
209
232
  onPasswordRequired?: () => void;
210
233
  /** Answer to a submitted password. */
@@ -273,4 +296,4 @@ declare const PLAYRUO_UUID_STORAGE_KEY = "playruo_uuid";
273
296
  */
274
297
  declare const resolveVisitorUuid: (clientFingerprint?: string) => string;
275
298
 
276
- export { type DemoCompletedPayload, EmbedTester, type EmbedTesterProps, PLAYRUO_IFRAME_ALLOW, PLAYRUO_UUID_STORAGE_KEY, type PlayruoDemoCompletedMessage, PlayruoEmbed, type PlayruoEmbedActions, type PlayruoEmbedMessage, type PlayruoEmbedPasswordState, type PlayruoEmbedProps, type PlayruoEmbedRenderState, type PlayruoEmbedState, type PlayruoErrorMessage, type PlayruoEventMessage, type PlayruoEventPayload, type PlayruoInternalMessage, type PlayruoPasswordError, type PlayruoPasswordErrorCode, type PlayruoPasswordNotRequiredMessage, type PlayruoPasswordRequiredMessage, type PlayruoPasswordResultMessage, type PlayruoPurchaseRequestMessage, type PlayruoReadyMessage, type PlayruoRequestExitFullscreenMessage, type PlayruoSessionOverMessage, type PlayruoStateUpdateMessage, type PlayruoStreamStartMessage, type PlayruoStreamStopMessage, buildEmbedUrl, isPlayruoEmbedMessage, isPlayruoInternalMessage, resolveVisitorUuid };
299
+ export { type DemoCompletedPayload, EmbedTester, type EmbedTesterProps, PLAYRUO_IFRAME_ALLOW, PLAYRUO_UUID_STORAGE_KEY, type PlayruoDemoCompletedMessage, PlayruoEmbed, type PlayruoEmbedActions, type PlayruoEmbedMessage, type PlayruoEmbedPasswordState, type PlayruoEmbedProps, type PlayruoEmbedRenderState, type PlayruoEmbedState, type PlayruoErrorDetails, type PlayruoErrorMessage, type PlayruoEventMessage, type PlayruoEventPayload, type PlayruoInternalMessage, type PlayruoPasswordError, type PlayruoPasswordErrorCode, type PlayruoPasswordNotRequiredMessage, type PlayruoPasswordRequiredMessage, type PlayruoPasswordResultMessage, type PlayruoPurchaseRequestMessage, type PlayruoReadyMessage, type PlayruoRequestExitFullscreenMessage, type PlayruoSessionOverMessage, type PlayruoStateUpdateMessage, type PlayruoStreamStartMessage, type PlayruoStreamStopMessage, buildEmbedUrl, isPlayruoEmbedMessage, isPlayruoInternalMessage, normalizePlayruoError, resolveVisitorUuid };
package/dist/index.d.ts CHANGED
@@ -49,12 +49,35 @@ interface PlayruoDemoCompletedMessage {
49
49
  type: "playruo_demo_completed";
50
50
  data: DemoCompletedPayload;
51
51
  }
52
+ /**
53
+ * What React `onError` sees after normalisation. `code` and `event` come from
54
+ * structured hard errors; extras such as `visibility` are dropped on purpose.
55
+ */
56
+ type PlayruoErrorDetails = {
57
+ message: string;
58
+ code?: string;
59
+ event?: string;
60
+ };
52
61
  interface PlayruoErrorMessage {
53
62
  type: "playruo_error";
63
+ /**
64
+ * Production hard errors carry `code` and `event`. Soft capacity blocks and
65
+ * legacy paths may send only `{ message }` or a bare string. Extra keys may
66
+ * appear on the wire; hosts that go through `normalizePlayruoError` never see
67
+ * them.
68
+ */
54
69
  data: {
55
70
  message: string;
71
+ code?: string;
72
+ event?: string;
56
73
  } | string;
57
74
  }
75
+ /**
76
+ * Reduce a `playruo_error.data` value (or a host-local string) to the shape
77
+ * React `onError` receives. Only string `code` / `event` survive; everything
78
+ * else is dropped so a host cannot grow a dependency on accidental extras.
79
+ */
80
+ declare const normalizePlayruoError: (data: unknown) => PlayruoErrorDetails;
58
81
  interface PlayruoSessionOverMessage {
59
82
  type: "playruo_session_over";
60
83
  data: PlayruoEmbedState;
@@ -204,7 +227,7 @@ interface PlayruoEmbedProps {
204
227
  onPurchaseRequest?: (data: {
205
228
  storeUrl: string;
206
229
  }) => void;
207
- onError?: (error: string) => void;
230
+ onError?: (error: string, details: PlayruoErrorDetails) => void;
208
231
  /** The operation is password protected and waits for one. */
209
232
  onPasswordRequired?: () => void;
210
233
  /** Answer to a submitted password. */
@@ -273,4 +296,4 @@ declare const PLAYRUO_UUID_STORAGE_KEY = "playruo_uuid";
273
296
  */
274
297
  declare const resolveVisitorUuid: (clientFingerprint?: string) => string;
275
298
 
276
- export { type DemoCompletedPayload, EmbedTester, type EmbedTesterProps, PLAYRUO_IFRAME_ALLOW, PLAYRUO_UUID_STORAGE_KEY, type PlayruoDemoCompletedMessage, PlayruoEmbed, type PlayruoEmbedActions, type PlayruoEmbedMessage, type PlayruoEmbedPasswordState, type PlayruoEmbedProps, type PlayruoEmbedRenderState, type PlayruoEmbedState, type PlayruoErrorMessage, type PlayruoEventMessage, type PlayruoEventPayload, type PlayruoInternalMessage, type PlayruoPasswordError, type PlayruoPasswordErrorCode, type PlayruoPasswordNotRequiredMessage, type PlayruoPasswordRequiredMessage, type PlayruoPasswordResultMessage, type PlayruoPurchaseRequestMessage, type PlayruoReadyMessage, type PlayruoRequestExitFullscreenMessage, type PlayruoSessionOverMessage, type PlayruoStateUpdateMessage, type PlayruoStreamStartMessage, type PlayruoStreamStopMessage, buildEmbedUrl, isPlayruoEmbedMessage, isPlayruoInternalMessage, resolveVisitorUuid };
299
+ export { type DemoCompletedPayload, EmbedTester, type EmbedTesterProps, PLAYRUO_IFRAME_ALLOW, PLAYRUO_UUID_STORAGE_KEY, type PlayruoDemoCompletedMessage, PlayruoEmbed, type PlayruoEmbedActions, type PlayruoEmbedMessage, type PlayruoEmbedPasswordState, type PlayruoEmbedProps, type PlayruoEmbedRenderState, type PlayruoEmbedState, type PlayruoErrorDetails, type PlayruoErrorMessage, type PlayruoEventMessage, type PlayruoEventPayload, type PlayruoInternalMessage, type PlayruoPasswordError, type PlayruoPasswordErrorCode, type PlayruoPasswordNotRequiredMessage, type PlayruoPasswordRequiredMessage, type PlayruoPasswordResultMessage, type PlayruoPurchaseRequestMessage, type PlayruoReadyMessage, type PlayruoRequestExitFullscreenMessage, type PlayruoSessionOverMessage, type PlayruoStateUpdateMessage, type PlayruoStreamStartMessage, type PlayruoStreamStopMessage, buildEmbedUrl, isPlayruoEmbedMessage, isPlayruoInternalMessage, normalizePlayruoError, resolveVisitorUuid };
package/dist/index.js CHANGED
@@ -4,6 +4,37 @@ var PLAYRUO_IFRAME_ALLOW = "cross-origin-isolated; fullscreen *; autoplay *; gam
4
4
  // src/react/playruo-embed.tsx
5
5
  import { useEffect, useMemo, useRef, useState, useCallback } from "react";
6
6
 
7
+ // src/post-message-types.ts
8
+ var normalizePlayruoError = (data) => {
9
+ if (typeof data === "string") {
10
+ return { message: data || "Unknown error" };
11
+ }
12
+ if (!data || typeof data !== "object") {
13
+ return { message: "Unknown error" };
14
+ }
15
+ const record = data;
16
+ const message = typeof record.message === "string" && record.message ? record.message : "Unknown error";
17
+ const details = { message };
18
+ if (typeof record.code === "string") {
19
+ details.code = record.code;
20
+ }
21
+ if (typeof record.event === "string") {
22
+ details.event = record.event;
23
+ }
24
+ return details;
25
+ };
26
+ var isPlayruoEmbedMessage = (data) => {
27
+ if (!data || typeof data !== "object") return false;
28
+ const msg = data;
29
+ if (typeof msg.type !== "string") return false;
30
+ return msg.type === "playruo_ready" || msg.type === "playruo_state_update" || msg.type === "playruo_purchase_request" || msg.type === "playruo_demo_completed" || msg.type === "playruo_error" || msg.type === "playruo_session_over" || msg.type === "playruo_stream_start" || msg.type === "playruo_stream_stop" || msg.type === "REQUEST_EXIT_FULLSCREEN" || msg.type === "playruo_event" || msg.type === "playruo_password_required" || msg.type === "playruo_password_not_required" || msg.type === "playruo_password_result";
31
+ };
32
+ var isPlayruoInternalMessage = (data) => {
33
+ if (!data || typeof data !== "object") return false;
34
+ const msg = data;
35
+ return msg.type === "playruo" && typeof msg.action === "string" && (msg.action === "tryNowClick" || msg.action === "exitFullscreen" || msg.action === "mute" || msg.action === "unmute" || msg.action === "submitPassword" || msg.action === "requestPassword") && msg.fromEmbed === true;
36
+ };
37
+
7
38
  // src/url.ts
8
39
  var PLAYRUO_ORIGIN = "https://playruo.live";
9
40
  var normalizeOperation = (operation) => {
@@ -406,7 +437,7 @@ var PlayruoEmbed = ({
406
437
  console.error("[PlayruoEmbed] Failed to start game:", error);
407
438
  setShowGameIframe(false);
408
439
  setErrorMessage("Failed to start game");
409
- onError?.("Failed to start game");
440
+ onError?.("Failed to start game", { message: "Failed to start game" });
410
441
  }
411
442
  }, [
412
443
  enableWindowedLaunch,
@@ -463,8 +494,9 @@ var PlayruoEmbed = ({
463
494
  console.log("\u{1F537} [Embed] playruo_demo_completed received:", data);
464
495
  cleanupEmbedSession({ payload: data });
465
496
  } else if (type === "playruo_error") {
466
- const errorMessage2 = typeof data === "string" ? data : data?.message || "Unknown error";
467
- console.log("\u{1F537} [Embed] playruo_error received:", errorMessage2);
497
+ const details = normalizePlayruoError(data);
498
+ const errorMessage2 = details.message;
499
+ console.log("\u{1F537} [Embed] playruo_error received:", errorMessage2, details);
468
500
  setErrorMessage(errorMessage2);
469
501
  const errorState = {
470
502
  hasPlayedOnce,
@@ -479,7 +511,7 @@ var PlayruoEmbed = ({
479
511
  };
480
512
  setIframeState(errorState);
481
513
  onStateChange?.(errorState);
482
- onError?.(errorMessage2);
514
+ onError?.(errorMessage2, details);
483
515
  } else if (type === "playruo_session_over" && data) {
484
516
  console.log("\u{1F537} [Embed] playruo_session_over received:", data);
485
517
  void exitEmbedFullscreen({ reason: "playruo_session_over" });
@@ -817,7 +849,7 @@ var PlayruoEmbed = ({
817
849
  onError: () => {
818
850
  console.error("[PlayruoEmbed] Iframe failed to load");
819
851
  setErrorMessage("Failed to load game");
820
- onError?.("Failed to load game");
852
+ onError?.("Failed to load game", { message: "Failed to load game" });
821
853
  }
822
854
  }
823
855
  )
@@ -2090,19 +2122,6 @@ var EmbedTester = (props = {}) => {
2090
2122
  }
2091
2123
  );
2092
2124
  };
2093
-
2094
- // src/post-message-types.ts
2095
- var isPlayruoEmbedMessage = (data) => {
2096
- if (!data || typeof data !== "object") return false;
2097
- const msg = data;
2098
- if (typeof msg.type !== "string") return false;
2099
- return msg.type === "playruo_ready" || msg.type === "playruo_state_update" || msg.type === "playruo_purchase_request" || msg.type === "playruo_demo_completed" || msg.type === "playruo_error" || msg.type === "playruo_session_over" || msg.type === "playruo_stream_start" || msg.type === "playruo_stream_stop" || msg.type === "REQUEST_EXIT_FULLSCREEN" || msg.type === "playruo_event" || msg.type === "playruo_password_required" || msg.type === "playruo_password_not_required" || msg.type === "playruo_password_result";
2100
- };
2101
- var isPlayruoInternalMessage = (data) => {
2102
- if (!data || typeof data !== "object") return false;
2103
- const msg = data;
2104
- return msg.type === "playruo" && typeof msg.action === "string" && (msg.action === "tryNowClick" || msg.action === "exitFullscreen" || msg.action === "mute" || msg.action === "unmute" || msg.action === "submitPassword" || msg.action === "requestPassword") && msg.fromEmbed === true;
2105
- };
2106
2125
  export {
2107
2126
  EmbedTester,
2108
2127
  PLAYRUO_IFRAME_ALLOW,
@@ -2111,5 +2130,6 @@ export {
2111
2130
  buildEmbedUrl,
2112
2131
  isPlayruoEmbedMessage,
2113
2132
  isPlayruoInternalMessage,
2133
+ normalizePlayruoError,
2114
2134
  resolveVisitorUuid
2115
2135
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playruo/embed",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "React SDK to embed Playruo with postMessage API.",
5
5
  "license": "MIT",
6
6
  "type": "module",