@ossy/platform 1.38.7 → 1.39.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/package.json +12 -10
- package/src/Definition.js +1 -7
- package/src/locale.js +90 -0
- package/src/runtime.js +7 -2
- package/src/server.js +7 -0
- package/src/test/jest.setup.js +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/platform",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.39.0",
|
|
4
4
|
"description": "Ossy application server runtime",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,8 +22,10 @@
|
|
|
22
22
|
"./definition": "./src/Definition.js",
|
|
23
23
|
"./integrations": "./src/integration.service.js",
|
|
24
24
|
"./test": "./src/test/index.js",
|
|
25
|
+
"./test/jest.setup.js": "./src/test/jest.setup.js",
|
|
25
26
|
"./test/e2e-runner.js": "./src/test/e2e-runner.js",
|
|
26
|
-
"./test/playwright.config.js": "./src/test/playwright.config.js"
|
|
27
|
+
"./test/playwright.config.js": "./src/test/playwright.config.js",
|
|
28
|
+
"./locale": "./src/locale.js"
|
|
27
29
|
},
|
|
28
30
|
"scripts": {
|
|
29
31
|
"start": "PORT=3003 node -e \"import('./src/server.js').then(m => m.startServer())\"",
|
|
@@ -38,13 +40,13 @@
|
|
|
38
40
|
"@aws-sdk/s3-request-presigner": "^3.1057.0",
|
|
39
41
|
"@aws-sdk/util-create-request": "^3.972.26",
|
|
40
42
|
"@aws-sdk/util-format-url": "^3.972.17",
|
|
41
|
-
"@ossy/event-store": "^1.
|
|
42
|
-
"@ossy/
|
|
43
|
-
"@ossy/
|
|
44
|
-
"@ossy/
|
|
45
|
-
"@ossy/sdk": "^1.
|
|
46
|
-
"@ossy/tokens": "^1.
|
|
47
|
-
"@ossy/users": "^1.
|
|
43
|
+
"@ossy/event-store": "^1.8.0",
|
|
44
|
+
"@ossy/locale": "^1.40.0",
|
|
45
|
+
"@ossy/observability": "^1.8.0",
|
|
46
|
+
"@ossy/policies": "^1.13.0",
|
|
47
|
+
"@ossy/sdk": "^1.40.0",
|
|
48
|
+
"@ossy/tokens": "^1.13.0",
|
|
49
|
+
"@ossy/users": "^1.13.0",
|
|
48
50
|
"cookie-parser": "^1.4.7",
|
|
49
51
|
"dotenv": ">=16.0.0 <18.0.0",
|
|
50
52
|
"express": ">=5.0.0 <6.0.0",
|
|
@@ -62,5 +64,5 @@
|
|
|
62
64
|
"src",
|
|
63
65
|
"Dockerfile"
|
|
64
66
|
],
|
|
65
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "d9d31182be64a448d575da432af2830d909ad4b9"
|
|
66
68
|
}
|
package/src/Definition.js
CHANGED
|
@@ -2,12 +2,6 @@ export const Definition = {
|
|
|
2
2
|
id: 'platform',
|
|
3
3
|
title: 'Platform',
|
|
4
4
|
description: 'Deployment platform configuration aligned with deployment-tools S3 platform-config.json.',
|
|
5
|
-
|
|
6
|
-
id: 'platform',
|
|
7
|
-
enabled: true
|
|
8
|
-
},
|
|
5
|
+
icon: 'controller',
|
|
9
6
|
statuses: ['beta'],
|
|
10
|
-
actions: ['resources.create', 'resources.update-content', 'resources.rename', 'resources.remove'],
|
|
11
|
-
views: ['home.page', 'resources.search', 'resources.get'],
|
|
12
|
-
tasks: []
|
|
13
7
|
}
|
package/src/locale.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { createTranslator } from '@ossy/locale'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} buildDir
|
|
8
|
+
* @param {string} language
|
|
9
|
+
* @returns {Record<string, string>}
|
|
10
|
+
*/
|
|
11
|
+
export function loadMessagesForLanguage (buildDir, language) {
|
|
12
|
+
const filePath = path.join(buildDir, 'public', `${language}.translations.json`)
|
|
13
|
+
if (!fs.existsSync(filePath)) return {}
|
|
14
|
+
try {
|
|
15
|
+
const raw = fs.readFileSync(filePath, 'utf8')
|
|
16
|
+
const parsed = JSON.parse(raw)
|
|
17
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {}
|
|
18
|
+
} catch {
|
|
19
|
+
return {}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} buildDir
|
|
25
|
+
* @param {string} language
|
|
26
|
+
* @param {{ defaultLanguage?: string }} [config]
|
|
27
|
+
* @returns {Record<string, string> | undefined}
|
|
28
|
+
*/
|
|
29
|
+
export function loadFallbackMessagesForLanguage (buildDir, language, config = {}) {
|
|
30
|
+
const defaultLanguage = config.defaultLanguage || 'en'
|
|
31
|
+
if (language === defaultLanguage) return undefined
|
|
32
|
+
return loadMessagesForLanguage(buildDir, defaultLanguage)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {{ getParamsFromUrl: (url: string) => Record<string, string> }} pageRouter
|
|
37
|
+
* @param {string} requestUrl
|
|
38
|
+
* @param {{ defaultLanguage?: string }} config
|
|
39
|
+
* @returns {string}
|
|
40
|
+
*/
|
|
41
|
+
export function resolveRequestLanguage (pageRouter, requestUrl, config) {
|
|
42
|
+
const params = pageRouter.getParamsFromUrl(requestUrl)
|
|
43
|
+
return params.language || config.defaultLanguage || 'en'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param {{ getParamsFromUrl: (url: string) => Record<string, string> }} pageRouter
|
|
48
|
+
* @param {string} requestUrl
|
|
49
|
+
* @param {string} buildDir
|
|
50
|
+
* @param {{ defaultLanguage?: string }} config
|
|
51
|
+
* @returns {{ language: string, messages: Record<string, string>, fallbackMessages?: Record<string, string> }}
|
|
52
|
+
*/
|
|
53
|
+
export function resolveRequestLocale (pageRouter, requestUrl, buildDir, config) {
|
|
54
|
+
const language = resolveRequestLanguage(pageRouter, requestUrl, config)
|
|
55
|
+
const messages = loadMessagesForLanguage(buildDir, language)
|
|
56
|
+
const fallbackMessages = loadFallbackMessagesForLanguage(buildDir, language, config)
|
|
57
|
+
return {
|
|
58
|
+
language,
|
|
59
|
+
messages,
|
|
60
|
+
...(fallbackMessages ? { fallbackMessages } : {}),
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Server-side `t()` for actions, tasks, and email — reads merged catalogs from build output.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} buildDir Absolute path to app `build/`
|
|
68
|
+
* @param {string} [language] Active locale
|
|
69
|
+
* @param {{ defaultLanguage?: string, warnOnMissingKey?: boolean }} [config]
|
|
70
|
+
* @returns {(key: string, params?: Record<string, string | number>) => string}
|
|
71
|
+
*/
|
|
72
|
+
export function createTranslatorForBuild (buildDir, language, config = {}) {
|
|
73
|
+
const defaultLanguage = config.defaultLanguage || 'en'
|
|
74
|
+
const activeLanguage = language || defaultLanguage
|
|
75
|
+
const messages = loadMessagesForLanguage(buildDir, activeLanguage)
|
|
76
|
+
const fallbackCatalog = activeLanguage !== defaultLanguage
|
|
77
|
+
? loadMessagesForLanguage(buildDir, defaultLanguage)
|
|
78
|
+
: undefined
|
|
79
|
+
|
|
80
|
+
const warnOnMissingKey = config.warnOnMissingKey ?? process.env.NODE_ENV !== 'production'
|
|
81
|
+
const onMissingKey = warnOnMissingKey
|
|
82
|
+
? (key) => {
|
|
83
|
+
if (typeof console !== 'undefined' && typeof console.warn === 'function') {
|
|
84
|
+
console.warn(`[@ossy/locale] Missing translation key: ${key}`)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
: undefined
|
|
88
|
+
|
|
89
|
+
return createTranslator(messages, { fallbackCatalog, onMissingKey })
|
|
90
|
+
}
|
package/src/runtime.js
CHANGED
|
@@ -5,6 +5,7 @@ import cookieParser from 'cookie-parser'
|
|
|
5
5
|
import morgan from 'morgan'
|
|
6
6
|
import { Router as OssyRouter } from '@ossy/router'
|
|
7
7
|
import { loadManifest, resolveEntryUrl } from './server.js'
|
|
8
|
+
import { resolveRequestLocale } from './locale.js'
|
|
8
9
|
import { buildManifestSummary } from '@ossy/app/manifest/build-manifest-summary'
|
|
9
10
|
import { ProxyInternal } from './proxy-internal.js'
|
|
10
11
|
import { loadSite, invalidateSite } from './site-loader.js'
|
|
@@ -49,7 +50,7 @@ function buildSiteContext (manifest, buildDir) {
|
|
|
49
50
|
return promise
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
return { pageRouter, apiRouter, manifest, manifestSummary: buildManifestSummary(manifest), loadEntry }
|
|
53
|
+
return { pageRouter, apiRouter, manifest, manifestSummary: buildManifestSummary(manifest), loadEntry, buildDir }
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
async function getSiteContext (domain) {
|
|
@@ -128,7 +129,7 @@ export async function startRuntime ({ port } = {}) {
|
|
|
128
129
|
return
|
|
129
130
|
}
|
|
130
131
|
|
|
131
|
-
const { pageRouter, apiRouter, manifest, manifestSummary, loadEntry } = context
|
|
132
|
+
const { pageRouter, apiRouter, manifest, manifestSummary, loadEntry, buildDir } = context
|
|
132
133
|
|
|
133
134
|
try {
|
|
134
135
|
const apiRoute = apiRouter.getPageByUrl(requestUrl)
|
|
@@ -167,6 +168,7 @@ export async function startRuntime ({ port } = {}) {
|
|
|
167
168
|
}
|
|
168
169
|
|
|
169
170
|
const config = manifest.config
|
|
171
|
+
const { language, messages, fallbackMessages } = resolveRequestLocale(pageRouter, requestUrl, buildDir, config)
|
|
170
172
|
const props = {
|
|
171
173
|
...config,
|
|
172
174
|
...(req.userAppSettings || {}),
|
|
@@ -176,6 +178,9 @@ export async function startRuntime ({ port } = {}) {
|
|
|
176
178
|
manifestSummary: cloneSerializable(manifestSummary),
|
|
177
179
|
url: requestUrl,
|
|
178
180
|
isAuthenticated: !!req.isAuthenticated,
|
|
181
|
+
language,
|
|
182
|
+
messages: cloneSerializable(messages),
|
|
183
|
+
...(fallbackMessages ? { fallbackMessages: cloneSerializable(fallbackMessages) } : {}),
|
|
179
184
|
pages: manifest.pages.map((page) => ({
|
|
180
185
|
id: page.id,
|
|
181
186
|
path: page.path,
|
package/src/server.js
CHANGED
|
@@ -19,6 +19,7 @@ import { createLogger } from '@ossy/observability'
|
|
|
19
19
|
import { ConfigService } from './config.service.js'
|
|
20
20
|
import { UsersMiddleware } from './users.middleware.js'
|
|
21
21
|
import { WorkspacesMiddleware } from './workspaces.middleware.js'
|
|
22
|
+
import { resolveRequestLocale } from './locale.js'
|
|
22
23
|
const log = createLogger('@ossy/platform')
|
|
23
24
|
|
|
24
25
|
const DEFAULT_PORT = 3000
|
|
@@ -82,6 +83,8 @@ export function loadManifest (buildDir) {
|
|
|
82
83
|
emails,
|
|
83
84
|
layouts,
|
|
84
85
|
config: manifest.config || {},
|
|
86
|
+
definitions: manifest.definitions || {},
|
|
87
|
+
translations: manifest.translations || {},
|
|
85
88
|
}
|
|
86
89
|
}
|
|
87
90
|
|
|
@@ -322,6 +325,7 @@ export async function startServer (options = {}) {
|
|
|
322
325
|
}
|
|
323
326
|
const Layout = appLayout?.component ?? null
|
|
324
327
|
const layoutEntry = appLayout?.entry ?? null
|
|
328
|
+
const { language, messages, fallbackMessages } = resolveRequestLocale(pageRouter, requestUrl, buildDir, config)
|
|
325
329
|
// Page component → `shell:content` is resolved in page-runtime (SSR + hydrate).
|
|
326
330
|
const props = {
|
|
327
331
|
...config,
|
|
@@ -332,6 +336,9 @@ export async function startServer (options = {}) {
|
|
|
332
336
|
manifestSummary: cloneSerializable(manifestSummary),
|
|
333
337
|
url: requestUrl,
|
|
334
338
|
isAuthenticated: !!req.isAuthenticated,
|
|
339
|
+
language,
|
|
340
|
+
messages: cloneSerializable(messages),
|
|
341
|
+
...(fallbackMessages ? { fallbackMessages: cloneSerializable(fallbackMessages) } : {}),
|
|
335
342
|
pages: manifest.pages.map((page) => ({
|
|
336
343
|
id: page.id,
|
|
337
344
|
path: page.path,
|
package/src/test/jest.setup.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { TestUtil } from './test.util.js'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Integration tests run in Node on the host. Mongo in Docker is often a single-node replica set
|
|
3
5
|
* whose persisted config advertises a hostname that only resolves inside Docker (e.g.
|
|
@@ -22,3 +24,7 @@ function jestMongoUrl() {
|
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
process.env.DB_URL = jestMongoUrl()
|
|
27
|
+
|
|
28
|
+
afterAll(async () => {
|
|
29
|
+
await TestUtil.CloseDbConnection()
|
|
30
|
+
})
|