@backstage/integration 1.17.1-next.1 → 1.18.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/ScmIntegrations.cjs.js.map +1 -1
- package/dist/ScmIntegrations.esm.js.map +1 -1
- package/dist/awsCodeCommit/AwsCodeCommitIntegration.cjs.js.map +1 -1
- 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.map +1 -1
- 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.map +1 -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.map +1 -1
- package/dist/azure/CachedAzureDevOpsCredentialsProvider.esm.js.map +1 -1
- package/dist/azure/DefaultAzureDevOpsCredentialsProvider.cjs.js.map +1 -1
- 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/deprecated.cjs.js.map +1 -1
- package/dist/azure/deprecated.esm.js.map +1 -1
- package/dist/azureBlobStorage/AzureBlobStorageIntegration.cjs.js.map +1 -1
- package/dist/azureBlobStorage/AzureBlobStorageIntegration.esm.js.map +1 -1
- package/dist/azureBlobStorage/DefaultAzureCredentialsProvider.cjs.js.map +1 -1
- 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/bitbucket/BitbucketIntegration.cjs.js.map +1 -1
- package/dist/bitbucket/BitbucketIntegration.esm.js.map +1 -1
- package/dist/bitbucket/config.cjs.js.map +1 -1
- package/dist/bitbucket/config.esm.js.map +1 -1
- package/dist/bitbucket/core.cjs.js.map +1 -1
- package/dist/bitbucket/core.esm.js.map +1 -1
- package/dist/bitbucketCloud/BitbucketCloudIntegration.cjs.js.map +1 -1
- 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.map +1 -1
- package/dist/bitbucketCloud/core.esm.js.map +1 -1
- package/dist/bitbucketServer/BitbucketServerIntegration.cjs.js.map +1 -1
- 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.map +1 -1
- 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.map +1 -1
- 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.map +1 -1
- package/dist/github/GithubIntegration.esm.js.map +1 -1
- package/dist/github/SingleInstanceGithubCredentialsProvider.cjs.js +2 -2
- package/dist/github/SingleInstanceGithubCredentialsProvider.cjs.js.map +1 -1
- package/dist/github/SingleInstanceGithubCredentialsProvider.esm.js +2 -2
- 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.map +1 -1
- package/dist/gitlab/DefaultGitlabCredentialsProvider.esm.js.map +1 -1
- package/dist/gitlab/GitLabIntegration.cjs.js.map +1 -1
- package/dist/gitlab/GitLabIntegration.esm.js.map +1 -1
- package/dist/gitlab/SingleInstanceGitlabCredentialsProvider.cjs.js.map +1 -1
- 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/config.cjs.js.map +1 -1
- package/dist/googleGcs/config.esm.js.map +1 -1
- package/dist/harness/HarnessIntegration.cjs.js.map +1 -1
- 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 +1 -1
- package/package.json +4 -4
|
@@ -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 */\n\nimport { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport { ScmIntegration, ScmIntegrationsFactory } from '../types';\nimport {\n GitLabIntegrationConfig,\n readGitLabIntegrationConfigs,\n} from './config';\n\n/**\n * A GitLab based integration.\n *\n * @public\n */\nexport class GitLabIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<GitLabIntegration> = ({ config }) => {\n const configs = readGitLabIntegrationConfigs(\n config.getOptionalConfigArray('integrations.gitlab') ?? [],\n );\n return basicIntegrations(\n configs.map(c => new GitLabIntegration(c)),\n i => i.config.host,\n );\n };\n\n constructor(private readonly integrationConfig: GitLabIntegrationConfig) {}\n\n get type(): string {\n return 'gitlab';\n }\n\n get title(): string {\n return this.integrationConfig.host;\n }\n\n get config(): GitLabIntegrationConfig {\n return this.integrationConfig;\n }\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n }): string {\n return defaultScmResolveUrl(options);\n }\n\n resolveEditUrl(url: string): string {\n return replaceGitLabUrlType(url, 'edit');\n }\n}\n\n/**\n * Takes a GitLab URL and replaces the type part (blob, tree etc).\n *\n * @param url - The original URL\n * @param type - The desired type, e.g. 'blob', 'tree', 'edit'\n * @public\n */\nexport function replaceGitLabUrlType(\n url: string,\n type: 'blob' | 'tree' | 'edit',\n): string {\n return url.replace(/\\/\\-\\/(blob|tree|edit)\\//, `/-/${type}/`);\n}\n"],"names":["config","readGitLabIntegrationConfigs","basicIntegrations","defaultScmResolveUrl"],"mappings":";;;;;AA4BO,MAAM,
|
|
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 */\n\nimport { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport { ScmIntegration, ScmIntegrationsFactory } from '../types';\nimport {\n GitLabIntegrationConfig,\n readGitLabIntegrationConfigs,\n} from './config';\n\n/**\n * A GitLab based integration.\n *\n * @public\n */\nexport class GitLabIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<GitLabIntegration> = ({ config }) => {\n const configs = readGitLabIntegrationConfigs(\n config.getOptionalConfigArray('integrations.gitlab') ?? [],\n );\n return basicIntegrations(\n configs.map(c => new GitLabIntegration(c)),\n i => i.config.host,\n );\n };\n\n constructor(private readonly integrationConfig: GitLabIntegrationConfig) {}\n\n get type(): string {\n return 'gitlab';\n }\n\n get title(): string {\n return this.integrationConfig.host;\n }\n\n get config(): GitLabIntegrationConfig {\n return this.integrationConfig;\n }\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n }): string {\n return defaultScmResolveUrl(options);\n }\n\n resolveEditUrl(url: string): string {\n return replaceGitLabUrlType(url, 'edit');\n }\n}\n\n/**\n * Takes a GitLab URL and replaces the type part (blob, tree etc).\n *\n * @param url - The original URL\n * @param type - The desired type, e.g. 'blob', 'tree', 'edit'\n * @public\n */\nexport function replaceGitLabUrlType(\n url: string,\n type: 'blob' | 'tree' | 'edit',\n): string {\n return url.replace(/\\/\\-\\/(blob|tree|edit)\\//, `/-/${type}/`);\n}\n"],"names":["config","readGitLabIntegrationConfigs","basicIntegrations","defaultScmResolveUrl"],"mappings":";;;;;AA4BO,MAAM,iBAAA,CAA4C;AAAA,EAWvD,YAA6B,iBAAA,EAA4C;AAA5C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAAA,EAA6C;AAAA,EAV1E,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,EAIA,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,6BAAqB,OAAO,CAAA;AAAA,EACrC;AAAA,EAEA,eAAe,GAAA,EAAqB;AAClC,IAAA,OAAO,oBAAA,CAAqB,KAAK,MAAM,CAAA;AAAA,EACzC;AACF;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":"GitLabIntegration.esm.js","sources":["../../src/gitlab/GitLabIntegration.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport { ScmIntegration, ScmIntegrationsFactory } from '../types';\nimport {\n GitLabIntegrationConfig,\n readGitLabIntegrationConfigs,\n} from './config';\n\n/**\n * A GitLab based integration.\n *\n * @public\n */\nexport class GitLabIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<GitLabIntegration> = ({ config }) => {\n const configs = readGitLabIntegrationConfigs(\n config.getOptionalConfigArray('integrations.gitlab') ?? [],\n );\n return basicIntegrations(\n configs.map(c => new GitLabIntegration(c)),\n i => i.config.host,\n );\n };\n\n constructor(private readonly integrationConfig: GitLabIntegrationConfig) {}\n\n get type(): string {\n return 'gitlab';\n }\n\n get title(): string {\n return this.integrationConfig.host;\n }\n\n get config(): GitLabIntegrationConfig {\n return this.integrationConfig;\n }\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n }): string {\n return defaultScmResolveUrl(options);\n }\n\n resolveEditUrl(url: string): string {\n return replaceGitLabUrlType(url, 'edit');\n }\n}\n\n/**\n * Takes a GitLab URL and replaces the type part (blob, tree etc).\n *\n * @param url - The original URL\n * @param type - The desired type, e.g. 'blob', 'tree', 'edit'\n * @public\n */\nexport function replaceGitLabUrlType(\n url: string,\n type: 'blob' | 'tree' | 'edit',\n): string {\n return url.replace(/\\/\\-\\/(blob|tree|edit)\\//, `/-/${type}/`);\n}\n"],"names":[],"mappings":";;;AA4BO,MAAM,
|
|
1
|
+
{"version":3,"file":"GitLabIntegration.esm.js","sources":["../../src/gitlab/GitLabIntegration.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport { ScmIntegration, ScmIntegrationsFactory } from '../types';\nimport {\n GitLabIntegrationConfig,\n readGitLabIntegrationConfigs,\n} from './config';\n\n/**\n * A GitLab based integration.\n *\n * @public\n */\nexport class GitLabIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<GitLabIntegration> = ({ config }) => {\n const configs = readGitLabIntegrationConfigs(\n config.getOptionalConfigArray('integrations.gitlab') ?? [],\n );\n return basicIntegrations(\n configs.map(c => new GitLabIntegration(c)),\n i => i.config.host,\n );\n };\n\n constructor(private readonly integrationConfig: GitLabIntegrationConfig) {}\n\n get type(): string {\n return 'gitlab';\n }\n\n get title(): string {\n return this.integrationConfig.host;\n }\n\n get config(): GitLabIntegrationConfig {\n return this.integrationConfig;\n }\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n }): string {\n return defaultScmResolveUrl(options);\n }\n\n resolveEditUrl(url: string): string {\n return replaceGitLabUrlType(url, 'edit');\n }\n}\n\n/**\n * Takes a GitLab URL and replaces the type part (blob, tree etc).\n *\n * @param url - The original URL\n * @param type - The desired type, e.g. 'blob', 'tree', 'edit'\n * @public\n */\nexport function replaceGitLabUrlType(\n url: string,\n type: 'blob' | 'tree' | 'edit',\n): string {\n return url.replace(/\\/\\-\\/(blob|tree|edit)\\//, `/-/${type}/`);\n}\n"],"names":[],"mappings":";;;AA4BO,MAAM,iBAAA,CAA4C;AAAA,EAWvD,YAA6B,iBAAA,EAA4C;AAA5C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAAA,EAA6C;AAAA,EAV1E,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,EAIA,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,OAAO,qBAAqB,OAAO,CAAA;AAAA,EACrC;AAAA,EAEA,eAAe,GAAA,EAAqB;AAClC,IAAA,OAAO,oBAAA,CAAqB,KAAK,MAAM,CAAA;AAAA,EACzC;AACF;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,
|
|
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,EANtD,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,
|
|
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,EANtD,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 * 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/**\n * Reads a single GitLab integration config.\n *\n * @param config - The config object of a single integration\n * @public\n */\nexport function readGitLabIntegrationConfig(\n config: Config,\n): GitLabIntegrationConfig {\n const host = config.getString('host');\n let apiBaseUrl = config.getOptionalString('apiBaseUrl');\n const token = config.getOptionalString('token')?.trim();\n let baseUrl = config.getOptionalString('baseUrl');\n if (apiBaseUrl) {\n apiBaseUrl = trimEnd(apiBaseUrl, '/');\n } else if (host === GITLAB_HOST) {\n apiBaseUrl = GITLAB_API_BASE_URL;\n }\n\n if (baseUrl) {\n baseUrl = trimEnd(baseUrl, '/');\n } else {\n baseUrl = `https://${host}`;\n }\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid GitLab integration config, '${host}' is not a valid host`,\n );\n } else if (!apiBaseUrl || !isValidUrl(apiBaseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${apiBaseUrl}' is not a valid apiBaseUrl`,\n );\n } else if (!isValidUrl(baseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${baseUrl}' is not a valid baseUrl`,\n );\n }\n\n return {\n host,\n token,\n apiBaseUrl,\n baseUrl,\n commitSigningKey: config.getOptionalString('commitSigningKey'),\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,
|
|
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 * 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/**\n * Reads a single GitLab integration config.\n *\n * @param config - The config object of a single integration\n * @public\n */\nexport function readGitLabIntegrationConfig(\n config: Config,\n): GitLabIntegrationConfig {\n const host = config.getString('host');\n let apiBaseUrl = config.getOptionalString('apiBaseUrl');\n const token = config.getOptionalString('token')?.trim();\n let baseUrl = config.getOptionalString('baseUrl');\n if (apiBaseUrl) {\n apiBaseUrl = trimEnd(apiBaseUrl, '/');\n } else if (host === GITLAB_HOST) {\n apiBaseUrl = GITLAB_API_BASE_URL;\n }\n\n if (baseUrl) {\n baseUrl = trimEnd(baseUrl, '/');\n } else {\n baseUrl = `https://${host}`;\n }\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid GitLab integration config, '${host}' is not a valid host`,\n );\n } else if (!apiBaseUrl || !isValidUrl(apiBaseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${apiBaseUrl}' is not a valid apiBaseUrl`,\n );\n } else if (!isValidUrl(baseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${baseUrl}' is not a valid baseUrl`,\n );\n }\n\n return {\n host,\n token,\n apiBaseUrl,\n baseUrl,\n commitSigningKey: config.getOptionalString('commitSigningKey'),\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;AAgDrB,SAAS,4BACd,MAAA,EACyB;AACzB,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,SAAA,CAAU,MAAM,CAAA;AACpC,EAAA,IAAI,UAAA,GAAa,MAAA,CAAO,iBAAA,CAAkB,YAAY,CAAA;AACtD,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,iBAAA,CAAkB,OAAO,GAAG,IAAA,EAAK;AACtD,EAAA,IAAI,OAAA,GAAU,MAAA,CAAO,iBAAA,CAAkB,SAAS,CAAA;AAChD,EAAA,IAAI,UAAA,EAAY;AACd,IAAA,UAAA,GAAaA,cAAA,CAAQ,YAAY,GAAG,CAAA;AAAA,EACtC,CAAA,MAAA,IAAW,SAAS,WAAA,EAAa;AAC/B,IAAA,UAAA,GAAa,mBAAA;AAAA,EACf;AAEA,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,OAAA,GAAUA,cAAA,CAAQ,SAAS,GAAG,CAAA;AAAA,EAChC,CAAA,MAAO;AACL,IAAA,OAAA,GAAU,WAAW,IAAI,CAAA,CAAA;AAAA,EAC3B;AAEA,EAAA,IAAI,CAACC,mBAAA,CAAY,IAAI,CAAA,EAAG;AACtB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,uCAAuC,IAAI,CAAA,qBAAA;AAAA,KAC7C;AAAA,EACF,WAAW,CAAC,UAAA,IAAc,CAACC,kBAAA,CAAW,UAAU,CAAA,EAAG;AACjD,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,uCAAuC,UAAU,CAAA,2BAAA;AAAA,KACnD;AAAA,EACF,CAAA,MAAA,IAAW,CAACA,kBAAA,CAAW,OAAO,CAAA,EAAG;AAC/B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,uCAAuC,OAAO,CAAA,wBAAA;AAAA,KAChD;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,KAAA;AAAA,IACA,UAAA;AAAA,IACA,OAAA;AAAA,IACA,gBAAA,EAAkB,MAAA,CAAO,iBAAA,CAAkB,kBAAkB;AAAA,GAC/D;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,OAAOF,cAAA,CAAQ,cAAc,GAAG,CAAA;AAClC;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.esm.js","sources":["../../src/gitlab/config.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\nimport { trimEnd } from 'lodash';\nimport { isValidHost, isValidUrl } from '../helpers';\n\nconst GITLAB_HOST = 'gitlab.com';\nconst GITLAB_API_BASE_URL = 'https://gitlab.com/api/v4';\n\n/**\n * The configuration parameters for a single GitLab integration.\n *\n * @public\n */\nexport type GitLabIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. `gitlab.com`.\n */\n host: string;\n\n /**\n * The base URL of the API of this provider, e.g.\n * `https://gitlab.com/api/v4`, with no trailing slash.\n *\n * May be omitted specifically for public GitLab; then it will be deduced.\n */\n apiBaseUrl: string;\n\n /**\n * The authorization token to use for requests to this provider.\n *\n * If no token is specified, anonymous access is used.\n */\n token?: string;\n\n /**\n * The baseUrl of this provider, e.g. `https://gitlab.com`, which is passed\n * into the GitLab client.\n *\n * If no baseUrl is provided, it will default to `https://${host}`\n */\n baseUrl: string;\n\n /**\n * Signing key to sign commits\n */\n commitSigningKey?: string;\n};\n\n/**\n * Reads a single GitLab integration config.\n *\n * @param config - The config object of a single integration\n * @public\n */\nexport function readGitLabIntegrationConfig(\n config: Config,\n): GitLabIntegrationConfig {\n const host = config.getString('host');\n let apiBaseUrl = config.getOptionalString('apiBaseUrl');\n const token = config.getOptionalString('token')?.trim();\n let baseUrl = config.getOptionalString('baseUrl');\n if (apiBaseUrl) {\n apiBaseUrl = trimEnd(apiBaseUrl, '/');\n } else if (host === GITLAB_HOST) {\n apiBaseUrl = GITLAB_API_BASE_URL;\n }\n\n if (baseUrl) {\n baseUrl = trimEnd(baseUrl, '/');\n } else {\n baseUrl = `https://${host}`;\n }\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid GitLab integration config, '${host}' is not a valid host`,\n );\n } else if (!apiBaseUrl || !isValidUrl(apiBaseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${apiBaseUrl}' is not a valid apiBaseUrl`,\n );\n } else if (!isValidUrl(baseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${baseUrl}' is not a valid baseUrl`,\n );\n }\n\n return {\n host,\n token,\n apiBaseUrl,\n baseUrl,\n commitSigningKey: config.getOptionalString('commitSigningKey'),\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,
|
|
1
|
+
{"version":3,"file":"config.esm.js","sources":["../../src/gitlab/config.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\nimport { trimEnd } from 'lodash';\nimport { isValidHost, isValidUrl } from '../helpers';\n\nconst GITLAB_HOST = 'gitlab.com';\nconst GITLAB_API_BASE_URL = 'https://gitlab.com/api/v4';\n\n/**\n * The configuration parameters for a single GitLab integration.\n *\n * @public\n */\nexport type GitLabIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. `gitlab.com`.\n */\n host: string;\n\n /**\n * The base URL of the API of this provider, e.g.\n * `https://gitlab.com/api/v4`, with no trailing slash.\n *\n * May be omitted specifically for public GitLab; then it will be deduced.\n */\n apiBaseUrl: string;\n\n /**\n * The authorization token to use for requests to this provider.\n *\n * If no token is specified, anonymous access is used.\n */\n token?: string;\n\n /**\n * The baseUrl of this provider, e.g. `https://gitlab.com`, which is passed\n * into the GitLab client.\n *\n * If no baseUrl is provided, it will default to `https://${host}`\n */\n baseUrl: string;\n\n /**\n * Signing key to sign commits\n */\n commitSigningKey?: string;\n};\n\n/**\n * Reads a single GitLab integration config.\n *\n * @param config - The config object of a single integration\n * @public\n */\nexport function readGitLabIntegrationConfig(\n config: Config,\n): GitLabIntegrationConfig {\n const host = config.getString('host');\n let apiBaseUrl = config.getOptionalString('apiBaseUrl');\n const token = config.getOptionalString('token')?.trim();\n let baseUrl = config.getOptionalString('baseUrl');\n if (apiBaseUrl) {\n apiBaseUrl = trimEnd(apiBaseUrl, '/');\n } else if (host === GITLAB_HOST) {\n apiBaseUrl = GITLAB_API_BASE_URL;\n }\n\n if (baseUrl) {\n baseUrl = trimEnd(baseUrl, '/');\n } else {\n baseUrl = `https://${host}`;\n }\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid GitLab integration config, '${host}' is not a valid host`,\n );\n } else if (!apiBaseUrl || !isValidUrl(apiBaseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${apiBaseUrl}' is not a valid apiBaseUrl`,\n );\n } else if (!isValidUrl(baseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${baseUrl}' is not a valid baseUrl`,\n );\n }\n\n return {\n host,\n token,\n apiBaseUrl,\n baseUrl,\n commitSigningKey: config.getOptionalString('commitSigningKey'),\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;AAgDrB,SAAS,4BACd,MAAA,EACyB;AACzB,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,SAAA,CAAU,MAAM,CAAA;AACpC,EAAA,IAAI,UAAA,GAAa,MAAA,CAAO,iBAAA,CAAkB,YAAY,CAAA;AACtD,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,iBAAA,CAAkB,OAAO,GAAG,IAAA,EAAK;AACtD,EAAA,IAAI,OAAA,GAAU,MAAA,CAAO,iBAAA,CAAkB,SAAS,CAAA;AAChD,EAAA,IAAI,UAAA,EAAY;AACd,IAAA,UAAA,GAAa,OAAA,CAAQ,YAAY,GAAG,CAAA;AAAA,EACtC,CAAA,MAAA,IAAW,SAAS,WAAA,EAAa;AAC/B,IAAA,UAAA,GAAa,mBAAA;AAAA,EACf;AAEA,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,OAAA,GAAU,OAAA,CAAQ,SAAS,GAAG,CAAA;AAAA,EAChC,CAA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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 fetch from 'cross-fetch';\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/projectId/repository/c.yaml?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/projectId/repository/files/filepath?ref=branch\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport async function getGitLabFileFetchUrl(\n url: string,\n config: GitLabIntegrationConfig,\n token?: string,\n): Promise<string> {\n const projectID = await getProjectId(url, config, token);\n return buildProjectUrl(url, projectID, 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/projectId/repository/files/filepath?ref=branch\nexport function buildProjectUrl(\n target: string,\n projectID: 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 url.pathname = [\n ...(relativePath ? [relativePath] : []),\n 'api/v4/projects',\n projectID,\n 'repository/files',\n encodeURIComponent(decodeURIComponent(filePath.join('/'))),\n 'raw',\n ].join('/');\n\n url.search = `?ref=${branch}`;\n\n return url;\n } catch (e) {\n throw new Error(`Incorrect url: ${target}, ${e}`);\n }\n}\n\n// Convert\n// from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n// to: The project ID that corresponds to the URL\nexport async function getProjectId(\n target: string,\n config: GitLabIntegrationConfig,\n token?: string,\n): Promise<number> {\n const url = new URL(target);\n\n if (!url.pathname.includes('/blob/')) {\n throw new Error(\n `Failed converting ${url.pathname} to a project id. Url path must include /blob/.`,\n );\n }\n\n try {\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 exist and replace it if it's the case.\n if (relativePath) {\n repo = repo.replace(relativePath, '');\n }\n\n // Convert\n // to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FsubgroupA%2FteamA%2Frepo\n const repoIDLookup = new URL(\n `${url.origin}${relativePath}/api/v4/projects/${encodeURIComponent(\n repo.replace(/^\\//, ''),\n )}`,\n );\n\n const response = await fetch(\n repoIDLookup.toString(),\n getGitLabRequestOptions(config, token),\n );\n\n const data = await response.json();\n\n if (!response.ok) {\n if (response.status === 401) {\n throw new Error(\n 'GitLab Error: 401 - Unauthorized. The access token used is either expired, or does not have permission to read the project',\n );\n }\n\n throw new Error(\n `GitLab Error '${data.error}', ${data.error_description}`,\n );\n }\n\n return Number(data.id);\n } catch (e) {\n throw new Error(`Could not get GitLab project ID for: ${target}, ${e}`);\n }\n}\n"],"names":["config","getGitLabIntegrationRelativePath","fetch"],"mappings":";;;;;;;;;
|
|
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 fetch from 'cross-fetch';\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/projectId/repository/c.yaml?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/projectId/repository/files/filepath?ref=branch\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport async function getGitLabFileFetchUrl(\n url: string,\n config: GitLabIntegrationConfig,\n token?: string,\n): Promise<string> {\n const projectID = await getProjectId(url, config, token);\n return buildProjectUrl(url, projectID, 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/projectId/repository/files/filepath?ref=branch\nexport function buildProjectUrl(\n target: string,\n projectID: 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 url.pathname = [\n ...(relativePath ? [relativePath] : []),\n 'api/v4/projects',\n projectID,\n 'repository/files',\n encodeURIComponent(decodeURIComponent(filePath.join('/'))),\n 'raw',\n ].join('/');\n\n url.search = `?ref=${branch}`;\n\n return url;\n } catch (e) {\n throw new Error(`Incorrect url: ${target}, ${e}`);\n }\n}\n\n// Convert\n// from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n// to: The project ID that corresponds to the URL\nexport async function getProjectId(\n target: string,\n config: GitLabIntegrationConfig,\n token?: string,\n): Promise<number> {\n const url = new URL(target);\n\n if (!url.pathname.includes('/blob/')) {\n throw new Error(\n `Failed converting ${url.pathname} to a project id. Url path must include /blob/.`,\n );\n }\n\n try {\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 exist and replace it if it's the case.\n if (relativePath) {\n repo = repo.replace(relativePath, '');\n }\n\n // Convert\n // to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FsubgroupA%2FteamA%2Frepo\n const repoIDLookup = new URL(\n `${url.origin}${relativePath}/api/v4/projects/${encodeURIComponent(\n repo.replace(/^\\//, ''),\n )}`,\n );\n\n const response = await fetch(\n repoIDLookup.toString(),\n getGitLabRequestOptions(config, token),\n );\n\n const data = await response.json();\n\n if (!response.ok) {\n if (response.status === 401) {\n throw new Error(\n 'GitLab Error: 401 - Unauthorized. The access token used is either expired, or does not have permission to read the project',\n );\n }\n\n throw new Error(\n `GitLab Error '${data.error}', ${data.error_description}`,\n );\n }\n\n return Number(data.id);\n } catch (e) {\n throw new Error(`Could not get GitLab project ID for: ${target}, ${e}`);\n }\n}\n"],"names":["config","getGitLabIntegrationRelativePath","fetch"],"mappings":";;;;;;;;;AAuCA,eAAsB,qBAAA,CACpB,GAAA,EACA,MAAA,EACA,KAAA,EACiB;AACjB,EAAA,MAAM,SAAA,GAAY,MAAM,YAAA,CAAa,GAAA,EAAK,QAAQ,KAAK,CAAA;AACvD,EAAA,OAAO,eAAA,CAAgB,GAAA,EAAK,SAAA,EAAW,MAAM,EAAE,QAAA,EAAS;AAC1D;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;AAKO,SAAS,eAAA,CACd,MAAA,EACA,SAAA,EACAA,QAAA,EACK;AACL,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,MAAM,CAAA;AAE1B,IAAA,MAAM,iBAAA,GAAoB,GAAA,CA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IAAA,MAAM,YAAA,GAAeC,wCAAiCD,QAAM,CAAA;AAG5D,IAAA,IAAI,YAAA,EAAc;AAChB,MAAA,IAAA,GAAO,IAAA,CAAK,OAAA,CAAQ,YAAA,EAAc,EAAE,CAAA;AAAA,IACtC;AAIA,IAAA,MAAM,eAAe,IAAI,GAAA;AAAA,MACvB,CAAA,EAAG,GAAA,CAAI,MAAM,CAAA,EAAG,YAAY,CAAA,iBAAA,EAAoB,kBAAA;AAAA,QAC9C,IAAA,CAAK,OAAA,CAAQ,KAAA,EAAO,EAAE;AAAA,OACvB,CAAA;AAAA,KACH;AAEA,IAAA,MAAM,WAAW,MAAME,sBAAA;AAAA,MACrB,aAAa,QAAA,EAAS;AAAA,MACtB,uBAAA,CAAwBF,UAAQ,KAAK;AAAA,KACvC;AAEA,IAAA,MAAM,IAAA,GAAO,MAAM,QAAA,CAAS,IAAA,EAAK;AAEjC,IAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,MAAA,IAAI,QAAA,CAAS,WAAW,GAAA,EAAK;AAC3B,QAAA,MAAM,IAAI,KAAA;AAAA,UACR;AAAA,SACF;AAAA,MACF;AAEA,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,cAAA,EAAiB,IAAA,CAAK,KAAK,CAAA,GAAA,EAAM,KAAK,iBAAiB,CAAA;AAAA,OACzD;AAAA,IACF;AAEA,IAAA,OAAO,MAAA,CAAO,KAAK,EAAE,CAAA;AAAA,EACvB,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,qCAAA,EAAwC,MAAM,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EACxE;AACF;;;;;;;"}
|
|
@@ -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 fetch from 'cross-fetch';\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/projectId/repository/c.yaml?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/projectId/repository/files/filepath?ref=branch\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport async function getGitLabFileFetchUrl(\n url: string,\n config: GitLabIntegrationConfig,\n token?: string,\n): Promise<string> {\n const projectID = await getProjectId(url, config, token);\n return buildProjectUrl(url, projectID, 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/projectId/repository/files/filepath?ref=branch\nexport function buildProjectUrl(\n target: string,\n projectID: 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 url.pathname = [\n ...(relativePath ? [relativePath] : []),\n 'api/v4/projects',\n projectID,\n 'repository/files',\n encodeURIComponent(decodeURIComponent(filePath.join('/'))),\n 'raw',\n ].join('/');\n\n url.search = `?ref=${branch}`;\n\n return url;\n } catch (e) {\n throw new Error(`Incorrect url: ${target}, ${e}`);\n }\n}\n\n// Convert\n// from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n// to: The project ID that corresponds to the URL\nexport async function getProjectId(\n target: string,\n config: GitLabIntegrationConfig,\n token?: string,\n): Promise<number> {\n const url = new URL(target);\n\n if (!url.pathname.includes('/blob/')) {\n throw new Error(\n `Failed converting ${url.pathname} to a project id. Url path must include /blob/.`,\n );\n }\n\n try {\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 exist and replace it if it's the case.\n if (relativePath) {\n repo = repo.replace(relativePath, '');\n }\n\n // Convert\n // to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FsubgroupA%2FteamA%2Frepo\n const repoIDLookup = new URL(\n `${url.origin}${relativePath}/api/v4/projects/${encodeURIComponent(\n repo.replace(/^\\//, ''),\n )}`,\n );\n\n const response = await fetch(\n repoIDLookup.toString(),\n getGitLabRequestOptions(config, token),\n );\n\n const data = await response.json();\n\n if (!response.ok) {\n if (response.status === 401) {\n throw new Error(\n 'GitLab Error: 401 - Unauthorized. The access token used is either expired, or does not have permission to read the project',\n );\n }\n\n throw new Error(\n `GitLab Error '${data.error}', ${data.error_description}`,\n );\n }\n\n return Number(data.id);\n } catch (e) {\n throw new Error(`Could not get GitLab project ID for: ${target}, ${e}`);\n }\n}\n"],"names":[],"mappings":";;;
|
|
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 fetch from 'cross-fetch';\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/projectId/repository/c.yaml?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/projectId/repository/files/filepath?ref=branch\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport async function getGitLabFileFetchUrl(\n url: string,\n config: GitLabIntegrationConfig,\n token?: string,\n): Promise<string> {\n const projectID = await getProjectId(url, config, token);\n return buildProjectUrl(url, projectID, 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/projectId/repository/files/filepath?ref=branch\nexport function buildProjectUrl(\n target: string,\n projectID: 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 url.pathname = [\n ...(relativePath ? [relativePath] : []),\n 'api/v4/projects',\n projectID,\n 'repository/files',\n encodeURIComponent(decodeURIComponent(filePath.join('/'))),\n 'raw',\n ].join('/');\n\n url.search = `?ref=${branch}`;\n\n return url;\n } catch (e) {\n throw new Error(`Incorrect url: ${target}, ${e}`);\n }\n}\n\n// Convert\n// from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n// to: The project ID that corresponds to the URL\nexport async function getProjectId(\n target: string,\n config: GitLabIntegrationConfig,\n token?: string,\n): Promise<number> {\n const url = new URL(target);\n\n if (!url.pathname.includes('/blob/')) {\n throw new Error(\n `Failed converting ${url.pathname} to a project id. Url path must include /blob/.`,\n );\n }\n\n try {\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 exist and replace it if it's the case.\n if (relativePath) {\n repo = repo.replace(relativePath, '');\n }\n\n // Convert\n // to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FsubgroupA%2FteamA%2Frepo\n const repoIDLookup = new URL(\n `${url.origin}${relativePath}/api/v4/projects/${encodeURIComponent(\n repo.replace(/^\\//, ''),\n )}`,\n );\n\n const response = await fetch(\n repoIDLookup.toString(),\n getGitLabRequestOptions(config, token),\n );\n\n const data = await response.json();\n\n if (!response.ok) {\n if (response.status === 401) {\n throw new Error(\n 'GitLab Error: 401 - Unauthorized. The access token used is either expired, or does not have permission to read the project',\n );\n }\n\n throw new Error(\n `GitLab Error '${data.error}', ${data.error_description}`,\n );\n }\n\n return Number(data.id);\n } catch (e) {\n throw new Error(`Could not get GitLab project ID for: ${target}, ${e}`);\n }\n}\n"],"names":[],"mappings":";;;AAuCA,eAAsB,qBAAA,CACpB,GAAA,EACA,MAAA,EACA,KAAA,EACiB;AACjB,EAAA,MAAM,SAAA,GAAY,MAAM,YAAA,CAAa,GAAA,EAAK,QAAQ,KAAK,CAAA;AACvD,EAAA,OAAO,eAAA,CAAgB,GAAA,EAAK,SAAA,EAAW,MAAM,EAAE,QAAA,EAAS;AAC1D;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;AAKO,SAAS,eAAA,CACd,MAAA,EACA,SAAA,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,GAAA,CAAI,QAAA,GAAW;AAAA,MACb,GAAI,YAAA,GAAe,CAAC,YAAY,IAAI,EAAC;AAAA,MACrC,iBAAA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,CAAA;AAAA,KACH;AAEA,IAAA,MAAM,WAAW,MAAM,KAAA;AAAA,MACrB,aAAa,QAAA,EAAS;AAAA,MACtB,uBAAA,CAAwB,QAAQ,KAAK;AAAA,KACvC;AAEA,IAAA,MAAM,IAAA,GAAO,MAAM,QAAA,CAAS,IAAA,EAAK;AAEjC,IAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,MAAA,IAAI,QAAA,CAAS,WAAW,GAAA,EAAK;AAC3B,QAAA,MAAM,IAAI,KAAA;AAAA,UACR;AAAA,SACF;AAAA,MACF;AAEA,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,cAAA,EAAiB,IAAA,CAAK,KAAK,CAAA,GAAA,EAAM,KAAK,iBAAiB,CAAA;AAAA,OACzD;AAAA,IACF;AAEA,IAAA,OAAO,MAAA,CAAO,KAAK,EAAE,CAAA;AAAA,EACvB,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,qCAAA,EAAwC,MAAM,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EACxE;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 configuration parameters for a single Google Cloud Storage provider.\n *\n * @public\n */\nexport type GoogleGcsIntegrationConfig = {\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 {};\n }\n\n if (!config.has('clientEmail') && !config.has('privateKey')) {\n return {};\n }\n\n const privateKey = config.getString('privateKey').split('\\\\n').join('\\n');\n\n const clientEmail = config.getString('clientEmail');\n return { clientEmail: clientEmail, privateKey: privateKey };\n}\n"],"names":[],"mappings":";;AAwCO,SAAS,+BACd,
|
|
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 configuration parameters for a single Google Cloud Storage provider.\n *\n * @public\n */\nexport type GoogleGcsIntegrationConfig = {\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 {};\n }\n\n if (!config.has('clientEmail') && !config.has('privateKey')) {\n return {};\n }\n\n const privateKey = config.getString('privateKey').split('\\\\n').join('\\n');\n\n const clientEmail = config.getString('clientEmail');\n return { clientEmail: clientEmail, privateKey: privateKey };\n}\n"],"names":[],"mappings":";;AAwCO,SAAS,+BACd,MAAA,EAC4B;AAC5B,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,IAAI,CAAC,OAAO,GAAA,CAAI,aAAa,KAAK,CAAC,MAAA,CAAO,GAAA,CAAI,YAAY,CAAA,EAAG;AAC3D,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,MAAM,UAAA,GAAa,OAAO,SAAA,CAAU,YAAY,EAAE,KAAA,CAAM,KAAK,CAAA,CAAE,IAAA,CAAK,IAAI,CAAA;AAExE,EAAA,MAAM,WAAA,GAAc,MAAA,CAAO,SAAA,CAAU,aAAa,CAAA;AAClD,EAAA,OAAO,EAAE,aAA0B,UAAA,EAAuB;AAC5D;;;;"}
|
|
@@ -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 configuration parameters for a single Google Cloud Storage provider.\n *\n * @public\n */\nexport type GoogleGcsIntegrationConfig = {\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 {};\n }\n\n if (!config.has('clientEmail') && !config.has('privateKey')) {\n return {};\n }\n\n const privateKey = config.getString('privateKey').split('\\\\n').join('\\n');\n\n const clientEmail = config.getString('clientEmail');\n return { clientEmail: clientEmail, privateKey: privateKey };\n}\n"],"names":[],"mappings":"AAwCO,SAAS,+BACd,
|
|
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 configuration parameters for a single Google Cloud Storage provider.\n *\n * @public\n */\nexport type GoogleGcsIntegrationConfig = {\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 {};\n }\n\n if (!config.has('clientEmail') && !config.has('privateKey')) {\n return {};\n }\n\n const privateKey = config.getString('privateKey').split('\\\\n').join('\\n');\n\n const clientEmail = config.getString('clientEmail');\n return { clientEmail: clientEmail, privateKey: privateKey };\n}\n"],"names":[],"mappings":"AAwCO,SAAS,+BACd,MAAA,EAC4B;AAC5B,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,IAAI,CAAC,OAAO,GAAA,CAAI,aAAa,KAAK,CAAC,MAAA,CAAO,GAAA,CAAI,YAAY,CAAA,EAAG;AAC3D,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,MAAM,UAAA,GAAa,OAAO,SAAA,CAAU,YAAY,EAAE,KAAA,CAAM,KAAK,CAAA,CAAE,IAAA,CAAK,IAAI,CAAA;AAExE,EAAA,MAAM,WAAA,GAAc,MAAA,CAAO,SAAA,CAAU,aAAa,CAAA;AAClD,EAAA,OAAO,EAAE,aAA0B,UAAA,EAAuB;AAC5D;;;;"}
|
|
@@ -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,
|
|
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,EAVxD,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;;;;"}
|
|
@@ -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,
|
|
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 +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,
|
|
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,
|
|
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+BgB,SAAA,yBAAA,CACd,QACA,GACA,EAAA;AACA,EAAM,MAAA,SAAA,GAAY,eAAgB,CAAA,MAAA,EAAQ,GAAG,CAAA;AAE7C,EAAA,OAAO,CAAG,EAAA,SAAA,CAAU,OAAO,CAAA,YAAA,EAAe,UAAU,SAAS,CAAA,YAAA,EAC3D,SAAU,CAAA,OAAA,KAAY,EAAK,GAAA,CAAA,MAAA,EAAS,SAAU,CAAA,OAAO,KAAK,EAC5D,CAAA,EACE,SAAU,CAAA,WAAA,KAAgB,EAAK,GAAA,CAAA,UAAA,EAAa,SAAU,CAAA,WAAW,KAAK,EACxE,CAAA,OAAA,EAAU,SAAU,CAAA,QAAQ,CAAU,OAAA,EAAA,SAAA,CAAU,MAAM,CAAA,GAAA,EAAM,UAAU,IAAI,CAAA,CAAA;AAC5E;AAgBgB,SAAA,yBAAA,CACd,QACA,GACA,EAAA;AACA,EAAM,MAAA,SAAA,GAAY,eAAgB,CAAA,MAAA,EAAQ,GAAG,CAAA;AAE7C,EAAA,IAAI,iBAAiB,CAAG,EAAA,SAAA,CAAU,OAAO,CAAA,2BAAA,EAA8B,UAAU,SAAS,CAAA,CAAA;AAE1F,EAAA,IAAI,UAAU,OAAS,EAAA;AACrB,IAAkB,cAAA,IAAA,CAAA,CAAA,EAAI,UAAU,OAAO,CAAA,CAAA;AAAA;AAGzC,EAAA,IAAI,UAAU,WAAa,EAAA;AACzB,IAA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Y,UAAW,CAAA,KAAA,CAAM,GAAG,QAAQ,CAAA,CAAE,KAAK,GAAG,CAAA;AAAA,MAClD,MACE,EAAA,QAAA,KAAa,CACT,CAAA,GAAA,UAAA,CAAW,KAAM,CAAA,CAAA,EAAG,QAAQ,CAAA,CAAE,IAAK,CAAA,GAAG,CACtC,GAAA,UAAA,CAAW,KAAK,GAAG;AAAA,KAC3B;AAAA,WACO,CAAG,EAAA;AACV,IAAA,MAAM,IAAI,KAAM,CAAA,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAE,CAAA,CAAA;AAAA;AAEjD;;;;;;;;;"}
|
|
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,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|
|
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+BgB,SAAA,yBAAA,CACd,QACA,GACA,EAAA;AACA,EAAM,MAAA,SAAA,GAAY,eAAgB,CAAA,MAAA,EAAQ,GAAG,CAAA;AAE7C,EAAA,OAAO,CAAG,EAAA,SAAA,CAAU,OAAO,CAAA,YAAA,EAAe,UAAU,SAAS,CAAA,YAAA,EAC3D,SAAU,CAAA,OAAA,KAAY,EAAK,GAAA,CAAA,MAAA,EAAS,SAAU,CAAA,OAAO,KAAK,EAC5D,CAAA,EACE,SAAU,CAAA,WAAA,KAAgB,EAAK,GAAA,CAAA,UAAA,EAAa,SAAU,CAAA,WAAW,KAAK,EACxE,CAAA,OAAA,EAAU,SAAU,CAAA,QAAQ,CAAU,OAAA,EAAA,SAAA,CAAU,MAAM,CAAA,GAAA,EAAM,UAAU,IAAI,CAAA,CAAA;AAC5E;A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,KAAK,GAAG,CAAA;AACxD,IAAA,MAAM,gBACJ,GAAA,QAAA,KAAa,CACT,CAAA,GAAA,UAAA,CACG,MAAM,QAAW,GAAA,CAAC,CAClB,CAAA,IAAA,CAAK,GAAG,CAAA,CACR,OAAQ,CAAA,KAAA,EAAO,EAAE,CACpB,GAAA,EAAA;AAEN,IAAO,OAAA;AAAA,MACL,OAAA;AAAA,MACA,SAAA;AAAA,MACA,OAAA;AAAA,MACA,WAAA;AAAA,MACA,SAAA;AAAA,MACA,IAAM,EAAA,gBAAA;AAAA,MACN,QAAA;AAAA,MACA,YAAY,UAAW,CAAA,KAAA,CAAM,GAAG,QAAQ,CAAA,CAAE,KAAK,GAAG,CAAA;AAAA,MAClD,MACE,EAAA,QAAA,KAAa,CACT,CAAA,GAAA,UAAA,CAAW,KAAM,CAAA,CAAA,EAAG,QAAQ,CAAA,CAAE,IAAK,CAAA,GAAG,CACtC,GAAA,UAAA,CAAW,KAAK,GAAG;AAAA,KAC3B;AAAA,WACO,CAAG,EAAA;AACV,IAAA,MAAM,IAAI,KAAM,CAAA,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAE,CAAA,CAAA;AAAA;AAEjD;;;;"}
|
|
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,CAAA,CAAA,EAAI,UAAU,OAAO,CAAA,CAAA;AAAA,EACzC;AAEA,EAAA,IAAI,UAAU,WAAA,EAAa;AACzB,IAAA,cAAA,IAAkB,CAAA,CAAA,EAAI,UAAU,WAAW,CAAA,CAAA;AAAA,EAC7C;AAEA,EAAA,cAAA,IAAkB,CAAA,C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;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;;;;"}
|
package/dist/helpers.cjs.js.map
CHANGED
|
@@ -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/** 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 } = parseGitUrl(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\n/**\n * Sets up handlers for request mocking\n *\n * Copied from test-utils, as that is a frontend-only package\n *\n * @param worker - service worker\n */\nexport function registerMswTestHooks(worker: {\n listen: (t: any) => void;\n close: () => void;\n resetHandlers: () => void;\n}) {\n beforeAll(() => worker.listen({ onUnhandledRequest: 'error' }));\n afterAll(() => worker.close());\n afterEach(() => worker.resetHandlers());\n}\n"],"names":["parseGitUrl","trimEnd"],"mappings":";;;;;;;;;AAqBO,SAAS,YAAY,
|
|
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/** 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 } = parseGitUrl(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\n/**\n * Sets up handlers for request mocking\n *\n * Copied from test-utils, as that is a frontend-only package\n *\n * @param worker - service worker\n */\nexport function registerMswTestHooks(worker: {\n listen: (t: any) => void;\n close: () => void;\n resetHandlers: () => void;\n}) {\n beforeAll(() => worker.listen({ onUnhandledRequest: 'error' }));\n afterAll(() => worker.close());\n afterEach(() => worker.resetHandlers());\n}\n"],"names":["parseGitUrl","trimEnd"],"mappings":";;;;;;;;;AAqBO,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,EAAkC;AACtC,MAAA,IAAI;AACF,QAAA,MAAM,SAAS,OAAO,GAAA,KAAQ,WAAW,IAAI,GAAA,CAAI,GAAG,CAAA,GAAI,GAAA;AACxD,QAAA,OAAO,aAAa,IAAA,CAAK,CAAA,CAAA,KAAK,QAAQ,CAAC,CAAA,KAAM,OAAO,IAAI,CAAA;AAAA,MAC1D,CAAA,CAAA,MAAQ;AACN,QAAA,OAAO,MAAA;AAAA,MACT;AAAA,IACF,CAAA;AAAA,IACA,OAAO,IAAA,EAA6B;AAClC,MAAA,OAAO,aAAa,IAAA,CAAK,CAAA,CAAA,KAAK,OAAA,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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 parseGitUrl from 'git-url-parse';\nimport { trimEnd } from 'lodash';\nimport { ScmIntegration, ScmIntegrationsGroup } from './types';\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 } = parseGitUrl(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\n/**\n * Sets up handlers for request mocking\n *\n * Copied from test-utils, as that is a frontend-only package\n *\n * @param worker - service worker\n */\nexport function registerMswTestHooks(worker: {\n listen: (t: any) => void;\n close: () => void;\n resetHandlers: () => void;\n}) {\n beforeAll(() => worker.listen({ onUnhandledRequest: 'error' }));\n afterAll(() => worker.close());\n afterEach(() => worker.resetHandlers());\n}\n"],"names":[],"mappings":";;;AAqBO,SAAS,YAAY,
|
|
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/** 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 } = parseGitUrl(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\n/**\n * Sets up handlers for request mocking\n *\n * Copied from test-utils, as that is a frontend-only package\n *\n * @param worker - service worker\n */\nexport function registerMswTestHooks(worker: {\n listen: (t: any) => void;\n close: () => void;\n resetHandlers: () => void;\n}) {\n beforeAll(() => worker.listen({ onUnhandledRequest: 'error' }));\n afterAll(() => worker.close());\n afterEach(() => worker.resetHandlers());\n}\n"],"names":[],"mappings":";;;AAqBO,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,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AAA,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;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1759,7 +1759,7 @@ declare class DefaultGithubCredentialsProvider implements GithubCredentialsProvi
|
|
|
1759
1759
|
*/
|
|
1760
1760
|
declare class GithubAppCredentialsMux {
|
|
1761
1761
|
private readonly apps;
|
|
1762
|
-
constructor(config: GithubIntegrationConfig);
|
|
1762
|
+
constructor(config: GithubIntegrationConfig, appIds?: number[]);
|
|
1763
1763
|
getAllInstallations(): Promise<RestEndpointMethodTypes['apps']['listInstallations']['response']['data']>;
|
|
1764
1764
|
getAppToken(owner: string, repo?: string): Promise<string | undefined>;
|
|
1765
1765
|
}
|