Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@open-audio-stack/core",
"version": "0.1.53",
"version": "0.1.54",
"description": "Open-source audio plugin management software",
"type": "module",
"main": "./build/index.js",
Expand Down
44 changes: 32 additions & 12 deletions src/classes/ManagerLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
isAdmin,
runCliAsAdmin,
} from '../helpers/file.js';
import { isValidVersion, pathGetSlug, pathGetVersion, toSlug } from '../helpers/utils.js';
import { isValidSlug, isValidVersion, pathGetSlug, pathGetVersion, toSlug } from '../helpers/utils.js';
import { commandExists, getArchitecture, getSystem, isTests } from '../helpers/utilsLocal.js';
import { apiBuffer } from '../helpers/api.js';
import { FileInterface } from '../types/File.js';
Expand Down Expand Up @@ -192,6 +192,12 @@ export class ManagerLocal extends Manager {

async install(slug: string, version?: string) {
this.log('install', slug, version);
// slug/version can originate from remote registry JSON (via sync(), e.g. through
// installAll() iterating every synced package) or from a local project file - never from a
// value the caller has already validated. Reject anything malformed before it can reach the
// elevated command payload built below.
if (!isValidSlug(slug)) throw new Error(`Invalid package slug: ${slug}`);
if (version && !isValidVersion(version)) throw new Error(`Invalid package version: ${version}`);
// Get package information from registry.
const pkg: Package | undefined = this.getPackage(slug);
if (!pkg) throw new Error(`Package ${slug} not found in registry`);
Expand Down Expand Up @@ -229,10 +235,14 @@ export class ManagerLocal extends Manager {

// Elevate permissions if not running as admin.
if (!isAdmin() && !isTests()) {
let command: string = `--appDir "${this.config.get('appDir')}" --operation "install" --type "${this.type}" --id "${slug}"`;
if (version) command += ` --ver "${version}"`;
if (this.debug) command += ` --log`;
await runCliAsAdmin(command);
await runCliAsAdmin({
appDir: this.config.get('appDir') as string,
operation: 'install',
type: this.type,
id: slug,
version,
log: this.debug,
});
const returnedPkg = this.getPackage(slug)?.getVersion(versionNum);
if (returnedPkg) {
if (this.isPackageInstalled(slug, versionNum)) returnedPkg.installed = true;
Expand Down Expand Up @@ -380,9 +390,13 @@ export class ManagerLocal extends Manager {
async installAll() {
// Elevate permissions if not running as admin.
if (!isAdmin() && !isTests()) {
let command: string = `--appDir "${this.config.get('appDir')}" --operation "installAll" --type "${this.type}"`;
if (this.debug) command += ` --log`;
await runCliAsAdmin(command);
await runCliAsAdmin({
appDir: this.config.get('appDir') as string,
operation: 'installAll',
type: this.type,
id: '',
log: this.debug,
});
return this.listPackages();
}

Expand Down Expand Up @@ -497,6 +511,8 @@ export class ManagerLocal extends Manager {
}

async uninstall(slug: string, version?: string) {
if (!isValidSlug(slug)) throw new Error(`Invalid package slug: ${slug}`);
if (version && !isValidVersion(version)) throw new Error(`Invalid package version: ${version}`);
// Get package information from registry.
const pkg: Package | undefined = this.getPackage(slug);
if (!pkg) throw new Error(`Package ${slug} not found in registry`);
Expand All @@ -508,10 +524,14 @@ export class ManagerLocal extends Manager {

// Elevate permissions if not running as admin.
if (!isAdmin() && !isTests()) {
let command: string = `--appDir "${this.config.get('appDir')}" --operation "uninstall" --type "${this.type}" --id "${slug}"`;
if (version) command += ` --ver "${version}"`;
if (this.debug) command += ` --log`;
await runCliAsAdmin(command);
await runCliAsAdmin({
appDir: this.config.get('appDir') as string,
operation: 'uninstall',
type: this.type,
id: slug,
version,
log: this.debug,
});
const returnedPkg = this.getPackage(slug)?.getVersion(versionNum);
if (returnedPkg) {
if (this.isPackageInstalled(slug, versionNum)) returnedPkg.installed = true;
Expand Down
10 changes: 10 additions & 0 deletions src/helpers/admin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// Run when Electron needs elevated privileges
// npm run build && node ./build/helpers/admin.js --operation install --type plugins --id surge-synthesizer/surge
// npm run build && node ./build/helpers/admin.js --operation uninstall --type plugins --id surge-synthesizer/surge
//
// runCliAsAdmin() (helpers/file.ts) invokes this via `--payload <base64url JSON>` rather than
// individual flags, since the values it carries (appDir/id/version) originate from registry
// metadata or local project files and must never be interpolated into a shell command as text.
// The individual --flag form above is still accepted for manual/developer invocation only.

import { RegistryType } from '../types/Registry.js';
import { ManagerLocal } from '../classes/ManagerLocal.js';
Expand All @@ -22,6 +27,11 @@ export function adminArguments(): Arguments {
type: RegistryType.Plugins,
id: 'surge-synthesizer/surge',
};
const payloadIndex = process.argv.indexOf('--payload');
if (payloadIndex !== -1 && process.argv[payloadIndex + 1]) {
const decoded = JSON.parse(Buffer.from(process.argv[payloadIndex + 1], 'base64url').toString('utf8'));
return { ...args, ...decoded };
}
for (let i = 0; i < process.argv.length; i++) {
const arg = process.argv[i];
if (arg === '--appDir') {
Expand Down
Loading
Loading