@unchainedshop/platform 4.5.0 → 4.6.1
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.
|
@@ -41,7 +41,7 @@ export const createMigrationRunner = ({ currentId, logger = console, migrationRe
|
|
|
41
41
|
return [mostRecentId, migrations.length];
|
|
42
42
|
}
|
|
43
43
|
catch (e) {
|
|
44
|
-
logger.error(e.name
|
|
44
|
+
logger.error(`Migration failed: ${e.name} - ${e.message}`);
|
|
45
45
|
return [e.migrationId, null];
|
|
46
46
|
}
|
|
47
47
|
},
|
package/lib/startPlatform.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type PlatformOptions = {
|
|
|
10
10
|
rolesOptions?: IRoleOptionConfig;
|
|
11
11
|
workQueueOptions?: SetupWorkqueueOptions;
|
|
12
12
|
} & Omit<UnchainedCoreOptions, 'migrationRepository' | 'db'> & Omit<UnchainedServerOptions, 'roles' | 'unchainedAPI'>;
|
|
13
|
-
export declare const startPlatform: ({ modules, services, options, rolesOptions, bulkImporter, workQueueOptions, ...arbitraryAPIServerConfiguration }: PlatformOptions) => Promise<{
|
|
13
|
+
export declare const startPlatform: ({ modules, services, options, rolesOptions, bulkImporter, bulkExporter, workQueueOptions, ...arbitraryAPIServerConfiguration }: PlatformOptions) => Promise<{
|
|
14
14
|
unchainedAPI: UnchainedCore;
|
|
15
15
|
graphqlHandler: any;
|
|
16
16
|
db: mongodb.Db;
|
package/lib/startPlatform.js
CHANGED
|
@@ -16,6 +16,7 @@ const REQUIRED_ENV_VARIABLES = [
|
|
|
16
16
|
'ROOT_URL',
|
|
17
17
|
'UNCHAINED_TOKEN_SECRET',
|
|
18
18
|
];
|
|
19
|
+
const CLEANUP_FORCE_EXIT_TIMEOUT_MS = 15000;
|
|
19
20
|
const exitOnMissingEnvironmentVariables = () => {
|
|
20
21
|
const failedEnv = REQUIRED_ENV_VARIABLES.filter((key) => !process.env[key]);
|
|
21
22
|
if (failedEnv.length > 0) {
|
|
@@ -29,7 +30,7 @@ const existOnInvalidEnvironmentVariables = () => {
|
|
|
29
30
|
process.exit(1);
|
|
30
31
|
}
|
|
31
32
|
};
|
|
32
|
-
export const startPlatform = async ({ modules, services, options, rolesOptions, bulkImporter, workQueueOptions, ...arbitraryAPIServerConfiguration }) => {
|
|
33
|
+
export const startPlatform = async ({ modules, services, options, rolesOptions, bulkImporter, bulkExporter, workQueueOptions, ...arbitraryAPIServerConfiguration }) => {
|
|
33
34
|
const start = performance.now();
|
|
34
35
|
exitOnMissingEnvironmentVariables();
|
|
35
36
|
existOnInvalidEnvironmentVariables();
|
|
@@ -43,6 +44,7 @@ export const startPlatform = async ({ modules, services, options, rolesOptions,
|
|
|
43
44
|
modules,
|
|
44
45
|
services,
|
|
45
46
|
options,
|
|
47
|
+
bulkExporter,
|
|
46
48
|
});
|
|
47
49
|
setupAccounts(unchainedAPI);
|
|
48
50
|
setupTemplates(unchainedAPI);
|
|
@@ -59,18 +61,51 @@ export const startPlatform = async ({ modules, services, options, rolesOptions,
|
|
|
59
61
|
});
|
|
60
62
|
const version = UNCHAINED_API_VERSION || npm_package_version || 'n/a';
|
|
61
63
|
defaultLogger.info(`Unchained Engine running`, { version });
|
|
64
|
+
let isCleaningUp = false;
|
|
62
65
|
const cleanup = (signal) => async () => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
if (isCleaningUp) {
|
|
67
|
+
defaultLogger.debug('Cleanup already in progress, ignoring signal', { signal });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
isCleaningUp = true;
|
|
71
|
+
defaultLogger.debug('Starting cleanup', { signal });
|
|
72
|
+
const forceExitTimeout = setTimeout(() => {
|
|
73
|
+
defaultLogger.error('Cleanup timeout exceeded, forcing exit');
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}, CLEANUP_FORCE_EXIT_TIMEOUT_MS);
|
|
76
|
+
forceExitTimeout.unref();
|
|
77
|
+
try {
|
|
78
|
+
defaultLogger.debug('Stopping Workqueue', { signal });
|
|
79
|
+
stopWorkqueue();
|
|
80
|
+
defaultLogger.debug('Stopping GraphQL server', { signal });
|
|
81
|
+
await graphqlHandler.dispose();
|
|
82
|
+
defaultLogger.debug('Stopping DB Connection', { signal });
|
|
83
|
+
await stopDb();
|
|
84
|
+
defaultLogger.debug(`Unchained Engine exiting gracefully`, { signal, version });
|
|
85
|
+
clearTimeout(forceExitTimeout);
|
|
86
|
+
process.exit(0);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
defaultLogger.error('Error during cleanup', {
|
|
90
|
+
signal,
|
|
91
|
+
error: error instanceof Error ? error.message : String(error),
|
|
92
|
+
});
|
|
93
|
+
clearTimeout(forceExitTimeout);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
71
96
|
};
|
|
72
97
|
process.on('SIGTERM', cleanup('SIGTERM'));
|
|
73
98
|
process.on('SIGINT', cleanup('SIGINT'));
|
|
99
|
+
process.on('uncaughtException', async (error) => {
|
|
100
|
+
defaultLogger.error('Uncaught exception', { error: error.message, stack: error.stack });
|
|
101
|
+
await cleanup('uncaughtException')();
|
|
102
|
+
});
|
|
103
|
+
process.on('unhandledRejection', async (reason) => {
|
|
104
|
+
defaultLogger.error('Unhandled rejection', {
|
|
105
|
+
reason: reason instanceof Error ? reason.message : String(reason),
|
|
106
|
+
});
|
|
107
|
+
await cleanup('unhandledRejection')();
|
|
108
|
+
});
|
|
74
109
|
const end = performance.now();
|
|
75
110
|
defaultLogger.debug(`Unchained Engine started in ${(end - start).toFixed(0)} ms`);
|
|
76
111
|
return { unchainedAPI, graphqlHandler, db };
|
|
@@ -11,7 +11,7 @@ export const resolveOrderRejectionTemplate = async ({ orderId, locale }, context
|
|
|
11
11
|
const text = `
|
|
12
12
|
I'm sorry we can't confirm your order.
|
|
13
13
|
|
|
14
|
-
This can happen when the payment was not successful or the order was manually canceled because of product availability or
|
|
14
|
+
This can happen when the payment was not successful or the order was manually canceled because of product availability or fulfillment issues.
|
|
15
15
|
|
|
16
16
|
The order in question is:
|
|
17
17
|
|
|
@@ -2,12 +2,6 @@ const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
|
|
|
2
2
|
export const resolveQuotationStatusTemplate = async ({ quotationId }, { modules }) => {
|
|
3
3
|
const quotation = await modules.quotations.findQuotation({ quotationId });
|
|
4
4
|
const user = await modules.users.findUserById(quotation.userId);
|
|
5
|
-
const attachments = (await modules.files.findFiles({ 'meta.quotationId': quotation._id, 'meta.type': 'PROPOSAL' }, { sort: { 'meta.date': -1 } }))
|
|
6
|
-
.filter(Boolean)
|
|
7
|
-
.map((file) => ({
|
|
8
|
-
filename: `${quotation.quotationNumber}_${file.name}`,
|
|
9
|
-
path: file.url,
|
|
10
|
-
}));
|
|
11
5
|
const subject = `${EMAIL_WEBSITE_NAME}: Updated Quotation / ${quotation.quotationNumber}`;
|
|
12
6
|
const url = `${EMAIL_WEBSITE_URL}/quotation?_id=${quotation._id}`;
|
|
13
7
|
const text = `
|
|
@@ -27,7 +21,6 @@ export const resolveQuotationStatusTemplate = async ({ quotationId }, { modules
|
|
|
27
21
|
to: modules.users.primaryEmail(user)?.address,
|
|
28
22
|
subject,
|
|
29
23
|
text,
|
|
30
|
-
attachments,
|
|
31
24
|
},
|
|
32
25
|
},
|
|
33
26
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/platform",
|
|
3
|
-
"
|
|
3
|
+
"description": "Complete e-commerce platform bundle for the Unchained Engine",
|
|
4
|
+
"version": "4.6.1",
|
|
4
5
|
"main": "lib/platform-index.js",
|
|
5
6
|
"types": "lib/platform-index.d.ts",
|
|
6
7
|
"type": "module",
|
|
@@ -37,15 +38,15 @@
|
|
|
37
38
|
"npm": ">=10.0.0"
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {
|
|
40
|
-
"@unchainedshop/api": "^4.
|
|
41
|
-
"@unchainedshop/core": "^4.
|
|
42
|
-
"@unchainedshop/events": "^4.
|
|
43
|
-
"@unchainedshop/file-upload": "^4.
|
|
44
|
-
"@unchainedshop/logger": "^4.
|
|
45
|
-
"@unchainedshop/mongodb": "^4.
|
|
46
|
-
"@unchainedshop/plugins": "^4.
|
|
47
|
-
"@unchainedshop/roles": "^4.
|
|
48
|
-
"@unchainedshop/utils": "^4.
|
|
41
|
+
"@unchainedshop/api": "^4.6.0",
|
|
42
|
+
"@unchainedshop/core": "^4.6.0",
|
|
43
|
+
"@unchainedshop/events": "^4.6.0",
|
|
44
|
+
"@unchainedshop/file-upload": "^4.6.0",
|
|
45
|
+
"@unchainedshop/logger": "^4.6.0",
|
|
46
|
+
"@unchainedshop/mongodb": "^4.6.0",
|
|
47
|
+
"@unchainedshop/plugins": "^4.6.0",
|
|
48
|
+
"@unchainedshop/roles": "^4.6.0",
|
|
49
|
+
"@unchainedshop/utils": "^4.6.0",
|
|
49
50
|
"safe-stable-stringify": "^2.5.0"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|