@pliancy/salesforce-cpq-sdk 3.2.0 → 3.4.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.
@@ -5,5 +5,6 @@ export declare class Contracts {
5
5
  private readonly client;
6
6
  constructor(connection: Connection);
7
7
  getById(id: string): Promise<Contract | null>;
8
+ getLatestActivatedByAccountId(id: string): Promise<Contract | undefined>;
8
9
  getDraftsByBillingPeriod(accountId: string, start: string, end: string): Promise<Contract[]>;
9
10
  }
@@ -10,6 +10,22 @@ class Contracts {
10
10
  async getById(id) {
11
11
  return this.client.findOne({ Id: id });
12
12
  }
13
+ async getLatestActivatedByAccountId(id) {
14
+ const query = { AccountId: id, Status: 'Activated' };
15
+ const contracts = (await this.client.find(query));
16
+ if (!(contracts && contracts.length))
17
+ return undefined;
18
+ // If there's only one contract, return it
19
+ if (contracts.length === 1)
20
+ return contracts.shift();
21
+ contracts.sort((a, b) => {
22
+ const aTime = new Date(a.ActivatedDate).getTime();
23
+ const bTime = new Date(b.ActivatedDate).getTime();
24
+ return bTime - aTime;
25
+ });
26
+ // Return the first in the array
27
+ return contracts.shift();
28
+ }
13
29
  async getDraftsByBillingPeriod(accountId, start, end) {
14
30
  return this.client.find({
15
31
  AccountId: accountId,
@@ -1,8 +1,9 @@
1
- import { Connection } from 'jsforce';
1
+ import { Connection, QueryCondition, Schema } from 'jsforce';
2
2
  import { Product } from './product.types';
3
3
  export declare class Products {
4
4
  private readonly connection;
5
5
  private readonly client;
6
6
  constructor(connection: Connection);
7
+ get(query: QueryCondition<Schema, 'Product2'>): Promise<Product[]>;
7
8
  getById(id: string): Promise<Product | null>;
8
9
  }
@@ -6,6 +6,9 @@ class Products {
6
6
  this.connection = connection;
7
7
  this.client = this.connection.sobject('Product2');
8
8
  }
9
+ async get(query) {
10
+ return this.client.find(query);
11
+ }
9
12
  async getById(id) {
10
13
  return this.client.findOne({ Id: id });
11
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pliancy/salesforce-cpq-sdk",
3
- "version": "3.2.0",
3
+ "version": "3.4.0",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "description": "Salesforce CPQ SDK for Node.js",