@cohostvip/cohost-react 0.1.13 → 0.1.15

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
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"authnet.d.ts","sourceRoot":"","sources":["../../../src/lib/tokenizers/authnet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,SAAS,EAAE,MAAM,SAAS,CAAC;AAE3D,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,MAAM,CAAC,EAAE,GAAG,CAAC;KAChB;CACJ;AAiDD,QAAA,MAAM,gBAAgB,EAAE,SAGvB,CAAA;AACD,OAAO,EACH,gBAAgB,EACnB,CAAA"}
1
+ {"version":3,"file":"authnet.d.ts","sourceRoot":"","sources":["../../../src/lib/tokenizers/authnet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,SAAS,EAAE,MAAM,SAAS,CAAC;AAE3D,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,MAAM,CAAC,EAAE,GAAG,CAAC;KAChB;CACJ;AAoDD,QAAA,MAAM,gBAAgB,EAAE,SAGvB,CAAA;AACD,OAAO,EACH,gBAAgB,EACnB,CAAA"}
@@ -29,11 +29,13 @@ const tokenizeCard = async (cardInfo, paymentIntent) => {
29
29
  };
30
30
  const registerScripts = () => {
31
31
  const scriptId = 'authnet-accept-js';
32
+ // const testingUrl = 'https://jstest.authorize.net/v1/Accept.js';
33
+ const productionUrl = 'https://js.authorize.net/v1/Accept.js';
32
34
  // Only add if not already in the DOM
33
35
  if (!document.getElementById(scriptId)) {
34
36
  const script = document.createElement('script');
35
37
  script.id = scriptId;
36
- script.src = 'https://jstest.authorize.net/v1/Accept.js';
38
+ script.src = productionUrl;
37
39
  script.async = true;
38
40
  document.body.appendChild(script);
39
41
  }
@@ -0,0 +1,41 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,31 @@
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
+ };
@@ -0,0 +1,3 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,37 @@
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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cohostvip/cohost-react",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
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.12"
30
+ "@cohostvip/cohost-node": "^0.1.15"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@testing-library/jest-dom": "6.6.3",
@@ -64,4 +64,4 @@
64
64
  "sdk",
65
65
  "typescript"
66
66
  ]
67
- }
67
+ }