@uniformdev/tms-sdk 19.153.1-alpha.7 → 19.154.1-alpha.14
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.mts +38 -19
- package/dist/index.d.ts +38 -19
- package/dist/index.esm.js +131 -51
- package/dist/index.js +136 -53
- package/dist/index.mjs +131 -51
- package/package.json +5 -9
package/dist/index.d.mts
CHANGED
|
@@ -9,7 +9,7 @@ type TranslationPayload = {
|
|
|
9
9
|
uniformTargetLocale: string;
|
|
10
10
|
uniformReleaseId?: string;
|
|
11
11
|
targetLang: string;
|
|
12
|
-
entityType: 'composition' | 'entry';
|
|
12
|
+
entityType: 'composition' | 'componentPattern' | 'compositionDefaults' | 'entry' | 'entryPattern' | 'asset';
|
|
13
13
|
entity: {
|
|
14
14
|
id: string;
|
|
15
15
|
slug: string | null | undefined;
|
|
@@ -41,53 +41,72 @@ declare const collectTranslationPayload: ({ uniformProjectId, uniformSourceLocal
|
|
|
41
41
|
uniformReleaseId: string | undefined;
|
|
42
42
|
targetLang: string;
|
|
43
43
|
entity: RootComponentInstance | EntryData;
|
|
44
|
-
entityType: '
|
|
44
|
+
entityType: TranslationPayload['metadata']['entityType'];
|
|
45
45
|
/**
|
|
46
46
|
* Ignore modified content in target locales and collect all supported parameters for translation
|
|
47
47
|
*/
|
|
48
48
|
overrideModifiedTargetLocale: boolean;
|
|
49
49
|
}) => CollectTranslationPayloadResult;
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
declare const getCompositionForTranslation: ({ canvasClient, compositionId, releaseId, state, }: {
|
|
52
|
+
canvasClient: CanvasClient;
|
|
53
|
+
compositionId: string;
|
|
54
|
+
releaseId?: string | undefined;
|
|
55
|
+
state?: number | undefined;
|
|
56
|
+
}) => Promise<CompositionGetResponse | undefined>;
|
|
57
|
+
|
|
58
|
+
declare const getEntryForTranslation: ({ contentClient, entryId, releaseId, pattern, state, }: {
|
|
59
|
+
contentClient: ContentClient;
|
|
60
|
+
entryId: string;
|
|
61
|
+
releaseId?: string | undefined;
|
|
62
|
+
pattern?: boolean | undefined;
|
|
63
|
+
state?: number | undefined;
|
|
64
|
+
}) => Promise<Entry | undefined>;
|
|
65
|
+
|
|
66
|
+
type MergeCompositionTranslationToUniformOptions = {
|
|
52
67
|
canvasClient: CanvasClient;
|
|
53
68
|
translationPayload: TranslationPayload;
|
|
54
|
-
getCurrentComposition?: (args: {
|
|
55
|
-
canvasClient: CanvasClient;
|
|
56
|
-
translationPayload: TranslationPayload;
|
|
57
|
-
}) => MaybePromise<CompositionGetResponse | undefined>;
|
|
58
69
|
updateComposition?: (args: {
|
|
59
70
|
canvasClient: CanvasClient;
|
|
60
71
|
translationPayload: TranslationPayload;
|
|
61
72
|
composition: Parameters<CanvasClient['updateComposition']>[0];
|
|
62
73
|
}) => MaybePromise<boolean>;
|
|
63
|
-
|
|
74
|
+
onNotFound?: (args: {
|
|
64
75
|
translationPayload: TranslationPayload;
|
|
65
76
|
}) => MaybePromise<void>;
|
|
66
|
-
|
|
77
|
+
onNotTranslatedResult?: (status: Pick<EntityTranslationResult, 'updated' | 'errorKind' | 'errorText'>) => MaybePromise<void>;
|
|
67
78
|
};
|
|
68
|
-
declare const mergeCompositionTranslationToUniform: ({ canvasClient, translationPayload,
|
|
79
|
+
declare const mergeCompositionTranslationToUniform: ({ canvasClient, translationPayload, updateComposition, onNotFound, onNotTranslatedResult, }: MergeCompositionTranslationToUniformOptions) => Promise<{
|
|
69
80
|
translationMerged: boolean;
|
|
70
81
|
entityId?: string | undefined;
|
|
71
82
|
}>;
|
|
72
83
|
|
|
73
|
-
type
|
|
84
|
+
type MergeEntryTranslationToUniformOptions = {
|
|
74
85
|
contentClient: ContentClient;
|
|
75
86
|
translationPayload: TranslationPayload;
|
|
76
|
-
getCurrentEntry?: (args: {
|
|
77
|
-
contentClient: ContentClient;
|
|
78
|
-
translationPayload: TranslationPayload;
|
|
79
|
-
}) => MaybePromise<Entry | undefined>;
|
|
80
87
|
updateEntry?: (args: {
|
|
81
88
|
contentClient: ContentClient;
|
|
82
89
|
translationPayload: TranslationPayload;
|
|
83
90
|
entry: Parameters<ContentClient['upsertEntry']>[0];
|
|
84
91
|
}) => MaybePromise<boolean>;
|
|
85
|
-
|
|
92
|
+
onNotFound?: (args: {
|
|
86
93
|
translationPayload: TranslationPayload;
|
|
87
94
|
}) => MaybePromise<void>;
|
|
88
|
-
|
|
95
|
+
onNotTranslatedResult?: (status: Pick<EntityTranslationResult, 'updated' | 'errorKind' | 'errorText'>) => MaybePromise<void>;
|
|
89
96
|
};
|
|
90
|
-
declare const mergeEntryTranslationToUniform: ({ contentClient, translationPayload,
|
|
97
|
+
declare const mergeEntryTranslationToUniform: ({ contentClient, translationPayload, updateEntry, onNotFound, onNotTranslatedResult, }: MergeEntryTranslationToUniformOptions) => Promise<{
|
|
98
|
+
translationMerged: boolean;
|
|
99
|
+
entityId?: string | undefined;
|
|
100
|
+
}>;
|
|
101
|
+
|
|
102
|
+
type MergeTranslationToUniformOptions = {
|
|
103
|
+
translationPayload: TranslationPayload;
|
|
104
|
+
onNotFound?: (args: {
|
|
105
|
+
translationPayload: TranslationPayload;
|
|
106
|
+
}) => MaybePromise<void>;
|
|
107
|
+
onNotTranslatedResult?: (status: Pick<EntityTranslationResult, 'updated' | 'errorKind' | 'errorText'>) => MaybePromise<void>;
|
|
108
|
+
} & Pick<MergeEntryTranslationToUniformOptions, 'contentClient' | 'updateEntry'> & Pick<MergeCompositionTranslationToUniformOptions, 'canvasClient' | 'updateComposition'>;
|
|
109
|
+
declare const mergeTranslationToUniform: ({ canvasClient, contentClient, translationPayload, updateComposition, updateEntry, onNotFound, onNotTranslatedResult, }: MergeTranslationToUniformOptions) => Promise<{
|
|
91
110
|
translationMerged: boolean;
|
|
92
111
|
entityId?: string | undefined;
|
|
93
112
|
}>;
|
|
@@ -104,4 +123,4 @@ declare const translateEntry: ({ entry, translationPayload, overrideModifiedTarg
|
|
|
104
123
|
overrideModifiedTargetLocale: boolean;
|
|
105
124
|
}) => EntityTranslationResult<Entry>;
|
|
106
125
|
|
|
107
|
-
export { type CollectTranslationPayloadResult, type ComponentTranslationPayload, type EntityTranslationResult, type MaybePromise, type TranslationPayload, collectTranslationPayload, mergeCompositionTranslationToUniform, mergeEntryTranslationToUniform, translateComposition, translateEntry };
|
|
126
|
+
export { type CollectTranslationPayloadResult, type ComponentTranslationPayload, type EntityTranslationResult, type MaybePromise, type MergeCompositionTranslationToUniformOptions, type MergeEntryTranslationToUniformOptions, type MergeTranslationToUniformOptions, type TranslationPayload, collectTranslationPayload, getCompositionForTranslation, getEntryForTranslation, mergeCompositionTranslationToUniform, mergeEntryTranslationToUniform, mergeTranslationToUniform, translateComposition, translateEntry };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ type TranslationPayload = {
|
|
|
9
9
|
uniformTargetLocale: string;
|
|
10
10
|
uniformReleaseId?: string;
|
|
11
11
|
targetLang: string;
|
|
12
|
-
entityType: 'composition' | 'entry';
|
|
12
|
+
entityType: 'composition' | 'componentPattern' | 'compositionDefaults' | 'entry' | 'entryPattern' | 'asset';
|
|
13
13
|
entity: {
|
|
14
14
|
id: string;
|
|
15
15
|
slug: string | null | undefined;
|
|
@@ -41,53 +41,72 @@ declare const collectTranslationPayload: ({ uniformProjectId, uniformSourceLocal
|
|
|
41
41
|
uniformReleaseId: string | undefined;
|
|
42
42
|
targetLang: string;
|
|
43
43
|
entity: RootComponentInstance | EntryData;
|
|
44
|
-
entityType: '
|
|
44
|
+
entityType: TranslationPayload['metadata']['entityType'];
|
|
45
45
|
/**
|
|
46
46
|
* Ignore modified content in target locales and collect all supported parameters for translation
|
|
47
47
|
*/
|
|
48
48
|
overrideModifiedTargetLocale: boolean;
|
|
49
49
|
}) => CollectTranslationPayloadResult;
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
declare const getCompositionForTranslation: ({ canvasClient, compositionId, releaseId, state, }: {
|
|
52
|
+
canvasClient: CanvasClient;
|
|
53
|
+
compositionId: string;
|
|
54
|
+
releaseId?: string | undefined;
|
|
55
|
+
state?: number | undefined;
|
|
56
|
+
}) => Promise<CompositionGetResponse | undefined>;
|
|
57
|
+
|
|
58
|
+
declare const getEntryForTranslation: ({ contentClient, entryId, releaseId, pattern, state, }: {
|
|
59
|
+
contentClient: ContentClient;
|
|
60
|
+
entryId: string;
|
|
61
|
+
releaseId?: string | undefined;
|
|
62
|
+
pattern?: boolean | undefined;
|
|
63
|
+
state?: number | undefined;
|
|
64
|
+
}) => Promise<Entry | undefined>;
|
|
65
|
+
|
|
66
|
+
type MergeCompositionTranslationToUniformOptions = {
|
|
52
67
|
canvasClient: CanvasClient;
|
|
53
68
|
translationPayload: TranslationPayload;
|
|
54
|
-
getCurrentComposition?: (args: {
|
|
55
|
-
canvasClient: CanvasClient;
|
|
56
|
-
translationPayload: TranslationPayload;
|
|
57
|
-
}) => MaybePromise<CompositionGetResponse | undefined>;
|
|
58
69
|
updateComposition?: (args: {
|
|
59
70
|
canvasClient: CanvasClient;
|
|
60
71
|
translationPayload: TranslationPayload;
|
|
61
72
|
composition: Parameters<CanvasClient['updateComposition']>[0];
|
|
62
73
|
}) => MaybePromise<boolean>;
|
|
63
|
-
|
|
74
|
+
onNotFound?: (args: {
|
|
64
75
|
translationPayload: TranslationPayload;
|
|
65
76
|
}) => MaybePromise<void>;
|
|
66
|
-
|
|
77
|
+
onNotTranslatedResult?: (status: Pick<EntityTranslationResult, 'updated' | 'errorKind' | 'errorText'>) => MaybePromise<void>;
|
|
67
78
|
};
|
|
68
|
-
declare const mergeCompositionTranslationToUniform: ({ canvasClient, translationPayload,
|
|
79
|
+
declare const mergeCompositionTranslationToUniform: ({ canvasClient, translationPayload, updateComposition, onNotFound, onNotTranslatedResult, }: MergeCompositionTranslationToUniformOptions) => Promise<{
|
|
69
80
|
translationMerged: boolean;
|
|
70
81
|
entityId?: string | undefined;
|
|
71
82
|
}>;
|
|
72
83
|
|
|
73
|
-
type
|
|
84
|
+
type MergeEntryTranslationToUniformOptions = {
|
|
74
85
|
contentClient: ContentClient;
|
|
75
86
|
translationPayload: TranslationPayload;
|
|
76
|
-
getCurrentEntry?: (args: {
|
|
77
|
-
contentClient: ContentClient;
|
|
78
|
-
translationPayload: TranslationPayload;
|
|
79
|
-
}) => MaybePromise<Entry | undefined>;
|
|
80
87
|
updateEntry?: (args: {
|
|
81
88
|
contentClient: ContentClient;
|
|
82
89
|
translationPayload: TranslationPayload;
|
|
83
90
|
entry: Parameters<ContentClient['upsertEntry']>[0];
|
|
84
91
|
}) => MaybePromise<boolean>;
|
|
85
|
-
|
|
92
|
+
onNotFound?: (args: {
|
|
86
93
|
translationPayload: TranslationPayload;
|
|
87
94
|
}) => MaybePromise<void>;
|
|
88
|
-
|
|
95
|
+
onNotTranslatedResult?: (status: Pick<EntityTranslationResult, 'updated' | 'errorKind' | 'errorText'>) => MaybePromise<void>;
|
|
89
96
|
};
|
|
90
|
-
declare const mergeEntryTranslationToUniform: ({ contentClient, translationPayload,
|
|
97
|
+
declare const mergeEntryTranslationToUniform: ({ contentClient, translationPayload, updateEntry, onNotFound, onNotTranslatedResult, }: MergeEntryTranslationToUniformOptions) => Promise<{
|
|
98
|
+
translationMerged: boolean;
|
|
99
|
+
entityId?: string | undefined;
|
|
100
|
+
}>;
|
|
101
|
+
|
|
102
|
+
type MergeTranslationToUniformOptions = {
|
|
103
|
+
translationPayload: TranslationPayload;
|
|
104
|
+
onNotFound?: (args: {
|
|
105
|
+
translationPayload: TranslationPayload;
|
|
106
|
+
}) => MaybePromise<void>;
|
|
107
|
+
onNotTranslatedResult?: (status: Pick<EntityTranslationResult, 'updated' | 'errorKind' | 'errorText'>) => MaybePromise<void>;
|
|
108
|
+
} & Pick<MergeEntryTranslationToUniformOptions, 'contentClient' | 'updateEntry'> & Pick<MergeCompositionTranslationToUniformOptions, 'canvasClient' | 'updateComposition'>;
|
|
109
|
+
declare const mergeTranslationToUniform: ({ canvasClient, contentClient, translationPayload, updateComposition, updateEntry, onNotFound, onNotTranslatedResult, }: MergeTranslationToUniformOptions) => Promise<{
|
|
91
110
|
translationMerged: boolean;
|
|
92
111
|
entityId?: string | undefined;
|
|
93
112
|
}>;
|
|
@@ -104,4 +123,4 @@ declare const translateEntry: ({ entry, translationPayload, overrideModifiedTarg
|
|
|
104
123
|
overrideModifiedTargetLocale: boolean;
|
|
105
124
|
}) => EntityTranslationResult<Entry>;
|
|
106
125
|
|
|
107
|
-
export { type CollectTranslationPayloadResult, type ComponentTranslationPayload, type EntityTranslationResult, type MaybePromise, type TranslationPayload, collectTranslationPayload, mergeCompositionTranslationToUniform, mergeEntryTranslationToUniform, translateComposition, translateEntry };
|
|
126
|
+
export { type CollectTranslationPayloadResult, type ComponentTranslationPayload, type EntityTranslationResult, type MaybePromise, type MergeCompositionTranslationToUniformOptions, type MergeEntryTranslationToUniformOptions, type MergeTranslationToUniformOptions, type TranslationPayload, collectTranslationPayload, getCompositionForTranslation, getEntryForTranslation, mergeCompositionTranslationToUniform, mergeEntryTranslationToUniform, mergeTranslationToUniform, translateComposition, translateEntry };
|
package/dist/index.esm.js
CHANGED
|
@@ -142,11 +142,61 @@ var isTargetLocaleUntouched = (sourceLocaleValue, targetLocaleValue) => {
|
|
|
142
142
|
return targetLocaleValue === void 0 || targetLocaleValue === null || targetLocaleValue === "" || targetLocaleValue === sourceLocaleValue;
|
|
143
143
|
};
|
|
144
144
|
|
|
145
|
-
// src/
|
|
145
|
+
// src/getCompositionForTranslation.ts
|
|
146
|
+
import { CANVAS_DRAFT_STATE } from "@uniformdev/canvas";
|
|
147
|
+
var getCompositionForTranslation = async ({
|
|
148
|
+
canvasClient,
|
|
149
|
+
compositionId,
|
|
150
|
+
releaseId,
|
|
151
|
+
state = CANVAS_DRAFT_STATE
|
|
152
|
+
}) => {
|
|
153
|
+
if (!compositionId) {
|
|
154
|
+
return void 0;
|
|
155
|
+
}
|
|
156
|
+
const composition = await canvasClient.getCompositionById({
|
|
157
|
+
compositionId,
|
|
158
|
+
releaseId: releaseId ? releaseId : void 0,
|
|
159
|
+
withComponentIDs: true,
|
|
160
|
+
skipDataResolution: true,
|
|
161
|
+
skipOverridesResolution: true,
|
|
162
|
+
skipPatternResolution: true,
|
|
163
|
+
state
|
|
164
|
+
});
|
|
165
|
+
return composition ? composition : void 0;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// src/getEntryForTranslation.ts
|
|
146
169
|
import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2 } from "@uniformdev/canvas";
|
|
170
|
+
var getEntryForTranslation = async ({
|
|
171
|
+
contentClient,
|
|
172
|
+
entryId,
|
|
173
|
+
releaseId,
|
|
174
|
+
pattern,
|
|
175
|
+
state = CANVAS_DRAFT_STATE2
|
|
176
|
+
}) => {
|
|
177
|
+
if (!entryId) {
|
|
178
|
+
return void 0;
|
|
179
|
+
}
|
|
180
|
+
const entriesResponse = await contentClient.getEntries({
|
|
181
|
+
entryIDs: [entryId],
|
|
182
|
+
releaseId: releaseId ? releaseId : void 0,
|
|
183
|
+
limit: 1,
|
|
184
|
+
withComponentIDs: true,
|
|
185
|
+
skipDataResolution: true,
|
|
186
|
+
skipOverridesResolution: true,
|
|
187
|
+
skipPatternResolution: true,
|
|
188
|
+
pattern,
|
|
189
|
+
state
|
|
190
|
+
});
|
|
191
|
+
const entry = entriesResponse.entries.at(0);
|
|
192
|
+
return entry ? entry : void 0;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// src/mergeCompositionTranslationToUniform.ts
|
|
196
|
+
import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE4 } from "@uniformdev/canvas";
|
|
147
197
|
|
|
148
198
|
// src/translateComposition.ts
|
|
149
|
-
import { CANVAS_DRAFT_STATE, walkNodeTree as walkNodeTree2 } from "@uniformdev/canvas";
|
|
199
|
+
import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3, walkNodeTree as walkNodeTree2 } from "@uniformdev/canvas";
|
|
150
200
|
import { produce } from "immer";
|
|
151
201
|
|
|
152
202
|
// src/translationHelpers.ts
|
|
@@ -268,7 +318,7 @@ var translateComposition = ({
|
|
|
268
318
|
let updated = false;
|
|
269
319
|
const translatedComposition = produce(composition, (draft) => {
|
|
270
320
|
var _a2, _b;
|
|
271
|
-
draft.state =
|
|
321
|
+
draft.state = CANVAS_DRAFT_STATE3;
|
|
272
322
|
if (!compositionLocales.includes(uniformTargetLocale)) {
|
|
273
323
|
(_b = (_a2 = draft.composition)._locales) != null ? _b : _a2._locales = [];
|
|
274
324
|
draft.composition._locales.push(uniformTargetLocale);
|
|
@@ -330,38 +380,35 @@ var translateComposition = ({
|
|
|
330
380
|
var mergeCompositionTranslationToUniform = async ({
|
|
331
381
|
canvasClient,
|
|
332
382
|
translationPayload,
|
|
333
|
-
getCurrentComposition = defaultGetCurrentComposition,
|
|
334
383
|
updateComposition = defaultUpdateComposition,
|
|
335
|
-
|
|
336
|
-
|
|
384
|
+
onNotFound,
|
|
385
|
+
onNotTranslatedResult
|
|
337
386
|
}) => {
|
|
338
387
|
if (!translationPayload) {
|
|
339
388
|
return { translationMerged: false };
|
|
340
389
|
}
|
|
390
|
+
const entityType = translationPayload.metadata.entityType;
|
|
341
391
|
const entityId = translationPayload.metadata.entity.id;
|
|
342
392
|
const overrideModifiedTargetLocale = translationPayload.metadata.overrideModifiedTargetLocale;
|
|
343
|
-
if (
|
|
393
|
+
if (entityType !== "composition" && entityType !== "componentPattern") {
|
|
344
394
|
return { translationMerged: false, entityId };
|
|
345
395
|
}
|
|
346
|
-
const composition = await
|
|
396
|
+
const composition = await getCurrentCompositionFromPayload({
|
|
347
397
|
canvasClient,
|
|
348
398
|
translationPayload
|
|
349
399
|
});
|
|
350
400
|
if (!composition) {
|
|
351
|
-
await (
|
|
401
|
+
await (onNotFound == null ? void 0 : onNotFound({
|
|
352
402
|
translationPayload
|
|
353
403
|
}));
|
|
354
404
|
return { translationMerged: false, entityId };
|
|
355
405
|
}
|
|
356
|
-
|
|
406
|
+
const translationResult = translateComposition({
|
|
357
407
|
composition,
|
|
358
408
|
translationPayload,
|
|
359
409
|
overrideModifiedTargetLocale
|
|
360
410
|
});
|
|
361
|
-
|
|
362
|
-
translationResult = await onTranslationResult(translationResult);
|
|
363
|
-
}
|
|
364
|
-
const { updated, errorKind, result: translatedComposition } = translationResult;
|
|
411
|
+
const { updated, errorKind, errorText, result: translatedComposition } = translationResult;
|
|
365
412
|
if (translatedComposition && updated && !errorKind) {
|
|
366
413
|
const translationMerged = await updateComposition({
|
|
367
414
|
canvasClient,
|
|
@@ -369,23 +416,22 @@ var mergeCompositionTranslationToUniform = async ({
|
|
|
369
416
|
composition: translatedComposition
|
|
370
417
|
});
|
|
371
418
|
return { translationMerged, entityId };
|
|
419
|
+
} else {
|
|
420
|
+
await (onNotTranslatedResult == null ? void 0 : onNotTranslatedResult({ updated, errorKind, errorText }));
|
|
421
|
+
return { translationMerged: false, entityId };
|
|
372
422
|
}
|
|
373
|
-
return { translationMerged: false, entityId };
|
|
374
423
|
};
|
|
375
|
-
var
|
|
424
|
+
var getCurrentCompositionFromPayload = async ({
|
|
376
425
|
canvasClient,
|
|
377
426
|
translationPayload
|
|
378
427
|
}) => {
|
|
379
428
|
const compositionId = translationPayload.metadata.entity.id;
|
|
380
429
|
const releaseId = translationPayload.metadata.uniformReleaseId;
|
|
381
|
-
const currentComposition = await
|
|
430
|
+
const currentComposition = await getCompositionForTranslation({
|
|
431
|
+
canvasClient,
|
|
382
432
|
compositionId,
|
|
383
|
-
releaseId
|
|
384
|
-
|
|
385
|
-
skipDataResolution: true,
|
|
386
|
-
skipOverridesResolution: true,
|
|
387
|
-
skipPatternResolution: true,
|
|
388
|
-
state: CANVAS_DRAFT_STATE2
|
|
433
|
+
releaseId,
|
|
434
|
+
state: CANVAS_DRAFT_STATE4
|
|
389
435
|
});
|
|
390
436
|
return currentComposition;
|
|
391
437
|
};
|
|
@@ -398,10 +444,10 @@ var defaultUpdateComposition = async ({
|
|
|
398
444
|
};
|
|
399
445
|
|
|
400
446
|
// src/mergeEntryTranslationToUniform.ts
|
|
401
|
-
import { CANVAS_DRAFT_STATE as
|
|
447
|
+
import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE6 } from "@uniformdev/canvas";
|
|
402
448
|
|
|
403
449
|
// src/translateEntry.ts
|
|
404
|
-
import { CANVAS_DRAFT_STATE as
|
|
450
|
+
import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE5, walkNodeTree as walkNodeTree3 } from "@uniformdev/canvas";
|
|
405
451
|
import { produce as produce2 } from "immer";
|
|
406
452
|
var translateEntry = ({
|
|
407
453
|
entry,
|
|
@@ -427,7 +473,7 @@ var translateEntry = ({
|
|
|
427
473
|
let updated = false;
|
|
428
474
|
const translatedEntry = produce2(entry, (draft) => {
|
|
429
475
|
var _a2, _b;
|
|
430
|
-
draft.state =
|
|
476
|
+
draft.state = CANVAS_DRAFT_STATE5;
|
|
431
477
|
if (!entryLocales.includes(uniformTargetLocale)) {
|
|
432
478
|
(_b = (_a2 = draft.entry)._locales) != null ? _b : _a2._locales = [];
|
|
433
479
|
draft.entry._locales.push(uniformTargetLocale);
|
|
@@ -489,38 +535,35 @@ var translateEntry = ({
|
|
|
489
535
|
var mergeEntryTranslationToUniform = async ({
|
|
490
536
|
contentClient,
|
|
491
537
|
translationPayload,
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
updateEntry = defaultUpdateEntry
|
|
538
|
+
updateEntry = defaultUpdateEntry,
|
|
539
|
+
onNotFound,
|
|
540
|
+
onNotTranslatedResult
|
|
496
541
|
}) => {
|
|
497
542
|
if (!translationPayload) {
|
|
498
543
|
return { translationMerged: false };
|
|
499
544
|
}
|
|
545
|
+
const entityType = translationPayload.metadata.entityType;
|
|
500
546
|
const entityId = translationPayload.metadata.entity.id;
|
|
501
547
|
const overrideModifiedTargetLocale = translationPayload.metadata.overrideModifiedTargetLocale;
|
|
502
|
-
if (
|
|
548
|
+
if (entityType !== "entry" && entityType !== "entryPattern") {
|
|
503
549
|
return { translationMerged: false, entityId };
|
|
504
550
|
}
|
|
505
|
-
const entry = await
|
|
551
|
+
const entry = await getCurrentEntryFromPayload({
|
|
506
552
|
contentClient,
|
|
507
553
|
translationPayload
|
|
508
554
|
});
|
|
509
555
|
if (!entry) {
|
|
510
|
-
await (
|
|
556
|
+
await (onNotFound == null ? void 0 : onNotFound({
|
|
511
557
|
translationPayload
|
|
512
558
|
}));
|
|
513
559
|
return { translationMerged: false, entityId };
|
|
514
560
|
}
|
|
515
|
-
|
|
561
|
+
const translationResult = translateEntry({
|
|
516
562
|
entry,
|
|
517
563
|
translationPayload,
|
|
518
564
|
overrideModifiedTargetLocale
|
|
519
565
|
});
|
|
520
|
-
|
|
521
|
-
translationResult = await onTranslationResult(translationResult);
|
|
522
|
-
}
|
|
523
|
-
const { updated, errorKind, result: translatedEntry } = translationResult;
|
|
566
|
+
const { updated, errorKind, errorText, result: translatedEntry } = translationResult;
|
|
524
567
|
if (translatedEntry && updated && !errorKind) {
|
|
525
568
|
const translationMerged = await updateEntry({
|
|
526
569
|
contentClient,
|
|
@@ -528,27 +571,26 @@ var mergeEntryTranslationToUniform = async ({
|
|
|
528
571
|
entry: translatedEntry
|
|
529
572
|
});
|
|
530
573
|
return { translationMerged, entityId };
|
|
574
|
+
} else {
|
|
575
|
+
await (onNotTranslatedResult == null ? void 0 : onNotTranslatedResult({ updated, errorKind, errorText }));
|
|
576
|
+
return { translationMerged: false, entityId };
|
|
531
577
|
}
|
|
532
|
-
return { translationMerged: false, entityId };
|
|
533
578
|
};
|
|
534
|
-
var
|
|
579
|
+
var getCurrentEntryFromPayload = async ({
|
|
535
580
|
contentClient,
|
|
536
581
|
translationPayload
|
|
537
582
|
}) => {
|
|
583
|
+
const entityType = translationPayload.metadata.entityType;
|
|
538
584
|
const entryId = translationPayload.metadata.entity.id;
|
|
539
585
|
const releaseId = translationPayload.metadata.uniformReleaseId;
|
|
540
|
-
const
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
skipOverridesResolution: true,
|
|
547
|
-
skipPatternResolution: true,
|
|
548
|
-
state: CANVAS_DRAFT_STATE4
|
|
586
|
+
const currentEntry = await getEntryForTranslation({
|
|
587
|
+
contentClient,
|
|
588
|
+
entryId,
|
|
589
|
+
releaseId,
|
|
590
|
+
pattern: entityType === "entryPattern",
|
|
591
|
+
state: CANVAS_DRAFT_STATE6
|
|
549
592
|
});
|
|
550
|
-
|
|
551
|
-
return currentEntry ? currentEntry : void 0;
|
|
593
|
+
return currentEntry;
|
|
552
594
|
};
|
|
553
595
|
var defaultUpdateEntry = async ({
|
|
554
596
|
contentClient,
|
|
@@ -557,10 +599,48 @@ var defaultUpdateEntry = async ({
|
|
|
557
599
|
await contentClient.upsertEntry(entry);
|
|
558
600
|
return true;
|
|
559
601
|
};
|
|
602
|
+
|
|
603
|
+
// src/mergeTranslationToUniform.ts
|
|
604
|
+
var mergeTranslationToUniform = async ({
|
|
605
|
+
canvasClient,
|
|
606
|
+
contentClient,
|
|
607
|
+
translationPayload,
|
|
608
|
+
updateComposition,
|
|
609
|
+
updateEntry,
|
|
610
|
+
onNotFound,
|
|
611
|
+
onNotTranslatedResult
|
|
612
|
+
}) => {
|
|
613
|
+
if (!translationPayload) {
|
|
614
|
+
return { translationMerged: false };
|
|
615
|
+
}
|
|
616
|
+
const entityType = translationPayload.metadata.entityType;
|
|
617
|
+
const entityId = translationPayload.metadata.entity.id;
|
|
618
|
+
if (entityType === "composition" || entityType === "componentPattern") {
|
|
619
|
+
return await mergeCompositionTranslationToUniform({
|
|
620
|
+
canvasClient,
|
|
621
|
+
translationPayload,
|
|
622
|
+
updateComposition,
|
|
623
|
+
onNotFound,
|
|
624
|
+
onNotTranslatedResult
|
|
625
|
+
});
|
|
626
|
+
} else if (entityType === "entry" || entityType === "entryPattern") {
|
|
627
|
+
return await mergeEntryTranslationToUniform({
|
|
628
|
+
contentClient,
|
|
629
|
+
translationPayload,
|
|
630
|
+
updateEntry,
|
|
631
|
+
onNotFound,
|
|
632
|
+
onNotTranslatedResult
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
return { translationMerged: false, entityId };
|
|
636
|
+
};
|
|
560
637
|
export {
|
|
561
638
|
collectTranslationPayload,
|
|
639
|
+
getCompositionForTranslation,
|
|
640
|
+
getEntryForTranslation,
|
|
562
641
|
mergeCompositionTranslationToUniform,
|
|
563
642
|
mergeEntryTranslationToUniform,
|
|
643
|
+
mergeTranslationToUniform,
|
|
564
644
|
translateComposition,
|
|
565
645
|
translateEntry
|
|
566
646
|
};
|
package/dist/index.js
CHANGED
|
@@ -21,8 +21,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
collectTranslationPayload: () => collectTranslationPayload,
|
|
24
|
+
getCompositionForTranslation: () => getCompositionForTranslation,
|
|
25
|
+
getEntryForTranslation: () => getEntryForTranslation,
|
|
24
26
|
mergeCompositionTranslationToUniform: () => mergeCompositionTranslationToUniform,
|
|
25
27
|
mergeEntryTranslationToUniform: () => mergeEntryTranslationToUniform,
|
|
28
|
+
mergeTranslationToUniform: () => mergeTranslationToUniform,
|
|
26
29
|
translateComposition: () => translateComposition,
|
|
27
30
|
translateEntry: () => translateEntry
|
|
28
31
|
});
|
|
@@ -169,11 +172,61 @@ var isTargetLocaleUntouched = (sourceLocaleValue, targetLocaleValue) => {
|
|
|
169
172
|
return targetLocaleValue === void 0 || targetLocaleValue === null || targetLocaleValue === "" || targetLocaleValue === sourceLocaleValue;
|
|
170
173
|
};
|
|
171
174
|
|
|
172
|
-
// src/
|
|
175
|
+
// src/getCompositionForTranslation.ts
|
|
176
|
+
var import_canvas2 = require("@uniformdev/canvas");
|
|
177
|
+
var getCompositionForTranslation = async ({
|
|
178
|
+
canvasClient,
|
|
179
|
+
compositionId,
|
|
180
|
+
releaseId,
|
|
181
|
+
state = import_canvas2.CANVAS_DRAFT_STATE
|
|
182
|
+
}) => {
|
|
183
|
+
if (!compositionId) {
|
|
184
|
+
return void 0;
|
|
185
|
+
}
|
|
186
|
+
const composition = await canvasClient.getCompositionById({
|
|
187
|
+
compositionId,
|
|
188
|
+
releaseId: releaseId ? releaseId : void 0,
|
|
189
|
+
withComponentIDs: true,
|
|
190
|
+
skipDataResolution: true,
|
|
191
|
+
skipOverridesResolution: true,
|
|
192
|
+
skipPatternResolution: true,
|
|
193
|
+
state
|
|
194
|
+
});
|
|
195
|
+
return composition ? composition : void 0;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// src/getEntryForTranslation.ts
|
|
173
199
|
var import_canvas3 = require("@uniformdev/canvas");
|
|
200
|
+
var getEntryForTranslation = async ({
|
|
201
|
+
contentClient,
|
|
202
|
+
entryId,
|
|
203
|
+
releaseId,
|
|
204
|
+
pattern,
|
|
205
|
+
state = import_canvas3.CANVAS_DRAFT_STATE
|
|
206
|
+
}) => {
|
|
207
|
+
if (!entryId) {
|
|
208
|
+
return void 0;
|
|
209
|
+
}
|
|
210
|
+
const entriesResponse = await contentClient.getEntries({
|
|
211
|
+
entryIDs: [entryId],
|
|
212
|
+
releaseId: releaseId ? releaseId : void 0,
|
|
213
|
+
limit: 1,
|
|
214
|
+
withComponentIDs: true,
|
|
215
|
+
skipDataResolution: true,
|
|
216
|
+
skipOverridesResolution: true,
|
|
217
|
+
skipPatternResolution: true,
|
|
218
|
+
pattern,
|
|
219
|
+
state
|
|
220
|
+
});
|
|
221
|
+
const entry = entriesResponse.entries.at(0);
|
|
222
|
+
return entry ? entry : void 0;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// src/mergeCompositionTranslationToUniform.ts
|
|
226
|
+
var import_canvas5 = require("@uniformdev/canvas");
|
|
174
227
|
|
|
175
228
|
// src/translateComposition.ts
|
|
176
|
-
var
|
|
229
|
+
var import_canvas4 = require("@uniformdev/canvas");
|
|
177
230
|
var import_immer = require("immer");
|
|
178
231
|
|
|
179
232
|
// src/translationHelpers.ts
|
|
@@ -295,12 +348,12 @@ var translateComposition = ({
|
|
|
295
348
|
let updated = false;
|
|
296
349
|
const translatedComposition = (0, import_immer.produce)(composition, (draft) => {
|
|
297
350
|
var _a2, _b;
|
|
298
|
-
draft.state =
|
|
351
|
+
draft.state = import_canvas4.CANVAS_DRAFT_STATE;
|
|
299
352
|
if (!compositionLocales.includes(uniformTargetLocale)) {
|
|
300
353
|
(_b = (_a2 = draft.composition)._locales) != null ? _b : _a2._locales = [];
|
|
301
354
|
draft.composition._locales.push(uniformTargetLocale);
|
|
302
355
|
}
|
|
303
|
-
(0,
|
|
356
|
+
(0, import_canvas4.walkNodeTree)(draft.composition, ({ node: component, type, actions }) => {
|
|
304
357
|
var _a3, _b2;
|
|
305
358
|
if (type !== "component") {
|
|
306
359
|
actions.stopProcessingDescendants();
|
|
@@ -357,38 +410,35 @@ var translateComposition = ({
|
|
|
357
410
|
var mergeCompositionTranslationToUniform = async ({
|
|
358
411
|
canvasClient,
|
|
359
412
|
translationPayload,
|
|
360
|
-
getCurrentComposition = defaultGetCurrentComposition,
|
|
361
413
|
updateComposition = defaultUpdateComposition,
|
|
362
|
-
|
|
363
|
-
|
|
414
|
+
onNotFound,
|
|
415
|
+
onNotTranslatedResult
|
|
364
416
|
}) => {
|
|
365
417
|
if (!translationPayload) {
|
|
366
418
|
return { translationMerged: false };
|
|
367
419
|
}
|
|
420
|
+
const entityType = translationPayload.metadata.entityType;
|
|
368
421
|
const entityId = translationPayload.metadata.entity.id;
|
|
369
422
|
const overrideModifiedTargetLocale = translationPayload.metadata.overrideModifiedTargetLocale;
|
|
370
|
-
if (
|
|
423
|
+
if (entityType !== "composition" && entityType !== "componentPattern") {
|
|
371
424
|
return { translationMerged: false, entityId };
|
|
372
425
|
}
|
|
373
|
-
const composition = await
|
|
426
|
+
const composition = await getCurrentCompositionFromPayload({
|
|
374
427
|
canvasClient,
|
|
375
428
|
translationPayload
|
|
376
429
|
});
|
|
377
430
|
if (!composition) {
|
|
378
|
-
await (
|
|
431
|
+
await (onNotFound == null ? void 0 : onNotFound({
|
|
379
432
|
translationPayload
|
|
380
433
|
}));
|
|
381
434
|
return { translationMerged: false, entityId };
|
|
382
435
|
}
|
|
383
|
-
|
|
436
|
+
const translationResult = translateComposition({
|
|
384
437
|
composition,
|
|
385
438
|
translationPayload,
|
|
386
439
|
overrideModifiedTargetLocale
|
|
387
440
|
});
|
|
388
|
-
|
|
389
|
-
translationResult = await onTranslationResult(translationResult);
|
|
390
|
-
}
|
|
391
|
-
const { updated, errorKind, result: translatedComposition } = translationResult;
|
|
441
|
+
const { updated, errorKind, errorText, result: translatedComposition } = translationResult;
|
|
392
442
|
if (translatedComposition && updated && !errorKind) {
|
|
393
443
|
const translationMerged = await updateComposition({
|
|
394
444
|
canvasClient,
|
|
@@ -396,23 +446,22 @@ var mergeCompositionTranslationToUniform = async ({
|
|
|
396
446
|
composition: translatedComposition
|
|
397
447
|
});
|
|
398
448
|
return { translationMerged, entityId };
|
|
449
|
+
} else {
|
|
450
|
+
await (onNotTranslatedResult == null ? void 0 : onNotTranslatedResult({ updated, errorKind, errorText }));
|
|
451
|
+
return { translationMerged: false, entityId };
|
|
399
452
|
}
|
|
400
|
-
return { translationMerged: false, entityId };
|
|
401
453
|
};
|
|
402
|
-
var
|
|
454
|
+
var getCurrentCompositionFromPayload = async ({
|
|
403
455
|
canvasClient,
|
|
404
456
|
translationPayload
|
|
405
457
|
}) => {
|
|
406
458
|
const compositionId = translationPayload.metadata.entity.id;
|
|
407
459
|
const releaseId = translationPayload.metadata.uniformReleaseId;
|
|
408
|
-
const currentComposition = await
|
|
460
|
+
const currentComposition = await getCompositionForTranslation({
|
|
461
|
+
canvasClient,
|
|
409
462
|
compositionId,
|
|
410
|
-
releaseId
|
|
411
|
-
|
|
412
|
-
skipDataResolution: true,
|
|
413
|
-
skipOverridesResolution: true,
|
|
414
|
-
skipPatternResolution: true,
|
|
415
|
-
state: import_canvas3.CANVAS_DRAFT_STATE
|
|
463
|
+
releaseId,
|
|
464
|
+
state: import_canvas5.CANVAS_DRAFT_STATE
|
|
416
465
|
});
|
|
417
466
|
return currentComposition;
|
|
418
467
|
};
|
|
@@ -425,10 +474,10 @@ var defaultUpdateComposition = async ({
|
|
|
425
474
|
};
|
|
426
475
|
|
|
427
476
|
// src/mergeEntryTranslationToUniform.ts
|
|
428
|
-
var
|
|
477
|
+
var import_canvas7 = require("@uniformdev/canvas");
|
|
429
478
|
|
|
430
479
|
// src/translateEntry.ts
|
|
431
|
-
var
|
|
480
|
+
var import_canvas6 = require("@uniformdev/canvas");
|
|
432
481
|
var import_immer2 = require("immer");
|
|
433
482
|
var translateEntry = ({
|
|
434
483
|
entry,
|
|
@@ -454,12 +503,12 @@ var translateEntry = ({
|
|
|
454
503
|
let updated = false;
|
|
455
504
|
const translatedEntry = (0, import_immer2.produce)(entry, (draft) => {
|
|
456
505
|
var _a2, _b;
|
|
457
|
-
draft.state =
|
|
506
|
+
draft.state = import_canvas6.CANVAS_DRAFT_STATE;
|
|
458
507
|
if (!entryLocales.includes(uniformTargetLocale)) {
|
|
459
508
|
(_b = (_a2 = draft.entry)._locales) != null ? _b : _a2._locales = [];
|
|
460
509
|
draft.entry._locales.push(uniformTargetLocale);
|
|
461
510
|
}
|
|
462
|
-
(0,
|
|
511
|
+
(0, import_canvas6.walkNodeTree)(draft.entry, ({ node: component, type, actions }) => {
|
|
463
512
|
var _a3, _b2;
|
|
464
513
|
if (type !== "entry") {
|
|
465
514
|
actions.stopProcessingDescendants();
|
|
@@ -516,38 +565,35 @@ var translateEntry = ({
|
|
|
516
565
|
var mergeEntryTranslationToUniform = async ({
|
|
517
566
|
contentClient,
|
|
518
567
|
translationPayload,
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
updateEntry = defaultUpdateEntry
|
|
568
|
+
updateEntry = defaultUpdateEntry,
|
|
569
|
+
onNotFound,
|
|
570
|
+
onNotTranslatedResult
|
|
523
571
|
}) => {
|
|
524
572
|
if (!translationPayload) {
|
|
525
573
|
return { translationMerged: false };
|
|
526
574
|
}
|
|
575
|
+
const entityType = translationPayload.metadata.entityType;
|
|
527
576
|
const entityId = translationPayload.metadata.entity.id;
|
|
528
577
|
const overrideModifiedTargetLocale = translationPayload.metadata.overrideModifiedTargetLocale;
|
|
529
|
-
if (
|
|
578
|
+
if (entityType !== "entry" && entityType !== "entryPattern") {
|
|
530
579
|
return { translationMerged: false, entityId };
|
|
531
580
|
}
|
|
532
|
-
const entry = await
|
|
581
|
+
const entry = await getCurrentEntryFromPayload({
|
|
533
582
|
contentClient,
|
|
534
583
|
translationPayload
|
|
535
584
|
});
|
|
536
585
|
if (!entry) {
|
|
537
|
-
await (
|
|
586
|
+
await (onNotFound == null ? void 0 : onNotFound({
|
|
538
587
|
translationPayload
|
|
539
588
|
}));
|
|
540
589
|
return { translationMerged: false, entityId };
|
|
541
590
|
}
|
|
542
|
-
|
|
591
|
+
const translationResult = translateEntry({
|
|
543
592
|
entry,
|
|
544
593
|
translationPayload,
|
|
545
594
|
overrideModifiedTargetLocale
|
|
546
595
|
});
|
|
547
|
-
|
|
548
|
-
translationResult = await onTranslationResult(translationResult);
|
|
549
|
-
}
|
|
550
|
-
const { updated, errorKind, result: translatedEntry } = translationResult;
|
|
596
|
+
const { updated, errorKind, errorText, result: translatedEntry } = translationResult;
|
|
551
597
|
if (translatedEntry && updated && !errorKind) {
|
|
552
598
|
const translationMerged = await updateEntry({
|
|
553
599
|
contentClient,
|
|
@@ -555,27 +601,26 @@ var mergeEntryTranslationToUniform = async ({
|
|
|
555
601
|
entry: translatedEntry
|
|
556
602
|
});
|
|
557
603
|
return { translationMerged, entityId };
|
|
604
|
+
} else {
|
|
605
|
+
await (onNotTranslatedResult == null ? void 0 : onNotTranslatedResult({ updated, errorKind, errorText }));
|
|
606
|
+
return { translationMerged: false, entityId };
|
|
558
607
|
}
|
|
559
|
-
return { translationMerged: false, entityId };
|
|
560
608
|
};
|
|
561
|
-
var
|
|
609
|
+
var getCurrentEntryFromPayload = async ({
|
|
562
610
|
contentClient,
|
|
563
611
|
translationPayload
|
|
564
612
|
}) => {
|
|
613
|
+
const entityType = translationPayload.metadata.entityType;
|
|
565
614
|
const entryId = translationPayload.metadata.entity.id;
|
|
566
615
|
const releaseId = translationPayload.metadata.uniformReleaseId;
|
|
567
|
-
const
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
skipOverridesResolution: true,
|
|
574
|
-
skipPatternResolution: true,
|
|
575
|
-
state: import_canvas5.CANVAS_DRAFT_STATE
|
|
616
|
+
const currentEntry = await getEntryForTranslation({
|
|
617
|
+
contentClient,
|
|
618
|
+
entryId,
|
|
619
|
+
releaseId,
|
|
620
|
+
pattern: entityType === "entryPattern",
|
|
621
|
+
state: import_canvas7.CANVAS_DRAFT_STATE
|
|
576
622
|
});
|
|
577
|
-
|
|
578
|
-
return currentEntry ? currentEntry : void 0;
|
|
623
|
+
return currentEntry;
|
|
579
624
|
};
|
|
580
625
|
var defaultUpdateEntry = async ({
|
|
581
626
|
contentClient,
|
|
@@ -584,11 +629,49 @@ var defaultUpdateEntry = async ({
|
|
|
584
629
|
await contentClient.upsertEntry(entry);
|
|
585
630
|
return true;
|
|
586
631
|
};
|
|
632
|
+
|
|
633
|
+
// src/mergeTranslationToUniform.ts
|
|
634
|
+
var mergeTranslationToUniform = async ({
|
|
635
|
+
canvasClient,
|
|
636
|
+
contentClient,
|
|
637
|
+
translationPayload,
|
|
638
|
+
updateComposition,
|
|
639
|
+
updateEntry,
|
|
640
|
+
onNotFound,
|
|
641
|
+
onNotTranslatedResult
|
|
642
|
+
}) => {
|
|
643
|
+
if (!translationPayload) {
|
|
644
|
+
return { translationMerged: false };
|
|
645
|
+
}
|
|
646
|
+
const entityType = translationPayload.metadata.entityType;
|
|
647
|
+
const entityId = translationPayload.metadata.entity.id;
|
|
648
|
+
if (entityType === "composition" || entityType === "componentPattern") {
|
|
649
|
+
return await mergeCompositionTranslationToUniform({
|
|
650
|
+
canvasClient,
|
|
651
|
+
translationPayload,
|
|
652
|
+
updateComposition,
|
|
653
|
+
onNotFound,
|
|
654
|
+
onNotTranslatedResult
|
|
655
|
+
});
|
|
656
|
+
} else if (entityType === "entry" || entityType === "entryPattern") {
|
|
657
|
+
return await mergeEntryTranslationToUniform({
|
|
658
|
+
contentClient,
|
|
659
|
+
translationPayload,
|
|
660
|
+
updateEntry,
|
|
661
|
+
onNotFound,
|
|
662
|
+
onNotTranslatedResult
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
return { translationMerged: false, entityId };
|
|
666
|
+
};
|
|
587
667
|
// Annotate the CommonJS export names for ESM import in node:
|
|
588
668
|
0 && (module.exports = {
|
|
589
669
|
collectTranslationPayload,
|
|
670
|
+
getCompositionForTranslation,
|
|
671
|
+
getEntryForTranslation,
|
|
590
672
|
mergeCompositionTranslationToUniform,
|
|
591
673
|
mergeEntryTranslationToUniform,
|
|
674
|
+
mergeTranslationToUniform,
|
|
592
675
|
translateComposition,
|
|
593
676
|
translateEntry
|
|
594
677
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -142,11 +142,61 @@ var isTargetLocaleUntouched = (sourceLocaleValue, targetLocaleValue) => {
|
|
|
142
142
|
return targetLocaleValue === void 0 || targetLocaleValue === null || targetLocaleValue === "" || targetLocaleValue === sourceLocaleValue;
|
|
143
143
|
};
|
|
144
144
|
|
|
145
|
-
// src/
|
|
145
|
+
// src/getCompositionForTranslation.ts
|
|
146
|
+
import { CANVAS_DRAFT_STATE } from "@uniformdev/canvas";
|
|
147
|
+
var getCompositionForTranslation = async ({
|
|
148
|
+
canvasClient,
|
|
149
|
+
compositionId,
|
|
150
|
+
releaseId,
|
|
151
|
+
state = CANVAS_DRAFT_STATE
|
|
152
|
+
}) => {
|
|
153
|
+
if (!compositionId) {
|
|
154
|
+
return void 0;
|
|
155
|
+
}
|
|
156
|
+
const composition = await canvasClient.getCompositionById({
|
|
157
|
+
compositionId,
|
|
158
|
+
releaseId: releaseId ? releaseId : void 0,
|
|
159
|
+
withComponentIDs: true,
|
|
160
|
+
skipDataResolution: true,
|
|
161
|
+
skipOverridesResolution: true,
|
|
162
|
+
skipPatternResolution: true,
|
|
163
|
+
state
|
|
164
|
+
});
|
|
165
|
+
return composition ? composition : void 0;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// src/getEntryForTranslation.ts
|
|
146
169
|
import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2 } from "@uniformdev/canvas";
|
|
170
|
+
var getEntryForTranslation = async ({
|
|
171
|
+
contentClient,
|
|
172
|
+
entryId,
|
|
173
|
+
releaseId,
|
|
174
|
+
pattern,
|
|
175
|
+
state = CANVAS_DRAFT_STATE2
|
|
176
|
+
}) => {
|
|
177
|
+
if (!entryId) {
|
|
178
|
+
return void 0;
|
|
179
|
+
}
|
|
180
|
+
const entriesResponse = await contentClient.getEntries({
|
|
181
|
+
entryIDs: [entryId],
|
|
182
|
+
releaseId: releaseId ? releaseId : void 0,
|
|
183
|
+
limit: 1,
|
|
184
|
+
withComponentIDs: true,
|
|
185
|
+
skipDataResolution: true,
|
|
186
|
+
skipOverridesResolution: true,
|
|
187
|
+
skipPatternResolution: true,
|
|
188
|
+
pattern,
|
|
189
|
+
state
|
|
190
|
+
});
|
|
191
|
+
const entry = entriesResponse.entries.at(0);
|
|
192
|
+
return entry ? entry : void 0;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// src/mergeCompositionTranslationToUniform.ts
|
|
196
|
+
import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE4 } from "@uniformdev/canvas";
|
|
147
197
|
|
|
148
198
|
// src/translateComposition.ts
|
|
149
|
-
import { CANVAS_DRAFT_STATE, walkNodeTree as walkNodeTree2 } from "@uniformdev/canvas";
|
|
199
|
+
import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3, walkNodeTree as walkNodeTree2 } from "@uniformdev/canvas";
|
|
150
200
|
import { produce } from "immer";
|
|
151
201
|
|
|
152
202
|
// src/translationHelpers.ts
|
|
@@ -268,7 +318,7 @@ var translateComposition = ({
|
|
|
268
318
|
let updated = false;
|
|
269
319
|
const translatedComposition = produce(composition, (draft) => {
|
|
270
320
|
var _a2, _b;
|
|
271
|
-
draft.state =
|
|
321
|
+
draft.state = CANVAS_DRAFT_STATE3;
|
|
272
322
|
if (!compositionLocales.includes(uniformTargetLocale)) {
|
|
273
323
|
(_b = (_a2 = draft.composition)._locales) != null ? _b : _a2._locales = [];
|
|
274
324
|
draft.composition._locales.push(uniformTargetLocale);
|
|
@@ -330,38 +380,35 @@ var translateComposition = ({
|
|
|
330
380
|
var mergeCompositionTranslationToUniform = async ({
|
|
331
381
|
canvasClient,
|
|
332
382
|
translationPayload,
|
|
333
|
-
getCurrentComposition = defaultGetCurrentComposition,
|
|
334
383
|
updateComposition = defaultUpdateComposition,
|
|
335
|
-
|
|
336
|
-
|
|
384
|
+
onNotFound,
|
|
385
|
+
onNotTranslatedResult
|
|
337
386
|
}) => {
|
|
338
387
|
if (!translationPayload) {
|
|
339
388
|
return { translationMerged: false };
|
|
340
389
|
}
|
|
390
|
+
const entityType = translationPayload.metadata.entityType;
|
|
341
391
|
const entityId = translationPayload.metadata.entity.id;
|
|
342
392
|
const overrideModifiedTargetLocale = translationPayload.metadata.overrideModifiedTargetLocale;
|
|
343
|
-
if (
|
|
393
|
+
if (entityType !== "composition" && entityType !== "componentPattern") {
|
|
344
394
|
return { translationMerged: false, entityId };
|
|
345
395
|
}
|
|
346
|
-
const composition = await
|
|
396
|
+
const composition = await getCurrentCompositionFromPayload({
|
|
347
397
|
canvasClient,
|
|
348
398
|
translationPayload
|
|
349
399
|
});
|
|
350
400
|
if (!composition) {
|
|
351
|
-
await (
|
|
401
|
+
await (onNotFound == null ? void 0 : onNotFound({
|
|
352
402
|
translationPayload
|
|
353
403
|
}));
|
|
354
404
|
return { translationMerged: false, entityId };
|
|
355
405
|
}
|
|
356
|
-
|
|
406
|
+
const translationResult = translateComposition({
|
|
357
407
|
composition,
|
|
358
408
|
translationPayload,
|
|
359
409
|
overrideModifiedTargetLocale
|
|
360
410
|
});
|
|
361
|
-
|
|
362
|
-
translationResult = await onTranslationResult(translationResult);
|
|
363
|
-
}
|
|
364
|
-
const { updated, errorKind, result: translatedComposition } = translationResult;
|
|
411
|
+
const { updated, errorKind, errorText, result: translatedComposition } = translationResult;
|
|
365
412
|
if (translatedComposition && updated && !errorKind) {
|
|
366
413
|
const translationMerged = await updateComposition({
|
|
367
414
|
canvasClient,
|
|
@@ -369,23 +416,22 @@ var mergeCompositionTranslationToUniform = async ({
|
|
|
369
416
|
composition: translatedComposition
|
|
370
417
|
});
|
|
371
418
|
return { translationMerged, entityId };
|
|
419
|
+
} else {
|
|
420
|
+
await (onNotTranslatedResult == null ? void 0 : onNotTranslatedResult({ updated, errorKind, errorText }));
|
|
421
|
+
return { translationMerged: false, entityId };
|
|
372
422
|
}
|
|
373
|
-
return { translationMerged: false, entityId };
|
|
374
423
|
};
|
|
375
|
-
var
|
|
424
|
+
var getCurrentCompositionFromPayload = async ({
|
|
376
425
|
canvasClient,
|
|
377
426
|
translationPayload
|
|
378
427
|
}) => {
|
|
379
428
|
const compositionId = translationPayload.metadata.entity.id;
|
|
380
429
|
const releaseId = translationPayload.metadata.uniformReleaseId;
|
|
381
|
-
const currentComposition = await
|
|
430
|
+
const currentComposition = await getCompositionForTranslation({
|
|
431
|
+
canvasClient,
|
|
382
432
|
compositionId,
|
|
383
|
-
releaseId
|
|
384
|
-
|
|
385
|
-
skipDataResolution: true,
|
|
386
|
-
skipOverridesResolution: true,
|
|
387
|
-
skipPatternResolution: true,
|
|
388
|
-
state: CANVAS_DRAFT_STATE2
|
|
433
|
+
releaseId,
|
|
434
|
+
state: CANVAS_DRAFT_STATE4
|
|
389
435
|
});
|
|
390
436
|
return currentComposition;
|
|
391
437
|
};
|
|
@@ -398,10 +444,10 @@ var defaultUpdateComposition = async ({
|
|
|
398
444
|
};
|
|
399
445
|
|
|
400
446
|
// src/mergeEntryTranslationToUniform.ts
|
|
401
|
-
import { CANVAS_DRAFT_STATE as
|
|
447
|
+
import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE6 } from "@uniformdev/canvas";
|
|
402
448
|
|
|
403
449
|
// src/translateEntry.ts
|
|
404
|
-
import { CANVAS_DRAFT_STATE as
|
|
450
|
+
import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE5, walkNodeTree as walkNodeTree3 } from "@uniformdev/canvas";
|
|
405
451
|
import { produce as produce2 } from "immer";
|
|
406
452
|
var translateEntry = ({
|
|
407
453
|
entry,
|
|
@@ -427,7 +473,7 @@ var translateEntry = ({
|
|
|
427
473
|
let updated = false;
|
|
428
474
|
const translatedEntry = produce2(entry, (draft) => {
|
|
429
475
|
var _a2, _b;
|
|
430
|
-
draft.state =
|
|
476
|
+
draft.state = CANVAS_DRAFT_STATE5;
|
|
431
477
|
if (!entryLocales.includes(uniformTargetLocale)) {
|
|
432
478
|
(_b = (_a2 = draft.entry)._locales) != null ? _b : _a2._locales = [];
|
|
433
479
|
draft.entry._locales.push(uniformTargetLocale);
|
|
@@ -489,38 +535,35 @@ var translateEntry = ({
|
|
|
489
535
|
var mergeEntryTranslationToUniform = async ({
|
|
490
536
|
contentClient,
|
|
491
537
|
translationPayload,
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
updateEntry = defaultUpdateEntry
|
|
538
|
+
updateEntry = defaultUpdateEntry,
|
|
539
|
+
onNotFound,
|
|
540
|
+
onNotTranslatedResult
|
|
496
541
|
}) => {
|
|
497
542
|
if (!translationPayload) {
|
|
498
543
|
return { translationMerged: false };
|
|
499
544
|
}
|
|
545
|
+
const entityType = translationPayload.metadata.entityType;
|
|
500
546
|
const entityId = translationPayload.metadata.entity.id;
|
|
501
547
|
const overrideModifiedTargetLocale = translationPayload.metadata.overrideModifiedTargetLocale;
|
|
502
|
-
if (
|
|
548
|
+
if (entityType !== "entry" && entityType !== "entryPattern") {
|
|
503
549
|
return { translationMerged: false, entityId };
|
|
504
550
|
}
|
|
505
|
-
const entry = await
|
|
551
|
+
const entry = await getCurrentEntryFromPayload({
|
|
506
552
|
contentClient,
|
|
507
553
|
translationPayload
|
|
508
554
|
});
|
|
509
555
|
if (!entry) {
|
|
510
|
-
await (
|
|
556
|
+
await (onNotFound == null ? void 0 : onNotFound({
|
|
511
557
|
translationPayload
|
|
512
558
|
}));
|
|
513
559
|
return { translationMerged: false, entityId };
|
|
514
560
|
}
|
|
515
|
-
|
|
561
|
+
const translationResult = translateEntry({
|
|
516
562
|
entry,
|
|
517
563
|
translationPayload,
|
|
518
564
|
overrideModifiedTargetLocale
|
|
519
565
|
});
|
|
520
|
-
|
|
521
|
-
translationResult = await onTranslationResult(translationResult);
|
|
522
|
-
}
|
|
523
|
-
const { updated, errorKind, result: translatedEntry } = translationResult;
|
|
566
|
+
const { updated, errorKind, errorText, result: translatedEntry } = translationResult;
|
|
524
567
|
if (translatedEntry && updated && !errorKind) {
|
|
525
568
|
const translationMerged = await updateEntry({
|
|
526
569
|
contentClient,
|
|
@@ -528,27 +571,26 @@ var mergeEntryTranslationToUniform = async ({
|
|
|
528
571
|
entry: translatedEntry
|
|
529
572
|
});
|
|
530
573
|
return { translationMerged, entityId };
|
|
574
|
+
} else {
|
|
575
|
+
await (onNotTranslatedResult == null ? void 0 : onNotTranslatedResult({ updated, errorKind, errorText }));
|
|
576
|
+
return { translationMerged: false, entityId };
|
|
531
577
|
}
|
|
532
|
-
return { translationMerged: false, entityId };
|
|
533
578
|
};
|
|
534
|
-
var
|
|
579
|
+
var getCurrentEntryFromPayload = async ({
|
|
535
580
|
contentClient,
|
|
536
581
|
translationPayload
|
|
537
582
|
}) => {
|
|
583
|
+
const entityType = translationPayload.metadata.entityType;
|
|
538
584
|
const entryId = translationPayload.metadata.entity.id;
|
|
539
585
|
const releaseId = translationPayload.metadata.uniformReleaseId;
|
|
540
|
-
const
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
skipOverridesResolution: true,
|
|
547
|
-
skipPatternResolution: true,
|
|
548
|
-
state: CANVAS_DRAFT_STATE4
|
|
586
|
+
const currentEntry = await getEntryForTranslation({
|
|
587
|
+
contentClient,
|
|
588
|
+
entryId,
|
|
589
|
+
releaseId,
|
|
590
|
+
pattern: entityType === "entryPattern",
|
|
591
|
+
state: CANVAS_DRAFT_STATE6
|
|
549
592
|
});
|
|
550
|
-
|
|
551
|
-
return currentEntry ? currentEntry : void 0;
|
|
593
|
+
return currentEntry;
|
|
552
594
|
};
|
|
553
595
|
var defaultUpdateEntry = async ({
|
|
554
596
|
contentClient,
|
|
@@ -557,10 +599,48 @@ var defaultUpdateEntry = async ({
|
|
|
557
599
|
await contentClient.upsertEntry(entry);
|
|
558
600
|
return true;
|
|
559
601
|
};
|
|
602
|
+
|
|
603
|
+
// src/mergeTranslationToUniform.ts
|
|
604
|
+
var mergeTranslationToUniform = async ({
|
|
605
|
+
canvasClient,
|
|
606
|
+
contentClient,
|
|
607
|
+
translationPayload,
|
|
608
|
+
updateComposition,
|
|
609
|
+
updateEntry,
|
|
610
|
+
onNotFound,
|
|
611
|
+
onNotTranslatedResult
|
|
612
|
+
}) => {
|
|
613
|
+
if (!translationPayload) {
|
|
614
|
+
return { translationMerged: false };
|
|
615
|
+
}
|
|
616
|
+
const entityType = translationPayload.metadata.entityType;
|
|
617
|
+
const entityId = translationPayload.metadata.entity.id;
|
|
618
|
+
if (entityType === "composition" || entityType === "componentPattern") {
|
|
619
|
+
return await mergeCompositionTranslationToUniform({
|
|
620
|
+
canvasClient,
|
|
621
|
+
translationPayload,
|
|
622
|
+
updateComposition,
|
|
623
|
+
onNotFound,
|
|
624
|
+
onNotTranslatedResult
|
|
625
|
+
});
|
|
626
|
+
} else if (entityType === "entry" || entityType === "entryPattern") {
|
|
627
|
+
return await mergeEntryTranslationToUniform({
|
|
628
|
+
contentClient,
|
|
629
|
+
translationPayload,
|
|
630
|
+
updateEntry,
|
|
631
|
+
onNotFound,
|
|
632
|
+
onNotTranslatedResult
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
return { translationMerged: false, entityId };
|
|
636
|
+
};
|
|
560
637
|
export {
|
|
561
638
|
collectTranslationPayload,
|
|
639
|
+
getCompositionForTranslation,
|
|
640
|
+
getEntryForTranslation,
|
|
562
641
|
mergeCompositionTranslationToUniform,
|
|
563
642
|
mergeEntryTranslationToUniform,
|
|
643
|
+
mergeTranslationToUniform,
|
|
564
644
|
translateComposition,
|
|
565
645
|
translateEntry
|
|
566
646
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/tms-sdk",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.154.1-alpha.14+6d8f85cd07",
|
|
4
4
|
"description": "Uniform Translation Management System SDK",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dev": "run-s dev:ts",
|
|
22
22
|
"dev:ts": "tsup --watch",
|
|
23
23
|
"clean": "rimraf dist",
|
|
24
|
-
"test": "jest --maxWorkers=1",
|
|
24
|
+
"test": "jest --maxWorkers=1 --passWithNoTests",
|
|
25
25
|
"lint": "eslint \"src/**/*.{js,ts,tsx}\"",
|
|
26
26
|
"format": "prettier --write \"src/**/*.{js,ts,tsx}\"",
|
|
27
27
|
"document": "api-extractor run --local"
|
|
@@ -33,13 +33,9 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@uniformdev/canvas": "19.
|
|
36
|
+
"@uniformdev/canvas": "19.154.1-alpha.14+6d8f85cd07",
|
|
37
37
|
"dequal": "2.0.3",
|
|
38
|
-
"immer": "10.0.4"
|
|
39
|
-
"uuid": "9.0.1"
|
|
38
|
+
"immer": "10.0.4"
|
|
40
39
|
},
|
|
41
|
-
"
|
|
42
|
-
"@types/uuid": "9.0.4"
|
|
43
|
-
},
|
|
44
|
-
"gitHead": "f044ed03fac543671ed2db1869cc173618f4d46c"
|
|
40
|
+
"gitHead": "6d8f85cd07989bfda0ad73c6ec2e1532949553dd"
|
|
45
41
|
}
|