@protobase/server 0.66.0 → 0.66.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/package.js +1 -1
- package/dist/personal-mail/gmail.js +20 -5
- package/package.json +4 -4
package/dist/package.js
CHANGED
|
@@ -29,15 +29,30 @@ const gmail = (fetcher = (...args) => fetch(...args)) => ({
|
|
|
29
29
|
body: new Uint8Array(body)
|
|
30
30
|
});
|
|
31
31
|
if (response.ok) return;
|
|
32
|
-
if (response.status === 401
|
|
33
|
-
|
|
32
|
+
if (response.status === 401) throw new PersonalMailError("link_expired", "gmail");
|
|
33
|
+
const error = await gmailError(response);
|
|
34
|
+
if (response.status === 403 && gmailReason(error) === "insufficientPermissions") throw new PersonalMailError("link_expired", "gmail");
|
|
35
|
+
throw new Error(`Gmail refused the message: ${response.status} ${response.statusText}${gmailCause(error)}`);
|
|
34
36
|
}
|
|
35
37
|
});
|
|
36
|
-
const
|
|
38
|
+
const gmailError = async (response) => {
|
|
37
39
|
if (!response.headers.get("content-type")?.includes("json")) return;
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
+
const text = await response.text();
|
|
41
|
+
try {
|
|
42
|
+
return JSON.parse(text).error;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (error instanceof SyntaxError) return;
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const gmailReason = (error) => {
|
|
49
|
+
const reasons = [...error?.errors ?? [], ...error?.details ?? []].map((entry) => entry.reason);
|
|
40
50
|
return reasons.includes("insufficientPermissions") || reasons.includes("ACCESS_TOKEN_SCOPE_INSUFFICIENT") ? "insufficientPermissions" : reasons[0];
|
|
41
51
|
};
|
|
52
|
+
const gmailCause = (error) => {
|
|
53
|
+
if (!error) return "";
|
|
54
|
+
const detail = [error.errors?.[0]?.reason, error.message].filter(Boolean).join(": ");
|
|
55
|
+
return `${error.status ? ` ${error.status}` : ""}${detail ? ` (${detail})` : ""}`;
|
|
56
|
+
};
|
|
42
57
|
//#endregion
|
|
43
58
|
export { gmail, gmailSendScope, gmailSendUrl };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/server",
|
|
3
|
-
"version": "0.66.
|
|
3
|
+
"version": "0.66.1",
|
|
4
4
|
"description": "The Protobase REST API as a Hono app, with Better Auth sign-in.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"@better-auth/sso": "^1.7.12",
|
|
43
43
|
"@livekit/protocol": "1.53.1",
|
|
44
44
|
"@modelcontextprotocol/server": "^2.3.1",
|
|
45
|
-
"@protobase/layout": "0.66.
|
|
46
|
-
"@protobase/query": "0.66.
|
|
47
|
-
"@protobase/schema": "0.66.
|
|
45
|
+
"@protobase/layout": "0.66.1",
|
|
46
|
+
"@protobase/query": "0.66.1",
|
|
47
|
+
"@protobase/schema": "0.66.1",
|
|
48
48
|
"@react-email/render": "^2.1.0",
|
|
49
49
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
50
50
|
"@sentry/core": "^11.7.0",
|