From a1718875d9d8d10e91db344ee2defbc1abe09a48 Mon Sep 17 00:00:00 2001 From: Emily Date: Fri, 31 Jan 2025 18:46:13 +0100 Subject: [PATCH] remove shared --- dashboard/.gitignore | 2 + dashboard/shared/data/ADMINS.ts | 5 - dashboard/shared/data/PREMIUM.ts | 184 -------------- dashboard/shared/data/broker/Limits.ts | 5 - dashboard/shared/schema/ApiSettingsSchema.ts | 20 -- dashboard/shared/schema/FeedbackSchema.ts | 16 -- dashboard/shared/schema/OnboardingSchema.ts | 16 -- dashboard/shared/schema/PasswordSchema.ts | 14 -- dashboard/shared/schema/RegisterSchema.ts | 16 -- dashboard/shared/schema/TeamMemberSchema.ts | 22 -- dashboard/shared/schema/UserSchema.ts | 38 --- dashboard/shared/schema/UserSettings.ts | 16 -- dashboard/shared/schema/ai/AiChatSchema.ts | 26 -- .../schema/anomalies/AnomalyDomainSchema.ts | 16 -- .../schema/anomalies/AnomalyEventsSchema.ts | 16 -- .../schema/anomalies/AnomalyVisitSchema.ts | 16 -- .../schema/appsumo/AppsumoCodeSchema.ts | 16 -- .../schema/appsumo/AppsumoCodeTrySchema.ts | 15 -- .../shared/schema/broker/LimitNotifySchema.ts | 18 -- .../shared/schema/metrics/EventSchema.ts | 22 -- .../shared/schema/metrics/SessionSchema.ts | 23 -- .../shared/schema/metrics/VisitSchema.ts | 45 ---- .../shared/schema/project/ProjectSchema.ts | 26 -- .../shared/schema/project/ProjectSnapshot.ts | 20 -- .../shared/schema/project/ProjectsCounts.ts | 22 -- .../shared/schema/project/ProjectsLimits.ts | 26 -- dashboard/shared/services/DateService.ts | 224 ------------------ dashboard/shared/services/EmailService.ts | 35 --- 28 files changed, 2 insertions(+), 918 deletions(-) delete mode 100644 dashboard/shared/data/ADMINS.ts delete mode 100644 dashboard/shared/data/PREMIUM.ts delete mode 100644 dashboard/shared/data/broker/Limits.ts delete mode 100644 dashboard/shared/schema/ApiSettingsSchema.ts delete mode 100644 dashboard/shared/schema/FeedbackSchema.ts delete mode 100644 dashboard/shared/schema/OnboardingSchema.ts delete mode 100644 dashboard/shared/schema/PasswordSchema.ts delete mode 100644 dashboard/shared/schema/RegisterSchema.ts delete mode 100644 dashboard/shared/schema/TeamMemberSchema.ts delete mode 100644 dashboard/shared/schema/UserSchema.ts delete mode 100644 dashboard/shared/schema/UserSettings.ts delete mode 100644 dashboard/shared/schema/ai/AiChatSchema.ts delete mode 100644 dashboard/shared/schema/anomalies/AnomalyDomainSchema.ts delete mode 100644 dashboard/shared/schema/anomalies/AnomalyEventsSchema.ts delete mode 100644 dashboard/shared/schema/anomalies/AnomalyVisitSchema.ts delete mode 100644 dashboard/shared/schema/appsumo/AppsumoCodeSchema.ts delete mode 100644 dashboard/shared/schema/appsumo/AppsumoCodeTrySchema.ts delete mode 100644 dashboard/shared/schema/broker/LimitNotifySchema.ts delete mode 100644 dashboard/shared/schema/metrics/EventSchema.ts delete mode 100644 dashboard/shared/schema/metrics/SessionSchema.ts delete mode 100644 dashboard/shared/schema/metrics/VisitSchema.ts delete mode 100644 dashboard/shared/schema/project/ProjectSchema.ts delete mode 100644 dashboard/shared/schema/project/ProjectSnapshot.ts delete mode 100644 dashboard/shared/schema/project/ProjectsCounts.ts delete mode 100644 dashboard/shared/schema/project/ProjectsLimits.ts delete mode 100644 dashboard/shared/services/DateService.ts delete mode 100644 dashboard/shared/services/EmailService.ts diff --git a/dashboard/.gitignore b/dashboard/.gitignore index 06b4ddf..96e1eba 100644 --- a/dashboard/.gitignore +++ b/dashboard/.gitignore @@ -39,3 +39,5 @@ explains #Ecosystem ecosystem.config.cjs ecosystem.config.js + +shared diff --git a/dashboard/shared/data/ADMINS.ts b/dashboard/shared/data/ADMINS.ts deleted file mode 100644 index 4383529..0000000 --- a/dashboard/shared/data/ADMINS.ts +++ /dev/null @@ -1,5 +0,0 @@ -export const ADMIN_EMAILS = [ - 'laura.emily.lovi@gmail.com', - 'mangaiomaster@gmail.com', - 'helplitlyx@gmail.com' -] \ No newline at end of file diff --git a/dashboard/shared/data/PREMIUM.ts b/dashboard/shared/data/PREMIUM.ts deleted file mode 100644 index 0ff4b1c..0000000 --- a/dashboard/shared/data/PREMIUM.ts +++ /dev/null @@ -1,184 +0,0 @@ -export type PREMIUM_TAG = typeof PREMIUM_TAGS[number]; - -export const PREMIUM_TAGS = [ - 'FREE', - 'PLAN_1', - 'PLAN_2', - 'CUSTOM_1', - 'INCUBATION', - 'ACCELERATION', - 'GROWTH', - 'EXPANSION', - 'SCALING', - 'UNICORN', - 'LIFETIME_GROWTH_ONETIME', - 'GROWTH_DUMMY', - 'APPSUMO_INCUBATION', - 'APPSUMO_ACCELERATION', - 'APPSUMO_GROWTH', - 'APPSUMO_UNICORN' -] as const; - - -export type PREMIUM_DATA = { - COUNT_LIMIT: number, - AI_MESSAGE_LIMIT: number, - PRICE: string, - PRICE_TEST: string, - ID: number, - COST: number -} - -export const PREMIUM_PLAN: Record = { - FREE: { - ID: 0, - COUNT_LIMIT: 5_000, - AI_MESSAGE_LIMIT: 10, - PRICE: 'price_1POKCMB2lPUiVs9VLe3QjIHl', - PRICE_TEST: 'price_1PNbHYB2lPUiVs9VZP32xglF', - COST: 0 - }, - PLAN_1: { - ID: 1, - COUNT_LIMIT: 150_000, - AI_MESSAGE_LIMIT: 100, - PRICE: 'price_1POKCOB2lPUiVs9VC13s2rQw', - PRICE_TEST: 'price_1PNZjVB2lPUiVs9VrsTbJL04', - COST: 0 - }, - PLAN_2: { - ID: 2, - COUNT_LIMIT: 500_000, - AI_MESSAGE_LIMIT: 5_000, - PRICE: 'price_1POKCKB2lPUiVs9Vol8XOmhW', - PRICE_TEST: 'price_1POK34B2lPUiVs9VIROb0IIV', - COST: 0 - }, - CUSTOM_1: { - ID: 1001, - COUNT_LIMIT: 10_000_000, - AI_MESSAGE_LIMIT: 100_000, - PRICE: 'price_1POKZyB2lPUiVs9VMAY6jXTV', - PRICE_TEST: '', - COST: 0 - }, - INCUBATION: { - ID: 101, - COUNT_LIMIT: 50_000, - AI_MESSAGE_LIMIT: 30, - PRICE: 'price_1PdsyzB2lPUiVs9V4J246Jw0', - PRICE_TEST: '', - COST: 499 - }, - ACCELERATION: { - ID: 102, - COUNT_LIMIT: 150_000, - AI_MESSAGE_LIMIT: 100, - PRICE: 'price_1Pdt5bB2lPUiVs9VhkuCouEt', - PRICE_TEST: '', - COST: 999 - }, - GROWTH: { - ID: 103, - COUNT_LIMIT: 500_000, - AI_MESSAGE_LIMIT: 3_000, - PRICE: 'price_1PdszrB2lPUiVs9VIdkT3thv', - PRICE_TEST: '', - COST: 2999 - }, - EXPANSION: { - ID: 104, - COUNT_LIMIT: 1_000_000, - AI_MESSAGE_LIMIT: 5_000, - PRICE: 'price_1Pdt0xB2lPUiVs9V0Rdt80Fe', - PRICE_TEST: '', - COST: 5999 - }, - SCALING: { - ID: 105, - COUNT_LIMIT: 2_500_000, - AI_MESSAGE_LIMIT: 10_000, - PRICE: 'price_1Pdt1UB2lPUiVs9VUmxntSwZ', - PRICE_TEST: '', - COST: 9999 - }, - UNICORN: { - ID: 106, - COUNT_LIMIT: 5_000_000, - AI_MESSAGE_LIMIT: 20_000, - PRICE: 'price_1Pdt2LB2lPUiVs9VGBFAIG9G', - PRICE_TEST: '', - COST: 14999 - }, - LIFETIME_GROWTH_ONETIME: { - ID: 2001, - COUNT_LIMIT: 500_000, - AI_MESSAGE_LIMIT: 3_000, - PRICE: 'price_1PvewGB2lPUiVs9VLheJC8s1', - PRICE_TEST: 'price_1Pvf7LB2lPUiVs9VMFNyzpim', - COST: 239900 - }, - GROWTH_DUMMY: { - ID: 5001, - COUNT_LIMIT: 500_000, - AI_MESSAGE_LIMIT: 3_000, - PRICE: 'price_1PvgoRB2lPUiVs9VC51YBT7J', - PRICE_TEST: 'price_1PvgRTB2lPUiVs9V3kFSNC3G', - COST: 0 - }, - APPSUMO_INCUBATION: { - ID: 6001, - COUNT_LIMIT: 50_000, - AI_MESSAGE_LIMIT: 30, - PRICE: 'price_1QIXwbB2lPUiVs9VKSsoksaU', - PRICE_TEST: '', - COST: 0 - }, - APPSUMO_ACCELERATION: { - ID: 6002, - COUNT_LIMIT: 150_000, - AI_MESSAGE_LIMIT: 100, - PRICE: 'price_1QIXxRB2lPUiVs9VrjaVRoOl', - PRICE_TEST: '', - COST: 0 - }, - APPSUMO_GROWTH: { - ID: 6003, - COUNT_LIMIT: 500_000, - AI_MESSAGE_LIMIT: 3_000, - PRICE: 'price_1QIXy8B2lPUiVs9VQBOUPAoE', - PRICE_TEST: '', - COST: 0 - }, - APPSUMO_UNICORN: { - ID: 6006, - COUNT_LIMIT: 5_000_000, - AI_MESSAGE_LIMIT: 20_000, - PRICE: 'price_1Qls1lB2lPUiVs9VI6ej8hwE', - PRICE_TEST: '', - COST: 0 - } -} - -export function getPlanFromTag(tag: PREMIUM_TAG) { - return PREMIUM_PLAN[tag]; -} - -export function getPlanFromId(id: number) { - for (const tag of PREMIUM_TAGS) { - const plan = getPlanFromTag(tag); - if (plan.ID === id) return plan; - } -} - -export function getPlanFromPrice(price: string, testMode: boolean) { - for (const tag of PREMIUM_TAGS) { - const plan = getPlanFromTag(tag); - if (testMode) { - if (plan.PRICE_TEST === price) return plan; - } else { - if (plan.PRICE === price) return plan; - } - - } -} \ No newline at end of file diff --git a/dashboard/shared/data/broker/Limits.ts b/dashboard/shared/data/broker/Limits.ts deleted file mode 100644 index fd28d88..0000000 --- a/dashboard/shared/data/broker/Limits.ts +++ /dev/null @@ -1,5 +0,0 @@ - - -// Default: 1.01 -// ((events + visits) * VALUE) > limit -export const MAX_LOG_LIMIT_PERCENT = 1.01; \ No newline at end of file diff --git a/dashboard/shared/schema/ApiSettingsSchema.ts b/dashboard/shared/schema/ApiSettingsSchema.ts deleted file mode 100644 index 61f8681..0000000 --- a/dashboard/shared/schema/ApiSettingsSchema.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - -export type TApiSettings = { - _id: Schema.Types.ObjectId, - project_id: Schema.Types.ObjectId, - apiKey: string, - apiName: string, - usage: number, - created_at: Date -} - -const ApiSettingsSchema = new Schema({ - project_id: { type: Types.ObjectId, index: 1 }, - apiKey: { type: String, required: true }, - apiName: { type: String, required: true }, - usage: { type: Number, default: 0, required: true, }, - created_at: { type: Date, default: () => Date.now() }, -}); - -export const ApiSettingsModel = model('api_settings', ApiSettingsSchema); diff --git a/dashboard/shared/schema/FeedbackSchema.ts b/dashboard/shared/schema/FeedbackSchema.ts deleted file mode 100644 index 4078e0e..0000000 --- a/dashboard/shared/schema/FeedbackSchema.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - -export type TFeedback = { - user_id: Types.ObjectId, - project_id: Types.ObjectId, - text: string -} - -const FeedbackSchema = new Schema({ - user_id: { type: Schema.Types.ObjectId, required: true }, - project_id: { type: Schema.Types.ObjectId, required: true }, - text: { type: String, required: true }, -}); - -export const FeedbackModel = model('feedbacks', FeedbackSchema); - diff --git a/dashboard/shared/schema/OnboardingSchema.ts b/dashboard/shared/schema/OnboardingSchema.ts deleted file mode 100644 index b4cc6ed..0000000 --- a/dashboard/shared/schema/OnboardingSchema.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - -export type TOnboarding = { - user_id: Types.ObjectId, - analytics: string, - job: string -} - -const OnboardingSchema = new Schema({ - user_id: { type: Schema.Types.ObjectId, required: true }, - analytics: { type: String, required: false }, - job: { type: String, required: false }, -}); - -export const OnboardingModel = model('onboardings', OnboardingSchema); - diff --git a/dashboard/shared/schema/PasswordSchema.ts b/dashboard/shared/schema/PasswordSchema.ts deleted file mode 100644 index a15a2e0..0000000 --- a/dashboard/shared/schema/PasswordSchema.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - -export type TPassword = { - email: string, - password: string, -} - -const PasswordSchema = new Schema({ - email: { type: String, index: true, unique: true }, - password: { type: String }, -}); - -export const PasswordModel = model('passwords', PasswordSchema); - diff --git a/dashboard/shared/schema/RegisterSchema.ts b/dashboard/shared/schema/RegisterSchema.ts deleted file mode 100644 index 2834d48..0000000 --- a/dashboard/shared/schema/RegisterSchema.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - -export type TRegister = { - email: string, - password: string, - created_at: Date -} - -const RegisterSchema = new Schema({ - email: { type: String }, - password: { type: String }, - created_at: { type: Date, default: () => Date.now() } -}); - -export const RegisterModel = model('registers', RegisterSchema); - diff --git a/dashboard/shared/schema/TeamMemberSchema.ts b/dashboard/shared/schema/TeamMemberSchema.ts deleted file mode 100644 index 11d5a84..0000000 --- a/dashboard/shared/schema/TeamMemberSchema.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - -export type TeamMemberRole = 'ADMIN' | 'GUEST'; - -export type TTeamMember = { - _id: Schema.Types.ObjectId, - project_id: Schema.Types.ObjectId, - user_id: Schema.Types.ObjectId, - role: TeamMemberRole, - pending: boolean, - created_at: Date, -} - -const TeamMemberSchema = new Schema({ - project_id: { type: Types.ObjectId, index: true }, - user_id: { type: Types.ObjectId, index: true }, - role: { type: String, required: true }, - pending: { type: Boolean, required: true }, - created_at: { type: Date, required: true, default: () => Date.now() }, -}); - -export const TeamMemberModel = model('team_members', TeamMemberSchema); \ No newline at end of file diff --git a/dashboard/shared/schema/UserSchema.ts b/dashboard/shared/schema/UserSchema.ts deleted file mode 100644 index d312393..0000000 --- a/dashboard/shared/schema/UserSchema.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - -export type TUser = { - email: string, - name: string, - given_name: string, - locale: string, - picture: string, - created_at: Date, - google_tokens?: { - refresh_token?: string; - expiry_date?: number; - access_token?: string; - token_type?: string; - id_token?: string; - scope?: string; - } -} - -const UserSchema = new Schema({ - email: { type: String, unique: true, index: 1 }, - name: String, - given_name: String, - locale: String, - picture: String, - google_tokens: { - refresh_token: String, - expiry_date: Number, - access_token: String, - token_type: String, - id_token: String, - scope: String - }, - created_at: { type: Date, default: () => Date.now() } -}) - -export const UserModel = model('users', UserSchema); - diff --git a/dashboard/shared/schema/UserSettings.ts b/dashboard/shared/schema/UserSettings.ts deleted file mode 100644 index c1faa57..0000000 --- a/dashboard/shared/schema/UserSettings.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - -export type TUserSettings = { - user_id: Schema.Types.ObjectId, - max_projects: number, - active_project_id: Schema.Types.ObjectId -} - -const UserSettingsSchema = new Schema({ - user_id: { type: Types.ObjectId, unique: true, index: 1 }, - max_projects: { type: Number, default: 3 }, - active_project_id: Schema.Types.ObjectId, -}); - -export const UserSettingsModel = model('user_settings', UserSettingsSchema); - diff --git a/dashboard/shared/schema/ai/AiChatSchema.ts b/dashboard/shared/schema/ai/AiChatSchema.ts deleted file mode 100644 index 934f4b0..0000000 --- a/dashboard/shared/schema/ai/AiChatSchema.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { model, Schema } from 'mongoose'; - -export type TAiChatSchema = { - _id: Schema.Types.ObjectId, - project_id: Schema.Types.ObjectId, - messages: any[], - status: string, - completed: boolean, - title: string, - deleted: boolean, - created_at: Date, - updated_at: Date -} - -const AiChatSchema = new Schema({ - project_id: { type: Schema.Types.ObjectId, index: 1 }, - status: { type: String }, - completed: { type: Boolean }, - messages: [{ _id: false, type: Schema.Types.Mixed }], - title: { type: String, required: true }, - deleted: { type: Boolean, default: false }, - created_at: { type: Date, default: () => Date.now() }, - updated_at: { type: Date, default: () => Date.now() }, -}); - -export const AiChatModel = model('ai_chats', AiChatSchema); \ No newline at end of file diff --git a/dashboard/shared/schema/anomalies/AnomalyDomainSchema.ts b/dashboard/shared/schema/anomalies/AnomalyDomainSchema.ts deleted file mode 100644 index a67f575..0000000 --- a/dashboard/shared/schema/anomalies/AnomalyDomainSchema.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - - -export type TAnomalyDomain = { - project_id: Schema.Types.ObjectId - domain: string, - created_at: Date -} - -const AnomalyDomainSchema = new Schema({ - project_id: { type: Types.ObjectId, required: true }, - domain: { type: String, required: true }, - created_at: { type: Date, required: true }, -}) - -export const AnomalyDomainModel = model('anomaly_domains', AnomalyDomainSchema); diff --git a/dashboard/shared/schema/anomalies/AnomalyEventsSchema.ts b/dashboard/shared/schema/anomalies/AnomalyEventsSchema.ts deleted file mode 100644 index b0f5348..0000000 --- a/dashboard/shared/schema/anomalies/AnomalyEventsSchema.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - - -export type TAnomalyEvents = { - project_id: Schema.Types.ObjectId - eventDate: Date, - created_at: Date -} - -const AnomalyEventsSchema = new Schema({ - project_id: { type: Types.ObjectId, required: true }, - eventDate: { type: Date, required: true }, - created_at: { type: Date, required: true }, -}) - -export const AnomalyEventsModel = model('anomaly_events', AnomalyEventsSchema); diff --git a/dashboard/shared/schema/anomalies/AnomalyVisitSchema.ts b/dashboard/shared/schema/anomalies/AnomalyVisitSchema.ts deleted file mode 100644 index 6faf0b4..0000000 --- a/dashboard/shared/schema/anomalies/AnomalyVisitSchema.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - - -export type TAnomalyVisit = { - project_id: Schema.Types.ObjectId - visitDate: Date, - created_at: Date -} - -const AnomalyVisitSchema = new Schema({ - project_id: { type: Types.ObjectId, required: true }, - visitDate: { type: Date, required: true }, - created_at: { type: Date, required: true }, -}) - -export const AnomalyVisitModel = model('anomaly_visits', AnomalyVisitSchema); diff --git a/dashboard/shared/schema/appsumo/AppsumoCodeSchema.ts b/dashboard/shared/schema/appsumo/AppsumoCodeSchema.ts deleted file mode 100644 index ec594c3..0000000 --- a/dashboard/shared/schema/appsumo/AppsumoCodeSchema.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - -export type TAppsumoCode = { - _id: Schema.Types.ObjectId, - code: string, - used_at: Date, - created_at?: Date, -} - -const AppsumoCodeSchema = new Schema({ - code: { type: String, index: 1 }, - created_at: { type: Date, default: () => Date.now() }, - used_at: { type: Date, required: false }, -}); - -export const AppsumoCodeModel = model('appsumo_codes', AppsumoCodeSchema); diff --git a/dashboard/shared/schema/appsumo/AppsumoCodeTrySchema.ts b/dashboard/shared/schema/appsumo/AppsumoCodeTrySchema.ts deleted file mode 100644 index a5f9db1..0000000 --- a/dashboard/shared/schema/appsumo/AppsumoCodeTrySchema.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - -export type TAppsumoCodeTry = { - project_id: Types.ObjectId, - codes: string[], - valid_codes: string[], -} - -const AppsumoCodeTrySchema = new Schema({ - project_id: { type: Schema.Types.ObjectId, required: true, unique: true, index: 1 }, - codes: [{ type: String }], - valid_codes: [{ type: String }] -}); - -export const AppsumoCodeTryModel = model('appsumo_codes_tries', AppsumoCodeTrySchema); diff --git a/dashboard/shared/schema/broker/LimitNotifySchema.ts b/dashboard/shared/schema/broker/LimitNotifySchema.ts deleted file mode 100644 index c1ec3d6..0000000 --- a/dashboard/shared/schema/broker/LimitNotifySchema.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - -export type TLimitNotify = { - _id: Schema.Types.ObjectId, - project_id: Schema.Types.ObjectId, - limit1: boolean, - limit2: boolean, - limit3: boolean -} - -const LimitNotifySchema = new Schema({ - project_id: { type: Types.ObjectId, index: 1 }, - limit1: { type: Boolean }, - limit2: { type: Boolean }, - limit3: { type: Boolean } -}); - -export const LimitNotifyModel = model('limit_notifies', LimitNotifySchema); \ No newline at end of file diff --git a/dashboard/shared/schema/metrics/EventSchema.ts b/dashboard/shared/schema/metrics/EventSchema.ts deleted file mode 100644 index 17ffc2b..0000000 --- a/dashboard/shared/schema/metrics/EventSchema.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - -export type TEvent = { - project_id: Schema.Types.ObjectId, - name: string, - metadata: Record, - session: string, - flowHash: string, - created_at: Date -} - -const EventSchema = new Schema({ - project_id: { type: Types.ObjectId, index: 1 }, - name: { type: String, required: true, index: 1 }, - metadata: Schema.Types.Mixed, - session: { type: String, index: 1 }, - flowHash: { type: String }, - created_at: { type: Date, default: () => Date.now(), index: true }, -}) - -export const EventModel = model('events', EventSchema); - diff --git a/dashboard/shared/schema/metrics/SessionSchema.ts b/dashboard/shared/schema/metrics/SessionSchema.ts deleted file mode 100644 index 152e534..0000000 --- a/dashboard/shared/schema/metrics/SessionSchema.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - - -export type TSession = { - project_id: Schema.Types.ObjectId, - session: string, - flowHash: string, - duration: number, - updated_at: Date, - created_at: Date, -} - -const SessionSchema = new Schema({ - project_id: { type: Types.ObjectId, index: 1 }, - session: { type: String, required: true, index: 1 }, - flowHash: { type: String }, - duration: { type: Number, required: true, default: 0 }, - updated_at: { type: Date, default: () => Date.now() }, - created_at: { type: Date, default: () => Date.now(), index: true }, -}) - -export const SessionModel = model('sessions', SessionSchema); - diff --git a/dashboard/shared/schema/metrics/VisitSchema.ts b/dashboard/shared/schema/metrics/VisitSchema.ts deleted file mode 100644 index 8981baa..0000000 --- a/dashboard/shared/schema/metrics/VisitSchema.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { model, Schema } from 'mongoose'; - -export type TVisit = { - project_id: Schema.Types.ObjectId, - - browser: string, - os: string, - - continent: string, - country: string, - - session: string, - flowHash: string, - device: string, - - website: string, - page: string, - referrer: string, - - created_at: Date -} - -const VisitSchema = new Schema({ - project_id: { type: Schema.Types.ObjectId, index: true }, - - browser: { type: String, required: true }, - os: { type: String, required: true }, - - continent: { type: String }, - country: { type: String }, - - session: { type: String, index: true }, - flowHash: { type: String }, - device: { type: String }, - - website: { type: String, required: true, index: true }, - page: { type: String, required: true }, - referrer: { type: String, required: true }, - created_at: { type: Date, default: () => Date.now() }, -}) - -VisitSchema.index({ project_id: 1, created_at: -1 }); - -export const VisitModel = model('visits', VisitSchema); - diff --git a/dashboard/shared/schema/project/ProjectSchema.ts b/dashboard/shared/schema/project/ProjectSchema.ts deleted file mode 100644 index 5470139..0000000 --- a/dashboard/shared/schema/project/ProjectSchema.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - -export type TProject = { - _id: Schema.Types.ObjectId, - owner: Schema.Types.ObjectId, - name: string, - premium: boolean, - premium_type: number, - customer_id: string, - subscription_id: string, - premium_expire_at: Date, - created_at: Date -} - -const ProjectSchema = new Schema({ - owner: { type: Types.ObjectId, index: 1 }, - name: { type: String, required: true }, - premium: { type: Boolean, default: false }, - premium_type: { type: Number, default: 0 }, - customer_id: { type: String, required: true }, - subscription_id: { type: String, required: true }, - premium_expire_at: { type: Date, required: true }, - created_at: { type: Date, default: () => Date.now() }, -}) - -export const ProjectModel = model('projects', ProjectSchema); diff --git a/dashboard/shared/schema/project/ProjectSnapshot.ts b/dashboard/shared/schema/project/ProjectSnapshot.ts deleted file mode 100644 index 7dbcc28..0000000 --- a/dashboard/shared/schema/project/ProjectSnapshot.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - -export type TProjectSnapshot = { - _id: Schema.Types.ObjectId, - project_id: Schema.Types.ObjectId, - name: string, - from: Date, - to: Date, - color: string -} - -const ProjectSnapshotSchema = new Schema({ - project_id: { type: Types.ObjectId, index: true }, - name: { type: String, required: true }, - from: { type: Date, required: true }, - to: { type: Date, required: true }, - color: { type: String, required: true }, -}); - -export const ProjectSnapshotModel = model('project_snapshots', ProjectSnapshotSchema); \ No newline at end of file diff --git a/dashboard/shared/schema/project/ProjectsCounts.ts b/dashboard/shared/schema/project/ProjectsCounts.ts deleted file mode 100644 index bf4124b..0000000 --- a/dashboard/shared/schema/project/ProjectsCounts.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - -export type TProjectCount = { - _id: Schema.Types.ObjectId, - project_id: Schema.Types.ObjectId, - events: number, - visits: number, - sessions: number, - lastRecheck?: Date, - updated_at: Date -} - -const ProjectCountSchema = new Schema({ - project_id: { type: Types.ObjectId, index: true, unique: true }, - events: { type: Number, required: true, default: 0 }, - visits: { type: Number, required: true, default: 0 }, - sessions: { type: Number, required: true, default: 0 }, - lastRecheck: { type: Date }, - updated_at: { type: Date } -}, { timestamps: { updatedAt: 'updated_at' } }); - -export const ProjectCountModel = model('project_counts', ProjectCountSchema); \ No newline at end of file diff --git a/dashboard/shared/schema/project/ProjectsLimits.ts b/dashboard/shared/schema/project/ProjectsLimits.ts deleted file mode 100644 index b619225..0000000 --- a/dashboard/shared/schema/project/ProjectsLimits.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { model, Schema, Types } from 'mongoose'; - -export type TProjectLimit = { - _id: Schema.Types.ObjectId, - project_id: Schema.Types.ObjectId, - events: number, - visits: number, - ai_messages: number, - limit: number, - ai_limit: number, - billing_expire_at: Date, - billing_start_at: Date, -} - -const ProjectLimitSchema = new Schema({ - project_id: { type: Types.ObjectId, index: true, unique: true }, - events: { type: Number, required: true, default: 0 }, - visits: { type: Number, required: true, default: 0 }, - ai_messages: { type: Number, required: true, default: 0 }, - limit: { type: Number, required: true }, - ai_limit: { type: Number, required: true }, - billing_start_at: { type: Date, required: true }, - billing_expire_at: { type: Date, required: true }, -}); - -export const ProjectLimitModel = model('project_limits', ProjectLimitSchema); \ No newline at end of file diff --git a/dashboard/shared/services/DateService.ts b/dashboard/shared/services/DateService.ts deleted file mode 100644 index 1bc2c63..0000000 --- a/dashboard/shared/services/DateService.ts +++ /dev/null @@ -1,224 +0,0 @@ - -import dayjs from 'dayjs'; -import * as fns from 'date-fns'; - -export type Slice = keyof typeof slicesData; - -const slicesData = { - hour: {}, - day: {}, - week: {}, - month: {}, - year: {} -} - -const startOfFunctions: { [key in Slice]: (date: Date) => Date } = { - hour: fns.startOfHour, - day: fns.startOfDay, - week: fns.startOfWeek, - month: fns.startOfMonth, - year: fns.startOfYear -}; - -const endOfFunctions: { [key in Slice]: (date: Date) => Date } = { - hour: fns.endOfHour, - day: fns.endOfDay, - week: fns.endOfWeek, - month: fns.endOfMonth, - year: fns.endOfYear -}; - -class DateService { - - public slicesData = slicesData; - - getChartLabelFromISO(iso: string, offset: number, slice: Slice) { - const date = new Date(new Date(iso).getTime() + offset * 1000 * 60); - if (slice === 'hour') return fns.format(date, 'HH:mm'); - if (slice === 'day') return fns.format(date, 'dd/MM'); - if (slice === 'week') return fns.format(date, 'dd/MM'); - if (slice === 'month') return fns.format(date, 'MMMM'); - if (slice === 'year') return fns.format(date, 'YYYY'); - return iso; - } - - canUseSlice(from: string | number | Date, to: string | number | Date, slice: Slice) { - - const daysDiff = fns.differenceInDays( - new Date(new Date(to).getTime() + 1000), - new Date(from) - ); - - return this.canUseSliceFromDays(daysDiff, slice); - } - - canUseSliceFromDays(days: number, slice: Slice): [false, string] | [true, number] { - - // 3 Days - if (slice === 'hour' && (days > 3)) return [false, 'Date gap too big for this slice']; - // 3 Weeks - if (slice === 'day' && (days > 31)) return [false, 'Date gap too big for this slice']; - // 3 Years - if (slice === 'month' && (days > 365 * 3)) return [false, 'Date gap too big for this slice']; - - // 2 days - if (slice === 'day' && (days < 2)) return [false, 'Date gap too small for this slice']; - // 2 month - if (slice === 'month' && (days < 31 * 2)) return [false, 'Date gap too small for this slice']; - - return [true, days] - } - - startOfSlice(date: Date, slice: Slice) { - const fn = startOfFunctions[slice]; - if (!fn) throw Error(`startOfFunction of slice ${slice} not found`); - return fn(date); - } - - endOfSlice(date: Date, slice: Slice) { - const fn = endOfFunctions[slice]; - if (!fn) throw Error(`endOfFunction of slice ${slice} not found`); - return fn(date); - } - - - getGranularityData(slice: Slice, dateField: string) { - - const dateFromParts: Record = {}; - let granularity; - - switch (slice) { - case 'hour': - dateFromParts.hour = { $hour: { date: dateField } } - granularity = granularity || 'hour'; - case 'day': - dateFromParts.day = { $dayOfMonth: { date: dateField } } - granularity = granularity || 'day'; - case 'month': - dateFromParts.month = { $month: { date: dateField } } - granularity = granularity || 'month'; - case 'year': - dateFromParts.year = { $year: { date: dateField } } - granularity = granularity || 'year'; - } - - return { dateFromParts, granularity } - } - - /** - * @deprecated interal to generateDateSlices - */ - prepareDateRange(from: string, to: string, slice: Slice) { - - let fromDate = dayjs(from).minute(0).second(0).millisecond(0); - let toDate = dayjs(to).minute(0).second(0).millisecond(0); - - switch (slice) { - case 'day': - fromDate = fromDate.hour(0); - toDate = toDate.hour(0); - break; - case 'hour': - break; - } - - return { - from: fromDate.toDate(), - to: toDate.toDate() - } - } - - /** - * @deprecated interal to generateDateSlices - */ - createBetweenDates(from: string, to: string, slice: Slice) { - let start = dayjs(from); - const end = dayjs(to); - const filledDates: dayjs.Dayjs[] = []; - while (start.isBefore(end) || start.isSame(end)) { - filledDates.push(start); - start = start.add(1, slice); - } - return { dates: filledDates, from, to }; - } - - /** - * @deprecated use generateDateSlices - */ - fillDates(dates: string[], slice: Slice) { - const allDates: dayjs.Dayjs[] = []; - const firstDate = dayjs(dates.at(0)); - const lastDate = dayjs(dates.at(-1)); - let currentDate = firstDate.clone(); - - allDates.push(currentDate); - - while (currentDate.isBefore(lastDate, slice)) { - currentDate = currentDate.add(1, slice); - allDates.push(currentDate); - } - - return allDates; - } - - /** - * @deprecated use mergeDates - */ - mergeFilledDates, K extends keyof T>(dates: dayjs.Dayjs[], items: T[], dateField: K, slice: Slice, fillData: Omit) { - const result = new Array(); - for (const date of dates) { - const item = items.find(e => dayjs(e[dateField]).isSame(date, slice)); - result.push(item ?? { ...fillData, [dateField]: date.format() } as T); - } - return result; - } - - generateDateSlices(slice: Slice, fromDate: Date, toDate: Date) { - const slices: Date[] = []; - let currentDate = fromDate; - const addFunctions: { [key in Slice]: any } = { hour: fns.addHours, day: fns.addDays, week: fns.addWeeks, month: fns.addMonths, year: fns.addYears }; - const addFunction = addFunctions[slice]; - if (!addFunction) { throw new Error(`Invalid slice: ${slice}`); } - while (fns.isBefore(currentDate, toDate) || currentDate.getTime() === toDate.getTime()) { - slices.push(currentDate); - currentDate = addFunction(currentDate, 1); - } - return slices; - } - - isSameDayUTC(a: Date, b: Date) { - return a.getUTCFullYear() === b.getUTCFullYear() && a.getUTCMonth() === b.getUTCMonth() && a.getUTCDate() === b.getUTCDate(); - } - - mergeDates(timeline: { _id: string, count: number }[], allDates: Date[], slice: Slice) { - - const result: { _id: string, count: number }[] = []; - - const isSames: { [key in Slice]: any } = { hour: fns.isSameHour, day: this.isSameDayUTC, week: fns.isSameWeek, month: fns.isSameMonth, year: fns.isSameYear, } - - const isSame = isSames[slice]; - - if (!isSame) { - throw new Error(`Invalid slice: ${slice}`); - } - - for (const date of allDates) { - result.push({ _id: date.toISOString(), count: 0 }); - for (const element of timeline) { - const elementDate = new Date(element._id); - if (isSame(elementDate, date)) { - const existingEntry = result.find(item => isSame(date, new Date(item._id))); - if (!existingEntry) throw new Error('THIS CANNOT HAPPEN'); - existingEntry.count += element.count; - } - } - } - - return result; - } - - -} - -const dateServiceInstance = new DateService(); -export default dateServiceInstance; diff --git a/dashboard/shared/services/EmailService.ts b/dashboard/shared/services/EmailService.ts deleted file mode 100644 index 30759f2..0000000 --- a/dashboard/shared/services/EmailService.ts +++ /dev/null @@ -1,35 +0,0 @@ -const templateMap = { - confirm: '/confirm', - welcome: '/welcome', - purchase: '/purchase', - reset_password: '/reset_password', - anomaly_domain: '/anomaly/domain', - anomaly_visits_events: '/anomaly_visits_events', - limit_50: '/limit/50', - limit_90: '/limit/90', - limit_max: '/limit/max', -} as const; - -export type EmailTemplate = keyof typeof templateMap; -export type EmailServerInfo = { url: string, body: Record, headers: Record }; - -type EmailData = - | { template: 'confirm', data: { target: string, link: string } } - | { template: 'welcome', data: { target: string } } - | { template: 'purchase', data: { target: string, projectName: string } } - | { template: 'reset_password', data: { target: string, newPassword: string } } - | { template: 'anomaly_domain', data: { target: string, projectName: string, domains: string[] } } - | { template: 'anomaly_visits_events', data: { target: string, projectName: string, data: any[] } } - | { template: 'limit_50', data: { target: string, projectName: string } } - | { template: 'limit_90', data: { target: string, projectName: string } } - | { template: 'limit_max', data: { target: string, projectName: string } }; - -export class EmailService { - static getEmailServerInfo(template: T, data: Extract['data']): EmailServerInfo { - return { - url: `https://mail-service.litlyx.com/send${templateMap[template]}`, - body: data, - headers: { 'Content-Type': 'application/json' } - }; - } -} \ No newline at end of file