@getspot/spot-widget 0.1.3 → 0.2.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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @getspot/spot-widget@0.1.3 build /builds/getspot/spot-widget/packages/core
2
+ > @getspot/spot-widget@0.2.0 build /builds/getspot/spot-widget/packages/core
3
3
  > vite build
4
4
 
5
5
  The CJS build of Vite's Node API is deprecated. See https://vite.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
@@ -8,6 +8,6 @@ transforming...
8
8
  ✓ 5 modules transformed.
9
9
  rendering chunks...
10
10
  computing gzip size...
11
- dist/index.umd.js 21.85 kB │ gzip: 7.00 kB
12
- dist/index.es.js 23.88 kB │ gzip: 7.23 kB
13
- ✓ built in 145ms
11
+ dist/index.umd.js 22.08 kB │ gzip: 7.07 kB
12
+ dist/index.es.js 24.17 kB │ gzip: 7.31 kB
13
+ ✓ built in 149ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @getspot/spot-widget
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 25bba43: Making cartId required on quoteRequest
8
+
9
+ ## 0.1.4
10
+
11
+ ### Patch Changes
12
+
13
+ - c4d64a9: fix api urls
14
+
3
15
  ## 0.1.3
4
16
 
5
17
  ### Patch Changes
package/dist/index.es.js CHANGED
@@ -7,12 +7,12 @@ async function b(s, e, t) {
7
7
  "X-Spot-Partner-Id": e
8
8
  },
9
9
  body: JSON.stringify(t)
10
- }), r = await o.json();
10
+ }), n = await o.json();
11
11
  if (!o.ok) {
12
- const n = new Error((r == null ? void 0 : r.message) || "Failed to fetch quote");
13
- throw n.status = o.status, n.responseBody = r, n;
12
+ const r = new Error((n == null ? void 0 : n.message) || "Failed to fetch quote");
13
+ throw r.status = o.status, r.responseBody = n, r;
14
14
  }
15
- return r;
15
+ return n;
16
16
  } catch (o) {
17
17
  throw o instanceof Error ? o : new Error("Unknown error occurred while fetching quote");
18
18
  }
@@ -26,8 +26,8 @@ function _(s) {
26
26
  apiConfig: e = {},
27
27
  quoteRequestData: t,
28
28
  callbacks: o = {},
29
- location: r,
30
- theme: n
29
+ location: n,
30
+ theme: r
31
31
  } = s, {
32
32
  environment: a = "sandbox",
33
33
  partnerId: p,
@@ -48,15 +48,16 @@ function _(s) {
48
48
  "productDuration",
49
49
  "productPrice",
50
50
  "productId",
51
+ "cartId",
51
52
  "productName"
52
- ].forEach((d) => {
53
- if (!Object.prototype.hasOwnProperty.call(t, d) || t[d] === void 0 || t[d] === null)
54
- throw new Error(`Missing required quoteRequestData field: '${d}'`);
53
+ ].forEach((c) => {
54
+ if (!Object.prototype.hasOwnProperty.call(t, c) || t[c] === void 0 || t[c] === null)
55
+ throw new Error(`Missing required quoteRequestData field: '${c}'`);
55
56
  });
56
- const c = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;
57
- if (!c.test(t.startDate))
57
+ const f = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;
58
+ if (!f.test(t.startDate))
58
59
  throw new Error("startDate must be a valid ISO8601 string");
59
- if (!c.test(t.endDate))
60
+ if (!f.test(t.endDate))
60
61
  throw new Error("endDate must be a valid ISO8601 string");
61
62
  if (typeof t.currencyCode != "string")
62
63
  throw new Error("currencyCode must be a string");
@@ -82,6 +83,8 @@ function _(s) {
82
83
  throw new Error("productPrice must be a valid number");
83
84
  if (typeof t.productId != "string")
84
85
  throw new Error("productId must be a string");
86
+ if (typeof t.cartId != "string")
87
+ throw new Error("cartId must be a string");
85
88
  if (typeof t.productName != "string")
86
89
  throw new Error("productName must be a string");
87
90
  if ([
@@ -90,20 +93,20 @@ function _(s) {
90
93
  "onQuoteRetrieved",
91
94
  "onError",
92
95
  "noMatchingQuote"
93
- ].forEach((d) => {
94
- const g = o[d];
96
+ ].forEach((c) => {
97
+ const g = o[c];
95
98
  if (g && typeof g != "function")
96
- throw new Error(`Callback '${d}' must be a function.`);
97
- }), typeof r == "string" && !document.querySelector(r))
98
- throw new Error(`Invalid location selector: '${r}'`);
99
- if (n && typeof n != "object")
99
+ throw new Error(`Callback '${c}' must be a function.`);
100
+ }), typeof n == "string" && !document.querySelector(n))
101
+ throw new Error(`Invalid location selector: '${n}'`);
102
+ if (r && typeof r != "object")
100
103
  throw new Error(
101
104
  "Theme must be an object with CSS variables, do not include the '--' prefix"
102
105
  );
103
106
  }
104
- function i(s, { text: e, className: t, parent: o, innerHTML: r } = {}) {
105
- const n = document.createElement(s);
106
- return t && (n.className = t), e != null && (n.textContent = e), r != null && (n.innerHTML = r), o && o.appendChild(n), n;
107
+ function i(s, { text: e, className: t, parent: o, innerHTML: n } = {}) {
108
+ const r = document.createElement(s);
109
+ return t && (r.className = t), e != null && (r.textContent = e), n != null && (r.innerHTML = n), o && o.appendChild(r), r;
107
110
  }
108
111
  function y(s, { name: e, description: t }) {
109
112
  i("div", {
@@ -122,12 +125,12 @@ function C(s, e = []) {
122
125
  parent: s
123
126
  });
124
127
  e.forEach((o) => {
125
- const r = i("li", { parent: t });
126
- r.innerHTML = `
128
+ const n = i("li", { parent: t });
129
+ n.innerHTML = `
127
130
  <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
128
131
  <path d="M11.6666 3.5L5.24998 9.91667L2.33331 7"
129
132
  stroke="#2E2E2E" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
130
- </svg>`, i("span", { text: o, parent: r });
133
+ </svg>`, i("span", { text: o, parent: n });
131
134
  });
132
135
  }
133
136
  function v(s, e = []) {
@@ -137,31 +140,31 @@ function v(s, e = []) {
137
140
  }), o = i("table", {
138
141
  className: "spot-refund__table spot-table--dynamic",
139
142
  parent: t
140
- }), r = i("thead", { parent: o }), n = i("tr", { parent: r });
141
- i("th", { text: "When you cancel", parent: n }), i("th", { text: "You will receive", parent: n });
143
+ }), n = i("thead", { parent: o }), r = i("tr", { parent: n });
144
+ i("th", { text: "When you cancel", parent: r }), i("th", { text: "You will receive", parent: r });
142
145
  const a = i("tbody", { parent: o });
143
- e.forEach(({ text: p, percent: l, amount: f }) => {
146
+ e.forEach(({ text: p, percent: l, amount: d }) => {
144
147
  const m = i("tr", { parent: a });
145
148
  i("td", { text: p, parent: m });
146
- const c = l === "Not eligible for refund" ? "Not eligible for a refund" : `$${f} refund`;
147
- i("td", { text: c, parent: m });
149
+ const f = l === "Not eligible for refund" ? "Not eligible for a refund" : `$${d} refund`;
150
+ i("td", { text: f, parent: m });
148
151
  });
149
152
  }
150
153
  function E(s, e, t) {
151
154
  const o = i("div", {
152
155
  className: "spot-selection__options",
153
156
  parent: s
154
- }), r = i("label", {
157
+ }), n = i("label", {
155
158
  className: `spot-selection__option ${t ? "selected" : ""}`,
156
159
  parent: o
157
- }), n = i("input", { parent: r });
158
- n.type = "radio", n.name = "selection", n.value = "yes", t && (n.checked = !0), i("strong", {
160
+ }), r = i("input", { parent: n });
161
+ r.type = "radio", r.name = "selection", r.value = "yes", t && (r.checked = !0), i("strong", {
159
162
  text: `Yes, protect my booking for $${e}`,
160
- parent: r
163
+ parent: n
161
164
  }), i("span", {
162
165
  className: "spot-selection__recommended-tag",
163
166
  text: "Recommended",
164
- parent: r
167
+ parent: n
165
168
  });
166
169
  const a = i("label", {
167
170
  className: "spot-selection__option",
@@ -186,11 +189,11 @@ function k(s, e) {
186
189
  text: "Refund Guarantee Terms and Conditions",
187
190
  parent: o
188
191
  });
189
- const r = i("p", {
192
+ const n = i("p", {
190
193
  className: "spot-footer__powered-by",
191
194
  parent: t
192
195
  });
193
- return r.innerHTML = `
196
+ return n.innerHTML = `
194
197
  <svg width="145" height="28" viewBox="0 0 145 28" fill="none" xmlns="http://www.w3.org/2000/svg">
195
198
  <rect width="145" height="28"/>
196
199
  <rect x="-655" y="-270" width="819" height="325" rx="10"/>
@@ -214,10 +217,10 @@ function H(s) {
214
217
  }
215
218
  H(x);
216
219
  const q = {
217
- sandbox: "https://api.sandbox.getspot.com/v1/quote",
218
- production: "https://api.getspot.com/v1/quote"
220
+ sandbox: "https://api.sandbox.getspot.com/api/v1/quote",
221
+ production: "https://api.getspot.com/api/v1/quote"
219
222
  };
220
- class S {
223
+ class I {
221
224
  constructor(e = {}) {
222
225
  this.options = {
223
226
  location: "body",
@@ -230,41 +233,42 @@ class S {
230
233
  }, 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();
231
234
  }
232
235
  async _init() {
236
+ var e, t, o, n;
233
237
  try {
234
238
  _(this.options);
235
239
  const {
236
- environment: e,
237
- partnerId: t,
238
- endpoint: o
239
- } = this.options.apiConfig, r = o || q[e], n = await b(
240
- r,
241
- t,
240
+ environment: r,
241
+ partnerId: a,
242
+ endpoint: p
243
+ } = this.options.apiConfig, l = p || q[r], d = await b(
244
+ l,
245
+ a,
242
246
  this.options.quoteRequestData
243
247
  );
244
- if (n.status !== "QUOTE_AVAILABLE") {
245
- n.status === "NO_MATCHING_QUOTE" && this.options.callbacks.noMatchingQuote({
248
+ if (d.status !== "QUOTE_AVAILABLE") {
249
+ d.status === "NO_MATCHING_QUOTE" && ((e = this.options.callbacks) != null && e.noMatchingQuote) && this.options.callbacks.noMatchingQuote({
246
250
  status: "NO_MATCHING_QUOTE",
247
251
  data: this.options.quoteRequestData
248
252
  });
249
253
  return;
250
254
  }
251
- this.quote = n.data, this._renderWidget(), this.options.optInSelected && this.options.callbacks.onOptIn && this.options.callbacks.onOptIn({
255
+ this.quote = d.data, this._renderWidget(), this.options.optInSelected && ((t = this.options.callbacks) != null && t.onOptIn) && this.options.callbacks.onOptIn({
252
256
  status: "QUOTE_ACCEPTED",
253
257
  spotPrice: this.quote.spotPrice,
254
258
  quoteId: this.quote.id
255
- }), this.options.callbacks.onQuoteRetrieved && this.options.callbacks.onQuoteRetrieved(this.quote);
256
- } catch (e) {
257
- this.options.callbacks.onError({
258
- message: e.message,
259
- status: e.status,
260
- responseBody: e.responseBody
259
+ }), (o = this.options.callbacks) != null && o.onQuoteRetrieved && this.options.callbacks.onQuoteRetrieved(this.quote);
260
+ } catch (r) {
261
+ (n = this.options.callbacks) == null || n.onError({
262
+ message: r.message,
263
+ status: r.status,
264
+ responseBody: r.responseBody
261
265
  });
262
266
  }
263
267
  }
264
268
  _renderWidget() {
265
- this.container = document.createElement("div"), this.container.className = "spot-refund-guarantee", this.root.appendChild(this.container), Object.entries(this.options.theme || {}).forEach(([o, r]) => {
266
- const n = `--${o}`;
267
- this.container.style.setProperty(n, r);
269
+ this.container = document.createElement("div"), this.container.className = "spot-refund-guarantee", this.root.appendChild(this.container), Object.entries(this.options.theme || {}).forEach(([o, n]) => {
270
+ const r = `--${o}`;
271
+ this.container.style.setProperty(r, n);
268
272
  }), y(this.container, this.quote.communication);
269
273
  const e = document.createElement("div");
270
274
  e.className = "spot-content__wrapper", this.container.appendChild(e), C(e, this.quote.communication.bulletPoints), this.options.showTable && v(e, this.quote.payoutSchedule);
@@ -281,15 +285,15 @@ class S {
281
285
  }
282
286
  _setupOptionListeners(e) {
283
287
  const t = e.querySelectorAll('input[type="radio"]'), o = e.querySelectorAll(".spot-selection__option");
284
- t.forEach((r) => {
285
- r.addEventListener("change", (n) => {
286
- var p;
287
- const a = n.target.value;
288
- this.hideSelectionError(), this.currentSelection = a, o.forEach((l) => l.classList.remove("selected")), (p = n.target.closest(".spot-selection__option")) == null || p.classList.add("selected"), a === "yes" && this.options.callbacks.onOptIn && this.options.callbacks.onOptIn({
288
+ t.forEach((n) => {
289
+ n.addEventListener("change", (r) => {
290
+ var p, l, d;
291
+ const a = r.target.value;
292
+ this.hideSelectionError(), this.currentSelection = a, o.forEach((m) => m.classList.remove("selected")), (p = r.target.closest(".spot-selection__option")) == null || p.classList.add("selected"), a === "yes" && ((l = this.options.callbacks) != null && l.onOptIn) && this.options.callbacks.onOptIn({
289
293
  status: "QUOTE_ACCEPTED",
290
294
  spotPrice: this.quote.spotPrice,
291
295
  quoteId: this.quote.id
292
- }), a === "no" && this.options.callbacks.onOptOut && this.options.callbacks.onOptOut({
296
+ }), a === "no" && ((d = this.options.callbacks) != null && d.onOptOut) && this.options.callbacks.onOptOut({
293
297
  status: "QUOTE_DECLINED",
294
298
  quoteId: this.quote.id
295
299
  });
@@ -331,5 +335,5 @@ class S {
331
335
  }
332
336
  }
333
337
  export {
334
- S as default
338
+ I as default
335
339
  };
package/dist/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
- (function(l,c){typeof exports=="object"&&typeof module<"u"?module.exports=c():typeof define=="function"&&define.amd?define(c):(l=typeof globalThis<"u"?globalThis:l||self,l.SpotWidget=c())})(this,function(){"use strict";async function l(s,e,t){try{const o=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json","X-Spot-Partner-Id":e},body:JSON.stringify(t)}),n=await o.json();if(!o.ok){const i=new Error((n==null?void 0:n.message)||"Failed to fetch quote");throw i.status=o.status,i.responseBody=n,i}return n}catch(o){throw o instanceof Error?o:new Error("Unknown error occurred while fetching quote")}}const c={sandbox:"https://api.sandbox.getspot.com/v1/quote",production:"https://api.getspot.com/v1/quote"};function _(s){const{apiConfig:e={},quoteRequestData:t,callbacks:o={},location:n,theme:i}=s,{environment:a="sandbox",partnerId:p,endpoint:f}=e;if(!p||typeof p!="string")throw new Error("Invalid or missing partnerId in apiConfig");if(!(f||c[a]))throw new Error(`Invalid environment in apiConfig: ${a}`);if(!t||typeof t!="object")throw new Error("quoteRequestData must be a non-null object");["startDate","endDate","currencyCode","eventType","productType","productDuration","productPrice","productId","productName"].forEach(d=>{if(!Object.prototype.hasOwnProperty.call(t,d)||t[d]===void 0||t[d]===null)throw new Error(`Missing required quoteRequestData field: '${d}'`)});const m=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;if(!m.test(t.startDate))throw new Error("startDate must be a valid ISO8601 string");if(!m.test(t.endDate))throw new Error("endDate must be a valid ISO8601 string");if(typeof t.currencyCode!="string")throw new Error("currencyCode must be a string");if(!["USD","CAD","AUD"].includes(t.currencyCode))throw new Error(`Invalid currency code: ${t.currencyCode}`);if(typeof t.eventType!="string")throw new Error("eventType must be a string");if(typeof t.productType!="string")throw new Error("productType must be a string");const g=["Pass","Trip","Registration"];if(!g.includes(t.productType))throw new Error(`productType must be one of ${g.join(", ")}`);if(typeof t.productDuration!="string")throw new Error("productDuration must be a string");const b=["Daily","Seasonal","Trip","Event"];if(!b.includes(t.productDuration))throw new Error(`productDuration must be one of ${b.join(", ")}`);if(typeof t.productPrice!="number"||isNaN(t.productPrice))throw new Error("productPrice must be a valid number");if(typeof t.productId!="string")throw new Error("productId must be a string");if(typeof t.productName!="string")throw new Error("productName must be a string");if(["onOptIn","onOptOut","onQuoteRetrieved","onError","noMatchingQuote"].forEach(d=>{const w=o[d];if(w&&typeof w!="function")throw new Error(`Callback '${d}' must be a function.`)}),typeof n=="string"&&!document.querySelector(n))throw new Error(`Invalid location selector: '${n}'`);if(i&&typeof i!="object")throw new Error("Theme must be an object with CSS variables, do not include the '--' prefix")}function r(s,{text:e,className:t,parent:o,innerHTML:n}={}){const i=document.createElement(s);return t&&(i.className=t),e!=null&&(i.textContent=e),n!=null&&(i.innerHTML=n),o&&o.appendChild(i),i}function y(s,{name:e,description:t}){r("div",{className:"spot-header__title",text:e,parent:s}),r("div",{className:"spot-header__description",text:t,parent:s})}function C(s,e=[]){const t=r("ul",{className:"spot-benefits__list",parent:s});e.forEach(o=>{const n=r("li",{parent:t});n.innerHTML=`
1
+ (function(f,m){typeof exports=="object"&&typeof module<"u"?module.exports=m():typeof define=="function"&&define.amd?define(m):(f=typeof globalThis<"u"?globalThis:f||self,f.SpotWidget=m())})(this,function(){"use strict";async function f(s,e,t){try{const o=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json","X-Spot-Partner-Id":e},body:JSON.stringify(t)}),n=await o.json();if(!o.ok){const r=new Error((n==null?void 0:n.message)||"Failed to fetch quote");throw r.status=o.status,r.responseBody=n,r}return n}catch(o){throw o instanceof Error?o:new Error("Unknown error occurred while fetching quote")}}const m={sandbox:"https://api.sandbox.getspot.com/v1/quote",production:"https://api.getspot.com/v1/quote"};function _(s){const{apiConfig:e={},quoteRequestData:t,callbacks:o={},location:n,theme:r}=s,{environment:a="sandbox",partnerId:p,endpoint:l}=e;if(!p||typeof p!="string")throw new Error("Invalid or missing partnerId in apiConfig");if(!(l||m[a]))throw new Error(`Invalid environment in apiConfig: ${a}`);if(!t||typeof t!="object")throw new Error("quoteRequestData must be a non-null object");["startDate","endDate","currencyCode","eventType","productType","productDuration","productPrice","productId","cartId","productName"].forEach(c=>{if(!Object.prototype.hasOwnProperty.call(t,c)||t[c]===void 0||t[c]===null)throw new Error(`Missing required quoteRequestData field: '${c}'`)});const h=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;if(!h.test(t.startDate))throw new Error("startDate must be a valid ISO8601 string");if(!h.test(t.endDate))throw new Error("endDate must be a valid ISO8601 string");if(typeof t.currencyCode!="string")throw new Error("currencyCode must be a string");if(!["USD","CAD","AUD"].includes(t.currencyCode))throw new Error(`Invalid currency code: ${t.currencyCode}`);if(typeof t.eventType!="string")throw new Error("eventType must be a string");if(typeof t.productType!="string")throw new Error("productType must be a string");const g=["Pass","Trip","Registration"];if(!g.includes(t.productType))throw new Error(`productType must be one of ${g.join(", ")}`);if(typeof t.productDuration!="string")throw new Error("productDuration must be a string");const b=["Daily","Seasonal","Trip","Event"];if(!b.includes(t.productDuration))throw new Error(`productDuration must be one of ${b.join(", ")}`);if(typeof t.productPrice!="number"||isNaN(t.productPrice))throw new Error("productPrice must be a valid number");if(typeof t.productId!="string")throw new Error("productId must be a string");if(typeof t.cartId!="string")throw new Error("cartId must be a string");if(typeof t.productName!="string")throw new Error("productName must be a string");if(["onOptIn","onOptOut","onQuoteRetrieved","onError","noMatchingQuote"].forEach(c=>{const w=o[c];if(w&&typeof w!="function")throw new Error(`Callback '${c}' must be a function.`)}),typeof n=="string"&&!document.querySelector(n))throw new Error(`Invalid location selector: '${n}'`);if(r&&typeof r!="object")throw new Error("Theme must be an object with CSS variables, do not include the '--' prefix")}function i(s,{text:e,className:t,parent:o,innerHTML:n}={}){const r=document.createElement(s);return t&&(r.className=t),e!=null&&(r.textContent=e),n!=null&&(r.innerHTML=n),o&&o.appendChild(r),r}function y(s,{name:e,description:t}){i("div",{className:"spot-header__title",text:e,parent:s}),i("div",{className:"spot-header__description",text:t,parent:s})}function C(s,e=[]){const t=i("ul",{className:"spot-benefits__list",parent:s});e.forEach(o=>{const n=i("li",{parent:t});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>`,r("span",{text:o,parent:n})})}function v(s,e=[]){const t=r("div",{className:"spot-table__container",parent:s}),o=r("table",{className:"spot-refund__table spot-table--dynamic",parent:t}),n=r("thead",{parent:o}),i=r("tr",{parent:n});r("th",{text:"When you cancel",parent:i}),r("th",{text:"You will receive",parent:i});const a=r("tbody",{parent:o});e.forEach(({text:p,percent:f,amount:h})=>{const u=r("tr",{parent:a});r("td",{text:p,parent:u});const m=f==="Not eligible for refund"?"Not eligible for a refund":`$${h} refund`;r("td",{text:m,parent:u})})}function E(s,e,t){const o=r("div",{className:"spot-selection__options",parent:s}),n=r("label",{className:`spot-selection__option ${t?"selected":""}`,parent:o}),i=r("input",{parent:n});i.type="radio",i.name="selection",i.value="yes",t&&(i.checked=!0),r("strong",{text:`Yes, protect my booking for $${e}`,parent:n}),r("span",{className:"spot-selection__recommended-tag",text:"Recommended",parent:n});const a=r("label",{className:"spot-selection__option",parent:o}),p=r("input",{parent:a});return p.type="radio",p.name="selection",p.value="no",r("span",{text:"No, do not protect my booking",parent:a}),o}function k(s,e){const t=r("div",{className:"spot-footer__container",parent:s}),o=r("div",{className:"spot-footer__terms",parent:t});r("span",{innerHTML:e.communication.legalDisclaimer,parent:o}),r("br",{parent:o}),r("a",{href:e.communication.termsAndConditionsUrl,className:"spot-footer__terms-link",text:"Refund Guarantee Terms and Conditions",parent:o});const n=r("p",{className:"spot-footer__powered-by",parent:t});return n.innerHTML=`
5
+ </svg>`,i("span",{text:o,parent:n})})}function v(s,e=[]){const t=i("div",{className:"spot-table__container",parent:s}),o=i("table",{className:"spot-refund__table spot-table--dynamic",parent:t}),n=i("thead",{parent:o}),r=i("tr",{parent:n});i("th",{text:"When you cancel",parent:r}),i("th",{text:"You will receive",parent:r});const a=i("tbody",{parent:o});e.forEach(({text:p,percent:l,amount:d})=>{const u=i("tr",{parent:a});i("td",{text:p,parent:u});const h=l==="Not eligible for refund"?"Not eligible for a refund":`$${d} refund`;i("td",{text:h,parent:u})})}function E(s,e,t){const o=i("div",{className:"spot-selection__options",parent:s}),n=i("label",{className:`spot-selection__option ${t?"selected":""}`,parent:o}),r=i("input",{parent:n});r.type="radio",r.name="selection",r.value="yes",t&&(r.checked=!0),i("strong",{text:`Yes, protect my booking for $${e}`,parent:n}),i("span",{className:"spot-selection__recommended-tag",text:"Recommended",parent:n});const a=i("label",{className:"spot-selection__option",parent:o}),p=i("input",{parent:a});return p.type="radio",p.name="selection",p.value="no",i("span",{text:"No, do not protect my booking",parent:a}),o}function k(s,e){const t=i("div",{className:"spot-footer__container",parent:s}),o=i("div",{className:"spot-footer__terms",parent:t});i("span",{innerHTML:e.communication.legalDisclaimer,parent:o}),i("br",{parent:o}),i("a",{href:e.communication.termsAndConditionsUrl,className:"spot-footer__terms-link",text:"Refund Guarantee Terms and Conditions",parent:o});const n=i("p",{className:"spot-footer__powered-by",parent:t});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>`,t}const x=":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-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-selection__options{grid-row:2}.desktop-layout .spot-table__container{grid-row:1 / span 2}}@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-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-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 H(s){const e=document.createElement("style");e.textContent=s,document.head.appendChild(e)}H(x);const q={sandbox:"https://api.sandbox.getspot.com/v1/quote",production:"https://api.getspot.com/v1/quote"};class T{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(){try{_(this.options);const{environment:e,partnerId:t,endpoint:o}=this.options.apiConfig,n=o||q[e],i=await l(n,t,this.options.quoteRequestData);if(i.status!=="QUOTE_AVAILABLE"){i.status==="NO_MATCHING_QUOTE"&&this.options.callbacks.noMatchingQuote({status:"NO_MATCHING_QUOTE",data:this.options.quoteRequestData});return}this.quote=i.data,this._renderWidget(),this.options.optInSelected&&this.options.callbacks.onOptIn&&this.options.callbacks.onOptIn({status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id}),this.options.callbacks.onQuoteRetrieved&&this.options.callbacks.onQuoteRetrieved(this.quote)}catch(e){this.options.callbacks.onError({message:e.message,status:e.status,responseBody:e.responseBody})}}_renderWidget(){this.container=document.createElement("div"),this.container.className="spot-refund-guarantee",this.root.appendChild(this.container),Object.entries(this.options.theme||{}).forEach(([o,n])=>{const i=`--${o}`;this.container.style.setProperty(i,n)}),y(this.container,this.quote.communication);const e=document.createElement("div");e.className="spot-content__wrapper",this.container.appendChild(e),C(e,this.quote.communication.bulletPoints),this.options.showTable&&v(e,this.quote.payoutSchedule);const t=E(e,this.quote.spotPrice,this.options.optInSelected);e.appendChild(t),k(this.container,this.quote),window.addEventListener("resize",this._onResize),this._updateLayout(),this._setupOptionListeners(t)}_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 t=e.querySelectorAll('input[type="radio"]'),o=e.querySelectorAll(".spot-selection__option");t.forEach(n=>{n.addEventListener("change",i=>{var p;const a=i.target.value;this.hideSelectionError(),this.currentSelection=a,o.forEach(f=>f.classList.remove("selected")),(p=i.target.closest(".spot-selection__option"))==null||p.classList.add("selected"),a==="yes"&&this.options.callbacks.onOptIn&&this.options.callbacks.onOptIn({status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id}),a==="no"&&this.options.callbacks.onOptOut&&this.options.callbacks.onOptOut({status:"QUOTE_DECLINED",quoteId:this.quote.id})})})}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 t=(e=this.container)==null?void 0:e.querySelector(".spot-selection__options");t&&t.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}getSelection(){var e,t;return this.currentSelection==null?null:{selection:this.currentSelection,quoteId:(e=this.quote)==null?void 0:e.id,spotPrice:(t=this.quote)==null?void 0:t.spotPrice,status:this.currentSelection==="yes"?"QUOTE_ACCEPTED":"QUOTE_DECLINED"}}destroy(){window.removeEventListener("resize",this._onResize),this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container)}}return T});
20
+ </svg>`,t}const x=":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-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-selection__options{grid-row:2}.desktop-layout .spot-table__container{grid-row:1 / span 2}}@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-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-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 H(s){const e=document.createElement("style");e.textContent=s,document.head.appendChild(e)}H(x);const q={sandbox:"https://api.sandbox.getspot.com/api/v1/quote",production:"https://api.getspot.com/api/v1/quote"};class T{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,t,o,n;try{_(this.options);const{environment:r,partnerId:a,endpoint:p}=this.options.apiConfig,l=p||q[r],d=await f(l,a,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}this.quote=d.data,this._renderWidget(),this.options.optInSelected&&((t=this.options.callbacks)!=null&&t.onOptIn)&&this.options.callbacks.onOptIn({status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id}),(o=this.options.callbacks)!=null&&o.onQuoteRetrieved&&this.options.callbacks.onQuoteRetrieved(this.quote)}catch(r){(n=this.options.callbacks)==null||n.onError({message:r.message,status:r.status,responseBody:r.responseBody})}}_renderWidget(){this.container=document.createElement("div"),this.container.className="spot-refund-guarantee",this.root.appendChild(this.container),Object.entries(this.options.theme||{}).forEach(([o,n])=>{const r=`--${o}`;this.container.style.setProperty(r,n)}),y(this.container,this.quote.communication);const e=document.createElement("div");e.className="spot-content__wrapper",this.container.appendChild(e),C(e,this.quote.communication.bulletPoints),this.options.showTable&&v(e,this.quote.payoutSchedule);const t=E(e,this.quote.spotPrice,this.options.optInSelected);e.appendChild(t),k(this.container,this.quote),window.addEventListener("resize",this._onResize),this._updateLayout(),this._setupOptionListeners(t)}_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 t=e.querySelectorAll('input[type="radio"]'),o=e.querySelectorAll(".spot-selection__option");t.forEach(n=>{n.addEventListener("change",r=>{var p,l,d;const a=r.target.value;this.hideSelectionError(),this.currentSelection=a,o.forEach(u=>u.classList.remove("selected")),(p=r.target.closest(".spot-selection__option"))==null||p.classList.add("selected"),a==="yes"&&((l=this.options.callbacks)!=null&&l.onOptIn)&&this.options.callbacks.onOptIn({status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id}),a==="no"&&((d=this.options.callbacks)!=null&&d.onOptOut)&&this.options.callbacks.onOptOut({status:"QUOTE_DECLINED",quoteId:this.quote.id})})})}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 t=(e=this.container)==null?void 0:e.querySelector(".spot-selection__options");t&&t.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}getSelection(){var e,t;return this.currentSelection==null?null:{selection:this.currentSelection,quoteId:(e=this.quote)==null?void 0:e.id,spotPrice:(t=this.quote)==null?void 0:t.spotPrice,status:this.currentSelection==="yes"?"QUOTE_ACCEPTED":"QUOTE_DECLINED"}}destroy(){window.removeEventListener("resize",this._onResize),this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container)}}return T});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getspot/spot-widget",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/index.js CHANGED
@@ -19,8 +19,8 @@ function injectStyles(css) {
19
19
  injectStyles(styles);
20
20
 
21
21
  const apiEndpoint = {
22
- sandbox: "https://api.sandbox.getspot.com/v1/quote",
23
- production: "https://api.getspot.com/v1/quote",
22
+ sandbox: "https://api.sandbox.getspot.com/api/v1/quote",
23
+ production: "https://api.getspot.com/api/v1/quote",
24
24
  };
25
25
 
26
26
  class SpotWidget {
@@ -63,7 +63,10 @@ class SpotWidget {
63
63
  );
64
64
 
65
65
  if (response.status !== "QUOTE_AVAILABLE") {
66
- if (response.status === "NO_MATCHING_QUOTE") {
66
+ if (
67
+ response.status === "NO_MATCHING_QUOTE" &&
68
+ this.options.callbacks?.noMatchingQuote
69
+ ) {
67
70
  this.options.callbacks.noMatchingQuote({
68
71
  status: "NO_MATCHING_QUOTE",
69
72
  data: this.options.quoteRequestData,
@@ -75,7 +78,7 @@ class SpotWidget {
75
78
  this.quote = response.data;
76
79
  this._renderWidget();
77
80
 
78
- if (this.options.optInSelected && this.options.callbacks.onOptIn) {
81
+ if (this.options.optInSelected && this.options.callbacks?.onOptIn) {
79
82
  this.options.callbacks.onOptIn({
80
83
  status: "QUOTE_ACCEPTED",
81
84
  spotPrice: this.quote.spotPrice,
@@ -83,11 +86,11 @@ class SpotWidget {
83
86
  });
84
87
  }
85
88
 
86
- if (this.options.callbacks.onQuoteRetrieved) {
89
+ if (this.options.callbacks?.onQuoteRetrieved) {
87
90
  this.options.callbacks.onQuoteRetrieved(this.quote);
88
91
  }
89
92
  } catch (err) {
90
- this.options.callbacks.onError({
93
+ this.options.callbacks?.onError({
91
94
  message: err.message,
92
95
  status: err.status,
93
96
  responseBody: err.responseBody,
@@ -147,14 +150,14 @@ class SpotWidget {
147
150
  options.forEach((label) => label.classList.remove("selected"));
148
151
  e.target.closest(".spot-selection__option")?.classList.add("selected");
149
152
 
150
- if (val === "yes" && this.options.callbacks.onOptIn) {
153
+ if (val === "yes" && this.options.callbacks?.onOptIn) {
151
154
  this.options.callbacks.onOptIn({
152
155
  status: "QUOTE_ACCEPTED",
153
156
  spotPrice: this.quote.spotPrice,
154
157
  quoteId: this.quote.id,
155
158
  });
156
159
  }
157
- if (val === "no" && this.options.callbacks.onOptOut) {
160
+ if (val === "no" && this.options.callbacks?.onOptOut) {
158
161
  this.options.callbacks.onOptOut({
159
162
  status: "QUOTE_DECLINED",
160
163
  quoteId: this.quote.id,
@@ -41,6 +41,7 @@ export function validateOptions(options) {
41
41
  "productDuration",
42
42
  "productPrice",
43
43
  "productId",
44
+ "cartId",
44
45
  "productName",
45
46
  ];
46
47
 
@@ -108,6 +109,10 @@ export function validateOptions(options) {
108
109
  throw new Error("productId must be a string");
109
110
  }
110
111
 
112
+ if (typeof quoteRequestData.cartId !== "string") {
113
+ throw new Error("cartId must be a string");
114
+ }
115
+
111
116
  if (typeof quoteRequestData.productName !== "string") {
112
117
  throw new Error("productName must be a string");
113
118
  }