Compare commits
9 Commits
1.3.0
...
alarmas-ob
| Author | SHA1 | Date | |
|---|---|---|---|
| 7c2e86779a | |||
| 1780cf1743 | |||
| 10104c202f | |||
| 1b6da651a6 | |||
| 9b305f887f | |||
| 9506b9e28e | |||
| 61c0edca07 | |||
| 9470b5605d | |||
| ef8222ae30 |
1
packages/sim-alarmas-objenious/.env
Normal file
1
packages/sim-alarmas-objenious/.env
Normal file
@@ -0,0 +1 @@
|
||||
PORT=3001
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Request, Response } from "express"
|
||||
|
||||
export class AlarmsController {
|
||||
constructor() {
|
||||
// Alarm usecases
|
||||
}
|
||||
|
||||
public recibe() {
|
||||
return (req: Request, res: Response) => {
|
||||
const body = req.body()
|
||||
const header = req.headers
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
14
packages/sim-alarmas-objenious/aplication/Alarms.usecases.ts
Normal file
14
packages/sim-alarmas-objenious/aplication/Alarms.usecases.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { PgClient } from "sim-shared/infrastructure/PgClient.js";
|
||||
|
||||
export class AlarmUsecases {
|
||||
constructor(
|
||||
private alarmRepository: any
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public saveAlarm() {
|
||||
|
||||
}
|
||||
}
|
||||
23
packages/sim-alarmas-objenious/config/env/index.ts
vendored
Normal file
23
packages/sim-alarmas-objenious/config/env/index.ts
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { loadEnvFile } from "node:process";
|
||||
loadEnvFile("../../.env")
|
||||
|
||||
export const env = {
|
||||
PORT: Number(process.env.PORT),
|
||||
ENVIRONMENT: process.env.ENVIORMENT,
|
||||
POSTGRES_USER: process.env.POSTGRES_USER,
|
||||
POSTGRES_PASSWORD: process.env.POSTGRES_PASSWORD,
|
||||
POSTGRES_PORT: process.env.POSTGRES_PORT,
|
||||
POSTGRES_HOST: process.env.POSTGRES_HOST,
|
||||
POSTGRES_DATABASE: process.env.POSTGRES_DATABASE,
|
||||
RABBITMQ_HOST: String(process.env.RABBITMQ_HOST ?? "localhost"),
|
||||
RABBITMQ_USER: String(process.env.RABBITMQ_USER ?? "test"),
|
||||
RABBITMQ_PASSWORD: String(process.env.RABBITMQ_PASSWORD ?? "test"),
|
||||
RABBITMQ_EXCHANGE: String(process.env.RABBITMQ_EXCHANGE ?? "/"),
|
||||
RABBITMQ_PORT: parseInt(process.env.RABBITMQ_PORT ?? "5672"),
|
||||
RABBITMQ_MODULENAME: process.env.MODULENAME,
|
||||
RABBITMQ_TTL: process.env.RABBITMQ_TTL,
|
||||
RABBITMQ_SECURE: process.env.RABBITMQ_SECURE,
|
||||
RABBITMQ_RETRY_INTERVAL: process.env.RABBITMQ_INTERVAL,
|
||||
RABBITMQ_VHOST: String(process.env.RABBITMQ_VHOST),
|
||||
};
|
||||
|
||||
18
packages/sim-alarmas-objenious/config/postgreConfig.ts
Normal file
18
packages/sim-alarmas-objenious/config/postgreConfig.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Pool } from 'pg';
|
||||
import { PgClient } from 'sim-shared/infrastructure/PgClient.js'
|
||||
import { env } from './env/index.js';
|
||||
|
||||
// Configuracion de la conexion a la BDD, deberia ser la
|
||||
// Misma para todos los servicios pero hasta que se unifique todo
|
||||
// se hace una por servicio.
|
||||
export const pgPool = new Pool({
|
||||
user: env.POSTGRES_USER,
|
||||
host: env.POSTGRES_HOST,
|
||||
database: env.POSTGRES_DATABASE,
|
||||
password: env.POSTGRES_PASSWORD,
|
||||
port: Number(env.POSTGRES_PORT) || 5432,
|
||||
});
|
||||
|
||||
export const postgresClient = new PgClient({
|
||||
pool: pgPool
|
||||
})
|
||||
62
packages/sim-alarmas-objenious/domain/alarmTypes.ts
Normal file
62
packages/sim-alarmas-objenious/domain/alarmTypes.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
export type ObjeniousAlarmType =
|
||||
"PLMN_CHANGE" |
|
||||
"COUNTRY_CHANGE" |
|
||||
"OVER_CONSUMPTION_VOLUME" |
|
||||
"UNDER_CONSUMPTION_VOLUME" |
|
||||
"IMEI_CHANGE" |
|
||||
"OVER_CONSUMPTION_VOLUME" |
|
||||
string
|
||||
|
||||
export type ObjeniousAlarm = {
|
||||
alarmId: Number,
|
||||
emissionDate: Date //"07/02/2019 14:44:00"
|
||||
alarmType: ObjeniousAlarmType,
|
||||
lineInfos: {
|
||||
msisdn: string,
|
||||
iccid: string
|
||||
},
|
||||
change?: ObjeniousChangeTypes,
|
||||
usage?: ObjeniousUsageTypes
|
||||
}
|
||||
|
||||
export type ObjeniousChangeTypes = ChangePayload | ImeiChangePayload;
|
||||
export type ObjeniousUsageTypes = UsageAlarmPayload | OverConsumptionPayload;
|
||||
|
||||
/**
|
||||
* PLMN_CHANGE
|
||||
* COUNTRY_CHANGE
|
||||
* STATUS_CHANGE
|
||||
* */
|
||||
export type ChangePayload = {
|
||||
previous: string,
|
||||
current: string
|
||||
}
|
||||
|
||||
/**
|
||||
* IMEI_CHANGE
|
||||
*/
|
||||
export type ImeiChangePayload = {
|
||||
previous: string,//"42947662490276",
|
||||
current: string, //"74845559130697",
|
||||
previousManufacturer: string, //"u-blox AG",
|
||||
currentManufacturer: string, //"SierraWireless"
|
||||
}
|
||||
|
||||
/**
|
||||
* OVER_CONSUMPTION_VOLUME
|
||||
* UNDER_CONSUMPTION_VOLUME
|
||||
*/
|
||||
export type UsageAlarmPayload = {
|
||||
type: string,
|
||||
threshold: string,
|
||||
trigerValue: string
|
||||
}
|
||||
|
||||
/**
|
||||
* OVER_CONSUMPTION_VOLUME
|
||||
*/
|
||||
export type OverConsumptionPayload = {
|
||||
type: string, //"data-sms-smsIN-voiceOUT",
|
||||
threshold: string, // "500-200-100-10",
|
||||
triggerValue: string, // "600-300-101-15"
|
||||
}
|
||||
29
packages/sim-alarmas-objenious/index.ts
Normal file
29
packages/sim-alarmas-objenious/index.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import express from "express"
|
||||
import cors from 'cors';
|
||||
import { env } from "#config/env/index.js"
|
||||
import { AlarmsController } from "aplication/Alarms.controller";
|
||||
|
||||
const PORT = env.PORT
|
||||
const HOSTNAME = "0.0.0.0"
|
||||
const app = express()
|
||||
|
||||
// Instancias
|
||||
const alarmsController = new AlarmsController();
|
||||
|
||||
// Middleware
|
||||
app.use(cors());
|
||||
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
app.use("/fr/alarms", alarmsController.recibe())
|
||||
|
||||
app.get("/health", (req, res) => {
|
||||
res.status(200).json({ status: "ok" })
|
||||
})
|
||||
|
||||
app.listen(PORT, HOSTNAME, () => {
|
||||
console.log("[o] Servidor iniciado en el puerto %d", PORT)
|
||||
})
|
||||
|
||||
export default {}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { PgClient } from "sim-shared/infrastructure/PgClient.js";
|
||||
|
||||
export class AlarmsRepository {
|
||||
constructor(private pgClient: PgClient) {
|
||||
}
|
||||
|
||||
public createAlarm() {
|
||||
|
||||
}
|
||||
}
|
||||
76
packages/sim-alarmas-objenious/package.json
Normal file
76
packages/sim-alarmas-objenious/package.json
Normal file
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"name": "sim-alarmas-objenious",
|
||||
"version": "1.0.0",
|
||||
"description": "Recibe las alarmas de los webhook de objenious",
|
||||
"main": "index.ts",
|
||||
"scripts": {
|
||||
"test": "node --import tsx --test ./**/*.test.ts",
|
||||
"build": "tsc --build && tsc-alias -p tsconfig.json && cp package.json ../../dist/packages/sim-alarmas-objenious/",
|
||||
"dev": "tsx watch index.ts",
|
||||
"start": "node ../../dist/packages/sim-alarmas-objenious/index.js"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"packageManager": "yarn@4.12.0",
|
||||
"imports": {
|
||||
"#config/*.js": {
|
||||
"types": "./config/*.ts",
|
||||
"default": "./config/*.js"
|
||||
},
|
||||
"#config/*": {
|
||||
"types": "./config/*.ts",
|
||||
"default": "./config/*.js"
|
||||
},
|
||||
"#adapters/*.js": {
|
||||
"types": "./adapters/*.ts",
|
||||
"default": "./adapters/*.js"
|
||||
},
|
||||
"#adapters/*": {
|
||||
"types": "./adapters/*.ts",
|
||||
"default": "./adapters/*.js"
|
||||
},
|
||||
"#domain/*.js": {
|
||||
"types": "./domain/*.ts",
|
||||
"default": "./domain/*.js"
|
||||
},
|
||||
"#domain/*": {
|
||||
"types": "./domain/*.ts",
|
||||
"default": "./domain/*.js"
|
||||
},
|
||||
"#ports/*.js": {
|
||||
"types": "./ports/*.ts",
|
||||
"default": "./ports/*.js"
|
||||
},
|
||||
"#ports/*": {
|
||||
"types": "./ports/*.ts",
|
||||
"default": "./ports/*.js"
|
||||
},
|
||||
"#tests/*.js": {
|
||||
"types": "./__tests__/*.ts",
|
||||
"default": "./__tests__/*.js"
|
||||
},
|
||||
"#tests/*": {
|
||||
"types": "./__tests__/*.ts",
|
||||
"default": "./__tests__/*.js"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@tsconfig/node22": "*",
|
||||
"amqplib": "^0.10.9",
|
||||
"cors": "*",
|
||||
"dotenv": "*",
|
||||
"express": "*",
|
||||
"typescript": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/amqplib": "^0.10.8",
|
||||
"@types/cors": "*",
|
||||
"@types/express": "*",
|
||||
"@types/node": "*",
|
||||
"@types/supertest": "*",
|
||||
"prettier": "*",
|
||||
"supertest": "*",
|
||||
"tsx": "*",
|
||||
"vitest": "*"
|
||||
}
|
||||
}
|
||||
17
packages/sim-alarmas-objenious/tsconfig.json
Normal file
17
packages/sim-alarmas-objenious/tsconfig.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../dist",
|
||||
"baseUrl": ".",
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
],
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
"src/**/*.d.ts"
|
||||
],
|
||||
"files": [
|
||||
"index.ts"
|
||||
]
|
||||
}
|
||||
@@ -7,6 +7,6 @@ OBJ_KID=xNfbMiyL1ORXGP8lElhcv8nVaG3EJKye4Lc1YoN3I1E
|
||||
OBJ_BASE_URL=https://api-getway.objenious.com/ws
|
||||
# OBJ_BASE_URL=https://api-getway.objenious.com/ws/test
|
||||
|
||||
# NOTIFICATION_URL="https://sf-sim-activation.savefamilygps.net/send-activation-mail"
|
||||
NOTIFICATION_URL="localhost"
|
||||
NOTIFICATION_URL="https://sf-sim-activation.savefamilygps.net/send-activation-mail"
|
||||
# NOTIFICATION_URL="localhost"
|
||||
SIM_ACTIVATION_API_KEY=9e48c4ac-1ab0-4397-b3f3-6c239200dfe6
|
||||
|
||||
10
packages/sim-objenious-cron/config/env/index.ts
vendored
10
packages/sim-objenious-cron/config/env/index.ts
vendored
@@ -31,15 +31,15 @@ export const env = {
|
||||
OBJ_KID: String(process.env.OBJ_KID),
|
||||
OBJ_BASE_URL: String(process.env.OBJ_BASE_URL),
|
||||
|
||||
NOTIFICATION_URL: String(process.env.NOTIFICATION_URL),
|
||||
SIM_ACTIVATION_API_KEY: String(process.env.SIM_ACTIVATION_API_KEY)
|
||||
NOTIFICATION_URL: String(process.env.NOTIFICATION_URL ?? ""),
|
||||
SIM_ACTIVATION_API_KEY: String(process.env.SIM_ACTIVATION_API_KEY ?? "")
|
||||
};
|
||||
|
||||
// assert las partes criticas
|
||||
assert(env.RABBITMQ_PASSWORD != undefined)
|
||||
assert(env.RABBITMQ_USER != undefined)
|
||||
assert(env.SIM_ACTIVATION_API_KEY != undefined)
|
||||
assert(env.NOTIFICATION_URL != undefined)
|
||||
assert(env.SIM_ACTIVATION_API_KEY != "")
|
||||
assert(env.NOTIFICATION_URL != "")
|
||||
|
||||
if (env.ENVIRONMENT == "production") {
|
||||
assert(env.RABBITMQ_PASSWORD != "guest")
|
||||
@@ -47,3 +47,5 @@ if (env.ENVIRONMENT == "production") {
|
||||
}
|
||||
|
||||
|
||||
console.log("[i] verificado env")
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ async function startCron() {
|
||||
|
||||
const volcadoLineasTask = new TaskVolcadoLineas(httpClient, objeniousLineRepository)
|
||||
|
||||
const PERIODO_PETICIONES = 10 * 60 * 60
|
||||
const PERIODO_PETICIONES = 10 * 60 * 1000
|
||||
const interval = setInterval(async () => {
|
||||
try {
|
||||
await objTask.getPendingOperations()
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node --import tsx --test ./**/*.test.ts",
|
||||
"build": "tsc --build && tsc-alias -p tsconfig.json && cp package.json ../../dist/packages/sim-objenious-cron/",
|
||||
"build": "tsc --build && tsc-alias -p tsconfig.json && cp .env package.json ../../dist/packages/sim-objenious-cron/",
|
||||
"dev": "tsx watch index.ts",
|
||||
"start": "node ../../dist/packages/sim-objenious-cron/index.js"
|
||||
},
|
||||
|
||||
@@ -137,7 +137,7 @@ export class CheckObjeniousRequests {
|
||||
})
|
||||
}
|
||||
|
||||
if (originalAction.operation == "activation") {
|
||||
if (originalAction.operation == "activate") {
|
||||
this.notifyFinalization({
|
||||
...originalAction,
|
||||
msisdn
|
||||
@@ -300,6 +300,8 @@ export class CheckObjeniousRequests {
|
||||
* al servicio que manda los mails
|
||||
*/
|
||||
private async notifyFinalization(operation: ObjeniousOperation & { msisdn: string }) {
|
||||
console.log("[i] Enviando activacion a", env.NOTIFICATION_URL)
|
||||
console.log("[i] Operation", operation)
|
||||
const req = axios.post(env.NOTIFICATION_URL, {
|
||||
...operation,
|
||||
iccids: [operation.iccids]
|
||||
|
||||
@@ -12,7 +12,7 @@ export type ObjeniousOperation = {
|
||||
id?: number;
|
||||
/** Uuid del mensaje asociado a la operacion */
|
||||
correlation_id?: string;
|
||||
operation: string;
|
||||
operation: "activate" | string; // TODO: completar y actualizar
|
||||
retry_count?: number;
|
||||
max_retry?: number;
|
||||
max_date_retry?: string | null;
|
||||
|
||||
Reference in New Issue
Block a user