/** * State object * @typedef {Object} SurveyCTOState * @property data - the parsed response body * @property response - the response from the SurveyCTO server, including headers, statusCode etc * @property references - an array of all previous data objects used in the Job. **/ /** * List State object * @typedef {Object} SurveyCTOListState * @property data - the parsed response body * @property response - the response from the server with `total` and `nextCursor` * @property references - an array of all previous data objects used in the Job. **/ /** * Execute a sequence of operations. * Wraps `@openfn/language-common/execute`, and prepends initial state for http. * @example * execute( * create('foo'), * delete('bar') * )(state) * @private * @param {Operations} operations - Operations to be performed. * @returns {Operation} */ export function execute(...operations: Operations): Operation; /** * Options provided to `fetchSubmissions()` * @typedef {Object} FetchSubmissionOptions * @public * @property {string} [date=0] - Fetch only submissions from this timestamp. Acccepts SuvreyCTO date strings, unix and epoch timestamps, and ISO dates. By default, all submissions will be retrieved. * @property {string} [format=json] - Format the submission data type as `csv` or `json`. * @property {string} [status] - Review status. Can be either, `approved`, `rejected`, `pending` or combine eg `approved|rejected`. */ /** * Fetch form submissions. * * If a date filter is provided, it will be converted internally to the surveyCTO `MMM dd, yyy h:mm:ss` format (in UTC time). * @example Fetch all form submissions * fetchSubmissions('test'); * @example With SurveyCTO date format (UTC) * fetchSubmissions('test', { date: 'Apr 18, 2024 6:26:21 AM' }); * @example Using a rolling cursor * cursor((state) => state.cursor, { defaultValue: 'today' }); * fetchSubmissions('test', { date: (state) => state.cursor, format: 'csv' }); * cursor('now'); * @example Formatting the results to CSV String * fetchSubmissions('test', { format: 'csv' }); * @example With reviewStatus filter * fetchSubmissions('test', { status: 'approved|rejected' }); * @public * @function * @param {string} formId - Form id * @param {FetchSubmissionOptions} options - Form submission date, format, status parameters * @returns {Operation} * @state {SurveyCTOState} */ export function fetchSubmissions(formId: string, options?: FetchSubmissionOptions): Operation; /** * List resources from SurveyCTO * @public * @example List all dataset records * list(`datasets/${$.datasetId}/records`) * @example List all datasets * list('datasets') * @example List dataset records with pagination options * list(`datasets/${$.datasetId}/records`,{ * limit: 2, * }); * @example List datasets with pagination options * list('datasets',{ * limit: 2, * }); * @function * @param {string} resource - Resource to fetch * @param {object} options - Optional request query options. [See the API docs for details](https://developer.surveycto.com/api-v2.html#getdatasets-parameters) * @property {number} options.limit - Maximum number of items to return. Defaults to 20. Maximum is 1000. * @property {string} options.cursor - Optional string to specify the starting point of the next page of results. * @returns {Operation} * @state {SurveyCTOListState} */ export function list(resource: string, options?: object): Operation; /** * Update (if exist) or create a dataset in SurveyCTO * @public * @example Upsert a dataset * upsertDataset({ * id: 'enum_dataset', * title: 'Enum Dataset', * discriminator: 'ENUMERATORS', * locationContext: { * parentGroupId: 1, * siblingAbove: { * id: 'new_dataset', * itemClass: 'DATASET', * }, * }, * allowOfflineUpdates: false, * idFormatOptions: { * prefix: 'enum', * suffix: '', * numberOfDigits: '8', * allowCapitalLetters: true, * }, * }); * @function * @param {object} data - The dataset object to create or update * @returns {Operation} * @state {SurveyCTOState} */ export function upsertDataset(data: object): Operation; /** * Update (if exist) or create a dataset record in SurveyCTO * @public * @example Upsert a dataset record * upsertRecord('enumerators_dataset', { * id: '2', * name: 'Trial update', * users: 'All users', * }); * @function * @param {string} datasetId - ID of the dataset * @param {object} data - The record object to create or update * @returns {Operation} * @state {SurveyCTOState} */ export function upsertRecord(datasetId: string, data: object): Operation; /** * Upload CSV dataset records * @public * @example Upload records * uploadCsvRecords('enumerators_dataset', [ * { * id: '4', * name: 'Trial update', * users: 'All users', * }, * { * id: '5', * name: 'Trials', * users: 'All users here', * }, * ]); * @example Upload records with metadata * uploadCsvRecords( * 'enumerators_dataset', * [ * { * id: '4', * name: 'Trial update', * users: 'All users', * }, * { * id: '5', * name: 'Trials', * users: 'All users here', * }, * ], * { * uploadMode: 'MERGE', * joiningField: 'id', * } * ); * @function * @param {string} datasetId - ID of the dataset * @param {string} rows - An array of JSON objects to be uploaded as records. The data will be converted to CSV format before upload. * @param {object} metadata - Optional metadata for configuring how the uploaded data should be processed * @property {string} joiningField - Optional field name to use for merging records. Required when uploadMode is `MERGE`. * @property {string} uploadMode - Optional upload mode. One of `APPEND` (default), `MERGE` and `CLEAR`. * @returns {Operation} * @state {SurveyCTOState} */ export function uploadCsvRecords(datasetId: string, rows: string, metadata?: object): Operation; /** * Sets `state.cursor` to a SurveyCTO timestamp string (`MMM dd, yyy h:mm:ss a`). * This supports natural language dates like `now`, `today`, `yesterday`, `n hours ago`, `n days ago`, and `start`, * which will be converted into timestamp strings. * See the usage guide at {@link https://docs.openfn.org/documentation/jobs/job-writing-guide#using-cursors} * @public * @example Use a cursor from state if present, or else use the default value * cursor('today') * fetchSubmissions('test', { date: $.cursor }); * @function * @param {any} value - the cursor value. Usually an ISO date, natural language date, or page number * @param {object} options - options to control the cursor. * @param {string} options.key - set the cursor key. Will persist through the whole run. * @param {any} options.defaultValue - the value to use if value is falsy * @param {Function} options.format - custom formatter for the final cursor value * @returns {Operation} */ export function cursor(value: any, options: { key: string; defaultValue: any; format: Function; }): Operation; /** * Converts an array of objects to a CSV buffer. * @public * @example * jsonToCSVBuffer([ * { * lastName: 'Rothfuss', * firstName: 'Patrick', * book: 'The Name of the Wind' * }, * { * lastName: 'Martin', * firstName: 'George', * book: 'A Game of Thrones' * }, * ]) * @param {*} rows An array of JSON objects. * @returns {Operation} */ export function jsonToCSVBuffer(rows: any): Operation; /** * State object */ export type SurveyCTOState = { /** * - the parsed response body */ data: any; /** * - the response from the SurveyCTO server, including headers, statusCode etc */ response: any; /** * - an array of all previous data objects used in the Job. */ references: any; }; /** * List State object */ export type SurveyCTOListState = { /** * - the parsed response body */ data: any; /** * - the response from the server with `total` and `nextCursor` */ response: any; /** * - an array of all previous data objects used in the Job. */ references: any; }; /** * Options provided to `fetchSubmissions()` */ export type FetchSubmissionOptions = any; export { alterState, chunk, combine, dataPath, dataValue, dateFns, field, fields, fn, fnIf, lastReferenceValue, log, merge, parseCsv, sourceValue } from "@openfn/language-common";