streamby-core 0.12.3 → 0.14.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/db/initExportModel.d.ts +60 -0
- package/dist/db/initExportModel.js +18 -0
- package/dist/db/initProjectModel.d.ts +24 -0
- package/dist/db/initProjectModel.js +7 -4
- package/dist/db/initUserModel.d.ts +48 -0
- package/dist/db/initUserModel.js +19 -0
- package/dist/middleware/createRouter.js +111 -22
- package/dist/models/ExportCollection.d.ts +54 -0
- package/dist/models/ExportCollection.js +19 -0
- package/dist/providers/createDatabaseProvider.d.ts +1 -0
- package/dist/providers/createDatabaseProvider.js +9 -4
- package/dist/providers/mongoExportProvider.d.ts +3 -0
- package/dist/providers/mongoExportProvider.js +13 -0
- package/dist/providers/mongoProjectProvider.d.ts +1 -1
- package/dist/providers/mongoProjectProvider.js +60 -24
- package/dist/types/index.d.ts +40 -2
- package/package.json +1 -1
- package/dist/dev/server.d.ts +0 -4
- package/dist/dev/server.js +0 -14
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
export declare function initExportModel(connection: mongoose.Connection): mongoose.Model<{
|
|
3
|
+
createdAt: NativeDate;
|
|
4
|
+
updatedAt: NativeDate;
|
|
5
|
+
} & {
|
|
6
|
+
name: string;
|
|
7
|
+
collectionName: string;
|
|
8
|
+
projectId: mongoose.Types.ObjectId;
|
|
9
|
+
description?: string | null | undefined;
|
|
10
|
+
}, {}, {}, {}, mongoose.Document<unknown, {}, {
|
|
11
|
+
createdAt: NativeDate;
|
|
12
|
+
updatedAt: NativeDate;
|
|
13
|
+
} & {
|
|
14
|
+
name: string;
|
|
15
|
+
collectionName: string;
|
|
16
|
+
projectId: mongoose.Types.ObjectId;
|
|
17
|
+
description?: string | null | undefined;
|
|
18
|
+
}> & {
|
|
19
|
+
createdAt: NativeDate;
|
|
20
|
+
updatedAt: NativeDate;
|
|
21
|
+
} & {
|
|
22
|
+
name: string;
|
|
23
|
+
collectionName: string;
|
|
24
|
+
projectId: mongoose.Types.ObjectId;
|
|
25
|
+
description?: string | null | undefined;
|
|
26
|
+
} & {
|
|
27
|
+
_id: mongoose.Types.ObjectId;
|
|
28
|
+
} & {
|
|
29
|
+
__v: number;
|
|
30
|
+
}, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
31
|
+
timestamps: true;
|
|
32
|
+
}, {
|
|
33
|
+
createdAt: NativeDate;
|
|
34
|
+
updatedAt: NativeDate;
|
|
35
|
+
} & {
|
|
36
|
+
name: string;
|
|
37
|
+
collectionName: string;
|
|
38
|
+
projectId: mongoose.Types.ObjectId;
|
|
39
|
+
description?: string | null | undefined;
|
|
40
|
+
}, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
|
|
41
|
+
createdAt: NativeDate;
|
|
42
|
+
updatedAt: NativeDate;
|
|
43
|
+
} & {
|
|
44
|
+
name: string;
|
|
45
|
+
collectionName: string;
|
|
46
|
+
projectId: mongoose.Types.ObjectId;
|
|
47
|
+
description?: string | null | undefined;
|
|
48
|
+
}>> & mongoose.FlatRecord<{
|
|
49
|
+
createdAt: NativeDate;
|
|
50
|
+
updatedAt: NativeDate;
|
|
51
|
+
} & {
|
|
52
|
+
name: string;
|
|
53
|
+
collectionName: string;
|
|
54
|
+
projectId: mongoose.Types.ObjectId;
|
|
55
|
+
description?: string | null | undefined;
|
|
56
|
+
}> & {
|
|
57
|
+
_id: mongoose.Types.ObjectId;
|
|
58
|
+
} & {
|
|
59
|
+
__v: number;
|
|
60
|
+
}>>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.initExportModel = initExportModel;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
function initExportModel(connection) {
|
|
9
|
+
const exportSchema = new mongoose_1.default.Schema({
|
|
10
|
+
name: { type: String, required: true },
|
|
11
|
+
description: { type: String },
|
|
12
|
+
collectionName: { type: String, required: true },
|
|
13
|
+
projectId: { type: mongoose_1.default.Schema.Types.ObjectId, ref: 'Project', required: true },
|
|
14
|
+
}, {
|
|
15
|
+
timestamps: true
|
|
16
|
+
});
|
|
17
|
+
return connection.model('Export', exportSchema);
|
|
18
|
+
}
|
|
@@ -398,13 +398,17 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
398
398
|
members: mongoose.Types.DocumentArray<{
|
|
399
399
|
userId: mongoose.Types.ObjectId;
|
|
400
400
|
role: "viewer" | "editor" | "admin";
|
|
401
|
+
archived: boolean;
|
|
401
402
|
}, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
|
|
402
403
|
userId: mongoose.Types.ObjectId;
|
|
403
404
|
role: "viewer" | "editor" | "admin";
|
|
405
|
+
archived: boolean;
|
|
404
406
|
}> & {
|
|
405
407
|
userId: mongoose.Types.ObjectId;
|
|
406
408
|
role: "viewer" | "editor" | "admin";
|
|
409
|
+
archived: boolean;
|
|
407
410
|
}>;
|
|
411
|
+
exports: mongoose.Types.ObjectId[];
|
|
408
412
|
allowUpload: boolean;
|
|
409
413
|
allowSharing: boolean;
|
|
410
414
|
image?: string | null | undefined;
|
|
@@ -808,13 +812,17 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
808
812
|
members: mongoose.Types.DocumentArray<{
|
|
809
813
|
userId: mongoose.Types.ObjectId;
|
|
810
814
|
role: "viewer" | "editor" | "admin";
|
|
815
|
+
archived: boolean;
|
|
811
816
|
}, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
|
|
812
817
|
userId: mongoose.Types.ObjectId;
|
|
813
818
|
role: "viewer" | "editor" | "admin";
|
|
819
|
+
archived: boolean;
|
|
814
820
|
}> & {
|
|
815
821
|
userId: mongoose.Types.ObjectId;
|
|
816
822
|
role: "viewer" | "editor" | "admin";
|
|
823
|
+
archived: boolean;
|
|
817
824
|
}>;
|
|
825
|
+
exports: mongoose.Types.ObjectId[];
|
|
818
826
|
allowUpload: boolean;
|
|
819
827
|
allowSharing: boolean;
|
|
820
828
|
image?: string | null | undefined;
|
|
@@ -1218,13 +1226,17 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
1218
1226
|
members: mongoose.Types.DocumentArray<{
|
|
1219
1227
|
userId: mongoose.Types.ObjectId;
|
|
1220
1228
|
role: "viewer" | "editor" | "admin";
|
|
1229
|
+
archived: boolean;
|
|
1221
1230
|
}, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
|
|
1222
1231
|
userId: mongoose.Types.ObjectId;
|
|
1223
1232
|
role: "viewer" | "editor" | "admin";
|
|
1233
|
+
archived: boolean;
|
|
1224
1234
|
}> & {
|
|
1225
1235
|
userId: mongoose.Types.ObjectId;
|
|
1226
1236
|
role: "viewer" | "editor" | "admin";
|
|
1237
|
+
archived: boolean;
|
|
1227
1238
|
}>;
|
|
1239
|
+
exports: mongoose.Types.ObjectId[];
|
|
1228
1240
|
allowUpload: boolean;
|
|
1229
1241
|
allowSharing: boolean;
|
|
1230
1242
|
image?: string | null | undefined;
|
|
@@ -1634,13 +1646,17 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
1634
1646
|
members: mongoose.Types.DocumentArray<{
|
|
1635
1647
|
userId: mongoose.Types.ObjectId;
|
|
1636
1648
|
role: "viewer" | "editor" | "admin";
|
|
1649
|
+
archived: boolean;
|
|
1637
1650
|
}, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
|
|
1638
1651
|
userId: mongoose.Types.ObjectId;
|
|
1639
1652
|
role: "viewer" | "editor" | "admin";
|
|
1653
|
+
archived: boolean;
|
|
1640
1654
|
}> & {
|
|
1641
1655
|
userId: mongoose.Types.ObjectId;
|
|
1642
1656
|
role: "viewer" | "editor" | "admin";
|
|
1657
|
+
archived: boolean;
|
|
1643
1658
|
}>;
|
|
1659
|
+
exports: mongoose.Types.ObjectId[];
|
|
1644
1660
|
allowUpload: boolean;
|
|
1645
1661
|
allowSharing: boolean;
|
|
1646
1662
|
image?: string | null | undefined;
|
|
@@ -2044,13 +2060,17 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
2044
2060
|
members: mongoose.Types.DocumentArray<{
|
|
2045
2061
|
userId: mongoose.Types.ObjectId;
|
|
2046
2062
|
role: "viewer" | "editor" | "admin";
|
|
2063
|
+
archived: boolean;
|
|
2047
2064
|
}, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
|
|
2048
2065
|
userId: mongoose.Types.ObjectId;
|
|
2049
2066
|
role: "viewer" | "editor" | "admin";
|
|
2067
|
+
archived: boolean;
|
|
2050
2068
|
}> & {
|
|
2051
2069
|
userId: mongoose.Types.ObjectId;
|
|
2052
2070
|
role: "viewer" | "editor" | "admin";
|
|
2071
|
+
archived: boolean;
|
|
2053
2072
|
}>;
|
|
2073
|
+
exports: mongoose.Types.ObjectId[];
|
|
2054
2074
|
allowUpload: boolean;
|
|
2055
2075
|
allowSharing: boolean;
|
|
2056
2076
|
image?: string | null | undefined;
|
|
@@ -2454,13 +2474,17 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
2454
2474
|
members: mongoose.Types.DocumentArray<{
|
|
2455
2475
|
userId: mongoose.Types.ObjectId;
|
|
2456
2476
|
role: "viewer" | "editor" | "admin";
|
|
2477
|
+
archived: boolean;
|
|
2457
2478
|
}, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
|
|
2458
2479
|
userId: mongoose.Types.ObjectId;
|
|
2459
2480
|
role: "viewer" | "editor" | "admin";
|
|
2481
|
+
archived: boolean;
|
|
2460
2482
|
}> & {
|
|
2461
2483
|
userId: mongoose.Types.ObjectId;
|
|
2462
2484
|
role: "viewer" | "editor" | "admin";
|
|
2485
|
+
archived: boolean;
|
|
2463
2486
|
}>;
|
|
2487
|
+
exports: mongoose.Types.ObjectId[];
|
|
2464
2488
|
allowUpload: boolean;
|
|
2465
2489
|
allowSharing: boolean;
|
|
2466
2490
|
image?: string | null | undefined;
|
|
@@ -11,6 +11,11 @@ function initProjectModel(connection) {
|
|
|
11
11
|
name: String,
|
|
12
12
|
children: [Object],
|
|
13
13
|
}, { _id: false });
|
|
14
|
+
const memberSchema = new mongoose_1.default.Schema({
|
|
15
|
+
userId: { type: mongoose_1.default.Schema.Types.ObjectId, ref: 'User', required: true },
|
|
16
|
+
role: { type: String, enum: ['viewer', 'editor', 'admin'], default: 'viewer' },
|
|
17
|
+
archived: { type: Boolean, default: false }
|
|
18
|
+
}, { _id: false });
|
|
14
19
|
const projectSchema = new mongoose_1.default.Schema({
|
|
15
20
|
name: { type: String, required: true },
|
|
16
21
|
description: { type: String },
|
|
@@ -18,10 +23,8 @@ function initProjectModel(connection) {
|
|
|
18
23
|
rootFolders: [folderNodeSchema],
|
|
19
24
|
allowUpload: { type: Boolean, default: true },
|
|
20
25
|
allowSharing: { type: Boolean, default: false },
|
|
21
|
-
members: [
|
|
22
|
-
|
|
23
|
-
role: { type: String, enum: ['viewer', 'editor', 'admin'], default: 'viewer' }
|
|
24
|
-
}]
|
|
26
|
+
members: [memberSchema],
|
|
27
|
+
exports: [{ type: mongoose_1.default.Schema.Types.ObjectId, ref: 'Export' }]
|
|
25
28
|
}, {
|
|
26
29
|
timestamps: true
|
|
27
30
|
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
export declare function initUserModel(connection: mongoose.Connection): mongoose.Model<any, {}, {}, {}, any, any> | mongoose.Model<{
|
|
3
|
+
createdAt: NativeDate;
|
|
4
|
+
updatedAt: NativeDate;
|
|
5
|
+
} & {
|
|
6
|
+
username: string;
|
|
7
|
+
email: string;
|
|
8
|
+
}, {}, {}, {}, mongoose.Document<unknown, {}, {
|
|
9
|
+
createdAt: NativeDate;
|
|
10
|
+
updatedAt: NativeDate;
|
|
11
|
+
} & {
|
|
12
|
+
username: string;
|
|
13
|
+
email: string;
|
|
14
|
+
}> & {
|
|
15
|
+
createdAt: NativeDate;
|
|
16
|
+
updatedAt: NativeDate;
|
|
17
|
+
} & {
|
|
18
|
+
username: string;
|
|
19
|
+
email: string;
|
|
20
|
+
} & {
|
|
21
|
+
_id: mongoose.Types.ObjectId;
|
|
22
|
+
} & {
|
|
23
|
+
__v: number;
|
|
24
|
+
}, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
25
|
+
timestamps: true;
|
|
26
|
+
}, {
|
|
27
|
+
createdAt: NativeDate;
|
|
28
|
+
updatedAt: NativeDate;
|
|
29
|
+
} & {
|
|
30
|
+
username: string;
|
|
31
|
+
email: string;
|
|
32
|
+
}, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
|
|
33
|
+
createdAt: NativeDate;
|
|
34
|
+
updatedAt: NativeDate;
|
|
35
|
+
} & {
|
|
36
|
+
username: string;
|
|
37
|
+
email: string;
|
|
38
|
+
}>> & mongoose.FlatRecord<{
|
|
39
|
+
createdAt: NativeDate;
|
|
40
|
+
updatedAt: NativeDate;
|
|
41
|
+
} & {
|
|
42
|
+
username: string;
|
|
43
|
+
email: string;
|
|
44
|
+
}> & {
|
|
45
|
+
_id: mongoose.Types.ObjectId;
|
|
46
|
+
} & {
|
|
47
|
+
__v: number;
|
|
48
|
+
}>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.initUserModel = initUserModel;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
function initUserModel(connection) {
|
|
9
|
+
const userSchema = new mongoose_1.default.Schema({
|
|
10
|
+
username: { type: String, required: true, unique: true },
|
|
11
|
+
email: { type: String, required: true, unique: true },
|
|
12
|
+
}, {
|
|
13
|
+
timestamps: true
|
|
14
|
+
});
|
|
15
|
+
if (connection.models.User) {
|
|
16
|
+
return connection.models.User;
|
|
17
|
+
}
|
|
18
|
+
return connection.model('User', userSchema);
|
|
19
|
+
}
|
|
@@ -15,13 +15,11 @@ function isProjectMember(project, userId) {
|
|
|
15
15
|
function createStreamByRouter(config) {
|
|
16
16
|
const router = express_1.default.Router();
|
|
17
17
|
const adapter = config.adapter || (0, createStorageProvider_1.createStorageProvider)(config.storageProviders);
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return dbResult.projectProvider;
|
|
24
|
-
})();
|
|
18
|
+
const dbResult = config.projectProvider
|
|
19
|
+
? { projectProvider: config.projectProvider, exportProvider: config.exportProvider, mongoConnection: undefined }
|
|
20
|
+
: (0, createDatabaseProvider_1.createDatabaseProvider)(config.databases, adapter);
|
|
21
|
+
const projectProvider = dbResult.projectProvider;
|
|
22
|
+
const exportProvider = dbResult.exportProvider;
|
|
25
23
|
router.get('/auth', async (req, res) => {
|
|
26
24
|
try {
|
|
27
25
|
const auth = await config.authProvider(req);
|
|
@@ -80,21 +78,14 @@ function createStreamByRouter(config) {
|
|
|
80
78
|
res.status(500).json({ error: 'Failed to list files', details: err });
|
|
81
79
|
}
|
|
82
80
|
});
|
|
83
|
-
router.get('/projects
|
|
81
|
+
router.get('/projects', async (req, res) => {
|
|
84
82
|
try {
|
|
85
83
|
const auth = await config.authProvider(req);
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
if (!project) {
|
|
89
|
-
return res.status(404).json({ error: 'Project not found' });
|
|
90
|
-
}
|
|
91
|
-
if (!isProjectMember(project, auth.userId)) {
|
|
92
|
-
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
93
|
-
}
|
|
94
|
-
res.json({ project });
|
|
84
|
+
const projects = await projectProvider.list(auth.userId);
|
|
85
|
+
res.json({ projects });
|
|
95
86
|
}
|
|
96
87
|
catch (err) {
|
|
97
|
-
res.status(500).json({ error: 'Failed to
|
|
88
|
+
res.status(500).json({ error: 'Failed to list projects', details: err });
|
|
98
89
|
}
|
|
99
90
|
});
|
|
100
91
|
router.post('/projects/create', async (req, res) => {
|
|
@@ -115,6 +106,23 @@ function createStreamByRouter(config) {
|
|
|
115
106
|
res.status(500).json({ error: 'Failed to create project', details: err.message });
|
|
116
107
|
}
|
|
117
108
|
});
|
|
109
|
+
router.get('/projects/:id', async (req, res) => {
|
|
110
|
+
try {
|
|
111
|
+
const auth = await config.authProvider(req);
|
|
112
|
+
const projectId = req.params.id;
|
|
113
|
+
const project = await projectProvider.getById(projectId);
|
|
114
|
+
if (!project) {
|
|
115
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
116
|
+
}
|
|
117
|
+
if (!isProjectMember(project, auth.userId)) {
|
|
118
|
+
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
119
|
+
}
|
|
120
|
+
res.json({ project });
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
res.status(500).json({ error: 'Failed to fetch project', details: err.message });
|
|
124
|
+
}
|
|
125
|
+
});
|
|
118
126
|
router.patch('/projects/:id', async (req, res) => {
|
|
119
127
|
try {
|
|
120
128
|
const auth = await config.authProvider(req);
|
|
@@ -158,14 +166,95 @@ function createStreamByRouter(config) {
|
|
|
158
166
|
res.status(500).json({ error: 'Failed to delete project', details: err.message });
|
|
159
167
|
}
|
|
160
168
|
});
|
|
161
|
-
router.
|
|
169
|
+
router.patch('/projects/:id/archive', async (req, res) => {
|
|
162
170
|
try {
|
|
163
171
|
const auth = await config.authProvider(req);
|
|
164
|
-
const
|
|
165
|
-
|
|
172
|
+
const projectId = req.params.id;
|
|
173
|
+
const project = await projectProvider.getById(projectId);
|
|
174
|
+
if (!project || !isProjectMember(project, auth.userId)) {
|
|
175
|
+
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
176
|
+
}
|
|
177
|
+
const result = await projectProvider.archive(projectId, auth.userId);
|
|
178
|
+
res.status(200).json(result);
|
|
166
179
|
}
|
|
167
180
|
catch (err) {
|
|
168
|
-
res.status(500).json({ error: 'Failed to
|
|
181
|
+
res.status(500).json({ error: 'Failed to archive project', details: err.message });
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
router.patch('/projects/:id/unarchive', async (req, res) => {
|
|
185
|
+
try {
|
|
186
|
+
const auth = await config.authProvider(req);
|
|
187
|
+
const projectId = req.params.id;
|
|
188
|
+
const project = await projectProvider.getById(projectId);
|
|
189
|
+
if (!project || !isProjectMember(project, auth.userId)) {
|
|
190
|
+
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
191
|
+
}
|
|
192
|
+
const result = await projectProvider.unarchive(projectId, auth.userId);
|
|
193
|
+
res.status(200).json(result);
|
|
194
|
+
}
|
|
195
|
+
catch (err) {
|
|
196
|
+
res.status(500).json({ error: 'Failed to unarchive project', details: err.message });
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
router.get('/projects/:id/exports/:export_id', async (req, res) => {
|
|
200
|
+
try {
|
|
201
|
+
const auth = await config.authProvider(req);
|
|
202
|
+
const projectId = req.params.id;
|
|
203
|
+
const exportId = req.params.export_id;
|
|
204
|
+
const project = await projectProvider.getById(projectId);
|
|
205
|
+
if (!project) {
|
|
206
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
207
|
+
}
|
|
208
|
+
if (!isProjectMember(project, auth.userId)) {
|
|
209
|
+
return res.status(403).json({ error: 'Unauthorized access' });
|
|
210
|
+
}
|
|
211
|
+
const data = await exportProvider.getById(exportId);
|
|
212
|
+
res.json({ data });
|
|
213
|
+
}
|
|
214
|
+
catch (err) {
|
|
215
|
+
res.status(500).json({ error: 'Failed to fetch export data', details: err.message });
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
router.post('/projects/:id/exports', async (req, res) => {
|
|
219
|
+
try {
|
|
220
|
+
const auth = await config.authProvider(req);
|
|
221
|
+
const projectId = req.params.id;
|
|
222
|
+
const { name, description, collectionName } = req.body;
|
|
223
|
+
if (!name || !collectionName) {
|
|
224
|
+
return res.status(400).json({ error: 'Missing export name or collectionName' });
|
|
225
|
+
}
|
|
226
|
+
const project = await projectProvider.getById(projectId);
|
|
227
|
+
if (!project || !isProjectMember(project, auth.userId)) {
|
|
228
|
+
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
229
|
+
}
|
|
230
|
+
const newExport = await exportProvider.create({
|
|
231
|
+
name,
|
|
232
|
+
description,
|
|
233
|
+
collectionName,
|
|
234
|
+
projectId
|
|
235
|
+
});
|
|
236
|
+
await projectProvider.addExportToProject(projectId, newExport.id);
|
|
237
|
+
res.status(201).json({ data: newExport });
|
|
238
|
+
}
|
|
239
|
+
catch (err) {
|
|
240
|
+
res.status(500).json({ error: 'Failed to create export', details: err.message });
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
router.get('/projects/:id/members', async (req, res) => {
|
|
244
|
+
try {
|
|
245
|
+
const auth = await config.authProvider(req);
|
|
246
|
+
const projectId = req.params.id;
|
|
247
|
+
const project = await projectProvider.getById(projectId, true);
|
|
248
|
+
if (!project) {
|
|
249
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
250
|
+
}
|
|
251
|
+
if (!isProjectMember(project, auth.userId)) {
|
|
252
|
+
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
253
|
+
}
|
|
254
|
+
res.json({ members: project.members });
|
|
255
|
+
}
|
|
256
|
+
catch (err) {
|
|
257
|
+
res.status(500).json({ error: 'Failed to fetch project members', details: err.message });
|
|
169
258
|
}
|
|
170
259
|
});
|
|
171
260
|
return router;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
export declare function initExportCollectionModel(connection: mongoose.Connection): mongoose.Model<{
|
|
3
|
+
createdAt: NativeDate;
|
|
4
|
+
updatedAt: NativeDate;
|
|
5
|
+
} & {
|
|
6
|
+
name: string;
|
|
7
|
+
entries: mongoose.Types.DocumentArray<{}, mongoose.Types.Subdocument<unknown, any, {}>>;
|
|
8
|
+
projectId: mongoose.Types.ObjectId;
|
|
9
|
+
}, {}, {}, {}, mongoose.Document<unknown, {}, {
|
|
10
|
+
createdAt: NativeDate;
|
|
11
|
+
updatedAt: NativeDate;
|
|
12
|
+
} & {
|
|
13
|
+
name: string;
|
|
14
|
+
entries: mongoose.Types.DocumentArray<{}, mongoose.Types.Subdocument<unknown, any, {}>>;
|
|
15
|
+
projectId: mongoose.Types.ObjectId;
|
|
16
|
+
}> & {
|
|
17
|
+
createdAt: NativeDate;
|
|
18
|
+
updatedAt: NativeDate;
|
|
19
|
+
} & {
|
|
20
|
+
name: string;
|
|
21
|
+
entries: mongoose.Types.DocumentArray<{}, mongoose.Types.Subdocument<unknown, any, {}>>;
|
|
22
|
+
projectId: mongoose.Types.ObjectId;
|
|
23
|
+
} & {
|
|
24
|
+
_id: mongoose.Types.ObjectId;
|
|
25
|
+
} & {
|
|
26
|
+
__v: number;
|
|
27
|
+
}, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
28
|
+
timestamps: true;
|
|
29
|
+
}, {
|
|
30
|
+
createdAt: NativeDate;
|
|
31
|
+
updatedAt: NativeDate;
|
|
32
|
+
} & {
|
|
33
|
+
name: string;
|
|
34
|
+
entries: mongoose.Types.DocumentArray<{}, mongoose.Types.Subdocument<unknown, any, {}>>;
|
|
35
|
+
projectId: mongoose.Types.ObjectId;
|
|
36
|
+
}, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
|
|
37
|
+
createdAt: NativeDate;
|
|
38
|
+
updatedAt: NativeDate;
|
|
39
|
+
} & {
|
|
40
|
+
name: string;
|
|
41
|
+
entries: mongoose.Types.DocumentArray<{}, mongoose.Types.Subdocument<unknown, any, {}>>;
|
|
42
|
+
projectId: mongoose.Types.ObjectId;
|
|
43
|
+
}>> & mongoose.FlatRecord<{
|
|
44
|
+
createdAt: NativeDate;
|
|
45
|
+
updatedAt: NativeDate;
|
|
46
|
+
} & {
|
|
47
|
+
name: string;
|
|
48
|
+
entries: mongoose.Types.DocumentArray<{}, mongoose.Types.Subdocument<unknown, any, {}>>;
|
|
49
|
+
projectId: mongoose.Types.ObjectId;
|
|
50
|
+
}> & {
|
|
51
|
+
_id: mongoose.Types.ObjectId;
|
|
52
|
+
} & {
|
|
53
|
+
__v: number;
|
|
54
|
+
}>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.initExportCollectionModel = initExportCollectionModel;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
const ExportEntrySchema = new mongoose_1.default.Schema({}, { strict: false, _id: false });
|
|
9
|
+
const ExportCollectionSchema = new mongoose_1.default.Schema({
|
|
10
|
+
projectId: { type: mongoose_1.default.Schema.Types.ObjectId, ref: 'Project', required: true },
|
|
11
|
+
name: { type: String, required: true }, // e.g., "experience"
|
|
12
|
+
entries: [ExportEntrySchema],
|
|
13
|
+
}, {
|
|
14
|
+
timestamps: true,
|
|
15
|
+
});
|
|
16
|
+
ExportCollectionSchema.index({ projectId: 1, name: 1 }, { unique: true });
|
|
17
|
+
function initExportCollectionModel(connection) {
|
|
18
|
+
return connection.model('ExportCollection', ExportCollectionSchema);
|
|
19
|
+
}
|
|
@@ -6,6 +6,7 @@ export interface DatabaseCredential {
|
|
|
6
6
|
connectionString: string;
|
|
7
7
|
}
|
|
8
8
|
export declare function createDatabaseProvider(databases: DatabaseCredential[], adapter: StorageAdapter): {
|
|
9
|
+
exportProvider: import("../types").ExportProvider;
|
|
9
10
|
projectProvider: import("../types").ProjectProvider;
|
|
10
11
|
mongoConnection: mongoose.Connection;
|
|
11
12
|
};
|
|
@@ -6,20 +6,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createDatabaseProvider = createDatabaseProvider;
|
|
7
7
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
8
|
const initProjectModel_1 = require("../db/initProjectModel");
|
|
9
|
+
const initUserModel_1 = require("../db/initUserModel");
|
|
10
|
+
const mongoExportProvider_1 = require("./mongoExportProvider");
|
|
9
11
|
const mongoProjectProvider_1 = require("./mongoProjectProvider");
|
|
12
|
+
const initExportModel_1 = require("../db/initExportModel");
|
|
10
13
|
function createDatabaseProvider(databases, adapter) {
|
|
11
|
-
// Solo una conexión mongo por ahora
|
|
12
14
|
const mongoConfig = databases.find((db) => db.dbType === 'mongo');
|
|
13
15
|
if (!mongoConfig) {
|
|
14
16
|
throw new Error('No MongoDB configuration provided. Mongo is currently required.');
|
|
15
17
|
}
|
|
16
|
-
// Conexión a MongoDB
|
|
17
18
|
const connection = mongoose_1.default.createConnection(mongoConfig.connectionString, {
|
|
18
|
-
dbName: undefined,
|
|
19
|
+
dbName: undefined,
|
|
19
20
|
});
|
|
21
|
+
const ExportModel = (0, initExportModel_1.initExportModel)(connection);
|
|
20
22
|
const ProjectModel = (0, initProjectModel_1.initProjectModel)(connection);
|
|
21
|
-
const
|
|
23
|
+
const UserModel = (0, initUserModel_1.initUserModel)(connection);
|
|
24
|
+
const exportProvider = (0, mongoExportProvider_1.createMongoExportProvider)(ExportModel);
|
|
25
|
+
const projectProvider = (0, mongoProjectProvider_1.createMongoProjectProvider)(ProjectModel, ExportModel, adapter);
|
|
22
26
|
return {
|
|
27
|
+
exportProvider,
|
|
23
28
|
projectProvider,
|
|
24
29
|
mongoConnection: connection,
|
|
25
30
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMongoExportProvider = createMongoExportProvider;
|
|
4
|
+
function createMongoExportProvider(ExportModel) {
|
|
5
|
+
return {
|
|
6
|
+
async getById(exportId) {
|
|
7
|
+
return await ExportModel.findById(exportId).lean();
|
|
8
|
+
},
|
|
9
|
+
async create(data) {
|
|
10
|
+
return await ExportModel.create(data);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ProjectProvider, StorageAdapter } from '../types';
|
|
2
2
|
import { Model } from 'mongoose';
|
|
3
|
-
export declare function createMongoProjectProvider(ProjectModel: Model<any>, adapter: StorageAdapter): ProjectProvider;
|
|
3
|
+
export declare function createMongoProjectProvider(ProjectModel: Model<any>, ExportModel: Model<any>, adapter: StorageAdapter): ProjectProvider;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createMongoProjectProvider = createMongoProjectProvider;
|
|
4
|
-
function createMongoProjectProvider(ProjectModel, adapter) {
|
|
4
|
+
function createMongoProjectProvider(ProjectModel, ExportModel, adapter) {
|
|
5
5
|
return {
|
|
6
|
-
async getById(projectId) {
|
|
7
|
-
|
|
6
|
+
async getById(projectId, populateMembers = false) {
|
|
7
|
+
let query = ProjectModel.findById(projectId).populate('exports', ['_id', 'collectionName']);
|
|
8
|
+
if (populateMembers) {
|
|
9
|
+
query = query.populate('members.userId');
|
|
10
|
+
}
|
|
11
|
+
const project = await query;
|
|
8
12
|
if (!project)
|
|
9
13
|
throw new Error('Project not found');
|
|
10
14
|
return formatProject(project);
|
|
@@ -15,6 +19,7 @@ function createMongoProjectProvider(ProjectModel, adapter) {
|
|
|
15
19
|
{
|
|
16
20
|
userId: data.members?.[0].userId,
|
|
17
21
|
role: data.members?.[0].role,
|
|
22
|
+
archived: false
|
|
18
23
|
}
|
|
19
24
|
],
|
|
20
25
|
name: data.name,
|
|
@@ -27,15 +32,16 @@ function createMongoProjectProvider(ProjectModel, adapter) {
|
|
|
27
32
|
return formatProject(newProject);
|
|
28
33
|
},
|
|
29
34
|
async update(projectId, updates) {
|
|
30
|
-
const updated = await ProjectModel.findByIdAndUpdate(projectId, updates, { new: true });
|
|
35
|
+
const updated = await ProjectModel.findByIdAndUpdate(projectId, updates, { new: true }).populate('exports', ['_id', 'collectionName']);
|
|
31
36
|
if (!updated)
|
|
32
37
|
throw new Error('Project not found');
|
|
33
38
|
return formatProject(updated);
|
|
34
39
|
},
|
|
35
40
|
async list(userId) {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
const all = await ProjectModel.find(userId
|
|
42
|
+
? { 'members': { $elemMatch: { userId } } }
|
|
43
|
+
: {});
|
|
44
|
+
return all.map(doc => formatProjectList(doc, userId));
|
|
39
45
|
},
|
|
40
46
|
async delete(projectId) {
|
|
41
47
|
try {
|
|
@@ -46,23 +52,53 @@ function createMongoProjectProvider(ProjectModel, adapter) {
|
|
|
46
52
|
catch (error) {
|
|
47
53
|
throw new Error('Project not found');
|
|
48
54
|
}
|
|
55
|
+
},
|
|
56
|
+
async archive(projectId, userId) {
|
|
57
|
+
await ProjectModel.updateOne({ _id: projectId, 'members.userId': userId }, { $set: { 'members.$.archived': true } });
|
|
58
|
+
return { success: true, projects: await this.list(userId) };
|
|
59
|
+
},
|
|
60
|
+
async unarchive(projectId, userId) {
|
|
61
|
+
await ProjectModel.updateOne({ _id: projectId, 'members.userId': userId }, { $set: { 'members.$.archived': false } });
|
|
62
|
+
return { success: true, projects: await this.list(userId) };
|
|
63
|
+
},
|
|
64
|
+
async getExport(projectId, exportId) {
|
|
65
|
+
const exportDoc = await ExportModel.findOne({ _id: exportId, project: projectId });
|
|
66
|
+
if (!exportDoc)
|
|
67
|
+
throw new Error('Export not found');
|
|
68
|
+
return exportDoc;
|
|
69
|
+
},
|
|
70
|
+
async addExportToProject(projectId, exportId) {
|
|
71
|
+
await ProjectModel.findByIdAndUpdate(projectId, { $push: { exports: exportId } });
|
|
49
72
|
}
|
|
50
73
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
74
|
+
function formatProject(doc) {
|
|
75
|
+
return {
|
|
76
|
+
id: doc._id.toString(),
|
|
77
|
+
name: doc.name,
|
|
78
|
+
image: doc.image,
|
|
79
|
+
members: doc.members.map((m) => ({
|
|
80
|
+
userId: m.userId?._id || m.userId,
|
|
81
|
+
username: m.userId?.username,
|
|
82
|
+
email: m.userId?.email,
|
|
83
|
+
role: m.role,
|
|
84
|
+
archived: m.archived ?? false
|
|
85
|
+
})),
|
|
86
|
+
description: doc.description,
|
|
87
|
+
rootFolders: doc.rootFolders || [],
|
|
88
|
+
settings: {
|
|
89
|
+
allowUpload: doc.allowUpload,
|
|
90
|
+
allowSharing: doc.allowSharing,
|
|
91
|
+
},
|
|
92
|
+
exports: doc.exports || []
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function formatProjectList(doc, userId) {
|
|
96
|
+
const archived = doc.members?.find((m) => m.userId?.toString() === userId)?.archived ?? false;
|
|
97
|
+
return {
|
|
98
|
+
id: doc._id.toString(),
|
|
99
|
+
name: doc.name,
|
|
100
|
+
image: doc.image,
|
|
101
|
+
archived
|
|
102
|
+
};
|
|
103
|
+
}
|
|
68
104
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -28,16 +28,27 @@ export interface ProjectInfo {
|
|
|
28
28
|
name: string;
|
|
29
29
|
image?: string;
|
|
30
30
|
members?: {
|
|
31
|
-
userId: string;
|
|
32
31
|
role: 'viewer' | 'editor' | 'admin';
|
|
32
|
+
userId: string;
|
|
33
|
+
archived?: boolean;
|
|
33
34
|
}[];
|
|
34
35
|
description?: string;
|
|
35
36
|
rootFolders?: FolderNode[];
|
|
37
|
+
exports?: {
|
|
38
|
+
_id: string;
|
|
39
|
+
collectionName: string;
|
|
40
|
+
}[];
|
|
36
41
|
settings?: {
|
|
37
42
|
allowUpload?: boolean;
|
|
38
43
|
allowSharing?: boolean;
|
|
39
44
|
};
|
|
40
45
|
}
|
|
46
|
+
export interface ProjectListInfo {
|
|
47
|
+
id: string;
|
|
48
|
+
name: string;
|
|
49
|
+
image?: string;
|
|
50
|
+
archived: boolean;
|
|
51
|
+
}
|
|
41
52
|
export interface FolderNode {
|
|
42
53
|
id: string;
|
|
43
54
|
name: string;
|
|
@@ -55,6 +66,7 @@ export interface StreamByConfig {
|
|
|
55
66
|
}[];
|
|
56
67
|
authProvider: AuthProvider;
|
|
57
68
|
databases?: DatabaseCredential[];
|
|
69
|
+
exportProvider?: ExportProvider;
|
|
58
70
|
projectProvider?: ProjectProvider;
|
|
59
71
|
adapter?: StorageAdapter;
|
|
60
72
|
}
|
|
@@ -65,9 +77,34 @@ export interface AuthContext {
|
|
|
65
77
|
role: 'viewer' | 'editor' | 'admin';
|
|
66
78
|
}
|
|
67
79
|
export type AuthProvider = (req: Request) => Promise<AuthContext>;
|
|
80
|
+
export interface Export {
|
|
81
|
+
id: string;
|
|
82
|
+
collectionName: string;
|
|
83
|
+
projectId: string;
|
|
84
|
+
createdAt: Date;
|
|
85
|
+
updatedAt: Date;
|
|
86
|
+
}
|
|
87
|
+
export interface ExportProvider {
|
|
88
|
+
getById(exportId: string): Promise<Export>;
|
|
89
|
+
create(data: {
|
|
90
|
+
name: string;
|
|
91
|
+
description?: string;
|
|
92
|
+
collectionName: string;
|
|
93
|
+
projectId: string;
|
|
94
|
+
}): Promise<Export>;
|
|
95
|
+
}
|
|
68
96
|
export interface ProjectProvider {
|
|
97
|
+
getExport(projectId: string, exportName: string): Promise<any[]>;
|
|
98
|
+
archive(projectId: string, userId: string): Promise<{
|
|
99
|
+
success: boolean;
|
|
100
|
+
projects: ProjectInfo[];
|
|
101
|
+
}>;
|
|
102
|
+
unarchive(projectId: string, userId: string): Promise<{
|
|
103
|
+
success: boolean;
|
|
104
|
+
projects: ProjectInfo[];
|
|
105
|
+
}>;
|
|
69
106
|
list(userId?: string): Promise<ProjectInfo[]>;
|
|
70
|
-
getById(projectId: string): Promise<ProjectInfo>;
|
|
107
|
+
getById(projectId: string, populateMembers?: boolean): Promise<ProjectInfo>;
|
|
71
108
|
delete(projectId: string): Promise<{
|
|
72
109
|
success: boolean;
|
|
73
110
|
}>;
|
|
@@ -84,4 +121,5 @@ export interface ProjectProvider {
|
|
|
84
121
|
allowSharing?: boolean;
|
|
85
122
|
rootFolders?: FolderNode[];
|
|
86
123
|
}): Promise<ProjectInfo>;
|
|
124
|
+
addExportToProject(projectId: string, exportId: string): Promise<void>;
|
|
87
125
|
}
|
package/package.json
CHANGED
package/dist/dev/server.d.ts
DELETED
package/dist/dev/server.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createDevServer = createDevServer;
|
|
7
|
-
const express_1 = __importDefault(require("express"));
|
|
8
|
-
const createRouter_1 = require("../middleware/createRouter");
|
|
9
|
-
function createDevServer(config) {
|
|
10
|
-
const app = (0, express_1.default)();
|
|
11
|
-
app.use(express_1.default.json());
|
|
12
|
-
app.use((0, createRouter_1.createStreamByRouter)(config));
|
|
13
|
-
return app;
|
|
14
|
-
}
|