@pliancy/salesforce-cpq-sdk 1.5.0 → 1.7.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.
@@ -8,6 +8,7 @@ export declare class Quotes {
8
8
  getAll(options?: QuoteQuery): Promise<QuoteWithLineItems[]>;
9
9
  getById(id: string): Promise<QuoteWithLineItems | null>;
10
10
  getByAccountId(accountId: string, options?: QuoteQuery): Promise<QuoteWithLineItems[]>;
11
+ getOriginal(accountId: string): Promise<Quote | undefined>;
11
12
  update(quoteId: string, query: Partial<Omit<Quote, 'Id'>>): Promise<SaveResult>;
12
13
  updateLineItemQuantities(lineItems: UpdateQuoteLine[]): Promise<SaveResult[]>;
13
14
  order(quoteId: string, options?: UpdateQuoteQuery): Promise<SaveResult>;
@@ -35,6 +35,27 @@ class Quotes {
35
35
  }
36
36
  return quotes;
37
37
  }
38
+ async getOriginal(accountId) {
39
+ const query = {
40
+ SBQQ__Account__c: accountId,
41
+ SBQQ__Type__c: 'Quote',
42
+ Approval_Status_R__c: { $or: ['Approved', 'Approval Not Required'] },
43
+ };
44
+ const quotes = (await this.client.find(query));
45
+ if (!(quotes && quotes.length))
46
+ return undefined;
47
+ // If there's only one quote, return it
48
+ if (quotes.length === 1)
49
+ return quotes.shift();
50
+ // Sort by StartDate with oldest quote first
51
+ quotes.sort((a, b) => {
52
+ const aTime = new Date(a.SBQQ__StartDate__c).getTime();
53
+ const bTime = new Date(b.SBQQ__StartDate__c).getTime();
54
+ return aTime - bTime;
55
+ });
56
+ // Return the first in the array
57
+ return quotes.shift();
58
+ }
38
59
  async update(quoteId, query) {
39
60
  return this.client.update({ Id: quoteId, ...query });
40
61
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pliancy/salesforce-cpq-sdk",
3
- "version": "1.5.0",
3
+ "version": "1.7.0",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "description": "Salesforce CPQ SDK for Node.js",