@unchainedshop/api 2.1.0 → 2.1.1
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/lib/loaders/index.js +28 -43
- package/lib/loaders/index.js.map +1 -1
- package/package.json +12 -12
- package/src/loaders/index.ts +40 -42
package/lib/loaders/index.js
CHANGED
|
@@ -3,6 +3,27 @@ import { systemLocale } from '@unchainedshop/utils';
|
|
|
3
3
|
import localePkg from 'locale';
|
|
4
4
|
import { ProductStatus } from '@unchainedshop/core-products';
|
|
5
5
|
const { Locale } = localePkg;
|
|
6
|
+
function getLocaleStrings(localeObj) {
|
|
7
|
+
return [localeObj.normalized, localeObj.language, systemLocale.normalized, systemLocale.language];
|
|
8
|
+
}
|
|
9
|
+
function findMatchingText(texts, localeStrings) {
|
|
10
|
+
return localeStrings.reduce((acc, localeString) => {
|
|
11
|
+
if (acc)
|
|
12
|
+
return acc;
|
|
13
|
+
return texts.find((p) => p.locale === localeString);
|
|
14
|
+
}, null);
|
|
15
|
+
}
|
|
16
|
+
function getFilteredQueries({ queries, texts, filterFn }) {
|
|
17
|
+
return queries.map(({ locale, ...queryParams }) => {
|
|
18
|
+
const localeObj = new Locale(locale);
|
|
19
|
+
const filteredTexts = texts.filter(filterFn(queryParams));
|
|
20
|
+
if (!filteredTexts.length)
|
|
21
|
+
return null;
|
|
22
|
+
const localeStrings = getLocaleStrings(localeObj);
|
|
23
|
+
const filterText = findMatchingText(filteredTexts, localeStrings);
|
|
24
|
+
return filterText || filteredTexts[0];
|
|
25
|
+
});
|
|
26
|
+
}
|
|
6
27
|
export default async (req, res, unchainedAPI) => {
|
|
7
28
|
return {
|
|
8
29
|
assortmentLoader: new DataLoader(async (queries) => {
|
|
@@ -27,20 +48,8 @@ export default async (req, res, unchainedAPI) => {
|
|
|
27
48
|
assortmentId: 1,
|
|
28
49
|
},
|
|
29
50
|
});
|
|
30
|
-
const
|
|
31
|
-
return
|
|
32
|
-
const localeObj = new Locale(locale);
|
|
33
|
-
const assortmentTexts = texts.filter((text) => text.assortmentId === assortmentId);
|
|
34
|
-
if (!assortmentTexts.length)
|
|
35
|
-
return null;
|
|
36
|
-
const localeStrings = [localeObj.normalized, localeObj.language, ...systemLocaleStrings];
|
|
37
|
-
const assortmentText = localeStrings.reduce((acc, localeString) => {
|
|
38
|
-
if (acc)
|
|
39
|
-
return acc;
|
|
40
|
-
return assortmentTexts.find((p) => p.locale === localeString);
|
|
41
|
-
}, null);
|
|
42
|
-
return assortmentText || assortmentTexts[0];
|
|
43
|
-
});
|
|
51
|
+
const filterFn = ({ assortmentId }) => (text) => text.assortmentId === assortmentId;
|
|
52
|
+
return getFilteredQueries({ queries, texts, filterFn });
|
|
44
53
|
}),
|
|
45
54
|
filterLoader: new DataLoader(async (queries) => {
|
|
46
55
|
const filterIds = [...new Set(queries.map((q) => q.filterId).filter(Boolean))];
|
|
@@ -63,23 +72,11 @@ export default async (req, res, unchainedAPI) => {
|
|
|
63
72
|
filterId: 1,
|
|
64
73
|
},
|
|
65
74
|
});
|
|
66
|
-
const
|
|
67
|
-
return
|
|
68
|
-
const localeObj = new Locale(locale);
|
|
69
|
-
const filterTexts = texts.filter((text) => text.filterId === filterId && text.filterOptionValue === filterOptionValue);
|
|
70
|
-
if (!filterTexts.length)
|
|
71
|
-
return null;
|
|
72
|
-
const localeStrings = [localeObj.normalized, localeObj.language, ...systemLocaleStrings];
|
|
73
|
-
const filterText = localeStrings.reduce((acc, localeString) => {
|
|
74
|
-
if (acc)
|
|
75
|
-
return acc;
|
|
76
|
-
return filterTexts.find((p) => p.locale === localeString);
|
|
77
|
-
}, null);
|
|
78
|
-
return filterText || filterTexts[0];
|
|
79
|
-
});
|
|
75
|
+
const filterFn = ({ filterId, filterOptionValue }) => (text) => text.filterId === filterId && text.filterOptionValue === filterOptionValue;
|
|
76
|
+
return getFilteredQueries({ queries, texts, filterFn });
|
|
80
77
|
}),
|
|
81
78
|
productLoader: new DataLoader(async (queries) => {
|
|
82
|
-
const productIds = [...new Set(queries.map((q) => q.productId).filter(Boolean))];
|
|
79
|
+
const productIds = [...new Set(queries.map((q) => q.productId).filter(Boolean))]; // you don't need lodash, _.unique my ass
|
|
83
80
|
const products = await unchainedAPI.modules.products.findProducts({
|
|
84
81
|
productIds,
|
|
85
82
|
productSelector: {
|
|
@@ -101,20 +98,8 @@ export default async (req, res, unchainedAPI) => {
|
|
|
101
98
|
productId: 1,
|
|
102
99
|
},
|
|
103
100
|
});
|
|
104
|
-
const
|
|
105
|
-
return
|
|
106
|
-
const localeObj = new Locale(locale);
|
|
107
|
-
const productTexts = texts.filter((text) => text.productId === productId);
|
|
108
|
-
if (!productTexts.length)
|
|
109
|
-
return null;
|
|
110
|
-
const localeStrings = [localeObj.normalized, localeObj.language, ...systemLocaleStrings];
|
|
111
|
-
const productText = localeStrings.reduce((acc, localeString) => {
|
|
112
|
-
if (acc)
|
|
113
|
-
return acc;
|
|
114
|
-
return productTexts.find((p) => p.locale === localeString);
|
|
115
|
-
}, null);
|
|
116
|
-
return productText || productTexts[0];
|
|
117
|
-
});
|
|
101
|
+
const filterFn = ({ productId }) => (text) => text.productId === productId;
|
|
102
|
+
return getFilteredQueries({ queries, texts, filterFn });
|
|
118
103
|
}),
|
|
119
104
|
};
|
|
120
105
|
};
|
package/lib/loaders/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/loaders/index.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,SAAS,MAAM,QAAQ,CAAC;AAK/B,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;AAE7B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/loaders/index.ts"],"names":[],"mappings":"AACA,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C5C,OAAO,IAAI,CAAC;gBACd,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QAEF,iBAAiB,EAAE,IAAI,UAAU,CAC/B,KAAK,EAAE,OAAO,EAAE,EAAE;YAChB,MAAM,UAAU,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAEjF,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAC/D,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAClC;gBACE,IAAI,EAAE;oBACJ,SAAS,EAAE,CAAC;iBACb;aACF,CACF,CAAC;YAEF,MAAM,QAAQ,GACZ,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAClB,CAAC,IAAI,EAAE,EAAE,CACP,IAAI,CAAC,SAAS,KAAK,SAAS,CAAC;YAEjC,OAAO,kBAAkB,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC1D,CAAC,CACF;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/api",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"main": "lib/api-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/api-index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@apollo/server": "^4.
|
|
43
|
+
"@apollo/server": "^4.5.0",
|
|
44
44
|
"cookie": "^0.5.0",
|
|
45
45
|
"graphql": "^16.6.0"
|
|
46
46
|
},
|
|
@@ -49,14 +49,14 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@metamask/eth-sig-util": "^5.0.2",
|
|
52
|
-
"@unchainedshop/core": "^2.1.
|
|
53
|
-
"@unchainedshop/events": "^2.1.
|
|
54
|
-
"@unchainedshop/logger": "^2.1.
|
|
55
|
-
"@unchainedshop/roles": "^2.1.
|
|
56
|
-
"@unchainedshop/utils": "^2.1.
|
|
52
|
+
"@unchainedshop/core": "^2.1.1",
|
|
53
|
+
"@unchainedshop/events": "^2.1.1",
|
|
54
|
+
"@unchainedshop/logger": "^2.1.1",
|
|
55
|
+
"@unchainedshop/roles": "^2.1.1",
|
|
56
|
+
"@unchainedshop/utils": "^2.1.1",
|
|
57
57
|
"accounting": "0.4.1",
|
|
58
58
|
"dataloader": "^2.2.2",
|
|
59
|
-
"graphql-scalars": "^1.
|
|
59
|
+
"graphql-scalars": "^1.21.3",
|
|
60
60
|
"graphql-upload": "^16.0.2",
|
|
61
61
|
"locale": "0.1.0",
|
|
62
62
|
"lodash.isnumber": "3.0.3",
|
|
@@ -65,12 +65,12 @@
|
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@types/graphql-upload": "^15.0.2",
|
|
67
67
|
"@types/locale": "^0.1.1",
|
|
68
|
-
"@types/node": "^18.
|
|
69
|
-
"@unchainedshop/types": "^2.1.
|
|
68
|
+
"@types/node": "^18.15.11",
|
|
69
|
+
"@unchainedshop/types": "^2.1.1",
|
|
70
70
|
"express": "^4.18.2",
|
|
71
71
|
"graphql": "^16.6.0",
|
|
72
|
-
"jest": "^29.
|
|
73
|
-
"ts-jest": "^29.0
|
|
72
|
+
"jest": "^29.5.0",
|
|
73
|
+
"ts-jest": "^29.1.0",
|
|
74
74
|
"typescript": "^4.9.5"
|
|
75
75
|
}
|
|
76
76
|
}
|
package/src/loaders/index.ts
CHANGED
|
@@ -11,6 +11,30 @@ import { ProductStatus } from '@unchainedshop/core-products';
|
|
|
11
11
|
|
|
12
12
|
const { Locale } = localePkg;
|
|
13
13
|
|
|
14
|
+
function getLocaleStrings(localeObj) {
|
|
15
|
+
return [localeObj.normalized, localeObj.language, systemLocale.normalized, systemLocale.language];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function findMatchingText(texts, localeStrings) {
|
|
19
|
+
return localeStrings.reduce((acc, localeString) => {
|
|
20
|
+
if (acc) return acc;
|
|
21
|
+
return texts.find((p) => p.locale === localeString);
|
|
22
|
+
}, null);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getFilteredQueries({ queries, texts, filterFn }) {
|
|
26
|
+
return queries.map(({ locale, ...queryParams }) => {
|
|
27
|
+
const localeObj = new Locale(locale);
|
|
28
|
+
|
|
29
|
+
const filteredTexts = texts.filter(filterFn(queryParams));
|
|
30
|
+
if (!filteredTexts.length) return null;
|
|
31
|
+
|
|
32
|
+
const localeStrings = getLocaleStrings(localeObj);
|
|
33
|
+
const filterText = findMatchingText(filteredTexts, localeStrings);
|
|
34
|
+
return filterText || filteredTexts[0];
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
14
38
|
export default async (
|
|
15
39
|
req: IncomingMessage,
|
|
16
40
|
res: OutgoingMessage,
|
|
@@ -47,20 +71,12 @@ export default async (
|
|
|
47
71
|
},
|
|
48
72
|
);
|
|
49
73
|
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const assortmentTexts = texts.filter((text) => text.assortmentId === assortmentId);
|
|
55
|
-
if (!assortmentTexts.length) return null;
|
|
56
|
-
const localeStrings = [localeObj.normalized, localeObj.language, ...systemLocaleStrings];
|
|
74
|
+
const filterFn =
|
|
75
|
+
({ assortmentId }) =>
|
|
76
|
+
(text) =>
|
|
77
|
+
text.assortmentId === assortmentId;
|
|
57
78
|
|
|
58
|
-
|
|
59
|
-
if (acc) return acc;
|
|
60
|
-
return assortmentTexts.find((p) => p.locale === localeString);
|
|
61
|
-
}, null);
|
|
62
|
-
return assortmentText || assortmentTexts[0];
|
|
63
|
-
});
|
|
79
|
+
return getFilteredQueries({ queries, texts, filterFn });
|
|
64
80
|
},
|
|
65
81
|
),
|
|
66
82
|
|
|
@@ -95,26 +111,16 @@ export default async (
|
|
|
95
111
|
},
|
|
96
112
|
);
|
|
97
113
|
|
|
98
|
-
const
|
|
114
|
+
const filterFn =
|
|
115
|
+
({ filterId, filterOptionValue }) =>
|
|
116
|
+
(text) =>
|
|
117
|
+
text.filterId === filterId && text.filterOptionValue === filterOptionValue;
|
|
99
118
|
|
|
100
|
-
return
|
|
101
|
-
const localeObj = new Locale(locale);
|
|
102
|
-
const filterTexts = texts.filter(
|
|
103
|
-
(text) => text.filterId === filterId && text.filterOptionValue === filterOptionValue,
|
|
104
|
-
);
|
|
105
|
-
if (!filterTexts.length) return null;
|
|
106
|
-
const localeStrings = [localeObj.normalized, localeObj.language, ...systemLocaleStrings];
|
|
107
|
-
|
|
108
|
-
const filterText = localeStrings.reduce<FilterText>((acc, localeString) => {
|
|
109
|
-
if (acc) return acc;
|
|
110
|
-
return filterTexts.find((p) => p.locale === localeString);
|
|
111
|
-
}, null);
|
|
112
|
-
return filterText || filterTexts[0];
|
|
113
|
-
});
|
|
119
|
+
return getFilteredQueries({ queries, texts, filterFn });
|
|
114
120
|
}),
|
|
115
121
|
|
|
116
122
|
productLoader: new DataLoader<{ productId: string }, Product>(async (queries) => {
|
|
117
|
-
const productIds = [...new Set(queries.map((q) => q.productId).filter(Boolean))];
|
|
123
|
+
const productIds = [...new Set(queries.map((q) => q.productId).filter(Boolean))]; // you don't need lodash, _.unique my ass
|
|
118
124
|
|
|
119
125
|
const products = await unchainedAPI.modules.products.findProducts({
|
|
120
126
|
productIds,
|
|
@@ -144,20 +150,12 @@ export default async (
|
|
|
144
150
|
},
|
|
145
151
|
);
|
|
146
152
|
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const productTexts = texts.filter((text) => text.productId === productId);
|
|
152
|
-
if (!productTexts.length) return null;
|
|
153
|
-
const localeStrings = [localeObj.normalized, localeObj.language, ...systemLocaleStrings];
|
|
153
|
+
const filterFn =
|
|
154
|
+
({ productId }) =>
|
|
155
|
+
(text) =>
|
|
156
|
+
text.productId === productId;
|
|
154
157
|
|
|
155
|
-
|
|
156
|
-
if (acc) return acc;
|
|
157
|
-
return productTexts.find((p) => p.locale === localeString);
|
|
158
|
-
}, null);
|
|
159
|
-
return productText || productTexts[0];
|
|
160
|
-
});
|
|
158
|
+
return getFilteredQueries({ queries, texts, filterFn });
|
|
161
159
|
},
|
|
162
160
|
),
|
|
163
161
|
};
|