iturri 0.2.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/index.mjs +9 -2
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -3,13 +3,20 @@
|
|
|
3
3
|
// Data and tooling only — never signals, predictions, or financial advice.
|
|
4
4
|
|
|
5
5
|
export const BASE_URL = "https://iturri.ai";
|
|
6
|
+
|
|
7
|
+
// membership token: setToken("...") or ITURRI_TOKEN env (node)
|
|
8
|
+
export let token = (typeof process !== "undefined" && process.env?.ITURRI_TOKEN) || null;
|
|
9
|
+
export const setToken = (t) => { token = t; };
|
|
10
|
+
const authHeaders = () => (token ? { authorization: `Bearer ${token}` } : {});
|
|
6
11
|
export const QUALITY = ["verified", "raw", "reconciled", "interpolated", "disputed", "outage"];
|
|
7
12
|
|
|
8
13
|
async function get(path, params) {
|
|
9
14
|
const url = new URL(BASE_URL + path);
|
|
10
15
|
for (const [k, v] of Object.entries(params ?? {}))
|
|
11
16
|
if (v !== undefined && v !== null) url.searchParams.set(k, v);
|
|
12
|
-
const r = await fetch(url);
|
|
17
|
+
const r = await fetch(url, { headers: authHeaders() });
|
|
18
|
+
if (r.status === 402)
|
|
19
|
+
throw new Error("402 payment required — setToken()/ITURRI_TOKEN with a membership token from https://iturri.ai/subscribe, or pay per-call with an x402 client");
|
|
13
20
|
if (!r.ok) throw new Error(`iturri api ${r.status}: ${(await r.json()).error ?? r.statusText}`);
|
|
14
21
|
return r.json();
|
|
15
22
|
}
|
|
@@ -55,7 +62,7 @@ export const validate = (symbol, tf, o = {}) => get("/api/validate", { symbol, t
|
|
|
55
62
|
/** Signed download URLs: pack "crypto"|"equities", or "tokens" with a symbol. */
|
|
56
63
|
export async function bundle(pack, symbol) {
|
|
57
64
|
const r = await fetch(BASE_URL + "/api/bundle", {
|
|
58
|
-
method: "POST", headers: { "content-type": "application/json" },
|
|
65
|
+
method: "POST", headers: { "content-type": "application/json", ...authHeaders() },
|
|
59
66
|
body: JSON.stringify({ pack, symbol }),
|
|
60
67
|
});
|
|
61
68
|
if (!r.ok) throw new Error(`iturri api ${r.status}`);
|