const app=document.querySelector('#app'); let catalog=[],cart={items:[],addons:[],plan:{servings:2,meals:3,preference:'All'},selected_meals:0,total:0},filters={q:'',category:'All',calories:0}; const money=n=>'$'+Number(n||0).toFixed(2); const esc=s=>String(s??'').replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); function route(path){history.pushState({},'',path);boot()} window.onpopstate=boot; function shell(content,{simple=false}={}){document.body.className=simple?'simple':'';app.innerHTML=`
${content}
`} function img(item){return item.image?`${esc(item.name)}`:`
Blue Apron
`} function card(item,weekly=false){return `
${img(item)}
${esc(item.category)}

${esc(item.name)}

${esc((item.description||'').slice(0,95))}

${item.menuFacts?`${esc(item.menuFacts)}`:`${esc(item.calories||'Chef curated')}${weekly?'From $11.99 / serving':'View recipe'}`}
${weekly?`
`:''}
`} async function getCart(){cart=await(await fetch('/api/cart')).json();return cart} async function getCatalog(params=''){let result=await(await fetch('/api/recipes'+params)).json();catalog=result.recipes;return result} function privacyBanner(){return ``} function home(){let picks=catalog.slice(0,4);shell(`
NO SUBSCRIPTION NEEDED

Dinner's Back on the Calendar

Your week has enough on its plate. Let us handle what's on yours.

More Ways to Blue Apron

${[['20 MIN OR LESS','Fast, flavorful recipes ready in 20 minutes or less.'],['ASSEMBLE & BAKE','One-pan meals. Minimal effort, maximum reward.'],['MEAL KITS','Easy recipes. Pre-portioned ingredients.'],['FAMILY STYLE','Mix & match, family-sized mains & sides.']].map((x,i)=>`
${x[0]}
${img(picks[i])}

${x[1]}

`).join('')}
ON THE MENU

Something delicious for every night

View all meals →
${picks.map(x=>card(x)).join('')}
${privacyBanner()}`)} function plans(){shell(`
SUBSCRIBE & SAVE

Build a plan for your week

Choose the number of people, meals, and preferences. Your estimate updates instantly.

Flexible by design

Change your menu or delivery date before the weekly cutoff. Skip a week, pause, or cancel from your local account.

`)} function estimate(){document.querySelector('#estimate').textContent=money(servings.value*meals.value*11.99)} async function savePlan(){let r=await fetch('/api/plan',{method:'PUT',headers:{'Content-Type':'application/json'},body:JSON.stringify({servings:servings.value,meals:meals.value,preference:preference.value})});let x=await r.json();if(!r.ok)return alert(x.error);cart=x;route('/menu')} function menu(){let weekly=catalog.slice(0,48);let current=new URLSearchParams(location.search).get('cycle_date')==='2026-09-14';shell(`
${privacyBanner()}`)} async function menuFilter(value){filters.category=value;await refreshMenu()} async function calorieFilter(on){filters.calories=on?600:0;await refreshMenu()} async function refreshMenu(){let p=new URLSearchParams();if(filters.category!=='All')p.set('category',filters.category);if(filters.calories)p.set('calories',filters.calories);p.set('limit','48');await getCatalog('?'+p);menu()} async function addMeal(id,upgrade=''){let r=await fetch('/api/cart',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({recipe_id:id,upgrade})});let x=await r.json();if(!r.ok)return alert(x.error);cart=x;let bag=document.querySelector('#bagCount');if(bag)bag.textContent=cart.selected_meals;let msg=document.createElement('div');msg.className='toast';msg.textContent=`Added — ${cart.selected_meals} of ${cart.plan.meals} meals selected`;document.body.append(msg);setTimeout(()=>msg.remove(),1800)} function openMeal(id){let item=catalog.find(x=>x.id===id);if(item)route('/recipes/'+item.path.split('/').slice(1).join('/'))} function cookbook(){shell(`
THE BLUE APRON COOKBOOK

Recipes worth returning to

Explore hundreds of chef-designed meals, techniques, and seasonal ideas.

${['Standard Meal Kit','Assemble And Bake Meal Kit','15 Minute Meal Kit','Lunch Meal Kit'].map(x=>``).join('')}
${catalog.length?`${catalog.length} recipes`:'No recipes found'}
${catalog.length?`
${catalog.map(x=>card(x)).join('')}
`:`

No recipes match “${esc(filters.q)}”

Try another search or clear your filters.

`}
`)} async function searchRecipes(e){e.preventDefault();filters.q=recipeSearch.value.trim();let x=await getCatalog('?q='+encodeURIComponent(filters.q));cookbook()} async function bookFilter(cat){filters.category=cat;await getCatalog(cat==='All'?'':'?category='+encodeURIComponent(cat));cookbook()} async function clearSearch(){filters={q:'',category:'All',calories:0};await getCatalog();cookbook()} function detail(item){let ingredients=(item.ingredients||[]).map(x=>`
  • ${esc(x)}
  • `).join('');let steps=(item.instructions||[]).map((x,i)=>`
  • ${i+1}

    ${esc(x)}

  • `).join('');shell(`
    ${img(item)}

    ${esc(item.name)}

    ${esc(item.subtitle||item.category)}

    ${esc(item.description)}

    Ingredients

    Ingredient list

    Cooking instructions

      ${steps}
    `)} function cartPage(){let items=cart.items.map(x=>`
    ${x.image?``:''}
    ${esc(x.name)}${cart.plan.servings} servings ${x.upgrade?'· '+esc(x.upgrade):''}
    ${x.qty}
    ${money(x.line_total)}
    `).join('');let addons=cart.addons.map(x=>`
    ${x.qty} × ${esc(x.name)}${money(x.line_total)}
    `).join('');shell(`

    Review your box

    ${cart.plan.servings} people · ${cart.plan.meals} mealsEdit plan
    ${items||`

    Your box is empty

    Choose meals from this week's menu.

    `}

    Add something extra

    ${Object.entries({breakfast:['Blueberry Overnight Oats',8.99],snack:['Chocolate Chip Oat Cookies',6.99],protein:['Extra Garlic-Herb Chicken',11.99]}).map(([id,x])=>`
    ${x[0]}${money(x[1])}
    `).join('')}
    `)} async function qty(id,n){cart=await(await fetch('/api/cart/'+id,{method:'PATCH',headers:{'Content-Type':'application/json'},body:JSON.stringify({qty:n})})).json();cartPage()} async function addAddon(id){let r=await fetch('/api/addons',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({addon_id:id})});let x=await r.json();if(!r.ok)return alert(x.error);cart=x;cartPage()} async function addonQty(id,qty){let r=await fetch('/api/addons/'+id,{method:'PATCH',headers:{'Content-Type':'application/json'},body:JSON.stringify({qty})});let x=await r.json();if(!r.ok)return alert(x.error);cart=x;cartPage()} function checkout(){let d=cart.delivery||{};shell(`

    Delivery & payment

    Delivery address

    ${[['name','Full name'],['address','Street address'],['city','City'],['state','State'],['zip','ZIP code'],['phone','Mobile phone number']].map(([id,label])=>``).join('')}
    `)} async function saveDelivery(e){e.preventDefault();let value=id=>document.getElementById(id).value;let data={name:value('name'),address:value('address'),city:value('city'),state:value('state'),zip:value('zip'),phone:value('phone'),date:value('date')};let r=await fetch('/api/delivery',{method:'PUT',headers:{'Content-Type':'application/json'},body:JSON.stringify(data)});let x=await r.json();if(!r.ok){deliveryError.textContent=x.error;return}cart=x;deliveryError.className='success';deliveryError.textContent='Delivery information saved.'} async function reviewOrder(){let r=await fetch('/api/checkout/review',{method:'POST'});let x=await r.json();reviewMessage.className=r.ok?'success':'error';reviewMessage.textContent=r.ok?'Ready for final review. No purchase has been submitted.':x.error} function authPage(kind){let signin=kind==='signin';shell(`

    ${signin?'Welcome back!':'Create an account'}

    ${signin?`Don’t have an account? Get started`:`Have an account? Login`}

    ${signin?`
    or
    Forgot your password? Reset it here.
    `:`
    Password must be 8 to 25 characters and include numbers and letters.

    By creating an account, you agree to the Terms of Service and Privacy Policy.

    `}
    ${privacyBanner()}`,{simple:true})} async function registerStart(e){e.preventDefault();let r=await fetch('/api/auth/register/start',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({first_name:firstName.value,last_name:lastName.value,email:registerEmail.value,password:registerPassword.value,phone:registerPhone.value})});let x=await r.json();if(!r.ok)return authMessage.textContent=x.error;authMessage.className='sandbox-code';authMessage.innerHTML=`Offline verification code: ${x.verification_code}`} async function registerFinish(){let r=await fetch('/api/auth/register/verify',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({code:verifyCode.value})});let x=await r.json();if(!r.ok){verificationError.textContent=x.error;return}route('/account/upcoming')} async function signIn(e){e.preventDefault();let r=await fetch('/api/auth/signin',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({email:loginEmail.value,password:loginPassword.value})});let x=await r.json();if(!r.ok)return authMessage.textContent=x.error;route('/account/upcoming')} function resetPage(){shell(`

    Reset your password

    Enter the email address associated with your account.

    Return to sign in
    `,{simple:true})} async function resetRequest(e){e.preventDefault();let r=await fetch('/api/reset-request',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({email:resetEmail.value})});let x=await r.json();resetMessage.className=r.ok?'notice':'error';resetMessage.textContent=x.message||x.error} async function accountPage(){let s=await(await fetch('/api/auth/session')).json();if(!s.authenticated){authPage('signin');authMessage.textContent='Sign in to manage your deliveries.';return}let r=await fetch('/api/subscription');let sub=await r.json();shell(`
    MY ACCOUNT

    Upcoming deliveries

    ${esc(s.account.display_name)} · ${esc(s.account.email_normalized)}

    ${esc(sub.status)}

    ${sub.skipped?'Week skipped':'Delivery '+esc(sub.next_date)}

    ${esc(sub.address)}

    ${cart.plan.servings} people · ${cart.plan.meals} meals

    Order history

    September 14, 2026Delivered · ${cart.plan.meals} meals · ${money(cart.total||78.42)}View recipes
    `)} async function subAction(action){let r=await fetch('/api/subscription',{method:'PATCH',headers:{'Content-Type':'application/json'},body:JSON.stringify({action})});let x=await r.json();if(!r.ok)return alert(x.error);accountPage()} async function editSub(kind){let value=prompt(kind==='date'?'Enter a new delivery date':'Enter a new delivery address');if(!value)return;let r=await fetch('/api/subscription',{method:'PATCH',headers:{'Content-Type':'application/json'},body:JSON.stringify({action:kind,[kind]:value})});let x=await r.json();if(!r.ok)return alert(x.error);accountPage()} function confirmCancel(){if(confirm('Cancel your local offline subscription? This has no effect on Blue Apron.'))subAction('cancel')} async function logout(){await fetch('/api/auth/signout',{method:'POST'});route('/')} function infoPage(kind){if(kind==='gifts'){shell(`

    Give a Blue Apron
    gift card

    A gift that never expires.
    Customized to their favorite Blue Apron meal.

    FAQs

    For more information on gift cards, view our full list of FAQs here.

    ${privacyBanner()}`,{simple:true});return}if(kind==='about'){shell(`

    Helping everyone get
    amazing food on the table

    WHY WE'RE HERE

    We believe that a great meal can change your day.

    But with everything life throws at you during the week, getting great meals on the table is not always easy.

    You need a helping hand in the kitchen. That’s where Blue Apron comes in.

    ${privacyBanner()}`);return}let content={help:['Help Center & FAQ','How can we help?','Find guidance for orders, deliveries, account access, failed actions, and subscription changes without exposing private account data.']}[kind];shell(`
    BLUE APRON

    ${content[0]}

    ${content[1]}

    ${content[2]}

    `)} function notFound(){shell(`
    BA

    Page not found

    We couldn't find the page you requested.

    `)} async function boot(){await getCart();let path=decodeURIComponent(location.pathname);if(!catalog.length)await getCatalog();if(path==='/')home();else if(path==='/menu'){await refreshMenu()}else if(path==='/plans')plans();else if(path==='/cookbook'){await getCatalog(filters.q?'?q='+encodeURIComponent(filters.q):'');cookbook()}else if(path.startsWith('/recipes/')){let slug=path.split('/').pop();let r=await fetch('/api/recipes/'+encodeURIComponent(slug));r.ok?detail(await r.json()):notFound()}else if(path==='/cart')cartPage();else if(path==='/checkout')checkout();else if(path==='/user/sign-in'||path==='/users/sign_in')authPage('signin');else if(path==='/user/sign-up'||path==='/users/sign_up')authPage('signup');else if(path==='/user/password-reset'||path==='/users/password/new')resetPage();else if(path==='/account/upcoming')await accountPage();else if(path==='/gifts'||path==='/gift-cards')infoPage('gifts');else if(path==='/help')infoPage('help');else if(path==='/about'||path==='/pages/vision')infoPage('about');else if(path==='/pages/blue-apron-plus'||path==='/pages/subscribe-and-save')notFound();else notFound()} const _shell=shell; shell=function(content,opts={}){_shell(content,opts);const actions=document.querySelector('.header-actions');if(actions&&!document.querySelector('#bagCount')){const b=document.createElement('button');b.className='cart-button';b.onclick=()=>route('/cart');b.innerHTML=`Bag ${cart.selected_meals||0}`;actions.append(b)}} const _menuVisual=menu;menu=function(){_menuVisual();if(new URLSearchParams(location.search).get('cycle_date')==='2026-09-14'){let rail=document.querySelector('.category-rail');if(rail)rail.innerHTML=[['01','LABOR DAY'],['02','20 MINUTES
    OR LESS'],['03','MEAL KITS'],['04','ASSEMBLE &
    BAKE'],['03','FAMILY STYLE']].map(x=>`
    ${x[1]}
    `).join('')}} boot();