@eeplatform/core 1.0.2 → 1.0.3

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.js CHANGED
@@ -11478,9 +11478,9 @@ function useVerificationRepo() {
11478
11478
  }
11479
11479
  const namespace_collection = "verifications";
11480
11480
  const collection = db.collection(namespace_collection);
11481
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils2.useCache)();
11481
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils2.useCache)(namespace_collection);
11482
11482
  function delCachedData() {
11483
- delNamespace(namespace_collection).then(() => {
11483
+ delNamespace().then(() => {
11484
11484
  import_nodejs_utils2.logger.log({
11485
11485
  level: "info",
11486
11486
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -11568,7 +11568,7 @@ function useVerificationRepo() {
11568
11568
  return cached;
11569
11569
  }
11570
11570
  const data = await collection.findOne({ _id });
11571
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
11571
+ setCache(cacheKey, data, 300).then(() => {
11572
11572
  import_nodejs_utils2.logger.log({
11573
11573
  level: "info",
11574
11574
  message: `Cache set for verification by id: ${cacheKey}`
@@ -11648,7 +11648,7 @@ function useVerificationRepo() {
11648
11648
  ]).toArray();
11649
11649
  const length = await collection.countDocuments(query);
11650
11650
  const data = (0, import_nodejs_utils2.paginate)(items, page, limit, length);
11651
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
11651
+ setCache(cacheKey, data, 600).then(() => {
11652
11652
  import_nodejs_utils2.logger.log({
11653
11653
  level: "info",
11654
11654
  message: `Cache set for getVerifications: ${cacheKey}`
@@ -11679,7 +11679,7 @@ function useVerificationRepo() {
11679
11679
  return cached;
11680
11680
  }
11681
11681
  const data = await collection.find({ type }).toArray();
11682
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
11682
+ setCache(cacheKey, data, 600).then(() => {
11683
11683
  import_nodejs_utils2.logger.log({
11684
11684
  level: "info",
11685
11685
  message: `Cache set for verification by type: ${cacheKey}`
@@ -11824,9 +11824,9 @@ function useUserRepo() {
11824
11824
  }
11825
11825
  const namespace_collection = "users";
11826
11826
  const collection = db.collection(namespace_collection);
11827
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils3.useCache)();
11827
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils3.useCache)(namespace_collection);
11828
11828
  function delCachedData() {
11829
- delNamespace(namespace_collection).then(() => {
11829
+ delNamespace().then(() => {
11830
11830
  import_nodejs_utils3.logger.log({
11831
11831
  level: "info",
11832
11832
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -11888,7 +11888,7 @@ function useUserRepo() {
11888
11888
  }
11889
11889
  const result = await collection.findOne({ email });
11890
11890
  if (result) {
11891
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
11891
+ setCache(cacheKey, result, 300).then(() => {
11892
11892
  import_nodejs_utils3.logger.log({
11893
11893
  level: "info",
11894
11894
  message: `Cache set for user by email: ${cacheKey}`
@@ -11918,7 +11918,7 @@ function useUserRepo() {
11918
11918
  }
11919
11919
  const result = await collection.findOne({ referralCode });
11920
11920
  if (result) {
11921
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
11921
+ setCache(cacheKey, result, 300).then(() => {
11922
11922
  import_nodejs_utils3.logger.log({
11923
11923
  level: "info",
11924
11924
  message: `Cache set for user by referral code: ${cacheKey}`
@@ -11953,7 +11953,7 @@ function useUserRepo() {
11953
11953
  }
11954
11954
  const result = await collection.findOne({ _id });
11955
11955
  if (result) {
11956
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
11956
+ setCache(cacheKey, result, 300).then(() => {
11957
11957
  import_nodejs_utils3.logger.log({
11958
11958
  level: "info",
11959
11959
  message: `Cache set for user by id: ${cacheKey}`
@@ -12027,7 +12027,7 @@ function useUserRepo() {
12027
12027
  ]).toArray();
12028
12028
  const length = await collection.countDocuments(query);
12029
12029
  const data = (0, import_nodejs_utils3.paginate)(items, page, limit, length);
12030
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
12030
+ setCache(cacheKey, data, 600).then(() => {
12031
12031
  import_nodejs_utils3.logger.log({
12032
12032
  level: "info",
12033
12033
  message: `Cache set for getUsers: ${cacheKey}`
@@ -12241,9 +12241,9 @@ function useMemberRepo() {
12241
12241
  }
12242
12242
  const namespace_collection = "members";
12243
12243
  const collection = db.collection(namespace_collection);
12244
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils5.useCache)();
12244
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils5.useCache)(namespace_collection);
12245
12245
  function delCachedData() {
12246
- delNamespace(namespace_collection).then(() => {
12246
+ delNamespace().then(() => {
12247
12247
  import_nodejs_utils5.logger.log({
12248
12248
  level: "info",
12249
12249
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -12334,7 +12334,7 @@ function useMemberRepo() {
12334
12334
  return cached;
12335
12335
  }
12336
12336
  const data = await collection.findOne({ _id });
12337
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
12337
+ setCache(cacheKey, data, 300).then(() => {
12338
12338
  import_nodejs_utils5.logger.log({
12339
12339
  level: "info",
12340
12340
  message: `Cache set for member by id: ${cacheKey}`
@@ -12371,7 +12371,7 @@ function useMemberRepo() {
12371
12371
  return cached;
12372
12372
  }
12373
12373
  const data = await collection.findOne({ user });
12374
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
12374
+ setCache(cacheKey, data, 300).then(() => {
12375
12375
  import_nodejs_utils5.logger.log({
12376
12376
  level: "info",
12377
12377
  message: `Cache set for member by user ID: ${cacheKey}`
@@ -12424,7 +12424,7 @@ function useMemberRepo() {
12424
12424
  return cached;
12425
12425
  }
12426
12426
  const data = await collection.findOne(query);
12427
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
12427
+ setCache(cacheKey, data, 300).then(() => {
12428
12428
  import_nodejs_utils5.logger.log({
12429
12429
  level: "info",
12430
12430
  message: `Cache set for member by user ID: ${cacheKey}`
@@ -12528,7 +12528,7 @@ function useMemberRepo() {
12528
12528
  ]).toArray();
12529
12529
  const length = await collection.countDocuments(query);
12530
12530
  const data = (0, import_nodejs_utils5.paginate)(items, page, limit, length);
12531
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
12531
+ setCache(cacheKey, data, 600).then(() => {
12532
12532
  import_nodejs_utils5.logger.log({
12533
12533
  level: "info",
12534
12534
  message: `Cache set for getAll members: ${cacheKey}`
@@ -12563,7 +12563,7 @@ function useMemberRepo() {
12563
12563
  return cached;
12564
12564
  }
12565
12565
  const data = await collection.countDocuments({ org, status: "active" });
12566
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
12566
+ setCache(cacheKey, data, 300).then(() => {
12567
12567
  import_nodejs_utils5.logger.log({
12568
12568
  level: "info",
12569
12569
  message: `Cache set for countByOrg members: ${cacheKey}`
@@ -12600,7 +12600,7 @@ function useMemberRepo() {
12600
12600
  return cached;
12601
12601
  }
12602
12602
  const data = await collection.countDocuments({ user, status: "active" });
12603
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
12603
+ setCache(cacheKey, data, 300).then(() => {
12604
12604
  import_nodejs_utils5.logger.log({
12605
12605
  level: "info",
12606
12606
  message: `Cache set for countByUser members: ${cacheKey}`
@@ -12674,7 +12674,7 @@ function useMemberRepo() {
12674
12674
  ]).toArray();
12675
12675
  const length = await collection.countDocuments(query);
12676
12676
  const data = (0, import_nodejs_utils5.paginate)(items, page, limit, length);
12677
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
12677
+ setCache(cacheKey, data, 600).then(() => {
12678
12678
  import_nodejs_utils5.logger.log({
12679
12679
  level: "info",
12680
12680
  message: `Cache set for getOrgsByMembership members: ${cacheKey}`
@@ -12752,7 +12752,7 @@ function useMemberRepo() {
12752
12752
  ]).toArray();
12753
12753
  const length = await collection.countDocuments(query);
12754
12754
  const data = (0, import_nodejs_utils5.paginate)(items, page, limit, length);
12755
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
12755
+ setCache(cacheKey, data, 300).then(() => {
12756
12756
  import_nodejs_utils5.logger.log({
12757
12757
  level: "info",
12758
12758
  message: `Cache set for getOrgsByUserId members: ${cacheKey}`
@@ -13315,9 +13315,9 @@ function useTokenRepo() {
13315
13315
  }
13316
13316
  const namespace_collection = "tokens";
13317
13317
  const collection = db.collection(namespace_collection);
13318
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils8.useCache)();
13318
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils8.useCache)(namespace_collection);
13319
13319
  function delCachedData() {
13320
- delNamespace(namespace_collection).then(() => {
13320
+ delNamespace().then(() => {
13321
13321
  import_nodejs_utils8.logger.log({
13322
13322
  level: "info",
13323
13323
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -13356,7 +13356,7 @@ function useTokenRepo() {
13356
13356
  }
13357
13357
  const data = await collection.findOne({ token });
13358
13358
  if (data) {
13359
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
13359
+ setCache(cacheKey, data, 300).then(() => {
13360
13360
  import_nodejs_utils8.logger.log({
13361
13361
  level: "info",
13362
13362
  message: `Cache set for token: ${cacheKey}`
@@ -13415,9 +13415,9 @@ function useFileRepo() {
13415
13415
  }
13416
13416
  const namespace_collection = "files";
13417
13417
  const collection = db.collection(namespace_collection);
13418
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils9.useCache)();
13418
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils9.useCache)(namespace_collection);
13419
13419
  function delCachedData() {
13420
- delNamespace(namespace_collection).then(() => {
13420
+ delNamespace().then(() => {
13421
13421
  import_nodejs_utils9.logger.log({
13422
13422
  level: "info",
13423
13423
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -13465,7 +13465,7 @@ function useFileRepo() {
13465
13465
  return cached;
13466
13466
  }
13467
13467
  const data = await collection.find({ $and: [{ status: "draft" }, { status: null }] }).toArray();
13468
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
13468
+ setCache(cacheKey, data, 300).then(() => {
13469
13469
  import_nodejs_utils9.logger.log({
13470
13470
  level: "info",
13471
13471
  message: `Cache set for getAllDraftedFiles: ${cacheKey}`
@@ -13538,6 +13538,16 @@ var isPlainObject = (val) => {
13538
13538
  const prototype3 = getPrototypeOf(val);
13539
13539
  return (prototype3 === null || prototype3 === Object.prototype || Object.getPrototypeOf(prototype3) === null) && !(toStringTag in val) && !(iterator in val);
13540
13540
  };
13541
+ var isEmptyObject = (val) => {
13542
+ if (!isObject(val) || isBuffer(val)) {
13543
+ return false;
13544
+ }
13545
+ try {
13546
+ return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
13547
+ } catch (e) {
13548
+ return false;
13549
+ }
13550
+ };
13541
13551
  var isDate = kindOfTest("Date");
13542
13552
  var isFile = kindOfTest("File");
13543
13553
  var isBlob = kindOfTest("Blob");
@@ -13565,6 +13575,9 @@ function forEach(obj, fn, { allOwnKeys = false } = {}) {
13565
13575
  fn.call(null, obj[i], i, obj);
13566
13576
  }
13567
13577
  } else {
13578
+ if (isBuffer(obj)) {
13579
+ return;
13580
+ }
13568
13581
  const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
13569
13582
  const len = keys.length;
13570
13583
  let key;
@@ -13575,6 +13588,9 @@ function forEach(obj, fn, { allOwnKeys = false } = {}) {
13575
13588
  }
13576
13589
  }
13577
13590
  function findKey(obj, key) {
13591
+ if (isBuffer(obj)) {
13592
+ return null;
13593
+ }
13578
13594
  key = key.toLowerCase();
13579
13595
  const keys = Object.keys(obj);
13580
13596
  let i = keys.length;
@@ -13771,6 +13787,9 @@ var toJSONObject = (obj) => {
13771
13787
  if (stack.indexOf(source) >= 0) {
13772
13788
  return;
13773
13789
  }
13790
+ if (isBuffer(source)) {
13791
+ return source;
13792
+ }
13774
13793
  if (!("toJSON" in source)) {
13775
13794
  stack[i] = source;
13776
13795
  const target = isArray(source) ? [] : {};
@@ -13820,6 +13839,7 @@ var utils_default = {
13820
13839
  isBoolean,
13821
13840
  isObject,
13822
13841
  isPlainObject,
13842
+ isEmptyObject,
13823
13843
  isReadableStream,
13824
13844
  isRequest,
13825
13845
  isResponse,
@@ -14264,15 +14284,16 @@ var platform_default = {
14264
14284
 
14265
14285
  // node_modules/axios/lib/helpers/toURLEncodedForm.js
14266
14286
  function toURLEncodedForm(data, options) {
14267
- return toFormData_default(data, new platform_default.classes.URLSearchParams(), Object.assign({
14287
+ return toFormData_default(data, new platform_default.classes.URLSearchParams(), {
14268
14288
  visitor: function(value, key, path, helpers) {
14269
14289
  if (platform_default.isNode && utils_default.isBuffer(value)) {
14270
14290
  this.append(key, value.toString("base64"));
14271
14291
  return false;
14272
14292
  }
14273
14293
  return helpers.defaultVisitor.apply(this, arguments);
14274
- }
14275
- }, options));
14294
+ },
14295
+ ...options
14296
+ });
14276
14297
  }
14277
14298
 
14278
14299
  // node_modules/axios/lib/helpers/formDataToJSON.js
@@ -14785,7 +14806,7 @@ var import_follow_redirects = __toESM(require_follow_redirects(), 1);
14785
14806
  var import_zlib = __toESM(require("zlib"), 1);
14786
14807
 
14787
14808
  // node_modules/axios/lib/env/data.js
14788
- var VERSION = "1.10.0";
14809
+ var VERSION = "1.11.0";
14789
14810
 
14790
14811
  // node_modules/axios/lib/helpers/parseProtocol.js
14791
14812
  function parseProtocol(url2) {
@@ -15127,7 +15148,7 @@ function throttle(fn, freq) {
15127
15148
  clearTimeout(timer);
15128
15149
  timer = null;
15129
15150
  }
15130
- fn.apply(null, args);
15151
+ fn(...args);
15131
15152
  };
15132
15153
  const throttled = (...args) => {
15133
15154
  const now = Date.now();
@@ -15802,7 +15823,7 @@ function mergeConfig(config1, config2) {
15802
15823
  validateStatus: mergeDirectKeys,
15803
15824
  headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
15804
15825
  };
15805
- utils_default.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
15826
+ utils_default.forEach(Object.keys({ ...config1, ...config2 }), function computeConfigValue(prop) {
15806
15827
  const merge2 = mergeMap[prop] || mergeDeepProperties;
15807
15828
  const configValue = merge2(config1[prop], config2[prop], prop);
15808
15829
  utils_default.isUndefined(configValue) && merge2 !== mergeDirectKeys || (config3[prop] = configValue);
@@ -16516,8 +16537,8 @@ var Axios = class {
16516
16537
  let len;
16517
16538
  if (!synchronousRequestInterceptors) {
16518
16539
  const chain = [dispatchRequest.bind(this), void 0];
16519
- chain.unshift.apply(chain, requestInterceptorChain);
16520
- chain.push.apply(chain, responseInterceptorChain);
16540
+ chain.unshift(...requestInterceptorChain);
16541
+ chain.push(...responseInterceptorChain);
16521
16542
  len = chain.length;
16522
16543
  promise = Promise.resolve(config2);
16523
16544
  while (i < len) {
@@ -17491,9 +17512,9 @@ function useRoleRepo() {
17491
17512
  }
17492
17513
  const namespace_collection = "roles";
17493
17514
  const collection = db.collection(namespace_collection);
17494
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils11.useCache)();
17515
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils11.useCache)(namespace_collection);
17495
17516
  function delCachedData() {
17496
- delNamespace(namespace_collection).then(() => {
17517
+ delNamespace().then(() => {
17497
17518
  import_nodejs_utils11.logger.log({
17498
17519
  level: "info",
17499
17520
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -17566,7 +17587,7 @@ function useRoleRepo() {
17566
17587
  return cached;
17567
17588
  }
17568
17589
  const data = await collection.findOne({ user: value });
17569
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
17590
+ setCache(cacheKey, data, 300).then(() => {
17570
17591
  import_nodejs_utils11.logger.log({
17571
17592
  level: "info",
17572
17593
  message: `Cache set for role by user ID: ${cacheKey}`
@@ -17601,7 +17622,7 @@ function useRoleRepo() {
17601
17622
  return cached;
17602
17623
  }
17603
17624
  const data = await collection.findOne({ _id });
17604
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
17625
+ setCache(cacheKey, data, 300).then(() => {
17605
17626
  import_nodejs_utils11.logger.log({
17606
17627
  level: "info",
17607
17628
  message: `Cache set for role by id: ${cacheKey}`
@@ -17634,7 +17655,7 @@ function useRoleRepo() {
17634
17655
  return cached;
17635
17656
  }
17636
17657
  const data = await collection.findOne({ name });
17637
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
17658
+ setCache(cacheKey, data, 300).then(() => {
17638
17659
  import_nodejs_utils11.logger.log({
17639
17660
  level: "info",
17640
17661
  message: `Cache set for role by name: ${cacheKey}`
@@ -17708,7 +17729,7 @@ function useRoleRepo() {
17708
17729
  ]).toArray();
17709
17730
  const length = await collection.countDocuments(query);
17710
17731
  const data = (0, import_nodejs_utils11.paginate)(items, page, limit, length);
17711
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
17732
+ setCache(cacheKey, data, 600).then(() => {
17712
17733
  import_nodejs_utils11.logger.log({
17713
17734
  level: "info",
17714
17735
  message: `Cache set for getRoles: ${cacheKey}`
@@ -18414,8 +18435,10 @@ function useUserController() {
18414
18435
  // src/services/auth.service.ts
18415
18436
  var import_nodejs_utils14 = require("@eeplatform/nodejs-utils");
18416
18437
  var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
18438
+ var import_uuid = require("uuid");
18417
18439
  function useAuthService() {
18418
18440
  const expiresIn = "1m";
18441
+ const { setCache, delCache } = (0, import_nodejs_utils14.useCache)("sessions");
18419
18442
  async function login({ email, password } = {}) {
18420
18443
  if (!email) {
18421
18444
  throw new import_nodejs_utils14.BadRequestError("Email is required");
@@ -18447,34 +18470,14 @@ function useAuthService() {
18447
18470
  if (!isPasswordValid) {
18448
18471
  throw new import_nodejs_utils14.BadRequestError("Invalid password");
18449
18472
  }
18450
- const metadata = { user: _user._id };
18451
- let refreshToken2;
18452
- try {
18453
- refreshToken2 = (0, import_nodejs_utils14.generateToken)({
18454
- secret: REFRESH_TOKEN_SECRET,
18455
- metadata,
18456
- options: { expiresIn: "7d" }
18457
- });
18458
- } catch (error) {
18459
- throw new import_nodejs_utils14.BadRequestError("Error generating refresh token");
18460
- }
18461
- let accessToken;
18462
- try {
18463
- accessToken = (0, import_nodejs_utils14.generateToken)({
18464
- secret: ACCESS_TOKEN_SECRET,
18465
- metadata,
18466
- options: { expiresIn }
18467
- });
18468
- } catch (error) {
18469
- throw new import_nodejs_utils14.BadRequestError("Error generating access token");
18470
- }
18471
- const user = _user._id ?? "";
18472
- try {
18473
- await useTokenRepo().createToken({ token: refreshToken2, user });
18474
- } catch (error) {
18475
- throw new import_nodejs_utils14.BadRequestError("Error creating refresh token");
18476
- }
18477
- return { accessToken, refreshToken: refreshToken2, id: _user._id };
18473
+ const sid = (0, import_uuid.v4)();
18474
+ const cacheKey = `sid:${sid}`;
18475
+ setCache(cacheKey, _user, 14400).then(() => {
18476
+ console.log("Session ID cached successfully");
18477
+ }).catch((error) => {
18478
+ console.error("Error caching session ID:", error);
18479
+ });
18480
+ return { sid, user: _user._id?.toString() ?? "" };
18478
18481
  }
18479
18482
  async function refreshToken(token) {
18480
18483
  let decoded;
@@ -18508,26 +18511,13 @@ function useAuthService() {
18508
18511
  }
18509
18512
  return accessToken;
18510
18513
  }
18511
- async function logout(token) {
18512
- let _token;
18513
- try {
18514
- _token = await useTokenRepo().getToken(token);
18515
- if (!_token) {
18516
- throw new import_nodejs_utils14.NotFoundError("Invalid token");
18517
- }
18518
- } catch (error) {
18519
- if (error instanceof import_nodejs_utils14.AppError) {
18520
- throw error;
18521
- } else {
18522
- throw new import_nodejs_utils14.InternalServerError(`${error}`);
18523
- }
18524
- }
18514
+ async function logout(sid) {
18525
18515
  try {
18526
- await useTokenRepo().deleteToken(token);
18516
+ await delCache(`sid:${sid}`);
18517
+ return "Session deleted successfully";
18527
18518
  } catch (error) {
18528
18519
  throw new import_nodejs_utils14.InternalServerError("Error deleting token");
18529
18520
  }
18530
- return "Logged out successfully";
18531
18521
  }
18532
18522
  return {
18533
18523
  login,
@@ -18551,16 +18541,26 @@ function useAuthController() {
18551
18541
  const { error } = validation.validate({ email, password });
18552
18542
  if (error) {
18553
18543
  next(new import_nodejs_utils15.BadRequestError(error.message));
18544
+ return;
18554
18545
  }
18555
18546
  try {
18556
- const token = await useAuthService().login({ email, password });
18557
- res.json(token);
18547
+ const session = await useAuthService().login({
18548
+ email,
18549
+ password
18550
+ });
18551
+ res.json(session);
18558
18552
  } catch (error2) {
18553
+ import_nodejs_utils15.logger.log({
18554
+ level: "error",
18555
+ message: `Error during login: ${error2.message}`
18556
+ });
18557
+ console.log(`Error during login: ${error2}`);
18559
18558
  if (error2 instanceof import_nodejs_utils15.AppError) {
18560
18559
  next(error2);
18561
18560
  } else {
18562
18561
  next(new import_nodejs_utils15.InternalServerError("An unexpected error occurred"));
18563
18562
  }
18563
+ return;
18564
18564
  }
18565
18565
  }
18566
18566
  async function refreshToken(req, res, next) {
@@ -18581,13 +18581,13 @@ function useAuthController() {
18581
18581
  }
18582
18582
  }
18583
18583
  async function logout(req, res, next) {
18584
- const token = req.params.id || "";
18585
- if (!token) {
18586
- next(new import_nodejs_utils15.BadRequestError("Token is required"));
18584
+ const sid = req.headers["authorization"] ?? "";
18585
+ if (!sid) {
18586
+ next(new import_nodejs_utils15.BadRequestError("Session ID is required"));
18587
18587
  return;
18588
18588
  }
18589
18589
  try {
18590
- await useAuthService().logout(token);
18590
+ await useAuthService().logout(sid);
18591
18591
  res.json({ message: "Logged out successfully" });
18592
18592
  } catch (error) {
18593
18593
  if (error instanceof import_nodejs_utils15.AppError) {
@@ -18983,9 +18983,9 @@ function useEntityRepo() {
18983
18983
  }
18984
18984
  const namespace_collection = "entities";
18985
18985
  const collection = db.collection(namespace_collection);
18986
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils19.useCache)();
18986
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils19.useCache)(namespace_collection);
18987
18987
  function delCachedData() {
18988
- delNamespace(namespace_collection).then(() => {
18988
+ delNamespace().then(() => {
18989
18989
  import_nodejs_utils19.logger.log({
18990
18990
  level: "info",
18991
18991
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -19065,7 +19065,7 @@ function useEntityRepo() {
19065
19065
  ]).toArray();
19066
19066
  const length = await collection.countDocuments(query);
19067
19067
  const data = (0, import_nodejs_utils19.paginate)(items, page, limit, length);
19068
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
19068
+ setCache(cacheKey, data, 600).then(() => {
19069
19069
  import_nodejs_utils19.logger.log({
19070
19070
  level: "info",
19071
19071
  message: `Cache set for getEntities: ${cacheKey}`
@@ -19342,9 +19342,9 @@ function useSubscriptionRepo() {
19342
19342
  }
19343
19343
  const namespace_collection = "subscriptions";
19344
19344
  const collection = db.collection(namespace_collection);
19345
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils22.useCache)();
19345
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils22.useCache)(namespace_collection);
19346
19346
  function delCachedData() {
19347
- delNamespace(namespace_collection).then(() => {
19347
+ delNamespace().then(() => {
19348
19348
  import_nodejs_utils22.logger.log({
19349
19349
  level: "info",
19350
19350
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -19410,7 +19410,7 @@ function useSubscriptionRepo() {
19410
19410
  }
19411
19411
  const data = await collection.findOne({ _id });
19412
19412
  if (data) {
19413
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
19413
+ setCache(cacheKey, data, 300).then(() => {
19414
19414
  import_nodejs_utils22.logger.log({
19415
19415
  level: "info",
19416
19416
  message: `Cache set for subscription by ID: ${cacheKey}`
@@ -19445,7 +19445,7 @@ function useSubscriptionRepo() {
19445
19445
  }
19446
19446
  const data = await collection.findOne({ user });
19447
19447
  if (data) {
19448
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
19448
+ setCache(cacheKey, data, 300).then(() => {
19449
19449
  import_nodejs_utils22.logger.log({
19450
19450
  level: "info",
19451
19451
  message: `Cache set for subscription by user ID: ${cacheKey}`
@@ -19505,7 +19505,7 @@ function useSubscriptionRepo() {
19505
19505
  }
19506
19506
  const data = await collection.findOne({ subscriptionId });
19507
19507
  if (data) {
19508
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
19508
+ setCache(cacheKey, data, 300).then(() => {
19509
19509
  import_nodejs_utils22.logger.log({
19510
19510
  level: "info",
19511
19511
  message: `Cache set for subscription by subscription ID: ${cacheKey}`
@@ -19561,7 +19561,7 @@ function useSubscriptionRepo() {
19561
19561
  ]).toArray();
19562
19562
  const length = await collection.countDocuments(query);
19563
19563
  const data = (0, import_nodejs_utils22.paginate)(items, page, limit, length);
19564
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
19564
+ setCache(cacheKey, data, 600).then(() => {
19565
19565
  import_nodejs_utils22.logger.log({
19566
19566
  level: "info",
19567
19567
  message: `Cache set for getSubscriptions: ${cacheKey}`
@@ -20030,7 +20030,7 @@ function useOrgRepo() {
20030
20030
  }
20031
20031
  const namespace_collection = "organizations";
20032
20032
  const collection = db.collection(namespace_collection);
20033
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils24.useCache)();
20033
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils24.useCache)(namespace_collection);
20034
20034
  async function createIndex() {
20035
20035
  try {
20036
20036
  await collection.createIndex([
@@ -20065,7 +20065,7 @@ function useOrgRepo() {
20065
20065
  }
20066
20066
  }
20067
20067
  function delCachedData() {
20068
- delNamespace(namespace_collection).then(() => {
20068
+ delNamespace().then(() => {
20069
20069
  import_nodejs_utils24.logger.log({
20070
20070
  level: "info",
20071
20071
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -20149,7 +20149,7 @@ function useOrgRepo() {
20149
20149
  ]).toArray();
20150
20150
  const length = await collection.countDocuments(query);
20151
20151
  const data = (0, import_nodejs_utils24.paginate)(items, page, limit, length);
20152
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
20152
+ setCache(cacheKey, data, 600).then(() => {
20153
20153
  import_nodejs_utils24.logger.log({
20154
20154
  level: "info",
20155
20155
  message: `Cache set for getAll organizations: ${cacheKey}`
@@ -20186,7 +20186,7 @@ function useOrgRepo() {
20186
20186
  if (!result) {
20187
20187
  throw new import_nodejs_utils24.BadRequestError("Organization not found.");
20188
20188
  }
20189
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
20189
+ setCache(cacheKey, result, 300).then(() => {
20190
20190
  import_nodejs_utils24.logger.log({
20191
20191
  level: "info",
20192
20192
  message: `Cache set for organization by id: ${cacheKey}`
@@ -20221,7 +20221,7 @@ function useOrgRepo() {
20221
20221
  if (!result) {
20222
20222
  throw new import_nodejs_utils24.BadRequestError("Organization not found.");
20223
20223
  }
20224
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
20224
+ setCache(cacheKey, result, 300).then(() => {
20225
20225
  import_nodejs_utils24.logger.log({
20226
20226
  level: "info",
20227
20227
  message: `Cache set for organization by name: ${cacheKey}`
@@ -20353,9 +20353,9 @@ function useAddressRepo() {
20353
20353
  }
20354
20354
  const namespace_collection = "addresses";
20355
20355
  const collection = db.collection(namespace_collection);
20356
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils26.useCache)();
20356
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils26.useCache)(namespace_collection);
20357
20357
  function delCachedData() {
20358
- delNamespace(namespace_collection).then(() => {
20358
+ delNamespace().then(() => {
20359
20359
  import_nodejs_utils26.logger.log({
20360
20360
  level: "info",
20361
20361
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -20431,7 +20431,7 @@ function useAddressRepo() {
20431
20431
  }
20432
20432
  const data = await collection.findOne({ user });
20433
20433
  if (data) {
20434
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
20434
+ setCache(cacheKey, data, 300).then(() => {
20435
20435
  import_nodejs_utils26.logger.log({
20436
20436
  level: "info",
20437
20437
  message: `Cache set for address by user ID: ${cacheKey}`
@@ -20466,7 +20466,7 @@ function useAddressRepo() {
20466
20466
  }
20467
20467
  const data = await collection.findOne({ org });
20468
20468
  if (data) {
20469
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
20469
+ setCache(cacheKey, data, 300).then(() => {
20470
20470
  import_nodejs_utils26.logger.log({
20471
20471
  level: "info",
20472
20472
  message: `Cache set for address by org ID: ${cacheKey}`
@@ -20552,9 +20552,9 @@ function usePromoCodeRepo() {
20552
20552
  }
20553
20553
  const namespace_collection = "promo-codes";
20554
20554
  const collection = db.collection(namespace_collection);
20555
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils28.useCache)();
20555
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils28.useCache)(namespace_collection);
20556
20556
  function delCachedData() {
20557
- delNamespace(namespace_collection).then(() => {
20557
+ delNamespace().then(() => {
20558
20558
  import_nodejs_utils28.logger.log({
20559
20559
  level: "info",
20560
20560
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -20634,7 +20634,7 @@ function usePromoCodeRepo() {
20634
20634
  }
20635
20635
  const data = await collection.findOne(query);
20636
20636
  if (data) {
20637
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
20637
+ setCache(cacheKey, data, 300).then(() => {
20638
20638
  import_nodejs_utils28.logger.log({
20639
20639
  level: "info",
20640
20640
  message: `Cache set for promo code by code: ${cacheKey}`
@@ -20676,7 +20676,7 @@ function usePromoCodeRepo() {
20676
20676
  }
20677
20677
  const data = await collection.findOne({ _id });
20678
20678
  if (data) {
20679
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
20679
+ setCache(cacheKey, data, 300).then(() => {
20680
20680
  import_nodejs_utils28.logger.log({
20681
20681
  level: "info",
20682
20682
  message: `Cache set for promo code by ID: ${cacheKey}`
@@ -20735,7 +20735,7 @@ function usePromoCodeRepo() {
20735
20735
  ]).toArray();
20736
20736
  const length = await collection.countDocuments(query);
20737
20737
  const data = (0, import_nodejs_utils28.paginate)(items, page, limit, length);
20738
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
20738
+ setCache(cacheKey, data, 600).then(() => {
20739
20739
  import_nodejs_utils28.logger.log({
20740
20740
  level: "info",
20741
20741
  message: `Cache set for getPromoCodes: ${cacheKey}`
@@ -21101,9 +21101,9 @@ function useCounterRepo() {
21101
21101
  }
21102
21102
  const namespace_collection = "counters";
21103
21103
  const { collection, createCounter } = useCounterModel(db);
21104
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils32.useCache)();
21104
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils32.useCache)(namespace_collection);
21105
21105
  function delCachedData() {
21106
- delNamespace(namespace_collection).then(() => {
21106
+ delNamespace().then(() => {
21107
21107
  import_nodejs_utils32.logger.log({
21108
21108
  level: "info",
21109
21109
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -21173,7 +21173,7 @@ function useCounterRepo() {
21173
21173
  }
21174
21174
  const data = await collection.findOne({ type });
21175
21175
  if (data) {
21176
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
21176
+ setCache(cacheKey, data, 300).then(() => {
21177
21177
  import_nodejs_utils32.logger.log({
21178
21178
  level: "info",
21179
21179
  message: `Cache set for counter by type: ${cacheKey}`
@@ -21366,9 +21366,9 @@ function usePriceRepo() {
21366
21366
  }
21367
21367
  const namespace_collection = "prices";
21368
21368
  const { collection, createPrice } = usePriceModel(db);
21369
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils35.useCache)();
21369
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils35.useCache)(namespace_collection);
21370
21370
  function delCachedData() {
21371
- delNamespace(namespace_collection).then(() => {
21371
+ delNamespace().then(() => {
21372
21372
  import_nodejs_utils35.logger.log({
21373
21373
  level: "info",
21374
21374
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -21438,7 +21438,7 @@ function usePriceRepo() {
21438
21438
  }
21439
21439
  const data = await collection.findOne({ name, type });
21440
21440
  if (data) {
21441
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
21441
+ setCache(cacheKey, data, 300).then(() => {
21442
21442
  import_nodejs_utils35.logger.log({
21443
21443
  level: "info",
21444
21444
  message: `Cache set for price by name and type: ${cacheKey}`
@@ -24691,9 +24691,9 @@ function useOrderRepo() {
24691
24691
  }
24692
24692
  const namespace_collection = "orders";
24693
24693
  const collection = db.collection(namespace_collection);
24694
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils49.useCache)();
24694
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils49.useCache)(namespace_collection);
24695
24695
  function delCachedData() {
24696
- delNamespace(namespace_collection).then(() => {
24696
+ delNamespace().then(() => {
24697
24697
  import_nodejs_utils49.logger.log({
24698
24698
  level: "info",
24699
24699
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -24780,7 +24780,7 @@ function useOrderRepo() {
24780
24780
  ]).toArray();
24781
24781
  const length = await collection.countDocuments(query);
24782
24782
  const data = (0, import_nodejs_utils49.paginate)(items, page, limit, length);
24783
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
24783
+ setCache(cacheKey, data, 600).then(() => {
24784
24784
  import_nodejs_utils49.logger.log({
24785
24785
  level: "info",
24786
24786
  message: `Cache set for getOrders: ${cacheKey}`
@@ -25330,7 +25330,7 @@ function useRegionRepo() {
25330
25330
  }
25331
25331
  const namespace_collection = "regions";
25332
25332
  const collection = db.collection(namespace_collection);
25333
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils56.useCache)();
25333
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils56.useCache)(namespace_collection);
25334
25334
  async function createIndex() {
25335
25335
  try {
25336
25336
  await collection.createIndex([
@@ -25367,7 +25367,7 @@ function useRegionRepo() {
25367
25367
  }
25368
25368
  }
25369
25369
  function delCachedData() {
25370
- delNamespace(namespace_collection).then(() => {
25370
+ delNamespace().then(() => {
25371
25371
  import_nodejs_utils56.logger.log({
25372
25372
  level: "info",
25373
25373
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -25445,7 +25445,7 @@ function useRegionRepo() {
25445
25445
  ]).toArray();
25446
25446
  const length = await collection.countDocuments(query);
25447
25447
  const data = (0, import_nodejs_utils56.paginate)(items, page, limit, length);
25448
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
25448
+ setCache(cacheKey, data, 600).then(() => {
25449
25449
  import_nodejs_utils56.logger.log({
25450
25450
  level: "info",
25451
25451
  message: `Cache set for getAll regions: ${cacheKey}`
@@ -25485,7 +25485,7 @@ function useRegionRepo() {
25485
25485
  if (!result) {
25486
25486
  throw new import_nodejs_utils56.BadRequestError("Region not found.");
25487
25487
  }
25488
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
25488
+ setCache(cacheKey, result, 300).then(() => {
25489
25489
  import_nodejs_utils56.logger.log({
25490
25490
  level: "info",
25491
25491
  message: `Cache set for region by id: ${cacheKey}`
@@ -25523,7 +25523,7 @@ function useRegionRepo() {
25523
25523
  if (!result) {
25524
25524
  throw new import_nodejs_utils56.BadRequestError("Region not found.");
25525
25525
  }
25526
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
25526
+ setCache(cacheKey, result, 300).then(() => {
25527
25527
  import_nodejs_utils56.logger.log({
25528
25528
  level: "info",
25529
25529
  message: `Cache set for region by name: ${cacheKey}`
@@ -25860,7 +25860,7 @@ function useDivisionRepo() {
25860
25860
  }
25861
25861
  const namespace_collection = "divisions";
25862
25862
  const collection = db.collection(namespace_collection);
25863
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils60.useCache)();
25863
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils60.useCache)(namespace_collection);
25864
25864
  async function createIndex() {
25865
25865
  try {
25866
25866
  await collection.createIndex([
@@ -25899,7 +25899,7 @@ function useDivisionRepo() {
25899
25899
  }
25900
25900
  }
25901
25901
  function delCachedData() {
25902
- delNamespace(namespace_collection).then(() => {
25902
+ delNamespace().then(() => {
25903
25903
  import_nodejs_utils60.logger.log({
25904
25904
  level: "info",
25905
25905
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -25993,7 +25993,7 @@ function useDivisionRepo() {
25993
25993
  ]).toArray();
25994
25994
  const length = await collection.countDocuments(query);
25995
25995
  const data = (0, import_nodejs_utils60.paginate)(items, page, limit, length);
25996
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
25996
+ setCache(cacheKey, data, 600).then(() => {
25997
25997
  import_nodejs_utils60.logger.log({
25998
25998
  level: "info",
25999
25999
  message: `Cache set for getAll divisions: ${cacheKey}`
@@ -26033,7 +26033,7 @@ function useDivisionRepo() {
26033
26033
  if (!result) {
26034
26034
  throw new import_nodejs_utils60.BadRequestError("Division not found.");
26035
26035
  }
26036
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
26036
+ setCache(cacheKey, result, 300).then(() => {
26037
26037
  import_nodejs_utils60.logger.log({
26038
26038
  level: "info",
26039
26039
  message: `Cache set for division by id: ${cacheKey}`
@@ -26071,7 +26071,7 @@ function useDivisionRepo() {
26071
26071
  if (!result) {
26072
26072
  throw new import_nodejs_utils60.BadRequestError("Division not found.");
26073
26073
  }
26074
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
26074
+ setCache(cacheKey, result, 300).then(() => {
26075
26075
  import_nodejs_utils60.logger.log({
26076
26076
  level: "info",
26077
26077
  message: `Cache set for division by name: ${cacheKey}`
@@ -26454,9 +26454,9 @@ function useSchoolRepo() {
26454
26454
  }
26455
26455
  const namespace_collection = "schools";
26456
26456
  const collection = db.collection(namespace_collection);
26457
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils63.useCache)();
26457
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils63.useCache)(namespace_collection);
26458
26458
  function delCachedData() {
26459
- delNamespace(namespace_collection).then(() => {
26459
+ delNamespace().then(() => {
26460
26460
  import_nodejs_utils63.logger.log({
26461
26461
  level: "info",
26462
26462
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -26556,7 +26556,7 @@ function useSchoolRepo() {
26556
26556
  ]).toArray();
26557
26557
  const length = await collection.countDocuments(query);
26558
26558
  const data = (0, import_nodejs_utils63.paginate)(items, page, limit, length);
26559
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
26559
+ setCache(cacheKey, data, 600).then(() => {
26560
26560
  import_nodejs_utils63.logger.log({
26561
26561
  level: "info",
26562
26562
  message: `Cache set for key ${cacheKey}`
@@ -26647,7 +26647,7 @@ function useSchoolRepo() {
26647
26647
  }
26648
26648
  try {
26649
26649
  const school = await collection.findOne({ createdBy, status: "pending" });
26650
- setCache(cacheKey, school, 600, namespace_collection).then(() => {
26650
+ setCache(cacheKey, school, 600).then(() => {
26651
26651
  import_nodejs_utils63.logger.log({
26652
26652
  level: "info",
26653
26653
  message: `Cache set for school by createdBy: ${cacheKey}`
@@ -26679,7 +26679,7 @@ function useSchoolRepo() {
26679
26679
  }
26680
26680
  try {
26681
26681
  const school = await collection.findOne({ _id, status: "pending" });
26682
- setCache(cacheKey, school, 600, namespace_collection).then(() => {
26682
+ setCache(cacheKey, school, 600).then(() => {
26683
26683
  import_nodejs_utils63.logger.log({
26684
26684
  level: "info",
26685
26685
  message: `Cache set for school by ID: ${cacheKey}`