@unchainedshop/core-countries 2.12.1 → 2.13.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.
@@ -1,3 +1,2 @@
1
1
  export { configureCountriesModule } from './module/configureCountriesModule.js';
2
- export { countryServices } from './service/countryServices.js';
3
2
  //# sourceMappingURL=countries-index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"countries-index.d.ts","sourceRoot":"","sources":["../src/countries-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC"}
1
+ {"version":3,"file":"countries-index.d.ts","sourceRoot":"","sources":["../src/countries-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC"}
@@ -1,3 +1,2 @@
1
1
  export { configureCountriesModule } from './module/configureCountriesModule.js';
2
- export { countryServices } from './service/countryServices.js';
3
2
  //# sourceMappingURL=countries-index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"countries-index.js","sourceRoot":"","sources":["../src/countries-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC"}
1
+ {"version":3,"file":"countries-index.js","sourceRoot":"","sources":["../src/countries-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC"}
@@ -3,7 +3,7 @@ import SimpleSchema from 'simpl-schema';
3
3
  export const CountriesSchema = new SimpleSchema({
4
4
  isoCode: { type: String, required: true },
5
5
  isActive: Boolean,
6
- defaultCurrencyId: String,
6
+ defaultCurrencyCode: String,
7
7
  ...Schemas.timestampFields,
8
8
  }, { requiredByDefault: false });
9
9
  //# sourceMappingURL=CountriesSchema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CountriesSchema.js","sourceRoot":"","sources":["../../src/db/CountriesSchema.ts"],"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,iBAAiB,EAAE,MAAM;IACzB,GAAG,OAAO,CAAC,eAAe;CAC3B,EACD,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAC"}
1
+ {"version":3,"file":"CountriesSchema.js","sourceRoot":"","sources":["../../src/db/CountriesSchema.ts"],"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,mBAAmB,EAAE,MAAM;IAC3B,GAAG,OAAO,CAAC,eAAe;CAC3B,EACD,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Migration, MigrationRepository } from '@unchainedshop/types/core.js';
2
+ export default function addMigrations(repository: MigrationRepository<Migration>): void;
3
+ //# sourceMappingURL=addMigrations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addMigrations.d.ts","sourceRoot":"","sources":["../../src/migrations/addMigrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAI9E,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,UAAU,EAAE,mBAAmB,CAAC,SAAS,CAAC,QAmC/E"}
@@ -0,0 +1,28 @@
1
+ import { CountriesCollection } from '../db/CountriesCollection.js';
2
+ export default function addMigrations(repository) {
3
+ repository?.register({
4
+ id: 20240712123500,
5
+ name: 'Convert all tags to lower case to make it easy for search',
6
+ up: async () => {
7
+ const Currencies = await repository.db.collection('currencies');
8
+ const Countries = await CountriesCollection(repository.db);
9
+ const allCurrencies = await Currencies.find({}).toArray();
10
+ const allCountries = await Countries.find({}).toArray();
11
+ const currencyMap = allCurrencies.reduce((acc, currency) => {
12
+ acc[currency._id] = currency.isoCode;
13
+ return acc;
14
+ }, {});
15
+ for (const country of allCountries) {
16
+ await Countries.updateOne({ _id: country._id, defaultCurrencyId: { $exists: true } }, {
17
+ $set: {
18
+ defaultCurrencyCode: currencyMap[country.defaultCurrencyId],
19
+ },
20
+ $unset: {
21
+ defaultCurrencyId: 1,
22
+ },
23
+ });
24
+ }
25
+ },
26
+ });
27
+ }
28
+ //# sourceMappingURL=addMigrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addMigrations.js","sourceRoot":"","sources":["../../src/migrations/addMigrations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAGnE,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,UAA0C;IAC9E,UAAU,EAAE,QAAQ,CAAC;QACnB,EAAE,EAAE,cAAc;QAClB,IAAI,EAAE,2DAA2D;QACjE,EAAE,EAAE,KAAK,IAAI,EAAE;YACb,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,EAAE,CAAC,UAAU,CAAmC,YAAY,CAAC,CAAC;YAClG,MAAM,SAAS,GAAG,MAAM,mBAAmB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YAE3D,MAAM,aAAa,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;YAC1D,MAAM,YAAY,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;YAExD,MAAM,WAAW,GAAG,aAAa,CAAC,MAAM,CACtC,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE;gBAChB,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC;gBACrC,OAAO,GAAG,CAAC;YACb,CAAC,EACD,EAAyB,CAC1B,CAAC;YAEF,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC;gBACnC,MAAM,SAAS,CAAC,SAAS,CACvB,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,iBAAiB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAC1D;oBACE,IAAI,EAAE;wBACJ,mBAAmB,EACjB,WAAW,CAAE,OAAmD,CAAC,iBAAiB,CAAC;qBACtF;oBACD,MAAM,EAAE;wBACN,iBAAiB,EAAE,CAAC;qBACrB;iBACF,CACF,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -5,5 +5,5 @@ export declare const buildFindSelector: ({ includeInactive, queryString }: Count
5
5
  $text?: any;
6
6
  deleted?: Date;
7
7
  };
8
- export declare const configureCountriesModule: ({ db, }: ModuleInput<Record<string, never>>) => Promise<CountriesModule>;
8
+ export declare const configureCountriesModule: ({ db, migrationRepository, }: ModuleInput<Record<string, never>>) => Promise<CountriesModule>;
9
9
  //# sourceMappingURL=configureCountriesModule.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"configureCountriesModule.d.ts","sourceRoot":"","sources":["../../src/module/configureCountriesModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAmB,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAW,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAU3F,eAAO,MAAM,iBAAiB,qCAAmD,YAAY;eAC9D,IAAI;YAAU,GAAG;cAAY,IAAI;CAI/D,CAAC;AAEF,eAAO,MAAM,wBAAwB,YAElC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,KAAG,OAAO,CAAC,eAAe,CA0E9D,CAAC"}
1
+ {"version":3,"file":"configureCountriesModule.d.ts","sourceRoot":"","sources":["../../src/module/configureCountriesModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAmB,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAW,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAW3F,eAAO,MAAM,iBAAiB,qCAAmD,YAAY;eAC9D,IAAI;YAAU,GAAG;cAAY,IAAI;CAI/D,CAAC;AAEF,eAAO,MAAM,wBAAwB,iCAGlC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,KAAG,OAAO,CAAC,eAAe,CA6E9D,CAAC"}
@@ -4,6 +4,7 @@ import { SortDirection } from '@unchainedshop/types/api.js';
4
4
  import { systemLocale } from '@unchainedshop/utils';
5
5
  import { CountriesCollection } from '../db/CountriesCollection.js';
6
6
  import { CountriesSchema } from '../db/CountriesSchema.js';
7
+ import addMigrations from '../migrations/addMigrations.js';
7
8
  const COUNTRY_EVENTS = ['COUNTRY_CREATE', 'COUNTRY_UPDATE', 'COUNTRY_REMOVE'];
8
9
  export const buildFindSelector = ({ includeInactive = false, queryString = '' }) => {
9
10
  const selector = { deleted: null };
@@ -13,8 +14,10 @@ export const buildFindSelector = ({ includeInactive = false, queryString = '' })
13
14
  selector.$text = { $search: queryString };
14
15
  return selector;
15
16
  };
16
- export const configureCountriesModule = async ({ db, }) => {
17
+ export const configureCountriesModule = async ({ db, migrationRepository, }) => {
17
18
  registerEvents(COUNTRY_EVENTS);
19
+ // Migration
20
+ addMigrations(migrationRepository);
18
21
  const Countries = await CountriesCollection(db);
19
22
  const mutations = generateDbMutations(Countries, CountriesSchema);
20
23
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"configureCountriesMod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C1F,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC;gBACvC,GAAG,GAAG;gBACN,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE;gBAClC,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC;YACH,MAAM,IAAI,CAAC,gBAAgB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;YAC5C,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,EAAE,KAAK,EAAE,GAAW,EAAE,GAAqB,EAAE,EAAE;YACnD,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;YAC7D,MAAM,IAAI,CAAC,gBAAgB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;YAC5C,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE;YAC1B,MAAM,YAAY,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YACvD,MAAM,IAAI,CAAC,gBAAgB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;YAC5C,OAAO,YAAY,CAAC;QACtB,CAAC;QAED,iBAAiB,EAAE,SAAS,CAAC,iBAAiB;KAC/C,CAAC;AACJ,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/core-countries",
3
- "version": "2.12.1",
3
+ "version": "2.13.0",
4
4
  "main": "lib/countries-index.js",
5
5
  "exports": {
6
6
  ".": "./lib/countries-index.js",
@@ -31,17 +31,16 @@
31
31
  },
32
32
  "homepage": "https://github.com/unchainedshop/unchained#readme",
33
33
  "dependencies": {
34
- "@unchainedshop/events": "^2.12.1",
35
- "@unchainedshop/utils": "^2.12.1",
36
- "lru-cache": "^10.4.0",
34
+ "@unchainedshop/events": "^2.13.0",
35
+ "@unchainedshop/utils": "^2.13.0",
37
36
  "simpl-schema": "^3.4.6"
38
37
  },
39
38
  "devDependencies": {
40
- "@types/node": "^20.14.10",
41
- "@unchainedshop/types": "^2.12.1",
39
+ "@types/node": "^20.14.12",
40
+ "@unchainedshop/types": "^2.13.0",
42
41
  "cross-env": "^7.0.3",
43
42
  "jest": "^29.7.0",
44
- "ts-jest": "^29.1.5",
45
- "typescript": "^5.5.3"
43
+ "ts-jest": "^29.2.3",
44
+ "typescript": "^5.5.4"
46
45
  }
47
46
  }
@@ -1,3 +1 @@
1
1
  export { configureCountriesModule } from './module/configureCountriesModule.js';
2
-
3
- export { countryServices } from './service/countryServices.js';
@@ -5,7 +5,7 @@ export const CountriesSchema = new SimpleSchema(
5
5
  {
6
6
  isoCode: { type: String, required: true },
7
7
  isActive: Boolean,
8
- defaultCurrencyId: String,
8
+ defaultCurrencyCode: String,
9
9
  ...Schemas.timestampFields,
10
10
  },
11
11
  { requiredByDefault: false },
@@ -0,0 +1,40 @@
1
+ import { Migration, MigrationRepository } from '@unchainedshop/types/core.js';
2
+ import { CountriesCollection } from '../db/CountriesCollection.js';
3
+ import { Country } from '@unchainedshop/types/countries.js';
4
+
5
+ export default function addMigrations(repository: MigrationRepository<Migration>) {
6
+ repository?.register({
7
+ id: 20240712123500,
8
+ name: 'Convert all tags to lower case to make it easy for search',
9
+ up: async () => {
10
+ const Currencies = await repository.db.collection<{ _id: string; isoCode: string }>('currencies');
11
+ const Countries = await CountriesCollection(repository.db);
12
+
13
+ const allCurrencies = await Currencies.find({}).toArray();
14
+ const allCountries = await Countries.find({}).toArray();
15
+
16
+ const currencyMap = allCurrencies.reduce(
17
+ (acc, currency) => {
18
+ acc[currency._id] = currency.isoCode;
19
+ return acc;
20
+ },
21
+ {} as Record<string, any>,
22
+ );
23
+
24
+ for (const country of allCountries) {
25
+ await Countries.updateOne(
26
+ { _id: country._id, defaultCurrencyId: { $exists: true } },
27
+ {
28
+ $set: {
29
+ defaultCurrencyCode:
30
+ currencyMap[(country as Country & { defaultCurrencyId: string }).defaultCurrencyId],
31
+ },
32
+ $unset: {
33
+ defaultCurrencyId: 1,
34
+ },
35
+ },
36
+ );
37
+ }
38
+ },
39
+ });
40
+ }
@@ -6,6 +6,7 @@ import { SortDirection, SortOption } from '@unchainedshop/types/api.js';
6
6
  import { systemLocale } from '@unchainedshop/utils';
7
7
  import { CountriesCollection } from '../db/CountriesCollection.js';
8
8
  import { CountriesSchema } from '../db/CountriesSchema.js';
9
+ import addMigrations from '../migrations/addMigrations.js';
9
10
 
10
11
  const COUNTRY_EVENTS: string[] = ['COUNTRY_CREATE', 'COUNTRY_UPDATE', 'COUNTRY_REMOVE'];
11
12
 
@@ -18,9 +19,13 @@ export const buildFindSelector = ({ includeInactive = false, queryString = '' }:
18
19
 
19
20
  export const configureCountriesModule = async ({
20
21
  db,
22
+ migrationRepository,
21
23
  }: ModuleInput<Record<string, never>>): Promise<CountriesModule> => {
22
24
  registerEvents(COUNTRY_EVENTS);
23
25
 
26
+ // Migration
27
+ addMigrations(migrationRepository);
28
+
24
29
  const Countries = await CountriesCollection(db);
25
30
 
26
31
  const mutations = generateDbMutations<Country>(Countries, CountriesSchema) as ModuleMutations<Country>;
@@ -1,3 +0,0 @@
1
- import { CountryServices } from '@unchainedshop/types/countries.js';
2
- export declare const countryServices: CountryServices;
3
- //# sourceMappingURL=countryServices.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"countryServices.d.ts","sourceRoot":"","sources":["../../src/service/countryServices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAGpE,eAAO,MAAM,eAAe,EAAE,eAE7B,CAAC"}
@@ -1,5 +0,0 @@
1
- import { resolveDefaultCurrencyCodeService } from './resolveDefaultCurrencyCodeService.js';
2
- export const countryServices = {
3
- resolveDefaultCurrencyCode: resolveDefaultCurrencyCodeService,
4
- };
5
- //# sourceMappingURL=countryServices.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"countryServices.js","sourceRoot":"","sources":["../../src/service/countryServices.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAE3F,MAAM,CAAC,MAAM,eAAe,GAAoB;IAC9C,0BAA0B,EAAE,iCAAiC;CAC9D,CAAC"}
@@ -1,3 +0,0 @@
1
- import { ResolveDefaultCurrencyCodeService } from '@unchainedshop/types/countries.js';
2
- export declare const resolveDefaultCurrencyCodeService: ResolveDefaultCurrencyCodeService;
3
- //# sourceMappingURL=resolveDefaultCurrencyCodeService.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolveDefaultCurrencyCodeService.d.ts","sourceRoot":"","sources":["../../src/service/resolveDefaultCurrencyCodeService.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,iCAAiC,EAAE,MAAM,mCAAmC,CAAC;AAuB/F,eAAO,MAAM,iCAAiC,EAAE,iCAc/C,CAAC"}
@@ -1,27 +0,0 @@
1
- import * as lruCache from 'lru-cache';
2
- const { NODE_ENV } = process.env;
3
- const ttl = NODE_ENV === 'production' ? 1000 * 1 : 0; // minute or second
4
- const currencyCodeCache = new lruCache.LRUCache({
5
- max: 500,
6
- ttl,
7
- });
8
- const { UNCHAINED_CURRENCY } = process.env;
9
- const getDefaultCurrency = async (modules, country) => {
10
- if (country?.defaultCurrencyId) {
11
- return modules.currencies.findCurrency({
12
- currencyId: country.defaultCurrencyId,
13
- });
14
- }
15
- return null;
16
- };
17
- export const resolveDefaultCurrencyCodeService = async ({ isoCode }, { modules }) => {
18
- const currencyCode = currencyCodeCache.get(isoCode);
19
- if (currencyCode)
20
- return currencyCode;
21
- const country = await modules.countries.findCountry({ isoCode });
22
- const currency = await getDefaultCurrency(modules, country);
23
- const liveCurrencyCode = currency?.isoCode || UNCHAINED_CURRENCY || 'CHF';
24
- currencyCodeCache.set(isoCode, liveCurrencyCode);
25
- return liveCurrencyCode;
26
- };
27
- //# sourceMappingURL=resolveDefaultCurrencyCodeService.js.map
@@ -1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,kBAAkB,IAAI,KAAK,CAAC;IAC1E,iBAAiB,CAAC,GAAG,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAEjD,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC"}
@@ -1,6 +0,0 @@
1
- import { CountryServices } from '@unchainedshop/types/countries.js';
2
- import { resolveDefaultCurrencyCodeService } from './resolveDefaultCurrencyCodeService.js';
3
-
4
- export const countryServices: CountryServices = {
5
- resolveDefaultCurrencyCode: resolveDefaultCurrencyCodeService,
6
- };
@@ -1,39 +0,0 @@
1
- import { Context } from '@unchainedshop/types/api.js';
2
- import { Country, ResolveDefaultCurrencyCodeService } from '@unchainedshop/types/countries.js';
3
- import * as lruCache from 'lru-cache';
4
-
5
- const { NODE_ENV } = process.env;
6
-
7
- const ttl = NODE_ENV === 'production' ? 1000 * 1 : 0; // minute or second
8
-
9
- const currencyCodeCache = new lruCache.LRUCache({
10
- max: 500,
11
- ttl,
12
- });
13
-
14
- const { UNCHAINED_CURRENCY } = process.env;
15
-
16
- const getDefaultCurrency = async (modules: Context['modules'], country?: Country) => {
17
- if (country?.defaultCurrencyId) {
18
- return modules.currencies.findCurrency({
19
- currencyId: country.defaultCurrencyId,
20
- });
21
- }
22
- return null;
23
- };
24
-
25
- export const resolveDefaultCurrencyCodeService: ResolveDefaultCurrencyCodeService = async (
26
- { isoCode },
27
- { modules }: Context,
28
- ) => {
29
- const currencyCode = currencyCodeCache.get(isoCode) as string;
30
- if (currencyCode) return currencyCode;
31
-
32
- const country = await modules.countries.findCountry({ isoCode });
33
- const currency = await getDefaultCurrency(modules, country);
34
-
35
- const liveCurrencyCode = currency?.isoCode || UNCHAINED_CURRENCY || 'CHF';
36
- currencyCodeCache.set(isoCode, liveCurrencyCode);
37
-
38
- return liveCurrencyCode;
39
- };