@korioinc/next-conf 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Korio Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # @korioinc/next-conf
2
+
3
+ Configuration management system for Next.js applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @korioinc/next-conf
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - **Centralized Configuration**: Manage all app configurations in one place
14
+ - **Type-safe**: Full TypeScript support with autocompletion
15
+ - **Environment-aware**: Different configs for development/production
16
+ - **Plugin System**: Extensible plugin architecture
17
+ - **Next.js Optimized**: Built specifically for Next.js applications
18
+
19
+ ## Usage
20
+
21
+ ### Basic Setup
22
+
23
+ Create a `next-kit.config.ts` file in your project root:
24
+
25
+ ```typescript
26
+ import { defineConfig } from '@korioinc/next-conf';
27
+
28
+ export default defineConfig({
29
+ app: {
30
+ name: 'My App',
31
+ description: 'My awesome Next.js app',
32
+ },
33
+ api: {
34
+ baseUrl: process.env.NEXT_PUBLIC_API_URL || 'https://api.example.com',
35
+ timeout: 30000,
36
+ },
37
+ cookie: {
38
+ accessTokenName: '_at',
39
+ refreshTokenName: '_rt',
40
+ },
41
+ auth: {
42
+ redirectPath: '/dashboard',
43
+ loginPath: '/login',
44
+ },
45
+ });
46
+ ```
47
+
48
+ ### Using Configuration
49
+
50
+ ```typescript
51
+ import { getConfig } from '@korioinc/next-conf';
52
+
53
+ // In your components or API routes
54
+ const config = getConfig();
55
+ console.log(config.app.name); // "My App"
56
+ ```
57
+
58
+ ### Plugin System
59
+
60
+ ```typescript
61
+ import { defineConfig } from '@korioinc/next-conf';
62
+ import { myPlugin } from '@korioinc/next-conf/plugin';
63
+
64
+ export default defineConfig({
65
+ // Your config
66
+ }, {
67
+ plugins: [myPlugin()],
68
+ });
69
+ ```
70
+
71
+ ## Configuration Options
72
+
73
+ | Option | Type | Description |
74
+ |--------|------|-------------|
75
+ | `app.name` | `string` | Application name |
76
+ | `app.description` | `string` | Application description |
77
+ | `api.baseUrl` | `string` | API base URL |
78
+ | `api.timeout` | `number` | Request timeout in ms |
79
+ | `cookie.accessTokenName` | `string` | Access token cookie name |
80
+ | `cookie.refreshTokenName` | `string` | Refresh token cookie name |
81
+ | `auth.redirectPath` | `string` | Post-login redirect path |
82
+ | `auth.loginPath` | `string` | Login page path |
83
+
84
+ ## License
85
+
86
+ MIT
87
+
88
+ ## Contributing
89
+
90
+ Contributions are welcome! Please feel free to submit a Pull Request.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Default configuration export
3
+ * This file is used as a fallback when no user configuration exists
4
+ */
5
+ import type { NextCoreConfig } from '../types.js';
6
+ declare const config: NextCoreConfig;
7
+ export default config;
8
+ //# sourceMappingURL=config.default.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.default.d.ts","sourceRoot":"","sources":["../../src/core/config.default.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,QAAA,MAAM,MAAM,EAAE,cAAmB,CAAC;AAElC,eAAe,MAAM,CAAC"}
@@ -0,0 +1,2 @@
1
+ const config = {};
2
+ export default config;
@@ -0,0 +1,3 @@
1
+ import type { NextCoreConfig } from '../types.js';
2
+ export declare const defaultConfig: Required<NextCoreConfig>;
3
+ //# sourceMappingURL=defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/core/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,cAAc,CAwClD,CAAC"}
@@ -0,0 +1,37 @@
1
+ export const defaultConfig = {
2
+ // Analytics
3
+ analytics: {
4
+ gaId: undefined,
5
+ gtmId: undefined,
6
+ adsensePublisherId: undefined,
7
+ },
8
+ // API Configuration
9
+ api: {
10
+ baseUrl: 'http://localhost',
11
+ timeout: 10000, // 10 seconds
12
+ headers: {},
13
+ },
14
+ // Cookie Configuration
15
+ cookie: {
16
+ accessTokenName: '_at',
17
+ domain: undefined,
18
+ maxAge: 3 * 24 * 60 * 60, // 3 days in seconds
19
+ },
20
+ // Auth Routing Configuration
21
+ auth: {
22
+ // 로그인한 사용자가 접근할 수 없는 경로들 (로그인 상태에서 homeUrl로 리다이렉트)
23
+ restrictedPaths: ['/accounts/login', '/accounts/register', /^\/accounts\/login\/oauth\/[^/]+$/],
24
+ // 로그인이 필요한 보호된 경로들 (비로그인 상태에서 loginUrl로 리다이렉트)
25
+ requiredPaths: ['/accounts/profile', '/accounts/settings'],
26
+ // 로그인이 필요할 때 리다이렉트할 경로
27
+ loginUrl: '/accounts/login',
28
+ // 이미 로그인한 사용자가 제한된 경로 접근 시 리다이렉트할 경로
29
+ homeUrl: '/',
30
+ },
31
+ // Storage Configuration
32
+ storage: {
33
+ name: 'app-storage',
34
+ storeName: 'default-store',
35
+ driver: undefined, // Will use localforage default priority
36
+ },
37
+ };
@@ -0,0 +1,9 @@
1
+ import type { NextCoreConfig } from '../types.js';
2
+ /**
3
+ * Get the merged configuration
4
+ * This function merges user configuration with defaults
5
+ *
6
+ * @returns Configuration with all required properties
7
+ */
8
+ export declare function getConfig(): NextCoreConfig;
9
+ //# sourceMappingURL=get-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-config.d.ts","sourceRoot":"","sources":["../../src/core/get-config.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAqBlD;;;;;GAKG;AACH,wBAAgB,SAAS,IAAI,cAAc,CAQ1C"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Configuration loader using static imports
3
+ * Clean implementation without @ts-ignore
4
+ */
5
+ // Import user configuration via a stable specifier that our plugin aliases
6
+ // This avoids relying on relative aliasing which can break under Turbopack
7
+ import userConfig from '@korioinc/next-conf/src/core/config.default';
8
+ import { defaultConfig } from './defaults.js';
9
+ // Merge helper that ignores empty-string overrides
10
+ function mergeIgnoringEmptyStrings(defaults, overrides) {
11
+ if (!overrides)
12
+ return { ...defaults };
13
+ const result = { ...defaults };
14
+ for (const [key, value] of Object.entries(overrides)) {
15
+ if (value === undefined || value === null)
16
+ continue;
17
+ if (typeof value === 'string' && value.trim() === '')
18
+ continue;
19
+ result[key] = value;
20
+ }
21
+ return result;
22
+ }
23
+ /**
24
+ * Get the merged configuration
25
+ * This function merges user configuration with defaults
26
+ *
27
+ * @returns Configuration with all required properties
28
+ */
29
+ export function getConfig() {
30
+ return {
31
+ analytics: mergeIgnoringEmptyStrings(defaultConfig.analytics ?? {}, userConfig?.analytics),
32
+ api: mergeIgnoringEmptyStrings(defaultConfig.api ?? {}, userConfig?.api),
33
+ cookie: mergeIgnoringEmptyStrings(defaultConfig.cookie ?? {}, userConfig?.cookie),
34
+ auth: mergeIgnoringEmptyStrings(defaultConfig.auth ?? {}, userConfig?.auth),
35
+ storage: mergeIgnoringEmptyStrings(defaultConfig.storage ?? {}, userConfig?.storage),
36
+ };
37
+ }
@@ -0,0 +1,2 @@
1
+ export { getConfig } from './get-config.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1 @@
1
+ export { getConfig } from './get-config.js';
@@ -0,0 +1,3 @@
1
+ export { getConfig } from './core/get-config.js';
2
+ export * from './types.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,cAAc,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ // Core configuration functions
2
+ export { getConfig } from './core/get-config.js';
3
+ // Type definitions
4
+ export * from './types.js';
@@ -0,0 +1,3 @@
1
+ export { withNextKitConf } from './with-config.js';
2
+ export type { WithConfigOptions } from './with-config.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1 @@
1
+ export { withNextKitConf } from './with-config.js';
@@ -0,0 +1,24 @@
1
+ import type { NextConfig } from 'next';
2
+ export interface WithConfigOptions {
3
+ configFileName?: string;
4
+ }
5
+ /**
6
+ * Next.js configuration plugin that injects webpack aliases
7
+ * Maps the default config to the actual user config file
8
+ *
9
+ * @param nextConfig - The existing Next.js configuration
10
+ * @param options - Plugin options
11
+ * @returns Enhanced Next.js configuration with alias injection
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // next.config.ts
16
+ * import { withNextKitConf } from '@korioinc/next-conf/plugin';
17
+ *
18
+ * export default withNextKitConf({
19
+ * // your existing config
20
+ * });
21
+ * ```
22
+ */
23
+ export declare function withNextKitConf(nextConfig?: NextConfig, options?: WithConfigOptions): NextConfig;
24
+ //# sourceMappingURL=with-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-config.d.ts","sourceRoot":"","sources":["../../src/plugin/with-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AA2BvC,MAAM,WAAW,iBAAiB;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,UAAU,GAAE,UAAe,EAAE,OAAO,GAAE,iBAAsB,GAAG,UAAU,CAwDxG"}
@@ -0,0 +1,64 @@
1
+ import * as path from 'path';
2
+ /**
3
+ * Next.js configuration plugin that injects webpack aliases
4
+ * Maps the default config to the actual user config file
5
+ *
6
+ * @param nextConfig - The existing Next.js configuration
7
+ * @param options - Plugin options
8
+ * @returns Enhanced Next.js configuration with alias injection
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // next.config.ts
13
+ * import { withNextKitConf } from '@korioinc/next-conf/plugin';
14
+ *
15
+ * export default withNextKitConf({
16
+ * // your existing config
17
+ * });
18
+ * ```
19
+ */
20
+ export function withNextKitConf(nextConfig = {}, options = {}) {
21
+ const { configFileName = 'next-kit.config.ts' } = options;
22
+ return {
23
+ ...nextConfig,
24
+ // Turbopack configuration for development
25
+ turbopack: {
26
+ ...nextConfig.turbopack,
27
+ resolveAlias: {
28
+ ...nextConfig.turbopack?.resolveAlias,
29
+ // Map config.default to the user config using a project-relative specifier
30
+ // Turbopack prefers specifiers (./foo.ts) over absolute file paths
31
+ '@korioinc/next-conf/dist/core/config.default.js': configFileName.startsWith('.') || configFileName.startsWith('/') ? configFileName : `./${configFileName}`,
32
+ '@korioinc/next-conf/src/core/config.default.ts': configFileName.startsWith('.') || configFileName.startsWith('/') ? configFileName : `./${configFileName}`,
33
+ '@korioinc/next-conf/src/core/config.default': configFileName.startsWith('.') || configFileName.startsWith('/') ? configFileName : `./${configFileName}`,
34
+ },
35
+ },
36
+ // Webpack configuration for production builds
37
+ webpack: (config, options) => {
38
+ // Initialize resolve.alias if it doesn't exist
39
+ config.resolve = config.resolve || {};
40
+ config.resolve.alias = config.resolve.alias || {};
41
+ // Map the default config to the actual user config file
42
+ // This allows clean static imports without any @ts-ignore
43
+ const cwd = options?.dir || process.cwd();
44
+ const userConfigPath = path.resolve(cwd, configFileName);
45
+ // Map package paths used by this package
46
+ const newConfigPaths = [
47
+ '@korioinc/next-conf/dist/core/config.default',
48
+ '@korioinc/next-conf/src/core/config.default',
49
+ path.resolve(cwd, 'node_modules/@korioinc/next-conf/dist/core/config.default'),
50
+ ];
51
+ const allPaths = [...newConfigPaths];
52
+ allPaths.forEach((defaultPath) => {
53
+ if (config.resolve?.alias) {
54
+ config.resolve.alias[defaultPath] = userConfigPath;
55
+ }
56
+ });
57
+ // Call the original webpack function if it exists
58
+ if (typeof nextConfig.webpack === 'function') {
59
+ return nextConfig.webpack(config, options);
60
+ }
61
+ return config;
62
+ },
63
+ };
64
+ }
@@ -0,0 +1,29 @@
1
+ export interface NextCoreConfig {
2
+ analytics?: {
3
+ gaId?: string;
4
+ gtmId?: string;
5
+ adsensePublisherId?: string;
6
+ };
7
+ api?: {
8
+ baseUrl?: string;
9
+ timeout?: number;
10
+ headers?: Record<string, string>;
11
+ };
12
+ cookie?: {
13
+ accessTokenName?: string;
14
+ domain?: string;
15
+ maxAge?: number;
16
+ };
17
+ auth?: {
18
+ restrictedPaths?: (string | RegExp)[];
19
+ requiredPaths?: (string | RegExp)[];
20
+ loginUrl?: string;
21
+ homeUrl?: string;
22
+ };
23
+ storage?: {
24
+ name?: string;
25
+ storeName?: string;
26
+ driver?: string | string[];
27
+ };
28
+ }
29
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAE7B,SAAS,CAAC,EAAE;QACV,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,kBAAkB,CAAC,EAAE,MAAM,CAAC;KAC7B,CAAC;IAGF,GAAG,CAAC,EAAE;QACJ,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAClC,CAAC;IAGF,MAAM,CAAC,EAAE;QACP,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IAGF,IAAI,CAAC,EAAE;QAEL,eAAe,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;QAEtC,aAAa,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;QAEpC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAElB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IAGF,OAAO,CAAC,EAAE;QAER,IAAI,CAAC,EAAE,MAAM,CAAC;QAEd,SAAS,CAAC,EAAE,MAAM,CAAC;QAEnB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;KAC5B,CAAC;CACH"}
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@korioinc/next-conf",
3
+ "version": "1.0.0",
4
+ "description": "Configuration management for Next.js applications",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./plugin": {
16
+ "types": "./dist/plugin/index.d.ts",
17
+ "import": "./dist/plugin/index.js",
18
+ "default": "./dist/plugin/index.js"
19
+ },
20
+ "./types": {
21
+ "types": "./dist/types.d.ts"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "README.md",
27
+ "LICENSE"
28
+ ],
29
+ "scripts": {
30
+ "build": "tsc -p tsconfig.json",
31
+ "dev": "tsc -p tsconfig.json -w",
32
+ "test": "vitest",
33
+ "lint": "eslint . --max-warnings 0",
34
+ "typecheck": "tsc --noEmit"
35
+ },
36
+ "peerDependencies": {
37
+ "next": ">=15"
38
+ },
39
+ "peerDependenciesMeta": {
40
+ "next": {
41
+ "optional": true
42
+ }
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "^22.18.1",
46
+ "typescript": "^5.9.2",
47
+ "vitest": "^2.0.0"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public",
51
+ "registry": "https://registry.npmjs.org/"
52
+ },
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "git+https://github.com/korioinc/korio-nextjs-kit.git",
56
+ "directory": "packages/conf"
57
+ },
58
+ "author": "Korio Inc.",
59
+ "license": "MIT"
60
+ }