Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication plugin now uses email templates to render the email body. #51

Merged
21 changes: 21 additions & 0 deletions .changeset/curvy-bats-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
"@bugslifesolutions/bl-api-plugin-nodemailer": minor
"@bugslifesolutions/api-plugin-bull-queue": minor
"@bugslifesolutions/api-plugin-email": minor
"@bugslifesolutions/api-core": minor
---

# Enhancements:

AppEvent debug logging

# Fixed:

Nodemailer plugin:

- MSAL Auth secret corruption
- ensure auth failures are handled with error logging and transporter close

Email plugin:

- ensure process is rejected on unexpected errors
5 changes: 5 additions & 0 deletions .changeset/sharp-knives-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bugslifesolutions/bl-api-plugin-nodemailer": minor
---

Nodemailer plugin debug logging
11 changes: 11 additions & 0 deletions .changeset/sixty-teachers-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@bugslifesolutions/api-plugin-authentication": major
"@bugslifesolutions/api-plugin-email-templates": minor
"@bugslifesolutions/api-plugin-accounts": minor
---

Authentication plugin now uses email templates to render the email body.

Potential Breaking Change:

The built-in accountsjs email templates are not used in favor of using the email templates. This change was made to enable customization of the email body consistent with other email sending use cases.
7 changes: 2 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ defaults: &build
install_pnpm: &install_pnpm
- run:
name: Install pnpm package manager
command: sudo npm i -g pnpm@8.11.0
command: sudo npm i -g pnpm@8.14.0

pnpm_install: &pnpm_install
- run:
name: Install PNPM dependencies
command: pnpm install -r
command: pnpm install

integration: &integration
<<: *env
Expand Down Expand Up @@ -232,9 +232,6 @@ jobs:
echo "ES_CATALOG_SYNC_ENTERPRISESEARCH_URL=http://localhost:9090" >> .env
echo "ES_CATALOG_SYNC_ENTERPRISESEARCH_KEY=secretkey" >> .env
echo "REDIS_SERVER=redis://redis.reaction.localhost:6379" >> .env
- run:
name: Create reaction.localhost network
command: docker network create "reaction.localhost" || true
- run:
name: Configure docker-compose.circleci.yml with the latest docker image reference
command: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
node-version: "18.18.2"

- name: Install pnpm
run: npm i -g pnpm@8.11.0
run: npm i -g pnpm@8.14.0

- name: Install dependencies
run: pnpm install --ignore-scripts
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
node-version: "18.18.2"

- name: Install pnpm
run: npm i -g pnpm@8.11.0
run: npm i -g pnpm@8.14.0

- name: Install dependencies
run: pnpm install --ignore-scripts
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
node-version: "18.18.2"

- name: Install pnpm
run: npm i -g pnpm@8.11.0
run: npm i -g pnpm@8.14.0

- name: Install Dependencies
run: pnpm install --ignore-scripts
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tagging-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

- name: Install dependencies
run: |
npm i -g pnpm@8.11.0
npm i -g pnpm@8.14.0
pnpm install -r --ignore-scripts
- name: Get tag version
id: get-tag-version
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ instructions

## Install PNPM
```bash
npm i -g pnpm@8.11.0
npm i -g pnpm@8.14.0
```

## Clone and Start the source

```bash
git clone https://github.com/reactioncommerce/reaction.git
cd reaction
pnpm install
pnpm install -r
cp apps/reaction/.env.example apps/reaction/.env
```

Expand Down
4 changes: 2 additions & 2 deletions apps/reaction/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ COPY ./apps/reaction ./apps/reaction
COPY ./packages ./packages
COPY .npmrc .nvmrc package.json pnpm-lock.yaml pnpm-workspace.yaml ./

RUN npm i -g pnpm@8.11.0 && pnpm --filter=reaction deploy deps --ignore-scripts
RUN npm i -g pnpm@8.14.0 && pnpm --filter=reaction deploy deps --ignore-scripts

# hadolint ignore=DL3003,SC2015
RUN cd deps/node_modules/sharp && npm run install
Expand All @@ -31,7 +31,7 @@ RUN chown node:node .

ENV NODE_ENV=production

COPY --from=deps /app/deps /usr/local/src/app
COPY --from=deps /app/deps .

USER node

Expand Down
14 changes: 5 additions & 9 deletions docker-compose.circleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,36 @@ version: "3.9"
networks:
reaction:
name: reaction.localhost
external: true

services:
api:
image: DOCKER_IMAGE_URI_VERSIONED
image: ${API_IMAGE_URI:-DOCKER_IMAGE_URI_VERSIONED}
depends_on:
- mongo
env_file:
- ./.env
networks:
- default
- reaction
ports:
- "3000:3000"

mongo:
image: mongo:5.0
image: ${MONGO_IMAGE_URI:-mongo:5.0}
command: mongod --oplogSize 128 --replSet rs0 --storageEngine=wiredTiger
networks:
- default
- reaction
ports:
- "27017:27017"
volumes:
- mongo-db4:/data/db
healthcheck: # re-run rs.initiate() after startup if it failed.
test: test $$(echo "rs.status().ok || rs.initiate().ok" | mongo --quiet) -eq 1
test: test $$(echo "rs.status().ok || rs.initiate({_id:'rs0',members:[{_id:0,host:'mongo.reaction.localhost:27017'}]})" | mongo --quiet) -eq 1
interval: 10s
start_period: 30s
start_period: 50s

redis:
image: redis:7
image: redis:${REDIS_VERSION:-7}
networks:
- default
- reaction
ports:
- "6379:6379"
Expand Down
41 changes: 16 additions & 25 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,25 @@
# This Docker Compose file is used for development purposes.
# It defines the services and configurations required to run the Reaction development platform.# This docker-compose file is used to override the default docker-compose file
# in the reactioncommerce/reaction repository. It is used to add additional
# services to the default docker-compose file, such as maildev.
#
# example docker-compose command:
# docker-compose -f docker-compose.yml -f docker-compose.override.yml up -d
# or in this case:
# docker-compose -f docker-compose.yml -f docker-compose.override.yml -f docker-compose.dev.yml up -d
version: "3.4"

services:
mongo:
image: mongo:5.0
command: mongod --oplogSize 128 --replSet rs0 --storageEngine=wiredTiger
networks:
default:
ports:
- "27017:27017"
volumes:
- mongo-db4:/data/db
healthcheck: # re-run rs.initiate() after startup if it failed.
test: test $$(echo "rs.status().ok || rs.initiate().ok" | mongo --quiet) -eq 1
interval: 10s
start_period: 30s

redis:
image: redis:7
networks:
default:
ports:
- "6379:6379"
networks:
reaction:
name: reaction.localhost
attachable: true

services:
maildev:
image: maildev/maildev
networks:
default:
- default
- reaction
ports:
- "1080:1080"
- "1025:1025"

volumes:
mongo-db4:
29 changes: 1 addition & 28 deletions docker-compose.localtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,4 @@ version: "3.9"
networks:
reaction:
name: reaction.localhost
external: true

services:
mongo:
image: mongo:4.2
command: mongod --oplogSize 128 --replSet rs0 --storageEngine=wiredTiger
networks:
- default
- reaction
ports:
- "27017:27017"
volumes:
- mongo-db4:/data/db
healthcheck: # re-run rs.initiate() after startup if it failed.
test: test $$(echo "rs.status().ok || rs.initiate({_id:'rs0',members:[{_id:0,host:'mongo.reaction.localhost:27017'}]})" | mongo --quiet) -eq 1
interval: 10s
start_period: 30s

redis:
image: redis:7
networks:
- default
- reaction
ports:
- "6379:6379"

volumes:
mongo-db4:
attachable: true
9 changes: 4 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ version: "3.9"
networks:
reaction:
name: reaction.localhost
external: true

services:
api:
image: reactioncommerce/reaction:5.1.0.0
image: ${API_IMAGE_URI:-alpine:latest}
depends_on:
- mongo
env_file:
Expand All @@ -24,7 +23,7 @@ services:
- "3000:3000"

mongo:
image: mongo:4.2
image: ${MONGO_IMAGE_URI:-mongo:5.0}
command: mongod --oplogSize 128 --replSet rs0 --storageEngine=wiredTiger
networks:
- reaction
Expand All @@ -33,12 +32,12 @@ services:
volumes:
- mongo-db4:/data/db
healthcheck: # re-run rs.initiate() after startup if it failed.
test: test $$(echo "rs.status().ok || rs.initiate().ok" | mongo --quiet) -eq 1
test: test $$(echo "rs.status().ok || rs.initiate({_id:'rs0',members:[{_id:0,host:'mongo.reaction.localhost:27017'}]})" | mongo --quiet) -eq 1
interval: 10s
start_period: 50s

redis:
image: redis:7
image: redis:${REDIS_VERSION:-7}
networks:
- reaction
ports:
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"scripts": {
"env:version": "node ./extract_dot_version.mjs",
"env": "node CleanseProcessEnv.js",
"start:dev": "npm run start:dev -w apps/reaction",
"start:dev": "REACTION_SHOULD_ENCODE_IDS=false REACTION_LOG_LEVEL=DEBUG npm run start:dev -w apps/reaction",
"start:meteor-blaze-app": "npm run start -w=apps/meteor-blaze-app",
"build:packages": "pnpm -r run build",
"test": "pnpm -r run test",
Expand All @@ -24,8 +24,8 @@
"postinstall": "npm run build:packages && is-ci || is-docker || husky install .husky",
"api:docker:env": "pnpm run env:version && . ./.version && . ./.env.docker && echo \"DOCKER_IMAGE_URI is $DOCKER_IMAGE_URI\" && echo \"DOCKER_IMAGE_URI_VERSIONED is $DOCKER_IMAGE_URI_VERSIONED\"",
"api:docker:build": "pnpm run api:docker:env && . ./.version && . ./.env.docker && docker build --no-cache -t $DOCKER_IMAGE_URI_VERSIONED -t $DOCKER_IMAGE_URI:latest -f ./apps/reaction/Dockerfile .",
"api:docker:inspect": "pnpm run api:docker:env && . ./.version && . ./.env.docker && docker run --rm --network='reaction.localhost' --env-file './.env.docker' --mount type=bind,source=$(pwd)/apps/reaction/plugins.json,target=/usr/local/src/app/plugins.json $DOCKER_IMAGE_URI_VERSIONED node --inspect ./src/index.js",
"api:docker:inspect2": "pnpm run api:docker:env && . ./.version && . ./.env.docker && docker run --rm -it --network='reaction.localhost' --env-file './.env.docker' --mount type=bind,source=$(pwd)/apps/reaction/plugins.json,target=/usr/local/src/app/plugins.json $DOCKER_IMAGE_URI_VERSIONED node",
"api:docker:inspect": "pnpm run api:docker:env && . ./.version && . ./.env.docker && docker run --rm -p 9229:9229 --network='reaction.localhost' --env-file './.env.docker' --mount type=bind,source=$(pwd)/apps/reaction/plugins.json,target=/usr/local/src/app/plugins.json $DOCKER_IMAGE_URI_VERSIONED node --inspect=0.0.0.0:9229 ./src/index.js",
"api:docker:inspect-brk": "pnpm run api:docker:env && . ./.version && . ./.env.docker && docker run --rm -p 9229:9229 --network='reaction.localhost' --env-file './.env.docker' --mount type=bind,source=$(pwd)/apps/reaction/plugins.json,target=/usr/local/src/app/plugins.json $DOCKER_IMAGE_URI_VERSIONED node --inspect-brk=0.0.0.0:9229 ./src/index.js",
"api:docker:push": "pnpm run api:docker:env && . ./.version && . ./.env.docker && docker push $DOCKER_IMAGE_URI_VERSIONED && docker push $DOCKER_IMAGE_URI:latest"
},
"homepage": "https://github.com/bugslifesolutions/reaction",
Expand Down
14 changes: 13 additions & 1 deletion packages/api-core/src/util/appEvents.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import Logger from "@bugslifesolutions/logger";
import pkg from "./../../package.json" assert { type: "json" };

const logCtx = {
name: pkg.name,
version: pkg.version,
file: "appEvents.js"
};

/**
* This is a temporary events solution on our path to
Expand All @@ -23,7 +30,7 @@ async function synchronousPromiseLoop(name, funcs, args) {
try {
await func(...args);
} catch (error) {
Logger.error(`Error in "${name}" consumer`, error);
Logger.error({ ...logCtx }, `Error in "${name}" consumer`, error);
}

if (funcs.length) {
Expand All @@ -38,19 +45,23 @@ class AppEvents {
}

resume() {
Logger.debug({ ...logCtx, fn: "resume" }, `stopped was "${this.stopped}"`);
this.stopped = false;
}

stop() {
Logger.debug({ ...logCtx, fn: "stop" }, `stopped was "${this.stopped}"`);
this.stopped = true;
}

async emit(name, ...args) {
Logger.debug({ ...logCtx, fn: "emit", args: JSON.stringify(args) }, `started AppEvents emit "${name}", stopped is "${this.stopped}"`);
if (this.stopped || !this.handlers[name]) return;

// Can't use forEach or map because we want each func to wait
// until the previous func promise resolves
await synchronousPromiseLoop(name, this.handlers[name].slice(0), args);
Logger.debug({ ...logCtx, fn: "emit" }, `finished AppEvents emit "${name}", handler count "${this.handlers[name].length}"`);
}

on(name, func) {
Expand All @@ -59,6 +70,7 @@ class AppEvents {
}

this.handlers[name].push(func);
Logger.debug({ ...logCtx, fn: "on" }, `AppEvents on "${name}", handler count "${this.handlers[name].length}", stopped is "${this.stopped}"`);
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/api-plugin-accounts/src/mutations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import removeAccountFromGroup from "./removeAccountFromGroup.js";
import removeAccountGroup from "./removeAccountGroup.js";
import revokeAdminUIAccess from "./revokeAdminUIAccess.js";
import sendResetAccountPasswordEmail from "./sendResetAccountPasswordEmail.js";
import sendEmailWithTemplate from "./sendEmailWithTemplate.js";
import setAccountDefaultEmail from "./setAccountDefaultEmail.js";
import updateAccount from "./updateAccount.js";
import updateAccountAddressBookEntry from "./updateAccountAddressBookEntry.js";
Expand All @@ -36,6 +37,7 @@ export default {
removeAccountGroup,
revokeAdminUIAccess,
sendResetAccountPasswordEmail,
sendEmailWithTemplate,
setAccountDefaultEmail,
updateAccount,
updateAccountAddressBookEntry,
Expand Down
Loading