Skip to content

Commit

Permalink
Merge pull request #92 from RamprasadAkella/master
Browse files Browse the repository at this point in the history
parsing date strings as objects
  • Loading branch information
SandeepKumarG authored Dec 23, 2019
2 parents bd6807c + db2e13e commit ce0ba02
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,27 @@ the hook preSavePage function.
* The name of the function can be changed to anything you like.
*
* The function will be passed an 'options' argument and a callback argument.
* The first argument 'options' has the following structure: { bearerToken: '', preview: true/false, _exportId: '', _connectionId: '', _integrationId: '', _flowId: '', data: [], errors: [], settings: {}, configuration: {} }
* The first argument 'options' has the following fields:
* 'bearerToken' - a one-time bearer token which can be used to invoke selected integrator.io API routes.
* 'preview' - a boolean flag used to indicate that this export is being used by the integrator.io UI to get a sample of the data being exported.
* '_exportId' - the _exportId of the export for which the hook is defined.
* '_connectionId' - the _id of the connection linked to the export for which the hook is defined.
* '_integrationId' - the _id of the integration linked to the export for which the hook is defined.
* '_flowId' - the _id of the flow linked to the export for which the hook is defined.
* 'data' - an array of records representing one page of data. An individual record can be an object {}, or an array [] depending on the data source.
* 'errors' - an array of errors where each error has the structure {code: '', message: '', source: ''}.
* '_exportId' - the _exportId currently running.
* '_connectionId' - the _connectionId currently running.
* '_flowId' - the _flowId currently running.
* '_integrationId' - the _integrationId currently running.
* 'pageIndex' - 0 based. context is the batch export currently running.
* 'lastExportDateTime' - delta exports only.
* 'currentExportDateTime' - delta exports only.
* 'settings' - a container object for all the SmartConnector settings associated with the integration (applicable to SmartConnectors only).
* 'configuration' - an optional configuration object that can be set directly on the export resource (to further customize the hooks behavior).
* 'pageContext' - an object containing following page contextual data.
* 'lastExportDateTime' - this field is set only when export type is delta.
* 'currentExportDateTime' - this field is set only when export type is delta.
* 'pageIndex' - an index representing current page number starting from one.
*
* The function needs to call back with the following arguments:
* 'err' - an error object to signal a fatal exception and will stop the flow.
* 'responseData' - an object that has the following structure: { data: [], errors: [{code: '', message: '', source: ''}], abort: true }
* 'responseData' - an object that has the following structure: { data: [], errors: [{code: '', message: '', source: ''}], abort: true|false }
* 'data' - your modified data.
* 'errors' - your modified errors.
* 'abort' - boolean value. When true, export stops processing further pages and the current page will be generated with the data and errors of this preSavePageHook response.
* 'abort' - instruct the batch export currently running to stop generating new pages of data.
*/

module.hooks.preSavePageFunction = function (options, callback) {
Expand Down
15 changes: 15 additions & 0 deletions lib/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ Extension.prototype.callFunction = function (functionOptions, extensionOptions,
return callback({statusCode: 422, errors: [errors.get('EXTENSION_INCORRECT_FUNCTION')]})
}

if (extensionOptions.lastExportDateTime) {
try {
extensionOptions.lastExportDateTime = new Date(extensionOptions.lastExportDateTime)
} catch (err) {
return callback({statusCode: 422, errors: [{ message: err.message, code: err.code }]})
}
}
if (extensionOptions.currentExportDateTime) {
try {
extensionOptions.currentExportDateTime = new Date(extensionOptions.lastExportDateTime)
} catch (err) {
return callback({statusCode: 422, errors: [{ message: err.message, code: err.code }]})
}
}

// invoking the function from the object's context, this is to make sure if the
// module is an instance of a function and instance propeties are used within
// extension function, then those are evaluated with respect to the instance.
Expand Down

0 comments on commit ce0ba02

Please sign in to comment.