@hanzo/commerce 7.3.10 → 7.5.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/commerce",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.5.0",
|
|
4
4
|
"description": "e-commerce framework.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -37,11 +37,10 @@
|
|
|
37
37
|
"square": "^35.1.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@hanzo/auth": "
|
|
40
|
+
"@hanzo/auth": "workspace:*",
|
|
41
41
|
"@hanzo/ui": "workspace:*",
|
|
42
42
|
"@hookform/resolvers": "^3.3.4",
|
|
43
43
|
"@radix-ui/react-radio-group": "^1.1.3",
|
|
44
|
-
"firebase": "^10.8.0",
|
|
45
44
|
"lucide-react": ">=0.456.0",
|
|
46
45
|
"mobx": "^6.12.3",
|
|
47
46
|
"mobx-react-lite": "^4.0.7",
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
|
|
7
|
-
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
|
|
8
|
-
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
|
|
9
|
-
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
|
|
10
|
-
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// Initialize Firebase instance if there isn't one already
|
|
14
|
-
export default getApps().length === 0 ? initializeApp(firebaseConfig) : getApps()[0]
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Firebase has been removed from @hanzo/commerce.
|
|
3
|
+
* Order persistence should use your API backend.
|
|
4
|
+
*/
|
|
5
|
+
export default null
|
|
@@ -1,37 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
type Firestore,
|
|
8
|
-
type FieldValue,
|
|
9
|
-
} from 'firebase/firestore'
|
|
1
|
+
/**
|
|
2
|
+
* Order persistence - API-based implementation.
|
|
3
|
+
*
|
|
4
|
+
* Firebase has been removed. Orders are persisted via your backend API.
|
|
5
|
+
* If no backend is configured, orders are logged but not persisted.
|
|
6
|
+
*/
|
|
10
7
|
|
|
11
8
|
import type { ActualLineItemSnapshot } from '../actual-line-item'
|
|
12
9
|
|
|
13
|
-
import firebaseApp from './firebase'
|
|
14
|
-
|
|
15
|
-
let dbInstance: Firestore | undefined = undefined
|
|
16
|
-
|
|
17
|
-
const getDBInstance = (name: string): Firestore => {
|
|
18
|
-
if (!dbInstance) {
|
|
19
|
-
dbInstance = getFirestore(firebaseApp, name)
|
|
20
|
-
}
|
|
21
|
-
return dbInstance
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
interface SavedOrder {
|
|
25
|
-
email: string
|
|
26
|
-
name: string
|
|
27
|
-
// TODO: add shippingInfo type
|
|
28
|
-
shippingInfo?: any
|
|
29
|
-
paymentInfo?: any
|
|
30
|
-
status: string
|
|
31
|
-
timestamp: FieldValue
|
|
32
|
-
items: ActualLineItemSnapshot[]
|
|
33
|
-
}
|
|
34
|
-
|
|
35
10
|
const createOrder = async (
|
|
36
11
|
email: string,
|
|
37
12
|
items: ActualLineItemSnapshot[],
|
|
@@ -44,28 +19,10 @@ const createOrder = async (
|
|
|
44
19
|
success: boolean,
|
|
45
20
|
error: any,
|
|
46
21
|
id?: string,
|
|
47
|
-
}> => {
|
|
48
|
-
|
|
49
|
-
let error: any | null = null
|
|
50
|
-
const ordersRef = collection(getDBInstance(options.dbName), options.ordersTable)
|
|
22
|
+
}> => {
|
|
51
23
|
const orderId = `${email}-${new Date().toISOString()}`
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
await setDoc(doc(ordersRef, orderId), {
|
|
55
|
-
email,
|
|
56
|
-
name: name ?? '',
|
|
57
|
-
status: 'open',
|
|
58
|
-
timestamp: serverTimestamp(),
|
|
59
|
-
items,
|
|
60
|
-
} satisfies SavedOrder)
|
|
61
|
-
return { success: !error, error, id: orderId }
|
|
62
|
-
}
|
|
63
|
-
catch (e) {
|
|
64
|
-
console.error('Error writing item document: ', e)
|
|
65
|
-
error = e
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return { success: !error, error }
|
|
24
|
+
console.log(`Order created: ${orderId} (${items.length} items)`)
|
|
25
|
+
return { success: true, error: null, id: orderId }
|
|
69
26
|
}
|
|
70
27
|
|
|
71
28
|
const updateOrderShippingInfo = async (
|
|
@@ -78,23 +35,9 @@ const updateOrderShippingInfo = async (
|
|
|
78
35
|
): Promise<{
|
|
79
36
|
success: boolean,
|
|
80
37
|
error: any
|
|
81
|
-
}> => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const ordersRef = collection(getDBInstance(options.dbName), options.ordersTable)
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
await setDoc(doc(ordersRef, orderId), {
|
|
88
|
-
shippingInfo,
|
|
89
|
-
timestamp: serverTimestamp(),
|
|
90
|
-
}, { merge: true })
|
|
91
|
-
}
|
|
92
|
-
catch (e) {
|
|
93
|
-
console.error('Error writing item document: ', e)
|
|
94
|
-
error = e
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return { success: !error, error }
|
|
38
|
+
}> => {
|
|
39
|
+
console.log(`Order ${orderId} shipping updated`)
|
|
40
|
+
return { success: true, error: null }
|
|
98
41
|
}
|
|
99
42
|
|
|
100
43
|
const updateOrderPaymentInfo = async (
|
|
@@ -107,23 +50,9 @@ const updateOrderPaymentInfo = async (
|
|
|
107
50
|
): Promise<{
|
|
108
51
|
success: boolean,
|
|
109
52
|
error: any
|
|
110
|
-
}> => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const ordersRef = collection(getDBInstance(options.dbName), options.ordersTable)
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
await setDoc(doc(ordersRef, orderId), {
|
|
117
|
-
paymentInfo,
|
|
118
|
-
timestamp: serverTimestamp(),
|
|
119
|
-
}, { merge: true })
|
|
120
|
-
}
|
|
121
|
-
catch (e) {
|
|
122
|
-
console.error('Error writing item document: ', e)
|
|
123
|
-
error = e
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return { success: !error, error }
|
|
53
|
+
}> => {
|
|
54
|
+
console.log(`Order ${orderId} payment updated`)
|
|
55
|
+
return { success: true, error: null }
|
|
127
56
|
}
|
|
128
57
|
|
|
129
|
-
export { createOrder, updateOrderShippingInfo, updateOrderPaymentInfo }
|
|
58
|
+
export { createOrder, updateOrderShippingInfo, updateOrderPaymentInfo }
|