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

refactor(mojaloop/#2883): move repo code out of command module and into shared lib #358

Merged
merged 14 commits into from
Sep 2, 2022
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
24 changes: 12 additions & 12 deletions modules/api-svc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
},
"dependencies": {
"@koa/cors": "^3.4.1",
"@mojaloop/api-snippets": "^14.2.3",
"@mojaloop/api-snippets": "^14.2.4",
"@mojaloop/central-services-error-handling": "^12.0.4",
"@mojaloop/central-services-logger": "^11.0.1",
"@mojaloop/central-services-metrics": "^12.0.5",
Expand All @@ -70,8 +70,8 @@
"ajv": "8.11.0",
"axios": "^0.27.2",
"co-body": "^6.1.0",
"dotenv": "^16.0.1",
"env-var": "^7.1.1",
"dotenv": "^16.0.2",
"env-var": "^7.2.0",
"express": "^4.18.1",
"fast-json-patch": "^3.1.1",
"javascript-state-machine": "^3.1.0",
Expand All @@ -82,7 +82,7 @@
"lodash": "^4.17.21",
"module-alias": "^2.2.2",
"oauth2-server": "^4.0.0-dev.2",
"openapi-jsonschema-parameters": "^12.0.0",
"openapi-jsonschema-parameters": "^12.0.2",
"prom-client": "^14.1.0",
"promise-timeout": "^1.3.0",
"random-word-slugs": "^0.1.6",
Expand All @@ -94,17 +94,17 @@
"@babel/core": "^7.18.13",
"@babel/preset-env": "^7.18.10",
"@redocly/openapi-cli": "^1.0.0-beta.94",
"@types/jest": "^28.1.8",
"babel-jest": "^28.1.3",
"eslint": "^8.22.0",
"@types/jest": "^29.0.0",
"babel-jest": "^29.0.1",
"eslint": "^8.23.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.8.7",
"jest": "^28.1.3",
"jest-junit": "^14.0.0",
"eslint-plugin-jest": "^27.0.1",
"jest": "^29.0.1",
"jest-junit": "^14.0.1",
"nock": "^13.2.9",
"npm-check-updates": "^16.0.5",
"openapi-response-validator": "^12.0.0",
"npm-check-updates": "^16.0.6",
"openapi-response-validator": "^12.0.2",
"openapi-typescript": "^5.4.1",
"redis-mock": "^0.56.3",
"replace": "^1.2.1",
Expand Down
20 changes: 10 additions & 10 deletions modules/outbound-command-event-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,39 @@
"snapshot": "standard-version --no-verify --skip.changelog --prerelease snapshot --releaseCommitMessageFormat 'chore(snapshot): {{currentTag}}'"
},
"dependencies": {
"@mojaloop/api-snippets": "^14.2.3",
"@mojaloop/api-snippets": "^14.2.4",
"@mojaloop/logging-bc-client-lib": "^0.1.12",
"@mojaloop/logging-bc-public-types-lib": "^0.1.9",
"@mojaloop/sdk-scheme-adapter-private-shared-lib": "workspace:^",
"ajv": "^8.11.0",
"convict": "^6.2.3",
"express": "^4.18.1",
"openapi-backend": "^5.3.0",
"openapi-backend": "^5.5.0",
"redis": "^4.3.0",
"swagger-ui-express": "^4.5.0",
"yamljs": "^0.3.0"
},
"devDependencies": {
"@types/convict": "^6.1.1",
"@types/express": "^4.17.13",
"@types/jest": "^28.1.8",
"@types/node": "^18.7.13",
"@types/jest": "^29.0.0",
"@types/node": "^18.7.14",
"@types/node-cache": "^4.2.5",
"@types/supertest": "^2.0.12",
"@types/swagger-ui-express": "^4.1.3",
"@types/yamljs": "^0.2.31",
"@typescript-eslint/eslint-plugin": "^5.35.1",
"@typescript-eslint/parser": "^5.35.1",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"copyfiles": "^2.4.1",
"eslint": "^8.22.0",
"jest": "^28.1.3",
"eslint": "^8.23.0",
"jest": "^29.0.1",
"nodemon": "^2.0.19",
"npm-check-updates": "^16.0.5",
"npm-check-updates": "^16.0.6",
"replace": "^1.2.1",
"standard-version": "^9.5.0",
"ts-jest": "^28.0.8",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
"typescript": "^4.8.2"
},
"nodemonConfig": {
"watch": [
Expand Down
12 changes: 6 additions & 6 deletions modules/outbound-command-event-handler/src/api-server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ import type { Request } from 'openapi-backend';
import swaggerUi from 'swagger-ui-express';
import YAML from 'yamljs';
import Handlers from './handlers';
import { IBulkTransactionEntityRepo } from '../types';
import { IBulkTransactionEntityRepo } from '@mojaloop/sdk-scheme-adapter-private-shared-lib';

export interface IAPIServerOptions {
bulkTransactionEntityRepo: IBulkTransactionEntityRepo;
logger: ILogger;
}

export const CreateExpressServer =
export const CreateExpressServer =
async (
openApiSpecFilePath: string,
options: IAPIServerOptions,
Expand All @@ -54,15 +54,15 @@ export const CreateExpressServer =
},
}),
);

// API middle-wares
// To parse Json in the payload
app.use(Express.json());

// Pass repo to context
app.set('bulkTransactionRepo', options.bulkTransactionEntityRepo);
app.set('logger', options.logger);

// API routes based on the swagger file
const api = new OpenAPIBackend({
definition: openApiSpecFilePath,
Expand All @@ -73,9 +73,9 @@ export const CreateExpressServer =
notFound: async (_c, _req: Express.Request, res: Express.Response) => res.status(404).json({ err: 'not found' }),
},
});

api.init();

// Passing the openAPI object as express middle-ware
app.use((req, res) => api.handleRequest(req as Request, req, res));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { ILogger } from '@mojaloop/logging-bc-public-types-lib';
import { Server } from 'http';
import { CreateExpressServer } from './app';
import path from 'path';
import { IBulkTransactionEntityRepo } from '../types';
import { IBulkTransactionEntityRepo } from '@mojaloop/sdk-scheme-adapter-private-shared-lib';
import { Application } from 'express';


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import { BulkTransaction } from '../models';
import { ILogger } from '@mojaloop/logging-bc-public-types-lib';
import { RedisBulkTransactionStateRepo } from '../../infrastructure/redis_bulk_transaction_repo';
import { RedisBulkTransactionStateRepo } from '@mojaloop/sdk-scheme-adapter-private-shared-lib';
export class BulkTransactionsService {

private _repo: RedisBulkTransactionStateRepo;
Expand Down Expand Up @@ -57,4 +57,4 @@ export class BulkTransactionsService {
return bulkTransactions;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

'use strict';

import { BulkTransactionAgg } from '@module-domain';
import { ILogger } from '@mojaloop/logging-bc-public-types-lib';
import {
IRunHandler,
Expand All @@ -38,11 +39,10 @@ import {
ProcessSDKOutboundBulkPartyInfoRequestCmdEvt,
ProcessPartyInfoCallbackCmdEvt,
ProcessSDKOutboundBulkPartyInfoRequestCompleteCmdEvt,
IBulkTransactionEntityRepo,
} from '@mojaloop/sdk-scheme-adapter-private-shared-lib';
import { ICommandEventHandlerOptions } from '@module-types';

import { IBulkTransactionEntityRepo, ICommandEventHandlerOptions } from '../types';

import { BulkTransactionAgg } from '../domain';

export interface IOutboundEventHandlerOptions {
bulkTransactionEntityRepo: IBulkTransactionEntityRepo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@
import { DefaultLogger } from '@mojaloop/logging-bc-client-lib';
import { ILogger, LogLevel } from '@mojaloop/logging-bc-public-types-lib';

import { IRunHandler, BC_CONFIG } from '@mojaloop/sdk-scheme-adapter-private-shared-lib';
import { IRunHandler, BC_CONFIG, IRedisBulkTransactionStateRepoOptions, RedisBulkTransactionStateRepo } from '@mojaloop/sdk-scheme-adapter-private-shared-lib';
import { IOutboundEventHandlerOptions, OutboundEventHandler } from './handler';
import { IOutboundCommandEventHandlerAPIServerOptions, OutboundCommandEventHandlerAPIServer } from '../api-server';
import Config from '../shared/config';
import { IRedisBulkTransactionStateRepoOptions, RedisBulkTransactionStateRepo } from '../infrastructure';

(async () => {
// Instantiate logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@
'use strict';

import { ILogger } from '@mojaloop/logging-bc-public-types-lib';
import { CommandEvent, ProcessPartyInfoCallbackCmdEvt, PartyInfoCallbackProcessedDmEvt, IPartyResult } from '@mojaloop/sdk-scheme-adapter-private-shared-lib';
import {
CommandEvent,
IndividualTransferInternalState,
ProcessPartyInfoCallbackCmdEvt,
PartyInfoCallbackProcessedDmEvt,
IPartyResult,
} from '@mojaloop/sdk-scheme-adapter-private-shared-lib';
import { BulkTransactionAgg } from '..';
import { ICommandEventHandlerOptions } from '@module-types';
import { IndividualTransferInternalState } from '../..';

export async function handleProcessPartyInfoCallbackCmdEvt(
message: CommandEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@

import { ILogger } from '@mojaloop/logging-bc-public-types-lib';
import {
BulkTransactionInternalState,
CommandEvent,
IndividualTransferInternalState,
ProcessSDKOutboundBulkPartyInfoRequestCmdEvt,
PartyInfoRequestedDmEvt,
} from '@mojaloop/sdk-scheme-adapter-private-shared-lib';
import { BulkTransactionAgg } from '..';
import { ICommandEventHandlerOptions } from '@module-types';
import { BulkTransactionInternalState } from '../..';
import { IndividualTransferInternalState } from '../..';


export async function handleProcessSDKOutboundBulkPartyInfoRequestCmdEvt(
message: CommandEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

import { ILogger } from '@mojaloop/logging-bc-public-types-lib';
import {
BulkTransactionInternalState,
CommandEvent,
ProcessSDKOutboundBulkPartyInfoRequestCompleteCmdEvt,
SDKOutboundBulkAcceptPartyInfoRequestedDmEvt,
SDKOutboundBulkAutoAcceptPartyInfoRequestedDmEvt,
} from '@mojaloop/sdk-scheme-adapter-private-shared-lib';
import { BulkTransactionAgg } from '..';
import { ICommandEventHandlerOptions } from '@module-types';
import { BulkTransactionInternalState } from '../..';


export async function handleProcessSDKOutboundBulkPartyInfoRequestCompleteCmdEvt(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
'use strict';

import { ILogger } from '@mojaloop/logging-bc-public-types-lib';
import { CommandEvent, ProcessSDKOutboundBulkRequestCmdEvt, SDKOutboundBulkPartyInfoRequestedDmEvt } from '@mojaloop/sdk-scheme-adapter-private-shared-lib';
import {
CommandEvent,
ProcessSDKOutboundBulkRequestCmdEvt,
SDKOutboundBulkPartyInfoRequestedDmEvt,
} from '@mojaloop/sdk-scheme-adapter-private-shared-lib';
import { BulkTransactionAgg } from '..';
import { ICommandEventHandlerOptions } from '@module-types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@
'use strict';

import { ILogger } from '@mojaloop/logging-bc-public-types-lib';
import { BaseAggregate, CommandEvent, IEntityStateRepository } from '@mojaloop/sdk-scheme-adapter-private-shared-lib';
import { BulkTransactionEntity, BulkTransactionState } from '../bulk_transaction_entity';
import {
BaseAggregate,
BulkTransactionEntity,
BulkTransactionState,
CommandEvent,
IBulkTransactionEntityRepo,
IEntityStateRepository,
IndividualTransferEntity,
IndividualTransferState,
} from '../individual_transfer_entity';
import { IBulkTransactionEntityRepo, ICommandEventHandlerOptions } from '@module-types';
} from '@mojaloop/sdk-scheme-adapter-private-shared-lib';
import { SDKSchemeAdapter } from '@mojaloop/api-snippets';

import CommandEventHandlerFuntions from './handlers';

import CommandEventHandlerFunctions from './handlers';
import { ICommandEventHandlerOptions } from '@module-types';

export class BulkTransactionAgg extends BaseAggregate<BulkTransactionEntity, BulkTransactionState> {
// TODO: These counts can be part of bulk transaction entity?
Expand Down Expand Up @@ -175,11 +178,11 @@ export class BulkTransactionAgg extends BaseAggregate<BulkTransactionEntity, Bul
logger: ILogger,
) {
const handlerPrefix = 'handle';
if(!CommandEventHandlerFuntions.hasOwnProperty(handlerPrefix + message.constructor.name)) {
if(!CommandEventHandlerFunctions.hasOwnProperty(handlerPrefix + message.constructor.name)) {
logger.error(`Handler function for the command event message ${message.constructor.name} is not implemented`);
return;
}
await CommandEventHandlerFuntions[handlerPrefix + message.constructor.name](
await CommandEventHandlerFunctions[handlerPrefix + message.constructor.name](
message,
options,
logger,
Expand Down
2 changes: 0 additions & 2 deletions modules/outbound-command-event-handler/src/domain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@
******/

export * from './bulk_transaction_agg';
export * from './bulk_transaction_entity';
export * from './individual_transfer_entity';

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
******/

'use strict';
import { IDomainEventProducer } from '@mojaloop/sdk-scheme-adapter-private-shared-lib';
import { IBulkTransactionEntityRepo } from './bulk_transaction_entity_repo';
import { IBulkTransactionEntityRepo, IDomainEventProducer } from '@mojaloop/sdk-scheme-adapter-private-shared-lib';

export type ICommandEventHandlerOptions = {
bulkTransactionEntityRepo: IBulkTransactionEntityRepo
Expand Down
3 changes: 1 addition & 2 deletions modules/outbound-command-event-handler/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@
--------------
******/

export * from './bulk_transaction_entity_repo';
export * from './repo_infra_types';
export * from './command_event_handler_options';
export * from './repo_infra_types';
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ import { CommandEvent, ICommandEventData, DomainEvent,
IProcessSDKOutboundBulkRequestCmdEvtData,
IProcessPartyInfoCallbackCmdEvtData,
IProcessSDKOutboundBulkPartyInfoRequestCmdEvtData,
IProcessSDKOutboundBulkPartyInfoRequestCompleteCmdEvtData} from '@mojaloop/sdk-scheme-adapter-private-shared-lib'
IProcessSDKOutboundBulkPartyInfoRequestCompleteCmdEvtData,
RedisBulkTransactionStateRepo,
IRedisBulkTransactionStateRepoOptions,
} from '@mojaloop/sdk-scheme-adapter-private-shared-lib'
import { randomUUID } from "crypto";
import { RedisBulkTransactionStateRepo, IRedisBulkTransactionStateRepoOptions } from '../../../src/infrastructure/redis_bulk_transaction_repo'


const logger: ILogger = new DefaultLogger('bc', 'appName', 'appVersion'); //TODO: parameterize the names here

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
*/
import request from 'supertest';
import { OutboundCommandEventHandlerAPIServer as ApiServer } from '../../../src/api-server';
import {IBulkTransactionEntityRepo} from '../../../src/types';
import { IBulkTransactionEntityRepo } from '@mojaloop/sdk-scheme-adapter-private-shared-lib';
import { DefaultLogger } from "@mojaloop/logging-bc-client-lib";
import {ILogger} from '@mojaloop/logging-bc-public-types-lib';
import {Application} from 'express';
import { ILogger } from '@mojaloop/logging-bc-public-types-lib';
import { Application } from 'express';

const logger: ILogger = new DefaultLogger('bc', 'appName', 'appVersion');

Expand Down
Loading