🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
chore(scim): add [SCIM] log prefix and operation confirmations (#13245)
Steffen Schmitz011ce23d7f42
diff --git a/web/src/pages/api/public/scim/ResourceTypes.ts b/web/src/pages/api/public/scim/ResourceTypes.tsindex 1f7b24e322..92666fd875 100644--- a/web/src/pages/api/public/scim/ResourceTypes.ts+++ b/web/src/pages/api/public/scim/ResourceTypes.ts@@ -13,7 +13,7 @@ export default async function handler(if (req.method !== "GET") {logger.error(- `Method not allowed for ${req.method} on /api/public/scim/ResourceTypes`,+ `[SCIM] Method not allowed for ${req.method} on /api/public/scim/ResourceTypes`,);return res.status(405).json({schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],diff --git a/web/src/pages/api/public/scim/Schemas.ts b/web/src/pages/api/public/scim/Schemas.tsindex fc69dbff69..bda4c1f3f8 100644--- a/web/src/pages/api/public/scim/Schemas.ts+++ b/web/src/pages/api/public/scim/Schemas.ts@@ -13,7 +13,7 @@ export default async function handler(if (req.method !== "GET") {logger.error(- `Method not allowed for ${req.method} on /api/public/scim/Schemas`,+ `[SCIM] Method not allowed for ${req.method} on /api/public/scim/Schemas`,);return res.status(405).json({schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],diff --git a/web/src/pages/api/public/scim/ServiceProviderConfig.ts b/web/src/pages/api/public/scim/ServiceProviderConfig.tsindex eb1b98daf3..39a3a68752 100644--- a/web/src/pages/api/public/scim/ServiceProviderConfig.ts+++ b/web/src/pages/api/public/scim/ServiceProviderConfig.ts@@ -13,7 +13,7 @@ export default async function handler(if (req.method !== "GET") {logger.error(- `Method not allowed for ${req.method} on /api/public/scim/ServiceProviderConfig`,+ `[SCIM] Method not allowed for ${req.method} on /api/public/scim/ServiceProviderConfig`,);return res.status(405).json({schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],diff --git a/web/src/pages/api/public/scim/Users/[id].ts b/web/src/pages/api/public/scim/Users/[id].tsindex 72f81f8fa9..ed3d1a4ef7 100644--- a/web/src/pages/api/public/scim/Users/[id].ts+++ b/web/src/pages/api/public/scim/Users/[id].ts@@ -13,7 +13,7 @@ export default async function handler(if (!["GET", "DELETE", "PATCH", "PUT"].includes(req.method || "")) {logger.error(- `Method not allowed for ${req.method} on /api/public/scim/Users/[id]`,+ `[SCIM] Method not allowed for ${req.method} on /api/public/scim/Users/[id]`,);return res.status(405).json({schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],@@ -50,7 +50,7 @@ export default async function handler(}logger.info(- `Received request for /api/public/scim/Users/[id] with method ${req.method} for orgId ${authCheck.scope.orgId} and userId ${req.query.id}`,+ `[SCIM] Received request for /api/public/scim/Users/[id] with method ${req.method} for orgId ${authCheck.scope.orgId} and userId ${req.query.id}`,);// First, check if the user exists in the system at all@@ -89,7 +89,7 @@ export default async function handler(}} catch (error) {logger.error(- `Error handling SCIM user ${req.query.id} for ${req.method}`,+ `[SCIM] Error handling user ${req.query.id} for ${req.method}`,error,);return res.status(500).json({@@ -162,7 +162,7 @@ async function handlePatch(try {body = JSON.parse(body);} catch (error) {- logger.warn("Failed to parse JSON body", error);+ logger.warn("[SCIM] Failed to parse JSON body", error);return res.status(400).json({schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],detail: "Invalid JSON body",@@ -178,7 +178,7 @@ async function handlePatch(!body.schemas.includes("urn:ietf:params:scim:api:messages:2.0:PatchOp")) {logger.warn(- "Invalid request body. Must include 'schemas' with 'urn:ietf:params:scim:api:messages:2.0:PatchOp'.",+ "[SCIM] Invalid request body. Must include 'schemas' with 'urn:ietf:params:scim:api:messages:2.0:PatchOp'.",body,);return res.status(400).json({@@ -192,7 +192,7 @@ async function handlePatch(// Check for operationsif (!body.Operations || !Array.isArray(body.Operations)) {logger.warn(- "Invalid request body. Must include 'Operations' array with at least one operation.",+ "[SCIM] Invalid request body. Must include 'Operations' array with at least one operation.",body,);return res.status(400).json({@@ -226,6 +226,9 @@ async function handlePatch(},update: {},});+ logger.info(+ `[SCIM] Provisioned user ${user.id} in org ${orgId} via PATCH`,+ );} else {// Deprovision the user by removing them from the organizationawait prisma.organizationMembership.deleteMany({@@ -234,10 +237,13 @@ async function handlePatch(orgId: orgId,},});+ logger.info(+ `[SCIM] Deprovisioned user ${user.id} from org ${orgId} via PATCH`,+ );}} else {logger.error(- "Unsupported operation or invalid value in request body. Only 'replace' with 'active' field is supported.",+ "[SCIM] Unsupported operation or invalid value in request body. Only 'replace' with 'active' field is supported.",op,);return res.status(400).json({@@ -266,7 +272,7 @@ async function handlePut(try {body = JSON.parse(body);} catch (error) {- logger.warn("Failed to parse JSON body", error);+ logger.warn("[SCIM] Failed to parse JSON body", error);return res.status(400).json({schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],detail: "Invalid JSON body",@@ -282,7 +288,7 @@ async function handlePut(!body.schemas.includes("urn:ietf:params:scim:schemas:core:2.0:User")) {logger.warn(- "Invalid request body. Must include 'schemas' with 'urn:ietf:params:scim:schemas:core:2.0:User'.",+ "[SCIM] Invalid request body. Must include 'schemas' with 'urn:ietf:params:scim:schemas:core:2.0:User'.",body,);return res.status(400).json({@@ -326,6 +332,9 @@ async function handlePut(role: role,},});+ logger.info(+ `[SCIM] Provisioned user ${user.id} in org ${orgId} with role ${role} via PUT`,+ );} else {// Deprovision the user by removing them from the organizationawait prisma.organizationMembership.deleteMany({@@ -334,6 +343,9 @@ async function handlePut(orgId: orgId,},});+ logger.info(+ `[SCIM] Deprovisioned user ${user.id} from org ${orgId} via PUT`,+ );}}@@ -369,6 +381,7 @@ async function handleDelete(orgId: orgId,},});+ logger.info(`[SCIM] Removed user ${user.id} from org ${orgId} via DELETE`);// Return empty response with 204 No Content.// With NextJS 15, we can't return NextApiResponse objects anymorediff --git a/web/src/pages/api/public/scim/Users/index.ts b/web/src/pages/api/public/scim/Users/index.tsindex 3898f2a054..c68a34de90 100644--- a/web/src/pages/api/public/scim/Users/index.ts+++ b/web/src/pages/api/public/scim/Users/index.ts@@ -16,7 +16,7 @@ export default async function handler(if (req.method !== "GET" && req.method !== "POST") {logger.error(- `Method not allowed for ${req.method} on /api/public/scim/Users`,+ `[SCIM] Method not allowed for ${req.method} on /api/public/scim/Users`,);return res.status(405).json({schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],@@ -53,7 +53,7 @@ export default async function handler(}logger.info(- `Received request for /api/public/scim/Users with method ${req.method} for orgId ${authCheck.scope.orgId}`,+ `[SCIM] Received request for /api/public/scim/Users with method ${req.method} for orgId ${authCheck.scope.orgId}`,);if (req.method === "GET") {@@ -128,7 +128,7 @@ export default async function handler(Resources: scimUsers,});} catch (error) {- logger.error("Error retrieving SCIM users", error);+ logger.error("[SCIM] Error retrieving users", error);return res.status(500).json({schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],detail: "Internal server error",@@ -144,7 +144,7 @@ export default async function handler(try {body = JSON.parse(body);} catch (error) {- logger.error("Failed to parse JSON body", error);+ logger.error("[SCIM] Failed to parse JSON body", error);return res.status(400).json({schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],detail: "Invalid JSON body",@@ -156,7 +156,7 @@ export default async function handler(const { userName, name, password, displayName, roles } = body;if (!userName) {- logger.warn("userName is required for SCIM user creation");+ logger.warn("[SCIM] userName is required for user creation");return res.status(400).json({schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],detail: "userName is required",@@ -171,7 +171,7 @@ export default async function handler();const parsedRoles = roleSchema.safeParse(roles);if (!parsedRoles.success) {- logger.warn("Invalid roles provided for SCIM user creation");+ logger.warn("[SCIM] Invalid roles provided for user creation");return res.status(400).json({schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],detail: `Invalid roles provided: ${JSON.stringify(roles)}, must be one of OWNER, ADMIN, MEMBER, VIEWER, NONE`,@@ -194,7 +194,7 @@ export default async function handler(if (existingUser.length > 0) {logger.warn(- `User with userName ${userName} already exists in organization ${authCheck.scope.orgId}`,+ `[SCIM] User ${existingUser[0].userId} already exists in organization ${authCheck.scope.orgId}`,);return res.status(409).json({schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],@@ -222,6 +222,9 @@ export default async function handler(role,},});+ logger.info(+ `[SCIM] Assigned user ${user.id} to org ${authCheck.scope.orgId} with role ${role}`,+ );// Return SCIM formatted userreturn res.status(201).json({@@ -245,7 +248,7 @@ export default async function handler(},});} catch (error) {- logger.error("Failed to create SCIM user", error);+ logger.error("[SCIM] Failed to create user", error);return res.status(500).json({schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],detail: "Internal server error",