Skip to content

Commit

Permalink
chore: move proxyLink into cdk from engine backend
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyxiao committed Dec 20, 2023
1 parent 3b0218e commit 88c627c
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 15 deletions.
11 changes: 9 additions & 2 deletions connectors/connector-qbo/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {initSDK} from '@opensdks/runtime'
import type {QBOSDKTypes} from '@opensdks/sdk-qbo'
import {qboSdkDef} from '@opensdks/sdk-qbo'
import type {ConnectorServer} from '@usevenice/cdk'
import {nangoProxyLink} from '@usevenice/cdk'
import {Rx, rxjs, snakeCase} from '@usevenice/util'
import type {QBO, qboSchemas, TransactionTypeName} from './def'
import {QBO_ENTITY_NAME, qboHelpers, TRANSACTION_TYPE_NAME} from './def'
Expand All @@ -17,17 +18,23 @@ export const qboServer = {
const qbo = initQBOSdk({
envName: config.envName,
realmId: settings.oauth.connection_config.realmId,
// Access token may be out of date, we are relying on fetchLinks to contain a middleware to
// either refresh the token or proxy the request and with its own tokens
// Which means that in practice this is probably not gonna be used...
accessToken: settings.oauth.credentials.access_token,
links: (defaultLinks) => [
(req, next) => {
if (qbo.clientOptions.baseUrl) {
req.headers.set('base-url-override', qbo.clientOptions.baseUrl)
req.headers.set(
nangoProxyLink.kBaseUrlOverride,
qbo.clientOptions.baseUrl,
)
}
return next(req)
},
...fetchLinks,
...defaultLinks,
],
accessToken: '', // Will use passthrough api for this..
})
return qbo
},
Expand Down
2 changes: 1 addition & 1 deletion kits/cdk/connector-meta.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {z} from '@usevenice/zod'
import type {ConnHelpers} from './connector.types'
import type {EndUserId, ExtEndUserId, ExternalId, Id} from './id.types'
import {zExternalId} from './id.types'
import type {NangoProvider} from './oauth/NangoClient'
import type {NangoProvider} from './nango/NangoClient'
import type {AnyEntityPayload, ResoUpdateData, Source} from './protocol'

// aka verticals
Expand Down
4 changes: 1 addition & 3 deletions kits/cdk/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export * from './oauth/NangoClient'
export * from './oauth/oauthConnector'

// codegen:start {preset: barrel, include: "./{*.{ts,tsx},*/index.{ts,tsx}}", exclude: "./**/*.{spec,test,fixture}.{ts,tsx}"}
export * from './base-links'
export * from './connector-meta.types'
Expand All @@ -11,6 +8,7 @@ export * from './frontend-utils'
export * from './id.types'
export * from './metaForConnector'
export * from './models'
export * from './nango/index'
export * from './protocol'
export * from './sync'
export * from './verticals'
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** TODO: Move this into @opensdks */
import type {Endpoints, InfoFromEndpoints} from '@usevenice/util'
import {makeOpenApiClient} from '@usevenice/util'
import {z} from '@usevenice/zod'
Expand Down
5 changes: 5 additions & 0 deletions kits/cdk/nango/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// codegen:start {preset: barrel, include: "./{*.{ts,tsx},*/index.{ts,tsx}}", exclude: "./**/*.{spec,test,fixture}.{ts,tsx}"}
export * from './NangoClient'
export * from './nangoProxyLink'
export * from './oauthConnector'
// codegen:end
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function isNangoAuthError(err: unknown): err is AuthError {
return typeof err === 'object' && err != null && 'type' in err
}

/** Aka `nangoConnect` */
export function oauthConnect({
nangoFrontend,
connectorName,
Expand Down Expand Up @@ -70,6 +71,7 @@ export function oauthConnect({
})
}

/** aka `makeNangoConnectorServer` */
export function makeOauthConnectorServer({
nangoClient,
nangoProvider,
Expand Down
3 changes: 2 additions & 1 deletion kits/cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"sideEffects": false,
"module": "./index.ts",
"dependencies": {
"@opensdks/runtime": "0.0.12",
"@trpc/server": "10.40.0",
"@usevenice/util": "workspace:*",
"@usevenice/zod": "workspace:*",
Expand All @@ -13,7 +14,7 @@
},
"devDependencies": {
"@nangohq/frontend": "0.33.8",
"@opensdks/runtime": "0.0.12",
"@opensdks/sdk-qbo": "0.0.11",
"@types/jsonwebtoken": "9.0.2",
"@types/react": "*",
"@usevenice/trpc-openapi": "1.3.8",
Expand Down
1 change: 0 additions & 1 deletion packages/engine-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
},
"devDependencies": {
"@opensdks/runtime": "0.0.12",
"@opensdks/sdk-qbo": "0.0.11",
"@usevenice/trpc-openapi": "1.3.8"
}
}
2 changes: 1 addition & 1 deletion packages/engine-backend/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {logLink} from '@opensdks/runtime'
import type {AnyConnectorImpl} from '@usevenice/cdk'
import {nangoProxyLink} from '@usevenice/cdk'
import {R} from '@usevenice/util'
import {nangoProxyLink} from '../lib/nangoProxyLink'
import type {_ResourceExpanded} from './dbService'
import {makeDBService} from './dbService'
import type {MetaService} from './metaService'
Expand Down
12 changes: 6 additions & 6 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 88c627c

Please sign in to comment.