infrahub-sdk 0.0.8 → 0.0.9
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.js +30 -8
- package/dist/integration.test.d.ts +9 -0
- package/dist/integration.test.js +52 -0
- package/dist/rest.test.d.ts +1 -0
- package/dist/rest.test.js +930 -0
- package/package.json +1 -1
- package/src/index.ts +37 -13
- package/src/integration.test.ts +63 -0
- package/src/rest.test.ts +1107 -0
- package/test-schema.ts +76 -0
package/dist/index.js
CHANGED
|
@@ -35,7 +35,8 @@ class InfrahubClient {
|
|
|
35
35
|
this.defaultBranch = options.branch || DEFAULT_BRANCH_NAME;
|
|
36
36
|
this.branch = new branch_1.InfrahubBranchManager(this);
|
|
37
37
|
// Create custom fetch with TLS options if provided
|
|
38
|
-
|
|
38
|
+
// Also handle Request objects properly for node-fetch v2 compatibility
|
|
39
|
+
let httpsAgent;
|
|
39
40
|
if (options.tls) {
|
|
40
41
|
// Build agent options, ensuring rejectUnauthorized is explicitly set if provided
|
|
41
42
|
const agentOptions = {};
|
|
@@ -51,14 +52,35 @@ class InfrahubClient {
|
|
|
51
52
|
if (options.tls.key !== undefined) {
|
|
52
53
|
agentOptions.key = options.tls.key;
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
-
customFetch = ((url, opts = {}) => {
|
|
56
|
-
// Ensure agent is passed for HTTPS URLs
|
|
57
|
-
// node-fetch v2 requires the agent to be explicitly set
|
|
58
|
-
const fetchOptions = { ...opts, agent: httpsAgent };
|
|
59
|
-
return (0, node_fetch_1.default)(url, fetchOptions);
|
|
60
|
-
});
|
|
55
|
+
httpsAgent = new https_1.default.Agent(agentOptions);
|
|
61
56
|
}
|
|
57
|
+
// Wrap fetch to handle Request objects from openapi-fetch
|
|
58
|
+
// node-fetch v2 doesn't properly extract URL from Request objects
|
|
59
|
+
const customFetch = ((input, init) => {
|
|
60
|
+
let url;
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
62
|
+
let options = init || {};
|
|
63
|
+
// Handle Request objects by extracting URL and merging options
|
|
64
|
+
if (input && typeof input === 'object' && 'url' in input) {
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
|
+
const req = input;
|
|
67
|
+
url = req.url;
|
|
68
|
+
options = {
|
|
69
|
+
method: req.method,
|
|
70
|
+
headers: req.headers,
|
|
71
|
+
body: req.body,
|
|
72
|
+
...init
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
url = input;
|
|
77
|
+
}
|
|
78
|
+
// Add HTTPS agent if configured
|
|
79
|
+
if (httpsAgent) {
|
|
80
|
+
options = { ...options, agent: httpsAgent };
|
|
81
|
+
}
|
|
82
|
+
return (0, node_fetch_1.default)(url, options);
|
|
83
|
+
});
|
|
62
84
|
// Initialize the openapi-fetch client with TLS configuration
|
|
63
85
|
this.rest = (0, openapi_fetch_1.default)({
|
|
64
86
|
baseUrl: this.baseUrl,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration tests for the Infrahub SDK
|
|
3
|
+
*
|
|
4
|
+
* These tests require a running Infrahub server at http://localhost:8000
|
|
5
|
+
*
|
|
6
|
+
* Run with: npx jest --testPathPattern=integration --resetModules
|
|
7
|
+
* Or run directly: npx ts-node src/integration.test.ts
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Integration tests for the Infrahub SDK
|
|
4
|
+
*
|
|
5
|
+
* These tests require a running Infrahub server at http://localhost:8000
|
|
6
|
+
*
|
|
7
|
+
* Run with: npx jest --testPathPattern=integration --resetModules
|
|
8
|
+
* Or run directly: npx ts-node src/integration.test.ts
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
const index_1 = require("./index");
|
|
12
|
+
const globals_1 = require("@jest/globals");
|
|
13
|
+
const INFRAHUB_URL = process.env.INFRAHUB_URL || 'http://localhost:8000';
|
|
14
|
+
const INFRAHUB_TOKEN = process.env.INFRAHUB_TOKEN || '';
|
|
15
|
+
(0, globals_1.describe)('Integration Tests - Schema Loading', () => {
|
|
16
|
+
let client;
|
|
17
|
+
(0, globals_1.beforeAll)(() => {
|
|
18
|
+
const options = {
|
|
19
|
+
address: INFRAHUB_URL,
|
|
20
|
+
token: INFRAHUB_TOKEN
|
|
21
|
+
};
|
|
22
|
+
client = new index_1.InfrahubClient(options);
|
|
23
|
+
});
|
|
24
|
+
(0, globals_1.it)('should load schema from the server', async () => {
|
|
25
|
+
const result = await client.rest.GET('/api/schema');
|
|
26
|
+
(0, globals_1.expect)(result.error).toBeUndefined();
|
|
27
|
+
(0, globals_1.expect)(result.response?.status).toBe(200);
|
|
28
|
+
(0, globals_1.expect)(result.data).toBeDefined();
|
|
29
|
+
// Schema should have nodes and/or generics arrays
|
|
30
|
+
if (result.data) {
|
|
31
|
+
(0, globals_1.expect)(typeof result.data).toBe('object');
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
(0, globals_1.it)('should load schema summary from the server', async () => {
|
|
35
|
+
const result = await client.rest.GET('/api/schema/summary');
|
|
36
|
+
(0, globals_1.expect)(result.error).toBeUndefined();
|
|
37
|
+
(0, globals_1.expect)(result.response?.status).toBe(200);
|
|
38
|
+
(0, globals_1.expect)(result.data).toBeDefined();
|
|
39
|
+
});
|
|
40
|
+
(0, globals_1.it)('should get server info', async () => {
|
|
41
|
+
const result = await client.rest.GET('/api/info');
|
|
42
|
+
(0, globals_1.expect)(result.error).toBeUndefined();
|
|
43
|
+
(0, globals_1.expect)(result.response?.status).toBe(200);
|
|
44
|
+
(0, globals_1.expect)(result.data).toBeDefined();
|
|
45
|
+
});
|
|
46
|
+
(0, globals_1.it)('should get server config', async () => {
|
|
47
|
+
const result = await client.rest.GET('/api/config');
|
|
48
|
+
(0, globals_1.expect)(result.error).toBeUndefined();
|
|
49
|
+
(0, globals_1.expect)(result.response?.status).toBe(200);
|
|
50
|
+
(0, globals_1.expect)(result.data).toBeDefined();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|