akeyless-client-commons 1.1.128 → 1.1.130

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.
@@ -121,6 +121,47 @@ function _instanceof(left, right) {
121
121
  return left instanceof right;
122
122
  }
123
123
  }
124
+ function _getRequireWildcardCache(nodeInterop) {
125
+ if (typeof WeakMap !== "function") return null;
126
+ var cacheBabelInterop = new WeakMap();
127
+ var cacheNodeInterop = new WeakMap();
128
+ return (_getRequireWildcardCache = function(nodeInterop) {
129
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
130
+ })(nodeInterop);
131
+ }
132
+ function _interop_require_wildcard(obj, nodeInterop) {
133
+ if (!nodeInterop && obj && obj.__esModule) {
134
+ return obj;
135
+ }
136
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
137
+ return {
138
+ default: obj
139
+ };
140
+ }
141
+ var cache = _getRequireWildcardCache(nodeInterop);
142
+ if (cache && cache.has(obj)) {
143
+ return cache.get(obj);
144
+ }
145
+ var newObj = {
146
+ __proto__: null
147
+ };
148
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
149
+ for(var key in obj){
150
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
151
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
152
+ if (desc && (desc.get || desc.set)) {
153
+ Object.defineProperty(newObj, key, desc);
154
+ } else {
155
+ newObj[key] = obj[key];
156
+ }
157
+ }
158
+ }
159
+ newObj.default = obj;
160
+ if (cache) {
161
+ cache.set(obj, newObj);
162
+ }
163
+ return newObj;
164
+ }
124
165
  function _iterable_to_array(iter) {
125
166
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
126
167
  }
@@ -750,17 +791,73 @@ function timestamp_to_string(firebaseTimestamp, options) {
750
791
  return import_moment_timezone.default.utc(date).format(format);
751
792
  }
752
793
  }
753
- // src/helpers/firebase.ts
794
+ // src/helpers/global.ts
795
+ var import_akeyless_types_commons = require("akeyless-types-commons");
796
+ var import_axios = __toESM(require("axios"));
797
+ var import_lodash = require("lodash");
754
798
  var import_meta = {};
799
+ var renderOnce = function() {
800
+ return true;
801
+ };
802
+ var propsAreEqual = function(prevProps, nextProps) {
803
+ return (0, import_lodash.isEqual)(prevProps, nextProps);
804
+ };
805
+ var getLocationUrl = function(lng, lat) {
806
+ return "https://www.google.com/maps?q=".concat(lat, ",").concat(lng);
807
+ };
808
+ var isNodeEnv = typeof process !== "undefined" && process.env;
809
+ var _ref = {
810
+ mode: isNodeEnv ? process.env.NEXT_PUBLIC_MODE : import_meta.env.VITE_MODE,
811
+ isLocal: (isNodeEnv ? process.env.NEXT_PUBLIC_IS_LOCAL : import_meta.env.VITE_is_local) === "true"
812
+ }, mode = _ref.mode, isLocal = _ref.isLocal;
813
+ var getFixedNumber = function() {
814
+ var number = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0, fix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 4;
815
+ var sum_value = number % 1 === 0 ? number : number.toFixed(fix).replace(/\.?0+$/, "");
816
+ return String(sum_value);
817
+ };
818
+ var checkConditions = function(document2, conditions) {
819
+ if (!conditions || conditions.length === 0) return true;
820
+ return conditions.every(function(condition) {
821
+ var fieldValue = document2[condition.field_name];
822
+ switch(condition.operator){
823
+ case "==":
824
+ return fieldValue === condition.value;
825
+ case "!=":
826
+ return fieldValue !== condition.value;
827
+ case "<":
828
+ return fieldValue < condition.value;
829
+ case "<=":
830
+ return fieldValue <= condition.value;
831
+ case ">":
832
+ return fieldValue > condition.value;
833
+ case ">=":
834
+ return fieldValue >= condition.value;
835
+ case "in":
836
+ return Array.isArray(condition.value) && condition.value.includes(fieldValue);
837
+ case "not-in":
838
+ return Array.isArray(condition.value) && !condition.value.includes(fieldValue);
839
+ case "array-contains":
840
+ return Array.isArray(fieldValue) && fieldValue.includes(condition.value);
841
+ case "array-contains-any":
842
+ return Array.isArray(fieldValue) && Array.isArray(condition.value) && condition.value.some(function(v) {
843
+ return fieldValue.includes(v);
844
+ });
845
+ default:
846
+ return false;
847
+ }
848
+ });
849
+ };
850
+ // src/helpers/firebase.ts
851
+ var import_meta2 = {};
755
852
  var initApp = function() {
756
853
  var isNodeEnv2 = typeof process !== "undefined" && process.env;
757
854
  var firebaseConfig = {
758
- apiKey: isNodeEnv2 ? process.env.NEXT_PUBLIC_API_KEY : import_meta.env.VITE_API_KEY,
759
- authDomain: isNodeEnv2 ? process.env.NEXT_PUBLIC_AUTH_DOMAIN : import_meta.env.VITE_AUTH_DOMAIN,
760
- projectId: isNodeEnv2 ? process.env.NEXT_PUBLIC_PROJECT_ID : import_meta.env.VITE_PROJECT_ID,
761
- storageBucket: isNodeEnv2 ? process.env.NEXT_PUBLIC_STORAGE_BUCKET : import_meta.env.VITE_STORAGE_BUCKET,
762
- messagingSenderId: isNodeEnv2 ? process.env.NEXT_PUBLIC_MESSAGING_SENDER_ID : import_meta.env.VITE_MESSAGING_SENDER_ID,
763
- appId: isNodeEnv2 ? process.env.NEXT_PUBLIC_APP_ID : import_meta.env.VITE_APP_ID
855
+ apiKey: isNodeEnv2 ? process.env.NEXT_PUBLIC_API_KEY : import_meta2.env.VITE_API_KEY,
856
+ authDomain: isNodeEnv2 ? process.env.NEXT_PUBLIC_AUTH_DOMAIN : import_meta2.env.VITE_AUTH_DOMAIN,
857
+ projectId: isNodeEnv2 ? process.env.NEXT_PUBLIC_PROJECT_ID : import_meta2.env.VITE_PROJECT_ID,
858
+ storageBucket: isNodeEnv2 ? process.env.NEXT_PUBLIC_STORAGE_BUCKET : import_meta2.env.VITE_STORAGE_BUCKET,
859
+ messagingSenderId: isNodeEnv2 ? process.env.NEXT_PUBLIC_MESSAGING_SENDER_ID : import_meta2.env.VITE_MESSAGING_SENDER_ID,
860
+ appId: isNodeEnv2 ? process.env.NEXT_PUBLIC_APP_ID : import_meta2.env.VITE_APP_ID
764
861
  };
765
862
  try {
766
863
  var app2 = (0, import_app.initializeApp)(firebaseConfig);
@@ -769,7 +866,7 @@ var initApp = function() {
769
866
  var db2 = (0, import_firestore2.getFirestore)(app2);
770
867
  var storage2 = (0, import_storage.getStorage)(app2);
771
868
  var googleLoginProvider2 = new import_auth.GoogleAuthProvider();
772
- var recaptchaSiteKey = isNodeEnv2 ? process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY : import_meta.env.VITE_RECAPTCHA_SITE_KEY;
869
+ var recaptchaSiteKey = isNodeEnv2 ? process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY : import_meta2.env.VITE_RECAPTCHA_SITE_KEY;
773
870
  var result = {
774
871
  db: db2,
775
872
  auth: auth2,
@@ -1129,30 +1226,6 @@ var validateUserStatusAndPermissions = function(user, app2) {
1129
1226
  }
1130
1227
  return userPermissions;
1131
1228
  };
1132
- // src/helpers/global.ts
1133
- var import_akeyless_types_commons = require("akeyless-types-commons");
1134
- var import_axios = __toESM(require("axios"));
1135
- var import_lodash = require("lodash");
1136
- var import_meta2 = {};
1137
- var renderOnce = function() {
1138
- return true;
1139
- };
1140
- var propsAreEqual = function(prevProps, nextProps) {
1141
- return (0, import_lodash.isEqual)(prevProps, nextProps);
1142
- };
1143
- var getLocationUrl = function(lng, lat) {
1144
- return "https://www.google.com/maps?q=".concat(lat, ",").concat(lng);
1145
- };
1146
- var isNodeEnv = typeof process !== "undefined" && process.env;
1147
- var _ref = {
1148
- mode: isNodeEnv ? process.env.NEXT_PUBLIC_MODE : import_meta2.env.VITE_MODE,
1149
- isLocal: (isNodeEnv ? process.env.NEXT_PUBLIC_IS_LOCAL : import_meta2.env.VITE_is_local) === "true"
1150
- }, mode = _ref.mode, isLocal = _ref.isLocal;
1151
- var getFixedNumber = function() {
1152
- var number = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0, fix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 4;
1153
- var sum_value = number % 1 === 0 ? number : number.toFixed(fix).replace(/\.?0+$/, "");
1154
- return String(sum_value);
1155
- };
1156
1229
  // src/helpers/forms.ts
1157
1230
  var import_xregexp = __toESM(require("xregexp"));
1158
1231
  var textRegex = (0, import_xregexp.default)(String.raw(_templateObject()), "gu");
@@ -1299,6 +1372,9 @@ var SocketService = /*#__PURE__*/ function() {
1299
1372
  this.disconnectCallbacks = [];
1300
1373
  this.authToken = null;
1301
1374
  this.isDisconnected = true;
1375
+ /// the data-socket keeps one subscription per collection per socket, so a second condition set
1376
+ /// for a collection never reaches it and would silently receive the first one's documents
1377
+ this.activeConditions = /* @__PURE__ */ new Map();
1302
1378
  this.handleDisconnect = function(source, reason) {
1303
1379
  var _this_socket;
1304
1380
  if (_this.isDisconnected) {
@@ -1466,6 +1542,39 @@ var SocketService = /*#__PURE__*/ function() {
1466
1542
  }
1467
1543
  }
1468
1544
  },
1545
+ {
1546
+ key: "registerConditions",
1547
+ value: function registerConditions(collectionName) {
1548
+ var conditions = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
1549
+ var signature = JSON.stringify(conditions);
1550
+ var active = this.activeConditions.get(collectionName);
1551
+ if (!active) {
1552
+ this.activeConditions.set(collectionName, {
1553
+ signature: signature,
1554
+ conditions: conditions,
1555
+ count: 1
1556
+ });
1557
+ return;
1558
+ }
1559
+ active.count++;
1560
+ if (active.signature !== signature) {
1561
+ console.error('[socket] "'.concat(collectionName, '" is already subscribed with different conditions, and a collection supports one condition set at a time. The active set stays in effect, so this subscription receives its documents instead of its own. active: ').concat(active.signature, " requested: ").concat(signature));
1562
+ }
1563
+ }
1564
+ },
1565
+ {
1566
+ key: "releaseConditions",
1567
+ value: function releaseConditions(collectionName) {
1568
+ var active = this.activeConditions.get(collectionName);
1569
+ if (!active) {
1570
+ return;
1571
+ }
1572
+ active.count--;
1573
+ if (active.count <= 0) {
1574
+ this.activeConditions.delete(collectionName);
1575
+ }
1576
+ }
1577
+ },
1469
1578
  {
1470
1579
  key: "disconnectSocket",
1471
1580
  value: function disconnectSocket() {
@@ -1477,6 +1586,8 @@ var SocketService = /*#__PURE__*/ function() {
1477
1586
  },
1478
1587
  {
1479
1588
  /// subscribe to collections
1589
+ /// conditions are derived from OnSnapshotConfig.conditions, never passed in, so a caller cannot
1590
+ /// set them in a second place and have them silently overwritten
1480
1591
  key: "subscribeToCollections",
1481
1592
  value: function subscribeToCollections(config, options) {
1482
1593
  var _this = this;
@@ -1489,26 +1600,77 @@ var SocketService = /*#__PURE__*/ function() {
1489
1600
  });
1490
1601
  var eventHandlers = [];
1491
1602
  config.forEach(function(configuration) {
1492
- var collectionName = configuration.collectionName, onAdd = configuration.onAdd, onFirstTime = configuration.onFirstTime, onModify = configuration.onModify, onRemove = configuration.onRemove, extraParsers = configuration.extraParsers;
1603
+ var collectionName = configuration.collectionName, conditions = configuration.conditions;
1604
+ var parsers = [
1605
+ configuration
1606
+ ].concat(_to_consumable_array(configuration.extraParsers || []));
1607
+ var matchedIds = /* @__PURE__ */ new Set();
1493
1608
  var attach = function(eventName, handler) {
1494
- if (!handler) return;
1495
- _this.socket.off(eventName, handler);
1496
1609
  _this.socket.on(eventName, handler);
1497
1610
  eventHandlers.push({
1498
1611
  eventName: eventName,
1499
1612
  handler: handler
1500
1613
  });
1501
1614
  };
1502
- attach("initial:".concat(collectionName), onFirstTime);
1503
- attach("add:".concat(collectionName), onAdd);
1504
- attach("update:".concat(collectionName), onModify);
1505
- attach("delete:".concat(collectionName), onRemove);
1506
- extraParsers === null || extraParsers === void 0 ? void 0 : extraParsers.forEach(function(parsers) {
1507
- var extraOnAdd = parsers.onAdd, extraOnFirstTime = parsers.onFirstTime, extraOnModify = parsers.onModify, extraOnRemove = parsers.onRemove;
1508
- attach("initial:".concat(collectionName), extraOnFirstTime);
1509
- attach("add:".concat(collectionName), extraOnAdd);
1510
- attach("update:".concat(collectionName), extraOnModify);
1511
- attach("delete:".concat(collectionName), extraOnRemove);
1615
+ var toDocs = function(payload) {
1616
+ return Array.isArray(payload) ? payload : payload ? [
1617
+ payload
1618
+ ] : [];
1619
+ };
1620
+ var run = function(op, docs) {
1621
+ return parsers.forEach(function(parser) {
1622
+ var _parser_op;
1623
+ return (_parser_op = parser[op]) === null || _parser_op === void 0 ? void 0 : _parser_op.call(parser, docs, configuration);
1624
+ });
1625
+ };
1626
+ var runIfAny = function(op, docs) {
1627
+ if (docs.length) {
1628
+ run(op, docs);
1629
+ }
1630
+ };
1631
+ attach("initial:".concat(collectionName), function(payload) {
1632
+ var docs = toDocs(payload).filter(function(doc2) {
1633
+ return checkConditions(doc2, conditions);
1634
+ });
1635
+ matchedIds.clear();
1636
+ docs.forEach(function(doc2) {
1637
+ return matchedIds.add(doc2.id);
1638
+ });
1639
+ run("onFirstTime", docs);
1640
+ });
1641
+ var handleUpsert = function(payload, defaultOp) {
1642
+ var added = [];
1643
+ var modified = [];
1644
+ var removed = [];
1645
+ toDocs(payload).forEach(function(doc2) {
1646
+ if (!(conditions === null || conditions === void 0 ? void 0 : conditions.length)) {
1647
+ (defaultOp === "onAdd" ? added : modified).push(doc2);
1648
+ return;
1649
+ }
1650
+ var wasMatching = matchedIds.has(doc2.id);
1651
+ if (checkConditions(doc2, conditions)) {
1652
+ matchedIds.add(doc2.id);
1653
+ (wasMatching ? modified : added).push(doc2);
1654
+ } else if (wasMatching) {
1655
+ matchedIds.delete(doc2.id);
1656
+ removed.push(doc2);
1657
+ }
1658
+ });
1659
+ runIfAny("onAdd", added);
1660
+ runIfAny("onModify", modified);
1661
+ runIfAny("onRemove", removed);
1662
+ };
1663
+ attach("add:".concat(collectionName), function(payload) {
1664
+ return handleUpsert(payload, "onAdd");
1665
+ });
1666
+ attach("update:".concat(collectionName), function(payload) {
1667
+ return handleUpsert(payload, "onModify");
1668
+ });
1669
+ attach("delete:".concat(collectionName), function(payload) {
1670
+ var docs = toDocs(payload).filter(function(doc2) {
1671
+ return !(conditions === null || conditions === void 0 ? void 0 : conditions.length) || matchedIds.delete(doc2.id);
1672
+ });
1673
+ runIfAny("onRemove", docs);
1512
1674
  });
1513
1675
  });
1514
1676
  var acknowledge = function(callback) {
@@ -1518,12 +1680,28 @@ var SocketService = /*#__PURE__*/ function() {
1518
1680
  console.error("Failed to subscribe to ".concat(config.join(", "), ": ").concat(callback.message));
1519
1681
  }
1520
1682
  };
1521
- if (options) {
1522
- s.emit("subscribe_options", options);
1683
+ config.forEach(function(c) {
1684
+ return _this.registerConditions(c.collectionName, c.conditions);
1685
+ });
1686
+ var conditionsByCollection = config.reduce(function(acc, c) {
1687
+ var active = _this.activeConditions.get(c.collectionName);
1688
+ if (active === null || active === void 0 ? void 0 : active.conditions.length) {
1689
+ acc[c.collectionName] = active.conditions;
1690
+ }
1691
+ return acc;
1692
+ }, {});
1693
+ var subscribeOptions = Object.keys(conditionsByCollection).length ? _object_spread_props(_object_spread({}, options), {
1694
+ conditions: conditionsByCollection
1695
+ }) : options;
1696
+ if (subscribeOptions) {
1697
+ s.emit("subscribe_options", subscribeOptions);
1523
1698
  }
1524
1699
  s.emit("subscribe_collections", collectionsNames, acknowledge);
1525
1700
  return function() {
1526
1701
  console.log("Cleaning up subscriptions for: ".concat(collectionsNames.join(", ")));
1702
+ collectionsNames.forEach(function(name) {
1703
+ return _this.releaseConditions(name);
1704
+ });
1527
1705
  s.emit("unsubscribe_collections", collectionsNames);
1528
1706
  eventHandlers.forEach(function(eh) {
1529
1707
  s.off(eh.eventName, eh.handler);
@@ -5393,16 +5571,30 @@ function SearchSelect(param) {
5393
5571
  });
5394
5572
  }
5395
5573
  // src/helpers/excel.tsx
5396
- var import_exceljs = __toESM(require("exceljs"));
5397
- var import_file_saver = require("file-saver");
5398
5574
  var exportToExcel = /*#__PURE__*/ function() {
5399
5575
  var _ref = _async_to_generator(function(param) {
5400
- var columns, data, headline, fileName, cellStyle, direction, workbook, worksheet, titleRow, buffer, blob;
5576
+ var columns, data, headline, fileName, cellStyle, direction, _ref, _ref_, ExcelJS, saveAs, workbook, worksheet, titleRow, buffer, blob;
5401
5577
  return _ts_generator(this, function(_state) {
5402
5578
  switch(_state.label){
5403
5579
  case 0:
5404
5580
  columns = param.columns, data = param.data, headline = param.headline, fileName = param.fileName, cellStyle = param.cellStyle, direction = param.direction;
5405
- workbook = new import_exceljs.default.Workbook();
5581
+ return [
5582
+ 4,
5583
+ Promise.all([
5584
+ Promise.resolve().then(function() {
5585
+ return /*#__PURE__*/ _interop_require_wildcard(require("exceljs"));
5586
+ }),
5587
+ Promise.resolve().then(function() {
5588
+ return /*#__PURE__*/ _interop_require_wildcard(require("file-saver"));
5589
+ })
5590
+ ])
5591
+ ];
5592
+ case 1:
5593
+ _ref = _sliced_to_array.apply(void 0, [
5594
+ _state.sent(),
5595
+ 2
5596
+ ]), _ref_ = _ref[0], ExcelJS = _ref_.default, saveAs = _ref[1].saveAs;
5597
+ workbook = new ExcelJS.Workbook();
5406
5598
  worksheet = workbook.addWorksheet("Report");
5407
5599
  worksheet.views = [
5408
5600
  {
@@ -5453,14 +5645,14 @@ var exportToExcel = /*#__PURE__*/ function() {
5453
5645
  4,
5454
5646
  workbook.xlsx.writeBuffer()
5455
5647
  ];
5456
- case 1:
5648
+ case 2:
5457
5649
  buffer = _state.sent();
5458
5650
  blob = new Blob([
5459
5651
  buffer
5460
5652
  ], {
5461
5653
  type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
5462
5654
  });
5463
- (0, import_file_saver.saveAs)(blob, fileName || "export.xlsx");
5655
+ saveAs(blob, fileName || "export.xlsx");
5464
5656
  return [
5465
5657
  2
5466
5658
  ];