cyberdesk 0.1.3 → 0.2.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/README.md CHANGED
@@ -16,74 +16,88 @@ pnpm add cyberdesk
16
16
 
17
17
  ## Usage
18
18
 
19
- First, configure the client, for example, by setting default headers for authentication. You only need to do this once.
19
+ First, create a Cyberdesk client instance with your API key:
20
20
 
21
21
  ```typescript
22
- import { client, setConfig } from 'cyberdesk/client'; // Import client and setConfig
22
+ import { createCyberdeskClient } from 'cyberdesk';
23
23
 
24
- // Configure the client (e.g., with an API Key)
25
- // Adjust based on your actual authentication method
26
- setConfig({
27
- headers: {
28
- 'Authorization': `Bearer YOUR_API_KEY`
24
+ const cyberdesk = createCyberdeskClient({
25
+ apiKey: 'YOUR_API_KEY',
26
+ // Optionally, you can override the baseUrl or provide a custom fetch implementation
27
+ });
28
+ ```
29
+
30
+ ### Launch a Desktop
31
+
32
+ ```typescript
33
+ const launchResult = await cyberdesk.launchDesktop({
34
+ body: { timeout_ms: 10000 } // Optional: set a timeout for the desktop session
35
+ });
36
+
37
+ if (launchResult.error) {
38
+ throw new Error('Failed to launch desktop: ' + launchResult.error.error);
39
+ }
40
+
41
+ const desktopId = launchResult.id;
42
+ console.log('Launched desktop with ID:', desktopId);
43
+ ```
44
+
45
+ ### Get Desktop Info
46
+
47
+ ```typescript
48
+ const info = await cyberdesk.getDesktop({
49
+ path: { id: desktopId }
50
+ });
51
+
52
+ if ('error' in info) {
53
+ throw new Error('Failed to get desktop info: ' + info.error);
54
+ }
55
+
56
+ console.log('Desktop info:', info);
57
+ ```
58
+
59
+ ### Perform a Computer Action (e.g., Mouse Click)
60
+
61
+ ```typescript
62
+ const actionResult = await cyberdesk.executeComputerAction({
63
+ path: { id: desktopId },
64
+ body: {
65
+ type: 'click_mouse',
66
+ x: 100,
67
+ y: 150
29
68
  }
30
69
  });
70
+
71
+ if (actionResult.error) {
72
+ throw new Error('Action failed: ' + actionResult.error);
73
+ }
74
+
75
+ console.log('Action result:', actionResult);
31
76
  ```
32
77
 
33
- Then, import and call the specific API functions you need:
78
+ ### Run a Bash Command
34
79
 
35
80
  ```typescript
36
- import {
37
- postV1Desktop,
38
- postV1DesktopIdComputerAction,
39
- type PostV1DesktopData,
40
- type PostV1DesktopIdComputerActionData
41
- } from 'cyberdesk';
42
-
43
- async function createAndInteract() {
44
- try {
45
- // 1. Create a new desktop
46
- console.log('Creating desktop...');
47
- const createResponse = await postV1Desktop({
48
- // Pass request body parameters inside the 'data' object
49
- data: {
50
- timeoutMs: 10000
51
- }
52
- // Headers like Authorization should be set globally via setConfig (see above)
53
- });
54
-
55
- if (!createResponse.data) {
56
- throw new Error('Failed to create desktop: ' + (createResponse.error?.message || 'Unknown error'));
57
- }
58
-
59
- const desktopId = createResponse.data.id; // Assuming the response has an ID
60
- console.log(`Desktop created with ID: ${desktopId}`);
61
-
62
- // 2. Perform an action (e.g., a mouse click)
63
- console.log(`Performing action on desktop ${desktopId}...`);
64
- const actionData: PostV1DesktopIdComputerActionData['data'] = {
65
- type: 'click_mouse', // Example action type
66
- x: 100,
67
- y: 150
68
- };
69
-
70
- const actionResponse = await postV1DesktopIdComputerAction({
71
- path: { id: desktopId }, // Provide path parameters
72
- data: actionData // Provide request body data
73
- });
74
-
75
- if (actionResponse.error) {
76
- throw new Error(`Action failed: ${actionResponse.error.message}`);
77
- }
78
-
79
- console.log('Action successful:', actionResponse.data);
80
-
81
- } catch (error) {
82
- console.error('Error using Cyberdesk SDK:', error);
81
+ const bashResult = await cyberdesk.executeBashAction({
82
+ path: { id: desktopId },
83
+ body: {
84
+ command: 'echo Hello, world!'
83
85
  }
86
+ });
87
+
88
+ if (bashResult.error) {
89
+ throw new Error('Bash command failed: ' + bashResult.error);
84
90
  }
85
91
 
86
- createAndInteract();
92
+ console.log('Bash output:', bashResult.output);
93
+ ```
94
+
95
+ ## TypeScript Support
96
+
97
+ All request parameter types and the `CyberdeskSDK` type are exported for convenience:
98
+
99
+ ```typescript
100
+ import type { LaunchDesktopParams, CyberdeskSDK } from 'cyberdesk';
87
101
  ```
88
102
 
89
103
  ## License
@@ -9,7 +9,7 @@ const client_gen_1 = require("./client.gen");
9
9
  */
10
10
  const getV1DesktopId = (options) => {
11
11
  var _a;
12
- return ((_a = options.client) !== null && _a !== void 0 ? _a : client_gen_1.client).get(Object.assign({ url: '/v1/desktop/:id' }, options));
12
+ return ((_a = options.client) !== null && _a !== void 0 ? _a : client_gen_1.client).get(Object.assign({ url: '/v1/desktop/{id}' }, options));
13
13
  };
14
14
  exports.getV1DesktopId = getV1DesktopId;
15
15
  /**
@@ -27,7 +27,7 @@ exports.postV1Desktop = postV1Desktop;
27
27
  */
28
28
  const postV1DesktopIdStop = (options) => {
29
29
  var _a;
30
- return ((_a = options.client) !== null && _a !== void 0 ? _a : client_gen_1.client).post(Object.assign({ url: '/v1/desktop/:id/stop' }, options));
30
+ return ((_a = options.client) !== null && _a !== void 0 ? _a : client_gen_1.client).post(Object.assign({ url: '/v1/desktop/{id}/stop' }, options));
31
31
  };
32
32
  exports.postV1DesktopIdStop = postV1DesktopIdStop;
33
33
  /**
@@ -36,7 +36,7 @@ exports.postV1DesktopIdStop = postV1DesktopIdStop;
36
36
  */
37
37
  const postV1DesktopIdComputerAction = (options) => {
38
38
  var _a;
39
- return ((_a = options.client) !== null && _a !== void 0 ? _a : client_gen_1.client).post(Object.assign(Object.assign({ url: '/v1/desktop/:id/computer-action' }, options), { headers: Object.assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers) }));
39
+ return ((_a = options.client) !== null && _a !== void 0 ? _a : client_gen_1.client).post(Object.assign(Object.assign({ url: '/v1/desktop/{id}/computer-action' }, options), { headers: Object.assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers) }));
40
40
  };
41
41
  exports.postV1DesktopIdComputerAction = postV1DesktopIdComputerAction;
42
42
  /**
@@ -45,6 +45,6 @@ exports.postV1DesktopIdComputerAction = postV1DesktopIdComputerAction;
45
45
  */
46
46
  const postV1DesktopIdBashAction = (options) => {
47
47
  var _a;
48
- return ((_a = options.client) !== null && _a !== void 0 ? _a : client_gen_1.client).post(Object.assign(Object.assign({ url: '/v1/desktop/:id/bash-action' }, options), { headers: Object.assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers) }));
48
+ return ((_a = options.client) !== null && _a !== void 0 ? _a : client_gen_1.client).post(Object.assign(Object.assign({ url: '/v1/desktop/{id}/bash-action' }, options), { headers: Object.assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers) }));
49
49
  };
50
50
  exports.postV1DesktopIdBashAction = postV1DesktopIdBashAction;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { createClient, type Options as ClientOptions } from '@hey-api/client-fetch';
1
+ import { type Options as ClientOptions } from '@hey-api/client-fetch';
2
2
  import * as apiMethods from './client/sdk.gen';
3
- export * from './client/types.gen';
4
3
  import { type GetV1DesktopIdData, type PostV1DesktopData, type PostV1DesktopIdStopData, type PostV1DesktopIdComputerActionData, type PostV1DesktopIdBashActionData } from './client/types.gen';
5
4
  type FetchFn = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
6
5
  /**
@@ -16,12 +15,17 @@ export interface CyberdeskClientOptions {
16
15
  /** Optional: Provide additional default options for the underlying client (e.g., timeout, keepalive). */
17
16
  clientOptions?: Partial<ClientOptions>;
18
17
  }
19
- export type CyberdeskSdk = {
20
- getDesktopInfo: (opts: Omit<GetV1DesktopIdData, 'headers' | 'url'>) => ReturnType<typeof apiMethods.getV1DesktopId>;
21
- launchDesktop: (opts: Omit<PostV1DesktopData, 'headers' | 'url'>) => ReturnType<typeof apiMethods.postV1Desktop>;
22
- terminateDesktop: (opts: Omit<PostV1DesktopIdStopData, 'headers' | 'url'>) => ReturnType<typeof apiMethods.postV1DesktopIdStop>;
23
- executeActionOnDesktop: (opts: Omit<PostV1DesktopIdComputerActionData, 'headers' | 'url'>) => ReturnType<typeof apiMethods.postV1DesktopIdComputerAction>;
24
- bashCommandOnDesktop: (opts: Omit<PostV1DesktopIdBashActionData, 'headers' | 'url'>) => ReturnType<typeof apiMethods.postV1DesktopIdBashAction>;
18
+ export type GetDesktopParams = Omit<GetV1DesktopIdData, 'headers' | 'url'>;
19
+ export type LaunchDesktopParams = Omit<PostV1DesktopData, 'headers' | 'url'>;
20
+ export type TerminateDesktopParams = Omit<PostV1DesktopIdStopData, 'headers' | 'url'>;
21
+ export type ExecuteComputerActionParams = Omit<PostV1DesktopIdComputerActionData, 'headers' | 'url'>;
22
+ export type ExecuteBashActionParams = Omit<PostV1DesktopIdBashActionData, 'headers' | 'url'>;
23
+ export type CyberdeskSDK = {
24
+ getDesktop: (opts: GetDesktopParams) => ReturnType<typeof apiMethods.getV1DesktopId>;
25
+ launchDesktop: (opts: LaunchDesktopParams) => ReturnType<typeof apiMethods.postV1Desktop>;
26
+ terminateDesktop: (opts: TerminateDesktopParams) => ReturnType<typeof apiMethods.postV1DesktopIdStop>;
27
+ executeComputerAction: (opts: ExecuteComputerActionParams) => ReturnType<typeof apiMethods.postV1DesktopIdComputerAction>;
28
+ executeBashAction: (opts: ExecuteBashActionParams) => ReturnType<typeof apiMethods.postV1DesktopIdBashAction>;
25
29
  };
26
30
  /**
27
31
  * Creates a Cyberdesk SDK instance configured with your API key.
@@ -29,6 +33,5 @@ export type CyberdeskSdk = {
29
33
  * @param options - Configuration options including the API key.
30
34
  * @returns An SDK instance with methods ready to be called.
31
35
  */
32
- export declare function createCyberdeskClient(options: CyberdeskClientOptions): CyberdeskSdk;
33
- export { createClient };
34
- export * as rawApiMethods from './client/sdk.gen';
36
+ export declare function createCyberdeskClient(options: CyberdeskClientOptions): CyberdeskSDK;
37
+ export {};
package/dist/index.js CHANGED
@@ -33,18 +33,11 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  return result;
34
34
  };
35
35
  })();
36
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
37
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
38
- };
39
36
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.rawApiMethods = exports.createClient = void 0;
41
37
  exports.createCyberdeskClient = createCyberdeskClient;
42
38
  const client_fetch_1 = require("@hey-api/client-fetch");
43
- Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_fetch_1.createClient; } });
44
- const apiMethods = __importStar(require("./client/sdk.gen")); // Import the generated methods
45
- // Re-export all types from types.gen for user convenience
46
- __exportStar(require("./client/types.gen"), exports);
47
- const DEFAULT_BASE_URL = 'https://api.cyberdesk.io'; // Replace if needed
39
+ const apiMethods = __importStar(require("./client/sdk.gen"));
40
+ const DEFAULT_BASE_URL = 'https://api.cyberdesk.io';
48
41
  /**
49
42
  * Creates a Cyberdesk SDK instance configured with your API key.
50
43
  *
@@ -56,29 +49,16 @@ function createCyberdeskClient(options) {
56
49
  if (!apiKey) {
57
50
  throw new Error('Cyberdesk SDK requires an `apiKey` to be provided.');
58
51
  }
59
- // Ensure baseUrl is string | undefined before use
60
52
  const finalBaseUrl = baseUrl;
61
- // Prepare headers, merging defaults with any provided in clientOptions
62
53
  const mergedHeaders = Object.assign({ 'x-api-key': apiKey, 'Content-Type': 'application/json' }, (clientOptions.headers || {}));
63
- // Construct the final options for createClient explicitly
64
- const finalClientOptions = Object.assign({
65
- // Set base URL
66
- baseUrl: finalBaseUrl,
67
- // Set merged headers
68
- headers: mergedHeaders }, (customFetch && { fetch: customFetch }));
69
- // Pass the inferred options object directly
54
+ const finalClientOptions = Object.assign({ baseUrl: finalBaseUrl, headers: mergedHeaders }, (customFetch && { fetch: customFetch }));
70
55
  const configuredClient = (0, client_fetch_1.createClient)(finalClientOptions);
71
56
  // Return an object where each method is pre-configured with the client instance
72
57
  return {
73
- getDesktopInfo: (opts) => apiMethods.getV1DesktopId(Object.assign(Object.assign({}, opts), { client: configuredClient,
74
- // Merge client headers with potentially provided headers from opts
75
- headers: Object.assign(Object.assign({}, mergedHeaders), opts.headers) })),
58
+ getDesktop: (opts) => apiMethods.getV1DesktopId(Object.assign(Object.assign({}, opts), { client: configuredClient, headers: Object.assign(Object.assign({}, mergedHeaders), opts.headers) })),
76
59
  launchDesktop: (opts) => apiMethods.postV1Desktop(Object.assign(Object.assign({}, opts), { client: configuredClient, headers: Object.assign(Object.assign({}, mergedHeaders), opts.headers) })),
77
- terminateDesktop: (opts) => apiMethods.postV1DesktopIdStop(Object.assign(Object.assign({}, opts), { client: configuredClient, headers: Object.assign(Object.assign({}, mergedHeaders), opts.headers) })),
78
- executeActionOnDesktop: (opts) => apiMethods.postV1DesktopIdComputerAction(Object.assign(Object.assign({}, opts), { client: configuredClient, headers: Object.assign(Object.assign({}, mergedHeaders), opts.headers) })),
79
- bashCommandOnDesktop: (opts) => apiMethods.postV1DesktopIdBashAction(Object.assign(Object.assign({}, opts), { client: configuredClient, headers: Object.assign(Object.assign({}, mergedHeaders), opts.headers) })),
80
- // Add bindings for other generated methods here following the same pattern
60
+ terminateDesktop: (opts) => apiMethods.postV1DesktopIdStop(Object.assign(Object.assign({}, opts), { path: Object.assign(Object.assign({}, opts.path), { id: opts.path.id }), client: configuredClient, headers: Object.assign(Object.assign({}, mergedHeaders), opts.headers) })),
61
+ executeComputerAction: (opts) => apiMethods.postV1DesktopIdComputerAction(Object.assign(Object.assign({}, opts), { client: configuredClient, headers: Object.assign(Object.assign({}, mergedHeaders), opts.headers) })),
62
+ executeBashAction: (opts) => apiMethods.postV1DesktopIdBashAction(Object.assign(Object.assign({}, opts), { client: configuredClient, headers: Object.assign(Object.assign({}, mergedHeaders), opts.headers) })),
81
63
  };
82
64
  }
83
- // Optional: Export the underlying api methods if needed, though usually accessed via the sdk instance
84
- exports.rawApiMethods = __importStar(require("./client/sdk.gen"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cyberdesk",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "The official TypeScript SDK for Cyberdesk",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,7 +10,7 @@
10
10
  "README.md"
11
11
  ],
12
12
  "scripts": {
13
- "generate": "openapi-ts",
13
+ "generate": "openapi-ts && node scripts/fix-routes.js",
14
14
  "build": "npm run generate && tsc",
15
15
  "prepublishOnly": "npm run build"
16
16
  },