conductor-node 8.2.4 → 8.4.0
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/README.md +100 -15
- package/dist/package.json +1 -1
- package/dist/src/Client.d.ts +10 -1
- package/dist/src/Client.js +13 -0
- package/dist/src/error.d.ts +45 -6
- package/dist/src/error.js +88 -11
- package/dist/src/graphql/__generated__/operationTypes.d.ts +13 -0
- package/dist/src/graphql/__generated__/operationTypes.js +11 -1
- package/dist/src/graphql/graphqlOperationWrapper.d.ts +2 -2
- package/dist/src/graphql/graphqlOperationWrapper.js +27 -31
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,8 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Execute _any_ read or write [QuickBooks Desktop API](https://developer.intuit.com/app/developer/qbdesktop/docs/api-reference/qbdesktop) through async TypeScript and receive a fully-typed response.
|
|
4
4
|
|
|
5
|
+
<!-- markdownlint-disable MD033 -->
|
|
5
6
|
<img src="https://user-images.githubusercontent.com/170023/213273732-83dd6881-0b36-4787-820b-bd55cdc8444f.jpg" alt="qbd" width="600"/>
|
|
6
7
|
|
|
8
|
+
## Table of Contents
|
|
9
|
+
|
|
10
|
+
1. [Requirements](#requirements)
|
|
11
|
+
2. [Installation](#installation)
|
|
12
|
+
3. [Usage](#usage)
|
|
13
|
+
4. [APIs](#apis)
|
|
14
|
+
5. [TypeScript](#typescript)
|
|
15
|
+
6. [Error Handling](#error-handling)
|
|
16
|
+
|
|
7
17
|
## Requirements
|
|
8
18
|
|
|
9
19
|
1. A Conductor API key from Danny.
|
|
@@ -34,7 +44,7 @@ const newAccount = await conductor.qbd.account.add(qbdConnections[0].id, {
|
|
|
34
44
|
});
|
|
35
45
|
```
|
|
36
46
|
|
|
37
|
-
##
|
|
47
|
+
## APIs
|
|
38
48
|
|
|
39
49
|
### `createIntegrationConnection(input: CreateIntegrationConnectionInput)`
|
|
40
50
|
|
|
@@ -100,34 +110,39 @@ const qbdConnection = await conductor.getIntegrationConnectionById(
|
|
|
100
110
|
);
|
|
101
111
|
```
|
|
102
112
|
|
|
103
|
-
### `
|
|
113
|
+
### `pingIntegrationConnection(id: string)`
|
|
104
114
|
|
|
105
|
-
Check whether
|
|
115
|
+
Check whether the specified integration-connection can connect and process requests end-to-end.
|
|
106
116
|
|
|
107
|
-
|
|
117
|
+
If the connection fails, the error we encountered will be thrown as a [`ConductorError`](#error-handling). This information is useful for showing a "connection status" indicator in your app.
|
|
118
|
+
|
|
119
|
+
In the form of a rejected promise:
|
|
108
120
|
|
|
109
121
|
```ts
|
|
110
|
-
|
|
122
|
+
conductor.pingIntegrationConnection(qbdConnectionId).catch((error) => {
|
|
123
|
+
if (error instanceof ConductorError) {
|
|
124
|
+
// Update your app's UI to display `error.endUserMessage`.
|
|
125
|
+
}
|
|
126
|
+
// ...
|
|
127
|
+
});
|
|
111
128
|
```
|
|
112
129
|
|
|
113
|
-
|
|
130
|
+
Or using `async`/`await`:
|
|
114
131
|
|
|
115
132
|
```ts
|
|
116
|
-
{
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
code: "QBWC_CONNECTION_ERROR",
|
|
122
|
-
developerMessage: "QBWC Error 0x80040408: Could not start QuickBooks.",
|
|
123
|
-
endUserMessage: "An error occurred while connecting to QuickBooks Desktop. Please ensure QuickBooks Desktop is running and the correct company file is open, then try again.",
|
|
133
|
+
try {
|
|
134
|
+
await conductor.pingIntegrationConnection(qbdConnectionId);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
if (error instanceof ConductorError) {
|
|
137
|
+
// Update your app's UI to display `error.endUserMessage`.
|
|
124
138
|
}
|
|
139
|
+
// ...
|
|
125
140
|
}
|
|
126
141
|
```
|
|
127
142
|
|
|
128
143
|
## TypeScript
|
|
129
144
|
|
|
130
|
-
Access the full QuickBooks Desktop API through TypeScript. The `qbd.*` APIs are fully
|
|
145
|
+
Access the full QuickBooks Desktop API through TypeScript. The `qbd.*` APIs are fully typed with inline documentation and will autocomplete in your editor.
|
|
131
146
|
|
|
132
147
|
To manually access the QBD types, import them from `conductor-node` like so:
|
|
133
148
|
|
|
@@ -140,3 +155,73 @@ const accountAddInput: QbdTypes.AccountAdd = {
|
|
|
140
155
|
OpenBalance: "100",
|
|
141
156
|
};
|
|
142
157
|
```
|
|
158
|
+
|
|
159
|
+
## Error Handling
|
|
160
|
+
|
|
161
|
+
The `ConductorError` and its subclasses have the following properties:
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
{
|
|
165
|
+
// The error type.
|
|
166
|
+
type: string;
|
|
167
|
+
// The error code.
|
|
168
|
+
code: string;
|
|
169
|
+
// The developer-friendly error message for your logs.
|
|
170
|
+
message: string;
|
|
171
|
+
// The end-user-friendly error message to display in your app.
|
|
172
|
+
endUserMessage: string;
|
|
173
|
+
// The HTTP status code.
|
|
174
|
+
statusCode: number | undefined;
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Error Types
|
|
179
|
+
|
|
180
|
+
The error object you receive will have one of the following error types:
|
|
181
|
+
|
|
182
|
+
| Type | Description |
|
|
183
|
+
| ------------------------------ | ------------------------------------------------------------------------------------------------ |
|
|
184
|
+
| `ConductorIntegrationError` | An error occurred on the third-party integration's end while processing your end-user's request. |
|
|
185
|
+
| `ConductorInvalidRequestError` | You made an API call with the wrong parameters, in the wrong state, or in an invalid way. |
|
|
186
|
+
| `ConductorAuthenticationError` | Conductor cannot authenticate you with the credentials you provided. E.g., an incorrect API key. |
|
|
187
|
+
| `ConductorConnectionError` | There was a network problem between the client (on your server) and Conductor's servers. |
|
|
188
|
+
| `ConductorInternalError` | Something went wrong on Conductor's end. (These are rare.) |
|
|
189
|
+
|
|
190
|
+
### Example
|
|
191
|
+
|
|
192
|
+
Using `async`/`await`:
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
try {
|
|
196
|
+
const newAccount = await conductor.qbd.account.add(qbdConnectionId, {
|
|
197
|
+
Name: "Test Account",
|
|
198
|
+
AccountType: "Bank",
|
|
199
|
+
OpenBalance: "100",
|
|
200
|
+
});
|
|
201
|
+
} catch (error) {
|
|
202
|
+
if (error instanceof ConductorError) {
|
|
203
|
+
// Update your app's UI to display `error.endUserMessage`.
|
|
204
|
+
}
|
|
205
|
+
// ...
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Or in the form of a rejected promise:
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
conductor.qbd.account
|
|
213
|
+
.add(qbdConnectionId, {
|
|
214
|
+
Name: "Test Account",
|
|
215
|
+
AccountType: "Bank",
|
|
216
|
+
OpenBalance: "100",
|
|
217
|
+
})
|
|
218
|
+
.then((newAccount) => {
|
|
219
|
+
// ...
|
|
220
|
+
})
|
|
221
|
+
.catch((error) => {
|
|
222
|
+
if (error instanceof ConductorError) {
|
|
223
|
+
// Update your app's UI to display `error.endUserMessage`.
|
|
224
|
+
}
|
|
225
|
+
// ...
|
|
226
|
+
});
|
|
227
|
+
```
|
package/dist/package.json
CHANGED
package/dist/src/Client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GraphqlCreateIntegrationConnectionInput, GraphqlCreateIntegrationConnectionMutation, GraphqlGetConnectionStatusQuery, GraphqlGetConnectionStatusQueryVariables, GraphqlGetIntegrationConnectionQuery, GraphqlGetIntegrationConnectionQueryVariables, GraphqlGetIntegrationConnectionsQuery } from "./graphql/__generated__/operationTypes";
|
|
1
|
+
import type { GraphqlCreateIntegrationConnectionInput, GraphqlCreateIntegrationConnectionMutation, GraphqlGetConnectionStatusQuery, GraphqlGetConnectionStatusQueryVariables, GraphqlGetIntegrationConnectionQuery, GraphqlGetIntegrationConnectionQueryVariables, GraphqlGetIntegrationConnectionsQuery, GraphqlPingIntegrationConnectionMutation, GraphqlPingIntegrationConnectionMutationVariables } from "./graphql/__generated__/operationTypes";
|
|
2
2
|
import QbdIntegration from "./integrations/qbd/QbdIntegration";
|
|
3
3
|
import { getServerUrlForEnvironment } from "./utils";
|
|
4
4
|
export interface ClientOptions {
|
|
@@ -62,5 +62,14 @@ export default class Client {
|
|
|
62
62
|
createIntegrationConnection(input: GraphqlCreateIntegrationConnectionInput & {
|
|
63
63
|
integrationKey: "quickbooks-desktop";
|
|
64
64
|
}): Promise<GraphqlCreateIntegrationConnectionMutation["createIntegrationConnection"]["integrationConnection"]>;
|
|
65
|
+
/**
|
|
66
|
+
* Check whether the specified integration-connection can connect and process
|
|
67
|
+
* requests end-to-end.
|
|
68
|
+
*
|
|
69
|
+
* If the connection fails, the error we encountered will be thrown as a
|
|
70
|
+
* `ConductorError`. This information is useful for showing a "connection
|
|
71
|
+
* status" indicator in your app.
|
|
72
|
+
*/
|
|
73
|
+
pingIntegrationConnection(integrationConnectionId: GraphqlPingIntegrationConnectionMutationVariables["input"]["integrationConnectionId"]): Promise<GraphqlPingIntegrationConnectionMutation["pingIntegrationConnection"]>;
|
|
65
74
|
private createHeaders;
|
|
66
75
|
}
|
package/dist/src/Client.js
CHANGED
|
@@ -84,6 +84,19 @@ class Client {
|
|
|
84
84
|
.createIntegrationConnection({ input })
|
|
85
85
|
.then((result) => result.createIntegrationConnection.integrationConnection);
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Check whether the specified integration-connection can connect and process
|
|
89
|
+
* requests end-to-end.
|
|
90
|
+
*
|
|
91
|
+
* If the connection fails, the error we encountered will be thrown as a
|
|
92
|
+
* `ConductorError`. This information is useful for showing a "connection
|
|
93
|
+
* status" indicator in your app.
|
|
94
|
+
*/
|
|
95
|
+
async pingIntegrationConnection(integrationConnectionId) {
|
|
96
|
+
return this.graphqlOperations
|
|
97
|
+
.pingIntegrationConnection({ input: { integrationConnectionId } })
|
|
98
|
+
.then((result) => result.pingIntegrationConnection);
|
|
99
|
+
}
|
|
87
100
|
createHeaders(apiKey) {
|
|
88
101
|
return {
|
|
89
102
|
Authorization: `Bearer ${apiKey}`,
|
package/dist/src/error.d.ts
CHANGED
|
@@ -1,18 +1,57 @@
|
|
|
1
|
-
export declare const DEFAULT_ERROR_CODE = "CONDUCTOR__INTERNAL_SERVER_ERROR";
|
|
2
1
|
export declare const DEFAULT_END_USER_MESSAGE = "An internal server error occurred. Please try again later.";
|
|
3
|
-
interface
|
|
2
|
+
export interface ConductorErrorOptions {
|
|
4
3
|
readonly type: string;
|
|
5
4
|
readonly code: string;
|
|
6
|
-
readonly
|
|
5
|
+
readonly message: string;
|
|
7
6
|
readonly endUserMessage?: string;
|
|
8
7
|
readonly statusCode?: number;
|
|
9
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* The base error from which all other more specific Conductor errors derive.
|
|
11
|
+
* Specifically for errors returned from Conductor's API.
|
|
12
|
+
*/
|
|
10
13
|
export declare class ConductorError extends Error {
|
|
11
14
|
readonly type: string;
|
|
15
|
+
readonly rawType: string;
|
|
12
16
|
readonly code: string;
|
|
13
|
-
readonly developerMessage: string;
|
|
14
17
|
readonly endUserMessage: string;
|
|
15
18
|
readonly statusCode: number | undefined;
|
|
16
|
-
constructor(
|
|
19
|
+
constructor(options: ConductorErrorOptions);
|
|
17
20
|
}
|
|
18
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Raised when an error occurs on the third-party integration's end while
|
|
23
|
+
* processing your end-user's request. E.g., QBWC failed to connect to
|
|
24
|
+
* QuickBooks Desktop on the end-user's computer.
|
|
25
|
+
*/
|
|
26
|
+
export declare class ConductorIntegrationError extends ConductorError {
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Raised when you make an API call with the wrong parameters, in the wrong
|
|
30
|
+
* state, or in an invalid way.
|
|
31
|
+
*/
|
|
32
|
+
export declare class ConductorInvalidRequestError extends ConductorError {
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Raised when Conductor cannot authenticate you with the credentials you
|
|
36
|
+
* provided. E.g., an incorrect API key.
|
|
37
|
+
*/
|
|
38
|
+
export declare class ConductorAuthenticationError extends ConductorError {
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Raised when there is a network problem between the client (on your server)
|
|
42
|
+
* and Conductor's servers. E.g., a downed network or a bad TLS certificate.
|
|
43
|
+
*/
|
|
44
|
+
export declare class ConductorConnectionError extends ConductorError {
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Raised when something goes wrong on Conductor's end. (These are rare.)
|
|
48
|
+
*/
|
|
49
|
+
export declare class ConductorInternalError extends ConductorError {
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Raised as a fallback for any other error from Conductor that no other error
|
|
53
|
+
* type captures.
|
|
54
|
+
*/
|
|
55
|
+
export declare class ConductorUnknownError extends ConductorError {
|
|
56
|
+
}
|
|
57
|
+
export declare function generateConductorError(rawConductorError: ConductorErrorOptions): ConductorError;
|
package/dist/src/error.js
CHANGED
|
@@ -1,22 +1,99 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.generateConductorError = exports.ConductorUnknownError = exports.ConductorInternalError = exports.ConductorConnectionError = exports.ConductorAuthenticationError = exports.ConductorInvalidRequestError = exports.ConductorIntegrationError = exports.ConductorError = exports.DEFAULT_END_USER_MESSAGE = void 0;
|
|
4
|
+
/* eslint-disable max-classes-per-file -- Keep the error classes together */
|
|
5
5
|
exports.DEFAULT_END_USER_MESSAGE = "An internal server error occurred. Please try again later.";
|
|
6
|
+
/**
|
|
7
|
+
* The base error from which all other more specific Conductor errors derive.
|
|
8
|
+
* Specifically for errors returned from Conductor's API.
|
|
9
|
+
*/
|
|
6
10
|
class ConductorError extends Error {
|
|
7
11
|
type;
|
|
12
|
+
rawType;
|
|
8
13
|
code;
|
|
9
|
-
developerMessage;
|
|
10
14
|
endUserMessage;
|
|
11
15
|
statusCode;
|
|
12
|
-
constructor(
|
|
13
|
-
super(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
constructor(options) {
|
|
17
|
+
super(options.message);
|
|
18
|
+
// Set `name` to the constructor name so that the error appears in logs as
|
|
19
|
+
// `[ConductorError: foo]` instead of `[Error: foo]`.
|
|
20
|
+
this.name = this.constructor.name;
|
|
21
|
+
// 1. Set `type`, even though it's redundant with `name`, because `name`
|
|
22
|
+
// does not appear when doing `console.log(error)` unlike all other
|
|
23
|
+
// properties we set.
|
|
24
|
+
// 2. Set `type` to the constructor name to ensure that subclasses of
|
|
25
|
+
// `ConductorError` always have the correct `type` even if they are
|
|
26
|
+
// instantiated with the wrong options.
|
|
27
|
+
this.type = this.constructor.name;
|
|
28
|
+
this.rawType = options.type;
|
|
29
|
+
this.code = options.code;
|
|
30
|
+
this.endUserMessage = options.endUserMessage ?? exports.DEFAULT_END_USER_MESSAGE;
|
|
31
|
+
this.statusCode = options.statusCode;
|
|
20
32
|
}
|
|
21
33
|
}
|
|
22
34
|
exports.ConductorError = ConductorError;
|
|
35
|
+
/**
|
|
36
|
+
* Raised when an error occurs on the third-party integration's end while
|
|
37
|
+
* processing your end-user's request. E.g., QBWC failed to connect to
|
|
38
|
+
* QuickBooks Desktop on the end-user's computer.
|
|
39
|
+
*/
|
|
40
|
+
class ConductorIntegrationError extends ConductorError {
|
|
41
|
+
}
|
|
42
|
+
exports.ConductorIntegrationError = ConductorIntegrationError;
|
|
43
|
+
/**
|
|
44
|
+
* Raised when you make an API call with the wrong parameters, in the wrong
|
|
45
|
+
* state, or in an invalid way.
|
|
46
|
+
*/
|
|
47
|
+
class ConductorInvalidRequestError extends ConductorError {
|
|
48
|
+
}
|
|
49
|
+
exports.ConductorInvalidRequestError = ConductorInvalidRequestError;
|
|
50
|
+
/**
|
|
51
|
+
* Raised when Conductor cannot authenticate you with the credentials you
|
|
52
|
+
* provided. E.g., an incorrect API key.
|
|
53
|
+
*/
|
|
54
|
+
class ConductorAuthenticationError extends ConductorError {
|
|
55
|
+
}
|
|
56
|
+
exports.ConductorAuthenticationError = ConductorAuthenticationError;
|
|
57
|
+
/**
|
|
58
|
+
* Raised when there is a network problem between the client (on your server)
|
|
59
|
+
* and Conductor's servers. E.g., a downed network or a bad TLS certificate.
|
|
60
|
+
*/
|
|
61
|
+
class ConductorConnectionError extends ConductorError {
|
|
62
|
+
}
|
|
63
|
+
exports.ConductorConnectionError = ConductorConnectionError;
|
|
64
|
+
/**
|
|
65
|
+
* Raised when something goes wrong on Conductor's end. (These are rare.)
|
|
66
|
+
*/
|
|
67
|
+
class ConductorInternalError extends ConductorError {
|
|
68
|
+
}
|
|
69
|
+
exports.ConductorInternalError = ConductorInternalError;
|
|
70
|
+
/**
|
|
71
|
+
* Raised as a fallback for any other error from Conductor that no other error
|
|
72
|
+
* type captures.
|
|
73
|
+
*/
|
|
74
|
+
class ConductorUnknownError extends ConductorError {
|
|
75
|
+
}
|
|
76
|
+
exports.ConductorUnknownError = ConductorUnknownError;
|
|
77
|
+
function generateConductorError(rawConductorError) {
|
|
78
|
+
switch (rawConductorError.type) {
|
|
79
|
+
case "INTEGRATION_ERROR": {
|
|
80
|
+
return new ConductorIntegrationError(rawConductorError);
|
|
81
|
+
}
|
|
82
|
+
case "INVALID_REQUEST_ERROR": {
|
|
83
|
+
return new ConductorInvalidRequestError(rawConductorError);
|
|
84
|
+
}
|
|
85
|
+
case "AUTHENTICATION_ERROR": {
|
|
86
|
+
return new ConductorAuthenticationError(rawConductorError);
|
|
87
|
+
}
|
|
88
|
+
case "CONNECTION_ERROR": {
|
|
89
|
+
return new ConductorConnectionError(rawConductorError);
|
|
90
|
+
}
|
|
91
|
+
case "INTERNAL_ERROR": {
|
|
92
|
+
return new ConductorInternalError(rawConductorError);
|
|
93
|
+
}
|
|
94
|
+
default: {
|
|
95
|
+
return new ConductorUnknownError(rawConductorError);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.generateConductorError = generateConductorError;
|
|
@@ -29,6 +29,9 @@ export type GraphqlCreateIntegrationConnectionInput = {
|
|
|
29
29
|
endUserSourceId: Scalars["String"];
|
|
30
30
|
integrationKey: Scalars["String"];
|
|
31
31
|
};
|
|
32
|
+
export type GraphqlPingIntegrationConnectionInput = {
|
|
33
|
+
integrationConnectionId: Scalars["ID"];
|
|
34
|
+
};
|
|
32
35
|
export type GraphqlSendIntegrationRequestInput = {
|
|
33
36
|
integrationConnectionId: Scalars["ID"];
|
|
34
37
|
requestObject: Scalars["JSONObject"];
|
|
@@ -105,6 +108,14 @@ export type GraphqlCreateIntegrationConnectionMutation = {
|
|
|
105
108
|
};
|
|
106
109
|
};
|
|
107
110
|
};
|
|
111
|
+
export type GraphqlPingIntegrationConnectionMutationVariables = Exact<{
|
|
112
|
+
input: GraphqlPingIntegrationConnectionInput;
|
|
113
|
+
}>;
|
|
114
|
+
export type GraphqlPingIntegrationConnectionMutation = {
|
|
115
|
+
pingIntegrationConnection: {
|
|
116
|
+
duration: number;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
108
119
|
export type GraphqlSendIntegrationRequestMutationVariables = Exact<{
|
|
109
120
|
input: GraphqlSendIntegrationRequestInput;
|
|
110
121
|
}>;
|
|
@@ -119,6 +130,7 @@ export declare const GetIntegrationConnectionDocument: string;
|
|
|
119
130
|
export declare const GetIntegrationConnectionsDocument: string;
|
|
120
131
|
export declare const GetConnectionStatusDocument: string;
|
|
121
132
|
export declare const CreateIntegrationConnectionDocument: string;
|
|
133
|
+
export declare const PingIntegrationConnectionDocument = "\n mutation pingIntegrationConnection($input: PingIntegrationConnectionInput!) {\n pingIntegrationConnection(input: $input) {\n duration\n }\n}\n ";
|
|
122
134
|
export declare const SendIntegrationRequestDocument = "\n mutation sendIntegrationRequest($input: SendIntegrationRequestInput!) {\n sendIntegrationRequest(input: $input) {\n response\n }\n}\n ";
|
|
123
135
|
export type SdkFunctionWrapper = <T>(action: (requestHeaders?: Record<string, string>) => Promise<T>, operationName: string, operationType?: string) => Promise<T>;
|
|
124
136
|
export declare function getSdk(client: GraphQLClient, withWrapper?: SdkFunctionWrapper): {
|
|
@@ -126,6 +138,7 @@ export declare function getSdk(client: GraphQLClient, withWrapper?: SdkFunctionW
|
|
|
126
138
|
getIntegrationConnections(variables?: GraphqlGetIntegrationConnectionsQueryVariables, requestHeaders?: (Record<string, string> | Dom.Headers | string[][]) | undefined): Promise<GraphqlGetIntegrationConnectionsQuery>;
|
|
127
139
|
getConnectionStatus(variables: GraphqlGetConnectionStatusQueryVariables, requestHeaders?: (Record<string, string> | Dom.Headers | string[][]) | undefined): Promise<GraphqlGetConnectionStatusQuery>;
|
|
128
140
|
createIntegrationConnection(variables: GraphqlCreateIntegrationConnectionMutationVariables, requestHeaders?: (Record<string, string> | Dom.Headers | string[][]) | undefined): Promise<GraphqlCreateIntegrationConnectionMutation>;
|
|
141
|
+
pingIntegrationConnection(variables: GraphqlPingIntegrationConnectionMutationVariables, requestHeaders?: (Record<string, string> | Dom.Headers | string[][]) | undefined): Promise<GraphqlPingIntegrationConnectionMutation>;
|
|
129
142
|
sendIntegrationRequest(variables: GraphqlSendIntegrationRequestMutationVariables, requestHeaders?: (Record<string, string> | Dom.Headers | string[][]) | undefined): Promise<GraphqlSendIntegrationRequestMutation>;
|
|
130
143
|
};
|
|
131
144
|
export type Sdk = ReturnType<typeof getSdk>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSdk = exports.SendIntegrationRequestDocument = exports.CreateIntegrationConnectionDocument = exports.GetConnectionStatusDocument = exports.GetIntegrationConnectionsDocument = exports.GetIntegrationConnectionDocument = exports.UserErrorFragmentDoc = exports.IntegrationConnectionFragmentDoc = void 0;
|
|
3
|
+
exports.getSdk = exports.SendIntegrationRequestDocument = exports.PingIntegrationConnectionDocument = exports.CreateIntegrationConnectionDocument = exports.GetConnectionStatusDocument = exports.GetIntegrationConnectionsDocument = exports.GetIntegrationConnectionDocument = exports.UserErrorFragmentDoc = exports.IntegrationConnectionFragmentDoc = void 0;
|
|
4
4
|
exports.IntegrationConnectionFragmentDoc = `
|
|
5
5
|
fragment IntegrationConnection on IntegrationConnection {
|
|
6
6
|
id
|
|
@@ -53,6 +53,13 @@ exports.CreateIntegrationConnectionDocument = `
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
${exports.IntegrationConnectionFragmentDoc}`;
|
|
56
|
+
exports.PingIntegrationConnectionDocument = `
|
|
57
|
+
mutation pingIntegrationConnection($input: PingIntegrationConnectionInput!) {
|
|
58
|
+
pingIntegrationConnection(input: $input) {
|
|
59
|
+
duration
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
56
63
|
exports.SendIntegrationRequestDocument = `
|
|
57
64
|
mutation sendIntegrationRequest($input: SendIntegrationRequestInput!) {
|
|
58
65
|
sendIntegrationRequest(input: $input) {
|
|
@@ -75,6 +82,9 @@ function getSdk(client, withWrapper = defaultWrapper) {
|
|
|
75
82
|
createIntegrationConnection(variables, requestHeaders) {
|
|
76
83
|
return withWrapper((wrappedRequestHeaders) => client.request(exports.CreateIntegrationConnectionDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "createIntegrationConnection", "mutation");
|
|
77
84
|
},
|
|
85
|
+
pingIntegrationConnection(variables, requestHeaders) {
|
|
86
|
+
return withWrapper((wrappedRequestHeaders) => client.request(exports.PingIntegrationConnectionDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "pingIntegrationConnection", "mutation");
|
|
87
|
+
},
|
|
78
88
|
sendIntegrationRequest(variables, requestHeaders) {
|
|
79
89
|
return withWrapper((wrappedRequestHeaders) => client.request(exports.SendIntegrationRequestDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), "sendIntegrationRequest", "mutation");
|
|
80
90
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ConductorError } from "../error";
|
|
1
|
+
import type { ConductorError } from "../error";
|
|
2
2
|
import type { getSdk } from "../graphql/__generated__/operationTypes";
|
|
3
3
|
export declare function wrapGraphqlOperations<T extends ReturnType<typeof getSdk>>(graphqlOperations: T, verbose: boolean): T;
|
|
4
4
|
export declare function graphqlOperationWrapper<V extends {
|
|
5
5
|
[key: string]: unknown;
|
|
6
6
|
}, R>(operationName: string, variables: V | undefined, operation: (variables: V | undefined) => Promise<R>, verbose: boolean): Promise<R>;
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function wrapError(error: Error): ConductorError;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.wrapError = exports.graphqlOperationWrapper = exports.wrapGraphqlOperations = void 0;
|
|
7
7
|
const package_json_1 = __importDefault(require("../../package.json"));
|
|
8
8
|
const error_1 = require("../error");
|
|
9
9
|
const graphql_request_1 = require("graphql-request");
|
|
@@ -45,7 +45,7 @@ async function graphqlOperationWrapper(operationName, variables, operation, verb
|
|
|
45
45
|
return result;
|
|
46
46
|
}
|
|
47
47
|
catch (error) {
|
|
48
|
-
const conductorError =
|
|
48
|
+
const conductorError = wrapError(error);
|
|
49
49
|
if (verbose) {
|
|
50
50
|
const errorLog = {
|
|
51
51
|
duration: getDurationString(startTime),
|
|
@@ -59,48 +59,44 @@ async function graphqlOperationWrapper(operationName, variables, operation, verb
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
exports.graphqlOperationWrapper = graphqlOperationWrapper;
|
|
62
|
-
function
|
|
62
|
+
function wrapError(error) {
|
|
63
63
|
if (error instanceof graphql_request_1.ClientError) {
|
|
64
64
|
const { response } = error;
|
|
65
65
|
if ([404, 502, 503].includes(response.status)) {
|
|
66
|
-
return
|
|
67
|
-
type: "
|
|
68
|
-
code:
|
|
69
|
-
|
|
66
|
+
return (0, error_1.generateConductorError)({
|
|
67
|
+
type: "CONNECTION_ERROR",
|
|
68
|
+
code: "SERVER_UNAVAILABLE",
|
|
69
|
+
message: `The Conductor server returned a ${response.status} error, which may indicate that the server is unavailable. Please alert the Conductor team if this error persists.`,
|
|
70
70
|
statusCode: response.status,
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
const nestedError = response.errors?.[0];
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return new error_1.ConductorError({
|
|
90
|
-
type: "temp",
|
|
91
|
-
code: error_1.DEFAULT_ERROR_CODE,
|
|
92
|
-
developerMessage: errorMessage,
|
|
74
|
+
const errorExtensions = nestedError?.extensions;
|
|
75
|
+
if (errorExtensions) {
|
|
76
|
+
if (errorExtensions["code"] === "GRAPHQL_VALIDATION_FAILED") {
|
|
77
|
+
return (0, error_1.generateConductorError)({
|
|
78
|
+
type: "INVALID_REQUEST_ERROR",
|
|
79
|
+
code: "CLIENT_OUTDATED",
|
|
80
|
+
message: `Your version of "${package_json_1.default.name}" is not longer compatible with the Conductor server. Please run "yarn upgrade ${package_json_1.default.name} --latest" to update.`,
|
|
81
|
+
statusCode: response.status,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return (0, error_1.generateConductorError)({
|
|
85
|
+
type: errorExtensions["type"],
|
|
86
|
+
code: errorExtensions["code"],
|
|
87
|
+
message: nestedError.message,
|
|
88
|
+
endUserMessage: errorExtensions["endUserMessage"],
|
|
93
89
|
statusCode: response.status,
|
|
94
90
|
});
|
|
95
91
|
}
|
|
96
92
|
}
|
|
97
|
-
return
|
|
98
|
-
type: "
|
|
99
|
-
code:
|
|
100
|
-
|
|
93
|
+
return (0, error_1.generateConductorError)({
|
|
94
|
+
type: "INTERNAL_ERROR",
|
|
95
|
+
code: "INVALID_JSON_RESPONSE",
|
|
96
|
+
message: "Invalid JSON received from the Conductor API.",
|
|
101
97
|
});
|
|
102
98
|
}
|
|
103
|
-
exports.
|
|
99
|
+
exports.wrapError = wrapError;
|
|
104
100
|
function getDurationString(startTime) {
|
|
105
101
|
const duration = Date.now() - startTime;
|
|
106
102
|
return `${Math.round(duration / 10) / 100}s`;
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -15,6 +15,9 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
18
21
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
22
|
if (mod && mod.__esModule) return mod;
|
|
20
23
|
var result = {};
|
|
@@ -31,4 +34,5 @@ exports.QbdTypes = void 0;
|
|
|
31
34
|
const Client_1 = __importDefault(require("./Client"));
|
|
32
35
|
// eslint-disable-next-line unicorn/prefer-export-from -- We need `Client` to be the default export, which is impossible to define with `export from`.
|
|
33
36
|
exports.default = Client_1.default;
|
|
37
|
+
__exportStar(require("./error"), exports);
|
|
34
38
|
exports.QbdTypes = __importStar(require("./integrations/qbd/qbdTypes"));
|
package/package.json
CHANGED