@tomei/finance 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/configs/config.js +6 -10
- package/dist/account/account.d.ts +2 -4
- package/dist/account/account.js +3 -56
- package/dist/account/account.js.map +1 -1
- package/dist/enum/intuit-client.enum.d.ts +13 -0
- package/dist/enum/intuit-client.enum.js +19 -0
- package/dist/enum/intuit-client.enum.js.map +1 -0
- package/dist/intuit-client/client.d.ts +14 -0
- package/dist/intuit-client/client.js +44 -0
- package/dist/intuit-client/client.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -3
- package/src/account/account.ts +9 -86
- package/src/enum/intuit-client.enum.ts +14 -0
- package/src/intuit-client/client.ts +52 -0
package/configs/config.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
require('dotenv').config();
|
|
2
|
-
|
|
3
1
|
const config = {
|
|
4
2
|
development: {
|
|
5
|
-
env: 'development',
|
|
6
3
|
accountingSystem: {
|
|
7
4
|
quickbooks: {
|
|
8
5
|
packageName: process.env.PACKAGE_NAME,
|
|
@@ -19,21 +16,20 @@ const config = {
|
|
|
19
16
|
EZC: {
|
|
20
17
|
accountingSystem: 'quickbooks',
|
|
21
18
|
companyName: process.env.COMPANY_NAME,
|
|
22
|
-
API_Key: process.env.
|
|
23
|
-
API_Secret: process.env.
|
|
24
|
-
redirectUrl: process.env.
|
|
19
|
+
API_Key: process.env.QUICKBOOK_API_KEY,
|
|
20
|
+
API_Secret: process.env.QUICKBOOK_API_SECRET,
|
|
21
|
+
redirectUrl: process.env.EZCASH_REDIRECT_URL,
|
|
25
22
|
},
|
|
26
23
|
EZG: {
|
|
27
24
|
accountingSystem: 'xero',
|
|
28
25
|
companyName: process.env.COMPANY_NAME,
|
|
29
|
-
API_Key: process.env.
|
|
30
|
-
API_Secret: process.env.
|
|
31
|
-
redirectUrl: process.env.
|
|
26
|
+
API_Key: process.env.QUICKBOOK_API_KEY,
|
|
27
|
+
API_Secret: process.env.QUICKBOOK_API_SECRET,
|
|
28
|
+
redirectUrl: process.env.EZGOLD_REDIRECT_URL,
|
|
32
29
|
},
|
|
33
30
|
},
|
|
34
31
|
},
|
|
35
32
|
test: {
|
|
36
|
-
env: 'development',
|
|
37
33
|
accountingSystem: {
|
|
38
34
|
quickbooks: {
|
|
39
35
|
packageName: '',
|
|
@@ -2,6 +2,7 @@ import { ObjectBase } from 'src/base/object.base.abstract';
|
|
|
2
2
|
import { PersonBase } from 'src/base/person.base.abstract';
|
|
3
3
|
import { IAccountOptions, ICreateAccountAttr } from './interfaces/account-attr.interface';
|
|
4
4
|
import { IAccountRepository } from './interfaces/account.repository.interface';
|
|
5
|
+
import * as OAuthClient from 'intuit-oauth';
|
|
5
6
|
export declare class Account {
|
|
6
7
|
accountRepository: IAccountRepository;
|
|
7
8
|
intuitClient: any;
|
|
@@ -18,8 +19,5 @@ export declare class Account {
|
|
|
18
19
|
refreshToken: string;
|
|
19
20
|
constructor(accountRepository: IAccountRepository, SysCode: string, options?: IAccountOptions);
|
|
20
21
|
init(params: ICreateAccountAttr): void;
|
|
21
|
-
|
|
22
|
-
connect(): Promise<any>;
|
|
23
|
-
oAuthCallback(url: string): Promise<void>;
|
|
24
|
-
createAccount(): Promise<import(".").AccountModel>;
|
|
22
|
+
create(client: OAuthClient, dbOptions: any): Promise<import(".").AccountModel>;
|
|
25
23
|
}
|
package/dist/account/account.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Account = void 0;
|
|
4
|
-
const OAuthClient = require("intuit-oauth");
|
|
5
|
-
const axios_1 = require("axios");
|
|
6
4
|
class Account {
|
|
7
5
|
constructor(accountRepository, SysCode, options) {
|
|
8
6
|
this.accountRepository = accountRepository;
|
|
@@ -15,18 +13,11 @@ class Account {
|
|
|
15
13
|
this.parentAccount = options.account;
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
|
-
this.intuitClient = new OAuthClient({
|
|
19
|
-
clientId: process.env.API_KEY,
|
|
20
|
-
clientSecret: process.env.API_SECRET,
|
|
21
|
-
environment: 'sandbox',
|
|
22
|
-
redirectUri: process.env.REDIRECT_URL,
|
|
23
|
-
});
|
|
24
16
|
}
|
|
25
17
|
init(params) {
|
|
26
18
|
this.Owner = params.Owner;
|
|
27
19
|
this.RelatedObject = params.RelatedObject;
|
|
28
20
|
const ownerData = this.Owner.getDetails();
|
|
29
|
-
console.log(ownerData, '<<<<<<<<OWNER_DATA');
|
|
30
21
|
if (!ownerData) {
|
|
31
22
|
throw new Error('Please save owner information in the database before creating an account');
|
|
32
23
|
}
|
|
@@ -48,51 +39,7 @@ class Account {
|
|
|
48
39
|
this.RelatedObjectType = 'RelatedObject';
|
|
49
40
|
this.isParamsInitialized = true;
|
|
50
41
|
}
|
|
51
|
-
async
|
|
52
|
-
try {
|
|
53
|
-
const authUrl = this.intuitClient.authorizeUri({
|
|
54
|
-
scope: [OAuthClient.scopes.Accounting, OAuthClient.scopes.OpenId],
|
|
55
|
-
state: 'testState',
|
|
56
|
-
});
|
|
57
|
-
console.log(authUrl, '<<<<<<<<AUTH_URL');
|
|
58
|
-
return authUrl;
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
async connect() {
|
|
66
|
-
try {
|
|
67
|
-
const authUrl = this.intuitClient.authorizeUri({
|
|
68
|
-
scope: [OAuthClient.scopes.Accounting, OAuthClient.scopes.OpenId],
|
|
69
|
-
state: 'testState',
|
|
70
|
-
});
|
|
71
|
-
console.log(authUrl, '<<<<<<<<AUTH_URL');
|
|
72
|
-
return authUrl;
|
|
73
|
-
const response = await axios_1.default.request({
|
|
74
|
-
url: authUrl,
|
|
75
|
-
method: 'GET',
|
|
76
|
-
});
|
|
77
|
-
console.log(response, '<<<<<<<<<<<<<<< FIRST RESPONSE');
|
|
78
|
-
const AuthResponse = await this.intuitClient.createToken(response.config.url);
|
|
79
|
-
console.log(AuthResponse, '<<<<<<<<<<<<<<< SECOND RESPONSE');
|
|
80
|
-
this.accessToken = AuthResponse.getJson().access_token;
|
|
81
|
-
this.refreshToken = AuthResponse.getJson().refresh_token;
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
async oAuthCallback(url) {
|
|
89
|
-
const AuthResponse = await this.intuitClient.createToken(url);
|
|
90
|
-
console.log(AuthResponse, '<<<<<<<<<<<<<<< SECOND RESPONSE');
|
|
91
|
-
this.accessToken = AuthResponse.getJson().access_token;
|
|
92
|
-
this.refreshToken = AuthResponse.getJson().refresh_token;
|
|
93
|
-
}
|
|
94
|
-
async createAccount() {
|
|
95
|
-
await this.connect();
|
|
42
|
+
async create(client, dbOptions) {
|
|
96
43
|
if (!this.Owner || !this.RelatedObject) {
|
|
97
44
|
throw new Error('Owner must be set before creating an account." or "RelatedObject must be set before creating an account.');
|
|
98
45
|
}
|
|
@@ -102,8 +49,8 @@ class Account {
|
|
|
102
49
|
const account = await this.accountRepository.create({
|
|
103
50
|
Owner: this.Owner,
|
|
104
51
|
RelatedObject: this.RelatedObject,
|
|
105
|
-
Client:
|
|
106
|
-
});
|
|
52
|
+
Client: client,
|
|
53
|
+
}, dbOptions);
|
|
107
54
|
return account;
|
|
108
55
|
}
|
|
109
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/account/account.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/account/account.ts"],"names":[],"mappings":";;;AAQA,MAAa,OAAO;IAkBlB,YACE,iBAAqC,EACrC,OAAe,EACf,OAAyB;QAEzB,IAAI,CAAC,iBAAiB,GAAG,iB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QAC9C,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACtC,MAAM,IAAI,KAAK,CACb,0GAA0G,CAC3G,CAAC;SACH;QAED,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE;YAC7B,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;SACH;QAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,CACjD;YACE,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,MAAM,EAAE,MAAM;SACf,EACD,SAAS,CACV,CAAC;QAEF,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AA9FD,0BA8FC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientScopes = void 0;
|
|
4
|
+
const OAuthClient = require("intuit-oauth");
|
|
5
|
+
var ClientScopes;
|
|
6
|
+
(function (ClientScopes) {
|
|
7
|
+
ClientScopes[ClientScopes["ACCOUNTING"] = OAuthClient.scopes.Accounting] = "ACCOUNTING";
|
|
8
|
+
ClientScopes[ClientScopes["PAYMENT"] = OAuthClient.scopes.Payment] = "PAYMENT";
|
|
9
|
+
ClientScopes[ClientScopes["PAYROLL"] = OAuthClient.scopes.Payroll] = "PAYROLL";
|
|
10
|
+
ClientScopes[ClientScopes["TIMETRACKING"] = OAuthClient.scopes.TimeTracking] = "TIMETRACKING";
|
|
11
|
+
ClientScopes[ClientScopes["BENEFITS"] = OAuthClient.scopes.Benefits] = "BENEFITS";
|
|
12
|
+
ClientScopes[ClientScopes["PROFILE"] = OAuthClient.scopes.Profile] = "PROFILE";
|
|
13
|
+
ClientScopes[ClientScopes["EMAIL"] = OAuthClient.scopes.Email] = "EMAIL";
|
|
14
|
+
ClientScopes[ClientScopes["PHONE"] = OAuthClient.scopes.Phone] = "PHONE";
|
|
15
|
+
ClientScopes[ClientScopes["ADDRESS"] = OAuthClient.scopes.Address] = "ADDRESS";
|
|
16
|
+
ClientScopes[ClientScopes["OPENID"] = OAuthClient.scopes.OpenId] = "OPENID";
|
|
17
|
+
ClientScopes[ClientScopes["INTUIT_NAME"] = OAuthClient.scopes.Intuit_name] = "INTUIT_NAME";
|
|
18
|
+
})(ClientScopes = exports.ClientScopes || (exports.ClientScopes = {}));
|
|
19
|
+
//# sourceMappingURL=intuit-client.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intuit-client.enum.js","sourceRoot":"","sources":["../../src/enum/intuit-client.enum.ts"],"names":[],"mappings":";;;AAAA,4CAA4C;AAC5C,IAAY,YAYX;AAZD,WAAY,YAAY;IACtB,0CAAa,WAAW,CAAC,MAAM,CAAC,UAAU,gBAAA,CAAA;IAC1C,uCAAU,WAAW,CAAC,MAAM,CAAC,OAAO,aAAA,CAAA;IACpC,uCAAU,WAAW,CAAC,MAAM,CAAC,OAAO,aAAA,CAAA;IACpC,4CAAe,WAAW,CAAC,MAAM,CAAC,YAAY,kBAAA,CAAA;IAC9C,wCAAW,WAAW,CAAC,MAAM,CAAC,QAAQ,cAAA,CAAA;IACtC,uCAAU,WAAW,CAAC,MAAM,CAAC,OAAO,aAAA,CAAA;IACpC,qCAAQ,WAAW,CAAC,MAAM,CAAC,KAAK,WAAA,CAAA;IAChC,qCAAQ,WAAW,CAAC,MAAM,CAAC,KAAK,WAAA,CAAA;IAChC,uCAAU,WAAW,CAAC,MAAM,CAAC,OAAO,aAAA,CAAA;IACpC,sCAAS,WAAW,CAAC,MAAM,CAAC,MAAM,YAAA,CAAA;IAClC,2CAAc,WAAW,CAAC,MAAM,CAAC,WAAW,iBAAA,CAAA;AAC9C,CAAC,EAZW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAYvB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as OAuthClient from 'intuit-oauth';
|
|
2
|
+
import { ClientScopes } from 'src/enum/intuit-client.enum';
|
|
3
|
+
export declare class IntuitClient {
|
|
4
|
+
private client;
|
|
5
|
+
accessToken: string;
|
|
6
|
+
refreshToken: string;
|
|
7
|
+
constructor();
|
|
8
|
+
connect(scopes: ClientScopes[]): Promise<any>;
|
|
9
|
+
authCallback(url: string): Promise<void>;
|
|
10
|
+
isTokenValid(): any;
|
|
11
|
+
refreshAccessToken(): Promise<void>;
|
|
12
|
+
logout(): Promise<void>;
|
|
13
|
+
getClient(): OAuthClient;
|
|
14
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IntuitClient = void 0;
|
|
4
|
+
const OAuthClient = require("intuit-oauth");
|
|
5
|
+
class IntuitClient {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.client = new OAuthClient({
|
|
8
|
+
clientId: process.env.QUICKBOOK_API_KEY,
|
|
9
|
+
clientSecret: process.env.QUICKBOOK_API_SECRET,
|
|
10
|
+
environment: process.env.NODE_ENV === 'production' ? 'production' : 'sandbox',
|
|
11
|
+
redirectUri: process.env.INTUIT_REDIRECT_URL,
|
|
12
|
+
logging: process.env.NODE_ENV === 'production' ? false : true,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
connect(scopes) {
|
|
16
|
+
try {
|
|
17
|
+
const authUrl = this.client.authorizeUri({
|
|
18
|
+
scope: scopes,
|
|
19
|
+
state: 'testState',
|
|
20
|
+
});
|
|
21
|
+
return authUrl;
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async authCallback(url) {
|
|
28
|
+
await this.client.createToken(url);
|
|
29
|
+
}
|
|
30
|
+
isTokenValid() {
|
|
31
|
+
return this.client.isAccessTokenValid();
|
|
32
|
+
}
|
|
33
|
+
async refreshAccessToken() {
|
|
34
|
+
await this.client.refresh();
|
|
35
|
+
}
|
|
36
|
+
async logout() {
|
|
37
|
+
await this.client.revokeToken();
|
|
38
|
+
}
|
|
39
|
+
async getClient() {
|
|
40
|
+
return this.client;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.IntuitClient = IntuitClient;
|
|
44
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/intuit-client/client.ts"],"names":[],"mappings":";;;AAAA,4CAA4C;AAG5C,MAAa,YAAY;IAKvB;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,WAAW,CAAC;YAC5B,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB;YACvC,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB;YAC9C,WAAW,EACT,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS;YAClE,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB;YAC5C,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;SAC9D,CAAC,CAAC;IACL,CAAC;IAED,OAAO,CAAC,MAAsB;QAC5B,IAAI;YACF,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;gBACvC,KAAK,EAAE,MAAM;gBACb,KAAK,EAAE,WAAW;aACnB,CAAC,CAAC;YAEH,OAAO,OAAO,CAAC;SAChB;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,KAAK,CAAC;SACb;IACH,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,GAAW;QAC5B,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,MAAM,CAAC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