lexisync 0.2.0 → 0.2.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.
- package/README.md +15 -69
- package/lib/backend.js +3 -1
- package/lib/client.js +29 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# lexisync
|
|
2
2
|
|
|
3
|
-
Official **CLI**, **i18next backend**, and HTTP client for [LexiSync](https://lexisync
|
|
3
|
+
Official **CLI**, **i18next backend**, and HTTP client for [LexiSync](https://lexisync.app) — API-first, Locize-style translation management.
|
|
4
4
|
|
|
5
|
-
[Docs](https://lexisync
|
|
5
|
+
[Docs](https://lexisync.app/docs) · [API discovery](https://lexisync.app/api/v1) · [OpenAPI](https://lexisync.app/api/v1/openapi.json)
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -20,7 +20,7 @@ Requires **Node.js ≥ 18**.
|
|
|
20
20
|
|
|
21
21
|
## Quick start
|
|
22
22
|
|
|
23
|
-
1. Create an org + project at [lexisync
|
|
23
|
+
1. Create an org + project at [lexisync.app](https://lexisync.app/onboarding/1)
|
|
24
24
|
2. Copy **project id** and secret API key (`sk_…`)
|
|
25
25
|
3. Sync source strings, translate, publish a version, load from CDN
|
|
26
26
|
|
|
@@ -31,7 +31,7 @@ npx lexisync publish -p YOUR_PROJECT_ID -v production
|
|
|
31
31
|
npx lexisync pull -p YOUR_PROJECT_ID -n common -l en -v production -o ./locales/en.json
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
Config is stored in `~/.lexisync/config.json`. Override API host with `LEXISYNC_API_URL` (default: `https://lexisync
|
|
34
|
+
Config is stored in `~/.lexisync/config.json`. Override API host with `LEXISYNC_API_URL` (default: `https://lexisync.app`). Override CDN with `LEXISYNC_CDN_URL` (default: `https://cdn.lexisync.app`).
|
|
35
35
|
|
|
36
36
|
## Locize-style workflow
|
|
37
37
|
|
|
@@ -41,15 +41,16 @@ Config is stored in `~/.lexisync/config.json`. Override API host with `LEXISYNC_
|
|
|
41
41
|
| 2. Working copy | `lexisync sync` and/or `saveMissing: true` → version **`latest`** |
|
|
42
42
|
| 3. Translate | Dashboard → project → Translate & publish |
|
|
43
43
|
| 4. Publish | `lexisync publish -v production` freezes CDN catalogs |
|
|
44
|
-
| 5. Ship | App loads `version: "production"` (
|
|
44
|
+
| 5. Ship | App loads `version: "production"` (live tag) or `latest` (dev) |
|
|
45
45
|
|
|
46
46
|
**CDN (no auth):**
|
|
47
47
|
|
|
48
48
|
```
|
|
49
|
-
GET
|
|
49
|
+
GET https://cdn.lexisync.app/{projectId}/{version}/{lng}/{namespace}.json
|
|
50
|
+
GET https://cdn.lexisync.app/{projectId}/{version}/languages
|
|
50
51
|
```
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
Also: `https://lexisync.app/cdn/{projectId}/{version}/{lng}/{namespace}`
|
|
53
54
|
|
|
54
55
|
## CLI
|
|
55
56
|
|
|
@@ -76,7 +77,8 @@ await i18next.use(LexiSyncBackend).init({
|
|
|
76
77
|
backend: {
|
|
77
78
|
projectId: 'YOUR_PROJECT_ID',
|
|
78
79
|
apiKey: process.env.LEXISYNC_API_KEY, // needed for saveMissing
|
|
79
|
-
apiUrl: 'https://lexisync
|
|
80
|
+
apiUrl: 'https://lexisync.app', // optional — this is the default
|
|
81
|
+
// cdnUrl: 'https://cdn.lexisync.app', // optional — auto when apiUrl is lexisync.app
|
|
80
82
|
version: 'latest', // use "production" after publish
|
|
81
83
|
},
|
|
82
84
|
saveMissing: true, // only writes when version === "latest"
|
|
@@ -104,9 +106,10 @@ const {
|
|
|
104
106
|
downloadCatalog,
|
|
105
107
|
reportMissing,
|
|
106
108
|
publishVersion,
|
|
109
|
+
cdnUrl,
|
|
107
110
|
} = require('lexisync/client');
|
|
108
111
|
|
|
109
|
-
const apiUrl = 'https://lexisync
|
|
112
|
+
const apiUrl = 'https://lexisync.app';
|
|
110
113
|
const apiKey = process.env.LEXISYNC_API_KEY;
|
|
111
114
|
|
|
112
115
|
await discoverApi({ apiUrl });
|
|
@@ -119,69 +122,12 @@ await downloadCatalog({
|
|
|
119
122
|
version: 'latest',
|
|
120
123
|
format: 'nested', // or "flat"
|
|
121
124
|
});
|
|
122
|
-
await reportMissing({
|
|
123
|
-
apiUrl,
|
|
124
|
-
apiKey,
|
|
125
|
-
projectId: '…',
|
|
126
|
-
namespace: 'common',
|
|
127
|
-
languageCode: 'en',
|
|
128
|
-
keys: { new_cta: 'Try now' },
|
|
129
|
-
});
|
|
130
|
-
await publishVersion({ apiUrl, apiKey, projectId: '…', version: 'production' });
|
|
131
|
-
```
|
|
132
125
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
```bash
|
|
138
|
-
npm install lexisync-react i18next react-i18next
|
|
126
|
+
// Build a public CDN URL
|
|
127
|
+
cdnUrl({ projectId: '…', version: 'production', language: 'en', namespace: 'common' });
|
|
128
|
+
// → https://cdn.lexisync.app/…/production/en/common.json
|
|
139
129
|
```
|
|
140
130
|
|
|
141
|
-
```tsx
|
|
142
|
-
import { LexiSyncProvider, useT } from 'lexisync-react';
|
|
143
|
-
|
|
144
|
-
function App() {
|
|
145
|
-
return (
|
|
146
|
-
<LexiSyncProvider
|
|
147
|
-
projectId="…"
|
|
148
|
-
apiKey={import.meta.env.VITE_LEXISYNC_API_KEY}
|
|
149
|
-
version="latest"
|
|
150
|
-
saveMissing
|
|
151
|
-
>
|
|
152
|
-
<Page />
|
|
153
|
-
</LexiSyncProvider>
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function Page() {
|
|
158
|
-
const t = useT();
|
|
159
|
-
return <h1>{t('hello')}</h1>;
|
|
160
|
-
}
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
`lexisync-react` is a separate package on npm when published.
|
|
164
|
-
|
|
165
|
-
## Environment
|
|
166
|
-
|
|
167
|
-
| Variable | Description |
|
|
168
|
-
|----------|-------------|
|
|
169
|
-
| `LEXISYNC_API_URL` | API host (default production URL) |
|
|
170
|
-
| `LEXISYNC_API_KEY` | Secret key for CLI write ops |
|
|
171
|
-
|
|
172
|
-
## Security
|
|
173
|
-
|
|
174
|
-
- Use **secret** keys (`sk_…`) only server-side or in trusted CLI environments.
|
|
175
|
-
- Use **public** keys (`pub_…`) for read-only clients when possible.
|
|
176
|
-
- Never commit API keys. Prefer env vars or `~/.lexisync/config.json` (local).
|
|
177
|
-
|
|
178
|
-
## Links
|
|
179
|
-
|
|
180
|
-
- Product: https://lexisync-six.vercel.app
|
|
181
|
-
- Documentation: https://lexisync-six.vercel.app/docs
|
|
182
|
-
- API v1: https://lexisync-six.vercel.app/api/v1
|
|
183
|
-
- Source: https://github.com/sanderpost/lexisync (package under `packages/lexisync`)
|
|
184
|
-
|
|
185
131
|
## License
|
|
186
132
|
|
|
187
133
|
MIT
|
package/lib/backend.js
CHANGED
|
@@ -26,6 +26,7 @@ class LexiSyncBackend {
|
|
|
26
26
|
this.services = services;
|
|
27
27
|
this.options = {
|
|
28
28
|
apiUrl: backendOptions.apiUrl,
|
|
29
|
+
cdnUrl: backendOptions.cdnUrl,
|
|
29
30
|
projectId: backendOptions.projectId,
|
|
30
31
|
apiKey: backendOptions.apiKey,
|
|
31
32
|
version: backendOptions.version || 'latest',
|
|
@@ -44,7 +45,7 @@ class LexiSyncBackend {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
read(language, namespace, callback) {
|
|
47
|
-
const { projectId, apiUrl, version } = this.options;
|
|
48
|
+
const { projectId, apiUrl, cdnUrl, version } = this.options;
|
|
48
49
|
if (!projectId) {
|
|
49
50
|
callback(new Error('LexiSync backend: projectId is required'), null);
|
|
50
51
|
return;
|
|
@@ -52,6 +53,7 @@ class LexiSyncBackend {
|
|
|
52
53
|
|
|
53
54
|
getTranslations({
|
|
54
55
|
apiUrl,
|
|
56
|
+
cdnUrl,
|
|
55
57
|
projectId,
|
|
56
58
|
namespace,
|
|
57
59
|
language,
|
package/lib/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const DEFAULT_API_URL = 'https://lexisync
|
|
3
|
+
const DEFAULT_API_URL = 'https://lexisync.app';
|
|
4
|
+
const DEFAULT_CDN_URL = 'https://cdn.lexisync.app';
|
|
4
5
|
|
|
5
6
|
function resolveApiUrl(override) {
|
|
6
7
|
const raw =
|
|
@@ -24,22 +25,39 @@ function rowsToResource(rows) {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* CDN URLs:
|
|
29
|
+
* https://cdn.lexisync.app/{projectId}/{version}/{lng}/{ns}.json
|
|
30
|
+
* https://lexisync.app/cdn/{projectId}/{version}/{lng}/{ns}
|
|
31
|
+
* version "latest" = working copy; other versions = published catalogs (immediate after publish).
|
|
30
32
|
*/
|
|
31
|
-
function
|
|
33
|
+
function resolveCdnBase(apiUrl, cdnUrl) {
|
|
34
|
+
if (cdnUrl) return String(cdnUrl).replace(/\/$/, '');
|
|
35
|
+
if (typeof process !== 'undefined' && process.env && process.env.LEXISYNC_CDN_URL) {
|
|
36
|
+
return String(process.env.LEXISYNC_CDN_URL).replace(/\/$/, '');
|
|
37
|
+
}
|
|
38
|
+
// Prefer dedicated CDN host when using the default production API
|
|
32
39
|
const base = resolveApiUrl(apiUrl);
|
|
40
|
+
if (base === DEFAULT_API_URL || base.endsWith('lexisync.app')) {
|
|
41
|
+
return DEFAULT_CDN_URL;
|
|
42
|
+
}
|
|
43
|
+
return `${base}/cdn`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function cdnUrl({ apiUrl, cdnUrl: cdnBase, projectId, version, language, namespace }) {
|
|
47
|
+
const root = resolveCdnBase(apiUrl, cdnBase);
|
|
33
48
|
const v = encodeURIComponent(version || 'latest');
|
|
34
49
|
const lng = encodeURIComponent(language || 'en');
|
|
35
50
|
const ns = encodeURIComponent(namespace || 'default');
|
|
36
|
-
|
|
51
|
+
if (root.endsWith('/cdn')) {
|
|
52
|
+
return `${root}/${encodeURIComponent(projectId)}/${v}/${lng}/${ns}`;
|
|
53
|
+
}
|
|
54
|
+
// Pure CDN domain base (cdn.lexisync.app)
|
|
55
|
+
return `${root}/${encodeURIComponent(projectId)}/${v}/${lng}/${ns}.json`;
|
|
37
56
|
}
|
|
38
57
|
|
|
39
|
-
async function getTranslations({ apiUrl, projectId, namespace, language, version }) {
|
|
58
|
+
async function getTranslations({ apiUrl, cdnUrl: cdnBase, projectId, namespace, language, version }) {
|
|
40
59
|
const ver = version || 'latest';
|
|
41
|
-
|
|
42
|
-
const url = cdnUrl({ apiUrl, projectId, version: ver, language, namespace });
|
|
60
|
+
const url = cdnUrl({ apiUrl, cdnUrl: cdnBase, projectId, version: ver, language, namespace });
|
|
43
61
|
const res = await fetch(url);
|
|
44
62
|
if (res.ok) {
|
|
45
63
|
const data = await res.json();
|
|
@@ -209,7 +227,9 @@ async function reportMissing({ apiUrl, apiKey, projectId, namespace = 'common',
|
|
|
209
227
|
|
|
210
228
|
module.exports = {
|
|
211
229
|
DEFAULT_API_URL,
|
|
230
|
+
DEFAULT_CDN_URL,
|
|
212
231
|
resolveApiUrl,
|
|
232
|
+
resolveCdnBase,
|
|
213
233
|
rowsToResource,
|
|
214
234
|
cdnUrl,
|
|
215
235
|
getTranslations,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lexisync",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "CLI and i18next backend for LexiSync — sync locale files and load translations at runtime",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Sander Post",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"url": "git+https://github.com/sanderpost/lexisync.git",
|
|
10
10
|
"directory": "packages/lexisync"
|
|
11
11
|
},
|
|
12
|
-
"homepage": "https://lexisync
|
|
12
|
+
"homepage": "https://lexisync.app/docs",
|
|
13
13
|
"bugs": {
|
|
14
14
|
"url": "https://github.com/sanderpost/lexisync/issues"
|
|
15
15
|
},
|