-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(xero): listCategories, sourceSync account and category
- Loading branch information
Showing
10 changed files
with
122 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
import type {initXeroSDK} from '@opensdks/sdk-xero' | ||
|
||
// codegen:start {preset: barrel, include: "./{*.{ts,tsx},*/index.{ts,tsx}}", exclude: "./**/*.{d,spec,test,fixture,gen,node}.{ts,tsx}"} | ||
export * from './def' | ||
export * from './server' | ||
// codegen:end | ||
|
||
export * from '@opensdks/sdk-xero' | ||
|
||
export type XeroSDK = ReturnType<typeof initXeroSDK> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type {Oas_accounting, XeroSDK} from 'connectors/connector-xero' | ||
import type {StrictObj} from '@usevenice/vdk' | ||
import {mapper, z, zCast} from '@usevenice/vdk' | ||
import type {VerticalBanking} from '../banking' | ||
import {zBanking} from '../banking' | ||
|
||
type Xero = Oas_accounting['components']['schemas'] | ||
|
||
const mappers = { | ||
category: mapper( | ||
zCast<StrictObj<Xero['Account']>>(), | ||
zBanking.category.extend({_raw: z.unknown().optional()}), | ||
{ | ||
id: 'AccountID', | ||
name: 'Name', | ||
_raw: (a) => a, | ||
}, | ||
), | ||
} | ||
|
||
export const xeroAdapter = { | ||
listCategories: async ({instance}) => { | ||
// TODO: Abstract this away please... | ||
const tenantId = await instance.identity | ||
.GET('/Connections') | ||
.then((r) => r.data?.[0]?.tenantId) | ||
if (!tenantId) { | ||
throw new Error( | ||
'Missing access to any tenants. Check xero token permission', | ||
) | ||
} | ||
|
||
const res = await instance.accounting.GET('/Accounts', { | ||
params: { | ||
header: {'xero-tenant-id': tenantId}, | ||
query: { | ||
where: 'Class=="REVENUE"||Class=="EXPENSE"', | ||
}, | ||
}, | ||
}) | ||
return { | ||
hasNextPage: false, | ||
items: (res.data.Accounts ?? []).map(mappers.category), | ||
} | ||
}, | ||
} satisfies VerticalBanking<{instance: XeroSDK}> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters