@lingo.dev/_sdk 0.15.0 → 0.15.2

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/build/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2;// src/index.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3;// src/index.ts
2
2
  var _zod = require('zod'); var _zod2 = _interopRequireDefault(_zod);
3
3
  var __spec = require('@lingo.dev/_spec');
4
4
  var _cuid2 = require('@paralleldrive/cuid2');
@@ -97,7 +97,8 @@ var engineParamsSchema = _zod2.default.object({
97
97
  apiKey: _zod2.default.string(),
98
98
  apiUrl: _zod2.default.string().url().default("https://engine.lingo.dev"),
99
99
  batchSize: _zod2.default.number().int().gt(0).lte(250).default(25),
100
- idealBatchItemSize: _zod2.default.number().int().gt(0).lte(2500).default(250)
100
+ idealBatchItemSize: _zod2.default.number().int().gt(0).lte(2500).default(250),
101
+ engineId: _zod2.default.string().optional()
101
102
  }).passthrough();
102
103
  var payloadSchema = _zod2.default.record(_zod2.default.string(), _zod2.default.any());
103
104
  var referenceSchema = _zod2.default.record(__spec.localeCodeSchema, payloadSchema);
@@ -107,16 +108,35 @@ var localizationParamsSchema = _zod2.default.object({
107
108
  targetLocale: __spec.localeCodeSchema,
108
109
  fast: _zod2.default.boolean().optional(),
109
110
  reference: referenceSchema.optional(),
110
- hints: hintsSchema.optional()
111
+ hints: hintsSchema.optional(),
112
+ filePath: _zod2.default.string().optional(),
113
+ triggerType: _zod2.default.enum(["cli", "ci"]).optional()
111
114
  });
112
- var LingoDotDevEngine = class {
115
+ var LingoDotDevEngine = (_class = class {
113
116
 
117
+ __init() {this.sessionId = _cuid2.createId.call(void 0, )}
118
+ get isVNext() {
119
+ return !!this.config.engineId;
120
+ }
121
+ get headers() {
122
+ return this.isVNext ? {
123
+ "Content-Type": "application/json; charset=utf-8",
124
+ "X-API-Key": this.config.apiKey
125
+ } : {
126
+ "Content-Type": "application/json; charset=utf-8",
127
+ Authorization: `Bearer ${this.config.apiKey}`
128
+ };
129
+ }
114
130
  /**
115
131
  * Create a new LingoDotDevEngine instance
116
132
  * @param config - Configuration options for the Engine
117
133
  */
118
- constructor(config) {
119
- this.config = engineParamsSchema.parse(config);
134
+ constructor(config) {;_class.prototype.__init.call(this);
135
+ const parsed = engineParamsSchema.parse(config);
136
+ if (!config.apiUrl && parsed.engineId) {
137
+ parsed.apiUrl = "https://api.lingo.dev";
138
+ }
139
+ this.config = parsed;
120
140
  }
121
141
  /**
122
142
  * Localize content using the Lingo.dev API
@@ -144,6 +164,8 @@ var LingoDotDevEngine = class {
144
164
  { data: chunk, reference: params.reference, hints: params.hints },
145
165
  workflowId,
146
166
  params.fast || false,
167
+ params.filePath,
168
+ params.triggerType,
147
169
  signal
148
170
  );
149
171
  if (progressCallback) {
@@ -160,30 +182,37 @@ var LingoDotDevEngine = class {
160
182
  * @param payload - Payload containing the chunk to be localized
161
183
  * @param workflowId - Workflow ID for tracking
162
184
  * @param fast - Whether to use fast mode
185
+ * @param filePath - Optional file path for metadata
186
+ * @param triggerType - Optional trigger type for vNext requests
163
187
  * @param signal - Optional AbortSignal to cancel the operation
164
188
  * @returns Localized chunk
165
189
  */
166
- async localizeChunk(sourceLocale, targetLocale, payload, workflowId, fast, signal) {
167
- const res = await fetch(`${this.config.apiUrl}/i18n`, {
168
- method: "POST",
169
- headers: {
170
- "Content-Type": "application/json; charset=utf-8",
171
- Authorization: `Bearer ${this.config.apiKey}`
190
+ async localizeChunk(sourceLocale, targetLocale, payload, workflowId, fast, filePath, triggerType, signal) {
191
+ const url = this.isVNext ? `${this.config.apiUrl}/process/${this.config.engineId}/localize` : `${this.config.apiUrl}/i18n`;
192
+ const body = this.isVNext ? {
193
+ params: { fast },
194
+ sourceLocale,
195
+ targetLocale,
196
+ data: payload.data,
197
+ reference: payload.reference,
198
+ hints: payload.hints,
199
+ sessionId: this.sessionId,
200
+ triggerType,
201
+ metadata: filePath ? { filePath } : void 0
202
+ } : {
203
+ params: { workflowId, fast },
204
+ locale: {
205
+ source: sourceLocale,
206
+ target: targetLocale
172
207
  },
173
- body: JSON.stringify(
174
- {
175
- params: { workflowId, fast },
176
- locale: {
177
- source: sourceLocale,
178
- target: targetLocale
179
- },
180
- data: payload.data,
181
- reference: payload.reference,
182
- hints: payload.hints
183
- },
184
- null,
185
- 2
186
- ),
208
+ data: payload.data,
209
+ reference: payload.reference,
210
+ hints: payload.hints
211
+ };
212
+ const res = await fetch(url, {
213
+ method: "POST",
214
+ headers: this.headers,
215
+ body: JSON.stringify(body, null, 2),
187
216
  signal
188
217
  });
189
218
  if (!res.ok) {
@@ -452,8 +481,15 @@ var LingoDotDevEngine = class {
452
481
  trackProps
453
482
  );
454
483
  try {
484
+ const mapped = chat.reduce(
485
+ (acc, msg, i) => {
486
+ acc[`chat_${i}`] = msg.text;
487
+ return acc;
488
+ },
489
+ {}
490
+ );
455
491
  const localized = await this._localizeRaw(
456
- { chat },
492
+ mapped,
457
493
  params,
458
494
  progressCallback,
459
495
  signal
@@ -641,12 +677,10 @@ var LingoDotDevEngine = class {
641
677
  trackProps
642
678
  );
643
679
  try {
644
- const response = await fetch(`${this.config.apiUrl}/recognize`, {
680
+ const url = this.isVNext ? `${this.config.apiUrl}/process/recognize` : `${this.config.apiUrl}/recognize`;
681
+ const response = await fetch(url, {
645
682
  method: "POST",
646
- headers: {
647
- "Content-Type": "application/json; charset=utf-8",
648
- Authorization: `Bearer ${this.config.apiKey}`
649
- },
683
+ headers: this.headers,
650
684
  body: JSON.stringify({ text }),
651
685
  signal
652
686
  });
@@ -680,6 +714,9 @@ var LingoDotDevEngine = class {
680
714
  }
681
715
  }
682
716
  async whoami(signal) {
717
+ if (this.isVNext) {
718
+ return { email: "vnext-user", id: this.config.engineId };
719
+ }
683
720
  try {
684
721
  const res = await fetch(`${this.config.apiUrl}/whoami`, {
685
722
  method: "POST",
@@ -712,8 +749,8 @@ var LingoDotDevEngine = class {
712
749
  return null;
713
750
  }
714
751
  }
715
- };
716
- var ReplexicaEngine = (_class = class _ReplexicaEngine extends LingoDotDevEngine {
752
+ }, _class);
753
+ var ReplexicaEngine = (_class2 = class _ReplexicaEngine extends LingoDotDevEngine {
717
754
  static __initStatic() {this.hasWarnedDeprecation = false}
718
755
  constructor(config) {
719
756
  super(config);
@@ -724,8 +761,8 @@ var ReplexicaEngine = (_class = class _ReplexicaEngine extends LingoDotDevEngine
724
761
  _ReplexicaEngine.hasWarnedDeprecation = true;
725
762
  }
726
763
  }
727
- }, _class.__initStatic(), _class);
728
- var LingoEngine = (_class2 = class _LingoEngine extends LingoDotDevEngine {
764
+ }, _class2.__initStatic(), _class2);
765
+ var LingoEngine = (_class3 = class _LingoEngine extends LingoDotDevEngine {
729
766
  static __initStatic2() {this.hasWarnedDeprecation = false}
730
767
  constructor(config) {
731
768
  super(config);
@@ -736,7 +773,7 @@ var LingoEngine = (_class2 = class _LingoEngine extends LingoDotDevEngine {
736
773
  _LingoEngine.hasWarnedDeprecation = true;
737
774
  }
738
775
  }
739
- }, _class2.__initStatic2(), _class2);
776
+ }, _class3.__initStatic2(), _class3);
740
777
 
741
778
 
742
779
 
package/build/index.d.cts CHANGED
@@ -6,6 +6,7 @@ declare const engineParamsSchema: Z.ZodObject<{
6
6
  apiUrl: Z.ZodDefault<Z.ZodString>;
7
7
  batchSize: Z.ZodDefault<Z.ZodNumber>;
8
8
  idealBatchItemSize: Z.ZodDefault<Z.ZodNumber>;
9
+ engineId: Z.ZodOptional<Z.ZodString>;
9
10
  }, Z.core.$loose>;
10
11
  declare const payloadSchema: Z.ZodRecord<Z.ZodString, Z.ZodAny>;
11
12
  declare const localizationParamsSchema: Z.ZodObject<{
@@ -14,6 +15,11 @@ declare const localizationParamsSchema: Z.ZodObject<{
14
15
  fast: Z.ZodOptional<Z.ZodBoolean>;
15
16
  reference: Z.ZodOptional<Z.ZodRecord<Z.ZodString, Z.ZodRecord<Z.ZodString, Z.ZodAny>>>;
16
17
  hints: Z.ZodOptional<Z.ZodRecord<Z.ZodString, Z.ZodArray<Z.ZodString>>>;
18
+ filePath: Z.ZodOptional<Z.ZodString>;
19
+ triggerType: Z.ZodOptional<Z.ZodEnum<{
20
+ cli: "cli";
21
+ ci: "ci";
22
+ }>>;
17
23
  }, Z.core.$strip>;
18
24
  /**
19
25
  * LingoDotDevEngine class for interacting with the LingoDotDev API
@@ -22,6 +28,9 @@ declare const localizationParamsSchema: Z.ZodObject<{
22
28
  */
23
29
  declare class LingoDotDevEngine {
24
30
  protected config: Z.infer<typeof engineParamsSchema>;
31
+ private readonly sessionId;
32
+ private get isVNext();
33
+ private get headers();
25
34
  /**
26
35
  * Create a new LingoDotDevEngine instance
27
36
  * @param config - Configuration options for the Engine
@@ -44,6 +53,8 @@ declare class LingoDotDevEngine {
44
53
  * @param payload - Payload containing the chunk to be localized
45
54
  * @param workflowId - Workflow ID for tracking
46
55
  * @param fast - Whether to use fast mode
56
+ * @param filePath - Optional file path for metadata
57
+ * @param triggerType - Optional trigger type for vNext requests
47
58
  * @param signal - Optional AbortSignal to cancel the operation
48
59
  * @returns Localized chunk
49
60
  */
package/build/index.d.ts CHANGED
@@ -6,6 +6,7 @@ declare const engineParamsSchema: Z.ZodObject<{
6
6
  apiUrl: Z.ZodDefault<Z.ZodString>;
7
7
  batchSize: Z.ZodDefault<Z.ZodNumber>;
8
8
  idealBatchItemSize: Z.ZodDefault<Z.ZodNumber>;
9
+ engineId: Z.ZodOptional<Z.ZodString>;
9
10
  }, Z.core.$loose>;
10
11
  declare const payloadSchema: Z.ZodRecord<Z.ZodString, Z.ZodAny>;
11
12
  declare const localizationParamsSchema: Z.ZodObject<{
@@ -14,6 +15,11 @@ declare const localizationParamsSchema: Z.ZodObject<{
14
15
  fast: Z.ZodOptional<Z.ZodBoolean>;
15
16
  reference: Z.ZodOptional<Z.ZodRecord<Z.ZodString, Z.ZodRecord<Z.ZodString, Z.ZodAny>>>;
16
17
  hints: Z.ZodOptional<Z.ZodRecord<Z.ZodString, Z.ZodArray<Z.ZodString>>>;
18
+ filePath: Z.ZodOptional<Z.ZodString>;
19
+ triggerType: Z.ZodOptional<Z.ZodEnum<{
20
+ cli: "cli";
21
+ ci: "ci";
22
+ }>>;
17
23
  }, Z.core.$strip>;
18
24
  /**
19
25
  * LingoDotDevEngine class for interacting with the LingoDotDev API
@@ -22,6 +28,9 @@ declare const localizationParamsSchema: Z.ZodObject<{
22
28
  */
23
29
  declare class LingoDotDevEngine {
24
30
  protected config: Z.infer<typeof engineParamsSchema>;
31
+ private readonly sessionId;
32
+ private get isVNext();
33
+ private get headers();
25
34
  /**
26
35
  * Create a new LingoDotDevEngine instance
27
36
  * @param config - Configuration options for the Engine
@@ -44,6 +53,8 @@ declare class LingoDotDevEngine {
44
53
  * @param payload - Payload containing the chunk to be localized
45
54
  * @param workflowId - Workflow ID for tracking
46
55
  * @param fast - Whether to use fast mode
56
+ * @param filePath - Optional file path for metadata
57
+ * @param triggerType - Optional trigger type for vNext requests
47
58
  * @param signal - Optional AbortSignal to cancel the operation
48
59
  * @returns Localized chunk
49
60
  */
package/build/index.mjs CHANGED
@@ -97,7 +97,8 @@ var engineParamsSchema = Z.object({
97
97
  apiKey: Z.string(),
98
98
  apiUrl: Z.string().url().default("https://engine.lingo.dev"),
99
99
  batchSize: Z.number().int().gt(0).lte(250).default(25),
100
- idealBatchItemSize: Z.number().int().gt(0).lte(2500).default(250)
100
+ idealBatchItemSize: Z.number().int().gt(0).lte(2500).default(250),
101
+ engineId: Z.string().optional()
101
102
  }).passthrough();
102
103
  var payloadSchema = Z.record(Z.string(), Z.any());
103
104
  var referenceSchema = Z.record(localeCodeSchema, payloadSchema);
@@ -107,16 +108,35 @@ var localizationParamsSchema = Z.object({
107
108
  targetLocale: localeCodeSchema,
108
109
  fast: Z.boolean().optional(),
109
110
  reference: referenceSchema.optional(),
110
- hints: hintsSchema.optional()
111
+ hints: hintsSchema.optional(),
112
+ filePath: Z.string().optional(),
113
+ triggerType: Z.enum(["cli", "ci"]).optional()
111
114
  });
112
115
  var LingoDotDevEngine = class {
113
116
  config;
117
+ sessionId = createId();
118
+ get isVNext() {
119
+ return !!this.config.engineId;
120
+ }
121
+ get headers() {
122
+ return this.isVNext ? {
123
+ "Content-Type": "application/json; charset=utf-8",
124
+ "X-API-Key": this.config.apiKey
125
+ } : {
126
+ "Content-Type": "application/json; charset=utf-8",
127
+ Authorization: `Bearer ${this.config.apiKey}`
128
+ };
129
+ }
114
130
  /**
115
131
  * Create a new LingoDotDevEngine instance
116
132
  * @param config - Configuration options for the Engine
117
133
  */
118
134
  constructor(config) {
119
- this.config = engineParamsSchema.parse(config);
135
+ const parsed = engineParamsSchema.parse(config);
136
+ if (!config.apiUrl && parsed.engineId) {
137
+ parsed.apiUrl = "https://api.lingo.dev";
138
+ }
139
+ this.config = parsed;
120
140
  }
121
141
  /**
122
142
  * Localize content using the Lingo.dev API
@@ -144,6 +164,8 @@ var LingoDotDevEngine = class {
144
164
  { data: chunk, reference: params.reference, hints: params.hints },
145
165
  workflowId,
146
166
  params.fast || false,
167
+ params.filePath,
168
+ params.triggerType,
147
169
  signal
148
170
  );
149
171
  if (progressCallback) {
@@ -160,30 +182,37 @@ var LingoDotDevEngine = class {
160
182
  * @param payload - Payload containing the chunk to be localized
161
183
  * @param workflowId - Workflow ID for tracking
162
184
  * @param fast - Whether to use fast mode
185
+ * @param filePath - Optional file path for metadata
186
+ * @param triggerType - Optional trigger type for vNext requests
163
187
  * @param signal - Optional AbortSignal to cancel the operation
164
188
  * @returns Localized chunk
165
189
  */
166
- async localizeChunk(sourceLocale, targetLocale, payload, workflowId, fast, signal) {
167
- const res = await fetch(`${this.config.apiUrl}/i18n`, {
168
- method: "POST",
169
- headers: {
170
- "Content-Type": "application/json; charset=utf-8",
171
- Authorization: `Bearer ${this.config.apiKey}`
190
+ async localizeChunk(sourceLocale, targetLocale, payload, workflowId, fast, filePath, triggerType, signal) {
191
+ const url = this.isVNext ? `${this.config.apiUrl}/process/${this.config.engineId}/localize` : `${this.config.apiUrl}/i18n`;
192
+ const body = this.isVNext ? {
193
+ params: { fast },
194
+ sourceLocale,
195
+ targetLocale,
196
+ data: payload.data,
197
+ reference: payload.reference,
198
+ hints: payload.hints,
199
+ sessionId: this.sessionId,
200
+ triggerType,
201
+ metadata: filePath ? { filePath } : void 0
202
+ } : {
203
+ params: { workflowId, fast },
204
+ locale: {
205
+ source: sourceLocale,
206
+ target: targetLocale
172
207
  },
173
- body: JSON.stringify(
174
- {
175
- params: { workflowId, fast },
176
- locale: {
177
- source: sourceLocale,
178
- target: targetLocale
179
- },
180
- data: payload.data,
181
- reference: payload.reference,
182
- hints: payload.hints
183
- },
184
- null,
185
- 2
186
- ),
208
+ data: payload.data,
209
+ reference: payload.reference,
210
+ hints: payload.hints
211
+ };
212
+ const res = await fetch(url, {
213
+ method: "POST",
214
+ headers: this.headers,
215
+ body: JSON.stringify(body, null, 2),
187
216
  signal
188
217
  });
189
218
  if (!res.ok) {
@@ -452,8 +481,15 @@ var LingoDotDevEngine = class {
452
481
  trackProps
453
482
  );
454
483
  try {
484
+ const mapped = chat.reduce(
485
+ (acc, msg, i) => {
486
+ acc[`chat_${i}`] = msg.text;
487
+ return acc;
488
+ },
489
+ {}
490
+ );
455
491
  const localized = await this._localizeRaw(
456
- { chat },
492
+ mapped,
457
493
  params,
458
494
  progressCallback,
459
495
  signal
@@ -641,12 +677,10 @@ var LingoDotDevEngine = class {
641
677
  trackProps
642
678
  );
643
679
  try {
644
- const response = await fetch(`${this.config.apiUrl}/recognize`, {
680
+ const url = this.isVNext ? `${this.config.apiUrl}/process/recognize` : `${this.config.apiUrl}/recognize`;
681
+ const response = await fetch(url, {
645
682
  method: "POST",
646
- headers: {
647
- "Content-Type": "application/json; charset=utf-8",
648
- Authorization: `Bearer ${this.config.apiKey}`
649
- },
683
+ headers: this.headers,
650
684
  body: JSON.stringify({ text }),
651
685
  signal
652
686
  });
@@ -680,6 +714,9 @@ var LingoDotDevEngine = class {
680
714
  }
681
715
  }
682
716
  async whoami(signal) {
717
+ if (this.isVNext) {
718
+ return { email: "vnext-user", id: this.config.engineId };
719
+ }
683
720
  try {
684
721
  const res = await fetch(`${this.config.apiUrl}/whoami`, {
685
722
  method: "POST",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingo.dev/_sdk",
3
- "version": "0.15.0",
3
+ "version": "0.15.2",
4
4
  "description": "Lingo.dev JS SDK",
5
5
  "private": false,
6
6
  "repository": {
@@ -28,7 +28,7 @@
28
28
  "jsdom": "25.0.1",
29
29
  "posthog-node": "5.14.0",
30
30
  "zod": "4.1.12",
31
- "@lingo.dev/_spec": "0.48.0"
31
+ "@lingo.dev/_spec": "0.48.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/jsdom": "21.1.7",