Skip to content

Commit

Permalink
Made email logos optional
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-fabian committed Jun 13, 2023
1 parent bf8ce71 commit 01bf070
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 27 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lbx-jwt",
"description": "Provides JWT authentication for loopback applications. Includes storing roles inside tokens and handling refreshing. Built-in reuse detection.",
"version": "1.0.6",
"version": "1.0.7",
"keywords": [
"lb4",
"LoopBack",
Expand Down Expand Up @@ -42,12 +42,12 @@
},
"peerDependencies": {
"@loopback/authentication": "^9.0.3",
"@loopback/authorization": "^0.12.3",
"@loopback/core": "^4.0.3",
"@loopback/rest": "^12.0.3",
"@loopback/security": "^0.8.3",
"handlebars": "^4.7.7",
"nodemailer": "^6.8.0"
"@loopback/authorization": "^0.12",
"@loopback/core": "^4",
"@loopback/rest": "^12",
"@loopback/security": "^0.8",
"handlebars": "^4",
"nodemailer": "^6"
},
"dependencies": {
"bcryptjs": "^2.4.3",
Expand Down Expand Up @@ -75,4 +75,4 @@
"nodemailer": "^6.9.1",
"typescript": "~5.0.2"
}
}
}
10 changes: 5 additions & 5 deletions src/__tests__/unit/base-mail.service.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect } from '@loopback/testlab';
import { readFileSync } from 'fs';
import { Transporter } from 'nodemailer';
import { BaseUser, PasswordResetToken } from '../../models';
import { BaseMailService } from '../../services';
import { Transporter } from 'nodemailer';
import { DefaultEntityOmitKeys } from '../../types';
import { readFileSync } from 'fs';
import { expect } from '@loopback/testlab';

// eslint-disable-next-line jsdoc/require-jsdoc
class MailService extends BaseMailService<string> {
Expand All @@ -18,9 +18,9 @@ class MailService extends BaseMailService<string> {
// eslint-disable-next-line jsdoc/require-jsdoc
protected readonly SAVED_EMAILS_PATH: string = './test-emails';
// eslint-disable-next-line jsdoc/require-jsdoc
protected readonly LOGO_HEADER_URL: string = 'https://via.placeholder.com/165x165';
protected override readonly LOGO_HEADER_URL: string = 'https://via.placeholder.com/165x165';
// eslint-disable-next-line jsdoc/require-jsdoc
protected readonly LOGO_FOOTER_URL: string = 'https://via.placeholder.com/500x60';
protected override readonly LOGO_FOOTER_URL?: string = 'https://via.placeholder.com/500x60';
// eslint-disable-next-line jsdoc/require-jsdoc
protected readonly ADDRESS_LINES: string[] = ['my address', 'my name'];
}
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/unit/base-user.service.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DefaultHasOneRepository, HasOneRepository, juggler } from '@loopback/repository';
import { HttpErrors } from '@loopback/rest';
import { securityId } from '@loopback/security';
import { createStubInstance, expect, sinon, SinonSpy, StubbedInstanceWithSinonAccessor } from '@loopback/testlab';
import { SinonSpy, StubbedInstanceWithSinonAccessor, createStubInstance, expect, sinon } from '@loopback/testlab';
import { randomBytes } from 'crypto';
import { Transporter } from 'nodemailer';
import { RequestResetPasswordGrant } from '../../controllers/auth/request-reset-password-grant.model';
Expand Down Expand Up @@ -41,9 +41,9 @@ class MailService extends BaseMailService<string> {
// eslint-disable-next-line jsdoc/require-jsdoc
protected readonly SAVED_EMAILS_PATH: string = './test-emails';
// eslint-disable-next-line jsdoc/require-jsdoc
protected readonly LOGO_HEADER_URL: string = 'https://via.placeholder.com/165x165';
protected override readonly LOGO_HEADER_URL: string = 'https://via.placeholder.com/165x165';
// eslint-disable-next-line jsdoc/require-jsdoc
protected readonly LOGO_FOOTER_URL: string = 'https://via.placeholder.com/500x60';
protected override readonly LOGO_FOOTER_URL: string = 'https://via.placeholder.com/500x60';
// eslint-disable-next-line jsdoc/require-jsdoc
protected readonly ADDRESS_LINES: string[] = ['my address', 'my name'];
}
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/unit/refresh-token.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class MailService extends BaseMailService<Roles> {
// eslint-disable-next-line jsdoc/require-jsdoc
protected readonly SAVED_EMAILS_PATH: string = './test-emails';
// eslint-disable-next-line jsdoc/require-jsdoc
protected readonly LOGO_HEADER_URL: string = 'https://via.placeholder.com/165x165';
protected override readonly LOGO_HEADER_URL: string = 'https://via.placeholder.com/165x165';
// eslint-disable-next-line jsdoc/require-jsdoc
protected readonly LOGO_FOOTER_URL: string = 'https://via.placeholder.com/500x60';
protected override readonly LOGO_FOOTER_URL: string = 'https://via.placeholder.com/500x60';
// eslint-disable-next-line jsdoc/require-jsdoc
protected readonly ADDRESS_LINES: string[] = ['my address', 'my name'];
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/mail/base-default.replacements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ export interface BaseDefaultStaticReplacements {
/**
* The url of the logo to display at the top of the email.
*/
logoHeaderUrl: string,
logoHeaderUrl?: string,
/**
* The width of the logo inside the header of the email.
*/
logoHeaderWidth: number,
/**
* The url of the logo to display at the bottom of the email.
*/
logoFooterUrl: string,
logoFooterUrl?: string,
/**
* The width of the logo inside the footer.
*/
Expand Down
10 changes: 5 additions & 5 deletions src/services/mail/base-mail.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { readFileSync, writeFileSync } from 'fs';
import { Transporter } from 'nodemailer';
import path from 'path';
import { HandlebarsUtilities } from '../../encapsulation/handlebars.utilities';
import { BaseUserWithRelations } from '../../models';
import { PasswordResetTokenWithRelations } from '../../models/password-reset-token.model';
import { Transporter } from 'nodemailer';
import { Email } from './email.model';
import { BaseDefaultDynamicReplacements, BaseDefaultStaticReplacements } from './base-default.replacements';
import { Email } from './email.model';
import { ResetPasswordMailReplacements } from './reset-password-mail.replacements';
import path from 'path';

export const LBX_JWT_MAIL_TEMPLATE_DIRECTORY: string = path.join(__dirname, './templates');

Expand Down Expand Up @@ -52,7 +52,7 @@ export abstract class BaseMailService<
/**
* The url for the logo that is placed inside the header.
*/
protected abstract readonly LOGO_HEADER_URL: string;
protected readonly LOGO_HEADER_URL?: string;

/**
* The width of the logo placed inside the header.
Expand All @@ -62,7 +62,7 @@ export abstract class BaseMailService<
/**
* The url for the logo that is placed inside the footer.
*/
protected abstract readonly LOGO_FOOTER_URL: string;
protected readonly LOGO_FOOTER_URL?: string;

/**
* The width of the logo placed inside the footer.
Expand Down
6 changes: 5 additions & 1 deletion src/services/mail/templates/base-mail.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@
margin-top: 20px;
margin-bottom: 20px;
">
{{#if logoHeaderUrl}}
<tr>
<td style="text-align: center; padding: 30px;">
<img src="{{logoHeaderUrl}}" width="{{logoHeaderWidth}}" style="width: {{logoHeaderWidth}}px; max-width: 80%; height: auto;" alt="Logo">
</td>
</tr>
{{/if}}
<tr>
<td style="padding-left: 30px; padding-right: 30px;">
<h1 style="margin-top: 0px; color: {{headlineTextColor}}; text-align: center;">{{headline}}</h1>
Expand Down Expand Up @@ -96,11 +98,13 @@
color: {{textColor}};
margin-bottom: 20px;
">
<tr>
{{#if logoFooterUrl}}
<tr>
<td style="text-align: center; padding-left: 30px; padding-right: 30px;">
<img src="{{logoFooterUrl}}" width="{{logoFooterWidth}}" style="width: {{logoFooterWidth}}px; max-width: 80%; height: auto;" alt="Logo">
</td>
</tr>
{{/if}}
{{#each addressLines}}
<tr>
<td style="padding-left: 30px; padding-right: 30px; text-align: center;">
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.tsbuildinfo

Large diffs are not rendered by default.

0 comments on commit 01bf070

Please sign in to comment.