@ragable/sdk 0.6.4 → 0.6.5
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 +5 -7
- package/dist/index.d.ts +5 -7
- package/dist/index.js +58 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -55
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2158,26 +2158,65 @@ var RagableBrowserAuthClient = class {
|
|
|
2158
2158
|
}
|
|
2159
2159
|
};
|
|
2160
2160
|
var RagableBrowserDatabaseClient = class {
|
|
2161
|
-
constructor(options, ragableAuth = null
|
|
2161
|
+
constructor(options, ragableAuth = null) {
|
|
2162
2162
|
this.options = options;
|
|
2163
2163
|
this.ragableAuth = ragableAuth;
|
|
2164
|
-
this.postgrestFrom = postgrestFrom;
|
|
2165
2164
|
__publicField(this, "fetchImpl");
|
|
2165
|
+
__publicField(this, "_transport", null);
|
|
2166
2166
|
this.fetchImpl = bindFetch(options.fetch);
|
|
2167
2167
|
}
|
|
2168
|
-
/**
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2168
|
+
/** @internal Called by RagableBrowser to share the Transport instance. */
|
|
2169
|
+
_setTransport(transport) {
|
|
2170
|
+
this._transport = transport;
|
|
2171
|
+
}
|
|
2172
2172
|
from(table, databaseInstanceId) {
|
|
2173
|
-
|
|
2173
|
+
const id = databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
|
|
2174
|
+
if (!id) {
|
|
2174
2175
|
throw new RagableError(
|
|
2175
|
-
"database.from()
|
|
2176
|
-
|
|
2177
|
-
{ code: "
|
|
2176
|
+
"database.from() requires databaseInstanceId in client options or as the second argument",
|
|
2177
|
+
400,
|
|
2178
|
+
{ code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
|
|
2178
2179
|
);
|
|
2179
2180
|
}
|
|
2180
|
-
|
|
2181
|
+
const gid = requireAuthGroupId(this.options);
|
|
2182
|
+
const ragableAuth = this.ragableAuth;
|
|
2183
|
+
const opts = this.options;
|
|
2184
|
+
const transport = this._transport;
|
|
2185
|
+
const fetchImpl = this.fetchImpl;
|
|
2186
|
+
const pgFetch = async (params) => {
|
|
2187
|
+
const token = await resolveDatabaseAuthBearer(opts, ragableAuth);
|
|
2188
|
+
const baseUrl = normalizeBrowserApiBase(opts.baseUrl);
|
|
2189
|
+
const qs = params.searchParams.toString();
|
|
2190
|
+
const url = `${baseUrl}/auth-groups/${gid}/data/rest/${params.table}${qs ? `?${qs}` : ""}`;
|
|
2191
|
+
const headers = new Headers(opts.headers);
|
|
2192
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
2193
|
+
headers.set("X-Database-Instance-Id", params.databaseInstanceId);
|
|
2194
|
+
if (params.body !== void 0) {
|
|
2195
|
+
headers.set("Content-Type", "application/json");
|
|
2196
|
+
}
|
|
2197
|
+
if (params.headers) {
|
|
2198
|
+
for (const [k, v] of Object.entries(params.headers)) {
|
|
2199
|
+
headers.set(k, v);
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
if (transport) {
|
|
2203
|
+
return transport.execute({
|
|
2204
|
+
url,
|
|
2205
|
+
method: params.method,
|
|
2206
|
+
headers,
|
|
2207
|
+
body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
|
|
2208
|
+
signal: params.signal,
|
|
2209
|
+
idempotencyKey: params.idempotencyKey
|
|
2210
|
+
});
|
|
2211
|
+
}
|
|
2212
|
+
return fetchImpl(url, {
|
|
2213
|
+
method: params.method,
|
|
2214
|
+
headers,
|
|
2215
|
+
body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
|
|
2216
|
+
signal: params.signal
|
|
2217
|
+
});
|
|
2218
|
+
};
|
|
2219
|
+
return new PostgrestTableApi(pgFetch, id, table);
|
|
2181
2220
|
}
|
|
2182
2221
|
toUrl(path) {
|
|
2183
2222
|
return `${normalizeBrowserApiBase(this.options.baseUrl)}${path.startsWith("/") ? path : `/${path}`}`;
|
|
@@ -2187,8 +2226,10 @@ var RagableBrowserDatabaseClient = class {
|
|
|
2187
2226
|
const token = await resolveDatabaseAuthBearer(this.options, this.ragableAuth);
|
|
2188
2227
|
const databaseInstanceId = params.databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
|
|
2189
2228
|
if (!databaseInstanceId) {
|
|
2190
|
-
throw new
|
|
2191
|
-
"database.query requires databaseInstanceId in the request or on createBrowserClient({ databaseInstanceId })"
|
|
2229
|
+
throw new RagableError(
|
|
2230
|
+
"database.query requires databaseInstanceId in the request or on createBrowserClient({ databaseInstanceId })",
|
|
2231
|
+
400,
|
|
2232
|
+
{ code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
|
|
2192
2233
|
);
|
|
2193
2234
|
}
|
|
2194
2235
|
const headers = this.baseHeaders();
|
|
@@ -2261,9 +2302,7 @@ var RagableBrowser = class {
|
|
|
2261
2302
|
__publicField(this, "auth");
|
|
2262
2303
|
__publicField(this, "database");
|
|
2263
2304
|
__publicField(this, "transport");
|
|
2264
|
-
__publicField(this, "options");
|
|
2265
2305
|
__publicField(this, "_ragableAuth");
|
|
2266
|
-
this.options = options;
|
|
2267
2306
|
this.transport = new Transport({
|
|
2268
2307
|
fetch: options.fetch,
|
|
2269
2308
|
headers: options.headers,
|
|
@@ -2294,49 +2333,13 @@ var RagableBrowser = class {
|
|
|
2294
2333
|
this.auth = new RagableBrowserAuthClient(options, this._ragableAuth);
|
|
2295
2334
|
this.database = new RagableBrowserDatabaseClient(
|
|
2296
2335
|
options,
|
|
2297
|
-
this._ragableAuth
|
|
2298
|
-
(table, databaseInstanceId) => this.from(table, databaseInstanceId)
|
|
2336
|
+
this._ragableAuth
|
|
2299
2337
|
);
|
|
2338
|
+
this.database._setTransport(this.transport);
|
|
2300
2339
|
}
|
|
2340
|
+
/** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
|
|
2301
2341
|
from(table, databaseInstanceId) {
|
|
2302
|
-
|
|
2303
|
-
if (!id) {
|
|
2304
|
-
throw new RagableError(
|
|
2305
|
-
"RagableBrowser.from() requires databaseInstanceId in client options or as the second argument",
|
|
2306
|
-
400,
|
|
2307
|
-
{ code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
|
|
2308
|
-
);
|
|
2309
|
-
}
|
|
2310
|
-
const gid = requireAuthGroupId(this.options);
|
|
2311
|
-
const ragableAuth = this._ragableAuth;
|
|
2312
|
-
const opts = this.options;
|
|
2313
|
-
const transport = this.transport;
|
|
2314
|
-
const pgFetch = async (params) => {
|
|
2315
|
-
const token = await resolveDatabaseAuthBearer(opts, ragableAuth);
|
|
2316
|
-
const baseUrl = normalizeBrowserApiBase(opts.baseUrl);
|
|
2317
|
-
const qs = params.searchParams.toString();
|
|
2318
|
-
const url = `${baseUrl}/auth-groups/${gid}/data/rest/${params.table}${qs ? `?${qs}` : ""}`;
|
|
2319
|
-
const headers = new Headers(opts.headers);
|
|
2320
|
-
headers.set("Authorization", `Bearer ${token}`);
|
|
2321
|
-
headers.set("X-Database-Instance-Id", params.databaseInstanceId);
|
|
2322
|
-
if (params.body !== void 0) {
|
|
2323
|
-
headers.set("Content-Type", "application/json");
|
|
2324
|
-
}
|
|
2325
|
-
if (params.headers) {
|
|
2326
|
-
for (const [k, v] of Object.entries(params.headers)) {
|
|
2327
|
-
headers.set(k, v);
|
|
2328
|
-
}
|
|
2329
|
-
}
|
|
2330
|
-
return transport.execute({
|
|
2331
|
-
url,
|
|
2332
|
-
method: params.method,
|
|
2333
|
-
headers,
|
|
2334
|
-
body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
|
|
2335
|
-
signal: params.signal,
|
|
2336
|
-
idempotencyKey: params.idempotencyKey
|
|
2337
|
-
});
|
|
2338
|
-
};
|
|
2339
|
-
return new PostgrestTableApi(pgFetch, id, table);
|
|
2342
|
+
return this.database.from(table, databaseInstanceId);
|
|
2340
2343
|
}
|
|
2341
2344
|
destroy() {
|
|
2342
2345
|
this._ragableAuth?.destroy();
|