allow email visibility for exec

This commit is contained in:
chark1es 2025-03-12 01:27:37 -07:00
parent 0a8348729b
commit e2933b1c5f

View file

@ -152,6 +152,7 @@ export class Get {
...(options?.fields && { fields: options.fields.join(",") }), ...(options?.fields && { fields: options.fields.join(",") }),
...(expandString && { expand: expandString }), ...(expandString && { expand: expandString }),
...(options?.disableAutoCancellation && { requestKey: null }), ...(options?.disableAutoCancellation && { requestKey: null }),
emailVisibility: true,
}; };
const result = await pb const result = await pb
@ -206,6 +207,7 @@ export class Get {
...(options?.fields && { fields: options.fields.join(",") }), ...(options?.fields && { fields: options.fields.join(",") }),
...(expandString && { expand: expandString }), ...(expandString && { expand: expandString }),
...(options?.disableAutoCancellation && { requestKey: null }), ...(options?.disableAutoCancellation && { requestKey: null }),
emailVisibility: true,
}; };
const result = await pb const result = await pb
@ -251,11 +253,24 @@ export class Get {
try { try {
const pb = this.auth.getPocketBase(); const pb = this.auth.getPocketBase();
// Handle expand parameter
let expandString: string | undefined;
if (options?.expand) {
if (Array.isArray(options.expand)) {
expandString = options.expand.join(",");
} else if (typeof options.expand === "string") {
expandString = options.expand;
}
}
const requestOptions = { const requestOptions = {
...(filter && { filter }), ...(filter && { filter }),
...(sort && { sort }), ...(sort && { sort }),
...(options?.fields && { fields: options.fields.join(",") }), ...(options?.fields && { fields: options.fields.join(",") }),
...(expandString && { expand: expandString }),
...(options?.disableAutoCancellation && { requestKey: null }), ...(options?.disableAutoCancellation && { requestKey: null }),
emailVisibility: true,
}; };
const result = await pb const result = await pb
@ -290,14 +305,9 @@ export class Get {
options?: RequestOptions, options?: RequestOptions,
): Promise<T[]> { ): Promise<T[]> {
if (!this.auth.isAuthenticated()) { if (!this.auth.isAuthenticated()) {
console.warn( throw new Error("User must be authenticated to retrieve all records");
`User not authenticated, but attempting to get records from ${collectionName} anyway`,
);
} }
// Try to get records even if authentication check fails
// This is a workaround for cases where isAuthenticated() returns false
// but the token is still valid for API requests
try { try {
const pb = this.auth.getPocketBase(); const pb = this.auth.getPocketBase();
@ -317,11 +327,14 @@ export class Get {
...(options?.fields && { fields: options.fields.join(",") }), ...(options?.fields && { fields: options.fields.join(",") }),
...(expandString && { expand: expandString }), ...(expandString && { expand: expandString }),
...(options?.disableAutoCancellation && { requestKey: null }), ...(options?.disableAutoCancellation && { requestKey: null }),
emailVisibility: true,
}; };
// Get all items (will handle pagination automatically)
const result = await pb const result = await pb
.collection(collectionName) .collection(collectionName)
.getFullList<T>(requestOptions); .getFullList<T>(requestOptions);
return result.map((item) => convertUTCToLocal(item)); return result.map((item) => convertUTCToLocal(item));
} catch (err) { } catch (err) {
console.error(`Failed to get all records from ${collectionName}:`, err); console.error(`Failed to get all records from ${collectionName}:`, err);