@pliancy/salesforce-cpq-sdk 3.1.0 → 3.3.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,
@@ -94,7 +94,12 @@ export interface Quote {
94
94
  SBQQ__NetAmount__c: number;
95
95
  SBQQ__RegularAmount__c: number;
96
96
  }
97
- export type QuoteType = 'Quote' | 'Renewal' | 'Amendment' | 'Re-Quote';
97
+ export declare enum QuoteType {
98
+ QUOTE = "Quote",
99
+ RENEWAL = "Renewal",
100
+ AMENDMENT = "Amendment",
101
+ REQUOTE = "Re-Quote"
102
+ }
98
103
  export type QuoteWithLineItems = Quote & {
99
104
  lineItems: QuoteLine[];
100
105
  };
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApprovalStatus = void 0;
3
+ exports.ApprovalStatus = exports.QuoteType = void 0;
4
+ var QuoteType;
5
+ (function (QuoteType) {
6
+ QuoteType["QUOTE"] = "Quote";
7
+ QuoteType["RENEWAL"] = "Renewal";
8
+ QuoteType["AMENDMENT"] = "Amendment";
9
+ QuoteType["REQUOTE"] = "Re-Quote";
10
+ })(QuoteType || (exports.QuoteType = QuoteType = {}));
4
11
  var ApprovalStatus;
5
12
  (function (ApprovalStatus) {
6
13
  ApprovalStatus["APPROVED"] = "Approved";
@@ -74,11 +74,11 @@ class Quotes {
74
74
  skipEntryCriteria: true,
75
75
  }));
76
76
  if ((sResult === null || sResult === void 0 ? void 0 : sResult.newWorkItemIds) && (sResult === null || sResult === void 0 ? void 0 : sResult.newWorkItemIds.length)) {
77
- const workItemId = sResult.newWorkItemIds[0];
78
- if (!workItemId)
77
+ const id = sResult.newWorkItemIds[0];
78
+ if (!id)
79
79
  return { success: false, errors: ['No workItemId returned'] };
80
- await approvalProcess.approve(workItemId);
81
- return { success: true, workItemId };
80
+ await approvalProcess.approve(id);
81
+ return { success: true, workItemId: id };
82
82
  }
83
83
  else {
84
84
  return { success: false, errors: sResult.errors };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pliancy/salesforce-cpq-sdk",
3
- "version": "3.1.0",
3
+ "version": "3.3.0",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "description": "Salesforce CPQ SDK for Node.js",