credentials.js 505 B

123456789101112
  1. /**
  2. * Workspace-aware credential lookup.
  3. * Tries `${workspaceId}:${type}` first, falls back to bare `${type}` for
  4. * backwards compatibility with pre-migration documents.
  5. */
  6. async function getWorkspaceCredential(db, type, workspaceId = 'default') {
  7. const scoped = await db.collection('platform_credentials').findOne({ _id: `${workspaceId}:${type}` });
  8. if (scoped) return scoped;
  9. return db.collection('platform_credentials').findOne({ _id: type });
  10. }
  11. module.exports = { getWorkspaceCredential };