@djangocfg/ext-base 1.0.0 → 1.0.2

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.
Files changed (41) hide show
  1. package/README.md +140 -176
  2. package/package.json +28 -12
  3. package/preview.png +0 -0
  4. package/src/cli/index.ts +274 -0
  5. package/src/config.ts +17 -0
  6. package/src/index.ts +2 -1
  7. package/src/metadata.ts +73 -0
  8. package/src/types/context.ts +124 -3
  9. package/src/utils/createExtensionConfig.ts +139 -0
  10. package/src/utils/index.ts +5 -0
  11. package/templates/extension-template/README.md.template +62 -0
  12. package/templates/extension-template/package.json.template +73 -0
  13. package/templates/extension-template/preview.png +0 -0
  14. package/templates/extension-template/src/components/.gitkeep +0 -0
  15. package/templates/extension-template/src/config.ts +35 -0
  16. package/templates/extension-template/src/contexts/__PROVIDER_NAME__Context.tsx +41 -0
  17. package/templates/extension-template/src/contexts/__PROVIDER_NAME__ExtensionProvider.tsx +36 -0
  18. package/templates/extension-template/src/hooks/index.ts +27 -0
  19. package/templates/extension-template/src/index.ts +17 -0
  20. package/templates/extension-template/src/types.ts +7 -0
  21. package/templates/extension-template/tsconfig.json +8 -0
  22. package/templates/extension-template/tsup.config.ts +26 -0
  23. package/dist/api.cjs +0 -41
  24. package/dist/api.d.cts +0 -35
  25. package/dist/api.d.ts +0 -35
  26. package/dist/api.js +0 -2
  27. package/dist/auth.cjs +0 -10
  28. package/dist/auth.d.cts +0 -1
  29. package/dist/auth.d.ts +0 -1
  30. package/dist/auth.js +0 -2
  31. package/dist/chunk-3RG5ZIWI.js +0 -8
  32. package/dist/chunk-MECBWZG4.js +0 -44
  33. package/dist/chunk-YQGNYUBX.js +0 -67
  34. package/dist/hooks.cjs +0 -190
  35. package/dist/hooks.d.cts +0 -96
  36. package/dist/hooks.d.ts +0 -96
  37. package/dist/hooks.js +0 -65
  38. package/dist/index.cjs +0 -131
  39. package/dist/index.d.cts +0 -246
  40. package/dist/index.d.ts +0 -246
  41. package/dist/index.js +0 -3
package/dist/index.d.cts DELETED
@@ -1,246 +0,0 @@
1
- import { ReactNode } from 'react';
2
- export { createExtensionAPI, getSharedAuthStorage } from './api.cjs';
3
-
4
- /**
5
- * Pagination types for extension packages
6
- */
7
- interface PaginatedResponse<T> {
8
- results: T[];
9
- count: number;
10
- next?: number | null;
11
- previous?: number | null;
12
- next_page?: number | null;
13
- previous_page?: number | null;
14
- has_next?: boolean;
15
- has_previous?: boolean;
16
- total_pages?: number;
17
- }
18
- interface PaginationParams {
19
- page?: number;
20
- page_size?: number;
21
- ordering?: string;
22
- }
23
- interface PaginationState {
24
- page: number;
25
- pageSize: number;
26
- totalCount: number;
27
- totalPages: number;
28
- hasNext: boolean;
29
- hasPrevious: boolean;
30
- }
31
- interface InfinitePaginationReturn<T> {
32
- items: T[];
33
- isLoading: boolean;
34
- isLoadingMore: boolean;
35
- error: any;
36
- hasMore: boolean;
37
- totalCount: number;
38
- loadMore: () => void;
39
- refresh: () => Promise<void>;
40
- }
41
- interface InfinitePaginationOptions {
42
- pageSize?: number;
43
- revalidateFirstPage?: boolean;
44
- parallel?: boolean;
45
- }
46
-
47
- /**
48
- * Context and provider types for extension packages
49
- */
50
-
51
- interface ExtensionContextOptions {
52
- revalidateOnFocus?: boolean;
53
- revalidateOnReconnect?: boolean;
54
- revalidateIfStale?: boolean;
55
- }
56
- interface ExtensionMetadata {
57
- /**
58
- * Unique extension name (e.g., 'newsletter', 'payments')
59
- */
60
- name: string;
61
- /**
62
- * Extension version (semver format recommended)
63
- */
64
- version: string;
65
- /**
66
- * Extension author name or organization
67
- */
68
- author: string;
69
- /**
70
- * Extension display name
71
- */
72
- displayName?: string;
73
- /**
74
- * Extension description
75
- */
76
- description?: string;
77
- /**
78
- * GitHub repository URL
79
- * @example 'https://github.com/username/repo'
80
- */
81
- githubUrl?: string;
82
- /**
83
- * Extension homepage URL
84
- */
85
- homepage?: string;
86
- /**
87
- * License identifier (e.g., 'MIT', 'Apache-2.0')
88
- */
89
- license?: string;
90
- /**
91
- * Keywords for search and discovery
92
- */
93
- keywords?: string[];
94
- /**
95
- * Extension icon URL or emoji
96
- * @example '📧' or 'https://example.com/icon.png'
97
- */
98
- icon?: string;
99
- /**
100
- * List of extension dependencies
101
- * @example ['payments', 'auth']
102
- */
103
- dependencies?: string[];
104
- /**
105
- * Minimum required DjangoCFG version
106
- */
107
- minVersion?: string;
108
- }
109
- interface ExtensionProviderProps {
110
- /**
111
- * Extension metadata for registration
112
- */
113
- metadata: ExtensionMetadata;
114
- /**
115
- * SWR configuration options
116
- */
117
- options?: ExtensionContextOptions;
118
- /**
119
- * Child components
120
- */
121
- children: ReactNode;
122
- }
123
-
124
- /**
125
- * Error types for extension packages
126
- */
127
- interface ExtensionError {
128
- message: string;
129
- code?: string;
130
- details?: unknown;
131
- timestamp: string;
132
- }
133
- type ErrorHandler = (error: Error | ExtensionError) => void;
134
-
135
- /**
136
- * Logger types for extension packages
137
- */
138
- interface ExtensionLogger {
139
- info: (...args: any[]) => void;
140
- warn: (...args: any[]) => void;
141
- error: (...args: any[]) => void;
142
- debug: (...args: any[]) => void;
143
- success: (...args: any[]) => void;
144
- }
145
- interface LoggerOptions {
146
- tag: string;
147
- level?: 'debug' | 'info' | 'warn' | 'error';
148
- enabled?: boolean;
149
- }
150
-
151
- /**
152
- * Environment configuration utilities
153
- *
154
- * Safe to use in both client and server contexts.
155
- * Can be imported from server-safe entry point.
156
- */
157
- /**
158
- * Check if running in development mode
159
- */
160
- declare const isDevelopment: boolean;
161
- /**
162
- * Check if running in production mode
163
- */
164
- declare const isProduction: boolean;
165
- /**
166
- * Check if running in test mode
167
- */
168
- declare const isTest: boolean;
169
- /**
170
- * Check if this is a static build (Next.js export)
171
- */
172
- declare const isStaticBuild: boolean;
173
- /**
174
- * Check if code is running on client side
175
- * Safe to use in both client and server contexts
176
- */
177
- declare const isClient: boolean;
178
- /**
179
- * Check if code is running on server side
180
- * Safe to use in both client and server contexts
181
- */
182
- declare const isServer: boolean;
183
- /**
184
- * Get API URL from environment
185
- * Returns empty string if not set
186
- */
187
- declare const getApiUrl: () => string;
188
- /**
189
- * Environment configuration object
190
- */
191
- declare const env: {
192
- readonly isDevelopment: boolean;
193
- readonly isProduction: boolean;
194
- readonly isTest: boolean;
195
- readonly isStaticBuild: boolean;
196
- readonly isClient: boolean;
197
- readonly isServer: boolean;
198
- readonly getApiUrl: () => string;
199
- };
200
-
201
- /**
202
- * Error handling utilities for extension packages
203
- */
204
-
205
- /**
206
- * Checks if an error is an ExtensionError
207
- */
208
- declare function isExtensionError(error: unknown): error is ExtensionError;
209
- /**
210
- * Creates an ExtensionError from any error
211
- */
212
- declare function createExtensionError(error: unknown, code?: string, details?: unknown): ExtensionError;
213
- /**
214
- * Formats an error message for display
215
- */
216
- declare function formatErrorMessage(error: unknown): string;
217
- /**
218
- * Safe error handler that logs and optionally calls callback
219
- */
220
- declare function handleExtensionError(error: unknown, logger?: {
221
- error: (...args: any[]) => void;
222
- }, callback?: (error: ExtensionError) => void): void;
223
-
224
- /**
225
- * Logger factory for extension packages
226
- */
227
-
228
- /**
229
- * Creates a tagged logger for an extension
230
- *
231
- * @example
232
- * ```ts
233
- * // In extension package
234
- * export const logger = createExtensionLogger({
235
- * tag: 'ext-newsletter',
236
- * level: 'info'
237
- * });
238
- *
239
- * // Usage
240
- * logger.info('Campaign created:', campaignId);
241
- * logger.error('Failed to send campaign:', error);
242
- * ```
243
- */
244
- declare function createExtensionLogger(options: LoggerOptions): ExtensionLogger;
245
-
246
- export { type ErrorHandler, type ExtensionContextOptions, type ExtensionError, type ExtensionLogger, type ExtensionMetadata, type ExtensionProviderProps, type InfinitePaginationOptions, type InfinitePaginationReturn, type LoggerOptions, type PaginatedResponse, type PaginationParams, type PaginationState, createExtensionError, createExtensionLogger, env, formatErrorMessage, getApiUrl, handleExtensionError, isClient, isDevelopment, isExtensionError, isProduction, isServer, isStaticBuild, isTest };
package/dist/index.d.ts DELETED
@@ -1,246 +0,0 @@
1
- import { ReactNode } from 'react';
2
- export { createExtensionAPI, getSharedAuthStorage } from './api.js';
3
-
4
- /**
5
- * Pagination types for extension packages
6
- */
7
- interface PaginatedResponse<T> {
8
- results: T[];
9
- count: number;
10
- next?: number | null;
11
- previous?: number | null;
12
- next_page?: number | null;
13
- previous_page?: number | null;
14
- has_next?: boolean;
15
- has_previous?: boolean;
16
- total_pages?: number;
17
- }
18
- interface PaginationParams {
19
- page?: number;
20
- page_size?: number;
21
- ordering?: string;
22
- }
23
- interface PaginationState {
24
- page: number;
25
- pageSize: number;
26
- totalCount: number;
27
- totalPages: number;
28
- hasNext: boolean;
29
- hasPrevious: boolean;
30
- }
31
- interface InfinitePaginationReturn<T> {
32
- items: T[];
33
- isLoading: boolean;
34
- isLoadingMore: boolean;
35
- error: any;
36
- hasMore: boolean;
37
- totalCount: number;
38
- loadMore: () => void;
39
- refresh: () => Promise<void>;
40
- }
41
- interface InfinitePaginationOptions {
42
- pageSize?: number;
43
- revalidateFirstPage?: boolean;
44
- parallel?: boolean;
45
- }
46
-
47
- /**
48
- * Context and provider types for extension packages
49
- */
50
-
51
- interface ExtensionContextOptions {
52
- revalidateOnFocus?: boolean;
53
- revalidateOnReconnect?: boolean;
54
- revalidateIfStale?: boolean;
55
- }
56
- interface ExtensionMetadata {
57
- /**
58
- * Unique extension name (e.g., 'newsletter', 'payments')
59
- */
60
- name: string;
61
- /**
62
- * Extension version (semver format recommended)
63
- */
64
- version: string;
65
- /**
66
- * Extension author name or organization
67
- */
68
- author: string;
69
- /**
70
- * Extension display name
71
- */
72
- displayName?: string;
73
- /**
74
- * Extension description
75
- */
76
- description?: string;
77
- /**
78
- * GitHub repository URL
79
- * @example 'https://github.com/username/repo'
80
- */
81
- githubUrl?: string;
82
- /**
83
- * Extension homepage URL
84
- */
85
- homepage?: string;
86
- /**
87
- * License identifier (e.g., 'MIT', 'Apache-2.0')
88
- */
89
- license?: string;
90
- /**
91
- * Keywords for search and discovery
92
- */
93
- keywords?: string[];
94
- /**
95
- * Extension icon URL or emoji
96
- * @example '📧' or 'https://example.com/icon.png'
97
- */
98
- icon?: string;
99
- /**
100
- * List of extension dependencies
101
- * @example ['payments', 'auth']
102
- */
103
- dependencies?: string[];
104
- /**
105
- * Minimum required DjangoCFG version
106
- */
107
- minVersion?: string;
108
- }
109
- interface ExtensionProviderProps {
110
- /**
111
- * Extension metadata for registration
112
- */
113
- metadata: ExtensionMetadata;
114
- /**
115
- * SWR configuration options
116
- */
117
- options?: ExtensionContextOptions;
118
- /**
119
- * Child components
120
- */
121
- children: ReactNode;
122
- }
123
-
124
- /**
125
- * Error types for extension packages
126
- */
127
- interface ExtensionError {
128
- message: string;
129
- code?: string;
130
- details?: unknown;
131
- timestamp: string;
132
- }
133
- type ErrorHandler = (error: Error | ExtensionError) => void;
134
-
135
- /**
136
- * Logger types for extension packages
137
- */
138
- interface ExtensionLogger {
139
- info: (...args: any[]) => void;
140
- warn: (...args: any[]) => void;
141
- error: (...args: any[]) => void;
142
- debug: (...args: any[]) => void;
143
- success: (...args: any[]) => void;
144
- }
145
- interface LoggerOptions {
146
- tag: string;
147
- level?: 'debug' | 'info' | 'warn' | 'error';
148
- enabled?: boolean;
149
- }
150
-
151
- /**
152
- * Environment configuration utilities
153
- *
154
- * Safe to use in both client and server contexts.
155
- * Can be imported from server-safe entry point.
156
- */
157
- /**
158
- * Check if running in development mode
159
- */
160
- declare const isDevelopment: boolean;
161
- /**
162
- * Check if running in production mode
163
- */
164
- declare const isProduction: boolean;
165
- /**
166
- * Check if running in test mode
167
- */
168
- declare const isTest: boolean;
169
- /**
170
- * Check if this is a static build (Next.js export)
171
- */
172
- declare const isStaticBuild: boolean;
173
- /**
174
- * Check if code is running on client side
175
- * Safe to use in both client and server contexts
176
- */
177
- declare const isClient: boolean;
178
- /**
179
- * Check if code is running on server side
180
- * Safe to use in both client and server contexts
181
- */
182
- declare const isServer: boolean;
183
- /**
184
- * Get API URL from environment
185
- * Returns empty string if not set
186
- */
187
- declare const getApiUrl: () => string;
188
- /**
189
- * Environment configuration object
190
- */
191
- declare const env: {
192
- readonly isDevelopment: boolean;
193
- readonly isProduction: boolean;
194
- readonly isTest: boolean;
195
- readonly isStaticBuild: boolean;
196
- readonly isClient: boolean;
197
- readonly isServer: boolean;
198
- readonly getApiUrl: () => string;
199
- };
200
-
201
- /**
202
- * Error handling utilities for extension packages
203
- */
204
-
205
- /**
206
- * Checks if an error is an ExtensionError
207
- */
208
- declare function isExtensionError(error: unknown): error is ExtensionError;
209
- /**
210
- * Creates an ExtensionError from any error
211
- */
212
- declare function createExtensionError(error: unknown, code?: string, details?: unknown): ExtensionError;
213
- /**
214
- * Formats an error message for display
215
- */
216
- declare function formatErrorMessage(error: unknown): string;
217
- /**
218
- * Safe error handler that logs and optionally calls callback
219
- */
220
- declare function handleExtensionError(error: unknown, logger?: {
221
- error: (...args: any[]) => void;
222
- }, callback?: (error: ExtensionError) => void): void;
223
-
224
- /**
225
- * Logger factory for extension packages
226
- */
227
-
228
- /**
229
- * Creates a tagged logger for an extension
230
- *
231
- * @example
232
- * ```ts
233
- * // In extension package
234
- * export const logger = createExtensionLogger({
235
- * tag: 'ext-newsletter',
236
- * level: 'info'
237
- * });
238
- *
239
- * // Usage
240
- * logger.info('Campaign created:', campaignId);
241
- * logger.error('Failed to send campaign:', error);
242
- * ```
243
- */
244
- declare function createExtensionLogger(options: LoggerOptions): ExtensionLogger;
245
-
246
- export { type ErrorHandler, type ExtensionContextOptions, type ExtensionError, type ExtensionLogger, type ExtensionMetadata, type ExtensionProviderProps, type InfinitePaginationOptions, type InfinitePaginationReturn, type LoggerOptions, type PaginatedResponse, type PaginationParams, type PaginationState, createExtensionError, createExtensionLogger, env, formatErrorMessage, getApiUrl, handleExtensionError, isClient, isDevelopment, isExtensionError, isProduction, isServer, isStaticBuild, isTest };
package/dist/index.js DELETED
@@ -1,3 +0,0 @@
1
- export { createExtensionError, createExtensionLogger, formatErrorMessage, handleExtensionError, isExtensionError } from './chunk-YQGNYUBX.js';
2
- export { createExtensionAPI, env, getApiUrl, getSharedAuthStorage, isClient, isDevelopment, isProduction, isServer, isStaticBuild, isTest } from './chunk-MECBWZG4.js';
3
- import './chunk-3RG5ZIWI.js';