@things-factory/integration-accounting 5.0.14 → 6.0.0-alpha.3

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.
Files changed (52) hide show
  1. package/dist-server/controllers/accounting-api/index.js +2 -2
  2. package/dist-server/controllers/accounting-api/index.js.map +1 -1
  3. package/dist-server/controllers/xero/xero.js +2 -2
  4. package/dist-server/controllers/xero/xero.js.map +1 -1
  5. package/dist-server/engine/task/accounting-api.js +3 -3
  6. package/dist-server/engine/task/accounting-api.js.map +1 -1
  7. package/dist-server/entities/account.js +3 -4
  8. package/dist-server/entities/account.js.map +1 -1
  9. package/dist-server/graphql/resolvers/accounting/account.js +4 -4
  10. package/dist-server/graphql/resolvers/accounting/account.js.map +1 -1
  11. package/dist-server/graphql/resolvers/accounting/accounts.js +1 -2
  12. package/dist-server/graphql/resolvers/accounting/accounts.js.map +1 -1
  13. package/dist-server/graphql/resolvers/accounting/create-account.js +4 -3
  14. package/dist-server/graphql/resolvers/accounting/create-account.js.map +1 -1
  15. package/dist-server/graphql/resolvers/accounting/delete-account.js +5 -5
  16. package/dist-server/graphql/resolvers/accounting/delete-account.js.map +1 -1
  17. package/dist-server/graphql/resolvers/accounting/delete-accounts.js +5 -4
  18. package/dist-server/graphql/resolvers/accounting/delete-accounts.js.map +1 -1
  19. package/dist-server/graphql/resolvers/accounting/update-account.js +3 -3
  20. package/dist-server/graphql/resolvers/accounting/update-account.js.map +1 -1
  21. package/dist-server/graphql/resolvers/accounting/update-multiple-accounts.js +3 -3
  22. package/dist-server/graphql/resolvers/accounting/update-multiple-accounts.js.map +1 -1
  23. package/dist-server/graphql/resolvers/accounting/xero/deactivate-xero-account.js +4 -4
  24. package/dist-server/graphql/resolvers/accounting/xero/deactivate-xero-account.js.map +1 -1
  25. package/dist-server/graphql/resolvers/accounting/xero/get-xero-auth-url.js +4 -4
  26. package/dist-server/graphql/resolvers/accounting/xero/get-xero-auth-url.js.map +1 -1
  27. package/dist-server/graphql/resolvers/accounting/xero/refresh-xero-access-token.js +5 -5
  28. package/dist-server/graphql/resolvers/accounting/xero/refresh-xero-access-token.js.map +1 -1
  29. package/dist-server/graphql/resolvers/accounting-api/accounting-invoice.js.map +1 -1
  30. package/dist-server/graphql/resolvers/accounting-api/accounting-item.js.map +1 -1
  31. package/dist-server/graphql/resolvers/accounting-api/accounting-purchase-order.js.map +1 -1
  32. package/dist-server/routers/xero-router.js +3 -4
  33. package/dist-server/routers/xero-router.js.map +1 -1
  34. package/dist-server/tsconfig.tsbuildinfo +1 -1
  35. package/package.json +16 -16
  36. package/server/controllers/accounting-api/index.ts +1 -1
  37. package/server/controllers/xero/xero.ts +1 -1
  38. package/server/engine/task/accounting-api.ts +3 -2
  39. package/server/graphql/resolvers/accounting/account.ts +4 -3
  40. package/server/graphql/resolvers/accounting/accounts.ts +2 -4
  41. package/server/graphql/resolvers/accounting/create-account.ts +9 -6
  42. package/server/graphql/resolvers/accounting/delete-account.ts +5 -4
  43. package/server/graphql/resolvers/accounting/delete-accounts.ts +7 -4
  44. package/server/graphql/resolvers/accounting/update-account.ts +4 -3
  45. package/server/graphql/resolvers/accounting/update-multiple-accounts.ts +4 -3
  46. package/server/graphql/resolvers/accounting/xero/deactivate-xero-account.ts +6 -4
  47. package/server/graphql/resolvers/accounting/xero/get-xero-auth-url.ts +6 -4
  48. package/server/graphql/resolvers/accounting/xero/refresh-xero-access-token.ts +7 -5
  49. package/server/graphql/resolvers/accounting-api/accounting-invoice.ts +9 -9
  50. package/server/graphql/resolvers/accounting-api/accounting-item.ts +11 -12
  51. package/server/graphql/resolvers/accounting-api/accounting-purchase-order.ts +1 -1
  52. package/server/routers/xero-router.ts +2 -3
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@things-factory/integration-accounting",
3
- "version": "5.0.14",
3
+ "version": "6.0.0-alpha.3",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
7
7
  "license": "MIT",
8
- "author": "heartyoh",
8
+ "author": "heartyoh <heartyoh@hatiolab.com>",
9
9
  "description": "Module to manage integration with accounting service.",
10
10
  "publishConfig": {
11
11
  "access": "public",
@@ -25,19 +25,19 @@
25
25
  "test": "DEBUG=things-factory:* NODE_ENV=development npx mocha -r ts-node/register ./test/**/*spec.ts"
26
26
  },
27
27
  "dependencies": {
28
- "@things-factory/apptool-ui": "^5.0.14",
29
- "@things-factory/auth-ui": "^5.0.14",
30
- "@things-factory/biz-base": "^5.0.14",
31
- "@things-factory/code-ui": "^5.0.14",
32
- "@things-factory/context-ui": "^5.0.14",
33
- "@things-factory/grist-ui": "^5.0.14",
34
- "@things-factory/i18n-base": "^5.0.14",
35
- "@things-factory/integration-ui": "^5.0.14",
36
- "@things-factory/more-ui": "^5.0.14",
37
- "@things-factory/product-base": "^5.0.14",
38
- "@things-factory/resource-ui": "^5.0.14",
39
- "@things-factory/setting-ui": "^5.0.14",
40
- "@things-factory/system-ui": "^5.0.14",
28
+ "@things-factory/apptool-ui": "^6.0.0-alpha.3",
29
+ "@things-factory/auth-ui": "^6.0.0-alpha.3",
30
+ "@things-factory/biz-base": "^6.0.0-alpha.3",
31
+ "@things-factory/code-ui": "^6.0.0-alpha.3",
32
+ "@things-factory/context-ui": "^6.0.0-alpha.3",
33
+ "@things-factory/grist-ui": "^6.0.0-alpha.3",
34
+ "@things-factory/i18n-base": "^6.0.0-alpha.3",
35
+ "@things-factory/integration-ui": "^6.0.0-alpha.3",
36
+ "@things-factory/more-ui": "^6.0.0-alpha.3",
37
+ "@things-factory/product-base": "^6.0.0-alpha.3",
38
+ "@things-factory/resource-ui": "^6.0.0-alpha.3",
39
+ "@things-factory/setting-ui": "^6.0.0-alpha.3",
40
+ "@things-factory/system-ui": "^6.0.0-alpha.3",
41
41
  "debug": "^4.1.1",
42
42
  "node-fetch": "^2.6.0"
43
43
  },
@@ -51,5 +51,5 @@
51
51
  "nock": "^13.0.2",
52
52
  "should": "^13.2.3"
53
53
  },
54
- "gitHead": "9ceaa39746fcf42953e429fab2001353cd821ded"
54
+ "gitHead": "1e273b6485662da938cae8fdca035d994ef4a95d"
55
55
  }
@@ -1,4 +1,4 @@
1
- import { getRepository } from 'typeorm'
1
+ import { getRepository } from '@things-factory/shell'
2
2
 
3
3
  import { Account } from '../../entities'
4
4
  import { api } from './decorators'
@@ -1,6 +1,6 @@
1
1
  import fetch from 'node-fetch'
2
- import { getRepository } from 'typeorm'
3
2
 
3
+ import { getRepository } from '@things-factory/shell'
4
4
  import { parseJwt } from '@things-factory/utils'
5
5
 
6
6
  import { Account } from '../../entities/account'
@@ -1,8 +1,9 @@
1
1
  import { ConnectionManager, TaskRegistry } from '@things-factory/integration-base'
2
+ import { getRepository } from '@things-factory/shell'
2
3
  import { access } from '@things-factory/utils'
3
- import { getRepository } from 'typeorm'
4
- import { Account } from '../../entities'
4
+
5
5
  import { AccountingAPI as API } from '../../controllers/accounting-api'
6
+ import { Account } from '../../entities'
6
7
 
7
8
  async function AccountingAPI(step, { logger, data, domain }) {
8
9
  var {
@@ -1,12 +1,13 @@
1
- import { getRepository } from 'typeorm'
1
+ import { getRepository } from '@things-factory/shell'
2
+
2
3
  import { Account } from '../../../entities'
3
4
 
4
5
  export const accountResolver = {
5
- async account(_: any, { id }, context: any) {
6
+ async account(_: any, { id }, context: ResolverContext) {
6
7
  const repository = getRepository(Account)
7
8
 
8
9
  return await getRepository(Account).findOne({
9
- where: { domain: context.state.domain, id },
10
+ where: { domain: { id: context.state.domain.id }, id },
10
11
  relations: ['domain', 'creator', 'updater']
11
12
  })
12
13
  }
@@ -1,11 +1,9 @@
1
- import { getRepository } from 'typeorm'
2
-
3
- import { convertListParams, ListParam } from '@things-factory/shell'
1
+ import { convertListParams, getRepository, ListParam } from '@things-factory/shell'
4
2
 
5
3
  import { Account } from '../../../entities'
6
4
 
7
5
  export const accountsResolver = {
8
- async accounts(_: any, params: ListParam, context: any) {
6
+ async accounts(_: any, params: ListParam, context: ResolverContext) {
9
7
  const { domain } = context.state
10
8
  const convertedParams = convertListParams(params, { domain })
11
9
  const [items, total] = await getRepository(Account).findAndCount({
@@ -1,15 +1,18 @@
1
- import { getRepository } from 'typeorm'
2
- import { Account } from '../../../entities'
1
+ import { getRepository } from '@things-factory/shell'
2
+
3
3
  import { ACCOUNTING_STATUS } from '../../../controllers'
4
+ import { Account } from '../../../entities'
4
5
 
5
6
  export const createAccount = {
6
- async createAccount(_: any, { account }, context: any) {
7
+ async createAccount(_: any, { account }, context: ResolverContext) {
8
+ const { domain, user } = context.state
9
+
7
10
  return await getRepository(Account).save({
8
11
  status: ACCOUNTING_STATUS.INACTIVE,
9
12
  ...account,
10
- domain: context.state.domain,
11
- creator: context.state.user,
12
- updater: context.state.user
13
+ domain,
14
+ creator: user,
15
+ updater: user
13
16
  })
14
17
  }
15
18
  }
@@ -1,11 +1,12 @@
1
- import { getRepository } from 'typeorm'
2
- import { Account } from '../../../entities'
1
+ import { getRepository } from '@things-factory/shell'
2
+
3
3
  import { ACCOUNTING_STATUS } from '../../../controllers'
4
+ import { Account } from '../../../entities'
4
5
 
5
6
  export const deleteAccount = {
6
- async deleteAccount(_: any, { id }, context: any) {
7
+ async deleteAccount(_: any, { id }, context: ResolverContext) {
7
8
  const foundAccount: Account = await getRepository(Account).findOne({
8
- where: { domain: context.state.domain, id }
9
+ where: { domain: { id: context.state.domain.id }, id }
9
10
  })
10
11
 
11
12
  await getRepository(Account).save({
@@ -1,11 +1,14 @@
1
- import { getRepository, In } from 'typeorm'
2
- import { Account } from '../../../entities'
1
+ import { In } from 'typeorm'
2
+
3
+ import { getRepository } from '@things-factory/shell'
4
+
3
5
  import { ACCOUNTING_STATUS } from '../../../controllers'
6
+ import { Account } from '../../../entities'
4
7
 
5
8
  export const deleteAccounts = {
6
- async deleteAccounts(_: any, { ids }, context: any) {
9
+ async deleteAccounts(_: any, { ids }, context: ResolverContext) {
7
10
  let foundAccounts: Account[] = await getRepository(Account).find({
8
- where: { domain: context.state.domain, id: In(ids) }
11
+ where: { domain: { id: context.state.domain.id }, id: In(ids) }
9
12
  })
10
13
 
11
14
  const updatedAccount = foundAccounts.map((account: Account) => {
@@ -1,11 +1,12 @@
1
- import { getRepository } from 'typeorm'
1
+ import { getRepository } from '@things-factory/shell'
2
+
2
3
  import { Account } from '../../../entities'
3
4
 
4
5
  export const updateAccount = {
5
- async updateAccount(_: any, { name, patch }, context: any) {
6
+ async updateAccount(_: any, { name, patch }, context: ResolverContext) {
6
7
  const repository = getRepository(Account)
7
8
  const account: any = await repository.findOne({
8
- where: { domain: context.state.domain, name }
9
+ where: { domain: { id: context.state.domain.id }, name }
9
10
  })
10
11
 
11
12
  return await repository.save({
@@ -1,8 +1,9 @@
1
- import { getRepository } from 'typeorm'
1
+ import { getRepository } from '@things-factory/shell'
2
+
2
3
  import { Account } from '../../../entities'
3
4
 
4
5
  export const updateMultipleAccount = {
5
- async updateMultipleAccount(_: any, { patches }, context: any) {
6
+ async updateMultipleAccount(_: any, { patches }, context: ResolverContext) {
6
7
  let results = []
7
8
  const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
8
9
  const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
@@ -26,7 +27,7 @@ export const updateMultipleAccount = {
26
27
  if (_updateRecords.length > 0) {
27
28
  for (let i = 0; i < _updateRecords.length; i++) {
28
29
  const newRecord = _updateRecords[i]
29
- const account: Account = await accountRepo.findOne(newRecord.id)
30
+ const account: Account = await accountRepo.findOneBy({ id: newRecord.id })
30
31
 
31
32
  const result = await accountRepo.save({
32
33
  ...account,
@@ -1,15 +1,17 @@
1
1
  import fetch from 'node-fetch'
2
- import { getRepository } from 'typeorm'
3
- import { Account } from '../../../../entities'
2
+
3
+ import { getRepository } from '@things-factory/shell'
4
+
4
5
  import { ACCOUNTING_STATUS } from '../../../../controllers'
6
+ import { Account } from '../../../../entities'
5
7
 
6
8
  const debug = require('debug')('things-factory:integration-accounting:deactivate-xero-account')
7
9
 
8
10
  export const deactivateXeroAccount = {
9
- async deactivateXeroAccount(_: any, { id }, context: any) {
11
+ async deactivateXeroAccount(_: any, { id }, context: ResolverContext) {
10
12
  const repository = getRepository(Account)
11
13
  const account: any = await repository.findOne({
12
- where: { domain: context.state.domain, id }
14
+ where: { domain: { id: context.state.domain.id }, id }
13
15
  })
14
16
 
15
17
  try {
@@ -1,18 +1,20 @@
1
- import { getRepository } from 'typeorm'
2
- import { config } from '@things-factory/env'
1
+ import crypto from 'crypto'
2
+
3
3
  import { VerificationToken, VerificationTokenType } from '@things-factory/auth-base'
4
+ import { config } from '@things-factory/env'
5
+ import { getRepository } from '@things-factory/shell'
6
+
4
7
  import { Xero } from '../../../../controllers/xero'
5
8
 
6
9
  const xeroConfig = config.get('accountingIntegrationXero', {})
7
10
  const { apiKey, apiSecret, callback } = xeroConfig
8
11
 
9
- import crypto from 'crypto'
10
12
  export function makeVerificationTokenForNonce() {
11
13
  return crypto.randomBytes(16).toString('hex')
12
14
  }
13
15
 
14
16
  export const getXeroAuthURL = {
15
- async getXeroAuthURL(_: any, { accounting }, context: any) {
17
+ async getXeroAuthURL(_: any, { accounting }, context: ResolverContext) {
16
18
  const { user } = context.state
17
19
  const xero = new Xero({ apiKey, apiSecret, callback })
18
20
 
@@ -1,19 +1,21 @@
1
1
  import fetch from 'node-fetch'
2
- import { getRepository } from 'typeorm'
3
- import { Account } from '../../../../entities'
4
2
 
5
- import { parseJwt } from '@things-factory/utils'
6
3
  import { config } from '@things-factory/env'
4
+ import { getRepository } from '@things-factory/shell'
5
+ import { parseJwt } from '@things-factory/utils'
6
+
7
+ import { Account } from '../../../../entities'
8
+
7
9
  const xeroConfig = config.get('accountingIntegrationXero', {})
8
10
  const { apiKey, apiSecret } = xeroConfig
9
11
 
10
12
  const debug = require('debug')('things-factory:integration-accounting:refresh-xero-access-token')
11
13
 
12
14
  export const refreshXeroAccessToken = {
13
- async refreshXeroAccessToken(_: any, { id }, context: any) {
15
+ async refreshXeroAccessToken(_: any, { id }, context: ResolverContext) {
14
16
  const repository = getRepository(Account)
15
17
  const account: any = await repository.findOne({
16
- where: { domain: context.state.domain, id }
18
+ where: { domain: { id: context.state.domain.id }, id }
17
19
  })
18
20
 
19
21
  const refreshRequestData = {
@@ -1,9 +1,9 @@
1
1
  import { AccountingAPI } from '../../../controllers/accounting-api'
2
2
 
3
3
  export const queryAccountingInvoice = {
4
- async getAccountingInvoices(_: any, { accountingId, params: ListParam }, context: any) {
4
+ async getAccountingInvoices(_: any, { accountingId, params: ListParam }, context: ResolverContext) {
5
5
  var accounting = await AccountingAPI.getAccounting(accountingId)
6
-
6
+
7
7
  return await AccountingAPI.getInvoices(accounting, {
8
8
  pagination: {
9
9
  page: 0,
@@ -12,9 +12,9 @@ export const queryAccountingInvoice = {
12
12
  })
13
13
  },
14
14
 
15
- async getAccountingInvoice(_: any, { accountingId, invoiceNo }, context: any) {
15
+ async getAccountingInvoice(_: any, { accountingId, invoiceNo }, context: ResolverContext) {
16
16
  var accounting = await AccountingAPI.getAccounting(accountingId)
17
-
17
+
18
18
  return await AccountingAPI.getInvoice(accounting, {
19
19
  invoiceNo
20
20
  })
@@ -22,15 +22,15 @@ export const queryAccountingInvoice = {
22
22
  }
23
23
 
24
24
  export const mutateAccountingInvoice = {
25
- async createAccountingInvoice(_: any, { accountingId, newInvoice }, context: any) {
25
+ async createAccountingInvoice(_: any, { accountingId, newInvoice }, context: ResolverContext) {
26
26
  var accounting = await AccountingAPI.getAccounting(accountingId)
27
-
27
+
28
28
  return await AccountingAPI.createInvoice(accounting, newInvoice)
29
29
  },
30
30
 
31
- async updateAccountingInvoice(_: any, { accountingId, patch }, context: any) {
31
+ async updateAccountingInvoice(_: any, { accountingId, patch }, context: ResolverContext) {
32
32
  var accounting = await AccountingAPI.getAccounting(accountingId)
33
-
33
+
34
34
  return await AccountingAPI.updateInvoice(accounting, patch)
35
35
  }
36
- }
36
+ }
@@ -1,10 +1,9 @@
1
- import { convertListParams, ListParam } from '@things-factory/shell'
2
1
  import { AccountingAPI } from '../../../controllers/accounting-api'
3
2
 
4
3
  export const queryAccountingItem = {
5
- async getAccountingItems(_: any, { accountingId, params: ListParam }, context: any) {
4
+ async getAccountingItems(_: any, { accountingId, params: ListParam }, context: ResolverContext) {
6
5
  var accounting = await AccountingAPI.getAccounting(accountingId)
7
-
6
+
8
7
  return await AccountingAPI.getItems(accounting, {
9
8
  pagination: {
10
9
  page: 0,
@@ -13,9 +12,9 @@ export const queryAccountingItem = {
13
12
  })
14
13
  },
15
14
 
16
- async getAccountingItem(_: any, { accountingId, itemId }, context: any) {
15
+ async getAccountingItem(_: any, { accountingId, itemId }, context: ResolverContext) {
17
16
  var accounting = await AccountingAPI.getAccounting(accountingId)
18
-
17
+
19
18
  return await AccountingAPI.getItem(accounting, {
20
19
  itemId
21
20
  })
@@ -23,21 +22,21 @@ export const queryAccountingItem = {
23
22
  }
24
23
 
25
24
  export const mutateAccountingItem = {
26
- async createAccountingItem(_: any, { accountingId, newItem }, context: any) {
25
+ async createAccountingItem(_: any, { accountingId, newItem }, context: ResolverContext) {
27
26
  var accounting = await AccountingAPI.getAccounting(accountingId)
28
-
27
+
29
28
  return await AccountingAPI.createItem(accounting, newItem)
30
29
  },
31
30
 
32
- async updateAccountingItem(_: any, { accountingId, patch }, context: any) {
31
+ async updateAccountingItem(_: any, { accountingId, patch }, context: ResolverContext) {
33
32
  var accounting = await AccountingAPI.getAccounting(accountingId)
34
-
33
+
35
34
  return await AccountingAPI.updateItem(accounting, patch)
36
35
  },
37
36
 
38
- async deleteAccountingItem(_: any, { accountingId, itemId }, context: any) {
37
+ async deleteAccountingItem(_: any, { accountingId, itemId }, context: ResolverContext) {
39
38
  var accounting = await AccountingAPI.getAccounting(accountingId)
40
-
39
+
41
40
  return await AccountingAPI.deleteItem(accounting, itemId)
42
41
  }
43
- }
42
+ }
@@ -1,7 +1,7 @@
1
1
  import { AccountingAPI } from '../../../controllers/accounting-api'
2
2
 
3
3
  export const queryAccountingPurchaseOrder = {
4
- async getAccountingPurchaseOrders(_: any, { accountingId, params: ListParam }, context: any) {
4
+ async getAccountingPurchaseOrders(_: any, { accountingId, params: ListParam }, context: ResolverContext) {
5
5
  var accounting = await AccountingAPI.getAccounting(accountingId)
6
6
 
7
7
  return await AccountingAPI.getPurchaseOrders(accounting, {
@@ -1,10 +1,9 @@
1
1
  import Router from 'koa-router'
2
2
  import fetch from 'node-fetch'
3
- import { getRepository } from 'typeorm'
4
3
 
5
4
  import { User, VerificationToken, VerificationTokenType } from '@things-factory/auth-base'
6
5
  import { config } from '@things-factory/env'
7
- import { getUrlFromContext } from '@things-factory/shell'
6
+ import { getRepository, getUrlFromContext } from '@things-factory/shell'
8
7
  import { parseJwt } from '@things-factory/utils'
9
8
 
10
9
  import { ACCOUNTING_STATUS, AccountingAPI } from '../controllers/accounting-api'
@@ -107,7 +106,7 @@ xeroRouter.get('/callback-xero', async (context, next) => {
107
106
  expiresIn: new Date(exp * 1000)
108
107
  }
109
108
 
110
- var user = await getRepository(User).findOne(userId)
109
+ var user = await getRepository(User).findOneBy({ id: userId })
111
110
 
112
111
  account = await getRepository(Account).save({
113
112
  ...account,