Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f7c052572 | |||
| 3d9e2a6e9b | |||
| f94ee799d0 | |||
| d1e5892a0d | |||
| b14464da39 | |||
| cf6204e231 | |||
| 9d8788db39 | |||
| 79ceb74604 | |||
| d02b1d48bf | |||
| 1fb50323b0 |
@@ -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/"
|
|
||||||
|
|||||||
@@ -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,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"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/*"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,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) {
|
||||||
@@ -180,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)
|
||||||
}
|
}
|
||||||
@@ -195,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)
|
||||||
}
|
}
|
||||||
@@ -228,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)
|
||||||
|
|
||||||
@@ -239,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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user