@schematichq/schematic-vue 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 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:
@@ -173,6 +235,51 @@ The composable returns an object with the following properties:
173
235
  | `trialEndDate` | `Date \| undefined` | The trial end date, if the company has or had a trial |
174
236
  | `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 |
175
237
 
238
+ ### Credit balances
239
+
240
+ To display a company's credit balance, use the `useSchematicCreditBalance` composable. It is keyed by credit ID and updates reactively as the balance changes over the DataStream:
241
+
242
+ ```vue
243
+ <script setup lang="ts">
244
+ import { useSchematicCreditBalance } from "@schematichq/schematic-vue";
245
+
246
+ const { balance, isLoading } = useSchematicCreditBalance("credit-id");
247
+ </script>
248
+
249
+ <template>
250
+ <div v-if="isLoading">Loading…</div>
251
+ <div v-else>{{ balance }} credits remaining</div>
252
+ </template>
253
+ ```
254
+
255
+ The composable returns an object with the following reactive properties:
256
+
257
+ | Property | Type | Description |
258
+ | --- | --- | --- |
259
+ | `balance` | `ComputedRef<number>` | The spendable balance, or `0` while loading or when the company holds no balance in this credit |
260
+ | `isLoading` | `ComputedRef<boolean>` | `true` while the balance is still loading and no value has arrived yet |
261
+
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
+
176
283
  ## Fallback Behavior
177
284
 
178
285
  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 +340,7 @@ When events (track, identify) cannot be sent due to network issues, they are aut
233
340
 
234
341
  ### WebSocket Fallback
235
342
 
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](/#flag-check-fallbacks). The WebSocket will also automatically attempt to re-establish it's connection with Schematic using an exponential backoff.
343
+ 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
344
 
238
345
  ## Options API Support
239
346