@elding/sdk 0.6.2 → 0.6.4

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.
Files changed (2) hide show
  1. package/README.md +66 -38
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,67 +1,95 @@
1
1
  # @elding/sdk
2
2
 
3
- Utilise tes clés API sans jamais les écrire dans ton code. Elding garde la clé
4
- hors de ton app : ton code manipule un placeholder, la vraie valeur est injectée
5
- au dernier moment et verrouillée à un seul domaine (anti-exfiltration).
3
+ Your API keys are never in your code or in a `.env` file. Elding keeps them, your code calls the API normally, and the real key is injected at the last moment.
4
+
5
+ **The same code works in dev and in prod.** You change nothing.
6
6
 
7
7
  ```bash
8
8
  npm install @elding/sdk
9
9
  ```
10
10
 
11
- ## Pour une clé API HTTP : `configure()`
11
+ > ⚠️ **Elding warning:** always use the **scoped** name `@elding/sdk`. `npm install elding` (without the `@elding/` scope) installs an unrelated third-party package, not Elding.
12
+
13
+ ## Quickstart (2 min)
14
+
15
+ ### 1. Sign in and choose your set
16
+
17
+ ```bash
18
+ npx elding login # opens the browser, signs you in
19
+ npx elding init # creates .elding.json (links this project to a set)
20
+ ```
21
+
22
+ ### 2. Write your code
12
23
 
13
- Utilise `configure()` pour **toute clé d'API HTTP** (OpenAI, Mistral, Stripe,
14
- Resend, etc.). Retourne de quoi faire un `fetch` normal, sans jamais exposer la clé.
24
+ `configure()` replaces your real key. 1st argument = the secret name in Elding, 2nd = the API domain.
15
25
 
16
26
  ```ts
27
+ import OpenAI from "openai";
17
28
  import { configure } from "@elding/sdk";
18
29
 
19
- // "MISTRAL_KEY" = nom du secret dans ton vault Elding.
20
- // 2e arg = le domaine de l'API (verrouillage anti-fuite).
21
- const { apiKey, baseURL } = await configure("MISTRAL_KEY", "https://api.mistral.ai");
30
+ const openai = new OpenAI(
31
+ await configure("OPENAI_API_KEY", "https://api.openai.com")
32
+ );
22
33
 
23
- const res = await fetch(`${baseURL}/v1/chat/completions`, {
24
- method: "POST",
25
- headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
26
- body: JSON.stringify({ model: "mistral-small-latest", messages: [...] }),
27
- });
34
+ // use openai normally, the real key is never in your code
28
35
  ```
29
36
 
30
- Important :
31
- - **Utilise toujours `baseURL`** dans ton `fetch`, jamais l'URL de l'API en dur.
32
- En dev, `baseURL` pointe vers le proxy local qui injecte la vraie clé.
33
- - Mets `apiKey` dans un **header** (`Authorization`, `x-api-key`…), jamais dans l'URL.
34
- - `configure()` est réservé aux **API HTTP**. Pour autre chose, voir `secret()`.
37
+ ### 3. Run
35
38
 
36
- ## Pour un secret non-HTTP : `secret()`
39
+ ```bash
40
+ npx elding proxy -- npm run dev
41
+ ```
37
42
 
38
- `DATABASE_URL`, `REDIS_URL`, `JWT_SECRET`… tout ce qui n'est pas une API HTTP.
39
- Retourne la valeur brute. Jamais dans `process.env`, effacée de la mémoire après
40
- 5 min (réglable via `ELDING_CACHE_TTL_MS`).
43
+ That's it. The key **never** enters your application.
41
44
 
42
- ```ts
43
- import { secret } from "@elding/sdk";
45
+ ## In production (Vercel, server, CI)
44
46
 
45
- const dbUrl = await secret("DATABASE_URL");
47
+ No proxy in prod. Elding fetches the key at runtime. **You don't change your code**, you just add **2 environment variables**:
48
+
49
+ ```bash
50
+ ELDING_REFRESH_TOKEN=eld_rt_... # generate it in the dashboard → API keys
51
+ ELDING_SET_ID=... # your set's id (set page)
46
52
  ```
47
53
 
48
- ## Plusieurs secrets d'un coup : `client()`
54
+ And... that's all. The same `configure("OPENAI_API_KEY", "https://api.openai.com")` works.
55
+
56
+ > The SDK reads these 2 variables automatically. Keep these exact names (`ELDING_REFRESH_TOKEN`, `ELDING_SET_ID`) and you have **no option** to pass.
57
+
58
+ ### How to get the 2 keys
59
+
60
+ | Variable | Where to find it |
61
+ |---|---|
62
+ | `ELDING_REFRESH_TOKEN` | Dashboard → **API keys** → New key (shown only once) |
63
+ | `ELDING_SET_ID` | Open your set in the dashboard, the id is in the URL |
64
+
65
+ ## The 2 functions
66
+
67
+ **`configure(name, domain)`** — for any **HTTP API** key (OpenAI, Mistral, Stripe, Resend…).
68
+ You pass it directly to the provider's SDK:
49
69
 
50
70
  ```ts
51
- import { client } from "@elding/sdk";
71
+ const openai = new OpenAI(await configure("OPENAI_API_KEY", "https://api.openai.com"));
72
+ ```
73
+
74
+ **`secret(name)`** — for everything **else** (`DATABASE_URL`, `JWT_SECRET`, `REDIS_URL`…).
75
+ Returns the raw value, wiped from memory after 5 min.
52
76
 
53
- const elding = await client();
54
- const dbUrl = elding.secret("DATABASE_URL");
77
+ ```ts
78
+ import { secret } from "@elding/sdk";
79
+ const dbUrl = await secret("DATABASE_URL");
55
80
  ```
56
81
 
57
- ## Règle simple
82
+ ## Dev vs prod, at a glance
58
83
 
59
- - Clé qui part dans une **requête HTTP** → `configure(nom, "https://api.exemple.com")`.
60
- - N'importe quel **autre secret** → `secret(nom)`.
61
- - **Jamais** de clé en dur, jamais dans `process.env`, jamais dans l'URL.
84
+ | | Dev | Prod |
85
+ |---|---|---|
86
+ | Command | `elding proxy -- npm run dev` | `npm run build && npm start` |
87
+ | Mechanism | local proxy | runtime fetch |
88
+ | To configure | `elding login` + `elding init` | `ELDING_REFRESH_TOKEN` + `ELDING_SET_ID` |
89
+ | Your code | identical | **identical** |
62
90
 
63
- ## Dev vs prod
91
+ ## Rules
64
92
 
65
- - **Dev** (`elding proxy -- npm run dev`) : la clé n'entre jamais dans ton process.
66
- - **Prod** (serverless) : la clé est récupérée du vault au runtime. Elle reste
67
- verrouillée au domaine, surveillée, révocable en un clic.
93
+ - **Never** hardcode a key, never in `process.env`, never in the URL.
94
+ - A key that goes into an HTTP request `configure(name, "https://…")`.
95
+ - Any other secret `secret(name)`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elding/sdk",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "Elding SDK — accès aux secrets depuis le code, zéro .env",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",