@gomusdev/web-components 4.13.1 → 4.14.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.
@@ -2,6 +2,18 @@ import { SegmentDetails } from '../../../../components/ticketSelection/subcompon
2
2
  import { TicketSelectionDetails } from '../../../../components/ticketSelection/TicketSelectionDetails.svelte.ts';
3
3
  import { UITicket } from '../../../../lib/models/ticket/UITicket.svelte.ts';
4
4
  import { DateDetails, Quotas } from '@gomus/types';
5
+ /**
6
+ * The common tail of every ticket filter's `addToCart`: given the ticket
7
+ * its loader resolved, build the cart line, reject if the ticket is unavailable
8
+ * (sold out / unknown → the loader yielded nothing) or the quantity exceeds the
9
+ * remaining capacity, add the line, and return its uuid. Subtype-agnostic — the
10
+ * per-filter loader is the only thing that differs.
11
+ */
12
+ export declare function addResolvedTicketToCart(ticket: UITicket | undefined, { id, quantity, time }: {
13
+ id: number;
14
+ quantity: number;
15
+ time?: string;
16
+ }): string;
5
17
  /**
6
18
  * When a segment opts into content attributes (with-content), batch-fetch
7
19
  * tickets/content for the given tickets and merge each entry's `content` onto
@@ -1,4 +1,4 @@
1
1
  import { FilterModule, FilterName } from './types.ts';
2
2
  export declare function getFilter(name: FilterName): FilterModule;
3
3
  export declare function allFilters(): FilterModule[];
4
- export declare const validFilterNames: readonly ["ticket:timeslot", "ticket:day", "ticket:annual", "event:admission", "event:admission:day", "event:admission:timeslot", "event:price", "events:admission", "events:admission:day", "events:admission:timeslot", "events:price", "coupon"];
4
+ export declare const validFilterNames: readonly ["ticket:timeslot", "ticket:day", "ticket:annual", "event:admission", "event:admission:day", "event:admission:timeslot", "event:price", "events:admission", "events:admission:day", "events:admission:timeslot", "events:price", "coupon", "tour"];
@@ -0,0 +1,3 @@
1
+ import { FilterModule } from './types.ts';
2
+ declare const filter: FilterModule;
3
+ export default filter;
@@ -1,6 +1,6 @@
1
1
  import { TicketSelectionDetails } from '../../../../components/ticketSelection/TicketSelectionDetails.svelte.ts';
2
2
  import { SegmentDetails } from '../../../../components/ticketSelection/subcomponents/tickets/subcomponents/segment/SegmentDetails.svelte.ts';
3
- export declare const FILTER_NAMES: readonly ["ticket:timeslot", "ticket:day", "ticket:annual", "event:admission", "event:admission:day", "event:admission:timeslot", "event:price", "events:admission", "events:admission:day", "events:admission:timeslot", "events:price", "coupon"];
3
+ export declare const FILTER_NAMES: readonly ["ticket:timeslot", "ticket:day", "ticket:annual", "event:admission", "event:admission:day", "event:admission:timeslot", "event:price", "events:admission", "events:admission:day", "events:admission:timeslot", "events:price", "coupon", "tour"];
4
4
  export type FilterName = (typeof FILTER_NAMES)[number];
5
5
  export type Required = {
6
6
  kind: 'tsd';
@@ -10,6 +10,13 @@ export type Required = {
10
10
  field: keyof SegmentDetails;
11
11
  };
12
12
  export type CalendarEndpoint = 'tickets' | 'events' | null;
13
+ /**
14
+ * Args a filter's `addToCart` receives — the public `go.cart.addItem` options
15
+ * minus `filter`. Deliberately loose: each product kind carries different fields
16
+ * (a ticket has id/quantity/date|time; a tour has participants/languageId/…), so
17
+ * the receiving filter reads and validates the fields it needs.
18
+ */
19
+ export type AddToCartOptions = Record<string, unknown>;
13
20
  export interface FilterModule {
14
21
  name: FilterName;
15
22
  isCalendarVisible(tsd: TicketSelectionDetails): boolean;
@@ -17,6 +24,16 @@ export interface FilterModule {
17
24
  isTicketsVisible(tsd: TicketSelectionDetails): boolean;
18
25
  loadProducts(segment: SegmentDetails): Promise<void>;
19
26
  loadTimeslots(tsd: TicketSelectionDetails): Promise<void>;
27
+ /**
28
+ * Add ONE product straight to the cart — the headless entry behind the public
29
+ * `go.cart.addItem({ filter, … })` API. The filter owns its kind end-to-end:
30
+ * validate the args it needs, resolve the product (fetch by id / build from
31
+ * the given attributes), capacity-gate where it applies, add the line, and
32
+ * return its uuid. Throws on invalid args or an unavailable product. Optional
33
+ * because not every filter is addable (coupon / the event listings aren't yet);
34
+ * `go.cart.addItem` rejects a `filter` that doesn't implement it.
35
+ */
36
+ addToCart?(options: AddToCartOptions): Promise<string>;
20
37
  calendarEndpoint: CalendarEndpoint;
21
38
  apiToken?: string;
22
39
  requires: ReadonlyArray<Required>;
@@ -7,7 +7,7 @@ type TourOrderItem = Extract<OrderItem, {
7
7
  type: 'Tour';
8
8
  }>;
9
9
  export declare const TourFactories: {
10
- /** The camelCase options an integrator passes to go.cart.addTour. */
10
+ /** The camelCase attributes an integrator passes under go.cart.addItem({ filter: 'tour', … }). */
11
11
  addTourOptions(overrides?: Partial<AddTourOptionsShape>): AddTourOptionsShape;
12
12
  /** A UITour product with a fixed instanceKey for stable uuids/snapshots. */
13
13
  tour(overrides?: Partial<TourAttributes>, instanceKey?: string): {
@@ -1,19 +1,21 @@
1
- import { TourAttributes } from '../../lib/models/tour/UITour.svelte.ts';
1
+ import { FilterName } from '../../components/ticketSelection/filters/types.ts';
2
2
  /**
3
- * Options for go.cart.addTour (WI #128). camelCase like #129's addTicket;
4
- * the snake_case wire translation happens inside createUITour.
5
- */
6
- export type AddTourOptions = TourAttributes & {
7
- /** ISO date-time of the tour start — becomes tour_cart_item.start_time. */
8
- time: string;
9
- };
10
- /**
11
- * Adds a group-tour booking to the cart and resolves with the cart line's
12
- * uuid. Every call appends a NEW line — identical bookings coexist; use the
13
- * returned uuid to deduplicate or remove.
3
+ * Options for `go.cart.addItem` the one generic "add a product to the cart"
4
+ * call. `filter` names the registry filter that knows how to resolve and add
5
+ * that product kind; the remaining fields are that filter's own args, which it
6
+ * validates. Filter names are part of the public API:
7
+ *
8
+ * go.cart.addItem({ filter: 'ticket:day', id, quantity, date })
9
+ * go.cart.addItem({ filter: 'ticket:timeslot', id, quantity, time })
10
+ * go.cart.addItem({ filter: 'ticket:annual', id, quantity })
11
+ * go.cart.addItem({ filter: 'tour', id, time, participants, languageId, totalPriceCents, title, })
14
12
  *
15
- * Tours are not priced by the shop API: `totalPriceCents` is the
16
- * integrator-supplied booking total (incl. mandatory surcharges) and is
17
- * verified by the backend only at checkout.
13
+ * New product kinds are added by giving their filter an `addToCart` no change
14
+ * here (WI #129; replaces the per-product addTicket/addTour).
18
15
  */
19
- export declare function addTour(options: AddTourOptions): Promise<string>;
16
+ export type AddItemOptions = {
17
+ filter: FilterName;
18
+ } & Record<string, unknown>;
19
+ /** Resolves with the new cart line's uuid. Throws if the filter can't add to
20
+ * the cart, or on the filter's own validation / availability errors. */
21
+ export declare function addItem({ filter, ...options }: AddItemOptions): Promise<string>;
@@ -1,9 +1,9 @@
1
1
  import { CustomerAddressesResult, CustomerMembershipsResult, OrdersResult, ValidateTokenResult } from '../../lib/stores/shop.svelte.ts';
2
2
  import { OrdersParams } from '@gomus/types';
3
- import { AddTourOptions } from '../../go/cart.ts';
3
+ import { AddItemOptions } from '../../go/cart.ts';
4
4
  export type { CustomerAddressesResult, CustomerMembershipsResult, OrdersResult, ValidateTokenResult, } from '../../lib/stores/shop.svelte.ts';
5
5
  export type Command = {
6
- method: 'load' | 'config' | 'init' | 'cart.addTour' | (string & {});
6
+ method: 'load' | 'config' | 'init' | 'cart.addItem' | (string & {});
7
7
  options: Record<string, unknown>;
8
8
  };
9
9
  export declare function initGo(window: {
@@ -24,7 +24,7 @@ export declare const go: {
24
24
  getCustomerMemberships: () => Promise<CustomerMembershipsResult>;
25
25
  };
26
26
  cart: {
27
- addTour: (options: AddTourOptions) => Promise<string>;
27
+ addItem: (options: AddItemOptions) => Promise<string>;
28
28
  };
29
29
  };
30
30
  export type Go = typeof go;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Group-tour product added programmatically via go.cart.addTour (WI #128).
2
+ * Group-tour product added programmatically via go.cart.addItem({ filter: 'tour', … }) (WI #128).
3
3
  *
4
4
  * Tours are not priced by the shop API: POST /api/v4/cart echoes tour lines
5
5
  * verbatim, so `totalPriceCents` is the integrator-supplied booking total
@@ -48,7 +48,7 @@ export declare function isUITour(x: {
48
48
  } | null | undefined): x is UITour;
49
49
  interface Options {
50
50
  /**
51
- * Uniqueness key for the cart-line uuid. Every addTour call appends a NEW
51
+ * Uniqueness key for the cart-line uuid. Every tour add appends a NEW
52
52
  * cart line (no merge — locked contract), so each UITour needs its own key;
53
53
  * it is persisted with the product so rehydrated lines keep their identity.
54
54
  * Overridable for deterministic factories/specs.
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "Giantmonkey GmbH"
5
5
  },
6
6
  "license": "MIT",
7
- "version": "4.13.1",
7
+ "version": "4.14.0",
8
8
  "type": "module",
9
9
  "main": "./dist-js/gomus-webcomponents.iife.js",
10
10
  "module": "./dist-js/gomus-webcomponents.iife.js",