Compare commits
35 Commits
WEBINT-335
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f7c052572 | |||
| 3d9e2a6e9b | |||
| f94ee799d0 | |||
| d1e5892a0d | |||
| b14464da39 | |||
| cf6204e231 | |||
| 9d8788db39 | |||
| 79ceb74604 | |||
| d02b1d48bf | |||
| 1fb50323b0 | |||
| 985c85da59 | |||
| 23c61097a8 | |||
| 5372045bd7 | |||
| 72d61b8376 | |||
| 526c094494 | |||
| 474f7b7c68 | |||
| f8692e3e2e | |||
| 62715fae34 | |||
| f8678a68bb | |||
| 8f8ae22f23 | |||
| 2611147eb3 | |||
| b0b3badd5c | |||
| 2b812098fb | |||
| 3146efec64 | |||
| 44e4b98e35 | |||
| 6adb4d5c95 | |||
| bcb1a28164 | |||
| d5798602e2 | |||
| 1f94a89520 | |||
| 44bbc8f17c | |||
| 9e6877c329 | |||
| d5883ba75e | |||
| 421d0aa705 | |||
| 69b5958296 | |||
| b9e3e1784f |
@@ -2,10 +2,12 @@ compressionLevel: mixed
|
|||||||
|
|
||||||
enableGlobalCache: false
|
enableGlobalCache: false
|
||||||
|
|
||||||
|
enableScripts: true
|
||||||
|
|
||||||
nodeLinker: node-modules
|
nodeLinker: node-modules
|
||||||
|
|
||||||
|
npmRegistryServer: "https://registry.npmjs.org/"
|
||||||
|
|
||||||
npmScopes:
|
npmScopes:
|
||||||
sf-alvar:
|
sf-alvar:
|
||||||
npmRegistryServer: "https://git.savefamilygps.net/api/packages/SaveFamily/npm/"
|
npmRegistryServer: "https://git.savefamilygps.net/api/packages/SaveFamily/npm/"
|
||||||
|
|
||||||
npmRegistryServer: "https://registry.npmjs.org/"
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ networks:
|
|||||||
external: true
|
external: true
|
||||||
internal:
|
internal:
|
||||||
driver: bridge
|
driver: bridge
|
||||||
|
volumes:
|
||||||
|
rabbitmq_data:
|
||||||
|
|
||||||
services:
|
services:
|
||||||
rabbitmq-sim-broker:
|
rabbitmq-sim-broker:
|
||||||
@@ -28,6 +30,7 @@ services:
|
|||||||
entrypoint: ["bash", "/usr/local/bin/docker-entrypoint-wrapper.sh"]
|
entrypoint: ["bash", "/usr/local/bin/docker-entrypoint-wrapper.sh"]
|
||||||
command: ["rabbitmq-server"]
|
command: ["rabbitmq-server"]
|
||||||
volumes:
|
volumes:
|
||||||
|
- rabbitmq_data:/var/lib/rabbitmq
|
||||||
- ./rabbit/docker-entrypoint-wrapper.sh:/usr/local/bin/docker-entrypoint-wrapper.sh:ro
|
- ./rabbit/docker-entrypoint-wrapper.sh:/usr/local/bin/docker-entrypoint-wrapper.sh:ro
|
||||||
- ./rabbitmq_plugins/enabled_plugins:/etc/rabbitmq/enabled_plugins:ro
|
- ./rabbitmq_plugins/enabled_plugins:/etc/rabbitmq/enabled_plugins:ro
|
||||||
- ./rabbit/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro
|
- ./rabbit/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro
|
||||||
@@ -73,7 +76,9 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./.env:/home/node/app/.env:ro
|
- ./.env:/home/node/app/.env:ro
|
||||||
- ./sim-consumidor-nos.env:/home/node/app/packages/sim-consumidor-nos/.env:ro
|
- ./sim-consumidor-nos.env:/home/node/app/packages/sim-consumidor-nos/.env:ro
|
||||||
|
- ./sim-consumidor-alai.env:/home/node/app/packages/sim-consumidor-alai/.env:ro
|
||||||
- ./sim-consumidor-objenious.env:/home/node/app/packages/sim-consumidor-objenious/.env:ro
|
- ./sim-consumidor-objenious.env:/home/node/app/packages/sim-consumidor-objenious/.env:ro
|
||||||
|
- ./wsaccess_alaisecure_com_cert_client_new.p12:/home/node/app/packages/sim-consumidor-alai/certificates/wsaccess_alaisecure_com_cert_client_new.p12:ro
|
||||||
- ./sim-objenious-cron.env:/home/node/app/packages/sim-objenious-cron/.env:ro
|
- ./sim-objenious-cron.env:/home/node/app/packages/sim-objenious-cron/.env:ro
|
||||||
- ./obj.pem:/home/node/app/packages/sim-consumidor-objenious/obj.pem:ro
|
- ./obj.pem:/home/node/app/packages/sim-consumidor-objenious/obj.pem:ro
|
||||||
- ./obj.pem:/home/node/app/packages/sim-objenious-cron/obj.pem:ro
|
- ./obj.pem:/home/node/app/packages/sim-objenious-cron/obj.pem:ro
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ pipeline {
|
|||||||
stage("🧱 Building") {
|
stage("🧱 Building") {
|
||||||
steps {
|
steps {
|
||||||
sh 'rm -rf dist/'
|
sh 'rm -rf dist/'
|
||||||
sh 'yarn run build'
|
sh 'yarn run build:prod'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage("🏗 Deploying") {
|
stage("🏗 Deploying") {
|
||||||
@@ -40,31 +40,11 @@ pipeline {
|
|||||||
),
|
),
|
||||||
sshTransfer(
|
sshTransfer(
|
||||||
cleanRemote: false,
|
cleanRemote: false,
|
||||||
execCommand: "ln -sf $BASE_REMOTE_PATH/vault/savefamily/sf-sims/.env $APP_REMOTE_PATH/.env"
|
execCommand: "rm -rf $APP_REMOTE_PATH/dist"
|
||||||
),
|
),
|
||||||
sshTransfer(
|
sshTransfer(
|
||||||
cleanRemote: false,
|
cleanRemote: false,
|
||||||
execCommand: "ln -sf $BASE_REMOTE_PATH/vault/savefamily/sf-sims/sim-consumidor-objenious.env $APP_REMOTE_PATH/packages/sim-consumidor-objenious/.env"
|
execCommand: "ls -la $BASE_REMOTE_PATH/vault/savefamily/sf-sims/"
|
||||||
),
|
|
||||||
sshTransfer(
|
|
||||||
cleanRemote: false,
|
|
||||||
execCommand: "ln -sf $BASE_REMOTE_PATH/vault/savefamily/sf-sims/sim-consumidor-nos.env $APP_REMOTE_PATH/packages/sim-consumidor-nos/.env"
|
|
||||||
),
|
|
||||||
sshTransfer(
|
|
||||||
cleanRemote: false,
|
|
||||||
execCommand: "ln -sf $BASE_REMOTE_PATH/vault/savefamily/sf-sims/sim-consumidor-alai.env $APP_REMOTE_PATH/packages/sim-consumidor-alai/.env"
|
|
||||||
),
|
|
||||||
sshTransfer(
|
|
||||||
cleanRemote: false,
|
|
||||||
execCommand: "ln -sf $BASE_REMOTE_PATH/vault/savefamily/sf-sims/wsaccess_alaisecure_com_cert_client_new.p12 $APP_REMOTE_PATH/packages/wsaccess_alaisecure_com_cert_client_new.p12"
|
|
||||||
),
|
|
||||||
sshTransfer(
|
|
||||||
cleanRemote: false,
|
|
||||||
execCommand: "ln -sf $BASE_REMOTE_PATH/vault/savefamily/sf-sims/sim-objenious-cron.env $APP_REMOTE_PATH/packages/sim-objenious-cron/.env"
|
|
||||||
),
|
|
||||||
sshTransfer(
|
|
||||||
cleanRemote: false,
|
|
||||||
execCommand: "ln -sf $BASE_REMOTE_PATH/vault/savefamily/sf-sims/obj.pem $APP_REMOTE_PATH/packages/sim-consumidor-objenious/obj.pem"
|
|
||||||
),
|
),
|
||||||
sshTransfer(
|
sshTransfer(
|
||||||
cleanRemote: false,
|
cleanRemote: false,
|
||||||
@@ -72,6 +52,34 @@ pipeline {
|
|||||||
sourceFiles: "dist/**/*",
|
sourceFiles: "dist/**/*",
|
||||||
excludes: "dist/**/node_modules/**"
|
excludes: "dist/**/node_modules/**"
|
||||||
),
|
),
|
||||||
|
sshTransfer(
|
||||||
|
cleanRemote: false,
|
||||||
|
execCommand: "ln -sf $BASE_REMOTE_PATH/vault/savefamily/sf-sims/.env $APP_REMOTE_PATH/.env"
|
||||||
|
),
|
||||||
|
sshTransfer(
|
||||||
|
cleanRemote: false,
|
||||||
|
execCommand: "ln -sf $BASE_REMOTE_PATH/vault/savefamily/sf-sims/wsaccess_alaisecure_com_cert_client_new.p12 $APP_REMOTE_PATH/wsaccess_alaisecure_com_cert_client_new.p12"
|
||||||
|
),
|
||||||
|
sshTransfer(
|
||||||
|
cleanRemote: false,
|
||||||
|
execCommand: "ln -sf $BASE_REMOTE_PATH/vault/savefamily/sf-sims/sim-consumidor-objenious.env $APP_REMOTE_PATH/sim-consumidor-objenious.env"
|
||||||
|
),
|
||||||
|
sshTransfer(
|
||||||
|
cleanRemote: false,
|
||||||
|
execCommand: "ln -sf $BASE_REMOTE_PATH/vault/savefamily/sf-sims/sim-consumidor-nos.env $APP_REMOTE_PATH/sim-consumidor-nos.env"
|
||||||
|
),
|
||||||
|
sshTransfer(
|
||||||
|
cleanRemote: false,
|
||||||
|
execCommand: "ln -sf $BASE_REMOTE_PATH/vault/savefamily/sf-sims/sim-consumidor-alai.env $APP_REMOTE_PATH/sim-consumidor-alai.env"
|
||||||
|
),
|
||||||
|
sshTransfer(
|
||||||
|
cleanRemote: false,
|
||||||
|
execCommand: "ln -sf $BASE_REMOTE_PATH/vault/savefamily/sf-sims/sim-objenious-cron.env $APP_REMOTE_PATH/sim-objenious-cron.env"
|
||||||
|
),
|
||||||
|
sshTransfer(
|
||||||
|
cleanRemote: false,
|
||||||
|
execCommand: "ln -sf $BASE_REMOTE_PATH/vault/savefamily/sf-sims/obj.pem $APP_REMOTE_PATH/obj.pem"
|
||||||
|
),
|
||||||
sshTransfer(
|
sshTransfer(
|
||||||
cleanRemote: false,
|
cleanRemote: false,
|
||||||
remoteDirectory: "$APP_REMOTE_PATH",
|
remoteDirectory: "$APP_REMOTE_PATH",
|
||||||
|
|||||||
@@ -1,90 +1,92 @@
|
|||||||
{
|
{
|
||||||
"rabbit_version": "4.2.2",
|
"rabbit_version": "4.2.2",
|
||||||
"rabbitmq_version": "4.2.2",
|
"rabbitmq_version": "4.2.2",
|
||||||
"product_name": "RabbitMQ",
|
"product_name": "RabbitMQ",
|
||||||
"product_version": "4.2.2",
|
"product_version": "4.2.2",
|
||||||
"users": [
|
"users": [
|
||||||
{
|
{
|
||||||
"name": "RABBITMQ_USER_PLACEHOLDER",
|
"name": "RABBITMQ_USER_PLACEHOLDER",
|
||||||
"password": "RABBITMQ_PASSWORD_PLACEHOLDER",
|
"password": "RABBITMQ_PASSWORD_PLACEHOLDER",
|
||||||
"tags": ["administrator"]
|
"tags": [
|
||||||
}
|
"administrator"
|
||||||
],
|
]
|
||||||
"vhosts": [
|
}
|
||||||
{
|
],
|
||||||
"name": "sim-vhost"
|
"vhosts": [
|
||||||
}
|
{
|
||||||
],
|
"name": "sim-vhost"
|
||||||
"permissions": [
|
}
|
||||||
{
|
],
|
||||||
"user": "RABBITMQ_USER_PLACEHOLDER",
|
"permissions": [
|
||||||
"vhost": "sim-vhost",
|
{
|
||||||
"configure": ".*",
|
"user": "RABBITMQ_USER_PLACEHOLDER",
|
||||||
"write": ".*",
|
"vhost": "sim-vhost",
|
||||||
"read": ".*"
|
"configure": ".*",
|
||||||
}
|
"write": ".*",
|
||||||
],
|
"read": ".*"
|
||||||
"topic_permissions": [],
|
}
|
||||||
"parameters": [],
|
],
|
||||||
"global_parameters": [
|
"topic_permissions": [],
|
||||||
{
|
"parameters": [],
|
||||||
"name": "cluster_name",
|
"global_parameters": [
|
||||||
"value": "rabbit@a8d5c6e08439"
|
{
|
||||||
},
|
"name": "cluster_name",
|
||||||
{
|
"value": "rabbit@a8d5c6e08439"
|
||||||
"name": "internal_cluster_id",
|
},
|
||||||
"value": "rabbitmq-cluster-id-gXeBLbsUC2W2tU0Bx_QY_w"
|
{
|
||||||
}
|
"name": "internal_cluster_id",
|
||||||
],
|
"value": "rabbitmq-cluster-id-gXeBLbsUC2W2tU0Bx_QY_w"
|
||||||
"policies": [
|
}
|
||||||
{
|
],
|
||||||
"vhost": "sim-vhost",
|
"policies": [
|
||||||
"name": "pol.sim.dlx",
|
{
|
||||||
"pattern": "sim.*",
|
"vhost": "sim-vhost",
|
||||||
"apply-to": "queues",
|
"name": "pol.sim.dlx",
|
||||||
"definition": {
|
"pattern": "sim.*",
|
||||||
"dead-letter-exchange": "sim.dlx"
|
"apply-to": "queues",
|
||||||
},
|
"definition": {
|
||||||
"priority": 7
|
"dead-letter-exchange": "sim.dlx"
|
||||||
}
|
},
|
||||||
],
|
"priority": 7
|
||||||
"exchanges": [
|
}
|
||||||
{
|
],
|
||||||
"name": "sim.exchange",
|
"exchanges": [
|
||||||
"vhost": "sim-vhost",
|
{
|
||||||
"type": "topic",
|
"name": "sim.exchange",
|
||||||
"durable": true,
|
"vhost": "sim-vhost",
|
||||||
"auto_delete": false,
|
"type": "topic",
|
||||||
"internal": false,
|
"durable": true,
|
||||||
"argurments": {}
|
"auto_delete": false,
|
||||||
},
|
"internal": false,
|
||||||
{
|
"argurments": {}
|
||||||
"name": "sim.dlx",
|
},
|
||||||
"vhost": "sim-vhost",
|
{
|
||||||
"type": "topic",
|
"name": "sim.dlx",
|
||||||
"durable": true,
|
"vhost": "sim-vhost",
|
||||||
"auto_delete": false,
|
"type": "topic",
|
||||||
"internal": false,
|
"durable": true,
|
||||||
"argurments": {}
|
"auto_delete": false,
|
||||||
}
|
"internal": false,
|
||||||
],
|
"argurments": {}
|
||||||
"queues": [
|
}
|
||||||
{
|
],
|
||||||
"name": "sim.logs",
|
"queues": [
|
||||||
"vhost": "sim-vhost",
|
{
|
||||||
"durable": true,
|
"name": "sim.logs",
|
||||||
"auto_delete": false,
|
"vhost": "sim-vhost",
|
||||||
"arguments": {}
|
"durable": true,
|
||||||
}
|
"auto_delete": false,
|
||||||
],
|
"arguments": {}
|
||||||
"bindings": [
|
}
|
||||||
{
|
],
|
||||||
"source": "sim.exchange",
|
"bindings": [
|
||||||
"vhost": "sim-vhost",
|
{
|
||||||
"destination": "sim.logs",
|
"source": "sim.exchange",
|
||||||
"destination_type": "queue",
|
"vhost": "sim-vhost",
|
||||||
"routing_key": "sim.#",
|
"destination": "sim.logs",
|
||||||
"arguments": {}
|
"destination_type": "queue",
|
||||||
}
|
"routing_key": "sim.#",
|
||||||
]
|
"arguments": {}
|
||||||
}
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ post {
|
|||||||
|
|
||||||
body:json {
|
body:json {
|
||||||
{
|
{
|
||||||
"iccid": "1234"
|
"iccid": "8934909001500561503"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ params:query {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body:form-urlencoded {
|
body:form-urlencoded {
|
||||||
iccid: 8933201125065160380
|
iccid: 8934909001500954922
|
||||||
|
offer: mensual
|
||||||
|
orderId: test
|
||||||
}
|
}
|
||||||
|
|
||||||
settings {
|
settings {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ post {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body:form-urlencoded {
|
body:form-urlencoded {
|
||||||
iccid: 8935103196306448300
|
iccid: 8934909001500561503
|
||||||
~offer: SAVEFAMILY1
|
~offer: SAVEFAMILY1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
38
docs/sim-objenious/Alerts.bru
Normal file
38
docs/sim-objenious/Alerts.bru
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
meta {
|
||||||
|
name: Alerts
|
||||||
|
type: http
|
||||||
|
seq: 23
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url: https://api-getway.objenious.com/ws/alarms
|
||||||
|
body: formUrlEncoded
|
||||||
|
auth: bearer
|
||||||
|
}
|
||||||
|
|
||||||
|
auth:bearer {
|
||||||
|
token: {{ws-access-token-partenaire}}
|
||||||
|
}
|
||||||
|
|
||||||
|
body:json {
|
||||||
|
{
|
||||||
|
"identifier": {
|
||||||
|
"identifiers": ["8933201124059175967"],
|
||||||
|
"identifierType": "ICCID"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
body:form-urlencoded {
|
||||||
|
~identifier.identifierType: "ICCID"
|
||||||
|
~identifier.identifiers: ["8933201124059175967"]
|
||||||
|
}
|
||||||
|
|
||||||
|
vars:pre-request {
|
||||||
|
~id: 5187320
|
||||||
|
}
|
||||||
|
|
||||||
|
settings {
|
||||||
|
encodeUrl: true
|
||||||
|
timeout: 0
|
||||||
|
}
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "sim-eventos",
|
"name": "sim-eventos",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"packageManager": "yarn@4.12.0",
|
"packageManager": "yarn@4.14.1",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vitest watch",
|
"test": "vitest watch",
|
||||||
"build": "rm -rf ./dist && yarn workspaces foreach -Api run build && yarn setup:runtime",
|
"build": "rm -rf ./dist && yarn workspaces foreach -Api run build && yarn setup:runtime",
|
||||||
|
"build:prod": "rm -rf ./dist && yarn workspaces foreach -Api run build:prod && yarn setup:runtime",
|
||||||
"setup:runtime": "mkdir -p dist/packages/node_modules && ln -sf ../sim-shared dist/packages/node_modules/sim-shared && ln -sf ../sf-consumidor-objenious dist/packages/node_modules/sim-consumidor-objenious",
|
"setup:runtime": "mkdir -p dist/packages/node_modules && ln -sf ../sim-shared dist/packages/node_modules/sim-shared && ln -sf ../sf-consumidor-objenious dist/packages/node_modules/sim-consumidor-objenious",
|
||||||
"start": "yarn workspaces foreach -Apiv run start",
|
"start": "yarn workspaces foreach -Apiv run start",
|
||||||
"typecheck": "npx tsc --noEmit",
|
"typecheck": "npx tsc --noEmit",
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ import { SimEvents } from "sim-shared/domain/SimEvents.js";
|
|||||||
import { iccidValidator } from "./httpValidators.js";
|
import { iccidValidator } from "./httpValidators.js";
|
||||||
import { alaiSimToCommonSim } from "#domain/transformers.js";
|
import { alaiSimToCommonSim } from "#domain/transformers.js";
|
||||||
|
|
||||||
|
type ErrorUsecase = {
|
||||||
|
msg: string,
|
||||||
|
stackTrace?: string
|
||||||
|
}
|
||||||
|
|
||||||
export class SimAlaiController {
|
export class SimAlaiController {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -41,12 +46,13 @@ export class SimAlaiController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metodo duplicado se puede generalizar la a una clase sharedController con las funciones basicas
|
* Metodo duplicado se puede generalizar la a una clase sharedController con las funciones basicas
|
||||||
* TODO: meter un check de 429
|
* TODO: meter un check de 429
|
||||||
*/
|
*/
|
||||||
private async tryUseCase<T extends any>
|
private async tryUseCase<T extends any>
|
||||||
(msg: ConsumeMessage, usecase: () => Promise<Result<string, T>>): Promise<Result<string, T>> {
|
(msg: ConsumeMessage, usecase: () => Promise<Result<ErrorUsecase, T>>): Promise<Result<ErrorUsecase, T>> {
|
||||||
try {
|
try {
|
||||||
const result = await usecase()
|
const result = await usecase()
|
||||||
if (result.error == undefined) {
|
if (result.error == undefined) {
|
||||||
@@ -61,7 +67,10 @@ export class SimAlaiController {
|
|||||||
console.error("Error general procesando el caso de uso (Alai)")
|
console.error("Error general procesando el caso de uso (Alai)")
|
||||||
this.eventBus.nack(msg)
|
this.eventBus.nack(msg)
|
||||||
return {
|
return {
|
||||||
error: String(e)
|
error: {
|
||||||
|
msg: String(e),
|
||||||
|
stackTrace: String(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,9 +81,30 @@ export class SimAlaiController {
|
|||||||
const data = this.validateMsg(msg) as SimEvents.activation
|
const data = this.validateMsg(msg) as SimEvents.activation
|
||||||
const iccid = data.payload.iccid
|
const iccid = data.payload.iccid
|
||||||
const correlation_id = data.headers?.message_id
|
const correlation_id = data.headers?.message_id
|
||||||
|
const externalId = data.payload.orderId
|
||||||
|
|
||||||
const res = await this.tryUseCase(msg, this.uscases.activate({
|
const res = await this.tryUseCase(msg, this.uscases.activate({
|
||||||
iccid: iccid,
|
iccid: iccid,
|
||||||
correlation_id: correlation_id
|
correlation_id: correlation_id,
|
||||||
|
}))
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public preactivate() {
|
||||||
|
return async (msg: ConsumeMessage) => {
|
||||||
|
console.log("[i] Evento preactivate ", msg)
|
||||||
|
const data = this.validateMsg(msg) as SimEvents.preActivation
|
||||||
|
const iccid = data.payload.iccid
|
||||||
|
const correlation_id = data.headers?.message_id
|
||||||
|
const externalId = data.payload.orderId
|
||||||
|
|
||||||
|
console.log("MSG:", data, data.headers)
|
||||||
|
|
||||||
|
const res = await this.tryUseCase(msg, this.uscases.preactivate({
|
||||||
|
iccid: iccid,
|
||||||
|
correlation_id: correlation_id,
|
||||||
|
externalId: externalId
|
||||||
}))
|
}))
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -114,7 +144,7 @@ export class SimAlaiController {
|
|||||||
|
|
||||||
public terminate() {
|
public terminate() {
|
||||||
return async (msg: ConsumeMessage) => {
|
return async (msg: ConsumeMessage) => {
|
||||||
console.log("Evento reActivate ", msg.fields)
|
console.log("Evento reActivate ", msg.fields, msg)
|
||||||
const data = this.validateMsg(msg) as SimEvents.reActivation
|
const data = this.validateMsg(msg) as SimEvents.reActivation
|
||||||
const iccid = data.payload.iccid
|
const iccid = data.payload.iccid
|
||||||
const correlation_id = data.headers?.message_id
|
const correlation_id = data.headers?.message_id
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { EventBus } from "sim-shared/domain/EventBus.port.js";
|
|||||||
import { Result } from "sim-shared/domain/Result.js";
|
import { Result } from "sim-shared/domain/Result.js";
|
||||||
import { SimAlaiController } from "./SimAlai.controller.js";
|
import { SimAlaiController } from "./SimAlai.controller.js";
|
||||||
|
|
||||||
type FuncType = ((m: ConsumeMessage) => Promise<Result<string, any>>)
|
type FuncType = ((m: ConsumeMessage) => Promise<Result<{ msg: string, stackTrace?: string }, any>>)
|
||||||
|
|
||||||
export class SimAlaiRouter {
|
export class SimAlaiRouter {
|
||||||
private readonly routes: Map<string, FuncType>;
|
private readonly routes: Map<string, FuncType>;
|
||||||
@@ -24,7 +24,7 @@ export class SimAlaiRouter {
|
|||||||
["pause", this.simController.suspend()],
|
["pause", this.simController.suspend()],
|
||||||
["reactivate", this.simController.reActivate()],
|
["reactivate", this.simController.reActivate()],
|
||||||
["cancel", this.simController.terminate()],
|
["cancel", this.simController.terminate()],
|
||||||
["preActivate", this.simController.activate()]
|
["preactivate", this.simController.preactivate()]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,12 +10,10 @@
|
|||||||
*/
|
*/
|
||||||
import { AlaiAPI } from "#domain/AlaiAPI.js";
|
import { AlaiAPI } from "#domain/AlaiAPI.js";
|
||||||
import { AlaiRepository } from "#infrastructure/AlaiRepository.js";
|
import { AlaiRepository } from "#infrastructure/AlaiRepository.js";
|
||||||
import { ConsumeMessage } from "amqplib";
|
|
||||||
import { ErrorOrderDTO, FinishOrderDTO, UpdateOrderDTO } from "sim-shared/domain/Order.js";
|
import { ErrorOrderDTO, FinishOrderDTO, UpdateOrderDTO } from "sim-shared/domain/Order.js";
|
||||||
import { Result } from "sim-shared/domain/Result.js";
|
import { Result } from "sim-shared/domain/Result.js";
|
||||||
import { HttpClient } from "sim-shared/infrastructure/HTTPClient.js";
|
import { HttpClient } from "sim-shared/infrastructure/HTTPClient.js";
|
||||||
import { OrderRepository } from "sim-shared/infrastructure/OrderRepository.js";
|
import { OrderRepository } from "sim-shared/infrastructure/OrderRepository.js";
|
||||||
import { isOmittedExpression } from "typescript";
|
|
||||||
|
|
||||||
export class SimAlaiUsecases {
|
export class SimAlaiUsecases {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -44,7 +42,7 @@ export class SimAlaiUsecases {
|
|||||||
return order
|
return order
|
||||||
}
|
}
|
||||||
|
|
||||||
private async setFailed(correlation_id: string, reason: string, detail?: string) {
|
private async setFailed(correlation_id: string, reason: string, stackTrace?: string) {
|
||||||
// En NOS el updateOrder se hace con el correlation_id que viene en la cabecera del
|
// En NOS el updateOrder se hace con el correlation_id que viene en la cabecera del
|
||||||
// mensaje consumido
|
// mensaje consumido
|
||||||
const updateData: ErrorOrderDTO = {
|
const updateData: ErrorOrderDTO = {
|
||||||
@@ -52,7 +50,7 @@ export class SimAlaiUsecases {
|
|||||||
correlation_id: correlation_id,
|
correlation_id: correlation_id,
|
||||||
reason: reason,
|
reason: reason,
|
||||||
error: reason,
|
error: reason,
|
||||||
stackTrace: detail
|
stackTrace: stackTrace
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("SET FAILED DATA:", updateData)
|
console.log("SET FAILED DATA:", updateData)
|
||||||
@@ -66,11 +64,11 @@ export class SimAlaiUsecases {
|
|||||||
* a peticiones de lectura (no pasan por la cola y no generan un order)
|
* a peticiones de lectura (no pasan por la cola y no generan un order)
|
||||||
*/
|
*/
|
||||||
public usecaseTemplate<T, R>(
|
public usecaseTemplate<T, R>(
|
||||||
func: (_: T) => Promise<Result<string, R>>,
|
func: (_: T) => Promise<Result<{ msg: string, stackTrace?: string }, R>>,
|
||||||
args: T,
|
args: T,
|
||||||
correlation_id?: string | undefined
|
correlation_id?: string | undefined
|
||||||
) {
|
) {
|
||||||
return async (): Promise<Result<string, R>> => {
|
return async (): Promise<Result<{ msg: string, stackTrace?: string }, R>> => {
|
||||||
// Operacion pending -> running
|
// Operacion pending -> running
|
||||||
if (correlation_id != undefined)
|
if (correlation_id != undefined)
|
||||||
this.setRunning(correlation_id)
|
this.setRunning(correlation_id)
|
||||||
@@ -85,7 +83,7 @@ export class SimAlaiUsecases {
|
|||||||
if (res.error != undefined) {
|
if (res.error != undefined) {
|
||||||
console.log("Error peticion: ", res, correlation_id)
|
console.log("Error peticion: ", res, correlation_id)
|
||||||
if (correlation_id != undefined)
|
if (correlation_id != undefined)
|
||||||
this.setFailed(correlation_id, res.error)
|
this.setFailed(correlation_id, res.error.msg, res.error.stackTrace)
|
||||||
.then(e => console.log("failed", e))
|
.then(e => console.log("failed", e))
|
||||||
.catch(e => console.error(e))
|
.catch(e => console.error(e))
|
||||||
return res;
|
return res;
|
||||||
@@ -99,7 +97,9 @@ export class SimAlaiUsecases {
|
|||||||
if (correlation_id != undefined)
|
if (correlation_id != undefined)
|
||||||
this.setFailed(correlation_id, "Error general de operacion de SIM (NOS) ", String(e)).then()
|
this.setFailed(correlation_id, "Error general de operacion de SIM (NOS) ", String(e)).then()
|
||||||
return {
|
return {
|
||||||
error: "Error general de operacion de SIM (NOS) " + String(e)
|
error: {
|
||||||
|
msg: "Error general de operacion de SIM (NOS) " + String(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,17 +108,35 @@ export class SimAlaiUsecases {
|
|||||||
|
|
||||||
public activate(args: {
|
public activate(args: {
|
||||||
iccid: string,
|
iccid: string,
|
||||||
correlation_id: string | undefined
|
correlation_id: string | undefined,
|
||||||
}) {
|
}) {
|
||||||
return this.usecaseTemplate(async (iccid /*iccid*/) => {
|
return this.usecaseTemplate(async (iccid /*iccid*/) => {
|
||||||
const order = await this.alaiRepository.createOrder()
|
const sim = await this.alaiRepository.getSimByICCID(iccid)
|
||||||
if (order.error != undefined) {
|
if (sim.error != undefined) {
|
||||||
// Falla el crearse un order (problema de servidor, token, etc)
|
return sim
|
||||||
console.error(order.error)
|
|
||||||
return order
|
|
||||||
}
|
}
|
||||||
const reserved = await this.alaiRepository.createReserve(order.data.id, iccid)
|
|
||||||
return reserved
|
if (sim.data == undefined) {
|
||||||
|
return {
|
||||||
|
error: {
|
||||||
|
msg: `La sim ${iccid} no se ha encontrado`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const subscriptionId = sim.data.subscription!.id
|
||||||
|
|
||||||
|
if (subscriptionId == undefined) {
|
||||||
|
return {
|
||||||
|
error: {
|
||||||
|
msg: `La sim ${iccid} no tiene un id de subscripción`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const activationRes = await this.alaiRepository.activateSubscription(subscriptionId)
|
||||||
|
return activationRes
|
||||||
|
|
||||||
}, args.iccid, args.correlation_id)
|
}, args.iccid, args.correlation_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,6 +162,8 @@ export class SimAlaiUsecases {
|
|||||||
|
|
||||||
const applyOrder = await this.alaiRepository.applyOrder(orderId)
|
const applyOrder = await this.alaiRepository.applyOrder(orderId)
|
||||||
if (applyOrder.error != undefined) {
|
if (applyOrder.error != undefined) {
|
||||||
|
// TODO: gestion del error
|
||||||
|
// reusar el orderId
|
||||||
return applyOrder
|
return applyOrder
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +173,7 @@ export class SimAlaiUsecases {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Controlar sim no encotrada (No deberia pasar)
|
// TODO: Controlar sim no encotrada (No deberia pasar)
|
||||||
const subscriptionId = preactivatedSim.data!.subscription.id
|
const subscriptionId = preactivatedSim.data!.subscription!.id
|
||||||
if (args.externalId) {
|
if (args.externalId) {
|
||||||
const externalIdAdded = await this.alaiRepository.changeExternalId(subscriptionId, args.externalId)
|
const externalIdAdded = await this.alaiRepository.changeExternalId(subscriptionId, args.externalId)
|
||||||
if (externalIdAdded.error != undefined) {
|
if (externalIdAdded.error != undefined) {
|
||||||
@@ -178,7 +198,8 @@ export class SimAlaiUsecases {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Controlar que no se encuentre la subscription
|
// TODO: Controlar que no se encuentre la subscription
|
||||||
const suspension = this.alaiRepository.pauseSubscription(subscription.data!.id)
|
const subscriptionid = subscription.data?.subscription?.id
|
||||||
|
const suspension = this.alaiRepository.pauseSubscription(subscriptionid!)
|
||||||
return suspension
|
return suspension
|
||||||
}, args, args.correlation_id)
|
}, args, args.correlation_id)
|
||||||
}
|
}
|
||||||
@@ -193,9 +214,9 @@ export class SimAlaiUsecases {
|
|||||||
if (subscription.error != undefined) {
|
if (subscription.error != undefined) {
|
||||||
return subscription
|
return subscription
|
||||||
}
|
}
|
||||||
|
const subscriptionid = subscription.data?.subscription?.id
|
||||||
// TODO: Controlar que no se encuentre la subscription
|
// TODO: Controlar que no se encuentre la subscription
|
||||||
const suspension = this.alaiRepository.unPauseSubscription(subscription.data!.id)
|
const suspension = this.alaiRepository.unPauseSubscription(subscriptionid!)
|
||||||
return suspension
|
return suspension
|
||||||
}, args, args.correlation_id)
|
}, args, args.correlation_id)
|
||||||
}
|
}
|
||||||
@@ -226,10 +247,10 @@ export class SimAlaiUsecases {
|
|||||||
* Para sacar los datos de una liena hay que sacar sim -> subscripcion -> imei
|
* Para sacar los datos de una liena hay que sacar sim -> subscripcion -> imei
|
||||||
* son 3 llamadas distintas.
|
* son 3 llamadas distintas.
|
||||||
*/
|
*/
|
||||||
public async selectCompleteSim(iccid: string): Promise<Result<string, {
|
public async selectCompleteSim(iccid: string): Promise<Result<{ msg: string, stackTrace?: string }, {
|
||||||
sim: AlaiAPI.Sim,
|
sim: AlaiAPI.Sim,
|
||||||
subscription: AlaiAPI.Subscription,
|
subscription?: AlaiAPI.Subscription,
|
||||||
imei: AlaiAPI.GetImeiSubscriptionDTO
|
imei?: AlaiAPI.GetImeiSubscriptionDTO
|
||||||
}>> {
|
}>> {
|
||||||
const sim = await this.alaiRepository.getSimByICCID(iccid)
|
const sim = await this.alaiRepository.getSimByICCID(iccid)
|
||||||
|
|
||||||
@@ -237,7 +258,26 @@ export class SimAlaiUsecases {
|
|||||||
return sim
|
return sim
|
||||||
}
|
}
|
||||||
|
|
||||||
const subscriptionId = sim.data!.subscription.id
|
if (sim.data == undefined) {
|
||||||
|
return {
|
||||||
|
error: {
|
||||||
|
msg: `La sim ${iccid} no se ha encontrado`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// En este caso la tarjeta no se ha preactivado, por lo que no tiene subscripcion
|
||||||
|
if (sim.data.subscription == undefined) {
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
sim: sim.data,
|
||||||
|
subscription: undefined,
|
||||||
|
imei: undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const subscriptionId = sim.data.subscription.id
|
||||||
const subscription = await this.alaiRepository.getSubscriptionById(subscriptionId)
|
const subscription = await this.alaiRepository.getSubscriptionById(subscriptionId)
|
||||||
|
|
||||||
if (subscription.error != undefined) {
|
if (subscription.error != undefined) {
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
eyJhbGciOiJIUzM4NCJ9.eyJiciI6InNhdmVmYW1pbHkiLCJpcCI6Ijg4LjE1LjE1Ny4xNjciLCJzdWIiOiJwYWxvbWFpYmFuZXoiLCJzIjoiRVdTMTY0NmFmNjNlZGUyMjgzIiwicG9zIjoic2F2ZWZhbWlseUNhYyIsImlkV3NVc2VyIjoiODYiLCJpc012bmEiOmZhbHNlLCJkb21haW4iOiJBbGFpfHNhdmVmYW1pbHkiLCJpYXQiOjE3Nzc4OTk3MzcsImV4cCI6MTc3NzkxMDUzN30.PvTTRhUpKlslGOerQsLY4RLBXdQ5FIVvUKb_1ZK4b2Zggt04KZhwX0d-XoLAcP93
|
eyJhbGciOiJIUzM4NCJ9.eyJiciI6InNhdmVmYW1pbHkiLCJpcCI6Ijg4LjE1LjE1Ny4xNjciLCJzdWIiOiJwYWxvbWFpYmFuZXoiLCJzIjoiRVdTMTY3MzRhYTM2MDY1M2EwIiwicG9zIjoic2F2ZWZhbWlseUNhYyIsImlkV3NVc2VyIjoiODYiLCJpc012bmEiOmZhbHNlLCJkb21haW4iOiJBbGFpfHNhdmVmYW1pbHkiLCJpYXQiOjE3Nzg2ODQ0NjIsImV4cCI6MTc3ODY5NTI2Mn0.wMWgjaOErm5clang7ErYzREU56okgpXWzq1zihT4lOfUDRQ005r-nCHJu7rpilj1
|
||||||
|
|||||||
@@ -5,13 +5,16 @@ import { httpsAgent } from "./httpsAgent.js"
|
|||||||
import { DebugTokenManager } from "#aplication/DebugTokenManager.js";
|
import { DebugTokenManager } from "#aplication/DebugTokenManager.js";
|
||||||
|
|
||||||
const tokenManager = new AlaiTokenManager()
|
const tokenManager = new AlaiTokenManager()
|
||||||
//const debugTokenManagr = new DebugTokenManager()
|
const debugTokenManagr = new DebugTokenManager()
|
||||||
//console.error("USANDO DebugTokenManager! Eliminar en prod")
|
//console.error("USANDO DebugTokenManager! Eliminar en prod")
|
||||||
|
|
||||||
|
|
||||||
export const alaiHttp = new HttpClient({
|
export const alaiHttp = new HttpClient({
|
||||||
baseURL: env.ALAI_API_URL as string,
|
baseURL: env.ALAI_API_URL as string,
|
||||||
headers: {},
|
headers: {
|
||||||
|
"content-type": "application/json"
|
||||||
|
},
|
||||||
jwtManager: tokenManager,
|
jwtManager: tokenManager,
|
||||||
|
//jwtManager: debugTokenManagr,
|
||||||
httpsAgent: httpsAgent
|
httpsAgent: httpsAgent
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ export namespace AlaiAPI {
|
|||||||
name: string,
|
name: string,
|
||||||
links: Link[]
|
links: Link[]
|
||||||
},
|
},
|
||||||
subscription: {
|
subscription?: {
|
||||||
id: string,
|
id: string,
|
||||||
name: string,
|
name: string,
|
||||||
links: Link[]
|
links: Link[]
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ const alaiStates = new Map<AlaiAPI.Status, CommonSim<any>["billing_status"]>([
|
|||||||
["CONFIGURING", "SUSPENDED"],
|
["CONFIGURING", "SUSPENDED"],
|
||||||
["DELETED", "TERMINATED"],
|
["DELETED", "TERMINATED"],
|
||||||
["PRE_ACTIVE", "PREACTIVATED"],
|
["PRE_ACTIVE", "PREACTIVATED"],
|
||||||
["TERMINATED", "TERMINATED"]
|
["TERMINATED", "TERMINATED"],
|
||||||
|
|
||||||
])
|
])
|
||||||
|
|
||||||
const alaiNetworkStates = new Map<AlaiAPI.NetworkStatus, CommonSim<any>["network_status"]>([
|
const alaiNetworkStates = new Map<AlaiAPI.NetworkStatus, CommonSim<any>["network_status"]>([
|
||||||
@@ -22,23 +23,37 @@ const alaiNetworkStates = new Map<AlaiAPI.NetworkStatus, CommonSim<any>["network
|
|||||||
["FRAUD", "TERMINATED"]
|
["FRAUD", "TERMINATED"]
|
||||||
])
|
])
|
||||||
|
|
||||||
export function alaiSimToCommonSim(alaiSim: AlaiAPI.Sim, alaiSubscription: AlaiAPI.Subscription, imeiSubscription: AlaiAPI.GetImeiSubscriptionDTO):
|
export function alaiSimToCommonSim(alaiSim: AlaiAPI.Sim, alaiSubscription?: AlaiAPI.Subscription, imeiSubscription?: AlaiAPI.GetImeiSubscriptionDTO):
|
||||||
Result<string, CommonSim<AlaiAPI.Subscription>> {
|
Result<string, CommonSim<
|
||||||
|
{
|
||||||
|
sim: AlaiAPI.Sim,
|
||||||
|
subscription?: AlaiAPI.Subscription,
|
||||||
|
imeiSubscription?: AlaiAPI.GetImeiSubscriptionDTO
|
||||||
|
}
|
||||||
|
>> {
|
||||||
|
|
||||||
const status = alaiStates.get(alaiSubscription.status) ?? "UNKNOWN"
|
const billingStatus = (alaiSubscription == undefined) ? "AVAILABLE" : alaiStates.get(alaiSubscription?.status ?? "") ?? "UNKNOWN"
|
||||||
const networkStatus = alaiNetworkStates.get(alaiSubscription.networkStatus) ?? "UNKNOWN"
|
const networkStatus = (alaiSubscription == undefined) ? "AVAILABLE" : alaiNetworkStates.get(alaiSubscription.networkStatus) ?? "UNKNOWN"
|
||||||
|
|
||||||
const commonSim: CommonSim<AlaiAPI.Subscription> = {
|
const commonSim: CommonSim<{
|
||||||
|
sim: AlaiAPI.Sim,
|
||||||
|
subscription?: AlaiAPI.Subscription,
|
||||||
|
imeiSubscription?: AlaiAPI.GetImeiSubscriptionDTO
|
||||||
|
}> = {
|
||||||
company: "ALAI",
|
company: "ALAI",
|
||||||
tariff: alaiSubscription.name,
|
tariff: alaiSubscription?.name,
|
||||||
iccid: alaiSim.id,
|
iccid: alaiSim.id,
|
||||||
msisdn: alaiSubscription.lastMsisdnID,
|
msisdn: alaiSubscription?.lastMsisdnID,
|
||||||
billing_status: status,
|
billing_status: billingStatus,
|
||||||
network_status: networkStatus,
|
network_status: networkStatus,
|
||||||
raw: alaiSubscription,
|
raw: {
|
||||||
imei: imeiSubscription.content[0].id ?? "0",
|
subscription: alaiSubscription,
|
||||||
preactivation_date: new Date(alaiSubscription.creationDate),
|
sim: alaiSim,
|
||||||
activation_date: new Date(alaiSubscription.firstActivationDate)
|
imeiSubscription: imeiSubscription
|
||||||
|
},
|
||||||
|
imei: imeiSubscription?.content[0]?.id ?? "0",
|
||||||
|
preactivation_date: (alaiSubscription != undefined) ? new Date(alaiSubscription.creationDate) : undefined,
|
||||||
|
activation_date: (alaiSubscription != undefined) ? new Date(alaiSubscription.firstActivationDate) : undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -5,13 +5,18 @@ import { env } from "#config/env/env.js";
|
|||||||
import { HttpClient } from "sim-shared/infrastructure/HTTPClient.js";
|
import { HttpClient } from "sim-shared/infrastructure/HTTPClient.js";
|
||||||
import https from "https"
|
import https from "https"
|
||||||
|
|
||||||
|
type ErrorRepo = {
|
||||||
|
msg: string,
|
||||||
|
stackTrace?: string
|
||||||
|
}
|
||||||
|
|
||||||
export class AlaiRepository {
|
export class AlaiRepository {
|
||||||
constructor(
|
constructor(
|
||||||
private httpClient: HttpClient
|
private httpClient: HttpClient
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async manageRequest<E, T>(promiseReq: Promise<AxiosResponse<T>>): Promise<Result<string, T>> {
|
private async manageRequest<E, T>(promiseReq: Promise<AxiosResponse<T>>): Promise<Result<ErrorRepo, T>> {
|
||||||
try {
|
try {
|
||||||
const res = await promiseReq
|
const res = await promiseReq
|
||||||
return {
|
return {
|
||||||
@@ -19,19 +24,26 @@ export class AlaiRepository {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (axios.isAxiosError(e)) {
|
if (axios.isAxiosError(e)) {
|
||||||
|
console.log("ERROR REQUEST ", e.response)
|
||||||
const error = e as AxiosError
|
const error = e as AxiosError
|
||||||
return {
|
return {
|
||||||
error: error.code + " : " + String(error.response?.statusText)
|
error: {
|
||||||
|
msg: error.code + " : " + String(error.response?.statusText),
|
||||||
|
stackTrace: JSON.stringify(error.response?.data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
error: String(e)
|
error: {
|
||||||
|
msg: String(e),
|
||||||
|
stackTrace: String(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async login(httpsAgent: https.Agent): Promise<Result<string, AlaiAPI.LoginResponseDTO>> {
|
public static async login(httpsAgent: https.Agent): Promise<Result<ErrorRepo, AlaiAPI.LoginResponseDTO>> {
|
||||||
const alaiUrl = env.ALAI_API_URL
|
const alaiUrl = env.ALAI_API_URL
|
||||||
const endpoint = "/v1/auth/login"
|
const endpoint = "/v1/auth/login"
|
||||||
const fullUrl = alaiUrl + endpoint
|
const fullUrl = alaiUrl + endpoint
|
||||||
@@ -50,11 +62,16 @@ export class AlaiRepository {
|
|||||||
if (axios.isAxiosError(e)) {
|
if (axios.isAxiosError(e)) {
|
||||||
const error = e as AxiosError
|
const error = e as AxiosError
|
||||||
return {
|
return {
|
||||||
error: error.code + " : " + String(error.response?.statusText)
|
error: {
|
||||||
|
msg: error.code + " : " + String(error.response?.statusText),
|
||||||
|
stackTrace: String(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
error: String(e)
|
error: {
|
||||||
|
msg: String(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,7 +118,7 @@ export class AlaiRepository {
|
|||||||
/**
|
/**
|
||||||
* Antes se usaba PATCH /v1/sim/{iccid}/{orderId} pero en la docu ha pasado a POST
|
* Antes se usaba PATCH /v1/sim/{iccid}/{orderId} pero en la docu ha pasado a POST
|
||||||
*/
|
*/
|
||||||
public async createReserve(orderId: string, iccid: string): Promise<Result<string, AlaiAPI.CreateOrderResponseDTO>> {
|
public async createReserve(orderId: string, iccid: string): Promise<Result<ErrorRepo, AlaiAPI.CreateOrderResponseDTO>> {
|
||||||
const endpoint = `/v1/sim/${iccid}/order/${orderId}`
|
const endpoint = `/v1/sim/${iccid}/order/${orderId}`
|
||||||
// Crear la reserva no usa datos en el body
|
// Crear la reserva no usa datos en el body
|
||||||
const promReq = this.httpClient.post<AlaiAPI.CreateOrderResponseDTO>(endpoint, undefined)
|
const promReq = this.httpClient.post<AlaiAPI.CreateOrderResponseDTO>(endpoint, undefined)
|
||||||
@@ -135,16 +152,37 @@ export class AlaiRepository {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
public async unPauseSubscription(subscriptionId: string) {
|
public async activateSubscription(subscriptionId: string) {
|
||||||
const endpoint = `/v1/subscription/${subscriptionId}`
|
const endpoint = `/v1/subscription/${subscriptionId}`
|
||||||
// En teoria ahora se usa ["action", "UNBLOCK"] pero no he probado
|
// En teoria ahora se usa ["action", "UNBLOCK"] pero no he probado
|
||||||
const params = new URLSearchParams([
|
const params = new URLSearchParams([
|
||||||
["action", "CHANGE_STATUS"]
|
["action", "CHANGE_STATUS"]
|
||||||
])
|
])
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
"status": "ACTIVE"
|
||||||
|
}
|
||||||
|
|
||||||
|
const promReq = this.httpClient.patch<AlaiAPI.UpdateSubscriptionDTO | undefined>(endpoint, data, { params: params })
|
||||||
|
const res = await this.manageRequest(promReq)
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
public async unPauseSubscription(subscriptionId: string) {
|
||||||
|
const endpoint = `/v1/subscription/${subscriptionId}`
|
||||||
|
// En teoria ahora se usa ["action", "UNBLOCK"] pero no he probado
|
||||||
|
const params = new URLSearchParams([
|
||||||
|
["action", "UNBLOCK"]
|
||||||
|
])
|
||||||
|
|
||||||
|
const rawParams = {
|
||||||
|
"action": "UNBLOCK"
|
||||||
|
}
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
status: "ACTIVE"
|
status: "ACTIVE"
|
||||||
}
|
}
|
||||||
const promReq = this.httpClient.patch<AlaiAPI.UpdateSubscriptionDTO | undefined>(endpoint, data, { params: params })
|
const promReq = this.httpClient.patch<AlaiAPI.UpdateSubscriptionDTO | undefined>(endpoint, undefined, { params: rawParams })
|
||||||
const res = await this.manageRequest(promReq)
|
const res = await this.manageRequest(promReq)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,9 +39,10 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"build": "yarn tsc --project tsconfig.json && yarn tsc-alias && cp package.json ../../dist/packages/sim-consumidor-nos/ && cp -r certificates/ ../../dist/packages/sim-consumidor-alai/",
|
"build": "yarn tsc --project tsconfig.json && yarn tsc-alias && cp -P .env package.json ../../dist/packages/sim-consumidor-alai/ && cp -r certificates/ ../../dist/packages/sim-consumidor-alai/",
|
||||||
|
"build:prod": "yarn tsc --project tsconfig.json && yarn tsc-alias && cp -P package.json ../../dist/packages/sim-consumidor-alai/ && mkdir ../../dist/packages/sim-consumidor-alai/certificates",
|
||||||
"esbuild": "esbuild index.ts --platform=node",
|
"esbuild": "esbuild index.ts --platform=node",
|
||||||
"start": "node ../../dist/packages/sim-consumidor-nos/index.js",
|
"start": "node ../../dist/packages/sim-consumidor-alai/index.js",
|
||||||
"dev": "tsx watch index.ts"
|
"dev": "tsx watch index.ts"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ export const env = {
|
|||||||
RABBITMQ_RETRY_INTERVAL: process.env.RABBITMQ_INTERVAL,
|
RABBITMQ_RETRY_INTERVAL: process.env.RABBITMQ_INTERVAL,
|
||||||
RABBITMQ_VHOST: String(process.env.RABBITMQ_VHOST),
|
RABBITMQ_VHOST: String(process.env.RABBITMQ_VHOST),
|
||||||
|
|
||||||
APP_PORT: Number(process.env.NOS_PORT),
|
APP_PORT: Number(process.env.NOS_PORT ?? 3001),
|
||||||
APP_HOST: String(process.env.NOS_HOST),
|
APP_HOST: String(process.env.NOS_HOST ?? "0.0.0.0"),
|
||||||
|
|
||||||
// ESPECIFICO NOS
|
// ESPECIFICO NOS
|
||||||
NOS_BASE_URL: String(process.env.NOS_BASE_URL),
|
NOS_BASE_URL: String(process.env.NOS_BASE_URL),
|
||||||
|
|||||||
@@ -39,7 +39,8 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"build": "yarn tsc --project tsconfig.json && yarn tsc-alias && cp package.json ../../dist/packages/sim-consumidor-nos/",
|
"build": "yarn tsc --project tsconfig.json && yarn tsc-alias && cp -P .env package.json ../../dist/packages/sim-consumidor-nos/",
|
||||||
|
"build:prod": "yarn tsc --project tsconfig.json && yarn tsc-alias && cp -P package.json ../../dist/packages/sim-consumidor-nos/",
|
||||||
"esbuild": "esbuild index.ts --platform=node",
|
"esbuild": "esbuild index.ts --platform=node",
|
||||||
"start": "node ../../dist/packages/sim-consumidor-nos/index.js",
|
"start": "node ../../dist/packages/sim-consumidor-nos/index.js",
|
||||||
"dev": "tsx watch index.ts"
|
"dev": "tsx watch index.ts"
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export class SimRouter {
|
|||||||
["pause", this.simController.suspend()],
|
["pause", this.simController.suspend()],
|
||||||
["cancel", this.simController.terminate()],
|
["cancel", this.simController.terminate()],
|
||||||
["reactivate", this.simController.reActivate()],
|
["reactivate", this.simController.reActivate()],
|
||||||
["preActivate", this.simController.preActivate()]
|
["preactivate", this.simController.preActivate()]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ export class SimUseCases {
|
|||||||
console.log("Sim preactivada con exito", resp.data)
|
console.log("Sim preactivada con exito", resp.data)
|
||||||
const operation: ObjeniousOperation = {
|
const operation: ObjeniousOperation = {
|
||||||
correlation_id: preActivateData.correlation_id,
|
correlation_id: preActivateData.correlation_id,
|
||||||
operation: "preActivate",
|
operation: "preactivate",
|
||||||
iccids: String(preActivateData.identifier.identifiers),
|
iccids: String(preActivateData.identifier.identifiers),
|
||||||
status: "noMassID",
|
status: "noMassID",
|
||||||
request_id: resp.data.requestId
|
request_id: resp.data.requestId
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ async function buildQueues(channel: Channel) {
|
|||||||
await channel.assertExchange(EXCHANGES.DLX, "topic")
|
await channel.assertExchange(EXCHANGES.DLX, "topic")
|
||||||
await channel.assertExchange(EXCHANGES.MAIN, "topic")
|
await channel.assertExchange(EXCHANGES.MAIN, "topic")
|
||||||
|
|
||||||
await channel.assertQueue(QUEUES.OBJ)
|
await channel.assertQueue(QUEUES.OBJ, { durable: true })
|
||||||
await channel.assertQueue(QUEUES.OBJDLX)
|
await channel.assertQueue(QUEUES.OBJDLX, { durable: true })
|
||||||
await channel.assertQueue(QUEUES.OBJDEL, {
|
await channel.assertQueue(QUEUES.OBJDEL, {
|
||||||
durable: true,
|
durable: true,
|
||||||
arguments: {
|
arguments: {
|
||||||
|
|||||||
@@ -55,7 +55,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node --import tsx --test ./**/*.test.ts",
|
"test": "node --import tsx --test ./**/*.test.ts",
|
||||||
"dev": "tsx watch index.ts",
|
"dev": "tsx watch index.ts",
|
||||||
"build": "tsc --build && yarn tsc-alias -p tsconfig.json && cp .env package.json ../../dist/packages/sim-consumidor-objenious/",
|
"build": "tsc --build && yarn tsc-alias -p tsconfig.json && cp -P ./.env ./package.json ../../dist/packages/sim-consumidor-objenious/",
|
||||||
|
"build:prod": "tsc --build && yarn tsc-alias -p tsconfig.json && cp -P ./package.json ../../dist/packages/sim-consumidor-objenious/",
|
||||||
"start": "node ../../dist/packages/sim-consumidor-objenious/index.js",
|
"start": "node ../../dist/packages/sim-consumidor-objenious/index.js",
|
||||||
"type:test": "tsc --noEmit"
|
"type:test": "tsc --noEmit"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -164,15 +164,16 @@ export class SimUsecases {
|
|||||||
Promise<Result<string, { iccid: string, message_id: string, operation: "preactivation" }>> {
|
Promise<Result<string, { iccid: string, message_id: string, operation: "preactivation" }>> {
|
||||||
|
|
||||||
const preActivationEvent = <SimEvents.preActivation>{
|
const preActivationEvent = <SimEvents.preActivation>{
|
||||||
key: `sim.${args.compañia}.preActivate`,
|
key: `sim.${args.compañia}.preactivate`,
|
||||||
payload: {
|
payload: {
|
||||||
iccid: args.iccid
|
iccid: args.iccid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("[d] Pre - activation ", preActivationEvent)
|
|
||||||
await this.eventBus.publish([preActivationEvent])
|
const preActivationWithId = this.addMessage_id(preActivationEvent)
|
||||||
const preactivationWithId = this.addMessage_id(preActivationEvent)
|
console.log("[d] Pre - activation ", preActivationWithId)
|
||||||
const createdOrder = await this.saveOrder<SimEvents.preActivation>(preactivationWithId)
|
await this.eventBus.publish([preActivationWithId])
|
||||||
|
const createdOrder = await this.saveOrder<SimEvents.preActivation>(preActivationWithId)
|
||||||
if (createdOrder.error != undefined) {
|
if (createdOrder.error != undefined) {
|
||||||
console.error(createdOrder.error)
|
console.error(createdOrder.error)
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node --import tsx --test ./**/*.test.ts",
|
"test": "node --import tsx --test ./**/*.test.ts",
|
||||||
"build": "tsc --build && tsc-alias -p tsconfig.json && cp package.json ../../dist/packages/sim-entrada-eventos/",
|
"build": "tsc --build && tsc-alias -p tsconfig.json && cp package.json ../../dist/packages/sim-entrada-eventos/",
|
||||||
|
"build:prod": "yarn build",
|
||||||
"dev": "tsx watch index.ts",
|
"dev": "tsx watch index.ts",
|
||||||
"start": "node ../../dist/packages/sim-entrada-eventos/index.js"
|
"start": "node ../../dist/packages/sim-entrada-eventos/index.js"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node --import tsx --test ./**/*.test.ts",
|
"test": "node --import tsx --test ./**/*.test.ts",
|
||||||
"build": "tsc --build && tsc-alias -p tsconfig.json && cp .env package.json ../../dist/packages/sim-objenious-cron/",
|
"build": "tsc --build && tsc-alias -p tsconfig.json && cp .env package.json ../../dist/packages/sim-objenious-cron/",
|
||||||
|
"build:prod": "yarn build",
|
||||||
"dev": "tsx watch index.ts",
|
"dev": "tsx watch index.ts",
|
||||||
"start": "node ../../dist/packages/sim-objenious-cron/index.js"
|
"start": "node ../../dist/packages/sim-objenious-cron/index.js"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
export type CommonSim<T> = {
|
export type CommonSim<T> = {
|
||||||
company: "NOS" | "OBJ" | "ALAI",
|
company: "NOS" | "OBJ" | "ALAI",
|
||||||
iccid: string,
|
iccid: string,
|
||||||
msisdn: string,
|
msisdn?: string,
|
||||||
tariff: string, // Depende de la compañia
|
tariff?: string, // Depende de la compañia
|
||||||
billing_status: "PREACTIVATED" | "ACTIVE" | "SUSPENDED" | "TERMINATED" | "UNKNOWN",
|
billing_status: "AVAILABLE" | "PREACTIVATED" | "ACTIVE" | "SUSPENDED" | "TERMINATED" | "UNKNOWN",
|
||||||
network_status: "AVAILABLE" | "PREACTIVATED" | "ACTIVE" | "SUSPENDED" | "TERMINATED" | "UNKNOWN",
|
network_status: "AVAILABLE" | "PREACTIVATED" | "ACTIVE" | "SUSPENDED" | "TERMINATED" | "UNKNOWN",
|
||||||
preactivation_date?: Date | null,
|
preactivation_date?: Date | null,
|
||||||
activation_date?: Date | null,
|
activation_date?: Date | null,
|
||||||
|
|||||||
@@ -18,9 +18,10 @@ export namespace SimEvents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type preActivation = DomainEvent & {
|
export type preActivation = DomainEvent & {
|
||||||
key: `sim.${string}.preActivate`,
|
key: `sim.${string}.preactivate`,
|
||||||
payload: {
|
payload: {
|
||||||
iccid: string
|
iccid: string,
|
||||||
|
orderId?: string // Solo Alai
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node --import tsx --test ./**/*.test.ts",
|
"test": "node --import tsx --test ./**/*.test.ts",
|
||||||
"dev": "echo \" Shared no es un modulo ejecutable \" ",
|
"dev": "echo \" Shared no es un modulo ejecutable \" ",
|
||||||
"build": "tsc --build && tsc-alias -p tsconfig.json && cp package.json ../../dist/packages/sim-shared/"
|
"build": "tsc --build && tsc-alias -p tsconfig.json && cp package.json ../../dist/packages/sim-shared/",
|
||||||
|
"build:prod": "yarn build"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
|||||||
13
test_api.ts
13
test_api.ts
@@ -1,35 +1,34 @@
|
|||||||
import { NosHttpClient } from "./packages/sim-consumidor-nos/infrastructure/NosHttpClient.js";
|
import { NosHttpClient } from "./packages/sim-consumidor-nos/infrastructure/NosHttpClient.js";
|
||||||
import { NosRepository } from "./packages/sim-consumidor-nos/infrastructure/NosRepository.js";
|
|
||||||
import { env } from "./packages/sim-consumidor-nos/config/env/env.js";
|
import { env } from "./packages/sim-consumidor-nos/config/env/env.js";
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
console.log("NOS_BASE_URL", env.NOS_BASE_URL);
|
console.log("NOS_BASE_URL", env.NOS_BASE_URL);
|
||||||
const client = new NosHttpClient(env.NOS_BASE_URL);
|
const client = new NosHttpClient(env.NOS_BASE_URL);
|
||||||
|
|
||||||
// Try to get a subscriber
|
// Try to get a subscriber
|
||||||
const res = await client.get("/subscribers", { params: { limit: 1 } });
|
const res = await client.get("/subscribers", { params: { limit: 1 } });
|
||||||
console.log("SUBSCRIBER:", res.data.content[0].physicalId);
|
console.log("SUBSCRIBER:", res.data.content[0].physicalId);
|
||||||
|
|
||||||
const iccid = res.data.content[0].physicalId;
|
const iccid = res.data.content[0].physicalId;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const history = await client.get(`/subscribers/${iccid}/history`);
|
const history = await client.get(`/subscribers/${iccid}/history`);
|
||||||
console.log("HISTORY:", history.data);
|
console.log("HISTORY:", history.data);
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
console.error("HISTORY ERROR");
|
console.error("HISTORY ERROR");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const audit = await client.get(`/subscribers/${iccid}/audit`);
|
const audit = await client.get(`/subscribers/${iccid}/audit`);
|
||||||
console.log("AUDIT:", audit.data);
|
console.log("AUDIT:", audit.data);
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
console.error("AUDIT ERROR");
|
console.error("AUDIT ERROR");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const actions = await client.get(`/subscribers/${iccid}/actions`);
|
const actions = await client.get(`/subscribers/${iccid}/actions`);
|
||||||
console.log("ACTIONS:", actions.data);
|
console.log("ACTIONS:", actions.data);
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
console.error("ACTIONS ERROR");
|
console.error("ACTIONS ERROR");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user