@schematichq/schematic-react 1.16.0 → 1.16.1

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.
@@ -82,7 +82,7 @@ __export(index_exports, {
82
82
  });
83
83
  module.exports = __toCommonJS(index_exports);
84
84
 
85
- // node_modules/.pnpm/@schematichq+schematic-js@1.16.0/node_modules/@schematichq/schematic-js/dist/schematic.esm.js
85
+ // node_modules/.pnpm/@schematichq+schematic-js@1.16.1/node_modules/@schematichq/schematic-js/dist/schematic.esm.js
86
86
  var __create2 = Object.create;
87
87
  var __defProp2 = Object.defineProperty;
88
88
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
@@ -1413,7 +1413,7 @@ var ContextSignatureManager = class {
1413
1413
  }
1414
1414
  }
1415
1415
  };
1416
- var version = "1.16.0";
1416
+ var version = "1.16.1";
1417
1417
  var DEFAULT_CATALOG_QUERY = {};
1418
1418
  function normalizeCatalogQuery(query) {
1419
1419
  return query.catalogId === void 0 ? {} : { catalogId: query.catalogId };
@@ -7659,6 +7659,8 @@ var CheckoutDraft = class {
7659
7659
  /** Bumped by reset, so an answer for a discarded draft lands nowhere. */
7660
7660
  generation = 0;
7661
7661
  inFlight;
7662
+ /** The read of a resumed checkout, while one is out. */
7663
+ loading;
7662
7664
  queued;
7663
7665
  constructor(transport, options = {}) {
7664
7666
  this.transport = transport;
@@ -7684,10 +7686,19 @@ var CheckoutDraft = class {
7684
7686
  }
7685
7687
  /**
7686
7688
  * Reads the checkout this draft was opened on, for a resume. A draft with
7687
- * no checkout yet has nothing to read.
7689
+ * no checkout yet has nothing to read. A call while a read is out shares
7690
+ * its answer.
7688
7691
  */
7689
7692
  load() {
7690
- return this.refresh(this.generation);
7693
+ if (this.loading === void 0) {
7694
+ const generation = this.generation;
7695
+ this.loading = this.refresh(generation).finally(() => {
7696
+ if (generation === this.generation) {
7697
+ this.loading = void 0;
7698
+ }
7699
+ });
7700
+ }
7701
+ return this.loading;
7691
7702
  }
7692
7703
  /**
7693
7704
  * Replaces the cart and re-prices it. Resolves with the checkout the write
@@ -7720,11 +7731,12 @@ var CheckoutDraft = class {
7720
7731
  if (generation !== this.generation) {
7721
7732
  throw new Error("The checkout was reset before it was finalized.");
7722
7733
  }
7723
- if (this.checkoutId === void 0 || this.version === void 0) {
7734
+ if (this.checkoutId === void 0) {
7724
7735
  throw new Error("There is no checkout to finalize yet.");
7725
7736
  }
7726
7737
  this.update({ isFinalizing: true, error: void 0 });
7727
7738
  try {
7739
+ await this.readResumed(generation);
7728
7740
  const result = await this.finalizeOnce(generation, true);
7729
7741
  if (generation === this.generation) {
7730
7742
  this.update({ isFinalizing: false, result });
@@ -7752,6 +7764,7 @@ var CheckoutDraft = class {
7752
7764
  const queued = this.queued;
7753
7765
  this.queued = void 0;
7754
7766
  this.inFlight = void 0;
7767
+ this.loading = void 0;
7755
7768
  queued?.waiters.forEach((w) => w.resolve(void 0));
7756
7769
  this.update({ ...INITIAL_STATE });
7757
7770
  }
@@ -7801,6 +7814,7 @@ var CheckoutDraft = class {
7801
7814
  });
7802
7815
  }
7803
7816
  async write(generation, selections) {
7817
+ await this.readResumed(generation);
7804
7818
  let written;
7805
7819
  if (this.checkoutId === void 0 || this.version === void 0) {
7806
7820
  written = await this.transport.createCheckout(selections);
@@ -7862,6 +7876,20 @@ var CheckoutDraft = class {
7862
7876
  return this.finalizeOnce(generation, false);
7863
7877
  }
7864
7878
  }
7879
+ /**
7880
+ * A resumed checkout is read before it is written or finalized: a write
7881
+ * ahead of the read would open a second checkout beside it, and the read's
7882
+ * answer would then point the draft back at the first.
7883
+ */
7884
+ async readResumed(generation) {
7885
+ if (this.checkoutId === void 0 || this.version !== void 0) {
7886
+ return;
7887
+ }
7888
+ await this.load();
7889
+ if (generation !== this.generation) {
7890
+ throw new Error("The checkout was reset before it was read.");
7891
+ }
7892
+ }
7865
7893
  async refresh(generation) {
7866
7894
  if (this.checkoutId === void 0) {
7867
7895
  return void 0;
@@ -11401,7 +11429,7 @@ function staticSource(data) {
11401
11429
  }
11402
11430
 
11403
11431
  // src/version.ts
11404
- var version2 = "1.16.0";
11432
+ var version2 = "1.16.1";
11405
11433
 
11406
11434
  // src/context/schematic.tsx
11407
11435
  var import_jsx_runtime4 = require("react/jsx-runtime");
@@ -2763,6 +2763,8 @@ export declare class CheckoutDraft {
2763
2763
  /** Bumped by reset, so an answer for a discarded draft lands nowhere. */
2764
2764
  private generation;
2765
2765
  private inFlight;
2766
+ /** The read of a resumed checkout, while one is out. */
2767
+ private loading;
2766
2768
  private queued;
2767
2769
  constructor(transport: CheckoutTransport, options?: CheckoutDraftOptions);
2768
2770
  /**
@@ -2774,7 +2776,8 @@ export declare class CheckoutDraft {
2774
2776
  subscribe(listener: () => void): () => void;
2775
2777
  /**
2776
2778
  * Reads the checkout this draft was opened on, for a resume. A draft with
2777
- * no checkout yet has nothing to read.
2779
+ * no checkout yet has nothing to read. A call while a read is out shares
2780
+ * its answer.
2778
2781
  */
2779
2782
  load(): Promise<Checkout | undefined>;
2780
2783
  /**
@@ -2802,13 +2805,22 @@ export declare class CheckoutDraft {
2802
2805
  */
2803
2806
  private updateWithReplay;
2804
2807
  private finalizeOnce;
2808
+ /**
2809
+ * A resumed checkout is read before it is written or finalized: a write
2810
+ * ahead of the read would open a second checkout beside it, and the read's
2811
+ * answer would then point the draft back at the first.
2812
+ */
2813
+ private readResumed;
2805
2814
  private refresh;
2806
2815
  private adopt;
2807
2816
  private update;
2808
2817
  }
2809
2818
 
2810
2819
  declare interface CheckoutDraftOptions {
2811
- /** Resume this checkout rather than opening one on the first write. */
2820
+ /**
2821
+ * Resume this checkout rather than opening one on the first write. The
2822
+ * draft reads it before the first write or finalize.
2823
+ */
2812
2824
  checkoutId?: string;
2813
2825
  }
2814
2826
 
@@ -1,4 +1,4 @@
1
- // node_modules/.pnpm/@schematichq+schematic-js@1.16.0/node_modules/@schematichq/schematic-js/dist/schematic.esm.js
1
+ // node_modules/.pnpm/@schematichq+schematic-js@1.16.1/node_modules/@schematichq/schematic-js/dist/schematic.esm.js
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1329,7 +1329,7 @@ var ContextSignatureManager = class {
1329
1329
  }
1330
1330
  }
1331
1331
  };
1332
- var version = "1.16.0";
1332
+ var version = "1.16.1";
1333
1333
  var DEFAULT_CATALOG_QUERY = {};
1334
1334
  function normalizeCatalogQuery(query) {
1335
1335
  return query.catalogId === void 0 ? {} : { catalogId: query.catalogId };
@@ -7575,6 +7575,8 @@ var CheckoutDraft = class {
7575
7575
  /** Bumped by reset, so an answer for a discarded draft lands nowhere. */
7576
7576
  generation = 0;
7577
7577
  inFlight;
7578
+ /** The read of a resumed checkout, while one is out. */
7579
+ loading;
7578
7580
  queued;
7579
7581
  constructor(transport, options = {}) {
7580
7582
  this.transport = transport;
@@ -7600,10 +7602,19 @@ var CheckoutDraft = class {
7600
7602
  }
7601
7603
  /**
7602
7604
  * Reads the checkout this draft was opened on, for a resume. A draft with
7603
- * no checkout yet has nothing to read.
7605
+ * no checkout yet has nothing to read. A call while a read is out shares
7606
+ * its answer.
7604
7607
  */
7605
7608
  load() {
7606
- return this.refresh(this.generation);
7609
+ if (this.loading === void 0) {
7610
+ const generation = this.generation;
7611
+ this.loading = this.refresh(generation).finally(() => {
7612
+ if (generation === this.generation) {
7613
+ this.loading = void 0;
7614
+ }
7615
+ });
7616
+ }
7617
+ return this.loading;
7607
7618
  }
7608
7619
  /**
7609
7620
  * Replaces the cart and re-prices it. Resolves with the checkout the write
@@ -7636,11 +7647,12 @@ var CheckoutDraft = class {
7636
7647
  if (generation !== this.generation) {
7637
7648
  throw new Error("The checkout was reset before it was finalized.");
7638
7649
  }
7639
- if (this.checkoutId === void 0 || this.version === void 0) {
7650
+ if (this.checkoutId === void 0) {
7640
7651
  throw new Error("There is no checkout to finalize yet.");
7641
7652
  }
7642
7653
  this.update({ isFinalizing: true, error: void 0 });
7643
7654
  try {
7655
+ await this.readResumed(generation);
7644
7656
  const result = await this.finalizeOnce(generation, true);
7645
7657
  if (generation === this.generation) {
7646
7658
  this.update({ isFinalizing: false, result });
@@ -7668,6 +7680,7 @@ var CheckoutDraft = class {
7668
7680
  const queued = this.queued;
7669
7681
  this.queued = void 0;
7670
7682
  this.inFlight = void 0;
7683
+ this.loading = void 0;
7671
7684
  queued?.waiters.forEach((w) => w.resolve(void 0));
7672
7685
  this.update({ ...INITIAL_STATE });
7673
7686
  }
@@ -7717,6 +7730,7 @@ var CheckoutDraft = class {
7717
7730
  });
7718
7731
  }
7719
7732
  async write(generation, selections) {
7733
+ await this.readResumed(generation);
7720
7734
  let written;
7721
7735
  if (this.checkoutId === void 0 || this.version === void 0) {
7722
7736
  written = await this.transport.createCheckout(selections);
@@ -7778,6 +7792,20 @@ var CheckoutDraft = class {
7778
7792
  return this.finalizeOnce(generation, false);
7779
7793
  }
7780
7794
  }
7795
+ /**
7796
+ * A resumed checkout is read before it is written or finalized: a write
7797
+ * ahead of the read would open a second checkout beside it, and the read's
7798
+ * answer would then point the draft back at the first.
7799
+ */
7800
+ async readResumed(generation) {
7801
+ if (this.checkoutId === void 0 || this.version !== void 0) {
7802
+ return;
7803
+ }
7804
+ await this.load();
7805
+ if (generation !== this.generation) {
7806
+ throw new Error("The checkout was reset before it was read.");
7807
+ }
7808
+ }
7781
7809
  async refresh(generation) {
7782
7810
  if (this.checkoutId === void 0) {
7783
7811
  return void 0;
@@ -11324,7 +11352,7 @@ function staticSource(data) {
11324
11352
  }
11325
11353
 
11326
11354
  // src/version.ts
11327
- var version2 = "1.16.0";
11355
+ var version2 = "1.16.1";
11328
11356
 
11329
11357
  // src/context/schematic.tsx
11330
11358
  import { jsx as jsx4 } from "react/jsx-runtime";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schematichq/schematic-react",
3
- "version": "1.16.0",
3
+ "version": "1.16.1",
4
4
  "main": "dist/schematic-react.cjs.js",
5
5
  "module": "dist/schematic-react.esm.js",
6
6
  "types": "dist/schematic-react.d.ts",
@@ -34,7 +34,7 @@
34
34
  "devDependencies": {
35
35
  "@eslint/js": "^10.0.1",
36
36
  "@microsoft/api-extractor": "^7.59.4",
37
- "@schematichq/schematic-js": "^1.16.0",
37
+ "@schematichq/schematic-js": "^1.16.1",
38
38
  "@testing-library/dom": "^10.4.2",
39
39
  "@testing-library/jest-dom": "^7.0.1",
40
40
  "@testing-library/react": "^16.3.3",
@@ -46,7 +46,7 @@
46
46
  "eslint-plugin-react": "^7.37.5",
47
47
  "eslint-plugin-react-hooks": "^7.1.1",
48
48
  "globals": "^17.13.0",
49
- "happy-dom": "^20.14.6",
49
+ "happy-dom": "^21.0.4",
50
50
  "husky": "^9.1.7",
51
51
  "jsdom": "^30.1.2",
52
52
  "prettier": "^3.9.9",