Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@backstage/integration

Package Overview
Dependencies
Maintainers
4
Versions
967
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@backstage/integration - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

8

CHANGELOG.md
# @backstage/integration
## 0.1.4
### Patch Changes
- 1d1c2860f: Implement readTree on BitBucketUrlReader and getBitbucketDownloadUrl
- 4eafdec4a: Introduce readTree method for GitLab URL Reader
- 178e09323: Validate that integration config contains a valid host
## 0.1.3

@@ -4,0 +12,0 @@

69

dist/index.cjs.js

@@ -13,2 +13,8 @@ 'use strict';

function isValidHost(url) {
const check = new URL("http://example.com");
check.host = url;
return check.host === url;
}
const AZURE_HOST = "dev.azure.com";

@@ -19,2 +25,5 @@ function readAzureIntegrationConfig(config2) {

const token = config2.getOptionalString("token");
if (!isValidHost(host)) {
throw new Error(`Invalid Azure integration config, '${host}' is not a valid host`);
}
return {host, token};

@@ -97,2 +106,5 @@ }

const appPassword = config2.getOptionalString("appPassword");
if (!isValidHost(host)) {
throw new Error(`Invalid Bitbucket integration config, '${host}' is not a valid host`);
}
if (apiBaseUrl) {

@@ -122,2 +134,42 @@ apiBaseUrl = apiBaseUrl.replace(/\/+$/, "");

async function getBitbucketDefaultBranch(url, config2) {
const {name: repoName, owner: project, resource} = parseGitUrl__default['default'](url);
const isHosted = resource === "bitbucket.org";
const branchUrl = isHosted ? `${config2.apiBaseUrl}/repositories/${project}/${repoName}` : `${config2.apiBaseUrl}/projects/${project}/repos/${repoName}/branches/default`;
const response = await fetch__default['default'](branchUrl, getBitbucketRequestOptions(config2));
if (!response.ok) {
const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`;
throw new Error(message);
}
let defaultBranch;
if (isHosted) {
const repoInfo = await response.json();
defaultBranch = repoInfo.mainbranch.name;
} else {
const {displayId} = await response.json();
defaultBranch = displayId;
}
if (!defaultBranch) {
throw new Error(`Failed to read default branch from ${branchUrl}`);
}
return defaultBranch;
}
async function getBitbucketDownloadUrl(url, config2) {
const {
name: repoName,
owner: project,
ref,
protocol,
resource,
filepath
} = parseGitUrl__default['default'](url);
const isHosted = resource === "bitbucket.org";
let branch = ref;
if (!branch) {
branch = await getBitbucketDefaultBranch(url, config2);
}
const path = filepath ? `&path=${encodeURIComponent(filepath)}` : "";
const archiveUrl = isHosted ? `${protocol}://${resource}/${project}/${repoName}/get/${branch}.zip` : `${config2.apiBaseUrl}/projects/${project}/repos/${repoName}/archive?format=zip&at=${branch}&prefix=${project}-${repoName}${path}`;
return archiveUrl;
}
function getBitbucketFileFetchUrl(url, config2) {

@@ -163,2 +215,5 @@ try {

const token = config2.getOptionalString("token");
if (!isValidHost(host)) {
throw new Error(`Invalid GitHub integration config, '${host}' is not a valid host`);
}
if (apiBaseUrl) {

@@ -221,7 +276,17 @@ apiBaseUrl = apiBaseUrl.replace(/\/+$/, "");

const GITLAB_HOST = "gitlab.com";
const GITLAB_API_BASE_URL = "gitlab.com/api/v4";
function readGitLabIntegrationConfig(config2) {
var _a;
const host = (_a = config2.getOptionalString("host")) != null ? _a : GITLAB_HOST;
let apiBaseUrl = config2.getOptionalString("apiBaseUrl");
const token = config2.getOptionalString("token");
return {host, token};
if (!isValidHost(host)) {
throw new Error(`Invalid GitLab integration config, '${host}' is not a valid host`);
}
if (apiBaseUrl) {
apiBaseUrl = apiBaseUrl.replace(/\/+$/, "");
} else if (host === GITLAB_HOST) {
apiBaseUrl = GITLAB_API_BASE_URL;
}
return {host, token, apiBaseUrl};
}

@@ -414,2 +479,4 @@ function readGitLabIntegrationConfigs(configs) {

exports.getAzureRequestOptions = getAzureRequestOptions;
exports.getBitbucketDefaultBranch = getBitbucketDefaultBranch;
exports.getBitbucketDownloadUrl = getBitbucketDownloadUrl;
exports.getBitbucketFileFetchUrl = getBitbucketFileFetchUrl;

@@ -416,0 +483,0 @@ exports.getBitbucketRequestOptions = getBitbucketRequestOptions;

@@ -111,2 +111,17 @@ import { Config } from '@backstage/config';

/**
* Given a URL pointing to a path on a provider, returns the default branch.
*
* @param url A URL pointing to a path
* @param config The relevant provider config
*/
declare function getBitbucketDefaultBranch(url: string, config: BitbucketIntegrationConfig): Promise<string>;
/**
* Given a URL pointing to a path on a provider, returns a URL that is suitable
* for downloading the subtree.
*
* @param url A URL pointing to a path
* @param config The relevant provider config
*/
declare function getBitbucketDownloadUrl(url: string, config: BitbucketIntegrationConfig): Promise<string>;
/**
* Given a URL pointing to a file on a provider, returns a URL that is suitable

@@ -208,2 +223,12 @@ * for fetching the contents of the data.

/**
* The base URL of the API of this provider, e.g. "https://gitlab.com/api/v4",
* with no trailing slash.
*
* May be omitted specifically for GitLab; then it will be deduced.
*
* The API will always be preferred if both its base URL and a token are
* present.
*/
apiBaseUrl?: string;
/**
* The authorization token to use for requests this provider.

@@ -293,2 +318,2 @@ *

export { AzureIntegrationConfig, BitbucketIntegrationConfig, GitHubIntegrationConfig, GitLabIntegrationConfig, ScmIntegration, ScmIntegrationRegistry, ScmIntegrations, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs };
export { AzureIntegrationConfig, BitbucketIntegrationConfig, GitHubIntegrationConfig, GitLabIntegrationConfig, ScmIntegration, ScmIntegrationRegistry, ScmIntegrations, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs };
import parseGitUrl from 'git-url-parse';
import fetch from 'cross-fetch';
function isValidHost(url) {
const check = new URL("http://example.com");
check.host = url;
return check.host === url;
}
const AZURE_HOST = "dev.azure.com";

@@ -9,2 +15,5 @@ function readAzureIntegrationConfig(config2) {

const token = config2.getOptionalString("token");
if (!isValidHost(host)) {
throw new Error(`Invalid Azure integration config, '${host}' is not a valid host`);
}
return {host, token};

@@ -87,2 +96,5 @@ }

const appPassword = config2.getOptionalString("appPassword");
if (!isValidHost(host)) {
throw new Error(`Invalid Bitbucket integration config, '${host}' is not a valid host`);
}
if (apiBaseUrl) {

@@ -112,2 +124,42 @@ apiBaseUrl = apiBaseUrl.replace(/\/+$/, "");

async function getBitbucketDefaultBranch(url, config2) {
const {name: repoName, owner: project, resource} = parseGitUrl(url);
const isHosted = resource === "bitbucket.org";
const branchUrl = isHosted ? `${config2.apiBaseUrl}/repositories/${project}/${repoName}` : `${config2.apiBaseUrl}/projects/${project}/repos/${repoName}/branches/default`;
const response = await fetch(branchUrl, getBitbucketRequestOptions(config2));
if (!response.ok) {
const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`;
throw new Error(message);
}
let defaultBranch;
if (isHosted) {
const repoInfo = await response.json();
defaultBranch = repoInfo.mainbranch.name;
} else {
const {displayId} = await response.json();
defaultBranch = displayId;
}
if (!defaultBranch) {
throw new Error(`Failed to read default branch from ${branchUrl}`);
}
return defaultBranch;
}
async function getBitbucketDownloadUrl(url, config2) {
const {
name: repoName,
owner: project,
ref,
protocol,
resource,
filepath
} = parseGitUrl(url);
const isHosted = resource === "bitbucket.org";
let branch = ref;
if (!branch) {
branch = await getBitbucketDefaultBranch(url, config2);
}
const path = filepath ? `&path=${encodeURIComponent(filepath)}` : "";
const archiveUrl = isHosted ? `${protocol}://${resource}/${project}/${repoName}/get/${branch}.zip` : `${config2.apiBaseUrl}/projects/${project}/repos/${repoName}/archive?format=zip&at=${branch}&prefix=${project}-${repoName}${path}`;
return archiveUrl;
}
function getBitbucketFileFetchUrl(url, config2) {

@@ -153,2 +205,5 @@ try {

const token = config2.getOptionalString("token");
if (!isValidHost(host)) {
throw new Error(`Invalid GitHub integration config, '${host}' is not a valid host`);
}
if (apiBaseUrl) {

@@ -211,7 +266,17 @@ apiBaseUrl = apiBaseUrl.replace(/\/+$/, "");

const GITLAB_HOST = "gitlab.com";
const GITLAB_API_BASE_URL = "gitlab.com/api/v4";
function readGitLabIntegrationConfig(config2) {
var _a;
const host = (_a = config2.getOptionalString("host")) != null ? _a : GITLAB_HOST;
let apiBaseUrl = config2.getOptionalString("apiBaseUrl");
const token = config2.getOptionalString("token");
return {host, token};
if (!isValidHost(host)) {
throw new Error(`Invalid GitLab integration config, '${host}' is not a valid host`);
}
if (apiBaseUrl) {
apiBaseUrl = apiBaseUrl.replace(/\/+$/, "");
} else if (host === GITLAB_HOST) {
apiBaseUrl = GITLAB_API_BASE_URL;
}
return {host, token, apiBaseUrl};
}

@@ -400,3 +465,3 @@ function readGitLabIntegrationConfigs(configs) {

export { ScmIntegrations, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs };
export { ScmIntegrations, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs };
//# sourceMappingURL=index.esm.js.map

9

package.json
{
"name": "@backstage/integration",
"version": "0.1.3",
"version": "0.1.4",
"main": "dist/index.cjs.js",

@@ -34,6 +34,7 @@ "types": "dist/index.d.ts",

"cross-fetch": "^3.0.6",
"git-url-parse": "^11.4.0"
"git-url-parse": "^11.4.3"
},
"devDependencies": {
"@backstage/cli": "^0.4.1",
"@backstage/cli": "^0.4.2",
"@backstage/test-utils": "^0.1.5",
"@types/jest": "^26.0.7",

@@ -47,4 +48,4 @@ "msw": "^0.21.2"

"configSchema": "config.d.ts",
"gitHead": "f94ac54a7fc4b547aedd7cec55ddcbd5f24bb1ad",
"gitHead": "ebbc133eaa0a4883db97572cca4b1c94f680d95e",
"module": "dist/index.esm.js"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc