11<h1 align =" center " >
2- <code >@onecli-sdk/node </code >
2+ <code >@onecli-sh/sdk </code >
33</h1 >
44
55<p align =" center " >
1313</p >
1414
1515<p align =" center " >
16- <a href =" https://www.npmjs.com/package/@onecli-sdk/node " >
17- <img src="https://img.shields.io/npm/v/@onecli-sdk/node .svg" alt="npm version" />
16+ <a href =" https://www.npmjs.com/package/@onecli-sh/sdk " >
17+ <img src="https://img.shields.io/npm/v/@onecli-sh/sdk .svg" alt="npm version" />
1818 </a >
1919 <a href =" https://github.com/onecli/node-sdk/blob/main/LICENSE " >
2020 <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT License" />
2121 </a >
22- <a href =" https://www.npmjs.com/package/@onecli-sdk/node " >
23- <img src="https://img.shields.io/node/v/@onecli-sdk/node .svg" alt="Node.js version" />
22+ <a href =" https://www.npmjs.com/package/@onecli-sh/sdk " >
23+ <img src="https://img.shields.io/node/v/@onecli-sh/sdk .svg" alt="Node.js version" />
2424 </a >
2525</p >
2626
2929## Installation
3030
3131``` bash
32- pnpm add @onecli-sdk/node
32+ pnpm add @onecli-sh/sdk
3333```
3434
3535## Requirements
@@ -40,56 +40,44 @@ pnpm add @onecli-sdk/node
4040
4141## Quick Start
4242
43- ### Standalone function (simplest)
44-
45- A single function that fetches config from OneCLI and injects Docker flags:
46-
4743``` typescript
48- import { applyOneCLIConfig } from " @onecli-sdk/node " ;
44+ import { OneCLI } from " @onecli-sh/sdk " ;
4945
50- const args = [" run" , " -i" , " --rm" , " --name" , " my-agent" ];
51-
52- // Fetches container config and pushes -e / -v flags onto args
53- const active = await applyOneCLIConfig (args , process .env .ONECLI_KEY );
46+ // Reads ONECLI_API_KEY and ONECLI_URL from environment
47+ const onecli = new OneCLI ();
5448
49+ const args = [" run" , " -i" , " --rm" , " --name" , " my-agent" ];
50+ const active = await onecli .applyContainerConfig (args );
5551// args now contains proxy env vars and CA certificate mounts
5652console .log (active ); // true if OneCLI was reachable
5753```
5854
59- ### Class-based client
60-
61- For more control:
55+ ### Explicit configuration
6256
6357``` typescript
64- import { OneCLI } from " @onecli-sdk/node " ;
58+ import { OneCLI } from " @onecli-sh/sdk " ;
6559
66- const oc = new OneCLI ({
67- apiKey: " oc_..." , // required: from OneCLI dashboard
68- url: " http://localhost:3000" , // optional: defaults to https://app.onecli.sh
60+ const onecli = new OneCLI ({
61+ apiKey: " oc_..." , // optional: falls back to ONECLI_API_KEY env var
62+ url: " http://localhost:3000" , // optional: falls back to ONECLI_URL env var, then https://app.onecli.sh
6963});
7064
7165// Get raw container configuration
72- const config = await oc .getContainerConfig ();
66+ const config = await onecli .getContainerConfig ();
7367console .log (config .env ); // { HTTPS_PROXY: "...", HTTP_PROXY: "...", ... }
7468console .log (config .caCertificate ); // PEM content
7569
7670// Or apply directly to Docker run args
7771const args = [" run" , " -i" , " --rm" , " my-image" ];
78- const active = await oc .applyContainerConfig (args );
72+ const active = await onecli .applyContainerConfig (args );
7973```
8074
81- ### Environment variable
82-
83- Instead of passing ` url ` explicitly, set the ` ONECLI_URL ` environment variable:
84-
85- ``` bash
86- export ONECLI_URL=http://localhost:3000
87- ```
75+ ### Environment variables
8876
89- ``` typescript
90- const oc = new OneCLI ({ apiKey: " oc_... " });
91- // Automatically reads from ONECLI_URL, falls back to https://app.onecli.sh
92- ```
77+ | Variable | Description |
78+ | ---------------- | -------------------------------------------------------- |
79+ | ` ONECLI_API_KEY ` | User API key ( ` oc_... ` ). Used when ` apiKey ` is not passed to constructor. |
80+ | ` ONECLI_URL ` | Base URL of OneCLI instance. Defaults to ` https://app.onecli.sh ` . |
9381
9482## API Reference
9583
@@ -98,32 +86,32 @@ const oc = new OneCLI({ apiKey: "oc_..." });
9886Main SDK client.
9987
10088``` typescript
101- new OneCLI (options : OneCLIOptions )
89+ new OneCLI (options ? : OneCLIOptions )
10290```
10391
10492| Option | Type | Required | Default | Description |
10593| --------- | -------- | -------- | ----------------------------------- | ------------------------------- |
106- | ` apiKey ` | ` string ` | Yes | — | User API key (` oc_... ` ) |
94+ | ` apiKey ` | ` string ` | No | ` ONECLI_API_KEY ` env var | User API key (` oc_... ` ) |
10795| ` url ` | ` string ` | No | ` ONECLI_URL ` or ` https://app.onecli.sh ` | Base URL of the OneCLI instance |
10896| ` timeout ` | ` number ` | No | ` 5000 ` | Request timeout in milliseconds |
10997
110- #### ` oc .getContainerConfig()`
98+ #### ` onecli .getContainerConfig()`
11199
112100Fetch the raw container configuration from OneCLI.
113101
114102``` typescript
115- const config = await oc .getContainerConfig ();
103+ const config = await onecli .getContainerConfig ();
116104// Returns: { env, caCertificate, caCertificateContainerPath }
117105```
118106
119107** Throws** ` OneCLIRequestError ` on non-200 response.
120108
121- #### ` oc .applyContainerConfig(args, options?)`
109+ #### ` onecli .applyContainerConfig(args, options?)`
122110
123111Fetch config and push Docker flags onto the ` args ` array. Returns ` true ` on success, ` false ` on failure (graceful degradation).
124112
125113``` typescript
126- const active = await oc .applyContainerConfig (args , {
114+ const active = await onecli .applyContainerConfig (args , {
127115 combineCaBundle: true , // Merge system + OneCLI CAs (default: true)
128116 addHostMapping: true , // Add --add-host on Linux (default: true)
129117});
@@ -143,38 +131,25 @@ const active = await oc.applyContainerConfig(args, {
143131
144132---
145133
146- ### ` applyOneCLIConfig(args, apiKey, url?) `
147-
148- Standalone convenience function. Creates an ` OneCLI ` client internally.
149-
150- ``` typescript
151- import { applyOneCLIConfig } from " @onecli-sdk/node" ;
152-
153- const active = await applyOneCLIConfig (args , process .env .ONECLI_KEY );
154- // Pass undefined/null apiKey to skip (returns false immediately)
155- ```
156-
157- ---
158-
159134### Error Classes
160135
161136#### ` OneCLIError `
162137
163138General SDK error (e.g. missing ` apiKey ` ).
164139
165140``` typescript
166- import { OneCLIError } from " @onecli-sdk/node " ;
141+ import { OneCLIError } from " @onecli-sh/sdk " ;
167142```
168143
169144#### ` OneCLIRequestError `
170145
171146HTTP request error with ` url ` and ` statusCode ` properties.
172147
173148``` typescript
174- import { OneCLIRequestError } from " @onecli-sdk/node " ;
149+ import { OneCLIRequestError } from " @onecli-sh/sdk " ;
175150
176151try {
177- await oc .getContainerConfig ();
152+ await onecli .getContainerConfig ();
178153} catch (error ) {
179154 if (error instanceof OneCLIRequestError ) {
180155 console .error (error .url ); // Request URL
@@ -192,7 +167,7 @@ import type {
192167 OneCLIOptions ,
193168 ContainerConfig ,
194169 ApplyContainerConfigOptions ,
195- } from " @onecli-sdk/node " ;
170+ } from " @onecli-sh/sdk " ;
196171```
197172
198173## How It Works
0 commit comments