@uniformdev/canvas 19.35.3-alpha.82 → 19.36.1-alpha.7
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 +47 -76
- package/dist/index.d.ts +47 -76
- package/dist/index.esm.js +93 -182
- package/dist/index.js +104 -195
- package/dist/index.mjs +93 -182
- package/package.json +3 -3
package/dist/index.js
CHANGED
@@ -283,7 +283,7 @@ __export(src_exports, {
|
|
283
283
|
ATTRIBUTE_PARAMETER_TYPE: () => ATTRIBUTE_PARAMETER_TYPE,
|
284
284
|
ATTRIBUTE_PARAMETER_VALUE: () => ATTRIBUTE_PARAMETER_VALUE,
|
285
285
|
ATTRIBUTE_PLACEHOLDER: () => ATTRIBUTE_PLACEHOLDER,
|
286
|
-
ApiClientError: () =>
|
286
|
+
ApiClientError: () => import_api8.ApiClientError,
|
287
287
|
BatchEntry: () => BatchEntry,
|
288
288
|
CANVAS_DRAFT_STATE: () => CANVAS_DRAFT_STATE,
|
289
289
|
CANVAS_ENRICHMENT_TAG_PARAM: () => CANVAS_ENRICHMENT_TAG_PARAM,
|
@@ -331,7 +331,6 @@ __export(src_exports, {
|
|
331
331
|
createEventBus: () => createEventBus,
|
332
332
|
createLimitPolicy: () => createLimitPolicy,
|
333
333
|
createUniformApiEnhancer: () => createUniformApiEnhancer,
|
334
|
-
createVariableReference: () => createVariableReference,
|
335
334
|
enhance: () => enhance,
|
336
335
|
extractLocales: () => extractLocales,
|
337
336
|
generateHash: () => generateHash,
|
@@ -357,7 +356,6 @@ __export(src_exports, {
|
|
357
356
|
mapSlotToPersonalizedVariations: () => mapSlotToPersonalizedVariations,
|
358
357
|
mapSlotToTestVariations: () => mapSlotToTestVariations,
|
359
358
|
nullLimitPolicy: () => nullLimitPolicy,
|
360
|
-
parseVariableExpression: () => parseVariableExpression,
|
361
359
|
subscribeToComposition: () => subscribeToComposition,
|
362
360
|
unstable_CompositionRelationshipClient: () => unstable_CompositionRelationshipClient,
|
363
361
|
walkComponentTree: () => walkComponentTree
|
@@ -365,6 +363,9 @@ __export(src_exports, {
|
|
365
363
|
module.exports = __toCommonJS(src_exports);
|
366
364
|
|
367
365
|
// src/CanvasClient.ts
|
366
|
+
var import_api2 = require("@uniformdev/context/api");
|
367
|
+
|
368
|
+
// src/enhancement/createLimitPolicy.ts
|
368
369
|
var import_api = require("@uniformdev/context/api");
|
369
370
|
|
370
371
|
// ../../node_modules/.pnpm/p-retry@5.1.2/node_modules/p-retry/index.js
|
@@ -542,7 +543,17 @@ function createLimitPolicy({
|
|
542
543
|
}
|
543
544
|
if (retry2) {
|
544
545
|
const retryFunc = currentFunc;
|
545
|
-
currentFunc = () => pRetry(retryFunc,
|
546
|
+
currentFunc = () => pRetry(retryFunc, {
|
547
|
+
...retry2,
|
548
|
+
onFailedAttempt: async (error) => {
|
549
|
+
if (retry2.onFailedAttempt) {
|
550
|
+
await retry2.onFailedAttempt(error);
|
551
|
+
}
|
552
|
+
if (error instanceof import_api.ApiClientError && typeof error.statusCode === "number" && error.statusCode.toString().startsWith("4")) {
|
553
|
+
throw error;
|
554
|
+
}
|
555
|
+
}
|
556
|
+
});
|
546
557
|
}
|
547
558
|
return currentFunc();
|
548
559
|
};
|
@@ -551,7 +562,7 @@ var nullLimitPolicy = async (func) => await func();
|
|
551
562
|
|
552
563
|
// src/CanvasClient.ts
|
553
564
|
var CANVAS_URL = "/api/v1/canvas";
|
554
|
-
var CanvasClient = class extends
|
565
|
+
var CanvasClient = class extends import_api2.ApiClient {
|
555
566
|
constructor(options) {
|
556
567
|
var _a;
|
557
568
|
if (!options.limitPolicy) {
|
@@ -654,9 +665,9 @@ var UncachedCanvasClient = class extends CanvasClient {
|
|
654
665
|
};
|
655
666
|
|
656
667
|
// src/CategoryClient.ts
|
657
|
-
var
|
668
|
+
var import_api3 = require("@uniformdev/context/api");
|
658
669
|
var CATEGORIES_URL = "/api/v1/categories";
|
659
|
-
var CategoryClient = class extends
|
670
|
+
var CategoryClient = class extends import_api3.ApiClient {
|
660
671
|
constructor(options) {
|
661
672
|
if (!options.limitPolicy) {
|
662
673
|
options.limitPolicy = createLimitPolicy({});
|
@@ -697,9 +708,9 @@ var UncachedCategoryClient = class extends CategoryClient {
|
|
697
708
|
};
|
698
709
|
|
699
710
|
// src/CompositionRelationshipClient.ts
|
700
|
-
var
|
711
|
+
var import_api4 = require("@uniformdev/context/api");
|
701
712
|
var COMPOSITION_RELATIONSHIP_URL = "/api/v1/composition-relationships";
|
702
|
-
var unstable_CompositionRelationshipClient = class extends
|
713
|
+
var unstable_CompositionRelationshipClient = class extends import_api4.ApiClient {
|
703
714
|
constructor(options) {
|
704
715
|
super(options);
|
705
716
|
this.getDefinitionsRelationships = async ({
|
@@ -760,10 +771,10 @@ var unstable_CompositionRelationshipClient = class extends import_api3.ApiClient
|
|
760
771
|
};
|
761
772
|
|
762
773
|
// src/DataSourceClient.ts
|
763
|
-
var
|
774
|
+
var import_api5 = require("@uniformdev/context/api");
|
764
775
|
var dataSourceUrl = "/api/v1/data-source";
|
765
776
|
var dataSourcesUrl = "/api/v1/data-sources";
|
766
|
-
var DataSourceClient = class extends
|
777
|
+
var DataSourceClient = class extends import_api5.ApiClient {
|
767
778
|
constructor(options) {
|
768
779
|
super(options);
|
769
780
|
}
|
@@ -800,9 +811,9 @@ var DataSourceClient = class extends import_api4.ApiClient {
|
|
800
811
|
};
|
801
812
|
|
802
813
|
// src/DataTypeClient.ts
|
803
|
-
var
|
814
|
+
var import_api6 = require("@uniformdev/context/api");
|
804
815
|
var _url;
|
805
|
-
var _DataTypeClient = class _DataTypeClient extends
|
816
|
+
var _DataTypeClient = class _DataTypeClient extends import_api6.ApiClient {
|
806
817
|
constructor(options) {
|
807
818
|
super(options);
|
808
819
|
}
|
@@ -1719,9 +1730,9 @@ function subscribeToComposition({
|
|
1719
1730
|
}
|
1720
1731
|
|
1721
1732
|
// src/RouteClient.ts
|
1722
|
-
var
|
1733
|
+
var import_api7 = require("@uniformdev/context/api");
|
1723
1734
|
var ROUTE_URL = "/api/v1/route";
|
1724
|
-
var RouteClient = class extends
|
1735
|
+
var RouteClient = class extends import_api7.ApiClient {
|
1725
1736
|
constructor(options) {
|
1726
1737
|
var _a;
|
1727
1738
|
if (!options.limitPolicy) {
|
@@ -1738,6 +1749,80 @@ var RouteClient = class extends import_api6.ApiClient {
|
|
1738
1749
|
}
|
1739
1750
|
};
|
1740
1751
|
|
1752
|
+
// src/utils/bindVariables.ts
|
1753
|
+
function bindVariables({
|
1754
|
+
variables,
|
1755
|
+
value,
|
1756
|
+
errorPrefix = "Variable",
|
1757
|
+
handleBinding
|
1758
|
+
}) {
|
1759
|
+
let boundCount = 0;
|
1760
|
+
const errors = [];
|
1761
|
+
const defaultHandleBinding = (variableName, variables2, errors2) => {
|
1762
|
+
const variableValue = variables2[variableName];
|
1763
|
+
if (variableValue === void 0) {
|
1764
|
+
errors2.push(`${errorPrefix} "${variableName}" is not defined`);
|
1765
|
+
return "";
|
1766
|
+
}
|
1767
|
+
return variableValue;
|
1768
|
+
};
|
1769
|
+
const result = value.replace(/(?<!\\)\${([^}]+)}/g, (_match, variableName) => {
|
1770
|
+
const variableValue = (handleBinding != null ? handleBinding : defaultHandleBinding)(variableName, variables, errors);
|
1771
|
+
boundCount++;
|
1772
|
+
return variableValue;
|
1773
|
+
});
|
1774
|
+
return { result, boundCount, errors: errors.length > 0 ? errors : void 0 };
|
1775
|
+
}
|
1776
|
+
|
1777
|
+
// src/utils/bindVariablesToObject.ts
|
1778
|
+
var import_immer = require("immer");
|
1779
|
+
function bindVariablesToObject(options) {
|
1780
|
+
return bindVariablesToObjectRecursive(options);
|
1781
|
+
}
|
1782
|
+
function bindVariablesToObjectRecursive({
|
1783
|
+
value,
|
1784
|
+
recursivePath,
|
1785
|
+
...bindVariablesOptions
|
1786
|
+
}) {
|
1787
|
+
let boundCount = 0;
|
1788
|
+
const errors = [];
|
1789
|
+
if (typeof value === "string") {
|
1790
|
+
return bindVariables({ ...bindVariablesOptions, value });
|
1791
|
+
}
|
1792
|
+
if (typeof value !== "object" || value === null) {
|
1793
|
+
return { boundCount: 0, result: value };
|
1794
|
+
}
|
1795
|
+
const result = (0, import_immer.produce)(value, (draft) => {
|
1796
|
+
Object.entries(draft).forEach(([property, oldValue]) => {
|
1797
|
+
const currentObjectPath = recursivePath ? `${recursivePath}.${property}` : property;
|
1798
|
+
if (typeof oldValue === "string") {
|
1799
|
+
const bindResult = bindVariables({ ...bindVariablesOptions, value: oldValue });
|
1800
|
+
if (oldValue !== bindResult.result || bindResult.errors) {
|
1801
|
+
boundCount += bindResult.boundCount;
|
1802
|
+
draft[property] = bindResult.result;
|
1803
|
+
if (bindResult.errors) {
|
1804
|
+
errors.push(...bindResult.errors.map((e) => `${currentObjectPath}: ${e}`));
|
1805
|
+
}
|
1806
|
+
}
|
1807
|
+
return;
|
1808
|
+
}
|
1809
|
+
const childBind = bindVariablesToObjectRecursive({
|
1810
|
+
...bindVariablesOptions,
|
1811
|
+
value: oldValue,
|
1812
|
+
recursivePath: currentObjectPath
|
1813
|
+
});
|
1814
|
+
if (childBind.boundCount || childBind.errors) {
|
1815
|
+
boundCount += childBind.boundCount;
|
1816
|
+
draft[property] = childBind.result;
|
1817
|
+
if (childBind.errors) {
|
1818
|
+
errors.push(...childBind.errors.map((e) => `${currentObjectPath}: ${e}`));
|
1819
|
+
}
|
1820
|
+
}
|
1821
|
+
});
|
1822
|
+
});
|
1823
|
+
return { boundCount, result, errors: errors.length > 0 ? errors : void 0 };
|
1824
|
+
}
|
1825
|
+
|
1741
1826
|
// src/utils/createApiEnhancer.ts
|
1742
1827
|
var createUniformApiEnhancer = ({ apiUrl }) => {
|
1743
1828
|
return async (message) => {
|
@@ -1785,8 +1870,8 @@ var getParameterAttributes = ({
|
|
1785
1870
|
[ATTRIBUTE_PARAMETER_VALUE]: String(value != null ? value : ""),
|
1786
1871
|
[ATTRIBUTE_PARAMETER_TYPE]: type,
|
1787
1872
|
[ATTRIBUTE_PLACEHOLDER]: placeholder,
|
1788
|
-
[ATTRIBUTE_MULTILINE]:
|
1789
|
-
contentEditable:
|
1873
|
+
[ATTRIBUTE_MULTILINE]: isMultiline,
|
1874
|
+
contentEditable: isEditable
|
1790
1875
|
};
|
1791
1876
|
};
|
1792
1877
|
|
@@ -1827,183 +1912,9 @@ function mapSlotToTestVariations(slot) {
|
|
1827
1912
|
});
|
1828
1913
|
}
|
1829
1914
|
|
1830
|
-
// src/utils/variables/parseVariableExpression.ts
|
1831
|
-
var escapeCharacter = "\\";
|
1832
|
-
var variablePrefix = "${";
|
1833
|
-
var variableSuffix = "}";
|
1834
|
-
function parseVariableExpression(serialized, onToken) {
|
1835
|
-
let bufferStartIndex = 0;
|
1836
|
-
let bufferEndIndex = 0;
|
1837
|
-
let tokenCount = 0;
|
1838
|
-
const handleToken = (token, type) => {
|
1839
|
-
tokenCount++;
|
1840
|
-
return onToken == null ? void 0 : onToken(token, type);
|
1841
|
-
};
|
1842
|
-
let state = "text";
|
1843
|
-
for (let index = 0; index < serialized.length; index++) {
|
1844
|
-
const char = serialized[index];
|
1845
|
-
if (bufferStartIndex > bufferEndIndex) {
|
1846
|
-
bufferEndIndex = bufferStartIndex;
|
1847
|
-
}
|
1848
|
-
if (char === variablePrefix[0] && serialized[index + 1] === variablePrefix[1]) {
|
1849
|
-
if (serialized[index - 1] === escapeCharacter) {
|
1850
|
-
bufferEndIndex -= escapeCharacter.length;
|
1851
|
-
if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
|
1852
|
-
return tokenCount;
|
1853
|
-
}
|
1854
|
-
bufferStartIndex = index;
|
1855
|
-
bufferEndIndex = index + 1;
|
1856
|
-
continue;
|
1857
|
-
}
|
1858
|
-
state = "variable";
|
1859
|
-
if (bufferEndIndex > bufferStartIndex) {
|
1860
|
-
if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
|
1861
|
-
return tokenCount;
|
1862
|
-
}
|
1863
|
-
bufferStartIndex = bufferEndIndex;
|
1864
|
-
}
|
1865
|
-
index += variablePrefix.length - 1;
|
1866
|
-
bufferStartIndex += variablePrefix.length;
|
1867
|
-
continue;
|
1868
|
-
}
|
1869
|
-
if (char === variableSuffix && state === "variable") {
|
1870
|
-
state = "text";
|
1871
|
-
if (bufferEndIndex > bufferStartIndex) {
|
1872
|
-
if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "variable") === false) {
|
1873
|
-
return tokenCount;
|
1874
|
-
}
|
1875
|
-
bufferStartIndex = bufferEndIndex + variableSuffix.length;
|
1876
|
-
}
|
1877
|
-
continue;
|
1878
|
-
}
|
1879
|
-
bufferEndIndex++;
|
1880
|
-
}
|
1881
|
-
if (bufferEndIndex > bufferStartIndex) {
|
1882
|
-
if (state === "variable") {
|
1883
|
-
state = "text";
|
1884
|
-
bufferStartIndex -= variablePrefix.length;
|
1885
|
-
}
|
1886
|
-
handleToken(serialized.substring(bufferStartIndex), state);
|
1887
|
-
}
|
1888
|
-
return tokenCount;
|
1889
|
-
}
|
1890
|
-
|
1891
|
-
// src/utils/variables/bindVariables.ts
|
1892
|
-
function bindVariables({
|
1893
|
-
variables,
|
1894
|
-
value,
|
1895
|
-
errorPrefix = "Variable",
|
1896
|
-
handleBinding
|
1897
|
-
}) {
|
1898
|
-
let boundCount = 0;
|
1899
|
-
let tokenCount = 0;
|
1900
|
-
const errors = [];
|
1901
|
-
const defaultHandleBinding = (variableName, variables2, errors2) => {
|
1902
|
-
const variableValue = variables2[variableName];
|
1903
|
-
if (variableValue === void 0) {
|
1904
|
-
errors2.push(`${errorPrefix} "${variableName}" is not defined`);
|
1905
|
-
return "";
|
1906
|
-
}
|
1907
|
-
return variableValue;
|
1908
|
-
};
|
1909
|
-
const result = [];
|
1910
|
-
parseVariableExpression(value, (token, tokenType) => {
|
1911
|
-
tokenCount++;
|
1912
|
-
if (tokenType === "text") {
|
1913
|
-
result.push(token);
|
1914
|
-
return;
|
1915
|
-
}
|
1916
|
-
const variableValue = (handleBinding != null ? handleBinding : defaultHandleBinding)(token, variables, errors);
|
1917
|
-
boundCount++;
|
1918
|
-
result.push(variableValue);
|
1919
|
-
});
|
1920
|
-
return {
|
1921
|
-
result: tokenCount === 1 ? result[0] : result.join(""),
|
1922
|
-
boundCount,
|
1923
|
-
errors: errors.length > 0 ? errors : void 0
|
1924
|
-
};
|
1925
|
-
}
|
1926
|
-
|
1927
|
-
// src/utils/variables/bindVariablesToObject.ts
|
1928
|
-
var import_immer = require("immer");
|
1929
|
-
|
1930
|
-
// src/utils/variables/createVariableReference.ts
|
1931
|
-
function createVariableReference(variableName) {
|
1932
|
-
return `\${${variableName}}`;
|
1933
|
-
}
|
1934
|
-
|
1935
|
-
// src/utils/variables/bindVariablesToObject.ts
|
1936
|
-
function bindVariablesToObject(options) {
|
1937
|
-
return bindVariablesToObjectRecursive(options);
|
1938
|
-
}
|
1939
|
-
function bindVariablesToObjectRecursive({
|
1940
|
-
value,
|
1941
|
-
recursivePath,
|
1942
|
-
...bindVariablesOptions
|
1943
|
-
}) {
|
1944
|
-
let boundCount = 0;
|
1945
|
-
const errors = [];
|
1946
|
-
if (typeof value === "string") {
|
1947
|
-
return bindVariables({ ...bindVariablesOptions, value });
|
1948
|
-
}
|
1949
|
-
if (typeof value !== "object" || value === null) {
|
1950
|
-
return { boundCount: 0, result: value };
|
1951
|
-
}
|
1952
|
-
const richTextNodeResult = handleRichTextNodeBinding(value, bindVariablesOptions);
|
1953
|
-
if (richTextNodeResult !== void 0) {
|
1954
|
-
return richTextNodeResult;
|
1955
|
-
}
|
1956
|
-
const result = (0, import_immer.produce)(value, (draft) => {
|
1957
|
-
Object.entries(draft).forEach(([property, oldValue]) => {
|
1958
|
-
const currentObjectPath = recursivePath ? `${recursivePath}.${property}` : property;
|
1959
|
-
if (typeof oldValue === "string") {
|
1960
|
-
const bindResult = bindVariables({ ...bindVariablesOptions, value: oldValue });
|
1961
|
-
if (oldValue !== bindResult.result || bindResult.errors) {
|
1962
|
-
boundCount += bindResult.boundCount;
|
1963
|
-
draft[property] = bindResult.result;
|
1964
|
-
if (bindResult.errors) {
|
1965
|
-
errors.push(...bindResult.errors.map((e) => `${currentObjectPath}: ${e}`));
|
1966
|
-
}
|
1967
|
-
}
|
1968
|
-
return;
|
1969
|
-
}
|
1970
|
-
const childBind = bindVariablesToObjectRecursive({
|
1971
|
-
...bindVariablesOptions,
|
1972
|
-
value: oldValue,
|
1973
|
-
recursivePath: currentObjectPath
|
1974
|
-
});
|
1975
|
-
if (childBind.boundCount || childBind.errors) {
|
1976
|
-
boundCount += childBind.boundCount;
|
1977
|
-
draft[property] = childBind.result;
|
1978
|
-
if (childBind.errors) {
|
1979
|
-
errors.push(...childBind.errors);
|
1980
|
-
}
|
1981
|
-
}
|
1982
|
-
});
|
1983
|
-
});
|
1984
|
-
return { boundCount, result, errors: errors.length > 0 ? errors : void 0 };
|
1985
|
-
}
|
1986
|
-
function handleRichTextNodeBinding(object, options) {
|
1987
|
-
if ("type" in object && object.type === "variable" && "reference" in object && typeof object.reference === "string" && "version" in object && object.version === 1) {
|
1988
|
-
const value = createVariableReference(object.reference);
|
1989
|
-
const bindResult = bindVariables({ ...options, value });
|
1990
|
-
const bindResultAsTextNode = {
|
1991
|
-
detail: 0,
|
1992
|
-
format: 0,
|
1993
|
-
mode: "normal",
|
1994
|
-
style: "",
|
1995
|
-
text: bindResult.result,
|
1996
|
-
type: "text",
|
1997
|
-
version: 1
|
1998
|
-
};
|
1999
|
-
return { ...bindResult, result: bindResultAsTextNode };
|
2000
|
-
}
|
2001
|
-
return void 0;
|
2002
|
-
}
|
2003
|
-
|
2004
1915
|
// src/index.ts
|
2005
|
-
var
|
2006
|
-
var CanvasClientError =
|
1916
|
+
var import_api8 = require("@uniformdev/context/api");
|
1917
|
+
var CanvasClientError = import_api8.ApiClientError;
|
2007
1918
|
// Annotate the CommonJS export names for ESM import in node:
|
2008
1919
|
0 && (module.exports = {
|
2009
1920
|
ATTRIBUTE_COMPONENT_ID,
|
@@ -2060,7 +1971,6 @@ var CanvasClientError = import_api7.ApiClientError;
|
|
2060
1971
|
createEventBus,
|
2061
1972
|
createLimitPolicy,
|
2062
1973
|
createUniformApiEnhancer,
|
2063
|
-
createVariableReference,
|
2064
1974
|
enhance,
|
2065
1975
|
extractLocales,
|
2066
1976
|
generateHash,
|
@@ -2086,7 +1996,6 @@ var CanvasClientError = import_api7.ApiClientError;
|
|
2086
1996
|
mapSlotToPersonalizedVariations,
|
2087
1997
|
mapSlotToTestVariations,
|
2088
1998
|
nullLimitPolicy,
|
2089
|
-
parseVariableExpression,
|
2090
1999
|
subscribeToComposition,
|
2091
2000
|
unstable_CompositionRelationshipClient,
|
2092
2001
|
walkComponentTree
|