@devshopapp/common 1.0.13 → 1.0.15
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/src/constants/seller/product.interfaces.d.ts +14 -0
- package/build/src/constants/seller/product.interfaces.d.ts.map +1 -0
- package/build/src/constants/seller/product.interfaces.js +2 -0
- package/build/src/constants/seller/product.interfaces.js.map +1 -0
- package/build/src/index.d.ts +2 -0
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +2 -0
- package/build/src/index.js.map +1 -1
- package/build/src/middlewares/current.user.d.ts +1 -0
- package/build/src/middlewares/current.user.d.ts.map +1 -1
- package/build/src/middlewares/current.user.js.map +1 -1
- package/build/src/middlewares/uploader.d.ts +16 -0
- package/build/src/middlewares/uploader.d.ts.map +1 -0
- package/build/src/middlewares/uploader.js +42 -0
- package/build/src/middlewares/uploader.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
import type { UserI } from "../auth/user.interfaces.js";
|
|
3
|
+
export interface ProductI {
|
|
4
|
+
user: UserI;
|
|
5
|
+
name: string;
|
|
6
|
+
price: number;
|
|
7
|
+
description?: string;
|
|
8
|
+
images: {
|
|
9
|
+
src: string;
|
|
10
|
+
}[];
|
|
11
|
+
}
|
|
12
|
+
export interface ProductModelI extends mongoose.Model<ProductI> {
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=product.interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product.interfaces.d.ts","sourceRoot":"","sources":["../../../../src/constants/seller/product.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAExD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,aAAc,SAAQ,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product.interfaces.js","sourceRoot":"","sources":["../../../../src/constants/seller/product.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC"}
|
package/build/src/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './middlewares/current.user.js';
|
|
|
2
2
|
export * from './middlewares/require.auth.js';
|
|
3
3
|
export * from './middlewares/error.handler.js';
|
|
4
4
|
export * from './middlewares/validation.request.middleware.js';
|
|
5
|
+
export * from './middlewares/uploader.js';
|
|
5
6
|
export * from './errors/bad.request.error.js';
|
|
6
7
|
export * from './errors/database.connection.error.js';
|
|
7
8
|
export * from './errors/not.authorized.error.js';
|
|
@@ -9,6 +10,7 @@ export * from './errors/not.found.error.js';
|
|
|
9
10
|
export * from './errors/custom.errors.js';
|
|
10
11
|
export * from './errors/request.validation.error.js';
|
|
11
12
|
export * from './constants/auth/user.interfaces.js';
|
|
13
|
+
export * from './constants/seller/product.interfaces.js';
|
|
12
14
|
export * from './constants/global.js';
|
|
13
15
|
export * from './services/authentication.service.js';
|
|
14
16
|
//# sourceMappingURL=index.d.ts.map
|
package/build/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gDAAgD,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gDAAgD,CAAC;AAC/D,cAAc,2BAA2B,CAAC;AAE1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uCAAuC,CAAC;AACtD,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sCAAsC,CAAC;AAErD,cAAc,qCAAqC,CAAC;AACpD,cAAc,0CAA0C,CAAC;AACzD,cAAc,uBAAuB,CAAC;AAEtC,cAAc,sCAAsC,CAAC"}
|
package/build/src/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from './middlewares/current.user.js';
|
|
|
2
2
|
export * from './middlewares/require.auth.js';
|
|
3
3
|
export * from './middlewares/error.handler.js';
|
|
4
4
|
export * from './middlewares/validation.request.middleware.js';
|
|
5
|
+
export * from './middlewares/uploader.js';
|
|
5
6
|
export * from './errors/bad.request.error.js';
|
|
6
7
|
export * from './errors/database.connection.error.js';
|
|
7
8
|
export * from './errors/not.authorized.error.js';
|
|
@@ -9,6 +10,7 @@ export * from './errors/not.found.error.js';
|
|
|
9
10
|
export * from './errors/custom.errors.js';
|
|
10
11
|
export * from './errors/request.validation.error.js';
|
|
11
12
|
export * from './constants/auth/user.interfaces.js';
|
|
13
|
+
export * from './constants/seller/product.interfaces.js';
|
|
12
14
|
export * from './constants/global.js';
|
|
13
15
|
export * from './services/authentication.service.js';
|
|
14
16
|
//# sourceMappingURL=index.js.map
|
package/build/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gDAAgD,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gDAAgD,CAAC;AAC/D,cAAc,2BAA2B,CAAC;AAE1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uCAAuC,CAAC;AACtD,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sCAAsC,CAAC;AAErD,cAAc,qCAAqC,CAAC;AACpD,cAAc,0CAA0C,CAAC;AACzD,cAAc,uBAAuB,CAAC;AAEtC,cAAc,sCAAsC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"current.user.d.ts","sourceRoot":"","sources":["../../../src/middlewares/current.user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,OAAO,CAAC;QACd,UAAU,OAAO;YACb,OAAO,CAAC,EAAE,GAAG,CAAC;YACd,WAAW,CAAC,EAAE,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"current.user.d.ts","sourceRoot":"","sources":["../../../src/middlewares/current.user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,OAAO,CAAC;QACd,UAAU,OAAO;YACb,OAAO,CAAC,EAAE,GAAG,CAAC;YACd,WAAW,CAAC,EAAE,UAAU,CAAC;YACzB,aAAa,CAAC,EAAE,KAAK,CAAC;SAEzB;KACJ;CACJ;AAED,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,MAC9B,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,SAgB1D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"current.user.js","sourceRoot":"","sources":["../../../src/middlewares/current.user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkD,MAAM,SAAS,CAAC;AACzE,OAAO,GAAG,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"current.user.js","sourceRoot":"","sources":["../../../src/middlewares/current.user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkD,MAAM,SAAS,CAAC;AACzE,OAAO,GAAG,MAAM,cAAc,CAAC;AAc/B,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,EAAE;IAC1C,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QACvD,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC;QAE/B,IAAI,CAAC,KAAK,EAAE,CAAC;YACT,OAAO,IAAI,EAAE,CAAC;QAClB,CAAC;QAED,IAAI,CAAC;YACD,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAe,CAAC;YACxD,GAAG,CAAC,WAAW,GAAG,OAAO,CAAC;QAC9B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,OAAO,IAAI,EAAE,CAAC;QAClB,CAAC;QAED,IAAI,EAAE,CAAC;IACX,CAAC,CAAC;AACN,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Request } from "express";
|
|
2
|
+
import multer, { type FileFilterCallback } from "multer";
|
|
3
|
+
export interface UploaderMiddlewareOptionsI {
|
|
4
|
+
fieldName?: string;
|
|
5
|
+
types?: Array<string>;
|
|
6
|
+
}
|
|
7
|
+
export declare class Uploader {
|
|
8
|
+
uploadDirectory?: string | undefined;
|
|
9
|
+
defaultUploadDirectory: string;
|
|
10
|
+
constructor(uploadDirectory?: string | undefined);
|
|
11
|
+
fileFilter: (types?: Array<string>) => (req: Request, file: Express.Multer.File, cb: FileFilterCallback) => void;
|
|
12
|
+
storage: multer.StorageEngine;
|
|
13
|
+
uploadMultipleFiles(options?: UploaderMiddlewareOptionsI): import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
14
|
+
uploadSingleFile(options?: UploaderMiddlewareOptionsI): import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=uploader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploader.d.ts","sourceRoot":"","sources":["../../../src/middlewares/uploader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,MAAM,EAAE,EAAE,KAAK,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAEzD,MAAM,WAAW,0BAA0B;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACzB;AAED,qBAAa,QAAQ;IAGE,eAAe,CAAC,EAAE,MAAM;IAFpC,sBAAsB,SAAc;gBAExB,eAAe,CAAC,EAAE,MAAM,YAAA;IAEpC,UAAU,GAAI,QAAQ,KAAK,CAAC,MAAM,CAAC,MAC9B,KAAK,OAAO,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,kBAAkB,UAa1E;IAEM,OAAO,uBAQZ;IAEF,mBAAmB,CAAC,OAAO,CAAC,EAAE,0BAA0B;IAKxD,gBAAgB,CAAC,OAAO,CAAC,EAAE,0BAA0B;CAIxD"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import multer, {} from "multer";
|
|
2
|
+
export class Uploader {
|
|
3
|
+
uploadDirectory;
|
|
4
|
+
defaultUploadDirectory = '/uploads';
|
|
5
|
+
constructor(uploadDirectory) {
|
|
6
|
+
this.uploadDirectory = uploadDirectory;
|
|
7
|
+
}
|
|
8
|
+
fileFilter = (types) => {
|
|
9
|
+
return (req, file, cb) => {
|
|
10
|
+
const type = file.mimetype;
|
|
11
|
+
if (!types)
|
|
12
|
+
return cb(null, true);
|
|
13
|
+
if (types.length <= 0)
|
|
14
|
+
return cb(null, true);
|
|
15
|
+
if (types.some((accepted) => accepted === type)) {
|
|
16
|
+
cb(null, true);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
req.uploaderError = new Error(`we only accept the following types: ${types.join(', ')}`);
|
|
20
|
+
cb(null, false);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
storage = multer.diskStorage({
|
|
25
|
+
destination: (req, file, cb) => {
|
|
26
|
+
cb(null, this.uploadDirectory || this.defaultUploadDirectory);
|
|
27
|
+
},
|
|
28
|
+
filename: (req, file, cb) => {
|
|
29
|
+
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9);
|
|
30
|
+
cb(null, `${file.fieldname}${uniqueSuffix}`);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
uploadMultipleFiles(options) {
|
|
34
|
+
return multer({ storage: this.storage, fileFilter: this.fileFilter(options?.types) })
|
|
35
|
+
.array(options?.fieldName || 'file');
|
|
36
|
+
}
|
|
37
|
+
uploadSingleFile(options) {
|
|
38
|
+
return multer({ storage: this.storage, fileFilter: this.fileFilter(options?.types) })
|
|
39
|
+
.single(options?.fieldName || 'file');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=uploader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploader.js","sour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