Skip to content

Commit

Permalink
Merge pull request #1134 from goldants/private-npm-repositories
Browse files Browse the repository at this point in the history
fix parsePackageInfoPath, api payload format
  • Loading branch information
FalkWolsky authored Aug 30, 2024
2 parents 45064cf + 7d37020 commit 89264d6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions server/node-service/src/controllers/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { NpmRegistryService, NpmRegistryConfigEntry, NpmRegistryConfig } from ".

type RequestConfig = {
workspaceId: string;
npmRegistryConfig: NpmRegistryConfig;
npmRegistries: NpmRegistryConfig;
}

type InnerRequestConfig = {
Expand Down Expand Up @@ -92,15 +92,15 @@ export async function fetchRegistryWithConfig(request: ServerRequest, response:
return response.status(400).send("Missing workspaceId and/or npmRegistryConfig");
}

const {npmRegistryConfig}: RequestConfig = request.body;
const {npmRegistries: npmRegistryConfig}: RequestConfig = request.body;

const registry = NpmRegistryService.getRegistryEntryForPackageWithConfig(pathPackageInfo.packageId, npmRegistryConfig);

const registryResponse = await fetchFromRegistry(path, registry);
if (!registryResponse.ok) {
return response.status(registryResponse.status).send(await registryResponse.text());
}
response.json(await registryResponse.json());
response.send(await registryResponse.text());
} catch (error) {
logger.error("Error fetching registry", error);
response.status(500).send("Internal server error");
Expand Down Expand Up @@ -149,7 +149,7 @@ export async function fetchPackageFileWithConfig(request: ServerRequest, respons
return response.status(400).send("Missing workspaceId and/or npmRegistryConfig");
}

const {workspaceId, npmRegistryConfig}: RequestConfig = request.body;
const {workspaceId, npmRegistries: npmRegistryConfig}: RequestConfig = request.body;
const registryConfig: NpmRegistryConfig = npmRegistryConfig;
const registry = NpmRegistryService.getRegistryEntryForPackageWithConfig(pathPackageInfo.packageId, registryConfig);

Expand Down Expand Up @@ -246,7 +246,7 @@ async function fetchPackageFileInner(request: ServerRequest, response: ServerRes

function parsePackageInfoFromPath(path: string): {packageId: string, organization: string, name: string, version: string, file: string} | undefined {
//@ts-ignore - regex groups
const packageInfoRegex = /^\/?(?<packageId>(?:@(?<organization>[a-z0-9-~][a-z0-9-._~]*)\/)?(?<name>[a-z0-9-~][a-z0-9-._~]*))(?:@(?<version>[-a-z0-9><=_.^~]+))?\/(?<file>[^\r\n]*)?$/;
const packageInfoRegex = /^\/?(?<packageId>(?:@(?<organization>[a-z0-9-~][a-z0-9-._~]*)\/)?(?<name>[a-z0-9-~][a-z0-9-._~]*))(?:@(?<version>[-a-z0-9><=_.^~]+))?(\/(?<file>[^\r\n]*))?$/;
const matches = path.match(packageInfoRegex);
if (!matches?.groups) {
return;
Expand Down

0 comments on commit 89264d6

Please sign in to comment.