@ragable/sdk 0.6.0 → 0.6.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/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +60 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -90,6 +90,7 @@ type RequestOptions = Omit<RequestInit, "body"> & {
|
|
|
90
90
|
declare abstract class RagableSdkError extends Error {
|
|
91
91
|
abstract readonly __type: string;
|
|
92
92
|
constructor(message: string);
|
|
93
|
+
toJSON(): Record<string, unknown>;
|
|
93
94
|
}
|
|
94
95
|
declare class RagableError extends RagableSdkError {
|
|
95
96
|
readonly __type: "RagableError";
|
|
@@ -98,11 +99,13 @@ declare class RagableError extends RagableSdkError {
|
|
|
98
99
|
readonly code: string | undefined;
|
|
99
100
|
readonly details: string | undefined;
|
|
100
101
|
constructor(message: string, status: number, body: unknown);
|
|
102
|
+
toJSON(): Record<string, unknown>;
|
|
101
103
|
}
|
|
102
104
|
declare class RagableNetworkError extends RagableSdkError {
|
|
103
105
|
readonly __type: "RagableNetworkError";
|
|
104
106
|
readonly cause: unknown;
|
|
105
107
|
constructor(message: string, cause?: unknown);
|
|
108
|
+
toJSON(): Record<string, unknown>;
|
|
106
109
|
}
|
|
107
110
|
declare class RagableAbortError extends RagableSdkError {
|
|
108
111
|
readonly __type: "RagableAbortError";
|
|
@@ -112,6 +115,7 @@ declare class RagableTimeoutError extends RagableSdkError {
|
|
|
112
115
|
readonly __type: "RagableTimeoutError";
|
|
113
116
|
readonly timeoutMs: number;
|
|
114
117
|
constructor(timeoutMs: number);
|
|
118
|
+
toJSON(): Record<string, unknown>;
|
|
115
119
|
}
|
|
116
120
|
declare function extractErrorMessage(payload: unknown, fallback: string): string;
|
|
117
121
|
declare class RagableRequestClient {
|
package/dist/index.d.ts
CHANGED
|
@@ -90,6 +90,7 @@ type RequestOptions = Omit<RequestInit, "body"> & {
|
|
|
90
90
|
declare abstract class RagableSdkError extends Error {
|
|
91
91
|
abstract readonly __type: string;
|
|
92
92
|
constructor(message: string);
|
|
93
|
+
toJSON(): Record<string, unknown>;
|
|
93
94
|
}
|
|
94
95
|
declare class RagableError extends RagableSdkError {
|
|
95
96
|
readonly __type: "RagableError";
|
|
@@ -98,11 +99,13 @@ declare class RagableError extends RagableSdkError {
|
|
|
98
99
|
readonly code: string | undefined;
|
|
99
100
|
readonly details: string | undefined;
|
|
100
101
|
constructor(message: string, status: number, body: unknown);
|
|
102
|
+
toJSON(): Record<string, unknown>;
|
|
101
103
|
}
|
|
102
104
|
declare class RagableNetworkError extends RagableSdkError {
|
|
103
105
|
readonly __type: "RagableNetworkError";
|
|
104
106
|
readonly cause: unknown;
|
|
105
107
|
constructor(message: string, cause?: unknown);
|
|
108
|
+
toJSON(): Record<string, unknown>;
|
|
106
109
|
}
|
|
107
110
|
declare class RagableAbortError extends RagableSdkError {
|
|
108
111
|
readonly __type: "RagableAbortError";
|
|
@@ -112,6 +115,7 @@ declare class RagableTimeoutError extends RagableSdkError {
|
|
|
112
115
|
readonly __type: "RagableTimeoutError";
|
|
113
116
|
readonly timeoutMs: number;
|
|
114
117
|
constructor(timeoutMs: number);
|
|
118
|
+
toJSON(): Record<string, unknown>;
|
|
115
119
|
}
|
|
116
120
|
declare function extractErrorMessage(payload: unknown, fallback: string): string;
|
|
117
121
|
declare class RagableRequestClient {
|
package/dist/index.js
CHANGED
|
@@ -84,6 +84,13 @@ var RagableSdkError = class extends Error {
|
|
|
84
84
|
super(message);
|
|
85
85
|
this.name = this.constructor.name;
|
|
86
86
|
}
|
|
87
|
+
toJSON() {
|
|
88
|
+
return {
|
|
89
|
+
name: this.name,
|
|
90
|
+
message: this.message,
|
|
91
|
+
__type: this.__type
|
|
92
|
+
};
|
|
93
|
+
}
|
|
87
94
|
};
|
|
88
95
|
var RagableError = class extends RagableSdkError {
|
|
89
96
|
constructor(message, status, body) {
|
|
@@ -95,11 +102,17 @@ var RagableError = class extends RagableSdkError {
|
|
|
95
102
|
__publicField(this, "details");
|
|
96
103
|
this.status = status;
|
|
97
104
|
this.body = body;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
this.code = body && typeof body === "object" ? typeof body.code === "string" ? body.code : void 0 : void 0;
|
|
106
|
+
this.details = body && typeof body === "object" ? typeof body.details === "string" ? body.details : void 0 : void 0;
|
|
107
|
+
}
|
|
108
|
+
toJSON() {
|
|
109
|
+
return {
|
|
110
|
+
...super.toJSON(),
|
|
111
|
+
status: this.status,
|
|
112
|
+
body: this.body,
|
|
113
|
+
code: this.code,
|
|
114
|
+
details: this.details
|
|
115
|
+
};
|
|
103
116
|
}
|
|
104
117
|
};
|
|
105
118
|
var RagableNetworkError = class extends RagableSdkError {
|
|
@@ -109,6 +122,12 @@ var RagableNetworkError = class extends RagableSdkError {
|
|
|
109
122
|
__publicField(this, "cause");
|
|
110
123
|
this.cause = cause;
|
|
111
124
|
}
|
|
125
|
+
toJSON() {
|
|
126
|
+
return {
|
|
127
|
+
...super.toJSON(),
|
|
128
|
+
cause: this.cause instanceof Error ? this.cause.message : this.cause
|
|
129
|
+
};
|
|
130
|
+
}
|
|
112
131
|
};
|
|
113
132
|
var RagableAbortError = class extends RagableSdkError {
|
|
114
133
|
constructor(message = "Request aborted") {
|
|
@@ -123,6 +142,12 @@ var RagableTimeoutError = class extends RagableSdkError {
|
|
|
123
142
|
__publicField(this, "timeoutMs");
|
|
124
143
|
this.timeoutMs = timeoutMs;
|
|
125
144
|
}
|
|
145
|
+
toJSON() {
|
|
146
|
+
return {
|
|
147
|
+
...super.toJSON(),
|
|
148
|
+
timeoutMs: this.timeoutMs
|
|
149
|
+
};
|
|
150
|
+
}
|
|
126
151
|
};
|
|
127
152
|
function extractErrorMessage(payload, fallback) {
|
|
128
153
|
if (payload && typeof payload === "object") {
|
|
@@ -639,7 +664,15 @@ async function asPostgrestResponse(fn) {
|
|
|
639
664
|
const data = await fn();
|
|
640
665
|
return { data, error: null };
|
|
641
666
|
} catch (e) {
|
|
642
|
-
|
|
667
|
+
let err;
|
|
668
|
+
if (e instanceof RagableError) {
|
|
669
|
+
err = e;
|
|
670
|
+
} else if (e instanceof RagableSdkError) {
|
|
671
|
+
err = new RagableError(e.message, 0, { originalError: e.__type, cause: e.message });
|
|
672
|
+
} else {
|
|
673
|
+
const message = e instanceof Error ? e.message : typeof e === "string" ? e : "Unknown error";
|
|
674
|
+
err = new RagableError(message, 0, null);
|
|
675
|
+
}
|
|
643
676
|
return { data: null, error: err };
|
|
644
677
|
}
|
|
645
678
|
}
|
|
@@ -1986,8 +2019,10 @@ function normalizeBrowserApiBase(baseUrl) {
|
|
|
1986
2019
|
function requireAuthGroupId(options) {
|
|
1987
2020
|
const id = options.authGroupId?.trim();
|
|
1988
2021
|
if (!id) {
|
|
1989
|
-
throw new
|
|
1990
|
-
"authGroupId is required for auth and database methods on the browser client"
|
|
2022
|
+
throw new RagableError(
|
|
2023
|
+
"authGroupId is required for auth and database methods on the browser client",
|
|
2024
|
+
400,
|
|
2025
|
+
{ code: "SDK_MISSING_AUTH_GROUP_ID" }
|
|
1991
2026
|
);
|
|
1992
2027
|
}
|
|
1993
2028
|
return id;
|
|
@@ -2002,8 +2037,10 @@ async function requireAccessToken(options, ragableAuth) {
|
|
|
2002
2037
|
const token = await getter();
|
|
2003
2038
|
if (token?.trim()) return token.trim();
|
|
2004
2039
|
}
|
|
2005
|
-
throw new
|
|
2006
|
-
"No access token available
|
|
2040
|
+
throw new RagableError(
|
|
2041
|
+
"No access token available. Sign in first with auth.signInWithPassword() or provide getAccessToken callback.",
|
|
2042
|
+
401,
|
|
2043
|
+
{ code: "SDK_NO_ACCESS_TOKEN" }
|
|
2007
2044
|
);
|
|
2008
2045
|
}
|
|
2009
2046
|
async function resolveDatabaseAuthBearer(options, ragableAuth) {
|
|
@@ -2014,8 +2051,10 @@ async function resolveDatabaseAuthBearer(options, ragableAuth) {
|
|
|
2014
2051
|
const fromGetter = options.getDataStaticKey ? await options.getDataStaticKey() : null;
|
|
2015
2052
|
const key = (fromGetter?.trim() || options.dataStaticKey?.trim()) ?? "";
|
|
2016
2053
|
if (!key) {
|
|
2017
|
-
throw new
|
|
2018
|
-
mode === "publicAnon" ? "dataAuth publicAnon requires getDataStaticKey or dataStaticKey" : "dataAuth admin requires getDataStaticKey or dataStaticKey"
|
|
2054
|
+
throw new RagableError(
|
|
2055
|
+
mode === "publicAnon" ? "dataAuth publicAnon requires getDataStaticKey or dataStaticKey" : "dataAuth admin requires getDataStaticKey or dataStaticKey",
|
|
2056
|
+
400,
|
|
2057
|
+
{ code: "SDK_MISSING_STATIC_KEY" }
|
|
2019
2058
|
);
|
|
2020
2059
|
}
|
|
2021
2060
|
return key;
|
|
@@ -2248,13 +2287,16 @@ var RagableBrowser = class {
|
|
|
2248
2287
|
from(table, databaseInstanceId) {
|
|
2249
2288
|
const id = databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
|
|
2250
2289
|
if (!id) {
|
|
2251
|
-
throw new
|
|
2252
|
-
"RagableBrowser.from() requires databaseInstanceId in client options or as the second argument"
|
|
2290
|
+
throw new RagableError(
|
|
2291
|
+
"RagableBrowser.from() requires databaseInstanceId in client options or as the second argument",
|
|
2292
|
+
400,
|
|
2293
|
+
{ code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
|
|
2253
2294
|
);
|
|
2254
2295
|
}
|
|
2255
2296
|
const gid = requireAuthGroupId(this.options);
|
|
2256
2297
|
const ragableAuth = this._ragableAuth;
|
|
2257
2298
|
const opts = this.options;
|
|
2299
|
+
const transport = this.transport;
|
|
2258
2300
|
const pgFetch = async (params) => {
|
|
2259
2301
|
const token = await resolveDatabaseAuthBearer(opts, ragableAuth);
|
|
2260
2302
|
const baseUrl = normalizeBrowserApiBase(opts.baseUrl);
|
|
@@ -2271,15 +2313,13 @@ var RagableBrowser = class {
|
|
|
2271
2313
|
headers.set(k, v);
|
|
2272
2314
|
}
|
|
2273
2315
|
}
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
}
|
|
2277
|
-
const fetchImpl = bindFetch(opts.fetch);
|
|
2278
|
-
return fetchImpl(url, {
|
|
2316
|
+
return transport.execute({
|
|
2317
|
+
url,
|
|
2279
2318
|
method: params.method,
|
|
2280
2319
|
headers,
|
|
2281
2320
|
body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
|
|
2282
|
-
signal: params.signal
|
|
2321
|
+
signal: params.signal,
|
|
2322
|
+
idempotencyKey: params.idempotencyKey
|
|
2283
2323
|
});
|
|
2284
2324
|
};
|
|
2285
2325
|
return new PostgrestTableApi(pgFetch, id, table);
|