conductor-node 7.5.0 → 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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "conductor-node",
3
- "version": "7.5.0",
3
+ "version": "7.5.1",
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",
@@ -9,7 +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
12
  private readonly graphqlClient;
14
13
  private readonly graphqlOperations;
15
14
  constructor(apiKey: string, { verbose, serverEnvironment }?: ClientOptions);
@@ -50,8 +49,6 @@ export default class Client {
50
49
  createIntegrationConnection(input: GraphqlCreateIntegrationConnectionInput & {
51
50
  integrationKey: "quickbooks-desktop";
52
51
  }): Promise<GraphqlCreateIntegrationConnectionMutation["createIntegrationConnection"]>;
52
+ /** Not intended for public use. */
53
53
  sendIntegrationRequest(input: GraphqlSendIntegrationRequestInput): Promise<GraphqlSendIntegrationRequestMutation["sendIntegrationRequest"]["response"]>;
54
- private graphqlOperationWrapper;
55
- private reformatError;
56
- private checkForUpdates;
57
54
  }
@@ -4,34 +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
13
  class Client {
14
14
  /** QuickBooks Desktop integration. */
15
15
  qbd;
16
- verbose;
17
16
  graphqlClient;
18
17
  graphqlOperations;
19
18
  constructor(apiKey, { verbose = false, serverEnvironment = "production" } = {}) {
20
- this.checkForUpdates();
21
- this.verbose = verbose;
19
+ (0, checkForUpdates_1.default)();
22
20
  this.graphqlClient = new graphql_request_1.GraphQLClient(`${(0, environment_1.getServerUrlForEnvironment)(serverEnvironment)}/graphql`, {
23
21
  headers: {
24
22
  Authorization: `Bearer ${apiKey}`,
25
23
  "User-Agent": `${package_json_1.default.name}/${package_json_1.default.version} (Node.js ${process.version}; ${process.platform} ${process.arch})`,
26
24
  },
27
25
  });
28
- this.graphqlOperations = (0, operationTypes_1.getSdk)(this.graphqlClient);
29
- Object.entries(this.graphqlOperations).forEach(([operationName, operation]) => {
30
- // @ts-expect-error -- `operationName` is a key of `this.gqlOperations`.
31
- this.graphqlOperations[operationName] = async (variables) => this.graphqlOperationWrapper(operationName, variables,
32
- // @ts-expect-error -- It is safe to call `operation` with `variables`.
33
- operation);
34
- });
26
+ this.graphqlOperations = (0, graphqlOperationWrapper_1.wrapGraphqlOperations)((0, operationTypes_1.getSdk)(this.graphqlClient), verbose);
35
27
  this.qbd = new QbdIntegration_1.default(this);
36
28
  }
37
29
  async getIntegrationConnection(integrationConnectionId) {
@@ -85,84 +77,12 @@ class Client {
85
77
  .createIntegrationConnection({ input })
86
78
  .then((result) => result.createIntegrationConnection);
87
79
  }
88
- // TODO: Hide this method from the dev-user while still allowing the
89
- // integration clients to access it.
80
+ // TODO: Find a way to make this private.
81
+ /** Not intended for public use. */
90
82
  async sendIntegrationRequest(input) {
91
83
  return this.graphqlOperations
92
84
  .sendIntegrationRequest({ input })
93
85
  .then((result) => result.sendIntegrationRequest.response);
94
86
  }
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
- };
104
- if (this.verbose) {
105
- console.log(`Conductor request start: ${JSON.stringify(graphqlInfo, undefined, 2)}`);
106
- }
107
- const startTime = Date.now();
108
- try {
109
- const result = await operation(variables);
110
- if (this.verbose) {
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}`);
117
- }
118
- return result;
119
- }
120
- catch (error) {
121
- const formattedError = this.reformatError(error);
122
- if (this.verbose) {
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}`);
130
- }
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);
151
- }
152
- }
153
- return error;
154
- }
155
- checkForUpdates() {
156
- if (environment_1.currentEnvironment.isTest) {
157
- return;
158
- }
159
- const currentVersion = package_json_1.default.version;
160
- const latestVersion = (0, node_child_process_1.execSync)(`yarn info ${package_json_1.default.name} version`)
161
- .toString()
162
- .trim();
163
- if (currentVersion !== latestVersion) {
164
- 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.`));
165
- }
166
- }
167
87
  }
168
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
+ }
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "conductor-node",
3
- "version": "7.5.0",
3
+ "version": "7.5.1",
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,2 +0,0 @@
1
- export declare const CONDUCTOR_TEST_API_KEY = "063d95bc-a6f7-4b4b-841d-8007648a3112";
2
- export declare const CONDUCTOR_TEST_QBD_CONNECTION_ID = "49ee2e46-ec5a-40a0-8c37-43913994b2a9";
@@ -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";