conductor-node 4.1.10 → 6.1.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
@@ -31,3 +31,53 @@ const newAccount = await conductor.qbd.account.add(qbdConnections[0].id, {
31
31
  OpenBalance: "100",
32
32
  });
33
33
  ```
34
+
35
+ ## `Conductor` APIs
36
+
37
+ ### `getIntegrationConnections()`
38
+
39
+ Fetch all authorized integration-connections.
40
+
41
+ ```ts
42
+ const qbdConnections = await conductor.getIntegrationConnections();
43
+ ```
44
+
45
+ ### `qbd`
46
+
47
+ Execute any QuickBooks Desktop (QBD) API against a specific integration connection id. See the official [QuickBooks Desktop API Reference](https://developer.intuit.com/app/developer/qbdesktop/docs/api-reference/qbdesktop) for a full list of available APIs.
48
+
49
+ ```ts
50
+ const newAccount = await conductor.qbd.account.add(qbdConnections[0].id, {
51
+ Name: "Test Account",
52
+ AccountType: "Bank",
53
+ OpenBalance: "100",
54
+ });
55
+ ```
56
+
57
+ ### `getIntegrationConnectionById(id: string)`
58
+
59
+ Fetch a single integration connection by id.
60
+
61
+ ```ts
62
+ const connection = await conductor.getIntegrationConnectionById(
63
+ qbdConnections[0].id
64
+ );
65
+ ```
66
+
67
+ ### `isIntegrationConnectionActive(id: string, secondsSinceLastHeartbeat: number = 10)`
68
+
69
+ Check if an integration connection is active within the last `secondsSinceLastHeartbeat` seconds (defaults to 10 seconds).
70
+
71
+ ```ts
72
+ const isActive = await conductor.isIntegrationConnectionActive(
73
+ qbdConnections[0].id
74
+ );
75
+ ```
76
+
77
+ ### `logConnectionStatuses()`
78
+
79
+ Log the time since Conductor has heard from each authorized integration connection.
80
+
81
+ ```ts
82
+ conductor.logConnectionStatuses(); // Outputs to logs
83
+ ```
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "conductor-node",
3
- "version": "4.1.10",
3
+ "version": "6.1.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,6 +9,20 @@ interface IntegrationRequestParams {
9
9
  integrationConnectionId: string;
10
10
  requestObject: object;
11
11
  }
12
+ interface GetIntegrationConnectionByIdResult {
13
+ integrationConnection: {
14
+ id: string;
15
+ integration: {
16
+ id: string;
17
+ name: string;
18
+ };
19
+ qbwcUsername: string;
20
+ lastHeartbeatAt: string | null;
21
+ };
22
+ }
23
+ interface GetIntegrationConnectionsResult {
24
+ integrationConnections: GetIntegrationConnectionByIdResult["integrationConnection"][];
25
+ }
12
26
  export default class Client {
13
27
  /** QuickBooks Desktop integration. */
14
28
  readonly qbd: QbdIntegration;
@@ -16,8 +30,9 @@ export default class Client {
16
30
  private readonly gqlClient;
17
31
  private readonly verbose;
18
32
  constructor(apiKey: string, { verbose, serverEnvironment }?: ClientOptions);
19
- getIntegrationConnection(integrationConnectionId: string): Promise<object>;
20
- getIntegrationConnections(): Promise<object[]>;
33
+ getIntegrationConnectionById(integrationConnectionId: string): Promise<GetIntegrationConnectionByIdResult["integrationConnection"]>;
34
+ getIntegrationConnections(): Promise<GetIntegrationConnectionsResult["integrationConnections"]>;
35
+ isIntegrationConnectionActive(integrationConnectionId: string, secondsSinceLastHeartbeat?: number): Promise<boolean>;
21
36
  logConnectionStatuses(): Promise<void>;
22
37
  integrationRequest(integrationRequestParams: IntegrationRequestParams): Promise<object>;
23
38
  private request;
@@ -27,9 +27,9 @@ class Client {
27
27
  });
28
28
  this.qbd = new QbdIntegration_1.default(this);
29
29
  }
30
- async getIntegrationConnection(integrationConnectionId) {
31
- const data = await this.request(`#graphql
32
- query GetIntegrationConnection($integrationConnectionId: ID!) {
30
+ async getIntegrationConnectionById(integrationConnectionId) {
31
+ const data = (await this.request(`#graphql
32
+ query GetIntegrationConnectionById($integrationConnectionId: ID!) {
33
33
  integrationConnection(id: $integrationConnectionId) {
34
34
  id
35
35
  integration {
@@ -40,12 +40,11 @@ class Client {
40
40
  lastHeartbeatAt
41
41
  }
42
42
  }
43
- `, { integrationConnectionId });
44
- // @ts-expect-error - This will pass after we integrate GQL codegen.
43
+ `, { integrationConnectionId }));
45
44
  return data.integrationConnection;
46
45
  }
47
46
  async getIntegrationConnections() {
48
- const data = await this.request(`#graphql
47
+ const data = (await this.request(`#graphql
49
48
  query {
50
49
  integrationConnections {
51
50
  id
@@ -57,10 +56,19 @@ class Client {
57
56
  lastHeartbeatAt
58
57
  }
59
58
  }
60
- `);
61
- // @ts-expect-error - This will pass after we integrate GQL codegen.
59
+ `));
62
60
  return data.integrationConnections;
63
61
  }
62
+ async isIntegrationConnectionActive(integrationConnectionId, secondsSinceLastHeartbeat = 10) {
63
+ const integrationConnection = await this.getIntegrationConnectionById(integrationConnectionId);
64
+ if (integrationConnection.lastHeartbeatAt === null) {
65
+ return false;
66
+ }
67
+ const lastHeartbeatAt = new Date(integrationConnection.lastHeartbeatAt);
68
+ const now = new Date();
69
+ const secondsSinceLastHeartbeatActual = (now.getTime() - lastHeartbeatAt.getTime()) / 1000;
70
+ return secondsSinceLastHeartbeatActual <= secondsSinceLastHeartbeat;
71
+ }
64
72
  async logConnectionStatuses() {
65
73
  const integrationConnections = (await this.getIntegrationConnections());
66
74
  console.log("Time since Conductor last heard from each integration connection:");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "conductor-node",
3
- "version": "4.1.10",
3
+ "version": "6.1.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",