Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@energy-tracker/api-client",
"version": "2.1.0",
"version": "2.2.0",
"description": "Typed async client for the Energy Tracker public API",
"license": "MIT",
"author": "Stefan Nebel",
Expand Down
2 changes: 1 addition & 1 deletion src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class Transport {
this.#calculationTimeout = timeout(options.calculationTimeout ?? 60);
let url: URL;
try {
url = new URL(options.baseUrl ?? 'https://public-api.energy-tracker.best-ios-apps.de');
url = new URL(options.baseUrl ?? 'https://public-api.energy-tracker.app');
} catch (cause) {
throw new ValidationError('Base URL must be a valid HTTP(S) URL', { cause });
}
Expand Down
10 changes: 10 additions & 0 deletions tests/client.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ for (const url of [
test(`reject unsafe base URL ${url}`, () =>
assert.throws(() => client({ baseUrl: url }), api.ValidationError));
}
test('default base URL is the public API host', async () => {
let actual;
await client({
fetch: async (url) => {
actual = url;
return new Response(null, { status: 204 });
},
}).meterReadings.create('device', { value: '1' });
assert.equal(actual.origin, 'https://public-api.energy-tracker.app');
});
for (const value of [123.45, NaN, Infinity, 'NaN', 'Infinity', '', '1e3']) {
test(`reject lossy or invalid decimal input ${String(value)}`, async () => {
let requests = 0;
Expand Down