akeyless-client-commons 1.1.129 → 1.1.131
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/components/index.css.map +1 -1
- package/dist/components/index.d.mts +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +189 -52
- package/dist/components/index.mjs +180 -43
- package/dist/helpers/index.d.mts +6 -2
- package/dist/helpers/index.d.ts +6 -2
- package/dist/helpers/index.js +317 -200
- package/dist/helpers/index.mjs +305 -192
- package/dist/hooks/index.d.mts +5 -2
- package/dist/hooks/index.d.ts +5 -2
- package/dist/hooks/index.js +228 -103
- package/dist/hooks/index.mjs +219 -94
- package/package.json +2 -2
package/dist/hooks/index.mjs
CHANGED
|
@@ -7,6 +7,9 @@ function _array_like_to_array(arr, len) {
|
|
|
7
7
|
function _array_with_holes(arr) {
|
|
8
8
|
if (Array.isArray(arr)) return arr;
|
|
9
9
|
}
|
|
10
|
+
function _array_without_holes(arr) {
|
|
11
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
12
|
+
}
|
|
10
13
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
11
14
|
try {
|
|
12
15
|
var info = gen[key](arg);
|
|
@@ -75,6 +78,9 @@ function _instanceof(left, right) {
|
|
|
75
78
|
return left instanceof right;
|
|
76
79
|
}
|
|
77
80
|
}
|
|
81
|
+
function _iterable_to_array(iter) {
|
|
82
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
83
|
+
}
|
|
78
84
|
function _iterable_to_array_limit(arr, i) {
|
|
79
85
|
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
80
86
|
if (_i == null) return;
|
|
@@ -102,6 +108,9 @@ function _iterable_to_array_limit(arr, i) {
|
|
|
102
108
|
function _non_iterable_rest() {
|
|
103
109
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
104
110
|
}
|
|
111
|
+
function _non_iterable_spread() {
|
|
112
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
113
|
+
}
|
|
105
114
|
function _object_spread(target) {
|
|
106
115
|
for(var i = 1; i < arguments.length; i++){
|
|
107
116
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
@@ -154,6 +163,9 @@ function _tagged_template_literal(strings, raw) {
|
|
|
154
163
|
}
|
|
155
164
|
}));
|
|
156
165
|
}
|
|
166
|
+
function _to_consumable_array(arr) {
|
|
167
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
168
|
+
}
|
|
157
169
|
function _type_of(obj) {
|
|
158
170
|
"@swc/helpers - typeof";
|
|
159
171
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
@@ -330,6 +342,93 @@ import { ref, getDownloadURL, uploadBytes } from "firebase/storage";
|
|
|
330
342
|
// src/helpers/time_helpers.ts
|
|
331
343
|
import { Timestamp } from "firebase/firestore";
|
|
332
344
|
import moment from "moment-timezone";
|
|
345
|
+
// src/helpers/global.ts
|
|
346
|
+
import { CountryOptions, LanguageOptions } from "akeyless-types-commons";
|
|
347
|
+
import axios from "axios";
|
|
348
|
+
import { isEqual } from "lodash";
|
|
349
|
+
var getUserCountryByIp = /*#__PURE__*/ function() {
|
|
350
|
+
var _ref = _async_to_generator(function() {
|
|
351
|
+
var response, data, error;
|
|
352
|
+
return _ts_generator(this, function(_state) {
|
|
353
|
+
switch(_state.label){
|
|
354
|
+
case 0:
|
|
355
|
+
_state.trys.push([
|
|
356
|
+
0,
|
|
357
|
+
3,
|
|
358
|
+
,
|
|
359
|
+
4
|
|
360
|
+
]);
|
|
361
|
+
return [
|
|
362
|
+
4,
|
|
363
|
+
fetch("https://ipapi.co/json/")
|
|
364
|
+
];
|
|
365
|
+
case 1:
|
|
366
|
+
response = _state.sent();
|
|
367
|
+
return [
|
|
368
|
+
4,
|
|
369
|
+
response.json()
|
|
370
|
+
];
|
|
371
|
+
case 2:
|
|
372
|
+
data = _state.sent();
|
|
373
|
+
return [
|
|
374
|
+
2,
|
|
375
|
+
(data.country_code || CountryOptions.IL).toLowerCase()
|
|
376
|
+
];
|
|
377
|
+
case 3:
|
|
378
|
+
error = _state.sent();
|
|
379
|
+
console.error("Error fetching Country:", error);
|
|
380
|
+
return [
|
|
381
|
+
2,
|
|
382
|
+
CountryOptions.IL
|
|
383
|
+
];
|
|
384
|
+
case 4:
|
|
385
|
+
return [
|
|
386
|
+
2
|
|
387
|
+
];
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
return function getUserCountryByIp() {
|
|
392
|
+
return _ref.apply(this, arguments);
|
|
393
|
+
};
|
|
394
|
+
}();
|
|
395
|
+
var isNodeEnv = typeof process !== "undefined" && process.env;
|
|
396
|
+
var _ref = {
|
|
397
|
+
mode: isNodeEnv ? process.env.NEXT_PUBLIC_MODE : import.meta.env.VITE_MODE,
|
|
398
|
+
isLocal: (isNodeEnv ? process.env.NEXT_PUBLIC_IS_LOCAL : import.meta.env.VITE_is_local) === "true"
|
|
399
|
+
}, mode = _ref.mode, isLocal = _ref.isLocal;
|
|
400
|
+
var checkConditions = function(document2, conditions) {
|
|
401
|
+
if (!conditions || conditions.length === 0) return true;
|
|
402
|
+
return conditions.every(function(condition) {
|
|
403
|
+
var fieldValue = document2[condition.field_name];
|
|
404
|
+
switch(condition.operator){
|
|
405
|
+
case "==":
|
|
406
|
+
return fieldValue === condition.value;
|
|
407
|
+
case "!=":
|
|
408
|
+
return fieldValue !== condition.value;
|
|
409
|
+
case "<":
|
|
410
|
+
return fieldValue < condition.value;
|
|
411
|
+
case "<=":
|
|
412
|
+
return fieldValue <= condition.value;
|
|
413
|
+
case ">":
|
|
414
|
+
return fieldValue > condition.value;
|
|
415
|
+
case ">=":
|
|
416
|
+
return fieldValue >= condition.value;
|
|
417
|
+
case "in":
|
|
418
|
+
return Array.isArray(condition.value) && condition.value.includes(fieldValue);
|
|
419
|
+
case "not-in":
|
|
420
|
+
return Array.isArray(condition.value) && !condition.value.includes(fieldValue);
|
|
421
|
+
case "array-contains":
|
|
422
|
+
return Array.isArray(fieldValue) && fieldValue.includes(condition.value);
|
|
423
|
+
case "array-contains-any":
|
|
424
|
+
return Array.isArray(fieldValue) && Array.isArray(condition.value) && condition.value.some(function(v) {
|
|
425
|
+
return fieldValue.includes(v);
|
|
426
|
+
});
|
|
427
|
+
default:
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
};
|
|
333
432
|
// src/helpers/firebase.ts
|
|
334
433
|
var initApp = function() {
|
|
335
434
|
var isNodeEnv2 = typeof process !== "undefined" && process.env;
|
|
@@ -592,85 +691,6 @@ var snapshotDocument = function(config, snapshotsFirstTime) {
|
|
|
592
691
|
unsubscribe: unsubscribe
|
|
593
692
|
};
|
|
594
693
|
};
|
|
595
|
-
var checkConditions = function(document2, conditions) {
|
|
596
|
-
if (!conditions || conditions.length === 0) return true;
|
|
597
|
-
return conditions.every(function(condition) {
|
|
598
|
-
var fieldValue = document2[condition.field_name];
|
|
599
|
-
switch(condition.operator){
|
|
600
|
-
case "==":
|
|
601
|
-
return fieldValue === condition.value;
|
|
602
|
-
case "!=":
|
|
603
|
-
return fieldValue !== condition.value;
|
|
604
|
-
case "<":
|
|
605
|
-
return fieldValue < condition.value;
|
|
606
|
-
case "<=":
|
|
607
|
-
return fieldValue <= condition.value;
|
|
608
|
-
case ">":
|
|
609
|
-
return fieldValue > condition.value;
|
|
610
|
-
case ">=":
|
|
611
|
-
return fieldValue >= condition.value;
|
|
612
|
-
case "array-contains":
|
|
613
|
-
return Array.isArray(fieldValue) && fieldValue.includes(condition.value);
|
|
614
|
-
default:
|
|
615
|
-
return false;
|
|
616
|
-
}
|
|
617
|
-
});
|
|
618
|
-
};
|
|
619
|
-
// src/helpers/global.ts
|
|
620
|
-
import { CountryOptions, LanguageOptions } from "akeyless-types-commons";
|
|
621
|
-
import axios from "axios";
|
|
622
|
-
import { isEqual } from "lodash";
|
|
623
|
-
var getUserCountryByIp = /*#__PURE__*/ function() {
|
|
624
|
-
var _ref = _async_to_generator(function() {
|
|
625
|
-
var response, data, error;
|
|
626
|
-
return _ts_generator(this, function(_state) {
|
|
627
|
-
switch(_state.label){
|
|
628
|
-
case 0:
|
|
629
|
-
_state.trys.push([
|
|
630
|
-
0,
|
|
631
|
-
3,
|
|
632
|
-
,
|
|
633
|
-
4
|
|
634
|
-
]);
|
|
635
|
-
return [
|
|
636
|
-
4,
|
|
637
|
-
fetch("https://ipapi.co/json/")
|
|
638
|
-
];
|
|
639
|
-
case 1:
|
|
640
|
-
response = _state.sent();
|
|
641
|
-
return [
|
|
642
|
-
4,
|
|
643
|
-
response.json()
|
|
644
|
-
];
|
|
645
|
-
case 2:
|
|
646
|
-
data = _state.sent();
|
|
647
|
-
return [
|
|
648
|
-
2,
|
|
649
|
-
(data.country_code || CountryOptions.IL).toLowerCase()
|
|
650
|
-
];
|
|
651
|
-
case 3:
|
|
652
|
-
error = _state.sent();
|
|
653
|
-
console.error("Error fetching Country:", error);
|
|
654
|
-
return [
|
|
655
|
-
2,
|
|
656
|
-
CountryOptions.IL
|
|
657
|
-
];
|
|
658
|
-
case 4:
|
|
659
|
-
return [
|
|
660
|
-
2
|
|
661
|
-
];
|
|
662
|
-
}
|
|
663
|
-
});
|
|
664
|
-
});
|
|
665
|
-
return function getUserCountryByIp() {
|
|
666
|
-
return _ref.apply(this, arguments);
|
|
667
|
-
};
|
|
668
|
-
}();
|
|
669
|
-
var isNodeEnv = typeof process !== "undefined" && process.env;
|
|
670
|
-
var _ref = {
|
|
671
|
-
mode: isNodeEnv ? process.env.NEXT_PUBLIC_MODE : import.meta.env.VITE_MODE,
|
|
672
|
-
isLocal: (isNodeEnv ? process.env.NEXT_PUBLIC_IS_LOCAL : import.meta.env.VITE_is_local) === "true"
|
|
673
|
-
}, mode = _ref.mode, isLocal = _ref.isLocal;
|
|
674
694
|
// src/helpers/forms.ts
|
|
675
695
|
import XRegExp from "xregexp";
|
|
676
696
|
var textRegex = XRegExp(String.raw(_templateObject()), "gu");
|
|
@@ -713,6 +733,9 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
713
733
|
this.disconnectCallbacks = [];
|
|
714
734
|
this.authToken = null;
|
|
715
735
|
this.isDisconnected = true;
|
|
736
|
+
/// the data-socket keeps one subscription per collection per socket, so a second condition set
|
|
737
|
+
/// for a collection never reaches it and would silently receive the first one's documents
|
|
738
|
+
this.activeConditions = /* @__PURE__ */ new Map();
|
|
716
739
|
this.handleDisconnect = function(source, reason) {
|
|
717
740
|
var _this_socket;
|
|
718
741
|
if (_this.isDisconnected) {
|
|
@@ -880,6 +903,39 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
880
903
|
}
|
|
881
904
|
}
|
|
882
905
|
},
|
|
906
|
+
{
|
|
907
|
+
key: "registerConditions",
|
|
908
|
+
value: function registerConditions(collectionName) {
|
|
909
|
+
var conditions = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
910
|
+
var signature = JSON.stringify(conditions);
|
|
911
|
+
var active = this.activeConditions.get(collectionName);
|
|
912
|
+
if (!active) {
|
|
913
|
+
this.activeConditions.set(collectionName, {
|
|
914
|
+
signature: signature,
|
|
915
|
+
conditions: conditions,
|
|
916
|
+
count: 1
|
|
917
|
+
});
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
active.count++;
|
|
921
|
+
if (active.signature !== signature) {
|
|
922
|
+
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));
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
},
|
|
926
|
+
{
|
|
927
|
+
key: "releaseConditions",
|
|
928
|
+
value: function releaseConditions(collectionName) {
|
|
929
|
+
var active = this.activeConditions.get(collectionName);
|
|
930
|
+
if (!active) {
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
active.count--;
|
|
934
|
+
if (active.count <= 0) {
|
|
935
|
+
this.activeConditions.delete(collectionName);
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
},
|
|
883
939
|
{
|
|
884
940
|
key: "disconnectSocket",
|
|
885
941
|
value: function disconnectSocket() {
|
|
@@ -891,6 +947,8 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
891
947
|
},
|
|
892
948
|
{
|
|
893
949
|
/// subscribe to collections
|
|
950
|
+
/// conditions are derived from OnSnapshotConfig.conditions, never passed in, so a caller cannot
|
|
951
|
+
/// set them in a second place and have them silently overwritten
|
|
894
952
|
key: "subscribeToCollections",
|
|
895
953
|
value: function subscribeToCollections(config, options) {
|
|
896
954
|
var _this = this;
|
|
@@ -903,26 +961,77 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
903
961
|
});
|
|
904
962
|
var eventHandlers = [];
|
|
905
963
|
config.forEach(function(configuration) {
|
|
906
|
-
var collectionName = configuration.collectionName,
|
|
964
|
+
var collectionName = configuration.collectionName, conditions = configuration.conditions;
|
|
965
|
+
var parsers = [
|
|
966
|
+
configuration
|
|
967
|
+
].concat(_to_consumable_array(configuration.extraParsers || []));
|
|
968
|
+
var matchedIds = /* @__PURE__ */ new Set();
|
|
907
969
|
var attach = function(eventName, handler) {
|
|
908
|
-
if (!handler) return;
|
|
909
|
-
_this.socket.off(eventName, handler);
|
|
910
970
|
_this.socket.on(eventName, handler);
|
|
911
971
|
eventHandlers.push({
|
|
912
972
|
eventName: eventName,
|
|
913
973
|
handler: handler
|
|
914
974
|
});
|
|
915
975
|
};
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
976
|
+
var toDocs = function(payload) {
|
|
977
|
+
return Array.isArray(payload) ? payload : payload ? [
|
|
978
|
+
payload
|
|
979
|
+
] : [];
|
|
980
|
+
};
|
|
981
|
+
var run = function(op, docs) {
|
|
982
|
+
return parsers.forEach(function(parser) {
|
|
983
|
+
var _parser_op;
|
|
984
|
+
return (_parser_op = parser[op]) === null || _parser_op === void 0 ? void 0 : _parser_op.call(parser, docs, configuration);
|
|
985
|
+
});
|
|
986
|
+
};
|
|
987
|
+
var runIfAny = function(op, docs) {
|
|
988
|
+
if (docs.length) {
|
|
989
|
+
run(op, docs);
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
attach("initial:".concat(collectionName), function(payload) {
|
|
993
|
+
var docs = toDocs(payload).filter(function(doc2) {
|
|
994
|
+
return checkConditions(doc2, conditions);
|
|
995
|
+
});
|
|
996
|
+
matchedIds.clear();
|
|
997
|
+
docs.forEach(function(doc2) {
|
|
998
|
+
return matchedIds.add(doc2.id);
|
|
999
|
+
});
|
|
1000
|
+
run("onFirstTime", docs);
|
|
1001
|
+
});
|
|
1002
|
+
var handleUpsert = function(payload, defaultOp) {
|
|
1003
|
+
var added = [];
|
|
1004
|
+
var modified = [];
|
|
1005
|
+
var removed = [];
|
|
1006
|
+
toDocs(payload).forEach(function(doc2) {
|
|
1007
|
+
if (!(conditions === null || conditions === void 0 ? void 0 : conditions.length)) {
|
|
1008
|
+
(defaultOp === "onAdd" ? added : modified).push(doc2);
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
var wasMatching = matchedIds.has(doc2.id);
|
|
1012
|
+
if (checkConditions(doc2, conditions)) {
|
|
1013
|
+
matchedIds.add(doc2.id);
|
|
1014
|
+
(wasMatching ? modified : added).push(doc2);
|
|
1015
|
+
} else if (wasMatching) {
|
|
1016
|
+
matchedIds.delete(doc2.id);
|
|
1017
|
+
removed.push(doc2);
|
|
1018
|
+
}
|
|
1019
|
+
});
|
|
1020
|
+
runIfAny("onAdd", added);
|
|
1021
|
+
runIfAny("onModify", modified);
|
|
1022
|
+
runIfAny("onRemove", removed);
|
|
1023
|
+
};
|
|
1024
|
+
attach("add:".concat(collectionName), function(payload) {
|
|
1025
|
+
return handleUpsert(payload, "onAdd");
|
|
1026
|
+
});
|
|
1027
|
+
attach("update:".concat(collectionName), function(payload) {
|
|
1028
|
+
return handleUpsert(payload, "onModify");
|
|
1029
|
+
});
|
|
1030
|
+
attach("delete:".concat(collectionName), function(payload) {
|
|
1031
|
+
var docs = toDocs(payload).filter(function(doc2) {
|
|
1032
|
+
return !(conditions === null || conditions === void 0 ? void 0 : conditions.length) || matchedIds.delete(doc2.id);
|
|
1033
|
+
});
|
|
1034
|
+
runIfAny("onRemove", docs);
|
|
926
1035
|
});
|
|
927
1036
|
});
|
|
928
1037
|
var acknowledge = function(callback) {
|
|
@@ -932,12 +1041,28 @@ var SocketService = /*#__PURE__*/ function() {
|
|
|
932
1041
|
console.error("Failed to subscribe to ".concat(config.join(", "), ": ").concat(callback.message));
|
|
933
1042
|
}
|
|
934
1043
|
};
|
|
935
|
-
|
|
936
|
-
|
|
1044
|
+
config.forEach(function(c) {
|
|
1045
|
+
return _this.registerConditions(c.collectionName, c.conditions);
|
|
1046
|
+
});
|
|
1047
|
+
var conditionsByCollection = config.reduce(function(acc, c) {
|
|
1048
|
+
var active = _this.activeConditions.get(c.collectionName);
|
|
1049
|
+
if (active === null || active === void 0 ? void 0 : active.conditions.length) {
|
|
1050
|
+
acc[c.collectionName] = active.conditions;
|
|
1051
|
+
}
|
|
1052
|
+
return acc;
|
|
1053
|
+
}, {});
|
|
1054
|
+
var subscribeOptions = Object.keys(conditionsByCollection).length ? _object_spread_props(_object_spread({}, options), {
|
|
1055
|
+
conditions: conditionsByCollection
|
|
1056
|
+
}) : options;
|
|
1057
|
+
if (subscribeOptions) {
|
|
1058
|
+
s.emit("subscribe_options", subscribeOptions);
|
|
937
1059
|
}
|
|
938
1060
|
s.emit("subscribe_collections", collectionsNames, acknowledge);
|
|
939
1061
|
return function() {
|
|
940
1062
|
console.log("Cleaning up subscriptions for: ".concat(collectionsNames.join(", ")));
|
|
1063
|
+
collectionsNames.forEach(function(name) {
|
|
1064
|
+
return _this.releaseConditions(name);
|
|
1065
|
+
});
|
|
941
1066
|
s.emit("unsubscribe_collections", collectionsNames);
|
|
942
1067
|
eventHandlers.forEach(function(eh) {
|
|
943
1068
|
s.off(eh.eventName, eh.handler);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "akeyless-client-commons",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.131",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "tsup",
|
|
6
6
|
"deploy": "npm run build && npm version patch --no-git-tag-version && npm publish",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@radix-ui/react-progress": "^1.1.1",
|
|
19
19
|
"@radix-ui/react-slot": "^1.1.2",
|
|
20
20
|
"@types/lodash": "^4.17.13",
|
|
21
|
-
"akeyless-types-commons": "^1.0.
|
|
21
|
+
"akeyless-types-commons": "^1.0.128",
|
|
22
22
|
"assets": "^3.0.1",
|
|
23
23
|
"axios": "^1.7.9",
|
|
24
24
|
"class-variance-authority": "^0.7.0",
|