@schematichq/schematic-vue 1.5.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 +118 -2
- package/dist/schematic-vue.cjs.js +1044 -22
- package/dist/schematic-vue.d.ts +1124 -6
- package/dist/schematic-vue.esm.js +1052 -23
- package/package.json +23 -27
package/README.md
CHANGED
|
@@ -137,6 +137,68 @@ const {
|
|
|
137
137
|
|
|
138
138
|
_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`._
|
|
139
139
|
|
|
140
|
+
For features metered by credit burndown, the same composable exposes the company's credit position:
|
|
141
|
+
|
|
142
|
+
| Property | Type | Description |
|
|
143
|
+
| --- | --- | --- |
|
|
144
|
+
| `creditId` | `ComputedRef<string \| undefined>` | The ID of the credit funding this feature |
|
|
145
|
+
| `creditSettled` | `ComputedRef<number \| undefined>` | The spendable balance, including any amount held by an open lease. This is the number to show end users |
|
|
146
|
+
| `creditRemaining` | `ComputedRef<number \| undefined>` | The balance available to fund new consumption, excluding any open lease hold |
|
|
147
|
+
| `creditReserved` | `ComputedRef<number \| undefined>` | The unspent amount held by an open credit lease, `0` when none is open |
|
|
148
|
+
|
|
149
|
+
All four unwrap to `undefined` when the feature is not credit-based.
|
|
150
|
+
|
|
151
|
+
```vue
|
|
152
|
+
<script setup lang="ts">
|
|
153
|
+
import { useSchematicEntitlement } from "@schematichq/schematic-vue";
|
|
154
|
+
|
|
155
|
+
const { creditSettled, value: isFeatureEnabled } =
|
|
156
|
+
useSchematicEntitlement("my-flag-key");
|
|
157
|
+
</script>
|
|
158
|
+
|
|
159
|
+
<template>
|
|
160
|
+
<OutOfCredits v-if="!isFeatureEnabled" />
|
|
161
|
+
<Feature v-else :credits-remaining="creditSettled" />
|
|
162
|
+
</template>
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
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.
|
|
166
|
+
|
|
167
|
+
### Usage warnings
|
|
168
|
+
|
|
169
|
+
If a usage warning is configured on the entitlement, the composable exposes it as `warningTiers`, so you can warn a customer before they hit the limit rather than after:
|
|
170
|
+
|
|
171
|
+
| Property | Type | Description |
|
|
172
|
+
| --- | --- | --- |
|
|
173
|
+
| `warningTiers` | `ComputedRef<WarningTier[] \| undefined>` | The usage warning thresholds configured on the entitlement, each a `{ key, value }` pair in the entitlement's usage units. Unwraps to `undefined` when none are configured |
|
|
174
|
+
| `softLimit` | `ComputedRef<number \| undefined>` | For usage-based pricing, the soft limit for overage charges or the next tier boundary |
|
|
175
|
+
|
|
176
|
+
The dashboard writes a single tier under the key `default`.
|
|
177
|
+
|
|
178
|
+
```vue
|
|
179
|
+
<script setup lang="ts">
|
|
180
|
+
import { computed } from "vue";
|
|
181
|
+
import { useSchematicEntitlement } from "@schematichq/schematic-vue";
|
|
182
|
+
|
|
183
|
+
const { featureUsage, warningTiers } = useSchematicEntitlement("my-flag-key");
|
|
184
|
+
|
|
185
|
+
const warning = computed(() =>
|
|
186
|
+
warningTiers.value?.find((tier) => tier.key === "default"),
|
|
187
|
+
);
|
|
188
|
+
const approachingLimit = computed(
|
|
189
|
+
() =>
|
|
190
|
+
typeof featureUsage.value === "number" &&
|
|
191
|
+
typeof warning.value?.value === "number" &&
|
|
192
|
+
featureUsage.value >= warning.value.value,
|
|
193
|
+
);
|
|
194
|
+
</script>
|
|
195
|
+
|
|
196
|
+
<template>
|
|
197
|
+
<ApproachingLimit v-if="approachingLimit" :limit="warning!.value" />
|
|
198
|
+
<Feature />
|
|
199
|
+
</template>
|
|
200
|
+
```
|
|
201
|
+
|
|
140
202
|
### Company plan information
|
|
141
203
|
|
|
142
204
|
To access the current company's plan and trial status, you can use the `useSchematicPlan` composable:
|
|
@@ -197,7 +259,61 @@ The composable returns an object with the following reactive properties:
|
|
|
197
259
|
| `balance` | `ComputedRef<number>` | The spendable balance, or `0` while loading or when the company holds no balance in this credit |
|
|
198
260
|
| `isLoading` | `ComputedRef<boolean>` | `true` while the balance is still loading and no value has arrived yet |
|
|
199
261
|
|
|
200
|
-
The credit ID is available on a feature's entitlement
|
|
262
|
+
The credit ID is available on a feature's entitlement, and the composable accepts a ref or a getter as well as a plain string, so you can feed one straight through:
|
|
263
|
+
|
|
264
|
+
```vue
|
|
265
|
+
<script setup lang="ts">
|
|
266
|
+
import {
|
|
267
|
+
useSchematicCreditBalance,
|
|
268
|
+
useSchematicEntitlement,
|
|
269
|
+
} from "@schematichq/schematic-vue";
|
|
270
|
+
|
|
271
|
+
const { creditId } = useSchematicEntitlement("my-flag-key");
|
|
272
|
+
const { balance, isLoading } = useSchematicCreditBalance(creditId);
|
|
273
|
+
</script>
|
|
274
|
+
|
|
275
|
+
<template>
|
|
276
|
+
<div v-if="isLoading">Loading…</div>
|
|
277
|
+
<div v-else>{{ balance }} credits remaining</div>
|
|
278
|
+
</template>
|
|
279
|
+
```
|
|
280
|
+
|
|
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
|
+
|
|
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.
|
|
201
317
|
|
|
202
318
|
## Fallback Behavior
|
|
203
319
|
|
|
@@ -259,7 +375,7 @@ When events (track, identify) cannot be sent due to network issues, they are aut
|
|
|
259
375
|
|
|
260
376
|
### WebSocket Fallback
|
|
261
377
|
|
|
262
|
-
In WebSocket mode, if the WebSocket connection fails, the SDK will provide the last known value or the configured fallback values as [outlined above](
|
|
378
|
+
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.
|
|
263
379
|
|
|
264
380
|
## Options API Support
|
|
265
381
|
|