@braze/sanity-plugin-ai-translation 0.2.73 → 0.2.74
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 +14 -0
- package/dist/index.js +26 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -332,6 +332,20 @@ export declare interface PluginConfig {
|
|
|
332
332
|
* ```
|
|
333
333
|
*/
|
|
334
334
|
excludeFields?: string[];
|
|
335
|
+
/**
|
|
336
|
+
* Fields to completely remove from the translated document.
|
|
337
|
+
* Unlike `excludeFields` (which preserves fields with their original values),
|
|
338
|
+
* `unsetFields` strips matched fields entirely so they are absent from the output.
|
|
339
|
+
* Supports the same pattern syntax as `excludeFields`: field names (e.g., 'courseId'),
|
|
340
|
+
* nested paths (e.g., 'meta.internalId'), wildcard arrays (e.g., 'sections[*].legacyId'),
|
|
341
|
+
* and hierarchical matches (e.g., '**.tmpField').
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```typescript
|
|
345
|
+
* unsetFields: ['courseId', 'meta.internalId', 'sections[*].legacyId']
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
unsetFields?: string[];
|
|
335
349
|
/**
|
|
336
350
|
* Optional telemetry configuration for monitoring translation operations.
|
|
337
351
|
* Provides callbacks for lightweight events and detailed error bundles.
|
package/dist/index.js
CHANGED
|
@@ -1360,6 +1360,16 @@ const COMMON_ENUM_FIELDS = [
|
|
|
1360
1360
|
/** SEO and URL-related fields that often shouldn't be translated */
|
|
1361
1361
|
seo: ["slug", "handle", "permalink", "canonical", "redirect", "robots", "sitemap"]
|
|
1362
1362
|
};
|
|
1363
|
+
function unsetDocumentFields(document, unsetFields) {
|
|
1364
|
+
if (!unsetFields.length)
|
|
1365
|
+
return document;
|
|
1366
|
+
const { filteredDocument, excludedValues } = filterExcludedFields(document, unsetFields);
|
|
1367
|
+
return Object.keys(excludedValues).length > 0 && devLog.info("Unset fields from document (permanently removed)", {
|
|
1368
|
+
documentId: document._id || "unknown",
|
|
1369
|
+
unsetFieldCount: Object.keys(excludedValues).length,
|
|
1370
|
+
unsetFields: Object.keys(excludedValues)
|
|
1371
|
+
}), filteredDocument;
|
|
1372
|
+
}
|
|
1363
1373
|
function applyTransforms({
|
|
1364
1374
|
document,
|
|
1365
1375
|
registry,
|
|
@@ -2630,11 +2640,17 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
2630
2640
|
openaiConfig,
|
|
2631
2641
|
releaseId,
|
|
2632
2642
|
excludeFields = [],
|
|
2643
|
+
unsetFields = [],
|
|
2633
2644
|
replaceExisting = !1,
|
|
2634
2645
|
mainSourceDocumentId,
|
|
2635
2646
|
telemetryConfig
|
|
2636
2647
|
}) => {
|
|
2637
|
-
const startTime = Date.now(), sourceLanguage = sourceDocument[languageFieldName],
|
|
2648
|
+
const startTime = Date.now(), sourceLanguage = sourceDocument[languageFieldName], safeUnsetFields = unsetFields.filter((field) => field !== languageFieldName);
|
|
2649
|
+
unsetFields.length !== safeUnsetFields.length && devLog.warn("Language field was in unsetFields - removing it to prevent translation errors", {
|
|
2650
|
+
documentId: sourceDocument._id,
|
|
2651
|
+
languageFieldName
|
|
2652
|
+
});
|
|
2653
|
+
const documentAfterUnset = unsetDocumentFields(sourceDocument, safeUnsetFields), safeExcludeFields = excludeFields.filter((field) => field !== languageFieldName);
|
|
2638
2654
|
excludeFields.length !== safeExcludeFields.length && devLog.warn("Language field was in excludeFields - removing it to prevent translation errors", {
|
|
2639
2655
|
documentId: sourceDocument._id,
|
|
2640
2656
|
languageFieldName,
|
|
@@ -2645,10 +2661,10 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
2645
2661
|
documentType: sourceDocument._type,
|
|
2646
2662
|
excludeFields: safeExcludeFields,
|
|
2647
2663
|
excludeFieldsLength: safeExcludeFields?.length ?? 0,
|
|
2648
|
-
sourceHasTitle: "title" in
|
|
2649
|
-
sourceTitleValue:
|
|
2664
|
+
sourceHasTitle: "title" in documentAfterUnset,
|
|
2665
|
+
sourceTitleValue: documentAfterUnset.title
|
|
2650
2666
|
});
|
|
2651
|
-
const { filteredDocument, excludedValues } = filterExcludedFields(
|
|
2667
|
+
const { filteredDocument, excludedValues } = filterExcludedFields(documentAfterUnset, safeExcludeFields);
|
|
2652
2668
|
devLog.info("After filtering excluded fields", {
|
|
2653
2669
|
documentId: sourceDocument._id,
|
|
2654
2670
|
filteredHasTitle: "title" in filteredDocument,
|
|
@@ -2871,6 +2887,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
2871
2887
|
openaiConfig,
|
|
2872
2888
|
releaseId,
|
|
2873
2889
|
excludeFields,
|
|
2890
|
+
unsetFields,
|
|
2874
2891
|
replaceExisting,
|
|
2875
2892
|
mainSourceDocumentId,
|
|
2876
2893
|
telemetryConfig
|
|
@@ -2900,6 +2917,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
2900
2917
|
openaiConfig,
|
|
2901
2918
|
releaseId,
|
|
2902
2919
|
excludeFields,
|
|
2920
|
+
unsetFields,
|
|
2903
2921
|
replaceExisting,
|
|
2904
2922
|
mainSourceDocumentId,
|
|
2905
2923
|
telemetryConfig
|
|
@@ -3015,6 +3033,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3015
3033
|
translationMode,
|
|
3016
3034
|
openaiConfig,
|
|
3017
3035
|
excludeFields,
|
|
3036
|
+
unsetFields,
|
|
3018
3037
|
releaseConfig,
|
|
3019
3038
|
telemetryConfig
|
|
3020
3039
|
}) => {
|
|
@@ -3135,6 +3154,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3135
3154
|
openaiConfig,
|
|
3136
3155
|
releaseId,
|
|
3137
3156
|
excludeFields,
|
|
3157
|
+
unsetFields,
|
|
3138
3158
|
replaceExisting: releaseConfig.replaceExisting,
|
|
3139
3159
|
// Pass main source document ID for active translations tracking
|
|
3140
3160
|
mainSourceDocumentId: sourceDocument._id,
|
|
@@ -3319,6 +3339,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3319
3339
|
translationMode,
|
|
3320
3340
|
openaiConfig: config.openai,
|
|
3321
3341
|
excludeFields: config.excludeFields,
|
|
3342
|
+
unsetFields: config.unsetFields,
|
|
3322
3343
|
releaseConfig: {
|
|
3323
3344
|
...releaseConfig,
|
|
3324
3345
|
replaceExisting,
|
|
@@ -3341,6 +3362,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3341
3362
|
config.maxReferenceDepth,
|
|
3342
3363
|
config.openai,
|
|
3343
3364
|
config.excludeFields,
|
|
3365
|
+
config.unsetFields,
|
|
3344
3366
|
config.telemetry,
|
|
3345
3367
|
filteredReferences,
|
|
3346
3368
|
translationMode,
|