@schematichq/schematic-js 1.3.2 → 1.5.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 +17 -0
- package/dist/schematic.browser.js +2 -2
- package/dist/schematic.cjs.js +662 -34
- package/dist/schematic.d.ts +163 -21
- package/dist/schematic.esm.js +662 -34
- package/package.json +16 -17
package/dist/schematic.d.ts
CHANGED
|
@@ -67,11 +67,11 @@ export declare interface CheckFlagResponseData {
|
|
|
67
67
|
featureUsageEvent?: string | null;
|
|
68
68
|
/**
|
|
69
69
|
* Deprecated: Use Entitlement.MetricPeriod instead.
|
|
70
|
-
* @type {
|
|
70
|
+
* @type {MetricPeriod}
|
|
71
71
|
* @memberof CheckFlagResponseData
|
|
72
72
|
* @deprecated
|
|
73
73
|
*/
|
|
74
|
-
featureUsagePeriod?:
|
|
74
|
+
featureUsagePeriod?: MetricPeriod | null;
|
|
75
75
|
/**
|
|
76
76
|
* Deprecated: Use Entitlement.MetricResetAt instead.
|
|
77
77
|
* @type {Date}
|
|
@@ -105,10 +105,10 @@ export declare interface CheckFlagResponseData {
|
|
|
105
105
|
ruleId?: string | null;
|
|
106
106
|
/**
|
|
107
107
|
* If a rule was found, its type
|
|
108
|
-
* @type {
|
|
108
|
+
* @type {RuleType}
|
|
109
109
|
* @memberof CheckFlagResponseData
|
|
110
110
|
*/
|
|
111
|
-
ruleType?:
|
|
111
|
+
ruleType?: RuleType_2 | null;
|
|
112
112
|
/**
|
|
113
113
|
* If user keys were provided and matched a user, its ID
|
|
114
114
|
* @type {string}
|
|
@@ -130,6 +130,14 @@ export declare type CheckFlagReturn = {
|
|
|
130
130
|
featureUsageExceeded?: boolean;
|
|
131
131
|
/** If company keys were provided and matched a company, its ID */
|
|
132
132
|
companyId?: string;
|
|
133
|
+
/** If the company has a credit-based entitlement for this feature, the ID of the credit */
|
|
134
|
+
creditId?: string;
|
|
135
|
+
/** If the company has a credit-based entitlement for this feature, the credit available to fund new consumption excluding any open lease hold (the value lease-holding SDKs gate on) */
|
|
136
|
+
creditRemaining?: number;
|
|
137
|
+
/** If the company has a credit-based entitlement for this feature, the unspent amount held by an open credit lease, 0 when none is open */
|
|
138
|
+
creditReserved?: number;
|
|
139
|
+
/** If the company has a credit-based entitlement for this feature, the spendable balance including any open lease hold (creditRemaining + creditReserved); the number to display to end users */
|
|
140
|
+
creditSettled?: number;
|
|
133
141
|
/** If an error occurred while checking the flag, the error message */
|
|
134
142
|
error?: string;
|
|
135
143
|
/** If a numeric feature entitlement rule was matched, its allocation */
|
|
@@ -152,6 +160,8 @@ export declare type CheckFlagReturn = {
|
|
|
152
160
|
ruleId?: string;
|
|
153
161
|
/** If a rule was found, its type */
|
|
154
162
|
ruleType?: RuleType;
|
|
163
|
+
/** For usage-based pricing, the soft limit for overage charges or the next tier boundary */
|
|
164
|
+
softLimit?: number;
|
|
155
165
|
/** If user keys were provided and matched a user, its ID */
|
|
156
166
|
userId?: string;
|
|
157
167
|
/** A boolean flag check result; for feature entitlements, this represents whether further consumption of the feature is permitted */
|
|
@@ -188,6 +198,14 @@ declare interface CheckFlagsResponse {
|
|
|
188
198
|
* @interface CheckFlagsResponseData
|
|
189
199
|
*/
|
|
190
200
|
declare interface CheckFlagsResponseData {
|
|
201
|
+
/**
|
|
202
|
+
* Lease-aware credit balances keyed by credit ID, covering every credit type the company holds a balance in
|
|
203
|
+
* @type {{ [key: string]: CompanyCreditBalance; }}
|
|
204
|
+
* @memberof CheckFlagsResponseData
|
|
205
|
+
*/
|
|
206
|
+
creditBalances?: {
|
|
207
|
+
[key: string]: CompanyCreditBalance;
|
|
208
|
+
};
|
|
191
209
|
/**
|
|
192
210
|
*
|
|
193
211
|
* @type {Array<CheckFlagResponseData>}
|
|
@@ -221,6 +239,62 @@ export declare const CheckPlanReturnFromJSON: (json: any) => CheckPlanReturn;
|
|
|
221
239
|
|
|
222
240
|
export declare type CheckPlanReturnListenerFn = (value: CheckPlanReturn) => void;
|
|
223
241
|
|
|
242
|
+
/**
|
|
243
|
+
* Schematic API
|
|
244
|
+
* Schematic API
|
|
245
|
+
*
|
|
246
|
+
* The version of the OpenAPI document: 0.1
|
|
247
|
+
*
|
|
248
|
+
*
|
|
249
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
250
|
+
* https://openapi-generator.tech
|
|
251
|
+
* Do not edit the class manually.
|
|
252
|
+
*/
|
|
253
|
+
/**
|
|
254
|
+
*
|
|
255
|
+
* @export
|
|
256
|
+
* @interface CompanyCreditBalance
|
|
257
|
+
*/
|
|
258
|
+
export declare interface CompanyCreditBalance {
|
|
259
|
+
/**
|
|
260
|
+
* Remaining credit, excluding any open lease hold (the value SDKs gate on)
|
|
261
|
+
* @type {number}
|
|
262
|
+
* @memberof CompanyCreditBalance
|
|
263
|
+
*/
|
|
264
|
+
remaining: number;
|
|
265
|
+
/**
|
|
266
|
+
* Amount held by the company's open credit lease, 0 when none is open
|
|
267
|
+
* @type {number}
|
|
268
|
+
* @memberof CompanyCreditBalance
|
|
269
|
+
*/
|
|
270
|
+
reserved: number;
|
|
271
|
+
/**
|
|
272
|
+
* Spendable balance including the open lease hold (remaining + reserved)
|
|
273
|
+
* @type {number}
|
|
274
|
+
* @memberof CompanyCreditBalance
|
|
275
|
+
*/
|
|
276
|
+
settled: number;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** A company's lease-aware balance for a single credit type */
|
|
280
|
+
export declare type CreditBalance = {
|
|
281
|
+
/** Spendable balance including any open lease hold (remaining + reserved); the number to display to end users */
|
|
282
|
+
settled: number;
|
|
283
|
+
/** Remaining credit excluding any open lease hold (the value lease-holding SDKs gate on) */
|
|
284
|
+
remaining: number;
|
|
285
|
+
/** Amount held by the company's open credit lease, 0 when none is open */
|
|
286
|
+
reserved: number;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
export declare type CreditBalanceListenerFn = CreditBalancesListenerFn | EmptyListenerFn;
|
|
290
|
+
|
|
291
|
+
/** A company's lease-aware credit balances keyed by credit ID */
|
|
292
|
+
export declare type CreditBalances = Record<string, CreditBalance>;
|
|
293
|
+
|
|
294
|
+
export declare const CreditBalancesFromJSON: (json: any) => CreditBalances;
|
|
295
|
+
|
|
296
|
+
export declare type CreditBalancesListenerFn = (value: CreditBalances) => void;
|
|
297
|
+
|
|
224
298
|
/**
|
|
225
299
|
*
|
|
226
300
|
* @export
|
|
@@ -402,6 +476,12 @@ declare interface FeatureEntitlement {
|
|
|
402
476
|
* @memberof FeatureEntitlement
|
|
403
477
|
*/
|
|
404
478
|
allocation?: number | null;
|
|
479
|
+
/**
|
|
480
|
+
* If the company has a credit-based entitlement for this feature, the credit cost per unit of usage
|
|
481
|
+
* @type {number}
|
|
482
|
+
* @memberof FeatureEntitlement
|
|
483
|
+
*/
|
|
484
|
+
consumptionRate?: number | null;
|
|
405
485
|
/**
|
|
406
486
|
* If the company has a credit-based entitlement for this feature, the ID of the credit
|
|
407
487
|
* @type {string}
|
|
@@ -409,11 +489,23 @@ declare interface FeatureEntitlement {
|
|
|
409
489
|
*/
|
|
410
490
|
creditId?: string | null;
|
|
411
491
|
/**
|
|
412
|
-
* If the company has a credit-based entitlement for this feature, the
|
|
492
|
+
* If the company has a credit-based entitlement for this feature, the credit available to fund new consumption or a new lease hold — open lease holds are excluded. Clients that hold a lease should gate on this plus their own unspent hold; clients with no lease awareness should use credit_settled instead
|
|
413
493
|
* @type {number}
|
|
414
494
|
* @memberof FeatureEntitlement
|
|
415
495
|
*/
|
|
416
496
|
creditRemaining?: number | null;
|
|
497
|
+
/**
|
|
498
|
+
* If the company has a credit-based entitlement for this feature, the unspent amount held by an open credit lease. Returns to credit_remaining when the lease is released
|
|
499
|
+
* @type {number}
|
|
500
|
+
* @memberof FeatureEntitlement
|
|
501
|
+
*/
|
|
502
|
+
creditReserved?: number | null;
|
|
503
|
+
/**
|
|
504
|
+
* If the company has a credit-based entitlement for this feature, the balance net of actual consumption, unaffected by open lease holds (credit_remaining plus credit_reserved). The number to display to end users
|
|
505
|
+
* @type {number}
|
|
506
|
+
* @memberof FeatureEntitlement
|
|
507
|
+
*/
|
|
508
|
+
creditSettled?: number | null;
|
|
417
509
|
/**
|
|
418
510
|
* If the company has a credit-based entitlement for this feature, the total credit amount
|
|
419
511
|
* @type {number}
|
|
@@ -432,6 +524,12 @@ declare interface FeatureEntitlement {
|
|
|
432
524
|
* @memberof FeatureEntitlement
|
|
433
525
|
*/
|
|
434
526
|
eventName?: string | null;
|
|
527
|
+
/**
|
|
528
|
+
* For event-based or credit-metered feature entitlements, the event subtype whose usage is tracked
|
|
529
|
+
* @type {string}
|
|
530
|
+
* @memberof FeatureEntitlement
|
|
531
|
+
*/
|
|
532
|
+
eventSubtype?: string | null;
|
|
435
533
|
/**
|
|
436
534
|
* The ID of the feature
|
|
437
535
|
* @type {string}
|
|
@@ -446,10 +544,10 @@ declare interface FeatureEntitlement {
|
|
|
446
544
|
featureKey: string;
|
|
447
545
|
/**
|
|
448
546
|
* For event-based feature entitlements, the period over which usage is tracked
|
|
449
|
-
* @type {
|
|
547
|
+
* @type {MetricPeriod}
|
|
450
548
|
* @memberof FeatureEntitlement
|
|
451
549
|
*/
|
|
452
|
-
metricPeriod?:
|
|
550
|
+
metricPeriod?: MetricPeriod | null;
|
|
453
551
|
/**
|
|
454
552
|
* For event-based feature entitlements, when the usage period will reset
|
|
455
553
|
* @type {Date}
|
|
@@ -458,10 +556,10 @@ declare interface FeatureEntitlement {
|
|
|
458
556
|
metricResetAt?: Date | null;
|
|
459
557
|
/**
|
|
460
558
|
* For event-based feature entitlements that have a monthly period, whether that monthly reset is based on the calendar month or a billing cycle
|
|
461
|
-
* @type {
|
|
559
|
+
* @type {MetricPeriodMonthReset}
|
|
462
560
|
* @memberof FeatureEntitlement
|
|
463
561
|
*/
|
|
464
|
-
monthReset?:
|
|
562
|
+
monthReset?: MetricPeriodMonthReset | null;
|
|
465
563
|
/**
|
|
466
564
|
* For usage-based pricing, the soft limit for overage charges or the next tier boundary
|
|
467
565
|
* @type {number}
|
|
@@ -482,34 +580,36 @@ declare interface FeatureEntitlement {
|
|
|
482
580
|
valueType: EntitlementValueType;
|
|
483
581
|
}
|
|
484
582
|
|
|
583
|
+
export declare type FlagCheckListenerFn = CheckFlagReturnListenerFn | EmptyListenerFn;
|
|
584
|
+
|
|
585
|
+
export declare type FlagValueListenerFn = BooleanListenerFn | EmptyListenerFn;
|
|
586
|
+
|
|
587
|
+
/** A record of unique key-value pairs used for identifying a company or user */
|
|
588
|
+
export declare type Keys = Record<string, string>;
|
|
589
|
+
|
|
485
590
|
/**
|
|
591
|
+
*
|
|
486
592
|
* @export
|
|
487
593
|
*/
|
|
488
|
-
declare const
|
|
594
|
+
declare const MetricPeriod: {
|
|
489
595
|
readonly AllTime: "all_time";
|
|
490
596
|
readonly CurrentDay: "current_day";
|
|
491
597
|
readonly CurrentMonth: "current_month";
|
|
492
598
|
readonly CurrentWeek: "current_week";
|
|
493
599
|
};
|
|
494
600
|
|
|
495
|
-
declare type
|
|
601
|
+
declare type MetricPeriod = (typeof MetricPeriod)[keyof typeof MetricPeriod];
|
|
496
602
|
|
|
497
603
|
/**
|
|
604
|
+
*
|
|
498
605
|
* @export
|
|
499
606
|
*/
|
|
500
|
-
declare const
|
|
501
|
-
readonly FirstOfMonth: "first_of_month";
|
|
607
|
+
declare const MetricPeriodMonthReset: {
|
|
502
608
|
readonly BillingCycle: "billing_cycle";
|
|
609
|
+
readonly FirstOfMonth: "first_of_month";
|
|
503
610
|
};
|
|
504
611
|
|
|
505
|
-
declare type
|
|
506
|
-
|
|
507
|
-
export declare type FlagCheckListenerFn = CheckFlagReturnListenerFn | EmptyListenerFn;
|
|
508
|
-
|
|
509
|
-
export declare type FlagValueListenerFn = BooleanListenerFn | EmptyListenerFn;
|
|
510
|
-
|
|
511
|
-
/** A record of unique key-value pairs used for identifying a company or user */
|
|
512
|
-
export declare type Keys = Record<string, string>;
|
|
612
|
+
declare type MetricPeriodMonthReset = (typeof MetricPeriodMonthReset)[keyof typeof MetricPeriodMonthReset];
|
|
513
613
|
|
|
514
614
|
export declare type PendingListenerFn = BooleanListenerFn | EmptyListenerFn;
|
|
515
615
|
|
|
@@ -532,6 +632,22 @@ export declare enum RuleType {
|
|
|
532
632
|
DEFAULT = "default"
|
|
533
633
|
}
|
|
534
634
|
|
|
635
|
+
/**
|
|
636
|
+
*
|
|
637
|
+
* @export
|
|
638
|
+
*/
|
|
639
|
+
declare const RuleType_2: {
|
|
640
|
+
readonly CompanyOverride: "company_override";
|
|
641
|
+
readonly CompanyOverrideUsageExceeded: "company_override_usage_exceeded";
|
|
642
|
+
readonly Default: "default";
|
|
643
|
+
readonly GlobalOverride: "global_override";
|
|
644
|
+
readonly PlanEntitlement: "plan_entitlement";
|
|
645
|
+
readonly PlanEntitlementUsageExceeded: "plan_entitlement_usage_exceeded";
|
|
646
|
+
readonly Standard: "standard";
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
declare type RuleType_2 = (typeof RuleType_2)[keyof typeof RuleType_2];
|
|
650
|
+
|
|
535
651
|
export declare class Schematic {
|
|
536
652
|
private additionalHeaders;
|
|
537
653
|
private apiKey;
|
|
@@ -548,11 +664,17 @@ export declare class Schematic {
|
|
|
548
664
|
private isPending;
|
|
549
665
|
private isPendingListeners;
|
|
550
666
|
private planListeners;
|
|
667
|
+
private creditBalanceListeners;
|
|
551
668
|
private storage;
|
|
669
|
+
private persistFlagState;
|
|
670
|
+
private flagStateCacheKey;
|
|
671
|
+
private flagStateCacheMaxAgeMs;
|
|
672
|
+
private cachedFlagState;
|
|
552
673
|
private useWebSocket;
|
|
553
674
|
private checks;
|
|
554
675
|
private featureUsageEventMap;
|
|
555
676
|
private planChecks;
|
|
677
|
+
private creditBalances;
|
|
556
678
|
private webSocketUrl;
|
|
557
679
|
private webSocketConnectionTimeout;
|
|
558
680
|
private webSocketReconnect;
|
|
@@ -659,6 +781,13 @@ export declare class Schematic {
|
|
|
659
781
|
private stopRetryTimer;
|
|
660
782
|
private flushEventQueue;
|
|
661
783
|
private getAnonymousId;
|
|
784
|
+
private hasCachedValuesForContext;
|
|
785
|
+
private readFlagStateCache;
|
|
786
|
+
private reviveCachedCheck;
|
|
787
|
+
private reviveCachedPlan;
|
|
788
|
+
private reviveCachedCreditBalances;
|
|
789
|
+
private hydrateFlagStateFromCache;
|
|
790
|
+
private persistContextToCache;
|
|
662
791
|
private handleEvent;
|
|
663
792
|
private sendEvent;
|
|
664
793
|
private storeEvent;
|
|
@@ -758,6 +887,10 @@ export declare class Schematic {
|
|
|
758
887
|
addIsPendingListener: (listener: PendingListenerFn) => () => void;
|
|
759
888
|
private setIsPending;
|
|
760
889
|
getPlan: () => CheckPlanReturn | undefined;
|
|
890
|
+
/** Get the company's lease-aware credit balances for the current context, keyed by credit ID */
|
|
891
|
+
getCreditBalances: () => CreditBalances;
|
|
892
|
+
/** Get the company's lease-aware balance for a single credit type in the current context */
|
|
893
|
+
getCreditBalance: (creditId: string) => CreditBalance | undefined;
|
|
761
894
|
getFlagCheck: (flagKey: string) => CheckFlagReturn | undefined;
|
|
762
895
|
getFlagValue: (flagKey: string) => boolean | undefined;
|
|
763
896
|
/** Register an event listener that will be notified with the boolean value for a given flag when this value changes */
|
|
@@ -765,11 +898,14 @@ export declare class Schematic {
|
|
|
765
898
|
/** Register an event listener that will be notified with the full flag check response for a given flag whenever this value changes */
|
|
766
899
|
addFlagCheckListener: (flagKey: string, listener: FlagCheckListenerFn) => () => void;
|
|
767
900
|
addPlanListener: (listener: PlanListenerFn) => () => void;
|
|
901
|
+
/** Register an event listener that will be notified with the company's credit balances (keyed by credit ID) whenever they change */
|
|
902
|
+
addCreditBalanceListener: (listener: CreditBalanceListenerFn) => () => void;
|
|
768
903
|
private notifyFlagCheckListeners;
|
|
769
904
|
/** Add or update a CheckFlagReturn in the featureUsageEventMap */
|
|
770
905
|
private updateFeatureUsageEventMap;
|
|
771
906
|
private notifyFlagValueListeners;
|
|
772
907
|
private notifyPlanListeners;
|
|
908
|
+
private notifyCreditBalanceListeners;
|
|
773
909
|
}
|
|
774
910
|
|
|
775
911
|
/** Context for checking flags and sending events */
|
|
@@ -794,6 +930,12 @@ export declare type SchematicOptions = {
|
|
|
794
930
|
offline?: boolean;
|
|
795
931
|
/** Optionally provide a custom storage persister for client-side storage */
|
|
796
932
|
storage?: StoragePersister;
|
|
933
|
+
/** Persist flag check results (and plan) keyed by context to the storage persister so subsequent page loads can boot with last-known values rather than fallbacks. Defaults to true; set false to disable.
|
|
934
|
+
*
|
|
935
|
+
* When a cache hit is found on `setContext`, `isPending` flips to false synchronously even if the cache only contains a subset of the flags the app subscribes to — uncached flags will resolve via configured fallbacks (`flagCheckDefaults`/`flagValueDefaults`) until the WebSocket reconciles. */
|
|
936
|
+
persistFlagState?: boolean;
|
|
937
|
+
/** Maximum age (ms) of a persisted cache entry before it is treated as stale on hydration. Per-context; older entries are dropped at construction time and on the next persist. Defaults to 7 days. */
|
|
938
|
+
flagStateCacheMaxAgeMs?: number;
|
|
797
939
|
/** Use a WebSocket connection for real-time flag checks; if using this, run the cleanup function to close the connection */
|
|
798
940
|
useWebSocket?: boolean;
|
|
799
941
|
/** Optionally provide a custom WebSocket URL */
|