@gomusdev/web-components 1.34.0 → 1.35.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.
@@ -0,0 +1 @@
1
+ export { SvelteComponent as default } from 'svelte';
File without changes
@@ -0,0 +1,2 @@
1
+ import { default as UIForm } from '../forms/ui/generic/Form.svelte';
2
+ export declare function redeem(form: UIForm, host: HTMLElement): Promise<void>;
@@ -4,6 +4,7 @@ export type TicketSegmentFilter = 'timeslot' | 'annual' | 'custom' | 'day' | 'ev
4
4
  export declare class SegmentDetails {
5
5
  preCart: {
6
6
  items: import('../../../../../../lib/models/cart/types').CartItem[];
7
+ coupons: string[];
7
8
  contingent: number;
8
9
  uid: string;
9
10
  readonly nonEmptyItems: import('../../../../../../lib/models/cart/types').CartItem[];
@@ -32,7 +33,7 @@ export declare class SegmentDetails {
32
33
  comment: null;
33
34
  reference: null;
34
35
  payment_mode_id: string;
35
- coupons: never[];
36
+ coupons: string[];
36
37
  donations: never[];
37
38
  affiliate: {};
38
39
  total: number;
@@ -43,6 +44,9 @@ export declare class SegmentDetails {
43
44
  addItem(item: import('../../../../../../lib/models/cart/types').CartItem): void;
44
45
  addItems(items: import('../../../../../../lib/models/cart/types').CartItem[]): void;
45
46
  addProducts(products: import('../../../../../../lib/models/cart/types').Product[]): void;
47
+ addCoupon(token: string): void;
48
+ removeCoupon(token: string): void;
49
+ clearCoupons(): void;
46
50
  };
47
51
  filters: TicketSegmentFilter;
48
52
  ticketSelectionDetails: TicketSelectionDetails | undefined;
@@ -11250,7 +11250,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
11250
11250
  };
11251
11251
  }
11252
11252
  function updateLocalStorage(cart) {
11253
- const content = JSON.stringify(cart.items || []);
11253
+ const content = JSON.stringify({ items: cart.items || [], coupons: cart.coupons || [] });
11254
11254
  localStorage.setItem("go-cart", content);
11255
11255
  return content;
11256
11256
  }
@@ -11271,23 +11271,32 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
11271
11271
  }
11272
11272
  function loadFromLocalStorage(cart) {
11273
11273
  let lsItems = [];
11274
+ let lsCoupons = [];
11274
11275
  try {
11275
11276
  const content = localStorage.getItem("go-cart");
11276
11277
  if (!content) return [];
11277
- lsItems = JSON.parse(content);
11278
- if (!Array.isArray(lsItems)) {
11279
- console.dir({ lsItems, content });
11280
- throw new Error("go-cart is not an array");
11278
+ const parsed = JSON.parse(content);
11279
+ if (Array.isArray(parsed)) {
11280
+ lsItems = parsed;
11281
+ lsCoupons = [];
11282
+ } else if (typeof parsed === "object" && parsed !== null) {
11283
+ lsItems = parsed.items || [];
11284
+ lsCoupons = parsed.coupons || [];
11285
+ } else {
11286
+ console.dir({ parsed, content });
11287
+ throw new Error("go-cart has invalid format");
11281
11288
  }
11282
11289
  if (lsItems.length === 0) {
11283
11290
  cart.clearItems();
11284
- return [];
11291
+ } else {
11292
+ cart.items = lsItems.map(generateCartItem).filter(defined);
11285
11293
  }
11286
- cart.items = lsItems.map(generateCartItem).filter(defined);
11294
+ cart.clearCoupons();
11295
+ lsCoupons.forEach((coupon) => cart.addCoupon(coupon));
11287
11296
  return cart.items;
11288
11297
  } catch (e) {
11289
11298
  console.error(e);
11290
- localStorage.setItem("go-cart", JSON.stringify([]));
11299
+ localStorage.setItem("go-cart", JSON.stringify({ items: [], coupons: [] }));
11291
11300
  return [];
11292
11301
  }
11293
11302
  }
@@ -11324,8 +11333,10 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
11324
11333
  let lastUuid = 0;
11325
11334
  function createCart(products, contingent = 20) {
11326
11335
  const items = proxy([]);
11336
+ const coupons = proxy([]);
11327
11337
  const cart = {
11328
11338
  items,
11339
+ coupons,
11329
11340
  contingent,
11330
11341
  // caps the total number of items in the cart
11331
11342
  uid: `cart-${lastUuid++}`,
@@ -11351,7 +11362,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
11351
11362
  comment: null,
11352
11363
  reference: null,
11353
11364
  payment_mode_id: shop.settings?.defaultPaymentModeId,
11354
- coupons: [],
11365
+ coupons: this.coupons,
11355
11366
  donations: [],
11356
11367
  affiliate: {},
11357
11368
  total: this.totalPriceCents
@@ -11377,6 +11388,20 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
11377
11388
  },
11378
11389
  addProducts(products2) {
11379
11390
  products2.forEach((p2) => this.addItem(createCartItem(p2)));
11391
+ },
11392
+ addCoupon(token) {
11393
+ if (!this.coupons.includes(token)) {
11394
+ this.coupons.push(token);
11395
+ }
11396
+ },
11397
+ removeCoupon(token) {
11398
+ const index2 = this.coupons.indexOf(token);
11399
+ if (index2 > -1) {
11400
+ this.coupons.splice(index2, 1);
11401
+ }
11402
+ },
11403
+ clearCoupons() {
11404
+ while (this.coupons.length > 0) this.coupons.pop();
11380
11405
  }
11381
11406
  };
11382
11407
  if (products) products.forEach((p2) => cart.addItem(createCartItem(p2)));
@@ -12564,6 +12589,9 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
12564
12589
  requiredFields: ["date", "ticket_ids"]
12565
12590
  });
12566
12591
  }
12592
+ getCouponSaleByBarcode(token) {
12593
+ return this.fetchAndCache(`/api/v4/coupon_sales/barcode/${token}`, `coupon_sale_barcode_${token}`, "coupon_sale");
12594
+ }
12567
12595
  getEventDetailsOnDate(eventId, dateId) {
12568
12596
  return this.fetchAndCache(`/api/v4/events/${eventId}/dates/${dateId}`, `/api/v4/events/${eventId}/dates/${dateId}`, "date");
12569
12597
  }
@@ -15339,6 +15367,15 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
15339
15367
  description: "",
15340
15368
  autocomplete: "off",
15341
15369
  validator: string().date()
15370
+ },
15371
+ token: {
15372
+ key: "token",
15373
+ apiKey: "id",
15374
+ type: "text",
15375
+ label: "cart.coupon.form.code",
15376
+ placeholder: "",
15377
+ description: "",
15378
+ autocomplete: "off"
15342
15379
  }
15343
15380
  };
15344
15381
  function createField(data, required) {
@@ -15793,7 +15830,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
15793
15830
  ["details"],
15794
15831
  false
15795
15832
  ));
15796
- var root$b = /* @__PURE__ */ from_html(`<go-form></go-form>`, 2);
15833
+ var root$c = /* @__PURE__ */ from_html(`<go-form></go-form>`, 2);
15797
15834
  function PasswordReset($$anchor, $$props) {
15798
15835
  push($$props, true);
15799
15836
  let custom2 = prop($$props, "custom", 7, false);
@@ -15822,7 +15859,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
15822
15859
  flushSync();
15823
15860
  }
15824
15861
  };
15825
- var go_form = root$b();
15862
+ var go_form = root$c();
15826
15863
  set_custom_element_data(go_form, "formId", "passwordReset");
15827
15864
  template_effect(() => set_custom_element_data(go_form, "custom", custom2()));
15828
15865
  event("submit", go_form, passwordReset);
@@ -15830,7 +15867,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
15830
15867
  return pop($$exports);
15831
15868
  }
15832
15869
  customElements.define("go-password-reset", create_custom_element(PasswordReset, { custom: {} }, [], [], false));
15833
- var root$a = /* @__PURE__ */ from_html(`<go-form></go-form>`, 2);
15870
+ var root$b = /* @__PURE__ */ from_html(`<go-form></go-form>`, 2);
15834
15871
  function SignIn($$anchor, $$props) {
15835
15872
  push($$props, true);
15836
15873
  Forms.defineForm({
@@ -15850,7 +15887,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
15850
15887
  details.apiErrors = result.error.errors;
15851
15888
  }
15852
15889
  }
15853
- var go_form = root$a();
15890
+ var go_form = root$b();
15854
15891
  set_custom_element_data(go_form, "formId", "signIn");
15855
15892
  event("submit", go_form, signIn);
15856
15893
  append($$anchor, go_form);
@@ -15865,7 +15902,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
15865
15902
  [],
15866
15903
  false
15867
15904
  ));
15868
- var root$9 = /* @__PURE__ */ from_html(`<go-form></go-form>`, 2);
15905
+ var root$a = /* @__PURE__ */ from_html(`<go-form></go-form>`, 2);
15869
15906
  function SignUp($$anchor, $$props) {
15870
15907
  push($$props, true);
15871
15908
  Forms.defineForm({
@@ -15897,7 +15934,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
15897
15934
  details.apiErrors = result.error.errors;
15898
15935
  }
15899
15936
  }
15900
- var go_form = root$9();
15937
+ var go_form = root$a();
15901
15938
  set_custom_element_data(go_form, "formId", "signUp");
15902
15939
  event("submit", go_form, signUp);
15903
15940
  append($$anchor, go_form);
@@ -15913,7 +15950,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
15913
15950
  false
15914
15951
  ));
15915
15952
  var root_1$h = /* @__PURE__ */ from_html(`<span class="go-cart-item-date" data-testid="cart-item-date"> </span><span class="go-cart-item-time" data-testid="cart-item-time"> </span>`, 1);
15916
- var root$8 = /* @__PURE__ */ from_html(`<li data-go-cart-item-title=""><span class="go-cart-item-title" data-testid="cart-item-title"><span class="go-cart-item-title-event-title"> </span><span class="go-cart-item-title-ticket-title"> </span></span><!></li>`);
15953
+ var root$9 = /* @__PURE__ */ from_html(`<li data-go-cart-item-title=""><span class="go-cart-item-title" data-testid="cart-item-title"><span class="go-cart-item-title-event-title"> </span><span class="go-cart-item-title-ticket-title"> </span></span><!></li>`);
15917
15954
  function Event$2($$anchor, $$props) {
15918
15955
  push($$props, true);
15919
15956
  let cartItem = prop($$props, "cartItem", 7);
@@ -15928,7 +15965,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
15928
15965
  flushSync();
15929
15966
  }
15930
15967
  };
15931
- var li = root$8();
15968
+ var li = root$9();
15932
15969
  var span = child(li);
15933
15970
  var span_1 = child(span);
15934
15971
  var text2 = child(span_1, true);
@@ -15974,7 +16011,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
15974
16011
  create_custom_element(Event$2, { cartItem: {} }, [], [], true);
15975
16012
  var root_2$q = /* @__PURE__ */ from_html(`<span class="go-cart-item-time" data-testid="cart-item-time"> </span>`);
15976
16013
  var root_1$g = /* @__PURE__ */ from_html(`<span class="go-cart-item-date" data-testid="cart-item-date"> </span> <!>`, 1);
15977
- var root$7 = /* @__PURE__ */ from_html(`<li data-go-cart-item-title=""><span class="go-cart-item-title" data-testid="cart-item-title"> </span> <!></li>`);
16014
+ var root$8 = /* @__PURE__ */ from_html(`<li data-go-cart-item-title=""><span class="go-cart-item-title" data-testid="cart-item-title"> </span> <!></li>`);
15978
16015
  function Ticket($$anchor, $$props) {
15979
16016
  push($$props, true);
15980
16017
  let cartItem = prop($$props, "cartItem", 7);
@@ -15987,7 +16024,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
15987
16024
  flushSync();
15988
16025
  }
15989
16026
  };
15990
- var li = root$7();
16027
+ var li = root$8();
15991
16028
  var span = child(li);
15992
16029
  var text2 = child(span, true);
15993
16030
  reset(span);
@@ -16256,6 +16293,67 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
16256
16293
  return pop($$exports);
16257
16294
  }
16258
16295
  customElements.define("go-checkout-form", create_custom_element(CheckoutForm, { custom: {} }, [], [], false));
16296
+ async function redeem(form, host) {
16297
+ if (!form) {
16298
+ throw new Error("(go-coupon-redemption): form not found");
16299
+ }
16300
+ if (!shop.cart) {
16301
+ throw new Error("(go-coupon-redemption): cart not found");
16302
+ }
16303
+ const result = await shop.asyncFetch(() => shop.getCouponSaleByBarcode(form.details.formData.id));
16304
+ if (result?.is_valid && result.is_voucher_for) {
16305
+ const tickets = await shop.asyncFetch(
16306
+ () => shop.tickets({
16307
+ // @ts-ignore - api supports filter even if schema doesn't yet.
16308
+ "by_ticket_ids[]": [result.is_voucher_for]
16309
+ })
16310
+ );
16311
+ const ticket = tickets.find((t) => t.id === result.is_voucher_for);
16312
+ if (!ticket) {
16313
+ form.details.apiErrors ??= [];
16314
+ form.details.apiErrors = [shop.t("cart.coupon.form.errors.error")];
16315
+ return;
16316
+ }
16317
+ const voucherTicket = { ...ticket, price_cents: 0 };
16318
+ shop.cart.addItem(createCartItem(createUITicket(voucherTicket), { quantity: 1 }));
16319
+ const token = form.details.formData.id;
16320
+ shop.cart.addCoupon(token);
16321
+ const tokenField = form.details.fields.find((f) => f.key === "token");
16322
+ if (tokenField) tokenField.value = "";
16323
+ host.dispatchEvent(new Event("go-success", { bubbles: true, composed: true }));
16324
+ } else {
16325
+ form.details.apiErrors ??= [];
16326
+ form.details.apiErrors = [shop.t("cart.coupon.form.errors.notValid")];
16327
+ }
16328
+ }
16329
+ var root$7 = /* @__PURE__ */ from_html(`<go-form><go-field></go-field> <go-errors-feedback></go-errors-feedback> <go-submit> </go-submit></go-form>`, 2);
16330
+ function CouponRedemption($$anchor, $$props) {
16331
+ push($$props, true);
16332
+ let form;
16333
+ Forms.defineForm({
16334
+ id: "couponRedemption",
16335
+ fields: [{ key: "token", required: true }]
16336
+ });
16337
+ async function redeem$1() {
16338
+ await redeem(form, $$props.$$host);
16339
+ }
16340
+ var go_form = root$7();
16341
+ set_custom_element_data(go_form, "formId", "couponRedemption");
16342
+ set_custom_element_data(go_form, "custom", true);
16343
+ var go_field = child(go_form);
16344
+ set_custom_element_data(go_field, "key", "token");
16345
+ var go_errors_feedback = sibling(go_field, 2);
16346
+ var go_submit = sibling(go_errors_feedback, 2);
16347
+ var text2 = child(go_submit, true);
16348
+ reset(go_submit);
16349
+ reset(go_form);
16350
+ bind_this(go_form, ($$value) => form = $$value, () => form);
16351
+ template_effect(($0) => set_text(text2, $0), [() => shop.t("cart.coupon.form.submit")]);
16352
+ event("submit", go_form, redeem$1);
16353
+ append($$anchor, go_form);
16354
+ pop();
16355
+ }
16356
+ customElements.define("go-coupon-redemption", create_custom_element(CouponRedemption, {}, [], [], false));
16259
16357
  function isFunction$1(value) {
16260
16358
  return typeof value === "function";
16261
16359
  }
@@ -30218,6 +30316,39 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
30218
30316
  [],
30219
30317
  false
30220
30318
  ));
30319
+ function Link($$anchor, $$props) {
30320
+ push($$props, true);
30321
+ const to = prop($$props, "to", 7);
30322
+ const href = /* @__PURE__ */ user_derived(() => go.config.urls[to()]);
30323
+ const a2 = wrapInElement($$props.$$host, "a");
30324
+ user_effect(() => {
30325
+ if (!get$2(href)) {
30326
+ console.warn(`[go-link] No URL found for route "${to()}".`);
30327
+ a2.removeAttribute("href");
30328
+ return;
30329
+ }
30330
+ a2.setAttribute("href", get$2(href)());
30331
+ });
30332
+ a2.addEventListener("click", (e) => {
30333
+ e.preventDefault();
30334
+ if (!go.config.urls[to()]) {
30335
+ console.warn(`[go-link] No URL found for route "${to()}". You can define it with go.config.urls.${to()} = () => 'https://example.com/my-route'`);
30336
+ return;
30337
+ }
30338
+ go.config.navigateTo(go.config.urls[to()]());
30339
+ });
30340
+ var $$exports = {
30341
+ get to() {
30342
+ return to();
30343
+ },
30344
+ set to($$value) {
30345
+ to($$value);
30346
+ flushSync();
30347
+ }
30348
+ };
30349
+ return pop($$exports);
30350
+ }
30351
+ customElements.define("go-link", create_custom_element(Link, { to: { attribute: "to", reflect: true, type: "String" } }, [], [], false));
30221
30352
  class OrderDetails {
30222
30353
  #token = /* @__PURE__ */ state();
30223
30354
  get token() {
@@ -32058,39 +32189,6 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
32058
32189
  }
32059
32190
  delegate(["click"]);
32060
32191
  customElements.define("go-add-to-cart-button", create_custom_element(AddToCartButton, {}, [], ["details"], false));
32061
- function Link($$anchor, $$props) {
32062
- push($$props, true);
32063
- const to = prop($$props, "to", 7);
32064
- const href = /* @__PURE__ */ user_derived(() => go.config.urls[to()]);
32065
- const a2 = wrapInElement($$props.$$host, "a");
32066
- user_effect(() => {
32067
- if (!get$2(href)) {
32068
- console.warn(`[go-link] No URL found for route "${to()}".`);
32069
- a2.removeAttribute("href");
32070
- return;
32071
- }
32072
- a2.setAttribute("href", get$2(href)());
32073
- });
32074
- a2.addEventListener("click", (e) => {
32075
- e.preventDefault();
32076
- if (!go.config.urls[to()]) {
32077
- console.warn(`[go-link] No URL found for route "${to()}". You can define it with go.config.urls.${to()} = () => 'https://example.com/my-route'`);
32078
- return;
32079
- }
32080
- go.config.navigateTo(go.config.urls[to()]());
32081
- });
32082
- var $$exports = {
32083
- get to() {
32084
- return to();
32085
- },
32086
- set to($$value) {
32087
- to($$value);
32088
- flushSync();
32089
- }
32090
- };
32091
- return pop($$exports);
32092
- }
32093
- customElements.define("go-link", create_custom_element(Link, { to: { attribute: "to", reflect: true, type: "String" } }, [], [], false));
32094
32192
  var root$1 = /* @__PURE__ */ from_html(`<go-form></go-form>`, 2);
32095
32193
  function Password($$anchor, $$props) {
32096
32194
  push($$props, false);
@@ -11250,7 +11250,7 @@ function createCartItem(product, options) {
11250
11250
  };
11251
11251
  }
11252
11252
  function updateLocalStorage(cart) {
11253
- const content = JSON.stringify(cart.items || []);
11253
+ const content = JSON.stringify({ items: cart.items || [], coupons: cart.coupons || [] });
11254
11254
  localStorage.setItem("go-cart", content);
11255
11255
  return content;
11256
11256
  }
@@ -11271,23 +11271,32 @@ function generateCartItem(cartItem) {
11271
11271
  }
11272
11272
  function loadFromLocalStorage(cart) {
11273
11273
  let lsItems = [];
11274
+ let lsCoupons = [];
11274
11275
  try {
11275
11276
  const content = localStorage.getItem("go-cart");
11276
11277
  if (!content) return [];
11277
- lsItems = JSON.parse(content);
11278
- if (!Array.isArray(lsItems)) {
11279
- console.dir({ lsItems, content });
11280
- throw new Error("go-cart is not an array");
11278
+ const parsed = JSON.parse(content);
11279
+ if (Array.isArray(parsed)) {
11280
+ lsItems = parsed;
11281
+ lsCoupons = [];
11282
+ } else if (typeof parsed === "object" && parsed !== null) {
11283
+ lsItems = parsed.items || [];
11284
+ lsCoupons = parsed.coupons || [];
11285
+ } else {
11286
+ console.dir({ parsed, content });
11287
+ throw new Error("go-cart has invalid format");
11281
11288
  }
11282
11289
  if (lsItems.length === 0) {
11283
11290
  cart.clearItems();
11284
- return [];
11291
+ } else {
11292
+ cart.items = lsItems.map(generateCartItem).filter(defined);
11285
11293
  }
11286
- cart.items = lsItems.map(generateCartItem).filter(defined);
11294
+ cart.clearCoupons();
11295
+ lsCoupons.forEach((coupon) => cart.addCoupon(coupon));
11287
11296
  return cart.items;
11288
11297
  } catch (e) {
11289
11298
  console.error(e);
11290
- localStorage.setItem("go-cart", JSON.stringify([]));
11299
+ localStorage.setItem("go-cart", JSON.stringify({ items: [], coupons: [] }));
11291
11300
  return [];
11292
11301
  }
11293
11302
  }
@@ -11324,8 +11333,10 @@ const defined = (x) => x !== void 0;
11324
11333
  let lastUuid = 0;
11325
11334
  function createCart(products, contingent = 20) {
11326
11335
  const items = proxy([]);
11336
+ const coupons = proxy([]);
11327
11337
  const cart = {
11328
11338
  items,
11339
+ coupons,
11329
11340
  contingent,
11330
11341
  // caps the total number of items in the cart
11331
11342
  uid: `cart-${lastUuid++}`,
@@ -11351,7 +11362,7 @@ function createCart(products, contingent = 20) {
11351
11362
  comment: null,
11352
11363
  reference: null,
11353
11364
  payment_mode_id: shop.settings?.defaultPaymentModeId,
11354
- coupons: [],
11365
+ coupons: this.coupons,
11355
11366
  donations: [],
11356
11367
  affiliate: {},
11357
11368
  total: this.totalPriceCents
@@ -11377,6 +11388,20 @@ function createCart(products, contingent = 20) {
11377
11388
  },
11378
11389
  addProducts(products2) {
11379
11390
  products2.forEach((p2) => this.addItem(createCartItem(p2)));
11391
+ },
11392
+ addCoupon(token) {
11393
+ if (!this.coupons.includes(token)) {
11394
+ this.coupons.push(token);
11395
+ }
11396
+ },
11397
+ removeCoupon(token) {
11398
+ const index2 = this.coupons.indexOf(token);
11399
+ if (index2 > -1) {
11400
+ this.coupons.splice(index2, 1);
11401
+ }
11402
+ },
11403
+ clearCoupons() {
11404
+ while (this.coupons.length > 0) this.coupons.pop();
11380
11405
  }
11381
11406
  };
11382
11407
  if (products) products.forEach((p2) => cart.addItem(createCartItem(p2)));
@@ -12564,6 +12589,9 @@ class Shop {
12564
12589
  requiredFields: ["date", "ticket_ids"]
12565
12590
  });
12566
12591
  }
12592
+ getCouponSaleByBarcode(token) {
12593
+ return this.fetchAndCache(`/api/v4/coupon_sales/barcode/${token}`, `coupon_sale_barcode_${token}`, "coupon_sale");
12594
+ }
12567
12595
  getEventDetailsOnDate(eventId, dateId) {
12568
12596
  return this.fetchAndCache(`/api/v4/events/${eventId}/dates/${dateId}`, `/api/v4/events/${eventId}/dates/${dateId}`, "date");
12569
12597
  }
@@ -15339,6 +15367,15 @@ var allFields = {
15339
15367
  description: "",
15340
15368
  autocomplete: "off",
15341
15369
  validator: string().date()
15370
+ },
15371
+ token: {
15372
+ key: "token",
15373
+ apiKey: "id",
15374
+ type: "text",
15375
+ label: "cart.coupon.form.code",
15376
+ placeholder: "",
15377
+ description: "",
15378
+ autocomplete: "off"
15342
15379
  }
15343
15380
  };
15344
15381
  function createField(data, required) {
@@ -15793,7 +15830,7 @@ customElements.define("go-form", create_custom_element(
15793
15830
  ["details"],
15794
15831
  false
15795
15832
  ));
15796
- var root$b = /* @__PURE__ */ from_html(`<go-form></go-form>`, 2);
15833
+ var root$c = /* @__PURE__ */ from_html(`<go-form></go-form>`, 2);
15797
15834
  function PasswordReset($$anchor, $$props) {
15798
15835
  push($$props, true);
15799
15836
  let custom2 = prop($$props, "custom", 7, false);
@@ -15822,7 +15859,7 @@ function PasswordReset($$anchor, $$props) {
15822
15859
  flushSync();
15823
15860
  }
15824
15861
  };
15825
- var go_form = root$b();
15862
+ var go_form = root$c();
15826
15863
  set_custom_element_data(go_form, "formId", "passwordReset");
15827
15864
  template_effect(() => set_custom_element_data(go_form, "custom", custom2()));
15828
15865
  event("submit", go_form, passwordReset);
@@ -15830,7 +15867,7 @@ function PasswordReset($$anchor, $$props) {
15830
15867
  return pop($$exports);
15831
15868
  }
15832
15869
  customElements.define("go-password-reset", create_custom_element(PasswordReset, { custom: {} }, [], [], false));
15833
- var root$a = /* @__PURE__ */ from_html(`<go-form></go-form>`, 2);
15870
+ var root$b = /* @__PURE__ */ from_html(`<go-form></go-form>`, 2);
15834
15871
  function SignIn($$anchor, $$props) {
15835
15872
  push($$props, true);
15836
15873
  Forms.defineForm({
@@ -15850,7 +15887,7 @@ function SignIn($$anchor, $$props) {
15850
15887
  details.apiErrors = result.error.errors;
15851
15888
  }
15852
15889
  }
15853
- var go_form = root$a();
15890
+ var go_form = root$b();
15854
15891
  set_custom_element_data(go_form, "formId", "signIn");
15855
15892
  event("submit", go_form, signIn);
15856
15893
  append($$anchor, go_form);
@@ -15865,7 +15902,7 @@ customElements.define("go-sign-in", create_custom_element(
15865
15902
  [],
15866
15903
  false
15867
15904
  ));
15868
- var root$9 = /* @__PURE__ */ from_html(`<go-form></go-form>`, 2);
15905
+ var root$a = /* @__PURE__ */ from_html(`<go-form></go-form>`, 2);
15869
15906
  function SignUp($$anchor, $$props) {
15870
15907
  push($$props, true);
15871
15908
  Forms.defineForm({
@@ -15897,7 +15934,7 @@ function SignUp($$anchor, $$props) {
15897
15934
  details.apiErrors = result.error.errors;
15898
15935
  }
15899
15936
  }
15900
- var go_form = root$9();
15937
+ var go_form = root$a();
15901
15938
  set_custom_element_data(go_form, "formId", "signUp");
15902
15939
  event("submit", go_form, signUp);
15903
15940
  append($$anchor, go_form);
@@ -15913,7 +15950,7 @@ customElements.define("go-sign-up", create_custom_element(
15913
15950
  false
15914
15951
  ));
15915
15952
  var root_1$h = /* @__PURE__ */ from_html(`<span class="go-cart-item-date" data-testid="cart-item-date"> </span><span class="go-cart-item-time" data-testid="cart-item-time"> </span>`, 1);
15916
- var root$8 = /* @__PURE__ */ from_html(`<li data-go-cart-item-title=""><span class="go-cart-item-title" data-testid="cart-item-title"><span class="go-cart-item-title-event-title"> </span><span class="go-cart-item-title-ticket-title"> </span></span><!></li>`);
15953
+ var root$9 = /* @__PURE__ */ from_html(`<li data-go-cart-item-title=""><span class="go-cart-item-title" data-testid="cart-item-title"><span class="go-cart-item-title-event-title"> </span><span class="go-cart-item-title-ticket-title"> </span></span><!></li>`);
15917
15954
  function Event$2($$anchor, $$props) {
15918
15955
  push($$props, true);
15919
15956
  let cartItem = prop($$props, "cartItem", 7);
@@ -15928,7 +15965,7 @@ function Event$2($$anchor, $$props) {
15928
15965
  flushSync();
15929
15966
  }
15930
15967
  };
15931
- var li = root$8();
15968
+ var li = root$9();
15932
15969
  var span = child(li);
15933
15970
  var span_1 = child(span);
15934
15971
  var text2 = child(span_1, true);
@@ -15974,7 +16011,7 @@ function Event$2($$anchor, $$props) {
15974
16011
  create_custom_element(Event$2, { cartItem: {} }, [], [], true);
15975
16012
  var root_2$q = /* @__PURE__ */ from_html(`<span class="go-cart-item-time" data-testid="cart-item-time"> </span>`);
15976
16013
  var root_1$g = /* @__PURE__ */ from_html(`<span class="go-cart-item-date" data-testid="cart-item-date"> </span> <!>`, 1);
15977
- var root$7 = /* @__PURE__ */ from_html(`<li data-go-cart-item-title=""><span class="go-cart-item-title" data-testid="cart-item-title"> </span> <!></li>`);
16014
+ var root$8 = /* @__PURE__ */ from_html(`<li data-go-cart-item-title=""><span class="go-cart-item-title" data-testid="cart-item-title"> </span> <!></li>`);
15978
16015
  function Ticket($$anchor, $$props) {
15979
16016
  push($$props, true);
15980
16017
  let cartItem = prop($$props, "cartItem", 7);
@@ -15987,7 +16024,7 @@ function Ticket($$anchor, $$props) {
15987
16024
  flushSync();
15988
16025
  }
15989
16026
  };
15990
- var li = root$7();
16027
+ var li = root$8();
15991
16028
  var span = child(li);
15992
16029
  var text2 = child(span, true);
15993
16030
  reset(span);
@@ -16256,6 +16293,67 @@ function CheckoutForm($$anchor, $$props) {
16256
16293
  return pop($$exports);
16257
16294
  }
16258
16295
  customElements.define("go-checkout-form", create_custom_element(CheckoutForm, { custom: {} }, [], [], false));
16296
+ async function redeem(form, host) {
16297
+ if (!form) {
16298
+ throw new Error("(go-coupon-redemption): form not found");
16299
+ }
16300
+ if (!shop.cart) {
16301
+ throw new Error("(go-coupon-redemption): cart not found");
16302
+ }
16303
+ const result = await shop.asyncFetch(() => shop.getCouponSaleByBarcode(form.details.formData.id));
16304
+ if (result?.is_valid && result.is_voucher_for) {
16305
+ const tickets = await shop.asyncFetch(
16306
+ () => shop.tickets({
16307
+ // @ts-ignore - api supports filter even if schema doesn't yet.
16308
+ "by_ticket_ids[]": [result.is_voucher_for]
16309
+ })
16310
+ );
16311
+ const ticket = tickets.find((t) => t.id === result.is_voucher_for);
16312
+ if (!ticket) {
16313
+ form.details.apiErrors ??= [];
16314
+ form.details.apiErrors = [shop.t("cart.coupon.form.errors.error")];
16315
+ return;
16316
+ }
16317
+ const voucherTicket = { ...ticket, price_cents: 0 };
16318
+ shop.cart.addItem(createCartItem(createUITicket(voucherTicket), { quantity: 1 }));
16319
+ const token = form.details.formData.id;
16320
+ shop.cart.addCoupon(token);
16321
+ const tokenField = form.details.fields.find((f) => f.key === "token");
16322
+ if (tokenField) tokenField.value = "";
16323
+ host.dispatchEvent(new Event("go-success", { bubbles: true, composed: true }));
16324
+ } else {
16325
+ form.details.apiErrors ??= [];
16326
+ form.details.apiErrors = [shop.t("cart.coupon.form.errors.notValid")];
16327
+ }
16328
+ }
16329
+ var root$7 = /* @__PURE__ */ from_html(`<go-form><go-field></go-field> <go-errors-feedback></go-errors-feedback> <go-submit> </go-submit></go-form>`, 2);
16330
+ function CouponRedemption($$anchor, $$props) {
16331
+ push($$props, true);
16332
+ let form;
16333
+ Forms.defineForm({
16334
+ id: "couponRedemption",
16335
+ fields: [{ key: "token", required: true }]
16336
+ });
16337
+ async function redeem$1() {
16338
+ await redeem(form, $$props.$$host);
16339
+ }
16340
+ var go_form = root$7();
16341
+ set_custom_element_data(go_form, "formId", "couponRedemption");
16342
+ set_custom_element_data(go_form, "custom", true);
16343
+ var go_field = child(go_form);
16344
+ set_custom_element_data(go_field, "key", "token");
16345
+ var go_errors_feedback = sibling(go_field, 2);
16346
+ var go_submit = sibling(go_errors_feedback, 2);
16347
+ var text2 = child(go_submit, true);
16348
+ reset(go_submit);
16349
+ reset(go_form);
16350
+ bind_this(go_form, ($$value) => form = $$value, () => form);
16351
+ template_effect(($0) => set_text(text2, $0), [() => shop.t("cart.coupon.form.submit")]);
16352
+ event("submit", go_form, redeem$1);
16353
+ append($$anchor, go_form);
16354
+ pop();
16355
+ }
16356
+ customElements.define("go-coupon-redemption", create_custom_element(CouponRedemption, {}, [], [], false));
16259
16357
  function isFunction$1(value) {
16260
16358
  return typeof value === "function";
16261
16359
  }
@@ -30218,6 +30316,39 @@ customElements.define("go-init", create_custom_element(
30218
30316
  [],
30219
30317
  false
30220
30318
  ));
30319
+ function Link($$anchor, $$props) {
30320
+ push($$props, true);
30321
+ const to = prop($$props, "to", 7);
30322
+ const href = /* @__PURE__ */ user_derived(() => go.config.urls[to()]);
30323
+ const a2 = wrapInElement($$props.$$host, "a");
30324
+ user_effect(() => {
30325
+ if (!get$2(href)) {
30326
+ console.warn(`[go-link] No URL found for route "${to()}".`);
30327
+ a2.removeAttribute("href");
30328
+ return;
30329
+ }
30330
+ a2.setAttribute("href", get$2(href)());
30331
+ });
30332
+ a2.addEventListener("click", (e) => {
30333
+ e.preventDefault();
30334
+ if (!go.config.urls[to()]) {
30335
+ console.warn(`[go-link] No URL found for route "${to()}". You can define it with go.config.urls.${to()} = () => 'https://example.com/my-route'`);
30336
+ return;
30337
+ }
30338
+ go.config.navigateTo(go.config.urls[to()]());
30339
+ });
30340
+ var $$exports = {
30341
+ get to() {
30342
+ return to();
30343
+ },
30344
+ set to($$value) {
30345
+ to($$value);
30346
+ flushSync();
30347
+ }
30348
+ };
30349
+ return pop($$exports);
30350
+ }
30351
+ customElements.define("go-link", create_custom_element(Link, { to: { attribute: "to", reflect: true, type: "String" } }, [], [], false));
30221
30352
  class OrderDetails {
30222
30353
  #token = /* @__PURE__ */ state();
30223
30354
  get token() {
@@ -32058,39 +32189,6 @@ function AddToCartButton($$anchor, $$props) {
32058
32189
  }
32059
32190
  delegate(["click"]);
32060
32191
  customElements.define("go-add-to-cart-button", create_custom_element(AddToCartButton, {}, [], ["details"], false));
32061
- function Link($$anchor, $$props) {
32062
- push($$props, true);
32063
- const to = prop($$props, "to", 7);
32064
- const href = /* @__PURE__ */ user_derived(() => go.config.urls[to()]);
32065
- const a2 = wrapInElement($$props.$$host, "a");
32066
- user_effect(() => {
32067
- if (!get$2(href)) {
32068
- console.warn(`[go-link] No URL found for route "${to()}".`);
32069
- a2.removeAttribute("href");
32070
- return;
32071
- }
32072
- a2.setAttribute("href", get$2(href)());
32073
- });
32074
- a2.addEventListener("click", (e) => {
32075
- e.preventDefault();
32076
- if (!go.config.urls[to()]) {
32077
- console.warn(`[go-link] No URL found for route "${to()}". You can define it with go.config.urls.${to()} = () => 'https://example.com/my-route'`);
32078
- return;
32079
- }
32080
- go.config.navigateTo(go.config.urls[to()]());
32081
- });
32082
- var $$exports = {
32083
- get to() {
32084
- return to();
32085
- },
32086
- set to($$value) {
32087
- to($$value);
32088
- flushSync();
32089
- }
32090
- };
32091
- return pop($$exports);
32092
- }
32093
- customElements.define("go-link", create_custom_element(Link, { to: { attribute: "to", reflect: true, type: "String" } }, [], [], false));
32094
32192
  var root$1 = /* @__PURE__ */ from_html(`<go-form></go-form>`, 2);
32095
32193
  function Password($$anchor, $$props) {
32096
32194
  push($$props, false);
@@ -2,6 +2,7 @@ import { CartItem, Product } from './types.ts';
2
2
  export type Cart = ReturnType<typeof createCart>;
3
3
  export declare function createCart(products?: Product[], contingent?: number): {
4
4
  items: CartItem[];
5
+ coupons: string[];
5
6
  contingent: number;
6
7
  uid: string;
7
8
  readonly nonEmptyItems: CartItem[];
@@ -33,7 +34,7 @@ export declare function createCart(products?: Product[], contingent?: number): {
33
34
  comment: null;
34
35
  reference: null;
35
36
  payment_mode_id: string;
36
- coupons: never[];
37
+ coupons: string[];
37
38
  donations: never[];
38
39
  affiliate: {};
39
40
  total: number;
@@ -44,10 +45,14 @@ export declare function createCart(products?: Product[], contingent?: number): {
44
45
  addItem(item: CartItem): void;
45
46
  addItems(items: CartItem[]): void;
46
47
  addProducts(products: Product[]): void;
48
+ addCoupon(token: string): void;
49
+ removeCoupon(token: string): void;
50
+ clearCoupons(): void;
47
51
  };
48
52
  export declare function formatCurrency(priceCents: number): string;
49
53
  export declare function createMainCart(): {
50
54
  items: CartItem[];
55
+ coupons: string[];
51
56
  contingent: number;
52
57
  uid: string;
53
58
  readonly nonEmptyItems: CartItem[];
@@ -79,7 +84,7 @@ export declare function createMainCart(): {
79
84
  comment: null;
80
85
  reference: null;
81
86
  payment_mode_id: string;
82
- coupons: never[];
87
+ coupons: string[];
83
88
  donations: never[];
84
89
  affiliate: {};
85
90
  total: number;
@@ -90,4 +95,7 @@ export declare function createMainCart(): {
90
95
  addItem(item: CartItem): void;
91
96
  addItems(items: CartItem[]): void;
92
97
  addProducts(products: Product[]): void;
98
+ addCoupon(token: string): void;
99
+ removeCoupon(token: string): void;
100
+ clearCoupons(): void;
93
101
  };
@@ -88,6 +88,7 @@ export declare class Shop {
88
88
  };
89
89
  get cart(): {
90
90
  items: import('../models/cart/types').CartItem[];
91
+ coupons: string[];
91
92
  contingent: number;
92
93
  uid: string;
93
94
  readonly nonEmptyItems: import('../models/cart/types').CartItem[];
@@ -116,7 +117,7 @@ export declare class Shop {
116
117
  comment: null;
117
118
  reference: null;
118
119
  payment_mode_id: string;
119
- coupons: never[];
120
+ coupons: string[];
120
121
  donations: never[];
121
122
  affiliate: {};
122
123
  total: number;
@@ -127,6 +128,9 @@ export declare class Shop {
127
128
  addItem(item: import('../models/cart/types').CartItem): void;
128
129
  addItems(items: import('../models/cart/types').CartItem[]): void;
129
130
  addProducts(products: import('../models/cart/types').Product[]): void;
131
+ addCoupon(token: string): void;
132
+ removeCoupon(token: string): void;
133
+ clearCoupons(): void;
130
134
  } | undefined;
131
135
  get auth(): Auth;
132
136
  get currentUser(): User | undefined;
@@ -508,6 +512,14 @@ export declare class Shop {
508
512
  content: Record<string, never>;
509
513
  };
510
514
  getTicketCapacities(date: string, ticketIds: number[]): Promise<CapacitiesResponse>;
515
+ getCouponSaleByBarcode(token: string): {
516
+ id: number;
517
+ is_valid: boolean;
518
+ is_voucher_for: number | null;
519
+ value_cents: number;
520
+ value_action: string | null;
521
+ value: number | null;
522
+ };
511
523
  getEventDetailsOnDate(eventId: number, dateId: number): {
512
524
  id?: number;
513
525
  event_id?: number;
@@ -1094,6 +1094,7 @@ export declare const UIAnnualTicketMocks: {
1094
1094
  export declare const CartMocks: {
1095
1095
  cartOneItem: () => {
1096
1096
  items: import('../lib/models/cart/types').CartItem[];
1097
+ coupons: string[];
1097
1098
  contingent: number;
1098
1099
  uid: string;
1099
1100
  readonly nonEmptyItems: import('../lib/models/cart/types').CartItem[];
@@ -1122,7 +1123,7 @@ export declare const CartMocks: {
1122
1123
  comment: null;
1123
1124
  reference: null;
1124
1125
  payment_mode_id: string;
1125
- coupons: never[];
1126
+ coupons: string[];
1126
1127
  donations: never[];
1127
1128
  affiliate: {};
1128
1129
  total: number;
@@ -1133,9 +1134,13 @@ export declare const CartMocks: {
1133
1134
  addItem(item: import('../lib/models/cart/types').CartItem): void;
1134
1135
  addItems(items: import('../lib/models/cart/types').CartItem[]): void;
1135
1136
  addProducts(products: import('../lib/models/cart/types').Product[]): void;
1137
+ addCoupon(token: string): void;
1138
+ removeCoupon(token: string): void;
1139
+ clearCoupons(): void;
1136
1140
  };
1137
1141
  cartTwoItems: () => {
1138
1142
  items: import('../lib/models/cart/types').CartItem[];
1143
+ coupons: string[];
1139
1144
  contingent: number;
1140
1145
  uid: string;
1141
1146
  readonly nonEmptyItems: import('../lib/models/cart/types').CartItem[];
@@ -1164,7 +1169,7 @@ export declare const CartMocks: {
1164
1169
  comment: null;
1165
1170
  reference: null;
1166
1171
  payment_mode_id: string;
1167
- coupons: never[];
1172
+ coupons: string[];
1168
1173
  donations: never[];
1169
1174
  affiliate: {};
1170
1175
  total: number;
@@ -1175,9 +1180,13 @@ export declare const CartMocks: {
1175
1180
  addItem(item: import('../lib/models/cart/types').CartItem): void;
1176
1181
  addItems(items: import('../lib/models/cart/types').CartItem[]): void;
1177
1182
  addProducts(products: import('../lib/models/cart/types').Product[]): void;
1183
+ addCoupon(token: string): void;
1184
+ removeCoupon(token: string): void;
1185
+ clearCoupons(): void;
1178
1186
  };
1179
1187
  cartThreeItems: () => {
1180
1188
  items: import('../lib/models/cart/types').CartItem[];
1189
+ coupons: string[];
1181
1190
  contingent: number;
1182
1191
  uid: string;
1183
1192
  readonly nonEmptyItems: import('../lib/models/cart/types').CartItem[];
@@ -1206,7 +1215,7 @@ export declare const CartMocks: {
1206
1215
  comment: null;
1207
1216
  reference: null;
1208
1217
  payment_mode_id: string;
1209
- coupons: never[];
1218
+ coupons: string[];
1210
1219
  donations: never[];
1211
1220
  affiliate: {};
1212
1221
  total: number;
@@ -1217,6 +1226,9 @@ export declare const CartMocks: {
1217
1226
  addItem(item: import('../lib/models/cart/types').CartItem): void;
1218
1227
  addItems(items: import('../lib/models/cart/types').CartItem[]): void;
1219
1228
  addProducts(products: import('../lib/models/cart/types').Product[]): void;
1229
+ addCoupon(token: string): void;
1230
+ removeCoupon(token: string): void;
1231
+ clearCoupons(): void;
1220
1232
  };
1221
1233
  };
1222
1234
  export declare const CartItemMocks: {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "Giantmonkey GmbH"
5
5
  },
6
6
  "license": "MIT",
7
- "version": "1.34.0",
7
+ "version": "1.35.0",
8
8
  "type": "module",
9
9
  "main": "./dist-js/gomus-webcomponents.iife.js",
10
10
  "module": "./dist-js/gomus-webcomponents.iife.js",