@tomei/finance 0.0.10 → 0.0.12
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 -55
- 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/enum/quick-book-client-scopes.enum.d.ts +13 -0
- package/dist/enum/quick-book-client-scopes.enum.js +19 -0
- package/dist/enum/quick-book-client-scopes.enum.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- 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/quickbook-client/client.d.ts +17 -0
- package/dist/quickbook-client/client.js +67 -0
- package/dist/quickbook-client/client.js.map +1 -0
- package/dist/quickbook-client/constant.d.ts +1 -0
- package/dist/quickbook-client/constant.js +5 -0
- package/dist/quickbook-client/constant.js.map +1 -0
- package/dist/quickbook-client/index.d.ts +4 -0
- package/dist/quickbook-client/index.js +8 -0
- package/dist/quickbook-client/index.js.map +1 -0
- package/dist/quickbook-client/interfaces/quickbook-client-options.interface.d.ts +8 -0
- package/dist/quickbook-client/interfaces/quickbook-client-options.interface.js +3 -0
- package/dist/quickbook-client/interfaces/quickbook-client-options.interface.js.map +1 -0
- package/dist/quickbook-client/quickbook-client.module-definition.d.ts +2 -0
- package/dist/quickbook-client/quickbook-client.module-definition.js +9 -0
- package/dist/quickbook-client/quickbook-client.module-definition.js.map +1 -0
- package/dist/quickbook-client/quickbook-client.module.d.ts +6 -0
- package/dist/quickbook-client/quickbook-client.module.js +34 -0
- package/dist/quickbook-client/quickbook-client.module.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -3
- package/src/account/account.ts +9 -85
- package/src/enum/quick-book-client-scopes.enum.ts +14 -0
- package/src/index.ts +1 -3
- package/src/quickbook-client/client.ts +74 -0
- package/src/quickbook-client/constant.ts +1 -0
- package/src/quickbook-client/index.ts +9 -0
- package/src/quickbook-client/interfaces/quickbook-client-options.interface.ts +8 -0
- package/src/quickbook-client/quickbook-client.module-definition.ts +7 -0
- package/src/quickbook-client/quickbook-client.module.ts +24 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomei/finance",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "NestJS package for finance module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -39,8 +39,7 @@
|
|
|
39
39
|
"cuid": "^2.1.8",
|
|
40
40
|
"dotenv": "^16.0.3",
|
|
41
41
|
"intuit-oauth": "^4.0.0",
|
|
42
|
-
"sequelize-typescript": "^2.1.3"
|
|
43
|
-
"axios": "^1.1.3"
|
|
42
|
+
"sequelize-typescript": "^2.1.3"
|
|
44
43
|
},
|
|
45
44
|
"dependencies": {
|
|
46
45
|
},
|
package/src/account/account.ts
CHANGED
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
} from './interfaces/account-attr.interface';
|
|
7
7
|
import { IAccountRepository } from './interfaces/account.repository.interface';
|
|
8
8
|
import * as OAuthClient from 'intuit-oauth';
|
|
9
|
-
import axios from 'axios';
|
|
10
9
|
export class Account {
|
|
11
10
|
accountRepository: IAccountRepository;
|
|
12
11
|
intuitClient: any;
|
|
@@ -41,13 +40,6 @@ export class Account {
|
|
|
41
40
|
this.parentAccount = options.account;
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
|
-
|
|
45
|
-
this.intuitClient = new OAuthClient({
|
|
46
|
-
clientId: process.env.API_KEY,
|
|
47
|
-
clientSecret: process.env.API_SECRET,
|
|
48
|
-
environment: 'sandbox',
|
|
49
|
-
redirectUri: process.env.REDIRECT_URL,
|
|
50
|
-
});
|
|
51
43
|
}
|
|
52
44
|
|
|
53
45
|
init(params: ICreateAccountAttr) {
|
|
@@ -55,7 +47,6 @@ export class Account {
|
|
|
55
47
|
this.RelatedObject = params.RelatedObject;
|
|
56
48
|
|
|
57
49
|
const ownerData = this.Owner.getDetails();
|
|
58
|
-
console.log(ownerData, '<<<<<<<<OWNER_DATA');
|
|
59
50
|
if (!ownerData) {
|
|
60
51
|
throw new Error(
|
|
61
52
|
'Please save owner information in the database before creating an account',
|
|
@@ -85,77 +76,7 @@ export class Account {
|
|
|
85
76
|
this.isParamsInitialized = true;
|
|
86
77
|
}
|
|
87
78
|
|
|
88
|
-
async
|
|
89
|
-
try {
|
|
90
|
-
const authUrl = this.intuitClient.authorizeUri({
|
|
91
|
-
scope: [OAuthClient.scopes.Accounting, OAuthClient.scopes.OpenId],
|
|
92
|
-
state: 'testState',
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
console.log(authUrl, '<<<<<<<<AUTH_URL');
|
|
96
|
-
return authUrl;
|
|
97
|
-
|
|
98
|
-
// const response = await axios.request({
|
|
99
|
-
// url: authUrl,
|
|
100
|
-
// method: 'GET',
|
|
101
|
-
// });
|
|
102
|
-
|
|
103
|
-
// console.log(response, '<<<<<<<<<<<<<<< FIRST RESPONSE');
|
|
104
|
-
|
|
105
|
-
// const AuthResponse = await this.intuitClient.createToken(
|
|
106
|
-
// response.config.url,
|
|
107
|
-
// );
|
|
108
|
-
|
|
109
|
-
// console.log(AuthResponse, '<<<<<<<<<<<<<<< SECOND RESPONSE');
|
|
110
|
-
// this.accessToken = AuthResponse.getJson().access_token;
|
|
111
|
-
// this.refreshToken = AuthResponse.getJson().refresh_token;
|
|
112
|
-
|
|
113
|
-
return true;
|
|
114
|
-
} catch (error) {
|
|
115
|
-
throw error;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async connect(): Promise<any> {
|
|
120
|
-
try {
|
|
121
|
-
const authUrl = this.intuitClient.authorizeUri({
|
|
122
|
-
scope: [OAuthClient.scopes.Accounting, OAuthClient.scopes.OpenId],
|
|
123
|
-
state: 'testState',
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
console.log(authUrl, '<<<<<<<<AUTH_URL');
|
|
127
|
-
|
|
128
|
-
const response = await axios.request({
|
|
129
|
-
url: authUrl,
|
|
130
|
-
method: 'GET',
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
console.log(response, '<<<<<<<<<<<<<<< FIRST RESPONSE');
|
|
134
|
-
|
|
135
|
-
const AuthResponse = await this.intuitClient.createToken(
|
|
136
|
-
response.config.url,
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
console.log(AuthResponse, '<<<<<<<<<<<<<<< SECOND RESPONSE');
|
|
140
|
-
this.accessToken = AuthResponse.getJson().access_token;
|
|
141
|
-
this.refreshToken = AuthResponse.getJson().refresh_token;
|
|
142
|
-
|
|
143
|
-
return true;
|
|
144
|
-
} catch (error) {
|
|
145
|
-
throw error;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
async oAuthCallback(url: string) {
|
|
150
|
-
const AuthResponse = await this.intuitClient.createToken(url);
|
|
151
|
-
|
|
152
|
-
console.log(AuthResponse, '<<<<<<<<<<<<<<< SECOND RESPONSE');
|
|
153
|
-
this.accessToken = AuthResponse.getJson().access_token;
|
|
154
|
-
this.refreshToken = AuthResponse.getJson().refresh_token;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
async createAccount() {
|
|
158
|
-
await this.connect();
|
|
79
|
+
async create(client: OAuthClient, dbOptions: any) {
|
|
159
80
|
if (!this.Owner || !this.RelatedObject) {
|
|
160
81
|
throw new Error(
|
|
161
82
|
'Owner must be set before creating an account." or "RelatedObject must be set before creating an account.',
|
|
@@ -168,11 +89,14 @@ export class Account {
|
|
|
168
89
|
);
|
|
169
90
|
}
|
|
170
91
|
|
|
171
|
-
const account = await this.accountRepository.create(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
92
|
+
const account = await this.accountRepository.create(
|
|
93
|
+
{
|
|
94
|
+
Owner: this.Owner,
|
|
95
|
+
RelatedObject: this.RelatedObject,
|
|
96
|
+
Client: client,
|
|
97
|
+
},
|
|
98
|
+
dbOptions,
|
|
99
|
+
);
|
|
176
100
|
|
|
177
101
|
return account;
|
|
178
102
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as OAuthClient from 'intuit-oauth';
|
|
2
|
+
export enum ClientScopes {
|
|
3
|
+
ACCOUNTING = OAuthClient.scopes.Accounting,
|
|
4
|
+
PAYMENT = OAuthClient.scopes.Payment,
|
|
5
|
+
PAYROLL = OAuthClient.scopes.Payroll,
|
|
6
|
+
TIMETRACKING = OAuthClient.scopes.TimeTracking,
|
|
7
|
+
BENEFITS = OAuthClient.scopes.Benefits,
|
|
8
|
+
PROFILE = OAuthClient.scopes.Profile,
|
|
9
|
+
EMAIL = OAuthClient.scopes.Email,
|
|
10
|
+
PHONE = OAuthClient.scopes.Phone,
|
|
11
|
+
ADDRESS = OAuthClient.scopes.Address,
|
|
12
|
+
OPENID = OAuthClient.scopes.OpenId,
|
|
13
|
+
INTUIT_NAME = OAuthClient.scopes.Intuit_name,
|
|
14
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as OAuthClient from 'intuit-oauth';
|
|
2
|
+
import { ClientScopes } from 'src/enum/quick-book-client-scopes.enum';
|
|
3
|
+
import { IQuickBookClientModuleOptions } from './interfaces/quickbook-client-options.interface';
|
|
4
|
+
|
|
5
|
+
export class QuickBookClient {
|
|
6
|
+
private client: OAuthClient;
|
|
7
|
+
accessToken: string;
|
|
8
|
+
refreshToken: string;
|
|
9
|
+
|
|
10
|
+
constructor(options: IQuickBookClientModuleOptions) {
|
|
11
|
+
this.client = new OAuthClient({
|
|
12
|
+
clientId: options.clientId,
|
|
13
|
+
clientSecret: options.clientSecret,
|
|
14
|
+
environment: options.environment,
|
|
15
|
+
redirectUri: options.redirectUri,
|
|
16
|
+
logging: options.logging,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
connect(scopes: ClientScopes[]): string {
|
|
21
|
+
try {
|
|
22
|
+
const authUrl = this.client.authorizeUri({
|
|
23
|
+
scope: scopes,
|
|
24
|
+
state: 'testState',
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return authUrl;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async authCallback(url: string): Promise<void> {
|
|
34
|
+
try {
|
|
35
|
+
await this.client.createToken(url);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
isTokenValid(): boolean {
|
|
42
|
+
try {
|
|
43
|
+
return this.client.isAccessTokenValid();
|
|
44
|
+
} catch (error) {
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async refreshAccessToken(): Promise<void> {
|
|
50
|
+
try {
|
|
51
|
+
await this.client.refresh();
|
|
52
|
+
} catch (error) {
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async logout(): Promise<void> {
|
|
58
|
+
await this.client.revokeToken();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async getClient(): OAuthClient {
|
|
62
|
+
return this.client;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getCompanyId(): string {
|
|
66
|
+
return this.client.getToken().realmId;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async validateAndRefreshToken(): Promise<void> {
|
|
70
|
+
if (!this.client.isAccessTokenValid()) {
|
|
71
|
+
await this.client.refresh();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const QUICKBOOK_CLIENT = 'quickbook-client';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { QuickBookClientModule } from './quickbook-client.module';
|
|
2
|
+
import { IQuickBookClientModuleOptions } from './interfaces/quickbook-client-options.interface';
|
|
3
|
+
import { QUICKBOOK_CLIENT } from './constant';
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
QuickBookClientModule,
|
|
7
|
+
IQuickBookClientModuleOptions,
|
|
8
|
+
QUICKBOOK_CLIENT,
|
|
9
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConfigurableModuleBuilder } from '@nestjs/common';
|
|
2
|
+
import { IQuickBookClientModuleOptions } from './interfaces/quickbook-client-options.interface';
|
|
3
|
+
|
|
4
|
+
export const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN } =
|
|
5
|
+
new ConfigurableModuleBuilder<IQuickBookClientModuleOptions>()
|
|
6
|
+
.setClassMethodName('forRoot')
|
|
7
|
+
.build();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DynamicModule, Module, Provider } from '@nestjs/common';
|
|
2
|
+
import { QuickBookClient } from './client';
|
|
3
|
+
import { QUICKBOOK_CLIENT } from './constant';
|
|
4
|
+
import { IQuickBookClientModuleOptions } from './interfaces/quickbook-client-options.interface';
|
|
5
|
+
import { ConfigurableModuleClass } from './quickbook-client.module-definition';
|
|
6
|
+
|
|
7
|
+
@Module({})
|
|
8
|
+
export class QuickBookClientModule extends ConfigurableModuleClass {
|
|
9
|
+
static forRoot(options: IQuickBookClientModuleOptions): DynamicModule {
|
|
10
|
+
const client = new QuickBookClient(options);
|
|
11
|
+
|
|
12
|
+
const QuickBookClientProvider: Provider = {
|
|
13
|
+
provide: QUICKBOOK_CLIENT,
|
|
14
|
+
useValue: client,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
module: QuickBookClientModule,
|
|
19
|
+
providers: [QuickBookClientProvider],
|
|
20
|
+
exports: [QuickBookClientProvider],
|
|
21
|
+
global: true,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|