codebase-models 2.1.23 → 3.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.
Files changed (43) hide show
  1. package/.github/workflows/npm-publish-stage.yml +33 -0
  2. package/dist/index.d.ts +8 -5
  3. package/dist/index.js +17 -10
  4. package/dist/src/constant.d.ts +25 -1
  5. package/dist/src/constant.js +100 -3
  6. package/dist/src/models/Client.d.ts +1 -1
  7. package/dist/src/models/Client.js +7 -4
  8. package/dist/src/models/{SegmentCombination.d.ts → Invitation.d.ts} +15 -14
  9. package/dist/src/models/Invitation.js +55 -0
  10. package/dist/src/models/Organization.d.ts +8 -15
  11. package/dist/src/models/Organization.js +10 -58
  12. package/dist/src/models/{QueryLog.d.ts → Package.d.ts} +7 -7
  13. package/dist/src/models/{QueryLog.js → Package.js} +10 -19
  14. package/dist/src/models/Role.js +16 -7
  15. package/dist/src/models/{Segment.d.ts → Thread.d.ts} +7 -10
  16. package/dist/src/models/Thread.js +78 -0
  17. package/dist/src/models/ThreadMessage.d.ts +35 -0
  18. package/dist/src/models/ThreadMessage.js +86 -0
  19. package/dist/src/models/User.d.ts +8 -5
  20. package/dist/src/models/User.js +13 -37
  21. package/dist/src/models/UserIdentity.d.ts +35 -0
  22. package/dist/src/models/{SegmentCombination.js → UserIdentity.js} +11 -47
  23. package/dist/src/models/UserOrganization.d.ts +33 -0
  24. package/dist/src/models/{Segment.js → UserOrganization.js} +10 -33
  25. package/dist/src/models/UserPermission.d.ts +4 -11
  26. package/dist/src/models/UserPermission.js +27 -10
  27. package/index.ts +18 -11
  28. package/package.json +1 -1
  29. package/src/constant.ts +104 -4
  30. package/src/models/Client.ts +8 -5
  31. package/src/models/Invitation.ts +50 -0
  32. package/src/models/Organization.ts +18 -73
  33. package/src/models/Package.ts +24 -0
  34. package/src/models/Role.ts +51 -39
  35. package/src/models/Thread.ts +57 -0
  36. package/src/models/ThreadMessage.ts +67 -0
  37. package/src/models/User.ts +21 -43
  38. package/src/models/UserIdentity.ts +26 -0
  39. package/src/models/UserOrganization.ts +23 -0
  40. package/src/models/UserPermission.ts +31 -21
  41. package/src/models/QueryLog.ts +0 -35
  42. package/src/models/Segment.ts +0 -50
  43. package/src/models/SegmentCombination.ts +0 -68
@@ -0,0 +1,33 @@
1
+ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
+
4
+ name: Publish Codebase Shared Models on NPM (Stage)
5
+
6
+ on:
7
+ push:
8
+ branches:
9
+ - staging
10
+
11
+ jobs:
12
+ build:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: actions/setup-node@v4
17
+ with:
18
+ node-version: 20
19
+ - run: npm ci
20
+
21
+ publish-npm:
22
+ needs: build
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - uses: actions/checkout@v4
26
+ - uses: actions/setup-node@v4
27
+ with:
28
+ node-version: 20
29
+ registry-url: https://registry.npmjs.org/
30
+ - run: npm ci
31
+ - run: npm publish --tag stage
32
+ env:
33
+ NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
package/dist/index.d.ts CHANGED
@@ -25,7 +25,6 @@
25
25
  import mongoose from "mongoose";
26
26
  import Client from "./src/models/Client";
27
27
  import ClientReportsTemp from "./src/models/ClientReportsTemp";
28
- import QueryLog from "./src/models/QueryLog";
29
28
  import Report from "./src/models/Report";
30
29
  import Test from "./src/models/Test";
31
30
  import TestSequentialValue from "./src/models/TestSequentialValue";
@@ -57,8 +56,6 @@ import ReadNotification from "./src/models/ReadNotification";
57
56
  import Organization from "./src/models/Organization";
58
57
  import Role from "./src/models/Role";
59
58
  import SavedSegment from "./src/models/SavedSegment";
60
- import Segment from "./src/models/Segment";
61
- import SegmentCombination from "./src/models/SegmentCombination";
62
59
  import Snippet from "./src/models/Snippet";
63
60
  import StageInCustomerJourney from "./src/models/StageInCustomerJourney";
64
61
  import Tag from "./src/models/Tag";
@@ -72,9 +69,15 @@ import Environment from "./src/models/Environment";
72
69
  import PrecalculationFilters from "./src/models/PrecalculationFilters";
73
70
  import BqPreCompiledData from "./src/models/BqPreCompiledData";
74
71
  import CustomQuery from "./src/models/CustomQuery";
75
- import { generateRandomIID } from "./src/constant";
72
+ import { generateRandomIID, RolesConstants } from "./src/constant";
76
73
  import TestTimeline from "./src/models/TestTimeline";
77
74
  import CronData from "./src/models/CronData";
78
75
  import CronConfig from "./src/models/CronConfig";
76
+ import UserIdentity from "./src/models/UserIdentity";
77
+ import UserOrganization from "./src/models/UserOrganization";
78
+ import Package from "./src/models/Package";
79
+ import Invitation from "./src/models/Invitation";
80
+ import Thread from "./src/models/Thread";
81
+ import ThreadMessage from "./src/models/ThreadMessage";
79
82
  export declare function connect(uri: string, options?: mongoose.ConnectOptions | undefined): Promise<typeof mongoose>;
80
- export { generateRandomIID, Client, ClientReportsTemp, QueryLog, Report, Test, TestSequentialValue, User, AppEvent, Announcement, ClientAdditionalRevenue, ClientLearning, ClientLinks, ClientNextStep, ClientNote, ClientRetention, ClientStrategy, ClientSurvey, CVRReport, Faq, Feedback, Goal, Hypothesis, HypothesisSheet, LandingPages, NewIdeas, Notification, Page, PageElement, PageTestType, Portfolio, ReadNotification, Role, CustomQuery, SavedSegment, TestTimeline, Segment, SegmentCombination, Snippet, StageInCustomerJourney, Tag, Temp, Tier, Trigger, ClientScript, Audience, Environment, Organization, PrecalculationFilters, BqPreCompiledData, CronData, CronConfig, UserPermission };
83
+ export { generateRandomIID, RolesConstants, Client, ClientReportsTemp, Report, Test, TestSequentialValue, User, AppEvent, Announcement, ClientAdditionalRevenue, ClientLearning, ClientLinks, ClientNextStep, ClientNote, ClientRetention, ClientStrategy, ClientSurvey, CVRReport, Faq, Feedback, Goal, Hypothesis, HypothesisSheet, LandingPages, NewIdeas, Notification, Page, PageElement, PageTestType, Portfolio, ReadNotification, Role, CustomQuery, SavedSegment, TestTimeline, Snippet, StageInCustomerJourney, Tag, Temp, Tier, Trigger, ClientScript, Audience, Environment, Organization, PrecalculationFilters, BqPreCompiledData, CronData, CronConfig, UserPermission, UserIdentity, UserOrganization, Package, Invitation, Thread, ThreadMessage, };
package/dist/index.js CHANGED
@@ -12,15 +12,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.PrecalculationFilters = exports.Organization = exports.Environment = exports.Audience = exports.ClientScript = exports.Trigger = exports.Tier = exports.Temp = exports.Tag = exports.StageInCustomerJourney = exports.Snippet = exports.SegmentCombination = exports.Segment = exports.TestTimeline = exports.SavedSegment = exports.CustomQuery = exports.Role = exports.ReadNotification = exports.Portfolio = exports.PageTestType = exports.PageElement = exports.Page = exports.Notification = exports.NewIdeas = exports.LandingPages = exports.HypothesisSheet = exports.Hypothesis = exports.Goal = exports.Feedback = exports.Faq = exports.CVRReport = exports.ClientSurvey = exports.ClientStrategy = exports.ClientRetention = exports.ClientNote = exports.ClientNextStep = exports.ClientLinks = exports.ClientLearning = exports.ClientAdditionalRevenue = exports.Announcement = exports.AppEvent = exports.User = exports.TestSequentialValue = exports.Test = exports.Report = exports.QueryLog = exports.ClientReportsTemp = exports.Client = exports.generateRandomIID = exports.connect = void 0;
16
- exports.UserPermission = exports.CronConfig = exports.CronData = exports.BqPreCompiledData = void 0;
15
+ exports.CronData = exports.BqPreCompiledData = exports.PrecalculationFilters = exports.Organization = exports.Environment = exports.Audience = exports.ClientScript = exports.Trigger = exports.Tier = exports.Temp = exports.Tag = exports.StageInCustomerJourney = exports.Snippet = exports.TestTimeline = exports.SavedSegment = exports.CustomQuery = exports.Role = exports.ReadNotification = exports.Portfolio = exports.PageTestType = exports.PageElement = exports.Page = exports.Notification = exports.NewIdeas = exports.LandingPages = exports.HypothesisSheet = exports.Hypothesis = exports.Goal = exports.Feedback = exports.Faq = exports.CVRReport = exports.ClientSurvey = exports.ClientStrategy = exports.ClientRetention = exports.ClientNote = exports.ClientNextStep = exports.ClientLinks = exports.ClientLearning = exports.ClientAdditionalRevenue = exports.Announcement = exports.AppEvent = exports.User = exports.TestSequentialValue = exports.Test = exports.Report = exports.ClientReportsTemp = exports.Client = exports.RolesConstants = exports.generateRandomIID = exports.connect = void 0;
16
+ exports.ThreadMessage = exports.Thread = exports.Invitation = exports.Package = exports.UserOrganization = exports.UserIdentity = exports.UserPermission = exports.CronConfig = void 0;
17
17
  const mongoose_1 = __importDefault(require("mongoose"));
18
18
  const Client_1 = __importDefault(require("./src/models/Client"));
19
19
  exports.Client = Client_1.default;
20
20
  const ClientReportsTemp_1 = __importDefault(require("./src/models/ClientReportsTemp"));
21
21
  exports.ClientReportsTemp = ClientReportsTemp_1.default;
22
- const QueryLog_1 = __importDefault(require("./src/models/QueryLog"));
23
- exports.QueryLog = QueryLog_1.default;
24
22
  const Report_1 = __importDefault(require("./src/models/Report"));
25
23
  exports.Report = Report_1.default;
26
24
  const Test_1 = __importDefault(require("./src/models/Test"));
@@ -83,10 +81,6 @@ const Role_1 = __importDefault(require("./src/models/Role"));
83
81
  exports.Role = Role_1.default;
84
82
  const SavedSegment_1 = __importDefault(require("./src/models/SavedSegment"));
85
83
  exports.SavedSegment = SavedSegment_1.default;
86
- const Segment_1 = __importDefault(require("./src/models/Segment"));
87
- exports.Segment = Segment_1.default;
88
- const SegmentCombination_1 = __importDefault(require("./src/models/SegmentCombination"));
89
- exports.SegmentCombination = SegmentCombination_1.default;
90
84
  const Snippet_1 = __importDefault(require("./src/models/Snippet"));
91
85
  exports.Snippet = Snippet_1.default;
92
86
  const StageInCustomerJourney_1 = __importDefault(require("./src/models/StageInCustomerJourney"));
@@ -115,17 +109,30 @@ const CustomQuery_1 = __importDefault(require("./src/models/CustomQuery"));
115
109
  exports.CustomQuery = CustomQuery_1.default;
116
110
  const constant_1 = require("./src/constant");
117
111
  Object.defineProperty(exports, "generateRandomIID", { enumerable: true, get: function () { return constant_1.generateRandomIID; } });
112
+ Object.defineProperty(exports, "RolesConstants", { enumerable: true, get: function () { return constant_1.RolesConstants; } });
118
113
  const TestTimeline_1 = __importDefault(require("./src/models/TestTimeline"));
119
114
  exports.TestTimeline = TestTimeline_1.default;
120
115
  const CronData_1 = __importDefault(require("./src/models/CronData"));
121
116
  exports.CronData = CronData_1.default;
122
117
  const CronConfig_1 = __importDefault(require("./src/models/CronConfig"));
123
118
  exports.CronConfig = CronConfig_1.default;
119
+ const UserIdentity_1 = __importDefault(require("./src/models/UserIdentity"));
120
+ exports.UserIdentity = UserIdentity_1.default;
121
+ const UserOrganization_1 = __importDefault(require("./src/models/UserOrganization"));
122
+ exports.UserOrganization = UserOrganization_1.default;
123
+ const Package_1 = __importDefault(require("./src/models/Package"));
124
+ exports.Package = Package_1.default;
125
+ const Invitation_1 = __importDefault(require("./src/models/Invitation"));
126
+ exports.Invitation = Invitation_1.default;
127
+ const Thread_1 = __importDefault(require("./src/models/Thread"));
128
+ exports.Thread = Thread_1.default;
129
+ const ThreadMessage_1 = __importDefault(require("./src/models/ThreadMessage"));
130
+ exports.ThreadMessage = ThreadMessage_1.default;
124
131
  function seedRoles() {
125
132
  return __awaiter(this, void 0, void 0, function* () {
126
133
  const checkRoles = yield Role_1.default.countDocuments();
127
- if (checkRoles < 5) {
128
- Promise.all(["USER", "ADMIN", "EDITOR", "OPTIMIZER", "CLIENT", "EXTERNAL"].map((name) => {
134
+ if (checkRoles < constant_1.RolesConstants.length) {
135
+ Promise.all(constant_1.RolesConstants.map((name) => {
129
136
  Role_1.default.bulkWrite([
130
137
  {
131
138
  updateOne: {
@@ -8,11 +8,35 @@ declare const HypothesisSheetConstants: {
8
8
  MEDIUM: number;
9
9
  GOOD: number;
10
10
  };
11
+ declare const RolesConstants: string[];
11
12
  /**
12
13
  * Generates a random unique identifier
13
14
  * @returns A 12-character uppercase string (increased from 8 for better uniqueness)
14
15
  * @throws Error if UUID generation fails
15
16
  */
16
17
  declare const generateRandomIID: () => string;
17
- export { generateRandomIID };
18
+ declare const PermissionsConstants: {
19
+ dashboard: string;
20
+ reporting: string;
21
+ insights: string;
22
+ documentsAndLinks: string;
23
+ cvrReports: string;
24
+ abTesting: string;
25
+ abTestingDefault: string;
26
+ manageOrganizations: string;
27
+ manageInvitations: string;
28
+ manageClients: string;
29
+ };
30
+ declare const PackageFeaturesConstants: ({
31
+ name: string;
32
+ value: boolean;
33
+ description: string;
34
+ allowedCount: null;
35
+ } | {
36
+ name: string;
37
+ value: boolean;
38
+ description: string;
39
+ allowedCount: number;
40
+ })[];
41
+ export { generateRandomIID, RolesConstants, PermissionsConstants, PackageFeaturesConstants };
18
42
  export default HypothesisSheetConstants;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateRandomIID = void 0;
3
+ exports.PackageFeaturesConstants = exports.PermissionsConstants = exports.RolesConstants = exports.generateRandomIID = void 0;
4
4
  const uuid_1 = require("uuid");
5
5
  const HypothesisSheetConstants = {
6
6
  NO: 0,
@@ -14,6 +14,15 @@ const HypothesisSheetConstants = {
14
14
  MEDIUM: 1,
15
15
  GOOD: 2,
16
16
  };
17
+ const RolesConstants = [
18
+ "USER",
19
+ "ADMIN",
20
+ "CLIENT",
21
+ "EXTERNAL",
22
+ "QA",
23
+ "OPTIMIZER",
24
+ ];
25
+ exports.RolesConstants = RolesConstants;
17
26
  /**
18
27
  * Generates a random unique identifier
19
28
  * @returns A 12-character uppercase string (increased from 8 for better uniqueness)
@@ -22,11 +31,99 @@ const HypothesisSheetConstants = {
22
31
  const generateRandomIID = () => {
23
32
  try {
24
33
  // Take first 12 characters instead of 8 for better uniqueness
25
- return (0, uuid_1.v4)().replace(/-/g, '').substring(0, 12).toUpperCase();
34
+ return (0, uuid_1.v4)().replace(/-/g, "").substring(0, 12).toUpperCase();
26
35
  }
27
36
  catch (error) {
28
- throw new Error(`Failed to generate random IID: ${error instanceof Error ? error.message : 'Unknown error'}`);
37
+ throw new Error(`Failed to generate random IID: ${error instanceof Error ? error.message : "Unknown error"}`);
29
38
  }
30
39
  };
31
40
  exports.generateRandomIID = generateRandomIID;
41
+ const PermissionsConstants = {
42
+ dashboard: "dashboard",
43
+ reporting: "reporting",
44
+ insights: "insights",
45
+ documentsAndLinks: "documentsAndLinks",
46
+ cvrReports: "cvrReports",
47
+ abTesting: "abTesting",
48
+ abTestingDefault: "abTestingDefault",
49
+ manageOrganizations: "manageOrganizations",
50
+ manageInvitations: "manageInvitations",
51
+ manageClients: "manageClients",
52
+ };
53
+ exports.PermissionsConstants = PermissionsConstants;
54
+ const PackageFeaturesConstants = [
55
+ {
56
+ name: "DASHBOARD",
57
+ value: true,
58
+ description: "Access to the dashboard",
59
+ allowedCount: null,
60
+ },
61
+ {
62
+ name: "REPORTING",
63
+ value: true,
64
+ description: "Access to the reporting",
65
+ allowedCount: null,
66
+ },
67
+ {
68
+ name: "INSIGHTS",
69
+ value: true,
70
+ description: "Access to the insights",
71
+ allowedCount: null,
72
+ },
73
+ {
74
+ name: "DOCUMENTSANDLINKS",
75
+ value: true,
76
+ description: "Access to the documents and links",
77
+ allowedCount: 5,
78
+ },
79
+ {
80
+ name: "CVRREPORTS",
81
+ value: true,
82
+ description: "Access to the cvr reports",
83
+ allowedCount: null,
84
+ },
85
+ {
86
+ name: "ABTESTING",
87
+ value: false,
88
+ description: "Access to the ab testing",
89
+ allowedCount: null,
90
+ },
91
+ {
92
+ name: "ABTESTINGDEFAULT",
93
+ value: true,
94
+ description: "Access to the ab testing default",
95
+ allowedCount: null,
96
+ },
97
+ {
98
+ name: "MANAGEEXPERIMENTS",
99
+ value: true,
100
+ description: "Access to the experiments",
101
+ allowedCount: null,
102
+ },
103
+ {
104
+ name: "PRECALCULATIONS",
105
+ value: false,
106
+ description: "Access to the pre calculations",
107
+ allowedCount: null,
108
+ },
109
+ {
110
+ name: "MANAGEORGANIZATIONS",
111
+ value: true,
112
+ description: "Access to the organizations",
113
+ allowedCount: 1,
114
+ },
115
+ {
116
+ name: "MANAGEINVITATIONS",
117
+ value: true,
118
+ description: "Access to the invitations",
119
+ allowedCount: 1,
120
+ },
121
+ {
122
+ name: "MANAGECLIENTS",
123
+ value: true,
124
+ description: "Access to the clients",
125
+ allowedCount: 3,
126
+ },
127
+ ];
128
+ exports.PackageFeaturesConstants = PackageFeaturesConstants;
32
129
  exports.default = HypothesisSheetConstants;
@@ -30,7 +30,7 @@ export interface IProperty extends Document {
30
30
  }
31
31
  export interface IClient extends Document {
32
32
  iid: string;
33
- organizationId?: mongoose.Schema.Types.ObjectId;
33
+ organization: mongoose.Schema.Types.ObjectId;
34
34
  name: string;
35
35
  slug?: string;
36
36
  viewId?: string;
@@ -48,10 +48,14 @@ const ClientSchema = new mongoose_1.Schema({
48
48
  iid: {
49
49
  type: String,
50
50
  trim: true,
51
+ unique: true,
52
+ default: () => (0, constant_1.generateRandomIID)()
51
53
  },
52
- organizationId: { type: mongoose_1.default.Schema.Types.ObjectId,
54
+ organization: { type: mongoose_1.default.Schema.Types.ObjectId,
53
55
  ref: "organization",
54
- default: null },
56
+ default: null,
57
+ required: true
58
+ },
55
59
  name: { type: String, required: true },
56
60
  slug: {
57
61
  type: String,
@@ -100,10 +104,9 @@ ClientSchema.pre('save', function (next) {
100
104
  next();
101
105
  });
102
106
  });
103
- ClientSchema.index({ iid: 1 }, { unique: true });
104
107
  // Add compound indexes for better query performance
105
108
  ClientSchema.index({ active: 1 });
106
- ClientSchema.index({ organizationId: 1, active: 1 });
109
+ ClientSchema.index({ organization: 1, active: 1 });
107
110
  ClientSchema.index({ name: 1 }, { collation: { locale: 'en', strength: 2 } }); // Case-insensitive search
108
111
  ClientSchema.index({ tier: 1, active: 1 }); // For tier-based queries
109
112
  ClientSchema.index({ onboardDate: 1 }); // For date-based queries
@@ -23,18 +23,19 @@
23
23
  /// <reference types="mongoose/types/virtuals" />
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import mongoose, { Document } from "mongoose";
26
- export interface ISegmentCombination extends Document {
27
- name?: string;
28
- combination?: [];
29
- gagroup?: string;
30
- secondaryFilters?: [];
31
- segmentType?: string;
32
- client?: mongoose.Schema.Types.ObjectId[];
33
- published?: boolean;
34
- order?: Number;
35
- createdAt?: Date;
36
- updatedAt?: Date;
37
- organizationId?: mongoose.Schema.Types.ObjectId;
26
+ export interface IInvitation extends Document {
27
+ iid: string;
28
+ email: string;
29
+ invitedBy: mongoose.Types.ObjectId;
30
+ organization: mongoose.Types.ObjectId;
31
+ client?: mongoose.Types.ObjectId;
32
+ role?: string;
33
+ permissions?: mongoose.Schema.Types.Mixed;
34
+ token: string;
35
+ status: string;
36
+ expiresAt: Date;
37
+ createdAt: Date;
38
+ updatedAt: Date;
38
39
  }
39
- declare const SegmentCombination: mongoose.Model<any, {}, {}, {}, any, any>;
40
- export default SegmentCombination;
40
+ declare const Invitation: mongoose.Model<any, {}, {}, {}, any, any>;
41
+ export default Invitation;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const mongoose_1 = __importStar(require("mongoose"));
27
+ const constant_1 = require("../constant");
28
+ const InvitationSchema = new mongoose_1.Schema({
29
+ iid: { type: String, unique: true, default: () => (0, constant_1.generateRandomIID)() },
30
+ email: { type: String, required: true },
31
+ invitedBy: { type: mongoose_1.default.Schema.Types.ObjectId, ref: "user", required: true },
32
+ organization: { type: mongoose_1.default.Schema.Types.ObjectId, ref: "organization", required: true },
33
+ client: { type: mongoose_1.default.Schema.Types.ObjectId, ref: "client" },
34
+ role: { type: String, enum: ["owner", "admin", "member"], default: "member" },
35
+ permissions: { type: mongoose_1.default.Schema.Types.Mixed, required: true, default: {
36
+ dashboard: true,
37
+ reporting: false,
38
+ insights: false,
39
+ documentsAndLinks: false,
40
+ cvrReports: false,
41
+ abTesting: false,
42
+ abTestingDefault: true,
43
+ manageExperiments: false,
44
+ preCalculations: false,
45
+ } },
46
+ token: { type: String, unique: true, required: true },
47
+ status: { type: String, enum: ["pending", "accepted", "expired", "revoked"], default: "pending" },
48
+ expiresAt: { type: Date, default: Date.now() + 1000 * 60 * 60 * 24 * 30 },
49
+ }, {
50
+ timestamps: true
51
+ });
52
+ InvitationSchema.index({ email: 1, organization: 1 });
53
+ InvitationSchema.index({ token: 1 }, { unique: true });
54
+ const Invitation = mongoose_1.default.models.invitation || (0, mongoose_1.model)("invitation", InvitationSchema);
55
+ exports.default = Invitation;
@@ -24,22 +24,15 @@
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import mongoose, { Document } from "mongoose";
26
26
  export interface IOrganization extends Document {
27
+ iid: string;
27
28
  name: string;
28
- description: string;
29
- adminEmail: string;
30
- adminContact: string;
31
- createdBy: mongoose.Schema.Types.ObjectId;
32
- address: string;
33
- city: string;
34
- state: string;
35
- zip: string;
36
- country: string;
37
- phone: string;
38
- logo: string;
39
- website: string;
40
- createdAt: Date;
41
- updatedAt: Date;
42
- isActive: boolean;
29
+ ownerId: mongoose.Schema.Types.ObjectId;
30
+ stripeCustomerId?: string;
31
+ packageId?: mongoose.Schema.Types.ObjectId;
32
+ subscriptionId: String;
33
+ subscriptionStatus: String;
34
+ lastPaymentDate: Date;
35
+ currentPeriodEnd: Date;
43
36
  }
44
37
  declare const Organization: mongoose.Model<any, {}, {}, {}, any, any>;
45
38
  export default Organization;
@@ -24,67 +24,19 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  const mongoose_1 = __importStar(require("mongoose"));
27
+ const constant_1 = require("../constant");
27
28
  const OrganizationSchema = new mongoose_1.Schema({
28
- name: {
29
- type: String,
30
- required: true,
31
- unique: true,
32
- },
33
- description: {
34
- type: String,
35
- required: true,
36
- },
37
- adminEmail: {
38
- type: String,
39
- required: true,
40
- },
41
- adminContact: {
42
- type: String,
43
- required: true,
44
- },
45
- createdBy: {
46
- type: mongoose_1.default.Schema.Types.ObjectId,
47
- ref: "user",
48
- },
49
- address: {
50
- type: String,
51
- required: true,
52
- },
53
- city: {
54
- type: String,
55
- required: true,
56
- },
57
- state: {
58
- type: String,
59
- required: true,
60
- },
61
- zip: {
62
- type: String,
63
- required: true,
64
- },
65
- country: {
66
- type: String,
67
- required: true,
68
- },
69
- phone: {
70
- type: String,
71
- required: true,
72
- },
73
- logo: {
74
- type: String,
75
- required: true,
76
- },
77
- website: {
78
- type: String,
79
- required: true,
80
- },
81
- isActive: {
82
- type: Boolean,
83
- default: true,
84
- },
29
+ iid: { type: String, default: () => (0, constant_1.generateRandomIID)() },
30
+ name: { type: String, required: true },
31
+ ownerId: { type: mongoose_1.default.Schema.Types.ObjectId, ref: "user", required: true },
32
+ stripeCustomerId: String,
33
+ packageId: { type: mongoose_1.default.Types.ObjectId, ref: "package" },
34
+ subscriptionId: String,
35
+ subscriptionStatus: String,
36
+ lastPaymentDate: Date,
37
+ currentPeriodEnd: Date,
85
38
  }, {
86
39
  timestamps: true
87
40
  });
88
41
  const Organization = mongoose_1.default.models.organization || (0, mongoose_1.model)("organization", OrganizationSchema);
89
- OrganizationSchema.index({ name: 1, isActive: 1 });
90
42
  exports.default = Organization;
@@ -23,11 +23,11 @@
23
23
  /// <reference types="mongoose/types/virtuals" />
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import mongoose, { Document } from "mongoose";
26
- export interface IQueryLog extends Document {
27
- organizationId?: mongoose.Schema.Types.ObjectId;
28
- query: string;
29
- timeTaken: number;
30
- user?: mongoose.Schema.Types.ObjectId;
26
+ export interface IPackage extends Document {
27
+ iid: string;
28
+ name: string;
29
+ stripeProductId: string;
30
+ features: mongoose.Schema.Types.Mixed;
31
31
  }
32
- declare const QueryLog: mongoose.Model<any, {}, {}, {}, any, any>;
33
- export default QueryLog;
32
+ declare const Package: mongoose.Model<any, {}, {}, {}, any, any>;
33
+ export default Package;
@@ -24,24 +24,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  const mongoose_1 = __importStar(require("mongoose"));
27
- const QueryLogSchema = new mongoose_1.Schema({
28
- organizationId: {
29
- type: mongoose_1.default.Schema.Types.ObjectId,
30
- ref: "organization",
31
- default: null,
32
- },
33
- query: {
34
- type: String,
35
- },
36
- timeTaken: {
37
- type: Number,
38
- },
39
- user: {
40
- type: mongoose_1.default.Schema.Types.ObjectId,
41
- ref: "user",
42
- },
27
+ const constant_1 = require("../constant");
28
+ const PackageSchema = new mongoose_1.Schema({
29
+ iid: { type: String, unique: true, default: () => (0, constant_1.generateRandomIID)() },
30
+ name: { type: String, required: true },
31
+ stripeProductId: { type: String },
32
+ // userPermissions: { type: mongoose.Schema.Types.ObjectId, ref: "userpermission", required: true },
33
+ features: { type: mongoose_1.default.Schema.Types.Mixed, required: true, default: constant_1.PackageFeaturesConstants },
43
34
  }, {
44
- timestamps: true,
35
+ timestamps: true
45
36
  });
46
- const QueryLog = mongoose_1.default.models.querylog || (0, mongoose_1.model)("querylog", QueryLogSchema);
47
- exports.default = QueryLog;
37
+ const Package = mongoose_1.default.models.package || (0, mongoose_1.model)("package", PackageSchema);
38
+ exports.default = Package;
@@ -29,7 +29,16 @@ const RoleSchema = new mongoose_1.Schema({
29
29
  type: String,
30
30
  unique: true,
31
31
  required: true,
32
- enum: ["USER", "ADMIN", "EDITOR", "COLLABORATOR", "CLIENT", "EXTERNAL"],
32
+ enum: [
33
+ "USER",
34
+ "ADMIN",
35
+ "EDITOR",
36
+ "COLLABORATOR",
37
+ "CLIENT",
38
+ "EXTERNAL",
39
+ "QA",
40
+ "OPTIMIZER",
41
+ ],
33
42
  trim: true,
34
43
  uppercase: true,
35
44
  },
@@ -56,12 +65,12 @@ const RoleSchema = new mongoose_1.Schema({
56
65
  cvrReports: { type: Boolean, default: true },
57
66
  manageExperiments: { type: Boolean, default: true },
58
67
  dashboard: { type: Boolean, default: true },
59
- }
68
+ },
60
69
  }, {
61
- timestamps: true
70
+ timestamps: true,
62
71
  });
63
72
  // IF role is CLIENT then defaultPermissions should be false for all modules except reporting, insights, documentsAndLinks, cvrReports, dashboard
64
- RoleSchema.pre('save', function (next) {
73
+ RoleSchema.pre("save", function (next) {
65
74
  const allTrue = {
66
75
  abTestingDefault: true,
67
76
  abTesting: true,
@@ -73,7 +82,7 @@ RoleSchema.pre('save', function (next) {
73
82
  cvrReports: true,
74
83
  dashboard: true,
75
84
  };
76
- if (this.name === 'CLIENT') {
85
+ if (this.name === "CLIENT") {
77
86
  this.defaultPermissions = Object.assign(Object.assign({}, allTrue), { abTesting: false });
78
87
  }
79
88
  else {
@@ -86,8 +95,8 @@ RoleSchema.index({ name: 1, isActive: 1 });
86
95
  RoleSchema.index({ organizationId: 1, name: 1 });
87
96
  // Add text index for search
88
97
  RoleSchema.index({
89
- name: 'text',
90
- description: 'text'
98
+ name: "text",
99
+ description: "text",
91
100
  });
92
101
  const Role = mongoose_1.default.models.role || (0, mongoose_1.model)("role", RoleSchema);
93
102
  exports.default = Role;