astro-integration-pocketbase 2.1.4-next.2 → 2.1.4-next.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-integration-pocketbase",
3
- "version": "2.1.4-next.2",
3
+ "version": "2.1.4-next.4",
4
4
  "description": "An Astro integration to support developers working with astro-loader-pocketbase.",
5
5
  "keywords": [
6
6
  "astro",
@@ -33,21 +33,22 @@
33
33
  "scripts": {
34
34
  "format": "npx prettier . --write --cache",
35
35
  "format:check": "npx prettier . --check --cache",
36
- "lint": "oxlint",
37
- "lint:fix": "oxlint --fix",
36
+ "lint": "oxlint --type-aware",
37
+ "lint:fix": "oxlint --type-aware --fix",
38
38
  "prepare": "husky",
39
39
  "typecheck": "npx tsc --noEmit"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@commitlint/cli": "20.1.0",
43
43
  "@commitlint/config-conventional": "20.0.0",
44
- "@types/node": "24.9.1",
45
- "astro": "5.15.1",
44
+ "@types/node": "24.9.2",
45
+ "astro": "5.15.3",
46
46
  "eventsource": "4.0.0",
47
47
  "globals": "16.4.0",
48
48
  "husky": "9.1.7",
49
49
  "lint-staged": "16.2.6",
50
- "oxlint": "1.24.0",
50
+ "oxlint": "1.25.0",
51
+ "oxlint-tsgolint": "0.4.0",
51
52
  "prettier": "3.6.2",
52
53
  "prettier-plugin-organize-imports": "4.3.0",
53
54
  "prettier-plugin-packagejson": "2.5.19",
@@ -66,38 +66,45 @@ export function refreshCollectionsRealtime(
66
66
 
67
67
  // Add event listeners for all collections
68
68
  for (const collection of remoteCollections) {
69
- eventSource.addEventListener(`${collection}/*`, async (event) => {
70
- // Do not refresh if the refresh is disabled
71
- if (!refreshEnabled) {
72
- return;
73
- }
74
-
75
- // Refresh the content
76
- logger.info(`Received update for ${collection}. Refreshing content...`);
77
- await refreshContent({
78
- loaders: ["pocketbase-loader"],
79
- context: {
80
- source: "astro-integration-pocketbase",
81
- collection: collectionsMap.get(collection),
82
- data: JSON.parse(event.data)
69
+ eventSource.addEventListener(
70
+ `${collection}/*`,
71
+ async (event: MessageEvent<string>) => {
72
+ // Do not refresh if the refresh is disabled
73
+ if (!refreshEnabled) {
74
+ return;
83
75
  }
84
- });
85
- });
76
+
77
+ // Refresh the content
78
+ logger.info(`Received update for ${collection}. Refreshing content...`);
79
+ await refreshContent({
80
+ loaders: ["pocketbase-loader"],
81
+ context: {
82
+ source: "astro-integration-pocketbase",
83
+ collection: collectionsMap.get(collection),
84
+ // oxlint-disable-next-line @typescript-eslint/no-unsafe-assignment
85
+ data: JSON.parse(event.data)
86
+ }
87
+ });
88
+ }
89
+ );
86
90
  }
87
91
 
88
92
  // Add event listener for the connection event
89
- eventSource.addEventListener("PB_CONNECT", async (event) => {
90
- isConnected = await handleConnectEvent(
91
- event,
92
- remoteCollections,
93
- wasConnectedOnce,
94
- options,
95
- logger
96
- );
97
- if (isConnected) {
98
- wasConnectedOnce = true;
93
+ eventSource.addEventListener(
94
+ "PB_CONNECT",
95
+ async (event: MessageEvent<void>) => {
96
+ isConnected = await handleConnectEvent(
97
+ event,
98
+ remoteCollections,
99
+ wasConnectedOnce,
100
+ options,
101
+ logger
102
+ );
103
+ if (isConnected) {
104
+ wasConnectedOnce = true;
105
+ }
99
106
  }
100
- });
107
+ );
101
108
 
102
109
  return eventSource;
103
110
  }
@@ -120,9 +120,8 @@ export function createHeader(
120
120
 
121
121
  if (hasContentLoader) {
122
122
  // Add click listeners to the refresh button
123
- const refresh = windowElement.querySelector(
124
- "#refresh-content"
125
- ) as DevToolbarButton | null;
123
+ const refresh =
124
+ windowElement.querySelector<DevToolbarButton>("#refresh-content");
126
125
  if (!refresh) {
127
126
  throw new Error("The refresh button is missing");
128
127
  }
@@ -0,0 +1,21 @@
1
+ import { z } from "astro/zod";
2
+
3
+ /**
4
+ * The schema for a PocketBase error response.
5
+ */
6
+ export const pocketBaseErrorResponse = z.object({
7
+ /**
8
+ * The error message returned by PocketBase.
9
+ */
10
+ message: z.string()
11
+ });
12
+
13
+ /**
14
+ * The schema for a PocketBase login response.
15
+ */
16
+ export const pocketBaseLoginResponse = z.object({
17
+ /**
18
+ * The authentication token returned by PocketBase.
19
+ */
20
+ token: z.string()
21
+ });
@@ -1,4 +1,8 @@
1
1
  import type { AstroIntegrationLogger } from "astro";
2
+ import {
3
+ pocketBaseErrorResponse,
4
+ pocketBaseLoginResponse
5
+ } from "../types/pocketbase-api-response.type";
2
6
 
3
7
  /**
4
8
  * This function will get a superuser token from the given PocketBase instance.
@@ -35,12 +39,28 @@ export async function getSuperuserToken(
35
39
 
36
40
  // If the login request was not successful, print the error message and return undefined
37
41
  if (!loginRequest.ok) {
38
- const reason = await loginRequest.json().then((data) => data.message);
39
- const errorMessage = `The given email / password for ${url} was not correct. Astro may not have access to all resources and permissions.\nReason: ${reason}`;
42
+ if (loginRequest.status === 429) {
43
+ const info =
44
+ "A rate limit was hit while trying to authenticate with PocketBase. Consider using an `impersonateToken` as credentials to avoid this issue.";
45
+ logger.info(info);
46
+
47
+ // Random wait between 3 (default rate limit interval) and 8 seconds
48
+ const retryAfter = Math.random() * 5 + 3;
49
+ // oxlint-disable-next-line promise/avoid-new
50
+ await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000));
51
+
52
+ return getSuperuserToken(url, superuserCredentials, logger);
53
+ }
54
+
55
+ const errorResponse = pocketBaseErrorResponse.parse(
56
+ await loginRequest.json()
57
+ );
58
+ const errorMessage = `The given email / password for ${url} was not correct. Astro can't generate type definitions automatically and may not have access to all resources.\nReason: ${errorResponse.message}`;
40
59
  logger.error(errorMessage);
41
60
  return undefined;
42
61
  }
43
62
 
44
63
  // Return the token
45
- return await loginRequest.json().then((data) => data.token);
64
+ const response = pocketBaseLoginResponse.parse(await loginRequest.json());
65
+ return response.token;
46
66
  }