@braze/sanity-plugin-ai-translation 0.2.85 → 0.2.86

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 CHANGED
@@ -3409,18 +3409,19 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
3409
3409
  padding: 2
3410
3410
  }
3411
3411
  );
3412
- }, DocumentValidator = ({ documentId, documentType, onResult }) => {
3412
+ }, DocumentValidator = ({ documentId, documentType, perspective, onResult }) => {
3413
3413
  const client = useClient({ apiVersion: "vX" }), workspace = useWorkspace(), hasRun = useRef(!1);
3414
3414
  return useEffect(() => {
3415
3415
  hasRun.current || (hasRun.current = !0, (async () => {
3416
3416
  onResult(documentId, { isValidating: !0, errors: [] });
3417
3417
  try {
3418
- const publishedId = getPublishedId(documentId), draftId = `drafts.${publishedId}`, doc = await client.fetch(
3418
+ const publishedId = getPublishedId(documentId), draftId = `drafts.${publishedId}`;
3419
+ let doc;
3420
+ if (perspective === "published" ? doc = await client.fetch("*[_id == $publishedId][0]", { publishedId }) : doc = await client.fetch(
3419
3421
  "*[_id in [$draftId, $publishedId]] | order(_id desc) [0]",
3420
3422
  { draftId, publishedId }
3421
- );
3422
- if (!doc) {
3423
- devLog.warn("Document not found for validation", { documentId }), onResult(documentId, { isValidating: !1, errors: [] });
3423
+ ), !doc) {
3424
+ devLog.warn("Document not found for validation", { documentId, perspective }), onResult(documentId, { isValidating: !1, errors: [] });
3424
3425
  return;
3425
3426
  }
3426
3427
  const errors = (await validateDocument({
@@ -3430,6 +3431,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
3430
3431
  })).filter((m) => m.level === "error");
3431
3432
  errors.length > 0 && devLog.debug("Validation errors found", {
3432
3433
  documentId,
3434
+ perspective,
3433
3435
  errorCount: errors.length,
3434
3436
  component: "DocumentValidator"
3435
3437
  }), onResult(documentId, { isValidating: !1, errors });
@@ -3441,7 +3443,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
3441
3443
  ), onResult(documentId, { isValidating: !1, errors: [] });
3442
3444
  }
3443
3445
  })());
3444
- }, [documentId, documentType, onResult, client, workspace]), null;
3446
+ }, [documentId, documentType, perspective, onResult, client, workspace]), null;
3445
3447
  }, PreflightView = () => {
3446
3448
  const {
3447
3449
  document,
@@ -3676,6 +3678,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
3676
3678
  {
3677
3679
  documentId: doc._id,
3678
3680
  documentType: doc._type,
3681
+ perspective: documentSource === "published" ? "published" : "drafts",
3679
3682
  onResult: handleValidationResult
3680
3683
  },
3681
3684
  `${doc._id}-${scanKey}`