@hyve-sdk/js 2.4.4 → 2.5.0-canary.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/react.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode } from 'react';
2
+ import { ReactNode, CSSProperties } from 'react';
3
3
 
4
4
  /**
5
5
  * Telemetry configuration options
@@ -528,5 +528,21 @@ declare function HyveSdkProvider({ client, config, children, }: HyveSdkProviderP
528
528
  * }
529
529
  */
530
530
  declare function useHyveSdk(): HyveClient;
531
+ interface MachineViewProps {
532
+ /** The machine ID to fetch and render */
533
+ machineId: string;
534
+ /** Optional className applied to the iframe */
535
+ className?: string;
536
+ /** Optional inline styles applied to the iframe */
537
+ style?: CSSProperties;
538
+ }
539
+ /**
540
+ * Fetches the render for a machine by ID and displays it inside a sandboxed iframe.
541
+ * Must be used within a HyveSdkProvider.
542
+ *
543
+ * @example
544
+ * <MachineView machineId="daily-streak" style={{ width: "100%", height: 400 }} />
545
+ */
546
+ declare function MachineView({ machineId, className, style }: MachineViewProps): react_jsx_runtime.JSX.Element | null;
531
547
 
532
- export { HyveSdkProvider, useHyveSdk };
548
+ export { HyveSdkProvider, MachineView, useHyveSdk };
package/dist/react.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode } from 'react';
2
+ import { ReactNode, CSSProperties } from 'react';
3
3
 
4
4
  /**
5
5
  * Telemetry configuration options
@@ -528,5 +528,21 @@ declare function HyveSdkProvider({ client, config, children, }: HyveSdkProviderP
528
528
  * }
529
529
  */
530
530
  declare function useHyveSdk(): HyveClient;
531
+ interface MachineViewProps {
532
+ /** The machine ID to fetch and render */
533
+ machineId: string;
534
+ /** Optional className applied to the iframe */
535
+ className?: string;
536
+ /** Optional inline styles applied to the iframe */
537
+ style?: CSSProperties;
538
+ }
539
+ /**
540
+ * Fetches the render for a machine by ID and displays it inside a sandboxed iframe.
541
+ * Must be used within a HyveSdkProvider.
542
+ *
543
+ * @example
544
+ * <MachineView machineId="daily-streak" style={{ width: "100%", height: 400 }} />
545
+ */
546
+ declare function MachineView({ machineId, className, style }: MachineViewProps): react_jsx_runtime.JSX.Element | null;
531
547
 
532
- export { HyveSdkProvider, useHyveSdk };
548
+ export { HyveSdkProvider, MachineView, useHyveSdk };
package/dist/react.js CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var react_exports = {};
22
22
  __export(react_exports, {
23
23
  HyveSdkProvider: () => HyveSdkProvider,
24
+ MachineView: () => MachineView,
24
25
  useHyveSdk: () => useHyveSdk
25
26
  });
26
27
  module.exports = __toCommonJS(react_exports);
@@ -2228,8 +2229,73 @@ function useHyveSdk() {
2228
2229
  }
2229
2230
  return client;
2230
2231
  }
2232
+ function buildIframeHtml(js) {
2233
+ return `<!DOCTYPE html>
2234
+ <html>
2235
+ <head>
2236
+ <meta name="viewport" content="width=device-width, initial-scale=1">
2237
+ <style>
2238
+ * { box-sizing: border-box; }
2239
+ body {
2240
+ margin: 0;
2241
+ padding: 24px;
2242
+ min-height: 100vh;
2243
+ display: flex;
2244
+ align-items: center;
2245
+ justify-content: center;
2246
+ }
2247
+ #container { width: 100%; max-width: 480px; }
2248
+ </style>
2249
+ </head>
2250
+ <body>
2251
+ <div id="container"></div>
2252
+ <script>
2253
+ var container = document.getElementById('container');
2254
+ ${js}
2255
+ </script>
2256
+ </body>
2257
+ </html>`;
2258
+ }
2259
+ function MachineView({ machineId, className, style }) {
2260
+ const sdk = useHyveSdk();
2261
+ const [state, setState] = (0, import_react.useState)({ status: "loading" });
2262
+ (0, import_react.useEffect)(() => {
2263
+ let cancelled = false;
2264
+ setState({ status: "loading" });
2265
+ sdk.getMachineRender(machineId).then((js) => {
2266
+ if (!cancelled) {
2267
+ setState({ status: "ready", html: buildIframeHtml(js) });
2268
+ }
2269
+ }).catch((err) => {
2270
+ if (!cancelled) {
2271
+ const message = err instanceof Error ? err.message : "Failed to load machine render";
2272
+ setState({ status: "error", message });
2273
+ }
2274
+ });
2275
+ return () => {
2276
+ cancelled = true;
2277
+ };
2278
+ }, [sdk, machineId]);
2279
+ if (state.status === "loading") {
2280
+ return null;
2281
+ }
2282
+ if (state.status === "error") {
2283
+ return null;
2284
+ }
2285
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
2286
+ "iframe",
2287
+ {
2288
+ srcDoc: state.html,
2289
+ className,
2290
+ style,
2291
+ sandbox: "allow-scripts",
2292
+ referrerPolicy: "no-referrer"
2293
+ }
2294
+ );
2295
+ }
2231
2296
  // Annotate the CommonJS export names for ESM import in node:
2232
2297
  0 && (module.exports = {
2233
2298
  HyveSdkProvider,
2299
+ MachineView,
2234
2300
  useHyveSdk
2235
2301
  });
package/dist/react.mjs CHANGED
@@ -2,7 +2,9 @@
2
2
  import {
3
3
  createContext,
4
4
  useContext,
5
- useRef
5
+ useEffect,
6
+ useRef,
7
+ useState
6
8
  } from "react";
7
9
 
8
10
  // src/utils/index.ts
@@ -2207,7 +2209,72 @@ function useHyveSdk() {
2207
2209
  }
2208
2210
  return client;
2209
2211
  }
2212
+ function buildIframeHtml(js) {
2213
+ return `<!DOCTYPE html>
2214
+ <html>
2215
+ <head>
2216
+ <meta name="viewport" content="width=device-width, initial-scale=1">
2217
+ <style>
2218
+ * { box-sizing: border-box; }
2219
+ body {
2220
+ margin: 0;
2221
+ padding: 24px;
2222
+ min-height: 100vh;
2223
+ display: flex;
2224
+ align-items: center;
2225
+ justify-content: center;
2226
+ }
2227
+ #container { width: 100%; max-width: 480px; }
2228
+ </style>
2229
+ </head>
2230
+ <body>
2231
+ <div id="container"></div>
2232
+ <script>
2233
+ var container = document.getElementById('container');
2234
+ ${js}
2235
+ </script>
2236
+ </body>
2237
+ </html>`;
2238
+ }
2239
+ function MachineView({ machineId, className, style }) {
2240
+ const sdk = useHyveSdk();
2241
+ const [state, setState] = useState({ status: "loading" });
2242
+ useEffect(() => {
2243
+ let cancelled = false;
2244
+ setState({ status: "loading" });
2245
+ sdk.getMachineRender(machineId).then((js) => {
2246
+ if (!cancelled) {
2247
+ setState({ status: "ready", html: buildIframeHtml(js) });
2248
+ }
2249
+ }).catch((err) => {
2250
+ if (!cancelled) {
2251
+ const message = err instanceof Error ? err.message : "Failed to load machine render";
2252
+ setState({ status: "error", message });
2253
+ }
2254
+ });
2255
+ return () => {
2256
+ cancelled = true;
2257
+ };
2258
+ }, [sdk, machineId]);
2259
+ if (state.status === "loading") {
2260
+ return null;
2261
+ }
2262
+ if (state.status === "error") {
2263
+ return null;
2264
+ }
2265
+ return /* @__PURE__ */ jsx(
2266
+ "iframe",
2267
+ {
2268
+ srcDoc: state.html,
2269
+ className,
2270
+ style,
2271
+ sandbox: "allow-scripts",
2272
+ referrerPolicy: "no-referrer"
2273
+ }
2274
+ );
2275
+ }
2210
2276
  export {
2211
2277
  HyveSdkProvider,
2278
+ MachineView,
2212
2279
  useHyveSdk
2213
2280
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyve-sdk/js",
3
- "version": "2.4.4",
3
+ "version": "2.5.0-canary.0",
4
4
  "description": "Hyve SDK - TypeScript wrapper for Hyve game server integration",
5
5
  "private": false,
6
6
  "publishConfig": {