codebase-models 3.0.9 → 3.1.1
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/README.md +324 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +5 -3
- package/dist/src/models/{UserIdentity.d.ts → ApiLog.d.ts} +10 -7
- package/dist/src/models/{UserIdentity.js → ApiLog.js} +47 -10
- package/index.ts +4 -2
- package/package.json +4 -4
- package/src/constant.ts +2 -0
- package/src/models/ApiLog.ts +67 -0
- package/src/models/UserIdentity.ts +0 -26
package/README.md
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
# codebase-models
|
|
2
|
+
|
|
3
|
+
Common Mongoose models and utilities for the Conversion.IO codebase.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install codebase-models
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { connect, Client, User, Provider, ProviderType } from "codebase-models";
|
|
15
|
+
|
|
16
|
+
// Connect to MongoDB
|
|
17
|
+
await connect(process.env.MONGODB_URI);
|
|
18
|
+
|
|
19
|
+
// Use models
|
|
20
|
+
const client = await Client.findOne({ name: "Example Client" });
|
|
21
|
+
const user = await User.findOne({ email: "user@example.com" });
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- **50+ Mongoose Models**: Pre-defined schemas for clients, users, tests, reports, and more
|
|
27
|
+
- **Database Connection Helper**: Automatic connection management with role seeding
|
|
28
|
+
- **TypeScript Support**: Full TypeScript definitions for all models
|
|
29
|
+
- **Provider Integration**: Built-in support for third-party integrations (Shopify, BigQuery, Google services, etc.)
|
|
30
|
+
- **Utility Functions**: Helper functions for ID generation and constants
|
|
31
|
+
|
|
32
|
+
## Available Models
|
|
33
|
+
|
|
34
|
+
### Core Models
|
|
35
|
+
|
|
36
|
+
- `Client` - Client/organization management
|
|
37
|
+
- `User` - User accounts and authentication
|
|
38
|
+
- `Organization` - Organization structure
|
|
39
|
+
- `Role` - User roles and permissions
|
|
40
|
+
- `UserPermission` - User-specific permissions
|
|
41
|
+
- `UserOrganization` - User-organization relationships
|
|
42
|
+
- `Package` - Feature packages and subscriptions
|
|
43
|
+
- `Tier` - Client tiers
|
|
44
|
+
|
|
45
|
+
### Testing & Experiments
|
|
46
|
+
|
|
47
|
+
- `Test` - A/B tests and experiments
|
|
48
|
+
- `TestSequentialValue` - Sequential testing configuration
|
|
49
|
+
- `TestTimeline` - Test event timeline
|
|
50
|
+
- `Hypothesis` - Test hypotheses
|
|
51
|
+
- `HypothesisSheet` - Hypothesis evaluation sheets
|
|
52
|
+
- `Page` - Landing pages
|
|
53
|
+
- `PageElement` - Page elements/components
|
|
54
|
+
- `PageTestType` - Page test type configurations
|
|
55
|
+
- `Trigger` - Test triggers
|
|
56
|
+
- `Audience` - Test audiences
|
|
57
|
+
|
|
58
|
+
### Reporting & Analytics
|
|
59
|
+
|
|
60
|
+
- `Report` - General reports
|
|
61
|
+
- `CVRReport` - Conversion rate reports
|
|
62
|
+
- `ClientReportsTemp` - Temporary client reports
|
|
63
|
+
- `BqPreCompiledData` - BigQuery pre-compiled data
|
|
64
|
+
- `PrecalculationFilters` - Data precalculation filters
|
|
65
|
+
|
|
66
|
+
### Client Management
|
|
67
|
+
|
|
68
|
+
- `ClientRetention` - Client retention data
|
|
69
|
+
- `ClientStrategy` - Client strategies
|
|
70
|
+
- `ClientLearning` - Client learnings
|
|
71
|
+
- `ClientLinks` - Client links and documents
|
|
72
|
+
- `ClientNote` - Client notes
|
|
73
|
+
- `ClientNextStep` - Client next steps
|
|
74
|
+
- `ClientAdditionalRevenue` - Additional revenue tracking
|
|
75
|
+
- `ClientScript` - Client scripts
|
|
76
|
+
- `ClientSurvey` - Client surveys
|
|
77
|
+
|
|
78
|
+
### Content & Communication
|
|
79
|
+
|
|
80
|
+
- `Thread` - Communication threads
|
|
81
|
+
- `ThreadMessage` - Thread messages
|
|
82
|
+
- `Notification` - System notifications
|
|
83
|
+
- `ReadNotification` - Notification read status
|
|
84
|
+
- `Announcement` - System announcements
|
|
85
|
+
- `Invitation` - User invitations
|
|
86
|
+
- `Feedback` - User feedback
|
|
87
|
+
- `Faq` - Frequently asked questions
|
|
88
|
+
|
|
89
|
+
### Integrations & Providers
|
|
90
|
+
|
|
91
|
+
- `Provider` - Third-party provider configurations (Shopify, BigQuery, Google services, etc.)
|
|
92
|
+
- `ApiLog` - API call logging
|
|
93
|
+
|
|
94
|
+
### Other Models
|
|
95
|
+
|
|
96
|
+
- `Goal` - Goals and objectives
|
|
97
|
+
- `NewIdeas` - New ideas tracking
|
|
98
|
+
- `SavedSegment` - Saved user segments
|
|
99
|
+
- `Snippet` - Code snippets
|
|
100
|
+
- `Tag` - Tagging system
|
|
101
|
+
- `Portfolio` - Portfolio management
|
|
102
|
+
- `LandingPages` - Landing page management
|
|
103
|
+
- `StageInCustomerJourney` - Customer journey stages
|
|
104
|
+
- `Environment` - Environment configurations
|
|
105
|
+
- `CustomQuery` - Custom database queries
|
|
106
|
+
- `CronData` - Cron job data
|
|
107
|
+
- `CronConfig` - Cron job configurations
|
|
108
|
+
- `AppEvent` - Application events
|
|
109
|
+
- `Temp` - Temporary data storage
|
|
110
|
+
|
|
111
|
+
## Database Connection
|
|
112
|
+
|
|
113
|
+
The package provides a `connect` function that handles MongoDB connection and automatically seeds roles:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { connect } from "codebase-models";
|
|
117
|
+
|
|
118
|
+
// Basic connection
|
|
119
|
+
await connect(process.env.MONGODB_URI);
|
|
120
|
+
|
|
121
|
+
// With options
|
|
122
|
+
await connect(process.env.MONGODB_URI, {
|
|
123
|
+
maxPoolSize: 10,
|
|
124
|
+
serverSelectionTimeoutMS: 5000,
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The connection function:
|
|
129
|
+
|
|
130
|
+
- Automatically checks if already connected
|
|
131
|
+
- Seeds default roles on first connection
|
|
132
|
+
- Returns the mongoose instance
|
|
133
|
+
|
|
134
|
+
## Provider Model
|
|
135
|
+
|
|
136
|
+
The `Provider` model is designed to store API keys, secrets, and configurations for third-party integrations.
|
|
137
|
+
|
|
138
|
+
### Supported Provider Types
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { Provider, ProviderType } from "codebase-models";
|
|
142
|
+
|
|
143
|
+
// Available provider types
|
|
144
|
+
ProviderType.SHOPIFY;
|
|
145
|
+
ProviderType.BIGQUERY;
|
|
146
|
+
ProviderType.GOOGLE_ANALYTICS;
|
|
147
|
+
ProviderType.GOOGLE_TAG_MANAGER;
|
|
148
|
+
ProviderType.GOOGLE_ADS;
|
|
149
|
+
ProviderType.GOOGLE_SEARCH_CONSOLE;
|
|
150
|
+
ProviderType.GOOGLE_SHEETS;
|
|
151
|
+
ProviderType.GOOGLE_DOCS;
|
|
152
|
+
ProviderType.GOOGLE_DRIVE;
|
|
153
|
+
ProviderType.GOOGLE_MAIL;
|
|
154
|
+
ProviderType.GOOGLE_CALENDAR;
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Example: Shopify Provider
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import { Provider, ProviderType, IShopifyMetadata } from "codebase-models";
|
|
161
|
+
|
|
162
|
+
const shopifyProvider = new Provider({
|
|
163
|
+
name: "My Shopify Store",
|
|
164
|
+
providerType: ProviderType.SHOPIFY,
|
|
165
|
+
client: clientId,
|
|
166
|
+
user: userId,
|
|
167
|
+
organizationId: orgId,
|
|
168
|
+
metadata: {
|
|
169
|
+
apiKey: "your-api-key",
|
|
170
|
+
apiSecretKey: "your-secret-key",
|
|
171
|
+
hostName: "your-store.myshopify.com",
|
|
172
|
+
apiVersion: "2026-01",
|
|
173
|
+
} as IShopifyMetadata,
|
|
174
|
+
active: true,
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
await shopifyProvider.save();
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Example: BigQuery Provider
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import { Provider, ProviderType, IBigQueryMetadata } from "codebase-models";
|
|
184
|
+
|
|
185
|
+
const bigQueryProvider = new Provider({
|
|
186
|
+
name: "Analytics BigQuery",
|
|
187
|
+
providerType: ProviderType.BIGQUERY,
|
|
188
|
+
client: clientId,
|
|
189
|
+
user: userId,
|
|
190
|
+
organizationId: orgId,
|
|
191
|
+
metadata: {
|
|
192
|
+
projectId: "your-project-id",
|
|
193
|
+
credentials: {
|
|
194
|
+
type: "service_account",
|
|
195
|
+
project_id: "your-project-id",
|
|
196
|
+
private_key_id: "key-id",
|
|
197
|
+
private_key:
|
|
198
|
+
"-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
|
|
199
|
+
client_email: "service-account@project.iam.gserviceaccount.com",
|
|
200
|
+
client_id: "client-id",
|
|
201
|
+
auth_uri: "https://accounts.google.com/o/oauth2/auth",
|
|
202
|
+
token_uri: "https://oauth2.googleapis.com/token",
|
|
203
|
+
auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs",
|
|
204
|
+
client_x509_cert_url:
|
|
205
|
+
"https://www.googleapis.com/robot/v1/metadata/x509/...",
|
|
206
|
+
},
|
|
207
|
+
datasetId: "your-dataset",
|
|
208
|
+
location: "US",
|
|
209
|
+
} as IBigQueryMetadata,
|
|
210
|
+
active: true,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
await bigQueryProvider.save();
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Querying Providers
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
// Find all active Shopify providers for a client
|
|
220
|
+
const shopifyProviders = await Provider.find({
|
|
221
|
+
providerType: ProviderType.SHOPIFY,
|
|
222
|
+
client: clientId,
|
|
223
|
+
active: true,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// Find provider by IID
|
|
227
|
+
const provider = await Provider.findOne({ iid: "ABC123XYZ456" });
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Utility Functions
|
|
231
|
+
|
|
232
|
+
### Generate Random IID
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
import { generateRandomIID } from "codebase-models";
|
|
236
|
+
|
|
237
|
+
const uniqueId = generateRandomIID(); // Returns 12-character uppercase string
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Constants
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
import {
|
|
244
|
+
RolesConstants,
|
|
245
|
+
PermissionsConstants,
|
|
246
|
+
PackageFeaturesConstants,
|
|
247
|
+
HypothesisSheetConstants,
|
|
248
|
+
} from "codebase-models";
|
|
249
|
+
|
|
250
|
+
// Available roles
|
|
251
|
+
RolesConstants; // ['USER', 'ADMIN', 'CLIENT', 'EXTERNAL', 'QA', 'OPTIMIZER']
|
|
252
|
+
|
|
253
|
+
// Permissions
|
|
254
|
+
PermissionsConstants.dashboard;
|
|
255
|
+
PermissionsConstants.reporting;
|
|
256
|
+
PermissionsConstants.insights;
|
|
257
|
+
// ... etc
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Model Patterns
|
|
261
|
+
|
|
262
|
+
All models follow consistent patterns:
|
|
263
|
+
|
|
264
|
+
1. **Model Name Check**: Models check `mongoose.models.modelname` before creation to prevent overwrite errors
|
|
265
|
+
2. **Lowercase Model Names**: All model names are lowercase (e.g., `"client"`, `"user"`, `"provider"`)
|
|
266
|
+
3. **Timestamps**: Most models include `createdAt` and `updatedAt` timestamps
|
|
267
|
+
4. **IID Support**: Many models use `iid` (internal ID) generated via `generateRandomIID()`
|
|
268
|
+
5. **Indexes**: Models include appropriate indexes for common query patterns
|
|
269
|
+
|
|
270
|
+
## TypeScript Support
|
|
271
|
+
|
|
272
|
+
All models export TypeScript interfaces:
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
import { Client, IClient } from "codebase-models";
|
|
276
|
+
import { Provider, IProvider, ProviderType } from "codebase-models";
|
|
277
|
+
import { User, IUser } from "codebase-models";
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## Development
|
|
281
|
+
|
|
282
|
+
### Building
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
npm run build
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
This will:
|
|
289
|
+
|
|
290
|
+
1. Clean the `dist` directory
|
|
291
|
+
2. Compile TypeScript with declaration files
|
|
292
|
+
|
|
293
|
+
### Publishing
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
npm publish
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
The `prepublish` script automatically builds before publishing.
|
|
300
|
+
|
|
301
|
+
## Requirements
|
|
302
|
+
|
|
303
|
+
- Node.js 20+
|
|
304
|
+
- MongoDB
|
|
305
|
+
- TypeScript 5.4+
|
|
306
|
+
|
|
307
|
+
## Dependencies
|
|
308
|
+
|
|
309
|
+
- `mongoose` ^8.2.3 - MongoDB ODM
|
|
310
|
+
- `mongoose-slug-updater` ^3.3.0 - Slug generation
|
|
311
|
+
- `uuid` ^11.1.0 - Unique ID generation
|
|
312
|
+
|
|
313
|
+
## License
|
|
314
|
+
|
|
315
|
+
ISC
|
|
316
|
+
|
|
317
|
+
## Repository
|
|
318
|
+
|
|
319
|
+
- **GitHub**: [Conversion-IO/codebase-models](https://github.com/Conversion-IO/codebase-models)
|
|
320
|
+
- **Issues**: [GitHub Issues](https://github.com/Conversion-IO/codebase-models/issues)
|
|
321
|
+
|
|
322
|
+
## Author
|
|
323
|
+
|
|
324
|
+
Vaibhav Anchal <vaibhav@conversion.io>
|
package/dist/index.d.ts
CHANGED
|
@@ -73,12 +73,13 @@ import { generateRandomIID, RolesConstants } from "./src/constant";
|
|
|
73
73
|
import TestTimeline from "./src/models/TestTimeline";
|
|
74
74
|
import CronData from "./src/models/CronData";
|
|
75
75
|
import CronConfig from "./src/models/CronConfig";
|
|
76
|
-
import UserIdentity from "./src/models/UserIdentity";
|
|
77
76
|
import UserOrganization from "./src/models/UserOrganization";
|
|
78
77
|
import Package from "./src/models/Package";
|
|
79
78
|
import Invitation from "./src/models/Invitation";
|
|
80
79
|
import Thread from "./src/models/Thread";
|
|
81
80
|
import ThreadMessage from "./src/models/ThreadMessage";
|
|
82
81
|
import Provider from "./src/models/Provider";
|
|
82
|
+
import ApiLog from "./src/models/ApiLog";
|
|
83
|
+
import { ProviderType } from "./src/models/Provider";
|
|
83
84
|
export declare function connect(uri: string, options?: mongoose.ConnectOptions | undefined): Promise<typeof mongoose>;
|
|
84
|
-
export { generateRandomIID, RolesConstants, Client, ClientReportsTemp, Report, Provider, 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,
|
|
85
|
+
export { generateRandomIID, RolesConstants, Client, ClientReportsTemp, Report, Provider, 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, UserOrganization, Package, Invitation, Thread, ThreadMessage, ApiLog, ProviderType, };
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
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.Provider = 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.
|
|
16
|
+
exports.ProviderType = exports.ApiLog = exports.ThreadMessage = exports.Thread = exports.Invitation = exports.Package = exports.UserOrganization = exports.UserPermission = exports.CronConfig = exports.CronData = 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;
|
|
@@ -116,8 +116,6 @@ const CronData_1 = __importDefault(require("./src/models/CronData"));
|
|
|
116
116
|
exports.CronData = CronData_1.default;
|
|
117
117
|
const CronConfig_1 = __importDefault(require("./src/models/CronConfig"));
|
|
118
118
|
exports.CronConfig = CronConfig_1.default;
|
|
119
|
-
const UserIdentity_1 = __importDefault(require("./src/models/UserIdentity"));
|
|
120
|
-
exports.UserIdentity = UserIdentity_1.default;
|
|
121
119
|
const UserOrganization_1 = __importDefault(require("./src/models/UserOrganization"));
|
|
122
120
|
exports.UserOrganization = UserOrganization_1.default;
|
|
123
121
|
const Package_1 = __importDefault(require("./src/models/Package"));
|
|
@@ -130,6 +128,10 @@ const ThreadMessage_1 = __importDefault(require("./src/models/ThreadMessage"));
|
|
|
130
128
|
exports.ThreadMessage = ThreadMessage_1.default;
|
|
131
129
|
const Provider_1 = __importDefault(require("./src/models/Provider"));
|
|
132
130
|
exports.Provider = Provider_1.default;
|
|
131
|
+
const ApiLog_1 = __importDefault(require("./src/models/ApiLog"));
|
|
132
|
+
exports.ApiLog = ApiLog_1.default;
|
|
133
|
+
const Provider_2 = require("./src/models/Provider");
|
|
134
|
+
Object.defineProperty(exports, "ProviderType", { enumerable: true, get: function () { return Provider_2.ProviderType; } });
|
|
133
135
|
function seedRoles() {
|
|
134
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
137
|
const checkRoles = yield Role_1.default.countDocuments();
|
|
@@ -23,13 +23,16 @@
|
|
|
23
23
|
/// <reference types="mongoose/types/virtuals" />
|
|
24
24
|
/// <reference types="mongoose/types/inferschematype" />
|
|
25
25
|
import mongoose, { Document } from "mongoose";
|
|
26
|
-
export interface
|
|
26
|
+
export interface IApiLog extends Document {
|
|
27
27
|
iid: string;
|
|
28
|
+
apiName: string;
|
|
29
|
+
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
30
|
+
client: mongoose.Schema.Types.ObjectId;
|
|
28
31
|
user: mongoose.Schema.Types.ObjectId;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
metadata
|
|
32
|
+
endpoint: string;
|
|
33
|
+
createdAt: Date;
|
|
34
|
+
updatedAt: Date;
|
|
35
|
+
metadata: mongoose.Schema.Types.Mixed;
|
|
33
36
|
}
|
|
34
|
-
declare const
|
|
35
|
-
export default
|
|
37
|
+
declare const ApiLog: mongoose.Model<any, {}, {}, {}, any, any>;
|
|
38
|
+
export default ApiLog;
|
|
@@ -25,13 +25,50 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const mongoose_1 = __importStar(require("mongoose"));
|
|
27
27
|
const constant_1 = require("../constant");
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
const Provider_1 = require("./Provider");
|
|
29
|
+
const ApiLogSchema = new mongoose_1.Schema({
|
|
30
|
+
iid: {
|
|
31
|
+
type: String,
|
|
32
|
+
trim: true,
|
|
33
|
+
unique: true,
|
|
34
|
+
default: () => (0, constant_1.generateRandomIID)(),
|
|
35
|
+
},
|
|
36
|
+
apiName: {
|
|
37
|
+
type: String,
|
|
38
|
+
required: true,
|
|
39
|
+
enum: Object.values(Provider_1.ProviderType),
|
|
40
|
+
trim: true,
|
|
41
|
+
},
|
|
42
|
+
organizationId: {
|
|
43
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
44
|
+
ref: "organization",
|
|
45
|
+
default: null,
|
|
46
|
+
required: true,
|
|
47
|
+
},
|
|
48
|
+
client: {
|
|
49
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
50
|
+
ref: "client",
|
|
51
|
+
default: null,
|
|
52
|
+
required: true,
|
|
53
|
+
},
|
|
54
|
+
user: {
|
|
55
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
56
|
+
ref: "user",
|
|
57
|
+
default: null,
|
|
58
|
+
required: true,
|
|
59
|
+
},
|
|
60
|
+
endpoint: {
|
|
61
|
+
type: String,
|
|
62
|
+
required: true,
|
|
63
|
+
trim: true,
|
|
64
|
+
},
|
|
65
|
+
metadata: {
|
|
66
|
+
type: mongoose_1.default.Schema.Types.Mixed,
|
|
67
|
+
default: null,
|
|
68
|
+
trim: true,
|
|
69
|
+
},
|
|
70
|
+
}, {
|
|
71
|
+
timestamps: true
|
|
72
|
+
});
|
|
73
|
+
const ApiLog = mongoose_1.default.models.apiLog || (0, mongoose_1.model)("apiLog", ApiLogSchema);
|
|
74
|
+
exports.default = ApiLog;
|
package/index.ts
CHANGED
|
@@ -50,13 +50,14 @@ import { generateRandomIID, RolesConstants } from "./src/constant";
|
|
|
50
50
|
import TestTimeline from "./src/models/TestTimeline";
|
|
51
51
|
import CronData from "./src/models/CronData";
|
|
52
52
|
import CronConfig from "./src/models/CronConfig";
|
|
53
|
-
import UserIdentity from "./src/models/UserIdentity";
|
|
54
53
|
import UserOrganization from "./src/models/UserOrganization";
|
|
55
54
|
import Package from "./src/models/Package";
|
|
56
55
|
import Invitation from "./src/models/Invitation";
|
|
57
56
|
import Thread from "./src/models/Thread";
|
|
58
57
|
import ThreadMessage from "./src/models/ThreadMessage";
|
|
59
58
|
import Provider from "./src/models/Provider";
|
|
59
|
+
import ApiLog from "./src/models/ApiLog";
|
|
60
|
+
import { ProviderType } from "./src/models/Provider";
|
|
60
61
|
async function seedRoles() {
|
|
61
62
|
const checkRoles = await Role.countDocuments();
|
|
62
63
|
if (checkRoles < RolesConstants.length) {
|
|
@@ -157,10 +158,11 @@ export {
|
|
|
157
158
|
CronData,
|
|
158
159
|
CronConfig,
|
|
159
160
|
UserPermission,
|
|
160
|
-
UserIdentity,
|
|
161
161
|
UserOrganization,
|
|
162
162
|
Package,
|
|
163
163
|
Invitation,
|
|
164
164
|
Thread,
|
|
165
165
|
ThreadMessage,
|
|
166
|
+
ApiLog,
|
|
167
|
+
ProviderType,
|
|
166
168
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codebase-models",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Common models for codebase",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"types": "./dist/index.d.ts",
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|
|
27
|
-
"url": "git+https://github.com/
|
|
27
|
+
"url": "git+https://github.com/Conversion-IO/codebase-models.git"
|
|
28
28
|
},
|
|
29
29
|
"bugs": {
|
|
30
|
-
"url": "https://github.com/
|
|
30
|
+
"url": "https://github.com/Conversion-IO/codebase-models/issues"
|
|
31
31
|
},
|
|
32
|
-
"homepage": "https://github.com/
|
|
32
|
+
"homepage": "https://github.com/Conversion-IO/codebase-models#readme"
|
|
33
33
|
}
|
package/src/constant.ts
CHANGED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
+
import { generateRandomIID } from "../constant";
|
|
3
|
+
import { ProviderType } from "./Provider";
|
|
4
|
+
|
|
5
|
+
export interface IApiLog extends Document {
|
|
6
|
+
iid: string;
|
|
7
|
+
apiName: string;
|
|
8
|
+
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
9
|
+
client: mongoose.Schema.Types.ObjectId;
|
|
10
|
+
user: mongoose.Schema.Types.ObjectId;
|
|
11
|
+
endpoint: string;
|
|
12
|
+
createdAt: Date;
|
|
13
|
+
updatedAt: Date;
|
|
14
|
+
metadata: mongoose.Schema.Types.Mixed;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const ApiLogSchema = new Schema<IApiLog>(
|
|
18
|
+
{
|
|
19
|
+
iid: {
|
|
20
|
+
type: String,
|
|
21
|
+
trim: true,
|
|
22
|
+
unique: true,
|
|
23
|
+
default: () => generateRandomIID(),
|
|
24
|
+
},
|
|
25
|
+
apiName: {
|
|
26
|
+
type: String,
|
|
27
|
+
required: true,
|
|
28
|
+
enum: Object.values(ProviderType) as [string],
|
|
29
|
+
trim: true,
|
|
30
|
+
},
|
|
31
|
+
organizationId: {
|
|
32
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
33
|
+
ref: "organization",
|
|
34
|
+
default: null,
|
|
35
|
+
required: true,
|
|
36
|
+
},
|
|
37
|
+
client: {
|
|
38
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
39
|
+
ref: "client",
|
|
40
|
+
default: null,
|
|
41
|
+
required: true,
|
|
42
|
+
},
|
|
43
|
+
user: {
|
|
44
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
45
|
+
ref: "user",
|
|
46
|
+
default: null,
|
|
47
|
+
required: true,
|
|
48
|
+
},
|
|
49
|
+
endpoint: {
|
|
50
|
+
type: String,
|
|
51
|
+
required: true,
|
|
52
|
+
trim: true,
|
|
53
|
+
},
|
|
54
|
+
metadata: {
|
|
55
|
+
type: mongoose.Schema.Types.Mixed,
|
|
56
|
+
default: null,
|
|
57
|
+
trim: true,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
timestamps: true
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const ApiLog = mongoose.models.apiLog || model<IApiLog>("apiLog", ApiLogSchema);
|
|
66
|
+
|
|
67
|
+
export default ApiLog;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
-
import { generateRandomIID } from "../constant";
|
|
3
|
-
|
|
4
|
-
export interface IUserIdentity extends Document {
|
|
5
|
-
iid: string;
|
|
6
|
-
user: mongoose.Schema.Types.ObjectId;
|
|
7
|
-
provider: "google" | "microsoft" | "github" | "facebook" | "apple";
|
|
8
|
-
providerUserId: string;
|
|
9
|
-
email: string;
|
|
10
|
-
metadata?: any;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const UserIdentitySchema = new Schema<IUserIdentity>(
|
|
14
|
-
{
|
|
15
|
-
iid: { type: String, unique: true, default: () => generateRandomIID() },
|
|
16
|
-
user: { type: mongoose.Schema.Types.ObjectId, ref: "user", required: true },
|
|
17
|
-
email: { type: String, unique: true, required: true },
|
|
18
|
-
providerUserId: { type: String, required: true },
|
|
19
|
-
provider: { type: String, enum: ["google", "microsoft", "github", "facebook", "apple"], required: true },
|
|
20
|
-
metadata: { type: mongoose.Schema.Types.Mixed, default: {} },
|
|
21
|
-
},
|
|
22
|
-
{ timestamps: true }
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
const UserIdentity = mongoose.models.useridentity || model<IUserIdentity>("useridentity", UserIdentitySchema);
|
|
26
|
-
export default UserIdentity;
|