akeyless-client-commons 1.1.98 → 1.1.100

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.
@@ -476,6 +476,99 @@ var snapshot = function(config, snapshotsFirstTime, settings) {
476
476
  unsubscribe: unsubscribe
477
477
  };
478
478
  };
479
+ var snapshotDocument = function(config, snapshotsFirstTime) {
480
+ var resolvePromise;
481
+ var isResolved = false;
482
+ var promise = new Promise(function(resolve) {
483
+ console.log("==> Document in ".concat(config.collectionName, " subscribed."));
484
+ resolvePromise = function() {
485
+ if (!isResolved) {
486
+ isResolved = true;
487
+ resolve();
488
+ }
489
+ };
490
+ });
491
+ var documentRef = doc(db, config.collectionName, config.documentId);
492
+ var unsubscribe = onSnapshot(documentRef, function(docSnapshot) {
493
+ if (!snapshotsFirstTime.includes(config.collectionName)) {
494
+ snapshotsFirstTime.push(config.collectionName);
495
+ if (docSnapshot.exists()) {
496
+ var document2 = simpleExtractData(docSnapshot);
497
+ if (checkConditions(document2, config.conditions)) {
498
+ var _config_onFirstTime, _config_extraParsers;
499
+ (_config_onFirstTime = config.onFirstTime) === null || _config_onFirstTime === void 0 ? void 0 : _config_onFirstTime.call(config, [
500
+ document2
501
+ ], config);
502
+ (_config_extraParsers = config.extraParsers) === null || _config_extraParsers === void 0 ? void 0 : _config_extraParsers.forEach(function(extraParser) {
503
+ var _extraParser_onFirstTime;
504
+ (_extraParser_onFirstTime = extraParser.onFirstTime) === null || _extraParser_onFirstTime === void 0 ? void 0 : _extraParser_onFirstTime.call(extraParser, [
505
+ document2
506
+ ], config);
507
+ });
508
+ } else {
509
+ console.warn("Document in ".concat(config.collectionName, " does not meet conditions."));
510
+ }
511
+ } else {
512
+ console.warn("Document not found in ".concat(config.collectionName, "."));
513
+ }
514
+ resolvePromise();
515
+ } else {
516
+ if (docSnapshot.exists()) {
517
+ var document21 = simpleExtractData(docSnapshot);
518
+ if (checkConditions(document21, config.conditions)) {
519
+ var _config_onModify, _config_extraParsers1;
520
+ (_config_onModify = config.onModify) === null || _config_onModify === void 0 ? void 0 : _config_onModify.call(config, [
521
+ document21
522
+ ], config);
523
+ (_config_extraParsers1 = config.extraParsers) === null || _config_extraParsers1 === void 0 ? void 0 : _config_extraParsers1.forEach(function(extraParser) {
524
+ var _extraParser_onModify;
525
+ (_extraParser_onModify = extraParser.onModify) === null || _extraParser_onModify === void 0 ? void 0 : _extraParser_onModify.call(extraParser, [
526
+ document21
527
+ ], config);
528
+ });
529
+ }
530
+ } else {
531
+ var _config_onRemove, _config_extraParsers2;
532
+ (_config_onRemove = config.onRemove) === null || _config_onRemove === void 0 ? void 0 : _config_onRemove.call(config, [], config);
533
+ (_config_extraParsers2 = config.extraParsers) === null || _config_extraParsers2 === void 0 ? void 0 : _config_extraParsers2.forEach(function(extraParser) {
534
+ var _extraParser_onRemove;
535
+ (_extraParser_onRemove = extraParser.onRemove) === null || _extraParser_onRemove === void 0 ? void 0 : _extraParser_onRemove.call(extraParser, [], config);
536
+ });
537
+ }
538
+ }
539
+ }, function(error) {
540
+ console.error("Error listening to document in ".concat(config.collectionName, ":"), error);
541
+ resolvePromise();
542
+ });
543
+ return {
544
+ promise: promise,
545
+ unsubscribe: unsubscribe
546
+ };
547
+ };
548
+ var checkConditions = function(document2, conditions) {
549
+ if (!conditions || conditions.length === 0) return true;
550
+ return conditions.every(function(condition) {
551
+ var fieldValue = document2[condition.field_name];
552
+ switch(condition.operator){
553
+ case "==":
554
+ return fieldValue === condition.value;
555
+ case "!=":
556
+ return fieldValue !== condition.value;
557
+ case "<":
558
+ return fieldValue < condition.value;
559
+ case "<=":
560
+ return fieldValue <= condition.value;
561
+ case ">":
562
+ return fieldValue > condition.value;
563
+ case ">=":
564
+ return fieldValue >= condition.value;
565
+ case "array-contains":
566
+ return Array.isArray(fieldValue) && fieldValue.includes(condition.value);
567
+ default:
568
+ return false;
569
+ }
570
+ });
571
+ };
479
572
  // src/helpers/global.ts
480
573
  import { CountryOptions, LanguageOptions } from "akeyless-types-commons";
481
574
  import axios from "axios";
@@ -1207,7 +1300,7 @@ var useWebWorker = function(fn, options) {
1207
1300
  // src/hooks/snapshots/index.ts
1208
1301
  import { useCallback as useCallback3, useEffect as useEffect4, useMemo as useMemo3, useRef as useRef4, useState as useState2 } from "react";
1209
1302
  // src/hooks/snapshots/snapshotWorker.ts
1210
- var wrapConfigsWithWorker = function(cfgs, runProcessor, options) {
1303
+ var createRecentEventsDedupe = function(options) {
1211
1304
  var recentEvents = /* @__PURE__ */ new Map();
1212
1305
  var _options_eventTtlMs;
1213
1306
  var EVENT_TTL_MS = (_options_eventTtlMs = options === null || options === void 0 ? void 0 : options.eventTtlMs) !== null && _options_eventTtlMs !== void 0 ? _options_eventTtlMs : 1500;
@@ -1216,16 +1309,6 @@ var wrapConfigsWithWorker = function(cfgs, runProcessor, options) {
1216
1309
  var now = function() {
1217
1310
  return Date.now();
1218
1311
  };
1219
- var makeKey = function(op, docs, collectionName) {
1220
- try {
1221
- var ids = (docs || []).map(function(d) {
1222
- return d === null || d === void 0 ? void 0 : d.id;
1223
- }).filter(Boolean).sort().join(",");
1224
- return "".concat(collectionName || "unknown", ":").concat(op, ":").concat(ids);
1225
- } catch (e) {
1226
- return "".concat(collectionName || "unknown", ":").concat(op, ":*");
1227
- }
1228
- };
1229
1312
  var shouldProcess = function(key) {
1230
1313
  var ts = recentEvents.get(key);
1231
1314
  if (ts && now() - ts < EVENT_TTL_MS) {
@@ -1257,6 +1340,22 @@ var wrapConfigsWithWorker = function(cfgs, runProcessor, options) {
1257
1340
  recentEvents.set(key, now());
1258
1341
  return true;
1259
1342
  };
1343
+ return {
1344
+ shouldProcess: shouldProcess
1345
+ };
1346
+ };
1347
+ var wrapConfigsWithWorker = function(cfgs, runProcessor, options) {
1348
+ var shouldProcess = createRecentEventsDedupe(options).shouldProcess;
1349
+ var makeKey = function(op, docs, collectionName) {
1350
+ try {
1351
+ var ids = (docs || []).map(function(d) {
1352
+ return d === null || d === void 0 ? void 0 : d.id;
1353
+ }).filter(Boolean).sort().join(",");
1354
+ return "".concat(collectionName || "unknown", ":").concat(op, ":").concat(ids);
1355
+ } catch (e) {
1356
+ return "".concat(collectionName || "unknown", ":").concat(op, ":*");
1357
+ }
1358
+ };
1260
1359
  var wrapCb = function(cb, op, run) {
1261
1360
  if (!cb) return void 0;
1262
1361
  var handlerId = Math.random().toString(36).slice(2);
@@ -1332,6 +1431,91 @@ var wrapConfigsWithWorker = function(cfgs, runProcessor, options) {
1332
1431
  return wrapped;
1333
1432
  });
1334
1433
  };
1434
+ var wrapDocumentConfigsWithWorker = function(cfgs, runProcessor, options) {
1435
+ var shouldProcess = createRecentEventsDedupe(options).shouldProcess;
1436
+ var makeKey = function(op, docs, collectionName, documentId) {
1437
+ try {
1438
+ var ids = (docs || []).map(function(d) {
1439
+ return d === null || d === void 0 ? void 0 : d.id;
1440
+ }).filter(Boolean).sort().join(",");
1441
+ return "".concat(collectionName || "unknown", "/").concat(documentId || "unknown", ":").concat(op, ":").concat(ids);
1442
+ } catch (e) {
1443
+ return "".concat(collectionName || "unknown", "/").concat(documentId || "unknown", ":").concat(op, ":*");
1444
+ }
1445
+ };
1446
+ var wrapCb = function(cb, op) {
1447
+ if (!cb) return void 0;
1448
+ var handlerId = Math.random().toString(36).slice(2);
1449
+ return /*#__PURE__*/ function() {
1450
+ var _ref = _async_to_generator(function(docs, config) {
1451
+ var key, perHandlerKey, safeDocs, _ref, processed, e;
1452
+ return _ts_generator(this, function(_state) {
1453
+ switch(_state.label){
1454
+ case 0:
1455
+ _state.trys.push([
1456
+ 0,
1457
+ 2,
1458
+ ,
1459
+ 3
1460
+ ]);
1461
+ key = makeKey(op, docs, config === null || config === void 0 ? void 0 : config.collectionName, config === null || config === void 0 ? void 0 : config.documentId);
1462
+ perHandlerKey = "".concat(handlerId, ":").concat(key);
1463
+ if (!shouldProcess(perHandlerKey)) {
1464
+ return [
1465
+ 2
1466
+ ];
1467
+ }
1468
+ safeDocs = (options === null || options === void 0 ? void 0 : options.jsonClone) === false ? docs : JSON.parse(JSON.stringify(docs));
1469
+ return [
1470
+ 4,
1471
+ runProcessor({
1472
+ op: op,
1473
+ docs: safeDocs
1474
+ })
1475
+ ];
1476
+ case 1:
1477
+ _ref = _state.sent(), processed = _ref.docs;
1478
+ cb(processed, config);
1479
+ return [
1480
+ 3,
1481
+ 3
1482
+ ];
1483
+ case 2:
1484
+ e = _state.sent();
1485
+ cb(docs, config);
1486
+ return [
1487
+ 3,
1488
+ 3
1489
+ ];
1490
+ case 3:
1491
+ return [
1492
+ 2
1493
+ ];
1494
+ }
1495
+ });
1496
+ });
1497
+ return function(docs, config) {
1498
+ return _ref.apply(this, arguments);
1499
+ };
1500
+ }();
1501
+ };
1502
+ return cfgs.map(function(cfg) {
1503
+ var wrapped = _object_spread({}, cfg);
1504
+ wrapped.onFirstTime = wrapCb(cfg.onFirstTime, "first");
1505
+ wrapped.onModify = wrapCb(cfg.onModify, "modify");
1506
+ wrapped.onRemove = wrapCb(cfg.onRemove, "remove");
1507
+ if (cfg.extraParsers && cfg.extraParsers.length) {
1508
+ wrapped.extraParsers = cfg.extraParsers.map(function(p) {
1509
+ return {
1510
+ onFirstTime: wrapCb(p.onFirstTime, "first"),
1511
+ onModify: wrapCb(p.onModify, "modify"),
1512
+ onRemove: wrapCb(p.onRemove, "remove")
1513
+ };
1514
+ });
1515
+ }
1516
+ return wrapped;
1517
+ });
1518
+ };
1335
1519
  // src/hooks/snapshots/index.ts
1336
1520
  var useDbSnapshots = function(configs, label, settings) {
1337
1521
  var snapshotsFirstTime = useRef4([]);
@@ -1408,6 +1592,93 @@ var useDbSnapshots = function(configs, label, settings) {
1408
1592
  };
1409
1593
  }, []);
1410
1594
  };
1595
+ var useDbDocumentSnapshots = function(configs, label, settings) {
1596
+ var unsubscribeFunctions = useRef4([]);
1597
+ var lastDbDocsRef = useRef4([]);
1598
+ var perDocFirstTimeRef = useRef4({});
1599
+ var workerProcessorDb = useCallback3(function(payload) {
1600
+ return {
1601
+ docs: payload.docs
1602
+ };
1603
+ }, []);
1604
+ var runProcessor = useWebWorker(workerProcessorDb, settings === null || settings === void 0 ? void 0 : settings.worker);
1605
+ var wrapConfigsForWorker = function(cfgs) {
1606
+ return wrapDocumentConfigsWithWorker(cfgs, function(payload) {
1607
+ return runProcessor(payload);
1608
+ });
1609
+ };
1610
+ var getDocKey = function(config) {
1611
+ var _config_conditions;
1612
+ var conditionsKey = ((_config_conditions = config.conditions) === null || _config_conditions === void 0 ? void 0 : _config_conditions.length) ? JSON.stringify(config.conditions) : "";
1613
+ return "".concat(config.collectionName, "/").concat(config.documentId).concat(conditionsKey ? ":".concat(conditionsKey) : "");
1614
+ };
1615
+ var getFirstTimeBucket = function(config) {
1616
+ var key = getDocKey(config);
1617
+ if (!perDocFirstTimeRef.current[key]) {
1618
+ perDocFirstTimeRef.current[key] = [];
1619
+ }
1620
+ return perDocFirstTimeRef.current[key];
1621
+ };
1622
+ useDeepCompareEffect(function() {
1623
+ var start = performance.now();
1624
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
1625
+ console.log("==> ".concat(label || "DB document snapshots", " started from db... "));
1626
+ }
1627
+ var wrappedConfigs = wrapConfigsForWorker(configs);
1628
+ lastDbDocsRef.current = configs.map(function(c) {
1629
+ return "".concat(c.collectionName, "/").concat(c.documentId);
1630
+ });
1631
+ var snapshotResults = wrappedConfigs.map(function(config) {
1632
+ return snapshotDocument(config, getFirstTimeBucket(config));
1633
+ });
1634
+ unsubscribeFunctions.current = snapshotResults.map(function(result) {
1635
+ return result.unsubscribe;
1636
+ });
1637
+ Promise.all(snapshotResults.map(function(result) {
1638
+ return result.promise;
1639
+ })).then(function() {
1640
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
1641
+ console.log("==> ".concat(label || "DB document snapshots", " ended from db. It took ").concat((performance.now() - start).toFixed(2), " ms"));
1642
+ }
1643
+ });
1644
+ if (settings === null || settings === void 0 ? void 0 : settings.cleanupForConfigChange) {
1645
+ return function() {
1646
+ var _settings_worker;
1647
+ unsubscribeFunctions.current.forEach(function(unsubscribe) {
1648
+ if (unsubscribe) {
1649
+ unsubscribe();
1650
+ }
1651
+ });
1652
+ if ((settings === null || settings === void 0 ? void 0 : (_settings_worker = settings.worker) === null || _settings_worker === void 0 ? void 0 : _settings_worker.debug) && lastDbDocsRef.current.length) {
1653
+ console.log("==> ".concat(label || "DB document snapshots", " cleanup: cleaned previous subscriptions for [").concat(lastDbDocsRef.current.join(", "), "]"));
1654
+ }
1655
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
1656
+ console.log("==> ".concat(label || "DB document snapshots", " unsubscribed from db"));
1657
+ }
1658
+ };
1659
+ }
1660
+ }, [
1661
+ configs,
1662
+ label,
1663
+ settings
1664
+ ]);
1665
+ useEffect4(function() {
1666
+ return function() {
1667
+ var _settings_worker;
1668
+ unsubscribeFunctions.current.forEach(function(unsubscribe) {
1669
+ if (unsubscribe) {
1670
+ unsubscribe();
1671
+ }
1672
+ });
1673
+ if ((settings === null || settings === void 0 ? void 0 : (_settings_worker = settings.worker) === null || _settings_worker === void 0 ? void 0 : _settings_worker.debug) && lastDbDocsRef.current.length) {
1674
+ console.log("==> ".concat(label || "DB document snapshots", " cleanup: cleaned previous subscriptions for [").concat(lastDbDocsRef.current.join(", "), "]"));
1675
+ }
1676
+ if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
1677
+ console.log("==> ".concat(label || "DB document snapshots", " unsubscribed"));
1678
+ }
1679
+ };
1680
+ }, []);
1681
+ };
1411
1682
  var useSmartSnapshots = function(configs, label, settings) {
1412
1683
  var _useState2 = _sliced_to_array(useState2(null), 2), cacheCollectionsConfig = _useState2[0], setCacheCollectionsConfig = _useState2[1];
1413
1684
  useEffect4(function() {
@@ -1602,5 +1873,5 @@ var useSocketSnapshots = function(configs, label, settings) {
1602
1873
  socketConnected: socketConnected
1603
1874
  };
1604
1875
  };
1605
- export { useDbSnapshots, useDeepCompareEffect, useDeepCompareMemo, useDocumentTitle, useSafeEffect, useSetUserCountry, useSmartSnapshots, useSocketSnapshots, useWebWorker };
1876
+ export { useDbDocumentSnapshots, useDbSnapshots, useDeepCompareEffect, useDeepCompareMemo, useDocumentTitle, useSafeEffect, useSetUserCountry, useSmartSnapshots, useSocketSnapshots, useWebWorker };
1606
1877
  //# sourceMappingURL=index.mjs.map
@@ -185,6 +185,8 @@ interface DateInputElement extends BaseElementProps {
185
185
  props?: React.InputHTMLAttributes<HTMLInputElement>;
186
186
  calendarClassName?: string;
187
187
  inputClassName?: string;
188
+ selectedDayClassName?: string;
189
+ todayDayClassName?: string;
188
190
  }
189
191
  interface TextAreaElement extends BaseElementProps {
190
192
  type: "textarea";
@@ -360,6 +362,8 @@ interface DatePickerProps {
360
362
  toText?: string;
361
363
  buttonText?: string;
362
364
  calendarClassName?: string;
365
+ selectedDayClassName?: string;
366
+ todayDayClassName?: string;
363
367
  }
364
368
 
365
369
  export type { AppName, BaseElementProps, CheckboxContainerProps, ConfirmFormProps, CustomElementProps, DateInputContainerProps, DateInputElement, DatePickerProps, Direction, DurationInputOption, DurationInputProps, DurationValues, FormElement, FormSeparatorProps, InputContainerProps, InputElement, InternationalInputProps, LoginOption, ModularFormProps, ModularPopUp, MultiSelectProps, OnSnapshotCallback, OnSnapshotConfig, OnSnapshotConfigDocument, OnSnapshotParsers, SelectContainerProps, SelectElement, SelectWithSearchProps, SetState, Snapshot, SnapshotDocument, SnapshotResult, TextAreaContainerProps, TextAreaElement, WhereCondition };
@@ -185,6 +185,8 @@ interface DateInputElement extends BaseElementProps {
185
185
  props?: React.InputHTMLAttributes<HTMLInputElement>;
186
186
  calendarClassName?: string;
187
187
  inputClassName?: string;
188
+ selectedDayClassName?: string;
189
+ todayDayClassName?: string;
188
190
  }
189
191
  interface TextAreaElement extends BaseElementProps {
190
192
  type: "textarea";
@@ -360,6 +362,8 @@ interface DatePickerProps {
360
362
  toText?: string;
361
363
  buttonText?: string;
362
364
  calendarClassName?: string;
365
+ selectedDayClassName?: string;
366
+ todayDayClassName?: string;
363
367
  }
364
368
 
365
369
  export type { AppName, BaseElementProps, CheckboxContainerProps, ConfirmFormProps, CustomElementProps, DateInputContainerProps, DateInputElement, DatePickerProps, Direction, DurationInputOption, DurationInputProps, DurationValues, FormElement, FormSeparatorProps, InputContainerProps, InputElement, InternationalInputProps, LoginOption, ModularFormProps, ModularPopUp, MultiSelectProps, OnSnapshotCallback, OnSnapshotConfig, OnSnapshotConfigDocument, OnSnapshotParsers, SelectContainerProps, SelectElement, SelectWithSearchProps, SetState, Snapshot, SnapshotDocument, SnapshotResult, TextAreaContainerProps, TextAreaElement, WhereCondition };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akeyless-client-commons",
3
- "version": "1.1.98",
3
+ "version": "1.1.100",
4
4
  "scripts": {
5
5
  "build": "tsup",
6
6
  "deploy": "npm run build && npm version patch --no-git-tag-version && npm publish",