@lokalise/polyglot-sdk 13.0.0 → 13.1.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.
Files changed (31) hide show
  1. package/dist/index.d.ts +1 -2
  2. package/dist/index.js +2 -7
  3. package/dist/index.js.map +1 -1
  4. package/dist/sdk/PolyglotClient.d.ts +2 -2
  5. package/dist/sdk/PolyglotClient.js +2 -2
  6. package/dist/sdk/PolyglotClient.js.map +1 -1
  7. package/dist/sdk/schemas/common/commonSchemas.d.ts +2 -0
  8. package/dist/sdk/schemas/common/commonSchemas.js +26 -1
  9. package/dist/sdk/schemas/common/commonSchemas.js.map +1 -1
  10. package/dist/sdk/schemas/lqa/lqaAsyncSchemas.js +2 -2
  11. package/dist/sdk/schemas/lqa/lqaAsyncSchemas.js.map +1 -1
  12. package/dist/sdk/schemas/lqa/lqaSyncV2Schemas.js +2 -2
  13. package/dist/sdk/schemas/lqa/lqaSyncV2Schemas.js.map +1 -1
  14. package/dist/sdk/schemas/translation/sharedSchemas.d.ts +154 -0
  15. package/dist/sdk/schemas/translation/sharedSchemas.js +32 -1
  16. package/dist/sdk/schemas/translation/sharedSchemas.js.map +1 -1
  17. package/dist/sdk/schemas/translation/translateAsyncSchemas.d.ts +154 -141
  18. package/dist/sdk/schemas/translation/translateAsyncSchemas.js +7 -35
  19. package/dist/sdk/schemas/translation/translateAsyncSchemas.js.map +1 -1
  20. package/dist/sdk/schemas/translation/{translateSyncV2Schemas.d.ts → translateSyncSchemas.d.ts} +154 -144
  21. package/dist/sdk/schemas/translation/translateSyncSchemas.js +46 -0
  22. package/dist/sdk/schemas/translation/translateSyncSchemas.js.map +1 -0
  23. package/dist/sdk/validation/isSegmentExceedingLengthLimit.d.ts +0 -1
  24. package/dist/sdk/validation/isSegmentExceedingLengthLimit.js +3 -3
  25. package/dist/sdk/validation/isSegmentExceedingLengthLimit.js.map +1 -1
  26. package/dist/sdk/validation/requestSizeLimit.d.ts +14 -0
  27. package/dist/sdk/validation/requestSizeLimit.js +36 -0
  28. package/dist/sdk/validation/requestSizeLimit.js.map +1 -0
  29. package/package.json +5 -5
  30. package/dist/sdk/schemas/translation/translateSyncV2Schemas.js +0 -74
  31. package/dist/sdk/schemas/translation/translateSyncV2Schemas.js.map +0 -1
@@ -1,142 +1,5 @@
1
1
  import z from 'zod';
2
- export declare const TRANSLATE_SYNC_V2_SEGMENT_SCHEMA: z.ZodObject<{
3
- id: z.ZodString;
4
- tmMatch: z.ZodOptional<z.ZodObject<{
5
- sourceValue: z.ZodString;
6
- translatedValue: z.ZodString;
7
- }, "strip", z.ZodTypeAny, {
8
- sourceValue: string;
9
- translatedValue: string;
10
- }, {
11
- sourceValue: string;
12
- translatedValue: string;
13
- }>>;
14
- value: z.ZodEffects<z.ZodString, string, string>;
15
- }, "strip", z.ZodTypeAny, {
16
- value: string;
17
- id: string;
18
- tmMatch?: {
19
- sourceValue: string;
20
- translatedValue: string;
21
- } | undefined;
22
- }, {
23
- value: string;
24
- id: string;
25
- tmMatch?: {
26
- sourceValue: string;
27
- translatedValue: string;
28
- } | undefined;
29
- }>;
30
- export declare const TRANSLATE_SYNC_V2_CONTENT_UNIT_SCHEMA: z.ZodObject<{
31
- id: z.ZodString;
32
- context: z.ZodOptional<z.ZodObject<{
33
- description: z.ZodString;
34
- }, "strip", z.ZodTypeAny, {
35
- description: string;
36
- }, {
37
- description: string;
38
- }>>;
39
- characterLimit: z.ZodOptional<z.ZodNumber>;
40
- segments: z.ZodEffects<z.ZodArray<z.ZodObject<{
41
- id: z.ZodString;
42
- tmMatch: z.ZodOptional<z.ZodObject<{
43
- sourceValue: z.ZodString;
44
- translatedValue: z.ZodString;
45
- }, "strip", z.ZodTypeAny, {
46
- sourceValue: string;
47
- translatedValue: string;
48
- }, {
49
- sourceValue: string;
50
- translatedValue: string;
51
- }>>;
52
- value: z.ZodEffects<z.ZodString, string, string>;
53
- }, "strip", z.ZodTypeAny, {
54
- value: string;
55
- id: string;
56
- tmMatch?: {
57
- sourceValue: string;
58
- translatedValue: string;
59
- } | undefined;
60
- }, {
61
- value: string;
62
- id: string;
63
- tmMatch?: {
64
- sourceValue: string;
65
- translatedValue: string;
66
- } | undefined;
67
- }>, "atleastone">, [{
68
- value: string;
69
- id: string;
70
- tmMatch?: {
71
- sourceValue: string;
72
- translatedValue: string;
73
- } | undefined;
74
- }, ...{
75
- value: string;
76
- id: string;
77
- tmMatch?: {
78
- sourceValue: string;
79
- translatedValue: string;
80
- } | undefined;
81
- }[]], [{
82
- value: string;
83
- id: string;
84
- tmMatch?: {
85
- sourceValue: string;
86
- translatedValue: string;
87
- } | undefined;
88
- }, ...{
89
- value: string;
90
- id: string;
91
- tmMatch?: {
92
- sourceValue: string;
93
- translatedValue: string;
94
- } | undefined;
95
- }[]]>;
96
- }, "strip", z.ZodTypeAny, {
97
- id: string;
98
- segments: [{
99
- value: string;
100
- id: string;
101
- tmMatch?: {
102
- sourceValue: string;
103
- translatedValue: string;
104
- } | undefined;
105
- }, ...{
106
- value: string;
107
- id: string;
108
- tmMatch?: {
109
- sourceValue: string;
110
- translatedValue: string;
111
- } | undefined;
112
- }[]];
113
- context?: {
114
- description: string;
115
- } | undefined;
116
- characterLimit?: number | undefined;
117
- }, {
118
- id: string;
119
- segments: [{
120
- value: string;
121
- id: string;
122
- tmMatch?: {
123
- sourceValue: string;
124
- translatedValue: string;
125
- } | undefined;
126
- }, ...{
127
- value: string;
128
- id: string;
129
- tmMatch?: {
130
- sourceValue: string;
131
- translatedValue: string;
132
- } | undefined;
133
- }[]];
134
- context?: {
135
- description: string;
136
- } | undefined;
137
- characterLimit?: number | undefined;
138
- }>;
139
- export declare const TRANSLATE_SYNC_V2_BODY_SCHEMA: z.ZodEffects<z.ZodObject<{
2
+ export declare const TRANSLATE_SYNC_V2_BODY_SCHEMA: z.ZodEffects<z.ZodEffects<z.ZodObject<{
140
3
  tenantId: z.ZodOptional<z.ZodString>;
141
4
  ownerId: z.ZodOptional<z.ZodString>;
142
5
  sourceLocale: z.ZodEffects<z.ZodString, string, string>;
@@ -317,7 +180,7 @@ export declare const TRANSLATE_SYNC_V2_BODY_SCHEMA: z.ZodEffects<z.ZodObject<{
317
180
  sourceValue: string;
318
181
  translatedValue: string;
319
182
  }>>;
320
- value: z.ZodEffects<z.ZodString, string, string>;
183
+ value: z.ZodString;
321
184
  }, "strip", z.ZodTypeAny, {
322
185
  value: string;
323
186
  id: string;
@@ -780,6 +643,152 @@ export declare const TRANSLATE_SYNC_V2_BODY_SCHEMA: z.ZodEffects<z.ZodObject<{
780
643
  } | undefined;
781
644
  integration?: "Claude" | "ChatGPT-4" | "Gemini" | "DeepL" | "GoogleTranslate" | "MicrosoftTranslator" | undefined;
782
645
  tenantId?: string | undefined;
646
+ }>, {
647
+ sourceLocale: string;
648
+ contentUnits: [{
649
+ id: string;
650
+ segments: [{
651
+ value: string;
652
+ id: string;
653
+ tmMatch?: {
654
+ sourceValue: string;
655
+ translatedValue: string;
656
+ } | undefined;
657
+ }, ...{
658
+ value: string;
659
+ id: string;
660
+ tmMatch?: {
661
+ sourceValue: string;
662
+ translatedValue: string;
663
+ } | undefined;
664
+ }[]];
665
+ context?: {
666
+ description: string;
667
+ } | undefined;
668
+ characterLimit?: number | undefined;
669
+ }, ...{
670
+ id: string;
671
+ segments: [{
672
+ value: string;
673
+ id: string;
674
+ tmMatch?: {
675
+ sourceValue: string;
676
+ translatedValue: string;
677
+ } | undefined;
678
+ }, ...{
679
+ value: string;
680
+ id: string;
681
+ tmMatch?: {
682
+ sourceValue: string;
683
+ translatedValue: string;
684
+ } | undefined;
685
+ }[]];
686
+ context?: {
687
+ description: string;
688
+ } | undefined;
689
+ characterLimit?: number | undefined;
690
+ }[]];
691
+ targetLocale: string;
692
+ ownerId?: string | undefined;
693
+ context?: {
694
+ description?: string | undefined;
695
+ styleGuide?: {
696
+ targetAudience?: "general" | "technical" | "non-technical" | undefined;
697
+ toneOfVoice?: "friendly" | "empowering" | "informative" | "supportive" | "elegant" | undefined;
698
+ levelOfFormality?: "informal" | "formal" | "neutral" | undefined;
699
+ generalRule?: "active-voice" | "passive-voice" | undefined;
700
+ } | {
701
+ text: string;
702
+ } | undefined;
703
+ glossary?: {
704
+ term: string;
705
+ translatable: boolean;
706
+ forbidden: boolean;
707
+ caseSensitive: boolean;
708
+ description?: string | undefined;
709
+ translations?: {
710
+ locale: string;
711
+ translation: string;
712
+ description?: string | undefined;
713
+ }[] | undefined;
714
+ }[] | undefined;
715
+ targetPluralForms?: ["many" | "zero" | "one" | "two" | "few" | "other", ...("many" | "zero" | "one" | "two" | "few" | "other")[]] | undefined;
716
+ } | undefined;
717
+ integration?: "Claude" | "ChatGPT-4" | "Gemini" | "DeepL" | "GoogleTranslate" | "MicrosoftTranslator" | undefined;
718
+ tenantId?: string | undefined;
719
+ }, {
720
+ sourceLocale: string;
721
+ contentUnits: [{
722
+ id: string;
723
+ segments: [{
724
+ value: string;
725
+ id: string;
726
+ tmMatch?: {
727
+ sourceValue: string;
728
+ translatedValue: string;
729
+ } | undefined;
730
+ }, ...{
731
+ value: string;
732
+ id: string;
733
+ tmMatch?: {
734
+ sourceValue: string;
735
+ translatedValue: string;
736
+ } | undefined;
737
+ }[]];
738
+ context?: {
739
+ description: string;
740
+ } | undefined;
741
+ characterLimit?: number | undefined;
742
+ }, ...{
743
+ id: string;
744
+ segments: [{
745
+ value: string;
746
+ id: string;
747
+ tmMatch?: {
748
+ sourceValue: string;
749
+ translatedValue: string;
750
+ } | undefined;
751
+ }, ...{
752
+ value: string;
753
+ id: string;
754
+ tmMatch?: {
755
+ sourceValue: string;
756
+ translatedValue: string;
757
+ } | undefined;
758
+ }[]];
759
+ context?: {
760
+ description: string;
761
+ } | undefined;
762
+ characterLimit?: number | undefined;
763
+ }[]];
764
+ targetLocale: string;
765
+ ownerId?: string | undefined;
766
+ context?: {
767
+ description?: string | undefined;
768
+ styleGuide?: {
769
+ targetAudience?: "general" | "technical" | "non-technical" | undefined;
770
+ toneOfVoice?: "friendly" | "empowering" | "informative" | "supportive" | "elegant" | undefined;
771
+ levelOfFormality?: "informal" | "formal" | "neutral" | undefined;
772
+ generalRule?: "active-voice" | "passive-voice" | undefined;
773
+ } | {
774
+ text: string;
775
+ } | undefined;
776
+ glossary?: {
777
+ term: string;
778
+ description?: string | undefined;
779
+ translatable?: boolean | undefined;
780
+ forbidden?: boolean | undefined;
781
+ caseSensitive?: boolean | undefined;
782
+ translations?: {
783
+ locale: string;
784
+ translation: string;
785
+ description?: string | undefined;
786
+ }[] | undefined;
787
+ }[] | undefined;
788
+ targetPluralForms?: ["many" | "zero" | "one" | "two" | "few" | "other", ...("many" | "zero" | "one" | "two" | "few" | "other")[]] | undefined;
789
+ } | undefined;
790
+ integration?: "Claude" | "ChatGPT-4" | "Gemini" | "DeepL" | "GoogleTranslate" | "MicrosoftTranslator" | undefined;
791
+ tenantId?: string | undefined;
783
792
  }>;
784
793
  export declare const TRANSLATE_SYNC_V2_HEADERS_SCHEMA: z.ZodObject<{
785
794
  'x-fake-processing': z.ZodOptional<z.ZodEffects<z.ZodBoolean, boolean, unknown>>;
@@ -878,8 +887,9 @@ export declare const TRANSLATE_SYNC_V2_RESPONSE_SCHEMA: z.ZodObject<{
878
887
  details?: Record<string, unknown> | undefined;
879
888
  }[] | undefined;
880
889
  }>;
881
- export type TranslateSyncV2Body = z.infer<typeof TRANSLATE_SYNC_V2_BODY_SCHEMA>;
882
- export type TranslateSyncV2Headers = z.infer<typeof TRANSLATE_SYNC_V2_HEADERS_SCHEMA>;
883
- export type TranslateSyncV2Response = z.infer<typeof TRANSLATE_SYNC_V2_RESPONSE_SCHEMA>;
884
- export type TranslateSyncV2ContentUnit = z.infer<typeof TRANSLATE_SYNC_V2_CONTENT_UNIT_SCHEMA>;
885
- export type TranslateSyncV2Segment = z.infer<typeof TRANSLATE_SYNC_V2_SEGMENT_SCHEMA>;
890
+ export type TranslateSyncBody = z.infer<typeof TRANSLATE_SYNC_V2_BODY_SCHEMA>;
891
+ export type TranslateSyncHeaders = z.infer<typeof TRANSLATE_SYNC_V2_HEADERS_SCHEMA>;
892
+ export type TranslateSyncResponse = z.infer<typeof TRANSLATE_SYNC_V2_RESPONSE_SCHEMA>;
893
+ export type TranslateSyncV2Body = TranslateSyncBody;
894
+ export type TranslateSyncV2Headers = TranslateSyncHeaders;
895
+ export type TranslateSyncV2Response = TranslateSyncResponse;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TRANSLATE_SYNC_V2_RESPONSE_SCHEMA = exports.TRANSLATE_SYNC_V2_HEADERS_SCHEMA = exports.TRANSLATE_SYNC_V2_BODY_SCHEMA = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const zod_1 = tslib_1.__importDefault(require("zod"));
6
+ const asyncRequestSchemas_1 = require("../common/asyncRequestSchemas");
7
+ const commonSchemas_1 = require("../common/commonSchemas");
8
+ const translationContextSchemas_1 = require("../common/translationContextSchemas");
9
+ const sharedSchemas_1 = require("./sharedSchemas");
10
+ const CONTENT_UNITS_MAX_LENGTH = 1;
11
+ exports.TRANSLATE_SYNC_V2_BODY_SCHEMA = zod_1.default
12
+ .object({
13
+ tenantId: asyncRequestSchemas_1.TENANT_ID_SCHEMA.optional(),
14
+ ownerId: asyncRequestSchemas_1.OWNER_ID_SCHEMA.optional(),
15
+ sourceLocale: commonSchemas_1.LOCALE_SCHEMA,
16
+ targetLocale: commonSchemas_1.LOCALE_SCHEMA,
17
+ integration: commonSchemas_1.REAL_INTEGRATION_ENGINE_SCHEMA.optional(),
18
+ context: translationContextSchemas_1.TRANSLATION_CONTEXT_SCHEMA.optional(),
19
+ contentUnits: zod_1.default
20
+ .array(sharedSchemas_1.TRANSLATE_CONTENT_UNIT_SCHEMA)
21
+ .nonempty()
22
+ .max(CONTENT_UNITS_MAX_LENGTH)
23
+ .refine(...sharedSchemas_1.refineUniqueIds),
24
+ })
25
+ .refine(...sharedSchemas_1.refineDifferentSourceAndTargetLang)
26
+ .refine(...sharedSchemas_1.refineRequestSizeLimit);
27
+ exports.TRANSLATE_SYNC_V2_HEADERS_SCHEMA = commonSchemas_1.COMMON_REQUEST_HEADERS_SCHEMA;
28
+ exports.TRANSLATE_SYNC_V2_RESPONSE_SCHEMA = zod_1.default
29
+ .object({
30
+ data: zod_1.default.array(zod_1.default.object({
31
+ contentUnitId: sharedSchemas_1.CONTENT_ID_PROP_SCHEMA,
32
+ segmentId: sharedSchemas_1.CONTENT_ID_PROP_SCHEMA,
33
+ integration: zod_1.default.string(),
34
+ translation: zod_1.default.string(),
35
+ warnings: sharedSchemas_1.SEGMENT_WARNINGS_SCHEMA.optional(),
36
+ })),
37
+ errors: zod_1.default
38
+ .array(commonSchemas_1.COMMON_ERROR_RESPONSE_SCHEMA.extend({
39
+ contentUnitId: sharedSchemas_1.CONTENT_ID_PROP_SCHEMA,
40
+ segmentId: sharedSchemas_1.CONTENT_ID_PROP_SCHEMA,
41
+ integration: zod_1.default.string(),
42
+ }))
43
+ .optional(),
44
+ })
45
+ .describe('Results of the sync translation');
46
+ //# sourceMappingURL=translateSyncSchemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translateSyncSchemas.js","sourceRoot":"","sources":["../../../../src/sdk/schemas/translation/translateSyncSchemas.ts"],"names":[],"mappings":";;;;AAAA,sDAAmB;AAEnB,uEAAiF;AACjF,2DAKgC;AAChC,mFAAgF;AAChF,mDAOwB;AAExB,MAAM,wBAAwB,GAAG,CAAC,CAAA;AAErB,QAAA,6BAA6B,GAAG,aAAC;KAC3C,MAAM,CAAC;IACN,QAAQ,EAAE,sCAAgB,CAAC,QAAQ,EAAE;IACrC,OAAO,EAAE,qCAAe,CAAC,QAAQ,EAAE;IACnC,YAAY,EAAE,6BAAa;IAC3B,YAAY,EAAE,6BAAa;IAC3B,WAAW,EAAE,8CAA8B,CAAC,QAAQ,EAAE;IACtD,OAAO,EAAE,sDAA0B,CAAC,QAAQ,EAAE;IAC9C,YAAY,EAAE,aAAC;SACZ,KAAK,CAAC,6CAA6B,CAAC;SACpC,QAAQ,EAAE;SACV,GAAG,CAAC,wBAAwB,CAAC;SAC7B,MAAM,CAAC,GAAG,+BAAe,CAAC;CAC9B,CAAC;KACD,MAAM,CAAC,GAAG,kDAAkC,CAAC;KAC7C,MAAM,CAAC,GAAG,sCAAsB,CAAC,CAAA;AAEvB,QAAA,gCAAgC,GAAG,6CAA6B,CAAA;AAEhE,QAAA,iCAAiC,GAAG,aAAC;KAC/C,MAAM,CAAC;IACN,IAAI,EAAE,aAAC,CAAC,KAAK,CACX,aAAC,CAAC,MAAM,CAAC;QACP,aAAa,EAAE,sCAAsB;QACrC,SAAS,EAAE,sCAAsB;QACjC,WAAW,EAAE,aAAC,CAAC,MAAM,EAAE;QACvB,WAAW,EAAE,aAAC,CAAC,MAAM,EAAE;QACvB,QAAQ,EAAE,uCAAuB,CAAC,QAAQ,EAAE;KAC7C,CAAC,CACH;IACD,MAAM,EAAE,aAAC;SACN,KAAK,CACJ,4CAA4B,CAAC,MAAM,CAAC;QAClC,aAAa,EAAE,sCAAsB;QACrC,SAAS,EAAE,sCAAsB;QACjC,WAAW,EAAE,aAAC,CAAC,MAAM,EAAE;KACxB,CAAC,CACH;SACA,QAAQ,EAAE;CACd,CAAC;KACD,QAAQ,CAAC,iCAAiC,CAAC,CAAA"}
@@ -1,2 +1 @@
1
- export declare const SEGMENT_VALUE_MAX_LENGTH = 5000;
2
1
  export declare const isSegmentExceedingLengthLimit: (value: string) => boolean;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isSegmentExceedingLengthLimit = exports.SEGMENT_VALUE_MAX_LENGTH = void 0;
3
+ exports.isSegmentExceedingLengthLimit = void 0;
4
4
  const non_translatable_markup_1 = require("@lokalise/non-translatable-markup");
5
- exports.SEGMENT_VALUE_MAX_LENGTH = 5000;
5
+ const commonSchemas_1 = require("../schemas/common/commonSchemas");
6
6
  const isSegmentExceedingLengthLimit = (value) => {
7
7
  const pieces = (0, non_translatable_markup_1.extractTextBetweenTags)(value, { keepHtml: true });
8
8
  const length = pieces.reduce((acc, piece) => acc + piece.length, 0);
9
- return length <= exports.SEGMENT_VALUE_MAX_LENGTH;
9
+ return length <= commonSchemas_1.SEGMENT_VALUE_MAX_LENGTH_DEFAULT;
10
10
  };
11
11
  exports.isSegmentExceedingLengthLimit = isSegmentExceedingLengthLimit;
12
12
  //# sourceMappingURL=isSegmentExceedingLengthLimit.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"isSegmentExceedingLengthLimit.js","sourceRoot":"","sources":["../../../src/sdk/validation/isSegmentExceedingLengthLimit.ts"],"names":[],"mappings":";;;AAAA,+EAA0E;AAE7D,QAAA,wBAAwB,GAAG,IAAI,CAAA;AAErC,MAAM,6BAA6B,GAAG,CAAC,KAAa,EAAW,EAAE;IACtE,MAAM,MAAM,GAAG,IAAA,gDAAsB,EAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IAChE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;IACnE,OAAO,MAAM,IAAI,gCAAwB,CAAA;AAC3C,CAAC,CAAA;AAJY,QAAA,6BAA6B,iCAIzC"}
1
+ {"version":3,"file":"isSegmentExceedingLengthLimit.js","sourceRoot":"","sources":["../../../src/sdk/validation/isSegmentExceedingLengthLimit.ts"],"names":[],"mappings":";;;AAAA,+EAA0E;AAC1E,mEAAkF;AAE3E,MAAM,6BAA6B,GAAG,CAAC,KAAa,EAAW,EAAE;IACtE,MAAM,MAAM,GAAG,IAAA,gDAAsB,EAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IAChE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;IACnE,OAAO,MAAM,IAAI,gDAAgC,CAAA;AACnD,CAAC,CAAA;AAJY,QAAA,6BAA6B,iCAIzC"}
@@ -0,0 +1,14 @@
1
+ import { type IntegrationEngineEnum } from '../schemas/common/commonSchemas';
2
+ import type { ContentUnitLike } from '../schemas/translation/sharedSchemas';
3
+ /**
4
+ * Sums the lengths of the segments and checks if the total length exceeds the limit.
5
+ */
6
+ export declare const isContentUnitSizeUnderLimit: (segments: ContentUnitLike["segments"], limit: number) => boolean;
7
+ /**
8
+ * Checks if every content unit in the request is under the size limit.
9
+ */
10
+ export declare const isRequestSizeUnderLimit: (contentUnits: ContentUnitLike[], forcedIntegration?: IntegrationEngineEnum) => boolean;
11
+ /**
12
+ * Returns the request size limit based on the integration.
13
+ */
14
+ export declare const getRequestSizeLimit: (integration?: IntegrationEngineEnum) => number;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRequestSizeLimit = exports.isRequestSizeUnderLimit = exports.isContentUnitSizeUnderLimit = void 0;
4
+ const non_translatable_markup_1 = require("@lokalise/non-translatable-markup");
5
+ const commonSchemas_1 = require("../schemas/common/commonSchemas");
6
+ /**
7
+ * Sums the lengths of the segments and checks if the total length exceeds the limit.
8
+ */
9
+ const isContentUnitSizeUnderLimit = (segments, limit) => {
10
+ const totalLength = segments.reduce((acc, segment) => {
11
+ const pieces = (0, non_translatable_markup_1.extractTextBetweenTags)(segment.value, { keepHtml: true });
12
+ const length = pieces.reduce((acc, piece) => acc + piece.length, 0);
13
+ return acc + length;
14
+ }, 0);
15
+ return totalLength <= limit;
16
+ };
17
+ exports.isContentUnitSizeUnderLimit = isContentUnitSizeUnderLimit;
18
+ /**
19
+ * Checks if every content unit in the request is under the size limit.
20
+ */
21
+ const isRequestSizeUnderLimit = (contentUnits, forcedIntegration) => {
22
+ const limit = (0, exports.getRequestSizeLimit)(forcedIntegration);
23
+ return contentUnits.every((contentUnit) => (0, exports.isContentUnitSizeUnderLimit)(contentUnit.segments, limit));
24
+ };
25
+ exports.isRequestSizeUnderLimit = isRequestSizeUnderLimit;
26
+ /**
27
+ * Returns the request size limit based on the integration.
28
+ */
29
+ const getRequestSizeLimit = (integration) => {
30
+ if (integration && Object.hasOwn(commonSchemas_1.REQUEST_SIZE_LIMIT_MAP, integration)) {
31
+ return commonSchemas_1.REQUEST_SIZE_LIMIT_MAP[integration];
32
+ }
33
+ return commonSchemas_1.SEGMENT_VALUE_MAX_LENGTH_DEFAULT;
34
+ };
35
+ exports.getRequestSizeLimit = getRequestSizeLimit;
36
+ //# sourceMappingURL=requestSizeLimit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestSizeLimit.js","sourceRoot":"","sources":["../../../src/sdk/validation/requestSizeLimit.ts"],"names":[],"mappings":";;;AAAA,+EAA0E;AAC1E,mEAIwC;AAGxC;;GAEG;AACI,MAAM,2BAA2B,GAAG,CACzC,QAAqC,EACrC,KAAa,EACJ,EAAE;IACX,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;QACnD,MAAM,MAAM,GAAG,IAAA,gDAAsB,EAAC,OAAO,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;QACxE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;QACnE,OAAO,GAAG,GAAG,MAAM,CAAA;IACrB,CAAC,EAAE,CAAC,CAAC,CAAA;IACL,OAAO,WAAW,IAAI,KAAK,CAAA;AAC7B,CAAC,CAAA;AAVY,QAAA,2BAA2B,+BAUvC;AAED;;GAEG;AACI,MAAM,uBAAuB,GAAG,CACrC,YAA+B,EAC/B,iBAAyC,EAChC,EAAE;IACX,MAAM,KAAK,GAAG,IAAA,2BAAmB,EAAC,iBAAiB,CAAC,CAAA;IACpD,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,EAAE,CACxC,IAAA,mCAA2B,EAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,CACzD,CAAA;AACH,CAAC,CAAA;AARY,QAAA,uBAAuB,2BAQnC;AAED;;GAEG;AACI,MAAM,mBAAmB,GAAG,CAAC,WAAmC,EAAU,EAAE;IACjF,IAAI,WAAW,IAAI,MAAM,CAAC,MAAM,CAAC,sCAAsB,EAAE,WAAW,CAAC,EAAE,CAAC;QACtE,OAAO,sCAAsB,CAAC,WAAW,CAAC,CAAA;IAC5C,CAAC;IAED,OAAO,gDAAgC,CAAA;AACzC,CAAC,CAAA;AANY,QAAA,mBAAmB,uBAM/B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lokalise/polyglot-sdk",
3
- "version": "13.0.0",
3
+ "version": "13.1.0",
4
4
  "author": {
5
5
  "name": "Lokalise",
6
6
  "url": "https://lokalise.com/"
@@ -45,13 +45,13 @@
45
45
  "@lokalise/fastify-extras": ">=25.0.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@amplitude/analytics-types": "^2.8.2",
49
- "@biomejs/biome": "^1.9.3",
48
+ "@amplitude/analytics-types": "^2.8.3",
49
+ "@biomejs/biome": "^1.9.4",
50
50
  "@lokalise/biome-config": "^1.5.0",
51
51
  "@lokalise/fastify-extras": "^25.0.0",
52
52
  "@lokalise/prettier-config": "^1.0.1",
53
- "@types/node": "^22.7.7",
54
- "@vitest/coverage-v8": "^2.1.3",
53
+ "@types/node": "^22.8.1",
54
+ "@vitest/coverage-v8": "^2.1.4",
55
55
  "auto-changelog": "^2.5.0",
56
56
  "mockttp": "^3.15.3",
57
57
  "prettier": "^3.3.3",
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TRANSLATE_SYNC_V2_RESPONSE_SCHEMA = exports.TRANSLATE_SYNC_V2_HEADERS_SCHEMA = exports.TRANSLATE_SYNC_V2_BODY_SCHEMA = exports.TRANSLATE_SYNC_V2_CONTENT_UNIT_SCHEMA = exports.TRANSLATE_SYNC_V2_SEGMENT_SCHEMA = void 0;
4
- const tslib_1 = require("tslib");
5
- const zod_1 = tslib_1.__importDefault(require("zod"));
6
- const commonSchemas_1 = require("../common/commonSchemas");
7
- const translationContextSchemas_1 = require("../common/translationContextSchemas");
8
- const isSegmentExceedingLengthLimit_1 = require("../../validation/isSegmentExceedingLengthLimit");
9
- const asyncRequestSchemas_1 = require("../common/asyncRequestSchemas");
10
- const sharedSchemas_1 = require("./sharedSchemas");
11
- const SEGMENT_ID_MAX_LENGTH = 100;
12
- const CONTENT_UNIT_ID_MAX_LENGTH = 100;
13
- const CONTENT_UNIT_DESCRIPTION_MAX_LENGTH = 500;
14
- const CONTENT_UNIT_SEGMENTS_MAX_LENGTH = 500;
15
- const CONTENT_UNITS_MAX_LENGTH = 50;
16
- const TRANSLATE_SYNC_V2_SEGMENT_ID_SCHEMA = zod_1.default.string().min(1).max(SEGMENT_ID_MAX_LENGTH);
17
- exports.TRANSLATE_SYNC_V2_SEGMENT_SCHEMA = zod_1.default.object({
18
- id: TRANSLATE_SYNC_V2_SEGMENT_ID_SCHEMA,
19
- tmMatch: commonSchemas_1.TM_MATCH_SCHEMA,
20
- value: zod_1.default
21
- .string()
22
- .min(1)
23
- .refine((value) => (0, isSegmentExceedingLengthLimit_1.isSegmentExceedingLengthLimit)(value), `Too long segment value, max length is ${isSegmentExceedingLengthLimit_1.SEGMENT_VALUE_MAX_LENGTH} characters`),
24
- });
25
- const TRANSLATE_SYNC_V2_CONTENT_UNIT_ID_SCHEMA = zod_1.default.string().min(1).max(CONTENT_UNIT_ID_MAX_LENGTH);
26
- exports.TRANSLATE_SYNC_V2_CONTENT_UNIT_SCHEMA = zod_1.default.object({
27
- id: TRANSLATE_SYNC_V2_CONTENT_UNIT_ID_SCHEMA,
28
- context: zod_1.default
29
- .object({
30
- description: zod_1.default.string().min(1).max(CONTENT_UNIT_DESCRIPTION_MAX_LENGTH),
31
- })
32
- .optional(),
33
- characterLimit: zod_1.default.number().optional(),
34
- segments: zod_1.default
35
- .array(exports.TRANSLATE_SYNC_V2_SEGMENT_SCHEMA)
36
- .nonempty()
37
- .max(CONTENT_UNIT_SEGMENTS_MAX_LENGTH)
38
- .refine(...sharedSchemas_1.refineUniqueIds),
39
- });
40
- exports.TRANSLATE_SYNC_V2_BODY_SCHEMA = zod_1.default
41
- .object({
42
- tenantId: asyncRequestSchemas_1.TENANT_ID_SCHEMA.optional(),
43
- ownerId: asyncRequestSchemas_1.OWNER_ID_SCHEMA.optional(),
44
- sourceLocale: commonSchemas_1.LOCALE_SCHEMA,
45
- targetLocale: commonSchemas_1.LOCALE_SCHEMA,
46
- integration: commonSchemas_1.REAL_INTEGRATION_ENGINE_SCHEMA.optional(),
47
- context: translationContextSchemas_1.TRANSLATION_CONTEXT_SCHEMA.optional(),
48
- contentUnits: zod_1.default
49
- .array(exports.TRANSLATE_SYNC_V2_CONTENT_UNIT_SCHEMA)
50
- .nonempty()
51
- .max(CONTENT_UNITS_MAX_LENGTH)
52
- .refine(...sharedSchemas_1.refineUniqueIds),
53
- })
54
- .refine(...sharedSchemas_1.refineDifferentSourceAndTargetLang);
55
- exports.TRANSLATE_SYNC_V2_HEADERS_SCHEMA = commonSchemas_1.COMMON_REQUEST_HEADERS_SCHEMA;
56
- exports.TRANSLATE_SYNC_V2_RESPONSE_SCHEMA = zod_1.default
57
- .object({
58
- data: zod_1.default.array(zod_1.default.object({
59
- contentUnitId: TRANSLATE_SYNC_V2_SEGMENT_ID_SCHEMA,
60
- segmentId: TRANSLATE_SYNC_V2_SEGMENT_ID_SCHEMA,
61
- integration: zod_1.default.string(),
62
- translation: zod_1.default.string(),
63
- warnings: sharedSchemas_1.SEGMENT_WARNINGS_SCHEMA.optional(),
64
- })),
65
- errors: zod_1.default
66
- .array(commonSchemas_1.COMMON_ERROR_RESPONSE_SCHEMA.extend({
67
- contentUnitId: TRANSLATE_SYNC_V2_SEGMENT_ID_SCHEMA,
68
- segmentId: TRANSLATE_SYNC_V2_SEGMENT_ID_SCHEMA,
69
- integration: zod_1.default.string(),
70
- }))
71
- .optional(),
72
- })
73
- .describe('Results of the sync translation');
74
- //# sourceMappingURL=translateSyncV2Schemas.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"translateSyncV2Schemas.js","sourceRoot":"","sources":["../../../../src/sdk/schemas/translation/translateSyncV2Schemas.ts"],"names":[],"mappings":"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"}