@backstage/integration 2.1.2 → 2.1.3-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/ScmIntegrations.cjs.js.map +1 -1
- package/dist/ScmIntegrations.esm.js.map +1 -1
- package/dist/alpha/github/createGitHubCredentialsProviderFromConnection.cjs.js.map +1 -1
- package/dist/alpha/github/createGitHubCredentialsProviderFromConnection.esm.js.map +1 -1
- package/dist/awsCodeCommit/AwsCodeCommitIntegration.cjs.js +1 -0
- package/dist/awsCodeCommit/AwsCodeCommitIntegration.cjs.js.map +1 -1
- package/dist/awsCodeCommit/AwsCodeCommitIntegration.esm.js +1 -0
- package/dist/awsCodeCommit/AwsCodeCommitIntegration.esm.js.map +1 -1
- package/dist/awsCodeCommit/config.cjs.js.map +1 -1
- package/dist/awsCodeCommit/config.esm.js.map +1 -1
- package/dist/awsS3/AwsS3Integration.cjs.js +1 -0
- package/dist/awsS3/AwsS3Integration.cjs.js.map +1 -1
- package/dist/awsS3/AwsS3Integration.esm.js +1 -0
- package/dist/awsS3/AwsS3Integration.esm.js.map +1 -1
- package/dist/awsS3/config.cjs.js.map +1 -1
- package/dist/awsS3/config.esm.js.map +1 -1
- package/dist/azure/AzureIntegration.cjs.js +12 -1
- package/dist/azure/AzureIntegration.cjs.js.map +1 -1
- package/dist/azure/AzureIntegration.esm.js +12 -1
- package/dist/azure/AzureIntegration.esm.js.map +1 -1
- package/dist/azure/AzureUrl.cjs.js.map +1 -1
- package/dist/azure/AzureUrl.esm.js.map +1 -1
- package/dist/azure/CachedAzureDevOpsCredentialsProvider.cjs.js +1 -0
- package/dist/azure/CachedAzureDevOpsCredentialsProvider.cjs.js.map +1 -1
- package/dist/azure/CachedAzureDevOpsCredentialsProvider.esm.js +1 -0
- package/dist/azure/CachedAzureDevOpsCredentialsProvider.esm.js.map +1 -1
- package/dist/azure/DefaultAzureDevOpsCredentialsProvider.cjs.js +1 -0
- package/dist/azure/DefaultAzureDevOpsCredentialsProvider.cjs.js.map +1 -1
- package/dist/azure/DefaultAzureDevOpsCredentialsProvider.esm.js +1 -0
- package/dist/azure/DefaultAzureDevOpsCredentialsProvider.esm.js.map +1 -1
- package/dist/azure/ManagedIdentityClientAssertion.cjs.js.map +1 -1
- package/dist/azure/ManagedIdentityClientAssertion.esm.js.map +1 -1
- package/dist/azure/config.cjs.js.map +1 -1
- package/dist/azure/config.esm.js.map +1 -1
- package/dist/azure/core.cjs.js.map +1 -1
- package/dist/azure/core.esm.js.map +1 -1
- package/dist/azure/isVisualStudioDomain.cjs.js.map +1 -1
- package/dist/azure/isVisualStudioDomain.esm.js.map +1 -1
- package/dist/azureBlobStorage/AzureBlobStorageIntegration.cjs.js +1 -0
- package/dist/azureBlobStorage/AzureBlobStorageIntegration.cjs.js.map +1 -1
- package/dist/azureBlobStorage/AzureBlobStorageIntegration.esm.js +1 -0
- package/dist/azureBlobStorage/AzureBlobStorageIntegration.esm.js.map +1 -1
- package/dist/azureBlobStorage/DefaultAzureCredentialsProvider.cjs.js +1 -0
- package/dist/azureBlobStorage/DefaultAzureCredentialsProvider.cjs.js.map +1 -1
- package/dist/azureBlobStorage/DefaultAzureCredentialsProvider.esm.js +1 -0
- package/dist/azureBlobStorage/DefaultAzureCredentialsProvider.esm.js.map +1 -1
- package/dist/azureBlobStorage/config.cjs.js.map +1 -1
- package/dist/azureBlobStorage/config.esm.js.map +1 -1
- package/dist/bitbucketCloud/BitbucketCloudIntegration.cjs.js +1 -0
- package/dist/bitbucketCloud/BitbucketCloudIntegration.cjs.js.map +1 -1
- package/dist/bitbucketCloud/BitbucketCloudIntegration.esm.js +1 -0
- package/dist/bitbucketCloud/BitbucketCloudIntegration.esm.js.map +1 -1
- package/dist/bitbucketCloud/config.cjs.js.map +1 -1
- package/dist/bitbucketCloud/config.esm.js.map +1 -1
- package/dist/bitbucketCloud/core.cjs.js +17 -10
- package/dist/bitbucketCloud/core.cjs.js.map +1 -1
- package/dist/bitbucketCloud/core.esm.js +17 -10
- package/dist/bitbucketCloud/core.esm.js.map +1 -1
- package/dist/bitbucketServer/BitbucketServerIntegration.cjs.js +1 -0
- package/dist/bitbucketServer/BitbucketServerIntegration.cjs.js.map +1 -1
- package/dist/bitbucketServer/BitbucketServerIntegration.esm.js +1 -0
- package/dist/bitbucketServer/BitbucketServerIntegration.esm.js.map +1 -1
- package/dist/bitbucketServer/config.cjs.js.map +1 -1
- package/dist/bitbucketServer/config.esm.js.map +1 -1
- package/dist/bitbucketServer/core.cjs.js.map +1 -1
- package/dist/bitbucketServer/core.esm.js.map +1 -1
- package/dist/gerrit/GerritIntegration.cjs.js +1 -0
- package/dist/gerrit/GerritIntegration.cjs.js.map +1 -1
- package/dist/gerrit/GerritIntegration.esm.js +1 -0
- package/dist/gerrit/GerritIntegration.esm.js.map +1 -1
- package/dist/gerrit/config.cjs.js.map +1 -1
- package/dist/gerrit/config.esm.js.map +1 -1
- package/dist/gerrit/core.cjs.js.map +1 -1
- package/dist/gerrit/core.esm.js.map +1 -1
- package/dist/gitea/GiteaIntegration.cjs.js +1 -0
- package/dist/gitea/GiteaIntegration.cjs.js.map +1 -1
- package/dist/gitea/GiteaIntegration.esm.js +1 -0
- package/dist/gitea/GiteaIntegration.esm.js.map +1 -1
- package/dist/gitea/config.cjs.js.map +1 -1
- package/dist/gitea/config.esm.js.map +1 -1
- package/dist/gitea/core.cjs.js.map +1 -1
- package/dist/gitea/core.esm.js.map +1 -1
- package/dist/github/DefaultGithubCredentialsProvider.cjs.js.map +1 -1
- package/dist/github/DefaultGithubCredentialsProvider.esm.js.map +1 -1
- package/dist/github/GithubIntegration.cjs.js +1 -0
- package/dist/github/GithubIntegration.cjs.js.map +1 -1
- package/dist/github/GithubIntegration.esm.js +1 -0
- package/dist/github/GithubIntegration.esm.js.map +1 -1
- package/dist/github/SingleInstanceGithubCredentialsProvider.cjs.js.map +1 -1
- package/dist/github/SingleInstanceGithubCredentialsProvider.esm.js.map +1 -1
- package/dist/github/config.cjs.js.map +1 -1
- package/dist/github/config.esm.js.map +1 -1
- package/dist/github/core.cjs.js.map +1 -1
- package/dist/github/core.esm.js.map +1 -1
- package/dist/gitlab/DefaultGitlabCredentialsProvider.cjs.js +1 -0
- package/dist/gitlab/DefaultGitlabCredentialsProvider.cjs.js.map +1 -1
- package/dist/gitlab/DefaultGitlabCredentialsProvider.esm.js +1 -0
- package/dist/gitlab/DefaultGitlabCredentialsProvider.esm.js.map +1 -1
- package/dist/gitlab/GitLabIntegration.cjs.js +1 -0
- package/dist/gitlab/GitLabIntegration.cjs.js.map +1 -1
- package/dist/gitlab/GitLabIntegration.esm.js +1 -0
- package/dist/gitlab/GitLabIntegration.esm.js.map +1 -1
- package/dist/gitlab/SingleInstanceGitlabCredentialsProvider.cjs.js +1 -0
- package/dist/gitlab/SingleInstanceGitlabCredentialsProvider.cjs.js.map +1 -1
- package/dist/gitlab/SingleInstanceGitlabCredentialsProvider.esm.js +1 -0
- package/dist/gitlab/SingleInstanceGitlabCredentialsProvider.esm.js.map +1 -1
- package/dist/gitlab/config.cjs.js.map +1 -1
- package/dist/gitlab/config.esm.js.map +1 -1
- package/dist/gitlab/core.cjs.js.map +1 -1
- package/dist/gitlab/core.esm.js.map +1 -1
- package/dist/googleGcs/GoogleGcsIntegration.cjs.js +1 -0
- package/dist/googleGcs/GoogleGcsIntegration.cjs.js.map +1 -1
- package/dist/googleGcs/GoogleGcsIntegration.esm.js +1 -0
- package/dist/googleGcs/GoogleGcsIntegration.esm.js.map +1 -1
- package/dist/googleGcs/config.cjs.js.map +1 -1
- package/dist/googleGcs/config.esm.js.map +1 -1
- package/dist/harness/HarnessIntegration.cjs.js +1 -0
- package/dist/harness/HarnessIntegration.cjs.js.map +1 -1
- package/dist/harness/HarnessIntegration.esm.js +1 -0
- package/dist/harness/HarnessIntegration.esm.js.map +1 -1
- package/dist/harness/config.cjs.js.map +1 -1
- package/dist/harness/config.esm.js.map +1 -1
- package/dist/harness/core.cjs.js.map +1 -1
- package/dist/harness/core.esm.js.map +1 -1
- package/dist/helpers.cjs.js.map +1 -1
- package/dist/helpers.esm.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.cjs.js","sources":["../../src/github/core.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 { GithubIntegrationConfig } from './config';\nimport { parseGitUrlSafe } from '../helpers';\nimport { GithubCredentials } from './types';\n\n/**\n * Given a URL pointing to a file on a provider, returns a URL that is suitable\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://github.com/a/b/blob/branchname/path/to/c.yaml\n * to: https://api.github.com/repos/a/b/contents/path/to/c.yaml?ref=branchname\n * or: https://raw.githubusercontent.com/a/b/branchname/c.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getGithubFileFetchUrl(\n url: string,\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): string {\n try {\n const { owner, name, ref, filepathtype, filepath } = parseGitUrlSafe(url);\n if (\n !owner ||\n !name ||\n !ref ||\n // GitHub is automatically redirecting tree urls to blob urls so it's\n // fine to pass a tree url.\n (filepathtype !== 'blob' &&\n filepathtype !== 'raw' &&\n filepathtype !== 'tree')\n ) {\n throw new Error('Invalid GitHub URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n if (chooseEndpoint(config, credentials) === 'api') {\n return `${config.apiBaseUrl}/repos/${owner}/${name}/contents/${pathWithoutSlash}?ref=${ref}`;\n }\n return `${config.rawBaseUrl}/${owner}/${name}/${ref}/${pathWithoutSlash}`;\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n\nfunction chooseEndpoint(\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): 'api' | 'raw' {\n if (config.apiBaseUrl && (credentials.token || !config.rawBaseUrl)) {\n return 'api';\n }\n return 'raw';\n}\n"],"names":["parseGitUrlSafe"],"mappings":";;;;AAmCO,SAAS,qBAAA,CACd,GAAA,EACA,MAAA,EACA,WAAA,EACQ;AACR,EAAA,IAAI;AACF,IAAA,MAAM,EAAE,OAAO,IAAA,EAAM,GAAA,EAAK,cAAc,QAAA,EAAS,GAAIA,wBAAgB,GAAG,CAAA;AACxE,IAAA,IACE,CAAC,KAAA,IACD,CAAC,IAAA,IACD,CAAC,GAAA;AAAA;AAAA,IAGA,YAAA,KAAiB,MAAA,IAChB,YAAA,KAAiB,KAAA,IACjB,iBAAiB,MAAA,EACnB;AACA,MAAA,MAAM,IAAI,MAAM,iCAAiC,CAAA;AAAA,IACnD;AAEA,IAAA,MAAM,gBAAA,GAAmB,QAAA,CAAS,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AACnD,IAAA,IAAI,cAAA,CAAe,MAAA,EAAQ,WAAW,CAAA,KAAM,KAAA,EAAO;AACjD,MAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,OAAA,EAAU,KAAK,IAAI,IAAI,CAAA,UAAA,EAAa,gBAAgB,CAAA,KAAA,EAAQ,GAAG,CAAA,CAAA;AAAA,IAC5F;AACA,IAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,CAAA,EAAI,KAAK,IAAI,IAAI,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,EAAI,gBAAgB,CAAA,CAAA;AAAA,EACzE,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EAC/C;AACF;AAEA,SAAS,cAAA,CACP,QACA,WAAA,EACe;AACf,EAAA,IAAI,OAAO,UAAA,KAAe,WAAA,CAAY,KAAA,IAAS,CAAC,OAAO,UAAA,CAAA,EAAa;AAClE,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,KAAA;AACT
|
|
1
|
+
{"version":3,"file":"core.cjs.js","sources":["../../src/github/core.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 { GithubIntegrationConfig } from './config';\nimport { parseGitUrlSafe } from '../helpers';\nimport { GithubCredentials } from './types';\n\n/**\n * Given a URL pointing to a file on a provider, returns a URL that is suitable\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://github.com/a/b/blob/branchname/path/to/c.yaml\n * to: https://api.github.com/repos/a/b/contents/path/to/c.yaml?ref=branchname\n * or: https://raw.githubusercontent.com/a/b/branchname/c.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getGithubFileFetchUrl(\n url: string,\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): string {\n try {\n const { owner, name, ref, filepathtype, filepath } = parseGitUrlSafe(url);\n if (\n !owner ||\n !name ||\n !ref ||\n // GitHub is automatically redirecting tree urls to blob urls so it's\n // fine to pass a tree url.\n (filepathtype !== 'blob' &&\n filepathtype !== 'raw' &&\n filepathtype !== 'tree')\n ) {\n throw new Error('Invalid GitHub URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n if (chooseEndpoint(config, credentials) === 'api') {\n return `${config.apiBaseUrl}/repos/${owner}/${name}/contents/${pathWithoutSlash}?ref=${ref}`;\n }\n return `${config.rawBaseUrl}/${owner}/${name}/${ref}/${pathWithoutSlash}`;\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n\nfunction chooseEndpoint(\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): 'api' | 'raw' {\n if (config.apiBaseUrl && (credentials.token || !config.rawBaseUrl)) {\n return 'api';\n }\n return 'raw';\n}\n"],"names":["parseGitUrlSafe"],"mappings":";;;;AAmCO,SAAS,qBAAA,CACd,GAAA,EACA,MAAA,EACA,WAAA,EACQ;AACR,EAAA,IAAI;AACF,IAAA,MAAM,EAAE,OAAO,IAAA,EAAM,GAAA,EAAK,cAAc,QAAA,EAAS,GAAIA,wBAAgB,GAAG,CAAA;AACxE,IAAA,IACE,CAAC,KAAA,IACD,CAAC,IAAA,IACD,CAAC,GAAA;AAAA;AAAA,IAGA,YAAA,KAAiB,MAAA,IAChB,YAAA,KAAiB,KAAA,IACjB,iBAAiB,MAAA,EACnB;AACA,MAAA,MAAM,IAAI,MAAM,iCAAiC,CAAA;AAAA,IACnD;AAEA,IAAA,MAAM,gBAAA,GAAmB,QAAA,CAAS,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AACnD,IAAA,IAAI,cAAA,CAAe,MAAA,EAAQ,WAAW,CAAA,KAAM,KAAA,EAAO;AACjD,MAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,OAAA,EAAU,KAAK,IAAI,IAAI,CAAA,UAAA,EAAa,gBAAgB,CAAA,KAAA,EAAQ,GAAG,CAAA,CAAA;AAAA,IAC5F;AACA,IAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,CAAA,EAAI,KAAK,IAAI,IAAI,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,EAAI,gBAAgB,CAAA,CAAA;AAAA,EACzE,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EAC/C;AACF;AAEA,SAAS,cAAA,CACP,QACA,WAAA,EACe;AACf,EAAA,IAAI,OAAO,UAAA,KAAe,WAAA,CAAY,KAAA,IAAS,CAAC,OAAO,UAAA,CAAA,EAAa;AAClE,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,KAAA;AACT;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.esm.js","sources":["../../src/github/core.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 { GithubIntegrationConfig } from './config';\nimport { parseGitUrlSafe } from '../helpers';\nimport { GithubCredentials } from './types';\n\n/**\n * Given a URL pointing to a file on a provider, returns a URL that is suitable\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://github.com/a/b/blob/branchname/path/to/c.yaml\n * to: https://api.github.com/repos/a/b/contents/path/to/c.yaml?ref=branchname\n * or: https://raw.githubusercontent.com/a/b/branchname/c.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getGithubFileFetchUrl(\n url: string,\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): string {\n try {\n const { owner, name, ref, filepathtype, filepath } = parseGitUrlSafe(url);\n if (\n !owner ||\n !name ||\n !ref ||\n // GitHub is automatically redirecting tree urls to blob urls so it's\n // fine to pass a tree url.\n (filepathtype !== 'blob' &&\n filepathtype !== 'raw' &&\n filepathtype !== 'tree')\n ) {\n throw new Error('Invalid GitHub URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n if (chooseEndpoint(config, credentials) === 'api') {\n return `${config.apiBaseUrl}/repos/${owner}/${name}/contents/${pathWithoutSlash}?ref=${ref}`;\n }\n return `${config.rawBaseUrl}/${owner}/${name}/${ref}/${pathWithoutSlash}`;\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n\nfunction chooseEndpoint(\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): 'api' | 'raw' {\n if (config.apiBaseUrl && (credentials.token || !config.rawBaseUrl)) {\n return 'api';\n }\n return 'raw';\n}\n"],"names":[],"mappings":";;AAmCO,SAAS,qBAAA,CACd,GAAA,EACA,MAAA,EACA,WAAA,EACQ;AACR,EAAA,IAAI;AACF,IAAA,MAAM,EAAE,OAAO,IAAA,EAAM,GAAA,EAAK,cAAc,QAAA,EAAS,GAAI,gBAAgB,GAAG,CAAA;AACxE,IAAA,IACE,CAAC,KAAA,IACD,CAAC,IAAA,IACD,CAAC,GAAA;AAAA;AAAA,IAGA,YAAA,KAAiB,MAAA,IAChB,YAAA,KAAiB,KAAA,IACjB,iBAAiB,MAAA,EACnB;AACA,MAAA,MAAM,IAAI,MAAM,iCAAiC,CAAA;AAAA,IACnD;AAEA,IAAA,MAAM,gBAAA,GAAmB,QAAA,CAAS,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AACnD,IAAA,IAAI,cAAA,CAAe,MAAA,EAAQ,WAAW,CAAA,KAAM,KAAA,EAAO;AACjD,MAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,OAAA,EAAU,KAAK,IAAI,IAAI,CAAA,UAAA,EAAa,gBAAgB,CAAA,KAAA,EAAQ,GAAG,CAAA,CAAA;AAAA,IAC5F;AACA,IAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,CAAA,EAAI,KAAK,IAAI,IAAI,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,EAAI,gBAAgB,CAAA,CAAA;AAAA,EACzE,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EAC/C;AACF;AAEA,SAAS,cAAA,CACP,QACA,WAAA,EACe;AACf,EAAA,IAAI,OAAO,UAAA,KAAe,WAAA,CAAY,KAAA,IAAS,CAAC,OAAO,UAAA,CAAA,EAAa;AAClE,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,KAAA;AACT
|
|
1
|
+
{"version":3,"file":"core.esm.js","sources":["../../src/github/core.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 { GithubIntegrationConfig } from './config';\nimport { parseGitUrlSafe } from '../helpers';\nimport { GithubCredentials } from './types';\n\n/**\n * Given a URL pointing to a file on a provider, returns a URL that is suitable\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://github.com/a/b/blob/branchname/path/to/c.yaml\n * to: https://api.github.com/repos/a/b/contents/path/to/c.yaml?ref=branchname\n * or: https://raw.githubusercontent.com/a/b/branchname/c.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getGithubFileFetchUrl(\n url: string,\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): string {\n try {\n const { owner, name, ref, filepathtype, filepath } = parseGitUrlSafe(url);\n if (\n !owner ||\n !name ||\n !ref ||\n // GitHub is automatically redirecting tree urls to blob urls so it's\n // fine to pass a tree url.\n (filepathtype !== 'blob' &&\n filepathtype !== 'raw' &&\n filepathtype !== 'tree')\n ) {\n throw new Error('Invalid GitHub URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n if (chooseEndpoint(config, credentials) === 'api') {\n return `${config.apiBaseUrl}/repos/${owner}/${name}/contents/${pathWithoutSlash}?ref=${ref}`;\n }\n return `${config.rawBaseUrl}/${owner}/${name}/${ref}/${pathWithoutSlash}`;\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n\nfunction chooseEndpoint(\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): 'api' | 'raw' {\n if (config.apiBaseUrl && (credentials.token || !config.rawBaseUrl)) {\n return 'api';\n }\n return 'raw';\n}\n"],"names":[],"mappings":";;AAmCO,SAAS,qBAAA,CACd,GAAA,EACA,MAAA,EACA,WAAA,EACQ;AACR,EAAA,IAAI;AACF,IAAA,MAAM,EAAE,OAAO,IAAA,EAAM,GAAA,EAAK,cAAc,QAAA,EAAS,GAAI,gBAAgB,GAAG,CAAA;AACxE,IAAA,IACE,CAAC,KAAA,IACD,CAAC,IAAA,IACD,CAAC,GAAA;AAAA;AAAA,IAGA,YAAA,KAAiB,MAAA,IAChB,YAAA,KAAiB,KAAA,IACjB,iBAAiB,MAAA,EACnB;AACA,MAAA,MAAM,IAAI,MAAM,iCAAiC,CAAA;AAAA,IACnD;AAEA,IAAA,MAAM,gBAAA,GAAmB,QAAA,CAAS,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AACnD,IAAA,IAAI,cAAA,CAAe,MAAA,EAAQ,WAAW,CAAA,KAAM,KAAA,EAAO;AACjD,MAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,OAAA,EAAU,KAAK,IAAI,IAAI,CAAA,UAAA,EAAa,gBAAgB,CAAA,KAAA,EAAQ,GAAG,CAAA,CAAA;AAAA,IAC5F;AACA,IAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,CAAA,EAAI,KAAK,IAAI,IAAI,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,EAAI,gBAAgB,CAAA,CAAA;AAAA,EACzE,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EAC/C;AACF;AAEA,SAAS,cAAA,CACP,QACA,WAAA,EACe;AACf,EAAA,IAAI,OAAO,UAAA,KAAe,WAAA,CAAY,KAAA,IAAS,CAAC,OAAO,UAAA,CAAA,EAAa;AAClE,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,KAAA;AACT;;"}
|
|
@@ -6,6 +6,7 @@ class DefaultGitlabCredentialsProvider {
|
|
|
6
6
|
constructor(providers) {
|
|
7
7
|
this.providers = providers;
|
|
8
8
|
}
|
|
9
|
+
providers;
|
|
9
10
|
static fromIntegrations(integrations) {
|
|
10
11
|
const credentialsProviders = /* @__PURE__ */ new Map();
|
|
11
12
|
integrations.gitlab.list().forEach((integration) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultGitlabCredentialsProvider.cjs.js","sources":["../../src/gitlab/DefaultGitlabCredentialsProvider.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 { ScmIntegrationRegistry } from '../registry';\nimport { SingleInstanceGitlabCredentialsProvider } from './SingleInstanceGitlabCredentialsProvider';\nimport { GitlabCredentials, GitlabCredentialsProvider } from './types';\n\n/**\n * Handles the creation and caching of credentials for GitLab integrations.\n *\n * @public\n */\nexport class DefaultGitlabCredentialsProvider\n implements GitlabCredentialsProvider\n{\n static fromIntegrations(integrations: ScmIntegrationRegistry) {\n const credentialsProviders: Map<string, GitlabCredentialsProvider> =\n new Map<string, GitlabCredentialsProvider>();\n\n integrations.gitlab.list().forEach(integration => {\n const credentialsProvider =\n SingleInstanceGitlabCredentialsProvider.create(integration.config);\n credentialsProviders.set(integration.config.host, credentialsProvider);\n });\n return new DefaultGitlabCredentialsProvider(credentialsProviders);\n }\n\n private constructor(\n private readonly providers: Map<string, GitlabCredentialsProvider>,\n ) {}\n\n async getCredentials(opts: { url: string }): Promise<GitlabCredentials> {\n const parsed = new URL(opts.url);\n const provider = this.providers.get(parsed.host);\n\n if (!provider) {\n throw new Error(\n `There is no GitLab integration that matches ${opts.url}. Please add a configuration for an integration.`,\n );\n }\n\n return provider.getCredentials(opts);\n }\n}\n"],"names":["SingleInstanceGitlabCredentialsProvider"],"mappings":";;;;AAyBO,MAAM,gCAAA,CAEb;AAAA,EAaU,YACW,SAAA,EACjB;AADiB,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AAAA,EAChB;AAAA,
|
|
1
|
+
{"version":3,"file":"DefaultGitlabCredentialsProvider.cjs.js","sources":["../../src/gitlab/DefaultGitlabCredentialsProvider.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 { ScmIntegrationRegistry } from '../registry';\nimport { SingleInstanceGitlabCredentialsProvider } from './SingleInstanceGitlabCredentialsProvider';\nimport { GitlabCredentials, GitlabCredentialsProvider } from './types';\n\n/**\n * Handles the creation and caching of credentials for GitLab integrations.\n *\n * @public\n */\nexport class DefaultGitlabCredentialsProvider\n implements GitlabCredentialsProvider\n{\n static fromIntegrations(integrations: ScmIntegrationRegistry) {\n const credentialsProviders: Map<string, GitlabCredentialsProvider> =\n new Map<string, GitlabCredentialsProvider>();\n\n integrations.gitlab.list().forEach(integration => {\n const credentialsProvider =\n SingleInstanceGitlabCredentialsProvider.create(integration.config);\n credentialsProviders.set(integration.config.host, credentialsProvider);\n });\n return new DefaultGitlabCredentialsProvider(credentialsProviders);\n }\n\n private constructor(\n private readonly providers: Map<string, GitlabCredentialsProvider>,\n ) {}\n\n async getCredentials(opts: { url: string }): Promise<GitlabCredentials> {\n const parsed = new URL(opts.url);\n const provider = this.providers.get(parsed.host);\n\n if (!provider) {\n throw new Error(\n `There is no GitLab integration that matches ${opts.url}. Please add a configuration for an integration.`,\n );\n }\n\n return provider.getCredentials(opts);\n }\n}\n"],"names":["SingleInstanceGitlabCredentialsProvider"],"mappings":";;;;AAyBO,MAAM,gCAAA,CAEb;AAAA,EAaU,YACW,SAAA,EACjB;AADiB,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AAAA,EAChB;AAAA,EADgB,SAAA;AAAA,EAbnB,OAAO,iBAAiB,YAAA,EAAsC;AAC5D,IAAA,MAAM,oBAAA,uBACA,GAAA,EAAuC;AAE7C,IAAA,YAAA,CAAa,MAAA,CAAO,IAAA,EAAK,CAAE,OAAA,CAAQ,CAAA,WAAA,KAAe;AAChD,MAAA,MAAM,mBAAA,GACJA,+EAAA,CAAwC,MAAA,CAAO,WAAA,CAAY,MAAM,CAAA;AACnE,MAAA,oBAAA,CAAqB,GAAA,CAAI,WAAA,CAAY,MAAA,CAAO,IAAA,EAAM,mBAAmB,CAAA;AAAA,IACvE,CAAC,CAAA;AACD,IAAA,OAAO,IAAI,iCAAiC,oBAAoB,CAAA;AAAA,EAClE;AAAA,EAMA,MAAM,eAAe,IAAA,EAAmD;AACtE,IAAA,MAAM,MAAA,GAAS,IAAI,GAAA,CAAI,IAAA,CAAK,GAAG,CAAA;AAC/B,IAAA,MAAM,QAAA,GAAW,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,OAAO,IAAI,CAAA;AAE/C,IAAA,IAAI,CAAC,QAAA,EAAU;AACb,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,4CAAA,EAA+C,KAAK,GAAG,CAAA,gDAAA;AAAA,OACzD;AAAA,IACF;AAEA,IAAA,OAAO,QAAA,CAAS,eAAe,IAAI,CAAA;AAAA,EACrC;AACF;;"}
|
|
@@ -4,6 +4,7 @@ class DefaultGitlabCredentialsProvider {
|
|
|
4
4
|
constructor(providers) {
|
|
5
5
|
this.providers = providers;
|
|
6
6
|
}
|
|
7
|
+
providers;
|
|
7
8
|
static fromIntegrations(integrations) {
|
|
8
9
|
const credentialsProviders = /* @__PURE__ */ new Map();
|
|
9
10
|
integrations.gitlab.list().forEach((integration) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultGitlabCredentialsProvider.esm.js","sources":["../../src/gitlab/DefaultGitlabCredentialsProvider.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 { ScmIntegrationRegistry } from '../registry';\nimport { SingleInstanceGitlabCredentialsProvider } from './SingleInstanceGitlabCredentialsProvider';\nimport { GitlabCredentials, GitlabCredentialsProvider } from './types';\n\n/**\n * Handles the creation and caching of credentials for GitLab integrations.\n *\n * @public\n */\nexport class DefaultGitlabCredentialsProvider\n implements GitlabCredentialsProvider\n{\n static fromIntegrations(integrations: ScmIntegrationRegistry) {\n const credentialsProviders: Map<string, GitlabCredentialsProvider> =\n new Map<string, GitlabCredentialsProvider>();\n\n integrations.gitlab.list().forEach(integration => {\n const credentialsProvider =\n SingleInstanceGitlabCredentialsProvider.create(integration.config);\n credentialsProviders.set(integration.config.host, credentialsProvider);\n });\n return new DefaultGitlabCredentialsProvider(credentialsProviders);\n }\n\n private constructor(\n private readonly providers: Map<string, GitlabCredentialsProvider>,\n ) {}\n\n async getCredentials(opts: { url: string }): Promise<GitlabCredentials> {\n const parsed = new URL(opts.url);\n const provider = this.providers.get(parsed.host);\n\n if (!provider) {\n throw new Error(\n `There is no GitLab integration that matches ${opts.url}. Please add a configuration for an integration.`,\n );\n }\n\n return provider.getCredentials(opts);\n }\n}\n"],"names":[],"mappings":";;AAyBO,MAAM,gCAAA,CAEb;AAAA,EAaU,YACW,SAAA,EACjB;AADiB,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AAAA,EAChB;AAAA,
|
|
1
|
+
{"version":3,"file":"DefaultGitlabCredentialsProvider.esm.js","sources":["../../src/gitlab/DefaultGitlabCredentialsProvider.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 { ScmIntegrationRegistry } from '../registry';\nimport { SingleInstanceGitlabCredentialsProvider } from './SingleInstanceGitlabCredentialsProvider';\nimport { GitlabCredentials, GitlabCredentialsProvider } from './types';\n\n/**\n * Handles the creation and caching of credentials for GitLab integrations.\n *\n * @public\n */\nexport class DefaultGitlabCredentialsProvider\n implements GitlabCredentialsProvider\n{\n static fromIntegrations(integrations: ScmIntegrationRegistry) {\n const credentialsProviders: Map<string, GitlabCredentialsProvider> =\n new Map<string, GitlabCredentialsProvider>();\n\n integrations.gitlab.list().forEach(integration => {\n const credentialsProvider =\n SingleInstanceGitlabCredentialsProvider.create(integration.config);\n credentialsProviders.set(integration.config.host, credentialsProvider);\n });\n return new DefaultGitlabCredentialsProvider(credentialsProviders);\n }\n\n private constructor(\n private readonly providers: Map<string, GitlabCredentialsProvider>,\n ) {}\n\n async getCredentials(opts: { url: string }): Promise<GitlabCredentials> {\n const parsed = new URL(opts.url);\n const provider = this.providers.get(parsed.host);\n\n if (!provider) {\n throw new Error(\n `There is no GitLab integration that matches ${opts.url}. Please add a configuration for an integration.`,\n );\n }\n\n return provider.getCredentials(opts);\n }\n}\n"],"names":[],"mappings":";;AAyBO,MAAM,gCAAA,CAEb;AAAA,EAaU,YACW,SAAA,EACjB;AADiB,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AAAA,EAChB;AAAA,EADgB,SAAA;AAAA,EAbnB,OAAO,iBAAiB,YAAA,EAAsC;AAC5D,IAAA,MAAM,oBAAA,uBACA,GAAA,EAAuC;AAE7C,IAAA,YAAA,CAAa,MAAA,CAAO,IAAA,EAAK,CAAE,OAAA,CAAQ,CAAA,WAAA,KAAe;AAChD,MAAA,MAAM,mBAAA,GACJ,uCAAA,CAAwC,MAAA,CAAO,WAAA,CAAY,MAAM,CAAA;AACnE,MAAA,oBAAA,CAAqB,GAAA,CAAI,WAAA,CAAY,MAAA,CAAO,IAAA,EAAM,mBAAmB,CAAA;AAAA,IACvE,CAAC,CAAA;AACD,IAAA,OAAO,IAAI,iCAAiC,oBAAoB,CAAA;AAAA,EAClE;AAAA,EAMA,MAAM,eAAe,IAAA,EAAmD;AACtE,IAAA,MAAM,MAAA,GAAS,IAAI,GAAA,CAAI,IAAA,CAAK,GAAG,CAAA;AAC/B,IAAA,MAAM,QAAA,GAAW,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,OAAO,IAAI,CAAA;AAE/C,IAAA,IAAI,CAAC,QAAA,EAAU;AACb,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,4CAAA,EAA+C,KAAK,GAAG,CAAA,gDAAA;AAAA,OACzD;AAAA,IACF;AAEA,IAAA,OAAO,QAAA,CAAS,eAAe,IAAI,CAAA;AAAA,EACrC;AACF;;"}
|
|
@@ -13,6 +13,7 @@ class GitLabIntegration {
|
|
|
13
13
|
this.integrationConfig = integrationConfig;
|
|
14
14
|
this.fetchImpl = this.createFetchStrategy();
|
|
15
15
|
}
|
|
16
|
+
integrationConfig;
|
|
16
17
|
static factory = ({ config: config$1 }) => {
|
|
17
18
|
const configs = config.readGitLabIntegrationConfigs(
|
|
18
19
|
config$1.getOptionalConfigArray("integrations.gitlab") ?? []
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GitLabIntegration.cjs.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 */\nimport { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport { ScmIntegration, ScmIntegrationsFactory } from '../types';\nimport {\n GitLabIntegrationConfig,\n readGitLabIntegrationConfigs,\n} from './config';\nimport pThrottle from 'p-throttle';\n\ntype FetchFunction = typeof fetch;\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 private readonly fetchImpl: FetchFunction;\n\n constructor(private readonly integrationConfig: GitLabIntegrationConfig) {\n // Configure fetch strategy based on configuration\n this.fetchImpl = this.createFetchStrategy();\n }\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 fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {\n return this.fetchImpl(input, init);\n }\n\n private createFetchStrategy(): FetchFunction {\n let fetchFn: FetchFunction = (url, options) => fetch(url, options);\n\n const retryConfig = this.integrationConfig.retry;\n if (retryConfig) {\n // Apply retry wrapper if configured\n fetchFn = this.withRetry(fetchFn, retryConfig);\n\n // Apply throttling wrapper if configured\n if (\n retryConfig.maxApiRequestsPerMinute &&\n retryConfig.maxApiRequestsPerMinute > 0\n ) {\n fetchFn = pThrottle({\n limit: retryConfig.maxApiRequestsPerMinute,\n interval: 60_000,\n })(fetchFn);\n }\n }\n\n return fetchFn;\n }\n\n private withRetry(\n fetchFn: FetchFunction,\n retryConfig: { maxRetries?: number; retryStatusCodes?: number[] },\n ): FetchFunction {\n const maxRetries = retryConfig?.maxRetries ?? 0;\n const retryStatusCodes = retryConfig?.retryStatusCodes ?? [];\n if (maxRetries <= 0 || retryStatusCodes.length === 0) {\n return fetchFn;\n }\n\n // Exponential backoff, cap at 10 seconds\n const backoffDelay = (a: number) =>\n Math.min(100 * Math.pow(2, a - 1), 10000);\n\n return async (url, options) => {\n const abortSignal = options?.signal;\n let attempt = 0;\n for (;;) {\n let response: Response;\n try {\n response = await fetchFn(url, options);\n } catch (e) {\n // The caller aborted — surface that immediately rather than retrying.\n if (abortSignal?.aborted) throw e;\n // No more attempts left — propagate the network error.\n if (attempt++ >= maxRetries) throw e;\n await sleep(backoffDelay(attempt), abortSignal);\n if (abortSignal?.aborted) throw e;\n continue;\n }\n\n // Successful, non-retryable response: return immediately\n if (!retryStatusCodes.includes(response.status)) {\n return response;\n }\n\n // No more attempts left — return the last (retryable) response.\n if (attempt++ >= maxRetries) {\n return response;\n }\n\n // Retry-After is either delay-seconds or an HTTP-date (RFC 9110 §10.2.3).\n const delay = parseRetryAfterMs(\n response.headers.get('Retry-After'),\n backoffDelay(attempt),\n );\n\n // Release the underlying connection so it can be reused, since we're\n // about to discard this response in favor of a retry.\n await response.body?.cancel().catch(() => {});\n\n await sleep(delay, abortSignal);\n if (abortSignal?.aborted) return response;\n }\n };\n }\n}\n\n/** @internal */\nexport function parseRetryAfterMs(\n headerValue: string | null,\n fallbackMs: number,\n): number {\n if (!headerValue) {\n return fallbackMs;\n }\n\n // delay-seconds per RFC 9110 is 1*DIGIT\n if (/^\\d+$/.test(headerValue)) {\n return Number(headerValue) * 1000;\n }\n\n // HTTP-dates (IMF-fixdate) always contain a comma, e.g.\n // \"Sun, 06 Nov 1994 08:49:37 GMT\" — use that as a prerequisite\n // to avoid Date.parse interpreting random strings as dates.\n if (headerValue.includes(',')) {\n const dateMs = Date.parse(headerValue);\n if (Number.isFinite(dateMs)) {\n const deltaMs = dateMs - Date.now();\n return deltaMs > 0 ? deltaMs : 0;\n }\n }\n\n return fallbackMs;\n}\n\n/** @internal */\nexport async function sleep(\n durationMs: number,\n abortSignal: AbortSignal | null | undefined,\n): Promise<void> {\n if (abortSignal?.aborted) {\n return;\n }\n\n await new Promise<void>(resolve => {\n let timeoutHandle: NodeJS.Timeout | undefined = undefined;\n\n const done = () => {\n if (timeoutHandle) {\n clearTimeout(timeoutHandle);\n }\n abortSignal?.removeEventListener('abort', done);\n resolve();\n };\n\n timeoutHandle = setTimeout(done, durationMs);\n abortSignal?.addEventListener('abort', done);\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":["config","readGitLabIntegrationConfigs","basicIntegrations","defaultScmResolveUrl","pThrottle"],"mappings":";;;;;;;;;;AA8BO,MAAM,iBAAA,CAA4C;AAAA,EAavD,YAA6B,iBAAA,EAA4C;AAA5C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAE3B,IAAA,IAAA,CAAK,SAAA,GAAY,KAAK,mBAAA,EAAoB;AAAA,EAC5C;AAAA,EAfA,OAAO,OAAA,GAAqD,CAAC,UAAEA,UAAO,KAAM;AAC1E,IAAA,MAAM,OAAA,GAAUC,mCAAA;AAAA,MACdD,QAAA,CAAO,sBAAA,CAAuB,qBAAqB,CAAA,IAAK;AAAC,KAC3D;AACA,IAAA,OAAOE,yBAAA;AAAA,MACL,QAAQ,GAAA,CAAI,CAAA,CAAA,KAAK,IAAI,iBAAA,CAAkB,CAAC,CAAC,CAAA;AAAA,MACzC,CAAA,CAAA,KAAK,EAAE,MAAA,CAAO;AAAA,KAChB;AAAA,EACF,CAAA;AAAA,EAEiB,SAAA;AAAA,EAOjB,IAAI,IAAA,GAAe;AACjB,IAAA,OAAO,QAAA;AAAA,EACT;AAAA,EAEA,IAAI,KAAA,GAAgB;AAClB,IAAA,OAAO,KAAK,iBAAA,CAAkB,IAAA;AAAA,EAChC;AAAA,EAEA,IAAI,MAAA,GAAkC;AACpC,IAAA,OAAO,IAAA,CAAK,iBAAA;AAAA,EACd;AAAA,EAEA,WAAW,OAAA,EAIA;AACT,IAAA,OAAOC,6BAAq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":["/*\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 */\nimport { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport { ScmIntegration, ScmIntegrationsFactory } from '../types';\nimport {\n GitLabIntegrationConfig,\n readGitLabIntegrationConfigs,\n} from './config';\nimport pThrottle from 'p-throttle';\n\ntype FetchFunction = typeof fetch;\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 private readonly fetchImpl: FetchFunction;\n\n constructor(private readonly integrationConfig: GitLabIntegrationConfig) {\n // Configure fetch strategy based on configuration\n this.fetchImpl = this.createFetchStrategy();\n }\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 fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {\n return this.fetchImpl(input, init);\n }\n\n private createFetchStrategy(): FetchFunction {\n let fetchFn: FetchFunction = (url, options) => fetch(url, options);\n\n const retryConfig = this.integrationConfig.retry;\n if (retryConfig) {\n // Apply retry wrapper if configured\n fetchFn = this.withRetry(fetchFn, retryConfig);\n\n // Apply throttling wrapper if configured\n if (\n retryConfig.maxApiRequestsPerMinute &&\n retryConfig.maxApiRequestsPerMinute > 0\n ) {\n fetchFn = pThrottle({\n limit: retryConfig.maxApiRequestsPerMinute,\n interval: 60_000,\n })(fetchFn);\n }\n }\n\n return fetchFn;\n }\n\n private withRetry(\n fetchFn: FetchFunction,\n retryConfig: { maxRetries?: number; retryStatusCodes?: number[] },\n ): FetchFunction {\n const maxRetries = retryConfig?.maxRetries ?? 0;\n const retryStatusCodes = retryConfig?.retryStatusCodes ?? [];\n if (maxRetries <= 0 || retryStatusCodes.length === 0) {\n return fetchFn;\n }\n\n // Exponential backoff, cap at 10 seconds\n const backoffDelay = (a: number) =>\n Math.min(100 * Math.pow(2, a - 1), 10000);\n\n return async (url, options) => {\n const abortSignal = options?.signal;\n let attempt = 0;\n for (;;) {\n let response: Response;\n try {\n response = await fetchFn(url, options);\n } catch (e) {\n // The caller aborted — surface that immediately rather than retrying.\n if (abortSignal?.aborted) throw e;\n // No more attempts left — propagate the network error.\n if (attempt++ >= maxRetries) throw e;\n await sleep(backoffDelay(attempt), abortSignal);\n if (abortSignal?.aborted) throw e;\n continue;\n }\n\n // Successful, non-retryable response: return immediately\n if (!retryStatusCodes.includes(response.status)) {\n return response;\n }\n\n // No more attempts left — return the last (retryable) response.\n if (attempt++ >= maxRetries) {\n return response;\n }\n\n // Retry-After is either delay-seconds or an HTTP-date (RFC 9110 §10.2.3).\n const delay = parseRetryAfterMs(\n response.headers.get('Retry-After'),\n backoffDelay(attempt),\n );\n\n // Release the underlying connection so it can be reused, since we're\n // about to discard this response in favor of a retry.\n await response.body?.cancel().catch(() => {});\n\n await sleep(delay, abortSignal);\n if (abortSignal?.aborted) return response;\n }\n };\n }\n}\n\n/** @internal */\nexport function parseRetryAfterMs(\n headerValue: string | null,\n fallbackMs: number,\n): number {\n if (!headerValue) {\n return fallbackMs;\n }\n\n // delay-seconds per RFC 9110 is 1*DIGIT\n if (/^\\d+$/.test(headerValue)) {\n return Number(headerValue) * 1000;\n }\n\n // HTTP-dates (IMF-fixdate) always contain a comma, e.g.\n // \"Sun, 06 Nov 1994 08:49:37 GMT\" — use that as a prerequisite\n // to avoid Date.parse interpreting random strings as dates.\n if (headerValue.includes(',')) {\n const dateMs = Date.parse(headerValue);\n if (Number.isFinite(dateMs)) {\n const deltaMs = dateMs - Date.now();\n return deltaMs > 0 ? deltaMs : 0;\n }\n }\n\n return fallbackMs;\n}\n\n/** @internal */\nexport async function sleep(\n durationMs: number,\n abortSignal: AbortSignal | null | undefined,\n): Promise<void> {\n if (abortSignal?.aborted) {\n return;\n }\n\n await new Promise<void>(resolve => {\n let timeoutHandle: NodeJS.Timeout | undefined = undefined;\n\n const done = () => {\n if (timeoutHandle) {\n clearTimeout(timeoutHandle);\n }\n abortSignal?.removeEventListener('abort', done);\n resolve();\n };\n\n timeoutHandle = setTimeout(done, durationMs);\n abortSignal?.addEventListener('abort', done);\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":["config","readGitLabIntegrationConfigs","basicIntegrations","defaultScmResolveUrl","pThrottle"],"mappings":";;;;;;;;;;AA8BO,MAAM,iBAAA,CAA4C;AAAA,EAavD,YAA6B,iBAAA,EAA4C;AAA5C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAE3B,IAAA,IAAA,CAAK,SAAA,GAAY,KAAK,mBAAA,EAAoB;AAAA,EAC5C;AAAA,EAH6B,iBAAA;AAAA,EAZ7B,OAAO,OAAA,GAAqD,CAAC,UAAEA,UAAO,KAAM;AAC1E,IAAA,MAAM,OAAA,GAAUC,mCAAA;AAAA,MACdD,QAAA,CA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aAAA,EAAe;AACjB,QAAA,YAAA,CAAa,aAAa,CAAA;AAAA,MAC5B;AACA,MAAA,WAAA,EAAa,mBAAA,CAAoB,SAAS,IAAI,CAAA;AAC9C,MAAA,OAAA,EAAQ;AAAA,IACV,CAAA;AAEA,IAAA,aAAA,GAAgB,UAAA,CAAW,MAAM,UAAU,CAAA;AAC3C,IAAA,WAAA,EAAa,gBAAA,CAAiB,SAAS,IAAI,CAAA;AAAA,EAC7C,CAAC,CAAA;AACH;AASO,SAAS,oBAAA,CACd,KACA,IAAA,EACQ;AACR,EAAA,OAAO,GAAA,CAAI,OAAA,CAAQ,0BAAA,EAA4B,CAAA,GAAA,EAAM,IAAI,CAAA,CAAA,CAAG,CAAA;AAC9D;;;;;"}
|
|
@@ -7,6 +7,7 @@ class GitLabIntegration {
|
|
|
7
7
|
this.integrationConfig = integrationConfig;
|
|
8
8
|
this.fetchImpl = this.createFetchStrategy();
|
|
9
9
|
}
|
|
10
|
+
integrationConfig;
|
|
10
11
|
static factory = ({ config }) => {
|
|
11
12
|
const configs = readGitLabIntegrationConfigs(
|
|
12
13
|
config.getOptionalConfigArray("integrations.gitlab") ?? []
|
|
@@ -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 */\nimport { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport { ScmIntegration, ScmIntegrationsFactory } from '../types';\nimport {\n GitLabIntegrationConfig,\n readGitLabIntegrationConfigs,\n} from './config';\nimport pThrottle from 'p-throttle';\n\ntype FetchFunction = typeof fetch;\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 private readonly fetchImpl: FetchFunction;\n\n constructor(private readonly integrationConfig: GitLabIntegrationConfig) {\n // Configure fetch strategy based on configuration\n this.fetchImpl = this.createFetchStrategy();\n }\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 fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {\n return this.fetchImpl(input, init);\n }\n\n private createFetchStrategy(): FetchFunction {\n let fetchFn: FetchFunction = (url, options) => fetch(url, options);\n\n const retryConfig = this.integrationConfig.retry;\n if (retryConfig) {\n // Apply retry wrapper if configured\n fetchFn = this.withRetry(fetchFn, retryConfig);\n\n // Apply throttling wrapper if configured\n if (\n retryConfig.maxApiRequestsPerMinute &&\n retryConfig.maxApiRequestsPerMinute > 0\n ) {\n fetchFn = pThrottle({\n limit: retryConfig.maxApiRequestsPerMinute,\n interval: 60_000,\n })(fetchFn);\n }\n }\n\n return fetchFn;\n }\n\n private withRetry(\n fetchFn: FetchFunction,\n retryConfig: { maxRetries?: number; retryStatusCodes?: number[] },\n ): FetchFunction {\n const maxRetries = retryConfig?.maxRetries ?? 0;\n const retryStatusCodes = retryConfig?.retryStatusCodes ?? [];\n if (maxRetries <= 0 || retryStatusCodes.length === 0) {\n return fetchFn;\n }\n\n // Exponential backoff, cap at 10 seconds\n const backoffDelay = (a: number) =>\n Math.min(100 * Math.pow(2, a - 1), 10000);\n\n return async (url, options) => {\n const abortSignal = options?.signal;\n let attempt = 0;\n for (;;) {\n let response: Response;\n try {\n response = await fetchFn(url, options);\n } catch (e) {\n // The caller aborted — surface that immediately rather than retrying.\n if (abortSignal?.aborted) throw e;\n // No more attempts left — propagate the network error.\n if (attempt++ >= maxRetries) throw e;\n await sleep(backoffDelay(attempt), abortSignal);\n if (abortSignal?.aborted) throw e;\n continue;\n }\n\n // Successful, non-retryable response: return immediately\n if (!retryStatusCodes.includes(response.status)) {\n return response;\n }\n\n // No more attempts left — return the last (retryable) response.\n if (attempt++ >= maxRetries) {\n return response;\n }\n\n // Retry-After is either delay-seconds or an HTTP-date (RFC 9110 §10.2.3).\n const delay = parseRetryAfterMs(\n response.headers.get('Retry-After'),\n backoffDelay(attempt),\n );\n\n // Release the underlying connection so it can be reused, since we're\n // about to discard this response in favor of a retry.\n await response.body?.cancel().catch(() => {});\n\n await sleep(delay, abortSignal);\n if (abortSignal?.aborted) return response;\n }\n };\n }\n}\n\n/** @internal */\nexport function parseRetryAfterMs(\n headerValue: string | null,\n fallbackMs: number,\n): number {\n if (!headerValue) {\n return fallbackMs;\n }\n\n // delay-seconds per RFC 9110 is 1*DIGIT\n if (/^\\d+$/.test(headerValue)) {\n return Number(headerValue) * 1000;\n }\n\n // HTTP-dates (IMF-fixdate) always contain a comma, e.g.\n // \"Sun, 06 Nov 1994 08:49:37 GMT\" — use that as a prerequisite\n // to avoid Date.parse interpreting random strings as dates.\n if (headerValue.includes(',')) {\n const dateMs = Date.parse(headerValue);\n if (Number.isFinite(dateMs)) {\n const deltaMs = dateMs - Date.now();\n return deltaMs > 0 ? deltaMs : 0;\n }\n }\n\n return fallbackMs;\n}\n\n/** @internal */\nexport async function sleep(\n durationMs: number,\n abortSignal: AbortSignal | null | undefined,\n): Promise<void> {\n if (abortSignal?.aborted) {\n return;\n }\n\n await new Promise<void>(resolve => {\n let timeoutHandle: NodeJS.Timeout | undefined = undefined;\n\n const done = () => {\n if (timeoutHandle) {\n clearTimeout(timeoutHandle);\n }\n abortSignal?.removeEventListener('abort', done);\n resolve();\n };\n\n timeoutHandle = setTimeout(done, durationMs);\n abortSignal?.addEventListener('abort', done);\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":";;;;AA8BO,MAAM,iBAAA,CAA4C;AAAA,EAavD,YAA6B,iBAAA,EAA4C;AAA5C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAE3B,IAAA,IAAA,CAAK,SAAA,GAAY,KAAK,mBAAA,EAAoB;AAAA,EAC5C;AAAA,EAfA,OAAO,OAAA,GAAqD,CAAC,EAAE,QAAO,KAAM;AAC1E,IAAA,MAAM,OAAA,GAAU,4BAAA;AAAA,MACd,MAAA,CAAO,sBAAA,CAAuB,qBAAqB,CAAA,IAAK;AAAC,KAC3D;AACA,IAAA,OAAO,iBAAA;AAAA,MACL,QAAQ,GAAA,CAAI,CAAA,CAAA,KAAK,IAAI,iBAAA,CAAkB,CAAC,CAAC,CAAA;AAAA,MACzC,CAAA,CAAA,KAAK,EAAE,MAAA,CAAO;AAAA,KAChB;AAAA,EACF,CAAA;AAAA,EAEiB,SAAA;AAAA,EAOjB,IAAI,IAAA,GAAe;AACjB,IAAA,OAAO,QAAA;AAAA,EACT;AAAA,EAEA,IAAI,KAAA,GAAgB;AAClB,IAAA,OAAO,KAAK,iBAAA,CAAkB,IAAA;AAAA,EAChC;AAAA,EAEA,IAAI,MAAA,GAAkC;AACpC,IAAA,OAAO,IAAA,CAAK,iBAAA;AAAA,EACd;AAAA,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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 */\nimport { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport { ScmIntegration, ScmIntegrationsFactory } from '../types';\nimport {\n GitLabIntegrationConfig,\n readGitLabIntegrationConfigs,\n} from './config';\nimport pThrottle from 'p-throttle';\n\ntype FetchFunction = typeof fetch;\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 private readonly fetchImpl: FetchFunction;\n\n constructor(private readonly integrationConfig: GitLabIntegrationConfig) {\n // Configure fetch strategy based on configuration\n this.fetchImpl = this.createFetchStrategy();\n }\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 fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {\n return this.fetchImpl(input, init);\n }\n\n private createFetchStrategy(): FetchFunction {\n let fetchFn: FetchFunction = (url, options) => fetch(url, options);\n\n const retryConfig = this.integrationConfig.retry;\n if (retryConfig) {\n // Apply retry wrapper if configured\n fetchFn = this.withRetry(fetchFn, retryConfig);\n\n // Apply throttling wrapper if configured\n if (\n retryConfig.maxApiRequestsPerMinute &&\n retryConfig.maxApiRequestsPerMinute > 0\n ) {\n fetchFn = pThrottle({\n limit: retryConfig.maxApiRequestsPerMinute,\n interval: 60_000,\n })(fetchFn);\n }\n }\n\n return fetchFn;\n }\n\n private withRetry(\n fetchFn: FetchFunction,\n retryConfig: { maxRetries?: number; retryStatusCodes?: number[] },\n ): FetchFunction {\n const maxRetries = retryConfig?.maxRetries ?? 0;\n const retryStatusCodes = retryConfig?.retryStatusCodes ?? [];\n if (maxRetries <= 0 || retryStatusCodes.length === 0) {\n return fetchFn;\n }\n\n // Exponential backoff, cap at 10 seconds\n const backoffDelay = (a: number) =>\n Math.min(100 * Math.pow(2, a - 1), 10000);\n\n return async (url, options) => {\n const abortSignal = options?.signal;\n let attempt = 0;\n for (;;) {\n let response: Response;\n try {\n response = await fetchFn(url, options);\n } catch (e) {\n // The caller aborted — surface that immediately rather than retrying.\n if (abortSignal?.aborted) throw e;\n // No more attempts left — propagate the network error.\n if (attempt++ >= maxRetries) throw e;\n await sleep(backoffDelay(attempt), abortSignal);\n if (abortSignal?.aborted) throw e;\n continue;\n }\n\n // Successful, non-retryable response: return immediately\n if (!retryStatusCodes.includes(response.status)) {\n return response;\n }\n\n // No more attempts left — return the last (retryable) response.\n if (attempt++ >= maxRetries) {\n return response;\n }\n\n // Retry-After is either delay-seconds or an HTTP-date (RFC 9110 §10.2.3).\n const delay = parseRetryAfterMs(\n response.headers.get('Retry-After'),\n backoffDelay(attempt),\n );\n\n // Release the underlying connection so it can be reused, since we're\n // about to discard this response in favor of a retry.\n await response.body?.cancel().catch(() => {});\n\n await sleep(delay, abortSignal);\n if (abortSignal?.aborted) return response;\n }\n };\n }\n}\n\n/** @internal */\nexport function parseRetryAfterMs(\n headerValue: string | null,\n fallbackMs: number,\n): number {\n if (!headerValue) {\n return fallbackMs;\n }\n\n // delay-seconds per RFC 9110 is 1*DIGIT\n if (/^\\d+$/.test(headerValue)) {\n return Number(headerValue) * 1000;\n }\n\n // HTTP-dates (IMF-fixdate) always contain a comma, e.g.\n // \"Sun, 06 Nov 1994 08:49:37 GMT\" — use that as a prerequisite\n // to avoid Date.parse interpreting random strings as dates.\n if (headerValue.includes(',')) {\n const dateMs = Date.parse(headerValue);\n if (Number.isFinite(dateMs)) {\n const deltaMs = dateMs - Date.now();\n return deltaMs > 0 ? deltaMs : 0;\n }\n }\n\n return fallbackMs;\n}\n\n/** @internal */\nexport async function sleep(\n durationMs: number,\n abortSignal: AbortSignal | null | undefined,\n): Promise<void> {\n if (abortSignal?.aborted) {\n return;\n }\n\n await new Promise<void>(resolve => {\n let timeoutHandle: NodeJS.Timeout | undefined = undefined;\n\n const done = () => {\n if (timeoutHandle) {\n clearTimeout(timeoutHandle);\n }\n abortSignal?.removeEventListener('abort', done);\n resolve();\n };\n\n timeoutHandle = setTimeout(done, durationMs);\n abortSignal?.addEventListener('abort', done);\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":";;;;AA8BO,MAAM,iBAAA,CAA4C;AAAA,EAavD,YAA6B,iBAAA,EAA4C;AAA5C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAE3B,IAAA,IAAA,CAAK,SAAA,GAAY,KAAK,mBAAA,EAAoB;AAAA,EAC5C;AAAA,EAH6B,iBAAA;AAAA,EAZ7B,OAAO,OAAA,GAAqD,CAAC,EAAE,QAAO,KAAM;AAC1E,IAAA,MAAM,OAAA,GAAU,4BAAA;AAAA,MACd,MAAA,CAAO,sBAAA,CAAuB,qBAA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A,CAAa,aAAa,CAAA;AAAA,MAC5B;AACA,MAAA,WAAA,EAAa,mBAAA,CAAoB,SAAS,IAAI,CAAA;AAC9C,MAAA,OAAA,EAAQ;AAAA,IACV,CAAA;AAEA,IAAA,aAAA,GAAgB,UAAA,CAAW,MAAM,UAAU,CAAA;AAC3C,IAAA,WAAA,EAAa,gBAAA,CAAiB,SAAS,IAAI,CAAA;AAAA,EAC7C,CAAC,CAAA;AACH;AASO,SAAS,oBAAA,CACd,KACA,IAAA,EACQ;AACR,EAAA,OAAO,GAAA,CAAI,OAAA,CAAQ,0BAAA,EAA4B,CAAA,GAAA,EAAM,IAAI,CAAA,CAAA,CAAG,CAAA;AAC9D;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SingleInstanceGitlabCredentialsProvider.cjs.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,uCAAA,CAEb;AAAA,EAOU,YAA6B,KAAA,EAAgB;AAAhB,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AAAA,EAAiB;AAAA,
|
|
1
|
+
{"version":3,"file":"SingleInstanceGitlabCredentialsProvider.cjs.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,uCAAA,CAEb;AAAA,EAOU,YAA6B,KAAA,EAAgB;AAAhB,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AAAA,EAAiB;AAAA,EAAjB,KAAA;AAAA,EANrC,OAAO,SAE0B,CAAA,MAAA,KAAU;AACzC,IAAA,OAAO,IAAI,uCAAA,CAAwC,MAAA,CAAO,KAAK,CAAA;AAAA,EACjE,CAAA;AAAA,EAIA,MAAM,eAAe,KAAA,EAAoD;AACvE,IAAA,IAAI,CAAC,KAAK,KAAA,EAAO;AACf,MAAA,OAAO,EAAC;AAAA,IACV;AAEA,IAAA,OAAO;AAAA,MACL,OAAA,EAAS;AAAA,QACP,aAAA,EAAe,CAAA,OAAA,EAAU,IAAA,CAAK,KAAK,CAAA;AAAA,OACrC;AAAA,MACA,OAAO,IAAA,CAAK;AAAA,KACd;AAAA,EACF;AACF;;"}
|
|
@@ -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,uCAAA,CAEb;AAAA,EAOU,YAA6B,KAAA,EAAgB;AAAhB,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AAAA,EAAiB;AAAA,
|
|
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,uCAAA,CAEb;AAAA,EAOU,YAA6B,KAAA,EAAgB;AAAhB,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AAAA,EAAiB;AAAA,EAAjB,KAAA;AAAA,EANrC,OAAO,SAE0B,CAAA,MAAA,KAAU;AACzC,IAAA,OAAO,IAAI,uCAAA,CAAwC,MAAA,CAAO,KAAK,CAAA;AAAA,EACjE,CAAA;AAAA,EAIA,MAAM,eAAe,KAAA,EAAoD;AACvE,IAAA,IAAI,CAAC,KAAK,KAAA,EAAO;AACf,MAAA,OAAO,EAAC;AAAA,IACV;AAEA,IAAA,OAAO;AAAA,MACL,OAAA,EAAS;AAAA,QACP,aAAA,EAAe,CAAA,OAAA,EAAU,IAAA,CAAK,KAAK,CAAA;AAAA,OACrC;AAAA,MACA,OAAO,IAAA,CAAK;AAAA,KACd;AAAA,EACF;AACF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.cjs.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 * Reads an optional number array from config\n */\nfunction readOptionalNumberArray(\n config: Config,\n key: string,\n): number[] | undefined {\n const value = config.getOptional(key);\n if (value === undefined) {\n return undefined;\n }\n if (!Array.isArray(value)) {\n throw new Error(\n `Invalid ${key} config: expected an array, got ${typeof value}`,\n );\n }\n return value.map((item, index) => {\n if (typeof item !== 'number') {\n throw new Error(\n `Invalid ${key} config: all values must be numbers, got ${typeof item} at index ${index}`,\n );\n }\n return item;\n });\n}\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 * Signing key to sign commits\n */\n commitSigningKey?: string;\n\n /**\n * Retry configuration for failed requests.\n */\n retry?: {\n /**\n * Maximum number of retries for failed requests\n * @defaultValue 0\n */\n maxRetries?: number;\n\n /**\n * HTTP status codes that should trigger a retry\n * @defaultValue []\n */\n retryStatusCodes?: number[];\n\n /**\n * Rate limit for requests per minute\n * @defaultValue -1\n */\n maxApiRequestsPerMinute?: number;\n };\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 const retryConfig = config.getOptionalConfig('retry');\n\n const retry = retryConfig\n ? {\n maxRetries: retryConfig.getOptionalNumber('maxRetries') ?? 0,\n retryStatusCodes:\n readOptionalNumberArray(retryConfig, 'retryStatusCodes') ?? [],\n maxApiRequestsPerMinute:\n retryConfig.getOptionalNumber('maxApiRequestsPerMinute') ?? -1,\n }\n : undefined;\n\n return {\n host,\n token,\n apiBaseUrl,\n baseUrl,\n commitSigningKey: config.getOptionalString('commitSigningKey'),\n retry,\n };\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":["trimEnd","isValidHost","isValidUrl"],"mappings":";;;;;AAoBA,MAAM,WAAA,GAAc,YAAA;AACpB,MAAM,mBAAA,GAAsB,2BAAA;AAK5B,SAAS,uBAAA,CACP,QACA,GAAA,EACsB;AACtB,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,WAAA,CAAY,GAAG,CAAA;AACpC,EAAA,IAAI,UAAU,MAAA,EAAW;AACvB,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,IAAI,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACzB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,QAAA,EAAW,GAAG,CAAA,gCAAA,EAAmC,OAAO,KAAK,CAAA;AAAA,KAC/D;AAAA,EACF;AACA,EAAA,OAAO,KAAA,CAAM,GAAA,CAAI,CAAC,IAAA,EAAM,KAAA,KAAU;AAChC,IAAA,IAAI,OAAO,SAAS,QAAA,EAAU;AAC5B,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,WAAW,GAAG,CAAA,yCAAA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cesContent":["/*\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 * Reads an optional number array from config\n */\nfunction readOptionalNumberArray(\n config: Config,\n key: string,\n): number[] | undefined {\n const value = config.getOptional(key);\n if (value === undefined) {\n return undefined;\n }\n if (!Array.isArray(value)) {\n throw new Error(\n `Invalid ${key} config: expected an array, got ${typeof value}`,\n );\n }\n return value.map((item, index) => {\n if (typeof item !== 'number') {\n throw new Error(\n `Invalid ${key} config: all values must be numbers, got ${typeof item} at index ${index}`,\n );\n }\n return item;\n });\n}\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 * Signing key to sign commits\n */\n commitSigningKey?: string;\n\n /**\n * Retry configuration for failed requests.\n */\n retry?: {\n /**\n * Maximum number of retries for failed requests\n * @defaultValue 0\n */\n maxRetries?: number;\n\n /**\n * HTTP status codes that should trigger a retry\n * @defaultValue []\n */\n retryStatusCodes?: number[];\n\n /**\n * Rate limit for requests per minute\n * @defaultValue -1\n */\n maxApiRequestsPerMinute?: number;\n };\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 const retryConfig = config.getOptionalConfig('retry');\n\n const retry = retryConfig\n ? {\n maxRetries: retryConfig.getOptionalNumber('maxRetries') ?? 0,\n retryStatusCodes:\n readOptionalNumberArray(retryConfig, 'retryStatusCodes') ?? [],\n maxApiRequestsPerMinute:\n retryConfig.getOptionalNumber('maxApiRequestsPerMinute') ?? -1,\n }\n : undefined;\n\n return {\n host,\n token,\n apiBaseUrl,\n baseUrl,\n commitSigningKey: config.getOptionalString('commitSigningKey'),\n retry,\n };\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":["trimEnd","isValidHost","isValidUrl"],"mappings":";;;;;AAoBA,MAAM,WAAA,GAAc,YAAA;AACpB,MAAM,mBAAA,GAAsB,2BAAA;AAK5B,SAAS,uBAAA,CACP,QACA,GAAA,EACsB;AACtB,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,WAAA,CAAY,GAAG,CAAA;AACpC,EAAA,IAAI,UAAU,MAAA,EAAW;AACvB,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,IAAI,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACzB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,QAAA,EAAW,GAAG,CAAA,gCAAA,EAAmC,OAAO,KAAK,CAAA;AAAA,KAC/D;AAAA,EACF;AACA,EAAA,OAAO,KAAA,CAAM,GAAA,CAAI,CAAC,IAAA,EAAM,KAAA,KAAU;AAChC,IAAA,IAAI,OAAO,SAAS,QAAA,EAAU;AAC5B,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,WAAW,GAAG,CAAA,yCAAA,EAA4C,OAAO,IAAI,aAAa,KAAK,CAAA;AAAA,OACzF;AAAA,IACF;AACA,IA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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 * Reads an optional number array from config\n */\nfunction readOptionalNumberArray(\n config: Config,\n key: string,\n): number[] | undefined {\n const value = config.getOptional(key);\n if (value === undefined) {\n return undefined;\n }\n if (!Array.isArray(value)) {\n throw new Error(\n `Invalid ${key} config: expected an array, got ${typeof value}`,\n );\n }\n return value.map((item, index) => {\n if (typeof item !== 'number') {\n throw new Error(\n `Invalid ${key} config: all values must be numbers, got ${typeof item} at index ${index}`,\n );\n }\n return item;\n });\n}\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 * Signing key to sign commits\n */\n commitSigningKey?: string;\n\n /**\n * Retry configuration for failed requests.\n */\n retry?: {\n /**\n * Maximum number of retries for failed requests\n * @defaultValue 0\n */\n maxRetries?: number;\n\n /**\n * HTTP status codes that should trigger a retry\n * @defaultValue []\n */\n retryStatusCodes?: number[];\n\n /**\n * Rate limit for requests per minute\n * @defaultValue -1\n */\n maxApiRequestsPerMinute?: number;\n };\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 const retryConfig = config.getOptionalConfig('retry');\n\n const retry = retryConfig\n ? {\n maxRetries: retryConfig.getOptionalNumber('maxRetries') ?? 0,\n retryStatusCodes:\n readOptionalNumberArray(retryConfig, 'retryStatusCodes') ?? [],\n maxApiRequestsPerMinute:\n retryConfig.getOptionalNumber('maxApiRequestsPerMinute') ?? -1,\n }\n : undefined;\n\n return {\n host,\n token,\n apiBaseUrl,\n baseUrl,\n commitSigningKey: config.getOptionalString('commitSigningKey'),\n retry,\n };\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,WAAA,GAAc,YAAA;AACpB,MAAM,mBAAA,GAAsB,2BAAA;AAK5B,SAAS,uBAAA,CACP,QACA,GAAA,EACsB;AACtB,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,WAAA,CAAY,GAAG,CAAA;AACpC,EAAA,IAAI,UAAU,MAAA,EAAW;AACvB,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,IAAI,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACzB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,QAAA,EAAW,GAAG,CAAA,gCAAA,EAAmC,OAAO,KAAK,CAAA;AAAA,KAC/D;AAAA,EACF;AACA,EAAA,OAAO,KAAA,CAAM,GAAA,CAAI,CAAC,IAAA,EAAM,KAAA,KAAU;AAChC,IAAA,IAAI,OAAO,SAAS,QAAA,EAAU;AAC5B,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,WAAW,GAAG,CAAA,yCAAA,EAA4C,OAAO,IAAI,aAAa,KAAK,CAAA;AAAA,OACzF;AAAA,IACF;AACA,IAAA,OAAO,IAAA;AAAA,EACT,CAAC,CAAA;AACH;AAuEO,SAAS,4BACd,MAA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AAkB,YAAY,CAAA,IAAK,CAAA;AAAA,IAC3D,gBAAA,EACE,uBAAA,CAAwB,WAAA,EAAa,kBAAkB,KAAK,EAAC;AAAA,IAC/D,uBAAA,EACE,WAAA,CAAY,iBAAA,CAAkB,yBAAyB,CAAA,IAAK;AAAA,GAChE,GACA,MAAA;AAEJ,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,KAAA;AAAA,IACA,UAAA;AAAA,IACA,OAAA;AAAA,IACA,gBAAA,EAAkB,MAAA,CAAO,iBAAA,CAAkB,kBAAkB,CAAA;AAAA,IAC7D;AAAA,GACF;AACF;AASO,SAAS,6BACd,OAAA,EAC2B;AAE3B,EAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,GAAA,CAAI,2BAA2B,CAAA;AAItD,EAAA,IAAI,CAAC,MAAA,CAAO,IAAA,CAAK,OAAK,CAAA,CAAE,IAAA,KAAS,WAAW,CAAA,EAAG;AAC7C,IAAA,MAAA,CAAO,IAAA,CAAK;AAAA,MACV,IAAA,EAAM,WAAA;AAAA,MACN,UAAA,EAAY,mBAAA;AAAA,MACZ,OAAA,EAAS,WAAW,WAAW,CAAA;AAAA,KAChC,CAAA;AAAA,EACH;AAEA,EAAA,OAAO,MAAA;AACT;AASO,SAAS,iCACd,MAAA,EACQ;AACR,EAAA,IAAI,YAAA,GAAe,EAAA;AACnB,EAAA,IAAI,MAAA,CAAO,SAAS,WAAA,EAAa;AAC/B,IAAA,YAAA,GAAe,IAAI,GAAA,CAAI,MAAA,CAAO,OAAO,CAAA,CAAE,QAAA;AAAA,EACzC;AACA,EAAA,OAAO,OAAA,CAAQ,cAAc,GAAG,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 * Reads an optional number array from config\n */\nfunction readOptionalNumberArray(\n config: Config,\n key: string,\n): number[] | undefined {\n const value = config.getOptional(key);\n if (value === undefined) {\n return undefined;\n }\n if (!Array.isArray(value)) {\n throw new Error(\n `Invalid ${key} config: expected an array, got ${typeof value}`,\n );\n }\n return value.map((item, index) => {\n if (typeof item !== 'number') {\n throw new Error(\n `Invalid ${key} config: all values must be numbers, got ${typeof item} at index ${index}`,\n );\n }\n return item;\n });\n}\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 * Signing key to sign commits\n */\n commitSigningKey?: string;\n\n /**\n * Retry configuration for failed requests.\n */\n retry?: {\n /**\n * Maximum number of retries for failed requests\n * @defaultValue 0\n */\n maxRetries?: number;\n\n /**\n * HTTP status codes that should trigger a retry\n * @defaultValue []\n */\n retryStatusCodes?: number[];\n\n /**\n * Rate limit for requests per minute\n * @defaultValue -1\n */\n maxApiRequestsPerMinute?: number;\n };\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 const retryConfig = config.getOptionalConfig('retry');\n\n const retry = retryConfig\n ? {\n maxRetries: retryConfig.getOptionalNumber('maxRetries') ?? 0,\n retryStatusCodes:\n readOptionalNumberArray(retryConfig, 'retryStatusCodes') ?? [],\n maxApiRequestsPerMinute:\n retryConfig.getOptionalNumber('maxApiRequestsPerMinute') ?? -1,\n }\n : undefined;\n\n return {\n host,\n token,\n apiBaseUrl,\n baseUrl,\n commitSigningKey: config.getOptionalString('commitSigningKey'),\n retry,\n };\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,WAAA,GAAc,YAAA;AACpB,MAAM,mBAAA,GAAsB,2BAAA;AAK5B,SAAS,uBAAA,CACP,QACA,GAAA,EACsB;AACtB,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,WAAA,CAAY,GAAG,CAAA;AACpC,EAAA,IAAI,UAAU,MAAA,EAAW;AACvB,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,IAAI,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACzB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,QAAA,EAAW,GAAG,CAAA,gCAAA,EAAmC,OAAO,KAAK,CAAA;AAAA,KAC/D;AAAA,EACF;AACA,EAAA,OAAO,KAAA,CAAM,GAAA,CAAI,CAAC,IAAA,EAAM,KAAA,KAAU;AAChC,IAAA,IAAI,OAAO,SAAS,QAAA,EAAU;AAC5B,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,WAAW,GAAG,CAAA,yCAAA,EAA4C,OAAO,IAAI,aAAa,KAAK,CAAA;AAAA,OACzF;AAAA,IACF;AACA,IAAA,OAAO,IAAA;AAAA,EACT,CAAC,CAAA;AACH;AAuEO,SAAS,4BACd,MAAA,EACyB;AACzB,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,SAAA,CAAU,MAAM,CAAA;AACpC,EAAA,IAAI,UAAA,GAA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AAAA,IAC/D,uBAAA,EACE,WAAA,CAAY,iBAAA,CAAkB,yBAAyB,CAAA,IAAK;AAAA,GAChE,GACA,MAAA;AAEJ,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,KAAA;AAAA,IACA,UAAA;AAAA,IACA,OAAA;AAAA,IACA,gBAAA,EAAkB,MAAA,CAAO,iBAAA,CAAkB,kBAAkB,CAAA;AAAA,IAC7D;AAAA,GACF;AACF;AASO,SAAS,6BACd,OAAA,EAC2B;AAE3B,EAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,GAAA,CAAI,2BAA2B,CAAA;AAItD,EAAA,IAAI,CAAC,MAAA,CAAO,IAAA,CAAK,OAAK,CAAA,CAAE,IAAA,KAAS,WAAW,CAAA,EAAG;AAC7C,IAAA,MAAA,CAAO,IAAA,CAAK;AAAA,MACV,IAAA,EAAM,WAAA;AAAA,MACN,UAAA,EAAY,mBAAA;AAAA,MACZ,OAAA,EAAS,WAAW,WAAW,CAAA;AAAA,KAChC,CAAA;AAAA,EACH;AAEA,EAAA,OAAO,MAAA;AACT;AASO,SAAS,iCACd,MAAA,EACQ;AACR,EAAA,IAAI,YAAA,GAAe,EAAA;AACnB,EAAA,IAAI,MAAA,CAAO,SAAS,WAAA,EAAa;AAC/B,IAAA,YAAA,GAAe,IAAI,GAAA,CAAI,MAAA,CAAO,OAAO,CAAA,CAAE,QAAA;AAAA,EACzC;AACA,EAAA,OAAO,OAAA,CAAQ,cAAc,GAAG,CAAA;AAClC;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.cjs.js","sources":["../../src/gitlab/core.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 {\n getGitLabIntegrationRelativePath,\n GitLabIntegrationConfig,\n} from './config';\n\n/**\n * Given a URL pointing to a file on a provider, returns a URL that is suitable\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://gitlab.example.com/a/b/blob/master/c.yaml\n * to: https://gitlab.com/api/v4/projects/a%2Fb/repository/files/c.yaml/raw?ref=master\n * -or-\n * from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n * to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FteamA%2FsubgroupA%2FrepoA/repository/files/filepath/raw?ref=branch\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @param token - An optional auth token (not used in path extraction, kept for compatibility)\n * @public\n */\nexport function getGitLabFileFetchUrl(\n url: string,\n config: GitLabIntegrationConfig,\n _token?: string,\n): Promise<string> {\n // Use project path directly instead of making an API call to get project ID\n // Note: _token parameter kept for backward compatibility but not used for path extraction\n const projectPath = extractProjectPath(url, config);\n return Promise.resolve(buildProjectUrl(url, projectPath, config).toString());\n}\n\n/**\n * Gets the request options necessary to make requests to a given provider.\n *\n * @param config - The relevant provider config\n * @param token - An optional auth token to use for communicating with GitLab. By default uses the integration token\n * @public\n */\nexport function getGitLabRequestOptions(\n config: GitLabIntegrationConfig,\n token?: string,\n): { headers: Record<string, string> } {\n const headers: Record<string, string> = {};\n\n const accessToken = token || config.token;\n if (accessToken) {\n // OAuth, Personal, Project, and Group access tokens can all be passed via\n // a bearer authorization header\n // https://docs.gitlab.com/api/rest/authentication/#personalprojectgroup-access-tokens\n headers.Authorization = `Bearer ${accessToken}`;\n }\n\n return { headers };\n}\n\n// Converts\n// from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n// to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FteamA%2FsubgroupA%2FrepoA/repository/files/filepath/raw?ref=branch\nfunction buildProjectUrl(\n target: string,\n projectPathOrID: string | Number,\n config: GitLabIntegrationConfig,\n): URL {\n try {\n const url = new URL(target);\n\n const branchAndFilePath = url.pathname\n .split('/blob/')\n .slice(1)\n .join('/blob/');\n const [branch, ...filePath] = branchAndFilePath.split('/');\n const relativePath = getGitLabIntegrationRelativePath(config);\n\n const projectIdentifier = encodeURIComponent(String(projectPathOrID));\n\n url.pathname = [\n ...(relativePath ? [relativePath] : []),\n 'api/v4/projects',\n projectIdentifier,\n 'repository/files',\n encodeURIComponent(decodeURIComponent(filePath.join('/'))),\n 'raw',\n ].join('/');\n\n url.search = new URLSearchParams({\n ref: decodeURIComponent(branch),\n }).toString();\n\n return url;\n } catch (e) {\n throw new Error(`Incorrect url: ${target}, ${e}`);\n }\n}\n\n/**\n * Extracts the project path from a GitLab URL\n * from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n * to: groupA/teams/teamA/subgroupA/repoA\n */\nexport function extractProjectPath(\n target: string,\n config: GitLabIntegrationConfig,\n): string {\n const url = new URL(target);\n\n if (!url.pathname.includes('/blob/')) {\n throw new Error(\n `Failed extracting project path from ${url.pathname}. Url path must include /blob/.`,\n );\n }\n\n let repo = url.pathname.split('/-/blob/')[0].split('/blob/')[0];\n\n // Get gitlab relative path\n const relativePath = getGitLabIntegrationRelativePath(config);\n\n // Check relative path exists and remove it if it's the case.\n if (relativePath) {\n if (!repo.startsWith(`${relativePath}/`)) {\n throw new Error(\n `Failed extracting project path from ${url.pathname}. Url path must start with ${relativePath}/.`,\n );\n }\n repo = repo.slice(relativePath.length);\n }\n\n // Remove leading slash\n return repo.replace(/^\\//, '');\n}\n"],"names":["config","getGitLabIntegrationRelativePath"],"mappings":";;;;AAuCO,SAAS,qBAAA,CACd,GAAA,EACA,MAAA,EACA,MAAA,EACiB;AAGjB,EAAA,MAAM,WAAA,GAAc,kBAAA,CAAmB,GAAA,EAAK,MAAM,CAAA;AAClD,EA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,MAAM;AAAA,KAC/B,EAAE,QAAA,EAAS;AAEZ,IAAA,OAAO,GAAA;AAAA,EACT,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,eAAA,EAAkB,MAAM,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EAClD;AACF;AAOO,SAAS,kBAAA,CACd,QACAA,QAAA,EACQ;AACR,EAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,MAAM,CAAA;AAE1B,EAAA,IAAI,CAAC,GAAA,CAAI,QAAA,CAAS,QAAA,CAAS,QAAQ,CAAA,EAAG;AACpC,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,oCAAA,EAAuC,IAAI,QAAQ,CAAA,+BAAA;AAAA,KACrD;AAAA,EACF;AAEA,EAAA,IAAI,IAAA,GAAO,GAAA,CAAI,QAAA,CAAS,KAAA,CAAM,UAAU,CAAA,CAAE,CAAC,CAAA,CAAE,KAAA,CAAM,QAAQ,CAAA,CAAE,CAAC,CAAA;AAG9D,EAAA,MAAM,YAAA,GAAeC,wCAAiCD,QAAM,CAAA;AAG5D,EAAA,IAAI,YAAA,EAAc;AAChB,IAAA,IAAI,CAAC,IAAA,CAAK,UAAA,CAAW,CAAA,EAAG,YAAY,GAAG,CAAA,EAAG;AACxC,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,oCAAA,EAAuC,GAAA,CAAI,QAAQ,CAAA,2BAAA,EAA8B,YAAY,CAAA,EAAA;AAAA,OAC/F;AAAA,IACF;AACA,IAAA,IAAA,GAAO,IAAA,CAAK,KAAA,CAAM,YAAA,CAAa,MAAM,CAAA;AAAA,EACvC;AAGA,EAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AAC/B
|
|
1
|
+
{"version":3,"file":"core.cjs.js","sources":["../../src/gitlab/core.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 {\n getGitLabIntegrationRelativePath,\n GitLabIntegrationConfig,\n} from './config';\n\n/**\n * Given a URL pointing to a file on a provider, returns a URL that is suitable\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://gitlab.example.com/a/b/blob/master/c.yaml\n * to: https://gitlab.com/api/v4/projects/a%2Fb/repository/files/c.yaml/raw?ref=master\n * -or-\n * from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n * to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FteamA%2FsubgroupA%2FrepoA/repository/files/filepath/raw?ref=branch\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @param token - An optional auth token (not used in path extraction, kept for compatibility)\n * @public\n */\nexport function getGitLabFileFetchUrl(\n url: string,\n config: GitLabIntegrationConfig,\n _token?: string,\n): Promise<string> {\n // Use project path directly instead of making an API call to get project ID\n // Note: _token parameter kept for backward compatibility but not used for path extraction\n const projectPath = extractProjectPath(url, config);\n return Promise.resolve(buildProjectUrl(url, projectPath, config).toString());\n}\n\n/**\n * Gets the request options necessary to make requests to a given provider.\n *\n * @param config - The relevant provider config\n * @param token - An optional auth token to use for communicating with GitLab. By default uses the integration token\n * @public\n */\nexport function getGitLabRequestOptions(\n config: GitLabIntegrationConfig,\n token?: string,\n): { headers: Record<string, string> } {\n const headers: Record<string, string> = {};\n\n const accessToken = token || config.token;\n if (accessToken) {\n // OAuth, Personal, Project, and Group access tokens can all be passed via\n // a bearer authorization header\n // https://docs.gitlab.com/api/rest/authentication/#personalprojectgroup-access-tokens\n headers.Authorization = `Bearer ${accessToken}`;\n }\n\n return { headers };\n}\n\n// Converts\n// from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n// to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FteamA%2FsubgroupA%2FrepoA/repository/files/filepath/raw?ref=branch\nfunction buildProjectUrl(\n target: string,\n projectPathOrID: string | Number,\n config: GitLabIntegrationConfig,\n): URL {\n try {\n const url = new URL(target);\n\n const branchAndFilePath = url.pathname\n .split('/blob/')\n .slice(1)\n .join('/blob/');\n const [branch, ...filePath] = branchAndFilePath.split('/');\n const relativePath = getGitLabIntegrationRelativePath(config);\n\n const projectIdentifier = encodeURIComponent(String(projectPathOrID));\n\n url.pathname = [\n ...(relativePath ? [relativePath] : []),\n 'api/v4/projects',\n projectIdentifier,\n 'repository/files',\n encodeURIComponent(decodeURIComponent(filePath.join('/'))),\n 'raw',\n ].join('/');\n\n url.search = new URLSearchParams({\n ref: decodeURIComponent(branch),\n }).toString();\n\n return url;\n } catch (e) {\n throw new Error(`Incorrect url: ${target}, ${e}`);\n }\n}\n\n/**\n * Extracts the project path from a GitLab URL\n * from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n * to: groupA/teams/teamA/subgroupA/repoA\n */\nexport function extractProjectPath(\n target: string,\n config: GitLabIntegrationConfig,\n): string {\n const url = new URL(target);\n\n if (!url.pathname.includes('/blob/')) {\n throw new Error(\n `Failed extracting project path from ${url.pathname}. Url path must include /blob/.`,\n );\n }\n\n let repo = url.pathname.split('/-/blob/')[0].split('/blob/')[0];\n\n // Get gitlab relative path\n const relativePath = getGitLabIntegrationRelativePath(config);\n\n // Check relative path exists and remove it if it's the case.\n if (relativePath) {\n if (!repo.startsWith(`${relativePath}/`)) {\n throw new Error(\n `Failed extracting project path from ${url.pathname}. Url path must start with ${relativePath}/.`,\n );\n }\n repo = repo.slice(relativePath.length);\n }\n\n // Remove leading slash\n return repo.replace(/^\\//, '');\n}\n"],"names":["config","getG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AA,CAAK,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AAC/B;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.esm.js","sources":["../../src/gitlab/core.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 {\n getGitLabIntegrationRelativePath,\n GitLabIntegrationConfig,\n} from './config';\n\n/**\n * Given a URL pointing to a file on a provider, returns a URL that is suitable\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://gitlab.example.com/a/b/blob/master/c.yaml\n * to: https://gitlab.com/api/v4/projects/a%2Fb/repository/files/c.yaml/raw?ref=master\n * -or-\n * from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n * to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FteamA%2FsubgroupA%2FrepoA/repository/files/filepath/raw?ref=branch\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @param token - An optional auth token (not used in path extraction, kept for compatibility)\n * @public\n */\nexport function getGitLabFileFetchUrl(\n url: string,\n config: GitLabIntegrationConfig,\n _token?: string,\n): Promise<string> {\n // Use project path directly instead of making an API call to get project ID\n // Note: _token parameter kept for backward compatibility but not used for path extraction\n const projectPath = extractProjectPath(url, config);\n return Promise.resolve(buildProjectUrl(url, projectPath, config).toString());\n}\n\n/**\n * Gets the request options necessary to make requests to a given provider.\n *\n * @param config - The relevant provider config\n * @param token - An optional auth token to use for communicating with GitLab. By default uses the integration token\n * @public\n */\nexport function getGitLabRequestOptions(\n config: GitLabIntegrationConfig,\n token?: string,\n): { headers: Record<string, string> } {\n const headers: Record<string, string> = {};\n\n const accessToken = token || config.token;\n if (accessToken) {\n // OAuth, Personal, Project, and Group access tokens can all be passed via\n // a bearer authorization header\n // https://docs.gitlab.com/api/rest/authentication/#personalprojectgroup-access-tokens\n headers.Authorization = `Bearer ${accessToken}`;\n }\n\n return { headers };\n}\n\n// Converts\n// from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n// to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FteamA%2FsubgroupA%2FrepoA/repository/files/filepath/raw?ref=branch\nfunction buildProjectUrl(\n target: string,\n projectPathOrID: string | Number,\n config: GitLabIntegrationConfig,\n): URL {\n try {\n const url = new URL(target);\n\n const branchAndFilePath = url.pathname\n .split('/blob/')\n .slice(1)\n .join('/blob/');\n const [branch, ...filePath] = branchAndFilePath.split('/');\n const relativePath = getGitLabIntegrationRelativePath(config);\n\n const projectIdentifier = encodeURIComponent(String(projectPathOrID));\n\n url.pathname = [\n ...(relativePath ? [relativePath] : []),\n 'api/v4/projects',\n projectIdentifier,\n 'repository/files',\n encodeURIComponent(decodeURIComponent(filePath.join('/'))),\n 'raw',\n ].join('/');\n\n url.search = new URLSearchParams({\n ref: decodeURIComponent(branch),\n }).toString();\n\n return url;\n } catch (e) {\n throw new Error(`Incorrect url: ${target}, ${e}`);\n }\n}\n\n/**\n * Extracts the project path from a GitLab URL\n * from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n * to: groupA/teams/teamA/subgroupA/repoA\n */\nexport function extractProjectPath(\n target: string,\n config: GitLabIntegrationConfig,\n): string {\n const url = new URL(target);\n\n if (!url.pathname.includes('/blob/')) {\n throw new Error(\n `Failed extracting project path from ${url.pathname}. Url path must include /blob/.`,\n );\n }\n\n let repo = url.pathname.split('/-/blob/')[0].split('/blob/')[0];\n\n // Get gitlab relative path\n const relativePath = getGitLabIntegrationRelativePath(config);\n\n // Check relative path exists and remove it if it's the case.\n if (relativePath) {\n if (!repo.startsWith(`${relativePath}/`)) {\n throw new Error(\n `Failed extracting project path from ${url.pathname}. Url path must start with ${relativePath}/.`,\n );\n }\n repo = repo.slice(relativePath.length);\n }\n\n // Remove leading slash\n return repo.replace(/^\\//, '');\n}\n"],"names":[],"mappings":";;AAuCO,SAAS,qBAAA,CACd,GAAA,EACA,MAAA,EACA,MAAA,EACiB;AAGjB,EAAA,MAAM,WAAA,GAAc,kBAAA,CAAmB,GAAA,EAAK,MAAM,CAAA;AAClD,EAAA,OAAO,OAAA,CAAQ,QAAQ,eAAA,CAAgB,GAAA,EAAK,aAAa,MAAM,CAAA,CAAE,UAAU,CAAA;AAC7E;AASO,SAAS,uBAAA,CACd,QACA,KAAA,EACqC;AACrC,EAAA,MAAM,UAAkC,EAAC;AAEzC,EAAA,MAAM,WAAA,GAAc,SAAS,MAAA,CAAO,KAAA;AACpC,EAAA,IAAI,WAAA,EAAa;AAIf,IAAA,OAAA,CAAQ,aAAA,GAAgB,UAAU,WAAW,CAAA,CAAA;AAAA,EAC/C;AAEA,EAAA,OAAO,EAAE,OAAA,EAAQ;AACnB;AAKA,SAAS,eAAA,CACP,MAAA,EACA,eAAA,EACA,MAAA,EACK;AACL,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,MAAM,CAAA;AAE1B,IAAA,MAAM,iBAAA,GAAoB,GAAA,CAAI,QAAA,CAC3B,KAAA,CAAM,QAAQ,EACd,KAAA,CAAM,CAAC,CAAA,CACP,IAAA,CAAK,QAAQ,CAAA;AAChB,IAAA,MAAM,CAAC,MAAA,EAAQ,GAAG,QAAQ,CAAA,GAAI,iBAAA,CAAkB,MAAM,GAAG,CAAA;AACzD,IAAA,MAAM,YAAA,GAAe,iCAAiC,MAAM,CAAA;AAE5D,IAAA,MAAM,iBAAA,GAAoB,kBAAA,CAAmB,MAAA,CAAO,eAAe,CAAC,CAAA;AAEpE,IAAA,GAAA,CAAI,QAAA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A,2BAAA,EAA8B,YAAY,CAAA,EAAA;AAAA,OAC/F;AAAA,IACF;AACA,IAAA,IAAA,GAAO,IAAA,CAAK,KAAA,CAAM,YAAA,CAAa,MAAM,CAAA;AAAA,EACvC;AAGA,EAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AAC/B
|
|
1
|
+
{"version":3,"file":"core.esm.js","sources":["../../src/gitlab/core.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 {\n getGitLabIntegrationRelativePath,\n GitLabIntegrationConfig,\n} from './config';\n\n/**\n * Given a URL pointing to a file on a provider, returns a URL that is suitable\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://gitlab.example.com/a/b/blob/master/c.yaml\n * to: https://gitlab.com/api/v4/projects/a%2Fb/repository/files/c.yaml/raw?ref=master\n * -or-\n * from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n * to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FteamA%2FsubgroupA%2FrepoA/repository/files/filepath/raw?ref=branch\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @param token - An optional auth token (not used in path extraction, kept for compatibility)\n * @public\n */\nexport function getGitLabFileFetchUrl(\n url: string,\n config: GitLabIntegrationConfig,\n _token?: string,\n): Promise<string> {\n // Use project path directly instead of making an API call to get project ID\n // Note: _token parameter kept for backward compatibility but not used for path extraction\n const projectPath = extractProjectPath(url, config);\n return Promise.resolve(buildProjectUrl(url, projectPath, config).toString());\n}\n\n/**\n * Gets the request options necessary to make requests to a given provider.\n *\n * @param config - The relevant provider config\n * @param token - An optional auth token to use for communicating with GitLab. By default uses the integration token\n * @public\n */\nexport function getGitLabRequestOptions(\n config: GitLabIntegrationConfig,\n token?: string,\n): { headers: Record<string, string> } {\n const headers: Record<string, string> = {};\n\n const accessToken = token || config.token;\n if (accessToken) {\n // OAuth, Personal, Project, and Group access tokens can all be passed via\n // a bearer authorization header\n // https://docs.gitlab.com/api/rest/authentication/#personalprojectgroup-access-tokens\n headers.Authorization = `Bearer ${accessToken}`;\n }\n\n return { headers };\n}\n\n// Converts\n// from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n// to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FteamA%2FsubgroupA%2FrepoA/repository/files/filepath/raw?ref=branch\nfunction buildProjectUrl(\n target: string,\n projectPathOrID: string | Number,\n config: GitLabIntegrationConfig,\n): URL {\n try {\n const url = new URL(target);\n\n const branchAndFilePath = url.pathname\n .split('/blob/')\n .slice(1)\n .join('/blob/');\n const [branch, ...filePath] = branchAndFilePath.split('/');\n const relativePath = getGitLabIntegrationRelativePath(config);\n\n const projectIdentifier = encodeURIComponent(String(projectPathOrID));\n\n url.pathname = [\n ...(relativePath ? [relativePath] : []),\n 'api/v4/projects',\n projectIdentifier,\n 'repository/files',\n encodeURIComponent(decodeURIComponent(filePath.join('/'))),\n 'raw',\n ].join('/');\n\n url.search = new URLSearchParams({\n ref: decodeURIComponent(branch),\n }).toString();\n\n return url;\n } catch (e) {\n throw new Error(`Incorrect url: ${target}, ${e}`);\n }\n}\n\n/**\n * Extracts the project path from a GitLab URL\n * from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n * to: groupA/teams/teamA/subgroupA/repoA\n */\nexport function extractProjectPath(\n target: string,\n config: GitLabIntegrationConfig,\n): string {\n const url = new URL(target);\n\n if (!url.pathname.includes('/blob/')) {\n throw new Error(\n `Failed extracting project path from ${url.pathname}. Url path must include /blob/.`,\n );\n }\n\n let repo = url.pathname.split('/-/blob/')[0].split('/blob/')[0];\n\n // Get gitlab relative path\n const relativePath = getGitLabIntegrationRelativePath(config);\n\n // Check relative path exists and remove it if it's the case.\n if (relativePath) {\n if (!repo.startsWith(`${relativePath}/`)) {\n throw new Error(\n `Failed extracting project path from ${url.pathname}. Url path must start with ${relativePath}/.`,\n );\n }\n repo = repo.slice(relativePath.length);\n }\n\n // Remove leading slash\n return repo.replace(/^\\//, '');\n}\n"],"names":[],"mappings":";;AAuCO,SAAS,qBAAA,CACd,GAAA,EACA,MAAA,EACA,MAAA,EACiB;AAGjB,EAAA,MAAM,WAAA,GAAc,kBAAA,CAAmB,GAAA,EAAK,MAAM,CAAA;AAClD,EAAA,OAAO,OAAA,CAAQ,QAAQ,eAAA,CAAgB,GAAA,EAAK,aAAa,MAAM,CAAA,CAAE,UAAU,CAAA;AAC7E;AASO,SAAS,uBAAA,CACd,QACA,KAAA,EACqC;AACrC,EAAA,MAAM,UAAkC,EAAC;AAEzC,EAAA,MAAM,WAAA,GAAc,SAAS,MAAA,CAAO,KAAA;AACpC,EAAA,IAAI,WAAA,EAAa;AAIf,IAAA,OAAA,CAAQ,aAAA,GAAgB,UAAU,WAAW,CAAA,CAAA;AAAA,EAC/C;AAEA,EAAA,OAAO,EAAE,OAAA,EAAQ;AACnB;AAKA,SAAS,eAAA,CACP,MAAA,EACA,eAAA,EACA,MAAA,EACK;AACL,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,MAAM,CAAA;AAE1B,IAAA,MAAM,iBAAA,GAAoB,GAAA,CAAI,QAAA,CAC3B,KAAA,CAAM,QAAQ,EACd,KAAA,CAAM,CAAC,CAAA,CACP,IAAA,CAAK,QAAQ,CAAA;AAChB,IAAA,MAAM,CAAC,MAAA,EAAQ,GAAG,QAAQ,CAAA,GAAI,iBAAA,CAAkB,MAAM,GAAG,CAAA;AACzD,IAAA,MAAM,YAAA,G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,UAAA,CAAW,CAAA,EAAG,YAAY,GAAG,CAAA,EAAG;AACxC,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,oCAAA,EAAuC,GAAA,CAAI,QAAQ,CAAA,2BAAA,EAA8B,YAAY,CAAA,EAAA;AAAA,OAC/F;AAAA,IACF;AACA,IAAA,IAAA,GAAO,IAAA,CAAK,KAAA,CAAM,YAAA,CAAa,MAAM,CAAA;AAAA,EACvC;AAGA,EAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AAC/B;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GoogleGcsIntegration.cjs.js","sources":["../../src/googleGcs/GoogleGcsIntegration.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 GoogleGcsIntegrationConfig,\n readGoogleGcsIntegrationConfig,\n GOOGLE_GCS_HOST,\n} from './config';\n\n/**\n * A Google Cloud Storage based integration.\n *\n * @public\n */\nexport class GoogleGcsIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<GoogleGcsIntegration> = ({\n config,\n }) => {\n const gcsConfig = config.has('integrations.googleGcs')\n ? readGoogleGcsIntegrationConfig(\n config.getConfig('integrations.googleGcs'),\n )\n : { host: GOOGLE_GCS_HOST };\n\n return basicIntegrations(\n [new GoogleGcsIntegration(gcsConfig)],\n i => i.config.host,\n );\n };\n\n get type(): string {\n return 'googleGcs';\n }\n\n get title(): string {\n return this.integrationConfig.host;\n }\n\n get config(): GoogleGcsIntegrationConfig {\n return this.integrationConfig;\n }\n\n constructor(private readonly integrationConfig: GoogleGcsIntegrationConfig) {}\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number | undefined;\n }): string {\n return defaultScmResolveUrl(options);\n }\n\n resolveEditUrl(url: string): string {\n return url;\n }\n}\n"],"names":["config","readGoogleGcsIntegrationConfig","GOOGLE_GCS_HOST","basicIntegrations","defaultScmResolveUrl"],"mappings":";;;;;AA6BO,MAAM,oBAAA,CAA+C;AAAA,EA4B1D,YAA6B,iBAAA,EAA+C;AAA/C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAAA,EAAgD;AAAA,
|
|
1
|
+
{"version":3,"file":"GoogleGcsIntegration.cjs.js","sources":["../../src/googleGcs/GoogleGcsIntegration.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 GoogleGcsIntegrationConfig,\n readGoogleGcsIntegrationConfig,\n GOOGLE_GCS_HOST,\n} from './config';\n\n/**\n * A Google Cloud Storage based integration.\n *\n * @public\n */\nexport class GoogleGcsIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<GoogleGcsIntegration> = ({\n config,\n }) => {\n const gcsConfig = config.has('integrations.googleGcs')\n ? readGoogleGcsIntegrationConfig(\n config.getConfig('integrations.googleGcs'),\n )\n : { host: GOOGLE_GCS_HOST };\n\n return basicIntegrations(\n [new GoogleGcsIntegration(gcsConfig)],\n i => i.config.host,\n );\n };\n\n get type(): string {\n return 'googleGcs';\n }\n\n get title(): string {\n return this.integrationConfig.host;\n }\n\n get config(): GoogleGcsIntegrationConfig {\n return this.integrationConfig;\n }\n\n constructor(private readonly integrationConfig: GoogleGcsIntegrationConfig) {}\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number | undefined;\n }): string {\n return defaultScmResolveUrl(options);\n }\n\n resolveEditUrl(url: string): string {\n return url;\n }\n}\n"],"names":["config","readGoogleGcsIntegrationConfig","GOOGLE_GCS_HOST","basicIntegrations","defaultScmResolveUrl"],"mappings":";;;;;AA6BO,MAAM,oBAAA,CAA+C;AAAA,EA4B1D,YAA6B,iBAAA,EAA+C;AAA/C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAAA,EAAgD;AAAA,EAAhD,iBAAA;AAAA,EA3B7B,OAAO,UAAwD,CAAC;AAAA,YAC9DA;AAAA,GACF,KAAM;AACJ,IAAA,MAAM,SAAA,GAAYA,QAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA,GACjDC,qCAAA;AAAA,MACED,QAAA,CAAO,UAAU,wBAAwB;AAAA,KAC3C,GACA,EAAE,IAAA,EAAME,sBAAA,EAAgB;AAE5B,IAAA,OAAOC,yBAAA;AAAA,MACL,CAAC,IAAI,oBAAA,CAAqB,SAAS,CAAC,CAAA;AAAA,MACpC,CAAA,CAAA,KAAK,EAAE,MAAA,CAAO;AAAA,KAChB;AAAA,EACF,CAAA;AAAA,EAEA,IAAI,IAAA,GAAe;AACjB,IAAA,OAAO,WAAA;AAAA,EACT;AAAA,EAEA,IAAI,KAAA,GAAgB;AAClB,IAAA,OAAO,KAAK,iBAAA,CAAkB,IAAA;AAAA,EAChC;AAAA,EAEA,IAAI,MAAA,GAAqC;AACvC,IAAA,OAAO,IAAA,CAAK,iBAAA;AAAA,EACd;AAAA,EAIA,WAAW,OAAA,EAIA;AACT,IAAA,OAAOC,6BAAqB,OAAO,CAAA;AAAA,EACrC;AAAA,EAEA,eAAe,GAAA,EAAqB;AAClC,IAAA,OAAO,GAAA;AAAA,EACT;AACF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GoogleGcsIntegration.esm.js","sources":["../../src/googleGcs/GoogleGcsIntegration.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 GoogleGcsIntegrationConfig,\n readGoogleGcsIntegrationConfig,\n GOOGLE_GCS_HOST,\n} from './config';\n\n/**\n * A Google Cloud Storage based integration.\n *\n * @public\n */\nexport class GoogleGcsIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<GoogleGcsIntegration> = ({\n config,\n }) => {\n const gcsConfig = config.has('integrations.googleGcs')\n ? readGoogleGcsIntegrationConfig(\n config.getConfig('integrations.googleGcs'),\n )\n : { host: GOOGLE_GCS_HOST };\n\n return basicIntegrations(\n [new GoogleGcsIntegration(gcsConfig)],\n i => i.config.host,\n );\n };\n\n get type(): string {\n return 'googleGcs';\n }\n\n get title(): string {\n return this.integrationConfig.host;\n }\n\n get config(): GoogleGcsIntegrationConfig {\n return this.integrationConfig;\n }\n\n constructor(private readonly integrationConfig: GoogleGcsIntegrationConfig) {}\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number | undefined;\n }): string {\n return defaultScmResolveUrl(options);\n }\n\n resolveEditUrl(url: string): string {\n return url;\n }\n}\n"],"names":[],"mappings":";;;AA6BO,MAAM,oBAAA,CAA+C;AAAA,EA4B1D,YAA6B,iBAAA,EAA+C;AAA/C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAAA,EAAgD;AAAA,
|
|
1
|
+
{"version":3,"file":"GoogleGcsIntegration.esm.js","sources":["../../src/googleGcs/GoogleGcsIntegration.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 GoogleGcsIntegrationConfig,\n readGoogleGcsIntegrationConfig,\n GOOGLE_GCS_HOST,\n} from './config';\n\n/**\n * A Google Cloud Storage based integration.\n *\n * @public\n */\nexport class GoogleGcsIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<GoogleGcsIntegration> = ({\n config,\n }) => {\n const gcsConfig = config.has('integrations.googleGcs')\n ? readGoogleGcsIntegrationConfig(\n config.getConfig('integrations.googleGcs'),\n )\n : { host: GOOGLE_GCS_HOST };\n\n return basicIntegrations(\n [new GoogleGcsIntegration(gcsConfig)],\n i => i.config.host,\n );\n };\n\n get type(): string {\n return 'googleGcs';\n }\n\n get title(): string {\n return this.integrationConfig.host;\n }\n\n get config(): GoogleGcsIntegrationConfig {\n return this.integrationConfig;\n }\n\n constructor(private readonly integrationConfig: GoogleGcsIntegrationConfig) {}\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number | undefined;\n }): string {\n return defaultScmResolveUrl(options);\n }\n\n resolveEditUrl(url: string): string {\n return url;\n }\n}\n"],"names":[],"mappings":";;;AA6BO,MAAM,oBAAA,CAA+C;AAAA,EA4B1D,YAA6B,iBAAA,EAA+C;AAA/C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAAA,EAAgD;AAAA,EAAhD,iBAAA;AAAA,EA3B7B,OAAO,UAAwD,CAAC;AAAA,IAC9D;AAAA,GACF,KAAM;AACJ,IAAA,MAAM,SAAA,GAAY,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA,GACjD,8BAAA;AAAA,MACE,MAAA,CAAO,UAAU,wBAAwB;AAAA,KAC3C,GACA,EAAE,IAAA,EAAM,eAAA,EAAgB;AAE5B,IAAA,OAAO,iBAAA;AAAA,MACL,CAAC,IAAI,oBAAA,CAAqB,SAAS,CAAC,CAAA;AAAA,MACpC,CAAA,CAAA,KAAK,EAAE,MAAA,CAAO;AAAA,KAChB;AAAA,EACF,CAAA;AAAA,EAEA,IAAI,IAAA,GAAe;AACjB,IAAA,OAAO,WAAA;AAAA,EACT;AAAA,EAEA,IAAI,KAAA,GAAgB;AAClB,IAAA,OAAO,KAAK,iBAAA,CAAkB,IAAA;AAAA,EAChC;AAAA,EAEA,IAAI,MAAA,GAAqC;AACvC,IAAA,OAAO,IAAA,CAAK,iBAAA;AAAA,EACd;AAAA,EAIA,WAAW,OAAA,EAIA;AACT,IAAA,OAAO,qBAAqB,OAAO,CAAA;AAAA,EACrC;AAAA,EAEA,eAAe,GAAA,EAAqB;AAClC,IAAA,OAAO,GAAA;AAAA,EACT;AACF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.cjs.js","sources":["../../src/googleGcs/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';\n\n/**\n * The default Google Cloud Storage host.\n *\n */\nexport const GOOGLE_GCS_HOST = 'storage.cloud.google.com';\n\n/**\n * The configuration parameters for a single Google Cloud Storage provider.\n *\n * @public\n */\nexport type GoogleGcsIntegrationConfig = {\n /**\n * The host of the target that this matches on.\n */\n host: string;\n /**\n * Service account email used to authenticate requests.\n */\n clientEmail?: string;\n /**\n * Service account private key used to authenticate requests.\n */\n privateKey?: string;\n};\n\n/**\n * Reads a single Google GCS integration config.\n *\n * @param config - The config object of a single integration\n * @public\n */\nexport function readGoogleGcsIntegrationConfig(\n config: Config,\n): GoogleGcsIntegrationConfig {\n if (!config) {\n return { host: GOOGLE_GCS_HOST };\n }\n\n if (!config.has('clientEmail') && !config.has('privateKey')) {\n return { host: GOOGLE_GCS_HOST };\n }\n\n const privateKey = config.getString('privateKey').split('\\\\n').join('\\n');\n const clientEmail = config.getString('clientEmail');\n\n return {\n host: GOOGLE_GCS_HOST,\n clientEmail,\n privateKey,\n };\n}\n"],"names":[],"mappings":";;AAsBO,MAAM,eAAA,GAAkB;AA4BxB,SAAS,+BACd,MAAA,EAC4B;AAC5B,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,OAAO,EAAE,MAAM,eAAA,EAAgB;AAAA,EACjC;AAEA,EAAA,IAAI,CAAC,OAAO,GAAA,CAAI,aAAa,KAAK,CAAC,MAAA,CAAO,GAAA,CAAI,YAAY,CAAA,EAAG;AAC3D,IAAA,OAAO,EAAE,MAAM,eAAA,EAAgB;AAAA,EACjC;AAEA,EAAA,MAAM,UAAA,GAAa,OAAO,SAAA,CAAU,YAAY,EAAE,KAAA,CAAM,KAAK,CAAA,CAAE,IAAA,CAAK,IAAI,CAAA;AACxE,EAAA,MAAM,WAAA,GAAc,MAAA,CAAO,SAAA,CAAU,aAAa,CAAA;AAElD,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,eAAA;AAAA,IACN,WAAA;AAAA,IACA;AAAA,GACF;AACF
|
|
1
|
+
{"version":3,"file":"config.cjs.js","sources":["../../src/googleGcs/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';\n\n/**\n * The default Google Cloud Storage host.\n *\n */\nexport const GOOGLE_GCS_HOST = 'storage.cloud.google.com';\n\n/**\n * The configuration parameters for a single Google Cloud Storage provider.\n *\n * @public\n */\nexport type GoogleGcsIntegrationConfig = {\n /**\n * The host of the target that this matches on.\n */\n host: string;\n /**\n * Service account email used to authenticate requests.\n */\n clientEmail?: string;\n /**\n * Service account private key used to authenticate requests.\n */\n privateKey?: string;\n};\n\n/**\n * Reads a single Google GCS integration config.\n *\n * @param config - The config object of a single integration\n * @public\n */\nexport function readGoogleGcsIntegrationConfig(\n config: Config,\n): GoogleGcsIntegrationConfig {\n if (!config) {\n return { host: GOOGLE_GCS_HOST };\n }\n\n if (!config.has('clientEmail') && !config.has('privateKey')) {\n return { host: GOOGLE_GCS_HOST };\n }\n\n const privateKey = config.getString('privateKey').split('\\\\n').join('\\n');\n const clientEmail = config.getString('clientEmail');\n\n return {\n host: GOOGLE_GCS_HOST,\n clientEmail,\n privateKey,\n };\n}\n"],"names":[],"mappings":";;AAsBO,MAAM,eAAA,GAAkB;AA4BxB,SAAS,+BACd,MAAA,EAC4B;AAC5B,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,OAAO,EAAE,MAAM,eAAA,EAAgB;AAAA,EACjC;AAEA,EAAA,IAAI,CAAC,OAAO,GAAA,CAAI,aAAa,KAAK,CAAC,MAAA,CAAO,GAAA,CAAI,YAAY,CAAA,EAAG;AAC3D,IAAA,OAAO,EAAE,MAAM,eAAA,EAAgB;AAAA,EACjC;AAEA,EAAA,MAAM,UAAA,GAAa,OAAO,SAAA,CAAU,YAAY,EAAE,KAAA,CAAM,KAAK,CAAA,CAAE,IAAA,CAAK,IAAI,CAAA;AACxE,EAAA,MAAM,WAAA,GAAc,MAAA,CAAO,SAAA,CAAU,aAAa,CAAA;AAElD,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,eAAA;AAAA,IACN,WAAA;AAAA,IACA;AAAA,GACF;AACF;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.esm.js","sources":["../../src/googleGcs/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';\n\n/**\n * The default Google Cloud Storage host.\n *\n */\nexport const GOOGLE_GCS_HOST = 'storage.cloud.google.com';\n\n/**\n * The configuration parameters for a single Google Cloud Storage provider.\n *\n * @public\n */\nexport type GoogleGcsIntegrationConfig = {\n /**\n * The host of the target that this matches on.\n */\n host: string;\n /**\n * Service account email used to authenticate requests.\n */\n clientEmail?: string;\n /**\n * Service account private key used to authenticate requests.\n */\n privateKey?: string;\n};\n\n/**\n * Reads a single Google GCS integration config.\n *\n * @param config - The config object of a single integration\n * @public\n */\nexport function readGoogleGcsIntegrationConfig(\n config: Config,\n): GoogleGcsIntegrationConfig {\n if (!config) {\n return { host: GOOGLE_GCS_HOST };\n }\n\n if (!config.has('clientEmail') && !config.has('privateKey')) {\n return { host: GOOGLE_GCS_HOST };\n }\n\n const privateKey = config.getString('privateKey').split('\\\\n').join('\\n');\n const clientEmail = config.getString('clientEmail');\n\n return {\n host: GOOGLE_GCS_HOST,\n clientEmail,\n privateKey,\n };\n}\n"],"names":[],"mappings":"AAsBO,MAAM,eAAA,GAAkB;AA4BxB,SAAS,+BACd,MAAA,EAC4B;AAC5B,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,OAAO,EAAE,MAAM,eAAA,EAAgB;AAAA,EACjC;AAEA,EAAA,IAAI,CAAC,OAAO,GAAA,CAAI,aAAa,KAAK,CAAC,MAAA,CAAO,GAAA,CAAI,YAAY,CAAA,EAAG;AAC3D,IAAA,OAAO,EAAE,MAAM,eAAA,EAAgB;AAAA,EACjC;AAEA,EAAA,MAAM,UAAA,GAAa,OAAO,SAAA,CAAU,YAAY,EAAE,KAAA,CAAM,KAAK,CAAA,CAAE,IAAA,CAAK,IAAI,CAAA;AACxE,EAAA,MAAM,WAAA,GAAc,MAAA,CAAO,SAAA,CAAU,aAAa,CAAA;AAElD,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,eAAA;AAAA,IACN,WAAA;AAAA,IACA;AAAA,GACF;AACF
|
|
1
|
+
{"version":3,"file":"config.esm.js","sources":["../../src/googleGcs/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';\n\n/**\n * The default Google Cloud Storage host.\n *\n */\nexport const GOOGLE_GCS_HOST = 'storage.cloud.google.com';\n\n/**\n * The configuration parameters for a single Google Cloud Storage provider.\n *\n * @public\n */\nexport type GoogleGcsIntegrationConfig = {\n /**\n * The host of the target that this matches on.\n */\n host: string;\n /**\n * Service account email used to authenticate requests.\n */\n clientEmail?: string;\n /**\n * Service account private key used to authenticate requests.\n */\n privateKey?: string;\n};\n\n/**\n * Reads a single Google GCS integration config.\n *\n * @param config - The config object of a single integration\n * @public\n */\nexport function readGoogleGcsIntegrationConfig(\n config: Config,\n): GoogleGcsIntegrationConfig {\n if (!config) {\n return { host: GOOGLE_GCS_HOST };\n }\n\n if (!config.has('clientEmail') && !config.has('privateKey')) {\n return { host: GOOGLE_GCS_HOST };\n }\n\n const privateKey = config.getString('privateKey').split('\\\\n').join('\\n');\n const clientEmail = config.getString('clientEmail');\n\n return {\n host: GOOGLE_GCS_HOST,\n clientEmail,\n privateKey,\n };\n}\n"],"names":[],"mappings":"AAsBO,MAAM,eAAA,GAAkB;AA4BxB,SAAS,+BACd,MAAA,EAC4B;AAC5B,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,OAAO,EAAE,MAAM,eAAA,EAAgB;AAAA,EACjC;AAEA,EAAA,IAAI,CAAC,OAAO,GAAA,CAAI,aAAa,KAAK,CAAC,MAAA,CAAO,GAAA,CAAI,YAAY,CAAA,EAAG;AAC3D,IAAA,OAAO,EAAE,MAAM,eAAA,EAAgB;AAAA,EACjC;AAEA,EAAA,MAAM,UAAA,GAAa,OAAO,SAAA,CAAU,YAAY,EAAE,KAAA,CAAM,KAAK,CAAA,CAAE,IAAA,CAAK,IAAI,CAAA;AACxE,EAAA,MAAM,WAAA,GAAc,MAAA,CAAO,SAAA,CAAU,aAAa,CAAA;AAElD,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,eAAA;AAAA,IACN,WAAA;AAAA,IACA;AAAA,GACF;AACF;;"}
|
|
@@ -8,6 +8,7 @@ class HarnessIntegration {
|
|
|
8
8
|
constructor(config) {
|
|
9
9
|
this.config = config;
|
|
10
10
|
}
|
|
11
|
+
config;
|
|
11
12
|
static factory = ({ config: config$1 }) => {
|
|
12
13
|
const configs = config$1.getOptionalConfigArray("integrations.harness") ?? [];
|
|
13
14
|
const harnessConfigs = configs.map((c) => config.readHarnessConfig(c));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HarnessIntegration.cjs.js","sources":["../../src/harness/HarnessIntegration.ts"],"sourcesContent":["/*\n * Copyright 2024 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 { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport { ScmIntegration, ScmIntegrationsFactory } from '../types';\nimport { HarnessIntegrationConfig, readHarnessConfig } from './config';\nimport { getHarnessEditContentsUrl } from './core';\n\n/**\n * A Harness Code based integration.\n *\n * @public\n */\nexport class HarnessIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<HarnessIntegration> = ({ config }) => {\n const configs = config.getOptionalConfigArray('integrations.harness') ?? [];\n const harnessConfigs = configs.map(c => readHarnessConfig(c));\n\n return basicIntegrations(\n harnessConfigs.map(c => new HarnessIntegration(c)),\n (harness: HarnessIntegration) => harness.config.host,\n );\n };\n\n constructor(readonly config: HarnessIntegrationConfig) {}\n\n get type(): string {\n return 'harness';\n }\n\n get title(): string {\n return this.config.host;\n }\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number | undefined;\n }): string {\n return defaultScmResolveUrl(options);\n }\n\n resolveEditUrl(url: string): string {\n return getHarnessEditContentsUrl(this.config, url);\n }\n}\n"],"names":["config","readHarnessConfig","basicIntegrations","defaultScmResolveUrl","getHarnessEditContentsUrl"],"mappings":";;;;;;AAyBO,MAAM,kBAAA,CAA6C;AAAA,EAWxD,YAAqB,MAAA,EAAkC;AAAlC,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA,EAAmC;AAAA,
|
|
1
|
+
{"version":3,"file":"HarnessIntegration.cjs.js","sources":["../../src/harness/HarnessIntegration.ts"],"sourcesContent":["/*\n * Copyright 2024 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 { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport { ScmIntegration, ScmIntegrationsFactory } from '../types';\nimport { HarnessIntegrationConfig, readHarnessConfig } from './config';\nimport { getHarnessEditContentsUrl } from './core';\n\n/**\n * A Harness Code based integration.\n *\n * @public\n */\nexport class HarnessIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<HarnessIntegration> = ({ config }) => {\n const configs = config.getOptionalConfigArray('integrations.harness') ?? [];\n const harnessConfigs = configs.map(c => readHarnessConfig(c));\n\n return basicIntegrations(\n harnessConfigs.map(c => new HarnessIntegration(c)),\n (harness: HarnessIntegration) => harness.config.host,\n );\n };\n\n constructor(readonly config: HarnessIntegrationConfig) {}\n\n get type(): string {\n return 'harness';\n }\n\n get title(): string {\n return this.config.host;\n }\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number | undefined;\n }): string {\n return defaultScmResolveUrl(options);\n }\n\n resolveEditUrl(url: string): string {\n return getHarnessEditContentsUrl(this.config, url);\n }\n}\n"],"names":["config","readHarnessConfig","basicIntegrations","defaultScmResolveUrl","getHarnessEditContentsUrl"],"mappings":";;;;;;AAyBO,MAAM,kBAAA,CAA6C;AAAA,EAWxD,YAAqB,MAAA,EAAkC;AAAlC,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA,EAAmC;AAAA,EAAnC,MAAA;AAAA,EAVrB,OAAO,OAAA,GAAsD,CAAC,UAAEA,UAAO,KAAM;AAC3E,IAAA,MAAM,OAAA,GAAUA,QAAA,CAAO,sBAAA,CAAuB,sBAAsB,KAAK,EAAC;AAC1E,IAAA,MAAM,iBAAiB,OAAA,CAAQ,GAAA,CAAI,CAAA,CAAA,KAAKC,wBAAA,CAAkB,CAAC,CAAC,CAAA;AAE5D,IAAA,OAAOC,yBAAA;AAAA,MACL,eAAe,GAAA,CAAI,CAAA,CAAA,KAAK,IAAI,kBAAA,CAAmB,CAAC,CAAC,CAAA;AAAA,MACjD,CAAC,OAAA,KAAgC,OAAA,CAAQ,MAAA,CAAO;AAAA,KAClD;AAAA,EACF,CAAA;AAAA,EAIA,IAAI,IAAA,GAAe;AACjB,IAAA,OAAO,SAAA;AAAA,EACT;AAAA,EAEA,IAAI,KAAA,GAAgB;AAClB,IAAA,OAAO,KAAK,MAAA,CAAO,IAAA;AAAA,EACrB;AAAA,EAEA,WAAW,OAAA,EAIA;AACT,IAAA,OAAOC,6BAAqB,OAAO,CAAA;AAAA,EACrC;AAAA,EAEA,eAAe,GAAA,EAAqB;AAClC,IAAA,OAAOC,8BAAA,CAA0B,IAAA,CAAK,MAAA,EAAQ,GAAG,CAAA;AAAA,EACnD;AACF;;"}
|
|
@@ -6,6 +6,7 @@ class HarnessIntegration {
|
|
|
6
6
|
constructor(config) {
|
|
7
7
|
this.config = config;
|
|
8
8
|
}
|
|
9
|
+
config;
|
|
9
10
|
static factory = ({ config }) => {
|
|
10
11
|
const configs = config.getOptionalConfigArray("integrations.harness") ?? [];
|
|
11
12
|
const harnessConfigs = configs.map((c) => readHarnessConfig(c));
|