Skip to content

Commit

Permalink
feat: remove hard code in xero connector
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyxiao committed Apr 1, 2024
1 parent 0acfea7 commit 5d3124f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
2 changes: 1 addition & 1 deletion connectors/connector-xero/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"module": "./index.ts",
"dependencies": {
"@opensdks/runtime": "^0.0.19",
"@opensdks/sdk-xero": "^0.0.6",
"@opensdks/sdk-xero": "^0.0.7",
"@opensdks/util-zod": "^0.0.15",
"@usevenice/cdk": "workspace:*",
"@usevenice/util": "workspace:*"
Expand Down
34 changes: 22 additions & 12 deletions connectors/connector-xero/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ import {rxjs} from '@usevenice/util'
import {type xeroSchemas} from './def'

export const xeroServer = {
// Would be good if this was async...
newInstance: ({settings, fetchLinks}) => {
const xero = initXeroSDK({
headers: {
authorization: `Bearer ${settings.oauth.credentials.access_token}`,
},
links: (defaultLinks) => [
(req, next) => {
if (xero.clientOptions.baseUrl) {
req.headers.set(
nangoProxyLink.kBaseUrlOverride,
xero.clientOptions.baseUrl,
)
req.headers.set(
nangoProxyLink.kBaseUrlOverride,
'https://api.xero.com',
)
// nango's proxy endpoint is pretty annoying... Will only proxy
// if it is prefixed with nango-proxy. Might as well not proxy like this...
const tenantId = req.headers.get('xero-tenant-id')
if (tenantId) {
req.headers.delete('xero-tenant-id')
req.headers.set('nango-proxy-xero-tenant-id', tenantId)
}
return next(req)
},
Expand All @@ -27,15 +33,19 @@ export const xeroServer = {
return xero
},
sourceSync: ({instance: xero}) => {
// TODO(@jatin): Add logic here to handle sync.
console.log('[xero] Starting sync')
const getAll = async () => {
const result = await xero.GET('/Accounts', {
params: {
header: {
'xero-tenant-id': '35325d8f-5087-4c6d-b413-c3f740c26f2e', // TODO: Remove hardcoding
},
},
// TODO: Should handle more than one tenant Id
const tenantId = await xero.identity
.GET('/Connections')
.then((r) => r.data?.[0]?.tenantId)
if (!tenantId) {
throw new Error(
'Missing access to any tenants. Check xero token permission',
)
}
const result = await xero.accounting.GET('/Accounts', {
params: {header: {'xero-tenant-id': tenantId}},
})
console.log('result', result)
return result
Expand Down
2 changes: 2 additions & 0 deletions packages/engine-backend/router/endUserRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ export const endUserRouter = trpc.router({
const int = await ctx.asOrgIfNeeded.getConnectorConfigOrFail(ccfgId)
console.log('didConnect start', int.connector.name, input, connCtxInput)

// TODO: we should make it possible for oauth connectors to
// ALSO handle custom postConnect... This would be very handy for xero for instance
const resoUpdate = await (async () => {
if (
!int.connector.postConnect &&
Expand Down
24 changes: 20 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5d3124f

Please sign in to comment.