gt-node 1.0.7 → 1.0.9
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/CHANGELOG.md +14 -0
- package/dist/index.cjs +21 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +21 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# gt-node
|
|
2
2
|
|
|
3
|
+
## 1.0.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`bbf4eb0`](https://github.com/generaltranslation/gt/commit/bbf4eb0cf77160baa615776619acd7afe35697ba), [`f53bb5e`](https://github.com/generaltranslation/gt/commit/f53bb5ea4b4989a2a4ad3aebf464011f01e029ad)]:
|
|
8
|
+
- generaltranslation@9.0.4
|
|
9
|
+
- gt-i18n@1.0.8
|
|
10
|
+
|
|
11
|
+
## 1.0.8
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#1923](https://github.com/generaltranslation/gt/pull/1923) [`1ae3e65`](https://github.com/generaltranslation/gt/commit/1ae3e657f6e72f6fffa9bd5118c4c6aab2439846) Thanks [@JoshKappler](https://github.com/JoshKappler)! - `initializeGT()` now reads `GT_PROJECT_ID`, `GT_API_KEY`, and `GT_DEV_API_KEY` from the environment as a fallback when they are not passed explicitly, matching the gt-node quickstart which sets these in `.env`. Explicit params still take precedence.
|
|
16
|
+
|
|
3
17
|
## 1.0.7
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,24 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_AsyncConditionStore = require("./AsyncConditionStore-BzUMXkfg.cjs");
|
|
3
3
|
let gt_i18n_internal = require("gt-i18n/internal");
|
|
4
4
|
let gt_i18n = require("gt-i18n");
|
|
5
|
+
//#region src/setup/runtimeCredentials.ts
|
|
6
|
+
function addRuntimeCredentials(config) {
|
|
7
|
+
const credentials = getRuntimeCredentials();
|
|
8
|
+
return {
|
|
9
|
+
...config,
|
|
10
|
+
projectId: config.projectId || credentials.projectId,
|
|
11
|
+
apiKey: config.apiKey || credentials.apiKey,
|
|
12
|
+
devApiKey: config.devApiKey || credentials.devApiKey
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function getRuntimeCredentials() {
|
|
16
|
+
return {
|
|
17
|
+
projectId: process.env.GT_PROJECT_ID,
|
|
18
|
+
apiKey: process.env.GT_API_KEY,
|
|
19
|
+
devApiKey: process.env.GT_DEV_API_KEY
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
5
23
|
//#region src/setup/initializeGT.ts
|
|
6
24
|
/**
|
|
7
25
|
* Configure GT for node runtime. This must be called to setup GT for node runtime.
|
|
@@ -9,8 +27,9 @@ let gt_i18n = require("gt-i18n");
|
|
|
9
27
|
* TODO: auto detect if can find gt.config.json files
|
|
10
28
|
*/
|
|
11
29
|
function initializeGT(params) {
|
|
12
|
-
|
|
13
|
-
|
|
30
|
+
const config = addRuntimeCredentials(params);
|
|
31
|
+
(0, gt_i18n_internal.initializeI18nConfig)(config);
|
|
32
|
+
const i18nCache = new gt_i18n_internal.I18nCache(config);
|
|
14
33
|
const conditionStore = new require_AsyncConditionStore.AsyncConditionStore();
|
|
15
34
|
(0, gt_i18n_internal.setI18nCache)(i18nCache);
|
|
16
35
|
require_AsyncConditionStore.setAsyncConditionStore(conditionStore);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["I18nCache","AsyncConditionStore","getAsyncConditionStore"],"sources":["../src/setup/initializeGT.ts","../src/setup/withGT.ts","../src/helpers/getRequestLocale.ts"],"sourcesContent":["import { setAsyncConditionStore } from '../async-i18n-cache/singleton-operations';\nimport type { InitializeGTParams } from './types';\nimport {\n I18nCache,\n initializeI18nConfig,\n setI18nCache,\n} from 'gt-i18n/internal';\nimport { AsyncConditionStore } from '../async-i18n-cache/AsyncConditionStore';\n\n/**\n * Configure GT for node runtime. This must be called to setup GT for node runtime.\n * @param {InitializeGTParams} config - The configuration for the GT instance\n * TODO: auto detect if can find gt.config.json files\n */\nexport function initializeGT(params: InitializeGTParams): void {\n
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["I18nCache","AsyncConditionStore","getAsyncConditionStore"],"sources":["../src/setup/runtimeCredentials.ts","../src/setup/initializeGT.ts","../src/setup/withGT.ts","../src/helpers/getRequestLocale.ts"],"sourcesContent":["import type { InitializeGTParams } from './types';\n\ntype RuntimeCredentials = Pick<\n InitializeGTParams,\n 'projectId' | 'apiKey' | 'devApiKey'\n>;\n\nexport function addRuntimeCredentials<T extends RuntimeCredentials>(\n config: T\n): T {\n const credentials = getRuntimeCredentials();\n return {\n ...config,\n projectId: config.projectId || credentials.projectId,\n apiKey: config.apiKey || credentials.apiKey,\n devApiKey: config.devApiKey || credentials.devApiKey,\n };\n}\n\nfunction getRuntimeCredentials(): RuntimeCredentials {\n return {\n projectId: process.env.GT_PROJECT_ID,\n apiKey: process.env.GT_API_KEY,\n devApiKey: process.env.GT_DEV_API_KEY,\n };\n}\n","import { setAsyncConditionStore } from '../async-i18n-cache/singleton-operations';\nimport type { InitializeGTParams } from './types';\nimport {\n I18nCache,\n initializeI18nConfig,\n setI18nCache,\n} from 'gt-i18n/internal';\nimport { AsyncConditionStore } from '../async-i18n-cache/AsyncConditionStore';\nimport { addRuntimeCredentials } from './runtimeCredentials';\n\n/**\n * Configure GT for node runtime. This must be called to setup GT for node runtime.\n * @param {InitializeGTParams} config - The configuration for the GT instance\n * TODO: auto detect if can find gt.config.json files\n */\nexport function initializeGT(params: InitializeGTParams): void {\n const config = addRuntimeCredentials(params);\n\n initializeI18nConfig(config);\n\n const i18nCache = new I18nCache<string>(config);\n const conditionStore = new AsyncConditionStore();\n\n setI18nCache(i18nCache);\n setAsyncConditionStore(conditionStore);\n}\n","import { getAsyncConditionStore } from '../async-i18n-cache/singleton-operations';\n\n/**\n * This function wraps entry points to provide GT context\n */\nexport function withGT<T>(locale: string, fn: () => T): T {\n return getAsyncConditionStore().run<T>(locale, fn);\n}\n","import { getI18nConfig, parseAcceptLanguage } from 'gt-i18n/internal';\n\n/**\n * A request object like interface\n * @interface RequestLike\n * @property {Record<string, string | string[] | undefined>} headers - The request headers\n */\ninterface RequestLike {\n headers: Record<string, string | string[] | undefined>;\n}\n\n/**\n * Resolve the preferred locale from the request Accept-Language header, fallback to the default locale if no match is found\n * @param request - The request object\n * @returns The preferred locale\n *\n * @example\n * const locale = getRequestLocale({ headers: { 'accept-language': 'fr-FR,fr;q=0.9,en;q=0.8' } });\n * console.log(locale); // 'fr'\n *\n * @example\n * app.get('/', (req, res) => {\n * const locale = getRequestLocale(req);\n * withGT(locale, () => {\n * res.send(`Locale: ${locale}`);\n * });\n * });\n */\nexport function getRequestLocale(request: RequestLike): string {\n // Setup\n const i18nConfig = getI18nConfig();\n\n // Get the accept-language header\n const acceptLanguage = request.headers['accept-language'];\n const preferredLocales = parseAcceptLanguage(acceptLanguage);\n return (\n i18nConfig.determineLocale(preferredLocales) ||\n i18nConfig.getDefaultLocale()\n );\n}\n"],"mappings":";;;;;AAOA,SAAgB,sBACd,QACG;CACH,MAAM,cAAc,uBAAuB;AAC3C,QAAO;EACL,GAAG;EACH,WAAW,OAAO,aAAa,YAAY;EAC3C,QAAQ,OAAO,UAAU,YAAY;EACrC,WAAW,OAAO,aAAa,YAAY;EAC5C;;AAGH,SAAS,wBAA4C;AACnD,QAAO;EACL,WAAW,QAAQ,IAAI;EACvB,QAAQ,QAAQ,IAAI;EACpB,WAAW,QAAQ,IAAI;EACxB;;;;;;;;;ACTH,SAAgB,aAAa,QAAkC;CAC7D,MAAM,SAAS,sBAAsB,OAAO;AAE5C,EAAA,GAAA,iBAAA,sBAAqB,OAAO;CAE5B,MAAM,YAAY,IAAIA,iBAAAA,UAAkB,OAAO;CAC/C,MAAM,iBAAiB,IAAIC,4BAAAA,qBAAqB;AAEhD,EAAA,GAAA,iBAAA,cAAa,UAAU;AACvB,6BAAA,uBAAuB,eAAe;;;;;;;ACnBxC,SAAgB,OAAU,QAAgB,IAAgB;AACxD,QAAOC,4BAAAA,wBAAwB,CAAC,IAAO,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;ACsBpD,SAAgB,iBAAiB,SAA8B;CAE7D,MAAM,cAAA,GAAA,iBAAA,gBAA4B;CAGlC,MAAM,iBAAiB,QAAQ,QAAQ;CACvC,MAAM,oBAAA,GAAA,iBAAA,qBAAuC,eAAe;AAC5D,QACE,WAAW,gBAAgB,iBAAiB,IAC5C,WAAW,kBAAkB"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
import { n as getAsyncConditionStore, r as setAsyncConditionStore, t as AsyncConditionStore } from "./AsyncConditionStore-Dr27x7HT.mjs";
|
|
2
2
|
import { I18nCache, getGT, getI18nConfig, getMessages, getTranslations, initializeI18nConfig, parseAcceptLanguage, setI18nCache, tx } from "gt-i18n/internal";
|
|
3
3
|
import { declareVar, decodeMsg, decodeOptions, decodeVars, derive, getDefaultLocale, getLocale, getLocaleProperties, getLocales, getVersionId, msg } from "gt-i18n";
|
|
4
|
+
//#region src/setup/runtimeCredentials.ts
|
|
5
|
+
function addRuntimeCredentials(config) {
|
|
6
|
+
const credentials = getRuntimeCredentials();
|
|
7
|
+
return {
|
|
8
|
+
...config,
|
|
9
|
+
projectId: config.projectId || credentials.projectId,
|
|
10
|
+
apiKey: config.apiKey || credentials.apiKey,
|
|
11
|
+
devApiKey: config.devApiKey || credentials.devApiKey
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function getRuntimeCredentials() {
|
|
15
|
+
return {
|
|
16
|
+
projectId: process.env.GT_PROJECT_ID,
|
|
17
|
+
apiKey: process.env.GT_API_KEY,
|
|
18
|
+
devApiKey: process.env.GT_DEV_API_KEY
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
4
22
|
//#region src/setup/initializeGT.ts
|
|
5
23
|
/**
|
|
6
24
|
* Configure GT for node runtime. This must be called to setup GT for node runtime.
|
|
@@ -8,8 +26,9 @@ import { declareVar, decodeMsg, decodeOptions, decodeVars, derive, getDefaultLoc
|
|
|
8
26
|
* TODO: auto detect if can find gt.config.json files
|
|
9
27
|
*/
|
|
10
28
|
function initializeGT(params) {
|
|
11
|
-
|
|
12
|
-
|
|
29
|
+
const config = addRuntimeCredentials(params);
|
|
30
|
+
initializeI18nConfig(config);
|
|
31
|
+
const i18nCache = new I18nCache(config);
|
|
13
32
|
const conditionStore = new AsyncConditionStore();
|
|
14
33
|
setI18nCache(i18nCache);
|
|
15
34
|
setAsyncConditionStore(conditionStore);
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/setup/initializeGT.ts","../src/setup/withGT.ts","../src/helpers/getRequestLocale.ts"],"sourcesContent":["import { setAsyncConditionStore } from '../async-i18n-cache/singleton-operations';\nimport type { InitializeGTParams } from './types';\nimport {\n I18nCache,\n initializeI18nConfig,\n setI18nCache,\n} from 'gt-i18n/internal';\nimport { AsyncConditionStore } from '../async-i18n-cache/AsyncConditionStore';\n\n/**\n * Configure GT for node runtime. This must be called to setup GT for node runtime.\n * @param {InitializeGTParams} config - The configuration for the GT instance\n * TODO: auto detect if can find gt.config.json files\n */\nexport function initializeGT(params: InitializeGTParams): void {\n
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/setup/runtimeCredentials.ts","../src/setup/initializeGT.ts","../src/setup/withGT.ts","../src/helpers/getRequestLocale.ts"],"sourcesContent":["import type { InitializeGTParams } from './types';\n\ntype RuntimeCredentials = Pick<\n InitializeGTParams,\n 'projectId' | 'apiKey' | 'devApiKey'\n>;\n\nexport function addRuntimeCredentials<T extends RuntimeCredentials>(\n config: T\n): T {\n const credentials = getRuntimeCredentials();\n return {\n ...config,\n projectId: config.projectId || credentials.projectId,\n apiKey: config.apiKey || credentials.apiKey,\n devApiKey: config.devApiKey || credentials.devApiKey,\n };\n}\n\nfunction getRuntimeCredentials(): RuntimeCredentials {\n return {\n projectId: process.env.GT_PROJECT_ID,\n apiKey: process.env.GT_API_KEY,\n devApiKey: process.env.GT_DEV_API_KEY,\n };\n}\n","import { setAsyncConditionStore } from '../async-i18n-cache/singleton-operations';\nimport type { InitializeGTParams } from './types';\nimport {\n I18nCache,\n initializeI18nConfig,\n setI18nCache,\n} from 'gt-i18n/internal';\nimport { AsyncConditionStore } from '../async-i18n-cache/AsyncConditionStore';\nimport { addRuntimeCredentials } from './runtimeCredentials';\n\n/**\n * Configure GT for node runtime. This must be called to setup GT for node runtime.\n * @param {InitializeGTParams} config - The configuration for the GT instance\n * TODO: auto detect if can find gt.config.json files\n */\nexport function initializeGT(params: InitializeGTParams): void {\n const config = addRuntimeCredentials(params);\n\n initializeI18nConfig(config);\n\n const i18nCache = new I18nCache<string>(config);\n const conditionStore = new AsyncConditionStore();\n\n setI18nCache(i18nCache);\n setAsyncConditionStore(conditionStore);\n}\n","import { getAsyncConditionStore } from '../async-i18n-cache/singleton-operations';\n\n/**\n * This function wraps entry points to provide GT context\n */\nexport function withGT<T>(locale: string, fn: () => T): T {\n return getAsyncConditionStore().run<T>(locale, fn);\n}\n","import { getI18nConfig, parseAcceptLanguage } from 'gt-i18n/internal';\n\n/**\n * A request object like interface\n * @interface RequestLike\n * @property {Record<string, string | string[] | undefined>} headers - The request headers\n */\ninterface RequestLike {\n headers: Record<string, string | string[] | undefined>;\n}\n\n/**\n * Resolve the preferred locale from the request Accept-Language header, fallback to the default locale if no match is found\n * @param request - The request object\n * @returns The preferred locale\n *\n * @example\n * const locale = getRequestLocale({ headers: { 'accept-language': 'fr-FR,fr;q=0.9,en;q=0.8' } });\n * console.log(locale); // 'fr'\n *\n * @example\n * app.get('/', (req, res) => {\n * const locale = getRequestLocale(req);\n * withGT(locale, () => {\n * res.send(`Locale: ${locale}`);\n * });\n * });\n */\nexport function getRequestLocale(request: RequestLike): string {\n // Setup\n const i18nConfig = getI18nConfig();\n\n // Get the accept-language header\n const acceptLanguage = request.headers['accept-language'];\n const preferredLocales = parseAcceptLanguage(acceptLanguage);\n return (\n i18nConfig.determineLocale(preferredLocales) ||\n i18nConfig.getDefaultLocale()\n );\n}\n"],"mappings":";;;;AAOA,SAAgB,sBACd,QACG;CACH,MAAM,cAAc,uBAAuB;AAC3C,QAAO;EACL,GAAG;EACH,WAAW,OAAO,aAAa,YAAY;EAC3C,QAAQ,OAAO,UAAU,YAAY;EACrC,WAAW,OAAO,aAAa,YAAY;EAC5C;;AAGH,SAAS,wBAA4C;AACnD,QAAO;EACL,WAAW,QAAQ,IAAI;EACvB,QAAQ,QAAQ,IAAI;EACpB,WAAW,QAAQ,IAAI;EACxB;;;;;;;;;ACTH,SAAgB,aAAa,QAAkC;CAC7D,MAAM,SAAS,sBAAsB,OAAO;AAE5C,sBAAqB,OAAO;CAE5B,MAAM,YAAY,IAAI,UAAkB,OAAO;CAC/C,MAAM,iBAAiB,IAAI,qBAAqB;AAEhD,cAAa,UAAU;AACvB,wBAAuB,eAAe;;;;;;;ACnBxC,SAAgB,OAAU,QAAgB,IAAgB;AACxD,QAAO,wBAAwB,CAAC,IAAO,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;ACsBpD,SAAgB,iBAAiB,SAA8B;CAE7D,MAAM,aAAa,eAAe;CAGlC,MAAM,iBAAiB,QAAQ,QAAQ;CACvC,MAAM,mBAAmB,oBAAoB,eAAe;AAC5D,QACE,WAAW,gBAAgB,iBAAiB,IAC5C,WAAW,kBAAkB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gt-node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Node.js utilities for General Translation",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"definition": "dist/index.d.cts"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"gt-i18n": "1.0.
|
|
48
|
-
"generaltranslation": "9.0.
|
|
47
|
+
"gt-i18n": "1.0.8",
|
|
48
|
+
"generaltranslation": "9.0.4"
|
|
49
49
|
},
|
|
50
50
|
"exports": {
|
|
51
51
|
".": {
|