@gomusdev/web-components 4.4.0 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.5.0 (2026-07-13)
4
+
5
+ ### Features
6
+
7
+ * **checkout:** split guest and signed-in checkout, gated by go-if, closes [#data](https://gitlab.giantmonkey.de/gomus/frontend/issues/data)
8
+
3
9
  ## 4.4.0 (2026-07-13)
4
10
 
5
11
  ### Features
@@ -0,0 +1 @@
1
+ export { SvelteComponent as default } from 'svelte';
@@ -0,0 +1 @@
1
+ export { SvelteComponent as default } from 'svelte';
@@ -6554,12 +6554,12 @@ createHTML: (html) => {
6554
6554
  //#endregion
6555
6555
  //#region src/lib/stores/auth.svelte.ts
6556
6556
  var Auth = class {
6557
- #data = {
6557
+ #data = /* @__PURE__ */ state(proxy({
6558
6558
  uid: "",
6559
6559
  client: "",
6560
6560
  accessToken: "",
6561
6561
  expiry: 0
6562
- };
6562
+ }));
6563
6563
  constructor() {
6564
6564
  this.load();
6565
6565
  if (typeof window !== "undefined") window.addEventListener("storage", (e) => {
@@ -6571,34 +6571,39 @@ createHTML: (html) => {
6571
6571
  if (this.isLoggedIn()) return 20;
6572
6572
  }
6573
6573
  isAuthenticated() {
6574
- return this.#data.uid !== "";
6574
+ return this.data.uid !== "";
6575
6575
  }
6576
6576
  isLoggedIn() {
6577
- return Boolean(this.#data.uid && isEmail(this.#data.uid));
6577
+ return Boolean(this.data.uid && isEmail(this.data.uid));
6578
6578
  }
6579
6579
  isGuest() {
6580
- return Boolean(this.#data.uid && !isEmail(this.#data.uid));
6580
+ return Boolean(this.data.uid && !isEmail(this.data.uid));
6581
6581
  }
6582
6582
  signOut() {
6583
- this.#data.uid = "";
6584
- this.#data.client = "";
6585
- this.#data.accessToken = "";
6586
- this.#data.expiry = 0;
6583
+ get$2(this.#data).uid = "";
6584
+ get$2(this.#data).client = "";
6585
+ get$2(this.#data).accessToken = "";
6586
+ get$2(this.#data).expiry = 0;
6587
6587
  this.save();
6588
6588
  }
6589
6589
  signIn(options) {
6590
- this.#data.uid = options.uid;
6591
- this.#data.client = options.client;
6592
- this.#data.accessToken = options.accessToken;
6593
- this.#data.expiry = options.expiry;
6590
+ get$2(this.#data).uid = options.uid;
6591
+ get$2(this.#data).client = options.client;
6592
+ get$2(this.#data).accessToken = options.accessToken;
6593
+ get$2(this.#data).expiry = options.expiry;
6594
6594
  this.save();
6595
6595
  }
6596
6596
  get data() {
6597
- if (this.#data.expiry < Math.floor(Date.now() / 1e3)) this.signOut();
6598
- return this.#data;
6597
+ if (get$2(this.#data).uid !== "" && get$2(this.#data).expiry < Math.floor(Date.now() / 1e3)) return {
6598
+ uid: "",
6599
+ client: "",
6600
+ accessToken: "",
6601
+ expiry: 0
6602
+ };
6603
+ return get$2(this.#data);
6599
6604
  }
6600
6605
  toString() {
6601
- return JSON.stringify(this.#data);
6606
+ return JSON.stringify(get$2(this.#data));
6602
6607
  }
6603
6608
  save() {
6604
6609
  if (typeof localStorage === "undefined") return;
@@ -6613,6 +6618,10 @@ createHTML: (html) => {
6613
6618
  }
6614
6619
  const d = JSON.parse(str);
6615
6620
  if (!(isObject$2(d) && "uid" in d && "client" in d && "accessToken" in d && "expiry" in d)) throw new Error(`(Auth.loadFromString) invalid auth json ${str}`);
6621
+ if (d.uid !== "" && d.expiry < Math.floor(Date.now() / 1e3)) {
6622
+ this.signOut();
6623
+ return;
6624
+ }
6616
6625
  this.signIn(d);
6617
6626
  }
6618
6627
  };
@@ -18331,11 +18340,23 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
18331
18340
  }
18332
18341
  customElements.define("go-cart-counter", create_custom_element(CartCounter, {}, [], []));
18333
18342
  //#endregion
18334
- //#region src/components/checkoutForm/CheckoutForm.svelte
18335
- function CheckoutForm($$anchor, $$props) {
18336
- push($$props, true);
18337
- let custom = prop($$props, "custom", 7, false);
18338
- let cart = /* @__PURE__ */ user_derived(() => shop.cart);
18343
+ //#region src/components/checkoutForm/lib.ts
18344
+ async function finalizeCheckout(form, formId) {
18345
+ const cart = shop.cart;
18346
+ if (!cart) return;
18347
+ const paymentMode = form.details.fieldValue("paymentMode");
18348
+ cart.paymentModeId = paymentMode == null ? void 0 : String(paymentMode);
18349
+ const checkout = await shop.checkout(cart.orderData());
18350
+ if (checkout.error) {
18351
+ form.details.apiErrors = checkout.error;
18352
+ return;
18353
+ }
18354
+ const beforeSubmit = configStore.config.forms[formId]?.beforeSubmit;
18355
+ if (beforeSubmit) await beforeSubmit(form.details.formData);
18356
+ const paymentUrl = checkout.data.meta.payment_url;
18357
+ configStore.config.navigateTo?.(paymentUrl);
18358
+ }
18359
+ function setupGuestCheckout(host, custom) {
18339
18360
  Forms.defineForm({
18340
18361
  id: "checkoutGuest",
18341
18362
  submitLabel: "cart.detail.actions.checkout",
@@ -18366,30 +18387,48 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
18366
18387
  }
18367
18388
  ]
18368
18389
  });
18369
- wrapInElement($$props.$$host, "go-form", {
18390
+ wrapInElement(host, "go-form", {
18370
18391
  "form-id": "checkoutGuest",
18371
- custom: custom()
18392
+ custom
18372
18393
  });
18373
- $$props.$$host.addEventListener("submit", async (e) => {
18394
+ host.addEventListener("submit", async (e) => {
18374
18395
  const form = e.target;
18375
- if (!get$2(cart)) return;
18396
+ if (!shop.cart) return;
18376
18397
  const auth = await shop.signUp(form.details.formData, true);
18377
18398
  if (auth.error) {
18378
18399
  form.details.apiErrors = auth.error.errors;
18379
18400
  return;
18380
18401
  }
18381
- const paymentMode = form.details.fieldValue("paymentMode");
18382
- get$2(cart).paymentModeId = paymentMode == null ? void 0 : String(paymentMode);
18383
- const checkout = await shop.checkout(get$2(cart).orderData());
18384
- if (checkout.error) {
18385
- form.details.apiErrors = checkout.error;
18386
- return;
18387
- }
18388
- const beforeSubmit = configStore.config.forms.checkoutGuest?.beforeSubmit;
18389
- if (beforeSubmit) await beforeSubmit(form.details.formData);
18390
- const paymentUrl = checkout.data.meta.payment_url;
18391
- configStore.config.navigateTo?.(paymentUrl);
18402
+ await finalizeCheckout(form, "checkoutGuest");
18403
+ });
18404
+ }
18405
+ function setupUserCheckout(host, custom) {
18406
+ Forms.defineForm({
18407
+ id: "checkoutUser",
18408
+ submitLabel: "cart.detail.actions.checkout",
18409
+ fields: [{
18410
+ key: "acceptTerms",
18411
+ required: true
18412
+ }, {
18413
+ key: "paymentMode",
18414
+ required: true
18415
+ }]
18416
+ });
18417
+ wrapInElement(host, "go-form", {
18418
+ "form-id": "checkoutUser",
18419
+ custom
18420
+ });
18421
+ host.addEventListener("submit", async (e) => {
18422
+ const form = e.target;
18423
+ await finalizeCheckout(form, "checkoutUser");
18392
18424
  });
18425
+ }
18426
+ //#endregion
18427
+ //#region src/components/checkoutForm/CheckoutForm.svelte
18428
+ function CheckoutForm($$anchor, $$props) {
18429
+ push($$props, true);
18430
+ let custom = prop($$props, "custom", 7, false);
18431
+ setupGuestCheckout($$props.$$host, custom());
18393
18432
  return pop({
18394
18433
  get custom() {
18395
18434
  return custom();
@@ -18402,6 +18441,40 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
18402
18441
  }
18403
18442
  customElements.define("go-checkout-form", create_custom_element(CheckoutForm, { custom: {} }, [], []));
18404
18443
  //#endregion
18444
+ //#region src/components/checkoutForm/CheckoutGuest.svelte
18445
+ function CheckoutGuest($$anchor, $$props) {
18446
+ push($$props, true);
18447
+ let custom = prop($$props, "custom", 7, false);
18448
+ setupGuestCheckout($$props.$$host, custom());
18449
+ return pop({
18450
+ get custom() {
18451
+ return custom();
18452
+ },
18453
+ set custom($$value = false) {
18454
+ custom($$value);
18455
+ flushSync();
18456
+ }
18457
+ });
18458
+ }
18459
+ customElements.define("go-checkout-guest", create_custom_element(CheckoutGuest, { custom: {} }, [], []));
18460
+ //#endregion
18461
+ //#region src/components/checkoutForm/CheckoutUser.svelte
18462
+ function CheckoutUser($$anchor, $$props) {
18463
+ push($$props, true);
18464
+ let custom = prop($$props, "custom", 7, false);
18465
+ setupUserCheckout($$props.$$host, custom());
18466
+ return pop({
18467
+ get custom() {
18468
+ return custom();
18469
+ },
18470
+ set custom($$value = false) {
18471
+ custom($$value);
18472
+ flushSync();
18473
+ }
18474
+ });
18475
+ }
18476
+ customElements.define("go-checkout-user", create_custom_element(CheckoutUser, { custom: {} }, [], []));
18477
+ //#endregion
18405
18478
  //#region src/components/couponRedemption/lib.ts
18406
18479
  var APPLY_ORDER_DISCOUNT = "TokenActions::ApplyOrderDiscount";
18407
18480
  async function redeem(token) {
@@ -35760,12 +35833,18 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
35760
35833
  const formDetails = /* @__PURE__ */ user_derived(() => _formDetails.value);
35761
35834
  const _cartView = getCartDetails($$props.$$host);
35762
35835
  const cartView = /* @__PURE__ */ user_derived(() => _cartView.value);
35836
+ const auth = shop.auth;
35763
35837
  let data = /* @__PURE__ */ user_derived(() => ({
35764
35838
  ticketSelection: get$2(ticketSelectionDetails),
35765
35839
  personalizationDetails: get$2(personalizationDetails),
35766
35840
  formData: get$2(formDetails)?.formData,
35767
35841
  cart: shop.cart,
35768
- cartView: get$2(cartView)
35842
+ cartView: get$2(cartView),
35843
+ auth: {
35844
+ isAuthenticated: auth.isAuthenticated(),
35845
+ isLoggedIn: auth.isLoggedIn(),
35846
+ isGuest: auth.isGuest()
35847
+ }
35769
35848
  }));
35770
35849
  const _setData = (_data) => {
35771
35850
  set(data, _data);
@@ -6553,12 +6553,12 @@ var assign = (initial, override) => {
6553
6553
  //#endregion
6554
6554
  //#region src/lib/stores/auth.svelte.ts
6555
6555
  var Auth = class {
6556
- #data = {
6556
+ #data = /* @__PURE__ */ state(proxy({
6557
6557
  uid: "",
6558
6558
  client: "",
6559
6559
  accessToken: "",
6560
6560
  expiry: 0
6561
- };
6561
+ }));
6562
6562
  constructor() {
6563
6563
  this.load();
6564
6564
  if (typeof window !== "undefined") window.addEventListener("storage", (e) => {
@@ -6570,34 +6570,39 @@ var Auth = class {
6570
6570
  if (this.isLoggedIn()) return 20;
6571
6571
  }
6572
6572
  isAuthenticated() {
6573
- return this.#data.uid !== "";
6573
+ return this.data.uid !== "";
6574
6574
  }
6575
6575
  isLoggedIn() {
6576
- return Boolean(this.#data.uid && isEmail(this.#data.uid));
6576
+ return Boolean(this.data.uid && isEmail(this.data.uid));
6577
6577
  }
6578
6578
  isGuest() {
6579
- return Boolean(this.#data.uid && !isEmail(this.#data.uid));
6579
+ return Boolean(this.data.uid && !isEmail(this.data.uid));
6580
6580
  }
6581
6581
  signOut() {
6582
- this.#data.uid = "";
6583
- this.#data.client = "";
6584
- this.#data.accessToken = "";
6585
- this.#data.expiry = 0;
6582
+ get$2(this.#data).uid = "";
6583
+ get$2(this.#data).client = "";
6584
+ get$2(this.#data).accessToken = "";
6585
+ get$2(this.#data).expiry = 0;
6586
6586
  this.save();
6587
6587
  }
6588
6588
  signIn(options) {
6589
- this.#data.uid = options.uid;
6590
- this.#data.client = options.client;
6591
- this.#data.accessToken = options.accessToken;
6592
- this.#data.expiry = options.expiry;
6589
+ get$2(this.#data).uid = options.uid;
6590
+ get$2(this.#data).client = options.client;
6591
+ get$2(this.#data).accessToken = options.accessToken;
6592
+ get$2(this.#data).expiry = options.expiry;
6593
6593
  this.save();
6594
6594
  }
6595
6595
  get data() {
6596
- if (this.#data.expiry < Math.floor(Date.now() / 1e3)) this.signOut();
6597
- return this.#data;
6596
+ if (get$2(this.#data).uid !== "" && get$2(this.#data).expiry < Math.floor(Date.now() / 1e3)) return {
6597
+ uid: "",
6598
+ client: "",
6599
+ accessToken: "",
6600
+ expiry: 0
6601
+ };
6602
+ return get$2(this.#data);
6598
6603
  }
6599
6604
  toString() {
6600
- return JSON.stringify(this.#data);
6605
+ return JSON.stringify(get$2(this.#data));
6601
6606
  }
6602
6607
  save() {
6603
6608
  if (typeof localStorage === "undefined") return;
@@ -6612,6 +6617,10 @@ var Auth = class {
6612
6617
  }
6613
6618
  const d = JSON.parse(str);
6614
6619
  if (!(isObject$2(d) && "uid" in d && "client" in d && "accessToken" in d && "expiry" in d)) throw new Error(`(Auth.loadFromString) invalid auth json ${str}`);
6620
+ if (d.uid !== "" && d.expiry < Math.floor(Date.now() / 1e3)) {
6621
+ this.signOut();
6622
+ return;
6623
+ }
6615
6624
  this.signIn(d);
6616
6625
  }
6617
6626
  };
@@ -18330,11 +18339,23 @@ function CartCounter($$anchor, $$props) {
18330
18339
  }
18331
18340
  customElements.define("go-cart-counter", create_custom_element(CartCounter, {}, [], []));
18332
18341
  //#endregion
18333
- //#region src/components/checkoutForm/CheckoutForm.svelte
18334
- function CheckoutForm($$anchor, $$props) {
18335
- push($$props, true);
18336
- let custom = prop($$props, "custom", 7, false);
18337
- let cart = /* @__PURE__ */ user_derived(() => shop.cart);
18342
+ //#region src/components/checkoutForm/lib.ts
18343
+ async function finalizeCheckout(form, formId) {
18344
+ const cart = shop.cart;
18345
+ if (!cart) return;
18346
+ const paymentMode = form.details.fieldValue("paymentMode");
18347
+ cart.paymentModeId = paymentMode == null ? void 0 : String(paymentMode);
18348
+ const checkout = await shop.checkout(cart.orderData());
18349
+ if (checkout.error) {
18350
+ form.details.apiErrors = checkout.error;
18351
+ return;
18352
+ }
18353
+ const beforeSubmit = configStore.config.forms[formId]?.beforeSubmit;
18354
+ if (beforeSubmit) await beforeSubmit(form.details.formData);
18355
+ const paymentUrl = checkout.data.meta.payment_url;
18356
+ configStore.config.navigateTo?.(paymentUrl);
18357
+ }
18358
+ function setupGuestCheckout(host, custom) {
18338
18359
  Forms.defineForm({
18339
18360
  id: "checkoutGuest",
18340
18361
  submitLabel: "cart.detail.actions.checkout",
@@ -18365,30 +18386,48 @@ function CheckoutForm($$anchor, $$props) {
18365
18386
  }
18366
18387
  ]
18367
18388
  });
18368
- wrapInElement($$props.$$host, "go-form", {
18389
+ wrapInElement(host, "go-form", {
18369
18390
  "form-id": "checkoutGuest",
18370
- custom: custom()
18391
+ custom
18371
18392
  });
18372
- $$props.$$host.addEventListener("submit", async (e) => {
18393
+ host.addEventListener("submit", async (e) => {
18373
18394
  const form = e.target;
18374
- if (!get$2(cart)) return;
18395
+ if (!shop.cart) return;
18375
18396
  const auth = await shop.signUp(form.details.formData, true);
18376
18397
  if (auth.error) {
18377
18398
  form.details.apiErrors = auth.error.errors;
18378
18399
  return;
18379
18400
  }
18380
- const paymentMode = form.details.fieldValue("paymentMode");
18381
- get$2(cart).paymentModeId = paymentMode == null ? void 0 : String(paymentMode);
18382
- const checkout = await shop.checkout(get$2(cart).orderData());
18383
- if (checkout.error) {
18384
- form.details.apiErrors = checkout.error;
18385
- return;
18386
- }
18387
- const beforeSubmit = configStore.config.forms.checkoutGuest?.beforeSubmit;
18388
- if (beforeSubmit) await beforeSubmit(form.details.formData);
18389
- const paymentUrl = checkout.data.meta.payment_url;
18390
- configStore.config.navigateTo?.(paymentUrl);
18401
+ await finalizeCheckout(form, "checkoutGuest");
18402
+ });
18403
+ }
18404
+ function setupUserCheckout(host, custom) {
18405
+ Forms.defineForm({
18406
+ id: "checkoutUser",
18407
+ submitLabel: "cart.detail.actions.checkout",
18408
+ fields: [{
18409
+ key: "acceptTerms",
18410
+ required: true
18411
+ }, {
18412
+ key: "paymentMode",
18413
+ required: true
18414
+ }]
18415
+ });
18416
+ wrapInElement(host, "go-form", {
18417
+ "form-id": "checkoutUser",
18418
+ custom
18419
+ });
18420
+ host.addEventListener("submit", async (e) => {
18421
+ const form = e.target;
18422
+ await finalizeCheckout(form, "checkoutUser");
18391
18423
  });
18424
+ }
18425
+ //#endregion
18426
+ //#region src/components/checkoutForm/CheckoutForm.svelte
18427
+ function CheckoutForm($$anchor, $$props) {
18428
+ push($$props, true);
18429
+ let custom = prop($$props, "custom", 7, false);
18430
+ setupGuestCheckout($$props.$$host, custom());
18392
18431
  return pop({
18393
18432
  get custom() {
18394
18433
  return custom();
@@ -18401,6 +18440,40 @@ function CheckoutForm($$anchor, $$props) {
18401
18440
  }
18402
18441
  customElements.define("go-checkout-form", create_custom_element(CheckoutForm, { custom: {} }, [], []));
18403
18442
  //#endregion
18443
+ //#region src/components/checkoutForm/CheckoutGuest.svelte
18444
+ function CheckoutGuest($$anchor, $$props) {
18445
+ push($$props, true);
18446
+ let custom = prop($$props, "custom", 7, false);
18447
+ setupGuestCheckout($$props.$$host, custom());
18448
+ return pop({
18449
+ get custom() {
18450
+ return custom();
18451
+ },
18452
+ set custom($$value = false) {
18453
+ custom($$value);
18454
+ flushSync();
18455
+ }
18456
+ });
18457
+ }
18458
+ customElements.define("go-checkout-guest", create_custom_element(CheckoutGuest, { custom: {} }, [], []));
18459
+ //#endregion
18460
+ //#region src/components/checkoutForm/CheckoutUser.svelte
18461
+ function CheckoutUser($$anchor, $$props) {
18462
+ push($$props, true);
18463
+ let custom = prop($$props, "custom", 7, false);
18464
+ setupUserCheckout($$props.$$host, custom());
18465
+ return pop({
18466
+ get custom() {
18467
+ return custom();
18468
+ },
18469
+ set custom($$value = false) {
18470
+ custom($$value);
18471
+ flushSync();
18472
+ }
18473
+ });
18474
+ }
18475
+ customElements.define("go-checkout-user", create_custom_element(CheckoutUser, { custom: {} }, [], []));
18476
+ //#endregion
18404
18477
  //#region src/components/couponRedemption/lib.ts
18405
18478
  var APPLY_ORDER_DISCOUNT = "TokenActions::ApplyOrderDiscount";
18406
18479
  async function redeem(token) {
@@ -35759,12 +35832,18 @@ function If($$anchor, $$props) {
35759
35832
  const formDetails = /* @__PURE__ */ user_derived(() => _formDetails.value);
35760
35833
  const _cartView = getCartDetails($$props.$$host);
35761
35834
  const cartView = /* @__PURE__ */ user_derived(() => _cartView.value);
35835
+ const auth = shop.auth;
35762
35836
  let data = /* @__PURE__ */ user_derived(() => ({
35763
35837
  ticketSelection: get$2(ticketSelectionDetails),
35764
35838
  personalizationDetails: get$2(personalizationDetails),
35765
35839
  formData: get$2(formDetails)?.formData,
35766
35840
  cart: shop.cart,
35767
- cartView: get$2(cartView)
35841
+ cartView: get$2(cartView),
35842
+ auth: {
35843
+ isAuthenticated: auth.isAuthenticated(),
35844
+ isLoggedIn: auth.isLoggedIn(),
35845
+ isGuest: auth.isGuest()
35846
+ }
35768
35847
  }));
35769
35848
  const _setData = (_data) => {
35770
35849
  set(data, _data);