@cohostvip/cohost-react 0.1.17 → 0.2.1

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,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import type { CartSession, Customer, PersonAddress, UpdatableCartSession } from '@cohostvip/cohost-node';
3
3
  export type CohostCheckoutProviderProps = {
4
4
  cartSessionId: string;
@@ -9,6 +9,8 @@ export type CohostCheckoutContextType = {
9
9
  cartSession: CartSession | null;
10
10
  joinGroup: (groupId: string) => Promise<string | null>;
11
11
  updateItem: (offeringId: string, quantity: number, options?: any) => Promise<void>;
12
+ incrementItem: (offeringId: string, options?: any) => Promise<void>;
13
+ decrementItem: (offeringId: string) => Promise<void>;
12
14
  updateCartSession: (data: Partial<UpdatableCartSession>) => Promise<void>;
13
15
  placeOrder: () => Promise<CartSession | undefined>;
14
16
  processPayment: (data: unknown) => Promise<unknown>;
@@ -16,6 +18,7 @@ export type CohostCheckoutContextType = {
16
18
  removeCoupon: (id: string) => Promise<void>;
17
19
  setCustomer: (customer: Partial<Customer>) => Promise<void>;
18
20
  setBillingAddress: (address: Partial<PersonAddress>) => Promise<void>;
21
+ preValidate: (data: unknown) => Promise<unknown>;
19
22
  };
20
23
  export declare const CohostCheckoutContext: React.Context<CohostCheckoutContextType | null>;
21
24
  export declare const CohostCheckoutProvider: React.FC<CohostCheckoutProviderProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"CohostCheckoutContext.d.ts","sourceRoot":"","sources":["../../src/context/CohostCheckoutContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAEzG,MAAM,MAAM,2BAA2B,GAAG;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,KAAK,CAAC,S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CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D,iBAAiB,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtE,WAAW,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACpD,CAAC;AAGF,eAAO,MAAM,qBAAqB,iDAAwD,CAAC;AAE3F,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CAmPxE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,QAAO,yBAIpC,CAAC"}
@@ -1,6 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import * as React from 'react';
3
- import { createContext, useContext, useEffect } from 'react';
2
+ import React, { createContext, useContext, useEffect, useMemo } from 'react';
4
3
  import { useCohostClient } from './CohostContext';
5
4
  export const CohostCheckoutContext = createContext(null);
6
5
  export const CohostCheckoutProvider = ({ cartSessionId, children, }) => {
@@ -34,6 +33,16 @@ export const CohostCheckoutProvider = ({ cartSessionId, children, }) => {
34
33
  throw error;
35
34
  }
36
35
  };
36
+ const preValidate = async (data) => {
37
+ assertCartSession();
38
+ try {
39
+ return client.cart.preValidate(cartSessionId, data);
40
+ }
41
+ catch (error) {
42
+ console.error("Error removing coupon:", error);
43
+ throw error;
44
+ }
45
+ };
37
46
  const joinGroup = async (groupId) => {
38
47
  assertCartSession();
39
48
  try {
@@ -58,6 +67,41 @@ export const CohostCheckoutProvider = ({ cartSessionId, children, }) => {
58
67
  console.error("Error updating cart item:", error);
59
68
  }
60
69
  };
70
+ const incrementItem = async (itemId, options) => {
71
+ assertCartSession();
72
+ try {
73
+ const item = cartSession?.items.find(item => item.id === itemId);
74
+ if (!item) {
75
+ return;
76
+ }
77
+ const qty = Math.max(item.quantity + 1, item.offering?.minimumQuantity || 1);
78
+ if (item.offering?.maximumQuantity && qty > item.offering.maximumQuantity) {
79
+ return;
80
+ }
81
+ if (item.quantity !== qty) {
82
+ await updateItem(itemId, qty, options);
83
+ }
84
+ }
85
+ catch (error) {
86
+ console.error("Error incrementing cart item:", error);
87
+ }
88
+ };
89
+ const decrementItem = async (itemId) => {
90
+ assertCartSession();
91
+ try {
92
+ const item = cartSession?.items.find(item => item.id === itemId);
93
+ if (!item) {
94
+ return;
95
+ }
96
+ const qty = item.quantity === (item.offering.minimumQuantity || 1) ? 0 : item.quantity - 1;
97
+ if (item.quantity !== qty) {
98
+ await updateItem(itemId, qty);
99
+ }
100
+ }
101
+ catch (error) {
102
+ console.error("Error decrementing cart item:", error);
103
+ }
104
+ };
61
105
  const updateCartSession = async (data) => {
62
106
  assertCartSession();
63
107
  try {
@@ -85,14 +129,15 @@ export const CohostCheckoutProvider = ({ cartSessionId, children, }) => {
85
129
  };
86
130
  const setBillingAddress = async (address) => {
87
131
  assertCartSession();
132
+ const billingAddress = {
133
+ ...cartSession?.customer?.billingAddress,
134
+ ...address,
135
+ first: address.first || cartSession?.customer?.billingAddress?.first || cartSession?.customer?.first || '',
136
+ last: address.last || cartSession?.customer?.billingAddress?.last || cartSession?.customer?.last || '',
137
+ };
88
138
  const customer = {
89
139
  ...cartSession?.customer,
90
- billingAddress: {
91
- ...cartSession?.customer?.billingAddress,
92
- ...address,
93
- first: address.first || cartSession?.customer?.billingAddress?.first || cartSession?.customer?.first || '',
94
- last: address.last || cartSession?.customer?.billingAddress?.last || cartSession?.customer?.last || '',
95
- },
140
+ billingAddress,
96
141
  };
97
142
  return setCustomer(customer);
98
143
  };
@@ -134,19 +179,26 @@ export const CohostCheckoutProvider = ({ cartSessionId, children, }) => {
134
179
  };
135
180
  fetchCartSession();
136
181
  }, [cartSessionId]);
137
- return (_jsx(CohostCheckoutContext.Provider, { value: {
138
- cartSessionId,
139
- cartSession,
140
- updateItem,
141
- updateCartSession,
142
- placeOrder,
143
- joinGroup,
144
- processPayment,
145
- applyCoupon,
146
- removeCoupon,
147
- setCustomer,
148
- setBillingAddress,
149
- }, children: children }));
182
+ const stateValue = useMemo(() => ({
183
+ cartSessionId,
184
+ cartSession,
185
+ joinGroup,
186
+ updateItem,
187
+ incrementItem,
188
+ decrementItem,
189
+ updateCartSession,
190
+ placeOrder,
191
+ processPayment,
192
+ applyCoupon,
193
+ removeCoupon,
194
+ setCustomer,
195
+ setBillingAddress,
196
+ preValidate,
197
+ }), [
198
+ cartSessionId,
199
+ cartSession,
200
+ ]);
201
+ return (_jsx(CohostCheckoutContext.Provider, { value: stateValue, children: children }));
150
202
  };
151
203
  /**
152
204
  * Hook to access the current CohostCheckoutContext
@@ -1 +1,32 @@
1
+ export interface StartCheckoutOptions {
2
+ items: Array<{
3
+ offeringId: string;
4
+ quantity: number;
5
+ options?: Record<string, any>;
6
+ }>;
7
+ }
8
+ /**
9
+ * Hook to start the checkout process.
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * const { startCheckout, isStarting } = useCohostStartCheckout();
14
+ *
15
+ * const handleCheckout = async () => {
16
+ * const cartSessionId = await startCheckout({
17
+ * items: [
18
+ * { offeringId: 'ticket_123', quantity: 2 }
19
+ * ]
20
+ * });
21
+ *
22
+ * if (cartSessionId) {
23
+ * router.push(`/checkout/${cartSessionId}`);
24
+ * }
25
+ * };
26
+ * ```
27
+ */
28
+ export declare const useCohostStartCheckout: () => {
29
+ startCheckout: (options: StartCheckoutOptions) => Promise<string | null>;
30
+ contextId: string;
31
+ };
1
32
  //# sourceMappingURL=useCohostStartCheckout.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCohostStartCheckout.d.ts","sourceRoot":"","sources":["../../src/hooks/useCohostStartCheckout.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"useCohostStartCheckout.d.ts","sourceRoot":"","sources":["../../src/hooks/useCohostStartCheckout.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,oBAAoB;IACjC,KAAK,EAAE,KAAK,CAAC;QACT,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KACjC,CAAC,CAAC;CACN;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,sBAAsB;6BAgBO,oBAAoB,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;;CAgCtF,CAAC"}
@@ -1 +1,66 @@
1
- "use strict";
1
+ import { useContext } from 'react';
2
+ import { CohostStartCheckoutContext } from '../context/CohostStartCheckoutContext';
3
+ import { useCohostClient } from '../context/CohostContext';
4
+ /**
5
+ * Hook to start the checkout process.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * const { startCheckout, isStarting } = useCohostStartCheckout();
10
+ *
11
+ * const handleCheckout = async () => {
12
+ * const cartSessionId = await startCheckout({
13
+ * items: [
14
+ * { offeringId: 'ticket_123', quantity: 2 }
15
+ * ]
16
+ * });
17
+ *
18
+ * if (cartSessionId) {
19
+ * router.push(`/checkout/${cartSessionId}`);
20
+ * }
21
+ * };
22
+ * ```
23
+ */
24
+ export const useCohostStartCheckout = () => {
25
+ const ctx = useContext(CohostStartCheckoutContext);
26
+ const { client } = useCohostClient();
27
+ if (!ctx) {
28
+ throw new Error('useCohostStartCheckout must be used within a CohostStartCheckoutProvider');
29
+ }
30
+ const { contextId, getCartSessionId } = ctx;
31
+ /**
32
+ * Start the checkout process by creating a cart session and adding items to it.
33
+ *
34
+ * @param options - The items to add to the cart
35
+ * @returns The cart session ID or null if the operation failed
36
+ */
37
+ const startCheckout = async (options) => {
38
+ try {
39
+ // Get or create a cart session
40
+ let cartSessionId = await getCartSessionId();
41
+ if (!cartSessionId) {
42
+ console.error('Failed to create cart session');
43
+ return null;
44
+ }
45
+ // Add items to the cart session
46
+ for (const item of options.items) {
47
+ if (item.quantity > 0) {
48
+ await client.cart.updateItem(cartSessionId, {
49
+ itemId: item.offeringId,
50
+ quantity: item.quantity,
51
+ options: item.options,
52
+ });
53
+ }
54
+ }
55
+ return cartSessionId;
56
+ }
57
+ catch (error) {
58
+ console.error('Error starting checkout:', error);
59
+ return null;
60
+ }
61
+ };
62
+ return {
63
+ startCheckout,
64
+ contextId,
65
+ };
66
+ };
package/dist/index.d.ts CHANGED
@@ -5,5 +5,6 @@ export { PaymentElementProvider, usePaymentElement } from './context/PaymentElem
5
5
  export { CohostStartCheckoutProvider } from './provider/CohostStartCheckoutProvider';
6
6
  export { CreditCardInformation } from './lib/tokenizers/types';
7
7
  export { useCohost } from './hooks/useCohost';
8
+ export { useCohostStartCheckout } from './hooks/useCohostStartCheckout';
8
9
  export { formatCurrency } from './lib/utils';
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACnH,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAC5F,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAC;AACrF,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACnH,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAC5F,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAC;AACrF,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -4,4 +4,5 @@ export { CohostProvider } from './context/CohostContext';
4
4
  export { PaymentElementProvider, usePaymentElement } from './context/PaymentElementContext';
5
5
  export { CohostStartCheckoutProvider } from './provider/CohostStartCheckoutProvider';
6
6
  export { useCohost } from './hooks/useCohost';
7
+ export { useCohostStartCheckout } from './hooks/useCohostStartCheckout';
7
8
  export { formatCurrency } from './lib/utils';
@@ -1,2 +1,2 @@
1
- export declare const formatCurrency: (value: string) => string;
1
+ export declare const formatCurrency: (value?: string, defaultValue?: string) => string;
2
2
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,MAW9C,CAAA"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,EAAE,eAAe,MAAM,KAAG,MAatE,CAAA"}
package/dist/lib/utils.js CHANGED
@@ -1,4 +1,6 @@
1
- export const formatCurrency = (value) => {
1
+ export const formatCurrency = (value, defaultValue) => {
2
+ if (!value)
3
+ return defaultValue || '';
2
4
  const [currency, amount] = value.split(',');
3
5
  const formatter = new Intl.NumberFormat('en-US', {
4
6
  style: 'currency',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cohostvip/cohost-react",
3
- "version": "0.1.17",
3
+ "version": "0.2.1",
4
4
  "description": "React bindings for the Cohost API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -27,15 +27,17 @@
27
27
  "react-dom": "^18.0.0 || ^19.0.0"
28
28
  },
29
29
  "dependencies": {
30
- "@cohostvip/cohost-node": "^0.1.16"
30
+ "@cohostvip/cohost-node": "^0.2.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@testing-library/jest-dom": "6.6.3",
34
34
  "@testing-library/react": "^16.3.0",
35
- "@types/react": "19.0.10",
36
- "@types/react-dom": "19.0.4",
35
+ "@types/react": "19.2.0",
36
+ "@types/react-dom": "19.2.0",
37
37
  "jsdom": "26.0.0",
38
- "typescript": "5.8.2",
38
+ "react": "catalog:frontend",
39
+ "react-dom": "catalog:frontend",
40
+ "typescript": "5.9.3",
39
41
  "vitest": "^3.2.0"
40
42
  },
41
43
  "repository": {
@@ -1,41 +0,0 @@
1
- /**
2
- * A pre-parsed human-friendly representation of a date and time.
3
- */
4
- export interface StructuredDate {
5
- /** Formatted date strings. */
6
- date: {
7
- /** Full format, e.g., "Tuesday, October 3". */
8
- EEEEMMMMd: string;
9
- /** Short weekday/month/day, e.g., "Tue, Oct. 3". */
10
- EEEMMMd: string;
11
- /** Long date format, e.g., "Tuesday, October 3, 2023". */
12
- long: string;
13
- /** Short numeric format, e.g., "10/03/2023". */
14
- short: string;
15
- };
16
- /** Time string (e.g., "3:00 PM"). */
17
- time: string;
18
- /** UTC timestamp (e.g., "2006-10-25T12:00:00Z"). */
19
- utc: string;
20
- /** IANA timezone (e.g., "America/New_York"). */
21
- timezone: string;
22
- /** Local timestamp (e.g., "2006-10-25T12:00:00-04:00"). */
23
- local: string;
24
- /** Whether this date is in the future. */
25
- upcoming: boolean;
26
- /** Duration details from now to the date. */
27
- duration: {
28
- days: number;
29
- hours: number;
30
- minutes: number;
31
- weeks: number;
32
- months: number;
33
- };
34
- }
35
- export interface StructuredCost {
36
- currency: string;
37
- formatted: string;
38
- value: number;
39
- majorValue: number;
40
- }
41
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,8BAA8B;IAC9B,IAAI,EAAE;QACJ,+CAA+C;QAC/C,SAAS,EAAE,MAAM,CAAC;QAElB,oDAAoD;QACpD,OAAO,EAAE,MAAM,CAAC;QAEhB,0DAA0D;QAC1D,IAAI,EAAE,MAAM,CAAC;QAEb,gDAAgD;QAChD,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IAEF,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IAEb,oDAAoD;IACpD,GAAG,EAAE,MAAM,CAAC;IAEZ,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC;IAEjB,2DAA2D;IAC3D,KAAK,EAAE,MAAM,CAAC;IAEd,0CAA0C;IAC1C,QAAQ,EAAE,OAAO,CAAC;IAElB,6CAA6C;IAC7C,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAGD,MAAM,WAAW,cAAc;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACtB"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,7 +0,0 @@
1
- import { StructuredCost } from "../types";
2
- export declare const formatCost: (currency: string, amount: number, option?: {
3
- valueBase?: "major" | "minor";
4
- }) => string;
5
- export declare const toStructuredCost: (cost: string) => StructuredCost | undefined;
6
- export declare const toStructuredCosts: <T extends { [K in keyof T]: string; }>(costs: T) => { [K in keyof T]: StructuredCost | null; };
7
- //# sourceMappingURL=cost.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../../src/utils/cost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1C,eAAO,MAAM,UAAU,GAAI,UAAU,MAAM,EAAE,QAAQ,MAAM,EAAE,SAAS;IAClE,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;CACjC,KAAG,MAAyF,CAAC;AAO9F,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,KAAG,cAAc,GAAG,SAoBhE,CAAC;AAGF,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,GAAE,EAClE,OAAO,CAAC,KACT,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,cAAc,GAAG,IAAI,GASzC,CAAC"}
@@ -1,31 +0,0 @@
1
- export const formatCost = (currency, amount, option) => `${currency},${Math.round(amount * (option?.valueBase === 'major' ? 100 : 1))}`;
2
- const costValue = (cost) => {
3
- const [currency, value] = cost.split(",");
4
- return Number(value);
5
- };
6
- export const toStructuredCost = (cost) => {
7
- if (!cost || !cost.includes(","))
8
- return undefined;
9
- const [currency, strValue] = cost.split(",");
10
- const value = Number(strValue);
11
- const majorValue = value / 100;
12
- const formatted = majorValue.toLocaleString("en-US", {
13
- style: "currency",
14
- currency,
15
- // minimumFractionDigits: 0
16
- });
17
- return {
18
- currency,
19
- value,
20
- majorValue,
21
- formatted,
22
- };
23
- };
24
- export const toStructuredCosts = (costs) => {
25
- const result = {};
26
- for (const key in costs) {
27
- const cost = costs[key];
28
- result[key] = toStructuredCost(cost) ?? null;
29
- }
30
- return result;
31
- };
@@ -1,3 +0,0 @@
1
- import { StructuredDate } from '@guestwho/types/interfaces/common';
2
- export declare const getStructuredDate: (input: Date | string, timezone: string | null) => StructuredDate;
3
- //# sourceMappingURL=dates.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dates.d.ts","sourceRoot":"","sources":["../../src/utils/dates.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAGnE,eAAO,MAAM,iBAAiB,GAC1B,OAAO,IAAI,GAAG,MAAM,EACpB,UAAU,MAAM,GAAG,IAAI,KACxB,cA4CF,CAAC"}
@@ -1,37 +0,0 @@
1
- import { DateTime } from 'luxon';
2
- export const getStructuredDate = (input, timezone) => {
3
- // Convert to Luxon DateTime, assuming input is UTC if string
4
- const parsed = typeof input === 'string'
5
- ? DateTime.fromISO(input, { zone: 'utc' }).setZone(timezone || DateTime.local().zoneName)
6
- : DateTime.fromJSDate(input, { zone: timezone || DateTime.local().zoneName });
7
- // Check for invalid date
8
- if (!parsed.isValid) {
9
- throw new Error(`Invalid date input: "${input}". Details: ${parsed.invalidExplanation}`);
10
- }
11
- // Check for invalid timezone (e.g., if Luxon silently falls back to local)
12
- if (timezone !== null && parsed.zoneName !== timezone) {
13
- throw new Error(`Invalid timezone: "${timezone}"`);
14
- }
15
- const now = DateTime.now();
16
- const diff = parsed.diff(now, ['days', 'hours', 'minutes', 'months', 'weeks']);
17
- return {
18
- duration: {
19
- days: diff.days,
20
- hours: diff.hours,
21
- minutes: diff.minutes,
22
- weeks: diff.weeks,
23
- months: diff.months,
24
- },
25
- upcoming: parsed > now,
26
- date: {
27
- EEEEMMMMd: parsed.toFormat('EEEE, MMMM d'),
28
- EEEMMMd: parsed.toFormat("EEE, MMM'.' d"),
29
- long: parsed.toFormat('EEEE, MMMM d, yyyy'),
30
- short: parsed.toFormat('MM/dd/yyyy'),
31
- },
32
- time: parsed.toFormat('h:mm a'),
33
- utc: parsed.toUTC().toISO() ?? '',
34
- timezone: parsed.zoneName,
35
- local: parsed.toISO() ?? '',
36
- };
37
- };