@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 CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.66.0";
2
+ var version = "0.66.1";
3
3
  //#endregion
4
4
  export { version };
@@ -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 || response.status === 403 && await gmailReason(response) === "insufficientPermissions") throw new PersonalMailError("link_expired", "gmail");
33
- throw new Error(`Gmail refused the message: ${response.status} ${response.statusText}`);
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 gmailReason = async (response) => {
38
+ const gmailError = async (response) => {
37
39
  if (!response.headers.get("content-type")?.includes("json")) return;
38
- const body = await response.json();
39
- const reasons = [...body.error?.errors ?? [], ...body.error?.details ?? []].map((entry) => entry.reason);
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.0",
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.0",
46
- "@protobase/query": "0.66.0",
47
- "@protobase/schema": "0.66.0",
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",