/**
* State object
* @typedef {Object} ERPNextState
* @property data - The response body (as JSON)
* @property response - The HTTP response from the ERPNext server (excluding the body)
* @property references - An array of all previous data objects used in the Job
* @private
*/
/**
* Options object for list operations
* @typedef {Object} ListOptions
* @property {object} filters - Filters to apply to the query (e.g., `{ status: 'Open' }`).
* @property {string[]} fields - Array of field names to return (e.g., `['name', 'status']`).
* @property {number} limit - Maximum number of records to return. Defaults to `1000`.
* @property {number} offset - Number of records to skip. Defaults to `0`.
* @property {string} orderBy - Field to sort by with direction (e.g., `'creation desc'`).
* @see {@link https://frappeframework.com/docs/user/en/api/database#get-list Frappe Database API}
*/
/**
* Execute a sequence of operations.
* Wraps `language-common/execute` to make working with this API easier.
* @example
* execute(
* create('Customer', { customer_name: 'Acme Corp' }),
* getList('Sales Order', { filters: { status: 'Draft' } })
* )(state)
* @private
* @param {Operations} operations - Operations to be performed.
* @returns {Operation}
*/
export function execute(...operations: Operations): Operation;
/**
* Helper function for testing - allows setting a mock client
* @example
* setMockClient(mockFrappeClient)
* @function
* @private
* @param {object} mock - Mock client object
* @returns {void}
*/
export function setMockClient(mock: object): void;
/**
* Create a document in ERPNext. Returns the complete created document with all fields.
* @public
* @example
Create a customer record
* create('Customer', {
* customer_name: 'Acme Corporation',
* customer_type: 'Company'
* });
* @example Create with data from state
* create('Sales Order', $.orderData);
* @example Create an item with multiple fields
* create('Item', {
* item_code: 'ITEM-001',
* item_name: 'Sample Product',
* item_group: 'Products',
* stock_uom: 'Nos'
* });
* @function
* @param {string} doctype - The doctype to create (e.g., "Customer", "Sales Order")
* @param {object} data - The document data as JSON
* @state {ERPNextState}
* @returns {Operation}
*/
export function create(doctype: string, data: object): Operation;
/**
* Read a document from ERPNext by name/ID. Returns the complete document with all fields.
* Note: For field selection, use getList() with filters instead.
* @public
* @example Read a customer by name
* read('Customer', 'CUST-00001');
* @example Read from state data
* read('Item', $.data.item_code);
* @example Read a sales order
* read('Sales Order', $.orderId);
* @function
* @param {string} doctype - The doctype to read from (e.g., "Customer", "Sales Order")
* @param {string} name - The document name/ID to read
* @state {ERPNextState}
* @returns {Operation}
*/
export function read(doctype: string, name: string): Operation;
/**
* Update a document in ERPNext
* @public
* @example Update a customer's details
* update('Customer', 'CUST-00001', {
* customer_name: 'Updated Corp Name',
* mobile_no: '+1234567890'
* });
* @example Update using state data
* update('Sales Order', $.data.order_id, {
* status: 'Confirmed'
* });
* @example Update multiple fields
* update('Item', 'ITEM-001', {
* item_name: 'Updated Product Name',
* standard_rate: 150.00,
* description: 'Updated description'
* });
* @function
* @param {string} doctype - The doctype to update (e.g., "Customer", "Sales Order")
* @param {string} name - The document name/ID to update
* @param {object} data - The fields to update as JSON
* @state {ERPNextState}
* @returns {Operation}
*/
export function update(doctype: string, name: string, data: object): Operation;
/**
* Delete a document from ERPNext
* @public
* @example Delete a customer
* deleteRecord('Customer', 'CUST-00001');
* @example Delete using state data
* deleteRecord('Sales Order', $.data.order_id);
* @example Delete a draft document
* deleteRecord('Quotation', 'QTN-00001');
* @function
* @param {string} doctype - The doctype to delete from (e.g., "Customer", "Sales Order")
* @param {string} name - The document name/ID to delete
* @state {ERPNextState}
* @returns {Operation}
*/
export function deleteRecord(doctype: string, name: string): Operation;
/**
* Get a list of documents from ERPNext with filtering, field selection, and pagination
* @public
* @example Get all customers
* getList('Customer');
* @example Get customers with filters
* getList('Customer', {
* filters: { customer_type: 'Company' },
* fields: ['name', 'customer_name', 'territory']
* });
* @example Get with pagination
* getList('Sales Order', {
* filters: { status: 'Draft' },
* limit: 50,
* offset: 0,
* orderBy: 'creation desc'
* });
* @example Get specific fields only
* getList('Item', {
* fields: ['item_code', 'item_name', 'standard_rate'],
* filters: { item_group: 'Products' },
* limit: 100
* });
* @function
* @param {string} doctype - The doctype to query (e.g., "Customer", "Sales Order")
* @param {ListOptions} options - Optional query configuration. See {@link https://frappeframework.com/docs/user/en/api/database#get-list Frappe Database API} for supported options.
* @state {ERPNextState}
* @returns {Operation}
*/
export function getList(doctype: string, options?: ListOptions): Operation;
/**
* Get count of documents matching filters
* @public
* @example Count all customers
* getCount('Customer');
* @example Count with filters
* getCount('Sales Order', { status: 'Open' });
* @example Count from state data
* getCount('Item', { item_group: $.data.group_name });
* @function
* @param {string} doctype - The doctype to count (e.g., "Customer", "Sales Order")
* @param {object} filters - Optional filters to apply (e.g., `{ status: 'Open' }`)
* @state {ERPNextState}
* @returns {Operation}
*/
export function getCount(doctype: string, filters?: object): Operation;
/**
* State object
*/
export type ERPNextState = {
/**
* - The response body (as JSON)
*/
data: any;
/**
* - The HTTP response from the ERPNext server (excluding the body)
*/
response: any;
/**
* - An array of all previous data objects used in the Job
*/
references: any;
};
/**
* Options object for list operations
*/
export type ListOptions = {
/**
* - Filters to apply to the query (e.g., `{ status: 'Open' }`).
*/
filters: object;
/**
* - Array of field names to return (e.g., `['name', 'status']`).
*/
fields: string[];
/**
* - Maximum number of records to return. Defaults to `1000`.
*/
limit: number;
/**
* - Number of records to skip. Defaults to `0`.
*/
offset: number;
/**
* - Field to sort by with direction (e.g., `'creation desc'`).
*/
orderBy: string;
};
export { combine, dataPath, dataValue, dateFns, each, field, fields, fn, fnIf, lastReferenceValue, log, merge, sourceValue } from "@openfn/language-common";