@getspot/spot-widget 1.3.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +375 -5
- package/dist/__mocks__/ui.d.ts +12 -0
- package/dist/__mocks__/ui.d.ts.map +1 -0
- package/dist/api.d.ts +26 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/briefcase.svg +1 -0
- package/dist/building.svg +1 -0
- package/dist/cross.svg +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.es.js +433 -340
- package/dist/index.umd.js +3 -3
- package/dist/medal.svg +1 -0
- package/dist/plane.svg +1 -0
- package/dist/scale.svg +1 -0
- package/dist/types.d.ts +144 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/ui.d.ts +11 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/umbrella.svg +1 -0
- package/dist/users.svg +1 -0
- package/dist/validateOptions.d.ts +3 -0
- package/dist/validateOptions.d.ts.map +1 -0
- package/package.json +22 -3
- package/.turbo/turbo-build.log +0 -13
- package/src/api.js +0 -154
- package/src/index.js +0 -366
- package/src/styles.css +0 -411
- package/src/ui.js +0 -209
- package/src/validateOptions.js +0 -253
- package/vite.config.js +0 -17
package/dist/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
(function(_
|
|
1
|
+
(function(v,_){typeof exports=="object"&&typeof module<"u"?module.exports=_():typeof define=="function"&&define.amd?define(_):(v=typeof globalThis<"u"?globalThis:v||self,v.SpotWidget=_())})(this,function(){"use strict";var v=typeof document<"u"?document.currentScript:null;async function _(u,t,e){try{const r=await fetch(u,{method:"POST",headers:{"Content-Type":"application/json","X-Spot-Partner-Id":t},body:JSON.stringify(e)}),n=await r.json();if(!r.ok){const o=new Error((n==null?void 0:n.message)||"Failed to fetch quote");throw o.status=r.status,o.responseBody=n,o}return n}catch(r){throw r instanceof Error?r:new Error("Unknown error occurred while fetching quote")}}async function O(u,t,e){try{const r=u.replace("/quote","/quote/batch"),n=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json","X-Spot-Partner-Id":t},body:JSON.stringify(e)}),o=await n.json();if(!n.ok){const p=new Error((o==null?void 0:o.message)||"Failed to fetch batch quote");throw p.status=n.status,p.responseBody=o,p}return o}catch(r){throw r instanceof Error?r:new Error("Unknown error occurred while fetching batch quote")}}async function I(u,t,e){var r;try{const n={cartId:e.cartInfo.cartId,cartName:e.cartInfo.cartName,currencyCode:e.cartInfo.currencyCode,items:e.items.map((c,f)=>({cartItemId:c.cartItemId||`item-${f+1}`,productPrice:c.productPrice,productType:c.productType,productDuration:c.productDuration,productId:c.productId,productName:c.productName,participantDescription:c.participantDescription,eventType:c.eventType,startDate:c.startDate,endDate:c.endDate}))},o=await O(u,t,n);if(o.status!=="QUOTES_AVAILABLE"&&o.status!=="QUOTE_AVAILABLE")return{status:"NO_MATCHING_QUOTE"};const p=o.quotes.map(c=>{const f=e.items.find((b,m)=>(b.cartItemId||`item-${m+1}`)===c.cartItemId);return f?f.participantDescription?`${f.productName} - ${f.participantDescription}`:f.productName:`Item ${c.id}`}),s=Math.round((o.totalSpotPrice||o.spotPrice||0)*100)/100;return{status:"QUOTE_AVAILABLE",data:{id:o.quotes?o.quotes.map(c=>c.id).join(","):((r=o.data)==null?void 0:r.id)||"",spotPrice:s,currencyCode:o.currencyCode||"",communication:{...o.communication,yesOptionText:o.communication.yesOptionText.replace(String(o.totalSpotPrice),String(s))},payoutSchedule:o.payoutSchedule.map(c=>({...c,amount:c.amount!==void 0?c.amount:0})),coveredItems:p,originalQuotes:o.quotes||(o.data?[o.data]:[])},spotPrice:s,coveredItems:p}}catch(n){throw n instanceof Error?n:new Error("Unknown error occurred while fetching multiple quotes")}}const P={sandbox:"https://api.sandbox.getspot.com/v1/quote",production:"https://api.getspot.com/v1/quote",local:"http://localhost:3999/api/v1/quote"};function D(u){const{apiConfig:t={},quoteRequestData:e,callbacks:r={},location:n,theme:o}=u,{environment:p="sandbox",partnerId:s,customEndpoint:c}=t;if(!s||typeof s!="string")throw new Error("Invalid or missing partnerId in apiConfig");if(!(c||P[p]))throw new Error(`Invalid environment in apiConfig: ${p}`);if(!e||typeof e!="object"&&!Array.isArray(e))throw new Error("quoteRequestData must be a non-null object or array");const b=["startDate","endDate","currencyCode","eventType","productType","productDuration","productPrice","productId","cartId","productName"];function m(a,d=null){const l=d!==null?`quoteRequestData[${d}]`:"quoteRequestData";b.forEach(y=>{if(!Object.prototype.hasOwnProperty.call(a,y)||a[y]===void 0||a[y]===null)throw new Error(`Missing required ${l} field: '${y}'`)});const w=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;if(!w.test(a.startDate))throw new Error(`${l}.startDate must be a valid ISO8601 string`);if(!w.test(a.endDate))throw new Error(`${l}.endDate must be a valid ISO8601 string`);if(typeof a.currencyCode!="string")throw new Error(`${l}.currencyCode must be a string`);if(!["USD","CAD","AUD"].includes(a.currencyCode))throw new Error(`Invalid ${l}.currencyCode: ${a.currencyCode}`);if(typeof a.eventType!="string")throw new Error(`${l}.eventType must be a string`);if(typeof a.productType!="string")throw new Error(`${l}.productType must be a string`);const h=["Pass","Trip","Registration"];if(!h.includes(a.productType))throw new Error(`${l}.productType must be one of ${h.join(", ")}`);if(typeof a.productDuration!="string")throw new Error(`${l}.productDuration must be a string`);const C=["Daily","Seasonal","Trip","Event"];if(!C.includes(a.productDuration))throw new Error(`${l}.productDuration must be one of ${C.join(", ")}`);if(typeof a.productPrice!="number"||isNaN(a.productPrice))throw new Error(`${l}.productPrice must be a valid number`);if(typeof a.productId!="string")throw new Error(`${l}.productId must be a string`);if(typeof a.cartId!="string")throw new Error(`${l}.cartId must be a string`);if(typeof a.productName!="string")throw new Error(`${l}.productName must be a string`)}if("cartInfo"in e&&"items"in e){const a=e,{cartInfo:d,items:l}=a;if(!d||typeof d!="object")throw new Error("quoteRequestData.cartInfo must be a non-null object");if(!d.cartId||typeof d.cartId!="string")throw new Error("quoteRequestData.cartInfo.cartId must be a string");if(!d.cartName||typeof d.cartName!="string")throw new Error("quoteRequestData.cartInfo.cartName must be a string");if(!d.currencyCode||typeof d.currencyCode!="string")throw new Error("quoteRequestData.cartInfo.currencyCode must be a string");if(!["USD","CAD","AUD"].includes(d.currencyCode))throw new Error(`Invalid quoteRequestData.cartInfo.currencyCode: ${d.currencyCode}`);if(!Array.isArray(l)||l.length===0)throw new Error("quoteRequestData.items must be a non-empty array");const q=["startDate","endDate","eventType","productType","productDuration","productPrice","productId","productName"];l.forEach((h,C)=>{if(!h||typeof h!="object")throw new Error(`quoteRequestData.items[${C}] must be a non-null object`);const y=`quoteRequestData.items[${C}]`;q.forEach(E=>{if(!Object.prototype.hasOwnProperty.call(h,E)||h[E]===void 0||h[E]===null)throw new Error(`Missing required ${y} field: '${E}'`)});const T=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;if(!T.test(h.startDate))throw new Error(`${y}.startDate must be a valid ISO8601 string`);if(!T.test(h.endDate))throw new Error(`${y}.endDate must be a valid ISO8601 string`);if(typeof h.eventType!="string")throw new Error(`${y}.eventType must be a string`);if(typeof h.productType!="string")throw new Error(`${y}.productType must be a string`);const x=["Pass","Trip","Registration"];if(!x.includes(h.productType))throw new Error(`${y}.productType must be one of ${x.join(", ")}`);if(typeof h.productDuration!="string")throw new Error(`${y}.productDuration must be a string`);const N=["Daily","Seasonal","Trip","Event"];if(!N.includes(h.productDuration))throw new Error(`${y}.productDuration must be one of ${N.join(", ")}`);if(typeof h.productPrice!="number"||isNaN(h.productPrice))throw new Error(`${y}.productPrice must be a valid number`);if(typeof h.productId!="string")throw new Error(`${y}.productId must be a string`);if(typeof h.productName!="string")throw new Error(`${y}.productName must be a string`)})}else if(Array.isArray(e)){if(e.length===0)throw new Error("quoteRequestData array cannot be empty");e.forEach((a,d)=>{if(!a||typeof a!="object")throw new Error(`quoteRequestData[${d}] must be a non-null object`);m(a,d)})}else m(e);if(["onOptIn","onOptOut","onQuoteRetrieved","onError","noMatchingQuote"].forEach(a=>{const d=r[a];if(d&&typeof d!="function")throw new Error(`Callback '${a}' must be a function.`)}),typeof n=="string"&&!document.querySelector(n))throw new Error(`Invalid location selector: '${n}'`);if(o&&typeof o!="object")throw new Error("Theme must be an object with CSS variables, do not include the '--' prefix")}function i(u,{text:t,className:e,parent:r,innerHTML:n,href:o,target:p}={}){const s=document.createElement(u);return e&&(s.className=e),t!=null&&(s.textContent=t),n!=null&&(s.innerHTML=n),o&&"href"in s&&(s.href=o),p&&"target"in s&&(s.target=p),r&&r.appendChild(s),s}function R(u,{name:t,description:e}){i("div",{className:"spot-header__title",text:t,parent:u}),i("div",{className:"spot-header__description",text:e,parent:u})}function S(u,t=[]){const e=i("ul",{className:"spot-benefits__list",parent:u});t.forEach(r=>{const n=i("li",{parent:e});n.innerHTML=`
|
|
2
2
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none">
|
|
3
3
|
<path d="M11.6666 3.5L5.24998 9.91667L2.33331 7"
|
|
4
4
|
stroke="#2E2E2E" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
5
|
-
</svg>`,
|
|
5
|
+
</svg>`,i("span",{text:r,parent:n})})}function $(u,t=[]){if(!t||t.length===0)return;const e=i("div",{className:"spot-qualifying-reasons__container",parent:u}),r=[...t].sort((c,f)=>c.rank-f.rank),n=i("div",{className:"spot-qualifying-reasons__grid",parent:e}),o={"Accident & Illness":"cross.svg","Family Emergencies":"users.svg",Layoffs:"building.svg","Jury Duty":"scale.svg","Work Travel Conflict":"briefcase.svg","Severe Weather":"umbrella.svg","Travel Interruption":"plane.svg","Military Duty":"medal.svg"},p=new URL(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:v&&v.tagName.toUpperCase()==="SCRIPT"&&v.src||new URL("index.umd.js",document.baseURI).href),s=p.origin+p.pathname.replace(/\/src\/[^/]*$/,"/assets/");r.forEach(c=>{var g,a,d;const f=i("div",{className:"spot-qualifying-reasons__item",parent:n}),b=i("div",{className:"spot-qualifying-reasons__icon-wrapper",parent:f}),m=o[((g=c.benefitType)==null?void 0:g.name)||""]||o[c.name||""];if(m){const l=i("img",{parent:b});l.src=s+m,l.alt=((a=c.benefitType)==null?void 0:a.name)||c.name||"",l.className="spot-qualifying-reasons__icon"}i("span",{className:"spot-qualifying-reasons__label",text:((d=c.benefitType)==null?void 0:d.name)||c.name||"",parent:f})})}function z(u,t=[]){if(t.length===0)return;const e=i("div",{className:"spot-covered-items__container",parent:u});i("div",{className:"spot-covered-items__title",text:"Items covered in your cart:",parent:e});const r=i("ul",{className:"spot-covered-items__list",parent:e});t.forEach(n=>{const o=i("li",{parent:r});i("span",{text:n,parent:o})})}function Q(u,t=[]){const e=i("div",{className:"spot-table__container",parent:u}),r=i("table",{className:"spot-refund__table spot-table--dynamic",parent:e}),n=i("thead",{parent:r}),o=i("tr",{parent:n});i("th",{text:"When you cancel",parent:o}),i("th",{text:"You will receive",parent:o});const p=i("tbody",{parent:r});t.forEach(({text:s,percent:c,amount:f})=>{const b=i("tr",{parent:p});i("td",{text:s,parent:b});const m=c==="Not eligible for refund"?"Not eligible for a refund":`$${f} refund`;i("td",{text:m,parent:b})})}function H(u,t,e){const r=i("div",{className:"spot-selection__options",parent:u}),n=i("label",{className:`spot-selection__option ${t?"selected":""}`,parent:r}),o=i("input",{parent:n});o.type="radio",o.name="selection",o.value="yes",t&&(o.checked=!0),i("strong",{text:e.yesOptionText,parent:n}),i("span",{className:"spot-selection__recommended-tag",text:"Recommended",parent:n});const p=i("label",{className:"spot-selection__option",parent:r}),s=i("input",{parent:p});return s.type="radio",s.name="selection",s.value="no",i("span",{text:e.noOptionText,parent:p}),r}function M(u,t){var n;const e=(n=t.communication)==null?void 0:n.paymentTerms,r=i("div",{className:"spot-payment-terms",parent:u});return i("div",{className:"spot-payment-terms__header",text:"PAYMENT TERMS",parent:r}),i("div",{className:"spot-payment-terms__body",text:e||"",parent:r}),r}function L(u,t){const e=i("div",{className:"spot-footer__container",parent:u}),r=i("div",{className:"spot-footer__terms",parent:e});i("span",{innerHTML:t.communication.legalDisclaimer,parent:r}),i("br",{parent:r}),i("a",{href:t.communication.termsAndConditionsUrl,target:"_blank",className:"spot-footer__terms-link",text:"Refund Guarantee Terms and Conditions",parent:r});const n=i("p",{className:"spot-footer__powered-by",parent:e});return n.innerHTML=`
|
|
6
6
|
<svg width="145" height="28" viewBox="0 0 145 28" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
7
7
|
<rect width="145" height="28"/>
|
|
8
8
|
<rect x="-655" y="-270" width="819" height="325" rx="10"/>
|
|
@@ -17,4 +17,4 @@
|
|
|
17
17
|
<rect width="45.405" height="14.8867" fill="white" transform="translate(87 8)"/>
|
|
18
18
|
</clipPath>
|
|
19
19
|
</defs>
|
|
20
|
-
</svg>`,o}const z=":root{--spot-font-family: Arial;--spot-padding: 1.25rem;--spot-background-color: #ffffff;--spot-font-color: #000000;--spot-border-radius: .5rem;--spot-title-font-size: 1.25rem;--spot-title-font-weight: 700;--spot-title-padding: 0 0 1.25rem 0;--spot-description-font-size: .875rem;--spot-description-font-weight: 400;--spot-description-padding: 0 0 .5rem 0;--spot-bullets-font-size: .875rem;--spot-bullets-font-weight: 400;--spot-bullets-padding: .3125rem;--spot-table-border-radius: .625rem;--spot-table-header-font-size: .875rem;--spot-table-header-font-weight: 700;--spot-table-header-padding: 0 .5rem .625rem;--spot-table-cell-font-size: .815rem;--spot-table-cell-font-weight: 400;--spot-table-cell-padding: 0 .625rem;--spot-radio-border: #000000;--spot-radio-border-radius: .625rem;--spot-radio-checked-background: #000000;--spot-radio-text-font-size: .875rem;--spot-radio-text-font-weight: 400;--spot-radio-text-padding: .625rem;--spot-radio-selection-background: #f4f4f4;--spot-radio-selection-border-radius: .625rem;--spot-radio-selection-padding: .625rem;--spot-recommended-tag-background: #000000;--spot-recommended-tag-font-color: #ffffff;--spot-recommended-tag-font-size: .875rem;--spot-recommended-tag-font-weight: 700;--spot-recommended-tag-padding: .25rem .5rem;--spot-recommended-tag-border-radius: .5rem;--spot-selection-error-font-color: #ff0000;--spot-selection-error-font-size: .875rem;--spot-selection-error-padding: .5rem;--spot-payment-terms-background: #f4f4f4;--spot-payment-terms-border-radius: .625rem;--spot-payment-terms-padding: 1rem;--spot-payment-terms-font-color: #636569;--spot-payment-terms-font-size: .75rem;--spot-payment-terms-header-font-weight: 700;--spot-payment-terms-header-font-size: .875rem;--spot-payment-terms-header-margin-bottom: .5rem;--spot-payment-terms-header-border-color: #c2c2c2;--spot-payment-terms-header-padding: 0 0 .5rem 0;--spot-terms-font-size: .75rem;--spot-terms-font-weight: 400;--spot-terms-font-color: #636569;--spot-terms-padding: 0;--spot-terms-link-text-decoration: underline;--spot-terms-link-font-size: .75rem;--spot-terms-link-font-weight: 400;--spot-terms-link-font-color: #636569;--spot-terms-link-padding: 0}.spot-refund-guarantee{font-family:var(--spot-font-family);padding:var(--spot-padding);background-color:var(--spot-background-color);color:var(--spot-font-color);border:.0625rem solid #e0e0e0;border-radius:var(--spot-border-radius);max-width:51rem;margin:1rem}.spot-refund-guarantee *{color:inherit}.spot-header__title{font-size:var(--spot-title-font-size);font-weight:var(--spot-title-font-weight);padding:var(--spot-title-padding);color:var(--spot-title-font-color);font-family:var(--spot-title-font-family);line-height:120%;letter-spacing:-.03125rem}.spot-header__description{font-size:var(--spot-description-font-size);font-weight:var(--spot-description-font-weight);color:var(--spot-description-font-color);font-family:var(--spot-description-font-family);padding:var(--spot-description-padding);line-height:125%;letter-spacing:-.025rem}.spot-content__wrapper{display:flex;flex-direction:column}@media (min-width: 48rem){.spot-content__wrapper.desktop-layout{display:grid;grid-template-columns:1fr 20.3125rem;align-items:start;gap:1rem}.desktop-layout .spot-benefits__list{grid-row:1}.desktop-layout .spot-covered-items__container{grid-row:2;grid-column:1}.desktop-layout .spot-selection__options{grid-row:3}.desktop-layout .spot-table__container{grid-row:1 / span 3}}@media (max-width: 52.438rem){.spot-selection__recommended-tag{display:inline-block;margin-left:0}}@media (max-width: 47.938rem){.spot-selection__recommended-tag{margin-top:0rem}}@media (max-width: 32.125rem){.spot-selection__recommended-tag{margin-top:.5rem}}@media (max-width: 47.9375rem){.spot-table__container{display:flex;justify-content:center}.spot-selection__recommended-tag{display:inline-block;margin-left:0}.spot-footer__container{flex-direction:column;margin-top:.5rem}.spot-refund__table{width:100%;table-layout:auto}.spot-refund__table th{padding:0rem}}.spot-benefits__list{list-style-type:none;line-height:125%;gap:.5625rem;font-size:var(--spot-bullets-font-size);font-weight:var(--spot-bullets-font-weight);color:var(--spot-bullets-font-color);font-family:var(--spot-bullets-font-family);padding:var(--spot-bullets-padding);margin-block-start:0rem;margin-block-end:0rem}.spot-benefits__list li{margin-bottom:.5rem;display:flex;align-items:flex-start;gap:.5rem}.spot-benefits__list li svg{flex-shrink:0;position:relative;top:.125rem}.spot-covered-items__container{margin-top:0;margin-bottom:1rem}.spot-covered-items__title{font-size:var(--spot-description-font-size);font-weight:var(--spot-description-font-weight);color:var(--spot-description-font-color);font-family:var(--spot-description-font-family);padding:0 .3125rem .25rem;line-height:125%;margin:0}.spot-covered-items__list{list-style-type:disc;list-style-position:inside;line-height:125%;gap:.5625rem;font-size:var(--spot-bullets-font-size);font-weight:var(--spot-bullets-font-weight);color:var(--spot-bullets-font-color);font-family:var(--spot-bullets-font-family);padding:var(--spot-bullets-padding);margin-block-start:0rem;margin-block-end:0rem}.spot-covered-items__list li{margin-bottom:.3rem;text-align:left}.spot-table__container{width:100%}.spot-refund__table{max-width:22rem;border-radius:var(--spot-table-border-radius);overflow:hidden;border:.09375rem solid #636569;table-layout:fixed;margin-bottom:1.5rem;margin-top:.25rem;padding:.625rem}.spot-refund__table--dynamic{height:auto!important;min-height:7.5rem}.spot-refund__table td,.spot-refund__table th{padding:.375rem .625rem;text-align:left}.spot-refund__table th{text-align:left;font-size:var(--spot-table-header-font-size);font-weight:var(--spot-table-header-font-weight);color:var(--spot-table-header-font-color);font-family:var(--spot-table-header-font-family);padding:var(--spot-table-header-padding)}.spot-refund__table td{text-align:left;font-size:var(--spot-table-cell-font-size);font-weight:var(--spot-table-cell-font-weight);color:var(--spot-table-cell-font-color);font-family:var(--spot-table-cell-font-family);padding:var(--spot-table-cell-padding)}input[type=radio]{-webkit-appearance:none;-moz-appearance:none;appearance:none;width:.75rem;height:.75rem;border:.0625rem solid var(--spot-radio-border);border-radius:var(--spot-radio-border-radius);margin-right:.5rem;position:relative;vertical-align:middle;top:-.0625rem;cursor:pointer}input[type=radio]:checked{background:var(--spot-radio-checked-background);box-shadow:inset 0 0 0 .0625rem #fff}.spot-selection__options{display:flex;flex-direction:column;gap:.5rem}.spot-selection__option{display:block;position:relative;transition:background .2s;cursor:pointer;font-size:var(--spot-radio-text-font-size);font-weight:var(--spot-radio-text-font-weight);color:var(--spot-radio-text-font-color);font-family:var(--spot-radio-text-font-family);padding:var(--spot-radio-text-padding);margin-right:.5rem;gap:.5rem;flex:1 0 0;align-self:stretch}.spot-selection__option.selected{background:var(--spot-radio-selection-background);border-radius:var(--spot-radio-selection-border-radius);padding:var(--spot-radio-selection-padding)}.spot-selection__recommended-tag{background:var(--spot-recommended-tag-background);color:var(--spot-recommended-tag-font-color);font-size:var(--spot-recommended-tag-font-size);font-weight:var(--spot-recommended-tag-font-weight);padding:var(--spot-recommended-tag-padding);border-radius:var(--spot-recommended-tag-border-radius);margin-left:1.5rem;white-space:nowrap}.spot-selection__error{color:var(--spot-selection-error-font-color);font-size:var(--spot-selection-error-font-size);padding:var(--spot-selection-error-padding);display:none}.spot-payment-terms__wrapper{margin-top:1rem}.spot-payment-terms__header{font-weight:var(--spot-payment-terms-header-font-weight);margin-bottom:.5rem;padding:var(--spot-payment-terms-header-padding);font-size:var(--spot-payment-terms-header-font-size);border-bottom:1px solid var(--spot-payment-terms-header-border-color)}.spot-payment-terms{background-color:var(--spot-payment-terms-background);border-radius:var(--spot-payment-terms-border-radius);padding:var(--spot-payment-terms-padding);margin-right:.5rem;color:var(--spot-payment-terms-font-color);font-size:var(--spot-payment-terms-font-size)}.spot-footer__terms{margin-top:.625rem;margin-right:.25rem;font-size:var(--spot-terms-font-size);font-weight:var(--spot-terms-font-weight);color:var(--spot-terms-font-color);font-family:var(--spot-terms-font-family);padding:var(--spot-terms-padding)}.spot-footer__terms-link{text-decoration:var(--spot-terms-link-text-decoration);font-size:var(--spot-terms-link-font-size);font-weight:var(--spot-terms-link-font-weight);color:var(--spot-terms-link-font-color);font-family:var(--spot-terms-link-font-family);padding:var(--spot-terms-link-padding)}.spot-footer__container{display:flex;justify-content:space-between;align-items:center}.spot-footer__powered-by{margin-top:1.5rem}";function M(c){const e=document.createElement("style");e.textContent=c,document.head.appendChild(e)}M(z);const k={sandbox:"https://api.sandbox.getspot.com/api/v1/quote",production:"https://api.getspot.com/api/v1/quote",local:"http://localhost:3999/api/v1/quote"};class L{constructor(e={}){this.options={location:"body",showTable:!0,optInSelected:!1,apiConfig:{environment:"production",partnerId:""},quoteRequestData:{},callbacks:{},...e},this._onResize=this._updateLayout.bind(this),this.root=typeof this.options.location=="string"?document.querySelector(this.options.location):this.options.location,this.currentSelection=this.options.optInSelected?"yes":null,this._init()}async _init(){var e,o,n,t,r;try{D(this.options);const{environment:p,partnerId:i}=this.options.apiConfig,g=this.options.apiConfig.customEndpoint||k[p],d=this.options.quoteRequestData.cartInfo&&this.options.quoteRequestData.items?await I(g,i,this.options.quoteRequestData):await _(g,i,this.options.quoteRequestData);if(d.status!=="QUOTE_AVAILABLE"){d.status==="NO_MATCHING_QUOTE"&&((e=this.options.callbacks)!=null&&e.noMatchingQuote)&&this.options.callbacks.noMatchingQuote({status:"NO_MATCHING_QUOTE",data:this.options.quoteRequestData});return}if(this.quote=d.data,this._renderWidget(),this.options.optInSelected&&((o=this.options.callbacks)!=null&&o.onOptIn)){const b={status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id};this.quote.originalQuotes&&this.quote.originalQuotes.length>0&&(b.batchQuoteDetails=this.quote.originalQuotes.map(s=>{var f;const l=(f=this.options.quoteRequestData.items)==null?void 0:f.find(w=>(w.cartItemId||`item-${this.options.quoteRequestData.items.indexOf(w)+1}`)===s.cartItemId);return{quoteId:s.id,productPrice:(l==null?void 0:l.productPrice)||s.spotPrice,cartItemId:s.cartItemId}})),this.options.callbacks.onOptIn(b)}(n=this.options.callbacks)!=null&&n.onQuoteRetrieved&&this.options.callbacks.onQuoteRetrieved(this.quote)}catch(p){(t=this.options.callbacks)!=null&&t.onError&&((r=this.options.callbacks)==null||r.onError({message:p.message,status:p.status,responseBody:p.responseBody}))}}_renderWidget(){this.container=document.createElement("div"),this.container.className="spot-refund-guarantee",this.root.appendChild(this.container),Object.entries(this.options.theme||{}).forEach(([n,t])=>{const r=`--${n}`;this.container.style.setProperty(r,t)}),O(this.container,this.quote.communication);const e=document.createElement("div");e.className="spot-content__wrapper",this.container.appendChild(e),P(e,this.quote.communication.bulletPoints),this.quote.coveredItems&&$(e,this.quote.coveredItems),this.options.showTable&&R(e,this.quote.payoutSchedule);const o=Q(e,this.options.optInSelected,this.quote.communication);e.appendChild(o),this.paymentTermsEl=a("div",{className:"spot-payment-terms__wrapper",parent:e}),H(this.container,this.quote),window.addEventListener("resize",this._onResize),this._updateLayout(),this._setupOptionListeners(o)}_updateLayout(){const e=window.matchMedia("(min-width: 768px)").matches;this.container.querySelector(".spot-content__wrapper").classList.toggle("desktop-layout",e&&this.options.showTable)}_setupOptionListeners(e){const o=e.querySelectorAll('input[type="radio"]'),n=e.querySelectorAll(".spot-selection__option");o.forEach(t=>{t.addEventListener("change",r=>{var i,u,g;const p=r.target.value;if(this.hideSelectionError(),this.currentSelection=p,n.forEach(h=>h.classList.remove("selected")),(i=r.target.closest(".spot-selection__option"))==null||i.classList.add("selected"),this.paymentTermsEl&&(this.paymentTermsEl.innerHTML=""),p==="yes"&&(this.options.quoteRequestData.isPartialPayment&&S(this.paymentTermsEl,this.quote),(u=this.options.callbacks)!=null&&u.onOptIn)){const h={status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id};this.quote.originalQuotes&&this.quote.originalQuotes.length>0&&(h.batchQuoteDetails=this.quote.originalQuotes.map(d=>{var s;const b=(s=this.options.quoteRequestData.items)==null?void 0:s.find(l=>(l.cartItemId||`item-${this.options.quoteRequestData.items.indexOf(l)+1}`)===d.cartItemId);return{quoteId:d.id,productPrice:(b==null?void 0:b.productPrice)||d.spotPrice,cartItemId:d.cartItemId}})),this.options.callbacks.onOptIn(h)}if(p==="no"&&((g=this.options.callbacks)!=null&&g.onOptOut)){const h={status:"QUOTE_DECLINED",quoteId:this.quote.id};this.quote.originalQuotes&&this.quote.originalQuotes.length>0&&(h.batchQuoteDetails=this.quote.originalQuotes.map(d=>{var s;const b=(s=this.options.quoteRequestData.items)==null?void 0:s.find(l=>(l.cartItemId||`item-${this.options.quoteRequestData.items.indexOf(l)+1}`)===d.cartItemId);return{quoteId:d.id,productPrice:(b==null?void 0:b.productPrice)||d.spotPrice,cartItemId:d.cartItemId}})),this.options.callbacks.onOptOut(h)}})})}showSelectionError(){var e;if(!this.errorEl){this.errorEl=document.createElement("div"),this.errorEl.className="spot-selection__error",this.errorEl.textContent="Please make a selection";const o=(e=this.container)==null?void 0:e.querySelector(".spot-selection__options");o&&o.insertAdjacentElement("afterend",this.errorEl)}this.errorEl.style.display="block"}hideSelectionError(){this.errorEl&&(this.errorEl.style.display="none")}validateSelection(){if(!this.container)return!1;const e=!!this.container.querySelector('input[name="selection"]:checked');return e?this.hideSelectionError():this.showSelectionError(),e}async updateQuote(e){var o,n,t;try{const r={...this.options,quoteRequestData:e};D(r);const{environment:p,partnerId:i,endpoint:u}=this.options.apiConfig,g=u||k[p],d=r.quoteRequestData.cartInfo&&r.quoteRequestData.items?await I(g,i,r.quoteRequestData):await _(g,i,r.quoteRequestData);return d.status!=="QUOTE_AVAILABLE"?(d.status==="NO_MATCHING_QUOTE"&&((o=this.options.callbacks)!=null&&o.noMatchingQuote)&&this.options.callbacks.noMatchingQuote({status:"NO_MATCHING_QUOTE",data:r.quoteRequestData}),!1):(this.options.quoteRequestData=r.quoteRequestData,this.quote=d.data,this.currentSelection=null,this.destroy(),this._renderWidget(),(n=this.options.callbacks)!=null&&n.onQuoteRetrieved&&this.options.callbacks.onQuoteRetrieved(this.quote),!0)}catch(r){return(t=this.options.callbacks)==null||t.onError({message:r.message,status:r.status,responseBody:r.responseBody}),!1}}getSelection(){var o,n,t;if(this.currentSelection==null)return null;const e={selection:this.currentSelection,quoteId:(o=this.quote)==null?void 0:o.id,spotPrice:(n=this.quote)==null?void 0:n.spotPrice,status:this.currentSelection==="yes"?"QUOTE_ACCEPTED":"QUOTE_DECLINED"};return(t=this.quote)!=null&&t.originalQuotes&&this.quote.originalQuotes.length>0&&(e.batchQuoteDetails=this.quote.originalQuotes.map(r=>{var i;const p=(i=this.options.quoteRequestData.items)==null?void 0:i.find(u=>(u.cartItemId||`item-${this.options.quoteRequestData.items.indexOf(u)+1}`)===r.cartItemId);return{quoteId:r.id,productPrice:(p==null?void 0:p.productPrice)||r.spotPrice,cartItemId:r.cartItemId}})),e}destroy(){window.removeEventListener("resize",this._onResize),this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container)}}return L});
|
|
20
|
+
</svg>`,e}const A=":root{--spot-font-family: Arial;--spot-padding: 1.25rem;--spot-background-color: #ffffff;--spot-font-color: #000000;--spot-border-radius: .5rem;--spot-title-font-size: 1.25rem;--spot-title-font-weight: 700;--spot-title-padding: 0 0 1.25rem 0;--spot-description-font-size: .875rem;--spot-description-font-weight: 400;--spot-description-padding: 0 0 .5rem 0;--spot-bullets-font-size: .875rem;--spot-bullets-font-weight: 400;--spot-bullets-padding: .3125rem;--spot-table-border-radius: .625rem;--spot-table-header-font-size: .875rem;--spot-table-header-font-weight: 700;--spot-table-header-padding: 0 .5rem .625rem;--spot-table-cell-font-size: .815rem;--spot-table-cell-font-weight: 400;--spot-table-cell-padding: 0 .625rem;--spot-radio-border: #000000;--spot-radio-border-radius: .625rem;--spot-radio-checked-background: #000000;--spot-radio-text-font-size: .875rem;--spot-radio-text-font-weight: 400;--spot-radio-text-padding: .625rem;--spot-radio-selection-background: #f4f4f4;--spot-radio-selection-border-radius: .625rem;--spot-radio-selection-padding: .625rem;--spot-recommended-tag-background: #000000;--spot-recommended-tag-font-color: #ffffff;--spot-recommended-tag-font-size: .875rem;--spot-recommended-tag-font-weight: 700;--spot-recommended-tag-padding: .25rem .5rem;--spot-recommended-tag-border-radius: .5rem;--spot-selection-error-font-color: #ff0000;--spot-selection-error-font-size: .875rem;--spot-qualifying-reasons-margin: .75rem 0;--spot-qualifying-reasons-padding: 0 .3125rem;--spot-qualifying-reasons-column-gap: 3rem;--spot-qualifying-reasons-row-gap: .25rem;--spot-qualifying-reasons-grid-padding-left: 1rem;--spot-qualifying-reasons-icon-wrapper-size: 1.125rem;--spot-qualifying-reasons-icon-size: .75rem;--spot-qualifying-reasons-icon-border-color: #2E2E2E;--spot-qualifying-reasons-icon-border-width: 1px;--spot-qualifying-reasons-icon-background: #ffffff;--spot-qualifying-reasons-item-gap: .625rem;--spot-qualifying-reasons-label-font-size: .8rem;--spot-qualifying-reasons-label-font-weight: 400;--spot-qualifying-reasons-label-font-color: #000000;--spot-qualifying-reasons-label-font-family: Arial;--spot-selection-error-padding: .5rem;--spot-payment-terms-background: #f4f4f4;--spot-payment-terms-border-radius: .625rem;--spot-payment-terms-padding: 1rem;--spot-payment-terms-font-color: #636569;--spot-payment-terms-font-size: .75rem;--spot-payment-terms-header-font-weight: 700;--spot-payment-terms-header-font-size: .875rem;--spot-payment-terms-header-margin-bottom: .5rem;--spot-payment-terms-header-border-color: #c2c2c2;--spot-payment-terms-header-padding: 0 0 .5rem 0;--spot-terms-font-size: .75rem;--spot-terms-font-weight: 400;--spot-terms-font-color: #636569;--spot-terms-padding: 0;--spot-terms-link-text-decoration: underline;--spot-terms-link-font-size: .75rem;--spot-terms-link-font-weight: 400;--spot-terms-link-font-color: #636569;--spot-terms-link-padding: 0}.spot-refund-guarantee{font-family:var(--spot-font-family);padding:var(--spot-padding);background-color:var(--spot-background-color);color:var(--spot-font-color);border:.0625rem solid #e0e0e0;border-radius:var(--spot-border-radius);max-width:51rem;margin:1rem}.spot-refund-guarantee *{color:inherit}.spot-header__title{font-size:var(--spot-title-font-size);font-weight:var(--spot-title-font-weight);padding:var(--spot-title-padding);color:var(--spot-title-font-color);font-family:var(--spot-title-font-family);line-height:120%;letter-spacing:-.03125rem}.spot-header__description{font-size:var(--spot-description-font-size);font-weight:var(--spot-description-font-weight);color:var(--spot-description-font-color);font-family:var(--spot-description-font-family);padding:var(--spot-description-padding);line-height:125%;letter-spacing:-.025rem}.spot-content__wrapper{display:flex;flex-direction:column}@media (min-width: 48rem){.spot-content__wrapper.desktop-layout{display:grid;grid-template-columns:1fr 20.3125rem;align-items:start;gap:1rem}.desktop-layout .spot-benefits__list{grid-row:1}.desktop-layout .spot-covered-items__container{grid-row:2;grid-column:1}.desktop-layout .spot-selection__options{grid-row:3}.desktop-layout .spot-table__container{grid-row:1 / span 3}}@media (max-width: 52.438rem){.spot-selection__recommended-tag{display:inline-block;margin-left:0}}@media (max-width: 47.938rem){.spot-selection__recommended-tag{margin-top:0rem}}@media (max-width: 32.125rem){.spot-selection__recommended-tag{margin-top:.5rem}}@media (max-width: 47.9375rem){.spot-table__container{display:flex;justify-content:center}.spot-selection__recommended-tag{display:inline-block;margin-left:0}.spot-footer__container{flex-direction:column;margin-top:.5rem}.spot-refund__table{width:100%;table-layout:auto}.spot-refund__table th{padding:0rem}}.spot-benefits__list{list-style-type:none;line-height:125%;gap:.5625rem;font-size:var(--spot-bullets-font-size);font-weight:var(--spot-bullets-font-weight);color:var(--spot-bullets-font-color);font-family:var(--spot-bullets-font-family);padding:var(--spot-bullets-padding);margin-block-start:0rem;margin-block-end:0rem}.spot-benefits__list li{margin-bottom:.5rem;display:flex;align-items:flex-start;gap:.5rem}.spot-benefits__list li svg{flex-shrink:0;position:relative;top:.125rem}.spot-qualifying-reasons__container{margin:var(--spot-qualifying-reasons-margin);padding:var(--spot-qualifying-reasons-padding)}.spot-qualifying-reasons__grid{display:grid;grid-template-columns:repeat(2,minmax(0,max-content));column-gap:var(--spot-qualifying-reasons-column-gap);row-gap:var(--spot-qualifying-reasons-row-gap);max-width:100%;padding-left:var(--spot-qualifying-reasons-grid-padding-left)}.spot-qualifying-reasons__item{display:flex;align-items:center;gap:var(--spot-qualifying-reasons-item-gap)}.spot-qualifying-reasons__icon-wrapper{width:var(--spot-qualifying-reasons-icon-wrapper-size);height:var(--spot-qualifying-reasons-icon-wrapper-size);border-radius:50%;border:var(--spot-qualifying-reasons-icon-border-width) solid var(--spot-qualifying-reasons-icon-border-color);background-color:var(--spot-qualifying-reasons-icon-background);display:flex;align-items:center;justify-content:center;flex-shrink:0}.spot-qualifying-reasons__icon{width:var(--spot-qualifying-reasons-icon-size);height:var(--spot-qualifying-reasons-icon-size)}.spot-qualifying-reasons__label{font-size:var(--spot-qualifying-reasons-label-font-size);font-weight:var(--spot-qualifying-reasons-label-font-weight);color:var(--spot-qualifying-reasons-label-font-color);font-family:var(--spot-qualifying-reasons-label-font-family);line-height:1.2}@media (max-width: 480px){.spot-qualifying-reasons__grid{grid-template-columns:1fr}}.spot-covered-items__container{margin-top:0;margin-bottom:1rem}.spot-covered-items__title{font-size:var(--spot-description-font-size);font-weight:var(--spot-description-font-weight);color:var(--spot-description-font-color);font-family:var(--spot-description-font-family);padding:0 .3125rem .25rem;line-height:125%;margin:0}.spot-covered-items__list{list-style-type:disc;list-style-position:inside;line-height:125%;gap:.5625rem;font-size:var(--spot-bullets-font-size);font-weight:var(--spot-bullets-font-weight);color:var(--spot-bullets-font-color);font-family:var(--spot-bullets-font-family);padding:var(--spot-bullets-padding);margin-block-start:0rem;margin-block-end:0rem}.spot-covered-items__list li{margin-bottom:.3rem;text-align:left}.spot-table__container{width:100%}.spot-refund__table{max-width:22rem;border-radius:var(--spot-table-border-radius);overflow:hidden;border:.09375rem solid #636569;table-layout:fixed;margin-bottom:1.5rem;margin-top:.25rem;padding:.625rem}.spot-refund__table--dynamic{height:auto!important;min-height:7.5rem}.spot-refund__table td,.spot-refund__table th{padding:.375rem .625rem;text-align:left}.spot-refund__table th{text-align:left;font-size:var(--spot-table-header-font-size);font-weight:var(--spot-table-header-font-weight);color:var(--spot-table-header-font-color);font-family:var(--spot-table-header-font-family);padding:var(--spot-table-header-padding)}.spot-refund__table td{text-align:left;font-size:var(--spot-table-cell-font-size);font-weight:var(--spot-table-cell-font-weight);color:var(--spot-table-cell-font-color);font-family:var(--spot-table-cell-font-family);padding:var(--spot-table-cell-padding)}input[type=radio]{-webkit-appearance:none;-moz-appearance:none;appearance:none;width:.75rem;height:.75rem;border:.0625rem solid var(--spot-radio-border);border-radius:var(--spot-radio-border-radius);margin-right:.5rem;position:relative;vertical-align:middle;top:-.0625rem;cursor:pointer}input[type=radio]:checked{background:var(--spot-radio-checked-background);box-shadow:inset 0 0 0 .0625rem #fff}.spot-selection__options{display:flex;flex-direction:column;gap:.5rem}.spot-selection__option{display:block;position:relative;transition:background .2s;cursor:pointer;font-size:var(--spot-radio-text-font-size);font-weight:var(--spot-radio-text-font-weight);color:var(--spot-radio-text-font-color);font-family:var(--spot-radio-text-font-family);padding:var(--spot-radio-text-padding);margin-right:.5rem;gap:.5rem;flex:1 0 0;align-self:stretch}.spot-selection__option.selected{background:var(--spot-radio-selection-background);border-radius:var(--spot-radio-selection-border-radius);padding:var(--spot-radio-selection-padding)}.spot-selection__recommended-tag{background:var(--spot-recommended-tag-background);color:var(--spot-recommended-tag-font-color);font-size:var(--spot-recommended-tag-font-size);font-weight:var(--spot-recommended-tag-font-weight);padding:var(--spot-recommended-tag-padding);border-radius:var(--spot-recommended-tag-border-radius);margin-left:1.5rem;white-space:nowrap}.spot-selection__error{color:var(--spot-selection-error-font-color);font-size:var(--spot-selection-error-font-size);padding:var(--spot-selection-error-padding);display:none}.spot-payment-terms__wrapper{margin-top:1rem}.spot-payment-terms__header{font-weight:var(--spot-payment-terms-header-font-weight);margin-bottom:.5rem;padding:var(--spot-payment-terms-header-padding);font-size:var(--spot-payment-terms-header-font-size);border-bottom:1px solid var(--spot-payment-terms-header-border-color)}.spot-payment-terms{background-color:var(--spot-payment-terms-background);border-radius:var(--spot-payment-terms-border-radius);padding:var(--spot-payment-terms-padding);margin-right:.5rem;color:var(--spot-payment-terms-font-color);font-size:var(--spot-payment-terms-font-size)}.spot-footer__terms{margin-top:.625rem;margin-right:.25rem;font-size:var(--spot-terms-font-size);font-weight:var(--spot-terms-font-weight);color:var(--spot-terms-font-color);font-family:var(--spot-terms-font-family);padding:var(--spot-terms-padding)}.spot-footer__terms-link{text-decoration:var(--spot-terms-link-text-decoration);font-size:var(--spot-terms-link-font-size);font-weight:var(--spot-terms-link-font-weight);color:var(--spot-terms-link-font-color);font-family:var(--spot-terms-link-font-family);padding:var(--spot-terms-link-padding)}.spot-footer__container{display:flex;justify-content:space-between;align-items:center}.spot-footer__powered-by{margin-top:1.5rem}";function V(u){const t=document.createElement("style");t.textContent=u,document.head.appendChild(t)}V(A);const k={sandbox:"https://api.sandbox.getspot.com/api/v1/quote",production:"https://api.getspot.com/api/v1/quote",local:"http://localhost:3999/api/v1/quote"};class j{constructor(t={}){this.options={location:"body",showTable:!0,optInSelected:!1,apiConfig:{environment:"production",partnerId:""},quoteRequestData:{},callbacks:{},...t},this._onResize=this._updateLayout.bind(this),this.root=typeof this.options.location=="string"?document.querySelector(this.options.location):this.options.location,this.currentSelection=this.options.optInSelected?"yes":null,this._init()}async _init(){var t,e,r,n,o;try{D(this.options);const{environment:p,partnerId:s}=this.options.apiConfig,f=this.options.apiConfig.customEndpoint||k[p],m="cartInfo"in this.options.quoteRequestData&&"items"in this.options.quoteRequestData?await I(f,s,this.options.quoteRequestData):await _(f,s,this.options.quoteRequestData);if(m.status!=="QUOTE_AVAILABLE"){m.status==="NO_MATCHING_QUOTE"&&((t=this.options.callbacks)!=null&&t.noMatchingQuote)&&this.options.callbacks.noMatchingQuote({status:"NO_MATCHING_QUOTE",data:this.options.quoteRequestData});return}if(this.quote=m.data,this._renderWidget(),this.options.optInSelected&&((e=this.options.callbacks)!=null&&e.onOptIn)){const g={status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id};if(this.quote.originalQuotes&&this.quote.originalQuotes.length>0){const a=this.options.quoteRequestData;g.batchQuoteDetails=this.quote.originalQuotes.map(d=>{var w;const l=(w=a.items)==null?void 0:w.find(q=>(q.cartItemId||`item-${a.items.indexOf(q)+1}`)===d.id);return{quoteId:d.id,productPrice:(l==null?void 0:l.productPrice)||d.spotPrice,cartItemId:d.id}})}this.options.callbacks.onOptIn(g)}(r=this.options.callbacks)!=null&&r.onQuoteRetrieved&&this.options.callbacks.onQuoteRetrieved(this.quote)}catch(p){if((n=this.options.callbacks)!=null&&n.onError){const s=p;(o=this.options.callbacks)==null||o.onError({message:s.message,status:s.status,responseBody:s.responseBody})}}}_renderWidget(){if(!this.quote)return;this.container=document.createElement("div"),this.container.className="spot-refund-guarantee",this.root.appendChild(this.container),Object.entries(this.options.theme||{}).forEach(([r,n])=>{const o=`--${r}`;this.container.style.setProperty(o,n)}),R(this.container,this.quote.communication);const t=document.createElement("div");t.className="spot-content__wrapper",this.container.appendChild(t),this.quote.qualifyingReasons?$(t,this.quote.qualifyingReasons):S(t,this.quote.communication.bulletPoints),this.quote.coveredItems&&z(t,this.quote.coveredItems),this.options.showTable&&!this.quote.qualifyingReasons&&Q(t,this.quote.payoutSchedule);const e=H(t,this.options.optInSelected,this.quote.communication);t.appendChild(e),this.paymentTermsEl=i("div",{className:"spot-payment-terms__wrapper",parent:t}),L(this.container,this.quote),window.addEventListener("resize",this._onResize),this._updateLayout(),this._setupOptionListeners(e)}_updateLayout(){var r;if(!this.container||!this.quote)return;const t=window.matchMedia("(min-width: 768px)").matches,e=this.options.showTable&&!this.quote.qualifyingReasons;(r=this.container.querySelector(".spot-content__wrapper"))==null||r.classList.toggle("desktop-layout",t&&e)}_setupOptionListeners(t){const e=t.querySelectorAll('input[type="radio"]'),r=t.querySelectorAll(".spot-selection__option");e.forEach(n=>{n.addEventListener("change",o=>{var c,f,b;const p=o.target,s=p.value;if(this.hideSelectionError(),this.currentSelection=s,r.forEach(m=>m.classList.remove("selected")),(c=p.closest(".spot-selection__option"))==null||c.classList.add("selected"),this.paymentTermsEl&&(this.paymentTermsEl.innerHTML=""),s==="yes"&&(this.options.quoteRequestData.isPartialPayment&&M(this.paymentTermsEl,this.quote),(f=this.options.callbacks)!=null&&f.onOptIn)){const m={status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id};if(this.quote.originalQuotes&&this.quote.originalQuotes.length>0){const g=this.options.quoteRequestData;m.batchQuoteDetails=this.quote.originalQuotes.map(a=>{var l;const d=(l=g.items)==null?void 0:l.find(w=>(w.cartItemId||`item-${g.items.indexOf(w)+1}`)===a.id);return{quoteId:a.id,productPrice:(d==null?void 0:d.productPrice)||a.spotPrice,cartItemId:a.id}})}this.options.callbacks.onOptIn(m)}if(s==="no"&&((b=this.options.callbacks)!=null&&b.onOptOut)){const m={status:"QUOTE_DECLINED",quoteId:this.quote.id};if(this.quote.originalQuotes&&this.quote.originalQuotes.length>0){const g=this.options.quoteRequestData;m.batchQuoteDetails=this.quote.originalQuotes.map(a=>{var l;const d=(l=g.items)==null?void 0:l.find(w=>(w.cartItemId||`item-${g.items.indexOf(w)+1}`)===a.id);return{quoteId:a.id,productPrice:(d==null?void 0:d.productPrice)||a.spotPrice,cartItemId:a.id}})}this.options.callbacks.onOptOut(m)}})})}showSelectionError(){var t;if(!this.errorEl){this.errorEl=document.createElement("div"),this.errorEl.className="spot-selection__error",this.errorEl.textContent="Please make a selection";const e=(t=this.container)==null?void 0:t.querySelector(".spot-selection__options");e&&e.insertAdjacentElement("afterend",this.errorEl)}this.errorEl.style.display="block"}hideSelectionError(){this.errorEl&&(this.errorEl.style.display="none")}validateSelection(){if(!this.container)return!1;const t=!!this.container.querySelector('input[name="selection"]:checked');return t?this.hideSelectionError():this.showSelectionError(),t}async updateQuote(t){var e,r,n,o;try{const p={...this.options,quoteRequestData:t};D(p);const{environment:s,partnerId:c,customEndpoint:f}=this.options.apiConfig,b=f||k[s],g="cartInfo"in p.quoteRequestData&&"items"in p.quoteRequestData?await I(b,c,p.quoteRequestData):await _(b,c,p.quoteRequestData);return g.status!=="QUOTE_AVAILABLE"?(g.status==="NO_MATCHING_QUOTE"&&((e=this.options.callbacks)!=null&&e.noMatchingQuote)&&this.options.callbacks.noMatchingQuote({status:"NO_MATCHING_QUOTE",data:p.quoteRequestData}),!1):(this.options.quoteRequestData=p.quoteRequestData,this.quote=g.data,this.currentSelection=null,this.destroy(),this._renderWidget(),(r=this.options.callbacks)!=null&&r.onQuoteRetrieved&&this.options.callbacks.onQuoteRetrieved(this.quote),!0)}catch(p){const s=p;return(o=(n=this.options.callbacks)==null?void 0:n.onError)==null||o.call(n,{message:s.message,status:s.status,responseBody:s.responseBody}),!1}}getSelection(){var e,r,n;if(this.currentSelection==null)return null;const t={selection:this.currentSelection,quoteId:(e=this.quote)==null?void 0:e.id,spotPrice:(r=this.quote)==null?void 0:r.spotPrice,status:this.currentSelection==="yes"?"QUOTE_ACCEPTED":"QUOTE_DECLINED"};if((n=this.quote)!=null&&n.originalQuotes&&this.quote.originalQuotes.length>0){const o=this.options.quoteRequestData;t.batchQuoteDetails=this.quote.originalQuotes.map(p=>{var c;const s=(c=o.items)==null?void 0:c.find(f=>(f.cartItemId||`item-${o.items.indexOf(f)+1}`)===p.id);return{quoteId:p.id,productPrice:(s==null?void 0:s.productPrice)||p.spotPrice,cartItemId:p.id}})}return t}destroy(){window.removeEventListener("resize",this._onResize),this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container)}}return j});
|
package/dist/medal.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-medal-2"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M9 3h6l3 7l-6 2l-6 -2z" /><path d="M12 12l-3 -9" /><path d="M15 11l-3 -8" /><path d="M12 19.5l-3 1.5l.5 -3.5l-2 -2l3 -.5l1.5 -3l1.5 3l3 .5l-2 2l.5 3.5z" /></svg>
|
package/dist/plane.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-plane-icon lucide-plane"><path d="M17.8 19.2 16 11l3.5-3.5C21 6 21.5 4 21 3c-1-.5-3 0-4.5 1.5L13 8 4.8 6.2c-.5-.1-.9.1-1.1.5l-.3.5c-.2.5-.1 1 .3 1.3L9 12l-2 3H4l-1 1 3 2 2 3 1-1v-3l3-2 3.5 5.3c.3.4.8.5 1.3.3l.5-.2c.4-.3.6-.7.5-1.2z"/></svg>
|
package/dist/scale.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-scale-icon lucide-scale"><path d="m16 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z"/><path d="m2 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z"/><path d="M7 21h10"/><path d="M12 3v18"/><path d="M3 7h2c2 0 5-1 7-2 2 1 5 2 7 2h2"/></svg>
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
export interface ApiConfig {
|
|
2
|
+
environment: 'sandbox' | 'production' | 'local';
|
|
3
|
+
partnerId: string;
|
|
4
|
+
customEndpoint?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface QuoteMetadata {
|
|
7
|
+
segment?: string;
|
|
8
|
+
operator?: string;
|
|
9
|
+
channel?: string;
|
|
10
|
+
consumerId?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface CartInfo {
|
|
13
|
+
cartId: string;
|
|
14
|
+
cartName: string;
|
|
15
|
+
currencyCode: 'USD' | 'CAD' | 'AUD';
|
|
16
|
+
metadata?: QuoteMetadata;
|
|
17
|
+
isPartialPayment?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface QuoteItem {
|
|
20
|
+
productPrice: number;
|
|
21
|
+
productType: 'Pass' | 'Trip' | 'Registration';
|
|
22
|
+
productDuration: 'Daily' | 'Seasonal' | 'Trip' | 'Event';
|
|
23
|
+
productId: string;
|
|
24
|
+
cartId: string;
|
|
25
|
+
cartName: string;
|
|
26
|
+
productName: string;
|
|
27
|
+
participantDescription?: string;
|
|
28
|
+
eventType: string;
|
|
29
|
+
currencyCode: 'USD' | 'CAD' | 'AUD';
|
|
30
|
+
startDate: string;
|
|
31
|
+
endDate: string;
|
|
32
|
+
partnerRiskEnd?: Date;
|
|
33
|
+
metadata?: QuoteMetadata;
|
|
34
|
+
isPartialPayment?: boolean;
|
|
35
|
+
hostCountry?: string;
|
|
36
|
+
hostCountryState?: string;
|
|
37
|
+
destinations?: string[];
|
|
38
|
+
dob?: string;
|
|
39
|
+
}
|
|
40
|
+
type BatchItem = Omit<QuoteItem, 'cartName' | 'cartId' | 'currencyCode' | 'isPartialPayment' | 'metadata'>;
|
|
41
|
+
export interface BatchQuoteItem extends BatchItem {
|
|
42
|
+
cartItemId: string;
|
|
43
|
+
}
|
|
44
|
+
export interface BatchQuoteRequest {
|
|
45
|
+
cartInfo: CartInfo;
|
|
46
|
+
items: BatchQuoteItem[];
|
|
47
|
+
}
|
|
48
|
+
export type QuoteRequestData = QuoteItem | BatchQuoteRequest;
|
|
49
|
+
export interface QualifyingReason {
|
|
50
|
+
rank: number;
|
|
51
|
+
name?: string;
|
|
52
|
+
benefitType?: {
|
|
53
|
+
name: string;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export interface PayoutScheduleItem {
|
|
57
|
+
text: string;
|
|
58
|
+
percent: string | number;
|
|
59
|
+
amount: number;
|
|
60
|
+
}
|
|
61
|
+
export interface Communication {
|
|
62
|
+
name: string;
|
|
63
|
+
description: string;
|
|
64
|
+
bulletPoints: string[];
|
|
65
|
+
yesOptionText: string;
|
|
66
|
+
noOptionText: string;
|
|
67
|
+
legalDisclaimer: string;
|
|
68
|
+
termsAndConditionsUrl: string;
|
|
69
|
+
paymentTerms?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface Quote {
|
|
72
|
+
id: string;
|
|
73
|
+
cartItemId?: string;
|
|
74
|
+
spotPrice: number;
|
|
75
|
+
currencyCode: string;
|
|
76
|
+
communication: Communication;
|
|
77
|
+
payoutSchedule: PayoutScheduleItem[];
|
|
78
|
+
qualifyingReasons?: QualifyingReason[];
|
|
79
|
+
coveredItems?: string[];
|
|
80
|
+
originalQuotes?: Quote[];
|
|
81
|
+
}
|
|
82
|
+
export interface ApiResponse {
|
|
83
|
+
status: 'QUOTE_AVAILABLE' | 'QUOTES_AVAILABLE' | 'NO_MATCHING_QUOTE';
|
|
84
|
+
data?: Quote;
|
|
85
|
+
quotes?: Quote[];
|
|
86
|
+
totalSpotPrice?: number;
|
|
87
|
+
spotPrice?: number;
|
|
88
|
+
currencyCode?: string;
|
|
89
|
+
communication?: Communication;
|
|
90
|
+
payoutSchedule?: PayoutScheduleItem[];
|
|
91
|
+
coveredItems?: string[];
|
|
92
|
+
}
|
|
93
|
+
export interface SelectionData {
|
|
94
|
+
status: 'QUOTE_ACCEPTED' | 'QUOTE_DECLINED';
|
|
95
|
+
spotPrice?: number;
|
|
96
|
+
quoteId?: string;
|
|
97
|
+
selection?: string;
|
|
98
|
+
batchQuoteDetails?: Array<{
|
|
99
|
+
quoteId: string;
|
|
100
|
+
productPrice: number;
|
|
101
|
+
cartItemId: string;
|
|
102
|
+
}>;
|
|
103
|
+
}
|
|
104
|
+
export interface Callbacks {
|
|
105
|
+
onOptIn?: (data: SelectionData) => void;
|
|
106
|
+
onOptOut?: (data: SelectionData) => void;
|
|
107
|
+
onQuoteRetrieved?: (quote: Quote) => void;
|
|
108
|
+
onError?: (error: {
|
|
109
|
+
message: string;
|
|
110
|
+
status?: number;
|
|
111
|
+
responseBody?: any;
|
|
112
|
+
}) => void;
|
|
113
|
+
noMatchingQuote?: (data: {
|
|
114
|
+
status: string;
|
|
115
|
+
data: QuoteRequestData;
|
|
116
|
+
}) => void;
|
|
117
|
+
}
|
|
118
|
+
export interface Theme {
|
|
119
|
+
[key: string]: string;
|
|
120
|
+
}
|
|
121
|
+
export interface SpotWidgetOptions {
|
|
122
|
+
location?: string | HTMLElement;
|
|
123
|
+
showTable?: boolean;
|
|
124
|
+
optInSelected?: boolean;
|
|
125
|
+
apiConfig: ApiConfig;
|
|
126
|
+
quoteRequestData: QuoteRequestData;
|
|
127
|
+
callbacks?: Callbacks;
|
|
128
|
+
theme?: Theme;
|
|
129
|
+
isPartialPayment?: boolean;
|
|
130
|
+
}
|
|
131
|
+
export interface ApiError extends Error {
|
|
132
|
+
status?: number;
|
|
133
|
+
responseBody?: any;
|
|
134
|
+
}
|
|
135
|
+
export interface ElementOptions {
|
|
136
|
+
text?: string;
|
|
137
|
+
className?: string;
|
|
138
|
+
parent?: HTMLElement;
|
|
139
|
+
innerHTML?: string;
|
|
140
|
+
href?: string;
|
|
141
|
+
target?: string;
|
|
142
|
+
}
|
|
143
|
+
export {};
|
|
144
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,WAAW,EAAE,SAAS,GAAG,YAAY,GAAG,OAAO,CAAC;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;IACpC,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,cAAc,CAAC;IAC9C,eAAe,EAAE,OAAO,GAAG,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC;IACzD,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,IAAI,CAAC;IACtB,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,KAAK,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,UAAU,GAAG,QAAQ,GAAG,cAAc,GAAG,kBAAkB,GAAG,UAAU,CAAC,CAAC;AAE3G,MAAM,WAAW,cAAe,SAAQ,SAAS;IAC/C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,cAAc,EAAE,CAAC;CACzB;AAED,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,iBAAiB,CAAC;AAE7D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE;QACZ,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,aAAa,CAAC;IAC7B,cAAc,EAAE,kBAAkB,EAAE,CAAC;IACrC,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACvC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,cAAc,CAAC,EAAE,KAAK,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,iBAAiB,GAAG,kBAAkB,GAAG,mBAAmB,CAAC;IACrE,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,cAAc,CAAC,EAAE,kBAAkB,EAAE,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,CAAC;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,KAAK,CAAC;QACxB,OAAO,EAAE,MAAM,CAAC;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC,CAAC;CACJ;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;IACxC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;IACzC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC1C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,GAAG,CAAA;KAAE,KAAK,IAAI,CAAC;IACpF,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,gBAAgB,CAAA;KAAE,KAAK,IAAI,CAAC;CAC9E;AAED,MAAM,WAAW,KAAK;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IAChC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,SAAS,EAAE,SAAS,CAAC;IACrB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,QAAS,SAAQ,KAAK;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
package/dist/ui.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ElementOptions, Communication, QualifyingReason, PayoutScheduleItem, Quote } from './types.js';
|
|
2
|
+
export declare function makeEl<K extends keyof HTMLElementTagNameMap>(tag: K, { text, className, parent, innerHTML, href, target }?: ElementOptions): HTMLElementTagNameMap[K];
|
|
3
|
+
export declare function renderHeader(container: HTMLElement, { name, description }: Pick<Communication, 'name' | 'description'>): void;
|
|
4
|
+
export declare function renderBenefits(container: HTMLElement, bullets?: string[]): void;
|
|
5
|
+
export declare function renderQualifyingReasons(container: HTMLElement, qualifyingReasons?: QualifyingReason[]): void;
|
|
6
|
+
export declare function renderCoveredItems(container: HTMLElement, coveredItems?: string[]): void;
|
|
7
|
+
export declare function renderTable(container: HTMLElement, schedule?: PayoutScheduleItem[]): void;
|
|
8
|
+
export declare function renderOptions(container: HTMLElement, optInSelected: boolean, communication: Communication): HTMLElement;
|
|
9
|
+
export declare function renderPaymentTerms(container: HTMLElement, quote: Quote): HTMLElement;
|
|
10
|
+
export declare function renderFooter(container: HTMLElement, quote: Quote): HTMLElement;
|
|
11
|
+
//# sourceMappingURL=ui.d.ts.map
|
package/dist/ui.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAE7G,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,qBAAqB,EAC1D,GAAG,EAAE,CAAC,EACN,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,GAAE,cAAmB,GACxE,qBAAqB,CAAC,CAAC,CAAC,CAS1B;AAGD,wBAAgB,YAAY,CAAC,SAAS,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,aAAa,CAAC,GAAG,IAAI,CAW7H;AAGD,wBAAgB,cAAc,CAAC,SAAS,EAAE,WAAW,EAAE,OAAO,GAAE,MAAM,EAAO,GAAG,IAAI,CAcnF;AAGD,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,WAAW,EAAE,iBAAiB,GAAE,gBAAgB,EAAO,GAAG,IAAI,CA0DhH;AAGD,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,WAAW,EAAE,YAAY,GAAE,MAAM,EAAO,GAAG,IAAI,CAoB5F;AAGD,wBAAgB,WAAW,CAAC,SAAS,EAAE,WAAW,EAAE,QAAQ,GAAE,kBAAkB,EAAO,GAAG,IAAI,CAyB7F;AAGD,wBAAgB,aAAa,CAAC,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,GAAG,WAAW,CAyCvH;AAGD,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,GAAG,WAAW,CAqBpF;AAGD,wBAAgB,YAAY,CAAC,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,GAAG,WAAW,CA6C9E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-umbrella-icon lucide-umbrella"><path d="M22 12a10.06 10.06 1 0 0-20 0Z"/><path d="M12 12v8a2 2 0 0 0 4 0"/><path d="M12 2v1"/></svg>
|
package/dist/users.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-users-icon lucide-users"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><path d="M16 3.128a4 4 0 0 1 0 7.744"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><circle cx="9" cy="7" r="4"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateOptions.d.ts","sourceRoot":"","sources":["../src/validateOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAqC,MAAM,YAAY,CAAC;AAQvF,wBAAgB,eAAe,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,CA+PhE"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getspot/spot-widget",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
7
|
"main": "dist/index.umd.js",
|
|
8
8
|
"module": "dist/index.es.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md",
|
|
13
|
+
"CHANGELOG.md"
|
|
14
|
+
],
|
|
9
15
|
"devDependencies": {
|
|
10
|
-
"vite": "^5.0.0"
|
|
16
|
+
"vite": "^5.0.0",
|
|
17
|
+
"typescript": "~5.4.0",
|
|
18
|
+
"typedoc": "^0.28.0",
|
|
19
|
+
"typedoc-plugin-markdown": "^4.0.0",
|
|
20
|
+
"jest": "^29.0.0",
|
|
21
|
+
"@types/jest": "^29.0.0",
|
|
22
|
+
"jest-environment-jsdom": "^29.0.0",
|
|
23
|
+
"ts-jest": "^29.0.0"
|
|
11
24
|
},
|
|
12
25
|
"scripts": {
|
|
13
|
-
"build": "vite build"
|
|
26
|
+
"build": "vite build && npx -p typescript tsc --emitDeclarationOnly",
|
|
27
|
+
"docs": "node generate-docs.js",
|
|
28
|
+
"docs:readme": "npm run docs && node scripts/generate-readme.js",
|
|
29
|
+
"test": "jest",
|
|
30
|
+
"test:watch": "jest --watch",
|
|
31
|
+
"test:coverage": "jest --coverage",
|
|
32
|
+
"test:ci": "jest --ci --coverage --watchAll=false"
|
|
14
33
|
}
|
|
15
34
|
}
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @getspot/spot-widget@1.3.0 build /builds/getspot/spot-widget/packages/core
|
|
3
|
-
> vite build
|
|
4
|
-
|
|
5
|
-
[33mThe CJS build of Vite's Node API is deprecated. See https://vite.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.[39m
|
|
6
|
-
[36mvite v5.4.18 [32mbuilding for production...[36m[39m
|
|
7
|
-
transforming...
|
|
8
|
-
[32m✓[39m 5 modules transformed.
|
|
9
|
-
rendering chunks...
|
|
10
|
-
computing gzip size...
|
|
11
|
-
[2mdist/[22m[36mindex.umd.js [39m[1m[2m31.95 kB[22m[1m[22m[2m │ gzip: 8.86 kB[22m
|
|
12
|
-
[2mdist/[22m[36mindex.es.js [39m[1m[2m36.58 kB[22m[1m[22m[2m │ gzip: 9.39 kB[22m
|
|
13
|
-
[32m✓ built in 248ms[39m
|
package/src/api.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Retrieve quote from Spot API
|
|
3
|
-
* @param {string} endpoint – Spot API URL
|
|
4
|
-
* @param {string} partnerId – partner UUID
|
|
5
|
-
* @param {object} payload – quoteRequestData
|
|
6
|
-
* @returns {Promise<{ status: string, data?: object }>}
|
|
7
|
-
*/
|
|
8
|
-
export async function fetchQuote(endpoint, partnerId, payload) {
|
|
9
|
-
try {
|
|
10
|
-
const res = await fetch(endpoint, {
|
|
11
|
-
method: "POST",
|
|
12
|
-
headers: {
|
|
13
|
-
"Content-Type": "application/json",
|
|
14
|
-
"X-Spot-Partner-Id": partnerId,
|
|
15
|
-
},
|
|
16
|
-
body: JSON.stringify(payload),
|
|
17
|
-
});
|
|
18
|
-
const body = await res.json();
|
|
19
|
-
if (!res.ok) {
|
|
20
|
-
const error = new Error(body?.message || "Failed to fetch quote");
|
|
21
|
-
error.status = res.status;
|
|
22
|
-
error.responseBody = body;
|
|
23
|
-
throw error;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return body;
|
|
27
|
-
} catch (err) {
|
|
28
|
-
throw err instanceof Error
|
|
29
|
-
? err
|
|
30
|
-
: new Error("Unknown error occurred while fetching quote");
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Retrieve batch quote from Spot API
|
|
36
|
-
* @param {string} endpoint – Spot API URL
|
|
37
|
-
* @param {string} partnerId – partner UUID
|
|
38
|
-
* @param {object} batchPayload – batch request data with items array
|
|
39
|
-
* @returns {Promise<{ status: string, data?: object }>}
|
|
40
|
-
*/
|
|
41
|
-
export async function fetchBatchQuote(endpoint, partnerId, batchPayload) {
|
|
42
|
-
try {
|
|
43
|
-
const batchEndpoint = endpoint.replace('/quote', '/quote/batch');
|
|
44
|
-
const res = await fetch(batchEndpoint, {
|
|
45
|
-
method: "POST",
|
|
46
|
-
headers: {
|
|
47
|
-
"Content-Type": "application/json",
|
|
48
|
-
"X-Spot-Partner-Id": partnerId,
|
|
49
|
-
},
|
|
50
|
-
body: JSON.stringify(batchPayload),
|
|
51
|
-
});
|
|
52
|
-
const body = await res.json();
|
|
53
|
-
if (!res.ok) {
|
|
54
|
-
const error = new Error(body?.message || "Failed to fetch batch quote");
|
|
55
|
-
error.status = res.status;
|
|
56
|
-
error.responseBody = body;
|
|
57
|
-
throw error;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return body;
|
|
61
|
-
} catch (err) {
|
|
62
|
-
throw err instanceof Error
|
|
63
|
-
? err
|
|
64
|
-
: new Error("Unknown error occurred while fetching batch quote");
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Retrieve multiple quotes in parallel from Spot API
|
|
70
|
-
* @param {string} endpoint – Spot API URL
|
|
71
|
-
* @param {string} partnerId – partner UUID
|
|
72
|
-
* @param {object} batchData – batch quote data with cartInfo and items
|
|
73
|
-
* @param {object} batchData.cartInfo – cart-level information
|
|
74
|
-
* @param {string} batchData.cartInfo.cartId – cart ID
|
|
75
|
-
* @param {string} batchData.cartInfo.cartName – cart name
|
|
76
|
-
* @param {string} batchData.cartInfo.currencyCode – currency code
|
|
77
|
-
* @param {object[]} batchData.items – array of item data
|
|
78
|
-
* @returns {Promise<{ status: string, data?: object, spotPrice?: number, coveredItems?: string[] }>}
|
|
79
|
-
*/
|
|
80
|
-
export async function fetchMultipleQuotes(endpoint, partnerId, batchData) {
|
|
81
|
-
try {
|
|
82
|
-
// Transform into batch format for API
|
|
83
|
-
const batchPayload = {
|
|
84
|
-
cartId: batchData.cartInfo.cartId,
|
|
85
|
-
cartName: batchData.cartInfo.cartName,
|
|
86
|
-
currencyCode: batchData.cartInfo.currencyCode,
|
|
87
|
-
items: batchData.items.map((item, index) => ({
|
|
88
|
-
cartItemId: item.cartItemId || `item-${index + 1}`,
|
|
89
|
-
productPrice: item.productPrice,
|
|
90
|
-
productType: item.productType,
|
|
91
|
-
productDuration: item.productDuration,
|
|
92
|
-
productId: item.productId,
|
|
93
|
-
productName: item.productName,
|
|
94
|
-
participantDescription: item.participantDescription,
|
|
95
|
-
eventType: item.eventType,
|
|
96
|
-
startDate: item.startDate,
|
|
97
|
-
endDate: item.endDate
|
|
98
|
-
}))
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const response = await fetchBatchQuote(endpoint, partnerId, batchPayload);
|
|
102
|
-
|
|
103
|
-
// Check for various success statuses
|
|
104
|
-
if (response.status !== "QUOTES_AVAILABLE" && response.status !== "QUOTE_AVAILABLE") {
|
|
105
|
-
return { status: "NO_MATCHING_QUOTE" };
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Extract covered items only for successful quotes
|
|
109
|
-
const coveredItems = response.quotes.map(quote => {
|
|
110
|
-
// Find the corresponding item from the original request using cartItemId
|
|
111
|
-
const originalItem = batchData.items.find(item =>
|
|
112
|
-
(item.cartItemId || `item-${batchData.items.indexOf(item) + 1}`) === quote.cartItemId
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
if (originalItem) {
|
|
116
|
-
return originalItem.participantDescription
|
|
117
|
-
? `${originalItem.productName} - ${originalItem.participantDescription}`
|
|
118
|
-
: originalItem.productName;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Fallback if we can't find the original item
|
|
122
|
-
return `Item ${quote.cartItemId}`;
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
// Fix floating point precision issue
|
|
126
|
-
const totalSpotPrice = Math.round((response.totalSpotPrice || response.spotPrice || 0) * 100) / 100;
|
|
127
|
-
|
|
128
|
-
// Build response in expected format
|
|
129
|
-
return {
|
|
130
|
-
status: "QUOTE_AVAILABLE",
|
|
131
|
-
data: {
|
|
132
|
-
id: response.quotes ? response.quotes.map(q => q.id).join(',') : response.id,
|
|
133
|
-
spotPrice: totalSpotPrice,
|
|
134
|
-
currencyCode: response.currencyCode,
|
|
135
|
-
communication: {
|
|
136
|
-
...response.communication,
|
|
137
|
-
yesOptionText: response.communication.yesOptionText.replace(response.totalSpotPrice, totalSpotPrice)
|
|
138
|
-
},
|
|
139
|
-
payoutSchedule: response.payoutSchedule.map(item => ({
|
|
140
|
-
...item,
|
|
141
|
-
amount: item.amount !== undefined ? item.amount : 0
|
|
142
|
-
})),
|
|
143
|
-
coveredItems: coveredItems,
|
|
144
|
-
originalQuotes: response.quotes || [response]
|
|
145
|
-
},
|
|
146
|
-
spotPrice: totalSpotPrice,
|
|
147
|
-
coveredItems
|
|
148
|
-
};
|
|
149
|
-
} catch (err) {
|
|
150
|
-
throw err instanceof Error
|
|
151
|
-
? err
|
|
152
|
-
: new Error("Unknown error occurred while fetching multiple quotes");
|
|
153
|
-
}
|
|
154
|
-
}
|