@backstage/integration 1.16.4-next.0 → 1.16.4-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @backstage/integration
2
2
 
3
+ ## 1.16.4-next.1
4
+
5
+ ### Patch Changes
6
+
7
+ - acea1d4: update documentation
8
+ - Updated dependencies
9
+ - @backstage/config@1.3.2
10
+ - @backstage/errors@1.2.7
11
+
3
12
  ## 1.16.4-next.0
4
13
 
5
14
  ### Patch Changes
@@ -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): Promise<string> {\n const projectID = await getProjectId(url, config);\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 * @public\n */\nexport function getGitLabRequestOptions(\n config: GitLabIntegrationConfig,\n token?: string,\n): { headers: Record<string, string> } {\n if (token) {\n // If token comes from the user and starts with \"gl\", it's a private token (see https://docs.gitlab.com/ee/security/token_overview.html#token-prefixes)\n return {\n headers: token.startsWith('gl')\n ? { 'PRIVATE-TOKEN': token }\n : { Authorization: `Bearer ${token}` }, // Otherwise, it's a bearer token\n };\n }\n\n // If token not provided, fetch the integration token\n const { token: configToken = '' } = config;\n return {\n headers: { 'PRIVATE-TOKEN': configToken },\n };\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): 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),\n );\n\n const data = await response.json();\n\n if (!response.ok) {\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":";;;;;;;;;AAuCsB,eAAA,qBAAA,CACpB,KACA,MACiB,EAAA;AACjB,EAAA,MAAM,SAAY,GAAA,MAAM,YAAa,CAAA,GAAA,EAAK,MAAM,CAAA;AAChD,EAAA,OAAO,eAAgB,CAAA,GAAA,EAAK,SAAW,EAAA,MAAM,EAAE,QAAS,EAAA;AAC1D;AAQgB,SAAA,uBAAA,CACd,QACA,KACqC,EAAA;AACrC,EAAA,IAAI,KAAO,EAAA;AAET,IAAO,OAAA;AAAA,MACL,OAAS,EAAA,KAAA,CAAM,UAAW,CAAA,IAAI,CAC1B,GAAA,EAAE,eAAiB,EAAA,KAAA,EACnB,GAAA,EAAE,aAAe,EAAA,CAAA,OAAA,EAAU,KAAK,CAAG,CAAA;AAAA;AAAA,KACzC;AAAA;AAIF,EAAA,MAAM,EAAE,KAAA,EAAO,WAAc,GAAA,EAAA,EAAO,GAAA,MAAA;AACpC,EAAO,OAAA;AAAA,IACL,OAAA,EAAS,EAAE,eAAA,EAAiB,WAAY;AAAA,GAC1C;AACF;AAKgB,SAAA,eAAA,CACd,MACA,EAAA,SAAA,EACAA,QACK,EAAA;AACL,EAAI,IAAA;AACF,IAAM,MAAA,GAAA,GA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CAAM,QAAQ,CAAA,CAAE,CAAC,CAAA;AAG9D,IAAM,MAAA,YAAA,GAAeC,wCAAiCD,QAAM,CAAA;AAG5D,IAAA,IAAI,YAAc,EAAA;AAChB,MAAO,IAAA,GAAA,IAAA,CAAK,OAAQ,CAAA,YAAA,EAAc,EAAE,CAAA;AAAA;AAKtC,IAAA,MAAM,eAAe,IAAI,GAAA;AAAA,MACvB,CAAG,EAAA,GAAA,CAAI,MAAM,CAAA,EAAG,YAAY,CAAoB,iBAAA,EAAA,kBAAA;AAAA,QAC9C,IAAA,CAAK,OAAQ,CAAA,KAAA,EAAO,EAAE;AAAA,OACvB,CAAA;AAAA,KACH;AAEA,IAAA,MAAM,WAAW,MAAME,sBAAA;AAAA,MACrB,aAAa,QAAS,EAAA;AAAA,MACtB,wBAAwBF,QAAM;AAAA,KAChC;AAEA,IAAM,MAAA,IAAA,GAAO,MAAM,QAAA,CAAS,IAAK,EAAA;AAEjC,IAAI,IAAA,CAAC,SAAS,EAAI,EAAA;AAChB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAiB,cAAA,EAAA,IAAA,CAAK,KAAK,CAAA,GAAA,EAAM,KAAK,iBAAiB,CAAA;AAAA,OACzD;AAAA;AAGF,IAAO,OAAA,MAAA,CAAO,KAAK,EAAE,CAAA;AAAA,WACd,CAAG,EAAA;AACV,IAAA,MAAM,IAAI,KAAM,CAAA,CAAA,qCAAA,EAAwC,MAAM,CAAA,EAAA,EAAK,CAAC,CAAE,CAAA,CAAA;AAAA;AAE1E;;;;;;;"}
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): Promise<string> {\n const projectID = await getProjectId(url, config);\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 if (token) {\n // If token comes from the user and starts with \"gl\", it's a private token (see https://docs.gitlab.com/ee/security/token_overview.html#token-prefixes)\n return {\n headers: token.startsWith('gl')\n ? { 'PRIVATE-TOKEN': token }\n : { Authorization: `Bearer ${token}` }, // Otherwise, it's a bearer token\n };\n }\n\n // If token not provided, fetch the integration token\n const { token: configToken = '' } = config;\n return {\n headers: { 'PRIVATE-TOKEN': configToken },\n };\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): 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),\n );\n\n const data = await response.json();\n\n if (!response.ok) {\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":";;;;;;;;;AAuCsB,eAAA,qBAAA,CACpB,KACA,MACiB,EAAA;AACjB,EAAA,MAAM,SAAY,GAAA,MAAM,YAAa,CAAA,GAAA,EAAK,M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S,EAAI,EAAA;AAChB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAiB,cAAA,EAAA,IAAA,CAAK,KAAK,CAAA,GAAA,EAAM,KAAK,iBAAiB,CAAA;AAAA,OACzD;AAAA;AAGF,IAAO,OAAA,MAAA,CAAO,KAAK,EAAE,CAAA;AAAA,WACd,CAAG,EAAA;AACV,IAAA,MAAM,IAAI,KAAM,CAAA,CAAA,qCAAA,EAAwC,MAAM,CAAA,EAAA,EAAK,CAAC,CAAE,CAAA,CAAA;AAAA;AAE1E;;;;;;;"}
@@ -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): Promise<string> {\n const projectID = await getProjectId(url, config);\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 * @public\n */\nexport function getGitLabRequestOptions(\n config: GitLabIntegrationConfig,\n token?: string,\n): { headers: Record<string, string> } {\n if (token) {\n // If token comes from the user and starts with \"gl\", it's a private token (see https://docs.gitlab.com/ee/security/token_overview.html#token-prefixes)\n return {\n headers: token.startsWith('gl')\n ? { 'PRIVATE-TOKEN': token }\n : { Authorization: `Bearer ${token}` }, // Otherwise, it's a bearer token\n };\n }\n\n // If token not provided, fetch the integration token\n const { token: configToken = '' } = config;\n return {\n headers: { 'PRIVATE-TOKEN': configToken },\n };\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): 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),\n );\n\n const data = await response.json();\n\n if (!response.ok) {\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":";;;AAuCsB,eAAA,qBAAA,CACpB,KACA,MACiB,EAAA;AACjB,EAAA,MAAM,SAAY,GAAA,MAAM,YAAa,CAAA,GAAA,EAAK,MAAM,CAAA;AAChD,EAAA,OAAO,eAAgB,CAAA,GAAA,EAAK,SAAW,EAAA,MAAM,EAAE,QAAS,EAAA;AAC1D;AAQgB,SAAA,uBAAA,CACd,QACA,KACqC,EAAA;AACrC,EAAA,IAAI,KAAO,EAAA;AAET,IAAO,OAAA;AAAA,MACL,OAAS,EAAA,KAAA,CAAM,UAAW,CAAA,IAAI,CAC1B,GAAA,EAAE,eAAiB,EAAA,KAAA,EACnB,GAAA,EAAE,aAAe,EAAA,CAAA,OAAA,EAAU,KAAK,CAAG,CAAA;AAAA;AAAA,KACzC;AAAA;AAIF,EAAA,MAAM,EAAE,KAAA,EAAO,WAAc,GAAA,EAAA,EAAO,GAAA,MAAA;AACpC,EAAO,OAAA;AAAA,IACL,OAAA,EAAS,EAAE,eAAA,EAAiB,WAAY;AAAA,GAC1C;AACF;AAKgB,SAAA,eAAA,CACd,MACA,EAAA,SAAA,EACA,MACK,EAAA;AACL,EAAI,IAAA;AACF,IAAM,MAAA,GAAA,GAAM,IAAI,GAAA,CAAI,MAAM,CAAA;AAE1B,IAAM,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MAAA,YAAA,GAAe,iCAAiC,MAAM,CAAA;AAG5D,IAAA,IAAI,YAAc,EAAA;AAChB,MAAO,IAAA,GAAA,IAAA,CAAK,OAAQ,CAAA,YAAA,EAAc,EAAE,CAAA;AAAA;AAKtC,IAAA,MAAM,eAAe,IAAI,GAAA;AAAA,MACvB,CAAG,EAAA,GAAA,CAAI,MAAM,CAAA,EAAG,YAAY,CAAoB,iBAAA,EAAA,kBAAA;AAAA,QAC9C,IAAA,CAAK,OAAQ,CAAA,KAAA,EAAO,EAAE;AAAA,OACvB,CAAA;AAAA,KACH;AAEA,IAAA,MAAM,WAAW,MAAM,KAAA;AAAA,MACrB,aAAa,QAAS,EAAA;AAAA,MACtB,wBAAwB,MAAM;AAAA,KAChC;AAEA,IAAM,MAAA,IAAA,GAAO,MAAM,QAAA,CAAS,IAAK,EAAA;AAEjC,IAAI,IAAA,CAAC,SAAS,EAAI,EAAA;AAChB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAiB,cAAA,EAAA,IAAA,CAAK,KAAK,CAAA,GAAA,EAAM,KAAK,iBAAiB,CAAA;AAAA,OACzD;AAAA;AAGF,IAAO,OAAA,MAAA,CAAO,KAAK,EAAE,CAAA;AAAA,WACd,CAAG,EAAA;AACV,IAAA,MAAM,IAAI,KAAM,CAAA,CAAA,qCAAA,EAAwC,MAAM,CAAA,EAAA,EAAK,CAAC,CAAE,CAAA,CAAA;AAAA;AAE1E;;;;"}
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): Promise<string> {\n const projectID = await getProjectId(url, config);\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 if (token) {\n // If token comes from the user and starts with \"gl\", it's a private token (see https://docs.gitlab.com/ee/security/token_overview.html#token-prefixes)\n return {\n headers: token.startsWith('gl')\n ? { 'PRIVATE-TOKEN': token }\n : { Authorization: `Bearer ${token}` }, // Otherwise, it's a bearer token\n };\n }\n\n // If token not provided, fetch the integration token\n const { token: configToken = '' } = config;\n return {\n headers: { 'PRIVATE-TOKEN': configToken },\n };\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): 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),\n );\n\n const data = await response.json();\n\n if (!response.ok) {\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":";;;AAuCsB,eAAA,qBAAA,CACpB,KACA,MACiB,EAAA;AACjB,EAAA,MAAM,SAAY,GAAA,MAAM,YAAa,CAAA,GAAA,EAAK,MAAM,CAAA;AAChD,EAAA,OAAO,eAAgB,CAAA,GAAA,EAAK,SAAW,EAAA,MAAM,EAAE,QAAS,EAAA;AAC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,EAAM,KAAK,iBAAiB,CAAA;AAAA,OACzD;AAAA;AAGF,IAAO,OAAA,MAAA,CAAO,KAAK,EAAE,CAAA;AAAA,WACd,CAAG,EAAA;AACV,IAAA,MAAM,IAAI,KAAM,CAAA,CAAA,qCAAA,EAAwC,MAAM,CAAA,EAAA,EAAK,CAAC,CAAE,CAAA,CAAA;AAAA;AAE1E;;;;"}
package/dist/index.d.ts CHANGED
@@ -1798,6 +1798,7 @@ declare function getGitLabFileFetchUrl(url: string, config: GitLabIntegrationCon
1798
1798
  * Gets the request options necessary to make requests to a given provider.
1799
1799
  *
1800
1800
  * @param config - The relevant provider config
1801
+ * @param token - An optional auth token to use for communicating with GitLab. By default uses the integration token
1801
1802
  * @public
1802
1803
  */
1803
1804
  declare function getGitLabRequestOptions(config: GitLabIntegrationConfig, token?: string): {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/integration",
3
- "version": "1.16.4-next.0",
3
+ "version": "1.16.4-next.1",
4
4
  "description": "Helpers for managing integrations towards external systems",
5
5
  "backstage": {
6
6
  "role": "common-library"
@@ -49,8 +49,8 @@
49
49
  "luxon": "^3.0.0"
50
50
  },
51
51
  "devDependencies": {
52
- "@backstage/cli": "0.32.1-next.0",
53
- "@backstage/config-loader": "1.10.0",
52
+ "@backstage/cli": "0.32.1-next.1",
53
+ "@backstage/config-loader": "1.10.1-next.0",
54
54
  "@types/luxon": "^3.0.0",
55
55
  "msw": "^1.0.0"
56
56
  },