Skip to content

Commit

Permalink
Sync merge transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyxiao committed Oct 11, 2023
1 parent 6b67d37 commit 67fcc77
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion apps/app-config/register.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ implementProxyFn($getFetchFn, () => crossFetch ?? globalThis.fetch, {
implementProxyFn(
$makeProxyAgent,
(input) => {
if (globalThis.fetch !== crossFetch) {
if ($getFetchFn() !== crossFetch) {
console.warn(
'[proxy] Using proxy agent with non-polyfilled fetch may not work',
)
Expand Down
15 changes: 10 additions & 5 deletions integrations/integration-merge/def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import type {IntegrationDef, IntegrationSchemas} from '@usevenice/cdk-core'
import {intHelpers} from '@usevenice/cdk-core'
import type {Standard} from '@usevenice/standard'
import {z, zCast} from '@usevenice/util'

import {mergeLogoSvg} from './merge-logo.svg'
Expand Down Expand Up @@ -78,18 +79,22 @@ export const mergeDef = {
}
},
},
// Should be called accounting...
extension: {
sourceMapEntity: {
account: (entity) => ({
id: entity.id,
entityName: 'account',
entity: {name: entity.entity.name ?? ''},
}),
// transaction: (entity) => ({
// id: entity.id,
// entityName: 'transaction',
// entity: {date: entity.entity.transaction_date},
// }),
transaction: (entity) => ({
id: entity.id,
entityName: 'transaction',
entity: {
date: entity.entity.transaction_date ?? '',
description: entity.entity.line_items?.[0]?.memo ?? '',
} satisfies Standard.Transaction,
}),
},
},
} satisfies IntegrationDef<typeof mergeSchemas>
Expand Down
28 changes: 19 additions & 9 deletions integrations/integration-merge/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,26 @@ export const mergeServer = {
accountToken: settings.accountToken,
})

return rxjs
.from(
client.accounting
.get('/accounts', {})
.then((res) =>
(res.results ?? [])?.map((acct) =>
helpers._opData('account', acct.id ?? '', acct),
),
async function* iterateEntities() {
yield await client.accounting
.get('/accounts', {})
.then((res) =>
(res.results ?? [])?.map((acct) =>
helpers._opData('account', acct.id ?? '', acct),
),
)
)

yield await client.accounting
.get('/transactions', {})
.then((res) =>
(res.results ?? [])?.map((txn) =>
helpers._opData('transaction', txn.id ?? '', txn),
),
)
}

return rxjs
.from(iterateEntities())
.pipe(Rx.mergeMap((ops) => rxjs.from(ops)))
},
} satisfies IntegrationServer<typeof mergeSchemas>
Expand Down

0 comments on commit 67fcc77

Please sign in to comment.