conductor-node 7.5.0 → 8.0.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
@@ -42,9 +42,11 @@ Create a new integration-connection.
42
42
  const newQbdConnection = await conductor.createIntegrationConnection({
43
43
  // The identifier of the third-party platform to integrate.
44
44
  integrationKey: "quickbooks-desktop",
45
+ // Your end-user's unique ID in your product's database. Must be distinct
46
+ // from your other connections for the same integration.
47
+ endUserSourceId: "1234-abcd",
45
48
  // Your end-user's email address for identification only. No emails
46
- // will be sent. Must be distinct from your other connections for the
47
- // same `integrationKey`.
49
+ // will be sent.
48
50
  endUserEmail: "danny@constructionco.com",
49
51
  // Your end-user's company name that will be shown elsewhere in Conductor.
50
52
  endUserCompanyName: "Construction Corp",
@@ -69,6 +71,7 @@ The response includes the following:
69
71
  // this end-user's integration in the future.
70
72
  id: '{UUID}',
71
73
  integrationKey: 'quickbooks-desktop',
74
+ endUserSourceId: "1234-abcd",
72
75
  endUserEmail: 'danny@constructionco.com',
73
76
  endUserCompanyName: 'Construction Corp',
74
77
  lastHeartbeatAt: null
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "conductor-node",
3
- "version": "7.5.0",
3
+ "version": "8.0.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",
@@ -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);
@@ -26,12 +25,13 @@ export default class Client {
26
25
  * @param integrationConnectionId The ID of the integration connection.
27
26
  * @returns result Object with the following properties:
28
27
  * @returns result.isConnected Whether we can connect to the end-user's QBD.
29
- * @returns result.devErrorMessage If `isConnected=false`, this will be the
30
- * corresponding error message for the developer; e.g., "The end-user's
31
- * computer is likely off".
32
- * @returns result.endUserErrorMessage If `isConnected=false`, this will be
33
- * the corresponding error message for the end-user; e.g., "Please ensure your
34
- * computer is on and QuickBooks Desktop is open".
28
+ * @returns result.error If `isConnected=false`, this will be an object with
29
+ * the following properties:
30
+ * @returns result.error.code The unique error code.
31
+ * @returns result.error.developerMessage The technical error message for the
32
+ * developer.
33
+ * @returns result.error.endUserMessage The user-friendly error message to
34
+ * display to the the end-user.
35
35
  */
36
36
  getConnectionStatus(integrationConnectionId: GraphqlGetConnectionStatusQueryVariables["integrationConnectionId"]): Promise<GraphqlGetConnectionStatusQuery["integrationConnection"]["connectionStatus"]>;
37
37
  /**
@@ -40,9 +40,11 @@ export default class Client {
40
40
  * @param input - The input object to create the integration connection.
41
41
  * @param input.integrationKey The identifier of the third-party platform to
42
42
  * integrate.
43
+ * @param input.endUserSourceId Your end-user's unique ID in your product's
44
+ * database. Must be distinct from your other connections for the same
45
+ * integration.
43
46
  * @param input.endUserEmail Your end-user's email address for identification
44
- * only. No emails will be sent. Must be distinct from your other connections
45
- * for the same integration.
47
+ * only. No emails will be sent.
46
48
  * @param input.endUserCompanyName Your end-user's company name that will be
47
49
  * shown elsewhere in Conductor.
48
50
  * @returns The newly created integration connection.
@@ -50,8 +52,6 @@ export default class Client {
50
52
  createIntegrationConnection(input: GraphqlCreateIntegrationConnectionInput & {
51
53
  integrationKey: "quickbooks-desktop";
52
54
  }): Promise<GraphqlCreateIntegrationConnectionMutation["createIntegrationConnection"]>;
55
+ /** Not intended for public use. */
53
56
  sendIntegrationRequest(input: GraphqlSendIntegrationRequestInput): Promise<GraphqlSendIntegrationRequestMutation["sendIntegrationRequest"]["response"]>;
54
- private graphqlOperationWrapper;
55
- private reformatError;
56
- private checkForUpdates;
57
57
  }
@@ -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) {
@@ -55,12 +47,13 @@ class Client {
55
47
  * @param integrationConnectionId The ID of the integration connection.
56
48
  * @returns result Object with the following properties:
57
49
  * @returns result.isConnected Whether we can connect to the end-user's QBD.
58
- * @returns result.devErrorMessage If `isConnected=false`, this will be the
59
- * corresponding error message for the developer; e.g., "The end-user's
60
- * computer is likely off".
61
- * @returns result.endUserErrorMessage If `isConnected=false`, this will be
62
- * the corresponding error message for the end-user; e.g., "Please ensure your
63
- * computer is on and QuickBooks Desktop is open".
50
+ * @returns result.error If `isConnected=false`, this will be an object with
51
+ * the following properties:
52
+ * @returns result.error.code The unique error code.
53
+ * @returns result.error.developerMessage The technical error message for the
54
+ * developer.
55
+ * @returns result.error.endUserMessage The user-friendly error message to
56
+ * display to the the end-user.
64
57
  */
65
58
  async getConnectionStatus(integrationConnectionId) {
66
59
  return this.graphqlOperations
@@ -73,9 +66,11 @@ class Client {
73
66
  * @param input - The input object to create the integration connection.
74
67
  * @param input.integrationKey The identifier of the third-party platform to
75
68
  * integrate.
69
+ * @param input.endUserSourceId Your end-user's unique ID in your product's
70
+ * database. Must be distinct from your other connections for the same
71
+ * integration.
76
72
  * @param input.endUserEmail Your end-user's email address for identification
77
- * only. No emails will be sent. Must be distinct from your other connections
78
- * for the same integration.
73
+ * only. No emails will be sent.
79
74
  * @param input.endUserCompanyName Your end-user's company name that will be
80
75
  * shown elsewhere in Conductor.
81
76
  * @returns The newly created integration connection.
@@ -85,84 +80,12 @@ class Client {
85
80
  .createIntegrationConnection({ input })
86
81
  .then((result) => result.createIntegrationConnection);
87
82
  }
88
- // TODO: Hide this method from the dev-user while still allowing the
89
- // integration clients to access it.
83
+ // TODO: Find a way to make this private.
84
+ /** Not intended for public use. */
90
85
  async sendIntegrationRequest(input) {
91
86
  return this.graphqlOperations
92
87
  .sendIntegrationRequest({ input })
93
88
  .then((result) => result.sendIntegrationRequest.response);
94
89
  }
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
90
  }
168
91
  exports.default = Client;
@@ -26,6 +26,7 @@ export type Scalars = {
26
26
  export type GraphqlCreateIntegrationConnectionInput = {
27
27
  endUserCompanyName: Scalars["String"];
28
28
  endUserEmail: Scalars["String"];
29
+ endUserSourceId: Scalars["String"];
29
30
  integrationKey: Scalars["String"];
30
31
  };
31
32
  export type GraphqlSendIntegrationRequestInput = {
@@ -35,6 +36,7 @@ export type GraphqlSendIntegrationRequestInput = {
35
36
  export type GraphqlIntegrationConnectionFragment = {
36
37
  id: string;
37
38
  integrationKey: string;
39
+ endUserSourceId: string;
38
40
  endUserEmail: string;
39
41
  endUserCompanyName: string;
40
42
  lastHeartbeatAt: Date | null;
@@ -51,6 +53,7 @@ export type GraphqlGetIntegrationConnectionQuery = {
51
53
  integrationConnection: {
52
54
  id: string;
53
55
  integrationKey: string;
56
+ endUserSourceId: string;
54
57
  endUserEmail: string;
55
58
  endUserCompanyName: string;
56
59
  lastHeartbeatAt: Date | null;
@@ -63,6 +66,7 @@ export type GraphqlGetIntegrationConnectionsQuery = {
63
66
  integrationConnections: Array<{
64
67
  id: string;
65
68
  integrationKey: string;
69
+ endUserSourceId: string;
66
70
  endUserEmail: string;
67
71
  endUserCompanyName: string;
68
72
  lastHeartbeatAt: Date | null;
@@ -93,6 +97,7 @@ export type GraphqlCreateIntegrationConnectionMutation = {
93
97
  integrationConnection: {
94
98
  id: string;
95
99
  integrationKey: string;
100
+ endUserSourceId: string;
96
101
  endUserEmail: string;
97
102
  endUserCompanyName: string;
98
103
  lastHeartbeatAt: Date | null;
@@ -107,7 +112,7 @@ export type GraphqlSendIntegrationRequestMutation = {
107
112
  response: object;
108
113
  };
109
114
  };
110
- export declare const IntegrationConnectionFragmentDoc = "\n fragment IntegrationConnection on IntegrationConnection {\n id\n integrationKey\n endUserEmail\n endUserCompanyName\n lastHeartbeatAt\n}\n ";
115
+ export declare const IntegrationConnectionFragmentDoc = "\n fragment IntegrationConnection on IntegrationConnection {\n id\n integrationKey\n endUserSourceId\n endUserEmail\n endUserCompanyName\n lastHeartbeatAt\n}\n ";
111
116
  export declare const UserErrorFragmentDoc = "\n fragment UserError on UserError {\n code\n developerMessage\n endUserMessage\n}\n ";
112
117
  export declare const GetIntegrationConnectionDocument: string;
113
118
  export declare const GetIntegrationConnectionsDocument: string;
@@ -5,6 +5,7 @@ exports.IntegrationConnectionFragmentDoc = `
5
5
  fragment IntegrationConnection on IntegrationConnection {
6
6
  id
7
7
  integrationKey
8
+ endUserSourceId
8
9
  endUserEmail
9
10
  endUserCompanyName
10
11
  lastHeartbeatAt
@@ -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": "8.0.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,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";