brainerce 1.37.0 → 1.37.3

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 CHANGED
@@ -2050,37 +2050,41 @@ const checkout = await client.createCheckout({
2050
2050
  ```
2051
2051
 
2052
2052
  > The region is recorded on the checkout and used for payment-provider scoping.
2053
- > Currency continues to follow the cart until FX price conversion lands, so
2054
- > passing a `regionId` does not re-price the cart.
2053
+ > **FX-at-checkout:** when the region currency differs from the store base and its
2054
+ > provider can settle it (presentment-enabled — Stripe today), the buyer is charged
2055
+ > in the region currency and the checkout response carries a `presentment` overlay
2056
+ > (`presentment.total` / `presentment.currency` = what's charged). Otherwise the
2057
+ > checkout is charged in the store base currency.
2055
2058
 
2056
2059
  #### Region display pricing (`getProducts({ regionId })`)
2057
2060
 
2058
- Product reads accept an optional `regionId`. When set, each product/variant that
2059
- a region [price list](#price-lists) resolves gains additive fields —
2060
- `resolvedPrice`, `resolvedCurrency`, `resolvedCompareAtPrice`, and `priceSource`
2061
- (`'variant-entry'` | `'product-entry'`). Your existing `basePrice` / `salePrice`
2062
- stay in the store currency; the fields appear **only** when a region entry
2063
- actually applies, so an omitted/invalid region (or a catalog-price fallback)
2064
- leaves the response byte-identical.
2061
+ All three product reads accept an optional `regionId` `getProducts`,
2062
+ `getProduct(id)`, **and** `getProductBySlug(slug)` (the PDP path). When set and the
2063
+ region's currency differs from the store currency, each product/variant gains
2064
+ additive FX-display fields `displayPrice`, `displaySalePrice`, and
2065
+ `displayCurrency` (plus `displayPriceMin` / `displayPriceMax` on storefront-mode
2066
+ list reads). Your `basePrice` / `salePrice` stay in the store currency; the
2067
+ display fields appear **only** when an FX rate applies, so an omitted/invalid
2068
+ region or a same-currency region leaves the response byte-identical.
2065
2069
 
2066
2070
  ```typescript
2067
2071
  const { data: products } = await client.getProducts({ regionId: 'region_eu' });
2068
2072
  const p = products[0];
2069
- const display = p.resolvedPrice
2070
- ? `${p.resolvedPrice} ${p.resolvedCurrency}` // e.g. "27.00 EUR"
2071
- : p.basePrice; // store-currency catalog price
2073
+ const display = p.displayPrice
2074
+ ? `${p.displayPrice} ${p.displayCurrency}` // e.g. "27.00 EUR"
2075
+ : p.basePrice; // store-currency price (no FX rate / same currency)
2072
2076
 
2073
- // Single product (id or slug) takes the same option:
2077
+ // Single product by id OR slug takes the same option:
2074
2078
  await client.getProduct('prod_tshirt', { regionId: 'region_eu' });
2079
+ await client.getProductBySlug('blue-shirt', { regionId: 'region_eu' });
2075
2080
  ```
2076
2081
 
2077
2082
  > **Display-only** — like checkout, `regionId` here does not charge the region
2078
- > price; it only changes what you render until currency-lock ships. **Mode note:**
2079
- > the additive FX display overlay (`displayPrice` / `displayCurrency`, see
2080
- > [Regions](/docs/concepts/regions)) now applies in vibe-coded
2081
- > (`vc_*`/`salesChannelId`) mode too previously it was populated on storefront
2082
- > (`storeId`) and admin (`apiKey`) reads only. Pass `regionId` and the response
2083
- > gains `displayPrice` whenever a daily FX rate exists for the store→region pair.
2083
+ > currency; it only changes what you render until currency-lock ships. Works in
2084
+ > **all three modes** vibe-coded (`vc_*`/`salesChannelId`), storefront (`storeId`),
2085
+ > and admin (`apiKey`). The response gains `displayPrice` whenever a daily FX rate
2086
+ > exists for the store/region currency pair in **either** direction (the overlay
2087
+ > inverts the stored rate when needed). See [Regions](/docs/concepts/regions).
2084
2088
 
2085
2089
  #### Partial Checkout (AliExpress-style)
2086
2090
 
@@ -3637,8 +3641,10 @@ const { region: resolved } = await store.getAutoRegion('DE'); // server-side, on
3637
3641
 
3638
3642
  > **Multi-region checkout:** pass a `regionId` to `createCheckout` to associate the
3639
3643
  > checkout with a region (for reporting + payment-provider scoping). The region
3640
- > must belong to the store. Currency still follows the cart until FX price
3641
- > conversion lands. See the Checkout section.
3644
+ > must belong to the store. **FX-at-checkout:** presentment-enabled regions
3645
+ > (Stripe today) charge in the region currency and return a `presentment` overlay;
3646
+ > otherwise the checkout is charged in the store base currency. See the Checkout
3647
+ > section.
3642
3648
 
3643
3649
  ### Price Lists (per-region pricing)
3644
3650
 
package/dist/index.d.mts CHANGED
@@ -2507,8 +2507,11 @@ interface Checkout {
2507
2507
  currency: string;
2508
2508
  /**
2509
2509
  * Region this checkout is associated with (multi-region commerce), or null.
2510
- * Recorded for reporting + provider scoping; currency follows the cart until
2511
- * FX price conversion lands.
2510
+ * Recorded for reporting + provider scoping. FX-at-checkout: when the region
2511
+ * currency differs from the store base and its provider can settle it
2512
+ * (presentment-enabled — Stripe today), the buyer is charged in the region
2513
+ * currency and the `presentment` overlay below carries the charged amounts;
2514
+ * otherwise the checkout is charged in the store base currency.
2512
2515
  */
2513
2516
  regionId?: string | null;
2514
2517
  /** Subtotal as string - use parseFloat() */
@@ -2560,6 +2563,41 @@ interface Checkout {
2560
2563
  * @see ReservationInfo
2561
2564
  */
2562
2565
  reservation?: ReservationInfo;
2566
+ /**
2567
+ * FX-at-checkout presentment overlay. Present ONLY when the checkout's region
2568
+ * uses a different currency from the store base AND that region charges in its
2569
+ * own currency (presentment). These are the amounts the buyer will actually be
2570
+ * CHARGED, in `presentment.currency` — `presentment.total` equals the payment
2571
+ * intent amount to the cent. Render these (not the base `total`/`currency`
2572
+ * above) when present. Absent = the checkout is charged in the store base
2573
+ * currency (the fields above are authoritative).
2574
+ *
2575
+ * @example
2576
+ * const c = await client.getCheckout(id);
2577
+ * const shown = c.presentment
2578
+ * ? formatPrice(c.presentment.total, { currency: c.presentment.currency })
2579
+ * : formatPrice(c.total, { currency: c.currency });
2580
+ */
2581
+ presentment?: {
2582
+ /** ISO-4217 currency the buyer is charged in (e.g. "EUR"). */
2583
+ currency: string;
2584
+ /** Subtotal in the presentment currency as string - use parseFloat(). */
2585
+ subtotal: string;
2586
+ /** Discount amount in the presentment currency as string. */
2587
+ discountAmount: string;
2588
+ /** Shipping cost in the presentment currency as string. */
2589
+ shippingAmount: string;
2590
+ /** Tax amount in the presentment currency as string. */
2591
+ taxAmount: string;
2592
+ /** Surcharge amount in the presentment currency as string. */
2593
+ surchargeAmount: string;
2594
+ /** Grand total in the presentment currency — equals the charged amount. */
2595
+ total: string;
2596
+ /** Base→presentment rate applied (buffer included), as string. */
2597
+ fxChargingRate: string;
2598
+ /** FX buffer percent applied to the mid-market rate, as string (or null). */
2599
+ fxBufferPercent: string | null;
2600
+ };
2563
2601
  }
2564
2602
  /**
2565
2603
  * Options for creating a checkout from a cart.
@@ -5493,6 +5531,7 @@ declare class BrainerceClient {
5493
5531
  */
5494
5532
  getProductBySlug(slug: string, options?: {
5495
5533
  locale?: string;
5534
+ regionId?: string;
5496
5535
  }): Promise<Product>;
5497
5536
  /**
5498
5537
  * Get available categories for filtering products
package/dist/index.d.ts CHANGED
@@ -2507,8 +2507,11 @@ interface Checkout {
2507
2507
  currency: string;
2508
2508
  /**
2509
2509
  * Region this checkout is associated with (multi-region commerce), or null.
2510
- * Recorded for reporting + provider scoping; currency follows the cart until
2511
- * FX price conversion lands.
2510
+ * Recorded for reporting + provider scoping. FX-at-checkout: when the region
2511
+ * currency differs from the store base and its provider can settle it
2512
+ * (presentment-enabled — Stripe today), the buyer is charged in the region
2513
+ * currency and the `presentment` overlay below carries the charged amounts;
2514
+ * otherwise the checkout is charged in the store base currency.
2512
2515
  */
2513
2516
  regionId?: string | null;
2514
2517
  /** Subtotal as string - use parseFloat() */
@@ -2560,6 +2563,41 @@ interface Checkout {
2560
2563
  * @see ReservationInfo
2561
2564
  */
2562
2565
  reservation?: ReservationInfo;
2566
+ /**
2567
+ * FX-at-checkout presentment overlay. Present ONLY when the checkout's region
2568
+ * uses a different currency from the store base AND that region charges in its
2569
+ * own currency (presentment). These are the amounts the buyer will actually be
2570
+ * CHARGED, in `presentment.currency` — `presentment.total` equals the payment
2571
+ * intent amount to the cent. Render these (not the base `total`/`currency`
2572
+ * above) when present. Absent = the checkout is charged in the store base
2573
+ * currency (the fields above are authoritative).
2574
+ *
2575
+ * @example
2576
+ * const c = await client.getCheckout(id);
2577
+ * const shown = c.presentment
2578
+ * ? formatPrice(c.presentment.total, { currency: c.presentment.currency })
2579
+ * : formatPrice(c.total, { currency: c.currency });
2580
+ */
2581
+ presentment?: {
2582
+ /** ISO-4217 currency the buyer is charged in (e.g. "EUR"). */
2583
+ currency: string;
2584
+ /** Subtotal in the presentment currency as string - use parseFloat(). */
2585
+ subtotal: string;
2586
+ /** Discount amount in the presentment currency as string. */
2587
+ discountAmount: string;
2588
+ /** Shipping cost in the presentment currency as string. */
2589
+ shippingAmount: string;
2590
+ /** Tax amount in the presentment currency as string. */
2591
+ taxAmount: string;
2592
+ /** Surcharge amount in the presentment currency as string. */
2593
+ surchargeAmount: string;
2594
+ /** Grand total in the presentment currency — equals the charged amount. */
2595
+ total: string;
2596
+ /** Base→presentment rate applied (buffer included), as string. */
2597
+ fxChargingRate: string;
2598
+ /** FX buffer percent applied to the mid-market rate, as string (or null). */
2599
+ fxBufferPercent: string | null;
2600
+ };
2563
2601
  }
2564
2602
  /**
2565
2603
  * Options for creating a checkout from a cart.
@@ -5493,6 +5531,7 @@ declare class BrainerceClient {
5493
5531
  */
5494
5532
  getProductBySlug(slug: string, options?: {
5495
5533
  locale?: string;
5534
+ regionId?: string;
5496
5535
  }): Promise<Product>;
5497
5536
  /**
5498
5537
  * Get available categories for filtering products
package/dist/index.js CHANGED
@@ -1192,13 +1192,14 @@ var BrainerceClient = class {
1192
1192
  */
1193
1193
  async getProductBySlug(slug, options) {
1194
1194
  const headerOverrides = options?.locale ? { "Accept-Language": options.locale } : void 0;
1195
+ const queryParams = options?.regionId ? { regionId: options.regionId } : void 0;
1195
1196
  const encodedSlug = encodePathSegment(slug);
1196
1197
  if (this.isVibeCodedMode()) {
1197
1198
  return this.vibeCodedRequest(
1198
1199
  "GET",
1199
1200
  `/products/slug/${encodedSlug}`,
1200
1201
  void 0,
1201
- void 0,
1202
+ queryParams,
1202
1203
  headerOverrides
1203
1204
  );
1204
1205
  }
@@ -1207,11 +1208,16 @@ var BrainerceClient = class {
1207
1208
  "GET",
1208
1209
  `/products/slug/${encodedSlug}`,
1209
1210
  void 0,
1210
- void 0,
1211
+ queryParams,
1211
1212
  headerOverrides
1212
1213
  );
1213
1214
  }
1214
- return this.adminRequest("GET", `/api/v1/products/by-slug/${encodedSlug}`);
1215
+ return this.adminRequest(
1216
+ "GET",
1217
+ `/api/v1/products/by-slug/${encodedSlug}`,
1218
+ void 0,
1219
+ queryParams
1220
+ );
1215
1221
  }
1216
1222
  /**
1217
1223
  * Get available categories for filtering products
package/dist/index.mjs CHANGED
@@ -1122,13 +1122,14 @@ var BrainerceClient = class {
1122
1122
  */
1123
1123
  async getProductBySlug(slug, options) {
1124
1124
  const headerOverrides = options?.locale ? { "Accept-Language": options.locale } : void 0;
1125
+ const queryParams = options?.regionId ? { regionId: options.regionId } : void 0;
1125
1126
  const encodedSlug = encodePathSegment(slug);
1126
1127
  if (this.isVibeCodedMode()) {
1127
1128
  return this.vibeCodedRequest(
1128
1129
  "GET",
1129
1130
  `/products/slug/${encodedSlug}`,
1130
1131
  void 0,
1131
- void 0,
1132
+ queryParams,
1132
1133
  headerOverrides
1133
1134
  );
1134
1135
  }
@@ -1137,11 +1138,16 @@ var BrainerceClient = class {
1137
1138
  "GET",
1138
1139
  `/products/slug/${encodedSlug}`,
1139
1140
  void 0,
1140
- void 0,
1141
+ queryParams,
1141
1142
  headerOverrides
1142
1143
  );
1143
1144
  }
1144
- return this.adminRequest("GET", `/api/v1/products/by-slug/${encodedSlug}`);
1145
+ return this.adminRequest(
1146
+ "GET",
1147
+ `/api/v1/products/by-slug/${encodedSlug}`,
1148
+ void 0,
1149
+ queryParams
1150
+ );
1145
1151
  }
1146
1152
  /**
1147
1153
  * Get available categories for filtering products
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brainerce",
3
- "version": "1.37.0",
3
+ "version": "1.37.3",
4
4
  "description": "Official SDK for building e-commerce storefronts with Brainerce Platform. Perfect for vibe-coded sites, AI-built stores (Cursor, Lovable, v0), and custom storefronts.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",