@uniformdev/tms-sdk 20.48.1-alpha.27 → 20.48.1-alpha.33.sha-eb3f272086

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
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
6
11
  var __export = (target, all) => {
7
12
  for (var name in all)
8
13
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -15,11 +20,137 @@ var __copyProps = (to, from, except, desc) => {
15
20
  }
16
21
  return to;
17
22
  };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
18
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
32
 
33
+ // ../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js
34
+ var require_yocto_queue = __commonJS({
35
+ "../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js"(exports2, module2) {
36
+ "use strict";
37
+ var Node = class {
38
+ /// value;
39
+ /// next;
40
+ constructor(value) {
41
+ this.value = value;
42
+ this.next = void 0;
43
+ }
44
+ };
45
+ var Queue = class {
46
+ // TODO: Use private class fields when targeting Node.js 12.
47
+ // #_head;
48
+ // #_tail;
49
+ // #_size;
50
+ constructor() {
51
+ this.clear();
52
+ }
53
+ enqueue(value) {
54
+ const node = new Node(value);
55
+ if (this._head) {
56
+ this._tail.next = node;
57
+ this._tail = node;
58
+ } else {
59
+ this._head = node;
60
+ this._tail = node;
61
+ }
62
+ this._size++;
63
+ }
64
+ dequeue() {
65
+ const current = this._head;
66
+ if (!current) {
67
+ return;
68
+ }
69
+ this._head = this._head.next;
70
+ this._size--;
71
+ return current.value;
72
+ }
73
+ clear() {
74
+ this._head = void 0;
75
+ this._tail = void 0;
76
+ this._size = 0;
77
+ }
78
+ get size() {
79
+ return this._size;
80
+ }
81
+ *[Symbol.iterator]() {
82
+ let current = this._head;
83
+ while (current) {
84
+ yield current.value;
85
+ current = current.next;
86
+ }
87
+ }
88
+ };
89
+ module2.exports = Queue;
90
+ }
91
+ });
92
+
93
+ // ../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js
94
+ var require_p_limit = __commonJS({
95
+ "../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js"(exports2, module2) {
96
+ "use strict";
97
+ var Queue = require_yocto_queue();
98
+ var pLimit2 = (concurrency) => {
99
+ if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
100
+ throw new TypeError("Expected `concurrency` to be a number from 1 and up");
101
+ }
102
+ const queue = new Queue();
103
+ let activeCount = 0;
104
+ const next = () => {
105
+ activeCount--;
106
+ if (queue.size > 0) {
107
+ queue.dequeue()();
108
+ }
109
+ };
110
+ const run = async (fn, resolve, ...args) => {
111
+ activeCount++;
112
+ const result = (async () => fn(...args))();
113
+ resolve(result);
114
+ try {
115
+ await result;
116
+ } catch (e) {
117
+ }
118
+ next();
119
+ };
120
+ const enqueue = (fn, resolve, ...args) => {
121
+ queue.enqueue(run.bind(null, fn, resolve, ...args));
122
+ (async () => {
123
+ await Promise.resolve();
124
+ if (activeCount < concurrency && queue.size > 0) {
125
+ queue.dequeue()();
126
+ }
127
+ })();
128
+ };
129
+ const generator = (fn, ...args) => new Promise((resolve) => {
130
+ enqueue(fn, resolve, ...args);
131
+ });
132
+ Object.defineProperties(generator, {
133
+ activeCount: {
134
+ get: () => activeCount
135
+ },
136
+ pendingCount: {
137
+ get: () => queue.size
138
+ },
139
+ clearQueue: {
140
+ value: () => {
141
+ queue.clear();
142
+ }
143
+ }
144
+ });
145
+ return generator;
146
+ };
147
+ module2.exports = pLimit2;
148
+ }
149
+ });
150
+
20
151
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
152
+ var index_exports = {};
153
+ __export(index_exports, {
23
154
  collectTranslationPayload: () => collectTranslationPayload,
24
155
  getCompositionForTranslation: () => getCompositionForTranslation,
25
156
  getEntryForTranslation: () => getEntryForTranslation,
@@ -29,7 +160,7 @@ __export(src_exports, {
29
160
  translateComposition: () => translateComposition,
30
161
  translateEntry: () => translateEntry
31
162
  });
32
- module.exports = __toCommonJS(src_exports);
163
+ module.exports = __toCommonJS(index_exports);
33
164
 
34
165
  // src/collectTranslationPayload.ts
35
166
  var import_canvas2 = require("@uniformdev/canvas");
@@ -103,8 +234,23 @@ var getPropsAsBase64 = (node, ignoreProps) => {
103
234
  props[key] = node[key];
104
235
  }
105
236
  });
237
+ applyMissingSerializedDefaults(node.type, props);
106
238
  return btoa(JSON.stringify(props));
107
239
  };
240
+ function applyMissingSerializedDefaults(nodeType, props) {
241
+ if (props.version === void 0) {
242
+ props.version = 1;
243
+ }
244
+ if ((nodeType === "text" || nodeType === "tab") && props.format === void 0) {
245
+ props.format = 0;
246
+ } else if (nodeType === "list" && props.start === void 0) {
247
+ props.start = 1;
248
+ } else if (nodeType === "listitem" && props.value === void 0) {
249
+ props.value = 1;
250
+ } else if (nodeType === "tablecell" && props.headerState === void 0) {
251
+ props.headerState = 0;
252
+ }
253
+ }
108
254
  var getNodeMetaAttributesString = (node) => {
109
255
  const metadata = {};
110
256
  if ((0, import_richtext.isRichTextNodeType)(node, "text")) {
@@ -125,7 +271,10 @@ var getNodeMetaAttributesString = (node) => {
125
271
  metadata["tag"] = node.tag;
126
272
  }
127
273
  } else if ((0, import_richtext.isRichTextNodeType)(node, "listitem")) {
128
- metadata["value"] = String(node.value);
274
+ const value = (0, import_richtext.getRichTextListItemValue)(node.value);
275
+ if (typeof value === "number") {
276
+ metadata["value"] = String(value);
277
+ }
129
278
  }
130
279
  if (!Object.keys(metadata).length) {
131
280
  return "";
@@ -315,6 +464,9 @@ var processComponentTranslation = ({
315
464
  });
316
465
  return { updated };
317
466
  };
467
+ var isNestedParameterType = (type) => {
468
+ return type === import_canvas.CANVAS_BLOCK_PARAM_TYPE;
469
+ };
318
470
  var processParameterTranslation = ({
319
471
  uniformSourceLocale,
320
472
  uniformTargetLocale,
@@ -325,6 +477,14 @@ var processParameterTranslation = ({
325
477
  if (originalParameter.type !== parameter.type) {
326
478
  return { updated: false };
327
479
  }
480
+ if (isNestedParameterType(originalParameter.type)) {
481
+ return processNestedParameterTranslation({
482
+ uniformSourceLocale,
483
+ uniformTargetLocale,
484
+ originalParameter,
485
+ parameter
486
+ });
487
+ }
328
488
  if (!originalParameter.locales && originalParameter.value === void 0) {
329
489
  return { updated: false };
330
490
  }
@@ -337,7 +497,7 @@ var processParameterTranslation = ({
337
497
  left: originalParameterSource,
338
498
  right: sourceValue
339
499
  });
340
- const isTargetValueUntouched = isSameParameterValue({
500
+ const isTargetValueUntouched = originalTargetValue === void 0 ? true : isSameParameterValue({
341
501
  parameterType: originalParameter.type,
342
502
  left: (_d = originalParameter.locales) == null ? void 0 : _d[uniformTargetLocale],
343
503
  right: originalTargetValue
@@ -369,6 +529,39 @@ var processParameterTranslation = ({
369
529
  }
370
530
  return { updated: false };
371
531
  };
532
+ var processNestedParameterTranslation = ({
533
+ uniformSourceLocale,
534
+ uniformTargetLocale,
535
+ originalParameter,
536
+ parameter
537
+ }) => {
538
+ let updated = false;
539
+ if (originalParameter.type == import_canvas.CANVAS_BLOCK_PARAM_TYPE && Array.isArray(originalParameter.value) && Array.isArray(parameter.value)) {
540
+ const originalValue = originalParameter.value;
541
+ const translatedValue = parameter.value;
542
+ for (const translatedBlock of translatedValue) {
543
+ if (!translatedBlock._id || !translatedBlock.type) {
544
+ continue;
545
+ }
546
+ const originalBlock = originalValue.find(
547
+ (b) => b._id === translatedBlock._id && b.type === translatedBlock.type
548
+ );
549
+ if (!originalBlock) {
550
+ continue;
551
+ }
552
+ const { updated: blockUpdated } = processComponentTranslation({
553
+ uniformSourceLocale,
554
+ uniformTargetLocale,
555
+ originalNode: originalBlock,
556
+ translatedComponent: translatedBlock
557
+ });
558
+ if (blockUpdated) {
559
+ updated = true;
560
+ }
561
+ }
562
+ }
563
+ return { updated };
564
+ };
372
565
  var processOverrideTranslation = ({
373
566
  uniformSourceLocale,
374
567
  uniformTargetLocale,
@@ -481,7 +674,8 @@ var collectTranslationPayload = ({
481
674
  uniformReleaseId,
482
675
  targetLang,
483
676
  entity,
484
- entityType
677
+ entityType,
678
+ config = {}
485
679
  }) => {
486
680
  if (!uniformSourceLocale || !uniformTargetLocale || !targetLang || !entity) {
487
681
  return createErrorResult2("invalid-args");
@@ -505,16 +699,22 @@ var collectTranslationPayload = ({
505
699
  },
506
700
  components: {}
507
701
  };
508
- (0, import_canvas2.walkNodeTree)(entity, ({ node, actions }) => {
702
+ (0, import_canvas2.walkNodeTree)(entity, ({ node, actions, ancestorsAndSelf }) => {
703
+ var _a;
509
704
  if (!node.type || !node._id) {
510
705
  actions.stopProcessingDescendants();
511
706
  return;
512
707
  }
708
+ if (((_a = ancestorsAndSelf.at(0)) == null ? void 0 : _a.type) === "block") {
709
+ actions.stopProcessingDescendants();
710
+ return;
711
+ }
513
712
  const { _id, type, parameters, _overrides } = collectFromNode({
514
713
  uniformSourceLocale,
515
714
  uniformTargetLocale,
516
715
  node,
517
- deep: false
716
+ deep: false,
717
+ config
518
718
  });
519
719
  if (parameters || _overrides) {
520
720
  payload.components[node._id] = {
@@ -531,7 +731,8 @@ var collectFromNode = ({
531
731
  uniformSourceLocale,
532
732
  uniformTargetLocale,
533
733
  node,
534
- deep
734
+ deep,
735
+ config
535
736
  }) => {
536
737
  var _a, _b, _c;
537
738
  const collectedParameters = {};
@@ -541,12 +742,24 @@ var collectFromNode = ({
541
742
  const entryFields = "fields" in node ? node.fields : void 0;
542
743
  Object.entries((_a = componentParameters != null ? componentParameters : entryFields) != null ? _a : {}).forEach(([paramKey, param]) => {
543
744
  var _a2, _b2;
745
+ if (isNestedParameterType(param.type)) {
746
+ const nestedParam = collectNestedParameter({
747
+ param,
748
+ uniformSourceLocale,
749
+ uniformTargetLocale,
750
+ config
751
+ });
752
+ if (nestedParam) {
753
+ collectedParameters[paramKey] = nestedParam;
754
+ }
755
+ return;
756
+ }
544
757
  const sourceLocaleValue = (_a2 = param.locales) == null ? void 0 : _a2[uniformSourceLocale];
545
758
  const targetLocaleValue = (_b2 = param.locales) == null ? void 0 : _b2[uniformTargetLocale];
546
759
  if (!canTranslateParameterValue(param, sourceLocaleValue)) {
547
760
  return;
548
761
  }
549
- if (!isTargetLocaleUntouched(param.type, sourceLocaleValue, targetLocaleValue)) {
762
+ if (!config.ignoreTargetLocaleValueMismatch && !isTargetLocaleUntouched(param.type, sourceLocaleValue, targetLocaleValue)) {
550
763
  return;
551
764
  }
552
765
  collectedParameters[paramKey] = {
@@ -554,7 +767,7 @@ var collectFromNode = ({
554
767
  locales: {
555
768
  [TRANSLATION_PAYLOAD_SOURCE_KEY]: sourceLocaleValue,
556
769
  [TRANSLATION_PAYLOAD_TARGET_KEY]: preprocessTargetValue(param, sourceLocaleValue),
557
- [TRANSLATION_PAYLOAD_ORIGINAL_TARGET_KEY]: targetLocaleValue
770
+ [TRANSLATION_PAYLOAD_ORIGINAL_TARGET_KEY]: !config.ignoreTargetLocaleValueMismatch ? targetLocaleValue : void 0
558
771
  }
559
772
  };
560
773
  });
@@ -569,7 +782,8 @@ var collectFromNode = ({
569
782
  uniformSourceLocale,
570
783
  uniformTargetLocale,
571
784
  node: slotComponent,
572
- deep: true
785
+ deep: true,
786
+ config
573
787
  });
574
788
  const hasContent = collectedNode.parameters || collectedNode._overrides || collectedNode.slots;
575
789
  if (hasContent) {
@@ -582,23 +796,37 @@ var collectFromNode = ({
582
796
  Object.entries((_c = node._overrides) != null ? _c : {}).forEach(([overrideKey, override]) => {
583
797
  var _a2, _b2;
584
798
  Object.entries((_a2 = override.parameters) != null ? _a2 : {}).forEach(([paramKey, param]) => {
585
- var _a3, _b3, _c2, _d, _e;
586
- const sourceLocaleValue = (_a3 = param.locales) == null ? void 0 : _a3[uniformSourceLocale];
587
- const targetLocaleValue = (_b3 = param.locales) == null ? void 0 : _b3[uniformTargetLocale];
799
+ var _a3, _b3, _c2, _d, _e, _f, _g, _h;
800
+ if (isNestedParameterType(param.type)) {
801
+ const nestedParam = collectNestedParameter({
802
+ param,
803
+ uniformSourceLocale,
804
+ uniformTargetLocale,
805
+ config
806
+ });
807
+ if (nestedParam) {
808
+ (_a3 = collectedOverrides[overrideKey]) != null ? _a3 : collectedOverrides[overrideKey] = {};
809
+ (_c2 = (_b3 = collectedOverrides[overrideKey]).parameters) != null ? _c2 : _b3.parameters = {};
810
+ collectedOverrides[overrideKey].parameters[paramKey] = nestedParam;
811
+ }
812
+ return;
813
+ }
814
+ const sourceLocaleValue = (_d = param.locales) == null ? void 0 : _d[uniformSourceLocale];
815
+ const targetLocaleValue = (_e = param.locales) == null ? void 0 : _e[uniformTargetLocale];
588
816
  if (!canTranslateParameterValue(param, sourceLocaleValue)) {
589
817
  return;
590
818
  }
591
- if (!isTargetLocaleUntouched(param.type, sourceLocaleValue, targetLocaleValue)) {
819
+ if (!config.ignoreTargetLocaleValueMismatch && !isTargetLocaleUntouched(param.type, sourceLocaleValue, targetLocaleValue)) {
592
820
  return;
593
821
  }
594
- (_c2 = collectedOverrides[overrideKey]) != null ? _c2 : collectedOverrides[overrideKey] = {};
595
- (_e = (_d = collectedOverrides[overrideKey]).parameters) != null ? _e : _d.parameters = {};
822
+ (_f = collectedOverrides[overrideKey]) != null ? _f : collectedOverrides[overrideKey] = {};
823
+ (_h = (_g = collectedOverrides[overrideKey]).parameters) != null ? _h : _g.parameters = {};
596
824
  collectedOverrides[overrideKey].parameters[paramKey] = {
597
825
  type: param.type,
598
826
  locales: {
599
827
  [TRANSLATION_PAYLOAD_SOURCE_KEY]: sourceLocaleValue,
600
828
  [TRANSLATION_PAYLOAD_TARGET_KEY]: preprocessTargetValue(param, sourceLocaleValue),
601
- [TRANSLATION_PAYLOAD_ORIGINAL_TARGET_KEY]: targetLocaleValue
829
+ [TRANSLATION_PAYLOAD_ORIGINAL_TARGET_KEY]: !config.ignoreTargetLocaleValueMismatch ? targetLocaleValue : void 0
602
830
  }
603
831
  };
604
832
  });
@@ -614,7 +842,8 @@ var collectFromNode = ({
614
842
  node: slotComponent,
615
843
  // keep tree structure for `Slot Sections`
616
844
  // to store whole `override` content in scope of current component
617
- deep: true
845
+ deep: true,
846
+ config
618
847
  });
619
848
  const hasContent = collectedNode.parameters || collectedNode._overrides || collectedNode.slots;
620
849
  if (hasContent) {
@@ -637,6 +866,42 @@ var collectFromNode = ({
637
866
  _overrides: hasOverrides ? collectedOverrides : void 0
638
867
  };
639
868
  };
869
+ var collectNestedParameter = ({
870
+ param,
871
+ uniformSourceLocale,
872
+ uniformTargetLocale,
873
+ config
874
+ }) => {
875
+ if (param.type === import_canvas2.CANVAS_BLOCK_PARAM_TYPE && Array.isArray(param.value)) {
876
+ const blockValue = param.value;
877
+ const collectedBlocks = [];
878
+ for (const blockEntry of blockValue) {
879
+ if (!blockEntry._id || !blockEntry.type) {
880
+ continue;
881
+ }
882
+ const collectedNode = collectFromNode({
883
+ uniformSourceLocale,
884
+ uniformTargetLocale,
885
+ node: blockEntry,
886
+ deep: false,
887
+ config
888
+ });
889
+ const hasContent = collectedNode.parameters || collectedNode._overrides;
890
+ if (hasContent) {
891
+ collectedNode.slots = void 0;
892
+ collectedBlocks.push(collectedNode);
893
+ }
894
+ }
895
+ if (collectedBlocks.length === 0) {
896
+ return void 0;
897
+ }
898
+ return {
899
+ type: import_canvas2.CANVAS_BLOCK_PARAM_TYPE,
900
+ value: collectedBlocks
901
+ };
902
+ }
903
+ return void 0;
904
+ };
640
905
  var canTranslateParameterValue = (parameter, value) => {
641
906
  if (parameter.type === SUPPORTED_PARAM_TYPES.text) {
642
907
  if (typeof value !== "string" || !value) {
@@ -689,6 +954,421 @@ var preprocessTargetValue = (parameter, value) => {
689
954
 
690
955
  // src/getCompositionForTranslation.ts
691
956
  var import_canvas3 = require("@uniformdev/canvas");
957
+
958
+ // ../context/dist/api/api.mjs
959
+ var import_p_limit = __toESM(require_p_limit(), 1);
960
+ var __defProp2 = Object.defineProperty;
961
+ var __typeError = (msg) => {
962
+ throw TypeError(msg);
963
+ };
964
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
965
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
966
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
967
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
968
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
969
+ var defaultLimitPolicy = (0, import_p_limit.default)(6);
970
+ var UNIFORM_BEARER_TOKEN_NOT_VALID_OR_EXPIRED_MESSAGE = "Bearer token not valid or expired";
971
+ var ApiClientError = class _ApiClientError extends Error {
972
+ constructor(errorMessage, fetchMethod, fetchUri, statusCode, statusText, requestId) {
973
+ super(
974
+ `${errorMessage}
975
+ ${statusCode}${statusText ? " " + statusText : ""} (${fetchMethod} ${fetchUri}${requestId ? ` Request ID: ${requestId}` : ""})`
976
+ );
977
+ __publicField(this, "errorMessage", errorMessage);
978
+ __publicField(this, "fetchMethod", fetchMethod);
979
+ __publicField(this, "fetchUri", fetchUri);
980
+ __publicField(this, "statusCode", statusCode);
981
+ __publicField(this, "statusText", statusText);
982
+ __publicField(this, "requestId", requestId);
983
+ Object.setPrototypeOf(this, _ApiClientError.prototype);
984
+ }
985
+ };
986
+ var BearerTokenNotValidOrExpiredError = class _BearerTokenNotValidOrExpiredError extends ApiClientError {
987
+ constructor(errorMessage, fetchMethod, fetchUri, statusCode, statusText, requestId) {
988
+ super(errorMessage, fetchMethod, fetchUri, statusCode, statusText, requestId);
989
+ Object.setPrototypeOf(this, _BearerTokenNotValidOrExpiredError.prototype);
990
+ }
991
+ };
992
+ var ApiClient = class _ApiClient {
993
+ constructor(options) {
994
+ __publicField(this, "options");
995
+ var _a, _b, _c, _d, _e;
996
+ if (!options.apiKey && !options.bearerToken) {
997
+ throw new Error("You must provide an API key or a bearer token");
998
+ }
999
+ let leFetch = options.fetch;
1000
+ if (!leFetch) {
1001
+ if (typeof window !== "undefined") {
1002
+ leFetch = window.fetch.bind(window);
1003
+ } else if (typeof fetch !== "undefined") {
1004
+ leFetch = fetch;
1005
+ } else {
1006
+ throw new Error("You must provide or polyfill a fetch implementation when not in a browser");
1007
+ }
1008
+ }
1009
+ this.options = {
1010
+ ...options,
1011
+ fetch: leFetch,
1012
+ apiHost: this.ensureApiHost(options.apiHost),
1013
+ apiKey: (_a = options.apiKey) != null ? _a : null,
1014
+ projectId: (_b = options.projectId) != null ? _b : null,
1015
+ bearerToken: (_c = options.bearerToken) != null ? _c : null,
1016
+ limitPolicy: (_d = options.limitPolicy) != null ? _d : defaultLimitPolicy,
1017
+ bypassCache: (_e = options.bypassCache) != null ? _e : false
1018
+ };
1019
+ }
1020
+ async apiClient(fetchUri, options) {
1021
+ return (await this.apiClientWithResponse(fetchUri, options)).body;
1022
+ }
1023
+ async apiClientWithResponse(fetchUri, options) {
1024
+ return this.options.limitPolicy(async () => {
1025
+ var _a, _b;
1026
+ const coreHeaders = this.options.apiKey ? {
1027
+ "x-api-key": this.options.apiKey
1028
+ } : {
1029
+ Authorization: `Bearer ${this.options.bearerToken}`
1030
+ };
1031
+ if (this.options.bypassCache) {
1032
+ coreHeaders["x-bypass-cache"] = "true";
1033
+ }
1034
+ const { fetch: fetch2, signal } = this.options;
1035
+ const callApi = () => fetch2(fetchUri.toString(), {
1036
+ ...options,
1037
+ signal,
1038
+ headers: {
1039
+ ...options == null ? void 0 : options.headers,
1040
+ ...coreHeaders
1041
+ }
1042
+ });
1043
+ const apiResponse = await handleRateLimits(callApi);
1044
+ if (!apiResponse.ok) {
1045
+ let message = "";
1046
+ try {
1047
+ const responseText = await apiResponse.text();
1048
+ try {
1049
+ const parsed = JSON.parse(responseText);
1050
+ if (parsed.errorMessage) {
1051
+ message = Array.isArray(parsed.errorMessage) ? parsed.errorMessage.join(", ") : parsed.errorMessage;
1052
+ } else {
1053
+ message = responseText;
1054
+ }
1055
+ } catch (e) {
1056
+ message = responseText;
1057
+ }
1058
+ } catch (e) {
1059
+ message = `General error`;
1060
+ }
1061
+ if (apiResponse.status === 401 && message === UNIFORM_BEARER_TOKEN_NOT_VALID_OR_EXPIRED_MESSAGE) {
1062
+ throw new BearerTokenNotValidOrExpiredError(
1063
+ message,
1064
+ (_a = options == null ? void 0 : options.method) != null ? _a : "GET",
1065
+ fetchUri.toString(),
1066
+ apiResponse.status,
1067
+ apiResponse.statusText,
1068
+ _ApiClient.getRequestId(apiResponse)
1069
+ );
1070
+ }
1071
+ throw new ApiClientError(
1072
+ message,
1073
+ (_b = options == null ? void 0 : options.method) != null ? _b : "GET",
1074
+ fetchUri.toString(),
1075
+ apiResponse.status,
1076
+ apiResponse.statusText,
1077
+ _ApiClient.getRequestId(apiResponse)
1078
+ );
1079
+ }
1080
+ if (options == null ? void 0 : options.expectNoContent) {
1081
+ return { response: apiResponse, body: null };
1082
+ }
1083
+ return {
1084
+ response: apiResponse,
1085
+ body: await apiResponse.json()
1086
+ };
1087
+ });
1088
+ }
1089
+ createUrl(path, queryParams, hostOverride) {
1090
+ const url = new URL(`${hostOverride != null ? hostOverride : this.options.apiHost}${path}`);
1091
+ Object.entries(queryParams != null ? queryParams : {}).forEach(([key, value]) => {
1092
+ var _a;
1093
+ if (typeof value !== "undefined" && value !== null) {
1094
+ url.searchParams.append(key, Array.isArray(value) ? value.join(",") : (_a = value == null ? void 0 : value.toString()) != null ? _a : "");
1095
+ }
1096
+ });
1097
+ return url;
1098
+ }
1099
+ ensureApiHost(apiHost) {
1100
+ if (!apiHost) return "https://uniform.app";
1101
+ if (!(apiHost == null ? void 0 : apiHost.startsWith("http"))) {
1102
+ throw new Error('Your apiHost must start with "http"');
1103
+ }
1104
+ if (apiHost.indexOf("/", 8) > -1) {
1105
+ throw new Error("Your apiHost must not contain a path element after the domain");
1106
+ }
1107
+ if (apiHost.indexOf("?") > -1) {
1108
+ throw new Error("Your apiHost must not contain a query string");
1109
+ }
1110
+ if (apiHost == null ? void 0 : apiHost.endsWith("/")) {
1111
+ apiHost = apiHost.substring(0, apiHost.length - 1);
1112
+ }
1113
+ return apiHost;
1114
+ }
1115
+ static getRequestId(response) {
1116
+ const apigRequestId = response.headers.get("apigw-requestid");
1117
+ if (apigRequestId) {
1118
+ return apigRequestId;
1119
+ }
1120
+ return void 0;
1121
+ }
1122
+ };
1123
+ async function handleRateLimits(callApi) {
1124
+ var _a;
1125
+ const backoffRetries = 5;
1126
+ let backoffRetriesLeft = backoffRetries;
1127
+ let response;
1128
+ while (backoffRetriesLeft > 0) {
1129
+ response = await callApi();
1130
+ if (response.status !== 429) {
1131
+ break;
1132
+ }
1133
+ let resetWait = 0;
1134
+ try {
1135
+ const responseClone = response.clone();
1136
+ const dateHeader = responseClone.headers.get("date");
1137
+ const serverTime = dateHeader ? new Date(dateHeader).getTime() : void 0;
1138
+ const body = await responseClone.json();
1139
+ const resetTime = (_a = body == null ? void 0 : body.info) == null ? void 0 : _a.reset;
1140
+ if (typeof serverTime === "number" && typeof resetTime === "number") {
1141
+ resetWait = Math.max(0, Math.min(Math.round(1.1 * (resetTime - serverTime)), 1e4));
1142
+ }
1143
+ } catch (e) {
1144
+ }
1145
+ const base = Math.pow(2, backoffRetries - backoffRetriesLeft) * 333;
1146
+ const backoffWait = base + Math.round(Math.random() * (base / 2)) * (Math.random() > 0.5 ? 1 : -1);
1147
+ await new Promise((resolve) => setTimeout(resolve, Math.max(0, resetWait + backoffWait)));
1148
+ backoffRetriesLeft -= 1;
1149
+ }
1150
+ return response;
1151
+ }
1152
+ var _url;
1153
+ var _AggregateClient = class _AggregateClient2 extends ApiClient {
1154
+ constructor(options) {
1155
+ super(options);
1156
+ }
1157
+ /** Fetches all aggregates for a project */
1158
+ async get(options) {
1159
+ const { projectId } = this.options;
1160
+ const fetchUri = this.createUrl(__privateGet(_AggregateClient2, _url), { ...options, projectId });
1161
+ return await this.apiClient(fetchUri);
1162
+ }
1163
+ /** Updates or creates (based on id) an Aggregate */
1164
+ async upsert(body) {
1165
+ const fetchUri = this.createUrl(__privateGet(_AggregateClient2, _url));
1166
+ await this.apiClient(fetchUri, {
1167
+ method: "PUT",
1168
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1169
+ expectNoContent: true
1170
+ });
1171
+ }
1172
+ /** Deletes an Aggregate */
1173
+ async remove(body) {
1174
+ const fetchUri = this.createUrl(__privateGet(_AggregateClient2, _url));
1175
+ await this.apiClient(fetchUri, {
1176
+ method: "DELETE",
1177
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1178
+ expectNoContent: true
1179
+ });
1180
+ }
1181
+ };
1182
+ _url = /* @__PURE__ */ new WeakMap();
1183
+ __privateAdd(_AggregateClient, _url, "/api/v2/aggregate");
1184
+ var _url2;
1185
+ var _DimensionClient = class _DimensionClient2 extends ApiClient {
1186
+ constructor(options) {
1187
+ super(options);
1188
+ }
1189
+ /** Fetches the known score dimensions for a project */
1190
+ async get(options) {
1191
+ const { projectId } = this.options;
1192
+ const fetchUri = this.createUrl(__privateGet(_DimensionClient2, _url2), { ...options, projectId });
1193
+ return await this.apiClient(fetchUri);
1194
+ }
1195
+ };
1196
+ _url2 = /* @__PURE__ */ new WeakMap();
1197
+ __privateAdd(_DimensionClient, _url2, "/api/v2/dimension");
1198
+ var _url3;
1199
+ var _valueUrl;
1200
+ var _EnrichmentClient = class _EnrichmentClient2 extends ApiClient {
1201
+ constructor(options) {
1202
+ super(options);
1203
+ }
1204
+ /** Fetches all enrichments and values for a project, grouped by category */
1205
+ async get(options) {
1206
+ const { projectId } = this.options;
1207
+ const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _url3), { ...options, projectId });
1208
+ return await this.apiClient(fetchUri);
1209
+ }
1210
+ /** Updates or creates (based on id) an enrichment category */
1211
+ async upsertCategory(body) {
1212
+ const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _url3));
1213
+ await this.apiClient(fetchUri, {
1214
+ method: "PUT",
1215
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1216
+ expectNoContent: true
1217
+ });
1218
+ }
1219
+ /** Deletes an enrichment category */
1220
+ async removeCategory(body) {
1221
+ const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _url3));
1222
+ await this.apiClient(fetchUri, {
1223
+ method: "DELETE",
1224
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1225
+ expectNoContent: true
1226
+ });
1227
+ }
1228
+ /** Updates or creates (based on id) an enrichment value within an enrichment category */
1229
+ async upsertValue(body) {
1230
+ const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _valueUrl));
1231
+ await this.apiClient(fetchUri, {
1232
+ method: "PUT",
1233
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1234
+ expectNoContent: true
1235
+ });
1236
+ }
1237
+ /** Deletes an enrichment value within an enrichment category. The category is left alone. */
1238
+ async removeValue(body) {
1239
+ const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _valueUrl));
1240
+ await this.apiClient(fetchUri, {
1241
+ method: "DELETE",
1242
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1243
+ expectNoContent: true
1244
+ });
1245
+ }
1246
+ };
1247
+ _url3 = /* @__PURE__ */ new WeakMap();
1248
+ _valueUrl = /* @__PURE__ */ new WeakMap();
1249
+ __privateAdd(_EnrichmentClient, _url3, "/api/v1/enrichments");
1250
+ __privateAdd(_EnrichmentClient, _valueUrl, "/api/v1/enrichment-values");
1251
+ var _url4;
1252
+ var _ManifestClient = class _ManifestClient2 extends ApiClient {
1253
+ constructor(options) {
1254
+ super(options);
1255
+ }
1256
+ /** Fetches the Context manifest for a project */
1257
+ async get(options) {
1258
+ const { projectId } = this.options;
1259
+ const fetchUri = this.createUrl(__privateGet(_ManifestClient2, _url4), { ...options, projectId });
1260
+ return await this.apiClient(fetchUri);
1261
+ }
1262
+ /** Publishes the Context manifest for a project */
1263
+ async publish() {
1264
+ const { projectId } = this.options;
1265
+ const fetchUri = this.createUrl("/api/v1/publish", { siteId: projectId });
1266
+ await this.apiClient(fetchUri, {
1267
+ method: "POST",
1268
+ expectNoContent: true
1269
+ });
1270
+ }
1271
+ };
1272
+ _url4 = /* @__PURE__ */ new WeakMap();
1273
+ __privateAdd(_ManifestClient, _url4, "/api/v2/manifest");
1274
+ var _url5;
1275
+ var _QuirkClient = class _QuirkClient2 extends ApiClient {
1276
+ constructor(options) {
1277
+ super(options);
1278
+ }
1279
+ /** Fetches all Quirks for a project */
1280
+ async get(options) {
1281
+ const { projectId } = this.options;
1282
+ const fetchUri = this.createUrl(__privateGet(_QuirkClient2, _url5), { ...options, projectId });
1283
+ return await this.apiClient(fetchUri);
1284
+ }
1285
+ /** Updates or creates (based on id) a Quirk */
1286
+ async upsert(body) {
1287
+ const fetchUri = this.createUrl(__privateGet(_QuirkClient2, _url5));
1288
+ await this.apiClient(fetchUri, {
1289
+ method: "PUT",
1290
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1291
+ expectNoContent: true
1292
+ });
1293
+ }
1294
+ /** Deletes a Quirk */
1295
+ async remove(body) {
1296
+ const fetchUri = this.createUrl(__privateGet(_QuirkClient2, _url5));
1297
+ await this.apiClient(fetchUri, {
1298
+ method: "DELETE",
1299
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1300
+ expectNoContent: true
1301
+ });
1302
+ }
1303
+ };
1304
+ _url5 = /* @__PURE__ */ new WeakMap();
1305
+ __privateAdd(_QuirkClient, _url5, "/api/v2/quirk");
1306
+ var _url6;
1307
+ var _SignalClient = class _SignalClient2 extends ApiClient {
1308
+ constructor(options) {
1309
+ super(options);
1310
+ }
1311
+ /** Fetches all Signals for a project */
1312
+ async get(options) {
1313
+ const { projectId } = this.options;
1314
+ const fetchUri = this.createUrl(__privateGet(_SignalClient2, _url6), { ...options, projectId });
1315
+ return await this.apiClient(fetchUri);
1316
+ }
1317
+ /** Updates or creates (based on id) a Signal */
1318
+ async upsert(body) {
1319
+ const fetchUri = this.createUrl(__privateGet(_SignalClient2, _url6));
1320
+ await this.apiClient(fetchUri, {
1321
+ method: "PUT",
1322
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1323
+ expectNoContent: true
1324
+ });
1325
+ }
1326
+ /** Deletes a Signal */
1327
+ async remove(body) {
1328
+ const fetchUri = this.createUrl(__privateGet(_SignalClient2, _url6));
1329
+ await this.apiClient(fetchUri, {
1330
+ method: "DELETE",
1331
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1332
+ expectNoContent: true
1333
+ });
1334
+ }
1335
+ };
1336
+ _url6 = /* @__PURE__ */ new WeakMap();
1337
+ __privateAdd(_SignalClient, _url6, "/api/v2/signal");
1338
+ var _url7;
1339
+ var _TestClient = class _TestClient2 extends ApiClient {
1340
+ constructor(options) {
1341
+ super(options);
1342
+ }
1343
+ /** Fetches all Tests for a project */
1344
+ async get(options) {
1345
+ const { projectId } = this.options;
1346
+ const fetchUri = this.createUrl(__privateGet(_TestClient2, _url7), { ...options, projectId });
1347
+ return await this.apiClient(fetchUri);
1348
+ }
1349
+ /** Updates or creates (based on id) a Test */
1350
+ async upsert(body) {
1351
+ const fetchUri = this.createUrl(__privateGet(_TestClient2, _url7));
1352
+ await this.apiClient(fetchUri, {
1353
+ method: "PUT",
1354
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1355
+ expectNoContent: true
1356
+ });
1357
+ }
1358
+ /** Deletes a Test */
1359
+ async remove(body) {
1360
+ const fetchUri = this.createUrl(__privateGet(_TestClient2, _url7));
1361
+ await this.apiClient(fetchUri, {
1362
+ method: "DELETE",
1363
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1364
+ expectNoContent: true
1365
+ });
1366
+ }
1367
+ };
1368
+ _url7 = /* @__PURE__ */ new WeakMap();
1369
+ __privateAdd(_TestClient, _url7, "/api/v2/test");
1370
+
1371
+ // src/getCompositionForTranslation.ts
692
1372
  var getCompositionForTranslation = async ({
693
1373
  canvasClient,
694
1374
  compositionId,
@@ -698,16 +1378,19 @@ var getCompositionForTranslation = async ({
698
1378
  if (!compositionId) {
699
1379
  return void 0;
700
1380
  }
701
- const composition = await canvasClient.getCompositionById({
702
- compositionId,
703
- releaseId: releaseId ? releaseId : void 0,
704
- withComponentIDs: true,
705
- skipDataResolution: true,
706
- skipOverridesResolution: true,
707
- skipPatternResolution: true,
708
- state
709
- });
710
- return composition ? composition : void 0;
1381
+ try {
1382
+ const composition = await canvasClient.get({
1383
+ compositionId,
1384
+ releaseId: releaseId ? releaseId : void 0,
1385
+ state
1386
+ });
1387
+ return composition ? composition : void 0;
1388
+ } catch (error) {
1389
+ if (error instanceof ApiClientError && error.statusCode === 404) {
1390
+ return void 0;
1391
+ }
1392
+ throw error;
1393
+ }
711
1394
  };
712
1395
 
713
1396
  // src/getEntryForTranslation.ts
@@ -722,14 +1405,10 @@ var getEntryForTranslation = async ({
722
1405
  if (!entryId) {
723
1406
  return void 0;
724
1407
  }
725
- const entriesResponse = await contentClient.getEntries({
1408
+ const entriesResponse = await contentClient.list({
726
1409
  entryIDs: [entryId],
727
1410
  releaseId: releaseId ? releaseId : void 0,
728
1411
  limit: 1,
729
- withComponentIDs: true,
730
- skipDataResolution: true,
731
- skipOverridesResolution: true,
732
- skipPatternResolution: true,
733
1412
  pattern,
734
1413
  state
735
1414
  });
@@ -858,7 +1537,7 @@ var defaultUpdateComposition = async ({
858
1537
  canvasClient,
859
1538
  composition
860
1539
  }) => {
861
- await canvasClient.updateComposition(composition);
1540
+ await canvasClient.save(composition);
862
1541
  return true;
863
1542
  };
864
1543
 
@@ -986,7 +1665,7 @@ var defaultUpdateEntry = async ({
986
1665
  contentClient,
987
1666
  entry
988
1667
  }) => {
989
- await contentClient.upsertEntry(entry);
1668
+ await contentClient.save(entry);
990
1669
  return true;
991
1670
  };
992
1671