final touches for beta skymoney (at least i think)

This commit is contained in:
2026-01-18 00:00:44 -06:00
parent 4eae966f96
commit f4f0ae5df2
161 changed files with 26016 additions and 1966 deletions

View File

@@ -88,7 +88,6 @@ export type FetchLike = typeof fetch;
export type SDKOptions = {
baseUrl?: string;
userId?: string;
fetch?: FetchLike;
requestIdFactory?: () => string; // to set x-request-id if desired
};
@@ -107,14 +106,9 @@ export class SkyMoney {
readonly baseUrl: string;
private readonly f: FetchLike;
private readonly reqId?: () => string;
userId?: string;
constructor(opts: SDKOptions = {}) {
this.baseUrl = (opts.baseUrl || "http://localhost:8080").replace(/\/+$/, "");
this.userId = opts.userId ?? (
// Try localStorage if present (browser)
typeof localStorage !== "undefined" ? localStorage.getItem("x-user-id") || undefined : undefined
);
this.f = opts.fetch || fetch;
this.reqId = opts.requestIdFactory;
}
@@ -128,12 +122,12 @@ export class SkyMoney {
): Promise<T> {
const url = `${this.baseUrl}${path}${query ? makeQuery(query) : ""}`;
const h: Record<string, string> = { ...(headers || {}) };
if (this.userId) h["x-user-id"] = this.userId;
if (this.reqId) h["x-request-id"] = this.reqId();
const hasBody = body !== undefined && body !== null;
const res = await this.f(url, {
method,
credentials: "include",
headers: {
...(hasBody ? { "content-type": "application/json" } : {}),
...h,