IRestClient.h (4171B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include <winget/SQLiteVersion.h> 5 #include <winget/Manifest.h> 6 #include <winget/RepositorySearch.h> 7 #include <AppInstallerVersions.h> 8 #include <winget/Authentication.h> 9 #include <vector> 10 11 namespace AppInstaller::Repository::Rest::Schema 12 { 13 // The common interface used to interact with RestAPI responses. 14 struct IRestClient 15 { 16 virtual ~IRestClient() = default; 17 18 struct PackageInfo 19 { 20 std::string PackageIdentifier; 21 std::string PackageName; 22 std::string Publisher; 23 24 PackageInfo(std::string packageIdentifier, std::string packageName, std::string publisher) 25 : PackageIdentifier(std::move(packageIdentifier)), PackageName(std::move(packageName)), Publisher(std::move(publisher)) {} 26 }; 27 28 // NOTE: When changes are made to VersionInfo struct, remember to update the OptimizedSearch path in RestInterface1_0 29 // where VersionInfo struct was directly created from manifest. 30 struct VersionInfo 31 { 32 AppInstaller::Utility::VersionAndChannel VersionAndChannel; 33 std::optional<Manifest::Manifest> Manifest; 34 std::vector<std::string> PackageFamilyNames; 35 std::vector<std::string> ProductCodes; 36 std::vector<AppInstaller::Utility::Version> ArpVersions; 37 std::vector<std::string> UpgradeCodes; 38 39 VersionInfo(AppInstaller::Utility::VersionAndChannel versionAndChannel, std::optional<Manifest::Manifest> manifest, std::vector<std::string> packageFamilyNames = {}, std::vector<std::string> productCodes = {}, std::vector<AppInstaller::Utility::Version> arpVersions = {}, std::vector<std::string> upgradeCodes = {}) 40 : VersionAndChannel(std::move(versionAndChannel)), Manifest(std::move(manifest)), PackageFamilyNames(std::move(packageFamilyNames)), ProductCodes(std::move(productCodes)), ArpVersions(std::move(arpVersions)), UpgradeCodes(std::move(upgradeCodes)) {} 41 }; 42 43 // Minimal information retrieved for any search request. 44 struct Package 45 { 46 PackageInfo PackageInformation; 47 std::vector<VersionInfo> Versions; 48 49 Package(PackageInfo packageInfo, std::vector<VersionInfo> versions) 50 : PackageInformation(std::move(packageInfo)), Versions(std::move(versions)) {} 51 }; 52 53 struct SearchResult 54 { 55 std::vector<Package> Matches; 56 bool Truncated = false; 57 }; 58 59 struct SourceAgreementEntry 60 { 61 std::string Label; 62 std::string Text; 63 std::string Url; 64 }; 65 66 // Information endpoint models 67 struct Information 68 { 69 std::string SourceIdentifier; 70 std::vector<std::string> ServerSupportedVersions; 71 std::string SourceAgreementsIdentifier; 72 std::vector<SourceAgreementEntry> SourceAgreements; 73 std::vector<std::string> UnsupportedPackageMatchFields; 74 std::vector<std::string> RequiredPackageMatchFields; 75 std::vector<std::string> UnsupportedQueryParameters; 76 std::vector<std::string> RequiredQueryParameters; 77 Authentication::AuthenticationInfo Authentication; 78 79 Information() {} 80 Information(std::string sourceId, std::vector<std::string> versions) 81 : SourceIdentifier(std::move(sourceId)), ServerSupportedVersions(std::move(versions)) {} 82 }; 83 84 // Get interface version. 85 virtual Utility::Version GetVersion() const = 0; 86 87 // Get source information. 88 virtual Information GetSourceInformation() const = 0; 89 90 // Performs a search based on the given criteria. 91 virtual SearchResult Search(const SearchRequest& request) const = 0; 92 93 // Gets the manifest for given version 94 virtual std::optional<Manifest::Manifest> GetManifestByVersion(const std::string& packageId, const std::string& version, const std::string& channel) const = 0; 95 96 // Gets the manifests for given query parameters 97 virtual std::vector<Manifest::Manifest> GetManifests(const std::string& packageId, const std::map<std::string_view, std::string>& params = {}) const = 0; 98 }; 99 }