@unchainedshop/platform 2.13.0 → 3.0.0-alpha2
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/bulk-importer/handlers/assortment/create.d.ts.map +1 -1
- package/lib/bulk-importer/handlers/assortment/create.js +9 -7
- package/lib/bulk-importer/handlers/assortment/create.js.map +1 -1
- package/lib/bulk-importer/handlers/assortment/update.d.ts.map +1 -1
- package/lib/bulk-importer/handlers/assortment/update.js.map +1 -1
- package/lib/bulk-importer/handlers/filter/create.d.ts.map +1 -1
- package/lib/bulk-importer/handlers/filter/create.js +10 -6
- package/lib/bulk-importer/handlers/filter/create.js.map +1 -1
- package/lib/bulk-importer/handlers/filter/update.d.ts.map +1 -1
- package/lib/bulk-importer/handlers/filter/update.js +10 -6
- package/lib/bulk-importer/handlers/filter/update.js.map +1 -1
- package/lib/bulk-importer/handlers/product/create.d.ts.map +1 -1
- package/lib/bulk-importer/handlers/product/create.js +9 -7
- package/lib/bulk-importer/handlers/product/create.js.map +1 -1
- package/lib/bulk-importer/handlers/product/upsertVariations.d.ts.map +1 -1
- package/lib/bulk-importer/handlers/product/upsertVariations.js +17 -11
- package/lib/bulk-importer/handlers/product/upsertVariations.js.map +1 -1
- package/lib/context/index.d.ts +0 -1
- package/lib/context/index.d.ts.map +1 -1
- package/lib/context/index.js +0 -1
- package/lib/context/index.js.map +1 -1
- package/lib/context/setAccessToken.d.ts +1 -1
- package/lib/context/setAccessToken.d.ts.map +1 -1
- package/lib/context/setAccessToken.js +3 -1
- package/lib/context/setAccessToken.js.map +1 -1
- package/lib/platform-index.d.ts +4 -4
- package/lib/platform-index.d.ts.map +1 -1
- package/lib/setup/setupAccounts.d.ts +1 -1
- package/lib/setup/setupAccounts.d.ts.map +1 -1
- package/lib/setup/setupAccounts.js +8 -160
- package/lib/setup/setupAccounts.js.map +1 -1
- package/lib/startPlatform.d.ts +6 -9
- package/lib/startPlatform.d.ts.map +1 -1
- package/lib/startPlatform.js +4 -10
- package/lib/startPlatform.js.map +1 -1
- package/package.json +11 -11
- package/src/bulk-importer/handlers/assortment/create.ts +12 -10
- package/src/bulk-importer/handlers/assortment/update.ts +1 -0
- package/src/bulk-importer/handlers/filter/create.ts +13 -11
- package/src/bulk-importer/handlers/filter/update.ts +13 -11
- package/src/bulk-importer/handlers/product/create.ts +12 -10
- package/src/bulk-importer/handlers/product/upsertVariations.ts +24 -20
- package/src/context/index.ts +0 -1
- package/src/context/setAccessToken.ts +8 -1
- package/src/setup/setupAccounts.ts +8 -237
- package/src/startPlatform.ts +10 -25
- package/lib/context/withAccessToken.d.ts +0 -4
- package/lib/context/withAccessToken.d.ts.map +0 -1
- package/lib/context/withAccessToken.js +0 -37
- package/lib/context/withAccessToken.js.map +0 -1
- package/src/context/withAccessToken.ts +0 -40
package/lib/startPlatform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startPlatform.js","sourceRoot":"","sources":["../src/startPlatform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"startPlatform.js","sourceRoot":"","sources":["../src/startPlatform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAwB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5D,OAAO,EAAqB,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AACrG,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAA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QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QAC1D,MAAM,UAAU,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;IACnD,CAAC;IAED,qBAAqB;IACrB,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,yBAAyB,EAAE,CAAC;QAChD,YAAY,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC;IACrF,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;AAC1C,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/platform",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha2",
|
|
4
4
|
"main": "lib/platform-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/platform-index.js",
|
|
@@ -31,22 +31,22 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@unchainedshop/api": "^
|
|
35
|
-
"@unchainedshop/core": "^
|
|
36
|
-
"@unchainedshop/events": "^
|
|
37
|
-
"@unchainedshop/file-upload": "^
|
|
38
|
-
"@unchainedshop/logger": "^
|
|
39
|
-
"@unchainedshop/mongodb": "^
|
|
40
|
-
"@unchainedshop/plugins": "^
|
|
41
|
-
"@unchainedshop/roles": "^
|
|
42
|
-
"@unchainedshop/utils": "^
|
|
34
|
+
"@unchainedshop/api": "^3.0.0-alpha2",
|
|
35
|
+
"@unchainedshop/core": "^3.0.0-alpha2",
|
|
36
|
+
"@unchainedshop/events": "^3.0.0-alpha2",
|
|
37
|
+
"@unchainedshop/file-upload": "^3.0.0-alpha2",
|
|
38
|
+
"@unchainedshop/logger": "^3.0.0-alpha2",
|
|
39
|
+
"@unchainedshop/mongodb": "^3.0.0-alpha2",
|
|
40
|
+
"@unchainedshop/plugins": "^3.0.0-alpha2",
|
|
41
|
+
"@unchainedshop/roles": "^3.0.0-alpha2",
|
|
42
|
+
"@unchainedshop/utils": "^3.0.0-alpha2",
|
|
43
43
|
"event-iterator": "^2.0.0",
|
|
44
44
|
"JSONStream": "^1.3.5",
|
|
45
45
|
"moniker": "0.1.2"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/node": "^20.14.12",
|
|
49
|
-
"@unchainedshop/types": "^
|
|
49
|
+
"@unchainedshop/types": "^3.0.0-alpha2",
|
|
50
50
|
"cross-env": "^7.0.3",
|
|
51
51
|
"jest": "^29.7.0",
|
|
52
52
|
"ts-jest": "^29.2.3",
|
|
@@ -34,16 +34,18 @@ export default async function createAssortment(
|
|
|
34
34
|
throw new Error(`Can't create assortment ${_id}, fields missing?`);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
if (specification.content) {
|
|
38
|
+
logger.debug('create localized content for assortment', specification.content);
|
|
39
|
+
await modules.assortments.texts.updateTexts(
|
|
40
|
+
_id,
|
|
41
|
+
Object.entries(specification.content).map(([locale, localizedData]: [string, any]) => {
|
|
42
|
+
return {
|
|
43
|
+
locale,
|
|
44
|
+
...localizedData,
|
|
45
|
+
};
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
47
49
|
|
|
48
50
|
logger.debug('create assortment products', products);
|
|
49
51
|
await upsertAssortmentProducts(
|
|
@@ -27,6 +27,7 @@ export default async function updateAssortment(
|
|
|
27
27
|
specification.tags = convertTagsToLowerCase(specification?.tags);
|
|
28
28
|
|
|
29
29
|
await unchainedAPI.modules.assortments.update(_id, { ...specification });
|
|
30
|
+
|
|
30
31
|
if (specification.content) {
|
|
31
32
|
logger.debug('replace localized content for assortment', specification.content);
|
|
32
33
|
await modules.assortments.texts.updateTexts(
|
|
@@ -60,17 +60,19 @@ export default async function createFilter(
|
|
|
60
60
|
if (options) {
|
|
61
61
|
logger.debug('create localized content for filter options', content);
|
|
62
62
|
await Promise.all(
|
|
63
|
-
options.map(async ({ content: optionContent, value: optionValue }) =>
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
63
|
+
options.map(async ({ content: optionContent, value: optionValue }) => {
|
|
64
|
+
if (optionContent) {
|
|
65
|
+
await modules.filters.texts.updateTexts(
|
|
66
|
+
{ filterId: _id, filterOptionValue: optionValue },
|
|
67
|
+
Object.entries(optionContent).map(([locale, localizedData]: [string, any]) => {
|
|
68
|
+
return {
|
|
69
|
+
locale,
|
|
70
|
+
...localizedData,
|
|
71
|
+
};
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}),
|
|
74
76
|
);
|
|
75
77
|
}
|
|
76
78
|
|
|
@@ -47,17 +47,19 @@ export default async function updateFilter(
|
|
|
47
47
|
if (options) {
|
|
48
48
|
logger.debug('replace localized content for filter options', content);
|
|
49
49
|
await Promise.all(
|
|
50
|
-
options.map(async ({ content: optionContent, value: optionValue }) =>
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
options.map(async ({ content: optionContent, value: optionValue }) => {
|
|
51
|
+
if (optionContent) {
|
|
52
|
+
await modules.filters.texts.updateTexts(
|
|
53
|
+
{ filterId: _id, filterOptionValue: optionValue },
|
|
54
|
+
Object.entries(optionContent).map(([locale, localizedData]: [string, any]) => {
|
|
55
|
+
return {
|
|
56
|
+
locale,
|
|
57
|
+
...localizedData,
|
|
58
|
+
};
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}),
|
|
61
63
|
);
|
|
62
64
|
}
|
|
63
65
|
|
|
@@ -35,16 +35,18 @@ export default async function createProduct(
|
|
|
35
35
|
throw new Error(`Can't create product ${_id}, fields missing?`);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
if (specification.content) {
|
|
39
|
+
logger.debug('create localized content for product', specification.content);
|
|
40
|
+
await modules.products.texts.updateTexts(
|
|
41
|
+
_id,
|
|
42
|
+
Object.entries(specification.content).map(([locale, localizedData]: [string, any]) => {
|
|
43
|
+
return {
|
|
44
|
+
locale,
|
|
45
|
+
...localizedData,
|
|
46
|
+
};
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
48
50
|
|
|
49
51
|
logger.debug('create product variations', variations);
|
|
50
52
|
await upsertVariations(
|
|
@@ -26,28 +26,32 @@ export default async function upsertVariations({ variations, productId }, unchai
|
|
|
26
26
|
);
|
|
27
27
|
|
|
28
28
|
await Promise.all(
|
|
29
|
-
options.map(async ({ content: optionContent, value: optionValue }) =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
await modules.products.variations.texts.updateVariationTexts(
|
|
43
|
-
variation._id,
|
|
44
|
-
Object.entries(content).map(([locale, localizedData]: [string, any]) => {
|
|
45
|
-
return {
|
|
46
|
-
locale,
|
|
47
|
-
...localizedData,
|
|
48
|
-
};
|
|
29
|
+
options.map(async ({ content: optionContent, value: optionValue }) => {
|
|
30
|
+
if (optionContent) {
|
|
31
|
+
await modules.products.variations.texts.updateVariationTexts(
|
|
32
|
+
variation._id,
|
|
33
|
+
Object.entries(optionContent).map(([locale, localizedData]: [string, any]) => {
|
|
34
|
+
return {
|
|
35
|
+
locale,
|
|
36
|
+
...localizedData,
|
|
37
|
+
};
|
|
38
|
+
}),
|
|
39
|
+
optionValue,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
49
42
|
}),
|
|
50
43
|
);
|
|
44
|
+
if (content) {
|
|
45
|
+
await modules.products.variations.texts.updateVariationTexts(
|
|
46
|
+
variation._id,
|
|
47
|
+
Object.entries(content).map(([locale, localizedData]: [string, any]) => {
|
|
48
|
+
return {
|
|
49
|
+
locale,
|
|
50
|
+
...localizedData,
|
|
51
|
+
};
|
|
52
|
+
}),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
51
55
|
return variation._id;
|
|
52
56
|
}),
|
|
53
57
|
);
|
package/src/context/index.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { UnchainedCore } from '@unchainedshop/types/core.js';
|
|
2
|
+
import crypto from 'crypto';
|
|
3
|
+
|
|
4
|
+
export default async (
|
|
5
|
+
unchainedAPI: UnchainedCore,
|
|
6
|
+
username: string,
|
|
7
|
+
plainSecret: string,
|
|
8
|
+
): Promise<void> => {
|
|
9
|
+
const secret = crypto.createHash('sha256').update(`${username}:${plainSecret}`).digest('hex');
|
|
2
10
|
|
|
3
|
-
export default async (unchainedAPI: UnchainedCore, username: string, secret: string): Promise<void> => {
|
|
4
11
|
await unchainedAPI.modules.users.updateUser(
|
|
5
12
|
{ username },
|
|
6
13
|
{
|
|
@@ -1,245 +1,16 @@
|
|
|
1
|
-
import { User } from '@unchainedshop/types/user.js';
|
|
2
|
-
import { randomValueHex } from '@unchainedshop/utils';
|
|
3
|
-
import { accountsSettings } from '@unchainedshop/core-accountsjs';
|
|
4
|
-
import moniker from 'moniker';
|
|
5
1
|
import { UnchainedCore } from '@unchainedshop/types/core.js';
|
|
2
|
+
import { subscribe } from '@unchainedshop/events';
|
|
6
3
|
|
|
7
4
|
export const setupAccounts = (unchainedAPI: UnchainedCore) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
accountsServer.users = unchainedAPI.modules.users;
|
|
11
|
-
|
|
12
|
-
accountsServer.options.prepareMail = (
|
|
13
|
-
to: string,
|
|
14
|
-
token: string,
|
|
15
|
-
user: User & { id: string },
|
|
16
|
-
pathFragment: string,
|
|
17
|
-
) => {
|
|
18
|
-
return {
|
|
19
|
-
template: 'ACCOUNT_ACTION',
|
|
20
|
-
recipientEmail: to,
|
|
21
|
-
action: pathFragment,
|
|
22
|
-
userId: user.id || user._id,
|
|
23
|
-
token,
|
|
24
|
-
skipMessaging: !!user.guest && pathFragment === 'verify-email',
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
accountsServer.options.sendMail = (input: any) => {
|
|
29
|
-
if (!input) return true;
|
|
30
|
-
if (input.skipMessaging) return true;
|
|
31
|
-
|
|
32
|
-
return unchainedAPI.modules.worker.addWork({
|
|
5
|
+
subscribe('USER_ACCOUNT_ACTION', async ({ payload }: { payload: any }) => {
|
|
6
|
+
await unchainedAPI.modules.worker.addWork({
|
|
33
7
|
type: 'MESSAGE',
|
|
34
8
|
retries: 0,
|
|
35
|
-
input
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
accountsServer.services.guest = {
|
|
40
|
-
async authenticate(params: { email?: string | null }) {
|
|
41
|
-
const guestname = `${moniker.choose()}-${randomValueHex(5)}`;
|
|
42
|
-
|
|
43
|
-
const guestUserId = await unchainedAPI.modules.accounts.createUser(
|
|
44
|
-
{
|
|
45
|
-
email: params.email || `${guestname}@unchained.local`,
|
|
46
|
-
guest: true,
|
|
47
|
-
password: null,
|
|
48
|
-
initialPassword: true,
|
|
49
|
-
},
|
|
50
|
-
{},
|
|
51
|
-
);
|
|
52
|
-
return unchainedAPI.modules.users.findUserById(guestUserId);
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
accountsServer.services.webAuthn = {
|
|
57
|
-
async authenticate(params: { webAuthnPublicKeyCredentials: any }) {
|
|
58
|
-
const username =
|
|
59
|
-
Buffer.from(params.webAuthnPublicKeyCredentials?.response?.userHandle, 'base64').toString() ||
|
|
60
|
-
'';
|
|
61
|
-
|
|
62
|
-
const user = await unchainedAPI.modules.users.findUser({ username });
|
|
63
|
-
if (!user) throw new Error('User not found');
|
|
64
|
-
|
|
65
|
-
await unchainedAPI.modules.accounts.webAuthn.verifyCredentialRequest(
|
|
66
|
-
user.services?.webAuthn,
|
|
67
|
-
user.username,
|
|
68
|
-
params.webAuthnPublicKeyCredentials,
|
|
69
|
-
);
|
|
70
|
-
return user;
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
accountsServer.services.oauth2 = {
|
|
75
|
-
async authenticate({
|
|
76
|
-
authorizationCode,
|
|
77
|
-
provider,
|
|
78
|
-
redirectUrl,
|
|
79
|
-
}: {
|
|
80
|
-
authorizationCode: any;
|
|
81
|
-
provider: string;
|
|
82
|
-
redirectUrl: string;
|
|
83
|
-
}): Promise<any> {
|
|
84
|
-
if (!authorizationCode || !provider) {
|
|
85
|
-
return undefined;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const { modules, services } = unchainedAPI;
|
|
89
|
-
|
|
90
|
-
const authorizationToken = await modules.accounts.oAuth2.getAuthorizationToken(
|
|
91
|
-
provider,
|
|
92
|
-
authorizationCode,
|
|
93
|
-
redirectUrl,
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
if (!authorizationToken) throw new Error('Unable to authorize user');
|
|
97
|
-
const data = await modules.accounts.oAuth2.getAccountData(provider, authorizationToken);
|
|
98
|
-
if (!data?.id) {
|
|
99
|
-
throw new Error('OAuth authentication failed or no id returned from service');
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const user = await unchainedAPI.modules.users.findUser({
|
|
103
|
-
[`services.oauth.${provider}.id`]: data.id,
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
if (!user) {
|
|
107
|
-
const newUserId = await unchainedAPI.modules.accounts.createUser(
|
|
108
|
-
{
|
|
109
|
-
username: data.username || `${data.id}`,
|
|
110
|
-
email: data.email,
|
|
111
|
-
guest: false,
|
|
112
|
-
initialPassword: undefined,
|
|
113
|
-
password: undefined,
|
|
114
|
-
profile: {
|
|
115
|
-
address: {
|
|
116
|
-
firstName: data?.firstName,
|
|
117
|
-
lastName: data?.lastName,
|
|
118
|
-
addressLine: data?.address,
|
|
119
|
-
city: data?.city,
|
|
120
|
-
countryCode: data?.countryCode,
|
|
121
|
-
regionCode: data?.regionCode,
|
|
122
|
-
postalCode: data?.postalCode,
|
|
123
|
-
company: data?.company,
|
|
124
|
-
},
|
|
125
|
-
gender: data?.gender,
|
|
126
|
-
phoneMobile: data?.phoneNumber,
|
|
127
|
-
displayName: data?.displayName,
|
|
128
|
-
birthday: data?.birthDate,
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
{ skipPasswordEnrollment: true },
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
await modules.users.updateUser(
|
|
135
|
-
{ _id: newUserId },
|
|
136
|
-
{
|
|
137
|
-
$push: {
|
|
138
|
-
[`services.oauth.${provider}`]: {
|
|
139
|
-
id: data.id,
|
|
140
|
-
authorizationToken,
|
|
141
|
-
authorizationCode,
|
|
142
|
-
data,
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
{ upsert: true },
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
if (data?.avatarUrl) {
|
|
150
|
-
const file = await services.files.uploadFileFromURL(
|
|
151
|
-
{
|
|
152
|
-
directoryName: 'user-avatars',
|
|
153
|
-
fileInput: {
|
|
154
|
-
fileLink: data.avatarUrl,
|
|
155
|
-
fileName: `${data.firstName}-avatar`,
|
|
156
|
-
},
|
|
157
|
-
meta: { userId: newUserId },
|
|
158
|
-
},
|
|
159
|
-
unchainedAPI,
|
|
160
|
-
);
|
|
161
|
-
if (user?.avatarId) {
|
|
162
|
-
await services.files.removeFiles(
|
|
163
|
-
{
|
|
164
|
-
fileIds: [user.avatarId as string],
|
|
165
|
-
},
|
|
166
|
-
unchainedAPI,
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
return modules.users.updateAvatar(newUserId, file._id);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return user;
|
|
174
|
-
},
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
accountsServer.on('LoginTokenCreated', async (props) => {
|
|
178
|
-
const { userId, connection = {} } = props;
|
|
179
|
-
|
|
180
|
-
// TODO: Doubt that there is countryContext etc. here?
|
|
181
|
-
const { userIdBeforeLogin, countryContext, remoteAddress, remotePort, userAgent, normalizedLocale } =
|
|
182
|
-
connection;
|
|
183
|
-
|
|
184
|
-
await unchainedAPI.modules.users.updateHeartbeat(userId, {
|
|
185
|
-
remoteAddress,
|
|
186
|
-
remotePort,
|
|
187
|
-
userAgent,
|
|
188
|
-
locale: normalizedLocale,
|
|
189
|
-
countryCode: countryContext,
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
const user = await unchainedAPI.modules.users.findUserById(userId);
|
|
193
|
-
|
|
194
|
-
if (userIdBeforeLogin) {
|
|
195
|
-
const userBeforeLogin = await unchainedAPI.modules.users.findUserById(userIdBeforeLogin);
|
|
196
|
-
|
|
197
|
-
await unchainedAPI.services.orders.migrateOrderCarts(
|
|
198
|
-
{
|
|
199
|
-
fromUserId: userBeforeLogin._id,
|
|
200
|
-
toUserId: user._id,
|
|
201
|
-
shouldMerge: accountsSettings.mergeUserCartsOnLogin,
|
|
202
|
-
countryContext:
|
|
203
|
-
countryContext || userBeforeLogin.lastLogin?.countryCode || user.lastLogin?.countryCode,
|
|
204
|
-
},
|
|
205
|
-
unchainedAPI,
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
await unchainedAPI.services.bookmarks.migrateBookmarks(
|
|
209
|
-
{
|
|
210
|
-
fromUserId: userBeforeLogin._id,
|
|
211
|
-
toUserId: user._id,
|
|
212
|
-
shouldMerge: accountsSettings.mergeUserCartsOnLogin,
|
|
213
|
-
countryContext:
|
|
214
|
-
countryContext || userBeforeLogin.lastLogin?.countryCode || user.lastLogin?.countryCode,
|
|
215
|
-
},
|
|
216
|
-
unchainedAPI,
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
return unchainedAPI.services.orders.nextUserCart(
|
|
221
|
-
{
|
|
222
|
-
user,
|
|
223
|
-
countryCode: countryContext,
|
|
9
|
+
input: {
|
|
10
|
+
template: 'ACCOUNT_ACTION',
|
|
11
|
+
recipientEmail: payload.address,
|
|
12
|
+
...payload,
|
|
224
13
|
},
|
|
225
|
-
|
|
226
|
-
);
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
accountsServer.on('ResetPasswordSuccess', async (user: User) => {
|
|
230
|
-
await unchainedAPI.modules.users.updateInitialPassword(user, false);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
accountsServer.on('ChangePasswordSuccess', async (user: User) => {
|
|
234
|
-
await unchainedAPI.modules.users.updateInitialPassword(user, false);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
accountsServer.on('ValidateLogin', async (params: { service: string; user: User }) => {
|
|
238
|
-
if (params.service !== 'guest' && params.user.guest) {
|
|
239
|
-
await unchainedAPI.modules.users.updateGuest(params.user, false);
|
|
240
|
-
}
|
|
241
|
-
return true;
|
|
14
|
+
});
|
|
242
15
|
});
|
|
243
|
-
|
|
244
|
-
return accountsServer;
|
|
245
16
|
};
|
package/src/startPlatform.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { startAPIServer, roles } from '@unchainedshop/api';
|
|
1
|
+
import { startAPIServer, GraphQLServerOptions, roles } from '@unchainedshop/api';
|
|
2
2
|
import { initCore } from '@unchainedshop/core';
|
|
3
3
|
import { initDb } from '@unchainedshop/mongodb';
|
|
4
4
|
import { createLogger } from '@unchainedshop/logger';
|
|
@@ -6,6 +6,7 @@ import { UnchainedCore, UnchainedCoreOptions } from '@unchainedshop/types/core.j
|
|
|
6
6
|
import { getRegisteredEvents } from '@unchainedshop/events';
|
|
7
7
|
import { WorkerDirector } from '@unchainedshop/core-worker';
|
|
8
8
|
import { AdminUiConfig } from '@unchainedshop/types/api.js';
|
|
9
|
+
import { Db } from 'mongodb';
|
|
9
10
|
import { BulkImportHandler, createBulkImporterFactory } from './bulk-importer/createBulkImporter.js';
|
|
10
11
|
import { runMigrations } from './migrations/runMigrations.js';
|
|
11
12
|
import { setupAccounts } from './setup/setupAccounts.js';
|
|
@@ -17,19 +18,14 @@ import { createMigrationRepository } from './migrations/migrationRepository.js';
|
|
|
17
18
|
export { MessageTypes };
|
|
18
19
|
|
|
19
20
|
export type PlatformOptions = {
|
|
20
|
-
typeDefs?: Array<string>;
|
|
21
|
-
resolvers?: any;
|
|
22
|
-
schema?: any;
|
|
23
|
-
plugins?: any[];
|
|
24
|
-
cache?: any;
|
|
25
21
|
bulkImporter?: {
|
|
26
22
|
handlers?: Record<string, BulkImportHandler>;
|
|
27
23
|
};
|
|
28
24
|
context?: any;
|
|
29
25
|
workQueueOptions?: SetupWorkqueueOptions & SetupCartsOptions;
|
|
30
|
-
introspection?: boolean;
|
|
31
26
|
adminUiConfig?: AdminUiConfig;
|
|
32
|
-
} & Partial<Pick<UnchainedCoreOptions, 'modules' | 'services' | 'options' | 'rolesOptions'
|
|
27
|
+
} & Partial<Pick<UnchainedCoreOptions, 'modules' | 'services' | 'options' | 'rolesOptions'>> &
|
|
28
|
+
GraphQLServerOptions;
|
|
33
29
|
|
|
34
30
|
const logger = createLogger('unchained');
|
|
35
31
|
|
|
@@ -55,21 +51,16 @@ export const queueWorkers: Array<any> = [];
|
|
|
55
51
|
export const startPlatform = async ({
|
|
56
52
|
modules = {},
|
|
57
53
|
services = {},
|
|
58
|
-
typeDefs = [],
|
|
59
|
-
resolvers = [],
|
|
60
54
|
options = {},
|
|
61
55
|
adminUiConfig = {},
|
|
62
56
|
rolesOptions = {},
|
|
63
57
|
bulkImporter: bulkImporterOptions,
|
|
64
|
-
schema,
|
|
65
|
-
plugins,
|
|
66
|
-
cache,
|
|
67
58
|
workQueueOptions,
|
|
68
|
-
|
|
69
|
-
introspection,
|
|
59
|
+
...arbitraryGraphQLServerOptions
|
|
70
60
|
}: PlatformOptions): Promise<{
|
|
71
61
|
unchainedAPI: UnchainedCore;
|
|
72
|
-
|
|
62
|
+
yogaServer: any;
|
|
63
|
+
db: Db;
|
|
73
64
|
}> => {
|
|
74
65
|
exitOnMissingEnvironmentVariables();
|
|
75
66
|
|
|
@@ -107,19 +98,13 @@ export const startPlatform = async ({
|
|
|
107
98
|
setupTemplates(unchainedAPI);
|
|
108
99
|
|
|
109
100
|
// Start the graphQL server
|
|
110
|
-
const
|
|
101
|
+
const yogaServer = await startAPIServer({
|
|
111
102
|
unchainedAPI,
|
|
112
103
|
roles: configuredRoles,
|
|
113
104
|
events: configuredEvents,
|
|
114
105
|
workTypes: configuredWorkTypes,
|
|
115
|
-
typeDefs,
|
|
116
|
-
resolvers,
|
|
117
|
-
schema,
|
|
118
|
-
plugins,
|
|
119
|
-
cache,
|
|
120
|
-
context,
|
|
121
|
-
introspection,
|
|
122
106
|
adminUiConfig,
|
|
107
|
+
...arbitraryGraphQLServerOptions,
|
|
123
108
|
});
|
|
124
109
|
|
|
125
110
|
// Setup work queues for scheduled work
|
|
@@ -134,5 +119,5 @@ export const startPlatform = async ({
|
|
|
134
119
|
setImmediate(() => unchainedAPI.modules.filters.invalidateCache({}, unchainedAPI));
|
|
135
120
|
}
|
|
136
121
|
|
|
137
|
-
return { unchainedAPI,
|
|
122
|
+
return { unchainedAPI, yogaServer, db };
|
|
138
123
|
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"withAccessToken.d.ts","sourceRoot":"","sources":["../../src/context/withAccessToken.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;8BAOlC,CAAC,OAAO,EAAE,OAAO,KAAK,GAAG,KAAqB,GAAG;AAArE,wBA+BE"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
-
import { timingSafeEqual } from 'crypto';
|
|
3
|
-
const logger = createLogger('unchained:platform');
|
|
4
|
-
const contextIdentity = (params) => params;
|
|
5
|
-
export default (fn = contextIdentity) => {
|
|
6
|
-
return async (params, unchainedContextFn) => {
|
|
7
|
-
const unchainedContext = await unchainedContextFn(params);
|
|
8
|
-
const newContext = {
|
|
9
|
-
userId: unchainedContext.userId,
|
|
10
|
-
user: unchainedContext.user,
|
|
11
|
-
};
|
|
12
|
-
if (!unchainedContext.userId && params.req.headers.authorization) {
|
|
13
|
-
const [type, userToken] = params.req.headers.authorization.split(' ');
|
|
14
|
-
if (type === 'Bearer' && userToken) {
|
|
15
|
-
const [username, secret] = userToken.split(':');
|
|
16
|
-
const user = await unchainedContext.modules.users.findUser({
|
|
17
|
-
username,
|
|
18
|
-
});
|
|
19
|
-
if (secret && user?.services.token?.secret) {
|
|
20
|
-
if (timingSafeEqual(Buffer.from(secret), Buffer.from(user?.services.token?.secret))) {
|
|
21
|
-
newContext.userId = user._id;
|
|
22
|
-
newContext.user = user;
|
|
23
|
-
logger.debug('Token login success');
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
logger.warn('Token login failed');
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return fn({
|
|
32
|
-
...unchainedContext,
|
|
33
|
-
...newContext,
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
//# sourceMappingURL=withAccessToken.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"withAccessToken.js","s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