Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript Types #14

Open
izakfilmalter opened this issue Jun 16, 2020 · 13 comments
Open

Typescript Types #14

izakfilmalter opened this issue Jun 16, 2020 · 13 comments

Comments

@izakfilmalter
Copy link

izakfilmalter commented Jun 16, 2020

Here is my initial attempt at some really bad ts types for the lib. Still missing a lot of things, and crossing my eyes between the docs and the lib probably caused some errors.

The following still don't have types:

  export function Site(): void
  export function SipPeer(): void
  export const RateCenter: List<{}, {}>

  export function TnReservation(): void
  export function PortIn(): void
  export function PortOut(): void

  export const LnpChecker: {
    check: Array<unknown>
    checkAsync: Array<unknown>
  }

  export function User(): void

  export function LsrOrder(): void

  export function RemoveImportedTnOrder(): void
declare module '@bandwidth/numbers' {
  type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Pick<
    T,
    Exclude<keyof T, Keys>
  > &
    {
      [K in Keys]-?: Required<Pick<T, K>> &
        Partial<Record<Exclude<Keys, K>, unknown>>
    }[Keys]

  type Callback<T> = (error: Error | null, data: T) => void

  type DateStr = string

  type State = 'MA' | string
  type Country = 'United States' | string
  type VendorId = 49 | number
  type VendorName = 'Bandwidth CLEC' | string
  type Tier = 1 | 2 | 3 | 4 | 5

  type Links = {
    first: string
    last?: string
  }

  type TelephoneNumberType = {
    city: string
    lata: number
    state: State
    fullNumber: string
    tier: Tier
    vendorId: VendorId
    vendorName: VendorName
    onNetVendor: boolean
    rateCenter: string
    status: 'Inservice'
    accountId: number
    lastModified: DateStr
    client: Client.Client
  }

  type Query = {
    page: string | number
    size: number
  }

  // Client

  namespace Client {
    function getIdFromHeader(): void

    function getIdFromLocationHeader(): void

    function getIdFromHeaderAsync(): void

    function getIdFromLocationHeaderAsync(): void

    const globalOptions: {
      apiEndPoint: string
      userName: string
      password: string
      accountId: string
    }

    interface Client {
      prepareRequest: () => void
      concatAccountPath: () => void
      prepareUrl: () => void
      xml2jsParserOptions: {
        explicitArray: boolean
        tagNameProcessors: Array<null>
        async: boolean
      }
    }
  }

  export function Client(
    accountId: string,
    userName: string,
    password: string,
  ): Client.Client

  type List<T extends object, Q extends object> = {
    list: (query: Q, callback: Callback<T>) => void
    listAsync: (query: Q) => Promise<T>
  }

  // Account

  type AccountGetResult = {
    accountId: number
    globalAccountNumber: string
    associatedCatapultAccount: number
    companyName: string
    accountType: 'Business' | string
    tiers: { tier: Array<Tier> }
    address: {
      houseNumber: number
      streetName: string
      city: string
      stateCode: State
      zip: number
      country: Country
      addressType: 'Service' | string
    }
    contact: {
      firstName: string
      lastName: string
      phone: string
      email: string
    }
    sPID: 'mult' | string
    portCarrierType: 'WIRELINE' | string
    default911Provider: 'EVS' | string
    customerSegment: 'Wholesale' | string
  }

  namespace Account {
    function get(callback: Callback<AccountGetResult>): void
    function get(
      client: Client.Client,
      callback: Callback<AccountGetResult>,
    ): void

    function getAsync(): Promise<AccountGetResult>
    function getAsync(client: Client.Client): Promise<AccountGetResult>
  }

  // AvailableNpaNxx

  type AvailableNpaNxxListQuery = RequireOnlyOne<
    {
      areaCode?: number
      quantity?: number
      state?: State
    },
    'areaCode' | 'quantity' | 'state'
  >

  type AvailableNpaNxxListResult = Array<{
    city: string
    npa: number
    nxx: number
    quantity: number
    state: State
  }>

  namespace AvailableNpaNxx {
    function list(
      query: AvailableNpaNxxListQuery,
      callback: Callback<AvailableNpaNxxListResult>,
    ): void
    function list(
      client: Client.Client,
      query: AvailableNpaNxxListQuery,
      callback: Callback<AvailableNpaNxxListResult>,
    ): void

    function listAsync(
      query: AvailableNpaNxxListQuery,
    ): Promise<AvailableNpaNxxListResult>
    function listAsync(
      client: Client.Client,
      query: AvailableNpaNxxListQuery,
    ): Promise<AvailableNpaNxxListResult>
  }

  // AvailableNumbers

  type AvailableNumbersListQuery = RequireOnlyOne<
    {
      LCA?: boolean
      areaCode?: number | string
      city?: string
      enableTNDetail?: boolean
      endsIn?: boolean
      lata?: number
      localVanity?: string
      npaNxx?: number | string
      npaNxxx?: number | string
      orderBy?: 'fullNumber' | 'npaNxxx' | 'npaNxx' | 'areaCode'
      rateCenter?: string
      state?: State
      tollFreeVanity?: string
      tollFreeWildCardPattern?: string
      zip?: number
      quantity?: number
    },
    | 'LCA'
    | 'areaCode'
    | 'city'
    | 'enableTNDetail'
    | 'endsIn'
    | 'lata'
    | 'localVanity'
    | 'npaNxx'
    | 'npaNxxx'
    | 'orderBy'
    | 'rateCenter'
    | 'state'
    | 'tollFreeVanity'
    | 'tollFreeWildCardPattern'
    | 'zip'
  >

  type AvailableNumbersListResult = {
    resultCount: number
    telephoneNumberList: {
      telephoneNumber: Array<string>
    }
  }

  namespace AvailableNumbers {
    function list(
      query: AvailableNumbersListQuery,
      callback: Callback<AvailableNpaNxxListResult>,
    ): void
    function list(
      client: Client.Client,
      query: AvailableNumbersListQuery,
      callback: Callback<AvailableNpaNxxListResult>,
    ): void

    function listAsync(
      query: AvailableNumbersListQuery,
    ): Promise<AvailableNpaNxxListResult>
    function listAsync(
      client: Client.Client,
      query: AvailableNumbersListQuery,
    ): Promise<AvailableNpaNxxListResult>
  }

  // City

  type CityListQuery = {
    available?: boolean
    state: State
    supported?: boolean
  }

  type CityListResult = Array<{
    rcAbbreviation: string
    name: string
  }>

  namespace City {
    function list(
      query: CityListQuery,
      callback: Callback<CityListResult>,
    ): void
    function list(
      client: Client.Client,
      query: CityListQuery,
      callback: Callback<CityListResult>,
    ): void

    function listAsync(query: CityListQuery): Promise<CityListResult>
    function listAsync(
      client: Client.Client,
      query: CityListQuery,
    ): Promise<CityListResult>
  }

  // CoveredRateCenter

  type CoveredRateCenterQuery = Query & {
    abbreviation?: string
    city?: string
    embed?:
      | 'ZipCodes'
      | 'Cities'
      | 'Vendors'
      | 'Npa'
      | 'NpaNxxX'
      | 'AvailableNumberCount'
      | 'LimitedAvailableNumberCount'
      | 'LocalRateCenters'
    lata?: string
    name?: string
    npa?: number
    npaNxx?: number
    npaNxxX?: number
    state?: State
    tier?: Tier
    zip?: number
  }

  type CoveredRateCenterResult = Array<{
    id: number
    name: string
    abbreviation: string
    state: State
    lata: number
    tiers: {
      tier: Tier
    }
  }>

  namespace CoveredRateCenter {
    function list(
      query: CoveredRateCenterQuery,
      callback: Callback<CoveredRateCenterResult>,
    ): void
    function list(
      client: Client.Client,
      query: CoveredRateCenterQuery,
      callback: Callback<CoveredRateCenterResult>,
    ): void

    function listAsync(
      query: CoveredRateCenterQuery,
    ): Promise<CoveredRateCenterResult>
    function listAsync(
      client: Client.Client,
      query: CoveredRateCenterQuery,
    ): Promise<CoveredRateCenterResult>
  }

  // CsrOrder

  // Wasn't able to test any of the CsrOrder endpoints so these are my best guess based on the api reference.
  type CsrOrderGetResult = {
    customerOrderId: string
    lastModifiedBy: string
    orderCreateDate: DateStr
    accountId: number
    orderId: string
    lastModifiedDate: DateStr
    status: OrderStatus
    accountNumber: number
    accountTelephoneNumber: number
    endUserName: string
    authorizingUserName: string
    customerCode: number
    endUserPIN: number
    addressLine1: string
    city: string
    state: State
    zipCode: number
    typeOfService: 'residential' | string
    csrData: {
      accountNumber: number
      customerName: string
      serviceAddress: {
        unparsedAddress: string
        city: string
        state: State
        zip: number
      }
      workingTelephoneNumber: number
      workingTelephoneNumbersOnAccount: {
        telephoneNumber: number
      }
    }
  }

  namespace CsrOrder {
    function get(id: string, callback: Callback<CsrOrderGetResult>): void
    function get(
      client: Client.Client,
      id: string,
      callback: Callback<CsrOrderGetResult>,
    ): void

    function getAsync(id: string): Promise<CsrOrderGetResult>
    function getAsync(
      client: Client.Client,
      id: string,
    ): Promise<CsrOrderGetResult>

    // Can't find create in the api reference so unsure what the types are.
    function create(date: unknown, callback: Callback<unknown>): void
    function create(
      client: Client.Client,
      date: unknown,
      callback: Callback<unknown>,
    ): void

    function createAsync(date: unknown): Promise<unknown>
    function createAsync(client: Client.Client, date: unknown): Promise<unknown>
  }

  export function CsrOrder(): void

  // DiscNumber

  // Wasn't able to test this fully since I had no disconnected numbers.

  namespace DiscNumber {
    type DiscNumberListQuery = Query & { enddate?: string; startdate?: string }

    type DiscNumberListResult = {
      count: number
      telephoneNumber?: Array<string>
    }

    type DiscNumberTotalResult = {
      count: number
    }

    function list(
      query: DiscNumberListQuery,
      callback: Callback<DiscNumberListResult>,
    ): void
    function list(
      client: Client.Client,
      query: DiscNumberListQuery,
      callback: Callback<DiscNumberListResult>,
    ): void

    function listAsync(
      query: DiscNumberListQuery,
    ): Promise<DiscNumberListResult>
    function listAsync(
      client: Client.Client,
      query: DiscNumberListQuery,
    ): Promise<DiscNumberListResult>

    function totals(callback: Callback<DiscNumberTotalResult>): void
    function totals(
      client: Client.Client,
      callback: Callback<DiscNumberTotalResult>,
    ): void

    function totalsAsync(client?: Client.Client): Promise<DiscNumberTotalResult>
  }

  // Disconnect

  namespace Disconnect {
    type DisconnectListQuery = Query & {
      enddate?: string
      startdate?: string
      status?: 'complete' | string
      userid?: string
    }

    type DisconnectListResult = {
      ListOrderIdUserIdDate: {
        TotalCount: number
        Links: Links
        OrderIdUserIdDate: Array<{
          CountOfTNs: number
          userId: string
          lastModifiedDate: DateStr
          OrderId: string
          OrderType: 'disconnect' | string
          OrderDate: DateStr
          OrderStatus: OrderStatus
          TelephoneNumberDetails: {}
        }>
      }
    }

    type DisconnectGetQuery = {
      tndetail?: boolean
    }

    function create(
      orderName: string,
      numbers: Array<string>,
      callback: Callback<unknown>,
    ): void
    function create(
      client: Client.Client,
      orderName: string,
      numbers: Array<string>,
      callback: Callback<unknown>,
    ): void

    function createAsync(
      orderName: string,
      numbers: Array<string>,
    ): Promise<unknown>
    function createAsync(
      client: Client.Client,
      orderName: string,
      numbers: Array<string>,
    ): Promise<unknown>

    function list(
      query: DisconnectListQuery,
      callback: Callback<DisconnectListResult>,
    ): void
    function list(
      client: Client.Client,
      query: DisconnectListQuery,
      callback: Callback<DisconnectListResult>,
    ): void

    function listAsync(
      query: DisconnectListQuery,
    ): Promise<DisconnectListResult>
    function listAsync(
      client: Client.Client,
      query: DisconnectListQuery,
    ): Promise<DisconnectListResult>

    function get(
      id: string,
      query: DisconnectGetQuery,
      callback: Callback<unknown>,
    ): void
    function get(
      client: Client.Client,
      id: string,
      query: DisconnectGetQuery,
      callback: Callback<unknown>,
    ): void

    function getAsync(id: string, query: DisconnectGetQuery): Promise<unknown>
    function getAsync(
      client: Client.Client,
      id: string,
      query: DisconnectGetQuery,
    ): Promise<unknown>
  }

  export function Disconnect(): void

  // Dlda

  namespace Dlda {
    type DldaCreateItem = {
      customerOrderId: string
      dldaTnGroups: {
        dldaTnGroup: {
          telephoneNumbers: { telephoneNumber: string }
          subscriberType: 'RESIDENTIAL' | string
          listingType: 'LISTED' | string
          listingName: {
            firstName: string
            lastName: string
          }
          listAddress: boolean
          address: {
            houseNumber: number
            streetName: string
            streetSuffix: string
            city: string
            stateCode: State
            zip: number
            addressType: 'DLDA' | string
          }
        }
      }
    }

    type DldaListQuery = {
      lastModifiedAfter?: string
      modifiedDateFrom?: string
      modifiedDateTo?: string
      tn?: string
    }

    type DldaListResult = {
      listOrderIdUserIdDate: { totalCount: number }
    }

    function create(item: DldaCreateItem, callback: Callback<unknown>): void
    function create(
      client: Client.Client,
      item: DldaCreateItem,
      callback: Callback<unknown>,
    ): void

    function createAsync(item: DldaCreateItem): Promise<unknown>
    function createAsync(
      client: Client.Client,
      item: DldaCreateItem,
    ): Promise<unknown>

    function list(
      query: DldaListQuery,
      callback: Callback<DldaListResult>,
    ): void
    function list(
      client: Client.Client,
      query: DldaListQuery,
      callback: Callback<DldaListResult>,
    ): void

    function listAsync(query: DldaListQuery): Promise<DldaListResult>
    function listAsync(
      client: Client.Client,
      query: DldaListQuery,
    ): Promise<DldaListResult>

    function get(id: string, callback: Callback<unknown>): void
    function get(
      client: Client.Client,
      id: string,
      callback: Callback<unknown>,
    ): void

    function getAsync(id: string): Promise<unknown>
    function getAsync(client: Client.Client, id: string): Promise<unknown>
  }

  export function Dlda(): void

  // ImportTnChecker

  namespace ImportTnChecker {
    type ImportTnCheckerResult = {
      importTnCheckerPayload: {
        telephoneNumbers: number
        importTnErrors?: {
          importTnError: {
            code: 19005 | number
            description:
              | 'Messaging route of External Third Party TNs is not configured.'
              | string
            telephoneNumbers: { telephoneNumber: string }
          }
        }
      }
    }

    function check(
      numbers: Array<string>,
      callback: Callback<ImportTnCheckerResult>,
    ): void
    function check(
      client: Client.Client,
      numbers: Array<string>,
      callback: Callback<ImportTnCheckerResult>,
    ): void

    function checkAsync(numbers: Array<string>): Promise<ImportTnCheckerResult>
    function checkAsync(
      client: Client.Client,
      numbers: Array<string>,
    ): Promise<ImportTnCheckerResult>
  }

  // ImportTnOrder

  namespace ImportTnOrder {
    type ImportTnOrderData = {
      customerOrderID: string
      siteId: number
      sipPeerId: number
      subscriber: {
        mame: string
        serviceAddress: {
          houseNumber: number
          streetName: string
          city: string
          stateCode: State
          zip: number
          county: string
        }
      }
      loaAuthorizingPerson: string
      loaType: 'CARRIER' | string
      telephoneNumbers: {
        telephoneNumber: Array<string>
      }
    }

    type ImportTnOrderListQuery = {
      createdDateFrom?: string
      createdDateTo?: string
      customerOrderId?: string
      loaType?: 'CARRIER' | 'SUBSCRIBER'
      modifiedDateFrom?: string
      status?: 'RECEIVED' | 'PROCESSING' | 'COMPLETE' | 'PARTIAL' | 'FAILED'
      tn?: string
    }

    type ImportTnOrderListResult = {
      totalCount: number
    }

    function create(
      data: ImportTnOrderData,
      numbers: Array<string>,
      callback: Callback<unknown>,
    ): void
    function create(
      client: Client.Client,
      data: ImportTnOrderData,
      numbers: Array<string>,
      callback: Callback<unknown>,
    ): void

    function createAsync(
      data: ImportTnOrderData,
      numbers: Array<string>,
    ): Promise<unknown>
    function createAsync(
      client: Client.Client,
      data: ImportTnOrderData,
      numbers: Array<string>,
    ): Promise<unknown>

    function get(id: string, callback: Callback<unknown>): void
    function get(
      client: Client.Client,
      id: string,
      callback: Callback<unknown>,
    ): void

    function getAsync(id: string): Promise<unknown>
    function getAsync(client: Client.Client, id: string): Promise<unknown>

    function list(
      query: ImportTnOrderListQuery,
      callback: Callback<ImportTnOrderListResult>,
    ): void
    function list(
      client: Client.Client,
      query: ImportTnOrderListQuery,
      callback: Callback<ImportTnOrderListResult>,
    ): void

    function listAsync(
      query: ImportTnOrderListQuery,
    ): Promise<ImportTnOrderListResult>
    function listAsync(
      client: Client.Client,
      query: ImportTnOrderListQuery,
    ): Promise<ImportTnOrderListResult>
  }

  export function ImportTnOrder(): void

  // ImportToAccount

  namespace ImportToAccount {
    function create(item: unknown, callback: Callback<unknown>): void
    function create(
      client: Client.Client,
      item: unknown,
      callback: Callback<unknown>,
    ): void

    function createAsync(item: unknown): Promise<unknown>
    function createAsync(client: Client.Client, item: unknown): Promise<unknown>

    function list(query: unknown, callback: Callback<unknown>): void
    function list(
      client: Client.Client,
      query: unknown,
      callback: Callback<unknown>,
    ): void

    function listAsync(query: unknown): Promise<unknown>
    function listAsync(client: Client.Client, query: unknown): Promise<unknown>
  }

  export function ImportToAccount(): void

  // InServiceNumber

  namespace InServiceNumber {
    type InServiceNumberListQuery = Query & {
      areacode?: string
      enddate?: string
      lata?: number
      npanxx?: number
      ratecenter?: string
      startdate?: string
      state?: State
    }

    type InServiceNumberListResult = {
      totalCount: number
      links: Links
      telephoneNumbers: {
        count: number
        telephoneNumber: string | Array<string>
      }
    }

    type InServiceNumberTotalsResult = {
      count: number
    }

    type InServiceNumberGetResult = {}

    function list(
      query: InServiceNumberListQuery,
      callback: Callback<InServiceNumberListResult>,
    ): void
    function list(
      client: Client.Client,
      query: InServiceNumberListQuery,
      callback: Callback<InServiceNumberListResult>,
    ): void

    function listAsync(
      query: InServiceNumberListQuery,
    ): Promise<InServiceNumberListResult>
    function listAsync(
      client: Client.Client,
      query: InServiceNumberListQuery,
    ): Promise<InServiceNumberListResult>

    function totals(callback: Callback<InServiceNumberTotalsResult>): void
    function totals(
      client: Client.Client,
      callback: Callback<InServiceNumberTotalsResult>,
    ): void

    function totalsAsync(
      client?: Client.Client,
    ): Promise<InServiceNumberTotalsResult>

    function get(
      number: string,
      callback: Callback<InServiceNumberGetResult>,
    ): void
    function get(
      client: Client.Client,
      number: string,
      callback: Callback<InServiceNumberGetResult>,
    ): void

    function getAsync(number: string): Promise<InServiceNumberGetResult>
    function getAsync(
      client: Client.Client,
      number: string,
    ): Promise<InServiceNumberGetResult>
  }

  // Lidbs

  namespace Lidbs {
    type LidbsCreateItem = {
      customerOrderId: string
      lidbTnGroups: {
        lidbTnGroup: Array<{
          telephoneNumbers: {
            telephoneNumber: Array<string>
          }
          subscriberInformation: string
          useType: 'RESIDENTIAL' | 'BUSINESS'
          visibility: 'PUBLIC' | 'PRIVATE'
        }>
      }
    }

    function create(item: LidbsCreateItem, callback: Callback<unknown>): void
    function create(
      client: Client.Client,
      item: LidbsCreateItem,
      callback: Callback<unknown>,
    ): void

    function createAsync(item: LidbsCreateItem): Promise<unknown>
    function createAsync(
      client: Client.Client,
      item: LidbsCreateItem,
    ): Promise<unknown>

    function list(): void

    function get(): void
  }

  export function Lidbs(): void

  // Order

  type OrderStatus = 'BACKORDERED' | 'COMPLETE' | 'PARTIAL' | 'FAILED'

  type CreateOrderType = {
    name: string
    siteId: number
    existingTelephoneNumberOrderType: {
      telephoneNumberList: Array<{
        telephoneNumber: string
      }>
    }
  }

  type CreateOrderResult = {
    Order: {
      customerOrderId: string
      id: string
      name: string
      orderCreateDate: DateStr
      backOrderRequested: boolean
      ZIPSearchAndOrderType: {
        quantity: number
        zip: number
      }
      tnAttributes: Array<'Protected' | 'External' | 'Imported'>
      partialAllowed: boolean
      siteId: number
    }
  }

  type OrderGetResult = {
    completedQuantity: number
    createdByUser: string
    errorList: number
    failedNumbers: number
    lastModifiedDate: DateStr
    orderCompleteDate: DateStr
    order: {
      orderCreateDate: DateStr
      peerId: number
      backOrderRequested: boolean
      existingTelephoneNumberOrderType: {
        telephoneNumberList: { telephoneNumber: string }
      }
      partialAllowed: boolean
      siteId: number
      client: Client.Client
    }
    orderStatus: OrderStatus
    completedNumbers: { telephoneNumber: { fullNumber: string } }
    summary: string
    failedQuantity: number
  }

  type OrderListQuery = Query & {
    customerOrderId?: string
    enddate?: string
    status: OrderStatus
    startdate?: string
    userid?: string
  }

  type OrderListResult = {
    listOrderIdUserIdDate: {
      totalCount: number
      links: Links
      orderIdUserIdDate: {
        accountId: number
        countOfTNs: number
        userId: string
        lastModifiedDate: DateStr
        orderDate: DateStr
        orderType: 'new_number'
        orderId: string
        orderStatus: OrderStatus
        summary: string
        telephoneNumberDetails: {
          states: { stateWithCount: { state: State; count: number } }
          rateCenters: {
            rateCenterWithCount: { count: number; rateCenter: string }
          }
          cities: { cityWithCount: { city: string; count: number } }
          tiers: { tierWithCount: { tier: Tier; count: number } }
          vendors: {
            vendorWithCount: {
              vendorId: VendorId
              vendorName: VendorName
              count: number
            }
          }
        }
      }
    }
  }

  namespace Order {
    // create
    function create(
      order: CreateOrderType,
      callback: Callback<CreateOrderResult>,
    ): void
    function create(
      client: Client.Client,
      order: CreateOrderType,
      callback: Callback<CreateOrderResult>,
    ): void

    function createAsync(order: CreateOrderType): Promise<CreateOrderResult>
    function createAsync(
      client: Client.Client,
      order: CreateOrderType,
    ): Promise<CreateOrderResult>

    // get
    function get(id: string, callback: Callback<OrderGetResult>): void
    function get(
      client: Client.Client,
      id: string,
      callback: Callback<OrderGetResult>,
    ): void

    function getAsync(id: string): Promise<OrderGetResult>
    function getAsync(
      client: Client.Client,
      id: string,
    ): Promise<OrderGetResult>

    // list
    function list(
      query: OrderListQuery,
      callback: Callback<OrderListResult>,
    ): void
    function list(
      client: Client.Client,
      query: OrderListQuery,
      callback: Callback<OrderListResult>,
    ): void

    function listAsync(query: OrderListQuery): Promise<OrderListResult>
    function listAsync(
      client: Client.Client,
      query: OrderListQuery,
    ): Promise<OrderListResult>
  }

  export function Order(): undefined

  // TN
  type TnStatus = 'Inservice' | string

  type TnGetResult = {
    telephoneNumber: string
    status: TnStatus
    lastModifiedDate: DateStr
    orderCreateDate: DateStr
    orderId: string
    orderType: 'NEW_NUMBER_ORDER' | string
    inServiceDate: DateStr
    siteId: number
    accountId: number
    client: Client.Client
  }

  type TnListQuery = Query & {
    accountId?: string | number
    city?: string
    fullNumber?: string | number
    host?: string
    lata?: number
    npa?: string | number
    npaNxx?: string | number
    rateCenter?: string
    state?: State
    tier?: Tier
  }

  type TnListResult = {
    telephoneNumberCount: number
    links: Links
    telephoneNumbers: {
      telephoneNumber: Array<{
        city: string
        lata: number
        state: State
        fullNumber: string
        tier: Tier
        vendorId: VendorId
        status: TnStatus
        accountId: number
        lastModified: DateStr
        client: Client.Client
      }>
    }
  }

  namespace Tn {
    // get
    function get(number: string, callback: Callback<TnGetResult>): void
    function get(
      client: Client.Client,
      number: string,
      callback: Callback<TnGetResult>,
    ): void

    function getAsync(number: string): Promise<TnGetResult>
    function getAsync(
      client: Client.Client,
      number: string,
    ): Promise<TnGetResult>

    // list
    function list(query: TnListQuery, callback: Callback<TnListResult>): void
    function list(
      client: Client.Client,
      query: TnListQuery,
      callback: Callback<TnListResult>,
    ): void

    function listAsync(query: TnListQuery): Promise<TnListResult>
    function listAsync(
      client: Client.Client,
      query: TnListQuery,
    ): Promise<TnListResult>
  }

  export function Tn(): undefined

  // Subscription
  type SubscriptionOrderType =
    | 'portins'
    | 'orders'
    | 'portouts'
    | 'disconnects'
    | 'dldas'
    | 'lsrorders'
    | 'e911s'
    | 'tnoptions'
    | 'externalTns'
    | 'lidb'
    | 'bulkPortins'
    | 'importtnorders'
    | 'importtnorders'
    | 'csrs'

  type SubscriptionType = {
    subscriptionId: string
    orderType: SubscriptionOrderType
    callbackSubscription: {
      uRL: string
      expiry: string
      status: 'READY'
    }
    client: Client.Client
  }

  type CreateSubscriptionType = {
    orderType: SubscriptionOrderType
    callbackSubscription: {
      uRL: string
      expiry: number | string
      callbackCredentials?:
        | {
            basicAuthentication: {
              userName: string
              password: string
            }
          }
        | {
            publicKey: string
          }
    }
  }

  namespace Subscription {
    function get(id: string, callback: Callback<unknown>): void
    function get(
      client: Client.Client,
      id: string,
      callback: Callback<unknown>,
    ): void

    function getAsync(id: string): Promise<unknown>
    function getAsync(client: Client.Client, id: string): Promise<unknown>

    function list(
      query: unknown,
      callback: Callback<Array<SubscriptionType>>,
    ): void
    function list(
      client: Client.Client,
      query: unknown,
      callback: Callback<Array<SubscriptionType>>,
    ): void

    function listAsync(query: unknown): Promise<Array<SubscriptionType>>
    function listAsync(
      client: Client.Client,
      query: unknown,
    ): Promise<Array<SubscriptionType>>

    function create(
      item: CreateSubscriptionType,
      callback: Callback<SubscriptionType>,
    ): void
    function create(
      client: Client.Client,
      item: CreateSubscriptionType,
      callback: Callback<SubscriptionType>,
    ): void

    function createAsync(
      item: CreateSubscriptionType,
    ): Promise<SubscriptionType>
    function createAsync(
      client: Client.Client,
      item: CreateSubscriptionType,
    ): Promise<SubscriptionType>
  }

  export function Subscription(): void

  export function Site(): void
  export function SipPeer(): void

  export const RateCenter: List<{}, {}>

  export function TnReservation(): void
  export function PortIn(): void
  export function PortOut(): void

  export const LnpChecker: {
    check: Array<unknown>
    checkAsync: Array<unknown>
  }

  export function User(): void

  export function LsrOrder(): void

  export function RemoveImportedTnOrder(): void
}

Update 7/1/2021

  • Stubbed out Subscription
@willchertoff
Copy link

You are a god. Will try out and report back.

@statico
Copy link

statico commented Oct 21, 2021

I'd love to see this merged!

@statico
Copy link

statico commented Oct 21, 2021

I've tried this but I get an error I don't fully understand. I guess the types are exporting two things named Client, a namespace and a constructor?

I have import { Client as NumbersClient } from "@bandwidth/numbers" above this:

CleanShot 2021-10-21 at 11 55 34

@izakfilmalter
Copy link
Author

@statico You need to make a bandwidthNumbers.d.ts file and paste in the types into it.

It should just work then when you import. Don't need to do casting.

If it doesn't work, you will have to fiddle with your typeRoots field within tsconfig.json

@statico
Copy link

statico commented Oct 27, 2021

Thanks for helping. It's definitely finding the types, yet that error still occurs. I'm not sure why the types declare both a namespace and export a function with the same name. We're on TypeScript 4.4.2 BTW.

@izakfilmalter
Copy link
Author

izakfilmalter commented Oct 27, 2021 via email

@statico
Copy link

statico commented Oct 28, 2021

Thanks. I can't even get this module to work, and I'm guessing it's TypeScript.

import Numbers from "@bandwidth/numbers"

const numbers = new Numbers.Client(accountId, username, password)

const listAvailableDids = async (pattern?: string | null) => {
  try {
    const response = await numbers.AvailableNumbers.listAsync({
      tollFreeVanity: pattern ? pattern.replace(/\W/g, "") : "",
      quantity: "5",
    })
...

Gets me:

TypeError: Cannot read property 'listAsync' of undefined

@izakfilmalter
Copy link
Author

izakfilmalter commented Oct 28, 2021 via email

@izakfilmalter
Copy link
Author

import * as BandwidthNumbers from '@bandwidth/numbers'
import * as functions from 'firebase-functions'
import { Config } from 'types/functionsTypes'

BandwidthNumbers.Client.globalOptions.accountId = (
  functions.config() as Config
).bandwidth['account-id']

BandwidthNumbers.Client.globalOptions.userName = (
  functions.config() as Config
).bandwidth['user-name']

BandwidthNumbers.Client.globalOptions.password = (
  functions.config() as Config
).bandwidth.password

export const BandwidthNumbersClient = BandwidthNumbers

@statico
Copy link

statico commented Oct 28, 2021

That at least seems to make a request, but now I'm getting 400 Bad Request — the same error I got when trying the HTTP API directly. I'll keep digging.

Actually, that seems to work! I can inspect the thrown Error object and see some XML with a detailed error. I'll take it from here. Thanks for your help! Looking forward to a native TypeScript package :)

@izakfilmalter
Copy link
Author

My types are for v1.5 of the package as well. They are probably a little out of date.

@bchrobot
Copy link

Thank you @izakfilmalter!

It would be great to see this get adopted especially as other Bandwidth SDKs like @bandwidth/messaging get types.

@christopher-svensson-freespee

Thanks @izakfilmalter. Would love to see this merged too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants