Skip to content
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

pCloud component #1392

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

sergioeliot2039
Copy link
Collaborator

@sergioeliot2039 sergioeliot2039 commented Jul 11, 2021

Sources:

  • Watch Folder

Actions:

  • Copy a File
  • Create a Folder
  • Make an API Call
  • Copy a Folder
  • Download a File
  • Upload a File
  • List contents

Dev notes:

  1. Most of the actions related to an endpoint with API post method required using node.js FormData, but this doesn't seem documented in Cloud API docs, also the Content-lenght header was required. Make an API Call allows to post using FOrmData or application/json.
  2. Watch Folder is done against a folder's file created and modified times, because pCloud API doesn't support pagination. Perhaps using the max id for watching new files could be an alternative, but for accomplish this all files under the watched folder would have to be traversed.

@vercel
Copy link

vercel bot commented Jul 11, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

pipedream-docs – ./docs

🔍 Inspect: https://vercel.com/pipedreamers/pipedream-docs/2EamTarqhRERXzcUeL1S5CEPqcjE
✅ Preview: https://pipedream-docs-git-fork-sergioeliot2039-pcl-9c8fba-pipedreamers.vercel.app

pipedream-docs-redirect-do-not-edit – ./docs

🔍 Inspect: https://vercel.com/pipedreamers/pipedream-docs-redirect-do-not-edit/4U8GUrkjHJxf1xVkjfZaKsN9FEJJ
✅ Preview: https://pipedream-docs-redirect-do-not-edit-git-for-ae9186-pipedreamers.vercel.app

Copy link
Contributor

@compwright compwright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergioeliot2039 thank you for this! Per the Guidelines, please make the following changes:

  • Rebase off master
  • Fix all eslint issues
  • Refactor all props that are used more than once into the app file
  • Refactor all API access code to use the pcloud-sdk-js where possible, unless there is a good reason not to do so (please explain in detail wherever this is the case)
  • Move all require() statements to the top of the file, and declare them in a package.json file in the component dir
  • Remove the extraneous make-an-api-call/make-an-api-call.js action
  • Add options() methods to the fileId and folderId props to populate options

type: "action",
props: {
pcloud,
domainLocation: { propDefinition: [pcloud, "domainLocation"] },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dylburger can we move this into the app auth settings like we did for Mailgun?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dylburger this is good idea, to have Pipedream UI prompt for a domain or region, so that it is available in the auths variable. In my radar, besides pCloud, Zoho CRM prompts for region. her are the relevant URLs in the respective API documentation.
pCloud: https://docs.pcloud.com/methods/oauth_2.0/authorize.html
ZohoCrm: https://www.zoho.com/crm/developer/docs/api/v2/multi-dc.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, currently locationid gets returned in the access token request, which is the numeric ID corresponding to the location, so we can add this to the $auth variables. It looks like that might have to be mapped to EU / US here (we can't currently run those kind of custom transformations within the system that parses these variables from the OAuth flow), but you'll have access to the ID and shouldn't have to prompt the user.

I'll add that ASAP Monday.

@compwright compwright linked an issue Aug 4, 2021 that may be closed by this pull request
@compwright compwright changed the title [ACTION] pCloud #938 pCloud component Aug 4, 2021
@sergioeliot2039
Copy link
Collaborator Author

@sergioeliot2039 thank you for this! Per the Guidelines, please make the following changes:

  • Rebase off master
  • Fix all eslint issues
  • Refactor all props that are used more than once into the app file
  • Refactor all API access code to use the pcloud-sdk-js where possible, unless there is a good reason not to do so (please explain in detail wherever this is the case)
  • Move all require() statements to the top of the file, and declare them in a package.json file in the component dir
  • Remove the extraneous make-an-api-call/make-an-api-call.js action
  • Add options() methods to the fileId and folderId props to populate options

@dylburger could you please comment on this items rised by @compwright

  1. using pcloud-sdk-js, yes it's official, has only 62 weekly downloads, it was last updated 1 year ago. sorry to question again but i want to know if being an official library has much more precedence over the weekly download and maintenance criteria. i had been strict when choosing the sdk as you can see.
  2. about the make-an-api-call/make-an-api-call.js, this an action based from integromat
    image
    essentially, they expose this module for the user to create an arbitrary API call against the services. In my opinion, this is useful considering that with component actions atm the user can't reuse the underlying node.js code on the PD UI and edit it as needed, on the other hand, if keeping with the sdk, we'd have to mix the use of directly accessing the API to support this action. Should we implement this or not? Other apps will have indicated in the actions to do to include a "make an api call" so I think this is a good chance to if we should implement or just ignore it.

@dylburger
Copy link
Contributor

@sergioeliot2039 if the library is maintained by the company, and it's not visibly out-of-date or archived on GitHub (for example), I'll usually investigate it. If it's not well-documented or clearly buggy, I'll move to using the REST API. But since the JS client will normally facilitate a lot of the interaction with the API, it's normally worth our time to consider it. I think the number of weekly downloads with this one also speaks to the popularity of the app, and less the JS client itself.

Re: the Make an API call action, I actually wouldn't implement that. Getting it right with Pipedream actions may take time, and since our users are more technical than Integromat, I think they'll be able to more easily use the SDK / API directly for operations that aren't implemented in Pipedream. We have a large backlog of other, higher-priority actions, so I'd prefer to focus on those.

@compwright
Copy link
Contributor

compwright commented Aug 14, 2021 via email

@sergioeliot2039
Copy link
Collaborator Author

sergioeliot2039 commented Aug 17, 2021

@compwright pCloud is ready for review.
migration to use the pcloud SDK was not done -- SDK is buggy, breaks on any method call using the client. pCloud/pcloud-sdk-js#25

btw, from this app a user requested the "upload file" action

@compwright compwright self-requested a review August 17, 2021 17:59
@compwright
Copy link
Contributor

@compwright pCloud is ready for review.
migration to use the pcloud SDK was not done -- SDK is buggy, breaks on any method call using the client. pCloud/pcloud-sdk-js#25

btw, from this app a user requested the "upload file" action

I don't think it is a bug so much as it is perhaps incomplete/confusing documentation.

For context on that variable, see pCloud/pcloud-sdk-js@682ed7c

Can you give their SDK another try with this in mind?

@sergioeliot2039
Copy link
Collaborator Author

sergioeliot2039 commented Aug 18, 2021

@compwright pCloud is ready for review.
migration to use the pcloud SDK was not done -- SDK is buggy, breaks on any method call using the client. pCloud/pcloud-sdk-js#25
btw, from this app a user requested the "upload file" action

I don't think it is a bug so much as it is perhaps incomplete/confusing documentation.

For context on that variable, see pCloud/pcloud-sdk-js@682ed7c

Can you give their SDK another try with this in mind?

@compwright I gave another try and this is what I found.

The pCloud SDK is intended to be used under a browser. I tried a couple of example and it breaks with the error ReferenceErrorwindow is not defined
I checked all the example from the link you shared and they all call a method named initOauthToken to get the oauth token. The problem is with this method because it tries to open up a browser window for the user to authenticate and have an access token returned to he SDK.

This is initOauthToken implementation, there is only one signature on this method and in bold is the offended line.
function initOauthToken(options: oAuthOptions) {
const { client_id = null, redirect_uri = null, receiveToken = null, response_type = "token" } = options;

invariant(client_id, "client_id is required.");
invariant(redirect_uri, "redirect_uri is required.");
invariant(receiveToken, "receiveToken is required.");

const oauthUrl = buildOauthUrl({
redirect_uri: redirect_uri,
client_id: client_id,
response_type: response_type,
});

window.open(oauthUrl, "oauth", "width=680,height=700");
window.__setPcloudToken = function(token, locationid) {
receiveToken(token, locationid);
delete window.__setPcloudToken;
};
}

PLease your input.
As a workaround I think their repo could be forked and use it as a custom npm package such us in Publishing your npm package

Copy link
Contributor

@compwright compwright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is coming along, thanks for your work on this @sergioeliot2039!

@compwright
Copy link
Contributor

@sergioeliot2039 re: the pCloud SDK, you are incorrect about it being designed only for use in the browser. The SDK provides two types of clients: oauth and pcloud. All the references to window and so forth that you saw pertain to the oauth client, and yes, that one is for the browser. Use the other type. For more info, see https://github.com/pCloud/pcloud-sdk-js/blob/master/docs/createclient.md

I'd still like for us to switch this over to using their SDK, hopefully this gets you going in the right direction. If you have further issues let me know and I'm happy to help!

@sergioeliot2039
Copy link
Collaborator Author

@compwright @dylburger
i got working the pCloud client, using Pipedream's provided access token.
I tried the "pcloud" client with the access token, and it failed, I then checked the API and noticed login was required, so I "pcloud" with the login endpoint API works. I then instantiated the client with the access tokend and client type "oauth" and this worked.
I disregarded the documentation where it said it was needed to instantiate the "oauth" token with a initOauthToken method
this is a workflow working with pCloud's "oauth" client
https://pipedream.com/@sergio/pcloud-pcloud-sdk-client-working-p_n1Ce1Vo
this is with pCloud's "pcloud" client working which requries login (user/password)
https://pipedream.com/@sergio/pcloud-pcloud-sdk-client-working-with-login-p_aNCqAlp/edit
Sorry about the pivoting, I wrote down alonger Slack thread that I later erased.

"When you'd like an event to be emitted, by checking on the file's created or modified timestamps. Note: When you manually upload files on pCloud, the file originals's `created` and `modified` timestamps are preserved. When using pCloud API's `uploadfile` endpoint, these fields can be set by specifying the `mtime` and `ctime` parameters.",
default: "Created",
},
showdeleted: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergioeliot2039 this still needs to be done.

},
hooks: {
async deploy() {
const files = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergioeliot2039 this still needs to be done.

type: "action",
props: {
pcloud,
fileId: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergioeliot2039 please refactor all prop definitions into the main app file.

"overwrite",
],
},
modifiedTime: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move definition to app file

optional: true,
},
createdTime: {
type: "integer",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reuse previous definition

"If set, the uploaded file will be renamed, if file with the requested name exists in the folder.",
default: true,
},
mtime: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reuse time field definition

"Must be a UNIX timestamp",
optional: true,
},
ctime: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reuse time field definition

],
description: "ID of the folder you'd like to watch for created or modified files.",
},
event: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move definition to app file

].includes(this.emmitOn)
? "New created"
: "Modified";
const eventDate = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergioeliot2039 this still needs to be done

: pcloudEvent.modified;
return {
id: pcloudEvent.fileid,
summary: `${newOrModified} file "${pcloudEvent.name}"`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergioeliot2039 This still needs to be done.

@compwright compwright removed this from Ready for PR review in Component (Source and Action) Backlog Oct 15, 2021
@dannyroosevelt
Copy link
Collaborator

@sergioeliot2039 do you still have this on your radar to finish up? Do you need any help with it? Or do you want us to find someone else to take it over?

@sergioeliot2039
Copy link
Collaborator Author

@sergioeliot2039 do you still have this on your radar to finish up? Do you need any help with it? Or do you want us to find someone else to take it over?

I have pcloud on hold around September 7th at the request of @dylburger on Slack here. Back then we were discussing, in pCloud components, of including the account region prop available inside the auths variable, this dicussion is also on Slack

@sergioeliot2039
Copy link
Collaborator Author

@dylburger @dannyroosevelt being said that pcloud is on hold, i have in my radar this issue of pcloud "FIle UPload" action, this was a request by a user on Issue 934. Perhaps we should create a separate PR for File Upload, and only ship this action, and let the user enter the region prop, instead of have it provided in the auths variable. We'd leave the other actions on hold.

GTFalcao added a commit that referenced this pull request Jun 16, 2022
GTFalcao added a commit that referenced this pull request Jul 1, 2022
* [App:pCloud] Importing changes from PR #1392

* [App:pCloud] Description adjustments

* [App:pCloud] Syntax adjustments

* [App:pCloud] Linking doc in description

* [App:pCloud] Creating common action and $summary

* [App;pCloud] Improving prop sharing and naming

* [App:pCloud] Further refining descriptions, plus fixes

* [App:pCloud] Prop sharing improvements

* [App:pCloud] Customizing shared prop descriptions per component

* [App:pCloud] Creating location validation

* Initial PR adjustments

* [App:pCloud] Creating file validation

* [App:pCloud] Watch folder improvements

* [App:pCloud] Description updates

* [App:pCloud] Including docs in descriptions

* pnpm-lock.yaml pCloud #938

* [App:pCloud] Code review requested adjustments #1

* [App:pCloud] Adjusting custom description props

* [App:pCloud] Changing common props to propDefinitions

* [App:pCloud] Code review adjustments

* [App:pCloud] Fixing await inside try/catch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ACTION] pCloud
4 participants