@pliancy/salesforce-cpq-sdk 3.27.0 → 5.0.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.
@@ -1,11 +1,18 @@
1
1
  import { Connection, SaveResult, Schema, SObjectUpdateRecord } from 'jsforce';
2
2
  import { Account } from './account.types';
3
- import { CustomFieldQuery } from '../cpq.types';
3
+ import { CustomFieldQuery, FindAllQuery } from '../cpq.types';
4
4
  export declare class Accounts {
5
5
  private readonly connection;
6
6
  private readonly client;
7
7
  constructor(connection: Connection);
8
- getAll(): Promise<Account[]>;
8
+ /**
9
+ * Fetches all accounts with specified fields (defaults to Id and Name only) and sorts them by
10
+ * creation date in descending order.
11
+ *
12
+ * @param {string[]} [additionalFields=[]] - An array of additional field names to include in the query.
13
+ * @return {Promise<FindAllQuery<Account>>} A promise that resolves to the result of the find query containing all accounts with the specified fields.
14
+ */
15
+ getAll(additionalFields?: string[]): Promise<FindAllQuery<Account>>;
9
16
  getById(id: string): Promise<Account | null>;
10
17
  create(data: Partial<Omit<Account, 'Id'>>): Promise<SaveResult>;
11
18
  update(update: SObjectUpdateRecord<Schema, 'Account'>): Promise<SaveResult>;
@@ -6,8 +6,16 @@ class Accounts {
6
6
  this.connection = connection;
7
7
  this.client = this.connection.sobject('Account');
8
8
  }
9
- async getAll() {
10
- return this.client.find({ Type: 'Customer', IsDeleted: false });
9
+ /**
10
+ * Fetches all accounts with specified fields (defaults to Id and Name only) and sorts them by
11
+ * creation date in descending order.
12
+ *
13
+ * @param {string[]} [additionalFields=[]] - An array of additional field names to include in the query.
14
+ * @return {Promise<FindAllQuery<Account>>} A promise that resolves to the result of the find query containing all accounts with the specified fields.
15
+ */
16
+ async getAll(additionalFields = []) {
17
+ const fields = additionalFields.concat(['Id', 'Name']);
18
+ return this.client.find({}, fields, { sort: { CreatedDate: -1 } });
11
19
  }
12
20
  async getById(id) {
13
21
  return this.client.findOne({ Id: id });
@@ -1,13 +1,14 @@
1
- import { Connection } from 'jsforce';
2
- import { AmendmentQuote, Contract, ContractEntity, ContractQuery } from './contract.types';
1
+ import { Connection, QueryCondition, Schema } from 'jsforce';
2
+ import { AmendmentQuote, Contract, ContractEntity, ContractQuery, ContractStatus } from './contract.types';
3
3
  import { Base } from '../base/base';
4
4
  export declare class Contracts extends Base<ContractEntity> {
5
5
  private readonly connection;
6
6
  private readonly client;
7
7
  constructor(connection: Connection);
8
8
  getById(id: string): Promise<Contract | null>;
9
- getLatestActivatedByAccountId(id: string, options?: ContractQuery): Promise<Contract | undefined>;
9
+ getLatestByStatusForAccount(accountId: string, status: ContractStatus, options?: ContractQuery): Promise<Contract | undefined>;
10
10
  getDraftsByBillingPeriod(accountId: string, start: string, end: string): Promise<Contract[]>;
11
+ update(id: string, update: Partial<Omit<Contract, 'Id'>>, options?: QueryCondition<Schema, ContractEntity>): Promise<import("jsforce").SaveResult>;
11
12
  /**
12
13
  * Creates an amendment quote based on the provided contract ID.
13
14
  *
@@ -13,17 +13,18 @@ class Contracts extends base_1.Base {
13
13
  async getById(id) {
14
14
  return this.client.findOne({ Id: id });
15
15
  }
16
- async getLatestActivatedByAccountId(id, options) {
17
- const query = this.buildQuery({ AccountId: id, Status: 'Activated' }, options);
16
+ async getLatestByStatusForAccount(accountId, status, options) {
17
+ var _a;
18
+ const query = this.buildQuery({ AccountId: accountId, Status: status }, options);
18
19
  const contracts = (await this.client.find(query));
19
20
  if (!(contracts && contracts.length))
20
21
  return undefined;
21
22
  // If there's only one contract, return it
22
- if (contracts.length === 1)
23
+ if (contracts.length === 1 && ((_a = contracts[0]) === null || _a === void 0 ? void 0 : _a.Status) === status)
23
24
  return contracts.shift();
24
25
  contracts.sort((a, b) => {
25
- const aTime = new Date(a.ActivatedDate).getTime();
26
- const bTime = new Date(b.ActivatedDate).getTime();
26
+ const aTime = new Date(a.CreatedDate).getTime();
27
+ const bTime = new Date(b.CreatedDate).getTime();
27
28
  return bTime - aTime;
28
29
  });
29
30
  // Return the first in the array
@@ -37,6 +38,10 @@ class Contracts extends base_1.Base {
37
38
  EndDate: { $lte: new jsforce_1.SfDate(end) },
38
39
  });
39
40
  }
41
+ async update(id, update, options) {
42
+ const query = this.buildQuery({ Id: id, ...update }, options);
43
+ return this.client.update(query);
44
+ }
40
45
  /**
41
46
  * Creates an amendment quote based on the provided contract ID.
42
47
  *
@@ -1,3 +1,4 @@
1
+ import { PickIfMatch, SObjectFieldType } from 'jsforce';
1
2
  export interface CpqConfig {
2
3
  instanceUrl: string;
3
4
  oauth2: {
@@ -9,3 +10,6 @@ export interface CpqConfig {
9
10
  export type CustomFieldQuery<T> = Partial<T & {
10
11
  [index: string]: string;
11
12
  }>;
13
+ export type FindAllQuery<T> = (PickIfMatch<{
14
+ [name: string]: SObjectFieldType | null;
15
+ }, 'Id' | 'Name' | string> & T)[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pliancy/salesforce-cpq-sdk",
3
- "version": "3.27.0",
3
+ "version": "5.0.0",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "description": "Salesforce CPQ SDK for Node.js",