@ragable/sdk 0.6.24 → 0.7.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 +303 -27
- package/dist/index.d.ts +303 -27
- package/dist/index.js +166 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +165 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +49 -49
package/dist/index.mjs
CHANGED
|
@@ -10,10 +10,6 @@ function bindFetch(custom) {
|
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
var DEFAULT_RAGABLE_API_BASE = "https://ragable-341305259977.asia-southeast1.run.app/api";
|
|
13
|
-
function resolveRagableApiBase(explicitBaseUrl) {
|
|
14
|
-
const raw = typeof explicitBaseUrl === "string" && explicitBaseUrl.trim().length > 0 ? explicitBaseUrl.trim() : DEFAULT_RAGABLE_API_BASE.trim();
|
|
15
|
-
return raw.replace(/\/+$/, "");
|
|
16
|
-
}
|
|
17
13
|
var RagableSdkError = class extends Error {
|
|
18
14
|
constructor(message) {
|
|
19
15
|
super(message);
|
|
@@ -142,7 +138,7 @@ var RagableRequestClient = class {
|
|
|
142
138
|
__publicField(this, "fetchImpl");
|
|
143
139
|
__publicField(this, "defaultHeaders");
|
|
144
140
|
this.apiKey = options.apiKey;
|
|
145
|
-
this.baseUrl =
|
|
141
|
+
this.baseUrl = DEFAULT_RAGABLE_API_BASE.replace(/\/+$/, "");
|
|
146
142
|
this.fetchImpl = bindFetch(options.fetch);
|
|
147
143
|
this.defaultHeaders = options.headers;
|
|
148
144
|
}
|
|
@@ -2166,7 +2162,7 @@ var RagableAuth = class {
|
|
|
2166
2162
|
__publicField(this, "broadcast", null);
|
|
2167
2163
|
__publicField(this, "visibilityHandler", null);
|
|
2168
2164
|
__publicField(this, "initialized", false);
|
|
2169
|
-
this.baseUrl =
|
|
2165
|
+
this.baseUrl = DEFAULT_RAGABLE_API_BASE.replace(/\/+$/, "");
|
|
2170
2166
|
this.authGroupId = config.authGroupId;
|
|
2171
2167
|
this.fetchImpl = bindFetch(config.fetch);
|
|
2172
2168
|
this.defaultHeaders = config.headers;
|
|
@@ -2535,8 +2531,8 @@ function decodeJwtExpiry(jwt) {
|
|
|
2535
2531
|
}
|
|
2536
2532
|
|
|
2537
2533
|
// src/browser.ts
|
|
2538
|
-
function normalizeBrowserApiBase(
|
|
2539
|
-
return
|
|
2534
|
+
function normalizeBrowserApiBase() {
|
|
2535
|
+
return DEFAULT_RAGABLE_API_BASE.replace(/\/+$/, "");
|
|
2540
2536
|
}
|
|
2541
2537
|
function effectiveDataAuth(options) {
|
|
2542
2538
|
if (options.dataAuth) return options.dataAuth;
|
|
@@ -2827,7 +2823,6 @@ var RagableBrowserDatabaseClient = class {
|
|
|
2827
2823
|
this.options = options;
|
|
2828
2824
|
this.ragableAuth = ragableAuth;
|
|
2829
2825
|
__publicField(this, "fetchImpl");
|
|
2830
|
-
__publicField(this, "apiBase");
|
|
2831
2826
|
__publicField(this, "_transport", null);
|
|
2832
2827
|
__publicField(this, "collections");
|
|
2833
2828
|
__publicField(this, "collection");
|
|
@@ -2851,7 +2846,7 @@ var RagableBrowserDatabaseClient = class {
|
|
|
2851
2846
|
}
|
|
2852
2847
|
const gid = requireAuthGroupId(opts);
|
|
2853
2848
|
const token = await resolveDatabaseAuthBearer(opts, ragableAuth);
|
|
2854
|
-
const apiBase =
|
|
2849
|
+
const apiBase = normalizeBrowserApiBase();
|
|
2855
2850
|
const qs = params.searchParams.toString();
|
|
2856
2851
|
const url = `${apiBase}/auth-groups/${gid}/data/rest/${params.table}${qs ? `?${qs}` : ""}`;
|
|
2857
2852
|
const headers = new Headers(opts.headers);
|
|
@@ -2966,7 +2961,6 @@ var RagableBrowserDatabaseClient = class {
|
|
|
2966
2961
|
)
|
|
2967
2962
|
});
|
|
2968
2963
|
this.fetchImpl = bindFetch(options.fetch);
|
|
2969
|
-
this.apiBase = resolveRagableApiBase(options.baseUrl);
|
|
2970
2964
|
this.collections = new Proxy(
|
|
2971
2965
|
{},
|
|
2972
2966
|
{
|
|
@@ -2988,7 +2982,7 @@ var RagableBrowserDatabaseClient = class {
|
|
|
2988
2982
|
this._transport = transport;
|
|
2989
2983
|
}
|
|
2990
2984
|
toUrl(path) {
|
|
2991
|
-
return `${
|
|
2985
|
+
return `${normalizeBrowserApiBase()}${path.startsWith("/") ? path : `/${path}`}`;
|
|
2992
2986
|
}
|
|
2993
2987
|
async _requestCollection(method, path, body, databaseInstanceId) {
|
|
2994
2988
|
const gid = requireAuthGroupId(this.options);
|
|
@@ -3079,7 +3073,7 @@ async function subscribeBrowserRealtime(options, ragableAuth, fetchImpl, params)
|
|
|
3079
3073
|
headers.set("Authorization", `Bearer ${token}`);
|
|
3080
3074
|
headers.set("Content-Type", "application/json");
|
|
3081
3075
|
const response = await fetchImpl(
|
|
3082
|
-
`${
|
|
3076
|
+
`${normalizeBrowserApiBase()}/auth-groups/${gid}/data/realtime/stream`,
|
|
3083
3077
|
{
|
|
3084
3078
|
method: "POST",
|
|
3085
3079
|
headers,
|
|
@@ -3212,12 +3206,10 @@ var RagableBrowserAgentsClient = class {
|
|
|
3212
3206
|
constructor(options) {
|
|
3213
3207
|
this.options = options;
|
|
3214
3208
|
__publicField(this, "fetchImpl");
|
|
3215
|
-
__publicField(this, "apiBase");
|
|
3216
3209
|
this.fetchImpl = bindFetch(options.fetch);
|
|
3217
|
-
this.apiBase = resolveRagableApiBase(options.baseUrl);
|
|
3218
3210
|
}
|
|
3219
3211
|
toUrl(path) {
|
|
3220
|
-
return `${
|
|
3212
|
+
return `${normalizeBrowserApiBase()}${path.startsWith("/") ? path : `/${path}`}`;
|
|
3221
3213
|
}
|
|
3222
3214
|
requireWebsiteId() {
|
|
3223
3215
|
const websiteId = this.options.websiteId?.trim();
|
|
@@ -3417,7 +3409,6 @@ var RagableBrowser = class {
|
|
|
3417
3409
|
if (options.authGroupId) {
|
|
3418
3410
|
this._ragableAuth = new RagableAuth({
|
|
3419
3411
|
authGroupId: options.authGroupId,
|
|
3420
|
-
baseUrl: options.baseUrl,
|
|
3421
3412
|
fetch: options.fetch,
|
|
3422
3413
|
headers: options.headers,
|
|
3423
3414
|
auth: options.auth
|
|
@@ -3493,15 +3484,171 @@ function createRagPipeline(client, options) {
|
|
|
3493
3484
|
};
|
|
3494
3485
|
}
|
|
3495
3486
|
|
|
3487
|
+
// src/storage.ts
|
|
3488
|
+
function normalizeUploadFile2(file, contentType) {
|
|
3489
|
+
if (file instanceof Blob) return file;
|
|
3490
|
+
const u8 = file instanceof ArrayBuffer ? new Uint8Array(file) : new Uint8Array(file);
|
|
3491
|
+
return new Blob([u8.buffer], contentType ? { type: contentType } : {});
|
|
3492
|
+
}
|
|
3493
|
+
var StorageClient = class {
|
|
3494
|
+
constructor(client) {
|
|
3495
|
+
this.client = client;
|
|
3496
|
+
/**
|
|
3497
|
+
* Bucket-level CRUD — list, create and delete buckets for this organisation.
|
|
3498
|
+
*/
|
|
3499
|
+
__publicField(this, "buckets");
|
|
3500
|
+
this.buckets = {
|
|
3501
|
+
list: async (params) => {
|
|
3502
|
+
const qs = new URLSearchParams();
|
|
3503
|
+
if (params?.q) qs.set("q", params.q);
|
|
3504
|
+
if (params?.status) qs.set("status", params.status);
|
|
3505
|
+
if (params?.sort) qs.set("sort", params.sort);
|
|
3506
|
+
const query = qs.toString();
|
|
3507
|
+
return this.client.request(
|
|
3508
|
+
`/v1/storage/buckets${query ? `?${query}` : ""}`
|
|
3509
|
+
);
|
|
3510
|
+
},
|
|
3511
|
+
create: async (name) => {
|
|
3512
|
+
return this.client.request("/v1/storage/buckets", {
|
|
3513
|
+
method: "POST",
|
|
3514
|
+
body: { name }
|
|
3515
|
+
});
|
|
3516
|
+
},
|
|
3517
|
+
delete: async (bucketId) => {
|
|
3518
|
+
return this.client.request(
|
|
3519
|
+
`/v1/storage/buckets/${encodeURIComponent(bucketId)}`,
|
|
3520
|
+
{ method: "DELETE" }
|
|
3521
|
+
);
|
|
3522
|
+
}
|
|
3523
|
+
};
|
|
3524
|
+
}
|
|
3525
|
+
/**
|
|
3526
|
+
* Returns a {@link StorageBucketClient} scoped to the given bucket ID.
|
|
3527
|
+
*
|
|
3528
|
+
* All object operations (upload, download, list, copy, move, signed URLs, …)
|
|
3529
|
+
* are performed through the returned client.
|
|
3530
|
+
*
|
|
3531
|
+
* @param bucketId The Ragable bucket ID obtained from `buckets.list()` or `buckets.create()`.
|
|
3532
|
+
*/
|
|
3533
|
+
from(bucketId) {
|
|
3534
|
+
const { client } = this;
|
|
3535
|
+
const base = `/v1/storage/buckets/${encodeURIComponent(bucketId)}`;
|
|
3536
|
+
return {
|
|
3537
|
+
list: async (params) => {
|
|
3538
|
+
const qs = new URLSearchParams();
|
|
3539
|
+
if (params?.prefix) qs.set("prefix", params.prefix);
|
|
3540
|
+
if (params?.delimiter) qs.set("delimiter", params.delimiter);
|
|
3541
|
+
if (params?.maxResults != null)
|
|
3542
|
+
qs.set("maxResults", String(params.maxResults));
|
|
3543
|
+
if (params?.pageToken) qs.set("pageToken", params.pageToken);
|
|
3544
|
+
const query = qs.toString();
|
|
3545
|
+
return client.request(
|
|
3546
|
+
`${base}/contents${query ? `?${query}` : ""}`
|
|
3547
|
+
);
|
|
3548
|
+
},
|
|
3549
|
+
createFolder: async (folderPath) => {
|
|
3550
|
+
return client.request(
|
|
3551
|
+
`${base}/folders`,
|
|
3552
|
+
{ method: "POST", body: { folderPath } }
|
|
3553
|
+
);
|
|
3554
|
+
},
|
|
3555
|
+
deleteFolder: async (folderPath) => {
|
|
3556
|
+
return client.request(
|
|
3557
|
+
`${base}/folders`,
|
|
3558
|
+
{ method: "DELETE", body: { folderPath } }
|
|
3559
|
+
);
|
|
3560
|
+
},
|
|
3561
|
+
upload: async (params) => {
|
|
3562
|
+
const formData = new FormData();
|
|
3563
|
+
const blob = normalizeUploadFile2(params.file, params.contentType);
|
|
3564
|
+
const fileName = params.fileName ?? "upload";
|
|
3565
|
+
formData.set("file", blob, fileName);
|
|
3566
|
+
formData.set("objectPath", params.objectPath);
|
|
3567
|
+
if (params.cacheControl) {
|
|
3568
|
+
formData.set("cacheControl", params.cacheControl);
|
|
3569
|
+
}
|
|
3570
|
+
return client.request(`${base}/upload`, {
|
|
3571
|
+
method: "POST",
|
|
3572
|
+
body: formData
|
|
3573
|
+
});
|
|
3574
|
+
},
|
|
3575
|
+
delete: async (objectPath) => {
|
|
3576
|
+
return client.request(
|
|
3577
|
+
`${base}/objects`,
|
|
3578
|
+
{ method: "DELETE", body: { objectPath } }
|
|
3579
|
+
);
|
|
3580
|
+
},
|
|
3581
|
+
bulkDelete: async (objectPaths) => {
|
|
3582
|
+
return client.request(
|
|
3583
|
+
`${base}/objects/delete-bulk`,
|
|
3584
|
+
{ method: "POST", body: { objectPaths } }
|
|
3585
|
+
);
|
|
3586
|
+
},
|
|
3587
|
+
getMetadata: async (objectPath) => {
|
|
3588
|
+
const qs = new URLSearchParams({ objectPath });
|
|
3589
|
+
return client.request(
|
|
3590
|
+
`${base}/objects/metadata?${qs}`
|
|
3591
|
+
);
|
|
3592
|
+
},
|
|
3593
|
+
updateMetadata: async (params) => {
|
|
3594
|
+
return client.request(
|
|
3595
|
+
`${base}/objects/metadata`,
|
|
3596
|
+
{ method: "PATCH", body: params }
|
|
3597
|
+
);
|
|
3598
|
+
},
|
|
3599
|
+
download: async (params) => {
|
|
3600
|
+
const qs = new URLSearchParams({ objectPath: params.objectPath });
|
|
3601
|
+
if (params.asText != null) qs.set("asText", String(params.asText));
|
|
3602
|
+
if (params.maxTextBytes != null)
|
|
3603
|
+
qs.set("maxTextBytes", String(params.maxTextBytes));
|
|
3604
|
+
return client.request(
|
|
3605
|
+
`${base}/objects/download?${qs}`
|
|
3606
|
+
);
|
|
3607
|
+
},
|
|
3608
|
+
copy: async (params) => {
|
|
3609
|
+
return client.request(`${base}/objects/copy`, { method: "POST", body: params });
|
|
3610
|
+
},
|
|
3611
|
+
move: async (params) => {
|
|
3612
|
+
return client.request(`${base}/objects/move`, { method: "POST", body: params });
|
|
3613
|
+
},
|
|
3614
|
+
getSignedUploadUrl: async (params) => {
|
|
3615
|
+
return client.request(
|
|
3616
|
+
`${base}/signed-upload-url`,
|
|
3617
|
+
{ method: "POST", body: params }
|
|
3618
|
+
);
|
|
3619
|
+
},
|
|
3620
|
+
getSignedDownloadUrl: async (params) => {
|
|
3621
|
+
const qs = new URLSearchParams({ objectPath: params.objectPath });
|
|
3622
|
+
if (params.expiresInSeconds != null)
|
|
3623
|
+
qs.set("expiresInSeconds", String(params.expiresInSeconds));
|
|
3624
|
+
return client.request(
|
|
3625
|
+
`${base}/signed-download-url?${qs}`
|
|
3626
|
+
);
|
|
3627
|
+
},
|
|
3628
|
+
getSettings: async () => {
|
|
3629
|
+
return client.request(`${base}/settings`);
|
|
3630
|
+
},
|
|
3631
|
+
updateSettings: async (params) => {
|
|
3632
|
+
return client.request(`${base}/settings`, {
|
|
3633
|
+
method: "PATCH",
|
|
3634
|
+
body: params
|
|
3635
|
+
});
|
|
3636
|
+
}
|
|
3637
|
+
};
|
|
3638
|
+
}
|
|
3639
|
+
};
|
|
3640
|
+
|
|
3496
3641
|
// src/index.ts
|
|
3497
3642
|
var Ragable = class {
|
|
3498
3643
|
constructor(options) {
|
|
3499
3644
|
__publicField(this, "shift");
|
|
3500
3645
|
__publicField(this, "agents");
|
|
3646
|
+
__publicField(this, "storage");
|
|
3501
3647
|
__publicField(this, "infrastructure");
|
|
3502
3648
|
const client = new RagableRequestClient(options);
|
|
3503
3649
|
this.shift = new ShiftClient(client);
|
|
3504
3650
|
this.agents = new AgentsClient(client);
|
|
3651
|
+
this.storage = new StorageClient(client);
|
|
3505
3652
|
this.infrastructure = {
|
|
3506
3653
|
shift: this.shift
|
|
3507
3654
|
};
|
|
@@ -3564,6 +3711,7 @@ export {
|
|
|
3564
3711
|
RagableTimeoutError,
|
|
3565
3712
|
SessionStorageAdapter,
|
|
3566
3713
|
ShiftClient,
|
|
3714
|
+
StorageClient,
|
|
3567
3715
|
Transport,
|
|
3568
3716
|
asPostgrestResponse,
|
|
3569
3717
|
assertPostgrestSuccess,
|
|
@@ -3592,7 +3740,6 @@ export {
|
|
|
3592
3740
|
parseSseDataLine,
|
|
3593
3741
|
parseTransportResponse,
|
|
3594
3742
|
readSseStream,
|
|
3595
|
-
resolveRagableApiBase,
|
|
3596
3743
|
runAgentChatStream,
|
|
3597
3744
|
runAgentChatStreamForUi,
|
|
3598
3745
|
runAgentChatStreamLenient,
|