@elding/sdk 0.4.0 → 0.4.2
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/dist/apiUrl.js +1 -1
- package/dist/config.js +19 -4
- package/dist/configure.d.ts +7 -8
- package/dist/configure.js +30 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/package.json +5 -2
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://
|
|
8
|
+
const DEFAULT_BASE_URL = "https://elding-dev.vercel.app";
|
|
9
9
|
function stripBrackets(hostname) {
|
|
10
10
|
return hostname.startsWith("[") && hostname.endsWith("]")
|
|
11
11
|
? hostname.slice(1, -1)
|
package/dist/config.js
CHANGED
|
@@ -9,18 +9,33 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
9
9
|
const os_1 = __importDefault(require("os"));
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
11
|
const REFRESH_TOKEN = /^eld_rt_[a-f0-9]{64}$/i;
|
|
12
|
-
|
|
12
|
+
// Le CLI stocke le token dans le trousseau OS ; le fichier ne sert que de
|
|
13
|
+
// fallback (CI, headless). On lit donc le trousseau en priorite.
|
|
14
|
+
function tokenFromKeychain() {
|
|
15
|
+
try {
|
|
16
|
+
const { Entry } = require("@napi-rs/keyring");
|
|
17
|
+
return new Entry("elding", "refresh-token").getPassword();
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function tokenFromFile() {
|
|
13
24
|
try {
|
|
14
25
|
const file = path_1.default.join(os_1.default.homedir(), ".elding", "config.json");
|
|
15
26
|
const parsed = JSON.parse(fs_1.default.readFileSync(file, "utf-8"));
|
|
16
|
-
|
|
17
|
-
return null;
|
|
18
|
-
return { refreshToken: parsed.refreshToken };
|
|
27
|
+
return parsed.refreshToken ?? null;
|
|
19
28
|
}
|
|
20
29
|
catch {
|
|
21
30
|
return null;
|
|
22
31
|
}
|
|
23
32
|
}
|
|
33
|
+
function readGlobalConfig() {
|
|
34
|
+
const token = tokenFromKeychain() ?? tokenFromFile();
|
|
35
|
+
if (!token || !REFRESH_TOKEN.test(token))
|
|
36
|
+
return null;
|
|
37
|
+
return { refreshToken: token };
|
|
38
|
+
}
|
|
24
39
|
function readProjectConfig() {
|
|
25
40
|
try {
|
|
26
41
|
const parsed = JSON.parse(fs_1.default.readFileSync(".elding.json", "utf-8"));
|
package/dist/configure.d.ts
CHANGED
|
@@ -4,15 +4,14 @@ export type ProviderConfig = {
|
|
|
4
4
|
baseURL?: string;
|
|
5
5
|
defaultHeaders?: Record<string, string>;
|
|
6
6
|
};
|
|
7
|
+
export declare function configure(secretName: string, target: string, options?: ClientOptions): Promise<ProviderConfig>;
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* (
|
|
9
|
+
* Récupère la VALEUR BRUTE d'un secret (DATABASE_URL, config, secrets non-HTTP).
|
|
10
|
+
* La valeur entre en mémoire du process : non protégée par le proxy, à l'inverse
|
|
11
|
+
* de configure(). À réserver aux secrets qui ne passent pas par une API HTTP.
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
13
|
-
* import
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* const openai = new OpenAI(await configure("OPENAI_API_KEY", "https://api.openai.com"));
|
|
14
|
+
* import { secret } from "@elding/sdk";
|
|
15
|
+
* const dbUrl = await secret("DATABASE_URL");
|
|
17
16
|
*/
|
|
18
|
-
export declare function
|
|
17
|
+
export declare function secret(name: string, options?: ClientOptions): Promise<string>;
|
package/dist/configure.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.configure = configure;
|
|
4
|
+
exports.secret = secret;
|
|
4
5
|
const proxy_js_1 = require("./proxy.js");
|
|
5
6
|
const client_js_1 = require("./client.js");
|
|
6
7
|
const SECRET_NAME = /^[A-Z0-9_]+$/;
|
|
@@ -22,9 +23,23 @@ function getClient(options) {
|
|
|
22
23
|
*
|
|
23
24
|
* const openai = new OpenAI(await configure("OPENAI_API_KEY", "https://api.openai.com"));
|
|
24
25
|
*/
|
|
26
|
+
function isHttpTarget(target) {
|
|
27
|
+
try {
|
|
28
|
+
const u = new URL(target);
|
|
29
|
+
return u.protocol === "https:" || u.protocol === "http:";
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
25
35
|
async function configure(secretName, target, options = {}) {
|
|
26
36
|
if (!SECRET_NAME.test(secretName))
|
|
27
37
|
throw new Error("[elding] Nom de secret invalide (A-Z, 0-9, _).");
|
|
38
|
+
// configure() protège uniquement les API HTTP via le proxy. Pour une valeur
|
|
39
|
+
// non-HTTP (DATABASE_URL, config...), le proxy ne peut rien intercepter :
|
|
40
|
+
// on guide vers secret() plutot que de renvoyer une valeur faussement "protégée".
|
|
41
|
+
if (!isHttpTarget(target))
|
|
42
|
+
throw new Error(`[elding] configure() attend une API HTTP. Pour "${secretName}" (non-HTTP, ex. DATABASE_URL), utilise secret("${secretName}") — valeur brute, jamais protégée par le proxy.`);
|
|
28
43
|
// Mode proxy (dev) : placeholder, la vraie clé n'entre jamais dans le process.
|
|
29
44
|
if ((0, proxy_js_1.isProxyActive)()) {
|
|
30
45
|
const { baseURL, headers } = (0, proxy_js_1.proxyConfig)(target);
|
|
@@ -34,3 +49,18 @@ async function configure(secretName, target, options = {}) {
|
|
|
34
49
|
const elding = await getClient(options);
|
|
35
50
|
return { apiKey: elding.secret(secretName) };
|
|
36
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Récupère la VALEUR BRUTE d'un secret (DATABASE_URL, config, secrets non-HTTP).
|
|
54
|
+
* La valeur entre en mémoire du process : non protégée par le proxy, à l'inverse
|
|
55
|
+
* de configure(). À réserver aux secrets qui ne passent pas par une API HTTP.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* import { secret } from "@elding/sdk";
|
|
59
|
+
* const dbUrl = await secret("DATABASE_URL");
|
|
60
|
+
*/
|
|
61
|
+
async function secret(name, options = {}) {
|
|
62
|
+
if (!SECRET_NAME.test(name))
|
|
63
|
+
throw new Error("[elding] Nom de secret invalide (A-Z, 0-9, _).");
|
|
64
|
+
const elding = await getClient(options);
|
|
65
|
+
return elding.secret(name);
|
|
66
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { EldingClient, type ClientOptions } from "./client.js";
|
|
|
2
2
|
export { EldingClient };
|
|
3
3
|
export type { ClientOptions };
|
|
4
4
|
export { proxyConfig, isProxyActive, type ProxyConfig } from "./proxy.js";
|
|
5
|
-
export { configure, type ProviderConfig } from "./configure.js";
|
|
5
|
+
export { configure, secret, type ProviderConfig } from "./configure.js";
|
|
6
6
|
/**
|
|
7
7
|
* Crée un client Elding et charge tous les secrets du set configuré.
|
|
8
8
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.configure = exports.isProxyActive = exports.proxyConfig = exports.EldingClient = void 0;
|
|
3
|
+
exports.secret = exports.configure = exports.isProxyActive = exports.proxyConfig = exports.EldingClient = void 0;
|
|
4
4
|
exports.client = client;
|
|
5
5
|
const client_js_1 = require("./client.js");
|
|
6
6
|
Object.defineProperty(exports, "EldingClient", { enumerable: true, get: function () { return client_js_1.EldingClient; } });
|
|
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "proxyConfig", { enumerable: true, get: function
|
|
|
9
9
|
Object.defineProperty(exports, "isProxyActive", { enumerable: true, get: function () { return proxy_js_1.isProxyActive; } });
|
|
10
10
|
var configure_js_1 = require("./configure.js");
|
|
11
11
|
Object.defineProperty(exports, "configure", { enumerable: true, get: function () { return configure_js_1.configure; } });
|
|
12
|
+
Object.defineProperty(exports, "secret", { enumerable: true, get: function () { return configure_js_1.secret; } });
|
|
12
13
|
/**
|
|
13
14
|
* Crée un client Elding et charge tous les secrets du set configuré.
|
|
14
15
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elding/sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
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",
|
|
@@ -23,5 +23,8 @@
|
|
|
23
23
|
"engines": {
|
|
24
24
|
"node": ">=18"
|
|
25
25
|
},
|
|
26
|
-
"license": "MIT"
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@napi-rs/keyring": "1.1.7"
|
|
29
|
+
}
|
|
27
30
|
}
|