@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.
Files changed (129) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/ScmIntegrations.cjs.js.map +1 -1
  3. package/dist/ScmIntegrations.esm.js.map +1 -1
  4. package/dist/alpha/github/createGitHubCredentialsProviderFromConnection.cjs.js.map +1 -1
  5. package/dist/alpha/github/createGitHubCredentialsProviderFromConnection.esm.js.map +1 -1
  6. package/dist/awsCodeCommit/AwsCodeCommitIntegration.cjs.js +1 -0
  7. package/dist/awsCodeCommit/AwsCodeCommitIntegration.cjs.js.map +1 -1
  8. package/dist/awsCodeCommit/AwsCodeCommitIntegration.esm.js +1 -0
  9. package/dist/awsCodeCommit/AwsCodeCommitIntegration.esm.js.map +1 -1
  10. package/dist/awsCodeCommit/config.cjs.js.map +1 -1
  11. package/dist/awsCodeCommit/config.esm.js.map +1 -1
  12. package/dist/awsS3/AwsS3Integration.cjs.js +1 -0
  13. package/dist/awsS3/AwsS3Integration.cjs.js.map +1 -1
  14. package/dist/awsS3/AwsS3Integration.esm.js +1 -0
  15. package/dist/awsS3/AwsS3Integration.esm.js.map +1 -1
  16. package/dist/awsS3/config.cjs.js.map +1 -1
  17. package/dist/awsS3/config.esm.js.map +1 -1
  18. package/dist/azure/AzureIntegration.cjs.js +12 -1
  19. package/dist/azure/AzureIntegration.cjs.js.map +1 -1
  20. package/dist/azure/AzureIntegration.esm.js +12 -1
  21. package/dist/azure/AzureIntegration.esm.js.map +1 -1
  22. package/dist/azure/AzureUrl.cjs.js.map +1 -1
  23. package/dist/azure/AzureUrl.esm.js.map +1 -1
  24. package/dist/azure/CachedAzureDevOpsCredentialsProvider.cjs.js +1 -0
  25. package/dist/azure/CachedAzureDevOpsCredentialsProvider.cjs.js.map +1 -1
  26. package/dist/azure/CachedAzureDevOpsCredentialsProvider.esm.js +1 -0
  27. package/dist/azure/CachedAzureDevOpsCredentialsProvider.esm.js.map +1 -1
  28. package/dist/azure/DefaultAzureDevOpsCredentialsProvider.cjs.js +1 -0
  29. package/dist/azure/DefaultAzureDevOpsCredentialsProvider.cjs.js.map +1 -1
  30. package/dist/azure/DefaultAzureDevOpsCredentialsProvider.esm.js +1 -0
  31. package/dist/azure/DefaultAzureDevOpsCredentialsProvider.esm.js.map +1 -1
  32. package/dist/azure/ManagedIdentityClientAssertion.cjs.js.map +1 -1
  33. package/dist/azure/ManagedIdentityClientAssertion.esm.js.map +1 -1
  34. package/dist/azure/config.cjs.js.map +1 -1
  35. package/dist/azure/config.esm.js.map +1 -1
  36. package/dist/azure/core.cjs.js.map +1 -1
  37. package/dist/azure/core.esm.js.map +1 -1
  38. package/dist/azure/isVisualStudioDomain.cjs.js.map +1 -1
  39. package/dist/azure/isVisualStudioDomain.esm.js.map +1 -1
  40. package/dist/azureBlobStorage/AzureBlobStorageIntegration.cjs.js +1 -0
  41. package/dist/azureBlobStorage/AzureBlobStorageIntegration.cjs.js.map +1 -1
  42. package/dist/azureBlobStorage/AzureBlobStorageIntegration.esm.js +1 -0
  43. package/dist/azureBlobStorage/AzureBlobStorageIntegration.esm.js.map +1 -1
  44. package/dist/azureBlobStorage/DefaultAzureCredentialsProvider.cjs.js +1 -0
  45. package/dist/azureBlobStorage/DefaultAzureCredentialsProvider.cjs.js.map +1 -1
  46. package/dist/azureBlobStorage/DefaultAzureCredentialsProvider.esm.js +1 -0
  47. package/dist/azureBlobStorage/DefaultAzureCredentialsProvider.esm.js.map +1 -1
  48. package/dist/azureBlobStorage/config.cjs.js.map +1 -1
  49. package/dist/azureBlobStorage/config.esm.js.map +1 -1
  50. package/dist/bitbucketCloud/BitbucketCloudIntegration.cjs.js +1 -0
  51. package/dist/bitbucketCloud/BitbucketCloudIntegration.cjs.js.map +1 -1
  52. package/dist/bitbucketCloud/BitbucketCloudIntegration.esm.js +1 -0
  53. package/dist/bitbucketCloud/BitbucketCloudIntegration.esm.js.map +1 -1
  54. package/dist/bitbucketCloud/config.cjs.js.map +1 -1
  55. package/dist/bitbucketCloud/config.esm.js.map +1 -1
  56. package/dist/bitbucketCloud/core.cjs.js +17 -10
  57. package/dist/bitbucketCloud/core.cjs.js.map +1 -1
  58. package/dist/bitbucketCloud/core.esm.js +17 -10
  59. package/dist/bitbucketCloud/core.esm.js.map +1 -1
  60. package/dist/bitbucketServer/BitbucketServerIntegration.cjs.js +1 -0
  61. package/dist/bitbucketServer/BitbucketServerIntegration.cjs.js.map +1 -1
  62. package/dist/bitbucketServer/BitbucketServerIntegration.esm.js +1 -0
  63. package/dist/bitbucketServer/BitbucketServerIntegration.esm.js.map +1 -1
  64. package/dist/bitbucketServer/config.cjs.js.map +1 -1
  65. package/dist/bitbucketServer/config.esm.js.map +1 -1
  66. package/dist/bitbucketServer/core.cjs.js.map +1 -1
  67. package/dist/bitbucketServer/core.esm.js.map +1 -1
  68. package/dist/gerrit/GerritIntegration.cjs.js +1 -0
  69. package/dist/gerrit/GerritIntegration.cjs.js.map +1 -1
  70. package/dist/gerrit/GerritIntegration.esm.js +1 -0
  71. package/dist/gerrit/GerritIntegration.esm.js.map +1 -1
  72. package/dist/gerrit/config.cjs.js.map +1 -1
  73. package/dist/gerrit/config.esm.js.map +1 -1
  74. package/dist/gerrit/core.cjs.js.map +1 -1
  75. package/dist/gerrit/core.esm.js.map +1 -1
  76. package/dist/gitea/GiteaIntegration.cjs.js +1 -0
  77. package/dist/gitea/GiteaIntegration.cjs.js.map +1 -1
  78. package/dist/gitea/GiteaIntegration.esm.js +1 -0
  79. package/dist/gitea/GiteaIntegration.esm.js.map +1 -1
  80. package/dist/gitea/config.cjs.js.map +1 -1
  81. package/dist/gitea/config.esm.js.map +1 -1
  82. package/dist/gitea/core.cjs.js.map +1 -1
  83. package/dist/gitea/core.esm.js.map +1 -1
  84. package/dist/github/DefaultGithubCredentialsProvider.cjs.js.map +1 -1
  85. package/dist/github/DefaultGithubCredentialsProvider.esm.js.map +1 -1
  86. package/dist/github/GithubIntegration.cjs.js +1 -0
  87. package/dist/github/GithubIntegration.cjs.js.map +1 -1
  88. package/dist/github/GithubIntegration.esm.js +1 -0
  89. package/dist/github/GithubIntegration.esm.js.map +1 -1
  90. package/dist/github/SingleInstanceGithubCredentialsProvider.cjs.js.map +1 -1
  91. package/dist/github/SingleInstanceGithubCredentialsProvider.esm.js.map +1 -1
  92. package/dist/github/config.cjs.js.map +1 -1
  93. package/dist/github/config.esm.js.map +1 -1
  94. package/dist/github/core.cjs.js.map +1 -1
  95. package/dist/github/core.esm.js.map +1 -1
  96. package/dist/gitlab/DefaultGitlabCredentialsProvider.cjs.js +1 -0
  97. package/dist/gitlab/DefaultGitlabCredentialsProvider.cjs.js.map +1 -1
  98. package/dist/gitlab/DefaultGitlabCredentialsProvider.esm.js +1 -0
  99. package/dist/gitlab/DefaultGitlabCredentialsProvider.esm.js.map +1 -1
  100. package/dist/gitlab/GitLabIntegration.cjs.js +1 -0
  101. package/dist/gitlab/GitLabIntegration.cjs.js.map +1 -1
  102. package/dist/gitlab/GitLabIntegration.esm.js +1 -0
  103. package/dist/gitlab/GitLabIntegration.esm.js.map +1 -1
  104. package/dist/gitlab/SingleInstanceGitlabCredentialsProvider.cjs.js +1 -0
  105. package/dist/gitlab/SingleInstanceGitlabCredentialsProvider.cjs.js.map +1 -1
  106. package/dist/gitlab/SingleInstanceGitlabCredentialsProvider.esm.js +1 -0
  107. package/dist/gitlab/SingleInstanceGitlabCredentialsProvider.esm.js.map +1 -1
  108. package/dist/gitlab/config.cjs.js.map +1 -1
  109. package/dist/gitlab/config.esm.js.map +1 -1
  110. package/dist/gitlab/core.cjs.js.map +1 -1
  111. package/dist/gitlab/core.esm.js.map +1 -1
  112. package/dist/googleGcs/GoogleGcsIntegration.cjs.js +1 -0
  113. package/dist/googleGcs/GoogleGcsIntegration.cjs.js.map +1 -1
  114. package/dist/googleGcs/GoogleGcsIntegration.esm.js +1 -0
  115. package/dist/googleGcs/GoogleGcsIntegration.esm.js.map +1 -1
  116. package/dist/googleGcs/config.cjs.js.map +1 -1
  117. package/dist/googleGcs/config.esm.js.map +1 -1
  118. package/dist/harness/HarnessIntegration.cjs.js +1 -0
  119. package/dist/harness/HarnessIntegration.cjs.js.map +1 -1
  120. package/dist/harness/HarnessIntegration.esm.js +1 -0
  121. package/dist/harness/HarnessIntegration.esm.js.map +1 -1
  122. package/dist/harness/config.cjs.js.map +1 -1
  123. package/dist/harness/config.esm.js.map +1 -1
  124. package/dist/harness/core.cjs.js.map +1 -1
  125. package/dist/harness/core.esm.js.map +1 -1
  126. package/dist/helpers.cjs.js.map +1 -1
  127. package/dist/helpers.esm.js.map +1 -1
  128. package/dist/index.d.ts +4 -2
  129. package/package.json +7 -7
@@ -1 +1 @@
1
- {"version":3,"file":"HarnessIntegration.esm.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":[],"mappings":";;;;AAyBO,MAAM,kBAAA,CAA6C;AAAA,EAWxD,YAAqB,MAAA,EAAkC;AAAlC,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA,EAAmC;AAAA,EAVxD,OAAO,OAAA,GAAsD,CAAC,EAAE,QAAO,KAAM;AAC3E,IAAA,MAAM,OAAA,GAAU,MAAA,CAAO,sBAAA,CAAuB,sBAAsB,KAAK,EAAC;AAC1E,IAAA,MAAM,iBAAiB,OAAA,CAAQ,GAAA,CAAI,CAAA,CAAA,KAAK,iBAAA,CAAkB,CAAC,CAAC,CAAA;AAE5D,IAAA,OAAO,iBAAA;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,OAAO,qBAAqB,OAAO,CAAA;AAAA,EACrC;AAAA,EAEA,eAAe,GAAA,EAAqB;AAClC,IAAA,OAAO,yBAAA,CAA0B,IAAA,CAAK,MAAA,EAAQ,GAAG,CAAA;AAAA,EACnD;AACF;;;;"}
1
+ {"version":3,"file":"HarnessIntegration.esm.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":[],"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,EAAE,QAAO,KAAM;AAC3E,IAAA,MAAM,OAAA,GAAU,MAAA,CAAO,sBAAA,CAAuB,sBAAsB,KAAK,EAAC;AAC1E,IAAA,MAAM,iBAAiB,OAAA,CAAQ,GAAA,CAAI,CAAA,CAAA,KAAK,iBAAA,CAAkB,CAAC,CAAC,CAAA;AAE5D,IAAA,OAAO,iBAAA;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,OAAO,qBAAqB,OAAO,CAAA;AAAA,EACrC;AAAA,EAEA,eAAe,GAAA,EAAqB;AAClC,IAAA,OAAO,yBAAA,CAA0B,IAAA,CAAK,MAAA,EAAQ,GAAG,CAAA;AAAA,EACnD;AACF;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"config.cjs.js","sources":["../../src/harness/config.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 */\n\nimport { Config } from '@backstage/config';\nimport { isValidHost } from '../helpers';\n\n/**\n * The configuration for a single Harness integration.\n *\n * @public\n */\nexport type HarnessIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. \"app.harness.io\"\n */\n host: string;\n /**\n * The password or http token to use for authentication.\n */\n token?: string;\n /**\n * The API key to use for authentication.\n */\n apiKey?: string;\n};\n\n/**\n * Parses a location config block for use in HarnessIntegration\n *\n * @public\n */\nexport function readHarnessConfig(config: Config): HarnessIntegrationConfig {\n const host = config.getString('host');\n const token = config.getOptionalString('token');\n const apiKey = config.getOptionalString('apiKey');\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid Harness Code integration config, '${host}' is not a valid host`,\n );\n }\n\n return {\n host,\n apiKey,\n token,\n };\n}\n"],"names":["isValidHost"],"mappings":";;;;AA4CO,SAAS,kBAAkB,MAAA,EAA0C;AAC1E,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,SAAA,CAAU,MAAM,CAAA;AACpC,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,iBAAA,CAAkB,OAAO,CAAA;AAC9C,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,iBAAA,CAAkB,QAAQ,CAAA;AAEhD,EAAA,IAAI,CAACA,mBAAA,CAAY,IAAI,CAAA,EAAG;AACtB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,6CAA6C,IAAI,CAAA,qBAAA;AAAA,KACnD;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,MAAA;AAAA,IACA;AAAA,GACF;AACF;;;;"}
1
+ {"version":3,"file":"config.cjs.js","sources":["../../src/harness/config.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 */\n\nimport { Config } from '@backstage/config';\nimport { isValidHost } from '../helpers';\n\n/**\n * The configuration for a single Harness integration.\n *\n * @public\n */\nexport type HarnessIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. \"app.harness.io\"\n */\n host: string;\n /**\n * The password or http token to use for authentication.\n */\n token?: string;\n /**\n * The API key to use for authentication.\n */\n apiKey?: string;\n};\n\n/**\n * Parses a location config block for use in HarnessIntegration\n *\n * @public\n */\nexport function readHarnessConfig(config: Config): HarnessIntegrationConfig {\n const host = config.getString('host');\n const token = config.getOptionalString('token');\n const apiKey = config.getOptionalString('apiKey');\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid Harness Code integration config, '${host}' is not a valid host`,\n );\n }\n\n return {\n host,\n apiKey,\n token,\n };\n}\n"],"names":["isValidHost"],"mappings":";;;;AA4CO,SAAS,kBAAkB,MAAA,EAA0C;AAC1E,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,SAAA,CAAU,MAAM,CAAA;AACpC,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,iBAAA,CAAkB,OAAO,CAAA;AAC9C,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,iBAAA,CAAkB,QAAQ,CAAA;AAEhD,EAAA,IAAI,CAACA,mBAAA,CAAY,IAAI,CAAA,EAAG;AACtB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,6CAA6C,IAAI,CAAA,qBAAA;AAAA,KACnD;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,MAAA;AAAA,IACA;AAAA,GACF;AACF;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"config.esm.js","sources":["../../src/harness/config.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 */\n\nimport { Config } from '@backstage/config';\nimport { isValidHost } from '../helpers';\n\n/**\n * The configuration for a single Harness integration.\n *\n * @public\n */\nexport type HarnessIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. \"app.harness.io\"\n */\n host: string;\n /**\n * The password or http token to use for authentication.\n */\n token?: string;\n /**\n * The API key to use for authentication.\n */\n apiKey?: string;\n};\n\n/**\n * Parses a location config block for use in HarnessIntegration\n *\n * @public\n */\nexport function readHarnessConfig(config: Config): HarnessIntegrationConfig {\n const host = config.getString('host');\n const token = config.getOptionalString('token');\n const apiKey = config.getOptionalString('apiKey');\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid Harness Code integration config, '${host}' is not a valid host`,\n );\n }\n\n return {\n host,\n apiKey,\n token,\n };\n}\n"],"names":[],"mappings":";;AA4CO,SAAS,kBAAkB,MAAA,EAA0C;AAC1E,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,SAAA,CAAU,MAAM,CAAA;AACpC,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,iBAAA,CAAkB,OAAO,CAAA;AAC9C,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,iBAAA,CAAkB,QAAQ,CAAA;AAEhD,EAAA,IAAI,CAAC,WAAA,CAAY,IAAI,CAAA,EAAG;AACtB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,6CAA6C,IAAI,CAAA,qBAAA;AAAA,KACnD;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,MAAA;AAAA,IACA;AAAA,GACF;AACF;;;;"}
1
+ {"version":3,"file":"config.esm.js","sources":["../../src/harness/config.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 */\n\nimport { Config } from '@backstage/config';\nimport { isValidHost } from '../helpers';\n\n/**\n * The configuration for a single Harness integration.\n *\n * @public\n */\nexport type HarnessIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. \"app.harness.io\"\n */\n host: string;\n /**\n * The password or http token to use for authentication.\n */\n token?: string;\n /**\n * The API key to use for authentication.\n */\n apiKey?: string;\n};\n\n/**\n * Parses a location config block for use in HarnessIntegration\n *\n * @public\n */\nexport function readHarnessConfig(config: Config): HarnessIntegrationConfig {\n const host = config.getString('host');\n const token = config.getOptionalString('token');\n const apiKey = config.getOptionalString('apiKey');\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid Harness Code integration config, '${host}' is not a valid host`,\n );\n }\n\n return {\n host,\n apiKey,\n token,\n };\n}\n"],"names":[],"mappings":";;AA4CO,SAAS,kBAAkB,MAAA,EAA0C;AAC1E,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,SAAA,CAAU,MAAM,CAAA;AACpC,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,iBAAA,CAAkB,OAAO,CAAA;AAC9C,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,iBAAA,CAAkB,QAAQ,CAAA;AAEhD,EAAA,IAAI,CAAC,WAAA,CAAY,IAAI,CAAA,EAAG;AACtB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,6CAA6C,IAAI,CAAA,qBAAA;AAAA,KACnD;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,MAAA;AAAA,IACA;AAAA,GACF;AACF;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"core.cjs.js","sources":["../../src/harness/core.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 { HarnessIntegrationConfig } from './config';\n\n/**\n * Given a URL pointing to a file, returns a URL\n * for editing the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://app.harness.io/a/b/src/branchname/path/to/c.yaml\n * or: https://app.harness.io/a/b/_edit/branchname/path/to/c.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessEditContentsUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n return `${parsedUrl.baseUrl}/ng/account/${parsedUrl.accountId}/module/code${\n parsedUrl.orgName !== '' ? `/orgs/${parsedUrl.orgName}` : ''\n }${\n parsedUrl.projectName !== '' ? `/projects/${parsedUrl.projectName}` : ''\n }/repos/${parsedUrl.repoName}/files/${parsedUrl.branch}/~/${parsedUrl.path}`;\n}\n\n/**\n * Given a file path URL,\n * it returns an API URL which returns the contents of the file .\n * @remarks\n *\n * Converts\n * from: https://app.harness.io/ng/account/accountId/module/code/orgs/orgName/projects/projName/repos/repoName/files/refMain/~/all-apis.yaml\n * https://qa.harness.io/ng/account/bDCAuAjFSJCLFj_0ug3lCg/module/code/orgs/HiteshTest/repos/impoorter/files/main/~/catalog.yaml\n * to: https://app.harness.io/gateway/code/api/v1/repos/accountId/orgName/projName/repoName/+/content/all-apis.yaml?routingId=accountId&include_commit=false&ref=refMain\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessFileContentsUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;\n\n if (parsedUrl.orgName) {\n constructedUrl += `/${parsedUrl.orgName}`;\n }\n\n if (parsedUrl.projectName) {\n constructedUrl += `/${parsedUrl.projectName}`;\n }\n\n constructedUrl += `/${parsedUrl.repoName}/+/raw/${parsedUrl.path}?routingId=${parsedUrl.accountId}&git_ref=refs/heads/${parsedUrl.refString}`;\n\n return constructedUrl;\n}\n\n/**\n * Given a URL pointing to a repository/path, returns a URL\n * for archive contents of the repository.\n *\n * @remarks\n *\n * Converts\n * from: https://qa.harness.io/ng/account/accountId/module/code/orgs/orgId/projects/projectName/repos/repoName/files/branch/~/fileName\n * to: https://qa.harness.io/gateway/code/api/v1/repos/accountId/orgId/projectName/repoName/+/archive/branch.zip?routingId=accountId\n *\n * @param url - A URL pointing to a repository/path\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessArchiveUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;\n\n if (parsedUrl.orgName) {\n constructedUrl += `/${parsedUrl.orgName}`;\n }\n\n if (parsedUrl.projectName) {\n constructedUrl += `/${parsedUrl.projectName}`;\n }\n\n constructedUrl += `/${parsedUrl.repoName}/+/archive/${parsedUrl.branch}.zip?routingId=${parsedUrl.accountId}`;\n\n return constructedUrl;\n}\n\n/**\n * Given a URL pointing to a repository branch, returns a URL\n * for latest commit information.\n *\n * @remarks\n *\n * Converts\n * from: https://app.harness.io/ng/account/accountId/module/code/orgs/orgName/projects/projectName/repos/repoName/files/branchName\n * to: https://app.harness.io/gateway/code/api/v1/repos/accountId/orgName/projectName/repoName/+/content?routingId=accountId&include_commit=true&git_ref=refs/heads/branchName\n *\n * @param url - A URL pointing to a repository branch\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessLatestCommitUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;\n\n if (parsedUrl.orgName) {\n constructedUrl += `/${parsedUrl.orgName}`;\n }\n\n if (parsedUrl.projectName) {\n constructedUrl += `/${parsedUrl.projectName}`;\n }\n\n constructedUrl += `/${parsedUrl.repoName}/+/content?routingId=${parsedUrl.accountId}&include_commit=true&git_ref=refs/heads/${parsedUrl.branch}`;\n\n return constructedUrl;\n}\n\n/**\n * Return request headers for a Harness Code provider.\n *\n * @param config - A Harness Code provider config\n * @public\n */\nexport function getHarnessRequestOptions(config: HarnessIntegrationConfig): {\n headers?: Record<string, string>;\n} {\n const headers: Record<string, string> = {};\n const { token, apiKey } = config;\n\n if (apiKey) {\n headers['x-api-key'] = apiKey;\n } else if (token) {\n headers.Authorization = `Bearer ${token}`;\n }\n\n return {\n headers,\n };\n}\n\n/**\n * Return parsed git url properties.\n *\n * @param config - A Harness provider config\n * @param url - A URL pointing to a repository\n * @public\n */\nexport function parseHarnessUrl(\n config: HarnessIntegrationConfig,\n url: string,\n): {\n baseUrl: string;\n accountId: string;\n orgName: string;\n projectName: string;\n refString: string;\n repoName: string;\n path: string;\n refDashStr: string;\n branch: string;\n} {\n const baseUrl = `https://${config.host}`;\n try {\n const pathUrl = new URL(url);\n const pathSegments = pathUrl.pathname\n .split('/')\n .filter(segment => segment !== '');\n const urlParts = pathUrl.pathname.split('/');\n\n const accountIdIndex =\n pathSegments.findIndex(segment => segment === 'account') + 1;\n const accountId = pathSegments[accountIdIndex];\n\n const orgNameIndex = pathSegments.findIndex(segment => segment === 'orgs');\n const orgName = orgNameIndex !== -1 ? pathSegments[orgNameIndex + 1] : '';\n const projectNameIndex = pathSegments.findIndex(\n segment => segment === 'projects',\n );\n\n const projectName =\n projectNameIndex !== -1 ? pathSegments[projectNameIndex + 1] : '';\n // Adjust repoNameIndex to correctly identify the repository name\n const repoNameIndex =\n pathSegments.findIndex(\n (segment, index) =>\n segment === 'repos' &&\n index > Math.max(accountIdIndex, orgNameIndex, projectNameIndex),\n ) + 1;\n const repoName = pathSegments[repoNameIndex];\n const refAndPath = urlParts.slice(\n urlParts.findIndex(i => i === 'files' || i === 'edit') + 1,\n );\n const refIndex = refAndPath.findIndex(item => item === '~');\n\n const refString = refAndPath.slice(0, refIndex).join('/');\n const pathWithoutSlash =\n refIndex !== -1\n ? refAndPath\n .slice(refIndex + 1)\n .join('/')\n .replace(/^\\//, '')\n : '';\n\n return {\n baseUrl: baseUrl,\n accountId: accountId,\n orgName: orgName,\n projectName: projectName,\n refString: refString,\n path: pathWithoutSlash,\n repoName: repoName,\n refDashStr: refAndPath.slice(0, refIndex).join('-'),\n branch:\n refIndex !== -1\n ? refAndPath.slice(0, refIndex).join('/')\n : refAndPath.join('/'),\n };\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n"],"names":[],"mappings":";;AA+BO,SAAS,yBAAA,CACd,QACA,GAAA,EACA;AACA,EAAA,MAAM,SAAA,GAAY,eAAA,CAAgB,MAAA,EAAQ,GAAG,CAAA;AAE7C,EAAA,OAAO,CAAA,EAAG,SAAA,CAAU,OAAO,CAAA,YAAA,EAAe,UAAU,SAAS,CAAA,YAAA,EAC3D,SAAA,CAAU,OAAA,KAAY,EAAA,GAAK,CAAA,MAAA,EAAS,SAAA,CAAU,OAAO,KAAK,EAC5D,CAAA,EACE,SAAA,CAAU,WAAA,KAAgB,EAAA,GAAK,CAAA,UAAA,EAAa,SAAA,CAAU,WAAW,KAAK,EACxE,CAAA,OAAA,EAAU,SAAA,CAAU,QAAQ,CAAA,OAAA,EAAU,SAAA,CAAU,MAAM,CAAA,GAAA,EAAM,UAAU,IAAI,CAAA,CAAA;AAC5E;AAgBO,SAAS,yBAAA,CACd,QACA,GAAA,EACA;AACA,EAAA,MAAM,SAAA,GAAY,eAAA,CAAgB,MAAA,EAAQ,GAAG,CAAA;AAE7C,EAAA,IAAI,iBAAiB,CAAA,EAAG,SAAA,CAAU,OAAO,CAAA,2BAAA,EAA8B,UAAU,SAAS,CAAA,CAAA;AAE1F,EAAA,IAAI,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A,GACpB,EAAA;AAEN,IAAA,OAAO;AAAA,MACL,OAAA;AAAA,MACA,SAAA;AAAA,MACA,OAAA;AAAA,MACA,WAAA;AAAA,MACA,SAAA;AAAA,MACA,IAAA,EAAM,gBAAA;AAAA,MACN,QAAA;AAAA,MACA,YAAY,UAAA,CAAW,KAAA,CAAM,GAAG,QAAQ,CAAA,CAAE,KAAK,GAAG,CAAA;AAAA,MAClD,MAAA,EACE,QAAA,KAAa,CAAA,CAAA,GACT,UAAA,CAAW,KAAA,CAAM,CAAA,EAAG,QAAQ,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA,GACtC,UAAA,CAAW,KAAK,GAAG;AAAA,KAC3B;AAAA,EACF,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EAC/C;AACF;;;;;;;;;"}
1
+ {"version":3,"file":"core.cjs.js","sources":["../../src/harness/core.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 { HarnessIntegrationConfig } from './config';\n\n/**\n * Given a URL pointing to a file, returns a URL\n * for editing the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://app.harness.io/a/b/src/branchname/path/to/c.yaml\n * or: https://app.harness.io/a/b/_edit/branchname/path/to/c.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessEditContentsUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n return `${parsedUrl.baseUrl}/ng/account/${parsedUrl.accountId}/module/code${\n parsedUrl.orgName !== '' ? `/orgs/${parsedUrl.orgName}` : ''\n }${\n parsedUrl.projectName !== '' ? `/projects/${parsedUrl.projectName}` : ''\n }/repos/${parsedUrl.repoName}/files/${parsedUrl.branch}/~/${parsedUrl.path}`;\n}\n\n/**\n * Given a file path URL,\n * it returns an API URL which returns the contents of the file .\n * @remarks\n *\n * Converts\n * from: https://app.harness.io/ng/account/accountId/module/code/orgs/orgName/projects/projName/repos/repoName/files/refMain/~/all-apis.yaml\n * https://qa.harness.io/ng/account/bDCAuAjFSJCLFj_0ug3lCg/module/code/orgs/HiteshTest/repos/impoorter/files/main/~/catalog.yaml\n * to: https://app.harness.io/gateway/code/api/v1/repos/accountId/orgName/projName/repoName/+/content/all-apis.yaml?routingId=accountId&include_commit=false&ref=refMain\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessFileContentsUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;\n\n if (parsedUrl.orgName) {\n constructedUrl += `/${parsedUrl.orgName}`;\n }\n\n if (parsedUrl.projectName) {\n constructedUrl += `/${parsedUrl.projectName}`;\n }\n\n constructedUrl += `/${parsedUrl.repoName}/+/raw/${parsedUrl.path}?routingId=${parsedUrl.accountId}&git_ref=refs/heads/${parsedUrl.refString}`;\n\n return constructedUrl;\n}\n\n/**\n * Given a URL pointing to a repository/path, returns a URL\n * for archive contents of the repository.\n *\n * @remarks\n *\n * Converts\n * from: https://qa.harness.io/ng/account/accountId/module/code/orgs/orgId/projects/projectName/repos/repoName/files/branch/~/fileName\n * to: https://qa.harness.io/gateway/code/api/v1/repos/accountId/orgId/projectName/repoName/+/archive/branch.zip?routingId=accountId\n *\n * @param url - A URL pointing to a repository/path\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessArchiveUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;\n\n if (parsedUrl.orgName) {\n constructedUrl += `/${parsedUrl.orgName}`;\n }\n\n if (parsedUrl.projectName) {\n constructedUrl += `/${parsedUrl.projectName}`;\n }\n\n constructedUrl += `/${parsedUrl.repoName}/+/archive/${parsedUrl.branch}.zip?routingId=${parsedUrl.accountId}`;\n\n return constructedUrl;\n}\n\n/**\n * Given a URL pointing to a repository branch, returns a URL\n * for latest commit information.\n *\n * @remarks\n *\n * Converts\n * from: https://app.harness.io/ng/account/accountId/module/code/orgs/orgName/projects/projectName/repos/repoName/files/branchName\n * to: https://app.harness.io/gateway/code/api/v1/repos/accountId/orgName/projectName/repoName/+/content?routingId=accountId&include_commit=true&git_ref=refs/heads/branchName\n *\n * @param url - A URL pointing to a repository branch\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessLatestCommitUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;\n\n if (parsedUrl.orgName) {\n constructedUrl += `/${parsedUrl.orgName}`;\n }\n\n if (parsedUrl.projectName) {\n constructedUrl += `/${parsedUrl.projectName}`;\n }\n\n constructedUrl += `/${parsedUrl.repoName}/+/content?routingId=${parsedUrl.accountId}&include_commit=true&git_ref=refs/heads/${parsedUrl.branch}`;\n\n return constructedUrl;\n}\n\n/**\n * Return request headers for a Harness Code provider.\n *\n * @param config - A Harness Code provider config\n * @public\n */\nexport function getHarnessRequestOptions(config: HarnessIntegrationConfig): {\n headers?: Record<string, string>;\n} {\n const headers: Record<string, string> = {};\n const { token, apiKey } = config;\n\n if (apiKey) {\n headers['x-api-key'] = apiKey;\n } else if (token) {\n headers.Authorization = `Bearer ${token}`;\n }\n\n return {\n headers,\n };\n}\n\n/**\n * Return parsed git url properties.\n *\n * @param config - A Harness provider config\n * @param url - A URL pointing to a repository\n * @public\n */\nexport function parseHarnessUrl(\n config: HarnessIntegrationConfig,\n url: string,\n): {\n baseUrl: string;\n accountId: string;\n orgName: string;\n projectName: string;\n refString: string;\n repoName: string;\n path: string;\n refDashStr: string;\n branch: string;\n} {\n const baseUrl = `https://${config.host}`;\n try {\n const pathUrl = new URL(url);\n const pathSegments = pathUrl.pathname\n .split('/')\n .filter(segment => segment !== '');\n const urlParts = pathUrl.pathname.split('/');\n\n const accountIdIndex =\n pathSegments.findIndex(segment => segment === 'account') + 1;\n const accountId = pathSegments[accountIdIndex];\n\n const orgNameIndex = pathSegments.findIndex(segment => segment === 'orgs');\n const orgName = orgNameIndex !== -1 ? pathSegments[orgNameIndex + 1] : '';\n const projectNameIndex = pathSegments.findIndex(\n segment => segment === 'projects',\n );\n\n const projectName =\n projectNameIndex !== -1 ? pathSegments[projectNameIndex + 1] : '';\n // Adjust repoNameIndex to correctly identify the repository name\n const repoNameIndex =\n pathSegments.findIndex(\n (segment, index) =>\n segment === 'repos' &&\n index > Math.max(accountIdIndex, orgNameIndex, projectNameIndex),\n ) + 1;\n const repoName = pathSegments[repoNameIndex];\n const refAndPath = urlParts.slice(\n urlParts.findIndex(i => i === 'files' || i === 'edit') + 1,\n );\n const refIndex = refAndPath.findIndex(item => item === '~');\n\n const refString = refAndPath.slice(0, refIndex).join('/');\n const pathWithoutSlash =\n refIndex !== -1\n ? refAndPath\n .slice(refIndex + 1)\n .join('/')\n .replace(/^\\//, '')\n : '';\n\n return {\n baseUrl: baseUrl,\n accountId: accountId,\n orgName: orgName,\n projectName: projectName,\n refString: refString,\n path: pathWithoutSlash,\n repoName: repoName,\n refDashStr: refAndPath.slice(0, refIndex).join('-'),\n branch:\n refIndex !== -1\n ? refAndPath.slice(0, refIndex).join('/')\n : refAndPath.join('/'),\n };\n } cat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AA,EACF,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EAC/C;AACF;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"core.esm.js","sources":["../../src/harness/core.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 { HarnessIntegrationConfig } from './config';\n\n/**\n * Given a URL pointing to a file, returns a URL\n * for editing the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://app.harness.io/a/b/src/branchname/path/to/c.yaml\n * or: https://app.harness.io/a/b/_edit/branchname/path/to/c.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessEditContentsUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n return `${parsedUrl.baseUrl}/ng/account/${parsedUrl.accountId}/module/code${\n parsedUrl.orgName !== '' ? `/orgs/${parsedUrl.orgName}` : ''\n }${\n parsedUrl.projectName !== '' ? `/projects/${parsedUrl.projectName}` : ''\n }/repos/${parsedUrl.repoName}/files/${parsedUrl.branch}/~/${parsedUrl.path}`;\n}\n\n/**\n * Given a file path URL,\n * it returns an API URL which returns the contents of the file .\n * @remarks\n *\n * Converts\n * from: https://app.harness.io/ng/account/accountId/module/code/orgs/orgName/projects/projName/repos/repoName/files/refMain/~/all-apis.yaml\n * https://qa.harness.io/ng/account/bDCAuAjFSJCLFj_0ug3lCg/module/code/orgs/HiteshTest/repos/impoorter/files/main/~/catalog.yaml\n * to: https://app.harness.io/gateway/code/api/v1/repos/accountId/orgName/projName/repoName/+/content/all-apis.yaml?routingId=accountId&include_commit=false&ref=refMain\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessFileContentsUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;\n\n if (parsedUrl.orgName) {\n constructedUrl += `/${parsedUrl.orgName}`;\n }\n\n if (parsedUrl.projectName) {\n constructedUrl += `/${parsedUrl.projectName}`;\n }\n\n constructedUrl += `/${parsedUrl.repoName}/+/raw/${parsedUrl.path}?routingId=${parsedUrl.accountId}&git_ref=refs/heads/${parsedUrl.refString}`;\n\n return constructedUrl;\n}\n\n/**\n * Given a URL pointing to a repository/path, returns a URL\n * for archive contents of the repository.\n *\n * @remarks\n *\n * Converts\n * from: https://qa.harness.io/ng/account/accountId/module/code/orgs/orgId/projects/projectName/repos/repoName/files/branch/~/fileName\n * to: https://qa.harness.io/gateway/code/api/v1/repos/accountId/orgId/projectName/repoName/+/archive/branch.zip?routingId=accountId\n *\n * @param url - A URL pointing to a repository/path\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessArchiveUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;\n\n if (parsedUrl.orgName) {\n constructedUrl += `/${parsedUrl.orgName}`;\n }\n\n if (parsedUrl.projectName) {\n constructedUrl += `/${parsedUrl.projectName}`;\n }\n\n constructedUrl += `/${parsedUrl.repoName}/+/archive/${parsedUrl.branch}.zip?routingId=${parsedUrl.accountId}`;\n\n return constructedUrl;\n}\n\n/**\n * Given a URL pointing to a repository branch, returns a URL\n * for latest commit information.\n *\n * @remarks\n *\n * Converts\n * from: https://app.harness.io/ng/account/accountId/module/code/orgs/orgName/projects/projectName/repos/repoName/files/branchName\n * to: https://app.harness.io/gateway/code/api/v1/repos/accountId/orgName/projectName/repoName/+/content?routingId=accountId&include_commit=true&git_ref=refs/heads/branchName\n *\n * @param url - A URL pointing to a repository branch\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessLatestCommitUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;\n\n if (parsedUrl.orgName) {\n constructedUrl += `/${parsedUrl.orgName}`;\n }\n\n if (parsedUrl.projectName) {\n constructedUrl += `/${parsedUrl.projectName}`;\n }\n\n constructedUrl += `/${parsedUrl.repoName}/+/content?routingId=${parsedUrl.accountId}&include_commit=true&git_ref=refs/heads/${parsedUrl.branch}`;\n\n return constructedUrl;\n}\n\n/**\n * Return request headers for a Harness Code provider.\n *\n * @param config - A Harness Code provider config\n * @public\n */\nexport function getHarnessRequestOptions(config: HarnessIntegrationConfig): {\n headers?: Record<string, string>;\n} {\n const headers: Record<string, string> = {};\n const { token, apiKey } = config;\n\n if (apiKey) {\n headers['x-api-key'] = apiKey;\n } else if (token) {\n headers.Authorization = `Bearer ${token}`;\n }\n\n return {\n headers,\n };\n}\n\n/**\n * Return parsed git url properties.\n *\n * @param config - A Harness provider config\n * @param url - A URL pointing to a repository\n * @public\n */\nexport function parseHarnessUrl(\n config: HarnessIntegrationConfig,\n url: string,\n): {\n baseUrl: string;\n accountId: string;\n orgName: string;\n projectName: string;\n refString: string;\n repoName: string;\n path: string;\n refDashStr: string;\n branch: string;\n} {\n const baseUrl = `https://${config.host}`;\n try {\n const pathUrl = new URL(url);\n const pathSegments = pathUrl.pathname\n .split('/')\n .filter(segment => segment !== '');\n const urlParts = pathUrl.pathname.split('/');\n\n const accountIdIndex =\n pathSegments.findIndex(segment => segment === 'account') + 1;\n const accountId = pathSegments[accountIdIndex];\n\n const orgNameIndex = pathSegments.findIndex(segment => segment === 'orgs');\n const orgName = orgNameIndex !== -1 ? pathSegments[orgNameIndex + 1] : '';\n const projectNameIndex = pathSegments.findIndex(\n segment => segment === 'projects',\n );\n\n const projectName =\n projectNameIndex !== -1 ? pathSegments[projectNameIndex + 1] : '';\n // Adjust repoNameIndex to correctly identify the repository name\n const repoNameIndex =\n pathSegments.findIndex(\n (segment, index) =>\n segment === 'repos' &&\n index > Math.max(accountIdIndex, orgNameIndex, projectNameIndex),\n ) + 1;\n const repoName = pathSegments[repoNameIndex];\n const refAndPath = urlParts.slice(\n urlParts.findIndex(i => i === 'files' || i === 'edit') + 1,\n );\n const refIndex = refAndPath.findIndex(item => item === '~');\n\n const refString = refAndPath.slice(0, refIndex).join('/');\n const pathWithoutSlash =\n refIndex !== -1\n ? refAndPath\n .slice(refIndex + 1)\n .join('/')\n .replace(/^\\//, '')\n : '';\n\n return {\n baseUrl: baseUrl,\n accountId: accountId,\n orgName: orgName,\n projectName: projectName,\n refString: refString,\n path: pathWithoutSlash,\n repoName: repoName,\n refDashStr: refAndPath.slice(0, refIndex).join('-'),\n branch:\n refIndex !== -1\n ? refAndPath.slice(0, refIndex).join('/')\n : refAndPath.join('/'),\n };\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n"],"names":[],"mappings":"AA+BO,SAAS,yBAAA,CACd,QACA,GAAA,EACA;AACA,EAAA,MAAM,SAAA,GAAY,eAAA,CAAgB,MAAA,EAAQ,GAAG,CAAA;AAE7C,EAAA,OAAO,CAAA,EAAG,SAAA,CAAU,OAAO,CAAA,YAAA,EAAe,UAAU,SAAS,CAAA,YAAA,EAC3D,SAAA,CAAU,OAAA,KAAY,EAAA,GAAK,CAAA,MAAA,EAAS,SAAA,CAAU,OAAO,KAAK,EAC5D,CAAA,EACE,SAAA,CAAU,WAAA,KAAgB,EAAA,GAAK,CAAA,UAA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KAAM,MAAM,CAAA,GAAI;AAAA,KAC3D;AACA,IAAA,MAAM,QAAA,GAAW,UAAA,CAAW,SAAA,CAAU,CAAA,IAAA,KAAQ,SAAS,GAAG,CAAA;AAE1D,IAAA,MAAM,YAAY,UAAA,CAAW,KAAA,CAAM,GAAG,QAAQ,CAAA,CAAE,KAAK,GAAG,CAAA;AACxD,IAAA,MAAM,gBAAA,GACJ,QAAA,KAAa,CAAA,CAAA,GACT,UAAA,CACG,MAAM,QAAA,GAAW,CAAC,CAAA,CAClB,IAAA,CAAK,GAAG,CAAA,CACR,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA,GACpB,EAAA;AAEN,IAAA,OAAO;AAAA,MACL,OAAA;AAAA,MACA,SAAA;AAAA,MACA,OAAA;AAAA,MACA,WAAA;AAAA,MACA,SAAA;AAAA,MACA,IAAA,EAAM,gBAAA;AAAA,MACN,QAAA;AAAA,MACA,YAAY,UAAA,CAAW,KAAA,CAAM,GAAG,QAAQ,CAAA,CAAE,KAAK,GAAG,CAAA;AAAA,MAClD,MAAA,EACE,QAAA,KAAa,CAAA,CAAA,GACT,UAAA,CAAW,KAAA,CAAM,CAAA,EAAG,QAAQ,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA,GACtC,UAAA,CAAW,KAAK,GAAG;AAAA,KAC3B;AAAA,EACF,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EAC/C;AACF;;;;"}
1
+ {"version":3,"file":"core.esm.js","sources":["../../src/harness/core.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 { HarnessIntegrationConfig } from './config';\n\n/**\n * Given a URL pointing to a file, returns a URL\n * for editing the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://app.harness.io/a/b/src/branchname/path/to/c.yaml\n * or: https://app.harness.io/a/b/_edit/branchname/path/to/c.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessEditContentsUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n return `${parsedUrl.baseUrl}/ng/account/${parsedUrl.accountId}/module/code${\n parsedUrl.orgName !== '' ? `/orgs/${parsedUrl.orgName}` : ''\n }${\n parsedUrl.projectName !== '' ? `/projects/${parsedUrl.projectName}` : ''\n }/repos/${parsedUrl.repoName}/files/${parsedUrl.branch}/~/${parsedUrl.path}`;\n}\n\n/**\n * Given a file path URL,\n * it returns an API URL which returns the contents of the file .\n * @remarks\n *\n * Converts\n * from: https://app.harness.io/ng/account/accountId/module/code/orgs/orgName/projects/projName/repos/repoName/files/refMain/~/all-apis.yaml\n * https://qa.harness.io/ng/account/bDCAuAjFSJCLFj_0ug3lCg/module/code/orgs/HiteshTest/repos/impoorter/files/main/~/catalog.yaml\n * to: https://app.harness.io/gateway/code/api/v1/repos/accountId/orgName/projName/repoName/+/content/all-apis.yaml?routingId=accountId&include_commit=false&ref=refMain\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessFileContentsUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;\n\n if (parsedUrl.orgName) {\n constructedUrl += `/${parsedUrl.orgName}`;\n }\n\n if (parsedUrl.projectName) {\n constructedUrl += `/${parsedUrl.projectName}`;\n }\n\n constructedUrl += `/${parsedUrl.repoName}/+/raw/${parsedUrl.path}?routingId=${parsedUrl.accountId}&git_ref=refs/heads/${parsedUrl.refString}`;\n\n return constructedUrl;\n}\n\n/**\n * Given a URL pointing to a repository/path, returns a URL\n * for archive contents of the repository.\n *\n * @remarks\n *\n * Converts\n * from: https://qa.harness.io/ng/account/accountId/module/code/orgs/orgId/projects/projectName/repos/repoName/files/branch/~/fileName\n * to: https://qa.harness.io/gateway/code/api/v1/repos/accountId/orgId/projectName/repoName/+/archive/branch.zip?routingId=accountId\n *\n * @param url - A URL pointing to a repository/path\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessArchiveUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;\n\n if (parsedUrl.orgName) {\n constructedUrl += `/${parsedUrl.orgName}`;\n }\n\n if (parsedUrl.projectName) {\n constructedUrl += `/${parsedUrl.projectName}`;\n }\n\n constructedUrl += `/${parsedUrl.repoName}/+/archive/${parsedUrl.branch}.zip?routingId=${parsedUrl.accountId}`;\n\n return constructedUrl;\n}\n\n/**\n * Given a URL pointing to a repository branch, returns a URL\n * for latest commit information.\n *\n * @remarks\n *\n * Converts\n * from: https://app.harness.io/ng/account/accountId/module/code/orgs/orgName/projects/projectName/repos/repoName/files/branchName\n * to: https://app.harness.io/gateway/code/api/v1/repos/accountId/orgName/projectName/repoName/+/content?routingId=accountId&include_commit=true&git_ref=refs/heads/branchName\n *\n * @param url - A URL pointing to a repository branch\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessLatestCommitUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;\n\n if (parsedUrl.orgName) {\n constructedUrl += `/${parsedUrl.orgName}`;\n }\n\n if (parsedUrl.projectName) {\n constructedUrl += `/${parsedUrl.projectName}`;\n }\n\n constructedUrl += `/${parsedUrl.repoName}/+/content?routingId=${parsedUrl.accountId}&include_commit=true&git_ref=refs/heads/${parsedUrl.branch}`;\n\n return constructedUrl;\n}\n\n/**\n * Return request headers for a Harness Code provider.\n *\n * @param config - A Harness Code provider config\n * @public\n */\nexport function getHarnessRequestOptions(config: HarnessIntegrationConfig): {\n headers?: Record<string, string>;\n} {\n const headers: Record<string, string> = {};\n const { token, apiKey } = config;\n\n if (apiKey) {\n headers['x-api-key'] = apiKey;\n } else if (token) {\n headers.Authorization = `Bearer ${token}`;\n }\n\n return {\n headers,\n };\n}\n\n/**\n * Return parsed git url properties.\n *\n * @param config - A Harness provider config\n * @param url - A URL pointing to a repository\n * @public\n */\nexport function parseHarnessUrl(\n config: HarnessIntegrationConfig,\n url: string,\n): {\n baseUrl: string;\n accountId: string;\n orgName: string;\n projectName: string;\n refString: string;\n repoName: string;\n path: string;\n refDashStr: string;\n branch: string;\n} {\n const baseUrl = `https://${config.host}`;\n try {\n const pathUrl = new URL(url);\n const pathSegments = pathUrl.pathname\n .split('/')\n .filter(segment => segment !== '');\n const urlParts = pathUrl.pathname.split('/');\n\n const accountIdIndex =\n pathSegments.findIndex(segment => segment === 'account') + 1;\n const accountId = pathSegments[accountIdIndex];\n\n const orgNameIndex = pathSegments.findIndex(segment => segment === 'orgs');\n const orgName = orgNameIndex !== -1 ? pathSegments[orgNameIndex + 1] : '';\n const projectNameIndex = pathSegments.findIndex(\n segment => segment === 'projects',\n );\n\n const projectName =\n projectNameIndex !== -1 ? pathSegments[projectNameIndex + 1] : '';\n // Adjust repoNameIndex to correctly identify the repository name\n const repoNameIndex =\n pathSegments.findIndex(\n (segment, index) =>\n segment === 'repos' &&\n index > Math.max(accountIdIndex, orgNameIndex, projectNameIndex),\n ) + 1;\n const repoName = pathSegments[repoNameIndex];\n const refAndPath = urlParts.slice(\n urlParts.findIndex(i => i === 'files' || i === 'edit') + 1,\n );\n const refIndex = refAndPath.findIndex(item => item === '~');\n\n const refString = refAndPath.slice(0, refIndex).join('/');\n const pathWithoutSlash =\n refIndex !== -1\n ? refAndPath\n .slice(refIndex + 1)\n .join('/')\n .replace(/^\\//, '')\n : '';\n\n return {\n baseUrl: baseUrl,\n accountId: accountId,\n orgName: orgName,\n projectName: projectName,\n refString: refString,\n path: pathWithoutSlash,\n repoName: repoName,\n refDashStr: refAndPath.slice(0, refIndex).join('-'),\n branch:\n refIndex !== -1\n ? refAndPath.slice(0, refIndex).join('/')\n : refAndPath.join('/'),\n };\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n"],"names":[],"mappings":"AA+BO,SAAS,yBAAA,CACd,QACA,GAAA,EACA;AACA,EAAA,MAAM,SAAA,GAAY,eAAA,CAAgB,MAAA,EAAQ,GAAG,CAAA;AAE7C,EAAA,OAAO,CAAA,EAAG,SAAA,CAAU,OAAO,CAAA,YAAA,EAAe,UAAU,SAAS,CAAA,YAAA,EAC3D,SAAA,CAAU,OAAA,KAAY,EAAA,GAAK,CAAA,MAAA,EAAS,SAAA,CAAU,OAAO,KAAK,EAC5D,CAAA,EACE,SAAA,CAAU,WAAA,KAAgB,EAAA,GAAK,CAAA,UAAA,EAAa,SAAA,CAAU,WAAW,KAAK,EACxE,CAAA,OAAA,EAAU,SAAA,CAAU,QAAQ,CAAA,OAAA,EAAU,SAAA,CAAU,MAAM,CAAA,GAAA,EAAM,UAAU,IAAI,CAAA,CAAA;AAC5E;AAgBO,SAAS,yBAAA,CACd,QACA,GAAA,EACA;AACA,EAAA,MAAM,SAAA,GAAY,eAAA,CAAgB,MAAA,EAAQ,GAAG,CAAA;AAE7C,EAAA,IAAI,iBAAiB,CAAA,EAAG,SAAA,CAAU,OAAO,CAAA,2BAAA,EAA8B,UAAU,SAAS,CAAA,CAAA;AAE1F,EAAA,IAAI,UAAU,OAAA,EAAS;AACrB,IAAA,cAAA,IAAkB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,OAAA;AAAA,MACA,SAAA;AAAA,MACA,OAAA;AAAA,MACA,WAAA;AAAA,MACA,SAAA;AAAA,MACA,IAAA,EAAM,gBAAA;AAAA,MACN,QAAA;AAAA,MACA,YAAY,UAAA,CAAW,KAAA,CAAM,GAAG,QAAQ,CAAA,CAAE,KAAK,GAAG,CAAA;AAAA,MAClD,MAAA,EACE,QAAA,KAAa,CAAA,CAAA,GACT,UAAA,CAAW,KAAA,CAAM,CAAA,EAAG,QAAQ,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA,GACtC,UAAA,CAAW,KAAK,GAAG;AAAA,KAC3B;AAAA,EACF,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EAC/C;AACF;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.cjs.js","sources":["../src/helpers.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 parseGitUrl from 'git-url-parse';\nimport { trimEnd } from 'lodash';\nimport { ScmIntegration, ScmIntegrationsGroup } from './types';\n\n/**\n * Wraps git-url-parse and rejects URLs whose filepath contains path traversal\n * segments. Without this check, a URL like\n * `https://github.com/o/r/blob/main/%2e%2e%2f%2e%2e%2fuser/repos` would be\n * decoded to `../../user/repos` and could escape the expected API path when\n * interpolated into provider API URLs.\n */\nexport function parseGitUrlSafe(url: string) {\n const parsed = parseGitUrl(url);\n if (parsed.filepath) {\n let decoded = parsed.filepath;\n let previous;\n do {\n previous = decoded;\n try {\n decoded = decodeURIComponent(decoded);\n } catch {\n break;\n }\n } while (decoded !== previous);\n\n if (\n decoded.split('/').some(segment => segment === '..' || segment === '.')\n ) {\n throw new Error(\n 'Invalid SCM URL: path traversal is not allowed in the URL',\n );\n }\n }\n return parsed;\n}\n\n/** Checks whether the given argument is a valid URL hostname */\nexport function isValidHost(host: string): boolean {\n const check = new URL('http://example.com');\n check.host = host;\n return check.host === host;\n}\n\n/** Checks whether the given argument is a valid URL */\nexport function isValidUrl(url: string): boolean {\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function basicIntegrations<T extends ScmIntegration>(\n integrations: T[],\n getHost: (integration: T) => string,\n): ScmIntegrationsGroup<T> {\n return {\n list(): T[] {\n return integrations;\n },\n byUrl(url: string | URL): T | undefined {\n try {\n const parsed = typeof url === 'string' ? new URL(url) : url;\n return integrations.find(i => getHost(i) === parsed.host);\n } catch {\n return undefined;\n }\n },\n byHost(host: string): T | undefined {\n return integrations.find(i => getHost(i) === host);\n },\n };\n}\n\n/**\n * Default implementation of {@link ScmIntegration} `resolveUrl`, that only\n * works with URL pathname based providers.\n *\n * @public\n */\nexport function defaultScmResolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n}): string {\n const { url, base, lineNumber } = options;\n\n // If it is a fully qualified URL - then return it verbatim\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return url;\n } catch {\n // ignore intentionally\n }\n\n let updated: URL;\n\n if (url.startsWith('/')) {\n // If it is an absolute path, move relative to the repo root\n const { href, filepath } = parseGitUrlSafe(base);\n\n updated = new URL(href);\n\n const repoRootPath = trimEnd(\n updated.pathname.substring(0, updated.pathname.length - filepath.length),\n '/',\n );\n updated.pathname = `${repoRootPath}${url}`;\n } else {\n // For relative URLs, just let the default URL constructor handle the\n // resolving. Note that this essentially will treat the last segment of the\n // base as a file - NOT a folder - unless the url ends in a slash.\n updated = new URL(url, base);\n }\n\n updated.search = new URL(base).search;\n if (lineNumber) {\n updated.hash = `L${lineNumber}`;\n }\n return updated.toString();\n}\n"],"names":["parseGitUrl","trimEnd"],"mappings":";;;;;;;;;AA2BO,SAAS,gBAAgB,GAAA,EAAa;AAC3C,EAAA,MAAM,MAAA,GAASA,6BAAY,GAAG,CAAA;AAC9B,EAAA,IAAI,OAAO,QAAA,EAAU;AACnB,IAAA,IAAI,UAAU,MAAA,CAAO,QAAA;AACrB,IAAA,IAAI,QAAA;AACJ,IAAA,GAAG;AACD,MAAA,QAAA,GAAW,OAAA;AACX,MAAA,IAAI;AACF,QAAA,OAAA,GAAU,mBAAmB,OAAO,CAAA;AAAA,MACtC,CAAA,CAAA,MAAQ;AACN,QAAA;AAAA,MACF;AAAA,IACF,SAAS,OAAA,KAAY,QAAA;AAErB,IAAA,IACE,OAAA,CAAQ,KAAA,CAAM,GAAG,CAAA,CAAE,IAAA,CAAK,aAAW,OAAA,KAAY,IAAA,IAAQ,OAAA,KAAY,GAAG,CAAA,EACtE;AACA,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;AAGO,SAAS,YAAY,IAAA,EAAuB;AACjD,EAAA,MAAM,KAAA,GAAQ,IAAI,GAAA,CAAI,oBAAoB,CAAA;AAC1C,EAAA,KAAA,CAAM,IAAA,GAAO,IAAA;AACb,EAAA,OAAO,MAAM,IAAA,KAAS,IAAA;AACxB;AAGO,SAAS,WAAW,GAAA,EAAsB;AAC/C,EAAA,IAAI;AAEF,IAAA,IAAI,IAAI,GAAG,CAAA;AACX,IAAA,OAAO,IAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,KAAA;AAAA,EACT;AACF;AAEO,SAAS,iBAAA,CACd,cACA,OAAA,EACyB;AACzB,EAAA,OAAO;AAAA,IACL,IAAA,GAAY;AACV,MAAA,OAAO,YAAA;AAAA,IACT,CAAA;AAAA,IACA,MAAM,GAAA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7B;AAEA,EAAA,OAAA,CAAQ,MAAA,GAAS,IAAI,GAAA,CAAI,IAAI,CAAA,CAAE,MAAA;AAC/B,EAAA,IAAI,UAAA,EAAY;AACd,IAAA,OAAA,CAAQ,IAAA,GAAO,IAAI,UAAU,CAAA,CAAA;AAAA,EAC/B;AACA,EAAA,OAAO,QAAQ,QAAA,EAAS;AAC1B;;;;;;;;"}
1
+ {"version":3,"file":"helpers.cjs.js","sources":["../src/helpers.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 parseGitUrl from 'git-url-parse';\nimport { trimEnd } from 'lodash';\nimport { ScmIntegration, ScmIntegrationsGroup } from './types';\n\n/**\n * Wraps git-url-parse and rejects URLs whose filepath contains path traversal\n * segments. Without this check, a URL like\n * `https://github.com/o/r/blob/main/%2e%2e%2f%2e%2e%2fuser/repos` would be\n * decoded to `../../user/repos` and could escape the expected API path when\n * interpolated into provider API URLs.\n */\nexport function parseGitUrlSafe(url: string) {\n const parsed = parseGitUrl(url);\n if (parsed.filepath) {\n let decoded = parsed.filepath;\n let previous;\n do {\n previous = decoded;\n try {\n decoded = decodeURIComponent(decoded);\n } catch {\n break;\n }\n } while (decoded !== previous);\n\n if (\n decoded.split('/').some(segment => segment === '..' || segment === '.')\n ) {\n throw new Error(\n 'Invalid SCM URL: path traversal is not allowed in the URL',\n );\n }\n }\n return parsed;\n}\n\n/** Checks whether the given argument is a valid URL hostname */\nexport function isValidHost(host: string): boolean {\n const check = new URL('http://example.com');\n check.host = host;\n return check.host === host;\n}\n\n/** Checks whether the given argument is a valid URL */\nexport function isValidUrl(url: string): boolean {\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function basicIntegrations<T extends ScmIntegration>(\n integrations: T[],\n getHost: (integration: T) => string,\n): ScmIntegrationsGroup<T> {\n return {\n list(): T[] {\n return integrations;\n },\n byUrl(url: string | URL): T | undefined {\n try {\n const parsed = typeof url === 'string' ? new URL(url) : url;\n return integrations.find(i => getHost(i) === parsed.host);\n } catch {\n return undefined;\n }\n },\n byHost(host: string): T | undefined {\n return integrations.find(i => getHost(i) === host);\n },\n };\n}\n\n/**\n * Default implementation of {@link ScmIntegration} `resolveUrl`, that only\n * works with URL pathname based providers.\n *\n * @public\n */\nexport function defaultScmResolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n}): string {\n const { url, base, lineNumber } = options;\n\n // If it is a fully qualified URL - then return it verbatim\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return url;\n } catch {\n // ignore intentionally\n }\n\n let updated: URL;\n\n if (url.startsWith('/')) {\n // If it is an absolute path, move relative to the repo root\n const { href, filepath } = parseGitUrlSafe(base);\n\n updated = new URL(href);\n\n const repoRootPath = trimEnd(\n updated.pathname.substring(0, updated.pathname.length - filepath.length),\n '/',\n );\n updated.pathname = `${repoRootPath}${url}`;\n } else {\n // For relative URLs, just let the default URL constructor handle the\n // resolving. Note that this essentially will treat the last segment of the\n // base as a file - NOT a folder - unless the url ends in a slash.\n updated = new URL(url, base);\n }\n\n updated.search = new URL(base).search;\n if (lineNumber) {\n updated.hash = `L${lineNumber}`;\n }\n return updated.toString();\n}\n"],"names":["parseGitUrl","trimEnd"],"mappings":";;;;;;;;;AA2BO,SAAS,gBAAgB,GAAA,EAAa;AAC3C,EAAA,MAAM,MAAA,GAASA,6BAAY,GAAG,CAAA;AAC9B,EAAA,IAAI,OAAO,QAAA,EAAU;AACnB,IAAA,IAAI,UAAU,MAAA,CAAO,QAAA;AACrB,IAAA,IAAI,QAAA;AACJ,I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esContent":["/*\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 parseGitUrl from 'git-url-parse';\nimport { trimEnd } from 'lodash';\nimport { ScmIntegration, ScmIntegrationsGroup } from './types';\n\n/**\n * Wraps git-url-parse and rejects URLs whose filepath contains path traversal\n * segments. Without this check, a URL like\n * `https://github.com/o/r/blob/main/%2e%2e%2f%2e%2e%2fuser/repos` would be\n * decoded to `../../user/repos` and could escape the expected API path when\n * interpolated into provider API URLs.\n */\nexport function parseGitUrlSafe(url: string) {\n const parsed = parseGitUrl(url);\n if (parsed.filepath) {\n let decoded = parsed.filepath;\n let previous;\n do {\n previous = decoded;\n try {\n decoded = decodeURIComponent(decoded);\n } catch {\n break;\n }\n } while (decoded !== previous);\n\n if (\n decoded.split('/').some(segment => segment === '..' || segment === '.')\n ) {\n throw new Error(\n 'Invalid SCM URL: path traversal is not allowed in the URL',\n );\n }\n }\n return parsed;\n}\n\n/** Checks whether the given argument is a valid URL hostname */\nexport function isValidHost(host: string): boolean {\n const check = new URL('http://example.com');\n check.host = host;\n return check.host === host;\n}\n\n/** Checks whether the given argument is a valid URL */\nexport function isValidUrl(url: string): boolean {\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function basicIntegrations<T extends ScmIntegration>(\n integrations: T[],\n getHost: (integration: T) => string,\n): ScmIntegrationsGroup<T> {\n return {\n list(): T[] {\n return integrations;\n },\n byUrl(url: string | URL): T | undefined {\n try {\n const parsed = typeof url === 'string' ? new URL(url) : url;\n return integrations.find(i => getHost(i) === parsed.host);\n } catch {\n return undefined;\n }\n },\n byHost(host: string): T | undefined {\n return integrations.find(i => getHost(i) === host);\n },\n };\n}\n\n/**\n * Default implementation of {@link ScmIntegration} `resolveUrl`, that only\n * works with URL pathname based providers.\n *\n * @public\n */\nexport function defaultScmResolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n}): string {\n const { url, base, lineNumber } = options;\n\n // If it is a fully qualified URL - then return it verbatim\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return url;\n } catch {\n // ignore intentionally\n }\n\n let updated: URL;\n\n if (url.startsWith('/')) {\n // If it is an absolute path, move relative to the repo root\n const { href, filepath } = parseGitUrlSafe(base);\n\n updated = new URL(href);\n\n const repoRootPath = trimEnd(\n updated.pathname.substring(0, updated.pathname.length - filepath.length),\n '/',\n );\n updated.pathname = `${repoRootPath}${url}`;\n } else {\n // For relative URLs, just let the default URL constructor handle the\n // resolving. Note that this essentially will treat the last segment of the\n // base as a file - NOT a folder - unless the url ends in a slash.\n updated = new URL(url, base);\n }\n\n updated.search = new URL(base).search;\n if (lineNumber) {\n updated.hash = `L${lineNumber}`;\n }\n return updated.toString();\n}\n"],"names":[],"mappings":";;;AA2BO,SAAS,gBAAgB,GAAA,EAAa;AAC3C,EAAA,MAAM,MAAA,GAAS,YAAY,GAAG,CAAA;AAC9B,EAAA,IAAI,OAAO,QAAA,EAAU;AACnB,IAAA,IAAI,UAAU,MAAA,CAAO,QAAA;AACrB,IAAA,IAAI,QAAA;AACJ,IAAA,GAAG;AACD,MAAA,QAAA,GAAW,OAAA;AACX,MAAA,IAAI;AACF,QAAA,OAAA,GAAU,mBAAmB,OAAO,CAAA;AAAA,MACtC,CAAA,CAAA,MAAQ;AACN,QAAA;AAAA,MACF;AAAA,IACF,SAAS,OAAA,KAAY,QAAA;AAErB,IAAA,IACE,OAAA,CAAQ,KAAA,CAAM,GAAG,CAAA,CAAE,IAAA,CAAK,aAAW,OAAA,KAAY,IAAA,IAAQ,OAAA,KAAY,GAAG,CAAA,EACtE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AAA;AAAA,EACT,CAAA,CAAA,MAAQ;AAAA,EAER;AAEA,EAAA,IAAI,OAAA;AAEJ,EAAA,IAAI,GAAA,CAAI,UAAA,CAAW,GAAG,CAAA,EAAG;AAEvB,IAAA,MAAM,EAAE,IAAA,EAAM,QAAA,EAAS,GAAI,gBAAgB,IAAI,CAAA;AAE/C,IAAA,OAAA,GAAU,IAAI,IAAI,IAAI,CAAA;AAEtB,IAAA,MAAM,YAAA,GAAe,OAAA;AAAA,MACnB,OAAA,CAAQ,SAAS,SAAA,CAAU,CAAA,EAAG,QAAQ,QAAA,CAAS,MAAA,GAAS,SAAS,MAAM,CAAA;AAAA,MACvE;AAAA,KACF;AACA,IAAA,OAAA,CAAQ,QAAA,GAAW,CAAA,EAAG,YAAY,CAAA,EAAG,GAAG,CAAA,CAAA;AAAA,EAC1C,CAAA,MAAO;AAIL,IAAA,OAAA,GAAU,IAAI,GAAA,CAAI,GAAA,EAAK,IAAI,CAAA;AAAA,EAC7B;AAEA,EAAA,OAAA,CAAQ,MAAA,GAAS,IAAI,GAAA,CAAI,IAAI,CAAA,CAAE,MAAA;AAC/B,EAAA,IAAI,UAAA,EAAY;AACd,IAAA,OAAA,CAAQ,IAAA,GAAO,IAAI,UAAU,CAAA,CAAA;AAAA,EAC/B;AACA,EAAA,OAAO,QAAQ,QAAA,EAAS;AAC1B;;;;"}
1
+ {"version":3,"file":"helpers.esm.js","sources":["../src/helpers.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 parseGitUrl from 'git-url-parse';\nimport { trimEnd } from 'lodash';\nimport { ScmIntegration, ScmIntegrationsGroup } from './types';\n\n/**\n * Wraps git-url-parse and rejects URLs whose filepath contains path traversal\n * segments. Without this check, a URL like\n * `https://github.com/o/r/blob/main/%2e%2e%2f%2e%2e%2fuser/repos` would be\n * decoded to `../../user/repos` and could escape the expected API path when\n * interpolated into provider API URLs.\n */\nexport function parseGitUrlSafe(url: string) {\n const parsed = parseGitUrl(url);\n if (parsed.filepath) {\n let decoded = parsed.filepath;\n let previous;\n do {\n previous = decoded;\n try {\n decoded = decodeURIComponent(decoded);\n } catch {\n break;\n }\n } while (decoded !== previous);\n\n if (\n decoded.split('/').some(segment => segment === '..' || segment === '.')\n ) {\n throw new Error(\n 'Invalid SCM URL: path traversal is not allowed in the URL',\n );\n }\n }\n return parsed;\n}\n\n/** Checks whether the given argument is a valid URL hostname */\nexport function isValidHost(host: string): boolean {\n const check = new URL('http://example.com');\n check.host = host;\n return check.host === host;\n}\n\n/** Checks whether the given argument is a valid URL */\nexport function isValidUrl(url: string): boolean {\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function basicIntegrations<T extends ScmIntegration>(\n integrations: T[],\n getHost: (integration: T) => string,\n): ScmIntegrationsGroup<T> {\n return {\n list(): T[] {\n return integrations;\n },\n byUrl(url: string | URL): T | undefined {\n try {\n const parsed = typeof url === 'string' ? new URL(url) : url;\n return integrations.find(i => getHost(i) === parsed.host);\n } catch {\n return undefined;\n }\n },\n byHost(host: string): T | undefined {\n return integrations.find(i => getHost(i) === host);\n },\n };\n}\n\n/**\n * Default implementation of {@link ScmIntegration} `resolveUrl`, that only\n * works with URL pathname based providers.\n *\n * @public\n */\nexport function defaultScmResolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n}): string {\n const { url, base, lineNumber } = options;\n\n // If it is a fully qualified URL - then return it verbatim\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return url;\n } catch {\n // ignore intentionally\n }\n\n let updated: URL;\n\n if (url.startsWith('/')) {\n // If it is an absolute path, move relative to the repo root\n const { href, filepath } = parseGitUrlSafe(base);\n\n updated = new URL(href);\n\n const repoRootPath = trimEnd(\n updated.pathname.substring(0, updated.pathname.length - filepath.length),\n '/',\n );\n updated.pathname = `${repoRootPath}${url}`;\n } else {\n // For relative URLs, just let the default URL constructor handle the\n // resolving. Note that this essentially will treat the last segment of the\n // base as a file - NOT a folder - unless the url ends in a slash.\n updated = new URL(url, base);\n }\n\n updated.search = new URL(base).search;\n if (lineNumber) {\n updated.hash = `L${lineNumber}`;\n }\n return updated.toString();\n}\n"],"names":[],"mappings":";;;AA2BO,SAAS,gBAAgB,GAAA,EAAa;AAC3C,EAAA,MAAM,MAAA,GAAS,YAAY,GAAG,CAAA;AAC9B,EAAA,IAAI,OAAO,QAAA,EAAU;AACnB,IAAA,IAAI,UAAU,MAAA,CAAO,QAAA;AACrB,IAAA,IAAI,QAAA;AACJ,IAAA,GAAG;AACD,MAAA,QAAA,GAAW,OAAA;AACX,MAAA,IAAI;AACF,QAAA,OAAA,GAAU,mBAAmB,OAAO,CAAA;AAAA,MACtC,CAAA,CAAA,MAAQ;AACN,QAAA;AAAA,MACF;AAAA,IACF,SAAS,OAAA,KAAY,QAAA;AAErB,IAAA,IACE,OAAA,CAAQ,KAAA,CAAM,GAAG,CAAA,CAAE,IAAA,CAAK,aAAW,OAAA,KAAY,IAAA,IAAQ,OAAA,KAAY,GAAG,CAAA,EACtE;AACA,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;AAGO,SAAS,YAAY,IAAA,EAAuB;AACjD,EAAA,MAAM,KAAA,GAAQ,IAAI,GAAA,CAAI,oBAAoB,CAAA;AAC1C,EAAA,KAAA,CAAM,IAAA,GAAO,IAAA;AACb,EAAA,OAAO,MAAM,IAAA,KAAS,IAAA;AACxB;AAGO,SAAS,WAAW,GAAA,EAAsB;AAC/C,EAAA,IAAI;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CAAA,EAAG,QAAQ,QAAA,CAAS,MAAA,GAAS,SAAS,MAAM,CAAA;AAAA,MACvE;AAAA,KACF;AACA,IAAA,OAAA,CAAQ,QAAA,GAAW,CAAA,EAAG,YAAY,CAAA,EAAG,GAAG,CAAA,CAAA;AAAA,EAC1C,CAAA,MAAO;AAIL,IAAA,OAAA,GAAU,IAAI,GAAA,CAAI,GAAA,EAAK,IAAI,CAAA;AAAA,EAC7B;AAEA,EAAA,OAAA,CAAQ,MAAA,GAAS,IAAI,GAAA,CAAI,IAAI,CAAA,CAAE,MAAA;AAC/B,EAAA,IAAI,UAAA,EAAY;AACd,IAAA,OAAA,CAAQ,IAAA,GAAO,IAAI,UAAU,CAAA,CAAA;AAAA,EAC/B;AACA,EAAA,OAAO,QAAQ,QAAA,EAAS;AAC1B;;"}
package/dist/index.d.ts CHANGED
@@ -482,7 +482,8 @@ declare function readAzureIntegrationConfig(config: Config): AzureIntegrationCon
482
482
  declare function readAzureIntegrationConfigs(configs: Config[]): AzureIntegrationConfig[];
483
483
 
484
484
  /**
485
- * Microsoft Azure based integration.
485
+ * Microsoft Azure based integration. Repository file URLs resolve directly to
486
+ * the Azure DevOps edit view.
486
487
  *
487
488
  * @public
488
489
  */
@@ -1286,7 +1287,8 @@ declare function getBitbucketCloudFileFetchUrl(url: string, config: BitbucketClo
1286
1287
  /**
1287
1288
  * Gets the request options necessary to make requests to a given provider.
1288
1289
  * Returns headers for authenticating with Bitbucket Cloud.
1289
- * Supports OAuth (clientId/clientSecret), username/token, and username/appPassword auth.
1290
+ * Supports OAuth (clientId/clientSecret), username/token, username/appPassword,
1291
+ * and Bearer token auth.
1290
1292
  *
1291
1293
  * @param config - The relevant provider config
1292
1294
  * @public
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/integration",
3
- "version": "2.1.2",
3
+ "version": "2.1.3-next.1",
4
4
  "description": "Helpers for managing integrations towards external systems",
5
5
  "backstage": {
6
6
  "role": "common-library"
@@ -61,9 +61,9 @@
61
61
  "dependencies": {
62
62
  "@azure/identity": "^4.0.0",
63
63
  "@azure/storage-blob": "^12.5.0",
64
- "@backstage/config": "^1.3.9",
65
- "@backstage/connections": "^0.4.0",
66
- "@backstage/errors": "^1.3.1",
64
+ "@backstage/config": "1.3.10-next.0",
65
+ "@backstage/connections": "0.4.1-next.0",
66
+ "@backstage/errors": "1.3.2-next.0",
67
67
  "@octokit/auth-app": "^4.0.0",
68
68
  "@octokit/rest": "^19.0.3",
69
69
  "cross-fetch": "^4.0.0",
@@ -73,9 +73,9 @@
73
73
  "p-throttle": "^4.1.1"
74
74
  },
75
75
  "devDependencies": {
76
- "@backstage/backend-test-utils": "^1.11.7",
77
- "@backstage/cli": "^0.36.6",
78
- "@backstage/config-loader": "^1.11.3",
76
+ "@backstage/backend-test-utils": "1.11.8-next.1",
77
+ "@backstage/cli": "0.36.7-next.0",
78
+ "@backstage/config-loader": "1.11.4-next.0",
79
79
  "msw": "^2.0.0"
80
80
  },
81
81
  "configSchema": "config.schema.json",