biz-email-builder-shared 1.6.1 → 1.6.2

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.
@@ -1,8 +1,8 @@
1
1
  import { Response, NextFunction } from "express";
2
2
  import { FEATURE_TYPE, ROLES } from "../utilities";
3
3
  import { IRequest } from "../types";
4
- declare const authorize: () => (req: IRequest, res: Response, next: NextFunction) => Promise<Response<any, Record<string, any>> | undefined>;
5
- declare const checkRoleAccess: (roles: ROLES[]) => (req: IRequest, res: Response, next: NextFunction) => Promise<Response<any, Record<string, any>> | undefined>;
6
- declare const checkFeatureAccess: (features: FEATURE_TYPE[]) => (req: IRequest, res: Response, next: NextFunction) => Promise<Response<any, Record<string, any>> | undefined>;
4
+ declare const authorize: () => (req: IRequest, res: Response, next: NextFunction) => Promise<void>;
5
+ declare const checkRoleAccess: (roles: ROLES[]) => (req: IRequest, res: Response, next: NextFunction) => Promise<void>;
6
+ declare const checkFeatureAccess: (features: FEATURE_TYPE[]) => (req: IRequest, res: Response, next: NextFunction) => Promise<void>;
7
7
  export { authorize, checkFeatureAccess, checkRoleAccess };
8
8
  //# sourceMappingURL=authentication.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../../src/middleware/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,KAAK,EAA8B,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAIpC,QAAA,MAAM,SAAS,cACe,QAAQ,OAAO,QAAQ,QAAQ,YAAY,4DAwCxE,CAAA;AAED,QAAA,MAAM,eAAe,UAAW,KAAK,EAAE,WACT,QAAQ,OAAO,QAAQ,QAAQ,YAAY,4DAcxE,CAAA;AAED,QAAA,MAAM,kBAAkB,aAAc,YAAY,EAAE,WACtB,QAAQ,OAAO,QAAQ,QAAQ,YAAY,4DAmBxE,CAAA;AAGD,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../../src/middleware/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,KAAK,EAA8B,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAIpC,QAAA,MAAM,SAAS,cACe,QAAQ,OAAO,QAAQ,QAAQ,YAAY,kBA0CxE,CAAC;AAEF,QAAA,MAAM,eAAe,UAAW,KAAK,EAAE,WACT,QAAQ,OAAO,QAAQ,QAAQ,YAAY,kBAaxE,CAAC;AAEF,QAAA,MAAM,kBAAkB,aAAc,YAAY,EAAE,WACtB,QAAQ,OAAO,QAAQ,QAAQ,YAAY,kBAgBxE,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,eAAe,EAAE,CAAC"}
@@ -14,32 +14,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.checkRoleAccess = exports.checkFeatureAccess = exports.authorize = void 0;
15
15
  const utilities_1 = require("../utilities");
16
16
  const entity_1 = require("../entity");
17
+ const resHandler_1 = require("../resHandler");
17
18
  const authorize = () => {
18
19
  return async function (req, res, next) {
19
20
  try {
20
21
  if (!req.headers.authorization) {
21
- return res.status(401).json({ message: utilities_1.SERVER_MESSAGES.SE_UNAUTHORIZED });
22
+ throw new resHandler_1.UnauthorizedRequestError(utilities_1.SERVER_MESSAGES.SE_UNAUTHORIZED);
22
23
  }
23
24
  if (req.headers.authorization) {
24
25
  const token = await (0, utilities_1.verifyUid)(req.headers.authorization);
25
26
  if (!token) {
26
- return res.status(401).json({ message: utilities_1.SERVER_MESSAGES.SE_SESSION_EXPIRED });
27
+ throw new resHandler_1.UnauthorizedRequestError(utilities_1.SERVER_MESSAGES.SE_SESSION_EXPIRED);
27
28
  }
28
- let user = await entity_1.UserModel.findById(token.value.id).populate({
29
+ let user = await entity_1.UserModel.findById(token.value.id)
30
+ .populate({
29
31
  path: "groups",
30
32
  populate: { path: "features", select: "name" },
31
- }).lean();
33
+ })
34
+ .lean();
32
35
  if (!user) {
33
- return res.status(401).json({ message: utilities_1.SERVER_MESSAGES.SE_USER_NOT_FOUND });
36
+ throw new resHandler_1.UnauthorizedRequestError(utilities_1.SERVER_MESSAGES.SE_USER_NOT_FOUND);
34
37
  }
35
38
  if (user.role === undefined || user.role === null || !Object.values(utilities_1.ROLES).includes(user.role)) {
36
- return res.status(401).json({ message: utilities_1.SERVER_MESSAGES.SE_NO_ROLE_ASSIGNED_ROLE_INVALID });
39
+ throw new resHandler_1.UnauthorizedRequestError(utilities_1.SERVER_MESSAGES.SE_NO_ROLE_ASSIGNED_ROLE_INVALID);
37
40
  }
38
41
  const { createdAt, updatedAt, deletedAt, password } = user, rest = __rest(user, ["createdAt", "updatedAt", "deletedAt", "password"]);
39
42
  req.user = rest;
40
43
  if (req.user && user.role === utilities_1.ROLES.ADMIN) {
41
44
  req.user.isAdmin = true;
42
- req.user.groups.push({ name: "DEFAULT", features: Object.values(utilities_1.FEATURE_TYPE).map(value => ({ name: value })) });
45
+ req.user.groups.push({ name: "DEFAULT", features: Object.values(utilities_1.FEATURE_TYPE).map((value) => ({ name: value })) });
43
46
  }
44
47
  next();
45
48
  }
@@ -54,11 +57,11 @@ const checkRoleAccess = (roles) => {
54
57
  return async function (req, res, next) {
55
58
  const { user } = req;
56
59
  if (!user) {
57
- return res.status(401).json({ message: utilities_1.SERVER_MESSAGES.SE_UNAUTHORIZED });
60
+ throw new resHandler_1.UnauthorizedRequestError(utilities_1.SERVER_MESSAGES.SE_UNAUTHORIZED);
58
61
  }
59
- const hasAccess = roles.find(role => role === user.role);
62
+ const hasAccess = roles.find((role) => role === user.role);
60
63
  if (!hasAccess) {
61
- return res.status(403).json({ message: utilities_1.SERVER_MESSAGES.SE_FORBIDDEN_ROLE_ACCESS_DENIED });
64
+ throw new resHandler_1.UnauthorizedRequestError(utilities_1.SERVER_MESSAGES.SE_FORBIDDEN_ROLE_ACCESS_DENIED);
62
65
  }
63
66
  next();
64
67
  };
@@ -68,12 +71,12 @@ const checkFeatureAccess = (features) => {
68
71
  return async function (req, res, next) {
69
72
  const { user } = req;
70
73
  if (!user) {
71
- return res.status(401).json({ message: utilities_1.SERVER_MESSAGES.SE_UNAUTHORIZED });
74
+ throw new resHandler_1.UnauthorizedRequestError(utilities_1.SERVER_MESSAGES.SE_UNAUTHORIZED);
72
75
  }
73
- const userFeatureNames = user.groups.flatMap(group => group.features ? group.features.map((feature) => feature.name) : []);
76
+ const userFeatureNames = user.groups.flatMap((group) => (group.features ? group.features.map((feature) => feature.name) : []));
74
77
  const hasAccess = features.some((feature) => userFeatureNames.includes(feature));
75
78
  if (!hasAccess) {
76
- return res.status(403).json({ message: utilities_1.SERVER_MESSAGES.SE_FORBIDDEN_FEATURE_ACCESS_DENIED });
79
+ throw new resHandler_1.ForbiddenRequestError(utilities_1.SERVER_MESSAGES.SE_FORBIDDEN_FEATURE_ACCESS_DENIED);
77
80
  }
78
81
  next();
79
82
  };
@@ -1,5 +1,5 @@
1
1
  import { NextFunction, Response } from "express";
2
- import Joi from 'joi';
2
+ import Joi from "joi";
3
3
  import { IRequest } from "../types";
4
- export declare const validateSchema: (schema: Joi.ObjectSchema<any>) => (req: IRequest, res: Response, next: NextFunction) => Promise<Response<any, Record<string, any>> | undefined>;
4
+ export declare const validateSchema: (schema: Joi.ObjectSchema<any>) => (req: IRequest, res: Response, next: NextFunction) => Promise<void>;
5
5
  //# sourceMappingURL=schemaValidate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemaValidate.d.ts","sourceRoot":"","sources":["../../src/middleware/schemaValidate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGpC,eAAO,MAAM,cAAc,WAAY,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAC9B,QAAQ,OAAO,QAAQ,QAAQ,YAAY,4DAWxE,CAAA"}
1
+ {"version":3,"file":"schemaValidate.d.ts","sourceRoot":"","sources":["../../src/middleware/schemaValidate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAIpC,eAAO,MAAM,cAAc,WAAY,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAC9B,QAAQ,OAAO,QAAQ,QAAQ,YAAY,kBAUxE,CAAC"}
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateSchema = void 0;
4
4
  const utilities_1 = require("../utilities");
5
+ const resHandler_1 = require("../resHandler");
5
6
  const validateSchema = (schema) => {
6
7
  return async function (req, res, next) {
7
8
  const { error } = schema.validate(req.body, { abortEarly: false });
8
9
  if (error) {
9
- const errorMessage = error.details.map((err) => err.message).join(', ');
10
- return res.status(400).json({ message: utilities_1.SERVER_MESSAGES.SE_INVALID_INPUT, description: errorMessage });
10
+ const errorMessage = error.details.map((err) => err.message).join(", ");
11
+ throw new resHandler_1.BadRequestError(`{ message: ${utilities_1.SERVER_MESSAGES.SE_INVALID_INPUT}, description: ${errorMessage}`);
11
12
  }
12
13
  else {
13
14
  next();
@@ -35,6 +35,7 @@ export declare enum FEATURE_TYPE {
35
35
  DELETE_TEMPLATE = "DELETE_TEMPLATE",
36
36
  SHARE_TEMPLATE = "SHARE_TEMPLATE",
37
37
  UPDATE_TEAMPLATE = "UPDATE_TEAMPLATE",
38
- LIST_TEMPLATE = "LIST_TEMPLATE"
38
+ LIST_TEMPLATE = "LIST_TEMPLATE",
39
+ SEND_EMAIL = "SEND_EMAIL"
39
40
  }
40
41
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AAEjC,oBAAY,KAAK;IACf,KAAK,UAAU;IACf,IAAI,SAAS;CACd;AAED,oBAAY,WAAW;IACrB,GAAG,QAAQ;IACX,OAAO,YAAY;IACnB,WAAW,gBAAgB;CAC5B;AAED,oBAAY,cAAc;IACxB,KAAK,UAAU;IACf,QAAQ,aAAa;IACrB,MAAM,WAAW;IACjB,MAAM,WAAW;CAClB;AAED,oBAAY,YAAY;IAEtB,QAAQ,aAAW;IACnB,WAAW,gBAAc;IACzB,WAAW,gBAAc;IACzB,SAAS,cAAY;IAGrB,cAAc,mBAAiB;IAC/B,iBAAiB,sBAAoB;IACrC,iBAAiB,sBAAoB;IACrC,eAAe,oBAAkB;IACjC,cAAc,mBAAiB;IAG/B,0BAA0B,+BAA6B;IACvD,cAAc,mBAAiB;IAC/B,eAAe,oBAAkB;IACjC,YAAY,iBAAe;IAC3B,eAAe,oBAAkB;IACjC,cAAc,mBAAiB;IAC/B,gBAAgB,qBAAmB;IACnC,aAAa,kBAAgB;CAC9B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AAEjC,oBAAY,KAAK;IACf,KAAK,UAAU;IACf,IAAI,SAAS;CACd;AAED,oBAAY,WAAW;IACrB,GAAG,QAAQ;IACX,OAAO,YAAY;IACnB,WAAW,gBAAgB;CAC5B;AAED,oBAAY,cAAc;IACxB,KAAK,UAAU;IACf,QAAQ,aAAa;IACrB,MAAM,WAAW;IACjB,MAAM,WAAW;CAClB;AAED,oBAAY,YAAY;IAEtB,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,WAAW,gBAAgB;IAC3B,SAAS,cAAc;IAGvB,cAAc,mBAAmB;IACjC,iBAAiB,sBAAsB;IACvC,iBAAiB,sBAAsB;IACvC,eAAe,oBAAoB;IACnC,cAAc,mBAAmB;IAGjC,0BAA0B,+BAA+B;IACzD,cAAc,mBAAmB;IACjC,eAAe,oBAAoB;IACnC,YAAY,iBAAiB;IAC7B,eAAe,oBAAoB;IACnC,cAAc,mBAAmB;IACjC,gBAAgB,qBAAqB;IACrC,aAAa,kBAAkB;IAC/B,UAAU,eAAe;CAC1B"}
@@ -60,4 +60,5 @@ var FEATURE_TYPE;
60
60
  FEATURE_TYPE["SHARE_TEMPLATE"] = "SHARE_TEMPLATE";
61
61
  FEATURE_TYPE["UPDATE_TEAMPLATE"] = "UPDATE_TEAMPLATE";
62
62
  FEATURE_TYPE["LIST_TEMPLATE"] = "LIST_TEMPLATE";
63
+ FEATURE_TYPE["SEND_EMAIL"] = "SEND_EMAIL";
63
64
  })(FEATURE_TYPE || (exports.FEATURE_TYPE = FEATURE_TYPE = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "biz-email-builder-shared",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -1,5 +0,0 @@
1
- import { IEmailTemplateLayout } from "../types";
2
- export declare const EmailTemplate: import("mongoose").Model<IEmailTemplateLayout, {}, {}, {}, import("mongoose").Document<unknown, {}, IEmailTemplateLayout> & Omit<IEmailTemplateLayout & {
3
- _id: import("mongoose").Types.ObjectId;
4
- }, never>, any>;
5
- //# sourceMappingURL=emailTemplate.entity.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"emailTemplate.entity.d.ts","sourceRoot":"","sources":["../../src/entity/emailTemplate.entity.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAwD3D,eAAO,MAAM,aAAa;;eAAqE,CAAC"}
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EmailTemplate = void 0;
4
- const mongoose_1 = require("mongoose");
5
- const types_1 = require("../types");
6
- const BlockDataPropsSchema = new mongoose_1.Schema({
7
- imageUrl: { type: String, default: "" },
8
- text: { type: String, default: "" },
9
- rows: { type: Number, default: 0 },
10
- columns: { type: Number, default: 0 },
11
- navigateToUrl: { type: String, default: "" },
12
- altText: { type: String, default: "" },
13
- cellWidths: { type: [Number], default: [] },
14
- }, { _id: false });
15
- const BlockDataSchema = new mongoose_1.Schema({
16
- style: { type: mongoose_1.Schema.Types.Mixed },
17
- props: { type: BlockDataPropsSchema },
18
- childrenIds: { type: [String], default: [] },
19
- }, { _id: false });
20
- const BlockSchema = new mongoose_1.Schema({
21
- type: {
22
- type: String,
23
- required: true,
24
- enum: Object.values(types_1.BlockType),
25
- },
26
- data: BlockDataSchema,
27
- }, { _id: false });
28
- const EmailTemplateSchema = new mongoose_1.Schema({
29
- name: {
30
- type: String,
31
- required: true
32
- },
33
- layout: {
34
- type: Map,
35
- of: BlockSchema,
36
- required: true,
37
- },
38
- isDeleted: {
39
- type: Boolean,
40
- default: false,
41
- },
42
- user: { type: mongoose_1.Schema.Types.ObjectId, ref: 'user' },
43
- deletedAt: Date
44
- }, { timestamps: true });
45
- exports.EmailTemplate = (0, mongoose_1.model)("email-template", EmailTemplateSchema);
@@ -1,14 +0,0 @@
1
- import { Types } from "mongoose";
2
- interface IRole {
3
- name: string;
4
- isDeleted: boolean;
5
- createdAt: Date;
6
- updatedAt: Date;
7
- deletedAt: Date;
8
- features: Types.ObjectId[];
9
- }
10
- export declare const RoleModel: import("mongoose").Model<IRole, {}, {}, {}, import("mongoose").Document<unknown, {}, IRole> & Omit<IRole & {
11
- _id: Types.ObjectId;
12
- }, never>, any>;
13
- export {};
14
- //# sourceMappingURL=role.entitty.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"role.entitty.d.ts","sourceRoot":"","sources":["../../src/entity/role.entitty.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,EAAE,MAAM,UAAU,CAAC;AAEhD,UAAU,KAAK;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;CAC5B;AAcD,eAAO,MAAM,SAAS;SAC4mI,MAAO,QAAQ;eADxlI,CAAC"}
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RoleModel = void 0;
4
- const mongoose_1 = require("mongoose");
5
- const RoleSchema = new mongoose_1.Schema({
6
- name: { type: String, unique: true, sparse: true },
7
- isDeleted: { type: Boolean, default: false },
8
- deletedAt: { type: Date, default: null },
9
- features: { type: [{ type: mongoose_1.Schema.Types.ObjectId, ref: 'feature' }], default: [], _id: false },
10
- }, {
11
- timestamps: true,
12
- });
13
- exports.RoleModel = (0, mongoose_1.model)("role", RoleSchema);