@braze/sanity-plugin-ai-translation 0.2.3 → 0.2.4
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/dist/index.d.ts +146 -1
- package/dist/index.js +532 -62
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,30 @@ export declare const aiTranslationPlugin: Plugin_2<PluginConfig>;
|
|
|
38
38
|
*/
|
|
39
39
|
export declare type AnyFieldTransform = FieldTransform<any, any>;
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Common enum field names that are typically excluded from translation
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
export declare const COMMON_ENUM_FIELDS: readonly [
|
|
46
|
+
"status",
|
|
47
|
+
"state",
|
|
48
|
+
"type",
|
|
49
|
+
"category",
|
|
50
|
+
"priority",
|
|
51
|
+
"visibility",
|
|
52
|
+
"role",
|
|
53
|
+
"permission",
|
|
54
|
+
"level",
|
|
55
|
+
"mode",
|
|
56
|
+
"format",
|
|
57
|
+
"variant",
|
|
58
|
+
"size",
|
|
59
|
+
"theme",
|
|
60
|
+
"kind",
|
|
61
|
+
"phase",
|
|
62
|
+
"stage",
|
|
63
|
+
];
|
|
64
|
+
|
|
41
65
|
/**
|
|
42
66
|
* Criteria for matching fields that should be transformed.
|
|
43
67
|
* @public
|
|
@@ -169,6 +193,36 @@ export declare interface FieldTransform<
|
|
|
169
193
|
) => TOriginal;
|
|
170
194
|
}
|
|
171
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Result of filtering excluded fields from a document
|
|
198
|
+
* @internal
|
|
199
|
+
*/
|
|
200
|
+
export declare interface FilteredDocument<T = any> {
|
|
201
|
+
/** Document with excluded fields removed */
|
|
202
|
+
filteredDocument: T;
|
|
203
|
+
/** Excluded field values that were removed */
|
|
204
|
+
excludedValues: Record<string, any>;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Recursively filters out excluded fields from a document
|
|
209
|
+
* @param document - The document to filter
|
|
210
|
+
* @param excludeFields - Array of field patterns to exclude. Supports:
|
|
211
|
+
* - Field names: 'status' (matches any field named 'status' anywhere)
|
|
212
|
+
* - Exact paths: 'meta.category' (matches only 'category' under 'meta')
|
|
213
|
+
* - Array paths: 'body[0].imageType' (matches 'imageType' in first array item)
|
|
214
|
+
* - Wildcard arrays: 'body[*].imageType' (matches 'imageType' in any array item)
|
|
215
|
+
* - Hierarchical: '**.status' (explicitly matches 'status' anywhere - same as just 'status')
|
|
216
|
+
* @param currentPath - Current path in the document (used internally)
|
|
217
|
+
* @returns Filtered document and excluded values
|
|
218
|
+
* @internal
|
|
219
|
+
*/
|
|
220
|
+
export declare function filterExcludedFields<T extends Record<string, any>>(
|
|
221
|
+
document: T,
|
|
222
|
+
excludeFields?: string[],
|
|
223
|
+
currentPath?: string,
|
|
224
|
+
): FilteredDocument<T>;
|
|
225
|
+
|
|
172
226
|
/**
|
|
173
227
|
* Helper type to infer the original type from a FieldTransform.
|
|
174
228
|
* Useful for type checking and creating wrapper functions.
|
|
@@ -233,14 +287,105 @@ export declare interface PluginConfig {
|
|
|
233
287
|
maxReferenceDepth?: number;
|
|
234
288
|
openai?: {
|
|
235
289
|
apiKey: string;
|
|
236
|
-
model?:
|
|
290
|
+
model?:
|
|
291
|
+
| "gpt-5.1"
|
|
292
|
+
| "gpt-5"
|
|
293
|
+
| "gpt-5-mini"
|
|
294
|
+
| "gpt-5-nano"
|
|
295
|
+
| "gpt-5-pro"
|
|
296
|
+
| "gpt-4o"
|
|
297
|
+
| "gpt-4-turbo"
|
|
298
|
+
| "gpt-4";
|
|
237
299
|
reasoningEffort?: "low" | "medium" | "high";
|
|
238
300
|
enabled?: boolean;
|
|
239
301
|
defaultMode?: TranslationMode;
|
|
240
302
|
};
|
|
241
303
|
fieldTransforms?: AnyFieldTransform[];
|
|
304
|
+
/**
|
|
305
|
+
* Fields to exclude from translation. These fields will be preserved as-is in the translated document.
|
|
306
|
+
* Supports field names (e.g., 'status') and nested field paths (e.g., 'meta.category').
|
|
307
|
+
* Useful for enum fields, IDs, technical values, and other non-translatable content.
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```typescript
|
|
311
|
+
* excludeFields: ['status', 'category', 'type', 'meta.priority', 'config.mode']
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
excludeFields?: string[];
|
|
242
315
|
}
|
|
243
316
|
|
|
317
|
+
/**
|
|
318
|
+
* Predefined exclusion lists for common use cases
|
|
319
|
+
* @internal
|
|
320
|
+
*/
|
|
321
|
+
export declare const PREDEFINED_EXCLUSIONS: {
|
|
322
|
+
/** Common enum and status fields */
|
|
323
|
+
readonly enums: readonly [
|
|
324
|
+
"status",
|
|
325
|
+
"state",
|
|
326
|
+
"type",
|
|
327
|
+
"category",
|
|
328
|
+
"priority",
|
|
329
|
+
"visibility",
|
|
330
|
+
"role",
|
|
331
|
+
"permission",
|
|
332
|
+
"level",
|
|
333
|
+
"mode",
|
|
334
|
+
"format",
|
|
335
|
+
"variant",
|
|
336
|
+
"size",
|
|
337
|
+
"theme",
|
|
338
|
+
"kind",
|
|
339
|
+
"phase",
|
|
340
|
+
"stage",
|
|
341
|
+
];
|
|
342
|
+
/** All metadata and system fields (starting with _) */
|
|
343
|
+
readonly metadata: readonly [
|
|
344
|
+
"_id",
|
|
345
|
+
"_type",
|
|
346
|
+
"_rev",
|
|
347
|
+
"_createdAt",
|
|
348
|
+
"_updatedAt",
|
|
349
|
+
];
|
|
350
|
+
/** Common technical and configuration fields */
|
|
351
|
+
readonly technical: readonly [
|
|
352
|
+
"slug",
|
|
353
|
+
"handle",
|
|
354
|
+
"key",
|
|
355
|
+
"code",
|
|
356
|
+
"id",
|
|
357
|
+
"uuid",
|
|
358
|
+
"token",
|
|
359
|
+
"hash",
|
|
360
|
+
"checksum",
|
|
361
|
+
"version",
|
|
362
|
+
"config",
|
|
363
|
+
"settings",
|
|
364
|
+
];
|
|
365
|
+
/** SEO and URL-related fields that often shouldn't be translated */
|
|
366
|
+
readonly seo: readonly [
|
|
367
|
+
"slug",
|
|
368
|
+
"handle",
|
|
369
|
+
"permalink",
|
|
370
|
+
"canonical",
|
|
371
|
+
"redirect",
|
|
372
|
+
"robots",
|
|
373
|
+
"sitemap",
|
|
374
|
+
];
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Restores previously excluded fields to a translated document
|
|
379
|
+
* @param translatedDocument - The translated document
|
|
380
|
+
* @param excludedValues - The excluded field values to restore
|
|
381
|
+
* @returns Document with excluded fields restored
|
|
382
|
+
* @internal
|
|
383
|
+
*/
|
|
384
|
+
export declare function restoreExcludedFields<T extends Record<string, any>>(
|
|
385
|
+
translatedDocument: T,
|
|
386
|
+
excludedValues: Record<string, any>,
|
|
387
|
+
): T;
|
|
388
|
+
|
|
244
389
|
/**
|
|
245
390
|
* Transform for handling Portable Text (rich text) content using XML-like serialization.
|
|
246
391
|
* This leverages the existing serialization utilities to convert complex rich text
|