@brainerce/mcp-server 3.5.0 → 3.5.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/dist/bin/http.js +136 -88
- package/dist/bin/stdio.js +136 -88
- package/dist/index.js +136 -88
- package/dist/index.mjs +136 -88
- package/package.json +1 -1
package/dist/bin/stdio.js
CHANGED
|
@@ -93,7 +93,7 @@ npm install brainerce
|
|
|
93
93
|
import { BrainerceClient } from 'brainerce';
|
|
94
94
|
|
|
95
95
|
export const client = new BrainerceClient({
|
|
96
|
-
|
|
96
|
+
salesChannelId: '${connectionId}',
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
// Cart helpers \u2014 save cart ID to localStorage
|
|
@@ -195,7 +195,7 @@ async function startCheckout() {
|
|
|
195
195
|
### Full Checkout Flow (Multi-Provider)
|
|
196
196
|
|
|
197
197
|
1. Customer fills cart
|
|
198
|
-
2. Customer optionally applies coupon
|
|
198
|
+
2. Customer optionally applies coupon on cart page \u2192 \`applyCoupon(cartId, code)\`
|
|
199
199
|
3. Detect payment providers \u2192 \`getPaymentProviders()\`
|
|
200
200
|
4. Start checkout session (\`startGuestCheckout()\` or \`createCheckout()\`)
|
|
201
201
|
5. Set shipping address (includes required email) \u2192 \`setShippingAddress()\`
|
|
@@ -213,7 +213,7 @@ import { Elements, PaymentElement, useStripe, useElements } from '@stripe/react-
|
|
|
213
213
|
|
|
214
214
|
function CheckoutPage() {
|
|
215
215
|
const [paymentData, setPaymentData] = useState<{
|
|
216
|
-
clientSecret: string; provider: string; checkoutId: string;
|
|
216
|
+
clientSecret: string; provider: string; checkoutId: string; clientSdk?: { renderType: string };
|
|
217
217
|
} | null>(null);
|
|
218
218
|
const [stripePromise, setStripePromise] = useState<ReturnType<typeof loadStripe> | null>(null);
|
|
219
219
|
const [paypalClientId, setPaypalClientId] = useState<string | null>(null);
|
|
@@ -275,7 +275,7 @@ function CheckoutPage() {
|
|
|
275
275
|
// saveCard: customerOptedIn, // optional opt-in
|
|
276
276
|
});
|
|
277
277
|
|
|
278
|
-
setPaymentData({ clientSecret: paymentIntent.clientSecret, provider: paymentIntent.provider, checkoutId });
|
|
278
|
+
setPaymentData({ clientSecret: paymentIntent.clientSecret, provider: paymentIntent.provider, checkoutId, clientSdk: paymentIntent.clientSdk });
|
|
279
279
|
|
|
280
280
|
// Step 5: Initialize the correct payment provider
|
|
281
281
|
if (paymentIntent.provider === 'stripe' && stripeProvider) {
|
|
@@ -885,6 +885,10 @@ function ProductPage({ product, storeInfo }: { product: Product; storeInfo: Stor
|
|
|
885
885
|
? getVariantPrice(selectedVariant, product.basePrice).toString()
|
|
886
886
|
: product.salePrice || product.basePrice;
|
|
887
887
|
|
|
888
|
+
// \u2705 For catalog cards: use pre-computed priceMin/priceMax instead of iterating variants
|
|
889
|
+
// product.priceMin / product.priceMax are always set for VARIABLE products with explicit variant prices.
|
|
890
|
+
// product.priceVaries is true when the range should be shown as "\u20AA49 \u2013 \u20AA199".
|
|
891
|
+
|
|
888
892
|
// Build attribute buttons (size, color, etc.)
|
|
889
893
|
const allOptions = product.variants?.map(v => getVariantOptions(v)) || [];
|
|
890
894
|
const attrNames = [...new Set(allOptions.flatMap(opts => opts.map(o => o.name)))];
|
|
@@ -1099,6 +1103,7 @@ const total = cart.total;
|
|
|
1099
1103
|
|
|
1100
1104
|
### Coupons
|
|
1101
1105
|
|
|
1106
|
+
**On the cart page** (before checkout is created):
|
|
1102
1107
|
\`\`\`typescript
|
|
1103
1108
|
// Apply coupon \u2014 returns updated Cart with discountAmount
|
|
1104
1109
|
const updatedCart = await client.applyCoupon(cartId, 'SAVE20');
|
|
@@ -1106,13 +1111,24 @@ console.log(updatedCart.discountAmount); // "10.00"
|
|
|
1106
1111
|
console.log(updatedCart.couponCode); // "SAVE20"
|
|
1107
1112
|
|
|
1108
1113
|
// Remove coupon
|
|
1109
|
-
|
|
1114
|
+
await client.removeCoupon(cartId);
|
|
1110
1115
|
|
|
1111
1116
|
// Calculate totals including discount
|
|
1112
1117
|
const totals = getCartTotals(cart); // { subtotal, discount, shipping, total }
|
|
1113
1118
|
\`\`\`
|
|
1114
1119
|
|
|
1115
|
-
|
|
1120
|
+
**On the checkout page** (after checkout session exists \u2014 ALWAYS use this when checkoutId is available):
|
|
1121
|
+
\`\`\`typescript
|
|
1122
|
+
// Applies to cart AND updates checkout totals in one call
|
|
1123
|
+
const checkout = await client.applyCheckoutCoupon(checkoutId, 'SAVE20');
|
|
1124
|
+
console.log(checkout.discountAmount); // "10.00"
|
|
1125
|
+
console.log(checkout.total); // correctly updated total
|
|
1126
|
+
|
|
1127
|
+
// Remove coupon from checkout
|
|
1128
|
+
await client.removeCheckoutCoupon(checkoutId);
|
|
1129
|
+
\`\`\`
|
|
1130
|
+
|
|
1131
|
+
> \u26A0\uFE0F **Critical:** if a checkout session already exists, ALWAYS use \`applyCheckoutCoupon(checkoutId, code)\`. Using \`applyCoupon(cartId, code)\` after checkout creation does NOT update the checkout total \u2014 payment will charge the original amount. Show \`checkout.discountAmount\` and \`checkout.couponCode\` in the order summary.
|
|
1116
1132
|
|
|
1117
1133
|
### \u26A0\uFE0F Checkout Order Summary \u2014 Use checkout.lineItems, NOT cart.items!
|
|
1118
1134
|
|
|
@@ -1932,7 +1948,7 @@ subsequent SDK call sends the \`Accept-Language\` header automatically:
|
|
|
1932
1948
|
\`\`\`typescript
|
|
1933
1949
|
import { BrainerceClient } from 'brainerce';
|
|
1934
1950
|
|
|
1935
|
-
const client = new BrainerceClient({
|
|
1951
|
+
const client = new BrainerceClient({ salesChannelId: 'vc_...' });
|
|
1936
1952
|
client.setLocale('he'); // done \u2014 all calls are now in Hebrew
|
|
1937
1953
|
\`\`\`
|
|
1938
1954
|
|
|
@@ -2649,6 +2665,9 @@ interface Product {
|
|
|
2649
2665
|
basePrice: string; // Use parseFloat() for calculations
|
|
2650
2666
|
salePrice?: string | null;
|
|
2651
2667
|
costPrice?: string | null;
|
|
2668
|
+
priceMin?: string | null; // Lowest variant price (VARIABLE products). Use for catalog/JSON-LD range display.
|
|
2669
|
+
priceMax?: string | null; // Highest variant price (VARIABLE products).
|
|
2670
|
+
priceVaries?: boolean; // true when variant prices differ \u2014 show "\u20AA49 \u2013 \u20AA199" range.
|
|
2652
2671
|
status: string;
|
|
2653
2672
|
type: 'SIMPLE' | 'VARIABLE';
|
|
2654
2673
|
isDownloadable?: boolean;
|
|
@@ -3219,9 +3238,9 @@ var HELPERS_TYPES = `// ---- Helper Functions (import from 'brainerce') ----
|
|
|
3219
3238
|
// Price helpers
|
|
3220
3239
|
function formatPrice(priceString: string | number | undefined | null, options?: { currency?: string; locale?: string; }): string;
|
|
3221
3240
|
function getProductPrice(product: Pick<Product, 'basePrice' | 'salePrice'>): number;
|
|
3222
|
-
function getProductPriceInfo(product: Pick<Product, 'basePrice' | 'salePrice'>): {
|
|
3241
|
+
function getProductPriceInfo(product: Pick<Product, 'basePrice' | 'salePrice' | 'discount' | 'priceMin' | 'priceVaries'>): {
|
|
3223
3242
|
price: number; originalPrice: number; isOnSale: boolean; discountAmount: number; discountPercent: number;
|
|
3224
|
-
};
|
|
3243
|
+
}; // Falls back to priceMin when basePrice=0 (VARIABLE products)
|
|
3225
3244
|
function getVariantPrice(variant: Pick<ProductVariant, 'price' | 'salePrice'>, productBasePrice: string): number;
|
|
3226
3245
|
|
|
3227
3246
|
// Cart helpers
|
|
@@ -3723,7 +3742,7 @@ function selectVariant(product: Product, selections: Record<string, string>) {
|
|
|
3723
3742
|
import { client } from './brainerce';
|
|
3724
3743
|
|
|
3725
3744
|
// 1. Submit the address + email. Email is REQUIRED on the DTO.
|
|
3726
|
-
const {
|
|
3745
|
+
const { checkout, rates } = await client.setShippingAddress(checkoutId, {
|
|
3727
3746
|
email,
|
|
3728
3747
|
firstName,
|
|
3729
3748
|
lastName,
|
|
@@ -3734,10 +3753,11 @@ const { shippingRates } = await client.setShippingAddress(checkoutId, {
|
|
|
3734
3753
|
postalCode,
|
|
3735
3754
|
country,
|
|
3736
3755
|
});
|
|
3756
|
+
// rates = available shipping rates; checkout = updated checkout object
|
|
3737
3757
|
|
|
3738
3758
|
// 2. Let the customer pick one of the returned rates.
|
|
3739
|
-
const chosen =
|
|
3740
|
-
await client.
|
|
3759
|
+
const chosen = rates[0]; // user selection
|
|
3760
|
+
await client.selectShippingMethod(checkoutId, chosen.id);
|
|
3741
3761
|
|
|
3742
3762
|
// 3. Re-fetch the checkout to get updated totals (tax may change after address).
|
|
3743
3763
|
const checkout = await client.getCheckout(checkoutId);
|
|
@@ -3791,21 +3811,21 @@ if (providers.length === 0) {
|
|
|
3791
3811
|
}
|
|
3792
3812
|
|
|
3793
3813
|
const active = providers[0];`,
|
|
3794
|
-
"checkout-stripe-confirm": `// Stripe confirm flow. Requires @stripe/stripe-js
|
|
3795
|
-
// (or the vanilla Stripe.js browser SDK).
|
|
3814
|
+
"checkout-stripe-confirm": `// Stripe confirm flow. Requires @stripe/stripe-js.
|
|
3796
3815
|
import { loadStripe } from '@stripe/stripe-js';
|
|
3797
3816
|
import { client } from './brainerce';
|
|
3798
3817
|
|
|
3799
3818
|
const stripe = await loadStripe(stripePublicKey);
|
|
3800
3819
|
if (!stripe) throw new Error('Stripe failed to load');
|
|
3801
3820
|
|
|
3802
|
-
//
|
|
3803
|
-
const
|
|
3804
|
-
|
|
3821
|
+
// Create a payment intent \u2014 returns clientSecret for Stripe Elements.
|
|
3822
|
+
const intent = await client.createPaymentIntent(checkoutId, {
|
|
3823
|
+
successUrl: \`\${window.location.origin}/order-confirmation?checkoutId=\${checkoutId}\`,
|
|
3824
|
+
cancelUrl: \`\${window.location.origin}/checkout?error=cancelled\`,
|
|
3805
3825
|
});
|
|
3806
3826
|
|
|
3807
|
-
// Use Stripe Elements to
|
|
3808
|
-
const result = await stripe.confirmCardPayment(clientSecret, {
|
|
3827
|
+
// Use Stripe Elements to confirm:
|
|
3828
|
+
const result = await stripe.confirmCardPayment(intent.clientSecret, {
|
|
3809
3829
|
payment_method: { card: cardElement },
|
|
3810
3830
|
});
|
|
3811
3831
|
|
|
@@ -3814,21 +3834,21 @@ if (result.error) {
|
|
|
3814
3834
|
return;
|
|
3815
3835
|
}
|
|
3816
3836
|
|
|
3817
|
-
// Success \u2014 redirect to
|
|
3837
|
+
// Success \u2014 redirect to confirmation page.
|
|
3818
3838
|
// The confirmation page runs handlePaymentSuccess + waitForOrder.
|
|
3819
3839
|
window.location.assign(\`/order-confirmation?checkoutId=\${checkoutId}\`);`,
|
|
3820
3840
|
"checkout-paypal-confirm": `// PayPal confirm flow. Use the PayPal JS SDK (render a PayPal button component).
|
|
3821
3841
|
import { client } from './brainerce';
|
|
3822
3842
|
|
|
3823
|
-
//
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
});
|
|
3843
|
+
// Create a payment intent first \u2014 for PayPal this returns the PayPal order ID.
|
|
3844
|
+
const intent = await client.createPaymentIntent(checkoutId, {
|
|
3845
|
+
successUrl: \`\${window.location.origin}/order-confirmation?checkoutId=\${checkoutId}\`,
|
|
3846
|
+
cancelUrl: \`\${window.location.origin}/checkout?error=cancelled\`,
|
|
3847
|
+
});
|
|
3829
3848
|
|
|
3830
|
-
|
|
3831
|
-
|
|
3849
|
+
// Render a PayPal button using intent.clientSdk (provider SDK config).
|
|
3850
|
+
// When the PayPal button's onApprove fires, redirect to confirmation:
|
|
3851
|
+
function onPayPalApprove() {
|
|
3832
3852
|
window.location.assign(\`/order-confirmation?checkoutId=\${checkoutId}\`);
|
|
3833
3853
|
}`,
|
|
3834
3854
|
"checkout-sandbox-confirm": `// Sandbox payment \u2014 store has sandboxPaymentsEnabled=true. No real charge.
|
|
@@ -3871,7 +3891,7 @@ async function registerAndMaybeVerify(input: {
|
|
|
3871
3891
|
firstName: string;
|
|
3872
3892
|
lastName: string;
|
|
3873
3893
|
}) {
|
|
3874
|
-
const result = await client.
|
|
3894
|
+
const result = await client.registerCustomer(input);
|
|
3875
3895
|
if (result.requiresVerification) {
|
|
3876
3896
|
// Route the user to your verify-email UI. Do NOT treat them as logged in.
|
|
3877
3897
|
return { state: 'needs-verification' as const };
|
|
@@ -3892,7 +3912,7 @@ async function resendCode() {
|
|
|
3892
3912
|
import { client } from './brainerce';
|
|
3893
3913
|
|
|
3894
3914
|
async function login(email: string, password: string) {
|
|
3895
|
-
const result = await client.
|
|
3915
|
+
const result = await client.loginCustomer(email, password);
|
|
3896
3916
|
if (result.requiresVerification) {
|
|
3897
3917
|
return { state: 'needs-verification' as const };
|
|
3898
3918
|
}
|
|
@@ -3927,25 +3947,37 @@ async function submitReset(token: string, newPassword: string) {
|
|
|
3927
3947
|
"oauth-redirect-and-callback": `// OAuth sign-in. Redirect flow, NOT popup.
|
|
3928
3948
|
import { client } from './brainerce';
|
|
3929
3949
|
|
|
3930
|
-
//
|
|
3931
|
-
const providers = await client.getAvailableOAuthProviders();
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3950
|
+
// Step 1: Get available provider names (strings: 'GOOGLE', 'FACEBOOK', 'GITHUB')
|
|
3951
|
+
const { providers } = await client.getAvailableOAuthProviders();
|
|
3952
|
+
|
|
3953
|
+
// Step 2: For each provider, fetch the authorization URL, then redirect.
|
|
3954
|
+
// Call this when the user clicks a provider button:
|
|
3955
|
+
async function redirectToOAuth(provider: string) {
|
|
3956
|
+
const { authorizationUrl } = await client.getOAuthAuthorizeUrl(provider, {
|
|
3957
|
+
redirectUrl: \`\${window.location.origin}/auth/callback\`,
|
|
3958
|
+
});
|
|
3959
|
+
window.location.href = authorizationUrl; // full-page redirect, NOT a popup
|
|
3935
3960
|
}
|
|
3936
3961
|
|
|
3937
|
-
// On your
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3962
|
+
// Step 3: On your /auth/callback route, read token from URL params:
|
|
3963
|
+
const params = new URLSearchParams(window.location.search);
|
|
3964
|
+
const oauthError = params.get('oauth_error');
|
|
3965
|
+
const token = params.get('token');
|
|
3966
|
+
if (oauthError) {
|
|
3967
|
+
window.location.href = '/login?error=' + encodeURIComponent(oauthError);
|
|
3968
|
+
} else if (token) {
|
|
3969
|
+
client.setCustomerToken(token);
|
|
3970
|
+
window.location.href = '/account';
|
|
3971
|
+
}`,
|
|
3943
3972
|
"coupon-apply-and-remove": `// Coupon input. Build the UI even if no coupons exist today \u2014 it auto-hides.
|
|
3973
|
+
// IMPORTANT: use applyCheckoutCoupon when a checkoutId is available (checkout page).
|
|
3974
|
+
// Using applyCoupon after checkout creation does NOT update the checkout total.
|
|
3944
3975
|
import { client } from './brainerce';
|
|
3945
3976
|
|
|
3946
|
-
|
|
3977
|
+
// On cart page (no checkout session yet)
|
|
3978
|
+
async function applyCouponToCart(cartId: string, code: string) {
|
|
3947
3979
|
try {
|
|
3948
|
-
const cart = await client.applyCoupon(code);
|
|
3980
|
+
const cart = await client.applyCoupon(cartId, code);
|
|
3949
3981
|
return { ok: true, cart };
|
|
3950
3982
|
} catch (err) {
|
|
3951
3983
|
// Invalid / expired / minimum not met. Surface the specific error.
|
|
@@ -3953,17 +3985,30 @@ async function applyCoupon(code: string) {
|
|
|
3953
3985
|
}
|
|
3954
3986
|
}
|
|
3955
3987
|
|
|
3956
|
-
async function
|
|
3957
|
-
|
|
3958
|
-
|
|
3988
|
+
async function removeCouponFromCart(cartId: string) {
|
|
3989
|
+
return client.removeCoupon(cartId);
|
|
3990
|
+
}
|
|
3991
|
+
|
|
3992
|
+
// On checkout page (checkout session already exists \u2014 always prefer this)
|
|
3993
|
+
async function applyCouponToCheckout(checkoutId: string, code: string) {
|
|
3994
|
+
try {
|
|
3995
|
+
const checkout = await client.applyCheckoutCoupon(checkoutId, code);
|
|
3996
|
+
return { ok: true, checkout }; // checkout.total is already updated
|
|
3997
|
+
} catch (err) {
|
|
3998
|
+
return { ok: false, error: (err as Error).message };
|
|
3999
|
+
}
|
|
4000
|
+
}
|
|
4001
|
+
|
|
4002
|
+
async function removeCouponFromCheckout(checkoutId: string) {
|
|
4003
|
+
return client.removeCheckoutCoupon(checkoutId);
|
|
3959
4004
|
}`,
|
|
3960
4005
|
"reservation-countdown": `// Reservation countdown. Use the SDK's expiry timestamp \u2014 do NOT invent
|
|
3961
4006
|
// your own timer state.
|
|
3962
4007
|
import { client } from './brainerce';
|
|
3963
4008
|
|
|
3964
|
-
function getRemainingMs(cart: {
|
|
3965
|
-
if (!cart.
|
|
3966
|
-
const expiry = new Date(cart.
|
|
4009
|
+
function getRemainingMs(cart: { reservation?: { expiresAt?: string } }): number {
|
|
4010
|
+
if (!cart.reservation?.expiresAt) return 0;
|
|
4011
|
+
const expiry = new Date(cart.reservation.expiresAt).getTime();
|
|
3967
4012
|
return Math.max(0, expiry - Date.now());
|
|
3968
4013
|
}
|
|
3969
4014
|
|
|
@@ -3990,8 +4035,8 @@ function onSearchChange(query: string, onResults: (items: unknown[]) => void) {
|
|
|
3990
4035
|
return;
|
|
3991
4036
|
}
|
|
3992
4037
|
searchTimer = setTimeout(async () => {
|
|
3993
|
-
const
|
|
3994
|
-
onResults(
|
|
4038
|
+
const { products } = await client.getSearchSuggestions(query);
|
|
4039
|
+
onResults(products);
|
|
3995
4040
|
}, 300);
|
|
3996
4041
|
}`,
|
|
3997
4042
|
"i18n-set-locale": `// i18n \u2014 only if get-store-capabilities reports i18n.enabled.
|
|
@@ -4348,19 +4393,13 @@ import { client } from './brainerce-client';
|
|
|
4348
4393
|
|
|
4349
4394
|
interface CheckoutOptions {
|
|
4350
4395
|
cartId: string;
|
|
4351
|
-
shippingAddress: object;
|
|
4352
|
-
shippingMethodId: string;
|
|
4353
|
-
paymentProviderId: string;
|
|
4354
4396
|
}
|
|
4355
4397
|
|
|
4356
4398
|
async function createCheckoutSafe(opts: CheckoutOptions) {
|
|
4357
4399
|
try {
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
shippingMethodId: opts.shippingMethodId,
|
|
4362
|
-
paymentProviderId: opts.paymentProviderId,
|
|
4363
|
-
});
|
|
4400
|
+
// createCheckout only takes cartId (+ optional customerId, selectedItemIds).
|
|
4401
|
+
// Shipping address, shipping method, and payment are set via separate calls.
|
|
4402
|
+
return await client.createCheckout({ cartId: opts.cartId });
|
|
4364
4403
|
} catch (err: unknown) {
|
|
4365
4404
|
if (!isApiError(err, 'PRICE_DRIFT')) throw err;
|
|
4366
4405
|
|
|
@@ -5035,21 +5074,21 @@ var FLOWS = {
|
|
|
5035
5074
|
1. **Collect address + email.** Build a form that captures customer email, billing address, shipping address (with \`line1\`, \`line2\`, \`city\`, \`region\`, \`postalCode\`, \`country\`). \`email\` is REQUIRED on \`SetShippingAddressDto\`.
|
|
5036
5075
|
2. **Submit the address to get shipping rates.**
|
|
5037
5076
|
\`\`\`ts
|
|
5038
|
-
const {
|
|
5077
|
+
const { checkout, rates } = await client.setShippingAddress(checkoutId, {
|
|
5039
5078
|
email,
|
|
5040
5079
|
firstName,
|
|
5041
5080
|
lastName,
|
|
5042
5081
|
line1, line2, city, region, postalCode, country,
|
|
5043
5082
|
});
|
|
5044
5083
|
\`\`\`
|
|
5045
|
-
|
|
5084
|
+
\`rates\` = available shipping rates for that address + the store's zones. \`checkout\` = updated checkout object.
|
|
5046
5085
|
3. **Let the customer pick a rate**, then persist the selection:
|
|
5047
5086
|
\`\`\`ts
|
|
5048
|
-
await client.
|
|
5087
|
+
await client.selectShippingMethod(checkoutId, rateId);
|
|
5049
5088
|
\`\`\`
|
|
5050
|
-
4. **Fetch payment providers
|
|
5089
|
+
4. **Fetch payment providers:**
|
|
5051
5090
|
\`\`\`ts
|
|
5052
|
-
const providers = await client.getPaymentProviders(
|
|
5091
|
+
const providers = await client.getPaymentProviders();
|
|
5053
5092
|
\`\`\`
|
|
5054
5093
|
The response tells you which providers are configured (Stripe, Grow, PayPal, Sandbox) and how to render each. Each provider has a \`renderType\` telling you whether to show a Stripe Elements form, a redirect button, a PayPal button, or a sandbox "complete test order" button.
|
|
5055
5094
|
5. **Confirm payment using the provider's recommended flow.** For Stripe: Stripe Elements \u2192 \`stripe.confirmCardPayment\` using the clientSecret returned by the SDK. For sandbox payments: call \`completeGuestCheckout(checkoutId)\` directly. For PayPal/Grow: follow the redirect and handle the return on your confirmation page.
|
|
@@ -5065,28 +5104,28 @@ Never bypass these steps. Never call \`submitGuestOrder\` / \`createOrder\` \u20
|
|
|
5065
5104
|
"auth-register": {
|
|
5066
5105
|
title: "Registration",
|
|
5067
5106
|
body: `1. **Collect** email, password, first name, last name. Enforce strong passwords client-side: 8+ chars, upper, lower, number, special.
|
|
5068
|
-
2. **Call
|
|
5107
|
+
2. **Call registerCustomer:**
|
|
5069
5108
|
\`\`\`ts
|
|
5070
|
-
const result = await client.
|
|
5109
|
+
const result = await client.registerCustomer({ email, password, firstName, lastName });
|
|
5071
5110
|
\`\`\`
|
|
5072
5111
|
3. **Branch on \`result.requiresVerification\`:**
|
|
5073
|
-
- If \`true\`: route the user to your verify-email UI. Do NOT treat them as logged in yet.
|
|
5074
|
-
- If \`false\`:
|
|
5112
|
+
- If \`true\`: store the token temporarily (e.g. sessionStorage), route the user to your verify-email UI. Do NOT treat them as logged in yet.
|
|
5113
|
+
- If \`false\`: call \`client.setCustomerToken(result.token)\` and route to the account area.
|
|
5075
5114
|
4. **On the verify-email step:** collect a 6-digit code and call \`client.verifyEmail(code)\`. Offer a "resend code" button wired to \`client.resendVerificationEmail()\`.
|
|
5076
|
-
5. **After verifyEmail resolves:** the user is now logged in
|
|
5115
|
+
5. **After verifyEmail resolves:** call \`client.setCustomerToken(result.token)\` \u2014 the user is now logged in \u2014 then route to the account area.
|
|
5077
5116
|
|
|
5078
5117
|
Build the verify-email step EVEN IF the store currently has verification disabled. It auto-hides; store owners enable it later.`
|
|
5079
5118
|
},
|
|
5080
5119
|
"auth-login": {
|
|
5081
5120
|
title: "Login",
|
|
5082
5121
|
body: `1. **Collect** email + password.
|
|
5083
|
-
2. **Call
|
|
5122
|
+
2. **Call loginCustomer:**
|
|
5084
5123
|
\`\`\`ts
|
|
5085
|
-
const result = await client.
|
|
5124
|
+
const result = await client.loginCustomer(email, password);
|
|
5086
5125
|
\`\`\`
|
|
5087
5126
|
3. **Branch on \`result.requiresVerification\`:**
|
|
5088
5127
|
- If \`true\`: route to verify-email. The user must complete verification before accessing account features.
|
|
5089
|
-
- If \`false\`:
|
|
5128
|
+
- If \`false\`: call \`client.setCustomerToken(result.token)\` and route to the previous page (or account area).
|
|
5090
5129
|
4. **Offer OAuth buttons** from \`client.getAvailableOAuthProviders()\`. Render a placeholder region even when no providers are returned \u2014 the region auto-hides today and shows buttons the moment a provider is enabled in the dashboard.
|
|
5091
5130
|
5. **On error**, render the specific message (invalid credentials, rate limited, account disabled) \u2014 never swallow.`
|
|
5092
5131
|
},
|
|
@@ -5111,15 +5150,24 @@ Build both steps EVEN IF the store has no email provider configured today \u2014
|
|
|
5111
5150
|
},
|
|
5112
5151
|
oauth: {
|
|
5113
5152
|
title: "OAuth sign-in",
|
|
5114
|
-
body: `1. **
|
|
5153
|
+
body: `1. **Get available provider names:**
|
|
5154
|
+
\`\`\`ts
|
|
5155
|
+
const { providers } = await client.getAvailableOAuthProviders();
|
|
5156
|
+
// providers = ['GOOGLE', 'FACEBOOK', 'GITHUB'] (strings, not objects with authorizationUrl)
|
|
5157
|
+
\`\`\`
|
|
5158
|
+
2. **For each provider, fetch the authorization URL:**
|
|
5159
|
+
\`\`\`ts
|
|
5160
|
+
const { authorizationUrl } = await client.getOAuthAuthorizeUrl(provider, {
|
|
5161
|
+
redirectUrl: \`\${window.location.origin}/auth/callback\`,
|
|
5162
|
+
});
|
|
5163
|
+
window.location.href = authorizationUrl; // full-page redirect, NOT a popup
|
|
5164
|
+
\`\`\`
|
|
5165
|
+
3. **On the callback page** the URL contains \`token\` + \`oauth_success\` (or \`oauth_error\`) query params. Extract and apply the token:
|
|
5115
5166
|
\`\`\`ts
|
|
5116
|
-
const
|
|
5167
|
+
const token = new URLSearchParams(location.search).get('token');
|
|
5168
|
+
if (token) client.setCustomerToken(token); // then redirect to account
|
|
5117
5169
|
\`\`\`
|
|
5118
|
-
|
|
5119
|
-
2. **Build a button for each** that redirects the browser to \`authorizationUrl\`. Do NOT open a popup; the full-page redirect is required.
|
|
5120
|
-
3. **On the provider's side** the user authenticates, and the provider redirects back to your OAuth callback URL with \`token\` + \`oauth_success\` (or \`oauth_error\`) query params.
|
|
5121
|
-
4. **The callback handler MUST run server-side (BFF).** Extract the token from the query params, exchange it for a session cookie via your BFF, then redirect the browser to the account area. Never let the token land in browser history as a query param or localStorage.
|
|
5122
|
-
5. **On \`oauth_error\`:** redirect to login with an error message.
|
|
5170
|
+
4. **On \`oauth_error\`:** redirect to login with an error message.
|
|
5123
5171
|
|
|
5124
5172
|
Build the OAuth button region AND the callback handler even when no providers are configured. They auto-hide.`
|
|
5125
5173
|
},
|
|
@@ -5141,7 +5189,7 @@ Build the OAuth button region AND the callback handler even when no providers ar
|
|
|
5141
5189
|
|
|
5142
5190
|
- **Cart ID persistence:** the SDK stores the cart ID across reloads. You do not need to write cart-to-localStorage code yourself.
|
|
5143
5191
|
- **Reads:** \`client.getCart()\` returns the current cart. Call it on mount in your cart UI and on any page that shows a cart count (header).
|
|
5144
|
-
- **Writes:** use \`client.addToCart\`, \`client.updateCartItem\`, \`client.removeCartItem\`, \`client.applyCoupon\`, \`client.removeCoupon\`. After each mutation the SDK returns the updated cart.
|
|
5192
|
+
- **Writes:** use \`client.addToCart\`, \`client.updateCartItem\`, \`client.removeCartItem\`, \`client.applyCoupon\`, \`client.removeCoupon\`. After each mutation the SDK returns the updated cart. On the **checkout page** use \`client.applyCheckoutCoupon(checkoutId, code)\` / \`client.removeCheckoutCoupon(checkoutId)\` \u2014 these update checkout totals atomically. Never use \`applyCoupon\` after a checkout session exists.
|
|
5145
5193
|
- **Totals:** call \`getCartTotals(cart)\` \u2014 do NOT read \`cart.total\`. The helper understands taxes, shipping, and discounts.
|
|
5146
5194
|
- **\`smartGetCart()\`** returns \`CartWithIncludes\` (extends \`Cart\`). All carts are server-side. Pass \`{ include: ['recommendations', 'upgrades', 'bundles'] }\` to fetch extras in one request.
|
|
5147
5195
|
- **NEVER mutate cart state outside SDK helpers.** Any hand-rolled cart update risks desync with the reservation timer and the checkout flow.`
|
|
@@ -5273,7 +5321,7 @@ var FEATURES = [
|
|
|
5273
5321
|
id: "browse-products",
|
|
5274
5322
|
title: "Browse, filter, and search products",
|
|
5275
5323
|
description: "Users can list products with pagination, apply category / price / attribute / custom-field filters, sort by name / price / newest, and run a search with autocomplete. Custom-field filters surface metafield definitions whose filterable=true (SELECT, MULTI_SELECT, BOOLEAN). Must handle empty states and loading states.",
|
|
5276
|
-
sdk: "client.getProducts({ page, limit, filters, sort, metafields }), client.getPublicMetafieldDefinitions(), client.
|
|
5324
|
+
sdk: "client.getProducts({ page, limit, filters, sort, metafields }), client.getPublicMetafieldDefinitions(), client.getSearchSuggestions(query)",
|
|
5277
5325
|
mandatory: "mandatory"
|
|
5278
5326
|
},
|
|
5279
5327
|
{
|
|
@@ -5303,7 +5351,7 @@ var FEATURES = [
|
|
|
5303
5351
|
id: "cart-coupons",
|
|
5304
5352
|
title: "Apply and remove coupon codes",
|
|
5305
5353
|
description: "Users can enter a coupon code, see it applied to the cart, see the discount amount, and remove it. Build the UI even if no coupons are configured today \u2014 it auto-hides.",
|
|
5306
|
-
sdk: "client.applyCoupon(code), client.removeCoupon()",
|
|
5354
|
+
sdk: "client.applyCoupon(cartId, code), client.removeCoupon(cartId) \u2014 on cart page. client.applyCheckoutCoupon(checkoutId, code), client.removeCheckoutCoupon(checkoutId) \u2014 on checkout page (use when checkoutId exists)",
|
|
5307
5355
|
mandatory: "mandatory",
|
|
5308
5356
|
capabilityFlag: "hasCoupons",
|
|
5309
5357
|
whenDisabledNote: "Store has no coupons configured today. Build the UI anyway \u2014 it auto-hides until the store owner creates a coupon."
|
|
@@ -5320,7 +5368,7 @@ var FEATURES = [
|
|
|
5320
5368
|
id: "checkout",
|
|
5321
5369
|
title: "Complete a full checkout end-to-end",
|
|
5322
5370
|
description: "Users can enter their address, pick a shipping rate, pick a payment provider, pay, and land on a confirmation page showing the real order. Displays checkout.lineItems (not cart.items) on the summary.",
|
|
5323
|
-
sdk: "client.setShippingAddress, client.
|
|
5371
|
+
sdk: "client.setShippingAddress (returns { checkout, rates }), client.selectShippingMethod, client.getPaymentProviders(), provider-specific confirm, client.handlePaymentSuccess, client.waitForOrder",
|
|
5324
5372
|
flowRef: "checkout",
|
|
5325
5373
|
mandatory: "mandatory"
|
|
5326
5374
|
},
|
|
@@ -5336,7 +5384,7 @@ var FEATURES = [
|
|
|
5336
5384
|
id: "register",
|
|
5337
5385
|
title: "Register a new account with email verification",
|
|
5338
5386
|
description: 'Users can create an account (email, password, first + last name). Handles the requiresVerification branch by routing to an email-verification step. Verification step collects a 6-digit code and has a "resend code" action.',
|
|
5339
|
-
sdk: "client.
|
|
5387
|
+
sdk: "client.registerCustomer({email, password, firstName, lastName}), client.verifyEmail(code), client.resendVerificationEmail()",
|
|
5340
5388
|
flowRef: "auth-register",
|
|
5341
5389
|
mandatory: "mandatory",
|
|
5342
5390
|
capabilityFlag: "oauth",
|
|
@@ -5346,7 +5394,7 @@ var FEATURES = [
|
|
|
5346
5394
|
id: "login",
|
|
5347
5395
|
title: "Log in with email / password and handle verification branch",
|
|
5348
5396
|
description: "Users can log in. The login form handles the requiresVerification branch by routing to the verify-email step. Specific errors render (bad credentials, rate limited, disabled account).",
|
|
5349
|
-
sdk: "client.
|
|
5397
|
+
sdk: "client.loginCustomer(email, password)",
|
|
5350
5398
|
flowRef: "auth-login",
|
|
5351
5399
|
mandatory: "mandatory"
|
|
5352
5400
|
},
|
|
@@ -5379,14 +5427,14 @@ var FEATURES = [
|
|
|
5379
5427
|
id: "header",
|
|
5380
5428
|
title: "Global header with cart count and search",
|
|
5381
5429
|
description: "A header visible across the experience with the store logo, navigation, a cart icon with live item count, a search input with autocomplete (debounced ~300ms, 2-char minimum), and a login / account action. Below the header, discount banners render when active.",
|
|
5382
|
-
sdk: "client.getCart() for the count, client.
|
|
5430
|
+
sdk: "client.getCart() for the count, client.getSearchSuggestions(query) for autocomplete",
|
|
5383
5431
|
mandatory: "mandatory"
|
|
5384
5432
|
},
|
|
5385
5433
|
{
|
|
5386
5434
|
id: "discount-banners",
|
|
5387
5435
|
title: "Show active discount banners and badges",
|
|
5388
5436
|
description: "Active discount rules render as banners (below the header) and as badges on product cards / detail pages. Build the UI even if the store has no active discounts today \u2014 it auto-hides.",
|
|
5389
|
-
sdk: "client.getDiscountBanners(), getProductDiscountBadge(
|
|
5437
|
+
sdk: "client.getDiscountBanners(), client.getProductDiscountBadge(productId)",
|
|
5390
5438
|
mandatory: "mandatory",
|
|
5391
5439
|
capabilityFlag: "hasDiscountRules",
|
|
5392
5440
|
whenDisabledNote: "Store has no discount rules active. Build the banner and badge components anyway \u2014 they auto-hide."
|