@getspot/spot-widget 0.2.0 → 1.1.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,13 +1,13 @@
1
1
 
2
- > @getspot/spot-widget@0.2.0 build /builds/getspot/spot-widget/packages/core
2
+ > @getspot/spot-widget@1.1.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.
6
- vite v5.4.18 building for production...
6
+ vite v5.4.19 building for production...
7
7
  transforming...
8
8
  ✓ 5 modules transformed.
9
9
  rendering chunks...
10
10
  computing gzip size...
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
11
+ dist/index.umd.js 24.52 kB │ gzip: 7.49 kB
12
+ dist/index.es.js 27.03 kB │ gzip: 7.77 kB
13
+ ✓ built in 164ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @getspot/spot-widget
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 9574bc9: add payment terms
8
+
9
+ ## 1.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - 4f9e10e: First major release of all the widget variants.
14
+
15
+ This is really a major release for the sake of having our first major bump. The package is now ready for external use.
16
+
17
+ Includes updated functionality for updating quotes.
18
+
3
19
  ## 0.2.0
4
20
 
5
21
  ### Minor Changes
package/dist/index.es.js CHANGED
@@ -1,6 +1,6 @@
1
- async function b(s, e, t) {
1
+ async function b(i, e, t) {
2
2
  try {
3
- const o = await fetch(s, {
3
+ const o = await fetch(i, {
4
4
  method: "POST",
5
5
  headers: {
6
6
  "Content-Type": "application/json",
@@ -17,25 +17,25 @@ async function b(s, e, t) {
17
17
  throw o instanceof Error ? o : new Error("Unknown error occurred while fetching quote");
18
18
  }
19
19
  }
20
- const w = {
20
+ const v = {
21
21
  sandbox: "https://api.sandbox.getspot.com/v1/quote",
22
22
  production: "https://api.getspot.com/v1/quote"
23
23
  };
24
- function _(s) {
24
+ function y(i) {
25
25
  const {
26
26
  apiConfig: e = {},
27
27
  quoteRequestData: t,
28
28
  callbacks: o = {},
29
29
  location: n,
30
30
  theme: r
31
- } = s, {
31
+ } = i, {
32
32
  environment: a = "sandbox",
33
33
  partnerId: p,
34
- endpoint: l
34
+ endpoint: c
35
35
  } = e;
36
36
  if (!p || typeof p != "string")
37
37
  throw new Error("Invalid or missing partnerId in apiConfig");
38
- if (!(l || w[a]))
38
+ if (!(c || v[a]))
39
39
  throw new Error(`Invalid environment in apiConfig: ${a}`);
40
40
  if (!t || typeof t != "object")
41
41
  throw new Error("quoteRequestData must be a non-null object");
@@ -50,14 +50,14 @@ function _(s) {
50
50
  "productId",
51
51
  "cartId",
52
52
  "productName"
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}'`);
53
+ ].forEach((m) => {
54
+ if (!Object.prototype.hasOwnProperty.call(t, m) || t[m] === void 0 || t[m] === null)
55
+ throw new Error(`Missing required quoteRequestData field: '${m}'`);
56
56
  });
57
- const f = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;
58
- if (!f.test(t.startDate))
57
+ const u = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;
58
+ if (!u.test(t.startDate))
59
59
  throw new Error("startDate must be a valid ISO8601 string");
60
- if (!f.test(t.endDate))
60
+ if (!u.test(t.endDate))
61
61
  throw new Error("endDate must be a valid ISO8601 string");
62
62
  if (typeof t.currencyCode != "string")
63
63
  throw new Error("currencyCode must be a string");
@@ -67,10 +67,10 @@ function _(s) {
67
67
  throw new Error("eventType must be a string");
68
68
  if (typeof t.productType != "string")
69
69
  throw new Error("productType must be a string");
70
- const u = ["Pass", "Trip", "Registration"];
71
- if (!u.includes(t.productType))
70
+ const f = ["Pass", "Trip", "Registration"];
71
+ if (!f.includes(t.productType))
72
72
  throw new Error(
73
- `productType must be one of ${u.join(", ")}`
73
+ `productType must be one of ${f.join(", ")}`
74
74
  );
75
75
  if (typeof t.productDuration != "string")
76
76
  throw new Error("productDuration must be a string");
@@ -93,10 +93,10 @@ function _(s) {
93
93
  "onQuoteRetrieved",
94
94
  "onError",
95
95
  "noMatchingQuote"
96
- ].forEach((c) => {
97
- const g = o[c];
96
+ ].forEach((m) => {
97
+ const g = o[m];
98
98
  if (g && typeof g != "function")
99
- throw new Error(`Callback '${c}' must be a function.`);
99
+ throw new Error(`Callback '${m}' must be a function.`);
100
100
  }), typeof n == "string" && !document.querySelector(n))
101
101
  throw new Error(`Invalid location selector: '${n}'`);
102
102
  if (r && typeof r != "object")
@@ -104,92 +104,108 @@ function _(s) {
104
104
  "Theme must be an object with CSS variables, do not include the '--' prefix"
105
105
  );
106
106
  }
107
- function i(s, { text: e, className: t, parent: o, innerHTML: n } = {}) {
108
- const r = document.createElement(s);
107
+ function s(i, { text: e, className: t, parent: o, innerHTML: n } = {}) {
108
+ const r = document.createElement(i);
109
109
  return t && (r.className = t), e != null && (r.textContent = e), n != null && (r.innerHTML = n), o && o.appendChild(r), r;
110
110
  }
111
- function y(s, { name: e, description: t }) {
112
- i("div", {
111
+ function w(i, { name: e, description: t }) {
112
+ s("div", {
113
113
  className: "spot-header__title",
114
114
  text: e,
115
- parent: s
116
- }), i("div", {
115
+ parent: i
116
+ }), s("div", {
117
117
  className: "spot-header__description",
118
118
  text: t,
119
- parent: s
119
+ parent: i
120
120
  });
121
121
  }
122
- function C(s, e = []) {
123
- const t = i("ul", {
122
+ function C(i, e = []) {
123
+ const t = s("ul", {
124
124
  className: "spot-benefits__list",
125
- parent: s
125
+ parent: i
126
126
  });
127
127
  e.forEach((o) => {
128
- const n = i("li", { parent: t });
128
+ const n = s("li", { parent: t });
129
129
  n.innerHTML = `
130
130
  <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
131
131
  <path d="M11.6666 3.5L5.24998 9.91667L2.33331 7"
132
132
  stroke="#2E2E2E" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
133
- </svg>`, i("span", { text: o, parent: n });
133
+ </svg>`, s("span", { text: o, parent: n });
134
134
  });
135
135
  }
136
- function v(s, e = []) {
137
- const t = i("div", {
136
+ function E(i, e = []) {
137
+ const t = s("div", {
138
138
  className: "spot-table__container",
139
- parent: s
140
- }), o = i("table", {
139
+ parent: i
140
+ }), o = s("table", {
141
141
  className: "spot-refund__table spot-table--dynamic",
142
142
  parent: t
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 });
145
- const a = i("tbody", { parent: o });
146
- e.forEach(({ text: p, percent: l, amount: d }) => {
147
- const m = i("tr", { parent: a });
148
- i("td", { text: p, parent: m });
149
- const f = l === "Not eligible for refund" ? "Not eligible for a refund" : `$${d} refund`;
150
- i("td", { text: f, parent: m });
143
+ }), n = s("thead", { parent: o }), r = s("tr", { parent: n });
144
+ s("th", { text: "When you cancel", parent: r }), s("th", { text: "You will receive", parent: r });
145
+ const a = s("tbody", { parent: o });
146
+ e.forEach(({ text: p, percent: c, amount: l }) => {
147
+ const d = s("tr", { parent: a });
148
+ s("td", { text: p, parent: d });
149
+ const u = c === "Not eligible for refund" ? "Not eligible for a refund" : `$${l} refund`;
150
+ s("td", { text: u, parent: d });
151
151
  });
152
152
  }
153
- function E(s, e, t) {
154
- const o = i("div", {
153
+ function k(i, e, t) {
154
+ const o = s("div", {
155
155
  className: "spot-selection__options",
156
- parent: s
157
- }), n = i("label", {
156
+ parent: i
157
+ }), n = s("label", {
158
158
  className: `spot-selection__option ${t ? "selected" : ""}`,
159
159
  parent: o
160
- }), r = i("input", { parent: n });
161
- r.type = "radio", r.name = "selection", r.value = "yes", t && (r.checked = !0), i("strong", {
160
+ }), r = s("input", { parent: n });
161
+ r.type = "radio", r.name = "selection", r.value = "yes", t && (r.checked = !0), s("strong", {
162
162
  text: `Yes, protect my booking for $${e}`,
163
163
  parent: n
164
- }), i("span", {
164
+ }), s("span", {
165
165
  className: "spot-selection__recommended-tag",
166
166
  text: "Recommended",
167
167
  parent: n
168
168
  });
169
- const a = i("label", {
169
+ const a = s("label", {
170
170
  className: "spot-selection__option",
171
171
  parent: o
172
- }), p = i("input", { parent: a });
173
- return p.type = "radio", p.name = "selection", p.value = "no", i("span", { text: "No, do not protect my booking", parent: a }), o;
172
+ }), p = s("input", { parent: a });
173
+ return p.type = "radio", p.name = "selection", p.value = "no", s("span", { text: "No, do not protect my booking", parent: a }), o;
174
174
  }
175
- function k(s, e) {
176
- const t = i("div", {
175
+ function q(i, e) {
176
+ var n;
177
+ const t = (n = e.communication) == null ? void 0 : n.paymentTerms, o = s("div", {
178
+ className: "spot-payment-terms",
179
+ parent: i
180
+ });
181
+ return s("div", {
182
+ className: "spot-payment-terms__header",
183
+ text: "PAYMENT TERMS",
184
+ parent: o
185
+ }), s("div", {
186
+ className: "spot-payment-terms__body",
187
+ text: t,
188
+ parent: o
189
+ }), o;
190
+ }
191
+ function x(i, e) {
192
+ const t = s("div", {
177
193
  className: "spot-footer__container",
178
- parent: s
179
- }), o = i("div", {
194
+ parent: i
195
+ }), o = s("div", {
180
196
  className: "spot-footer__terms",
181
197
  parent: t
182
198
  });
183
- i("span", {
199
+ s("span", {
184
200
  innerHTML: e.communication.legalDisclaimer,
185
201
  parent: o
186
- }), i("br", { parent: o }), i("a", {
202
+ }), s("br", { parent: o }), s("a", {
187
203
  href: e.communication.termsAndConditionsUrl,
188
204
  className: "spot-footer__terms-link",
189
205
  text: "Refund Guarantee Terms and Conditions",
190
206
  parent: o
191
207
  });
192
- const n = i("p", {
208
+ const n = s("p", {
193
209
  className: "spot-footer__powered-by",
194
210
  parent: t
195
211
  });
@@ -210,17 +226,17 @@ function k(s, e) {
210
226
  </defs>
211
227
  </svg>`, t;
212
228
  }
213
- 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}";
214
- function H(s) {
229
+ const T = ":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-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-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}";
230
+ function H(i) {
215
231
  const e = document.createElement("style");
216
- e.textContent = s, document.head.appendChild(e);
232
+ e.textContent = i, document.head.appendChild(e);
217
233
  }
218
- H(x);
219
- const q = {
234
+ H(T);
235
+ const _ = {
220
236
  sandbox: "https://api.sandbox.getspot.com/api/v1/quote",
221
237
  production: "https://api.getspot.com/api/v1/quote"
222
238
  };
223
- class I {
239
+ class M {
224
240
  constructor(e = {}) {
225
241
  this.options = {
226
242
  location: "body",
@@ -233,16 +249,12 @@ class I {
233
249
  }, 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();
234
250
  }
235
251
  async _init() {
236
- var e, t, o, n;
252
+ var e, t, o, n, r;
237
253
  try {
238
- _(this.options);
239
- const {
240
- environment: r,
241
- partnerId: a,
242
- endpoint: p
243
- } = this.options.apiConfig, l = p || q[r], d = await b(
254
+ y(this.options);
255
+ const { environment: a, partnerId: p } = this.options.apiConfig, l = this.options.apiConfig.customEndpoint || _[a], d = await b(
244
256
  l,
245
- a,
257
+ p,
246
258
  this.options.quoteRequestData
247
259
  );
248
260
  if (d.status !== "QUOTE_AVAILABLE") {
@@ -257,27 +269,30 @@ class I {
257
269
  spotPrice: this.quote.spotPrice,
258
270
  quoteId: this.quote.id
259
271
  }), (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
265
- });
272
+ } catch (a) {
273
+ (n = this.options.callbacks) != null && n.onError && ((r = this.options.callbacks) == null || r.onError({
274
+ message: a.message,
275
+ status: a.status,
276
+ responseBody: a.responseBody
277
+ }));
266
278
  }
267
279
  }
268
280
  _renderWidget() {
269
281
  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
282
  const r = `--${o}`;
271
283
  this.container.style.setProperty(r, n);
272
- }), y(this.container, this.quote.communication);
284
+ }), w(this.container, this.quote.communication);
273
285
  const e = document.createElement("div");
274
- e.className = "spot-content__wrapper", this.container.appendChild(e), C(e, this.quote.communication.bulletPoints), this.options.showTable && v(e, this.quote.payoutSchedule);
275
- const t = E(
286
+ e.className = "spot-content__wrapper", this.container.appendChild(e), C(e, this.quote.communication.bulletPoints), this.options.showTable && E(e, this.quote.payoutSchedule);
287
+ const t = k(
276
288
  e,
277
289
  this.quote.spotPrice,
278
290
  this.options.optInSelected
279
291
  );
280
- e.appendChild(t), k(this.container, this.quote), window.addEventListener("resize", this._onResize), this._updateLayout(), this._setupOptionListeners(t);
292
+ e.appendChild(t), this.paymentTermsEl = s("div", {
293
+ className: "spot-payment-terms__wrapper",
294
+ parent: e
295
+ }), x(this.container, this.quote), window.addEventListener("resize", this._onResize), this._updateLayout(), this._setupOptionListeners(t);
281
296
  }
282
297
  _updateLayout() {
283
298
  const e = window.matchMedia("(min-width: 768px)").matches;
@@ -287,13 +302,13 @@ class I {
287
302
  const t = e.querySelectorAll('input[type="radio"]'), o = e.querySelectorAll(".spot-selection__option");
288
303
  t.forEach((n) => {
289
304
  n.addEventListener("change", (r) => {
290
- var p, l, d;
305
+ var p, c, l;
291
306
  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({
307
+ this.hideSelectionError(), this.currentSelection = a, o.forEach((d) => d.classList.remove("selected")), (p = r.target.closest(".spot-selection__option")) == null || p.classList.add("selected"), this.paymentTermsEl && (this.paymentTermsEl.innerHTML = ""), a === "yes" && (this.options.quoteRequestData.isPartialPayment && q(this.paymentTermsEl, this.quote), (c = this.options.callbacks) != null && c.onOptIn && this.options.callbacks.onOptIn({
293
308
  status: "QUOTE_ACCEPTED",
294
309
  spotPrice: this.quote.spotPrice,
295
310
  quoteId: this.quote.id
296
- }), a === "no" && ((d = this.options.callbacks) != null && d.onOptOut) && this.options.callbacks.onOptOut({
311
+ })), a === "no" && ((l = this.options.callbacks) != null && l.onOptOut) && this.options.callbacks.onOptOut({
297
312
  status: "QUOTE_DECLINED",
298
313
  quoteId: this.quote.id
299
314
  });
@@ -321,6 +336,38 @@ class I {
321
336
  );
322
337
  return e ? this.hideSelectionError() : this.showSelectionError(), e;
323
338
  }
339
+ async updateQuote(e) {
340
+ var t, o, n;
341
+ try {
342
+ const r = {
343
+ ...this.options,
344
+ quoteRequestData: {
345
+ ...this.options.quoteRequestData,
346
+ ...e
347
+ }
348
+ };
349
+ y(r);
350
+ const {
351
+ environment: a,
352
+ partnerId: p,
353
+ endpoint: c
354
+ } = this.options.apiConfig, l = c || _[a], d = await b(
355
+ l,
356
+ p,
357
+ r.quoteRequestData
358
+ );
359
+ return d.status !== "QUOTE_AVAILABLE" ? (d.status === "NO_MATCHING_QUOTE" && ((t = this.options.callbacks) != null && t.noMatchingQuote) && this.options.callbacks.noMatchingQuote({
360
+ status: "NO_MATCHING_QUOTE",
361
+ data: r.quoteRequestData
362
+ }), !1) : (this.options.quoteRequestData = r.quoteRequestData, this.quote = d.data, this.currentSelection = null, this.destroy(), this._renderWidget(), (o = this.options.callbacks) != null && o.onQuoteRetrieved && this.options.callbacks.onQuoteRetrieved(this.quote), !0);
363
+ } catch (r) {
364
+ return (n = this.options.callbacks) == null || n.onError({
365
+ message: r.message,
366
+ status: r.status,
367
+ responseBody: r.responseBody
368
+ }), !1;
369
+ }
370
+ }
324
371
  getSelection() {
325
372
  var e, t;
326
373
  return this.currentSelection == null ? null : {
@@ -335,5 +382,5 @@ class I {
335
382
  }
336
383
  }
337
384
  export {
338
- I as default
385
+ M as default
339
386
  };
package/dist/index.umd.js CHANGED
@@ -1,8 +1,8 @@
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=`
1
+ (function(u,f){typeof exports=="object"&&typeof module<"u"?module.exports=f():typeof define=="function"&&define.amd?define(f):(u=typeof globalThis<"u"?globalThis:u||self,u.SpotWidget=f())})(this,function(){"use strict";async function u(i,e,t){try{const o=await fetch(i,{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 f={sandbox:"https://api.sandbox.getspot.com/v1/quote",production:"https://api.getspot.com/v1/quote"};function g(i){const{apiConfig:e={},quoteRequestData:t,callbacks:o={},location:n,theme:r}=i,{environment:a="sandbox",partnerId:p,endpoint:c}=e;if(!p||typeof p!="string")throw new Error("Invalid or missing partnerId in apiConfig");if(!(c||f[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(m=>{if(!Object.prototype.hasOwnProperty.call(t,m)||t[m]===void 0||t[m]===null)throw new Error(`Missing required quoteRequestData field: '${m}'`)});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 y=["Pass","Trip","Registration"];if(!y.includes(t.productType))throw new Error(`productType must be one of ${y.join(", ")}`);if(typeof t.productDuration!="string")throw new Error("productDuration must be a string");const _=["Daily","Seasonal","Trip","Event"];if(!_.includes(t.productDuration))throw new Error(`productDuration must be one of ${_.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(m=>{const v=o[m];if(v&&typeof v!="function")throw new Error(`Callback '${m}' 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 s(i,{text:e,className:t,parent:o,innerHTML:n}={}){const r=document.createElement(i);return t&&(r.className=t),e!=null&&(r.textContent=e),n!=null&&(r.innerHTML=n),o&&o.appendChild(r),r}function w(i,{name:e,description:t}){s("div",{className:"spot-header__title",text:e,parent:i}),s("div",{className:"spot-header__description",text:t,parent:i})}function C(i,e=[]){const t=s("ul",{className:"spot-benefits__list",parent:i});e.forEach(o=>{const n=s("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>`,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=`
5
+ </svg>`,s("span",{text:o,parent:n})})}function E(i,e=[]){const t=s("div",{className:"spot-table__container",parent:i}),o=s("table",{className:"spot-refund__table spot-table--dynamic",parent:t}),n=s("thead",{parent:o}),r=s("tr",{parent:n});s("th",{text:"When you cancel",parent:r}),s("th",{text:"You will receive",parent:r});const a=s("tbody",{parent:o});e.forEach(({text:p,percent:c,amount:l})=>{const d=s("tr",{parent:a});s("td",{text:p,parent:d});const h=c==="Not eligible for refund"?"Not eligible for a refund":`$${l} refund`;s("td",{text:h,parent:d})})}function k(i,e,t){const o=s("div",{className:"spot-selection__options",parent:i}),n=s("label",{className:`spot-selection__option ${t?"selected":""}`,parent:o}),r=s("input",{parent:n});r.type="radio",r.name="selection",r.value="yes",t&&(r.checked=!0),s("strong",{text:`Yes, protect my booking for $${e}`,parent:n}),s("span",{className:"spot-selection__recommended-tag",text:"Recommended",parent:n});const a=s("label",{className:"spot-selection__option",parent:o}),p=s("input",{parent:a});return p.type="radio",p.name="selection",p.value="no",s("span",{text:"No, do not protect my booking",parent:a}),o}function x(i,e){var n;const t=(n=e.communication)==null?void 0:n.paymentTerms,o=s("div",{className:"spot-payment-terms",parent:i});return s("div",{className:"spot-payment-terms__header",text:"PAYMENT TERMS",parent:o}),s("div",{className:"spot-payment-terms__body",text:t,parent:o}),o}function q(i,e){const t=s("div",{className:"spot-footer__container",parent:i}),o=s("div",{className:"spot-footer__terms",parent:t});s("span",{innerHTML:e.communication.legalDisclaimer,parent:o}),s("br",{parent:o}),s("a",{href:e.communication.termsAndConditionsUrl,className:"spot-footer__terms-link",text:"Refund Guarantee Terms and Conditions",parent:o});const n=s("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/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});
20
+ </svg>`,t}const T=":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-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-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 H(i){const e=document.createElement("style");e.textContent=i,document.head.appendChild(e)}H(T);const b={sandbox:"https://api.sandbox.getspot.com/api/v1/quote",production:"https://api.getspot.com/api/v1/quote"};class N{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,r;try{g(this.options);const{environment:a,partnerId:p}=this.options.apiConfig,l=this.options.apiConfig.customEndpoint||b[a],d=await u(l,p,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(a){(n=this.options.callbacks)!=null&&n.onError&&((r=this.options.callbacks)==null||r.onError({message:a.message,status:a.status,responseBody:a.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)}),w(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&&E(e,this.quote.payoutSchedule);const t=k(e,this.quote.spotPrice,this.options.optInSelected);e.appendChild(t),this.paymentTermsEl=s("div",{className:"spot-payment-terms__wrapper",parent:e}),q(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,c,l;const a=r.target.value;this.hideSelectionError(),this.currentSelection=a,o.forEach(d=>d.classList.remove("selected")),(p=r.target.closest(".spot-selection__option"))==null||p.classList.add("selected"),this.paymentTermsEl&&(this.paymentTermsEl.innerHTML=""),a==="yes"&&(this.options.quoteRequestData.isPartialPayment&&x(this.paymentTermsEl,this.quote),(c=this.options.callbacks)!=null&&c.onOptIn&&this.options.callbacks.onOptIn({status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id})),a==="no"&&((l=this.options.callbacks)!=null&&l.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}async updateQuote(e){var t,o,n;try{const r={...this.options,quoteRequestData:{...this.options.quoteRequestData,...e}};g(r);const{environment:a,partnerId:p,endpoint:c}=this.options.apiConfig,l=c||b[a],d=await u(l,p,r.quoteRequestData);return d.status!=="QUOTE_AVAILABLE"?(d.status==="NO_MATCHING_QUOTE"&&((t=this.options.callbacks)!=null&&t.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(),(o=this.options.callbacks)!=null&&o.onQuoteRetrieved&&this.options.callbacks.onQuoteRetrieved(this.quote),!0)}catch(r){return(n=this.options.callbacks)==null||n.onError({message:r.message,status:r.status,responseBody:r.responseBody}),!1}}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 N});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getspot/spot-widget",
3
- "version": "0.2.0",
3
+ "version": "1.1.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/index.js CHANGED
@@ -6,6 +6,8 @@ import {
6
6
  renderTable,
7
7
  renderOptions,
8
8
  renderFooter,
9
+ renderPaymentTerms,
10
+ makeEl,
9
11
  } from "./ui.js";
10
12
 
11
13
  import styles from "./styles.css?inline";
@@ -48,11 +50,9 @@ class SpotWidget {
48
50
  async _init() {
49
51
  try {
50
52
  validateOptions(this.options);
51
- const {
52
- environment,
53
- partnerId,
54
- endpoint: customEndpoint,
55
- } = this.options.apiConfig;
53
+
54
+ const { environment, partnerId } = this.options.apiConfig;
55
+ const customEndpoint = this.options.apiConfig.customEndpoint;
56
56
 
57
57
  const endpoint = customEndpoint || apiEndpoint[environment];
58
58
 
@@ -90,11 +90,13 @@ class SpotWidget {
90
90
  this.options.callbacks.onQuoteRetrieved(this.quote);
91
91
  }
92
92
  } catch (err) {
93
- this.options.callbacks?.onError({
94
- message: err.message,
95
- status: err.status,
96
- responseBody: err.responseBody,
97
- });
93
+ if (this.options.callbacks?.onError) {
94
+ this.options.callbacks?.onError({
95
+ message: err.message,
96
+ status: err.status,
97
+ responseBody: err.responseBody,
98
+ });
99
+ }
98
100
  }
99
101
  }
100
102
 
@@ -121,7 +123,10 @@ class SpotWidget {
121
123
  this.options.optInSelected
122
124
  );
123
125
  cw.appendChild(optsEl);
124
-
126
+ this.paymentTermsEl = makeEl("div", {
127
+ className: "spot-payment-terms__wrapper",
128
+ parent: cw,
129
+ });
125
130
  renderFooter(this.container, this.quote);
126
131
 
127
132
  window.addEventListener("resize", this._onResize);
@@ -150,12 +155,19 @@ class SpotWidget {
150
155
  options.forEach((label) => label.classList.remove("selected"));
151
156
  e.target.closest(".spot-selection__option")?.classList.add("selected");
152
157
 
153
- if (val === "yes" && this.options.callbacks?.onOptIn) {
154
- this.options.callbacks.onOptIn({
155
- status: "QUOTE_ACCEPTED",
156
- spotPrice: this.quote.spotPrice,
157
- quoteId: this.quote.id,
158
- });
158
+ if (this.paymentTermsEl) this.paymentTermsEl.innerHTML = "";
159
+
160
+ if (val === "yes") {
161
+ if (this.options.quoteRequestData.isPartialPayment) {
162
+ renderPaymentTerms(this.paymentTermsEl, this.quote);
163
+ }
164
+ if (this.options.callbacks?.onOptIn) {
165
+ this.options.callbacks.onOptIn({
166
+ status: "QUOTE_ACCEPTED",
167
+ spotPrice: this.quote.spotPrice,
168
+ quoteId: this.quote.id,
169
+ });
170
+ }
159
171
  }
160
172
  if (val === "no" && this.options.callbacks?.onOptOut) {
161
173
  this.options.callbacks.onOptOut({
@@ -205,6 +217,68 @@ class SpotWidget {
205
217
  return isSelected;
206
218
  }
207
219
 
220
+ async updateQuote(newQuoteRequestData) {
221
+ try {
222
+ const updatedOptions = {
223
+ ...this.options,
224
+ quoteRequestData: {
225
+ ...this.options.quoteRequestData,
226
+ ...newQuoteRequestData,
227
+ },
228
+ };
229
+
230
+ validateOptions(updatedOptions);
231
+
232
+ const {
233
+ environment,
234
+ partnerId,
235
+ endpoint: customEndpoint,
236
+ } = this.options.apiConfig;
237
+
238
+ const endpoint = customEndpoint || apiEndpoint[environment];
239
+
240
+ const response = await fetchQuote(
241
+ endpoint,
242
+ partnerId,
243
+ updatedOptions.quoteRequestData
244
+ );
245
+
246
+ if (response.status !== "QUOTE_AVAILABLE") {
247
+ if (
248
+ response.status === "NO_MATCHING_QUOTE" &&
249
+ this.options.callbacks?.noMatchingQuote
250
+ ) {
251
+ this.options.callbacks.noMatchingQuote({
252
+ status: "NO_MATCHING_QUOTE",
253
+ data: updatedOptions.quoteRequestData,
254
+ });
255
+ }
256
+ return false;
257
+ }
258
+
259
+ this.options.quoteRequestData = updatedOptions.quoteRequestData;
260
+ this.quote = response.data;
261
+ this.currentSelection = null;
262
+
263
+ this.destroy();
264
+
265
+ this._renderWidget();
266
+
267
+ if (this.options.callbacks?.onQuoteRetrieved) {
268
+ this.options.callbacks.onQuoteRetrieved(this.quote);
269
+ }
270
+
271
+ return true;
272
+ } catch (err) {
273
+ this.options.callbacks?.onError({
274
+ message: err.message,
275
+ status: err.status,
276
+ responseBody: err.responseBody,
277
+ });
278
+ return false;
279
+ }
280
+ }
281
+
208
282
  getSelection() {
209
283
  if (this.currentSelection == null) return null;
210
284
 
package/src/styles.css CHANGED
@@ -50,6 +50,18 @@
50
50
  --spot-selection-error-font-size: 0.875rem;
51
51
  --spot-selection-error-padding: 0.5rem;
52
52
 
53
+ --spot-payment-terms-background: #f4f4f4;
54
+ --spot-payment-terms-border-radius: 0.625rem;
55
+ --spot-payment-terms-padding: 1rem;
56
+ --spot-payment-terms-font-color: #636569;
57
+ --spot-payment-terms-font-size: 0.75rem;
58
+
59
+ --spot-payment-terms-header-font-weight: 700;
60
+ --spot-payment-terms-header-font-size: 0.875rem;
61
+ --spot-payment-terms-header-margin-bottom: 0.5rem;
62
+ --spot-payment-terms-header-border-color: #c2c2c2;
63
+ --spot-payment-terms-header-padding: 0 0 0.5rem 0;
64
+
53
65
  --spot-terms-font-size: 0.75rem;
54
66
  --spot-terms-font-weight: 400;
55
67
  --spot-terms-font-color: #636569;
@@ -307,6 +319,27 @@ input[type="radio"]:checked {
307
319
  display: none;
308
320
  }
309
321
 
322
+ .spot-payment-terms__wrapper {
323
+ margin-top: 1rem;
324
+ }
325
+
326
+ .spot-payment-terms__header {
327
+ font-weight: var(--spot-payment-terms-header-font-weight);
328
+ margin-bottom: 0.5rem;
329
+ padding: var(--spot-payment-terms-header-padding);
330
+ font-size: var(--spot-payment-terms-header-font-size);
331
+ border-bottom: 1px solid var(--spot-payment-terms-header-border-color);
332
+ }
333
+
334
+ .spot-payment-terms {
335
+ background-color: var(--spot-payment-terms-background);
336
+ border-radius: var(--spot-payment-terms-border-radius);
337
+ padding: var(--spot-payment-terms-padding);
338
+ margin-right: 0.5rem;
339
+ color: var(--spot-payment-terms-font-color);
340
+ font-size: var(--spot-payment-terms-font-size);
341
+ }
342
+
310
343
  /* Footer */
311
344
  .spot-footer__terms {
312
345
  margin-top: 0.625rem;
package/src/ui.js CHANGED
@@ -1,4 +1,4 @@
1
- function makeEl(tag, { text, className, parent, innerHTML } = {}) {
1
+ export function makeEl(tag, { text, className, parent, innerHTML } = {}) {
2
2
  const el = document.createElement(tag);
3
3
  if (className) el.className = className;
4
4
  if (text != null) el.textContent = text;
@@ -110,6 +110,30 @@ export function renderOptions(container, spotPrice, optInSelected) {
110
110
  return optionsWrapper;
111
111
  }
112
112
 
113
+ // payment terms
114
+ export function renderPaymentTerms(container, quote) {
115
+ const terms = quote.communication?.paymentTerms;
116
+
117
+ const wrapper = makeEl("div", {
118
+ className: "spot-payment-terms",
119
+ parent: container,
120
+ });
121
+
122
+ makeEl("div", {
123
+ className: "spot-payment-terms__header",
124
+ text: "PAYMENT TERMS",
125
+ parent: wrapper,
126
+ });
127
+
128
+ makeEl("div", {
129
+ className: "spot-payment-terms__body",
130
+ text: terms,
131
+ parent: wrapper,
132
+ });
133
+
134
+ return wrapper;
135
+ }
136
+
113
137
  // footer
114
138
  export function renderFooter(container, quote) {
115
139
  const footer = makeEl("div", {