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

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
@@ -1 +1 @@
1
- {"version":3,"file":"accounting-item.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/accounting-api/accounting-item.ts"],"names":[],"mappings":";;;AACA,wEAAmE;AAEtD,QAAA,mBAAmB,GAAG;IACjC,KAAK,CAAC,kBAAkB,CAAC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AY,CAAC,CAAA;QAEhE,OAAO,MAAM,8BAAa,CAAC,UAAU,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;IAC3D,CAAC;CACF,CAAA","sourcesContent":["import { convertListParams, ListParam } from '@things-factory/shell'\nimport { AccountingAPI } from '../../../controllers/accounting-api'\n\nexport const queryAccountingItem = {\n async getAccountingItems(_: any, { accountingId, params: ListParam }, context: any) {\n var accounting = await AccountingAPI.getAccounting(accountingId)\n \n return await AccountingAPI.getItems(accounting, {\n pagination: {\n page: 0,\n limit: 100\n }\n })\n },\n\n async getAccountingItem(_: any, { accountingId, itemId }, context: any) {\n var accounting = await AccountingAPI.getAccounting(accountingId)\n \n return await AccountingAPI.getItem(accounting, {\n itemId\n })\n }\n}\n\nexport const mutateAccountingItem = {\n async createAccountingItem(_: any, { accountingId, newItem }, context: any) {\n var accounting = await AccountingAPI.getAccounting(accountingId)\n \n return await AccountingAPI.createItem(accounting, newItem)\n },\n\n async updateAccountingItem(_: any, { accountingId, patch }, context: any) {\n var accounting = await AccountingAPI.getAccounting(accountingId)\n \n return await AccountingAPI.updateItem(accounting, patch)\n },\n\n async deleteAccountingItem(_: any, { accountingId, itemId }, context: any) {\n var accounting = await AccountingAPI.getAccounting(accountingId)\n \n return await AccountingAPI.deleteItem(accounting, itemId)\n }\n}"]}
1
+ {"version":3,"file":"accounting-item.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/accounting-api/accounting-item.ts"],"names":[],"mappings":";;;AAAA,wEAAmE;AAEtD,QAAA,mBAAmB,GAAG;IACjC,KAAK,CAAC,kBAAkB,CAAC,CAAM,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,OAAwB;QAC5F,IAAI,UAAU,GAAG,MAAM,8BAAa,CAAC,aAAa,CAAC,YAAY,CAAC,CAAA;QAEhE,OAAO,MAAM,8BAAa,CAAC,QAAQ,CAAC,UAAU,EAAE;YAC9C,UAAU,EAAE;gBACV,IAAI,EAAE,CAAC;gBACP,KAAK,EAAE,GAAG;aACX;SACF,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,CAAM,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,OAAwB;QAChF,IAAI,UAAU,GAAG,MAAM,8BAAa,CAAC,aAAa,CAAC,YAAY,CAAC,CAAA;QAEhE,OAAO,MAAM,8BAAa,CAAC,OAAO,CAAC,UAAU,EAAE;YAC7C,MAAM;SACP,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAEY,QAAA,oBAAoB,GAAG;IAClC,KAAK,CAAC,oBAAoB,CAAC,CAAM,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,EAAE,OAAwB;QACpF,IAAI,UAAU,GAAG,MAAM,8BAAa,CAAC,aAAa,CAAC,YAAY,CAAC,CAAA;QAEhE,OAAO,MAAM,8BAAa,CAAC,UAAU,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IAC5D,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,CAAM,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,OAAwB;QAClF,IAAI,UAAU,GAAG,MAAM,8BAAa,CAAC,aAAa,CAAC,YAAY,CAAC,CAAA;QAEhE,OAAO,MAAM,8BAAa,CAAC,UAAU,CAAC,UAAU,EAAE,KAAK,CAAC,CAAA;IAC1D,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,CAAM,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,OAAwB;QACnF,IAAI,UAAU,GAAG,MAAM,8BAAa,CAAC,aAAa,CAAC,YAAY,CAAC,CAAA;QAEhE,OAAO,MAAM,8BAAa,CAAC,UAAU,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;IAC3D,CAAC;CACF,CAAA","sourcesContent":["import { AccountingAPI } from '../../../controllers/accounting-api'\n\nexport const queryAccountingItem = {\n async getAccountingItems(_: any, { accountingId, params: ListParam }, context: ResolverContext) {\n var accounting = await AccountingAPI.getAccounting(accountingId)\n\n return await AccountingAPI.getItems(accounting, {\n pagination: {\n page: 0,\n limit: 100\n }\n })\n },\n\n async getAccountingItem(_: any, { accountingId, itemId }, context: ResolverContext) {\n var accounting = await AccountingAPI.getAccounting(accountingId)\n\n return await AccountingAPI.getItem(accounting, {\n itemId\n })\n }\n}\n\nexport const mutateAccountingItem = {\n async createAccountingItem(_: any, { accountingId, newItem }, context: ResolverContext) {\n var accounting = await AccountingAPI.getAccounting(accountingId)\n\n return await AccountingAPI.createItem(accounting, newItem)\n },\n\n async updateAccountingItem(_: any, { accountingId, patch }, context: ResolverContext) {\n var accounting = await AccountingAPI.getAccounting(accountingId)\n\n return await AccountingAPI.updateItem(accounting, patch)\n },\n\n async deleteAccountingItem(_: any, { accountingId, itemId }, context: ResolverContext) {\n var accounting = await AccountingAPI.getAccounting(accountingId)\n\n return await AccountingAPI.deleteItem(accounting, itemId)\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"accounting-purchase-order.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/accounting-api/accounting-purchase-order.ts"],"names":[],"mappings":";;;AAAA,wEAAmE;AAEtD,QAAA,4BAA4B,GAAG;IAC1C,KAAK,CAAC,2BAA2B,CAAC,CAAM,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,OAAY;QACzF,IAAI,UAAU,GAAG,MAAM,8BAAa,CAAC,aAAa,CAAC,YAAY,CAAC,CAAA;QAEhE,OAAO,MAAM,8BAAa,CAAC,iBAAiB,CAAC,UAAU,EAAE;YACvD,UAAU,EAAE;gBACV,IAAI,EAAE,CAAC;gBACP,KAAK,EAAE,GAAG;aACX;SACF,CAAC,CAAA;IACJ,CAAC;CACF,CAAA","sourcesContent":["import { AccountingAPI } from '../../../controllers/accounting-api'\n\nexport const queryAccountingPurchaseOrder = {\n async getAccountingPurchaseOrders(_: any, { accountingId, params: ListParam }, context: any) {\n var accounting = await AccountingAPI.getAccounting(accountingId)\n\n return await AccountingAPI.getPurchaseOrders(accounting, {\n pagination: {\n page: 0,\n limit: 100\n }\n })\n }\n}\n"]}
1
+ {"version":3,"file":"accounting-purchase-order.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/accounting-api/accounting-purchase-order.ts"],"names":[],"mappings":";;;AAAA,wEAAmE;AAEtD,QAAA,4BAA4B,GAAG;IAC1C,KAAK,CAAC,2BAA2B,CAAC,CAAM,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,OAAwB;QACrG,IAAI,UAAU,GAAG,MAAM,8BAAa,CAAC,aAAa,CAAC,YAAY,CAAC,CAAA;QAEhE,OAAO,MAAM,8BAAa,CAAC,iBAAiB,CAAC,UAAU,EAAE;YACvD,UAAU,EAAE;gBACV,IAAI,EAAE,CAAC;gBACP,KAAK,EAAE,GAAG;aACX;SACF,CAAC,CAAA;IACJ,CAAC;CACF,CAAA","sourcesContent":["import { AccountingAPI } from '../../../controllers/accounting-api'\n\nexport const queryAccountingPurchaseOrder = {\n async getAccountingPurchaseOrders(_: any, { accountingId, params: ListParam }, context: ResolverContext) {\n var accounting = await AccountingAPI.getAccounting(accountingId)\n\n return await AccountingAPI.getPurchaseOrders(accounting, {\n pagination: {\n page: 0,\n limit: 100\n }\n })\n }\n}\n"]}
@@ -4,7 +4,6 @@ exports.xeroRouter = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const koa_router_1 = tslib_1.__importDefault(require("koa-router"));
6
6
  const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
7
- const typeorm_1 = require("typeorm");
8
7
  const auth_base_1 = require("@things-factory/auth-base");
9
8
  const env_1 = require("@things-factory/env");
10
9
  const shell_1 = require("@things-factory/shell");
@@ -17,7 +16,7 @@ exports.xeroRouter = new koa_router_1.default();
17
16
  exports.xeroRouter.get('/callback-xero', async (context, next) => {
18
17
  try {
19
18
  const { code, state: nonce } = context.query;
20
- const verificationTokenRepository = (0, typeorm_1.getRepository)(auth_base_1.VerificationToken);
19
+ const verificationTokenRepository = (0, shell_1.getRepository)(auth_base_1.VerificationToken);
21
20
  var verification = await verificationTokenRepository.findOne({
22
21
  where: {
23
22
  token: nonce,
@@ -85,8 +84,8 @@ exports.xeroRouter.get('/callback-xero', async (context, next) => {
85
84
  tokenType,
86
85
  expiresIn: new Date(exp * 1000)
87
86
  };
88
- var user = await (0, typeorm_1.getRepository)(auth_base_1.User).findOne(userId);
89
- account = await (0, typeorm_1.getRepository)(entities_1.Account).save(Object.assign(Object.assign(Object.assign({}, account), patch), { updater: user }));
87
+ var user = await (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: userId });
88
+ account = await (0, shell_1.getRepository)(entities_1.Account).save(Object.assign(Object.assign(Object.assign({}, account), patch), { updater: user }));
90
89
  context.cookies.set('xero-accounting', JSON.stringify(Object.assign(Object.assign({}, account), { message: 'success to activate' })), {
91
90
  httpOnly: true
92
91
  });
@@ -1 +1 @@
1
- {"version":3,"file":"xero-router.js","sourceRoot":"","sources":["../../server/routers/xero-router.ts"],"names":[],"mappings":";;;;AAAA,oEAA+B;AAC/B,oEAA8B;AAC9B,qCAAuC;AAEvC,yDAA0F;AAC1F,6CAA4C;AAC5C,iDAAyD;AACzD,iDAAgD;AAEhD,kEAAgF;AAChF,0CAAqC;AAErC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,YAAM,CAAC,GAAG,CAAC,2BAA2B,EAAE,EAAE,CAAC,CAAA;AAE3G,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,mDAAmD,CAAC,CAAA;AAEtE,QAAA,UAAU,GAAG,IAAI,oBAAM,EAAE,CAAA;AAEtC,kBAAU,CAAC,GAAG,CAAC,gBAAgB,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;IACvD,IAAI;QACF,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,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ACvD,OAAO,CAAC,MAAM,GAAG,GAAG,CAAA;AACtB,CAAC,CAAC,CAAA","sourcesContent":["import Router from 'koa-router'\nimport fetch from 'node-fetch'\nimport { getRepository } from 'typeorm'\n\nimport { User, VerificationToken, VerificationTokenType } from '@things-factory/auth-base'\nimport { config } from '@things-factory/env'\nimport { getUrlFromContext } from '@things-factory/shell'\nimport { parseJwt } from '@things-factory/utils'\n\nimport { ACCOUNTING_STATUS, AccountingAPI } from '../controllers/accounting-api'\nimport { Account } from '../entities'\n\nconst { apiKey, apiSecret, hostname, callback: redirect_uri } = config.get('accountingIntegrationXero', {})\n\nconst debug = require('debug')('things-factory:integration-accounting:xero-router')\n\nexport const xeroRouter = new Router()\n\nxeroRouter.get('/callback-xero', async (context, next) => {\n try {\n const { code, state: nonce } = context.query\n\n const verificationTokenRepository = getRepository(VerificationToken)\n\n var verification: VerificationToken = await verificationTokenRepository.findOne({\n where: {\n token: nonce,\n type: VerificationTokenType.REQUEST_ACCESS_TOKEN\n }\n })\n\n const { userId, suppliment: accountId } = verification\n\n await verificationTokenRepository.delete({\n userId,\n token: nonce,\n type: VerificationTokenType.REQUEST_ACCESS_TOKEN\n })\n\n var account = await AccountingAPI.getAccounting(accountId)\n const connectRequestData = {\n grant_type: 'authorization_code',\n code,\n redirect_uri\n }\n\n const connectResponse = await fetch(`https://identity.xero.com/connect/token`, {\n method: 'post',\n headers: {\n Authorization: `Basic ${Buffer.from(apiKey + ':' + apiSecret).toString('base64')}`,\n 'Content-Type': 'application/x-www-form-urlencoded'\n },\n body: Object.entries(connectRequestData)\n .map(([key, value]) => encodeURIComponent(key) + '=' + encodeURIComponent(value))\n .join('&')\n })\n\n if (!connectResponse.ok) {\n throw new Error(`get account information failed: ${await connectResponse.text()}`)\n }\n\n const body = await connectResponse.json()\n const {\n access_token /* token used to call the API */,\n id_token /* token containing user identity details (only returned if OpenID Connect scopes are requested) */,\n expires_in /* amount of seconds until the access token expires */,\n token_type: tokenType /* must be Bearer */,\n refresh_token\n /* token used to refresh the access token once it has expired (only returned if the offline_access scope is requested).\n */\n } = body\n\n /* decode access_token to get auth-event-id */\n const accessInfo = parseJwt(access_token)\n const { authentication_event_id, exp } = accessInfo\n\n /* get connections through the authentication_event_id */\n const connectionsResponse = await fetch(`https://api.xero.com/connections?authEventId=${authentication_event_id}`, {\n method: 'get',\n headers: {\n Authorization: `Bearer ${access_token}`,\n 'Content-Type': 'application/json'\n }\n })\n\n if (!connectionsResponse.ok) {\n context.throw(connectionsResponse.status, `get connection list failed: ${await connectionsResponse.text()}`)\n }\n\n const connections = await connectionsResponse.json()\n debug('connections', connections)\n\n var connection = connections[0]\n if (!connection) {\n context.throw(400, 'connection not found for this access token')\n }\n\n var patch = {\n name: connection.tenantName,\n accessToken: access_token,\n refreshToken: refresh_token,\n accessInfo: JSON.stringify(accessInfo, null, 2),\n accountInfo: JSON.stringify(connection, null, 2),\n accountId: connection.tenantId,\n status: ACCOUNTING_STATUS.ACTIVE,\n tokenType,\n expiresIn: new Date(exp * 1000)\n }\n\n var user = await getRepository(User).findOne(userId)\n\n account = await getRepository(Account).save({\n ...account,\n ...patch,\n updater: user\n })\n\n context.cookies.set(\n 'xero-accounting',\n JSON.stringify({\n ...account,\n message: 'success to activate'\n }),\n {\n httpOnly: true\n }\n )\n\n context.redirect(getUrlFromContext(context, '/callback-private-xero'))\n } catch (err) {\n var message: string = err.message\n\n if (account) {\n context.cookies.set(\n 'xero-accounting',\n JSON.stringify({\n ...account,\n message\n }),\n {\n httpOnly: true\n }\n )\n\n context.redirect(getUrlFromContext(context, '/callback-private-xero'))\n return\n }\n\n throw err\n }\n})\n\nxeroRouter.post('/webhook-xero', async (context, next) => {\n context.status = 200\n})\n"]}
1
+ {"version":3,"file":"xero-router.js","sourceRoot":"","sources":["../../server/routers/xero-router.ts"],"names":[],"mappings":";;;;AAAA,oEAA+B;AAC/B,oEAA8B;AAE9B,yDAA0F;AAC1F,6CAA4C;AAC5C,iDAAwE;AACxE,iDAAgD;AAEh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vE;IAAC,OAAO,GAAG,EAAE;QACZ,IAAI,OAAO,GAAW,GAAG,CAAC,OAAO,CAAA;QAEjC,IAAI,OAAO,EAAE;YACX,OAAO,CAAC,OAAO,CAAC,GAAG,CACjB,iBAAiB,EACjB,IAAI,CAAC,SAAS,iCACT,OAAO,KACV,OAAO,IACP,EACF;gBACE,QAAQ,EAAE,IAAI;aACf,CACF,CAAA;YAED,OAAO,CAAC,QAAQ,CAAC,IAAA,yBAAiB,EAAC,OAAO,EAAE,wBAAwB,CAAC,CAAC,CAAA;YACtE,OAAM;SACP;QAED,MAAM,GAAG,CAAA;KACV;AACH,CAAC,CAAC,CAAA;AAEF,kBAAU,CAAC,IAAI,CAAC,eAAe,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;IACvD,OAAO,CAAC,MAAM,GAAG,GAAG,CAAA;AACtB,CAAC,CAAC,CAAA","sourcesContent":["import Router from 'koa-router'\nimport fetch from 'node-fetch'\n\nimport { User, VerificationToken, VerificationTokenType } from '@things-factory/auth-base'\nimport { config } from '@things-factory/env'\nimport { getRepository, getUrlFromContext } from '@things-factory/shell'\nimport { parseJwt } from '@things-factory/utils'\n\nimport { ACCOUNTING_STATUS, AccountingAPI } from '../controllers/accounting-api'\nimport { Account } from '../entities'\n\nconst { apiKey, apiSecret, hostname, callback: redirect_uri } = config.get('accountingIntegrationXero', {})\n\nconst debug = require('debug')('things-factory:integration-accounting:xero-router')\n\nexport const xeroRouter = new Router()\n\nxeroRouter.get('/callback-xero', async (context, next) => {\n try {\n const { code, state: nonce } = context.query\n\n const verificationTokenRepository = getRepository(VerificationToken)\n\n var verification: VerificationToken = await verificationTokenRepository.findOne({\n where: {\n token: nonce,\n type: VerificationTokenType.REQUEST_ACCESS_TOKEN\n }\n })\n\n const { userId, suppliment: accountId } = verification\n\n await verificationTokenRepository.delete({\n userId,\n token: nonce,\n type: VerificationTokenType.REQUEST_ACCESS_TOKEN\n })\n\n var account = await AccountingAPI.getAccounting(accountId)\n const connectRequestData = {\n grant_type: 'authorization_code',\n code,\n redirect_uri\n }\n\n const connectResponse = await fetch(`https://identity.xero.com/connect/token`, {\n method: 'post',\n headers: {\n Authorization: `Basic ${Buffer.from(apiKey + ':' + apiSecret).toString('base64')}`,\n 'Content-Type': 'application/x-www-form-urlencoded'\n },\n body: Object.entries(connectRequestData)\n .map(([key, value]) => encodeURIComponent(key) + '=' + encodeURIComponent(value))\n .join('&')\n })\n\n if (!connectResponse.ok) {\n throw new Error(`get account information failed: ${await connectResponse.text()}`)\n }\n\n const body = await connectResponse.json()\n const {\n access_token /* token used to call the API */,\n id_token /* token containing user identity details (only returned if OpenID Connect scopes are requested) */,\n expires_in /* amount of seconds until the access token expires */,\n token_type: tokenType /* must be Bearer */,\n refresh_token\n /* token used to refresh the access token once it has expired (only returned if the offline_access scope is requested).\n */\n } = body\n\n /* decode access_token to get auth-event-id */\n const accessInfo = parseJwt(access_token)\n const { authentication_event_id, exp } = accessInfo\n\n /* get connections through the authentication_event_id */\n const connectionsResponse = await fetch(`https://api.xero.com/connections?authEventId=${authentication_event_id}`, {\n method: 'get',\n headers: {\n Authorization: `Bearer ${access_token}`,\n 'Content-Type': 'application/json'\n }\n })\n\n if (!connectionsResponse.ok) {\n context.throw(connectionsResponse.status, `get connection list failed: ${await connectionsResponse.text()}`)\n }\n\n const connections = await connectionsResponse.json()\n debug('connections', connections)\n\n var connection = connections[0]\n if (!connection) {\n context.throw(400, 'connection not found for this access token')\n }\n\n var patch = {\n name: connection.tenantName,\n accessToken: access_token,\n refreshToken: refresh_token,\n accessInfo: JSON.stringify(accessInfo, null, 2),\n accountInfo: JSON.stringify(connection, null, 2),\n accountId: connection.tenantId,\n status: ACCOUNTING_STATUS.ACTIVE,\n tokenType,\n expiresIn: new Date(exp * 1000)\n }\n\n var user = await getRepository(User).findOneBy({ id: userId })\n\n account = await getRepository(Account).save({\n ...account,\n ...patch,\n updater: user\n })\n\n context.cookies.set(\n 'xero-accounting',\n JSON.stringify({\n ...account,\n message: 'success to activate'\n }),\n {\n httpOnly: true\n }\n )\n\n context.redirect(getUrlFromContext(context, '/callback-private-xero'))\n } catch (err) {\n var message: string = err.message\n\n if (account) {\n context.cookies.set(\n 'xero-accounting',\n JSON.stringify({\n ...account,\n message\n }),\n {\n httpOnly: true\n }\n )\n\n context.redirect(getUrlFromContext(context, '/callback-private-xero'))\n return\n }\n\n throw err\n }\n})\n\nxeroRouter.post('/webhook-xero', async (context, next) => {\n context.status = 200\n})\n"]}