@envsafes-org/cli 0.0.10 → 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 CHANGED
@@ -1,343 +1,209 @@
1
- # 🔐 EnvSafe CLI
1
+ # EnvSafe CLI
2
2
 
3
- **Gestionnaire sécurisé de variables d'environnement pour vos équipes**
3
+ CLI officiel pour **EnvSafe** - Gestionnaire sécurisé de variables d'environnement pour équipes.
4
4
 
5
- [![npm version](https://img.shields.io/npm/v/@envsafes-org/cli.svg)](https://www.npmjs.com/package/@envsafes-org/cli)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7
-
8
- EnvSafe CLI vous permet de gérer vos variables d'environnement de manière sécurisée avec chiffrement de bout en bout. Idéal pour les équipes qui veulent centraliser leurs secrets sans compromettre la sécurité.
9
-
10
- ## 🛑 Prérequis
11
-
12
- Avant d'utiliser la CLI, vous devez créer un compte et un projet sur **[https://www.envsafe.dev](https://www.envsafe.dev)**.
13
-
14
- ## 📦 Installation
5
+ ## Installation
15
6
 
16
7
  ```bash
17
- # Installation globale (recommandé)
8
+ # Installation globale (recommandée)
18
9
  npm install -g @envsafes-org/cli
19
10
 
20
- # Avec yarn
11
+ # Ou avec yarn
21
12
  yarn global add @envsafes-org/cli
22
13
 
23
- # Avec pnpm
14
+ # Ou avec pnpm
24
15
  pnpm add -g @envsafes-org/cli
25
16
 
26
- # Utilisation ponctuelle sans installation
27
- npx @envsafes-org/cli
17
+ # Sans installation (npx)
18
+ npx @envsafes-org/cli --help
28
19
  ```
29
20
 
30
- ## 🚀 Démarrage rapide
21
+ ## Configuration rapide
22
+
23
+ ### 1. Connexion
31
24
 
32
25
  ```bash
33
- # 1. Connectez-vous avec votre token API
26
+ # Se connecter (ouvre le navigateur pour générer un token)
34
27
  envsafe login
35
28
 
36
- # 2. Listez vos projets
37
- envsafe projects
38
-
39
- # 3. Récupérez vos variables
40
- envsafe pull mon-projet
41
-
42
- # 4. Ou exécutez directement avec injection
43
- envsafe run mon-projet -- npm start
29
+ # Ou avec un token directement
30
+ envsafe login --token <votre-token>
44
31
  ```
45
32
 
46
- ## 📖 Commandes
47
-
48
- ### `envsafe login`
49
-
50
- Authentifiez-vous avec un token d'accès personnel (PAT).
33
+ ### 2. Lier un workspace
51
34
 
52
35
  ```bash
53
- # Mode interactif
54
- envsafe login
36
+ # Mode interactif - sélectionner un workspace
37
+ envsafe link
55
38
 
56
- # Avec token direct (CI/CD)
57
- envsafe login --token es_live_xxxxxxxxxxxxx
39
+ # Ou spécifier directement le workspace
40
+ envsafe link mon-workspace
58
41
  ```
59
42
 
60
- **💡 Générer un token :** Rendez-vous dans votre Dashboard → Settings → API Tokens
43
+ Cette commande crée un fichier `.envsafe` dans le répertoire courant.
61
44
 
62
- ---
45
+ ### 3. Sélectionner un projet
63
46
 
64
- ### `envsafe projects` (alias: `ls`)
47
+ ```bash
48
+ # Mode interactif - configurer workspace + projet
49
+ envsafe init
65
50
 
66
- Listez tous les projets accessibles.
51
+ # Ou lister les projets disponibles
52
+ envsafe list
67
53
 
68
- ```bash
69
- envsafe projects
70
- # ou
71
- envsafe ls
54
+ # Puis sélectionner un projet
55
+ envsafe select mon-projet
72
56
  ```
73
57
 
74
- ---
58
+ ## Commandes principales
75
59
 
76
- ### `envsafe pull <project>`
77
-
78
- Téléchargez les variables d'environnement dans un fichier local.
60
+ ### Récupérer les variables (Pull)
79
61
 
80
62
  ```bash
81
- # Environnement de développement (par défaut)
82
- envsafe pull mon-projet
83
-
84
- # Environnement spécifique
85
- envsafe pull mon-projet --env staging
86
- envsafe pull mon-projet --env production
63
+ # Récupérer les variables development (par défaut)
64
+ envsafe pull
87
65
 
88
- # Fichier de sortie personnalisé
89
- envsafe pull mon-projet --output .env.local
90
- envsafe pull mon-projet --env production --output .env.prod
91
- ```
92
-
93
- **Options:**
94
- - `-e, --env <environment>` : Environnement (development, staging, production) - Défaut: `development`
95
- - `-o, --output <file>` : Fichier de sortie - Défaut: `.env`
66
+ # Avec raccourcis d'environnement
67
+ envsafe pull -d # development
68
+ envsafe pull -s # staging
69
+ envsafe pull -p # production
96
70
 
97
- ---
71
+ # Spécifier un projet manuellement
72
+ envsafe pull mon-projet -p
98
73
 
99
- ### `envsafe push <project>`
74
+ # Changer le fichier de sortie
75
+ envsafe pull -d -o .env.local
76
+ ```
100
77
 
101
- Envoyez vos variables locales vers EnvSafe (chiffrées automatiquement).
78
+ ### Envoyer les variables (Push)
102
79
 
103
80
  ```bash
104
- # Envoyer .env vers development
105
- envsafe push mon-projet
106
-
107
- # Environnement et fichier spécifiques
108
- envsafe push mon-projet --env production --file .env.prod
109
- ```
81
+ # Envoyer vers development (par défaut)
82
+ envsafe push
110
83
 
111
- **Options:**
112
- - `-e, --env <environment>` : Environnement cible - Défaut: `development`
113
- - `-f, --file <file>` : Fichier source - Défaut: `.env`
84
+ # Avec raccourcis d'environnement
85
+ envsafe push -d # development
86
+ envsafe push -s # staging
87
+ envsafe push -p # production
114
88
 
115
- ---
116
-
117
- ### `envsafe run <project> -- <command>`
89
+ # Spécifier un fichier source
90
+ envsafe push -p -f .env.production
91
+ ```
118
92
 
119
- **⭐️ Commande recommandée** : Exécutez une commande avec les variables injectées directement, sans créer de fichier `.env` sur le disque.
93
+ ### Exécuter avec injection (Run)
120
94
 
121
95
  ```bash
122
- # Développement
123
- envsafe run mon-projet -- npm start
124
- envsafe run mon-projet -- npm run dev
96
+ # Exécuter une commande avec les variables injectées
97
+ envsafe run npm start
125
98
 
126
- # Production
127
- envsafe run mon-projet --env production -- node server.js
99
+ # Avec un environnement spécifique
100
+ envsafe run -p npm start
128
101
 
129
- # Autres exemples
130
- envsafe run mon-projet -- pnpm build
131
- envsafe run mon-projet -- python main.py
132
- envsafe run mon-projet -- docker-compose up
102
+ # Spécifier un projet
103
+ envsafe run mon-projet -s yarn dev
133
104
  ```
134
105
 
135
- **Avantages:**
136
- - ✅ Plus sécurisé (pas de fichier .env sur le disque)
137
- - ✅ Idéal pour CI/CD
138
- - ✅ Pas de risque de commit accidentel de secrets
139
-
140
- ---
141
-
142
- ### `envsafe whoami`
143
-
144
- Affichez les informations du compte connecté.
106
+ ### Créer un projet
145
107
 
146
108
  ```bash
147
- envsafe whoami
148
- ```
109
+ # Mode interactif
110
+ envsafe create
149
111
 
150
- ---
112
+ # Avec un nom
113
+ envsafe create "Mon Nouveau Projet"
114
+ ```
151
115
 
152
- ### `envsafe logout`
116
+ ## Toutes les commandes
153
117
 
154
- Déconnectez-vous (supprime le token local).
118
+ | Commande | Alias | Description |
119
+ |----------|-------|-------------|
120
+ | `envsafe login` | - | Se connecter avec un token API |
121
+ | `envsafe logout` | - | Se déconnecter |
122
+ | `envsafe whoami` | - | Afficher l'utilisateur connecté |
123
+ | `envsafe link [workspace]` | - | Lier ce répertoire à un workspace |
124
+ | `envsafe init` | - | Configurer un projet (interactif) |
125
+ | `envsafe list` | `ls` | Lister les projets du workspace |
126
+ | `envsafe select <projet>` | - | Sélectionner un projet |
127
+ | `envsafe create [nom]` | `new` | Créer un nouveau projet |
128
+ | `envsafe pull [projet]` | - | Télécharger les variables |
129
+ | `envsafe push [projet]` | - | Envoyer les variables |
130
+ | `envsafe run [projet] <cmd>` | - | Exécuter avec injection |
131
+ | `envsafe projects` | - | Lister tous les projets (global) |
132
+ | `envsafe config` | - | Gérer la configuration |
155
133
 
156
- ```bash
157
- envsafe logout
158
- ```
134
+ ## Options d'environnement
159
135
 
160
- ---
136
+ Les commandes `pull`, `push` et `run` supportent ces raccourcis :
161
137
 
162
- ### `envsafe config`
138
+ | Option | Environnement |
139
+ |--------|---------------|
140
+ | `-d`, `--dev` | development |
141
+ | `-s`, `--staging` | staging |
142
+ | `-p`, `--prod` | production |
143
+ | `-e <env>` | personnalisé |
163
144
 
164
- Gérez la configuration de la CLI.
145
+ ## Fichier .envsafe
165
146
 
166
- ```bash
167
- # Afficher la configuration actuelle
168
- envsafe config --show
147
+ Le fichier `.envsafe` stocke la configuration locale du projet :
169
148
 
170
- # Changer l'URL de l'API (pour instances self-hosted)
171
- envsafe config --api-url https://votre-instance.com
149
+ ```json
150
+ {
151
+ "workspace": "mon-workspace",
152
+ "project": "mon-projet"
153
+ }
172
154
  ```
173
155
 
174
- ---
156
+ > **Conseil :** Ajoutez `.envsafe` à votre `.gitignore` si vous ne voulez pas partager cette configuration.
175
157
 
176
- ## 🔧 Utilisation en CI/CD
158
+ ## CI/CD
177
159
 
178
- ### Méthode recommandée : Variable d'environnement
160
+ Dans les environnements automatisés, utilisez la variable `ENVSAFE_TOKEN` :
179
161
 
180
- Définissez `ENVSAFE_TOKEN` comme secret dans votre CI/CD, puis utilisez directement les commandes sans `login`.
162
+ ```bash
163
+ export ENVSAFE_TOKEN=your-token-here
164
+ envsafe pull mon-projet -p
165
+ ```
181
166
 
182
- #### GitHub Actions
167
+ ### GitHub Actions
183
168
 
184
169
  ```yaml
185
- name: Deploy
186
- on: [push]
187
-
188
170
  jobs:
189
171
  deploy:
190
172
  runs-on: ubuntu-latest
191
173
  steps:
192
174
  - uses: actions/checkout@v4
193
-
194
175
  - name: Install EnvSafe CLI
195
176
  run: npm install -g @envsafes-org/cli
196
-
197
- - name: Run tests with EnvSafe
198
- env:
199
- ENVSAFE_TOKEN: ${{ secrets.ENVSAFE_TOKEN }}
200
- run: |
201
- envsafe run mon-projet --env staging -- npm test
202
-
203
- - name: Deploy to production
177
+ - name: Pull secrets
204
178
  env:
205
179
  ENVSAFE_TOKEN: ${{ secrets.ENVSAFE_TOKEN }}
206
- run: |
207
- envsafe run mon-projet --env production -- npm run build
208
- envsafe run mon-projet --env production -- npm run deploy
180
+ run: envsafe pull mon-projet -p -o .env
209
181
  ```
210
182
 
211
- #### GitLab CI
183
+ ### GitLab CI
212
184
 
213
185
  ```yaml
214
186
  deploy:
215
- stage: deploy
216
187
  script:
217
188
  - npm install -g @envsafes-org/cli
218
- - envsafe run mon-projet --env production -- npm run deploy
189
+ - envsafe pull mon-projet -p -o .env
219
190
  variables:
220
- ENVSAFE_TOKEN: $ENVSAFE_TOKEN_SECRET
221
- ```
222
-
223
- #### Docker
224
-
225
- ```dockerfile
226
- FROM node:20-alpine
227
-
228
- # Installer la CLI
229
- RUN npm install -g @envsafes-org/cli
230
-
231
- WORKDIR /app
232
- COPY . .
233
-
234
- # Injecter les variables au démarrage
235
- CMD ["envsafe", "run", "mon-projet", "--env", "production", "--", "npm", "start"]
236
- ```
237
-
238
- ---
239
-
240
- ## 💡 Exemples d'utilisation
241
-
242
- ### Développement local
243
-
244
- ```bash
245
- # Option 1 : Fichier .env (traditionnel)
246
- envsafe pull mon-projet
247
- npm run dev
248
-
249
- # Option 2 : Injection directe (recommandé)
250
- envsafe run mon-projet -- npm run dev
251
- ```
252
-
253
- ### Script de déploiement
254
-
255
- ```bash
256
- #!/bin/bash
257
- # deploy.sh
258
-
259
- # Charger les variables de production et déployer
260
- envsafe run mon-projet --env production -- npm run build
261
- envsafe run mon-projet --env production -- npm run deploy
262
- ```
263
-
264
- ### Tests automatisés
265
-
266
- ```bash
267
- # Exécuter les tests avec les variables de staging
268
- envsafe run mon-projet --env staging -- npm test
191
+ ENVSAFE_TOKEN: $ENVSAFE_TOKEN
269
192
  ```
270
193
 
271
- ### Multi-environnements
194
+ ## Aide
272
195
 
273
196
  ```bash
274
- # Développement
275
- envsafe run mon-projet --env development -- npm run dev
276
-
277
- # Staging
278
- envsafe run mon-projet --env staging -- npm run build
279
-
280
- # Production
281
- envsafe run mon-projet --env production -- npm start
197
+ envsafe --help
198
+ envsafe <command> --help
282
199
  ```
283
200
 
284
- ---
285
-
286
- ## 🔐 Sécurité
287
-
288
- EnvSafe utilise une architecture de chiffrement de bout en bout :
289
-
290
- - **Chiffrement des variables** : AES-256-GCM
291
- - **Gestion des clés** : RSA-2048 avec chiffrement asymétrique
292
- - **Transport** : TLS 1.3
293
- - **Zero Knowledge** : Vos clés privées ne quittent jamais votre machine
294
-
295
- ### Bonnes pratiques
296
-
297
- ✅ **À faire :**
298
- - Utilisez `ENVSAFE_TOKEN` en CI/CD
299
- - Configurez des dates d'expiration pour vos tokens
300
- - Privilégiez `envsafe run` pour éviter les fichiers .env
301
- - Révoquez immédiatement les tokens compromis
302
-
303
- ❌ **À éviter :**
304
- - Ne commitez jamais vos tokens dans Git
305
- - N'utilisez pas `--token` en ligne de commande (visible dans l'historique)
306
- - Ne partagez pas vos tokens par email/Slack
307
-
308
- ---
309
-
310
- ## 🌍 Variables d'environnement
311
-
312
- | Variable | Description | Exemple |
313
- |----------|-------------|---------|
314
- | `ENVSAFE_TOKEN` | Token d'authentification (recommandé en CI/CD) | `es_live_xxx...` |
315
- | `ENVSAFE_API_URL` | URL de l'API (pour instances self-hosted) | `https://api.example.com` |
316
-
317
- ---
318
-
319
- ## 📚 Documentation complète
320
-
321
- Pour plus d'informations, consultez la [documentation officielle](https://www.envsafe.dev/docs).
322
-
323
- ---
324
-
325
- ## 🐛 Signaler un bug
326
-
327
- Si vous rencontrez un problème, [ouvrez une issue](https://github.com/Ifiboys/envsafe-cli/issues).
328
-
329
- ---
330
-
331
- ## 📄 Licence
332
-
333
- MIT © EnvSafe Team
334
-
335
- ---
336
-
337
- ## 🤝 Contribuer
201
+ ## Liens
338
202
 
339
- Les contributions sont les bienvenues ! Consultez notre [guide de contribution](CONTRIBUTING.md).
203
+ - 🌐 [Dashboard EnvSafe](https://www.envsafe.dev)
204
+ - 📖 [Documentation](https://www.envsafe.dev/docs)
205
+ - 🐛 [GitHub Issues](https://github.com/Ifiboys/envsafe-cli/issues)
340
206
 
341
- ---
207
+ ## Licence
342
208
 
343
- Made with ❤️ by the EnvSafe Team
209
+ MIT
@@ -0,0 +1 @@
1
+ export declare function create(projectName?: string): Promise<void>;
@@ -0,0 +1,84 @@
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.create = create;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const inquirer_1 = __importDefault(require("inquirer"));
9
+ const ora_1 = __importDefault(require("ora"));
10
+ const index_js_1 = require("../index.js");
11
+ const api_js_1 = require("../utils/api.js");
12
+ const config_js_1 = require("../utils/config.js");
13
+ async function create(projectName) {
14
+ const token = index_js_1.config.get("token");
15
+ if (!token) {
16
+ console.log(chalk_1.default.red("✗ Non connecté. Utilisez 'envsafe login' d'abord."));
17
+ return;
18
+ }
19
+ const localConfig = (0, config_js_1.readConfig)();
20
+ if (!localConfig?.workspace) {
21
+ console.log(chalk_1.default.yellow("⚠ Aucun workspace lié."));
22
+ console.log(chalk_1.default.dim(" Utilisez 'envsafe link <workspace>' d'abord."));
23
+ return;
24
+ }
25
+ let name = projectName;
26
+ let description;
27
+ if (!name) {
28
+ const answers = await inquirer_1.default.prompt([
29
+ {
30
+ type: "input",
31
+ name: "name",
32
+ message: "Nom du projet:",
33
+ validate: (input) => input.trim().length > 0 || "Le nom est requis",
34
+ },
35
+ {
36
+ type: "input",
37
+ name: "description",
38
+ message: "Description (optionnel):",
39
+ },
40
+ ]);
41
+ name = answers.name;
42
+ description = answers.description;
43
+ }
44
+ const spinner = (0, ora_1.default)(`Création du projet "${name}"...`).start();
45
+ try {
46
+ const response = await (0, api_js_1.apiRequest)(`/api/v1/workspaces/${localConfig.workspace}/projects`, {
47
+ method: "POST",
48
+ token,
49
+ body: {
50
+ name: name.trim(),
51
+ description: description?.trim() || undefined,
52
+ },
53
+ });
54
+ if (response.error) {
55
+ spinner.fail(chalk_1.default.red(response.error));
56
+ return;
57
+ }
58
+ spinner.succeed(chalk_1.default.green(`Projet "${response.project.name}" créé avec succès`));
59
+ console.log(chalk_1.default.dim(`\n Slug: ${response.project.slug}`));
60
+ console.log(chalk_1.default.dim(` Environnements: ${response.project.environments.join(", ")}`));
61
+ // Ask if user wants to select this project
62
+ const { selectProject } = await inquirer_1.default.prompt([
63
+ {
64
+ type: "confirm",
65
+ name: "selectProject",
66
+ message: "Sélectionner ce projet maintenant ?",
67
+ default: true,
68
+ },
69
+ ]);
70
+ if (selectProject) {
71
+ (0, config_js_1.writeConfig)({
72
+ ...localConfig,
73
+ project: response.project.slug,
74
+ });
75
+ console.log(chalk_1.default.green(`\n✓ Projet "${response.project.slug}" sélectionné`));
76
+ console.log(chalk_1.default.cyan("\n Commandes disponibles:"));
77
+ console.log(chalk_1.default.dim(" envsafe pull -d - Récupérer les variables (development)"));
78
+ console.log(chalk_1.default.dim(" envsafe push - Envoyer les variables"));
79
+ }
80
+ }
81
+ catch (error) {
82
+ spinner.fail(chalk_1.default.red(`Erreur: ${error.message}`));
83
+ }
84
+ }
@@ -0,0 +1 @@
1
+ export declare function init(): Promise<void>;