infrahub-sdk 0.0.6 → 0.0.7

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.
Files changed (40) hide show
  1. package/.github/workflows/publish.yml +13 -9
  2. package/README.md +54 -0
  3. package/dist/index.d.ts +24 -0
  4. package/dist/index.js +32 -14
  5. package/dist/index.test.js +65 -2
  6. package/package.json +5 -3
  7. package/src/index.test.ts +70 -2
  8. package/src/index.ts +63 -17
  9. package/dist/cjs/index.js +0 -65
  10. package/dist/cjs/index.js.map +0 -7
  11. package/dist/client.d.ts +0 -6
  12. package/dist/client.js +0 -35
  13. package/dist/constants.d.ts +0 -0
  14. package/dist/constants.js +0 -1
  15. package/dist/esm/index.js +0 -32
  16. package/dist/esm/index.js.map +0 -7
  17. package/dist/types/client.d.ts +0 -7
  18. package/dist/types/client.d.ts.map +0 -1
  19. package/dist/types/constants.d.ts +0 -1
  20. package/dist/types/constants.d.ts.map +0 -1
  21. package/dist/types/index.d.ts +0 -2
  22. package/dist/types/index.d.ts.map +0 -1
  23. package/dist/types/utils/auth.d.ts +0 -1
  24. package/dist/types/utils/auth.d.ts.map +0 -1
  25. package/dist/types/utils/error-handling.d.ts +0 -1
  26. package/dist/types/utils/error-handling.d.ts.map +0 -1
  27. package/dist/types/utils/index.d.ts +0 -1
  28. package/dist/types/utils/index.d.ts.map +0 -1
  29. package/dist/types/utils/validation.d.ts +0 -1
  30. package/dist/types/utils/validation.d.ts.map +0 -1
  31. package/dist/utils/auth.d.ts +0 -0
  32. package/dist/utils/auth.js +0 -1
  33. package/dist/utils/error-handling.d.ts +0 -0
  34. package/dist/utils/error-handling.js +0 -1
  35. package/dist/utils/index.d.ts +0 -0
  36. package/dist/utils/index.js +0 -1
  37. package/dist/utils/validation.d.ts +0 -0
  38. package/dist/utils/validation.js +0 -1
  39. package/test/package-lock.json +0 -1044
  40. package/test/package.json +0 -14
@@ -2,21 +2,25 @@ name: Publish Package to npmjs
2
2
  on:
3
3
  release:
4
4
  types: [published]
5
+
6
+ permissions:
7
+ id-token: write # Required for OIDC
8
+ contents: read
9
+
5
10
  jobs:
6
- build:
11
+ publish:
7
12
  runs-on: ubuntu-latest
8
- permissions:
9
- contents: read
10
- id-token: write
11
13
  steps:
12
14
  - uses: actions/checkout@v4
13
- # Setup .npmrc file to publish to npm
15
+
14
16
  - uses: actions/setup-node@v4
15
17
  with:
16
- node-version: '20.x'
18
+ node-version: '20'
17
19
  registry-url: 'https://registry.npmjs.org'
20
+
21
+ # Ensure npm 11.5.1 or later is installed
22
+ - name: Update npm
23
+ run: npm install -g npm@latest
18
24
  - run: npm ci
19
- - run: npm run build
25
+ - run: npm run build --if-present
20
26
  - run: npm publish
21
- env:
22
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/README.md CHANGED
@@ -37,6 +37,60 @@ const listDevices = gql`
37
37
  const usersData = await client.executeGraphQL(listDevices);
38
38
  ```
39
39
 
40
+ ## TLS/SSL Configuration
41
+
42
+ When connecting to Infrahub instances with custom or self-signed certificates, you can configure TLS options:
43
+
44
+ ### Disable Certificate Verification (for development/testing)
45
+
46
+ ```typescript
47
+ const options: InfrahubClientOptions = {
48
+ address: "https://infrahub.example.com",
49
+ token: "your-api-token",
50
+ tls: {
51
+ rejectUnauthorized: false
52
+ }
53
+ }
54
+
55
+ const client = new InfrahubClient(options);
56
+ ```
57
+
58
+ **Warning**: Disabling certificate verification is not recommended for production environments as it makes your connection vulnerable to man-in-the-middle attacks.
59
+
60
+ ### Use Custom CA Certificate
61
+
62
+ ```typescript
63
+ import fs from 'fs';
64
+
65
+ const options: InfrahubClientOptions = {
66
+ address: "https://infrahub.example.com",
67
+ token: "your-api-token",
68
+ tls: {
69
+ ca: fs.readFileSync('/path/to/ca-certificate.pem')
70
+ }
71
+ }
72
+
73
+ const client = new InfrahubClient(options);
74
+ ```
75
+
76
+ ### Mutual TLS (Client Certificate Authentication)
77
+
78
+ ```typescript
79
+ import fs from 'fs';
80
+
81
+ const options: InfrahubClientOptions = {
82
+ address: "https://infrahub.example.com",
83
+ token: "your-api-token",
84
+ tls: {
85
+ ca: fs.readFileSync('/path/to/ca-certificate.pem'),
86
+ cert: fs.readFileSync('/path/to/client-cert.pem'),
87
+ key: fs.readFileSync('/path/to/client-key.pem')
88
+ }
89
+ }
90
+
91
+ const client = new InfrahubClient(options);
92
+ ```
93
+
40
94
  ## Development
41
95
 
42
96
  - Build: `npm run build`
package/dist/index.d.ts CHANGED
@@ -13,10 +13,34 @@ import { InfrahubBranchManager } from './branch';
13
13
  import { InfrahubUserResponse } from './graphql/client';
14
14
  export * from 'graphql-request';
15
15
  export * from './types';
16
+ export interface TLSConfig {
17
+ /**
18
+ * If true, the server certificate is verified against the list of supplied CAs.
19
+ * Set to false to disable certificate verification (not recommended for production).
20
+ */
21
+ rejectUnauthorized?: boolean;
22
+ /**
23
+ * Optional CA certificates to trust. Can be a string or Buffer containing the certificate(s).
24
+ */
25
+ ca?: string | Buffer | Array<string | Buffer>;
26
+ /**
27
+ * Optional client certificate for mutual TLS authentication.
28
+ */
29
+ cert?: string | Buffer;
30
+ /**
31
+ * Optional client private key for mutual TLS authentication.
32
+ */
33
+ key?: string | Buffer;
34
+ }
16
35
  export interface InfrahubClientOptions {
17
36
  address: string;
18
37
  token?: string;
19
38
  branch?: string;
39
+ /**
40
+ * TLS/SSL configuration options for HTTPS connections.
41
+ * Use this to handle custom certificates or disable certificate verification.
42
+ */
43
+ tls?: TLSConfig;
20
44
  }
21
45
  export declare class InfrahubClient {
22
46
  rest: ReturnType<typeof createClient<paths>>;
package/dist/index.js CHANGED
@@ -18,6 +18,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.InfrahubClient = void 0;
21
+ const https_1 = __importDefault(require("https"));
22
+ const node_fetch_1 = __importDefault(require("node-fetch"));
21
23
  const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
22
24
  const graphql_request_1 = require("graphql-request");
23
25
  const branch_1 = require("./branch");
@@ -32,24 +34,40 @@ class InfrahubClient {
32
34
  this.token = options.token;
33
35
  this.defaultBranch = options.branch || DEFAULT_BRANCH_NAME;
34
36
  this.branch = new branch_1.InfrahubBranchManager(this);
35
- // Initialize the openapi-fetch client
37
+ // Create custom fetch with TLS options if provided
38
+ let customFetch = node_fetch_1.default;
39
+ if (options.tls) {
40
+ const httpsAgent = new https_1.default.Agent({
41
+ rejectUnauthorized: options.tls.rejectUnauthorized,
42
+ ca: options.tls.ca,
43
+ cert: options.tls.cert,
44
+ key: options.tls.key
45
+ });
46
+ customFetch = ((url, opts = {}) => {
47
+ return (0, node_fetch_1.default)(url, { ...opts, agent: httpsAgent });
48
+ });
49
+ }
50
+ // Initialize the openapi-fetch client with TLS configuration
36
51
  this.rest = (0, openapi_fetch_1.default)({
37
- baseUrl: this.baseUrl
52
+ baseUrl: this.baseUrl,
53
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
+ fetch: customFetch
38
55
  });
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);
56
+ // Use middleware to dynamically add the auth token to every REST request.
57
+ this.rest.use({
58
+ onRequest: (req) => {
59
+ req.headers.set('content-type', 'application/json');
60
+ if (this.token) {
61
+ req.headers.set('X-INFRAHUB-KEY', this.token);
45
62
  }
46
- request.headers.set('content-type', 'application/json');
47
- return request;
48
- },
49
- };
50
- this.rest.use(myMiddleware);
63
+ return req;
64
+ }
65
+ });
51
66
  // Initialize the GraphQL client with the default branch endpoint
52
- this.graphqlClient = new graphql_request_1.GraphQLClient(this._graphqlUrl(this.defaultBranch));
67
+ this.graphqlClient = new graphql_request_1.GraphQLClient(this._graphqlUrl(this.defaultBranch), {
68
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
+ fetch: customFetch
70
+ });
53
71
  this.graphqlClient.setHeaders({
54
72
  'Content-Type': 'application/json'
55
73
  });
@@ -24,8 +24,8 @@ const globals_1 = require("@jest/globals");
24
24
  const newToken = 'new-token';
25
25
  client.setAuthToken(newToken);
26
26
  (0, globals_1.expect)(client.token).toBe(newToken);
27
- // GraphQLClient headers are private, so we check no error is thrown
28
- (0, globals_1.expect)(() => client.executeGraphQL('{ __typename }')).not.toThrow();
27
+ // Check that the GraphQL headers are properly set by verifying the token is updated
28
+ (0, globals_1.expect)(client.graphqlClient.requestConfig.headers['X-INFRAHUB-KEY']).toBe(newToken);
29
29
  });
30
30
  (0, globals_1.it)('should call graphqlQuery and handle errors', async () => {
31
31
  const mockRequest = globals_1.jest
@@ -59,4 +59,67 @@ const globals_1 = require("@jest/globals");
59
59
  const url = client._graphqlUrl(branchName);
60
60
  (0, globals_1.expect)(url).toBe(`${baseURL}/graphql/${branchName}`);
61
61
  });
62
+ (0, globals_1.describe)('TLS Configuration', () => {
63
+ (0, globals_1.it)('should accept TLS configuration with rejectUnauthorized set to false', () => {
64
+ const options = {
65
+ address: baseURL,
66
+ token: token,
67
+ tls: {
68
+ rejectUnauthorized: false
69
+ }
70
+ };
71
+ const tlsClient = new index_1.InfrahubClient(options);
72
+ (0, globals_1.expect)(tlsClient).toBeDefined();
73
+ (0, globals_1.expect)(tlsClient.graphqlClient).toBeInstanceOf(graphql_request_1.GraphQLClient);
74
+ });
75
+ (0, globals_1.it)('should accept TLS configuration with custom CA certificate', () => {
76
+ const options = {
77
+ address: baseURL,
78
+ token: token,
79
+ tls: {
80
+ ca: '-----BEGIN CERTIFICATE-----\nMockCertificate\n-----END CERTIFICATE-----'
81
+ }
82
+ };
83
+ const tlsClient = new index_1.InfrahubClient(options);
84
+ (0, globals_1.expect)(tlsClient).toBeDefined();
85
+ (0, globals_1.expect)(tlsClient.graphqlClient).toBeInstanceOf(graphql_request_1.GraphQLClient);
86
+ });
87
+ (0, globals_1.it)('should accept TLS configuration with client certificate and key', () => {
88
+ const options = {
89
+ address: baseURL,
90
+ token: token,
91
+ tls: {
92
+ cert: '-----BEGIN CERTIFICATE-----\nMockCert\n-----END CERTIFICATE-----',
93
+ key: '-----BEGIN PRIVATE KEY-----\nMockKey\n-----END PRIVATE KEY-----'
94
+ }
95
+ };
96
+ const tlsClient = new index_1.InfrahubClient(options);
97
+ (0, globals_1.expect)(tlsClient).toBeDefined();
98
+ (0, globals_1.expect)(tlsClient.graphqlClient).toBeInstanceOf(graphql_request_1.GraphQLClient);
99
+ });
100
+ (0, globals_1.it)('should accept TLS configuration with all options', () => {
101
+ const options = {
102
+ address: baseURL,
103
+ token: token,
104
+ tls: {
105
+ rejectUnauthorized: true,
106
+ ca: '-----BEGIN CERTIFICATE-----\nMockCA\n-----END CERTIFICATE-----',
107
+ cert: '-----BEGIN CERTIFICATE-----\nMockCert\n-----END CERTIFICATE-----',
108
+ key: '-----BEGIN PRIVATE KEY-----\nMockKey\n-----END PRIVATE KEY-----'
109
+ }
110
+ };
111
+ const tlsClient = new index_1.InfrahubClient(options);
112
+ (0, globals_1.expect)(tlsClient).toBeDefined();
113
+ (0, globals_1.expect)(tlsClient.graphqlClient).toBeInstanceOf(graphql_request_1.GraphQLClient);
114
+ });
115
+ (0, globals_1.it)('should work without TLS configuration (backward compatibility)', () => {
116
+ const options = {
117
+ address: baseURL,
118
+ token: token
119
+ };
120
+ const normalClient = new index_1.InfrahubClient(options);
121
+ (0, globals_1.expect)(normalClient).toBeDefined();
122
+ (0, globals_1.expect)(normalClient.graphqlClient).toBeInstanceOf(graphql_request_1.GraphQLClient);
123
+ });
124
+ });
62
125
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "infrahub-sdk",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
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,16 @@
19
19
  "dependencies": {
20
20
  "@graphql-codegen/typed-document-node": "^5.1.2",
21
21
  "graphql-request": "^6.1.0",
22
- "openapi-fetch": "^0.14.0"
22
+ "node-fetch": "^2.7.0",
23
+ "openapi-fetch": "^0.9.4"
23
24
  },
24
25
  "devDependencies": {
25
26
  "@eslint/js": "^9.31.0",
27
+ "@types/node": "^24.10.0",
28
+ "@types/node-fetch": "^2.6.13",
26
29
  "eslint": "^9.31.0",
27
30
  "eslint-config-prettier": "^10.1.5",
28
31
  "eslint-plugin-prettier": "^5.5.1",
29
- "openapi-typescript": "^7.8.0",
30
32
  "prettier": "3.6.2",
31
33
  "ts-jest": "^29.4.0",
32
34
  "typescript": "^5.8.3",
package/src/index.test.ts CHANGED
@@ -27,8 +27,8 @@ describe('InfrahubClient', () => {
27
27
  const newToken = 'new-token';
28
28
  client.setAuthToken(newToken);
29
29
  expect((client as any).token).toBe(newToken);
30
- // GraphQLClient headers are private, so we check no error is thrown
31
- expect(() => client.executeGraphQL('{ __typename }')).not.toThrow();
30
+ // Check that the GraphQL headers are properly set by verifying the token is updated
31
+ expect((client as any).graphqlClient.requestConfig.headers['X-INFRAHUB-KEY']).toBe(newToken);
32
32
  });
33
33
 
34
34
  it('should call graphqlQuery and handle errors', async () => {
@@ -71,4 +71,72 @@ describe('InfrahubClient', () => {
71
71
  const url = (client as any)._graphqlUrl(branchName);
72
72
  expect(url).toBe(`${baseURL}/graphql/${branchName}`);
73
73
  });
74
+
75
+ describe('TLS Configuration', () => {
76
+ it('should accept TLS configuration with rejectUnauthorized set to false', () => {
77
+ const options: InfrahubClientOptions = {
78
+ address: baseURL,
79
+ token: token,
80
+ tls: {
81
+ rejectUnauthorized: false
82
+ }
83
+ };
84
+ const tlsClient = new InfrahubClient(options);
85
+ expect(tlsClient).toBeDefined();
86
+ expect((tlsClient as any).graphqlClient).toBeInstanceOf(GraphQLClient);
87
+ });
88
+
89
+ it('should accept TLS configuration with custom CA certificate', () => {
90
+ const options: InfrahubClientOptions = {
91
+ address: baseURL,
92
+ token: token,
93
+ tls: {
94
+ ca: '-----BEGIN CERTIFICATE-----\nMockCertificate\n-----END CERTIFICATE-----'
95
+ }
96
+ };
97
+ const tlsClient = new InfrahubClient(options);
98
+ expect(tlsClient).toBeDefined();
99
+ expect((tlsClient as any).graphqlClient).toBeInstanceOf(GraphQLClient);
100
+ });
101
+
102
+ it('should accept TLS configuration with client certificate and key', () => {
103
+ const options: InfrahubClientOptions = {
104
+ address: baseURL,
105
+ token: token,
106
+ tls: {
107
+ cert: '-----BEGIN CERTIFICATE-----\nMockCert\n-----END CERTIFICATE-----',
108
+ key: '-----BEGIN PRIVATE KEY-----\nMockKey\n-----END PRIVATE KEY-----'
109
+ }
110
+ };
111
+ const tlsClient = new InfrahubClient(options);
112
+ expect(tlsClient).toBeDefined();
113
+ expect((tlsClient as any).graphqlClient).toBeInstanceOf(GraphQLClient);
114
+ });
115
+
116
+ it('should accept TLS configuration with all options', () => {
117
+ const options: InfrahubClientOptions = {
118
+ address: baseURL,
119
+ token: token,
120
+ tls: {
121
+ rejectUnauthorized: true,
122
+ ca: '-----BEGIN CERTIFICATE-----\nMockCA\n-----END CERTIFICATE-----',
123
+ cert: '-----BEGIN CERTIFICATE-----\nMockCert\n-----END CERTIFICATE-----',
124
+ key: '-----BEGIN PRIVATE KEY-----\nMockKey\n-----END PRIVATE KEY-----'
125
+ }
126
+ };
127
+ const tlsClient = new InfrahubClient(options);
128
+ expect(tlsClient).toBeDefined();
129
+ expect((tlsClient as any).graphqlClient).toBeInstanceOf(GraphQLClient);
130
+ });
131
+
132
+ it('should work without TLS configuration (backward compatibility)', () => {
133
+ const options: InfrahubClientOptions = {
134
+ address: baseURL,
135
+ token: token
136
+ };
137
+ const normalClient = new InfrahubClient(options);
138
+ expect(normalClient).toBeDefined();
139
+ expect((normalClient as any).graphqlClient).toBeInstanceOf(GraphQLClient);
140
+ });
141
+ });
74
142
  });
package/src/index.ts CHANGED
@@ -4,9 +4,11 @@ export type SafeResult<T> =
4
4
  | { data: undefined; error: Error };
5
5
 
6
6
  import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
7
+ import https from 'https';
8
+ import fetch from 'node-fetch';
7
9
 
8
- import createClient, { Middleware } from 'openapi-fetch';
9
- import { GraphQLClient, Variables } from 'graphql-request';
10
+ import createClient from 'openapi-fetch';
11
+ import { GraphQLClient, Variables, gql } from 'graphql-request';
10
12
  import type { paths } from './types';
11
13
  import { InfrahubBranchManager } from './branch';
12
14
  import {
@@ -21,10 +23,35 @@ export * from 'graphql-request';
21
23
 
22
24
  export * from './types';
23
25
 
26
+ export interface TLSConfig {
27
+ /**
28
+ * If true, the server certificate is verified against the list of supplied CAs.
29
+ * Set to false to disable certificate verification (not recommended for production).
30
+ */
31
+ rejectUnauthorized?: boolean;
32
+ /**
33
+ * Optional CA certificates to trust. Can be a string or Buffer containing the certificate(s).
34
+ */
35
+ ca?: string | Buffer | Array<string | Buffer>;
36
+ /**
37
+ * Optional client certificate for mutual TLS authentication.
38
+ */
39
+ cert?: string | Buffer;
40
+ /**
41
+ * Optional client private key for mutual TLS authentication.
42
+ */
43
+ key?: string | Buffer;
44
+ }
45
+
24
46
  export interface InfrahubClientOptions {
25
47
  address: string;
26
48
  token?: string;
27
49
  branch?: string;
50
+ /**
51
+ * TLS/SSL configuration options for HTTPS connections.
52
+ * Use this to handle custom certificates or disable certificate verification.
53
+ */
54
+ tls?: TLSConfig;
28
55
  }
29
56
 
30
57
  const DEFAULT_BRANCH_NAME = 'main';
@@ -43,29 +70,48 @@ export class InfrahubClient {
43
70
  this.defaultBranch = options.branch || DEFAULT_BRANCH_NAME;
44
71
  this.branch = new InfrahubBranchManager(this);
45
72
 
46
- // Initialize the openapi-fetch client
73
+ // Create custom fetch with TLS options if provided
74
+ let customFetch: typeof fetch = fetch;
75
+ if (options.tls) {
76
+ const httpsAgent = new https.Agent({
77
+ rejectUnauthorized: options.tls.rejectUnauthorized,
78
+ ca: options.tls.ca,
79
+ cert: options.tls.cert,
80
+ key: options.tls.key
81
+ });
82
+ customFetch = ((
83
+ url: Parameters<typeof fetch>[0],
84
+ opts: Parameters<typeof fetch>[1] = {}
85
+ ) => {
86
+ return fetch(url, { ...opts, agent: httpsAgent });
87
+ }) as typeof fetch;
88
+ }
47
89
 
90
+ // Initialize the openapi-fetch client with TLS configuration
48
91
  this.rest = createClient<paths>({
49
- baseUrl: this.baseUrl
92
+ baseUrl: this.baseUrl,
93
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
+ fetch: customFetch as any
50
95
  });
51
96
 
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);
97
+ // Use middleware to dynamically add the auth token to every REST request.
98
+ this.rest.use({
99
+ onRequest: (req) => {
100
+ req.headers.set('content-type', 'application/json');
101
+ if (this.token) {
102
+ req.headers.set('X-INFRAHUB-KEY', this.token);
58
103
  }
59
- request.headers.set('content-type', 'application/json');
60
- return request;
61
- },
62
- };
63
-
64
- this.rest.use(myMiddleware);
104
+ return req;
105
+ }
106
+ });
65
107
 
66
108
  // Initialize the GraphQL client with the default branch endpoint
67
109
  this.graphqlClient = new GraphQLClient(
68
- this._graphqlUrl(this.defaultBranch)
110
+ this._graphqlUrl(this.defaultBranch),
111
+ {
112
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
113
+ fetch: customFetch as any
114
+ }
69
115
  );
70
116
  this.graphqlClient.setHeaders({
71
117
  'Content-Type': 'application/json'
package/dist/cjs/index.js DELETED
@@ -1,65 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- InfrahubClient: () => InfrahubClient
34
- });
35
- module.exports = __toCommonJS(index_exports);
36
-
37
- // src/client.ts
38
- var import_axios = __toESM(require("axios"), 1);
39
- var InfrahubClient = class {
40
- constructor(baseURL, token) {
41
- this.axiosInstance = import_axios.default.create({
42
- baseURL,
43
- headers: {
44
- "Content-Type": "application/json"
45
- }
46
- });
47
- if (token) {
48
- this.setAuthToken(token);
49
- }
50
- }
51
- setAuthToken(token) {
52
- this.axiosInstance.defaults.headers.common["X-INFRAHUB-KEY"] = token;
53
- }
54
- // get info from /api/info endpoint
55
- async getInfo() {
56
- try {
57
- const response = await this.axiosInstance.get("/api/info");
58
- return response.data;
59
- } catch (error) {
60
- console.error("Error fetching info:", error);
61
- throw error;
62
- }
63
- }
64
- };
65
- //# sourceMappingURL=index.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/index.ts", "../../src/client.ts"],
4
- "sourcesContent": ["export * from './client';", "import axios, { AxiosInstance } from 'axios';\n\nexport class InfrahubClient {\n private axiosInstance: AxiosInstance;\n\n constructor(baseURL: string, token?: string) {\n this.axiosInstance = axios.create({\n baseURL,\n headers: {\n 'Content-Type': 'application/json',\n }\n });\n if (token) {\n this.setAuthToken(token);\n }\n\n }\n\n public setAuthToken(token: string) {\n this.axiosInstance.defaults.headers.common[\"X-INFRAHUB-KEY\"] = token;\n }\n\n // get info from /api/info endpoint\n public async getInfo() {\n try {\n const response = await this.axiosInstance.get('/api/info');\n return response.data;\n } catch (error) {\n console.error('Error fetching info:', error);\n throw error;\n }\n }\n}"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAqC;AAE9B,IAAM,iBAAN,MAAqB;AAAA,EAGxB,YAAY,SAAiB,OAAgB;AACzC,SAAK,gBAAgB,aAAAA,QAAM,OAAO;AAAA,MAC9B;AAAA,MACA,SAAS;AAAA,QACL,gBAAgB;AAAA,MACpB;AAAA,IACJ,CAAC;AACD,QAAI,OAAO;AACP,WAAK,aAAa,KAAK;AAAA,IAC3B;AAAA,EAEJ;AAAA,EAEO,aAAa,OAAe;AAC/B,SAAK,cAAc,SAAS,QAAQ,OAAO,gBAAgB,IAAI;AAAA,EACnE;AAAA;AAAA,EAGA,MAAa,UAAU;AACnB,QAAI;AACA,YAAM,WAAW,MAAM,KAAK,cAAc,IAAI,WAAW;AACzD,aAAO,SAAS;AAAA,IACpB,SAAS,OAAO;AACZ,cAAQ,MAAM,wBAAwB,KAAK;AAC3C,YAAM;AAAA,IACV;AAAA,EACJ;AACJ;",
6
- "names": ["axios"]
7
- }
package/dist/client.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export declare class InfrahubClient {
2
- private axiosInstance;
3
- constructor(baseURL: string, token?: string);
4
- setAuthToken(token: string): void;
5
- getInfo(): Promise<any>;
6
- }
package/dist/client.js DELETED
@@ -1,35 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.InfrahubClient = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- class InfrahubClient {
9
- constructor(baseURL, token) {
10
- this.axiosInstance = axios_1.default.create({
11
- baseURL,
12
- headers: {
13
- 'Content-Type': 'application/json',
14
- }
15
- });
16
- if (token) {
17
- this.setAuthToken(token);
18
- }
19
- }
20
- setAuthToken(token) {
21
- this.axiosInstance.defaults.headers.common["X-INFRAHUB-KEY"] = token;
22
- }
23
- // get info from /api/info endpoint
24
- async getInfo() {
25
- try {
26
- const response = await this.axiosInstance.get('/api/info');
27
- return response.data;
28
- }
29
- catch (error) {
30
- console.error('Error fetching info:', error);
31
- throw error;
32
- }
33
- }
34
- }
35
- exports.InfrahubClient = InfrahubClient;
File without changes
package/dist/constants.js DELETED
@@ -1 +0,0 @@
1
- "use strict";
package/dist/esm/index.js DELETED
@@ -1,32 +0,0 @@
1
- // src/client.ts
2
- import axios from "axios";
3
- var InfrahubClient = class {
4
- constructor(baseURL, token) {
5
- this.axiosInstance = axios.create({
6
- baseURL,
7
- headers: {
8
- "Content-Type": "application/json"
9
- }
10
- });
11
- if (token) {
12
- this.setAuthToken(token);
13
- }
14
- }
15
- setAuthToken(token) {
16
- this.axiosInstance.defaults.headers.common["X-INFRAHUB-KEY"] = token;
17
- }
18
- // get info from /api/info endpoint
19
- async getInfo() {
20
- try {
21
- const response = await this.axiosInstance.get("/api/info");
22
- return response.data;
23
- } catch (error) {
24
- console.error("Error fetching info:", error);
25
- throw error;
26
- }
27
- }
28
- };
29
- export {
30
- InfrahubClient
31
- };
32
- //# sourceMappingURL=index.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/client.ts"],
4
- "sourcesContent": ["import axios, { AxiosInstance } from 'axios';\n\nexport class InfrahubClient {\n private axiosInstance: AxiosInstance;\n\n constructor(baseURL: string, token?: string) {\n this.axiosInstance = axios.create({\n baseURL,\n headers: {\n 'Content-Type': 'application/json',\n }\n });\n if (token) {\n this.setAuthToken(token);\n }\n\n }\n\n public setAuthToken(token: string) {\n this.axiosInstance.defaults.headers.common[\"X-INFRAHUB-KEY\"] = token;\n }\n\n // get info from /api/info endpoint\n public async getInfo() {\n try {\n const response = await this.axiosInstance.get('/api/info');\n return response.data;\n } catch (error) {\n console.error('Error fetching info:', error);\n throw error;\n }\n }\n}"],
5
- "mappings": ";AAAA,OAAO,WAA8B;AAE9B,IAAM,iBAAN,MAAqB;AAAA,EAGxB,YAAY,SAAiB,OAAgB;AACzC,SAAK,gBAAgB,MAAM,OAAO;AAAA,MAC9B;AAAA,MACA,SAAS;AAAA,QACL,gBAAgB;AAAA,MACpB;AAAA,IACJ,CAAC;AACD,QAAI,OAAO;AACP,WAAK,aAAa,KAAK;AAAA,IAC3B;AAAA,EAEJ;AAAA,EAEO,aAAa,OAAe;AAC/B,SAAK,cAAc,SAAS,QAAQ,OAAO,gBAAgB,IAAI;AAAA,EACnE;AAAA;AAAA,EAGA,MAAa,UAAU;AACnB,QAAI;AACA,YAAM,WAAW,MAAM,KAAK,cAAc,IAAI,WAAW;AACzD,aAAO,SAAS;AAAA,IACpB,SAAS,OAAO;AACZ,cAAQ,MAAM,wBAAwB,KAAK;AAC3C,YAAM;AAAA,IACV;AAAA,EACJ;AACJ;",
6
- "names": []
7
- }