@schematichq/schematic-react 1.8.0 → 1.10.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 +37 -0
- package/dist/schematic-react.cjs.js +794 -11
- package/dist/schematic-react.d.ts +511 -10
- package/dist/schematic-react.esm.js +801 -12
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -280,6 +280,43 @@ const CreditMeter = () => {
|
|
|
280
280
|
|
|
281
281
|
While `creditId` is `undefined`, the hook reports the client's loading state and a balance of `0`.
|
|
282
282
|
|
|
283
|
+
### Credit spend policies
|
|
284
|
+
|
|
285
|
+
To show the spend limits that bind the current company and user, use the `useSchematicCreditSpendPolicies` hook. It updates over the DataStream, so a policy edited or deleted in the dashboard reaches the component without a refetch:
|
|
286
|
+
|
|
287
|
+
```tsx
|
|
288
|
+
import { useSchematicCreditSpendPolicies } from "@schematichq/schematic-react";
|
|
289
|
+
|
|
290
|
+
const SpendLimits = () => {
|
|
291
|
+
const { policies, isLoading } = useSchematicCreditSpendPolicies();
|
|
292
|
+
|
|
293
|
+
if (isLoading) {
|
|
294
|
+
return <div>Loading…</div>;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return (
|
|
298
|
+
<ul>
|
|
299
|
+
{policies.map((policy) => (
|
|
300
|
+
<li key={policy.id}>
|
|
301
|
+
{policy.kind === "window" && policy.window
|
|
302
|
+
? `${policy.scope} limit: ${policy.consumed} of ${policy.limit} credits used this ${policy.window.unit}`
|
|
303
|
+
: `${policy.scope} limit: ${policy.limit} credits per request`}
|
|
304
|
+
</li>
|
|
305
|
+
))}
|
|
306
|
+
</ul>
|
|
307
|
+
);
|
|
308
|
+
};
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
| Property | Type | Description |
|
|
312
|
+
| --- | --- | --- |
|
|
313
|
+
| `policies` | `CreditSpendPolicies` | Company-scope policies first, then the user's own; empty when none bind |
|
|
314
|
+
| `isLoading` | `boolean` | `true` while the policies are still loading and nothing has arrived yet |
|
|
315
|
+
|
|
316
|
+
A `per_draw` policy caps a single draw. A `window` policy caps what can be spent in one period: `consumed` is what the current period has spent, `resetsAt` is when the period ends, and `window` names the period. Each new spend sends an updated `consumed`. Once `resetsAt` has passed, read `consumed` as `0` until the next update arrives.
|
|
317
|
+
|
|
318
|
+
The policies are advisory for display: the server and the flag check enforce them.
|
|
319
|
+
|
|
283
320
|
## Fallback Behavior
|
|
284
321
|
|
|
285
322
|
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).
|