@schematichq/schematic-angular 1.5.0 → 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
|
@@ -202,6 +202,86 @@ export class EntitlementComponent {
|
|
|
202
202
|
|
|
203
203
|
*Note: `isPending$` checks if entitlement data has been loaded, typically via `identify`. It should be used to wrap flag and entitlement checks, but never the initial call to `identify`.*
|
|
204
204
|
|
|
205
|
+
For features metered by credit burndown, the emitted entitlement also carries the company's credit position:
|
|
206
|
+
|
|
207
|
+
| Property | Type | Description |
|
|
208
|
+
| --- | --- | --- |
|
|
209
|
+
| `creditId` | `string \| undefined` | The ID of the credit funding this feature |
|
|
210
|
+
| `creditSettled` | `number \| undefined` | The spendable balance, including any amount held by an open lease. This is the number to show end users |
|
|
211
|
+
| `creditRemaining` | `number \| undefined` | The balance available to fund new consumption, excluding any open lease hold |
|
|
212
|
+
| `creditReserved` | `number \| undefined` | The unspent amount held by an open credit lease, `0` when none is open |
|
|
213
|
+
|
|
214
|
+
All four are `undefined` when the feature is not credit-based.
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
@Component({
|
|
218
|
+
selector: "app-credit-feature",
|
|
219
|
+
standalone: true,
|
|
220
|
+
imports: [AsyncPipe],
|
|
221
|
+
template: `
|
|
222
|
+
@if (entitlement$ | async; as entitlement) {
|
|
223
|
+
@if (entitlement.value) {
|
|
224
|
+
<app-feature [creditsRemaining]="entitlement.creditSettled" />
|
|
225
|
+
} @else {
|
|
226
|
+
<app-out-of-credits />
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
`,
|
|
230
|
+
})
|
|
231
|
+
export class CreditFeatureComponent {
|
|
232
|
+
private schematic = inject(SchematicService);
|
|
233
|
+
entitlement$ = this.schematic.entitlement$("my-flag-key");
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
These values refresh with each flag check. For a balance that also updates on the credit partials arriving between checks, pipe `creditId` into [`creditBalance$`](#credit-balances) instead.
|
|
238
|
+
|
|
239
|
+
### Usage warnings
|
|
240
|
+
|
|
241
|
+
If a usage warning is configured on the entitlement, the emitted entitlement carries it as `warningTiers`, so you can warn a customer before they hit the limit rather than after:
|
|
242
|
+
|
|
243
|
+
| Property | Type | Description |
|
|
244
|
+
| --- | --- | --- |
|
|
245
|
+
| `warningTiers` | `WarningTier[] \| undefined` | The usage warning thresholds configured on the entitlement, each a `{ key, value }` pair in the entitlement's usage units. `undefined` when none are configured |
|
|
246
|
+
| `softLimit` | `number \| undefined` | For usage-based pricing, the soft limit for overage charges or the next tier boundary |
|
|
247
|
+
|
|
248
|
+
The dashboard writes a single tier under the key `default`.
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
import { Component, inject } from "@angular/core";
|
|
252
|
+
import { AsyncPipe } from "@angular/common";
|
|
253
|
+
import { map } from "rxjs";
|
|
254
|
+
import { SchematicService } from "@schematichq/schematic-angular";
|
|
255
|
+
|
|
256
|
+
@Component({
|
|
257
|
+
selector: "app-usage-warning",
|
|
258
|
+
standalone: true,
|
|
259
|
+
imports: [AsyncPipe],
|
|
260
|
+
template: `
|
|
261
|
+
@if (approachingLimit$ | async) {
|
|
262
|
+
<app-approaching-limit />
|
|
263
|
+
}
|
|
264
|
+
<app-feature />
|
|
265
|
+
`,
|
|
266
|
+
})
|
|
267
|
+
export class UsageWarningComponent {
|
|
268
|
+
private schematic = inject(SchematicService);
|
|
269
|
+
entitlement$ = this.schematic.entitlement$("my-flag-key");
|
|
270
|
+
approachingLimit$ = this.entitlement$.pipe(
|
|
271
|
+
map((entitlement) => {
|
|
272
|
+
const warning = entitlement.warningTiers?.find(
|
|
273
|
+
(tier) => tier.key === "default",
|
|
274
|
+
);
|
|
275
|
+
return (
|
|
276
|
+
typeof entitlement.featureUsage === "number" &&
|
|
277
|
+
typeof warning?.value === "number" &&
|
|
278
|
+
entitlement.featureUsage >= warning.value
|
|
279
|
+
);
|
|
280
|
+
}),
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
205
285
|
### Checking plans
|
|
206
286
|
|
|
207
287
|
Use `plan$` to get an Observable of the current plan information:
|
|
@@ -265,7 +345,36 @@ export class CreditMeterComponent {
|
|
|
265
345
|
| `balance` | `number` | The spendable balance, or `0` while loading or when the company holds no balance in this credit |
|
|
266
346
|
| `isLoading` | `boolean` | `true` while the balance is still loading and no value has arrived yet |
|
|
267
347
|
|
|
268
|
-
It surfaces the `settled` (spendable) balance. The credit ID is available on a feature's entitlement
|
|
348
|
+
It surfaces the `settled` (spendable) balance. The credit ID is available on a feature's entitlement, and `creditBalance$` accepts an Observable of credit IDs as well as a plain one, so you can pipe the entitlement straight in:
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
import { map } from "rxjs";
|
|
352
|
+
|
|
353
|
+
@Component({
|
|
354
|
+
selector: "app-credit-meter",
|
|
355
|
+
standalone: true,
|
|
356
|
+
imports: [AsyncPipe],
|
|
357
|
+
template: `
|
|
358
|
+
@if (creditBalance$ | async; as credit) {
|
|
359
|
+
@if (credit.isLoading) {
|
|
360
|
+
<div>Loading…</div>
|
|
361
|
+
} @else {
|
|
362
|
+
<div>{{ credit.balance }} credits remaining</div>
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
`,
|
|
366
|
+
})
|
|
367
|
+
export class CreditMeterComponent {
|
|
368
|
+
private schematic = inject(SchematicService);
|
|
369
|
+
creditBalance$ = this.schematic.creditBalance$(
|
|
370
|
+
this.schematic
|
|
371
|
+
.entitlement$("my-flag-key")
|
|
372
|
+
.pipe(map((entitlement) => entitlement.creditId)),
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
It switches to the new credit as the source emits. While the ID is `undefined`, it emits the client's loading state and a balance of `0`.
|
|
269
378
|
|
|
270
379
|
## API Reference
|
|
271
380
|
|
|
@@ -286,7 +395,7 @@ Injectable service providing all Schematic functionality:
|
|
|
286
395
|
| `flagValue$(key, fallback?)` | `Observable<boolean>` | Observe a feature flag's boolean value |
|
|
287
396
|
| `entitlement$(key, fallback?)` | `Observable<CheckFlagReturn>` | Observe detailed entitlement data |
|
|
288
397
|
| `plan$()` | `Observable<CheckPlanReturn \| undefined>` | Observe plan information |
|
|
289
|
-
| `creditBalance$(creditId)` | `Observable<SchematicCreditBalance>` | Observe a company's lease-aware credit balance |
|
|
398
|
+
| `creditBalance$(creditId)` | `Observable<SchematicCreditBalance>` | Observe a company's lease-aware credit balance. Takes a credit ID or an Observable of credit IDs |
|
|
290
399
|
| `isPending$()` | `Observable<boolean>` | Observe loading state |
|
|
291
400
|
|
|
292
401
|
### `SCHEMATIC_CLIENT`
|
|
@@ -2,7 +2,7 @@ import * as i0 from '@angular/core';
|
|
|
2
2
|
import { InjectionToken, inject, Injectable, makeEnvironmentProviders, DestroyRef } from '@angular/core';
|
|
3
3
|
import * as SchematicJS from '@schematichq/schematic-js';
|
|
4
4
|
export { RuleType, Schematic, TrialStatus, UsagePeriod } from '@schematichq/schematic-js';
|
|
5
|
-
import { Observable, distinctUntilChanged, shareReplay, finalize } from 'rxjs';
|
|
5
|
+
import { Observable, distinctUntilChanged, shareReplay, finalize, isObservable, switchMap, map } from 'rxjs';
|
|
6
6
|
|
|
7
7
|
const SCHEMATIC_CLIENT = new InjectionToken("SchematicClient");
|
|
8
8
|
|
|
@@ -105,9 +105,28 @@ class SchematicService {
|
|
|
105
105
|
* `remaining` would otherwise read stale / falsely "exhausted".
|
|
106
106
|
*
|
|
107
107
|
* The credit ID is available on a feature's entitlement: `entitlement$(key)`
|
|
108
|
-
* emits `creditId` for credit-based features.
|
|
108
|
+
* emits `creditId` for credit-based features. Pass that stream straight in:
|
|
109
|
+
* this accepts an Observable of credit IDs as well as a plain one, switching
|
|
110
|
+
* to the new credit as the source emits. While the ID is undefined it emits
|
|
111
|
+
* the client's loading state and a balance of 0.
|
|
109
112
|
*/
|
|
110
113
|
creditBalance$(creditId) {
|
|
114
|
+
if (isObservable(creditId)) {
|
|
115
|
+
return creditId.pipe(distinctUntilChanged(), switchMap((id) => this.creditBalanceFor(id)), distinctUntilChanged(shallowEqual), shareReplay({ bufferSize: 1, refCount: true }));
|
|
116
|
+
}
|
|
117
|
+
return this.creditBalanceFor(creditId);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Emits a zeroed balance that still tracks the client's loading state, for
|
|
121
|
+
* when there is no credit ID to read (a check that has not arrived yet, or a
|
|
122
|
+
* feature that is not credit-based).
|
|
123
|
+
*/
|
|
124
|
+
noCreditBalance$() {
|
|
125
|
+
return this.isPending$().pipe(map((isLoading) => ({ balance: 0, isLoading })));
|
|
126
|
+
}
|
|
127
|
+
creditBalanceFor(creditId) {
|
|
128
|
+
if (creditId === undefined)
|
|
129
|
+
return this.noCreditBalance$();
|
|
111
130
|
let cached = this.creditBalanceCache.get(creditId);
|
|
112
131
|
if (cached)
|
|
113
132
|
return cached;
|
|
@@ -144,14 +163,14 @@ class SchematicService {
|
|
|
144
163
|
}));
|
|
145
164
|
return this.isPendingCache;
|
|
146
165
|
}
|
|
147
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
148
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
166
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: SchematicService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
167
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: SchematicService });
|
|
149
168
|
}
|
|
150
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
169
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: SchematicService, decorators: [{
|
|
151
170
|
type: Injectable
|
|
152
171
|
}] });
|
|
153
172
|
|
|
154
|
-
const version = "1.
|
|
173
|
+
const version = "1.6.0";
|
|
155
174
|
|
|
156
175
|
function provideSchematic(config) {
|
|
157
176
|
const { client: providedClient, publishableKey, additionalHeaders, ...restOpts } = config;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schematichq-schematic-angular.mjs","sources":["../../src/token.ts","../../src/schematic.service.ts","../../src/version.ts","../../src/provide.ts","../../src/schematichq-schematic-angular.ts"],"sourcesContent":["import { InjectionToken } from \"@angular/core\";\nimport * as SchematicJS from \"@schematichq/schematic-js\";\n\nexport const SCHEMATIC_CLIENT = new InjectionToken<SchematicJS.Schematic>(\n \"SchematicClient\",\n);\n","import { Injectable, inject } from \"@angular/core\";\nimport * as SchematicJS from \"@schematichq/schematic-js\";\nimport { Observable, distinctUntilChanged, finalize, shareReplay } from \"rxjs\";\nimport { SCHEMATIC_CLIENT } from \"./token\";\n\n/** A company's credit balance for a single credit type, plus a loading flag */\nexport type SchematicCreditBalance = {\n /** The spendable balance; 0 while loading or when the company holds no balance in this credit */\n balance: number;\n /** True while the balance is still loading and no value has arrived yet */\n isLoading: boolean;\n};\n\nfunction shallowEqual<T extends Record<string, unknown>>(\n a: T | undefined,\n b: T | undefined,\n): boolean {\n if (a === b) return true;\n if (!a || !b) return false;\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n if (keysA.length !== keysB.length) return false;\n return keysA.every((key) => {\n const valA = a[key];\n const valB = b[key];\n if (valA instanceof Date && valB instanceof Date) {\n return valA.getTime() === valB.getTime();\n }\n return valA === valB;\n });\n}\n\n@Injectable()\nexport class SchematicService {\n private client = inject(SCHEMATIC_CLIENT);\n\n private flagValueCache = new Map<string, Observable<boolean>>();\n private entitlementCache = new Map<\n string,\n Observable<SchematicJS.CheckFlagReturn>\n >();\n private creditBalanceCache = new Map<\n string,\n Observable<SchematicCreditBalance>\n >();\n private planCache?: Observable<SchematicJS.CheckPlanReturn | undefined>;\n private isPendingCache?: Observable<boolean>;\n\n getClient(): SchematicJS.Schematic {\n return this.client;\n }\n\n setContext(context: SchematicJS.SchematicContext): void {\n this.client.setContext(context);\n }\n\n identify(body: SchematicJS.EventBodyIdentify): void {\n this.client.identify(body);\n }\n\n track(body: SchematicJS.EventBodyTrack): void {\n this.client.track(body);\n }\n\n flagValue$(key: string, fallback: boolean = false): Observable<boolean> {\n const cacheKey = `${key}:${fallback}`;\n let cached = this.flagValueCache.get(cacheKey);\n if (cached) return cached;\n\n cached = new Observable<boolean>((subscriber) => {\n const current = this.client.getFlagValue(key);\n subscriber.next(current ?? fallback);\n\n const unsubscribe = this.client.addFlagValueListener(key, () => {\n const value = this.client.getFlagValue(key);\n subscriber.next(value ?? fallback);\n });\n\n return () => unsubscribe();\n }).pipe(\n distinctUntilChanged(),\n shareReplay({ bufferSize: 1, refCount: true }),\n finalize(() => this.flagValueCache.delete(cacheKey)),\n );\n\n this.flagValueCache.set(cacheKey, cached);\n return cached;\n }\n\n entitlement$(\n key: string,\n fallback: boolean = false,\n ): Observable<SchematicJS.CheckFlagReturn> {\n const cacheKey = `${key}:${fallback}`;\n let cached = this.entitlementCache.get(cacheKey);\n if (cached) return cached;\n\n const fallbackCheck: SchematicJS.CheckFlagReturn = {\n flag: key,\n reason: \"Fallback\",\n value: fallback,\n };\n\n cached = new Observable<SchematicJS.CheckFlagReturn>((subscriber) => {\n const current = this.client.getFlagCheck(key);\n subscriber.next(current ?? fallbackCheck);\n\n const unsubscribe = this.client.addFlagCheckListener(key, () => {\n const check = this.client.getFlagCheck(key);\n subscriber.next(check ?? fallbackCheck);\n });\n\n return () => unsubscribe();\n }).pipe(\n distinctUntilChanged(shallowEqual),\n shareReplay({ bufferSize: 1, refCount: true }),\n finalize(() => this.entitlementCache.delete(cacheKey)),\n );\n\n this.entitlementCache.set(cacheKey, cached);\n return cached;\n }\n\n plan$(): Observable<SchematicJS.CheckPlanReturn | undefined> {\n if (this.planCache) return this.planCache;\n\n this.planCache = new Observable<SchematicJS.CheckPlanReturn | undefined>(\n (subscriber) => {\n subscriber.next(this.client.getPlan());\n\n const unsubscribe = this.client.addPlanListener(() => {\n subscriber.next(this.client.getPlan());\n });\n\n return () => unsubscribe();\n },\n ).pipe(\n distinctUntilChanged(shallowEqual),\n shareReplay({ bufferSize: 1, refCount: true }),\n finalize(() => {\n this.planCache = undefined;\n }),\n );\n\n return this.planCache;\n }\n\n /**\n * Observe a company's live, lease-aware credit balance for a single credit type.\n *\n * Surfaces the spendable `settled` balance, sourced from the streamed credit\n * balances map (keyed by credit ID). It emits as partials arrive over the\n * DataStream, so it stays accurate during an open lease — when the raw\n * `remaining` would otherwise read stale / falsely \"exhausted\".\n *\n * The credit ID is available on a feature's entitlement: `entitlement$(key)`\n * emits `creditId` for credit-based features.\n */\n creditBalance$(creditId: string): Observable<SchematicCreditBalance> {\n let cached = this.creditBalanceCache.get(creditId);\n if (cached) return cached;\n\n cached = new Observable<SchematicCreditBalance>((subscriber) => {\n const emit = () => {\n const balance = this.client.getCreditBalance(creditId);\n subscriber.next({\n balance: balance?.settled ?? 0,\n isLoading: balance === undefined && this.client.getIsPending(),\n });\n };\n\n emit();\n\n const unsubscribeBalance = this.client.addCreditBalanceListener(() =>\n emit(),\n );\n const unsubscribePending = this.client.addIsPendingListener(() => emit());\n\n return () => {\n unsubscribeBalance();\n unsubscribePending();\n };\n }).pipe(\n distinctUntilChanged(shallowEqual),\n shareReplay({ bufferSize: 1, refCount: true }),\n finalize(() => this.creditBalanceCache.delete(creditId)),\n );\n\n this.creditBalanceCache.set(creditId, cached);\n return cached;\n }\n\n isPending$(): Observable<boolean> {\n if (this.isPendingCache) return this.isPendingCache;\n\n this.isPendingCache = new Observable<boolean>((subscriber) => {\n subscriber.next(this.client.getIsPending());\n\n const unsubscribe = this.client.addIsPendingListener(() => {\n subscriber.next(this.client.getIsPending());\n });\n\n return () => unsubscribe();\n }).pipe(\n distinctUntilChanged(),\n shareReplay({ bufferSize: 1, refCount: true }),\n finalize(() => {\n this.isPendingCache = undefined;\n }),\n );\n\n return this.isPendingCache;\n }\n}\n","export const version = \"1.5.0\";\n","import { DestroyRef, inject, makeEnvironmentProviders } from \"@angular/core\";\nimport * as SchematicJS from \"@schematichq/schematic-js\";\n\nimport { SchematicService } from \"./schematic.service\";\nimport { SCHEMATIC_CLIENT } from \"./token\";\nimport { version } from \"./version\";\n\ntype BaseSchematicConfig = Omit<SchematicJS.SchematicOptions, \"useWebSocket\">;\n\ntype SchematicConfigWithClient = BaseSchematicConfig & {\n client: SchematicJS.Schematic;\n publishableKey?: never;\n};\n\ntype SchematicConfigWithKey = BaseSchematicConfig & {\n client?: never;\n publishableKey: string;\n};\n\nexport type SchematicConfig =\n | SchematicConfigWithClient\n | SchematicConfigWithKey;\n\nexport function provideSchematic(config: SchematicConfig) {\n const {\n client: providedClient,\n publishableKey,\n additionalHeaders,\n ...restOpts\n } = config;\n\n return makeEnvironmentProviders([\n {\n provide: SCHEMATIC_CLIENT,\n useFactory: () => {\n const isProvidedClient = !!providedClient;\n\n const client = isProvidedClient\n ? providedClient\n : new SchematicJS.Schematic(publishableKey!, {\n ...restOpts,\n useWebSocket: true,\n additionalHeaders: {\n \"X-Schematic-Client-Version\": `schematic-angular@${version}`,\n ...additionalHeaders,\n },\n });\n\n const destroyRef = inject(DestroyRef);\n destroyRef.onDestroy(() => {\n if (!isProvidedClient) {\n client.cleanup().catch((error: unknown) => {\n console.error(\"Error during Schematic cleanup:\", error);\n });\n }\n });\n\n return client;\n },\n },\n SchematicService,\n ]);\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;MAGa,gBAAgB,GAAG,IAAI,cAAc,CAChD,iBAAiB;;ACSnB,SAAS,YAAY,CACnB,CAAgB,EAChB,CAAgB,EAAA;IAEhB,IAAI,CAAC,KAAK,CAAC;AAAE,QAAA,OAAO,IAAI;AACxB,IAAA,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;AAAE,QAAA,OAAO,KAAK;I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B,EAAA,UAAA,EAAA,CAAA;kBAD5B;;;AChCM,MAAM,OAAO,GAAG,OAAO;;ACuBxB,SAAU,gBAAgB,CAAC,MAAuB,EAAA;AACtD,IAAA,MAAM,EACJ,MAAM,EAAE,cAAc,EACtB,cAAc,EACd,iBAAiB,EACjB,GAAG,QAAQ,EACZ,GAAG,MAAM;AAEV,IAAA,OAAO,wBAAwB,CAAC;AAC9B,QAAA;AACE,YAAA,OAAO,EAAE,gBAAgB;YACzB,UAAU,EAAE,MAAK;AACf,gBAAA,MAAM,gBAAgB,GAAG,CAAC,CAAC,cAAc;gBAEzC,MAAM,MAAM,GAAG;AACb,sBAAE;AACF,sBAAE,IAAI,WAAW,CAAC,SAAS,CAAC,cAAe,EAAE;AACzC,wBAAA,GAAG,QAAQ;AACX,wBAAA,YAAY,EAAE,IAAI;AAClB,wBAAA,iBAAiB,EAAE;4BACjB,4BAA4B,EAAE,CAAA,kBAAA,EAAqB,OAAO,CAAA,CAAE;AAC5D,4BAAA,GAAG,iBAAiB;AACrB,yBAAA;AACF,qBAAA,CAAC;AAEN,gBAAA,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;AACrC,gBAAA,UAAU,CAAC,SAAS,CAAC,MAAK;oBACxB,IAAI,CAAC,gBAAgB,EAAE;wBACrB,MAAM,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,KAAI;AACxC,4BAAA,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC;AACzD,wBAAA,CAAC,CAAC;oBACJ;AACF,gBAAA,CAAC,CAAC;AAEF,gBAAA,OAAO,MAAM;YACf,CAAC;AACF,SAAA;QACD,gBAAgB;AACjB,KAAA,CAAC;AACJ;;AC9DA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"schematichq-schematic-angular.mjs","sources":["../../src/token.ts","../../src/schematic.service.ts","../../src/version.ts","../../src/provide.ts","../../src/schematichq-schematic-angular.ts"],"sourcesContent":["import { InjectionToken } from \"@angular/core\";\nimport * as SchematicJS from \"@schematichq/schematic-js\";\n\nexport const SCHEMATIC_CLIENT = new InjectionToken<SchematicJS.Schematic>(\n \"SchematicClient\",\n);\n","import { Injectable, inject } from \"@angular/core\";\nimport * as SchematicJS from \"@schematichq/schematic-js\";\nimport {\n Observable,\n distinctUntilChanged,\n finalize,\n isObservable,\n map,\n shareReplay,\n switchMap,\n} from \"rxjs\";\nimport { SCHEMATIC_CLIENT } from \"./token\";\n\n/** A company's credit balance for a single credit type, plus a loading flag */\nexport type SchematicCreditBalance = {\n /** The spendable balance; 0 while loading or when the company holds no balance in this credit */\n balance: number;\n /** True while the balance is still loading and no value has arrived yet */\n isLoading: boolean;\n};\n\nfunction shallowEqual<T extends Record<string, unknown>>(\n a: T | undefined,\n b: T | undefined,\n): boolean {\n if (a === b) return true;\n if (!a || !b) return false;\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n if (keysA.length !== keysB.length) return false;\n return keysA.every((key) => {\n const valA = a[key];\n const valB = b[key];\n if (valA instanceof Date && valB instanceof Date) {\n return valA.getTime() === valB.getTime();\n }\n return valA === valB;\n });\n}\n\n@Injectable()\nexport class SchematicService {\n private client = inject(SCHEMATIC_CLIENT);\n\n private flagValueCache = new Map<string, Observable<boolean>>();\n private entitlementCache = new Map<\n string,\n Observable<SchematicJS.CheckFlagReturn>\n >();\n private creditBalanceCache = new Map<\n string,\n Observable<SchematicCreditBalance>\n >();\n private planCache?: Observable<SchematicJS.CheckPlanReturn | undefined>;\n private isPendingCache?: Observable<boolean>;\n\n getClient(): SchematicJS.Schematic {\n return this.client;\n }\n\n setContext(context: SchematicJS.SchematicContext): void {\n this.client.setContext(context);\n }\n\n identify(body: SchematicJS.EventBodyIdentify): void {\n this.client.identify(body);\n }\n\n track(body: SchematicJS.EventBodyTrack): void {\n this.client.track(body);\n }\n\n flagValue$(key: string, fallback: boolean = false): Observable<boolean> {\n const cacheKey = `${key}:${fallback}`;\n let cached = this.flagValueCache.get(cacheKey);\n if (cached) return cached;\n\n cached = new Observable<boolean>((subscriber) => {\n const current = this.client.getFlagValue(key);\n subscriber.next(current ?? fallback);\n\n const unsubscribe = this.client.addFlagValueListener(key, () => {\n const value = this.client.getFlagValue(key);\n subscriber.next(value ?? fallback);\n });\n\n return () => unsubscribe();\n }).pipe(\n distinctUntilChanged(),\n shareReplay({ bufferSize: 1, refCount: true }),\n finalize(() => this.flagValueCache.delete(cacheKey)),\n );\n\n this.flagValueCache.set(cacheKey, cached);\n return cached;\n }\n\n entitlement$(\n key: string,\n fallback: boolean = false,\n ): Observable<SchematicJS.CheckFlagReturn> {\n const cacheKey = `${key}:${fallback}`;\n let cached = this.entitlementCache.get(cacheKey);\n if (cached) return cached;\n\n const fallbackCheck: SchematicJS.CheckFlagReturn = {\n flag: key,\n reason: \"Fallback\",\n value: fallback,\n };\n\n cached = new Observable<SchematicJS.CheckFlagReturn>((subscriber) => {\n const current = this.client.getFlagCheck(key);\n subscriber.next(current ?? fallbackCheck);\n\n const unsubscribe = this.client.addFlagCheckListener(key, () => {\n const check = this.client.getFlagCheck(key);\n subscriber.next(check ?? fallbackCheck);\n });\n\n return () => unsubscribe();\n }).pipe(\n distinctUntilChanged(shallowEqual),\n shareReplay({ bufferSize: 1, refCount: true }),\n finalize(() => this.entitlementCache.delete(cacheKey)),\n );\n\n this.entitlementCache.set(cacheKey, cached);\n return cached;\n }\n\n plan$(): Observable<SchematicJS.CheckPlanReturn | undefined> {\n if (this.planCache) return this.planCache;\n\n this.planCache = new Observable<SchematicJS.CheckPlanReturn | undefined>(\n (subscriber) => {\n subscriber.next(this.client.getPlan());\n\n const unsubscribe = this.client.addPlanListener(() => {\n subscriber.next(this.client.getPlan());\n });\n\n return () => unsubscribe();\n },\n ).pipe(\n distinctUntilChanged(shallowEqual),\n shareReplay({ bufferSize: 1, refCount: true }),\n finalize(() => {\n this.planCache = undefined;\n }),\n );\n\n return this.planCache;\n }\n\n /**\n * Observe a company's live, lease-aware credit balance for a single credit type.\n *\n * Surfaces the spendable `settled` balance, sourced from the streamed credit\n * balances map (keyed by credit ID). It emits as partials arrive over the\n * DataStream, so it stays accurate during an open lease — when the raw\n * `remaining` would otherwise read stale / falsely \"exhausted\".\n *\n * The credit ID is available on a feature's entitlement: `entitlement$(key)`\n * emits `creditId` for credit-based features. Pass that stream straight in:\n * this accepts an Observable of credit IDs as well as a plain one, switching\n * to the new credit as the source emits. While the ID is undefined it emits\n * the client's loading state and a balance of 0.\n */\n creditBalance$(\n creditId: string | undefined | Observable<string | undefined>,\n ): Observable<SchematicCreditBalance> {\n if (isObservable(creditId)) {\n return creditId.pipe(\n distinctUntilChanged(),\n switchMap((id) => this.creditBalanceFor(id)),\n distinctUntilChanged(shallowEqual),\n shareReplay({ bufferSize: 1, refCount: true }),\n );\n }\n\n return this.creditBalanceFor(creditId);\n }\n\n /**\n * Emits a zeroed balance that still tracks the client's loading state, for\n * when there is no credit ID to read (a check that has not arrived yet, or a\n * feature that is not credit-based).\n */\n private noCreditBalance$(): Observable<SchematicCreditBalance> {\n return this.isPending$().pipe(\n map((isLoading) => ({ balance: 0, isLoading })),\n );\n }\n\n private creditBalanceFor(\n creditId: string | undefined,\n ): Observable<SchematicCreditBalance> {\n if (creditId === undefined) return this.noCreditBalance$();\n\n let cached = this.creditBalanceCache.get(creditId);\n if (cached) return cached;\n\n cached = new Observable<SchematicCreditBalance>((subscriber) => {\n const emit = () => {\n const balance = this.client.getCreditBalance(creditId);\n subscriber.next({\n balance: balance?.settled ?? 0,\n isLoading: balance === undefined && this.client.getIsPending(),\n });\n };\n\n emit();\n\n const unsubscribeBalance = this.client.addCreditBalanceListener(() =>\n emit(),\n );\n const unsubscribePending = this.client.addIsPendingListener(() => emit());\n\n return () => {\n unsubscribeBalance();\n unsubscribePending();\n };\n }).pipe(\n distinctUntilChanged(shallowEqual),\n shareReplay({ bufferSize: 1, refCount: true }),\n finalize(() => this.creditBalanceCache.delete(creditId)),\n );\n\n this.creditBalanceCache.set(creditId, cached);\n return cached;\n }\n\n isPending$(): Observable<boolean> {\n if (this.isPendingCache) return this.isPendingCache;\n\n this.isPendingCache = new Observable<boolean>((subscriber) => {\n subscriber.next(this.client.getIsPending());\n\n const unsubscribe = this.client.addIsPendingListener(() => {\n subscriber.next(this.client.getIsPending());\n });\n\n return () => unsubscribe();\n }).pipe(\n distinctUntilChanged(),\n shareReplay({ bufferSize: 1, refCount: true }),\n finalize(() => {\n this.isPendingCache = undefined;\n }),\n );\n\n return this.isPendingCache;\n }\n}\n","export const version = \"1.6.0\";\n","import { DestroyRef, inject, makeEnvironmentProviders } from \"@angular/core\";\nimport * as SchematicJS from \"@schematichq/schematic-js\";\n\nimport { SchematicService } from \"./schematic.service\";\nimport { SCHEMATIC_CLIENT } from \"./token\";\nimport { version } from \"./version\";\n\ntype BaseSchematicConfig = Omit<SchematicJS.SchematicOptions, \"useWebSocket\">;\n\ntype SchematicConfigWithClient = BaseSchematicConfig & {\n client: SchematicJS.Schematic;\n publishableKey?: never;\n};\n\ntype SchematicConfigWithKey = BaseSchematicConfig & {\n client?: never;\n publishableKey: string;\n};\n\nexport type SchematicConfig =\n SchematicConfigWithClient | SchematicConfigWithKey;\n\nexport function provideSchematic(config: SchematicConfig) {\n const {\n client: providedClient,\n publishableKey,\n additionalHeaders,\n ...restOpts\n } = config;\n\n return makeEnvironmentProviders([\n {\n provide: SCHEMATIC_CLIENT,\n useFactory: () => {\n const isProvidedClient = !!providedClient;\n\n const client = isProvidedClient\n ? providedClient\n : new SchematicJS.Schematic(publishableKey!, {\n ...restOpts,\n useWebSocket: true,\n additionalHeaders: {\n \"X-Schematic-Client-Version\": `schematic-angular@${version}`,\n ...additionalHeaders,\n },\n });\n\n const destroyRef = inject(DestroyRef);\n destroyRef.onDestroy(() => {\n if (!isProvidedClient) {\n client.cleanup().catch((error: unknown) => {\n console.error(\"Error during Schematic cleanup:\", error);\n });\n }\n });\n\n return client;\n },\n },\n SchematicService,\n ]);\n}\n","/**\n * Generated bundle index. Do not edit.\n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EAAE,gBAAgB;YACzB,UAAU,EAAE,MAAK;AACf,gBAAA,MAAM,gBAAgB,GAAG,CAAC,CAAC,cAAc;gBAEzC,MAAM,MAAM,GAAG;AACb,sBAAE;AACF,sBAAE,IAAI,WAAW,CAAC,SAAS,CAAC,cAAe,EAAE;AACzC,wBAAA,GAAG,QAAQ;AACX,wBAAA,YAAY,EAAE,IAAI;AAClB,wBAAA,iBAAiB,EAAE;4BACjB,4BAA4B,EAAE,CAAA,kBAAA,EAAqB,OAAO,CAAA,CAAE;AAC5D,4BAAA,GAAG,iBAAiB;AACrB,yBAAA;AACF,qBAAA,CAAC;AAEN,gBAAA,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;AACrC,gBAAA,UAAU,CAAC,SAAS,CAAC,MAAK;oBACxB,IAAI,CAAC,gBAAgB,EAAE;wBACrB,MAAM,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,KAAI;AACxC,4BAAA,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC;AACzD,wBAAA,CAAC,CAAC;oBACJ;AACF,gBAAA,CAAC,CAAC;AAEF,gBAAA,OAAO,MAAM;YACf,CAAC;AACF,SAAA;QACD,gBAAgB;AACjB,KAAA,CAAC;AACJ;;AC7DA;;AAEG;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schematichq/schematic-angular",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"author": "Schematic <engineering@schematichq.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -8,19 +8,14 @@
|
|
|
8
8
|
"url": "git+ssh://git@github.com/SchematicHQ/schematic-js.git"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@schematichq/schematic-js": "^1.
|
|
11
|
+
"@schematichq/schematic-js": "^1.8.0",
|
|
12
12
|
"tslib": "^2.3.0"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
15
|
"@angular/core": ">=19.0.0",
|
|
16
16
|
"rxjs": ">=7.0.0"
|
|
17
17
|
},
|
|
18
|
-
"
|
|
19
|
-
"minimatch": ">=3.1.3",
|
|
20
|
-
"esbuild": ">=0.28.1",
|
|
21
|
-
"@babel/core": "^7.29.6"
|
|
22
|
-
},
|
|
23
|
-
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
|
|
18
|
+
"packageManager": "pnpm@11.9.0+sha512.bd682d5d03fe525ef7c9fd6780c6884d1e756ac4c9c9fe00c538782824310dcf90e3ddc4f53835f06dfaebd5085e41855e0bcbb3b60de2ac5bbab89e5036f03b",
|
|
24
19
|
"module": "fesm2022/schematichq-schematic-angular.mjs",
|
|
25
20
|
"typings": "types/schematichq-schematic-angular.d.ts",
|
|
26
21
|
"exports": {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { InjectionToken } from '@angular/core';
|
|
3
3
|
import * as SchematicJS from '@schematichq/schematic-js';
|
|
4
|
-
export { CheckFlagReturn, CheckPlanReturn, CompanyCreditBalance, CreditBalance, CreditBalances, Event, EventBody, EventBodyIdentify, EventBodyTrack, EventType, Keys, RuleType, Schematic, SchematicContext, SchematicOptions, StoragePersister, Traits, TrialStatus, UsagePeriod } from '@schematichq/schematic-js';
|
|
4
|
+
export { CheckFlagReturn, CheckPlanReturn, CompanyCreditBalance, CreditBalance, CreditBalances, Event, EventBody, EventBodyIdentify, EventBodyTrack, EventType, Keys, RuleType, Schematic, SchematicContext, SchematicOptions, StoragePersister, Traits, TrialStatus, UsagePeriod, WarningTier } from '@schematichq/schematic-js';
|
|
5
5
|
import { Observable } from 'rxjs';
|
|
6
6
|
|
|
7
7
|
type BaseSchematicConfig = Omit<SchematicJS.SchematicOptions, "useWebSocket">;
|
|
@@ -48,12 +48,22 @@ declare class SchematicService {
|
|
|
48
48
|
* `remaining` would otherwise read stale / falsely "exhausted".
|
|
49
49
|
*
|
|
50
50
|
* The credit ID is available on a feature's entitlement: `entitlement$(key)`
|
|
51
|
-
* emits `creditId` for credit-based features.
|
|
51
|
+
* emits `creditId` for credit-based features. Pass that stream straight in:
|
|
52
|
+
* this accepts an Observable of credit IDs as well as a plain one, switching
|
|
53
|
+
* to the new credit as the source emits. While the ID is undefined it emits
|
|
54
|
+
* the client's loading state and a balance of 0.
|
|
52
55
|
*/
|
|
53
|
-
creditBalance$(creditId: string): Observable<SchematicCreditBalance>;
|
|
56
|
+
creditBalance$(creditId: string | undefined | Observable<string | undefined>): Observable<SchematicCreditBalance>;
|
|
57
|
+
/**
|
|
58
|
+
* Emits a zeroed balance that still tracks the client's loading state, for
|
|
59
|
+
* when there is no credit ID to read (a check that has not arrived yet, or a
|
|
60
|
+
* feature that is not credit-based).
|
|
61
|
+
*/
|
|
62
|
+
private noCreditBalance$;
|
|
63
|
+
private creditBalanceFor;
|
|
54
64
|
isPending$(): Observable<boolean>;
|
|
55
65
|
static ɵfac: i0.ɵɵFactoryDeclaration<SchematicService, never>;
|
|
56
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<
|
|
66
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
57
67
|
}
|
|
58
68
|
|
|
59
69
|
export { SCHEMATIC_CLIENT, SchematicService, provideSchematic };
|