npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@stevegoossens/ofcom

v1.0.1

Published

Ofcom broadband speed and mobile coverage API clients

Downloads

5

Readme

@stevegoossens/ofcom

CI test

Client for api.ofcom.org.uk which provides Broadband speeds and Mobile coverage for each address of a specified postcode.

Ofcom API account

Create an Ofcom API account at the sign up page, and then request access to the products you wish to use:

| Name | Description | |------|-------------| | Broadband Coverage (Basic) | Subscribers can retrieve broadband coverage data against postcodes up to run 100 calls/minute for 50,000 requests per month. | | Broadband Coverage (Premium) | Subscribers can retrieve broadband coverage data against postcodes up to run 500 calls/minute for 150,000 requests per month. | | Mobile Coverage (Basic) | Subscribers can retrieve mobile coverage data against postcodes up to run 100 calls/minute for 50,000 requests per month. | | Mobile Coverage (Premium) | Subscribers can retrieve broadband coverage data against postcodes up to run 500 calls/minute for 150,000 requests per month. |

Usage

Add this as a dependency for your TypeScript/JavaScript project, create a .env file with Ofcom API credentials, and then add client code to your project.

Install

Use your chosen package manager to install this dependency:

npm install --save @stevegoossens/ofcom
yarn add @stevegoossens/ofcom
bun add @stevegoossens/ofcom

Credentials

The API keys are listed on your profile page as "Primary key" and "Secondary key" for each of the Ofcom API products that you have been granted access.

Create a .env file containing the credentials, e.g.

BROADBAND_API_KEY=abcdef1234567890
MOBILE_API_KEY=01543987abcdef

Example code

import { BroadbandApi } from "@stevegoossens/ofcom";

const broadbandApi = new BroadbandApi();

const postCode = 'BR1 2WJ';

const { data, error, response } = await broadbandApi.coverageByPostCode(postCode);
import { MobileApi } from "@stevegoossens/ofcom";

const mobileApi = new MobileApi();

const postCode = 'BR1 2WJ';

const { data, error, response } = await mobileApi.coverageByPostCode(postCode);
  • data: successful response body
  • error: error response body
  • response: the fetch Response

Development

OpenAPI

The Ofcom APIs for Broadband and Mobile are available at:

  • https://api.ofcom.org.uk/api-details#api=ofcom-connected-nations-broadband-api
  • https://api.ofcom.org.uk/api-details#api=ofcom-connected-nations-api

These can be downloaded (by clicking the "API definition" dropdown, then clicking "Open API 3 (YAML)") and copied to ./data

OpenAPI errata

There are some inaccuracies in the OpenAPI spec files for each API. These need to be corrected in the YAML before generating code from them.

Broadband errata

The OpenAPI document for Broadband API has the following errata:

  • GET /coverage/{PostCode}
    • 200 response body schema
      • is missing the Count property (type: integer)
    • 401 response is missing
      • body schema has:
        • statusCode (type: integer)
        • message (type: string)
      • headers:
        • WWW-Authenticate: AzureApiManagementKey realm="https://api-proxy.ofcom.org.uk/broadband",name="Ocp-Apim-Subscription-Key",type="header"
    • 404 response body schema
      • ErrorMessage property is actually named Error
    • 500 response body schema
      • ErrorMessage property is actually named Error
Mobile errata

The OpenAPI document for Mobile API has the following errata:

  • GET /coverage/{PostCode}
    • 200 response body schema
      • is specified as MobileAvailabilityArray when it is actually MobileAvailability
      • is missing the DBName property (type: string)
    • 401 response is missing
      • body schema has:
        • statusCode (type: integer)
        • message (type: string)
      • headers:
        • WWW-Authenticate: AzureApiManagementKey realm="https://api-proxy.ofcom.org.uk/broadband",name="Ocp-Apim-Subscription-Key",type="header"
    • 404 response body schema
      • ErrorMessage property is actually named Error
    • 500 response body schema
      • ErrorMessage property is actually named Error

Install

bun install

Generate code from OpenAPI

Clean out the previously generated code at ./src/openapi-fetch:

bun clean

Generate the API code:

bun generate:broadband
bun generate:mobile

Format

Apply code style

bun run format

Lint

Fix linting errors

bun run lint

Check

Fix linting errors and apply code style

bun run check

Test

Run unit tests

bun test

Tests with coverage

bun test --coverage

Build

bun run build

NPM

Publish package to NPM

Login to NPM repository

npm login

Open the generated URL in a browser, login, supply the MFA/2FA code.

Publish to NPM repository

First time, if the package does not exist:

npm publish --access=public

Update Table of Contents

The table of contents in this readme was generated by markdown-toc. If you add/remove headings or change the order of them, regenerate the table of contents:

bun toc