@schematichq/schematic-react 1.4.1 → 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 +27 -0
- package/dist/schematic-react.cjs.js +665 -27
- package/dist/schematic-react.d.ts +184 -22
- package/dist/schematic-react.esm.js +665 -27
- package/package.json +16 -16
|
@@ -73,11 +73,11 @@ declare interface CheckFlagResponseData {
|
|
|
73
73
|
featureUsageEvent?: string | null;
|
|
74
74
|
/**
|
|
75
75
|
* Deprecated: Use Entitlement.MetricPeriod instead.
|
|
76
|
-
* @type {
|
|
76
|
+
* @type {MetricPeriod}
|
|
77
77
|
* @memberof CheckFlagResponseData
|
|
78
78
|
* @deprecated
|
|
79
79
|
*/
|
|
80
|
-
featureUsagePeriod?:
|
|
80
|
+
featureUsagePeriod?: MetricPeriod | null;
|
|
81
81
|
/**
|
|
82
82
|
* Deprecated: Use Entitlement.MetricResetAt instead.
|
|
83
83
|
* @type {Date}
|
|
@@ -111,10 +111,10 @@ declare interface CheckFlagResponseData {
|
|
|
111
111
|
ruleId?: string | null;
|
|
112
112
|
/**
|
|
113
113
|
* If a rule was found, its type
|
|
114
|
-
* @type {
|
|
114
|
+
* @type {RuleType}
|
|
115
115
|
* @memberof CheckFlagResponseData
|
|
116
116
|
*/
|
|
117
|
-
ruleType?:
|
|
117
|
+
ruleType?: RuleType_2 | null;
|
|
118
118
|
/**
|
|
119
119
|
* If user keys were provided and matched a user, its ID
|
|
120
120
|
* @type {string}
|
|
@@ -136,8 +136,14 @@ export declare type CheckFlagReturn = {
|
|
|
136
136
|
featureUsageExceeded?: boolean;
|
|
137
137
|
/** If company keys were provided and matched a company, its ID */
|
|
138
138
|
companyId?: string;
|
|
139
|
-
/** If the company has a credit-based entitlement for this feature, the
|
|
139
|
+
/** If the company has a credit-based entitlement for this feature, the ID of the credit */
|
|
140
|
+
creditId?: string;
|
|
141
|
+
/** 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) */
|
|
140
142
|
creditRemaining?: number;
|
|
143
|
+
/** 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 */
|
|
144
|
+
creditReserved?: number;
|
|
145
|
+
/** 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 */
|
|
146
|
+
creditSettled?: number;
|
|
141
147
|
/** If an error occurred while checking the flag, the error message */
|
|
142
148
|
error?: string;
|
|
143
149
|
/** If a numeric feature entitlement rule was matched, its allocation */
|
|
@@ -198,6 +204,14 @@ declare interface CheckFlagsResponse {
|
|
|
198
204
|
* @interface CheckFlagsResponseData
|
|
199
205
|
*/
|
|
200
206
|
declare interface CheckFlagsResponseData {
|
|
207
|
+
/**
|
|
208
|
+
* Lease-aware credit balances keyed by credit ID, covering every credit type the company holds a balance in
|
|
209
|
+
* @type {{ [key: string]: CompanyCreditBalance; }}
|
|
210
|
+
* @memberof CheckFlagsResponseData
|
|
211
|
+
*/
|
|
212
|
+
creditBalances?: {
|
|
213
|
+
[key: string]: CompanyCreditBalance;
|
|
214
|
+
};
|
|
201
215
|
/**
|
|
202
216
|
*
|
|
203
217
|
* @type {Array<CheckFlagResponseData>}
|
|
@@ -231,6 +245,62 @@ declare const CheckPlanReturnFromJSON: (json: any) => CheckPlanReturn;
|
|
|
231
245
|
|
|
232
246
|
declare type CheckPlanReturnListenerFn = (value: CheckPlanReturn) => void;
|
|
233
247
|
|
|
248
|
+
/**
|
|
249
|
+
* Schematic API
|
|
250
|
+
* Schematic API
|
|
251
|
+
*
|
|
252
|
+
* The version of the OpenAPI document: 0.1
|
|
253
|
+
*
|
|
254
|
+
*
|
|
255
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
256
|
+
* https://openapi-generator.tech
|
|
257
|
+
* Do not edit the class manually.
|
|
258
|
+
*/
|
|
259
|
+
/**
|
|
260
|
+
*
|
|
261
|
+
* @export
|
|
262
|
+
* @interface CompanyCreditBalance
|
|
263
|
+
*/
|
|
264
|
+
export declare interface CompanyCreditBalance {
|
|
265
|
+
/**
|
|
266
|
+
* Remaining credit, excluding any open lease hold (the value SDKs gate on)
|
|
267
|
+
* @type {number}
|
|
268
|
+
* @memberof CompanyCreditBalance
|
|
269
|
+
*/
|
|
270
|
+
remaining: number;
|
|
271
|
+
/**
|
|
272
|
+
* Amount held by the company's open credit lease, 0 when none is open
|
|
273
|
+
* @type {number}
|
|
274
|
+
* @memberof CompanyCreditBalance
|
|
275
|
+
*/
|
|
276
|
+
reserved: number;
|
|
277
|
+
/**
|
|
278
|
+
* Spendable balance including the open lease hold (remaining + reserved)
|
|
279
|
+
* @type {number}
|
|
280
|
+
* @memberof CompanyCreditBalance
|
|
281
|
+
*/
|
|
282
|
+
settled: number;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** A company's lease-aware balance for a single credit type */
|
|
286
|
+
export declare type CreditBalance = {
|
|
287
|
+
/** Spendable balance including any open lease hold (remaining + reserved); the number to display to end users */
|
|
288
|
+
settled: number;
|
|
289
|
+
/** Remaining credit excluding any open lease hold (the value lease-holding SDKs gate on) */
|
|
290
|
+
remaining: number;
|
|
291
|
+
/** Amount held by the company's open credit lease, 0 when none is open */
|
|
292
|
+
reserved: number;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
declare type CreditBalanceListenerFn = CreditBalancesListenerFn | EmptyListenerFn;
|
|
296
|
+
|
|
297
|
+
/** A company's lease-aware credit balances keyed by credit ID */
|
|
298
|
+
export declare type CreditBalances = Record<string, CreditBalance>;
|
|
299
|
+
|
|
300
|
+
declare const CreditBalancesFromJSON: (json: any) => CreditBalances;
|
|
301
|
+
|
|
302
|
+
declare type CreditBalancesListenerFn = (value: CreditBalances) => void;
|
|
303
|
+
|
|
234
304
|
/**
|
|
235
305
|
*
|
|
236
306
|
* @export
|
|
@@ -412,6 +482,12 @@ declare interface FeatureEntitlement {
|
|
|
412
482
|
* @memberof FeatureEntitlement
|
|
413
483
|
*/
|
|
414
484
|
allocation?: number | null;
|
|
485
|
+
/**
|
|
486
|
+
* If the company has a credit-based entitlement for this feature, the credit cost per unit of usage
|
|
487
|
+
* @type {number}
|
|
488
|
+
* @memberof FeatureEntitlement
|
|
489
|
+
*/
|
|
490
|
+
consumptionRate?: number | null;
|
|
415
491
|
/**
|
|
416
492
|
* If the company has a credit-based entitlement for this feature, the ID of the credit
|
|
417
493
|
* @type {string}
|
|
@@ -419,11 +495,23 @@ declare interface FeatureEntitlement {
|
|
|
419
495
|
*/
|
|
420
496
|
creditId?: string | null;
|
|
421
497
|
/**
|
|
422
|
-
* If the company has a credit-based entitlement for this feature, the
|
|
498
|
+
* 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
|
|
423
499
|
* @type {number}
|
|
424
500
|
* @memberof FeatureEntitlement
|
|
425
501
|
*/
|
|
426
502
|
creditRemaining?: number | null;
|
|
503
|
+
/**
|
|
504
|
+
* 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
|
|
505
|
+
* @type {number}
|
|
506
|
+
* @memberof FeatureEntitlement
|
|
507
|
+
*/
|
|
508
|
+
creditReserved?: number | null;
|
|
509
|
+
/**
|
|
510
|
+
* 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
|
|
511
|
+
* @type {number}
|
|
512
|
+
* @memberof FeatureEntitlement
|
|
513
|
+
*/
|
|
514
|
+
creditSettled?: number | null;
|
|
427
515
|
/**
|
|
428
516
|
* If the company has a credit-based entitlement for this feature, the total credit amount
|
|
429
517
|
* @type {number}
|
|
@@ -442,6 +530,12 @@ declare interface FeatureEntitlement {
|
|
|
442
530
|
* @memberof FeatureEntitlement
|
|
443
531
|
*/
|
|
444
532
|
eventName?: string | null;
|
|
533
|
+
/**
|
|
534
|
+
* For event-based or credit-metered feature entitlements, the event subtype whose usage is tracked
|
|
535
|
+
* @type {string}
|
|
536
|
+
* @memberof FeatureEntitlement
|
|
537
|
+
*/
|
|
538
|
+
eventSubtype?: string | null;
|
|
445
539
|
/**
|
|
446
540
|
* The ID of the feature
|
|
447
541
|
* @type {string}
|
|
@@ -456,10 +550,10 @@ declare interface FeatureEntitlement {
|
|
|
456
550
|
featureKey: string;
|
|
457
551
|
/**
|
|
458
552
|
* For event-based feature entitlements, the period over which usage is tracked
|
|
459
|
-
* @type {
|
|
553
|
+
* @type {MetricPeriod}
|
|
460
554
|
* @memberof FeatureEntitlement
|
|
461
555
|
*/
|
|
462
|
-
metricPeriod?:
|
|
556
|
+
metricPeriod?: MetricPeriod | null;
|
|
463
557
|
/**
|
|
464
558
|
* For event-based feature entitlements, when the usage period will reset
|
|
465
559
|
* @type {Date}
|
|
@@ -468,10 +562,10 @@ declare interface FeatureEntitlement {
|
|
|
468
562
|
metricResetAt?: Date | null;
|
|
469
563
|
/**
|
|
470
564
|
* For event-based feature entitlements that have a monthly period, whether that monthly reset is based on the calendar month or a billing cycle
|
|
471
|
-
* @type {
|
|
565
|
+
* @type {MetricPeriodMonthReset}
|
|
472
566
|
* @memberof FeatureEntitlement
|
|
473
567
|
*/
|
|
474
|
-
monthReset?:
|
|
568
|
+
monthReset?: MetricPeriodMonthReset | null;
|
|
475
569
|
/**
|
|
476
570
|
* For usage-based pricing, the soft limit for overage charges or the next tier boundary
|
|
477
571
|
* @type {number}
|
|
@@ -492,34 +586,36 @@ declare interface FeatureEntitlement {
|
|
|
492
586
|
valueType: EntitlementValueType;
|
|
493
587
|
}
|
|
494
588
|
|
|
589
|
+
declare type FlagCheckListenerFn = CheckFlagReturnListenerFn | EmptyListenerFn;
|
|
590
|
+
|
|
591
|
+
declare type FlagValueListenerFn = BooleanListenerFn | EmptyListenerFn;
|
|
592
|
+
|
|
593
|
+
/** A record of unique key-value pairs used for identifying a company or user */
|
|
594
|
+
export declare type Keys = Record<string, string>;
|
|
595
|
+
|
|
495
596
|
/**
|
|
597
|
+
*
|
|
496
598
|
* @export
|
|
497
599
|
*/
|
|
498
|
-
declare const
|
|
600
|
+
declare const MetricPeriod: {
|
|
499
601
|
readonly AllTime: "all_time";
|
|
500
602
|
readonly CurrentDay: "current_day";
|
|
501
603
|
readonly CurrentMonth: "current_month";
|
|
502
604
|
readonly CurrentWeek: "current_week";
|
|
503
605
|
};
|
|
504
606
|
|
|
505
|
-
declare type
|
|
607
|
+
declare type MetricPeriod = (typeof MetricPeriod)[keyof typeof MetricPeriod];
|
|
506
608
|
|
|
507
609
|
/**
|
|
610
|
+
*
|
|
508
611
|
* @export
|
|
509
612
|
*/
|
|
510
|
-
declare const
|
|
511
|
-
readonly FirstOfMonth: "first_of_month";
|
|
613
|
+
declare const MetricPeriodMonthReset: {
|
|
512
614
|
readonly BillingCycle: "billing_cycle";
|
|
615
|
+
readonly FirstOfMonth: "first_of_month";
|
|
513
616
|
};
|
|
514
617
|
|
|
515
|
-
declare type
|
|
516
|
-
|
|
517
|
-
declare type FlagCheckListenerFn = CheckFlagReturnListenerFn | EmptyListenerFn;
|
|
518
|
-
|
|
519
|
-
declare type FlagValueListenerFn = BooleanListenerFn | EmptyListenerFn;
|
|
520
|
-
|
|
521
|
-
/** A record of unique key-value pairs used for identifying a company or user */
|
|
522
|
-
export declare type Keys = Record<string, string>;
|
|
618
|
+
declare type MetricPeriodMonthReset = (typeof MetricPeriodMonthReset)[keyof typeof MetricPeriodMonthReset];
|
|
523
619
|
|
|
524
620
|
declare type PendingListenerFn = BooleanListenerFn | EmptyListenerFn;
|
|
525
621
|
|
|
@@ -542,6 +638,22 @@ export declare enum RuleType {
|
|
|
542
638
|
DEFAULT = "default"
|
|
543
639
|
}
|
|
544
640
|
|
|
641
|
+
/**
|
|
642
|
+
*
|
|
643
|
+
* @export
|
|
644
|
+
*/
|
|
645
|
+
declare const RuleType_2: {
|
|
646
|
+
readonly CompanyOverride: "company_override";
|
|
647
|
+
readonly CompanyOverrideUsageExceeded: "company_override_usage_exceeded";
|
|
648
|
+
readonly Default: "default";
|
|
649
|
+
readonly GlobalOverride: "global_override";
|
|
650
|
+
readonly PlanEntitlement: "plan_entitlement";
|
|
651
|
+
readonly PlanEntitlementUsageExceeded: "plan_entitlement_usage_exceeded";
|
|
652
|
+
readonly Standard: "standard";
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
declare type RuleType_2 = (typeof RuleType_2)[keyof typeof RuleType_2];
|
|
656
|
+
|
|
545
657
|
export declare class Schematic {
|
|
546
658
|
private additionalHeaders;
|
|
547
659
|
private apiKey;
|
|
@@ -558,11 +670,17 @@ export declare class Schematic {
|
|
|
558
670
|
private isPending;
|
|
559
671
|
private isPendingListeners;
|
|
560
672
|
private planListeners;
|
|
673
|
+
private creditBalanceListeners;
|
|
561
674
|
private storage;
|
|
675
|
+
private persistFlagState;
|
|
676
|
+
private flagStateCacheKey;
|
|
677
|
+
private flagStateCacheMaxAgeMs;
|
|
678
|
+
private cachedFlagState;
|
|
562
679
|
private useWebSocket;
|
|
563
680
|
private checks;
|
|
564
681
|
private featureUsageEventMap;
|
|
565
682
|
private planChecks;
|
|
683
|
+
private creditBalances;
|
|
566
684
|
private webSocketUrl;
|
|
567
685
|
private webSocketConnectionTimeout;
|
|
568
686
|
private webSocketReconnect;
|
|
@@ -669,6 +787,13 @@ export declare class Schematic {
|
|
|
669
787
|
private stopRetryTimer;
|
|
670
788
|
private flushEventQueue;
|
|
671
789
|
private getAnonymousId;
|
|
790
|
+
private hasCachedValuesForContext;
|
|
791
|
+
private readFlagStateCache;
|
|
792
|
+
private reviveCachedCheck;
|
|
793
|
+
private reviveCachedPlan;
|
|
794
|
+
private reviveCachedCreditBalances;
|
|
795
|
+
private hydrateFlagStateFromCache;
|
|
796
|
+
private persistContextToCache;
|
|
672
797
|
private handleEvent;
|
|
673
798
|
private sendEvent;
|
|
674
799
|
private storeEvent;
|
|
@@ -768,6 +893,10 @@ export declare class Schematic {
|
|
|
768
893
|
addIsPendingListener: (listener: PendingListenerFn) => () => void;
|
|
769
894
|
private setIsPending;
|
|
770
895
|
getPlan: () => CheckPlanReturn | undefined;
|
|
896
|
+
/** Get the company's lease-aware credit balances for the current context, keyed by credit ID */
|
|
897
|
+
getCreditBalances: () => CreditBalances;
|
|
898
|
+
/** Get the company's lease-aware balance for a single credit type in the current context */
|
|
899
|
+
getCreditBalance: (creditId: string) => CreditBalance | undefined;
|
|
771
900
|
getFlagCheck: (flagKey: string) => CheckFlagReturn | undefined;
|
|
772
901
|
getFlagValue: (flagKey: string) => boolean | undefined;
|
|
773
902
|
/** Register an event listener that will be notified with the boolean value for a given flag when this value changes */
|
|
@@ -775,11 +904,14 @@ export declare class Schematic {
|
|
|
775
904
|
/** Register an event listener that will be notified with the full flag check response for a given flag whenever this value changes */
|
|
776
905
|
addFlagCheckListener: (flagKey: string, listener: FlagCheckListenerFn) => () => void;
|
|
777
906
|
addPlanListener: (listener: PlanListenerFn) => () => void;
|
|
907
|
+
/** Register an event listener that will be notified with the company's credit balances (keyed by credit ID) whenever they change */
|
|
908
|
+
addCreditBalanceListener: (listener: CreditBalanceListenerFn) => () => void;
|
|
778
909
|
private notifyFlagCheckListeners;
|
|
779
910
|
/** Add or update a CheckFlagReturn in the featureUsageEventMap */
|
|
780
911
|
private updateFeatureUsageEventMap;
|
|
781
912
|
private notifyFlagValueListeners;
|
|
782
913
|
private notifyPlanListeners;
|
|
914
|
+
private notifyCreditBalanceListeners;
|
|
783
915
|
}
|
|
784
916
|
|
|
785
917
|
/** Context for checking flags and sending events */
|
|
@@ -792,6 +924,14 @@ declare interface SchematicContextProps {
|
|
|
792
924
|
client: SchematicJS.Schematic;
|
|
793
925
|
}
|
|
794
926
|
|
|
927
|
+
/** A company's credit balance for a single credit type, plus a loading flag */
|
|
928
|
+
export declare type SchematicCreditBalance = {
|
|
929
|
+
/** The spendable balance; 0 while loading or when the company holds no balance in this credit */
|
|
930
|
+
balance: number;
|
|
931
|
+
/** True while the balance is still loading and no value has arrived yet */
|
|
932
|
+
isLoading: boolean;
|
|
933
|
+
};
|
|
934
|
+
|
|
795
935
|
export declare interface SchematicHookOpts {
|
|
796
936
|
client?: SchematicJS.Schematic;
|
|
797
937
|
}
|
|
@@ -811,6 +951,12 @@ declare namespace SchematicJS {
|
|
|
811
951
|
CheckPlanReturn,
|
|
812
952
|
CheckPlanReturnFromJSON,
|
|
813
953
|
CheckPlanReturnListenerFn,
|
|
954
|
+
CompanyCreditBalance,
|
|
955
|
+
CreditBalance,
|
|
956
|
+
CreditBalanceListenerFn,
|
|
957
|
+
CreditBalances,
|
|
958
|
+
CreditBalancesFromJSON,
|
|
959
|
+
CreditBalancesListenerFn,
|
|
814
960
|
EmptyListenerFn,
|
|
815
961
|
Event_2 as Event,
|
|
816
962
|
EventBody,
|
|
@@ -850,6 +996,12 @@ export declare type SchematicOptions = {
|
|
|
850
996
|
offline?: boolean;
|
|
851
997
|
/** Optionally provide a custom storage persister for client-side storage */
|
|
852
998
|
storage?: StoragePersister;
|
|
999
|
+
/** 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.
|
|
1000
|
+
*
|
|
1001
|
+
* 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. */
|
|
1002
|
+
persistFlagState?: boolean;
|
|
1003
|
+
/** 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. */
|
|
1004
|
+
flagStateCacheMaxAgeMs?: number;
|
|
853
1005
|
/** Use a WebSocket connection for real-time flag checks; if using this, run the cleanup function to close the connection */
|
|
854
1006
|
useWebSocket?: boolean;
|
|
855
1007
|
/** Optionally provide a custom WebSocket URL */
|
|
@@ -929,6 +1081,16 @@ export declare const useSchematicContext: (opts?: SchematicHookOpts) => {
|
|
|
929
1081
|
setContext: (context: SchematicJS.SchematicContext) => Promise<void>;
|
|
930
1082
|
};
|
|
931
1083
|
|
|
1084
|
+
/**
|
|
1085
|
+
* Returns a company's live, lease-aware credit balance for a single credit type.
|
|
1086
|
+
*
|
|
1087
|
+
* Surfaces the spendable `settled` balance, sourced from the streamed
|
|
1088
|
+
* `credit_balances` map (keyed by credit ID). It re-renders as partials arrive
|
|
1089
|
+
* over the DataStream, so it stays accurate during an open lease — when the raw
|
|
1090
|
+
* `remaining` would otherwise read stale / falsely "exhausted".
|
|
1091
|
+
*/
|
|
1092
|
+
export declare const useSchematicCreditBalance: (creditId: string, opts?: SchematicHookOpts) => SchematicCreditBalance;
|
|
1093
|
+
|
|
932
1094
|
export declare const useSchematicEntitlement: (key: string, opts?: UseSchematicFlagOpts) => SchematicJS.CheckFlagReturn;
|
|
933
1095
|
|
|
934
1096
|
export declare const useSchematicEvents: (opts?: SchematicHookOpts) => {
|