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/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -83,11 +83,12 @@ export class InfrahubClient {
|
|
|
83
83
|
this.branch = new InfrahubBranchManager(this);
|
|
84
84
|
|
|
85
85
|
// Create custom fetch with TLS options if provided
|
|
86
|
-
|
|
86
|
+
// Also handle Request objects properly for node-fetch v2 compatibility
|
|
87
|
+
let httpsAgent: https.Agent | undefined;
|
|
87
88
|
if (options.tls) {
|
|
88
89
|
// Build agent options, ensuring rejectUnauthorized is explicitly set if provided
|
|
89
90
|
const agentOptions: https.AgentOptions = {};
|
|
90
|
-
|
|
91
|
+
|
|
91
92
|
if (options.tls.rejectUnauthorized !== undefined) {
|
|
92
93
|
agentOptions.rejectUnauthorized = options.tls.rejectUnauthorized;
|
|
93
94
|
}
|
|
@@ -101,19 +102,42 @@ export class InfrahubClient {
|
|
|
101
102
|
agentOptions.key = options.tls.key;
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
customFetch = ((
|
|
107
|
-
url: Parameters<typeof fetch>[0],
|
|
108
|
-
opts: Parameters<typeof fetch>[1] = {}
|
|
109
|
-
) => {
|
|
110
|
-
// Ensure agent is passed for HTTPS URLs
|
|
111
|
-
// node-fetch v2 requires the agent to be explicitly set
|
|
112
|
-
const fetchOptions = { ...opts, agent: httpsAgent };
|
|
113
|
-
return fetch(url, fetchOptions);
|
|
114
|
-
}) as typeof fetch;
|
|
105
|
+
httpsAgent = new https.Agent(agentOptions);
|
|
115
106
|
}
|
|
116
107
|
|
|
108
|
+
// Wrap fetch to handle Request objects from openapi-fetch
|
|
109
|
+
// node-fetch v2 doesn't properly extract URL from Request objects
|
|
110
|
+
const customFetch = ((
|
|
111
|
+
input: Parameters<typeof fetch>[0],
|
|
112
|
+
init?: Parameters<typeof fetch>[1]
|
|
113
|
+
) => {
|
|
114
|
+
let url: string;
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
116
|
+
let options: any = init || {};
|
|
117
|
+
|
|
118
|
+
// Handle Request objects by extracting URL and merging options
|
|
119
|
+
if (input && typeof input === 'object' && 'url' in input) {
|
|
120
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
121
|
+
const req = input as any;
|
|
122
|
+
url = req.url;
|
|
123
|
+
options = {
|
|
124
|
+
method: req.method,
|
|
125
|
+
headers: req.headers,
|
|
126
|
+
body: req.body,
|
|
127
|
+
...init
|
|
128
|
+
};
|
|
129
|
+
} else {
|
|
130
|
+
url = input as string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Add HTTPS agent if configured
|
|
134
|
+
if (httpsAgent) {
|
|
135
|
+
options = { ...options, agent: httpsAgent };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return fetch(url, options);
|
|
139
|
+
}) as typeof fetch;
|
|
140
|
+
|
|
117
141
|
// Initialize the openapi-fetch client with TLS configuration
|
|
118
142
|
this.rest = createClient<paths>({
|
|
119
143
|
baseUrl: this.baseUrl,
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
|
|
10
|
+
import { InfrahubClient, InfrahubClientOptions } from './index';
|
|
11
|
+
import { describe, expect, it, beforeAll } from '@jest/globals';
|
|
12
|
+
|
|
13
|
+
const INFRAHUB_URL = process.env.INFRAHUB_URL || 'http://localhost:8000';
|
|
14
|
+
const INFRAHUB_TOKEN = process.env.INFRAHUB_TOKEN || '';
|
|
15
|
+
|
|
16
|
+
describe('Integration Tests - Schema Loading', () => {
|
|
17
|
+
let client: InfrahubClient;
|
|
18
|
+
|
|
19
|
+
beforeAll(() => {
|
|
20
|
+
const options: InfrahubClientOptions = {
|
|
21
|
+
address: INFRAHUB_URL,
|
|
22
|
+
token: INFRAHUB_TOKEN
|
|
23
|
+
};
|
|
24
|
+
client = new InfrahubClient(options);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should load schema from the server', async () => {
|
|
28
|
+
const result = await client.rest.GET('/api/schema');
|
|
29
|
+
|
|
30
|
+
expect(result.error).toBeUndefined();
|
|
31
|
+
expect(result.response?.status).toBe(200);
|
|
32
|
+
expect(result.data).toBeDefined();
|
|
33
|
+
|
|
34
|
+
// Schema should have nodes and/or generics arrays
|
|
35
|
+
if (result.data) {
|
|
36
|
+
expect(typeof result.data).toBe('object');
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should load schema summary from the server', async () => {
|
|
41
|
+
const result = await client.rest.GET('/api/schema/summary');
|
|
42
|
+
|
|
43
|
+
expect(result.error).toBeUndefined();
|
|
44
|
+
expect(result.response?.status).toBe(200);
|
|
45
|
+
expect(result.data).toBeDefined();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should get server info', async () => {
|
|
49
|
+
const result = await client.rest.GET('/api/info');
|
|
50
|
+
|
|
51
|
+
expect(result.error).toBeUndefined();
|
|
52
|
+
expect(result.response?.status).toBe(200);
|
|
53
|
+
expect(result.data).toBeDefined();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should get server config', async () => {
|
|
57
|
+
const result = await client.rest.GET('/api/config');
|
|
58
|
+
|
|
59
|
+
expect(result.error).toBeUndefined();
|
|
60
|
+
expect(result.response?.status).toBe(200);
|
|
61
|
+
expect(result.data).toBeDefined();
|
|
62
|
+
});
|
|
63
|
+
});
|