brainerce 1.10.3 → 1.11.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 +65 -6
- package/dist/index.d.mts +64 -4
- package/dist/index.d.ts +64 -4
- package/dist/index.js +62 -8
- package/dist/index.mjs +60 -8
- package/package.json +2 -3
- package/AI_BUILDER_PROMPT.md +0 -843
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ var index_exports = {};
|
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
BrainerceClient: () => BrainerceClient,
|
|
34
34
|
BrainerceError: () => BrainerceError,
|
|
35
|
+
SDK_VERSION: () => SDK_VERSION,
|
|
35
36
|
createWebhookHandler: () => createWebhookHandler,
|
|
36
37
|
enableDevGuards: () => enableDevGuards,
|
|
37
38
|
formatPrice: () => formatPrice,
|
|
@@ -45,6 +46,7 @@ __export(index_exports, {
|
|
|
45
46
|
getProductMetafieldsByType: () => getProductMetafieldsByType,
|
|
46
47
|
getProductPrice: () => getProductPrice,
|
|
47
48
|
getProductPriceInfo: () => getProductPriceInfo,
|
|
49
|
+
getProductSwatches: () => getProductSwatches,
|
|
48
50
|
getStockStatus: () => getStockStatus,
|
|
49
51
|
getVariantOptions: () => getVariantOptions,
|
|
50
52
|
getVariantPrice: () => getVariantPrice,
|
|
@@ -172,6 +174,9 @@ function isDevGuardsEnabled() {
|
|
|
172
174
|
return _devGuardsEnabled;
|
|
173
175
|
}
|
|
174
176
|
|
|
177
|
+
// src/version.ts
|
|
178
|
+
var SDK_VERSION = "1.11.2";
|
|
179
|
+
|
|
175
180
|
// src/client.ts
|
|
176
181
|
var DEFAULT_BASE_URL = "https://api.brainerce.com";
|
|
177
182
|
var DEFAULT_TIMEOUT = 3e4;
|
|
@@ -223,6 +228,15 @@ var BrainerceClient = class {
|
|
|
223
228
|
}
|
|
224
229
|
this.baseUrl = resolvedBase;
|
|
225
230
|
this.timeout = options.timeout || DEFAULT_TIMEOUT;
|
|
231
|
+
if (options.origin) {
|
|
232
|
+
this.origin = options.origin;
|
|
233
|
+
} else if (typeof window === "undefined") {
|
|
234
|
+
try {
|
|
235
|
+
const parsed = new URL(resolvedBase);
|
|
236
|
+
this.origin = parsed.origin;
|
|
237
|
+
} catch {
|
|
238
|
+
}
|
|
239
|
+
}
|
|
226
240
|
this.proxyMode = options.proxyMode || false;
|
|
227
241
|
this.onAuthError = options.onAuthError;
|
|
228
242
|
this.hydrateSessionCart();
|
|
@@ -327,14 +341,18 @@ var BrainerceClient = class {
|
|
|
327
341
|
const controller = new AbortController();
|
|
328
342
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
329
343
|
try {
|
|
344
|
+
const headers = {
|
|
345
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
346
|
+
"Content-Type": "application/json",
|
|
347
|
+
"X-SDK-Version": SDK_VERSION,
|
|
348
|
+
"ngrok-skip-browser-warning": "true"
|
|
349
|
+
};
|
|
350
|
+
if (this.origin) {
|
|
351
|
+
headers["Origin"] = this.origin;
|
|
352
|
+
}
|
|
330
353
|
const response = await fetch(url.toString(), {
|
|
331
354
|
method,
|
|
332
|
-
headers
|
|
333
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
334
|
-
"Content-Type": "application/json",
|
|
335
|
-
"X-SDK-Version": "0.3.0",
|
|
336
|
-
"ngrok-skip-browser-warning": "true"
|
|
337
|
-
},
|
|
355
|
+
headers,
|
|
338
356
|
body: body ? JSON.stringify(body) : void 0,
|
|
339
357
|
signal: controller.signal
|
|
340
358
|
});
|
|
@@ -384,9 +402,12 @@ var BrainerceClient = class {
|
|
|
384
402
|
try {
|
|
385
403
|
const headers = {
|
|
386
404
|
"Content-Type": "application/json",
|
|
387
|
-
"X-SDK-Version":
|
|
405
|
+
"X-SDK-Version": SDK_VERSION,
|
|
388
406
|
"ngrok-skip-browser-warning": "true"
|
|
389
407
|
};
|
|
408
|
+
if (this.origin) {
|
|
409
|
+
headers["Origin"] = this.origin;
|
|
410
|
+
}
|
|
390
411
|
if (this.proxyMode && method !== "GET") {
|
|
391
412
|
headers["X-Requested-With"] = "brainerce";
|
|
392
413
|
}
|
|
@@ -452,9 +473,12 @@ var BrainerceClient = class {
|
|
|
452
473
|
try {
|
|
453
474
|
const headers = {
|
|
454
475
|
"Content-Type": "application/json",
|
|
455
|
-
"X-SDK-Version":
|
|
476
|
+
"X-SDK-Version": SDK_VERSION,
|
|
456
477
|
"ngrok-skip-browser-warning": "true"
|
|
457
478
|
};
|
|
479
|
+
if (this.origin) {
|
|
480
|
+
headers["Origin"] = this.origin;
|
|
481
|
+
}
|
|
458
482
|
if (this.customerToken) {
|
|
459
483
|
headers["Authorization"] = `Bearer ${this.customerToken}`;
|
|
460
484
|
}
|
|
@@ -5914,6 +5938,34 @@ function getVariantOptions(variant) {
|
|
|
5914
5938
|
]);
|
|
5915
5939
|
return Object.entries(variant.attributes).filter(([key, value]) => typeof value === "string" && !internalKeys.has(key)).map(([name, value]) => ({ name, value }));
|
|
5916
5940
|
}
|
|
5941
|
+
function getProductSwatches(product) {
|
|
5942
|
+
if (!product?.productAttributeOptions) return [];
|
|
5943
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
5944
|
+
for (const pao of product.productAttributeOptions) {
|
|
5945
|
+
if (!pao.attribute || !pao.attributeOption) continue;
|
|
5946
|
+
const attrName = pao.attribute.name;
|
|
5947
|
+
if (!grouped.has(attrName)) {
|
|
5948
|
+
grouped.set(attrName, {
|
|
5949
|
+
displayType: pao.attribute.displayType || "DEFAULT",
|
|
5950
|
+
options: []
|
|
5951
|
+
});
|
|
5952
|
+
}
|
|
5953
|
+
const entry = grouped.get(attrName);
|
|
5954
|
+
if (!entry.options.some((o) => o.name === pao.attributeOption.name)) {
|
|
5955
|
+
entry.options.push({
|
|
5956
|
+
name: pao.attributeOption.name,
|
|
5957
|
+
value: pao.attributeOption.value,
|
|
5958
|
+
swatchColor: pao.attributeOption.swatchColor,
|
|
5959
|
+
swatchColor2: pao.attributeOption.swatchColor2,
|
|
5960
|
+
swatchImageUrl: pao.attributeOption.swatchImageUrl
|
|
5961
|
+
});
|
|
5962
|
+
}
|
|
5963
|
+
}
|
|
5964
|
+
return Array.from(grouped.entries()).map(([attributeName, data]) => ({
|
|
5965
|
+
attributeName,
|
|
5966
|
+
...data
|
|
5967
|
+
}));
|
|
5968
|
+
}
|
|
5917
5969
|
function getProductMetafield(product, key) {
|
|
5918
5970
|
return product.metafields?.find((m) => m.definitionKey === key);
|
|
5919
5971
|
}
|
|
@@ -5946,6 +5998,7 @@ function isCouponApplicableToProduct(coupon, productId) {
|
|
|
5946
5998
|
0 && (module.exports = {
|
|
5947
5999
|
BrainerceClient,
|
|
5948
6000
|
BrainerceError,
|
|
6001
|
+
SDK_VERSION,
|
|
5949
6002
|
createWebhookHandler,
|
|
5950
6003
|
enableDevGuards,
|
|
5951
6004
|
formatPrice,
|
|
@@ -5959,6 +6012,7 @@ function isCouponApplicableToProduct(coupon, productId) {
|
|
|
5959
6012
|
getProductMetafieldsByType,
|
|
5960
6013
|
getProductPrice,
|
|
5961
6014
|
getProductPriceInfo,
|
|
6015
|
+
getProductSwatches,
|
|
5962
6016
|
getStockStatus,
|
|
5963
6017
|
getVariantOptions,
|
|
5964
6018
|
getVariantPrice,
|
package/dist/index.mjs
CHANGED
|
@@ -114,6 +114,9 @@ function isDevGuardsEnabled() {
|
|
|
114
114
|
return _devGuardsEnabled;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
// src/version.ts
|
|
118
|
+
var SDK_VERSION = "1.11.2";
|
|
119
|
+
|
|
117
120
|
// src/client.ts
|
|
118
121
|
var DEFAULT_BASE_URL = "https://api.brainerce.com";
|
|
119
122
|
var DEFAULT_TIMEOUT = 3e4;
|
|
@@ -165,6 +168,15 @@ var BrainerceClient = class {
|
|
|
165
168
|
}
|
|
166
169
|
this.baseUrl = resolvedBase;
|
|
167
170
|
this.timeout = options.timeout || DEFAULT_TIMEOUT;
|
|
171
|
+
if (options.origin) {
|
|
172
|
+
this.origin = options.origin;
|
|
173
|
+
} else if (typeof window === "undefined") {
|
|
174
|
+
try {
|
|
175
|
+
const parsed = new URL(resolvedBase);
|
|
176
|
+
this.origin = parsed.origin;
|
|
177
|
+
} catch {
|
|
178
|
+
}
|
|
179
|
+
}
|
|
168
180
|
this.proxyMode = options.proxyMode || false;
|
|
169
181
|
this.onAuthError = options.onAuthError;
|
|
170
182
|
this.hydrateSessionCart();
|
|
@@ -269,14 +281,18 @@ var BrainerceClient = class {
|
|
|
269
281
|
const controller = new AbortController();
|
|
270
282
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
271
283
|
try {
|
|
284
|
+
const headers = {
|
|
285
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
286
|
+
"Content-Type": "application/json",
|
|
287
|
+
"X-SDK-Version": SDK_VERSION,
|
|
288
|
+
"ngrok-skip-browser-warning": "true"
|
|
289
|
+
};
|
|
290
|
+
if (this.origin) {
|
|
291
|
+
headers["Origin"] = this.origin;
|
|
292
|
+
}
|
|
272
293
|
const response = await fetch(url.toString(), {
|
|
273
294
|
method,
|
|
274
|
-
headers
|
|
275
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
276
|
-
"Content-Type": "application/json",
|
|
277
|
-
"X-SDK-Version": "0.3.0",
|
|
278
|
-
"ngrok-skip-browser-warning": "true"
|
|
279
|
-
},
|
|
295
|
+
headers,
|
|
280
296
|
body: body ? JSON.stringify(body) : void 0,
|
|
281
297
|
signal: controller.signal
|
|
282
298
|
});
|
|
@@ -326,9 +342,12 @@ var BrainerceClient = class {
|
|
|
326
342
|
try {
|
|
327
343
|
const headers = {
|
|
328
344
|
"Content-Type": "application/json",
|
|
329
|
-
"X-SDK-Version":
|
|
345
|
+
"X-SDK-Version": SDK_VERSION,
|
|
330
346
|
"ngrok-skip-browser-warning": "true"
|
|
331
347
|
};
|
|
348
|
+
if (this.origin) {
|
|
349
|
+
headers["Origin"] = this.origin;
|
|
350
|
+
}
|
|
332
351
|
if (this.proxyMode && method !== "GET") {
|
|
333
352
|
headers["X-Requested-With"] = "brainerce";
|
|
334
353
|
}
|
|
@@ -394,9 +413,12 @@ var BrainerceClient = class {
|
|
|
394
413
|
try {
|
|
395
414
|
const headers = {
|
|
396
415
|
"Content-Type": "application/json",
|
|
397
|
-
"X-SDK-Version":
|
|
416
|
+
"X-SDK-Version": SDK_VERSION,
|
|
398
417
|
"ngrok-skip-browser-warning": "true"
|
|
399
418
|
};
|
|
419
|
+
if (this.origin) {
|
|
420
|
+
headers["Origin"] = this.origin;
|
|
421
|
+
}
|
|
400
422
|
if (this.customerToken) {
|
|
401
423
|
headers["Authorization"] = `Bearer ${this.customerToken}`;
|
|
402
424
|
}
|
|
@@ -5856,6 +5878,34 @@ function getVariantOptions(variant) {
|
|
|
5856
5878
|
]);
|
|
5857
5879
|
return Object.entries(variant.attributes).filter(([key, value]) => typeof value === "string" && !internalKeys.has(key)).map(([name, value]) => ({ name, value }));
|
|
5858
5880
|
}
|
|
5881
|
+
function getProductSwatches(product) {
|
|
5882
|
+
if (!product?.productAttributeOptions) return [];
|
|
5883
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
5884
|
+
for (const pao of product.productAttributeOptions) {
|
|
5885
|
+
if (!pao.attribute || !pao.attributeOption) continue;
|
|
5886
|
+
const attrName = pao.attribute.name;
|
|
5887
|
+
if (!grouped.has(attrName)) {
|
|
5888
|
+
grouped.set(attrName, {
|
|
5889
|
+
displayType: pao.attribute.displayType || "DEFAULT",
|
|
5890
|
+
options: []
|
|
5891
|
+
});
|
|
5892
|
+
}
|
|
5893
|
+
const entry = grouped.get(attrName);
|
|
5894
|
+
if (!entry.options.some((o) => o.name === pao.attributeOption.name)) {
|
|
5895
|
+
entry.options.push({
|
|
5896
|
+
name: pao.attributeOption.name,
|
|
5897
|
+
value: pao.attributeOption.value,
|
|
5898
|
+
swatchColor: pao.attributeOption.swatchColor,
|
|
5899
|
+
swatchColor2: pao.attributeOption.swatchColor2,
|
|
5900
|
+
swatchImageUrl: pao.attributeOption.swatchImageUrl
|
|
5901
|
+
});
|
|
5902
|
+
}
|
|
5903
|
+
}
|
|
5904
|
+
return Array.from(grouped.entries()).map(([attributeName, data]) => ({
|
|
5905
|
+
attributeName,
|
|
5906
|
+
...data
|
|
5907
|
+
}));
|
|
5908
|
+
}
|
|
5859
5909
|
function getProductMetafield(product, key) {
|
|
5860
5910
|
return product.metafields?.find((m) => m.definitionKey === key);
|
|
5861
5911
|
}
|
|
@@ -5887,6 +5937,7 @@ function isCouponApplicableToProduct(coupon, productId) {
|
|
|
5887
5937
|
export {
|
|
5888
5938
|
BrainerceClient,
|
|
5889
5939
|
BrainerceError,
|
|
5940
|
+
SDK_VERSION,
|
|
5890
5941
|
createWebhookHandler,
|
|
5891
5942
|
enableDevGuards,
|
|
5892
5943
|
formatPrice,
|
|
@@ -5900,6 +5951,7 @@ export {
|
|
|
5900
5951
|
getProductMetafieldsByType,
|
|
5901
5952
|
getProductPrice,
|
|
5902
5953
|
getProductPriceInfo,
|
|
5954
|
+
getProductSwatches,
|
|
5903
5955
|
getStockStatus,
|
|
5904
5956
|
getVariantOptions,
|
|
5905
5957
|
getVariantPrice,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brainerce",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.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",
|
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
|
-
"README.md"
|
|
18
|
-
"AI_BUILDER_PROMPT.md"
|
|
17
|
+
"README.md"
|
|
19
18
|
],
|
|
20
19
|
"scripts": {
|
|
21
20
|
"build": "tsup src/index.ts --format cjs,esm --dts",
|