feat: archive bindings on Feishu lifecycle events

This commit is contained in:
2026-07-13 15:53:28 +08:00
parent d94cc787b2
commit 82f57317df
7 changed files with 402 additions and 7 deletions
+8 -3
View File
@@ -66,7 +66,7 @@ export async function upsertScopedFeishuIdentityInTransaction(
const principalId = scopedFeishuPrincipalId("USER", connectionId, openId);
const userId = deterministicFeishuUserId(connectionId, openId);
const connection = await lockActiveConnection(prisma, connectionId);
const connection = await requireActiveFeishuApplicationConnectionInTransaction(prisma, connectionId);
if (input.expectedOrganizationId !== undefined &&
input.expectedOrganizationId !== connection.organizationId) {
throw new Error("Feishu identity Organization scope mismatch");
@@ -114,7 +114,7 @@ export async function resolveScopedFeishuIdentity(
const connectionId = nonEmpty(input.connectionId, "Feishu connectionId");
const openId = nonEmpty(input.openId, "Feishu openId");
return prisma.$transaction(async (tx) => {
const connection = await lockActiveConnection(tx, connectionId);
const connection = await requireActiveFeishuApplicationConnectionInTransaction(tx, connectionId);
if (input.expectedOrganizationId !== undefined &&
input.expectedOrganizationId !== connection.organizationId) {
throw new Error("Feishu identity Organization scope mismatch");
@@ -127,7 +127,12 @@ export async function resolveScopedFeishuIdentity(
});
}
async function lockActiveConnection(
/**
* Lock and prove that a Feishu application connection is currently usable.
* Callers handling provider-originated data use this before trusting a
* connection-scoped identifier.
*/
export async function requireActiveFeishuApplicationConnectionInTransaction(
prisma: Prisma.TransactionClient,
connectionId: string,
): Promise<{ readonly organizationId: string }> {