PageSourceSearch

https://margegranola.com/_next/static/chunks/976-bd47b1304b8773f3.js

js margegranola.com collected 2026-10-04 02:46:04 UTC 11,707 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[976],{6289:(e,t,r)=>{r.d(t,{S:()=>i});var o=r(12466),s=r(72845),a=r(22134);class i{static async getProfile(e){try{let t;if(e){let r=a.go.getTenantDomain(),o=r.startsWith("http://")||r.startsWith("https://")?r:"http://".concat(r,"/api/v1"),i=function(){let e={"Content-Type":"application/json"},t="snovalleyfoods";t&&(e["x-tenant-slug"]=t);let r=(0,s.hb)();return r&&(e["x-site-slug"]=r),e}();i.Authorization="Bearer ".concat(e);let l=await fetch("".concat(o).concat(this.ENDPOINTS.PROFILE),{headers:i});if(!l.ok)throw Error("HTTP error! status: ".concat(l.status));t=await l.json()}else t=await o.g0.get(this.ENDPOINTS.PROFILE);return t.customer}catch(e){throw this.handleError(e)}}static async updateProfile(e){try{return(await o.g0.put(this.ENDPOINTS.UPDATE_PROFILE,e)).customer}catch(e){throw this.handleError(e)}}static async changePassword(e){try{await o.g0.put(this.ENDPOINTS.CHANGE_PASSWORD,e)}catch(e){throw this.handleError(e)}}static handleError(e){var t;return(null==(t=e.response)?void 0:t.data)?Error(e.response.data.message||e.response.data.error||"Request failed"):e.message?Error(e.message):Error("An unexpected error occurred")}}i.ENDPOINTS={PROFILE:"/storefront/customer/profile",UPDATE_PROFILE:"/storefront/customer/profile",CHANGE_PASSWORD:"/storefront/customer/password"}},10196:(e,t,r)=>{r.d(t,{Ey:()=>s,Lb:()=>a,aO:()=>i});let o={MARGE_GRANOLA:"margegranola"};function s(){return"margegranola".trim().toLowerCase()}function a(e){let t=(e||"").trim().toLowerCase();return t===o.MARGE_GRANOLA||"marge-granola"===t}function i(){let e=s(),t=a(e);return{siteSlug:e,isMargeGranolaSite:t,deepSearchAvailable:!t,topBarPromoText:t?"Save with our 3 pouch Breakfast Bundle!":null}}},22692:(e,t,r)=>{r.d(t,{z:()=>s});var o=r(12466);class s{static setCookie(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:7,o=new Date;o.setTime(o.getTime()+24*r*36e5);let s=["".concat(e,"=").concat(encodeURIComponent(t)),"expires=".concat(o.toUTCString()),"path=/","SameSite=Lax","Secure"];document.cookie=s.join("; ")}static getCookie(e){if("undefined"==typeof document)return null;let t="; ".concat(document.cookie).split("; ".concat(e,"="));if(2===t.length){var r;let e=null==(r=t.pop())?void 0:r.split(";").shift();return e?decodeURIComponent(e):null}return null}static removeCookie(e){"undefined"!=typeof document&&(document.cookie="".concat(e,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; SameSite=Lax"))}static async login(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];try{let r=await o.g0.post(this.ENDPOINTS.LOGIN,e);return r.token&&(this.setCookie(this.COOKIE_NAMES.ACCESS_TOKEN,r.token,t?2:1),this.setCookie(this.COOKIE_NAMES.REFRESH_TOKEN,r.refreshToken,t?90:30)),r}catch(e){throw this.handleAuthError(e)}}static async register(e){try{let t=await o.g0.post(this.ENDPOINTS.REGISTER,e);return t.token&&(this.setCookie(this.COOKIE_NAMES.ACCESS_TOKEN,t.token,1),this.setCookie(this.COOKIE_NAMES.REFRESH_TOKEN,t.refreshToken,30)),t}catch(e){throw this.handleAuthError(e)}}static async refreshToken(){try{let e=this.getCookie(this.COOKIE_NAMES.REFRESH_TOKEN);if(!e)throw Error("No refresh token available");let t=await o.g0.post(this.ENDPOINTS.REFRESH,{refreshToken:e});return t.token&&(this.setCookie(this.COOKIE_NAMES.ACCESS_TOKEN,t.token,1),this.setCookie(this.COOKIE_NAMES.REFRESH_TOKEN,t.refreshToken,30)),t}catch(e){throw this.logout(),this.handleAuthError(e)}}static async logout(){try{await o.g0.post(this.ENDPOINTS.LOGOUT,{})}catch(e){console.warn("Logout API call failed:",e)}finally{this.removeCookie(this.COOKIE_NAMES.ACCESS_TOKEN),this.removeCookie(this.COOKIE_NAMES.REFRESH_TOKEN)}}static async getProfile(){try{return await o.g0.get(this.ENDPOINTS.PROFILE)}catch(e){throw this.handleAuthError(e)}}static async getCurrentCustomer(){try{if(!this.isAuthenticated())return null;return await this.getProfile()}catch(e){return console.error("Error fetching customer data:",e),null}}static isAuthenticated(){return!!this.getCookie(this.COOKIE_NAMES.ACCESS_TOKEN)}static getAccessToken(){return this.getCookie(this.COOKIE_NAMES.ACCESS_TOKEN)}static getRefreshToken(){return this.getCookie(this.COOKIE_NAMES.REFRESH_TOKEN)}static handleAuthError(e){var t,r,o;let s="Authentication failed";if(null==(t=e.response)?void 0:t.data){let t=e.response.data;s=t.message||t.error||s,(null==(o=e.response)?void 0:o.status)===409||/already in use|already exists/i.test(s)?s="An account with this email already exists":s.includes("must NOT have fewer than 6 characters")?s="Password must be at least 6 characters long":s.includes("body/")&&(s=s.replace(/body\//g,"").replace(/must NOT have/g,"must have").replace(/must be/g,"must be"))}else e.message&&(s=e.message);let a=Error(s);return a.statusCode=(null==(r=e.response)?void 0:r.status)||500,a.originalError=e,a}static async requestPasswordReset(e){return o.g0.post("/auth/customer/forgot-password",{email:e})}static async resetPasswordWithToken(e,t){return o.g0.post("/auth/customer/reset-password",{token:e,newPassword:t})}static validateEmail(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}static validatePassword(e){let t=[];return e.length<6&&t.push("Password must be at least 6 characters long"),/[A-Z]/.test(e)||t.push("Password must contain at least one uppercase letter"),/[a-z]/.test(e)||t.push("Password must contain at least one lowercase letter"),/\d/.test(e)||t.push("Password must contain at least one number"),{isValid:0===t.length,errors:t}}}
1s.ENDPOINTS={LOGIN:"/auth/customer/login",REGISTER:"/auth/customer/register",REFRESH:"/auth/refresh",LOGOUT:"/auth/customer/logout",PROFILE:"/storefront/customer/profile"},s.COOKIE_NAMES={ACCESS_TOKEN:"store_access_token",REFRESH_TOKEN:"store_refresh_token"}},49458:(e,t,r)=>{r.d(t,{WholesaleAuthProvider:()=>u,u:()=>c});var o=r(95155),s=r(12115),a=r(88569),i=r(18720),l=r(17740);let n=(0,s.createContext)(void 0);function u(e){let{children:t}=e,[r,u]=(0,s.useState)(null),[c,h]=(0,s.useState)(!0),d=(0,s.useRef)(null),{refreshCart:E}=(0,l._)(),f=(0,s.useCallback)(()=>{d.current&&(clearInterval(d.current),d.current=null),a.r.clearAuth(),u(null),E()},[E]),m=(0,s.useCallback)(async()=>{var e,t,o,s,l,n;if(r&&a.r.getToken())try{let l=(await a.O.getProfile()).profile;if("DEACTIVATED"===l.status){i.toast.error("Your wholesale account has been deactivated. Please contact support."),f(),window.location.href="/wholesale/login";return}if(l.status!==r.status){let r={id:l.id,email:(null==(e=l.customers)?void 0:e.email)||"",firstName:(null==(t=l.customers)?void 0:t.firstName)||"",lastName:(null==(o=l.customers)?void 0:o.lastName)||"",businessName:l.businessName||"",status:l.status||"PENDING_APPROVAL",additionalDiscountTier:null!=(s=null==l?void 0:l.additionalDiscountTier)?s:0};a.r.storeCustomer(r),u(r)}}catch(e){((null==(l=e.response)?void 0:l.status)===401||(null==(n=e.response)?void 0:n.status)===403)&&(console.log("Session expired or access denied, logging out"),f(),window.location.href="/wholesale/login")}},[r,f]);(0,s.useEffect)(()=>{(async()=>{var e,t,r,o,s,i,l,n,c,d,E,f,m;let g=a.r.getCustomer(),p=a.r.getToken();if(p&&g){try{let i=await a.O.getProfile(),l={id:i.profile.id,email:(null==(e=i.profile.customers)?void 0:e.email)||"",firstName:(null==(t=i.profile.customers)?void 0:t.firstName)||"",lastName:(null==(r=i.profile.customers)?void 0:r.lastName)||"",businessName:i.profile.businessName||"",status:i.profile.status||"PENDING_APPROVAL",additionalDiscountTier:null!=(s=null==(o=i.profile)?void 0:o.additionalDiscountTier)?s:0};a.r.storeCustomer(l),u(l)}catch(r){let e=null==(i=r.response)?void 0:i.status,t=(null==(n=r.response)||null==(l=n.data)?void 0:l.message)||"";401===e||403===e||"string"==typeof t&&/authentication required/i.test(t)?(a.r.clearAuth(),u(null)):u(g)}h(!1)}else if(p&&!g){try{let e=await a.O.getProfile(),t={id:e.profile.id,email:(null==(c=e.profile.customers)?void 0:c.email)||"",firstName:(null==(d=e.profile.customers)?void 0:d.firstName)||"",lastName:(null==(E=e.profile.customers)?void 0:E.lastName)||"",businessName:e.profile.businessName||"",status:e.profile.status||"PENDING_APPROVAL",additionalDiscountTier:null!=(m=null==(f=e.profile)?void 0:f.additionalDiscountTier)?m:0};a.r.storeCustomer(t),u(t)}catch(e){console.error("Token exists but failed to fetch customer:",e),a.r.clearAuth()}h(!1)}else h(!1)})()},[]),(0,s.useEffect)(()=>{if(r&&a.r.getToken())return d.current=setInterval(m,3e4),()=>{d.current&&(clearInterval(d.current),d.current=null)}},[r,m]),(0,s.useEffect)(()=>()=>{d.current&&clearInterval(d.current)},[]);let g=async e=>{try{let t=await a.O.login(e),r={...t.customer,businessName:t.customer.businessName||""};a.r.storeTokens(t.token,t.refreshToken),a.r.storeCustomer(r),u(r)}catch(e){var t,r;throw Error((null==(r=e.response)||null==(t=r.data)?void 0:t.message)||e.message||"Login failed")}},p=async e=>{var t,r,o;try{let r=await a.O.register(e);if(r.token&&r.refreshToken&&r.customer){let e={...r.customer,businessName:r.customer.businessName||"",additionalDiscountTier:null!=(t=r.customer.additionalDiscountTier)?t:0};a.r.storeTokens(r.token,r.refreshToken),a.r.storeCustomer(e),u(e)}return r}catch(e){throw Error((null==(o=e.response)||null==(r=o.data)?void 0:r.message)||e.message||"Registration failed")}},N=async()=>{try{var e,t,r;let o=await a.O.getProfile(),s={id:o.profile.id,email:(null==(e=o.profile.customers)?void 0:e.email)||"",firstName:(null==(t=o.profile.customers)?void 0:t.firstName)||"",lastName:(null==(r=o.profile.customers)?void 0:r.lastName)||"",businessName:o.profile.businessName||"",status:o.profile.status||"PENDING_APPROVAL",wholesaleTier:o.profile.wholesaleTier||"BASIC"};a.r.storeCustomer(s),u(s)}catch(e){console.error("Failed to refresh customer:",e)}},O={customer:r,isAuthenticated:!!r&&!!a.r.getToken(),isLoading:c,login:g,register:p,logout:f,refreshCustomer:N};return(0,o.jsx)(n.Provider,{value:O,children:t})}function c(){let e=(0,s.useContext)(n);if(void 0===e)throw Error("useWholesaleAuth must be used within a WholesaleAuthProvider");return e}},65380:(e,t,r)=>{r.d(t,{A:()=>u,AuthProvider:()=>n});var o=r(95155),s=r(12115),a=r(22692),i=r(6289);let l=(0,s.createContext)(void 0);function n(e){let{children:t}
1=e,[r,n]=(0,s.useState)(null),[u,c]=(0,s.useState)(!0);(0,s.useEffect)(()=>{(async()=>{try{if(a.z.isAuthenticated())try{let e=await i.S.getProfile();n(e)}catch(e){console.error("Error loading customer profile:",e),await a.z.logout(),n(null)}else n(null)}catch(e){console.error("Error loading customer data:",e),n(null)}finally{c(!1)}})()},[]);let h=async(e,t)=>{try{await a.z.login({email:e,password:t});try{let e=await i.S.getProfile();n(e)}catch(e){throw console.error("Error loading customer profile after login:",e),await a.z.logout(),Error("Failed to load customer profile")}}catch(e){throw e}},d=async e=>{try{await a.z.register(e);try{let e=await i.S.getProfile();n(e)}catch(e){throw console.error("Error loading customer profile after register:",e),await a.z.logout(),Error("Failed to load customer profile")}}catch(e){throw e}},E=async()=>{try{await a.z.logout(),n(null)}catch(e){console.error("Logout error:",e),n(null)}},f=async()=>{try{if(a.z.isAuthenticated())try{let e=await i.S.getProfile();n(e)}catch(e){console.error("Error refreshing customer profile:",e),await a.z.logout(),n(null)}else n(null)}catch(e){console.error("Error refreshing customer:",e),n(null)}},m={customer:r,isAuthenticated:!!r&&a.z.isAuthenticated(),isLoading:u,login:h,register:d,logout:E,refreshCustomer:f};return(0,o.jsx)(l.Provider,{value:m,children:t})}function u(){let e=(0,s.useContext)(l);if(void 0===e)throw Error("useAuth must be used within an AuthProvider");return e}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.