@varek/sdk 0.1.0 → 0.2.1
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.
- package/README.md +2 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -2
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @varek/sdk — Typed TypeScript client for the VAREK public API.
|
|
3
|
-
* Docs: https://varek.fi/docs/docs/
|
|
3
|
+
* Docs: https://varek.fi/docs/api (interactive reference) · https://varek.fi/docs/asetukset/rajapinta
|
|
4
4
|
*/
|
|
5
5
|
import type { components } from "./openapi-types.js";
|
|
6
6
|
export type Defect = components["schemas"]["Defect"];
|
|
@@ -22,6 +22,17 @@ export interface VarekClientOptions {
|
|
|
22
22
|
baseUrl?: string;
|
|
23
23
|
/** Custom fetch implementation (defaults to global fetch) */
|
|
24
24
|
fetch?: typeof fetch;
|
|
25
|
+
/**
|
|
26
|
+
* Per-request timeout in milliseconds (default 30000). Set 0 to disable.
|
|
27
|
+
* Backed by AbortSignal.timeout when available.
|
|
28
|
+
*/
|
|
29
|
+
timeoutMs?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Allow a non-https baseUrl. Default false. Your API key is sent as a Bearer
|
|
32
|
+
* header to the configured host, so only enable this for local testing
|
|
33
|
+
* against a host you trust — never for a public/untrusted endpoint.
|
|
34
|
+
*/
|
|
35
|
+
allowInsecure?: boolean;
|
|
25
36
|
}
|
|
26
37
|
export declare class VarekApiError extends Error {
|
|
27
38
|
readonly type: string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,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MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,2EAA2E;IAC3E,MAAM,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;gBAExB,OAAO,EAAE,OAAO;CAQ7B;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7D,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvC,UAAU,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3D,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;CACtC;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAoF1E"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @varek/sdk — Typed TypeScript client for the VAREK public API.
|
|
3
|
-
* Docs: https://varek.fi/docs/docs/
|
|
3
|
+
* Docs: https://varek.fi/docs/api (interactive reference) · https://varek.fi/docs/asetukset/rajapinta
|
|
4
4
|
*/
|
|
5
5
|
export class VarekApiError extends Error {
|
|
6
6
|
type;
|
|
@@ -26,14 +26,34 @@ export class VarekApiError extends Error {
|
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
28
|
export function createVarekClient(options) {
|
|
29
|
-
const { apiKey, baseUrl = "https://api.varek.fi/v1", fetch: fetchImpl = globalThis.fetch, } = options;
|
|
29
|
+
const { apiKey, baseUrl = "https://api.varek.fi/v1", fetch: fetchImpl = globalThis.fetch, timeoutMs = 30_000, allowInsecure = false, } = options;
|
|
30
|
+
// Validate the base URL up front: every request attaches the API key as a
|
|
31
|
+
// Bearer header to `${base}${path}`, so a malformed or non-https host would
|
|
32
|
+
// silently leak the key. Fail fast instead of sending the credential.
|
|
33
|
+
let parsed;
|
|
34
|
+
try {
|
|
35
|
+
parsed = new URL(baseUrl);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw new Error(`VarekClient: invalid baseUrl "${baseUrl}"`);
|
|
39
|
+
}
|
|
40
|
+
if (parsed.protocol !== "https:" && !allowInsecure) {
|
|
41
|
+
throw new Error(`VarekClient: refusing to send the API key over a non-https baseUrl ("${baseUrl}"). ` +
|
|
42
|
+
`Pass allowInsecure: true only for local testing against a trusted host.`);
|
|
43
|
+
}
|
|
30
44
|
const base = baseUrl.replace(/\/$/, "");
|
|
31
45
|
async function request(path) {
|
|
46
|
+
const signal = timeoutMs > 0 &&
|
|
47
|
+
typeof AbortSignal !== "undefined" &&
|
|
48
|
+
typeof AbortSignal.timeout === "function"
|
|
49
|
+
? AbortSignal.timeout(timeoutMs)
|
|
50
|
+
: undefined;
|
|
32
51
|
const response = await fetchImpl(`${base}${path}`, {
|
|
33
52
|
headers: {
|
|
34
53
|
Authorization: `Bearer ${apiKey}`,
|
|
35
54
|
Accept: "application/json",
|
|
36
55
|
},
|
|
56
|
+
...(signal ? { signal } : {}),
|
|
37
57
|
});
|
|
38
58
|
if (!response.ok) {
|
|
39
59
|
let problem;
|