@schematichq/schematic-vue 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,56 +1,1026 @@
1
1
  import { App } from 'vue';
2
- import { CheckFlagReturn } from '@schematichq/schematic-js';
3
- import { CheckPlanReturn } from '@schematichq/schematic-js';
4
2
  import { ComputedRef } from 'vue';
5
- import { Event as Event_2 } from '@schematichq/schematic-js';
6
- import { EventBody } from '@schematichq/schematic-js';
7
- import { EventBodyIdentify } from '@schematichq/schematic-js';
8
- import { EventBodyTrack } from '@schematichq/schematic-js';
9
- import { EventType } from '@schematichq/schematic-js';
10
- import { Keys } from '@schematichq/schematic-js';
11
3
  import { Ref } from 'vue';
12
- import { RuleType } from '@schematichq/schematic-js';
13
- import { Schematic } from '@schematichq/schematic-js';
14
- import { SchematicContext } from '@schematichq/schematic-js';
15
- import * as SchematicJS from '@schematichq/schematic-js';
16
- import { SchematicOptions } from '@schematichq/schematic-js';
17
- import { StoragePersister } from '@schematichq/schematic-js';
18
- import { Traits } from '@schematichq/schematic-js';
19
- import { UsagePeriod } from '@schematichq/schematic-js';
20
4
 
21
5
  declare type BaseSchematicPluginOptions = Omit<SchematicJS.SchematicOptions, "client" | "publishableKey">;
22
6
 
23
- export { CheckFlagReturn }
7
+ declare type BooleanListenerFn = (value: boolean) => void;
24
8
 
25
- 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;
26
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];
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
+ };
27
365
  export { Event_2 as Event }
28
366
 
29
- export { EventBody }
367
+ export declare type EventBody = EventBodyIdentify | EventBodyTrack | EventBodyFlagCheck;
30
368
 
31
- export { EventBodyIdentify }
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
+ }
32
451
 
33
- export { EventBodyTrack }
452
+ declare function EventBodyFlagCheckToJSON(json: any): EventBodyFlagCheck;
34
453
 
35
- export { EventType }
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
+ }
36
588
 
37
- export { Keys }
589
+ declare type FlagCheckListenerFn = CheckFlagReturnListenerFn | EmptyListenerFn;
38
590
 
39
- export { RuleType }
591
+ declare type FlagValueListenerFn = BooleanListenerFn | EmptyListenerFn;
40
592
 
41
- export { Schematic }
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];
608
+
609
+ /**
610
+ *
611
+ * @export
612
+ */
613
+ declare const MetricPeriodMonthReset: {
614
+ readonly BillingCycle: "billing_cycle";
615
+ readonly FirstOfMonth: "first_of_month";
616
+ };
617
+
618
+ declare type MetricPeriodMonthReset = (typeof MetricPeriodMonthReset)[keyof typeof MetricPeriodMonthReset];
619
+
620
+ declare type PendingListenerFn = BooleanListenerFn | EmptyListenerFn;
621
+
622
+ declare type PlanListenerFn = CheckPlanReturnListenerFn | EmptyListenerFn;
623
+
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
+ }
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
+
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
+ }
42
916
 
43
917
  export declare interface SchematicComposableOpts {
44
918
  client?: SchematicJS.Schematic;
45
919
  }
46
920
 
47
- export { SchematicContext }
921
+ /** Context for checking flags and sending events */
922
+ export declare type SchematicContext = {
923
+ company?: Keys;
924
+ user?: Keys;
925
+ };
48
926
 
49
927
  export declare interface SchematicContextValue {
50
928
  client: SchematicJS.Schematic;
51
929
  }
52
930
 
53
- export { SchematicOptions }
931
+ declare namespace SchematicJS {
932
+ export {
933
+ CheckFlagResponseFromJSON,
934
+ CheckFlagsResponseFromJSON,
935
+ DatastreamCompanyPlanFromJSON,
936
+ EventBodyFlagCheckToJSON,
937
+ BooleanListenerFn,
938
+ CheckFlagResponseData,
939
+ CheckFlagReturn,
940
+ CheckFlagReturnFromJSON,
941
+ CheckFlagReturnListenerFn,
942
+ CheckOptions,
943
+ CheckPlanReturn,
944
+ CheckPlanReturnFromJSON,
945
+ CheckPlanReturnListenerFn,
946
+ CompanyCreditBalance,
947
+ CreditBalance,
948
+ CreditBalanceListenerFn,
949
+ CreditBalances,
950
+ CreditBalancesFromJSON,
951
+ CreditBalancesListenerFn,
952
+ EmptyListenerFn,
953
+ Event_2 as Event,
954
+ EventBody,
955
+ EventBodyFlagCheck,
956
+ EventBodyIdentify,
957
+ EventBodyTrack,
958
+ EventType,
959
+ FlagCheckListenerFn,
960
+ FlagValueListenerFn,
961
+ Keys,
962
+ PendingListenerFn,
963
+ PlanListenerFn,
964
+ RuleType,
965
+ Schematic,
966
+ SchematicContext,
967
+ SchematicOptions,
968
+ StoragePersister,
969
+ Traits,
970
+ TrialStatus,
971
+ UsagePeriod
972
+ }
973
+ }
974
+
975
+ export declare type SchematicOptions = {
976
+ /** Optionally provide any additional headers to include in the request */
977
+ additionalHeaders?: Record<string, string>;
978
+ /** Optionally provide a custom API URL */
979
+ apiUrl?: string;
980
+ /** Enable debug mode to log flag check results and events to the console.
981
+ * Can also be enabled at runtime via URL query parameter "schematic_debug=true" */
982
+ debug?: boolean;
983
+ /** Optionally provide a custom event URL */
984
+ eventUrl?: string;
985
+ /** Enable offline mode to prevent all network requests.
986
+ * When enabled, events are only logged not sent, and flag checks return fallback values.
987
+ * Can also be enabled at runtime via URL query parameter "schematic_offline=true" */
988
+ offline?: boolean;
989
+ /** Optionally provide a custom storage persister for client-side storage */
990
+ storage?: StoragePersister;
991
+ /** 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.
992
+ *
993
+ * 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. */
994
+ persistFlagState?: boolean;
995
+ /** 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. */
996
+ flagStateCacheMaxAgeMs?: number;
997
+ /** Use a WebSocket connection for real-time flag checks; if using this, run the cleanup function to close the connection */
998
+ useWebSocket?: boolean;
999
+ /** Optionally provide a custom WebSocket URL */
1000
+ webSocketUrl?: string;
1001
+ /** WebSocket connection timeout in milliseconds (default: 10000) */
1002
+ webSocketConnectionTimeout?: number;
1003
+ /** Enable automatic reconnection on WebSocket disconnect (default: true) */
1004
+ webSocketReconnect?: boolean;
1005
+ /** Maximum number of reconnection attempts (default: 7, set to Infinity for unlimited) */
1006
+ webSocketMaxReconnectAttempts?: number;
1007
+ /** Initial retry delay in milliseconds for exponential backoff (default: 1000) */
1008
+ webSocketInitialRetryDelay?: number;
1009
+ /** Maximum retry delay in milliseconds for exponential backoff (default: 30000) */
1010
+ webSocketMaxRetryDelay?: number;
1011
+ /** Maximum number of events to queue for retry when network is down (default: 100) */
1012
+ maxEventQueueSize?: number;
1013
+ /** Maximum number of retry attempts for failed events (default: 5) */
1014
+ maxEventRetries?: number;
1015
+ /** Initial retry delay in milliseconds for failed events (default: 1000) */
1016
+ eventRetryInitialDelay?: number;
1017
+ /** Maximum retry delay in milliseconds for failed events (default: 30000) */
1018
+ eventRetryMaxDelay?: number;
1019
+ /** Default boolean values for flags when Schematic API cannot be reached and no callsite fallback is provided */
1020
+ flagValueDefaults?: Record<string, boolean>;
1021
+ /** Default CheckFlagReturn objects for flags when Schematic API cannot be reached and no callsite fallback is provided */
1022
+ flagCheckDefaults?: Record<string, CheckFlagReturn>;
1023
+ };
54
1024
 
55
1025
  /**
56
1026
  * Vue plugin for Schematic
@@ -81,11 +1051,36 @@ declare type SchematicPluginOptionsWithPublishableKey = BaseSchematicPluginOptio
81
1051
  publishableKey: string;
82
1052
  };
83
1053
 
84
- export { StoragePersister }
1054
+ /** Optional type for implementing custom client-side storage */
1055
+ export declare type StoragePersister = {
1056
+ setItem(key: string, value: any): void;
1057
+ getItem(key: string): any;
1058
+ removeItem(key: string): void;
1059
+ };
1060
+
1061
+ /**
1062
+ * A flexible key/value type that can store any type of value on a company or user.
1063
+ */
1064
+ export declare type Traits = Record<string, any>;
1065
+
1066
+ /**
1067
+ *
1068
+ * @export
1069
+ */
1070
+ declare const TrialStatus: {
1071
+ readonly Active: "active";
1072
+ readonly Converted: "converted";
1073
+ readonly Expired: "expired";
1074
+ };
85
1075
 
86
- export { Traits }
1076
+ declare type TrialStatus = (typeof TrialStatus)[keyof typeof TrialStatus];
87
1077
 
88
- export { UsagePeriod }
1078
+ export declare enum UsagePeriod {
1079
+ ALL_TIME = "all_time",
1080
+ CURRENT_DAY = "current_day",
1081
+ CURRENT_MONTH = "current_month",
1082
+ CURRENT_WEEK = "current_week"
1083
+ }
89
1084
 
90
1085
  /**
91
1086
  * Access the Schematic client instance
@@ -118,6 +1113,38 @@ export declare const useSchematicContext: (opts?: SchematicComposableOpts) => {
118
1113
  setContext: (context: SchematicJS.SchematicContext) => Promise<void>;
119
1114
  };
120
1115
 
1116
+ /**
1117
+ * Get a company's live, lease-aware credit balance for a single credit type.
1118
+ * Returns reactive computed refs for the balance and a loading flag.
1119
+ *
1120
+ * Surfaces the spendable `settled` balance, sourced from the streamed credit
1121
+ * balances map (keyed by credit ID). It updates as partials arrive over the
1122
+ * DataStream, so it stays accurate during an open lease — when the raw
1123
+ * `remaining` would otherwise read stale / falsely "exhausted".
1124
+ *
1125
+ * The credit ID is available on a feature's entitlement: `useSchematicEntitlement(key)`
1126
+ * returns `creditId` for credit-based features.
1127
+ *
1128
+ * @param creditId - The credit ID to read the balance for
1129
+ * @param opts - Optional configuration including a client override
1130
+ * @returns Object with `balance` and `isLoading` computed refs
1131
+ *
1132
+ * @example
1133
+ * ```typescript
1134
+ * const { balance, isLoading } = useSchematicCreditBalance('credit-id')
1135
+ *
1136
+ * // In template
1137
+ * <div v-if="isLoading">Loading…</div>
1138
+ * <div v-else>{{ balance }} credits remaining</div>
1139
+ * ```
1140
+ */
1141
+ export declare const useSchematicCreditBalance: (creditId: string, opts?: SchematicComposableOpts) => {
1142
+ /** The spendable balance; 0 while loading or when the company holds no balance in this credit */
1143
+ balance: ComputedRef<number>;
1144
+ /** True while the balance is still loading and no value has arrived yet */
1145
+ isLoading: ComputedRef<boolean>;
1146
+ };
1147
+
121
1148
  /**
122
1149
  * Check feature entitlement with usage details
123
1150
  * Returns reactive refs for flag value, usage, allocation, and exceeded status
@@ -145,7 +1172,10 @@ export declare const useSchematicEntitlement: (key: string, opts?: UseSchematicF
145
1172
  check: ComputedRef< {
146
1173
  featureUsageExceeded?: boolean | undefined;
147
1174
  companyId?: string | undefined;
1175
+ creditId?: string | undefined;
148
1176
  creditRemaining?: number | undefined;
1177
+ creditReserved?: number | undefined;
1178
+ creditSettled?: number | undefined;
149
1179
  error?: string | undefined;
150
1180
  featureAllocation?: number | undefined;
151
1181
  featureUsage?: number | undefined;