@cohostvip/cohost-react 0.1.17 → 0.2.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.
@@ -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>;
@@ -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,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,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,CA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
  };
61
+ const incrementItem = async (itemId, options) => {
62
+ assertCartSession();
63
+ try {
64
+ const item = cartSession?.items.find(item => item.id === itemId);
65
+ if (!item) {
66
+ return;
67
+ }
68
+ const qty = Math.max(item.quantity + 1, item.offering?.minimumQuantity || 1);
69
+ if (item.offering?.maximumQuantity && qty > item.offering.maximumQuantity) {
70
+ return;
71
+ }
72
+ if (item.quantity !== qty) {
73
+ await updateItem(itemId, qty, options);
74
+ }
75
+ }
76
+ catch (error) {
77
+ console.error("Error incrementing cart item:", error);
78
+ }
79
+ };
80
+ const decrementItem = async (itemId) => {
81
+ assertCartSession();
82
+ try {
83
+ const item = cartSession?.items.find(item => item.id === itemId);
84
+ if (!item) {
85
+ return;
86
+ }
87
+ const qty = item.quantity === (item.offering.minimumQuantity || 1) ? 0 : item.quantity - 1;
88
+ if (item.quantity !== qty) {
89
+ await updateItem(itemId, qty);
90
+ }
91
+ }
92
+ catch (error) {
93
+ console.error("Error decrementing cart item:", error);
94
+ }
95
+ };
61
96
  const updateCartSession = async (data) => {
62
97
  assertCartSession();
63
98
  try {
@@ -137,7 +172,12 @@ export const CohostCheckoutProvider = ({ cartSessionId, children, }) => {
137
172
  return (_jsx(CohostCheckoutContext.Provider, { value: {
138
173
  cartSessionId,
139
174
  cartSession,
175
+ /**
176
+ * Item quantity management
177
+ */
140
178
  updateItem,
179
+ incrementItem,
180
+ decrementItem,
141
181
  updateCartSession,
142
182
  placeOrder,
143
183
  joinGroup,
@@ -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.0",
4
4
  "description": "React bindings for the Cohost API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -27,15 +27,15 @@
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
+ "typescript": "5.9.3",
39
39
  "vitest": "^3.2.0"
40
40
  },
41
41
  "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
- };