From da2413002b526152648ff5521328422add1bd024 Mon Sep 17 00:00:00 2001 From: Alvar San Martin Date: Fri, 17 Apr 2026 14:06:41 +0200 Subject: [PATCH] Repositorio de nos completo --- docs/sim-nos/environments/local.yml | 5 + docs/sim-nos/environments/prod.yml | 7 ++ docs/sim-nos/opencollection.yml | 10 ++ docs/sim-nos/subscriber actions.yml | 22 ++++ docs/sim-nos/subscriber info.yml | 22 ++++ .../sim-nos/subscriber products available.yml | 22 ++++ docs/sim-nos/subscribers.yml | 22 ++++ .../aplication/SimNOS.usecases.ts | 26 ++-- packages/sim-consumidor-nos/domain/NosAPI.ts | 95 ++++++++++++-- .../infrastructure/NOSRepository.ts | 117 ++++++++++++++++++ .../infrastructure/NosHttpClient.ts | 8 ++ packages/sim-consumidor-nos/tsconfig.json | 3 +- .../sim-consumidor-objenious/tsconfig.json | 1 + 13 files changed, 337 insertions(+), 23 deletions(-) create mode 100644 docs/sim-nos/environments/local.yml create mode 100644 docs/sim-nos/environments/prod.yml create mode 100644 docs/sim-nos/opencollection.yml create mode 100644 docs/sim-nos/subscriber actions.yml create mode 100644 docs/sim-nos/subscriber info.yml create mode 100644 docs/sim-nos/subscriber products available.yml create mode 100644 docs/sim-nos/subscribers.yml create mode 100644 packages/sim-consumidor-nos/infrastructure/NOSRepository.ts diff --git a/docs/sim-nos/environments/local.yml b/docs/sim-nos/environments/local.yml new file mode 100644 index 0000000..7a2fe1b --- /dev/null +++ b/docs/sim-nos/environments/local.yml @@ -0,0 +1,5 @@ +name: local +color: "#2E8A54" +variables: + - name: baseulr + value: http://localhost:3000 diff --git a/docs/sim-nos/environments/prod.yml b/docs/sim-nos/environments/prod.yml new file mode 100644 index 0000000..080fcff --- /dev/null +++ b/docs/sim-nos/environments/prod.yml @@ -0,0 +1,7 @@ +name: prod +color: "#CE4F3B" +variables: + - name: baseurl + value: https://nosconnectcenter-api.iot-x.com + - secret: true + name: token diff --git a/docs/sim-nos/opencollection.yml b/docs/sim-nos/opencollection.yml new file mode 100644 index 0000000..e88b0ef --- /dev/null +++ b/docs/sim-nos/opencollection.yml @@ -0,0 +1,10 @@ +opencollection: 1.0.0 + +info: + name: sim-nos +bundled: false +extensions: + bruno: + ignore: + - node_modules + - .git diff --git a/docs/sim-nos/subscriber actions.yml b/docs/sim-nos/subscriber actions.yml new file mode 100644 index 0000000..7740ead --- /dev/null +++ b/docs/sim-nos/subscriber actions.yml @@ -0,0 +1,22 @@ +info: + name: subscriber actions + type: http + seq: 1 + +http: + method: GET + url: "{{baseurl}}/subscribers/{{iccid}}/actions" + auth: + type: bearer + token: "{{token}}" + +runtime: + variables: + - name: iccid + value: "8935103196306448300" + +settings: + encodeUrl: true + timeout: 0 + followRedirects: true + maxRedirects: 5 diff --git a/docs/sim-nos/subscriber info.yml b/docs/sim-nos/subscriber info.yml new file mode 100644 index 0000000..0b2098c --- /dev/null +++ b/docs/sim-nos/subscriber info.yml @@ -0,0 +1,22 @@ +info: + name: subscriber info + type: http + seq: 2 + +http: + method: GET + url: "{{baseurl}}/subscribers/{{iccid}}" + auth: + type: bearer + token: "{{token}}" + +runtime: + variables: + - name: iccid + value: "8935103196306448300" + +settings: + encodeUrl: true + timeout: 0 + followRedirects: true + maxRedirects: 5 diff --git a/docs/sim-nos/subscriber products available.yml b/docs/sim-nos/subscriber products available.yml new file mode 100644 index 0000000..926b413 --- /dev/null +++ b/docs/sim-nos/subscriber products available.yml @@ -0,0 +1,22 @@ +info: + name: subscriber products available + type: http + seq: 4 + +http: + method: GET + url: "{{baseurl}}/subscribers/{{iccid}}/products/available" + auth: + type: bearer + token: "{{token}}" + +runtime: + variables: + - name: iccid + value: "8935103196306448300" + +settings: + encodeUrl: true + timeout: 0 + followRedirects: true + maxRedirects: 5 diff --git a/docs/sim-nos/subscribers.yml b/docs/sim-nos/subscribers.yml new file mode 100644 index 0000000..5cab8a5 --- /dev/null +++ b/docs/sim-nos/subscribers.yml @@ -0,0 +1,22 @@ +info: + name: subscribers + type: http + seq: 3 + +http: + method: GET + url: "{{baseurl}}/subscribers" + auth: + type: bearer + token: "{{token}}" + +runtime: + variables: + - name: iccid + value: "8935103196306448300" + +settings: + encodeUrl: true + timeout: 0 + followRedirects: true + maxRedirects: 5 diff --git a/packages/sim-consumidor-nos/aplication/SimNOS.usecases.ts b/packages/sim-consumidor-nos/aplication/SimNOS.usecases.ts index 0352c88..b418472 100644 --- a/packages/sim-consumidor-nos/aplication/SimNOS.usecases.ts +++ b/packages/sim-consumidor-nos/aplication/SimNOS.usecases.ts @@ -6,30 +6,28 @@ * - Control de errores más preciso * */ - import { NosHttpClient } from "infrastructure/NosHttpClient"; +import { NosRepository } from "infrastructure/NOSRepository"; export class SimNosUsecases { constructor( - private httpClient: NosHttpClient + private httpClient: NosHttpClient, + private nosRepository: NosRepository ) { } public activate() { - const PATH = '/provisioning' - const PRODUCT_ID = 1330 // No se que es, preguntar a Ivan - - return async (args: { iccid: string }) => { - const data = { - productSetId: PRODUCT_ID - } - try { - const res = await this.httpClient.client.post(PATH, data) - } catch (e) { - console.error(e) - } + return (args: { iccid: string }) => { } } + public suspend() { + + } + + public terminate() { + + } + } diff --git a/packages/sim-consumidor-nos/domain/NosAPI.ts b/packages/sim-consumidor-nos/domain/NosAPI.ts index 77bbc04..c093ff5 100644 --- a/packages/sim-consumidor-nos/domain/NosAPI.ts +++ b/packages/sim-consumidor-nos/domain/NosAPI.ts @@ -1,5 +1,6 @@ export namespace NosApi { - export type ActivateResponseOK = { + + export type ActivationData = { /** The unique physical subscriber identifier: Cellular - the ICCID @@ -11,7 +12,7 @@ export namespace NosApi { /** example: 447000000001 The unique network subscriber identifier: - + Cellular subscriber - the MSISDN Non - IP subscriber - the Device EUI Satellite subscriber - the Subscription ID @@ -35,14 +36,92 @@ export namespace NosApi { The subscriber IMSI. */ imsi: string + } - export type ActivateResponseError = { - error: { - children: string, - code: string, - messafe: string + type OkResponse = { + error?: undefined | null, + content: T + } + + type ErrorResponse = { + content?: undefined | null, + error: E + } + + type GeneralError = { + children?: string[], + code: string, + message: string + } + + export type ActivateResponseOK = OkResponse + export type ActivateResponseError = ErrorResponse + export type ActivateResponse = ActivateResponseOK | ActivateResponseError + + export type LineDataResponseOK = OkResponse + export type LineDataResponseError = ErrorResponse + export type LineDataResponse = LineDataResponseOK | LineDataResponseError + + export type LineData = { + physicalId: string + subscriberId: string + imsi: string + nickname: string + operatorCode: string + tariffName: string + lineRental: number + contractLength: number + isBarred: boolean + isActive: boolean + terminateDate: any + groupId: number + subscriberType: any + connectionDate: string + expiryDate: string + networkState: NetworkState + billingState: BillingState + operatorName: string + imei: string + dataUsage?: number + eid?: string + smdpProvider?: string + related?: { + parent: RelatedItem, + profiles: RelatedItem[] } - } + + type RelatedItem = { + physicalId: string + isEnabledOnParent: boolean + } + + export type NetworkState = { + currentStateId: number + currentState: string + isTransferring: boolean + lastTransferred: number + isOnline: boolean + lastSeenOnline: number + } + + export type BillingState = { + currentStateId: number + currentState: string + } + + export type BarData = { + product: string + description: string + enabled: boolean + } + + export type BarResponseOk = OkResponse + export type BarResponseError = ErrorResponse + export type BarResponse = BarResponseOk | BarResponseError + + } + + diff --git a/packages/sim-consumidor-nos/infrastructure/NOSRepository.ts b/packages/sim-consumidor-nos/infrastructure/NOSRepository.ts new file mode 100644 index 0000000..67163a7 --- /dev/null +++ b/packages/sim-consumidor-nos/infrastructure/NOSRepository.ts @@ -0,0 +1,117 @@ +import { Result } from "sim-shared/domain/Result.js"; +import { NosHttpClient } from "./NosHttpClient"; +import { NosApi } from "#domain/NosAPI.js"; +import axios, { AxiosError, AxiosResponse } from "axios"; + +export class NosRepository { + constructor( + private httpClient: NosHttpClient + ) { + } + + /** + * E => Tipo de error + * T => Tipo de dato para cod 200 + * + * TODO: + * - Mejor gestion de los errores + * - E no se aplica todavia por no hacer la transformacion del error + */ + private async manageNosRequest(promise: Promise>): Promise> { + try { + const res = await promise + return { + data: res.data + } + } catch (e) { + if (axios.isAxiosError(e)) { + const error = e as AxiosError + return { + error: error.code + " : " + JSON.stringify(error.response) + } + } else { + return { + error: JSON.stringify(e) + } + } + } + } + + public async getLineInfo(iccid: string): Promise> { + const PATH = "/subscribers/" + iccid + + const req = this.httpClient.post(PATH) + const resp = await this.manageNosRequest(req) + + if (resp.error != undefined) { + return resp + } else { + return { + data: resp.data.content + } + } + } + + public async activateSim(iccid: string): Promise> { + const PATH = '/provisioning' + const PRODUCT_ID = 1330 // No se que es, preguntar a Ivan + const data = { + productSetId: PRODUCT_ID + } + + const req = this.httpClient.post(PATH, data) + const resp = await this.manageNosRequest(req) + + if (resp.error != undefined) { + return resp + } else { + return { + data: resp.data.content + } + } + } + + /** + * "A bar is a service provisioning action that results in a subscriber being blocked from accessing an operator's network. The bar remains in place until the operator is sent an unbar request." + * Se entiende que un "bar" es una suspension temporal + */ + public async bar(iccid: string) { + const PATH = `/subscribers/${iccid}/products` + const data = { + product: "BAR DN TOTAL", + action: "enable" + } + + const req = this.httpClient.post(PATH, data) + const resp = await this.manageNosRequest(req) + + if (resp.error != undefined) { + return resp + } else { + return { + data: resp.data.content + } + } + } + + public async unbar(iccid: string) { + const PATH = `/subscribers/${iccid}/products` + const data = { + product: "BAR DN TOTAL", + action: "disable" + } + + const req = this.httpClient.post(PATH, data) + const resp = await this.manageNosRequest(req) + + if (resp.error != undefined) { + return resp + } else { + return { + data: resp.data.content + } + } + + } + +} diff --git a/packages/sim-consumidor-nos/infrastructure/NosHttpClient.ts b/packages/sim-consumidor-nos/infrastructure/NosHttpClient.ts index 35e24ab..c0dc46c 100644 --- a/packages/sim-consumidor-nos/infrastructure/NosHttpClient.ts +++ b/packages/sim-consumidor-nos/infrastructure/NosHttpClient.ts @@ -25,5 +25,13 @@ export class NosHttpClient { ) } + get post() { + return this.client.post + } + + get get() { + return this.client.get + } + } diff --git a/packages/sim-consumidor-nos/tsconfig.json b/packages/sim-consumidor-nos/tsconfig.json index c508953..90eddd0 100644 --- a/packages/sim-consumidor-nos/tsconfig.json +++ b/packages/sim-consumidor-nos/tsconfig.json @@ -9,7 +9,8 @@ ], "include": [ "**/*.ts", - "src/**/*.d.ts" + "**/*.d.ts", + "../../packages/sim-shared/**/*.ts" ], "files": [ "index.ts" diff --git a/packages/sim-consumidor-objenious/tsconfig.json b/packages/sim-consumidor-objenious/tsconfig.json index c027227..43ffe23 100644 --- a/packages/sim-consumidor-objenious/tsconfig.json +++ b/packages/sim-consumidor-objenious/tsconfig.json @@ -9,6 +9,7 @@ ], "include": [ "**/*.ts", + "**/*.d.ts", "../../packages/sim-shared/**/*.ts" ] }