@unchainedshop/core-countries 5.0.0-alpha.1 → 5.0.0-alpha.10
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 +11 -58
- package/lib/db/CountriesCollection.js +11 -13
- package/lib/module/configureCountriesModule.js +1 -2
- package/package.json +9 -5
package/README.md
CHANGED
|
@@ -13,72 +13,25 @@ npm install @unchainedshop/core-countries
|
|
|
13
13
|
|
|
14
14
|
## Usage
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
import { configureCountriesModule } from '@unchainedshop/core-countries';
|
|
16
|
+
The platform initializes this module as `platform.unchainedAPI.modules.countries`.
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
```typescript
|
|
19
|
+
const { countries } = platform.unchainedAPI.modules;
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
const countryId = await countriesModule.create({
|
|
21
|
+
const countryId = await countries.create({
|
|
23
22
|
isoCode: 'CH',
|
|
24
23
|
defaultCurrencyCode: 'CHF',
|
|
24
|
+
isActive: true,
|
|
25
25
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
// Get localized country name
|
|
31
|
-
const name = countriesModule.name(country, new Intl.Locale('en'));
|
|
26
|
+
const country = await countries.findCountry({ countryId });
|
|
27
|
+
if (country) {
|
|
28
|
+
const name = countries.name(country, new Intl.Locale('en'));
|
|
29
|
+
}
|
|
32
30
|
```
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
### Module Configuration
|
|
37
|
-
|
|
38
|
-
| Export | Description |
|
|
39
|
-
|--------|-------------|
|
|
40
|
-
| `configureCountriesModule` | Configure and return the countries module |
|
|
41
|
-
|
|
42
|
-
### Queries
|
|
43
|
-
|
|
44
|
-
| Method | Description |
|
|
45
|
-
|--------|-------------|
|
|
46
|
-
| `findCountry` | Find country by ID or ISO code |
|
|
47
|
-
| `findCountries` | Find countries with filtering, sorting, and pagination |
|
|
48
|
-
| `count` | Count countries matching query |
|
|
49
|
-
| `countryExists` | Check if a country exists |
|
|
50
|
-
|
|
51
|
-
### Mutations
|
|
52
|
-
|
|
53
|
-
| Method | Description |
|
|
54
|
-
|--------|-------------|
|
|
55
|
-
| `create` | Create a new country |
|
|
56
|
-
| `update` | Update an existing country |
|
|
57
|
-
| `delete` | Soft delete a country |
|
|
58
|
-
|
|
59
|
-
### Helper Methods
|
|
60
|
-
|
|
61
|
-
| Method | Description |
|
|
62
|
-
|--------|-------------|
|
|
63
|
-
| `name` | Get localized country name using Intl.DisplayNames |
|
|
64
|
-
| `flagEmoji` | Get flag emoji for a country |
|
|
65
|
-
| `isBase` | Check if country is the base/system country |
|
|
66
|
-
|
|
67
|
-
### Types
|
|
68
|
-
|
|
69
|
-
| Export | Description |
|
|
70
|
-
|--------|-------------|
|
|
71
|
-
| `Country` | Country document type |
|
|
72
|
-
| `CountryQuery` | Query parameters type |
|
|
73
|
-
| `CountriesModule` | Module interface type |
|
|
74
|
-
|
|
75
|
-
## Events
|
|
32
|
+
`create` returns a country ID. Configure currencies separately before assigning them to countries.
|
|
76
33
|
|
|
77
|
-
|
|
78
|
-
|-------|-------------|
|
|
79
|
-
| `COUNTRY_CREATE` | Emitted when a country is created |
|
|
80
|
-
| `COUNTRY_UPDATE` | Emitted when a country is updated |
|
|
81
|
-
| `COUNTRY_REMOVE` | Emitted when a country is removed |
|
|
34
|
+
See the [module guide](https://docs.unchained.shop/platform-configuration/modules/countries), [public exports](src/countries-index.ts), and [module implementation](src/module/configureCountriesModule.ts) for queries, helpers, and events.
|
|
82
35
|
|
|
83
36
|
## License
|
|
84
37
|
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import { mongodb, buildDbIndexes
|
|
1
|
+
import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
|
|
2
2
|
export const CountriesCollection = async (db) => {
|
|
3
3
|
const Countries = db.collection('countries');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
isoCode: 6,
|
|
12
|
-
},
|
|
13
|
-
name: 'countries_fulltext_search',
|
|
4
|
+
await buildDbIndexes(Countries, [
|
|
5
|
+
{
|
|
6
|
+
index: { isoCode: 'text', _id: 'text' },
|
|
7
|
+
options: {
|
|
8
|
+
weights: {
|
|
9
|
+
_id: 8,
|
|
10
|
+
isoCode: 6,
|
|
14
11
|
},
|
|
12
|
+
name: 'countries_fulltext_search',
|
|
15
13
|
},
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
},
|
|
15
|
+
]);
|
|
18
16
|
await buildDbIndexes(Countries, [
|
|
19
17
|
{ index: { isoCode: 1 }, options: { unique: true } },
|
|
20
18
|
{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mongodb
|
|
1
|
+
import { mongodb } from '@unchainedshop/mongodb';
|
|
2
2
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
3
3
|
import { generateDbFilterById, buildSortOptions, generateDbObjectId } from '@unchainedshop/mongodb';
|
|
4
4
|
import { SortDirection } from '@unchainedshop/utils';
|
|
@@ -14,7 +14,6 @@ export const buildFindSelector = ({ includeInactive = false, queryString = '', i
|
|
|
14
14
|
selector.isoCode = { $in: isoCodes };
|
|
15
15
|
}
|
|
16
16
|
if (queryString) {
|
|
17
|
-
assertDocumentDBCompatMode();
|
|
18
17
|
selector.$text = { $search: queryString };
|
|
19
18
|
}
|
|
20
19
|
return selector;
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-countries",
|
|
3
3
|
"description": "Country management module for the Unchained Engine",
|
|
4
|
-
"version": "5.0.0-alpha.
|
|
4
|
+
"version": "5.0.0-alpha.10",
|
|
5
|
+
"files": [
|
|
6
|
+
"lib"
|
|
7
|
+
],
|
|
5
8
|
"main": "lib/countries-index.js",
|
|
6
9
|
"types": "lib/countries-index.d.ts",
|
|
7
10
|
"type": "module",
|
|
@@ -35,11 +38,12 @@
|
|
|
35
38
|
},
|
|
36
39
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
37
40
|
"dependencies": {
|
|
38
|
-
"@unchainedshop/events": "^5.0.0-alpha.
|
|
39
|
-
"@unchainedshop/
|
|
41
|
+
"@unchainedshop/events": "^5.0.0-alpha.10",
|
|
42
|
+
"@unchainedshop/mongodb": "^5.0.0-alpha.10",
|
|
43
|
+
"@unchainedshop/utils": "^5.0.0-alpha.10"
|
|
40
44
|
},
|
|
41
45
|
"devDependencies": {
|
|
42
|
-
"@types/node": "^
|
|
43
|
-
"typescript": "^
|
|
46
|
+
"@types/node": "^26.2.0",
|
|
47
|
+
"typescript": "^6.0.3"
|
|
44
48
|
}
|
|
45
49
|
}
|