docta-package 1.0.1 → 1.1.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.
Files changed (164) hide show
  1. package/README.md +1 -0
  2. package/build/config.d.ts +14 -0
  3. package/build/config.js +15 -0
  4. package/build/dto/input/doctor.d.ts +28 -0
  5. package/build/dto/input/doctor.js +131 -0
  6. package/build/dto/input/education.d.ts +4 -0
  7. package/build/dto/input/education.js +26 -0
  8. package/build/dto/input/faq.d.ts +4 -0
  9. package/build/dto/input/faq.js +26 -0
  10. package/build/dto/input/index.js +25 -0
  11. package/build/dto/input/language.d.ts +5 -0
  12. package/build/dto/input/language.js +28 -0
  13. package/build/dto/input/location.d.ts +9 -0
  14. package/build/dto/input/location.js +51 -0
  15. package/build/dto/input/patient.d.ts +6 -0
  16. package/build/dto/input/patient.js +33 -0
  17. package/build/dto/input/position.d.ts +6 -0
  18. package/build/dto/input/position.js +37 -0
  19. package/build/dto/input/specialty.d.ts +12 -0
  20. package/build/dto/input/specialty.js +56 -0
  21. package/build/dto/input/user.d.ts +29 -0
  22. package/build/dto/input/user.js +112 -0
  23. package/build/dto/output/doctor.d.ts +38 -0
  24. package/build/dto/output/doctor.js +61 -0
  25. package/build/dto/output/education.d.ts +6 -0
  26. package/build/dto/output/education.js +10 -0
  27. package/build/dto/output/faq.d.ts +6 -0
  28. package/build/dto/output/faq.js +10 -0
  29. package/build/dto/output/index.js +25 -0
  30. package/build/dto/output/language.d.ts +6 -0
  31. package/build/dto/output/language.js +10 -0
  32. package/build/dto/output/location.d.ts +11 -0
  33. package/build/dto/output/location.js +16 -0
  34. package/build/dto/output/patient.d.ts +20 -0
  35. package/build/dto/output/patient.js +34 -0
  36. package/build/dto/output/position.d.ts +8 -0
  37. package/build/dto/output/position.js +13 -0
  38. package/build/dto/output/specialty.d.ts +23 -0
  39. package/build/dto/output/specialty.js +40 -0
  40. package/build/dto/output/user.d.ts +24 -0
  41. package/build/dto/output/user.js +36 -0
  42. package/build/enums/gender.d.ts +4 -0
  43. package/build/enums/gender.js +8 -0
  44. package/build/enums/index.js +20 -0
  45. package/build/enums/language-levels.d.ts +8 -0
  46. package/build/enums/language-levels.js +12 -0
  47. package/build/enums/status-codes.d.ts +24 -0
  48. package/build/enums/status-codes.js +28 -0
  49. package/build/enums/user-role.d.ts +5 -0
  50. package/build/enums/user-role.js +9 -0
  51. package/build/errors/BadRequestError.d.ts +8 -0
  52. package/build/errors/BadRequestError.js +15 -0
  53. package/build/errors/CustomError.d.ts +8 -0
  54. package/build/errors/CustomError.js +13 -0
  55. package/build/errors/NotFoundError.d.ts +8 -0
  56. package/build/errors/NotFoundError.js +15 -0
  57. package/build/errors/UnAuthorizedError.d.ts +8 -0
  58. package/build/errors/UnAuthorizedError.js +15 -0
  59. package/build/errors/index.js +20 -0
  60. package/{src/index.ts → build/index.d.ts} +4 -6
  61. package/build/index.js +25 -0
  62. package/build/interfaces/LoggedInUserToken.d.ts +6 -0
  63. package/build/interfaces/LoggedInUserToken.js +2 -0
  64. package/build/interfaces/index.js +17 -0
  65. package/build/middleware/errorHandler.d.ts +2 -0
  66. package/build/middleware/errorHandler.js +26 -0
  67. package/build/middleware/index.js +21 -0
  68. package/build/middleware/multer.d.ts +6 -0
  69. package/build/middleware/multer.js +58 -0
  70. package/build/middleware/require-auth.d.ts +2 -0
  71. package/build/middleware/require-auth.js +39 -0
  72. package/build/middleware/validate-request.d.ts +2 -0
  73. package/build/middleware/validate-request.js +41 -0
  74. package/build/middleware/verify-roles.d.ts +3 -0
  75. package/build/middleware/verify-roles.js +17 -0
  76. package/build/models/base.d.ts +13 -0
  77. package/build/models/base.js +41 -0
  78. package/build/models/doctor.d.ts +33 -0
  79. package/build/models/doctor.js +55 -0
  80. package/build/models/education.d.ts +14 -0
  81. package/build/models/education.js +8 -0
  82. package/build/models/faq.d.ts +14 -0
  83. package/build/models/faq.js +8 -0
  84. package/build/models/index.js +26 -0
  85. package/build/models/language.d.ts +15 -0
  86. package/build/models/language.js +14 -0
  87. package/build/models/location.d.ts +19 -0
  88. package/{src/models/location.ts → build/models/location.js} +6 -17
  89. package/build/models/patient.d.ts +15 -0
  90. package/build/models/patient.js +15 -0
  91. package/build/models/position.d.ts +16 -0
  92. package/build/models/position.js +10 -0
  93. package/build/models/specialty.d.ts +15 -0
  94. package/build/models/specialty.js +12 -0
  95. package/build/models/user.d.ts +19 -0
  96. package/build/models/user.js +47 -0
  97. package/build/utils/index.js +21 -0
  98. package/build/utils/orchestration-result.d.ts +38 -0
  99. package/build/utils/orchestration-result.js +26 -0
  100. package/build/utils/s3-helper.d.ts +13 -0
  101. package/build/utils/s3-helper.js +67 -0
  102. package/build/utils/token-utils.d.ts +11 -0
  103. package/build/utils/token-utils.js +77 -0
  104. package/build/utils/validate-info.d.ts +4 -0
  105. package/build/utils/validate-info.js +20 -0
  106. package/build/utils/winston.d.ts +3 -0
  107. package/build/utils/winston.js +32 -0
  108. package/package.json +7 -2
  109. package/src/config.ts +0 -25
  110. package/src/dto/input/doctor.ts +0 -120
  111. package/src/dto/input/education.ts +0 -11
  112. package/src/dto/input/faq.ts +0 -11
  113. package/src/dto/input/language.ts +0 -13
  114. package/src/dto/input/location.ts +0 -31
  115. package/src/dto/input/patient.ts +0 -17
  116. package/src/dto/input/position.ts +0 -21
  117. package/src/dto/input/specialty.ts +0 -40
  118. package/src/dto/input/user.ts +0 -87
  119. package/src/dto/output/doctor.ts +0 -90
  120. package/src/dto/output/education.ts +0 -11
  121. package/src/dto/output/faq.ts +0 -11
  122. package/src/dto/output/language.ts +0 -11
  123. package/src/dto/output/location.ts +0 -21
  124. package/src/dto/output/patient.ts +0 -49
  125. package/src/dto/output/position.ts +0 -15
  126. package/src/dto/output/specialty.ts +0 -53
  127. package/src/dto/output/user.ts +0 -57
  128. package/src/enums/gender.ts +0 -4
  129. package/src/enums/language-levels.ts +0 -9
  130. package/src/enums/status-codes.ts +0 -28
  131. package/src/enums/user-role.ts +0 -5
  132. package/src/errors/BadRequestError.ts +0 -18
  133. package/src/errors/CustomError.ts +0 -18
  134. package/src/errors/NotFoundError.ts +0 -18
  135. package/src/errors/UnAuthorizedError.ts +0 -18
  136. package/src/interfaces/LoggedInUserToken.ts +0 -9
  137. package/src/middleware/errorHandler.ts +0 -31
  138. package/src/middleware/multer.ts +0 -74
  139. package/src/middleware/require-auth.ts +0 -46
  140. package/src/middleware/validate-request.ts +0 -40
  141. package/src/middleware/verify-roles.ts +0 -17
  142. package/src/models/base.ts +0 -52
  143. package/src/models/doctor.ts +0 -96
  144. package/src/models/education.ts +0 -14
  145. package/src/models/faq.ts +0 -14
  146. package/src/models/language.ts +0 -20
  147. package/src/models/patient.ts +0 -35
  148. package/src/models/position.ts +0 -19
  149. package/src/models/specialty.ts +0 -37
  150. package/src/models/user.ts +0 -67
  151. package/src/utils/orchestration-result.ts +0 -74
  152. package/src/utils/s3-helper.ts +0 -72
  153. package/src/utils/token-utils.ts +0 -86
  154. package/src/utils/validate-info.ts +0 -26
  155. package/src/utils/winston.ts +0 -33
  156. package/tsconfig.json +0 -120
  157. /package/{src/dto/input/index.ts → build/dto/input/index.d.ts} +0 -0
  158. /package/{src/dto/output/index.ts → build/dto/output/index.d.ts} +0 -0
  159. /package/{src/enums/index.ts → build/enums/index.d.ts} +0 -0
  160. /package/{src/errors/index.ts → build/errors/index.d.ts} +0 -0
  161. /package/{src/interfaces/index.ts → build/interfaces/index.d.ts} +0 -0
  162. /package/{src/middleware/index.ts → build/middleware/index.d.ts} +0 -0
  163. /package/{src/models/index.ts → build/models/index.d.ts} +0 -0
  164. /package/{src/utils/index.ts → build/utils/index.d.ts} +0 -0
@@ -0,0 +1,26 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./base"), exports);
18
+ __exportStar(require("./doctor"), exports);
19
+ __exportStar(require("./education"), exports);
20
+ __exportStar(require("./faq"), exports);
21
+ __exportStar(require("./language"), exports);
22
+ __exportStar(require("./location"), exports);
23
+ __exportStar(require("./patient"), exports);
24
+ __exportStar(require("./position"), exports);
25
+ __exportStar(require("./specialty"), exports);
26
+ __exportStar(require("./user"), exports);
@@ -0,0 +1,15 @@
1
+ import { Schema } from "mongoose";
2
+ import { EnumLanguageLevel } from "../enums";
3
+ export interface ILanguage {
4
+ title: string;
5
+ level: EnumLanguageLevel;
6
+ }
7
+ export declare const LanguageSchema: Schema<ILanguage, import("mongoose").Model<ILanguage, any, any, any, import("mongoose").Document<unknown, any, ILanguage, any, {}> & ILanguage & {
8
+ _id: import("mongoose").Types.ObjectId;
9
+ } & {
10
+ __v: number;
11
+ }, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, ILanguage, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<ILanguage>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<ILanguage> & {
12
+ _id: import("mongoose").Types.ObjectId;
13
+ } & {
14
+ __v: number;
15
+ }>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LanguageSchema = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ const enums_1 = require("../enums");
6
+ exports.LanguageSchema = new mongoose_1.Schema({
7
+ title: { type: String, required: true, trim: true },
8
+ level: {
9
+ type: String,
10
+ enum: Object.values(enums_1.EnumLanguageLevel),
11
+ required: true,
12
+ trim: true,
13
+ },
14
+ }, { _id: false });
@@ -0,0 +1,19 @@
1
+ import { Schema } from "mongoose";
2
+ export interface ILocation {
3
+ address?: string;
4
+ city?: string;
5
+ country?: string;
6
+ lat?: number;
7
+ lng?: number;
8
+ zipcode?: string;
9
+ distanceInMeters?: number | null;
10
+ }
11
+ export declare const LocationSchema: Schema<ILocation, import("mongoose").Model<ILocation, any, any, any, import("mongoose").Document<unknown, any, ILocation, any, {}> & ILocation & {
12
+ _id: import("mongoose").Types.ObjectId;
13
+ } & {
14
+ __v: number;
15
+ }, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, ILocation, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<ILocation>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<ILocation> & {
16
+ _id: import("mongoose").Types.ObjectId;
17
+ } & {
18
+ __v: number;
19
+ }>;
@@ -1,17 +1,8 @@
1
- import { Schema } from "mongoose";
2
-
3
- export interface ILocation {
4
- address?: string;
5
- city?: string;
6
- country?: string; // ISO code eg: fr
7
- lat?: number;
8
- lng?: number;
9
- zipcode?: string;
10
- distanceInMeters?: number | null;
11
- }
12
-
13
- export const LocationSchema = new Schema<ILocation>(
14
- {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocationSchema = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ exports.LocationSchema = new mongoose_1.Schema({
15
6
  address: { type: String, required: false, trim: true },
16
7
  city: { type: String, required: false, trim: true },
17
8
  country: { type: String, required: false, trim: true },
@@ -19,6 +10,4 @@ export const LocationSchema = new Schema<ILocation>(
19
10
  lng: { type: Number, required: false },
20
11
  zipcode: { type: String, required: false, trim: true },
21
12
  distanceInMeters: { type: Number, required: false, default: null },
22
- },
23
- { _id: false }
24
- );
13
+ }, { _id: false });
@@ -0,0 +1,15 @@
1
+ import { Document, Model } from "mongoose";
2
+ import { IUserDocument } from ".";
3
+ import { IBaseModel } from ".";
4
+ import { Gender } from "../enums";
5
+ export interface IPatient extends IBaseModel {
6
+ user: IUserDocument;
7
+ dob?: number;
8
+ gender?: Gender;
9
+ phoneNumber?: string;
10
+ }
11
+ export interface IPatientDocument extends IPatient, Document {
12
+ }
13
+ export interface IPatientModel extends Model<IPatientDocument> {
14
+ }
15
+ export declare const PatientModel: IPatientModel;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PatientModel = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ const _1 = require(".");
6
+ const _2 = require(".");
7
+ const enums_1 = require("../enums");
8
+ const PatientSchema = new mongoose_1.Schema(Object.assign(Object.assign({}, _2.BaseSchemaFields), { user: {
9
+ type: mongoose_1.Schema.Types.ObjectId,
10
+ ref: _1.UserModel.modelName,
11
+ required: true,
12
+ onDelete: "cascade",
13
+ }, dob: { type: Number, required: false }, phoneNumber: { type: String, required: false }, gender: { type: String, enum: Object.values(enums_1.Gender), required: false } }));
14
+ PatientSchema.plugin(_2.BaseSchemaPlugin);
15
+ exports.PatientModel = (0, mongoose_1.model)("Patient", PatientSchema);
@@ -0,0 +1,16 @@
1
+ import { Schema } from "mongoose";
2
+ export interface IPosition {
3
+ startDate: number;
4
+ endDate?: number;
5
+ title: string;
6
+ company: string;
7
+ }
8
+ export declare const PositionSchema: Schema<IPosition, import("mongoose").Model<IPosition, any, any, any, import("mongoose").Document<unknown, any, IPosition, any, {}> & IPosition & {
9
+ _id: import("mongoose").Types.ObjectId;
10
+ } & {
11
+ __v: number;
12
+ }, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, IPosition, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<IPosition>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<IPosition> & {
13
+ _id: import("mongoose").Types.ObjectId;
14
+ } & {
15
+ __v: number;
16
+ }>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PositionSchema = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ exports.PositionSchema = new mongoose_1.Schema({
6
+ startDate: { type: Number, required: true },
7
+ endDate: { type: Number, required: false },
8
+ title: { type: String, required: true, trim: true },
9
+ company: { type: String, required: true, trim: true },
10
+ }, { _id: false });
@@ -0,0 +1,15 @@
1
+ import { Document, Model } from "mongoose";
2
+ import { IBaseModel } from ".";
3
+ export interface ILocalizedSpecialtyFields {
4
+ name: string;
5
+ description?: string | null;
6
+ }
7
+ export interface ISpecialty extends IBaseModel {
8
+ en: ILocalizedSpecialtyFields;
9
+ fr?: ILocalizedSpecialtyFields;
10
+ }
11
+ export interface ISpecialtyDocument extends ISpecialty, Document {
12
+ }
13
+ export interface ISpecialtyModel extends Model<ISpecialtyDocument> {
14
+ }
15
+ export declare const SpecialtyModel: ISpecialtyModel;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SpecialtyModel = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ const _1 = require(".");
6
+ const LocalizedFieldsSchema = new mongoose_1.Schema({
7
+ name: { type: String, required: true },
8
+ description: { type: String, default: null },
9
+ }, { _id: false });
10
+ const SpecialtySchema = new mongoose_1.Schema(Object.assign(Object.assign({}, _1.BaseSchemaFields), { en: { type: LocalizedFieldsSchema, required: true }, fr: { type: LocalizedFieldsSchema, required: false, default: null } }));
11
+ SpecialtySchema.plugin(_1.BaseSchemaPlugin);
12
+ exports.SpecialtyModel = (0, mongoose_1.model)("Specialty", SpecialtySchema);
@@ -0,0 +1,19 @@
1
+ import { Document, Model } from "mongoose";
2
+ import { EnumUserRole } from "../enums";
3
+ import { IBaseModel } from ".";
4
+ export interface IUser extends IBaseModel {
5
+ role: EnumUserRole;
6
+ name: string;
7
+ email: string;
8
+ password?: string;
9
+ activationToken?: string | null;
10
+ forgotPasswordToken?: string | null;
11
+ token?: string | null;
12
+ isActive: boolean;
13
+ }
14
+ export interface IUserDocument extends IUser, Document {
15
+ comparePassword(candidatePassword: string): Promise<boolean>;
16
+ }
17
+ export interface IUserModel extends Model<IUserDocument> {
18
+ }
19
+ export declare const UserModel: IUserModel;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.UserModel = void 0;
13
+ const mongoose_1 = require("mongoose");
14
+ const enums_1 = require("../enums");
15
+ const bcrypt = require("bcryptjs");
16
+ const _1 = require(".");
17
+ const UserSchema = new mongoose_1.Schema(Object.assign(Object.assign({}, _1.BaseSchemaFields), { name: { type: String, required: true }, email: { type: String, required: true, unique: true, trim: true }, password: { type: String, required: false, default: null }, activationToken: { type: String, default: null }, forgotPasswordToken: { type: String, default: null }, token: { type: String, default: null }, isActive: { type: Boolean, default: false }, role: {
18
+ type: String,
19
+ enum: Object.values(enums_1.EnumUserRole),
20
+ default: enums_1.EnumUserRole.PATIENT,
21
+ } }));
22
+ UserSchema.plugin(_1.BaseSchemaPlugin);
23
+ UserSchema.pre("save", function (next) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ if (!this.isModified("password")) {
26
+ return next();
27
+ }
28
+ try {
29
+ const salt = yield bcrypt.genSalt(10);
30
+ this.password = yield bcrypt.hash(this.password, salt);
31
+ return next();
32
+ }
33
+ catch (error) {
34
+ return next(error);
35
+ }
36
+ });
37
+ });
38
+ UserSchema.methods.comparePassword = function (candidatePassword) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return bcrypt.compare(candidatePassword, this.password);
41
+ });
42
+ };
43
+ exports.UserModel = (0, mongoose_1.model)("User", UserSchema);
44
+ // const tot = async (): Promise<IUserDocument[]> => {
45
+ // const user: IUserDocument[] = await UserModel.find({});
46
+ // return user;
47
+ // };
@@ -0,0 +1,21 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./orchestration-result"), exports);
18
+ __exportStar(require("./s3-helper"), exports);
19
+ __exportStar(require("./token-utils"), exports);
20
+ __exportStar(require("./validate-info"), exports);
21
+ __exportStar(require("./winston"), exports);
@@ -0,0 +1,38 @@
1
+ import { EnumStatusCode } from "../enums";
2
+ export type ErrorResult = {
3
+ code: EnumStatusCode;
4
+ message: string;
5
+ };
6
+ export type PaginatedResult<T> = {
7
+ code: EnumStatusCode;
8
+ message: string;
9
+ data: {
10
+ items: T[];
11
+ totalItems: number;
12
+ itemsPerPage: number;
13
+ page: number;
14
+ totalPages: number;
15
+ };
16
+ };
17
+ export type SimpleItemResult<T> = {
18
+ code: EnumStatusCode;
19
+ message: string;
20
+ data: {
21
+ item: T;
22
+ } | undefined;
23
+ };
24
+ export declare class OrchestrationResult {
25
+ static paginated<T>({ data, totalItems, itemsPerPage, page, code, message, }: {
26
+ data: T[];
27
+ totalItems: number;
28
+ itemsPerPage: number;
29
+ page: number;
30
+ code: EnumStatusCode;
31
+ message: string;
32
+ }): PaginatedResult<T>;
33
+ static item<T>({ code, data, message, }: {
34
+ code: EnumStatusCode;
35
+ message: string;
36
+ data?: T;
37
+ }): SimpleItemResult<T>;
38
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OrchestrationResult = void 0;
4
+ class OrchestrationResult {
5
+ static paginated({ data, totalItems, itemsPerPage, page, code, message, }) {
6
+ return {
7
+ code,
8
+ message,
9
+ data: {
10
+ items: data,
11
+ totalItems,
12
+ itemsPerPage,
13
+ page,
14
+ totalPages: Math.ceil(totalItems / itemsPerPage),
15
+ },
16
+ };
17
+ }
18
+ static item({ code, data, message, }) {
19
+ return {
20
+ code,
21
+ message,
22
+ data: data === undefined ? undefined : { item: data },
23
+ };
24
+ }
25
+ }
26
+ exports.OrchestrationResult = OrchestrationResult;
@@ -0,0 +1,13 @@
1
+ export declare class AwsS3Helper {
2
+ private s3;
3
+ private bucketName;
4
+ private bucketRegion;
5
+ private accessKey;
6
+ private secretKey;
7
+ private signedUrlExpiry;
8
+ constructor();
9
+ private sendCommand;
10
+ uploadImage(key: string, contentType: string, file: Buffer): Promise<string>;
11
+ getImageUrl(key: string): Promise<string>;
12
+ deleteImageFromS3(key: string): Promise<void>;
13
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AwsS3Helper = void 0;
13
+ const client_s3_1 = require("@aws-sdk/client-s3");
14
+ const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
15
+ const config_1 = require("../config");
16
+ class AwsS3Helper {
17
+ constructor() {
18
+ this.signedUrlExpiry = 3600; // 1 hour
19
+ this.bucketName = config_1.generalConfig.awsS3Bucket;
20
+ this.bucketRegion = config_1.generalConfig.awsS3Region;
21
+ this.accessKey = config_1.generalConfig.awsAccessKey;
22
+ this.secretKey = config_1.generalConfig.awsSecretKey;
23
+ this.s3 = new client_s3_1.S3Client({
24
+ credentials: {
25
+ accessKeyId: this.accessKey,
26
+ secretAccessKey: this.secretKey,
27
+ },
28
+ region: this.bucketRegion,
29
+ requestHandler: { socketTimeout: 120000 },
30
+ });
31
+ }
32
+ sendCommand(command) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ return this.s3.send(command);
35
+ });
36
+ }
37
+ uploadImage(key, contentType, file) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const s3Key = key;
40
+ yield this.sendCommand(new client_s3_1.PutObjectCommand({
41
+ Bucket: this.bucketName,
42
+ Key: s3Key,
43
+ Body: file,
44
+ ContentType: contentType,
45
+ }));
46
+ return s3Key;
47
+ });
48
+ }
49
+ getImageUrl(key) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ const command = new client_s3_1.GetObjectCommand({
52
+ Bucket: this.bucketName,
53
+ Key: key,
54
+ });
55
+ return (0, s3_request_presigner_1.getSignedUrl)(this.s3, command, { expiresIn: this.signedUrlExpiry });
56
+ });
57
+ }
58
+ deleteImageFromS3(key) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ yield this.sendCommand(new client_s3_1.DeleteObjectCommand({
61
+ Bucket: this.bucketName,
62
+ Key: key,
63
+ }));
64
+ });
65
+ }
66
+ }
67
+ exports.AwsS3Helper = AwsS3Helper;
@@ -0,0 +1,11 @@
1
+ import { LoggedInUserTokenData } from "../interfaces";
2
+ export declare class TokenUtils {
3
+ static createActivationToken(userId: string): string;
4
+ static decodeActivationToken(token: string): string | null;
5
+ static createAccessToken(payload: LoggedInUserTokenData): string;
6
+ static createRefreshToken(payload: LoggedInUserTokenData): string;
7
+ static verifyRefreshToken(token: string): LoggedInUserTokenData | null;
8
+ static verifyAccessToken(token: string): LoggedInUserTokenData;
9
+ static createForgotPasswordToken(userId: string): string;
10
+ static decodeForgotPasswordToken(token: string): string | null;
11
+ }
@@ -0,0 +1,77 @@
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.TokenUtils = void 0;
7
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ const config_1 = require("../config");
9
+ class TokenUtils {
10
+ static createActivationToken(userId) {
11
+ return jsonwebtoken_1.default.sign({ userId }, config_1.generalConfig.accessTokenSecret);
12
+ }
13
+ static decodeActivationToken(token) {
14
+ try {
15
+ const decoded = jsonwebtoken_1.default.verify(token, config_1.generalConfig.activationTokenSecret);
16
+ if (typeof decoded === "string") {
17
+ return null;
18
+ }
19
+ return typeof decoded.userId === "string" ? decoded.userId : null;
20
+ }
21
+ catch (_a) {
22
+ return null;
23
+ }
24
+ }
25
+ static createAccessToken(payload) {
26
+ return jsonwebtoken_1.default.sign(payload, config_1.generalConfig.accessTokenSecret, {
27
+ expiresIn: config_1.generalConfig.accessTokenExpiry,
28
+ });
29
+ }
30
+ static createRefreshToken(payload) {
31
+ return jsonwebtoken_1.default.sign(payload, config_1.generalConfig.refreshTokenSecret, {
32
+ expiresIn: config_1.generalConfig.refreshTokenExpiry,
33
+ });
34
+ }
35
+ static verifyRefreshToken(token) {
36
+ try {
37
+ const decoded = jsonwebtoken_1.default.verify(token, config_1.generalConfig.refreshTokenSecret);
38
+ return {
39
+ id: decoded.id,
40
+ email: decoded.email,
41
+ role: decoded.role,
42
+ };
43
+ }
44
+ catch (_a) {
45
+ return null;
46
+ }
47
+ }
48
+ static verifyAccessToken(token) {
49
+ try {
50
+ const decoded = jsonwebtoken_1.default.verify(token, config_1.generalConfig.accessTokenSecret);
51
+ return {
52
+ id: decoded.id,
53
+ email: decoded.email,
54
+ role: decoded.role,
55
+ };
56
+ }
57
+ catch (error) {
58
+ throw error;
59
+ }
60
+ }
61
+ static createForgotPasswordToken(userId) {
62
+ return jsonwebtoken_1.default.sign({ userId }, config_1.generalConfig.forgotPasswordTokenSecret);
63
+ }
64
+ static decodeForgotPasswordToken(token) {
65
+ try {
66
+ const decoded = jsonwebtoken_1.default.verify(token, config_1.generalConfig.forgotPasswordTokenSecret);
67
+ if (typeof decoded === "string") {
68
+ return null;
69
+ }
70
+ return typeof decoded.userId === "string" ? decoded.userId : null;
71
+ }
72
+ catch (_a) {
73
+ return null;
74
+ }
75
+ }
76
+ }
77
+ exports.TokenUtils = TokenUtils;
@@ -0,0 +1,4 @@
1
+ import { IUserDocument } from "../models";
2
+ export declare class ValidateInfo {
3
+ static validateUser(user: IUserDocument): void;
4
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidateInfo = void 0;
4
+ const enums_1 = require("../enums");
5
+ const errors_1 = require("../errors");
6
+ const errors_2 = require("../errors");
7
+ class ValidateInfo {
8
+ static validateUser(user) {
9
+ if (!user) {
10
+ throw new errors_1.NotFoundError(enums_1.EnumStatusCode.NOT_FOUND, "User not found");
11
+ }
12
+ if (user.isDeleted) {
13
+ throw new errors_2.UnAuthorizedError(enums_1.EnumStatusCode.ACCOUNT_DELETED, "Your account has been deleted");
14
+ }
15
+ if (!user.isActive) {
16
+ throw new errors_2.UnAuthorizedError(enums_1.EnumStatusCode.ACCOUNT_DEACTIVATED, "Account is deactivated");
17
+ }
18
+ }
19
+ }
20
+ exports.ValidateInfo = ValidateInfo;
@@ -0,0 +1,3 @@
1
+ import winston from "winston";
2
+ import "winston-daily-rotate-file";
3
+ export declare const logger: winston.Logger;
@@ -0,0 +1,32 @@
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.logger = void 0;
7
+ // src/utils/logger.ts
8
+ const winston_1 = __importDefault(require("winston"));
9
+ require("winston-daily-rotate-file");
10
+ const path_1 = __importDefault(require("path"));
11
+ const fs_1 = __importDefault(require("fs"));
12
+ const logDir = path_1.default.join(process.cwd(), "logs");
13
+ // ensure logs directory exists
14
+ if (!fs_1.default.existsSync(logDir)) {
15
+ fs_1.default.mkdirSync(logDir, { recursive: true });
16
+ }
17
+ const transport = new winston_1.default.transports.DailyRotateFile({
18
+ dirname: logDir,
19
+ filename: "%DATE%.log",
20
+ datePattern: "YYYY-MM-DD",
21
+ zippedArchive: false,
22
+ maxSize: "20m",
23
+ maxFiles: "14d",
24
+ });
25
+ exports.logger = winston_1.default.createLogger({
26
+ level: "error",
27
+ format: winston_1.default.format.combine(winston_1.default.format.timestamp(), winston_1.default.format.json()),
28
+ transports: [
29
+ transport,
30
+ new winston_1.default.transports.Console({ format: winston_1.default.format.simple() }), // optional
31
+ ],
32
+ });
package/package.json CHANGED
@@ -1,14 +1,19 @@
1
1
  {
2
2
  "name": "docta-package",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "This package will contail all the required files to run the docta micro-service app",
5
5
  "main": "index.js",
6
6
  "types": "build/index.d.ts",
7
+ "files": [
8
+ "build"
9
+ ],
7
10
  "scripts": {
8
11
  "clean": "rm -rf build",
9
12
  "build": "npm run clean && tsc",
10
13
  "prepublishOnly": "npm run build",
11
- "release": "npm version patch -m 'Release %s' && npm publish --access public"
14
+ "release:patch": "npm version patch -m 'Release %s' && npm run build && npm publish --access public",
15
+ "release:minor": "npm version minor -m 'Release %s' && npm run build && npm publish --access public",
16
+ "release:major": "npm version major -m 'Release %s' && npm run build && npm publish --access public"
12
17
  },
13
18
  "author": "",
14
19
  "license": "ISC",
package/src/config.ts DELETED
@@ -1,25 +0,0 @@
1
- interface GeneralConfig {
2
- accessTokenSecret: string;
3
- refreshTokenSecret: string;
4
- accessTokenExpiry: number;
5
- refreshTokenExpiry: number;
6
- awsAccessKey: string;
7
- awsSecretKey: string;
8
- awsS3Bucket: string;
9
- awsS3Region: string;
10
- forgotPasswordTokenSecret: string;
11
- activationTokenSecret: string;
12
- }
13
-
14
- export const generalConfig: GeneralConfig = {
15
- accessTokenSecret: String(process.env.ACCESS_TOKEN_SECRET),
16
- refreshTokenSecret: String(process.env.REFRESH_TOKEN_SECRET),
17
- accessTokenExpiry: Number(process.env.ACCESS_TOKEN_EXPIRY),
18
- refreshTokenExpiry: Number(process.env.REFRESH_TOKEN_EXPIRY),
19
- awsAccessKey: String(process.env.AWS_ACCESS_KEY),
20
- awsSecretKey: String(process.env.AWS_SECRET_KEY),
21
- awsS3Bucket: String(process.env.AWS_S3_BUCKET),
22
- awsS3Region: String(process.env.AWS_S3_REGION),
23
- forgotPasswordTokenSecret: String(process.env.FORGOT_PASSWORD_TOKEN_SECRET),
24
- activationTokenSecret: String(process.env.ACTIVATION_TOKEN_SECRET),
25
- };