@pliancy/salesforce-cpq-sdk 4.0.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,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": "4.0.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",