@theruntimehq/react 0.2.1 → 0.2.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/README.md CHANGED
@@ -51,7 +51,7 @@ export default function Root() {
51
51
  return (
52
52
  <RuntimeHQProvider
53
53
  runtimeKey="rt_prod_your_key_here"
54
- intervalSeconds={15}
54
+ intervalSeconds={60}
55
55
  >
56
56
  <App />
57
57
  </RuntimeHQProvider>
@@ -114,7 +114,7 @@ import { useRuntimeHQState } from "@theruntimehq/react";
114
114
  function IndependentWidget() {
115
115
  const { runtime, loading, error } = useRuntimeHQState({
116
116
  runtimeKey: "rt_prod_your_key_here",
117
- intervalSeconds: 30,
117
+ intervalSeconds: 60,
118
118
  });
119
119
 
120
120
  if (loading) return <Spinner />;
@@ -195,7 +195,7 @@ interface ClientSidePollerProps {
195
195
  export default function ClientSidePoller({ initialData }: ClientSidePollerProps) {
196
196
  const { runtime } = useRuntimeHQState({
197
197
  runtimeKey: "rt_prod_your_key_here",
198
- intervalSeconds: 15,
198
+ intervalSeconds: 60,
199
199
  });
200
200
 
201
201
  // Hydrate client-side with server-fetched data initially
package/dist/index.cjs CHANGED
@@ -40,7 +40,7 @@ const RuntimeHQContext = (0, react.createContext)(null);
40
40
  * A direct React hook to fetch and watch RuntimeHQ status without using a Context Provider.
41
41
  */
42
42
  function useRuntimeHQState(options) {
43
- const { runtimeKey, intervalSeconds = 15 } = options;
43
+ const { runtimeKey, intervalSeconds = 60 } = options;
44
44
  const [client, clientInitError] = (0, react.useMemo)(() => {
45
45
  if (!runtimeKey) return [null, /* @__PURE__ */ new Error("runtimeKey is required")];
46
46
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["RuntimeHQClient"],"sources":["../src/context/index.ts","../src/hooks/useRuntimeHQState.ts","../src/provider/index.tsx","../src/hooks/useRuntimeHQ.ts","../src/helpers/index.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext } from \"react\";\nimport { RuntimeHQContextValue } from \"../types\";\n\nexport const RuntimeHQContext = createContext<RuntimeHQContextValue | null>(null);\n","\"use client\";\n\nimport { useState, useEffect, useMemo, useCallback } from \"react\";\nimport { RuntimeHQClient } from \"@theruntimehq/js\";\nimport { RuntimeResponse, RuntimeHQContextValue } from \"../types\";\n\nexport interface UseRuntimeHQStateOptions {\n runtimeKey: string;\n intervalSeconds?: number;\n}\n\n/**\n * A direct React hook to fetch and watch RuntimeHQ status without using a Context Provider.\n */\nexport function useRuntimeHQState(options: UseRuntimeHQStateOptions): RuntimeHQContextValue {\n const { runtimeKey, intervalSeconds = 15 } = options;\n\n // Safely instantiate RuntimeHQClient\n const [client, clientInitError] = useMemo(() => {\n if (!runtimeKey) {\n return [null, new Error(\"runtimeKey is required\")] as const;\n }\n try {\n return [new RuntimeHQClient({ runtimeKey }), null] as const;\n } catch (err) {\n return [null, err instanceof Error ? err : new Error(String(err))] as const;\n }\n }, [runtimeKey]);\n\n const [runtime, setRuntime] = useState<RuntimeResponse | null>(null);\n const [error, setError] = useState<Error | null>(clientInitError || null);\n const [loading, setLoading] = useState<boolean>(!clientInitError);\n\n useEffect(() => {\n if (clientInitError) {\n setError(clientInitError);\n setLoading(false);\n return;\n }\n\n if (!client) {\n return;\n }\n\n // Reset states when the client or key changes\n setRuntime(null);\n setError(null);\n setLoading(true);\n\n let active = true;\n\n const unsubscribe = client.watchRuntime({\n intervalSeconds,\n onUpdate: (data) => {\n if (active) {\n setRuntime(data);\n setError(null);\n setLoading(false);\n }\n },\n onError: (err) => {\n if (active) {\n setError(err);\n setLoading(false);\n }\n },\n });\n\n return () => {\n active = false;\n unsubscribe();\n };\n }, [client, clientInitError, intervalSeconds]);\n\n const hasCapability = useCallback((name: string) => {\n return runtime ? runtime.hasCapability(name) : false;\n }, [runtime]);\n\n const getCapabilityState = useCallback((name: string) => {\n return runtime ? runtime.getCapabilityState(name) : undefined;\n }, [runtime]);\n\n return {\n runtime,\n loading,\n error,\n hasCapability,\n getCapabilityState,\n };\n}\n","\"use client\";\n\nimport React from \"react\";\nimport { RuntimeHQContext } from \"../context\";\nimport { useRuntimeHQState } from \"../hooks/useRuntimeHQState\";\n\nexport interface RuntimeHQProviderProps {\n runtimeKey: string;\n intervalSeconds?: number;\n children: React.ReactNode;\n}\n\n/**\n * Context Provider that manages a global RuntimeHQ client subscription and polling loop,\n * making the status state available to all child components using `useRuntimeHQ()`.\n */\nexport function RuntimeHQProvider({\n runtimeKey,\n intervalSeconds,\n children,\n}: RuntimeHQProviderProps) {\n const value = useRuntimeHQState({ runtimeKey, intervalSeconds });\n\n return (\n <RuntimeHQContext.Provider value={value}>\n {children}\n </RuntimeHQContext.Provider>\n );\n}\n","\"use client\";\n\nimport { useContext } from \"react\";\nimport { RuntimeHQContext } from \"../context\";\nimport { RuntimeHQContextValue } from \"../types\";\n\n/**\n * Accesses the global RuntimeHQ status check context.\n * Must be used within a `<RuntimeHQProvider>`.\n */\nexport function useRuntimeHQ(): RuntimeHQContextValue {\n const context = useContext(RuntimeHQContext);\n if (!context) {\n throw new Error(\"useRuntimeHQ must be used within a RuntimeHQProvider\");\n }\n return context;\n}\n","import { RuntimeResponse, RuntimeState, CapabilityState } from \"../types\";\n\ntype StateInput = RuntimeResponse | CapabilityState | RuntimeState | null | undefined;\n\nfunction getState(input: StateInput): RuntimeState | null {\n if (!input) return null;\n if (typeof input === \"string\") return input;\n return input.state || null;\n}\n\n/**\n * Checks if the application runtime status is OPERATIONAL.\n */\nexport function isOperational(input: StateInput): boolean {\n return getState(input) === \"OPERATIONAL\";\n}\n\n/**\n * Checks if the application runtime status is MAINTENANCE.\n */\nexport function isMaintenance(input: StateInput): boolean {\n return getState(input) === \"MAINTENANCE\";\n}\n\n/**\n * Checks if the application runtime status is DEGRADED.\n */\nexport function isDegraded(input: StateInput): boolean {\n return getState(input) === \"DEGRADED\";\n}\n\n/**\n * Checks if the application runtime status is OUTAGE.\n */\nexport function isOutage(input: StateInput): boolean {\n return getState(input) === \"OUTAGE\";\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AO,UAAU,QAAQ,mBAAmB,IAAI,IAAI;EACtD,GAAG,CAAC,OAAO,CAOQ;CACnB;AACF;;;;;;;;ACzEA,SAAgB,kBAAkB,EAChC,YACA,iBACA,YACyB;CACzB,MAAM,QAAQ,kBAAkB;EAAE;EAAY;CAAgB,CAAC;CAE/D,OACE,2CAAC,iBAAiB,UAAlB;EAAkC;EAC/B;CACwB;AAE/B;;;;;;;;AClBA,SAAgB,eAAsC;CACpD,MAAM,gCAAqB,gBAAgB;CAC3C,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,sDAAsD;CAExE,OAAO;AACT;;;;ACZA,SAAS,SAAS,OAAwC;CACxD,IAAI,CAAC,OAAO,OAAO;CACnB,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,OAAO,MAAM,SAAS;AACxB;;;;AAKA,SAAgB,cAAc,OAA4B;CACxD,OAAO,SAAS,KAAK,MAAM;AAC7B;;;;AAKA,SAAgB,cAAc,OAA4B;CACxD,OAAO,SAAS,KAAK,MAAM;AAC7B;;;;AAKA,SAAgB,WAAW,OAA4B;CACrD,OAAO,SAAS,KAAK,MAAM;AAC7B;;;;AAKA,SAAgB,SAAS,OAA4B;CACnD,OAAO,SAAS,KAAK,MAAM;AAC7B"}
1
+ {"version":3,"file":"index.cjs","names":["RuntimeHQClient"],"sources":["../src/context/index.ts","../src/hooks/useRuntimeHQState.ts","../src/provider/index.tsx","../src/hooks/useRuntimeHQ.ts","../src/helpers/index.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext } from \"react\";\nimport { RuntimeHQContextValue } from \"../types\";\n\nexport const RuntimeHQContext = createContext<RuntimeHQContextValue | null>(null);\n","\"use client\";\n\nimport { useState, useEffect, useMemo, useCallback } from \"react\";\nimport { RuntimeHQClient } from \"@theruntimehq/js\";\nimport { RuntimeResponse, RuntimeHQContextValue } from \"../types\";\n\nexport interface UseRuntimeHQStateOptions {\n runtimeKey: string;\n intervalSeconds?: number;\n}\n\n/**\n * A direct React hook to fetch and watch RuntimeHQ status without using a Context Provider.\n */\nexport function useRuntimeHQState(options: UseRuntimeHQStateOptions): RuntimeHQContextValue {\n const { runtimeKey, intervalSeconds = 60 } = options;\n\n // Safely instantiate RuntimeHQClient\n const [client, clientInitError] = useMemo(() => {\n if (!runtimeKey) {\n return [null, new Error(\"runtimeKey is required\")] as const;\n }\n try {\n return [new RuntimeHQClient({ runtimeKey }), null] as const;\n } catch (err) {\n return [null, err instanceof Error ? err : new Error(String(err))] as const;\n }\n }, [runtimeKey]);\n\n const [runtime, setRuntime] = useState<RuntimeResponse | null>(null);\n const [error, setError] = useState<Error | null>(clientInitError || null);\n const [loading, setLoading] = useState<boolean>(!clientInitError);\n\n useEffect(() => {\n if (clientInitError) {\n setError(clientInitError);\n setLoading(false);\n return;\n }\n\n if (!client) {\n return;\n }\n\n // Reset states when the client or key changes\n setRuntime(null);\n setError(null);\n setLoading(true);\n\n let active = true;\n\n const unsubscribe = client.watchRuntime({\n intervalSeconds,\n onUpdate: (data) => {\n if (active) {\n setRuntime(data);\n setError(null);\n setLoading(false);\n }\n },\n onError: (err) => {\n if (active) {\n setError(err);\n setLoading(false);\n }\n },\n });\n\n return () => {\n active = false;\n unsubscribe();\n };\n }, [client, clientInitError, intervalSeconds]);\n\n const hasCapability = useCallback((name: string) => {\n return runtime ? runtime.hasCapability(name) : false;\n }, [runtime]);\n\n const getCapabilityState = useCallback((name: string) => {\n return runtime ? runtime.getCapabilityState(name) : undefined;\n }, [runtime]);\n\n return {\n runtime,\n loading,\n error,\n hasCapability,\n getCapabilityState,\n };\n}\n","\"use client\";\n\nimport React from \"react\";\nimport { RuntimeHQContext } from \"../context\";\nimport { useRuntimeHQState } from \"../hooks/useRuntimeHQState\";\n\nexport interface RuntimeHQProviderProps {\n runtimeKey: string;\n intervalSeconds?: number;\n children: React.ReactNode;\n}\n\n/**\n * Context Provider that manages a global RuntimeHQ client subscription and polling loop,\n * making the status state available to all child components using `useRuntimeHQ()`.\n */\nexport function RuntimeHQProvider({\n runtimeKey,\n intervalSeconds,\n children,\n}: RuntimeHQProviderProps) {\n const value = useRuntimeHQState({ runtimeKey, intervalSeconds });\n\n return (\n <RuntimeHQContext.Provider value={value}>\n {children}\n </RuntimeHQContext.Provider>\n );\n}\n","\"use client\";\n\nimport { useContext } from \"react\";\nimport { RuntimeHQContext } from \"../context\";\nimport { RuntimeHQContextValue } from \"../types\";\n\n/**\n * Accesses the global RuntimeHQ status check context.\n * Must be used within a `<RuntimeHQProvider>`.\n */\nexport function useRuntimeHQ(): RuntimeHQContextValue {\n const context = useContext(RuntimeHQContext);\n if (!context) {\n throw new Error(\"useRuntimeHQ must be used within a RuntimeHQProvider\");\n }\n return context;\n}\n","import { RuntimeResponse, RuntimeState, CapabilityState } from \"../types\";\n\ntype StateInput = RuntimeResponse | CapabilityState | RuntimeState | null | undefined;\n\nfunction getState(input: StateInput): RuntimeState | null {\n if (!input) return null;\n if (typeof input === \"string\") return input;\n return input.state || null;\n}\n\n/**\n * Checks if the application runtime status is OPERATIONAL.\n */\nexport function isOperational(input: StateInput): boolean {\n return getState(input) === \"OPERATIONAL\";\n}\n\n/**\n * Checks if the application runtime status is MAINTENANCE.\n */\nexport function isMaintenance(input: StateInput): boolean {\n return getState(input) === \"MAINTENANCE\";\n}\n\n/**\n * Checks if the application runtime status is DEGRADED.\n */\nexport function isDegraded(input: StateInput): boolean {\n return getState(input) === \"DEGRADED\";\n}\n\n/**\n * Checks if the application runtime status is OUTAGE.\n */\nexport function isOutage(input: StateInput): boolean {\n return getState(input) === \"OUTAGE\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAa,4CAA+D,IAAI;;;;;;;ACShF,SAAgB,kBAAkB,SAA0D;CAC1F,MAAM,EAAE,YAAY,kBAAkB,OAAO;CAG7C,MAAM,CAAC,QAAQ,4CAAiC;EAC9C,IAAI,CAAC,YACH,OAAO,CAAC,sBAAM,IAAI,MAAM,wBAAwB,CAAC;EAEnD,IAAI;GAC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;CACpD,MAAM,gCAAqB,gBAAgB;CAC3C,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,sDAAsD;CAExE,OAAO;AACT;;;;ACZA,SAAS,SAAS,OAAwC;CACxD,IAAI,CAAC,OAAO,OAAO;CACnB,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,OAAO,MAAM,SAAS;AACxB;;;;AAKA,SAAgB,cAAc,OAA4B;CACxD,OAAO,SAAS,KAAK,MAAM;AAC7B;;;;AAKA,SAAgB,cAAc,OAA4B;CACxD,OAAO,SAAS,KAAK,MAAM;AAC7B;;;;AAKA,SAAgB,WAAW,OAA4B;CACrD,OAAO,SAAS,KAAK,MAAM;AAC7B;;;;AAKA,SAAgB,SAAS,OAA4B;CACnD,OAAO,SAAS,KAAK,MAAM;AAC7B"}
package/dist/index.mjs CHANGED
@@ -11,7 +11,7 @@ const RuntimeHQContext = createContext(null);
11
11
  * A direct React hook to fetch and watch RuntimeHQ status without using a Context Provider.
12
12
  */
13
13
  function useRuntimeHQState(options) {
14
- const { runtimeKey, intervalSeconds = 15 } = options;
14
+ const { runtimeKey, intervalSeconds = 60 } = options;
15
15
  const [client, clientInitError] = useMemo(() => {
16
16
  if (!runtimeKey) return [null, /* @__PURE__ */ new Error("runtimeKey is required")];
17
17
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/context/index.ts","../src/hooks/useRuntimeHQState.ts","../src/provider/index.tsx","../src/hooks/useRuntimeHQ.ts","../src/helpers/index.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext } from \"react\";\nimport { RuntimeHQContextValue } from \"../types\";\n\nexport const RuntimeHQContext = createContext<RuntimeHQContextValue | null>(null);\n","\"use client\";\n\nimport { useState, useEffect, useMemo, useCallback } from \"react\";\nimport { RuntimeHQClient } from \"@theruntimehq/js\";\nimport { RuntimeResponse, RuntimeHQContextValue } from \"../types\";\n\nexport interface UseRuntimeHQStateOptions {\n runtimeKey: string;\n intervalSeconds?: number;\n}\n\n/**\n * A direct React hook to fetch and watch RuntimeHQ status without using a Context Provider.\n */\nexport function useRuntimeHQState(options: UseRuntimeHQStateOptions): RuntimeHQContextValue {\n const { runtimeKey, intervalSeconds = 15 } = options;\n\n // Safely instantiate RuntimeHQClient\n const [client, clientInitError] = useMemo(() => {\n if (!runtimeKey) {\n return [null, new Error(\"runtimeKey is required\")] as const;\n }\n try {\n return [new RuntimeHQClient({ runtimeKey }), null] as const;\n } catch (err) {\n return [null, err instanceof Error ? err : new Error(String(err))] as const;\n }\n }, [runtimeKey]);\n\n const [runtime, setRuntime] = useState<RuntimeResponse | null>(null);\n const [error, setError] = useState<Error | null>(clientInitError || null);\n const [loading, setLoading] = useState<boolean>(!clientInitError);\n\n useEffect(() => {\n if (clientInitError) {\n setError(clientInitError);\n setLoading(false);\n return;\n }\n\n if (!client) {\n return;\n }\n\n // Reset states when the client or key changes\n setRuntime(null);\n setError(null);\n setLoading(true);\n\n let active = true;\n\n const unsubscribe = client.watchRuntime({\n intervalSeconds,\n onUpdate: (data) => {\n if (active) {\n setRuntime(data);\n setError(null);\n setLoading(false);\n }\n },\n onError: (err) => {\n if (active) {\n setError(err);\n setLoading(false);\n }\n },\n });\n\n return () => {\n active = false;\n unsubscribe();\n };\n }, [client, clientInitError, intervalSeconds]);\n\n const hasCapability = useCallback((name: string) => {\n return runtime ? runtime.hasCapability(name) : false;\n }, [runtime]);\n\n const getCapabilityState = useCallback((name: string) => {\n return runtime ? runtime.getCapabilityState(name) : undefined;\n }, [runtime]);\n\n return {\n runtime,\n loading,\n error,\n hasCapability,\n getCapabilityState,\n };\n}\n","\"use client\";\n\nimport React from \"react\";\nimport { RuntimeHQContext } from \"../context\";\nimport { useRuntimeHQState } from \"../hooks/useRuntimeHQState\";\n\nexport interface RuntimeHQProviderProps {\n runtimeKey: string;\n intervalSeconds?: number;\n children: React.ReactNode;\n}\n\n/**\n * Context Provider that manages a global RuntimeHQ client subscription and polling loop,\n * making the status state available to all child components using `useRuntimeHQ()`.\n */\nexport function RuntimeHQProvider({\n runtimeKey,\n intervalSeconds,\n children,\n}: RuntimeHQProviderProps) {\n const value = useRuntimeHQState({ runtimeKey, intervalSeconds });\n\n return (\n <RuntimeHQContext.Provider value={value}>\n {children}\n </RuntimeHQContext.Provider>\n );\n}\n","\"use client\";\n\nimport { useContext } from \"react\";\nimport { RuntimeHQContext } from \"../context\";\nimport { RuntimeHQContextValue } from \"../types\";\n\n/**\n * Accesses the global RuntimeHQ status check context.\n * Must be used within a `<RuntimeHQProvider>`.\n */\nexport function useRuntimeHQ(): RuntimeHQContextValue {\n const context = useContext(RuntimeHQContext);\n if (!context) {\n throw new Error(\"useRuntimeHQ must be used within a RuntimeHQProvider\");\n }\n return context;\n}\n","import { RuntimeResponse, RuntimeState, CapabilityState } from \"../types\";\n\ntype StateInput = RuntimeResponse | CapabilityState | RuntimeState | null | undefined;\n\nfunction getState(input: StateInput): RuntimeState | null {\n if (!input) return null;\n if (typeof input === \"string\") return input;\n return input.state || null;\n}\n\n/**\n * Checks if the application runtime status is OPERATIONAL.\n */\nexport function isOperational(input: StateInput): boolean {\n return getState(input) === \"OPERATIONAL\";\n}\n\n/**\n * Checks if the application runtime status is MAINTENANCE.\n */\nexport function isMaintenance(input: StateInput): boolean {\n return getState(input) === \"MAINTENANCE\";\n}\n\n/**\n * Checks if the application runtime status is DEGRADED.\n */\nexport function isDegraded(input: StateInput): boolean {\n return getState(input) === \"DEGRADED\";\n}\n\n/**\n * Checks if the application runtime status is OUTAGE.\n */\nexport function isOutage(input: StateInput): boolean {\n return getState(input) === \"OUTAGE\";\n}\n"],"mappings":";;;;;AAKA,MAAa,mBAAmB,cAA4C,IAAI;;;;;;;ACShF,SAAgB,kBAAkB,SAA0D;CAC1F,MAAM,EAAE,YAAY,kBAAkB,OAAO;CAG7C,MAAM,CAAC,QAAQ,mBAAmB,cAAc;EAC9C,IAAI,CAAC,YACH,OAAO,CAAC,sBAAM,IAAI,MAAM,wBAAwB,CAAC;EAEnD,IAAI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;;;;;;;AClBA,SAAgB,eAAsC;CACpD,MAAM,UAAU,WAAW,gBAAgB;CAC3C,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,sDAAsD;CAExE,OAAO;AACT;;;;ACZA,SAAS,SAAS,OAAwC;CACxD,IAAI,CAAC,OAAO,OAAO;CACnB,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,OAAO,MAAM,SAAS;AACxB;;;;AAKA,SAAgB,cAAc,OAA4B;CACxD,OAAO,SAAS,KAAK,MAAM;AAC7B;;;;AAKA,SAAgB,cAAc,OAA4B;CACxD,OAAO,SAAS,KAAK,MAAM;AAC7B;;;;AAKA,SAAgB,WAAW,OAA4B;CACrD,OAAO,SAAS,KAAK,MAAM;AAC7B;;;;AAKA,SAAgB,SAAS,OAA4B;CACnD,OAAO,SAAS,KAAK,MAAM;AAC7B"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/context/index.ts","../src/hooks/useRuntimeHQState.ts","../src/provider/index.tsx","../src/hooks/useRuntimeHQ.ts","../src/helpers/index.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext } from \"react\";\nimport { RuntimeHQContextValue } from \"../types\";\n\nexport const RuntimeHQContext = createContext<RuntimeHQContextValue | null>(null);\n","\"use client\";\n\nimport { useState, useEffect, useMemo, useCallback } from \"react\";\nimport { RuntimeHQClient } from \"@theruntimehq/js\";\nimport { RuntimeResponse, RuntimeHQContextValue } from \"../types\";\n\nexport interface UseRuntimeHQStateOptions {\n runtimeKey: string;\n intervalSeconds?: number;\n}\n\n/**\n * A direct React hook to fetch and watch RuntimeHQ status without using a Context Provider.\n */\nexport function useRuntimeHQState(options: UseRuntimeHQStateOptions): RuntimeHQContextValue {\n const { runtimeKey, intervalSeconds = 60 } = options;\n\n // Safely instantiate RuntimeHQClient\n const [client, clientInitError] = useMemo(() => {\n if (!runtimeKey) {\n return [null, new Error(\"runtimeKey is required\")] as const;\n }\n try {\n return [new RuntimeHQClient({ runtimeKey }), null] as const;\n } catch (err) {\n return [null, err instanceof Error ? err : new Error(String(err))] as const;\n }\n }, [runtimeKey]);\n\n const [runtime, setRuntime] = useState<RuntimeResponse | null>(null);\n const [error, setError] = useState<Error | null>(clientInitError || null);\n const [loading, setLoading] = useState<boolean>(!clientInitError);\n\n useEffect(() => {\n if (clientInitError) {\n setError(clientInitError);\n setLoading(false);\n return;\n }\n\n if (!client) {\n return;\n }\n\n // Reset states when the client or key changes\n setRuntime(null);\n setError(null);\n setLoading(true);\n\n let active = true;\n\n const unsubscribe = client.watchRuntime({\n intervalSeconds,\n onUpdate: (data) => {\n if (active) {\n setRuntime(data);\n setError(null);\n setLoading(false);\n }\n },\n onError: (err) => {\n if (active) {\n setError(err);\n setLoading(false);\n }\n },\n });\n\n return () => {\n active = false;\n unsubscribe();\n };\n }, [client, clientInitError, intervalSeconds]);\n\n const hasCapability = useCallback((name: string) => {\n return runtime ? runtime.hasCapability(name) : false;\n }, [runtime]);\n\n const getCapabilityState = useCallback((name: string) => {\n return runtime ? runtime.getCapabilityState(name) : undefined;\n }, [runtime]);\n\n return {\n runtime,\n loading,\n error,\n hasCapability,\n getCapabilityState,\n };\n}\n","\"use client\";\n\nimport React from \"react\";\nimport { RuntimeHQContext } from \"../context\";\nimport { useRuntimeHQState } from \"../hooks/useRuntimeHQState\";\n\nexport interface RuntimeHQProviderProps {\n runtimeKey: string;\n intervalSeconds?: number;\n children: React.ReactNode;\n}\n\n/**\n * Context Provider that manages a global RuntimeHQ client subscription and polling loop,\n * making the status state available to all child components using `useRuntimeHQ()`.\n */\nexport function RuntimeHQProvider({\n runtimeKey,\n intervalSeconds,\n children,\n}: RuntimeHQProviderProps) {\n const value = useRuntimeHQState({ runtimeKey, intervalSeconds });\n\n return (\n <RuntimeHQContext.Provider value={value}>\n {children}\n </RuntimeHQContext.Provider>\n );\n}\n","\"use client\";\n\nimport { useContext } from \"react\";\nimport { RuntimeHQContext } from \"../context\";\nimport { RuntimeHQContextValue } from \"../types\";\n\n/**\n * Accesses the global RuntimeHQ status check context.\n * Must be used within a `<RuntimeHQProvider>`.\n */\nexport function useRuntimeHQ(): RuntimeHQContextValue {\n const context = useContext(RuntimeHQContext);\n if (!context) {\n throw new Error(\"useRuntimeHQ must be used within a RuntimeHQProvider\");\n }\n return context;\n}\n","import { RuntimeResponse, RuntimeState, CapabilityState } from \"../types\";\n\ntype StateInput = RuntimeResponse | CapabilityState | RuntimeState | null | undefined;\n\nfunction getState(input: StateInput): RuntimeState | null {\n if (!input) return null;\n if (typeof input === \"string\") return input;\n return input.state || null;\n}\n\n/**\n * Checks if the application runtime status is OPERATIONAL.\n */\nexport function isOperational(input: StateInput): boolean {\n return getState(input) === \"OPERATIONAL\";\n}\n\n/**\n * Checks if the application runtime status is MAINTENANCE.\n */\nexport function isMaintenance(input: StateInput): boolean {\n return getState(input) === \"MAINTENANCE\";\n}\n\n/**\n * Checks if the application runtime status is DEGRADED.\n */\nexport function isDegraded(input: StateInput): boolean {\n return getState(input) === \"DEGRADED\";\n}\n\n/**\n * Checks if the application runtime status is OUTAGE.\n */\nexport function isOutage(input: StateInput): boolean {\n return getState(input) === \"OUTAGE\";\n}\n"],"mappings":";;;;;AAKA,MAAa,mBAAmB,cAA4C,IAAI;;;;;;;ACShF,SAAgB,kBAAkB,SAA0D;CAC1F,MAAM,EAAE,YAAY,kBAAkB,OAAO;CAG7C,MAAM,CAAC,QAAQ,mBAAmB,cAAc;EAC9C,IAAI,CAAC,YACH,OAAO,CAAC,sBAAM,IAAI,MAAM,wBAAwB,CAAC;EAEnD,IAAI;GACF,OAAO,CAAC,IAAI,gBAAgB,EAAE,WAAW,CAAC,GAAG,IAAI;EACnD,SAAS,KAAK;GACZ,OAAO,CAAC,MAAM,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC;EACnE;CACF,GAAG,CAAC,UAAU,CAAC;CAEf,MAAM,CAAC,SAAS,cAAc,SAAiC,IAAI;CACnE,MAAM,CAAC,OAAO,YAAY,SAAuB,mBAAmB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;CACxD,OAAO,SAAS,KAAK,MAAM;AAC7B;;;;AAKA,SAAgB,cAAc,OAA4B;CACxD,OAAO,SAAS,KAAK,MAAM;AAC7B;;;;AAKA,SAAgB,WAAW,OAA4B;CACrD,OAAO,SAAS,KAAK,MAAM;AAC7B;;;;AAKA,SAAgB,SAAS,OAA4B;CACnD,OAAO,SAAS,KAAK,MAAM;AAC7B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theruntimehq/react",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Official React SDK for RuntimeHQ status checking and monitoring.",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -43,7 +43,7 @@
43
43
  "react-dom": ">=18.0.0"
44
44
  },
45
45
  "dependencies": {
46
- "@theruntimehq/js": "^0.2.1"
46
+ "@theruntimehq/js": "^0.2.2"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@testing-library/react": "^15.0.7",