joye-backend-utility 8.2.12 → 9.0.0
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/database.js +4 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +11 -1
- package/dist/schema/accessTier.d.ts +5 -0
- package/dist/schema/accessTier.js +60 -0
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +6 -1
- package/dist/tierAccess.d.ts +23 -0
- package/dist/tierAccess.js +78 -0
- package/package.json +1 -1
package/dist/database.js
CHANGED
|
@@ -70,6 +70,10 @@ class database {
|
|
|
70
70
|
con.model('User_Wellbeing_Data', schema_1.UserWellbeingDataSchema);
|
|
71
71
|
con.model('User_Emotional_Health', schema_1.UserEmotionalHealthSchema);
|
|
72
72
|
con.model('User_Emotional_Health_Detail', schema_1.UserEmotionalHealthDetailSchema);
|
|
73
|
+
con.model('Access_Feature', schema_1.AccessFeatureSchema);
|
|
74
|
+
con.model('Access_Tier', schema_1.AccessTierSchema);
|
|
75
|
+
con.model('Access_Entitlement', schema_1.AccessEntitlementSchema);
|
|
76
|
+
con.model('Access_Trial_Policy', schema_1.AccessTrialPolicySchema);
|
|
73
77
|
};
|
|
74
78
|
this.connectToDatabase = () => {
|
|
75
79
|
const env = config_1.NODE_ENV || 'development';
|
package/dist/index.d.ts
CHANGED
|
@@ -6,4 +6,7 @@ export { getPreviousWorkday, get2ndLastPreviousWorkday, addDays, addMinutes, add
|
|
|
6
6
|
export { RedisClient } from './redisClient';
|
|
7
7
|
export { hasDailySuggestionFlag } from './userAnalytic';
|
|
8
8
|
export { LlmBatchJobSchema, LLM_BATCH_IN_PROGRESS_ITEM_STATUSES } from './schema/llm_batch_job';
|
|
9
|
+
export { AccessFeatureSchema, AccessTierSchema, AccessEntitlementSchema, AccessTrialPolicySchema } from './schema/accessTier';
|
|
10
|
+
export { entitlementInForce, expandTierChain, tiersToGrant, collectGrantedFeatures } from './tierAccess';
|
|
11
|
+
export type { TierRecord, FeatureRecord, EntitlementWindow } from './tierAccess';
|
|
9
12
|
export type { LlmBatchItemStatus, LlmBatchJobStatus, LlmBatchProvider } from './schema/llm_batch_job';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LLM_BATCH_IN_PROGRESS_ITEM_STATUSES = exports.LlmBatchJobSchema = exports.hasDailySuggestionFlag = 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.collectGrantedFeatures = exports.tiersToGrant = exports.expandTierChain = exports.entitlementInForce = exports.AccessTrialPolicySchema = exports.AccessEntitlementSchema = exports.AccessTierSchema = exports.AccessFeatureSchema = exports.LLM_BATCH_IN_PROGRESS_ITEM_STATUSES = exports.LlmBatchJobSchema = exports.hasDailySuggestionFlag = 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");
|
|
@@ -29,3 +29,13 @@ Object.defineProperty(exports, "hasDailySuggestionFlag", { enumerable: true, get
|
|
|
29
29
|
var llm_batch_job_1 = require("./schema/llm_batch_job");
|
|
30
30
|
Object.defineProperty(exports, "LlmBatchJobSchema", { enumerable: true, get: function () { return llm_batch_job_1.LlmBatchJobSchema; } });
|
|
31
31
|
Object.defineProperty(exports, "LLM_BATCH_IN_PROGRESS_ITEM_STATUSES", { enumerable: true, get: function () { return llm_batch_job_1.LLM_BATCH_IN_PROGRESS_ITEM_STATUSES; } });
|
|
32
|
+
var accessTier_1 = require("./schema/accessTier");
|
|
33
|
+
Object.defineProperty(exports, "AccessFeatureSchema", { enumerable: true, get: function () { return accessTier_1.AccessFeatureSchema; } });
|
|
34
|
+
Object.defineProperty(exports, "AccessTierSchema", { enumerable: true, get: function () { return accessTier_1.AccessTierSchema; } });
|
|
35
|
+
Object.defineProperty(exports, "AccessEntitlementSchema", { enumerable: true, get: function () { return accessTier_1.AccessEntitlementSchema; } });
|
|
36
|
+
Object.defineProperty(exports, "AccessTrialPolicySchema", { enumerable: true, get: function () { return accessTier_1.AccessTrialPolicySchema; } });
|
|
37
|
+
var tierAccess_1 = require("./tierAccess");
|
|
38
|
+
Object.defineProperty(exports, "entitlementInForce", { enumerable: true, get: function () { return tierAccess_1.entitlementInForce; } });
|
|
39
|
+
Object.defineProperty(exports, "expandTierChain", { enumerable: true, get: function () { return tierAccess_1.expandTierChain; } });
|
|
40
|
+
Object.defineProperty(exports, "tiersToGrant", { enumerable: true, get: function () { return tierAccess_1.tiersToGrant; } });
|
|
41
|
+
Object.defineProperty(exports, "collectGrantedFeatures", { enumerable: true, get: function () { return tierAccess_1.collectGrantedFeatures; } });
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Schema } from 'mongoose';
|
|
2
|
+
export declare const AccessFeatureSchema: Schema<import("mongoose").Document<any, any, any>, import("mongoose").Model<import("mongoose").Document<any, any, any>, any, any>, undefined, {}>;
|
|
3
|
+
export declare const AccessTierSchema: Schema<import("mongoose").Document<any, any, any>, import("mongoose").Model<import("mongoose").Document<any, any, any>, any, any>, undefined, {}>;
|
|
4
|
+
export declare const AccessEntitlementSchema: Schema<import("mongoose").Document<any, any, any>, import("mongoose").Model<import("mongoose").Document<any, any, any>, any, any>, undefined, {}>;
|
|
5
|
+
export declare const AccessTrialPolicySchema: Schema<import("mongoose").Document<any, any, any>, import("mongoose").Model<import("mongoose").Document<any, any, any>, any, any>, undefined, {}>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccessTrialPolicySchema = exports.AccessEntitlementSchema = exports.AccessTierSchema = exports.AccessFeatureSchema = void 0;
|
|
4
|
+
const mongoose_1 = require("mongoose");
|
|
5
|
+
const featureSchema = new mongoose_1.Schema({
|
|
6
|
+
key: { type: String, required: true, unique: true },
|
|
7
|
+
name: { type: String, required: true },
|
|
8
|
+
kind: { type: String, required: true, enum: ['feature', 'page', 'message'] },
|
|
9
|
+
group: { type: String, required: true },
|
|
10
|
+
route: { type: String, default: '' },
|
|
11
|
+
description: { type: String, default: '' },
|
|
12
|
+
ai: { type: Boolean, default: false },
|
|
13
|
+
chatAvailable: { type: Boolean, default: false },
|
|
14
|
+
chatType: { type: String, default: '' },
|
|
15
|
+
active: { type: Boolean, default: true },
|
|
16
|
+
sort: { type: Number, default: 0 },
|
|
17
|
+
}, { collection: 'features' });
|
|
18
|
+
const tierSchema = new mongoose_1.Schema({
|
|
19
|
+
key: { type: String, required: true, unique: true },
|
|
20
|
+
name: { type: String, required: true },
|
|
21
|
+
description: { type: String, default: '' },
|
|
22
|
+
rank: { type: Number, default: 0 },
|
|
23
|
+
sort: { type: Number, default: 0 },
|
|
24
|
+
includesTierKeys: { type: [String], default: [] },
|
|
25
|
+
featureKeys: { type: [String], default: [] },
|
|
26
|
+
active: { type: Boolean, default: true },
|
|
27
|
+
highlighted: { type: Boolean, default: false },
|
|
28
|
+
}, { collection: 'tiers' });
|
|
29
|
+
const entitlementSchema = new mongoose_1.Schema({
|
|
30
|
+
platformKey: { type: String, required: true, index: true },
|
|
31
|
+
tId: { type: String, default: '' },
|
|
32
|
+
userId: { type: String, default: '' },
|
|
33
|
+
tierKey: { type: String, required: true },
|
|
34
|
+
status: { type: String, required: true, enum: ['active', 'cancelled'], default: 'active' },
|
|
35
|
+
startsAt: { type: Number, required: true },
|
|
36
|
+
endsAt: { type: Number, default: 0 },
|
|
37
|
+
source: { type: String, required: true, enum: ['contract', 'purchase', 'admin', 'comp', 'trial'] },
|
|
38
|
+
policyScope: { type: String, default: '' },
|
|
39
|
+
externalRef: { type: String, default: '' },
|
|
40
|
+
assignedBy: { type: String, default: '' },
|
|
41
|
+
createdAt: { type: Number, required: true },
|
|
42
|
+
updatedAt: { type: Number, required: true },
|
|
43
|
+
}, { collection: 'entitlements' });
|
|
44
|
+
entitlementSchema.index({ platformKey: 1, tId: 1, userId: 1, status: 1, endsAt: 1 });
|
|
45
|
+
const trialPolicySchema = new mongoose_1.Schema({
|
|
46
|
+
platformKey: { type: String, required: true },
|
|
47
|
+
tId: { type: String, default: '' },
|
|
48
|
+
durationDays: { type: Number, required: true },
|
|
49
|
+
tierKeys: { type: [String], default: [] },
|
|
50
|
+
postTrialTierKeys: { type: [String], default: [] },
|
|
51
|
+
startsOn: { type: String, required: true, enum: ['created', 'first_login', 'consent'] },
|
|
52
|
+
active: { type: Boolean, default: true },
|
|
53
|
+
createdAt: { type: Number, required: true },
|
|
54
|
+
updatedAt: { type: Number, required: true },
|
|
55
|
+
}, { collection: 'trial_policies' });
|
|
56
|
+
trialPolicySchema.index({ platformKey: 1, tId: 1 }, { unique: true });
|
|
57
|
+
exports.AccessFeatureSchema = featureSchema;
|
|
58
|
+
exports.AccessTierSchema = tierSchema;
|
|
59
|
+
exports.AccessEntitlementSchema = entitlementSchema;
|
|
60
|
+
exports.AccessTrialPolicySchema = trialPolicySchema;
|
package/dist/schema/index.d.ts
CHANGED
|
@@ -61,3 +61,4 @@ export { UserSuperPowerDataSchema } from './userSuperPowerData';
|
|
|
61
61
|
export { UserWellbeingDataSchema } from './user_wellbeing_data';
|
|
62
62
|
export { UserEmotionalHealthSchema } from './user_emotional_health';
|
|
63
63
|
export { UserEmotionalHealthDetailSchema } from './user_emotional_health_detail';
|
|
64
|
+
export { AccessFeatureSchema, AccessTierSchema, AccessEntitlementSchema, AccessTrialPolicySchema } from './accessTier';
|
package/dist/schema/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UserAnalyticSchema = exports.AIResponsesTrackingSchema = exports.UserProfileSchema = exports.UserChatSessionSchema = exports.FeatureFeedbackSchema = exports.UserWeekActivitySchema = exports.UserTrainingRemindersSchema = exports.UserTrainingDailyDataSchema = exports.MasterTrainingDaysSchema = exports.UserTrainingWeekDataSchema = exports.UserTrainingDataSchema = exports.MasterTrainingWeekSchema = exports.MasterTrainingSchema = exports.userJoyLevelQaSchema = exports.userGoalSchema = exports.OrganizationUserAttrPermissionSchema = exports.TimezoneSchema = exports.UserVideoSchema = exports.UserFeedbackSchema = exports.UserReminderSchema = exports.MasterLinkCardSchema = exports.UserRecommendationSchema = exports.MasterSuggestionsParameterSchema = exports.MasterSuggestionsMessageSchema = exports.MasterBlessingsDataSchema = exports.MasterVideoSchema = exports.DatabaseInfoSchema = exports.UserSchema = exports.UserConsentHistorySchema = exports.UserNotificationLogSchema = exports.UserMessageLogSchema = exports.UserMessageSchema = exports.UserMeetingSchema = exports.UserLogSchema = exports.PlatformSchema = exports.OrganizationAnalyticsSchema = exports.OrganizationSchema = exports.MasterThemeMessageSchema = exports.MasterThemeDataSchema = exports.MasterPredictionEmotionsMessageMappingSchema = exports.MasterPredictionEmotionMessageSchema = exports.MasterPredictionEmotionSchema = exports.MasterPodcastSchema = exports.MasterEmotionMessageTypeThemeMappingSchema = exports.MasterEmotionsMessageMappingSchemaV2 = exports.MasterEmotionsMessageMappingSchema = exports.MasterEmotionsSchema = exports.MasterDataSchema = exports.MasterAppSettingSchema = exports.BrewSchema = void 0;
|
|
4
|
-
exports.UserEmotionalHealthDetailSchema = exports.UserEmotionalHealthSchema = exports.UserWellbeingDataSchema = exports.UserSuperPowerDataSchema = exports.MasterSuperPowerRuleSchema = exports.MasterSuperPowerDataSchema = exports.MasterEmotionalHealthSchema = exports.MasterEmotionalDriverSchema = exports.MasterEmotionsSchemaV2 = exports.ErrorLogSchema = exports.PageViewSchema = exports.AIPromptsSchema = exports.LlmBatchJobSchema = void 0;
|
|
4
|
+
exports.AccessTrialPolicySchema = exports.AccessEntitlementSchema = exports.AccessTierSchema = exports.AccessFeatureSchema = exports.UserEmotionalHealthDetailSchema = exports.UserEmotionalHealthSchema = exports.UserWellbeingDataSchema = exports.UserSuperPowerDataSchema = exports.MasterSuperPowerRuleSchema = exports.MasterSuperPowerDataSchema = exports.MasterEmotionalHealthSchema = exports.MasterEmotionalDriverSchema = exports.MasterEmotionsSchemaV2 = exports.ErrorLogSchema = exports.PageViewSchema = exports.AIPromptsSchema = exports.LlmBatchJobSchema = void 0;
|
|
5
5
|
var brew_1 = require("./brew");
|
|
6
6
|
Object.defineProperty(exports, "BrewSchema", { enumerable: true, get: function () { return brew_1.BrewSchema; } });
|
|
7
7
|
var masterAppSetting_1 = require("./masterAppSetting");
|
|
@@ -128,3 +128,8 @@ var user_emotional_health_1 = require("./user_emotional_health");
|
|
|
128
128
|
Object.defineProperty(exports, "UserEmotionalHealthSchema", { enumerable: true, get: function () { return user_emotional_health_1.UserEmotionalHealthSchema; } });
|
|
129
129
|
var user_emotional_health_detail_1 = require("./user_emotional_health_detail");
|
|
130
130
|
Object.defineProperty(exports, "UserEmotionalHealthDetailSchema", { enumerable: true, get: function () { return user_emotional_health_detail_1.UserEmotionalHealthDetailSchema; } });
|
|
131
|
+
var accessTier_1 = require("./accessTier");
|
|
132
|
+
Object.defineProperty(exports, "AccessFeatureSchema", { enumerable: true, get: function () { return accessTier_1.AccessFeatureSchema; } });
|
|
133
|
+
Object.defineProperty(exports, "AccessTierSchema", { enumerable: true, get: function () { return accessTier_1.AccessTierSchema; } });
|
|
134
|
+
Object.defineProperty(exports, "AccessEntitlementSchema", { enumerable: true, get: function () { return accessTier_1.AccessEntitlementSchema; } });
|
|
135
|
+
Object.defineProperty(exports, "AccessTrialPolicySchema", { enumerable: true, get: function () { return accessTier_1.AccessTrialPolicySchema; } });
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare type TierRecord = {
|
|
2
|
+
key: string;
|
|
3
|
+
includesTierKeys?: string[];
|
|
4
|
+
featureKeys?: string[];
|
|
5
|
+
active?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare type FeatureRecord = {
|
|
8
|
+
key: string;
|
|
9
|
+
active?: boolean;
|
|
10
|
+
chatAvailable?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare type EntitlementWindow = {
|
|
13
|
+
status: string;
|
|
14
|
+
startsAt?: number;
|
|
15
|
+
endsAt?: number | null;
|
|
16
|
+
};
|
|
17
|
+
export declare function entitlementInForce(row: EntitlementWindow, now: number): boolean;
|
|
18
|
+
export declare function expandTierChain(tierKey: string, tiers: Map<string, TierRecord>, visiting?: Set<string>): string[];
|
|
19
|
+
export declare function tiersToGrant(tierKeys: string[], tiers: Map<string, TierRecord>): string[];
|
|
20
|
+
export declare function collectGrantedFeatures(grantedTierKeys: string[], tiers: Map<string, TierRecord>, features: Map<string, FeatureRecord>): {
|
|
21
|
+
tierKeys: string[];
|
|
22
|
+
grantedBy: Map<string, string[]>;
|
|
23
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectGrantedFeatures = exports.tiersToGrant = exports.expandTierChain = exports.entitlementInForce = void 0;
|
|
4
|
+
function entitlementInForce(row, now) {
|
|
5
|
+
if (row.status !== 'active')
|
|
6
|
+
return false;
|
|
7
|
+
if (row.startsAt && row.startsAt > now)
|
|
8
|
+
return false;
|
|
9
|
+
if (row.endsAt && row.endsAt > 0 && row.endsAt <= now)
|
|
10
|
+
return false;
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
exports.entitlementInForce = entitlementInForce;
|
|
14
|
+
function expandTierChain(tierKey, tiers, visiting = new Set()) {
|
|
15
|
+
if (visiting.has(tierKey))
|
|
16
|
+
return [];
|
|
17
|
+
const tier = tiers.get(tierKey);
|
|
18
|
+
if (!tier)
|
|
19
|
+
return [];
|
|
20
|
+
visiting.add(tierKey);
|
|
21
|
+
const chain = [];
|
|
22
|
+
for (const parent of tier.includesTierKeys || []) {
|
|
23
|
+
for (const key of expandTierChain(parent, tiers, visiting)) {
|
|
24
|
+
if (!chain.includes(key))
|
|
25
|
+
chain.push(key);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!chain.includes(tierKey))
|
|
29
|
+
chain.push(tierKey);
|
|
30
|
+
visiting.delete(tierKey);
|
|
31
|
+
return chain;
|
|
32
|
+
}
|
|
33
|
+
exports.expandTierChain = expandTierChain;
|
|
34
|
+
function tiersToGrant(tierKeys, tiers) {
|
|
35
|
+
const chains = new Map();
|
|
36
|
+
for (const key of tierKeys) {
|
|
37
|
+
chains.set(key, new Set(expandTierChain(key, tiers)));
|
|
38
|
+
}
|
|
39
|
+
return tierKeys.filter(key => {
|
|
40
|
+
for (const other of tierKeys) {
|
|
41
|
+
if (other === key)
|
|
42
|
+
continue;
|
|
43
|
+
const otherChain = chains.get(other);
|
|
44
|
+
if (otherChain && otherChain.has(key))
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
exports.tiersToGrant = tiersToGrant;
|
|
51
|
+
function collectGrantedFeatures(grantedTierKeys, tiers, features) {
|
|
52
|
+
const tierKeys = [];
|
|
53
|
+
const seenTiers = new Set();
|
|
54
|
+
for (const key of grantedTierKeys) {
|
|
55
|
+
for (const expanded of expandTierChain(key, tiers)) {
|
|
56
|
+
if (seenTiers.has(expanded))
|
|
57
|
+
continue;
|
|
58
|
+
seenTiers.add(expanded);
|
|
59
|
+
tierKeys.push(expanded);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const grantedBy = new Map();
|
|
63
|
+
for (const tierKey of tierKeys) {
|
|
64
|
+
const tier = tiers.get(tierKey);
|
|
65
|
+
if (!tier)
|
|
66
|
+
continue;
|
|
67
|
+
for (const featureKey of tier.featureKeys || []) {
|
|
68
|
+
const feature = features.get(featureKey);
|
|
69
|
+
if (!feature || feature.active === false)
|
|
70
|
+
continue;
|
|
71
|
+
const sources = grantedBy.get(featureKey) || [];
|
|
72
|
+
sources.push(tierKey);
|
|
73
|
+
grantedBy.set(featureKey, sources);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return { tierKeys, grantedBy };
|
|
77
|
+
}
|
|
78
|
+
exports.collectGrantedFeatures = collectGrantedFeatures;
|