• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

safe-global / safe-client-gateway / 6824988676

10 Nov 2023 12:47PM UTC coverage: 90.808% (-0.3%) from 91.077%
6824988676

push

github

web-flow
Add Emails Datasource (#829)

Datasource

Adds a `IEmailDataSource` – this component can be used to interact with the underlying data source which stores the email addresses for a given signer, for a given safe address on a specific chain. The following functionality was added:
  * `saveEmail` – saves an email address in the database. Returns a verification code if it was successfully stored.
  * `setVerificationCode` – resets the verification code for a signer. Returns the new verification code if successful.
  * `verifyEmail` – verifies a specific email given the code that was returned on registration. If the code matches then the email is considered verified. There's a configurable expiration time for the code that was introduced for security reasons – the code needs to be verified within a given timeframe to be considered valid. If the code is not verified in this timeframe then it should be reset.

Database

- Adds one table – `signer_emails` under the `emails` schema.
- A unique constraint exists for entries on `signer_emails`: an entry is considered unique when the following fields are considered: `chain_id`, `safe_address`, `signer`.

Migration Support

Migration support was added. Migration files need to be under the `migrations` folder. Inside it, a migration folder should be created with 5 digits and under that folder, an `index.sql` containing the migration file. 

For example, the initial migration has the following structure:

migrations/
└── 00001_initial
    └── index.sql

The initial migration creates the `signer_emails` table. The migration is done whenever the `PostgresDatabaseModule` is initialised (via the `PostgresDatabaseMigrationHook`).

Note on running multiple instances of the service: an advisory lock is acquired so that only one instance performs the migration. Other instances will wait for the lock to be released (via `pg_advisory_lock`). Migrations should be idempotent so that the final state of th... (continued)

1368 of 1646 branches covered (0.0%)

Branch coverage included in aggregate %.

19 of 40 new or added lines in 6 files covered. (47.5%)

5103 of 5480 relevant lines covered (93.12%)

163.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/datasources/db/postgres-database.module.ts
1
import * as postgres from 'postgres';
×
2
import { Module } from '@nestjs/common';
×
NEW
3
import { PostgresDatabaseShutdownHook } from '@/datasources/db/postgres-database.shutdown.hook';
×
4
import { IConfigurationService } from '@/config/configuration.service.interface';
×
NEW
5
import { PostgresDatabaseMigrationHook } from '@/datasources/db/postgres-database.migration.hook';
×
6

7
function dbFactory(configurationService: IConfigurationService): postgres.Sql {
8
  return postgres({
×
9
    host: configurationService.getOrThrow('db.postgres.host'),
10
    port: configurationService.getOrThrow('db.postgres.port'),
11
    db: configurationService.getOrThrow('db.postgres.database'),
12
    user: configurationService.getOrThrow('db.postgres.username'),
13
    password: configurationService.getOrThrow('db.postgres.password'),
14
  });
15
}
16

17
@Module({
18
  providers: [
19
    {
20
      provide: 'DB_INSTANCE',
21
      useFactory: dbFactory,
22
      inject: [IConfigurationService],
23
    },
24
    PostgresDatabaseShutdownHook,
25
    PostgresDatabaseMigrationHook,
26
  ],
27
  exports: ['DB_INSTANCE'],
28
})
29
export class PostgresDatabaseModule {}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc