@schematichq/schematic-vue 1.6.0 → 1.7.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 +35 -0
- package/dist/schematic-vue.cjs.js +633 -6
- package/dist/schematic-vue.d.ts +473 -5
- package/dist/schematic-vue.esm.js +633 -6
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -280,6 +280,41 @@ const { balance, isLoading } = useSchematicCreditBalance(creditId);
|
|
|
280
280
|
|
|
281
281
|
The composable re-keys to the new credit whenever the source resolves to a different ID. While it resolves to `undefined`, it 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` composable. It updates over the DataStream, so a policy edited or deleted in the dashboard reaches the component without a refetch:
|
|
286
|
+
|
|
287
|
+
```vue
|
|
288
|
+
<script setup lang="ts">
|
|
289
|
+
import { useSchematicCreditSpendPolicies } from "@schematichq/schematic-vue";
|
|
290
|
+
|
|
291
|
+
const { policies, isLoading } = useSchematicCreditSpendPolicies();
|
|
292
|
+
</script>
|
|
293
|
+
|
|
294
|
+
<template>
|
|
295
|
+
<div v-if="isLoading">Loading…</div>
|
|
296
|
+
<ul v-else>
|
|
297
|
+
<li v-for="policy in policies" :key="policy.id">
|
|
298
|
+
<template v-if="policy.kind === 'window' && policy.window">
|
|
299
|
+
{{ policy.scope }} limit: {{ policy.consumed }} of {{ policy.limit }} credits used this {{ policy.window.unit }}
|
|
300
|
+
</template>
|
|
301
|
+
<template v-else>
|
|
302
|
+
{{ policy.scope }} limit: {{ policy.limit }} credits per request
|
|
303
|
+
</template>
|
|
304
|
+
</li>
|
|
305
|
+
</ul>
|
|
306
|
+
</template>
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
The composable returns an object with the following reactive properties:
|
|
310
|
+
|
|
311
|
+
| Property | Type | Description |
|
|
312
|
+
| --- | --- | --- |
|
|
313
|
+
| `policies` | `ComputedRef<CreditSpendPolicies>` | Company-scope policies first, then the user's own; empty when none bind |
|
|
314
|
+
| `isLoading` | `ComputedRef<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
|
+
|
|
283
318
|
## Fallback Behavior
|
|
284
319
|
|
|
285
320
|
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).
|