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
973
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.5 to 0.2.0

6

CHANGELOG.md
# @backstage/integration
## 0.2.0
### Minor Changes
- 466354aaa: Build out the `ScmIntegrations` class, as well as the individual `*Integration` classes
## 0.1.5

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

112

dist/index.cjs.js

@@ -18,2 +18,16 @@ 'use strict';

}
function basicIntegrations(integrations, getHost) {
return {
list() {
return integrations;
},
byUrl(url) {
const parsed = typeof url === "string" ? new URL(url) : url;
return integrations.find((i) => getHost(i) === parsed.hostname);
},
byHost(host) {
return integrations.find((i) => getHost(i) === host);
}
};
}

@@ -366,4 +380,4 @@ const AZURE_HOST = "dev.azure.com";

const AzureIntegration2 = class {
constructor(config2) {
this.config = config2;
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}

@@ -374,4 +388,7 @@ get type() {

get title() {
return this.config.host;
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
};

@@ -382,11 +399,8 @@ let AzureIntegration = AzureIntegration2;

const configs = readAzureIntegrationConfigs((_a = config2.getOptionalConfigArray("integrations.azure")) != null ? _a : []);
return configs.map((integration) => ({
predicate: (url) => url.host === integration.host,
integration: new AzureIntegration2(integration)
}));
return basicIntegrations(configs.map((c) => new AzureIntegration2(c)), (i) => i.config.host);
};
const BitbucketIntegration2 = class {
constructor(config2) {
this.config = config2;
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}

@@ -397,18 +411,20 @@ get type() {

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

@@ -419,4 +435,7 @@ get type() {

get title() {
return this.config.host;
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
};

@@ -427,11 +446,8 @@ let GitHubIntegration = GitHubIntegration2;

const configs = readGitHubIntegrationConfigs((_a = config2.getOptionalConfigArray("integrations.github")) != null ? _a : []);
return configs.map((integration) => ({
predicate: (url) => url.host === integration.host,
integration: new GitHubIntegration2(integration)
}));
return basicIntegrations(configs.map((c) => new GitHubIntegration2(c)), (i) => i.config.host);
};
const GitLabIntegration2 = class {
constructor(config2) {
this.config = config2;
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}

@@ -442,4 +458,7 @@ get type() {

get title() {
return this.config.host;
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
};

@@ -450,27 +469,38 @@ let GitLabIntegration = GitLabIntegration2;

const configs = readGitLabIntegrationConfigs((_a = config2.getOptionalConfigArray("integrations.gitlab")) != null ? _a : []);
return configs.map((integration) => ({
predicate: (url) => url.host === integration.host,
integration: new GitLabIntegration2(integration)
}));
return basicIntegrations(configs.map((c) => new GitLabIntegration2(c)), (i) => i.config.host);
};
class ScmIntegrations {
constructor(integrations) {
this.integrations = integrations;
}
static fromConfig(config2) {
return new ScmIntegrations([
...AzureIntegration.factory({config: config2}),
...BitbucketIntegration.factory({config: config2}),
...GitHubIntegration.factory({config: config2}),
...GitLabIntegration.factory({config: config2})
]);
return new ScmIntegrations({
azure: AzureIntegration.factory({config: config2}),
bitbucket: BitbucketIntegration.factory({config: config2}),
github: GitHubIntegration.factory({config: config2}),
gitlab: GitLabIntegration.factory({config: config2})
});
}
constructor(integrationsByType) {
this.byType = integrationsByType;
}
get azure() {
return this.byType.azure;
}
get bitbucket() {
return this.byType.bitbucket;
}
get github() {
return this.byType.github;
}
get gitlab() {
return this.byType.gitlab;
}
list() {
return this.integrations.map((i) => i.integration);
return Object.values(this.byType).flatMap((i) => i.list());
}
byUrl(url) {
var _a;
return (_a = this.integrations.find((i) => i.predicate(new URL(url)))) == null ? void 0 : _a.integration;
return Object.values(this.byType).map((i) => i.byUrl(url)).find(Boolean);
}
byHost(host) {
return Object.values(this.byType).map((i) => i.byHost(host)).find(Boolean);
}
}

@@ -477,0 +507,0 @@

@@ -274,6 +274,33 @@ import { Config } from '@backstage/config';

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 {
private readonly integrationConfig;
static factory: ScmIntegrationsFactory<GitLabIntegration>;
constructor(integrationConfig: GitLabIntegrationConfig);
get type(): string;
get title(): string;
get config(): GitLabIntegrationConfig;
}
/**
* Encapsulates a single SCM integration.
*/
declare type ScmIntegration = {
interface ScmIntegration {
/**

@@ -288,31 +315,65 @@ * The type of integration, e.g. "github".

title: string;
};
}
/**
* Holds all registered SCM integrations.
* Encapsulates several integrations, that are all of the same type.
*/
declare type ScmIntegrationRegistry = {
interface ScmIntegrationsGroup<T extends ScmIntegration> {
/**
* Lists all registered integrations.
* Lists all registered integrations of this type.
*/
list(): ScmIntegration[];
list(): T[];
/**
* Fetches an integration by URL.
* Fetches an integration of this type by URL.
*
* @param url A URL that matches a registered integration
* @param url A URL that matches a registered integration of this type
*/
byUrl(url: string): ScmIntegration | undefined;
byUrl(url: string | URL): T | undefined;
/**
* Fetches an integration of this type by host name.
*
* @param url A host name that matches a registered integration of this type
*/
byHost(host: string): T | undefined;
}
/**
* Holds all registered SCM integrations, of all types.
*/
interface ScmIntegrationRegistry extends ScmIntegrationsGroup<ScmIntegration> {
azure: ScmIntegrationsGroup<AzureIntegration>;
bitbucket: ScmIntegrationsGroup<BitbucketIntegration>;
github: ScmIntegrationsGroup<GitHubIntegration>;
gitlab: ScmIntegrationsGroup<GitLabIntegration>;
}
declare type ScmIntegrationsFactory<T extends ScmIntegration> = (options: {
config: Config;
}) => ScmIntegrationsGroup<T>;
declare class AzureIntegration implements ScmIntegration {
private readonly integrationConfig;
static factory: ScmIntegrationsFactory<AzureIntegration>;
constructor(integrationConfig: AzureIntegrationConfig);
get type(): string;
get title(): string;
get config(): AzureIntegrationConfig;
}
declare type IntegrationsByType = {
azure: ScmIntegrationsGroup<AzureIntegration>;
bitbucket: ScmIntegrationsGroup<BitbucketIntegration>;
github: ScmIntegrationsGroup<GitHubIntegration>;
gitlab: ScmIntegrationsGroup<GitLabIntegration>;
};
declare type ScmIntegrationPredicateTuple = {
predicate: (url: URL) => boolean;
integration: ScmIntegration;
};
declare class ScmIntegrations implements ScmIntegrationRegistry {
private readonly integrations;
private readonly byType;
static fromConfig(config: Config): ScmIntegrations;
constructor(integrations: ScmIntegrationPredicateTuple[]);
constructor(integrationsByType: IntegrationsByType);
get azure(): ScmIntegrationsGroup<AzureIntegration>;
get bitbucket(): ScmIntegrationsGroup<BitbucketIntegration>;
get github(): ScmIntegrationsGroup<GitHubIntegration>;
get gitlab(): ScmIntegrationsGroup<GitLabIntegration>;
list(): ScmIntegration[];
byUrl(url: string): ScmIntegration | undefined;
byUrl(url: string | URL): ScmIntegration | undefined;
byHost(host: string): ScmIntegration | undefined;
}
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 };

@@ -9,2 +9,16 @@ import parseGitUrl from 'git-url-parse';

}
function basicIntegrations(integrations, getHost) {
return {
list() {
return integrations;
},
byUrl(url) {
const parsed = typeof url === "string" ? new URL(url) : url;
return integrations.find((i) => getHost(i) === parsed.hostname);
},
byHost(host) {
return integrations.find((i) => getHost(i) === host);
}
};
}

@@ -357,4 +371,4 @@ const AZURE_HOST = "dev.azure.com";

const AzureIntegration2 = class {
constructor(config2) {
this.config = config2;
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}

@@ -365,4 +379,7 @@ get type() {

get title() {
return this.config.host;
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
};

@@ -373,11 +390,8 @@ let AzureIntegration = AzureIntegration2;

const configs = readAzureIntegrationConfigs((_a = config2.getOptionalConfigArray("integrations.azure")) != null ? _a : []);
return configs.map((integration) => ({
predicate: (url) => url.host === integration.host,
integration: new AzureIntegration2(integration)
}));
return basicIntegrations(configs.map((c) => new AzureIntegration2(c)), (i) => i.config.host);
};
const BitbucketIntegration2 = class {
constructor(config2) {
this.config = config2;
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}

@@ -388,18 +402,20 @@ get type() {

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

@@ -410,4 +426,7 @@ get type() {

get title() {
return this.config.host;
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
};

@@ -418,11 +437,8 @@ let GitHubIntegration = GitHubIntegration2;

const configs = readGitHubIntegrationConfigs((_a = config2.getOptionalConfigArray("integrations.github")) != null ? _a : []);
return configs.map((integration) => ({
predicate: (url) => url.host === integration.host,
integration: new GitHubIntegration2(integration)
}));
return basicIntegrations(configs.map((c) => new GitHubIntegration2(c)), (i) => i.config.host);
};
const GitLabIntegration2 = class {
constructor(config2) {
this.config = config2;
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}

@@ -433,4 +449,7 @@ get type() {

get title() {
return this.config.host;
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
};

@@ -441,27 +460,38 @@ let GitLabIntegration = GitLabIntegration2;

const configs = readGitLabIntegrationConfigs((_a = config2.getOptionalConfigArray("integrations.gitlab")) != null ? _a : []);
return configs.map((integration) => ({
predicate: (url) => url.host === integration.host,
integration: new GitLabIntegration2(integration)
}));
return basicIntegrations(configs.map((c) => new GitLabIntegration2(c)), (i) => i.config.host);
};
class ScmIntegrations {
constructor(integrations) {
this.integrations = integrations;
}
static fromConfig(config2) {
return new ScmIntegrations([
...AzureIntegration.factory({config: config2}),
...BitbucketIntegration.factory({config: config2}),
...GitHubIntegration.factory({config: config2}),
...GitLabIntegration.factory({config: config2})
]);
return new ScmIntegrations({
azure: AzureIntegration.factory({config: config2}),
bitbucket: BitbucketIntegration.factory({config: config2}),
github: GitHubIntegration.factory({config: config2}),
gitlab: GitLabIntegration.factory({config: config2})
});
}
constructor(integrationsByType) {
this.byType = integrationsByType;
}
get azure() {
return this.byType.azure;
}
get bitbucket() {
return this.byType.bitbucket;
}
get github() {
return this.byType.github;
}
get gitlab() {
return this.byType.gitlab;
}
list() {
return this.integrations.map((i) => i.integration);
return Object.values(this.byType).flatMap((i) => i.list());
}
byUrl(url) {
var _a;
return (_a = this.integrations.find((i) => i.predicate(new URL(url)))) == null ? void 0 : _a.integration;
return Object.values(this.byType).map((i) => i.byUrl(url)).find(Boolean);
}
byHost(host) {
return Object.values(this.byType).map((i) => i.byHost(host)).find(Boolean);
}
}

@@ -468,0 +498,0 @@

{
"name": "@backstage/integration",
"version": "0.1.5",
"version": "0.2.0",
"main": "dist/index.cjs.js",

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

"devDependencies": {
"@backstage/cli": "^0.4.5",
"@backstage/cli": "^0.4.6",
"@backstage/test-utils": "^0.1.5",

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

"configSchema": "config.d.ts",
"gitHead": "3c341e5bde29b325e84c6bf88b29f3027c8c3384",
"gitHead": "78a04ec03473ae52e3bff84d61e75c6aaaeee261",
"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