infrahub-sdk 0.0.2 → 0.0.5
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/.github/workflows/publish.yml +1 -0
- package/dist/branch.d.ts +20 -0
- package/dist/branch.js +105 -0
- package/dist/cjs/index.js +65 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/client.d.ts +6 -0
- package/dist/client.js +35 -0
- package/dist/constants.d.ts +0 -0
- package/dist/constants.js +1 -0
- package/dist/esm/index.js +32 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/graphql/branch.d.ts +23 -0
- package/dist/graphql/branch.js +35 -0
- package/dist/graphql/client.d.ts +71 -0
- package/dist/graphql/client.js +82 -0
- package/dist/graphql.d.ts +31 -0
- package/dist/graphql.js +174 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +128 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +62 -0
- package/dist/types/client.d.ts +7 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/utils/auth.d.ts +1 -0
- package/dist/types/utils/auth.d.ts.map +1 -0
- package/dist/types/utils/error-handling.d.ts +1 -0
- package/dist/types/utils/error-handling.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/validation.d.ts +1 -0
- package/dist/types/utils/validation.d.ts.map +1 -0
- package/dist/types.d.ts +3144 -0
- package/dist/types.js +6 -0
- package/dist/utils/auth.d.ts +0 -0
- package/dist/utils/auth.js +1 -0
- package/dist/utils/error-handling.d.ts +0 -0
- package/dist/utils/error-handling.js +1 -0
- package/dist/utils/index.d.ts +0 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/validation.d.ts +0 -0
- package/dist/utils/validation.js +1 -0
- package/package.json +4 -2
- package/src/branch.ts +130 -0
- package/src/graphql/branch.ts +61 -0
- package/src/graphql/client.ts +158 -0
- package/src/graphql.ts +266 -0
- package/src/index.ts +36 -2
- package/test/main.js +11 -0
- package/test/package-lock.json +1044 -0
- package/test/package.json +14 -0
- package/tsconfig.json +1 -1
package/src/index.ts
CHANGED
|
@@ -3,9 +3,18 @@ export type SafeResult<T> =
|
|
|
3
3
|
| { data: T; error: undefined }
|
|
4
4
|
| { data: undefined; error: Error };
|
|
5
5
|
|
|
6
|
+
import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
7
|
+
|
|
6
8
|
import createClient from 'openapi-fetch';
|
|
7
|
-
import { GraphQLClient, Variables } from 'graphql-request';
|
|
9
|
+
import { GraphQLClient, Variables, gql } from 'graphql-request';
|
|
8
10
|
import type { paths } from './types';
|
|
11
|
+
import { InfrahubBranchManager } from './branch';
|
|
12
|
+
import {
|
|
13
|
+
InfrahubInfoQuery,
|
|
14
|
+
InfrahubInfoResponse,
|
|
15
|
+
InfrahubUserResponse,
|
|
16
|
+
InfrahubUserQuery
|
|
17
|
+
} from './graphql/client';
|
|
9
18
|
|
|
10
19
|
// Re-export gql and all exports from graphql-request
|
|
11
20
|
export * from 'graphql-request';
|
|
@@ -26,11 +35,13 @@ export class InfrahubClient {
|
|
|
26
35
|
private baseUrl: string;
|
|
27
36
|
private token?: string;
|
|
28
37
|
public defaultBranch: string;
|
|
38
|
+
public branch: InfrahubBranchManager;
|
|
29
39
|
|
|
30
40
|
constructor(options: InfrahubClientOptions) {
|
|
31
41
|
this.baseUrl = options.address;
|
|
32
42
|
this.token = options.token;
|
|
33
43
|
this.defaultBranch = options.branch || DEFAULT_BRANCH_NAME;
|
|
44
|
+
this.branch = new InfrahubBranchManager(this);
|
|
34
45
|
|
|
35
46
|
// Initialize the openapi-fetch client
|
|
36
47
|
|
|
@@ -122,7 +133,7 @@ export class InfrahubClient {
|
|
|
122
133
|
TData = any,
|
|
123
134
|
TVariables extends Variables = Variables
|
|
124
135
|
>(
|
|
125
|
-
query: string,
|
|
136
|
+
query: string | TypedDocumentNode<TData, TVariables>,
|
|
126
137
|
variables?: TVariables,
|
|
127
138
|
branchName?: string
|
|
128
139
|
): Promise<TData> {
|
|
@@ -138,4 +149,27 @@ export class InfrahubClient {
|
|
|
138
149
|
throw error;
|
|
139
150
|
}
|
|
140
151
|
}
|
|
152
|
+
|
|
153
|
+
public async getVersion(): Promise<string> {
|
|
154
|
+
const data = await this.executeGraphQL<
|
|
155
|
+
InfrahubInfoResponse,
|
|
156
|
+
Record<any, never>
|
|
157
|
+
>(InfrahubInfoQuery);
|
|
158
|
+
return data.InfrahubInfo.version;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public async getUser(): Promise<InfrahubUserResponse> {
|
|
162
|
+
const data = await this.executeGraphQL<
|
|
163
|
+
InfrahubUserResponse,
|
|
164
|
+
Record<any, never>
|
|
165
|
+
>(InfrahubUserQuery);
|
|
166
|
+
return data;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public async getUserPermissions(): Promise<
|
|
170
|
+
InfrahubUserResponse['AccountProfile']['member_of_groups']['edges']
|
|
171
|
+
> {
|
|
172
|
+
const user = await this.getUser();
|
|
173
|
+
return user.AccountProfile.member_of_groups.edges;
|
|
174
|
+
}
|
|
141
175
|
}
|
package/test/main.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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();
|