@porulle/adapter-shopify 0.64.0 → 0.65.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/dist/index.js +3 -30
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/index.ts +3 -30
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineChannelConnector, Err, Ok } from "@porulle/core";
|
|
1
|
+
import { defineChannelConnector, Err, Ok, toMinorUnits } from "@porulle/core";
|
|
2
2
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
3
3
|
import { pushCatalog as executePushCatalog, } from "./push-catalog.js";
|
|
4
4
|
export { PORULLE_METAFIELD_NAMESPACE, PUSH_CATALOG_SCOPE, SHOPIFY_NATIVE_PRODUCT_FIELDS, SHOPIFY_NATIVE_VARIANT_FIELDS, shopifyGrantedScopes, shopifyPushCatalogEnabled, shopifyWriteProductsScopeMissingError, } from "./push-catalog.js";
|
|
@@ -10,45 +10,18 @@ export const REQUIRED_SCOPES = [
|
|
|
10
10
|
"read_fulfillments",
|
|
11
11
|
"write_products",
|
|
12
12
|
];
|
|
13
|
-
const zeroDecimalCurrencies = new Set([
|
|
14
|
-
"BIF",
|
|
15
|
-
"CLP",
|
|
16
|
-
"DJF",
|
|
17
|
-
"GNF",
|
|
18
|
-
"ISK",
|
|
19
|
-
"JPY",
|
|
20
|
-
"KMF",
|
|
21
|
-
"KRW",
|
|
22
|
-
"PYG",
|
|
23
|
-
"RWF",
|
|
24
|
-
"UGX",
|
|
25
|
-
"VND",
|
|
26
|
-
"VUV",
|
|
27
|
-
"XAF",
|
|
28
|
-
"XOF",
|
|
29
|
-
"XPF",
|
|
30
|
-
]);
|
|
31
13
|
function normalizeCurrency(value) {
|
|
32
14
|
if (typeof value !== "string" || value.trim() === "")
|
|
33
15
|
return undefined;
|
|
34
16
|
return value.trim().toUpperCase();
|
|
35
17
|
}
|
|
36
|
-
function parseMoney(value, currency) {
|
|
37
|
-
if (value == null || value.trim() === "")
|
|
38
|
-
return undefined;
|
|
39
|
-
const parsed = Number(value);
|
|
40
|
-
if (!Number.isFinite(parsed))
|
|
41
|
-
return undefined;
|
|
42
|
-
const exponent = zeroDecimalCurrencies.has(currency) ? 0 : 2;
|
|
43
|
-
return Math.round(parsed * (10 ** exponent));
|
|
44
|
-
}
|
|
45
18
|
function pricesForVariant(variant, currency) {
|
|
46
19
|
if (!currency)
|
|
47
20
|
return undefined;
|
|
48
|
-
const amount =
|
|
21
|
+
const amount = toMinorUnits(variant.price, currency);
|
|
49
22
|
if (amount === undefined)
|
|
50
23
|
return undefined;
|
|
51
|
-
const compareAtAmount =
|
|
24
|
+
const compareAtAmount = toMinorUnits(variant.compare_at_price, currency);
|
|
52
25
|
return [{
|
|
53
26
|
currency,
|
|
54
27
|
amount,
|