@schematichq/schematic-vue 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,165 @@
1
1
  import { App } from 'vue';
2
2
  import { ComputedRef } from 'vue';
3
+ import { MaybeRefOrGetter } from 'vue';
3
4
  import { Ref } from 'vue';
4
5
 
6
+ declare type AccessToken = string | AccessTokenProvider;
7
+
8
+ /**
9
+ * The machinery every temporary-access-token surface shares: which session is
10
+ * being read, the credential for it, and the request that carries it. It
11
+ * knows nothing about invoices, subscriptions, or checkout — a domain client
12
+ * (see `SchematicBillingClient`) is constructed over it, and several may
13
+ * share one session rather than each minting tokens of its own.
14
+ */
15
+ /** Called once per session, and again when a request comes back 401. */
16
+ declare type AccessTokenProvider = () => Promise<string | AccessTokenResult>;
17
+
18
+ /**
19
+ * A bare token, or one that says when it expires and who it was minted for.
20
+ * `company`/`user` are the host restating the pair it asked for; stated, they
21
+ * are checked against the session the resolution was started for.
22
+ */
23
+ declare interface AccessTokenResult {
24
+ token: string;
25
+ expiresAt?: Date | string | null;
26
+ company?: string;
27
+ user?: string;
28
+ }
29
+
5
30
  declare type BaseSchematicPluginOptions = Omit<SchematicJS.SchematicOptions, "client" | "publishableKey">;
6
31
 
32
+ declare namespace billingApi {
33
+ export {
34
+ instanceOfApiError,
35
+ ApiErrorFromJSON,
36
+ ApiErrorFromJSONTyped,
37
+ ApiErrorToJSON,
38
+ ApiErrorToJSONTyped,
39
+ ApiError,
40
+ instanceOfCompanyDiscountResponseData,
41
+ CompanyDiscountResponseDataFromJSON,
42
+ CompanyDiscountResponseDataFromJSONTyped,
43
+ CompanyDiscountResponseDataToJSON,
44
+ CompanyDiscountResponseDataToJSONTyped,
45
+ CompanyDiscountResponseData,
46
+ instanceOfCompanyInvoiceResponseData,
47
+ CompanyInvoiceResponseDataFromJSON,
48
+ CompanyInvoiceResponseDataFromJSONTyped,
49
+ CompanyInvoiceResponseDataToJSON,
50
+ CompanyInvoiceResponseDataToJSONTyped,
51
+ CompanyInvoiceResponseData,
52
+ instanceOfCompanyInvoicesResponseData,
53
+ CompanyInvoicesResponseDataFromJSON,
54
+ CompanyInvoicesResponseDataFromJSONTyped,
55
+ CompanyInvoicesResponseDataToJSON,
56
+ CompanyInvoicesResponseDataToJSONTyped,
57
+ CompanyInvoicesResponseData,
58
+ instanceOfCompanyUpcomingInvoiceResponseData,
59
+ CompanyUpcomingInvoiceResponseDataFromJSON,
60
+ CompanyUpcomingInvoiceResponseDataFromJSONTyped,
61
+ CompanyUpcomingInvoiceResponseDataToJSON,
62
+ CompanyUpcomingInvoiceResponseDataToJSONTyped,
63
+ CompanyUpcomingInvoiceResponseData,
64
+ instanceOfGetCompanyInvoicesParams,
65
+ GetCompanyInvoicesParamsFromJSON,
66
+ GetCompanyInvoicesParamsFromJSONTyped,
67
+ GetCompanyInvoicesParamsToJSON,
68
+ GetCompanyInvoicesParamsToJSONTyped,
69
+ GetCompanyInvoicesParams,
70
+ instanceOfGetCompanyInvoicesResponse,
71
+ GetCompanyInvoicesResponseFromJSON,
72
+ GetCompanyInvoicesResponseFromJSONTyped,
73
+ GetCompanyInvoicesResponseToJSON,
74
+ GetCompanyInvoicesResponseToJSONTyped,
75
+ GetCompanyInvoicesResponse,
76
+ instanceOfGetCompanyUpcomingInvoiceResponse,
77
+ GetCompanyUpcomingInvoiceResponseFromJSON,
78
+ GetCompanyUpcomingInvoiceResponseFromJSONTyped,
79
+ GetCompanyUpcomingInvoiceResponseToJSON,
80
+ GetCompanyUpcomingInvoiceResponseToJSONTyped,
81
+ GetCompanyUpcomingInvoiceResponse,
82
+ instanceOfInvoiceStatus,
83
+ InvoiceStatusFromJSON,
84
+ InvoiceStatusFromJSONTyped,
85
+ InvoiceStatusToJSON,
86
+ InvoiceStatusToJSONTyped,
87
+ InvoiceStatus
88
+ }
89
+ }
90
+
91
+ /**
92
+ * What a reader of billing data can ask for. Subscription and usage — the
93
+ * rest of what `hydrate` serves — and the checkout calls that change them
94
+ * join this interface as their endpoints ship.
95
+ */
96
+ declare interface BillingClient {
97
+ fetchInvoices(params: InvoicesRequest): Promise<InvoicesResult>;
98
+ /** `null` when the company has no next bill. */
99
+ fetchUpcomingInvoice(): Promise<UpcomingInvoice | null>;
100
+ readonly sessionStatus: SessionStatus;
101
+ readonly sessionKey: string | undefined;
102
+ setSession(session: SessionInput): void;
103
+ onSessionChange(listener: (event: SessionEvent) => void): () => void;
104
+ }
105
+
106
+ declare type BillingClientOptions = SessionOptions;
107
+
108
+ /**
109
+ * A prefetch or fixture. An omitted key reports as pending; a keyed resource
110
+ * seeds under `params`, or its defaults when absent, so a prefetch for a
111
+ * non-default query is claimed rather than refetched by the element.
112
+ */
113
+ declare type BillingData = {
114
+ [K in BillingResourceName]?: BillingResources[K];
115
+ } & {
116
+ params?: Partial<BillingResourceParams>;
117
+ /**
118
+ * A prefetch outlives the render that made it — a cached page, a session
119
+ * resolving to somebody else — so a store adopts it only for the session
120
+ * it names. `fetchBillingData` fills it in; a fixture need not.
121
+ */
122
+ sessionKey?: string;
123
+ };
124
+
125
+ declare interface BillingPrefetchOptions {
126
+ /**
127
+ * The resources the page renders, and no default: each one is a request
128
+ * on the server — the upcoming invoice is a live provider preview — and
129
+ * the list grows with every element, so a page names what it needs rather
130
+ * than paying for everything.
131
+ */
132
+ names: BillingResourceName[];
133
+ /** The invoice query to prefetch for; the element must ask the same one. */
134
+ invoices?: InvoiceQuery;
135
+ }
136
+
137
+ declare type BillingResourceName = keyof BillingResources;
138
+
139
+ /** `Record<string, never>` marks a singleton; anything else is keyed. */
140
+ declare interface BillingResourceParams {
141
+ invoices: InvoiceQuery;
142
+ upcomingInvoice: Record<string, never>;
143
+ }
144
+
145
+ /**
146
+ * Nothing in the store, the hooks, or the resource keys may be addressed by
147
+ * company or user id: users and companies are many-to-many, and a token names
148
+ * the pair. What is loaded belongs to the session it was read under — the
149
+ * pair, as `sessionKey` writes it — and a store that keeps more than one
150
+ * session's data keys it by that and serves only the active one.
151
+ */
152
+ declare interface BillingResources {
153
+ /** `GET /company/invoices?limit&offset&include_pending`. */
154
+ invoices: InvoicePage;
155
+ /**
156
+ * `GET /company/upcoming-invoice`. `null` is a loaded value — the company
157
+ * has no next bill, which the endpoint reports as a 204 — so only
158
+ * `undefined` means the resource has not loaded.
159
+ */
160
+ upcomingInvoice: UpcomingInvoice | null;
161
+ }
162
+
7
163
  declare type BooleanListenerFn = (value: boolean) => void;
8
164
 
9
165
  /**
@@ -172,6 +328,8 @@ export declare type CheckFlagReturn = {
172
328
  userId?: string;
173
329
  /** A boolean flag check result; for feature entitlements, this represents whether further consumption of the feature is permitted */
174
330
  value: boolean;
331
+ /** Customer-defined usage warning thresholds configured on this entitlement */
332
+ warningTiers?: WarningTier[];
175
333
  };
176
334
 
177
335
  declare const CheckFlagReturnFromJSON: (json: any) => CheckFlagReturn;
@@ -282,6 +440,167 @@ export declare interface CompanyCreditBalance {
282
440
  settled: number;
283
441
  }
284
442
 
443
+ /**
444
+ * Schematic API
445
+ * Schematic API
446
+ *
447
+ * The version of the OpenAPI document: 0.1
448
+ *
449
+ *
450
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
451
+ * https://openapi-generator.tech
452
+ * Do not edit the class manually.
453
+ */
454
+ /**
455
+ *
456
+ * @export
457
+ * @interface CompanyDiscountResponseData
458
+ */
459
+ declare interface CompanyDiscountResponseData {
460
+ /**
461
+ *
462
+ * @type {number}
463
+ * @memberof CompanyDiscountResponseData
464
+ */
465
+ amountOff?: number | null;
466
+ /**
467
+ *
468
+ * @type {string}
469
+ * @memberof CompanyDiscountResponseData
470
+ */
471
+ couponName: string;
472
+ /**
473
+ *
474
+ * @type {string}
475
+ * @memberof CompanyDiscountResponseData
476
+ */
477
+ currency?: string | null;
478
+ /**
479
+ *
480
+ * @type {string}
481
+ * @memberof CompanyDiscountResponseData
482
+ */
483
+ customerFacingCode?: string | null;
484
+ /**
485
+ * Provider vocabulary: once, repeating, or forever.
486
+ * @type {string}
487
+ * @memberof CompanyDiscountResponseData
488
+ */
489
+ duration: string;
490
+ /**
491
+ *
492
+ * @type {number}
493
+ * @memberof CompanyDiscountResponseData
494
+ */
495
+ durationInMonths?: number | null;
496
+ /**
497
+ *
498
+ * @type {number}
499
+ * @memberof CompanyDiscountResponseData
500
+ */
501
+ percentOff?: number | null;
502
+ }
503
+
504
+ /**
505
+ *
506
+ * @export
507
+ * @interface CompanyInvoiceResponseData
508
+ */
509
+ declare interface CompanyInvoiceResponseData {
510
+ /**
511
+ *
512
+ * @type {number}
513
+ * @memberof CompanyInvoiceResponseData
514
+ */
515
+ amountDue: number;
516
+ /**
517
+ *
518
+ * @type {Date}
519
+ * @memberof CompanyInvoiceResponseData
520
+ */
521
+ createdAt: Date;
522
+ /**
523
+ *
524
+ * @type {string}
525
+ * @memberof CompanyInvoiceResponseData
526
+ */
527
+ currency: string;
528
+ /**
529
+ *
530
+ * @type {Date}
531
+ * @memberof CompanyInvoiceResponseData
532
+ */
533
+ dueDate?: Date | null;
534
+ /**
535
+ *
536
+ * @type {string}
537
+ * @memberof CompanyInvoiceResponseData
538
+ */
539
+ id: string;
540
+ /**
541
+ *
542
+ * @type {InvoiceStatus}
543
+ * @memberof CompanyInvoiceResponseData
544
+ */
545
+ status?: InvoiceStatus | null;
546
+ /**
547
+ *
548
+ * @type {string}
549
+ * @memberof CompanyInvoiceResponseData
550
+ */
551
+ url?: string | null;
552
+ }
553
+
554
+ /**
555
+ *
556
+ * @export
557
+ * @interface CompanyUpcomingInvoiceResponseData
558
+ */
559
+ declare interface CompanyUpcomingInvoiceResponseData {
560
+ /**
561
+ *
562
+ * @type {number}
563
+ * @memberof CompanyUpcomingInvoiceResponseData
564
+ */
565
+ amountDue: number;
566
+ /**
567
+ *
568
+ * @type {string}
569
+ * @memberof CompanyUpcomingInvoiceResponseData
570
+ */
571
+ currency: string;
572
+ /**
573
+ * How much of the company's existing balance this invoice consumes.
574
+ * @type {number}
575
+ * @memberof CompanyUpcomingInvoiceResponseData
576
+ */
577
+ customerBalanceApplied: number;
578
+ /**
579
+ * Balance left over after this invoice.
580
+ * @type {number}
581
+ * @memberof CompanyUpcomingInvoiceResponseData
582
+ */
583
+ customerBalanceRemaining: number;
584
+ /**
585
+ * Only active discounts that reduce the bill.
586
+ * @type {Array<CompanyDiscountResponseData>}
587
+ * @memberof CompanyUpcomingInvoiceResponseData
588
+ */
589
+ discounts: Array<CompanyDiscountResponseData>;
590
+ /**
591
+ *
592
+ * @type {Date}
593
+ * @memberof CompanyUpcomingInvoiceResponseData
594
+ */
595
+ dueDate?: Date | null;
596
+ /**
597
+ * Amount before discounts and tax.
598
+ * @type {number}
599
+ * @memberof CompanyUpcomingInvoiceResponseData
600
+ */
601
+ subtotal: number;
602
+ }
603
+
285
604
  /** A company's lease-aware balance for a single credit type */
286
605
  export declare type CreditBalance = {
287
606
  /** Spendable balance including any open lease hold (remaining + reserved); the number to display to end users */
@@ -335,6 +654,10 @@ declare interface DatastreamCompanyPlan {
335
654
 
336
655
  declare function DatastreamCompanyPlanFromJSON(json: any): DatastreamCompanyPlan;
337
656
 
657
+ declare const DEFAULT_INVOICE_QUERY: InvoiceQuery;
658
+
659
+ declare type Discount = CompanyDiscountResponseData;
660
+
338
661
  declare type EmptyListenerFn = () => void;
339
662
 
340
663
  /**
@@ -407,6 +730,12 @@ declare interface EventBodyFlagCheck {
407
730
  * @memberof EventBodyFlagCheck
408
731
  */
409
732
  flagKey: string;
733
+ /**
734
+ * Whether the check was a preflight, asking whether an action would be allowed rather than reporting one that happened. Absent on ordinary checks
735
+ * @type {boolean}
736
+ * @memberof EventBodyFlagCheck
737
+ */
738
+ preflight?: boolean;
410
739
  /**
411
740
  * The reason why the value was returned
412
741
  * @type {string}
@@ -584,12 +913,69 @@ declare interface FeatureEntitlement {
584
913
  * @memberof FeatureEntitlement
585
914
  */
586
915
  valueType: EntitlementValueType;
916
+ /**
917
+ * Customer-defined usage warning thresholds configured on this entitlement
918
+ * @type {Array<WarningTier>}
919
+ * @memberof FeatureEntitlement
920
+ */
921
+ warningTiers?: Array<WarningTier>;
587
922
  }
588
923
 
924
+ /**
925
+ * Server prefetch for a provider's `initialData`. A resource that fails is
926
+ * left out rather than thrown, so one of them cannot block a page.
927
+ */
928
+ declare function fetchBillingData(client: BillingClient, options: BillingPrefetchOptions): Promise<BillingData>;
929
+
589
930
  declare type FlagCheckListenerFn = CheckFlagReturnListenerFn | EmptyListenerFn;
590
931
 
591
932
  declare type FlagValueListenerFn = BooleanListenerFn | EmptyListenerFn;
592
933
 
934
+ declare type Invoice = CompanyInvoiceResponseData;
935
+
936
+ /** A `limit` above this is a 400 (PaginationFilter in schematic-api). */
937
+ declare const INVOICE_MAX_PAGE_SIZE = 250;
938
+
939
+ declare const INVOICE_PAGE_SIZE = 12;
940
+
941
+ declare interface InvoicePage {
942
+ invoices: Invoice[];
943
+ /** Matching the query on the server, not the number loaded here. */
944
+ count: number;
945
+ hasMore: boolean;
946
+ }
947
+
948
+ /** Each distinct query is its own row set with its own paging. */
949
+ declare interface InvoiceQuery {
950
+ /** Include unpaid invoices that are not yet due. Default false. */
951
+ includePending?: boolean;
952
+ }
953
+
954
+ declare interface InvoicesRequest extends InvoiceQuery {
955
+ limit: number;
956
+ offset: number;
957
+ }
958
+
959
+ /**
960
+ * The rows asked for, and how many the query matches in total. `hasMore` is
961
+ * the page's, and only the caller knows its offset.
962
+ */
963
+ declare type InvoicesResult = Omit<InvoicePage, "hasMore">;
964
+
965
+ /**
966
+ *
967
+ * @export
968
+ */
969
+ declare const InvoiceStatus: {
970
+ readonly Draft: "draft";
971
+ readonly Open: "open";
972
+ readonly Paid: "paid";
973
+ readonly Uncollectible: "uncollectible";
974
+ readonly Void: "void";
975
+ };
976
+
977
+ declare type InvoiceStatus = (typeof InvoiceStatus)[keyof typeof InvoiceStatus];
978
+
593
979
  /** A record of unique key-value pairs used for identifying a company or user */
594
980
  export declare type Keys = Record<string, string>;
595
981
 
@@ -617,10 +1003,39 @@ declare const MetricPeriodMonthReset: {
617
1003
 
618
1004
  declare type MetricPeriodMonthReset = (typeof MetricPeriodMonthReset)[keyof typeof MetricPeriodMonthReset];
619
1005
 
1006
+ /**
1007
+ * The store keys a resource by the query's shape, so without this
1008
+ * `{ includePending: false }` is a different row set from `{}` — it would
1009
+ * miss the seed and refetch rows identical to those already on screen.
1010
+ */
1011
+ declare function normalizeInvoiceQuery(query: InvoiceQuery): InvoiceQuery;
1012
+
620
1013
  declare type PendingListenerFn = BooleanListenerFn | EmptyListenerFn;
621
1014
 
622
1015
  declare type PlanListenerFn = CheckPlanReturnListenerFn | EmptyListenerFn;
623
1016
 
1017
+ declare interface RequestOptions {
1018
+ method?: string;
1019
+ body?: unknown;
1020
+ /**
1021
+ * Success statuses that carry no body — a 204 for a resource that is
1022
+ * legitimately absent. The request resolves `undefined` for them, which
1023
+ * is distinct from a body that parsed to `null`. A 401 is never one — the
1024
+ * refresh and retry run first, and only what comes back from that is
1025
+ * judged.
1026
+ */
1027
+ noContentOn?: number[];
1028
+ }
1029
+
1030
+ declare interface ResourceState<T> {
1031
+ /** `undefined` until the first successful load; retained across later errors. */
1032
+ data: T | undefined;
1033
+ /** The latest failure; cleared by the next success. */
1034
+ error: Error | undefined;
1035
+ /** A request is in flight and no data has arrived yet, or a refetch is running. */
1036
+ isPending: boolean;
1037
+ }
1038
+
624
1039
  export declare enum RuleType {
625
1040
  /** A global rule that, if present, will override all other rules for a flag */
626
1041
  GLOBAL_OVERRIDE = "global_override",
@@ -655,9 +1070,9 @@ declare const RuleType_2: {
655
1070
  declare type RuleType_2 = (typeof RuleType_2)[keyof typeof RuleType_2];
656
1071
 
657
1072
  export declare class Schematic {
658
- private additionalHeaders;
1073
+ private _additionalHeaders;
659
1074
  private apiKey;
660
- private apiUrl;
1075
+ private _apiUrl;
661
1076
  private conn;
662
1077
  private context;
663
1078
  private debugEnabled;
@@ -702,6 +1117,8 @@ export declare class Schematic {
702
1117
  private flagCheckDefaults;
703
1118
  private fallbackCheckCache;
704
1119
  constructor(apiKey: string, options?: SchematicOptions);
1120
+ get apiUrl(): string;
1121
+ get additionalHeaders(): Record<string, string>;
705
1122
  /**
706
1123
  * Resolve fallback value according to priority order:
707
1124
  * 1. Callsite fallback value (if provided)
@@ -914,6 +1331,28 @@ export declare class Schematic {
914
1331
  private notifyCreditBalanceListeners;
915
1332
  }
916
1333
 
1334
+ declare class SchematicApiError extends Error {
1335
+ readonly status: number;
1336
+ readonly path: string;
1337
+ readonly body: unknown;
1338
+ constructor(status: number, path: string, body: unknown);
1339
+ }
1340
+
1341
+ declare class SchematicBillingClient implements BillingClient {
1342
+ /**
1343
+ * Public so a second client over the same surface can be constructed on
1344
+ * this one rather than minting tokens of its own.
1345
+ */
1346
+ readonly session: SchematicSession;
1347
+ constructor(options?: BillingClientOptions | SchematicSession);
1348
+ get sessionKey(): string | undefined;
1349
+ get sessionStatus(): SessionStatus;
1350
+ setSession(session: SessionInput): void;
1351
+ onSessionChange(listener: (event: SessionEvent) => void): () => void;
1352
+ fetchInvoices(params: InvoicesRequest): Promise<InvoicesResult>;
1353
+ fetchUpcomingInvoice(): Promise<UpcomingInvoice | null>;
1354
+ }
1355
+
917
1356
  export declare interface SchematicComposableOpts {
918
1357
  client?: SchematicJS.Schematic;
919
1358
  }
@@ -934,6 +1373,20 @@ declare namespace SchematicJS {
934
1373
  CheckFlagsResponseFromJSON,
935
1374
  DatastreamCompanyPlanFromJSON,
936
1375
  EventBodyFlagCheckToJSON,
1376
+ fetchBillingData,
1377
+ normalizeInvoiceQuery,
1378
+ sessionKey,
1379
+ AccessToken,
1380
+ AccessTokenProvider,
1381
+ AccessTokenResult,
1382
+ billingApi,
1383
+ BillingClient,
1384
+ BillingClientOptions,
1385
+ BillingData,
1386
+ BillingPrefetchOptions,
1387
+ BillingResourceName,
1388
+ BillingResourceParams,
1389
+ BillingResources,
937
1390
  BooleanListenerFn,
938
1391
  CheckFlagResponseData,
939
1392
  CheckFlagReturn,
@@ -944,11 +1397,16 @@ declare namespace SchematicJS {
944
1397
  CheckPlanReturnFromJSON,
945
1398
  CheckPlanReturnListenerFn,
946
1399
  CompanyCreditBalance,
1400
+ CompanyDiscountResponseData,
1401
+ CompanyInvoiceResponseData,
1402
+ CompanyUpcomingInvoiceResponseData,
947
1403
  CreditBalance,
948
1404
  CreditBalanceListenerFn,
949
1405
  CreditBalances,
950
1406
  CreditBalancesFromJSON,
951
1407
  CreditBalancesListenerFn,
1408
+ DEFAULT_INVOICE_QUERY,
1409
+ Discount,
952
1410
  EmptyListenerFn,
953
1411
  Event_2 as Event,
954
1412
  EventBody,
@@ -958,17 +1416,39 @@ declare namespace SchematicJS {
958
1416
  EventType,
959
1417
  FlagCheckListenerFn,
960
1418
  FlagValueListenerFn,
1419
+ Invoice,
1420
+ INVOICE_MAX_PAGE_SIZE,
1421
+ INVOICE_PAGE_SIZE,
1422
+ InvoicePage,
1423
+ InvoiceQuery,
1424
+ InvoicesRequest,
1425
+ InvoicesResult,
1426
+ InvoiceStatus,
961
1427
  Keys,
962
1428
  PendingListenerFn,
963
1429
  PlanListenerFn,
1430
+ RequestOptions,
1431
+ ResourceState,
964
1432
  RuleType,
965
1433
  Schematic,
1434
+ SchematicApiError,
1435
+ SchematicBillingClient,
966
1436
  SchematicContext,
967
1437
  SchematicOptions,
1438
+ SchematicSession,
1439
+ Session,
1440
+ SessionEvent,
1441
+ SessionInput,
1442
+ SessionOptions,
1443
+ SessionStatus,
1444
+ SINGLETON,
968
1445
  StoragePersister,
1446
+ TOKEN_CACHE_SIZE,
969
1447
  Traits,
970
1448
  TrialStatus,
971
- UsagePeriod
1449
+ UpcomingInvoice,
1450
+ UsagePeriod,
1451
+ WarningTier
972
1452
  }
973
1453
  }
974
1454
 
@@ -1051,6 +1531,114 @@ declare type SchematicPluginOptionsWithPublishableKey = BaseSchematicPluginOptio
1051
1531
  publishableKey: string;
1052
1532
  };
1053
1533
 
1534
+ /**
1535
+ * Session identity is the (company, user) pair alone: a freshly minted token,
1536
+ * a rebuilt provider closure, and a refresh this session asked for itself are
1537
+ * all the same session. Nothing in a token says who it was minted for, so
1538
+ * that question is the host's to answer.
1539
+ *
1540
+ * Credentials survive a change of session, keyed by pair — switching back to
1541
+ * a company reads with the token already in hand. They do not survive the
1542
+ * session ending: after a sign-out the next person at this page is somebody
1543
+ * else, and nothing minted for the last one is theirs to send.
1544
+ */
1545
+ declare class SchematicSession {
1546
+ private readonly _apiUrl;
1547
+ private readonly _headers;
1548
+ private readonly _fetch;
1549
+ private _session;
1550
+ private readonly _tokens;
1551
+ private readonly _resolving;
1552
+ /**
1553
+ * Bumped when the session's identity changes, and only then — the object
1554
+ * itself is replaced on every render. Anything asking "is this still the
1555
+ * session I started under?" counts generations rather than comparing.
1556
+ */
1557
+ private _generation;
1558
+ private readonly _listeners;
1559
+ constructor(options?: SessionOptions);
1560
+ get key(): string | undefined;
1561
+ get status(): SessionStatus;
1562
+ /** Only a statement that changes which pair is read counts as a change. */
1563
+ set(session: SessionInput): void;
1564
+ onChange(listener: (event: SessionEvent) => void): () => void;
1565
+ private _emit;
1566
+ private _cached;
1567
+ private _cache;
1568
+ /**
1569
+ * The credential for a session, minted if this one is not held. `force`
1570
+ * retires what is held first: the caller is a request the API has just
1571
+ * rejected.
1572
+ */
1573
+ resolveToken(session: Session, force: boolean): Promise<string>;
1574
+ /**
1575
+ * Sends a request under the active session's credential, refreshing once
1576
+ * and retrying if the API rejects it. Rejects rather than answering when
1577
+ * the session changes while the request is in flight: the rows would
1578
+ * otherwise come back as the answer to a question asked for another pair.
1579
+ */
1580
+ request(path: string, options?: RequestOptions): Promise<unknown>;
1581
+ }
1582
+
1583
+ /**
1584
+ * Who is being read. Users and companies are many-to-many: the same person
1585
+ * reads one company's billing and then another's, and the same company is
1586
+ * read by several people. A token is minted for the pair, so the pair — not
1587
+ * the company alone — is the session's identity.
1588
+ */
1589
+ declare interface Session {
1590
+ /** The host's name for the company, its id in their own system say. */
1591
+ company: string;
1592
+ /**
1593
+ * The user, where the host mints per (company, user). Left out by a host
1594
+ * whose tokens are company-wide, and then every reader of that company
1595
+ * shares one session.
1596
+ */
1597
+ user?: string;
1598
+ token: AccessToken;
1599
+ }
1600
+
1601
+ /**
1602
+ * What happened to the session, for anything holding data that belongs to
1603
+ * one. `started`: whatever is loaded belongs to the new session — a prefetch
1604
+ * the host seeded before its auth resolved. `changed`: another pair is being
1605
+ * read, and what is loaded belongs to the pair being left. `ended`: nobody is
1606
+ * signed in, and what is loaded belongs to nobody.
1607
+ */
1608
+ declare type SessionEvent = {
1609
+ type: "started" | "changed" | "ended";
1610
+ };
1611
+
1612
+ /**
1613
+ * Three states that are not interchangeable:
1614
+ *
1615
+ * * `Session` — active: this pair, read with this credential.
1616
+ * * `null` — ended: nobody is signed in; what is loaded is dropped.
1617
+ * * `undefined` — pending: the host's auth has not resolved. It states
1618
+ * nothing, so the session in hand stands.
1619
+ */
1620
+ declare type SessionInput = Session | null | undefined;
1621
+
1622
+ /**
1623
+ * The pair as one string, for anything that has to compare sessions or key
1624
+ * something by one — a prefetch stating which session it was fetched for, a
1625
+ * store keeping a page per session. Opaque: read it only by equality.
1626
+ */
1627
+ declare function sessionKey(session: Session): string;
1628
+
1629
+ declare interface SessionOptions {
1630
+ session?: SessionInput;
1631
+ apiUrl?: string;
1632
+ additionalHeaders?: Record<string, string>;
1633
+ /** Override for tests and non-browser runtimes. */
1634
+ fetch?: typeof fetch;
1635
+ }
1636
+
1637
+ declare type SessionStatus = "pending" | "active" | "ended";
1638
+
1639
+ /** The params of every singleton resource. */
1640
+ declare const SINGLETON: Record<string, never>;
1641
+
1054
1642
  /** Optional type for implementing custom client-side storage */
1055
1643
  export declare type StoragePersister = {
1056
1644
  setItem(key: string, value: any): void;
@@ -1058,6 +1646,15 @@ export declare type StoragePersister = {
1058
1646
  removeItem(key: string): void;
1059
1647
  };
1060
1648
 
1649
+ /**
1650
+ * Sessions whose credentials are kept. A reader switching between the
1651
+ * organizations they belong to walks a handful of them and comes back, and
1652
+ * re-minting on every step is a round trip to the host's token endpoint for
1653
+ * a token this client already holds and has not seen expire. The same
1654
+ * handful the flag cache bounds its contexts at.
1655
+ */
1656
+ declare const TOKEN_CACHE_SIZE = 10;
1657
+
1061
1658
  /**
1062
1659
  * A flexible key/value type that can store any type of value on a company or user.
1063
1660
  */
@@ -1075,6 +1672,8 @@ declare const TrialStatus: {
1075
1672
 
1076
1673
  declare type TrialStatus = (typeof TrialStatus)[keyof typeof TrialStatus];
1077
1674
 
1675
+ declare type UpcomingInvoice = CompanyUpcomingInvoiceResponseData;
1676
+
1078
1677
  export declare enum UsagePeriod {
1079
1678
  ALL_TIME = "all_time",
1080
1679
  CURRENT_DAY = "current_day",
@@ -1123,9 +1722,12 @@ export declare const useSchematicContext: (opts?: SchematicComposableOpts) => {
1123
1722
  * `remaining` would otherwise read stale / falsely "exhausted".
1124
1723
  *
1125
1724
  * The credit ID is available on a feature's entitlement: `useSchematicEntitlement(key)`
1126
- * returns `creditId` for credit-based features.
1725
+ * returns `creditId` for credit-based features. Pass that computed ref straight
1726
+ * in; the composable unwraps a ref, a getter, or a plain string, and re-keys to
1727
+ * the new credit when the source changes. While the ID is undefined it reports
1728
+ * the client's loading state and a balance of 0.
1127
1729
  *
1128
- * @param creditId - The credit ID to read the balance for
1730
+ * @param creditId - The credit ID to read the balance for, as a ref, a getter, or a plain string
1129
1731
  * @param opts - Optional configuration including a client override
1130
1732
  * @returns Object with `balance` and `isLoading` computed refs
1131
1733
  *
@@ -1133,12 +1735,16 @@ export declare const useSchematicContext: (opts?: SchematicComposableOpts) => {
1133
1735
  * ```typescript
1134
1736
  * const { balance, isLoading } = useSchematicCreditBalance('credit-id')
1135
1737
  *
1738
+ * // Or keyed off an entitlement, without unwrapping it yourself
1739
+ * const { creditId } = useSchematicEntitlement('my-flag-key')
1740
+ * const { balance } = useSchematicCreditBalance(creditId)
1741
+ *
1136
1742
  * // In template
1137
1743
  * <div v-if="isLoading">Loading…</div>
1138
1744
  * <div v-else>{{ balance }} credits remaining</div>
1139
1745
  * ```
1140
1746
  */
1141
- export declare const useSchematicCreditBalance: (creditId: string, opts?: SchematicComposableOpts) => {
1747
+ export declare const useSchematicCreditBalance: (creditId: MaybeRefOrGetter<string | undefined>, opts?: SchematicComposableOpts) => {
1142
1748
  /** The spendable balance; 0 while loading or when the company holds no balance in this credit */
1143
1749
  balance: ComputedRef<number>;
1144
1750
  /** True while the balance is still loading and no value has arrived yet */
@@ -1190,6 +1796,10 @@ export declare const useSchematicEntitlement: (key: string, opts?: UseSchematicF
1190
1796
  softLimit?: number | undefined;
1191
1797
  userId?: string | undefined;
1192
1798
  value: boolean;
1799
+ warningTiers?: {
1800
+ key: string;
1801
+ value: number;
1802
+ }[] | undefined;
1193
1803
  }>;
1194
1804
  value: ComputedRef<boolean>;
1195
1805
  flag: ComputedRef<string>;
@@ -1199,10 +1809,19 @@ export declare const useSchematicEntitlement: (key: string, opts?: UseSchematicF
1199
1809
  featureUsageExceeded: ComputedRef<boolean | undefined>;
1200
1810
  featureUsageEvent: ComputedRef<string | undefined>;
1201
1811
  featureUsagePeriod: ComputedRef<SchematicJS.UsagePeriod | undefined>;
1812
+ softLimit: ComputedRef<number | undefined>;
1813
+ warningTiers: ComputedRef< {
1814
+ key: string;
1815
+ value: number;
1816
+ }[] | undefined>;
1202
1817
  flagId: ComputedRef<string | undefined>;
1203
1818
  ruleId: ComputedRef<string | undefined>;
1204
1819
  companyId: ComputedRef<string | undefined>;
1205
1820
  userId: ComputedRef<string | undefined>;
1821
+ creditId: ComputedRef<string | undefined>;
1822
+ creditSettled: ComputedRef<number | undefined>;
1823
+ creditRemaining: ComputedRef<number | undefined>;
1824
+ creditReserved: ComputedRef<number | undefined>;
1206
1825
  };
1207
1826
 
1208
1827
  /**
@@ -1292,4 +1911,35 @@ export declare type UseSchematicPlanOpts = SchematicComposableOpts & {
1292
1911
  fallback?: SchematicJS.CheckPlanReturn;
1293
1912
  };
1294
1913
 
1914
+ /**
1915
+ * Schematic API
1916
+ * Schematic API
1917
+ *
1918
+ * The version of the OpenAPI document: 0.1
1919
+ *
1920
+ *
1921
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
1922
+ * https://openapi-generator.tech
1923
+ * Do not edit the class manually.
1924
+ */
1925
+ /**
1926
+ *
1927
+ * @export
1928
+ * @interface WarningTier
1929
+ */
1930
+ export declare interface WarningTier {
1931
+ /**
1932
+ * A customer-defined identifier for the warning tier
1933
+ * @type {string}
1934
+ * @memberof WarningTier
1935
+ */
1936
+ key: string;
1937
+ /**
1938
+ * The warning threshold, in the entitlement's usage units
1939
+ * @type {number}
1940
+ * @memberof WarningTier
1941
+ */
1942
+ value: number;
1943
+ }
1944
+
1295
1945
  export { }