@elding/sdk 0.6.1 → 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.
- package/README.md +66 -38
- package/dist/apiUrl.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,67 +1,95 @@
|
|
|
1
1
|
# @elding/sdk
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
const openai = new OpenAI(
|
|
31
|
+
await configure("OPENAI_API_KEY", "https://api.openai.com")
|
|
32
|
+
);
|
|
22
33
|
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
|
|
39
|
+
```bash
|
|
40
|
+
npx elding proxy -- npm run dev
|
|
41
|
+
```
|
|
37
42
|
|
|
38
|
-
|
|
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
|
-
|
|
43
|
-
import { secret } from "@elding/sdk";
|
|
45
|
+
## In production (Vercel, server, CI)
|
|
44
46
|
|
|
45
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
54
|
-
|
|
77
|
+
```ts
|
|
78
|
+
import { secret } from "@elding/sdk";
|
|
79
|
+
const dbUrl = await secret("DATABASE_URL");
|
|
55
80
|
```
|
|
56
81
|
|
|
57
|
-
##
|
|
82
|
+
## Dev vs prod, at a glance
|
|
58
83
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
##
|
|
91
|
+
## Rules
|
|
64
92
|
|
|
65
|
-
- **
|
|
66
|
-
-
|
|
67
|
-
|
|
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/dist/apiUrl.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.resolveBaseUrl = resolveBaseUrl;
|
|
7
7
|
const net_1 = __importDefault(require("net"));
|
|
8
|
-
const DEFAULT_BASE_URL = "https://elding
|
|
8
|
+
const DEFAULT_BASE_URL = "https://elding.app";
|
|
9
9
|
function stripBrackets(hostname) {
|
|
10
10
|
return hostname.startsWith("[") && hostname.endsWith("]")
|
|
11
11
|
? hostname.slice(1, -1)
|