@unchainedshop/core-countries 1.1.3
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/.npm/package/README +7 -0
- package/.npm/package/npm-shrinkwrap.json +167 -0
- package/.versions +54 -0
- package/README.md +3 -0
- package/lib/countries-index.d.ts +2 -0
- package/lib/countries-index.js +3 -0
- package/lib/countries-index.js.map +1 -0
- package/lib/db/CountriesCollection.d.ts +3 -0
- package/lib/db/CountriesCollection.js +19 -0
- package/lib/db/CountriesCollection.js.map +1 -0
- package/lib/db/CountriesSchema.d.ts +1 -0
- package/lib/db/CountriesSchema.js +10 -0
- package/lib/db/CountriesSchema.js.map +1 -0
- package/lib/module/configureCountriesModule.d.ts +3 -0
- package/lib/module/configureCountriesModule.js +74 -0
- package/lib/module/configureCountriesModule.js.map +1 -0
- package/lib/service/countryServices.d.ts +2 -0
- package/lib/service/countryServices.js +5 -0
- package/lib/service/countryServices.js.map +1 -0
- package/lib/service/resolveDefaultCurrencyCodeService.d.ts +3 -0
- package/lib/service/resolveDefaultCurrencyCodeService.js +29 -0
- package/lib/service/resolveDefaultCurrencyCodeService.js.map +1 -0
- package/package.js +36 -0
- package/package.json +45 -0
- package/src/countries-index.ts +3 -0
- package/src/db/CountriesCollection.ts +23 -0
- package/src/db/CountriesSchema.js +13 -0
- package/src/module/configureCountriesModule.ts +97 -0
- package/src/service/countryServices.ts +6 -0
- package/src/service/resolveDefaultCurrencyCodeService.ts +42 -0
- package/tests/countries-index.test.ts +47 -0
- package/tsconfig.build.json +26 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
This directory and the files immediately inside it are automatically generated
|
|
2
|
+
when you change this package's NPM dependencies. Commit the files in this
|
|
3
|
+
directory (npm-shrinkwrap.json, .gitignore, and this README) to source control
|
|
4
|
+
so that others run the same versions of sub-dependencies.
|
|
5
|
+
|
|
6
|
+
You should NOT check in the node_modules directory that Meteor automatically
|
|
7
|
+
creates; if you are using git, the .gitignore file tells git to ignore it.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lockfileVersion": 1,
|
|
3
|
+
"dependencies": {
|
|
4
|
+
"abort-controller": {
|
|
5
|
+
"version": "3.0.0",
|
|
6
|
+
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
|
|
7
|
+
"integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg=="
|
|
8
|
+
},
|
|
9
|
+
"ansi-regex": {
|
|
10
|
+
"version": "1.1.1",
|
|
11
|
+
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-1.1.1.tgz",
|
|
12
|
+
"integrity": "sha512-q5i8bFLg2wDfsuR56c1NzlJFPzVD+9mxhDrhqOGigEFa87OZHlF+9dWeGWzVTP/0ECiA/JUGzfzRr2t3eYORRw=="
|
|
13
|
+
},
|
|
14
|
+
"clone": {
|
|
15
|
+
"version": "1.0.4",
|
|
16
|
+
"resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz",
|
|
17
|
+
"integrity": "sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg=="
|
|
18
|
+
},
|
|
19
|
+
"columnify": {
|
|
20
|
+
"version": "1.5.1",
|
|
21
|
+
"resolved": "https://registry.npmjs.org/columnify/-/columnify-1.5.1.tgz",
|
|
22
|
+
"integrity": "sha512-JUsujUm6cRwWegK9l8WK4ykTAyqLYzzuJN82TTxxgGyDpSgjdx0Mzs9tWGaU8UIDupVt70dbzqUGBxYtNOOTUw=="
|
|
23
|
+
},
|
|
24
|
+
"defaults": {
|
|
25
|
+
"version": "1.0.3",
|
|
26
|
+
"resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.3.tgz",
|
|
27
|
+
"integrity": "sha512-s82itHOnYrN0Ib8r+z7laQz3sdE+4FP3d9Q7VLO7U+KRT+CR0GsWuyHxzdAY82I7cXv0G/twrqomTJLOssO5HA=="
|
|
28
|
+
},
|
|
29
|
+
"diacritics": {
|
|
30
|
+
"version": "1.3.0",
|
|
31
|
+
"resolved": "https://registry.npmjs.org/diacritics/-/diacritics-1.3.0.tgz",
|
|
32
|
+
"integrity": "sha512-wlwEkqcsaxvPJML+rDh/2iS824jbREk6DUMUKkEaSlxdYHeS43cClJtsWglvw2RfeXGm6ohKDqsXteJ5sP5enA=="
|
|
33
|
+
},
|
|
34
|
+
"emoji-flags": {
|
|
35
|
+
"version": "1.3.0",
|
|
36
|
+
"resolved": "https://registry.npmjs.org/emoji-flags/-/emoji-flags-1.3.0.tgz",
|
|
37
|
+
"integrity": "sha512-cw6zdVlLPtFhpTurp9AM7c6+dBeCQAu0PrGpUQ9lA1XWsWW9lNEEbnAF9gtf8acb4jTSpUTOFZ1hHsBdSTQZGg=="
|
|
38
|
+
},
|
|
39
|
+
"event-target-shim": {
|
|
40
|
+
"version": "5.0.1",
|
|
41
|
+
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
|
|
42
|
+
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ=="
|
|
43
|
+
},
|
|
44
|
+
"i18n-iso-countries": {
|
|
45
|
+
"version": "6.4.0",
|
|
46
|
+
"resolved": "https://registry.npmjs.org/i18n-iso-countries/-/i18n-iso-countries-6.4.0.tgz",
|
|
47
|
+
"integrity": "sha512-OTDUJq0OqCP+rXnWksTbMDsTE3ZGj92h8GCqIxxZM0eNtdkLVgd5c27q6C6uaZQHy0H/Vskyyx9ieMBBJCMdPw=="
|
|
48
|
+
},
|
|
49
|
+
"lodash._basecallback": {
|
|
50
|
+
"version": "3.3.1",
|
|
51
|
+
"resolved": "https://registry.npmjs.org/lodash._basecallback/-/lodash._basecallback-3.3.1.tgz",
|
|
52
|
+
"integrity": "sha512-LQffghuO63ufDY33KKO1ezGKbcFZK3ngYV7JpxaUomoM5acf0YeXU3Pm8csVE0girVs50TXzfNibl69Co3ggJA=="
|
|
53
|
+
},
|
|
54
|
+
"lodash._baseeach": {
|
|
55
|
+
"version": "3.0.4",
|
|
56
|
+
"resolved": "https://registry.npmjs.org/lodash._baseeach/-/lodash._baseeach-3.0.4.tgz",
|
|
57
|
+
"integrity": "sha512-IqUZ9MQo2UT1XPGuBntInqTOlc+oV+bCo0kMp+yuKGsfvRSNgUW0YjWVZUrG/gs+8z/Eyuc0jkJjOBESt9BXxg=="
|
|
58
|
+
},
|
|
59
|
+
"lodash._basefind": {
|
|
60
|
+
"version": "3.0.0",
|
|
61
|
+
"resolved": "https://registry.npmjs.org/lodash._basefind/-/lodash._basefind-3.0.0.tgz",
|
|
62
|
+
"integrity": "sha512-OCYxW9f0nMWjRaJyvGxrM/x/xGZTIYEiz+PyFux4YIZr7DtXLQpmCc6aDJdhPA1vnnsrY+N7BvS76hAdlnGHfg=="
|
|
63
|
+
},
|
|
64
|
+
"lodash._basefindindex": {
|
|
65
|
+
"version": "3.6.0",
|
|
66
|
+
"resolved": "https://registry.npmjs.org/lodash._basefindindex/-/lodash._basefindindex-3.6.0.tgz",
|
|
67
|
+
"integrity": "sha512-Ay3Ok74tVwGB79L5lVZlVgpGYjV9ty8DEVPxIUhgGGkqrqk6I+BPJ5kUIxd5S1b2Qg03VXtdg/Dpv2zcwQReoA=="
|
|
68
|
+
},
|
|
69
|
+
"lodash._baseisequal": {
|
|
70
|
+
"version": "3.0.7",
|
|
71
|
+
"resolved": "https://registry.npmjs.org/lodash._baseisequal/-/lodash._baseisequal-3.0.7.tgz",
|
|
72
|
+
"integrity": "sha512-U+3GsNEZj9ebI03ncLC2pLmYVjgtYZEwdkAPO7UGgtGvAz36JVFPAQUufpSaVL93Cz5arc6JGRKZRhaOhyVJYA=="
|
|
73
|
+
},
|
|
74
|
+
"lodash._bindcallback": {
|
|
75
|
+
"version": "3.0.1",
|
|
76
|
+
"resolved": "https://registry.npmjs.org/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz",
|
|
77
|
+
"integrity": "sha512-2wlI0JRAGX8WEf4Gm1p/mv/SZ+jLijpj0jyaE/AXeuQphzCgD8ZQW4oSpoN8JAopujOFGU3KMuq7qfHBWlGpjQ=="
|
|
78
|
+
},
|
|
79
|
+
"lodash._getnative": {
|
|
80
|
+
"version": "3.9.1",
|
|
81
|
+
"resolved": "https://registry.npmjs.org/lodash._getnative/-/lodash._getnative-3.9.1.tgz",
|
|
82
|
+
"integrity": "sha512-RrL9VxMEPyDMHOd9uFbvMe8X55X16/cGM5IgOKgRElQZutpX89iS6vwl64duTV1/16w5JY7tuFNXqoekmh1EmA=="
|
|
83
|
+
},
|
|
84
|
+
"lodash._reinterpolate": {
|
|
85
|
+
"version": "3.0.0",
|
|
86
|
+
"resolved": "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz",
|
|
87
|
+
"integrity": "sha512-xYHt68QRoYGjeeM/XOE1uJtvXQAgvszfBhjV4yvsQH0u2i9I6cI6c6/eG4Hh3UAOVn0y/xAXwmTzEay49Q//HA=="
|
|
88
|
+
},
|
|
89
|
+
"lodash.find": {
|
|
90
|
+
"version": "3.2.1",
|
|
91
|
+
"resolved": "https://registry.npmjs.org/lodash.find/-/lodash.find-3.2.1.tgz",
|
|
92
|
+
"integrity": "sha512-pN4ZB4KEepNd/97vLC5F3rl1tAAa5uWvISru2psLyLA8BtqBQwOA+2D7fdusG0aGmElOEurbSMlKI3UxjqoLQg=="
|
|
93
|
+
},
|
|
94
|
+
"lodash.isarguments": {
|
|
95
|
+
"version": "3.1.0",
|
|
96
|
+
"resolved": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz",
|
|
97
|
+
"integrity": "sha512-chi4NHZlZqZD18a0imDHnZPrDeBbTtVN7GXMwuGdRH9qotxAjYs3aVLKc7zNOG9eddR5Ksd8rvFEBc9SsggPpg=="
|
|
98
|
+
},
|
|
99
|
+
"lodash.isarray": {
|
|
100
|
+
"version": "3.0.4",
|
|
101
|
+
"resolved": "https://registry.npmjs.org/lodash.isarray/-/lodash.isarray-3.0.4.tgz",
|
|
102
|
+
"integrity": "sha512-JwObCrNJuT0Nnbuecmqr5DgtuBppuCvGD9lxjFpAzwnVtdGoDQ1zig+5W8k5/6Gcn0gZ3936HDAlGd28i7sOGQ=="
|
|
103
|
+
},
|
|
104
|
+
"lodash.istypedarray": {
|
|
105
|
+
"version": "3.0.6",
|
|
106
|
+
"resolved": "https://registry.npmjs.org/lodash.istypedarray/-/lodash.istypedarray-3.0.6.tgz",
|
|
107
|
+
"integrity": "sha512-lGWJ6N8AA3KSv+ZZxlTdn4f6A7kMfpJboeyvbFdE7IU9YAgweODqmOgdUHOA+c6lVWeVLysdaxciFXi+foVsWw=="
|
|
108
|
+
},
|
|
109
|
+
"lodash.keys": {
|
|
110
|
+
"version": "3.1.2",
|
|
111
|
+
"resolved": "https://registry.npmjs.org/lodash.keys/-/lodash.keys-3.1.2.tgz",
|
|
112
|
+
"integrity": "sha512-CuBsapFjcubOGMn3VD+24HOAPxM79tH+V6ivJL3CHYjtrawauDJHUk//Yew9Hvc6e9rbCrURGk8z6PC+8WJBfQ=="
|
|
113
|
+
},
|
|
114
|
+
"lodash.pairs": {
|
|
115
|
+
"version": "3.0.1",
|
|
116
|
+
"resolved": "https://registry.npmjs.org/lodash.pairs/-/lodash.pairs-3.0.1.tgz",
|
|
117
|
+
"integrity": "sha512-lgXvpU43ZNQrZ/pK2cR97YzKeAno3e3HhcyvLKsofljeHKrQcZhT1vW7fg4X61c92tM+mjD/DypoLZYuAKNIkQ=="
|
|
118
|
+
},
|
|
119
|
+
"lodash.template": {
|
|
120
|
+
"version": "4.5.0",
|
|
121
|
+
"resolved": "https://registry.npmjs.org/lodash.template/-/lodash.template-4.5.0.tgz",
|
|
122
|
+
"integrity": "sha512-84vYFxIkmidUiFxidA/KjjH9pAycqW+h980j7Fuz5qxRtO9pgB7MDFTdys1N7A5mcucRiDyEq4fusljItR1T/A=="
|
|
123
|
+
},
|
|
124
|
+
"lodash.templatesettings": {
|
|
125
|
+
"version": "4.2.0",
|
|
126
|
+
"resolved": "https://registry.npmjs.org/lodash.templatesettings/-/lodash.templatesettings-4.2.0.tgz",
|
|
127
|
+
"integrity": "sha512-stgLz+i3Aa9mZgnjr/O+v9ruKZsPsndy7qPZOchbqk2cnTU1ZaldKK+v7m54WoKIyxiuMZTKT2H81F8BeAc3ZQ=="
|
|
128
|
+
},
|
|
129
|
+
"lru-cache": {
|
|
130
|
+
"version": "7.7.0",
|
|
131
|
+
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.7.0.tgz",
|
|
132
|
+
"integrity": "sha512-3W9Irr9YR2ZHJbfRr/hj8VtzqH7DugwWyHONyDByP6PLS/YJV7GTX5dDYS+qFe/LkVfnCjtk6vkVsxxKGol6jQ=="
|
|
133
|
+
},
|
|
134
|
+
"message-box": {
|
|
135
|
+
"version": "0.2.7",
|
|
136
|
+
"resolved": "https://registry.npmjs.org/message-box/-/message-box-0.2.7.tgz",
|
|
137
|
+
"integrity": "sha512-C4ccA5nHb58kTS+pLrgF/JWtr7fAIkHxRDceH7tdy5fMA783nUfbYwZ7H2XLvSeYfcnWIYCig5dWW+icK9X/Ag=="
|
|
138
|
+
},
|
|
139
|
+
"mongo-object": {
|
|
140
|
+
"version": "0.1.4",
|
|
141
|
+
"resolved": "https://registry.npmjs.org/mongo-object/-/mongo-object-0.1.4.tgz",
|
|
142
|
+
"integrity": "sha512-QtYk0gupWEn2+iB+DDRt1L+WbcNYvJRaHdih/dcqthOa1DbnREUGSs2WGcW478GNYpElflo/yybZXu0sTiRXHg=="
|
|
143
|
+
},
|
|
144
|
+
"simpl-schema": {
|
|
145
|
+
"version": "1.12.0",
|
|
146
|
+
"resolved": "https://registry.npmjs.org/simpl-schema/-/simpl-schema-1.12.0.tgz",
|
|
147
|
+
"integrity": "sha512-lzXC3L8jJbPhNXGR3cjlyIauqqrC5WUJS4O34Ym/wLIvb8K3ZieK+1OfTzs4mBpDc3Y8u53gQFAr1X37DmTcEg==",
|
|
148
|
+
"dependencies": {
|
|
149
|
+
"clone": {
|
|
150
|
+
"version": "2.1.2",
|
|
151
|
+
"resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz",
|
|
152
|
+
"integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w=="
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
"strip-ansi": {
|
|
157
|
+
"version": "2.0.1",
|
|
158
|
+
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-2.0.1.tgz",
|
|
159
|
+
"integrity": "sha512-2h8q2CP3EeOhDJ+jd932PRMpa3/pOJFGoF22J1U/DNbEK2gSW2DqeF46VjCXsSQXhC+k/l8/gaaRBQKL6hUPfQ=="
|
|
160
|
+
},
|
|
161
|
+
"wcwidth": {
|
|
162
|
+
"version": "1.0.1",
|
|
163
|
+
"resolved": "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.1.tgz",
|
|
164
|
+
"integrity": "sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg=="
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
package/.versions
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
allow-deny@1.1.1
|
|
2
|
+
babel-compiler@7.9.0
|
|
3
|
+
babel-runtime@1.5.1
|
|
4
|
+
base64@1.0.12
|
|
5
|
+
binary-heap@1.0.11
|
|
6
|
+
boilerplate-generator@1.7.1
|
|
7
|
+
callback-hook@1.4.0
|
|
8
|
+
check@1.3.1
|
|
9
|
+
ddp@1.4.0
|
|
10
|
+
ddp-client@2.5.0
|
|
11
|
+
ddp-common@1.4.0
|
|
12
|
+
ddp-server@2.5.0
|
|
13
|
+
diff-sequence@1.1.1
|
|
14
|
+
dynamic-import@0.7.2
|
|
15
|
+
ecmascript@0.16.2
|
|
16
|
+
ecmascript-runtime@0.8.0
|
|
17
|
+
ecmascript-runtime-client@0.12.1
|
|
18
|
+
ecmascript-runtime-server@0.11.0
|
|
19
|
+
ejson@1.1.2
|
|
20
|
+
fetch@0.1.1
|
|
21
|
+
geojson-utils@1.0.10
|
|
22
|
+
id-map@1.1.1
|
|
23
|
+
inter-process-messaging@0.1.1
|
|
24
|
+
local-test:unchained:core-countries@1.1.1
|
|
25
|
+
logging@1.3.1
|
|
26
|
+
meteor@1.10.0
|
|
27
|
+
meteortesting:browser-tests@0.1.2
|
|
28
|
+
meteortesting:mocha@0.4.4
|
|
29
|
+
minimongo@1.8.0
|
|
30
|
+
modern-browsers@0.1.8
|
|
31
|
+
modules@0.18.0
|
|
32
|
+
modules-runtime@0.13.0
|
|
33
|
+
mongo@1.15.0
|
|
34
|
+
mongo-decimal@0.1.3
|
|
35
|
+
mongo-dev-server@1.1.0
|
|
36
|
+
mongo-id@1.0.8
|
|
37
|
+
npm-mongo@4.3.1
|
|
38
|
+
ordered-dict@1.1.0
|
|
39
|
+
practicalmeteor:mocha-core@1.0.1
|
|
40
|
+
promise@0.12.0
|
|
41
|
+
random@1.2.0
|
|
42
|
+
react-fast-refresh@0.2.3
|
|
43
|
+
reload@1.3.1
|
|
44
|
+
retry@1.1.0
|
|
45
|
+
routepolicy@1.1.1
|
|
46
|
+
socket-stream-client@0.5.0
|
|
47
|
+
tracker@1.2.0
|
|
48
|
+
typescript@4.5.4
|
|
49
|
+
unchained:core-countries@1.1.1
|
|
50
|
+
|
|
51
|
+
unchained:mongodb@1.1.0
|
|
52
|
+
underscore@1.0.10
|
|
53
|
+
webapp@1.13.1
|
|
54
|
+
webapp-hashing@1.1.0
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"countries-index.js","sourceRoot":"","sources":["../src/countries-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAE7E,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { buildDbIndexes } from '@unchainedshop/utils';
|
|
2
|
+
export const CountriesCollection = async (db) => {
|
|
3
|
+
const Countries = db.collection('countries');
|
|
4
|
+
await buildDbIndexes(Countries, [
|
|
5
|
+
{ index: { isoCode: 1 }, options: { unique: true } },
|
|
6
|
+
{
|
|
7
|
+
index: { isoCode: 'text', _id: 'text' },
|
|
8
|
+
options: {
|
|
9
|
+
weights: {
|
|
10
|
+
_id: 8,
|
|
11
|
+
isoCode: 6,
|
|
12
|
+
},
|
|
13
|
+
name: 'countries_fulltext_search',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
]);
|
|
17
|
+
return Countries;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=CountriesCollection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CountriesCollection.js","sourceRoot":"","sources":["../../src/db/CountriesCollection.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,EAAM,EAAE,EAAE;IAClD,MAAM,SAAS,GAAG,EAAE,CAAC,UAAU,CAAU,WAAW,CAAC,CAAC;IAEtD,MAAM,cAAc,CAAU,SAAS,EAAE;QACvC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;QACpD;YACE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE;YACvC,OAAO,EAAE;gBACP,OAAO,EAAE;oBACP,GAAG,EAAE,CAAC;oBACN,OAAO,EAAE,CAAC;iBACX;gBACD,IAAI,EAAE,2BAA2B;aAClC;SACF;KACF,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const CountriesSchema: any;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Schemas } from '@unchainedshop/utils';
|
|
2
|
+
import SimpleSchema from 'simpl-schema';
|
|
3
|
+
export const CountriesSchema = new SimpleSchema({
|
|
4
|
+
isoCode: { type: String, required: true },
|
|
5
|
+
isActive: Boolean,
|
|
6
|
+
authorId: { type: String, required: true },
|
|
7
|
+
defaultCurrencyId: String,
|
|
8
|
+
...Schemas.timestampFields,
|
|
9
|
+
}, { requiredByDefault: false });
|
|
10
|
+
//# sourceMappingURL=CountriesSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CountriesSchema.js","sourceRoot":"","sources":["../../src/db/CountriesSchema.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,YAAY,CAC7C;IACE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACzC,QAAQ,EAAE,OAAO;IACjB,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IAC1C,iBAAiB,EAAE,MAAM;IACzB,GAAG,OAAO,CAAC,eAAe;CAC3B,EACD,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import countryFlags from 'emoji-flags';
|
|
2
|
+
import countryI18n from 'i18n-iso-countries';
|
|
3
|
+
import { emit, registerEvents } from '@unchainedshop/events';
|
|
4
|
+
import { generateDbFilterById, generateDbMutations, systemLocale, buildSortOptions, } from '@unchainedshop/utils';
|
|
5
|
+
import { CountriesCollection } from '../db/CountriesCollection';
|
|
6
|
+
import { CountriesSchema } from '../db/CountriesSchema';
|
|
7
|
+
const COUNTRY_EVENTS = ['COUNTRY_CREATE', 'COUNTRY_UPDATE', 'COUNTRY_REMOVE'];
|
|
8
|
+
const buildFindSelector = ({ includeInactive = false, queryString = '' }) => {
|
|
9
|
+
const selector = { deleted: null };
|
|
10
|
+
if (!includeInactive)
|
|
11
|
+
selector.isActive = true;
|
|
12
|
+
if (queryString)
|
|
13
|
+
selector.$text = { $search: queryString };
|
|
14
|
+
return selector;
|
|
15
|
+
};
|
|
16
|
+
export const configureCountriesModule = async ({ db, }) => {
|
|
17
|
+
registerEvents(COUNTRY_EVENTS);
|
|
18
|
+
const Countries = await CountriesCollection(db);
|
|
19
|
+
const mutations = generateDbMutations(Countries, CountriesSchema);
|
|
20
|
+
return {
|
|
21
|
+
count: async (query) => {
|
|
22
|
+
const countryCount = await Countries.countDocuments(buildFindSelector(query));
|
|
23
|
+
return countryCount;
|
|
24
|
+
},
|
|
25
|
+
findCountry: async ({ countryId, isoCode }) => {
|
|
26
|
+
return Countries.findOne(countryId ? generateDbFilterById(countryId) : { isoCode });
|
|
27
|
+
},
|
|
28
|
+
findCountries: async ({ limit, offset, sort, includeInactive, queryString }, options) => {
|
|
29
|
+
const countries = Countries.find(buildFindSelector({ includeInactive, queryString }), {
|
|
30
|
+
skip: offset,
|
|
31
|
+
limit,
|
|
32
|
+
sort: buildSortOptions(sort),
|
|
33
|
+
...options,
|
|
34
|
+
});
|
|
35
|
+
return countries.toArray();
|
|
36
|
+
},
|
|
37
|
+
countryExists: async ({ countryId }) => {
|
|
38
|
+
const countryCount = await Countries.countDocuments(generateDbFilterById(countryId, { deleted: null }), {
|
|
39
|
+
limit: 1,
|
|
40
|
+
});
|
|
41
|
+
return !!countryCount;
|
|
42
|
+
},
|
|
43
|
+
name(country, language) {
|
|
44
|
+
return countryI18n.getName(country.isoCode, language) || language;
|
|
45
|
+
},
|
|
46
|
+
flagEmoji(country) {
|
|
47
|
+
return countryFlags.countryCode(country.isoCode).emoji || '❌';
|
|
48
|
+
},
|
|
49
|
+
isBase(country) {
|
|
50
|
+
return country.isoCode === systemLocale.country;
|
|
51
|
+
},
|
|
52
|
+
create: async (doc, userId) => {
|
|
53
|
+
await Countries.deleteOne({ isoCode: doc.isoCode.toUpperCase(), deleted: { $ne: null } });
|
|
54
|
+
const countryId = await mutations.create({
|
|
55
|
+
...doc,
|
|
56
|
+
isoCode: doc.isoCode.toUpperCase(),
|
|
57
|
+
isActive: true,
|
|
58
|
+
}, userId);
|
|
59
|
+
emit('COUNTRY_CREATE', { countryId });
|
|
60
|
+
return countryId;
|
|
61
|
+
},
|
|
62
|
+
update: async (_id, doc, userId) => {
|
|
63
|
+
const countryId = await mutations.update(_id, { $set: doc }, userId);
|
|
64
|
+
emit('COUNTRY_UPDATE', { countryId });
|
|
65
|
+
return countryId;
|
|
66
|
+
},
|
|
67
|
+
delete: async (countryId, userId) => {
|
|
68
|
+
const deletedCount = await mutations.delete(countryId, userId);
|
|
69
|
+
emit('COUNTRY_REMOVE', { countryId });
|
|
70
|
+
return deletedCount;
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=configureCountriesModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configureCountriesModule.js","sourceRoot":"","sources":["../../src/module/configureCountriesModule.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"countryServices.js","sourceRoot":"","sources":["../../src/service/countryServices.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAExF,MAAM,CAAC,MAAM,eAAe,GAAoB;IAC9C,0BAA0B,EAAE,iCAAiC;CAC9D,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import 'abort-controller/polyfill';
|
|
2
|
+
import LRU from 'lru-cache';
|
|
3
|
+
// REMARK: --> combines defaultCurrency and resolveDefaultCurrencyCode helpers
|
|
4
|
+
const { NODE_ENV } = process.env;
|
|
5
|
+
const ttl = NODE_ENV === 'production' ? 1000 * 60 : 0; // minute or second
|
|
6
|
+
const currencyCodeCache = new LRU({
|
|
7
|
+
max: 500,
|
|
8
|
+
ttl,
|
|
9
|
+
});
|
|
10
|
+
const { UNCHAINED_CURRENCY } = process.env;
|
|
11
|
+
const getDefaultCurrency = async (modules, country) => {
|
|
12
|
+
if (country?.defaultCurrencyId) {
|
|
13
|
+
return modules.currencies.findCurrency({
|
|
14
|
+
currencyId: country.defaultCurrencyId,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
};
|
|
19
|
+
export const resolveDefaultCurrencyCodeService = async ({ isoCode }, { modules }) => {
|
|
20
|
+
const currencyCode = currencyCodeCache.get(isoCode);
|
|
21
|
+
if (currencyCode)
|
|
22
|
+
return currencyCode;
|
|
23
|
+
const country = await modules.countries.findCountry({ isoCode });
|
|
24
|
+
const currency = await getDefaultCurrency(modules, country);
|
|
25
|
+
const liveCurrencyCode = currency?.isoCode || UNCHAINED_CURRENCY || 'CHF';
|
|
26
|
+
currencyCodeCache.set(isoCode, liveCurrencyCode);
|
|
27
|
+
return liveCurrencyCode;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=resolveDefaultCurrencyCodeService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveDefaultCurrencyCodeService.js","sourceRoot":"","sources":["../../src/service/resolveDefaultCurrencyCodeService.ts"],"names":[],"mappings":"AAEA,OAAO,2BAA2B,CAAC;AACnC,OAAO,GAAG,MAAM,WAAW,CAAC;AAE5B,8EAA8E;AAE9E,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAEjC,MAAM,GAAG,GAAG,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,mBAAmB;AAE1E,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,GAAG,EAAE,GAAG;IACR,GAAG;CACJ,CAAC,CAAC;AAEH,MAAM,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAE3C,MAAM,kBAAkB,GAAG,KAAK,EAAE,OAAgB,EAAE,OAAiB,EAAE,EAAE;IACvE,IAAI,OAAO,EAAE,iBAAiB,EAAE;QAC9B,OAAO,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC;YACrC,UAAU,EAAE,OAAO,CAAC,iBAAiB;SACtC,CAAC,CAAC;KACJ;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iCAAiC,GAAsC,KAAK,EACvF,EAAE,OAAO,EAAE,EACX,EAAE,OAAO,EAAE,EACX,EAAE;IACF,MAAM,YAAY,GAAG,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACpD,IAAI,YAAY;QAAE,OAAO,YAAY,CAAC;IAEtC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IACjE,MAAM,QAAQ,GAAG,MAAM,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAE5D,MAAM,gBAAgB,GAAG,QAAQ,EAAE,OAAO,IAAI,kBAAkB,IAAI,KAAK,CAAC;IAC1E,iBAAiB,CAAC,GAAG,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAEjD,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC"}
|
package/package.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Package.describe({
|
|
2
|
+
name: 'unchained:core-countries',
|
|
3
|
+
version: '1.1.3',
|
|
4
|
+
summary: 'Unchained Engine Core: Countries',
|
|
5
|
+
git: 'https://github.com/unchainedshop/unchained',
|
|
6
|
+
documentation: 'README.md',
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
Npm.depends({
|
|
10
|
+
'emoji-flags': '1.3.0',
|
|
11
|
+
'i18n-iso-countries': '6.4.0',
|
|
12
|
+
'lru-cache': '7.7.0',
|
|
13
|
+
'abort-controller': '3.0.0',
|
|
14
|
+
'simpl-schema': '1.12.0',
|
|
15
|
+
'@unchainedshop/utils': '1.1.3',
|
|
16
|
+
// '@unchainedshop/events': '1.1.4', // PEER
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
Package.onUse((api) => {
|
|
20
|
+
api.versionsFrom('2.7.3');
|
|
21
|
+
api.use('ecmascript');
|
|
22
|
+
api.use('typescript');
|
|
23
|
+
|
|
24
|
+
api.mainModule('src/countries-index.ts', 'server');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
Package.onTest((api) => {
|
|
28
|
+
api.use('meteortesting:mocha');
|
|
29
|
+
api.use('ecmascript');
|
|
30
|
+
api.use('typescript');
|
|
31
|
+
|
|
32
|
+
api.use('unchained:mongodb@1.1.3');
|
|
33
|
+
api.use('unchained:core-countries');
|
|
34
|
+
|
|
35
|
+
api.mainModule('tests/countries-index.test.ts');
|
|
36
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@unchainedshop/core-countries",
|
|
3
|
+
"version": "1.1.3",
|
|
4
|
+
"main": "lib/countries-index.js",
|
|
5
|
+
"types": "lib/countries-index.d.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"clean": "rm -rf lib",
|
|
9
|
+
"build": "npm run clean && tsc -p tsconfig.build.json",
|
|
10
|
+
"watch": "tsc --watch",
|
|
11
|
+
"link:core": "npm link @unchainedshop/types",
|
|
12
|
+
"test": "cross-env METEOR_PACKAGE_DIRS=../ TEST_CLIENT=0 TEST_WATCH=1 meteor test-packages ./ --driver-package meteortesting:mocha --port 4200"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/unchainedshop/unchained.git"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"unchained",
|
|
20
|
+
"ecommerce",
|
|
21
|
+
"core"
|
|
22
|
+
],
|
|
23
|
+
"author": "Joël Meiller",
|
|
24
|
+
"license": "EUPL-1.2",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/unchainedshop/unchained/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@unchainedshop/events": "latest",
|
|
31
|
+
"@unchainedshop/utils": "latest",
|
|
32
|
+
"emoji-flags": "^1.3.0",
|
|
33
|
+
"i18n-iso-countries": "^7.5.0",
|
|
34
|
+
"lru-cache": "^7.10.2",
|
|
35
|
+
"simpl-schema": "^1.12.2"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/chai": "^4.3.1",
|
|
39
|
+
"@types/mocha": "^9.1.1",
|
|
40
|
+
"@unchainedshop/types": "latest",
|
|
41
|
+
"chai": "^4.3.6",
|
|
42
|
+
"cross-env": "^7.0.3",
|
|
43
|
+
"typescript": "^4.7.4"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Db } from '@unchainedshop/types/common';
|
|
2
|
+
import { Country } from '@unchainedshop/types/countries';
|
|
3
|
+
import { buildDbIndexes } from '@unchainedshop/utils';
|
|
4
|
+
|
|
5
|
+
export const CountriesCollection = async (db: Db) => {
|
|
6
|
+
const Countries = db.collection<Country>('countries');
|
|
7
|
+
|
|
8
|
+
await buildDbIndexes<Country>(Countries, [
|
|
9
|
+
{ index: { isoCode: 1 }, options: { unique: true } },
|
|
10
|
+
{
|
|
11
|
+
index: { isoCode: 'text', _id: 'text' },
|
|
12
|
+
options: {
|
|
13
|
+
weights: {
|
|
14
|
+
_id: 8,
|
|
15
|
+
isoCode: 6,
|
|
16
|
+
},
|
|
17
|
+
name: 'countries_fulltext_search',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
return Countries;
|
|
23
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Schemas } from '@unchainedshop/utils';
|
|
2
|
+
import SimpleSchema from 'simpl-schema';
|
|
3
|
+
|
|
4
|
+
export const CountriesSchema = new SimpleSchema(
|
|
5
|
+
{
|
|
6
|
+
isoCode: { type: String, required: true },
|
|
7
|
+
isActive: Boolean,
|
|
8
|
+
authorId: { type: String, required: true },
|
|
9
|
+
defaultCurrencyId: String,
|
|
10
|
+
...Schemas.timestampFields,
|
|
11
|
+
},
|
|
12
|
+
{ requiredByDefault: false },
|
|
13
|
+
);
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ModuleInput, ModuleMutations } from '@unchainedshop/types/common';
|
|
2
|
+
import { CountriesModule, Country, CountryQuery } from '@unchainedshop/types/countries';
|
|
3
|
+
import countryFlags from 'emoji-flags';
|
|
4
|
+
import countryI18n from 'i18n-iso-countries';
|
|
5
|
+
import { emit, registerEvents } from '@unchainedshop/events';
|
|
6
|
+
import {
|
|
7
|
+
generateDbFilterById,
|
|
8
|
+
generateDbMutations,
|
|
9
|
+
systemLocale,
|
|
10
|
+
buildSortOptions,
|
|
11
|
+
} from '@unchainedshop/utils';
|
|
12
|
+
import { CountriesCollection } from '../db/CountriesCollection';
|
|
13
|
+
import { CountriesSchema } from '../db/CountriesSchema';
|
|
14
|
+
|
|
15
|
+
const COUNTRY_EVENTS: string[] = ['COUNTRY_CREATE', 'COUNTRY_UPDATE', 'COUNTRY_REMOVE'];
|
|
16
|
+
|
|
17
|
+
const buildFindSelector = ({ includeInactive = false, queryString = '' }: CountryQuery) => {
|
|
18
|
+
const selector: { isActive?: true; $text?: any; deleted?: Date } = { deleted: null };
|
|
19
|
+
if (!includeInactive) selector.isActive = true;
|
|
20
|
+
if (queryString) selector.$text = { $search: queryString };
|
|
21
|
+
return selector;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const configureCountriesModule = async ({
|
|
25
|
+
db,
|
|
26
|
+
}: ModuleInput<Record<string, never>>): Promise<CountriesModule> => {
|
|
27
|
+
registerEvents(COUNTRY_EVENTS);
|
|
28
|
+
|
|
29
|
+
const Countries = await CountriesCollection(db);
|
|
30
|
+
|
|
31
|
+
const mutations = generateDbMutations<Country>(Countries, CountriesSchema) as ModuleMutations<Country>;
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
count: async (query) => {
|
|
35
|
+
const countryCount = await Countries.countDocuments(buildFindSelector(query));
|
|
36
|
+
return countryCount;
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
findCountry: async ({ countryId, isoCode }) => {
|
|
40
|
+
return Countries.findOne(countryId ? generateDbFilterById(countryId) : { isoCode });
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
findCountries: async ({ limit, offset, sort, includeInactive, queryString }, options) => {
|
|
44
|
+
const countries = Countries.find(buildFindSelector({ includeInactive, queryString }), {
|
|
45
|
+
skip: offset,
|
|
46
|
+
limit,
|
|
47
|
+
sort: buildSortOptions(sort),
|
|
48
|
+
...options,
|
|
49
|
+
});
|
|
50
|
+
return countries.toArray();
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
countryExists: async ({ countryId }) => {
|
|
54
|
+
const countryCount = await Countries.countDocuments(
|
|
55
|
+
generateDbFilterById(countryId, { deleted: null }),
|
|
56
|
+
{
|
|
57
|
+
limit: 1,
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
return !!countryCount;
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
name(country, language) {
|
|
64
|
+
return countryI18n.getName(country.isoCode, language) || language;
|
|
65
|
+
},
|
|
66
|
+
flagEmoji(country) {
|
|
67
|
+
return countryFlags.countryCode(country.isoCode).emoji || '❌';
|
|
68
|
+
},
|
|
69
|
+
isBase(country) {
|
|
70
|
+
return country.isoCode === systemLocale.country;
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
create: async (doc: Country, userId: string) => {
|
|
74
|
+
await Countries.deleteOne({ isoCode: doc.isoCode.toUpperCase(), deleted: { $ne: null } });
|
|
75
|
+
const countryId = await mutations.create(
|
|
76
|
+
{
|
|
77
|
+
...doc,
|
|
78
|
+
isoCode: doc.isoCode.toUpperCase(),
|
|
79
|
+
isActive: true,
|
|
80
|
+
},
|
|
81
|
+
userId,
|
|
82
|
+
);
|
|
83
|
+
emit('COUNTRY_CREATE', { countryId });
|
|
84
|
+
return countryId;
|
|
85
|
+
},
|
|
86
|
+
update: async (_id: string, doc: Partial<Country>, userId: string) => {
|
|
87
|
+
const countryId = await mutations.update(_id, { $set: doc }, userId);
|
|
88
|
+
emit('COUNTRY_UPDATE', { countryId });
|
|
89
|
+
return countryId;
|
|
90
|
+
},
|
|
91
|
+
delete: async (countryId, userId) => {
|
|
92
|
+
const deletedCount = await mutations.delete(countryId, userId);
|
|
93
|
+
emit('COUNTRY_REMOVE', { countryId });
|
|
94
|
+
return deletedCount;
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CountryServices } from '@unchainedshop/types/countries';
|
|
2
|
+
import { resolveDefaultCurrencyCodeService } from './resolveDefaultCurrencyCodeService';
|
|
3
|
+
|
|
4
|
+
export const countryServices: CountryServices = {
|
|
5
|
+
resolveDefaultCurrencyCode: resolveDefaultCurrencyCodeService,
|
|
6
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Country, ResolveDefaultCurrencyCodeService } from '@unchainedshop/types/countries';
|
|
2
|
+
import { Modules } from '@unchainedshop/types/modules';
|
|
3
|
+
import 'abort-controller/polyfill';
|
|
4
|
+
import LRU from 'lru-cache';
|
|
5
|
+
|
|
6
|
+
// REMARK: --> combines defaultCurrency and resolveDefaultCurrencyCode helpers
|
|
7
|
+
|
|
8
|
+
const { NODE_ENV } = process.env;
|
|
9
|
+
|
|
10
|
+
const ttl = NODE_ENV === 'production' ? 1000 * 60 : 0; // minute or second
|
|
11
|
+
|
|
12
|
+
const currencyCodeCache = new LRU({
|
|
13
|
+
max: 500,
|
|
14
|
+
ttl,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const { UNCHAINED_CURRENCY } = process.env;
|
|
18
|
+
|
|
19
|
+
const getDefaultCurrency = async (modules: Modules, country?: Country) => {
|
|
20
|
+
if (country?.defaultCurrencyId) {
|
|
21
|
+
return modules.currencies.findCurrency({
|
|
22
|
+
currencyId: country.defaultCurrencyId,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const resolveDefaultCurrencyCodeService: ResolveDefaultCurrencyCodeService = async (
|
|
29
|
+
{ isoCode },
|
|
30
|
+
{ modules },
|
|
31
|
+
) => {
|
|
32
|
+
const currencyCode = currencyCodeCache.get(isoCode);
|
|
33
|
+
if (currencyCode) return currencyCode;
|
|
34
|
+
|
|
35
|
+
const country = await modules.countries.findCountry({ isoCode });
|
|
36
|
+
const currency = await getDefaultCurrency(modules, country);
|
|
37
|
+
|
|
38
|
+
const liveCurrencyCode = currency?.isoCode || UNCHAINED_CURRENCY || 'CHF';
|
|
39
|
+
currencyCodeCache.set(isoCode, liveCurrencyCode);
|
|
40
|
+
|
|
41
|
+
return liveCurrencyCode;
|
|
42
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { assert } from 'chai';
|
|
2
|
+
import { initDb } from 'meteor/unchained:mongodb';
|
|
3
|
+
import { configureCountriesModule } from 'meteor/unchained:core-countries';
|
|
4
|
+
|
|
5
|
+
describe('Test exports', () => {
|
|
6
|
+
let module;
|
|
7
|
+
|
|
8
|
+
before(async () => {
|
|
9
|
+
const db = await initDb();
|
|
10
|
+
module = await configureCountriesModule({ db });
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('Check Country module', async () => {
|
|
14
|
+
assert.ok(module);
|
|
15
|
+
assert.isFunction(module.findCountry);
|
|
16
|
+
assert.isFunction(module.findCountries);
|
|
17
|
+
assert.isFunction(module.countryExists);
|
|
18
|
+
assert.isFunction(module.create);
|
|
19
|
+
assert.isFunction(module.update);
|
|
20
|
+
assert.isFunction(module.delete);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('Mutate country', async () => {
|
|
24
|
+
const countryId = await module.create(
|
|
25
|
+
{
|
|
26
|
+
authorId: 'Test-User-1',
|
|
27
|
+
isoCode: 'CHF',
|
|
28
|
+
},
|
|
29
|
+
'Test-User-1'
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
assert.ok(countryId);
|
|
33
|
+
const country = await module.findCountry(countryId);
|
|
34
|
+
|
|
35
|
+
assert.ok(country);
|
|
36
|
+
assert.equal(country._id, countryId);
|
|
37
|
+
assert.equal(country.isoCode, 'CHF');
|
|
38
|
+
assert.equal(country.userId, 'Test-User-1');
|
|
39
|
+
assert.isDefined(country.created);
|
|
40
|
+
assert.isUndefined(country.updated);
|
|
41
|
+
assert.isUndefined(country.updatedBy);
|
|
42
|
+
assert.equal(country.createdBy, 'Test-User-1');
|
|
43
|
+
|
|
44
|
+
const deletedCount = await module.delete(countryId);
|
|
45
|
+
assert.equal(deletedCount, 1);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"allowSyntheticDefaultImports": true,
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"lib": ["esnext"],
|
|
10
|
+
"module": "esnext",
|
|
11
|
+
"moduleResolution": "node",
|
|
12
|
+
"noImplicitReturns": true,
|
|
13
|
+
"noUnusedLocals": false,
|
|
14
|
+
"outDir": "lib",
|
|
15
|
+
"preserveWatchOutput": true,
|
|
16
|
+
"skipLibCheck": true,
|
|
17
|
+
"sourceMap": true,
|
|
18
|
+
"target": "esnext",
|
|
19
|
+
"types": ["node"],
|
|
20
|
+
"baseUrl": ".", // This must be specified if "paths" is.
|
|
21
|
+
"paths": {
|
|
22
|
+
"meteor/unchained:*": ["node_modules/@unchainedshop/types/index.d.ts"]
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"include": ["src"]
|
|
26
|
+
}
|