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/
There are a few key aspects of this example worth pointing out.
The solarnetwork-datum-loader package is included in the project, which provides many helpful utilities in both TypeScript and JavaScript for working with the SolarNetwork API.
{
"dependencies": {
"solarnetwork-datum-loader": "^2.0.0"
}
}
The example demonstrates using SolarNetwork token authentication with the browser Fetch API.
First the demo imports the AuthorizationV2Builder class and creates a reusable instance in an auth
variable:
import { AuthorizationV2Builder } from "solarnetwork-api-core/lib/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);
To build yourself, clone or download this repository. You need to have Node 16+ 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.