@djangocfg/ext-base 1.0.0
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/README.md +346 -0
- package/dist/api.cjs +41 -0
- package/dist/api.d.cts +35 -0
- package/dist/api.d.ts +35 -0
- package/dist/api.js +2 -0
- package/dist/auth.cjs +10 -0
- package/dist/auth.d.cts +1 -0
- package/dist/auth.d.ts +1 -0
- package/dist/auth.js +2 -0
- package/dist/chunk-3RG5ZIWI.js +8 -0
- package/dist/chunk-MECBWZG4.js +44 -0
- package/dist/chunk-YQGNYUBX.js +67 -0
- package/dist/hooks.cjs +190 -0
- package/dist/hooks.d.cts +96 -0
- package/dist/hooks.d.ts +96 -0
- package/dist/hooks.js +65 -0
- package/dist/index.cjs +131 -0
- package/dist/index.d.cts +246 -0
- package/dist/index.d.ts +246 -0
- package/dist/index.js +3 -0
- package/package.json +80 -0
- package/src/api/createExtensionAPI.ts +63 -0
- package/src/api/index.ts +5 -0
- package/src/auth/index.ts +13 -0
- package/src/config/env.ts +59 -0
- package/src/config/index.ts +5 -0
- package/src/context/ExtensionProvider.tsx +102 -0
- package/src/context/createExtensionContext.tsx +78 -0
- package/src/context/index.ts +7 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/useInfinitePagination.ts +117 -0
- package/src/hooks/usePagination.ts +155 -0
- package/src/hooks.ts +17 -0
- package/src/index.ts +21 -0
- package/src/logger/createExtensionLogger.ts +61 -0
- package/src/logger/index.ts +5 -0
- package/src/types/context.ts +93 -0
- package/src/types/error.ts +12 -0
- package/src/types/index.ts +17 -0
- package/src/types/logger.ts +17 -0
- package/src/types/pagination.ts +47 -0
- package/src/utils/errors.ts +71 -0
- package/src/utils/index.ts +10 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context and provider types for extension packages
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
export interface ExtensionContextOptions {
|
|
8
|
+
revalidateOnFocus?: boolean;
|
|
9
|
+
revalidateOnReconnect?: boolean;
|
|
10
|
+
revalidateIfStale?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ExtensionMetadata {
|
|
14
|
+
/**
|
|
15
|
+
* Unique extension name (e.g., 'newsletter', 'payments')
|
|
16
|
+
*/
|
|
17
|
+
name: string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Extension version (semver format recommended)
|
|
21
|
+
*/
|
|
22
|
+
version: string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Extension author name or organization
|
|
26
|
+
*/
|
|
27
|
+
author: string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Extension display name
|
|
31
|
+
*/
|
|
32
|
+
displayName?: string;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Extension description
|
|
36
|
+
*/
|
|
37
|
+
description?: string;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* GitHub repository URL
|
|
41
|
+
* @example 'https://github.com/username/repo'
|
|
42
|
+
*/
|
|
43
|
+
githubUrl?: string;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Extension homepage URL
|
|
47
|
+
*/
|
|
48
|
+
homepage?: string;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* License identifier (e.g., 'MIT', 'Apache-2.0')
|
|
52
|
+
*/
|
|
53
|
+
license?: string;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Keywords for search and discovery
|
|
57
|
+
*/
|
|
58
|
+
keywords?: string[];
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Extension icon URL or emoji
|
|
62
|
+
* @example '📧' or 'https://example.com/icon.png'
|
|
63
|
+
*/
|
|
64
|
+
icon?: string;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* List of extension dependencies
|
|
68
|
+
* @example ['payments', 'auth']
|
|
69
|
+
*/
|
|
70
|
+
dependencies?: string[];
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Minimum required DjangoCFG version
|
|
74
|
+
*/
|
|
75
|
+
minVersion?: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface ExtensionProviderProps {
|
|
79
|
+
/**
|
|
80
|
+
* Extension metadata for registration
|
|
81
|
+
*/
|
|
82
|
+
metadata: ExtensionMetadata;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* SWR configuration options
|
|
86
|
+
*/
|
|
87
|
+
options?: ExtensionContextOptions;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Child components
|
|
91
|
+
*/
|
|
92
|
+
children: ReactNode;
|
|
93
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common types for extension packages
|
|
3
|
+
*
|
|
4
|
+
* Re-exports all types from individual modules
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Pagination types
|
|
8
|
+
export * from './pagination';
|
|
9
|
+
|
|
10
|
+
// Context and provider types
|
|
11
|
+
export * from './context';
|
|
12
|
+
|
|
13
|
+
// Error types
|
|
14
|
+
export * from './error';
|
|
15
|
+
|
|
16
|
+
// Logger types
|
|
17
|
+
export * from './logger';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger types for extension packages
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface ExtensionLogger {
|
|
6
|
+
info: (...args: any[]) => void;
|
|
7
|
+
warn: (...args: any[]) => void;
|
|
8
|
+
error: (...args: any[]) => void;
|
|
9
|
+
debug: (...args: any[]) => void;
|
|
10
|
+
success: (...args: any[]) => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface LoggerOptions {
|
|
14
|
+
tag: string;
|
|
15
|
+
level?: 'debug' | 'info' | 'warn' | 'error';
|
|
16
|
+
enabled?: boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pagination types for extension packages
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface PaginatedResponse<T> {
|
|
6
|
+
results: T[];
|
|
7
|
+
count: number;
|
|
8
|
+
next?: number | null;
|
|
9
|
+
previous?: number | null;
|
|
10
|
+
next_page?: number | null;
|
|
11
|
+
previous_page?: number | null;
|
|
12
|
+
has_next?: boolean;
|
|
13
|
+
has_previous?: boolean;
|
|
14
|
+
total_pages?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface PaginationParams {
|
|
18
|
+
page?: number;
|
|
19
|
+
page_size?: number;
|
|
20
|
+
ordering?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface PaginationState {
|
|
24
|
+
page: number;
|
|
25
|
+
pageSize: number;
|
|
26
|
+
totalCount: number;
|
|
27
|
+
totalPages: number;
|
|
28
|
+
hasNext: boolean;
|
|
29
|
+
hasPrevious: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface InfinitePaginationReturn<T> {
|
|
33
|
+
items: T[];
|
|
34
|
+
isLoading: boolean;
|
|
35
|
+
isLoadingMore: boolean;
|
|
36
|
+
error: any;
|
|
37
|
+
hasMore: boolean;
|
|
38
|
+
totalCount: number;
|
|
39
|
+
loadMore: () => void;
|
|
40
|
+
refresh: () => Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface InfinitePaginationOptions {
|
|
44
|
+
pageSize?: number;
|
|
45
|
+
revalidateFirstPage?: boolean;
|
|
46
|
+
parallel?: boolean;
|
|
47
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error handling utilities for extension packages
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { ExtensionError } from '../types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Checks if an error is an ExtensionError
|
|
9
|
+
*/
|
|
10
|
+
export function isExtensionError(error: unknown): error is ExtensionError {
|
|
11
|
+
return (
|
|
12
|
+
typeof error === 'object' &&
|
|
13
|
+
error !== null &&
|
|
14
|
+
'message' in error &&
|
|
15
|
+
'timestamp' in error
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Creates an ExtensionError from any error
|
|
21
|
+
*/
|
|
22
|
+
export function createExtensionError(
|
|
23
|
+
error: unknown,
|
|
24
|
+
code?: string,
|
|
25
|
+
details?: unknown
|
|
26
|
+
): ExtensionError {
|
|
27
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
message,
|
|
31
|
+
code,
|
|
32
|
+
details,
|
|
33
|
+
timestamp: new Date().toISOString(),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Formats an error message for display
|
|
39
|
+
*/
|
|
40
|
+
export function formatErrorMessage(error: unknown): string {
|
|
41
|
+
if (isExtensionError(error)) {
|
|
42
|
+
return error.code ? `[${error.code}] ${error.message}` : error.message;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (error instanceof Error) {
|
|
46
|
+
return error.message;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return String(error);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Safe error handler that logs and optionally calls callback
|
|
54
|
+
*/
|
|
55
|
+
export function handleExtensionError(
|
|
56
|
+
error: unknown,
|
|
57
|
+
logger?: { error: (...args: any[]) => void },
|
|
58
|
+
callback?: (error: ExtensionError) => void
|
|
59
|
+
): void {
|
|
60
|
+
const extensionError = isExtensionError(error)
|
|
61
|
+
? error
|
|
62
|
+
: createExtensionError(error);
|
|
63
|
+
|
|
64
|
+
if (logger) {
|
|
65
|
+
logger.error('Extension error:', extensionError);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (callback) {
|
|
69
|
+
callback(extensionError);
|
|
70
|
+
}
|
|
71
|
+
}
|