conductor-node 8.3.0 → 8.4.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 CHANGED
@@ -158,16 +158,17 @@ const accountAddInput: QbdTypes.AccountAdd = {
158
158
 
159
159
  ## Error Handling
160
160
 
161
- The `ConductorError` has the following properties:
161
+ The `ConductorError` and its subclasses have the following properties:
162
162
 
163
163
  ```ts
164
164
  {
165
165
  // The error type.
166
166
  type: string;
167
- // The error code.
167
+ // The unique error code. This is useful for adding special handling for
168
+ // specific errors.
168
169
  code: string;
169
- // The developer-friendly error message for your logs.
170
- developerMessage: string;
170
+ // The error message for your logs.
171
+ message: string;
171
172
  // The end-user-friendly error message to display in your app.
172
173
  endUserMessage: string;
173
174
  // The HTTP status code.
@@ -177,15 +178,15 @@ The `ConductorError` has the following properties:
177
178
 
178
179
  ### Error Types
179
180
 
180
- The error object you receive will have one of the following category types:
181
+ The error object you receive will have one of the following error types:
181
182
 
182
- | Type | Description |
183
- | ----------------------- | ----------------------------------------------------------------------------------------- |
184
- | `authentication_error` | Conductor can't authenticate you with the information provided. E.g. incorrect API key. |
185
- | `connection_error` | There was a network problem between your server and Conductor. |
186
- | `integration_error` | An error occurred on the third-party integration's end while processing your request. |
187
- | `internal_error` | Something went wrong on Conductor's end. (These are rare.) |
188
- | `invalid_request_error` | You made an API call with the wrong parameters, in the wrong state, or in an invalid way. |
183
+ | Type | Description |
184
+ | ------------------------------ | ------------------------------------------------------------------------------------------------ |
185
+ | `ConductorIntegrationError` | An error occurred on the third-party integration's end while processing your end-user's request. |
186
+ | `ConductorInvalidRequestError` | You made an API call with the wrong parameters, in the wrong state, or in an invalid way. |
187
+ | `ConductorAuthenticationError` | Conductor cannot authenticate you with the credentials you provided. E.g., an incorrect API key. |
188
+ | `ConductorConnectionError` | There was a network problem between the client (on your server) and Conductor's servers. |
189
+ | `ConductorInternalError` | Something went wrong on Conductor's end. (These are rare.) |
189
190
 
190
191
  ### Example
191
192
 
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "conductor-node",
3
- "version": "8.3.0",
3
+ "version": "8.4.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",
@@ -0,0 +1,73 @@
1
+ export declare const DEFAULT_END_USER_MESSAGE = "An internal server error occurred. Please try again later.";
2
+ export interface ConductorErrorOptions {
3
+ readonly type: string;
4
+ readonly code: string;
5
+ readonly message: string;
6
+ readonly endUserMessage?: string;
7
+ readonly statusCode?: number;
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
+ */
13
+ export declare class ConductorError extends Error {
14
+ /**
15
+ * The error type.
16
+ */
17
+ readonly type: string;
18
+ /**
19
+ * The raw error type for internal debugging.
20
+ */
21
+ readonly rawType: string;
22
+ /**
23
+ * The unique error code. This is useful for adding special handling
24
+ * for specific errors.
25
+ */
26
+ readonly code: string;
27
+ /**
28
+ * The end-user-friendly error message to display in your app.
29
+ */
30
+ readonly endUserMessage: string;
31
+ /**
32
+ * The HTTP status code of the response that included the error.
33
+ */
34
+ readonly statusCode: number | undefined;
35
+ constructor(options: ConductorErrorOptions);
36
+ }
37
+ /**
38
+ * Raised when an error occurs on the third-party integration's end while
39
+ * processing your end-user's request. E.g., QBWC failed to connect to
40
+ * QuickBooks Desktop on the end-user's computer.
41
+ */
42
+ export declare class ConductorIntegrationError extends ConductorError {
43
+ }
44
+ /**
45
+ * Raised when you make an API call with the wrong parameters, in the wrong
46
+ * state, or in an invalid way.
47
+ */
48
+ export declare class ConductorInvalidRequestError extends ConductorError {
49
+ }
50
+ /**
51
+ * Raised when Conductor cannot authenticate you with the credentials you
52
+ * provided. E.g., an incorrect API key.
53
+ */
54
+ export declare class ConductorAuthenticationError extends ConductorError {
55
+ }
56
+ /**
57
+ * Raised when there is a network problem between the client (on your server)
58
+ * and Conductor's servers. E.g., a downed network or a bad TLS certificate.
59
+ */
60
+ export declare class ConductorConnectionError extends ConductorError {
61
+ }
62
+ /**
63
+ * Raised when something goes wrong on Conductor's end. (These are rare.)
64
+ */
65
+ export declare class ConductorInternalError extends ConductorError {
66
+ }
67
+ /**
68
+ * Raised as a fallback for any other error from Conductor that no other error
69
+ * type captures.
70
+ */
71
+ export declare class ConductorUnknownError extends ConductorError {
72
+ }
73
+ export declare function generateConductorError(rawConductorError: ConductorErrorOptions): ConductorError;
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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
+ 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
+ */
10
+ class ConductorError extends Error {
11
+ /**
12
+ * The error type.
13
+ */
14
+ type;
15
+ /**
16
+ * The raw error type for internal debugging.
17
+ */
18
+ rawType;
19
+ /**
20
+ * The unique error code. This is useful for adding special handling
21
+ * for specific errors.
22
+ */
23
+ code;
24
+ /**
25
+ * The end-user-friendly error message to display in your app.
26
+ */
27
+ endUserMessage;
28
+ /**
29
+ * The HTTP status code of the response that included the error.
30
+ */
31
+ statusCode;
32
+ constructor(options) {
33
+ super(options.message);
34
+ // Set `name` to the constructor name so that the error appears in logs as
35
+ // `[ConductorError: foo]` instead of `[Error: foo]`.
36
+ this.name = this.constructor.name;
37
+ // 1. Set `type`, even though it's redundant with `name`, because `name`
38
+ // does not appear when doing `console.log(error)` unlike all other
39
+ // properties we set.
40
+ // 2. Set `type` to the constructor name to ensure that subclasses of
41
+ // `ConductorError` always have the correct `type` even if they are
42
+ // instantiated with the wrong options.
43
+ this.type = this.constructor.name;
44
+ this.rawType = options.type;
45
+ this.code = options.code;
46
+ this.endUserMessage = options.endUserMessage ?? exports.DEFAULT_END_USER_MESSAGE;
47
+ this.statusCode = options.statusCode;
48
+ }
49
+ }
50
+ exports.ConductorError = ConductorError;
51
+ /**
52
+ * Raised when an error occurs on the third-party integration's end while
53
+ * processing your end-user's request. E.g., QBWC failed to connect to
54
+ * QuickBooks Desktop on the end-user's computer.
55
+ */
56
+ class ConductorIntegrationError extends ConductorError {
57
+ }
58
+ exports.ConductorIntegrationError = ConductorIntegrationError;
59
+ /**
60
+ * Raised when you make an API call with the wrong parameters, in the wrong
61
+ * state, or in an invalid way.
62
+ */
63
+ class ConductorInvalidRequestError extends ConductorError {
64
+ }
65
+ exports.ConductorInvalidRequestError = ConductorInvalidRequestError;
66
+ /**
67
+ * Raised when Conductor cannot authenticate you with the credentials you
68
+ * provided. E.g., an incorrect API key.
69
+ */
70
+ class ConductorAuthenticationError extends ConductorError {
71
+ }
72
+ exports.ConductorAuthenticationError = ConductorAuthenticationError;
73
+ /**
74
+ * Raised when there is a network problem between the client (on your server)
75
+ * and Conductor's servers. E.g., a downed network or a bad TLS certificate.
76
+ */
77
+ class ConductorConnectionError extends ConductorError {
78
+ }
79
+ exports.ConductorConnectionError = ConductorConnectionError;
80
+ /**
81
+ * Raised when something goes wrong on Conductor's end. (These are rare.)
82
+ */
83
+ class ConductorInternalError extends ConductorError {
84
+ }
85
+ exports.ConductorInternalError = ConductorInternalError;
86
+ /**
87
+ * Raised as a fallback for any other error from Conductor that no other error
88
+ * type captures.
89
+ */
90
+ class ConductorUnknownError extends ConductorError {
91
+ }
92
+ exports.ConductorUnknownError = ConductorUnknownError;
93
+ function generateConductorError(rawConductorError) {
94
+ switch (rawConductorError.type) {
95
+ case "INTEGRATION_ERROR": {
96
+ return new ConductorIntegrationError(rawConductorError);
97
+ }
98
+ case "INVALID_REQUEST_ERROR": {
99
+ return new ConductorInvalidRequestError(rawConductorError);
100
+ }
101
+ case "AUTHENTICATION_ERROR": {
102
+ return new ConductorAuthenticationError(rawConductorError);
103
+ }
104
+ case "CONNECTION_ERROR": {
105
+ return new ConductorConnectionError(rawConductorError);
106
+ }
107
+ case "INTERNAL_ERROR": {
108
+ return new ConductorInternalError(rawConductorError);
109
+ }
110
+ default: {
111
+ return new ConductorUnknownError(rawConductorError);
112
+ }
113
+ }
114
+ }
115
+ exports.generateConductorError = generateConductorError;
@@ -1,7 +1,7 @@
1
- import { ConductorError } from "../error";
1
+ import type { ConductorError } from "../errors";
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 generateConductorError(error: Error): ConductorError;
7
+ export declare function wrapError(error: Error): ConductorError;
@@ -3,9 +3,9 @@ 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.generateConductorError = exports.graphqlOperationWrapper = exports.wrapGraphqlOperations = void 0;
6
+ exports.wrapError = exports.graphqlOperationWrapper = exports.wrapGraphqlOperations = void 0;
7
7
  const package_json_1 = __importDefault(require("../../package.json"));
8
- const error_1 = require("../error");
8
+ const errors_1 = require("../errors");
9
9
  const graphql_request_1 = require("graphql-request");
10
10
  const node_util_1 = __importDefault(require("node:util"));
11
11
  function wrapGraphqlOperations(graphqlOperations, verbose) {
@@ -45,7 +45,7 @@ async function graphqlOperationWrapper(operationName, variables, operation, verb
45
45
  return result;
46
46
  }
47
47
  catch (error) {
48
- const conductorError = generateConductorError(error);
48
+ const conductorError = wrapError(error);
49
49
  if (verbose) {
50
50
  const errorLog = {
51
51
  duration: getDurationString(startTime),
@@ -59,49 +59,44 @@ async function graphqlOperationWrapper(operationName, variables, operation, verb
59
59
  }
60
60
  }
61
61
  exports.graphqlOperationWrapper = graphqlOperationWrapper;
62
- function generateConductorError(error) {
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 new error_1.ConductorError({
67
- type: "connection_error",
68
- code: error_1.DEFAULT_ERROR_CODE,
69
- developerMessage: `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
+ return (0, errors_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
- if (nestedError?.extensions["code"] === "GRAPHQL_VALIDATION_FAILED") {
75
- return new error_1.ConductorError({
76
- type: "temp",
77
- code: error_1.DEFAULT_ERROR_CODE,
78
- developerMessage: `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" to update.`,
79
- statusCode: response.status,
80
- });
81
- }
82
- // TODO: Integrate with new error attributes.
83
- const errorMessage = nestedError?.message ??
84
- // Though `ClientError.response.error` is *not* defined in the type
85
- // definition, we've seen it occur (e.g., attempting to access the
86
- // `development` environment when `ngrok` is not running locally).
87
- response["error"];
88
- console.log("***********************");
89
- if (errorMessage !== undefined) {
90
- return new error_1.ConductorError({
91
- type: "temp",
92
- code: error_1.DEFAULT_ERROR_CODE,
93
- developerMessage: errorMessage,
74
+ const errorExtensions = nestedError?.extensions;
75
+ if (errorExtensions) {
76
+ if (errorExtensions["code"] === "GRAPHQL_VALIDATION_FAILED") {
77
+ return (0, errors_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, errors_1.generateConductorError)({
85
+ type: errorExtensions["type"],
86
+ code: errorExtensions["code"],
87
+ message: nestedError.message,
88
+ endUserMessage: errorExtensions["endUserMessage"],
94
89
  statusCode: response.status,
95
90
  });
96
91
  }
97
92
  }
98
- return new error_1.ConductorError({
99
- type: "temp",
100
- code: error_1.DEFAULT_ERROR_CODE,
101
- developerMessage: "Invalid JSON received from the Conductor API.",
93
+ return (0, errors_1.generateConductorError)({
94
+ type: "INTERNAL_ERROR",
95
+ code: "INVALID_JSON_RESPONSE",
96
+ message: "Invalid JSON received from the Conductor API.",
102
97
  });
103
98
  }
104
- exports.generateConductorError = generateConductorError;
99
+ exports.wrapError = wrapError;
105
100
  function getDurationString(startTime) {
106
101
  const duration = Date.now() - startTime;
107
102
  return `${Math.round(duration / 10) / 100}s`;
@@ -1,4 +1,5 @@
1
1
  import Client from "./Client";
2
2
  export default Client;
3
3
  export { type ClientOptions } from "./Client";
4
+ export * from "./errors";
4
5
  export * as QbdTypes from "./integrations/qbd/qbdTypes";
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("./errors"), exports);
34
38
  exports.QbdTypes = __importStar(require("./integrations/qbd/qbdTypes"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "conductor-node",
3
- "version": "8.3.0",
3
+ "version": "8.4.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,18 +0,0 @@
1
- export declare const DEFAULT_ERROR_CODE = "CONDUCTOR__INTERNAL_SERVER_ERROR";
2
- export declare const DEFAULT_END_USER_MESSAGE = "An internal server error occurred. Please try again later.";
3
- interface ConductorRawError {
4
- readonly type: string;
5
- readonly code: string;
6
- readonly developerMessage: string;
7
- readonly endUserMessage?: string;
8
- readonly statusCode?: number;
9
- }
10
- export declare class ConductorError extends Error {
11
- readonly type: string;
12
- readonly code: string;
13
- readonly developerMessage: string;
14
- readonly endUserMessage: string;
15
- readonly statusCode: number | undefined;
16
- constructor(raw: ConductorRawError);
17
- }
18
- export {};
package/dist/src/error.js DELETED
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConductorError = exports.DEFAULT_END_USER_MESSAGE = exports.DEFAULT_ERROR_CODE = void 0;
4
- exports.DEFAULT_ERROR_CODE = "CONDUCTOR__INTERNAL_SERVER_ERROR";
5
- exports.DEFAULT_END_USER_MESSAGE = "An internal server error occurred. Please try again later.";
6
- class ConductorError extends Error {
7
- type;
8
- code;
9
- developerMessage;
10
- endUserMessage;
11
- statusCode;
12
- constructor(raw) {
13
- super(raw.developerMessage);
14
- this.name = "ConductorError";
15
- this.type = raw.type;
16
- this.code = raw.code;
17
- this.developerMessage = raw.developerMessage;
18
- this.endUserMessage = raw.endUserMessage ?? exports.DEFAULT_END_USER_MESSAGE;
19
- this.statusCode = raw.statusCode;
20
- }
21
- }
22
- exports.ConductorError = ConductorError;