@reactionary/feeds 0.10.35 → 0.10.37
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/cli.cjs +74 -11
- package/package.json +9 -9
package/cli.cjs
CHANGED
|
@@ -112951,11 +112951,41 @@ var init_category_factory2 = __esm({
|
|
|
112951
112951
|
}
|
|
112952
112952
|
});
|
|
112953
112953
|
|
|
112954
|
+
// packages/commercetools/src/core/payment-protocol-data.ts
|
|
112955
|
+
function serializeProtocolData(entries) {
|
|
112956
|
+
return JSON.stringify(Object.fromEntries(entries.map((entry) => [entry.key, entry.value])));
|
|
112957
|
+
}
|
|
112958
|
+
function parseProtocolDataField(value) {
|
|
112959
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
112960
|
+
return [];
|
|
112961
|
+
}
|
|
112962
|
+
try {
|
|
112963
|
+
const parsed = JSON.parse(value);
|
|
112964
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
112965
|
+
return [];
|
|
112966
|
+
}
|
|
112967
|
+
return Object.entries(parsed).map(([key, entry]) => ({
|
|
112968
|
+
key,
|
|
112969
|
+
value: typeof entry === "string" ? entry : JSON.stringify(entry)
|
|
112970
|
+
}));
|
|
112971
|
+
} catch {
|
|
112972
|
+
return [];
|
|
112973
|
+
}
|
|
112974
|
+
}
|
|
112975
|
+
var PROTOCOL_DATA_FIELD;
|
|
112976
|
+
var init_payment_protocol_data = __esm({
|
|
112977
|
+
"packages/commercetools/src/core/payment-protocol-data.ts"() {
|
|
112978
|
+
"use strict";
|
|
112979
|
+
PROTOCOL_DATA_FIELD = "reactionaryProtocolData";
|
|
112980
|
+
}
|
|
112981
|
+
});
|
|
112982
|
+
|
|
112954
112983
|
// packages/commercetools/src/factories/checkout/checkout.factory.ts
|
|
112955
112984
|
var CommercetoolsCheckoutFactory;
|
|
112956
112985
|
var init_checkout_factory2 = __esm({
|
|
112957
112986
|
"packages/commercetools/src/factories/checkout/checkout.factory.ts"() {
|
|
112958
112987
|
"use strict";
|
|
112988
|
+
init_payment_protocol_data();
|
|
112959
112989
|
init_src();
|
|
112960
112990
|
init_locale_utils();
|
|
112961
112991
|
CommercetoolsCheckoutFactory = class {
|
|
@@ -113136,10 +113166,9 @@ var init_checkout_factory2 = __esm({
|
|
|
113136
113166
|
name: paymentName || method || "Unknown"
|
|
113137
113167
|
};
|
|
113138
113168
|
const customData = data.custom?.fields || {};
|
|
113139
|
-
const protocolData = Object.keys(customData).
|
|
113140
|
-
key,
|
|
113141
|
-
|
|
113142
|
-
}));
|
|
113169
|
+
const protocolData = Object.keys(customData).flatMap(
|
|
113170
|
+
(key) => key === PROTOCOL_DATA_FIELD ? parseProtocolDataField(customData[key]) : [{ key, value: customData[key] }]
|
|
113171
|
+
);
|
|
113143
113172
|
let status = "pending";
|
|
113144
113173
|
if (data.transactions && data.transactions.length > 0) {
|
|
113145
113174
|
const lastTransaction = data.transactions[data.transactions.length - 1];
|
|
@@ -114771,6 +114800,7 @@ var CheckoutNotReadyForFinalizationError, CommercetoolsCheckoutCapability;
|
|
|
114771
114800
|
var init_checkout_capability2 = __esm({
|
|
114772
114801
|
"packages/commercetools/src/capabilities/checkout.capability.ts"() {
|
|
114773
114802
|
"use strict";
|
|
114803
|
+
init_payment_protocol_data();
|
|
114774
114804
|
init_src();
|
|
114775
114805
|
init_zod();
|
|
114776
114806
|
init_locale_utils();
|
|
@@ -114908,16 +114938,46 @@ var init_checkout_capability2 = __esm({
|
|
|
114908
114938
|
}
|
|
114909
114939
|
async getAvailableShippingMethods(payload) {
|
|
114910
114940
|
const client = await this.getClient();
|
|
114911
|
-
const shippingMethodsResponse = await
|
|
114912
|
-
|
|
114913
|
-
|
|
114914
|
-
|
|
114915
|
-
|
|
114941
|
+
const [shippingMethodsResponse, cartResponse] = await Promise.all([
|
|
114942
|
+
client.shippingMethods.matchingCart().get({
|
|
114943
|
+
queryArgs: {
|
|
114944
|
+
cartId: payload.checkout.key
|
|
114945
|
+
}
|
|
114946
|
+
}).execute(),
|
|
114947
|
+
client.carts.withId({ ID: payload.checkout.key }).get().execute()
|
|
114948
|
+
]);
|
|
114916
114949
|
const result = shippingMethodsResponse.body.results.map(
|
|
114917
|
-
(shippingMethod) => this.factory.parseShippingMethod(this.context, shippingMethod)
|
|
114950
|
+
(shippingMethod) => this.factory.parseShippingMethod(this.context, this.withFreeShipping(shippingMethod, cartResponse.body))
|
|
114918
114951
|
);
|
|
114919
114952
|
return success(result);
|
|
114920
114953
|
}
|
|
114954
|
+
/**
|
|
114955
|
+
* Quotes the matching shipping rates as free where the cart reaches the
|
|
114956
|
+
* rate's free-above threshold. commercetools' matching-cart query returns
|
|
114957
|
+
* the rates at their configured price and only applies the threshold once
|
|
114958
|
+
* the method is set on the cart.
|
|
114959
|
+
*/
|
|
114960
|
+
withFreeShipping(shippingMethod, cart) {
|
|
114961
|
+
return {
|
|
114962
|
+
...shippingMethod,
|
|
114963
|
+
zoneRates: shippingMethod.zoneRates.map((zoneRate) => ({
|
|
114964
|
+
...zoneRate,
|
|
114965
|
+
shippingRates: zoneRate.shippingRates.map((rate) => rate.isMatching && this.isFreeShipping(rate, cart) ? { ...rate, price: { ...rate.price, centAmount: 0 } } : rate)
|
|
114966
|
+
}))
|
|
114967
|
+
};
|
|
114968
|
+
}
|
|
114969
|
+
/**
|
|
114970
|
+
* Whether commercetools charges nothing for the rate once the method is set:
|
|
114971
|
+
* shipping is free if the sum of the (custom) line item prices, after line
|
|
114972
|
+
* item discounts, reaches the rate's free-above threshold.
|
|
114973
|
+
*/
|
|
114974
|
+
isFreeShipping(rate, cart) {
|
|
114975
|
+
if (!rate.freeAbove || rate.freeAbove.currencyCode !== cart.totalPrice.currencyCode) {
|
|
114976
|
+
return false;
|
|
114977
|
+
}
|
|
114978
|
+
const itemsTotal = [...cart.lineItems, ...cart.customLineItems].reduce((sum, item) => sum + item.totalPrice.centAmount, 0);
|
|
114979
|
+
return itemsTotal >= rate.freeAbove.centAmount;
|
|
114980
|
+
}
|
|
114921
114981
|
async getAvailablePaymentMethods(payload) {
|
|
114922
114982
|
const staticMethods = this.getStaticPaymentMethods(payload.checkout);
|
|
114923
114983
|
const dynamicMethods = [];
|
|
@@ -114949,7 +115009,10 @@ var init_checkout_capability2 = __esm({
|
|
|
114949
115009
|
key: "reactionaryPaymentCustomFields"
|
|
114950
115010
|
},
|
|
114951
115011
|
fields: {
|
|
114952
|
-
commerceToolsCartId: payload.checkout.key
|
|
115012
|
+
commerceToolsCartId: payload.checkout.key,
|
|
115013
|
+
// Protocol data (e.g. agentic delegated payment tokens) is passed
|
|
115014
|
+
// verbatim for the project's payment extensions to interpret.
|
|
115015
|
+
...payload.paymentInstruction.protocolData.length > 0 ? { [PROTOCOL_DATA_FIELD]: serializeProtocolData(payload.paymentInstruction.protocolData) } : {}
|
|
114953
115016
|
}
|
|
114954
115017
|
}
|
|
114955
115018
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/feeds",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.37",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
"url": "git+https://github.com/Solteq/reactionary.git"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@reactionary/algolia": "0.10.
|
|
16
|
-
"@reactionary/commercetools": "0.10.
|
|
17
|
-
"@reactionary/core": "0.10.
|
|
18
|
-
"@reactionary/fake": "0.10.
|
|
19
|
-
"@reactionary/magento": "0.10.
|
|
20
|
-
"@reactionary/medusa": "0.10.
|
|
21
|
-
"@reactionary/meilisearch": "0.10.
|
|
22
|
-
"@reactionary/unomi": "0.10.
|
|
15
|
+
"@reactionary/algolia": "0.10.37",
|
|
16
|
+
"@reactionary/commercetools": "0.10.37",
|
|
17
|
+
"@reactionary/core": "0.10.37",
|
|
18
|
+
"@reactionary/fake": "0.10.37",
|
|
19
|
+
"@reactionary/magento": "0.10.37",
|
|
20
|
+
"@reactionary/medusa": "0.10.37",
|
|
21
|
+
"@reactionary/meilisearch": "0.10.37",
|
|
22
|
+
"@reactionary/unomi": "0.10.37",
|
|
23
23
|
"commander": "^15.0.0",
|
|
24
24
|
"dotenv": "^17.2.2",
|
|
25
25
|
"sitemap": "^9.0.1",
|