@unchainedshop/platform 3.0.0 → 3.1.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/lib/context/withAccessToken.d.ts +4 -0
- package/lib/context/withAccessToken.d.ts.map +1 -0
- package/lib/context/withAccessToken.js +42 -0
- package/lib/context/withAccessToken.js.map +1 -0
- package/lib/migrations/runMigrations.js +3 -3
- package/lib/migrations/runMigrations.js.map +1 -1
- package/lib/platform-index.d.ts +1 -0
- package/lib/platform-index.d.ts.map +1 -1
- package/lib/platform-index.js +11 -0
- package/lib/platform-index.js.map +1 -1
- package/lib/startPlatform.d.ts +1 -1
- package/lib/startPlatform.d.ts.map +1 -1
- package/lib/startPlatform.js +6 -9
- package/lib/startPlatform.js.map +1 -1
- package/lib/templates/order-parser/formatAddress.d.ts +3 -0
- package/lib/templates/order-parser/formatAddress.d.ts.map +1 -0
- package/lib/templates/order-parser/formatAddress.js +14 -0
- package/lib/templates/order-parser/formatAddress.js.map +1 -0
- package/lib/templates/order-parser/formatPrice.d.ts +6 -0
- package/lib/templates/order-parser/formatPrice.d.ts.map +1 -0
- package/lib/templates/order-parser/formatPrice.js +6 -0
- package/lib/templates/order-parser/formatPrice.js.map +1 -0
- package/package.json +11 -11
- package/src/migrations/runMigrations.ts +3 -3
- package/src/platform-index.ts +15 -0
- package/src/startPlatform.ts +8 -12
|
@@ -0,0 +1 @@
|
|
|
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,wBAmCE"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
try {
|
|
21
|
+
if (timingSafeEqual(Buffer.from(secret), Buffer.from(user?.services.token?.secret))) {
|
|
22
|
+
newContext.userId = user._id;
|
|
23
|
+
newContext.user = user;
|
|
24
|
+
logger.debug('Token login success');
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
throw new Error('Access Token not valid');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
logger.warn(`Token login failed: ${e.message}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return fn({
|
|
37
|
+
...unchainedContext,
|
|
38
|
+
...newContext,
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=withAccessToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withAccessToken.js","sourceRoot":"","sources":["../../src/context/withAccessToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEzC,MAAM,MAAM,GAAG,YAAY,CAAC,oBAAoB,CAAC,C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qBAAqB,CAAC,CAAC;wBACtC,CAAC;6BAAM,CAAC;4BACN,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;wBAC5C,CAAC;oBACH,CAAC;oBAAC,OAAO,CAAC,EAAE,CAAC;wBACX,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;oBAClD,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,EAAE,CAAC;YACR,GAAG,gBAAgB;YACnB,GAAG,UAAU;SACd,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -6,7 +6,7 @@ export const runMigrations = async ({ migrationRepository, logger = createLogger
|
|
|
6
6
|
const findCurrentId = async () => {
|
|
7
7
|
const last = await LastMigration.findOne({ category: 'unchained' }, { sort: { _id: -1 } });
|
|
8
8
|
const id = last ? last._id : 0;
|
|
9
|
-
logger.
|
|
9
|
+
logger.debug(`Most recent migration id: ${id}`);
|
|
10
10
|
return id;
|
|
11
11
|
};
|
|
12
12
|
const onMigrationComplete = async (id, action) => {
|
|
@@ -37,11 +37,11 @@ export const runMigrations = async ({ migrationRepository, logger = createLogger
|
|
|
37
37
|
logger.info(`All ${operationCount} migrations completed with most recent id: ${lastMigrationId}`);
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
|
-
logger.
|
|
40
|
+
logger.debug(`No migrations run, already at latest id: ${currentId}`);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
|
-
logger.
|
|
44
|
+
logger.warn(`Some migrations failed, last successful id: ${lastMigrationId}`);
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
//# sourceMappingURL=runMigrations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runMigrations.js","sourceRoot":"","sources":["../../src/migrations/runMigrations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;A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AAS,EAAE,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,IAAI,CAAC,+CAA+C,eAAe,EAAE,CAAC,CAAC;IAChF,CAAC;AACH,CAAC,CAAC"}
|
package/lib/platform-index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export * from './startPlatform.js';
|
|
|
2
2
|
export * from './context/index.js';
|
|
3
3
|
export * from './bulk-importer/createBulkImporter.js';
|
|
4
4
|
export * from './templates/index.js';
|
|
5
|
+
export declare const printRuntimeConfiguration: () => void;
|
|
5
6
|
//# sourceMappingURL=platform-index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-index.d.ts","sourceRoot":"","sources":["../src/platform-index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uCAAuC,CAAC;AACtD,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"platform-index.d.ts","sourceRoot":"","sources":["../src/platform-index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uCAAuC,CAAC;AACtD,cAAc,sBAAsB,CAAC;AAMrC,eAAO,MAAM,yBAAyB,YASrC,CAAC"}
|
package/lib/platform-index.js
CHANGED
|
@@ -2,4 +2,15 @@ export * from './startPlatform.js';
|
|
|
2
2
|
export * from './context/index.js';
|
|
3
3
|
export * from './bulk-importer/createBulkImporter.js';
|
|
4
4
|
export * from './templates/index.js';
|
|
5
|
+
import { MessagingDirector, getAllAdapters } from '@unchainedshop/core';
|
|
6
|
+
import { getRegisteredEvents } from '@unchainedshop/events';
|
|
7
|
+
import { log } from '@unchainedshop/logger';
|
|
8
|
+
export const printRuntimeConfiguration = () => {
|
|
9
|
+
const messaging = MessagingDirector.getRegisteredTemplates();
|
|
10
|
+
log(`Messaging Templates: ${messaging.length}`, { messaging });
|
|
11
|
+
const events = getRegisteredEvents();
|
|
12
|
+
log(`Events: ${events.length}`, { events });
|
|
13
|
+
const adapters = getAllAdapters().map((adapter) => adapter.asString());
|
|
14
|
+
log(`Adapters: ${adapters.length}`, { adapters });
|
|
15
|
+
};
|
|
5
16
|
//# sourceMappingURL=platform-index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-index.js","sourceRoot":"","sources":["../src/platform-index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uCAAuC,CAAC;AACtD,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"platform-index.js","sourceRoot":"","sources":["../src/platform-index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uCAAuC,CAAC;AACtD,cAAc,sBAAsB,CAAC;AAErC,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAE5C,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,EAAE;IAC5C,MAAM,SAAS,GAAG,iBAAiB,CAAC,sBAAsB,EAAE,CAAC;IAC7D,GAAG,CAAC,wBAAwB,SAAS,CAAC,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;IAE/D,MAAM,MAAM,GAAG,mBAAmB,EAAE,CAAC;IACrC,GAAG,CAAC,WAAW,MAAM,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAE5C,MAAM,QAAQ,GAAG,cAAc,EAAE,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IACvE,GAAG,CAAC,aAAa,QAAQ,CAAC,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;AACpD,CAAC,CAAC"}
|
package/lib/startPlatform.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type PlatformOptions = {
|
|
|
16
16
|
workQueueOptions?: SetupWorkqueueOptions & SetupCartsOptions & {
|
|
17
17
|
skipInvalidationOnStartup?: boolean;
|
|
18
18
|
};
|
|
19
|
-
} & Omit<UnchainedCoreOptions, 'bulkImporter' | 'migrationRepository' | 'db'> & Omit<UnchainedServerOptions, 'roles' | 'unchainedAPI'
|
|
19
|
+
} & Omit<UnchainedCoreOptions, 'bulkImporter' | 'migrationRepository' | 'db'> & Omit<UnchainedServerOptions, 'roles' | 'unchainedAPI'>;
|
|
20
20
|
export declare const queueWorkers: Array<any>;
|
|
21
21
|
export declare const startPlatform: ({ modules, services, options, rolesOptions, bulkImporter: bulkImporterOptions, workQueueOptions, ...arbitraryAPIServerConfiguration }: PlatformOptions) => Promise<{
|
|
22
22
|
unchainedAPI: UnchainedCore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startPlatform.d.ts","sourceRoot":"","sources":["../src/startPlatform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,EAAY,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAU,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"startPlatform.d.ts","sourceRoot":"","sources":["../src/startPlatform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,EAAY,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAU,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAA6B,MAAM,uCAAuC,CAAC;AAIrG,OAAO,EAAE,iBAAiB,EAAc,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAkB,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAkB,MAAM,2BAA2B,CAAC;AAElF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,CAAC,EAAE;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;KAC9C,CAAC;IACF,YAAY,CAAC,EAAE,iBAAiB,CAAC;IACjC,gBAAgB,CAAC,EAAE,qBAAqB,GAAG,iBAAiB,GAAG;QAAE,yBAAyB,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CACxG,GAAG,IAAI,CAAC,oBAAoB,EAAE,cAAc,GAAG,qBAAqB,GAAG,IAAI,CAAC,GAC3E,IAAI,CAAC,sBAAsB,EAAE,OAAO,GAAG,cAAc,CAAC,CAAC;AAyBzD,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,GAAG,CAAM,CAAC;AAE3C,eAAO,MAAM,aAAa,0IAQvB,eAAe,KAAG,OAAO,CAAC;IAC3B,YAAY,EAAE,aAAa,CAAC;IAC5B,cAAc,EAAE,GAAG,CAAC;IACpB,EAAE,EAAE,OAAO,CAAC,EAAE,CAAC;CAChB,CA8DA,CAAC"}
|
package/lib/startPlatform.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { startAPIServer, roles } from '@unchainedshop/api';
|
|
2
2
|
import { initCore } from '@unchainedshop/core';
|
|
3
3
|
import { initDb } from '@unchainedshop/mongodb';
|
|
4
|
-
import {
|
|
5
|
-
import { getRegisteredEvents } from '@unchainedshop/events';
|
|
6
|
-
import { WorkerDirector } from '@unchainedshop/core';
|
|
4
|
+
import { defaultLogger } from '@unchainedshop/logger';
|
|
7
5
|
import { createBulkImporterFactory } from './bulk-importer/createBulkImporter.js';
|
|
8
6
|
import { runMigrations } from './migrations/runMigrations.js';
|
|
9
7
|
import { setupAccounts } from './setup/setupAccounts.js';
|
|
@@ -13,7 +11,6 @@ import { setupTemplates, MessageTypes } from './setup/setupTemplates.js';
|
|
|
13
11
|
import { setupWorkqueue } from './setup/setupWorkqueue.js';
|
|
14
12
|
import { createMigrationRepository } from './migrations/migrationRepository.js';
|
|
15
13
|
export { MessageTypes };
|
|
16
|
-
const logger = createLogger('unchained');
|
|
17
14
|
const REQUIRED_ENV_VARIABLES = [
|
|
18
15
|
'EMAIL_WEBSITE_NAME',
|
|
19
16
|
'EMAIL_WEBSITE_URL',
|
|
@@ -25,7 +22,7 @@ const { UNCHAINED_DISABLE_WORKER } = process.env;
|
|
|
25
22
|
const exitOnMissingEnvironmentVariables = () => {
|
|
26
23
|
const failedEnv = REQUIRED_ENV_VARIABLES.filter((key) => !process.env[key]);
|
|
27
24
|
if (failedEnv.length > 0) {
|
|
28
|
-
|
|
25
|
+
defaultLogger.error(`Missing required environment variables at boot time: ${failedEnv.join(', ')}`);
|
|
29
26
|
process.exit(1);
|
|
30
27
|
}
|
|
31
28
|
};
|
|
@@ -56,8 +53,6 @@ export const startPlatform = async ({ modules, services, options, rolesOptions =
|
|
|
56
53
|
if (isWorkQueueEnabled) {
|
|
57
54
|
await runMigrations({ migrationRepository, unchainedAPI });
|
|
58
55
|
}
|
|
59
|
-
const configuredEvents = getRegisteredEvents();
|
|
60
|
-
const configuredWorkTypes = WorkerDirector.getActivePluginTypes();
|
|
61
56
|
// Setup accountsjs specific extensions and event handlers
|
|
62
57
|
setupAccounts(unchainedAPI);
|
|
63
58
|
// Setup email templates
|
|
@@ -68,8 +63,6 @@ export const startPlatform = async ({ modules, services, options, rolesOptions =
|
|
|
68
63
|
const graphqlHandler = await startAPIServer({
|
|
69
64
|
unchainedAPI,
|
|
70
65
|
roles: configuredRoles,
|
|
71
|
-
events: configuredEvents,
|
|
72
|
-
workTypes: configuredWorkTypes,
|
|
73
66
|
...arbitraryAPIServerConfiguration,
|
|
74
67
|
});
|
|
75
68
|
// Setup work queues for scheduled work
|
|
@@ -82,6 +75,10 @@ export const startPlatform = async ({ modules, services, options, rolesOptions =
|
|
|
82
75
|
if (!workQueueOptions?.skipInvalidationOnStartup) {
|
|
83
76
|
setImmediate(() => unchainedAPI.services.filters.invalidateFilterCache());
|
|
84
77
|
}
|
|
78
|
+
const { default: packageJson } = await import(`${import.meta.dirname}/../package.json`, {
|
|
79
|
+
with: { type: 'json' },
|
|
80
|
+
});
|
|
81
|
+
defaultLogger.info(`Unchained Engine running`, { version: packageJson.version });
|
|
85
82
|
return { unchainedAPI, graphqlHandler, db };
|
|
86
83
|
};
|
|
87
84
|
//# sourceMappingURL=startPlatform.js.map
|
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,EAAE,KAAK,EAA0B,MAAM,oBAAoB,CAAC;AACnF,OAAO,EAAE,QAAQ,EAAwB,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,MAAM,EAAW,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"startPlatform.js","sourceRoot":"","sources":["../src/startPlatform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,EAA0B,MAAM,oBAAoB,CAAC;AACnF,OAAO,EAAE,QAAQ,EAAwB,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,MAAM,EAAW,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EAAqB,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AACrG,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YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QAC1D,MAAM,UAAU,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;IACnD,CAAC;IAED,qBAAqB;IACrB,IAAI,CAAC,gBAAgB,EAAE,yBAAyB,EAAE,CAAC;QACjD,YAAY,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,MAAM,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,kBAAkB,EAAE;QACtF,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;KACvB,CAAC,CAAC;IACH,aAAa,CAAC,IAAI,CAAC,0BAA0B,EAAE,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC;IAEjF,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC;AAC9C,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatAddress.d.ts","sourceRoot":"","sources":["../../../src/templates/order-parser/formatAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAEzD,eAAO,MAAM,aAAa,YAAa,OAAO,WAY7C,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const formatAddress = (address) => {
|
|
2
|
+
return [
|
|
3
|
+
[address.firstName, address.lastName].filter(Boolean).join(' '),
|
|
4
|
+
address.company,
|
|
5
|
+
address.addressLine,
|
|
6
|
+
address.addressLine2,
|
|
7
|
+
[address.postalCode, address.city].filter(Boolean).join(' '),
|
|
8
|
+
address.regionCode,
|
|
9
|
+
[address.countryCode].filter(Boolean).join(''),
|
|
10
|
+
]
|
|
11
|
+
.filter(Boolean)
|
|
12
|
+
.join('\n');
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=formatAddress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatAddress.js","sourceRoot":"","sources":["../../../src/templates/order-parser/formatAddress.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAgB,EAAE,EAAE;IAChD,OAAO;QACL,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAC/D,OAAO,CAAC,OAAO;QACf,OAAO,CAAC,WAAW;QACnB,OAAO,CAAC,YAAY;QACpB,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAC5D,OAAO,CAAC,UAAU;QAClB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;KAC/C;SACE,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatPrice.d.ts","sourceRoot":"","sources":["../../../src/templates/order-parser/formatPrice.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,yBAA0B;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,WAGrF,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatPrice.js","sourceRoot":"","sources":["../../../src/templates/order-parser/formatPrice.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAwC,EAAE,EAAE;IACxF,MAAM,UAAU,GAAG,MAAM,GAAG,GAAG,CAAC;IAChC,OAAO,GAAG,QAAQ,IAAI,UAAU,EAAE,CAAC;AACrC,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/platform",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"main": "lib/platform-index.js",
|
|
5
5
|
"types": "lib/platform-index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -34,21 +34,21 @@
|
|
|
34
34
|
"node": ">=22.0.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@unchainedshop/api": "^3.
|
|
38
|
-
"@unchainedshop/core": "^3.
|
|
39
|
-
"@unchainedshop/events": "^3.
|
|
40
|
-
"@unchainedshop/file-upload": "^3.
|
|
41
|
-
"@unchainedshop/logger": "^3.
|
|
42
|
-
"@unchainedshop/mongodb": "^3.
|
|
43
|
-
"@unchainedshop/plugins": "^3.
|
|
44
|
-
"@unchainedshop/roles": "^3.
|
|
45
|
-
"@unchainedshop/utils": "^3.
|
|
37
|
+
"@unchainedshop/api": "^3.1.0",
|
|
38
|
+
"@unchainedshop/core": "^3.1.0",
|
|
39
|
+
"@unchainedshop/events": "^3.1.0",
|
|
40
|
+
"@unchainedshop/file-upload": "^3.1.0",
|
|
41
|
+
"@unchainedshop/logger": "^3.1.0",
|
|
42
|
+
"@unchainedshop/mongodb": "^3.1.0",
|
|
43
|
+
"@unchainedshop/plugins": "^3.1.0",
|
|
44
|
+
"@unchainedshop/roles": "^3.1.0",
|
|
45
|
+
"@unchainedshop/utils": "^3.1.0",
|
|
46
46
|
"mustache": "^4.2.0",
|
|
47
47
|
"safe-stable-stringify": "^2.5.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/mustache": "^4.2.5",
|
|
51
|
-
"@types/node": "^22.
|
|
51
|
+
"@types/node": "^22.13.1",
|
|
52
52
|
"jest": "^29.7.0",
|
|
53
53
|
"ts-jest": "^29.2.5",
|
|
54
54
|
"typescript": "^5.7.3"
|
|
@@ -17,7 +17,7 @@ export const runMigrations = async ({
|
|
|
17
17
|
const findCurrentId = async () => {
|
|
18
18
|
const last = await LastMigration.findOne({ category: 'unchained' }, { sort: { _id: -1 } });
|
|
19
19
|
const id = last ? last._id : 0;
|
|
20
|
-
logger.
|
|
20
|
+
logger.debug(`Most recent migration id: ${id}`);
|
|
21
21
|
return id;
|
|
22
22
|
};
|
|
23
23
|
|
|
@@ -55,9 +55,9 @@ export const runMigrations = async ({
|
|
|
55
55
|
if (operationCount > 0) {
|
|
56
56
|
logger.info(`All ${operationCount} migrations completed with most recent id: ${lastMigrationId}`);
|
|
57
57
|
} else {
|
|
58
|
-
logger.
|
|
58
|
+
logger.debug(`No migrations run, already at latest id: ${currentId}`);
|
|
59
59
|
}
|
|
60
60
|
} else {
|
|
61
|
-
logger.
|
|
61
|
+
logger.warn(`Some migrations failed, last successful id: ${lastMigrationId}`);
|
|
62
62
|
}
|
|
63
63
|
};
|
package/src/platform-index.ts
CHANGED
|
@@ -2,3 +2,18 @@ export * from './startPlatform.js';
|
|
|
2
2
|
export * from './context/index.js';
|
|
3
3
|
export * from './bulk-importer/createBulkImporter.js';
|
|
4
4
|
export * from './templates/index.js';
|
|
5
|
+
|
|
6
|
+
import { MessagingDirector, getAllAdapters } from '@unchainedshop/core';
|
|
7
|
+
import { getRegisteredEvents } from '@unchainedshop/events';
|
|
8
|
+
import { log } from '@unchainedshop/logger';
|
|
9
|
+
|
|
10
|
+
export const printRuntimeConfiguration = () => {
|
|
11
|
+
const messaging = MessagingDirector.getRegisteredTemplates();
|
|
12
|
+
log(`Messaging Templates: ${messaging.length}`, { messaging });
|
|
13
|
+
|
|
14
|
+
const events = getRegisteredEvents();
|
|
15
|
+
log(`Events: ${events.length}`, { events });
|
|
16
|
+
|
|
17
|
+
const adapters = getAllAdapters().map((adapter) => adapter.asString());
|
|
18
|
+
log(`Adapters: ${adapters.length}`, { adapters });
|
|
19
|
+
};
|
package/src/startPlatform.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { startAPIServer, roles, UnchainedServerOptions } from '@unchainedshop/api';
|
|
2
2
|
import { initCore, UnchainedCoreOptions } from '@unchainedshop/core';
|
|
3
3
|
import { initDb, mongodb } from '@unchainedshop/mongodb';
|
|
4
|
-
import {
|
|
4
|
+
import { defaultLogger } from '@unchainedshop/logger';
|
|
5
5
|
import { UnchainedCore } from '@unchainedshop/core';
|
|
6
|
-
import { getRegisteredEvents } from '@unchainedshop/events';
|
|
7
|
-
import { WorkerDirector } from '@unchainedshop/core';
|
|
8
6
|
import { BulkImportHandler, createBulkImporterFactory } from './bulk-importer/createBulkImporter.js';
|
|
9
7
|
import { runMigrations } from './migrations/runMigrations.js';
|
|
10
8
|
import { setupAccounts } from './setup/setupAccounts.js';
|
|
@@ -24,9 +22,7 @@ export type PlatformOptions = {
|
|
|
24
22
|
rolesOptions?: IRoleOptionConfig;
|
|
25
23
|
workQueueOptions?: SetupWorkqueueOptions & SetupCartsOptions & { skipInvalidationOnStartup?: boolean };
|
|
26
24
|
} & Omit<UnchainedCoreOptions, 'bulkImporter' | 'migrationRepository' | 'db'> &
|
|
27
|
-
Omit<UnchainedServerOptions, 'roles' | 'unchainedAPI'
|
|
28
|
-
|
|
29
|
-
const logger = createLogger('unchained');
|
|
25
|
+
Omit<UnchainedServerOptions, 'roles' | 'unchainedAPI'>;
|
|
30
26
|
|
|
31
27
|
const REQUIRED_ENV_VARIABLES = [
|
|
32
28
|
'EMAIL_WEBSITE_NAME',
|
|
@@ -41,7 +37,7 @@ const { UNCHAINED_DISABLE_WORKER } = process.env;
|
|
|
41
37
|
const exitOnMissingEnvironmentVariables = () => {
|
|
42
38
|
const failedEnv = REQUIRED_ENV_VARIABLES.filter((key) => !process.env[key]);
|
|
43
39
|
if (failedEnv.length > 0) {
|
|
44
|
-
|
|
40
|
+
defaultLogger.error(`Missing required environment variables at boot time: ${failedEnv.join(', ')}`);
|
|
45
41
|
process.exit(1);
|
|
46
42
|
}
|
|
47
43
|
};
|
|
@@ -93,9 +89,6 @@ export const startPlatform = async ({
|
|
|
93
89
|
await runMigrations({ migrationRepository, unchainedAPI });
|
|
94
90
|
}
|
|
95
91
|
|
|
96
|
-
const configuredEvents = getRegisteredEvents();
|
|
97
|
-
const configuredWorkTypes = WorkerDirector.getActivePluginTypes();
|
|
98
|
-
|
|
99
92
|
// Setup accountsjs specific extensions and event handlers
|
|
100
93
|
setupAccounts(unchainedAPI);
|
|
101
94
|
|
|
@@ -109,8 +102,6 @@ export const startPlatform = async ({
|
|
|
109
102
|
const graphqlHandler = await startAPIServer({
|
|
110
103
|
unchainedAPI,
|
|
111
104
|
roles: configuredRoles,
|
|
112
|
-
events: configuredEvents,
|
|
113
|
-
workTypes: configuredWorkTypes,
|
|
114
105
|
...arbitraryAPIServerConfiguration,
|
|
115
106
|
});
|
|
116
107
|
|
|
@@ -126,5 +117,10 @@ export const startPlatform = async ({
|
|
|
126
117
|
setImmediate(() => unchainedAPI.services.filters.invalidateFilterCache());
|
|
127
118
|
}
|
|
128
119
|
|
|
120
|
+
const { default: packageJson } = await import(`${import.meta.dirname}/../package.json`, {
|
|
121
|
+
with: { type: 'json' },
|
|
122
|
+
});
|
|
123
|
+
defaultLogger.info(`Unchained Engine running`, { version: packageJson.version });
|
|
124
|
+
|
|
129
125
|
return { unchainedAPI, graphqlHandler, db };
|
|
130
126
|
};
|