New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@backstage/integration

Package Overview
Dependencies
Maintainers
4
Versions
984
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.4.0 to 0.5.0

6

CHANGELOG.md
# @backstage/integration
## 0.5.0
### Minor Changes
- 491f3a0ec: Make `ScmIntegration.resolveUrl` mandatory.
## 0.4.0

@@ -4,0 +10,0 @@

210

dist/index.cjs.js

@@ -43,2 +43,21 @@ 'use strict';

}
function defaultScmResolveUrl(options) {
const {url, base} = options;
try {
new URL(url);
return url;
} catch {
}
let updated;
if (url.startsWith("/")) {
const {filepath} = parseGitUrl__default['default'](base);
updated = new URL(base);
const repoRootPath = updated.pathname.substring(0, updated.pathname.length - filepath.length).replace(/\/+$/, "");
updated.pathname = `${repoRootPath}${url}`;
} else {
updated = new URL(url, base);
}
updated.search = new URL(base).search;
return updated.toString();
}

@@ -63,2 +82,42 @@ const AZURE_HOST = "dev.azure.com";

const AzureIntegration2 = class {
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}
get type() {
return "azure";
}
get title() {
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
resolveUrl(options) {
const {url, base} = options;
try {
new URL(url);
return url;
} catch {
}
const parsed = parseGitUrl__default['default'](base);
const {organization, owner, name, filepath} = parsed;
if (!organization || !owner || !name) {
return new URL(url, base).toString();
}
const path = (filepath == null ? void 0 : filepath.replace(/^\//, "")) || "";
const mockBaseUrl = new URL(`https://a.com/${path}`);
const updatedPath = new URL(url, mockBaseUrl).pathname;
const newUrl = new URL(base);
newUrl.searchParams.set("path", updatedPath);
return newUrl.toString();
}
};
let AzureIntegration = AzureIntegration2;
AzureIntegration.factory = ({config: config2}) => {
var _a;
const configs = readAzureIntegrationConfigs((_a = config2.getOptionalConfigArray("integrations.azure")) != null ? _a : []);
return basicIntegrations(configs.map((c) => new AzureIntegration2(c)), (i) => i.config.host);
};
function getAzureFileFetchUrl(url) {

@@ -194,2 +253,28 @@ var _a;

const BitbucketIntegration2 = class {
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}
get type() {
return "bitbucket";
}
get title() {
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
resolveUrl(options) {
return defaultScmResolveUrl(options);
}
};
let BitbucketIntegration = BitbucketIntegration2;
BitbucketIntegration.factory = ({
config: config2
}) => {
var _a;
const configs = readBitbucketIntegrationConfigs((_a = config2.getOptionalConfigArray("integrations.bitbucket")) != null ? _a : []);
return basicIntegrations(configs.map((c) => new BitbucketIntegration2(c)), (i) => i.config.host);
};
async function getBitbucketDefaultBranch(url, config2) {

@@ -480,2 +565,26 @@ const {name: repoName, owner: project, resource} = parseGitUrl__default['default'](url);

const GitHubIntegration2 = class {
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}
get type() {
return "github";
}
get title() {
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
resolveUrl(options) {
return defaultScmResolveUrl(options);
}
};
let GitHubIntegration = GitHubIntegration2;
GitHubIntegration.factory = ({config: config2}) => {
var _a;
const configs = readGitHubIntegrationConfigs((_a = config2.getOptionalConfigArray("integrations.github")) != null ? _a : []);
return basicIntegrations(configs.map((c) => new GitHubIntegration2(c)), (i) => i.config.host);
};
const GITLAB_HOST = "gitlab.com";

@@ -592,3 +701,3 @@ const GITLAB_API_BASE_URL = "https://gitlab.com/api/v4";

const AzureIntegration2 = class {
const GitLabIntegration2 = class {
constructor(integrationConfig) {

@@ -598,3 +707,3 @@ this.integrationConfig = integrationConfig;

get type() {
return "azure";
return "gitlab";
}

@@ -608,86 +717,5 @@ get title() {

resolveUrl(options) {
const {url, base} = options;
try {
new URL(url);
return url;
} catch {
}
const parsed = parseGitUrl__default['default'](base);
const {organization, owner, name, filepath} = parsed;
if (!organization || !owner || !name) {
return new URL(url, base).toString();
}
const path = (filepath == null ? void 0 : filepath.replace(/^\//, "")) || "";
const mockBaseUrl = new URL(`https://a.com/${path}`);
const updatedPath = new URL(url, mockBaseUrl).pathname;
const newUrl = new URL(base);
newUrl.searchParams.set("path", updatedPath);
return newUrl.toString();
return defaultScmResolveUrl(options);
}
};
let AzureIntegration = AzureIntegration2;
AzureIntegration.factory = ({config: config2}) => {
var _a;
const configs = readAzureIntegrationConfigs((_a = config2.getOptionalConfigArray("integrations.azure")) != null ? _a : []);
return basicIntegrations(configs.map((c) => new AzureIntegration2(c)), (i) => i.config.host);
};
const BitbucketIntegration2 = class {
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}
get type() {
return "bitbucket";
}
get title() {
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
};
let BitbucketIntegration = BitbucketIntegration2;
BitbucketIntegration.factory = ({
config: config2
}) => {
var _a;
const configs = readBitbucketIntegrationConfigs((_a = config2.getOptionalConfigArray("integrations.bitbucket")) != null ? _a : []);
return basicIntegrations(configs.map((c) => new BitbucketIntegration2(c)), (i) => i.config.host);
};
const GitHubIntegration2 = class {
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}
get type() {
return "github";
}
get title() {
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
};
let GitHubIntegration = GitHubIntegration2;
GitHubIntegration.factory = ({config: config2}) => {
var _a;
const configs = readGitHubIntegrationConfigs((_a = config2.getOptionalConfigArray("integrations.github")) != null ? _a : []);
return basicIntegrations(configs.map((c) => new GitHubIntegration2(c)), (i) => i.config.host);
};
const GitLabIntegration2 = class {
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}
get type() {
return "gitlab";
}
get title() {
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
};
let GitLabIntegration = GitLabIntegration2;

@@ -734,13 +762,17 @@ GitLabIntegration.factory = ({config: config2}) => {

resolveUrl(options) {
var _a;
const resolve = (_a = this.byUrl(options.base)) == null ? void 0 : _a.resolveUrl;
if (!resolve) {
return new URL(options.url, options.base).toString();
const integration = this.byUrl(options.base);
if (!integration) {
return defaultScmResolveUrl(options);
}
return resolve(options);
return integration.resolveUrl(options);
}
}
exports.AzureIntegration = AzureIntegration;
exports.BitbucketIntegration = BitbucketIntegration;
exports.GitHubIntegration = GitHubIntegration;
exports.GitLabIntegration = GitLabIntegration;
exports.GithubCredentialsProvider = GithubCredentialsProvider;
exports.ScmIntegrations = ScmIntegrations;
exports.defaultScmResolveUrl = defaultScmResolveUrl;
exports.getAzureCommitsUrl = getAzureCommitsUrl;

@@ -747,0 +779,0 @@ exports.getAzureDownloadUrl = getAzureDownloadUrl;

import { Config } from '@backstage/config';
/**
* The configuration parameters for a single Azure provider.
*/
declare type AzureIntegrationConfig = {
/**
* The host of the target that this matches on, e.g. "dev.azure.com".
*
* Currently only "dev.azure.com" is supported.
*/
host: string;
/**
* The authorization token to use for requests.
*
* If no token is specified, anonymous access is used.
*/
token?: string;
};
/**
* Reads a single Azure integration config.
*
* @param config The config object of a single integration
*/
declare function readAzureIntegrationConfig(config: Config): AzureIntegrationConfig;
/**
* Reads a set of Azure integration configs, and inserts some defaults for
* public Azure if not specified.
*
* @param configs All of the integration config objects
*/
declare function readAzureIntegrationConfigs(configs: Config[]): AzureIntegrationConfig[];
/**
* Given a URL pointing to a file on a provider, returns a URL that is suitable
* for fetching the contents of the data.
*
* Converts
* from: https://dev.azure.com/{organization}/{project}/_git/reponame?path={path}&version=GB{commitOrBranch}&_a=contents
* to: https://dev.azure.com/{organization}/{project}/_apis/git/repositories/reponame/items?path={path}&version={commitOrBranch}
*
* @param url A URL pointing to a file
*/
declare function getAzureFileFetchUrl(url: string): 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
*/
declare function getAzureDownloadUrl(url: string): string;
/**
* Given a URL, return the API URL to fetch commits on the branch.
*
* @param url A URL pointing to a repository or a sub-path
*/
declare function getAzureCommitsUrl(url: string): string;
/**
* Gets the request options necessary to make requests to a given provider.
*
* @param config The relevant provider config
*/
declare function getAzureRequestOptions(config: AzureIntegrationConfig, additionalHeaders?: Record<string, string>): RequestInit;
/**
* The configuration parameters for a single Bitbucket API provider.

@@ -116,35 +54,14 @@ */

/**
* 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
* for fetching the contents of the data.
*
* Converts
* from: https://bitbucket.org/orgname/reponame/src/master/file.yaml
* to: https://api.bitbucket.org/2.0/repositories/orgname/reponame/src/master/file.yaml
*
* @param url A URL pointing to a file
* @param config The relevant provider config
*/
declare function getBitbucketFileFetchUrl(url: string, config: BitbucketIntegrationConfig): string;
/**
* Gets the request options necessary to make requests to a given provider.
*
* @param config The relevant provider config
*/
declare function getBitbucketRequestOptions(config: BitbucketIntegrationConfig): RequestInit;
declare class BitbucketIntegration implements ScmIntegration {
private readonly integrationConfig;
static factory: ScmIntegrationsFactory<BitbucketIntegration>;
constructor(integrationConfig: BitbucketIntegrationConfig);
get type(): string;
get title(): string;
get config(): BitbucketIntegrationConfig;
resolveUrl(options: {
url: string;
base: string;
}): string;
}

@@ -233,45 +150,13 @@ /**

/**
* Given a URL pointing to a file on a provider, returns a URL that is suitable
* for fetching the contents of the data.
*
* Converts
* from: https://github.com/a/b/blob/branchname/path/to/c.yaml
* to: https://api.github.com/repos/a/b/contents/path/to/c.yaml?ref=branchname
* or: https://raw.githubusercontent.com/a/b/branchname/c.yaml
*
* @param url A URL pointing to a file
* @param config The relevant provider config
*/
declare function getGitHubFileFetchUrl(url: string, config: GitHubIntegrationConfig): string;
/**
* Gets the request options necessary to make requests to a given provider.
*
* @param config The relevant provider config
*/
declare function getGitHubRequestOptions(config: GitHubIntegrationConfig): RequestInit;
declare type GithubCredentials = {
headers?: {
[name: string]: string;
};
token?: string;
};
declare class GithubCredentialsProvider {
private readonly githubAppCredentialsMux;
private readonly token?;
static create(config: GitHubIntegrationConfig): GithubCredentialsProvider;
private constructor();
/**
* Returns GithubCredentials for requested url.
* Consecutive calls to this method with the same url will return cached credentials.
* The shortest lifetime for a token returned is 10 minutes.
* @param opts containing the organization or repository url
* @returns {Promise} of @type {GithubCredentials}.
* @example
* const { token, headers } = await getCredentials({url: 'github.com/backstage/foobar'})
*/
getCredentials(opts: {
declare class GitHubIntegration implements ScmIntegration {
private readonly integrationConfig;
static factory: ScmIntegrationsFactory<GitHubIntegration>;
constructor(integrationConfig: GitHubIntegrationConfig);
get type(): string;
get title(): string;
get config(): GitHubIntegrationConfig;
resolveUrl(options: {
url: string;
}): Promise<GithubCredentials>;
base: string;
}): string;
}

@@ -325,42 +210,2 @@

/**
* Given a URL pointing to a file on a provider, returns a URL that is suitable
* for fetching the contents of the data.
*
* Converts
* from: https://gitlab.example.com/a/b/blob/master/c.yaml
* to: https://gitlab.example.com/a/b/raw/master/c.yaml
* -or-
* from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath
* to: https://gitlab.com/api/v4/projects/projectId/repository/files/filepath?ref=branch
*
* @param url A URL pointing to a file
* @param config The relevant provider config
*/
declare function getGitLabFileFetchUrl(url: string, config: GitLabIntegrationConfig): Promise<string>;
/**
* Gets the request options necessary to make requests to a given provider.
*
* @param config The relevant provider config
*/
declare function getGitLabRequestOptions(config: GitLabIntegrationConfig): RequestInit;
declare class BitbucketIntegration implements ScmIntegration {
private readonly integrationConfig;
static factory: ScmIntegrationsFactory<BitbucketIntegration>;
constructor(integrationConfig: BitbucketIntegrationConfig);
get type(): string;
get title(): string;
get config(): BitbucketIntegrationConfig;
}
declare class GitHubIntegration implements ScmIntegration {
private readonly integrationConfig;
static factory: ScmIntegrationsFactory<GitHubIntegration>;
constructor(integrationConfig: GitHubIntegrationConfig);
get type(): string;
get title(): string;
get config(): GitHubIntegrationConfig;
}
declare class GitLabIntegration implements ScmIntegration {

@@ -373,2 +218,6 @@ private readonly integrationConfig;

get config(): GitLabIntegrationConfig;
resolveUrl(options: {
url: string;
base: string;
}): string;
}

@@ -390,12 +239,17 @@

/**
* Works like the two-argument form of the URL constructor, resolving an
* absolute or relative URL in relation to a base URL.
* Resolves an absolute or relative URL in relation to a base URL.
*
* If this method is not implemented, the URL constructor is used instead for
* URLs that match this integration.
* This method is adapted for use within SCM systems, so relative URLs are
* within the context of the root of the hierarchy pointed to by the base
* URL.
*
* For example, if the base URL is `<repo root url>/folder/a.yaml`, i.e.
* within the file tree of a certain repo, an absolute path of `/b.yaml` does
* not resolve to `https://hostname/b.yaml` but rather to
* `<repo root url>/b.yaml` inside the file tree of that same repo.
*
* @param options.url The (absolute or relative) URL or path to resolve
* @param options.base The base URL onto which this resolution happens
*/
resolveUrl?(options: {
resolveUrl(options: {
url: string;

@@ -435,5 +289,13 @@ base: string;

/**
* Works like the two-argument form of the URL constructor, resolving an
* absolute or relative URL in relation to a base URL.
* Resolves an absolute or relative URL in relation to a base URL.
*
* This method is adapted for use within SCM systems, so relative URLs are
* within the context of the root of the hierarchy pointed to by the base
* URL.
*
* For example, if the base URL is `<repo root url>/folder/a.yaml`, i.e.
* within the file tree of a certain repo, an absolute path of `/b.yaml` does
* not resolve to `https://hostname/b.yaml` but rather to
* `<repo root url>/b.yaml` inside the file tree of that same repo.
*
* @param options.url The (absolute or relative) URL or path to resolve

@@ -451,2 +313,33 @@ * @param options.base The base URL onto which this resolution happens

/**
* The configuration parameters for a single Azure provider.
*/
declare type AzureIntegrationConfig = {
/**
* The host of the target that this matches on, e.g. "dev.azure.com".
*
* Currently only "dev.azure.com" is supported.
*/
host: string;
/**
* The authorization token to use for requests.
*
* If no token is specified, anonymous access is used.
*/
token?: string;
};
/**
* Reads a single Azure integration config.
*
* @param config The config object of a single integration
*/
declare function readAzureIntegrationConfig(config: Config): AzureIntegrationConfig;
/**
* Reads a set of Azure integration configs, and inserts some defaults for
* public Azure if not specified.
*
* @param configs All of the integration config objects
*/
declare function readAzureIntegrationConfigs(configs: Config[]): AzureIntegrationConfig[];
declare class AzureIntegration implements ScmIntegration {

@@ -465,2 +358,143 @@ private readonly integrationConfig;

/**
* Given a URL pointing to a file on a provider, returns a URL that is suitable
* for fetching the contents of the data.
*
* Converts
* from: https://dev.azure.com/{organization}/{project}/_git/reponame?path={path}&version=GB{commitOrBranch}&_a=contents
* to: https://dev.azure.com/{organization}/{project}/_apis/git/repositories/reponame/items?path={path}&version={commitOrBranch}
*
* @param url A URL pointing to a file
*/
declare function getAzureFileFetchUrl(url: string): 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
*/
declare function getAzureDownloadUrl(url: string): string;
/**
* Given a URL, return the API URL to fetch commits on the branch.
*
* @param url A URL pointing to a repository or a sub-path
*/
declare function getAzureCommitsUrl(url: string): string;
/**
* Gets the request options necessary to make requests to a given provider.
*
* @param config The relevant provider config
*/
declare function getAzureRequestOptions(config: AzureIntegrationConfig, additionalHeaders?: Record<string, string>): RequestInit;
/**
* 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
* for fetching the contents of the data.
*
* Converts
* from: https://bitbucket.org/orgname/reponame/src/master/file.yaml
* to: https://api.bitbucket.org/2.0/repositories/orgname/reponame/src/master/file.yaml
*
* @param url A URL pointing to a file
* @param config The relevant provider config
*/
declare function getBitbucketFileFetchUrl(url: string, config: BitbucketIntegrationConfig): string;
/**
* Gets the request options necessary to make requests to a given provider.
*
* @param config The relevant provider config
*/
declare function getBitbucketRequestOptions(config: BitbucketIntegrationConfig): RequestInit;
/**
* Given a URL pointing to a file on a provider, returns a URL that is suitable
* for fetching the contents of the data.
*
* Converts
* from: https://github.com/a/b/blob/branchname/path/to/c.yaml
* to: https://api.github.com/repos/a/b/contents/path/to/c.yaml?ref=branchname
* or: https://raw.githubusercontent.com/a/b/branchname/c.yaml
*
* @param url A URL pointing to a file
* @param config The relevant provider config
*/
declare function getGitHubFileFetchUrl(url: string, config: GitHubIntegrationConfig): string;
/**
* Gets the request options necessary to make requests to a given provider.
*
* @param config The relevant provider config
*/
declare function getGitHubRequestOptions(config: GitHubIntegrationConfig): RequestInit;
declare type GithubCredentials = {
headers?: {
[name: string]: string;
};
token?: string;
};
declare class GithubCredentialsProvider {
private readonly githubAppCredentialsMux;
private readonly token?;
static create(config: GitHubIntegrationConfig): GithubCredentialsProvider;
private constructor();
/**
* Returns GithubCredentials for requested url.
* Consecutive calls to this method with the same url will return cached credentials.
* The shortest lifetime for a token returned is 10 minutes.
* @param opts containing the organization or repository url
* @returns {Promise} of @type {GithubCredentials}.
* @example
* const { token, headers } = await getCredentials({url: 'github.com/backstage/foobar'})
*/
getCredentials(opts: {
url: string;
}): Promise<GithubCredentials>;
}
/**
* Given a URL pointing to a file on a provider, returns a URL that is suitable
* for fetching the contents of the data.
*
* Converts
* from: https://gitlab.example.com/a/b/blob/master/c.yaml
* to: https://gitlab.example.com/a/b/raw/master/c.yaml
* -or-
* from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath
* to: https://gitlab.com/api/v4/projects/projectId/repository/files/filepath?ref=branch
*
* @param url A URL pointing to a file
* @param config The relevant provider config
*/
declare function getGitLabFileFetchUrl(url: string, config: GitLabIntegrationConfig): Promise<string>;
/**
* Gets the request options necessary to make requests to a given provider.
*
* @param config The relevant provider config
*/
declare function getGitLabRequestOptions(config: GitLabIntegrationConfig): RequestInit;
/**
* Default implementation of ScmIntegration.resolveUrl, that only works with
* URL pathname based providers.
*/
declare function defaultScmResolveUrl(options: {
url: string;
base: string;
}): string;
declare type IntegrationsByType = {

@@ -489,2 +523,2 @@ azure: ScmIntegrationsGroup<AzureIntegration>;

export { AzureIntegrationConfig, BitbucketIntegrationConfig, GitHubIntegrationConfig, GitLabIntegrationConfig, GithubCredentialsProvider, ScmIntegration, ScmIntegrationRegistry, ScmIntegrations, getAzureCommitsUrl, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs };
export { AzureIntegration, AzureIntegrationConfig, BitbucketIntegration, BitbucketIntegrationConfig, GitHubIntegration, GitHubIntegrationConfig, GitLabIntegration, GitLabIntegrationConfig, GithubCredentialsProvider, ScmIntegration, ScmIntegrationRegistry, ScmIntegrations, defaultScmResolveUrl, getAzureCommitsUrl, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs };

@@ -34,2 +34,21 @@ import parseGitUrl from 'git-url-parse';

}
function defaultScmResolveUrl(options) {
const {url, base} = options;
try {
new URL(url);
return url;
} catch {
}
let updated;
if (url.startsWith("/")) {
const {filepath} = parseGitUrl(base);
updated = new URL(base);
const repoRootPath = updated.pathname.substring(0, updated.pathname.length - filepath.length).replace(/\/+$/, "");
updated.pathname = `${repoRootPath}${url}`;
} else {
updated = new URL(url, base);
}
updated.search = new URL(base).search;
return updated.toString();
}

@@ -54,2 +73,42 @@ const AZURE_HOST = "dev.azure.com";

const AzureIntegration2 = class {
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}
get type() {
return "azure";
}
get title() {
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
resolveUrl(options) {
const {url, base} = options;
try {
new URL(url);
return url;
} catch {
}
const parsed = parseGitUrl(base);
const {organization, owner, name, filepath} = parsed;
if (!organization || !owner || !name) {
return new URL(url, base).toString();
}
const path = (filepath == null ? void 0 : filepath.replace(/^\//, "")) || "";
const mockBaseUrl = new URL(`https://a.com/${path}`);
const updatedPath = new URL(url, mockBaseUrl).pathname;
const newUrl = new URL(base);
newUrl.searchParams.set("path", updatedPath);
return newUrl.toString();
}
};
let AzureIntegration = AzureIntegration2;
AzureIntegration.factory = ({config: config2}) => {
var _a;
const configs = readAzureIntegrationConfigs((_a = config2.getOptionalConfigArray("integrations.azure")) != null ? _a : []);
return basicIntegrations(configs.map((c) => new AzureIntegration2(c)), (i) => i.config.host);
};
function getAzureFileFetchUrl(url) {

@@ -185,2 +244,28 @@ var _a;

const BitbucketIntegration2 = class {
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}
get type() {
return "bitbucket";
}
get title() {
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
resolveUrl(options) {
return defaultScmResolveUrl(options);
}
};
let BitbucketIntegration = BitbucketIntegration2;
BitbucketIntegration.factory = ({
config: config2
}) => {
var _a;
const configs = readBitbucketIntegrationConfigs((_a = config2.getOptionalConfigArray("integrations.bitbucket")) != null ? _a : []);
return basicIntegrations(configs.map((c) => new BitbucketIntegration2(c)), (i) => i.config.host);
};
async function getBitbucketDefaultBranch(url, config2) {

@@ -471,2 +556,26 @@ const {name: repoName, owner: project, resource} = parseGitUrl(url);

const GitHubIntegration2 = class {
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}
get type() {
return "github";
}
get title() {
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
resolveUrl(options) {
return defaultScmResolveUrl(options);
}
};
let GitHubIntegration = GitHubIntegration2;
GitHubIntegration.factory = ({config: config2}) => {
var _a;
const configs = readGitHubIntegrationConfigs((_a = config2.getOptionalConfigArray("integrations.github")) != null ? _a : []);
return basicIntegrations(configs.map((c) => new GitHubIntegration2(c)), (i) => i.config.host);
};
const GITLAB_HOST = "gitlab.com";

@@ -583,3 +692,3 @@ const GITLAB_API_BASE_URL = "https://gitlab.com/api/v4";

const AzureIntegration2 = class {
const GitLabIntegration2 = class {
constructor(integrationConfig) {

@@ -589,3 +698,3 @@ this.integrationConfig = integrationConfig;

get type() {
return "azure";
return "gitlab";
}

@@ -599,86 +708,5 @@ get title() {

resolveUrl(options) {
const {url, base} = options;
try {
new URL(url);
return url;
} catch {
}
const parsed = parseGitUrl(base);
const {organization, owner, name, filepath} = parsed;
if (!organization || !owner || !name) {
return new URL(url, base).toString();
}
const path = (filepath == null ? void 0 : filepath.replace(/^\//, "")) || "";
const mockBaseUrl = new URL(`https://a.com/${path}`);
const updatedPath = new URL(url, mockBaseUrl).pathname;
const newUrl = new URL(base);
newUrl.searchParams.set("path", updatedPath);
return newUrl.toString();
return defaultScmResolveUrl(options);
}
};
let AzureIntegration = AzureIntegration2;
AzureIntegration.factory = ({config: config2}) => {
var _a;
const configs = readAzureIntegrationConfigs((_a = config2.getOptionalConfigArray("integrations.azure")) != null ? _a : []);
return basicIntegrations(configs.map((c) => new AzureIntegration2(c)), (i) => i.config.host);
};
const BitbucketIntegration2 = class {
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}
get type() {
return "bitbucket";
}
get title() {
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
};
let BitbucketIntegration = BitbucketIntegration2;
BitbucketIntegration.factory = ({
config: config2
}) => {
var _a;
const configs = readBitbucketIntegrationConfigs((_a = config2.getOptionalConfigArray("integrations.bitbucket")) != null ? _a : []);
return basicIntegrations(configs.map((c) => new BitbucketIntegration2(c)), (i) => i.config.host);
};
const GitHubIntegration2 = class {
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}
get type() {
return "github";
}
get title() {
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
};
let GitHubIntegration = GitHubIntegration2;
GitHubIntegration.factory = ({config: config2}) => {
var _a;
const configs = readGitHubIntegrationConfigs((_a = config2.getOptionalConfigArray("integrations.github")) != null ? _a : []);
return basicIntegrations(configs.map((c) => new GitHubIntegration2(c)), (i) => i.config.host);
};
const GitLabIntegration2 = class {
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}
get type() {
return "gitlab";
}
get title() {
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
};
let GitLabIntegration = GitLabIntegration2;

@@ -725,12 +753,11 @@ GitLabIntegration.factory = ({config: config2}) => {

resolveUrl(options) {
var _a;
const resolve = (_a = this.byUrl(options.base)) == null ? void 0 : _a.resolveUrl;
if (!resolve) {
return new URL(options.url, options.base).toString();
const integration = this.byUrl(options.base);
if (!integration) {
return defaultScmResolveUrl(options);
}
return resolve(options);
return integration.resolveUrl(options);
}
}
export { GithubCredentialsProvider, ScmIntegrations, getAzureCommitsUrl, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs };
export { AzureIntegration, BitbucketIntegration, GitHubIntegration, GitLabIntegration, GithubCredentialsProvider, ScmIntegrations, defaultScmResolveUrl, getAzureCommitsUrl, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs };
//# sourceMappingURL=index.esm.js.map
{
"name": "@backstage/integration",
"version": "0.4.0",
"version": "0.5.0",
"main": "dist/index.cjs.js",

@@ -40,3 +40,3 @@ "types": "dist/index.d.ts",

"devDependencies": {
"@backstage/cli": "^0.6.0",
"@backstage/cli": "^0.6.1",
"@backstage/test-utils": "^0.1.7",

@@ -52,4 +52,4 @@ "@types/jest": "^26.0.7",

"configSchema": "config.d.ts",
"gitHead": "a85406defcbaa02ebf435575688154d8d14156d2",
"gitHead": "07fee9d9222c61a05ee50ba348b513fce28f194a",
"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