@cohostvip/cohost-react 0.1.14 → 0.1.16

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,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import type { CartSession, UpdatableCartSession } from '@cohostvip/cohost-node';
2
+ import type { CartSession, Customer, PersonAddress, UpdatableCartSession } from '@cohostvip/cohost-node';
3
3
  export type CohostCheckoutProviderProps = {
4
4
  cartSessionId: string;
5
5
  children: React.ReactNode;
@@ -14,6 +14,8 @@ export type CohostCheckoutContextType = {
14
14
  processPayment: (data: unknown) => Promise<unknown>;
15
15
  applyCoupon: (code: string) => Promise<void>;
16
16
  removeCoupon: (id: string) => Promise<void>;
17
+ setCustomer: (customer: Partial<Customer>) => Promise<void>;
18
+ setBillingAddress: (address: Partial<PersonAddress>) => Promise<void>;
17
19
  };
18
20
  export declare const CohostCheckoutContext: React.Context<CohostCheckoutContextType | null>;
19
21
  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,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAEhF,MAAM,MAAM,2BAA2B,GAAG;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACvD,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,QAA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vD,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACnF,iBAAiB,EAAE,CAAC,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,CAmLxE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,QAAO,yBAIpC,CAAC"}
@@ -68,6 +68,34 @@ export const CohostCheckoutProvider = ({ cartSessionId, children, }) => {
68
68
  console.error("Error updating cart session:", error);
69
69
  }
70
70
  };
71
+ const setCustomer = async (customer) => {
72
+ assertCartSession();
73
+ try {
74
+ const updatedCart = await client.cart.update(cartSessionId, {
75
+ customer: {
76
+ ...cartSession?.customer,
77
+ ...customer,
78
+ },
79
+ });
80
+ setCartSession(updatedCart);
81
+ }
82
+ catch (error) {
83
+ console.error("Error setting customer:", error);
84
+ }
85
+ };
86
+ const setBillingAddress = async (address) => {
87
+ assertCartSession();
88
+ const customer = {
89
+ ...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
+ },
96
+ };
97
+ return setCustomer(customer);
98
+ };
71
99
  const placeOrder = async () => {
72
100
  assertCartSession();
73
101
  try {
@@ -116,6 +144,8 @@ export const CohostCheckoutProvider = ({ cartSessionId, children, }) => {
116
144
  processPayment,
117
145
  applyCoupon,
118
146
  removeCoupon,
147
+ setCustomer,
148
+ setBillingAddress,
119
149
  }, children: children }));
120
150
  };
121
151
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cohostvip/cohost-react",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "React bindings for the Cohost API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -27,7 +27,7 @@
27
27
  "react-dom": "^18.0.0 || ^19.0.0"
28
28
  },
29
29
  "dependencies": {
30
- "@cohostvip/cohost-node": "^0.1.14"
30
+ "@cohostvip/cohost-node": "^0.1.16"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@testing-library/jest-dom": "6.6.3",