@voltcast/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Official TypeScript SDK for the Voltcast API (https://voltcast.com/docs).
3
+ *
4
+ * import { Voltcast } from "@voltcast/sdk";
5
+ * const vc = new Voltcast("YOUR_API_KEY");
6
+ * const prices = await vc.prices("DE-LU", { from: "2026-07-10", to: "2026-07-12" });
7
+ */
8
+ export interface PriceRow {
9
+ delivery_start: string;
10
+ delivery_end: string;
11
+ price_eur_mwh: number;
12
+ resolution_flag: "PT15M" | "PT60M";
13
+ source: string;
14
+ }
15
+ export interface ForecastRow {
16
+ target_start: string;
17
+ resolution_flag: "PT15M";
18
+ p50: number;
19
+ p10?: number;
20
+ p90?: number;
21
+ }
22
+ export interface Zone {
23
+ code: string;
24
+ eic_code: string;
25
+ name: string;
26
+ country_code: string;
27
+ timezone: string;
28
+ currency: string;
29
+ native_resolution: "PT15M" | "PT60M";
30
+ fifteen_min_since: string | null;
31
+ launch_zone: boolean;
32
+ }
33
+ export interface CheapestWindow {
34
+ start: string;
35
+ end: string;
36
+ avg_price_eur_mwh: number;
37
+ basis: "published" | "forecast";
38
+ }
39
+ export interface ScheduleSlot {
40
+ start: string;
41
+ end: string;
42
+ power_kw: number;
43
+ energy_kwh: number;
44
+ price_eur_mwh: number;
45
+ basis: "published" | "forecast";
46
+ }
47
+ export interface Schedule {
48
+ schedule: ScheduleSlot[];
49
+ energy_kwh: number;
50
+ expected_cost_eur: number;
51
+ baseline_cost_eur: number;
52
+ savings_eur: number;
53
+ savings_pct: number | null;
54
+ }
55
+ export interface ExportFile {
56
+ year: number;
57
+ format: "parquet" | "csv";
58
+ size_bytes: number;
59
+ url: string;
60
+ expires_at: string;
61
+ }
62
+ export interface ApiResponse<T> {
63
+ data: T;
64
+ meta: Record<string, unknown>;
65
+ }
66
+ export declare class VoltcastError extends Error {
67
+ readonly status: number;
68
+ readonly code: string | null;
69
+ constructor(status: number, code: string | null, message: string);
70
+ }
71
+ export declare class Voltcast {
72
+ #private;
73
+ constructor(apiKey: string, baseUrl?: string);
74
+ /** All bidding zones with EIC codes and resolution metadata. */
75
+ zones(): Promise<ApiResponse<Zone[]>>;
76
+ /** Day-ahead prices (defaults: yesterday → tomorrow, native resolution). */
77
+ prices(zone: string, options?: {
78
+ from?: string;
79
+ to?: string;
80
+ resolution?: "native" | "hourly";
81
+ }): Promise<ApiResponse<PriceRow[]>>;
82
+ /** Latest probabilistic forecast curve. */
83
+ forecast(zone: string, options?: {
84
+ horizon?: "48h" | "7d";
85
+ }): Promise<ApiResponse<ForecastRow[]>>;
86
+ /** Cheapest contiguous windows over the forward curve (Pro+). */
87
+ cheapestWindow(body: {
88
+ zone: string;
89
+ duration_minutes: number;
90
+ from?: string;
91
+ to?: string;
92
+ count?: number;
93
+ }): Promise<ApiResponse<CheapestWindow[]>>;
94
+ /** Cost-optimal charge/dispatch schedule (Pro+). */
95
+ schedule(body: {
96
+ zone: string;
97
+ energy_kwh: number;
98
+ max_power_kw: number;
99
+ deadline: string;
100
+ start?: string;
101
+ }): Promise<ApiResponse<Schedule>>;
102
+ /** Signed bulk-export URLs for zone-year files (Pro+). */
103
+ exportUrls(query: {
104
+ zone: string;
105
+ from: string;
106
+ to: string;
107
+ format?: "parquet" | "csv";
108
+ }): Promise<ApiResponse<ExportFile[]>>;
109
+ private request;
110
+ }
package/dist/index.js ADDED
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Official TypeScript SDK for the Voltcast API (https://voltcast.com/docs).
3
+ *
4
+ * import { Voltcast } from "@voltcast/sdk";
5
+ * const vc = new Voltcast("YOUR_API_KEY");
6
+ * const prices = await vc.prices("DE-LU", { from: "2026-07-10", to: "2026-07-12" });
7
+ */
8
+ const DEFAULT_BASE_URL = "https://voltcast.com/api";
9
+ export class VoltcastError extends Error {
10
+ status;
11
+ code;
12
+ constructor(status, code, message) {
13
+ super(`[${status}${code ? ` ${code}` : ""}] ${message}`);
14
+ this.name = "VoltcastError";
15
+ this.status = status;
16
+ this.code = code;
17
+ }
18
+ }
19
+ export class Voltcast {
20
+ #apiKey;
21
+ #baseUrl;
22
+ constructor(apiKey, baseUrl = DEFAULT_BASE_URL) {
23
+ this.#apiKey = apiKey;
24
+ this.#baseUrl = baseUrl;
25
+ }
26
+ /** All bidding zones with EIC codes and resolution metadata. */
27
+ zones() {
28
+ return this.request("GET", "/v1/zones");
29
+ }
30
+ /** Day-ahead prices (defaults: yesterday → tomorrow, native resolution). */
31
+ prices(zone, options = {}) {
32
+ return this.request("GET", `/v1/prices/${zone}`, { query: options });
33
+ }
34
+ /** Latest probabilistic forecast curve. */
35
+ forecast(zone, options = {}) {
36
+ return this.request("GET", `/v1/forecasts/${zone}`, { query: options });
37
+ }
38
+ /** Cheapest contiguous windows over the forward curve (Pro+). */
39
+ cheapestWindow(body) {
40
+ return this.request("POST", "/v1/optimize/cheapest-window", { body });
41
+ }
42
+ /** Cost-optimal charge/dispatch schedule (Pro+). */
43
+ schedule(body) {
44
+ return this.request("POST", "/v1/optimize/schedule", { body });
45
+ }
46
+ /** Signed bulk-export URLs for zone-year files (Pro+). */
47
+ exportUrls(query) {
48
+ return this.request("GET", "/v1/history/export", { query });
49
+ }
50
+ async request(method, path, options = {}) {
51
+ const url = new URL(this.#baseUrl + path);
52
+ for (const [key, value] of Object.entries(options.query ?? {})) {
53
+ if (value !== undefined)
54
+ url.searchParams.set(key, String(value));
55
+ }
56
+ const response = await fetch(url, {
57
+ method,
58
+ headers: {
59
+ Authorization: `Bearer ${this.#apiKey}`,
60
+ Accept: "application/json",
61
+ ...(options.body ? { "Content-Type": "application/json" } : {}),
62
+ },
63
+ body: options.body ? JSON.stringify(options.body) : undefined,
64
+ });
65
+ if (!response.ok) {
66
+ let code = null;
67
+ let message = response.statusText;
68
+ try {
69
+ const parsed = (await response.json());
70
+ code = parsed.error?.code ?? null;
71
+ message = parsed.error?.message ?? message;
72
+ }
73
+ catch {
74
+ /* non-JSON error body */
75
+ }
76
+ throw new VoltcastError(response.status, code, message);
77
+ }
78
+ return (await response.json());
79
+ }
80
+ }
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@voltcast/sdk",
3
+ "version": "0.1.0",
4
+ "description": "Official TypeScript SDK for the Voltcast API — 15-minute European power prices and probabilistic forecasts.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": ["dist"],
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "test": "node --test --experimental-strip-types test/client.test.ts"
18
+ },
19
+ "keywords": ["electricity", "prices", "epex", "day-ahead", "forecast", "energy", "api"],
20
+ "license": "MIT",
21
+ "homepage": "https://voltcast.com/docs",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/Voltcast-com/sdk.git",
25
+ "directory": "typescript"
26
+ },
27
+ "devDependencies": {
28
+ "typescript": "^5.6.0",
29
+ "@types/node": "^22.0.0"
30
+ }
31
+ }