joye-backend-utility 7.3.2 → 7.3.6

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.
@@ -1,12 +1,14 @@
1
1
  /**
2
2
  * Platform → segment base (added before `hash(employeeId) % 1000` for stored `User.bucket`).
3
3
  *
4
- * Only platforms listed in **`DEFAULT_BUCKET_SEGMENT_BASE_BY_PLATFORM`** get a `bucket`.
5
- * Keys are matched **case-insensitively** to `Organization.platformKey`. Anything else no bucket.
4
+ * Keys are matched **case-insensitively** to `Organization.platformKey`.
5
+ * Reserved key **`pwa`**: used as the segment base for any org whose `Platform` doc has **`pwa: true`** but whose `platformKey` is not otherwise listed here.
6
6
  */
7
7
  /** Edit this object only — add one entry per platform that should participate in notification sharding. */
8
8
  export declare const DEFAULT_BUCKET_SEGMENT_BASE_BY_PLATFORM: Record<string, number>;
9
9
  export declare function getBucketSegmentMapping(): Record<string, number>;
10
10
  export declare function segmentBaseForPlatformKey(orgPlatformKey: string, mapping: Record<string, number>): number | null;
11
- /** Segment base if `platformKey` is in the map; otherwise `null` (do not set `User.bucket`). */
12
- export declare function resolveBucketSegmentBase(orgPlatformKey: string): number | null;
11
+ /**
12
+ * Segment base: explicit map first; if missing and **`isPwaPlatform`**, use the **`pwa`** entry in the same map.
13
+ */
14
+ export declare function resolveBucketSegmentBase(orgPlatformKey: string, isPwaPlatform?: boolean): number | null;
@@ -2,16 +2,17 @@
2
2
  /**
3
3
  * Platform → segment base (added before `hash(employeeId) % 1000` for stored `User.bucket`).
4
4
  *
5
- * Only platforms listed in **`DEFAULT_BUCKET_SEGMENT_BASE_BY_PLATFORM`** get a `bucket`.
6
- * Keys are matched **case-insensitively** to `Organization.platformKey`. Anything else no bucket.
5
+ * Keys are matched **case-insensitively** to `Organization.platformKey`.
6
+ * Reserved key **`pwa`**: used as the segment base for any org whose `Platform` doc has **`pwa: true`** but whose `platformKey` is not otherwise listed here.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.resolveBucketSegmentBase = exports.segmentBaseForPlatformKey = exports.getBucketSegmentMapping = exports.DEFAULT_BUCKET_SEGMENT_BASE_BY_PLATFORM = void 0;
10
10
  /** Edit this object only — add one entry per platform that should participate in notification sharding. */
11
11
  exports.DEFAULT_BUCKET_SEGMENT_BASE_BY_PLATFORM = {
12
12
  teams: 0,
13
- visit: 1000,
14
- medibuddy: 3000,
13
+ pwa: 1000,
14
+ visit: 3000,
15
+ medibuddy: 4000,
15
16
  };
16
17
  function lowercaseKeys(map) {
17
18
  const out = {};
@@ -38,8 +39,20 @@ function segmentBaseForPlatformKey(orgPlatformKey, mapping) {
38
39
  return null;
39
40
  }
40
41
  exports.segmentBaseForPlatformKey = segmentBaseForPlatformKey;
41
- /** Segment base if `platformKey` is in the map; otherwise `null` (do not set `User.bucket`). */
42
- function resolveBucketSegmentBase(orgPlatformKey) {
43
- return segmentBaseForPlatformKey(orgPlatformKey, getBucketSegmentMapping());
42
+ /**
43
+ * Segment base: explicit map first; if missing and **`isPwaPlatform`**, use the **`pwa`** entry in the same map.
44
+ */
45
+ function resolveBucketSegmentBase(orgPlatformKey, isPwaPlatform = false) {
46
+ const mapping = getBucketSegmentMapping();
47
+ const key = String(orgPlatformKey || '').trim();
48
+ if (key !== '') {
49
+ const mapped = segmentBaseForPlatformKey(key, mapping);
50
+ if (mapped != null)
51
+ return mapped;
52
+ }
53
+ if (isPwaPlatform) {
54
+ return segmentBaseForPlatformKey('pwa', mapping);
55
+ }
56
+ return null;
44
57
  }
45
58
  exports.resolveBucketSegmentBase = resolveBucketSegmentBase;
package/dist/index.d.ts CHANGED
@@ -4,5 +4,3 @@ export { createHashPassword, createUuid } from './util';
4
4
  export { createToken, jwtVerify } from './jwt';
5
5
  export { getPreviousWorkday, get2ndLastPreviousWorkday, addDays, addMinutes, addYears, getCurrentDateTime, getCurrentUtcTime, newDate, getDatesBetweenRange, getMoment, getCurrentEpoch, } from './dateTime';
6
6
  export { RedisClient } from './redisClient';
7
- export { DEFAULT_BUCKET_SEGMENT_BASE_BY_PLATFORM, getBucketSegmentMapping, segmentBaseForPlatformKey, resolveBucketSegmentBase, } from './config/notificationBucketSegmentRules';
8
- export { BUCKET_SEGMENT_SPAN, stableBucketFromEmployeeId, notificationBucketFromSegmentBase } from './config/notificationBucket';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.notificationBucketFromSegmentBase = exports.stableBucketFromEmployeeId = exports.BUCKET_SEGMENT_SPAN = exports.resolveBucketSegmentBase = exports.segmentBaseForPlatformKey = exports.getBucketSegmentMapping = exports.DEFAULT_BUCKET_SEGMENT_BASE_BY_PLATFORM = exports.RedisClient = exports.getCurrentEpoch = exports.getMoment = exports.getDatesBetweenRange = exports.newDate = exports.getCurrentUtcTime = exports.getCurrentDateTime = exports.addYears = exports.addMinutes = exports.addDays = exports.get2ndLastPreviousWorkday = exports.getPreviousWorkday = exports.jwtVerify = exports.createToken = exports.createUuid = exports.createHashPassword = void 0;
3
+ exports.RedisClient = exports.getCurrentEpoch = exports.getMoment = exports.getDatesBetweenRange = exports.newDate = exports.getCurrentUtcTime = exports.getCurrentDateTime = exports.addYears = exports.addMinutes = exports.addDays = exports.get2ndLastPreviousWorkday = exports.getPreviousWorkday = exports.jwtVerify = exports.createToken = exports.createUuid = exports.createHashPassword = void 0;
4
4
  const database_1 = require("./database");
5
5
  exports.default = database_1.default;
6
6
  var util_1 = require("./util");
@@ -24,12 +24,3 @@ Object.defineProperty(exports, "getMoment", { enumerable: true, get: function ()
24
24
  Object.defineProperty(exports, "getCurrentEpoch", { enumerable: true, get: function () { return dateTime_1.getCurrentEpoch; } });
25
25
  var redisClient_1 = require("./redisClient");
26
26
  Object.defineProperty(exports, "RedisClient", { enumerable: true, get: function () { return redisClient_1.RedisClient; } });
27
- var notificationBucketSegmentRules_1 = require("./config/notificationBucketSegmentRules");
28
- Object.defineProperty(exports, "DEFAULT_BUCKET_SEGMENT_BASE_BY_PLATFORM", { enumerable: true, get: function () { return notificationBucketSegmentRules_1.DEFAULT_BUCKET_SEGMENT_BASE_BY_PLATFORM; } });
29
- Object.defineProperty(exports, "getBucketSegmentMapping", { enumerable: true, get: function () { return notificationBucketSegmentRules_1.getBucketSegmentMapping; } });
30
- Object.defineProperty(exports, "segmentBaseForPlatformKey", { enumerable: true, get: function () { return notificationBucketSegmentRules_1.segmentBaseForPlatformKey; } });
31
- Object.defineProperty(exports, "resolveBucketSegmentBase", { enumerable: true, get: function () { return notificationBucketSegmentRules_1.resolveBucketSegmentBase; } });
32
- var notificationBucket_1 = require("./config/notificationBucket");
33
- Object.defineProperty(exports, "BUCKET_SEGMENT_SPAN", { enumerable: true, get: function () { return notificationBucket_1.BUCKET_SEGMENT_SPAN; } });
34
- Object.defineProperty(exports, "stableBucketFromEmployeeId", { enumerable: true, get: function () { return notificationBucket_1.stableBucketFromEmployeeId; } });
35
- Object.defineProperty(exports, "notificationBucketFromSegmentBase", { enumerable: true, get: function () { return notificationBucket_1.notificationBucketFromSegmentBase; } });
@@ -206,7 +206,7 @@ const User = new mongoose_1.Schema({
206
206
  required: false,
207
207
  },
208
208
  /**
209
- * Stable shard index: segment base from `DEFAULT_BUCKET_SEGMENT_BASE_BY_PLATFORM` + hash(employeeId)%1000; see BUCKET_SHARDING.md.
209
+ * Stable shard index: segment base (see user-service / notification-delivery `notificationBucketSegmentRules`) + hash(employeeId)%1000; see BUCKET_SHARDING.md.
210
210
  * Schedulers filter `bucket` in [BUCKET_MIN, BUCKET_MAX]; omit field for platforms without notification sharding.
211
211
  */
212
212
  bucket: {
@@ -8,6 +8,12 @@ const UserAnalytic = new mongoose_1.Schema({
8
8
  required: true,
9
9
  index: true,
10
10
  },
11
+ /** Denormalized from `User.bucket` for sharded schedulers (e.g. daily-suggestion queue cron). */
12
+ bucket: {
13
+ type: Number,
14
+ required: false,
15
+ index: true,
16
+ },
11
17
  date: {
12
18
  type: String,
13
19
  required: true,
@@ -133,4 +139,5 @@ const UserAnalytic = new mongoose_1.Schema({
133
139
  });
134
140
  UserAnalytic.index({ employeeId: 1, weekNumber: -1, year: -1, date: -1 });
135
141
  UserAnalytic.index({ employeeId: 1, month: -1, year: -1, date: -1 });
142
+ UserAnalytic.index({ year: 1, weekNumber: 1, bucket: 1 });
136
143
  exports.UserAnalyticSchema = UserAnalytic;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "joye-backend-utility",
3
- "version": "7.3.2",
3
+ "version": "7.3.6",
4
4
  "description": "Joye backend utility for db functions and common functions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",