Skip to content

Commit fd9048f

Browse files
committed
adding org id to connect context
1 parent f6df933 commit fd9048f

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

connectors/cnext/_defaults/oauth2/server.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ describeEachDatabase({drivers: ['pglite'], migrate: true, logger}, () => {
115115
{
116116
extCustomerId: `cust_123` as any,
117117
webhookBaseUrl: 'https://example.com/webhook',
118+
orgId: `org_123` as any,
118119
},
119120
{connectionId: 'test_connection_id'},
120121
)
@@ -166,6 +167,7 @@ describeEachDatabase({drivers: ['pglite'], migrate: true, logger}, () => {
166167
{
167168
extCustomerId: `cust_123` as any,
168169
webhookBaseUrl: 'https://example.com/webhook',
170+
orgId: `org_123` as any,
169171
},
170172
{connectionId: 'test_connection_id'},
171173
),
@@ -186,6 +188,7 @@ describeEachDatabase({drivers: ['pglite'], migrate: true, logger}, () => {
186188
{
187189
extCustomerId: `cust_123` as any,
188190
webhookBaseUrl: 'https://example.com/webhook',
191+
orgId: `org_123` as any,
189192
},
190193
{connectionId: 'test_connection_id'},
191194
),

kits/cdk/connector-meta.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export interface ConnectContext<TSettings>
113113
externalId: ExternalId
114114
settings: TSettings
115115
} | null
116+
orgId: `org_${string}`
116117
}
117118

118119
// TODO: We should rename `provider` to `integration` given that they are both

packages/api-v1/routers/connect.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ export const connectRouter = router({
8787
})
8888
}
8989

90+
if (!ctx.viewer.orgId) {
91+
throw new TRPCError({
92+
code: 'BAD_REQUEST',
93+
message: 'OrgId is required',
94+
})
95+
}
96+
9097
console.log('preConnect', input, ctx, ccfg)
9198
const res = await connector.preConnect?.(
9299
ccfg.config,
@@ -96,6 +103,7 @@ export const connectRouter = router({
96103
extCustomerId: (ctx.viewer.role === 'customer'
97104
? ctx.viewer.customerId
98105
: ctx.viewer.userId) as ExtCustomerId,
106+
orgId: ctx.viewer.orgId,
99107
},
100108
input.data.input,
101109
)
@@ -162,6 +170,12 @@ export const connectRouter = router({
162170
})
163171
}
164172

173+
if (!ctx.viewer.orgId) {
174+
throw new TRPCError({
175+
code: 'BAD_REQUEST',
176+
message: 'OrgId is required',
177+
})
178+
}
165179
console.log('preConnect', input, ctx, ccfg)
166180
const connUpdate = await connector.postConnect?.(
167181
input.data.input,
@@ -172,6 +186,7 @@ export const connectRouter = router({
172186
extCustomerId: (ctx.viewer.role === 'customer'
173187
? ctx.viewer.customerId
174188
: ctx.viewer.userId) as ExtCustomerId,
189+
orgId: ctx.viewer.orgId,
175190
},
176191
)
177192
const id = makeId('conn', input.data.connector_name, makeUlid())

packages/engine-backend/router/customerRouter.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ export const customerRouter = trpc.router({
306306
makeId('conn', int.connector.name, connectionExternalId),
307307
)
308308
: undefined
309+
if (!ctx.viewer.orgId) {
310+
throw new TRPCError({
311+
code: 'BAD_REQUEST',
312+
message: 'OrgId is required',
313+
})
314+
}
309315
return int.connector.preConnect?.(
310316
int.config,
311317
{
@@ -323,6 +329,7 @@ export const customerRouter = trpc.router({
323329
customerId:
324330
ctx.viewer.role === 'customer' ? ctx.viewer.customerId : null,
325331
}),
332+
orgId: ctx.viewer.orgId,
326333
},
327334
preConnInput,
328335
)
@@ -393,6 +400,12 @@ export const customerRouter = trpc.router({
393400
console.warn('postConnect input c', parsedInput.error)
394401
}
395402

403+
if (!ctx.viewer.orgId) {
404+
throw new TRPCError({
405+
code: 'BAD_REQUEST',
406+
message: 'OrgId is required',
407+
})
408+
}
396409
return await int.connector.postConnect(
397410
int.connector.schemas.connectOutput.parse(input),
398411
{
@@ -414,6 +427,7 @@ export const customerRouter = trpc.router({
414427
customerId:
415428
ctx.viewer.role === 'customer' ? ctx.viewer.customerId : null,
416429
}),
430+
orgId: ctx.viewer.orgId,
417431
},
418432
)
419433
})()

0 commit comments

Comments
 (0)