conductor-node 7.4.11 → 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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "conductor-node",
3
- "version": "7.4.11",
3
+ "version": "7.5.0",
4
4
  "description": "Easily integrate with the entire QuickBooks Desktop API with fully-typed async TypeScript",
5
5
  "author": "Danny Nemer <hi@DannyNemer.com>",
6
6
  "license": "MIT",
@@ -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
  }
@@ -10,19 +10,16 @@ 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.serverURL = (0, environment_1.getServerUrlForEnvironment)(serverEnvironment);
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(`Client sent request to ${this.serverURL}:`, operationName, node_util_1.default.inspect(variables, { depth: undefined, colors: true }));
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
- console.timeEnd("Request time");
107
- console.log(`Client received response from ${this.serverURL}:`, node_util_1.default.inspect(result, { depth: undefined, colors: true }));
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
- console.timeEnd("Request time");
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
- 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
- }
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) {
@@ -1,4 +1,4 @@
1
1
  import Client from "./Client";
2
2
  export default Client;
3
3
  export { type ClientOptions } from "./Client";
4
- export * as Types from "./integrations/types";
4
+ export * as QbdTypes from "./integrations/qbd/qbdTypes";
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.Types = void 0;
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.Types = __importStar(require("./integrations/types"));
34
+ exports.QbdTypes = __importStar(require("./integrations/qbd/qbdTypes"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "conductor-node",
3
- "version": "7.4.11",
3
+ "version": "7.5.0",
4
4
  "description": "Easily integrate with the entire QuickBooks Desktop API with fully-typed async TypeScript",
5
5
  "author": "Danny Nemer <hi@DannyNemer.com>",
6
6
  "license": "MIT",
@@ -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"));