validateOfficialNameSource function

String? validateOfficialNameSource(
  1. String name,
  2. PluginSourceConfig source
)

Validate that a marketplace with a reserved name comes from the official source.

Implementation

String? validateOfficialNameSource(String name, PluginSourceConfig source) {
  final normalizedName = name.toLowerCase();
  if (!allowedOfficialMarketplaceNames.contains(normalizedName)) {
    return null;
  }

  if (source.type == 'github') {
    final repo = source.repo ?? '';
    if (!repo.toLowerCase().startsWith('$officialGithubOrg/')) {
      return "The name '$name' is reserved for official Anthropic marketplaces. "
          "Only repositories from 'github.com/$officialGithubOrg/' can use this name.";
    }
    return null;
  }

  if (source.type == 'git' && source.url != null) {
    final url = source.url!.toLowerCase();
    final isHttpsAnthropics = url.contains('github.com/anthropics/');
    final isSshAnthropics = url.contains('git@github.com:anthropics/');
    if (isHttpsAnthropics || isSshAnthropics) {
      return null;
    }
    return "The name '$name' is reserved for official Anthropic marketplaces. "
        "Only repositories from 'github.com/$officialGithubOrg/' can use this name.";
  }

  return "The name '$name' is reserved for official Anthropic marketplaces and "
      "can only be used with GitHub sources from the '$officialGithubOrg' organization.";
}