@docmana/sdk 0.47.0 → 0.48.0
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/CHANGELOG.md +6 -0
- package/README.md +32 -0
- package/dist/cli.mjs +55 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +55 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -1
- package/dist/index.mjs.map +1 -1
- package/dist/reviews.d.ts +17 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -666,12 +666,66 @@ var Reviews = class {
|
|
|
666
666
|
query: {
|
|
667
667
|
organization: options.organization,
|
|
668
668
|
...options.version ? { v: options.version } : {},
|
|
669
|
-
...options.size ? { size: options.size } : {}
|
|
669
|
+
...options.size ? { size: options.size } : {},
|
|
670
|
+
...options.language ? { language: options.language } : {}
|
|
670
671
|
}
|
|
671
672
|
}
|
|
672
673
|
);
|
|
673
674
|
}
|
|
675
|
+
async requestDocumentTranslation(executionId, docKey, language, options) {
|
|
676
|
+
if (!options.organization?.trim()) throw new Error("Organization is required");
|
|
677
|
+
if (!language?.trim()) throw new Error("Language is required");
|
|
678
|
+
const response = await this.http.requestRaw(
|
|
679
|
+
"POST",
|
|
680
|
+
`/executions/${segment(executionId)}/review/documents/${segment(docKey)}/translations`,
|
|
681
|
+
{
|
|
682
|
+
signal: options.signal,
|
|
683
|
+
query: { organization: options.organization },
|
|
684
|
+
headers: { "content-type": "application/json" },
|
|
685
|
+
body: JSON.stringify({ language })
|
|
686
|
+
}
|
|
687
|
+
);
|
|
688
|
+
let body;
|
|
689
|
+
try {
|
|
690
|
+
body = await response.json();
|
|
691
|
+
} catch (error) {
|
|
692
|
+
if (options.signal?.aborted || error instanceof Error && error.name === "AbortError")
|
|
693
|
+
throw new DocmanaAbortError("Request aborted");
|
|
694
|
+
throw new DocmanaError("Invalid document translation response", {
|
|
695
|
+
status: response.status,
|
|
696
|
+
requestId: response.headers.get("x-request-id") ?? void 0,
|
|
697
|
+
code: "invalid_translation_response"
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
return parseDocumentTranslation(body, response.status === 202 ? 202 : 200, response);
|
|
701
|
+
}
|
|
674
702
|
};
|
|
703
|
+
var VARIANTS = ["original", "translation"];
|
|
704
|
+
var TRANSLATION_STATES = [
|
|
705
|
+
"absent",
|
|
706
|
+
"preparing",
|
|
707
|
+
"ready",
|
|
708
|
+
"failed",
|
|
709
|
+
"unsupported"
|
|
710
|
+
];
|
|
711
|
+
function parseDocumentTranslation(body, status, response) {
|
|
712
|
+
const data = typeof body === "object" && body !== null ? body : {};
|
|
713
|
+
const servedLanguage = data.servedLanguage;
|
|
714
|
+
if (typeof data.requestedLanguage !== "string" || !(servedLanguage === null || typeof servedLanguage === "string") || !VARIANTS.includes(data.variant) || typeof data.fallback !== "boolean" || !TRANSLATION_STATES.includes(data.translationState))
|
|
715
|
+
throw new DocmanaError("Invalid document translation response", {
|
|
716
|
+
status: response.status,
|
|
717
|
+
requestId: response.headers.get("x-request-id") ?? void 0,
|
|
718
|
+
code: "invalid_translation_response"
|
|
719
|
+
});
|
|
720
|
+
return {
|
|
721
|
+
status,
|
|
722
|
+
requestedLanguage: data.requestedLanguage,
|
|
723
|
+
servedLanguage,
|
|
724
|
+
variant: data.variant,
|
|
725
|
+
fallback: data.fallback,
|
|
726
|
+
translationState: data.translationState
|
|
727
|
+
};
|
|
728
|
+
}
|
|
675
729
|
|
|
676
730
|
// src/sdk/execution-events.ts
|
|
677
731
|
import { createHmac as createHmac2, timingSafeEqual as timingSafeEqual2 } from "crypto";
|