infrahub-sdk 0.0.1

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 (53) hide show
  1. package/.eslintrc.js +18 -0
  2. package/.prettierrc +6 -0
  3. package/LICENSE +201 -0
  4. package/README.md +47 -0
  5. package/dist/branch.d.ts +36 -0
  6. package/dist/branch.js +136 -0
  7. package/dist/cjs/index.js +65 -0
  8. package/dist/cjs/index.js.map +7 -0
  9. package/dist/client.d.ts +6 -0
  10. package/dist/client.js +35 -0
  11. package/dist/constants.d.ts +0 -0
  12. package/dist/constants.js +1 -0
  13. package/dist/esm/index.js +32 -0
  14. package/dist/esm/index.js.map +7 -0
  15. package/dist/graphql.d.ts +31 -0
  16. package/dist/graphql.js +174 -0
  17. package/dist/index.d.ts +47 -0
  18. package/dist/index.js +115 -0
  19. package/dist/index.test.d.ts +1 -0
  20. package/dist/index.test.js +62 -0
  21. package/dist/types/client.d.ts +7 -0
  22. package/dist/types/client.d.ts.map +1 -0
  23. package/dist/types/constants.d.ts +1 -0
  24. package/dist/types/constants.d.ts.map +1 -0
  25. package/dist/types/index.d.ts +2 -0
  26. package/dist/types/index.d.ts.map +1 -0
  27. package/dist/types/utils/auth.d.ts +1 -0
  28. package/dist/types/utils/auth.d.ts.map +1 -0
  29. package/dist/types/utils/error-handling.d.ts +1 -0
  30. package/dist/types/utils/error-handling.d.ts.map +1 -0
  31. package/dist/types/utils/index.d.ts +1 -0
  32. package/dist/types/utils/index.d.ts.map +1 -0
  33. package/dist/types/utils/validation.d.ts +1 -0
  34. package/dist/types/utils/validation.d.ts.map +1 -0
  35. package/dist/types.d.ts +3144 -0
  36. package/dist/types.js +6 -0
  37. package/dist/utils/auth.d.ts +0 -0
  38. package/dist/utils/auth.js +1 -0
  39. package/dist/utils/error-handling.d.ts +0 -0
  40. package/dist/utils/error-handling.js +1 -0
  41. package/dist/utils/index.d.ts +0 -0
  42. package/dist/utils/index.js +1 -0
  43. package/dist/utils/validation.d.ts +0 -0
  44. package/dist/utils/validation.js +1 -0
  45. package/eslint.config.mjs +9 -0
  46. package/jest.config.js +6 -0
  47. package/package.json +33 -0
  48. package/src/branch.ts +161 -0
  49. package/src/graphql.ts +266 -0
  50. package/src/index.test.ts +74 -0
  51. package/src/index.ts +144 -0
  52. package/src/types.ts +3169 -0
  53. package/tsconfig.json +14 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,18 @@
1
+ module.exports = {
2
+ root: true,
3
+ parser: '@typescript-eslint/parser',
4
+ plugins: ['@typescript-eslint'],
5
+ extends: [
6
+ 'eslint:recommended',
7
+ 'plugin:@typescript-eslint/recommended',
8
+ 'prettier'
9
+ ],
10
+ env: {
11
+ node: true,
12
+ jest: true,
13
+ es2021: true
14
+ },
15
+ rules: {
16
+ '@typescript-eslint/no-explicit-any': 'off',
17
+ }
18
+ };
package/.prettierrc ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "semi": true,
3
+ "trailingComma": "none",
4
+ "singleQuote": true,
5
+ "printWidth": 80
6
+ }
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # infrahub-sdk-typescript
2
+
3
+ A TypeScript SDK for interacting with the Infrahub API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install infrahub-sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { InfrahubClient, gql, InfrahubClientOptions } from 'infrahub-sdk';
15
+
16
+ const options: InfrahubClientOptions = {
17
+ address: "https://demo.infrahub.app",
18
+ token: "your-api-token"
19
+ }
20
+
21
+ console.log('Executing GraphQL query...');
22
+
23
+ const client = new InfrahubClient(options);
24
+
25
+ const listDevices = gql`
26
+ query MyQuery {
27
+ InfraDevice {
28
+ edges {
29
+ node {
30
+ display_label
31
+ }
32
+ }
33
+ }
34
+ }
35
+ `;
36
+
37
+ const usersData = await client.executeGraphQL(listDevices);
38
+ ```
39
+
40
+ ## Development
41
+
42
+ - Build: `npm run build`
43
+ - Test: `npm test`
44
+
45
+ ## License
46
+
47
+ Apache License 2.0
@@ -0,0 +1,36 @@
1
+ import { InfrahubClient } from './index';
2
+ interface Branch {
3
+ id: string;
4
+ name: string;
5
+ description: string;
6
+ origin_branch: string;
7
+ branched_from: string;
8
+ is_default: boolean;
9
+ sync_with_git: boolean;
10
+ has_schema_changes: boolean;
11
+ }
12
+ export interface BranchCreateInput {
13
+ name: string;
14
+ description?: string;
15
+ sync_with_git?: boolean;
16
+ wait_until_completion?: boolean;
17
+ }
18
+ export declare class BranchNotFoundError extends Error {
19
+ constructor(identifier: string);
20
+ }
21
+ export declare class InfrahubBranchManager {
22
+ private client;
23
+ constructor(client: InfrahubClient);
24
+ /**
25
+ * Fetches all branches using GraphQL and returns an object mapping branch names to branch data.
26
+ */
27
+ all(): Promise<Record<string, Branch>>;
28
+ /**
29
+ * Fetches a specific branch by name.
30
+ * @param branchName The name of the branch to fetch.
31
+ */
32
+ get(branchName: string): Promise<Branch | null>;
33
+ create(input: BranchCreateInput): Promise<Branch>;
34
+ delete(branchName: string): Promise<boolean>;
35
+ }
36
+ export {};
package/dist/branch.js ADDED
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InfrahubBranchManager = exports.BranchNotFoundError = void 0;
4
+ const index_1 = require("./index");
5
+ const graphql_1 = require("./graphql");
6
+ class BranchNotFoundError extends Error {
7
+ constructor(identifier) {
8
+ super(`Branch not found: ${identifier}`);
9
+ this.name = 'BranchNotFoundError';
10
+ }
11
+ }
12
+ exports.BranchNotFoundError = BranchNotFoundError;
13
+ const MUTATION_QUERY_TASK = { ok: null, task: { id: null } };
14
+ const MUTATION_QUERY_DATA = {
15
+ ok: null,
16
+ object: {
17
+ id: null,
18
+ name: null,
19
+ description: null,
20
+ origin_branch: null,
21
+ branched_from: null,
22
+ is_default: null,
23
+ sync_with_git: null,
24
+ has_schema_changes: null
25
+ }
26
+ };
27
+ // InfrahubBranchManager class to manage branches via GraphQL
28
+ class InfrahubBranchManager {
29
+ constructor(client) {
30
+ this.client = client;
31
+ }
32
+ /**
33
+ * Fetches all branches using GraphQL and returns an object mapping branch names to branch data.
34
+ */
35
+ async all() {
36
+ const query = (0, index_1.gql) `
37
+ query BranchQuery {
38
+ Branch {
39
+ id
40
+ name
41
+ description
42
+ origin_branch
43
+ branched_from
44
+ is_default
45
+ sync_with_git
46
+ has_schema_changes
47
+ }
48
+ }
49
+ `;
50
+ const response = await this.client.executeGraphQL(query);
51
+ const branches = response.Branch || [];
52
+ const result = {};
53
+ for (const branch of branches) {
54
+ result[branch.name] = branch;
55
+ }
56
+ return result;
57
+ }
58
+ /**
59
+ * Fetches a specific branch by name.
60
+ * @param branchName The name of the branch to fetch.
61
+ */
62
+ async get(branchName) {
63
+ const query = (0, index_1.gql) `
64
+ query BranchQuery($name: String!) {
65
+ Branch(name: $name) {
66
+ id
67
+ name
68
+ description
69
+ origin_branch
70
+ branched_from
71
+ is_default
72
+ sync_with_git
73
+ has_schema_changes
74
+ }
75
+ }
76
+ `;
77
+ const response = await this.client.executeGraphQL(query, {
78
+ name: branchName
79
+ });
80
+ const branchArr = response.Branch || [];
81
+ if (!branchArr.length) {
82
+ throw new BranchNotFoundError(branchName);
83
+ }
84
+ return branchArr[0];
85
+ }
86
+ async create(input) {
87
+ const inputData = {
88
+ background_execution: input.wait_until_completion,
89
+ data: {
90
+ name: input.name,
91
+ description: input.description,
92
+ sync_with_git: input.sync_with_git
93
+ }
94
+ };
95
+ // set mutation query to MUTATION_QUERY_TASK if brackground_execution is true
96
+ const mutationQuery = input.wait_until_completion
97
+ ? MUTATION_QUERY_TASK
98
+ : MUTATION_QUERY_DATA;
99
+ const mutation = new graphql_1.Mutation({
100
+ mutation: 'BranchCreate',
101
+ inputData: inputData,
102
+ query: mutationQuery,
103
+ name: 'CreateBranch'
104
+ });
105
+ // You may want to remove this log in production
106
+ console.log(mutation.render());
107
+ const response = await this.client.executeGraphQL(mutation.render(), {
108
+ input: inputData
109
+ });
110
+ // Adjust the response path as needed based on your API
111
+ const branchData = response.BranchCreate?.object || response.BranchCreate?.task || null;
112
+ if (!branchData) {
113
+ throw new Error('Branch creation failed');
114
+ }
115
+ return branchData;
116
+ }
117
+ async delete(branchName) {
118
+ const inputData = {
119
+ data: {
120
+ name: branchName
121
+ }
122
+ };
123
+ const mutation = new graphql_1.Mutation({
124
+ mutation: 'BranchDelete',
125
+ inputData: inputData,
126
+ query: { ok: null },
127
+ name: 'DeleteBranch'
128
+ });
129
+ const response = await this.client.executeGraphQL(mutation.render(), {
130
+ input: inputData
131
+ });
132
+ console.log(response);
133
+ return !!(response.BranchDelete && response.BranchDelete.ok);
134
+ }
135
+ }
136
+ exports.InfrahubBranchManager = InfrahubBranchManager;
@@ -0,0 +1,65 @@
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
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,6 @@
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 ADDED
@@ -0,0 +1,35 @@
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
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,32 @@
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
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,31 @@
1
+ export type VariableType = string | number | boolean | null | undefined | VariableType[] | Record<string, any>;
2
+ export declare function convertToGraphqlAsString(value: VariableType, convertEnum?: boolean): string;
3
+ export declare function renderVariablesToString(data: Record<string, any>): string;
4
+ export declare function renderQueryBlock(data: Record<string, any>, offset?: number, indentation?: number, convertEnum?: boolean): string[];
5
+ export declare function renderInputBlock(data: Record<string, any>, offset?: number, indentation?: number, convertEnum?: boolean): string[];
6
+ export declare class BaseGraphQLQuery {
7
+ queryType: string;
8
+ indentation: number;
9
+ query: Record<string, any>;
10
+ variables?: Record<string, any>;
11
+ name: string;
12
+ constructor(query: Record<string, any>, variables?: Record<string, any>, name?: string);
13
+ renderFirstLine(): string;
14
+ }
15
+ export declare class Query extends BaseGraphQLQuery {
16
+ queryType: string;
17
+ render(convertEnum?: boolean): string;
18
+ }
19
+ export declare class Mutation extends BaseGraphQLQuery {
20
+ queryType: string;
21
+ inputData: Record<string, any>;
22
+ mutation: string;
23
+ constructor({ mutation, inputData, query, variables, name }: {
24
+ mutation: string;
25
+ inputData: Record<string, any>;
26
+ query: Record<string, any>;
27
+ variables?: Record<string, any>;
28
+ name?: string;
29
+ });
30
+ render(convertEnum?: boolean): string;
31
+ }