@neetru/cli 1.0.1 → 2.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/CHANGELOG.md +136 -0
- package/README.md +109 -152
- package/dist/commands/add.d.ts +8 -3
- package/dist/commands/add.js +70 -143
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/ai.d.ts +4 -0
- package/dist/commands/ai.js +88 -0
- package/dist/commands/ai.js.map +1 -0
- package/dist/commands/autocomplete.d.ts +7 -0
- package/dist/commands/autocomplete.js +107 -0
- package/dist/commands/autocomplete.js.map +1 -0
- package/dist/commands/build.d.ts +18 -0
- package/dist/commands/build.js +288 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/config.d.ts +3 -0
- package/dist/commands/config.js +70 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/db.d.ts +14 -0
- package/dist/commands/db.js +187 -0
- package/dist/commands/db.js.map +1 -0
- package/dist/commands/deploy.d.ts +16 -3
- package/dist/commands/deploy.js +400 -180
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/doctor.d.ts +27 -0
- package/dist/commands/doctor.js +211 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/env.d.ts +15 -0
- package/dist/commands/env.js +56 -0
- package/dist/commands/env.js.map +1 -0
- package/dist/commands/fn.d.ts +6 -0
- package/dist/commands/fn.js +87 -0
- package/dist/commands/fn.js.map +1 -0
- package/dist/commands/init.d.ts +10 -3
- package/dist/commands/init.js +212 -143
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/login.d.ts +6 -3
- package/dist/commands/login.js +222 -92
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.d.ts +1 -0
- package/dist/commands/logout.js +28 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/logs.d.ts +14 -3
- package/dist/commands/logs.js +132 -106
- package/dist/commands/logs.js.map +1 -1
- package/dist/commands/mocks.d.ts +5 -0
- package/dist/commands/mocks.js +23 -0
- package/dist/commands/mocks.js.map +1 -0
- package/dist/commands/open.d.ts +4 -3
- package/dist/commands/open.js +53 -85
- package/dist/commands/open.js.map +1 -1
- package/dist/commands/promote.d.ts +9 -0
- package/dist/commands/promote.js +114 -0
- package/dist/commands/promote.js.map +1 -0
- package/dist/commands/publish.d.ts +14 -0
- package/dist/commands/publish.js +180 -0
- package/dist/commands/publish.js.map +1 -0
- package/dist/commands/status.d.ts +5 -3
- package/dist/commands/status.js +91 -93
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/upgrade.d.ts +12 -0
- package/dist/commands/upgrade.js +77 -0
- package/dist/commands/upgrade.js.map +1 -0
- package/dist/commands/validate.d.ts +1 -3
- package/dist/commands/validate.js +83 -91
- package/dist/commands/validate.js.map +1 -1
- package/dist/commands/whoami.d.ts +5 -3
- package/dist/commands/whoami.js +76 -28
- package/dist/commands/whoami.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +337 -36
- package/dist/index.js.map +1 -1
- package/dist/lib/ai/context.d.ts +11 -0
- package/dist/lib/ai/context.js +112 -0
- package/dist/lib/ai/context.js.map +1 -0
- package/dist/lib/ai/orchestrator.d.ts +10 -0
- package/dist/lib/ai/orchestrator.js +92 -0
- package/dist/lib/ai/orchestrator.js.map +1 -0
- package/dist/lib/api-client.d.ts +21 -0
- package/dist/lib/api-client.js +65 -0
- package/dist/lib/api-client.js.map +1 -0
- package/dist/lib/auth.d.ts +15 -0
- package/dist/lib/auth.js +98 -0
- package/dist/lib/auth.js.map +1 -0
- package/dist/lib/config-schema.d.ts +165 -0
- package/dist/lib/config-schema.js +57 -0
- package/dist/lib/config-schema.js.map +1 -0
- package/dist/lib/config.d.ts +15 -0
- package/dist/lib/config.js +33 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/utils/logger.d.ts +13 -0
- package/dist/utils/logger.js +27 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +35 -33
- package/templates/auth/callback.ts +22 -0
- package/templates/auth/sign-in.tsx +41 -0
- package/templates/billing/checkout.ts +22 -0
- package/templates/billing/page.tsx +43 -0
- package/templates/support/ticket-form.tsx +68 -0
- package/templates/usage/track.ts +30 -0
- package/templates/users/profile.tsx +43 -0
- package/LICENSE +0 -21
- package/dist/commands/add.d.ts.map +0 -1
- package/dist/commands/deploy.d.ts.map +0 -1
- package/dist/commands/generate-types.d.ts +0 -3
- package/dist/commands/generate-types.d.ts.map +0 -1
- package/dist/commands/generate-types.js +0 -150
- package/dist/commands/generate-types.js.map +0 -1
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/login.d.ts.map +0 -1
- package/dist/commands/logs.d.ts.map +0 -1
- package/dist/commands/open.d.ts.map +0 -1
- package/dist/commands/status.d.ts.map +0 -1
- package/dist/commands/validate.d.ts.map +0 -1
- package/dist/commands/whoami.d.ts.map +0 -1
- package/dist/config.d.ts +0 -14
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -83
- package/dist/config.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/scaffold/auth.d.ts +0 -3
- package/dist/scaffold/auth.d.ts.map +0 -1
- package/dist/scaffold/auth.js +0 -228
- package/dist/scaffold/auth.js.map +0 -1
- package/dist/scaffold/billing.d.ts +0 -3
- package/dist/scaffold/billing.d.ts.map +0 -1
- package/dist/scaffold/billing.js +0 -184
- package/dist/scaffold/billing.js.map +0 -1
- package/dist/scaffold/usage.d.ts +0 -3
- package/dist/scaffold/usage.d.ts.map +0 -1
- package/dist/scaffold/usage.js +0 -173
- package/dist/scaffold/usage.js.map +0 -1
- package/dist/scaffold/users.d.ts +0 -3
- package/dist/scaffold/users.d.ts.map +0 -1
- package/dist/scaffold/users.js +0 -135
- package/dist/scaffold/users.js.map +0 -1
package/dist/commands/init.js
CHANGED
|
@@ -1,149 +1,218 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import * as fs from 'fs/promises';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import ora from 'ora';
|
|
4
|
+
import { log } from '../utils/logger.js';
|
|
5
|
+
/**
|
|
6
|
+
* Scaffold de projeto SaaS Neetru.
|
|
7
|
+
* Gera estrutura mínima com Core SDK wired: auth, tenant gate, billing hook.
|
|
8
|
+
*/
|
|
9
|
+
export async function runInit({ name, type }) {
|
|
10
|
+
log.banner();
|
|
11
|
+
log.heading(`Inicializando produto: ${name}`);
|
|
12
|
+
console.log();
|
|
13
|
+
const dir = path.resolve(process.cwd(), name);
|
|
14
|
+
// Verifica se diretório já existe
|
|
15
|
+
try {
|
|
16
|
+
await fs.access(dir);
|
|
17
|
+
log.error(`Diretório "${name}" já existe.`);
|
|
18
|
+
process.exit(1);
|
|
7
19
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.initCommand = initCommand;
|
|
40
|
-
const commander_1 = require("commander");
|
|
41
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
42
|
-
const ora_1 = __importDefault(require("ora"));
|
|
43
|
-
const fs = __importStar(require("fs-extra"));
|
|
44
|
-
const path = __importStar(require("path"));
|
|
45
|
-
const config_1 = require("../config");
|
|
46
|
-
// Dynamically import inquirer to avoid top-level await issues
|
|
47
|
-
async function prompt(questions) {
|
|
48
|
-
const { default: inquirer } = await Promise.resolve().then(() => __importStar(require('inquirer')));
|
|
49
|
-
return inquirer.prompt(questions);
|
|
50
|
-
}
|
|
51
|
-
function initCommand() {
|
|
52
|
-
const cmd = new commander_1.Command('init');
|
|
53
|
-
cmd
|
|
54
|
-
.description('Inicializa a integração Neetru no projeto atual')
|
|
55
|
-
.option('--core-url <url>', 'URL do Neetru Core (ex: https://core.neetru.com)')
|
|
56
|
-
.option('--client-id <id>', 'OAuth Client ID fornecido pelo Neetru Core')
|
|
57
|
-
.option('--yes', 'Pular confirmações interativas')
|
|
58
|
-
.action(async (options) => {
|
|
59
|
-
console.log('\n' + chalk_1.default.bold.cyan('🚀 Neetru SDK — Inicialização'));
|
|
60
|
-
console.log(chalk_1.default.dim('Conectando seu SaaS ao Neetru Core\n'));
|
|
61
|
-
// Check if already initialized
|
|
62
|
-
if (fs.existsSync('neetru.json') && !options.yes) {
|
|
63
|
-
const { overwrite } = await prompt([{
|
|
64
|
-
type: 'confirm',
|
|
65
|
-
name: 'overwrite',
|
|
66
|
-
message: chalk_1.default.yellow('neetru.json já existe. Sobrescrever?'),
|
|
67
|
-
default: false,
|
|
68
|
-
}]);
|
|
69
|
-
if (!overwrite) {
|
|
70
|
-
console.log(chalk_1.default.dim('Cancelado.'));
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// Collect info interactively if not provided via flags
|
|
75
|
-
const coreUrl = options.coreUrl ?? (await prompt([{
|
|
76
|
-
type: 'input',
|
|
77
|
-
name: 'coreUrl',
|
|
78
|
-
message: 'URL do Neetru Core:',
|
|
79
|
-
default: 'https://core.neetru.com',
|
|
80
|
-
validate: (v) => v.startsWith('http') || 'URL inválida',
|
|
81
|
-
}])).coreUrl;
|
|
82
|
-
const clientId = options.clientId ?? (await prompt([{
|
|
83
|
-
type: 'input',
|
|
84
|
-
name: 'clientId',
|
|
85
|
-
message: 'OAuth Client ID (do painel Neetru → Workspaces → Credenciais):',
|
|
86
|
-
validate: (v) => v.length > 0 || 'Client ID obrigatório',
|
|
87
|
-
}])).clientId;
|
|
88
|
-
const projectName = path.basename(process.cwd());
|
|
89
|
-
const { features } = await prompt([{
|
|
90
|
-
type: 'checkbox',
|
|
91
|
-
name: 'features',
|
|
92
|
-
message: 'Quais integrações você precisa?',
|
|
93
|
-
choices: [
|
|
94
|
-
{ name: 'auth — Login com OAuth Neetru (SSO)', value: 'auth', checked: true },
|
|
95
|
-
{ name: 'billing — Assinaturas e planos', value: 'billing', checked: true },
|
|
96
|
-
{ name: 'usage — Metered billing (reporte de uso)', value: 'usage' },
|
|
97
|
-
{ name: 'users — API de usuários Neetru', value: 'users' },
|
|
98
|
-
],
|
|
99
|
-
}]);
|
|
100
|
-
// Validate connection
|
|
101
|
-
const spinner = (0, ora_1.default)('Verificando conexão com o Core...').start();
|
|
102
|
-
try {
|
|
103
|
-
const res = await fetch(`${coreUrl}/api/health`, { signal: AbortSignal.timeout(5000) });
|
|
104
|
-
if (res.ok) {
|
|
105
|
-
spinner.succeed('Conexão verificada');
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
spinner.warn(`Core respondeu com status ${res.status} — continuando mesmo assim`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
catch {
|
|
112
|
-
spinner.warn('Não foi possível verificar a conexão — continuando offline');
|
|
113
|
-
}
|
|
114
|
-
// Write neetru.json
|
|
115
|
-
(0, config_1.writeLocalConfig)({
|
|
116
|
-
coreUrl,
|
|
117
|
-
clientId,
|
|
118
|
-
projectName,
|
|
119
|
-
features,
|
|
120
|
-
createdAt: new Date().toISOString(),
|
|
121
|
-
});
|
|
122
|
-
// Write .env.example entries
|
|
123
|
-
const envPath = '.env.example';
|
|
124
|
-
const envEntries = [
|
|
125
|
-
'',
|
|
126
|
-
'# Neetru Core',
|
|
127
|
-
`NEETRU_CORE_URL=${coreUrl}`,
|
|
128
|
-
`NEETRU_CLIENT_ID=${clientId}`,
|
|
129
|
-
'NEETRU_CLIENT_SECRET=your_client_secret_here',
|
|
130
|
-
...(features.includes('billing') ? ['NEETRU_WEBHOOK_SECRET=your_webhook_secret_here'] : []),
|
|
131
|
-
].join('\n');
|
|
132
|
-
if (fs.existsSync(envPath)) {
|
|
133
|
-
fs.appendFileSync(envPath, envEntries);
|
|
134
|
-
console.log(chalk_1.default.dim(` → Entradas adicionadas ao ${envPath}`));
|
|
20
|
+
catch {
|
|
21
|
+
// ok, não existe
|
|
22
|
+
}
|
|
23
|
+
const spinner = ora({ text: 'Criando estrutura...', color: 'blue' }).start();
|
|
24
|
+
try {
|
|
25
|
+
await fs.mkdir(dir, { recursive: true });
|
|
26
|
+
if (type === 'nextjs') {
|
|
27
|
+
await scaffoldNextjs(dir, name);
|
|
135
28
|
}
|
|
136
29
|
else {
|
|
137
|
-
|
|
138
|
-
console.log(chalk_1.default.dim(` → ${envPath} criado`));
|
|
30
|
+
await scaffoldNodeApi(dir, name);
|
|
139
31
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
32
|
+
// Arquivo de config do projeto
|
|
33
|
+
const slug = name
|
|
34
|
+
.trim()
|
|
35
|
+
.toLowerCase()
|
|
36
|
+
.replace(/[^a-z0-9-]+/g, '-')
|
|
37
|
+
.replace(/-+/g, '-')
|
|
38
|
+
.replace(/^-|-$/g, '');
|
|
39
|
+
await fs.writeFile(path.join(dir, 'neetru.config.json'), JSON.stringify({
|
|
40
|
+
$schema: 'https://neetru.com/schema/neetru.config.json',
|
|
41
|
+
slug: slug || name,
|
|
42
|
+
name,
|
|
43
|
+
runtime: type,
|
|
44
|
+
tenantId: '',
|
|
45
|
+
publish: {
|
|
46
|
+
tagline: '',
|
|
47
|
+
description: '',
|
|
48
|
+
iconKey: 'spark',
|
|
49
|
+
status: 'soon',
|
|
50
|
+
order: 100,
|
|
51
|
+
},
|
|
52
|
+
}, null, 2));
|
|
53
|
+
spinner.succeed('Projeto criado com sucesso!');
|
|
54
|
+
console.log();
|
|
55
|
+
log.info(`Diretório: ${dir}`);
|
|
56
|
+
log.info(`Próximos passos:`);
|
|
57
|
+
log.dim(` cd ${name}`);
|
|
58
|
+
log.dim(` npm install`);
|
|
59
|
+
log.dim(` neetru ai # inicie o assistente dentro do projeto`);
|
|
60
|
+
log.dim(` neetru dev # inicia servidor de dev local`);
|
|
61
|
+
console.log();
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
spinner.fail('Falha ao criar projeto.');
|
|
65
|
+
log.error(err?.message);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function scaffoldNextjs(dir, name) {
|
|
70
|
+
const src = path.join(dir, 'src', 'app');
|
|
71
|
+
await fs.mkdir(src, { recursive: true });
|
|
72
|
+
await fs.mkdir(path.join(dir, 'src', 'lib'), { recursive: true });
|
|
73
|
+
await fs.mkdir(path.join(dir, 'src', 'components'), { recursive: true });
|
|
74
|
+
// package.json
|
|
75
|
+
await fs.writeFile(path.join(dir, 'package.json'), JSON.stringify({
|
|
76
|
+
name,
|
|
77
|
+
version: '0.1.0',
|
|
78
|
+
private: true,
|
|
79
|
+
scripts: {
|
|
80
|
+
dev: 'next dev -p 3000',
|
|
81
|
+
build: 'next build',
|
|
82
|
+
start: 'next start',
|
|
83
|
+
},
|
|
84
|
+
dependencies: {
|
|
85
|
+
next: '^15.0.0',
|
|
86
|
+
react: '^19.0.0',
|
|
87
|
+
'react-dom': '^19.0.0',
|
|
88
|
+
'@neetru/sdk': 'latest',
|
|
89
|
+
firebase: '^11.0.0',
|
|
90
|
+
},
|
|
91
|
+
devDependencies: {
|
|
92
|
+
typescript: '^5.7.0',
|
|
93
|
+
'@types/node': '^22.0.0',
|
|
94
|
+
'@types/react': '^19.0.0',
|
|
95
|
+
},
|
|
96
|
+
}, null, 2));
|
|
97
|
+
// next.config.mjs
|
|
98
|
+
await fs.writeFile(path.join(dir, 'next.config.mjs'), `/** @type {import('next').NextConfig} */
|
|
99
|
+
const nextConfig = {};
|
|
100
|
+
export default nextConfig;
|
|
101
|
+
`);
|
|
102
|
+
// Layout raiz
|
|
103
|
+
await fs.writeFile(path.join(src, 'layout.tsx'), `import type { Metadata } from 'next';
|
|
104
|
+
|
|
105
|
+
export const metadata: Metadata = {
|
|
106
|
+
title: '${name}',
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
110
|
+
return (
|
|
111
|
+
<html lang="pt-BR">
|
|
112
|
+
<body>{children}</body>
|
|
113
|
+
</html>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
`);
|
|
117
|
+
// Página inicial com tenant gate
|
|
118
|
+
await fs.writeFile(path.join(src, 'page.tsx'), `// Produto Neetru — gerado por neetru init
|
|
119
|
+
// Auth via Core session cookie + tenant gate
|
|
120
|
+
|
|
121
|
+
import { getServerSession } from '@neetru/sdk/server';
|
|
122
|
+
import { redirect } from 'next/navigation';
|
|
123
|
+
|
|
124
|
+
export default async function HomePage() {
|
|
125
|
+
const session = await getServerSession();
|
|
126
|
+
if (!session) redirect('/login');
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<main>
|
|
130
|
+
<h1>Bem-vindo, {session.email}</h1>
|
|
131
|
+
<p>Tenant: {session.tenantId}</p>
|
|
132
|
+
</main>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
`);
|
|
136
|
+
// Middleware com tenant gate
|
|
137
|
+
await fs.writeFile(path.join(dir, 'src', 'middleware.ts'), `import { withNeetruAuth } from '@neetru/sdk/middleware';
|
|
138
|
+
|
|
139
|
+
export const middleware = withNeetruAuth({
|
|
140
|
+
loginPath: '/login',
|
|
141
|
+
publicPaths: ['/login', '/api/auth'],
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
export const config = {
|
|
145
|
+
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
|
|
146
|
+
};
|
|
147
|
+
`);
|
|
148
|
+
// tsconfig.json
|
|
149
|
+
await fs.writeFile(path.join(dir, 'tsconfig.json'), JSON.stringify({
|
|
150
|
+
compilerOptions: {
|
|
151
|
+
target: 'ES2017',
|
|
152
|
+
lib: ['dom', 'dom.iterable', 'esnext'],
|
|
153
|
+
allowJs: true,
|
|
154
|
+
skipLibCheck: true,
|
|
155
|
+
strict: true,
|
|
156
|
+
noEmit: true,
|
|
157
|
+
esModuleInterop: true,
|
|
158
|
+
module: 'esnext',
|
|
159
|
+
moduleResolution: 'bundler',
|
|
160
|
+
resolveJsonModule: true,
|
|
161
|
+
isolatedModules: true,
|
|
162
|
+
jsx: 'preserve',
|
|
163
|
+
incremental: true,
|
|
164
|
+
plugins: [{ name: 'next' }],
|
|
165
|
+
paths: { '@/*': ['./src/*'] },
|
|
166
|
+
},
|
|
167
|
+
include: ['next-env.d.ts', '**/*.ts', '**/*.tsx', '.next/types/**/*.ts'],
|
|
168
|
+
exclude: ['node_modules'],
|
|
169
|
+
}, null, 2));
|
|
170
|
+
}
|
|
171
|
+
async function scaffoldNodeApi(dir, name) {
|
|
172
|
+
await fs.mkdir(path.join(dir, 'src', 'routes'), { recursive: true });
|
|
173
|
+
await fs.mkdir(path.join(dir, 'src', 'middleware'), { recursive: true });
|
|
174
|
+
await fs.writeFile(path.join(dir, 'package.json'), JSON.stringify({
|
|
175
|
+
name,
|
|
176
|
+
version: '0.1.0',
|
|
177
|
+
private: true,
|
|
178
|
+
type: 'module',
|
|
179
|
+
scripts: {
|
|
180
|
+
dev: 'tsx --watch src/index.ts',
|
|
181
|
+
build: 'tsc',
|
|
182
|
+
start: 'node dist/index.js',
|
|
183
|
+
},
|
|
184
|
+
dependencies: {
|
|
185
|
+
fastify: '^5.0.0',
|
|
186
|
+
'@neetru/sdk': 'latest',
|
|
187
|
+
},
|
|
188
|
+
devDependencies: {
|
|
189
|
+
tsx: '^4.0.0',
|
|
190
|
+
typescript: '^5.7.0',
|
|
191
|
+
'@types/node': '^22.0.0',
|
|
192
|
+
},
|
|
193
|
+
}, null, 2));
|
|
194
|
+
await fs.writeFile(path.join(dir, 'src', 'index.ts'), `import Fastify from 'fastify';
|
|
195
|
+
import { neetruPlugin } from '@neetru/sdk/fastify';
|
|
196
|
+
|
|
197
|
+
const app = Fastify({ logger: true });
|
|
198
|
+
|
|
199
|
+
// Plugin Core: auth, tenant gate, entitlements
|
|
200
|
+
await app.register(neetruPlugin, {
|
|
201
|
+
apiKey: process.env.NEETRU_API_KEY,
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
app.get('/health', async () => ({ status: 'ok' }));
|
|
205
|
+
|
|
206
|
+
// Rota protegida com verificação de entitlement
|
|
207
|
+
app.get('/api/data', {
|
|
208
|
+
preHandler: app.auth([app.neetruAuth]),
|
|
209
|
+
handler: async (req) => {
|
|
210
|
+
const { tenantId } = req.neetruSession;
|
|
211
|
+
return { tenantId, data: [] };
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
await app.listen({ port: 3000, host: '0.0.0.0' });
|
|
216
|
+
`);
|
|
148
217
|
}
|
|
149
218
|
//# sourceMappingURL=init.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,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AAY;IACtD,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACrE,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,YAAY,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAEzE,MAAM,EAAE,CAAC,SAAS,CAChB,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,EAC9B,IAAI,CAAC,SAAS,CACZ;QACE,IAAI;QACJ,OAAO,EAAE,OAAO;QAChB,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE;YACP,GAAG,EAAE,0BAA0B;YAC/B,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,oBAAoB;SAC5B;QACD,YAAY,EAAE;YACZ,OAAO,EAAE,QAAQ;YACjB,aAAa,EAAE,QAAQ;SACxB;QACD,eAAe,EAAE;YACf,GAAG,EAAE,QAAQ;YACb,UAAU,EAAE,QAAQ;YACpB,aAAa,EAAE,SAAS;SACzB;KACF,EACD,IAAI,EACJ,CAAC,CACF,CACF,CAAC;IAEF,MAAM,EAAE,CAAC,SAAS,CAChB,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,UAAU,CAAC,EACjC;;;;;;;;;;;;;;;;;;;;;;CAsBH,CACE,CAAC;AACJ,CAAC"}
|
package/dist/commands/login.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
interface RunLoginOpts {
|
|
2
|
+
token?: string;
|
|
3
|
+
json?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function runLogin(opts?: RunLoginOpts): Promise<void>;
|
|
6
|
+
export {};
|