mgc 1.0.0 → 1.2.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/bin/generate.js CHANGED
@@ -3,7 +3,7 @@
3
3
  import path from "path";
4
4
  import { program } from "commander";
5
5
 
6
- import { generateProject } from "../services/filecopy.service.js";
6
+ import { generateModule } from "../services/filecopy.service.js";
7
7
 
8
8
  program
9
9
  .command("gen <modulePath>")
@@ -18,7 +18,7 @@ program
18
18
 
19
19
  const currentDir = path.join(process.cwd(), externalPath || "");
20
20
 
21
- generateProject(modulePath, currentDir);
21
+ generateModule(modulePath, currentDir);
22
22
  });
23
23
 
24
24
  program.parse(process.argv);
@@ -0,0 +1,57 @@
1
+ # Email Module
2
+
3
+ ## Required env variables
4
+
5
+ ```
6
+ EMAIL_FROM=""
7
+ AWS_REGION=""
8
+ AWS_ACCESS_KEY_ID=""
9
+ AWS_SECRET_ACCESS_KEY=""
10
+ ```
11
+
12
+ ## Usae
13
+
14
+ ### Packages Requied
15
+
16
+ ```
17
+ yarn add nodemailer handlebars @aws-sdk/client-ses zod
18
+ ```
19
+
20
+ - First you have to create a `.hbs` template in `/templates` directory with necessary placeholders i.e. `{{verificationCode}}` or any other name as per your requirement
21
+ - Then in `email.interface.ts` file on `EmailTemplate` type, append the newly created file name, i.e. if you created `forgot-password.hbs`, the new type should be
22
+
23
+ ```ts
24
+ export type EmailTemplate = "welcome" | "verify-email" | "forgot-password";
25
+ ```
26
+
27
+ - Now use `sendMail` function wherever you require
28
+
29
+ ```ts
30
+ sendMail({
31
+ to: "user@email.com",
32
+ subject: "Email verification",
33
+ template: "verify-email",
34
+ context: {
35
+ verificationCode: "", // populate the placeholder you placed in .hbs file
36
+ },
37
+ });
38
+ ```
39
+
40
+ ## Important Note
41
+
42
+ - we have to copy hbs file as it won't happen during ts compilation step thus add this script on your `package.json`
43
+
44
+ ```json
45
+ "copy-hbs": "copyfiles -u 1 src/**/*.hbs dist"
46
+ ```
47
+
48
+ - and modify your build script to
49
+
50
+ ```json
51
+ "build": "tsc && yarn copy-hbs",
52
+ ```
53
+
54
+ ## Bugs
55
+
56
+ - [ ] Ts do not read .hbs file so, for now, we have copy hbs file using copy-hbs package when building and starting the application.
57
+ - [ ] need to generate dynamic date i.e. @2023 copyright
@@ -0,0 +1,24 @@
1
+ import "dotenv/config";
2
+
3
+ import { z } from "zod";
4
+
5
+ const envSchema = z.object({
6
+ BUCKET: z.string().optional(),
7
+ EMAIL_FROM: z.string().nonempty(),
8
+ AWS_REGION: z.string().nonempty(),
9
+ AWS_ACCESS_KEY_ID: z.string().nonempty(),
10
+ AWS_SECRET_ACCESS_KEY: z.string().nonempty(),
11
+ });
12
+
13
+ export const env = envSchema.parse(process.env);
14
+
15
+ export default {
16
+ aws: {
17
+ region: env.AWS_REGION,
18
+ accessKeyId: env.AWS_ACCESS_KEY_ID,
19
+ secretAccessKey: env.AWS_SECRET_ACCESS_KEY,
20
+ },
21
+ email: {
22
+ from: process.env.EMAIL_FROM,
23
+ },
24
+ };
@@ -0,0 +1,13 @@
1
+ import { Attachment } from "nodemailer/lib/mailer";
2
+
3
+ export type MailerParams = {
4
+ from?: string;
5
+ to: string | Array<string>;
6
+ subject: string;
7
+ context?: Record<string, any>;
8
+ attachments?: Attachment[];
9
+ template?: EmailTemplate;
10
+ html?: string;
11
+ };
12
+
13
+ export type EmailTemplate = "welcome" | "verify-email";
@@ -0,0 +1,46 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import nodemailer from "nodemailer";
4
+ import handlebars from "handlebars";
5
+ import * as aws from "@aws-sdk/client-ses";
6
+
7
+ import config from "./email.config";
8
+ import { MailerParams, EmailTemplate } from "./email.interface";
9
+
10
+ const ses = new aws.SESClient({
11
+ apiVersion: "2010-12-01",
12
+ region: config.aws.region,
13
+ credentials: {
14
+ accessKeyId: config.aws.accessKeyId,
15
+ secretAccessKey: config.aws.secretAccessKey,
16
+ },
17
+ });
18
+
19
+ const nodeMailerTransporter = nodemailer.createTransport({
20
+ SES: { ses, aws },
21
+ });
22
+
23
+ export function sendMail(emailData: MailerParams) {
24
+ emailData.from = emailData.from || config.email.from;
25
+
26
+ // handlebars config
27
+ if (emailData.template) {
28
+ const emailTemplate = fs.readFileSync(
29
+ path.join(__dirname, `./templates/${emailData.template}.hbs`),
30
+ "utf8"
31
+ );
32
+ const template = handlebars.compile(emailTemplate);
33
+ emailData.template = emailTemplate as EmailTemplate;
34
+ emailData.html = template(emailData.context);
35
+ }
36
+
37
+ nodeMailerTransporter.sendMail(emailData, (err, info) => {
38
+ if (err) {
39
+ console.log(`[EmailService] - Error sending email ${err}`);
40
+ } else {
41
+ console.log(
42
+ `[EmailService] - Email sent successfully with response id ${info.response}`
43
+ );
44
+ }
45
+ });
46
+ }
@@ -0,0 +1,14 @@
1
+ <html>
2
+
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Example App - Home</title>
6
+ </head>
7
+
8
+ <body>
9
+
10
+ <p>{{message}}</p>
11
+
12
+ </body>
13
+
14
+ </html>
@@ -0,0 +1,50 @@
1
+ # S3 Module
2
+
3
+ Generating signed url for uploading and previewing files
4
+
5
+ ## Required env variables
6
+
7
+ ```
8
+ BUCKET: '',
9
+ AWS_REGION: '',
10
+ AWS_ACCESS_KEY_ID: '',
11
+ AWS_SECRET_ACCESS_KEY: '',
12
+
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Packages Required
18
+
19
+ ```
20
+ yarn add http-status http-errors @aws-sdk/client-s3 @aws-sdk/s3-request-presigner zod dotenv
21
+ ```
22
+
23
+ ### Implementation
24
+
25
+ ```ts
26
+ // 1. signed url for previewing file
27
+ const key = "file-management/sample.pdf";
28
+ const fileName = "sample.pdf";
29
+ const downlaod = false as boolean;
30
+
31
+ const previewSignedUrl = await s3Service.generateSignedURL({
32
+ key: key,
33
+ fileName: fileName,
34
+ download: download,
35
+ });
36
+
37
+ // 2. generate a pre-signed url for uploading the file
38
+ const fileName = "sample.pdf";
39
+ const prefix = "file-management/";
40
+
41
+ const { signedUrl: preSignedUploadUrl, key } =
42
+ await s3Service.generatePresignedUrl({ prefix, fileName });
43
+
44
+ // Optionally for mime-types
45
+ import mime from "mime-types";
46
+ const mimeType = mime.lookup(fileName);
47
+
48
+ // 3. Delete file
49
+ await s3Service.deleteFile(file.key);
50
+ ```
@@ -0,0 +1,24 @@
1
+ import "dotenv/config";
2
+
3
+ import ms from "ms";
4
+ import { z } from "zod";
5
+
6
+ // validate environment variables to ensure they are available at runtime
7
+ const envSchema = z.object({
8
+ BUCKET: z.string().optional(),
9
+ AWS_REGION: z.string().nonempty(),
10
+ AWS_ACCESS_KEY_ID: z.string().nonempty(),
11
+ AWS_SECRET_ACCESS_KEY: z.string().nonempty(),
12
+ });
13
+
14
+ export const env = envSchema.parse(process.env);
15
+
16
+ export default {
17
+ aws: {
18
+ bucket: env.BUCKET,
19
+ region: env.AWS_REGION,
20
+ accessKeyId: env.AWS_ACCESS_KEY_ID,
21
+ secretAccessKey: env.AWS_SECRET_ACCESS_KEY,
22
+ uploadSignedUrlExpiresIn: ms("60m"), // since we are expecting large files, we are setting this to 60 minutes
23
+ },
24
+ };
@@ -0,0 +1,11 @@
1
+ import { S3Client } from '@aws-sdk/client-s3';
2
+
3
+ import config from './s3.config';
4
+
5
+ export const s3Client = new S3Client({
6
+ region: config.aws.region,
7
+ credentials: {
8
+ accessKeyId: config.aws.accessKeyId,
9
+ secretAccessKey: config.aws.secretAccessKey,
10
+ },
11
+ });
@@ -0,0 +1,103 @@
1
+ import httpStatus from "http-status";
2
+ import createError from "http-errors";
3
+ import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
4
+ import {
5
+ GetObjectCommand,
6
+ PutObjectCommand,
7
+ HeadObjectCommand,
8
+ DeleteObjectCommand,
9
+ } from "@aws-sdk/client-s3";
10
+
11
+ import config from "./s3.config";
12
+ import { s3Client } from "./s3.lib";
13
+ import { generateString, getMime } from "./S3.helper";
14
+
15
+ import { IGeneratePresignedUrl } from "./s3.interface";
16
+
17
+ export const msToSeconds = (ms: number) => ms / 1000;
18
+
19
+ /**
20
+ * Generates a signed URL for accessing an S3 object.
21
+ * @param {string} key - The file name stored in s3.
22
+ * @param {string} fileName - The file name stored in db.
23
+ * @returns {Promise<{key: string, signedUrl: string}>>} The signed URL.
24
+ */
25
+ export const generateSignedURL = async ({
26
+ key,
27
+ fileName,
28
+ download,
29
+ }: {
30
+ key: string;
31
+ fileName: string;
32
+ download: boolean;
33
+ }) => {
34
+ const getObjectParams = {
35
+ Bucket: config.aws.bucket,
36
+ Key: key,
37
+ ...(download
38
+ ? { ResponseContentDisposition: `attachment;filename=${fileName}` }
39
+ : {}), // use browser default download manager
40
+ };
41
+
42
+ const command = new GetObjectCommand(getObjectParams);
43
+ const signedUrl = await getSignedUrl(s3Client, command, { expiresIn: 120 });
44
+
45
+ return {
46
+ key,
47
+ signedUrl,
48
+ };
49
+ };
50
+
51
+ /**
52
+ * Generates a presigned URL for uploading a file to an S3 bucket.
53
+ * @param {object} params - The parameters for generating the presigned URL.
54
+ * @param {string} params.bucket - The S3 bucket name.
55
+ * @param {string} params.fileName - The desired file name.
56
+ * @returns {Promise<{key: string, signedUrl: string}>} The presigned URL.
57
+ */
58
+ export const generatePresignedUrl = async ({
59
+ prefix = "",
60
+ bucket,
61
+ fileName,
62
+ }: IGeneratePresignedUrl) => {
63
+ const mime = getMime(fileName);
64
+
65
+ const key = prefix + `${await generateString(10)}_${Date.now()}.` + mime;
66
+
67
+ const command = new PutObjectCommand({
68
+ Bucket: bucket || config.aws.bucket,
69
+ Key: key,
70
+ });
71
+ const signedUrl = await getSignedUrl(s3Client, command, {
72
+ expiresIn: msToSeconds(config.aws.uploadSignedUrlExpiresIn),
73
+ });
74
+ return {
75
+ key,
76
+ signedUrl,
77
+ };
78
+ };
79
+
80
+ export const getFileSize = async (key: string): Promise<number> => {
81
+ const getObjectMetaDataParams = {
82
+ Bucket: config.aws.bucket,
83
+ Key: key,
84
+ };
85
+
86
+ const response = await s3Client.send(
87
+ new HeadObjectCommand(getObjectMetaDataParams)
88
+ );
89
+ const sizeInBytes = response.ContentLength;
90
+
91
+ if (!sizeInBytes) throw createError(httpStatus.NOT_FOUND, "File not found");
92
+
93
+ return sizeInBytes;
94
+ };
95
+
96
+ export const deleteFile = (key: string) => {
97
+ const deleteObjectParams = {
98
+ Bucket: config.aws.bucket,
99
+ Key: key,
100
+ };
101
+
102
+ return s3Client.send(new DeleteObjectCommand(deleteObjectParams));
103
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mgc",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "A cli based tool for generating your saved modules",
5
5
  "author": "Admond Tamang",
6
6
  "license": "MIT",
@@ -8,6 +8,10 @@
8
8
  "bin": {
9
9
  "cli": "bin/generate.js"
10
10
  },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git@github.com:admondtamang/module-generate-cli.git"
14
+ },
11
15
  "publishConfig": {
12
16
  "access": "public"
13
17
  },
@@ -25,9 +29,15 @@
25
29
  },
26
30
  "type": "module",
27
31
  "dependencies": {
32
+ "@aws-sdk/client-ses": "^3.398.0",
28
33
  "chalk": "^5.3.0",
29
34
  "commander": "^11.0.0",
30
35
  "dotenv": "^16.3.1",
36
+ "handlebars": "^4.7.8",
37
+ "nodemailer": "^6.9.4",
31
38
  "openai": "^3.3.0"
39
+ },
40
+ "devDependencies": {
41
+ "@types/nodemailer": "^6.4.9"
32
42
  }
33
43
  }
package/readme.md CHANGED
@@ -1,4 +1,16 @@
1
+ # Introducation
2
+
3
+ Module Generate Cli (mgc)
4
+
5
+ ## Quick start
6
+
7
+ To generate a module
8
+
9
+ ```
10
+ npx mgc gen express/email
11
+ ```
12
+
1
13
  ## Inspiration
2
14
 
3
- https://github.com/arminbro/generate-react-cli#openai-integration-alpha-release
4
- https://github.com/shadcn-ui
15
+ - https://github.com/arminbro/generate-react-cli#openai-integration-alpha-release
16
+ - https://github.com/shadcn-ui
@@ -39,13 +39,13 @@ export const getCurrentFolder = (name) => {
39
39
  else return name;
40
40
  };
41
41
 
42
- export const generateProject = (modulePath, toGeneratePath) => {
42
+ export const generateModule = (modulePath, toGeneratePath) => {
43
43
  // to get __dirname
44
44
  const __filename = fileURLToPath(import.meta.url);
45
45
  const __dirname = path.dirname(__filename);
46
46
 
47
47
  // copy template files and folders
48
- const templatePath = path.join(__dirname, "../templates/" + modulePath);
48
+ const templatePath = path.join(__dirname, "../modules/" + modulePath);
49
49
 
50
50
  // generate module folder
51
51
  const moduleName = getCurrentFolder(modulePath);
@@ -58,5 +58,5 @@ export const generateProject = (modulePath, toGeneratePath) => {
58
58
  // copy module to your dir
59
59
  copyFolderSync(templatePath, newPathToGenerate);
60
60
 
61
- console.log("Module generated successfully!");
61
+ console.log("Yeah!!! Module generated successfully!");
62
62
  };
@@ -1,13 +0,0 @@
1
- import { Attachment } from 'nodemailer/lib/mailer';
2
-
3
- export interface IEmailInterface {
4
- from?: string;
5
- to: string | Array<string>;
6
- subject: string;
7
- context?: Record<string, any>;
8
- attachments?: Attachment[];
9
- template?: EmailTemplate;
10
- html?: string;
11
- }
12
-
13
- export type EmailTemplate = 'welcome' | 'mfa' | 'registration-invite' | 'forgot-password' | 'axp-user-notifications';
@@ -1,29 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import handlebars from 'handlebars';
4
-
5
- import { config } from '../../../config';
6
- import { logger } from '../../../lib/logger';
7
- import { nodeMailerTransporter } from '../../../lib/nodemailer';
8
-
9
- import { IEmailInterface, EmailTemplate } from './email.interface';
10
-
11
- export const sendMail = (emailData: IEmailInterface) => {
12
- emailData.from = emailData.from || config.email.from;
13
-
14
- // handlebars config
15
- if (emailData.template) {
16
- const emailTemplate = fs.readFileSync(path.join(__dirname, `./templates/${emailData.template}.hbs`), 'utf8');
17
- const template = handlebars.compile(emailTemplate);
18
- emailData.template = emailTemplate as EmailTemplate;
19
- emailData.html = template(emailData.context);
20
- }
21
-
22
- nodeMailerTransporter.sendMail(emailData, (err, info) => {
23
- if (err) {
24
- throw err;
25
- } else {
26
- logger.info(`[EmailService] - Email sent successfully with response id ${info.response}`);
27
- }
28
- });
29
- };
@@ -1,52 +0,0 @@
1
- <html lang='en'>
2
-
3
- <head>
4
- <title>{{title}}</title>
5
-
6
- <meta charset='utf-8' />
7
- <meta name='viewport' content='width=device-width, initial-scale=1' />
8
-
9
- <style>
10
- .body { padding-bottom: 82px; font-size: 16px; background-color: rgba(0, 0, 0, 0.04); font-family: Arial,
11
- sans-serif } .header { background-color: #042940; padding: 23px 48px; border-radius: 16px 16px 0px 0px; } .main {
12
- max-width: 635px; margin: 0 auto; padding: 68px 0 51px 0; color: rgba(0, 0, 0, 0.74); line-height: 140%;
13
- letter-spacing: 0.16px; border-radius: 16px; } .content { background-color: #fff; padding: 51px 48px 87px 48px;
14
- border-radius: 0px 0px 16px 16px; } .content-main { margin: 24px 0 68px 0; } .content-main p { margin: 20px 0 0 0;
15
- } .content-main p:first { margin: 0; } .mfa-code { color: #000; font-style: normal; font-weight: 500; } .greeting
16
- { color: #321D36; font-style: normal; font-weight: 500; } .copyright { color: rgba(17, 18, 24, 0.54); text-align:
17
- center; font-size: 13px; font-family: Inter; line-height: 130%; } .salutation { font-family: Verdana, Geneva,
18
- sans-serif; } .action-link { font-size: 14px; font-weight: 500; color: #004C95; line-height: 140%; letter-spacing:
19
- 0.42px; text-decoration: none; } .sub-text { color: rgba(0, 0, 0, 0.54); font-size: 14px; }
20
- </style>
21
- </head>
22
-
23
- <body>
24
- <div class='body'>
25
- <div class='main'>
26
- <div class='header'>
27
- <img src='https://axp-data-dev.s3.us-east-2.amazonaws.com/public-assets/logo.png' alt='AXP Logo' />
28
- </div>
29
-
30
- <div class='content'>
31
- <p class='greeting salutation'>Hello,</p>
32
-
33
- <div class='content-main'>
34
- <p>{{{message}}} Click the link below to view in detail, or perform actions:</p>
35
-
36
- <p><a href='{{dashboardUrl}}' class='action-link'>{{dashboardUrl}}</a></p>
37
-
38
- </div>
39
-
40
- <p>
41
- <div class='greeting'>Regards,</div>
42
- AX Partners Digital Technology Team
43
- </p>
44
-
45
- </div>
46
- </div>
47
-
48
- <div class='copyright'>© AX Partner Corporation 2023</div>
49
- </div>
50
- </body>
51
-
52
- </html>
@@ -1,57 +0,0 @@
1
- <html lang='en'>
2
-
3
- <head>
4
- <title>Password Reset Request</title>
5
-
6
- <meta charset='utf-8' />
7
- <meta name='viewport' content='width=device-width, initial-scale=1' />
8
-
9
- <style>
10
- .body { padding-bottom: 82px; font-size: 16px; background-color: rgba(0, 0, 0, 0.04); font-family: Arial,
11
- sans-serif } .header { background-color: #042940; padding: 23px 48px; border-radius: 16px 16px 0px 0px; } .main {
12
- max-width: 635px; margin: 0 auto; padding: 68px 0 51px 0; color: rgba(0, 0, 0, 0.74); line-height: 140%;
13
- letter-spacing: 0.16px; border-radius: 16px; } .content { background-color: #fff; padding: 51px 48px 87px 48px;
14
- border-radius: 0px 0px 16px 16px; } .content-main { margin: 24px 0 68px 0; } .content-main p { margin: 20px 0 0 0;
15
- } .content-main p:first { margin: 0; } .mfa-code { color: #000; font-style: normal; font-weight: 500; } .greeting
16
- { color: #321D36; font-style: normal; font-weight: 500; } .copyright { color: rgba(17, 18, 24, 0.54); text-align:
17
- center; font-size: 13px; font-family: Inter; line-height: 130%; } .salutation { font-family: Verdana, Geneva,
18
- sans-serif; } .action-link { font-size: 14px; font-weight: 500; color: #004C95; line-height: 140%; letter-spacing:
19
- 0.42px; text-decoration: none; } .sub-text { color: rgba(0, 0, 0, 0.54); font-size: 14px; }
20
- </style>
21
- </head>
22
-
23
- <body>
24
- <div class='body'>
25
- <div class='main'>
26
- <div class='header'>
27
- <img src='https://axp-data-dev.s3.us-east-2.amazonaws.com/public-assets/logo.png' alt='AXP Logo' />
28
- </div>
29
-
30
- <div class='content'>
31
- <p class='greeting salutation'>Dear {{firstName}},</p>
32
-
33
- <div class='content-main'>
34
- <p>You recently requested a password reset for your AX Partner account. Click the link below to set a new
35
- password:</p>
36
-
37
- <p><a href='{{passwordResetUrl}}' class='action-link'>{{passwordResetUrl}}</a></p>
38
- <div class='sub-text'>* This link is valid for a week</div>
39
-
40
- <p>If you didn't make this request, please disregard this email. Your account remains secure.</p>
41
-
42
- <p>If you need further assistance, please contact our support team at [support email/phone number].</p>
43
- </div>
44
-
45
- <p>
46
- <div class='greeting'>Regards,</div>
47
- AX Partners Digital Technology Team
48
- </p>
49
-
50
- </div>
51
- </div>
52
-
53
- <div class='copyright'>© AX Partner Corporation 2023</div>
54
- </div>
55
- </body>
56
-
57
- </html>
@@ -1,64 +0,0 @@
1
- <html lang='en'>
2
-
3
- <head>
4
- <title>Multi Factor Authentication Code</title>
5
-
6
- <meta charset='utf-8' />
7
- <meta name='viewport' content='width=device-width, initial-scale=1' />
8
-
9
- <style>
10
- .body { padding-bottom: 82px; font-size: 16px; background-color: rgba(0, 0, 0, 0.04); font-family: Arial,
11
- sans-serif } .header { background-color: #042940; padding: 23px 48px; border-radius: 16px 16px 0px 0px; } .main {
12
- max-width: 635px; margin: 0 auto; padding: 68px 0 51px 0; color: rgba(0, 0, 0, 0.74); line-height: 140%;
13
- letter-spacing: 0.16px; border-radius: 16px; } .content { background-color: #fff; padding: 51px 48px 87px 48px;
14
- border-radius: 0px 0px 16px 16px; } .content-main { margin: 24px 0 68px 0; } .content-main p { margin: 20px 0 0 0;
15
- } .content-main p:first { margin: 0; } .mfa-code { color: #000; font-style: normal; font-weight: 500; } .greeting
16
- { color: #321D36; font-style: normal; font-weight: 500; } .copyright { color: rgba(17, 18, 24, 0.54); text-align:
17
- center; font-size: 13px; font-family: Inter; line-height: 130%; } .salutation { font-family: Verdana, Geneva,
18
- sans-serif; }
19
- </style>
20
- </head>
21
-
22
- <body>
23
- <div class='body'>
24
- <div class='main'>
25
- <div class='header'>
26
- <img src='https://axp-data-dev.s3.us-east-2.amazonaws.com/public-assets/logo.png' alt='AXP Logo' />
27
- </div>
28
-
29
- <div class='content'>
30
- <p class='greeting salutation'>Dear {{firstName}},</p>
31
-
32
- <div class='content-main'>
33
- <p>To enhance the security of your AX Partner account, we have implemented Multi-Factor Authentication
34
- (MFA). As part of this security measure, you are required to provide a verification code during the login
35
- process. Please find your MFA code below:</p>
36
-
37
- <p class='mfa-code'>MFA Code: {{mfaCode}}</p>
38
-
39
- <p>Please follow the steps below to complete the login process:
40
- <ol>
41
- <li>Visit the AX Partner login page at {{loginUrl}}.</li>
42
- <li>Enter your username and password as usual.</li>
43
- <li>When prompted, enter the provided MFA code {{mfaCode}} in the designated field.</li>
44
- </ol>
45
- </p>
46
-
47
- <p>Please note that the MFA code is time-sensitive and will expire after a certain period. If the code
48
- expires, you can request a new one by clicking on the "Resend Code" option on the login page.</p>
49
- <p>Thank you for your cooperation in keeping your AX Partner account secure.</p>
50
- </div>
51
-
52
- <p>
53
- <div class='greeting'>Regards,</div>
54
- AX Partners Digital Technology Team
55
- </p>
56
-
57
- </div>
58
- </div>
59
-
60
- <div class='copyright'>© AX Partner Corporation 2023</div>
61
- </div>
62
- </body>
63
-
64
- </html>
@@ -1,60 +0,0 @@
1
- <html lang='en'>
2
-
3
- <head>
4
- <title>Register Your Account</title>
5
-
6
- <meta charset='utf-8' />
7
- <meta name='viewport' content='width=device-width, initial-scale=1' />
8
-
9
- <style>
10
- .body { padding-bottom: 82px; font-size: 16px; background-color: rgba(0, 0, 0, 0.04); font-family: Arial,
11
- sans-serif } .header { background-color: #042940; padding: 23px 48px; border-radius: 16px 16px 0px 0px; } .main {
12
- max-width: 635px; margin: 0 auto; padding: 68px 0 51px 0; color: rgba(0, 0, 0, 0.74); line-height: 140%;
13
- letter-spacing: 0.16px; border-radius: 16px; } .content { background-color: #fff; padding: 51px 48px 87px 48px;
14
- border-radius: 0px 0px 16px 16px; } .content-main { margin: 24px 0 68px 0; } .content-main p { margin: 20px 0 0 0;
15
- } .content-main p:first { margin: 0; } .mfa-code { color: #000; font-style: normal; font-weight: 500; } .greeting
16
- { color: #321D36; font-style: normal; font-weight: 500; } .copyright { color: rgba(17, 18, 24, 0.54); text-align:
17
- center; font-size: 13px; font-family: Inter; line-height: 130%; } .salutation { font-family: Verdana, Geneva,
18
- sans-serif; } .action-link { font-size: 14px; font-weight: 500; color: #004C95; line-height: 140%; letter-spacing:
19
- 0.42px; text-decoration: none; } .sub-text { color: rgba(0, 0, 0, 0.54); font-size: 14px; }
20
- </style>
21
- </head>
22
-
23
- <body>
24
- <div class='body'>
25
- <div class='main'>
26
- <div class='header'>
27
- <img src='https://axp-data-dev.s3.us-east-2.amazonaws.com/public-assets/logo.png' alt='AXP Logo' />
28
- </div>
29
-
30
- <div class='content'>
31
- <p class='greeting salutation'>Hello,</p>
32
-
33
- <div class='content-main'>
34
- <p>Thank you for choosing AX Partner as your trusted platform for [specific purpose]. We are excited to have
35
- you join our community of.</p>
36
-
37
- <p>To complete your registration and gain access to our exclusive features and resources, please click on
38
- the following link:
39
- </p>
40
- <p><a href='{{inviteLink}}' class='action-link'>{{inviteLink}}</a></p>
41
- <div class='sub-text'>* This link is valid for a week</div>
42
-
43
- <p>By clicking the link, you will be directed to a secure registration page where you can set up your
44
- account and provide the necessary information.</p>
45
-
46
- </div>
47
-
48
- <p>
49
- <div class='greeting'>Regards,</div>
50
- AX Partners Digital Technology Team
51
- </p>
52
-
53
- </div>
54
- </div>
55
-
56
- <div class='copyright'>© AX Partner Corporation 2023</div>
57
- </div>
58
- </body>
59
-
60
- </html>
@@ -1,16 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
-
4
- <head>
5
- <meta charset="utf-8">
6
- <title>Example App - Home</title>
7
- </head>
8
-
9
- <body>
10
-
11
- <p>{{message}}</p>
12
-
13
-
14
- </body>
15
-
16
- </html>
@@ -1,121 +0,0 @@
1
- import fs from 'fs';
2
- import httpStatus from 'http-status';
3
- import createError from 'http-errors';
4
- import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
5
- import { GetObjectCommand, PutObjectCommand, HeadObjectCommand, DeleteObjectCommand } from '@aws-sdk/client-s3';
6
-
7
- import { config } from '../../../config';
8
- import { s3Client } from '../../../lib/aws';
9
- import { generateString, getMime } from './S3.helper';
10
- import { msToSeconds } from '../../../utils/msToSeconds';
11
-
12
- import { IFileUploadResult, IGeneratePresignedUrl, IPutFilesOptions } from './s3.interface';
13
-
14
- /**
15
- * Generates a signed URL for accessing an S3 object.
16
- * @param {string} key - The file name stored in s3.
17
- * @returns {Promise<{key: string, signedUrl: string}>>} The signed URL.
18
- */
19
- export const generateSignedURL = async (key: string) => {
20
- const getObjectParams = {
21
- Bucket: config.aws.bucket,
22
- Key: key,
23
- };
24
-
25
- const command = new GetObjectCommand(getObjectParams);
26
- const signedUrl = await getSignedUrl(s3Client, command, { expiresIn: 120 });
27
-
28
- return {
29
- key,
30
- signedUrl,
31
- };
32
- };
33
-
34
- /**
35
- * Generates a presigned URL for uploading a file to an S3 bucket.
36
- * @param {object} params - The parameters for generating the presigned URL.
37
- * @param {string} params.bucket - The S3 bucket name.
38
- * @param {string} params.fileName - The desired file name.
39
- * @returns {Promise<{key: string, signedUrl: string}>} The presigned URL.
40
- */
41
- export const generatePresignedUrl = async ({ prefix = '', bucket, fileName }: IGeneratePresignedUrl) => {
42
- const mime = getMime(fileName);
43
-
44
- const key = prefix + `${await generateString(10)}_${Date.now()}.` + mime;
45
-
46
- const command = new PutObjectCommand({ Bucket: bucket || config.aws.bucket, Key: key });
47
- const signedUrl = await getSignedUrl(s3Client, command, {
48
- expiresIn: msToSeconds(config.aws.uploadSignedUrlExpiresIn),
49
- });
50
- return {
51
- key,
52
- signedUrl,
53
- };
54
- };
55
-
56
- /**
57
- * Uploads multiple files to an S3 bucket.
58
- * @param {any[]} files - The array of files to upload.
59
- * @param {IOptions} [options] - The optional upload options.
60
- * @returns {Promise<IFileUploadResult[]>} The array of file upload results.
61
- */
62
- export const putFilesToBucket = async (files: any, options?: IPutFilesOptions): Promise<IFileUploadResult[]> => {
63
- let path = options?.path;
64
-
65
- const bucketName = options?.bucketName || config.aws.bucket;
66
-
67
- return await Promise.all(
68
- files.map(async (file: any) => {
69
- const fileContent = fs.readFileSync(file.path);
70
-
71
- const originalname = file.originalname;
72
- const mime = getMime(originalname);
73
-
74
- const filename = `${await generateString(10)}_${Date.now()}.` + mime;
75
- if (path) path = path.startsWith('/') ? path.replace('/', '') : `${path}`;
76
-
77
- // path from aws
78
- const key = path ? `${path}/${filename}` : filename;
79
- const filePath = `https://${bucketName}.s3.amazonaws.com/${key}`;
80
-
81
- const command = new PutObjectCommand({
82
- Bucket: bucketName,
83
- Key: key,
84
- Body: fileContent,
85
- });
86
-
87
- await s3Client.send(command);
88
-
89
- return {
90
- key,
91
- mime,
92
- completedUrl: filePath,
93
- originalFileName: originalname,
94
- createdAt: new Date(),
95
- };
96
- }),
97
- );
98
- };
99
-
100
- export const getFileSize = async (key: string): Promise<number> => {
101
- const getObjectMetaDataParams = {
102
- Bucket: config.aws.bucket,
103
- Key: key,
104
- };
105
-
106
- const response = await s3Client.send(new HeadObjectCommand(getObjectMetaDataParams));
107
- const sizeInBytes = response.ContentLength;
108
-
109
- if (!sizeInBytes) throw createError(httpStatus.NOT_FOUND, 'File not found');
110
-
111
- return sizeInBytes;
112
- };
113
-
114
- export const deleteFile = (key: string) => {
115
- const deleteObjectParams = {
116
- Bucket: config.aws.bucket,
117
- Key: key,
118
- };
119
-
120
- return s3Client.send(new DeleteObjectCommand(deleteObjectParams));
121
- };
File without changes