conductor-node 7.4.11 → 7.5.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.
- package/README.md +16 -0
- package/dist/package.json +1 -1
- package/dist/src/Client.d.ts +1 -4
- package/dist/src/Client.js +7 -68
- package/dist/src/graphql/graphqlOperationWrapper.d.ts +6 -0
- package/dist/src/graphql/graphqlOperationWrapper.js +86 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +2 -2
- package/dist/src/utils/checkForUpdates.d.ts +1 -0
- package/dist/src/utils/checkForUpdates.js +22 -0
- package/package.json +1 -1
- package/dist/src/integrations/types.d.ts +0 -1
- package/dist/src/integrations/types.js +0 -27
- package/dist/src/utils/testConstants.d.ts +0 -2
- package/dist/src/utils/testConstants.js +0 -5
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
|
@@ -9,8 +9,6 @@ export interface ClientOptions {
|
|
|
9
9
|
export default class Client {
|
|
10
10
|
/** QuickBooks Desktop integration. */
|
|
11
11
|
readonly qbd: QbdIntegration;
|
|
12
|
-
private readonly verbose;
|
|
13
|
-
private readonly serverURL;
|
|
14
12
|
private readonly graphqlClient;
|
|
15
13
|
private readonly graphqlOperations;
|
|
16
14
|
constructor(apiKey: string, { verbose, serverEnvironment }?: ClientOptions);
|
|
@@ -51,7 +49,6 @@ export default class Client {
|
|
|
51
49
|
createIntegrationConnection(input: GraphqlCreateIntegrationConnectionInput & {
|
|
52
50
|
integrationKey: "quickbooks-desktop";
|
|
53
51
|
}): Promise<GraphqlCreateIntegrationConnectionMutation["createIntegrationConnection"]>;
|
|
52
|
+
/** Not intended for public use. */
|
|
54
53
|
sendIntegrationRequest(input: GraphqlSendIntegrationRequestInput): Promise<GraphqlSendIntegrationRequestMutation["sendIntegrationRequest"]["response"]>;
|
|
55
|
-
private graphqlOperationWrapper;
|
|
56
|
-
private checkForUpdates;
|
|
57
54
|
}
|
package/dist/src/Client.js
CHANGED
|
@@ -4,37 +4,26 @@ 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 graphqlOperationWrapper_1 = require("./graphql/graphqlOperationWrapper");
|
|
7
8
|
const operationTypes_1 = require("./graphql/__generated__/operationTypes");
|
|
8
9
|
const QbdIntegration_1 = __importDefault(require("./integrations/qbd/QbdIntegration"));
|
|
10
|
+
const checkForUpdates_1 = __importDefault(require("./utils/checkForUpdates"));
|
|
9
11
|
const environment_1 = require("./utils/environment");
|
|
10
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
11
12
|
const graphql_request_1 = require("graphql-request");
|
|
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
|
-
verbose;
|
|
18
|
-
serverURL;
|
|
19
16
|
graphqlClient;
|
|
20
17
|
graphqlOperations;
|
|
21
18
|
constructor(apiKey, { verbose = false, serverEnvironment = "production" } = {}) {
|
|
22
|
-
|
|
23
|
-
this.
|
|
24
|
-
this.serverURL = (0, environment_1.getServerUrlForEnvironment)(serverEnvironment);
|
|
25
|
-
this.graphqlClient = new graphql_request_1.GraphQLClient(`${this.serverURL}/graphql`, {
|
|
19
|
+
(0, checkForUpdates_1.default)();
|
|
20
|
+
this.graphqlClient = new graphql_request_1.GraphQLClient(`${(0, environment_1.getServerUrlForEnvironment)(serverEnvironment)}/graphql`, {
|
|
26
21
|
headers: {
|
|
27
22
|
Authorization: `Bearer ${apiKey}`,
|
|
28
23
|
"User-Agent": `${package_json_1.default.name}/${package_json_1.default.version} (Node.js ${process.version}; ${process.platform} ${process.arch})`,
|
|
29
24
|
},
|
|
30
25
|
});
|
|
31
|
-
this.graphqlOperations = (0, operationTypes_1.getSdk)(this.graphqlClient);
|
|
32
|
-
Object.entries(this.graphqlOperations).forEach(([operationName, operation]) => {
|
|
33
|
-
// @ts-expect-error -- `operationName` is a key of `this.gqlOperations`.
|
|
34
|
-
this.graphqlOperations[operationName] = async (variables) => this.graphqlOperationWrapper(operationName, variables,
|
|
35
|
-
// @ts-expect-error -- It is safe to call `operation` with `variables`.
|
|
36
|
-
operation);
|
|
37
|
-
});
|
|
26
|
+
this.graphqlOperations = (0, graphqlOperationWrapper_1.wrapGraphqlOperations)((0, operationTypes_1.getSdk)(this.graphqlClient), verbose);
|
|
38
27
|
this.qbd = new QbdIntegration_1.default(this);
|
|
39
28
|
}
|
|
40
29
|
async getIntegrationConnection(integrationConnectionId) {
|
|
@@ -88,62 +77,12 @@ class Client {
|
|
|
88
77
|
.createIntegrationConnection({ input })
|
|
89
78
|
.then((result) => result.createIntegrationConnection);
|
|
90
79
|
}
|
|
91
|
-
// TODO:
|
|
92
|
-
|
|
80
|
+
// TODO: Find a way to make this private.
|
|
81
|
+
/** Not intended for public use. */
|
|
93
82
|
async sendIntegrationRequest(input) {
|
|
94
83
|
return this.graphqlOperations
|
|
95
84
|
.sendIntegrationRequest({ input })
|
|
96
85
|
.then((result) => result.sendIntegrationRequest.response);
|
|
97
86
|
}
|
|
98
|
-
async graphqlOperationWrapper(operationName, variables, operation) {
|
|
99
|
-
if (this.verbose) {
|
|
100
|
-
console.log(`Client sent request to ${this.serverURL}:`, operationName, node_util_1.default.inspect(variables, { depth: undefined, colors: true }));
|
|
101
|
-
console.time("Request time");
|
|
102
|
-
}
|
|
103
|
-
try {
|
|
104
|
-
const result = await operation(variables);
|
|
105
|
-
if (this.verbose) {
|
|
106
|
-
console.timeEnd("Request time");
|
|
107
|
-
console.log(`Client received response from ${this.serverURL}:`, node_util_1.default.inspect(result, { depth: undefined, colors: true }));
|
|
108
|
-
}
|
|
109
|
-
return result;
|
|
110
|
-
}
|
|
111
|
-
catch (error) {
|
|
112
|
-
if (this.verbose) {
|
|
113
|
-
console.timeEnd("Request time");
|
|
114
|
-
}
|
|
115
|
-
if (error instanceof graphql_request_1.ClientError) {
|
|
116
|
-
const { response } = error;
|
|
117
|
-
if ([404, 502, 503].includes(response.status)) {
|
|
118
|
-
throw 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.`);
|
|
119
|
-
}
|
|
120
|
-
const nestedError = response.errors?.[0];
|
|
121
|
-
if (nestedError?.extensions["code"] === "GRAPHQL_VALIDATION_FAILED") {
|
|
122
|
-
throw 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.`);
|
|
123
|
-
}
|
|
124
|
-
const errorMessage = nestedError?.message ??
|
|
125
|
-
// Though `ClientError.response.error` is *not* defined in the type
|
|
126
|
-
// definition, we've seen it occur (e.g., attempting to access the
|
|
127
|
-
// `development` environment when `ngrok` is not running locally).
|
|
128
|
-
response["error"];
|
|
129
|
-
if (errorMessage !== undefined) {
|
|
130
|
-
throw new Error(errorMessage);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
throw error;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
checkForUpdates() {
|
|
137
|
-
if (environment_1.currentEnvironment.isTest) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
const currentVersion = package_json_1.default.version;
|
|
141
|
-
const latestVersion = (0, node_child_process_1.execSync)(`yarn info ${package_json_1.default.name} version`)
|
|
142
|
-
.toString()
|
|
143
|
-
.trim();
|
|
144
|
-
if (currentVersion !== latestVersion) {
|
|
145
|
-
console.warn(chalk_1.default.yellow(`⚠️ A new version of Conductor is available! You are using "${package_json_1.default.name}" version ${currentVersion} but the latest version is ${latestVersion}. Please run "yarn upgrade ${package_json_1.default.name} --latest" to update.`));
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
87
|
}
|
|
149
88
|
exports.default = Client;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { getSdk } from "../graphql/__generated__/operationTypes";
|
|
2
|
+
export declare function wrapGraphqlOperations<T extends ReturnType<typeof getSdk>>(graphqlOperations: T, verbose: boolean): T;
|
|
3
|
+
export declare function graphqlOperationWrapper<V extends {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}, R>(operationName: string, variables: V | undefined, operation: (variables: V | undefined) => Promise<R>, verbose: boolean): Promise<R>;
|
|
6
|
+
export declare function formatGraphqlError(error: Error): Error;
|
|
@@ -0,0 +1,86 @@
|
|
|
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.formatGraphqlError = exports.graphqlOperationWrapper = exports.wrapGraphqlOperations = void 0;
|
|
7
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
|
8
|
+
const graphql_request_1 = require("graphql-request");
|
|
9
|
+
const node_util_1 = __importDefault(require("node:util"));
|
|
10
|
+
function wrapGraphqlOperations(graphqlOperations, verbose) {
|
|
11
|
+
return Object.fromEntries(Object.entries(graphqlOperations).map(([operationName, operation]) => [
|
|
12
|
+
operationName,
|
|
13
|
+
async (variables) => graphqlOperationWrapper(operationName,
|
|
14
|
+
// @ts-expect-error -- It is safe to call `operation` with `variables`.
|
|
15
|
+
variables, operation, verbose),
|
|
16
|
+
]));
|
|
17
|
+
}
|
|
18
|
+
exports.wrapGraphqlOperations = wrapGraphqlOperations;
|
|
19
|
+
async function graphqlOperationWrapper(operationName, variables, operation, verbose) {
|
|
20
|
+
const graphqlInfo = {
|
|
21
|
+
operationName,
|
|
22
|
+
input: variables
|
|
23
|
+
? Object.keys(variables).length === 1 && "input" in variables
|
|
24
|
+
? variables["input"] // Flatten the input if it only has one key called "input".
|
|
25
|
+
: variables
|
|
26
|
+
: {},
|
|
27
|
+
};
|
|
28
|
+
if (verbose) {
|
|
29
|
+
console.log(`Conductor request sent: ${node_util_1.default.inspect(graphqlInfo, {
|
|
30
|
+
depth: undefined,
|
|
31
|
+
})}`);
|
|
32
|
+
}
|
|
33
|
+
const startTime = Date.now();
|
|
34
|
+
try {
|
|
35
|
+
const result = await operation(variables);
|
|
36
|
+
if (verbose) {
|
|
37
|
+
const responseInfo = {
|
|
38
|
+
duration: getDurationString(startTime),
|
|
39
|
+
...graphqlInfo,
|
|
40
|
+
};
|
|
41
|
+
const responseString = node_util_1.default.inspect(responseInfo, { depth: undefined });
|
|
42
|
+
console.log(`Conductor response: ${responseString}`);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
const formattedError = formatGraphqlError(error);
|
|
48
|
+
if (verbose) {
|
|
49
|
+
const errorInfo = {
|
|
50
|
+
duration: getDurationString(startTime),
|
|
51
|
+
error: String(formattedError),
|
|
52
|
+
...graphqlInfo,
|
|
53
|
+
};
|
|
54
|
+
const errorString = node_util_1.default.inspect(errorInfo, { depth: undefined });
|
|
55
|
+
console.log(`Conductor error: ${errorString}`);
|
|
56
|
+
}
|
|
57
|
+
throw formattedError;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.graphqlOperationWrapper = graphqlOperationWrapper;
|
|
61
|
+
function formatGraphqlError(error) {
|
|
62
|
+
if (error instanceof graphql_request_1.ClientError) {
|
|
63
|
+
const { response } = error;
|
|
64
|
+
if ([404, 502, 503].includes(response.status)) {
|
|
65
|
+
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.`);
|
|
66
|
+
}
|
|
67
|
+
const nestedError = response.errors?.[0];
|
|
68
|
+
if (nestedError?.extensions["code"] === "GRAPHQL_VALIDATION_FAILED") {
|
|
69
|
+
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.`);
|
|
70
|
+
}
|
|
71
|
+
const errorMessage = nestedError?.message ??
|
|
72
|
+
// Though `ClientError.response.error` is *not* defined in the type
|
|
73
|
+
// definition, we've seen it occur (e.g., attempting to access the
|
|
74
|
+
// `development` environment when `ngrok` is not running locally).
|
|
75
|
+
response["error"];
|
|
76
|
+
if (errorMessage !== undefined) {
|
|
77
|
+
return new Error(errorMessage);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return error;
|
|
81
|
+
}
|
|
82
|
+
exports.formatGraphqlError = formatGraphqlError;
|
|
83
|
+
function getDurationString(startTime) {
|
|
84
|
+
const duration = Date.now() - startTime;
|
|
85
|
+
return `${Math.round(duration / 10) / 100}s`;
|
|
86
|
+
}
|
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"));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function checkForUpdates(): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
|
7
|
+
const environment_1 = require("../utils/environment");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const node_child_process_1 = require("node:child_process");
|
|
10
|
+
function checkForUpdates() {
|
|
11
|
+
if (environment_1.currentEnvironment.isTest) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const currentVersion = package_json_1.default.version;
|
|
15
|
+
const latestVersion = (0, node_child_process_1.execSync)(`yarn info ${package_json_1.default.name} version`)
|
|
16
|
+
.toString()
|
|
17
|
+
.trim();
|
|
18
|
+
if (currentVersion !== latestVersion) {
|
|
19
|
+
console.warn(chalk_1.default.yellow(`⚠️ A new version of Conductor is available! You are using "${package_json_1.default.name}" version ${currentVersion} but the latest version is ${latestVersion}. Please run "yarn upgrade ${package_json_1.default.name} --latest" to update.`));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.default = checkForUpdates;
|
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"));
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CONDUCTOR_TEST_QBD_CONNECTION_ID = exports.CONDUCTOR_TEST_API_KEY = void 0;
|
|
4
|
-
exports.CONDUCTOR_TEST_API_KEY = "063d95bc-a6f7-4b4b-841d-8007648a3112";
|
|
5
|
-
exports.CONDUCTOR_TEST_QBD_CONNECTION_ID = "49ee2e46-ec5a-40a0-8c37-43913994b2a9";
|