@payloadcms/plugin-ecommerce 4.0.0-internal.4a8e202 → 4.0.0-internal.4c2ee12
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/README.md +6 -0
- package/dist/collections/addresses/createAddressesCollection.d.ts.map +1 -1
- package/dist/collections/addresses/createAddressesCollection.js +1 -0
- package/dist/collections/addresses/createAddressesCollection.js.map +1 -1
- package/dist/collections/carts/beforeChange.d.ts.map +1 -1
- package/dist/collections/carts/beforeChange.js +2 -0
- package/dist/collections/carts/beforeChange.js.map +1 -1
- package/dist/collections/carts/createCartsCollection.d.ts.map +1 -1
- package/dist/collections/carts/createCartsCollection.js +1 -0
- package/dist/collections/carts/createCartsCollection.js.map +1 -1
- package/dist/collections/orders/createOrdersCollection.d.ts.map +1 -1
- package/dist/collections/orders/createOrdersCollection.js +1 -0
- package/dist/collections/orders/createOrdersCollection.js.map +1 -1
- package/dist/collections/products/createProductsCollection.d.ts.map +1 -1
- package/dist/collections/products/createProductsCollection.js +1 -0
- package/dist/collections/products/createProductsCollection.js.map +1 -1
- package/dist/collections/transactions/createTransactionsCollection.d.ts.map +1 -1
- package/dist/collections/transactions/createTransactionsCollection.js +1 -0
- package/dist/collections/transactions/createTransactionsCollection.js.map +1 -1
- package/dist/collections/variants/createVariantOptionsCollection.d.ts.map +1 -1
- package/dist/collections/variants/createVariantOptionsCollection.js +1 -0
- package/dist/collections/variants/createVariantOptionsCollection.js.map +1 -1
- package/dist/collections/variants/createVariantTypesCollection.d.ts.map +1 -1
- package/dist/collections/variants/createVariantTypesCollection.js +1 -0
- package/dist/collections/variants/createVariantTypesCollection.js.map +1 -1
- package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.d.ts.map +1 -1
- package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.js +2 -0
- package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.js.map +1 -1
- package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.d.ts.map +1 -1
- package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.js +1 -0
- package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.js.map +1 -1
- package/dist/collections/variants/createVariantsCollection/index.d.ts.map +1 -1
- package/dist/collections/variants/createVariantsCollection/index.js +1 -0
- package/dist/collections/variants/createVariantsCollection/index.js.map +1 -1
- package/dist/endpoints/confirmOrder.d.ts.map +1 -1
- package/dist/endpoints/confirmOrder.js +306 -44
- package/dist/endpoints/confirmOrder.js.map +1 -1
- package/dist/endpoints/initiatePayment.d.ts.map +1 -1
- package/dist/endpoints/initiatePayment.js +2 -0
- package/dist/endpoints/initiatePayment.js.map +1 -1
- package/dist/fields/statusField.d.ts.map +1 -1
- package/dist/fields/statusField.js +5 -0
- package/dist/fields/statusField.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/payments/adapters/stripe/confirmOrder.d.ts.map +1 -1
- package/dist/payments/adapters/stripe/confirmOrder.js +108 -75
- package/dist/payments/adapters/stripe/confirmOrder.js.map +1 -1
- package/dist/payments/adapters/stripe/initiatePayment.d.ts.map +1 -1
- package/dist/payments/adapters/stripe/initiatePayment.js +1 -0
- package/dist/payments/adapters/stripe/initiatePayment.js.map +1 -1
- package/dist/payments/adapters/stripe/validateSettlement.d.ts +37 -0
- package/dist/payments/adapters/stripe/validateSettlement.d.ts.map +1 -0
- package/dist/payments/adapters/stripe/validateSettlement.js +157 -0
- package/dist/payments/adapters/stripe/validateSettlement.js.map +1 -0
- package/dist/react/provider/index.d.ts.map +1 -1
- package/dist/react/provider/index.js +75 -34
- package/dist/react/provider/index.js.map +1 -1
- package/dist/types/index.d.ts +24 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/ui/VariantOptionsSelector/index.d.ts.map +1 -1
- package/dist/ui/VariantOptionsSelector/index.js +3 -1
- package/dist/ui/VariantOptionsSelector/index.js.map +1 -1
- package/package.json +10 -10
- package/dist/collections/carts/operations/defaultCartItemMatcher.spec.js +0 -358
- package/dist/collections/carts/operations/defaultCartItemMatcher.spec.js.map +0 -1
- package/dist/payments/adapters/stripe/confirmOrder.spec.js +0 -166
- package/dist/payments/adapters/stripe/confirmOrder.spec.js.map +0 -1
- package/dist/utilities/accessComposition.spec.js +0 -765
- package/dist/utilities/accessComposition.spec.js.map +0 -1
- package/dist/utilities/defaultProductsValidation.spec.js +0 -384
- package/dist/utilities/defaultProductsValidation.spec.js.map +0 -1
- package/dist/utilities/getCollectionSlugMap.spec.js +0 -254
- package/dist/utilities/getCollectionSlugMap.spec.js.map +0 -1
- package/dist/utilities/sanitizePluginConfig.spec.js +0 -516
- package/dist/utilities/sanitizePluginConfig.spec.js.map +0 -1
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
export const getRelationshipID = (value)=>{
|
|
2
|
+
const relationshipID = isRecord(value) ? value.id : value;
|
|
3
|
+
if (typeof relationshipID === 'number' && Number.isFinite(relationshipID)) {
|
|
4
|
+
return String(relationshipID);
|
|
5
|
+
}
|
|
6
|
+
if (typeof relationshipID === 'string' && relationshipID.trim()) {
|
|
7
|
+
return relationshipID;
|
|
8
|
+
}
|
|
9
|
+
return undefined;
|
|
10
|
+
};
|
|
11
|
+
export const normalizeEmail = (value)=>{
|
|
12
|
+
if (typeof value !== 'string') {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const normalizedEmail = value.trim().toLowerCase();
|
|
16
|
+
return normalizedEmail || undefined;
|
|
17
|
+
};
|
|
18
|
+
export const normalizeCartItems = (items)=>{
|
|
19
|
+
if (!Array.isArray(items) || items.length === 0) {
|
|
20
|
+
throw new Error('Cart items are missing or invalid');
|
|
21
|
+
}
|
|
22
|
+
return items.map((item)=>{
|
|
23
|
+
if (!isRecord(item)) {
|
|
24
|
+
throw new Error('Cart items are missing or invalid');
|
|
25
|
+
}
|
|
26
|
+
const productID = getRelationshipID(item.product);
|
|
27
|
+
if (!productID || typeof item.quantity !== 'number' || !Number.isFinite(item.quantity)) {
|
|
28
|
+
throw new Error('Cart items are missing or invalid');
|
|
29
|
+
}
|
|
30
|
+
return Object.fromEntries(Object.entries(item).flatMap(([key, value])=>{
|
|
31
|
+
if (key === 'product') {
|
|
32
|
+
return [
|
|
33
|
+
[
|
|
34
|
+
key,
|
|
35
|
+
productID
|
|
36
|
+
]
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
if (key === 'variant') {
|
|
40
|
+
if (value === null || value === undefined) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
const variantID = getRelationshipID(value);
|
|
44
|
+
if (!variantID) {
|
|
45
|
+
throw new Error('Cart item variant relationship is invalid');
|
|
46
|
+
}
|
|
47
|
+
return [
|
|
48
|
+
[
|
|
49
|
+
key,
|
|
50
|
+
variantID
|
|
51
|
+
]
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
const normalizedValue = normalizeValue(value);
|
|
55
|
+
return normalizedValue === undefined ? [] : [
|
|
56
|
+
[
|
|
57
|
+
key,
|
|
58
|
+
normalizedValue
|
|
59
|
+
]
|
|
60
|
+
];
|
|
61
|
+
}));
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
export const validateSettlement = ({ canonicalCartID, cartItemsSnapshot, customerEmail, paymentIntent, paymentIntentID, transaction, user })=>{
|
|
65
|
+
if (paymentIntentID !== getNestedString(transaction, 'stripe', 'paymentIntentID') || paymentIntentID !== paymentIntent.id) {
|
|
66
|
+
throw new Error('PaymentIntent does not match the transaction');
|
|
67
|
+
}
|
|
68
|
+
const normalizedCartID = getRelationshipID(canonicalCartID);
|
|
69
|
+
if (!normalizedCartID || normalizedCartID !== getRelationshipID(transaction.cart)) {
|
|
70
|
+
throw new Error('Canonical cart does not match the transaction cart');
|
|
71
|
+
}
|
|
72
|
+
const metadata = isRecord(paymentIntent.metadata) ? paymentIntent.metadata : undefined;
|
|
73
|
+
if (normalizedCartID !== getRelationshipID(metadata?.cartID)) {
|
|
74
|
+
throw new Error('Canonical cart does not match the PaymentIntent cart');
|
|
75
|
+
}
|
|
76
|
+
const transactionCustomerID = getRelationshipID(transaction.customer);
|
|
77
|
+
if (user !== null && user !== undefined) {
|
|
78
|
+
const authenticatedUserID = getRelationshipID(user.id);
|
|
79
|
+
if (!authenticatedUserID) {
|
|
80
|
+
throw new Error('Authenticated customer ID is missing or invalid');
|
|
81
|
+
}
|
|
82
|
+
if (transactionCustomerID !== authenticatedUserID) {
|
|
83
|
+
throw new Error('Authenticated customer does not match the transaction customer');
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
if (transactionCustomerID) {
|
|
87
|
+
throw new Error('Guest transaction belongs to an authenticated customer');
|
|
88
|
+
}
|
|
89
|
+
const normalizedCustomerEmail = normalizeEmail(customerEmail);
|
|
90
|
+
if (!normalizedCustomerEmail || normalizedCustomerEmail !== normalizeEmail(transaction.customerEmail)) {
|
|
91
|
+
throw new Error('Guest email does not match the transaction email');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const stripeCustomerID = getNestedString(transaction, 'stripe', 'customerID');
|
|
95
|
+
if (!stripeCustomerID || stripeCustomerID !== getRelationshipID(paymentIntent.customer)) {
|
|
96
|
+
throw new Error('Stripe customer does not match the transaction');
|
|
97
|
+
}
|
|
98
|
+
if (paymentIntent.amount !== transaction.amount) {
|
|
99
|
+
throw new Error('Stripe amount does not match the transaction amount');
|
|
100
|
+
}
|
|
101
|
+
if (typeof paymentIntent.currency !== 'string' || typeof transaction.currency !== 'string' || paymentIntent.currency.toUpperCase() !== transaction.currency) {
|
|
102
|
+
throw new Error('Stripe currency does not match the transaction currency');
|
|
103
|
+
}
|
|
104
|
+
const normalizedSnapshot = normalizeCartItems(cartItemsSnapshot);
|
|
105
|
+
const normalizedTransactionItems = normalizeCartItems(transaction.items);
|
|
106
|
+
if (stableSerialize(normalizedSnapshot) !== stableSerialize(normalizedTransactionItems)) {
|
|
107
|
+
throw new Error('Stripe cart items do not match the transaction items');
|
|
108
|
+
}
|
|
109
|
+
if (paymentIntent.status !== 'succeeded') {
|
|
110
|
+
throw new Error('Payment not completed.');
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const getNestedString = (value, groupName, fieldName)=>{
|
|
114
|
+
if (!isRecord(value)) {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
const group = value[groupName];
|
|
118
|
+
if (!isRecord(group) || typeof group[fieldName] !== 'string') {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
return group[fieldName];
|
|
122
|
+
};
|
|
123
|
+
const isRecord = (value)=>typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
124
|
+
const normalizeValue = (value)=>{
|
|
125
|
+
if (Array.isArray(value)) {
|
|
126
|
+
return value.map((entry)=>normalizeValue(entry));
|
|
127
|
+
}
|
|
128
|
+
if (isRecord(value)) {
|
|
129
|
+
return Object.fromEntries(Object.entries(value).flatMap(([entryKey, entryValue])=>{
|
|
130
|
+
const normalizedValue = normalizeValue(entryValue);
|
|
131
|
+
return normalizedValue === undefined ? [] : [
|
|
132
|
+
[
|
|
133
|
+
entryKey,
|
|
134
|
+
normalizedValue
|
|
135
|
+
]
|
|
136
|
+
];
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
if (value === null || typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string') {
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
if (value === undefined) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
throw new Error('Cart items contain unsupported data');
|
|
146
|
+
};
|
|
147
|
+
const stableSerialize = (value)=>{
|
|
148
|
+
if (Array.isArray(value)) {
|
|
149
|
+
return `[${value.map((entry)=>stableSerialize(entry)).join(',')}]`;
|
|
150
|
+
}
|
|
151
|
+
if (isRecord(value)) {
|
|
152
|
+
return `{${Object.keys(value).sort().map((key)=>`${JSON.stringify(key)}:${stableSerialize(value[key])}`).join(',')}}`;
|
|
153
|
+
}
|
|
154
|
+
return JSON.stringify(value);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
//# sourceMappingURL=validateSettlement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/payments/adapters/stripe/validateSettlement.ts"],"sourcesContent":["type RecordValue = Record<string, unknown>\n\ntype SettlementPaymentIntent = {\n amount?: unknown\n currency?: unknown\n customer?: unknown\n id?: unknown\n metadata?: unknown\n status?: unknown\n}\n\ntype SettlementTransaction = {\n amount?: unknown\n cart?: unknown\n currency?: unknown\n customer?: unknown\n customerEmail?: unknown\n id?: unknown\n items?: unknown\n order?: unknown\n status?: unknown\n stripe?: unknown\n}\n\ntype SettlementValidationArgs = {\n canonicalCartID: unknown\n cartItemsSnapshot: unknown\n customerEmail: unknown\n paymentIntent: SettlementPaymentIntent\n paymentIntentID: string\n transaction: SettlementTransaction\n user?: { id?: unknown } | null\n}\n\nexport const getRelationshipID = (value: unknown): string | undefined => {\n const relationshipID = isRecord(value) ? value.id : value\n\n if (typeof relationshipID === 'number' && Number.isFinite(relationshipID)) {\n return String(relationshipID)\n }\n\n if (typeof relationshipID === 'string' && relationshipID.trim()) {\n return relationshipID\n }\n\n return undefined\n}\n\nexport const normalizeEmail = (value: unknown): string | undefined => {\n if (typeof value !== 'string') {\n return undefined\n }\n\n const normalizedEmail = value.trim().toLowerCase()\n\n return normalizedEmail || undefined\n}\n\nexport const normalizeCartItems = (items: unknown): unknown[] => {\n if (!Array.isArray(items) || items.length === 0) {\n throw new Error('Cart items are missing or invalid')\n }\n\n return items.map((item) => {\n if (!isRecord(item)) {\n throw new Error('Cart items are missing or invalid')\n }\n\n const productID = getRelationshipID(item.product)\n\n if (!productID || typeof item.quantity !== 'number' || !Number.isFinite(item.quantity)) {\n throw new Error('Cart items are missing or invalid')\n }\n\n return Object.fromEntries(\n Object.entries(item).flatMap(([key, value]) => {\n if (key === 'product') {\n return [[key, productID]]\n }\n\n if (key === 'variant') {\n if (value === null || value === undefined) {\n return []\n }\n\n const variantID = getRelationshipID(value)\n\n if (!variantID) {\n throw new Error('Cart item variant relationship is invalid')\n }\n\n return [[key, variantID]]\n }\n\n const normalizedValue = normalizeValue(value)\n\n return normalizedValue === undefined ? [] : [[key, normalizedValue]]\n }),\n )\n })\n}\n\nexport const validateSettlement = ({\n canonicalCartID,\n cartItemsSnapshot,\n customerEmail,\n paymentIntent,\n paymentIntentID,\n transaction,\n user,\n}: SettlementValidationArgs): void => {\n if (\n paymentIntentID !== getNestedString(transaction, 'stripe', 'paymentIntentID') ||\n paymentIntentID !== paymentIntent.id\n ) {\n throw new Error('PaymentIntent does not match the transaction')\n }\n\n const normalizedCartID = getRelationshipID(canonicalCartID)\n\n if (!normalizedCartID || normalizedCartID !== getRelationshipID(transaction.cart)) {\n throw new Error('Canonical cart does not match the transaction cart')\n }\n\n const metadata = isRecord(paymentIntent.metadata) ? paymentIntent.metadata : undefined\n\n if (normalizedCartID !== getRelationshipID(metadata?.cartID)) {\n throw new Error('Canonical cart does not match the PaymentIntent cart')\n }\n\n const transactionCustomerID = getRelationshipID(transaction.customer)\n\n if (user !== null && user !== undefined) {\n const authenticatedUserID = getRelationshipID(user.id)\n\n if (!authenticatedUserID) {\n throw new Error('Authenticated customer ID is missing or invalid')\n }\n\n if (transactionCustomerID !== authenticatedUserID) {\n throw new Error('Authenticated customer does not match the transaction customer')\n }\n } else {\n if (transactionCustomerID) {\n throw new Error('Guest transaction belongs to an authenticated customer')\n }\n\n const normalizedCustomerEmail = normalizeEmail(customerEmail)\n\n if (\n !normalizedCustomerEmail ||\n normalizedCustomerEmail !== normalizeEmail(transaction.customerEmail)\n ) {\n throw new Error('Guest email does not match the transaction email')\n }\n }\n\n const stripeCustomerID = getNestedString(transaction, 'stripe', 'customerID')\n\n if (!stripeCustomerID || stripeCustomerID !== getRelationshipID(paymentIntent.customer)) {\n throw new Error('Stripe customer does not match the transaction')\n }\n\n if (paymentIntent.amount !== transaction.amount) {\n throw new Error('Stripe amount does not match the transaction amount')\n }\n\n if (\n typeof paymentIntent.currency !== 'string' ||\n typeof transaction.currency !== 'string' ||\n paymentIntent.currency.toUpperCase() !== transaction.currency\n ) {\n throw new Error('Stripe currency does not match the transaction currency')\n }\n\n const normalizedSnapshot = normalizeCartItems(cartItemsSnapshot)\n const normalizedTransactionItems = normalizeCartItems(transaction.items)\n\n if (stableSerialize(normalizedSnapshot) !== stableSerialize(normalizedTransactionItems)) {\n throw new Error('Stripe cart items do not match the transaction items')\n }\n\n if (paymentIntent.status !== 'succeeded') {\n throw new Error('Payment not completed.')\n }\n}\n\nconst getNestedString = (\n value: unknown,\n groupName: string,\n fieldName: string,\n): string | undefined => {\n if (!isRecord(value)) {\n return undefined\n }\n\n const group = value[groupName]\n\n if (!isRecord(group) || typeof group[fieldName] !== 'string') {\n return undefined\n }\n\n return group[fieldName]\n}\n\nconst isRecord = (value: unknown): value is RecordValue =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\nconst normalizeValue = (value: unknown): unknown => {\n if (Array.isArray(value)) {\n return value.map((entry) => normalizeValue(entry))\n }\n\n if (isRecord(value)) {\n return Object.fromEntries(\n Object.entries(value).flatMap(([entryKey, entryValue]) => {\n const normalizedValue = normalizeValue(entryValue)\n\n return normalizedValue === undefined ? [] : [[entryKey, normalizedValue]]\n }),\n )\n }\n\n if (\n value === null ||\n typeof value === 'boolean' ||\n typeof value === 'number' ||\n typeof value === 'string'\n ) {\n return value\n }\n\n if (value === undefined) {\n return undefined\n }\n\n throw new Error('Cart items contain unsupported data')\n}\n\nconst stableSerialize = (value: unknown): string => {\n if (Array.isArray(value)) {\n return `[${value.map((entry) => stableSerialize(entry)).join(',')}]`\n }\n\n if (isRecord(value)) {\n return `{${Object.keys(value)\n .sort()\n .map((key) => `${JSON.stringify(key)}:${stableSerialize(value[key])}`)\n .join(',')}}`\n }\n\n return JSON.stringify(value)\n}\n"],"names":["getRelationshipID","value","relationshipID","isRecord","id","Number","isFinite","String","trim","undefined","normalizeEmail","normalizedEmail","toLowerCase","normalizeCartItems","items","Array","isArray","length","Error","map","item","productID","product","quantity","Object","fromEntries","entries","flatMap","key","variantID","normalizedValue","normalizeValue","validateSettlement","canonicalCartID","cartItemsSnapshot","customerEmail","paymentIntent","paymentIntentID","transaction","user","getNestedString","normalizedCartID","cart","metadata","cartID","transactionCustomerID","customer","authenticatedUserID","normalizedCustomerEmail","stripeCustomerID","amount","currency","toUpperCase","normalizedSnapshot","normalizedTransactionItems","stableSerialize","status","groupName","fieldName","group","entry","entryKey","entryValue","join","keys","sort","JSON","stringify"],"mappings":"AAkCA,OAAO,MAAMA,oBAAoB,CAACC;IAChC,MAAMC,iBAAiBC,SAASF,SAASA,MAAMG,EAAE,GAAGH;IAEpD,IAAI,OAAOC,mBAAmB,YAAYG,OAAOC,QAAQ,CAACJ,iBAAiB;QACzE,OAAOK,OAAOL;IAChB;IAEA,IAAI,OAAOA,mBAAmB,YAAYA,eAAeM,IAAI,IAAI;QAC/D,OAAON;IACT;IAEA,OAAOO;AACT,EAAC;AAED,OAAO,MAAMC,iBAAiB,CAACT;IAC7B,IAAI,OAAOA,UAAU,UAAU;QAC7B,OAAOQ;IACT;IAEA,MAAME,kBAAkBV,MAAMO,IAAI,GAAGI,WAAW;IAEhD,OAAOD,mBAAmBF;AAC5B,EAAC;AAED,OAAO,MAAMI,qBAAqB,CAACC;IACjC,IAAI,CAACC,MAAMC,OAAO,CAACF,UAAUA,MAAMG,MAAM,KAAK,GAAG;QAC/C,MAAM,IAAIC,MAAM;IAClB;IAEA,OAAOJ,MAAMK,GAAG,CAAC,CAACC;QAChB,IAAI,CAACjB,SAASiB,OAAO;YACnB,MAAM,IAAIF,MAAM;QAClB;QAEA,MAAMG,YAAYrB,kBAAkBoB,KAAKE,OAAO;QAEhD,IAAI,CAACD,aAAa,OAAOD,KAAKG,QAAQ,KAAK,YAAY,CAAClB,OAAOC,QAAQ,CAACc,KAAKG,QAAQ,GAAG;YACtF,MAAM,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@@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/provider/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAIpD,OAAO,KAAgF,MAAM,OAAO,CAAA;AAEpG,OAAO,KAAK,EACV,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,QAAQ,EACR,eAAe,EACf,oBAAoB,EAErB,MAAM,sBAAsB,CAAA;AAsD7B,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/provider/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAIpD,OAAO,KAAgF,MAAM,OAAO,CAAA;AAEpG,OAAO,KAAK,EACV,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,QAAQ,EACR,eAAe,EACf,oBAAoB,EAErB,MAAM,sBAAsB,CAAA;AAsD7B,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAyiCpD,CAAA;AAED,eAAO,MAAM,YAAY,4BAQxB,CAAA;AAED,eAAO,MAAM,kBAAkB,uBAI9B,CAAA;AAED,eAAO,MAAM,WAAW;;6BAIX,IAAI,GAAG,MAAM,YAAY;QAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,KAAG,MAAM;;;CAmCtF,CAAA;AAED,wBAAgB,OAAO,CAAC,CAAC,SAAS,eAAe;;;;;UAkB/B,CAAC;;;;;;;EAQlB;AAED,eAAO,MAAM,WAAW;;;;;;;;;;CASvB,CAAA;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,mBAAmB;eAOvB,CAAC,EAAE;;;;;;;;;;EACrC"}
|
|
@@ -68,10 +68,6 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
68
68
|
...syncLocalStorage
|
|
69
69
|
} : defaultLocalStorage;
|
|
70
70
|
const { apiRoute = '/api', cartsFetchQuery = {} } = api || {};
|
|
71
|
-
const baseAPIURL = formatAdminURL({
|
|
72
|
-
apiRoute,
|
|
73
|
-
path: ''
|
|
74
|
-
});
|
|
75
71
|
const config = useMemo(()=>({
|
|
76
72
|
addressesSlug,
|
|
77
73
|
api: {
|
|
@@ -126,7 +122,10 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
126
122
|
]);
|
|
127
123
|
const createCart = useCallback(async (initialData)=>{
|
|
128
124
|
const query = qs.stringify(cartQuery);
|
|
129
|
-
const response = await fetch(
|
|
125
|
+
const response = await fetch(formatAdminURL({
|
|
126
|
+
apiRoute,
|
|
127
|
+
path: `/${cartsSlug}?${query}`
|
|
128
|
+
}), {
|
|
130
129
|
body: JSON.stringify({
|
|
131
130
|
...initialData,
|
|
132
131
|
currency: selectedCurrency.code,
|
|
@@ -152,7 +151,7 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
152
151
|
}
|
|
153
152
|
return data.doc;
|
|
154
153
|
}, [
|
|
155
|
-
|
|
154
|
+
apiRoute,
|
|
156
155
|
cartQuery,
|
|
157
156
|
cartsSlug,
|
|
158
157
|
selectedCurrency.code,
|
|
@@ -165,7 +164,10 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
165
164
|
secret: options.secret
|
|
166
165
|
} : {}
|
|
167
166
|
});
|
|
168
|
-
const response = await fetch(
|
|
167
|
+
const response = await fetch(formatAdminURL({
|
|
168
|
+
apiRoute,
|
|
169
|
+
path: `/${cartsSlug}/${cartID}?${query}`
|
|
170
|
+
}), {
|
|
169
171
|
credentials: 'include',
|
|
170
172
|
headers: {
|
|
171
173
|
'Content-Type': 'application/json'
|
|
@@ -182,7 +184,7 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
182
184
|
}
|
|
183
185
|
return data;
|
|
184
186
|
}, [
|
|
185
|
-
|
|
187
|
+
apiRoute,
|
|
186
188
|
cartQuery,
|
|
187
189
|
cartsSlug
|
|
188
190
|
]);
|
|
@@ -223,7 +225,10 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
223
225
|
try {
|
|
224
226
|
if (cartID) {
|
|
225
227
|
// Use server-side endpoint for adding items
|
|
226
|
-
const response = await fetch(
|
|
228
|
+
const response = await fetch(formatAdminURL({
|
|
229
|
+
apiRoute,
|
|
230
|
+
path: `/${cartsSlug}/${cartID}/add-item`
|
|
231
|
+
}), {
|
|
227
232
|
body: JSON.stringify({
|
|
228
233
|
item,
|
|
229
234
|
quantity,
|
|
@@ -274,7 +279,7 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
274
279
|
setIsLoading(false);
|
|
275
280
|
}
|
|
276
281
|
}, [
|
|
277
|
-
|
|
282
|
+
apiRoute,
|
|
278
283
|
cartID,
|
|
279
284
|
cartSecret,
|
|
280
285
|
cartsSlug,
|
|
@@ -288,7 +293,10 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
288
293
|
}
|
|
289
294
|
setIsLoading(true);
|
|
290
295
|
try {
|
|
291
|
-
const response = await fetch(
|
|
296
|
+
const response = await fetch(formatAdminURL({
|
|
297
|
+
apiRoute,
|
|
298
|
+
path: `/${cartsSlug}/${cartID}/remove-item`
|
|
299
|
+
}), {
|
|
292
300
|
body: JSON.stringify({
|
|
293
301
|
itemID: targetID,
|
|
294
302
|
secret: cartSecret
|
|
@@ -325,7 +333,7 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
325
333
|
setIsLoading(false);
|
|
326
334
|
}
|
|
327
335
|
}, [
|
|
328
|
-
|
|
336
|
+
apiRoute,
|
|
329
337
|
cartID,
|
|
330
338
|
cartSecret,
|
|
331
339
|
cartsSlug,
|
|
@@ -338,7 +346,10 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
338
346
|
}
|
|
339
347
|
setIsLoading(true);
|
|
340
348
|
try {
|
|
341
|
-
const response = await fetch(
|
|
349
|
+
const response = await fetch(formatAdminURL({
|
|
350
|
+
apiRoute,
|
|
351
|
+
path: `/${cartsSlug}/${cartID}/update-item`
|
|
352
|
+
}), {
|
|
342
353
|
body: JSON.stringify({
|
|
343
354
|
itemID: targetID,
|
|
344
355
|
quantity: {
|
|
@@ -378,7 +389,7 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
378
389
|
setIsLoading(false);
|
|
379
390
|
}
|
|
380
391
|
}, [
|
|
381
|
-
|
|
392
|
+
apiRoute,
|
|
382
393
|
cartID,
|
|
383
394
|
cartSecret,
|
|
384
395
|
cartsSlug,
|
|
@@ -391,7 +402,10 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
391
402
|
}
|
|
392
403
|
setIsLoading(true);
|
|
393
404
|
try {
|
|
394
|
-
const response = await fetch(
|
|
405
|
+
const response = await fetch(formatAdminURL({
|
|
406
|
+
apiRoute,
|
|
407
|
+
path: `/${cartsSlug}/${cartID}/update-item`
|
|
408
|
+
}), {
|
|
395
409
|
body: JSON.stringify({
|
|
396
410
|
itemID: targetID,
|
|
397
411
|
quantity: {
|
|
@@ -431,7 +445,7 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
431
445
|
setIsLoading(false);
|
|
432
446
|
}
|
|
433
447
|
}, [
|
|
434
|
-
|
|
448
|
+
apiRoute,
|
|
435
449
|
cartID,
|
|
436
450
|
cartSecret,
|
|
437
451
|
cartsSlug,
|
|
@@ -444,7 +458,10 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
444
458
|
}
|
|
445
459
|
setIsLoading(true);
|
|
446
460
|
try {
|
|
447
|
-
const response = await fetch(
|
|
461
|
+
const response = await fetch(formatAdminURL({
|
|
462
|
+
apiRoute,
|
|
463
|
+
path: `/${cartsSlug}/${cartID}/clear`
|
|
464
|
+
}), {
|
|
448
465
|
body: JSON.stringify({
|
|
449
466
|
secret: cartSecret
|
|
450
467
|
}),
|
|
@@ -480,7 +497,7 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
480
497
|
setIsLoading(false);
|
|
481
498
|
}
|
|
482
499
|
}, [
|
|
483
|
-
|
|
500
|
+
apiRoute,
|
|
484
501
|
cartID,
|
|
485
502
|
cartSecret,
|
|
486
503
|
cartsSlug,
|
|
@@ -511,7 +528,10 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
511
528
|
setSelectedPaymentMethod(paymentMethodID);
|
|
512
529
|
if (paymentMethod.initiatePayment) {
|
|
513
530
|
try {
|
|
514
|
-
const response = await fetch(
|
|
531
|
+
const response = await fetch(formatAdminURL({
|
|
532
|
+
apiRoute,
|
|
533
|
+
path: `/payments/${paymentMethodID}/initiate`
|
|
534
|
+
}), {
|
|
515
535
|
body: JSON.stringify({
|
|
516
536
|
cartID,
|
|
517
537
|
currency: selectedCurrency.code,
|
|
@@ -544,7 +564,7 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
544
564
|
throw new Error(`Payment method "${paymentMethodID}" does not support payment initiation`);
|
|
545
565
|
}
|
|
546
566
|
}, [
|
|
547
|
-
|
|
567
|
+
apiRoute,
|
|
548
568
|
cartID,
|
|
549
569
|
cartSecret,
|
|
550
570
|
debug,
|
|
@@ -560,7 +580,10 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
560
580
|
throw new Error(`Payment method with ID "${paymentMethodID}" not found`);
|
|
561
581
|
}
|
|
562
582
|
if (paymentMethod.confirmOrder) {
|
|
563
|
-
const response = await fetch(
|
|
583
|
+
const response = await fetch(formatAdminURL({
|
|
584
|
+
apiRoute,
|
|
585
|
+
path: `/payments/${paymentMethodID}/confirm-order`
|
|
586
|
+
}), {
|
|
564
587
|
body: JSON.stringify({
|
|
565
588
|
cartID,
|
|
566
589
|
currency: selectedCurrency.code,
|
|
@@ -586,7 +609,7 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
586
609
|
throw new Error(`Payment method "${paymentMethodID}" does not support order confirmation`);
|
|
587
610
|
}
|
|
588
611
|
}, [
|
|
589
|
-
|
|
612
|
+
apiRoute,
|
|
590
613
|
cartID,
|
|
591
614
|
cartSecret,
|
|
592
615
|
paymentMethods,
|
|
@@ -601,7 +624,10 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
601
624
|
cart: true
|
|
602
625
|
}
|
|
603
626
|
});
|
|
604
|
-
const response = await fetch(
|
|
627
|
+
const response = await fetch(formatAdminURL({
|
|
628
|
+
apiRoute,
|
|
629
|
+
path: `/${customersSlug}/me?${query}`
|
|
630
|
+
}), {
|
|
605
631
|
credentials: 'include',
|
|
606
632
|
headers: {
|
|
607
633
|
'Content-Type': 'application/json'
|
|
@@ -629,7 +655,7 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
629
655
|
throw new Error(`Failed to fetch user: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
630
656
|
}
|
|
631
657
|
}, [
|
|
632
|
-
|
|
658
|
+
apiRoute,
|
|
633
659
|
customersSlug,
|
|
634
660
|
debug
|
|
635
661
|
]);
|
|
@@ -643,7 +669,10 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
643
669
|
limit: 0,
|
|
644
670
|
pagination: false
|
|
645
671
|
});
|
|
646
|
-
const response = await fetch(
|
|
672
|
+
const response = await fetch(formatAdminURL({
|
|
673
|
+
apiRoute,
|
|
674
|
+
path: `/${addressesSlug}?${query}`
|
|
675
|
+
}), {
|
|
647
676
|
credentials: 'include',
|
|
648
677
|
headers: {
|
|
649
678
|
'Content-Type': 'application/json'
|
|
@@ -671,7 +700,7 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
671
700
|
}
|
|
672
701
|
}, [
|
|
673
702
|
user,
|
|
674
|
-
|
|
703
|
+
apiRoute,
|
|
675
704
|
addressesSlug,
|
|
676
705
|
debug
|
|
677
706
|
]);
|
|
@@ -680,7 +709,10 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
680
709
|
throw new Error('User must be logged in to update or create an address');
|
|
681
710
|
}
|
|
682
711
|
try {
|
|
683
|
-
const response = await fetch(
|
|
712
|
+
const response = await fetch(formatAdminURL({
|
|
713
|
+
apiRoute,
|
|
714
|
+
path: `/${addressesSlug}/${addressID}`
|
|
715
|
+
}), {
|
|
684
716
|
body: JSON.stringify(address),
|
|
685
717
|
credentials: 'include',
|
|
686
718
|
headers: {
|
|
@@ -707,7 +739,7 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
707
739
|
}
|
|
708
740
|
}, [
|
|
709
741
|
user,
|
|
710
|
-
|
|
742
|
+
apiRoute,
|
|
711
743
|
addressesSlug,
|
|
712
744
|
getAddresses,
|
|
713
745
|
debug
|
|
@@ -717,7 +749,10 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
717
749
|
throw new Error('User must be logged in to update or create an address');
|
|
718
750
|
}
|
|
719
751
|
try {
|
|
720
|
-
const response = await fetch(
|
|
752
|
+
const response = await fetch(formatAdminURL({
|
|
753
|
+
apiRoute,
|
|
754
|
+
path: `/${addressesSlug}`
|
|
755
|
+
}), {
|
|
721
756
|
body: JSON.stringify(address),
|
|
722
757
|
credentials: 'include',
|
|
723
758
|
headers: {
|
|
@@ -744,7 +779,7 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
744
779
|
}
|
|
745
780
|
}, [
|
|
746
781
|
user,
|
|
747
|
-
|
|
782
|
+
apiRoute,
|
|
748
783
|
addressesSlug,
|
|
749
784
|
getAddresses,
|
|
750
785
|
debug
|
|
@@ -784,7 +819,10 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
784
819
|
*/ const mergeCart = useCallback(async (targetCartID, sourceCartID, sourceSecret)=>{
|
|
785
820
|
setIsLoading(true);
|
|
786
821
|
try {
|
|
787
|
-
const response = await fetch(
|
|
822
|
+
const response = await fetch(formatAdminURL({
|
|
823
|
+
apiRoute,
|
|
824
|
+
path: `/${cartsSlug}/${targetCartID}/merge`
|
|
825
|
+
}), {
|
|
788
826
|
body: JSON.stringify({
|
|
789
827
|
sourceCartID,
|
|
790
828
|
sourceSecret
|
|
@@ -818,7 +856,7 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
818
856
|
setIsLoading(false);
|
|
819
857
|
}
|
|
820
858
|
}, [
|
|
821
|
-
|
|
859
|
+
apiRoute,
|
|
822
860
|
cartsSlug,
|
|
823
861
|
debug,
|
|
824
862
|
getCart
|
|
@@ -862,7 +900,10 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
862
900
|
} else {
|
|
863
901
|
// User has no existing cart - transfer guest cart to user
|
|
864
902
|
try {
|
|
865
|
-
const response = await fetch(
|
|
903
|
+
const response = await fetch(formatAdminURL({
|
|
904
|
+
apiRoute,
|
|
905
|
+
path: `/${cartsSlug}/${guestCartID}?secret=${guestSecret}`
|
|
906
|
+
}), {
|
|
866
907
|
body: JSON.stringify({
|
|
867
908
|
customer: fetchedUser.id,
|
|
868
909
|
secret: null
|
|
@@ -897,7 +938,7 @@ export const EcommerceProvider = ({ addressesSlug = 'addresses', api, cartsSlug
|
|
|
897
938
|
localStorage.setItem(localStorageConfig.key, cartID);
|
|
898
939
|
}
|
|
899
940
|
}, [
|
|
900
|
-
|
|
941
|
+
apiRoute,
|
|
901
942
|
cartID,
|
|
902
943
|
cartSecret,
|
|
903
944
|
cartsSlug,
|