@braze/sanity-plugin-ai-translation 0.2.21 → 0.2.22
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.js +22 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ const TranslationContext = createContext({
|
|
|
31
31
|
"useTranslationContext must be used within a TranslationContextProvider with document and config props"
|
|
32
32
|
);
|
|
33
33
|
return context;
|
|
34
|
-
}, TRANSLATION_METADATA_TYPE = "translation.metadata", undraftId = (id) => id.replace(/^drafts\./, ""), TRANSLATION_METADATA_QUERY = "*[_type == $translationMetadataType && references($documentId)][0]", useTranslationMetadata = ({ documentId }) => {
|
|
34
|
+
}, TRANSLATION_METADATA_TYPE = "translation.metadata", undraftId = (id) => id.replace(/^drafts\./, ""), draftId = (id) => `drafts.${undraftId(id)}`, TRANSLATION_METADATA_QUERY = "*[_type == $translationMetadataType && references($documentId)][0]", useTranslationMetadata = ({ documentId }) => {
|
|
35
35
|
const { dispatch } = useTranslationContext(), { data, loading, error } = useListeningQuery(TRANSLATION_METADATA_QUERY, {
|
|
36
36
|
params: {
|
|
37
37
|
documentId: undraftId(documentId),
|
|
@@ -2511,19 +2511,34 @@ ${glossaryTerms}`, buildStyleGuideSection = (globalPrompt, localePrompt) => {
|
|
|
2511
2511
|
...logContext,
|
|
2512
2512
|
existingTranslationId
|
|
2513
2513
|
});
|
|
2514
|
-
|
|
2514
|
+
let existingDoc = await client.getDocument(existingTranslationId), actualDocumentId = existingTranslationId;
|
|
2515
|
+
if (!existingDoc) {
|
|
2516
|
+
const alternateId = existingTranslationId.startsWith("drafts.") ? undraftId(existingTranslationId) : draftId(existingTranslationId);
|
|
2517
|
+
devLog.info("Document not found with stored ID, trying alternate ID", {
|
|
2518
|
+
...logContext,
|
|
2519
|
+
storedId: existingTranslationId,
|
|
2520
|
+
alternateId
|
|
2521
|
+
}), existingDoc = await client.getDocument(alternateId), existingDoc && (actualDocumentId = alternateId, devLog.info("Found document with alternate ID", {
|
|
2522
|
+
...logContext,
|
|
2523
|
+
actualDocumentId
|
|
2524
|
+
}));
|
|
2525
|
+
}
|
|
2515
2526
|
if (!existingDoc)
|
|
2516
|
-
throw new Error(
|
|
2527
|
+
throw new Error(
|
|
2528
|
+
`Existing translation document not found: ${existingTranslationId} (also tried ${existingTranslationId.startsWith("drafts.") ? undraftId(existingTranslationId) : draftId(existingTranslationId)})`
|
|
2529
|
+
);
|
|
2530
|
+
const publishedId = undraftId(actualDocumentId);
|
|
2517
2531
|
await client.action({
|
|
2518
2532
|
actionType: "sanity.action.document.version.create",
|
|
2519
|
-
publishedId
|
|
2533
|
+
publishedId,
|
|
2520
2534
|
document: {
|
|
2521
2535
|
...existingDoc,
|
|
2522
|
-
_id: `versions.${releaseId}.${
|
|
2536
|
+
_id: `versions.${releaseId}.${publishedId}`
|
|
2523
2537
|
}
|
|
2524
|
-
}), versionedDocumentId = `versions.${releaseId}.${
|
|
2538
|
+
}), versionedDocumentId = `versions.${releaseId}.${publishedId}`, baseDocumentId = publishedId, devLog.info("Existing translation version created", {
|
|
2525
2539
|
...logContext,
|
|
2526
|
-
versionedDocumentId
|
|
2540
|
+
versionedDocumentId,
|
|
2541
|
+
baseDocumentId
|
|
2527
2542
|
});
|
|
2528
2543
|
const { _id, _createdAt, _updatedAt, _rev, ...sourceContent } = sourceDocument;
|
|
2529
2544
|
await client.createOrReplace({
|