@backstage/integration 0.6.7 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -37,7 +37,7 @@ function basicIntegrations(integrations, getHost) {
37
37
  };
38
38
  }
39
39
  function defaultScmResolveUrl(options) {
40
- const {url, base, lineNumber} = options;
40
+ const { url, base, lineNumber } = options;
41
41
  try {
42
42
  new URL(url);
43
43
  return url;
@@ -45,7 +45,7 @@ function defaultScmResolveUrl(options) {
45
45
  }
46
46
  let updated;
47
47
  if (url.startsWith("/")) {
48
- const {filepath} = parseGitUrl(base);
48
+ const { filepath } = parseGitUrl(base);
49
49
  updated = new URL(base);
50
50
  const repoRootPath = trimEnd(updated.pathname.substring(0, updated.pathname.length - filepath.length), "/");
51
51
  updated.pathname = `${repoRootPath}${url}`;
@@ -67,6 +67,11 @@ var __privateGet = (obj, member, getter) => {
67
67
  __accessCheck(obj, member, "read from private field");
68
68
  return getter ? getter.call(obj) : member.get(obj);
69
69
  };
70
+ var __privateAdd = (obj, member, value) => {
71
+ if (member.has(obj))
72
+ throw TypeError("Cannot add the same private member more than once");
73
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
74
+ };
70
75
  var __privateSet = (obj, member, value, setter) => {
71
76
  __accessCheck(obj, member, "write to private field");
72
77
  setter ? setter.call(obj, value) : member.set(obj, value);
@@ -76,13 +81,13 @@ var _origin, _owner, _project, _repo, _path, _ref, _baseUrl;
76
81
  const VERSION_PREFIX_GIT_BRANCH = "GB";
77
82
  const _AzureUrl = class {
78
83
  constructor(origin, owner, project, repo, path, ref) {
79
- _origin.set(this, void 0);
80
- _owner.set(this, void 0);
81
- _project.set(this, void 0);
82
- _repo.set(this, void 0);
83
- _path.set(this, void 0);
84
- _ref.set(this, void 0);
85
- _baseUrl.set(this, (...parts) => {
84
+ __privateAdd(this, _origin, void 0);
85
+ __privateAdd(this, _owner, void 0);
86
+ __privateAdd(this, _project, void 0);
87
+ __privateAdd(this, _repo, void 0);
88
+ __privateAdd(this, _path, void 0);
89
+ __privateAdd(this, _ref, void 0);
90
+ __privateAdd(this, _baseUrl, (...parts) => {
86
91
  const url = new URL(__privateGet(this, _origin));
87
92
  url.pathname = parts.map((part) => encodeURIComponent(part)).join("/");
88
93
  return url;
@@ -205,12 +210,12 @@ function readAzureIntegrationConfig(config) {
205
210
  if (!isValidHost(host)) {
206
211
  throw new Error(`Invalid Azure integration config, '${host}' is not a valid host`);
207
212
  }
208
- return {host, token};
213
+ return { host, token };
209
214
  }
210
215
  function readAzureIntegrationConfigs(configs) {
211
216
  const result = configs.map(readAzureIntegrationConfig);
212
217
  if (!result.some((c) => c.host === AZURE_HOST)) {
213
- result.push({host: AZURE_HOST});
218
+ result.push({ host: AZURE_HOST });
214
219
  }
215
220
  return result;
216
221
  }
@@ -230,7 +235,7 @@ const _AzureIntegration = class {
230
235
  }
231
236
  resolveUrl(options) {
232
237
  var _a;
233
- const {url, base} = options;
238
+ const { url, base } = options;
234
239
  if (isValidUrl(url)) {
235
240
  return url;
236
241
  }
@@ -256,7 +261,7 @@ const _AzureIntegration = class {
256
261
  }
257
262
  };
258
263
  let AzureIntegration = _AzureIntegration;
259
- AzureIntegration.factory = ({config}) => {
264
+ AzureIntegration.factory = ({ config }) => {
260
265
  var _a;
261
266
  const configs = readAzureIntegrationConfigs((_a = config.getOptionalConfigArray("integrations.azure")) != null ? _a : []);
262
267
  return basicIntegrations(configs.map((c) => new _AzureIntegration(c)), (i) => i.config.host);
@@ -272,12 +277,12 @@ function getAzureCommitsUrl(url) {
272
277
  return AzureUrl.fromRepoUrl(url).toCommitsUrl();
273
278
  }
274
279
  function getAzureRequestOptions(config, additionalHeaders) {
275
- const headers = additionalHeaders ? {...additionalHeaders} : {};
280
+ const headers = additionalHeaders ? { ...additionalHeaders } : {};
276
281
  if (config.token) {
277
282
  const buffer = Buffer.from(`:${config.token}`, "utf8");
278
283
  headers.Authorization = `Basic ${buffer.toString("base64")}`;
279
284
  }
280
- return {headers};
285
+ return { headers };
281
286
  }
282
287
 
283
288
  const BITBUCKET_HOST = "bitbucket.org";
@@ -358,7 +363,7 @@ BitbucketIntegration.factory = ({
358
363
  };
359
364
 
360
365
  async function getBitbucketDefaultBranch(url, config) {
361
- const {name: repoName, owner: project, resource} = parseGitUrl(url);
366
+ const { name: repoName, owner: project, resource } = parseGitUrl(url);
362
367
  const isHosted = resource === "bitbucket.org";
363
368
  let branchUrl = isHosted ? `${config.apiBaseUrl}/repositories/${project}/${repoName}` : `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/default-branch`;
364
369
  let response = await fetch(branchUrl, getBitbucketRequestOptions(config));
@@ -375,7 +380,7 @@ async function getBitbucketDefaultBranch(url, config) {
375
380
  const repoInfo = await response.json();
376
381
  defaultBranch = repoInfo.mainbranch.name;
377
382
  } else {
378
- const {displayId} = await response.json();
383
+ const { displayId } = await response.json();
379
384
  defaultBranch = displayId;
380
385
  }
381
386
  if (!defaultBranch) {
@@ -403,7 +408,7 @@ async function getBitbucketDownloadUrl(url, config) {
403
408
  }
404
409
  function getBitbucketFileFetchUrl(url, config) {
405
410
  try {
406
- const {owner, name, ref, filepathtype, filepath} = parseGitUrl(url);
411
+ const { owner, name, ref, filepathtype, filepath } = parseGitUrl(url);
407
412
  if (!owner || !name || filepathtype !== "browse" && filepathtype !== "raw" && filepathtype !== "src") {
408
413
  throw new Error("Invalid Bitbucket URL or file path");
409
414
  }
@@ -462,7 +467,7 @@ function readGitHubIntegrationConfig(config) {
462
467
  } else if (host === GITHUB_HOST) {
463
468
  rawBaseUrl = GITHUB_RAW_BASE_URL;
464
469
  }
465
- return {host, apiBaseUrl, rawBaseUrl, token, apps};
470
+ return { host, apiBaseUrl, rawBaseUrl, token, apps };
466
471
  }
467
472
  function readGitHubIntegrationConfigs(configs) {
468
473
  const result = configs.map(readGitHubIntegrationConfig);
@@ -478,7 +483,7 @@ function readGitHubIntegrationConfigs(configs) {
478
483
 
479
484
  function getGitHubFileFetchUrl(url, config, credentials) {
480
485
  try {
481
- const {owner, name, ref, filepathtype, filepath} = parseGitUrl(url);
486
+ const { owner, name, ref, filepathtype, filepath } = parseGitUrl(url);
482
487
  if (!owner || !name || !ref || filepathtype !== "blob" && filepathtype !== "raw" && filepathtype !== "tree") {
483
488
  throw new Error("Invalid GitHub URL or file path");
484
489
  }
@@ -499,7 +504,7 @@ function getGitHubRequestOptions(config, credentials) {
499
504
  if (credentials.token) {
500
505
  headers.Authorization = `token ${credentials.token}`;
501
506
  }
502
- return {headers};
507
+ return { headers };
503
508
  }
504
509
  function chooseEndpoint(config, credentials) {
505
510
  if (config.apiBaseUrl && (credentials.token || !config.rawBaseUrl)) {
@@ -510,17 +515,17 @@ function chooseEndpoint(config, credentials) {
510
515
 
511
516
  class Cache {
512
517
  constructor() {
513
- this.tokenCache = new Map();
518
+ this.tokenCache = /* @__PURE__ */ new Map();
514
519
  this.isNotExpired = (date) => date.diff(DateTime.local(), "minutes").minutes > 50;
515
520
  }
516
521
  async getOrCreateToken(key, supplier) {
517
522
  const item = this.tokenCache.get(key);
518
523
  if (item && this.isNotExpired(item.expiresAt)) {
519
- return {accessToken: item.token};
524
+ return { accessToken: item.token };
520
525
  }
521
526
  const result = await supplier();
522
527
  this.tokenCache.set(key, result);
523
- return {accessToken: result.token};
528
+ return { accessToken: result.token };
524
529
  }
525
530
  }
526
531
  const HEADERS = {
@@ -533,7 +538,7 @@ class GithubAppManager {
533
538
  this.baseUrl = baseUrl;
534
539
  this.baseAuthConfig = {
535
540
  appId: config.appId,
536
- privateKey: config.privateKey
541
+ privateKey: config.privateKey.replace(/\\n/gm, "\n")
537
542
  };
538
543
  this.appClient = new Octokit({
539
544
  baseUrl,
@@ -544,7 +549,7 @@ class GithubAppManager {
544
549
  }
545
550
  async getInstallationCredentials(owner, repo) {
546
551
  var _a;
547
- const {installationId, suspended} = await this.getInstallationData(owner);
552
+ const { installationId, suspended } = await this.getInstallationData(owner);
548
553
  if (this.allowedInstallationOwners) {
549
554
  if (!((_a = this.allowedInstallationOwners) == null ? void 0 : _a.includes(owner))) {
550
555
  throw new Error(`The GitHub application for ${owner} is not included in the allowed installation list (${installationId}).`);
@@ -614,7 +619,7 @@ class GithubAppCredentialsMux {
614
619
  if (this.apps.length === 0) {
615
620
  return void 0;
616
621
  }
617
- const results = await Promise.all(this.apps.map((app) => app.getInstallationCredentials(owner, repo).then((credentials) => ({credentials, error: void 0}), (error) => ({credentials: void 0, error}))));
622
+ const results = await Promise.all(this.apps.map((app) => app.getInstallationCredentials(owner, repo).then((credentials) => ({ credentials, error: void 0 }), (error) => ({ credentials: void 0, error }))));
618
623
  const result = results.find((resultItem) => resultItem.credentials);
619
624
  if (result) {
620
625
  return result.credentials.accessToken;
@@ -627,14 +632,11 @@ class GithubAppCredentialsMux {
627
632
  return void 0;
628
633
  }
629
634
  }
630
- class GithubCredentialsProvider {
635
+ const _SingleInstanceGithubCredentialsProvider = class {
631
636
  constructor(githubAppCredentialsMux, token) {
632
637
  this.githubAppCredentialsMux = githubAppCredentialsMux;
633
638
  this.token = token;
634
639
  }
635
- static create(config) {
636
- return new GithubCredentialsProvider(new GithubAppCredentialsMux(config), config.token);
637
- }
638
640
  async getCredentials(opts) {
639
641
  const parsed = parseGitUrl(opts.url);
640
642
  const owner = parsed.owner || parsed.name;
@@ -646,12 +648,16 @@ class GithubCredentialsProvider {
646
648
  token = this.token;
647
649
  }
648
650
  return {
649
- headers: token ? {Authorization: `Bearer ${token}`} : void 0,
651
+ headers: token ? { Authorization: `Bearer ${token}` } : void 0,
650
652
  token,
651
653
  type
652
654
  };
653
655
  }
654
- }
656
+ };
657
+ let SingleInstanceGithubCredentialsProvider = _SingleInstanceGithubCredentialsProvider;
658
+ SingleInstanceGithubCredentialsProvider.create = (config) => {
659
+ return new _SingleInstanceGithubCredentialsProvider(new GithubAppCredentialsMux(config), config.token);
660
+ };
655
661
 
656
662
  const _GitHubIntegration = class {
657
663
  constructor(integrationConfig) {
@@ -667,19 +673,19 @@ const _GitHubIntegration = class {
667
673
  return this.integrationConfig;
668
674
  }
669
675
  resolveUrl(options) {
670
- return replaceUrlType$1(defaultScmResolveUrl(options), "tree");
676
+ return replaceGitHubUrlType(defaultScmResolveUrl(options), "tree");
671
677
  }
672
678
  resolveEditUrl(url) {
673
- return replaceUrlType$1(url, "edit");
679
+ return replaceGitHubUrlType(url, "edit");
674
680
  }
675
681
  };
676
682
  let GitHubIntegration = _GitHubIntegration;
677
- GitHubIntegration.factory = ({config}) => {
683
+ GitHubIntegration.factory = ({ config }) => {
678
684
  var _a;
679
685
  const configs = readGitHubIntegrationConfigs((_a = config.getOptionalConfigArray("integrations.github")) != null ? _a : []);
680
686
  return basicIntegrations(configs.map((c) => new _GitHubIntegration(c)), (i) => i.config.host);
681
687
  };
682
- function replaceUrlType$1(url, type) {
688
+ function replaceGitHubUrlType(url, type) {
683
689
  return url.replace(/\/\/([^/]+)\/([^/]+)\/([^/]+)\/(blob|tree|edit)\//, (_, host, owner, repo) => {
684
690
  return `//${host}/${owner}/${repo}/${type}/`;
685
691
  });
@@ -711,7 +717,7 @@ function readGitLabIntegrationConfig(config) {
711
717
  } else if (!isValidUrl(baseUrl)) {
712
718
  throw new Error(`Invalid GitLab integration config, '${baseUrl}' is not a valid baseUrl`);
713
719
  }
714
- return {host, token, apiBaseUrl, baseUrl};
720
+ return { host, token, apiBaseUrl, baseUrl };
715
721
  }
716
722
  function readGitLabIntegrationConfigs(configs) {
717
723
  const result = configs.map(readGitLabIntegrationConfig);
@@ -733,7 +739,7 @@ async function getGitLabFileFetchUrl(url, config) {
733
739
  return buildRawUrl(url).toString();
734
740
  }
735
741
  function getGitLabRequestOptions(config) {
736
- const {token = ""} = config;
742
+ const { token = "" } = config;
737
743
  return {
738
744
  headers: {
739
745
  "PRIVATE-TOKEN": token
@@ -811,7 +817,7 @@ const _GitLabIntegration = class {
811
817
  }
812
818
  };
813
819
  let GitLabIntegration = _GitLabIntegration;
814
- GitLabIntegration.factory = ({config}) => {
820
+ GitLabIntegration.factory = ({ config }) => {
815
821
  var _a;
816
822
  const configs = readGitLabIntegrationConfigs((_a = config.getOptionalConfigArray("integrations.gitlab")) != null ? _a : []);
817
823
  return basicIntegrations(configs.map((c) => new _GitLabIntegration(c)), (i) => i.config.host);
@@ -829,20 +835,41 @@ function readGoogleGcsIntegrationConfig(config) {
829
835
  }
830
836
  const privateKey = config.getString("privateKey").split("\\n").join("\n");
831
837
  const clientEmail = config.getString("clientEmail");
832
- return {clientEmail, privateKey};
838
+ return { clientEmail, privateKey };
833
839
  }
834
840
 
835
841
  const AMAZON_AWS_HOST = "amazonaws.com";
836
842
  function readAwsS3IntegrationConfig(config) {
837
843
  var _a;
838
- const host = (_a = config.getOptionalString("host")) != null ? _a : AMAZON_AWS_HOST;
844
+ const endpoint = config.getOptionalString("endpoint");
845
+ const s3ForcePathStyle = (_a = config.getOptionalBoolean("s3ForcePathStyle")) != null ? _a : false;
846
+ let host;
847
+ let pathname;
848
+ if (endpoint) {
849
+ try {
850
+ const url = new URL(endpoint);
851
+ host = url.host;
852
+ pathname = url.pathname;
853
+ } catch {
854
+ throw new Error(`invalid awsS3 integration config, endpoint '${endpoint}' is not a valid URL`);
855
+ }
856
+ if (pathname !== "/") {
857
+ throw new Error(`invalid awsS3 integration config, endpoints cannot contain path, got '${endpoint}'`);
858
+ }
859
+ } else {
860
+ host = AMAZON_AWS_HOST;
861
+ }
839
862
  const accessKeyId = config.getOptionalString("accessKeyId");
840
863
  const secretAccessKey = config.getOptionalString("secretAccessKey");
841
864
  const roleArn = config.getOptionalString("roleArn");
842
- if (!isValidHost(host)) {
843
- throw new Error(`Invalid awsS3 integration config, '${host}' is not a valid host`);
844
- }
845
- return {host, accessKeyId, secretAccessKey, roleArn};
865
+ return {
866
+ host,
867
+ endpoint,
868
+ s3ForcePathStyle,
869
+ accessKeyId,
870
+ secretAccessKey,
871
+ roleArn
872
+ };
846
873
  }
847
874
  function readAwsS3IntegrationConfigs(configs) {
848
875
  const result = configs.map(readAwsS3IntegrationConfig);
@@ -876,7 +903,7 @@ const _AwsS3Integration = class {
876
903
  }
877
904
  };
878
905
  let AwsS3Integration = _AwsS3Integration;
879
- AwsS3Integration.factory = ({config}) => {
906
+ AwsS3Integration.factory = ({ config }) => {
880
907
  var _a;
881
908
  const configs = readAwsS3IntegrationConfigs((_a = config.getOptionalConfigArray("integrations.awsS3")) != null ? _a : []);
882
909
  return basicIntegrations(configs.map((c) => new _AwsS3Integration(c)), (i) => i.config.host);
@@ -885,11 +912,11 @@ AwsS3Integration.factory = ({config}) => {
885
912
  class ScmIntegrations {
886
913
  static fromConfig(config) {
887
914
  return new ScmIntegrations({
888
- awsS3: AwsS3Integration.factory({config}),
889
- azure: AzureIntegration.factory({config}),
890
- bitbucket: BitbucketIntegration.factory({config}),
891
- github: GitHubIntegration.factory({config}),
892
- gitlab: GitLabIntegration.factory({config})
915
+ awsS3: AwsS3Integration.factory({ config }),
916
+ azure: AzureIntegration.factory({ config }),
917
+ bitbucket: BitbucketIntegration.factory({ config }),
918
+ github: GitHubIntegration.factory({ config }),
919
+ gitlab: GitLabIntegration.factory({ config })
893
920
  });
894
921
  }
895
922
  constructor(integrationsByType) {
@@ -935,5 +962,5 @@ class ScmIntegrations {
935
962
  }
936
963
  }
937
964
 
938
- export { AwsS3Integration, AzureIntegration, BitbucketIntegration, GitHubIntegration, GitLabIntegration, GithubAppCredentialsMux, GithubCredentialsProvider, ScmIntegrations, defaultScmResolveUrl, getAzureCommitsUrl, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAwsS3IntegrationConfig, readAwsS3IntegrationConfigs, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs, readGoogleGcsIntegrationConfig, replaceUrlType$1 as replaceGitHubUrlType };
965
+ export { AwsS3Integration, AzureIntegration, BitbucketIntegration, GitHubIntegration, GitLabIntegration, GithubAppCredentialsMux, ScmIntegrations, SingleInstanceGithubCredentialsProvider, defaultScmResolveUrl, getAzureCommitsUrl, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAwsS3IntegrationConfig, readAwsS3IntegrationConfigs, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs, readGoogleGcsIntegrationConfig, replaceGitHubUrlType };
939
966
  //# sourceMappingURL=index.esm.js.map