Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Oauth Implementation #267

Merged
merged 17 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 153 additions & 53 deletions apps/app-config/_generateConnectorLists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ import type {ConnectorDef} from '@openint/cdk'
import {camelCase} from '@openint/util/string-utils'
import prettierConfig from '../../prettier.config'

async function writePretty(filename: string, content: string, pretty = true) {
fs.mkdirSync(pathJoin(__dirname, 'connectors'), {recursive: true})
async function writePretty(
filename: string,
content: string,
outputPath = pathJoin(__dirname, 'connectors'),
pretty = true,
) {
fs.mkdirSync(outputPath, {recursive: true})
fs.writeFileSync(
pathJoin(__dirname, 'connectors', filename),
pathJoin(outputPath, filename),
!pretty
? content
: await prettier.format(
Expand All @@ -25,42 +30,114 @@ async function writePretty(filename: string, content: string, pretty = true) {
)
}

const connectorList = fs
.readdirSync(pathJoin(__dirname, '../../connectors'), {
withFileTypes: true,
})
.filter((r) => r.isDirectory())
.map((d) => {
const path = pathJoin(__dirname, '../../connectors', d.name)
const def = fs.existsSync(pathJoin(path, 'def.ts'))
? // TODO: Automate generation of package.json is still needed, otherwise does not work for new packages
// @see https://share.cleanshot.com/wDmqwsHS
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
(require(`@openint/${d.name}/def`).default as ConnectorDef)
: undefined
// we do some validation also

if (def && `connector-${def.name}` !== d.name) {
throw new Error(`Mismatched connector: ${def.name} dir: ${d.name}`)
}
return {
name: def?.name,
dirName: d.name,
varName: camelCase(d.name),
async function generateCnextIndex() {
const cnextPath = pathJoin(__dirname, '../../connectors/cnext')
const cnextConnectors = fs
.readdirSync(cnextPath, {
withFileTypes: true,
})
.filter(
(r) =>
r.isDirectory() &&
r.name !== 'def' &&
!r.name.startsWith('.') &&
r.name !== 'node_modules',
)

await writePretty(
'index.ts',
`export type {ConnectorDef} from './def'
export type {AuthType} from './def'

${cnextConnectors
.map((d) => {
const connectorName = `connector${d.name
.charAt(0)
.toUpperCase()}${camelCase(d.name.slice(1))}`
return `import {server as ${connectorName}_server, def as ${connectorName}_def} from './${d.name}'`
})
.join('\n')}

export {
${cnextConnectors
.map((d) => {
const connectorName = `connector${d.name
.charAt(0)
.toUpperCase()}${camelCase(d.name.slice(1))}`
return `${connectorName}_server, ${connectorName}_def`
})
.join(',\n ')}
}`,
cnextPath,
)
}

const connectorList = [
...fs
.readdirSync(pathJoin(__dirname, '../../connectors'), {
withFileTypes: true,
})
.filter((r) => r.isDirectory() && r.name !== 'cnext')
.map((d) => {
const path = pathJoin(__dirname, '../../connectors', d.name)
const def = fs.existsSync(pathJoin(path, 'def.ts'))
? // TODO: Automate generation of package.json is still needed, otherwise does not work for new packages
// @see https://share.cleanshot.com/wDmqwsHS
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
(require(`@openint/${d.name}/def`).default as ConnectorDef)
: undefined
// we do some validation also

if (def && `connector-${def.name}` !== d.name) {
throw new Error(`Mismatched connector: ${def.name} dir: ${d.name}`)
}
return {
name: def?.name,
dirName: d.name,
varName: camelCase(d.name),
imports: {
def: fs.existsSync(pathJoin(path, 'def.ts'))
? `@openint/${d.name}/def`
: undefined,
client: fs.existsSync(pathJoin(path, 'client.ts'))
? `@openint/${d.name}/client`
: undefined,
server: fs.existsSync(pathJoin(path, 'server.ts'))
? `@openint/${d.name}/server`
: undefined,
},
}
}),

// Add cnext connectors
...fs
.readdirSync(pathJoin(__dirname, '../../connectors/cnext'), {
withFileTypes: true,
})
.filter(
(r) =>
r.isDirectory() &&
r.name !== 'def' &&
!r.name.startsWith('.') &&
r.name !== 'node_modules',
)
.map((d) => ({
name: d.name,
dirName: `cnext-${d.name}`,
varName: `connector${d.name.charAt(0).toUpperCase()}${camelCase(
d.name.slice(1),
)}`,
imports: {
def: fs.existsSync(pathJoin(path, 'def.ts'))
? `@openint/${d.name}/def`
: undefined,
client: fs.existsSync(pathJoin(path, 'client.ts'))
? `@openint/${d.name}/client`
: undefined,
server: fs.existsSync(pathJoin(path, 'server.ts'))
? `@openint/${d.name}/server`
: undefined,
def: '@openint/cnext',
server: '@openint/cnext',
},
}
})
})),
]

async function main() {
// Generate the cnext index.ts first
await generateCnextIndex()

await writePretty(
'meta.js',
`
Expand All @@ -71,21 +148,32 @@ async function main() {
const entries = ['def', 'client', 'server'] as const

for (const entry of entries) {
const list = connectorList.filter((int) => !!int.imports[entry])
const list = connectorList.filter(
(int) => !!int.imports[entry as keyof typeof int.imports],
)
await writePretty(
`connectors.${entry}.ts`,
`${list
.map(
(int) =>
`import {default as ${int.varName}} from '${int.imports[entry]}'`,
)
.map((int) => {
// Check if this is a cnext connector
const isCnext = int.dirName.startsWith('cnext-')
if (isCnext) {
return `import {${int.varName}_${entry} as ${int.varName}} from '${
int.imports[entry as keyof typeof int.imports]
}'`
}
return `import {default as ${int.varName}} from '${
int.imports[entry as keyof typeof int.imports]
}'`
})
.join('\n')}
export const ${entry}Connectors = {${list
.map(({name, varName}) => `${name}: ${varName},`)
.map(({name, varName}) => `'${name}': ${varName},`)
.join('\n')}}
`,
)
}

const mergedlist = connectorList.filter((int) =>
Object.values(int.imports).some((v) => !!v),
)
Expand All @@ -101,26 +189,38 @@ async function main() {
// This avoids server needing to import client side code unnecessarily
.filter(([k]) => k !== 'client'),
)
// Check if this is a cnext connector
const isCnext = int.dirName.startsWith('cnext-')

return [
Object.entries(validImports)
.map(
([k, v]) => `import {default as ${int.varName}_${k}} from '${v}'`,
)
.join('\n'),
isCnext
? `import {${Object.keys(validImports)
.map((k) => `${int.varName}_${k}`)
.join(', ')}} from '${validImports['def']}'`
: Object.entries(validImports)
.map(
([k, v]) =>
`import {default as ${int.varName}_${k}} from '${v}'`,
)
.join('\n'),
`const ${int.varName} = {
${Object.keys(validImports)
.map((k) => `...${int.varName}_${k}`)
.join(',')}
}`,
}`,
]
})
.join('\n')}


export const mergedConnectors = {${mergedlist
.map(({name, varName}) => `${name}: ${varName},`)
.join('\n')}}
`,
export const mergedConnectors = {${mergedlist
.map(({name, varName}) => {
// Skip node_modules
if (name === 'node_modules') return null
return `'${name?.toLowerCase().replace(/-/g, '')}': ${varName},`
})
.filter(Boolean)
.join('\n')}}
`,
)
}

Expand Down
2 changes: 2 additions & 0 deletions apps/app-config/connectors/connectors.def.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// generated by _generateConnectorLists.ts. Do not modify by hand
import {connectorGoogledrive_def as connectorGoogledrive} from '@openint/cnext'
import {default as connectorAircall} from '@openint/connector-aircall/def'
import {default as connectorAirtable} from '@openint/connector-airtable/def'
import {default as connectorApollo} from '@openint/connector-apollo/def'
Expand Down Expand Up @@ -109,4 +110,5 @@ export const defConnectors = {
xero: connectorXero,
yodlee: connectorYodlee,
zohodesk: connectorZohodesk,
googledrive: connectorGoogledrive,
}
10 changes: 10 additions & 0 deletions apps/app-config/connectors/connectors.merged.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// generated by _generateConnectorLists.ts. Do not modify by hand
import {
connectorGoogledrive_def,
connectorGoogledrive_server,
} from '@openint/cnext'
import {default as connectorAircall_def} from '@openint/connector-aircall/def'
import {default as connectorAircall_server} from '@openint/connector-aircall/server'
import {default as connectorAirtable_def} from '@openint/connector-airtable/def'
Expand Down Expand Up @@ -374,6 +378,11 @@ const connectorZohodesk = {
...connectorZohodesk_server,
}

const connectorGoogledrive = {
...connectorGoogledrive_def,
...connectorGoogledrive_server,
}

export const mergedConnectors = {
aircall: connectorAircall,
airtable: connectorAirtable,
Expand Down Expand Up @@ -429,4 +438,5 @@ export const mergedConnectors = {
xero: connectorXero,
yodlee: connectorYodlee,
zohodesk: connectorZohodesk,
googledrive: connectorGoogledrive,
}
2 changes: 2 additions & 0 deletions apps/app-config/connectors/connectors.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// generated by _generateConnectorLists.ts. Do not modify by hand
import {connectorGoogledrive_server as connectorGoogledrive} from '@openint/cnext'
import {default as connectorAircall} from '@openint/connector-aircall/server'
import {default as connectorAirtable} from '@openint/connector-airtable/server'
import {default as connectorApollo} from '@openint/connector-apollo/server'
Expand Down Expand Up @@ -105,4 +106,5 @@ export const serverConnectors = {
xero: connectorXero,
yodlee: connectorYodlee,
zohodesk: connectorZohodesk,
googledrive: connectorGoogledrive,
}
8 changes: 8 additions & 0 deletions apps/app-config/connectors/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ module.exports = [
server: '@openint/connector-onebrick/server',
},
},
{dirName: 'connector-outlook', varName: 'connectorOutlook', imports: {}},
{
name: 'outreach',
dirName: 'connector-outreach',
Expand Down Expand Up @@ -405,6 +406,7 @@ module.exports = [
server: '@openint/connector-spreadsheet/server',
},
},
{dirName: 'connector-starbase', varName: 'connectorStarbase', imports: {}},
{
name: 'stripe',
dirName: 'connector-stripe',
Expand Down Expand Up @@ -494,4 +496,10 @@ module.exports = [
server: '@openint/connector-zohodesk/server',
},
},
{
name: 'googledrive',
dirName: 'cnext-googledrive',
varName: 'connectorGoogledrive',
imports: {def: '@openint/cnext', server: '@openint/cnext'},
},
]
1 change: 1 addition & 0 deletions apps/app-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@clerk/nextjs": "5.6.0",
"@openint/cdk": "workspace:*",
"@openint/cnext": "workspace:*",
"@openint/connector-aircall": "workspace:*",
"@openint/connector-airtable": "workspace:*",
"@openint/connector-alphavantage": "workspace:*",
Expand Down
Loading