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

fr/dropbox #204

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api-module-library/dropbox/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@friggframework/eslint-config"
}
24 changes: 24 additions & 0 deletions api-module-library/dropbox/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# dependencies
**/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

# webstorm local config
.idea/

.env
4 changes: 4 additions & 0 deletions api-module-library/dropbox/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# v0.0.1 (Jul 24 2023)

#### Generated
- Initialized from template
9 changes: 9 additions & 0 deletions api-module-library/dropbox/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2023 Left Hook Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5 changes: 5 additions & 0 deletions api-module-library/dropbox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Dropbox

This is the API Module for Dropbox that allows the [Frigg](https://friggframework.org) code to talk to the Dropbox API.

Read more on the [Frigg documentation site](https://docs.friggframework.org/api-modules/list/dropbox
142 changes: 142 additions & 0 deletions api-module-library/dropbox/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
const { OAuth2Requester } = require('@friggframework/module-plugin');
const { get } = require('@friggframework/assertions');

class Api extends OAuth2Requester {
constructor(params) {
super(params);
this.baseUrl = 'https://api.dropboxapi.com/2';
this.URLs = {
me: '/openid/userinfo',
listFolders: '/files/list_folder',
listFoldersContinue: '/files/list_folder/continue',
listSharedFolders: '/sharing/list_folders',
listSharedFoldersContinue: '/sharing/list_folders/continue',
};
this.authorizationUri = encodeURI(
`https://www.dropbox.com/oauth2/authorize?response_type=code` +
`&token_access_type=offline` +
`&prompt=consent` +
`&scope=${this.scope}` +
`&client_id=${this.client_id}` +
`&redirect_uri=${this.redirect_uri}`
);
this.tokenUri = 'https://api.dropboxapi.com/oauth2/token';
}



async getTokenFromCode(code) {
const params = new URLSearchParams();
params.append('grant_type', 'authorization_code');
params.append('client_id', this.client_id);
params.append('client_secret', this.client_secret);
params.append('redirect_uri', this.redirect_uri);
params.append('code', code);
const options = {
body: params,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
url: this.tokenUri,
};
const response = await this._post(options, false);
await this.setTokens(response);
return response;
}

async refreshAccessToken(refreshTokenObject) {
this.access_token = undefined;
const params = new URLSearchParams();
params.append('grant_type', 'refresh_token');
params.append('client_id', this.client_id);
params.append('client_secret', this.client_secret);
params.append('refresh_token', refreshTokenObject.refresh_token);

const options = {
body: params,
url: this.tokenUri,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
};
const response = await this._post(options, false);
response.refresh_token = refreshTokenObject.refresh_token;
await this.setTokens(response);
}

async getUserDetails() {
const options = {
url: this.baseUrl + this.URLs.me,
headers: {
'Content-Type': 'application/json'
},
body: {}
};
return this._post(options);
}
async getTokenIdentity() {
const userDetails = await this.getUserDetails();
return {identifier: userDetails.sub, name: `${userDetails.givenName} ${userDetails.familyName}`}
}

async listFolders(bodyOverride) {
const options = {
url: this.baseUrl + this.URLs.listFolders,
headers: {
'Content-Type': 'application/json'
},
body: {
path: '',
"include_deleted": false,
"include_has_explicit_shared_members": false,
"include_media_info": false,
"include_mounted_folders": true,
"include_non_downloadable_files": true,
"recursive": false,
}
};
options.body = {...options.body, ...bodyOverride}
return this._post(options);
}

async listFoldersContinue(cursor) {
const options = {
url: this.baseUrl + this.URLs.listFoldersContinue,
headers: {
'Content-Type': 'application/json'
},
body: {
cursor
}
};
return this._post(options);
}

async listSharedFolders(bodyOverride) {
const options = {
url: this.baseUrl + this.URLs.listSharedFolders,
headers: {
'Content-Type': 'application/json'
},
body: {
}
};
options.body = {...options.body, ...bodyOverride}
return this._post(options);
}

async listSharedFoldersContinue(cursor) {
const options = {
url: this.baseUrl + this.URLs.listSharedFoldersContinue,
headers: {
'Content-Type': 'application/json'
},
body: {
cursor
}
};
return this._post(options);
}
}

module.exports = { Api };
9 changes: 9 additions & 0 deletions api-module-library/dropbox/defaultConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "dropbox",
"label": "Dropbox",
"productUrl": "",
"apiDocs": "",
"logoUrl": "https://friggframework.org/assets/img/dropbox.jpeg",
"categories": [],
"description": "Dropbox"
}
13 changes: 13 additions & 0 deletions api-module-library/dropbox/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { Api } = require('./api');
const { Credential } = require('./models/credential');
const { Entity } = require('./models/entity');
const ModuleManager = require('./manager');
const Config = require('./defaultConfig');

module.exports = {
Api,
Credential,
Entity,
ModuleManager,
Config,
};
2 changes: 2 additions & 0 deletions api-module-library/dropbox/jest-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const { globalSetup } = require('@friggframework/test-environment');
module.exports = globalSetup;
2 changes: 2 additions & 0 deletions api-module-library/dropbox/jest-teardown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const { globalTeardown } = require('@friggframework/test-environment');
module.exports = globalTeardown;
21 changes: 21 additions & 0 deletions api-module-library/dropbox/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
*/

module.exports = {
// preset: '@friggframework/test-environment',
coverageThreshold: {
global: {
statements: 13,
branches: 0,
functions: 1,
lines: 13,
},
},
// A path to a module which exports an async function that is triggered once before all test suites
globalSetup: './jest-setup.js',

// A path to a module which exports an async function that is triggered once after all test suites
globalTeardown: './jest-teardown.js',
};
Loading