@acarmisc/backstage-plugin-litellm-backend 0.7.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -168,8 +168,7 @@ async function provisionUser(client, userId, defaults, profile, backstageEntity,
168
168
  }),
169
169
  },
170
170
  };
171
- logger.info(`Provisioning new LiteLLM user for Backstage identity: ${userId}` +
172
- (profile.email ? ` (email=${profile.email})` : ''));
171
+ logger.info(`Provisioning new LiteLLM user for Backstage identity: ${userId}${profile.email ? ` (email=${profile.email})` : ''}`);
173
172
  try {
174
173
  await client.createUser(payload);
175
174
  // Defensive /user/update: LiteLLM's /user/new upsert path has been
package/dist/router.js CHANGED
@@ -189,12 +189,18 @@ async function createRouter(options) {
189
189
  ? (0, provisioning_1.toLiteLLMUserId)(tokenEntityRef, userIdDomain)
190
190
  : req.query.user_id;
191
191
  if (!userId) {
192
- throw { status: 403, body: { error: 'Cannot verify key ownership without an authenticated user' } };
192
+ throw Object.assign(new Error('Cannot verify key ownership without an authenticated user'), {
193
+ status: 403,
194
+ body: { error: 'Cannot verify key ownership without an authenticated user' },
195
+ });
193
196
  }
194
197
  const ownKeys = await client.listKeys(userId);
195
198
  const owns = ownKeys.some(k => (k.token ?? k.key) === keyId);
196
199
  if (!owns) {
197
- throw { status: 403, body: { error: 'Access denied: key does not belong to the caller' } };
200
+ throw Object.assign(new Error('Access denied: key does not belong to the caller'), {
201
+ status: 403,
202
+ body: { error: 'Access denied: key does not belong to the caller' },
203
+ });
198
204
  }
199
205
  return { tokenEntityRef, userId };
200
206
  }
@@ -287,6 +293,16 @@ async function createRouter(options) {
287
293
  });
288
294
  return;
289
295
  }
296
+ // Preserve upstream LiteLLM status + structured error (e.g. a 400 with
297
+ // param "key_alias" for a duplicate alias) so the frontend can
298
+ // distinguish "alias taken" from a genuine server error.
299
+ if (error instanceof client_1.LiteLLMUpstreamError) {
300
+ res.status(error.status).json({
301
+ error: error.message,
302
+ ...(error.param ? { param: error.param } : {}),
303
+ });
304
+ return;
305
+ }
290
306
  logger.error('Failed to generate key', error);
291
307
  res.status(500).json({ error: error.message });
292
308
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acarmisc/backstage-plugin-litellm-backend",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "description": "The Backstage backend plugin for LiteLLM governance",
5
5
  "backstage": {
6
6
  "role": "backend-plugin",
@@ -29,6 +29,8 @@
29
29
  ],
30
30
  "scripts": {
31
31
  "build": "node build.js && tsc -p tsconfig.json",
32
+ "lint": "eslint src --ext .ts",
33
+ "test": "tsc -p tsconfig.test.json && node --test dist-test/**/*.test.js dist-test/*.test.js",
32
34
  "prepack": "npm run build",
33
35
  "postpack": ""
34
36
  },