-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Adding output fields for dataset items #51
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
52b9397
feat: Adding output fields for dataset items [WIP]
drobnikj a97fb9a
fix: Fixing e2e tests, adding dynamic output fields in fetch dataset …
drobnikj 74b14e6
fix: test and output schema for actor task
drobnikj 68bf29c
fix: adding notes
drobnikj 414d6d4
fix: adding change log
drobnikj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "apify-zapier-integration", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"description": "Apify integration for Zapier platform", | ||
"homepage": "https://apify.com/", | ||
"author": "Jakub Drobník <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const _ = require('lodash'); | ||
const { ACTOR_JOB_STATUSES } = require('@apify/consts'); | ||
const { getDatasetItems } = require('./apify_helpers'); | ||
const { wrapRequestWithRetries } = require('./request_helpers'); | ||
const { APIFY_API_ENDPOINTS } = require('./consts'); | ||
const { convertPlainObjectToFieldSchema } = require('./zapier_helpers'); | ||
|
||
/** | ||
* Download items from dataset and create FieldSchema out of them. | ||
* @param {string} datasetId | ||
* @returns {Promise<*[]>} | ||
*/ | ||
const getDatasetItemsOutputFields = async (z, datasetId, actorId, keyPrefix = 'datasetItems[]') => { | ||
let datasetItems; | ||
try { | ||
datasetItems = await getDatasetItems(z, datasetId, { | ||
limit: 10, | ||
}, actorId); | ||
} catch (err) { | ||
z.console.error('Error while fetching dataset items', err); | ||
// Return default output fields, if there is no successful run yet or any other error. | ||
return []; | ||
} | ||
|
||
const { items } = datasetItems; | ||
// If there are no items, return default output fields. | ||
if (items.length === 0) return []; | ||
// NOTE: We are using the first 10 items to generate output fields to cover most of the cases. | ||
const mergedItem = _.merge({}, ...items); | ||
return convertPlainObjectToFieldSchema(mergedItem, keyPrefix); | ||
}; | ||
|
||
const getActorDatasetOutputFields = async (z, bundle) => { | ||
const { actorId } = bundle.inputData; | ||
let lastSuccessDatasetItems; | ||
try { | ||
lastSuccessDatasetItems = await wrapRequestWithRetries(z.request, { | ||
url: `${APIFY_API_ENDPOINTS.actors}/${actorId}/runs/last`, | ||
params: { | ||
status: ACTOR_JOB_STATUSES.SUCCEEDED, | ||
}, | ||
}); | ||
} catch (err) { | ||
// 404 status = There is not successful run yet. | ||
if (err.status !== 404) { | ||
z.console.error('Error while fetching dataset items', err); | ||
} | ||
// Return default output fields, if there is no successful run yet or any other error. | ||
return []; | ||
} | ||
const { data: run } = lastSuccessDatasetItems; | ||
return getDatasetItemsOutputFields(z, run.defaultDatasetId, actorId); | ||
}; | ||
|
||
const getTaskDatasetOutputFields = async (z, bundle) => { | ||
const { taskId } = bundle.inputData; | ||
let lastSuccessDatasetItems; | ||
try { | ||
lastSuccessDatasetItems = await wrapRequestWithRetries(z.request, { | ||
url: `${APIFY_API_ENDPOINTS.tasks}/${taskId}/runs/last`, | ||
params: { | ||
status: ACTOR_JOB_STATUSES.SUCCEEDED, | ||
}, | ||
}); | ||
} catch (err) { | ||
// 404 status = There is not successful run yet. | ||
if (err.status !== 404) { | ||
z.console.error('Error while fetching dataset items', err); | ||
} | ||
// Return default output fields, if there is no successful run yet or any other error. | ||
return []; | ||
} | ||
const { data: run } = lastSuccessDatasetItems; | ||
return getDatasetItemsOutputFields(z, run.defaultDatasetId, run.actId); | ||
}; | ||
|
||
module.exports = { | ||
getDatasetItemsOutputFields, | ||
getActorDatasetOutputFields, | ||
getTaskDatasetOutputFields, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const { getActorDatasetOutputFields } = require('../output_fields'); | ||
|
||
/** | ||
* This is hidden trigger is used to test getActorDatasetOutputFields function. | ||
* It is only way how to test function like that in Zapier context, | ||
* check my issue https://github.com/zapier/zapier-platform-cli/issues/418 | ||
*/ | ||
module.exports = { | ||
key: 'getActorDatasetOutputFieldsTest', | ||
noun: 'Dataset Output Additional Fields', | ||
display: { | ||
label: 'Dataset Output Additional Fields', | ||
description: 'This is a hidden trigger used to test getActorDatasetOutputFields function.', | ||
hidden: true, | ||
}, | ||
operation: { | ||
// since this is a "hidden" trigger, there aren't any inputFields needed | ||
perform: getActorDatasetOutputFields, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just fixing typo