@ragable/sdk 0.7.8 → 0.7.9
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 +95 -1
- package/dist/index.d.ts +95 -1
- package/dist/index.js +118 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +117 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3782,6 +3782,120 @@ var RagableBrowserStorageClient = class {
|
|
|
3782
3782
|
return new BrowserStorageBucketClient(this.options, this.fetchImpl, bucketId);
|
|
3783
3783
|
}
|
|
3784
3784
|
};
|
|
3785
|
+
var RagableBrowserMailClient = class {
|
|
3786
|
+
constructor(options, auth) {
|
|
3787
|
+
this.options = options;
|
|
3788
|
+
this.auth = auth;
|
|
3789
|
+
__publicField(this, "fetchImpl");
|
|
3790
|
+
this.fetchImpl = bindFetch(options.fetch);
|
|
3791
|
+
}
|
|
3792
|
+
requireWebsiteId() {
|
|
3793
|
+
const websiteId = this.options.websiteId?.trim();
|
|
3794
|
+
if (!websiteId) {
|
|
3795
|
+
throw new RagableError(
|
|
3796
|
+
"websiteId is required for mail operations. Use createWebsiteRagableClient() or pass createBrowserClient({ websiteId, ... }).",
|
|
3797
|
+
400,
|
|
3798
|
+
{ code: "SDK_MISSING_WEBSITE_ID" }
|
|
3799
|
+
);
|
|
3800
|
+
}
|
|
3801
|
+
return websiteId;
|
|
3802
|
+
}
|
|
3803
|
+
pathTo(p) {
|
|
3804
|
+
const websiteId = this.requireWebsiteId();
|
|
3805
|
+
const orgId = this.options.organizationId;
|
|
3806
|
+
return `${normalizeBrowserApiBase()}/public/organizations/${orgId}/websites/${websiteId}/mail${p.startsWith("/") ? p : `/${p}`}`;
|
|
3807
|
+
}
|
|
3808
|
+
/**
|
|
3809
|
+
* Get the Bearer token used to authenticate the call:
|
|
3810
|
+
* 1. End-user access token (preferred when an auth group is configured
|
|
3811
|
+
* and the user has signed in)
|
|
3812
|
+
* 2. `dataStaticKey` from createBrowserClient options
|
|
3813
|
+
* 3. Caller-supplied `getAccessToken()`
|
|
3814
|
+
*
|
|
3815
|
+
* If none is available, throws — server-side use should pass the
|
|
3816
|
+
* data-admin key as `dataStaticKey`.
|
|
3817
|
+
*/
|
|
3818
|
+
async getBearerToken() {
|
|
3819
|
+
if (this.auth) {
|
|
3820
|
+
const token = await this.auth.getValidAccessToken().catch(() => null);
|
|
3821
|
+
if (token) return token;
|
|
3822
|
+
}
|
|
3823
|
+
const callerProvided = await this.options.getAccessToken?.();
|
|
3824
|
+
if (typeof callerProvided === "string" && callerProvided.length > 0) {
|
|
3825
|
+
return callerProvided;
|
|
3826
|
+
}
|
|
3827
|
+
if (this.options.dataStaticKey?.trim()) {
|
|
3828
|
+
return this.options.dataStaticKey.trim();
|
|
3829
|
+
}
|
|
3830
|
+
throw new RagableError(
|
|
3831
|
+
"Mail requests need authentication: either sign in via client.auth.signIn(...) or pass dataStaticKey (the auth group data-admin key) when creating the client.",
|
|
3832
|
+
401,
|
|
3833
|
+
{ code: "SDK_MAIL_NOT_AUTHENTICATED" }
|
|
3834
|
+
);
|
|
3835
|
+
}
|
|
3836
|
+
async request(path, init = {}) {
|
|
3837
|
+
const token = await this.getBearerToken();
|
|
3838
|
+
const headers = new Headers(init.headers ?? this.options.headers);
|
|
3839
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
3840
|
+
if (init.body && !headers.has("Content-Type")) {
|
|
3841
|
+
headers.set("Content-Type", "application/json");
|
|
3842
|
+
}
|
|
3843
|
+
const response = await this.fetchImpl(this.pathTo(path), {
|
|
3844
|
+
...init,
|
|
3845
|
+
headers
|
|
3846
|
+
});
|
|
3847
|
+
const payload = await parseMaybeJsonBody(response);
|
|
3848
|
+
if (!response.ok) {
|
|
3849
|
+
const message = extractErrorMessage(payload, response.statusText);
|
|
3850
|
+
throw new RagableError(message, response.status, payload);
|
|
3851
|
+
}
|
|
3852
|
+
return payload;
|
|
3853
|
+
}
|
|
3854
|
+
/** Send an email from this website's linked Gmail account. */
|
|
3855
|
+
async send(params) {
|
|
3856
|
+
if (!params.to?.length) {
|
|
3857
|
+
throw new RagableError(
|
|
3858
|
+
"`to` must contain at least one recipient.",
|
|
3859
|
+
400,
|
|
3860
|
+
{ code: "SDK_MAIL_NO_RECIPIENTS" }
|
|
3861
|
+
);
|
|
3862
|
+
}
|
|
3863
|
+
if (!params.bodyText && !params.bodyHtml) {
|
|
3864
|
+
throw new RagableError(
|
|
3865
|
+
"Provide at least one of `bodyText` or `bodyHtml`.",
|
|
3866
|
+
400,
|
|
3867
|
+
{ code: "SDK_MAIL_NO_BODY" }
|
|
3868
|
+
);
|
|
3869
|
+
}
|
|
3870
|
+
return this.request("/send", {
|
|
3871
|
+
method: "POST",
|
|
3872
|
+
body: JSON.stringify(params)
|
|
3873
|
+
});
|
|
3874
|
+
}
|
|
3875
|
+
/** Search messages with Gmail query syntax. */
|
|
3876
|
+
async search(params = {}) {
|
|
3877
|
+
const qs = new URLSearchParams();
|
|
3878
|
+
if (params.query) qs.set("q", params.query);
|
|
3879
|
+
if (params.maxResults) qs.set("maxResults", String(params.maxResults));
|
|
3880
|
+
if (params.pageToken) qs.set("pageToken", params.pageToken);
|
|
3881
|
+
if (params.labelIds?.length) qs.set("labelIds", params.labelIds.join(","));
|
|
3882
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
3883
|
+
return this.request(`/search${suffix}`, { method: "GET" });
|
|
3884
|
+
}
|
|
3885
|
+
/** Fetch a single message in full (headers + decoded text/html body). */
|
|
3886
|
+
async getMessage(messageId) {
|
|
3887
|
+
if (!messageId) {
|
|
3888
|
+
throw new RagableError("`messageId` is required.", 400, {
|
|
3889
|
+
code: "SDK_MAIL_NO_MESSAGE_ID"
|
|
3890
|
+
});
|
|
3891
|
+
}
|
|
3892
|
+
const { message } = await this.request(
|
|
3893
|
+
`/messages/${encodeURIComponent(messageId)}`,
|
|
3894
|
+
{ method: "GET" }
|
|
3895
|
+
);
|
|
3896
|
+
return message;
|
|
3897
|
+
}
|
|
3898
|
+
};
|
|
3785
3899
|
var RagableBrowserAgentsClient = class {
|
|
3786
3900
|
constructor(options) {
|
|
3787
3901
|
this.options = options;
|
|
@@ -4108,6 +4222,7 @@ var RagableBrowser = class {
|
|
|
4108
4222
|
__publicField(this, "database");
|
|
4109
4223
|
__publicField(this, "db");
|
|
4110
4224
|
__publicField(this, "storage");
|
|
4225
|
+
__publicField(this, "mail");
|
|
4111
4226
|
__publicField(this, "transport");
|
|
4112
4227
|
__publicField(this, "_ragableAuth");
|
|
4113
4228
|
/** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
|
|
@@ -4153,6 +4268,7 @@ var RagableBrowser = class {
|
|
|
4153
4268
|
this.database._setTransport(this.transport);
|
|
4154
4269
|
this.db = this.database;
|
|
4155
4270
|
this.storage = new RagableBrowserStorageClient(options, bindFetch(options.fetch));
|
|
4271
|
+
this.mail = new RagableBrowserMailClient(options, this._ragableAuth);
|
|
4156
4272
|
}
|
|
4157
4273
|
destroy() {
|
|
4158
4274
|
this._ragableAuth?.destroy();
|
|
@@ -4193,6 +4309,7 @@ export {
|
|
|
4193
4309
|
RagableBrowserAiClient,
|
|
4194
4310
|
RagableBrowserAuthClient,
|
|
4195
4311
|
RagableBrowserDatabaseClient,
|
|
4312
|
+
RagableBrowserMailClient,
|
|
4196
4313
|
RagableBrowserStorageClient,
|
|
4197
4314
|
RagableError,
|
|
4198
4315
|
RagableNetworkError,
|