infrahub-sdk 0.0.5 → 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 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
- // Use middleware to dynamically add the auth token to every REST request.
40
- this.rest.use({
41
- onRequest: (req) => {
42
- req.headers.set('content-type', 'application/json');
43
- if (this.token) {
44
- req.headers.set('X-INFRAHUB-KEY', this.token);
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
- return req;
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.5",
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,14 +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.9.4",
23
- "openapi-typescript-fetch": "^2.2.1"
22
+ "openapi-fetch": "^0.14.0"
24
23
  },
25
24
  "devDependencies": {
26
25
  "@eslint/js": "^9.31.0",
27
26
  "eslint": "^9.31.0",
28
27
  "eslint-config-prettier": "^10.1.5",
29
28
  "eslint-plugin-prettier": "^5.5.1",
29
+ "openapi-typescript": "^7.8.0",
30
30
  "prettier": "3.6.2",
31
31
  "ts-jest": "^29.4.0",
32
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 =
@@ -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, gql } from 'graphql-request';
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
- // Use middleware to dynamically add the auth token to every REST request.
53
- this.rest.use({
54
- onRequest: (req) => {
55
- req.headers.set('content-type', 'application/json');
56
- if (this.token) {
57
- req.headers.set('X-INFRAHUB-KEY', this.token);
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
- return req;
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/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();