Repositorio de nos completo
This commit is contained in:
5
docs/sim-nos/environments/local.yml
Normal file
5
docs/sim-nos/environments/local.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
name: local
|
||||
color: "#2E8A54"
|
||||
variables:
|
||||
- name: baseulr
|
||||
value: http://localhost:3000
|
||||
7
docs/sim-nos/environments/prod.yml
Normal file
7
docs/sim-nos/environments/prod.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
name: prod
|
||||
color: "#CE4F3B"
|
||||
variables:
|
||||
- name: baseurl
|
||||
value: https://nosconnectcenter-api.iot-x.com
|
||||
- secret: true
|
||||
name: token
|
||||
10
docs/sim-nos/opencollection.yml
Normal file
10
docs/sim-nos/opencollection.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
opencollection: 1.0.0
|
||||
|
||||
info:
|
||||
name: sim-nos
|
||||
bundled: false
|
||||
extensions:
|
||||
bruno:
|
||||
ignore:
|
||||
- node_modules
|
||||
- .git
|
||||
22
docs/sim-nos/subscriber actions.yml
Normal file
22
docs/sim-nos/subscriber actions.yml
Normal file
@@ -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
|
||||
22
docs/sim-nos/subscriber info.yml
Normal file
22
docs/sim-nos/subscriber info.yml
Normal file
@@ -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
|
||||
22
docs/sim-nos/subscriber products available.yml
Normal file
22
docs/sim-nos/subscriber products available.yml
Normal file
@@ -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
|
||||
22
docs/sim-nos/subscribers.yml
Normal file
22
docs/sim-nos/subscribers.yml
Normal file
@@ -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
|
||||
@@ -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() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<T> = {
|
||||
error?: undefined | null,
|
||||
content: T
|
||||
}
|
||||
|
||||
type ErrorResponse<E = GeneralError> = {
|
||||
content?: undefined | null,
|
||||
error: E
|
||||
}
|
||||
|
||||
type GeneralError = {
|
||||
children?: string[],
|
||||
code: string,
|
||||
message: string
|
||||
}
|
||||
|
||||
export type ActivateResponseOK = OkResponse<ActivationData>
|
||||
export type ActivateResponseError = ErrorResponse
|
||||
export type ActivateResponse = ActivateResponseOK | ActivateResponseError
|
||||
|
||||
export type LineDataResponseOK = OkResponse<LineData>
|
||||
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<BarData>
|
||||
export type BarResponseError = ErrorResponse
|
||||
export type BarResponse = BarResponseOk | BarResponseError
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
117
packages/sim-consumidor-nos/infrastructure/NOSRepository.ts
Normal file
117
packages/sim-consumidor-nos/infrastructure/NOSRepository.ts
Normal file
@@ -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<E, T>(promise: Promise<AxiosResponse<T>>): Promise<Result<string, T>> {
|
||||
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<Result<string, NosApi.LineData>> {
|
||||
const PATH = "/subscribers/" + iccid
|
||||
|
||||
const req = this.httpClient.post<NosApi.LineDataResponseOK>(PATH)
|
||||
const resp = await this.manageNosRequest<string, NosApi.LineDataResponseOK>(req)
|
||||
|
||||
if (resp.error != undefined) {
|
||||
return resp
|
||||
} else {
|
||||
return {
|
||||
data: resp.data.content
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async activateSim(iccid: string): Promise<Result<string, NosApi.ActivationData>> {
|
||||
const PATH = '/provisioning'
|
||||
const PRODUCT_ID = 1330 // No se que es, preguntar a Ivan
|
||||
const data = {
|
||||
productSetId: PRODUCT_ID
|
||||
}
|
||||
|
||||
const req = this.httpClient.post<NosApi.ActivateResponseOK>(PATH, data)
|
||||
const resp = await this.manageNosRequest<string, NosApi.ActivateResponseOK>(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<NosApi.BarResponseOk>(PATH, data)
|
||||
const resp = await this.manageNosRequest<string, NosApi.BarResponseOk>(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<NosApi.BarResponseOk>(PATH, data)
|
||||
const resp = await this.manageNosRequest<string, NosApi.BarResponseOk>(req)
|
||||
|
||||
if (resp.error != undefined) {
|
||||
return resp
|
||||
} else {
|
||||
return {
|
||||
data: resp.data.content
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,5 +25,13 @@ export class NosHttpClient {
|
||||
)
|
||||
}
|
||||
|
||||
get post() {
|
||||
return this.client.post
|
||||
}
|
||||
|
||||
get get() {
|
||||
return this.client.get
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
],
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
"src/**/*.d.ts"
|
||||
"**/*.d.ts",
|
||||
"../../packages/sim-shared/**/*.ts"
|
||||
],
|
||||
"files": [
|
||||
"index.ts"
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
],
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
"**/*.d.ts",
|
||||
"../../packages/sim-shared/**/*.ts"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user