mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-06 20:15:17 +02:00
feat: implement page limit exceeded notifications and enhance handling in the notification system
This commit is contained in:
parent
4e04b4053a
commit
d476e18c54
7 changed files with 291 additions and 29 deletions
|
|
@ -9,6 +9,7 @@ export const inboxItemTypeEnum = z.enum([
|
|||
"connector_indexing",
|
||||
"document_processing",
|
||||
"new_mention",
|
||||
"page_limit_exceeded",
|
||||
]);
|
||||
|
||||
/**
|
||||
|
|
@ -88,6 +89,21 @@ export const newMentionMetadata = z.object({
|
|||
content_preview: z.string(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Page limit exceeded metadata schema
|
||||
*/
|
||||
export const pageLimitExceededMetadata = baseInboxItemMetadata.extend({
|
||||
document_name: z.string(),
|
||||
document_type: z.string(),
|
||||
pages_used: z.number(),
|
||||
pages_limit: z.number(),
|
||||
pages_to_add: z.number(),
|
||||
error_type: z.literal("page_limit_exceeded"),
|
||||
// Navigation target for frontend
|
||||
action_url: z.string(),
|
||||
action_label: z.string(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Union of all inbox item metadata types
|
||||
* Use this when the inbox item type is unknown
|
||||
|
|
@ -96,6 +112,7 @@ export const inboxItemMetadata = z.union([
|
|||
connectorIndexingMetadata,
|
||||
documentProcessingMetadata,
|
||||
newMentionMetadata,
|
||||
pageLimitExceededMetadata,
|
||||
baseInboxItemMetadata,
|
||||
]);
|
||||
|
||||
|
|
@ -133,6 +150,11 @@ export const newMentionInboxItem = inboxItem.extend({
|
|||
metadata: newMentionMetadata,
|
||||
});
|
||||
|
||||
export const pageLimitExceededInboxItem = inboxItem.extend({
|
||||
type: z.literal("page_limit_exceeded"),
|
||||
metadata: pageLimitExceededMetadata,
|
||||
});
|
||||
|
||||
// =============================================================================
|
||||
// API Request/Response Schemas
|
||||
// =============================================================================
|
||||
|
|
@ -229,13 +251,27 @@ export function isNewMentionMetadata(metadata: unknown): metadata is NewMentionM
|
|||
return newMentionMetadata.safeParse(metadata).success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard for PageLimitExceededMetadata
|
||||
*/
|
||||
export function isPageLimitExceededMetadata(
|
||||
metadata: unknown
|
||||
): metadata is PageLimitExceededMetadata {
|
||||
return pageLimitExceededMetadata.safeParse(metadata).success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Safe metadata parser - returns typed metadata or null
|
||||
*/
|
||||
export function parseInboxItemMetadata(
|
||||
type: InboxItemTypeEnum,
|
||||
metadata: unknown
|
||||
): ConnectorIndexingMetadata | DocumentProcessingMetadata | NewMentionMetadata | null {
|
||||
):
|
||||
| ConnectorIndexingMetadata
|
||||
| DocumentProcessingMetadata
|
||||
| NewMentionMetadata
|
||||
| PageLimitExceededMetadata
|
||||
| null {
|
||||
switch (type) {
|
||||
case "connector_indexing": {
|
||||
const result = connectorIndexingMetadata.safeParse(metadata);
|
||||
|
|
@ -249,6 +285,10 @@ export function parseInboxItemMetadata(
|
|||
const result = newMentionMetadata.safeParse(metadata);
|
||||
return result.success ? result.data : null;
|
||||
}
|
||||
case "page_limit_exceeded": {
|
||||
const result = pageLimitExceededMetadata.safeParse(metadata);
|
||||
return result.success ? result.data : null;
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
@ -265,11 +305,13 @@ export type BaseInboxItemMetadata = z.infer<typeof baseInboxItemMetadata>;
|
|||
export type ConnectorIndexingMetadata = z.infer<typeof connectorIndexingMetadata>;
|
||||
export type DocumentProcessingMetadata = z.infer<typeof documentProcessingMetadata>;
|
||||
export type NewMentionMetadata = z.infer<typeof newMentionMetadata>;
|
||||
export type PageLimitExceededMetadata = z.infer<typeof pageLimitExceededMetadata>;
|
||||
export type InboxItemMetadata = z.infer<typeof inboxItemMetadata>;
|
||||
export type InboxItem = z.infer<typeof inboxItem>;
|
||||
export type ConnectorIndexingInboxItem = z.infer<typeof connectorIndexingInboxItem>;
|
||||
export type DocumentProcessingInboxItem = z.infer<typeof documentProcessingInboxItem>;
|
||||
export type NewMentionInboxItem = z.infer<typeof newMentionInboxItem>;
|
||||
export type PageLimitExceededInboxItem = z.infer<typeof pageLimitExceededInboxItem>;
|
||||
|
||||
// API Request/Response types
|
||||
export type GetNotificationsRequest = z.infer<typeof getNotificationsRequest>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue