@localess/cli 3.0.5-dev.20260428203008 → 3.0.5-dev.20260501212257

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.
Files changed (37) hide show
  1. package/SKILL.md +11 -6
  2. package/dist/cache.d.ts +29 -0
  3. package/dist/client.d.ts +142 -0
  4. package/dist/commands/login/index.d.ts +2 -0
  5. package/dist/commands/login/login.test.d.ts +1 -0
  6. package/dist/commands/logout/index.d.ts +2 -0
  7. package/dist/commands/translations/index.d.ts +2 -0
  8. package/dist/commands/translations/pull/index.d.ts +7 -0
  9. package/dist/commands/translations/push/index.d.ts +9 -0
  10. package/dist/commands/types/generate/generator.d.ts +3 -0
  11. package/dist/commands/types/generate/generator.test.d.ts +1 -0
  12. package/dist/commands/types/generate/index.d.ts +2 -0
  13. package/dist/commands/types/index.d.ts +2 -0
  14. package/dist/commands/types/types.test.d.ts +1 -0
  15. package/dist/file.d.ts +7 -0
  16. package/dist/index.d.ts +2 -1
  17. package/dist/index.mjs +153 -146
  18. package/dist/models/content-asset.d.ts +13 -0
  19. package/dist/models/content-data.d.ts +27 -0
  20. package/dist/models/content-link.d.ts +21 -0
  21. package/dist/models/content-metadata.d.ts +41 -0
  22. package/dist/models/content-reference.d.ts +13 -0
  23. package/dist/models/content-rich-text.d.ts +13 -0
  24. package/dist/models/content.d.ts +21 -0
  25. package/dist/models/index.d.ts +13 -0
  26. package/dist/models/links.d.ts +7 -0
  27. package/dist/models/locale.d.ts +10 -0
  28. package/dist/models/references.d.ts +7 -0
  29. package/dist/models/schema.d.ts +142 -0
  30. package/dist/models/space.d.ts +21 -0
  31. package/dist/models/translation.zod.d.ts +13 -0
  32. package/dist/models/translations.d.ts +25 -0
  33. package/dist/program.d.ts +2 -0
  34. package/dist/session.d.ts +22 -0
  35. package/dist/utils.d.ts +45 -0
  36. package/dist/utils.test.d.ts +1 -0
  37. package/package.json +2 -3
package/dist/index.mjs CHANGED
@@ -1,28 +1,28 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command as e } from "commander";
3
3
  import { input as t, password as n } from "@inquirer/prompts";
4
- import { access as r, mkdir as i, readFile as a, writeFile as o } from "node:fs/promises";
5
- import { join as s, parse as c } from "node:path";
6
- import * as l from "node:process";
7
- import u from "node:process";
8
- import { z as d } from "zod";
4
+ import { access as r, appendFile as i, mkdir as a, readFile as o, writeFile as s } from "node:fs/promises";
5
+ import { join as c, parse as l } from "node:path";
6
+ import * as u from "node:process";
7
+ import d from "node:process";
8
+ import { z as f } from "zod";
9
9
  //#region src/utils.ts
10
- var f = "\x1B[0m", p = "\x1B[34m";
11
- function m(e) {
10
+ var p = "\x1B[0m", m = "\x1B[34m";
11
+ function h(e) {
12
12
  return Object.keys(e).sort().reduce((t, n) => {
13
13
  let r = e[n];
14
- return t[n] = typeof r == "object" && r && !Array.isArray(r) ? m(r) : r, t;
14
+ return t[n] = typeof r == "object" && r && !Array.isArray(r) ? h(r) : r, t;
15
15
  }, {});
16
16
  }
17
- function h(e, t = "") {
17
+ function g(e, t = "") {
18
18
  let n = {};
19
19
  for (let [r, i] of Object.entries(e)) {
20
20
  let e = t ? `${t}.${r}` : r;
21
- typeof i == "object" && i && !Array.isArray(i) ? Object.assign(n, h(i, e)) : n[e] = String(i);
21
+ typeof i == "object" && i && !Array.isArray(i) ? Object.assign(n, g(i, e)) : n[e] = String(i);
22
22
  }
23
23
  return n;
24
24
  }
25
- function g(e) {
25
+ function _(e) {
26
26
  let t = {};
27
27
  for (let [n, r] of Object.entries(e)) {
28
28
  let e = n.split("."), i = t;
@@ -32,13 +32,13 @@ function g(e) {
32
32
  }
33
33
  //#endregion
34
34
  //#region src/cache.ts
35
- var _ = class {
35
+ var v = class {
36
36
  set(e, t) {}
37
37
  get(e) {}
38
38
  has(e) {
39
39
  return !1;
40
40
  }
41
- }, v = class {
41
+ }, y = class {
42
42
  cache = /* @__PURE__ */ new Map();
43
43
  constructor(e = 3e5) {
44
44
  this.ttlMs = e;
@@ -62,23 +62,23 @@ var _ = class {
62
62
  has(e) {
63
63
  return this.get(e) !== void 0;
64
64
  }
65
- }, y = `${p}[Localess:Client]${f}`;
66
- async function b(e, t, n = 3, r = 500, i) {
65
+ }, b = `${m}[Localess:Client]${p}`;
66
+ async function x(e, t, n = 3, r = 500, i) {
67
67
  let a = 0, o;
68
68
  for (; a <= n;) {
69
69
  try {
70
70
  let n = await fetch(e, t);
71
- if (!n.ok && n.status >= 500) i && console.log(y, `fetchWithRetry: HTTP ${n.status} on attempt ${a + 1}`), o = /* @__PURE__ */ Error(`HTTP ${n.status}`);
71
+ if (!n.ok && n.status >= 500) i && console.log(b, `fetchWithRetry: HTTP ${n.status} on attempt ${a + 1}`), o = /* @__PURE__ */ Error(`HTTP ${n.status}`);
72
72
  else return n;
73
73
  } catch (e) {
74
- i && console.log(y, `fetchWithRetry: network error on attempt ${a + 1}`, e), o = e;
74
+ i && console.log(b, `fetchWithRetry: network error on attempt ${a + 1}`, e), o = e;
75
75
  }
76
76
  a++, a <= n && await new Promise((e) => setTimeout(e, r));
77
77
  }
78
78
  throw o;
79
79
  }
80
- function x(e) {
81
- e.debug && console.log(y, "Client Options : ", e);
80
+ function S(e) {
81
+ e.debug && console.log(b, "Client Options : ", e);
82
82
  let t = e.origin.replace(/\/+$/, ""), n = {
83
83
  redirect: "follow",
84
84
  headers: {
@@ -87,23 +87,23 @@ function x(e) {
87
87
  "X-Localess-Agent": "Localess-CLI-Client",
88
88
  "X-Localess-Agent-Version": "0.9.0"
89
89
  }
90
- }, r = e.cacheTTL === !1 ? new _() : new v(e.cacheTTL);
90
+ }, r = e.cacheTTL === !1 ? new v() : new y(e.cacheTTL);
91
91
  return {
92
92
  async getSpace() {
93
- e.debug && console.log(y, "getSpace()");
93
+ e.debug && console.log(b, "getSpace()");
94
94
  let i = `${t}/api/v1/spaces/${e.spaceId}?token=${e.token}`;
95
- if (e.debug && console.log(y, "getSpace fetch url : ", i), r.has(i)) return e.debug && console.log(y, "getSpace cache hit"), r.get(i);
95
+ if (e.debug && console.log(b, "getSpace fetch url : ", i), r.has(i)) return e.debug && console.log(b, "getSpace cache hit"), r.get(i);
96
96
  try {
97
- let t = await b(i, n, e.retryCount, e.retryDelay, e.debug);
98
- e.debug && console.log(y, "getSpace status : ", t.status);
97
+ let t = await x(i, n, e.retryCount, e.retryDelay, e.debug);
98
+ e.debug && console.log(b, "getSpace status : ", t.status);
99
99
  let a = await t.json();
100
100
  return r.set(i, a), a;
101
101
  } catch (e) {
102
- return console.error(y, "getSpace error : ", e), {};
102
+ return console.error(b, "getSpace error : ", e), {};
103
103
  }
104
104
  },
105
105
  async getLinks(i) {
106
- e.debug && console.log(y, "getLinks() params : ", JSON.stringify(i));
106
+ e.debug && console.log(b, "getLinks() params : ", JSON.stringify(i));
107
107
  let a = "";
108
108
  i?.kind && (a = `&kind=${i.kind}`);
109
109
  let o = "";
@@ -111,72 +111,72 @@ function x(e) {
111
111
  let s = "";
112
112
  i?.excludeChildren && (s = `&excludeChildren=${i.excludeChildren}`);
113
113
  let c = `${t}/api/v1/spaces/${e.spaceId}/links?token=${e.token}${a}${o}${s}`;
114
- if (e.debug && console.log(y, "getLinks fetch url : ", c), r.has(c)) return e.debug && console.log(y, "getLinks cache hit"), r.get(c);
114
+ if (e.debug && console.log(b, "getLinks fetch url : ", c), r.has(c)) return e.debug && console.log(b, "getLinks cache hit"), r.get(c);
115
115
  try {
116
- let t = await b(c, n, e.retryCount, e.retryDelay, e.debug);
117
- e.debug && console.log(y, "getLinks status : ", t.status);
116
+ let t = await x(c, n, e.retryCount, e.retryDelay, e.debug);
117
+ e.debug && console.log(b, "getLinks status : ", t.status);
118
118
  let i = await t.json();
119
119
  return r.set(c, i), i;
120
120
  } catch (e) {
121
- return console.error(y, "getLinks error : ", e), {};
121
+ return console.error(b, "getLinks error : ", e), {};
122
122
  }
123
123
  },
124
124
  async getContentBySlug(i, a) {
125
- e.debug && (console.log(y, "getContentBySlug() slug : ", i), console.log(y, "getContentBySlug() params : ", JSON.stringify(a)));
125
+ e.debug && (console.log(b, "getContentBySlug() slug : ", i), console.log(b, "getContentBySlug() params : ", JSON.stringify(a)));
126
126
  let o = "";
127
127
  e?.version && e.version == "draft" && (o = `&version=${e.version}`), a?.version && a.version == "draft" && (o = `&version=${a.version}`);
128
128
  let s = a?.locale ? `&locale=${a.locale}` : "", c = a?.resolveReference ? `&resolveReference=${a.resolveReference}` : "", l = a?.resolveLink ? `&resolveLink=${a.resolveLink}` : "", u = `${t}/api/v1/spaces/${e.spaceId}/contents/slugs/${i}?token=${e.token}${o}${s}${c}${l}`;
129
- if (e.debug && console.log(y, "getContentBySlug fetch url : ", u), r.has(u)) return e.debug && console.log(y, "getContentBySlug cache hit"), r.get(u);
129
+ if (e.debug && console.log(b, "getContentBySlug fetch url : ", u), r.has(u)) return e.debug && console.log(b, "getContentBySlug cache hit"), r.get(u);
130
130
  try {
131
- let t = await b(u, n, e.retryCount, e.retryDelay, e.debug);
132
- e.debug && console.log(y, "getContentBySlug status : ", t.status);
131
+ let t = await x(u, n, e.retryCount, e.retryDelay, e.debug);
132
+ e.debug && console.log(b, "getContentBySlug status : ", t.status);
133
133
  let i = await t.json();
134
134
  return r.set(u, i), i;
135
135
  } catch (e) {
136
- return console.error(y, "getContentBySlug error : ", e), {};
136
+ return console.error(b, "getContentBySlug error : ", e), {};
137
137
  }
138
138
  },
139
139
  async getContentById(i, a) {
140
- e.debug && (console.log(y, "getContentById() id : ", i), console.log(y, "getContentById() params : ", JSON.stringify(a)));
140
+ e.debug && (console.log(b, "getContentById() id : ", i), console.log(b, "getContentById() params : ", JSON.stringify(a)));
141
141
  let o = "";
142
142
  e?.version && e.version == "draft" && (o = `&version=${e.version}`), a?.version && a.version == "draft" && (o = `&version=${a.version}`);
143
143
  let s = a?.locale ? `&locale=${a.locale}` : "", c = a?.resolveReference ? `&resolveReference=${a.resolveReference}` : "", l = a?.resolveLink ? `&resolveLink=${a.resolveLink}` : "", u = `${t}/api/v1/spaces/${e.spaceId}/contents/${i}?token=${e.token}${o}${s}${c}${l}`;
144
- if (e.debug && console.log(y, "getContentById fetch url : ", u), r.has(u)) return e.debug && console.log(y, "getContentById cache hit"), r.get(u);
144
+ if (e.debug && console.log(b, "getContentById fetch url : ", u), r.has(u)) return e.debug && console.log(b, "getContentById cache hit"), r.get(u);
145
145
  try {
146
- let t = await b(u, n, e.retryCount, e.retryDelay, e.debug);
147
- e.debug && console.log(y, "getContentById status : ", t.status);
146
+ let t = await x(u, n, e.retryCount, e.retryDelay, e.debug);
147
+ e.debug && console.log(b, "getContentById status : ", t.status);
148
148
  let i = await t.json();
149
149
  return r.set(u, i), i;
150
150
  } catch (e) {
151
- return console.error(y, "getContentById error : ", e), {};
151
+ return console.error(b, "getContentById error : ", e), {};
152
152
  }
153
153
  },
154
154
  async getTranslations(i, a) {
155
- e.debug && (console.log(y, "getTranslations() locale : ", i), console.log(y, "getTranslations() params : ", JSON.stringify(a)));
155
+ e.debug && (console.log(b, "getTranslations() locale : ", i), console.log(b, "getTranslations() params : ", JSON.stringify(a)));
156
156
  let o = "";
157
157
  e?.version && e.version == "draft" && (o = `&version=${e.version}`), a?.version && a.version == "draft" && (o = `&version=${a.version}`);
158
158
  let s = `${t}/api/v1/spaces/${e.spaceId}/translations/${i}?token=${e.token}${o}`;
159
- if (e.debug && console.log(y, "getTranslations fetch url : ", s), r.has(s)) return e.debug && console.log(y, "getTranslations cache hit"), r.get(s);
159
+ if (e.debug && console.log(b, "getTranslations fetch url : ", s), r.has(s)) return e.debug && console.log(b, "getTranslations cache hit"), r.get(s);
160
160
  try {
161
- let t = await b(s, n, e.retryCount, e.retryDelay, e.debug);
162
- e.debug && console.log(y, "getTranslations status : ", t.status);
161
+ let t = await x(s, n, e.retryCount, e.retryDelay, e.debug);
162
+ e.debug && console.log(b, "getTranslations status : ", t.status);
163
163
  let i = await t.json();
164
164
  return r.set(s, i), i;
165
165
  } catch (e) {
166
- return console.error(y, "getTranslations error : ", e), {};
166
+ return console.error(b, "getTranslations error : ", e), {};
167
167
  }
168
168
  },
169
169
  async updateTranslations(r, i, a, o) {
170
- e.debug && (console.log(y, "updateTranslations() locale : ", r), console.log(y, "updateTranslations() type : ", i), console.log(y, "updateTranslations() values : ", JSON.stringify(a)));
170
+ e.debug && (console.log(b, "updateTranslations() locale : ", r), console.log(b, "updateTranslations() type : ", i), console.log(b, "updateTranslations() values : ", JSON.stringify(a)));
171
171
  let s = `${t}/api/v1/spaces/${e.spaceId}/translations/${r}`;
172
- e.debug && console.log(y, "updateTranslations fetch url : ", s);
172
+ e.debug && console.log(b, "updateTranslations fetch url : ", s);
173
173
  let c = {
174
174
  type: i,
175
175
  values: a,
176
176
  dryRun: o
177
177
  };
178
178
  try {
179
- let t = await b(s, {
179
+ let t = await x(s, {
180
180
  method: "POST",
181
181
  headers: {
182
182
  "X-API-KEY": e.token,
@@ -184,35 +184,35 @@ function x(e) {
184
184
  },
185
185
  body: JSON.stringify(c)
186
186
  }, e.retryCount, e.retryDelay, e.debug);
187
- return e.debug && console.log(y, "updateTranslations status : ", t.status), t.json();
187
+ return e.debug && console.log(b, "updateTranslations status : ", t.status), t.json();
188
188
  } catch (e) {
189
- console.error(y, "updateTranslations error : ", e);
189
+ console.error(b, "updateTranslations error : ", e);
190
190
  }
191
191
  },
192
192
  async getOpenApi() {
193
- e.debug && console.log(y, "getOpenApi()");
193
+ e.debug && console.log(b, "getOpenApi()");
194
194
  let i = `${t}/api/v1/spaces/${e.spaceId}/open-api?token=${e.token}`;
195
- if (e.debug && console.log(y, "getOpenApi fetch url : ", i), r.has(i)) return e.debug && console.log(y, "getOpenApi cache hit"), r.get(i);
195
+ if (e.debug && console.log(b, "getOpenApi fetch url : ", i), r.has(i)) return e.debug && console.log(b, "getOpenApi cache hit"), r.get(i);
196
196
  try {
197
- let t = await b(i, n, e.retryCount, e.retryDelay, e.debug);
198
- e.debug && console.log(y, "getOpenApi status : ", t.status);
197
+ let t = await x(i, n, e.retryCount, e.retryDelay, e.debug);
198
+ e.debug && console.log(b, "getOpenApi status : ", t.status);
199
199
  let a = await t.json();
200
200
  return r.set(i, a), a;
201
201
  } catch (e) {
202
- return console.error(y, "getOpenApi error : ", e), {};
202
+ return console.error(b, "getOpenApi error : ", e), {};
203
203
  }
204
204
  },
205
205
  async getSchemas() {
206
- e.debug && console.log(y, "getSchemas()");
206
+ e.debug && console.log(b, "getSchemas()");
207
207
  let i = `${t}/api/v1/spaces/${e.spaceId}/schemas?token=${e.token}`;
208
- if (e.debug && console.log(y, "getSchemas fetch url : ", i), r.has(i)) return e.debug && console.log(y, "getSchemas cache hit"), r.get(i);
208
+ if (e.debug && console.log(b, "getSchemas fetch url : ", i), r.has(i)) return e.debug && console.log(b, "getSchemas cache hit"), r.get(i);
209
209
  try {
210
- let t = await b(i, n, e.retryCount, e.retryDelay, e.debug);
211
- e.debug && console.log(y, "getSchemas status : ", t.status);
210
+ let t = await x(i, n, e.retryCount, e.retryDelay, e.debug);
211
+ e.debug && console.log(b, "getSchemas status : ", t.status);
212
212
  let a = await t.json();
213
213
  return r.set(i, a), a;
214
214
  } catch (e) {
215
- return console.error(y, "getSchemas error : ", e), {};
215
+ return console.error(b, "getSchemas error : ", e), {};
216
216
  }
217
217
  },
218
218
  assetLink(n) {
@@ -222,26 +222,33 @@ function x(e) {
222
222
  }
223
223
  //#endregion
224
224
  //#region src/file.ts
225
- var S = ".localess";
226
- async function C(e, t, n) {
227
- let r = c(e).dir;
225
+ var C = ".localess";
226
+ async function w(e, t, n) {
227
+ let r = l(e).dir;
228
228
  try {
229
- await i(r, { recursive: !0 });
229
+ await a(r, { recursive: !0 });
230
230
  } catch {
231
231
  return;
232
232
  }
233
233
  try {
234
- await o(e, t, n);
234
+ await s(e, t, n);
235
235
  } catch {}
236
236
  }
237
- async function w(e) {
238
- return a(e, "utf-8");
237
+ async function T(e) {
238
+ return o(e, "utf-8");
239
+ }
240
+ async function E(e, t) {
241
+ let n = c(e, ".gitignore"), r = "";
242
+ try {
243
+ r = await o(n, "utf-8");
244
+ } catch {}
245
+ r.split("\n").map((e) => e.trim()).includes(t) || await i(n, `${r.length > 0 && !r.endsWith("\n") ? "\n" : ""}${t}\n`, "utf-8");
239
246
  }
240
247
  //#endregion
241
248
  //#region src/session.ts
242
- var T = s(l.cwd(), S, "credentials.json");
243
- async function E() {
244
- let e = { isLoggedIn: !1 }, t = l.env.LOCALESS_TOKEN, n = l.env.LOCALESS_SPACE, i = l.env.LOCALESS_ORIGIN;
249
+ var D = c(u.cwd(), C, "credentials.json");
250
+ async function O() {
251
+ let e = { isLoggedIn: !1 }, t = u.env.LOCALESS_TOKEN, n = u.env.LOCALESS_SPACE, i = u.env.LOCALESS_ORIGIN;
245
252
  if (t && n && i) return console.debug("Login in using environment variables."), {
246
253
  isLoggedIn: !0,
247
254
  space: n,
@@ -250,8 +257,8 @@ async function E() {
250
257
  method: "env"
251
258
  };
252
259
  try {
253
- await r(T);
254
- let t = await a(T, "utf8"), n = JSON.parse(t);
260
+ await r(D);
261
+ let t = await o(D, "utf8"), n = JSON.parse(t);
255
262
  if (Object.keys(n).length === 0) return e;
256
263
  if (n.origin && n.token && n.space) return console.debug("Login in using credentials file."), {
257
264
  isLoggedIn: !0,
@@ -263,21 +270,21 @@ async function E() {
263
270
  } catch {}
264
271
  return e;
265
272
  }
266
- async function D(e) {
267
- if (e.origin && e.token && e.space) await C(T, JSON.stringify(e, null, 2), { mode: 384 }), console.log("Add session credentials to file system."), console.log("Add .localess to .gitignore to avoid committing them to your repository.");
273
+ async function k(e) {
274
+ if (e.origin && e.token && e.space) await w(D, JSON.stringify(e, null, 2), { mode: 384 }), console.log("Session credentials saved to file system."), await E(u.cwd(), C), console.log(`Added '${C}' to .gitignore to prevent credentials from being committed.`);
268
275
  else throw Error("Cannot persist session: missing required fields.");
269
276
  }
270
- async function O() {
277
+ async function A() {
271
278
  try {
272
- await r(T), await C(T, "{}", { mode: 384 });
279
+ await r(D), await w(D, "{}", { mode: 384 });
273
280
  } catch {
274
281
  throw Error("Failed to clear session credentials.");
275
282
  }
276
283
  }
277
284
  //#endregion
278
285
  //#region src/commands/login/index.ts
279
- var k = new e("login").description("Login to Localess CLI").option("-o, --origin <origin>", "Origin of the Localess instance").option("-s, --space <space>", "Space ID to login to").option("-t, --token <token>", "Token to login to Localess CLI").action(async (e) => {
280
- if ((await E()).isLoggedIn) {
286
+ var j = new e("login").description("Login to Localess CLI").option("-o, --origin <origin>", "Origin of the Localess instance").option("-s, --space <space>", "Space ID to login to").option("-t, --token <token>", "Token to login to Localess CLI").action(async (e) => {
287
+ if ((await O()).isLoggedIn) {
281
288
  console.log("Already logged in."), console.log("If you want to log in with different credentials, please log out first using \"localess logout\" command.");
282
289
  return;
283
290
  }
@@ -290,14 +297,14 @@ var k = new e("login").description("Login to Localess CLI").option("-o, --origin
290
297
  }), a = e.token ?? await n({
291
298
  message: "Token:",
292
299
  mask: !0
293
- }), o = x({
300
+ }), o = S({
294
301
  origin: r,
295
302
  spaceId: i,
296
303
  token: a
297
304
  });
298
305
  try {
299
306
  let e = await o.getSpace();
300
- console.log(`Successfully logged in to space: ${e.name} (${e.id})`), await D({
307
+ console.log(`Successfully logged in to space: ${e.name} (${e.id})`), await k({
301
308
  origin: r,
302
309
  space: i,
303
310
  token: a
@@ -305,9 +312,9 @@ var k = new e("login").description("Login to Localess CLI").option("-o, --origin
305
312
  } catch {
306
313
  console.error("Login failed");
307
314
  }
308
- }), A = new e("logout").description("Logout from Localess CLI").action(async () => {
315
+ }), M = new e("logout").description("Logout from Localess CLI").action(async () => {
309
316
  console.log("Logging out...");
310
- let e = await E();
317
+ let e = await O();
311
318
  if (!e.isLoggedIn) {
312
319
  console.log("Not currently logged in.");
313
320
  return;
@@ -317,22 +324,22 @@ var k = new e("login").description("Login to Localess CLI").option("-o, --origin
317
324
  return;
318
325
  }
319
326
  try {
320
- await O(), console.log("Successfully logged out.");
327
+ await A(), console.log("Successfully logged out.");
321
328
  } catch (e) {
322
329
  console.error("Failed to log out:", e);
323
330
  }
324
- }), j = /* @__PURE__ */ function(e) {
331
+ }), N = /* @__PURE__ */ function(e) {
325
332
  return e.ROOT = "ROOT", e.NODE = "NODE", e.ENUM = "ENUM", e;
326
- }({}), M = /* @__PURE__ */ function(e) {
333
+ }({}), P = /* @__PURE__ */ function(e) {
327
334
  return e.TEXT = "TEXT", e.TEXTAREA = "TEXTAREA", e.RICH_TEXT = "RICH_TEXT", e.MARKDOWN = "MARKDOWN", e.NUMBER = "NUMBER", e.COLOR = "COLOR", e.DATE = "DATE", e.DATETIME = "DATETIME", e.BOOLEAN = "BOOLEAN", e.OPTION = "OPTION", e.OPTIONS = "OPTIONS", e.LINK = "LINK", e.REFERENCE = "REFERENCE", e.REFERENCES = "REFERENCES", e.ASSET = "ASSET", e.ASSETS = "ASSETS", e.SCHEMA = "SCHEMA", e.SCHEMAS = "SCHEMAS", e;
328
- }({}), N = /* @__PURE__ */ function(e) {
335
+ }({}), F = /* @__PURE__ */ function(e) {
329
336
  return e.ADD_MISSING = "add-missing", e.UPDATE_EXISTING = "update-existing", e.DELETE_MISSING = "delete-missing", e;
330
- }({}), P = /* @__PURE__ */ function(e) {
337
+ }({}), I = /* @__PURE__ */ function(e) {
331
338
  return e.FLAT = "flat", e.NESTED = "nested", e;
332
339
  }({});
333
340
  //#endregion
334
341
  //#region src/commands/types/generate/generator.ts
335
- function F(e) {
342
+ function L(e) {
336
343
  return `/**
337
344
  * Generated by Localess CLI
338
345
  * Do not edit manually.
@@ -383,49 +390,49 @@ export interface ${e}ContentRichText {
383
390
  }
384
391
  `;
385
392
  }
386
- function I(e) {
393
+ function R(e) {
387
394
  return e.replace(/[-_\s]+([a-zA-Z0-9])/g, (e, t) => t.toUpperCase()).replace(/^[a-z]/, (e) => e.toUpperCase());
388
395
  }
389
- function L(e, t) {
396
+ function z(e, t) {
390
397
  switch (e.kind) {
391
- case M.TEXT:
392
- case M.TEXTAREA:
393
- case M.MARKDOWN:
394
- case M.COLOR:
395
- case M.DATE:
396
- case M.DATETIME: return "string";
397
- case M.NUMBER: return "number";
398
- case M.BOOLEAN: return "boolean";
399
- case M.RICH_TEXT: return `${t}ContentRichText`;
400
- case M.LINK: return `${t}ContentLink`;
401
- case M.ASSET: return `${t}ContentAsset`;
402
- case M.ASSETS: return `${t}ContentAsset[]`;
403
- case M.REFERENCE: return `${t}ContentReference`;
404
- case M.REFERENCES: return `${t}ContentReference[]`;
405
- case M.OPTION: return e.source ? t + I(e.source) : "string";
406
- case M.OPTIONS: return e.source ? `${t + I(e.source)}[]` : "string[]";
407
- case M.SCHEMA: {
398
+ case P.TEXT:
399
+ case P.TEXTAREA:
400
+ case P.MARKDOWN:
401
+ case P.COLOR:
402
+ case P.DATE:
403
+ case P.DATETIME: return "string";
404
+ case P.NUMBER: return "number";
405
+ case P.BOOLEAN: return "boolean";
406
+ case P.RICH_TEXT: return `${t}ContentRichText`;
407
+ case P.LINK: return `${t}ContentLink`;
408
+ case P.ASSET: return `${t}ContentAsset`;
409
+ case P.ASSETS: return `${t}ContentAsset[]`;
410
+ case P.REFERENCE: return `${t}ContentReference`;
411
+ case P.REFERENCES: return `${t}ContentReference[]`;
412
+ case P.OPTION: return e.source ? t + R(e.source) : "string";
413
+ case P.OPTIONS: return e.source ? `${t + R(e.source)}[]` : "string[]";
414
+ case P.SCHEMA: {
408
415
  let n = e.schemas;
409
416
  if (!n || n.length === 0) return "unknown";
410
- let r = n.map((e) => t + I(e));
417
+ let r = n.map((e) => t + R(e));
411
418
  return r.length === 1 ? r[0] : r.join(" | ");
412
419
  }
413
- case M.SCHEMAS: {
420
+ case P.SCHEMAS: {
414
421
  let n = e.schemas;
415
422
  if (!n || n.length === 0) return "unknown[]";
416
- let r = n.map((e) => t + I(e));
423
+ let r = n.map((e) => t + R(e));
417
424
  return `${r.length === 1 ? r[0] : `(${r.join(" | ")})`}[]`;
418
425
  }
419
426
  }
420
427
  }
421
- function R(e, t = "") {
428
+ function B(e, t = "") {
422
429
  return `${t}/**\n${t} * ${e}\n${t} */`;
423
430
  }
424
- function z(e, t = "") {
425
- let n = [F(t)], r = [];
431
+ function V(e, t = "") {
432
+ let n = [L(t)], r = [];
426
433
  for (let [i, a] of Object.entries(e)) {
427
- let e = t + I(i), o = a.description ? `${R(a.description)}\n` : "";
428
- if (a.type === j.ENUM) {
434
+ let e = t + R(i), o = a.description ? `${B(a.description)}\n` : "";
435
+ if (a.type === N.ENUM) {
429
436
  let t = a.values ?? [];
430
437
  if (t.length === 0) n.push(`${o}export type ${e} = string;\n`);
431
438
  else {
@@ -434,14 +441,14 @@ function z(e, t = "") {
434
441
  }
435
442
  } else {
436
443
  let s = a;
437
- a.type === j.ROOT && r.push(e);
444
+ a.type === N.ROOT && r.push(e);
438
445
  let c = [
439
446
  " /** Unique identifier of a component in a content. */",
440
447
  " _id: string;",
441
448
  " /** Unique identifier for the Schema object. */",
442
449
  ` _schema: '${i}';`,
443
450
  ...(s.fields ?? []).slice().sort((e, t) => e.name.localeCompare(t.name)).flatMap((e) => {
444
- let n = L(e, t), r = e.required ? "" : "?", i = [];
451
+ let n = z(e, t), r = e.required ? "" : "?", i = [];
445
452
  return e.description && i.push(` /** ${e.description} */`), i.push(` ${e.name}${r}: ${n};`), i;
446
453
  })
447
454
  ];
@@ -452,14 +459,14 @@ function z(e, t = "") {
452
459
  }
453
460
  //#endregion
454
461
  //#region src/commands/types/generate/index.ts
455
- var B = s(u.cwd(), S, "localess.ts"), V = new e("generate").description("Generate types for your schemas").option("-p, --path <path>", "Path to the file where to save the generated types. Default is .localess/localess.ts", B).option("--prefix <prefix>", "Prefix to prepend to all generated type names", "").action(async (e) => {
462
+ var H = c(d.cwd(), C, "localess.ts"), U = new e("generate").description("Generate types for your schemas").option("-p, --path <path>", "Path to the file where to save the generated types. Default is .localess/localess.ts", H).option("--prefix <prefix>", "Prefix to prepend to all generated type names", "").action(async (e) => {
456
463
  console.log("Types in with options:", e);
457
- let t = await E();
464
+ let t = await O();
458
465
  if (!t.isLoggedIn) {
459
466
  console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
460
467
  return;
461
468
  }
462
- let n = x({
469
+ let n = S({
463
470
  origin: t.origin,
464
471
  spaceId: t.space,
465
472
  token: t.token
@@ -467,34 +474,34 @@ var B = s(u.cwd(), S, "localess.ts"), V = new e("generate").description("Generat
467
474
  console.log("Fetching schemas from Localess...");
468
475
  let r = await n.getSchemas();
469
476
  console.log("Generating types...");
470
- let i = z(r, e.prefix);
471
- await C(e.path, i), console.log(`Types written to ${e.path}`);
472
- }), H = new e("types").description("Generate types for your schemas").addCommand(V), U = d.record(d.string(), d.string()), W = d.enum(["add-missing", "update-existing"]);
473
- d.object({
474
- type: W,
475
- values: U
477
+ let i = V(r, e.prefix);
478
+ await w(e.path, i), console.log(`Types written to ${e.path}`);
479
+ }), W = new e("types").description("Generate types for your schemas").addCommand(U), G = f.record(f.string(), f.string()), K = f.enum(["add-missing", "update-existing"]);
480
+ f.object({
481
+ type: K,
482
+ values: G
476
483
  });
477
484
  //#endregion
478
485
  //#region src/commands/translations/push/index.ts
479
- var G = new e("push").argument("<locale>", "Locale to push").description("Push locale translations to Localess").requiredOption("-p, --path <path>", "Path to the translations file to push").option("-f, --format <format>", `File format. Possible values are : ${Object.values(P)}`, P.FLAT).option("-t, --type <type>", `Push type. Possible values are : ${Object.values(N)}`, N.ADD_MISSING).option("--dry-run", "Preview changes without applying them to Localess").action(async (e, t) => {
480
- if (console.log("Pushing translations with arguments:", e), console.log("Pushing translations with options:", t), !W.safeParse(t.type).success) {
481
- console.error("Invalid type provided. Possible values are :", Object.values(N));
486
+ var q = new e("push").argument("<locale>", "Locale to push").description("Push locale translations to Localess").requiredOption("-p, --path <path>", "Path to the translations file to push").option("-f, --format <format>", `File format. Possible values are : ${Object.values(I)}`, I.FLAT).option("-t, --type <type>", `Push type. Possible values are : ${Object.values(F)}`, F.ADD_MISSING).option("--dry-run", "Preview changes without applying them to Localess").action(async (e, t) => {
487
+ if (console.log("Pushing translations with arguments:", e), console.log("Pushing translations with options:", t), !K.safeParse(t.type).success) {
488
+ console.error("Invalid type provided. Possible values are :", Object.values(F));
482
489
  return;
483
490
  }
484
- let n = await E();
491
+ let n = await O();
485
492
  if (!n.isLoggedIn) {
486
493
  console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
487
494
  return;
488
495
  }
489
- let r = x({
496
+ let r = S({
490
497
  origin: n.origin,
491
498
  spaceId: n.space,
492
499
  token: n.token
493
500
  });
494
501
  t.dryRun && console.warn("Dry run mode enabled: No changes will be made."), console.log("Reading translations file from:", t.path);
495
- let i = await w(t.path), a = JSON.parse(i), o;
496
- o = t.format === P.NESTED ? h(a) : a;
497
- let s = U.safeParse(o);
502
+ let i = await T(t.path), a = JSON.parse(i), o;
503
+ o = t.format === I.NESTED ? g(a) : a;
504
+ let s = G.safeParse(o);
498
505
  if (!s.success) {
499
506
  console.error("Invalid translations file format:", s.error);
500
507
  return;
@@ -502,35 +509,35 @@ var G = new e("push").argument("<locale>", "Locale to push").description("Push l
502
509
  console.log("Pushing translations to Localess with locale:", e, "and type:", t.type);
503
510
  let c = await r.updateTranslations(e, t.type, o, t.dryRun);
504
511
  c ? (c.dryRun && console.log("Dry run results:"), console.log("Successfully pushed translations to Localess"), console.log("Summary:", c.message), c.ids && console.log("Updated translation IDs:", c.ids)) : console.log("Something went wrong while pushing translations to Localess");
505
- }), K = new e("pull").argument("<locale>", "Locale to pull").description("Pull locale translations from Localess").requiredOption("-p, --path <path>", "Path where the translations file will be saved").option("-f, --format <format>", `File format. Possible values are : ${Object.values(P)}`, P.FLAT).action(async (e, t) => {
506
- if (console.log("Pulling translations with arguments:", e), console.log("Pulling translations with options:", t), !Object.values(P).includes(t.format)) {
507
- console.error("Invalid format provided. Possible values are :", Object.values(P));
512
+ }), J = new e("pull").argument("<locale>", "Locale to pull").description("Pull locale translations from Localess").requiredOption("-p, --path <path>", "Path where the translations file will be saved").option("-f, --format <format>", `File format. Possible values are : ${Object.values(I)}`, I.FLAT).action(async (e, t) => {
513
+ if (console.log("Pulling translations with arguments:", e), console.log("Pulling translations with options:", t), !Object.values(I).includes(t.format)) {
514
+ console.error("Invalid format provided. Possible values are :", Object.values(I));
508
515
  return;
509
516
  }
510
- let n = await E();
517
+ let n = await O();
511
518
  if (!n.isLoggedIn) {
512
519
  console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
513
520
  return;
514
521
  }
515
- let r = x({
522
+ let r = S({
516
523
  origin: n.origin,
517
524
  spaceId: n.space,
518
525
  token: n.token
519
526
  });
520
527
  console.log("Pulling translations from Localess for locale:", e);
521
528
  let i = await r.getTranslations(e);
522
- if (console.log("Saving translations in file:", t.path), t.format === P.FLAT) await C(t.path, JSON.stringify(m(i), null, 2));
523
- else if (t.format === P.NESTED) {
524
- let e = m(g(i));
525
- await C(t.path, JSON.stringify(e, null, 2));
529
+ if (console.log("Saving translations in file:", t.path), t.format === I.FLAT) await w(t.path, JSON.stringify(h(i), null, 2));
530
+ else if (t.format === I.NESTED) {
531
+ let e = h(_(i));
532
+ await w(t.path, JSON.stringify(e, null, 2));
526
533
  }
527
534
  console.log("Successfully saved translations from Localess");
528
- }), q = new e("translations").description("Manage translations").addCommand(G).addCommand(K), J = new e();
529
- J.name("Localess CLI").description("CLI tool for Localess platform management").version("3.0.5"), J.addCommand(k), J.addCommand(A), J.addCommand(q), J.addCommand(H);
535
+ }), Y = new e("translations").description("Manage translations").addCommand(q).addCommand(J), X = new e();
536
+ X.name("Localess CLI").description("CLI tool for Localess platform management").version("3.0.5"), X.addCommand(j), X.addCommand(M), X.addCommand(Y), X.addCommand(W);
530
537
  //#endregion
531
538
  //#region src/index.ts
532
539
  try {
533
- J.parse(process.argv);
540
+ X.parse(process.argv);
534
541
  } catch (e) {
535
542
  console.error("Error executing command:", e instanceof Error ? e.message : e), process.exit(1);
536
543
  }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Content Asset defines reference to an Asset.
3
+ */
4
+ export interface ContentAsset {
5
+ /**
6
+ * Define the type of Asset
7
+ */
8
+ kind: 'ASSET';
9
+ /**
10
+ * Unique identifier for the asset.
11
+ */
12
+ uri: string;
13
+ }