-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Setup eslint - Setup eslint under Airbnb standards - Add CI action with linter - Update code to fit linting standards
- Loading branch information
Showing
12 changed files
with
144 additions
and
85 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist/ |
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,17 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
node: true, | ||
}, | ||
extends: [ | ||
'airbnb-base', | ||
], | ||
parserOptions: { | ||
ecmaVersion: 12, | ||
sourceType: 'module', | ||
}, | ||
rules: { | ||
'import/extensions': 0, | ||
}, | ||
}; |
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,29 @@ | ||
name: CI | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
ci: | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest] | ||
node: [10, 12, 14] | ||
runs-on: ${{ matrix.os }} | ||
continue-on-error: true | ||
steps: | ||
- name: Checkout Package 🛎️ | ||
uses: actions/checkout@v2 | ||
- name: Setup Node.JS 🎱 | ||
uses: actions/setup-node@v2.1.2 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
- name: Install Package 📥 | ||
run: | | ||
npm install | ||
- name: Build Package 🏗️ | ||
run: | | ||
npm run build | ||
- name: Run Linter 🗞️ | ||
run: | | ||
npm run lint |
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 |
---|---|---|
@@ -1,56 +1,55 @@ | ||
import { DropboxAuth } from 'dropbox'; | ||
|
||
function dispatchResult() { | ||
const params = window.location.href; | ||
if (window.opener) { | ||
// send them to the opening window | ||
window.opener.postMessage(params); | ||
// close the popup | ||
window.close(); | ||
} | ||
} | ||
|
||
window.addEventListener('load', dispatchResult); | ||
|
||
const popupFeatures = | ||
'toolbar=no, menubar=no, width=600, height=800, top=100, left=100'; | ||
const popupFeatures = 'toolbar=no, menubar=no, width=600, height=800, top=100, left=100'; | ||
const popupName = 'Dropbox OAuth'; | ||
export default class DropboxPopup { | ||
constructor(options) { | ||
this.clientId = options.clientId; | ||
this.clientSecret = options.clientSecret; | ||
this.authObject = new DropboxAuth({ | ||
clientId: this.clientId, | ||
clientSecret: this.clientSecret | ||
}); | ||
this.redirectUri = options.redirectUri; | ||
this.codeOffset = this.redirectUri.length + 7 // format is `${redirectUri}/?code={code} | ||
} | ||
constructor(options) { | ||
this.clientId = options.clientId; | ||
this.clientSecret = options.clientSecret; | ||
this.authObject = new DropboxAuth({ | ||
clientId: this.clientId, | ||
clientSecret: this.clientSecret, | ||
}); | ||
this.redirectUri = options.redirectUri; | ||
this.codeOffset = this.redirectUri.length + 7; // format is `${redirectUri}/?code={code} | ||
} | ||
|
||
authUser(callback) { | ||
window.removeEventListener('message', this.handleRedirect); | ||
this.callback = callback; | ||
this.callback.bind(this); | ||
const authUrl = this.authObject.getAuthenticationUrl(this.redirectUri, '', 'code', 'offline'); | ||
const popupWindow = window.open(authUrl, popupName, popupFeatures); | ||
popupWindow.focus(); | ||
authUser(callback) { | ||
window.removeEventListener('message', this.handleRedirect); | ||
this.callback = callback; | ||
this.callback.bind(this); | ||
const authUrl = this.authObject.getAuthenticationUrl(this.redirectUri, '', 'code', 'offline'); | ||
const popupWindow = window.open(authUrl, popupName, popupFeatures); | ||
popupWindow.focus(); | ||
|
||
window.addEventListener('message', event => this.handleRedirect(event), false); | ||
} | ||
window.addEventListener('message', (event) => this.handleRedirect(event), false); | ||
} | ||
|
||
handleRedirect(event) { | ||
const { data } = event; | ||
const code = data.substring(this.codeOffset); | ||
this.authObject.getAccessTokenFromCode(this.redirectUri, code) | ||
.then((response) => { | ||
const result = response.result; | ||
this.authObject.setAccessToken(result.access_token); | ||
this.authObject.setRefreshToken(result.refresh_token); | ||
this.authObject.setAccessTokenExpiresAt(new Date(Date.now() + result.expires_in)); | ||
this.callback(this.authObject) | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
}); | ||
} | ||
handleRedirect(event) { | ||
const { data } = event; | ||
const code = data.substring(this.codeOffset); | ||
this.authObject.getAccessTokenFromCode(this.redirectUri, code) | ||
.then((response) => { | ||
const { result } = response; | ||
this.authObject.setAccessToken(result.access_token); | ||
this.authObject.setRefreshToken(result.refresh_token); | ||
this.authObject.setAccessTokenExpiresAt(new Date(Date.now() + result.expires_in)); | ||
this.callback(this.authObject); | ||
}) | ||
.catch((error) => { | ||
throw error; | ||
}); | ||
} | ||
} | ||
|
||
function dispatchResult() { | ||
const params = window.location.href; | ||
if (window.opener) { | ||
// send them to the opening window | ||
window.opener.postMessage(params); | ||
// close the popup | ||
window.close(); | ||
} | ||
} |
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,5 @@ | ||
module.exports = { | ||
rules: { | ||
'no-console': 0, | ||
}, | ||
}; |
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,10 +1,11 @@ | ||
const express = require('express'); | ||
|
||
const app = express(); | ||
const port = 8080; | ||
|
||
app.use('/', express.static('test/static')); | ||
app.use('/src', express.static('dist')); | ||
|
||
app.listen(port, () => { | ||
console.log(`Listening at http://localhost:${port}`); | ||
}); | ||
console.log(`Listening at http://localhost:${port}`); | ||
}); |