package_manager_backend/package_manager

TODO@P3: Methods to query for all installed packages.

actor class PackageManager({ packageManager : Principal; mainIndirect : Principal; simpleIndirect : Principal; battery : Principal; user : Principal; installationId : Common.InstallationId; userArg : Blob })

type HalfInstalledPackageInfo = { package : Common.PackageInfo; packageRepoCanister : Principal; modulesInstalledByDefault : HashMap.HashMap<Text, Principal>; minInstallationId : Nat; afterInstallCallback : ?{ canister : Principal; name : Text; data : Blob }; bootstrapping : Bool; var remainingModules : Nat; arg : Blob; initArg : ?Blob }

type SharedHalfInstalledPackageInfo = { package : Common.SharedPackageInfo; packageRepoCanister : Principal; modulesInstalledByDefault : [(Text, Principal)]; minInstallationId : Nat; afterInstallCallback : ?{ canister : Principal; name : Text; data : Blob }; bootstrapping : Bool; remainingModules : Nat; arg : Blob; initArg : ?Blob }

type HalfUninstalledPackageInfo = { installationId : Common.InstallationId; package : Common.PackageInfo; var remainingModules : Nat }

type SharedHalfUninstalledPackageInfo = { installationId : Common.InstallationId; package : Common.SharedPackageInfo; remainingModules : Nat }

type HalfUpgradedPackageInfo = { installationId : Common.InstallationId; package : Common.PackageInfo; newRepo : Principal; modulesInstalledByDefault : HashMap.HashMap<Text, Principal>; modulesToDelete : [(Text, Principal)]; var remainingModules : Nat; arg : Blob; initArg : ?Blob }

type SharedHalfUpgradedPackageInfo = { installationId : Common.InstallationId; package : Common.SharedPackageInfo; newRepo : Principal; modulesInstalledByDefault : [(Text, Principal)]; modulesToDelete : [(Text, Principal)]; remainingModules : Nat; arg : Blob; initArg : ?Blob }

public func init({ }) : async ()

public func setOwners(newOwners : [Principal]) : async ()

public func addOwner(newOwner : Principal) : async ()

public func removeOwner(oldOwner : Principal) : async ()

public func getOwners() : async [Principal]

public func isAllInitialized() : async ()

public func setMainIndirect(main_indirect_v : MainIndirect.MainIndirect) : async ()

public func installPackages({ packages : [{ packageName : Common.PackageName; version : Common.Version; repo : Common.RepositoryRO; arg : Blob; initArg : ?Blob }]; user : Principal; afterInstallCallback : ?{ canister : Principal; name : Text; data : Blob } }) : async { minInstallationId : Common.InstallationId }

public func uninstallPackages({ packages : [Common.InstallationId]; user : Principal }) : async { minUninstallationId : Common.UninstallationId }

public func upgradePackages({ packages : [{ installationId : Common.InstallationId; packageName : Common.PackageName; version : Common.Version; repo : Common.RepositoryRO; arg : Blob; initArg : ?Blob }]; user : Principal; afterUpgradeCallback : ?{ canister : Principal; name : Text; data : Blob } }) : async { minUpgradeId : Common.UpgradeId }

We first add new and upgrade existing modules (including executing hooks) and only then delete modules to be deleted. That's because deleted modules may contain important data that needs to be imported. Also having deleting modules at the end does not prevent the package to start fully function before this.

public func upgradeStart({ minUpgradeId : Common.UpgradeId; user : Principal; packages : [{ installationId : Common.InstallationId; package : Common.SharedPackageInfo; repo : Common.RepositoryRO; arg : Blob; initArg : ?Blob }]; afterUpgradeCallback : ?{ canister : Principal; name : Text; data : Blob } }) : async ()

Internal.

public func onUpgradeOrInstallModule({ upgradeId : Common.UpgradeId; moduleName : Text; canister_id : Principal; afterUpgradeCallback : ?{ canister : Principal; name : Text; data : Blob } }) : async ()

Internal

public func onDeleteCanister({ uninstallationId : Common.UninstallationId }) : async ()

Internal

public func facilitateBootstrap({ packageName : Common.PackageName; version : Common.Version; repo : Common.RepositoryRO; arg : Blob; initArg : ?Blob; user : Principal; mainIndirect : Principal; preinstalledModules : [(Text, Principal)] }) : async { minInstallationId : Common.InstallationId }

Internal used for bootstrapping.

public func installStart({ minInstallationId : Common.InstallationId; afterInstallCallback : ?{ canister : Principal; name : Text; data : Blob }; user : Principal; packages : [{ package : Common.SharedPackageInfo; repo : Common.RepositoryRO; preinstalledModules : [(Text, Principal)]; arg : Blob; initArg : ?Blob }]; bootstrapping : Bool })

Internal.

Initialize installation process object.

public func onInstallCode({ installationId : Common.InstallationId; canister : Principal; moduleNumber : Nat; moduleName : ?Text; user : Principal; module_ : Common.SharedModule; packageManager : Principal; afterInstallCallback : ?{ canister : Principal; name : Text; data : Blob } }) : async ()

Internal

public func getAllCanisters() : async [({ packageName : Text; guid : Blob }, [(Text, Principal)])]

Returns all (default installed and additional) modules canisters. Internal.

public func getInstalledPackage(id : Common.InstallationId) : async Common.SharedInstalledPackageInfo

public func getModulePrincipal(installationId : Common.InstallationId, moduleName : Text) : async Principal

Note that it applies only to default installed modules and fails for additional modules.

public func getInstalledPackagesInfoByName(name : Text, guid : Blob) : async { all : [Common.SharedInstalledPackageInfo]; default : Common.InstallationId }

public func getAllInstalledPackages() : async [(Common.InstallationId, Common.SharedInstalledPackageInfo)]

public func getHalfInstalledPackages() : async [{ installationId : Common.InstallationId; package : Common.SharedPackageInfo }]

Internal.

public func getHalfUninstalledPackages() : async [{ uninstallationId : Common.UninstallationId; package : Common.SharedPackageInfo }]

Internal.

public func getHalfUpgradedPackages() : async [{ upgradeId : Common.UpgradeId; package : Common.SharedPackageInfo }]

Internal.

public func getHalfInstalledPackageModulesById(installationId : Common.InstallationId) : async [(Text, Principal)]

TODO@P3: very unstable API.

public func setPinned(installationId : Common.InstallationId, pinned : Bool) : async ()

public func removeStalled({ install : [Common.InstallationId]; uninstall : [Common.UninstallationId]; upgrade : [Common.UpgradeId] }) : async ()

public func userAccountText() : async Principal

public func userBalance() : async Nat

public func getNewCanisterCycles() : async Nat

The total cycles amount, including canister creation fee.

public func addRepository(canister : Principal, name : Text) : async ()

public func removeRepository(canister : Principal) : async ()

public func getRepositories() : async [{ canister : Principal; name : Text }]

public func setDefaultInstalledPackage(
  name : Common.PackageName,
  guid : Blob,
  installationId : Common.InstallationId
) : async ()

public func withdrawCycles(amount : Nat, payee : Principal) : async ()

public func startModularUpgrade({ installationId : Common.InstallationId; packageName : Common.PackageName; version : Common.Version; repo : Common.RepositoryRO; arg : Blob; initArg : ?Blob; user : Principal }) : async { upgradeId : Common.UpgradeId; totalModules : Nat; modulesToUpgrade : [Text]; modulesToDelete : [(Text, Principal)] }

New API for step-by-step upgrades Initiates an upgrade process and returns upgrade information

public func upgradeModule({ upgradeId : Common.UpgradeId; moduleName : Text; user : Principal }) : async { completed : Bool }

Upgrade a specific module as part of modular upgrade

public func getModularUpgradeStatus(upgradeId : Common.UpgradeId) : async { upgradeId : Common.UpgradeId; installationId : Common.InstallationId; packageName : Text; completedModules : Nat; totalModules : Nat; remainingModules : Nat; isCompleted : Bool }

Get the current status of a modular upgrade

public func completeModularUpgrade(upgradeId : Common.UpgradeId) : async ()

Mark all modules as upgraded for a modular upgrade (used for frontend-driven upgrades)