brainerce 1.0.0 → 1.0.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.
- package/AI_BUILDER_PROMPT.md +720 -716
- package/README.md +4371 -4409
- package/dist/index.d.mts +258 -219
- package/dist/index.d.ts +258 -219
- package/dist/index.js +197 -200
- package/dist/index.mjs +186 -204
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
1
|
// src/dev-guards.ts
|
|
9
2
|
var CART_GUARDS = [
|
|
10
3
|
{
|
|
@@ -137,15 +130,15 @@ var BrainerceClient = class {
|
|
|
137
130
|
* localStorage key for persisting active checkout across page redirects.
|
|
138
131
|
* This is needed because Stripe redirects lose in-memory state.
|
|
139
132
|
*/
|
|
140
|
-
this.ACTIVE_CHECKOUT_KEY = "
|
|
133
|
+
this.ACTIVE_CHECKOUT_KEY = "brainerce_active_checkout";
|
|
141
134
|
// -------------------- Local Cart (Client-Side for Guests) --------------------
|
|
142
135
|
// These methods store cart data in localStorage - NO API calls!
|
|
143
136
|
// Use for guest users in vibe-coded sites
|
|
144
|
-
this.LOCAL_CART_KEY = "
|
|
137
|
+
this.LOCAL_CART_KEY = "brainerce_cart";
|
|
145
138
|
if (!options.apiKey && !options.storeId && !options.connectionId) {
|
|
146
139
|
throw new Error("BrainerceClient: either connectionId, apiKey, or storeId is required");
|
|
147
140
|
}
|
|
148
|
-
if (options.apiKey && !options.apiKey.startsWith("brainerce_")
|
|
141
|
+
if (options.apiKey && !options.apiKey.startsWith("brainerce_")) {
|
|
149
142
|
console.warn('BrainerceClient: apiKey should start with "brainerce_"');
|
|
150
143
|
}
|
|
151
144
|
if (options.connectionId && !options.connectionId.startsWith("vc_")) {
|
|
@@ -219,11 +212,11 @@ var BrainerceClient = class {
|
|
|
219
212
|
*
|
|
220
213
|
* @example
|
|
221
214
|
* ```typescript
|
|
222
|
-
* const auth = await
|
|
223
|
-
*
|
|
215
|
+
* const auth = await client.loginCustomer('user@example.com', 'password');
|
|
216
|
+
* client.setCustomerToken(auth.token);
|
|
224
217
|
*
|
|
225
218
|
* // Now can access customer data
|
|
226
|
-
* const profile = await
|
|
219
|
+
* const profile = await client.getMyProfile();
|
|
227
220
|
* ```
|
|
228
221
|
*/
|
|
229
222
|
setCustomerToken(token) {
|
|
@@ -461,10 +454,10 @@ var BrainerceClient = class {
|
|
|
461
454
|
* @example
|
|
462
455
|
* ```typescript
|
|
463
456
|
* // Basic usage
|
|
464
|
-
* const products = await
|
|
457
|
+
* const products = await client.getProducts({ page: 1, limit: 20 });
|
|
465
458
|
*
|
|
466
459
|
* // With filters (vibe-coded mode)
|
|
467
|
-
* const filtered = await
|
|
460
|
+
* const filtered = await client.getProducts({
|
|
468
461
|
* categories: ['cat_123', 'cat_456'],
|
|
469
462
|
* minPrice: 10,
|
|
470
463
|
* maxPrice: 100,
|
|
@@ -535,7 +528,7 @@ var BrainerceClient = class {
|
|
|
535
528
|
* @example
|
|
536
529
|
* ```typescript
|
|
537
530
|
* // Get product by its URL-friendly slug
|
|
538
|
-
* const product = await
|
|
531
|
+
* const product = await client.getProductBySlug('awesome-product-name');
|
|
539
532
|
* ```
|
|
540
533
|
*/
|
|
541
534
|
async getProductBySlug(slug) {
|
|
@@ -553,7 +546,7 @@ var BrainerceClient = class {
|
|
|
553
546
|
*
|
|
554
547
|
* @example
|
|
555
548
|
* ```typescript
|
|
556
|
-
* const { categories } = await
|
|
549
|
+
* const { categories } = await client.getCategories();
|
|
557
550
|
* // categories is a tree structure with children
|
|
558
551
|
* ```
|
|
559
552
|
*/
|
|
@@ -569,7 +562,7 @@ var BrainerceClient = class {
|
|
|
569
562
|
*
|
|
570
563
|
* @example
|
|
571
564
|
* ```typescript
|
|
572
|
-
* const { brands } = await
|
|
565
|
+
* const { brands } = await client.getBrands();
|
|
573
566
|
* // Use brand IDs in getProducts({ brands: ['brand_id'] })
|
|
574
567
|
* ```
|
|
575
568
|
*/
|
|
@@ -585,7 +578,7 @@ var BrainerceClient = class {
|
|
|
585
578
|
*
|
|
586
579
|
* @example
|
|
587
580
|
* ```typescript
|
|
588
|
-
* const { tags } = await
|
|
581
|
+
* const { tags } = await client.getTags();
|
|
589
582
|
* // Use tag IDs in getProducts({ tags: ['tag_id'] })
|
|
590
583
|
* ```
|
|
591
584
|
*/
|
|
@@ -607,12 +600,12 @@ var BrainerceClient = class {
|
|
|
607
600
|
* @example
|
|
608
601
|
* ```typescript
|
|
609
602
|
* // Basic autocomplete
|
|
610
|
-
* const suggestions = await
|
|
603
|
+
* const suggestions = await client.getSearchSuggestions('shirt');
|
|
611
604
|
* console.log(suggestions.products); // [{ id, name, image, basePrice, type }]
|
|
612
605
|
* console.log(suggestions.categories); // [{ id, name, productCount }]
|
|
613
606
|
*
|
|
614
607
|
* // With custom limit
|
|
615
|
-
* const suggestions = await
|
|
608
|
+
* const suggestions = await client.getSearchSuggestions('dress', 3);
|
|
616
609
|
* ```
|
|
617
610
|
*/
|
|
618
611
|
async getSearchSuggestions(query, limit) {
|
|
@@ -665,11 +658,11 @@ var BrainerceClient = class {
|
|
|
665
658
|
*
|
|
666
659
|
* @example
|
|
667
660
|
* ```typescript
|
|
668
|
-
* // Delete from
|
|
669
|
-
* const result = await
|
|
661
|
+
* // Delete from Brainerce only
|
|
662
|
+
* const result = await client.deleteProduct('prod_123');
|
|
670
663
|
*
|
|
671
|
-
* // Delete from
|
|
672
|
-
* const result = await
|
|
664
|
+
* // Delete from Brainerce and connected platforms
|
|
665
|
+
* const result = await client.deleteProduct('prod_123', {
|
|
673
666
|
* platforms: ['SHOPIFY', 'WOOCOMMERCE']
|
|
674
667
|
* });
|
|
675
668
|
* console.log(result.success); // true
|
|
@@ -691,7 +684,7 @@ var BrainerceClient = class {
|
|
|
691
684
|
*
|
|
692
685
|
* @example
|
|
693
686
|
* ```typescript
|
|
694
|
-
* const product = await
|
|
687
|
+
* const product = await client.convertToVariable('prod_123');
|
|
695
688
|
* console.log('Product type:', product.type); // 'VARIABLE'
|
|
696
689
|
* ```
|
|
697
690
|
*/
|
|
@@ -704,7 +697,7 @@ var BrainerceClient = class {
|
|
|
704
697
|
*
|
|
705
698
|
* @example
|
|
706
699
|
* ```typescript
|
|
707
|
-
* const product = await
|
|
700
|
+
* const product = await client.convertToSimple('prod_123');
|
|
708
701
|
* console.log('Product type:', product.type); // 'SIMPLE'
|
|
709
702
|
* ```
|
|
710
703
|
*/
|
|
@@ -716,7 +709,7 @@ var BrainerceClient = class {
|
|
|
716
709
|
*
|
|
717
710
|
* @example
|
|
718
711
|
* ```typescript
|
|
719
|
-
* const result = await
|
|
712
|
+
* const result = await client.publishProduct('prod_123', ['SHOPIFY', 'WOOCOMMERCE']);
|
|
720
713
|
* console.log('Publish results:', result.results);
|
|
721
714
|
* ```
|
|
722
715
|
*/
|
|
@@ -731,7 +724,7 @@ var BrainerceClient = class {
|
|
|
731
724
|
*
|
|
732
725
|
* @example
|
|
733
726
|
* ```typescript
|
|
734
|
-
* const variant = await
|
|
727
|
+
* const variant = await client.createVariant('prod_123', {
|
|
735
728
|
* sku: 'PROD-SM-RED',
|
|
736
729
|
* name: 'Small / Red',
|
|
737
730
|
* attributes: { size: 'S', color: 'Red' },
|
|
@@ -748,7 +741,7 @@ var BrainerceClient = class {
|
|
|
748
741
|
*
|
|
749
742
|
* @example
|
|
750
743
|
* ```typescript
|
|
751
|
-
* const result = await
|
|
744
|
+
* const result = await client.bulkSaveVariants('prod_123', {
|
|
752
745
|
* variants: [
|
|
753
746
|
* { sku: 'SM-RED', attributes: { size: 'S', color: 'Red' }, stock: 10, isEnabled: true },
|
|
754
747
|
* { id: 'var_456', sku: 'MD-BLUE', attributes: { size: 'M', color: 'Blue' }, stock: 5, isEnabled: true },
|
|
@@ -770,7 +763,7 @@ var BrainerceClient = class {
|
|
|
770
763
|
*
|
|
771
764
|
* @example
|
|
772
765
|
* ```typescript
|
|
773
|
-
* const variant = await
|
|
766
|
+
* const variant = await client.updateVariant('prod_123', 'var_456', {
|
|
774
767
|
* price: 34.99,
|
|
775
768
|
* salePrice: 29.99,
|
|
776
769
|
* });
|
|
@@ -788,7 +781,7 @@ var BrainerceClient = class {
|
|
|
788
781
|
*
|
|
789
782
|
* @example
|
|
790
783
|
* ```typescript
|
|
791
|
-
* await
|
|
784
|
+
* await client.deleteVariant('prod_123', 'var_456');
|
|
792
785
|
* ```
|
|
793
786
|
*/
|
|
794
787
|
async deleteVariant(productId, variantId) {
|
|
@@ -799,7 +792,7 @@ var BrainerceClient = class {
|
|
|
799
792
|
*
|
|
800
793
|
* @example
|
|
801
794
|
* ```typescript
|
|
802
|
-
* const inventory = await
|
|
795
|
+
* const inventory = await client.getVariantInventory('prod_123', 'var_456');
|
|
803
796
|
* console.log('Available:', inventory.available);
|
|
804
797
|
* ```
|
|
805
798
|
*/
|
|
@@ -814,7 +807,7 @@ var BrainerceClient = class {
|
|
|
814
807
|
*
|
|
815
808
|
* @example
|
|
816
809
|
* ```typescript
|
|
817
|
-
* const inventory = await
|
|
810
|
+
* const inventory = await client.updateVariantInventory('prod_123', 'var_456', {
|
|
818
811
|
* newTotal: 50,
|
|
819
812
|
* reason: 'Restocked from supplier',
|
|
820
813
|
* });
|
|
@@ -867,7 +860,7 @@ var BrainerceClient = class {
|
|
|
867
860
|
*
|
|
868
861
|
* @example
|
|
869
862
|
* ```typescript
|
|
870
|
-
* const order = await
|
|
863
|
+
* const order = await client.updateOrderStatus('order_123', 'shipped');
|
|
871
864
|
* ```
|
|
872
865
|
*/
|
|
873
866
|
async updateOrderStatus(orderId, status) {
|
|
@@ -879,7 +872,7 @@ var BrainerceClient = class {
|
|
|
879
872
|
*
|
|
880
873
|
* @example
|
|
881
874
|
* ```typescript
|
|
882
|
-
* const order = await
|
|
875
|
+
* const order = await client.updatePaymentMethod('order_123', 'credit_card');
|
|
883
876
|
* ```
|
|
884
877
|
*/
|
|
885
878
|
async updatePaymentMethod(orderId, paymentMethod) {
|
|
@@ -892,7 +885,7 @@ var BrainerceClient = class {
|
|
|
892
885
|
*
|
|
893
886
|
* @example
|
|
894
887
|
* ```typescript
|
|
895
|
-
* const order = await
|
|
888
|
+
* const order = await client.updateOrderNotes('order_123', 'Customer requested gift wrapping');
|
|
896
889
|
* ```
|
|
897
890
|
*/
|
|
898
891
|
async updateOrderNotes(orderId, notes) {
|
|
@@ -904,7 +897,7 @@ var BrainerceClient = class {
|
|
|
904
897
|
*
|
|
905
898
|
* @example
|
|
906
899
|
* ```typescript
|
|
907
|
-
* const refunds = await
|
|
900
|
+
* const refunds = await client.getOrderRefunds('order_123');
|
|
908
901
|
* console.log('Total refunds:', refunds.length);
|
|
909
902
|
* ```
|
|
910
903
|
*/
|
|
@@ -918,7 +911,7 @@ var BrainerceClient = class {
|
|
|
918
911
|
* @example
|
|
919
912
|
* ```typescript
|
|
920
913
|
* // Full refund
|
|
921
|
-
* const refund = await
|
|
914
|
+
* const refund = await client.createRefund('order_123', {
|
|
922
915
|
* type: 'full',
|
|
923
916
|
* restockInventory: true,
|
|
924
917
|
* notifyCustomer: true,
|
|
@@ -926,7 +919,7 @@ var BrainerceClient = class {
|
|
|
926
919
|
* });
|
|
927
920
|
*
|
|
928
921
|
* // Partial refund
|
|
929
|
-
* const partialRefund = await
|
|
922
|
+
* const partialRefund = await client.createRefund('order_123', {
|
|
930
923
|
* type: 'partial',
|
|
931
924
|
* items: [
|
|
932
925
|
* { lineItemId: 'item_456', quantity: 1 },
|
|
@@ -944,7 +937,7 @@ var BrainerceClient = class {
|
|
|
944
937
|
*
|
|
945
938
|
* @example
|
|
946
939
|
* ```typescript
|
|
947
|
-
* const order = await
|
|
940
|
+
* const order = await client.updateOrderShipping('order_123', {
|
|
948
941
|
* firstName: 'John',
|
|
949
942
|
* lastName: 'Doe',
|
|
950
943
|
* line1: '456 New Address',
|
|
@@ -964,7 +957,7 @@ var BrainerceClient = class {
|
|
|
964
957
|
*
|
|
965
958
|
* @example
|
|
966
959
|
* ```typescript
|
|
967
|
-
* const order = await
|
|
960
|
+
* const order = await client.cancelOrder('order_123');
|
|
968
961
|
* console.log('Order status:', order.status); // 'cancelled'
|
|
969
962
|
* ```
|
|
970
963
|
*/
|
|
@@ -977,7 +970,7 @@ var BrainerceClient = class {
|
|
|
977
970
|
*
|
|
978
971
|
* @example
|
|
979
972
|
* ```typescript
|
|
980
|
-
* const order = await
|
|
973
|
+
* const order = await client.fulfillOrder('order_123', {
|
|
981
974
|
* trackingNumber: '1Z999AA10123456784',
|
|
982
975
|
* trackingCompany: 'UPS',
|
|
983
976
|
* notifyCustomer: true,
|
|
@@ -992,7 +985,7 @@ var BrainerceClient = class {
|
|
|
992
985
|
*
|
|
993
986
|
* @example
|
|
994
987
|
* ```typescript
|
|
995
|
-
* const result = await
|
|
988
|
+
* const result = await client.syncDraftOrders();
|
|
996
989
|
* console.log('Draft orders synced');
|
|
997
990
|
* ```
|
|
998
991
|
*/
|
|
@@ -1004,7 +997,7 @@ var BrainerceClient = class {
|
|
|
1004
997
|
*
|
|
1005
998
|
* @example
|
|
1006
999
|
* ```typescript
|
|
1007
|
-
* const order = await
|
|
1000
|
+
* const order = await client.completeDraftOrder('draft_123', {
|
|
1008
1001
|
* paymentPending: false,
|
|
1009
1002
|
* });
|
|
1010
1003
|
* ```
|
|
@@ -1017,7 +1010,7 @@ var BrainerceClient = class {
|
|
|
1017
1010
|
*
|
|
1018
1011
|
* @example
|
|
1019
1012
|
* ```typescript
|
|
1020
|
-
* await
|
|
1013
|
+
* await client.sendDraftInvoice('draft_123', {
|
|
1021
1014
|
* to: 'customer@example.com',
|
|
1022
1015
|
* subject: 'Your Invoice',
|
|
1023
1016
|
* customMessage: 'Thank you for your order!',
|
|
@@ -1036,7 +1029,7 @@ var BrainerceClient = class {
|
|
|
1036
1029
|
*
|
|
1037
1030
|
* @example
|
|
1038
1031
|
* ```typescript
|
|
1039
|
-
* await
|
|
1032
|
+
* await client.deleteDraftOrder('draft_123');
|
|
1040
1033
|
* ```
|
|
1041
1034
|
*/
|
|
1042
1035
|
async deleteDraftOrder(orderId) {
|
|
@@ -1047,7 +1040,7 @@ var BrainerceClient = class {
|
|
|
1047
1040
|
*
|
|
1048
1041
|
* @example
|
|
1049
1042
|
* ```typescript
|
|
1050
|
-
* const order = await
|
|
1043
|
+
* const order = await client.updateDraftOrder('draft_123', {
|
|
1051
1044
|
* note: 'Updated customer note',
|
|
1052
1045
|
* email: 'newemail@example.com',
|
|
1053
1046
|
* shippingAddress: {
|
|
@@ -1084,7 +1077,7 @@ var BrainerceClient = class {
|
|
|
1084
1077
|
*
|
|
1085
1078
|
* @example
|
|
1086
1079
|
* ```typescript
|
|
1087
|
-
* const inventory = await
|
|
1080
|
+
* const inventory = await client.editInventory({
|
|
1088
1081
|
* productId: 'prod_123',
|
|
1089
1082
|
* newTotal: 100,
|
|
1090
1083
|
* reason: 'Restocked from warehouse',
|
|
@@ -1099,7 +1092,7 @@ var BrainerceClient = class {
|
|
|
1099
1092
|
*
|
|
1100
1093
|
* @example
|
|
1101
1094
|
* ```typescript
|
|
1102
|
-
* const status = await
|
|
1095
|
+
* const status = await client.getInventorySyncStatus();
|
|
1103
1096
|
* console.log(`${status.pending} products pending sync`);
|
|
1104
1097
|
* console.log(`Last sync: ${status.lastSyncAt}`);
|
|
1105
1098
|
* ```
|
|
@@ -1112,7 +1105,7 @@ var BrainerceClient = class {
|
|
|
1112
1105
|
*
|
|
1113
1106
|
* @example
|
|
1114
1107
|
* ```typescript
|
|
1115
|
-
* const inventories = await
|
|
1108
|
+
* const inventories = await client.getBulkInventory(['prod_123', 'prod_456', 'prod_789']);
|
|
1116
1109
|
* inventories.forEach(inv => {
|
|
1117
1110
|
* console.log(`${inv.productId}: ${inv.available} available`);
|
|
1118
1111
|
* });
|
|
@@ -1128,10 +1121,10 @@ var BrainerceClient = class {
|
|
|
1128
1121
|
* @example
|
|
1129
1122
|
* ```typescript
|
|
1130
1123
|
* // Reconcile single product (dry run)
|
|
1131
|
-
* const result = await
|
|
1124
|
+
* const result = await client.reconcileInventory({ productId: 'prod_123' });
|
|
1132
1125
|
*
|
|
1133
1126
|
* // Reconcile all products with auto-fix
|
|
1134
|
-
* const summary = await
|
|
1127
|
+
* const summary = await client.reconcileInventory({ autoFix: true });
|
|
1135
1128
|
* console.log(`Reconciled ${summary.reconciled} products`);
|
|
1136
1129
|
* ```
|
|
1137
1130
|
*/
|
|
@@ -1153,7 +1146,7 @@ var BrainerceClient = class {
|
|
|
1153
1146
|
* @example
|
|
1154
1147
|
* ```typescript
|
|
1155
1148
|
* // Check if items are available before adding to cart
|
|
1156
|
-
* const result = await
|
|
1149
|
+
* const result = await client.checkStockAvailability([
|
|
1157
1150
|
* { productId: 'prod_123', quantity: 2 },
|
|
1158
1151
|
* { productId: 'prod_456', variantId: 'var_789', quantity: 1 }
|
|
1159
1152
|
* ]);
|
|
@@ -1203,10 +1196,10 @@ var BrainerceClient = class {
|
|
|
1203
1196
|
* @example
|
|
1204
1197
|
* ```typescript
|
|
1205
1198
|
* // Check all cart items (full checkout)
|
|
1206
|
-
* const result = await
|
|
1199
|
+
* const result = await client.checkCartStock(cart);
|
|
1207
1200
|
*
|
|
1208
1201
|
* // Check only selected items (partial checkout - server cart only)
|
|
1209
|
-
* const result = await
|
|
1202
|
+
* const result = await client.checkCartStock(cart, ['item_1', 'item_3']);
|
|
1210
1203
|
*
|
|
1211
1204
|
* if (!result.allAvailable) {
|
|
1212
1205
|
* const unavailable = result.results.filter(r => !r.isAvailable);
|
|
@@ -1268,7 +1261,7 @@ var BrainerceClient = class {
|
|
|
1268
1261
|
*
|
|
1269
1262
|
* @example
|
|
1270
1263
|
* ```typescript
|
|
1271
|
-
* const coupon = await
|
|
1264
|
+
* const coupon = await client.createCoupon({
|
|
1272
1265
|
* code: 'SUMMER20',
|
|
1273
1266
|
* type: 'PERCENTAGE',
|
|
1274
1267
|
* value: 20,
|
|
@@ -1312,7 +1305,7 @@ var BrainerceClient = class {
|
|
|
1312
1305
|
* @example
|
|
1313
1306
|
* ```typescript
|
|
1314
1307
|
* // Only sync to WooCommerce and Shopify
|
|
1315
|
-
* await
|
|
1308
|
+
* await client.publishCoupon('coupon_123', ['WOOCOMMERCE', 'SHOPIFY']);
|
|
1316
1309
|
* ```
|
|
1317
1310
|
*/
|
|
1318
1311
|
async publishCoupon(couponId, platforms) {
|
|
@@ -1324,7 +1317,7 @@ var BrainerceClient = class {
|
|
|
1324
1317
|
*
|
|
1325
1318
|
* @example
|
|
1326
1319
|
* ```typescript
|
|
1327
|
-
* const capabilities = await
|
|
1320
|
+
* const capabilities = await client.getCouponPlatformCapabilities();
|
|
1328
1321
|
* if (!capabilities.SHOPIFY.supportsProductExclusions) {
|
|
1329
1322
|
* console.log('Shopify does not support product exclusions');
|
|
1330
1323
|
* }
|
|
@@ -1342,7 +1335,7 @@ var BrainerceClient = class {
|
|
|
1342
1335
|
*
|
|
1343
1336
|
* @example
|
|
1344
1337
|
* ```typescript
|
|
1345
|
-
* const customer = await
|
|
1338
|
+
* const customer = await client.createCustomer({
|
|
1346
1339
|
* email: 'customer@example.com',
|
|
1347
1340
|
* firstName: 'John',
|
|
1348
1341
|
* lastName: 'Doe',
|
|
@@ -1377,7 +1370,7 @@ var BrainerceClient = class {
|
|
|
1377
1370
|
*
|
|
1378
1371
|
* @example
|
|
1379
1372
|
* ```typescript
|
|
1380
|
-
* const auth = await
|
|
1373
|
+
* const auth = await client.loginCustomer('customer@example.com', 'password123');
|
|
1381
1374
|
* console.log('Customer logged in:', auth.customer.email);
|
|
1382
1375
|
* // Store auth.token for subsequent authenticated requests
|
|
1383
1376
|
* ```
|
|
@@ -1406,7 +1399,7 @@ var BrainerceClient = class {
|
|
|
1406
1399
|
*
|
|
1407
1400
|
* @example
|
|
1408
1401
|
* ```typescript
|
|
1409
|
-
* const auth = await
|
|
1402
|
+
* const auth = await client.registerCustomer({
|
|
1410
1403
|
* email: 'newcustomer@example.com',
|
|
1411
1404
|
* password: 'securepassword123',
|
|
1412
1405
|
* firstName: 'Jane',
|
|
@@ -1452,14 +1445,14 @@ var BrainerceClient = class {
|
|
|
1452
1445
|
* @example
|
|
1453
1446
|
* ```typescript
|
|
1454
1447
|
* // Option 1: Pass token directly (recommended for verification flow)
|
|
1455
|
-
* const auth = await
|
|
1448
|
+
* const auth = await client.registerCustomer({...});
|
|
1456
1449
|
* if (auth.requiresVerification) {
|
|
1457
|
-
* const result = await
|
|
1450
|
+
* const result = await client.verifyEmail('123456', auth.token);
|
|
1458
1451
|
* }
|
|
1459
1452
|
*
|
|
1460
1453
|
* // Option 2: Use setCustomerToken first
|
|
1461
|
-
*
|
|
1462
|
-
* const result = await
|
|
1454
|
+
* client.setCustomerToken(auth.token);
|
|
1455
|
+
* const result = await client.verifyEmail('123456');
|
|
1463
1456
|
* ```
|
|
1464
1457
|
*/
|
|
1465
1458
|
async verifyEmail(code, token) {
|
|
@@ -1501,11 +1494,11 @@ var BrainerceClient = class {
|
|
|
1501
1494
|
* @example
|
|
1502
1495
|
* ```typescript
|
|
1503
1496
|
* // Option 1: Pass token directly
|
|
1504
|
-
* await
|
|
1497
|
+
* await client.resendVerificationEmail(auth.token);
|
|
1505
1498
|
*
|
|
1506
1499
|
* // Option 2: Use setCustomerToken first
|
|
1507
|
-
*
|
|
1508
|
-
* await
|
|
1500
|
+
* client.setCustomerToken(auth.token);
|
|
1501
|
+
* await client.resendVerificationEmail();
|
|
1509
1502
|
* ```
|
|
1510
1503
|
*/
|
|
1511
1504
|
async resendVerificationEmail(token) {
|
|
@@ -1546,7 +1539,7 @@ var BrainerceClient = class {
|
|
|
1546
1539
|
*
|
|
1547
1540
|
* @example
|
|
1548
1541
|
* ```typescript
|
|
1549
|
-
* const { providers } = await
|
|
1542
|
+
* const { providers } = await client.getAvailableOAuthProviders();
|
|
1550
1543
|
* // providers: ['GOOGLE', 'FACEBOOK'] - array of strings, not objects!
|
|
1551
1544
|
*
|
|
1552
1545
|
* // To display with friendly names:
|
|
@@ -1586,7 +1579,7 @@ var BrainerceClient = class {
|
|
|
1586
1579
|
* @example
|
|
1587
1580
|
* ```typescript
|
|
1588
1581
|
* // Get authorization URL (redirectUrl MUST be absolute with origin)
|
|
1589
|
-
* const { authorizationUrl } = await
|
|
1582
|
+
* const { authorizationUrl } = await client.getOAuthAuthorizeUrl('GOOGLE', {
|
|
1590
1583
|
* redirectUrl: window.location.origin + '/auth/callback'
|
|
1591
1584
|
* });
|
|
1592
1585
|
*
|
|
@@ -1597,7 +1590,7 @@ var BrainerceClient = class {
|
|
|
1597
1590
|
* const params = new URLSearchParams(window.location.search);
|
|
1598
1591
|
* if (params.get('oauth_success') === 'true') {
|
|
1599
1592
|
* const token = params.get('token');
|
|
1600
|
-
*
|
|
1593
|
+
* client.setCustomerToken(token);
|
|
1601
1594
|
* // Also available: customer_id, customer_email, is_new
|
|
1602
1595
|
* } else if (params.get('oauth_error')) {
|
|
1603
1596
|
* // Show error
|
|
@@ -1666,10 +1659,10 @@ var BrainerceClient = class {
|
|
|
1666
1659
|
* @example
|
|
1667
1660
|
* ```typescript
|
|
1668
1661
|
* // Customer must be logged in first
|
|
1669
|
-
*
|
|
1662
|
+
* client.setCustomerToken(auth.token);
|
|
1670
1663
|
*
|
|
1671
1664
|
* // Get authorization URL for linking
|
|
1672
|
-
* const { authorizationUrl } = await
|
|
1665
|
+
* const { authorizationUrl } = await client.linkOAuthProvider('GITHUB', {
|
|
1673
1666
|
* redirectUrl: '/settings'
|
|
1674
1667
|
* });
|
|
1675
1668
|
*
|
|
@@ -1706,8 +1699,8 @@ var BrainerceClient = class {
|
|
|
1706
1699
|
*
|
|
1707
1700
|
* @example
|
|
1708
1701
|
* ```typescript
|
|
1709
|
-
*
|
|
1710
|
-
* await
|
|
1702
|
+
* client.setCustomerToken(auth.token);
|
|
1703
|
+
* await client.unlinkOAuthProvider('FACEBOOK');
|
|
1711
1704
|
* ```
|
|
1712
1705
|
*/
|
|
1713
1706
|
async unlinkOAuthProvider(provider) {
|
|
@@ -1731,8 +1724,8 @@ var BrainerceClient = class {
|
|
|
1731
1724
|
*
|
|
1732
1725
|
* @example
|
|
1733
1726
|
* ```typescript
|
|
1734
|
-
*
|
|
1735
|
-
* const { connections } = await
|
|
1727
|
+
* client.setCustomerToken(auth.token);
|
|
1728
|
+
* const { connections } = await client.getOAuthConnections();
|
|
1736
1729
|
* // connections: [{ id: '...', provider: 'GOOGLE', email: 'user@gmail.com', createdAt: '...' }]
|
|
1737
1730
|
* ```
|
|
1738
1731
|
*/
|
|
@@ -1762,10 +1755,10 @@ var BrainerceClient = class {
|
|
|
1762
1755
|
* @example
|
|
1763
1756
|
* ```typescript
|
|
1764
1757
|
* // After login/register, set the token
|
|
1765
|
-
*
|
|
1758
|
+
* client.setCustomerToken(auth.token);
|
|
1766
1759
|
*
|
|
1767
1760
|
* // Then get the profile
|
|
1768
|
-
* const profile = await
|
|
1761
|
+
* const profile = await client.getCustomerProfile();
|
|
1769
1762
|
* console.log('Customer:', profile.email);
|
|
1770
1763
|
* ```
|
|
1771
1764
|
*/
|
|
@@ -1795,7 +1788,7 @@ var BrainerceClient = class {
|
|
|
1795
1788
|
*
|
|
1796
1789
|
* @example
|
|
1797
1790
|
* ```typescript
|
|
1798
|
-
* const address = await
|
|
1791
|
+
* const address = await client.addCustomerAddress('cust_123', {
|
|
1799
1792
|
* firstName: 'John',
|
|
1800
1793
|
* lastName: 'Doe',
|
|
1801
1794
|
* line1: '123 Main St',
|
|
@@ -1835,7 +1828,7 @@ var BrainerceClient = class {
|
|
|
1835
1828
|
*
|
|
1836
1829
|
* @example
|
|
1837
1830
|
* ```typescript
|
|
1838
|
-
* const orders = await
|
|
1831
|
+
* const orders = await client.getCustomerOrders('cust_123', { page: 1, limit: 10 });
|
|
1839
1832
|
* console.log(`Customer has ${orders.meta.total} total orders`);
|
|
1840
1833
|
* ```
|
|
1841
1834
|
*/
|
|
@@ -1854,7 +1847,7 @@ var BrainerceClient = class {
|
|
|
1854
1847
|
*
|
|
1855
1848
|
* @example
|
|
1856
1849
|
* ```typescript
|
|
1857
|
-
* const cart = await
|
|
1850
|
+
* const cart = await client.createCart();
|
|
1858
1851
|
* console.log('Cart session:', cart.sessionToken);
|
|
1859
1852
|
* // Store sessionToken in localStorage or cookie
|
|
1860
1853
|
* ```
|
|
@@ -1877,7 +1870,7 @@ var BrainerceClient = class {
|
|
|
1877
1870
|
*
|
|
1878
1871
|
* @example
|
|
1879
1872
|
* ```typescript
|
|
1880
|
-
* const cart = await
|
|
1873
|
+
* const cart = await client.getCartBySession('sess_abc123');
|
|
1881
1874
|
* console.log('Items in cart:', cart.itemCount);
|
|
1882
1875
|
* ```
|
|
1883
1876
|
*/
|
|
@@ -1892,7 +1885,7 @@ var BrainerceClient = class {
|
|
|
1892
1885
|
*
|
|
1893
1886
|
* @example
|
|
1894
1887
|
* ```typescript
|
|
1895
|
-
* const cart = await
|
|
1888
|
+
* const cart = await client.getCartByCustomer('cust_123');
|
|
1896
1889
|
* console.log('Customer cart total:', cart.subtotal);
|
|
1897
1890
|
* ```
|
|
1898
1891
|
*/
|
|
@@ -1922,7 +1915,7 @@ var BrainerceClient = class {
|
|
|
1922
1915
|
*
|
|
1923
1916
|
* @example
|
|
1924
1917
|
* ```typescript
|
|
1925
|
-
* const cart = await
|
|
1918
|
+
* const cart = await client.addToCart('cart_123', {
|
|
1926
1919
|
* productId: 'prod_abc',
|
|
1927
1920
|
* quantity: 2,
|
|
1928
1921
|
* notes: 'Gift wrap please',
|
|
@@ -1988,7 +1981,7 @@ var BrainerceClient = class {
|
|
|
1988
1981
|
*
|
|
1989
1982
|
* @example
|
|
1990
1983
|
* ```typescript
|
|
1991
|
-
* const cart = await
|
|
1984
|
+
* const cart = await client.updateCartItem('cart_123', 'item_456', { quantity: 3 });
|
|
1992
1985
|
* ```
|
|
1993
1986
|
*/
|
|
1994
1987
|
async updateCartItem(cartId, itemId, data) {
|
|
@@ -2023,7 +2016,7 @@ var BrainerceClient = class {
|
|
|
2023
2016
|
*
|
|
2024
2017
|
* @example
|
|
2025
2018
|
* ```typescript
|
|
2026
|
-
* const cart = await
|
|
2019
|
+
* const cart = await client.removeCartItem('cart_123', 'item_456');
|
|
2027
2020
|
* ```
|
|
2028
2021
|
*/
|
|
2029
2022
|
async removeCartItem(cartId, itemId) {
|
|
@@ -2058,7 +2051,7 @@ var BrainerceClient = class {
|
|
|
2058
2051
|
*
|
|
2059
2052
|
* @example
|
|
2060
2053
|
* ```typescript
|
|
2061
|
-
* await
|
|
2054
|
+
* await client.clearCart('cart_123');
|
|
2062
2055
|
* ```
|
|
2063
2056
|
*/
|
|
2064
2057
|
async clearCart(cartId) {
|
|
@@ -2081,7 +2074,7 @@ var BrainerceClient = class {
|
|
|
2081
2074
|
*
|
|
2082
2075
|
* @example
|
|
2083
2076
|
* ```typescript
|
|
2084
|
-
* const cart = await
|
|
2077
|
+
* const cart = await client.applyCoupon('cart_123', 'SAVE20');
|
|
2085
2078
|
* console.log('Discount:', cart.discountAmount);
|
|
2086
2079
|
* ```
|
|
2087
2080
|
*/
|
|
@@ -2108,7 +2101,7 @@ var BrainerceClient = class {
|
|
|
2108
2101
|
*
|
|
2109
2102
|
* @example
|
|
2110
2103
|
* ```typescript
|
|
2111
|
-
* const cart = await
|
|
2104
|
+
* const cart = await client.removeCoupon('cart_123');
|
|
2112
2105
|
* ```
|
|
2113
2106
|
*/
|
|
2114
2107
|
async removeCoupon(cartId) {
|
|
@@ -2141,8 +2134,8 @@ var BrainerceClient = class {
|
|
|
2141
2134
|
* @example
|
|
2142
2135
|
* ```typescript
|
|
2143
2136
|
* // After customer logs in
|
|
2144
|
-
*
|
|
2145
|
-
* const cart = await
|
|
2137
|
+
* client.setCustomerToken(authResponse.token);
|
|
2138
|
+
* const cart = await client.linkCart('cart_123'); // cartId is REQUIRED
|
|
2146
2139
|
* // Cart is now linked to the customer
|
|
2147
2140
|
* ```
|
|
2148
2141
|
*/
|
|
@@ -2168,7 +2161,7 @@ var BrainerceClient = class {
|
|
|
2168
2161
|
* @example
|
|
2169
2162
|
* ```typescript
|
|
2170
2163
|
* // After customer logs in, merge their guest cart
|
|
2171
|
-
* const mergedCart = await
|
|
2164
|
+
* const mergedCart = await client.mergeCarts({
|
|
2172
2165
|
* sourceSessionToken: 'sess_guest_abc',
|
|
2173
2166
|
* targetCustomerId: 'cust_123',
|
|
2174
2167
|
* });
|
|
@@ -2187,7 +2180,7 @@ var BrainerceClient = class {
|
|
|
2187
2180
|
*
|
|
2188
2181
|
* @example
|
|
2189
2182
|
* ```typescript
|
|
2190
|
-
* const banners = await
|
|
2183
|
+
* const banners = await client.getDiscountBanners();
|
|
2191
2184
|
* banners.forEach(b => console.log(b.text));
|
|
2192
2185
|
* ```
|
|
2193
2186
|
*/
|
|
@@ -2209,7 +2202,7 @@ var BrainerceClient = class {
|
|
|
2209
2202
|
*
|
|
2210
2203
|
* @example
|
|
2211
2204
|
* ```typescript
|
|
2212
|
-
* const badge = await
|
|
2205
|
+
* const badge = await client.getProductDiscountBadge('prod_123');
|
|
2213
2206
|
* if (badge) {
|
|
2214
2207
|
* console.log(badge.badgeText); // e.g., "20% OFF"
|
|
2215
2208
|
* console.log(badge.discountedPrice); // e.g., "39.99"
|
|
@@ -2242,7 +2235,7 @@ var BrainerceClient = class {
|
|
|
2242
2235
|
*
|
|
2243
2236
|
* @example
|
|
2244
2237
|
* ```typescript
|
|
2245
|
-
* const nudges = await
|
|
2238
|
+
* const nudges = await client.getCartNudges('cart_123');
|
|
2246
2239
|
* nudges.forEach(n => {
|
|
2247
2240
|
* console.log(n.text); // e.g., "Add $12.50 more for free shipping!"
|
|
2248
2241
|
* });
|
|
@@ -2267,7 +2260,7 @@ var BrainerceClient = class {
|
|
|
2267
2260
|
*
|
|
2268
2261
|
* @example
|
|
2269
2262
|
* ```typescript
|
|
2270
|
-
* const recs = await
|
|
2263
|
+
* const recs = await client.getProductRecommendations('prod_123');
|
|
2271
2264
|
* console.log(recs.crossSells); // complementary products
|
|
2272
2265
|
* console.log(recs.upsells); // premium alternatives
|
|
2273
2266
|
* console.log(recs.related); // related products
|
|
@@ -2301,7 +2294,7 @@ var BrainerceClient = class {
|
|
|
2301
2294
|
*
|
|
2302
2295
|
* @example
|
|
2303
2296
|
* ```typescript
|
|
2304
|
-
* const recs = await
|
|
2297
|
+
* const recs = await client.getCartRecommendations('cart_123', 6);
|
|
2305
2298
|
* recs.recommendations.forEach(product => {
|
|
2306
2299
|
* console.log(product.name, product.basePrice);
|
|
2307
2300
|
* });
|
|
@@ -2333,7 +2326,7 @@ var BrainerceClient = class {
|
|
|
2333
2326
|
*
|
|
2334
2327
|
* @example
|
|
2335
2328
|
* ```typescript
|
|
2336
|
-
* if (
|
|
2329
|
+
* if (client.isCustomerLoggedIn()) {
|
|
2337
2330
|
* console.log('Cart will be stored on server');
|
|
2338
2331
|
* } else {
|
|
2339
2332
|
* console.log('Cart will be stored in localStorage');
|
|
@@ -2403,7 +2396,7 @@ var BrainerceClient = class {
|
|
|
2403
2396
|
* @example
|
|
2404
2397
|
* ```typescript
|
|
2405
2398
|
* // Works the same whether logged in or not
|
|
2406
|
-
* await
|
|
2399
|
+
* await client.smartAddToCart({
|
|
2407
2400
|
* productId: 'prod_123',
|
|
2408
2401
|
* quantity: 2,
|
|
2409
2402
|
* name: 'Cool Product', // Optional: for localStorage display
|
|
@@ -2428,7 +2421,7 @@ var BrainerceClient = class {
|
|
|
2428
2421
|
*
|
|
2429
2422
|
* @example
|
|
2430
2423
|
* ```typescript
|
|
2431
|
-
* const cart = await
|
|
2424
|
+
* const cart = await client.smartGetCart();
|
|
2432
2425
|
* console.log('Items:', cart.items.length);
|
|
2433
2426
|
* ```
|
|
2434
2427
|
*/
|
|
@@ -2444,8 +2437,8 @@ var BrainerceClient = class {
|
|
|
2444
2437
|
*
|
|
2445
2438
|
* @example
|
|
2446
2439
|
* ```typescript
|
|
2447
|
-
* await
|
|
2448
|
-
* await
|
|
2440
|
+
* await client.smartUpdateCartItem('prod_123', 3); // Set quantity to 3
|
|
2441
|
+
* await client.smartUpdateCartItem('prod_123', 0); // Remove item
|
|
2449
2442
|
* ```
|
|
2450
2443
|
*/
|
|
2451
2444
|
async smartUpdateCartItem(productId, quantity, variantId) {
|
|
@@ -2470,8 +2463,8 @@ var BrainerceClient = class {
|
|
|
2470
2463
|
*
|
|
2471
2464
|
* @example
|
|
2472
2465
|
* ```typescript
|
|
2473
|
-
* await
|
|
2474
|
-
* await
|
|
2466
|
+
* await client.smartRemoveFromCart('prod_123');
|
|
2467
|
+
* await client.smartRemoveFromCart('prod_456', 'variant_789');
|
|
2475
2468
|
* ```
|
|
2476
2469
|
*/
|
|
2477
2470
|
async smartRemoveFromCart(productId, variantId) {
|
|
@@ -2491,11 +2484,11 @@ var BrainerceClient = class {
|
|
|
2491
2484
|
* @example
|
|
2492
2485
|
* ```typescript
|
|
2493
2486
|
* // Customer logs in
|
|
2494
|
-
* const auth = await
|
|
2495
|
-
*
|
|
2487
|
+
* const auth = await client.login(email, password);
|
|
2488
|
+
* client.setCustomerToken(auth.token);
|
|
2496
2489
|
*
|
|
2497
2490
|
* // Sync their local cart to server
|
|
2498
|
-
* const cart = await
|
|
2491
|
+
* const cart = await client.syncCartOnLogin();
|
|
2499
2492
|
* console.log('Cart synced, items:', cart.items.length);
|
|
2500
2493
|
* ```
|
|
2501
2494
|
*/
|
|
@@ -2532,11 +2525,11 @@ var BrainerceClient = class {
|
|
|
2532
2525
|
*
|
|
2533
2526
|
* @example
|
|
2534
2527
|
* ```typescript
|
|
2535
|
-
*
|
|
2536
|
-
*
|
|
2528
|
+
* client.clearCustomerToken();
|
|
2529
|
+
* client.onLogout();
|
|
2537
2530
|
*
|
|
2538
2531
|
* // Now back to guest mode - cart uses localStorage
|
|
2539
|
-
* await
|
|
2532
|
+
* await client.smartAddToCart({ productId: 'prod_123', quantity: 1 });
|
|
2540
2533
|
* ```
|
|
2541
2534
|
*/
|
|
2542
2535
|
onLogout() {
|
|
@@ -2552,8 +2545,8 @@ var BrainerceClient = class {
|
|
|
2552
2545
|
* ```typescript
|
|
2553
2546
|
* // After payment success
|
|
2554
2547
|
* if (paymentStatus === 'succeeded') {
|
|
2555
|
-
*
|
|
2556
|
-
*
|
|
2548
|
+
* client.onCheckoutComplete();
|
|
2549
|
+
* client.clearLocalCart(); // Also clear localStorage for guests
|
|
2557
2550
|
* }
|
|
2558
2551
|
* ```
|
|
2559
2552
|
*/
|
|
@@ -2573,10 +2566,10 @@ var BrainerceClient = class {
|
|
|
2573
2566
|
* @example
|
|
2574
2567
|
* ```typescript
|
|
2575
2568
|
* // Full cart checkout (default)
|
|
2576
|
-
* const checkout = await
|
|
2569
|
+
* const checkout = await client.createCheckout({ cartId: 'cart_123' });
|
|
2577
2570
|
*
|
|
2578
2571
|
* // Partial checkout - only buy selected items
|
|
2579
|
-
* const checkout = await
|
|
2572
|
+
* const checkout = await client.createCheckout({
|
|
2580
2573
|
* cartId: 'cart_123',
|
|
2581
2574
|
* selectedItemIds: ['item_1', 'item_3'], // Only these items will be purchased
|
|
2582
2575
|
* });
|
|
@@ -2611,7 +2604,7 @@ var BrainerceClient = class {
|
|
|
2611
2604
|
*
|
|
2612
2605
|
* @example
|
|
2613
2606
|
* ```typescript
|
|
2614
|
-
* const checkout = await
|
|
2607
|
+
* const checkout = await client.getCheckout('checkout_123');
|
|
2615
2608
|
* console.log('Status:', checkout.status);
|
|
2616
2609
|
* ```
|
|
2617
2610
|
*/
|
|
@@ -2638,7 +2631,7 @@ var BrainerceClient = class {
|
|
|
2638
2631
|
*
|
|
2639
2632
|
* @example
|
|
2640
2633
|
* ```typescript
|
|
2641
|
-
* const checkout = await
|
|
2634
|
+
* const checkout = await client.setCheckoutCustomer('checkout_123', {
|
|
2642
2635
|
* email: 'customer@example.com',
|
|
2643
2636
|
* firstName: 'John',
|
|
2644
2637
|
* lastName: 'Doe',
|
|
@@ -2663,7 +2656,7 @@ var BrainerceClient = class {
|
|
|
2663
2656
|
*
|
|
2664
2657
|
* @example
|
|
2665
2658
|
* ```typescript
|
|
2666
|
-
* const { checkout, rates } = await
|
|
2659
|
+
* const { checkout, rates } = await client.setShippingAddress('checkout_123', {
|
|
2667
2660
|
* email: 'customer@example.com', // Required!
|
|
2668
2661
|
* firstName: 'John',
|
|
2669
2662
|
* lastName: 'Doe',
|
|
@@ -2703,7 +2696,7 @@ var BrainerceClient = class {
|
|
|
2703
2696
|
*
|
|
2704
2697
|
* @example
|
|
2705
2698
|
* ```typescript
|
|
2706
|
-
* const rates = await
|
|
2699
|
+
* const rates = await client.getShippingRates('checkout_123');
|
|
2707
2700
|
* console.log('Shipping options:', rates);
|
|
2708
2701
|
* ```
|
|
2709
2702
|
*/
|
|
@@ -2731,7 +2724,7 @@ var BrainerceClient = class {
|
|
|
2731
2724
|
*
|
|
2732
2725
|
* @example
|
|
2733
2726
|
* ```typescript
|
|
2734
|
-
* const checkout = await
|
|
2727
|
+
* const checkout = await client.selectShippingMethod('checkout_123', 'rate_express');
|
|
2735
2728
|
* console.log('Shipping cost:', checkout.shippingAmount);
|
|
2736
2729
|
* ```
|
|
2737
2730
|
*/
|
|
@@ -2766,13 +2759,13 @@ var BrainerceClient = class {
|
|
|
2766
2759
|
* @example
|
|
2767
2760
|
* ```typescript
|
|
2768
2761
|
* // Use same as shipping
|
|
2769
|
-
* const checkout = await
|
|
2762
|
+
* const checkout = await client.setBillingAddress('checkout_123', {
|
|
2770
2763
|
* ...shippingAddress,
|
|
2771
2764
|
* sameAsShipping: true,
|
|
2772
2765
|
* });
|
|
2773
2766
|
*
|
|
2774
2767
|
* // Or set different billing address
|
|
2775
|
-
* const checkout = await
|
|
2768
|
+
* const checkout = await client.setBillingAddress('checkout_123', {
|
|
2776
2769
|
* firstName: 'John',
|
|
2777
2770
|
* lastName: 'Doe',
|
|
2778
2771
|
* line1: '456 Business Ave',
|
|
@@ -2810,7 +2803,7 @@ var BrainerceClient = class {
|
|
|
2810
2803
|
*
|
|
2811
2804
|
* @example
|
|
2812
2805
|
* ```typescript
|
|
2813
|
-
* const { orderId } = await
|
|
2806
|
+
* const { orderId } = await client.completeCheckout('checkout_123');
|
|
2814
2807
|
* console.log('Order created:', orderId);
|
|
2815
2808
|
* ```
|
|
2816
2809
|
*/
|
|
@@ -2849,7 +2842,7 @@ var BrainerceClient = class {
|
|
|
2849
2842
|
*
|
|
2850
2843
|
* @example
|
|
2851
2844
|
* ```typescript
|
|
2852
|
-
* const config = await
|
|
2845
|
+
* const config = await client.getPaymentConfig();
|
|
2853
2846
|
*
|
|
2854
2847
|
* // Initialize Stripe.js with the public key
|
|
2855
2848
|
* const stripe = Stripe(config.publicKey);
|
|
@@ -2882,7 +2875,7 @@ var BrainerceClient = class {
|
|
|
2882
2875
|
*
|
|
2883
2876
|
* @example
|
|
2884
2877
|
* ```typescript
|
|
2885
|
-
* const { providers, hasPayments, defaultProvider } = await
|
|
2878
|
+
* const { providers, hasPayments, defaultProvider } = await client.getPaymentProviders();
|
|
2886
2879
|
*
|
|
2887
2880
|
* if (!hasPayments) {
|
|
2888
2881
|
* // Show error: "Payment is not configured for this store"
|
|
@@ -2934,7 +2927,7 @@ var BrainerceClient = class {
|
|
|
2934
2927
|
* @example
|
|
2935
2928
|
* ```typescript
|
|
2936
2929
|
* // After completing checkout steps (shipping address, method, etc.)
|
|
2937
|
-
* const intent = await
|
|
2930
|
+
* const intent = await client.createPaymentIntent(checkout.id, {
|
|
2938
2931
|
* successUrl: `${window.location.origin}/order-confirmation?checkout_id=${checkout.id}`,
|
|
2939
2932
|
* cancelUrl: `${window.location.origin}/checkout?error=cancelled`,
|
|
2940
2933
|
* });
|
|
@@ -2981,7 +2974,7 @@ var BrainerceClient = class {
|
|
|
2981
2974
|
* @example
|
|
2982
2975
|
* ```typescript
|
|
2983
2976
|
* // After returning from Stripe redirect
|
|
2984
|
-
* const status = await
|
|
2977
|
+
* const status = await client.getPaymentStatus(checkoutId);
|
|
2985
2978
|
*
|
|
2986
2979
|
* if (status.status === 'succeeded') {
|
|
2987
2980
|
* // Redirect to order confirmation
|
|
@@ -3031,7 +3024,7 @@ var BrainerceClient = class {
|
|
|
3031
3024
|
* @example
|
|
3032
3025
|
* ```typescript
|
|
3033
3026
|
* // Basic usage - wait up to 30 seconds
|
|
3034
|
-
* const result = await
|
|
3027
|
+
* const result = await client.waitForOrder(checkoutId);
|
|
3035
3028
|
*
|
|
3036
3029
|
* if (result.success) {
|
|
3037
3030
|
* console.log('Order created:', result.status.orderNumber);
|
|
@@ -3044,7 +3037,7 @@ var BrainerceClient = class {
|
|
|
3044
3037
|
* @example
|
|
3045
3038
|
* ```typescript
|
|
3046
3039
|
* // With progress callback for UI updates
|
|
3047
|
-
* const result = await
|
|
3040
|
+
* const result = await client.waitForOrder(checkoutId, {
|
|
3048
3041
|
* maxWaitMs: 20000,
|
|
3049
3042
|
* onPollAttempt: (attempt, status) => {
|
|
3050
3043
|
* setLoadingMessage(`Confirming order... (attempt ${attempt})`);
|
|
@@ -3112,7 +3105,7 @@ var BrainerceClient = class {
|
|
|
3112
3105
|
if (typeof window === "undefined" || !window.localStorage) {
|
|
3113
3106
|
return false;
|
|
3114
3107
|
}
|
|
3115
|
-
const test = "
|
|
3108
|
+
const test = "__brainerce_test__";
|
|
3116
3109
|
window.localStorage.setItem(test, test);
|
|
3117
3110
|
window.localStorage.removeItem(test);
|
|
3118
3111
|
return true;
|
|
@@ -3126,7 +3119,7 @@ var BrainerceClient = class {
|
|
|
3126
3119
|
*
|
|
3127
3120
|
* @example
|
|
3128
3121
|
* ```typescript
|
|
3129
|
-
* const cart =
|
|
3122
|
+
* const cart = client.getLocalCart();
|
|
3130
3123
|
* console.log('Items in cart:', cart.items.length);
|
|
3131
3124
|
* ```
|
|
3132
3125
|
*/
|
|
@@ -3215,7 +3208,7 @@ var BrainerceClient = class {
|
|
|
3215
3208
|
*
|
|
3216
3209
|
* @example
|
|
3217
3210
|
* ```typescript
|
|
3218
|
-
*
|
|
3211
|
+
* client.addToLocalCart({
|
|
3219
3212
|
* productId: 'prod_123',
|
|
3220
3213
|
* quantity: 2,
|
|
3221
3214
|
* name: 'Cool Shirt',
|
|
@@ -3248,8 +3241,8 @@ var BrainerceClient = class {
|
|
|
3248
3241
|
*
|
|
3249
3242
|
* @example
|
|
3250
3243
|
* ```typescript
|
|
3251
|
-
*
|
|
3252
|
-
*
|
|
3244
|
+
* client.updateLocalCartItem('prod_123', 3); // Set quantity to 3
|
|
3245
|
+
* client.updateLocalCartItem('prod_123', 0); // Remove item
|
|
3253
3246
|
* ```
|
|
3254
3247
|
*/
|
|
3255
3248
|
updateLocalCartItem(productId, quantity, variantId) {
|
|
@@ -3272,8 +3265,8 @@ var BrainerceClient = class {
|
|
|
3272
3265
|
*
|
|
3273
3266
|
* @example
|
|
3274
3267
|
* ```typescript
|
|
3275
|
-
*
|
|
3276
|
-
*
|
|
3268
|
+
* client.removeFromLocalCart('prod_123');
|
|
3269
|
+
* client.removeFromLocalCart('prod_456', 'variant_789');
|
|
3277
3270
|
* ```
|
|
3278
3271
|
*/
|
|
3279
3272
|
removeFromLocalCart(productId, variantId) {
|
|
@@ -3284,7 +3277,7 @@ var BrainerceClient = class {
|
|
|
3284
3277
|
*
|
|
3285
3278
|
* @example
|
|
3286
3279
|
* ```typescript
|
|
3287
|
-
*
|
|
3280
|
+
* client.clearLocalCart();
|
|
3288
3281
|
* ```
|
|
3289
3282
|
*/
|
|
3290
3283
|
clearLocalCart() {
|
|
@@ -3297,7 +3290,7 @@ var BrainerceClient = class {
|
|
|
3297
3290
|
*
|
|
3298
3291
|
* @example
|
|
3299
3292
|
* ```typescript
|
|
3300
|
-
*
|
|
3293
|
+
* client.setLocalCartCustomer({
|
|
3301
3294
|
* email: 'john@example.com',
|
|
3302
3295
|
* firstName: 'John',
|
|
3303
3296
|
* lastName: 'Doe',
|
|
@@ -3315,7 +3308,7 @@ var BrainerceClient = class {
|
|
|
3315
3308
|
*
|
|
3316
3309
|
* @example
|
|
3317
3310
|
* ```typescript
|
|
3318
|
-
*
|
|
3311
|
+
* client.setLocalCartShippingAddress({
|
|
3319
3312
|
* firstName: 'John',
|
|
3320
3313
|
* lastName: 'Doe',
|
|
3321
3314
|
* line1: '123 Main St',
|
|
@@ -3368,12 +3361,12 @@ var BrainerceClient = class {
|
|
|
3368
3361
|
* @example
|
|
3369
3362
|
* ```typescript
|
|
3370
3363
|
* // Build up the local cart first
|
|
3371
|
-
*
|
|
3372
|
-
*
|
|
3373
|
-
*
|
|
3364
|
+
* client.addToLocalCart({ productId: 'prod_123', quantity: 2 });
|
|
3365
|
+
* client.setLocalCartCustomer({ email: 'john@example.com', firstName: 'John' });
|
|
3366
|
+
* client.setLocalCartShippingAddress({ ... });
|
|
3374
3367
|
*
|
|
3375
3368
|
* // Then submit the order - tracking is automatic if enabled in admin!
|
|
3376
|
-
* const result = await
|
|
3369
|
+
* const result = await client.submitGuestOrder();
|
|
3377
3370
|
* console.log('Order created:', result.orderId);
|
|
3378
3371
|
*
|
|
3379
3372
|
* // Cart is automatically cleared on success
|
|
@@ -3456,14 +3449,14 @@ var BrainerceClient = class {
|
|
|
3456
3449
|
* @example
|
|
3457
3450
|
* ```typescript
|
|
3458
3451
|
* // Full checkout (all items)
|
|
3459
|
-
* const result = await
|
|
3452
|
+
* const result = await client.startGuestCheckout();
|
|
3460
3453
|
*
|
|
3461
3454
|
* // Partial checkout (only items at index 0 and 2)
|
|
3462
|
-
* const result = await
|
|
3455
|
+
* const result = await client.startGuestCheckout({ selectedIndices: [0, 2] });
|
|
3463
3456
|
*
|
|
3464
3457
|
* if (result.tracked) {
|
|
3465
3458
|
* // IMPORTANT: Fetch checkout and use checkout.lineItems for Order Summary!
|
|
3466
|
-
* const checkout = await
|
|
3459
|
+
* const checkout = await client.getCheckout(result.checkoutId);
|
|
3467
3460
|
*
|
|
3468
3461
|
* // Display Order Summary using checkout.lineItems (NOT localCart.items!)
|
|
3469
3462
|
* // checkout.lineItems contains ONLY the selected items
|
|
@@ -3472,15 +3465,15 @@ var BrainerceClient = class {
|
|
|
3472
3465
|
* });
|
|
3473
3466
|
*
|
|
3474
3467
|
* // Update checkout with address
|
|
3475
|
-
* await
|
|
3468
|
+
* await client.updateGuestCheckoutAddress(result.checkoutId, {
|
|
3476
3469
|
* shippingAddress: { ... },
|
|
3477
3470
|
* });
|
|
3478
3471
|
*
|
|
3479
3472
|
* // After payment success, call handlePaymentSuccess() to clear cart
|
|
3480
|
-
*
|
|
3473
|
+
* client.handlePaymentSuccess(result.checkoutId);
|
|
3481
3474
|
* } else {
|
|
3482
3475
|
* // Tracking not enabled, use regular submitGuestOrder
|
|
3483
|
-
* const order = await
|
|
3476
|
+
* const order = await client.submitGuestOrder();
|
|
3484
3477
|
* }
|
|
3485
3478
|
* ```
|
|
3486
3479
|
*/
|
|
@@ -3556,7 +3549,7 @@ var BrainerceClient = class {
|
|
|
3556
3549
|
* @example
|
|
3557
3550
|
* ```typescript
|
|
3558
3551
|
* // After partial checkout success, remove purchased items
|
|
3559
|
-
*
|
|
3552
|
+
* client.removeLocalCartItemsByIndex([0, 2]); // Removes items at index 0 and 2
|
|
3560
3553
|
* ```
|
|
3561
3554
|
*/
|
|
3562
3555
|
removeLocalCartItemsByIndex(indices) {
|
|
@@ -3612,13 +3605,13 @@ var BrainerceClient = class {
|
|
|
3612
3605
|
*
|
|
3613
3606
|
* @example Full checkout (clears entire cart):
|
|
3614
3607
|
* ```typescript
|
|
3615
|
-
* await
|
|
3608
|
+
* await client.completeGuestCheckout(checkoutId);
|
|
3616
3609
|
* ```
|
|
3617
3610
|
*
|
|
3618
3611
|
* @example Partial checkout (removes only purchased items):
|
|
3619
3612
|
* ```typescript
|
|
3620
3613
|
* // User selected items at indices 0 and 2 for checkout
|
|
3621
|
-
* await
|
|
3614
|
+
* await client.completeGuestCheckout(checkoutId, { selectedIndices: [0, 2] });
|
|
3622
3615
|
* // Items at indices 1, 3, etc. remain in cart
|
|
3623
3616
|
* ```
|
|
3624
3617
|
*/
|
|
@@ -3648,7 +3641,7 @@ var BrainerceClient = class {
|
|
|
3648
3641
|
*
|
|
3649
3642
|
* @example
|
|
3650
3643
|
* ```typescript
|
|
3651
|
-
* const activeCheckout =
|
|
3644
|
+
* const activeCheckout = client.getActiveGuestCheckout();
|
|
3652
3645
|
* if (activeCheckout) {
|
|
3653
3646
|
* console.log('Active checkout:', activeCheckout.checkoutId);
|
|
3654
3647
|
* console.log('Partial checkout:', activeCheckout.selectedIndices?.length);
|
|
@@ -3689,7 +3682,7 @@ var BrainerceClient = class {
|
|
|
3689
3682
|
*
|
|
3690
3683
|
* if (!error && paymentIntent?.status === 'succeeded') {
|
|
3691
3684
|
* // Clear the cart automatically - handles all scenarios!
|
|
3692
|
-
* const result =
|
|
3685
|
+
* const result = client.handlePaymentSuccess(checkoutId);
|
|
3693
3686
|
* console.log('Cart cleared:', result.cleared);
|
|
3694
3687
|
* console.log('User type:', result.userType); // 'guest' or 'customer'
|
|
3695
3688
|
* }
|
|
@@ -3700,13 +3693,13 @@ var BrainerceClient = class {
|
|
|
3700
3693
|
* // On success page (after redirect)
|
|
3701
3694
|
* const checkoutId = new URLSearchParams(location.search).get('checkout_id');
|
|
3702
3695
|
* if (checkoutId) {
|
|
3703
|
-
*
|
|
3696
|
+
* client.handlePaymentSuccess(checkoutId);
|
|
3704
3697
|
* }
|
|
3705
3698
|
* ```
|
|
3706
3699
|
*/
|
|
3707
3700
|
handlePaymentSuccess(checkoutId) {
|
|
3708
3701
|
const isLoggedIn = this.isCustomerLoggedIn();
|
|
3709
|
-
const handledKey = `
|
|
3702
|
+
const handledKey = `brainerce_payment_handled_${checkoutId || "latest"}`;
|
|
3710
3703
|
if (typeof window !== "undefined" && window.sessionStorage) {
|
|
3711
3704
|
if (sessionStorage.getItem(handledKey)) {
|
|
3712
3705
|
return {
|
|
@@ -3766,7 +3759,7 @@ var BrainerceClient = class {
|
|
|
3766
3759
|
*
|
|
3767
3760
|
* @example
|
|
3768
3761
|
* ```typescript
|
|
3769
|
-
* const result = await
|
|
3762
|
+
* const result = await client.createGuestOrder({
|
|
3770
3763
|
* items: [{ productId: 'prod_123', quantity: 2 }],
|
|
3771
3764
|
* customer: { email: 'john@example.com' },
|
|
3772
3765
|
* shippingAddress: { firstName: 'John', ... },
|
|
@@ -3784,9 +3777,9 @@ var BrainerceClient = class {
|
|
|
3784
3777
|
*
|
|
3785
3778
|
* @example
|
|
3786
3779
|
* ```typescript
|
|
3787
|
-
* const auth = await
|
|
3788
|
-
*
|
|
3789
|
-
* const profile = await
|
|
3780
|
+
* const auth = await client.loginCustomer('user@example.com', 'password');
|
|
3781
|
+
* client.setCustomerToken(auth.token);
|
|
3782
|
+
* const profile = await client.getMyProfile();
|
|
3790
3783
|
* ```
|
|
3791
3784
|
*/
|
|
3792
3785
|
async getMyProfile() {
|
|
@@ -3814,9 +3807,9 @@ var BrainerceClient = class {
|
|
|
3814
3807
|
*
|
|
3815
3808
|
* @example
|
|
3816
3809
|
* ```typescript
|
|
3817
|
-
*
|
|
3810
|
+
* client.setCustomerToken(auth.token);
|
|
3818
3811
|
*
|
|
3819
|
-
* const prefill = await
|
|
3812
|
+
* const prefill = await client.getCheckoutPrefillData();
|
|
3820
3813
|
*
|
|
3821
3814
|
* if (prefill.shippingAddress) {
|
|
3822
3815
|
* // Pre-fill shipping form with customer's default address
|
|
@@ -3913,7 +3906,7 @@ var BrainerceClient = class {
|
|
|
3913
3906
|
*
|
|
3914
3907
|
* @example
|
|
3915
3908
|
* ```typescript
|
|
3916
|
-
* const links = await
|
|
3909
|
+
* const links = await client.getOrderDownloads('order_123');
|
|
3917
3910
|
* for (const link of links) {
|
|
3918
3911
|
* console.log(`${link.productName}: ${link.downloadUrl}`);
|
|
3919
3912
|
* }
|
|
@@ -4066,7 +4059,7 @@ var BrainerceClient = class {
|
|
|
4066
4059
|
*
|
|
4067
4060
|
* @example
|
|
4068
4061
|
* ```typescript
|
|
4069
|
-
* const integrations = await
|
|
4062
|
+
* const integrations = await client.getCustomApiIntegrations();
|
|
4070
4063
|
* integrations.forEach(api => {
|
|
4071
4064
|
* console.log(`${api.name}: ${api.status}`);
|
|
4072
4065
|
* });
|
|
@@ -4081,7 +4074,7 @@ var BrainerceClient = class {
|
|
|
4081
4074
|
*
|
|
4082
4075
|
* @example
|
|
4083
4076
|
* ```typescript
|
|
4084
|
-
* const api = await
|
|
4077
|
+
* const api = await client.getCustomApiIntegration('api_123');
|
|
4085
4078
|
* console.log(`API: ${api.name}, URL: ${api.baseUrl}`);
|
|
4086
4079
|
* ```
|
|
4087
4080
|
*/
|
|
@@ -4094,7 +4087,7 @@ var BrainerceClient = class {
|
|
|
4094
4087
|
*
|
|
4095
4088
|
* @example
|
|
4096
4089
|
* ```typescript
|
|
4097
|
-
* const api = await
|
|
4090
|
+
* const api = await client.createCustomApiIntegration({
|
|
4098
4091
|
* name: 'My External API',
|
|
4099
4092
|
* baseUrl: 'https://api.example.com',
|
|
4100
4093
|
* authType: 'api_key',
|
|
@@ -4120,7 +4113,7 @@ var BrainerceClient = class {
|
|
|
4120
4113
|
*
|
|
4121
4114
|
* @example
|
|
4122
4115
|
* ```typescript
|
|
4123
|
-
* const api = await
|
|
4116
|
+
* const api = await client.updateCustomApiIntegration('api_123', {
|
|
4124
4117
|
* enabled: false,
|
|
4125
4118
|
* syncConfig: { products: true, orders: false, inventory: true },
|
|
4126
4119
|
* });
|
|
@@ -4139,7 +4132,7 @@ var BrainerceClient = class {
|
|
|
4139
4132
|
*
|
|
4140
4133
|
* @example
|
|
4141
4134
|
* ```typescript
|
|
4142
|
-
* await
|
|
4135
|
+
* await client.deleteCustomApiIntegration('api_123');
|
|
4143
4136
|
* ```
|
|
4144
4137
|
*/
|
|
4145
4138
|
async deleteCustomApiIntegration(integrationId) {
|
|
@@ -4151,7 +4144,7 @@ var BrainerceClient = class {
|
|
|
4151
4144
|
*
|
|
4152
4145
|
* @example
|
|
4153
4146
|
* ```typescript
|
|
4154
|
-
* const result = await
|
|
4147
|
+
* const result = await client.testCustomApiConnection('api_123');
|
|
4155
4148
|
* if (result.success) {
|
|
4156
4149
|
* console.log(`Connection OK, latency: ${result.latency}ms`);
|
|
4157
4150
|
* } else {
|
|
@@ -4179,7 +4172,7 @@ var BrainerceClient = class {
|
|
|
4179
4172
|
*
|
|
4180
4173
|
* @example
|
|
4181
4174
|
* ```typescript
|
|
4182
|
-
* const availability = await
|
|
4175
|
+
* const availability = await client.getAvailability(['prod_123', 'prod_456']);
|
|
4183
4176
|
* availability.forEach(item => {
|
|
4184
4177
|
* if (!item.canPurchase) {
|
|
4185
4178
|
* console.log(`${item.productId}: Cannot purchase`);
|
|
@@ -4213,7 +4206,7 @@ var BrainerceClient = class {
|
|
|
4213
4206
|
* @example
|
|
4214
4207
|
* ```typescript
|
|
4215
4208
|
* // Extend reservation when customer shows activity
|
|
4216
|
-
* const result = await
|
|
4209
|
+
* const result = await client.extendReservation({ checkoutId: 'chk_123' });
|
|
4217
4210
|
* if (result.success) {
|
|
4218
4211
|
* console.log(`Reservation extended until ${result.reservation.expiresAt}`);
|
|
4219
4212
|
* }
|
|
@@ -4243,7 +4236,7 @@ var BrainerceClient = class {
|
|
|
4243
4236
|
* @example
|
|
4244
4237
|
* ```typescript
|
|
4245
4238
|
* // Release reservation when customer abandons checkout
|
|
4246
|
-
* await
|
|
4239
|
+
* await client.releaseReservation({ checkoutId: 'chk_123' });
|
|
4247
4240
|
* ```
|
|
4248
4241
|
*/
|
|
4249
4242
|
async releaseReservation(options) {
|
|
@@ -4266,7 +4259,7 @@ var BrainerceClient = class {
|
|
|
4266
4259
|
*
|
|
4267
4260
|
* @example
|
|
4268
4261
|
* ```typescript
|
|
4269
|
-
* const categories = await
|
|
4262
|
+
* const categories = await client.listCategories({ page: 1, limit: 20 });
|
|
4270
4263
|
* console.log(`Found ${categories.meta.total} categories`);
|
|
4271
4264
|
* ```
|
|
4272
4265
|
*/
|
|
@@ -4291,7 +4284,7 @@ var BrainerceClient = class {
|
|
|
4291
4284
|
*
|
|
4292
4285
|
* @example
|
|
4293
4286
|
* ```typescript
|
|
4294
|
-
* const category = await
|
|
4287
|
+
* const category = await client.createCategory({
|
|
4295
4288
|
* name: 'Electronics',
|
|
4296
4289
|
* slug: 'electronics',
|
|
4297
4290
|
* description: 'Electronic devices and accessories',
|
|
@@ -4337,7 +4330,7 @@ var BrainerceClient = class {
|
|
|
4337
4330
|
*
|
|
4338
4331
|
* @example
|
|
4339
4332
|
* ```typescript
|
|
4340
|
-
* const brand = await
|
|
4333
|
+
* const brand = await client.createBrand({
|
|
4341
4334
|
* name: 'Nike',
|
|
4342
4335
|
* slug: 'nike',
|
|
4343
4336
|
* logoUrl: 'https://example.com/nike-logo.png',
|
|
@@ -4383,7 +4376,7 @@ var BrainerceClient = class {
|
|
|
4383
4376
|
*
|
|
4384
4377
|
* @example
|
|
4385
4378
|
* ```typescript
|
|
4386
|
-
* const tag = await
|
|
4379
|
+
* const tag = await client.createTag({
|
|
4387
4380
|
* name: 'New Arrival',
|
|
4388
4381
|
* slug: 'new-arrival',
|
|
4389
4382
|
* });
|
|
@@ -4433,7 +4426,7 @@ var BrainerceClient = class {
|
|
|
4433
4426
|
*
|
|
4434
4427
|
* @example
|
|
4435
4428
|
* ```typescript
|
|
4436
|
-
* const attribute = await
|
|
4429
|
+
* const attribute = await client.createAttribute({
|
|
4437
4430
|
* name: 'Color',
|
|
4438
4431
|
* slug: 'color',
|
|
4439
4432
|
* source: 'custom',
|
|
@@ -4470,7 +4463,7 @@ var BrainerceClient = class {
|
|
|
4470
4463
|
*
|
|
4471
4464
|
* @example
|
|
4472
4465
|
* ```typescript
|
|
4473
|
-
* const option = await
|
|
4466
|
+
* const option = await client.createAttributeOption('attr_123', {
|
|
4474
4467
|
* value: 'Red',
|
|
4475
4468
|
* slug: 'red',
|
|
4476
4469
|
* sortOrder: 1,
|
|
@@ -4532,7 +4525,7 @@ var BrainerceClient = class {
|
|
|
4532
4525
|
*
|
|
4533
4526
|
* @example
|
|
4534
4527
|
* ```typescript
|
|
4535
|
-
* const zone = await
|
|
4528
|
+
* const zone = await client.createShippingZone({
|
|
4536
4529
|
* name: 'US Domestic',
|
|
4537
4530
|
* countries: ['US'],
|
|
4538
4531
|
* regions: ['CA', 'NY', 'TX'],
|
|
@@ -4569,7 +4562,7 @@ var BrainerceClient = class {
|
|
|
4569
4562
|
*
|
|
4570
4563
|
* @example
|
|
4571
4564
|
* ```typescript
|
|
4572
|
-
* const rate = await
|
|
4565
|
+
* const rate = await client.createZoneShippingRate('zone_123', {
|
|
4573
4566
|
* name: 'Standard Shipping',
|
|
4574
4567
|
* type: 'flat',
|
|
4575
4568
|
* price: 5.99,
|
|
@@ -4625,7 +4618,7 @@ var BrainerceClient = class {
|
|
|
4625
4618
|
*
|
|
4626
4619
|
* @example
|
|
4627
4620
|
* ```typescript
|
|
4628
|
-
* const rate = await
|
|
4621
|
+
* const rate = await client.createTaxRate({
|
|
4629
4622
|
* name: 'California Sales Tax',
|
|
4630
4623
|
* rate: 7.25,
|
|
4631
4624
|
* country: 'US',
|
|
@@ -4711,7 +4704,7 @@ var BrainerceClient = class {
|
|
|
4711
4704
|
*
|
|
4712
4705
|
* @example
|
|
4713
4706
|
* ```typescript
|
|
4714
|
-
* const definition = await
|
|
4707
|
+
* const definition = await client.createMetafieldDefinition({
|
|
4715
4708
|
* name: 'Care Instructions',
|
|
4716
4709
|
* key: 'care_instructions',
|
|
4717
4710
|
* type: 'multi_line_text',
|
|
@@ -4758,7 +4751,7 @@ var BrainerceClient = class {
|
|
|
4758
4751
|
*
|
|
4759
4752
|
* @example
|
|
4760
4753
|
* ```typescript
|
|
4761
|
-
* const metafield = await
|
|
4754
|
+
* const metafield = await client.setProductMetafield('prod_123', 'def_456', {
|
|
4762
4755
|
* value: 'Machine wash cold, tumble dry low',
|
|
4763
4756
|
* });
|
|
4764
4757
|
* ```
|
|
@@ -4835,7 +4828,7 @@ var BrainerceClient = class {
|
|
|
4835
4828
|
*
|
|
4836
4829
|
* @example
|
|
4837
4830
|
* ```typescript
|
|
4838
|
-
* const { members, invitations } = await
|
|
4831
|
+
* const { members, invitations } = await client.getStoreTeam('store_id');
|
|
4839
4832
|
* ```
|
|
4840
4833
|
*/
|
|
4841
4834
|
async getStoreTeam(storeId) {
|
|
@@ -4847,7 +4840,7 @@ var BrainerceClient = class {
|
|
|
4847
4840
|
*
|
|
4848
4841
|
* @example
|
|
4849
4842
|
* ```typescript
|
|
4850
|
-
* const invitation = await
|
|
4843
|
+
* const invitation = await client.inviteStoreMember('store_id', {
|
|
4851
4844
|
* email: 'newmember@example.com',
|
|
4852
4845
|
* role: 'MANAGER', // 'MANAGER' | 'STAFF' | 'VIEWER'
|
|
4853
4846
|
* });
|
|
@@ -4867,10 +4860,10 @@ var BrainerceClient = class {
|
|
|
4867
4860
|
* @example
|
|
4868
4861
|
* ```typescript
|
|
4869
4862
|
* // Update role
|
|
4870
|
-
* await
|
|
4863
|
+
* await client.updateStoreMember('store_id', 'member_id', { role: 'MANAGER' });
|
|
4871
4864
|
*
|
|
4872
4865
|
* // Set custom permissions (overrides role defaults)
|
|
4873
|
-
* await
|
|
4866
|
+
* await client.updateStoreMember('store_id', 'member_id', {
|
|
4874
4867
|
* permissions: ['VIEW_PRODUCTS', 'VIEW_ORDERS', 'FULFILL_ORDERS'],
|
|
4875
4868
|
* });
|
|
4876
4869
|
* ```
|
|
@@ -4929,7 +4922,7 @@ var BrainerceClient = class {
|
|
|
4929
4922
|
*
|
|
4930
4923
|
* @example
|
|
4931
4924
|
* ```typescript
|
|
4932
|
-
* const stores = await
|
|
4925
|
+
* const stores = await client.getMyStores();
|
|
4933
4926
|
* // Returns stores from all accounts where user is owner or team member
|
|
4934
4927
|
* stores.forEach(store => {
|
|
4935
4928
|
* console.log(`${store.name} - ${store.role} (${store.context})`);
|
|
@@ -4945,7 +4938,7 @@ var BrainerceClient = class {
|
|
|
4945
4938
|
*
|
|
4946
4939
|
* @example
|
|
4947
4940
|
* ```typescript
|
|
4948
|
-
* const { role, permissions } = await
|
|
4941
|
+
* const { role, permissions } = await client.getMyStorePermissions('store_id');
|
|
4949
4942
|
* if (permissions.includes('MANAGE_TEAM')) {
|
|
4950
4943
|
* // Show team management UI
|
|
4951
4944
|
* }
|
|
@@ -4993,7 +4986,7 @@ var BrainerceClient = class {
|
|
|
4993
4986
|
*
|
|
4994
4987
|
* @example
|
|
4995
4988
|
* ```typescript
|
|
4996
|
-
* const template = await
|
|
4989
|
+
* const template = await client.createEmailTemplate({
|
|
4997
4990
|
* name: 'Order Confirmation',
|
|
4998
4991
|
* eventType: 'ORDER_CONFIRMATION',
|
|
4999
4992
|
* subject: 'Your order #{{orderNumber}} has been confirmed',
|
|
@@ -5105,7 +5098,7 @@ var BrainerceClient = class {
|
|
|
5105
5098
|
*
|
|
5106
5099
|
* @example
|
|
5107
5100
|
* ```typescript
|
|
5108
|
-
* const config = await
|
|
5101
|
+
* const config = await client.configureOAuthProvider({
|
|
5109
5102
|
* provider: 'GOOGLE',
|
|
5110
5103
|
* clientId: 'your-google-client-id',
|
|
5111
5104
|
* clientSecret: 'your-google-client-secret',
|
|
@@ -5145,6 +5138,7 @@ var BrainerceError = class extends Error {
|
|
|
5145
5138
|
};
|
|
5146
5139
|
|
|
5147
5140
|
// src/webhooks.ts
|
|
5141
|
+
import crypto from "crypto";
|
|
5148
5142
|
function verifyWebhook(payload, signature, secret) {
|
|
5149
5143
|
if (!signature || !secret) {
|
|
5150
5144
|
return false;
|
|
@@ -5154,12 +5148,6 @@ function verifyWebhook(payload, signature, secret) {
|
|
|
5154
5148
|
}
|
|
5155
5149
|
function verifyHmacSignature(payload, signature, secret) {
|
|
5156
5150
|
try {
|
|
5157
|
-
if (typeof globalThis.crypto === "undefined") {
|
|
5158
|
-
const crypto2 = __require("crypto");
|
|
5159
|
-
const expectedSignature2 = crypto2.createHmac("sha256", secret).update(payload).digest("hex");
|
|
5160
|
-
return timingSafeEqual(signature, expectedSignature2);
|
|
5161
|
-
}
|
|
5162
|
-
const crypto = __require("crypto");
|
|
5163
5151
|
const expectedSignature = crypto.createHmac("sha256", secret).update(payload).digest("hex");
|
|
5164
5152
|
return timingSafeEqual(signature, expectedSignature);
|
|
5165
5153
|
} catch (error) {
|
|
@@ -5385,15 +5373,9 @@ function isCouponApplicableToProduct(coupon, productId) {
|
|
|
5385
5373
|
}
|
|
5386
5374
|
return true;
|
|
5387
5375
|
}
|
|
5388
|
-
|
|
5389
|
-
// src/index.ts
|
|
5390
|
-
var OmniSyncClient = BrainerceClient;
|
|
5391
|
-
var OmniSyncError = BrainerceError;
|
|
5392
5376
|
export {
|
|
5393
5377
|
BrainerceClient,
|
|
5394
5378
|
BrainerceError,
|
|
5395
|
-
OmniSyncClient,
|
|
5396
|
-
OmniSyncError,
|
|
5397
5379
|
createWebhookHandler,
|
|
5398
5380
|
enableDevGuards,
|
|
5399
5381
|
formatPrice,
|