-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add Csvbox integration with import event trigger and sample row functionality #18982
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
Open
SumitYewale-Thalia
wants to merge
14
commits into
PipedreamHQ:master
Choose a base branch
from
SumitYewale-Thalia:feature/csvbox-app-integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bd37d5b
Code: Custom CSVBOX source implemented
SumitYewale-Thalia 6dc70d3
Merge branch 'master' of https://github.com/SumitYewale-Thalia/pipedr…
SumitYewale-Thalia fca35f3
code: fixes added for calling csvbox api we getting response from API
SumitYewale-Thalia 5cc5ea5
Fix: updated API from constant
SumitYewale-Thalia b099d8b
Fixed: Removed unauthorized code
SumitYewale-Thalia fa29835
Fixed: Removed unnecessory files and updated the source name
SumitYewale-Thalia 89914a0
Fixed: fixed code issues for run function
SumitYewale-Thalia fd3ca8a
Code: Fixed package json version
SumitYewale-Thalia b052912
Code: unused code removed and improvements done
SumitYewale-Thalia f3afbbc
Fixed: fixed code repetation and avoiding unecessary ambiguity
SumitYewale-Thalia 087a246
Code: code improvements done
SumitYewale-Thalia 2c34709
Code: fixed event name convention
SumitYewale-Thalia 46da2a6
Code: fixed error throw
SumitYewale-Thalia e1ac262
Merge branch 'master' into feature/csvbox-app-integration
SumitYewale-Thalia 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
119 changes: 0 additions & 119 deletions
119
components/csvbox/actions/submit-spreadsheet/submit-spreadsheet.mjs
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,5 @@ | ||
| const BASE_URL = "https://api.csvbox.io/1.1/pipedream"; | ||
|
|
||
| export default { | ||
| BASE_URL | ||
| }; |
This file contains hidden or 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,149 @@ | ||
| import app from "../csvbox.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "csvbox-new-row", | ||
| name: "New Import", | ||
| description: "Emit new events when a new row is added to a CSVBox sheet", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| db: "$.service.db", | ||
| app, | ||
| sheetId: { | ||
| propDefinition: [app, "sheetId"], | ||
| description: "Select the sheet to receive data from", | ||
| }, | ||
| http: "$.interface.http", | ||
| }, | ||
| hooks: { | ||
| async activate() { | ||
| if (!this.sheetId) { | ||
| throw new Error("Sheet selection is required before activation."); | ||
| } | ||
|
|
||
| try { | ||
| const { data } = await this.app.createHook({ | ||
| data: { | ||
| sheet_slug: this.sheetId, | ||
| webhook_url: this.http.endpoint, | ||
| }, | ||
| }); | ||
|
|
||
| const { webhookId, sample_response } = data; | ||
| this._setHookID(webhookId); | ||
|
|
||
| if (!Array.isArray(sample_response) || sample_response.length === 0) { | ||
| throw new Error("Unable to fetch sample data from selected sheet."); | ||
| } | ||
|
|
||
| const first = sample_response[0]; | ||
| this.$emit({ | ||
| import_id: `sample_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`, | ||
| sheet_id: this.sheetId, | ||
| sheet_name: first.sheet_name || "Sample Data", | ||
| row_number: first.row_number || 1, | ||
| row_data: first.row_data || first, | ||
| total_rows: first.total_rows || 10, | ||
| env_name: first.env_name || "default", | ||
| custom_fields: first.custom_fields || { user_id: "default123" }, | ||
| import_description: first.import_description || "This is a sample test import", | ||
| original_filename: first.original_filename || "product_details.csv", | ||
| }, { | ||
| id: `sample_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`, | ||
SumitYewale-Thalia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| summary: `Sample data loaded from sheet - ${first.sheet_name} `, | ||
SumitYewale-Thalia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ts: Date.now(), | ||
| }); | ||
|
|
||
|
|
||
| this._setSampleRow(first); | ||
SumitYewale-Thalia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } catch (err) { | ||
| console.error("Error during source activation:", err); | ||
| throw new Error(err?.message || "Failed to register webhook or fetch sample data."); | ||
| } | ||
SumitYewale-Thalia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| async deactivate() { | ||
| try { | ||
| const hookId = this._getHookID(); | ||
| if (hookId) { | ||
| await this.app.deleteHook({ | ||
| data: { | ||
| webhook_id: hookId, | ||
| sheet_slug: this.sheetId, | ||
| }, | ||
| }); | ||
| this._setHookID(null); | ||
| this._setSampleRow(null); | ||
| } | ||
| } catch (err) { | ||
| console.error("Deactivation Error:", err); | ||
| } | ||
| }, | ||
| async deploy() { | ||
| const sampleRow = this._getSampleRow(); | ||
| if (sampleRow) { | ||
| this.$emit(sampleRow, { | ||
| id: `sample_${Date.now()}`, | ||
| summary: "Sample row event", | ||
| ts: Date.now(), | ||
| }); | ||
SumitYewale-Thalia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| else { | ||
| console.log("No sample row data found to emit during deploy."); | ||
| return; | ||
| } | ||
| }, | ||
SumitYewale-Thalia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| methods: { | ||
| _getHookID() { | ||
| return this.db.get("hookId"); | ||
| }, | ||
| _setHookID(hookID) { | ||
| this.db.set("hookId", hookID); | ||
| }, | ||
| _getSampleRow() { | ||
| return this.db.get("sampleRow"); | ||
| }, | ||
| _setSampleRow(rowData) { | ||
| this.db.set("sampleRow", rowData); | ||
| }, | ||
SumitYewale-Thalia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| async run(event) { | ||
| const { body } = event; | ||
|
|
||
| if (!Array.isArray(body) || body.length === 0) { | ||
| console.error("Received webhook payload without row data"); | ||
| return; | ||
| } | ||
|
|
||
| for (const row of body) { | ||
| this.$emit(row, { | ||
| id: row.import_id || `${row.sheet_id}_${row.row_number}_${Date.now()}`, | ||
| summary: `New data imported to sheet ${row.sheet_name}`, | ||
| ts: Date.now(), | ||
| }); | ||
| } | ||
| }, | ||
| sampleEvents: [ | ||
| { | ||
| import_id: 79418895, | ||
| sheet_id: 55, | ||
| sheet_name: "Products", | ||
| row_number: 1, | ||
| row_data: { | ||
| "col1": "", | ||
| "col2": "", | ||
| "col3": "", | ||
| "col4": "", | ||
| "col5": "", | ||
| }, | ||
| total_rows: 10, | ||
| env_name: "default", | ||
| custom_fields: { | ||
| user_id: "default123" | ||
| }, | ||
| import_description: "This is a sample test import", | ||
| original_filename: "product_details.csv", | ||
| } | ||
| ], | ||
| }; | ||
This file contains hidden or 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,55 +1,80 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
| import constants from "./common/constants.mjs"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "csvbox", | ||
| propDefinitions: { | ||
| sheetLicenseKey: { | ||
| sheetId: { | ||
| type: "string", | ||
| label: "Sheet License Key", | ||
| description: "The unique identifier for your CSVBox sheet. You can find it in **Sheets - Edit - Code Snippet - Sheet License Key**.", | ||
| }, | ||
| userId: { | ||
| type: "string", | ||
| label: "User ID", | ||
| description: "The unique identifier for the user. You can find it in the **Dashboard - Edit - Code Snippet**.", | ||
| optional: true, | ||
| }, | ||
| hasHeaders: { | ||
| type: "boolean", | ||
| label: "Has Headers", | ||
| description: "Whether the spreadsheet has headers.", | ||
| label: "Sheet", | ||
| description: "Select the sheet you want to receive data from", | ||
| optional: true, | ||
| async options() { | ||
| const { data } = await this.listSheets(); | ||
| return data.map((sheet) => ({ | ||
| label: sheet.name, | ||
| value: sheet.value, | ||
| })); | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| methods: { | ||
| getUrl(path) { | ||
| return `https://api.csvbox.io/1.1${path}`; | ||
| _getAuthKeys() { | ||
| return this.$auth.api_key; | ||
| }, | ||
| _getSecretAuthKeys() { | ||
| return this.$auth.secret_api_key; | ||
| }, | ||
| getHeaders(headers) { | ||
| _getUrl(path) { | ||
| return `${constants.BASE_URL}${path}`; | ||
| }, | ||
| _getHeaders(headers) { | ||
| return { | ||
| "Content-Type": "application/json", | ||
| "x-csvbox-api-key": `${this.$auth.api_key}`, | ||
| "x-csvbox-secret-api-key": `${this.$auth.secret_api_key}`, | ||
| ...headers, | ||
| accept: "application/json", | ||
| "Content-Type": "application/json", | ||
| "x-csvbox-api-key": this._getAuthKeys(), | ||
| "x-csvbox-secret-api-key": this._getSecretAuthKeys(), | ||
| }; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, headers, ...args | ||
| } = {}) { | ||
| return axios($, { | ||
| debug: true, | ||
| url: this.getUrl(path), | ||
| headers: this.getHeaders(headers), | ||
|
|
||
| async _makeRequest({ $ = this, path, headers, ...otherConfig } = {}) { | ||
| const config = { | ||
| url: this._getUrl(path), | ||
| headers: this._getHeaders(headers), | ||
| returnFullResponse: true, | ||
| ...otherConfig, | ||
| }; | ||
| return axios($, config); | ||
| }, | ||
|
|
||
| async createHook({ data, ...args } = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/register-webhook", | ||
| data, | ||
| ...args, | ||
| }); | ||
| }, | ||
| submitFile(args = {}) { | ||
|
|
||
| async deleteHook({ data, ...args } = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/file", | ||
| method: "DELETE", | ||
| path: `/delete-webhook`, | ||
| data, | ||
| ...args, | ||
| }); | ||
| }, | ||
|
|
||
| async listSheets(args = {}) { | ||
| const res = await this._makeRequest({ | ||
| method: "GET", | ||
| path: "/list-sheets", | ||
| ...args, | ||
| }); | ||
| return res; | ||
| }, | ||
| }, | ||
| }; |
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.