@schematichq/schematic-react 1.5.0 → 1.7.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,283 @@
1
1
  import { default as React_2 } from 'react';
2
2
 
3
+ export declare type AccessToken = string | AccessTokenProvider;
4
+
5
+ /**
6
+ * The machinery every temporary-access-token surface shares: which session is
7
+ * being read, the credential for it, and the request that carries it. It
8
+ * knows nothing about invoices, subscriptions, or checkout — a domain client
9
+ * (see `SchematicBillingClient`) is constructed over it, and several may
10
+ * share one session rather than each minting tokens of its own.
11
+ */
12
+ /** Called once per session, and again when a request comes back 401. */
13
+ export declare type AccessTokenProvider = () => Promise<string | AccessTokenResult>;
14
+
15
+ /**
16
+ * A bare token, or one that says when it expires and who it was minted for.
17
+ * `company`/`user` are the host restating the pair it asked for; stated, they
18
+ * are checked against the session the resolution was started for.
19
+ */
20
+ declare interface AccessTokenResult {
21
+ token: string;
22
+ expiresAt?: Date | string | null;
23
+ company?: string;
24
+ user?: string;
25
+ }
26
+
3
27
  declare type BaseSchematicProviderProps = Omit<SchematicJS.SchematicOptions, "client" | "publishableKey" | "useWebSocket"> & {
4
28
  children: React_2.ReactNode;
29
+ /**
30
+ * The billing session: which (company, user) pair the `/company/*`
31
+ * endpoints are read for and the credential for it, `null` when nobody is
32
+ * signed in, and `undefined` while the host is finding out. Held alongside
33
+ * the publishable key, which keeps serving flags.
34
+ */
35
+ session?: SessionInput;
36
+ /** A billing client; schematic-js supplies one when omitted. */
37
+ billingClient?: BillingProviderClient;
38
+ /**
39
+ * Prefetched billing data, so the first render is complete (SSR). Rows
40
+ * stamped with their session paint on the first render only if `session`
41
+ * is stated on that render; under `undefined` they are held until it
42
+ * starts. State the pair on the first client render — `token` may be an
43
+ * async provider — or hydration will not match.
44
+ */
45
+ initialData?: BillingData;
46
+ } & SchematicI18nConfig;
47
+
48
+ declare namespace billingApi {
49
+ export {
50
+ instanceOfApiError,
51
+ ApiErrorFromJSON,
52
+ ApiErrorFromJSONTyped,
53
+ ApiErrorToJSON,
54
+ ApiErrorToJSONTyped,
55
+ ApiError,
56
+ instanceOfCompanyDiscountResponseData,
57
+ CompanyDiscountResponseDataFromJSON,
58
+ CompanyDiscountResponseDataFromJSONTyped,
59
+ CompanyDiscountResponseDataToJSON,
60
+ CompanyDiscountResponseDataToJSONTyped,
61
+ CompanyDiscountResponseData,
62
+ instanceOfCompanyInvoiceResponseData,
63
+ CompanyInvoiceResponseDataFromJSON,
64
+ CompanyInvoiceResponseDataFromJSONTyped,
65
+ CompanyInvoiceResponseDataToJSON,
66
+ CompanyInvoiceResponseDataToJSONTyped,
67
+ CompanyInvoiceResponseData,
68
+ instanceOfCompanyInvoicesResponseData,
69
+ CompanyInvoicesResponseDataFromJSON,
70
+ CompanyInvoicesResponseDataFromJSONTyped,
71
+ CompanyInvoicesResponseDataToJSON,
72
+ CompanyInvoicesResponseDataToJSONTyped,
73
+ CompanyInvoicesResponseData,
74
+ instanceOfCompanyUpcomingInvoiceResponseData,
75
+ CompanyUpcomingInvoiceResponseDataFromJSON,
76
+ CompanyUpcomingInvoiceResponseDataFromJSONTyped,
77
+ CompanyUpcomingInvoiceResponseDataToJSON,
78
+ CompanyUpcomingInvoiceResponseDataToJSONTyped,
79
+ CompanyUpcomingInvoiceResponseData,
80
+ instanceOfGetCompanyInvoicesParams,
81
+ GetCompanyInvoicesParamsFromJSON,
82
+ GetCompanyInvoicesParamsFromJSONTyped,
83
+ GetCompanyInvoicesParamsToJSON,
84
+ GetCompanyInvoicesParamsToJSONTyped,
85
+ GetCompanyInvoicesParams,
86
+ instanceOfGetCompanyInvoicesResponse,
87
+ GetCompanyInvoicesResponseFromJSON,
88
+ GetCompanyInvoicesResponseFromJSONTyped,
89
+ GetCompanyInvoicesResponseToJSON,
90
+ GetCompanyInvoicesResponseToJSONTyped,
91
+ GetCompanyInvoicesResponse,
92
+ instanceOfGetCompanyUpcomingInvoiceResponse,
93
+ GetCompanyUpcomingInvoiceResponseFromJSON,
94
+ GetCompanyUpcomingInvoiceResponseFromJSONTyped,
95
+ GetCompanyUpcomingInvoiceResponseToJSON,
96
+ GetCompanyUpcomingInvoiceResponseToJSONTyped,
97
+ GetCompanyUpcomingInvoiceResponse,
98
+ instanceOfInvoiceStatus,
99
+ InvoiceStatusFromJSON,
100
+ InvoiceStatusFromJSONTyped,
101
+ InvoiceStatusToJSON,
102
+ InvoiceStatusToJSONTyped,
103
+ InvoiceStatus
104
+ }
105
+ }
106
+
107
+ /**
108
+ * What a reader of billing data can ask for. Subscription and usage — the
109
+ * rest of what `hydrate` serves — and the checkout calls that change them
110
+ * join this interface as their endpoints ship.
111
+ */
112
+ declare interface BillingClient {
113
+ fetchInvoices(params: InvoicesRequest): Promise<InvoicesResult>;
114
+ /** `null` when the company has no next bill. */
115
+ fetchUpcomingInvoice(): Promise<UpcomingInvoice | null>;
116
+ readonly sessionStatus: SessionStatus;
117
+ readonly sessionKey: string | undefined;
118
+ setSession(session: SessionInput): void;
119
+ onSessionChange(listener: (event: SessionEvent) => void): () => void;
120
+ }
121
+
122
+ declare type BillingClientOptions = SessionOptions;
123
+
124
+ /**
125
+ * A prefetch or fixture. An omitted key reports as pending; a keyed resource
126
+ * seeds under `params`, or its defaults when absent, so a prefetch for a
127
+ * non-default query is claimed rather than refetched by the element.
128
+ */
129
+ export declare type BillingData = {
130
+ [K in BillingResourceName]?: BillingResources[K];
131
+ } & {
132
+ params?: Partial<BillingResourceParams>;
133
+ /**
134
+ * A prefetch outlives the render that made it — a cached page, a session
135
+ * resolving to somebody else — so a store adopts it only for the session
136
+ * it names. `fetchBillingData` fills it in; a fixture need not.
137
+ */
138
+ sessionKey?: string;
139
+ };
140
+
141
+ export declare function BillingDataProvider({ children, data, locale, onLoadMoreInvoices, onMissingString, onRefetch, status, strings, translate, }: BillingDataProviderProps): React_2.JSX.Element;
142
+
143
+ declare interface BillingDataProviderDataProps {
144
+ /** A missing key reports as pending. */
145
+ data: BillingData;
146
+ /** Simulated loading / failure per resource; wins over `data`. */
147
+ status?: BillingDataStatus;
148
+ onRefetch?: (name: BillingResourceName_2) => void;
149
+ onLoadMoreInvoices?: (query: InvoiceQuery) => void;
150
+ children?: React_2.ReactNode;
151
+ }
152
+
153
+ /**
154
+ * Feeds the billing hooks from plain data with no fetching: fixtures,
155
+ * stories, tests, or a fully prefetched page. The i18n props configure a
156
+ * `SchematicI18nProvider` around the children and never touch the data seam.
157
+ */
158
+ export declare type BillingDataProviderProps = BillingDataProviderDataProps & SchematicI18nConfig;
159
+
160
+ /**
161
+ * The seam between the hooks and whatever supplies data: the provider's
162
+ * store, a server prefetch, or fixtures.
163
+ */
164
+ export declare interface BillingDataSource {
165
+ /**
166
+ * Sources that hold one value per resource (fixtures, prefetch) serve it
167
+ * for every parameter set.
168
+ */
169
+ subscribe<K extends BillingResourceName_2>(name: K, params: BillingResourceParams_2[K], listener: () => void): () => void;
170
+ handle<K extends BillingResourceName_2>(name: K, params: BillingResourceParams_2[K]): ResourceHandle<BillingResources_2[K]>;
171
+ /** Never rejects: a failure lands on the resource's `error`. */
172
+ loadMoreInvoices: (query: InvoiceQuery) => Promise<void>;
173
+ invalidateAll: () => void;
174
+ }
175
+
176
+ /** Per-resource status overrides, for fixtures that simulate loading and failure. */
177
+ export declare type BillingDataStatus = {
178
+ [K in BillingResourceName_2]?: {
179
+ isPending?: boolean;
180
+ error?: Error;
181
+ };
5
182
  };
6
183
 
184
+ declare interface BillingPrefetchOptions {
185
+ /**
186
+ * The resources the page renders, and no default: each one is a request
187
+ * on the server — the upcoming invoice is a live provider preview — and
188
+ * the list grows with every element, so a page names what it needs rather
189
+ * than paying for everything.
190
+ */
191
+ names: BillingResourceName[];
192
+ /** The invoice query to prefetch for; the element must ask the same one. */
193
+ invoices?: InvoiceQuery;
194
+ }
195
+
196
+ /**
197
+ * Provides the billing hooks from a `BillingStore` over a `BillingProviderClient`.
198
+ * Rendered by `SchematicProvider`; usable on its own with a client.
199
+ */
200
+ export declare function BillingProvider({ billingClient, children, initialData, locale, onMissingString, session, strings, translate, }: BillingProviderProps): React_2.JSX.Element;
201
+
202
+ /**
203
+ * What `BillingProvider` asks of its client: the session it reads under, and
204
+ * the fetch behind each resource above. schematic-js's `SchematicBillingClient`
205
+ * satisfies it, and so does a host's own client that implements only this
206
+ * much. Named apart from schematic-js's `BillingClient`, which is the whole
207
+ * interface; this is the part the hooks here call.
208
+ */
209
+ export declare type BillingProviderClient = Pick<BillingClient, "sessionStatus" | "sessionKey" | "setSession" | "onSessionChange" | "fetchInvoices">;
210
+
211
+ declare interface BillingProviderDataProps {
212
+ /**
213
+ * Required: this provider does not build one, and without it every hook
214
+ * reports the missing-source error and `session` has nowhere to go.
215
+ * `SchematicProvider` constructs one from its publishable key and renders
216
+ * this underneath, which is the usual path.
217
+ */
218
+ billingClient?: BillingProviderClient;
219
+ /**
220
+ * Read once, at mount. A prefetch stamped with its session paints on the
221
+ * first render only if `session` is stated on that render; under
222
+ * `undefined` it is held until the session starts. On a server-rendered
223
+ * page, state the pair on the first client render — `token` may be an
224
+ * async provider — or hydration will not match.
225
+ */
226
+ initialData?: BillingData;
227
+ /**
228
+ * Who is being read, and the credential for it: `{ company, user?, token }`
229
+ * while someone is signed in, `null` when nobody is, and `undefined` while
230
+ * the host is still finding out.
231
+ *
232
+ * The (company, user) pair is the identity, so a token that rotates — a
233
+ * provider called again, a closure rebuilt on a render — is the same
234
+ * session and keeps what is loaded, while another pair drops it.
235
+ * `undefined` states nothing, which is what an auth resolving
236
+ * asynchronously renders first.
237
+ */
238
+ session?: SessionInput;
239
+ children?: React_2.ReactNode;
240
+ }
241
+
242
+ /**
243
+ * The i18n props are forwarded to a `SchematicI18nProvider` and never reach
244
+ * the data seam.
245
+ */
246
+ export declare type BillingProviderProps = BillingProviderDataProps & SchematicI18nConfig;
247
+
248
+ declare type BillingResourceName = keyof BillingResources;
249
+
250
+ /** The resources this package serves; a key of schematic-js's contract. */
251
+ declare type BillingResourceName_2 = "invoices";
252
+
253
+ /** `Record<string, never>` marks a singleton; anything else is keyed. */
254
+ declare interface BillingResourceParams {
255
+ invoices: InvoiceQuery;
256
+ upcomingInvoice: Record<string, never>;
257
+ }
258
+
259
+ declare type BillingResourceParams_2 = Pick<BillingResourceParams, BillingResourceName_2>;
260
+
261
+ /**
262
+ * Nothing in the store, the hooks, or the resource keys may be addressed by
263
+ * company or user id: users and companies are many-to-many, and a token names
264
+ * the pair. What is loaded belongs to the session it was read under — the
265
+ * pair, as `sessionKey` writes it — and a store that keeps more than one
266
+ * session's data keys it by that and serves only the active one.
267
+ */
268
+ declare interface BillingResources {
269
+ /** `GET /company/invoices?limit&offset&include_pending`. */
270
+ invoices: InvoicePage;
271
+ /**
272
+ * `GET /company/upcoming-invoice`. `null` is a loaded value — the company
273
+ * has no next bill, which the endpoint reports as a 204 — so only
274
+ * `undefined` means the resource has not loaded.
275
+ */
276
+ upcomingInvoice: UpcomingInvoice | null;
277
+ }
278
+
279
+ declare type BillingResources_2 = Pick<BillingResources, BillingResourceName_2>;
280
+
7
281
  declare type BooleanListenerFn = (value: boolean) => void;
8
282
 
9
283
  /**
@@ -172,6 +446,8 @@ export declare type CheckFlagReturn = {
172
446
  userId?: string;
173
447
  /** A boolean flag check result; for feature entitlements, this represents whether further consumption of the feature is permitted */
174
448
  value: boolean;
449
+ /** Customer-defined usage warning thresholds configured on this entitlement */
450
+ warningTiers?: WarningTier[];
175
451
  };
176
452
 
177
453
  declare const CheckFlagReturnFromJSON: (json: any) => CheckFlagReturn;
@@ -282,6 +558,167 @@ export declare interface CompanyCreditBalance {
282
558
  settled: number;
283
559
  }
284
560
 
561
+ /**
562
+ * Schematic API
563
+ * Schematic API
564
+ *
565
+ * The version of the OpenAPI document: 0.1
566
+ *
567
+ *
568
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
569
+ * https://openapi-generator.tech
570
+ * Do not edit the class manually.
571
+ */
572
+ /**
573
+ *
574
+ * @export
575
+ * @interface CompanyDiscountResponseData
576
+ */
577
+ declare interface CompanyDiscountResponseData {
578
+ /**
579
+ *
580
+ * @type {number}
581
+ * @memberof CompanyDiscountResponseData
582
+ */
583
+ amountOff?: number | null;
584
+ /**
585
+ *
586
+ * @type {string}
587
+ * @memberof CompanyDiscountResponseData
588
+ */
589
+ couponName: string;
590
+ /**
591
+ *
592
+ * @type {string}
593
+ * @memberof CompanyDiscountResponseData
594
+ */
595
+ currency?: string | null;
596
+ /**
597
+ *
598
+ * @type {string}
599
+ * @memberof CompanyDiscountResponseData
600
+ */
601
+ customerFacingCode?: string | null;
602
+ /**
603
+ * Provider vocabulary: once, repeating, or forever.
604
+ * @type {string}
605
+ * @memberof CompanyDiscountResponseData
606
+ */
607
+ duration: string;
608
+ /**
609
+ *
610
+ * @type {number}
611
+ * @memberof CompanyDiscountResponseData
612
+ */
613
+ durationInMonths?: number | null;
614
+ /**
615
+ *
616
+ * @type {number}
617
+ * @memberof CompanyDiscountResponseData
618
+ */
619
+ percentOff?: number | null;
620
+ }
621
+
622
+ /**
623
+ *
624
+ * @export
625
+ * @interface CompanyInvoiceResponseData
626
+ */
627
+ declare interface CompanyInvoiceResponseData {
628
+ /**
629
+ *
630
+ * @type {number}
631
+ * @memberof CompanyInvoiceResponseData
632
+ */
633
+ amountDue: number;
634
+ /**
635
+ *
636
+ * @type {Date}
637
+ * @memberof CompanyInvoiceResponseData
638
+ */
639
+ createdAt: Date;
640
+ /**
641
+ *
642
+ * @type {string}
643
+ * @memberof CompanyInvoiceResponseData
644
+ */
645
+ currency: string;
646
+ /**
647
+ *
648
+ * @type {Date}
649
+ * @memberof CompanyInvoiceResponseData
650
+ */
651
+ dueDate?: Date | null;
652
+ /**
653
+ *
654
+ * @type {string}
655
+ * @memberof CompanyInvoiceResponseData
656
+ */
657
+ id: string;
658
+ /**
659
+ *
660
+ * @type {InvoiceStatus}
661
+ * @memberof CompanyInvoiceResponseData
662
+ */
663
+ status?: InvoiceStatus | null;
664
+ /**
665
+ *
666
+ * @type {string}
667
+ * @memberof CompanyInvoiceResponseData
668
+ */
669
+ url?: string | null;
670
+ }
671
+
672
+ /**
673
+ *
674
+ * @export
675
+ * @interface CompanyUpcomingInvoiceResponseData
676
+ */
677
+ declare interface CompanyUpcomingInvoiceResponseData {
678
+ /**
679
+ *
680
+ * @type {number}
681
+ * @memberof CompanyUpcomingInvoiceResponseData
682
+ */
683
+ amountDue: number;
684
+ /**
685
+ *
686
+ * @type {string}
687
+ * @memberof CompanyUpcomingInvoiceResponseData
688
+ */
689
+ currency: string;
690
+ /**
691
+ * How much of the company's existing balance this invoice consumes.
692
+ * @type {number}
693
+ * @memberof CompanyUpcomingInvoiceResponseData
694
+ */
695
+ customerBalanceApplied: number;
696
+ /**
697
+ * Balance left over after this invoice.
698
+ * @type {number}
699
+ * @memberof CompanyUpcomingInvoiceResponseData
700
+ */
701
+ customerBalanceRemaining: number;
702
+ /**
703
+ * Only active discounts that reduce the bill.
704
+ * @type {Array<CompanyDiscountResponseData>}
705
+ * @memberof CompanyUpcomingInvoiceResponseData
706
+ */
707
+ discounts: Array<CompanyDiscountResponseData>;
708
+ /**
709
+ *
710
+ * @type {Date}
711
+ * @memberof CompanyUpcomingInvoiceResponseData
712
+ */
713
+ dueDate?: Date | null;
714
+ /**
715
+ * Amount before discounts and tax.
716
+ * @type {number}
717
+ * @memberof CompanyUpcomingInvoiceResponseData
718
+ */
719
+ subtotal: number;
720
+ }
721
+
285
722
  /** A company's lease-aware balance for a single credit type */
286
723
  export declare type CreditBalance = {
287
724
  /** Spendable balance including any open lease hold (remaining + reserved); the number to display to end users */
@@ -335,6 +772,10 @@ declare interface DatastreamCompanyPlan {
335
772
 
336
773
  declare function DatastreamCompanyPlanFromJSON(json: any): DatastreamCompanyPlan;
337
774
 
775
+ export declare const DEFAULT_INVOICE_QUERY: InvoiceQuery;
776
+
777
+ declare type Discount = CompanyDiscountResponseData;
778
+
338
779
  declare type EmptyListenerFn = () => void;
339
780
 
340
781
  /**
@@ -407,6 +848,12 @@ declare interface EventBodyFlagCheck {
407
848
  * @memberof EventBodyFlagCheck
408
849
  */
409
850
  flagKey: string;
851
+ /**
852
+ * Whether the check was a preflight, asking whether an action would be allowed rather than reporting one that happened. Absent on ordinary checks
853
+ * @type {boolean}
854
+ * @memberof EventBodyFlagCheck
855
+ */
856
+ preflight?: boolean;
410
857
  /**
411
858
  * The reason why the value was returned
412
859
  * @type {string}
@@ -584,12 +1031,79 @@ declare interface FeatureEntitlement {
584
1031
  * @memberof FeatureEntitlement
585
1032
  */
586
1033
  valueType: EntitlementValueType;
1034
+ /**
1035
+ * Customer-defined usage warning thresholds configured on this entitlement
1036
+ * @type {Array<WarningTier>}
1037
+ * @memberof FeatureEntitlement
1038
+ */
1039
+ warningTiers?: Array<WarningTier>;
587
1040
  }
588
1041
 
1042
+ /**
1043
+ * Server prefetch for a provider's `initialData`. A resource that fails is
1044
+ * left out rather than thrown, so one of them cannot block a page.
1045
+ */
1046
+ declare function fetchBillingData(client: BillingClient, options: BillingPrefetchOptions): Promise<BillingData>;
1047
+
589
1048
  declare type FlagCheckListenerFn = CheckFlagReturnListenerFn | EmptyListenerFn;
590
1049
 
591
1050
  declare type FlagValueListenerFn = BooleanListenerFn | EmptyListenerFn;
592
1051
 
1052
+ export declare type Invoice = CompanyInvoiceResponseData;
1053
+
1054
+ /** A `limit` above this is a 400 (PaginationFilter in schematic-api). */
1055
+ declare const INVOICE_MAX_PAGE_SIZE = 250;
1056
+
1057
+ export declare const INVOICE_PAGE_SIZE = 12;
1058
+
1059
+ export declare interface InvoicePage {
1060
+ invoices: Invoice[];
1061
+ /** Matching the query on the server, not the number loaded here. */
1062
+ count: number;
1063
+ hasMore: boolean;
1064
+ }
1065
+
1066
+ /** Each distinct query is its own row set with its own paging. */
1067
+ export declare interface InvoiceQuery {
1068
+ /** Include unpaid invoices that are not yet due. Default false. */
1069
+ includePending?: boolean;
1070
+ }
1071
+
1072
+ export declare interface InvoicesHandle extends ResourceHandle<InvoicePage> {
1073
+ /**
1074
+ * Requests the next page; appended to `data.invoices` when it arrives.
1075
+ * `isPending` is true while it is on the wire and `error` records a
1076
+ * failure, so a caller can track both without awaiting — the promise
1077
+ * never rejects.
1078
+ */
1079
+ loadMore: () => Promise<void>;
1080
+ }
1081
+
1082
+ declare interface InvoicesRequest extends InvoiceQuery {
1083
+ limit: number;
1084
+ offset: number;
1085
+ }
1086
+
1087
+ /**
1088
+ * The rows asked for, and how many the query matches in total. `hasMore` is
1089
+ * the page's, and only the caller knows its offset.
1090
+ */
1091
+ declare type InvoicesResult = Omit<InvoicePage, "hasMore">;
1092
+
1093
+ /**
1094
+ *
1095
+ * @export
1096
+ */
1097
+ export declare const InvoiceStatus: {
1098
+ readonly Draft: "draft";
1099
+ readonly Open: "open";
1100
+ readonly Paid: "paid";
1101
+ readonly Uncollectible: "uncollectible";
1102
+ readonly Void: "void";
1103
+ };
1104
+
1105
+ export declare type InvoiceStatus = (typeof InvoiceStatus)[keyof typeof InvoiceStatus];
1106
+
593
1107
  /** A record of unique key-value pairs used for identifying a company or user */
594
1108
  export declare type Keys = Record<string, string>;
595
1109
 
@@ -617,10 +1131,51 @@ declare const MetricPeriodMonthReset: {
617
1131
 
618
1132
  declare type MetricPeriodMonthReset = (typeof MetricPeriodMonthReset)[keyof typeof MetricPeriodMonthReset];
619
1133
 
1134
+ /**
1135
+ * Keeps only the fields the request reads. The store keys a row set by the
1136
+ * query's shape, so a field the API never sees would key a row set of its
1137
+ * own, and a varying one a row set per render. schematic-js's normalizer
1138
+ * passes unknown fields through; this export shadows it on purpose.
1139
+ */
1140
+ export declare function normalizeInvoiceQuery(query: InvoiceQuery): InvoiceQuery;
1141
+
1142
+ /**
1143
+ * The store keys a resource by the query's shape, so without this
1144
+ * `{ includePending: false }` is a different row set from `{}` — it would
1145
+ * miss the seed and refetch rows identical to those already on screen.
1146
+ */
1147
+ declare function normalizeInvoiceQuery_2(query: InvoiceQuery): InvoiceQuery;
1148
+
620
1149
  declare type PendingListenerFn = BooleanListenerFn | EmptyListenerFn;
621
1150
 
622
1151
  declare type PlanListenerFn = CheckPlanReturnListenerFn | EmptyListenerFn;
623
1152
 
1153
+ declare interface RequestOptions {
1154
+ method?: string;
1155
+ body?: unknown;
1156
+ /**
1157
+ * Success statuses that carry no body — a 204 for a resource that is
1158
+ * legitimately absent. The request resolves `undefined` for them, which
1159
+ * is distinct from a body that parsed to `null`. A 401 is never one — the
1160
+ * refresh and retry run first, and only what comes back from that is
1161
+ * judged.
1162
+ */
1163
+ noContentOn?: number[];
1164
+ }
1165
+
1166
+ export declare interface ResourceHandle<T> extends ResourceState<T> {
1167
+ refetch: () => void;
1168
+ }
1169
+
1170
+ export declare interface ResourceState<T> {
1171
+ /** `undefined` until the first successful load; retained across later errors. */
1172
+ data: T | undefined;
1173
+ /** The latest failure; cleared by the next success. */
1174
+ error: Error | undefined;
1175
+ /** A request is in flight and no data has arrived yet, or a refetch is running. */
1176
+ isPending: boolean;
1177
+ }
1178
+
624
1179
  export declare enum RuleType {
625
1180
  /** A global rule that, if present, will override all other rules for a flag */
626
1181
  GLOBAL_OVERRIDE = "global_override",
@@ -655,9 +1210,9 @@ declare const RuleType_2: {
655
1210
  declare type RuleType_2 = (typeof RuleType_2)[keyof typeof RuleType_2];
656
1211
 
657
1212
  export declare class Schematic {
658
- private additionalHeaders;
1213
+ private _additionalHeaders;
659
1214
  private apiKey;
660
- private apiUrl;
1215
+ private _apiUrl;
661
1216
  private conn;
662
1217
  private context;
663
1218
  private debugEnabled;
@@ -702,6 +1257,8 @@ export declare class Schematic {
702
1257
  private flagCheckDefaults;
703
1258
  private fallbackCheckCache;
704
1259
  constructor(apiKey: string, options?: SchematicOptions);
1260
+ get apiUrl(): string;
1261
+ get additionalHeaders(): Record<string, string>;
705
1262
  /**
706
1263
  * Resolve fallback value according to priority order:
707
1264
  * 1. Callsite fallback value (if provided)
@@ -914,6 +1471,28 @@ export declare class Schematic {
914
1471
  private notifyCreditBalanceListeners;
915
1472
  }
916
1473
 
1474
+ declare class SchematicApiError extends Error {
1475
+ readonly status: number;
1476
+ readonly path: string;
1477
+ readonly body: unknown;
1478
+ constructor(status: number, path: string, body: unknown);
1479
+ }
1480
+
1481
+ declare class SchematicBillingClient implements BillingClient {
1482
+ /**
1483
+ * Public so a second client over the same surface can be constructed on
1484
+ * this one rather than minting tokens of its own.
1485
+ */
1486
+ readonly session: SchematicSession;
1487
+ constructor(options?: BillingClientOptions | SchematicSession);
1488
+ get sessionKey(): string | undefined;
1489
+ get sessionStatus(): SessionStatus;
1490
+ setSession(session: SessionInput): void;
1491
+ onSessionChange(listener: (event: SessionEvent) => void): () => void;
1492
+ fetchInvoices(params: InvoicesRequest): Promise<InvoicesResult>;
1493
+ fetchUpcomingInvoice(): Promise<UpcomingInvoice | null>;
1494
+ }
1495
+
917
1496
  /** Context for checking flags and sending events */
918
1497
  export declare type SchematicContext = {
919
1498
  company?: Keys;
@@ -936,12 +1515,53 @@ export declare interface SchematicHookOpts {
936
1515
  client?: SchematicJS.Schematic;
937
1516
  }
938
1517
 
1518
+ export declare interface SchematicI18nConfig {
1519
+ /** BCP 47 tag the elements format in; defaults to the runtime's locale. */
1520
+ locale?: string;
1521
+ /** Routes element copy to the host's i18n stack — pass i18next's `t`. */
1522
+ translate?: Translate;
1523
+ /**
1524
+ * Copy by key, for a host renaming strings rather than translating them.
1525
+ * Wins over `translate`; an element's own `strings` prop wins over both.
1526
+ */
1527
+ strings?: StringOverrides;
1528
+ /** Reports a mis-wired catalogue that would otherwise look correct. */
1529
+ onMissingString?: (key: string) => void;
1530
+ }
1531
+
1532
+ export declare const SchematicI18nContext: React_2.Context<SchematicI18nConfig>;
1533
+
1534
+ /**
1535
+ * `SchematicProvider` renders one of these, so most hosts never name it.
1536
+ * Nesting merges rather than replaces: a provider setting only `locale`
1537
+ * keeps the translator above it, and `strings` layers key by key.
1538
+ */
1539
+ export declare function SchematicI18nProvider({ children, locale, onMissingString, strings, translate, }: SchematicI18nProviderProps): React_2.JSX.Element;
1540
+
1541
+ export declare interface SchematicI18nProviderProps extends SchematicI18nConfig {
1542
+ children?: React_2.ReactNode;
1543
+ }
1544
+
939
1545
  declare namespace SchematicJS {
940
1546
  export {
941
1547
  CheckFlagResponseFromJSON,
942
1548
  CheckFlagsResponseFromJSON,
943
1549
  DatastreamCompanyPlanFromJSON,
944
1550
  EventBodyFlagCheckToJSON,
1551
+ fetchBillingData,
1552
+ normalizeInvoiceQuery_2 as normalizeInvoiceQuery,
1553
+ sessionKey,
1554
+ AccessToken,
1555
+ AccessTokenProvider,
1556
+ AccessTokenResult,
1557
+ billingApi,
1558
+ BillingClient,
1559
+ BillingClientOptions,
1560
+ BillingData,
1561
+ BillingPrefetchOptions,
1562
+ BillingResourceName,
1563
+ BillingResourceParams,
1564
+ BillingResources,
945
1565
  BooleanListenerFn,
946
1566
  CheckFlagResponseData,
947
1567
  CheckFlagReturn,
@@ -952,11 +1572,16 @@ declare namespace SchematicJS {
952
1572
  CheckPlanReturnFromJSON,
953
1573
  CheckPlanReturnListenerFn,
954
1574
  CompanyCreditBalance,
1575
+ CompanyDiscountResponseData,
1576
+ CompanyInvoiceResponseData,
1577
+ CompanyUpcomingInvoiceResponseData,
955
1578
  CreditBalance,
956
1579
  CreditBalanceListenerFn,
957
1580
  CreditBalances,
958
1581
  CreditBalancesFromJSON,
959
1582
  CreditBalancesListenerFn,
1583
+ DEFAULT_INVOICE_QUERY,
1584
+ Discount,
960
1585
  EmptyListenerFn,
961
1586
  Event_2 as Event,
962
1587
  EventBody,
@@ -966,17 +1591,39 @@ declare namespace SchematicJS {
966
1591
  EventType,
967
1592
  FlagCheckListenerFn,
968
1593
  FlagValueListenerFn,
1594
+ Invoice,
1595
+ INVOICE_MAX_PAGE_SIZE,
1596
+ INVOICE_PAGE_SIZE,
1597
+ InvoicePage,
1598
+ InvoiceQuery,
1599
+ InvoicesRequest,
1600
+ InvoicesResult,
1601
+ InvoiceStatus,
969
1602
  Keys,
970
1603
  PendingListenerFn,
971
1604
  PlanListenerFn,
1605
+ RequestOptions,
1606
+ ResourceState,
972
1607
  RuleType,
973
1608
  Schematic,
1609
+ SchematicApiError,
1610
+ SchematicBillingClient,
974
1611
  SchematicContext,
975
1612
  SchematicOptions,
1613
+ SchematicSession,
1614
+ Session,
1615
+ SessionEvent,
1616
+ SessionInput,
1617
+ SessionOptions,
1618
+ SessionStatus,
1619
+ SINGLETON,
976
1620
  StoragePersister,
1621
+ TOKEN_CACHE_SIZE,
977
1622
  Traits,
978
1623
  TrialStatus,
979
- UsagePeriod
1624
+ UpcomingInvoice,
1625
+ UsagePeriod,
1626
+ WarningTier
980
1627
  }
981
1628
  }
982
1629
 
@@ -1044,6 +1691,114 @@ declare type SchematicProviderPropsWithPublishableKey = BaseSchematicProviderPro
1044
1691
  publishableKey: string;
1045
1692
  };
1046
1693
 
1694
+ /**
1695
+ * Session identity is the (company, user) pair alone: a freshly minted token,
1696
+ * a rebuilt provider closure, and a refresh this session asked for itself are
1697
+ * all the same session. Nothing in a token says who it was minted for, so
1698
+ * that question is the host's to answer.
1699
+ *
1700
+ * Credentials survive a change of session, keyed by pair — switching back to
1701
+ * a company reads with the token already in hand. They do not survive the
1702
+ * session ending: after a sign-out the next person at this page is somebody
1703
+ * else, and nothing minted for the last one is theirs to send.
1704
+ */
1705
+ declare class SchematicSession {
1706
+ private readonly _apiUrl;
1707
+ private readonly _headers;
1708
+ private readonly _fetch;
1709
+ private _session;
1710
+ private readonly _tokens;
1711
+ private readonly _resolving;
1712
+ /**
1713
+ * Bumped when the session's identity changes, and only then — the object
1714
+ * itself is replaced on every render. Anything asking "is this still the
1715
+ * session I started under?" counts generations rather than comparing.
1716
+ */
1717
+ private _generation;
1718
+ private readonly _listeners;
1719
+ constructor(options?: SessionOptions);
1720
+ get key(): string | undefined;
1721
+ get status(): SessionStatus;
1722
+ /** Only a statement that changes which pair is read counts as a change. */
1723
+ set(session: SessionInput): void;
1724
+ onChange(listener: (event: SessionEvent) => void): () => void;
1725
+ private _emit;
1726
+ private _cached;
1727
+ private _cache;
1728
+ /**
1729
+ * The credential for a session, minted if this one is not held. `force`
1730
+ * retires what is held first: the caller is a request the API has just
1731
+ * rejected.
1732
+ */
1733
+ resolveToken(session: Session, force: boolean): Promise<string>;
1734
+ /**
1735
+ * Sends a request under the active session's credential, refreshing once
1736
+ * and retrying if the API rejects it. Rejects rather than answering when
1737
+ * the session changes while the request is in flight: the rows would
1738
+ * otherwise come back as the answer to a question asked for another pair.
1739
+ */
1740
+ request(path: string, options?: RequestOptions): Promise<unknown>;
1741
+ }
1742
+
1743
+ /**
1744
+ * Who is being read. Users and companies are many-to-many: the same person
1745
+ * reads one company's billing and then another's, and the same company is
1746
+ * read by several people. A token is minted for the pair, so the pair — not
1747
+ * the company alone — is the session's identity.
1748
+ */
1749
+ export declare interface Session {
1750
+ /** The host's name for the company, its id in their own system say. */
1751
+ company: string;
1752
+ /**
1753
+ * The user, where the host mints per (company, user). Left out by a host
1754
+ * whose tokens are company-wide, and then every reader of that company
1755
+ * shares one session.
1756
+ */
1757
+ user?: string;
1758
+ token: AccessToken;
1759
+ }
1760
+
1761
+ /**
1762
+ * What happened to the session, for anything holding data that belongs to
1763
+ * one. `started`: whatever is loaded belongs to the new session — a prefetch
1764
+ * the host seeded before its auth resolved. `changed`: another pair is being
1765
+ * read, and what is loaded belongs to the pair being left. `ended`: nobody is
1766
+ * signed in, and what is loaded belongs to nobody.
1767
+ */
1768
+ export declare type SessionEvent = {
1769
+ type: "started" | "changed" | "ended";
1770
+ };
1771
+
1772
+ /**
1773
+ * Three states that are not interchangeable:
1774
+ *
1775
+ * * `Session` — active: this pair, read with this credential.
1776
+ * * `null` — ended: nobody is signed in; what is loaded is dropped.
1777
+ * * `undefined` — pending: the host's auth has not resolved. It states
1778
+ * nothing, so the session in hand stands.
1779
+ */
1780
+ export declare type SessionInput = Session | null | undefined;
1781
+
1782
+ /**
1783
+ * The pair as one string, for anything that has to compare sessions or key
1784
+ * something by one — a prefetch stating which session it was fetched for, a
1785
+ * store keeping a page per session. Opaque: read it only by equality.
1786
+ */
1787
+ declare function sessionKey(session: Session): string;
1788
+
1789
+ declare interface SessionOptions {
1790
+ session?: SessionInput;
1791
+ apiUrl?: string;
1792
+ additionalHeaders?: Record<string, string>;
1793
+ /** Override for tests and non-browser runtimes. */
1794
+ fetch?: typeof fetch;
1795
+ }
1796
+
1797
+ export declare type SessionStatus = "pending" | "active" | "ended";
1798
+
1799
+ /** The params of every singleton resource. */
1800
+ declare const SINGLETON: Record<string, never>;
1801
+
1047
1802
  /** Optional type for implementing custom client-side storage */
1048
1803
  export declare type StoragePersister = {
1049
1804
  setItem(key: string, value: any): void;
@@ -1051,11 +1806,44 @@ export declare type StoragePersister = {
1051
1806
  removeItem(key: string): void;
1052
1807
  };
1053
1808
 
1809
+ /** Copy overrides by key. Keys are the element package's `StringKey`s. */
1810
+ export declare type StringOverrides = Record<string, string | undefined>;
1811
+
1812
+ /**
1813
+ * Sessions whose credentials are kept. A reader switching between the
1814
+ * organizations they belong to walks a handful of them and comes back, and
1815
+ * re-minting on every step is a round trip to the host's token endpoint for
1816
+ * a token this client already holds and has not seen expire. The same
1817
+ * handful the flag cache bounds its contexts at.
1818
+ */
1819
+ declare const TOKEN_CACHE_SIZE = 10;
1820
+
1054
1821
  /**
1055
1822
  * A flexible key/value type that can store any type of value on a company or user.
1056
1823
  */
1057
1824
  export declare type Traits = Record<string, any>;
1058
1825
 
1826
+ /**
1827
+ * Locale and copy live in their own context, not on the billing data source:
1828
+ * a host's `t` changes identity whenever its language does, and a source
1829
+ * rebuilt for that takes its cached snapshots with it, leaving
1830
+ * `useSyncExternalStore` a new handle every render.
1831
+ *
1832
+ * Nothing here interprets a key — the element package owns the key list and
1833
+ * the English copy.
1834
+ */
1835
+ /**
1836
+ * Shaped like i18next's `t` so `translate={t}` is the whole integration.
1837
+ * `vars` reaches it as the options object, which is what lets `{ count }`
1838
+ * resolve a language's plural forms in the host's own stack rather than in
1839
+ * ours.
1840
+ *
1841
+ * Returning `undefined` means "no translation" and the caller falls back to
1842
+ * its English default. Elements also pass a sentinel `defaultValue`, so a stack
1843
+ * that answers every key with something still reports a real miss.
1844
+ */
1845
+ export declare type Translate = (key: string, vars?: Record<string, unknown>) => string | undefined;
1846
+
1059
1847
  /**
1060
1848
  *
1061
1849
  * @export
@@ -1068,6 +1856,8 @@ export declare const TrialStatus: {
1068
1856
 
1069
1857
  export declare type TrialStatus = (typeof TrialStatus)[keyof typeof TrialStatus];
1070
1858
 
1859
+ declare type UpcomingInvoice = CompanyUpcomingInvoiceResponseData;
1860
+
1071
1861
  export declare enum UsagePeriod {
1072
1862
  ALL_TIME = "all_time",
1073
1863
  CURRENT_DAY = "current_day",
@@ -1075,6 +1865,17 @@ export declare enum UsagePeriod {
1075
1865
  CURRENT_WEEK = "current_week"
1076
1866
  }
1077
1867
 
1868
+ export declare function useBillingDataSource(): BillingDataSource;
1869
+
1870
+ /** Reloads every loaded billing resource (after a plan change, for instance). */
1871
+ export declare function useInvalidateBillingData(): () => void;
1872
+
1873
+ /**
1874
+ * The invoice list for `query`. Each distinct query is its own list with its
1875
+ * own paging; an inline object literal is fine, the hook keys by value.
1876
+ */
1877
+ export declare function useInvoices(query?: InvoiceQuery): InvoicesHandle;
1878
+
1078
1879
  export declare const useSchematic: () => SchematicContextProps;
1079
1880
 
1080
1881
  export declare const useSchematicContext: (opts?: SchematicHookOpts) => {
@@ -1088,8 +1889,13 @@ export declare const useSchematicContext: (opts?: SchematicHookOpts) => {
1088
1889
  * `credit_balances` map (keyed by credit ID). It re-renders as partials arrive
1089
1890
  * over the DataStream, so it stays accurate during an open lease — when the raw
1090
1891
  * `remaining` would otherwise read stale / falsely "exhausted".
1892
+ *
1893
+ * `creditId` accepts `undefined` so it can be fed straight from an
1894
+ * entitlement's `creditId`, which is undefined until the check arrives and for
1895
+ * features that are not credit-based. While the ID is undefined the hook
1896
+ * reports the client's loading state and a balance of 0.
1091
1897
  */
1092
- export declare const useSchematicCreditBalance: (creditId: string, opts?: SchematicHookOpts) => SchematicCreditBalance;
1898
+ export declare const useSchematicCreditBalance: (creditId: string | undefined, opts?: SchematicHookOpts) => SchematicCreditBalance;
1093
1899
 
1094
1900
  export declare const useSchematicEntitlement: (key: string, opts?: UseSchematicFlagOpts) => SchematicJS.CheckFlagReturn;
1095
1901
 
@@ -1104,12 +1910,53 @@ export declare type UseSchematicFlagOpts = SchematicHookOpts & {
1104
1910
  fallback?: boolean;
1105
1911
  };
1106
1912
 
1913
+ /** Empty, never undefined, outside a provider. */
1914
+ export declare function useSchematicI18n(): SchematicI18nConfig;
1915
+
1107
1916
  export declare const useSchematicIsPending: (opts?: SchematicHookOpts) => boolean;
1108
1917
 
1918
+ /** Unresolved: elements call `useResolvedLocale`, which applies the fallback. */
1919
+ export declare function useSchematicLocale(): string | undefined;
1920
+
1109
1921
  export declare const useSchematicPlan: (opts?: UseSchematicPlanOpts) => SchematicJS.CheckPlanReturn | undefined;
1110
1922
 
1111
1923
  export declare type UseSchematicPlanOpts = SchematicHookOpts & {
1112
1924
  fallback?: SchematicJS.CheckPlanReturn;
1113
1925
  };
1114
1926
 
1927
+ export declare function useSchematicStrings(): StringOverrides | undefined;
1928
+
1929
+ export declare function useSchematicTranslate(): Translate | undefined;
1930
+
1931
+ /**
1932
+ * Schematic API
1933
+ * Schematic API
1934
+ *
1935
+ * The version of the OpenAPI document: 0.1
1936
+ *
1937
+ *
1938
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
1939
+ * https://openapi-generator.tech
1940
+ * Do not edit the class manually.
1941
+ */
1942
+ /**
1943
+ *
1944
+ * @export
1945
+ * @interface WarningTier
1946
+ */
1947
+ export declare interface WarningTier {
1948
+ /**
1949
+ * A customer-defined identifier for the warning tier
1950
+ * @type {string}
1951
+ * @memberof WarningTier
1952
+ */
1953
+ key: string;
1954
+ /**
1955
+ * The warning threshold, in the entitlement's usage units
1956
+ * @type {number}
1957
+ * @memberof WarningTier
1958
+ */
1959
+ value: number;
1960
+ }
1961
+
1115
1962
  export { }