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

Son/techn 373 apply template for email notifier #102

Open
wants to merge 29 commits into
base: son/techn-371-fix-todo-tasks-discovery-scope
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4fde1ac
[framework] release: publish version v0.6.1
evias Jan 13, 2023
9e6e9e3
[@dhealthdapps/backend] fix(api): update multiplier computation in sc…
evias Jan 17, 2023
b16a942
[@dhealthdapps/frontend] deps: add signer environment variable
evias Jan 17, 2023
f85f974
[@dhealthdapps/frontend] feat(state): add refresh interceptor for act…
kravchenkodhealth Jan 3, 2023
d8846a7
[@dhealthdapps/frontend] fix(screens): add storage for accepted docs
kravchenkodhealth Jan 16, 2023
9e5454e
[@dhealthdapps/backend] refactor: implement getConfig() in AppConfigu…
nsonanh Dec 15, 2022
d41af09
[@dhealthdapps/backend] fix: linter issues
nsonanh Dec 15, 2022
338d245
[@dhealthdapps/backend] refactor: add static factory method to Pagina…
nsonanh Dec 17, 2022
a28342e
[@dhealthdapps/backend] refactor(common): return state data's hash in…
nsonanh Dec 17, 2022
372d74e
[@dhealthdapps/backend] refactor(common): decouple LogModule from not…
nsonanh Dec 17, 2022
99533ce
[@dhealthdapps/backend] refactor(common): remove obsolete todo tasks
nsonanh Dec 17, 2022
5cc7d97
[@dhealthdapps/backend] test: update unit tests
nsonanh Dec 17, 2022
929f75d
[@dhealthdapps/backend] fix: linter
nsonanh Dec 17, 2022
1071121
[@dhealthdapps/backend] refactor(common): remove transaction's serial…
nsonanh Dec 20, 2022
a23f77e
[@dhealthdapps/backend] refactor(discovery): update discoverAccounts …
nsonanh Dec 27, 2022
4b372ab
[@dhealthdapps/backend] refactor(discovery): update debug option valu…
nsonanh Dec 27, 2022
4309aa3
[@dhealthdapps/backend] refactor(discovery): remove obsolete todo tasks
nsonanh Dec 27, 2022
aff58f0
[@dhealthdapps/backend] feat(notifier): add & use templates for alert…
nsonanh Dec 30, 2022
0e19989
[@dhealthdapps/backend] test(notifier): update & fix failed unit tests
nsonanh Dec 30, 2022
dc7cb86
[@dhealthdapps/backend] refactor(notifier): remove DappHelper depende…
nsonanh Dec 30, 2022
a96853b
[@dhealthdapps/backend] feat(notifier): persist alert event to db to …
nsonanh Jan 3, 2023
fe89014
[@dhealthdapps/backend] refactor(notifier): remove unnecessary log in…
nsonanh Jan 5, 2023
a37d5c9
[@dhealthdapps/backend] refactor(oauth): create basic webhook request…
nsonanh Jan 5, 2023
79a47d3
[@dhealthdapps/backend] refactor(oauth): apply strategy pattern for e…
nsonanh Jan 5, 2023
1056a49
[@dhealthdapps/backend] test(oauth): create & fix tests for oauth scope
nsonanh Jan 5, 2023
e69568a
[@dhealthdapps/backend] refactor(common): update find() to be findWit…
nsonanh Jan 11, 2023
91511bb
[@dhealthdapps/backend] refactor(common): remove related todo tasks
nsonanh Jan 11, 2023
b265700
[@dhealthdapps/backend] test: update & add unit tests
nsonanh Jan 17, 2023
aa90d5a
[@dhealthdapps/backend] fix: linter issues
nsonanh Jan 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhealth/contracts",
"version": "0.6.0",
"version": "0.6.1",
"homepage": "https://github.com/dhealthproject/dapps-framework/tree/main/libraries/contracts#readme",
"description": "Contracts for dApps Development with dHealth Network",
"author": "dHealth Network <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion libraries/ui-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhealth/components",
"version": "0.6.0",
"version": "0.6.1",
"homepage": "https://github.com/dhealthproject/dapps-framework/tree/main/libraries/ui-components#readme",
"description": "Components Library for dApps Development with dHealth Network",
"author": "dHealth Network <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhealthdapps/framework",
"version": "0.6.0",
"version": "0.6.1",
"homepage": "https://github.com/dhealthproject/dapps-framework#readme",
"description": "dHealth dApps Framework: Build dApps that scale.",
"author": "dHealth Network <[email protected]>",
Expand Down
13 changes: 11 additions & 2 deletions runtime/backend/nest-cli.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
"sourceRoot": "src",
"compilerOptions": {
"assets": [
{
"include": "**/templates/**/*",
"outDir": "dist/src",
"watchAssets": true
}
]
}
}
2 changes: 1 addition & 1 deletion runtime/backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhealthdapps/backend",
"version": "0.6.0",
"version": "0.6.1",
"homepage": "https://github.com/dhealthproject/dapps-framework/tree/main/runtime/backend#readme",
"description": "dHealth ELEVATE API",
"author": "dHealth Network <[email protected]>",
Expand Down
46 changes: 46 additions & 0 deletions runtime/backend/src/AppConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { DynamicModule } from "@nestjs/common";
import { MailerModule } from "@nestjs-modules/mailer";
import { Account, Address, PublicAccount } from "@dhealth/sdk";
import SMTPTransport from "nodemailer/lib/smtp-transport";
import { HandlebarsAdapter } from "@nestjs-modules/mailer/dist/adapters/handlebars.adapter";

// internal dependencies
import { ConfigurationError } from "./common/errors/ConfigurationError";
Expand Down Expand Up @@ -298,6 +299,44 @@ export class AppConfiguration {
return dappConfig.dappName;
}

/**
* This static helper method returns the configuration section value
* based on the provided section name.
*
* @access public
* @static
* @param {string} section The config section name e.g. `"dapp"`, `"statistics"`.
* @returns {object}
*/
public static getConfig(section: string): object {
switch (section) {
case "assets":
return assetsConfigLoader();
case "dapp":
return dappConfigLoader();
case "network":
return networkConfigLoader();
case "oauth":
return oauthConfigLoader();
case "payout":
return payoutConfigLoader();
case "processor":
return processorConfigLoader();
case "security":
return securityConfigLoader();
case "statistics":
return statisticsConfigLoader();
case "social":
return socialConfigLoader();
case "monitoring":
return monitoringConfigLoader();
case "transport":
return transportConfigLoader();
default:
throw new Error(`Cannot find relevant config for section: ${section}`);
}
}

/**
* This static helper method returns all the configuration loaders. This
* method *does not* interpret the content of configuration objects.
Expand Down Expand Up @@ -431,6 +470,13 @@ export class AppConfiguration {
defaults: {
from: mailConfig.from,
},
template: {
dir: __dirname + "/notifier/templates/",
adapter: new HandlebarsAdapter(), // or new PugAdapter()
options: {
strict: true,
},
},
};
},
inject: [ConfigService],
Expand Down
3 changes: 2 additions & 1 deletion runtime/backend/src/common/Schedulers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { UserAggregationCommand } from "../statistics/schedulers/UserAggregation
import { UserTopActivitiesCommand } from "../statistics/schedulers/UserTopActivities/UserTopActivitiesCommand";

// notifier scope
import { AlertsModule } from "../notifier/modules/AlertsModule";
import { ReportNotifierCommand } from "../notifier/schedulers/ReportNotifier/ReportNotifierCommand";

/**
Expand Down Expand Up @@ -102,7 +103,7 @@ export const Schedulers: { [key: string]: any[] } = {
UserAggregationCommand,
UserTopActivitiesCommand,
],
notifier: [ReportNotifierCommand.register()],
notifier: [AlertsModule, ReportNotifierCommand.register()],
oauth: [],
users: [],
};
2 changes: 1 addition & 1 deletion runtime/backend/src/common/concerns/Countable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export interface Countable {
*
* @var {number}
*/
total: number;
total?: number;
}
1 change: 0 additions & 1 deletion runtime/backend/src/common/models/AccountDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { BaseDTO } from "./BaseDTO";
* This class shall be used in **HTTP responses** to avoid any additional
* data about accounts to be revealed.
*
* @todo The transaction timestamp in `firstTransactionAt` should probably be a **number** to avoid timezone issues.
* @since v0.1.0
*/
export class AccountDTO extends BaseDTO {
Expand Down
1 change: 0 additions & 1 deletion runtime/backend/src/common/models/BaseDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* This class shall be used in **HTTP responses** to avoid any additional
* data about accounts to be revealed.
*
* @todo Currently this is using a "to any"-cast trick that should be avoided.
* @since v0.3.0
*/
export class BaseDTO {
Expand Down
1 change: 0 additions & 1 deletion runtime/backend/src/common/models/DappConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export type AppConnectionPayload = {
* This interface is mainly used **internally** to restrict the configuration
* values provided to some modules or services and methods.
*
* @todo Allow for updated discovery sources configuration (must be backwards compatible).
* @link DappConfig
* @since v0.1.0
*/
Expand Down
17 changes: 17 additions & 0 deletions runtime/backend/src/common/models/PaginatedResultDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,21 @@ export class PaginatedResultDTO<TData> {
(this.pagination.total ?? 0)
);
}

/**
* Method to dynamically create and return an instance of this class
* with the provided data type, data content and pagination content.
*
* @access public
* @static
* @param {TData[]} data The results returned by the query in an array of template type `TData`.
* @param {Pageable & Countable} pagination The pagination object, contains properties such as `pageSize`, `pageNumber` and `total`.
* @returns {PaginatedResultDTO<TData>}
*/
public static create<TData>(
data: TData[],
pagination: Pageable & Countable,
): PaginatedResultDTO<TData> {
return new PaginatedResultDTO<TData>(data, pagination);
}
}
18 changes: 7 additions & 11 deletions runtime/backend/src/common/models/StateDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import { ApiProperty } from "@nestjs/swagger";

// internal dependencies
import { StateData } from "./StateData";
import { BaseDTO } from "./BaseDTO";

/**
Expand Down Expand Up @@ -47,22 +46,19 @@ export class StateDTO extends BaseDTO {
public name: string;

/**
* Contains the actual state cache data. This field is usually
* populated or updated within a service class.
* Contains the actual state cache data's hash.
* <br /><br />
* This field can hold **any** type of information as it extends
* the `Record<string, any>` type to permit greater flexibility
* around state cache entries.
* The content is hashed with SHA3-256 to prevent revealing actual
* state data to the client.
*
* @todo We probably don't want this data to be as public, instead should be the "cache hash".
* @access public
* @var {string}
*/
@ApiProperty({
type: Object,
example: { stateKey1: 1, stateKey2: "value2", stateKey3: true },
type: "string",
example: "",
description:
"Contains the actual state cache data. This field is usually populated or updated within a service class.",
"Contains the actual state cache data's hash. The content is hashed with SHA3-256 to prevent revealing actual state data to the client.",
})
public data: StateData;
public data: string;
}
4 changes: 3 additions & 1 deletion runtime/backend/src/common/models/StateSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// external dependencies
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { Model } from "mongoose";
import { sha3_256 } from "js-sha3";

// internal dependencies
import { Documentable } from "../concerns/Documentable";
Expand Down Expand Up @@ -134,7 +135,8 @@ export class State extends Transferable<StateDTO> {
*/
public static fillDTO(doc: StateDocument, dto: StateDTO): StateDTO {
dto.name = doc.name;
dto.data = doc.data;
// hash the actual state data in the dto to prevent its exposure to the client.
dto.data = sha3_256(JSON.stringify(doc.data));
return dto;
}
}
Expand Down
37 changes: 34 additions & 3 deletions runtime/backend/src/common/models/TransactionSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
*/
// external dependencies
import {
Convert,
NetworkType,
Transaction as SdkTransaction,
TransactionMapping,
TransactionType,
} from "@dhealth/sdk";
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { Model } from "mongoose";
Expand All @@ -32,7 +35,6 @@ import { TransactionDTO } from "../../discovery/models/TransactionDTO";
* Note that this class uses the generic {@link Transferable} trait to
* enable a `toDTO()` method on the model.
*
* @todo Timestamp fields should be **numbers** to avoid timezone issues.
* @since v0.2.0
*/
@Schema({
Expand Down Expand Up @@ -325,8 +327,37 @@ export class Transaction extends Transferable<TransactionDTO> {
* @returns {SdkTransaction} The `SdkTransaction` object with payload set.
*/
public toSDK(): SdkTransaction {
//XXX this assumes "encodedBody" contains the *full* payload.
return TransactionMapping.createFromPayload(this.encodedBody, false); // false for `isEmbedded`
const sizeBytes = Convert.numberToUint8Array(
(this.encodedBody.length + 256) / 2,
4,
);
const verifiableEntityHeader_Reserved4Bytes = Convert.numberToUint8Array(
0,
4,
);
const signatureBytes = Convert.hexToUint8(this.signature);
const signerPublicKeyBytes = Convert.hexToUint8(this.signerPublicKey);
const entityBody_Reserved4Bytes = Convert.numberToUint8Array(0, 4);
const versionBytes = Convert.numberToUint8Array(0, 1);
const networkBytes = Convert.numberToUint8Array(NetworkType.MAIN_NET, 1);
const typeBytes = Convert.numberToUint8Array(TransactionType.TRANSFER, 2);
const feeBytes = Convert.numberToUint8Array(0, 8);
const deadlineBytes = Convert.numberToUint8Array(0, 8);
const headersUint8Array = [
...sizeBytes,
...verifiableEntityHeader_Reserved4Bytes,
...signatureBytes,
...signerPublicKeyBytes,
...entityBody_Reserved4Bytes,
...versionBytes,
...networkBytes,
...typeBytes,
...feeBytes,
...deadlineBytes,
];
const fullEncodedBody =
Convert.uint8ToHex(headersUint8Array) + this.encodedBody;
return TransactionMapping.createFromPayload(fullEncodedBody, false); // false for `isEmbedded`
}

/**
Expand Down
3 changes: 2 additions & 1 deletion runtime/backend/src/common/modules/AuthModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { QueryModule } from "../modules/QueryModule";
import { LogModule } from "../modules/LogModule";
import { AuthService } from "../services/AuthService";
import { AuthStrategy } from "../traits/AuthStrategy";
import { RefreshStrategy } from "../traits/RefreshStrategy";
import { AuthController } from "../routes/AuthController";
import { ValidateChallengeScheduler } from "../schedulers/ValidateChallengeScheduler";
import {
Expand All @@ -41,7 +42,6 @@ import { AuthGateway } from "../gateways/AuthGateway";

// configuration resources
import securityConfigLoader from "../../../config/security";
import { RefreshStrategy } from "../traits";
const auth = securityConfigLoader().auth;

/**
Expand Down Expand Up @@ -82,6 +82,7 @@ const auth = securityConfigLoader().auth;
AuthGateway,
ValidateChallengeScheduler,
SchedulerRegistry,
RefreshStrategy,
],
exports: [AuthService, CipherService],
})
Expand Down
4 changes: 0 additions & 4 deletions runtime/backend/src/common/modules/LogModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import { QueryModule } from "../modules/QueryModule";
import { Log, LogSchema } from "../models/LogSchema";
import { LogService } from "../services/LogService";

// @todo decouple from notifier scope
import { AlertsModule } from "../../notifier/modules/AlertsModule";

/**
* @class LogModule
* @description The main definition for the Log module.
Expand All @@ -33,7 +30,6 @@ import { AlertsModule } from "../../notifier/modules/AlertsModule";
schema: LogSchema,
}, // requirement from LogModule
]),
AlertsModule,
QueryModule, // requirement from LogService
],
providers: [LogService],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ import { ConfigService } from "@nestjs/config";
// internal dependencies
import { AccessTokenRequest } from "../requests/AccessTokenRequest";
import { AccountsService } from "../services/AccountsService";
import {
Account,
AccountDocument,
AccountQuery,
} from "../models/AccountSchema";
import { AuthService } from "../services/AuthService";
import { LogService } from "../services/LogService";
import { OnAuthCompleted } from "../events/OnAuthCompleted";
Expand Down
12 changes: 8 additions & 4 deletions runtime/backend/src/common/services/AccountsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import {
} from "../models/AccountSchema";

// configuration resources
import dappConfigLoader from "../../../config/dapp";
import networkConfigLoader from "../../../config/network";
import { DappConfig, NetworkConfig } from "../models";
import { AppConfiguration } from "../../AppConfiguration";

/**
* @class AccountsService
Expand Down Expand Up @@ -218,7 +218,9 @@ export class AccountsService {
*/
public static createAddress(publicKeyOrAddress: string): Address {
// extracts the network type from configuration
const { networkIdentifier } = networkConfigLoader().network;
const { networkIdentifier } = (
AppConfiguration.getConfig("network") as NetworkConfig
).network;
const networkType = networkIdentifier as NetworkType;

// if we have a public key (64 characters in hexadecimal format)
Expand All @@ -238,7 +240,9 @@ export class AccountsService {

// source input is **not** a valid address, return fallback
if (sourceAddress.length !== 39) {
return AccountsService.createAddress(dappConfigLoader().dappPublicKey);
return AccountsService.createAddress(
(AppConfiguration.getConfig("dapp") as DappConfig).dappPublicKey,
);
}

// source input **is a valid address format**
Expand Down
Loading