@schematichq/schematic-react 1.4.0 → 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.
@@ -1,57 +1,1034 @@
1
- import { CheckFlagReturn } from '@schematichq/schematic-js';
2
- import { CheckPlanReturn } from '@schematichq/schematic-js';
3
- import { Event as Event_2 } from '@schematichq/schematic-js';
4
- import { EventBody } from '@schematichq/schematic-js';
5
- import { EventBodyIdentify } from '@schematichq/schematic-js';
6
- import { EventBodyTrack } from '@schematichq/schematic-js';
7
- import { EventType } from '@schematichq/schematic-js';
8
- import { Keys } from '@schematichq/schematic-js';
9
1
  import { default as React_2 } from 'react';
10
- import { RuleType } from '@schematichq/schematic-js';
11
- import { Schematic } from '@schematichq/schematic-js';
12
- import { SchematicContext } from '@schematichq/schematic-js';
13
- import * as SchematicJS from '@schematichq/schematic-js';
14
- import { SchematicOptions } from '@schematichq/schematic-js';
15
- import { StoragePersister } from '@schematichq/schematic-js';
16
- import { Traits } from '@schematichq/schematic-js';
17
- import { TrialStatus } from '@schematichq/schematic-js';
18
- import { UsagePeriod } from '@schematichq/schematic-js';
19
2
 
20
3
  declare type BaseSchematicProviderProps = Omit<SchematicJS.SchematicOptions, "client" | "publishableKey" | "useWebSocket"> & {
21
4
  children: React_2.ReactNode;
22
5
  };
23
6
 
24
- export { CheckFlagReturn }
7
+ declare type BooleanListenerFn = (value: boolean) => void;
25
8
 
26
- export { CheckPlanReturn }
9
+ /**
10
+ *
11
+ * @export
12
+ * @interface CheckFlagResponse
13
+ */
14
+ declare interface CheckFlagResponse {
15
+ /**
16
+ *
17
+ * @type {CheckFlagResponseData}
18
+ * @memberof CheckFlagResponse
19
+ */
20
+ data: CheckFlagResponseData;
21
+ /**
22
+ * Input parameters
23
+ * @type {object}
24
+ * @memberof CheckFlagResponse
25
+ */
26
+ params: object;
27
+ }
28
+
29
+ /**
30
+ *
31
+ * @export
32
+ * @interface CheckFlagResponseData
33
+ */
34
+ declare interface CheckFlagResponseData {
35
+ /**
36
+ * If company keys were provided and matched a company, its ID
37
+ * @type {string}
38
+ * @memberof CheckFlagResponseData
39
+ */
40
+ companyId?: string | null;
41
+ /**
42
+ * If a feature entitlement rule was matched, its entitlement details
43
+ * @type {FeatureEntitlement}
44
+ * @memberof CheckFlagResponseData
45
+ */
46
+ entitlement?: FeatureEntitlement;
47
+ /**
48
+ * If an error occurred while checking the flag, the error message
49
+ * @type {string}
50
+ * @memberof CheckFlagResponseData
51
+ */
52
+ error?: string | null;
53
+ /**
54
+ * Deprecated: Use Entitlement.Allocation instead.
55
+ * @type {number}
56
+ * @memberof CheckFlagResponseData
57
+ * @deprecated
58
+ */
59
+ featureAllocation?: number | null;
60
+ /**
61
+ * Deprecated: Use Entitlement.Usage instead.
62
+ * @type {number}
63
+ * @memberof CheckFlagResponseData
64
+ * @deprecated
65
+ */
66
+ featureUsage?: number | null;
67
+ /**
68
+ * Deprecated: Use Entitlement.EventName instead.
69
+ * @type {string}
70
+ * @memberof CheckFlagResponseData
71
+ * @deprecated
72
+ */
73
+ featureUsageEvent?: string | null;
74
+ /**
75
+ * Deprecated: Use Entitlement.MetricPeriod instead.
76
+ * @type {MetricPeriod}
77
+ * @memberof CheckFlagResponseData
78
+ * @deprecated
79
+ */
80
+ featureUsagePeriod?: MetricPeriod | null;
81
+ /**
82
+ * Deprecated: Use Entitlement.MetricResetAt instead.
83
+ * @type {Date}
84
+ * @memberof CheckFlagResponseData
85
+ * @deprecated
86
+ */
87
+ featureUsageResetAt?: Date | null;
88
+ /**
89
+ * The key used to check the flag
90
+ * @type {string}
91
+ * @memberof CheckFlagResponseData
92
+ */
93
+ flag: string;
94
+ /**
95
+ * If a flag was found, its ID
96
+ * @type {string}
97
+ * @memberof CheckFlagResponseData
98
+ */
99
+ flagId?: string | null;
100
+ /**
101
+ * A human-readable explanation of the result
102
+ * @type {string}
103
+ * @memberof CheckFlagResponseData
104
+ */
105
+ reason: string;
106
+ /**
107
+ * If a rule was found, its ID
108
+ * @type {string}
109
+ * @memberof CheckFlagResponseData
110
+ */
111
+ ruleId?: string | null;
112
+ /**
113
+ * If a rule was found, its type
114
+ * @type {RuleType}
115
+ * @memberof CheckFlagResponseData
116
+ */
117
+ ruleType?: RuleType_2 | null;
118
+ /**
119
+ * If user keys were provided and matched a user, its ID
120
+ * @type {string}
121
+ * @memberof CheckFlagResponseData
122
+ */
123
+ userId?: string | null;
124
+ /**
125
+ * A boolean flag check result; for feature entitlements, this represents whether further consumption of the feature is permitted
126
+ * @type {boolean}
127
+ * @memberof CheckFlagResponseData
128
+ */
129
+ value: boolean;
130
+ }
131
+
132
+ declare function CheckFlagResponseFromJSON(json: any): CheckFlagResponse;
133
+
134
+ export declare type CheckFlagReturn = {
135
+ /** The company has access to the feature, but has exceeded the usage limit */
136
+ featureUsageExceeded?: boolean;
137
+ /** If company keys were provided and matched a company, its ID */
138
+ companyId?: string;
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) */
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;
147
+ /** If an error occurred while checking the flag, the error message */
148
+ error?: string;
149
+ /** If a numeric feature entitlement rule was matched, its allocation */
150
+ featureAllocation?: number;
151
+ /** If a numeric feature entitlement rule was matched, the company's usage */
152
+ featureUsage?: number;
153
+ /** Event representing the feature usage */
154
+ featureUsageEvent?: string;
155
+ /** For event-based feature entitlement rules, the period over which usage is tracked (current_month, current_day, current_week, all_time) */
156
+ featureUsagePeriod?: UsagePeriod;
157
+ /** For event-based feature entitlement rules, when the usage period will reset */
158
+ featureUsageResetAt?: Date;
159
+ /** The key used to check the flag */
160
+ flag: string;
161
+ /** If a flag was found, its ID */
162
+ flagId?: string;
163
+ /** A human-readable explanation of the result */
164
+ reason: string;
165
+ /** If a rule was found, its ID */
166
+ ruleId?: string;
167
+ /** If a rule was found, its type */
168
+ ruleType?: RuleType;
169
+ /** For usage-based pricing, the soft limit for overage charges or the next tier boundary */
170
+ softLimit?: number;
171
+ /** If user keys were provided and matched a user, its ID */
172
+ userId?: string;
173
+ /** A boolean flag check result; for feature entitlements, this represents whether further consumption of the feature is permitted */
174
+ value: boolean;
175
+ };
176
+
177
+ declare const CheckFlagReturnFromJSON: (json: any) => CheckFlagReturn;
178
+
179
+ declare type CheckFlagReturnListenerFn = (value: CheckFlagReturn) => void;
180
+
181
+ /**
182
+ *
183
+ * @export
184
+ * @interface CheckFlagsResponse
185
+ */
186
+ declare interface CheckFlagsResponse {
187
+ /**
188
+ *
189
+ * @type {CheckFlagsResponseData}
190
+ * @memberof CheckFlagsResponse
191
+ */
192
+ data: CheckFlagsResponseData;
193
+ /**
194
+ * Input parameters
195
+ * @type {object}
196
+ * @memberof CheckFlagsResponse
197
+ */
198
+ params: object;
199
+ }
200
+
201
+ /**
202
+ *
203
+ * @export
204
+ * @interface CheckFlagsResponseData
205
+ */
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
+ };
215
+ /**
216
+ *
217
+ * @type {Array<CheckFlagResponseData>}
218
+ * @memberof CheckFlagsResponseData
219
+ */
220
+ flags: Array<CheckFlagResponseData>;
221
+ /**
222
+ *
223
+ * @type {DatastreamCompanyPlan}
224
+ * @memberof CheckFlagsResponseData
225
+ */
226
+ plan?: DatastreamCompanyPlan;
227
+ }
228
+
229
+ declare function CheckFlagsResponseFromJSON(json: any): CheckFlagsResponse;
230
+
231
+ declare type CheckOptions = {
232
+ context?: SchematicContext;
233
+ fallback?: boolean;
234
+ key: string;
235
+ };
236
+
237
+ export declare type CheckPlanReturn = {
238
+ id: string;
239
+ name: string;
240
+ trialEndDate?: Date;
241
+ trialStatus?: TrialStatus;
242
+ };
243
+
244
+ declare const CheckPlanReturnFromJSON: (json: any) => CheckPlanReturn;
245
+
246
+ declare type CheckPlanReturnListenerFn = (value: CheckPlanReturn) => void;
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
+
304
+ /**
305
+ *
306
+ * @export
307
+ * @interface DatastreamCompanyPlan
308
+ */
309
+ declare interface DatastreamCompanyPlan {
310
+ /**
311
+ *
312
+ * @type {string}
313
+ * @memberof DatastreamCompanyPlan
314
+ */
315
+ id: string;
316
+ /**
317
+ *
318
+ * @type {string}
319
+ * @memberof DatastreamCompanyPlan
320
+ */
321
+ name: string;
322
+ /**
323
+ *
324
+ * @type {Date}
325
+ * @memberof DatastreamCompanyPlan
326
+ */
327
+ trialEndDate?: Date | null;
328
+ /**
329
+ *
330
+ * @type {TrialStatus}
331
+ * @memberof DatastreamCompanyPlan
332
+ */
333
+ trialStatus?: TrialStatus | null;
334
+ }
335
+
336
+ declare function DatastreamCompanyPlanFromJSON(json: any): DatastreamCompanyPlan;
337
+
338
+ declare type EmptyListenerFn = () => void;
339
+
340
+ /**
341
+ *
342
+ * @export
343
+ */
344
+ declare const EntitlementValueType: {
345
+ readonly Boolean: "boolean";
346
+ readonly Credit: "credit";
347
+ readonly Numeric: "numeric";
348
+ readonly Trait: "trait";
349
+ readonly Unknown: "unknown";
350
+ readonly Unlimited: "unlimited";
351
+ };
352
+
353
+ declare type EntitlementValueType = (typeof EntitlementValueType)[keyof typeof EntitlementValueType];
27
354
 
355
+ declare type Event_2 = {
356
+ api_key: string;
357
+ body: EventBody;
358
+ sent_at: string;
359
+ tracker_event_id: string;
360
+ tracker_user_id: string;
361
+ type: EventType;
362
+ retry_count?: number;
363
+ next_retry_at?: number;
364
+ };
28
365
  export { Event_2 as Event }
29
366
 
30
- export { EventBody }
367
+ export declare type EventBody = EventBodyIdentify | EventBodyTrack | EventBodyFlagCheck;
368
+
369
+ /**
370
+ * Schematic API
371
+ * Schematic API
372
+ *
373
+ * The version of the OpenAPI document: 0.1
374
+ *
375
+ *
376
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
377
+ * https://openapi-generator.tech
378
+ * Do not edit the class manually.
379
+ */
380
+ /**
381
+ *
382
+ * @export
383
+ * @interface EventBodyFlagCheck
384
+ */
385
+ declare interface EventBodyFlagCheck {
386
+ /**
387
+ * Schematic company ID (starting with 'comp_') of the company evaluated, if any
388
+ * @type {string}
389
+ * @memberof EventBodyFlagCheck
390
+ */
391
+ companyId?: string | null;
392
+ /**
393
+ * Report an error that occurred during the flag check
394
+ * @type {string}
395
+ * @memberof EventBodyFlagCheck
396
+ */
397
+ error?: string | null;
398
+ /**
399
+ * Schematic flag ID (starting with 'flag_') for the flag matching the key, if any
400
+ * @type {string}
401
+ * @memberof EventBodyFlagCheck
402
+ */
403
+ flagId?: string | null;
404
+ /**
405
+ * The key of the flag being checked
406
+ * @type {string}
407
+ * @memberof EventBodyFlagCheck
408
+ */
409
+ flagKey: string;
410
+ /**
411
+ * The reason why the value was returned
412
+ * @type {string}
413
+ * @memberof EventBodyFlagCheck
414
+ */
415
+ reason: string;
416
+ /**
417
+ * Key-value pairs used to to identify company for which the flag was checked
418
+ * @type {{ [key: string]: string; }}
419
+ * @memberof EventBodyFlagCheck
420
+ */
421
+ reqCompany?: {
422
+ [key: string]: string;
423
+ } | null;
424
+ /**
425
+ * Key-value pairs used to to identify user for which the flag was checked
426
+ * @type {{ [key: string]: string; }}
427
+ * @memberof EventBodyFlagCheck
428
+ */
429
+ reqUser?: {
430
+ [key: string]: string;
431
+ } | null;
432
+ /**
433
+ * Schematic rule ID (starting with 'rule_') of the rule that matched for the flag, if any
434
+ * @type {string}
435
+ * @memberof EventBodyFlagCheck
436
+ */
437
+ ruleId?: string | null;
438
+ /**
439
+ * Schematic user ID (starting with 'user_') of the user evaluated, if any
440
+ * @type {string}
441
+ * @memberof EventBodyFlagCheck
442
+ */
443
+ userId?: string | null;
444
+ /**
445
+ * The value of the flag for the given company and/or user
446
+ * @type {boolean}
447
+ * @memberof EventBodyFlagCheck
448
+ */
449
+ value: boolean;
450
+ }
451
+
452
+ declare function EventBodyFlagCheckToJSON(json: any): EventBodyFlagCheck;
453
+
454
+ export declare type EventBodyIdentify = {
455
+ company?: {
456
+ keys?: Keys;
457
+ name?: string;
458
+ traits?: Traits;
459
+ };
460
+ keys?: Keys;
461
+ name?: string;
462
+ traits?: Traits;
463
+ };
464
+
465
+ export declare type EventBodyTrack = SchematicContext & {
466
+ event: string;
467
+ quantity?: number;
468
+ traits?: Traits;
469
+ };
470
+
471
+ export declare type EventType = "identify" | "track" | "flag_check";
472
+
473
+ /**
474
+ *
475
+ * @export
476
+ * @interface FeatureEntitlement
477
+ */
478
+ declare interface FeatureEntitlement {
479
+ /**
480
+ * If the company has a numeric entitlement for this feature, the allocated amount
481
+ * @type {number}
482
+ * @memberof FeatureEntitlement
483
+ */
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;
491
+ /**
492
+ * If the company has a credit-based entitlement for this feature, the ID of the credit
493
+ * @type {string}
494
+ * @memberof FeatureEntitlement
495
+ */
496
+ creditId?: string | null;
497
+ /**
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
499
+ * @type {number}
500
+ * @memberof FeatureEntitlement
501
+ */
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;
515
+ /**
516
+ * If the company has a credit-based entitlement for this feature, the total credit amount
517
+ * @type {number}
518
+ * @memberof FeatureEntitlement
519
+ */
520
+ creditTotal?: number | null;
521
+ /**
522
+ * If the company has a credit-based entitlement for this feature, the amount of credit used
523
+ * @type {number}
524
+ * @memberof FeatureEntitlement
525
+ */
526
+ creditUsed?: number | null;
527
+ /**
528
+ * If the feature is event-based, the name of the event tracked for usage
529
+ * @type {string}
530
+ * @memberof FeatureEntitlement
531
+ */
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;
539
+ /**
540
+ * The ID of the feature
541
+ * @type {string}
542
+ * @memberof FeatureEntitlement
543
+ */
544
+ featureId: string;
545
+ /**
546
+ * The key of the flag associated with the feature
547
+ * @type {string}
548
+ * @memberof FeatureEntitlement
549
+ */
550
+ featureKey: string;
551
+ /**
552
+ * For event-based feature entitlements, the period over which usage is tracked
553
+ * @type {MetricPeriod}
554
+ * @memberof FeatureEntitlement
555
+ */
556
+ metricPeriod?: MetricPeriod | null;
557
+ /**
558
+ * For event-based feature entitlements, when the usage period will reset
559
+ * @type {Date}
560
+ * @memberof FeatureEntitlement
561
+ */
562
+ metricResetAt?: Date | null;
563
+ /**
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
565
+ * @type {MetricPeriodMonthReset}
566
+ * @memberof FeatureEntitlement
567
+ */
568
+ monthReset?: MetricPeriodMonthReset | null;
569
+ /**
570
+ * For usage-based pricing, the soft limit for overage charges or the next tier boundary
571
+ * @type {number}
572
+ * @memberof FeatureEntitlement
573
+ */
574
+ softLimit?: number | null;
575
+ /**
576
+ * If the company has a numeric entitlement for this feature, the current usage amount
577
+ * @type {number}
578
+ * @memberof FeatureEntitlement
579
+ */
580
+ usage?: number | null;
581
+ /**
582
+ * The type of the entitlement value
583
+ * @type {EntitlementValueType}
584
+ * @memberof FeatureEntitlement
585
+ */
586
+ valueType: EntitlementValueType;
587
+ }
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
+
596
+ /**
597
+ *
598
+ * @export
599
+ */
600
+ declare const MetricPeriod: {
601
+ readonly AllTime: "all_time";
602
+ readonly CurrentDay: "current_day";
603
+ readonly CurrentMonth: "current_month";
604
+ readonly CurrentWeek: "current_week";
605
+ };
606
+
607
+ declare type MetricPeriod = (typeof MetricPeriod)[keyof typeof MetricPeriod];
31
608
 
32
- export { EventBodyIdentify }
609
+ /**
610
+ *
611
+ * @export
612
+ */
613
+ declare const MetricPeriodMonthReset: {
614
+ readonly BillingCycle: "billing_cycle";
615
+ readonly FirstOfMonth: "first_of_month";
616
+ };
33
617
 
34
- export { EventBodyTrack }
618
+ declare type MetricPeriodMonthReset = (typeof MetricPeriodMonthReset)[keyof typeof MetricPeriodMonthReset];
35
619
 
36
- export { EventType }
620
+ declare type PendingListenerFn = BooleanListenerFn | EmptyListenerFn;
37
621
 
38
- export { Keys }
622
+ declare type PlanListenerFn = CheckPlanReturnListenerFn | EmptyListenerFn;
39
623
 
40
- export { RuleType }
624
+ export declare enum RuleType {
625
+ /** A global rule that, if present, will override all other rules for a flag */
626
+ GLOBAL_OVERRIDE = "global_override",
627
+ /** Rule type indicating feature access provisioned to a company via an override */
628
+ COMPANY_OVERRIDE = "company_override",
629
+ /** Rule type indicating that feature access has been provisione to a company via an override, but the usage limit has been reached or exceeded */
630
+ COMPANY_OVERRIDE_USAGE_EXCEEDED = "company_override_usage_exceeded",
631
+ /** Rule type indicating feature access provisioned to a company via its base plan or add-ons */
632
+ PLAN_ENTITLEMENT = "plan_entitlement",
633
+ /** Rule type indicating that feature access has been provisione to a company via base plan or add-ons, but the usage limit has been reached or exceeded */
634
+ PLAN_ENTITLEMENT_USAGE_EXCEEDED = "plan_entitlement_usage_exceeded",
635
+ /** General-purpose targeting rule */
636
+ STANDARD = "standard",
637
+ /** Default rule type that will be used if no other rules are matched */
638
+ DEFAULT = "default"
639
+ }
41
640
 
42
- export { Schematic }
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
+ };
43
654
 
44
- export { SchematicContext }
655
+ declare type RuleType_2 = (typeof RuleType_2)[keyof typeof RuleType_2];
656
+
657
+ export declare class Schematic {
658
+ private additionalHeaders;
659
+ private apiKey;
660
+ private apiUrl;
661
+ private conn;
662
+ private context;
663
+ private debugEnabled;
664
+ private offlineEnabled;
665
+ private eventQueue;
666
+ private contextDependentEventQueue;
667
+ private eventUrl;
668
+ private flagCheckListeners;
669
+ private flagValueListeners;
670
+ private isPending;
671
+ private isPendingListeners;
672
+ private planListeners;
673
+ private creditBalanceListeners;
674
+ private storage;
675
+ private persistFlagState;
676
+ private flagStateCacheKey;
677
+ private flagStateCacheMaxAgeMs;
678
+ private cachedFlagState;
679
+ private useWebSocket;
680
+ private checks;
681
+ private featureUsageEventMap;
682
+ private planChecks;
683
+ private creditBalances;
684
+ private webSocketUrl;
685
+ private webSocketConnectionTimeout;
686
+ private webSocketReconnect;
687
+ private webSocketMaxReconnectAttempts;
688
+ private webSocketMaxConnectionAttempts;
689
+ private webSocketInitialRetryDelay;
690
+ private webSocketMaxRetryDelay;
691
+ private wsReconnectAttempts;
692
+ private wsReconnectTimer;
693
+ private wsIntentionalDisconnect;
694
+ private currentWebSocket;
695
+ private isConnecting;
696
+ private maxEventQueueSize;
697
+ private maxEventRetries;
698
+ private eventRetryInitialDelay;
699
+ private eventRetryMaxDelay;
700
+ private retryTimer;
701
+ private flagValueDefaults;
702
+ private flagCheckDefaults;
703
+ private fallbackCheckCache;
704
+ constructor(apiKey: string, options?: SchematicOptions);
705
+ /**
706
+ * Resolve fallback value according to priority order:
707
+ * 1. Callsite fallback value (if provided)
708
+ * 2. Boolean value from flagCheckDefaults initialization option
709
+ * 3. Boolean value from flagValueDefaults initialization option
710
+ * 4. Default to false
711
+ */
712
+ private resolveFallbackValue;
713
+ /**
714
+ * Resolve complete CheckFlagReturn object according to priority order:
715
+ * 1. Use callsite fallback for boolean value, construct CheckFlagReturn
716
+ * 2. Use flagCheckDefaults if available for this flag
717
+ * 3. Use flagValueDefaults if available for this flag, construct CheckFlagReturn
718
+ * 4. Default CheckFlagReturn with value: false
719
+ */
720
+ private resolveFallbackCheckFlagReturn;
721
+ /**
722
+ * Get value for a single flag.
723
+ * In WebSocket mode, returns cached values if connection is active, otherwise establishes
724
+ * new connection and then returns the requested value. Falls back to preconfigured fallback
725
+ * values if WebSocket connection fails.
726
+ * In REST mode, makes an API call for each check.
727
+ */
728
+ checkFlag(options: CheckOptions): Promise<boolean>;
729
+ /**
730
+ * Helper function to log debug messages
731
+ * Only logs if debug mode is enabled
732
+ */
733
+ debug(message: string, ...args: unknown[]): void;
734
+ /**
735
+ * Create a persistent message handler for websocket flag updates
736
+ */
737
+ private createPersistentMessageHandler;
738
+ /**
739
+ * Helper function to check if client is in offline mode
740
+ */
741
+ private isOffline;
742
+ /**
743
+ * Submit a flag check event
744
+ * Records data about a flag check for analytics
745
+ */
746
+ private submitFlagCheckEvent;
747
+ /**
748
+ * Make an API call to fetch all flag values for a given context.
749
+ * Recommended for use in REST mode only.
750
+ * In offline mode, returns an empty object.
751
+ */
752
+ checkFlags: (context?: SchematicContext) => Promise<Record<string, boolean>>;
753
+ /**
754
+ * Send an identify event.
755
+ * This will set the context for subsequent flag evaluation and events, and will also
756
+ * send an identify event to the Schematic API which will upsert a user and company.
757
+ */
758
+ identify: (body: EventBodyIdentify) => Promise<void>;
759
+ /**
760
+ * Set the flag evaluation context.
761
+ * In WebSocket mode, this will:
762
+ * 1. Open a websocket connection if not already open
763
+ * 2. Send the context to the server
764
+ * 3. Wait for initial flag values to be returned
765
+ * The promise resolves when initial flag values are received.
766
+ * In offline mode, this will just set the context locally without connecting.
767
+ */
768
+ setContext: (context: SchematicContext) => Promise<void>;
769
+ /**
770
+ * Send a track event
771
+ * Track usage for a company and/or user.
772
+ * Optimistically updates feature usage flags if tracking a featureUsageEvent.
773
+ */
774
+ track: (body: EventBodyTrack) => Promise<void>;
775
+ /**
776
+ * Optimistically update feature usage flags associated with a tracked event
777
+ * This updates flags in memory with updated usage counts and value/featureUsageExceeded flags
778
+ * before the network request completes
779
+ */
780
+ private optimisticallyUpdateFeatureUsage;
781
+ /**
782
+ * Event processing
783
+ */
784
+ private hasContext;
785
+ private flushContextDependentEventQueue;
786
+ private startRetryTimer;
787
+ private stopRetryTimer;
788
+ private flushEventQueue;
789
+ private getAnonymousId;
790
+ private hasCachedValuesForContext;
791
+ private readFlagStateCache;
792
+ private reviveCachedCheck;
793
+ private reviveCachedPlan;
794
+ private reviveCachedCreditBalances;
795
+ private hydrateFlagStateFromCache;
796
+ private persistContextToCache;
797
+ private handleEvent;
798
+ private sendEvent;
799
+ private storeEvent;
800
+ /**
801
+ * Websocket management
802
+ */
803
+ /**
804
+ * Force an immediate WebSocket reconnection.
805
+ * This is useful when the application returns from a background state (e.g., mobile app
806
+ * coming back to foreground) and wants to immediately re-establish the connection
807
+ * rather than waiting for the exponential backoff timer.
808
+ *
809
+ * This method will:
810
+ * - Cancel any pending reconnection timer
811
+ * - Reset the reconnection attempt counter
812
+ * - Close any existing connection
813
+ * - Immediately attempt to reconnect
814
+ * - Re-send the current context to get fresh flag values
815
+ *
816
+ * Use this when you need guaranteed fresh values (e.g., after an in-app purchase).
817
+ *
818
+ * @example
819
+ * ```typescript
820
+ * // React Native example: reconnect when app comes to foreground
821
+ * useEffect(() => {
822
+ * const subscription = AppState.addEventListener("change", (state) => {
823
+ * if (state === "active") {
824
+ * client.forceReconnect();
825
+ * }
826
+ * });
827
+ * return () => subscription.remove();
828
+ * }, [client]);
829
+ * ```
830
+ */
831
+ forceReconnect: () => Promise<void>;
832
+ /**
833
+ * Reconnect the WebSocket connection only if the current connection is unhealthy.
834
+ * This is useful when the application returns from a background state and wants to
835
+ * ensure a healthy connection exists, but doesn't need to force a reconnection if
836
+ * the connection is still active.
837
+ *
838
+ * This method will:
839
+ * - Check if an existing connection is healthy (readyState === OPEN)
840
+ * - If healthy, return immediately without reconnecting
841
+ * - If unhealthy, perform the same reconnection logic as forceReconnect()
842
+ *
843
+ * Use this when you want efficient reconnection that avoids unnecessary disconnects.
844
+ *
845
+ * @example
846
+ * ```typescript
847
+ * // React Native example: reconnect only if needed when app comes to foreground
848
+ * useEffect(() => {
849
+ * const subscription = AppState.addEventListener("change", (state) => {
850
+ * if (state === "active") {
851
+ * client.reconnectIfNeeded();
852
+ * }
853
+ * });
854
+ * return () => subscription.remove();
855
+ * }, [client]);
856
+ * ```
857
+ */
858
+ reconnectIfNeeded: () => Promise<void>;
859
+ /**
860
+ * Internal method to handle reconnection logic for both forceReconnect and reconnectIfNeeded.
861
+ */
862
+ private reconnect;
863
+ /**
864
+ * If using websocket mode, close the connection when done.
865
+ * In offline mode, this is a no-op.
866
+ */
867
+ cleanup: () => Promise<void>;
868
+ /**
869
+ * Calculate the delay for the next reconnection attempt using exponential backoff with jitter.
870
+ * This helps prevent dogpiling when the server recovers from an outage.
871
+ */
872
+ private calculateReconnectDelay;
873
+ /**
874
+ * Handle browser going offline
875
+ */
876
+ private handleNetworkOffline;
877
+ /**
878
+ * Handle browser coming back online
879
+ */
880
+ private handleNetworkOnline;
881
+ /**
882
+ * Attempt to reconnect the WebSocket connection with exponential backoff.
883
+ * Called automatically when the connection closes unexpectedly.
884
+ */
885
+ private attemptReconnect;
886
+ private wsConnect;
887
+ private wsConnectOnce;
888
+ private wsSendMessage;
889
+ /**
890
+ * State management
891
+ */
892
+ getIsPending: () => boolean;
893
+ addIsPendingListener: (listener: PendingListenerFn) => () => void;
894
+ private setIsPending;
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;
900
+ getFlagCheck: (flagKey: string) => CheckFlagReturn | undefined;
901
+ getFlagValue: (flagKey: string) => boolean | undefined;
902
+ /** Register an event listener that will be notified with the boolean value for a given flag when this value changes */
903
+ addFlagValueListener: (flagKey: string, listener: FlagValueListenerFn) => () => void;
904
+ /** Register an event listener that will be notified with the full flag check response for a given flag whenever this value changes */
905
+ addFlagCheckListener: (flagKey: string, listener: FlagCheckListenerFn) => () => void;
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;
909
+ private notifyFlagCheckListeners;
910
+ /** Add or update a CheckFlagReturn in the featureUsageEventMap */
911
+ private updateFeatureUsageEventMap;
912
+ private notifyFlagValueListeners;
913
+ private notifyPlanListeners;
914
+ private notifyCreditBalanceListeners;
915
+ }
916
+
917
+ /** Context for checking flags and sending events */
918
+ export declare type SchematicContext = {
919
+ company?: Keys;
920
+ user?: Keys;
921
+ };
45
922
 
46
923
  declare interface SchematicContextProps {
47
924
  client: SchematicJS.Schematic;
48
925
  }
49
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
+
50
935
  export declare interface SchematicHookOpts {
51
936
  client?: SchematicJS.Schematic;
52
937
  }
53
938
 
54
- export { SchematicOptions }
939
+ declare namespace SchematicJS {
940
+ export {
941
+ CheckFlagResponseFromJSON,
942
+ CheckFlagsResponseFromJSON,
943
+ DatastreamCompanyPlanFromJSON,
944
+ EventBodyFlagCheckToJSON,
945
+ BooleanListenerFn,
946
+ CheckFlagResponseData,
947
+ CheckFlagReturn,
948
+ CheckFlagReturnFromJSON,
949
+ CheckFlagReturnListenerFn,
950
+ CheckOptions,
951
+ CheckPlanReturn,
952
+ CheckPlanReturnFromJSON,
953
+ CheckPlanReturnListenerFn,
954
+ CompanyCreditBalance,
955
+ CreditBalance,
956
+ CreditBalanceListenerFn,
957
+ CreditBalances,
958
+ CreditBalancesFromJSON,
959
+ CreditBalancesListenerFn,
960
+ EmptyListenerFn,
961
+ Event_2 as Event,
962
+ EventBody,
963
+ EventBodyFlagCheck,
964
+ EventBodyIdentify,
965
+ EventBodyTrack,
966
+ EventType,
967
+ FlagCheckListenerFn,
968
+ FlagValueListenerFn,
969
+ Keys,
970
+ PendingListenerFn,
971
+ PlanListenerFn,
972
+ RuleType,
973
+ Schematic,
974
+ SchematicContext,
975
+ SchematicOptions,
976
+ StoragePersister,
977
+ Traits,
978
+ TrialStatus,
979
+ UsagePeriod
980
+ }
981
+ }
982
+
983
+ export declare type SchematicOptions = {
984
+ /** Optionally provide any additional headers to include in the request */
985
+ additionalHeaders?: Record<string, string>;
986
+ /** Optionally provide a custom API URL */
987
+ apiUrl?: string;
988
+ /** Enable debug mode to log flag check results and events to the console.
989
+ * Can also be enabled at runtime via URL query parameter "schematic_debug=true" */
990
+ debug?: boolean;
991
+ /** Optionally provide a custom event URL */
992
+ eventUrl?: string;
993
+ /** Enable offline mode to prevent all network requests.
994
+ * When enabled, events are only logged not sent, and flag checks return fallback values.
995
+ * Can also be enabled at runtime via URL query parameter "schematic_offline=true" */
996
+ offline?: boolean;
997
+ /** Optionally provide a custom storage persister for client-side storage */
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;
1005
+ /** Use a WebSocket connection for real-time flag checks; if using this, run the cleanup function to close the connection */
1006
+ useWebSocket?: boolean;
1007
+ /** Optionally provide a custom WebSocket URL */
1008
+ webSocketUrl?: string;
1009
+ /** WebSocket connection timeout in milliseconds (default: 10000) */
1010
+ webSocketConnectionTimeout?: number;
1011
+ /** Enable automatic reconnection on WebSocket disconnect (default: true) */
1012
+ webSocketReconnect?: boolean;
1013
+ /** Maximum number of reconnection attempts (default: 7, set to Infinity for unlimited) */
1014
+ webSocketMaxReconnectAttempts?: number;
1015
+ /** Initial retry delay in milliseconds for exponential backoff (default: 1000) */
1016
+ webSocketInitialRetryDelay?: number;
1017
+ /** Maximum retry delay in milliseconds for exponential backoff (default: 30000) */
1018
+ webSocketMaxRetryDelay?: number;
1019
+ /** Maximum number of events to queue for retry when network is down (default: 100) */
1020
+ maxEventQueueSize?: number;
1021
+ /** Maximum number of retry attempts for failed events (default: 5) */
1022
+ maxEventRetries?: number;
1023
+ /** Initial retry delay in milliseconds for failed events (default: 1000) */
1024
+ eventRetryInitialDelay?: number;
1025
+ /** Maximum retry delay in milliseconds for failed events (default: 30000) */
1026
+ eventRetryMaxDelay?: number;
1027
+ /** Default boolean values for flags when Schematic API cannot be reached and no callsite fallback is provided */
1028
+ flagValueDefaults?: Record<string, boolean>;
1029
+ /** Default CheckFlagReturn objects for flags when Schematic API cannot be reached and no callsite fallback is provided */
1030
+ flagCheckDefaults?: Record<string, CheckFlagReturn>;
1031
+ };
55
1032
 
56
1033
  export declare const SchematicProvider: React_2.FC<SchematicProviderProps>;
57
1034
 
@@ -67,13 +1044,36 @@ declare type SchematicProviderPropsWithPublishableKey = BaseSchematicProviderPro
67
1044
  publishableKey: string;
68
1045
  };
69
1046
 
70
- export { StoragePersister }
1047
+ /** Optional type for implementing custom client-side storage */
1048
+ export declare type StoragePersister = {
1049
+ setItem(key: string, value: any): void;
1050
+ getItem(key: string): any;
1051
+ removeItem(key: string): void;
1052
+ };
1053
+
1054
+ /**
1055
+ * A flexible key/value type that can store any type of value on a company or user.
1056
+ */
1057
+ export declare type Traits = Record<string, any>;
71
1058
 
72
- export { Traits }
1059
+ /**
1060
+ *
1061
+ * @export
1062
+ */
1063
+ export declare const TrialStatus: {
1064
+ readonly Active: "active";
1065
+ readonly Converted: "converted";
1066
+ readonly Expired: "expired";
1067
+ };
73
1068
 
74
- export { TrialStatus }
1069
+ export declare type TrialStatus = (typeof TrialStatus)[keyof typeof TrialStatus];
75
1070
 
76
- export { UsagePeriod }
1071
+ export declare enum UsagePeriod {
1072
+ ALL_TIME = "all_time",
1073
+ CURRENT_DAY = "current_day",
1074
+ CURRENT_MONTH = "current_month",
1075
+ CURRENT_WEEK = "current_week"
1076
+ }
77
1077
 
78
1078
  export declare const useSchematic: () => SchematicContextProps;
79
1079
 
@@ -81,6 +1081,16 @@ export declare const useSchematicContext: (opts?: SchematicHookOpts) => {
81
1081
  setContext: (context: SchematicJS.SchematicContext) => Promise<void>;
82
1082
  };
83
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
+
84
1094
  export declare const useSchematicEntitlement: (key: string, opts?: UseSchematicFlagOpts) => SchematicJS.CheckFlagReturn;
85
1095
 
86
1096
  export declare const useSchematicEvents: (opts?: SchematicHookOpts) => {