@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
@@ -0,0 +1,62 @@
1
+ <div align="center">
2
+
3
+ ![DjangoCFG Extension Preview](https://unpkg.com/@djangocfg/ext-__NAME__@latest/preview.png)
4
+
5
+ </div>
6
+
7
+ # @djangocfg/ext-__NAME__
8
+
9
+ __DESCRIPTION__
10
+
11
+ **Part of [DjangoCFG](https://djangocfg.com)** — modern Django framework for production-ready SaaS applications.
12
+
13
+ ## Features
14
+
15
+ - Feature 1
16
+ - Feature 2
17
+ - Feature 3
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ pnpm add @djangocfg/ext-__NAME__
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ### Provider Setup
28
+
29
+ ```typescript
30
+ import { __PROVIDER_NAME__ExtensionProvider } from '@djangocfg/ext-__NAME__/hooks';
31
+
32
+ export default function RootLayout({ children }) {
33
+ return (
34
+ <__PROVIDER_NAME__ExtensionProvider>
35
+ {children}
36
+ </__PROVIDER_NAME__ExtensionProvider>
37
+ );
38
+ }
39
+ ```
40
+
41
+ ### Using Hooks
42
+
43
+ ```typescript
44
+ 'use client';
45
+
46
+ import { use__PROVIDER_NAME__ } from '@djangocfg/ext-__NAME__/hooks';
47
+
48
+ export function MyComponent() {
49
+ const context = use__PROVIDER_NAME__();
50
+
51
+ return <div>Your component</div>;
52
+ }
53
+ ```
54
+
55
+ ## License
56
+
57
+ MIT
58
+
59
+ ## Links
60
+
61
+ - [DjangoCFG Documentation](https://djangocfg.com)
62
+ - [GitHub](https://github.com/markolofsen/django-cfg)
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@djangocfg/ext-__NAME__",
3
+ "version": "1.0.0",
4
+ "description": "__DESCRIPTION__",
5
+ "keywords": [
6
+ "django",
7
+ "djangocfg",
8
+ "extension",
9
+ "__NAME__",
10
+ "typescript",
11
+ "react"
12
+ ],
13
+ "author": {
14
+ "name": "DjangoCFG",
15
+ "url": "https://djangocfg.com"
16
+ },
17
+ "homepage": "https://djangocfg.com",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/markolofsen/django-cfg.git",
21
+ "directory": "extensions/__NAME__"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/markolofsen/django-cfg/issues"
25
+ },
26
+ "license": "MIT",
27
+ "type": "module",
28
+ "main": "./dist/index.cjs",
29
+ "module": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/index.js",
35
+ "require": "./dist/index.cjs"
36
+ },
37
+ "./hooks": {
38
+ "types": "./dist/hooks.d.ts",
39
+ "import": "./dist/hooks.js",
40
+ "require": "./dist/hooks.cjs"
41
+ }
42
+ },
43
+ "files": [
44
+ "dist",
45
+ "src",
46
+ "preview.png"
47
+ ],
48
+ "scripts": {
49
+ "build": "tsup",
50
+ "dev": "tsup --watch",
51
+ "check": "tsc --noEmit"
52
+ },
53
+ "peerDependencies": {
54
+ "@djangocfg/ext-base": "latest",
55
+ "@djangocfg/ui-core": "latest",
56
+ "@djangocfg/ui-nextjs": "latest",
57
+ "consola": "^3.4.2",
58
+ "lucide-react": "^0.545.0",
59
+ "next": "^15.5.7",
60
+ "react": "^18 || ^19",
61
+ "swr": "^2.3.7"
62
+ },
63
+ "devDependencies": {
64
+ "@djangocfg/ext-base": "latest",
65
+ "@djangocfg/typescript-config": "latest",
66
+ "@types/node": "^24.7.2",
67
+ "@types/react": "^19.0.0",
68
+ "consola": "^3.4.2",
69
+ "swr": "^2.3.7",
70
+ "tsup": "^8.5.0",
71
+ "typescript": "^5.9.3"
72
+ }
73
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * __DISPLAY_NAME__ extension configuration
3
+ */
4
+
5
+ import { createExtensionConfig } from '@djangocfg/ext-base';
6
+ import packageJson from '../package.json';
7
+
8
+ export const extensionConfig = createExtensionConfig(packageJson, {
9
+ name: '__NAME__',
10
+ displayName: '__DISPLAY_NAME__',
11
+ icon: '__ICON__',
12
+ category: '__CATEGORY__',
13
+ features: [
14
+ 'Feature 1',
15
+ 'Feature 2',
16
+ 'Feature 3',
17
+ ],
18
+ minVersion: '2.0.0',
19
+ examples: [
20
+ {
21
+ title: 'Basic Usage',
22
+ description: 'How to use this extension',
23
+ code: `import { __PROVIDER_NAME__ExtensionProvider } from '@djangocfg/ext-__NAME__/hooks';
24
+
25
+ export default function RootLayout({ children }) {
26
+ return (
27
+ <__PROVIDER_NAME__ExtensionProvider>
28
+ {children}
29
+ </__PROVIDER_NAME__ExtensionProvider>
30
+ );
31
+ }`,
32
+ language: 'tsx',
33
+ },
34
+ ],
35
+ });
@@ -0,0 +1,41 @@
1
+ 'use client';
2
+
3
+ /**
4
+ * Main __DISPLAY_NAME__ Context
5
+ */
6
+
7
+ import { createContext, useContext, type ReactNode } from 'react';
8
+
9
+ interface __PROVIDER_NAME__ContextValue {
10
+ // Add your context values here
11
+ }
12
+
13
+ const __PROVIDER_NAME__Context = createContext<__PROVIDER_NAME__ContextValue | undefined>(undefined);
14
+
15
+ export interface __PROVIDER_NAME__ProviderProps {
16
+ children: ReactNode;
17
+ }
18
+
19
+ export function __PROVIDER_NAME__Provider({ children }: __PROVIDER_NAME__ProviderProps) {
20
+ const value: __PROVIDER_NAME__ContextValue = {
21
+ // Implement your context logic here
22
+ };
23
+
24
+ return (
25
+ <__PROVIDER_NAME__Context.Provider value={value}>
26
+ {children}
27
+ </__PROVIDER_NAME__Context.Provider>
28
+ );
29
+ }
30
+
31
+ export function use__PROVIDER_NAME__() {
32
+ const context = useContext(__PROVIDER_NAME__Context);
33
+ if (context === undefined) {
34
+ throw new Error('use__PROVIDER_NAME__ must be used within __PROVIDER_NAME__Provider');
35
+ }
36
+ return context;
37
+ }
38
+
39
+ export function use__PROVIDER_NAME__Optional() {
40
+ return useContext(__PROVIDER_NAME__Context);
41
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Main __DISPLAY_NAME__ Extension Provider
3
+ *
4
+ * Wraps all contexts with ExtensionProvider for proper registration
5
+ */
6
+
7
+ 'use client';
8
+
9
+ import type { ReactNode } from 'react';
10
+ import { ExtensionProvider } from '@djangocfg/ext-base/hooks';
11
+ import { extensionConfig } from '../config';
12
+ import { __PROVIDER_NAME__Provider } from './__PROVIDER_NAME__Context';
13
+
14
+ interface __PROVIDER_NAME__ExtensionProviderProps {
15
+ children: ReactNode;
16
+ }
17
+
18
+ /**
19
+ * Main provider for __DISPLAY_NAME__ extension
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * <__PROVIDER_NAME__ExtensionProvider>
24
+ * <YourApp />
25
+ * </__PROVIDER_NAME__ExtensionProvider>
26
+ * ```
27
+ */
28
+ export function __PROVIDER_NAME__ExtensionProvider({ children }: __PROVIDER_NAME__ExtensionProviderProps) {
29
+ return (
30
+ <ExtensionProvider metadata={extensionConfig}>
31
+ <__PROVIDER_NAME__Provider>
32
+ {children}
33
+ </__PROVIDER_NAME__Provider>
34
+ </ExtensionProvider>
35
+ );
36
+ }
@@ -0,0 +1,27 @@
1
+ 'use client';
2
+
3
+ /**
4
+ * @djangocfg/ext-__NAME__/hooks
5
+ * React hooks and client-only components
6
+ *
7
+ * This entry point includes React components, hooks, and SWR functionality.
8
+ * NOT safe for Server Components.
9
+ */
10
+
11
+ // ============================================================================
12
+ // Re-export everything from main entry (types, constants)
13
+ // ============================================================================
14
+ export * from '../index';
15
+
16
+ // ============================================================================
17
+ // Contexts & Hooks
18
+ // ============================================================================
19
+ export {
20
+ __PROVIDER_NAME__ExtensionProvider,
21
+ } from '../contexts/__PROVIDER_NAME__ExtensionProvider';
22
+
23
+ export {
24
+ __PROVIDER_NAME__Provider,
25
+ use__PROVIDER_NAME__,
26
+ use__PROVIDER_NAME__Optional,
27
+ } from '../contexts/__PROVIDER_NAME__Context';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @djangocfg/ext-__NAME__
3
+ * Server-safe entry point (no client-only code)
4
+ *
5
+ * Contains types and server-safe exports only.
6
+ * For React hooks and SWR, use '@djangocfg/ext-__NAME__/hooks'
7
+ */
8
+
9
+ // ============================================================================
10
+ // Config
11
+ // ============================================================================
12
+ export { extensionConfig } from './config';
13
+
14
+ // ============================================================================
15
+ // Types
16
+ // ============================================================================
17
+ export type * from './types';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Extension TypeScript types
3
+ */
4
+
5
+ export interface ExtensionData {
6
+ // Add your types here
7
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "@djangocfg/typescript-config/nextjs.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist"
5
+ },
6
+ "include": ["src"],
7
+ "exclude": ["node_modules", "dist"]
8
+ }
@@ -0,0 +1,26 @@
1
+ import { defineConfig } from 'tsup';
2
+
3
+ export default defineConfig({
4
+ entry: {
5
+ index: 'src/index.ts',
6
+ hooks: 'src/hooks/index.ts',
7
+ },
8
+ format: ['esm', 'cjs'],
9
+ dts: true,
10
+ splitting: false,
11
+ sourcemap: true,
12
+ clean: true,
13
+ external: [
14
+ 'react',
15
+ 'react-dom',
16
+ 'next',
17
+ 'lucide-react',
18
+ '@djangocfg/ext-base',
19
+ '@djangocfg/ui-nextjs',
20
+ 'swr',
21
+ 'consola',
22
+ ],
23
+ banner: {
24
+ js: "'use client';",
25
+ },
26
+ });
package/dist/api.cjs DELETED
@@ -1,41 +0,0 @@
1
- 'use strict';
2
-
3
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
4
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
5
- }) : x)(function(x) {
6
- if (typeof require !== "undefined") return require.apply(this, arguments);
7
- throw Error('Dynamic require of "' + x + '" is not supported');
8
- });
9
-
10
- // src/config/env.ts
11
- process.env.NODE_ENV === "development";
12
- process.env.NODE_ENV === "production";
13
- process.env.NODE_ENV === "test";
14
- var isStaticBuild = process.env.NEXT_PUBLIC_STATIC_BUILD === "true";
15
- var getApiUrl = () => {
16
- return process.env.NEXT_PUBLIC_API_URL || "";
17
- };
18
-
19
- // src/api/createExtensionAPI.ts
20
- function createExtensionAPI(APIClass) {
21
- let storage;
22
- try {
23
- const { api: accountsApi } = __require("@djangocfg/api");
24
- storage = accountsApi._storage;
25
- } catch (error) {
26
- storage = void 0;
27
- }
28
- const apiUrl = isStaticBuild ? "" : getApiUrl();
29
- return new APIClass(apiUrl, storage ? { storage } : void 0);
30
- }
31
- function getSharedAuthStorage() {
32
- try {
33
- const { api: accountsApi } = __require("@djangocfg/api");
34
- return accountsApi._storage;
35
- } catch (error) {
36
- return void 0;
37
- }
38
- }
39
-
40
- exports.createExtensionAPI = createExtensionAPI;
41
- exports.getSharedAuthStorage = getSharedAuthStorage;
package/dist/api.d.cts DELETED
@@ -1,35 +0,0 @@
1
- /**
2
- * Factory for creating extension API instances
3
- *
4
- * Provides consistent API setup across all extensions with shared authentication
5
- */
6
- /**
7
- * Creates an extension API instance with shared authentication storage
8
- *
9
- * @param APIClass - The generated API class from your extension
10
- * @returns Configured API instance with shared auth storage
11
- *
12
- * @example
13
- * ```typescript
14
- * // In your extension's api/index.ts
15
- * import { API } from './generated/ext_newsletter';
16
- * import { createExtensionAPI } from '@djangocfg/ext-base/api';
17
- *
18
- * export const apiNewsletter = createExtensionAPI(API);
19
- * ```
20
- */
21
- declare function createExtensionAPI<T>(APIClass: new (url: string, options?: any) => T): T;
22
- /**
23
- * Get shared authentication storage from accounts API
24
- *
25
- * @returns Storage instance or undefined if not available
26
- *
27
- * @example
28
- * ```typescript
29
- * const storage = getSharedAuthStorage();
30
- * const api = new API(apiUrl, { storage });
31
- * ```
32
- */
33
- declare function getSharedAuthStorage(): any | undefined;
34
-
35
- export { createExtensionAPI, getSharedAuthStorage };
package/dist/api.d.ts DELETED
@@ -1,35 +0,0 @@
1
- /**
2
- * Factory for creating extension API instances
3
- *
4
- * Provides consistent API setup across all extensions with shared authentication
5
- */
6
- /**
7
- * Creates an extension API instance with shared authentication storage
8
- *
9
- * @param APIClass - The generated API class from your extension
10
- * @returns Configured API instance with shared auth storage
11
- *
12
- * @example
13
- * ```typescript
14
- * // In your extension's api/index.ts
15
- * import { API } from './generated/ext_newsletter';
16
- * import { createExtensionAPI } from '@djangocfg/ext-base/api';
17
- *
18
- * export const apiNewsletter = createExtensionAPI(API);
19
- * ```
20
- */
21
- declare function createExtensionAPI<T>(APIClass: new (url: string, options?: any) => T): T;
22
- /**
23
- * Get shared authentication storage from accounts API
24
- *
25
- * @returns Storage instance or undefined if not available
26
- *
27
- * @example
28
- * ```typescript
29
- * const storage = getSharedAuthStorage();
30
- * const api = new API(apiUrl, { storage });
31
- * ```
32
- */
33
- declare function getSharedAuthStorage(): any | undefined;
34
-
35
- export { createExtensionAPI, getSharedAuthStorage };
package/dist/api.js DELETED
@@ -1,2 +0,0 @@
1
- export { createExtensionAPI, getSharedAuthStorage } from './chunk-MECBWZG4.js';
2
- import './chunk-3RG5ZIWI.js';
package/dist/auth.cjs DELETED
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- var auth = require('@djangocfg/api/auth');
4
-
5
-
6
-
7
- Object.defineProperty(exports, "useAuth", {
8
- enumerable: true,
9
- get: function () { return auth.useAuth; }
10
- });
package/dist/auth.d.cts DELETED
@@ -1 +0,0 @@
1
- export { AuthContextType, UserProfile, useAuth } from '@djangocfg/api/auth';
package/dist/auth.d.ts DELETED
@@ -1 +0,0 @@
1
- export { AuthContextType, UserProfile, useAuth } from '@djangocfg/api/auth';
package/dist/auth.js DELETED
@@ -1,2 +0,0 @@
1
- import './chunk-3RG5ZIWI.js';
2
- export { useAuth } from '@djangocfg/api/auth';
@@ -1,8 +0,0 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error('Dynamic require of "' + x + '" is not supported');
6
- });
7
-
8
- export { __require };
@@ -1,44 +0,0 @@
1
- import { __require } from './chunk-3RG5ZIWI.js';
2
-
3
- // src/config/env.ts
4
- var isDevelopment = process.env.NODE_ENV === "development";
5
- var isProduction = process.env.NODE_ENV === "production";
6
- var isTest = process.env.NODE_ENV === "test";
7
- var isStaticBuild = process.env.NEXT_PUBLIC_STATIC_BUILD === "true";
8
- var isClient = typeof window !== "undefined";
9
- var isServer = !isClient;
10
- var getApiUrl = () => {
11
- return process.env.NEXT_PUBLIC_API_URL || "";
12
- };
13
- var env = {
14
- isDevelopment,
15
- isProduction,
16
- isTest,
17
- isStaticBuild,
18
- isClient,
19
- isServer,
20
- getApiUrl
21
- };
22
-
23
- // src/api/createExtensionAPI.ts
24
- function createExtensionAPI(APIClass) {
25
- let storage;
26
- try {
27
- const { api: accountsApi } = __require("@djangocfg/api");
28
- storage = accountsApi._storage;
29
- } catch (error) {
30
- storage = void 0;
31
- }
32
- const apiUrl = isStaticBuild ? "" : getApiUrl();
33
- return new APIClass(apiUrl, storage ? { storage } : void 0);
34
- }
35
- function getSharedAuthStorage() {
36
- try {
37
- const { api: accountsApi } = __require("@djangocfg/api");
38
- return accountsApi._storage;
39
- } catch (error) {
40
- return void 0;
41
- }
42
- }
43
-
44
- export { createExtensionAPI, env, getApiUrl, getSharedAuthStorage, isClient, isDevelopment, isProduction, isServer, isStaticBuild, isTest };
@@ -1,67 +0,0 @@
1
- import { createConsola } from 'consola';
2
-
3
- // src/utils/errors.ts
4
- function isExtensionError(error) {
5
- return typeof error === "object" && error !== null && "message" in error && "timestamp" in error;
6
- }
7
- function createExtensionError(error, code, details) {
8
- const message = error instanceof Error ? error.message : String(error);
9
- return {
10
- message,
11
- code,
12
- details,
13
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
14
- };
15
- }
16
- function formatErrorMessage(error) {
17
- if (isExtensionError(error)) {
18
- return error.code ? `[${error.code}] ${error.message}` : error.message;
19
- }
20
- if (error instanceof Error) {
21
- return error.message;
22
- }
23
- return String(error);
24
- }
25
- function handleExtensionError(error, logger, callback) {
26
- const extensionError = isExtensionError(error) ? error : createExtensionError(error);
27
- if (logger) {
28
- logger.error("Extension error:", extensionError);
29
- }
30
- if (callback) {
31
- callback(extensionError);
32
- }
33
- }
34
- var isDevelopment = process.env.NODE_ENV === "development";
35
- var LEVEL_MAP = {
36
- debug: 4,
37
- info: 3,
38
- warn: 2,
39
- error: 1
40
- };
41
- function createExtensionLogger(options) {
42
- const { tag, level = "info", enabled = true } = options;
43
- if (!enabled) {
44
- const noop = () => {
45
- };
46
- return {
47
- info: noop,
48
- warn: noop,
49
- error: noop,
50
- debug: noop,
51
- success: noop
52
- };
53
- }
54
- const logLevel = isDevelopment ? LEVEL_MAP[level] : LEVEL_MAP.error;
55
- const consola = createConsola({
56
- level: logLevel
57
- }).withTag(tag);
58
- return {
59
- info: (...args) => consola.info(...args),
60
- warn: (...args) => consola.warn(...args),
61
- error: (...args) => consola.error(...args),
62
- debug: (...args) => consola.debug(...args),
63
- success: (...args) => consola.success(...args)
64
- };
65
- }
66
-
67
- export { createExtensionError, createExtensionLogger, formatErrorMessage, handleExtensionError, isExtensionError };