@positivegrid/pg-mongoose-schema 28.0.0-beta.3 → 28.0.0-beta.4

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.mjs CHANGED
@@ -1,15 +1,14 @@
1
- import debug from "debug";
2
- import _ from "lodash";
1
+ import { debuglog } from "node:util";
2
+ import { has, isEmpty, isPlainObject, isString, merge, orderBy } from "es-toolkit/compat";
3
3
  import mongooseLeanVirtuals from "mongoose-lean-virtuals";
4
+ import { difference, intersection, omit } from "es-toolkit";
4
5
  import deepPopulateFactory from "mongoose-deep-populate";
6
+ import { isValid, subMonths } from "date-fns";
5
7
  import isSubset from "is-subset";
6
- import moment from "moment";
7
8
  import crypto from "node:crypto";
8
- import { ApiErrorCode } from "@positivegrid/pg-error";
9
9
  import isEmail from "is-email";
10
10
  import randomString from "random-string";
11
11
  //#region src/models/banks.ts
12
- debug("model:banks");
13
12
  function buildBanks(mongoose) {
14
13
  const { Schema } = mongoose;
15
14
  const ObjectId = Schema.Types.ObjectId;
@@ -291,7 +290,10 @@ function buildFeaturedList(mongoose) {
291
290
  is_shown: true,
292
291
  list_for: "jamup"
293
292
  };
294
- const queryObj = _.has(reqQuery, "list_for") ? _.assign({}, defaultQuery, { list_for: reqQuery.list_for }) : defaultQuery;
293
+ const queryObj = has(reqQuery, "list_for") ? {
294
+ ...defaultQuery,
295
+ list_for: reqQuery.list_for
296
+ } : defaultQuery;
295
297
  return this.find(queryObj).sort({ order: 1 }).select("-is_shown").lean({ virtuals: true }).exec();
296
298
  },
297
299
  getLimitedPresetLists(reqQuery) {
@@ -300,7 +302,10 @@ function buildFeaturedList(mongoose) {
300
302
  is_shown: true,
301
303
  list_for: "jamup"
302
304
  };
303
- const queryObj = _.has(reqQuery, "list_for") ? _.assign({}, defaultQuery, { list_for: reqQuery.list_for }) : defaultQuery;
305
+ const queryObj = has(reqQuery, "list_for") ? {
306
+ ...defaultQuery,
307
+ list_for: reqQuery.list_for
308
+ } : defaultQuery;
304
309
  return this.find(queryObj).sort({ order: 1 }).select("-is_shown").lean({ virtuals: true }).exec();
305
310
  }
306
311
  });
@@ -314,7 +319,7 @@ function buildFeaturedList(mongoose) {
314
319
  }
315
320
  //#endregion
316
321
  //#region src/models/hardware.ts
317
- const log$7 = debug("model:promo");
322
+ const log$7 = debuglog("model:promo");
318
323
  function _identifyHardwareByModel(model) {
319
324
  switch (model) {
320
325
  case "G1": return "head";
@@ -325,7 +330,7 @@ function _identifyHardwareByModel(model) {
325
330
  }
326
331
  }
327
332
  function _parseHardwareSerialNumber(hwSn) {
328
- if (!_.isString(hwSn)) throw new Error(`Invalid hardware series number format: ${hwSn}`);
333
+ if (typeof hwSn !== "string") throw new Error(`Invalid hardware series number format: ${hwSn}`);
329
334
  if (/^S/.test(hwSn)) {
330
335
  const hwModel = hwSn.slice(0, 1);
331
336
  const hwWattage = hwSn.slice(1, 4);
@@ -630,15 +635,15 @@ function buildHardware(mongoose) {
630
635
  let mostMatchingMeta = {};
631
636
  let mostMatchingNumber = 0;
632
637
  allMatch.forEach((metaItem) => {
633
- if (_.isArray(metaItem.pattern) && metaItem.pattern.length > 0) {
634
- const matchItem = _.intersection(metaItem.pattern, snPatternArr);
638
+ if (Array.isArray(metaItem.pattern) && metaItem.pattern.length > 0) {
639
+ const matchItem = intersection(metaItem.pattern, snPatternArr);
635
640
  if (matchItem.length === metaItem.pattern.length && matchItem.length > mostMatchingNumber) {
636
641
  mostMatchingMeta = metaItem;
637
642
  mostMatchingNumber = matchItem.length;
638
643
  }
639
644
  }
640
645
  });
641
- if (_.isEmpty(mostMatchingMeta) || mostMatchingNumber === 0) {
646
+ if (isEmpty(mostMatchingMeta) || mostMatchingNumber === 0) {
642
647
  if (opts.allowEmpty === true) return null;
643
648
  throw new Error("Cannot find any activation meta match the SN pattern");
644
649
  }
@@ -879,7 +884,7 @@ function buildOauth(mongoose) {
879
884
  }
880
885
  //#endregion
881
886
  //#region src/models/partner.ts
882
- const log$6 = debug("model:partner");
887
+ const log$6 = debuglog("model:partner");
883
888
  const OEM_PROMOTION_TYPE = ["discount_coupon"];
884
889
  function _identifyItemTypeBySku(sku) {
885
890
  if (/^B(.*)/.test(sku)) return "bundle";
@@ -1216,8 +1221,8 @@ function buildPartner(mongoose) {
1216
1221
  });
1217
1222
  OemRedeemPromotionSchema.static({ async findRedeemFullfillPromotion(redeemData) {
1218
1223
  try {
1219
- if (!_.has(redeemData, "metadata.OEM_Name")) throw new Error("This is not a OEM redeem code.");
1220
- if (!_.has(redeemData, "metadata.product_name") || !_.has(redeemData, "metadata.type")) throw new Error("This is not a valid redeem code.");
1224
+ if (!has(redeemData, "metadata.OEM_Name")) throw new Error("This is not a OEM redeem code.");
1225
+ if (!has(redeemData, "metadata.product_name") || !has(redeemData, "metadata.type")) throw new Error("This is not a valid redeem code.");
1221
1226
  return this.find({
1222
1227
  redeem_product: redeemData.metadata.product_name,
1223
1228
  product_type: redeemData.metadata.type,
@@ -1241,7 +1246,7 @@ function buildPartner(mongoose) {
1241
1246
  }
1242
1247
  //#endregion
1243
1248
  //#region src/models/payment.ts
1244
- const log$5 = debug("model:payment");
1249
+ const log$5 = debuglog("model:payment");
1245
1250
  const OEM_FOCUSRITE_SUPPORT_LICENSE = [
1246
1251
  {
1247
1252
  support_type: {
@@ -1283,13 +1288,13 @@ function _oemMetaToLicenseName(redeemMeta) {
1283
1288
  let ret;
1284
1289
  switch (redeemMeta.OEM_Name) {
1285
1290
  case "focusrite":
1286
- ret = _.find(OEM_FOCUSRITE_SUPPORT_LICENSE, (o) => isSubset(redeemMeta, o.support_type));
1291
+ ret = OEM_FOCUSRITE_SUPPORT_LICENSE.find((o) => isSubset(redeemMeta, o.support_type));
1287
1292
  break;
1288
1293
  case "Apogee":
1289
- ret = _.find(OEM_APOGEE_SUPPORT_LICENSE, (o) => isSubset(redeemMeta, o.support_type));
1294
+ ret = OEM_APOGEE_SUPPORT_LICENSE.find((o) => isSubset(redeemMeta, o.support_type));
1290
1295
  break;
1291
1296
  case "ProSonus":
1292
- ret = _.find(OEM_PROSONUS_SUPPORT_LICENSE, (o) => isSubset(redeemMeta, o.support_type));
1297
+ ret = OEM_PROSONUS_SUPPORT_LICENSE.find((o) => isSubset(redeemMeta, o.support_type));
1293
1298
  break;
1294
1299
  default:
1295
1300
  log$5("ERROR:_oemMetaToLicenseName %o", redeemMeta);
@@ -1957,16 +1962,16 @@ function buildPayment(mongoose) {
1957
1962
  AdditionalPurchaseSchema.index({ exclude_country: 1 });
1958
1963
  AdditionalPurchaseSchema.static({
1959
1964
  async canPurchaseAdditional(ownedSku, additionalSku) {
1960
- if (!_.isArray(ownedSku) || !_.isArray(additionalSku)) throw new Error("Invalid parameter format!");
1965
+ if (!Array.isArray(ownedSku) || !Array.isArray(additionalSku)) throw new Error("Invalid parameter format!");
1961
1966
  const additionalPurchaseData = await this.find({
1962
1967
  "additional_purchase.sku": { $in: additionalSku },
1963
1968
  status: 1
1964
1969
  }).exec();
1965
1970
  if (additionalPurchaseData.length <= 0) return true;
1966
1971
  let canPurchase = false;
1967
- _.forEach(additionalPurchaseData, (addition) => {
1972
+ additionalPurchaseData.forEach((addition) => {
1968
1973
  if (addition.rule === "has") {
1969
- if (_.difference(ownedSku, addition.main_product_sku).length < ownedSku.length) canPurchase = true;
1974
+ if (difference(ownedSku, addition.main_product_sku).length < ownedSku.length) canPurchase = true;
1970
1975
  }
1971
1976
  });
1972
1977
  return canPurchase;
@@ -1978,10 +1983,10 @@ function buildPayment(mongoose) {
1978
1983
  }).lean().exec();
1979
1984
  if (hasAdditionalPurchase.length <= 0) return true;
1980
1985
  let hasFulfill = true;
1981
- _.forEach(hasAdditionalPurchase, (addition) => {
1986
+ hasAdditionalPurchase.forEach((addition) => {
1982
1987
  if (addition.rule === "has") {
1983
1988
  const mainSkus = addition.main_product_sku;
1984
- if (_.difference(mainSkus, skus).length >= mainSkus.length) hasFulfill = false;
1989
+ if (difference(mainSkus, skus).length >= mainSkus.length) hasFulfill = false;
1985
1990
  }
1986
1991
  });
1987
1992
  return hasFulfill;
@@ -2017,7 +2022,7 @@ function buildPayment(mongoose) {
2017
2022
  }, { collection: "cn_sales_meta" });
2018
2023
  CnSalesMetaSchema.static({ async getAllSaleItems(query = {}) {
2019
2024
  try {
2020
- const queryCondition = _.isObject(query) && _.isEmpty(query) ? { status: 1 } : query;
2025
+ const queryCondition = typeof query === "object" && query !== null && isEmpty(query) ? { status: 1 } : query;
2021
2026
  return await this.aggregate().match(queryCondition).lookup({
2022
2027
  from: "jamup_product",
2023
2028
  localField: "product_id",
@@ -2255,11 +2260,12 @@ function buildPayment(mongoose) {
2255
2260
  }).sort({ created_on: -1 }).populate("product_id").exec();
2256
2261
  },
2257
2262
  getUserLicense(query, cb) {
2258
- if (!_.isObject(query)) return cb(/* @__PURE__ */ new Error("Given query params should be a object"));
2259
- const queryObj = _.assign({}, query, {
2263
+ if (typeof query !== "object" || query === null) return cb(/* @__PURE__ */ new Error("Given query params should be a object"));
2264
+ const queryObj = {
2265
+ ...query,
2260
2266
  status: { $in: [1, 4] },
2261
2267
  $or: [{ due_date: null }, { due_date: { $gt: /* @__PURE__ */ new Date() } }]
2262
- });
2268
+ };
2263
2269
  this.find(queryObj).sort({ created_on: -1 }).populate("product_id", "id name price product_type status version addition extra_payment_fields").then((licenses) => {
2264
2270
  if (!Array.isArray(licenses)) return cb(/* @__PURE__ */ new Error("Invalid data format"));
2265
2271
  const result = [];
@@ -2270,13 +2276,14 @@ function buildPayment(mongoose) {
2270
2276
  }, (err) => cb(err));
2271
2277
  },
2272
2278
  async getUserLicensePromise(query) {
2273
- if (!_.isObject(query)) throw new Error("Given query params should be a object");
2274
- const queryObj = _.assign({}, query, {
2279
+ if (typeof query !== "object" || query === null) throw new Error("Given query params should be a object");
2280
+ const queryObj = {
2281
+ ...query,
2275
2282
  status: { $in: [1, 4] },
2276
2283
  $or: [{ due_date: null }, { due_date: { $gt: /* @__PURE__ */ new Date() } }]
2277
- });
2284
+ };
2278
2285
  const licenseData = await this.find(queryObj).sort({ created_on: -1 }).populate("product_id", "id name price product_type status version addition extra_payment_fields").exec();
2279
- if (!_.isArray(licenseData)) throw new Error("Invalid license data");
2286
+ if (!Array.isArray(licenseData)) throw new Error("Invalid license data");
2280
2287
  const result = [];
2281
2288
  licenseData.forEach((item) => {
2282
2289
  if (item.product_id) result.push(item);
@@ -2284,23 +2291,25 @@ function buildPayment(mongoose) {
2284
2291
  return result;
2285
2292
  },
2286
2293
  getUserPurchase(query, productType, cb) {
2287
- if (!_.isObject(query)) return cb(/* @__PURE__ */ new Error("Given query params should be a object"));
2294
+ if (typeof query !== "object" || query === null) return cb(/* @__PURE__ */ new Error("Given query params should be a object"));
2288
2295
  const populateProductList = productType === "pack" ? "id name product_type display_name extra_payment_fields created_on" : "id name price product_type display_name status version addition";
2289
- const queryObj = _.assign({}, query, {
2296
+ const queryObj = {
2297
+ ...query,
2290
2298
  status: { $in: [1, 4] },
2291
2299
  $or: [{ due_date: null }, { due_date: { $gt: /* @__PURE__ */ new Date() } }]
2292
- });
2300
+ };
2293
2301
  this.find(queryObj).sort({ created_on: -1 }).populate("product_id", populateProductList).then((docs) => cb(null, docs), (err) => cb(err));
2294
2302
  },
2295
2303
  async getUserPurchasePromise(query, productType, opts) {
2296
- if (!_.isObject(query)) throw new Error("Given query params should be a object");
2304
+ if (typeof query !== "object" || query === null) throw new Error("Given query params should be a object");
2297
2305
  const populateProductList = productType === "pack" ? "id name sku product_type display_name extra_payment_fields created_on" : "id name sku product_type display_name addition created_on";
2298
- const freeTrialQuery = productType === "free_trial" ? { $and: [{ from_free_trial: { $ne: null } }, { from_free_trial: { $exists: true } }] } : { $or: [{ from_free_trial: null }, { from_free_trial: { $exists: false } }] };
2299
- const queryObj = _.assign({}, {
2306
+ const queryObj = {
2300
2307
  status: { $in: [1, 4] },
2301
- $or: [{ due_date: null }, { due_date: { $gt: /* @__PURE__ */ new Date() } }]
2302
- }, freeTrialQuery, query);
2303
- if (_.has(opts, "isLean") && opts.isLean === true) return this.find(queryObj).sort({ created_on: -1 }).populate("product_id", populateProductList).lean({ virtuals: true }).exec();
2308
+ $or: [{ due_date: null }, { due_date: { $gt: /* @__PURE__ */ new Date() } }],
2309
+ ...productType === "free_trial" ? { $and: [{ from_free_trial: { $ne: null } }, { from_free_trial: { $exists: true } }] } : { $or: [{ from_free_trial: null }, { from_free_trial: { $exists: false } }] },
2310
+ ...query
2311
+ };
2312
+ if (opts?.isLean === true) return this.find(queryObj).sort({ created_on: -1 }).populate("product_id", populateProductList).lean({ virtuals: true }).exec();
2304
2313
  return this.find(queryObj).sort({ created_on: -1 }).populate("product_id", populateProductList).exec();
2305
2314
  },
2306
2315
  async getUserIapLicenses(userId, iapIds) {
@@ -2336,11 +2345,13 @@ function buildPayment(mongoose) {
2336
2345
  },
2337
2346
  async createTrialLicense(data) {
2338
2347
  try {
2339
- if (!_.has(data, "due_date") || !moment(data.due_date).isValid()) throw new Error("Invalid trail license format!");
2340
- return await this.create(_.assign({}, data, {
2348
+ const dueDate = new Date(data.due_date);
2349
+ if (!Object.hasOwn(data, "due_date") || !isValid(dueDate)) throw new Error("Invalid trail license format!");
2350
+ return await this.create({
2351
+ ...data,
2341
2352
  status: 4,
2342
- due_date: moment(data.due_date).toDate()
2343
- }));
2353
+ due_date: dueDate
2354
+ });
2344
2355
  } catch (err) {
2345
2356
  log$5("ERR:createTrialLicense:%o", err);
2346
2357
  throw err;
@@ -2496,11 +2507,14 @@ function buildPgConfig(mongoose) {
2496
2507
  const that = this;
2497
2508
  let realCb = cb;
2498
2509
  let realMerge;
2499
- if (_.isFunction(doMerge)) realCb = doMerge;
2510
+ if (typeof doMerge === "function") realCb = doMerge;
2500
2511
  else realMerge = doMerge;
2501
2512
  that.findOne({ config_key: key }).then((config) => {
2502
2513
  if (config) {
2503
- config.config_value = _.isBoolean(realMerge) && realMerge === true ? _.assign({}, config.config_value, value) : value;
2514
+ config.config_value = realMerge === true ? {
2515
+ ...config.config_value,
2516
+ ...value
2517
+ } : value;
2504
2518
  config.created_on = /* @__PURE__ */ new Date();
2505
2519
  config.save().then((saved) => realCb(null, saved), (err) => realCb(err));
2506
2520
  } else that.create({
@@ -2525,12 +2539,18 @@ function buildPgConfig(mongoose) {
2525
2539
  }
2526
2540
  //#endregion
2527
2541
  //#region src/models/preset.ts
2528
- const log$4 = debug("model:preset");
2542
+ const log$4 = debuglog("model:preset");
2529
2543
  function _queryCompatibilityHandler(query) {
2530
2544
  let formatQuery = {};
2531
- if (_.has(query, "preset_for") && query.preset_for === "amp2") formatQuery = _.assign({}, query, { preset_for: { $in: ["amp2", "bias"] } });
2532
- else if (!_.has(query, "preset_for") || query.preset_for === "") formatQuery = _.assign({}, query, { preset_for: "jamup" });
2533
- if (_.isEmpty(formatQuery)) formatQuery = _.clone(query);
2545
+ if (has(query, "preset_for") && query.preset_for === "amp2") formatQuery = {
2546
+ ...query,
2547
+ preset_for: { $in: ["amp2", "bias"] }
2548
+ };
2549
+ else if (!has(query, "preset_for") || query.preset_for === "") formatQuery = {
2550
+ ...query,
2551
+ preset_for: "jamup"
2552
+ };
2553
+ if (isEmpty(formatQuery)) formatQuery = { ...query };
2534
2554
  return formatQuery;
2535
2555
  }
2536
2556
  function _handlePresetVersion(queryObj, req) {
@@ -2542,15 +2562,15 @@ function _handlePresetVersion(queryObj, req) {
2542
2562
  "lte",
2543
2563
  "ne"
2544
2564
  ];
2545
- if (!_.has(req.query, "preset_for") || _.has(req.query, "preset_for") && req.query.preset_for !== "live") return _.clone(queryObj);
2546
- else if (_.has(req.query, "preset_version") && _.has(req.query, "version_comparison")) {
2547
- if (_.indexOf(supportVersionComparison, req.query.version_comparison) !== -1) {
2548
- const tmpVersionQuery = _.clone(queryObj);
2565
+ if (!has(req.query, "preset_for") || has(req.query, "preset_for") && req.query.preset_for !== "live") return { ...queryObj };
2566
+ else if (has(req.query, "preset_version") && has(req.query, "version_comparison")) {
2567
+ if (supportVersionComparison.indexOf(req.query.version_comparison) !== -1) {
2568
+ const tmpVersionQuery = { ...queryObj };
2549
2569
  const versionQuery = _buildPresetVersionQuery(req.query.preset_version, req.query.version_comparison);
2550
- if (versionQuery) return _.merge(tmpVersionQuery, versionQuery);
2570
+ if (versionQuery) return merge(tmpVersionQuery, versionQuery);
2551
2571
  }
2552
2572
  }
2553
- return _.clone(queryObj);
2573
+ return { ...queryObj };
2554
2574
  }
2555
2575
  function _buildPresetVersionQuery(version, comparison) {
2556
2576
  const tmpAttrs = String(version).split(".");
@@ -2584,7 +2604,7 @@ function _buildLicenseTierQuery(licenseTierParam) {
2584
2604
  const tmpData = /* @__PURE__ */ new Set();
2585
2605
  const expansionData = /* @__PURE__ */ new Set();
2586
2606
  const allExpansion = new Set(["celestion", "classic"]);
2587
- _.forEach(tmpLicenseTier, (lic) => {
2607
+ tmpLicenseTier.forEach((lic) => {
2588
2608
  switch (lic) {
2589
2609
  case "celestion":
2590
2610
  case "classic":
@@ -2615,7 +2635,7 @@ function _buildLicenseTierQuery(licenseTierParam) {
2615
2635
  });
2616
2636
  return expansionData.size > 0 ? { $and: [
2617
2637
  { license_tier: { $in: Array.from(tmpData) } },
2618
- { license_tier: { $in: _.concat(Array.from(tmpData), Array.from(expansionData)) } },
2638
+ { license_tier: { $in: [...Array.from(tmpData), ...Array.from(expansionData)] } },
2619
2639
  { license_tier: { $nin: Array.from(allExpansion) } }
2620
2640
  ] } : { $and: [{ license_tier: { $in: Array.from(tmpData) } }, { license_tier: { $nin: Array.from(allExpansion) } }] };
2621
2641
  }
@@ -2624,13 +2644,13 @@ function _parsePageParams(data) {
2624
2644
  page_size: 12,
2625
2645
  page: 1
2626
2646
  };
2627
- if (data && _.has(data, "page_size")) {
2647
+ if (data && has(data, "page_size")) {
2628
2648
  const pageSize = Array.isArray(data.page_size) ? parseInt(data.page_size.pop(), 10) : parseInt(data.page_size, 10);
2629
- if (pageSize >= 1) pageParams = _.merge(pageParams, { page_size: pageSize });
2649
+ if (pageSize >= 1) pageParams = merge(pageParams, { page_size: pageSize });
2630
2650
  }
2631
- if (data && _.has(data, "page")) {
2651
+ if (data && has(data, "page")) {
2632
2652
  const page = Array.isArray(data.page) ? parseInt(data.page.pop(), 10) : parseInt(data.page, 10);
2633
- if (page > 1) pageParams = _.merge(pageParams, { page });
2653
+ if (page > 1) pageParams = merge(pageParams, { page });
2634
2654
  }
2635
2655
  return pageParams;
2636
2656
  }
@@ -2898,14 +2918,17 @@ function buildPreset(mongoose) {
2898
2918
  this.find({ creator_id: userId }).sort({ created_on: -1 }).then((docs) => cb(null, docs), (err) => cb(err));
2899
2919
  },
2900
2920
  async getPresetByQuery(req, opts = {}) {
2901
- if (!_.has(req.query, "keyword") || !_.isString(req.query.keyword)) throw new Error("missing the searching term");
2921
+ if (!has(req.query, "keyword") || !isString(req.query.keyword)) throw new Error("missing the searching term");
2902
2922
  const pageParams = _parsePageParams(req.query);
2903
2923
  let searchCondition = {
2904
2924
  preset_for: req.query.preset_for ? req.query.preset_for : "jamup",
2905
2925
  status: 0
2906
2926
  };
2907
- if (_.has(req.query, "license_tier")) searchCondition = _.merge(_.clone(searchCondition), _buildLicenseTierQuery(req.query.license_tier));
2908
- if (_.has(req.query, "order") && req.query.order === "hot") searchCondition = _.assign({}, searchCondition, { created_on: { $gte: moment().subtract(1, "month").toDate() } });
2927
+ if (has(req.query, "license_tier")) searchCondition = merge({ ...searchCondition }, _buildLicenseTierQuery(req.query.license_tier));
2928
+ if (has(req.query, "order") && req.query.order === "hot") searchCondition = {
2929
+ ...searchCondition,
2930
+ created_on: { $gte: subMonths(/* @__PURE__ */ new Date(), 1) }
2931
+ };
2909
2932
  searchCondition = _handlePresetVersion(searchCondition, req);
2910
2933
  const aggregatePipeline = [
2911
2934
  { $search: {
@@ -2933,7 +2956,7 @@ function buildPreset(mongoose) {
2933
2956
  { $skip: (pageParams.page - 1) * pageParams.page_size },
2934
2957
  { $limit: pageParams.page_size }
2935
2958
  ];
2936
- if (!_.has(opts, "full")) aggregatePipeline.push({ $project: { preset_data: 0 } });
2959
+ if (!has(opts, "full")) aggregatePipeline.push({ $project: { preset_data: 0 } });
2937
2960
  return this.aggregate(aggregatePipeline);
2938
2961
  },
2939
2962
  async getPresetsBySearch(req) {
@@ -2944,52 +2967,55 @@ function buildPreset(mongoose) {
2944
2967
  status: 0
2945
2968
  };
2946
2969
  let selectOps = {};
2947
- if (!_.has(req.query, "detail") || req.query.detail !== "yes") selectOps = { preset_data: 0 };
2948
- if (_.has(req.query, "pids")) {
2970
+ if (!has(req.query, "detail") || req.query.detail !== "yes") selectOps = { preset_data: 0 };
2971
+ if (has(req.query, "pids")) {
2949
2972
  const pids = req.query.pids.split(",");
2950
2973
  searchCondition._id = { $in: pids };
2951
2974
  }
2952
- if (_.has(req.query, "category")) searchCondition.category = { $in: String(req.query.category).split(",") };
2953
- else if (_.has(req.query, "except_cateogry")) searchCondition.category = { $nin: String(req.query.except_cateogry).split(",") };
2954
- if (_.has(req.query, "pedal_type")) searchCondition["preset_meta.pedal_type"] = req.query.pedal_type;
2955
- if (_.has(req.query, "preset_features")) {
2975
+ if (has(req.query, "category")) searchCondition.category = { $in: String(req.query.category).split(",") };
2976
+ else if (has(req.query, "except_cateogry")) searchCondition.category = { $nin: String(req.query.except_cateogry).split(",") };
2977
+ if (has(req.query, "pedal_type")) searchCondition["preset_meta.pedal_type"] = req.query.pedal_type;
2978
+ if (has(req.query, "preset_features")) {
2956
2979
  const params = req.query.preset_features.split(",");
2957
2980
  const featureQuery = {};
2958
- _.forEach(params, (param) => {
2981
+ params.forEach((param) => {
2959
2982
  const t = param.split(":");
2960
2983
  if (t.length === 2) featureQuery[t[0]] = parseInt(t[1], 10);
2961
2984
  });
2962
2985
  searchCondition.preset_features = featureQuery;
2963
2986
  }
2964
2987
  const createQuery = {};
2965
- if (_.has(req.query, "create_after")) {
2966
- const d = moment(req.query.create_after);
2967
- if (d.isValid()) createQuery.$gte = d.toDate();
2988
+ if (has(req.query, "create_after")) {
2989
+ const d = new Date(req.query.create_after);
2990
+ if (isValid(d)) createQuery.$gte = d;
2968
2991
  }
2969
- if (_.has(req.query, "create_before")) {
2970
- const d = moment(req.query.create_before);
2971
- if (d.isValid()) createQuery.$lte = d.toDate();
2992
+ if (has(req.query, "create_before")) {
2993
+ const d = new Date(req.query.create_before);
2994
+ if (isValid(d)) createQuery.$lte = d;
2972
2995
  }
2973
- if (!_.isEmpty(createQuery)) searchCondition.created_on = createQuery;
2996
+ if (!isEmpty(createQuery)) searchCondition.created_on = createQuery;
2974
2997
  const updateQuery = {};
2975
- if (_.has(req.query, "update_after")) {
2976
- const d = moment(req.query.update_after);
2977
- if (d.isValid()) updateQuery.$gte = d.toDate();
2998
+ if (has(req.query, "update_after")) {
2999
+ const d = new Date(req.query.update_after);
3000
+ if (isValid(d)) updateQuery.$gte = d;
2978
3001
  }
2979
- if (_.has(req.query, "update_before")) {
2980
- const d = moment(req.query.update_before);
2981
- if (d.isValid()) updateQuery.$lte = d.toDate();
3002
+ if (has(req.query, "update_before")) {
3003
+ const d = new Date(req.query.update_before);
3004
+ if (isValid(d)) updateQuery.$lte = d;
2982
3005
  }
2983
- if (!_.isEmpty(updateQuery)) searchCondition.updated_on = updateQuery;
2984
- if (_.has(req.query, "license_tier")) searchCondition = _.merge(_.clone(searchCondition), _buildLicenseTierQuery(req.query.license_tier));
2985
- if (_.has(req.query, "order") && req.query.order === "hot") searchCondition = _.assign({}, searchCondition, { created_on: { $gte: moment().subtract(1, "month").toDate() } });
3006
+ if (!isEmpty(updateQuery)) searchCondition.updated_on = updateQuery;
3007
+ if (has(req.query, "license_tier")) searchCondition = merge({ ...searchCondition }, _buildLicenseTierQuery(req.query.license_tier));
3008
+ if (has(req.query, "order") && req.query.order === "hot") searchCondition = {
3009
+ ...searchCondition,
3010
+ created_on: { $gte: subMonths(/* @__PURE__ */ new Date(), 1) }
3011
+ };
2986
3012
  if (searchCondition.preset_for === "spark") {
2987
- if (_.has(req.query, "signal_chain_type")) searchCondition.signal_chain_type = req.query.signal_chain_type;
2988
- if (_.has(req.query, "no_dspid")) searchCondition["preset_meta.dspId"] = { $nin: String(req.query.no_dspid).split(",") };
3013
+ if (has(req.query, "signal_chain_type")) searchCondition.signal_chain_type = req.query.signal_chain_type;
3014
+ if (has(req.query, "no_dspid")) searchCondition["preset_meta.dspId"] = { $nin: String(req.query.no_dspid).split(",") };
2989
3015
  }
2990
3016
  searchCondition = _handlePresetVersion(searchCondition, req);
2991
- if (_.has(req, "query.keyword") && !_.isEmpty(req.query.keyword)) {
2992
- if (_.has(process.env, "IS_CHINA")) {
3017
+ if (has(req, "query.keyword") && !isEmpty(req.query.keyword)) {
3018
+ if (has(process.env, "IS_CHINA")) {
2993
3019
  searchCondition.$or = [{ name: new RegExp(`^${_filterKeyword(req.query.keyword)}`, "i") }, { description: new RegExp(`${_filterKeyword(req.query.keyword)}`, "i") }];
2994
3020
  return this.aggregate([
2995
3021
  { $match: _queryCompatibilityHandler(searchCondition) },
@@ -3025,14 +3051,14 @@ function buildPreset(mongoose) {
3025
3051
  getPresetsList(query, sort, req, cb) {
3026
3052
  const pageParams = _parsePageParams(req.query);
3027
3053
  let q = query;
3028
- if (_.isObject(q)) q.status = 0;
3029
- if (_.has(q, "preset_for") && q.preset_for !== "jamup") {
3054
+ if (isPlainObject(q)) q.status = 0;
3055
+ if (has(q, "preset_for") && q.preset_for !== "jamup") {
3030
3056
  q.image_url = { $ne: null };
3031
3057
  q.thumb_url = { $ne: null };
3032
3058
  }
3033
- if (_.has(req.query, "license_tier")) q = _.merge(_.clone(q), _buildLicenseTierQuery(req.query.license_tier));
3059
+ if (has(req.query, "license_tier")) q = merge({ ...q }, _buildLicenseTierQuery(req.query.license_tier));
3034
3060
  let finalSort = sort;
3035
- if (_.has(req.query, "order")) finalSort = _buildSortQuery(req.query.order);
3061
+ if (has(req.query, "order")) finalSort = _buildSortQuery(req.query.order);
3036
3062
  q = _handlePresetVersion(q, req);
3037
3063
  this.find(_queryCompatibilityHandler(q)).sort(finalSort).select("-preset_data").skip((pageParams.page - 1) * pageParams.page_size).limit(pageParams.page_size).then((docs) => cb(null, docs), (err) => cb(err));
3038
3064
  },
@@ -3044,8 +3070,8 @@ function buildPreset(mongoose) {
3044
3070
  getMyPresets(query, sort, req, cb) {
3045
3071
  const pageParams = _parsePageParams(req.query);
3046
3072
  let q = query;
3047
- if (_.isObject(q)) q.status = { $in: [0, 2] };
3048
- if (_.has(q, "preset_for") && q.preset_for !== "jamup") {
3073
+ if (isPlainObject(q)) q.status = { $in: [0, 2] };
3074
+ if (has(q, "preset_for") && q.preset_for !== "jamup") {
3049
3075
  q.image_url = { $ne: null };
3050
3076
  q.thumb_url = { $ne: null };
3051
3077
  }
@@ -3053,8 +3079,8 @@ function buildPreset(mongoose) {
3053
3079
  this.find(_queryCompatibilityHandler(q)).sort(sort).select("-preset_data").skip((pageParams.page - 1) * pageParams.page_size).limit(pageParams.page_size).then((docs) => cb(null, docs), (err) => cb(err));
3054
3080
  },
3055
3081
  getOnePresetByCondition(query, opts, cb) {
3056
- const defaultSort = _.has(opts, "sort") && _.isObject(opts.sort) ? opts.sort : { created_on: -1 };
3057
- const defaultSelect = _.has(opts, "select") && _.isString(opts.select) ? opts.select : "";
3082
+ const defaultSort = has(opts, "sort") && isPlainObject(opts.sort) ? opts.sort : { created_on: -1 };
3083
+ const defaultSelect = has(opts, "select") && isString(opts.select) ? opts.select : "";
3058
3084
  this.findOne(_queryCompatibilityHandler(query)).sort(defaultSort).select(defaultSelect).then((doc) => cb(null, doc), (err) => cb(err));
3059
3085
  },
3060
3086
  getSinglePreset(id, cb) {
@@ -3123,9 +3149,8 @@ function buildPreset(mongoose) {
3123
3149
  PresetUserLike.static({
3124
3150
  getCountByPresetCondition(query, condition, cb) {
3125
3151
  this.find(query).populate("preset_id").then((result) => {
3126
- return cb(null, _.filter(result, (item) => {
3127
- const tmpObj = item.toObject ? item.toObject() : item;
3128
- return _.has(tmpObj.preset_id, condition);
3152
+ return cb(null, result.filter((item) => {
3153
+ return has((item.toObject ? item.toObject() : item).preset_id, condition);
3129
3154
  }).length);
3130
3155
  }, (err) => cb(err));
3131
3156
  },
@@ -3133,12 +3158,15 @@ function buildPreset(mongoose) {
3133
3158
  const pageParams = _parsePageParams(req.query);
3134
3159
  const defaultPresetCondition = { "preset.status": { $eq: 0 } };
3135
3160
  let filterQuery = {};
3136
- if (_.has(query, "no_dspid")) {
3161
+ if (has(query, "no_dspid")) {
3137
3162
  defaultPresetCondition["preset.preset_meta.dspId"] = { $nin: String(query.no_dspid).split(",") };
3138
- filterQuery = _.omit(query, ["no_dspid"]);
3139
- } else filterQuery = _.clone(query);
3163
+ filterQuery = omit(query, ["no_dspid"]);
3164
+ } else filterQuery = { ...query };
3140
3165
  const aggregateQuery = [
3141
- { $match: _.assign({}, _queryCompatibilityHandler(filterQuery), { user_id: new mongoose.Types.ObjectId(filterQuery.user_id) }) },
3166
+ { $match: {
3167
+ ..._queryCompatibilityHandler(filterQuery),
3168
+ user_id: new mongoose.Types.ObjectId(filterQuery.user_id)
3169
+ } },
3142
3170
  { $lookup: {
3143
3171
  from: "jamup_preset",
3144
3172
  localField: "preset_id",
@@ -3149,10 +3177,10 @@ function buildPreset(mongoose) {
3149
3177
  { $match: defaultPresetCondition }
3150
3178
  ];
3151
3179
  const presetQuery = _handlePresetVersion({}, req);
3152
- if (!_.isEmpty(presetQuery) && _.has(presetQuery, "$and") && _.isArray(presetQuery.$and)) _.forEach(presetQuery.$and, (item) => {
3180
+ if (!isEmpty(presetQuery) && has(presetQuery, "$and") && Array.isArray(presetQuery.$and)) presetQuery.$and.forEach((item) => {
3153
3181
  const newQuery = { $match: {} };
3154
- const objKey = _.keys(item);
3155
- const objVal = _.values(item);
3182
+ const objKey = Object.keys(item);
3183
+ const objVal = Object.values(item);
3156
3184
  if (objKey.length === 1 && objVal.length === 1) {
3157
3185
  newQuery.$match[`preset.${objKey[0]}`] = objVal[0];
3158
3186
  aggregateQuery.push(newQuery);
@@ -3190,7 +3218,7 @@ function buildPreset(mongoose) {
3190
3218
  }
3191
3219
  //#endregion
3192
3220
  //#region src/models/promotion.ts
3193
- const log$3 = debug("model:promotion");
3221
+ const log$3 = debuglog("model:promotion");
3194
3222
  const CAMPAIGN_TYPE = ["free_upgrade"];
3195
3223
  function buildPromotion(mongoose) {
3196
3224
  const { Schema } = mongoose;
@@ -3349,15 +3377,15 @@ function buildPromotion(mongoose) {
3349
3377
  try {
3350
3378
  const nowTime = /* @__PURE__ */ new Date();
3351
3379
  const defaultQuery = { $and: [{ $or: [{ start_time: null }, { start_time: { $lt: nowTime } }] }, { $or: [{ end_time: null }, { end_time: { $gt: nowTime } }] }] };
3352
- if (!_.isUndefined(params)) {
3380
+ if (params !== void 0) {
3353
3381
  log$3("getAvailableAnnouncement:querystring %o", params);
3354
3382
  const { pname, locale, ta_device, country, device_list, device_os } = params;
3355
- if (!_.isUndefined(pname) && _.isString(pname)) defaultQuery.$and.push({ announce_for: { $in: _.concat([pname], "all") } });
3356
- if (!_.isUndefined(locale) && _.isString(locale)) defaultQuery.$and.push({ locale });
3357
- if (!_.isUndefined(ta_device) && _.isString(ta_device)) defaultQuery.$and.push({ target_audience_device: { $in: _.concat(ta_device.split(","), "all") } });
3358
- if (!_.isUndefined(country) && _.isString(country)) defaultQuery.$and.push({ $or: [{ country: { $all: country.split(",") } }, { country: { $in: ["all"] } }] });
3383
+ if (typeof pname === "string") defaultQuery.$and.push({ announce_for: { $in: [pname, "all"] } });
3384
+ if (typeof locale === "string") defaultQuery.$and.push({ locale });
3385
+ if (typeof ta_device === "string") defaultQuery.$and.push({ target_audience_device: { $in: [...ta_device.split(","), "all"] } });
3386
+ if (typeof country === "string") defaultQuery.$and.push({ $or: [{ country: { $all: country.split(",") } }, { country: { $in: ["all"] } }] });
3359
3387
  else defaultQuery.$and.push({ $or: [{ country: { $in: ["all"] } }, { country: { $exists: false } }] });
3360
- if (!_.isUndefined(device_list)) if (_.isString(device_list) && !_.isEmpty(device_list)) {
3388
+ if (device_list !== void 0) if (typeof device_list === "string" && device_list.length > 0) {
3361
3389
  const tmpDeviceList = device_list.split(",");
3362
3390
  const deviceList = [];
3363
3391
  const allTypeSet = /* @__PURE__ */ new Set();
@@ -3372,17 +3400,17 @@ function buildPromotion(mongoose) {
3372
3400
  if (uniqueProductLineSet.size > 0) uniqueProductLineSet.forEach((item) => deviceList.push(`${item}_all`));
3373
3401
  defaultQuery.$and.push({ device_list: { $in: deviceList } });
3374
3402
  } else defaultQuery.$and.push({ device_list: { $in: ["none"] } });
3375
- if (!_.isUndefined(device_os) && _.isString(device_os)) defaultQuery.$and.push({ $or: [{ device_os: "all" }, { device_os }] });
3403
+ if (typeof device_os === "string") defaultQuery.$and.push({ $or: [{ device_os: "all" }, { device_os }] });
3376
3404
  }
3377
3405
  let ret;
3378
- if (!_.has(params, "email") || _.has(params, "email") && _.isUndefined(params.email)) {
3406
+ if (params?.email === void 0) {
3379
3407
  defaultQuery.$and.push({ user_list_num: 0 });
3380
3408
  defaultQuery.$and.push({ action_button: { $elemMatch: { type: { $ne: "free_trial" } } } });
3381
3409
  ret = await this.find(defaultQuery).lean().exec();
3382
3410
  } else {
3383
- const noUserQuery = _.cloneDeep(defaultQuery);
3411
+ const noUserQuery = structuredClone(defaultQuery);
3384
3412
  noUserQuery.$and.push({ user_list_num: 0 });
3385
- const hasUserQuery = _.cloneDeep(defaultQuery);
3413
+ const hasUserQuery = structuredClone(defaultQuery);
3386
3414
  hasUserQuery.$and.push({ user_list_num: { $gt: 0 } });
3387
3415
  const [noUserData, hasUserData] = await Promise.all([this.aggregate([{ $match: noUserQuery }]).exec(), this.aggregate([
3388
3416
  { $match: hasUserQuery },
@@ -3398,9 +3426,9 @@ function buildPromotion(mongoose) {
3398
3426
  "paUserList.status": 1
3399
3427
  } }
3400
3428
  ]).exec()]);
3401
- ret = _.concat(noUserData, hasUserData);
3429
+ ret = [...noUserData, ...hasUserData];
3402
3430
  }
3403
- return _.orderBy(ret, ["order", "start_time"], ["desc", "asc"]);
3431
+ return orderBy(ret, ["order", "start_time"], ["desc", "asc"]);
3404
3432
  } catch (err) {
3405
3433
  log$3("ERR:getAvailableAnnouncement %j", err);
3406
3434
  throw err;
@@ -4283,7 +4311,34 @@ function buildToneThemeFeaturedList(mongoose) {
4283
4311
  }
4284
4312
  //#endregion
4285
4313
  //#region src/models/user.ts
4286
- const log$2 = debug("model:user");
4314
+ const log$2 = debuglog("model:user");
4315
+ /**
4316
+ * Error thrown by User auth statics. Replaces the previous dependency on
4317
+ * `@positivegrid/pg-error`'s `AuthError`. Preserves the `errorCode` +
4318
+ * `statusCode` property contract so existing duck-typing checks
4319
+ * (`err.errorCode === 'USER_UNAUTHORIZED'`) keep working. Consumers that
4320
+ * relied on `instanceof AuthError` should switch to `instanceof AuthError`
4321
+ * (re-exported from the package root).
4322
+ */
4323
+ const AUTH_ERROR_STATUS = {
4324
+ USER_UNAUTHORIZED: 401,
4325
+ USER_NOT_EXIST: 404,
4326
+ USER_OAUTH_LOGIN: 400,
4327
+ ACCOUNT_WERE_DELETED: 400,
4328
+ INTERNAL_SYSMTEM_ERROR: 500
4329
+ };
4330
+ var AuthError = class extends Error {
4331
+ errorCode;
4332
+ statusCode;
4333
+ customData;
4334
+ constructor(code, message, customData) {
4335
+ super(message);
4336
+ this.name = "AuthError";
4337
+ this.errorCode = code;
4338
+ this.statusCode = AUTH_ERROR_STATUS[code.toUpperCase()] ?? 500;
4339
+ if (customData) this.customData = customData;
4340
+ }
4341
+ };
4287
4342
  function encryptPassword(pwd) {
4288
4343
  if (!pwd) return "";
4289
4344
  const encryptType = "sha1";
@@ -4715,23 +4770,23 @@ function buildUser(mongoose) {
4715
4770
  try {
4716
4771
  user = await this.findOne({ username: normalized }).exec();
4717
4772
  } catch (err) {
4718
- throw new ApiErrorCode("internal_sysmtem_error", err.message);
4773
+ throw new AuthError("internal_sysmtem_error", err.message);
4719
4774
  }
4720
4775
  if (!user) {
4721
4776
  let bgUser;
4722
4777
  try {
4723
4778
  bgUser = await this.findOne({ bk_username: { $in: [normalized] } }).exec();
4724
4779
  } catch (err) {
4725
- throw new ApiErrorCode("INTERNAL_SYSMTEM_ERROR", err.message);
4780
+ throw new AuthError("INTERNAL_SYSMTEM_ERROR", err.message);
4726
4781
  }
4727
- if (!bgUser) throw new ApiErrorCode("USER_NOT_EXIST", `Cannot find user ${normalized}`);
4728
- else if (!bgUser.authenticate(password)) throw new ApiErrorCode("USER_UNAUTHORIZED", "unauthorized");
4782
+ if (!bgUser) throw new AuthError("USER_NOT_EXIST", `Cannot find user ${normalized}`);
4783
+ else if (!bgUser.authenticate(password)) throw new AuthError("USER_UNAUTHORIZED", "unauthorized");
4729
4784
  return bgUser;
4730
4785
  }
4731
- if (user.user_status === 2) throw new ApiErrorCode("ACCOUNT_WERE_DELETED", `Account ${user.email} already deleted`);
4786
+ if (user.user_status === 2) throw new AuthError("ACCOUNT_WERE_DELETED", `Account ${user.email} already deleted`);
4732
4787
  if (!user.authenticate(password)) {
4733
- if (user.facebook_id !== null) throw new ApiErrorCode("USER_OAUTH_LOGIN", "Please use FB to login your account");
4734
- throw new ApiErrorCode("USER_UNAUTHORIZED", "unauthorized");
4788
+ if (user.facebook_id !== null) throw new AuthError("USER_OAUTH_LOGIN", "Please use FB to login your account");
4789
+ throw new AuthError("USER_UNAUTHORIZED", "unauthorized");
4735
4790
  }
4736
4791
  return user;
4737
4792
  },
@@ -4740,14 +4795,14 @@ function buildUser(mongoose) {
4740
4795
  this._async_auth(uname, password).then((user) => cb(null, user), (err) => cb(err));
4741
4796
  },
4742
4797
  login(query, cb) {
4743
- if (!_.isObject(query)) return cb(/* @__PURE__ */ new Error("Invalid login parameter"));
4798
+ if (typeof query !== "object" || query === null) return cb(/* @__PURE__ */ new Error("Invalid login parameter"));
4744
4799
  this.findOne(query).then((u) => cb(null, u), (err) => cb(err));
4745
4800
  },
4746
4801
  loginForPassport(query, cb) {
4747
- if (!_.isObject(query)) return cb(/* @__PURE__ */ new Error("Invalid login parameter"));
4802
+ if (typeof query !== "object" || query === null) return cb(/* @__PURE__ */ new Error("Invalid login parameter"));
4748
4803
  const q = query;
4749
- if (_.has(q, "username")) q.username = String(_.trim(q.username)).toLowerCase();
4750
- if (_.has(q, "email")) q.email = String(_.trim(q.email)).toLowerCase();
4804
+ if (Object.hasOwn(q, "username")) q.username = String(q.username).trim().toLowerCase();
4805
+ if (Object.hasOwn(q, "email")) q.email = String(q.email).trim().toLowerCase();
4751
4806
  this.findOne(q).then((user) => {
4752
4807
  if (!user) return cb({
4753
4808
  status: 404,
@@ -4799,9 +4854,12 @@ function buildUser(mongoose) {
4799
4854
  },
4800
4855
  async getUserDetail(query, projectFields = {}) {
4801
4856
  try {
4802
- if (!_.isObject(query)) throw new Error("Query need to be object!");
4803
- const queryCondition = _.assign({}, { user_status: 1 }, query);
4804
- const defaultProjectFields = _.assign({}, {
4857
+ if (typeof query !== "object" || query === null) throw new Error("Query need to be object!");
4858
+ const queryCondition = {
4859
+ user_status: 1,
4860
+ ...query
4861
+ };
4862
+ const defaultProjectFields = {
4805
4863
  _id: 1,
4806
4864
  email: 1,
4807
4865
  username: 1,
@@ -4809,8 +4867,9 @@ function buildUser(mongoose) {
4809
4867
  last_login: 1,
4810
4868
  "userprofile.first_name": 1,
4811
4869
  "userprofile.last_name": 1,
4812
- "userprofile.full_name": 1
4813
- }, projectFields);
4870
+ "userprofile.full_name": 1,
4871
+ ...projectFields
4872
+ };
4814
4873
  return await this.aggregate([
4815
4874
  { $match: queryCondition },
4816
4875
  { $lookup: {
@@ -4829,8 +4888,11 @@ function buildUser(mongoose) {
4829
4888
  },
4830
4889
  async getDealerDetail(query) {
4831
4890
  try {
4832
- if (!_.isObject(query)) throw new Error("Query need to be object!");
4833
- const queryCondition = _.assign({}, { user_status: 1 }, query);
4891
+ if (typeof query !== "object" || query === null) throw new Error("Query need to be object!");
4892
+ const queryCondition = {
4893
+ user_status: 1,
4894
+ ...query
4895
+ };
4834
4896
  return await this.aggregate([
4835
4897
  { $match: queryCondition },
4836
4898
  { $lookup: {
@@ -4957,7 +5019,7 @@ function buildUser(mongoose) {
4957
5019
  }
4958
5020
  //#endregion
4959
5021
  //#region src/models/userTrack.ts
4960
- const log$1 = debug("model:usertrack");
5022
+ const log$1 = debuglog("model:usertrack");
4961
5023
  const LICENSE_ADDITION = {
4962
5024
  PRO: 0,
4963
5025
  DEMO: 1,
@@ -5063,16 +5125,16 @@ function buildUserTrack(mongoose) {
5063
5125
  const userID = new mongoose.Types.ObjectId(data.userID);
5064
5126
  const startedAt = parseInt(String(data.startedAt), 10);
5065
5127
  if (!mongoose.Types.ObjectId.isValid(userID) || PRODUCTS.indexOf(product) === -1 || Object.keys(LICENSE_ADDITION).indexOf(addition) === -1) throw new Error(`Invalid parameter: ${String(userID)}/${product}/${addition}`);
5066
- else if (!startedAt || !moment(startedAt).isValid()) throw new Error(`Invalid timestamp format: ${startedAt}/${data.updatedAt}`);
5128
+ else if (!startedAt || !isValid(new Date(startedAt))) throw new Error(`Invalid timestamp format: ${startedAt}/${data.updatedAt}`);
5067
5129
  const trackData = {
5068
5130
  user_id: userID,
5069
5131
  product,
5070
5132
  addition: LICENSE_ADDITION[addition],
5071
- started_at: moment(startedAt).toDate()
5133
+ started_at: new Date(startedAt)
5072
5134
  };
5073
- if (_.has(data, "updatedAt")) {
5135
+ if (Object.hasOwn(data, "updatedAt")) {
5074
5136
  const updatedAt = parseInt(String(data.updatedAt), 10);
5075
- if (updatedAt && moment(updatedAt).isValid()) trackData.updated_at = moment(updatedAt).toDate();
5137
+ if (updatedAt && isValid(new Date(updatedAt))) trackData.updated_at = new Date(updatedAt);
5076
5138
  }
5077
5139
  if (!await this.findOne(trackData).exec()) await this.create(trackData);
5078
5140
  return true;
@@ -5089,7 +5151,7 @@ function buildUserTrack(mongoose) {
5089
5151
  }
5090
5152
  //#endregion
5091
5153
  //#region src/index.ts
5092
- const log = debug("model:init");
5154
+ const log = debuglog("model:init");
5093
5155
  const ALL_BUILDERS = [
5094
5156
  buildBanks,
5095
5157
  buildDevice,
@@ -5125,4 +5187,4 @@ function register(mongoose, type) {
5125
5187
  for (const build of ALL_BUILDERS) build(mongoose);
5126
5188
  }
5127
5189
  //#endregion
5128
- export { register as default, register };
5190
+ export { AuthError, register as default, register };