From 88c627c9659b582bff1b5b557678aaba0381784b Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Wed, 20 Dec 2023 06:07:51 -0100 Subject: [PATCH] chore: move proxyLink into cdk from engine backend --- connectors/connector-qbo/server.ts | 11 +++++++++-- kits/cdk/connector-meta.types.ts | 2 +- kits/cdk/index.ts | 4 +--- kits/cdk/{oauth => nango}/NangoClient.spec.ts | 0 kits/cdk/{oauth => nango}/NangoClient.ts | 1 + kits/cdk/nango/index.ts | 5 +++++ .../lib => kits/cdk/nango}/nangoProxyLink.spec.ts | 0 .../lib => kits/cdk/nango}/nangoProxyLink.ts | 0 kits/cdk/{oauth => nango}/oauthConnector.ts | 2 ++ kits/cdk/package.json | 3 ++- packages/engine-backend/package.json | 1 - packages/engine-backend/services/index.ts | 2 +- pnpm-lock.yaml | 12 ++++++------ 13 files changed, 28 insertions(+), 15 deletions(-) rename kits/cdk/{oauth => nango}/NangoClient.spec.ts (100%) rename kits/cdk/{oauth => nango}/NangoClient.ts (99%) create mode 100644 kits/cdk/nango/index.ts rename {packages/engine-backend/lib => kits/cdk/nango}/nangoProxyLink.spec.ts (100%) rename {packages/engine-backend/lib => kits/cdk/nango}/nangoProxyLink.ts (100%) rename kits/cdk/{oauth => nango}/oauthConnector.ts (98%) diff --git a/connectors/connector-qbo/server.ts b/connectors/connector-qbo/server.ts index bc4df24c..a83ee141 100644 --- a/connectors/connector-qbo/server.ts +++ b/connectors/connector-qbo/server.ts @@ -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' @@ -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 }, diff --git a/kits/cdk/connector-meta.types.ts b/kits/cdk/connector-meta.types.ts index 3c419f16..a8fe2ef2 100644 --- a/kits/cdk/connector-meta.types.ts +++ b/kits/cdk/connector-meta.types.ts @@ -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 diff --git a/kits/cdk/index.ts b/kits/cdk/index.ts index f98507c9..c0bfbb79 100644 --- a/kits/cdk/index.ts +++ b/kits/cdk/index.ts @@ -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' @@ -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' diff --git a/kits/cdk/oauth/NangoClient.spec.ts b/kits/cdk/nango/NangoClient.spec.ts similarity index 100% rename from kits/cdk/oauth/NangoClient.spec.ts rename to kits/cdk/nango/NangoClient.spec.ts diff --git a/kits/cdk/oauth/NangoClient.ts b/kits/cdk/nango/NangoClient.ts similarity index 99% rename from kits/cdk/oauth/NangoClient.ts rename to kits/cdk/nango/NangoClient.ts index 72044ba3..db0c0789 100644 --- a/kits/cdk/oauth/NangoClient.ts +++ b/kits/cdk/nango/NangoClient.ts @@ -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' diff --git a/kits/cdk/nango/index.ts b/kits/cdk/nango/index.ts new file mode 100644 index 00000000..e47e98c6 --- /dev/null +++ b/kits/cdk/nango/index.ts @@ -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 diff --git a/packages/engine-backend/lib/nangoProxyLink.spec.ts b/kits/cdk/nango/nangoProxyLink.spec.ts similarity index 100% rename from packages/engine-backend/lib/nangoProxyLink.spec.ts rename to kits/cdk/nango/nangoProxyLink.spec.ts diff --git a/packages/engine-backend/lib/nangoProxyLink.ts b/kits/cdk/nango/nangoProxyLink.ts similarity index 100% rename from packages/engine-backend/lib/nangoProxyLink.ts rename to kits/cdk/nango/nangoProxyLink.ts diff --git a/kits/cdk/oauth/oauthConnector.ts b/kits/cdk/nango/oauthConnector.ts similarity index 98% rename from kits/cdk/oauth/oauthConnector.ts rename to kits/cdk/nango/oauthConnector.ts index c359c099..8f100c98 100644 --- a/kits/cdk/oauth/oauthConnector.ts +++ b/kits/cdk/nango/oauthConnector.ts @@ -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, @@ -70,6 +71,7 @@ export function oauthConnect({ }) } +/** aka `makeNangoConnectorServer` */ export function makeOauthConnectorServer({ nangoClient, nangoProvider, diff --git a/kits/cdk/package.json b/kits/cdk/package.json index 1b2891bc..84b75e3d 100644 --- a/kits/cdk/package.json +++ b/kits/cdk/package.json @@ -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:*", @@ -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", diff --git a/packages/engine-backend/package.json b/packages/engine-backend/package.json index 1d767851..d5bd15b6 100644 --- a/packages/engine-backend/package.json +++ b/packages/engine-backend/package.json @@ -14,7 +14,6 @@ }, "devDependencies": { "@opensdks/runtime": "0.0.12", - "@opensdks/sdk-qbo": "0.0.11", "@usevenice/trpc-openapi": "1.3.8" } } diff --git a/packages/engine-backend/services/index.ts b/packages/engine-backend/services/index.ts index c795c9d2..c26a4859 100644 --- a/packages/engine-backend/services/index.ts +++ b/packages/engine-backend/services/index.ts @@ -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' diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ba0aec20..afbe4896 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1159,6 +1159,9 @@ importers: kits/cdk: dependencies: + '@opensdks/runtime': + specifier: 0.0.12 + version: 0.0.12 '@trpc/server': specifier: 10.40.0 version: 10.40.0 @@ -1181,9 +1184,9 @@ importers: '@nangohq/frontend': specifier: 0.33.8 version: 0.33.8(patch_hash=cscdyzeu5adridjxg5g7kdqy6q) - '@opensdks/runtime': - specifier: 0.0.12 - version: 0.0.12 + '@opensdks/sdk-qbo': + specifier: 0.0.11 + version: 0.0.11 '@types/jsonwebtoken': specifier: 9.0.2 version: 9.0.2 @@ -1310,9 +1313,6 @@ importers: '@opensdks/runtime': specifier: 0.0.12 version: 0.0.12 - '@opensdks/sdk-qbo': - specifier: 0.0.11 - version: 0.0.11 '@usevenice/trpc-openapi': specifier: 1.3.8 version: 1.3.8(@trpc/server@10.40.0)(zod@3.21.4)