@things-factory/integration-accounting 8.0.0-beta.1 → 8.0.0-beta.4
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/package.json +13 -13
- package/server/controllers/accounting-api/decorators.ts +0 -47
- package/server/controllers/accounting-api/index.ts +0 -72
- package/server/controllers/index.ts +0 -3
- package/server/controllers/xero/apis/contact/get-contact.ts +0 -38
- package/server/controllers/xero/apis/contact/get-contacts.ts +0 -16
- package/server/controllers/xero/apis/contact/index.ts +0 -2
- package/server/controllers/xero/apis/index.ts +0 -4
- package/server/controllers/xero/apis/invoice/create-invoice.ts +0 -12
- package/server/controllers/xero/apis/invoice/get-invoice.ts +0 -14
- package/server/controllers/xero/apis/invoice/get-invoices.ts +0 -76
- package/server/controllers/xero/apis/invoice/index.ts +0 -4
- package/server/controllers/xero/apis/invoice/update-invoice.ts +0 -12
- package/server/controllers/xero/apis/item/create-item.ts +0 -37
- package/server/controllers/xero/apis/item/delete-item.ts +0 -19
- package/server/controllers/xero/apis/item/get-item.ts +0 -41
- package/server/controllers/xero/apis/item/get-items.ts +0 -41
- package/server/controllers/xero/apis/item/index.ts +0 -6
- package/server/controllers/xero/apis/item/update-item.ts +0 -35
- package/server/controllers/xero/apis/item/update-items.ts +0 -43
- package/server/controllers/xero/apis/purchase-order/get-purchase-orders.ts +0 -61
- package/server/controllers/xero/apis/purchase-order/index.ts +0 -1
- package/server/controllers/xero/index.ts +0 -8
- package/server/controllers/xero/platform-action.ts +0 -53
- package/server/controllers/xero/xero.ts +0 -215
- package/server/engine/connector/accounting-connector.ts +0 -33
- package/server/engine/connector/index.ts +0 -1
- package/server/engine/index.ts +0 -2
- package/server/engine/task/accounting-api.ts +0 -64
- package/server/engine/task/index.ts +0 -1
- package/server/entities/account.ts +0 -86
- package/server/entities/index.ts +0 -5
- package/server/graphql/index.ts +0 -7
- package/server/graphql/resolvers/accounting/account.ts +0 -14
- package/server/graphql/resolvers/accounting/accounts.ts +0 -15
- package/server/graphql/resolvers/accounting/create-account.ts +0 -18
- package/server/graphql/resolvers/accounting/delete-account.ts +0 -20
- package/server/graphql/resolvers/accounting/delete-accounts.ts +0 -25
- package/server/graphql/resolvers/accounting/index.ts +0 -25
- package/server/graphql/resolvers/accounting/update-account.ts +0 -18
- package/server/graphql/resolvers/accounting/update-multiple-accounts.ts +0 -44
- package/server/graphql/resolvers/accounting/xero/deactivate-xero-account.ts +0 -57
- package/server/graphql/resolvers/accounting/xero/get-xero-auth-url.ts +0 -32
- package/server/graphql/resolvers/accounting/xero/index.ts +0 -13
- package/server/graphql/resolvers/accounting/xero/refresh-xero-access-token.ts +0 -67
- package/server/graphql/resolvers/accounting-api/accounting-invoice.ts +0 -36
- package/server/graphql/resolvers/accounting-api/accounting-item.ts +0 -42
- package/server/graphql/resolvers/accounting-api/accounting-purchase-order.ts +0 -14
- package/server/graphql/resolvers/accounting-api/index.ts +0 -14
- package/server/graphql/resolvers/index.ts +0 -5
- package/server/graphql/types/accounting/account-list.ts +0 -8
- package/server/graphql/types/accounting/account-patch.ts +0 -14
- package/server/graphql/types/accounting/account.ts +0 -25
- package/server/graphql/types/accounting/index.ts +0 -44
- package/server/graphql/types/accounting/new-account.ts +0 -12
- package/server/graphql/types/accounting-api/invoice.ts +0 -65
- package/server/graphql/types/accounting-api/item.ts +0 -64
- package/server/graphql/types/accounting-api/purchase-order.ts +0 -30
- package/server/graphql/types/index.ts +0 -10
- package/server/index.ts +0 -9
- package/server/migrations/index.ts +0 -9
- package/server/routers/xero-private-router.ts +0 -24
- package/server/routers/xero-router.ts +0 -154
- package/server/routes.ts +0 -10
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import Router from 'koa-router'
|
|
2
|
-
import fetch from 'node-fetch'
|
|
3
|
-
|
|
4
|
-
import { User, VerificationToken, VerificationTokenType } from '@things-factory/auth-base'
|
|
5
|
-
import { config } from '@things-factory/env'
|
|
6
|
-
import { getRepository, getUrlFromContext } from '@things-factory/shell'
|
|
7
|
-
import { parseJwt } from '@things-factory/utils'
|
|
8
|
-
|
|
9
|
-
import { ACCOUNTING_STATUS, AccountingAPI } from '../controllers/accounting-api'
|
|
10
|
-
import { Account } from '../entities'
|
|
11
|
-
|
|
12
|
-
const { apiKey, apiSecret, hostname, callback: redirect_uri } = config.get('accountingIntegrationXero', {})
|
|
13
|
-
|
|
14
|
-
const debug = require('debug')('things-factory:integration-accounting:xero-router')
|
|
15
|
-
|
|
16
|
-
export const xeroRouter = new Router()
|
|
17
|
-
|
|
18
|
-
xeroRouter.get('/callback-xero', async (context, next) => {
|
|
19
|
-
try {
|
|
20
|
-
const { code, state: nonce } = context.query
|
|
21
|
-
|
|
22
|
-
const verificationTokenRepository = getRepository(VerificationToken)
|
|
23
|
-
|
|
24
|
-
var verification: VerificationToken = await verificationTokenRepository.findOne({
|
|
25
|
-
where: {
|
|
26
|
-
token: nonce,
|
|
27
|
-
type: VerificationTokenType.REQUEST_ACCESS_TOKEN
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
const { userId, suppliment: accountId } = verification
|
|
32
|
-
|
|
33
|
-
await verificationTokenRepository.delete({
|
|
34
|
-
userId,
|
|
35
|
-
token: nonce,
|
|
36
|
-
type: VerificationTokenType.REQUEST_ACCESS_TOKEN
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
var account = await AccountingAPI.getAccounting(accountId)
|
|
40
|
-
const connectRequestData = {
|
|
41
|
-
grant_type: 'authorization_code',
|
|
42
|
-
code,
|
|
43
|
-
redirect_uri
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const connectResponse = await fetch(`https://identity.xero.com/connect/token`, {
|
|
47
|
-
method: 'post',
|
|
48
|
-
headers: {
|
|
49
|
-
Authorization: `Basic ${Buffer.from(apiKey + ':' + apiSecret).toString('base64')}`,
|
|
50
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
|
51
|
-
},
|
|
52
|
-
body: Object.entries(connectRequestData)
|
|
53
|
-
.map(([key, value]) => encodeURIComponent(key) + '=' + encodeURIComponent(value))
|
|
54
|
-
.join('&')
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
if (!connectResponse.ok) {
|
|
58
|
-
throw new Error(`get account information failed: ${await connectResponse.text()}`)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const body = await connectResponse.json()
|
|
62
|
-
const {
|
|
63
|
-
access_token /* token used to call the API */,
|
|
64
|
-
id_token /* token containing user identity details (only returned if OpenID Connect scopes are requested) */,
|
|
65
|
-
expires_in /* amount of seconds until the access token expires */,
|
|
66
|
-
token_type: tokenType /* must be Bearer */,
|
|
67
|
-
refresh_token
|
|
68
|
-
/* token used to refresh the access token once it has expired (only returned if the offline_access scope is requested).
|
|
69
|
-
*/
|
|
70
|
-
} = body
|
|
71
|
-
|
|
72
|
-
/* decode access_token to get auth-event-id */
|
|
73
|
-
const accessInfo = parseJwt(access_token)
|
|
74
|
-
const { authentication_event_id, exp } = accessInfo
|
|
75
|
-
|
|
76
|
-
/* get connections through the authentication_event_id */
|
|
77
|
-
const connectionsResponse = await fetch(`https://api.xero.com/connections?authEventId=${authentication_event_id}`, {
|
|
78
|
-
method: 'get',
|
|
79
|
-
headers: {
|
|
80
|
-
Authorization: `Bearer ${access_token}`,
|
|
81
|
-
'Content-Type': 'application/json'
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
if (!connectionsResponse.ok) {
|
|
86
|
-
context.throw(connectionsResponse.status, `get connection list failed: ${await connectionsResponse.text()}`)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const connections = await connectionsResponse.json()
|
|
90
|
-
debug('connections', connections)
|
|
91
|
-
|
|
92
|
-
var connection = connections[0]
|
|
93
|
-
if (!connection) {
|
|
94
|
-
context.throw(400, 'connection not found for this access token')
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
var patch = {
|
|
98
|
-
name: connection.tenantName,
|
|
99
|
-
accessToken: access_token,
|
|
100
|
-
refreshToken: refresh_token,
|
|
101
|
-
accessInfo: JSON.stringify(accessInfo, null, 2),
|
|
102
|
-
accountInfo: JSON.stringify(connection, null, 2),
|
|
103
|
-
accountId: connection.tenantId,
|
|
104
|
-
status: ACCOUNTING_STATUS.ACTIVE,
|
|
105
|
-
tokenType,
|
|
106
|
-
expiresIn: new Date(exp * 1000)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
var user = await getRepository(User).findOneBy({ id: userId })
|
|
110
|
-
|
|
111
|
-
account = await getRepository(Account).save({
|
|
112
|
-
...account,
|
|
113
|
-
...patch,
|
|
114
|
-
updater: user
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
context.cookies.set(
|
|
118
|
-
'xero-accounting',
|
|
119
|
-
JSON.stringify({
|
|
120
|
-
...account,
|
|
121
|
-
message: 'success to activate'
|
|
122
|
-
}),
|
|
123
|
-
{
|
|
124
|
-
httpOnly: true
|
|
125
|
-
}
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
context.redirect(getUrlFromContext(context, '/callback-private-xero'))
|
|
129
|
-
} catch (err) {
|
|
130
|
-
var message: string = err.message
|
|
131
|
-
|
|
132
|
-
if (account) {
|
|
133
|
-
context.cookies.set(
|
|
134
|
-
'xero-accounting',
|
|
135
|
-
JSON.stringify({
|
|
136
|
-
...account,
|
|
137
|
-
message
|
|
138
|
-
}),
|
|
139
|
-
{
|
|
140
|
-
httpOnly: true
|
|
141
|
-
}
|
|
142
|
-
)
|
|
143
|
-
|
|
144
|
-
context.redirect(getUrlFromContext(context, '/callback-private-xero'))
|
|
145
|
-
return
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
throw err
|
|
149
|
-
}
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
xeroRouter.post('/webhook-xero', async (context, next) => {
|
|
153
|
-
context.status = 200
|
|
154
|
-
})
|
package/server/routes.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { xeroPrivateRouter } from './routers/xero-private-router'
|
|
2
|
-
import { xeroRouter } from './routers/xero-router'
|
|
3
|
-
|
|
4
|
-
process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {
|
|
5
|
-
globalPublicRouter.use(xeroRouter.routes(), xeroRouter.allowedMethods())
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
process.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {
|
|
9
|
-
domainPrivateRouter.use(xeroPrivateRouter.routes(), xeroPrivateRouter.allowedMethods())
|
|
10
|
-
})
|