Skip to content

SolarNetwork/solarnetwork-example-ts-datum-loader

Repository files navigation

SolarNetwork Example: TypeScript Datum Loader

This project is a little web app to show the basics of using the SolarNetwork API in a TypeScript project to download large sets of datum stream data using the DatumLoader helper class.

You can see the example in action here:

https://go.solarnetwork.net/dev/example/typescript-datum-loader/

Screenshot of the TypeScript Datum Loader app

Key aspects

There are a few key aspects of this example worth pointing out.

SolarNetwork API

The solarnetwork-api-core package is included in the project, which provides helpful utilities in both TypeScript and JavaScript for querying datum streams with the SolarNetwork API.

{
	"dependencies": {
		"solarnetwork-api-core": "^3.1.2"
	}
}

Token authentication

The example demonstrates using the SolarNetwork token authentication support included with the solarnetwork-datum-loader library.

First the demo imports the AuthorizationV2Builder class and creates a reusable instance in an auth variable:

import { AuthorizationV2Builder } from "solarnetwork-api-core/net";

const auth = new AuthorizationV2Builder();

A change form event handler listens for changes to the form's token and secret fields, and saves the credentials for future API calls:

// save credentials
auth.tokenId = settingsForm.snToken.value;
auth.saveSigningKey(settingsForm.snTokenSecret.value);

Building from source

To build yourself, clone or download this repository. You need to have Node 20+ installed. Then:

# initialize dependencies
npm ci

# run development live server on http://localhost:8080
npm run dev

# build for production
npm run build

Running the build script will generate the application into the dist/ directory.

About

Example web app using the solarnetwork-datum-loader package to query SolarNetwork for large data sets, using TypeScript.

Topics

Resources

Stars

Watchers

Forks