@unchainedshop/core-products 1.1.3 → 1.2.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/jest.config.js +5 -0
- package/lib/module/configureProductMediaModule.js +2 -1
- package/lib/module/configureProductMediaModule.js.map +1 -1
- package/lib/module/configureProductTextsModule.js +2 -1
- package/lib/module/configureProductTextsModule.js.map +1 -1
- package/lib/module/configureProductVariationsModule.js +2 -1
- package/lib/module/configureProductVariationsModule.js.map +1 -1
- package/package.json +16 -13
- package/src/module/configureProductMediaModule.ts +3 -1
- package/src/module/configureProductTextsModule.ts +5 -3
- package/src/module/configureProductVariationsModule.ts +3 -1
- package/tests/products-index.test.ts +2 -2
- package/tsconfig.json +26 -5
- package/.npm/package/README +0 -7
- package/.npm/package/npm-shrinkwrap.json +0 -55
- package/.versions +0 -53
- package/package.js +0 -35
- package/plugins/product-catalog-price.ts +0 -56
- package/plugins/product-discount.ts +0 -69
- package/plugins/product-price-ECB-interbank-exchange.ts +0 -108
- package/plugins/product-price-coinbase-exchange.ts +0 -82
- package/plugins/product-price-cryptopay.ts +0 -25
- package/plugins/product-price-rateconversion.ts +0 -73
- package/plugins/product-price-round.ts +0 -78
- package/plugins/product-swiss-tax.ts +0 -117
- package/plugins/utils/cache.js +0 -32
- package/tsconfig.build.json +0 -26
package/jest.config.js
ADDED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import localePkg from 'locale';
|
|
2
2
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
3
3
|
import { findLocalizedText, generateDbFilterById, generateDbMutations, generateDbObjectId, } from '@unchainedshop/utils';
|
|
4
4
|
import { FileDirector } from '@unchainedshop/file-upload';
|
|
5
5
|
import { ProductMediaCollection } from '../db/ProductMediaCollection';
|
|
6
6
|
import { ProductMediaSchema } from '../db/ProductMediaSchema';
|
|
7
|
+
const { Locale } = localePkg;
|
|
7
8
|
const PRODUCT_MEDIA_EVENTS = [
|
|
8
9
|
'PRODUCT_ADD_MEDIA',
|
|
9
10
|
'PRODUCT_REMOVE_MEDIA',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureProductMediaModule.js","sourceRoot":"","sources":["../../src/module/configureProductMediaModule.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"configureProductMediaModule.js","sourceRoot":"","sources":["../../src/module/configureProductMediaModule.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,QAAQ,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;AAE7B,MAAM,oBAAoB,GAAG;IAC3B,mBAAmB;IACnB,sBAAsB;IACtB,uBAAuB;IACvB,2BAA2B;CAC5B,CAAC;AAEF,YAAY,CAAC,0BAA0B,CAAC,eAAe,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE;IAC3F,MAAM,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CACjC;QACE,SAAS,EAAE,IAAI,CAAC,IAAI,EAAE,SAAmB;QACzC,OAAO,EAAE,IAAI,CAAC,GAAG;KAClB,EACD,MAAM,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAC3C,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,EAAE,EAChD,EAAE,GACiC,EAA+B,EAA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EAAE,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE;gBAC3D,MAAM,YAAY,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;gBAExC,MAAM,IAAI,GAAG,MAAM,iBAAiB,CAClC,iBAAiB,EACjB,EAAE,cAAc,EAAE,EAClB,YAAY,CACb,CAAC;gBAEF,OAAO,IAAI,CAAC;YACd,CAAC;YAED,YAAY;YACZ,gBAAgB,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;gBACxD,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,GAAG,CAClC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,EAAE,EAAE,CACzC,mBAAmB,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,CACnE,CACF,CAAC;gBAEF,IAAI,CAAC,2BAA2B,EAAE;oBAChC,cAAc;oBACd,UAAU;iBACX,CAAC,CAAC;gBAEH,OAAO,UAAU,CAAC;YACpB,CAAC;YAED,mBAAmB;SACpB;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import localePkg from 'locale';
|
|
2
2
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
3
3
|
import { findLocalizedText, findUnusedSlug, generateDbFilterById, generateDbObjectId, } from '@unchainedshop/utils';
|
|
4
4
|
import { productsSettings } from '../products-settings';
|
|
5
|
+
const { Locale } = localePkg;
|
|
5
6
|
const PRODUCT_TEXT_EVENTS = ['PRODUCT_UPDATE_TEXTS'];
|
|
6
7
|
export const configureProductTextsModule = ({ Products, ProductTexts, }) => {
|
|
7
8
|
registerEvents(PRODUCT_TEXT_EVENTS);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureProductTextsModule.js","sourceRoot":"","sources":["../../src/module/configureProductTextsModule.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"configureProductTextsModule.js","sourceRoot":"","sources":["../../src/module/configureProductTextsModule.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,QAAQ,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;AAE7B,MAAM,mBAAmB,GAAG,CAAC,sBAAsB,CAAC,CAAC;AAErD,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,EAC1C,QAAQ,EACR,YAAY,GAIb,EAA2B,EAAE;IAC5B,cAAc,CAAC,mBAAmB,CAAC,CAAC;IAEpC,MAAM,QAAQ,GAAG,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE;QACpD,MAAM,iBAAiB,GAAG,KAAK,EAAE,gBAAwB,EAAE,EAAE;YAC3D,OAAO,CACL,CAAC,MAAM,YAAY,CAAC,cAAc,CAChC;gBACE,SAAS,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE;gBAC7B,IAAI,EAAE,gBAAgB;aACvB,EACD,EAAE,KAAK,EAAE,CAAC,EAAE,CACb,CAAC,KAAK,CAAC,CACT,CAAC;QACJ,CAAC,CAAC;QAEF,MAAM,QAAQ,GAAG,cAAc,CAAC,iBAAiB,EAAE,EAAE,OAAO,EAAE,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;QAC1F,OAAO,QAAQ,CAAC;YACd,YAAY,EAAE,IAAI;YAClB,KAAK,EAAE,KAAK,IAAI,SAAS;SAC1B,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,mBAAmB,GAAmD,KAAK,EAC/E,SAAS,EACT,MAA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AED,YAAY;QACZ,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAC9C,MAAM,YAAY,GAAG,KAAK;gBACxB,CAAC,CAAC,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CACzF;gBACH,CAAC,CAAC,EAAE,CAAC;YAEP,IAAI,CAAC,sBAAsB,EAAE;gBAC3B,SAAS;gBACT,YAAY;aACb,CAAC,CAAC;YAEH,OAAO,YAAY,CAAC;QACtB,CAAC;QAED,mBAAmB;QACnB,QAAQ;QAER,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE;YAC9B,MAAM,aAAa,GAAG,MAAM,YAAY,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;YAEnE,OAAO,aAAa,CAAC,YAAY,CAAC;QACpC,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import localePkg from 'locale';
|
|
2
2
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
3
3
|
import { findLocalizedText, generateDbFilterById, generateDbMutations, generateDbObjectId, } from '@unchainedshop/utils';
|
|
4
4
|
import { ProductVariationsCollection } from '../db/ProductVariationsCollection';
|
|
5
5
|
import { ProductVariationsSchema, ProductVariationType } from '../db/ProductVariationsSchema';
|
|
6
|
+
const { Locale } = localePkg;
|
|
6
7
|
const PRODUCT_VARIATION_EVENTS = [
|
|
7
8
|
'PRODUCT_CREATE_VARIATION',
|
|
8
9
|
'PRODUCT_REMOVE_VARIATION',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureProductVariationsModule.js","sourceRoot":"","sources":["../../src/module/configureProductVariationsModule.ts"],"names":[],"mappings":"AAMA,OAAO,
|
|
1
|
+
{"version":3,"file":"configureProductVariationsModule.js","sourceRoot":"","sources":["../../src/module/configureProductVariationsModule.ts"],"names":[],"mappings":"AAMA,OAAO,SAAS,MAAM,QAAQ,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,2BAA2B,EAAE,MAAM,mCAAmC,CAAC;AAChF,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAE9F,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;AAE7B,MAAM,wBAAwB,GAAG;IAC/B,0BAA0B;IAC1B,0BAA0B;IAC1B,gCAAgC;IAChC,iCAAiC;IACjC,iCAAiC;CAClC,CAAC;AAEF,MAAM,CAAC,MAAM,gCAAgC,GAAG,KAAK,EAAE,EACrD,EAAE,GACiC,EAAoC,EAAE;IACzE,cAAc,CAAC,wBAAwB,CAAC,CAAC;IAEzC,MAAM,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,GAAG,MAAM,2BAA2B,CAAC,EAAE,CAAC,CAAC;IAE3F,MAAM,SAAS,GAAG,mBAAmB,CAAmB,iBAAiB,EAAE,uBAAuB,EAAE;QAClG,0BAA0B,EAAE,IAAI;QAChC,aAAa,EAAE,KAAK;KACrB,CAAsC,CAAC;IAExC,MAAM,mBAAmB,GAAG,KAAK,EAC/B,EACE,kBAAkB,EAClB,2BAA2B,GAAG,IAAI,EAClC,MAAM,EACN,GAAG,IAAI,EACgC,EACzC,MAAc,EACd,EAAE;QACF,MAAM,QAAQ,GAAG;YACf,kBAAkB;YAClB,2BAA2B,EAAE,2BAA2B,IAAI;gBAC1D,GAAG,EAAE,IAAI;aACV;YACD,MAAM;SACP,CAAC;QAEF,MAAM,qB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Z,oBAAoB,EAAE,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,2BAA2B,EAAE,MAAM,EAAE,EAAE;gBAC7F,MAAM,qBAAqB,GAAG,MAAM,OAAO,CAAC,GAAG,CAC7C,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAChC,mBAAmB,CACjB;oBACE,GAAG,IAAI;oBACP,MAAM;oBACN,kBAAkB;oBAClB,2BAA2B;iBAC5B,EACD,MAAM,CACP,CACF,CACF,CAAC;gBAEF,IAAI,CAAC,gCAAgC,EAAE;oBACrC,kBAAkB;oBAClB,2BAA2B;oBAC3B,qBAAqB;iBACtB,CAAC,CAAC;gBAEH,OAAO,qBAAqB,CAAC;YAC/B,CAAC;YAED,mBAAmB,EAAE,KAAK,EACxB,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,EACnD,MAAM,EACN,IAAI,EACJ,MAAM,EACN,EAAE,CACF,mBAAmB,CACjB;gBACE,GAAG,IAAI;gBACP,kBAAkB;gBAClB,2BAA2B;gBAC3B,MAAM;aACP,EACD,MAAM,CACP;SACJ;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-products",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"main": "lib/products-index.js",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./lib/products-index.js",
|
|
7
|
+
"./*": "./lib/*"
|
|
8
|
+
},
|
|
5
9
|
"types": "lib/products-index.d.ts",
|
|
6
10
|
"type": "module",
|
|
7
11
|
"scripts": {
|
|
12
|
+
"prepublishOnly": "npm install && npm run build || :",
|
|
8
13
|
"clean": "rm -rf lib",
|
|
9
|
-
"build": "npm run clean && tsc
|
|
10
|
-
"watch": "tsc
|
|
11
|
-
"
|
|
12
|
-
"test": "cross-env METEOR_PACKAGE_DIRS=../ TEST_CLIENT=0 TEST_WATCH=1 meteor test-packages ./ --driver-package meteortesting:mocha --port 4200"
|
|
14
|
+
"build": "npm run clean && tsc",
|
|
15
|
+
"watch": "tsc -w",
|
|
16
|
+
"test": "jest --watch"
|
|
13
17
|
},
|
|
14
18
|
"repository": {
|
|
15
19
|
"type": "git",
|
|
@@ -27,20 +31,19 @@
|
|
|
27
31
|
},
|
|
28
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
29
33
|
"dependencies": {
|
|
30
|
-
"@unchainedshop/events": "
|
|
31
|
-
"@unchainedshop/file-upload": "
|
|
32
|
-
"@unchainedshop/utils": "
|
|
34
|
+
"@unchainedshop/events": "^1.1.9",
|
|
35
|
+
"@unchainedshop/file-upload": "^1.1.9",
|
|
36
|
+
"@unchainedshop/utils": "^1.1.9",
|
|
33
37
|
"locale": "^0.1.0",
|
|
34
38
|
"lru-cache": "^7.10.2",
|
|
35
39
|
"simpl-schema": "^1.12.2"
|
|
36
40
|
},
|
|
37
41
|
"devDependencies": {
|
|
38
|
-
"@types/chai": "^4.3.1",
|
|
39
42
|
"@types/locale": "^0.1.1",
|
|
40
|
-
"@types/
|
|
41
|
-
"@unchainedshop/types": "
|
|
42
|
-
"
|
|
43
|
-
"
|
|
43
|
+
"@types/node": "^16.11.44",
|
|
44
|
+
"@unchainedshop/types": "^1.1.9",
|
|
45
|
+
"jest": "^28.1.2",
|
|
46
|
+
"ts-jest": "^28.0.5",
|
|
44
47
|
"typescript": "^4.7.4"
|
|
45
48
|
}
|
|
46
49
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ProductMedia, ProductMediaModule, ProductMediaText } from '@unchainedshop/types/products.media';
|
|
2
2
|
import { ModuleInput, ModuleMutations, Query } from '@unchainedshop/types/common';
|
|
3
|
-
import
|
|
3
|
+
import localePkg from 'locale';
|
|
4
4
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
5
5
|
import {
|
|
6
6
|
findLocalizedText,
|
|
@@ -13,6 +13,8 @@ import { ProductsModule } from '@unchainedshop/types/products';
|
|
|
13
13
|
import { ProductMediaCollection } from '../db/ProductMediaCollection';
|
|
14
14
|
import { ProductMediaSchema } from '../db/ProductMediaSchema';
|
|
15
15
|
|
|
16
|
+
const { Locale } = localePkg;
|
|
17
|
+
|
|
16
18
|
const PRODUCT_MEDIA_EVENTS = [
|
|
17
19
|
'PRODUCT_ADD_MEDIA',
|
|
18
20
|
'PRODUCT_REMOVE_MEDIA',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Collection } from '@unchainedshop/types/common';
|
|
2
2
|
import { Product, ProductsModule, ProductText } from '@unchainedshop/types/products';
|
|
3
|
-
import
|
|
3
|
+
import localePkg from 'locale';
|
|
4
4
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
5
5
|
import {
|
|
6
6
|
findLocalizedText,
|
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
} from '@unchainedshop/utils';
|
|
11
11
|
import { productsSettings } from '../products-settings';
|
|
12
12
|
|
|
13
|
+
const { Locale } = localePkg;
|
|
14
|
+
|
|
13
15
|
const PRODUCT_TEXT_EVENTS = ['PRODUCT_UPDATE_TEXTS'];
|
|
14
16
|
|
|
15
17
|
export const configureProductTextsModule = ({
|
|
@@ -147,8 +149,8 @@ export const configureProductTextsModule = ({
|
|
|
147
149
|
updateTexts: async (productId, texts, userId) => {
|
|
148
150
|
const productTexts = texts
|
|
149
151
|
? await Promise.all(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
+
texts.map(({ locale, ...text }) => upsertLocalizedText(productId, locale, text, userId)),
|
|
153
|
+
)
|
|
152
154
|
: [];
|
|
153
155
|
|
|
154
156
|
emit('PRODUCT_UPDATE_TEXTS', {
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
ProductVariationText,
|
|
5
5
|
} from '@unchainedshop/types/products.variations';
|
|
6
6
|
import { ModuleInput, ModuleMutations, Query } from '@unchainedshop/types/common';
|
|
7
|
-
import
|
|
7
|
+
import localePkg from 'locale';
|
|
8
8
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
9
9
|
import {
|
|
10
10
|
findLocalizedText,
|
|
@@ -15,6 +15,8 @@ import {
|
|
|
15
15
|
import { ProductVariationsCollection } from '../db/ProductVariationsCollection';
|
|
16
16
|
import { ProductVariationsSchema, ProductVariationType } from '../db/ProductVariationsSchema';
|
|
17
17
|
|
|
18
|
+
const { Locale } = localePkg;
|
|
19
|
+
|
|
18
20
|
const PRODUCT_VARIATION_EVENTS = [
|
|
19
21
|
'PRODUCT_CREATE_VARIATION',
|
|
20
22
|
'PRODUCT_REMOVE_VARIATION',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assert } from 'chai';
|
|
2
|
-
import { initDb } from '
|
|
3
|
-
import { configureProductsModule } from '
|
|
2
|
+
import { initDb } from '@unchainedshop/mongodb';
|
|
3
|
+
import { configureProductsModule } from '@unchainedshop/core-products';
|
|
4
4
|
import { ProductsModule } from '@unchainedshop/types/products';
|
|
5
5
|
|
|
6
6
|
describe('Test exports', () => {
|
package/tsconfig.json
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "./tsconfig.build.json",
|
|
3
2
|
"compilerOptions": {
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"allowSyntheticDefaultImports": true,
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"lib": [
|
|
10
|
+
"esnext"
|
|
11
|
+
],
|
|
12
|
+
"module": "esnext",
|
|
13
|
+
"moduleResolution": "node",
|
|
14
|
+
"noImplicitReturns": true,
|
|
15
|
+
"noUnusedLocals": false,
|
|
16
|
+
"outDir": "lib",
|
|
17
|
+
"preserveWatchOutput": true,
|
|
18
|
+
"skipLibCheck": true,
|
|
19
|
+
"sourceMap": true,
|
|
20
|
+
"target": "esnext",
|
|
21
|
+
"types": [
|
|
22
|
+
"node",
|
|
23
|
+
"jest"
|
|
24
|
+
]
|
|
6
25
|
},
|
|
7
|
-
"include": [
|
|
8
|
-
|
|
26
|
+
"include": [
|
|
27
|
+
"src"
|
|
28
|
+
]
|
|
29
|
+
}
|
package/.npm/package/README
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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.
|
|
@@ -1,55 +0,0 @@
|
|
|
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
|
-
"clone": {
|
|
10
|
-
"version": "2.1.2",
|
|
11
|
-
"resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz",
|
|
12
|
-
"integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w=="
|
|
13
|
-
},
|
|
14
|
-
"event-target-shim": {
|
|
15
|
-
"version": "5.0.1",
|
|
16
|
-
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
|
|
17
|
-
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ=="
|
|
18
|
-
},
|
|
19
|
-
"lodash._reinterpolate": {
|
|
20
|
-
"version": "3.0.0",
|
|
21
|
-
"resolved": "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz",
|
|
22
|
-
"integrity": "sha512-xYHt68QRoYGjeeM/XOE1uJtvXQAgvszfBhjV4yvsQH0u2i9I6cI6c6/eG4Hh3UAOVn0y/xAXwmTzEay49Q//HA=="
|
|
23
|
-
},
|
|
24
|
-
"lodash.template": {
|
|
25
|
-
"version": "4.5.0",
|
|
26
|
-
"resolved": "https://registry.npmjs.org/lodash.template/-/lodash.template-4.5.0.tgz",
|
|
27
|
-
"integrity": "sha512-84vYFxIkmidUiFxidA/KjjH9pAycqW+h980j7Fuz5qxRtO9pgB7MDFTdys1N7A5mcucRiDyEq4fusljItR1T/A=="
|
|
28
|
-
},
|
|
29
|
-
"lodash.templatesettings": {
|
|
30
|
-
"version": "4.2.0",
|
|
31
|
-
"resolved": "https://registry.npmjs.org/lodash.templatesettings/-/lodash.templatesettings-4.2.0.tgz",
|
|
32
|
-
"integrity": "sha512-stgLz+i3Aa9mZgnjr/O+v9ruKZsPsndy7qPZOchbqk2cnTU1ZaldKK+v7m54WoKIyxiuMZTKT2H81F8BeAc3ZQ=="
|
|
33
|
-
},
|
|
34
|
-
"lru-cache": {
|
|
35
|
-
"version": "7.7.0",
|
|
36
|
-
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.7.0.tgz",
|
|
37
|
-
"integrity": "sha512-3W9Irr9YR2ZHJbfRr/hj8VtzqH7DugwWyHONyDByP6PLS/YJV7GTX5dDYS+qFe/LkVfnCjtk6vkVsxxKGol6jQ=="
|
|
38
|
-
},
|
|
39
|
-
"message-box": {
|
|
40
|
-
"version": "0.2.7",
|
|
41
|
-
"resolved": "https://registry.npmjs.org/message-box/-/message-box-0.2.7.tgz",
|
|
42
|
-
"integrity": "sha512-C4ccA5nHb58kTS+pLrgF/JWtr7fAIkHxRDceH7tdy5fMA783nUfbYwZ7H2XLvSeYfcnWIYCig5dWW+icK9X/Ag=="
|
|
43
|
-
},
|
|
44
|
-
"mongo-object": {
|
|
45
|
-
"version": "0.1.4",
|
|
46
|
-
"resolved": "https://registry.npmjs.org/mongo-object/-/mongo-object-0.1.4.tgz",
|
|
47
|
-
"integrity": "sha512-QtYk0gupWEn2+iB+DDRt1L+WbcNYvJRaHdih/dcqthOa1DbnREUGSs2WGcW478GNYpElflo/yybZXu0sTiRXHg=="
|
|
48
|
-
},
|
|
49
|
-
"simpl-schema": {
|
|
50
|
-
"version": "1.12.0",
|
|
51
|
-
"resolved": "https://registry.npmjs.org/simpl-schema/-/simpl-schema-1.12.0.tgz",
|
|
52
|
-
"integrity": "sha512-lzXC3L8jJbPhNXGR3cjlyIauqqrC5WUJS4O34Ym/wLIvb8K3ZieK+1OfTzs4mBpDc3Y8u53gQFAr1X37DmTcEg=="
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
package/.versions
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
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-products@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-products@1.1.1
|
|
50
|
-
unchained:mongodb@1.0.0
|
|
51
|
-
underscore@1.0.10
|
|
52
|
-
webapp@1.13.1
|
|
53
|
-
webapp-hashing@1.1.0
|
package/package.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
Package.describe({
|
|
2
|
-
name: 'unchained:core-products',
|
|
3
|
-
version: '1.1.3',
|
|
4
|
-
summary: 'Unchained Engine Core: Products',
|
|
5
|
-
git: 'https://github.com/unchainedshop/unchained',
|
|
6
|
-
documentation: 'README.md',
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
Npm.depends({
|
|
10
|
-
'lru-cache': '7.7.0',
|
|
11
|
-
'abort-controller': '3.0.0',
|
|
12
|
-
'simpl-schema': '1.12.0',
|
|
13
|
-
'@unchainedshop/utils': '1.1.3',
|
|
14
|
-
// '@unchainedshop/events': '1.1.4', // PEER!
|
|
15
|
-
// '@unchainedshop/file-upload': '1.1.4', // PEER!
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
Package.onUse((api) => {
|
|
19
|
-
api.versionsFrom('2.7.3');
|
|
20
|
-
api.use('ecmascript');
|
|
21
|
-
api.use('typescript');
|
|
22
|
-
|
|
23
|
-
api.mainModule('src/products-index.ts', 'server');
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
Package.onTest((api) => {
|
|
27
|
-
api.use('meteortesting:mocha');
|
|
28
|
-
api.use('ecmascript');
|
|
29
|
-
api.use('typescript');
|
|
30
|
-
|
|
31
|
-
api.use('unchained:mongodb');
|
|
32
|
-
api.use('unchained:core-products');
|
|
33
|
-
|
|
34
|
-
api.mainModule('tests/products-index.test.ts');
|
|
35
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { IProductPricingAdapter } from '@unchainedshop/types/products.pricing';
|
|
2
|
-
import { ProductPricingDirector, ProductPricingAdapter } from 'meteor/unchained:core-products';
|
|
3
|
-
|
|
4
|
-
const ProductPrice: IProductPricingAdapter = {
|
|
5
|
-
...ProductPricingAdapter,
|
|
6
|
-
|
|
7
|
-
key: 'shop.unchained.pricing.product-price',
|
|
8
|
-
version: '1.0',
|
|
9
|
-
label: 'Add Gross Price to Product',
|
|
10
|
-
orderIndex: 0,
|
|
11
|
-
|
|
12
|
-
isActivatedFor: () => {
|
|
13
|
-
return true;
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
actions: (params) => {
|
|
17
|
-
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
...pricingAdapter,
|
|
21
|
-
|
|
22
|
-
calculate: async () => {
|
|
23
|
-
const {
|
|
24
|
-
product,
|
|
25
|
-
country,
|
|
26
|
-
currency: forcedCurrency,
|
|
27
|
-
quantity,
|
|
28
|
-
modules,
|
|
29
|
-
services,
|
|
30
|
-
} = params.context;
|
|
31
|
-
const currency =
|
|
32
|
-
forcedCurrency ||
|
|
33
|
-
(await services.countries.resolveDefaultCurrencyCode(
|
|
34
|
-
{
|
|
35
|
-
isoCode: country,
|
|
36
|
-
},
|
|
37
|
-
params.context,
|
|
38
|
-
));
|
|
39
|
-
const price = await modules.products.prices.price(product, { country, currency, quantity });
|
|
40
|
-
if (price) {
|
|
41
|
-
const itemTotal = price.amount * quantity;
|
|
42
|
-
pricingAdapter.resultSheet().addItem({
|
|
43
|
-
amount: itemTotal,
|
|
44
|
-
isTaxable: price.isTaxable,
|
|
45
|
-
isNetPrice: price.isNetPrice,
|
|
46
|
-
meta: { adapter: ProductPrice.key },
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return pricingAdapter.calculate();
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
ProductPricingDirector.registerAdapter(ProductPrice);
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Discount, DiscountConfiguration } from '@unchainedshop/types/orders.discounts';
|
|
2
|
-
import {
|
|
3
|
-
IProductPricingAdapter,
|
|
4
|
-
ProductPricingRowCategory,
|
|
5
|
-
} from '@unchainedshop/types/products.pricing';
|
|
6
|
-
import { ProductPricingDirector, ProductPricingAdapter } from 'meteor/unchained:core-products';
|
|
7
|
-
|
|
8
|
-
const applyRate = (configuration: DiscountConfiguration, amount) => {
|
|
9
|
-
const { rate, fixedRate } = configuration;
|
|
10
|
-
return rate ? amount * rate : Math.min(fixedRate, amount);
|
|
11
|
-
};
|
|
12
|
-
const ProductDiscount: IProductPricingAdapter = {
|
|
13
|
-
...ProductPricingAdapter,
|
|
14
|
-
|
|
15
|
-
key: 'shop.unchained.pricing.product-discount',
|
|
16
|
-
version: '1.0',
|
|
17
|
-
label: 'Apply Discounts on Product Price',
|
|
18
|
-
orderIndex: 10,
|
|
19
|
-
|
|
20
|
-
isActivatedFor: () => {
|
|
21
|
-
return true;
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
actions: (params) => {
|
|
25
|
-
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
26
|
-
|
|
27
|
-
const addDiscount = (discount: Discount, total: number, isTaxable: boolean) => {
|
|
28
|
-
const { configuration, discountId } = discount;
|
|
29
|
-
const { isNetPrice = false, ...meta } = configuration;
|
|
30
|
-
const amount = applyRate(configuration, total);
|
|
31
|
-
|
|
32
|
-
pricingAdapter.resultSheet().addDiscount({
|
|
33
|
-
amount: amount * -1,
|
|
34
|
-
discountId,
|
|
35
|
-
isNetPrice,
|
|
36
|
-
isTaxable,
|
|
37
|
-
meta: { adapter: ProductDiscount.key, ...meta },
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
...pricingAdapter,
|
|
43
|
-
|
|
44
|
-
calculate: async () => {
|
|
45
|
-
const taxableTotal = params.calculationSheet.sum({
|
|
46
|
-
category: ProductPricingRowCategory.Item,
|
|
47
|
-
isTaxable: true,
|
|
48
|
-
});
|
|
49
|
-
const nonTaxableTotal = params.calculationSheet.sum({
|
|
50
|
-
category: ProductPricingRowCategory.Item,
|
|
51
|
-
isTaxable: false,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
params.discounts.forEach((discount) => {
|
|
55
|
-
if (taxableTotal !== 0) {
|
|
56
|
-
addDiscount(discount, taxableTotal, true);
|
|
57
|
-
}
|
|
58
|
-
if (nonTaxableTotal !== 0) {
|
|
59
|
-
addDiscount(discount, nonTaxableTotal, false);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
return pricingAdapter.calculate();
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
ProductPricingDirector.registerAdapter(ProductDiscount);
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { IProductPricingAdapter } from '@unchainedshop/types/products.pricing';
|
|
2
|
-
import fetch from 'isomorphic-unfetch';
|
|
3
|
-
import { ProductPricingDirector, ProductPricingAdapter } from 'meteor/unchained:core-products';
|
|
4
|
-
|
|
5
|
-
import Cache from './utils/cache';
|
|
6
|
-
|
|
7
|
-
const CACHE_PERIOD = 60 * 60 * 24; // 1 day
|
|
8
|
-
|
|
9
|
-
const SUPPORTED_CURRENCIES = [
|
|
10
|
-
'USD',
|
|
11
|
-
'JPY',
|
|
12
|
-
'BGN',
|
|
13
|
-
'CZK',
|
|
14
|
-
'DKK',
|
|
15
|
-
'GBP',
|
|
16
|
-
'HUF',
|
|
17
|
-
'PLN',
|
|
18
|
-
'RON',
|
|
19
|
-
'SEK',
|
|
20
|
-
'CHF',
|
|
21
|
-
'ISK',
|
|
22
|
-
'NOK',
|
|
23
|
-
'HRK',
|
|
24
|
-
'RUB',
|
|
25
|
-
'TRY',
|
|
26
|
-
'AUD',
|
|
27
|
-
'BRL',
|
|
28
|
-
'CAD',
|
|
29
|
-
'CNY',
|
|
30
|
-
'HKD',
|
|
31
|
-
'IDR',
|
|
32
|
-
'ILS',
|
|
33
|
-
'INR',
|
|
34
|
-
'KRW',
|
|
35
|
-
'MXN',
|
|
36
|
-
'MYR',
|
|
37
|
-
'NZD',
|
|
38
|
-
'PHP',
|
|
39
|
-
'SGD',
|
|
40
|
-
'THB',
|
|
41
|
-
'ZAR',
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
const cache = new Cache(CACHE_PERIOD);
|
|
45
|
-
const xmlJs = require('xml-js'); // eslint-disable-line
|
|
46
|
-
|
|
47
|
-
const getEURexchangeRateForCurrency = async (currency) => {
|
|
48
|
-
const response = cache.get(currency, () =>
|
|
49
|
-
fetch(`https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml`, {
|
|
50
|
-
method: 'GET',
|
|
51
|
-
})
|
|
52
|
-
.then((res) => res.text())
|
|
53
|
-
.then((text) => JSON.parse(xmlJs.xml2json(text)))
|
|
54
|
-
.then(
|
|
55
|
-
(json) =>
|
|
56
|
-
json.elements?.[0]?.elements
|
|
57
|
-
.filter((e) => e.name.toLowerCase() === 'cube')[0]
|
|
58
|
-
?.elements[0]?.elements.filter((a) => a.attributes.currency === currency)?.[0]?.attributes,
|
|
59
|
-
),
|
|
60
|
-
);
|
|
61
|
-
return response;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const ProductPriceECBIntraBankExchange: IProductPricingAdapter = {
|
|
65
|
-
...ProductPricingAdapter,
|
|
66
|
-
|
|
67
|
-
key: 'shop.unchained.pricing.price-ECB-intrabank-exchange',
|
|
68
|
-
version: '1.0',
|
|
69
|
-
label: 'Convert EUR to X with current exchange rate',
|
|
70
|
-
orderIndex: 1,
|
|
71
|
-
|
|
72
|
-
isActivatedFor: (context) => {
|
|
73
|
-
return SUPPORTED_CURRENCIES.indexOf(context.currency) !== -1;
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
actions: (params) => {
|
|
77
|
-
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
...pricingAdapter,
|
|
81
|
-
|
|
82
|
-
calculate: async () => {
|
|
83
|
-
const { product, country, quantity, currency, modules } = params.context;
|
|
84
|
-
const { calculation = [] } = params.calculationSheet;
|
|
85
|
-
const EURprice = await modules.products.prices.price(product, {
|
|
86
|
-
country,
|
|
87
|
-
currency: 'EUR',
|
|
88
|
-
quantity,
|
|
89
|
-
});
|
|
90
|
-
if (!EURprice || !EURprice?.amount || calculation?.length) return pricingAdapter.calculate();
|
|
91
|
-
|
|
92
|
-
const exchange = await getEURexchangeRateForCurrency(currency);
|
|
93
|
-
const convertedAmount = EURprice.amount * exchange.rate;
|
|
94
|
-
pricingAdapter.resultSheet().resetCalculation(params.calculationSheet);
|
|
95
|
-
pricingAdapter.resultSheet().addItem({
|
|
96
|
-
amount: convertedAmount * quantity,
|
|
97
|
-
isTaxable: EURprice.isTaxable,
|
|
98
|
-
isNetPrice: EURprice.isNetPrice,
|
|
99
|
-
meta: { adapter: ProductPriceECBIntraBankExchange.key },
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
return pricingAdapter.calculate();
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
ProductPricingDirector.registerAdapter(ProductPriceECBIntraBankExchange);
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { IProductPricingAdapter } from '@unchainedshop/types/products.pricing';
|
|
2
|
-
import fetch from 'isomorphic-unfetch';
|
|
3
|
-
import { ProductPricingDirector, ProductPricingAdapter } from 'meteor/unchained:core-products';
|
|
4
|
-
|
|
5
|
-
import Cache from './utils/cache';
|
|
6
|
-
|
|
7
|
-
const CACHE_PERIOD = 60 * 60 * 0.1; // 10 minutes
|
|
8
|
-
const SUPPORTED_CURRENCIES = ['BTC', 'ETH', 'XRP', 'USDT', 'BCH', 'BSV', 'LTC', 'EOS', 'BNB', 'XTZ'];
|
|
9
|
-
const cache = new Cache(CACHE_PERIOD);
|
|
10
|
-
|
|
11
|
-
const getFiatexchangeRateForCrypto = async (base, target) => {
|
|
12
|
-
const { data } = await cache.get(`${base}-${target}`, () =>
|
|
13
|
-
fetch(`https://api.coinbase.com/v2/exchange-rates?currency=${base}`, {
|
|
14
|
-
method: 'GET',
|
|
15
|
-
}).then((res) => res.json()),
|
|
16
|
-
);
|
|
17
|
-
return data?.rates?.[target];
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const ProductPriceCoinbaseExchange: IProductPricingAdapter = {
|
|
21
|
-
...ProductPricingAdapter,
|
|
22
|
-
|
|
23
|
-
key: 'shop.unchained.pricing.price-coinbase-exchange',
|
|
24
|
-
version: '1.0',
|
|
25
|
-
label: 'Convert fiat/crypto to crypto with current exchange rate',
|
|
26
|
-
orderIndex: 1,
|
|
27
|
-
|
|
28
|
-
isActivatedFor: (context) => {
|
|
29
|
-
return SUPPORTED_CURRENCIES.indexOf(context.currency.toUpperCase()) !== -1;
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
actions: (params) => {
|
|
33
|
-
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
34
|
-
const { services, modules } = params.context;
|
|
35
|
-
return {
|
|
36
|
-
...pricingAdapter,
|
|
37
|
-
|
|
38
|
-
calculate: async () => {
|
|
39
|
-
const { product, country, quantity, currency } = params.context;
|
|
40
|
-
const defaultCurrency = await services.countries.resolveDefaultCurrencyCode(
|
|
41
|
-
{
|
|
42
|
-
isoCode: country,
|
|
43
|
-
},
|
|
44
|
-
params.context,
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const productPrice = await modules.products.prices.price(product, {
|
|
48
|
-
country,
|
|
49
|
-
currency: defaultCurrency,
|
|
50
|
-
quantity,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const { calculation = [] } = params.calculationSheet;
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
!productPrice ||
|
|
57
|
-
!productPrice?.amount ||
|
|
58
|
-
calculation?.length ||
|
|
59
|
-
defaultCurrency === currency
|
|
60
|
-
)
|
|
61
|
-
return pricingAdapter.calculate();
|
|
62
|
-
|
|
63
|
-
const rate = await getFiatexchangeRateForCrypto(defaultCurrency, currency);
|
|
64
|
-
|
|
65
|
-
if (rate > 0) {
|
|
66
|
-
const convertedAmount = productPrice.amount * rate;
|
|
67
|
-
pricingAdapter.resultSheet().resetCalculation(params.calculationSheet);
|
|
68
|
-
pricingAdapter.resultSheet().addItem({
|
|
69
|
-
amount: convertedAmount * quantity,
|
|
70
|
-
isTaxable: productPrice?.isTaxable,
|
|
71
|
-
isNetPrice: productPrice?.isNetPrice,
|
|
72
|
-
meta: { adapter: ProductPriceCoinbaseExchange.key },
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return pricingAdapter.calculate();
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
ProductPricingDirector.registerAdapter(ProductPriceCoinbaseExchange);
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Context } from '@unchainedshop/types/api';
|
|
2
|
-
import { ProductPriceRate } from '@unchainedshop/types/products.pricing';
|
|
3
|
-
import bodyParser from 'body-parser';
|
|
4
|
-
import { useMiddlewareWithCurrentContext } from 'meteor/unchained:api';
|
|
5
|
-
|
|
6
|
-
const { CRYPTOPAY_SECRET, CRYPTOPAY_PRICING_WEBHOOK_PATH = '/graphql/cryptopay-pricing' } = process.env;
|
|
7
|
-
|
|
8
|
-
useMiddlewareWithCurrentContext(CRYPTOPAY_PRICING_WEBHOOK_PATH, bodyParser.json());
|
|
9
|
-
|
|
10
|
-
useMiddlewareWithCurrentContext(CRYPTOPAY_PRICING_WEBHOOK_PATH, async (request, response) => {
|
|
11
|
-
const resolvedContext = request.unchainedContext as Context;
|
|
12
|
-
const { baseCurrency, token, rate, timestamp, secret } = request.body;
|
|
13
|
-
if (secret !== CRYPTOPAY_SECRET) {
|
|
14
|
-
response.end(JSON.stringify({ success: false }));
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const rateData: ProductPriceRate = {
|
|
18
|
-
baseCurrency,
|
|
19
|
-
quoteCurrency: token,
|
|
20
|
-
rate,
|
|
21
|
-
timestamp,
|
|
22
|
-
};
|
|
23
|
-
const success = await resolvedContext.modules.products.prices.rates.updateRate(rateData);
|
|
24
|
-
response.end(JSON.stringify({ success }));
|
|
25
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { IProductPricingAdapter } from '@unchainedshop/types/products.pricing';
|
|
2
|
-
import { ProductPricingDirector, ProductPricingAdapter } from 'meteor/unchained:core-products';
|
|
3
|
-
|
|
4
|
-
const { RATECONVERSION_MAX_AGE = '360' } = process.env;
|
|
5
|
-
|
|
6
|
-
const MAX_RATE_AGE = parseInt(RATECONVERSION_MAX_AGE, 10);
|
|
7
|
-
|
|
8
|
-
const ProductPriceRateConversion: IProductPricingAdapter = {
|
|
9
|
-
...ProductPricingAdapter,
|
|
10
|
-
|
|
11
|
-
key: 'shop.unchained.pricing.rate-conversion',
|
|
12
|
-
version: '1.0',
|
|
13
|
-
label: 'Generic rate conversion plugin that converts between rates if entry in DB exists.',
|
|
14
|
-
orderIndex: 1,
|
|
15
|
-
|
|
16
|
-
isActivatedFor: () => {
|
|
17
|
-
return true;
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
actions: (params) => {
|
|
21
|
-
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
22
|
-
const { services, modules } = params.context;
|
|
23
|
-
return {
|
|
24
|
-
...pricingAdapter,
|
|
25
|
-
|
|
26
|
-
calculate: async () => {
|
|
27
|
-
const { product, country, quantity, currency } = params.context;
|
|
28
|
-
const defaultCurrency = await services.countries.resolveDefaultCurrencyCode(
|
|
29
|
-
{
|
|
30
|
-
isoCode: country,
|
|
31
|
-
},
|
|
32
|
-
params.context,
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const productPrice = await modules.products.prices.price(product, {
|
|
36
|
-
country,
|
|
37
|
-
currency: defaultCurrency,
|
|
38
|
-
quantity,
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const { calculation = [] } = params.calculationSheet;
|
|
42
|
-
if (
|
|
43
|
-
!productPrice ||
|
|
44
|
-
!productPrice?.amount ||
|
|
45
|
-
calculation?.length ||
|
|
46
|
-
defaultCurrency === currency
|
|
47
|
-
)
|
|
48
|
-
return pricingAdapter.calculate();
|
|
49
|
-
|
|
50
|
-
const rate = await modules.products.prices.rates.getRate(
|
|
51
|
-
defaultCurrency,
|
|
52
|
-
currency,
|
|
53
|
-
MAX_RATE_AGE,
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
if (rate > 0) {
|
|
57
|
-
const convertedAmount = productPrice.amount * rate;
|
|
58
|
-
pricingAdapter.resultSheet().resetCalculation(params.calculationSheet);
|
|
59
|
-
pricingAdapter.resultSheet().addItem({
|
|
60
|
-
amount: convertedAmount * quantity,
|
|
61
|
-
isTaxable: productPrice?.isTaxable,
|
|
62
|
-
isNetPrice: productPrice?.isNetPrice,
|
|
63
|
-
meta: { adapter: ProductPriceRateConversion.key },
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return pricingAdapter.calculate();
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
ProductPricingDirector.registerAdapter(ProductPriceRateConversion);
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { IProductPricingAdapter } from '@unchainedshop/types/products.pricing';
|
|
2
|
-
import { ProductPricingAdapter } from 'meteor/unchained:core-products';
|
|
3
|
-
|
|
4
|
-
const roundToNext = (value, precision) =>
|
|
5
|
-
value % precision === precision / 2
|
|
6
|
-
? value + precision / 2
|
|
7
|
-
: value + (precision - (value % precision));
|
|
8
|
-
|
|
9
|
-
// String is referencing to a currency
|
|
10
|
-
interface PriceRoundSettings {
|
|
11
|
-
configurations: Record<string, number>;
|
|
12
|
-
defaultPrecision: number;
|
|
13
|
-
skip: Array<string>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const ProductPriceRoundSettings: PriceRoundSettings = {
|
|
17
|
-
configurations: {},
|
|
18
|
-
defaultPrecision: 50,
|
|
19
|
-
skip: [],
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const configureProductPriceRounding = ({
|
|
23
|
-
configurations,
|
|
24
|
-
defaultPrecision,
|
|
25
|
-
skip,
|
|
26
|
-
}: PriceRoundSettings) => {
|
|
27
|
-
if (defaultPrecision) ProductPriceRoundSettings.defaultPrecision = defaultPrecision;
|
|
28
|
-
if (configurations) ProductPriceRoundSettings.configurations = configurations;
|
|
29
|
-
if (skip?.length) ProductPriceRoundSettings.skip = skip;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const ProductPriceRound: IProductPricingAdapter & {
|
|
33
|
-
configure: (params: PriceRoundSettings) => void;
|
|
34
|
-
} = {
|
|
35
|
-
...ProductPricingAdapter,
|
|
36
|
-
|
|
37
|
-
key: 'shop.unchained.pricing.price-round',
|
|
38
|
-
version: '1.0',
|
|
39
|
-
label: 'Round product price to the next precision number',
|
|
40
|
-
orderIndex: 2,
|
|
41
|
-
|
|
42
|
-
isActivatedFor: () => {
|
|
43
|
-
return true;
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
configure: configureProductPriceRounding,
|
|
47
|
-
|
|
48
|
-
actions: (params) => {
|
|
49
|
-
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
...pricingAdapter,
|
|
53
|
-
|
|
54
|
-
calculate: async () => {
|
|
55
|
-
const { currency, quantity } = params.context;
|
|
56
|
-
const { configurations, skip, defaultPrecision } = ProductPriceRoundSettings;
|
|
57
|
-
const { calculation = [] } = params.calculationSheet;
|
|
58
|
-
|
|
59
|
-
if (skip?.indexOf(currency) !== -1) return pricingAdapter.calculate();
|
|
60
|
-
|
|
61
|
-
const roundPrecision = configurations?.[currency] || defaultPrecision;
|
|
62
|
-
|
|
63
|
-
if (calculation?.length && roundPrecision) {
|
|
64
|
-
const [productPrice] = calculation;
|
|
65
|
-
pricingAdapter.resultSheet().resetCalculation(params.calculationSheet);
|
|
66
|
-
pricingAdapter.resultSheet().addItem({
|
|
67
|
-
amount: roundToNext(productPrice.amount, roundPrecision) * quantity,
|
|
68
|
-
isTaxable: productPrice.isTaxable,
|
|
69
|
-
isNetPrice: productPrice.isNetPrice,
|
|
70
|
-
meta: { adapter: ProductPriceRound.key },
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return pricingAdapter.calculate();
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
},
|
|
78
|
-
};
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import moment from 'moment';
|
|
2
|
-
import { ProductPricingDirector, ProductPricingAdapter } from 'meteor/unchained:core-products';
|
|
3
|
-
import {
|
|
4
|
-
IProductPricingAdapter,
|
|
5
|
-
ProductPricingAdapterContext,
|
|
6
|
-
} from '@unchainedshop/types/products.pricing';
|
|
7
|
-
|
|
8
|
-
// https://www.ch.ch/de/mehrwertsteuersatz-schweiz/
|
|
9
|
-
export const SwissTaxCategories = {
|
|
10
|
-
DEFAULT: {
|
|
11
|
-
rate: (date) => {
|
|
12
|
-
const referenceDate = moment(date);
|
|
13
|
-
if (referenceDate.isBefore('2018-01-01')) {
|
|
14
|
-
return 0.08;
|
|
15
|
-
}
|
|
16
|
-
return 0.077;
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
REDUCED: {
|
|
20
|
-
tag: 'swiss-tax-category:reduced',
|
|
21
|
-
rate: () => {
|
|
22
|
-
return 0.025;
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
SPECIAL: {
|
|
26
|
-
tag: 'swiss-tax-category:special',
|
|
27
|
-
rate: () => {
|
|
28
|
-
return 0.037;
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const getTaxRate = (context: ProductPricingAdapterContext) => {
|
|
34
|
-
const date = context.order && context.order.ordered ? new Date(context.order.ordered) : new Date();
|
|
35
|
-
const { product } = context;
|
|
36
|
-
|
|
37
|
-
if (product.tags?.includes(SwissTaxCategories.REDUCED.tag)) {
|
|
38
|
-
return SwissTaxCategories.REDUCED.rate();
|
|
39
|
-
}
|
|
40
|
-
if (product.tags?.includes(SwissTaxCategories.SPECIAL.tag)) {
|
|
41
|
-
return SwissTaxCategories.SPECIAL.rate();
|
|
42
|
-
}
|
|
43
|
-
return SwissTaxCategories.DEFAULT.rate(date);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const isDeliveryAddressInSwitzerland = async ({ order, country, modules }) => {
|
|
47
|
-
let countryCode = country?.toUpperCase().trim();
|
|
48
|
-
|
|
49
|
-
if (order) {
|
|
50
|
-
const orderDelivery = await modules.orders.deliveries.findDelivery({
|
|
51
|
-
orderDeliveryId: order.deliveryId,
|
|
52
|
-
});
|
|
53
|
-
const address = orderDelivery?.context?.address || order.billingAddress;
|
|
54
|
-
|
|
55
|
-
if (address?.countryCode > '') {
|
|
56
|
-
countryCode = address.countryCode?.toUpperCase().trim();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return countryCode === 'CH' || countryCode === 'LI';
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const ProductSwissTax: IProductPricingAdapter = {
|
|
64
|
-
...ProductPricingAdapter,
|
|
65
|
-
|
|
66
|
-
key: 'shop.unchained.pricing.product-swiss-tax',
|
|
67
|
-
version: '1.0',
|
|
68
|
-
label: 'Apply Swiss Tax on Product',
|
|
69
|
-
orderIndex: 20,
|
|
70
|
-
|
|
71
|
-
isActivatedFor: () => {
|
|
72
|
-
return true;
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
actions: (params) => {
|
|
76
|
-
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
77
|
-
const { context } = params;
|
|
78
|
-
return {
|
|
79
|
-
...pricingAdapter,
|
|
80
|
-
|
|
81
|
-
calculate: async () => {
|
|
82
|
-
if (!(await isDeliveryAddressInSwitzerland(context))) {
|
|
83
|
-
return pricingAdapter.calculate();
|
|
84
|
-
}
|
|
85
|
-
const taxRate = getTaxRate(context);
|
|
86
|
-
ProductPricingAdapter.log(`ProductSwissTax -> Tax Multiplicator: ${taxRate}`);
|
|
87
|
-
params.calculationSheet.filterBy({ isTaxable: true }).forEach(({ isNetPrice, ...row }) => {
|
|
88
|
-
if (!isNetPrice) {
|
|
89
|
-
const taxAmount = row.amount - row.amount / (1 + taxRate);
|
|
90
|
-
pricingAdapter.resultSheet().calculation.push({
|
|
91
|
-
...row,
|
|
92
|
-
amount: -taxAmount,
|
|
93
|
-
isTaxable: false,
|
|
94
|
-
isNetPrice: false,
|
|
95
|
-
meta: { adapter: ProductSwissTax.key },
|
|
96
|
-
});
|
|
97
|
-
pricingAdapter.resultSheet().addTax({
|
|
98
|
-
amount: taxAmount,
|
|
99
|
-
rate: taxRate,
|
|
100
|
-
meta: { adapter: ProductSwissTax.key },
|
|
101
|
-
});
|
|
102
|
-
} else {
|
|
103
|
-
const taxAmount = row.amount * taxRate;
|
|
104
|
-
pricingAdapter.resultSheet().addTax({
|
|
105
|
-
amount: taxAmount,
|
|
106
|
-
rate: taxRate,
|
|
107
|
-
meta: { adapter: ProductSwissTax.key },
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
return pricingAdapter.calculate();
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
ProductPricingDirector.registerAdapter(ProductSwissTax);
|
package/plugins/utils/cache.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import 'abort-controller/polyfill';
|
|
2
|
-
import LRUCache from 'lru-cache';
|
|
3
|
-
|
|
4
|
-
class Cache {
|
|
5
|
-
constructor(ttlSeconds = 60) {
|
|
6
|
-
this.cache = new LRUCache({
|
|
7
|
-
max: 500,
|
|
8
|
-
ttl: ttlSeconds * 1000,
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
get(key, currentFuntion) {
|
|
13
|
-
const value = this.cache.get(key);
|
|
14
|
-
if (value) {
|
|
15
|
-
return Promise.resolve(value);
|
|
16
|
-
}
|
|
17
|
-
return currentFuntion().then((result) => {
|
|
18
|
-
this.cache.set(key, result);
|
|
19
|
-
return result;
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
del(keys) {
|
|
24
|
-
this.cache.del(keys);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
flushAll() {
|
|
28
|
-
this.cache.reset();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export default Cache;
|
package/tsconfig.build.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
}
|