@unchainedshop/plugins 2.0.0-beta1 → 2.0.0-beta3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/pricing/product-price-round.js +1 -3
- package/lib/pricing/product-price-round.js.map +1 -1
- package/lib/worker/export-token.d.ts +1 -0
- package/lib/worker/export-token.js +1 -0
- package/lib/worker/export-token.js.map +1 -1
- package/lib/worker/update-token-ownership.d.ts +6 -0
- package/lib/worker/update-token-ownership.js +69 -0
- package/lib/worker/update-token-ownership.js.map +1 -0
- package/package.json +19 -19
- package/src/pricing/product-price-round.ts +1 -4
- package/src/worker/export-token.ts +2 -0
- package/src/worker/update-token-ownership.ts +89 -0
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { ProductPricingDirector, ProductPricingAdapter } from '@unchainedshop/core-products';
|
|
2
|
-
const roundToNext = (value, precision) => value
|
|
3
|
-
? value + precision / 2
|
|
4
|
-
: value + (precision - (value % precision));
|
|
2
|
+
const roundToNext = (value, precision) => Math.ceil(value / precision) * precision;
|
|
5
3
|
const ProductPriceRoundSettings = {
|
|
6
4
|
configurations: {},
|
|
7
5
|
defaultPrecision: 50,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-price-round.js","sourceRoot":"","sources":["../../src/pricing/product-price-round.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAE7F,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"product-price-round.js","sourceRoot":"","sources":["../../src/pricing/product-price-round.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAE7F,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,SAA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CAAC;gBAEtE,MAAM,cAAc,GAAG,cAAc,EAAE,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC;gBAEtE,IAAI,WAAW,EAAE,MAAM,IAAI,cAAc,EAAE;oBACzC,MAAM,CAAC,YAAY,CAAC,GAAG,WAAW,CAAC;oBACnC,cAAc,CAAC,WAAW,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;oBACvE,cAAc,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC;wBACnC,MAAM,EAAE,WAAW,CAAC,YAAY,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,QAAQ;wBACnE,SAAS,EAAE,YAAY,CAAC,SAAS;wBACjC,UAAU,EAAE,YAAY,CAAC,UAAU;wBACnC,IAAI,EAAE,EAAE,OAAO,EAAE,iBAAiB,CAAC,GAAG,EAAE;qBACzC,CAAC,CAAC;iBACJ;gBAED,OAAO,cAAc,CAAC,SAAS,EAAE,CAAC;YACpC,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,sBAAsB,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC"}
|
|
@@ -2,3 +2,4 @@ import { IWorkerAdapter } from '@unchainedshop/types/worker';
|
|
|
2
2
|
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
3
3
|
export declare const ExportTokenWorker: IWorkerAdapter<void, void>;
|
|
4
4
|
export declare const configureExportToken: (unchainedApi: UnchainedCore) => void;
|
|
5
|
+
export default configureExportToken;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export-token.js","sourceRoot":"","sources":["../../src/worker/export-token.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAG7F,MAAM,CAAC,MAAM,iBAAiB,GAA+B;IAC3D,GAAG,aAAa;IAEhB,GAAG,EAAE,2CAA2C;IAChD,KAAK,EAAE,2EAA2E;IAClF,OAAO,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AAc,CAAC,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QACrE,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,IAAI,IAAI,CAAC,OAAO,EAAE;YAChD,MAAM,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,oBAAoB,CAAC;gBAC1D,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG;gBAC7B,MAAM,EAAE,IAAI;gBACZ,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,sBAAsB;aACjD,CAAC,CAAC;SACJ;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,eAAe,oBAAoB,CAAC;AAEpC,cAAc,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IWorkerAdapter } from '@unchainedshop/types/worker';
|
|
2
|
+
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
3
|
+
export declare const UpdateTokenOwnership: IWorkerAdapter<void, void>;
|
|
4
|
+
export declare const RefreshTokens: IWorkerAdapter<void, any>;
|
|
5
|
+
export declare const configureUpdateTokenOwnership: (unchainedApi: UnchainedCore) => void;
|
|
6
|
+
export default configureUpdateTokenOwnership;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { WorkerDirector, WorkerAdapter, WorkerEventTypes } from '@unchainedshop/core-worker';
|
|
2
|
+
import later from '@breejs/later';
|
|
3
|
+
const everyMinute = later.parse.cron('* * * * *');
|
|
4
|
+
export const UpdateTokenOwnership = {
|
|
5
|
+
...WorkerAdapter,
|
|
6
|
+
key: 'shop.unchained.worker-plugin.update-token-ownership',
|
|
7
|
+
label: 'External worker to update ownership of provided tokens',
|
|
8
|
+
version: '1.0',
|
|
9
|
+
type: 'UPDATE_TOKEN_OWNERSHIP',
|
|
10
|
+
external: true,
|
|
11
|
+
async doWork() {
|
|
12
|
+
throw new Error('Cannot do work for external workers');
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
export const RefreshTokens = {
|
|
16
|
+
...WorkerAdapter,
|
|
17
|
+
key: 'shop.unchained.worker-plugin.refresh-tokens',
|
|
18
|
+
label: 'Worker to refresh tokens for accounts',
|
|
19
|
+
version: '1.0',
|
|
20
|
+
type: 'REFRESH_TOKENS',
|
|
21
|
+
external: false,
|
|
22
|
+
async doWork(input, requestContext) {
|
|
23
|
+
const { modules } = requestContext;
|
|
24
|
+
const tokens = await modules.warehousing.findTokens({});
|
|
25
|
+
const users = await modules.users.findUsers({ includeGuests: true });
|
|
26
|
+
const accounts = users.flatMap((user) => {
|
|
27
|
+
return user?.services?.web3?.flatMap((service) => {
|
|
28
|
+
if (service.verified)
|
|
29
|
+
return [service.address];
|
|
30
|
+
return [];
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
tokens.forEach((token) => {
|
|
34
|
+
accounts.push(token.walletAddress);
|
|
35
|
+
});
|
|
36
|
+
if (!tokens?.length) {
|
|
37
|
+
return { success: true, result: {} };
|
|
38
|
+
}
|
|
39
|
+
const forked = await modules.worker.addWork({
|
|
40
|
+
type: 'UPDATE_TOKEN_OWNERSHIP',
|
|
41
|
+
retries: 0,
|
|
42
|
+
input: {
|
|
43
|
+
filter: {
|
|
44
|
+
tokens,
|
|
45
|
+
accounts: [...new Set(accounts)],
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
}, null);
|
|
49
|
+
return { success: true, result: { forked } };
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
export const configureUpdateTokenOwnership = (unchainedApi) => {
|
|
53
|
+
WorkerDirector.events.on(WorkerEventTypes.FINISHED, async ({ work }) => {
|
|
54
|
+
if (work.type === 'UPDATE_TOKEN_OWNERSHIP' && work.success) {
|
|
55
|
+
await Promise.all((work.result?.tokens || []).map(unchainedApi.modules.warehousing.updateTokenOwnership));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
export default configureUpdateTokenOwnership;
|
|
60
|
+
WorkerDirector.registerAdapter(RefreshTokens);
|
|
61
|
+
WorkerDirector.registerAdapter(UpdateTokenOwnership);
|
|
62
|
+
WorkerDirector.configureAutoscheduling(RefreshTokens, {
|
|
63
|
+
schedule: everyMinute,
|
|
64
|
+
retries: 5,
|
|
65
|
+
input: () => {
|
|
66
|
+
/* */
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=update-token-ownership.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-token-ownership.js","sourceRoot":"","sources":["../../src/worker/update-token-ownership.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE7F,OAAO,KAAK,MAAM,eAAe,CAAC;AAElC,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAElD,MAAM,CAAC,MAAM,oBAAoB,GAA+B;IAC9D,GAAG,aAAa;IAEhB,GAAG,EAAE,qDAAqD;IAC1D,KAAK,EAAE,wDAAwD;IAC/D,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,wBAAwB;IAC9B,QAAQ,EAAE,IAAI;IAEd,KAAK,CAAC,MAAM;QACV,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAA8B;IACtD,GAAG,aAAa;IAEhB,GAAG,EAAE,6CAA6C;IAClD,KAAK,EAAE,uCAAuC;IAC9C,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,gBAAgB;IACtB,QAAQ,EAAE,KAAK;IAEf,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,cAAc;QAChC,MAAM,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC;QAEnC,MAAM,MAAM,GAAG,MAAM,OAA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QAAQ,EAAE,KAAK,EAAE,EAAE,IAAI,EAAkB,EAAE,EAAE;QACrF,IAAI,IAAI,CAAC,IAAI,KAAK,wBAAwB,IAAI,IAAI,CAAC,OAAO,EAAE;YAC1D,MAAM,OAAO,CAAC,GAAG,CACf,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,oBAAoB,CAAC,CACvF,CAAC;SACH;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,eAAe,6BAA6B,CAAC;AAE7C,cAAc,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;AAC9C,cAAc,CAAC,eAAe,CAAC,oBAAoB,CAAC,CAAC;AAErD,cAAc,CAAC,uBAAuB,CAAC,aAAa,EAAE;IACpD,QAAQ,EAAE,WAAW;IACrB,OAAO,EAAE,CAAC;IACV,KAAK,EAAE,GAAG,EAAE;QACV,KAAK;IACP,CAAC;CACF,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/plugins",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-beta3",
|
|
4
4
|
"main": "lib/plugins-index.js",
|
|
5
5
|
"types": "lib/plugins-index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -64,31 +64,31 @@
|
|
|
64
64
|
},
|
|
65
65
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@types/node": "^16.11.
|
|
68
|
-
"@unchainedshop/api": "^2.0.0-
|
|
67
|
+
"@types/node": "^16.11.68",
|
|
68
|
+
"@unchainedshop/api": "^2.0.0-beta3",
|
|
69
69
|
"@unchainedshop/client-oauth2": "^4.3.3",
|
|
70
|
-
"@unchainedshop/core-delivery": "^2.0.0-
|
|
71
|
-
"@unchainedshop/core-enrollments": "^2.0.0-
|
|
72
|
-
"@unchainedshop/core-filters": "^2.0.0-
|
|
73
|
-
"@unchainedshop/core-messaging": "^2.0.0-
|
|
74
|
-
"@unchainedshop/core-orders": "^2.0.0-
|
|
75
|
-
"@unchainedshop/core-payment": "^2.0.0-
|
|
76
|
-
"@unchainedshop/core-products": "^2.0.0-
|
|
77
|
-
"@unchainedshop/core-quotations": "^2.0.0-
|
|
78
|
-
"@unchainedshop/core-warehousing": "^2.0.0-
|
|
79
|
-
"@unchainedshop/core-worker": "^2.0.0-
|
|
80
|
-
"@unchainedshop/events": "^2.0.0-
|
|
81
|
-
"@unchainedshop/file-upload": "^2.0.0-
|
|
82
|
-
"@unchainedshop/logger": "^2.0.0-
|
|
83
|
-
"@unchainedshop/types": "^2.0.0-
|
|
84
|
-
"@unchainedshop/utils": "^2.0.0-
|
|
70
|
+
"@unchainedshop/core-delivery": "^2.0.0-beta3",
|
|
71
|
+
"@unchainedshop/core-enrollments": "^2.0.0-beta3",
|
|
72
|
+
"@unchainedshop/core-filters": "^2.0.0-beta3",
|
|
73
|
+
"@unchainedshop/core-messaging": "^2.0.0-beta3",
|
|
74
|
+
"@unchainedshop/core-orders": "^2.0.0-beta3",
|
|
75
|
+
"@unchainedshop/core-payment": "^2.0.0-beta3",
|
|
76
|
+
"@unchainedshop/core-products": "^2.0.0-beta3",
|
|
77
|
+
"@unchainedshop/core-quotations": "^2.0.0-beta3",
|
|
78
|
+
"@unchainedshop/core-warehousing": "^2.0.0-beta3",
|
|
79
|
+
"@unchainedshop/core-worker": "^2.0.0-beta3",
|
|
80
|
+
"@unchainedshop/events": "^2.0.0-beta3",
|
|
81
|
+
"@unchainedshop/file-upload": "^2.0.0-beta3",
|
|
82
|
+
"@unchainedshop/logger": "^2.0.0-beta3",
|
|
83
|
+
"@unchainedshop/types": "^2.0.0-beta3",
|
|
84
|
+
"@unchainedshop/utils": "^2.0.0-beta3",
|
|
85
85
|
"bluebird": "^3.7.2",
|
|
86
86
|
"body-parser": "^1.20.0",
|
|
87
87
|
"event-iterator": "^2.0.0",
|
|
88
88
|
"jest": "^29.2.1",
|
|
89
89
|
"JSONStream": "^1.3.5",
|
|
90
90
|
"minio": "^7.0.32",
|
|
91
|
-
"mongodb": "^4.
|
|
91
|
+
"mongodb": "^4.11.0",
|
|
92
92
|
"node-sheets": "^1.2.0",
|
|
93
93
|
"nodemailer": "^6.8.0",
|
|
94
94
|
"open": "^8.4.0",
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { IProductPricingAdapter } from '@unchainedshop/types/products.pricing';
|
|
2
2
|
import { ProductPricingDirector, ProductPricingAdapter } from '@unchainedshop/core-products';
|
|
3
3
|
|
|
4
|
-
const roundToNext = (value, precision) =>
|
|
5
|
-
value % precision === precision / 2
|
|
6
|
-
? value + precision / 2
|
|
7
|
-
: value + (precision - (value % precision));
|
|
4
|
+
const roundToNext = (value, precision) => Math.ceil(value / precision) * precision;
|
|
8
5
|
|
|
9
6
|
// String is referencing to a currency
|
|
10
7
|
interface PriceRoundSettings {
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { IWorkerAdapter, Work } from '@unchainedshop/types/worker';
|
|
2
|
+
import { WorkerDirector, WorkerAdapter, WorkerEventTypes } from '@unchainedshop/core-worker';
|
|
3
|
+
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
4
|
+
import later from '@breejs/later';
|
|
5
|
+
|
|
6
|
+
const everyMinute = later.parse.cron('* * * * *');
|
|
7
|
+
|
|
8
|
+
export const UpdateTokenOwnership: IWorkerAdapter<void, void> = {
|
|
9
|
+
...WorkerAdapter,
|
|
10
|
+
|
|
11
|
+
key: 'shop.unchained.worker-plugin.update-token-ownership',
|
|
12
|
+
label: 'External worker to update ownership of provided tokens',
|
|
13
|
+
version: '1.0',
|
|
14
|
+
type: 'UPDATE_TOKEN_OWNERSHIP',
|
|
15
|
+
external: true,
|
|
16
|
+
|
|
17
|
+
async doWork() {
|
|
18
|
+
throw new Error('Cannot do work for external workers');
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const RefreshTokens: IWorkerAdapter<void, any> = {
|
|
23
|
+
...WorkerAdapter,
|
|
24
|
+
|
|
25
|
+
key: 'shop.unchained.worker-plugin.refresh-tokens',
|
|
26
|
+
label: 'Worker to refresh tokens for accounts',
|
|
27
|
+
version: '1.0',
|
|
28
|
+
type: 'REFRESH_TOKENS',
|
|
29
|
+
external: false,
|
|
30
|
+
|
|
31
|
+
async doWork(input, requestContext) {
|
|
32
|
+
const { modules } = requestContext;
|
|
33
|
+
|
|
34
|
+
const tokens = await modules.warehousing.findTokens({});
|
|
35
|
+
const users = await modules.users.findUsers({ includeGuests: true });
|
|
36
|
+
const accounts = users.flatMap((user) => {
|
|
37
|
+
return user?.services?.web3?.flatMap((service) => {
|
|
38
|
+
if (service.verified) return [service.address];
|
|
39
|
+
return [];
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
tokens.forEach((token) => {
|
|
44
|
+
accounts.push(token.walletAddress);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (!tokens?.length) {
|
|
48
|
+
return { success: true, result: {} };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const forked = await modules.worker.addWork(
|
|
52
|
+
{
|
|
53
|
+
type: 'UPDATE_TOKEN_OWNERSHIP',
|
|
54
|
+
retries: 0,
|
|
55
|
+
input: {
|
|
56
|
+
filter: {
|
|
57
|
+
tokens,
|
|
58
|
+
accounts: [...new Set(accounts)],
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
null,
|
|
63
|
+
);
|
|
64
|
+
return { success: true, result: { forked } };
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const configureUpdateTokenOwnership = (unchainedApi: UnchainedCore) => {
|
|
69
|
+
WorkerDirector.events.on(WorkerEventTypes.FINISHED, async ({ work }: { work: Work }) => {
|
|
70
|
+
if (work.type === 'UPDATE_TOKEN_OWNERSHIP' && work.success) {
|
|
71
|
+
await Promise.all(
|
|
72
|
+
(work.result?.tokens || []).map(unchainedApi.modules.warehousing.updateTokenOwnership),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export default configureUpdateTokenOwnership;
|
|
79
|
+
|
|
80
|
+
WorkerDirector.registerAdapter(RefreshTokens);
|
|
81
|
+
WorkerDirector.registerAdapter(UpdateTokenOwnership);
|
|
82
|
+
|
|
83
|
+
WorkerDirector.configureAutoscheduling(RefreshTokens, {
|
|
84
|
+
schedule: everyMinute,
|
|
85
|
+
retries: 5,
|
|
86
|
+
input: () => {
|
|
87
|
+
/* */
|
|
88
|
+
},
|
|
89
|
+
});
|