@redcumbrecl/cli 0.1.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/README.md +25 -0
- package/dist/cli.js +1049 -0
- package/dist/plantillas/dotnet/AGENTS.md +24 -0
- package/dist/plantillas/dotnet/Program.cs +106 -0
- package/dist/plantillas/dotnet/Redcumbre/LlaveRedcumbre.cs +48 -0
- package/dist/plantillas/php/AGENTS.md +24 -0
- package/dist/plantillas/php/redcumbre/ejemplo.php +117 -0
- package/dist/plantillas/php/redcumbre/llave.php +48 -0
- package/dist/plantillas/python/AGENTS.md +24 -0
- package/dist/plantillas/python/redcumbre_ejemplo.py +97 -0
- package/dist/plantillas/python/redcumbre_llave.py +38 -0
- package/dist/plantillas/typescript/AGENTS.md +24 -0
- package/dist/plantillas/typescript/redcumbre/ejemplo.ts +82 -0
- package/dist/plantillas/typescript/redcumbre/llave.ts +44 -0
- package/package.json +43 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Lector de la llave de rCAPI, generado por `npx @redcumbrecl/cli init`.
|
|
2
|
+
//
|
|
3
|
+
// El `.env` NO guarda el secreto: guarda la ruta al archivo de la llave
|
|
4
|
+
// (REDCUMBRE_LLAVE_SANDBOX=keys/redcumbre-sandbox.json). El archivo es el JSON que descarga la
|
|
5
|
+
// pantalla web de llaves, y queda fuera del control de versiones (.gitignore).
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
|
|
9
|
+
export type Entorno = 'sandbox' | 'produccion';
|
|
10
|
+
|
|
11
|
+
export interface Llave {
|
|
12
|
+
tenantSlug: string;
|
|
13
|
+
name: string;
|
|
14
|
+
isSandbox: boolean;
|
|
15
|
+
token: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const API = process.env.REDCUMBRE_API_URL ?? 'https://api.redcumbre.cl';
|
|
19
|
+
|
|
20
|
+
const variable = (entorno: Entorno) => `REDCUMBRE_LLAVE_${entorno.toUpperCase()}`;
|
|
21
|
+
|
|
22
|
+
/** Carga el `.env` del proyecto sin pisar las variables que ya vienen del entorno. */
|
|
23
|
+
export function cargarEnv(proyecto = process.cwd()): void {
|
|
24
|
+
const ruta = path.join(proyecto, '.env');
|
|
25
|
+
if (!fs.existsSync(ruta)) return;
|
|
26
|
+
for (const linea of fs.readFileSync(ruta, 'utf8').split(/\r?\n/)) {
|
|
27
|
+
const m = linea.match(/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/);
|
|
28
|
+
if (m && process.env[m[1]] === undefined) process.env[m[1]] = m[2].replace(/^["']|["']$/g, '');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type Lectura =
|
|
33
|
+
| { estado: 'sin-puntero' }
|
|
34
|
+
| { estado: 'sin-archivo'; ruta: string }
|
|
35
|
+
| { estado: 'ok'; llave: Llave };
|
|
36
|
+
|
|
37
|
+
/** Lee la llave de un entorno siguiendo el puntero del `.env`. */
|
|
38
|
+
export function leerLlave(entorno: Entorno, proyecto = process.cwd()): Lectura {
|
|
39
|
+
const puntero = process.env[variable(entorno)];
|
|
40
|
+
if (!puntero) return { estado: 'sin-puntero' };
|
|
41
|
+
const ruta = path.resolve(proyecto, puntero);
|
|
42
|
+
if (!fs.existsSync(ruta)) return { estado: 'sin-archivo', ruta };
|
|
43
|
+
return { estado: 'ok', llave: JSON.parse(fs.readFileSync(ruta, 'utf8')) as Llave };
|
|
44
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@redcumbrecl/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Conecta tu proyecto con rCAPI de REDCUMBRE: inicia sesión con tu cuenta e instala la llave de la API en el proyecto.",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"redcumbre": "dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist/"
|
|
12
|
+
],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=20"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public",
|
|
18
|
+
"provenance": false
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/redcumbre/rCAPI.git",
|
|
23
|
+
"directory": "apps/cli"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://docs.redcumbre.cl/primeros-pasos/integrar-con-ia/",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "node scripts/build.mjs",
|
|
28
|
+
"test": "node scripts/test.mjs",
|
|
29
|
+
"typecheck": "tsc --noEmit"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@inquirer/prompts": "^7.10.1",
|
|
33
|
+
"@napi-rs/keyring": "^1.3.0",
|
|
34
|
+
"commander": "^14.0.2",
|
|
35
|
+
"openid-client": "^6.8.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^22.10.5",
|
|
39
|
+
"esbuild": "^0.25.12",
|
|
40
|
+
"tsx": "^4.20.6",
|
|
41
|
+
"typescript": "^5.7.3"
|
|
42
|
+
}
|
|
43
|
+
}
|