@schematichq/schematic-react 1.4.1 → 1.6.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/README.md +72 -1
- package/dist/schematic-react.cjs.js +2266 -200
- package/dist/schematic-react.d.ts +847 -22
- package/dist/schematic-react.esm.js +2267 -201
- package/package.json +27 -31
package/README.md
CHANGED
|
@@ -136,6 +136,35 @@ const MyComponent = () => {
|
|
|
136
136
|
|
|
137
137
|
*Note: `useSchematicIsPending` is checking if entitlement data has been loaded, typically via `identify`. It should, therefore, be used to wrap flag and entitlement checks, but never the initial call to `identify`.*
|
|
138
138
|
|
|
139
|
+
For features metered by credit burndown, the same entitlement object carries the company's credit position:
|
|
140
|
+
|
|
141
|
+
| Property | Type | Description |
|
|
142
|
+
| --- | --- | --- |
|
|
143
|
+
| `creditId` | `string \| undefined` | The ID of the credit funding this feature |
|
|
144
|
+
| `creditSettled` | `number \| undefined` | The spendable balance, including any amount held by an open lease. This is the number to show end users |
|
|
145
|
+
| `creditRemaining` | `number \| undefined` | The balance available to fund new consumption, excluding any open lease hold |
|
|
146
|
+
| `creditReserved` | `number \| undefined` | The unspent amount held by an open credit lease, `0` when none is open |
|
|
147
|
+
|
|
148
|
+
All four are `undefined` when the feature is not credit-based.
|
|
149
|
+
|
|
150
|
+
```tsx
|
|
151
|
+
import { useSchematicEntitlement } from "@schematichq/schematic-react";
|
|
152
|
+
import { Feature, OutOfCredits } from "./components";
|
|
153
|
+
|
|
154
|
+
const MyComponent = () => {
|
|
155
|
+
const { creditSettled, value: isFeatureEnabled } =
|
|
156
|
+
useSchematicEntitlement("my-flag-key");
|
|
157
|
+
|
|
158
|
+
if (!isFeatureEnabled) {
|
|
159
|
+
return <OutOfCredits />;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return <Feature creditsRemaining={creditSettled} />;
|
|
163
|
+
};
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
These values refresh with each flag check. For a balance that also updates on the credit partials arriving between checks, pass `creditId` to [`useSchematicCreditBalance`](#credit-balances) instead.
|
|
167
|
+
|
|
139
168
|
### Company plan information
|
|
140
169
|
|
|
141
170
|
To access the current company's plan and trial status, you can use the `useSchematicPlan` hook:
|
|
@@ -175,6 +204,48 @@ The hook returns an object with the following properties:
|
|
|
175
204
|
| `trialEndDate` | `Date \| undefined` | The trial end date, if the company has or had a trial |
|
|
176
205
|
| `trialStatus` | `"active" \| "expired" \| "converted" \| undefined` | The company's trial status: `active` if the trial is ongoing, `expired` if the trial ended without conversion, `converted` if the company converted to a paid plan, or `undefined` if the company has never trialed |
|
|
177
206
|
|
|
207
|
+
### Credit balances
|
|
208
|
+
|
|
209
|
+
To display a company's credit balance, use the `useSchematicCreditBalance` hook. It is keyed by credit ID and updates reactively as the balance changes over the DataStream:
|
|
210
|
+
|
|
211
|
+
```tsx
|
|
212
|
+
import { useSchematicCreditBalance } from "@schematichq/schematic-react";
|
|
213
|
+
|
|
214
|
+
const CreditMeter = () => {
|
|
215
|
+
const { balance, isLoading } = useSchematicCreditBalance("credit-id");
|
|
216
|
+
|
|
217
|
+
if (isLoading) {
|
|
218
|
+
return <div>Loading…</div>;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return <div>{balance} credits remaining</div>;
|
|
222
|
+
};
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
The hook returns an object with the following properties:
|
|
226
|
+
|
|
227
|
+
| Property | Type | Description |
|
|
228
|
+
| --- | --- | --- |
|
|
229
|
+
| `balance` | `number` | The spendable balance, or `0` while loading or when the company holds no balance in this credit |
|
|
230
|
+
| `isLoading` | `boolean` | `true` while the balance is still loading and no value has arrived yet |
|
|
231
|
+
|
|
232
|
+
The credit ID is available on a feature's entitlement, and the hook accepts `string | undefined`, so you can feed it straight through without waiting for the check to arrive:
|
|
233
|
+
|
|
234
|
+
```tsx
|
|
235
|
+
const CreditMeter = () => {
|
|
236
|
+
const { creditId } = useSchematicEntitlement("my-flag-key");
|
|
237
|
+
const { balance, isLoading } = useSchematicCreditBalance(creditId);
|
|
238
|
+
|
|
239
|
+
if (isLoading) {
|
|
240
|
+
return <div>Loading…</div>;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return <div>{balance} credits remaining</div>;
|
|
244
|
+
};
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
While `creditId` is `undefined`, the hook reports the client's loading state and a balance of `0`.
|
|
248
|
+
|
|
178
249
|
## Fallback Behavior
|
|
179
250
|
|
|
180
251
|
The SDK includes built-in fallback behavior you can use to ensure your application continues to function even when unable to reach Schematic (e.g., during service disruptions or network issues).
|
|
@@ -233,7 +304,7 @@ When events (track, identify) cannot be sent due to network issues, they are aut
|
|
|
233
304
|
|
|
234
305
|
### WebSocket Fallback
|
|
235
306
|
|
|
236
|
-
In WebSocket mode, if the WebSocket connection fails, the SDK will provide the last known value or the configured fallback values as [outlined above](
|
|
307
|
+
In WebSocket mode, if the WebSocket connection fails, the SDK will provide the last known value or the configured fallback values as [outlined above](#flag-check-fallbacks). The WebSocket will also automatically attempt to re-establish its connection with Schematic using an exponential backoff.
|
|
237
308
|
|
|
238
309
|
## React Native
|
|
239
310
|
|