@theruntimehq/react 0.1.2 → 0.2.1

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
@@ -14,6 +14,20 @@ This SDK is a **pure state management SDK** with:
14
14
 
15
15
  ---
16
16
 
17
+ ## Table of Contents
18
+
19
+ - [Installation](#installation)
20
+ - [Core Hooks & Provider APIs](#core-hooks--provider-apis)
21
+ - [1. Global Provider (\`RuntimeHQProvider\`)](#1-global-provider-runtimehqprovider)
22
+ - [2. Context Hook (\`useRuntimeHQ\`)](#2-context-hook-useruntimehq)
23
+ - [3. Standalone Direct Hook (\`useRuntimeHQState\`)](#3-standalone-direct-hook-useruntimehqstate)
24
+ - [Convenience Helpers](#convenience-helpers)
25
+ - [Server Rendering (SSR) & Next.js App Router Integration](#server-rendering-ssr--nextjs-app-router-integration)
26
+ - [Examples Directory](#examples-directory)
27
+ - [License](#license)
28
+
29
+ ---
30
+
17
31
  ## Installation
18
32
 
19
33
  Ensure you have `@theruntimehq/js` and React installed in your project:
@@ -112,7 +126,7 @@ function IndependentWidget() {
112
126
 
113
127
  ## Convenience Helpers
114
128
 
115
- Quickly determine states using utility checkers. These accept either the full `RuntimeResponse` object, the `RuntimeState` string, or `null`/`undefined`.
129
+ Quickly determine states using utility checkers. These accept either the full `RuntimeResponse` object, a `CapabilityState` object, the `RuntimeState` string, or `null`/`undefined`.
116
130
 
117
131
  ```typescript
118
132
  import {
@@ -197,6 +211,36 @@ export default function ClientSidePoller({ initialData }: ClientSidePollerProps)
197
211
  }
198
212
  ```
199
213
 
214
+ ## Examples Directory
215
+
216
+ Check out the [examples directory](./examples) for common integration patterns:
217
+
218
+ | File Name | Business Outcome |
219
+ | :--- | :--- |
220
+ | `01-application-wide-banner.tsx` | Inform all users when the application is degraded, under maintenance, or unavailable. |
221
+ | `02-capability-outage-tooltip.tsx` | Explain why a specific feature is unavailable. |
222
+ | `03-feature-gating.tsx` | Hide unavailable functionality from users. |
223
+ | `04-disable-checkout-when-payments-down.tsx` | Prevent purchases when the payments capability is unavailable. |
224
+ | `05-disable-document-upload-during-maintenance.tsx` | Prevent uploads while the upload capability is under maintenance. |
225
+ | `06-read-only-mode-during-outage.tsx` | Keep the application usable while blocking write operations. |
226
+ | `07-degraded-experience-message.tsx` | Communicate reduced functionality without blocking users. |
227
+ | `08-runtime-status-indicator.tsx` | Show operational status in the application header, footer, or navigation. |
228
+ | `09-customer-facing-status-page.tsx` | Build a public status page powered by RuntimeHQ. |
229
+ | `10-runtime-aware-navigation.tsx` | Hide or disable navigation items for unavailable capabilities. |
230
+ | `11-runtime-aware-routing.tsx` | Prevent access to routes backed by unavailable capabilities. |
231
+ | `12-runtime-aware-redirection.tsx` | Automatically redirect users when a capability becomes unavailable. |
232
+ | `13-runtime-aware-fallback-route.tsx` | Redirect users to an alternative workflow when the primary capability is unavailable. |
233
+ | `14-outage-toast-notifications.tsx` | Notify users immediately when runtime state changes occur. |
234
+ | `15-runtime-dashboard.tsx` | Build an operational dashboard displaying application health and capability health. |
235
+ | `16-multi-application-operations-center.tsx` | Monitor multiple applications from a unified screen. |
236
+ | `17-runtime-aware-error-page.tsx` | Replace generic errors with operationally-aware messaging. |
237
+ | `18-runtime-aware-empty-state.tsx` | Show meaningful empty states when functionality is unavailable. |
238
+ | `19-maintenance-lock-screen.tsx` | Restrict access to workflows during active maintenance windows. |
239
+ | `20-live-system-health-widget.tsx` | Embed a reusable health widget anywhere in the application. |
240
+ | `21-production-ready-provider.tsx` | Complete production integration including provider setup, refresh handling, and resilience patterns. |
241
+
242
+ ---
243
+
200
244
  ## License
201
245
 
202
246
  MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,173 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) {
14
+ __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ }
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
27
+
28
+ //#endregion
29
+ let react = require("react");
30
+ react = __toESM(react);
31
+ let _theruntimehq_js = require("@theruntimehq/js");
32
+ let react_jsx_runtime = require("react/jsx-runtime");
33
+
34
+ //#region src/context/index.ts
35
+ const RuntimeHQContext = (0, react.createContext)(null);
36
+
37
+ //#endregion
38
+ //#region src/hooks/useRuntimeHQState.ts
39
+ /**
40
+ * A direct React hook to fetch and watch RuntimeHQ status without using a Context Provider.
41
+ */
42
+ function useRuntimeHQState(options) {
43
+ const { runtimeKey, intervalSeconds = 15 } = options;
44
+ const [client, clientInitError] = (0, react.useMemo)(() => {
45
+ if (!runtimeKey) return [null, /* @__PURE__ */ new Error("runtimeKey is required")];
46
+ try {
47
+ return [new _theruntimehq_js.RuntimeHQClient({ runtimeKey }), null];
48
+ } catch (err) {
49
+ return [null, err instanceof Error ? err : new Error(String(err))];
50
+ }
51
+ }, [runtimeKey]);
52
+ const [runtime, setRuntime] = (0, react.useState)(null);
53
+ const [error, setError] = (0, react.useState)(clientInitError || null);
54
+ const [loading, setLoading] = (0, react.useState)(!clientInitError);
55
+ (0, react.useEffect)(() => {
56
+ if (clientInitError) {
57
+ setError(clientInitError);
58
+ setLoading(false);
59
+ return;
60
+ }
61
+ if (!client) return;
62
+ setRuntime(null);
63
+ setError(null);
64
+ setLoading(true);
65
+ let active = true;
66
+ const unsubscribe = client.watchRuntime({
67
+ intervalSeconds,
68
+ onUpdate: (data) => {
69
+ if (active) {
70
+ setRuntime(data);
71
+ setError(null);
72
+ setLoading(false);
73
+ }
74
+ },
75
+ onError: (err) => {
76
+ if (active) {
77
+ setError(err);
78
+ setLoading(false);
79
+ }
80
+ }
81
+ });
82
+ return () => {
83
+ active = false;
84
+ unsubscribe();
85
+ };
86
+ }, [
87
+ client,
88
+ clientInitError,
89
+ intervalSeconds
90
+ ]);
91
+ return {
92
+ runtime,
93
+ loading,
94
+ error,
95
+ hasCapability: (0, react.useCallback)((name) => {
96
+ return runtime ? runtime.hasCapability(name) : false;
97
+ }, [runtime]),
98
+ getCapabilityState: (0, react.useCallback)((name) => {
99
+ return runtime ? runtime.getCapabilityState(name) : void 0;
100
+ }, [runtime])
101
+ };
102
+ }
103
+
104
+ //#endregion
105
+ //#region src/provider/index.tsx
106
+ /**
107
+ * Context Provider that manages a global RuntimeHQ client subscription and polling loop,
108
+ * making the status state available to all child components using `useRuntimeHQ()`.
109
+ */
110
+ function RuntimeHQProvider({ runtimeKey, intervalSeconds, children }) {
111
+ const value = useRuntimeHQState({
112
+ runtimeKey,
113
+ intervalSeconds
114
+ });
115
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RuntimeHQContext.Provider, {
116
+ value,
117
+ children
118
+ });
119
+ }
120
+
121
+ //#endregion
122
+ //#region src/hooks/useRuntimeHQ.ts
123
+ /**
124
+ * Accesses the global RuntimeHQ status check context.
125
+ * Must be used within a `<RuntimeHQProvider>`.
126
+ */
127
+ function useRuntimeHQ() {
128
+ const context = (0, react.useContext)(RuntimeHQContext);
129
+ if (!context) throw new Error("useRuntimeHQ must be used within a RuntimeHQProvider");
130
+ return context;
131
+ }
132
+
133
+ //#endregion
134
+ //#region src/helpers/index.ts
135
+ function getState(input) {
136
+ if (!input) return null;
137
+ if (typeof input === "string") return input;
138
+ return input.state || null;
139
+ }
140
+ /**
141
+ * Checks if the application runtime status is OPERATIONAL.
142
+ */
143
+ function isOperational(input) {
144
+ return getState(input) === "OPERATIONAL";
145
+ }
146
+ /**
147
+ * Checks if the application runtime status is MAINTENANCE.
148
+ */
149
+ function isMaintenance(input) {
150
+ return getState(input) === "MAINTENANCE";
151
+ }
152
+ /**
153
+ * Checks if the application runtime status is DEGRADED.
154
+ */
155
+ function isDegraded(input) {
156
+ return getState(input) === "DEGRADED";
157
+ }
158
+ /**
159
+ * Checks if the application runtime status is OUTAGE.
160
+ */
161
+ function isOutage(input) {
162
+ return getState(input) === "OUTAGE";
163
+ }
164
+
165
+ //#endregion
166
+ exports.RuntimeHQProvider = RuntimeHQProvider;
167
+ exports.isDegraded = isDegraded;
168
+ exports.isMaintenance = isMaintenance;
169
+ exports.isOperational = isOperational;
170
+ exports.isOutage = isOutage;
171
+ exports.useRuntimeHQ = useRuntimeHQ;
172
+ exports.useRuntimeHQState = useRuntimeHQState;
173
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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\";\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;GACF,OAAO,CAAC,IAAIA,iCAAgB,EAAE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C,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"}
@@ -0,0 +1,66 @@
1
+ import React from "react";
2
+ import { CapabilityState, CapabilityState as CapabilityState$1, RuntimeHQClientOptions, RuntimeResponse, RuntimeResponse as RuntimeResponse$1, RuntimeState, WatchRuntimeOptions } from "@theruntimehq/js";
3
+
4
+ //#region src/provider/index.d.ts
5
+ interface RuntimeHQProviderProps {
6
+ runtimeKey: string;
7
+ intervalSeconds?: number;
8
+ children: React.ReactNode;
9
+ }
10
+ /**
11
+ * Context Provider that manages a global RuntimeHQ client subscription and polling loop,
12
+ * making the status state available to all child components using `useRuntimeHQ()`.
13
+ */
14
+ declare function RuntimeHQProvider({
15
+ runtimeKey,
16
+ intervalSeconds,
17
+ children
18
+ }: RuntimeHQProviderProps): React.JSX.Element;
19
+ //#endregion
20
+ //#region src/types/index.d.ts
21
+ interface RuntimeHQContextValue {
22
+ runtime: RuntimeResponse$1 | null;
23
+ loading: boolean;
24
+ error: Error | null;
25
+ hasCapability: (name: string) => boolean;
26
+ getCapabilityState: (name: string) => CapabilityState$1 | undefined;
27
+ }
28
+ //#endregion
29
+ //#region src/hooks/useRuntimeHQ.d.ts
30
+ /**
31
+ * Accesses the global RuntimeHQ status check context.
32
+ * Must be used within a `<RuntimeHQProvider>`.
33
+ */
34
+ declare function useRuntimeHQ(): RuntimeHQContextValue;
35
+ //#endregion
36
+ //#region src/hooks/useRuntimeHQState.d.ts
37
+ interface UseRuntimeHQStateOptions {
38
+ runtimeKey: string;
39
+ intervalSeconds?: number;
40
+ }
41
+ /**
42
+ * A direct React hook to fetch and watch RuntimeHQ status without using a Context Provider.
43
+ */
44
+ declare function useRuntimeHQState(options: UseRuntimeHQStateOptions): RuntimeHQContextValue;
45
+ //#endregion
46
+ //#region src/helpers/index.d.ts
47
+ type StateInput = RuntimeResponse | CapabilityState | RuntimeState | null | undefined;
48
+ /**
49
+ * Checks if the application runtime status is OPERATIONAL.
50
+ */
51
+ declare function isOperational(input: StateInput): boolean;
52
+ /**
53
+ * Checks if the application runtime status is MAINTENANCE.
54
+ */
55
+ declare function isMaintenance(input: StateInput): boolean;
56
+ /**
57
+ * Checks if the application runtime status is DEGRADED.
58
+ */
59
+ declare function isDegraded(input: StateInput): boolean;
60
+ /**
61
+ * Checks if the application runtime status is OUTAGE.
62
+ */
63
+ declare function isOutage(input: StateInput): boolean;
64
+ //#endregion
65
+ export { type CapabilityState, type RuntimeHQClientOptions, RuntimeHQContextValue, RuntimeHQProvider, type RuntimeHQProviderProps, type RuntimeResponse, type RuntimeState, type UseRuntimeHQStateOptions, type WatchRuntimeOptions, isDegraded, isMaintenance, isOperational, isOutage, useRuntimeHQ, useRuntimeHQState };
66
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/provider/index.tsx","../src/types/index.ts","../src/hooks/useRuntimeHQ.ts","../src/hooks/useRuntimeHQState.ts","../src/helpers/index.ts"],"mappings":";;;;UAMiB,sBAAA;EACf,UAAA;EACA,eAAA;EACA,QAAA,EAAU,KAAA,CAAM,SAAS;AAAA;;;;;iBAOX,iBAAA;EACd,UAAA;EACA,eAAA;EACA;AAAA,GACC,sBAAA,GAAsB,KAAA,CAAA,GAAA,CAAA,OAAA;;;UCVR,qBAAA;EACf,OAAA,EAAS,iBAAA;EACT,OAAA;EACA,KAAA,EAAO,KAAA;EACP,aAAA,GAAgB,IAAA;EAChB,kBAAA,GAAqB,IAAA,aAAiB,iBAAA;AAAA;;;;;;ADTxC;iBEIgB,YAAA,IAAgB,qBAAqB;;;UCJpC,wBAAA;EACf,UAAA;EACA,eAAe;AAAA;;;;iBAMD,iBAAA,CAAkB,OAAA,EAAS,wBAAA,GAA2B,qBAAqB;;;KCZtF,UAAA,GAAa,eAAA,GAAkB,eAAA,GAAkB,YAAA;;;AJItD;iBIOgB,aAAA,CAAc,KAAiB,EAAV,UAAU;;;;iBAO/B,aAAA,CAAc,KAAiB,EAAV,UAAU;;;;iBAO/B,UAAA,CAAW,KAAiB,EAAV,UAAU;AJlBjB;AAO3B;;AAP2B,iBIyBX,QAAA,CAAS,KAAiB,EAAV,UAAU"}
package/dist/index.d.mts CHANGED
@@ -1,54 +1,66 @@
1
- import React from 'react';
2
- import { RuntimeResponse, RuntimeState } from '@theruntimehq/js';
3
- export { RuntimeHQClientOptions, RuntimeResponse, RuntimeSourceType, RuntimeState, WatchRuntimeOptions } from '@theruntimehq/js';
1
+ import React from "react";
2
+ import { CapabilityState, CapabilityState as CapabilityState$1, RuntimeHQClientOptions, RuntimeResponse, RuntimeResponse as RuntimeResponse$1, RuntimeState, WatchRuntimeOptions } from "@theruntimehq/js";
4
3
 
4
+ //#region src/provider/index.d.ts
5
5
  interface RuntimeHQProviderProps {
6
- runtimeKey: string;
7
- intervalSeconds?: number;
8
- children: React.ReactNode;
6
+ runtimeKey: string;
7
+ intervalSeconds?: number;
8
+ children: React.ReactNode;
9
9
  }
10
10
  /**
11
11
  * Context Provider that manages a global RuntimeHQ client subscription and polling loop,
12
12
  * making the status state available to all child components using `useRuntimeHQ()`.
13
13
  */
14
- declare function RuntimeHQProvider({ runtimeKey, intervalSeconds, children, }: RuntimeHQProviderProps): React.JSX.Element;
15
-
14
+ declare function RuntimeHQProvider({
15
+ runtimeKey,
16
+ intervalSeconds,
17
+ children
18
+ }: RuntimeHQProviderProps): React.JSX.Element;
19
+ //#endregion
20
+ //#region src/types/index.d.ts
16
21
  interface RuntimeHQContextValue {
17
- runtime: RuntimeResponse | null;
18
- loading: boolean;
19
- error: Error | null;
22
+ runtime: RuntimeResponse$1 | null;
23
+ loading: boolean;
24
+ error: Error | null;
25
+ hasCapability: (name: string) => boolean;
26
+ getCapabilityState: (name: string) => CapabilityState$1 | undefined;
20
27
  }
21
-
28
+ //#endregion
29
+ //#region src/hooks/useRuntimeHQ.d.ts
22
30
  /**
23
31
  * Accesses the global RuntimeHQ status check context.
24
32
  * Must be used within a `<RuntimeHQProvider>`.
25
33
  */
26
34
  declare function useRuntimeHQ(): RuntimeHQContextValue;
27
-
35
+ //#endregion
36
+ //#region src/hooks/useRuntimeHQState.d.ts
28
37
  interface UseRuntimeHQStateOptions {
29
- runtimeKey: string;
30
- intervalSeconds?: number;
38
+ runtimeKey: string;
39
+ intervalSeconds?: number;
31
40
  }
32
41
  /**
33
42
  * A direct React hook to fetch and watch RuntimeHQ status without using a Context Provider.
34
43
  */
35
44
  declare function useRuntimeHQState(options: UseRuntimeHQStateOptions): RuntimeHQContextValue;
36
-
45
+ //#endregion
46
+ //#region src/helpers/index.d.ts
47
+ type StateInput = RuntimeResponse | CapabilityState | RuntimeState | null | undefined;
37
48
  /**
38
49
  * Checks if the application runtime status is OPERATIONAL.
39
50
  */
40
- declare function isOperational(runtime: RuntimeResponse | RuntimeState | null | undefined): boolean;
51
+ declare function isOperational(input: StateInput): boolean;
41
52
  /**
42
53
  * Checks if the application runtime status is MAINTENANCE.
43
54
  */
44
- declare function isMaintenance(runtime: RuntimeResponse | RuntimeState | null | undefined): boolean;
55
+ declare function isMaintenance(input: StateInput): boolean;
45
56
  /**
46
57
  * Checks if the application runtime status is DEGRADED.
47
58
  */
48
- declare function isDegraded(runtime: RuntimeResponse | RuntimeState | null | undefined): boolean;
59
+ declare function isDegraded(input: StateInput): boolean;
49
60
  /**
50
61
  * Checks if the application runtime status is OUTAGE.
51
62
  */
52
- declare function isOutage(runtime: RuntimeResponse | RuntimeState | null | undefined): boolean;
53
-
54
- export { type RuntimeHQContextValue, RuntimeHQProvider, type RuntimeHQProviderProps, type UseRuntimeHQStateOptions, isDegraded, isMaintenance, isOperational, isOutage, useRuntimeHQ, useRuntimeHQState };
63
+ declare function isOutage(input: StateInput): boolean;
64
+ //#endregion
65
+ export { type CapabilityState, type RuntimeHQClientOptions, RuntimeHQContextValue, RuntimeHQProvider, type RuntimeHQProviderProps, type RuntimeResponse, type RuntimeState, type UseRuntimeHQStateOptions, type WatchRuntimeOptions, isDegraded, isMaintenance, isOperational, isOutage, useRuntimeHQ, useRuntimeHQState };
66
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/provider/index.tsx","../src/types/index.ts","../src/hooks/useRuntimeHQ.ts","../src/hooks/useRuntimeHQState.ts","../src/helpers/index.ts"],"mappings":";;;;UAMiB,sBAAA;EACf,UAAA;EACA,eAAA;EACA,QAAA,EAAU,KAAA,CAAM,SAAS;AAAA;;;;;iBAOX,iBAAA;EACd,UAAA;EACA,eAAA;EACA;AAAA,GACC,sBAAA,GAAsB,KAAA,CAAA,GAAA,CAAA,OAAA;;;UCVR,qBAAA;EACf,OAAA,EAAS,iBAAA;EACT,OAAA;EACA,KAAA,EAAO,KAAA;EACP,aAAA,GAAgB,IAAA;EAChB,kBAAA,GAAqB,IAAA,aAAiB,iBAAA;AAAA;;;;;;ADTxC;iBEIgB,YAAA,IAAgB,qBAAqB;;;UCJpC,wBAAA;EACf,UAAA;EACA,eAAe;AAAA;;;;iBAMD,iBAAA,CAAkB,OAAA,EAAS,wBAAA,GAA2B,qBAAqB;;;KCZtF,UAAA,GAAa,eAAA,GAAkB,eAAA,GAAkB,YAAA;;;AJItD;iBIOgB,aAAA,CAAc,KAAiB,EAAV,UAAU;;;;iBAO/B,aAAA,CAAc,KAAiB,EAAV,UAAU;;;;iBAO/B,UAAA,CAAW,KAAiB,EAAV,UAAU;AJlBjB;AAO3B;;AAP2B,iBIyBX,QAAA,CAAS,KAAiB,EAAV,UAAU"}
package/dist/index.mjs CHANGED
@@ -1,99 +1,138 @@
1
- import { createContext, useMemo, useState, useEffect, useContext } from 'react';
2
- import { RuntimeHQClient } from '@theruntimehq/js';
3
- import { jsx } from 'react/jsx-runtime';
1
+ import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
2
+ import { RuntimeHQClient } from "@theruntimehq/js";
3
+ import { jsx } from "react/jsx-runtime";
4
4
 
5
- // src/context/index.ts
6
- var RuntimeHQContext = createContext(null);
5
+ //#region src/context/index.ts
6
+ const RuntimeHQContext = createContext(null);
7
+
8
+ //#endregion
9
+ //#region src/hooks/useRuntimeHQState.ts
10
+ /**
11
+ * A direct React hook to fetch and watch RuntimeHQ status without using a Context Provider.
12
+ */
7
13
  function useRuntimeHQState(options) {
8
- const { runtimeKey, intervalSeconds = 15 } = options;
9
- const [client, clientInitError] = useMemo(() => {
10
- if (!runtimeKey) {
11
- return [null, new Error("runtimeKey is required")];
12
- }
13
- try {
14
- return [new RuntimeHQClient({ runtimeKey }), null];
15
- } catch (err) {
16
- return [null, err instanceof Error ? err : new Error(String(err))];
17
- }
18
- }, [runtimeKey]);
19
- const [runtime, setRuntime] = useState(null);
20
- const [error, setError] = useState(clientInitError || null);
21
- const [loading, setLoading] = useState(!clientInitError);
22
- useEffect(() => {
23
- if (clientInitError) {
24
- setError(clientInitError);
25
- setLoading(false);
26
- return;
27
- }
28
- if (!client) {
29
- return;
30
- }
31
- setRuntime(null);
32
- setError(null);
33
- setLoading(true);
34
- let active = true;
35
- const unsubscribe = client.watchRuntime({
36
- intervalSeconds,
37
- onUpdate: (data) => {
38
- if (active) {
39
- setRuntime(data);
40
- setError(null);
41
- setLoading(false);
42
- }
43
- },
44
- onError: (err) => {
45
- if (active) {
46
- setError(err);
47
- setLoading(false);
48
- }
49
- }
50
- });
51
- return () => {
52
- active = false;
53
- unsubscribe();
54
- };
55
- }, [client, clientInitError, intervalSeconds]);
56
- return {
57
- runtime,
58
- loading,
59
- error
60
- };
14
+ const { runtimeKey, intervalSeconds = 15 } = options;
15
+ const [client, clientInitError] = useMemo(() => {
16
+ if (!runtimeKey) return [null, /* @__PURE__ */ new Error("runtimeKey is required")];
17
+ try {
18
+ return [new RuntimeHQClient({ runtimeKey }), null];
19
+ } catch (err) {
20
+ return [null, err instanceof Error ? err : new Error(String(err))];
21
+ }
22
+ }, [runtimeKey]);
23
+ const [runtime, setRuntime] = useState(null);
24
+ const [error, setError] = useState(clientInitError || null);
25
+ const [loading, setLoading] = useState(!clientInitError);
26
+ useEffect(() => {
27
+ if (clientInitError) {
28
+ setError(clientInitError);
29
+ setLoading(false);
30
+ return;
31
+ }
32
+ if (!client) return;
33
+ setRuntime(null);
34
+ setError(null);
35
+ setLoading(true);
36
+ let active = true;
37
+ const unsubscribe = client.watchRuntime({
38
+ intervalSeconds,
39
+ onUpdate: (data) => {
40
+ if (active) {
41
+ setRuntime(data);
42
+ setError(null);
43
+ setLoading(false);
44
+ }
45
+ },
46
+ onError: (err) => {
47
+ if (active) {
48
+ setError(err);
49
+ setLoading(false);
50
+ }
51
+ }
52
+ });
53
+ return () => {
54
+ active = false;
55
+ unsubscribe();
56
+ };
57
+ }, [
58
+ client,
59
+ clientInitError,
60
+ intervalSeconds
61
+ ]);
62
+ return {
63
+ runtime,
64
+ loading,
65
+ error,
66
+ hasCapability: useCallback((name) => {
67
+ return runtime ? runtime.hasCapability(name) : false;
68
+ }, [runtime]),
69
+ getCapabilityState: useCallback((name) => {
70
+ return runtime ? runtime.getCapabilityState(name) : void 0;
71
+ }, [runtime])
72
+ };
61
73
  }
62
- function RuntimeHQProvider({
63
- runtimeKey,
64
- intervalSeconds,
65
- children
66
- }) {
67
- const value = useRuntimeHQState({ runtimeKey, intervalSeconds });
68
- return /* @__PURE__ */ jsx(RuntimeHQContext.Provider, { value, children });
74
+
75
+ //#endregion
76
+ //#region src/provider/index.tsx
77
+ /**
78
+ * Context Provider that manages a global RuntimeHQ client subscription and polling loop,
79
+ * making the status state available to all child components using `useRuntimeHQ()`.
80
+ */
81
+ function RuntimeHQProvider({ runtimeKey, intervalSeconds, children }) {
82
+ const value = useRuntimeHQState({
83
+ runtimeKey,
84
+ intervalSeconds
85
+ });
86
+ return /* @__PURE__ */ jsx(RuntimeHQContext.Provider, {
87
+ value,
88
+ children
89
+ });
69
90
  }
91
+
92
+ //#endregion
93
+ //#region src/hooks/useRuntimeHQ.ts
94
+ /**
95
+ * Accesses the global RuntimeHQ status check context.
96
+ * Must be used within a `<RuntimeHQProvider>`.
97
+ */
70
98
  function useRuntimeHQ() {
71
- const context = useContext(RuntimeHQContext);
72
- if (!context) {
73
- throw new Error("useRuntimeHQ must be used within a RuntimeHQProvider");
74
- }
75
- return context;
99
+ const context = useContext(RuntimeHQContext);
100
+ if (!context) throw new Error("useRuntimeHQ must be used within a RuntimeHQProvider");
101
+ return context;
76
102
  }
77
103
 
78
- // src/helpers/index.ts
79
- function getState(runtime) {
80
- if (!runtime) return null;
81
- if (typeof runtime === "string") return runtime;
82
- return runtime.state || null;
104
+ //#endregion
105
+ //#region src/helpers/index.ts
106
+ function getState(input) {
107
+ if (!input) return null;
108
+ if (typeof input === "string") return input;
109
+ return input.state || null;
83
110
  }
84
- function isOperational(runtime) {
85
- return getState(runtime) === "OPERATIONAL";
111
+ /**
112
+ * Checks if the application runtime status is OPERATIONAL.
113
+ */
114
+ function isOperational(input) {
115
+ return getState(input) === "OPERATIONAL";
86
116
  }
87
- function isMaintenance(runtime) {
88
- return getState(runtime) === "MAINTENANCE";
117
+ /**
118
+ * Checks if the application runtime status is MAINTENANCE.
119
+ */
120
+ function isMaintenance(input) {
121
+ return getState(input) === "MAINTENANCE";
89
122
  }
90
- function isDegraded(runtime) {
91
- return getState(runtime) === "DEGRADED";
123
+ /**
124
+ * Checks if the application runtime status is DEGRADED.
125
+ */
126
+ function isDegraded(input) {
127
+ return getState(input) === "DEGRADED";
92
128
  }
93
- function isOutage(runtime) {
94
- return getState(runtime) === "OUTAGE";
129
+ /**
130
+ * Checks if the application runtime status is OUTAGE.
131
+ */
132
+ function isOutage(input) {
133
+ return getState(input) === "OUTAGE";
95
134
  }
96
135
 
136
+ //#endregion
97
137
  export { RuntimeHQProvider, isDegraded, isMaintenance, isOperational, isOutage, useRuntimeHQ, useRuntimeHQState };
98
- //# sourceMappingURL=index.mjs.map
99
138
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/context/index.ts","../src/hooks/useRuntimeHQState.ts","../src/provider/index.tsx","../src/hooks/useRuntimeHQ.ts","../src/helpers/index.ts"],"names":[],"mappings":";;;;;AAKO,IAAM,gBAAA,GAAmB,cAA4C,IAAI,CAAA;ACSzE,SAAS,kBAAkB,OAAA,EAA0D;AAC1F,EAAA,MAAM,EAAE,UAAA,EAAY,eAAA,GAAkB,EAAA,EAAG,GAAI,OAAA;AAG7C,EAAA,MAAM,CAAC,MAAA,EAAQ,eAAe,CAAA,GAAI,QAAQ,MAAM;AAC9C,IAAA,IAAI,CAAC,UAAA,EAAY;AACf,MAAA,OAAO,CAAC,IAAA,EAAM,IAAI,KAAA,CAAM,wBAAwB,CAAC,CAAA;AAAA,IACnD;AACA,IAAA,IAAI;AACF,MAAA,OAAO,CAAC,IAAI,eAAA,CAAgB,EAAE,UAAA,EAAY,GAAG,IAAI,CAAA;AAAA,IACnD,SAAS,GAAA,EAAK;AACZ,MAAA,OAAO,CAAC,IAAA,EAAM,GAAA,YAAe,KAAA,GAAQ,GAAA,GAAM,IAAI,KAAA,CAAM,MAAA,CAAO,GAAG,CAAC,CAAC,CAAA;AAAA,IACnE;AAAA,EACF,CAAA,EAAG,CAAC,UAAU,CAAC,CAAA;AAEf,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAI,SAAiC,IAAI,CAAA;AACnE,EAAA,MAAM,CAAC,KAAA,E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A,EAChC,UAAA;AAAA,EACA,eAAA;AAAA,EACA;AACF,CAAA,EAA2B;AACzB,EAAA,MAAM,KAAA,GAAQ,iBAAA,CAAkB,EAAE,UAAA,EAAY,iBAAiB,CAAA;AAE/D,EAAA,uBACE,GAAA,CAAC,gBAAA,CAAiB,QAAA,EAAjB,EAA0B,OACxB,QAAA,EACH,CAAA;AAEJ;AClBO,SAAS,YAAA,GAAsC;AACpD,EAAA,MAAM,OAAA,GAAU,WAAW,gBAAgB,CAAA;AAC3C,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,MAAM,sDAAsD,CAAA;AAAA,EACxE;AACA,EAAA,OAAO,OAAA;AACT;;;ACdA,SAAS,SAAS,OAAA,EAAiF;AACjG,EAAA,IAAI,CAAC,SAAS,OAAO,IAAA;AACrB,EAAA,IAAI,OAAO,OAAA,KAAY,QAAA,EAAU,OAAO,OAAA;AACxC,EAAA,OAAO,QAAQ,KAAA,IAAS,IAAA;AAC1B;AAKO,SAAS,cAAc,OAAA,EAAqE;AACjG,EAAA,OAAO,QAAA,CAAS,OAAO,CAAA,KAAM,aAAA;AAC/B;AAKO,SAAS,cAAc,OAAA,EAAqE;AACjG,EAAA,OAAO,QAAA,CAAS,OAAO,CAAA,KAAM,aAAA;AAC/B;AAKO,SAAS,WAAW,OAAA,EAAqE;AAC9F,EAAA,OAAO,QAAA,CAAS,OAAO,CAAA,KAAM,UAAA;AAC/B;AAKO,SAAS,SAAS,OAAA,EAAqE;AAC5F,EAAA,OAAO,QAAA,CAAS,OAAO,CAAA,KAAM,QAAA;AAC/B","file":"index.mjs","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 } 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 return {\n runtime,\n loading,\n error,\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 } from \"../types\";\n\nfunction getState(runtime: RuntimeResponse | RuntimeState | null | undefined): RuntimeState | null {\n if (!runtime) return null;\n if (typeof runtime === \"string\") return runtime;\n return runtime.state || null;\n}\n\n/**\n * Checks if the application runtime status is OPERATIONAL.\n */\nexport function isOperational(runtime: RuntimeResponse | RuntimeState | null | undefined): boolean {\n return getState(runtime) === \"OPERATIONAL\";\n}\n\n/**\n * Checks if the application runtime status is MAINTENANCE.\n */\nexport function isMaintenance(runtime: RuntimeResponse | RuntimeState | null | undefined): boolean {\n return getState(runtime) === \"MAINTENANCE\";\n}\n\n/**\n * Checks if the application runtime status is DEGRADED.\n */\nexport function isDegraded(runtime: RuntimeResponse | RuntimeState | null | undefined): boolean {\n return getState(runtime) === \"DEGRADED\";\n}\n\n/**\n * Checks if the application runtime status is OUTAGE.\n */\nexport function isOutage(runtime: RuntimeResponse | RuntimeState | null | undefined): boolean {\n return getState(runtime) === \"OUTAGE\";\n}\n"]}
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;CAC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zEA,SAAgB,kBAAkB,EAChC,YACA,iBACA,YACyB;CACzB,MAAM,QAAQ,kBAAkB;EAAE;EAAY;CAAgB,CAAC;CAE/D,OACE,oBAAC,iBAAiB,UAAlB;EAAkC;EAC/B;CACwB;AAE/B;;;;;;;;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"}
package/package.json CHANGED
@@ -1,14 +1,17 @@
1
1
  {
2
2
  "name": "@theruntimehq/react",
3
- "version": "0.1.2",
3
+ "version": "0.2.1",
4
4
  "description": "Official React SDK for RuntimeHQ status checking and monitoring.",
5
- "main": "./dist/index.js",
5
+ "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
7
- "types": "./dist/index.d.ts",
7
+ "types": "./dist/index.d.cts",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./dist/index.d.ts",
11
- "require": "./dist/index.js",
10
+ "types": {
11
+ "import": "./dist/index.d.mts",
12
+ "require": "./dist/index.d.cts"
13
+ },
14
+ "require": "./dist/index.cjs",
12
15
  "import": "./dist/index.mjs"
13
16
  }
14
17
  },
@@ -16,7 +19,7 @@
16
19
  "dist"
17
20
  ],
18
21
  "scripts": {
19
- "build": "tsup",
22
+ "build": "tsdown",
20
23
  "test": "vitest run",
21
24
  "prepublishOnly": "npm run build",
22
25
  "postversion": "git push && git push --tags"
@@ -40,7 +43,7 @@
40
43
  "react-dom": ">=18.0.0"
41
44
  },
42
45
  "dependencies": {
43
- "@theruntimehq/js": "^0.1.4"
46
+ "@theruntimehq/js": "^0.2.1"
44
47
  },
45
48
  "devDependencies": {
46
49
  "@testing-library/react": "^15.0.7",
@@ -49,8 +52,8 @@
49
52
  "jsdom": "^24.0.0",
50
53
  "react": "^18.2.0",
51
54
  "react-dom": "^18.2.0",
52
- "tsup": "^8.0.2",
55
+ "tsdown": "^0.22.3",
53
56
  "typescript": "^5.4.5",
54
- "vitest": "^4.1.8"
57
+ "vitest": "^4.1.9"
55
58
  }
56
59
  }
package/dist/index.d.ts DELETED
@@ -1,54 +0,0 @@
1
- import React from 'react';
2
- import { RuntimeResponse, RuntimeState } from '@theruntimehq/js';
3
- export { RuntimeHQClientOptions, RuntimeResponse, RuntimeSourceType, RuntimeState, WatchRuntimeOptions } from '@theruntimehq/js';
4
-
5
- interface RuntimeHQProviderProps {
6
- runtimeKey: string;
7
- intervalSeconds?: number;
8
- children: React.ReactNode;
9
- }
10
- /**
11
- * Context Provider that manages a global RuntimeHQ client subscription and polling loop,
12
- * making the status state available to all child components using `useRuntimeHQ()`.
13
- */
14
- declare function RuntimeHQProvider({ runtimeKey, intervalSeconds, children, }: RuntimeHQProviderProps): React.JSX.Element;
15
-
16
- interface RuntimeHQContextValue {
17
- runtime: RuntimeResponse | null;
18
- loading: boolean;
19
- error: Error | null;
20
- }
21
-
22
- /**
23
- * Accesses the global RuntimeHQ status check context.
24
- * Must be used within a `<RuntimeHQProvider>`.
25
- */
26
- declare function useRuntimeHQ(): RuntimeHQContextValue;
27
-
28
- interface UseRuntimeHQStateOptions {
29
- runtimeKey: string;
30
- intervalSeconds?: number;
31
- }
32
- /**
33
- * A direct React hook to fetch and watch RuntimeHQ status without using a Context Provider.
34
- */
35
- declare function useRuntimeHQState(options: UseRuntimeHQStateOptions): RuntimeHQContextValue;
36
-
37
- /**
38
- * Checks if the application runtime status is OPERATIONAL.
39
- */
40
- declare function isOperational(runtime: RuntimeResponse | RuntimeState | null | undefined): boolean;
41
- /**
42
- * Checks if the application runtime status is MAINTENANCE.
43
- */
44
- declare function isMaintenance(runtime: RuntimeResponse | RuntimeState | null | undefined): boolean;
45
- /**
46
- * Checks if the application runtime status is DEGRADED.
47
- */
48
- declare function isDegraded(runtime: RuntimeResponse | RuntimeState | null | undefined): boolean;
49
- /**
50
- * Checks if the application runtime status is OUTAGE.
51
- */
52
- declare function isOutage(runtime: RuntimeResponse | RuntimeState | null | undefined): boolean;
53
-
54
- export { type RuntimeHQContextValue, RuntimeHQProvider, type RuntimeHQProviderProps, type UseRuntimeHQStateOptions, isDegraded, isMaintenance, isOperational, isOutage, useRuntimeHQ, useRuntimeHQState };
package/dist/index.js DELETED
@@ -1,107 +0,0 @@
1
- 'use strict';
2
-
3
- var react = require('react');
4
- var js = require('@theruntimehq/js');
5
- var jsxRuntime = require('react/jsx-runtime');
6
-
7
- // src/context/index.ts
8
- var RuntimeHQContext = react.createContext(null);
9
- function useRuntimeHQState(options) {
10
- const { runtimeKey, intervalSeconds = 15 } = options;
11
- const [client, clientInitError] = react.useMemo(() => {
12
- if (!runtimeKey) {
13
- return [null, new Error("runtimeKey is required")];
14
- }
15
- try {
16
- return [new js.RuntimeHQClient({ runtimeKey }), null];
17
- } catch (err) {
18
- return [null, err instanceof Error ? err : new Error(String(err))];
19
- }
20
- }, [runtimeKey]);
21
- const [runtime, setRuntime] = react.useState(null);
22
- const [error, setError] = react.useState(clientInitError || null);
23
- const [loading, setLoading] = react.useState(!clientInitError);
24
- react.useEffect(() => {
25
- if (clientInitError) {
26
- setError(clientInitError);
27
- setLoading(false);
28
- return;
29
- }
30
- if (!client) {
31
- return;
32
- }
33
- setRuntime(null);
34
- setError(null);
35
- setLoading(true);
36
- let active = true;
37
- const unsubscribe = client.watchRuntime({
38
- intervalSeconds,
39
- onUpdate: (data) => {
40
- if (active) {
41
- setRuntime(data);
42
- setError(null);
43
- setLoading(false);
44
- }
45
- },
46
- onError: (err) => {
47
- if (active) {
48
- setError(err);
49
- setLoading(false);
50
- }
51
- }
52
- });
53
- return () => {
54
- active = false;
55
- unsubscribe();
56
- };
57
- }, [client, clientInitError, intervalSeconds]);
58
- return {
59
- runtime,
60
- loading,
61
- error
62
- };
63
- }
64
- function RuntimeHQProvider({
65
- runtimeKey,
66
- intervalSeconds,
67
- children
68
- }) {
69
- const value = useRuntimeHQState({ runtimeKey, intervalSeconds });
70
- return /* @__PURE__ */ jsxRuntime.jsx(RuntimeHQContext.Provider, { value, children });
71
- }
72
- function useRuntimeHQ() {
73
- const context = react.useContext(RuntimeHQContext);
74
- if (!context) {
75
- throw new Error("useRuntimeHQ must be used within a RuntimeHQProvider");
76
- }
77
- return context;
78
- }
79
-
80
- // src/helpers/index.ts
81
- function getState(runtime) {
82
- if (!runtime) return null;
83
- if (typeof runtime === "string") return runtime;
84
- return runtime.state || null;
85
- }
86
- function isOperational(runtime) {
87
- return getState(runtime) === "OPERATIONAL";
88
- }
89
- function isMaintenance(runtime) {
90
- return getState(runtime) === "MAINTENANCE";
91
- }
92
- function isDegraded(runtime) {
93
- return getState(runtime) === "DEGRADED";
94
- }
95
- function isOutage(runtime) {
96
- return getState(runtime) === "OUTAGE";
97
- }
98
-
99
- exports.RuntimeHQProvider = RuntimeHQProvider;
100
- exports.isDegraded = isDegraded;
101
- exports.isMaintenance = isMaintenance;
102
- exports.isOperational = isOperational;
103
- exports.isOutage = isOutage;
104
- exports.useRuntimeHQ = useRuntimeHQ;
105
- exports.useRuntimeHQState = useRuntimeHQState;
106
- //# sourceMappingURL=index.js.map
107
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/context/index.ts","../src/hooks/useRuntimeHQState.ts","../src/provider/index.tsx","../src/hooks/useRuntimeHQ.ts","../src/helpers/index.ts"],"names":["createContext","use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E;AACA,EAAA,OAAO,OAAA;AACT;;;ACdA,SAAS,SAAS,OAAA,EAAiF;AACjG,EAAA,IAAI,CAAC,SAAS,OAAO,IAAA;AACrB,EAAA,IAAI,OAAO,OAAA,KAAY,QAAA,EAAU,OAAO,OAAA;AACxC,EAAA,OAAO,QAAQ,KAAA,IAAS,IAAA;AAC1B;AAKO,SAAS,cAAc,OAAA,EAAqE;AACjG,EAAA,OAAO,QAAA,CAAS,OAAO,CAAA,KAAM,aAAA;AAC/B;AAKO,SAAS,cAAc,OAAA,EAAqE;AACjG,EAAA,OAAO,QAAA,CAAS,OAAO,CAAA,KAAM,aAAA;AAC/B;AAKO,SAAS,WAAW,OAAA,EAAqE;AAC9F,EAAA,OAAO,QAAA,CAAS,OAAO,CAAA,KAAM,UAAA;AAC/B;AAKO,SAAS,SAAS,OAAA,EAAqE;AAC5F,EAAA,OAAO,QAAA,CAAS,OAAO,CAAA,KAAM,QAAA;AAC/B","file":"index.js","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 } 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 return {\n runtime,\n loading,\n error,\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 } from \"../types\";\n\nfunction getState(runtime: RuntimeResponse | RuntimeState | null | undefined): RuntimeState | null {\n if (!runtime) return null;\n if (typeof runtime === \"string\") return runtime;\n return runtime.state || null;\n}\n\n/**\n * Checks if the application runtime status is OPERATIONAL.\n */\nexport function isOperational(runtime: RuntimeResponse | RuntimeState | null | undefined): boolean {\n return getState(runtime) === \"OPERATIONAL\";\n}\n\n/**\n * Checks if the application runtime status is MAINTENANCE.\n */\nexport function isMaintenance(runtime: RuntimeResponse | RuntimeState | null | undefined): boolean {\n return getState(runtime) === \"MAINTENANCE\";\n}\n\n/**\n * Checks if the application runtime status is DEGRADED.\n */\nexport function isDegraded(runtime: RuntimeResponse | RuntimeState | null | undefined): boolean {\n return getState(runtime) === \"DEGRADED\";\n}\n\n/**\n * Checks if the application runtime status is OUTAGE.\n */\nexport function isOutage(runtime: RuntimeResponse | RuntimeState | null | undefined): boolean {\n return getState(runtime) === \"OUTAGE\";\n}\n"]}