@cohostvip/cohost-react 0.2.1 → 0.2.2

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 React from 'react';
1
+ import * as React from 'react';
2
2
  import type { CartSession, Customer, PersonAddress, UpdatableCartSession } from '@cohostvip/cohost-node';
3
3
  export type CohostCheckoutProviderProps = {
4
4
  cartSessionId: string;
@@ -7,7 +7,13 @@ export type CohostCheckoutProviderProps = {
7
7
  export type CohostCheckoutContextType = {
8
8
  cartSessionId: string;
9
9
  cartSession: CartSession | null;
10
- joinGroup: (groupId: string) => Promise<string | null>;
10
+ joinGroup: (groupId: string) => Promise<{
11
+ itemId: string | null;
12
+ error?: {
13
+ message: string;
14
+ status?: number;
15
+ };
16
+ }>;
11
17
  updateItem: (offeringId: string, quantity: number, options?: any) => Promise<void>;
12
18
  incrementItem: (offeringId: string, options?: any) => Promise<void>;
13
19
  decrementItem: (offeringId: string) => Promise<void>;
@@ -18,7 +24,6 @@ export type CohostCheckoutContextType = {
18
24
  removeCoupon: (id: string) => Promise<void>;
19
25
  setCustomer: (customer: Partial<Customer>) => Promise<void>;
20
26
  setBillingAddress: (address: Partial<PersonAddress>) => Promise<void>;
21
- preValidate: (data: unknown) => Promise<unknown>;
22
27
  };
23
28
  export declare const CohostCheckoutContext: React.Context<CohostCheckoutContextType | null>;
24
29
  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,KAAwD,MAAM,OAAO,CAAC;AAE7E,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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,IAAI,EAAE,OAAO,CAAC,oBAAoB,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1E,UAAU,EAAE,MAAM,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IACnD,cAAc,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACpD,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,WAAW,EAAE,CAAC,QAAQ,EAAE,OAAO,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;CACzE,CAAC;AAGF,eAAO,MAAM,qBAAqB,iDAAwD,CAAC;AAE3F,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CA4OxE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,QAAO,yBAIpC,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import React, { createContext, useContext, useEffect, useMemo } from 'react';
2
+ import * as React from 'react';
3
+ import { createContext, useContext, useEffect } from 'react';
3
4
  import { useCohostClient } from './CohostContext';
4
5
  export const CohostCheckoutContext = createContext(null);
5
6
  export const CohostCheckoutProvider = ({ cartSessionId, children, }) => {
@@ -33,28 +34,25 @@ export const CohostCheckoutProvider = ({ cartSessionId, children, }) => {
33
34
  throw error;
34
35
  }
35
36
  };
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
- };
46
37
  const joinGroup = async (groupId) => {
47
38
  assertCartSession();
48
39
  try {
49
40
  const updatedCart = await client.cart.joinTableCommitment(cartSessionId, groupId);
50
41
  setCartSession(updatedCart);
51
- return updatedCart
42
+ const itemId = updatedCart
52
43
  .items
53
44
  .find((item) => item.tableCommitmentId === groupId)?.id || null;
45
+ return { itemId };
54
46
  }
55
47
  catch (error) {
56
48
  console.error("Error joining group:", error);
57
- return null;
49
+ return {
50
+ itemId: null,
51
+ error: {
52
+ message: error?.message || 'Failed to join group',
53
+ status: error?.status || error?.response?.status,
54
+ },
55
+ };
58
56
  }
59
57
  };
60
58
  const updateItem = async (itemId, quantity, options) => {
@@ -129,15 +127,14 @@ export const CohostCheckoutProvider = ({ cartSessionId, children, }) => {
129
127
  };
130
128
  const setBillingAddress = async (address) => {
131
129
  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
- };
138
130
  const customer = {
139
131
  ...cartSession?.customer,
140
- billingAddress,
132
+ 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
+ },
141
138
  };
142
139
  return setCustomer(customer);
143
140
  };
@@ -179,26 +176,24 @@ export const CohostCheckoutProvider = ({ cartSessionId, children, }) => {
179
176
  };
180
177
  fetchCartSession();
181
178
  }, [cartSessionId]);
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 }));
179
+ return (_jsx(CohostCheckoutContext.Provider, { value: {
180
+ cartSessionId,
181
+ cartSession,
182
+ /**
183
+ * Item quantity management
184
+ */
185
+ updateItem,
186
+ incrementItem,
187
+ decrementItem,
188
+ updateCartSession,
189
+ placeOrder,
190
+ joinGroup,
191
+ processPayment,
192
+ applyCoupon,
193
+ removeCoupon,
194
+ setCustomer,
195
+ setBillingAddress,
196
+ }, children: children }));
202
197
  };
203
198
  /**
204
199
  * Hook to access the current CohostCheckoutContext
@@ -1,32 +1 @@
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
- };
32
1
  //# sourceMappingURL=useCohostStartCheckout.d.ts.map
@@ -1 +1 @@
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
+ {"version":3,"file":"useCohostStartCheckout.d.ts","sourceRoot":"","sources":["../../src/hooks/useCohostStartCheckout.ts"],"names":[],"mappings":""}
@@ -1,66 +1 @@
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
- };
1
+ "use strict";
package/dist/index.d.ts CHANGED
@@ -5,6 +5,5 @@ 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';
9
8
  export { formatCurrency } from './lib/utils';
10
9
  //# 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,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,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,cAAc,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -4,5 +4,4 @@ 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';
8
7
  export { formatCurrency } from './lib/utils';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cohostvip/cohost-react",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "React bindings for the Cohost API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -35,19 +35,18 @@
35
35
  "@types/react": "19.2.0",
36
36
  "@types/react-dom": "19.2.0",
37
37
  "jsdom": "26.0.0",
38
- "react": "catalog:frontend",
39
- "react-dom": "catalog:frontend",
40
38
  "typescript": "5.9.3",
41
39
  "vitest": "^3.2.0"
42
40
  },
43
41
  "repository": {
44
42
  "type": "git",
45
- "url": "https://github.com/cohostvip/cohost-react.git"
43
+ "url": "https://github.com/cohostvip/cohost-js.git",
44
+ "directory": "packages/react"
46
45
  },
47
46
  "bugs": {
48
- "url": "https://github.com/cohostvip/cohost-react/issues"
47
+ "url": "https://github.com/cohostvip/cohost-js/issues"
49
48
  },
50
- "homepage": "https://github.com/cohostvip/cohost-react",
49
+ "homepage": "https://github.com/cohostvip/cohost-js/tree/main/packages/react",
51
50
  "author": "Cohost <support@cohost.vip> (https://cohost.vip)",
52
51
  "license": "MIT",
53
52
  "publishConfig": {