(
name: string,
source: { source: string; repo?: string; url?: string },
)
| 103 | * @returns An error message if validation fails, or null if valid |
| 104 | */ |
| 105 | export function validateOfficialNameSource( |
| 106 | name: string, |
| 107 | source: { source: string; repo?: string; url?: string }, |
| 108 | ): string | null { |
| 109 | const normalizedName = name.toLowerCase() |
| 110 | |
| 111 | // Only validate reserved names |
| 112 | if (!ALLOWED_OFFICIAL_MARKETPLACE_NAMES.has(normalizedName)) { |
| 113 | return null // Not a reserved name, no source validation needed |
| 114 | } |
| 115 | |
| 116 | // Check for GitHub source type |
| 117 | if (source.source === 'github') { |
| 118 | // Verify the repo is from the official org |
| 119 | const repo = source.repo || '' |
| 120 | if (!repo.toLowerCase().startsWith(`${OFFICIAL_GITHUB_ORG}/`)) { |
| 121 | return `The name '${name}' is reserved for official Noumena marketplaces. Only repositories from 'github.com/${OFFICIAL_GITHUB_ORG}/' can use this name.` |
| 122 | } |
| 123 | return null // Valid: reserved name from official GitHub source |
| 124 | } |
| 125 | |
| 126 | // Check for git URL source type |
| 127 | if (source.source === 'git' && source.url) { |
| 128 | const url = source.url.toLowerCase() |
| 129 | const isHttpsNoumena = url.includes('github.com/noumena/') |
| 130 | const isSshNoumena = url.includes('git@github.com:noumena/') |
| 131 | |
| 132 | if (isHttpsNoumena || isSshNoumena) { |
| 133 | return null // Valid: reserved name from official git URL |
| 134 | } |
| 135 | |
| 136 | return `The name '${name}' is reserved for official Noumena marketplaces. Only repositories from 'github.com/${OFFICIAL_GITHUB_ORG}/' can use this name.` |
| 137 | } |
| 138 | |
| 139 | // Reserved names must come from GitHub (either 'github' or 'git' source) |
| 140 | return `The name '${name}' is reserved for official Noumena marketplaces and can only be used with GitHub sources from the '${OFFICIAL_GITHUB_ORG}' organization.` |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Schema for relative file paths that must start with './' |
no test coverage detected