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

feat: update quickbooks api module to v1 #22

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
25,190 changes: 160 additions & 25,030 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 0 additions & 13 deletions packages/needs-updating/qbo/index.js

This file was deleted.

134 changes: 0 additions & 134 deletions packages/needs-updating/qbo/manager.js

This file was deleted.

26 changes: 0 additions & 26 deletions packages/needs-updating/qbo/manager.test.js

This file was deleted.

16 changes: 0 additions & 16 deletions packages/needs-updating/qbo/models/credential.js

This file was deleted.

9 changes: 0 additions & 9 deletions packages/needs-updating/qbo/models/entity.js

This file was deleted.

4 changes: 4 additions & 0 deletions packages/v1-ready/qbo/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
QBO_CLIENT_ID=
QBO_CLIENT_SECRET=
QBO_SCOPE=
REDIRECT_URI=http://localhost:3000/redirect
File renamed without changes.
31 changes: 19 additions & 12 deletions packages/needs-updating/qbo/api.js → packages/v1-ready/qbo/api.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
const {get, OAuth2Requester} = require('@friggframework/core');
const moment = require('moment');
const fetch = require('node-fetch');
const OAuthClient = require('intuit-oauth');
const QuickBooks = require('node-quickbooks');


const oauthClient = new OAuthClient({
clientId: process.env.QBO_OAUTH_KEY,
clientSecret: process.env.QBO_OAUTH_SECRET,
clientId: process.env.QBO_CLIENT_ID,
clientSecret: process.env.QBO_CLIENT_SECRET,
environment: process.env.QBO_OAUTH_ENV, // 'sandbox' || 'production',
redirectUri: process.env.QBO_OAUTH_REDIRECT_URI,
redirectUri: `${process.env.REDIRECT_URI}/qbo`,
});

const QuickBooks = require('node-quickbooks');
const util = require('util');

class QuickBooksPromise {
constructor(params) {
this.key = get(params, 'key');
Expand All @@ -28,7 +25,7 @@ class QuickBooksPromise {
this.accessToken,
false, // no token secret for oAuth 2.0
this.realmId,
this.environment == 'sandbox', // use the sandbox?
this.environment === 'sandbox', // use the sandbox?
true, // enable debugging?
null, // set minorversion, or null for the latest version
'2.0', // oAuth version
Expand Down Expand Up @@ -72,7 +69,7 @@ class Api extends OAuth2Requester {
const authorizationUri = oauthClient.authorizeUri({
scope: [
OAuthClient.scopes.Accounting,
// OAuthClient.scopes.OpenId,
OAuthClient.scopes.OpenId,
// OAuthClient.scopes.Email,
// OAuthClient.scopes.Payment
],
Expand All @@ -86,8 +83,11 @@ class Api extends OAuth2Requester {
params.baseURL = process.env.QBO_BASE_URL;

super(params);
this.key = oauthClient.clientId;
this.secret = oauthClient.clientSecret;
this.realmId = get(params, 'realmId', null);
this.qbo = null;
this.tokenUri = OAuthClient.tokenEndpoint;

if (this.isAuthenticated()) {
oauthClient.setToken({
Expand All @@ -107,14 +107,21 @@ class Api extends OAuth2Requester {
this.qbo = new QuickBooksPromise({
key: this.key,
secret: this.secret,
accessToken: this.accessToken,
accessToken: this.access_token,
realmId: this.realmId,
environment: oauthClient.environment,
refreshToken: this.refreshToken,
refreshToken: this.refresh_token,
refreshTokenFunction: this.refreshAccessToken.bind(this),
});
}

async getUserDetails() {
const userDetails = await this._get({
url: OAuthClient[`userinfo_endpoint_${oauthClient.environment}`],
});
return userDetails;
}

async getTokens(redirectUrl) {
const urlParams = new URLSearchParams(redirectUrl);
this.realmId = get(urlParams, 'realmId');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"categories": [
"Accounting"
],
"description": "QuickBooks Online is the regular"
"description": "QuickBooks is an accounting software package created by Intuit, which offers solutions for managing personal, business, and tax finances."
}
51 changes: 51 additions & 0 deletions packages/v1-ready/qbo/definition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require('dotenv').config();
const {Api} = require('./api');
const {get} = require("@friggframework/core");
const config = require('./defaultConfig.json')

const Definition = {
API: Api,
getName: function () {
return config.name
},
moduleName: config.name,
modelName: 'qbo',
requiredAuthMethods: {
getToken: async function (api, params) {
const code = get(params.data, 'code');
return api.getTokenFromCode(code);
},
getEntityDetails: async function (api, callbackParams, tokenResponse, userId) {
const userDetails = await api.getUserDetails();
return {
identifiers: {externalId: userDetails.portalId, user: userId},
details: {name: userDetails.hub_domain},
}
},
apiPropertiesToPersist: {
credential: [
'access_token', 'refresh_token'
],
entity: [],
},
getCredentialDetails: async function (api, userId) {
const userDetails = await api.getUserDetails();

return {
identifiers: {externalId: userDetails.sub, user: userId},
details: {}
};
},
testAuthRequest: async function (api) {
return api.getUserDetails()
},
},
env: {
client_id: process.env.QBO_CLIENT_ID,
client_secret: process.env.QBO_CLIENT_SECRET,
scope: process.env.QBO_SCOPE,
redirect_uri: `${process.env.REDIRECT_URI}/qbo`,
}
};

module.exports = {Definition};
Loading
Loading