brainerce 1.36.2 → 1.36.4
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 +2 -1
- package/dist/index.d.mts +52 -4
- package/dist/index.d.ts +52 -4
- package/dist/index.js +73 -4
- package/dist/index.mjs +73 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2206,7 +2206,8 @@ interface Checkout {
|
|
|
2206
2206
|
subtotal: string;
|
|
2207
2207
|
discountAmount: string;
|
|
2208
2208
|
shippingAmount: string;
|
|
2209
|
-
taxAmount: string;
|
|
2209
|
+
taxAmount: string; // "0" in inclusive (VAT) mode — see taxBreakdown.totalTax
|
|
2210
|
+
taxBreakdown?: TaxBreakdown | null; // { totalTax, pricesIncludeTax, breakdown[] }
|
|
2210
2211
|
total: string;
|
|
2211
2212
|
couponCode?: string | null;
|
|
2212
2213
|
items: CheckoutLineItem[];
|
package/dist/index.d.mts
CHANGED
|
@@ -1139,8 +1139,15 @@ interface Order {
|
|
|
1139
1139
|
}> | null;
|
|
1140
1140
|
/** Shipping cost */
|
|
1141
1141
|
shippingAmount?: string | null;
|
|
1142
|
-
/** Tax amount
|
|
1142
|
+
/** Tax amount. In inclusive (VAT) mode this is `"0"` — read the included VAT
|
|
1143
|
+
* from {@link Order.taxBreakdown}.totalTax instead. */
|
|
1143
1144
|
taxAmount?: string | null;
|
|
1145
|
+
/**
|
|
1146
|
+
* Frozen tax breakdown snapshot. In inclusive (VAT) pricing `taxAmount` is 0
|
|
1147
|
+
* and the real VAT lives here (`taxBreakdown.totalTax`, with
|
|
1148
|
+
* `pricesIncludeTax: true`). Use it to display "incl. VAT" on receipts.
|
|
1149
|
+
*/
|
|
1150
|
+
taxBreakdown?: TaxBreakdown | null;
|
|
1144
1151
|
createdAt: string;
|
|
1145
1152
|
/** Payment method used (e.g., "card", "paypal", "cash_on_delivery"). */
|
|
1146
1153
|
paymentMethod?: string | null;
|
|
@@ -2204,6 +2211,12 @@ interface TaxBreakdown {
|
|
|
2204
2211
|
total: number;
|
|
2205
2212
|
/** Itemized tax breakdown */
|
|
2206
2213
|
breakdown: TaxBreakdownItem[];
|
|
2214
|
+
/**
|
|
2215
|
+
* True when the store's prices already include tax (inclusive/VAT mode). In
|
|
2216
|
+
* that mode `totalTax` is the VAT backed out of the displayed price — it is
|
|
2217
|
+
* already part of `total`, not added on top. Display it as "incl. VAT".
|
|
2218
|
+
*/
|
|
2219
|
+
pricesIncludeTax?: boolean;
|
|
2207
2220
|
/** Currency code */
|
|
2208
2221
|
currency?: string;
|
|
2209
2222
|
}
|
|
@@ -5287,6 +5300,13 @@ declare class BrainerceClient {
|
|
|
5287
5300
|
private sessionToken;
|
|
5288
5301
|
private _sessionCartPromise;
|
|
5289
5302
|
private _migrationDone;
|
|
5303
|
+
/**
|
|
5304
|
+
* Cart id to adopt from an abandoned-checkout recovery redirect. brainerce's
|
|
5305
|
+
* recover endpoint 302s the shopper to `{storeDomain}/cart?brainerce_cart=<id>`;
|
|
5306
|
+
* we pick it up on construction and adopt it as the active cart on first access,
|
|
5307
|
+
* so the recovered cart shows up with zero per-store code.
|
|
5308
|
+
*/
|
|
5309
|
+
private _pendingRecoverCartId;
|
|
5290
5310
|
/** localStorage key for session cart reference (sessionToken + cartId) */
|
|
5291
5311
|
private readonly SESSION_CART_KEY;
|
|
5292
5312
|
/**
|
|
@@ -5582,8 +5602,12 @@ declare class BrainerceClient {
|
|
|
5582
5602
|
*/
|
|
5583
5603
|
convertToVariable(productId: string): Promise<Product>;
|
|
5584
5604
|
/**
|
|
5585
|
-
* Convert a VARIABLE product to SIMPLE
|
|
5586
|
-
*
|
|
5605
|
+
* Convert a VARIABLE product back to SIMPLE.
|
|
5606
|
+
*
|
|
5607
|
+
* The product must have **at most one variant**. That variant's price and
|
|
5608
|
+
* inventory are merged back into the parent product, then the variant row is
|
|
5609
|
+
* deleted. Throws `400` if more than one variant exists — delete the extras
|
|
5610
|
+
* first. Throws `400` if the product is already SIMPLE.
|
|
5587
5611
|
*
|
|
5588
5612
|
* @example
|
|
5589
5613
|
* ```typescript
|
|
@@ -5618,7 +5642,16 @@ declare class BrainerceClient {
|
|
|
5618
5642
|
*/
|
|
5619
5643
|
createVariant(productId: string, data: CreateVariantDto): Promise<ProductVariant>;
|
|
5620
5644
|
/**
|
|
5621
|
-
* Bulk save variants (create, update, delete in one operation)
|
|
5645
|
+
* Bulk save variants (create, update, delete in one atomic operation).
|
|
5646
|
+
*
|
|
5647
|
+
* **Auto-conversion:** if the product is currently `SIMPLE` and the payload
|
|
5648
|
+
* includes new variants (entries without an `id`), the product is
|
|
5649
|
+
* automatically converted to `VARIABLE` before the variants are created.
|
|
5650
|
+
* You do **not** need to call `convertToVariable` first.
|
|
5651
|
+
*
|
|
5652
|
+
* To delete a variant include its `id` and set `isDeleted: true`.
|
|
5653
|
+
* To update an existing variant supply its `id` with changed fields.
|
|
5654
|
+
* Entries without an `id` (or with an `id` prefixed `new-`) are created.
|
|
5622
5655
|
*
|
|
5623
5656
|
* @example
|
|
5624
5657
|
* ```typescript
|
|
@@ -7224,6 +7257,21 @@ declare class BrainerceClient {
|
|
|
7224
7257
|
* @internal
|
|
7225
7258
|
*/
|
|
7226
7259
|
private hydrateSessionCart;
|
|
7260
|
+
/**
|
|
7261
|
+
* Detect an abandoned-checkout recovery redirect. brainerce's recover endpoint
|
|
7262
|
+
* sends the shopper to `{storeDomain}/cart?brainerce_cart=<cartId>`; we stash
|
|
7263
|
+
* the id and adopt it (with its real session token) on the first cart access.
|
|
7264
|
+
* @internal
|
|
7265
|
+
*/
|
|
7266
|
+
private detectRecoverCartFromUrl;
|
|
7267
|
+
/**
|
|
7268
|
+
* Adopt a recovery-redirect cart if one is pending. Runs as the first step of
|
|
7269
|
+
* session-cart resolution so the recovered cart wins over any stale local
|
|
7270
|
+
* session. Returns the adopted cart, or null to fall through to normal
|
|
7271
|
+
* resolution (no pending id, or the cart is no longer recoverable).
|
|
7272
|
+
* @internal
|
|
7273
|
+
*/
|
|
7274
|
+
private adoptPendingRecoverCart;
|
|
7227
7275
|
/**
|
|
7228
7276
|
* Persist session cart reference to localStorage.
|
|
7229
7277
|
* @internal
|
package/dist/index.d.ts
CHANGED
|
@@ -1139,8 +1139,15 @@ interface Order {
|
|
|
1139
1139
|
}> | null;
|
|
1140
1140
|
/** Shipping cost */
|
|
1141
1141
|
shippingAmount?: string | null;
|
|
1142
|
-
/** Tax amount
|
|
1142
|
+
/** Tax amount. In inclusive (VAT) mode this is `"0"` — read the included VAT
|
|
1143
|
+
* from {@link Order.taxBreakdown}.totalTax instead. */
|
|
1143
1144
|
taxAmount?: string | null;
|
|
1145
|
+
/**
|
|
1146
|
+
* Frozen tax breakdown snapshot. In inclusive (VAT) pricing `taxAmount` is 0
|
|
1147
|
+
* and the real VAT lives here (`taxBreakdown.totalTax`, with
|
|
1148
|
+
* `pricesIncludeTax: true`). Use it to display "incl. VAT" on receipts.
|
|
1149
|
+
*/
|
|
1150
|
+
taxBreakdown?: TaxBreakdown | null;
|
|
1144
1151
|
createdAt: string;
|
|
1145
1152
|
/** Payment method used (e.g., "card", "paypal", "cash_on_delivery"). */
|
|
1146
1153
|
paymentMethod?: string | null;
|
|
@@ -2204,6 +2211,12 @@ interface TaxBreakdown {
|
|
|
2204
2211
|
total: number;
|
|
2205
2212
|
/** Itemized tax breakdown */
|
|
2206
2213
|
breakdown: TaxBreakdownItem[];
|
|
2214
|
+
/**
|
|
2215
|
+
* True when the store's prices already include tax (inclusive/VAT mode). In
|
|
2216
|
+
* that mode `totalTax` is the VAT backed out of the displayed price — it is
|
|
2217
|
+
* already part of `total`, not added on top. Display it as "incl. VAT".
|
|
2218
|
+
*/
|
|
2219
|
+
pricesIncludeTax?: boolean;
|
|
2207
2220
|
/** Currency code */
|
|
2208
2221
|
currency?: string;
|
|
2209
2222
|
}
|
|
@@ -5287,6 +5300,13 @@ declare class BrainerceClient {
|
|
|
5287
5300
|
private sessionToken;
|
|
5288
5301
|
private _sessionCartPromise;
|
|
5289
5302
|
private _migrationDone;
|
|
5303
|
+
/**
|
|
5304
|
+
* Cart id to adopt from an abandoned-checkout recovery redirect. brainerce's
|
|
5305
|
+
* recover endpoint 302s the shopper to `{storeDomain}/cart?brainerce_cart=<id>`;
|
|
5306
|
+
* we pick it up on construction and adopt it as the active cart on first access,
|
|
5307
|
+
* so the recovered cart shows up with zero per-store code.
|
|
5308
|
+
*/
|
|
5309
|
+
private _pendingRecoverCartId;
|
|
5290
5310
|
/** localStorage key for session cart reference (sessionToken + cartId) */
|
|
5291
5311
|
private readonly SESSION_CART_KEY;
|
|
5292
5312
|
/**
|
|
@@ -5582,8 +5602,12 @@ declare class BrainerceClient {
|
|
|
5582
5602
|
*/
|
|
5583
5603
|
convertToVariable(productId: string): Promise<Product>;
|
|
5584
5604
|
/**
|
|
5585
|
-
* Convert a VARIABLE product to SIMPLE
|
|
5586
|
-
*
|
|
5605
|
+
* Convert a VARIABLE product back to SIMPLE.
|
|
5606
|
+
*
|
|
5607
|
+
* The product must have **at most one variant**. That variant's price and
|
|
5608
|
+
* inventory are merged back into the parent product, then the variant row is
|
|
5609
|
+
* deleted. Throws `400` if more than one variant exists — delete the extras
|
|
5610
|
+
* first. Throws `400` if the product is already SIMPLE.
|
|
5587
5611
|
*
|
|
5588
5612
|
* @example
|
|
5589
5613
|
* ```typescript
|
|
@@ -5618,7 +5642,16 @@ declare class BrainerceClient {
|
|
|
5618
5642
|
*/
|
|
5619
5643
|
createVariant(productId: string, data: CreateVariantDto): Promise<ProductVariant>;
|
|
5620
5644
|
/**
|
|
5621
|
-
* Bulk save variants (create, update, delete in one operation)
|
|
5645
|
+
* Bulk save variants (create, update, delete in one atomic operation).
|
|
5646
|
+
*
|
|
5647
|
+
* **Auto-conversion:** if the product is currently `SIMPLE` and the payload
|
|
5648
|
+
* includes new variants (entries without an `id`), the product is
|
|
5649
|
+
* automatically converted to `VARIABLE` before the variants are created.
|
|
5650
|
+
* You do **not** need to call `convertToVariable` first.
|
|
5651
|
+
*
|
|
5652
|
+
* To delete a variant include its `id` and set `isDeleted: true`.
|
|
5653
|
+
* To update an existing variant supply its `id` with changed fields.
|
|
5654
|
+
* Entries without an `id` (or with an `id` prefixed `new-`) are created.
|
|
5622
5655
|
*
|
|
5623
5656
|
* @example
|
|
5624
5657
|
* ```typescript
|
|
@@ -7224,6 +7257,21 @@ declare class BrainerceClient {
|
|
|
7224
7257
|
* @internal
|
|
7225
7258
|
*/
|
|
7226
7259
|
private hydrateSessionCart;
|
|
7260
|
+
/**
|
|
7261
|
+
* Detect an abandoned-checkout recovery redirect. brainerce's recover endpoint
|
|
7262
|
+
* sends the shopper to `{storeDomain}/cart?brainerce_cart=<cartId>`; we stash
|
|
7263
|
+
* the id and adopt it (with its real session token) on the first cart access.
|
|
7264
|
+
* @internal
|
|
7265
|
+
*/
|
|
7266
|
+
private detectRecoverCartFromUrl;
|
|
7267
|
+
/**
|
|
7268
|
+
* Adopt a recovery-redirect cart if one is pending. Runs as the first step of
|
|
7269
|
+
* session-cart resolution so the recovered cart wins over any stale local
|
|
7270
|
+
* session. Returns the adopted cart, or null to fall through to normal
|
|
7271
|
+
* resolution (no pending id, or the cart is no longer recoverable).
|
|
7272
|
+
* @internal
|
|
7273
|
+
*/
|
|
7274
|
+
private adoptPendingRecoverCart;
|
|
7227
7275
|
/**
|
|
7228
7276
|
* Persist session cart reference to localStorage.
|
|
7229
7277
|
* @internal
|
package/dist/index.js
CHANGED
|
@@ -234,6 +234,13 @@ var BrainerceClient = class {
|
|
|
234
234
|
this.sessionToken = null;
|
|
235
235
|
this._sessionCartPromise = null;
|
|
236
236
|
this._migrationDone = false;
|
|
237
|
+
/**
|
|
238
|
+
* Cart id to adopt from an abandoned-checkout recovery redirect. brainerce's
|
|
239
|
+
* recover endpoint 302s the shopper to `{storeDomain}/cart?brainerce_cart=<id>`;
|
|
240
|
+
* we pick it up on construction and adopt it as the active cart on first access,
|
|
241
|
+
* so the recovered cart shows up with zero per-store code.
|
|
242
|
+
*/
|
|
243
|
+
this._pendingRecoverCartId = null;
|
|
237
244
|
/** localStorage key for session cart reference (sessionToken + cartId) */
|
|
238
245
|
this.SESSION_CART_KEY = "brainerce_session";
|
|
239
246
|
/**
|
|
@@ -648,6 +655,7 @@ var BrainerceClient = class {
|
|
|
648
655
|
this.proxyMode = options.proxyMode || false;
|
|
649
656
|
this.onAuthError = options.onAuthError;
|
|
650
657
|
this.hydrateSessionCart();
|
|
658
|
+
this.detectRecoverCartFromUrl();
|
|
651
659
|
}
|
|
652
660
|
// -------------------- Locale --------------------
|
|
653
661
|
/**
|
|
@@ -1379,8 +1387,12 @@ var BrainerceClient = class {
|
|
|
1379
1387
|
);
|
|
1380
1388
|
}
|
|
1381
1389
|
/**
|
|
1382
|
-
* Convert a VARIABLE product to SIMPLE
|
|
1383
|
-
*
|
|
1390
|
+
* Convert a VARIABLE product back to SIMPLE.
|
|
1391
|
+
*
|
|
1392
|
+
* The product must have **at most one variant**. That variant's price and
|
|
1393
|
+
* inventory are merged back into the parent product, then the variant row is
|
|
1394
|
+
* deleted. Throws `400` if more than one variant exists — delete the extras
|
|
1395
|
+
* first. Throws `400` if the product is already SIMPLE.
|
|
1384
1396
|
*
|
|
1385
1397
|
* @example
|
|
1386
1398
|
* ```typescript
|
|
@@ -1435,7 +1447,16 @@ var BrainerceClient = class {
|
|
|
1435
1447
|
);
|
|
1436
1448
|
}
|
|
1437
1449
|
/**
|
|
1438
|
-
* Bulk save variants (create, update, delete in one operation)
|
|
1450
|
+
* Bulk save variants (create, update, delete in one atomic operation).
|
|
1451
|
+
*
|
|
1452
|
+
* **Auto-conversion:** if the product is currently `SIMPLE` and the payload
|
|
1453
|
+
* includes new variants (entries without an `id`), the product is
|
|
1454
|
+
* automatically converted to `VARIABLE` before the variants are created.
|
|
1455
|
+
* You do **not** need to call `convertToVariable` first.
|
|
1456
|
+
*
|
|
1457
|
+
* To delete a variant include its `id` and set `isDeleted: true`.
|
|
1458
|
+
* To update an existing variant supply its `id` with changed fields.
|
|
1459
|
+
* Entries without an `id` (or with an `id` prefixed `new-`) are created.
|
|
1439
1460
|
*
|
|
1440
1461
|
* @example
|
|
1441
1462
|
* ```typescript
|
|
@@ -3953,6 +3974,48 @@ var BrainerceClient = class {
|
|
|
3953
3974
|
} catch {
|
|
3954
3975
|
}
|
|
3955
3976
|
}
|
|
3977
|
+
/**
|
|
3978
|
+
* Detect an abandoned-checkout recovery redirect. brainerce's recover endpoint
|
|
3979
|
+
* sends the shopper to `{storeDomain}/cart?brainerce_cart=<cartId>`; we stash
|
|
3980
|
+
* the id and adopt it (with its real session token) on the first cart access.
|
|
3981
|
+
* @internal
|
|
3982
|
+
*/
|
|
3983
|
+
detectRecoverCartFromUrl() {
|
|
3984
|
+
if (typeof window === "undefined" || !window.location?.search) return;
|
|
3985
|
+
try {
|
|
3986
|
+
const recoverId = new URLSearchParams(window.location.search).get("brainerce_cart");
|
|
3987
|
+
if (recoverId) this._pendingRecoverCartId = recoverId;
|
|
3988
|
+
} catch {
|
|
3989
|
+
}
|
|
3990
|
+
}
|
|
3991
|
+
/**
|
|
3992
|
+
* Adopt a recovery-redirect cart if one is pending. Runs as the first step of
|
|
3993
|
+
* session-cart resolution so the recovered cart wins over any stale local
|
|
3994
|
+
* session. Returns the adopted cart, or null to fall through to normal
|
|
3995
|
+
* resolution (no pending id, or the cart is no longer recoverable).
|
|
3996
|
+
* @internal
|
|
3997
|
+
*/
|
|
3998
|
+
async adoptPendingRecoverCart() {
|
|
3999
|
+
const recoverId = this._pendingRecoverCartId;
|
|
4000
|
+
if (!recoverId) return null;
|
|
4001
|
+
this._pendingRecoverCartId = null;
|
|
4002
|
+
try {
|
|
4003
|
+
const cart = await this.getCart(recoverId);
|
|
4004
|
+
if (cart.status !== "ACTIVE") return null;
|
|
4005
|
+
if (cart.sessionToken) {
|
|
4006
|
+
this.saveSessionCart({
|
|
4007
|
+
sessionToken: cart.sessionToken,
|
|
4008
|
+
cartId: cart.id,
|
|
4009
|
+
itemCount: cart.itemCount
|
|
4010
|
+
});
|
|
4011
|
+
} else {
|
|
4012
|
+
this.sessionCartId = cart.id;
|
|
4013
|
+
}
|
|
4014
|
+
return cart;
|
|
4015
|
+
} catch {
|
|
4016
|
+
return null;
|
|
4017
|
+
}
|
|
4018
|
+
}
|
|
3956
4019
|
/**
|
|
3957
4020
|
* Persist session cart reference to localStorage.
|
|
3958
4021
|
* @internal
|
|
@@ -4052,6 +4115,8 @@ var BrainerceClient = class {
|
|
|
4052
4115
|
}
|
|
4053
4116
|
/** @internal */
|
|
4054
4117
|
async _getOrCreateSessionCartImpl() {
|
|
4118
|
+
const recovered = await this.adoptPendingRecoverCart();
|
|
4119
|
+
if (recovered) return recovered;
|
|
4055
4120
|
const migrated = await this.migrateLocalCartToSession();
|
|
4056
4121
|
if (migrated) return migrated;
|
|
4057
4122
|
if (this.sessionCartId && this.sessionToken) {
|
|
@@ -4285,9 +4350,13 @@ var BrainerceClient = class {
|
|
|
4285
4350
|
*/
|
|
4286
4351
|
async smartGetCart(options) {
|
|
4287
4352
|
if (this.isCustomerLoggedIn()) {
|
|
4353
|
+
if (this._pendingRecoverCartId) {
|
|
4354
|
+
const recovered = await this.adoptPendingRecoverCart();
|
|
4355
|
+
if (recovered) return recovered;
|
|
4356
|
+
}
|
|
4288
4357
|
return this.getOrCreateCustomerCart(options);
|
|
4289
4358
|
} else {
|
|
4290
|
-
if (!this.sessionToken) {
|
|
4359
|
+
if (!this.sessionToken && !this._pendingRecoverCartId) {
|
|
4291
4360
|
return this.emptyCart();
|
|
4292
4361
|
}
|
|
4293
4362
|
return this.getOrCreateSessionCart(options);
|
package/dist/index.mjs
CHANGED
|
@@ -164,6 +164,13 @@ var BrainerceClient = class {
|
|
|
164
164
|
this.sessionToken = null;
|
|
165
165
|
this._sessionCartPromise = null;
|
|
166
166
|
this._migrationDone = false;
|
|
167
|
+
/**
|
|
168
|
+
* Cart id to adopt from an abandoned-checkout recovery redirect. brainerce's
|
|
169
|
+
* recover endpoint 302s the shopper to `{storeDomain}/cart?brainerce_cart=<id>`;
|
|
170
|
+
* we pick it up on construction and adopt it as the active cart on first access,
|
|
171
|
+
* so the recovered cart shows up with zero per-store code.
|
|
172
|
+
*/
|
|
173
|
+
this._pendingRecoverCartId = null;
|
|
167
174
|
/** localStorage key for session cart reference (sessionToken + cartId) */
|
|
168
175
|
this.SESSION_CART_KEY = "brainerce_session";
|
|
169
176
|
/**
|
|
@@ -578,6 +585,7 @@ var BrainerceClient = class {
|
|
|
578
585
|
this.proxyMode = options.proxyMode || false;
|
|
579
586
|
this.onAuthError = options.onAuthError;
|
|
580
587
|
this.hydrateSessionCart();
|
|
588
|
+
this.detectRecoverCartFromUrl();
|
|
581
589
|
}
|
|
582
590
|
// -------------------- Locale --------------------
|
|
583
591
|
/**
|
|
@@ -1309,8 +1317,12 @@ var BrainerceClient = class {
|
|
|
1309
1317
|
);
|
|
1310
1318
|
}
|
|
1311
1319
|
/**
|
|
1312
|
-
* Convert a VARIABLE product to SIMPLE
|
|
1313
|
-
*
|
|
1320
|
+
* Convert a VARIABLE product back to SIMPLE.
|
|
1321
|
+
*
|
|
1322
|
+
* The product must have **at most one variant**. That variant's price and
|
|
1323
|
+
* inventory are merged back into the parent product, then the variant row is
|
|
1324
|
+
* deleted. Throws `400` if more than one variant exists — delete the extras
|
|
1325
|
+
* first. Throws `400` if the product is already SIMPLE.
|
|
1314
1326
|
*
|
|
1315
1327
|
* @example
|
|
1316
1328
|
* ```typescript
|
|
@@ -1365,7 +1377,16 @@ var BrainerceClient = class {
|
|
|
1365
1377
|
);
|
|
1366
1378
|
}
|
|
1367
1379
|
/**
|
|
1368
|
-
* Bulk save variants (create, update, delete in one operation)
|
|
1380
|
+
* Bulk save variants (create, update, delete in one atomic operation).
|
|
1381
|
+
*
|
|
1382
|
+
* **Auto-conversion:** if the product is currently `SIMPLE` and the payload
|
|
1383
|
+
* includes new variants (entries without an `id`), the product is
|
|
1384
|
+
* automatically converted to `VARIABLE` before the variants are created.
|
|
1385
|
+
* You do **not** need to call `convertToVariable` first.
|
|
1386
|
+
*
|
|
1387
|
+
* To delete a variant include its `id` and set `isDeleted: true`.
|
|
1388
|
+
* To update an existing variant supply its `id` with changed fields.
|
|
1389
|
+
* Entries without an `id` (or with an `id` prefixed `new-`) are created.
|
|
1369
1390
|
*
|
|
1370
1391
|
* @example
|
|
1371
1392
|
* ```typescript
|
|
@@ -3883,6 +3904,48 @@ var BrainerceClient = class {
|
|
|
3883
3904
|
} catch {
|
|
3884
3905
|
}
|
|
3885
3906
|
}
|
|
3907
|
+
/**
|
|
3908
|
+
* Detect an abandoned-checkout recovery redirect. brainerce's recover endpoint
|
|
3909
|
+
* sends the shopper to `{storeDomain}/cart?brainerce_cart=<cartId>`; we stash
|
|
3910
|
+
* the id and adopt it (with its real session token) on the first cart access.
|
|
3911
|
+
* @internal
|
|
3912
|
+
*/
|
|
3913
|
+
detectRecoverCartFromUrl() {
|
|
3914
|
+
if (typeof window === "undefined" || !window.location?.search) return;
|
|
3915
|
+
try {
|
|
3916
|
+
const recoverId = new URLSearchParams(window.location.search).get("brainerce_cart");
|
|
3917
|
+
if (recoverId) this._pendingRecoverCartId = recoverId;
|
|
3918
|
+
} catch {
|
|
3919
|
+
}
|
|
3920
|
+
}
|
|
3921
|
+
/**
|
|
3922
|
+
* Adopt a recovery-redirect cart if one is pending. Runs as the first step of
|
|
3923
|
+
* session-cart resolution so the recovered cart wins over any stale local
|
|
3924
|
+
* session. Returns the adopted cart, or null to fall through to normal
|
|
3925
|
+
* resolution (no pending id, or the cart is no longer recoverable).
|
|
3926
|
+
* @internal
|
|
3927
|
+
*/
|
|
3928
|
+
async adoptPendingRecoverCart() {
|
|
3929
|
+
const recoverId = this._pendingRecoverCartId;
|
|
3930
|
+
if (!recoverId) return null;
|
|
3931
|
+
this._pendingRecoverCartId = null;
|
|
3932
|
+
try {
|
|
3933
|
+
const cart = await this.getCart(recoverId);
|
|
3934
|
+
if (cart.status !== "ACTIVE") return null;
|
|
3935
|
+
if (cart.sessionToken) {
|
|
3936
|
+
this.saveSessionCart({
|
|
3937
|
+
sessionToken: cart.sessionToken,
|
|
3938
|
+
cartId: cart.id,
|
|
3939
|
+
itemCount: cart.itemCount
|
|
3940
|
+
});
|
|
3941
|
+
} else {
|
|
3942
|
+
this.sessionCartId = cart.id;
|
|
3943
|
+
}
|
|
3944
|
+
return cart;
|
|
3945
|
+
} catch {
|
|
3946
|
+
return null;
|
|
3947
|
+
}
|
|
3948
|
+
}
|
|
3886
3949
|
/**
|
|
3887
3950
|
* Persist session cart reference to localStorage.
|
|
3888
3951
|
* @internal
|
|
@@ -3982,6 +4045,8 @@ var BrainerceClient = class {
|
|
|
3982
4045
|
}
|
|
3983
4046
|
/** @internal */
|
|
3984
4047
|
async _getOrCreateSessionCartImpl() {
|
|
4048
|
+
const recovered = await this.adoptPendingRecoverCart();
|
|
4049
|
+
if (recovered) return recovered;
|
|
3985
4050
|
const migrated = await this.migrateLocalCartToSession();
|
|
3986
4051
|
if (migrated) return migrated;
|
|
3987
4052
|
if (this.sessionCartId && this.sessionToken) {
|
|
@@ -4215,9 +4280,13 @@ var BrainerceClient = class {
|
|
|
4215
4280
|
*/
|
|
4216
4281
|
async smartGetCart(options) {
|
|
4217
4282
|
if (this.isCustomerLoggedIn()) {
|
|
4283
|
+
if (this._pendingRecoverCartId) {
|
|
4284
|
+
const recovered = await this.adoptPendingRecoverCart();
|
|
4285
|
+
if (recovered) return recovered;
|
|
4286
|
+
}
|
|
4218
4287
|
return this.getOrCreateCustomerCart(options);
|
|
4219
4288
|
} else {
|
|
4220
|
-
if (!this.sessionToken) {
|
|
4289
|
+
if (!this.sessionToken && !this._pendingRecoverCartId) {
|
|
4221
4290
|
return this.emptyCart();
|
|
4222
4291
|
}
|
|
4223
4292
|
return this.getOrCreateSessionCart(options);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brainerce",
|
|
3
|
-
"version": "1.36.
|
|
3
|
+
"version": "1.36.4",
|
|
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",
|