@elding/sdk 0.4.1 → 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/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 +1 -1
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/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
|
*
|