infrahub-sdk 0.0.4 → 0.0.6
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/branch.js +0 -1
- package/dist/index.js +11 -9
- package/package.json +3 -2
- package/src/branch.ts +0 -2
- package/src/graphql/client.ts +0 -2
- package/src/index.ts +14 -11
- package/test/package-lock.json +4 -4
- package/test/package.json +1 -1
- package/test/main.js +0 -11
package/dist/branch.js
CHANGED
|
@@ -74,7 +74,6 @@ class InfrahubBranchManager {
|
|
|
74
74
|
query: mutationQuery,
|
|
75
75
|
name: 'CreateBranch'
|
|
76
76
|
});
|
|
77
|
-
console.log(mutation.render());
|
|
78
77
|
const response = await this.client.executeGraphQL(mutation.render());
|
|
79
78
|
// Adjust the response path as needed based on your API
|
|
80
79
|
const branchData = response.BranchCreate?.object || response.BranchCreate?.task || null;
|
package/dist/index.js
CHANGED
|
@@ -36,16 +36,18 @@ class InfrahubClient {
|
|
|
36
36
|
this.rest = (0, openapi_fetch_1.default)({
|
|
37
37
|
baseUrl: this.baseUrl
|
|
38
38
|
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
onRequest
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
|
|
39
|
+
const token = this.token;
|
|
40
|
+
const myMiddleware = {
|
|
41
|
+
async onRequest({ request }) {
|
|
42
|
+
// set "X-INFRAHUB-KEY" header if token is present
|
|
43
|
+
if (token) {
|
|
44
|
+
request.headers.set('X-INFRAHUB-KEY', token);
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
request.headers.set('content-type', 'application/json');
|
|
47
|
+
return request;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
this.rest.use(myMiddleware);
|
|
49
51
|
// Initialize the GraphQL client with the default branch endpoint
|
|
50
52
|
this.graphqlClient = new graphql_request_1.GraphQLClient(this._graphqlUrl(this.defaultBranch));
|
|
51
53
|
this.graphqlClient.setHeaders({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "infrahub-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "A client SDK for the Infrahub API.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,13 +19,14 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@graphql-codegen/typed-document-node": "^5.1.2",
|
|
21
21
|
"graphql-request": "^6.1.0",
|
|
22
|
-
"openapi-fetch": "^0.
|
|
22
|
+
"openapi-fetch": "^0.14.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@eslint/js": "^9.31.0",
|
|
26
26
|
"eslint": "^9.31.0",
|
|
27
27
|
"eslint-config-prettier": "^10.1.5",
|
|
28
28
|
"eslint-plugin-prettier": "^5.5.1",
|
|
29
|
+
"openapi-typescript": "^7.8.0",
|
|
29
30
|
"prettier": "3.6.2",
|
|
30
31
|
"ts-jest": "^29.4.0",
|
|
31
32
|
"typescript": "^5.8.3",
|
package/src/branch.ts
CHANGED
|
@@ -97,8 +97,6 @@ export class InfrahubBranchManager {
|
|
|
97
97
|
name: 'CreateBranch'
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
-
console.log(mutation.render());
|
|
101
|
-
|
|
102
100
|
const response = await this.client.executeGraphQL(mutation.render());
|
|
103
101
|
// Adjust the response path as needed based on your API
|
|
104
102
|
const branchData =
|
package/src/graphql/client.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
2
2
|
import { parse } from 'graphql';
|
|
3
3
|
import { gql } from 'graphql-request';
|
|
4
|
-
import { InfrahubClient } from '..';
|
|
5
4
|
|
|
6
5
|
const InfrahubInfoDocument = parse(gql`
|
|
7
6
|
query InfrahubInfo {
|
|
@@ -155,4 +154,3 @@ export const InfrahubUserQuery: TypedDocumentNode<
|
|
|
155
154
|
InfrahubUserResponse,
|
|
156
155
|
Record<any, never>
|
|
157
156
|
> = InfrahubUserDocument;
|
|
158
|
-
|
package/src/index.ts
CHANGED
|
@@ -5,8 +5,8 @@ export type SafeResult<T> =
|
|
|
5
5
|
|
|
6
6
|
import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
7
7
|
|
|
8
|
-
import createClient from 'openapi-fetch';
|
|
9
|
-
import { GraphQLClient, Variables
|
|
8
|
+
import createClient, { Middleware } from 'openapi-fetch';
|
|
9
|
+
import { GraphQLClient, Variables } from 'graphql-request';
|
|
10
10
|
import type { paths } from './types';
|
|
11
11
|
import { InfrahubBranchManager } from './branch';
|
|
12
12
|
import {
|
|
@@ -49,16 +49,19 @@ export class InfrahubClient {
|
|
|
49
49
|
baseUrl: this.baseUrl
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
onRequest
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
|
|
52
|
+
const token = this.token;
|
|
53
|
+
const myMiddleware: Middleware = {
|
|
54
|
+
async onRequest({ request }) {
|
|
55
|
+
// set "X-INFRAHUB-KEY" header if token is present
|
|
56
|
+
if (token) {
|
|
57
|
+
request.headers.set('X-INFRAHUB-KEY', token);
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
request.headers.set('content-type', 'application/json');
|
|
60
|
+
return request;
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
this.rest.use(myMiddleware);
|
|
62
65
|
|
|
63
66
|
// Initialize the GraphQL client with the default branch endpoint
|
|
64
67
|
this.graphqlClient = new GraphQLClient(
|
package/test/package-lock.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"version": "1.0.0",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"infrahub-sdk": "^0.0.
|
|
12
|
+
"infrahub-sdk": "^0.0.4"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"node_modules/@ardatan/relay-compiler": {
|
|
@@ -590,9 +590,9 @@
|
|
|
590
590
|
}
|
|
591
591
|
},
|
|
592
592
|
"node_modules/infrahub-sdk": {
|
|
593
|
-
"version": "0.0.
|
|
594
|
-
"resolved": "https://registry.npmjs.org/infrahub-sdk/-/infrahub-sdk-0.0.
|
|
595
|
-
"integrity": "sha512-
|
|
593
|
+
"version": "0.0.4",
|
|
594
|
+
"resolved": "https://registry.npmjs.org/infrahub-sdk/-/infrahub-sdk-0.0.4.tgz",
|
|
595
|
+
"integrity": "sha512-Nez4MZd7ikja/3oxS2vm067H4qcUJcqGKPrPQvfsEZz5zCR9v+0lTDUbYmuQ28ED25AvABw6EZ8bbM2V18qIeg==",
|
|
596
596
|
"license": "Apache-2.0",
|
|
597
597
|
"dependencies": {
|
|
598
598
|
"@graphql-codegen/typed-document-node": "^5.1.2",
|
package/test/package.json
CHANGED
package/test/main.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { InfrahubClient } from 'infrahub-sdk';
|
|
2
|
-
|
|
3
|
-
const options = {
|
|
4
|
-
address: "https://demo.infrahub.app",
|
|
5
|
-
token: "your-api-token"
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
console.log('Executing GraphQL query...');
|
|
9
|
-
|
|
10
|
-
const client = new InfrahubClient(options);
|
|
11
|
-
await client.getVersion();
|