brainerce 1.17.0 → 1.18.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 +4487 -4447
- package/dist/index.d.mts +113 -12
- package/dist/index.d.ts +113 -12
- package/dist/index.js +119 -18
- package/dist/index.mjs +119 -18
- package/package.json +76 -76
package/dist/index.js
CHANGED
|
@@ -2112,30 +2112,82 @@ var BrainerceClient = class {
|
|
|
2112
2112
|
}
|
|
2113
2113
|
/**
|
|
2114
2114
|
* Get a cart by ID
|
|
2115
|
+
*
|
|
2116
|
+
* @param cartId - The cart ID
|
|
2117
|
+
* @param options - Optional settings. Use `include` to fetch related data in a single request.
|
|
2118
|
+
*
|
|
2119
|
+
* @example
|
|
2120
|
+
* ```typescript
|
|
2121
|
+
* // Basic cart fetch
|
|
2122
|
+
* const cart = await client.getCart('cart_123');
|
|
2123
|
+
*
|
|
2124
|
+
* // Fetch cart with recommendations, upgrades, and bundles in one call
|
|
2125
|
+
* const enriched = await client.getCart('cart_123', {
|
|
2126
|
+
* include: ['recommendations', 'upgrades', 'bundles'],
|
|
2127
|
+
* });
|
|
2128
|
+
* console.log(enriched.recommendations); // { recommendations: [...] }
|
|
2129
|
+
* console.log(enriched.upgrades); // { upgrades: { ... } }
|
|
2130
|
+
* console.log(enriched.bundles); // { bundles: [...] }
|
|
2131
|
+
* ```
|
|
2115
2132
|
*/
|
|
2116
|
-
async getCart(cartId) {
|
|
2133
|
+
async getCart(cartId, options) {
|
|
2117
2134
|
if (cartId === this.VIRTUAL_LOCAL_CART_ID) {
|
|
2118
2135
|
console.warn('getCart("__local__") is deprecated. Use smartGetCart() instead.');
|
|
2119
2136
|
return this.withGuards(this.localCartToCart(this.getLocalCart()), "cart");
|
|
2120
2137
|
}
|
|
2138
|
+
const queryParams = options?.include?.length ? { include: options.include.join(",") } : void 0;
|
|
2121
2139
|
if (this.isVibeCodedMode()) {
|
|
2122
|
-
return this.withGuards(
|
|
2140
|
+
return this.withGuards(
|
|
2141
|
+
this.vibeCodedRequest("GET", `/cart/${cartId}`, void 0, queryParams),
|
|
2142
|
+
"cart"
|
|
2143
|
+
);
|
|
2123
2144
|
}
|
|
2124
2145
|
if (this.storeId && !this.apiKey) {
|
|
2125
|
-
return this.withGuards(
|
|
2146
|
+
return this.withGuards(
|
|
2147
|
+
this.storefrontRequest("GET", `/cart/${cartId}`, void 0, queryParams),
|
|
2148
|
+
"cart"
|
|
2149
|
+
);
|
|
2126
2150
|
}
|
|
2127
|
-
return this.withGuards(
|
|
2151
|
+
return this.withGuards(
|
|
2152
|
+
this.adminRequest("GET", `/api/v1/cart/${cartId}`, void 0, queryParams),
|
|
2153
|
+
"cart"
|
|
2154
|
+
);
|
|
2128
2155
|
}
|
|
2129
2156
|
/**
|
|
2130
|
-
* Add an item to the cart
|
|
2157
|
+
* Add an item to the cart.
|
|
2158
|
+
*
|
|
2159
|
+
* If the product has `customizationFields` (merchant-defined buyer input
|
|
2160
|
+
* like engraving text, uploaded photos, select options), pass the buyer's
|
|
2161
|
+
* values in `metadata`. Keys must match each field's `key`. For `IMAGE` /
|
|
2162
|
+
* `GALLERY` types, upload the file first via `uploadCustomizationFile()`
|
|
2163
|
+
* and pass the returned URL. The server validates every value against its
|
|
2164
|
+
* `MetafieldDefinition` and rejects the request with HTTP 400 if anything
|
|
2165
|
+
* fails (type mismatch, required missing, not in `enumValues`, etc.).
|
|
2166
|
+
*
|
|
2167
|
+
* Values are snapshotted onto the order line at checkout — later edits to
|
|
2168
|
+
* the field definition do not retroactively change existing orders.
|
|
2131
2169
|
*
|
|
2132
2170
|
* @example
|
|
2133
2171
|
* ```typescript
|
|
2172
|
+
* // Product with no customization fields
|
|
2134
2173
|
* const cart = await client.addToCart('cart_123', {
|
|
2135
2174
|
* productId: 'prod_abc',
|
|
2136
2175
|
* quantity: 2,
|
|
2137
2176
|
* notes: 'Gift wrap please',
|
|
2138
2177
|
* });
|
|
2178
|
+
*
|
|
2179
|
+
* // Product WITH customization fields (engraving + photo + select + multi)
|
|
2180
|
+
* const { url: photoUrl } = await client.uploadCustomizationFile(file);
|
|
2181
|
+
* const cart = await client.addToCart('cart_123', {
|
|
2182
|
+
* productId: 'prod_mug',
|
|
2183
|
+
* quantity: 1,
|
|
2184
|
+
* metadata: {
|
|
2185
|
+
* engraving_text: 'Happy Birthday!', // TEXT
|
|
2186
|
+
* frame_color: 'Gold', // SELECT (must be in enumValues)
|
|
2187
|
+
* upload_photo: photoUrl, // IMAGE
|
|
2188
|
+
* addons: ['Gift wrap'], // MULTI_SELECT (always array)
|
|
2189
|
+
* },
|
|
2190
|
+
* });
|
|
2139
2191
|
* ```
|
|
2140
2192
|
*/
|
|
2141
2193
|
async addToCart(cartId, item) {
|
|
@@ -2783,11 +2835,21 @@ var BrainerceClient = class {
|
|
|
2783
2835
|
* Uses promise dedup lock to prevent race conditions on parallel calls.
|
|
2784
2836
|
* @internal
|
|
2785
2837
|
*/
|
|
2786
|
-
async getOrCreateSessionCart() {
|
|
2787
|
-
if (this._sessionCartPromise)
|
|
2838
|
+
async getOrCreateSessionCart(options) {
|
|
2839
|
+
if (this._sessionCartPromise) {
|
|
2840
|
+
const base = await this._sessionCartPromise;
|
|
2841
|
+
if (options?.include?.length && base.id) {
|
|
2842
|
+
return this.getCart(base.id, options);
|
|
2843
|
+
}
|
|
2844
|
+
return base;
|
|
2845
|
+
}
|
|
2788
2846
|
this._sessionCartPromise = this._getOrCreateSessionCartImpl();
|
|
2789
2847
|
try {
|
|
2790
|
-
|
|
2848
|
+
const base = await this._sessionCartPromise;
|
|
2849
|
+
if (options?.include?.length && base.id) {
|
|
2850
|
+
return this.getCart(base.id, options);
|
|
2851
|
+
}
|
|
2852
|
+
return base;
|
|
2791
2853
|
} finally {
|
|
2792
2854
|
this._sessionCartPromise = null;
|
|
2793
2855
|
}
|
|
@@ -2920,10 +2982,10 @@ var BrainerceClient = class {
|
|
|
2920
2982
|
* Caches the cart ID for subsequent calls
|
|
2921
2983
|
* @internal
|
|
2922
2984
|
*/
|
|
2923
|
-
async getOrCreateCustomerCart() {
|
|
2985
|
+
async getOrCreateCustomerCart(options) {
|
|
2924
2986
|
if (this.customerCartId) {
|
|
2925
2987
|
try {
|
|
2926
|
-
const existingCart = await this.getCart(this.customerCartId);
|
|
2988
|
+
const existingCart = await this.getCart(this.customerCartId, options);
|
|
2927
2989
|
if (existingCart.status === "ACTIVE") {
|
|
2928
2990
|
return existingCart;
|
|
2929
2991
|
}
|
|
@@ -2936,6 +2998,9 @@ var BrainerceClient = class {
|
|
|
2936
2998
|
const cart2 = await this.fetchCustomerCart();
|
|
2937
2999
|
if (cart2.status === "ACTIVE") {
|
|
2938
3000
|
this.customerCartId = cart2.id;
|
|
3001
|
+
if (options?.include?.length) {
|
|
3002
|
+
return this.getCart(cart2.id, options);
|
|
3003
|
+
}
|
|
2939
3004
|
return cart2;
|
|
2940
3005
|
}
|
|
2941
3006
|
} catch {
|
|
@@ -2987,7 +3052,8 @@ var BrainerceClient = class {
|
|
|
2987
3052
|
const updated = await this.addToCart(cart.id, {
|
|
2988
3053
|
productId: item.productId,
|
|
2989
3054
|
variantId: item.variantId,
|
|
2990
|
-
quantity: item.quantity
|
|
3055
|
+
quantity: item.quantity,
|
|
3056
|
+
metadata: item.metadata
|
|
2991
3057
|
});
|
|
2992
3058
|
return updated;
|
|
2993
3059
|
} else {
|
|
@@ -2995,7 +3061,8 @@ var BrainerceClient = class {
|
|
|
2995
3061
|
const updated = await this.addToCart(cart.id, {
|
|
2996
3062
|
productId: item.productId,
|
|
2997
3063
|
variantId: item.variantId,
|
|
2998
|
-
quantity: item.quantity
|
|
3064
|
+
quantity: item.quantity,
|
|
3065
|
+
metadata: item.metadata
|
|
2999
3066
|
});
|
|
3000
3067
|
this.updateSessionCartItemCount(updated.items?.length ?? 0);
|
|
3001
3068
|
return updated;
|
|
@@ -3008,20 +3075,28 @@ var BrainerceClient = class {
|
|
|
3008
3075
|
* - **Guest with session**: Returns server-side session cart
|
|
3009
3076
|
* - **Guest without session**: Returns empty cart (no server call, cart created lazily on add)
|
|
3010
3077
|
*
|
|
3078
|
+
* @param options - Optional. Use `include` to fetch recommendations, upgrades, and bundles
|
|
3079
|
+
* in a single request instead of separate calls.
|
|
3080
|
+
*
|
|
3011
3081
|
* @example
|
|
3012
3082
|
* ```typescript
|
|
3013
3083
|
* const cart = await client.smartGetCart();
|
|
3014
3084
|
* console.log('Items:', cart.items.length);
|
|
3085
|
+
*
|
|
3086
|
+
* // With includes — single request for cart + extras
|
|
3087
|
+
* const enriched = await client.smartGetCart({
|
|
3088
|
+
* include: ['recommendations', 'upgrades', 'bundles'],
|
|
3089
|
+
* });
|
|
3015
3090
|
* ```
|
|
3016
3091
|
*/
|
|
3017
|
-
async smartGetCart() {
|
|
3092
|
+
async smartGetCart(options) {
|
|
3018
3093
|
if (this.isCustomerLoggedIn()) {
|
|
3019
|
-
return this.getOrCreateCustomerCart();
|
|
3094
|
+
return this.getOrCreateCustomerCart(options);
|
|
3020
3095
|
} else {
|
|
3021
3096
|
if (!this.sessionToken) {
|
|
3022
3097
|
return this.emptyCart();
|
|
3023
3098
|
}
|
|
3024
|
-
return this.getOrCreateSessionCart();
|
|
3099
|
+
return this.getOrCreateSessionCart(options);
|
|
3025
3100
|
}
|
|
3026
3101
|
}
|
|
3027
3102
|
/**
|
|
@@ -5698,9 +5773,35 @@ var BrainerceClient = class {
|
|
|
5698
5773
|
);
|
|
5699
5774
|
}
|
|
5700
5775
|
/**
|
|
5701
|
-
* Upload a file
|
|
5702
|
-
*
|
|
5703
|
-
*
|
|
5776
|
+
* Upload a buyer-submitted file (engraving photo, custom image, etc.) for a
|
|
5777
|
+
* product customization field of type `IMAGE` or `GALLERY`. The returned `url`
|
|
5778
|
+
* is what you pass back in the add-to-cart `metadata` payload.
|
|
5779
|
+
*
|
|
5780
|
+
* Available in storefront and vibe-coded modes — no customer login required.
|
|
5781
|
+
*
|
|
5782
|
+
* Server rules:
|
|
5783
|
+
* - `image/*` MIME only. Other types → HTTP 400.
|
|
5784
|
+
* - Max 5 MB per file.
|
|
5785
|
+
* - Throttled to 10 uploads / minute per IP → HTTP 429.
|
|
5786
|
+
* - Retention: at least 7 days. If the cart never becomes an order, the file
|
|
5787
|
+
* is reclaimed automatically. Once the order exists, the file is kept for
|
|
5788
|
+
* order-history purposes.
|
|
5789
|
+
*
|
|
5790
|
+
* @example
|
|
5791
|
+
* ```ts
|
|
5792
|
+
* // On a product page with IMAGE/GALLERY customization fields:
|
|
5793
|
+
* const { url } = await client.uploadCustomizationFile(fileInput.files[0]);
|
|
5794
|
+
*
|
|
5795
|
+
* // Then include the URL in the add-to-cart metadata:
|
|
5796
|
+
* await client.addToCart(cart.id, {
|
|
5797
|
+
* productId: product.id,
|
|
5798
|
+
* quantity: 1,
|
|
5799
|
+
* metadata: {
|
|
5800
|
+
* engraving_text: 'Happy Birthday!',
|
|
5801
|
+
* upload_photo: url,
|
|
5802
|
+
* },
|
|
5803
|
+
* });
|
|
5804
|
+
* ```
|
|
5704
5805
|
*/
|
|
5705
5806
|
async uploadCustomizationFile(file) {
|
|
5706
5807
|
const formData = new FormData();
|
package/dist/index.mjs
CHANGED
|
@@ -2051,30 +2051,82 @@ var BrainerceClient = class {
|
|
|
2051
2051
|
}
|
|
2052
2052
|
/**
|
|
2053
2053
|
* Get a cart by ID
|
|
2054
|
+
*
|
|
2055
|
+
* @param cartId - The cart ID
|
|
2056
|
+
* @param options - Optional settings. Use `include` to fetch related data in a single request.
|
|
2057
|
+
*
|
|
2058
|
+
* @example
|
|
2059
|
+
* ```typescript
|
|
2060
|
+
* // Basic cart fetch
|
|
2061
|
+
* const cart = await client.getCart('cart_123');
|
|
2062
|
+
*
|
|
2063
|
+
* // Fetch cart with recommendations, upgrades, and bundles in one call
|
|
2064
|
+
* const enriched = await client.getCart('cart_123', {
|
|
2065
|
+
* include: ['recommendations', 'upgrades', 'bundles'],
|
|
2066
|
+
* });
|
|
2067
|
+
* console.log(enriched.recommendations); // { recommendations: [...] }
|
|
2068
|
+
* console.log(enriched.upgrades); // { upgrades: { ... } }
|
|
2069
|
+
* console.log(enriched.bundles); // { bundles: [...] }
|
|
2070
|
+
* ```
|
|
2054
2071
|
*/
|
|
2055
|
-
async getCart(cartId) {
|
|
2072
|
+
async getCart(cartId, options) {
|
|
2056
2073
|
if (cartId === this.VIRTUAL_LOCAL_CART_ID) {
|
|
2057
2074
|
console.warn('getCart("__local__") is deprecated. Use smartGetCart() instead.');
|
|
2058
2075
|
return this.withGuards(this.localCartToCart(this.getLocalCart()), "cart");
|
|
2059
2076
|
}
|
|
2077
|
+
const queryParams = options?.include?.length ? { include: options.include.join(",") } : void 0;
|
|
2060
2078
|
if (this.isVibeCodedMode()) {
|
|
2061
|
-
return this.withGuards(
|
|
2079
|
+
return this.withGuards(
|
|
2080
|
+
this.vibeCodedRequest("GET", `/cart/${cartId}`, void 0, queryParams),
|
|
2081
|
+
"cart"
|
|
2082
|
+
);
|
|
2062
2083
|
}
|
|
2063
2084
|
if (this.storeId && !this.apiKey) {
|
|
2064
|
-
return this.withGuards(
|
|
2085
|
+
return this.withGuards(
|
|
2086
|
+
this.storefrontRequest("GET", `/cart/${cartId}`, void 0, queryParams),
|
|
2087
|
+
"cart"
|
|
2088
|
+
);
|
|
2065
2089
|
}
|
|
2066
|
-
return this.withGuards(
|
|
2090
|
+
return this.withGuards(
|
|
2091
|
+
this.adminRequest("GET", `/api/v1/cart/${cartId}`, void 0, queryParams),
|
|
2092
|
+
"cart"
|
|
2093
|
+
);
|
|
2067
2094
|
}
|
|
2068
2095
|
/**
|
|
2069
|
-
* Add an item to the cart
|
|
2096
|
+
* Add an item to the cart.
|
|
2097
|
+
*
|
|
2098
|
+
* If the product has `customizationFields` (merchant-defined buyer input
|
|
2099
|
+
* like engraving text, uploaded photos, select options), pass the buyer's
|
|
2100
|
+
* values in `metadata`. Keys must match each field's `key`. For `IMAGE` /
|
|
2101
|
+
* `GALLERY` types, upload the file first via `uploadCustomizationFile()`
|
|
2102
|
+
* and pass the returned URL. The server validates every value against its
|
|
2103
|
+
* `MetafieldDefinition` and rejects the request with HTTP 400 if anything
|
|
2104
|
+
* fails (type mismatch, required missing, not in `enumValues`, etc.).
|
|
2105
|
+
*
|
|
2106
|
+
* Values are snapshotted onto the order line at checkout — later edits to
|
|
2107
|
+
* the field definition do not retroactively change existing orders.
|
|
2070
2108
|
*
|
|
2071
2109
|
* @example
|
|
2072
2110
|
* ```typescript
|
|
2111
|
+
* // Product with no customization fields
|
|
2073
2112
|
* const cart = await client.addToCart('cart_123', {
|
|
2074
2113
|
* productId: 'prod_abc',
|
|
2075
2114
|
* quantity: 2,
|
|
2076
2115
|
* notes: 'Gift wrap please',
|
|
2077
2116
|
* });
|
|
2117
|
+
*
|
|
2118
|
+
* // Product WITH customization fields (engraving + photo + select + multi)
|
|
2119
|
+
* const { url: photoUrl } = await client.uploadCustomizationFile(file);
|
|
2120
|
+
* const cart = await client.addToCart('cart_123', {
|
|
2121
|
+
* productId: 'prod_mug',
|
|
2122
|
+
* quantity: 1,
|
|
2123
|
+
* metadata: {
|
|
2124
|
+
* engraving_text: 'Happy Birthday!', // TEXT
|
|
2125
|
+
* frame_color: 'Gold', // SELECT (must be in enumValues)
|
|
2126
|
+
* upload_photo: photoUrl, // IMAGE
|
|
2127
|
+
* addons: ['Gift wrap'], // MULTI_SELECT (always array)
|
|
2128
|
+
* },
|
|
2129
|
+
* });
|
|
2078
2130
|
* ```
|
|
2079
2131
|
*/
|
|
2080
2132
|
async addToCart(cartId, item) {
|
|
@@ -2722,11 +2774,21 @@ var BrainerceClient = class {
|
|
|
2722
2774
|
* Uses promise dedup lock to prevent race conditions on parallel calls.
|
|
2723
2775
|
* @internal
|
|
2724
2776
|
*/
|
|
2725
|
-
async getOrCreateSessionCart() {
|
|
2726
|
-
if (this._sessionCartPromise)
|
|
2777
|
+
async getOrCreateSessionCart(options) {
|
|
2778
|
+
if (this._sessionCartPromise) {
|
|
2779
|
+
const base = await this._sessionCartPromise;
|
|
2780
|
+
if (options?.include?.length && base.id) {
|
|
2781
|
+
return this.getCart(base.id, options);
|
|
2782
|
+
}
|
|
2783
|
+
return base;
|
|
2784
|
+
}
|
|
2727
2785
|
this._sessionCartPromise = this._getOrCreateSessionCartImpl();
|
|
2728
2786
|
try {
|
|
2729
|
-
|
|
2787
|
+
const base = await this._sessionCartPromise;
|
|
2788
|
+
if (options?.include?.length && base.id) {
|
|
2789
|
+
return this.getCart(base.id, options);
|
|
2790
|
+
}
|
|
2791
|
+
return base;
|
|
2730
2792
|
} finally {
|
|
2731
2793
|
this._sessionCartPromise = null;
|
|
2732
2794
|
}
|
|
@@ -2859,10 +2921,10 @@ var BrainerceClient = class {
|
|
|
2859
2921
|
* Caches the cart ID for subsequent calls
|
|
2860
2922
|
* @internal
|
|
2861
2923
|
*/
|
|
2862
|
-
async getOrCreateCustomerCart() {
|
|
2924
|
+
async getOrCreateCustomerCart(options) {
|
|
2863
2925
|
if (this.customerCartId) {
|
|
2864
2926
|
try {
|
|
2865
|
-
const existingCart = await this.getCart(this.customerCartId);
|
|
2927
|
+
const existingCart = await this.getCart(this.customerCartId, options);
|
|
2866
2928
|
if (existingCart.status === "ACTIVE") {
|
|
2867
2929
|
return existingCart;
|
|
2868
2930
|
}
|
|
@@ -2875,6 +2937,9 @@ var BrainerceClient = class {
|
|
|
2875
2937
|
const cart2 = await this.fetchCustomerCart();
|
|
2876
2938
|
if (cart2.status === "ACTIVE") {
|
|
2877
2939
|
this.customerCartId = cart2.id;
|
|
2940
|
+
if (options?.include?.length) {
|
|
2941
|
+
return this.getCart(cart2.id, options);
|
|
2942
|
+
}
|
|
2878
2943
|
return cart2;
|
|
2879
2944
|
}
|
|
2880
2945
|
} catch {
|
|
@@ -2926,7 +2991,8 @@ var BrainerceClient = class {
|
|
|
2926
2991
|
const updated = await this.addToCart(cart.id, {
|
|
2927
2992
|
productId: item.productId,
|
|
2928
2993
|
variantId: item.variantId,
|
|
2929
|
-
quantity: item.quantity
|
|
2994
|
+
quantity: item.quantity,
|
|
2995
|
+
metadata: item.metadata
|
|
2930
2996
|
});
|
|
2931
2997
|
return updated;
|
|
2932
2998
|
} else {
|
|
@@ -2934,7 +3000,8 @@ var BrainerceClient = class {
|
|
|
2934
3000
|
const updated = await this.addToCart(cart.id, {
|
|
2935
3001
|
productId: item.productId,
|
|
2936
3002
|
variantId: item.variantId,
|
|
2937
|
-
quantity: item.quantity
|
|
3003
|
+
quantity: item.quantity,
|
|
3004
|
+
metadata: item.metadata
|
|
2938
3005
|
});
|
|
2939
3006
|
this.updateSessionCartItemCount(updated.items?.length ?? 0);
|
|
2940
3007
|
return updated;
|
|
@@ -2947,20 +3014,28 @@ var BrainerceClient = class {
|
|
|
2947
3014
|
* - **Guest with session**: Returns server-side session cart
|
|
2948
3015
|
* - **Guest without session**: Returns empty cart (no server call, cart created lazily on add)
|
|
2949
3016
|
*
|
|
3017
|
+
* @param options - Optional. Use `include` to fetch recommendations, upgrades, and bundles
|
|
3018
|
+
* in a single request instead of separate calls.
|
|
3019
|
+
*
|
|
2950
3020
|
* @example
|
|
2951
3021
|
* ```typescript
|
|
2952
3022
|
* const cart = await client.smartGetCart();
|
|
2953
3023
|
* console.log('Items:', cart.items.length);
|
|
3024
|
+
*
|
|
3025
|
+
* // With includes — single request for cart + extras
|
|
3026
|
+
* const enriched = await client.smartGetCart({
|
|
3027
|
+
* include: ['recommendations', 'upgrades', 'bundles'],
|
|
3028
|
+
* });
|
|
2954
3029
|
* ```
|
|
2955
3030
|
*/
|
|
2956
|
-
async smartGetCart() {
|
|
3031
|
+
async smartGetCart(options) {
|
|
2957
3032
|
if (this.isCustomerLoggedIn()) {
|
|
2958
|
-
return this.getOrCreateCustomerCart();
|
|
3033
|
+
return this.getOrCreateCustomerCart(options);
|
|
2959
3034
|
} else {
|
|
2960
3035
|
if (!this.sessionToken) {
|
|
2961
3036
|
return this.emptyCart();
|
|
2962
3037
|
}
|
|
2963
|
-
return this.getOrCreateSessionCart();
|
|
3038
|
+
return this.getOrCreateSessionCart(options);
|
|
2964
3039
|
}
|
|
2965
3040
|
}
|
|
2966
3041
|
/**
|
|
@@ -5637,9 +5712,35 @@ var BrainerceClient = class {
|
|
|
5637
5712
|
);
|
|
5638
5713
|
}
|
|
5639
5714
|
/**
|
|
5640
|
-
* Upload a file
|
|
5641
|
-
*
|
|
5642
|
-
*
|
|
5715
|
+
* Upload a buyer-submitted file (engraving photo, custom image, etc.) for a
|
|
5716
|
+
* product customization field of type `IMAGE` or `GALLERY`. The returned `url`
|
|
5717
|
+
* is what you pass back in the add-to-cart `metadata` payload.
|
|
5718
|
+
*
|
|
5719
|
+
* Available in storefront and vibe-coded modes — no customer login required.
|
|
5720
|
+
*
|
|
5721
|
+
* Server rules:
|
|
5722
|
+
* - `image/*` MIME only. Other types → HTTP 400.
|
|
5723
|
+
* - Max 5 MB per file.
|
|
5724
|
+
* - Throttled to 10 uploads / minute per IP → HTTP 429.
|
|
5725
|
+
* - Retention: at least 7 days. If the cart never becomes an order, the file
|
|
5726
|
+
* is reclaimed automatically. Once the order exists, the file is kept for
|
|
5727
|
+
* order-history purposes.
|
|
5728
|
+
*
|
|
5729
|
+
* @example
|
|
5730
|
+
* ```ts
|
|
5731
|
+
* // On a product page with IMAGE/GALLERY customization fields:
|
|
5732
|
+
* const { url } = await client.uploadCustomizationFile(fileInput.files[0]);
|
|
5733
|
+
*
|
|
5734
|
+
* // Then include the URL in the add-to-cart metadata:
|
|
5735
|
+
* await client.addToCart(cart.id, {
|
|
5736
|
+
* productId: product.id,
|
|
5737
|
+
* quantity: 1,
|
|
5738
|
+
* metadata: {
|
|
5739
|
+
* engraving_text: 'Happy Birthday!',
|
|
5740
|
+
* upload_photo: url,
|
|
5741
|
+
* },
|
|
5742
|
+
* });
|
|
5743
|
+
* ```
|
|
5643
5744
|
*/
|
|
5644
5745
|
async uploadCustomizationFile(file) {
|
|
5645
5746
|
const formData = new FormData();
|
package/package.json
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "brainerce",
|
|
3
|
-
"version": "1.
|
|
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
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
|
-
"require": "./dist/index.js",
|
|
12
|
-
"import": "./dist/index.mjs"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"files": [
|
|
16
|
-
"dist",
|
|
17
|
-
"README.md"
|
|
18
|
-
],
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
21
|
-
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
22
|
-
"lint": "eslint \"src/**/*.ts\"",
|
|
23
|
-
"test": "vitest run",
|
|
24
|
-
"test:watch": "vitest",
|
|
25
|
-
"prepublishOnly": "pnpm build"
|
|
26
|
-
},
|
|
27
|
-
"keywords": [
|
|
28
|
-
"brainerce",
|
|
29
|
-
"e-commerce",
|
|
30
|
-
"ecommerce",
|
|
31
|
-
"sdk",
|
|
32
|
-
"vibe-coding",
|
|
33
|
-
"vibe-coded",
|
|
34
|
-
"ai-commerce",
|
|
35
|
-
"storefront",
|
|
36
|
-
"headless-commerce",
|
|
37
|
-
"multi-platform",
|
|
38
|
-
"shopify",
|
|
39
|
-
"tiktok",
|
|
40
|
-
"cursor",
|
|
41
|
-
"lovable",
|
|
42
|
-
"v0",
|
|
43
|
-
"cart",
|
|
44
|
-
"checkout",
|
|
45
|
-
"products",
|
|
46
|
-
"sync"
|
|
47
|
-
],
|
|
48
|
-
"author": "Brainerce",
|
|
49
|
-
"license": "MIT",
|
|
50
|
-
"repository": {
|
|
51
|
-
"type": "git",
|
|
52
|
-
"url": "https://github.com/brainerce/brainerce.git",
|
|
53
|
-
"directory": "packages/sdk"
|
|
54
|
-
},
|
|
55
|
-
"homepage": "https://brainerce.com",
|
|
56
|
-
"bugs": {
|
|
57
|
-
"url": "https://github.com/brainerce/brainerce/issues"
|
|
58
|
-
},
|
|
59
|
-
"devDependencies": {
|
|
60
|
-
"@types/node": "^25.0.3",
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
62
|
-
"@typescript-eslint/parser": "^8.50.1",
|
|
63
|
-
"eslint": "^9.39.2",
|
|
64
|
-
"tsup": "^8.0.0",
|
|
65
|
-
"typescript": "^5.3.0",
|
|
66
|
-
"vitest": "^1.0.0"
|
|
67
|
-
},
|
|
68
|
-
"peerDependencies": {
|
|
69
|
-
"typescript": ">=4.7.0"
|
|
70
|
-
},
|
|
71
|
-
"peerDependenciesMeta": {
|
|
72
|
-
"typescript": {
|
|
73
|
-
"optional": true
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "brainerce",
|
|
3
|
+
"version": "1.18.0",
|
|
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
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"import": "./dist/index.mjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
21
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
22
|
+
"lint": "eslint \"src/**/*.ts\"",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:watch": "vitest",
|
|
25
|
+
"prepublishOnly": "pnpm build"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"brainerce",
|
|
29
|
+
"e-commerce",
|
|
30
|
+
"ecommerce",
|
|
31
|
+
"sdk",
|
|
32
|
+
"vibe-coding",
|
|
33
|
+
"vibe-coded",
|
|
34
|
+
"ai-commerce",
|
|
35
|
+
"storefront",
|
|
36
|
+
"headless-commerce",
|
|
37
|
+
"multi-platform",
|
|
38
|
+
"shopify",
|
|
39
|
+
"tiktok",
|
|
40
|
+
"cursor",
|
|
41
|
+
"lovable",
|
|
42
|
+
"v0",
|
|
43
|
+
"cart",
|
|
44
|
+
"checkout",
|
|
45
|
+
"products",
|
|
46
|
+
"sync"
|
|
47
|
+
],
|
|
48
|
+
"author": "Brainerce",
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "https://github.com/brainerce/brainerce.git",
|
|
53
|
+
"directory": "packages/sdk"
|
|
54
|
+
},
|
|
55
|
+
"homepage": "https://brainerce.com",
|
|
56
|
+
"bugs": {
|
|
57
|
+
"url": "https://github.com/brainerce/brainerce/issues"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/node": "^25.0.3",
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
62
|
+
"@typescript-eslint/parser": "^8.50.1",
|
|
63
|
+
"eslint": "^9.39.2",
|
|
64
|
+
"tsup": "^8.0.0",
|
|
65
|
+
"typescript": "^5.3.0",
|
|
66
|
+
"vitest": "^1.0.0"
|
|
67
|
+
},
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"typescript": ">=4.7.0"
|
|
70
|
+
},
|
|
71
|
+
"peerDependenciesMeta": {
|
|
72
|
+
"typescript": {
|
|
73
|
+
"optional": true
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|