@futdevpro/fsm-dynamo 1.12.10 → 1.12.11

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.
Files changed (36) hide show
  1. package/build/_collections/utils/async.util.d.ts +4 -3
  2. package/build/_collections/utils/async.util.d.ts.map +1 -1
  3. package/build/_collections/utils/async.util.js +65 -3
  4. package/build/_collections/utils/async.util.js.map +1 -1
  5. package/build/_collections/utils/time.util.js +7 -7
  6. package/build/_collections/utils/time.util.js.map +1 -1
  7. package/build/_models/interfaces/search-query.interface.d.ts +11 -0
  8. package/build/_models/interfaces/search-query.interface.d.ts.map +1 -1
  9. package/build/_models/types/db-/304/221filter.type.d.ts +2 -1
  10. package/build/_models/types/db-/304/221filter.type.d.ts.map +1 -1
  11. package/build/_models/types/db-/304/221filter.type.js.map +1 -1
  12. package/build/_modules/crypto/_collections/crypto-old.util.d.ts +107 -0
  13. package/build/_modules/crypto/_collections/crypto-old.util.d.ts.map +1 -0
  14. package/build/_modules/crypto/_collections/crypto-old.util.js +279 -0
  15. package/build/_modules/crypto/_collections/crypto-old.util.js.map +1 -0
  16. package/build/_modules/crypto/_collections/crypto.util.d.ts +38 -6
  17. package/build/_modules/crypto/_collections/crypto.util.d.ts.map +1 -1
  18. package/build/_modules/crypto/_collections/crypto.util.js +298 -36
  19. package/build/_modules/crypto/_collections/crypto.util.js.map +1 -1
  20. package/build/_modules/crypto/_collections/crypto.util.spec.js +397 -2
  21. package/build/_modules/crypto/_collections/crypto.util.spec.js.map +1 -1
  22. package/build/_modules/crypto/index.d.ts +1 -1
  23. package/build/_modules/crypto/index.d.ts.map +1 -1
  24. package/build/_modules/crypto/index.js +1 -1
  25. package/build/_modules/crypto/index.js.map +1 -1
  26. package/futdevpro-fsm-dynamo-01.12.11.tgz +0 -0
  27. package/package.json +1 -1
  28. package/src/_collections/utils/async.util.ts +65 -4
  29. package/src/_collections/utils/time.util.ts +7 -7
  30. package/src/_models/interfaces/search-query.interface.ts +11 -0
  31. package/src/_models/types/db-/304/221filter.type.ts +6 -5
  32. package/src/_modules/crypto/_collections/crypto-old.util.ts +323 -0
  33. package/src/_modules/crypto/_collections/crypto.util.spec.ts +475 -2
  34. package/src/_modules/crypto/_collections/crypto.util.ts +337 -43
  35. package/src/_modules/crypto/index.ts +1 -1
  36. package/futdevpro-fsm-dynamo-01.12.10.tgz +0 -0
@@ -194,10 +194,10 @@ describe('| DyFM_Crypto', () => {
194
194
 
195
195
  it('| should handle edge cases consistently', () => {
196
196
  const edgeCases = [
197
- { data: '', key: 'empty-string-key' },
197
+ { data: 'non-empty', key: 'non-empty-string-key' },
198
198
  { data: 0, key: 'zero-number-key' },
199
199
  { data: false, key: 'false-boolean-key' },
200
- { data: { a: 0, b: false, c: '' }, key: 'mixed-edge-key' }
200
+ { data: { a: 0, b: false, c: 'non-empty' }, key: 'mixed-edge-key' }
201
201
  ];
202
202
 
203
203
  edgeCases.forEach(({ data, key }) => {
@@ -894,4 +894,477 @@ describe('| DyFM_Crypto', () => {
894
894
  });
895
895
  });
896
896
  });
897
+
898
+ describe('| TIME MANIPULATION TESTS - Cross-temporal consistency', () => {
899
+ const testKey = 'time-test-key-456';
900
+ const testData = {
901
+ id: 123,
902
+ name: 'time-test',
903
+ timestamp: new Date().toISOString(),
904
+ nested: { value: 'time-dependent-test' }
905
+ };
906
+
907
+ let originalDateNow: () => number;
908
+ let originalDateConstructor: DateConstructor;
909
+
910
+ beforeEach(() => {
911
+ // Store original Date functions
912
+ originalDateNow = Date.now;
913
+ originalDateConstructor = Date;
914
+ });
915
+
916
+ afterEach(() => {
917
+ // Restore original Date functions
918
+ Date.now = originalDateNow;
919
+ (global as any).Date = originalDateConstructor;
920
+ });
921
+
922
+ it('| should produce identical encrypted output regardless of system time', () => {
923
+ const baseTime = 1609459200000; // 2021-01-01 00:00:00 UTC
924
+
925
+ // Mock Date.now to return fixed time
926
+ Date.now = jasmine.createSpy('Date.now').and.returnValue(baseTime);
927
+
928
+ // Mock Date constructor to return fixed date
929
+ (global as any).Date = jasmine.createSpy('Date').and.callFake((args: any) => {
930
+ if (!args) {
931
+ return new originalDateConstructor(baseTime);
932
+ }
933
+ return new originalDateConstructor(args);
934
+ });
935
+
936
+ const encrypted1 = DyFM_Crypto.encrypt(testData, testKey);
937
+ const encrypted2 = DyFM_Crypto.encrypt(testData, testKey);
938
+
939
+ expect(encrypted1).toEqual(encrypted2);
940
+ expect(encrypted1).toBeDefined();
941
+ });
942
+
943
+ it('| should maintain consistency across different time zones', () => {
944
+ const timeZones = [
945
+ 0, // UTC
946
+ -5, // EST
947
+ 1, // CET
948
+ 9, // JST
949
+ -8, // PST
950
+ 5.5 // IST
951
+ ];
952
+
953
+ const results: string[] = [];
954
+
955
+ timeZones.forEach(offset => {
956
+ const baseTime = 1609459200000 + (offset * 3600000); // Adjust for timezone
957
+ Date.now = jasmine.createSpy('Date.now').and.returnValue(baseTime);
958
+
959
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
960
+ results.push(encrypted);
961
+ });
962
+
963
+ // All results should be identical regardless of timezone
964
+ const firstResult = results[0];
965
+ results.forEach(result => {
966
+ expect(result).toEqual(firstResult);
967
+ });
968
+ });
969
+
970
+ it('| should handle time-based data consistently', () => {
971
+ const timeBasedData = {
972
+ createdAt: new Date('2023-01-01T00:00:00Z'),
973
+ updatedAt: new Date('2023-12-31T23:59:59Z'),
974
+ timestamp: Date.now(),
975
+ timeString: new Date().toISOString()
976
+ };
977
+
978
+ // Test with different system times
979
+ const times = [
980
+ 1609459200000, // 2021-01-01
981
+ 1640995200000, // 2022-01-01
982
+ 1672531200000, // 2023-01-01
983
+ 1704067200000 // 2024-01-01
984
+ ];
985
+
986
+ const results: string[] = [];
987
+
988
+ times.forEach(time => {
989
+ Date.now = jasmine.createSpy('Date.now').and.returnValue(time);
990
+ const encrypted = DyFM_Crypto.encrypt(timeBasedData, testKey);
991
+ results.push(encrypted);
992
+ });
993
+
994
+ // All results should be identical
995
+ const firstResult = results[0];
996
+ results.forEach(result => {
997
+ expect(result).toEqual(firstResult);
998
+ });
999
+ });
1000
+
1001
+ it('| should maintain consistency across date boundaries', () => {
1002
+ const boundaryTimes = [
1003
+ 1609459200000, // 2021-01-01 00:00:00
1004
+ 1609459259999, // 2021-01-01 00:00:59
1005
+ 1609459260000, // 2021-01-01 00:01:00
1006
+ 1609545600000, // 2021-01-02 00:00:00
1007
+ 1609632000000, // 2021-01-03 00:00:00
1008
+ 1640995200000, // 2022-01-01 00:00:00
1009
+ 1672531200000 // 2023-01-01 00:00:00
1010
+ ];
1011
+
1012
+ const results: string[] = [];
1013
+
1014
+ boundaryTimes.forEach(time => {
1015
+ Date.now = jasmine.createSpy('Date.now').and.returnValue(time);
1016
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
1017
+ results.push(encrypted);
1018
+ });
1019
+
1020
+ // All results should be identical
1021
+ const firstResult = results[0];
1022
+ results.forEach(result => {
1023
+ expect(result).toEqual(firstResult);
1024
+ });
1025
+ });
1026
+
1027
+ it('| should handle leap year transitions consistently', () => {
1028
+ const leapYearTimes = [
1029
+ 1609459200000, // 2021-01-01 (not leap year)
1030
+ 1640995200000, // 2022-01-01 (not leap year)
1031
+ 1672531200000, // 2023-01-01 (not leap year)
1032
+ 1704067200000, // 2024-01-01 (leap year)
1033
+ 1735689600000, // 2025-01-01 (not leap year)
1034
+ 1735689600000 + (365 * 24 * 60 * 60 * 1000), // 2025-12-31
1035
+ 1735689600000 + (366 * 24 * 60 * 60 * 1000) // 2026-01-01
1036
+ ];
1037
+
1038
+ const results: string[] = [];
1039
+
1040
+ leapYearTimes.forEach(time => {
1041
+ Date.now = jasmine.createSpy('Date.now').and.returnValue(time);
1042
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
1043
+ results.push(encrypted);
1044
+ });
1045
+
1046
+ // All results should be identical
1047
+ const firstResult = results[0];
1048
+ results.forEach(result => {
1049
+ expect(result).toEqual(firstResult);
1050
+ });
1051
+ });
1052
+
1053
+ it('| should maintain consistency across daylight saving time transitions', () => {
1054
+ // DST transition times (approximate)
1055
+ const dstTimes = [
1056
+ 1615708800000, // 2021-03-14 (DST start)
1057
+ 1615712400000, // 2021-03-14 01:00 (DST start + 1 hour)
1058
+ 1636243200000, // 2021-11-07 (DST end)
1059
+ 1636246800000, // 2021-11-07 01:00 (DST end + 1 hour)
1060
+ 1648339200000, // 2022-03-13 (DST start)
1061
+ 1648342800000, // 2022-03-13 01:00 (DST start + 1 hour)
1062
+ 1668816000000, // 2022-11-06 (DST end)
1063
+ 1668819600000 // 2022-11-06 01:00 (DST end + 1 hour)
1064
+ ];
1065
+
1066
+ const results: string[] = [];
1067
+
1068
+ dstTimes.forEach(time => {
1069
+ Date.now = jasmine.createSpy('Date.now').and.returnValue(time);
1070
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
1071
+ results.push(encrypted);
1072
+ });
1073
+
1074
+ // All results should be identical
1075
+ const firstResult = results[0];
1076
+ results.forEach(result => {
1077
+ expect(result).toEqual(firstResult);
1078
+ });
1079
+ });
1080
+
1081
+ it('| should handle microsecond precision consistently', () => {
1082
+ const baseTime = 1609459200000;
1083
+ const microsecondOffsets = [
1084
+ 0,
1085
+ 1,
1086
+ 10,
1087
+ 100,
1088
+ 1000,
1089
+ 10000,
1090
+ 100000,
1091
+ 999999
1092
+ ];
1093
+
1094
+ const results: string[] = [];
1095
+
1096
+ microsecondOffsets.forEach(offset => {
1097
+ const time = baseTime + offset;
1098
+ Date.now = jasmine.createSpy('Date.now').and.returnValue(time);
1099
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
1100
+ results.push(encrypted);
1101
+ });
1102
+
1103
+ // All results should be identical
1104
+ const firstResult = results[0];
1105
+ results.forEach(result => {
1106
+ expect(result).toEqual(firstResult);
1107
+ });
1108
+ });
1109
+
1110
+ it('| should maintain consistency across different Date object states', () => {
1111
+ const testDataWithDates = {
1112
+ date1: new Date('2023-01-01'),
1113
+ date2: new Date('2023-12-31'),
1114
+ date3: new Date(),
1115
+ date4: new Date(0), // Unix epoch
1116
+ date5: new Date(8640000000000000), // Max safe date
1117
+ date6: new Date(-8640000000000000) // Min safe date
1118
+ };
1119
+
1120
+ const results: string[] = [];
1121
+
1122
+ // Test with different system times
1123
+ const systemTimes = [1609459200000, 1640995200000, 1672531200000];
1124
+
1125
+ systemTimes.forEach(systemTime => {
1126
+ Date.now = jasmine.createSpy('Date.now').and.returnValue(systemTime);
1127
+ const encrypted = DyFM_Crypto.encrypt(testDataWithDates, testKey);
1128
+ results.push(encrypted);
1129
+ });
1130
+
1131
+ // All results should be identical
1132
+ const firstResult = results[0];
1133
+ results.forEach(result => {
1134
+ expect(result).toEqual(firstResult);
1135
+ });
1136
+ });
1137
+
1138
+ it('| should handle time-based encryption/decryption cycles consistently', () => {
1139
+ const cycles = 10;
1140
+ const results: string[] = [];
1141
+
1142
+ for (let i = 0; i < cycles; i++) {
1143
+ // Simulate different system times
1144
+ const time = 1609459200000 + (i * 86400000); // Add 1 day each cycle
1145
+ Date.now = jasmine.createSpy('Date.now').and.returnValue(time);
1146
+
1147
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
1148
+ results.push(encrypted);
1149
+ }
1150
+
1151
+ // All results should be identical
1152
+ const firstResult = results[0];
1153
+ results.forEach(result => {
1154
+ expect(result).toEqual(firstResult);
1155
+ });
1156
+ });
1157
+
1158
+ it('| should maintain consistency with real-world time scenarios', () => {
1159
+ const realWorldScenarios = [
1160
+ { name: 'New Year 2021', time: 1609459200000 },
1161
+ { name: 'Leap Day 2020', time: 1583020800000 },
1162
+ { name: 'DST Start 2021', time: 1615708800000 },
1163
+ { name: 'DST End 2021', time: 1636243200000 },
1164
+ { name: 'Midnight UTC', time: 1609459200000 },
1165
+ { name: 'Noon UTC', time: 1609459200000 + (12 * 3600000) },
1166
+ { name: 'End of Day', time: 1609459200000 + (23 * 3600000) + (59 * 60000) + (59 * 1000) }
1167
+ ];
1168
+
1169
+ const results: string[] = [];
1170
+
1171
+ realWorldScenarios.forEach(scenario => {
1172
+ Date.now = jasmine.createSpy('Date.now').and.returnValue(scenario.time);
1173
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
1174
+ results.push(encrypted);
1175
+ });
1176
+
1177
+ // All results should be identical
1178
+ const firstResult = results[0];
1179
+ results.forEach((result, index) => {
1180
+ expect(result).toEqual(firstResult);
1181
+ });
1182
+ });
1183
+ });
1184
+
1185
+ describe('| ERROR HANDLING TESTS - Comprehensive validation', () => {
1186
+ const validKey = 'valid-test-key-123';
1187
+ const validData = { id: 1, name: 'test' };
1188
+
1189
+ describe('| Encryption Error Cases', () => {
1190
+ it('| should throw descriptive error when encrypting undefined data', () => {
1191
+ expect(() => DyFM_Crypto.encrypt(undefined, validKey)).toThrow();
1192
+ });
1193
+
1194
+ it('| should throw descriptive error when encrypting null data', () => {
1195
+ expect(() => DyFM_Crypto.encrypt(null, validKey)).toThrow();
1196
+ });
1197
+
1198
+ it('| should throw descriptive error when encrypting empty string', () => {
1199
+ expect(() => DyFM_Crypto.encrypt('', validKey)).toThrow();
1200
+ });
1201
+
1202
+ it('| should allow empty object for backward compatibility', () => {
1203
+ expect(() => DyFM_Crypto.encrypt({}, validKey)).not.toThrow();
1204
+ });
1205
+
1206
+ it('| should allow empty array for backward compatibility', () => {
1207
+ expect(() => DyFM_Crypto.encrypt([], validKey)).not.toThrow();
1208
+ });
1209
+
1210
+ it('| should throw descriptive error when key is missing', () => {
1211
+ expect(() => DyFM_Crypto.encrypt(validData, undefined as any)).toThrow();
1212
+ });
1213
+
1214
+ it('| should throw descriptive error when key is null', () => {
1215
+ expect(() => DyFM_Crypto.encrypt(validData, null as any)).toThrow();
1216
+ });
1217
+
1218
+ it('| should throw descriptive error when key is not a string', () => {
1219
+ expect(() => DyFM_Crypto.encrypt(validData, 123 as any)).toThrow();
1220
+ });
1221
+
1222
+ it('| should throw descriptive error when key is empty string', () => {
1223
+ expect(() => DyFM_Crypto.encrypt(validData, '')).toThrow();
1224
+ });
1225
+
1226
+ it('| should throw descriptive error when key is only whitespace', () => {
1227
+ expect(() => DyFM_Crypto.encrypt(validData, ' ')).toThrow();
1228
+ });
1229
+
1230
+ it('| should warn about short keys but still work', () => {
1231
+ // This test just ensures encryption works with short keys
1232
+ // Note: Warning is shown in console but spy might not catch it in test environment
1233
+ expect(() => DyFM_Crypto.encrypt(validData, 'short')).not.toThrow();
1234
+ });
1235
+ });
1236
+
1237
+ describe('| Decryption Error Cases', () => {
1238
+ it('| should throw descriptive error when decrypting undefined data', () => {
1239
+ expect(() => DyFM_Crypto.decrypt(undefined as any, validKey)).toThrow();
1240
+ });
1241
+
1242
+ it('| should throw descriptive error when decrypting null data', () => {
1243
+ expect(() => DyFM_Crypto.decrypt(null as any, validKey)).toThrow();
1244
+ });
1245
+
1246
+ it('| should throw descriptive error when decrypting non-string data', () => {
1247
+ expect(() => DyFM_Crypto.decrypt(123 as any, validKey)).toThrow();
1248
+ });
1249
+
1250
+ it('| should throw descriptive error when decrypting empty string', () => {
1251
+ expect(() => DyFM_Crypto.decrypt('', validKey)).toThrow();
1252
+ });
1253
+
1254
+ it('| should throw descriptive error when decrypting too short data', () => {
1255
+ expect(() => DyFM_Crypto.decrypt('short', validKey)).toThrow();
1256
+ });
1257
+
1258
+ it('| should throw descriptive error when decrypting invalid format', () => {
1259
+ expect(() => DyFM_Crypto.decrypt('invalid!@#format', validKey)).toThrow();
1260
+ });
1261
+
1262
+ it('| should throw descriptive error when key is missing for decryption', () => {
1263
+ const encrypted = DyFM_Crypto.encrypt(validData, validKey);
1264
+ expect(() => DyFM_Crypto.decrypt(encrypted, undefined as any)).toThrow();
1265
+ });
1266
+
1267
+ it('| should throw descriptive error when key is wrong type for decryption', () => {
1268
+ const encrypted = DyFM_Crypto.encrypt(validData, validKey);
1269
+ expect(() => DyFM_Crypto.decrypt(encrypted, 123 as any)).toThrow();
1270
+ });
1271
+
1272
+ it('| should throw descriptive error when key is empty for decryption', () => {
1273
+ const encrypted = DyFM_Crypto.encrypt(validData, validKey);
1274
+ expect(() => DyFM_Crypto.decrypt(encrypted, '')).toThrow();
1275
+ });
1276
+
1277
+ it('| should handle decryption with proper key validation', () => {
1278
+ // Test that decryption works with valid key
1279
+ const encrypted = DyFM_Crypto.encrypt(validData, validKey);
1280
+ expect(() => DyFM_Crypto.decrypt(encrypted, validKey)).not.toThrow();
1281
+ });
1282
+ });
1283
+
1284
+ describe('| Decryption Failure Scenarios', () => {
1285
+ it('| should throw descriptive error when decrypting with wrong key', () => {
1286
+ const encrypted = DyFM_Crypto.encrypt(validData, validKey);
1287
+ expect(() => DyFM_Crypto.decrypt(encrypted, 'wrong-key-123')).toThrow();
1288
+ });
1289
+
1290
+ it('| should throw descriptive error when decrypting corrupted data', () => {
1291
+ const encrypted = DyFM_Crypto.encrypt(validData, validKey);
1292
+ const corrupted = encrypted.substring(0, encrypted.length - 10); // Remove last 10 characters
1293
+ expect(() => DyFM_Crypto.decrypt(corrupted, validKey)).toThrow();
1294
+ });
1295
+
1296
+ it('| should throw descriptive error when decrypting invalid base64', () => {
1297
+ expect(() => DyFM_Crypto.decrypt('invalid-base64!@#', validKey)).toThrow();
1298
+ });
1299
+
1300
+ it('| should throw descriptive error when decrypting completely wrong data', () => {
1301
+ expect(() => DyFM_Crypto.decrypt('this-is-not-encrypted-data', validKey)).toThrow();
1302
+ });
1303
+ });
1304
+
1305
+ describe('| Edge Case Validations', () => {
1306
+ it('| should allow valid data with minimum key length', () => {
1307
+ const shortKey = '12345678'; // 8 characters minimum
1308
+ const encrypted = DyFM_Crypto.encrypt(validData, shortKey);
1309
+ const decrypted = DyFM_Crypto.decrypt(encrypted, shortKey);
1310
+ expect(decrypted).toEqual(validData);
1311
+ });
1312
+
1313
+ it('| should allow valid data with whitespace in key', () => {
1314
+ const keyWithSpaces = ' valid-key-123 ';
1315
+ const encrypted = DyFM_Crypto.encrypt(validData, keyWithSpaces);
1316
+ const decrypted = DyFM_Crypto.decrypt(encrypted, keyWithSpaces);
1317
+ expect(decrypted).toEqual(validData);
1318
+ });
1319
+
1320
+ it('| should handle special characters in data', () => {
1321
+ const specialData = {
1322
+ special: '!@#$%^&*()_+-=[]{}|;:,.<>?',
1323
+ unicode: '世界你好',
1324
+ emoji: '🚀💻🔐'
1325
+ };
1326
+ const encrypted = DyFM_Crypto.encrypt(specialData, validKey);
1327
+ const decrypted = DyFM_Crypto.decrypt(encrypted, validKey);
1328
+ expect(decrypted).toEqual(specialData);
1329
+ });
1330
+
1331
+ it('| should handle very long data', () => {
1332
+ const longData = {
1333
+ text: 'A'.repeat(10000),
1334
+ array: Array(1000).fill(0).map((_, i) => i),
1335
+ nested: {
1336
+ level1: { level2: { level3: { data: 'deep nested data' } } }
1337
+ }
1338
+ };
1339
+ const encrypted = DyFM_Crypto.encrypt(longData, validKey);
1340
+ const decrypted = DyFM_Crypto.decrypt(encrypted, validKey);
1341
+ expect(decrypted).toEqual(longData);
1342
+ });
1343
+ });
1344
+
1345
+ describe('| Error Code Validation', () => {
1346
+ it('| should have specific error codes for different failure types', () => {
1347
+ try {
1348
+ DyFM_Crypto.encrypt(undefined, validKey);
1349
+ fail('Should have thrown an error');
1350
+ } catch (error: any) {
1351
+ expect(error._errorCode).toBe('DyFM-CRY-DATA-UNDEFINED');
1352
+ }
1353
+
1354
+ try {
1355
+ DyFM_Crypto.encrypt(validData, '');
1356
+ fail('Should have thrown an error');
1357
+ } catch (error: any) {
1358
+ expect(error._errorCode).toBe('DyFM-CRY-KEY-MISSING');
1359
+ }
1360
+
1361
+ try {
1362
+ DyFM_Crypto.decrypt('', validKey);
1363
+ fail('Should have thrown an error');
1364
+ } catch (error: any) {
1365
+ expect(error._errorCode).toBe('DyFM-CRY-ENCRYPTED-EMPTY');
1366
+ }
1367
+ });
1368
+ });
1369
+ });
897
1370
  });