@backstage/integration 1.11.0-next.0 → 1.12.0-next.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.
Files changed (68) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/ScmIntegrations.esm.js +4 -10
  3. package/dist/ScmIntegrations.esm.js.map +1 -1
  4. package/dist/awsCodeCommit/AwsCodeCommitIntegration.esm.js +13 -21
  5. package/dist/awsCodeCommit/AwsCodeCommitIntegration.esm.js.map +1 -1
  6. package/dist/awsCodeCommit/config.esm.js +1 -2
  7. package/dist/awsCodeCommit/config.esm.js.map +1 -1
  8. package/dist/awsS3/AwsS3Integration.esm.js +11 -19
  9. package/dist/awsS3/AwsS3Integration.esm.js.map +1 -1
  10. package/dist/awsS3/config.esm.js +2 -3
  11. package/dist/awsS3/config.esm.js.map +1 -1
  12. package/dist/azure/AzureIntegration.esm.js +12 -21
  13. package/dist/azure/AzureIntegration.esm.js.map +1 -1
  14. package/dist/azure/AzureUrl.esm.js +72 -76
  15. package/dist/azure/AzureUrl.esm.js.map +1 -1
  16. package/dist/azure/CachedAzureDevOpsCredentialsProvider.esm.js +2 -8
  17. package/dist/azure/CachedAzureDevOpsCredentialsProvider.esm.js.map +1 -1
  18. package/dist/azure/DefaultAzureDevOpsCredentialsProvider.esm.js +3 -6
  19. package/dist/azure/DefaultAzureDevOpsCredentialsProvider.esm.js.map +1 -1
  20. package/dist/azure/config.esm.js +12 -15
  21. package/dist/azure/config.esm.js.map +1 -1
  22. package/dist/azure/deprecated.esm.js +2 -3
  23. package/dist/azure/deprecated.esm.js.map +1 -1
  24. package/dist/bitbucket/BitbucketIntegration.esm.js +19 -27
  25. package/dist/bitbucket/BitbucketIntegration.esm.js.map +1 -1
  26. package/dist/bitbucket/config.esm.js +3 -4
  27. package/dist/bitbucket/config.esm.js.map +1 -1
  28. package/dist/bitbucketCloud/BitbucketCloudIntegration.esm.js +13 -21
  29. package/dist/bitbucketCloud/BitbucketCloudIntegration.esm.js.map +1 -1
  30. package/dist/bitbucketCloud/config.esm.js +1 -2
  31. package/dist/bitbucketCloud/config.esm.js.map +1 -1
  32. package/dist/bitbucketServer/BitbucketServerIntegration.esm.js +13 -21
  33. package/dist/bitbucketServer/BitbucketServerIntegration.esm.js.map +1 -1
  34. package/dist/bitbucketServer/config.esm.js +1 -2
  35. package/dist/bitbucketServer/config.esm.js.map +1 -1
  36. package/dist/gerrit/GerritIntegration.esm.js +11 -19
  37. package/dist/gerrit/GerritIntegration.esm.js.map +1 -1
  38. package/dist/gerrit/config.esm.js +1 -2
  39. package/dist/gerrit/config.esm.js.map +1 -1
  40. package/dist/gitea/GiteaIntegration.esm.js +10 -18
  41. package/dist/gitea/GiteaIntegration.esm.js.map +1 -1
  42. package/dist/gitea/config.esm.js +1 -2
  43. package/dist/gitea/config.esm.js.map +1 -1
  44. package/dist/gitea/core.esm.js +1 -2
  45. package/dist/gitea/core.esm.js.map +1 -1
  46. package/dist/github/GithubIntegration.esm.js +11 -19
  47. package/dist/github/GithubIntegration.esm.js.map +1 -1
  48. package/dist/github/SingleInstanceGithubCredentialsProvider.esm.js +22 -40
  49. package/dist/github/SingleInstanceGithubCredentialsProvider.esm.js.map +1 -1
  50. package/dist/github/config.esm.js +3 -4
  51. package/dist/github/config.esm.js.map +1 -1
  52. package/dist/github/deprecated.esm.js +1 -7
  53. package/dist/github/deprecated.esm.js.map +1 -1
  54. package/dist/gitlab/GitLabIntegration.esm.js +11 -19
  55. package/dist/gitlab/GitLabIntegration.esm.js.map +1 -1
  56. package/dist/gitlab/SingleInstanceGitlabCredentialsProvider.esm.js +5 -12
  57. package/dist/gitlab/SingleInstanceGitlabCredentialsProvider.esm.js.map +1 -1
  58. package/dist/gitlab/config.esm.js +1 -2
  59. package/dist/gitlab/config.esm.js.map +1 -1
  60. package/dist/harness/HarnessIntegration.esm.js +10 -18
  61. package/dist/harness/HarnessIntegration.esm.js.map +1 -1
  62. package/dist/harness/core.esm.js +48 -46
  63. package/dist/harness/core.esm.js.map +1 -1
  64. package/dist/index.cjs.js +323 -471
  65. package/dist/index.cjs.js.map +1 -1
  66. package/dist/index.d.ts +50 -2
  67. package/dist/index.esm.js +1 -1
  68. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"core.esm.js","sources":["../../src/gitea/core.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { GiteaIntegrationConfig } from './config';\n\n/**\n * Given a URL pointing to a file, returns a URL\n * for editing the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://gitea.com/a/b/src/branchname/path/to/c.yaml\n * or: https://gitea.com/a/b/_edit/branchname/path/to/c.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getGiteaEditContentsUrl(\n config: GiteaIntegrationConfig,\n url: string,\n) {\n const giteaUrl = parseGiteaUrl(config, url);\n return `${giteaUrl.url}/${giteaUrl.owner}/${giteaUrl.name}/_edit/${giteaUrl.ref}/${giteaUrl.path}`;\n}\n\n/**\n * Given a URL pointing to a file, returns an api URL\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://gitea.com/a/b/src/branch/branchname/path/to/c.yaml\n * to: https://gitea.com/api/v1/repos/a/b/contents/path/to/c.yaml?ref=branchname\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getGiteaFileContentsUrl(\n config: GiteaIntegrationConfig,\n url: string,\n) {\n const giteaUrl = parseGiteaUrl(config, url);\n return `${giteaUrl.url}/api/v1/repos/${giteaUrl.owner}/${giteaUrl.name}/contents/${giteaUrl.path}?ref=${giteaUrl.ref}`;\n}\n\n/**\n * Given a URL pointing to a repository/path, returns a URL\n * for archive contents of the repository.\n *\n * @remarks\n *\n * Converts\n * from: https://gitea.com/a/b/src/branchname\n * or: https://gitea.com/api/v1/repos/a/b/archive/branchname.tar.gz\n *\n * @param url - A URL pointing to a repository/path\n * @param config - The relevant provider config\n * @public\n */\nexport function getGiteaArchiveUrl(\n config: GiteaIntegrationConfig,\n url: string,\n) {\n const giteaUrl = parseGiteaUrl(config, url);\n return `${giteaUrl.url}/api/v1/repos/${giteaUrl.owner}/${giteaUrl.name}/archive/${giteaUrl.ref}.tar.gz`;\n}\n\n/**\n * Given a URL pointing to a repository branch, returns a URL\n * for latest commit information.\n *\n * @remarks\n *\n * Converts\n * from: https://gitea.com/a/b/src/branchname\n * or: https://gitea.com/api/v1/repos/a/b/git/commits/branchname\n *\n * @param url - A URL pointing to a repository branch\n * @param config - The relevant provider config\n * @public\n */\nexport function getGiteaLatestCommitUrl(\n config: GiteaIntegrationConfig,\n url: string,\n) {\n const giteaUrl = parseGiteaUrl(config, url);\n return `${giteaUrl.url}/api/v1/repos/${giteaUrl.owner}/${giteaUrl.name}/git/commits/${giteaUrl.ref}`;\n}\n\n/**\n * Return request headers for a Gitea provider.\n *\n * @param config - A Gitea provider config\n * @public\n */\nexport function getGiteaRequestOptions(config: GiteaIntegrationConfig): {\n headers?: Record<string, string>;\n} {\n const headers: Record<string, string> = {};\n const { username, password } = config;\n\n if (!password) {\n return headers;\n }\n\n if (username) {\n headers.Authorization = `basic ${Buffer.from(\n `${username}:${password}`,\n ).toString('base64')}`;\n } else {\n headers.Authorization = `token ${password}`;\n }\n\n return {\n headers,\n };\n}\n\n/**\n * Return parsed git url properties.\n *\n * @param config - A Gitea provider config\n * @param url - A URL pointing to a repository\n * @public\n */\nexport function parseGiteaUrl(\n config: GiteaIntegrationConfig,\n url: string,\n): {\n url: string;\n owner: string;\n name: string;\n ref: string;\n path: string;\n} {\n const baseUrl = config.baseUrl ?? `https://${config.host}`;\n try {\n const [_blank, owner, name, _src, _branch, ref, ...path] = url\n .replace(baseUrl, '')\n .split('/');\n const pathWithoutSlash = path.join('/').replace(/^\\//, '');\n\n return {\n url: baseUrl,\n owner: owner,\n name: name,\n ref: ref,\n path: pathWithoutSlash,\n };\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n"],"names":[],"mappings":"AA+BgB,SAAA,uBAAA,CACd,QACA,GACA,EAAA;AACA,EAAM,MAAA,QAAA,GAAW,aAAc,CAAA,MAAA,EAAQ,GAAG,CAAA,CAAA;AAC1C,EAAA,OAAO,CAAG,EAAA,QAAA,CAAS,GAAG,CAAA,CAAA,EAAI,SAAS,KAAK,CAAA,CAAA,EAAI,QAAS,CAAA,IAAI,CAAU,OAAA,EAAA,QAAA,CAAS,GAAG,CAAA,CAAA,EAAI,SAAS,IAAI,CAAA,CAAA,CAAA;AAClG,CAAA;AAgBgB,SAAA,uBAAA,CACd,QACA,GACA,EAAA;AACA,EAAM,MAAA,QAAA,GAAW,aAAc,CAAA,MAAA,EAAQ,GAAG,CAAA,CAAA;AAC1C,EAAA,OAAO,CAAG,EAAA,QAAA,CAAS,GAAG,CAAA,cAAA,EAAiB,SAAS,KAAK,CAAA,CAAA,EAAI,QAAS,CAAA,IAAI,CAAa,UAAA,EAAA,QAAA,CAAS,IAAI,CAAA,KAAA,EAAQ,SAAS,GAAG,CAAA,CAAA,CAAA;AACtH,CAAA;AAgBgB,SAAA,kBAAA,CACd,QACA,GACA,EAAA;AACA,EAAM,MAAA,QAAA,GAAW,aAAc,CAAA,MAAA,EAAQ,GAAG,CAAA,CAAA;AAC1C,EAAO,OAAA,CAAA,EAAG,QAAS,CAAA,GAAG,CAAiB,cAAA,EAAA,QAAA,CAAS,KAAK,CAAA,CAAA,EAAI,QAAS,CAAA,IAAI,CAAY,SAAA,EAAA,QAAA,CAAS,GAAG,CAAA,OAAA,CAAA,CAAA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,IAAI,CAAA,GAAI,IACxD,OAAQ,CAAA,OAAA,EAAS,EAAE,CAAA,CACnB,MAAM,GAAG,CAAA,CAAA;AACZ,IAAA,MAAM,mBAAmB,IAAK,CAAA,IAAA,CAAK,GAAG,CAAE,CAAA,OAAA,CAAQ,OAAO,EAAE,CAAA,CAAA;AAEzD,IAAO,OAAA;AAAA,MACL,GAAK,EAAA,OAAA;AAAA,MACL,KAAA;AAAA,MACA,IAAA;AAAA,MACA,GAAA;AAAA,MACA,IAAM,EAAA,gBAAA;AAAA,KACR,CAAA;AAAA,WACO,CAAG,EAAA;AACV,IAAA,MAAM,IAAI,KAAM,CAAA,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAE,CAAA,CAAA,CAAA;AAAA,GAC/C;AACF;;;;"}
1
+ {"version":3,"file":"core.esm.js","sources":["../../src/gitea/core.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { GiteaIntegrationConfig } from './config';\n\n/**\n * Given a URL pointing to a file, returns a URL\n * for editing the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://gitea.com/a/b/src/branchname/path/to/c.yaml\n * or: https://gitea.com/a/b/_edit/branchname/path/to/c.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getGiteaEditContentsUrl(\n config: GiteaIntegrationConfig,\n url: string,\n) {\n const giteaUrl = parseGiteaUrl(config, url);\n return `${giteaUrl.url}/${giteaUrl.owner}/${giteaUrl.name}/_edit/${giteaUrl.ref}/${giteaUrl.path}`;\n}\n\n/**\n * Given a URL pointing to a file, returns an api URL\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://gitea.com/a/b/src/branch/branchname/path/to/c.yaml\n * to: https://gitea.com/api/v1/repos/a/b/contents/path/to/c.yaml?ref=branchname\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getGiteaFileContentsUrl(\n config: GiteaIntegrationConfig,\n url: string,\n) {\n const giteaUrl = parseGiteaUrl(config, url);\n return `${giteaUrl.url}/api/v1/repos/${giteaUrl.owner}/${giteaUrl.name}/contents/${giteaUrl.path}?ref=${giteaUrl.ref}`;\n}\n\n/**\n * Given a URL pointing to a repository/path, returns a URL\n * for archive contents of the repository.\n *\n * @remarks\n *\n * Converts\n * from: https://gitea.com/a/b/src/branchname\n * or: https://gitea.com/api/v1/repos/a/b/archive/branchname.tar.gz\n *\n * @param url - A URL pointing to a repository/path\n * @param config - The relevant provider config\n * @public\n */\nexport function getGiteaArchiveUrl(\n config: GiteaIntegrationConfig,\n url: string,\n) {\n const giteaUrl = parseGiteaUrl(config, url);\n return `${giteaUrl.url}/api/v1/repos/${giteaUrl.owner}/${giteaUrl.name}/archive/${giteaUrl.ref}.tar.gz`;\n}\n\n/**\n * Given a URL pointing to a repository branch, returns a URL\n * for latest commit information.\n *\n * @remarks\n *\n * Converts\n * from: https://gitea.com/a/b/src/branchname\n * or: https://gitea.com/api/v1/repos/a/b/git/commits/branchname\n *\n * @param url - A URL pointing to a repository branch\n * @param config - The relevant provider config\n * @public\n */\nexport function getGiteaLatestCommitUrl(\n config: GiteaIntegrationConfig,\n url: string,\n) {\n const giteaUrl = parseGiteaUrl(config, url);\n return `${giteaUrl.url}/api/v1/repos/${giteaUrl.owner}/${giteaUrl.name}/git/commits/${giteaUrl.ref}`;\n}\n\n/**\n * Return request headers for a Gitea provider.\n *\n * @param config - A Gitea provider config\n * @public\n */\nexport function getGiteaRequestOptions(config: GiteaIntegrationConfig): {\n headers?: Record<string, string>;\n} {\n const headers: Record<string, string> = {};\n const { username, password } = config;\n\n if (!password) {\n return headers;\n }\n\n if (username) {\n headers.Authorization = `basic ${Buffer.from(\n `${username}:${password}`,\n ).toString('base64')}`;\n } else {\n headers.Authorization = `token ${password}`;\n }\n\n return {\n headers,\n };\n}\n\n/**\n * Return parsed git url properties.\n *\n * @param config - A Gitea provider config\n * @param url - A URL pointing to a repository\n * @public\n */\nexport function parseGiteaUrl(\n config: GiteaIntegrationConfig,\n url: string,\n): {\n url: string;\n owner: string;\n name: string;\n ref: string;\n path: string;\n} {\n const baseUrl = config.baseUrl ?? `https://${config.host}`;\n try {\n const [_blank, owner, name, _src, _branch, ref, ...path] = url\n .replace(baseUrl, '')\n .split('/');\n const pathWithoutSlash = path.join('/').replace(/^\\//, '');\n\n return {\n url: baseUrl,\n owner: owner,\n name: name,\n ref: ref,\n path: pathWithoutSlash,\n };\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n"],"names":[],"mappings":"AA+BgB,SAAA,uBAAA,CACd,QACA,GACA,EAAA;AACA,EAAM,MAAA,QAAA,GAAW,aAAc,CAAA,MAAA,EAAQ,GAAG,CAAA,CAAA;AAC1C,EAAA,OAAO,CAAG,EAAA,QAAA,CAAS,GAAG,CAAA,CAAA,EAAI,SAAS,KAAK,CAAA,CAAA,EAAI,QAAS,CAAA,IAAI,CAAU,OAAA,EAAA,QAAA,CAAS,GAAG,CAAA,CAAA,EAAI,SAAS,IAAI,CAAA,CAAA,CAAA;AAClG,CAAA;AAgBgB,SAAA,uBAAA,CACd,QACA,GACA,EAAA;AACA,EAAM,MAAA,QAAA,GAAW,aAAc,CAAA,MAAA,EAAQ,GAAG,CAAA,CAAA;AAC1C,EAAA,OAAO,CAAG,EAAA,QAAA,CAAS,GAAG,CAAA,cAAA,EAAiB,SAAS,KAAK,CAAA,CAAA,EAAI,QAAS,CAAA,IAAI,CAAa,UAAA,EAAA,QAAA,CAAS,IAAI,CAAA,KAAA,EAAQ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GACF,CAAA;AACF,CAAA;AASgB,SAAA,aAAA,CACd,QACA,GAOA,EAAA;AACA,EAAA,MAAM,OAAU,GAAA,MAAA,CAAO,OAAW,IAAA,CAAA,QAAA,EAAW,OAAO,IAAI,CAAA,CAAA,CAAA;AACxD,EAAI,IAAA;AACF,IAAA,MAAM,CAAC,MAAQ,EAAA,KAAA,EAAO,IAAM,EAAA,IAAA,EAAM,SAAS,GAAK,EAAA,GAAG,IAAI,CAAA,GAAI,IACxD,OAAQ,CAAA,OAAA,EAAS,EAAE,CAAA,CACnB,MAAM,GAAG,CAAA,CAAA;AACZ,IAAA,MAAM,mBAAmB,IAAK,CAAA,IAAA,CAAK,GAAG,CAAE,CAAA,OAAA,CAAQ,OAAO,EAAE,CAAA,CAAA;AAEzD,IAAO,OAAA;AAAA,MACL,GAAK,EAAA,OAAA;AAAA,MACL,KAAA;AAAA,MACA,IAAA;AAAA,MACA,GAAA;AAAA,MACA,IAAM,EAAA,gBAAA;AAAA,KACR,CAAA;AAAA,WACO,CAAG,EAAA;AACV,IAAA,MAAM,IAAI,KAAM,CAAA,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAE,CAAA,CAAA,CAAA;AAAA,GAC/C;AACF;;;;"}
@@ -1,16 +1,19 @@
1
1
  import { basicIntegrations, defaultScmResolveUrl } from '../helpers.esm.js';
2
2
  import { readGithubIntegrationConfigs } from './config.esm.js';
3
3
 
4
- var __defProp = Object.defineProperty;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __publicField = (obj, key, value) => {
7
- __defNormalProp(obj, key + "" , value);
8
- return value;
9
- };
10
- const _GithubIntegration = class _GithubIntegration {
4
+ class GithubIntegration {
11
5
  constructor(integrationConfig) {
12
6
  this.integrationConfig = integrationConfig;
13
7
  }
8
+ static factory = ({ config }) => {
9
+ const configs = readGithubIntegrationConfigs(
10
+ config.getOptionalConfigArray("integrations.github") ?? []
11
+ );
12
+ return basicIntegrations(
13
+ configs.map((c) => new GithubIntegration(c)),
14
+ (i) => i.config.host
15
+ );
16
+ };
14
17
  get type() {
15
18
  return "github";
16
19
  }
@@ -31,18 +34,7 @@ const _GithubIntegration = class _GithubIntegration {
31
34
  isRateLimited: response.status === 429 || response.status === 403 && response.headers.get("x-ratelimit-remaining") === "0"
32
35
  };
33
36
  }
34
- };
35
- __publicField(_GithubIntegration, "factory", ({ config }) => {
36
- var _a;
37
- const configs = readGithubIntegrationConfigs(
38
- (_a = config.getOptionalConfigArray("integrations.github")) != null ? _a : []
39
- );
40
- return basicIntegrations(
41
- configs.map((c) => new _GithubIntegration(c)),
42
- (i) => i.config.host
43
- );
44
- });
45
- let GithubIntegration = _GithubIntegration;
37
+ }
46
38
  function replaceGithubUrlType(url, type) {
47
39
  return url.replace(
48
40
  /\/\/([^/]+)\/([^/]+)\/([^/]+)\/(blob|tree|edit)\//,
@@ -1 +1 @@
1
- {"version":3,"file":"GithubIntegration.esm.js","sources":["../../src/github/GithubIntegration.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport {\n RateLimitInfo,\n ScmIntegration,\n ScmIntegrationsFactory,\n} from '../types';\nimport {\n GithubIntegrationConfig,\n readGithubIntegrationConfigs,\n} from './config';\nimport { ConsumedResponse } from '@backstage/errors';\n\n/**\n * A GitHub based integration.\n *\n * @public\n */\nexport class GithubIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<GithubIntegration> = ({ config }) => {\n const configs = readGithubIntegrationConfigs(\n config.getOptionalConfigArray('integrations.github') ?? [],\n );\n return basicIntegrations(\n configs.map(c => new GithubIntegration(c)),\n i => i.config.host,\n );\n };\n\n constructor(private readonly integrationConfig: GithubIntegrationConfig) {}\n\n get type(): string {\n return 'github';\n }\n\n get title(): string {\n return this.integrationConfig.host;\n }\n\n get config(): GithubIntegrationConfig {\n return this.integrationConfig;\n }\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n }): string {\n // GitHub uses blob URLs for files and tree urls for directory listings. But\n // there is a redirect from tree to blob for files, so we can always return\n // tree urls here.\n return replaceGithubUrlType(defaultScmResolveUrl(options), 'tree');\n }\n\n resolveEditUrl(url: string): string {\n return replaceGithubUrlType(url, 'edit');\n }\n\n parseRateLimitInfo(response: ConsumedResponse): RateLimitInfo {\n return {\n isRateLimited:\n response.status === 429 ||\n (response.status === 403 &&\n response.headers.get('x-ratelimit-remaining') === '0'),\n };\n }\n}\n\n/**\n * Takes a GitHub URL and replaces the type part (blob, tree etc).\n *\n * @param url - The original URL\n * @param type - The desired type, e.g. \"blob\"\n * @public\n */\nexport function replaceGithubUrlType(\n url: string,\n type: 'blob' | 'tree' | 'edit',\n): string {\n return url.replace(\n /\\/\\/([^/]+)\\/([^/]+)\\/([^/]+)\\/(blob|tree|edit)\\//,\n (_, host, owner, repo) => {\n return `//${host}/${owner}/${repo}/${type}/`;\n },\n );\n}\n"],"names":[],"mappings":";;;;;;;;;AAiCO,MAAM,kBAAA,GAAN,MAAM,kBAA4C,CAAA;AAAA,EAWvD,YAA6B,iBAA4C,EAAA;AAA5C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA,CAAA;AAAA,GAA6C;AAAA,EAE1E,IAAI,IAAe,GAAA;AACjB,IAAO,OAAA,QAAA,CAAA;AAAA,GACT;AAAA,EAEA,IAAI,KAAgB,GAAA;AAClB,IAAA,OAAO,KAAK,iBAAkB,CAAA,IAAA,CAAA;AAAA,GAChC;AA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K,IAAI,CAAA,CAAA,EAAI,KAAK,CAAI,CAAA,EAAA,IAAI,IAAI,IAAI,CAAA,CAAA,CAAA,CAAA;AAAA,KAC3C;AAAA,GACF,CAAA;AACF;;;;"}
1
+ {"version":3,"file":"GithubIntegration.esm.js","sources":["../../src/github/GithubIntegration.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport {\n RateLimitInfo,\n ScmIntegration,\n ScmIntegrationsFactory,\n} from '../types';\nimport {\n GithubIntegrationConfig,\n readGithubIntegrationConfigs,\n} from './config';\nimport { ConsumedResponse } from '@backstage/errors';\n\n/**\n * A GitHub based integration.\n *\n * @public\n */\nexport class GithubIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<GithubIntegration> = ({ config }) => {\n const configs = readGithubIntegrationConfigs(\n config.getOptionalConfigArray('integrations.github') ?? [],\n );\n return basicIntegrations(\n configs.map(c => new GithubIntegration(c)),\n i => i.config.host,\n );\n };\n\n constructor(private readonly integrationConfig: GithubIntegrationConfig) {}\n\n get type(): string {\n return 'github';\n }\n\n get title(): string {\n return this.integrationConfig.host;\n }\n\n get config(): GithubIntegrationConfig {\n return this.integrationConfig;\n }\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n }): string {\n // GitHub uses blob URLs for files and tree urls for directory listings. But\n // there is a redirect from tree to blob for files, so we can always return\n // tree urls here.\n return replaceGithubUrlType(defaultScmResolveUrl(options), 'tree');\n }\n\n resolveEditUrl(url: string): string {\n return replaceGithubUrlType(url, 'edit');\n }\n\n parseRateLimitInfo(response: ConsumedResponse): RateLimitInfo {\n return {\n isRateLimited:\n response.status === 429 ||\n (response.status === 403 &&\n response.headers.get('x-ratelimit-remaining') === '0'),\n };\n }\n}\n\n/**\n * Takes a GitHub URL and replaces the type part (blob, tree etc).\n *\n * @param url - The original URL\n * @param type - The desired type, e.g. \"blob\"\n * @public\n */\nexport function replaceGithubUrlType(\n url: string,\n type: 'blob' | 'tree' | 'edit',\n): string {\n return url.replace(\n /\\/\\/([^/]+)\\/([^/]+)\\/([^/]+)\\/(blob|tree|edit)\\//,\n (_, host, owner, repo) => {\n return `//${host}/${owner}/${repo}/${type}/`;\n },\n );\n}\n"],"names":[],"mappings":";;;AAiCO,MAAM,iBAA4C,CAAA;AAAA,EAWvD,YAA6B,iBAA4C,EAAA;AAA5C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA,CAAA;AAAA,GAA6C;AAAA,EAV1E,OAAO,OAAA,GAAqD,CAAC,EAAE,QAAa,KAAA;AAC1E,IAAA,MAAM,OAAU,GAAA,4BAAA;AAAA,MACd,MAAO,CAAA,sBAAA,CAAuB,qBAAqB,CAAA,IAAK,EAAC;AAAA,KAC3D,CAAA;AACA,IAAO,OAAA,iBAAA;AAAA,MACL,QAAQ,GAAI,CAAA,CAAA,CAAA,KAAK,IAAI,iBAAA,CAAkB,CAAC,CAAC,CAAA;AAAA,MACzC,CAAA,CAAA,KAAK,EAAE,MAAO,CAAA,IAAA;AAAA,KAChB,CAAA;AAAA,GACF,CAAA;AAAA,EAIA,IAAI,IAAe,GAAA;AACjB,IAAO,OAAA,QAAA,CAAA;AAAA,GACT;AAAA,EAEA,IAAI,KAAgB,GAAA;AAClB,IAAA,OAAO,KAAK,iBAAkB,CAAA,IAAA,CAAA;AAAA,GAChC;AAAA,EAEA,IAAI,MAAkC,GAAA;AACpC,IAAA,OAAO,IAAK,CAAA,iBAAA,CAAA;AAAA,GACd;AAAA,EAEA,WAAW,OAIA,EAAA;AAIT,IAAA,OAAO,oBAAqB,CAAA,oBAAA,CAAqB,OAAO,CAAA,EAAG,MAAM,CAAA,CAAA;AAAA,GACnE;AAAA,EAEA,eAAe,GAAqB,EAAA;AAClC,IAAO,OAAA,oBAAA,CAAqB,KAAK,MAAM,CAAA,CAAA;AAAA,GACzC;AAAA,EAEA,mBAAmB,QAA2C,EAAA;AAC5D,IAAO,OAAA;AAAA,MACL,aAAA,EACE,QAAS,CAAA,MAAA,KAAW,GACnB,IAAA,QAAA,CAAS,MAAW,KAAA,GAAA,IACnB,QAAS,CAAA,OAAA,CAAQ,GAAI,CAAA,uBAAuB,CAAM,KAAA,GAAA;AAAA,KACxD,CAAA;AAAA,GACF;AACF,CAAA;AASgB,SAAA,oBAAA,CACd,KACA,IACQ,EAAA;AACR,EAAA,OAAO,GAAI,CAAA,OAAA;AAAA,IACT,mDAAA;AAAA,IACA,CAAC,CAAA,EAAG,IAAM,EAAA,KAAA,EAAO,IAAS,KAAA;AACxB,MAAA,OAAO,KAAK,IAAI,CAAA,CAAA,EAAI,KAAK,CAAI,CAAA,EAAA,IAAI,IAAI,IAAI,CAAA,CAAA,CAAA,CAAA;AAAA,KAC3C;AAAA,GACF,CAAA;AACF;;;;"}
@@ -3,17 +3,8 @@ import { createAppAuth } from '@octokit/auth-app';
3
3
  import { Octokit } from '@octokit/rest';
4
4
  import { DateTime } from 'luxon';
5
5
 
6
- var __defProp = Object.defineProperty;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __publicField = (obj, key, value) => {
9
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
- return value;
11
- };
12
6
  class Cache {
13
- constructor() {
14
- __publicField(this, "tokenCache", /* @__PURE__ */ new Map());
15
- __publicField(this, "isExpired", (date) => DateTime.local() > date);
16
- }
7
+ tokenCache = /* @__PURE__ */ new Map();
17
8
  async getOrCreateToken(owner, repo, supplier) {
18
9
  let existingInstallationData = this.tokenCache.get(owner);
19
10
  if (!existingInstallationData || this.isExpired(existingInstallationData.expiresAt)) {
@@ -28,6 +19,7 @@ class Cache {
28
19
  }
29
20
  return { accessToken: existingInstallationData.token };
30
21
  }
22
+ isExpired = (date) => DateTime.local() > date;
31
23
  appliesToRepo(tokenData, repo) {
32
24
  if (repo === void 0) {
33
25
  return true;
@@ -42,13 +34,13 @@ const HEADERS = {
42
34
  Accept: "application/vnd.github.machine-man-preview+json"
43
35
  };
44
36
  class GithubAppManager {
37
+ appClient;
38
+ baseUrl;
39
+ baseAuthConfig;
40
+ cache = new Cache();
41
+ allowedInstallationOwners;
45
42
  // undefined allows all installations
46
43
  constructor(config, baseUrl) {
47
- __publicField(this, "appClient");
48
- __publicField(this, "baseUrl");
49
- __publicField(this, "baseAuthConfig");
50
- __publicField(this, "cache", new Cache());
51
- __publicField(this, "allowedInstallationOwners");
52
44
  this.allowedInstallationOwners = config.allowedInstallationOwners;
53
45
  this.baseUrl = baseUrl;
54
46
  this.baseAuthConfig = {
@@ -63,14 +55,12 @@ class GithubAppManager {
63
55
  });
64
56
  }
65
57
  async getInstallationCredentials(owner, repo) {
66
- var _a;
67
58
  if (this.allowedInstallationOwners) {
68
- if (!((_a = this.allowedInstallationOwners) == null ? void 0 : _a.includes(owner))) {
59
+ if (!this.allowedInstallationOwners?.includes(owner)) {
69
60
  return { accessToken: void 0 };
70
61
  }
71
62
  }
72
63
  return this.cache.getOrCreateToken(owner, repo, async () => {
73
- var _a2;
74
64
  const { installationId, suspended } = await this.getInstallationData(
75
65
  owner
76
66
  );
@@ -90,7 +80,7 @@ class GithubAppManager {
90
80
  const repos = await installationClient.paginate(
91
81
  installationClient.apps.listReposAccessibleToInstallation
92
82
  );
93
- const repositories = (_a2 = repos.repositories) != null ? _a2 : repos;
83
+ const repositories = repos.repositories ?? repos;
94
84
  repositoryNames = repositories.map((repository) => repository.name);
95
85
  }
96
86
  return {
@@ -106,10 +96,7 @@ class GithubAppManager {
106
96
  async getInstallationData(owner) {
107
97
  const allInstallations = await this.getInstallations();
108
98
  const installation = allInstallations.find(
109
- (inst) => {
110
- var _a;
111
- return inst.account && "login" in inst.account && ((_a = inst.account.login) == null ? void 0 : _a.toLocaleLowerCase("en-US")) === owner.toLocaleLowerCase("en-US");
112
- }
99
+ (inst) => inst.account && "login" in inst.account && inst.account.login?.toLocaleLowerCase("en-US") === owner.toLocaleLowerCase("en-US")
113
100
  );
114
101
  if (installation) {
115
102
  return {
@@ -125,10 +112,9 @@ class GithubAppManager {
125
112
  }
126
113
  }
127
114
  class GithubAppCredentialsMux {
115
+ apps;
128
116
  constructor(config) {
129
- __publicField(this, "apps");
130
- var _a, _b;
131
- this.apps = (_b = (_a = config.apps) == null ? void 0 : _a.map((ac) => new GithubAppManager(ac, config.apiBaseUrl))) != null ? _b : [];
117
+ this.apps = config.apps?.map((ac) => new GithubAppManager(ac, config.apiBaseUrl)) ?? [];
132
118
  }
133
119
  async getAllInstallations() {
134
120
  if (!this.apps.length) {
@@ -152,27 +138,30 @@ class GithubAppCredentialsMux {
152
138
  )
153
139
  );
154
140
  const result = results.find(
155
- (resultItem) => {
156
- var _a;
157
- return (_a = resultItem.credentials) == null ? void 0 : _a.accessToken;
158
- }
141
+ (resultItem) => resultItem.credentials?.accessToken
159
142
  );
160
143
  if (result) {
161
144
  return result.credentials.accessToken;
162
145
  }
163
146
  const errors = results.map((r) => r.error);
164
- const notNotFoundError = errors.find((err) => (err == null ? void 0 : err.name) !== "NotFoundError");
147
+ const notNotFoundError = errors.find((err) => err?.name !== "NotFoundError");
165
148
  if (notNotFoundError) {
166
149
  throw notNotFoundError;
167
150
  }
168
151
  return void 0;
169
152
  }
170
153
  }
171
- const _SingleInstanceGithubCredentialsProvider = class _SingleInstanceGithubCredentialsProvider {
154
+ class SingleInstanceGithubCredentialsProvider {
172
155
  constructor(githubAppCredentialsMux, token) {
173
156
  this.githubAppCredentialsMux = githubAppCredentialsMux;
174
157
  this.token = token;
175
158
  }
159
+ static create = (config) => {
160
+ return new SingleInstanceGithubCredentialsProvider(
161
+ new GithubAppCredentialsMux(config),
162
+ config.token
163
+ );
164
+ };
176
165
  /**
177
166
  * Returns {@link GithubCredentials} for a given URL.
178
167
  *
@@ -209,14 +198,7 @@ const _SingleInstanceGithubCredentialsProvider = class _SingleInstanceGithubCred
209
198
  type
210
199
  };
211
200
  }
212
- };
213
- __publicField(_SingleInstanceGithubCredentialsProvider, "create", (config) => {
214
- return new _SingleInstanceGithubCredentialsProvider(
215
- new GithubAppCredentialsMux(config),
216
- config.token
217
- );
218
- });
219
- let SingleInstanceGithubCredentialsProvider = _SingleInstanceGithubCredentialsProvider;
201
+ }
220
202
 
221
203
  export { GithubAppCredentialsMux, SingleInstanceGithubCredentialsProvider };
222
204
  //# sourceMappingURL=SingleInstanceGithubCredentialsProvider.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SingleInstanceGithubCredentialsProvider.esm.js","sources":["../../src/github/SingleInstanceGithubCredentialsProvider.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport parseGitUrl from 'git-url-parse';\nimport { GithubAppConfig, GithubIntegrationConfig } from './config';\nimport { createAppAuth } from '@octokit/auth-app';\nimport { Octokit, RestEndpointMethodTypes } from '@octokit/rest';\nimport { DateTime } from 'luxon';\nimport {\n GithubCredentials,\n GithubCredentialsProvider,\n GithubCredentialType,\n} from './types';\n\ntype InstallationData = {\n installationId: number;\n suspended: boolean;\n};\n\ntype InstallationTokenData = {\n token: string;\n expiresAt: DateTime;\n repositories?: String[];\n};\n\nclass Cache {\n private readonly tokenCache = new Map<string, InstallationTokenData>();\n\n async getOrCreateToken(\n owner: string,\n repo: string | undefined,\n supplier: () => Promise<InstallationTokenData>,\n ): Promise<{ accessToken: string }> {\n let existingInstallationData = this.tokenCache.get(owner);\n\n if (\n !existingInstallationData ||\n this.isExpired(existingInstallationData.expiresAt)\n ) {\n existingInstallationData = await supplier();\n // Allow 10 minutes grace to account for clock skew\n existingInstallationData.expiresAt =\n existingInstallationData.expiresAt.minus({ minutes: 10 });\n this.tokenCache.set(owner, existingInstallationData);\n }\n\n if (!this.appliesToRepo(existingInstallationData, repo)) {\n throw new Error(\n `The Backstage GitHub application used in the ${owner} organization does not have access to a repository with the name ${repo}`,\n );\n }\n\n return { accessToken: existingInstallationData.token };\n }\n\n private isExpired = (date: DateTime) => DateTime.local() > date;\n\n private appliesToRepo(tokenData: InstallationTokenData, repo?: string) {\n // If no specific repo has been requested the token is applicable\n if (repo === undefined) {\n return true;\n }\n // If the token is restricted to repositories, the token only applies if the repo is in the allow list\n if (tokenData.repositories !== undefined) {\n return tokenData.repositories.includes(repo);\n }\n // Otherwise the token is applicable\n return true;\n }\n}\n\n/**\n * This accept header is required when calling App APIs in GitHub Enterprise.\n * It has no effect on calls to github.com and can probably be removed entirely\n * once GitHub Apps is out of preview.\n */\nconst HEADERS = {\n Accept: 'application/vnd.github.machine-man-preview+json',\n};\n\n/**\n * GithubAppManager issues and caches tokens for a specific GitHub App.\n */\nclass GithubAppManager {\n private readonly appClient: Octokit;\n private readonly baseUrl?: string;\n private readonly baseAuthConfig: { appId: number; privateKey: string };\n private readonly cache = new Cache();\n private readonly allowedInstallationOwners: string[] | undefined; // undefined allows all installations\n\n constructor(config: GithubAppConfig, baseUrl?: string) {\n this.allowedInstallationOwners = config.allowedInstallationOwners;\n this.baseUrl = baseUrl;\n this.baseAuthConfig = {\n appId: config.appId,\n privateKey: config.privateKey.replace(/\\\\n/gm, '\\n'),\n };\n this.appClient = new Octokit({\n baseUrl,\n headers: HEADERS,\n authStrategy: createAppAuth,\n auth: this.baseAuthConfig,\n });\n }\n\n async getInstallationCredentials(\n owner: string,\n repo?: string,\n ): Promise<{ accessToken: string | undefined }> {\n if (this.allowedInstallationOwners) {\n if (!this.allowedInstallationOwners?.includes(owner)) {\n return { accessToken: undefined }; // An empty token allows anonymous access to public repos\n }\n }\n\n // Go and grab an access token for the app scoped to a repository if provided, if not use the organisation installation.\n return this.cache.getOrCreateToken(owner, repo, async () => {\n const { installationId, suspended } = await this.getInstallationData(\n owner,\n );\n if (suspended) {\n throw new Error(`The GitHub application for ${owner} is suspended`);\n }\n\n const result = await this.appClient.apps.createInstallationAccessToken({\n installation_id: installationId,\n headers: HEADERS,\n });\n\n let repositoryNames;\n\n if (result.data.repository_selection === 'selected') {\n const installationClient = new Octokit({\n baseUrl: this.baseUrl,\n auth: result.data.token,\n });\n const repos = await installationClient.paginate(\n installationClient.apps.listReposAccessibleToInstallation,\n );\n // The return type of the paginate method is incorrect.\n const repositories: RestEndpointMethodTypes['apps']['listReposAccessibleToInstallation']['response']['data']['repositories'] =\n repos.repositories ?? repos;\n\n repositoryNames = repositories.map(repository => repository.name);\n }\n return {\n token: result.data.token,\n expiresAt: DateTime.fromISO(result.data.expires_at),\n repositories: repositoryNames,\n };\n });\n }\n\n getInstallations(): Promise<\n RestEndpointMethodTypes['apps']['listInstallations']['response']['data']\n > {\n return this.appClient.paginate(this.appClient.apps.listInstallations);\n }\n\n private async getInstallationData(owner: string): Promise<InstallationData> {\n const allInstallations = await this.getInstallations();\n const installation = allInstallations.find(\n inst =>\n inst.account &&\n 'login' in inst.account &&\n inst.account.login?.toLocaleLowerCase('en-US') ===\n owner.toLocaleLowerCase('en-US'),\n );\n if (installation) {\n return {\n installationId: installation.id,\n suspended: Boolean(installation.suspended_by),\n };\n }\n const notFoundError = new Error(\n `No app installation found for ${owner} in ${this.baseAuthConfig.appId}`,\n );\n notFoundError.name = 'NotFoundError';\n throw notFoundError;\n }\n}\n\n/**\n * Corresponds to a Github installation which internally could hold several GitHub Apps.\n *\n * @public\n */\nexport class GithubAppCredentialsMux {\n private readonly apps: GithubAppManager[];\n\n constructor(config: GithubIntegrationConfig) {\n this.apps =\n config.apps?.map(ac => new GithubAppManager(ac, config.apiBaseUrl)) ?? [];\n }\n\n async getAllInstallations(): Promise<\n RestEndpointMethodTypes['apps']['listInstallations']['response']['data']\n > {\n if (!this.apps.length) {\n return [];\n }\n\n const installs = await Promise.all(\n this.apps.map(app => app.getInstallations()),\n );\n\n return installs.flat();\n }\n\n async getAppToken(owner: string, repo?: string): Promise<string | undefined> {\n if (this.apps.length === 0) {\n return undefined;\n }\n\n const results = await Promise.all(\n this.apps.map(app =>\n app.getInstallationCredentials(owner, repo).then(\n credentials => ({ credentials, error: undefined }),\n error => ({ credentials: undefined, error }),\n ),\n ),\n );\n\n const result = results.find(\n resultItem => resultItem.credentials?.accessToken,\n );\n if (result) {\n return result.credentials!.accessToken;\n }\n\n const errors = results.map(r => r.error);\n const notNotFoundError = errors.find(err => err?.name !== 'NotFoundError');\n if (notNotFoundError) {\n throw notNotFoundError;\n }\n\n return undefined;\n }\n}\n\n/**\n * Handles the creation and caching of credentials for GitHub integrations.\n *\n * @public\n * @remarks\n *\n * TODO: Possibly move this to a backend only package so that it's not used in the frontend by mistake\n */\nexport class SingleInstanceGithubCredentialsProvider\n implements GithubCredentialsProvider\n{\n static create: (\n config: GithubIntegrationConfig,\n ) => GithubCredentialsProvider = config => {\n return new SingleInstanceGithubCredentialsProvider(\n new GithubAppCredentialsMux(config),\n config.token,\n );\n };\n\n private constructor(\n private readonly githubAppCredentialsMux: GithubAppCredentialsMux,\n private readonly token?: string,\n ) {}\n\n /**\n * Returns {@link GithubCredentials} for a given URL.\n *\n * @remarks\n *\n * Consecutive calls to this method with the same URL will return cached\n * credentials.\n *\n * The shortest lifetime for a token returned is 10 minutes.\n *\n * @example\n * ```ts\n * const { token, headers } = await getCredentials({\n * url: 'github.com/backstage/foobar'\n * })\n * ```\n *\n * @param opts - The organization or repository URL\n * @returns A promise of {@link GithubCredentials}.\n */\n async getCredentials(opts: { url: string }): Promise<GithubCredentials> {\n const parsed = parseGitUrl(opts.url);\n\n const owner = parsed.owner || parsed.name;\n const repo = parsed.owner ? parsed.name : undefined;\n\n let type: GithubCredentialType = 'app';\n let token = await this.githubAppCredentialsMux.getAppToken(owner, repo);\n if (!token) {\n type = 'token';\n token = this.token;\n }\n\n return {\n headers: token ? { Authorization: `Bearer ${token}` } : undefined,\n token,\n type,\n };\n }\n}\n"],"names":["_a"],"mappings":";;;;;;;;;;;AAsCA,MAAM,KAAM,CAAA;AAAA,EAAZ,WAAA,GAAA;AACE,IAAiB,aAAA,CAAA,IAAA,EAAA,YAAA,sBAAiB,GAAmC,EAAA,CAAA,CAAA;AA6BrE,IAAA,aAAA,CAAA,IAAA,EAAQ,WAAY,EAAA,CAAC,IAAmB,KAAA,QAAA,CAAS,OAAU,GAAA,IAAA,CAAA,CAAA;AAAA,GAAA;AAAA,EA3B3D,MAAM,gBAAA,CACJ,KACA,EAAA,IAAA,EACA,QACkC,EAAA;AAClC,IAAA,IAAI,wBAA2B,GAAA,IAAA,CAAK,UAAW,CAAA,GAAA,CAAI,KAAK,CAAA,CAAA;AAExD,IAAA,IACE,CAAC,wBACD,IAAA,IAAA,CAAK,SAAU,CAAA,wBAAA,CAAyB,SAAS,CACjD,EAAA;AACA,MAAA,wBAAA,GAA2B,MAAM,QAAS,EAAA,CAAA;AAE1C,MAAA,wBAAA,CAAyB,YACvB,wBAAyB,CAAA,SAAA,CAAU,MAAM,EAAE,OAAA,EAAS,IAAI,CAAA,CAAA;AAC1D,MAAK,IAAA,CAAA,UAAA,CAAW,GAAI,CAAA,KAAA,EAAO,wBAAwB,CAAA,CAAA;AAAA,KACrD;AAEA,IAAA,IAAI,CAAC,IAAA,CAAK,aAAc,CAAA,wBAAA,EAA0B,IAAI,CAAG,EAAA;AACvD,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,6CAAA,EAAgD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AAA,IACT,IAAI,wBAAwB,MAAM,CAAA;AAAA,IAClC,MAAO,CAAA,KAAA;AAAA,GACT,CAAA;AACF,CAAA,CAAA,CAAA;AAVK,IAAM,uCAAN,GAAA;;;;"}
1
+ {"version":3,"file":"SingleInstanceGithubCredentialsProvider.esm.js","sources":["../../src/github/SingleInstanceGithubCredentialsProvider.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport parseGitUrl from 'git-url-parse';\nimport { GithubAppConfig, GithubIntegrationConfig } from './config';\nimport { createAppAuth } from '@octokit/auth-app';\nimport { Octokit, RestEndpointMethodTypes } from '@octokit/rest';\nimport { DateTime } from 'luxon';\nimport {\n GithubCredentials,\n GithubCredentialsProvider,\n GithubCredentialType,\n} from './types';\n\ntype InstallationData = {\n installationId: number;\n suspended: boolean;\n};\n\ntype InstallationTokenData = {\n token: string;\n expiresAt: DateTime;\n repositories?: String[];\n};\n\nclass Cache {\n private readonly tokenCache = new Map<string, InstallationTokenData>();\n\n async getOrCreateToken(\n owner: string,\n repo: string | undefined,\n supplier: () => Promise<InstallationTokenData>,\n ): Promise<{ accessToken: string }> {\n let existingInstallationData = this.tokenCache.get(owner);\n\n if (\n !existingInstallationData ||\n this.isExpired(existingInstallationData.expiresAt)\n ) {\n existingInstallationData = await supplier();\n // Allow 10 minutes grace to account for clock skew\n existingInstallationData.expiresAt =\n existingInstallationData.expiresAt.minus({ minutes: 10 });\n this.tokenCache.set(owner, existingInstallationData);\n }\n\n if (!this.appliesToRepo(existingInstallationData, repo)) {\n throw new Error(\n `The Backstage GitHub application used in the ${owner} organization does not have access to a repository with the name ${repo}`,\n );\n }\n\n return { accessToken: existingInstallationData.token };\n }\n\n private isExpired = (date: DateTime) => DateTime.local() > date;\n\n private appliesToRepo(tokenData: InstallationTokenData, repo?: string) {\n // If no specific repo has been requested the token is applicable\n if (repo === undefined) {\n return true;\n }\n // If the token is restricted to repositories, the token only applies if the repo is in the allow list\n if (tokenData.repositories !== undefined) {\n return tokenData.repositories.includes(repo);\n }\n // Otherwise the token is applicable\n return true;\n }\n}\n\n/**\n * This accept header is required when calling App APIs in GitHub Enterprise.\n * It has no effect on calls to github.com and can probably be removed entirely\n * once GitHub Apps is out of preview.\n */\nconst HEADERS = {\n Accept: 'application/vnd.github.machine-man-preview+json',\n};\n\n/**\n * GithubAppManager issues and caches tokens for a specific GitHub App.\n */\nclass GithubAppManager {\n private readonly appClient: Octokit;\n private readonly baseUrl?: string;\n private readonly baseAuthConfig: { appId: number; privateKey: string };\n private readonly cache = new Cache();\n private readonly allowedInstallationOwners: string[] | undefined; // undefined allows all installations\n\n constructor(config: GithubAppConfig, baseUrl?: string) {\n this.allowedInstallationOwners = config.allowedInstallationOwners;\n this.baseUrl = baseUrl;\n this.baseAuthConfig = {\n appId: config.appId,\n privateKey: config.privateKey.replace(/\\\\n/gm, '\\n'),\n };\n this.appClient = new Octokit({\n baseUrl,\n headers: HEADERS,\n authStrategy: createAppAuth,\n auth: this.baseAuthConfig,\n });\n }\n\n async getInstallationCredentials(\n owner: string,\n repo?: string,\n ): Promise<{ accessToken: string | undefined }> {\n if (this.allowedInstallationOwners) {\n if (!this.allowedInstallationOwners?.includes(owner)) {\n return { accessToken: undefined }; // An empty token allows anonymous access to public repos\n }\n }\n\n // Go and grab an access token for the app scoped to a repository if provided, if not use the organisation installation.\n return this.cache.getOrCreateToken(owner, repo, async () => {\n const { installationId, suspended } = await this.getInstallationData(\n owner,\n );\n if (suspended) {\n throw new Error(`The GitHub application for ${owner} is suspended`);\n }\n\n const result = await this.appClient.apps.createInstallationAccessToken({\n installation_id: installationId,\n headers: HEADERS,\n });\n\n let repositoryNames;\n\n if (result.data.repository_selection === 'selected') {\n const installationClient = new Octokit({\n baseUrl: this.baseUrl,\n auth: result.data.token,\n });\n const repos = await installationClient.paginate(\n installationClient.apps.listReposAccessibleToInstallation,\n );\n // The return type of the paginate method is incorrect.\n const repositories: RestEndpointMethodTypes['apps']['listReposAccessibleToInstallation']['response']['data']['repositories'] =\n repos.repositories ?? repos;\n\n repositoryNames = repositories.map(repository => repository.name);\n }\n return {\n token: result.data.token,\n expiresAt: DateTime.fromISO(result.data.expires_at),\n repositories: repositoryNames,\n };\n });\n }\n\n getInstallations(): Promise<\n RestEndpointMethodTypes['apps']['listInstallations']['response']['data']\n > {\n return this.appClient.paginate(this.appClient.apps.listInstallations);\n }\n\n private async getInstallationData(owner: string): Promise<InstallationData> {\n const allInstallations = await this.getInstallations();\n const installation = allInstallations.find(\n inst =>\n inst.account &&\n 'login' in inst.account &&\n inst.account.login?.toLocaleLowerCase('en-US') ===\n owner.toLocaleLowerCase('en-US'),\n );\n if (installation) {\n return {\n installationId: installation.id,\n suspended: Boolean(installation.suspended_by),\n };\n }\n const notFoundError = new Error(\n `No app installation found for ${owner} in ${this.baseAuthConfig.appId}`,\n );\n notFoundError.name = 'NotFoundError';\n throw notFoundError;\n }\n}\n\n/**\n * Corresponds to a Github installation which internally could hold several GitHub Apps.\n *\n * @public\n */\nexport class GithubAppCredentialsMux {\n private readonly apps: GithubAppManager[];\n\n constructor(config: GithubIntegrationConfig) {\n this.apps =\n config.apps?.map(ac => new GithubAppManager(ac, config.apiBaseUrl)) ?? [];\n }\n\n async getAllInstallations(): Promise<\n RestEndpointMethodTypes['apps']['listInstallations']['response']['data']\n > {\n if (!this.apps.length) {\n return [];\n }\n\n const installs = await Promise.all(\n this.apps.map(app => app.getInstallations()),\n );\n\n return installs.flat();\n }\n\n async getAppToken(owner: string, repo?: string): Promise<string | undefined> {\n if (this.apps.length === 0) {\n return undefined;\n }\n\n const results = await Promise.all(\n this.apps.map(app =>\n app.getInstallationCredentials(owner, repo).then(\n credentials => ({ credentials, error: undefined }),\n error => ({ credentials: undefined, error }),\n ),\n ),\n );\n\n const result = results.find(\n resultItem => resultItem.credentials?.accessToken,\n );\n if (result) {\n return result.credentials!.accessToken;\n }\n\n const errors = results.map(r => r.error);\n const notNotFoundError = errors.find(err => err?.name !== 'NotFoundError');\n if (notNotFoundError) {\n throw notNotFoundError;\n }\n\n return undefined;\n }\n}\n\n/**\n * Handles the creation and caching of credentials for GitHub integrations.\n *\n * @public\n * @remarks\n *\n * TODO: Possibly move this to a backend only package so that it's not used in the frontend by mistake\n */\nexport class SingleInstanceGithubCredentialsProvider\n implements GithubCredentialsProvider\n{\n static create: (\n config: GithubIntegrationConfig,\n ) => GithubCredentialsProvider = config => {\n return new SingleInstanceGithubCredentialsProvider(\n new GithubAppCredentialsMux(config),\n config.token,\n );\n };\n\n private constructor(\n private readonly githubAppCredentialsMux: GithubAppCredentialsMux,\n private readonly token?: string,\n ) {}\n\n /**\n * Returns {@link GithubCredentials} for a given URL.\n *\n * @remarks\n *\n * Consecutive calls to this method with the same URL will return cached\n * credentials.\n *\n * The shortest lifetime for a token returned is 10 minutes.\n *\n * @example\n * ```ts\n * const { token, headers } = await getCredentials({\n * url: 'github.com/backstage/foobar'\n * })\n * ```\n *\n * @param opts - The organization or repository URL\n * @returns A promise of {@link GithubCredentials}.\n */\n async getCredentials(opts: { url: string }): Promise<GithubCredentials> {\n const parsed = parseGitUrl(opts.url);\n\n const owner = parsed.owner || parsed.name;\n const repo = parsed.owner ? parsed.name : undefined;\n\n let type: GithubCredentialType = 'app';\n let token = await this.githubAppCredentialsMux.getAppToken(owner, repo);\n if (!token) {\n type = 'token';\n token = this.token;\n }\n\n return {\n headers: token ? { Authorization: `Bearer ${token}` } : undefined,\n token,\n type,\n };\n }\n}\n"],"names":[],"mappings":";;;;;AAsCA,MAAM,KAAM,CAAA;AAAA,EACO,UAAA,uBAAiB,GAAmC,E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B_API_BASE_URL = "https://api.github.com";
6
6
  const GITHUB_RAW_BASE_URL = "https://raw.githubusercontent.com";
7
7
  function readGithubIntegrationConfig(config) {
8
- var _a, _b, _c;
9
- const host = (_a = config.getOptionalString("host")) != null ? _a : GITHUB_HOST;
8
+ const host = config.getOptionalString("host") ?? GITHUB_HOST;
10
9
  let apiBaseUrl = config.getOptionalString("apiBaseUrl");
11
10
  let rawBaseUrl = config.getOptionalString("rawBaseUrl");
12
- const token = (_b = config.getOptionalString("token")) == null ? void 0 : _b.trim();
13
- const apps = (_c = config.getOptionalConfigArray("apps")) == null ? void 0 : _c.map((c) => ({
11
+ const token = config.getOptionalString("token")?.trim();
12
+ const apps = config.getOptionalConfigArray("apps")?.map((c) => ({
14
13
  appId: c.getNumber("appId"),
15
14
  clientId: c.getString("clientId"),
16
15
  clientSecret: c.getString("clientSecret"),
@@ -1 +1 @@
1
- {"version":3,"file":"config.esm.js","sources":["../../src/github/config.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\nimport { trimEnd } from 'lodash';\nimport { isValidHost } from '../helpers';\n\nconst GITHUB_HOST = 'github.com';\nconst GITHUB_API_BASE_URL = 'https://api.github.com';\nconst GITHUB_RAW_BASE_URL = 'https://raw.githubusercontent.com';\n\n/**\n * The configuration parameters for a single GitHub integration.\n *\n * @public\n */\nexport type GithubIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. \"github.com\"\n */\n host: string;\n\n /**\n * The base URL of the API of this provider, e.g. \"https://api.github.com\",\n * with no trailing slash.\n *\n * May be omitted specifically for GitHub; then it will be deduced.\n *\n * The API will always be preferred if both its base URL and a token are\n * present.\n */\n apiBaseUrl?: string;\n\n /**\n * The base URL of the raw fetch endpoint of this provider, e.g.\n * \"https://raw.githubusercontent.com\", with no trailing slash.\n *\n * May be omitted specifically for GitHub; then it will be deduced.\n *\n * The API will always be preferred if both its base URL and a token are\n * present.\n */\n rawBaseUrl?: string;\n\n /**\n * The authorization token to use for requests to this provider.\n *\n * If no token is specified, anonymous access is used.\n */\n token?: string;\n\n /**\n * The GitHub Apps configuration to use for requests to this provider.\n *\n * If no apps are specified, token or anonymous is used.\n */\n apps?: GithubAppConfig[];\n};\n\n/**\n * The configuration parameters for authenticating a GitHub Application.\n *\n * @remarks\n *\n * A GitHub Apps configuration can be generated using the `backstage-cli create-github-app` command.\n *\n * @public\n */\nexport type GithubAppConfig = {\n /**\n * Unique app identifier, found at https://github.com/organizations/$org/settings/apps/$AppName\n */\n appId: number;\n /**\n * The private key is used by the GitHub App integration to authenticate the app.\n * A private key can be generated from the app at https://github.com/organizations/$org/settings/apps/$AppName\n */\n privateKey: string;\n /**\n * Webhook secret can be configured at https://github.com/organizations/$org/settings/apps/$AppName\n */\n webhookSecret: string;\n /**\n * Found at https://github.com/organizations/$org/settings/apps/$AppName\n */\n clientId: string;\n /**\n * Client secrets can be generated at https://github.com/organizations/$org/settings/apps/$AppName\n */\n clientSecret: string;\n /**\n * List of installation owners allowed to be used by this GitHub app. The GitHub UI does not provide a way to list the installations.\n * However you can list the installations with the GitHub API. You can find the list of installations here:\n * https://api.github.com/app/installations\n * The relevant documentation for this is here.\n * https://docs.github.com/en/rest/reference/apps#list-installations-for-the-authenticated-app--code-samples\n */\n allowedInstallationOwners?: string[];\n};\n\n/**\n * Reads a single GitHub integration config.\n *\n * @param config - The config object of a single integration\n * @public\n */\nexport function readGithubIntegrationConfig(\n config: Config,\n): GithubIntegrationConfig {\n const host = config.getOptionalString('host') ?? GITHUB_HOST;\n let apiBaseUrl = config.getOptionalString('apiBaseUrl');\n let rawBaseUrl = config.getOptionalString('rawBaseUrl');\n const token = config.getOptionalString('token')?.trim();\n const apps = config.getOptionalConfigArray('apps')?.map(c => ({\n appId: c.getNumber('appId'),\n clientId: c.getString('clientId'),\n clientSecret: c.getString('clientSecret'),\n webhookSecret: c.getString('webhookSecret'),\n privateKey: c.getString('privateKey'),\n allowedInstallationOwners: c.getOptionalStringArray(\n 'allowedInstallationOwners',\n ),\n }));\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid GitHub integration config, '${host}' is not a valid host`,\n );\n }\n\n if (apiBaseUrl) {\n apiBaseUrl = trimEnd(apiBaseUrl, '/');\n } else if (host === GITHUB_HOST) {\n apiBaseUrl = GITHUB_API_BASE_URL;\n }\n\n if (rawBaseUrl) {\n rawBaseUrl = trimEnd(rawBaseUrl, '/');\n } else if (host === GITHUB_HOST) {\n rawBaseUrl = GITHUB_RAW_BASE_URL;\n }\n\n return { host, apiBaseUrl, rawBaseUrl, token, apps };\n}\n\n/**\n * Reads a set of GitHub integration configs, and inserts some defaults for\n * public GitHub if not specified.\n *\n * @param configs - All of the integration config objects\n * @public\n */\nexport function readGithubIntegrationConfigs(\n configs: Config[],\n): GithubIntegrationConfig[] {\n // First read all the explicit integrations\n const result = configs.map(readGithubIntegrationConfig);\n\n // If no explicit github.com integration was added, put one in the list as\n // a convenience\n if (!result.some(c => c.host === GITHUB_HOST)) {\n result.push({\n host: GITHUB_HOST,\n apiBaseUrl: GITHUB_API_BASE_URL,\n rawBaseUrl: GITHUB_RAW_BASE_URL,\n });\n }\n\n return result;\n}\n"],"names":[],"mappings":";;;AAoBA,MAAM,WAAc,GAAA,YAAA,CAAA;AACpB,MAAM,mBAAsB,GAAA,wBAAA,CAAA;AAC5B,MAAM,mBAAsB,GAAA,mCAAA,CAAA;AAiGrB,SAAS,4BACd,MACyB,EAAA;AAzH3B,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA;AA0HE,EAAA,MAAM,IAA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S,WAAa,EAAA;AAC/B,IAAa,UAAA,GAAA,mBAAA,CAAA;AAAA,GACf;AAEA,EAAA,IAAI,UAAY,EAAA;AACd,IAAa,UAAA,GAAA,OAAA,CAAQ,YAAY,GAAG,CAAA,CAAA;AAAA,GACtC,MAAA,IAAW,SAAS,WAAa,EAAA;AAC/B,IAAa,UAAA,GAAA,mBAAA,CAAA;AAAA,GACf;AAEA,EAAA,OAAO,EAAE,IAAA,EAAM,UAAY,EAAA,UAAA,EAAY,OAAO,IAAK,EAAA,CAAA;AACrD,CAAA;AASO,SAAS,6BACd,OAC2B,EAAA;AAE3B,EAAM,MAAA,MAAA,GAAS,OAAQ,CAAA,GAAA,CAAI,2BAA2B,CAAA,CAAA;AAItD,EAAA,IAAI,CAAC,MAAO,CAAA,IAAA,CAAK,OAAK,CAAE,CAAA,IAAA,KAAS,WAAW,CAAG,EAAA;AAC7C,IAAA,MAAA,CAAO,IAAK,CAAA;AAAA,MACV,IAAM,EAAA,WAAA;AAAA,MACN,UAAY,EAAA,mBAAA;AAAA,MACZ,UAAY,EAAA,mBAAA;AAAA,KACb,CAAA,CAAA;AAAA,GACH;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"config.esm.js","sources":["../../src/github/config.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\nimport { trimEnd } from 'lodash';\nimport { isValidHost } from '../helpers';\n\nconst GITHUB_HOST = 'github.com';\nconst GITHUB_API_BASE_URL = 'https://api.github.com';\nconst GITHUB_RAW_BASE_URL = 'https://raw.githubusercontent.com';\n\n/**\n * The configuration parameters for a single GitHub integration.\n *\n * @public\n */\nexport type GithubIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. \"github.com\"\n */\n host: string;\n\n /**\n * The base URL of the API of this provider, e.g. \"https://api.github.com\",\n * with no trailing slash.\n *\n * May be omitted specifically for GitHub; then it will be deduced.\n *\n * The API will always be preferred if both its base URL and a token are\n * present.\n */\n apiBaseUrl?: string;\n\n /**\n * The base URL of the raw fetch endpoint of this provider, e.g.\n * \"https://raw.githubusercontent.com\", with no trailing slash.\n *\n * May be omitted specifically for GitHub; then it will be deduced.\n *\n * The API will always be preferred if both its base URL and a token are\n * present.\n */\n rawBaseUrl?: string;\n\n /**\n * The authorization token to use for requests to this provider.\n *\n * If no token is specified, anonymous access is used.\n */\n token?: string;\n\n /**\n * The GitHub Apps configuration to use for requests to this provider.\n *\n * If no apps are specified, token or anonymous is used.\n */\n apps?: GithubAppConfig[];\n};\n\n/**\n * The configuration parameters for authenticating a GitHub Application.\n *\n * @remarks\n *\n * A GitHub Apps configuration can be generated using the `backstage-cli create-github-app` command.\n *\n * @public\n */\nexport type GithubAppConfig = {\n /**\n * Unique app identifier, found at https://github.com/organizations/$org/settings/apps/$AppName\n */\n appId: number;\n /**\n * The private key is used by the GitHub App integration to authenticate the app.\n * A private key can be generated from the app at https://github.com/organizations/$org/settings/apps/$AppName\n */\n privateKey: string;\n /**\n * Webhook secret can be configured at https://github.com/organizations/$org/settings/apps/$AppName\n */\n webhookSecret: string;\n /**\n * Found at https://github.com/organizations/$org/settings/apps/$AppName\n */\n clientId: string;\n /**\n * Client secrets can be generated at https://github.com/organizations/$org/settings/apps/$AppName\n */\n clientSecret: string;\n /**\n * List of installation owners allowed to be used by this GitHub app. The GitHub UI does not provide a way to list the installations.\n * However you can list the installations with the GitHub API. You can find the list of installations here:\n * https://api.github.com/app/installations\n * The relevant documentation for this is here.\n * https://docs.github.com/en/rest/reference/apps#list-installations-for-the-authenticated-app--code-samples\n */\n allowedInstallationOwners?: string[];\n};\n\n/**\n * Reads a single GitHub integration config.\n *\n * @param config - The config object of a single integration\n * @public\n */\nexport function readGithubIntegrationConfig(\n config: Config,\n): GithubIntegrationConfig {\n const host = config.getOptionalString('host') ?? GITHUB_HOST;\n let apiBaseUrl = config.getOptionalString('apiBaseUrl');\n let rawBaseUrl = config.getOptionalString('rawBaseUrl');\n const token = config.getOptionalString('token')?.trim();\n const apps = config.getOptionalConfigArray('apps')?.map(c => ({\n appId: c.getNumber('appId'),\n clientId: c.getString('clientId'),\n clientSecret: c.getString('clientSecret'),\n webhookSecret: c.getString('webhookSecret'),\n privateKey: c.getString('privateKey'),\n allowedInstallationOwners: c.getOptionalStringArray(\n 'allowedInstallationOwners',\n ),\n }));\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid GitHub integration config, '${host}' is not a valid host`,\n );\n }\n\n if (apiBaseUrl) {\n apiBaseUrl = trimEnd(apiBaseUrl, '/');\n } else if (host === GITHUB_HOST) {\n apiBaseUrl = GITHUB_API_BASE_URL;\n }\n\n if (rawBaseUrl) {\n rawBaseUrl = trimEnd(rawBaseUrl, '/');\n } else if (host === GITHUB_HOST) {\n rawBaseUrl = GITHUB_RAW_BASE_URL;\n }\n\n return { host, apiBaseUrl, rawBaseUrl, token, apps };\n}\n\n/**\n * Reads a set of GitHub integration configs, and inserts some defaults for\n * public GitHub if not specified.\n *\n * @param configs - All of the integration config objects\n * @public\n */\nexport function readGithubIntegrationConfigs(\n configs: Config[],\n): GithubIntegrationConfig[] {\n // First read all the explicit integrations\n const result = configs.map(readGithubIntegrationConfig);\n\n // If no explicit github.com integration was added, put one in the list as\n // a convenience\n if (!result.some(c => c.host === GITHUB_HOST)) {\n result.push({\n host: GITHUB_HOST,\n apiBaseUrl: GITHUB_API_BASE_URL,\n rawBaseUrl: GITHUB_RAW_BASE_URL,\n });\n }\n\n return result;\n}\n"],"names":[],"mappings":";;;AAoBA,MAAM,WAAc,GAAA,YAAA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AAC/B,IAAa,UAAA,GAAA,mBAAA,CAAA;AAAA,GACf;AAEA,EAAA,IAAI,UAAY,EAAA;AACd,IAAa,UAAA,GAAA,OAAA,CAAQ,YAAY,GAAG,CAAA,CAAA;AAAA,GACtC,MAAA,IAAW,SAAS,WAAa,EAAA;AAC/B,IAAa,UAAA,GAAA,mBAAA,CAAA;AAAA,GACf;AAEA,EAAA,OAAO,EAAE,IAAA,EAAM,UAAY,EAAA,UAAA,EAAY,OAAO,IAAK,EAAA,CAAA;AACrD,CAAA;AASO,SAAS,6BACd,OAC2B,EAAA;AAE3B,EAAM,MAAA,MAAA,GAAS,OAAQ,CAAA,GAAA,CAAI,2BAA2B,CAAA,CAAA;AAItD,EAAA,IAAI,CAAC,MAAO,CAAA,IAAA,CAAK,OAAK,CAAE,CAAA,IAAA,KAAS,WAAW,CAAG,EAAA;AAC7C,IAAA,MAAA,CAAO,IAAK,CAAA;AAAA,MACV,IAAM,EAAA,WAAA;AAAA,MACN,UAAY,EAAA,mBAAA;AAAA,MACZ,UAAY,EAAA,mBAAA;AAAA,KACb,CAAA,CAAA;AAAA,GACH;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
@@ -2,14 +2,9 @@ import { readGithubIntegrationConfig, readGithubIntegrationConfigs } from './con
2
2
  import { getGithubFileFetchUrl } from './core.esm.js';
3
3
  import { GithubIntegration, replaceGithubUrlType } from './GithubIntegration.esm.js';
4
4
 
5
- var __defProp = Object.defineProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __publicField = (obj, key, value) => {
8
- __defNormalProp(obj, key + "" , value);
9
- return value;
10
- };
11
5
  const getGitHubFileFetchUrl = getGithubFileFetchUrl;
12
6
  class GitHubIntegration extends GithubIntegration {
7
+ static factory = GithubIntegration.factory;
13
8
  constructor(integrationConfig) {
14
9
  super(integrationConfig);
15
10
  }
@@ -17,7 +12,6 @@ class GitHubIntegration extends GithubIntegration {
17
12
  return super.config;
18
13
  }
19
14
  }
20
- __publicField(GitHubIntegration, "factory", GithubIntegration.factory);
21
15
  const readGitHubIntegrationConfig = readGithubIntegrationConfig;
22
16
  const readGitHubIntegrationConfigs = readGithubIntegrationConfigs;
23
17
  const replaceGitHubUrlType = replaceGithubUrlType;
@@ -1 +1 @@
1
- {"version":3,"file":"deprecated.esm.js","sources":["../../src/github/deprecated.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n GithubIntegrationConfig,\n readGithubIntegrationConfig,\n readGithubIntegrationConfigs,\n} from './config';\nimport { getGithubFileFetchUrl } from './core';\nimport { GithubIntegration, replaceGithubUrlType } from './GithubIntegration';\nimport { ScmIntegrationsFactory } from '../types';\n\n/**\n * @public\n * @deprecated Use {@link getGithubFileFetchUrl} instead.\n */\nexport const getGitHubFileFetchUrl = getGithubFileFetchUrl;\n\n/**\n * @public\n * @deprecated Use {@link GithubIntegrationConfig} instead.\n */\nexport type GitHubIntegrationConfig = GithubIntegrationConfig;\n\n/**\n * @public\n * @deprecated Use {@link GithubIntegration} instead.\n */\nexport class GitHubIntegration extends GithubIntegration {\n static factory: ScmIntegrationsFactory<GitHubIntegration> =\n GithubIntegration.factory;\n\n constructor(integrationConfig: GitHubIntegrationConfig) {\n super(integrationConfig as GithubIntegrationConfig);\n }\n\n get config(): GitHubIntegrationConfig {\n return super.config as GitHubIntegrationConfig;\n }\n}\n\n/**\n * @public\n * @deprecated Use {@link readGithubIntegrationConfig} instead.\n */\nexport const readGitHubIntegrationConfig = readGithubIntegrationConfig;\n\n/**\n * @public\n * @deprecated Use {@link readGithubIntegrationConfigs} instead.\n */\nexport const readGitHubIntegrationConfigs = readGithubIntegrationConfigs;\n\n/**\n * @public\n * @deprecated Use {@link replaceGithubUrlType} instead.\n */\nexport const replaceGitHubUrlType = replaceGithubUrlType;\n"],"names":[],"mappings":";;;;;;;;;;AA6BO,MAAM,qBAAwB,GAAA,sBAAA;AAY9B,MAAM,0BAA0B,iBAAkB,CAAA;AAAA,EAIvD,YAAY,iBAA4C,EAAA;AACtD,IAAA,KAAA,CAAM,iBAA4C,CAAA,CAAA;AAAA,GACpD;AAAA,EAEA,IAAI,MAAkC,GAAA;AACpC,IAAA,OAAO,KAAM,CAAA,MAAA,CAAA;AAAA,GACf;AACF,CAAA;AAVE,aADW,CAAA,iBAAA,EACJ,WACL,iBAAkB,CAAA,OAAA,CAAA,CAAA;AAef,MAAM,2BAA8B,GAAA,4BAAA;AAMpC,MAAM,4BAA+B,GAAA,6BAAA;AAMrC,MAAM,oBAAuB,GAAA;;;;"}
1
+ {"version":3,"file":"deprecated.esm.js","sources":["../../src/github/deprecated.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n GithubIntegrationConfig,\n readGithubIntegrationConfig,\n readGithubIntegrationConfigs,\n} from './config';\nimport { getGithubFileFetchUrl } from './core';\nimport { GithubIntegration, replaceGithubUrlType } from './GithubIntegration';\nimport { ScmIntegrationsFactory } from '../types';\n\n/**\n * @public\n * @deprecated Use {@link getGithubFileFetchUrl} instead.\n */\nexport const getGitHubFileFetchUrl = getGithubFileFetchUrl;\n\n/**\n * @public\n * @deprecated Use {@link GithubIntegrationConfig} instead.\n */\nexport type GitHubIntegrationConfig = GithubIntegrationConfig;\n\n/**\n * @public\n * @deprecated Use {@link GithubIntegration} instead.\n */\nexport class GitHubIntegration extends GithubIntegration {\n static factory: ScmIntegrationsFactory<GitHubIntegration> =\n GithubIntegration.factory;\n\n constructor(integrationConfig: GitHubIntegrationConfig) {\n super(integrationConfig as GithubIntegrationConfig);\n }\n\n get config(): GitHubIntegrationConfig {\n return super.config as GitHubIntegrationConfig;\n }\n}\n\n/**\n * @public\n * @deprecated Use {@link readGithubIntegrationConfig} instead.\n */\nexport const readGitHubIntegrationConfig = readGithubIntegrationConfig;\n\n/**\n * @public\n * @deprecated Use {@link readGithubIntegrationConfigs} instead.\n */\nexport const readGitHubIntegrationConfigs = readGithubIntegrationConfigs;\n\n/**\n * @public\n * @deprecated Use {@link replaceGithubUrlType} instead.\n */\nexport const replaceGitHubUrlType = replaceGithubUrlType;\n"],"names":[],"mappings":";;;;AA6BO,MAAM,qBAAwB,GAAA,sBAAA;AAY9B,MAAM,0BAA0B,iBAAkB,CAAA;AAAA,EACvD,OAAO,UACL,iBAAkB,CAAA,OAAA,CAAA;AAAA,EAEpB,YAAY,iBAA4C,EAAA;AACtD,IAAA,KAAA,CAAM,iBAA4C,CAAA,CAAA;AAAA,GACpD;AAAA,EAEA,IAAI,MAAkC,GAAA;AACpC,IAAA,OAAO,KAAM,CAAA,MAAA,CAAA;AAAA,GACf;AACF,CAAA;AAMO,MAAM,2BAA8B,GAAA,4BAAA;AAMpC,MAAM,4BAA+B,GAAA,6BAAA;AAMrC,MAAM,oBAAuB,GAAA;;;;"}
@@ -1,16 +1,19 @@
1
1
  import { basicIntegrations, defaultScmResolveUrl } from '../helpers.esm.js';
2
2
  import { readGitLabIntegrationConfigs } from './config.esm.js';
3
3
 
4
- var __defProp = Object.defineProperty;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __publicField = (obj, key, value) => {
7
- __defNormalProp(obj, key + "" , value);
8
- return value;
9
- };
10
- const _GitLabIntegration = class _GitLabIntegration {
4
+ class GitLabIntegration {
11
5
  constructor(integrationConfig) {
12
6
  this.integrationConfig = integrationConfig;
13
7
  }
8
+ static factory = ({ config }) => {
9
+ const configs = readGitLabIntegrationConfigs(
10
+ config.getOptionalConfigArray("integrations.gitlab") ?? []
11
+ );
12
+ return basicIntegrations(
13
+ configs.map((c) => new GitLabIntegration(c)),
14
+ (i) => i.config.host
15
+ );
16
+ };
14
17
  get type() {
15
18
  return "gitlab";
16
19
  }
@@ -26,18 +29,7 @@ const _GitLabIntegration = class _GitLabIntegration {
26
29
  resolveEditUrl(url) {
27
30
  return replaceGitLabUrlType(url, "edit");
28
31
  }
29
- };
30
- __publicField(_GitLabIntegration, "factory", ({ config }) => {
31
- var _a;
32
- const configs = readGitLabIntegrationConfigs(
33
- (_a = config.getOptionalConfigArray("integrations.gitlab")) != null ? _a : []
34
- );
35
- return basicIntegrations(
36
- configs.map((c) => new _GitLabIntegration(c)),
37
- (i) => i.config.host
38
- );
39
- });
40
- let GitLabIntegration = _GitLabIntegration;
32
+ }
41
33
  function replaceGitLabUrlType(url, type) {
42
34
  return url.replace(/\/\-\/(blob|tree|edit)\//, `/-/${type}/`);
43
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"GitLabIntegration.esm.js","sources":["../../src/gitlab/GitLabIntegration.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport { ScmIntegration, ScmIntegrationsFactory } from '../types';\nimport {\n GitLabIntegrationConfig,\n readGitLabIntegrationConfigs,\n} from './config';\n\n/**\n * A GitLab based integration.\n *\n * @public\n */\nexport class GitLabIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<GitLabIntegration> = ({ config }) => {\n const configs = readGitLabIntegrationConfigs(\n config.getOptionalConfigArray('integrations.gitlab') ?? [],\n );\n return basicIntegrations(\n configs.map(c => new GitLabIntegration(c)),\n i => i.config.host,\n );\n };\n\n constructor(private readonly integrationConfig: GitLabIntegrationConfig) {}\n\n get type(): string {\n return 'gitlab';\n }\n\n get title(): string {\n return this.integrationConfig.host;\n }\n\n get config(): GitLabIntegrationConfig {\n return this.integrationConfig;\n }\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n }): string {\n return defaultScmResolveUrl(options);\n }\n\n resolveEditUrl(url: string): string {\n return replaceGitLabUrlType(url, 'edit');\n }\n}\n\n/**\n * Takes a GitLab URL and replaces the type part (blob, tree etc).\n *\n * @param url - The original URL\n * @param type - The desired type, e.g. 'blob', 'tree', 'edit'\n * @public\n */\nexport function replaceGitLabUrlType(\n url: string,\n type: 'blob' | 'tree' | 'edit',\n): string {\n return url.replace(/\\/\\-\\/(blob|tree|edit)\\//, `/-/${type}/`);\n}\n"],"names":[],"mappings":";;;;;;;;;AA4BO,MAAM,kBAAA,GAAN,MAAM,kBAA4C,CAAA;AAAA,EAWvD,YAA6B,iBAA4C,EAAA;AAA5C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA,CAAA;AAAA,GAA6C;AAAA,EAE1E,IAAI,IAAe,GAAA;AACjB,IAAO,OAAA,QAAA,CAAA;AAAA,GACT;AAAA,EAEA,IAAI,KAAgB,GAAA;AAClB,IAAA,OAAO,KAAK,iBAAkB,CAAA,IAAA,CAAA;AAAA,GAChC;AAAA,EAEA,IAAI,MAAkC,GAAA;AACpC,IAAA,OAAO,IAAK,CAAA,iBAAA,CAAA;AAAA,GACd;AAAA,EAEA,WAAW,OAIA,EAAA;AACT,IAAA,OAAO,qBAAqB,OAAO,CAAA,CAAA;AAAA,GACrC;AAAA,EAEA,eAAe,GAAqB,EAAA;AAClC,IAAO,OAAA,oBAAA,CAAqB,KAAK,MAAM,CAAA,CAAA;AAAA,GACzC;AACF,CAAA,CAAA;AAnCE,aAAA,CADW,kBACJ,EAAA,SAAA,EAAqD,CAAC,EAAE,QAAa,KAAA;AA7B9E,EAAA,IAAA,EAAA,CAAA;AA8BI,EAAA,MAAM,OAAU,GAAA,4BAAA;AAAA,IAAA,CACd,EAAO,GAAA,MAAA,CAAA,sBAAA,CAAuB,qBAAqB,CAAA,KAAnD,YAAwD,EAAC;AAAA,GAC3D,CAAA;AACA,EAAO,OAAA,iBAAA;AAAA,IACL,QAAQ,GAAI,CAAA,CAAA,CAAA,KAAK,IAAI,kBAAA,CAAkB,CAAC,CAAC,CAAA;AAAA,IACzC,CAAA,CAAA,KAAK,EAAE,MAAO,CAAA,IAAA;AAAA,GAChB,CAAA;AACF,CAAA,CAAA,CAAA;AATK,IAAM,iBAAN,GAAA,mBAAA;AA6CS,SAAA,oBAAA,CACd,KACA,IACQ,EAAA;AACR,EAAA,OAAO,GAAI,CAAA,OAAA,CAAQ,0BAA4B,EAAA,CAAA,GAAA,EAAM,IAAI,CAAG,CAAA,CAAA,CAAA,CAAA;AAC9D;;;;"}
1
+ {"version":3,"file":"GitLabIntegration.esm.js","sources":["../../src/gitlab/GitLabIntegration.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport { ScmIntegration, ScmIntegrationsFactory } from '../types';\nimport {\n GitLabIntegrationConfig,\n readGitLabIntegrationConfigs,\n} from './config';\n\n/**\n * A GitLab based integration.\n *\n * @public\n */\nexport class GitLabIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<GitLabIntegration> = ({ config }) => {\n const configs = readGitLabIntegrationConfigs(\n config.getOptionalConfigArray('integrations.gitlab') ?? [],\n );\n return basicIntegrations(\n configs.map(c => new GitLabIntegration(c)),\n i => i.config.host,\n );\n };\n\n constructor(private readonly integrationConfig: GitLabIntegrationConfig) {}\n\n get type(): string {\n return 'gitlab';\n }\n\n get title(): string {\n return this.integrationConfig.host;\n }\n\n get config(): GitLabIntegrationConfig {\n return this.integrationConfig;\n }\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n }): string {\n return defaultScmResolveUrl(options);\n }\n\n resolveEditUrl(url: string): string {\n return replaceGitLabUrlType(url, 'edit');\n }\n}\n\n/**\n * Takes a GitLab URL and replaces the type part (blob, tree etc).\n *\n * @param url - The original URL\n * @param type - The desired type, e.g. 'blob', 'tree', 'edit'\n * @public\n */\nexport function replaceGitLabUrlType(\n url: string,\n type: 'blob' | 'tree' | 'edit',\n): string {\n return url.replace(/\\/\\-\\/(blob|tree|edit)\\//, `/-/${type}/`);\n}\n"],"names":[],"mappings":";;;AA4BO,MAAM,iBAA4C,CAAA;AAAA,EAWvD,YAA6B,iBAA4C,EAAA;AAA5C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA,CAAA;AAAA,GAA6C;AAAA,EAV1E,OAAO,OAAA,GAAqD,CAAC,EAAE,QAAa,KAAA;AAC1E,IAAA,MAAM,OAAU,GAAA,4BAAA;AAAA,MACd,MAAO,CAAA,sBAAA,CAAuB,qBAAqB,CAAA,IAAK,EAAC;AAAA,KAC3D,CAAA;AACA,IAAO,OAAA,iBAAA;AAAA,MACL,QAAQ,GAAI,CAAA,CAAA,CAAA,KAAK,IAAI,iBAAA,CAAkB,CAAC,CAAC,CAAA;AAAA,MACzC,CAAA,CAAA,KAAK,EAAE,MAAO,CAAA,IAAA;AAAA,KAChB,CAAA;AAAA,GACF,CAAA;AAAA,EAIA,IAAI,IAAe,GAAA;AACjB,IAAO,OAAA,QAAA,CAAA;AAAA,GACT;AAAA,EAEA,IAAI,KAAgB,GAAA;AAClB,IAAA,OAAO,KAAK,iBAAkB,CAAA,IAAA,CAAA;AAAA,GAChC;AAAA,EAEA,IAAI,MAAkC,GAAA;AACpC,IAAA,OAAO,IAAK,CAAA,iBAAA,CAAA;AAAA,GACd;AAAA,EAEA,WAAW,OAIA,EAAA;AACT,IAAA,OAAO,qBAAqB,OAAO,CAAA,CAAA;AAAA,GACrC;AAAA,EAEA,eAAe,GAAqB,EAAA;AAClC,IAAO,OAAA,oBAAA,CAAqB,KAAK,MAAM,CAAA,CAAA;AAAA,GACzC;AACF,CAAA;AASgB,SAAA,oBAAA,CACd,KACA,IACQ,EAAA;AACR,EAAA,OAAO,GAAI,CAAA,OAAA,CAAQ,0BAA4B,EAAA,CAAA,GAAA,EAAM,IAAI,CAAG,CAAA,CAAA,CAAA,CAAA;AAC9D;;;;"}
@@ -1,13 +1,10 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => {
4
- __defNormalProp(obj, key + "" , value);
5
- return value;
6
- };
7
- const _SingleInstanceGitlabCredentialsProvider = class _SingleInstanceGitlabCredentialsProvider {
1
+ class SingleInstanceGitlabCredentialsProvider {
8
2
  constructor(token) {
9
3
  this.token = token;
10
4
  }
5
+ static create = (config) => {
6
+ return new SingleInstanceGitlabCredentialsProvider(config.token);
7
+ };
11
8
  async getCredentials(_opts) {
12
9
  if (!this.token) {
13
10
  return {};
@@ -19,11 +16,7 @@ const _SingleInstanceGitlabCredentialsProvider = class _SingleInstanceGitlabCred
19
16
  token: this.token
20
17
  };
21
18
  }
22
- };
23
- __publicField(_SingleInstanceGitlabCredentialsProvider, "create", (config) => {
24
- return new _SingleInstanceGitlabCredentialsProvider(config.token);
25
- });
26
- let SingleInstanceGitlabCredentialsProvider = _SingleInstanceGitlabCredentialsProvider;
19
+ }
27
20
 
28
21
  export { SingleInstanceGitlabCredentialsProvider };
29
22
  //# sourceMappingURL=SingleInstanceGitlabCredentialsProvider.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SingleInstanceGitlabCredentialsProvider.esm.js","sources":["../../src/gitlab/SingleInstanceGitlabCredentialsProvider.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { GitLabIntegrationConfig } from './config';\nimport { GitlabCredentials, GitlabCredentialsProvider } from './types';\n\nexport class SingleInstanceGitlabCredentialsProvider\n implements GitlabCredentialsProvider\n{\n static create: (\n config: GitLabIntegrationConfig,\n ) => GitlabCredentialsProvider = config => {\n return new SingleInstanceGitlabCredentialsProvider(config.token);\n };\n\n private constructor(private readonly token?: string) {}\n\n async getCredentials(_opts: { url: string }): Promise<GitlabCredentials> {\n if (!this.token) {\n return {};\n }\n\n return {\n headers: {\n Authorization: `Bearer ${this.token}`,\n },\n token: this.token,\n };\n }\n}\n"],"names":[],"mappings":";;;;;;AAmBO,MAAM,wCAAA,GAAN,MAAM,wCAEb,CAAA;AAAA,EAOU,YAA6B,KAAgB,EAAA;AAAhB,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA,CAAA;AAAA,GAAiB;AAAA,EAEtD,MAAM,eAAe,KAAoD,EAAA;AACvE,IAAI,IAAA,CAAC,KAAK,KAAO,EAAA;AACf,MAAA,OAAO,EAAC,CAAA;AAAA,KACV;AAEA,IAAO,OAAA;AAAA,MACL,OAAS,EAAA;AAAA,QACP,aAAA,EAAe,CAAU,OAAA,EAAA,IAAA,CAAK,KAAK,CAAA,CAAA;AAAA,OACrC;AAAA,MACA,OAAO,IAAK,CAAA,KAAA;AAAA,KACd,CAAA;AAAA,GACF;AACF,CAAA,CAAA;AApBE,aAHW,CAAA,wCAAA,EAGJ,UAE0B,CAAU,MAAA,KAAA;AACzC,EAAO,OAAA,IAAI,wCAAwC,CAAA,MAAA,CAAO,KAAK,CAAA,CAAA;AACjE,CAAA,CAAA,CAAA;AAPK,IAAM,uCAAN,GAAA;;;;"}
1
+ {"version":3,"file":"SingleInstanceGitlabCredentialsProvider.esm.js","sources":["../../src/gitlab/SingleInstanceGitlabCredentialsProvider.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { GitLabIntegrationConfig } from './config';\nimport { GitlabCredentials, GitlabCredentialsProvider } from './types';\n\nexport class SingleInstanceGitlabCredentialsProvider\n implements GitlabCredentialsProvider\n{\n static create: (\n config: GitLabIntegrationConfig,\n ) => GitlabCredentialsProvider = config => {\n return new SingleInstanceGitlabCredentialsProvider(config.token);\n };\n\n private constructor(private readonly token?: string) {}\n\n async getCredentials(_opts: { url: string }): Promise<GitlabCredentials> {\n if (!this.token) {\n return {};\n }\n\n return {\n headers: {\n Authorization: `Bearer ${this.token}`,\n },\n token: this.token,\n };\n }\n}\n"],"names":[],"mappings":"AAmBO,MAAM,uCAEb,CAAA;AAAA,EAOU,YAA6B,KAAgB,EAAA;AAAhB,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA,CAAA;AAAA,GAAiB;AAAA,EANtD,OAAO,SAE0B,CAAU,MAAA,KAAA;AACzC,IAAO,OAAA,IAAI,uCAAwC,CAAA,MAAA,CAAO,KAAK,CAAA,CAAA;AAAA,GACjE,CAAA;AAAA,EAIA,MAAM,eAAe,KAAoD,EAAA;AACvE,IAAI,IAAA,CAAC,KAAK,KAAO,EAAA;AACf,MAAA,OAAO,EAAC,CAAA;AAAA,KACV;AAEA,IAAO,OAAA;AAAA,MACL,OAAS,EAAA;AAAA,QACP,aAAA,EAAe,CAAU,OAAA,EAAA,IAAA,CAAK,KAAK,CAAA,CAAA;AAAA,OACrC;AAAA,MACA,OAAO,IAAK,CAAA,KAAA;AAAA,KACd,CAAA;AAAA,GACF;AACF;;;;"}
@@ -4,10 +4,9 @@ import { isValidHost, isValidUrl } from '../helpers.esm.js';
4
4
  const GITLAB_HOST = "gitlab.com";
5
5
  const GITLAB_API_BASE_URL = "https://gitlab.com/api/v4";
6
6
  function readGitLabIntegrationConfig(config) {
7
- var _a;
8
7
  const host = config.getString("host");
9
8
  let apiBaseUrl = config.getOptionalString("apiBaseUrl");
10
- const token = (_a = config.getOptionalString("token")) == null ? void 0 : _a.trim();
9
+ const token = config.getOptionalString("token")?.trim();
11
10
  let baseUrl = config.getOptionalString("baseUrl");
12
11
  if (apiBaseUrl) {
13
12
  apiBaseUrl = trimEnd(apiBaseUrl, "/");
@@ -1 +1 @@
1
- {"version":3,"file":"config.esm.js","sources":["../../src/gitlab/config.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\nimport { trimEnd } from 'lodash';\nimport { isValidHost, isValidUrl } from '../helpers';\n\nconst GITLAB_HOST = 'gitlab.com';\nconst GITLAB_API_BASE_URL = 'https://gitlab.com/api/v4';\n\n/**\n * The configuration parameters for a single GitLab integration.\n *\n * @public\n */\nexport type GitLabIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. `gitlab.com`.\n */\n host: string;\n\n /**\n * The base URL of the API of this provider, e.g.\n * `https://gitlab.com/api/v4`, with no trailing slash.\n *\n * May be omitted specifically for public GitLab; then it will be deduced.\n */\n apiBaseUrl: string;\n\n /**\n * The authorization token to use for requests to this provider.\n *\n * If no token is specified, anonymous access is used.\n */\n token?: string;\n\n /**\n * The baseUrl of this provider, e.g. `https://gitlab.com`, which is passed\n * into the GitLab client.\n *\n * If no baseUrl is provided, it will default to `https://${host}`\n */\n baseUrl: string;\n};\n\n/**\n * Reads a single GitLab integration config.\n *\n * @param config - The config object of a single integration\n * @public\n */\nexport function readGitLabIntegrationConfig(\n config: Config,\n): GitLabIntegrationConfig {\n const host = config.getString('host');\n let apiBaseUrl = config.getOptionalString('apiBaseUrl');\n const token = config.getOptionalString('token')?.trim();\n let baseUrl = config.getOptionalString('baseUrl');\n if (apiBaseUrl) {\n apiBaseUrl = trimEnd(apiBaseUrl, '/');\n } else if (host === GITLAB_HOST) {\n apiBaseUrl = GITLAB_API_BASE_URL;\n }\n\n if (baseUrl) {\n baseUrl = trimEnd(baseUrl, '/');\n } else {\n baseUrl = `https://${host}`;\n }\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid GitLab integration config, '${host}' is not a valid host`,\n );\n } else if (!apiBaseUrl || !isValidUrl(apiBaseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${apiBaseUrl}' is not a valid apiBaseUrl`,\n );\n } else if (!isValidUrl(baseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${baseUrl}' is not a valid baseUrl`,\n );\n }\n\n return { host, token, apiBaseUrl, baseUrl };\n}\n\n/**\n * Reads a set of GitLab integration configs, and inserts some defaults for\n * public GitLab if not specified.\n *\n * @param configs - All of the integration config objects\n * @public\n */\nexport function readGitLabIntegrationConfigs(\n configs: Config[],\n): GitLabIntegrationConfig[] {\n // First read all the explicit integrations\n const result = configs.map(readGitLabIntegrationConfig);\n\n // As a convenience we always make sure there's at least an unauthenticated\n // reader for public gitlab repos.\n if (!result.some(c => c.host === GITLAB_HOST)) {\n result.push({\n host: GITLAB_HOST,\n apiBaseUrl: GITLAB_API_BASE_URL,\n baseUrl: `https://${GITLAB_HOST}`,\n });\n }\n\n return result;\n}\n\n/**\n * Reads a GitLab integration config, and returns\n * relative path.\n *\n * @param config - GitLabIntegrationConfig object\n * @public\n */\nexport function getGitLabIntegrationRelativePath(\n config: GitLabIntegrationConfig,\n): string {\n let relativePath = '';\n if (config.host !== GITLAB_HOST) {\n relativePath = new URL(config.baseUrl).pathname;\n }\n return trimEnd(relativePath, '/');\n}\n"],"names":[],"mappings":";;;AAoBA,MAAM,WAAc,GAAA,YAAA,CAAA;AACpB,MAAM,mBAAsB,GAAA,2BAAA,CAAA;AA2CrB,SAAS,4BACd,MACyB,EAAA;AAlE3B,EAAA,IAAA,EAAA,CAAA;AAmEE,EAAM,MAAA,IAAA,GAAO,MAAO,CAAA,SAAA,CAAU,MAAM,CAAA,CAAA;AACpC,EAAI,IAAA,UAAA,GAAa,MAAO,CAAA,iBAAA,CAAkB,YAAY,CAAA,CAAA;AACtD,EAAA,MAAM,KAAQ,GAAA,CAAA,EAAA,GAAA,MAAA,CAAO,iBAAkB,CAAA,OAAO,MAAhC,IAAmC,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,IAAA,EAAA,CAAA;AACjD,EAAI,IAAA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,EAAA,WAAA;AAAA,MACN,UAAY,EAAA,mBAAA;AAAA,MACZ,OAAA,EAAS,WAAW,WAAW,CAAA,CAAA;AAAA,KAChC,CAAA,CAAA;AAAA,GACH;AAEA,EAAO,OAAA,MAAA,CAAA;AACT,CAAA;AASO,SAAS,iCACd,MACQ,EAAA;AACR,EAAA,IAAI,YAAe,GAAA,EAAA,CAAA;AACnB,EAAI,IAAA,MAAA,CAAO,SAAS,WAAa,EAAA;AAC/B,IAAA,YAAA,GAAe,IAAI,GAAA,CAAI,MAAO,CAAA,OAAO,CAAE,CAAA,QAAA,CAAA;AAAA,GACzC;AACA,EAAO,OAAA,OAAA,CAAQ,cAAc,GAAG,CAAA,CAAA;AAClC;;;;"}
1
+ {"version":3,"file":"config.esm.js","sources":["../../src/gitlab/config.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\nimport { trimEnd } from 'lodash';\nimport { isValidHost, isValidUrl } from '../helpers';\n\nconst GITLAB_HOST = 'gitlab.com';\nconst GITLAB_API_BASE_URL = 'https://gitlab.com/api/v4';\n\n/**\n * The configuration parameters for a single GitLab integration.\n *\n * @public\n */\nexport type GitLabIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. `gitlab.com`.\n */\n host: string;\n\n /**\n * The base URL of the API of this provider, e.g.\n * `https://gitlab.com/api/v4`, with no trailing slash.\n *\n * May be omitted specifically for public GitLab; then it will be deduced.\n */\n apiBaseUrl: string;\n\n /**\n * The authorization token to use for requests to this provider.\n *\n * If no token is specified, anonymous access is used.\n */\n token?: string;\n\n /**\n * The baseUrl of this provider, e.g. `https://gitlab.com`, which is passed\n * into the GitLab client.\n *\n * If no baseUrl is provided, it will default to `https://${host}`\n */\n baseUrl: string;\n};\n\n/**\n * Reads a single GitLab integration config.\n *\n * @param config - The config object of a single integration\n * @public\n */\nexport function readGitLabIntegrationConfig(\n config: Config,\n): GitLabIntegrationConfig {\n const host = config.getString('host');\n let apiBaseUrl = config.getOptionalString('apiBaseUrl');\n const token = config.getOptionalString('token')?.trim();\n let baseUrl = config.getOptionalString('baseUrl');\n if (apiBaseUrl) {\n apiBaseUrl = trimEnd(apiBaseUrl, '/');\n } else if (host === GITLAB_HOST) {\n apiBaseUrl = GITLAB_API_BASE_URL;\n }\n\n if (baseUrl) {\n baseUrl = trimEnd(baseUrl, '/');\n } else {\n baseUrl = `https://${host}`;\n }\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid GitLab integration config, '${host}' is not a valid host`,\n );\n } else if (!apiBaseUrl || !isValidUrl(apiBaseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${apiBaseUrl}' is not a valid apiBaseUrl`,\n );\n } else if (!isValidUrl(baseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${baseUrl}' is not a valid baseUrl`,\n );\n }\n\n return { host, token, apiBaseUrl, baseUrl };\n}\n\n/**\n * Reads a set of GitLab integration configs, and inserts some defaults for\n * public GitLab if not specified.\n *\n * @param configs - All of the integration config objects\n * @public\n */\nexport function readGitLabIntegrationConfigs(\n configs: Config[],\n): GitLabIntegrationConfig[] {\n // First read all the explicit integrations\n const result = configs.map(readGitLabIntegrationConfig);\n\n // As a convenience we always make sure there's at least an unauthenticated\n // reader for public gitlab repos.\n if (!result.some(c => c.host === GITLAB_HOST)) {\n result.push({\n host: GITLAB_HOST,\n apiBaseUrl: GITLAB_API_BASE_URL,\n baseUrl: `https://${GITLAB_HOST}`,\n });\n }\n\n return result;\n}\n\n/**\n * Reads a GitLab integration config, and returns\n * relative path.\n *\n * @param config - GitLabIntegrationConfig object\n * @public\n */\nexport function getGitLabIntegrationRelativePath(\n config: GitLabIntegrationConfig,\n): string {\n let relativePath = '';\n if (config.host !== GITLAB_HOST) {\n relativePath = new URL(config.baseUrl).pathname;\n }\n return trimEnd(relativePath, '/');\n}\n"],"names":[],"mappings":";;;AAoBA,MAAM,WAAc,GAAA,YAAA,CAAA;AACpB,MAAM,mBAAsB,GAAA,2BAAA,CAAA;AA2CrB,SAAS,4BACd,MACyB,EAAA;AACzB,EAAM,MAAA,IAAA,GAAO,MAAO,CAAA,SAAA,CAAU,MAAM,CAAA,CAAA;AACpC,EAAI,IAAA,UAAA,GAAa,MAAO,CAAA,iBAAA,CAAkB,YAAY,CAAA,CAAA;AACtD,EAAA,MAAM,KAAQ,GAAA,MAAA,CAAO,iBAAkB,CAAA,OAAO,GAAG,IAAK,EAAA,CAAA;AACtD,EAAI,IAAA,OAAA,GAAU,MAAO,CAAA,iBAAA,CAAkB,SAAS,CAAA,CAAA;AAChD,EAAA,IAAI,UAAY,EAAA;AACd,IAAa,UAAA,GAAA,OAAA,CAAQ,YAAY,GAAG,CAAA,CAAA;AAAA,GACtC,MAAA,IAAW,SAAS,WAAa,EAAA;AAC/B,IAAa,UAAA,GAAA,mBAAA,CAAA;AAAA,GACf;AAEA,EAAA,IAAI,OAAS,EAAA;AACX,IAAU,OAAA,GAAA,OAAA,CAAQ,SAAS,GAAG,CAAA,CAAA;AAAA,GACzB,MAAA;AACL,IAAA,OAAA,GAAU,WAAW,IAAI,CAAA,CAAA,CAAA;AAAA,GAC3B;AAEA,EAAI,IAAA,CAAC,WAAY,CAAA,IAAI,CAAG,EAAA;AACtB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,uCAAuC,IAAI,CAAA,qBAAA,CAAA;AAAA,KAC7C,CAAA;AAAA,aACS,CAAC,UAAA,IAAc,CAAC,UAAA,CAAW,UAAU,CAAG,EAAA;AACjD,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,uCAAuC,UAAU,CA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