@econneq/auth-cli 1.0.1

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/dist/bin.mjs ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ run
4
+ } from "./chunk-2DIZS5TH.mjs";
5
+
6
+ // src/bin.ts
7
+ run();
@@ -0,0 +1,225 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/commands/init.ts
4
+ import prompts from "prompts";
5
+ import chalk from "chalk";
6
+ import ora from "ora";
7
+ import fs from "fs-extra";
8
+ import path from "path";
9
+
10
+ // src/templates/auth.config.template.ts
11
+ function generateAuthConfig(a) {
12
+ const methods = a.authMethods.map((m) => `'${m}'`).join(", ");
13
+ return `import { defineAuthConfig } from '@econneq/auth-react'
14
+
15
+ export const authConfig = defineAuthConfig({
16
+ appName: '${a.appName}',
17
+ apiBaseUrl: process.env.NEXT_PUBLIC_AUTH_API_URL ?? '${a.apiBaseUrl}',
18
+ tenantMode: ${a.tenantMode},
19
+
20
+ routing: {
21
+ strategy: 'subdomain',
22
+ },
23
+
24
+ auth: {
25
+ methods: [${methods}],
26
+ mfa: false,
27
+ rememberSession: true,
28
+ },
29
+
30
+ storage: {
31
+ strategy: '${a.storage}',
32
+ },
33
+
34
+ tokens: {
35
+ autoRefresh: true,
36
+ accessTokenExpiry: 900,
37
+ refreshTokenExpiry: 604800,
38
+ },
39
+
40
+ security: {
41
+ csrf: true,
42
+ sameSite: 'lax',
43
+ rotateRefreshTokens: true,
44
+ },
45
+
46
+ ui: {
47
+ hostedPages: true,
48
+ darkMode: false,
49
+ },
50
+ })
51
+ `;
52
+ }
53
+
54
+ // src/templates/provider.template.ts
55
+ function generateProviderFile(a) {
56
+ const pkg = a.framework === "nextjs" ? "@econneq/auth-react" : "@econneq/auth-react";
57
+ return `'use client'
58
+ import { AuthProvider } from '${pkg}'
59
+ import { authConfig } from './auth.config'
60
+ import type { ReactNode } from 'react'
61
+
62
+ export function AppAuthProvider({ children }: { children: ReactNode }) {
63
+ return (
64
+ <AuthProvider config={authConfig}>
65
+ {children}
66
+ </AuthProvider>
67
+ )
68
+ }
69
+ `;
70
+ }
71
+
72
+ // src/templates/proxy.template.ts
73
+ function generateProxyFile(_a) {
74
+ return `/**
75
+ * proxy.ts \u2014 Econneq Auth Middleware
76
+ * Generated by: npx econneq-auth init
77
+ */
78
+ import { createAuthMiddleware } from '@econneq/auth-react/middleware'
79
+ import { authConfig } from './src/auth/auth.config'
80
+
81
+ export default createAuthMiddleware(authConfig, {
82
+ protectedRoutes: ['/dashboard', '/app', '/admin'],
83
+ publicRoutes: ['/auth/login', '/auth/register', '/auth/select-tenant'],
84
+ loginUrl: '/auth/login',
85
+ tenantSelectUrl: '/auth/select-tenant',
86
+ })
87
+
88
+ export const config = {
89
+ matcher: ['/((?!_next/static|_next/image|favicon\\.ico|.*\\.[a-zA-Z]{2,5}$).*)'],
90
+ }
91
+ `;
92
+ }
93
+
94
+ // src/templates/env.template.ts
95
+ function generateEnvFile(a) {
96
+ return `# @econneq-auth \u2014 generated by npx econneq-auth init
97
+ NEXT_PUBLIC_AUTH_API_URL=${a.apiBaseUrl}
98
+ NEXT_PUBLIC_ROOT_DOMAIN=yourdomain.com
99
+
100
+ # Optional: set these server-side only (not NEXT_PUBLIC_)
101
+ # AUTH_SECRET=your-jwt-secret
102
+ # AUTH_CSRF_SECRET=your-csrf-secret
103
+ `;
104
+ }
105
+
106
+ // src/commands/init.ts
107
+ async function initCommand() {
108
+ console.log("\n" + chalk.bold.cyan("\u{1F510} @econneq-auth init") + "\n");
109
+ const answers = await prompts([
110
+ {
111
+ type: "text",
112
+ name: "appName",
113
+ message: "Application name?",
114
+ initial: "My Enterprise App"
115
+ },
116
+ {
117
+ type: "text",
118
+ name: "apiBaseUrl",
119
+ message: "Auth API base URL?",
120
+ initial: "https://api.yourdomain.com"
121
+ },
122
+ {
123
+ type: "confirm",
124
+ name: "tenantMode",
125
+ message: "Enable multi-tenant mode?",
126
+ initial: true
127
+ },
128
+ {
129
+ type: "select",
130
+ name: "framework",
131
+ message: "Framework?",
132
+ choices: [
133
+ { title: "Next.js (App Router)", value: "nextjs" },
134
+ { title: "React (Vite/CRA)", value: "react" }
135
+ ]
136
+ },
137
+ {
138
+ type: "select",
139
+ name: "storage",
140
+ message: "Token storage strategy?",
141
+ choices: [
142
+ { title: "Cookies (recommended for SSR)", value: "cookies" },
143
+ { title: "localStorage", value: "localStorage" },
144
+ { title: "Memory", value: "memory" }
145
+ ]
146
+ },
147
+ {
148
+ type: "multiselect",
149
+ name: "authMethods",
150
+ message: "Auth methods to enable?",
151
+ choices: [
152
+ { title: "Password", value: "password", selected: true },
153
+ { title: "OTP", value: "otp", selected: false },
154
+ { title: "Google", value: "google", selected: false },
155
+ { title: "Magic Link", value: "magic-link", selected: false }
156
+ ]
157
+ }
158
+ ]);
159
+ if (!answers.appName) {
160
+ console.log(chalk.red("\nAborted."));
161
+ process.exit(1);
162
+ }
163
+ const spinner = ora("Generating auth files\u2026").start();
164
+ try {
165
+ const srcDir = path.join(process.cwd(), "src");
166
+ await fs.outputFile(
167
+ path.join(srcDir, "auth", "auth.config.ts"),
168
+ generateAuthConfig(answers)
169
+ );
170
+ await fs.outputFile(
171
+ path.join(srcDir, "auth", "provider.tsx"),
172
+ generateProviderFile(answers)
173
+ );
174
+ if (answers.framework === "nextjs") {
175
+ await fs.outputFile(
176
+ path.join(process.cwd(), "proxy.ts"),
177
+ generateProxyFile(answers)
178
+ );
179
+ }
180
+ await fs.outputFile(
181
+ path.join(process.cwd(), ".env.local"),
182
+ generateEnvFile(answers)
183
+ );
184
+ spinner.succeed("Auth files generated!");
185
+ console.log("\n" + chalk.bold("Files created:"));
186
+ console.log(" " + chalk.green("src/auth/auth.config.ts"));
187
+ console.log(" " + chalk.green("src/auth/provider.tsx"));
188
+ if (answers.framework === "nextjs") {
189
+ console.log(" " + chalk.green("proxy.ts"));
190
+ }
191
+ console.log(" " + chalk.green(".env.local"));
192
+ console.log("\n" + chalk.bold("Next steps:"));
193
+ if (answers.framework === "nextjs") {
194
+ console.log(` 1. npm install @econneq/auth-react @econneq/auth-ui`);
195
+ console.log(` 2. Wrap your root layout with <AuthProvider config={authConfig}>`);
196
+ console.log(` 3. Ensure proxy.ts is at your project root`);
197
+ } else {
198
+ console.log(` 1. npm install @econneq/auth-react @econneq/auth-ui`);
199
+ console.log(` 2. Wrap your App with <AuthProvider config={authConfig}>`);
200
+ }
201
+ console.log(` 4. Set your API URL in .env.local`);
202
+ console.log("\n" + chalk.cyan("Docs: https://github.com/econneq/econneq-auth") + "\n");
203
+ } catch (err) {
204
+ spinner.fail("Generation failed");
205
+ console.error(err);
206
+ process.exit(1);
207
+ }
208
+ }
209
+
210
+ // src/index.ts
211
+ async function run() {
212
+ const [, , cmd = "init"] = process.argv;
213
+ switch (cmd) {
214
+ case "init":
215
+ await initCommand();
216
+ break;
217
+ default:
218
+ console.log("Unknown command. Available: init");
219
+ process.exit(1);
220
+ }
221
+ }
222
+
223
+ export {
224
+ run
225
+ };
package/dist/index.mjs ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ run
4
+ } from "./chunk-2DIZS5TH.mjs";
5
+ export {
6
+ run
7
+ };
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@econneq/auth-cli",
3
+ "version": "1.0.1",
4
+ "description": "CLI — npx econneq-auth init",
5
+ "author": "Econneq",
6
+ "license": "MIT",
7
+ "bin": {
8
+ "econneq-auth": "./dist/bin.js"
9
+ },
10
+ "main": "./dist/index.js",
11
+ "files": [
12
+ "dist",
13
+ "README.md"
14
+ ],
15
+ "dependencies": {
16
+ "prompts": "^2.4.2",
17
+ "chalk": "^5.3.0",
18
+ "ora": "^8.0.1",
19
+ "fs-extra": "^11.2.0"
20
+ },
21
+ "devDependencies": {
22
+ "@types/prompts": "^2.4.9",
23
+ "@types/fs-extra": "^11.0.4",
24
+ "tsup": "^8.5.1",
25
+ "typescript": "^5.4.0",
26
+ "rimraf": "^5.0.0"
27
+ },
28
+ "scripts": {
29
+ "build": "tsup",
30
+ "dev": "tsup --watch",
31
+ "typecheck": "tsc --noEmit",
32
+ "clean": "rimraf dist"
33
+ }
34
+ }