@schematichq/schematic-react 1.7.0 → 1.8.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.
@@ -36,6 +36,7 @@ __export(index_exports, {
36
36
  INVOICE_PAGE_SIZE: () => INVOICE_PAGE_SIZE,
37
37
  InvoiceStatus: () => InvoiceStatus,
38
38
  RuleType: () => RuleType,
39
+ SINGLETON: () => SINGLETON,
39
40
  Schematic: () => Schematic,
40
41
  SchematicI18nContext: () => SchematicI18nContext,
41
42
  SchematicI18nProvider: () => SchematicI18nProvider,
@@ -57,7 +58,8 @@ __export(index_exports, {
57
58
  useSchematicLocale: () => useSchematicLocale,
58
59
  useSchematicPlan: () => useSchematicPlan,
59
60
  useSchematicStrings: () => useSchematicStrings,
60
- useSchematicTranslate: () => useSchematicTranslate
61
+ useSchematicTranslate: () => useSchematicTranslate,
62
+ useUpcomingInvoice: () => useUpcomingInvoice
61
63
  });
62
64
  module.exports = __toCommonJS(index_exports);
63
65
 
@@ -1210,6 +1212,7 @@ function contextString(context) {
1210
1212
  return JSON.stringify(sortedContext);
1211
1213
  }
1212
1214
  var version = "1.8.0";
1215
+ var SINGLETON = {};
1213
1216
  var models_exports = {};
1214
1217
  __export2(models_exports, {
1215
1218
  ApiErrorFromJSON: () => ApiErrorFromJSON,
@@ -3996,33 +3999,40 @@ var BillingStore = class {
3996
3999
  constructor(_client, initialData = {}, options = {}) {
3997
4000
  this._client = _client;
3998
4001
  this._pageSize = options.pageSize ?? INVOICE_PAGE_SIZE;
4002
+ const readiness = () => this._connected ? READINESS[this._client.sessionStatus] : "waiting";
3999
4003
  this.invoices = new KeyedResource(
4000
4004
  (query, current) => this._reloadWindow(
4001
4005
  query,
4002
4006
  Math.max(this._pageSize, current?.invoices.length ?? 0)
4003
4007
  ),
4004
- // Waiting until connected; then a session still pending stays
4005
- // pending, and one that has ended settles empty rather than recording
4006
- // the client's refusal as an error.
4007
- {
4008
- readiness: () => this._connected ? READINESS[this._client.sessionStatus] : "waiting"
4009
- }
4008
+ { readiness }
4010
4009
  );
4010
+ this.upcomingInvoice = new KeyedResource(
4011
+ () => this._client.fetchUpcomingInvoice(),
4012
+ { readiness }
4013
+ );
4014
+ const held = { key: initialData.sessionKey };
4011
4015
  if (initialData.invoices !== void 0) {
4012
- this._held = {
4016
+ held.invoices = {
4013
4017
  // Normalized the way the hook normalizes, or the caller asking for
4014
4018
  // it fetches the same page again.
4015
4019
  params: normalizeInvoiceQuery2(
4016
4020
  initialData.params?.invoices ?? DEFAULT_INVOICE_QUERY
4017
4021
  ),
4018
- data: initialData.invoices,
4019
- key: initialData.sessionKey
4022
+ data: initialData.invoices
4020
4023
  };
4024
+ }
4025
+ if (initialData.upcomingInvoice !== void 0) {
4026
+ held.upcomingInvoice = initialData.upcomingInvoice;
4027
+ }
4028
+ if (held.invoices !== void 0 || held.upcomingInvoice !== void 0) {
4029
+ this._held = held;
4021
4030
  this._settleSeed(claimFrom(options.session) ?? claimOf(this._client));
4022
4031
  }
4023
4032
  }
4024
4033
  _client;
4025
4034
  invoices;
4035
+ upcomingInvoice;
4026
4036
  _pageSize;
4027
4037
  _unsubscribe;
4028
4038
  _connected = false;
@@ -4092,7 +4102,12 @@ var BillingStore = class {
4092
4102
  }
4093
4103
  this._held = void 0;
4094
4104
  if (verdict === "adopt") {
4095
- this.invoices.seed(held.params, held.data);
4105
+ if (held.invoices !== void 0) {
4106
+ this.invoices.seed(held.invoices.params, held.invoices.data);
4107
+ }
4108
+ if (held.upcomingInvoice !== void 0) {
4109
+ this.upcomingInvoice.seed(SINGLETON, held.upcomingInvoice);
4110
+ }
4096
4111
  this._seedKey = held.key;
4097
4112
  this._seeded = true;
4098
4113
  }
@@ -4194,7 +4209,10 @@ var BillingStore = class {
4194
4209
  return this._client.fetchInvoices({ ...query, limit, offset });
4195
4210
  }
4196
4211
  };
4197
- var RESOURCE_NAMES = ["invoices"];
4212
+ var RESOURCE_NAMES = [
4213
+ "invoices",
4214
+ "upcomingInvoice"
4215
+ ];
4198
4216
 
4199
4217
  // src/billing/context.tsx
4200
4218
  var import_react2 = require("react");
@@ -4345,6 +4363,9 @@ function useInvoices(query = DEFAULT_INVOICE_QUERY) {
4345
4363
  );
4346
4364
  return (0, import_react3.useMemo)(() => ({ ...handle, loadMore }), [handle, loadMore]);
4347
4365
  }
4366
+ function useUpcomingInvoice() {
4367
+ return useBillingResource("upcomingInvoice", SINGLETON);
4368
+ }
4348
4369
  function useInvalidateBillingData() {
4349
4370
  return useBillingDataSource().invalidateAll;
4350
4371
  }
@@ -4464,7 +4485,7 @@ function staticSource(data) {
4464
4485
  }
4465
4486
 
4466
4487
  // src/version.ts
4467
- var version2 = "1.7.0";
4488
+ var version2 = "1.8.0";
4468
4489
 
4469
4490
  // src/context/schematic.tsx
4470
4491
  var import_jsx_runtime4 = require("react/jsx-runtime");
@@ -127,9 +127,9 @@ declare type BillingClientOptions = SessionOptions;
127
127
  * non-default query is claimed rather than refetched by the element.
128
128
  */
129
129
  export declare type BillingData = {
130
- [K in BillingResourceName]?: BillingResources[K];
130
+ [K in BillingResourceName_2]?: BillingResources_2[K];
131
131
  } & {
132
- params?: Partial<BillingResourceParams>;
132
+ params?: Partial<BillingResourceParams_2>;
133
133
  /**
134
134
  * A prefetch outlives the render that made it — a cached page, a session
135
135
  * resolving to somebody else — so a store adopts it only for the session
@@ -145,7 +145,7 @@ declare interface BillingDataProviderDataProps {
145
145
  data: BillingData;
146
146
  /** Simulated loading / failure per resource; wins over `data`. */
147
147
  status?: BillingDataStatus;
148
- onRefetch?: (name: BillingResourceName_2) => void;
148
+ onRefetch?: (name: BillingResourceName) => void;
149
149
  onLoadMoreInvoices?: (query: InvoiceQuery) => void;
150
150
  children?: React_2.ReactNode;
151
151
  }
@@ -166,8 +166,8 @@ export declare interface BillingDataSource {
166
166
  * Sources that hold one value per resource (fixtures, prefetch) serve it
167
167
  * for every parameter set.
168
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]>;
169
+ subscribe<K extends BillingResourceName>(name: K, params: BillingResourceParams[K], listener: () => void): () => void;
170
+ handle<K extends BillingResourceName>(name: K, params: BillingResourceParams[K]): ResourceHandle<BillingResources[K]>;
171
171
  /** Never rejects: a failure lands on the resource's `error`. */
172
172
  loadMoreInvoices: (query: InvoiceQuery) => Promise<void>;
173
173
  invalidateAll: () => void;
@@ -175,7 +175,7 @@ export declare interface BillingDataSource {
175
175
 
176
176
  /** Per-resource status overrides, for fixtures that simulate loading and failure. */
177
177
  export declare type BillingDataStatus = {
178
- [K in BillingResourceName_2]?: {
178
+ [K in BillingResourceName]?: {
179
179
  isPending?: boolean;
180
180
  error?: Error;
181
181
  };
@@ -188,7 +188,7 @@ declare interface BillingPrefetchOptions {
188
188
  * the list grows with every element, so a page names what it needs rather
189
189
  * than paying for everything.
190
190
  */
191
- names: BillingResourceName[];
191
+ names: BillingResourceName_2[];
192
192
  /** The invoice query to prefetch for; the element must ask the same one. */
193
193
  invoices?: InvoiceQuery;
194
194
  }
@@ -206,7 +206,7 @@ export declare function BillingProvider({ billingClient, children, initialData,
206
206
  * much. Named apart from schematic-js's `BillingClient`, which is the whole
207
207
  * interface; this is the part the hooks here call.
208
208
  */
209
- export declare type BillingProviderClient = Pick<BillingClient, "sessionStatus" | "sessionKey" | "setSession" | "onSessionChange" | "fetchInvoices">;
209
+ export declare type BillingProviderClient = Pick<BillingClient, "sessionStatus" | "sessionKey" | "setSession" | "onSessionChange" | "fetchInvoices" | "fetchUpcomingInvoice">;
210
210
 
211
211
  declare interface BillingProviderDataProps {
212
212
  /**
@@ -245,18 +245,20 @@ declare interface BillingProviderDataProps {
245
245
  */
246
246
  export declare type BillingProviderProps = BillingProviderDataProps & SchematicI18nConfig;
247
247
 
248
- declare type BillingResourceName = keyof BillingResources;
249
-
250
248
  /** The resources this package serves; a key of schematic-js's contract. */
251
- declare type BillingResourceName_2 = "invoices";
249
+ export declare type BillingResourceName = "invoices" | "upcomingInvoice";
250
+
251
+ declare type BillingResourceName_2 = keyof BillingResources_2;
252
+
253
+ export declare type BillingResourceParams = Pick<BillingResourceParams_2, BillingResourceName>;
252
254
 
253
255
  /** `Record<string, never>` marks a singleton; anything else is keyed. */
254
- declare interface BillingResourceParams {
256
+ declare interface BillingResourceParams_2 {
255
257
  invoices: InvoiceQuery;
256
258
  upcomingInvoice: Record<string, never>;
257
259
  }
258
260
 
259
- declare type BillingResourceParams_2 = Pick<BillingResourceParams, BillingResourceName_2>;
261
+ export declare type BillingResources = Pick<BillingResources_2, BillingResourceName>;
260
262
 
261
263
  /**
262
264
  * Nothing in the store, the hooks, or the resource keys may be addressed by
@@ -265,7 +267,7 @@ declare type BillingResourceParams_2 = Pick<BillingResourceParams, BillingResour
265
267
  * pair, as `sessionKey` writes it — and a store that keeps more than one
266
268
  * session's data keys it by that and serves only the active one.
267
269
  */
268
- declare interface BillingResources {
270
+ declare interface BillingResources_2 {
269
271
  /** `GET /company/invoices?limit&offset&include_pending`. */
270
272
  invoices: InvoicePage;
271
273
  /**
@@ -276,8 +278,6 @@ declare interface BillingResources {
276
278
  upcomingInvoice: UpcomingInvoice | null;
277
279
  }
278
280
 
279
- declare type BillingResources_2 = Pick<BillingResources, BillingResourceName_2>;
280
-
281
281
  declare type BooleanListenerFn = (value: boolean) => void;
282
282
 
283
283
  /**
@@ -774,7 +774,7 @@ declare function DatastreamCompanyPlanFromJSON(json: any): DatastreamCompanyPlan
774
774
 
775
775
  export declare const DEFAULT_INVOICE_QUERY: InvoiceQuery;
776
776
 
777
- declare type Discount = CompanyDiscountResponseData;
777
+ export declare type Discount = CompanyDiscountResponseData;
778
778
 
779
779
  declare type EmptyListenerFn = () => void;
780
780
 
@@ -1559,9 +1559,9 @@ declare namespace SchematicJS {
1559
1559
  BillingClientOptions,
1560
1560
  BillingData,
1561
1561
  BillingPrefetchOptions,
1562
- BillingResourceName,
1563
- BillingResourceParams,
1564
- BillingResources,
1562
+ BillingResourceName_2 as BillingResourceName,
1563
+ BillingResourceParams_2 as BillingResourceParams,
1564
+ BillingResources_2 as BillingResources,
1565
1565
  BooleanListenerFn,
1566
1566
  CheckFlagResponseData,
1567
1567
  CheckFlagReturn,
@@ -1797,7 +1797,7 @@ declare interface SessionOptions {
1797
1797
  export declare type SessionStatus = "pending" | "active" | "ended";
1798
1798
 
1799
1799
  /** The params of every singleton resource. */
1800
- declare const SINGLETON: Record<string, never>;
1800
+ export declare const SINGLETON: Record<string, never>;
1801
1801
 
1802
1802
  /** Optional type for implementing custom client-side storage */
1803
1803
  export declare type StoragePersister = {
@@ -1856,7 +1856,7 @@ export declare const TrialStatus: {
1856
1856
 
1857
1857
  export declare type TrialStatus = (typeof TrialStatus)[keyof typeof TrialStatus];
1858
1858
 
1859
- declare type UpcomingInvoice = CompanyUpcomingInvoiceResponseData;
1859
+ export declare type UpcomingInvoice = CompanyUpcomingInvoiceResponseData;
1860
1860
 
1861
1861
  export declare enum UsagePeriod {
1862
1862
  ALL_TIME = "all_time",
@@ -1928,6 +1928,13 @@ export declare function useSchematicStrings(): StringOverrides | undefined;
1928
1928
 
1929
1929
  export declare function useSchematicTranslate(): Translate | undefined;
1930
1930
 
1931
+ /**
1932
+ * The company's next bill. `data` is `null` when there is nothing to bill —
1933
+ * no subscription, which the endpoint reports as a 204 — so an element can
1934
+ * render an empty state; `data === undefined` is what means not loaded yet.
1935
+ */
1936
+ export declare function useUpcomingInvoice(): ResourceHandle<UpcomingInvoice | null>;
1937
+
1931
1938
  /**
1932
1939
  * Schematic API
1933
1940
  * Schematic API
@@ -1147,6 +1147,7 @@ function contextString(context) {
1147
1147
  return JSON.stringify(sortedContext);
1148
1148
  }
1149
1149
  var version = "1.8.0";
1150
+ var SINGLETON = {};
1150
1151
  var models_exports = {};
1151
1152
  __export(models_exports, {
1152
1153
  ApiErrorFromJSON: () => ApiErrorFromJSON,
@@ -3933,33 +3934,40 @@ var BillingStore = class {
3933
3934
  constructor(_client, initialData = {}, options = {}) {
3934
3935
  this._client = _client;
3935
3936
  this._pageSize = options.pageSize ?? INVOICE_PAGE_SIZE;
3937
+ const readiness = () => this._connected ? READINESS[this._client.sessionStatus] : "waiting";
3936
3938
  this.invoices = new KeyedResource(
3937
3939
  (query, current) => this._reloadWindow(
3938
3940
  query,
3939
3941
  Math.max(this._pageSize, current?.invoices.length ?? 0)
3940
3942
  ),
3941
- // Waiting until connected; then a session still pending stays
3942
- // pending, and one that has ended settles empty rather than recording
3943
- // the client's refusal as an error.
3944
- {
3945
- readiness: () => this._connected ? READINESS[this._client.sessionStatus] : "waiting"
3946
- }
3943
+ { readiness }
3947
3944
  );
3945
+ this.upcomingInvoice = new KeyedResource(
3946
+ () => this._client.fetchUpcomingInvoice(),
3947
+ { readiness }
3948
+ );
3949
+ const held = { key: initialData.sessionKey };
3948
3950
  if (initialData.invoices !== void 0) {
3949
- this._held = {
3951
+ held.invoices = {
3950
3952
  // Normalized the way the hook normalizes, or the caller asking for
3951
3953
  // it fetches the same page again.
3952
3954
  params: normalizeInvoiceQuery2(
3953
3955
  initialData.params?.invoices ?? DEFAULT_INVOICE_QUERY
3954
3956
  ),
3955
- data: initialData.invoices,
3956
- key: initialData.sessionKey
3957
+ data: initialData.invoices
3957
3958
  };
3959
+ }
3960
+ if (initialData.upcomingInvoice !== void 0) {
3961
+ held.upcomingInvoice = initialData.upcomingInvoice;
3962
+ }
3963
+ if (held.invoices !== void 0 || held.upcomingInvoice !== void 0) {
3964
+ this._held = held;
3958
3965
  this._settleSeed(claimFrom(options.session) ?? claimOf(this._client));
3959
3966
  }
3960
3967
  }
3961
3968
  _client;
3962
3969
  invoices;
3970
+ upcomingInvoice;
3963
3971
  _pageSize;
3964
3972
  _unsubscribe;
3965
3973
  _connected = false;
@@ -4029,7 +4037,12 @@ var BillingStore = class {
4029
4037
  }
4030
4038
  this._held = void 0;
4031
4039
  if (verdict === "adopt") {
4032
- this.invoices.seed(held.params, held.data);
4040
+ if (held.invoices !== void 0) {
4041
+ this.invoices.seed(held.invoices.params, held.invoices.data);
4042
+ }
4043
+ if (held.upcomingInvoice !== void 0) {
4044
+ this.upcomingInvoice.seed(SINGLETON, held.upcomingInvoice);
4045
+ }
4033
4046
  this._seedKey = held.key;
4034
4047
  this._seeded = true;
4035
4048
  }
@@ -4131,7 +4144,10 @@ var BillingStore = class {
4131
4144
  return this._client.fetchInvoices({ ...query, limit, offset });
4132
4145
  }
4133
4146
  };
4134
- var RESOURCE_NAMES = ["invoices"];
4147
+ var RESOURCE_NAMES = [
4148
+ "invoices",
4149
+ "upcomingInvoice"
4150
+ ];
4135
4151
 
4136
4152
  // src/billing/context.tsx
4137
4153
  import { createContext as createContext2, useContext as useContext2, useMemo as useMemo2 } from "react";
@@ -4282,6 +4298,9 @@ function useInvoices(query = DEFAULT_INVOICE_QUERY) {
4282
4298
  );
4283
4299
  return useMemo3(() => ({ ...handle, loadMore }), [handle, loadMore]);
4284
4300
  }
4301
+ function useUpcomingInvoice() {
4302
+ return useBillingResource("upcomingInvoice", SINGLETON);
4303
+ }
4285
4304
  function useInvalidateBillingData() {
4286
4305
  return useBillingDataSource().invalidateAll;
4287
4306
  }
@@ -4401,7 +4420,7 @@ function staticSource(data) {
4401
4420
  }
4402
4421
 
4403
4422
  // src/version.ts
4404
- var version2 = "1.7.0";
4423
+ var version2 = "1.8.0";
4405
4424
 
4406
4425
  // src/context/schematic.tsx
4407
4426
  import { jsx as jsx4 } from "react/jsx-runtime";
@@ -4625,6 +4644,7 @@ export {
4625
4644
  INVOICE_PAGE_SIZE,
4626
4645
  InvoiceStatus,
4627
4646
  RuleType,
4647
+ SINGLETON,
4628
4648
  Schematic,
4629
4649
  SchematicI18nContext,
4630
4650
  SchematicI18nProvider,
@@ -4646,7 +4666,8 @@ export {
4646
4666
  useSchematicLocale,
4647
4667
  useSchematicPlan,
4648
4668
  useSchematicStrings,
4649
- useSchematicTranslate
4669
+ useSchematicTranslate,
4670
+ useUpcomingInvoice
4650
4671
  };
4651
4672
  /*! Bundled license information:
4652
4673
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schematichq/schematic-react",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "main": "dist/schematic-react.cjs.js",
5
5
  "module": "dist/schematic-react.esm.js",
6
6
  "types": "dist/schematic-react.d.ts",