@elding/sdk 0.1.0 → 0.3.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/dist/index.d.ts +1 -0
- package/dist/index.js +4 -1
- package/dist/proxy.d.ts +23 -0
- package/dist/proxy.js +37 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EldingClient, type ClientOptions } from "./client.js";
|
|
2
2
|
export { EldingClient };
|
|
3
3
|
export type { ClientOptions };
|
|
4
|
+
export { proxyConfig, isProxyActive, type ProxyConfig } from "./proxy.js";
|
|
4
5
|
/**
|
|
5
6
|
* Crée un client Elding et charge tous les secrets du set configuré.
|
|
6
7
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EldingClient = void 0;
|
|
3
|
+
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; } });
|
|
7
|
+
var proxy_js_1 = require("./proxy.js");
|
|
8
|
+
Object.defineProperty(exports, "proxyConfig", { enumerable: true, get: function () { return proxy_js_1.proxyConfig; } });
|
|
9
|
+
Object.defineProperty(exports, "isProxyActive", { enumerable: true, get: function () { return proxy_js_1.isProxyActive; } });
|
|
7
10
|
/**
|
|
8
11
|
* Crée un client Elding et charge tous les secrets du set configuré.
|
|
9
12
|
*
|
package/dist/proxy.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type ProxyConfig = {
|
|
2
|
+
baseURL: string;
|
|
3
|
+
headers: Record<string, string>;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Retourne la config à passer à un SDK provider pour router via le proxy Elding.
|
|
7
|
+
* La vraie clé n'entre jamais dans votre process — utilisez le placeholder `{{NOM_SECRET}}`.
|
|
8
|
+
*
|
|
9
|
+
* Nécessite un lancement via `elding proxy -- <cmd>`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* import OpenAI from "openai";
|
|
13
|
+
* import { proxyConfig } from "@elding/sdk";
|
|
14
|
+
*
|
|
15
|
+
* const { baseURL, headers } = proxyConfig("https://api.openai.com");
|
|
16
|
+
* const openai = new OpenAI({
|
|
17
|
+
* apiKey: "{{OPENAI_API_KEY}}", // placeholder, jamais la vraie clé
|
|
18
|
+
* baseURL,
|
|
19
|
+
* defaultHeaders: headers,
|
|
20
|
+
* });
|
|
21
|
+
*/
|
|
22
|
+
export declare function proxyConfig(target: string): ProxyConfig;
|
|
23
|
+
export declare function isProxyActive(): boolean;
|
package/dist/proxy.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.proxyConfig = proxyConfig;
|
|
4
|
+
exports.isProxyActive = isProxyActive;
|
|
5
|
+
/**
|
|
6
|
+
* Retourne la config à passer à un SDK provider pour router via le proxy Elding.
|
|
7
|
+
* La vraie clé n'entre jamais dans votre process — utilisez le placeholder `{{NOM_SECRET}}`.
|
|
8
|
+
*
|
|
9
|
+
* Nécessite un lancement via `elding proxy -- <cmd>`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* import OpenAI from "openai";
|
|
13
|
+
* import { proxyConfig } from "@elding/sdk";
|
|
14
|
+
*
|
|
15
|
+
* const { baseURL, headers } = proxyConfig("https://api.openai.com");
|
|
16
|
+
* const openai = new OpenAI({
|
|
17
|
+
* apiKey: "{{OPENAI_API_KEY}}", // placeholder, jamais la vraie clé
|
|
18
|
+
* baseURL,
|
|
19
|
+
* defaultHeaders: headers,
|
|
20
|
+
* });
|
|
21
|
+
*/
|
|
22
|
+
function proxyConfig(target) {
|
|
23
|
+
const url = process.env.ELDING_PROXY_URL;
|
|
24
|
+
const token = process.env.ELDING_PROXY_TOKEN;
|
|
25
|
+
if (!url || !token)
|
|
26
|
+
throw new Error("[elding] Proxy non actif. Lancez via `elding proxy -- <cmd>`.");
|
|
27
|
+
return {
|
|
28
|
+
baseURL: url,
|
|
29
|
+
headers: {
|
|
30
|
+
"x-elding-token": token,
|
|
31
|
+
"x-elding-target": target,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function isProxyActive() {
|
|
36
|
+
return !!process.env.ELDING_PROXY_URL && !!process.env.ELDING_PROXY_TOKEN;
|
|
37
|
+
}
|