@ragable/sdk 0.6.0 → 0.6.2
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 +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +81 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +81 -22
- 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 {
|
|
@@ -859,11 +863,17 @@ interface BrowserSqlQueryResult<Row extends Record<string, unknown> = Record<str
|
|
|
859
863
|
truncated: boolean;
|
|
860
864
|
rows: Row[];
|
|
861
865
|
}
|
|
862
|
-
declare class RagableBrowserDatabaseClient<
|
|
866
|
+
declare class RagableBrowserDatabaseClient<Database extends RagableDatabase = DefaultRagableDatabase> {
|
|
863
867
|
private readonly options;
|
|
864
868
|
private readonly ragableAuth;
|
|
869
|
+
private readonly postgrestFrom?;
|
|
865
870
|
private readonly fetchImpl;
|
|
866
|
-
constructor(options: RagableBrowserClientOptions, ragableAuth?: RagableAuth | null);
|
|
871
|
+
constructor(options: RagableBrowserClientOptions, ragableAuth?: RagableAuth | null, postgrestFrom?: (<T extends RagableTableNames<Database>>(table: T, databaseInstanceId?: string) => PostgrestTableApi<Database, T>) | undefined);
|
|
872
|
+
/**
|
|
873
|
+
* PostgREST fluent API — same as `client.from('table')`.
|
|
874
|
+
* Use either the root client or `database` for Supabase-style table access; `database.query()` is raw SQL only.
|
|
875
|
+
*/
|
|
876
|
+
from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
|
|
867
877
|
private toUrl;
|
|
868
878
|
query<Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams): Promise<BrowserSqlQueryResult<Row>>;
|
|
869
879
|
private baseHeaders;
|
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 {
|
|
@@ -859,11 +863,17 @@ interface BrowserSqlQueryResult<Row extends Record<string, unknown> = Record<str
|
|
|
859
863
|
truncated: boolean;
|
|
860
864
|
rows: Row[];
|
|
861
865
|
}
|
|
862
|
-
declare class RagableBrowserDatabaseClient<
|
|
866
|
+
declare class RagableBrowserDatabaseClient<Database extends RagableDatabase = DefaultRagableDatabase> {
|
|
863
867
|
private readonly options;
|
|
864
868
|
private readonly ragableAuth;
|
|
869
|
+
private readonly postgrestFrom?;
|
|
865
870
|
private readonly fetchImpl;
|
|
866
|
-
constructor(options: RagableBrowserClientOptions, ragableAuth?: RagableAuth | null);
|
|
871
|
+
constructor(options: RagableBrowserClientOptions, ragableAuth?: RagableAuth | null, postgrestFrom?: (<T extends RagableTableNames<Database>>(table: T, databaseInstanceId?: string) => PostgrestTableApi<Database, T>) | undefined);
|
|
872
|
+
/**
|
|
873
|
+
* PostgREST fluent API — same as `client.from('table')`.
|
|
874
|
+
* Use either the root client or `database` for Supabase-style table access; `database.query()` is raw SQL only.
|
|
875
|
+
*/
|
|
876
|
+
from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
|
|
867
877
|
private toUrl;
|
|
868
878
|
query<Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams): Promise<BrowserSqlQueryResult<Row>>;
|
|
869
879
|
private baseHeaders;
|
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;
|
|
@@ -2124,12 +2163,27 @@ var RagableBrowserAuthClient = class {
|
|
|
2124
2163
|
}
|
|
2125
2164
|
};
|
|
2126
2165
|
var RagableBrowserDatabaseClient = class {
|
|
2127
|
-
constructor(options, ragableAuth = null) {
|
|
2166
|
+
constructor(options, ragableAuth = null, postgrestFrom) {
|
|
2128
2167
|
this.options = options;
|
|
2129
2168
|
this.ragableAuth = ragableAuth;
|
|
2169
|
+
this.postgrestFrom = postgrestFrom;
|
|
2130
2170
|
__publicField(this, "fetchImpl");
|
|
2131
2171
|
this.fetchImpl = bindFetch(options.fetch);
|
|
2132
2172
|
}
|
|
2173
|
+
/**
|
|
2174
|
+
* PostgREST fluent API — same as `client.from('table')`.
|
|
2175
|
+
* Use either the root client or `database` for Supabase-style table access; `database.query()` is raw SQL only.
|
|
2176
|
+
*/
|
|
2177
|
+
from(table, databaseInstanceId) {
|
|
2178
|
+
if (!this.postgrestFrom) {
|
|
2179
|
+
throw new RagableError(
|
|
2180
|
+
"database.from() is only available on the client from createBrowserClient().",
|
|
2181
|
+
500,
|
|
2182
|
+
{ code: "SDK_DATABASE_FROM_UNAVAILABLE" }
|
|
2183
|
+
);
|
|
2184
|
+
}
|
|
2185
|
+
return this.postgrestFrom(table, databaseInstanceId);
|
|
2186
|
+
}
|
|
2133
2187
|
toUrl(path) {
|
|
2134
2188
|
return `${normalizeBrowserApiBase(this.options.baseUrl)}${path.startsWith("/") ? path : `/${path}`}`;
|
|
2135
2189
|
}
|
|
@@ -2243,18 +2297,25 @@ var RagableBrowser = class {
|
|
|
2243
2297
|
}
|
|
2244
2298
|
this.agents = new RagableBrowserAgentsClient(options);
|
|
2245
2299
|
this.auth = new RagableBrowserAuthClient(options, this._ragableAuth);
|
|
2246
|
-
this.database = new RagableBrowserDatabaseClient(
|
|
2300
|
+
this.database = new RagableBrowserDatabaseClient(
|
|
2301
|
+
options,
|
|
2302
|
+
this._ragableAuth,
|
|
2303
|
+
(table, databaseInstanceId) => this.from(table, databaseInstanceId)
|
|
2304
|
+
);
|
|
2247
2305
|
}
|
|
2248
2306
|
from(table, databaseInstanceId) {
|
|
2249
2307
|
const id = databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
|
|
2250
2308
|
if (!id) {
|
|
2251
|
-
throw new
|
|
2252
|
-
"RagableBrowser.from() requires databaseInstanceId in client options or as the second argument"
|
|
2309
|
+
throw new RagableError(
|
|
2310
|
+
"RagableBrowser.from() requires databaseInstanceId in client options or as the second argument",
|
|
2311
|
+
400,
|
|
2312
|
+
{ code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
|
|
2253
2313
|
);
|
|
2254
2314
|
}
|
|
2255
2315
|
const gid = requireAuthGroupId(this.options);
|
|
2256
2316
|
const ragableAuth = this._ragableAuth;
|
|
2257
2317
|
const opts = this.options;
|
|
2318
|
+
const transport = this.transport;
|
|
2258
2319
|
const pgFetch = async (params) => {
|
|
2259
2320
|
const token = await resolveDatabaseAuthBearer(opts, ragableAuth);
|
|
2260
2321
|
const baseUrl = normalizeBrowserApiBase(opts.baseUrl);
|
|
@@ -2271,15 +2332,13 @@ var RagableBrowser = class {
|
|
|
2271
2332
|
headers.set(k, v);
|
|
2272
2333
|
}
|
|
2273
2334
|
}
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
}
|
|
2277
|
-
const fetchImpl = bindFetch(opts.fetch);
|
|
2278
|
-
return fetchImpl(url, {
|
|
2335
|
+
return transport.execute({
|
|
2336
|
+
url,
|
|
2279
2337
|
method: params.method,
|
|
2280
2338
|
headers,
|
|
2281
2339
|
body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
|
|
2282
|
-
signal: params.signal
|
|
2340
|
+
signal: params.signal,
|
|
2341
|
+
idempotencyKey: params.idempotencyKey
|
|
2283
2342
|
});
|
|
2284
2343
|
};
|
|
2285
2344
|
return new PostgrestTableApi(pgFetch, id, table);
|