@everfur/sdk 1.5.1 → 1.5.2

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.
Files changed (79) hide show
  1. package/dist/care/index.cjs +2 -2
  2. package/dist/care/index.js +2 -2
  3. package/dist/chat/index.cjs +235 -234
  4. package/dist/chat/index.js +311 -310
  5. package/dist/chat/lite/index.cjs +339 -338
  6. package/dist/chat/lite/index.js +314 -313
  7. package/dist/{chunk-NBAOR5TJ.js → chunk-2T5CB5MW.js} +21 -21
  8. package/dist/{chunk-RD6ZGYEJ.js → chunk-ASE36WGP.js} +7 -7
  9. package/dist/{chunk-IO4CGYHT.js → chunk-CMDCBYUH.js} +1 -1
  10. package/dist/{chunk-ZYHPCQVM.js → chunk-K7YHXFPQ.js} +1 -1
  11. package/dist/client/index.cjs +1 -1
  12. package/dist/client/index.d.cts +1 -1
  13. package/dist/client/index.d.ts +1 -1
  14. package/dist/client/index.js +1 -1
  15. package/dist/core/index.cjs +31 -31
  16. package/dist/core/index.js +31 -31
  17. package/dist/health-plan/index.cjs +266 -266
  18. package/dist/health-plan/index.js +443 -443
  19. package/dist/{inbox.d-DJ9xgU1Z.d.ts → inbox.d-B2JXK0uI.d.ts} +1 -1
  20. package/dist/{inbox.d-CPcMMz-Y.d.cts → inbox.d-CwA1ogzV.d.cts} +1 -1
  21. package/dist/index.cjs +257 -256
  22. package/dist/index.js +364 -363
  23. package/dist/notifications/inbox/index.cjs +28 -28
  24. package/dist/notifications/inbox/index.d.cts +5 -5
  25. package/dist/notifications/inbox/index.d.ts +5 -5
  26. package/dist/notifications/inbox/index.js +53 -53
  27. package/dist/notifications/index.cjs +1 -1
  28. package/dist/notifications/index.d.cts +3 -3
  29. package/dist/notifications/index.d.ts +3 -3
  30. package/dist/notifications/index.js +1 -1
  31. package/dist/{parse.d-Cj3fURer.d.ts → parse.d-QjB2LJCd.d.ts} +19 -10
  32. package/dist/{parse.d-cH7ZmMeo.d.cts → parse.d-_Ttu2h5g.d.cts} +19 -10
  33. package/dist/records/depth/index.cjs +80 -80
  34. package/dist/records/depth/index.js +115 -115
  35. package/dist/records/index.cjs +653 -653
  36. package/dist/records/index.js +1074 -1074
  37. package/dist/{route.d-DSYEd2MR.d.ts → route.d-DtuKY5dM.d.ts} +1 -1
  38. package/dist/{route.d-DCzQh4ix.d.cts → route.d-Nt-r-7IO.d.cts} +1 -1
  39. package/dist/server/events/index.cjs +1 -1
  40. package/dist/server/events/index.js +1 -1
  41. package/dist/server/index.cjs +1 -1
  42. package/dist/server/index.js +1 -1
  43. package/dist/shop/index.cjs +188 -188
  44. package/dist/shop/index.js +386 -386
  45. package/dist/shop/orders-v2/index.cjs +72 -72
  46. package/dist/shop/orders-v2/index.js +126 -126
  47. package/dist/tabs/index.cjs +114 -111
  48. package/dist/tabs/index.d.cts +18 -5
  49. package/dist/tabs/index.d.ts +18 -5
  50. package/dist/tabs/index.js +191 -188
  51. package/dist/televet/booking/index.cjs +214 -211
  52. package/dist/televet/booking/index.js +344 -341
  53. package/dist/televet/call/index.cjs +53 -53
  54. package/dist/televet/call/index.js +67 -67
  55. package/dist/{useInboxUnread.d-CXiaR3BZ.d.ts → useInboxUnread.d-0DrQPn7J.d.ts} +1 -1
  56. package/dist/{useInboxUnread.d-DERpMelw.d.cts → useInboxUnread.d-CRcOTkmu.d.cts} +1 -1
  57. package/dist/web/health-plan/index.cjs +1 -1
  58. package/dist/web/health-plan/index.js +1 -1
  59. package/dist/web/inbox/index.cjs +1 -1
  60. package/dist/web/inbox/index.d.cts +6 -6
  61. package/dist/web/inbox/index.d.ts +6 -6
  62. package/dist/web/inbox/index.js +1 -1
  63. package/dist/web/index.cjs +184 -184
  64. package/dist/web/index.js +181 -181
  65. package/dist/web/notifications/index.cjs +1 -1
  66. package/dist/web/notifications/index.d.cts +2 -2
  67. package/dist/web/notifications/index.d.ts +2 -2
  68. package/dist/web/notifications/index.js +1 -1
  69. package/dist/web/records-sheet/index.cjs +1 -1
  70. package/dist/web/records-sheet/index.js +1 -1
  71. package/dist/web/shop/index.cjs +1 -1
  72. package/dist/web/shop/index.js +2 -2
  73. package/dist/web/televet/booking/index.cjs +1 -1
  74. package/dist/web/televet/booking/index.js +1 -1
  75. package/dist/web/televet/call/index.cjs +1 -1
  76. package/dist/web/televet/call/index.js +1 -1
  77. package/dist/web/ui/index.cjs +1 -1
  78. package/dist/web/ui/index.js +16 -16
  79. package/package.json +1 -1
@@ -1,3 +1,3 @@
1
1
  /*! @everfur/sdk. Copyright (c) 2026 Strand Health Inc. dba Everfur. All rights reserved. Use is subject to the Everfur SDK License: https://docs.everfur.com/license */
2
- "use strict";var e=99,t=5,r=t=>{let r=t?.maxQuantity;return typeof r=="number"&&Number.isFinite(r)&&r>=1?Math.floor(r):e},n=(e,t)=>Math.max(1,Math.min(t,Math.round(e)));function cartLineKey(e){return`${e.offerId}|${e.petId??""}|${e.rxId??""}`}var i=e=>typeof e=="string"&&e!=="",s=e=>typeof e=="string"&&/^https:\/\/\S+$/i.test(e)?e:void 0,o=e=>typeof e=="string"&&e.trim()!==""&&e.length<=120;function u(e){let t=e.planWords,r=t!==null&&typeof t=="object"?t:null,n=e.cadenceDays,i=e.autoUnitPrice;return{...typeof i=="number"&&Number.isInteger(i)&&i>=0?{autoUnitPrice:i}:{},...typeof n=="number"&&Number.isInteger(n)&&n>=7&&n<=365?{cadenceDays:n}:{},...e.onePerCart===true?{onePerCart:true}:{},...o(e.meta)?{meta:e.meta}:{},...o(e.packLabel)?{packLabel:e.packLabel}:{},...o(e.planLabel)?{planLabel:e.planLabel}:{},...r&&o(r.auto)&&o(r.once)?{planWords:{auto:r.auto,once:r.once}}:{},...o(e.icon)?{icon:e.icon}:{},...o(e.tint)?{tint:e.tint}:{}}}var l=(e,t)=>!!e.rxId||t?.lockRxLines===true&&e.requiresRx;function parseCartItems(e,t){if(!e)return[];let r;try{r=JSON.parse(e)}catch{return[]}return Array.isArray(r)?a(r,t):[]}function a(t,o){let l=r(o),a=[];for(let r of t){if(!r||typeof r!="object")continue;let t=r,o=t.offerId,f=t.title,d=t.quantity;if(!i(o)||typeof f!="string"||typeof d!="number"||!Number.isFinite(d))continue;let p=t.petId,c=t.rxId,h={offerId:o,...i(p)?{petId:p}:{},...i(c)?{rxId:c}:{}},x=cartLineKey(h);if(a.some(e=>e.key===x))continue;let m=t.unitPrice,y=s(t.imageUrl),C=t.plan;a.push({...h,key:x,title:f,unitPrice:typeof m=="number"&&Number.isFinite(m)?m:null,requiresRx:t.requiresRx===true,quantity:n(d,h.rxId?e:l),...y?{imageUrl:y}:{},...C==="auto"||C==="once"?{plan:C}:{},...u(t)})}return a}function addLine(e,t,i){let o=cartLineKey({offerId:t.offerId,...t.petId?{petId:t.petId}:{},...t.rxId?{rxId:t.rxId}:{}}),a=e.find(e=>e.key===o),f=l({rxId:t.rxId,requiresRx:t.requiresRx},i)||t.onePerCart===true;if(a&&f)return{items:[...e],result:"already"};let d=e=>e??"";if(!a&&t.requiresRx&&e.some(e=>e.requiresRx&&d(e.petId)===d(t.petId)))return{items:[...e],result:"rx_limit"};let p=s(t.imageUrl),c=t.plan??a?.plan??t.defaultPlan??void 0,h={offerId:t.offerId,...t.petId?{petId:t.petId}:{},...t.rxId?{rxId:t.rxId}:{},key:o,title:t.title,unitPrice:t.unitPrice,requiresRx:t.requiresRx,quantity:a?n(a.quantity+1,r(i)):1,...p?{imageUrl:p}:{},...c?{plan:c}:{},...u(t)};return{items:a?e.map(e=>e.key===o?h:e):[...e,h],result:a?"more":"added"}}function setLineQuantity(e,t,i,s){if(i<=0)return e.filter(e=>e.key!==t);let o=r(s);return e.map(e=>e.key===t&&!l(e,s)?{...e,quantity:n(i,o)}:e)}function setLinePlan(e,t,r){return e.map(e=>e.key===t?{...e,plan:r}:e)}function removeLines(e,t){let r=new Set(t);return e.filter(e=>!r.has(e.key))}function restoreLines(e,t,r){let n=new Set(e.map(e=>e.key)),i=a(t,r).filter(e=>!n.has(e.key));return i.length>0?[...e,...i]:[...e]}function linesForPet(e,t){return t?e.filter(e=>e.petId===t):[]}function lastLines(e,t=3){return t>0?e.slice(-t):[]}function rxIdFor(e,t,r){if(!r)return null;let n=(e??[]).filter(e=>e.offerId===t&&e.petId===r);return(n.find(e=>e.status==="ready")??n[0])?.rxId??null}function withRxIds(e,t){return e.map(e=>{if(!e.requiresRx||e.rxId)return e;let r=rxIdFor(t,e.offerId,e.petId);return r?{...e,rxId:r}:e})}function rxLineOf(e,t){let r=cartLineKey(t);return e.find(e=>e.key===r)??e.find(e=>e.requiresRx&&e.offerId===t.offerId&&(e.petId??"")===(t.petId??""))??null}function needsRxId(e){return e.some(e=>e.requiresRx&&!e.rxId)}function omsLines(e,t,r){return withRxIds(e,t).map(e=>({offerId:e.offerId,quantity:e.quantity,...e.petId?{petId:e.petId}:{},...e.rxId?{rxId:e.rxId}:{},...r?.withPlan&&e.plan?{plan:e.plan}:{}}))}var f=/* @__PURE__ */Object.freeze([]);function createCareCartStore(e,t){let r=f;if(e)try{r=parseCartItems(e.read(),t)}catch{r=f}let n=/* @__PURE__ */new Set,i=t=>{r=t;try{e?.write(JSON.stringify(t))}catch{}for(let e of[...n])e()};return{items:()=>r,subscribe:e=>(n.add(e),()=>{n.delete(e)}),add:e=>{let{items:n,result:s}=addLine(r,e,t);return(s==="added"||s==="more")&&i(n),s},setQuantity:(e,n)=>i(setLineQuantity(r,e,n,t)),setPlan:(e,t)=>i(setLinePlan(r,e,t)),remove:e=>i(removeLines(r,[e])),removeKeys:e=>{let t=new Set(e);r.some(e=>t.has(e.key))&&i(removeLines(r,e))},restore:e=>{let n=restoreLines(r,e,t);n.length!==r.length&&i(n)},clear:()=>{r.length>0&&i(f)}}}var d=/* @__PURE__ */new Set(["a","about","again","an","and","as","at","back","before","but","by","down","for","from","here","if","in","into","now","off","on","or","out","over","so","than","that","the","there","through","to","too","up","when","with"]),p=/* @__PURE__ */new Set(["already","also","always","just","never","often","only","really","still","sometimes","usually"]),c=/* @__PURE__ */new Set(["been","done","gone","got","had","seen","eaten","taken","given"]),h={has:"have",is:"are",was:"were",does:"do"},x=/[A-Za-z]+(?:[’'][A-Za-z]+)?/g,m=(e,t)=>t[0]===t[0]?.toUpperCase()?(e[0]??"").toUpperCase()+e.slice(1):e;function theyVerb(e){let t=/^([A-Za-z]+)(n[’']t)?$/.exec(e);if(!t)return e;let r=t[1]??"",n=t[2]??"",i=r.toLowerCase(),s,o=h[i];if(o!==void 0)s=o;else if(/[^aeiou]ies$/.test(i))s=i.slice(0,-3)+"y";else if(/(ss|sh|ch|x|z|o)es$/.test(i))s=i.slice(0,-2);else if(/[^su]s$/.test(i))s=i.slice(0,-1);else return e;return m(s,r)+n}function swapPronoun(e,t){if(t==="her"||!/\b(?:her|hers|herself|she)\b/i.test(e))return e;let r=[...e.matchAll(x)],n=[],i=0,s=-1,o=t=>{let n=r[t],i=r[t-1];if(!n||!i)return null;let s=e.slice((i.index??0)+i[0].length,n.index);return/^\s+$/.test(s)?n:null};return r.forEach((r,u)=>{let l=r[0],a=r.index??0,f=o(u+1),h=f?f[0].toLowerCase():null,x=l.toLowerCase().replace("’","'"),y=null;if(u===s)y=theyVerb(l);else if(x==="her"){let e=h===null||d.has(h);y=t==="his"?e?"him":"his":e?"them":"their"}else if(x==="hers")y=t==="his"?"his":"theirs";else if(x==="herself")y=t==="his"?"himself":"themselves";else if(x==="she")y=t==="his"?"he":"they",t==="their"&&h!==null&&(s=p.has(h)&&o(u+2)?u+2:u+1);else if(x==="she's"){let e=l.includes("’")?"’":"'";y=t==="his"?`he${e}s`:`they${e}${h!==null&&c.has(h)?"ve":"re"}`}y!==null&&(n.push(e.slice(i,a),m(y,l)),i=a+l.length)}),n.push(e.slice(i)),n.join("")}function swapPronounCopy(e,t,r=[]){if(t==="her")return e;let n=e=>typeof e=="string"?swapPronoun(e,t):Array.isArray(e)?e.map(n):typeof e=="function"?(...t)=>n(e(...t)):e,i={};for(let[t,s]of Object.entries(e))i[t]=r.includes(t)?s:n(s);return i}function pronounForSex(e){return e==="female"?"her":e==="male"?"his":"their"}function unitCents(e,t=null){return t==="auto"&&e.plan==="auto"&&typeof e.autoUnitPrice=="number"?e.autoUnitPrice:e.unitPrice}function lineCents(e,t=null){return(unitCents(e,t)??0)*e.quantity}function cartTotals(e,t){let r=t.firstAutoOrderPrice??null,n=0,i=0,s=0,o=false;for(let t of e)t.unitPrice===null&&(o=true),t.requiresRx?n+=lineCents(t,r):i+=lineCents(t,r),s+=t.quantity;let u=n>0?Math.min(Math.max(0,t.firstRxDiscountCents??0),n):0,l=t.freeShippingThresholdCents??null;return{count:s,rxCents:n,boxCents:i,offCents:u,itemsCents:i+n-u,bigCents:i>0?i:n-u,toFreeCents:i>0&&l!==null&&i<l?l-i:0,unpriced:o}}function discountedLineKey(e,t){return t.offCents<=0?null:e.find(e=>e.requiresRx)?.key??null}function careMoney(e){return`${e<0?"-":""}$${(Math.abs(e)/100).toFixed(2)}`}function careMoneyShort(e){return e%100===0?`${e<0?"-":""}$${Math.abs(e)/100}`:careMoney(e)}function careItemCount(e){return`${e} ${e===1?"item":"items"}`}var y={shippingAtCheckout:"shipping at checkout",chargedWhenFilled:"charged when it’s filled",rxLimit:e=>`One prescription per cart. Order the one in it, then add ${e}.`};function careTrayCopy(e,t="her"){let r=e.offCents>0?swapPronoun(`${careMoney(e.itemsCents)} with ${careMoneyShort(e.offCents)} off her first prescription`,t):`${careMoney(e.itemsCents)} before tax`;return{button:`View cart · ${careItemCount(e.count)}`,fine:r}}function careFloatCopy(e,t){let r=careMoney(e.bigCents);if(e.rxCents>0&&e.boxCents>0)return{big:r,sub:`today, + ${careMoney(e.rxCents-e.offCents)} Rx when filled`,subIsOffer:false};if(e.rxCents>0)return e.offCents<=0?{big:r,sub:y.chargedWhenFilled,subIsOffer:false}:{big:r,sub:`when it’s filled, ${careMoneyShort(e.offCents)} off`,subIsOffer:true};let n=careItemCount(e.count);if(t===null)return{big:r,sub:`${n} · ${y.shippingAtCheckout}`,subIsOffer:false};let i=e.boxCents>=t;return{big:r,sub:i?`${n} · ships free`:`${n} · free shipping over ${careMoneyShort(t)}`,subIsOffer:false}}function careAddToast(e,t,r){return e==="already"?`${t} is already in the cart.`:e==="rx_limit"?y.rxLimit(t):r?`${t} refill added. The pharmacist checks it once you order.`:`${t} added to the cart.`}function cartBarSub(e,t,r="her"){let n=`${careItemCount(e.count)} · `;return e.offCents>0?swapPronoun(`${n}${careMoneyShort(e.offCents)} off her first prescription`,r):e.toFreeCents>0?`${n}${careMoney(e.toFreeCents)} to free shipping`:e.rxCents>0||e.boxCents===0?careItemCount(e.count):t===null?null:`${n}ships free`}var C={added:e=>`${e} added to the cart`,removed:e=>`${e} removed from the cart`,count:(e,t)=>`${e}: ${t} in the cart`};function shownLinePrices(e,t,r){let n=/* @__PURE__ */new Map,i=/* @__PURE__ */new Set;for(let s of e){let e=t?t.findIndex((e,t)=>!i.has(t)&&e.offerId===s.offerId&&(!e.petId||!s.petId||e.petId===s.petId)):-1,o=s.key===r.discountedKey,u=t&&e>=0?t[e]:void 0;if(u){i.add(e);let t=o?Math.max(0,Math.min(r.offCents,u.discountCents)):0;n.set(s.key,{priceCents:u.netCents+t,offCents:t})}else{let e=lineCents(s,r.firstAutoOrderPrice);n.set(s.key,{priceCents:e,offCents:o?Math.min(r.offCents,e):0})}}return n}function lineMeta(e,t){let r=e.toLowerCase(),n=[];for(let e of t){let t=e?.trim();if(!t)continue;let i=t.toLowerCase();r.includes(i)||n.some(e=>e.toLowerCase()===i)||n.push(t)}return n.join(" · ")}function I(e){/* @__PURE__ */
3
- return Object.freeze({ok:false,error:/* @__PURE__ */Object.freeze(e)})}function adaptQuote(e,t){let r=new Set(t.filter(e=>e.requiresRx).map(e=>e.offerId)),n=e=>e.isRx??e.chargedWhenFilled??r.has(e.offerId),i=e=>e.unitPrice*e.quantity,s=e=>i(e)-e.discount+e.tax,o=e.lines.map(e=>({offerId:e.offerId,petId:e.petId,quantity:e.quantity,grossCents:i(e),discountCents:e.discount,netCents:i(e)-e.discount})),u=e.lines.filter(e=>!n(e)),l=e.lines.filter(n),a=e.whenFilledDiscountCents??l.reduce((e,t)=>e+(t.whenFilledDiscountCents??0),0),f=u.reduce((e,t)=>e+s(t),0)+e.shipping,d=l.reduce((e,t)=>e+s(t),0);return{lines:o,itemsCents:o.reduce((e,t)=>e+t.netCents,0),totalCents:e.total,taxCents:e.tax,shippingCents:e.shipping,dueTodayCents:e.dueTodayCents??f,dueWhenFilledCents:e.dueWhenFilledCents??d,whenFilledDiscountCents:a,serverSplit:e.dueTodayCents!=null&&e.dueWhenFilledCents!=null,expiresAt:e.expiresAt,shipsOn:e.shipsOn??null,arrivesOn:e.arrivesOn??null}}function omsReceipt(e,t){let r=e.receipt;return typeof r!="function"?Promise.resolve(I({kind:"unavailable"})):r.call(e,t)}var b=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),g=e=>typeof e=="string"&&e.trim()!==""?e:null,_=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0?e:null,$=e=>{let t=g(e);return t!==null&&/^https:\/\/\S+$/i.test(t)?t:null},A=/^\d{4}-\d{2}-\d{2}$/;function firstAutoOrderPriceOf(e){let t=b(e)?e.first_auto_order_price:null;return t==="once"||t==="auto"?t:null}function firstRxDiscountCodeOf(e){let t=b(e)?e.first_rx_discount_code:null;return typeof t=="string"&&t.trim().length>0&&t.length<=32?t.trim():null}function rxShipsToStatesOf(e){let t=b(e)?e.rx_ships_to_states:null;if(!Array.isArray(t)||t.length===0)return null;let r=t.filter(e=>typeof e=="string"&&/^[A-Za-z]{2}$/.test(e));return r.length===t.length?r.map(e=>e.toUpperCase()):null}function tooSoonOnOf(e){if(!b(e)||e.reason_code!=="too_soon")return null;let t=e.available_on;return typeof t=="string"&&A.test(t)?t:null}function addressLocationOf(e){if(!b(e))return null;let t=e.latitude,r=e.longitude,n=g(e.place_id);return typeof t!="number"||!Number.isFinite(t)||Math.abs(t)>90||typeof r!="number"||!Number.isFinite(r)||Math.abs(r)>180||n===null?null:{latitude:t,longitude:r,placeId:n}}function addressLocationToWire(e){return{latitude:e.latitude,longitude:e.longitude,place_id:e.placeId}}function petQuery(e,t,r){if(!r||t.toUpperCase()!=="GET")return e;let n="https://oms.invalid",i;try{i=new URL(e,n)}catch{return e}let s=i.pathname.replace(/\/+$/,"");return!s.endsWith("/orders")&&!s.endsWith("/buy-again")?e:(i.searchParams.set("pet_id",r),i.origin===n&&!e.startsWith(n)?`${i.pathname}${i.search}`:i.href)}function R(e,t,r){if(b(e))return e[t]!==void 0?e[t]:e[r]}function summaryPetId(e){let t=R(e,"petId","pet_id");return t===void 0?void 0:g(t)}function summaryNeedsPayment(e){return R(e,"needsPayment","needs_payment")===true}function summaryLineCount(e){return _(R(e,"lineCount","line_count"))}function summaryClinicName(e){return g(R(e,"clinicName","clinic_name"))}function summaryDiscountCode(e){return g(R(e,"discountCode","discount_code"))}function againPetId(e){return g(R(e,"petId","pet_id"))}function planTitle(e){return g(R(e,"title","title"))}function planImageUrl(e){return $(R(e,"imageUrl","image_url"))}function planResumeShipOn(e){return g(R(e,"resumeShipOn","resume_ship_on"))}function orderCardActionUrl(e){let t=R(e,"cardActionLink","card_action_link");return $(typeof t=="string"?t:R(t,"url","url"))}function receiptRefund(e){let t=_(R(e,"refundedCents","refunded_cents"));return t===null||t<=0?null:{cents:t,on:g(R(e,"refundedOn","refunded_on"))}}var S=5,v=3,w=/* @__PURE__ */Object.freeze({available:false,suggestions:/* @__PURE__ */Object.freeze([])}),k=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),O=e=>typeof e=="string"&&e.trim()!==""?e.trim():null,P=(e,t)=>typeof e=="number"&&Number.isFinite(e)&&Math.abs(e)<=t?e:null;function parseAddressSuggestions(e,t=5){if(!k(e)||e.available!==true||!Array.isArray(e.suggestions))return w;let r=[];for(let n of e.suggestions){if(r.length>=t)break;if(!k(n))continue;let e=O(n.place_id),i=O(n.main);!e||!i||r.push({placeId:e,main:i,secondary:O(n.secondary)??""})}return{available:true,suggestions:r}}function parseAddressPlace(e){if(!k(e))return null;let t=O(e.line1),r=O(e.city),n=O(e.region),i=O(e.postal_code),s=O(e.place_id),o=P(e.latitude,90),u=P(e.longitude,180);return!t||!r||!n||!i||!s||o===null||u===null?null:{line1:t,city:r,region:n.toUpperCase(),postalCode:i,country:O(e.country)??"US",location:{latitude:o,longitude:u,placeId:s}}}function addressPlaceResult(e,t){if(e===404)return{kind:"notAddress"};if(e<200||e>=300)return{kind:"unavailable"};let r=parseAddressPlace(t);return r?{kind:"ok",place:r}:{kind:"unavailable"}}exports.CARE_ADDRESS_SEARCH_MIN_CHARS=v;exports.CARE_ADDRESS_SEARCH_OFF=w;exports.CARE_ADDRESS_SUGGESTIONS_SHOWN=S;exports.CARE_CART_MAX_QUANTITY=t;exports.CARE_CART_OMS_MAX_QUANTITY=e;exports.CARE_CART_UNDRAWN=y;exports.adaptQuote=adaptQuote;exports.addLine=addLine;exports.addressLocationOf=addressLocationOf;exports.addressLocationToWire=addressLocationToWire;exports.addressPlaceResult=addressPlaceResult;exports.againPetId=againPetId;exports.careAddToast=careAddToast;exports.careFloatCopy=careFloatCopy;exports.careItemCount=careItemCount;exports.careMoney=careMoney;exports.careMoneyShort=careMoneyShort;exports.careTrayCopy=careTrayCopy;exports.cartBarSub=cartBarSub;exports.cartLineKey=cartLineKey;exports.cartSaid=C;exports.cartTotals=cartTotals;exports.createCareCartStore=createCareCartStore;exports.discountedLineKey=discountedLineKey;exports.firstAutoOrderPriceOf=firstAutoOrderPriceOf;exports.firstRxDiscountCodeOf=firstRxDiscountCodeOf;exports.lastLines=lastLines;exports.lineCents=lineCents;exports.lineMeta=lineMeta;exports.linesForPet=linesForPet;exports.needsRxId=needsRxId;exports.omsLines=omsLines;exports.omsReceipt=omsReceipt;exports.orderCardActionUrl=orderCardActionUrl;exports.parseAddressPlace=parseAddressPlace;exports.parseAddressSuggestions=parseAddressSuggestions;exports.parseCartItems=parseCartItems;exports.petQuery=petQuery;exports.planImageUrl=planImageUrl;exports.planResumeShipOn=planResumeShipOn;exports.planTitle=planTitle;exports.pronounForSex=pronounForSex;exports.receiptRefund=receiptRefund;exports.removeLines=removeLines;exports.restoreLines=restoreLines;exports.rxIdFor=rxIdFor;exports.rxLineOf=rxLineOf;exports.rxShipsToStatesOf=rxShipsToStatesOf;exports.setLinePlan=setLinePlan;exports.setLineQuantity=setLineQuantity;exports.shownLinePrices=shownLinePrices;exports.summaryClinicName=summaryClinicName;exports.summaryDiscountCode=summaryDiscountCode;exports.summaryLineCount=summaryLineCount;exports.summaryNeedsPayment=summaryNeedsPayment;exports.summaryPetId=summaryPetId;exports.swapPronoun=swapPronoun;exports.swapPronounCopy=swapPronounCopy;exports.theyVerb=theyVerb;exports.tooSoonOnOf=tooSoonOnOf;exports.unitCents=unitCents;exports.withRxIds=withRxIds;
2
+ "use strict";var e=99,t=5,r=t=>{let r=t?.maxQuantity;return typeof r=="number"&&Number.isFinite(r)&&r>=1?Math.floor(r):e},n=(e,t)=>Math.max(1,Math.min(t,Math.round(e)));function cartLineKey(e){return`${e.offerId}|${e.petId??""}|${e.rxId??""}`}var i=e=>typeof e=="string"&&e!=="",s=e=>typeof e=="string"&&/^https:\/\/\S+$/i.test(e)?e:void 0,o=e=>typeof e=="string"&&e.trim()!==""&&e.length<=120;function u(e){let t=e.planWords,r=t!==null&&typeof t=="object"?t:null,n=e.cadenceDays,i=e.autoUnitPrice;return{...typeof i=="number"&&Number.isInteger(i)&&i>=0?{autoUnitPrice:i}:{},...typeof n=="number"&&Number.isInteger(n)&&n>=7&&n<=365?{cadenceDays:n}:{},...e.onePerCart===true?{onePerCart:true}:{},...o(e.meta)?{meta:e.meta}:{},...o(e.packLabel)?{packLabel:e.packLabel}:{},...o(e.planLabel)?{planLabel:e.planLabel}:{},...r&&o(r.auto)&&o(r.once)?{planWords:{auto:r.auto,once:r.once}}:{},...o(e.icon)?{icon:e.icon}:{},...o(e.tint)?{tint:e.tint}:{}}}var l=(e,t)=>!!e.rxId||t?.lockRxLines===true&&e.requiresRx;function parseCartItems(e,t){if(!e)return[];let r;try{r=JSON.parse(e)}catch{return[]}return Array.isArray(r)?a(r,t):[]}function a(t,o){let l=r(o),a=[];for(let r of t){if(!r||typeof r!="object")continue;let t=r,o=t.offerId,f=t.title,d=t.quantity;if(!i(o)||typeof f!="string"||typeof d!="number"||!Number.isFinite(d))continue;let p=t.petId,c=t.rxId,h={offerId:o,...i(p)?{petId:p}:{},...i(c)?{rxId:c}:{}},x=cartLineKey(h);if(a.some(e=>e.key===x))continue;let y=t.unitPrice,m=s(t.imageUrl),C=t.plan;a.push({...h,key:x,title:f,unitPrice:typeof y=="number"&&Number.isFinite(y)?y:null,requiresRx:t.requiresRx===true,quantity:n(d,h.rxId?e:l),...m?{imageUrl:m}:{},...C==="auto"||C==="once"?{plan:C}:{},...u(t)})}return a}function addLine(e,t,i){let o=cartLineKey({offerId:t.offerId,...t.petId?{petId:t.petId}:{},...t.rxId?{rxId:t.rxId}:{}}),a=e.find(e=>e.key===o),f=l({rxId:t.rxId,requiresRx:t.requiresRx},i)||t.onePerCart===true;if(a&&f)return{items:[...e],result:"already"};let d=e=>e??"";if(!a&&t.requiresRx&&e.some(e=>e.requiresRx&&d(e.petId)===d(t.petId)))return{items:[...e],result:"rx_limit"};let p=s(t.imageUrl),c=t.plan??a?.plan??t.defaultPlan??void 0,h={offerId:t.offerId,...t.petId?{petId:t.petId}:{},...t.rxId?{rxId:t.rxId}:{},key:o,title:t.title,unitPrice:t.unitPrice,requiresRx:t.requiresRx,quantity:a?n(a.quantity+1,r(i)):1,...p?{imageUrl:p}:{},...c?{plan:c}:{},...u(t)};return{items:a?e.map(e=>e.key===o?h:e):[...e,h],result:a?"more":"added"}}function setLineQuantity(e,t,i,s){if(i<=0)return e.filter(e=>e.key!==t);let o=r(s);return e.map(e=>e.key===t&&!l(e,s)?{...e,quantity:n(i,o)}:e)}function setLinePlan(e,t,r){return e.map(e=>e.key===t?{...e,plan:r}:e)}function removeLines(e,t){let r=new Set(t);return e.filter(e=>!r.has(e.key))}function restoreLines(e,t,r){let n=new Set(e.map(e=>e.key)),i=a(t,r).filter(e=>!n.has(e.key));return i.length>0?[...e,...i]:[...e]}function linesForPet(e,t){return t?e.filter(e=>e.petId===t):[]}function lastLines(e,t=3){return t>0?e.slice(-t):[]}function rxIdFor(e,t,r){if(!r)return null;let n=(e??[]).filter(e=>e.offerId===t&&e.petId===r);return(n.find(e=>e.status==="ready")??n[0])?.rxId??null}function withRxIds(e,t){return e.map(e=>{if(!e.requiresRx||e.rxId)return e;let r=rxIdFor(t,e.offerId,e.petId);return r?{...e,rxId:r}:e})}function rxLineOf(e,t){let r=cartLineKey(t);return e.find(e=>e.key===r)??e.find(e=>e.requiresRx&&e.offerId===t.offerId&&(e.petId??"")===(t.petId??""))??null}function needsRxId(e){return e.some(e=>e.requiresRx&&!e.rxId)}function omsLines(e,t,r){return withRxIds(e,t).map(e=>({offerId:e.offerId,quantity:e.quantity,...e.petId?{petId:e.petId}:{},...e.rxId?{rxId:e.rxId}:{},...r?.withPlan&&e.plan?{plan:e.plan}:{}}))}var f=/* @__PURE__ */Object.freeze([]);function createCareCartStore(e,t){let r=f;if(e)try{r=parseCartItems(e.read(),t)}catch{r=f}let n=/* @__PURE__ */new Set,i=t=>{r=t;try{e?.write(JSON.stringify(t))}catch{}for(let e of[...n])e()};return{items:()=>r,subscribe:e=>(n.add(e),()=>{n.delete(e)}),add:e=>{let{items:n,result:s}=addLine(r,e,t);return(s==="added"||s==="more")&&i(n),s},setQuantity:(e,n)=>i(setLineQuantity(r,e,n,t)),setPlan:(e,t)=>i(setLinePlan(r,e,t)),remove:e=>i(removeLines(r,[e])),removeKeys:e=>{let t=new Set(e);r.some(e=>t.has(e.key))&&i(removeLines(r,e))},restore:e=>{let n=restoreLines(r,e,t);n.length!==r.length&&i(n)},clear:()=>{r.length>0&&i(f)}}}var d=/* @__PURE__ */new Set(["a","about","again","an","and","as","at","back","before","but","by","down","for","from","here","if","in","into","now","off","on","or","out","over","so","than","that","the","there","through","to","too","up","when","with"]),p=/* @__PURE__ */new Set(["already","also","always","just","never","often","only","really","still","sometimes","usually"]),c=/* @__PURE__ */new Set(["been","done","gone","got","had","seen","eaten","taken","given"]),h={has:"have",is:"are",was:"were",does:"do"},x=/[A-Za-z]+(?:[’'][A-Za-z]+)?/g,y=(e,t)=>t[0]===t[0]?.toUpperCase()?(e[0]??"").toUpperCase()+e.slice(1):e;function theyVerb(e){let t=/^([A-Za-z]+)(n[’']t)?$/.exec(e);if(!t)return e;let r=t[1]??"",n=t[2]??"",i=r.toLowerCase(),s,o=h[i];if(o!==void 0)s=o;else if(/[^aeiou]ies$/.test(i))s=i.slice(0,-3)+"y";else if(/(ss|sh|ch|x|z|o)es$/.test(i))s=i.slice(0,-2);else if(/[^su]s$/.test(i))s=i.slice(0,-1);else return e;return y(s,r)+n}function swapPronoun(e,t){if(t==="her"||!/\b(?:her|hers|herself|she)\b/i.test(e))return e;let r=[...e.matchAll(x)],n=[],i=0,s=-1,o=t=>{let n=r[t],i=r[t-1];if(!n||!i)return null;let s=e.slice((i.index??0)+i[0].length,n.index);return/^\s+$/.test(s)?n:null};return r.forEach((r,u)=>{let l=r[0],a=r.index??0,f=o(u+1),h=f?f[0].toLowerCase():null,x=l.toLowerCase().replace("’","'"),m=null;if(u===s)m=theyVerb(l);else if(x==="her"){let e=h===null||d.has(h);m=t==="his"?e?"him":"his":e?"them":"their"}else if(x==="hers")m=t==="his"?"his":"theirs";else if(x==="herself")m=t==="his"?"himself":"themselves";else if(x==="she")m=t==="his"?"he":"they",t==="their"&&h!==null&&(s=p.has(h)&&o(u+2)?u+2:u+1);else if(x==="she's"){let e=l.includes("’")?"’":"'";m=t==="his"?`he${e}s`:`they${e}${h!==null&&c.has(h)?"ve":"re"}`}m!==null&&(n.push(e.slice(i,a),y(m,l)),i=a+l.length)}),n.push(e.slice(i)),n.join("")}function swapPronounCopy(e,t,r=[]){if(t==="her")return e;let n=e=>typeof e=="string"?swapPronoun(e,t):Array.isArray(e)?e.map(n):typeof e=="function"?(...t)=>n(e(...t)):e,i={};for(let[t,s]of Object.entries(e))i[t]=r.includes(t)?s:n(s);return i}function pronounForSex(e){return e==="female"?"her":e==="male"?"his":"their"}function unitCents(e,t=null){return t==="auto"&&e.plan==="auto"&&typeof e.autoUnitPrice=="number"?e.autoUnitPrice:e.unitPrice}function lineCents(e,t=null){return(unitCents(e,t)??0)*e.quantity}function cartTotals(e,t){let r=t.firstAutoOrderPrice??null,n=0,i=0,s=0,o=false;for(let t of e)t.unitPrice===null&&(o=true),t.requiresRx?n+=lineCents(t,r):i+=lineCents(t,r),s+=t.quantity;let u=n>0?Math.min(Math.max(0,t.firstRxDiscountCents??0),n):0,l=t.freeShippingThresholdCents??null;return{count:s,rxCents:n,boxCents:i,offCents:u,itemsCents:i+n-u,bigCents:i>0?i:n-u,toFreeCents:i>0&&l!==null&&i<l?l-i:0,unpriced:o}}function discountedLineKey(e,t){return t.offCents<=0?null:e.find(e=>e.requiresRx)?.key??null}function careMoney(e){return`${e<0?"-":""}$${(Math.abs(e)/100).toFixed(2)}`}function careMoneyShort(e){return e%100===0?`${e<0?"-":""}$${Math.abs(e)/100}`:careMoney(e)}function careItemCount(e){return`${e} ${e===1?"item":"items"}`}var m={shippingAtCheckout:"shipping at checkout",chargedWhenFilled:"charged when it’s filled",rxLimit:e=>`One prescription per cart. Order the one in it, then add ${e}.`};function careTrayCopy(e,t="her"){let r=e.offCents>0?swapPronoun(`${careMoney(e.itemsCents)} with ${careMoneyShort(e.offCents)} off her first prescription`,t):`${careMoney(e.itemsCents)} before tax`;return{button:`View cart · ${careItemCount(e.count)}`,fine:r}}function careFloatCopy(e,t){let r=careMoney(e.bigCents);if(e.rxCents>0&&e.boxCents>0)return{big:r,sub:`today, + ${careMoney(e.rxCents-e.offCents)} Rx when filled`,subIsOffer:false};if(e.rxCents>0)return e.offCents<=0?{big:r,sub:m.chargedWhenFilled,subIsOffer:false}:{big:r,sub:`when it’s filled, ${careMoneyShort(e.offCents)} off`,subIsOffer:true};let n=careItemCount(e.count);if(t===null)return{big:r,sub:`${n} · ${m.shippingAtCheckout}`,subIsOffer:false};let i=e.boxCents>=t;return{big:r,sub:i?`${n} · ships free`:`${n} · free shipping over ${careMoneyShort(t)}`,subIsOffer:false}}function careAddToast(e,t,r){return e==="already"?`${t} is already in the cart.`:e==="rx_limit"?m.rxLimit(t):r?`${t} refill added. The pharmacist checks it once you order.`:`${t} added to the cart.`}function cartBarSub(e,t,r="her"){let n=`${careItemCount(e.count)} · `;return e.offCents>0?swapPronoun(`${n}${careMoneyShort(e.offCents)} off her first prescription`,r):e.toFreeCents>0?`${n}${careMoney(e.toFreeCents)} to free shipping`:e.rxCents>0||e.boxCents===0?careItemCount(e.count):t===null?null:`${n}ships free`}var C={added:e=>`${e} added to the cart`,removed:e=>`${e} removed from the cart`,count:(e,t)=>`${e}: ${t} in the cart`};function shownLinePrices(e,t,r){let n=/* @__PURE__ */new Map,i=/* @__PURE__ */new Set;for(let s of e){let e=t?t.findIndex((e,t)=>!i.has(t)&&e.offerId===s.offerId&&(!e.petId||!s.petId||e.petId===s.petId)):-1,o=s.key===r.discountedKey,u=t&&e>=0?t[e]:void 0;if(u){i.add(e);let t=o?Math.max(0,Math.min(r.offCents,u.discountCents)):0;n.set(s.key,{priceCents:u.netCents+t,offCents:t})}else{let e=lineCents(s,r.firstAutoOrderPrice);n.set(s.key,{priceCents:e,offCents:o?Math.min(r.offCents,e):0})}}return n}function lineMeta(e,t){let r=e.toLowerCase(),n=[];for(let e of t){let t=e?.trim();if(!t)continue;let i=t.toLowerCase();r.includes(i)||n.some(e=>e.toLowerCase()===i)||n.push(t)}return n.join(" · ")}function I(e){/* @__PURE__ */
3
+ return Object.freeze({ok:false,error:/* @__PURE__ */Object.freeze(e)})}function adaptQuote(e,t){let r=new Set(t.filter(e=>e.requiresRx).map(e=>e.offerId)),n=e=>e.isRx??e.chargedWhenFilled??r.has(e.offerId),i=e=>e.unitPrice*e.quantity,s=e=>i(e)-e.discount+e.tax,o=e.lines.map(e=>({offerId:e.offerId,petId:e.petId,quantity:e.quantity,grossCents:i(e),discountCents:e.discount,netCents:i(e)-e.discount})),u=e.lines.filter(e=>!n(e)),l=e.lines.filter(n),a=e.whenFilledDiscountCents??l.reduce((e,t)=>e+(t.whenFilledDiscountCents??0),0),f=u.reduce((e,t)=>e+s(t),0)+e.shipping,d=l.reduce((e,t)=>e+s(t),0);return{lines:o,itemsCents:o.reduce((e,t)=>e+t.netCents,0),totalCents:e.total,taxCents:e.tax,shippingCents:e.shipping,dueTodayCents:e.dueTodayCents??f,dueWhenFilledCents:e.dueWhenFilledCents??d,whenFilledDiscountCents:a,serverSplit:e.dueTodayCents!=null&&e.dueWhenFilledCents!=null,expiresAt:e.expiresAt,shipsOn:e.shipsOn??null,arrivesOn:e.arrivesOn??null}}function omsReceipt(e,t){let r=e.receipt;return typeof r!="function"?Promise.resolve(I({kind:"unavailable"})):r.call(e,t)}var b=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),g=e=>typeof e=="string"&&e.trim()!==""?e:null,$=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0?e:null,_=e=>{let t=g(e);return t!==null&&/^https:\/\/\S+$/i.test(t)?t:null},A=/^\d{4}-\d{2}-\d{2}$/;function firstAutoOrderPriceOf(e){let t=b(e)?e.first_auto_order_price:null;return t==="once"||t==="auto"?t:null}function firstRxDiscountCodeOf(e){let t=b(e)?e.first_rx_discount_code:null;return typeof t=="string"&&t.trim().length>0&&t.length<=32?t.trim():null}function rxShipsToStatesOf(e){let t=b(e)?e.rx_ships_to_states:null;if(!Array.isArray(t)||t.length===0)return null;let r=t.filter(e=>typeof e=="string"&&/^[A-Za-z]{2}$/.test(e));return r.length===t.length?r.map(e=>e.toUpperCase()):null}function tooSoonOnOf(e){if(!b(e)||e.reason_code!=="too_soon")return null;let t=e.available_on;return typeof t=="string"&&A.test(t)?t:null}function addressLocationOf(e){if(!b(e))return null;let t=e.latitude,r=e.longitude,n=g(e.place_id);return typeof t!="number"||!Number.isFinite(t)||Math.abs(t)>90||typeof r!="number"||!Number.isFinite(r)||Math.abs(r)>180||n===null?null:{latitude:t,longitude:r,placeId:n}}function addressLocationToWire(e){return{latitude:e.latitude,longitude:e.longitude,place_id:e.placeId}}function petQuery(e,t,r){if(!r||t.toUpperCase()!=="GET")return e;let n=/^([a-z][a-z0-9+.-]*:\/\/[^/?#]*)?([^?#]*)(\?[^#]*)?(#.*)?$/i.exec(e);if(n===null)return e;let[,i="",s="",o="",u=""]=n,l=s.replace(/\/+$/,"");if(!l.endsWith("/orders")&&!l.endsWith("/buy-again"))return e;let a=o.replace(/^\?/,"").split("&").filter(e=>e!==""&&R(e)!=="pet_id");return`${i}${s}?${[...a,`pet_id=${encodeURIComponent(r)}`].join("&")}${u}`}function R(e){let t=e.split("=",1)[0]??"";try{return decodeURIComponent(t.replace(/\+/g," "))}catch{return t}}function S(e,t,r){if(b(e))return e[t]!==void 0?e[t]:e[r]}function summaryPetId(e){let t=S(e,"petId","pet_id");return t===void 0?void 0:g(t)}function summaryNeedsPayment(e){return S(e,"needsPayment","needs_payment")===true}function summaryLineCount(e){return $(S(e,"lineCount","line_count"))}function summaryClinicName(e){return g(S(e,"clinicName","clinic_name"))}function summaryDiscountCode(e){return g(S(e,"discountCode","discount_code"))}function againPetId(e){return g(S(e,"petId","pet_id"))}function planTitle(e){return g(S(e,"title","title"))}function planImageUrl(e){return _(S(e,"imageUrl","image_url"))}function planResumeShipOn(e){return g(S(e,"resumeShipOn","resume_ship_on"))}function orderCardActionUrl(e){let t=S(e,"cardActionLink","card_action_link");return _(typeof t=="string"?t:S(t,"url","url"))}function receiptRefund(e){let t=$(S(e,"refundedCents","refunded_cents"));return t===null||t<=0?null:{cents:t,on:g(S(e,"refundedOn","refunded_on"))}}var v=5,k=3,w=/* @__PURE__ */Object.freeze({available:false,suggestions:/* @__PURE__ */Object.freeze([])}),O=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),P=e=>typeof e=="string"&&e.trim()!==""?e.trim():null,L=(e,t)=>typeof e=="number"&&Number.isFinite(e)&&Math.abs(e)<=t?e:null;function parseAddressSuggestions(e,t=5){if(!O(e)||e.available!==true||!Array.isArray(e.suggestions))return w;let r=[];for(let n of e.suggestions){if(r.length>=t)break;if(!O(n))continue;let e=P(n.place_id),i=P(n.main);!e||!i||r.push({placeId:e,main:i,secondary:P(n.secondary)??""})}return{available:true,suggestions:r}}function parseAddressPlace(e){if(!O(e))return null;let t=P(e.line1),r=P(e.city),n=P(e.region),i=P(e.postal_code),s=P(e.place_id),o=L(e.latitude,90),u=L(e.longitude,180);return!t||!r||!n||!i||!s||o===null||u===null?null:{line1:t,city:r,region:n.toUpperCase(),postalCode:i,country:P(e.country)??"US",location:{latitude:o,longitude:u,placeId:s}}}function addressPlaceResult(e,t){if(e===404)return{kind:"notAddress"};if(e<200||e>=300)return{kind:"unavailable"};let r=parseAddressPlace(t);return r?{kind:"ok",place:r}:{kind:"unavailable"}}exports.CARE_ADDRESS_SEARCH_MIN_CHARS=k;exports.CARE_ADDRESS_SEARCH_OFF=w;exports.CARE_ADDRESS_SUGGESTIONS_SHOWN=v;exports.CARE_CART_MAX_QUANTITY=t;exports.CARE_CART_OMS_MAX_QUANTITY=e;exports.CARE_CART_UNDRAWN=m;exports.adaptQuote=adaptQuote;exports.addLine=addLine;exports.addressLocationOf=addressLocationOf;exports.addressLocationToWire=addressLocationToWire;exports.addressPlaceResult=addressPlaceResult;exports.againPetId=againPetId;exports.careAddToast=careAddToast;exports.careFloatCopy=careFloatCopy;exports.careItemCount=careItemCount;exports.careMoney=careMoney;exports.careMoneyShort=careMoneyShort;exports.careTrayCopy=careTrayCopy;exports.cartBarSub=cartBarSub;exports.cartLineKey=cartLineKey;exports.cartSaid=C;exports.cartTotals=cartTotals;exports.createCareCartStore=createCareCartStore;exports.discountedLineKey=discountedLineKey;exports.firstAutoOrderPriceOf=firstAutoOrderPriceOf;exports.firstRxDiscountCodeOf=firstRxDiscountCodeOf;exports.lastLines=lastLines;exports.lineCents=lineCents;exports.lineMeta=lineMeta;exports.linesForPet=linesForPet;exports.needsRxId=needsRxId;exports.omsLines=omsLines;exports.omsReceipt=omsReceipt;exports.orderCardActionUrl=orderCardActionUrl;exports.parseAddressPlace=parseAddressPlace;exports.parseAddressSuggestions=parseAddressSuggestions;exports.parseCartItems=parseCartItems;exports.petQuery=petQuery;exports.planImageUrl=planImageUrl;exports.planResumeShipOn=planResumeShipOn;exports.planTitle=planTitle;exports.pronounForSex=pronounForSex;exports.receiptRefund=receiptRefund;exports.removeLines=removeLines;exports.restoreLines=restoreLines;exports.rxIdFor=rxIdFor;exports.rxLineOf=rxLineOf;exports.rxShipsToStatesOf=rxShipsToStatesOf;exports.setLinePlan=setLinePlan;exports.setLineQuantity=setLineQuantity;exports.shownLinePrices=shownLinePrices;exports.summaryClinicName=summaryClinicName;exports.summaryDiscountCode=summaryDiscountCode;exports.summaryLineCount=summaryLineCount;exports.summaryNeedsPayment=summaryNeedsPayment;exports.summaryPetId=summaryPetId;exports.swapPronoun=swapPronoun;exports.swapPronounCopy=swapPronounCopy;exports.theyVerb=theyVerb;exports.tooSoonOnOf=tooSoonOnOf;exports.unitCents=unitCents;exports.withRxIds=withRxIds;
@@ -1,3 +1,3 @@
1
1
  /*! @everfur/sdk. Copyright (c) 2026 Strand Health Inc. dba Everfur. All rights reserved. Use is subject to the Everfur SDK License: https://docs.everfur.com/license */
2
- var e=99,t=5,n=t=>{let n=t?.maxQuantity;return typeof n=="number"&&Number.isFinite(n)&&n>=1?Math.floor(n):e},r=(e,t)=>Math.max(1,Math.min(t,Math.round(e)));function cartLineKey(e){return`${e.offerId}|${e.petId??""}|${e.rxId??""}`}var i=e=>typeof e=="string"&&e!=="",u=e=>typeof e=="string"&&/^https:\/\/\S+$/i.test(e)?e:void 0,l=e=>typeof e=="string"&&e.trim()!==""&&e.length<=120;function s(e){let t=e.planWords,n=t!==null&&typeof t=="object"?t:null,r=e.cadenceDays,i=e.autoUnitPrice;return{...typeof i=="number"&&Number.isInteger(i)&&i>=0?{autoUnitPrice:i}:{},...typeof r=="number"&&Number.isInteger(r)&&r>=7&&r<=365?{cadenceDays:r}:{},...e.onePerCart===true?{onePerCart:true}:{},...l(e.meta)?{meta:e.meta}:{},...l(e.packLabel)?{packLabel:e.packLabel}:{},...l(e.planLabel)?{planLabel:e.planLabel}:{},...n&&l(n.auto)&&l(n.once)?{planWords:{auto:n.auto,once:n.once}}:{},...l(e.icon)?{icon:e.icon}:{},...l(e.tint)?{tint:e.tint}:{}}}var o=(e,t)=>!!e.rxId||t?.lockRxLines===true&&e.requiresRx;function parseCartItems(e,t){if(!e)return[];let n;try{n=JSON.parse(e)}catch{return[]}return Array.isArray(n)?a(n,t):[]}function a(t,l){let o=n(l),a=[];for(let n of t){if(!n||typeof n!="object")continue;let t=n,l=t.offerId,f=t.title,d=t.quantity;if(!i(l)||typeof f!="string"||typeof d!="number"||!Number.isFinite(d))continue;let c=t.petId,p=t.rxId,h={offerId:l,...i(c)?{petId:c}:{},...i(p)?{rxId:p}:{}},y=cartLineKey(h);if(a.some(e=>e.key===y))continue;let m=t.unitPrice,b=u(t.imageUrl),g=t.plan;a.push({...h,key:y,title:f,unitPrice:typeof m=="number"&&Number.isFinite(m)?m:null,requiresRx:t.requiresRx===true,quantity:r(d,h.rxId?e:o),...b?{imageUrl:b}:{},...g==="auto"||g==="once"?{plan:g}:{},...s(t)})}return a}function addLine(e,t,i){let l=cartLineKey({offerId:t.offerId,...t.petId?{petId:t.petId}:{},...t.rxId?{rxId:t.rxId}:{}}),a=e.find(e=>e.key===l),f=o({rxId:t.rxId,requiresRx:t.requiresRx},i)||t.onePerCart===true;if(a&&f)return{items:[...e],result:"already"};let d=e=>e??"";if(!a&&t.requiresRx&&e.some(e=>e.requiresRx&&d(e.petId)===d(t.petId)))return{items:[...e],result:"rx_limit"};let c=u(t.imageUrl),p=t.plan??a?.plan??t.defaultPlan??void 0,h={offerId:t.offerId,...t.petId?{petId:t.petId}:{},...t.rxId?{rxId:t.rxId}:{},key:l,title:t.title,unitPrice:t.unitPrice,requiresRx:t.requiresRx,quantity:a?r(a.quantity+1,n(i)):1,...c?{imageUrl:c}:{},...p?{plan:p}:{},...s(t)};return{items:a?e.map(e=>e.key===l?h:e):[...e,h],result:a?"more":"added"}}function setLineQuantity(e,t,i,u){if(i<=0)return e.filter(e=>e.key!==t);let l=n(u);return e.map(e=>e.key===t&&!o(e,u)?{...e,quantity:r(i,l)}:e)}function setLinePlan(e,t,n){return e.map(e=>e.key===t?{...e,plan:n}:e)}function removeLines(e,t){let n=new Set(t);return e.filter(e=>!n.has(e.key))}function restoreLines(e,t,n){let r=new Set(e.map(e=>e.key)),i=a(t,n).filter(e=>!r.has(e.key));return i.length>0?[...e,...i]:[...e]}function linesForPet(e,t){return t?e.filter(e=>e.petId===t):[]}function lastLines(e,t=3){return t>0?e.slice(-t):[]}function rxIdFor(e,t,n){if(!n)return null;let r=(e??[]).filter(e=>e.offerId===t&&e.petId===n);return(r.find(e=>e.status==="ready")??r[0])?.rxId??null}function withRxIds(e,t){return e.map(e=>{if(!e.requiresRx||e.rxId)return e;let n=rxIdFor(t,e.offerId,e.petId);return n?{...e,rxId:n}:e})}function rxLineOf(e,t){let n=cartLineKey(t);return e.find(e=>e.key===n)??e.find(e=>e.requiresRx&&e.offerId===t.offerId&&(e.petId??"")===(t.petId??""))??null}function needsRxId(e){return e.some(e=>e.requiresRx&&!e.rxId)}function omsLines(e,t,n){return withRxIds(e,t).map(e=>({offerId:e.offerId,quantity:e.quantity,...e.petId?{petId:e.petId}:{},...e.rxId?{rxId:e.rxId}:{},...n?.withPlan&&e.plan?{plan:e.plan}:{}}))}var f=/* @__PURE__ */Object.freeze([]);function createCareCartStore(e,t){let n=f;if(e)try{n=parseCartItems(e.read(),t)}catch{n=f}let r=/* @__PURE__ */new Set,i=t=>{n=t;try{e?.write(JSON.stringify(t))}catch{}for(let e of[...r])e()};return{items:()=>n,subscribe:e=>(r.add(e),()=>{r.delete(e)}),add:e=>{let{items:r,result:u}=addLine(n,e,t);return(u==="added"||u==="more")&&i(r),u},setQuantity:(e,r)=>i(setLineQuantity(n,e,r,t)),setPlan:(e,t)=>i(setLinePlan(n,e,t)),remove:e=>i(removeLines(n,[e])),removeKeys:e=>{let t=new Set(e);n.some(e=>t.has(e.key))&&i(removeLines(n,e))},restore:e=>{let r=restoreLines(n,e,t);r.length!==n.length&&i(r)},clear:()=>{n.length>0&&i(f)}}}var d=/* @__PURE__ */new Set(["a","about","again","an","and","as","at","back","before","but","by","down","for","from","here","if","in","into","now","off","on","or","out","over","so","than","that","the","there","through","to","too","up","when","with"]),c=/* @__PURE__ */new Set(["already","also","always","just","never","often","only","really","still","sometimes","usually"]),p=/* @__PURE__ */new Set(["been","done","gone","got","had","seen","eaten","taken","given"]),h={has:"have",is:"are",was:"were",does:"do"},y=/[A-Za-z]+(?:[’'][A-Za-z]+)?/g,m=(e,t)=>t[0]===t[0]?.toUpperCase()?(e[0]??"").toUpperCase()+e.slice(1):e;function theyVerb(e){let t=/^([A-Za-z]+)(n[’']t)?$/.exec(e);if(!t)return e;let n=t[1]??"",r=t[2]??"",i=n.toLowerCase(),u,l=h[i];if(l!==void 0)u=l;else if(/[^aeiou]ies$/.test(i))u=i.slice(0,-3)+"y";else if(/(ss|sh|ch|x|z|o)es$/.test(i))u=i.slice(0,-2);else if(/[^su]s$/.test(i))u=i.slice(0,-1);else return e;return m(u,n)+r}function swapPronoun(e,t){if(t==="her"||!/\b(?:her|hers|herself|she)\b/i.test(e))return e;let n=[...e.matchAll(y)],r=[],i=0,u=-1,l=t=>{let r=n[t],i=n[t-1];if(!r||!i)return null;let u=e.slice((i.index??0)+i[0].length,r.index);return/^\s+$/.test(u)?r:null};return n.forEach((n,s)=>{let o=n[0],a=n.index??0,f=l(s+1),h=f?f[0].toLowerCase():null,y=o.toLowerCase().replace("’","'"),b=null;if(s===u)b=theyVerb(o);else if(y==="her"){let e=h===null||d.has(h);b=t==="his"?e?"him":"his":e?"them":"their"}else if(y==="hers")b=t==="his"?"his":"theirs";else if(y==="herself")b=t==="his"?"himself":"themselves";else if(y==="she")b=t==="his"?"he":"they",t==="their"&&h!==null&&(u=c.has(h)&&l(s+2)?s+2:s+1);else if(y==="she's"){let e=o.includes("’")?"’":"'";b=t==="his"?`he${e}s`:`they${e}${h!==null&&p.has(h)?"ve":"re"}`}b!==null&&(r.push(e.slice(i,a),m(b,o)),i=a+o.length)}),r.push(e.slice(i)),r.join("")}function swapPronounCopy(e,t,n=[]){if(t==="her")return e;let r=e=>typeof e=="string"?swapPronoun(e,t):Array.isArray(e)?e.map(r):typeof e=="function"?(...t)=>r(e(...t)):e,i={};for(let[t,u]of Object.entries(e))i[t]=n.includes(t)?u:r(u);return i}function pronounForSex(e){return e==="female"?"her":e==="male"?"his":"their"}function unitCents(e,t=null){return t==="auto"&&e.plan==="auto"&&typeof e.autoUnitPrice=="number"?e.autoUnitPrice:e.unitPrice}function lineCents(e,t=null){return(unitCents(e,t)??0)*e.quantity}function cartTotals(e,t){let n=t.firstAutoOrderPrice??null,r=0,i=0,u=0,l=false;for(let t of e)t.unitPrice===null&&(l=true),t.requiresRx?r+=lineCents(t,n):i+=lineCents(t,n),u+=t.quantity;let s=r>0?Math.min(Math.max(0,t.firstRxDiscountCents??0),r):0,o=t.freeShippingThresholdCents??null;return{count:u,rxCents:r,boxCents:i,offCents:s,itemsCents:i+r-s,bigCents:i>0?i:r-s,toFreeCents:i>0&&o!==null&&i<o?o-i:0,unpriced:l}}function discountedLineKey(e,t){return t.offCents<=0?null:e.find(e=>e.requiresRx)?.key??null}function careMoney(e){return`${e<0?"-":""}$${(Math.abs(e)/100).toFixed(2)}`}function careMoneyShort(e){return e%100===0?`${e<0?"-":""}$${Math.abs(e)/100}`:careMoney(e)}function careItemCount(e){return`${e} ${e===1?"item":"items"}`}var b={shippingAtCheckout:"shipping at checkout",chargedWhenFilled:"charged when it’s filled",rxLimit:e=>`One prescription per cart. Order the one in it, then add ${e}.`};function careTrayCopy(e,t="her"){let n=e.offCents>0?swapPronoun(`${careMoney(e.itemsCents)} with ${careMoneyShort(e.offCents)} off her first prescription`,t):`${careMoney(e.itemsCents)} before tax`;return{button:`View cart · ${careItemCount(e.count)}`,fine:n}}function careFloatCopy(e,t){let n=careMoney(e.bigCents);if(e.rxCents>0&&e.boxCents>0)return{big:n,sub:`today, + ${careMoney(e.rxCents-e.offCents)} Rx when filled`,subIsOffer:false};if(e.rxCents>0)return e.offCents<=0?{big:n,sub:b.chargedWhenFilled,subIsOffer:false}:{big:n,sub:`when it’s filled, ${careMoneyShort(e.offCents)} off`,subIsOffer:true};let r=careItemCount(e.count);if(t===null)return{big:n,sub:`${r} · ${b.shippingAtCheckout}`,subIsOffer:false};let i=e.boxCents>=t;return{big:n,sub:i?`${r} · ships free`:`${r} · free shipping over ${careMoneyShort(t)}`,subIsOffer:false}}function careAddToast(e,t,n){return e==="already"?`${t} is already in the cart.`:e==="rx_limit"?b.rxLimit(t):n?`${t} refill added. The pharmacist checks it once you order.`:`${t} added to the cart.`}function cartBarSub(e,t,n="her"){let r=`${careItemCount(e.count)} · `;return e.offCents>0?swapPronoun(`${r}${careMoneyShort(e.offCents)} off her first prescription`,n):e.toFreeCents>0?`${r}${careMoney(e.toFreeCents)} to free shipping`:e.rxCents>0||e.boxCents===0?careItemCount(e.count):t===null?null:`${r}ships free`}var g={added:e=>`${e} added to the cart`,removed:e=>`${e} removed from the cart`,count:(e,t)=>`${e}: ${t} in the cart`};function shownLinePrices(e,t,n){let r=/* @__PURE__ */new Map,i=/* @__PURE__ */new Set;for(let u of e){let e=t?t.findIndex((e,t)=>!i.has(t)&&e.offerId===u.offerId&&(!e.petId||!u.petId||e.petId===u.petId)):-1,l=u.key===n.discountedKey,s=t&&e>=0?t[e]:void 0;if(s){i.add(e);let t=l?Math.max(0,Math.min(n.offCents,s.discountCents)):0;r.set(u.key,{priceCents:s.netCents+t,offCents:t})}else{let e=lineCents(u,n.firstAutoOrderPrice);r.set(u.key,{priceCents:e,offCents:l?Math.min(n.offCents,e):0})}}return r}function lineMeta(e,t){let n=e.toLowerCase(),r=[];for(let e of t){let t=e?.trim();if(!t)continue;let i=t.toLowerCase();n.includes(i)||r.some(e=>e.toLowerCase()===i)||r.push(t)}return r.join(" · ")}function I(e){/* @__PURE__ */
3
- return Object.freeze({ok:false,error:/* @__PURE__ */Object.freeze(e)})}function adaptQuote(e,t){let n=new Set(t.filter(e=>e.requiresRx).map(e=>e.offerId)),r=e=>e.isRx??e.chargedWhenFilled??n.has(e.offerId),i=e=>e.unitPrice*e.quantity,u=e=>i(e)-e.discount+e.tax,l=e.lines.map(e=>({offerId:e.offerId,petId:e.petId,quantity:e.quantity,grossCents:i(e),discountCents:e.discount,netCents:i(e)-e.discount})),s=e.lines.filter(e=>!r(e)),o=e.lines.filter(r),a=e.whenFilledDiscountCents??o.reduce((e,t)=>e+(t.whenFilledDiscountCents??0),0),f=s.reduce((e,t)=>e+u(t),0)+e.shipping,d=o.reduce((e,t)=>e+u(t),0);return{lines:l,itemsCents:l.reduce((e,t)=>e+t.netCents,0),totalCents:e.total,taxCents:e.tax,shippingCents:e.shipping,dueTodayCents:e.dueTodayCents??f,dueWhenFilledCents:e.dueWhenFilledCents??d,whenFilledDiscountCents:a,serverSplit:e.dueTodayCents!=null&&e.dueWhenFilledCents!=null,expiresAt:e.expiresAt,shipsOn:e.shipsOn??null,arrivesOn:e.arrivesOn??null}}function omsReceipt(e,t){let n=e.receipt;return typeof n!="function"?Promise.resolve(I({kind:"unavailable"})):n.call(e,t)}var C=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),x=e=>typeof e=="string"&&e.trim()!==""?e:null,$=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0?e:null,v=e=>{let t=x(e);return t!==null&&/^https:\/\/\S+$/i.test(t)?t:null},k=/^\d{4}-\d{2}-\d{2}$/;function firstAutoOrderPriceOf(e){let t=C(e)?e.first_auto_order_price:null;return t==="once"||t==="auto"?t:null}function firstRxDiscountCodeOf(e){let t=C(e)?e.first_rx_discount_code:null;return typeof t=="string"&&t.trim().length>0&&t.length<=32?t.trim():null}function rxShipsToStatesOf(e){let t=C(e)?e.rx_ships_to_states:null;if(!Array.isArray(t)||t.length===0)return null;let n=t.filter(e=>typeof e=="string"&&/^[A-Za-z]{2}$/.test(e));return n.length===t.length?n.map(e=>e.toUpperCase()):null}function tooSoonOnOf(e){if(!C(e)||e.reason_code!=="too_soon")return null;let t=e.available_on;return typeof t=="string"&&k.test(t)?t:null}function addressLocationOf(e){if(!C(e))return null;let t=e.latitude,n=e.longitude,r=x(e.place_id);return typeof t!="number"||!Number.isFinite(t)||Math.abs(t)>90||typeof n!="number"||!Number.isFinite(n)||Math.abs(n)>180||r===null?null:{latitude:t,longitude:n,placeId:r}}function addressLocationToWire(e){return{latitude:e.latitude,longitude:e.longitude,place_id:e.placeId}}function petQuery(e,t,n){if(!n||t.toUpperCase()!=="GET")return e;let r="https://oms.invalid",i;try{i=new URL(e,r)}catch{return e}let u=i.pathname.replace(/\/+$/,"");return!u.endsWith("/orders")&&!u.endsWith("/buy-again")?e:(i.searchParams.set("pet_id",n),i.origin===r&&!e.startsWith(r)?`${i.pathname}${i.search}`:i.href)}function w(e,t,n){if(C(e))return e[t]!==void 0?e[t]:e[n]}function summaryPetId(e){let t=w(e,"petId","pet_id");return t===void 0?void 0:x(t)}function summaryNeedsPayment(e){return w(e,"needsPayment","needs_payment")===true}function summaryLineCount(e){return $(w(e,"lineCount","line_count"))}function summaryClinicName(e){return x(w(e,"clinicName","clinic_name"))}function summaryDiscountCode(e){return x(w(e,"discountCode","discount_code"))}function againPetId(e){return x(w(e,"petId","pet_id"))}function planTitle(e){return x(w(e,"title","title"))}function planImageUrl(e){return v(w(e,"imageUrl","image_url"))}function planResumeShipOn(e){return x(w(e,"resumeShipOn","resume_ship_on"))}function orderCardActionUrl(e){let t=w(e,"cardActionLink","card_action_link");return v(typeof t=="string"?t:w(t,"url","url"))}function receiptRefund(e){let t=$(w(e,"refundedCents","refunded_cents"));return t===null||t<=0?null:{cents:t,on:x(w(e,"refundedOn","refunded_on"))}}var _=5,q=3,A=/* @__PURE__ */Object.freeze({available:false,suggestions:/* @__PURE__ */Object.freeze([])}),O=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),P=e=>typeof e=="string"&&e.trim()!==""?e.trim():null,R=(e,t)=>typeof e=="number"&&Number.isFinite(e)&&Math.abs(e)<=t?e:null;function parseAddressSuggestions(e,t=5){if(!O(e)||e.available!==true||!Array.isArray(e.suggestions))return A;let n=[];for(let r of e.suggestions){if(n.length>=t)break;if(!O(r))continue;let e=P(r.place_id),i=P(r.main);!e||!i||n.push({placeId:e,main:i,secondary:P(r.secondary)??""})}return{available:true,suggestions:n}}function parseAddressPlace(e){if(!O(e))return null;let t=P(e.line1),n=P(e.city),r=P(e.region),i=P(e.postal_code),u=P(e.place_id),l=R(e.latitude,90),s=R(e.longitude,180);return!t||!n||!r||!i||!u||l===null||s===null?null:{line1:t,city:n,region:r.toUpperCase(),postalCode:i,country:P(e.country)??"US",location:{latitude:l,longitude:s,placeId:u}}}function addressPlaceResult(e,t){if(e===404)return{kind:"notAddress"};if(e<200||e>=300)return{kind:"unavailable"};let n=parseAddressPlace(t);return n?{kind:"ok",place:n}:{kind:"unavailable"}}export{q as CARE_ADDRESS_SEARCH_MIN_CHARS,A as CARE_ADDRESS_SEARCH_OFF,_ as CARE_ADDRESS_SUGGESTIONS_SHOWN,t as CARE_CART_MAX_QUANTITY,e as CARE_CART_OMS_MAX_QUANTITY,b as CARE_CART_UNDRAWN,adaptQuote,addLine,addressLocationOf,addressLocationToWire,addressPlaceResult,againPetId,careAddToast,careFloatCopy,careItemCount,careMoney,careMoneyShort,careTrayCopy,cartBarSub,cartLineKey,g as cartSaid,cartTotals,createCareCartStore,discountedLineKey,firstAutoOrderPriceOf,firstRxDiscountCodeOf,lastLines,lineCents,lineMeta,linesForPet,needsRxId,omsLines,omsReceipt,orderCardActionUrl,parseAddressPlace,parseAddressSuggestions,parseCartItems,petQuery,planImageUrl,planResumeShipOn,planTitle,pronounForSex,receiptRefund,removeLines,restoreLines,rxIdFor,rxLineOf,rxShipsToStatesOf,setLinePlan,setLineQuantity,shownLinePrices,summaryClinicName,summaryDiscountCode,summaryLineCount,summaryNeedsPayment,summaryPetId,swapPronoun,swapPronounCopy,theyVerb,tooSoonOnOf,unitCents,withRxIds};
2
+ var e=99,t=5,n=t=>{let n=t?.maxQuantity;return typeof n=="number"&&Number.isFinite(n)&&n>=1?Math.floor(n):e},r=(e,t)=>Math.max(1,Math.min(t,Math.round(e)));function cartLineKey(e){return`${e.offerId}|${e.petId??""}|${e.rxId??""}`}var i=e=>typeof e=="string"&&e!=="",u=e=>typeof e=="string"&&/^https:\/\/\S+$/i.test(e)?e:void 0,l=e=>typeof e=="string"&&e.trim()!==""&&e.length<=120;function o(e){let t=e.planWords,n=t!==null&&typeof t=="object"?t:null,r=e.cadenceDays,i=e.autoUnitPrice;return{...typeof i=="number"&&Number.isInteger(i)&&i>=0?{autoUnitPrice:i}:{},...typeof r=="number"&&Number.isInteger(r)&&r>=7&&r<=365?{cadenceDays:r}:{},...e.onePerCart===true?{onePerCart:true}:{},...l(e.meta)?{meta:e.meta}:{},...l(e.packLabel)?{packLabel:e.packLabel}:{},...l(e.planLabel)?{planLabel:e.planLabel}:{},...n&&l(n.auto)&&l(n.once)?{planWords:{auto:n.auto,once:n.once}}:{},...l(e.icon)?{icon:e.icon}:{},...l(e.tint)?{tint:e.tint}:{}}}var s=(e,t)=>!!e.rxId||t?.lockRxLines===true&&e.requiresRx;function parseCartItems(e,t){if(!e)return[];let n;try{n=JSON.parse(e)}catch{return[]}return Array.isArray(n)?a(n,t):[]}function a(t,l){let s=n(l),a=[];for(let n of t){if(!n||typeof n!="object")continue;let t=n,l=t.offerId,f=t.title,d=t.quantity;if(!i(l)||typeof f!="string"||typeof d!="number"||!Number.isFinite(d))continue;let c=t.petId,p=t.rxId,h={offerId:l,...i(c)?{petId:c}:{},...i(p)?{rxId:p}:{}},y=cartLineKey(h);if(a.some(e=>e.key===y))continue;let m=t.unitPrice,b=u(t.imageUrl),I=t.plan;a.push({...h,key:y,title:f,unitPrice:typeof m=="number"&&Number.isFinite(m)?m:null,requiresRx:t.requiresRx===true,quantity:r(d,h.rxId?e:s),...b?{imageUrl:b}:{},...I==="auto"||I==="once"?{plan:I}:{},...o(t)})}return a}function addLine(e,t,i){let l=cartLineKey({offerId:t.offerId,...t.petId?{petId:t.petId}:{},...t.rxId?{rxId:t.rxId}:{}}),a=e.find(e=>e.key===l),f=s({rxId:t.rxId,requiresRx:t.requiresRx},i)||t.onePerCart===true;if(a&&f)return{items:[...e],result:"already"};let d=e=>e??"";if(!a&&t.requiresRx&&e.some(e=>e.requiresRx&&d(e.petId)===d(t.petId)))return{items:[...e],result:"rx_limit"};let c=u(t.imageUrl),p=t.plan??a?.plan??t.defaultPlan??void 0,h={offerId:t.offerId,...t.petId?{petId:t.petId}:{},...t.rxId?{rxId:t.rxId}:{},key:l,title:t.title,unitPrice:t.unitPrice,requiresRx:t.requiresRx,quantity:a?r(a.quantity+1,n(i)):1,...c?{imageUrl:c}:{},...p?{plan:p}:{},...o(t)};return{items:a?e.map(e=>e.key===l?h:e):[...e,h],result:a?"more":"added"}}function setLineQuantity(e,t,i,u){if(i<=0)return e.filter(e=>e.key!==t);let l=n(u);return e.map(e=>e.key===t&&!s(e,u)?{...e,quantity:r(i,l)}:e)}function setLinePlan(e,t,n){return e.map(e=>e.key===t?{...e,plan:n}:e)}function removeLines(e,t){let n=new Set(t);return e.filter(e=>!n.has(e.key))}function restoreLines(e,t,n){let r=new Set(e.map(e=>e.key)),i=a(t,n).filter(e=>!r.has(e.key));return i.length>0?[...e,...i]:[...e]}function linesForPet(e,t){return t?e.filter(e=>e.petId===t):[]}function lastLines(e,t=3){return t>0?e.slice(-t):[]}function rxIdFor(e,t,n){if(!n)return null;let r=(e??[]).filter(e=>e.offerId===t&&e.petId===n);return(r.find(e=>e.status==="ready")??r[0])?.rxId??null}function withRxIds(e,t){return e.map(e=>{if(!e.requiresRx||e.rxId)return e;let n=rxIdFor(t,e.offerId,e.petId);return n?{...e,rxId:n}:e})}function rxLineOf(e,t){let n=cartLineKey(t);return e.find(e=>e.key===n)??e.find(e=>e.requiresRx&&e.offerId===t.offerId&&(e.petId??"")===(t.petId??""))??null}function needsRxId(e){return e.some(e=>e.requiresRx&&!e.rxId)}function omsLines(e,t,n){return withRxIds(e,t).map(e=>({offerId:e.offerId,quantity:e.quantity,...e.petId?{petId:e.petId}:{},...e.rxId?{rxId:e.rxId}:{},...n?.withPlan&&e.plan?{plan:e.plan}:{}}))}var f=/* @__PURE__ */Object.freeze([]);function createCareCartStore(e,t){let n=f;if(e)try{n=parseCartItems(e.read(),t)}catch{n=f}let r=/* @__PURE__ */new Set,i=t=>{n=t;try{e?.write(JSON.stringify(t))}catch{}for(let e of[...r])e()};return{items:()=>n,subscribe:e=>(r.add(e),()=>{r.delete(e)}),add:e=>{let{items:r,result:u}=addLine(n,e,t);return(u==="added"||u==="more")&&i(r),u},setQuantity:(e,r)=>i(setLineQuantity(n,e,r,t)),setPlan:(e,t)=>i(setLinePlan(n,e,t)),remove:e=>i(removeLines(n,[e])),removeKeys:e=>{let t=new Set(e);n.some(e=>t.has(e.key))&&i(removeLines(n,e))},restore:e=>{let r=restoreLines(n,e,t);r.length!==n.length&&i(r)},clear:()=>{n.length>0&&i(f)}}}var d=/* @__PURE__ */new Set(["a","about","again","an","and","as","at","back","before","but","by","down","for","from","here","if","in","into","now","off","on","or","out","over","so","than","that","the","there","through","to","too","up","when","with"]),c=/* @__PURE__ */new Set(["already","also","always","just","never","often","only","really","still","sometimes","usually"]),p=/* @__PURE__ */new Set(["been","done","gone","got","had","seen","eaten","taken","given"]),h={has:"have",is:"are",was:"were",does:"do"},y=/[A-Za-z]+(?:[’'][A-Za-z]+)?/g,m=(e,t)=>t[0]===t[0]?.toUpperCase()?(e[0]??"").toUpperCase()+e.slice(1):e;function theyVerb(e){let t=/^([A-Za-z]+)(n[’']t)?$/.exec(e);if(!t)return e;let n=t[1]??"",r=t[2]??"",i=n.toLowerCase(),u,l=h[i];if(l!==void 0)u=l;else if(/[^aeiou]ies$/.test(i))u=i.slice(0,-3)+"y";else if(/(ss|sh|ch|x|z|o)es$/.test(i))u=i.slice(0,-2);else if(/[^su]s$/.test(i))u=i.slice(0,-1);else return e;return m(u,n)+r}function swapPronoun(e,t){if(t==="her"||!/\b(?:her|hers|herself|she)\b/i.test(e))return e;let n=[...e.matchAll(y)],r=[],i=0,u=-1,l=t=>{let r=n[t],i=n[t-1];if(!r||!i)return null;let u=e.slice((i.index??0)+i[0].length,r.index);return/^\s+$/.test(u)?r:null};return n.forEach((n,o)=>{let s=n[0],a=n.index??0,f=l(o+1),h=f?f[0].toLowerCase():null,y=s.toLowerCase().replace("’","'"),b=null;if(o===u)b=theyVerb(s);else if(y==="her"){let e=h===null||d.has(h);b=t==="his"?e?"him":"his":e?"them":"their"}else if(y==="hers")b=t==="his"?"his":"theirs";else if(y==="herself")b=t==="his"?"himself":"themselves";else if(y==="she")b=t==="his"?"he":"they",t==="their"&&h!==null&&(u=c.has(h)&&l(o+2)?o+2:o+1);else if(y==="she's"){let e=s.includes("’")?"’":"'";b=t==="his"?`he${e}s`:`they${e}${h!==null&&p.has(h)?"ve":"re"}`}b!==null&&(r.push(e.slice(i,a),m(b,s)),i=a+s.length)}),r.push(e.slice(i)),r.join("")}function swapPronounCopy(e,t,n=[]){if(t==="her")return e;let r=e=>typeof e=="string"?swapPronoun(e,t):Array.isArray(e)?e.map(r):typeof e=="function"?(...t)=>r(e(...t)):e,i={};for(let[t,u]of Object.entries(e))i[t]=n.includes(t)?u:r(u);return i}function pronounForSex(e){return e==="female"?"her":e==="male"?"his":"their"}function unitCents(e,t=null){return t==="auto"&&e.plan==="auto"&&typeof e.autoUnitPrice=="number"?e.autoUnitPrice:e.unitPrice}function lineCents(e,t=null){return(unitCents(e,t)??0)*e.quantity}function cartTotals(e,t){let n=t.firstAutoOrderPrice??null,r=0,i=0,u=0,l=false;for(let t of e)t.unitPrice===null&&(l=true),t.requiresRx?r+=lineCents(t,n):i+=lineCents(t,n),u+=t.quantity;let o=r>0?Math.min(Math.max(0,t.firstRxDiscountCents??0),r):0,s=t.freeShippingThresholdCents??null;return{count:u,rxCents:r,boxCents:i,offCents:o,itemsCents:i+r-o,bigCents:i>0?i:r-o,toFreeCents:i>0&&s!==null&&i<s?s-i:0,unpriced:l}}function discountedLineKey(e,t){return t.offCents<=0?null:e.find(e=>e.requiresRx)?.key??null}function careMoney(e){return`${e<0?"-":""}$${(Math.abs(e)/100).toFixed(2)}`}function careMoneyShort(e){return e%100===0?`${e<0?"-":""}$${Math.abs(e)/100}`:careMoney(e)}function careItemCount(e){return`${e} ${e===1?"item":"items"}`}var b={shippingAtCheckout:"shipping at checkout",chargedWhenFilled:"charged when it’s filled",rxLimit:e=>`One prescription per cart. Order the one in it, then add ${e}.`};function careTrayCopy(e,t="her"){let n=e.offCents>0?swapPronoun(`${careMoney(e.itemsCents)} with ${careMoneyShort(e.offCents)} off her first prescription`,t):`${careMoney(e.itemsCents)} before tax`;return{button:`View cart · ${careItemCount(e.count)}`,fine:n}}function careFloatCopy(e,t){let n=careMoney(e.bigCents);if(e.rxCents>0&&e.boxCents>0)return{big:n,sub:`today, + ${careMoney(e.rxCents-e.offCents)} Rx when filled`,subIsOffer:false};if(e.rxCents>0)return e.offCents<=0?{big:n,sub:b.chargedWhenFilled,subIsOffer:false}:{big:n,sub:`when it’s filled, ${careMoneyShort(e.offCents)} off`,subIsOffer:true};let r=careItemCount(e.count);if(t===null)return{big:n,sub:`${r} · ${b.shippingAtCheckout}`,subIsOffer:false};let i=e.boxCents>=t;return{big:n,sub:i?`${r} · ships free`:`${r} · free shipping over ${careMoneyShort(t)}`,subIsOffer:false}}function careAddToast(e,t,n){return e==="already"?`${t} is already in the cart.`:e==="rx_limit"?b.rxLimit(t):n?`${t} refill added. The pharmacist checks it once you order.`:`${t} added to the cart.`}function cartBarSub(e,t,n="her"){let r=`${careItemCount(e.count)} · `;return e.offCents>0?swapPronoun(`${r}${careMoneyShort(e.offCents)} off her first prescription`,n):e.toFreeCents>0?`${r}${careMoney(e.toFreeCents)} to free shipping`:e.rxCents>0||e.boxCents===0?careItemCount(e.count):t===null?null:`${r}ships free`}var I={added:e=>`${e} added to the cart`,removed:e=>`${e} removed from the cart`,count:(e,t)=>`${e}: ${t} in the cart`};function shownLinePrices(e,t,n){let r=/* @__PURE__ */new Map,i=/* @__PURE__ */new Set;for(let u of e){let e=t?t.findIndex((e,t)=>!i.has(t)&&e.offerId===u.offerId&&(!e.petId||!u.petId||e.petId===u.petId)):-1,l=u.key===n.discountedKey,o=t&&e>=0?t[e]:void 0;if(o){i.add(e);let t=l?Math.max(0,Math.min(n.offCents,o.discountCents)):0;r.set(u.key,{priceCents:o.netCents+t,offCents:t})}else{let e=lineCents(u,n.firstAutoOrderPrice);r.set(u.key,{priceCents:e,offCents:l?Math.min(n.offCents,e):0})}}return r}function lineMeta(e,t){let n=e.toLowerCase(),r=[];for(let e of t){let t=e?.trim();if(!t)continue;let i=t.toLowerCase();n.includes(i)||r.some(e=>e.toLowerCase()===i)||r.push(t)}return r.join(" · ")}function g(e){/* @__PURE__ */
3
+ return Object.freeze({ok:false,error:/* @__PURE__ */Object.freeze(e)})}function adaptQuote(e,t){let n=new Set(t.filter(e=>e.requiresRx).map(e=>e.offerId)),r=e=>e.isRx??e.chargedWhenFilled??n.has(e.offerId),i=e=>e.unitPrice*e.quantity,u=e=>i(e)-e.discount+e.tax,l=e.lines.map(e=>({offerId:e.offerId,petId:e.petId,quantity:e.quantity,grossCents:i(e),discountCents:e.discount,netCents:i(e)-e.discount})),o=e.lines.filter(e=>!r(e)),s=e.lines.filter(r),a=e.whenFilledDiscountCents??s.reduce((e,t)=>e+(t.whenFilledDiscountCents??0),0),f=o.reduce((e,t)=>e+u(t),0)+e.shipping,d=s.reduce((e,t)=>e+u(t),0);return{lines:l,itemsCents:l.reduce((e,t)=>e+t.netCents,0),totalCents:e.total,taxCents:e.tax,shippingCents:e.shipping,dueTodayCents:e.dueTodayCents??f,dueWhenFilledCents:e.dueWhenFilledCents??d,whenFilledDiscountCents:a,serverSplit:e.dueTodayCents!=null&&e.dueWhenFilledCents!=null,expiresAt:e.expiresAt,shipsOn:e.shipsOn??null,arrivesOn:e.arrivesOn??null}}function omsReceipt(e,t){let n=e.receipt;return typeof n!="function"?Promise.resolve(g({kind:"unavailable"})):n.call(e,t)}var C=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),x=e=>typeof e=="string"&&e.trim()!==""?e:null,$=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0?e:null,v=e=>{let t=x(e);return t!==null&&/^https:\/\/\S+$/i.test(t)?t:null},k=/^\d{4}-\d{2}-\d{2}$/;function firstAutoOrderPriceOf(e){let t=C(e)?e.first_auto_order_price:null;return t==="once"||t==="auto"?t:null}function firstRxDiscountCodeOf(e){let t=C(e)?e.first_rx_discount_code:null;return typeof t=="string"&&t.trim().length>0&&t.length<=32?t.trim():null}function rxShipsToStatesOf(e){let t=C(e)?e.rx_ships_to_states:null;if(!Array.isArray(t)||t.length===0)return null;let n=t.filter(e=>typeof e=="string"&&/^[A-Za-z]{2}$/.test(e));return n.length===t.length?n.map(e=>e.toUpperCase()):null}function tooSoonOnOf(e){if(!C(e)||e.reason_code!=="too_soon")return null;let t=e.available_on;return typeof t=="string"&&k.test(t)?t:null}function addressLocationOf(e){if(!C(e))return null;let t=e.latitude,n=e.longitude,r=x(e.place_id);return typeof t!="number"||!Number.isFinite(t)||Math.abs(t)>90||typeof n!="number"||!Number.isFinite(n)||Math.abs(n)>180||r===null?null:{latitude:t,longitude:n,placeId:r}}function addressLocationToWire(e){return{latitude:e.latitude,longitude:e.longitude,place_id:e.placeId}}function petQuery(e,t,n){if(!n||t.toUpperCase()!=="GET")return e;let r=/^([a-z][a-z0-9+.-]*:\/\/[^/?#]*)?([^?#]*)(\?[^#]*)?(#.*)?$/i.exec(e);if(r===null)return e;let[,i="",u="",l="",o=""]=r,s=u.replace(/\/+$/,"");if(!s.endsWith("/orders")&&!s.endsWith("/buy-again"))return e;let a=l.replace(/^\?/,"").split("&").filter(e=>e!==""&&_(e)!=="pet_id");return`${i}${u}?${[...a,`pet_id=${encodeURIComponent(n)}`].join("&")}${o}`}function _(e){let t=e.split("=",1)[0]??"";try{return decodeURIComponent(t.replace(/\+/g," "))}catch{return t}}function w(e,t,n){if(C(e))return e[t]!==void 0?e[t]:e[n]}function summaryPetId(e){let t=w(e,"petId","pet_id");return t===void 0?void 0:x(t)}function summaryNeedsPayment(e){return w(e,"needsPayment","needs_payment")===true}function summaryLineCount(e){return $(w(e,"lineCount","line_count"))}function summaryClinicName(e){return x(w(e,"clinicName","clinic_name"))}function summaryDiscountCode(e){return x(w(e,"discountCode","discount_code"))}function againPetId(e){return x(w(e,"petId","pet_id"))}function planTitle(e){return x(w(e,"title","title"))}function planImageUrl(e){return v(w(e,"imageUrl","image_url"))}function planResumeShipOn(e){return x(w(e,"resumeShipOn","resume_ship_on"))}function orderCardActionUrl(e){let t=w(e,"cardActionLink","card_action_link");return v(typeof t=="string"?t:w(t,"url","url"))}function receiptRefund(e){let t=$(w(e,"refundedCents","refunded_cents"));return t===null||t<=0?null:{cents:t,on:x(w(e,"refundedOn","refunded_on"))}}var q=5,A=3,O=/* @__PURE__ */Object.freeze({available:false,suggestions:/* @__PURE__ */Object.freeze([])}),P=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),R=e=>typeof e=="string"&&e.trim()!==""?e.trim():null,F=(e,t)=>typeof e=="number"&&Number.isFinite(e)&&Math.abs(e)<=t?e:null;function parseAddressSuggestions(e,t=5){if(!P(e)||e.available!==true||!Array.isArray(e.suggestions))return O;let n=[];for(let r of e.suggestions){if(n.length>=t)break;if(!P(r))continue;let e=R(r.place_id),i=R(r.main);!e||!i||n.push({placeId:e,main:i,secondary:R(r.secondary)??""})}return{available:true,suggestions:n}}function parseAddressPlace(e){if(!P(e))return null;let t=R(e.line1),n=R(e.city),r=R(e.region),i=R(e.postal_code),u=R(e.place_id),l=F(e.latitude,90),o=F(e.longitude,180);return!t||!n||!r||!i||!u||l===null||o===null?null:{line1:t,city:n,region:r.toUpperCase(),postalCode:i,country:R(e.country)??"US",location:{latitude:l,longitude:o,placeId:u}}}function addressPlaceResult(e,t){if(e===404)return{kind:"notAddress"};if(e<200||e>=300)return{kind:"unavailable"};let n=parseAddressPlace(t);return n?{kind:"ok",place:n}:{kind:"unavailable"}}export{A as CARE_ADDRESS_SEARCH_MIN_CHARS,O as CARE_ADDRESS_SEARCH_OFF,q as CARE_ADDRESS_SUGGESTIONS_SHOWN,t as CARE_CART_MAX_QUANTITY,e as CARE_CART_OMS_MAX_QUANTITY,b as CARE_CART_UNDRAWN,adaptQuote,addLine,addressLocationOf,addressLocationToWire,addressPlaceResult,againPetId,careAddToast,careFloatCopy,careItemCount,careMoney,careMoneyShort,careTrayCopy,cartBarSub,cartLineKey,I as cartSaid,cartTotals,createCareCartStore,discountedLineKey,firstAutoOrderPriceOf,firstRxDiscountCodeOf,lastLines,lineCents,lineMeta,linesForPet,needsRxId,omsLines,omsReceipt,orderCardActionUrl,parseAddressPlace,parseAddressSuggestions,parseCartItems,petQuery,planImageUrl,planResumeShipOn,planTitle,pronounForSex,receiptRefund,removeLines,restoreLines,rxIdFor,rxLineOf,rxShipsToStatesOf,setLinePlan,setLineQuantity,shownLinePrices,summaryClinicName,summaryDiscountCode,summaryLineCount,summaryNeedsPayment,summaryPetId,swapPronoun,swapPronounCopy,theyVerb,tooSoonOnOf,unitCents,withRxIds};