@uniformdev/canvas 18.18.1-alpha.12 → 18.19.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.mjs CHANGED
@@ -16,6 +16,10 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
19
23
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
20
24
  mod
21
25
  ));
@@ -78,7 +82,7 @@ var require_retry_operation = __commonJS({
78
82
  if (!err) {
79
83
  return false;
80
84
  }
81
- var currentTime = new Date().getTime();
85
+ var currentTime = (/* @__PURE__ */ new Date()).getTime();
82
86
  if (err && currentTime - this._operationStart >= this._maxRetryTime) {
83
87
  this._errors.push(err);
84
88
  this._errors.unshift(new Error("RetryOperation timeout occurred"));
@@ -128,7 +132,7 @@ var require_retry_operation = __commonJS({
128
132
  self._operationTimeoutCb();
129
133
  }, self._operationTimeout);
130
134
  }
131
- this._operationStart = new Date().getTime();
135
+ this._operationStart = (/* @__PURE__ */ new Date()).getTime();
132
136
  this._fn(this._attempts);
133
137
  };
134
138
  RetryOperation.prototype.try = function(fn) {
@@ -268,10 +272,15 @@ import { ApiClient } from "@uniformdev/context/api";
268
272
  var import_retry = __toESM(require_retry2(), 1);
269
273
  var networkErrorMsgs = /* @__PURE__ */ new Set([
270
274
  "Failed to fetch",
275
+ // Chrome
271
276
  "NetworkError when attempting to fetch resource.",
277
+ // Firefox
272
278
  "The Internet connection appears to be offline.",
279
+ // Safari
273
280
  "Network request failed",
281
+ // `cross-fetch`
274
282
  "fetch failed"
283
+ // Undici (Node.js)
275
284
  ]);
276
285
  var AbortError = class extends Error {
277
286
  constructor(message) {
@@ -452,6 +461,7 @@ var CanvasClient = class extends ApiClient {
452
461
  super(options);
453
462
  this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
454
463
  }
464
+ /** Fetches lists of Canvas compositions, optionally by type */
455
465
  async getCompositionList(options) {
456
466
  const { projectId } = this.options;
457
467
  const fetchUri = this.createUrl(CANVAS_URL, { ...options, projectId });
@@ -460,12 +470,14 @@ var CanvasClient = class extends ApiClient {
460
470
  getCompositionByNodePath(options) {
461
471
  return this.getOneComposition(options);
462
472
  }
473
+ /** @deprecated use getCompositionByNodePath instead */
463
474
  unstable_getCompositionByNodePath(options) {
464
475
  return this.getOneComposition(options);
465
476
  }
466
477
  getCompositionByNodeId(options) {
467
478
  return this.getOneComposition(options);
468
479
  }
480
+ /** @deprecated Use getCompositionByNodeId instead */
469
481
  unstable_getCompositionByNodeId(options) {
470
482
  return this.getOneComposition(options);
471
483
  }
@@ -494,6 +506,7 @@ var CanvasClient = class extends ApiClient {
494
506
  const edgeUrl = this.createUrl("/api/v1/composition", edgeParams, this.edgeApiHost);
495
507
  return this.apiClient(edgeUrl);
496
508
  }
509
+ /** Updates or creates a Canvas component definition */
497
510
  async updateComposition(body) {
498
511
  const fetchUri = this.createUrl(CANVAS_URL);
499
512
  await this.apiClient(fetchUri, {
@@ -502,6 +515,7 @@ var CanvasClient = class extends ApiClient {
502
515
  expectNoContent: true
503
516
  });
504
517
  }
518
+ /** Deletes a Canvas component definition */
505
519
  async removeComposition(body) {
506
520
  const fetchUri = this.createUrl(CANVAS_URL);
507
521
  const { projectId } = this.options;
@@ -511,11 +525,13 @@ var CanvasClient = class extends ApiClient {
511
525
  expectNoContent: true
512
526
  });
513
527
  }
528
+ /** Fetches all Canvas component definitions */
514
529
  async getComponentDefinitions(options) {
515
530
  const { projectId } = this.options;
516
531
  const fetchUri = this.createUrl("/api/v1/canvas-definitions", { ...options, projectId });
517
532
  return await this.apiClient(fetchUri);
518
533
  }
534
+ /** Updates or creates a Canvas component definition */
519
535
  async updateComponentDefinition(body) {
520
536
  const fetchUri = this.createUrl("/api/v1/canvas-definitions");
521
537
  await this.apiClient(fetchUri, {
@@ -524,6 +540,7 @@ var CanvasClient = class extends ApiClient {
524
540
  expectNoContent: true
525
541
  });
526
542
  }
543
+ /** Deletes a Canvas component definition */
527
544
  async removeComponentDefinition(body) {
528
545
  const fetchUri = this.createUrl("/api/v1/canvas-definitions");
529
546
  await this.apiClient(fetchUri, {
@@ -547,16 +564,19 @@ var DataSourceClient = class extends ApiClient2 {
547
564
  constructor(options) {
548
565
  super(options);
549
566
  }
567
+ /** Fetches all DataSources for a project */
550
568
  async get(options) {
551
569
  const { projectId } = this.options;
552
570
  const fetchUri = this.createUrl(dataSourceUrl, { ...options, projectId });
553
571
  return await this.apiClient(fetchUri);
554
572
  }
573
+ /** Fetches all DataSources for a project */
555
574
  async getList(options) {
556
575
  const { projectId } = this.options;
557
576
  const fetchUri = this.createUrl(dataSourcesUrl, { ...options, projectId });
558
577
  return await this.apiClient(fetchUri);
559
578
  }
579
+ /** Updates or creates (based on id) a DataSource */
560
580
  async upsert(body) {
561
581
  const fetchUri = this.createUrl(dataSourceUrl);
562
582
  await this.apiClient(fetchUri, {
@@ -565,6 +585,7 @@ var DataSourceClient = class extends ApiClient2 {
565
585
  expectNoContent: true
566
586
  });
567
587
  }
588
+ /** Deletes a DataSource */
568
589
  async remove(body) {
569
590
  const fetchUri = this.createUrl(dataSourceUrl);
570
591
  await this.apiClient(fetchUri, {
@@ -582,11 +603,13 @@ var _DataTypeClient = class extends ApiClient3 {
582
603
  constructor(options) {
583
604
  super(options);
584
605
  }
606
+ /** Fetches all DataTypes for a project */
585
607
  async get(options) {
586
608
  const { projectId } = this.options;
587
609
  const fetchUri = this.createUrl(__privateGet(_DataTypeClient, _url), { ...options, projectId });
588
610
  return await this.apiClient(fetchUri);
589
611
  }
612
+ /** Updates or creates (based on id) a DataType */
590
613
  async upsert(body) {
591
614
  const fetchUri = this.createUrl(__privateGet(_DataTypeClient, _url));
592
615
  await this.apiClient(fetchUri, {
@@ -595,6 +618,7 @@ var _DataTypeClient = class extends ApiClient3 {
595
618
  expectNoContent: true
596
619
  });
597
620
  }
621
+ /** Deletes a DataType */
598
622
  async remove(body) {
599
623
  const fetchUri = this.createUrl(__privateGet(_DataTypeClient, _url));
600
624
  await this.apiClient(fetchUri, {
@@ -616,14 +640,17 @@ var BatchEntry = class {
616
640
  this.args = args;
617
641
  this._isCompleted = false;
618
642
  }
643
+ /** Mark the batch entry as successfully completed. */
619
644
  resolve(result) {
620
645
  this._resolve(result);
621
646
  this._isCompleted = true;
622
647
  }
648
+ /** Mark the batch entry as failed. */
623
649
  reject(reason) {
624
650
  this._reject(reason);
625
651
  this._isCompleted = true;
626
652
  }
653
+ /** @return Whether the batch entry has been completed (resolved or rejected). */
627
654
  get isCompleted() {
628
655
  return this._isCompleted;
629
656
  }
@@ -956,10 +983,12 @@ var ChildEnhancerBuilder = class {
956
983
  this._paramMatches = Array();
957
984
  this._dataMatches = /* @__PURE__ */ new Map();
958
985
  }
986
+ /** Targets an enhancer to modify the value of any parameter */
959
987
  parameter(enhancer) {
960
988
  this._paramMatches.push({ enhancer: this._resolveParameterEnhancer(enhancer) });
961
989
  return this;
962
990
  }
991
+ /** Targets an enhancer to modify the value of any parameter with a specific name */
963
992
  parameterName(name, enhancer) {
964
993
  const names = Array.isArray(name) ? name : [name];
965
994
  names.forEach(
@@ -967,6 +996,7 @@ var ChildEnhancerBuilder = class {
967
996
  );
968
997
  return this;
969
998
  }
999
+ /** Targets an enhancer to modify the value of any parameter with a specific type */
970
1000
  parameterType(type, enhancer) {
971
1001
  const types = Array.isArray(type) ? type : [type];
972
1002
  types.forEach(
@@ -974,6 +1004,10 @@ var ChildEnhancerBuilder = class {
974
1004
  );
975
1005
  return this;
976
1006
  }
1007
+ /**
1008
+ * Targets an enhancer to set a specific object key on the component's `data` property.
1009
+ * Note: an exception will be thrown if the same key is registered more than once.
1010
+ */
977
1011
  data(name, enhancer) {
978
1012
  if (this._dataMatches.has(name)) {
979
1013
  throw new Error(`${name} enhancer data key has been used more than once. This will cause data loss.`);
@@ -981,12 +1015,20 @@ var ChildEnhancerBuilder = class {
981
1015
  this._dataMatches.set(name, typeof enhancer === "function" ? { enhanceOne: enhancer } : enhancer);
982
1016
  return this;
983
1017
  }
1018
+ /**
1019
+ * Resolves the parameter enhancer for a given parameter, if one exists.
1020
+ * The first matching enhancer by registration order is returned, if more than one could match.
1021
+ */
984
1022
  resolveParameterEnhancer(parameterName, parameter) {
985
1023
  var _a;
986
1024
  return (_a = this._paramMatches.find(
987
1025
  (m) => m.name && m.name === parameterName || m.type && m.type === parameter.type || !m.type && !m.name
988
1026
  )) == null ? void 0 : _a.enhancer;
989
1027
  }
1028
+ /**
1029
+ * Resolves component enhancer(s) for a given component.
1030
+ * Returns a Map where the key is the name of the data property and the value is the enhancer.
1031
+ */
990
1032
  resolveComponentEnhancers() {
991
1033
  return this._dataMatches;
992
1034
  }
@@ -1003,22 +1045,33 @@ var EnhancerBuilder = class {
1003
1045
  this._componentIndex = {};
1004
1046
  this._rootBuilder = new ChildEnhancerBuilder();
1005
1047
  }
1048
+ /** Targets an enhancer to modify the value of any parameter */
1006
1049
  parameter(enhancer) {
1007
1050
  this._rootBuilder.parameter(enhancer);
1008
1051
  return this;
1009
1052
  }
1053
+ /** Targets an enhancer to modify the value of any parameter with a specific name */
1010
1054
  parameterName(name, enhancer) {
1011
1055
  this._rootBuilder.parameterName(name, enhancer);
1012
1056
  return this;
1013
1057
  }
1058
+ /** Targets an enhancer to modify the value of any parameter with a specific type */
1014
1059
  parameterType(type, enhancer) {
1015
1060
  this._rootBuilder.parameterType(type, enhancer);
1016
1061
  return this;
1017
1062
  }
1063
+ /**
1064
+ * Targets an enhancer to set a specific object key on the component's `data` property.
1065
+ * Note: an exception will be thrown if the same key is registered more than once.
1066
+ */
1018
1067
  data(name, enhancer) {
1019
1068
  this._rootBuilder.data(name, enhancer);
1020
1069
  return this;
1021
1070
  }
1071
+ /**
1072
+ * Targets a subset of enhancers at a specific component type.
1073
+ * Global enhancers will still be run if no matching enhancer is registered for this component's properties.
1074
+ */
1022
1075
  component(name, builder) {
1023
1076
  const names = Array.isArray(name) ? name : [name];
1024
1077
  names.forEach((name2) => {
@@ -1027,6 +1080,10 @@ var EnhancerBuilder = class {
1027
1080
  });
1028
1081
  return this;
1029
1082
  }
1083
+ /**
1084
+ * Resolves the parameter enhancer for a given parameter, if one exists.
1085
+ * The first matching enhancer by registration order is returned, if more than one could match.
1086
+ */
1030
1087
  resolveParameterEnhancer(component, parameterName, parameter) {
1031
1088
  const eb = this._componentIndex[component.type];
1032
1089
  if (eb) {
@@ -1037,6 +1094,10 @@ var EnhancerBuilder = class {
1037
1094
  }
1038
1095
  return this._rootBuilder.resolveParameterEnhancer(parameterName, parameter);
1039
1096
  }
1097
+ /**
1098
+ * Resolves component enhancer(s) for a given component.
1099
+ * Returns a Map where the key is the name of the data property and the value is the enhancer.
1100
+ */
1040
1101
  resolveComponentEnhancers(component) {
1041
1102
  let componentEnhancers = this._rootBuilder.resolveComponentEnhancers();
1042
1103
  const eb = this._componentIndex[component.type];
@@ -1127,9 +1188,11 @@ var UniqueBatchEntries = class {
1127
1188
  return acc;
1128
1189
  }, {});
1129
1190
  }
1191
+ /** Resolves all entries in a group key with the same result value. */
1130
1192
  resolveKey(key, result) {
1131
1193
  this.groups[key].forEach((task) => task.resolve(result));
1132
1194
  }
1195
+ /** Resolves all remaining entries that have not been otherwise resolved with a specific value */
1133
1196
  resolveRemaining(value) {
1134
1197
  Object.keys(this.groups).forEach((key) => {
1135
1198
  this.groups[key].forEach((task) => {
@@ -1302,7 +1365,7 @@ async function loadPusher() {
1302
1365
  resolve(window.Pusher);
1303
1366
  }
1304
1367
  reject(
1305
- `Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${PUSHER_SRC}"><\/script> manually.`
1368
+ `Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${PUSHER_SRC}"></script> manually.`
1306
1369
  );
1307
1370
  }, 5e3);
1308
1371
  const pusher = document.createElement("script");
@@ -1419,6 +1482,7 @@ function mapSlotToTestVariations(slot) {
1419
1482
  return {
1420
1483
  ...v,
1421
1484
  id
1485
+ //testDistribution: contextTag?.testDistribution,
1422
1486
  };
1423
1487
  });
1424
1488
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas",
3
- "version": "18.18.1-alpha.12+e9f4d7eda",
3
+ "version": "18.19.1-alpha.7+b4918b2f5",
4
4
  "description": "Common functionality and types for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -39,7 +39,8 @@
39
39
  "test": "jest --maxWorkers=1",
40
40
  "lint": "eslint \"src/**/*.{js,ts,tsx}\"",
41
41
  "format": "prettier --write \"src/**/*.{js,ts,tsx}\"",
42
- "update-openapi": "tsx ./scripts/update-openapi.cts"
42
+ "update-openapi": "tsx ./scripts/update-openapi.cts",
43
+ "document": "api-extractor run --local"
43
44
  },
44
45
  "devDependencies": {
45
46
  "@types/retry": "0.12.1",
@@ -48,7 +49,7 @@
48
49
  "pusher-js": "8.0.1"
49
50
  },
50
51
  "dependencies": {
51
- "@uniformdev/context": "18.18.1-alpha.12+e9f4d7eda"
52
+ "@uniformdev/context": "18.19.1-alpha.7+b4918b2f5"
52
53
  },
53
54
  "files": [
54
55
  "/dist"
@@ -56,5 +57,5 @@
56
57
  "publishConfig": {
57
58
  "access": "public"
58
59
  },
59
- "gitHead": "e9f4d7eda7b1b425205d0be4ec736ebd5dbaed4d"
60
+ "gitHead": "b4918b2f547ebb0b889528bbbacbc930cbb66694"
60
61
  }