@schematichq/schematic-react 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.
- package/README.md +46 -2
- package/dist/schematic-react.cjs.js +1480 -52
- package/dist/schematic-react.d.ts +666 -3
- package/dist/schematic-react.esm.js +1480 -52
- package/package.json +26 -30
|
@@ -1,9 +1,234 @@
|
|
|
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?: BillingClient;
|
|
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
|
+
instanceOfCompanyInvoiceResponseData,
|
|
57
|
+
CompanyInvoiceResponseDataFromJSON,
|
|
58
|
+
CompanyInvoiceResponseDataFromJSONTyped,
|
|
59
|
+
CompanyInvoiceResponseDataToJSON,
|
|
60
|
+
CompanyInvoiceResponseDataToJSONTyped,
|
|
61
|
+
CompanyInvoiceResponseData,
|
|
62
|
+
instanceOfCompanyInvoicesResponseData,
|
|
63
|
+
CompanyInvoicesResponseDataFromJSON,
|
|
64
|
+
CompanyInvoicesResponseDataFromJSONTyped,
|
|
65
|
+
CompanyInvoicesResponseDataToJSON,
|
|
66
|
+
CompanyInvoicesResponseDataToJSONTyped,
|
|
67
|
+
CompanyInvoicesResponseData,
|
|
68
|
+
instanceOfGetCompanyInvoicesParams,
|
|
69
|
+
GetCompanyInvoicesParamsFromJSON,
|
|
70
|
+
GetCompanyInvoicesParamsFromJSONTyped,
|
|
71
|
+
GetCompanyInvoicesParamsToJSON,
|
|
72
|
+
GetCompanyInvoicesParamsToJSONTyped,
|
|
73
|
+
GetCompanyInvoicesParams,
|
|
74
|
+
instanceOfGetCompanyInvoicesResponse,
|
|
75
|
+
GetCompanyInvoicesResponseFromJSON,
|
|
76
|
+
GetCompanyInvoicesResponseFromJSONTyped,
|
|
77
|
+
GetCompanyInvoicesResponseToJSON,
|
|
78
|
+
GetCompanyInvoicesResponseToJSONTyped,
|
|
79
|
+
GetCompanyInvoicesResponse,
|
|
80
|
+
instanceOfInvoiceStatus,
|
|
81
|
+
InvoiceStatusFromJSON,
|
|
82
|
+
InvoiceStatusFromJSONTyped,
|
|
83
|
+
InvoiceStatusToJSON,
|
|
84
|
+
InvoiceStatusToJSONTyped,
|
|
85
|
+
InvoiceStatus
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* What a reader of billing data can ask for. Subscription and usage — the
|
|
91
|
+
* rest of what `hydrate` serves — and the checkout calls that change them
|
|
92
|
+
* join this interface as their endpoints ship.
|
|
93
|
+
*/
|
|
94
|
+
export declare interface BillingClient {
|
|
95
|
+
fetchInvoices(params: InvoicesRequest): Promise<InvoicesResult>;
|
|
96
|
+
readonly sessionStatus: SessionStatus;
|
|
97
|
+
readonly sessionKey: string | undefined;
|
|
98
|
+
setSession(session: SessionInput): void;
|
|
99
|
+
onSessionChange(listener: (event: SessionEvent) => void): () => void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
declare type BillingClientOptions = SessionOptions;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A prefetch or fixture. An omitted key reports as pending; a keyed resource
|
|
106
|
+
* seeds under `params`, or its defaults when absent, so a prefetch for a
|
|
107
|
+
* non-default query is claimed rather than refetched by the element.
|
|
108
|
+
*/
|
|
109
|
+
export declare type BillingData = {
|
|
110
|
+
[K in BillingResourceName]?: BillingResources[K];
|
|
111
|
+
} & {
|
|
112
|
+
params?: Partial<BillingResourceParams>;
|
|
113
|
+
/**
|
|
114
|
+
* A prefetch outlives the render that made it — a cached page, a session
|
|
115
|
+
* resolving to somebody else — so a store adopts it only for the session
|
|
116
|
+
* it names. `fetchBillingData` fills it in; a fixture need not.
|
|
117
|
+
*/
|
|
118
|
+
sessionKey?: string;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export declare function BillingDataProvider({ children, data, locale, onLoadMoreInvoices, onMissingString, onRefetch, status, strings, translate, }: BillingDataProviderProps): React_2.JSX.Element;
|
|
122
|
+
|
|
123
|
+
declare interface BillingDataProviderDataProps {
|
|
124
|
+
/** A missing key reports as pending. */
|
|
125
|
+
data: BillingData;
|
|
126
|
+
/** Simulated loading / failure per resource; wins over `data`. */
|
|
127
|
+
status?: BillingDataStatus;
|
|
128
|
+
onRefetch?: (name: BillingResourceName) => void;
|
|
129
|
+
onLoadMoreInvoices?: (query: InvoiceQuery) => void;
|
|
130
|
+
children?: React_2.ReactNode;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Feeds the billing hooks from plain data with no fetching: fixtures,
|
|
135
|
+
* stories, tests, or a fully prefetched page. The i18n props configure a
|
|
136
|
+
* `SchematicI18nProvider` around the children and never touch the data seam.
|
|
137
|
+
*/
|
|
138
|
+
export declare type BillingDataProviderProps = BillingDataProviderDataProps & SchematicI18nConfig;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The seam between the hooks and whatever supplies data: the provider's
|
|
142
|
+
* store, a server prefetch, or fixtures.
|
|
143
|
+
*/
|
|
144
|
+
export declare interface BillingDataSource {
|
|
145
|
+
/**
|
|
146
|
+
* Sources that hold one value per resource (fixtures, prefetch) serve it
|
|
147
|
+
* for every parameter set.
|
|
148
|
+
*/
|
|
149
|
+
subscribe<K extends BillingResourceName>(name: K, params: BillingResourceParams[K], listener: () => void): () => void;
|
|
150
|
+
handle<K extends BillingResourceName>(name: K, params: BillingResourceParams[K]): ResourceHandle<BillingResources[K]>;
|
|
151
|
+
/** Never rejects: a failure lands on the resource's `error`. */
|
|
152
|
+
loadMoreInvoices: (query: InvoiceQuery) => Promise<void>;
|
|
153
|
+
invalidateAll: () => void;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Per-resource status overrides, for fixtures that simulate loading and failure. */
|
|
157
|
+
export declare type BillingDataStatus = {
|
|
158
|
+
[K in BillingResourceName]?: {
|
|
159
|
+
isPending?: boolean;
|
|
160
|
+
error?: Error;
|
|
161
|
+
};
|
|
5
162
|
};
|
|
6
163
|
|
|
164
|
+
declare interface BillingPrefetchOptions {
|
|
165
|
+
names?: BillingResourceName[];
|
|
166
|
+
/** The invoice query to prefetch for; the element must ask the same one. */
|
|
167
|
+
invoices?: InvoiceQuery;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Provides the billing hooks from a `BillingStore` over a `BillingClient`.
|
|
172
|
+
* Rendered by `SchematicProvider`; usable on its own with a client.
|
|
173
|
+
*/
|
|
174
|
+
export declare function BillingProvider({ billingClient, children, initialData, locale, onMissingString, session, strings, translate, }: BillingProviderProps): React_2.JSX.Element;
|
|
175
|
+
|
|
176
|
+
declare interface BillingProviderDataProps {
|
|
177
|
+
/**
|
|
178
|
+
* Required: this provider does not build one, and without it every hook
|
|
179
|
+
* reports the missing-source error and `session` has nowhere to go.
|
|
180
|
+
* `SchematicProvider` constructs one from its publishable key and renders
|
|
181
|
+
* this underneath, which is the usual path.
|
|
182
|
+
*/
|
|
183
|
+
billingClient?: BillingClient;
|
|
184
|
+
/**
|
|
185
|
+
* Read once, at mount. A prefetch stamped with its session paints on the
|
|
186
|
+
* first render only if `session` is stated on that render; under
|
|
187
|
+
* `undefined` it is held until the session starts. On a server-rendered
|
|
188
|
+
* page, state the pair on the first client render — `token` may be an
|
|
189
|
+
* async provider — or hydration will not match.
|
|
190
|
+
*/
|
|
191
|
+
initialData?: BillingData;
|
|
192
|
+
/**
|
|
193
|
+
* Who is being read, and the credential for it: `{ company, user?, token }`
|
|
194
|
+
* while someone is signed in, `null` when nobody is, and `undefined` while
|
|
195
|
+
* the host is still finding out.
|
|
196
|
+
*
|
|
197
|
+
* The (company, user) pair is the identity, so a token that rotates — a
|
|
198
|
+
* provider called again, a closure rebuilt on a render — is the same
|
|
199
|
+
* session and keeps what is loaded, while another pair drops it.
|
|
200
|
+
* `undefined` states nothing, which is what an auth resolving
|
|
201
|
+
* asynchronously renders first.
|
|
202
|
+
*/
|
|
203
|
+
session?: SessionInput;
|
|
204
|
+
children?: React_2.ReactNode;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* The i18n props are forwarded to a `SchematicI18nProvider` and never reach
|
|
209
|
+
* the data seam.
|
|
210
|
+
*/
|
|
211
|
+
export declare type BillingProviderProps = BillingProviderDataProps & SchematicI18nConfig;
|
|
212
|
+
|
|
213
|
+
export declare type BillingResourceName = keyof BillingResources;
|
|
214
|
+
|
|
215
|
+
/** `Record<string, never>` marks a singleton; anything else is keyed. */
|
|
216
|
+
export declare interface BillingResourceParams {
|
|
217
|
+
invoices: InvoiceQuery;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Nothing in the store, the hooks, or the resource keys may be addressed by
|
|
222
|
+
* company or user id: users and companies are many-to-many, and a token names
|
|
223
|
+
* the pair. What is loaded belongs to the session it was read under — the
|
|
224
|
+
* pair, as `sessionKey` writes it — and a store that keeps more than one
|
|
225
|
+
* session's data keys it by that and serves only the active one.
|
|
226
|
+
*/
|
|
227
|
+
export declare interface BillingResources {
|
|
228
|
+
/** `GET /company/invoices?limit&offset&include_pending`. */
|
|
229
|
+
invoices: InvoicePage;
|
|
230
|
+
}
|
|
231
|
+
|
|
7
232
|
declare type BooleanListenerFn = (value: boolean) => void;
|
|
8
233
|
|
|
9
234
|
/**
|
|
@@ -282,6 +507,56 @@ export declare interface CompanyCreditBalance {
|
|
|
282
507
|
settled: number;
|
|
283
508
|
}
|
|
284
509
|
|
|
510
|
+
/**
|
|
511
|
+
*
|
|
512
|
+
* @export
|
|
513
|
+
* @interface CompanyInvoiceResponseData
|
|
514
|
+
*/
|
|
515
|
+
declare interface CompanyInvoiceResponseData {
|
|
516
|
+
/**
|
|
517
|
+
*
|
|
518
|
+
* @type {number}
|
|
519
|
+
* @memberof CompanyInvoiceResponseData
|
|
520
|
+
*/
|
|
521
|
+
amountDue: number;
|
|
522
|
+
/**
|
|
523
|
+
*
|
|
524
|
+
* @type {Date}
|
|
525
|
+
* @memberof CompanyInvoiceResponseData
|
|
526
|
+
*/
|
|
527
|
+
createdAt: Date;
|
|
528
|
+
/**
|
|
529
|
+
*
|
|
530
|
+
* @type {string}
|
|
531
|
+
* @memberof CompanyInvoiceResponseData
|
|
532
|
+
*/
|
|
533
|
+
currency: string;
|
|
534
|
+
/**
|
|
535
|
+
*
|
|
536
|
+
* @type {Date}
|
|
537
|
+
* @memberof CompanyInvoiceResponseData
|
|
538
|
+
*/
|
|
539
|
+
dueDate?: Date | null;
|
|
540
|
+
/**
|
|
541
|
+
*
|
|
542
|
+
* @type {string}
|
|
543
|
+
* @memberof CompanyInvoiceResponseData
|
|
544
|
+
*/
|
|
545
|
+
id: string;
|
|
546
|
+
/**
|
|
547
|
+
*
|
|
548
|
+
* @type {InvoiceStatus}
|
|
549
|
+
* @memberof CompanyInvoiceResponseData
|
|
550
|
+
*/
|
|
551
|
+
status?: InvoiceStatus | null;
|
|
552
|
+
/**
|
|
553
|
+
*
|
|
554
|
+
* @type {string}
|
|
555
|
+
* @memberof CompanyInvoiceResponseData
|
|
556
|
+
*/
|
|
557
|
+
url?: string | null;
|
|
558
|
+
}
|
|
559
|
+
|
|
285
560
|
/** A company's lease-aware balance for a single credit type */
|
|
286
561
|
export declare type CreditBalance = {
|
|
287
562
|
/** Spendable balance including any open lease hold (remaining + reserved); the number to display to end users */
|
|
@@ -335,6 +610,8 @@ declare interface DatastreamCompanyPlan {
|
|
|
335
610
|
|
|
336
611
|
declare function DatastreamCompanyPlanFromJSON(json: any): DatastreamCompanyPlan;
|
|
337
612
|
|
|
613
|
+
export declare const DEFAULT_INVOICE_QUERY: InvoiceQuery;
|
|
614
|
+
|
|
338
615
|
declare type EmptyListenerFn = () => void;
|
|
339
616
|
|
|
340
617
|
/**
|
|
@@ -407,6 +684,12 @@ declare interface EventBodyFlagCheck {
|
|
|
407
684
|
* @memberof EventBodyFlagCheck
|
|
408
685
|
*/
|
|
409
686
|
flagKey: string;
|
|
687
|
+
/**
|
|
688
|
+
* Whether the check was a preflight, asking whether an action would be allowed rather than reporting one that happened. Absent on ordinary checks
|
|
689
|
+
* @type {boolean}
|
|
690
|
+
* @memberof EventBodyFlagCheck
|
|
691
|
+
*/
|
|
692
|
+
preflight?: boolean;
|
|
410
693
|
/**
|
|
411
694
|
* The reason why the value was returned
|
|
412
695
|
* @type {string}
|
|
@@ -584,12 +867,79 @@ declare interface FeatureEntitlement {
|
|
|
584
867
|
* @memberof FeatureEntitlement
|
|
585
868
|
*/
|
|
586
869
|
valueType: EntitlementValueType;
|
|
870
|
+
/**
|
|
871
|
+
* Customer-defined usage warning thresholds configured on this entitlement
|
|
872
|
+
* @type {Array<WarningTier>}
|
|
873
|
+
* @memberof FeatureEntitlement
|
|
874
|
+
*/
|
|
875
|
+
warningTiers?: Array<WarningTier>;
|
|
587
876
|
}
|
|
588
877
|
|
|
878
|
+
/**
|
|
879
|
+
* Server prefetch for a provider's `initialData`. A resource that fails is
|
|
880
|
+
* left out rather than thrown, so one of them cannot block a page.
|
|
881
|
+
*/
|
|
882
|
+
declare function fetchBillingData(client: BillingClient, options?: BillingPrefetchOptions): Promise<BillingData>;
|
|
883
|
+
|
|
589
884
|
declare type FlagCheckListenerFn = CheckFlagReturnListenerFn | EmptyListenerFn;
|
|
590
885
|
|
|
591
886
|
declare type FlagValueListenerFn = BooleanListenerFn | EmptyListenerFn;
|
|
592
887
|
|
|
888
|
+
export declare type Invoice = CompanyInvoiceResponseData;
|
|
889
|
+
|
|
890
|
+
/** A `limit` above this is a 400 (PaginationFilter in schematic-api). */
|
|
891
|
+
declare const INVOICE_MAX_PAGE_SIZE = 250;
|
|
892
|
+
|
|
893
|
+
export declare const INVOICE_PAGE_SIZE = 12;
|
|
894
|
+
|
|
895
|
+
export declare interface InvoicePage {
|
|
896
|
+
invoices: Invoice[];
|
|
897
|
+
/** Matching the query on the server, not the number loaded here. */
|
|
898
|
+
count: number;
|
|
899
|
+
hasMore: boolean;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
/** Each distinct query is its own row set with its own paging. */
|
|
903
|
+
export declare interface InvoiceQuery {
|
|
904
|
+
/** Include unpaid invoices that are not yet due. Default false. */
|
|
905
|
+
includePending?: boolean;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
export declare interface InvoicesHandle extends ResourceHandle<InvoicePage> {
|
|
909
|
+
/**
|
|
910
|
+
* Requests the next page; appended to `data.invoices` when it arrives.
|
|
911
|
+
* `isPending` is true while it is on the wire and `error` records a
|
|
912
|
+
* failure, so a caller can track both without awaiting — the promise
|
|
913
|
+
* never rejects.
|
|
914
|
+
*/
|
|
915
|
+
loadMore: () => Promise<void>;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
declare interface InvoicesRequest extends InvoiceQuery {
|
|
919
|
+
limit: number;
|
|
920
|
+
offset: number;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* The rows asked for, and how many the query matches in total. `hasMore` is
|
|
925
|
+
* the page's, and only the caller knows its offset.
|
|
926
|
+
*/
|
|
927
|
+
declare type InvoicesResult = Omit<InvoicePage, "hasMore">;
|
|
928
|
+
|
|
929
|
+
/**
|
|
930
|
+
*
|
|
931
|
+
* @export
|
|
932
|
+
*/
|
|
933
|
+
export declare const InvoiceStatus: {
|
|
934
|
+
readonly Draft: "draft";
|
|
935
|
+
readonly Open: "open";
|
|
936
|
+
readonly Paid: "paid";
|
|
937
|
+
readonly Uncollectible: "uncollectible";
|
|
938
|
+
readonly Void: "void";
|
|
939
|
+
};
|
|
940
|
+
|
|
941
|
+
export declare type InvoiceStatus = (typeof InvoiceStatus)[keyof typeof InvoiceStatus];
|
|
942
|
+
|
|
593
943
|
/** A record of unique key-value pairs used for identifying a company or user */
|
|
594
944
|
export declare type Keys = Record<string, string>;
|
|
595
945
|
|
|
@@ -617,10 +967,43 @@ declare const MetricPeriodMonthReset: {
|
|
|
617
967
|
|
|
618
968
|
declare type MetricPeriodMonthReset = (typeof MetricPeriodMonthReset)[keyof typeof MetricPeriodMonthReset];
|
|
619
969
|
|
|
970
|
+
/**
|
|
971
|
+
* Keeps only the fields the request reads. The store keys a row set by the
|
|
972
|
+
* query's shape, so a field the API never sees would key a row set of its
|
|
973
|
+
* own, and a varying one a row set per render. schematic-js's normalizer
|
|
974
|
+
* passes unknown fields through; this export shadows it on purpose.
|
|
975
|
+
*/
|
|
976
|
+
export declare function normalizeInvoiceQuery(query: InvoiceQuery): InvoiceQuery;
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* The store keys a resource by the query's shape, so without this
|
|
980
|
+
* `{ includePending: false }` is a different row set from `{}` — it would
|
|
981
|
+
* miss the seed and refetch rows identical to those already on screen.
|
|
982
|
+
*/
|
|
983
|
+
declare function normalizeInvoiceQuery_2(query: InvoiceQuery): InvoiceQuery;
|
|
984
|
+
|
|
620
985
|
declare type PendingListenerFn = BooleanListenerFn | EmptyListenerFn;
|
|
621
986
|
|
|
622
987
|
declare type PlanListenerFn = CheckPlanReturnListenerFn | EmptyListenerFn;
|
|
623
988
|
|
|
989
|
+
declare interface RequestOptions {
|
|
990
|
+
method?: string;
|
|
991
|
+
body?: unknown;
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
export declare interface ResourceHandle<T> extends ResourceState<T> {
|
|
995
|
+
refetch: () => void;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
export declare interface ResourceState<T> {
|
|
999
|
+
/** `undefined` until the first successful load; retained across later errors. */
|
|
1000
|
+
data: T | undefined;
|
|
1001
|
+
/** The latest failure; cleared by the next success. */
|
|
1002
|
+
error: Error | undefined;
|
|
1003
|
+
/** A request is in flight and no data has arrived yet, or a refetch is running. */
|
|
1004
|
+
isPending: boolean;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
624
1007
|
export declare enum RuleType {
|
|
625
1008
|
/** A global rule that, if present, will override all other rules for a flag */
|
|
626
1009
|
GLOBAL_OVERRIDE = "global_override",
|
|
@@ -655,9 +1038,9 @@ declare const RuleType_2: {
|
|
|
655
1038
|
declare type RuleType_2 = (typeof RuleType_2)[keyof typeof RuleType_2];
|
|
656
1039
|
|
|
657
1040
|
export declare class Schematic {
|
|
658
|
-
private
|
|
1041
|
+
private _additionalHeaders;
|
|
659
1042
|
private apiKey;
|
|
660
|
-
private
|
|
1043
|
+
private _apiUrl;
|
|
661
1044
|
private conn;
|
|
662
1045
|
private context;
|
|
663
1046
|
private debugEnabled;
|
|
@@ -702,6 +1085,8 @@ export declare class Schematic {
|
|
|
702
1085
|
private flagCheckDefaults;
|
|
703
1086
|
private fallbackCheckCache;
|
|
704
1087
|
constructor(apiKey: string, options?: SchematicOptions);
|
|
1088
|
+
get apiUrl(): string;
|
|
1089
|
+
get additionalHeaders(): Record<string, string>;
|
|
705
1090
|
/**
|
|
706
1091
|
* Resolve fallback value according to priority order:
|
|
707
1092
|
* 1. Callsite fallback value (if provided)
|
|
@@ -914,6 +1299,27 @@ export declare class Schematic {
|
|
|
914
1299
|
private notifyCreditBalanceListeners;
|
|
915
1300
|
}
|
|
916
1301
|
|
|
1302
|
+
declare class SchematicApiError extends Error {
|
|
1303
|
+
readonly status: number;
|
|
1304
|
+
readonly path: string;
|
|
1305
|
+
readonly body: unknown;
|
|
1306
|
+
constructor(status: number, path: string, body: unknown);
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
declare class SchematicBillingClient implements BillingClient {
|
|
1310
|
+
/**
|
|
1311
|
+
* Public so a second client over the same surface can be constructed on
|
|
1312
|
+
* this one rather than minting tokens of its own.
|
|
1313
|
+
*/
|
|
1314
|
+
readonly session: SchematicSession;
|
|
1315
|
+
constructor(options?: BillingClientOptions | SchematicSession);
|
|
1316
|
+
get sessionKey(): string | undefined;
|
|
1317
|
+
get sessionStatus(): SessionStatus;
|
|
1318
|
+
setSession(session: SessionInput): void;
|
|
1319
|
+
onSessionChange(listener: (event: SessionEvent) => void): () => void;
|
|
1320
|
+
fetchInvoices(params: InvoicesRequest): Promise<InvoicesResult>;
|
|
1321
|
+
}
|
|
1322
|
+
|
|
917
1323
|
/** Context for checking flags and sending events */
|
|
918
1324
|
export declare type SchematicContext = {
|
|
919
1325
|
company?: Keys;
|
|
@@ -936,12 +1342,53 @@ export declare interface SchematicHookOpts {
|
|
|
936
1342
|
client?: SchematicJS.Schematic;
|
|
937
1343
|
}
|
|
938
1344
|
|
|
1345
|
+
export declare interface SchematicI18nConfig {
|
|
1346
|
+
/** BCP 47 tag the elements format in; defaults to the runtime's locale. */
|
|
1347
|
+
locale?: string;
|
|
1348
|
+
/** Routes element copy to the host's i18n stack — pass i18next's `t`. */
|
|
1349
|
+
translate?: Translate;
|
|
1350
|
+
/**
|
|
1351
|
+
* Copy by key, for a host renaming strings rather than translating them.
|
|
1352
|
+
* Wins over `translate`; an element's own `strings` prop wins over both.
|
|
1353
|
+
*/
|
|
1354
|
+
strings?: StringOverrides;
|
|
1355
|
+
/** Reports a mis-wired catalogue that would otherwise look correct. */
|
|
1356
|
+
onMissingString?: (key: string) => void;
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
export declare const SchematicI18nContext: React_2.Context<SchematicI18nConfig>;
|
|
1360
|
+
|
|
1361
|
+
/**
|
|
1362
|
+
* `SchematicProvider` renders one of these, so most hosts never name it.
|
|
1363
|
+
* Nesting merges rather than replaces: a provider setting only `locale`
|
|
1364
|
+
* keeps the translator above it, and `strings` layers key by key.
|
|
1365
|
+
*/
|
|
1366
|
+
export declare function SchematicI18nProvider({ children, locale, onMissingString, strings, translate, }: SchematicI18nProviderProps): React_2.JSX.Element;
|
|
1367
|
+
|
|
1368
|
+
export declare interface SchematicI18nProviderProps extends SchematicI18nConfig {
|
|
1369
|
+
children?: React_2.ReactNode;
|
|
1370
|
+
}
|
|
1371
|
+
|
|
939
1372
|
declare namespace SchematicJS {
|
|
940
1373
|
export {
|
|
941
1374
|
CheckFlagResponseFromJSON,
|
|
942
1375
|
CheckFlagsResponseFromJSON,
|
|
943
1376
|
DatastreamCompanyPlanFromJSON,
|
|
944
1377
|
EventBodyFlagCheckToJSON,
|
|
1378
|
+
fetchBillingData,
|
|
1379
|
+
normalizeInvoiceQuery_2 as normalizeInvoiceQuery,
|
|
1380
|
+
sessionKey,
|
|
1381
|
+
AccessToken,
|
|
1382
|
+
AccessTokenProvider,
|
|
1383
|
+
AccessTokenResult,
|
|
1384
|
+
billingApi,
|
|
1385
|
+
BillingClient,
|
|
1386
|
+
BillingClientOptions,
|
|
1387
|
+
BillingData,
|
|
1388
|
+
BillingPrefetchOptions,
|
|
1389
|
+
BillingResourceName,
|
|
1390
|
+
BillingResourceParams,
|
|
1391
|
+
BillingResources,
|
|
945
1392
|
BooleanListenerFn,
|
|
946
1393
|
CheckFlagResponseData,
|
|
947
1394
|
CheckFlagReturn,
|
|
@@ -952,11 +1399,13 @@ declare namespace SchematicJS {
|
|
|
952
1399
|
CheckPlanReturnFromJSON,
|
|
953
1400
|
CheckPlanReturnListenerFn,
|
|
954
1401
|
CompanyCreditBalance,
|
|
1402
|
+
CompanyInvoiceResponseData,
|
|
955
1403
|
CreditBalance,
|
|
956
1404
|
CreditBalanceListenerFn,
|
|
957
1405
|
CreditBalances,
|
|
958
1406
|
CreditBalancesFromJSON,
|
|
959
1407
|
CreditBalancesListenerFn,
|
|
1408
|
+
DEFAULT_INVOICE_QUERY,
|
|
960
1409
|
EmptyListenerFn,
|
|
961
1410
|
Event_2 as Event,
|
|
962
1411
|
EventBody,
|
|
@@ -966,14 +1415,33 @@ declare namespace SchematicJS {
|
|
|
966
1415
|
EventType,
|
|
967
1416
|
FlagCheckListenerFn,
|
|
968
1417
|
FlagValueListenerFn,
|
|
1418
|
+
Invoice,
|
|
1419
|
+
INVOICE_MAX_PAGE_SIZE,
|
|
1420
|
+
INVOICE_PAGE_SIZE,
|
|
1421
|
+
InvoicePage,
|
|
1422
|
+
InvoiceQuery,
|
|
1423
|
+
InvoicesRequest,
|
|
1424
|
+
InvoicesResult,
|
|
1425
|
+
InvoiceStatus,
|
|
969
1426
|
Keys,
|
|
970
1427
|
PendingListenerFn,
|
|
971
1428
|
PlanListenerFn,
|
|
1429
|
+
RequestOptions,
|
|
1430
|
+
ResourceState,
|
|
972
1431
|
RuleType,
|
|
973
1432
|
Schematic,
|
|
1433
|
+
SchematicApiError,
|
|
1434
|
+
SchematicBillingClient,
|
|
974
1435
|
SchematicContext,
|
|
975
1436
|
SchematicOptions,
|
|
1437
|
+
SchematicSession,
|
|
1438
|
+
Session,
|
|
1439
|
+
SessionEvent,
|
|
1440
|
+
SessionInput,
|
|
1441
|
+
SessionOptions,
|
|
1442
|
+
SessionStatus,
|
|
976
1443
|
StoragePersister,
|
|
1444
|
+
TOKEN_CACHE_SIZE,
|
|
977
1445
|
Traits,
|
|
978
1446
|
TrialStatus,
|
|
979
1447
|
UsagePeriod
|
|
@@ -1044,6 +1512,111 @@ declare type SchematicProviderPropsWithPublishableKey = BaseSchematicProviderPro
|
|
|
1044
1512
|
publishableKey: string;
|
|
1045
1513
|
};
|
|
1046
1514
|
|
|
1515
|
+
/**
|
|
1516
|
+
* Session identity is the (company, user) pair alone: a freshly minted token,
|
|
1517
|
+
* a rebuilt provider closure, and a refresh this session asked for itself are
|
|
1518
|
+
* all the same session. Nothing in a token says who it was minted for, so
|
|
1519
|
+
* that question is the host's to answer.
|
|
1520
|
+
*
|
|
1521
|
+
* Credentials survive a change of session, keyed by pair — switching back to
|
|
1522
|
+
* a company reads with the token already in hand. They do not survive the
|
|
1523
|
+
* session ending: after a sign-out the next person at this page is somebody
|
|
1524
|
+
* else, and nothing minted for the last one is theirs to send.
|
|
1525
|
+
*/
|
|
1526
|
+
declare class SchematicSession {
|
|
1527
|
+
private readonly _apiUrl;
|
|
1528
|
+
private readonly _headers;
|
|
1529
|
+
private readonly _fetch;
|
|
1530
|
+
private _session;
|
|
1531
|
+
private readonly _tokens;
|
|
1532
|
+
private readonly _resolving;
|
|
1533
|
+
/**
|
|
1534
|
+
* Bumped when the session's identity changes, and only then — the object
|
|
1535
|
+
* itself is replaced on every render. Anything asking "is this still the
|
|
1536
|
+
* session I started under?" counts generations rather than comparing.
|
|
1537
|
+
*/
|
|
1538
|
+
private _generation;
|
|
1539
|
+
private readonly _listeners;
|
|
1540
|
+
constructor(options?: SessionOptions);
|
|
1541
|
+
get key(): string | undefined;
|
|
1542
|
+
get status(): SessionStatus;
|
|
1543
|
+
/** Only a statement that changes which pair is read counts as a change. */
|
|
1544
|
+
set(session: SessionInput): void;
|
|
1545
|
+
onChange(listener: (event: SessionEvent) => void): () => void;
|
|
1546
|
+
private _emit;
|
|
1547
|
+
private _cached;
|
|
1548
|
+
private _cache;
|
|
1549
|
+
/**
|
|
1550
|
+
* The credential for a session, minted if this one is not held. `force`
|
|
1551
|
+
* retires what is held first: the caller is a request the API has just
|
|
1552
|
+
* rejected.
|
|
1553
|
+
*/
|
|
1554
|
+
resolveToken(session: Session, force: boolean): Promise<string>;
|
|
1555
|
+
/**
|
|
1556
|
+
* Sends a request under the active session's credential, refreshing once
|
|
1557
|
+
* and retrying if the API rejects it. Rejects rather than answering when
|
|
1558
|
+
* the session changes while the request is in flight: the rows would
|
|
1559
|
+
* otherwise come back as the answer to a question asked for another pair.
|
|
1560
|
+
*/
|
|
1561
|
+
request(path: string, options?: RequestOptions): Promise<unknown>;
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
/**
|
|
1565
|
+
* Who is being read. Users and companies are many-to-many: the same person
|
|
1566
|
+
* reads one company's billing and then another's, and the same company is
|
|
1567
|
+
* read by several people. A token is minted for the pair, so the pair — not
|
|
1568
|
+
* the company alone — is the session's identity.
|
|
1569
|
+
*/
|
|
1570
|
+
export declare interface Session {
|
|
1571
|
+
/** The host's name for the company, its id in their own system say. */
|
|
1572
|
+
company: string;
|
|
1573
|
+
/**
|
|
1574
|
+
* The user, where the host mints per (company, user). Left out by a host
|
|
1575
|
+
* whose tokens are company-wide, and then every reader of that company
|
|
1576
|
+
* shares one session.
|
|
1577
|
+
*/
|
|
1578
|
+
user?: string;
|
|
1579
|
+
token: AccessToken;
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
/**
|
|
1583
|
+
* What happened to the session, for anything holding data that belongs to
|
|
1584
|
+
* one. `started`: whatever is loaded belongs to the new session — a prefetch
|
|
1585
|
+
* the host seeded before its auth resolved. `changed`: another pair is being
|
|
1586
|
+
* read, and what is loaded belongs to the pair being left. `ended`: nobody is
|
|
1587
|
+
* signed in, and what is loaded belongs to nobody.
|
|
1588
|
+
*/
|
|
1589
|
+
export declare type SessionEvent = {
|
|
1590
|
+
type: "started" | "changed" | "ended";
|
|
1591
|
+
};
|
|
1592
|
+
|
|
1593
|
+
/**
|
|
1594
|
+
* Three states that are not interchangeable:
|
|
1595
|
+
*
|
|
1596
|
+
* * `Session` — active: this pair, read with this credential.
|
|
1597
|
+
* * `null` — ended: nobody is signed in; what is loaded is dropped.
|
|
1598
|
+
* * `undefined` — pending: the host's auth has not resolved. It states
|
|
1599
|
+
* nothing, so the session in hand stands.
|
|
1600
|
+
*/
|
|
1601
|
+
export declare type SessionInput = Session | null | undefined;
|
|
1602
|
+
|
|
1603
|
+
/**
|
|
1604
|
+
* The pair as one string, for anything that has to compare sessions or key
|
|
1605
|
+
* something by one — a prefetch stating which session it was fetched for, a
|
|
1606
|
+
* store keeping a page per session. Opaque: read it only by equality.
|
|
1607
|
+
*/
|
|
1608
|
+
declare function sessionKey(session: Session): string;
|
|
1609
|
+
|
|
1610
|
+
declare interface SessionOptions {
|
|
1611
|
+
session?: SessionInput;
|
|
1612
|
+
apiUrl?: string;
|
|
1613
|
+
additionalHeaders?: Record<string, string>;
|
|
1614
|
+
/** Override for tests and non-browser runtimes. */
|
|
1615
|
+
fetch?: typeof fetch;
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
export declare type SessionStatus = "pending" | "active" | "ended";
|
|
1619
|
+
|
|
1047
1620
|
/** Optional type for implementing custom client-side storage */
|
|
1048
1621
|
export declare type StoragePersister = {
|
|
1049
1622
|
setItem(key: string, value: any): void;
|
|
@@ -1051,11 +1624,44 @@ export declare type StoragePersister = {
|
|
|
1051
1624
|
removeItem(key: string): void;
|
|
1052
1625
|
};
|
|
1053
1626
|
|
|
1627
|
+
/** Copy overrides by key. Keys are the element package's `StringKey`s. */
|
|
1628
|
+
export declare type StringOverrides = Record<string, string | undefined>;
|
|
1629
|
+
|
|
1630
|
+
/**
|
|
1631
|
+
* Sessions whose credentials are kept. A reader switching between the
|
|
1632
|
+
* organizations they belong to walks a handful of them and comes back, and
|
|
1633
|
+
* re-minting on every step is a round trip to the host's token endpoint for
|
|
1634
|
+
* a token this client already holds and has not seen expire. The same
|
|
1635
|
+
* handful the flag cache bounds its contexts at.
|
|
1636
|
+
*/
|
|
1637
|
+
declare const TOKEN_CACHE_SIZE = 10;
|
|
1638
|
+
|
|
1054
1639
|
/**
|
|
1055
1640
|
* A flexible key/value type that can store any type of value on a company or user.
|
|
1056
1641
|
*/
|
|
1057
1642
|
export declare type Traits = Record<string, any>;
|
|
1058
1643
|
|
|
1644
|
+
/**
|
|
1645
|
+
* Locale and copy live in their own context, not on the billing data source:
|
|
1646
|
+
* a host's `t` changes identity whenever its language does, and a source
|
|
1647
|
+
* rebuilt for that takes its cached snapshots with it, leaving
|
|
1648
|
+
* `useSyncExternalStore` a new handle every render.
|
|
1649
|
+
*
|
|
1650
|
+
* Nothing here interprets a key — the element package owns the key list and
|
|
1651
|
+
* the English copy.
|
|
1652
|
+
*/
|
|
1653
|
+
/**
|
|
1654
|
+
* Shaped like i18next's `t` so `translate={t}` is the whole integration.
|
|
1655
|
+
* `vars` reaches it as the options object, which is what lets `{ count }`
|
|
1656
|
+
* resolve a language's plural forms in the host's own stack rather than in
|
|
1657
|
+
* ours.
|
|
1658
|
+
*
|
|
1659
|
+
* Returning `undefined` means "no translation" and the caller falls back to
|
|
1660
|
+
* its English default. Elements also pass a sentinel `defaultValue`, so a stack
|
|
1661
|
+
* that answers every key with something still reports a real miss.
|
|
1662
|
+
*/
|
|
1663
|
+
export declare type Translate = (key: string, vars?: Record<string, unknown>) => string | undefined;
|
|
1664
|
+
|
|
1059
1665
|
/**
|
|
1060
1666
|
*
|
|
1061
1667
|
* @export
|
|
@@ -1075,6 +1681,17 @@ export declare enum UsagePeriod {
|
|
|
1075
1681
|
CURRENT_WEEK = "current_week"
|
|
1076
1682
|
}
|
|
1077
1683
|
|
|
1684
|
+
export declare function useBillingDataSource(): BillingDataSource;
|
|
1685
|
+
|
|
1686
|
+
/** Reloads every loaded billing resource (after a plan change, for instance). */
|
|
1687
|
+
export declare function useInvalidateBillingData(): () => void;
|
|
1688
|
+
|
|
1689
|
+
/**
|
|
1690
|
+
* The invoice list for `query`. Each distinct query is its own list with its
|
|
1691
|
+
* own paging; an inline object literal is fine, the hook keys by value.
|
|
1692
|
+
*/
|
|
1693
|
+
export declare function useInvoices(query?: InvoiceQuery): InvoicesHandle;
|
|
1694
|
+
|
|
1078
1695
|
export declare const useSchematic: () => SchematicContextProps;
|
|
1079
1696
|
|
|
1080
1697
|
export declare const useSchematicContext: (opts?: SchematicHookOpts) => {
|
|
@@ -1088,8 +1705,13 @@ export declare const useSchematicContext: (opts?: SchematicHookOpts) => {
|
|
|
1088
1705
|
* `credit_balances` map (keyed by credit ID). It re-renders as partials arrive
|
|
1089
1706
|
* over the DataStream, so it stays accurate during an open lease — when the raw
|
|
1090
1707
|
* `remaining` would otherwise read stale / falsely "exhausted".
|
|
1708
|
+
*
|
|
1709
|
+
* `creditId` accepts `undefined` so it can be fed straight from an
|
|
1710
|
+
* entitlement's `creditId`, which is undefined until the check arrives and for
|
|
1711
|
+
* features that are not credit-based. While the ID is undefined the hook
|
|
1712
|
+
* reports the client's loading state and a balance of 0.
|
|
1091
1713
|
*/
|
|
1092
|
-
export declare const useSchematicCreditBalance: (creditId: string, opts?: SchematicHookOpts) => SchematicCreditBalance;
|
|
1714
|
+
export declare const useSchematicCreditBalance: (creditId: string | undefined, opts?: SchematicHookOpts) => SchematicCreditBalance;
|
|
1093
1715
|
|
|
1094
1716
|
export declare const useSchematicEntitlement: (key: string, opts?: UseSchematicFlagOpts) => SchematicJS.CheckFlagReturn;
|
|
1095
1717
|
|
|
@@ -1104,12 +1726,53 @@ export declare type UseSchematicFlagOpts = SchematicHookOpts & {
|
|
|
1104
1726
|
fallback?: boolean;
|
|
1105
1727
|
};
|
|
1106
1728
|
|
|
1729
|
+
/** Empty, never undefined, outside a provider. */
|
|
1730
|
+
export declare function useSchematicI18n(): SchematicI18nConfig;
|
|
1731
|
+
|
|
1107
1732
|
export declare const useSchematicIsPending: (opts?: SchematicHookOpts) => boolean;
|
|
1108
1733
|
|
|
1734
|
+
/** Unresolved: elements call `useResolvedLocale`, which applies the fallback. */
|
|
1735
|
+
export declare function useSchematicLocale(): string | undefined;
|
|
1736
|
+
|
|
1109
1737
|
export declare const useSchematicPlan: (opts?: UseSchematicPlanOpts) => SchematicJS.CheckPlanReturn | undefined;
|
|
1110
1738
|
|
|
1111
1739
|
export declare type UseSchematicPlanOpts = SchematicHookOpts & {
|
|
1112
1740
|
fallback?: SchematicJS.CheckPlanReturn;
|
|
1113
1741
|
};
|
|
1114
1742
|
|
|
1743
|
+
export declare function useSchematicStrings(): StringOverrides | undefined;
|
|
1744
|
+
|
|
1745
|
+
export declare function useSchematicTranslate(): Translate | undefined;
|
|
1746
|
+
|
|
1747
|
+
/**
|
|
1748
|
+
* Schematic API
|
|
1749
|
+
* Schematic API
|
|
1750
|
+
*
|
|
1751
|
+
* The version of the OpenAPI document: 0.1
|
|
1752
|
+
*
|
|
1753
|
+
*
|
|
1754
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
1755
|
+
* https://openapi-generator.tech
|
|
1756
|
+
* Do not edit the class manually.
|
|
1757
|
+
*/
|
|
1758
|
+
/**
|
|
1759
|
+
*
|
|
1760
|
+
* @export
|
|
1761
|
+
* @interface WarningTier
|
|
1762
|
+
*/
|
|
1763
|
+
declare interface WarningTier {
|
|
1764
|
+
/**
|
|
1765
|
+
* A customer-defined identifier for the warning tier
|
|
1766
|
+
* @type {string}
|
|
1767
|
+
* @memberof WarningTier
|
|
1768
|
+
*/
|
|
1769
|
+
key: string;
|
|
1770
|
+
/**
|
|
1771
|
+
* The warning threshold, in the entitlement's usage units
|
|
1772
|
+
* @type {number}
|
|
1773
|
+
* @memberof WarningTier
|
|
1774
|
+
*/
|
|
1775
|
+
value: number;
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1115
1778
|
export { }
|