is the following code correct to use in a component and if it is ,
- where is the source being deployed
- what are we getting in the response data :
import { axios } from “@pipedream/platform”;
async function deploySource() {
const sourceCode = `
import { axios } from “@pipedream/platform”;
export default defineComponent({
name: “github-issues-sample”,
description:
“This is a custom source for Velora AI, which fetches user credentials from an external source, and then uses the GET API to fetch GitHub issues for a user repo, with 15-minute timer intervals.”,
props: {
timer: {
type: “$.interface.timer”,
default: {
intervalSeconds: 15 * 60,
},
},
repo_full_name: {
type: “string”,
label: “Repository Full Name”,
description:
“Enter the name of the GitHub repository in the format ‘owner/repo’”,
},
nango_connection_id: {
type: “string”,
label: “Nango Connection ID”,
description: “Enter the Nango Connection ID”,
},
nango_integration_id: {
type: “string”,
label: “Nango Integration ID”,
description: “Enter the Nango Integration ID”,
},
velora_workflow_id: {
type: “string”,
label: “Velora Workflow ID”,
description: “Enter the Workflow ID”,
},
velora_workspace_id: {
type: “string”,
label: “Velora Workspace ID”,
description: “Enter the Workspace ID”,
},
},
dedupe: “greatest”,
async run({ steps, $ }) {
try {
// Step 1: Retrieve the GitHub token from Nango
const nangoResponse = await axios($, {
method: “GET”,
headers: {
Authorization: `Bearer ${process.env.VELORA_NANGO_SECRET_KEY}`,
},
url: `https://api.nango.dev/connection/\${nango_connection_id}?provider_config_key=\${nango_integration_id}\`,
});
// Extract the GitHub access token from the response
const github_token = nangoResponse.credentials.access_token;
// Step 2: Use the GitHub token to make a request to the GitHub API
const data = await axios($, {
method: "get",
headers: {
Authorization: \`Bearer \${github_token}\`,
},
url: \`https://api.github.com/repos/\${repo_full_name}/issues\`,
});
// Step 3: Emit each issue as an event
data.forEach((issue) => {
this.$emit(issue, {
id: issue.id,
summary: \`ISSUE \${issue.number}: \${issue.title}\`,
body: issue.body,
ts: issue.created_at && +new Date(issue.created_at),
velora_workflow_id: velora_workflow_id,
velora_workspace_id: velora_workspace_id,
});
});
} catch (error) {
// Handle errors gracefully
\$.error(\`Failed to fetch issues: \${error.message}\`);
}
},
});
`;
const response = await axios($, {
method: “POST”,
url: “https://api.pipedream.com/v1/sources”,
headers: {
Authorization: Bearer ${process.env.PIPEDREAM_API_KEY}
,
},
data: {
component: sourceCode, // Directly pass the source code as a string
props: {
repo_full_name: steps.trigger.event.query.repo_full_name,
nango_connection_id: steps.trigger.event.query.nango_connection_id,
nango_integration_id: steps.trigger.event.query.nango_integration_id,
velora_workflow_id: steps.trigger.event.query.velora_workflow_id,
velora_workspace_id: steps.trigger.event.query.velora_workspace_id,
},
},
});
console.log(“Finish!”)
return response.data;
}