conductor-node 7.4.10 → 7.5.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 +16 -0
- package/dist/package.json +1 -1
- package/dist/src/Client.d.ts +2 -2
- package/dist/src/Client.js +47 -28
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +2 -2
- package/dist/src/{environment.d.ts → utils/environment.d.ts} +1 -2
- package/dist/src/{environment.js → utils/environment.js} +0 -4
- package/package.json +1 -1
- package/dist/src/integrations/types.d.ts +0 -1
- package/dist/src/integrations/types.js +0 -27
package/README.md
CHANGED
|
@@ -130,3 +130,19 @@ The response includes the following:
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
```
|
|
133
|
+
|
|
134
|
+
## TypeScript
|
|
135
|
+
|
|
136
|
+
Access the full QuickBooks Desktop API through TypeScript. The `qbd.*` APIs are fully-typed with inline documentation and will autocomplete in your editor.
|
|
137
|
+
|
|
138
|
+
To manually access the QBD types, import them from `conductor-node` like so:
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
import { QbdTypes } from "conductor-node";
|
|
142
|
+
|
|
143
|
+
const accountAddInput: QbdTypes.AccountAdd = {
|
|
144
|
+
Name: "Test Account",
|
|
145
|
+
AccountType: "Bank",
|
|
146
|
+
OpenBalance: "100",
|
|
147
|
+
};
|
|
148
|
+
```
|
package/dist/package.json
CHANGED
package/dist/src/Client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Environment } from "./environment";
|
|
2
1
|
import type { GraphqlCreateIntegrationConnectionInput, GraphqlCreateIntegrationConnectionMutation, GraphqlGetConnectionStatusQuery, GraphqlGetConnectionStatusQueryVariables, GraphqlGetIntegrationConnectionQuery, GraphqlGetIntegrationConnectionQueryVariables, GraphqlGetIntegrationConnectionsQuery, GraphqlSendIntegrationRequestInput, GraphqlSendIntegrationRequestMutation } from "./graphql/__generated__/operationTypes";
|
|
3
2
|
import QbdIntegration from "./integrations/qbd/QbdIntegration";
|
|
3
|
+
import type { Environment } from "./utils/environment";
|
|
4
4
|
export interface ClientOptions {
|
|
5
5
|
/** Log each request and response. */
|
|
6
6
|
readonly verbose?: boolean;
|
|
@@ -10,7 +10,6 @@ export default class Client {
|
|
|
10
10
|
/** QuickBooks Desktop integration. */
|
|
11
11
|
readonly qbd: QbdIntegration;
|
|
12
12
|
private readonly verbose;
|
|
13
|
-
private readonly serverURL;
|
|
14
13
|
private readonly graphqlClient;
|
|
15
14
|
private readonly graphqlOperations;
|
|
16
15
|
constructor(apiKey: string, { verbose, serverEnvironment }?: ClientOptions);
|
|
@@ -53,5 +52,6 @@ export default class Client {
|
|
|
53
52
|
}): Promise<GraphqlCreateIntegrationConnectionMutation["createIntegrationConnection"]>;
|
|
54
53
|
sendIntegrationRequest(input: GraphqlSendIntegrationRequestInput): Promise<GraphqlSendIntegrationRequestMutation["sendIntegrationRequest"]["response"]>;
|
|
55
54
|
private graphqlOperationWrapper;
|
|
55
|
+
private reformatError;
|
|
56
56
|
private checkForUpdates;
|
|
57
57
|
}
|
package/dist/src/Client.js
CHANGED
|
@@ -4,25 +4,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const package_json_1 = __importDefault(require("./../package.json"));
|
|
7
|
-
const environment_1 = require("./environment");
|
|
8
7
|
const operationTypes_1 = require("./graphql/__generated__/operationTypes");
|
|
9
8
|
const QbdIntegration_1 = __importDefault(require("./integrations/qbd/QbdIntegration"));
|
|
9
|
+
const environment_1 = require("./utils/environment");
|
|
10
10
|
const chalk_1 = __importDefault(require("chalk"));
|
|
11
11
|
const graphql_request_1 = require("graphql-request");
|
|
12
12
|
const node_child_process_1 = require("node:child_process");
|
|
13
|
-
const node_util_1 = __importDefault(require("node:util"));
|
|
14
13
|
class Client {
|
|
15
14
|
/** QuickBooks Desktop integration. */
|
|
16
15
|
qbd;
|
|
17
16
|
verbose;
|
|
18
|
-
serverURL;
|
|
19
17
|
graphqlClient;
|
|
20
18
|
graphqlOperations;
|
|
21
19
|
constructor(apiKey, { verbose = false, serverEnvironment = "production" } = {}) {
|
|
22
20
|
this.checkForUpdates();
|
|
23
21
|
this.verbose = verbose;
|
|
24
|
-
this.
|
|
25
|
-
this.graphqlClient = new graphql_request_1.GraphQLClient(`${this.serverURL}/graphql`, {
|
|
22
|
+
this.graphqlClient = new graphql_request_1.GraphQLClient(`${(0, environment_1.getServerUrlForEnvironment)(serverEnvironment)}/graphql`, {
|
|
26
23
|
headers: {
|
|
27
24
|
Authorization: `Bearer ${apiKey}`,
|
|
28
25
|
"User-Agent": `${package_json_1.default.name}/${package_json_1.default.version} (Node.js ${process.version}; ${process.platform} ${process.arch})`,
|
|
@@ -96,42 +93,64 @@ class Client {
|
|
|
96
93
|
.then((result) => result.sendIntegrationRequest.response);
|
|
97
94
|
}
|
|
98
95
|
async graphqlOperationWrapper(operationName, variables, operation) {
|
|
96
|
+
const graphqlInfo = {
|
|
97
|
+
operationName,
|
|
98
|
+
input: variables
|
|
99
|
+
? Object.keys(variables).length === 1 && "input" in variables
|
|
100
|
+
? variables["input"] // Flatten the input if it only has one key called "input".
|
|
101
|
+
: variables
|
|
102
|
+
: {},
|
|
103
|
+
};
|
|
99
104
|
if (this.verbose) {
|
|
100
|
-
console.log(`
|
|
101
|
-
console.time("Request time");
|
|
105
|
+
console.log(`Conductor request start: ${JSON.stringify(graphqlInfo, undefined, 2)}`);
|
|
102
106
|
}
|
|
107
|
+
const startTime = Date.now();
|
|
103
108
|
try {
|
|
104
109
|
const result = await operation(variables);
|
|
105
110
|
if (this.verbose) {
|
|
106
|
-
|
|
107
|
-
|
|
111
|
+
const responseInfo = {
|
|
112
|
+
duration: `${(Date.now() - startTime) / 1000}s`,
|
|
113
|
+
...graphqlInfo,
|
|
114
|
+
};
|
|
115
|
+
const responseString = JSON.stringify(responseInfo, undefined, 2);
|
|
116
|
+
console.log(`Conductor response: ${responseString}`);
|
|
108
117
|
}
|
|
109
118
|
return result;
|
|
110
119
|
}
|
|
111
120
|
catch (error) {
|
|
121
|
+
const formattedError = this.reformatError(error);
|
|
112
122
|
if (this.verbose) {
|
|
113
|
-
|
|
123
|
+
const errorInfo = {
|
|
124
|
+
duration: `${(Date.now() - startTime) / 1000}s`,
|
|
125
|
+
error: String(formattedError),
|
|
126
|
+
...graphqlInfo,
|
|
127
|
+
};
|
|
128
|
+
const errorString = JSON.stringify(errorInfo, undefined, 2);
|
|
129
|
+
console.log(`Conductor error: ${errorString}`);
|
|
114
130
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
throw formattedError;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
reformatError(error) {
|
|
135
|
+
if (error instanceof graphql_request_1.ClientError) {
|
|
136
|
+
const { response } = error;
|
|
137
|
+
if ([404, 502, 503].includes(response.status)) {
|
|
138
|
+
return new Error(`The Conductor server returned a ${response.status} error, which may indicate that the server is down. Please alert the Conductor team if this error persists.`);
|
|
139
|
+
}
|
|
140
|
+
const nestedError = response.errors?.[0];
|
|
141
|
+
if (nestedError?.extensions["code"] === "GRAPHQL_VALIDATION_FAILED") {
|
|
142
|
+
return new Error(`The Conductor server is no longer compatible with your version of "${package_json_1.default.name}". Please run "yarn upgrade ${package_json_1.default.name}@latest --latest" to update.`);
|
|
143
|
+
}
|
|
144
|
+
const errorMessage = nestedError?.message ??
|
|
145
|
+
// Though `ClientError.response.error` is *not* defined in the type
|
|
146
|
+
// definition, we've seen it occur (e.g., attempting to access the
|
|
147
|
+
// `development` environment when `ngrok` is not running locally).
|
|
148
|
+
response["error"];
|
|
149
|
+
if (errorMessage !== undefined) {
|
|
150
|
+
return new Error(errorMessage);
|
|
132
151
|
}
|
|
133
|
-
throw error;
|
|
134
152
|
}
|
|
153
|
+
return error;
|
|
135
154
|
}
|
|
136
155
|
checkForUpdates() {
|
|
137
156
|
if (environment_1.currentEnvironment.isTest) {
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -26,9 +26,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
29
|
+
exports.QbdTypes = void 0;
|
|
30
30
|
// eslint-disable-next-line consistent-default-export-name/default-export-match-filename -- This file defines the exports for the `conductor-node` package, as defined by `main` in `package.json`. Hence, no other internal code imports this module and we can ignore the error that that the file's name must match the default export (`Client`).
|
|
31
31
|
const Client_1 = __importDefault(require("./Client"));
|
|
32
32
|
// 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
33
|
exports.default = Client_1.default;
|
|
34
|
-
exports.
|
|
34
|
+
exports.QbdTypes = __importStar(require("./integrations/qbd/qbdTypes"));
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
export type Environment = "development" | "production" | "
|
|
1
|
+
export type Environment = "development" | "production" | "test";
|
|
2
2
|
export declare const currentEnvironment: {
|
|
3
3
|
name: Environment;
|
|
4
4
|
isTest: boolean;
|
|
5
5
|
isDevelopment: boolean;
|
|
6
|
-
isStaging: boolean;
|
|
7
6
|
isProduction: boolean;
|
|
8
7
|
};
|
|
9
8
|
export declare function getServerUrlForEnvironment(environment: Environment): string;
|
|
@@ -6,7 +6,6 @@ exports.currentEnvironment = {
|
|
|
6
6
|
name: currentEnvironmentName,
|
|
7
7
|
isTest: currentEnvironmentName === "test",
|
|
8
8
|
isDevelopment: currentEnvironmentName === "development",
|
|
9
|
-
isStaging: currentEnvironmentName === "staging",
|
|
10
9
|
isProduction: currentEnvironmentName === "production",
|
|
11
10
|
};
|
|
12
11
|
function getServerUrlForEnvironment(environment) {
|
|
@@ -18,9 +17,6 @@ function getServerUrlForEnvironment(environment) {
|
|
|
18
17
|
case "development": {
|
|
19
18
|
return "https://conductor.ngrok.io";
|
|
20
19
|
}
|
|
21
|
-
case "staging": {
|
|
22
|
-
return "https://staging.api.conductor.is";
|
|
23
|
-
}
|
|
24
20
|
case "production": {
|
|
25
21
|
return "https://production.api.conductor.is";
|
|
26
22
|
}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as qbd from "../integrations/qbd/qbdTypes";
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.qbd = void 0;
|
|
27
|
-
exports.qbd = __importStar(require("../integrations/qbd/qbdTypes"));
|