PageSourceSearch

https://us.eureka.com/cdn/shopifycloud/checkout-web/assets/c1/AutocompleteField-hooks.DlPCpnup.js

js eureka.com collected 2026-09-25 14:25:32 UTC 12,015 bytes, 1 lines download raw bytes

1import{q as z,T as w,k as D,A as Z,h as N}from"./esnext-vendor.B9Da21W6.js";import{S as ve,dH as Ee,cK as x,dI as De,dJ as ee,dK as Le,aj as Oe,bP as Ue,dt as me,H as j,dL as Ne,dM as he,dN as Ge}from"./addresses-is-address-empty.BgqK_zG_.js";import{s as He}from"./BillingAddressForm.DavEQGPd.js";import{u as Be}from"./components-RedirectionNotice.module.CtEG0YAw.js";import{ch as $e,d_ as Ve,d$ as ke,p as te,cM as je}from"./hydrate.B4yS4myh.js";import{A as Qe}from"./hooks-useReplaceShopPayInHistory.DcFB3a73.js";function Ke(e){const{observability:t}=ve(),{geolocation:s}=$e();return z(async(n,d,u)=>{const o=await e(n,d,u);return t.histogram({name:"prediction_duration",value:o.duration.end-o.duration.start,attributes:{buyerCountry:s.country.code}}),o.data},[e,t,s.country.code])}function we(e){return new Promise((t,s)=>{Ve(e.approvalScopes,Qe.CustomerPersonalData)||s(new Ee(`Extension ${e.id} at target \`${e.extensionPoint.target}\` is missing required access to read customer personal data.`)),t()})}function xe(e,t,s){switch(!0){case e instanceof Ee:Ae(e,t);break;case e instanceof x:if(t.type==="persisted")Ae(e,t);else{const{extensionPoint:{target:n}}=t;s(new x(`[${n}] ${e.message}`))}break;default:s(e)}}function Ae(e,t){const s=`[${t.extensionPoint.target}] ${e.name}: ${e.message}`;console.error(s)}function Xe(e){if(typeof e!="object")throw new x(`formattedAddress must be an object: received type ${typeof e}`);const t=Pe(e);if(t.length)throw new x(t.join("; "));return e}function Je(e){const t=[];if(!Array.isArray(e))throw new x("An array of address suggestions must be defined");const s=e.slice(0,5);for(const[n,{id:d,label:u,matchedSubstrings:o,formattedAddress:r}]of s.entries()){if(I(u)||t.push(`label is required and must be a non-empty string: received ${typeof u} in suggestions[${n}]`),d&&!I(d)&&t.push(`id must be a non-empty string: received ${typeof d} in suggestions[${n}]`),o)if(Array.isArray(o))for(const[l,{offset:a,length:c}]of o.entries())typeof a!="number"&&t.push(`offset must be a number: received type ${typeof a} in matchedSubstrings[${l}] for suggestions[${n}]`),typeof c!="number"&&t.push(`length must be a number: received type ${typeof c} in matchedSubstrings[${l}] for suggestions[${n}]`);else t.push(`matchedSubstrings must be an array: received type ${typeof o} in suggestions[${n}]`);if(r)if(typeof r=="object"){const l=Pe(r);for(const a of l)t.push(`${a} for suggestions[${n}]`)}else t.push(`formattedAddress must be an object: received type ${typeof r} in suggestions[${n}]`);if(t.length)throw new x(t.join("; "))}return s}function Pe(e){const t=[],{address1:s,address2:n,city:d,company:u,provinceCode:o,zip:r,countryCode:l,latitude:a,longitude:c}=e;return s&&!I(s)&&t.push(`address1 must be a non-empty string: received type ${typeof s} in formattedAddress`),n&&!I(n)&&t.push(`address2 must be a non-empty string: received type ${typeof n} in formattedAddress`),d&&!I(d)&&t.push(`city must be a non-empty string: received type ${typeof d} in formattedAddress`),u&&!I(u)&&t.push(`company must be a non-empty string: received type ${typeof u} in formattedAddress`),o&&!I(o)&&t.push(`provinceCode must be a non-empty string: received type ${typeof o} in formattedAddress`),r&&!I(r)&&t.push(`zip must be a non-empty string: received type ${typeof r} in formattedAddress`),l&&!De(l)&&t.push(`countryCode must be a valid alpha-2 country code: received "${l}" in formattedAddress`),a&&(typeof a!="number"?t.push(`latitude must be a number: received type ${typeof a} in formattedAddress`):(a<-90||a>90)&&t.push(`latitude must be between -90 and 90: received ${a} in formattedAddress`)),c&&(typeof c!="number"?t.push(`longitude must be a number: received type ${typeof c} in formattedAddress`):(c<-180||c>180)&&t.push(`longitude must be between -180 and 180: received ${c} in formattedAddress`)),t}function I(e){return typeof e=="string"||e instanceof String?e.trim().length>0:!1}function We(e){const t=ke(e),s=w(()=>e[0],[e]),n=te("purchase.address-autocomplete.suggest"),d=w(()=>n.length>0,[n]);return z(u=>s?new Promise((o,r)=>{Ye(d).then(()=>we(s)).then(()=>{const{internalId:l,...a}=u;return t({target:{selectedSuggestion:a}})}).then(l=>{const a=l?.formattedAddress||{};o({formattedAddress:Xe(a)})}).catch(l=>{xe(l,s,r),o({formattedAddress:{}})})}):Promise.resolve({formattedAddress:{}}),[t,s,d])}function Ye(e){return new Promise((t,s)=>{if(e)t();else{const n="A purchase.address-autocomplete.suggest extension is required for a purchase.address-autocomplete.format-suggestion extension";s(new x(n))}})}function Ze(e){return e.map((t,s)=>{const{id:n,label:d,matchedSubstrings:u,formattedAddress:o}=t;return{internalId:`extension-suggestion-${s}`,matchedSubstrings:et(u),label:d,...n&&{id:n},...o&&{formattedAddress:o}}})}function et(e){return e?.length?e.sort(tt):[{offset:0,length:0}]}function tt(e,t){return e.offset-t.offset}function st(e){const t=ke(e),s=w(()=>e[0],[e]);return z((n,d)=>s?new Promise((u,o)=>{d.aborted&&o(new ee(d.reason)),we(s).then(()=>t({signal:d,target:{...n}})).then(r=>r?.suggestions||[]).then(r=>Je(r)).then(r=>Ze(r)).then(r=>u(r)).catch(r=>{xe(r,s,o),u([])}),d.addEventListener("abort",()=>{o(new ee(d.reason))})}):Promise.resolve([]),[t,s])}const nt=300,ye="address_clobber",Se=20;function $(e){try{return e()}catch{return}}function ot({addressType:e,field:t,log:s,now:n=Date.now}){let d=0,u=0,o=0,r=0,l,a,c=!1,H=Se,E=Se;const q=(h,A)=>s(ye,`${ye}: ${h}`,{kind:h,addressType:e??"unknown",field:t??"unknown",...A});return{recordQuery(h){h!==l&&(l=h,r+=1)},resetPredictionContext(){a=void 0,c=!1},startPredictionRequest(){return[r,++d,n()]},recordPredictionResponse([h,A,M],L){const T=A<u,P=u;u=Math.max(u,A),a=h,c=T,!(!T||H===0)&&(H-=1,q("prediction-race",{latestAppliedPredictionGeneration:P,predictionCount:L,queryChangedSinceRequest:h!==r,requestGeneration:A,responseAgeMs:Math.max(0,n()-M)}))},startAddressRequest(){const h=c||a!==void 0&&a!==r;return[r,++o,h,n()]},recordAddressResponse([h,A,M,L]){const T=A!==o,P=h!==r;!T&&!P&&!M||E===0||(E-=1,q("address-race",{latestRequestGeneration:o,newerSelectionStarted:T,queryChangedSinceSelection:P,requestGeneration:A,responseAgeMs:Math.max(0,n()-L),selectedFromStalePredictionResponse:M}))}}}function pt({addressType:e,countryCode:t,field:s,initialAddressQuery:n="",provider:d="autocomplete-service",allowAllCountries:u}){const{i18n:{locale:o},observability:r,userEvents:l,shop:a,source:c,checkout:{address:H}}=ve(),{id:E}=a,[q,h]=D(n),[A,M]=D(q),[L,T]=D(!1),[P,F]=D([]),[se,Q]=D([]),K=Z(!1),[_,Re]=D(be(c.sourceId)
1),{geolocation:y}=$e(),Ce=a.hasFlagEnabled(Le),{search:Ie,fetchAddress:ne}=Be(),R=je(),{details:oe}=Oe(t),B=Ue(),re=H.extendedAddressMode.get(t)!==null,qe=Ce&&G(e)?Ne:void 0,ie=e==="pickup"?"google":qe,ce=Z(void 0);ce.current??=ot({addressType:e,field:s,log:(p,g,k)=>r.log(p,g,k)});const S=ce.current,de=te("purchase.address-autocomplete.suggest"),V=w(()=>de.map(me),[de]),Te=st(V),ue=w(()=>V.length>0,[V]),ae=te("purchase.address-autocomplete.format-suggestion"),X=w(()=>ae.map(me),[ae]),le=We(X),pe=w(()=>X.length>0,[X]),fe=z((p,g,k,m)=>{const b=B.value.defaultAttributes?.uniqToken||"";l.monorailEvent({schemaId:"checkout_autocomplete_suggestion/5.1",payload:{shopId:parseInt(j(E),10),checkoutToken:c.checkoutSessionIdentifier||"",uniqueToken:b,provider:g[0]?.completionService??"",context:p==="shipping"?"Shipping address":"Billing address",territoryCode:t??y.country.code,locale:o,query:k,sessionToken:_,requestProvider:m,requestLatitude:y.coordinates?.latitude,requestLongitude:y.coordinates?.longitude,addressIds:g.map(v=>v.addressId)}})},[t,y.country.code,o,_,E,c.checkoutSessionIdentifier,B.value.defaultAttributes?.uniqToken,l,y.coordinates]),J=w(()=>ue&&s&&G(e),[s,e,ue]),W=w(()=>J||u||He(t||y.country.code),[u,t,y.country.code,J]);N(()=>{const p=setTimeout(()=>{R&&M(q)},nt);return()=>{clearTimeout(p)}},[R,q]),N(()=>{$(()=>S.recordQuery(n)),h(n)},[n,S]),N(()=>{W||F([])},[W]);const Y=Z(t);N(()=>{Y.current!==t&&Y.current!==void 0&&(F([]),Q([]),K.current=!1),Y.current=t},[t]);const Fe=Ke(Ie);N(()=>{let p=!1;async function g(m){try{if(!m||typeof m!="string"||m.length<=1){$(()=>S.resetPredictionContext()),F([]);return}const b=$(()=>S.startPredictionRequest()),v=await Fe(m,{locale:o,countryCode:t??y.country.code,location:y.coordinates,requestToken:_,shopId:j(E),sourceId:c.sourceId||"",checkoutSessionIdentifier:c.checkoutSessionIdentifier||""},ie);R.current&&!p&&(b&&$(()=>S.recordPredictionResponse(b,v.length)),F(v),!K.current&&G(e)&&(fe(e,v,m,ie),K.current=!0))}catch(b){console.warn(`Unable to fetch predictions: ${b}`),R.current&&!p&&F([])}}async function k({query:m,field:b,signal:v}){function O(i){return i.map(({label:f,matchedSubstrings:C,internalId:Me})=>({addressId:Me,completionService:"AUTOCOMPLETE_EXTENSION",description:f,matchedSubstrings:C}))}function U(i){switch(i){case"address1":case"streetName":return"address1";case"postalCode":return"zip";default:{const f=i;throw new he(`Unknown Address Autocomplete field: ${f}`)}}}if(!m||typeof m!="string"||m.length<=1){$(()=>S.resetPredictionContext()),Q([]),F([]);return}try{const i=$(()=>S.startPredictionRequest()),f=await Te({value:m,field:U(b),selectedCountryCode:t},v);R.current&&!p&&(i&&$(()=>S.recordPredictionResponse(i,f.length)),Q(f),F(O(f)))}catch(i){if(i instanceof he&&r.error(i),V[0].type==="local")if(i instanceof ee)console.warn("AddressAutocompleteSignalAbortedError: ",i.message);else throw i}}if(W&&L)if(J&&G(e)){const m=new AbortController;return k({query:A,field:s,signal:m.signal}),()=>{p=!0,m.abort("The query was debounced")}}else g(A);return()=>{p=!0}},[t,A,o,_,fe]);const ge=z((p,g,k,m,b)=>{const v=oe?.zones.find(i=>i.code===g.zoneCode)?.name||void 0,O=B.value.defaultAttributes?.uniqToken,U=k.findIndex(i=>i.addressId===p)+1;l.monorailEvent({schemaId:"checkout_autocomplete_selection/6.2",payload:{shopId:parseInt(j(E),10),checkoutToken:c.checkoutSessionIdentifier||"",uniqueToken:O,address1:g.address1,address2:g.address2,city:g.city,zone:v,latitude:g.coordinates?.latitude,longitude:g.coordinates?.longitude,zip:g.postalCode,territoryCode:t??y.country.code,position:U,query:A,context:m==="shipping"?"Shipping address":"Billing address",locale:o,sessionToken:b,requestLatitude:y.coordinates?.latitude,requestLongitude:y.coordinates?.longitude}})},[oe,B.value.defaultAttributes?.uniqToken,E,c.checkoutSessionIdentifier,t,y.country.code,y.coordinates,A,o,l]),_e=z(async(p,g,k,m)=>{const b=$(()=>S.startAddressRequest());function v(i){const f=se.find(C=>C.internalId===i);return f||r.error(new Ge("Could not find selected suggestion in extension suggestions.")),f}async function O(i){if(pe&&i)return(await le(i)).formattedAddress;const f=new x("The address fields could not be auto-populated. Please provide a `formattedAddress` for the selected suggestion or implement the `purchase.address-autocomplete.format-suggestion` extension.");console.error(`${f.name}: ${f.message}`)}async function U(i){const f=v(i),C=f?.formattedAddress||await O(f);return rt(C)}try{let i,f;if(g==="AUTOCOMPLETE_EXTENSION")i=await U(p);else{const C=_;i=await ne(p,{locale:o,requestToken:_,completionService:g,shopId:j(E),sourceId:c.sourceId||"",checkoutSessionIdentifier:c.checkoutSessionIdentifier||"",extendedFields:!k&&re}
1),f=C,R.current&&(Re(be(c.sourceId)),G(e)&&ge(p,i,P,e,C))}R.current&&(b&&$(()=>S.recordAddressResponse(b)),m(i,f))}catch(i){if(i instanceof x)throw i;console.warn(`Unable to select prediction: ${i}`)}},[o,_,E,c.sourceId,c.checkoutSessionIdentifier,ne,R,e,ge,P,pe,se,le,r,re,S]),ze=z((p,g=!0)=>{$(()=>S.recordQuery(p)),h(p),T(g)},[S]);return{value:q,debouncedValue:A,setValue:ze,predictions:P,selectPrediction:_e,provider:d}}function be(e){return`${e}-${Date.now()}`}function rt(e){return{address1:e?.address1,address2:e?.address2,city:e?.city,company:e?.company,zoneCode:e?.provinceCode,postalCode:e?.zip,coordinates:e?.latitude&&e?.longitude?{latitude:e.latitude,longitude:e.longitude}:void 0}}function G(e){return e==="billing"||e==="shipping"}export{pt as u};

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.