1.2.0 • Published 1 year ago

infra-notification-sender v1.2.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

infra-notification-sender

The lambda function infra-notification-sender is connected to the queue infra-notification-sender where it gets the messages about events that ocurred, and then based on the tenants configuration and the event type an email with the relevant information will be sent to the address configured for the tenant.

For the PoC the tenants configuration is provided as JSON in an environment variable called TENANTS_CONFIG, but in the future this configuration will be stored in the Customer DB.

You can see the expected structure for a single tenant config in types.ts Currently the configurations follow this structure:

{
  "{tenantName}": TENANT_CONFIG <--- see types.ts
  ...
}

For the future implementation these are the points to consider:

  • The Nordsense domain needs to be validated as a trusted one for AWS SES.
  • Metrics like emails bounce rate should be added to the alarms and maybe to the dashboards.
CREATE TABLE IF NOT EXISTS public.tenant_notification_configuration (
  "tenant_id" TEXT UNIQUE NOT NULL,
  "emails" TEXT[] NOT NULL,
  "supported_types" TEXT[] NOT NULL,
  "locale" TEXT DEFAULT NULL
);

Example payload (See Notification in types.ts)

{
  "tenant": "test-playground",
  "type": "fire",
  "containerId": "1234"
}

The specific expected data depends on the type, so you can look at those to see which data we expect.

Scripts

Test

npm run test - runs the tests once

npm run watch:test - watches files and tests for changes and re-runs them

Preview Templates

npm run watch:templates

We use MJML and Handlebars. For the best development workflow with VSCode use the daniel knight fork of the MJML extension (danielknights.vscode-mjml), as it adds a way to persist the MJML file preview. See the settings in .vscode/settings.json. Note that the preview file needs to stay open in your editor somewhere, otherwise the preview will switch.

Watching the templates will output all templates in all supported locales into templatePreviews.

Make sure to review templates in all languages, especially an RTL vs LTR locale (f.ex. en-US vs he-IL).

Build

npm run build:staging - will run the tests, then build the output .zip into Terraform Staging Assets

npm run build:prod - will run the tests, then build the output .zip into Terraform Prod Assets

Release

npm run release:staging - runs the staging build and thereafter releases to staging terraform

npm run release:prod - runs the production build and thereafter releases to production terraform

Note that these commands require Terraform

Table schema

CREATE TABLE public.notification_events (
  id uuid NOT NULL PRIMARY KEY,
  tenant_id TEXT NOT NULL,
  sent_timestamp TIMESTAMP WITH TIME ZONE NOT NULL,
  event_timestamp TIMESTAMP WITH TIME ZONE NOT NULL,
  type TEXT NOT NULL,
  resource_id TEXT NOT NULL
);
CREATE UNIQUE INDEX notification_events_type_resource_id_event_timestamp_idx
  ON public.notification_events USING btree (type, resource_id, event_timestamp);
CREATE INDEX notification_events_tenant_id_event_timestamp_idx
  ON public.notification_events USING btree (tenant_id, event_timestamp);
CREATE INDEX notification_events_event_timestamp_idx
  ON public.notification_events USING btree (event_timestamp);
ALTER TABLE public.notification_events
	OWNER TO junk;