conductor-node 3.6.0 → 3.6.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.
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "conductor-node",
3
+ "version": "3.6.1",
4
+ "description": "Conductor API wrapper",
5
+ "author": "Danny Nemer <hi@DannyNemer.com>",
6
+ "license": "MIT",
7
+ "type": "commonjs",
8
+ "main": "dist/src/index.js",
9
+ "types": "dist/src/index.d.ts",
10
+ "files": [
11
+ "dist/src/**/*.[jt]s",
12
+ "dist/package.json"
13
+ ],
14
+ "scripts": {
15
+ "prepack": "yarn tsc && yarn delete-compiled-tests && yarn tsc-alias --verbose",
16
+ "delete-compiled-tests": "rm -rfv `find ./dist -type d -name __tests__`",
17
+ "postpack": "rm -rf dist",
18
+ "clean": "rm -rf dist package conductor-node-*.tgz tsconfig.tsbuildinfo"
19
+ },
20
+ "engines": {
21
+ "node": ">=16"
22
+ },
23
+ "devDependencies": {
24
+ "tsc-alias": "^1.7.0"
25
+ },
26
+ "dependencies": {
27
+ "graphql": "^16.6.0",
28
+ "graphql-request": "^5.0.0"
29
+ }
30
+ }
@@ -1,5 +1,5 @@
1
1
  import type { Environment } from "./environment";
2
- import QbdClient from "./integrations/qbd/QbdClient";
2
+ import QbdIntegration from "./integrations/qbd/QbdIntegration";
3
3
  export interface ClientOptions {
4
4
  /** Log the each request and response. */
5
5
  verbose?: boolean;
@@ -11,12 +11,12 @@ export interface IntegrationRequestParams {
11
11
  }
12
12
  export default class Client {
13
13
  /** QuickBooks Desktop integration. */
14
- readonly qbd: QbdClient;
14
+ readonly qbd: QbdIntegration;
15
15
  private readonly serverURL;
16
16
  private readonly gqlClient;
17
17
  private readonly verbose;
18
18
  constructor(apiKey: string, { verbose, environment }?: ClientOptions);
19
- private static getUserAgent;
20
19
  integrationUserConnections(): Promise<object[]>;
21
20
  integrationRequest(integrationRequestParams: IntegrationRequestParams): Promise<object>;
21
+ private request;
22
22
  }
@@ -3,8 +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
+ const package_json_1 = __importDefault(require("./../package.json"));
6
7
  const environment_1 = require("./environment");
7
- const QbdClient_1 = __importDefault(require("./integrations/qbd/QbdClient"));
8
+ const QbdIntegration_1 = __importDefault(require("./integrations/qbd/QbdIntegration"));
8
9
  const graphql_request_1 = require("graphql-request");
9
10
  class Client {
10
11
  /** QuickBooks Desktop integration. */
@@ -18,24 +19,13 @@ class Client {
18
19
  this.gqlClient = new graphql_request_1.GraphQLClient(`${this.serverURL}/graphql`, {
19
20
  headers: {
20
21
  Authorization: `Bearer ${apiKey}`,
21
- "User-Agent": Client.getUserAgent(),
22
+ "User-Agent": `${package_json_1.default.name}/${package_json_1.default.version} (Node.js ${process.version})`,
22
23
  },
23
24
  });
24
- this.qbd = new QbdClient_1.default(this);
25
- }
26
- static getUserAgent() {
27
- const packageName = process.env["npm_package_name"];
28
- if (packageName === undefined) {
29
- throw new Error("Package name not found");
30
- }
31
- const clientVersion = process.env["npm_package_version"];
32
- if (clientVersion === undefined) {
33
- throw new Error("Client version not found");
34
- }
35
- return `${packageName}/${clientVersion} (Node.js ${process.version})`;
25
+ this.qbd = new QbdIntegration_1.default(this);
36
26
  }
37
27
  async integrationUserConnections() {
38
- const data = await this.gqlClient.request(`#graphql
28
+ const data = await this.request(`#graphql
39
29
  query {
40
30
  integrationUserConnections {
41
31
  id
@@ -57,7 +47,7 @@ class Client {
57
47
  console.log(`Client sent request to ${this.serverURL}:`, JSON.stringify(integrationRequestParams, undefined, 2));
58
48
  console.time("Request time");
59
49
  }
60
- const response = await this.gqlClient.request(`#graphql
50
+ const response = await this.request(`#graphql
61
51
  query IntegrationRequest($integrationRequestParams: IntegrationRequestParams!) {
62
52
  integrationRequest(integrationRequestParams: $integrationRequestParams)
63
53
  }
@@ -70,5 +60,20 @@ class Client {
70
60
  }
71
61
  return responseBody;
72
62
  }
63
+ async request(document, variables) {
64
+ try {
65
+ const response = await this.gqlClient.request(document, variables);
66
+ return response;
67
+ }
68
+ catch (error) {
69
+ if (this.verbose) {
70
+ console.log(JSON.stringify(error, undefined, 2));
71
+ }
72
+ if (error instanceof graphql_request_1.ClientError) {
73
+ throw new Error(error.response.errors?.[0]?.message ?? "An unknown error occurred.");
74
+ }
75
+ throw error;
76
+ }
77
+ }
73
78
  }
74
79
  exports.default = Client;
@@ -0,0 +1,5 @@
1
+ import type Client from "../Client";
2
+ export default class BaseIntegration {
3
+ protected readonly client: Client;
4
+ constructor(client: Client);
5
+ }
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- class BaseClient {
4
- root;
3
+ class BaseIntegration {
4
+ client;
5
5
  constructor(client) {
6
- this.root = client;
6
+ this.client = client;
7
7
  }
8
8
  }
9
- exports.default = BaseClient;
9
+ exports.default = BaseIntegration;
@@ -1,6 +1,6 @@
1
- import BaseClient from "../../integrations/BaseClient";
1
+ import BaseIntegration from "../../integrations/BaseIntegration";
2
2
  import type * as QbdTypes from "../../integrations/qbd/qbdTypes";
3
- export default class QbdClient extends BaseClient {
3
+ export default class QbdIntegration extends BaseIntegration {
4
4
  account: {
5
5
  /**
6
6
  * Perform the same activities as a user does in the QB New Account form,
@@ -3,8 +3,8 @@ 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
- const BaseClient_1 = __importDefault(require("../../integrations/BaseClient"));
7
- class QbdClient extends BaseClient_1.default {
6
+ const BaseIntegration_1 = __importDefault(require("../../integrations/BaseIntegration"));
7
+ class QbdIntegration extends BaseIntegration_1.default {
8
8
  account = {
9
9
  /**
10
10
  * Perform the same activities as a user does in the QB New Account form,
@@ -631,7 +631,7 @@ class QbdClient extends BaseClient_1.default {
631
631
  * https://developer.intuit.com/app/developer/qbdesktop/docs/api-reference/qbdesktop
632
632
  */
633
633
  async sendRequest(integrationUserConnectionId, requestObject) {
634
- return this.root.integrationRequest({
634
+ return this.client.integrationRequest({
635
635
  integrationUserConnectionId,
636
636
  requestObject,
637
637
  });
@@ -645,4 +645,4 @@ class QbdClient extends BaseClient_1.default {
645
645
  return responseBody;
646
646
  }
647
647
  }
648
- exports.default = QbdClient;
648
+ exports.default = QbdIntegration;
@@ -0,0 +1,2 @@
1
+ export declare const MOCK_CLIENT_API_KEY = "mock_client_api_key";
2
+ export declare const MOCK_QBD_USER_CONNECTION_ID = "mock_qbd_user_connection_id";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MOCK_QBD_USER_CONNECTION_ID = exports.MOCK_CLIENT_API_KEY = void 0;
4
+ exports.MOCK_CLIENT_API_KEY = "mock_client_api_key";
5
+ exports.MOCK_QBD_USER_CONNECTION_ID = "mock_qbd_user_connection_id";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "conductor-node",
3
- "version": "3.6.0",
3
+ "version": "3.6.1",
4
4
  "description": "Conductor API wrapper",
5
5
  "author": "Danny Nemer <hi@DannyNemer.com>",
6
6
  "license": "MIT",
@@ -8,10 +8,12 @@
8
8
  "main": "dist/src/index.js",
9
9
  "types": "dist/src/index.d.ts",
10
10
  "files": [
11
- "dist/**/*.[jt]s"
11
+ "dist/src/**/*.[jt]s",
12
+ "dist/package.json"
12
13
  ],
13
14
  "scripts": {
14
- "prepack": "yarn tsc && yarn tsc-alias --verbose",
15
+ "prepack": "yarn tsc && yarn delete-compiled-tests && yarn tsc-alias --verbose",
16
+ "delete-compiled-tests": "rm -rfv `find ./dist -type d -name __tests__`",
15
17
  "postpack": "rm -rf dist",
16
18
  "clean": "rm -rf dist package conductor-node-*.tgz tsconfig.tsbuildinfo"
17
19
  },
@@ -1,5 +0,0 @@
1
- import type Client from "../Client";
2
- export default class BaseClient {
3
- protected readonly root: Client;
4
- constructor(client: Client);
5
- }