astro-loader-pocketbase 2.6.3-next.1 → 2.7.0-next.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-loader-pocketbase",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0-next.1",
|
|
4
4
|
"description": "A content loader for Astro that uses the PocketBase API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"test:e2e:watch": "vitest watch $(find test -name '*.e2e-spec.ts')",
|
|
40
40
|
"test:unit": "vitest run $(find test -name '*.spec.ts')",
|
|
41
41
|
"test:unit:watch": "vitest watch $(find test -name '*.spec.ts')",
|
|
42
|
-
"test:watch": "vitest watch"
|
|
42
|
+
"test:watch": "vitest watch",
|
|
43
|
+
"typecheck": "npx tsc --noEmit"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@commitlint/cli": "^19.8.1",
|
|
@@ -56,9 +56,16 @@ export async function cleanupEntries(
|
|
|
56
56
|
if (!collectionRequest.ok) {
|
|
57
57
|
// If the collection is locked, an superuser token is required
|
|
58
58
|
if (collectionRequest.status === 403) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
if (
|
|
60
|
+
options.superuserCredentials &&
|
|
61
|
+
"impersonateToken" in options.superuserCredentials
|
|
62
|
+
) {
|
|
63
|
+
context.logger.error("The given impersonate token is not valid.");
|
|
64
|
+
} else {
|
|
65
|
+
context.logger.error(
|
|
66
|
+
"The collection is not accessible without superuser rights. Please provide superuser credentials in the config."
|
|
67
|
+
);
|
|
68
|
+
}
|
|
62
69
|
} else {
|
|
63
70
|
const reason = await collectionRequest
|
|
64
71
|
.json()
|
|
@@ -9,8 +9,6 @@ import { parseEntry } from "./parse-entry";
|
|
|
9
9
|
* @param context Context of the loader.
|
|
10
10
|
* @param superuserToken Superuser token to access all resources.
|
|
11
11
|
* @param lastModified Date of the last fetch to only update changed entries.
|
|
12
|
-
*
|
|
13
|
-
* @returns `true` if the collection has an updated column, `false` otherwise.
|
|
14
12
|
*/
|
|
15
13
|
export async function loadEntries(
|
|
16
14
|
options: PocketBaseLoaderOptions,
|
|
@@ -78,9 +76,16 @@ export async function loadEntries(
|
|
|
78
76
|
if (!collectionRequest.ok) {
|
|
79
77
|
// If the collection is locked, an superuser token is required
|
|
80
78
|
if (collectionRequest.status === 403) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
if (
|
|
80
|
+
options.superuserCredentials &&
|
|
81
|
+
"impersonateToken" in options.superuserCredentials
|
|
82
|
+
) {
|
|
83
|
+
throw new Error("The given impersonate token is not valid.");
|
|
84
|
+
} else {
|
|
85
|
+
throw new Error(
|
|
86
|
+
"The collection is not accessible without superuser rights. Please provide superuser credentials in the config."
|
|
87
|
+
);
|
|
88
|
+
}
|
|
84
89
|
}
|
|
85
90
|
|
|
86
91
|
// Get the reason for the error
|
package/src/pocketbase-loader.ts
CHANGED
|
@@ -11,11 +11,22 @@ import { getSuperuserToken } from "./utils/get-superuser-token";
|
|
|
11
11
|
* @param options Options for the loader. See {@link PocketBaseLoaderOptions} for more details.
|
|
12
12
|
*/
|
|
13
13
|
export function pocketbaseLoader(options: PocketBaseLoaderOptions): Loader {
|
|
14
|
-
// Get a superuser token if credentials are provided
|
|
15
14
|
let tokenPromise: Promise<string | undefined>;
|
|
16
15
|
if (options.superuserCredentials) {
|
|
17
|
-
|
|
16
|
+
if ("impersonateToken" in options.superuserCredentials) {
|
|
17
|
+
// Impersonate token provided, so use it directly.
|
|
18
|
+
tokenPromise = Promise.resolve(
|
|
19
|
+
options.superuserCredentials.impersonateToken
|
|
20
|
+
);
|
|
21
|
+
} else {
|
|
22
|
+
// Email and password provided, so get a temporary superuser token.
|
|
23
|
+
tokenPromise = getSuperuserToken(
|
|
24
|
+
options.url,
|
|
25
|
+
options.superuserCredentials
|
|
26
|
+
);
|
|
27
|
+
}
|
|
18
28
|
} else {
|
|
29
|
+
// No credentials provided, so no token can be used.
|
|
19
30
|
tokenPromise = Promise.resolve(undefined);
|
|
20
31
|
}
|
|
21
32
|
|
|
@@ -58,16 +58,24 @@ export interface PocketBaseLoaderOptions {
|
|
|
58
58
|
* Credentials of a superuser to get full access to the PocketBase instance.
|
|
59
59
|
* This is required to get automatic type generation without a local schema, to access all resources even if they are not public and to fetch content of hidden fields.
|
|
60
60
|
*/
|
|
61
|
-
superuserCredentials?:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
61
|
+
superuserCredentials?:
|
|
62
|
+
| {
|
|
63
|
+
/**
|
|
64
|
+
* Email of the superuser.
|
|
65
|
+
*/
|
|
66
|
+
email: string;
|
|
67
|
+
/**
|
|
68
|
+
* Password of the superuser.
|
|
69
|
+
*/
|
|
70
|
+
password: string;
|
|
71
|
+
}
|
|
72
|
+
| {
|
|
73
|
+
/**
|
|
74
|
+
* Impersonate auth token of the superuser.
|
|
75
|
+
* This token will take precedence over the email and password.
|
|
76
|
+
*/
|
|
77
|
+
impersonateToken: string;
|
|
78
|
+
};
|
|
71
79
|
/**
|
|
72
80
|
* File path to the local schema file.
|
|
73
81
|
* This file will be used to generate the schema for the collection.
|