@ntalmagor/3drise-common 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/database.d.ts +3 -0
- package/build/database.js +33 -0
- package/build/errors/bad-request-error.d.ts +9 -0
- package/build/errors/bad-request-error.js +16 -0
- package/build/errors/custom-error.d.ts +8 -0
- package/build/errors/custom-error.js +10 -0
- package/build/errors/database-connection-error.d.ts +9 -0
- package/build/errors/database-connection-error.js +16 -0
- package/build/errors/not-authorized-error.d.ts +8 -0
- package/build/errors/not-authorized-error.js +15 -0
- package/build/errors/not-found-error.d.ts +8 -0
- package/build/errors/not-found-error.js +15 -0
- package/build/errors/request-validation-error.d.ts +14 -0
- package/build/errors/request-validation-error.js +22 -0
- package/build/events/base-listener.d.ts +18 -0
- package/build/events/base-listener.js +32 -0
- package/build/events/base-publisher.d.ts +13 -0
- package/build/events/base-publisher.js +20 -0
- package/build/events/subjects.d.ts +9 -0
- package/build/events/subjects.js +13 -0
- package/build/events/types/order-status.d.ts +6 -0
- package/build/events/types/order-status.js +18 -0
- package/build/events/types/upload-status.d.ts +18 -0
- package/build/events/types/upload-status.js +22 -0
- package/build/events/upload-complete-event.d.ts +9 -0
- package/build/events/upload-complete-event.js +2 -0
- package/build/index.d.ts +24 -0
- package/build/index.js +48 -0
- package/build/middlewares/current-user.d.ts +16 -0
- package/build/middlewares/current-user.js +26 -0
- package/build/middlewares/error-handler.d.ts +2 -0
- package/build/middlewares/error-handler.js +14 -0
- package/build/middlewares/require-auth.d.ts +2 -0
- package/build/middlewares/require-auth.js +11 -0
- package/build/middlewares/validate-request.d.ts +2 -0
- package/build/middlewares/validate-request.js +13 -0
- package/build/models/Asset.d.ts +52 -0
- package/build/models/Asset.js +133 -0
- package/build/models/Project.d.ts +27 -0
- package/build/models/Project.js +106 -0
- package/build/models/ProjectAsset.d.ts +12 -0
- package/build/models/ProjectAsset.js +58 -0
- package/build/models/ProjectDependency.d.ts +11 -0
- package/build/models/ProjectDependency.js +57 -0
- package/build/models/Transaction.d.ts +22 -0
- package/build/models/Transaction.js +92 -0
- package/build/models/User.d.ts +17 -0
- package/build/models/User.js +79 -0
- package/build/models/UserAsset.d.ts +13 -0
- package/build/models/UserAsset.js +62 -0
- package/build/models/index.d.ts +15 -0
- package/build/models/index.js +54 -0
- package/build/utils/redis.d.ts +0 -0
- package/build/utils/redis.js +1 -0
- package/build/utils/redisClient.d.ts +4 -0
- package/build/utils/redisClient.js +22 -0
- package/build/utils/storage.d.ts +16 -0
- package/build/utils/storage.js +102 -0
- package/build/utils/types.d.ts +10 -0
- package/build/utils/types.js +2 -0
- package/package.json +45 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const sequelize_typescript_1 = require("sequelize-typescript");
|
|
4
|
+
const User_1 = require("./models/User");
|
|
5
|
+
const Project_1 = require("./models/Project");
|
|
6
|
+
const ProjectDependency_1 = require("./models/ProjectDependency");
|
|
7
|
+
const Transaction_1 = require("./models/Transaction");
|
|
8
|
+
const Asset_1 = require("./models/Asset");
|
|
9
|
+
const UserAsset_1 = require("./models/UserAsset");
|
|
10
|
+
const ProjectAsset_1 = require("./models/ProjectAsset");
|
|
11
|
+
const sequelize = new sequelize_typescript_1.Sequelize({
|
|
12
|
+
database: process.env.RISE_MYSQL_DATABASE,
|
|
13
|
+
dialect: 'mysql',
|
|
14
|
+
host: process.env.MYSQL_HOST,
|
|
15
|
+
username: process.env.RISE_MYSQL_USER,
|
|
16
|
+
password: process.env.RISE_MYSQL_PASSWORD,
|
|
17
|
+
port: parseInt(process.env.MYSQL_PORT || '3306'),
|
|
18
|
+
models: [User_1.User, Project_1.Project, ProjectDependency_1.ProjectDependency, Transaction_1.Transaction, Asset_1.Asset, UserAsset_1.UserAsset, ProjectAsset_1.ProjectAsset],
|
|
19
|
+
logging: console.log, // Set to false in production
|
|
20
|
+
pool: {
|
|
21
|
+
max: 10,
|
|
22
|
+
min: 0,
|
|
23
|
+
acquire: 30000,
|
|
24
|
+
idle: 10000,
|
|
25
|
+
},
|
|
26
|
+
dialectOptions: {
|
|
27
|
+
connectTimeout: 60000
|
|
28
|
+
},
|
|
29
|
+
retry: {
|
|
30
|
+
max: 3
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
exports.default = sequelize;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BadRequestError = void 0;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
class BadRequestError extends custom_error_1.CustomError {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.message = message;
|
|
9
|
+
this.statusCode = 400;
|
|
10
|
+
Object.setPrototypeOf(this, BadRequestError.prototype);
|
|
11
|
+
}
|
|
12
|
+
serializeErrors() {
|
|
13
|
+
return [{ message: this.message }];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.BadRequestError = BadRequestError;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomError = void 0;
|
|
4
|
+
class CustomError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
Object.setPrototypeOf(this, CustomError.prototype);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.CustomError = CustomError;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseConnectionError = void 0;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
class DatabaseConnectionError extends custom_error_1.CustomError {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('Error connecting to db');
|
|
8
|
+
this.statusCode = 500;
|
|
9
|
+
this.reason = 'Error connecting to database';
|
|
10
|
+
Object.setPrototypeOf(this, DatabaseConnectionError.prototype);
|
|
11
|
+
}
|
|
12
|
+
serializeErrors() {
|
|
13
|
+
return [{ message: this.reason }];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.DatabaseConnectionError = DatabaseConnectionError;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotAuthorizedError = void 0;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
class NotAuthorizedError extends custom_error_1.CustomError {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('Not Authorized');
|
|
8
|
+
this.statusCode = 401;
|
|
9
|
+
Object.setPrototypeOf(this, NotAuthorizedError.prototype);
|
|
10
|
+
}
|
|
11
|
+
serializeErrors() {
|
|
12
|
+
return [{ message: 'Not authorized' }];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.NotAuthorizedError = NotAuthorizedError;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotFoundError = void 0;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
class NotFoundError extends custom_error_1.CustomError {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('Route not found');
|
|
8
|
+
this.statusCode = 404;
|
|
9
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
10
|
+
}
|
|
11
|
+
serializeErrors() {
|
|
12
|
+
return [{ message: 'Not Found' }];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.NotFoundError = NotFoundError;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ValidationError } from 'express-validator';
|
|
2
|
+
import { CustomError } from './custom-error';
|
|
3
|
+
export declare class RequestValidationError extends CustomError {
|
|
4
|
+
errors: ValidationError[];
|
|
5
|
+
statusCode: number;
|
|
6
|
+
constructor(errors: ValidationError[]);
|
|
7
|
+
serializeErrors(): ({
|
|
8
|
+
message: any;
|
|
9
|
+
field: string;
|
|
10
|
+
} | {
|
|
11
|
+
message: any;
|
|
12
|
+
field?: undefined;
|
|
13
|
+
})[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestValidationError = void 0;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
class RequestValidationError extends custom_error_1.CustomError {
|
|
6
|
+
constructor(errors) {
|
|
7
|
+
super('Invalid request parameters');
|
|
8
|
+
this.errors = errors;
|
|
9
|
+
this.statusCode = 400;
|
|
10
|
+
// Only because we are extending a built in class
|
|
11
|
+
Object.setPrototypeOf(this, RequestValidationError.prototype);
|
|
12
|
+
}
|
|
13
|
+
serializeErrors() {
|
|
14
|
+
return this.errors.map((err) => {
|
|
15
|
+
if (err.type === 'field') {
|
|
16
|
+
return { message: err.msg, field: err.path };
|
|
17
|
+
}
|
|
18
|
+
return { message: err.msg };
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.RequestValidationError = RequestValidationError;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Message, Stan } from 'node-nats-streaming';
|
|
2
|
+
import { Subjects } from './subjects';
|
|
3
|
+
interface Event {
|
|
4
|
+
subject: Subjects;
|
|
5
|
+
data: any;
|
|
6
|
+
}
|
|
7
|
+
export declare abstract class Listener<T extends Event> {
|
|
8
|
+
abstract subject: T['subject'];
|
|
9
|
+
abstract queueGroupName: string;
|
|
10
|
+
abstract onMessage(data: T['data'], msg: Message): void;
|
|
11
|
+
protected client: Stan;
|
|
12
|
+
protected ackWait: number;
|
|
13
|
+
constructor(client: Stan);
|
|
14
|
+
subscriptionOptions(): import("node-nats-streaming").SubscriptionOptions;
|
|
15
|
+
listen(): void;
|
|
16
|
+
parseMessage(msg: Message): any;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Listener = void 0;
|
|
4
|
+
class Listener {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.ackWait = 5 * 1000;
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
subscriptionOptions() {
|
|
10
|
+
return this.client
|
|
11
|
+
.subscriptionOptions()
|
|
12
|
+
.setDeliverAllAvailable()
|
|
13
|
+
.setManualAckMode(true)
|
|
14
|
+
.setAckWait(this.ackWait)
|
|
15
|
+
.setDurableName(this.queueGroupName);
|
|
16
|
+
}
|
|
17
|
+
listen() {
|
|
18
|
+
const subscription = this.client.subscribe(this.subject, this.queueGroupName, this.subscriptionOptions());
|
|
19
|
+
subscription.on('message', (msg) => {
|
|
20
|
+
console.log(`Message received: ${this.subject} / ${this.queueGroupName}`);
|
|
21
|
+
const parsedData = this.parseMessage(msg);
|
|
22
|
+
this.onMessage(parsedData, msg);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
parseMessage(msg) {
|
|
26
|
+
const data = msg.getData();
|
|
27
|
+
return typeof data === 'string'
|
|
28
|
+
? JSON.parse(data)
|
|
29
|
+
: JSON.parse(data.toString('utf8'));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Listener = Listener;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Stan } from "node-nats-streaming";
|
|
2
|
+
import { Subjects } from "./subjects";
|
|
3
|
+
interface Event {
|
|
4
|
+
subject: Subjects;
|
|
5
|
+
data: any;
|
|
6
|
+
}
|
|
7
|
+
export declare abstract class Publisher<T extends Event> {
|
|
8
|
+
abstract subject: T['subject'];
|
|
9
|
+
private client;
|
|
10
|
+
constructor(client: Stan);
|
|
11
|
+
publish(data: T['data']): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Publisher = void 0;
|
|
4
|
+
class Publisher {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
publish(data) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
this.client.publish(this.subject, JSON.stringify(data), (err) => {
|
|
11
|
+
if (err) {
|
|
12
|
+
return reject(err);
|
|
13
|
+
}
|
|
14
|
+
console.log('Event published to subject', this.subject);
|
|
15
|
+
resolve();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.Publisher = Publisher;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare enum Subjects {
|
|
2
|
+
UploadComplete = "upload:complete",
|
|
3
|
+
UploadFailed = "upload:failed",
|
|
4
|
+
UploadAborted = "upload:aborted",
|
|
5
|
+
UploadWaitingForNextChunk = "upload:waiting-for-next-chunk",
|
|
6
|
+
UploadUnzipping = "upload:unzipping",
|
|
7
|
+
UploadUploadingToCloud = "upload:uploading-to-cloud",
|
|
8
|
+
UploadUploadingToServer = "upload:uploading-to-server"
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Subjects = void 0;
|
|
4
|
+
var Subjects;
|
|
5
|
+
(function (Subjects) {
|
|
6
|
+
Subjects["UploadComplete"] = "upload:complete";
|
|
7
|
+
Subjects["UploadFailed"] = "upload:failed";
|
|
8
|
+
Subjects["UploadAborted"] = "upload:aborted";
|
|
9
|
+
Subjects["UploadWaitingForNextChunk"] = "upload:waiting-for-next-chunk";
|
|
10
|
+
Subjects["UploadUnzipping"] = "upload:unzipping";
|
|
11
|
+
Subjects["UploadUploadingToCloud"] = "upload:uploading-to-cloud";
|
|
12
|
+
Subjects["UploadUploadingToServer"] = "upload:uploading-to-server";
|
|
13
|
+
})(Subjects || (exports.Subjects = Subjects = {}));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OrderStatus = void 0;
|
|
4
|
+
var OrderStatus;
|
|
5
|
+
(function (OrderStatus) {
|
|
6
|
+
// When the order has been created, but the
|
|
7
|
+
// ticket it is trying to order has not been reserved
|
|
8
|
+
OrderStatus["Created"] = "created";
|
|
9
|
+
// The ticket the order is trying to reserve has already
|
|
10
|
+
// been reserved, or when the user has cancelled the order.
|
|
11
|
+
// The order expires before payment.
|
|
12
|
+
OrderStatus["Cancelled"] = "cancelled";
|
|
13
|
+
// The order has successfully reserved the ticket
|
|
14
|
+
OrderStatus["AwaitingPayment"] = "awaiting:payment";
|
|
15
|
+
// The order has reserved the ticket and the user has
|
|
16
|
+
// provided payment successfully
|
|
17
|
+
OrderStatus["Complete"] = "complete";
|
|
18
|
+
})(OrderStatus || (exports.OrderStatus = OrderStatus = {}));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare enum UploadStatus {
|
|
2
|
+
UploadingPdf = "Uploading pdf",
|
|
3
|
+
ConvertingToPdf = "Converting to pdf",
|
|
4
|
+
CreatingReport = "Creating report",
|
|
5
|
+
CreatingImagesWithAnnotations = "Creating images with annotations",
|
|
6
|
+
AbortedByUser = "Aborted by user",
|
|
7
|
+
Unzipping = "Unzipping",
|
|
8
|
+
Pending = "Pending",
|
|
9
|
+
UploadingToServer = "Uploading to server",
|
|
10
|
+
UploadingToCloud = "Uploading to cloud",
|
|
11
|
+
Failed = "Failed",
|
|
12
|
+
Complete = "Complete",
|
|
13
|
+
Merged = "Merged",
|
|
14
|
+
CreatingReportJsonFile = "Creating report JSON file",
|
|
15
|
+
CreatingZipFile = "Creating zip file",
|
|
16
|
+
DownloadingImages = "Downloading images",
|
|
17
|
+
Disconnected = "Disconnected"
|
|
18
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UploadStatus = void 0;
|
|
4
|
+
var UploadStatus;
|
|
5
|
+
(function (UploadStatus) {
|
|
6
|
+
UploadStatus["UploadingPdf"] = "Uploading pdf";
|
|
7
|
+
UploadStatus["ConvertingToPdf"] = "Converting to pdf";
|
|
8
|
+
UploadStatus["CreatingReport"] = "Creating report";
|
|
9
|
+
UploadStatus["CreatingImagesWithAnnotations"] = "Creating images with annotations";
|
|
10
|
+
UploadStatus["AbortedByUser"] = "Aborted by user";
|
|
11
|
+
UploadStatus["Unzipping"] = "Unzipping";
|
|
12
|
+
UploadStatus["Pending"] = "Pending";
|
|
13
|
+
UploadStatus["UploadingToServer"] = "Uploading to server";
|
|
14
|
+
UploadStatus["UploadingToCloud"] = "Uploading to cloud";
|
|
15
|
+
UploadStatus["Failed"] = "Failed";
|
|
16
|
+
UploadStatus["Complete"] = "Complete";
|
|
17
|
+
UploadStatus["Merged"] = "Merged";
|
|
18
|
+
UploadStatus["CreatingReportJsonFile"] = "Creating report JSON file";
|
|
19
|
+
UploadStatus["CreatingZipFile"] = "Creating zip file";
|
|
20
|
+
UploadStatus["DownloadingImages"] = "Downloading images";
|
|
21
|
+
UploadStatus["Disconnected"] = "Disconnected";
|
|
22
|
+
})(UploadStatus || (exports.UploadStatus = UploadStatus = {}));
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { default as express } from 'express';
|
|
2
|
+
export type { Request, Response, NextFunction, Application, Router } from 'express';
|
|
3
|
+
export * from 'express-validator';
|
|
4
|
+
export { default as jwt } from 'jsonwebtoken';
|
|
5
|
+
export type { JwtPayload, SignOptions, VerifyOptions } from 'jsonwebtoken';
|
|
6
|
+
export { default as session } from 'cookie-session';
|
|
7
|
+
export { default as sequelize } from './database';
|
|
8
|
+
export type { RedisType } from './utils/redisClient';
|
|
9
|
+
export * from './errors/bad-request-error';
|
|
10
|
+
export * from './errors/custom-error';
|
|
11
|
+
export * from './errors/database-connection-error';
|
|
12
|
+
export * from './errors/not-authorized-error';
|
|
13
|
+
export * from './errors/not-found-error';
|
|
14
|
+
export * from './errors/request-validation-error';
|
|
15
|
+
export * from './middlewares/current-user';
|
|
16
|
+
export * from './middlewares/error-handler';
|
|
17
|
+
export * from './middlewares/require-auth';
|
|
18
|
+
export * from './middlewares/validate-request';
|
|
19
|
+
export * from './events/base-listener';
|
|
20
|
+
export * from './events/base-publisher';
|
|
21
|
+
export * from './events/subjects';
|
|
22
|
+
export * from './events/types/order-status';
|
|
23
|
+
export * from './events/types/upload-status';
|
|
24
|
+
export * from './utils/types';
|
package/build/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.sequelize = exports.session = exports.jwt = exports.express = void 0;
|
|
21
|
+
// Re-export shared libraries and their types
|
|
22
|
+
var express_1 = require("express");
|
|
23
|
+
Object.defineProperty(exports, "express", { enumerable: true, get: function () { return __importDefault(express_1).default; } });
|
|
24
|
+
__exportStar(require("express-validator"), exports);
|
|
25
|
+
var jsonwebtoken_1 = require("jsonwebtoken");
|
|
26
|
+
Object.defineProperty(exports, "jwt", { enumerable: true, get: function () { return __importDefault(jsonwebtoken_1).default; } });
|
|
27
|
+
var cookie_session_1 = require("cookie-session");
|
|
28
|
+
Object.defineProperty(exports, "session", { enumerable: true, get: function () { return __importDefault(cookie_session_1).default; } });
|
|
29
|
+
// export { default as getRedisClient } from './utils/redisClient';
|
|
30
|
+
var database_1 = require("./database");
|
|
31
|
+
Object.defineProperty(exports, "sequelize", { enumerable: true, get: function () { return __importDefault(database_1).default; } });
|
|
32
|
+
__exportStar(require("./errors/bad-request-error"), exports);
|
|
33
|
+
__exportStar(require("./errors/custom-error"), exports);
|
|
34
|
+
__exportStar(require("./errors/database-connection-error"), exports);
|
|
35
|
+
__exportStar(require("./errors/not-authorized-error"), exports);
|
|
36
|
+
__exportStar(require("./errors/not-found-error"), exports);
|
|
37
|
+
__exportStar(require("./errors/request-validation-error"), exports);
|
|
38
|
+
__exportStar(require("./middlewares/current-user"), exports);
|
|
39
|
+
__exportStar(require("./middlewares/error-handler"), exports);
|
|
40
|
+
__exportStar(require("./middlewares/require-auth"), exports);
|
|
41
|
+
__exportStar(require("./middlewares/validate-request"), exports);
|
|
42
|
+
__exportStar(require("./events/base-listener"), exports);
|
|
43
|
+
__exportStar(require("./events/base-publisher"), exports);
|
|
44
|
+
__exportStar(require("./events/subjects"), exports);
|
|
45
|
+
__exportStar(require("./events/types/order-status"), exports);
|
|
46
|
+
__exportStar(require("./events/types/upload-status"), exports);
|
|
47
|
+
__exportStar(require("./utils/types"), exports);
|
|
48
|
+
// export { default as allJson } from './data/all.json';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
interface UserPayload {
|
|
3
|
+
id: string;
|
|
4
|
+
email: string;
|
|
5
|
+
exp: number;
|
|
6
|
+
roleId?: string;
|
|
7
|
+
}
|
|
8
|
+
declare global {
|
|
9
|
+
namespace Express {
|
|
10
|
+
interface Request {
|
|
11
|
+
currentUser?: UserPayload;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export declare const currentUser: (req: Request, res: Response, next: NextFunction) => void | Response<any, Record<string, any>>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
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.currentUser = void 0;
|
|
7
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
+
const currentUser = (req, res, next) => {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
console.log("currentUser middleware", (_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt);
|
|
11
|
+
if (!((_b = req.session) === null || _b === void 0 ? void 0 : _b.jwt)) {
|
|
12
|
+
return next();
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const payload = jsonwebtoken_1.default.verify(req.session.jwt, process.env.JWT_KEY);
|
|
16
|
+
console.log("currentUser middleware", payload);
|
|
17
|
+
const currentTime = Math.floor(Date.now() / 1000);
|
|
18
|
+
if (payload.exp < currentTime) {
|
|
19
|
+
return res.status(401).json({ error: 'Token has expired' });
|
|
20
|
+
}
|
|
21
|
+
req.currentUser = payload;
|
|
22
|
+
}
|
|
23
|
+
catch (err) { }
|
|
24
|
+
next();
|
|
25
|
+
};
|
|
26
|
+
exports.currentUser = currentUser;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errorHandler = void 0;
|
|
4
|
+
const custom_error_1 = require("../errors/custom-error");
|
|
5
|
+
const errorHandler = (err, req, res, next) => {
|
|
6
|
+
if (err instanceof custom_error_1.CustomError) {
|
|
7
|
+
return res.status(err.statusCode).send({ errors: err.serializeErrors() });
|
|
8
|
+
}
|
|
9
|
+
console.error(err);
|
|
10
|
+
res.status(400).send({
|
|
11
|
+
errors: [{ message: 'Something went wrong' }]
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
exports.errorHandler = errorHandler;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requireAuth = void 0;
|
|
4
|
+
const not_authorized_error_1 = require("../errors/not-authorized-error");
|
|
5
|
+
const requireAuth = (req, res, next) => {
|
|
6
|
+
if (!req.currentUser) {
|
|
7
|
+
throw new not_authorized_error_1.NotAuthorizedError();
|
|
8
|
+
}
|
|
9
|
+
next();
|
|
10
|
+
};
|
|
11
|
+
exports.requireAuth = requireAuth;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateRequest = void 0;
|
|
4
|
+
const express_validator_1 = require("express-validator");
|
|
5
|
+
const request_validation_error_1 = require("../errors/request-validation-error");
|
|
6
|
+
const validateRequest = (req, res, next) => {
|
|
7
|
+
const errors = (0, express_validator_1.validationResult)(req);
|
|
8
|
+
if (!errors.isEmpty()) {
|
|
9
|
+
throw new request_validation_error_1.RequestValidationError(errors.array());
|
|
10
|
+
}
|
|
11
|
+
next();
|
|
12
|
+
};
|
|
13
|
+
exports.validateRequest = validateRequest;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Model } from 'sequelize-typescript';
|
|
2
|
+
import { User } from './User';
|
|
3
|
+
import { Project } from './Project';
|
|
4
|
+
export declare enum AssetType {
|
|
5
|
+
MODEL = "model",
|
|
6
|
+
TEXTURE = "texture",
|
|
7
|
+
AUDIO = "audio",
|
|
8
|
+
MATERIAL = "material",
|
|
9
|
+
IMAGE = "image",
|
|
10
|
+
UI_TEMPLATE = "ui_template",
|
|
11
|
+
GALLERY = "gallery",
|
|
12
|
+
HDR = "hdr",
|
|
13
|
+
ANIMATION = "animation"
|
|
14
|
+
}
|
|
15
|
+
export type AssetPayload = {
|
|
16
|
+
creatorId: string;
|
|
17
|
+
projectId?: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
type?: AssetType;
|
|
20
|
+
description?: string;
|
|
21
|
+
path?: string;
|
|
22
|
+
price?: number;
|
|
23
|
+
privacy?: AssetPrivacy;
|
|
24
|
+
vertex?: string;
|
|
25
|
+
fragment?: string;
|
|
26
|
+
uniforms?: object;
|
|
27
|
+
url?: string;
|
|
28
|
+
settings?: object[];
|
|
29
|
+
};
|
|
30
|
+
export declare enum AssetPrivacy {
|
|
31
|
+
PUBLIC = "public",
|
|
32
|
+
PRIVATE = "private"
|
|
33
|
+
}
|
|
34
|
+
export declare class Asset extends Model {
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
type: AssetType;
|
|
38
|
+
url: string;
|
|
39
|
+
creatorId: string;
|
|
40
|
+
price?: number;
|
|
41
|
+
privacy: AssetPrivacy;
|
|
42
|
+
description?: string;
|
|
43
|
+
vertex?: string;
|
|
44
|
+
fragment?: string;
|
|
45
|
+
uniforms?: object;
|
|
46
|
+
settings?: object[];
|
|
47
|
+
createdAt: Date;
|
|
48
|
+
updatedAt: Date;
|
|
49
|
+
creator: User;
|
|
50
|
+
owners: User[];
|
|
51
|
+
projects: Project[];
|
|
52
|
+
}
|