ar-saas 0.1.0 → 0.2.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/LICENSE +21 -0
- package/README.md +201 -31
- package/dist/cli.js +3 -12
- package/dist/generator.js +6 -17
- package/dist/index.js +2 -1
- package/package.json +1 -1
- package/dist/license.js +0 -71
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ignacio Becher
|
|
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
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
# ar-saas
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<strong>Generador de proyectos SaaS multi-tenant para startups argentinas</strong><br/>
|
|
5
|
+
Backend NestJS + Frontend Next.js listos para producción en minutos.
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://www.npmjs.com/package/ar-saas"><img src="https://img.shields.io/npm/v/ar-saas.svg" alt="npm version" /></a>
|
|
10
|
+
<a href="https://www.npmjs.com/package/ar-saas"><img src="https://img.shields.io/npm/dm/ar-saas.svg" alt="npm downloads" /></a>
|
|
11
|
+
<a href="https://github.com/ignaciobecher/ar-saas/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="license" /></a>
|
|
12
|
+
<img src="https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen" alt="node version" />
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
---
|
|
4
16
|
|
|
5
17
|
## Quickstart
|
|
6
18
|
|
|
@@ -8,55 +20,213 @@ Generador de proyectos SaaS multi-tenant para startups argentinas.
|
|
|
8
20
|
npx ar-saas mi-proyecto
|
|
9
21
|
```
|
|
10
22
|
|
|
11
|
-
|
|
23
|
+
Respondés 4 preguntas y en minutos tenés un proyecto completo corriendo localmente.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## ¿Qué genera?
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
mi-proyecto/
|
|
31
|
+
├── backend/ # NestJS 11 + MongoDB
|
|
32
|
+
│ ├── src/
|
|
33
|
+
│ │ ├── modules/
|
|
34
|
+
│ │ │ ├── auth/ # Auth completo (JWT en cookies HttpOnly)
|
|
35
|
+
│ │ │ ├── users/ # Usuarios con roles
|
|
36
|
+
│ │ │ ├── workspaces/ # Multi-tenancy por workspace
|
|
37
|
+
│ │ │ └── mail/ # Emails transaccionales con Resend
|
|
38
|
+
│ │ └── common/ # Guards, filtros, decoradores, base repository
|
|
39
|
+
│ ├── .env.example
|
|
40
|
+
│ └── package.json
|
|
41
|
+
├── frontend/ # Next.js 15 + Tailwind CSS 4 + shadcn/ui
|
|
42
|
+
│ ├── src/
|
|
43
|
+
│ │ ├── app/
|
|
44
|
+
│ │ │ ├── (auth)/ # Login, register, verify email, reset password
|
|
45
|
+
│ │ │ ├── (dashboard)/ # Rutas protegidas con layout
|
|
46
|
+
│ │ │ └── setup/ # Pantalla de onboarding al abrir por primera vez
|
|
47
|
+
│ │ ├── providers/ # AuthProvider con estado global
|
|
48
|
+
│ │ └── lib/api/ # Cliente axios con refresh automático
|
|
49
|
+
│ └── package.json
|
|
50
|
+
└── railway.toml / fly.toml / docker-compose.yml
|
|
51
|
+
```
|
|
12
52
|
|
|
13
|
-
|
|
53
|
+
---
|
|
14
54
|
|
|
15
|
-
|
|
55
|
+
## Stack
|
|
16
56
|
|
|
17
|
-
|
|
57
|
+
### Backend
|
|
58
|
+
| Tecnología | Versión | Uso |
|
|
59
|
+
|---|---|---|
|
|
60
|
+
| NestJS | 11 | Framework principal |
|
|
61
|
+
| MongoDB + Mongoose | 9 | Base de datos |
|
|
62
|
+
| JWT (passport) | — | Autenticación en cookies HttpOnly |
|
|
63
|
+
| Resend | — | Emails transaccionales |
|
|
64
|
+
| Swagger | — | Documentación automática en `/api/docs` |
|
|
18
65
|
|
|
19
|
-
|
|
66
|
+
### Frontend
|
|
67
|
+
| Tecnología | Versión | Uso |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| Next.js | 15 | App Router, Server Components |
|
|
70
|
+
| Tailwind CSS | 4 | Estilos |
|
|
71
|
+
| shadcn/ui | — | Componentes UI |
|
|
72
|
+
| react-hook-form | — | Formularios |
|
|
73
|
+
| axios | — | HTTP client con interceptor de refresh |
|
|
20
74
|
|
|
21
|
-
|
|
22
|
-
- Multi-tenancy con aislamiento estricto por `workspaceId`
|
|
23
|
-
- Mail transaccional con Resend (verificación, bienvenida, reset)
|
|
75
|
+
---
|
|
24
76
|
|
|
25
|
-
## Módulos
|
|
77
|
+
## Módulos incluidos
|
|
78
|
+
|
|
79
|
+
### Free (siempre incluidos)
|
|
80
|
+
|
|
81
|
+
| Módulo | Descripción |
|
|
82
|
+
|---|---|
|
|
83
|
+
| **Auth completo** | Registro, login, verificación de email, reset de password |
|
|
84
|
+
| **Multi-tenancy** | Aislamiento estricto por `workspaceId` en todas las queries |
|
|
85
|
+
| **Mail transaccional** | Verificación, bienvenida y reset con Resend. Fail-open si Resend falla |
|
|
86
|
+
|
|
87
|
+
### Opcionales
|
|
26
88
|
|
|
27
89
|
| Módulo | Descripción |
|
|
28
90
|
|---|---|
|
|
29
|
-
| OAuth + 2FA | Login con GitHub/Google + autenticación de dos factores |
|
|
30
|
-
| Notificaciones | Notificaciones in-app + Push Web (VAPID) |
|
|
31
|
-
| Invoices + Quotes | Facturación con generación de PDF |
|
|
32
|
-
| CRM | Kanban + Pipeline de ventas |
|
|
33
|
-
| MercadoPago | Suscripciones recurrentes con webhooks |
|
|
91
|
+
| **OAuth + 2FA** | Login con GitHub/Google + autenticación de dos factores TOTP |
|
|
92
|
+
| **Notificaciones** | Notificaciones in-app + Push Web (VAPID) |
|
|
93
|
+
| **Invoices + Quotes** | Facturación con generación de PDF |
|
|
94
|
+
| **CRM** | Kanban + Pipeline de ventas |
|
|
95
|
+
| **MercadoPago** | Suscripciones recurrentes con webhooks |
|
|
34
96
|
|
|
35
|
-
|
|
97
|
+
---
|
|
36
98
|
|
|
37
|
-
|
|
99
|
+
## Configuración
|
|
38
100
|
|
|
39
|
-
|
|
40
|
-
- **Fly.io** — `fly.toml` con región `gru` (São Paulo)
|
|
41
|
-
- **Docker** — `docker-compose.yml` con MongoDB incluido
|
|
101
|
+
Al ejecutar el CLI se copian automáticamente los archivos `.env.example` → `.env`.
|
|
42
102
|
|
|
43
|
-
|
|
103
|
+
### Backend — variables requeridas
|
|
44
104
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
105
|
+
| Variable | Descripción |
|
|
106
|
+
|---|---|
|
|
107
|
+
| `MONGODB_URI` | URI de conexión a MongoDB |
|
|
108
|
+
| `JWT_ACCESS_SECRET` | Secreto para access tokens (`openssl rand -hex 64`) |
|
|
109
|
+
| `JWT_REFRESH_SECRET` | Secreto para refresh tokens (distinto al anterior) |
|
|
110
|
+
| `RESEND_API_KEY` | API Key de [Resend](https://resend.com) |
|
|
111
|
+
| `RESEND_FROM_EMAIL` | Email remitente verificado en Resend |
|
|
112
|
+
| `APP_URL` | URL del frontend (para links en emails) |
|
|
113
|
+
| `CORS_ORIGINS` | URL del frontend separada por comas |
|
|
114
|
+
|
|
115
|
+
### Frontend — variables requeridas
|
|
116
|
+
|
|
117
|
+
| Variable | Descripción |
|
|
118
|
+
|---|---|
|
|
119
|
+
| `NEXT_PUBLIC_API_URL` | URL base del backend (ej: `http://localhost:3000`) |
|
|
48
120
|
|
|
49
|
-
|
|
121
|
+
---
|
|
50
122
|
|
|
51
|
-
|
|
123
|
+
## Deploy
|
|
52
124
|
|
|
125
|
+
El CLI genera la configuración según el entorno elegido:
|
|
126
|
+
|
|
127
|
+
### Railway
|
|
128
|
+
```toml
|
|
129
|
+
# railway.toml generado automáticamente
|
|
130
|
+
[build]
|
|
131
|
+
builder = "nixpacks"
|
|
132
|
+
|
|
133
|
+
[deploy]
|
|
134
|
+
startCommand = "npm run start:prod"
|
|
135
|
+
healthcheckPath = "/api/health"
|
|
53
136
|
```
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
137
|
+
|
|
138
|
+
### Fly.io
|
|
139
|
+
```toml
|
|
140
|
+
# fly.toml generado automáticamente
|
|
141
|
+
app = "mi-proyecto"
|
|
142
|
+
primary_region = "gru" # São Paulo
|
|
58
143
|
```
|
|
59
144
|
|
|
145
|
+
### Docker
|
|
146
|
+
```yaml
|
|
147
|
+
# docker-compose.yml generado automáticamente
|
|
148
|
+
# Incluye backend + frontend + MongoDB
|
|
149
|
+
docker compose up
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Iniciar el proyecto generado
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
# Backend
|
|
158
|
+
cd mi-proyecto/backend
|
|
159
|
+
npm install
|
|
160
|
+
npm run start:dev
|
|
161
|
+
# → http://localhost:3000
|
|
162
|
+
# → Swagger: http://localhost:3000/api/docs
|
|
163
|
+
|
|
164
|
+
# Frontend (en otra terminal)
|
|
165
|
+
cd mi-proyecto/frontend
|
|
166
|
+
npm install
|
|
167
|
+
npm run dev
|
|
168
|
+
# → http://localhost:3001
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
La primera vez que abrís el frontend aparece una pantalla de onboarding que guía la configuración completa.
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Flujos de autenticación implementados
|
|
176
|
+
|
|
177
|
+
- `POST /api/auth/register` — Registro con email de verificación
|
|
178
|
+
- `GET /api/auth/verify-email?token=` — Verificación de email
|
|
179
|
+
- `POST /api/auth/login` — Login (setea cookies HttpOnly)
|
|
180
|
+
- `POST /api/auth/refresh` — Refresh automático del access token
|
|
181
|
+
- `POST /api/auth/logout` — Logout (limpia cookies)
|
|
182
|
+
- `POST /api/auth/forgot-password` — Solicitud de reset
|
|
183
|
+
- `POST /api/auth/reset-password` — Reset de contraseña
|
|
184
|
+
- `GET /api/auth/me` — Datos del usuario autenticado
|
|
185
|
+
|
|
186
|
+
Los tokens JWT viajan **únicamente en cookies HttpOnly**. Nunca en `localStorage` ni en el body de las respuestas.
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Requisitos
|
|
191
|
+
|
|
192
|
+
- **Node.js** 18+
|
|
193
|
+
- **MongoDB** local o [Atlas](https://www.mongodb.com/atlas) (free tier disponible)
|
|
194
|
+
- Cuenta en [Resend](https://resend.com) para emails (free tier: 100 emails/día)
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
60
198
|
## Licencia
|
|
61
199
|
|
|
62
|
-
MIT
|
|
200
|
+
MIT © 2026 [Ignacio Becher](https://github.com/ignaciobecher)
|
|
201
|
+
|
|
202
|
+
El código generado por esta herramienta es completamente tuyo, sin restricciones de uso comercial. Podés usarlo, modificarlo y distribuirlo libremente.
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## Legal
|
|
207
|
+
|
|
208
|
+
**Propiedad del código generado**
|
|
209
|
+
|
|
210
|
+
Todo el código que `ar-saas` genera en tu proyecto te pertenece a vos. No reclamamos ningún derecho sobre el código generado ni sobre los productos que construyas con él.
|
|
211
|
+
|
|
212
|
+
**Sin garantías**
|
|
213
|
+
|
|
214
|
+
Esta herramienta se provee "tal cual" (*as is*), sin garantías de ningún tipo. No nos hacemos responsables por:
|
|
215
|
+
|
|
216
|
+
- Vulnerabilidades de seguridad en el código generado si modificás la configuración por defecto
|
|
217
|
+
- Daños directos o indirectos derivados del uso del software
|
|
218
|
+
- Pérdida de datos o interrupciones de servicio en proyectos construidos con esta herramienta
|
|
219
|
+
|
|
220
|
+
**Dependencias de terceros**
|
|
221
|
+
|
|
222
|
+
El código generado incluye dependencias de terceros (NestJS, Next.js, MongoDB, etc.), cada una con su propia licencia. Es tu responsabilidad revisar y cumplir con los términos de cada dependencia en tu proyecto.
|
|
223
|
+
|
|
224
|
+
**Seguridad**
|
|
225
|
+
|
|
226
|
+
Si encontrás una vulnerabilidad de seguridad en esta herramienta, por favor reportala abriendo un issue en el [repositorio de GitHub](https://github.com/ignaciobecher/ar-saas) en lugar de hacerlo público. Intentaremos resolverlo a la brevedad.
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
<p align="center">
|
|
231
|
+
Hecho en Argentina 🇦🇷
|
|
232
|
+
</p>
|
package/dist/cli.js
CHANGED
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.runCli = runCli;
|
|
7
7
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
-
|
|
10
|
-
async function runCli() {
|
|
9
|
+
async function runCli(defaultName) {
|
|
11
10
|
console.log(chalk_1.default.bold('\n ar-saas'));
|
|
12
11
|
console.log(chalk_1.default.gray(' Backend NestJS + Frontend Next.js listos para producción\n'));
|
|
13
12
|
const answers = await inquirer_1.default.prompt([
|
|
@@ -15,7 +14,7 @@ async function runCli() {
|
|
|
15
14
|
type: 'input',
|
|
16
15
|
name: 'projectName',
|
|
17
16
|
message: 'Nombre del proyecto:',
|
|
18
|
-
default: 'my-saas',
|
|
17
|
+
default: defaultName ?? 'my-saas',
|
|
19
18
|
validate: (input) => {
|
|
20
19
|
if (!/^[a-z0-9][a-z0-9-]{1,}$/.test(input)) {
|
|
21
20
|
return 'Solo letras minúsculas, números y guiones (mínimo 2 caracteres)';
|
|
@@ -38,13 +37,10 @@ async function runCli() {
|
|
|
38
37
|
name: 'modules',
|
|
39
38
|
message: 'Módulos adicionales:',
|
|
40
39
|
choices: [
|
|
41
|
-
{ name: 'OAuth GitHub/Google + 2FA', value: 'auth-advanced' },
|
|
42
40
|
{ name: 'Notificaciones + Push Web', value: 'notifications' },
|
|
43
41
|
{ name: 'Invoices + Quotes + PDF', value: 'invoices' },
|
|
44
42
|
{ name: 'CRM + Kanban', value: 'crm' },
|
|
45
|
-
{ name: 'MercadoPago suscripciones', value: 'mercadopago' },
|
|
46
43
|
],
|
|
47
|
-
filter: (selected) => Array.from(new Set([...ALWAYS_INCLUDED, ...selected])),
|
|
48
44
|
},
|
|
49
45
|
{
|
|
50
46
|
type: 'list',
|
|
@@ -58,10 +54,5 @@ async function runCli() {
|
|
|
58
54
|
],
|
|
59
55
|
},
|
|
60
56
|
]);
|
|
61
|
-
return
|
|
62
|
-
projectName: answers.projectName,
|
|
63
|
-
stack: answers.stack,
|
|
64
|
-
modules: answers.modules,
|
|
65
|
-
deployTarget: answers.deployTarget,
|
|
66
|
-
};
|
|
57
|
+
return answers;
|
|
67
58
|
}
|
package/dist/generator.js
CHANGED
|
@@ -22,7 +22,6 @@ const TEXT_EXTENSIONS = new Set([
|
|
|
22
22
|
'Dockerfile', 'Makefile', 'Procfile',
|
|
23
23
|
]);
|
|
24
24
|
const SKIP_DIRS = new Set(['.git', 'node_modules', 'dist', '.next', '.turbo', 'build']);
|
|
25
|
-
const PRO_MODULES = new Set(['auth-advanced', 'notifications', 'invoices', 'crm', 'mercadopago']);
|
|
26
25
|
async function generate(config) {
|
|
27
26
|
const projectDir = path_1.default.join(process.cwd(), config.projectName);
|
|
28
27
|
const spinner = (0, ora_1.default)();
|
|
@@ -35,7 +34,6 @@ async function generate(config) {
|
|
|
35
34
|
fs_1.default.mkdirSync(projectDir, { recursive: true });
|
|
36
35
|
const hasBackend = config.stack === 'backend' || config.stack === 'backend-frontend';
|
|
37
36
|
const hasFrontend = config.stack === 'frontend' || config.stack === 'backend-frontend';
|
|
38
|
-
const hasValidPro = [...config.modules].some((m) => PRO_MODULES.has(m));
|
|
39
37
|
if (hasBackend) {
|
|
40
38
|
spinner.text = 'Copiando backend...';
|
|
41
39
|
const src = path_1.default.join(TEMPLATES_DIR, 'backend');
|
|
@@ -46,7 +44,7 @@ async function generate(config) {
|
|
|
46
44
|
}
|
|
47
45
|
else {
|
|
48
46
|
await fs_extra_1.default.copy(src, dest);
|
|
49
|
-
processDir(dest, config
|
|
47
|
+
processDir(dest, config);
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
50
|
if (hasFrontend) {
|
|
@@ -59,7 +57,7 @@ async function generate(config) {
|
|
|
59
57
|
}
|
|
60
58
|
else {
|
|
61
59
|
await fs_extra_1.default.copy(src, dest);
|
|
62
|
-
processDir(dest, config
|
|
60
|
+
processDir(dest, config);
|
|
63
61
|
}
|
|
64
62
|
}
|
|
65
63
|
spinner.text = 'Generando configuración de deploy...';
|
|
@@ -69,12 +67,11 @@ async function generate(config) {
|
|
|
69
67
|
spinner.succeed(chalk_1.default.green(`Proyecto ${chalk_1.default.bold(config.projectName)} creado`));
|
|
70
68
|
printNextSteps(config);
|
|
71
69
|
}
|
|
72
|
-
function processDir(dir, config
|
|
70
|
+
function processDir(dir, config) {
|
|
73
71
|
for (const file of collectTextFiles(dir)) {
|
|
74
72
|
try {
|
|
75
73
|
let content = fs_1.default.readFileSync(file, 'utf-8');
|
|
76
74
|
content = applyNameReplacements(content, config.projectName);
|
|
77
|
-
content = applyProModuleHandling(content, hasValidPro);
|
|
78
75
|
fs_1.default.writeFileSync(file, content, 'utf-8');
|
|
79
76
|
}
|
|
80
77
|
catch {
|
|
@@ -102,17 +99,9 @@ function collectTextFiles(dir) {
|
|
|
102
99
|
}
|
|
103
100
|
function applyNameReplacements(content, projectName) {
|
|
104
101
|
return content
|
|
105
|
-
.replace(/
|
|
106
|
-
.replace(/
|
|
107
|
-
.replace(/
|
|
108
|
-
}
|
|
109
|
-
function applyProModuleHandling(content, hasValidPro) {
|
|
110
|
-
if (hasValidPro) {
|
|
111
|
-
// Uncomment PRO code: remove the "// [PRO] " prefix
|
|
112
|
-
return content.replace(/^(\s*)\/\/ \[PRO\] /gm, '$1');
|
|
113
|
-
}
|
|
114
|
-
// Add explanatory placeholder for PRO lines
|
|
115
|
-
return content.replace(/^(\s*)\/\/ \[PRO\] (.+)$/gm, '$1// [PRO MODULE] $2 — requiere licencia PRO: https://ar-saas.dev');
|
|
102
|
+
.replace(/ar-saas-backend/g, `${projectName}-backend`)
|
|
103
|
+
.replace(/ar-saas-frontend/g, `${projectName}-frontend`)
|
|
104
|
+
.replace(/ar-saas/g, projectName);
|
|
116
105
|
}
|
|
117
106
|
function generateDeployConfig(projectDir, config) {
|
|
118
107
|
if (config.deployTarget === 'later')
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
const cli_1 = require("./cli");
|
|
5
5
|
const generator_1 = require("./generator");
|
|
6
6
|
async function main() {
|
|
7
|
-
const
|
|
7
|
+
const defaultName = process.argv[2];
|
|
8
|
+
const config = await (0, cli_1.runCli)(defaultName);
|
|
8
9
|
await (0, generator_1.generate)(config);
|
|
9
10
|
}
|
|
10
11
|
main().catch((error) => {
|
package/package.json
CHANGED
package/dist/license.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.validateLicense = validateLicense;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const os_1 = __importDefault(require("os"));
|
|
10
|
-
const CACHE_DIR = path_1.default.join(os_1.default.homedir(), '.ar-saas');
|
|
11
|
-
const CACHE_FILE = path_1.default.join(CACHE_DIR, 'license');
|
|
12
|
-
const LICENSE_API = 'https://api.create-saas-ar.dev/licenses/validate';
|
|
13
|
-
const LICENSE_REGEX = /^CSAR-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}$/;
|
|
14
|
-
async function validateLicense(license) {
|
|
15
|
-
const normalized = license.trim().toUpperCase();
|
|
16
|
-
if (!LICENSE_REGEX.test(normalized)) {
|
|
17
|
-
return {
|
|
18
|
-
valid: false,
|
|
19
|
-
error: 'Formato inválido. La licencia debe tener el formato CSAR-XXXX-XXXX-XXXX',
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
const cached = readCache();
|
|
23
|
-
if (cached === normalized) {
|
|
24
|
-
return { valid: true };
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
const controller = new AbortController();
|
|
28
|
-
const timeout = setTimeout(() => controller.abort(), 5000);
|
|
29
|
-
const response = await fetch(LICENSE_API, {
|
|
30
|
-
method: 'POST',
|
|
31
|
-
headers: { 'Content-Type': 'application/json' },
|
|
32
|
-
body: JSON.stringify({ license: normalized }),
|
|
33
|
-
signal: controller.signal,
|
|
34
|
-
});
|
|
35
|
-
clearTimeout(timeout);
|
|
36
|
-
if (!response.ok) {
|
|
37
|
-
return { valid: false, error: 'Licencia inválida o expirada' };
|
|
38
|
-
}
|
|
39
|
-
const data = (await response.json());
|
|
40
|
-
if (data.valid) {
|
|
41
|
-
writeCache(normalized);
|
|
42
|
-
return { valid: true };
|
|
43
|
-
}
|
|
44
|
-
return { valid: false, error: 'Licencia inválida o expirada' };
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
// Fail open: si la API no está disponible, aceptar la licencia
|
|
48
|
-
writeCache(normalized);
|
|
49
|
-
return { valid: true };
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
function readCache() {
|
|
53
|
-
try {
|
|
54
|
-
if (fs_1.default.existsSync(CACHE_FILE)) {
|
|
55
|
-
return fs_1.default.readFileSync(CACHE_FILE, 'utf-8').trim();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
// ignore
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
function writeCache(license) {
|
|
64
|
-
try {
|
|
65
|
-
fs_1.default.mkdirSync(CACHE_DIR, { recursive: true });
|
|
66
|
-
fs_1.default.writeFileSync(CACHE_FILE, license, 'utf-8');
|
|
67
|
-
}
|
|
68
|
-
catch {
|
|
69
|
-
// ignore — no bloquear al usuario si no se puede escribir la caché
|
|
70
|
-
}
|
|
71
|
-
}
|