@backstage/integration 2.0.0-next.1 → 2.0.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 +26 -0
- package/dist/bitbucketCloud/core.cjs.js +3 -2
- package/dist/bitbucketCloud/core.cjs.js.map +1 -1
- package/dist/bitbucketCloud/core.esm.js +3 -2
- package/dist/bitbucketCloud/core.esm.js.map +1 -1
- package/dist/bitbucketServer/core.cjs.js +8 -2
- package/dist/bitbucketServer/core.cjs.js.map +1 -1
- package/dist/bitbucketServer/core.esm.js +8 -2
- package/dist/bitbucketServer/core.esm.js.map +1 -1
- package/dist/github/core.cjs.js +2 -6
- package/dist/github/core.cjs.js.map +1 -1
- package/dist/github/core.esm.js +2 -2
- package/dist/github/core.esm.js.map +1 -1
- package/dist/helpers.cjs.js +23 -1
- package/dist/helpers.cjs.js.map +1 -1
- package/dist/helpers.esm.js +23 -2
- package/dist/helpers.esm.js.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @backstage/integration
|
|
2
2
|
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 527cf88: **BREAKING** Removed deprecated Azure DevOps, Bitbucket, Gerrit and GitHub code:
|
|
8
|
+
|
|
9
|
+
- For Azure DevOps, the long deprecated `token` string and `credential` object have been removed from the `config.d.ts`. Use the `credentials` array object instead.
|
|
10
|
+
- For Bitbucket, the long deprecated `bitbucket` object has been removed from the `config.d.ts`. Use the `bitbucketCloud` or `bitbucketServer` objects instead.
|
|
11
|
+
- For Gerrit, the `parseGerritGitilesUrl` function has been removed, use `parseGitilesUrlRef` instead. The `buildGerritGitilesArchiveUrl` function has also been removed, use `buildGerritGitilesArchiveUrlFromLocation` instead.
|
|
12
|
+
- For GitHub, the `getGitHubRequestOptions` function has been removed.
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- d933f62: Add configurable throttling and retry mechanism for GitLab integration.
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 1513a0b: Fixed a security vulnerability where path traversal sequences in SCM URLs could be used to access unintended API endpoints using server-side integration credentials.
|
|
21
|
+
- 993a598: Fixed Azure integration config schema visibility annotations to use per-field `@visibility secret` instead of `@deepVisibility secret` on parent objects, so that non-secret fields like `clientId`, `tenantId`, `organizations`, and `managedIdentityClientId` are no longer incorrectly marked as secret.
|
|
22
|
+
|
|
23
|
+
## 2.0.0-next.2
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- 1513a0b: Fixed a security vulnerability where path traversal sequences in SCM URLs could be used to access unintended API endpoints using server-side integration credentials.
|
|
28
|
+
|
|
3
29
|
## 2.0.0-next.1
|
|
4
30
|
|
|
5
31
|
### Major Changes
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var fetch = require('cross-fetch');
|
|
4
4
|
var parseGitUrl = require('git-url-parse');
|
|
5
|
+
var helpers = require('../helpers.cjs.js');
|
|
5
6
|
var luxon = require('luxon');
|
|
6
7
|
|
|
7
8
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
@@ -88,7 +89,7 @@ async function getBitbucketCloudDownloadUrl(url, config) {
|
|
|
88
89
|
ref,
|
|
89
90
|
protocol,
|
|
90
91
|
resource
|
|
91
|
-
} =
|
|
92
|
+
} = helpers.parseGitUrlSafe(url);
|
|
92
93
|
let branch = ref;
|
|
93
94
|
if (!branch) {
|
|
94
95
|
branch = await getBitbucketCloudDefaultBranch(url, config);
|
|
@@ -97,7 +98,7 @@ async function getBitbucketCloudDownloadUrl(url, config) {
|
|
|
97
98
|
}
|
|
98
99
|
function getBitbucketCloudFileFetchUrl(url, config) {
|
|
99
100
|
try {
|
|
100
|
-
const { owner, name, ref, filepathtype, filepath } =
|
|
101
|
+
const { owner, name, ref, filepathtype, filepath } = helpers.parseGitUrlSafe(url);
|
|
101
102
|
if (!owner || !name || filepathtype !== "src" && filepathtype !== "raw") {
|
|
102
103
|
throw new Error("Invalid Bitbucket Cloud URL or file path");
|
|
103
104
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.cjs.js","sources":["../../src/bitbucketCloud/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 parseGitUrl from 'git-url-parse';\nimport { BitbucketCloudIntegrationConfig } from './config';\nimport { DateTime } from 'luxon';\n\ntype OAuthTokenData = {\n token: string;\n expiresAt: DateTime;\n};\n\n// In-memory token cache (single entry since there's only one Bitbucket Cloud integration)\nlet cachedToken: OAuthTokenData | undefined;\n\n// Track in-flight token refresh request to prevent concurrent fetches\nlet refreshPromise: Promise<string> | undefined;\n\n/**\n * Fetches an OAuth access token from Bitbucket Cloud using client credentials flow.\n * Tokens are cached with a 10-minute grace period to account for clock skew.\n * Implements concurrent refresh protection to prevent multiple simultaneous token requests.\n *\n * @param clientId - OAuth client ID\n * @param clientSecret - OAuth client secret\n * @public\n */\nexport async function getBitbucketCloudOAuthToken(\n clientId: string,\n clientSecret: string,\n): Promise<string> {\n // Check cache\n if (cachedToken && DateTime.now() < cachedToken.expiresAt) {\n return cachedToken.token;\n }\n\n // Check if there's already a refresh in progress\n if (refreshPromise) {\n return refreshPromise;\n }\n\n // Start a new token fetch and track it\n refreshPromise = (async () => {\n try {\n // Fetch new token\n const credentials = Buffer.from(\n `${clientId}:${clientSecret}`,\n 'utf8',\n ).toString('base64');\n\n const response = await fetch(\n 'https://bitbucket.org/site/oauth2/access_token',\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n Authorization: `Basic ${credentials}`,\n },\n body: 'grant_type=client_credentials',\n },\n );\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch OAuth token from Bitbucket Cloud: ${response.status} ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n\n if (!data.access_token) {\n throw new Error('OAuth token response missing access_token field');\n }\n\n // Calculate expiration with 10-minute grace period\n const expiresIn = data.expires_in || 3600; // Default to 1 hour\n const expiresAt = DateTime.now()\n .plus({ seconds: expiresIn })\n .minus({ minutes: 10 });\n\n // Cache the token\n cachedToken = {\n token: data.access_token,\n expiresAt,\n };\n\n return data.access_token;\n } catch (error) {\n throw new Error(\n `Failed to fetch OAuth token for Bitbucket Cloud: ${error}`,\n );\n } finally {\n // Clean up the in-flight promise tracking\n refreshPromise = undefined;\n }\n })();\n\n return refreshPromise;\n}\n\n/**\n * Given a URL pointing to a path on a provider, returns the default branch.\n *\n * @param url - A URL pointing to a path\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketCloudDefaultBranch(\n url: string,\n config: BitbucketCloudIntegrationConfig,\n): Promise<string> {\n const { name: repoName, owner: project } = parseGitUrl(url);\n\n const branchUrl = `${config.apiBaseUrl}/repositories/${project}/${repoName}`;\n const response = await fetch(\n branchUrl,\n await getBitbucketCloudRequestOptions(config),\n );\n\n if (!response.ok) {\n const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`;\n throw new Error(message);\n }\n\n const repoInfo = await response.json();\n const defaultBranch = repoInfo.mainbranch.name;\n if (!defaultBranch) {\n throw new Error(\n `Failed to read default branch from ${branchUrl}. ` +\n `Response ${response.status} ${response.json()}`,\n );\n }\n return defaultBranch;\n}\n\n/**\n * Given a URL pointing to a path on a provider, returns a URL that is suitable\n * for downloading the subtree.\n *\n * @param url - A URL pointing to a path\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketCloudDownloadUrl(\n url: string,\n config: BitbucketCloudIntegrationConfig,\n): Promise<string> {\n const {\n name: repoName,\n owner: project,\n ref,\n protocol,\n resource,\n } = parseGitUrl(url);\n\n let branch = ref;\n if (!branch) {\n branch = await getBitbucketCloudDefaultBranch(url, config);\n }\n return `${protocol}://${resource}/${project}/${repoName}/get/${branch}.tar.gz`;\n}\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://bitbucket.org/orgname/reponame/src/master/file.yaml\n * to: https://api.bitbucket.org/2.0/repositories/orgname/reponame/src/master/file.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getBitbucketCloudFileFetchUrl(\n url: string,\n config: BitbucketCloudIntegrationConfig,\n): string {\n try {\n const { owner, name, ref, filepathtype, filepath } = parseGitUrl(url);\n if (!owner || !name || (filepathtype !== 'src' && filepathtype !== 'raw')) {\n throw new Error('Invalid Bitbucket Cloud URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n\n if (!ref) {\n throw new Error('Invalid Bitbucket Cloud URL or file path');\n }\n return `${config.apiBaseUrl}/repositories/${owner}/${name}/src/${ref}/${pathWithoutSlash}`;\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n\n/**\n * Gets the request options necessary to make requests to a given provider.\n * Returns headers for authenticating with Bitbucket Cloud.\n * Supports OAuth (clientId/clientSecret), username/token, and username/appPassword auth.\n *\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketCloudRequestOptions(\n config: BitbucketCloudIntegrationConfig,\n): Promise<{\n headers: Record<string, string>;\n}> {\n const headers: Record<string, string> = {};\n\n // OAuth authentication (clientId/clientSecret)\n if (config.clientId && config.clientSecret) {\n const token = await getBitbucketCloudOAuthToken(\n config.clientId,\n config.clientSecret,\n );\n headers.Authorization = `Bearer ${token}`;\n return { headers };\n }\n\n // Basic authentication (username + token/appPassword)\n // TODO: appPassword can be removed once fully\n // deprecated by BitBucket on 9th June 2026.\n if (config.username && (config.token ?? config.appPassword)) {\n const buffer = Buffer.from(\n `${config.username}:${config.token ?? config.appPassword}`,\n 'utf8',\n );\n headers.Authorization = `Basic ${buffer.toString('base64')}`;\n }\n\n return { headers };\n}\n"],"names":["DateTime","fetch","parseGitUrl"],"mappings":";;;;;;;;;;;AA2BA,IAAI,WAAA;AAGJ,IAAI,cAAA;AAWJ,eAAsB,2BAAA,CACpB,UACA,YAAA,EACiB;AAEjB,EAAA,IAAI,WAAA,IAAeA,cAAA,CAAS,GAAA,EAAI,GAAI,YAAY,SAAA,EAAW;AACzD,IAAA,OAAO,WAAA,CAAY,KAAA;AAAA,EACrB;AAGA,EAAA,IAAI,cAAA,EAAgB;AAClB,IAAA,OAAO,cAAA;AAAA,EACT;AAGA,EAAA,cAAA,GAAA,CAAkB,YAAY;AAC5B,IAAA,IAAI;AAEF,MAAA,MAAM,cAAc,MAAA,CAAO,IAAA;AAAA,QACzB,CAAA,EAAG,QAAQ,CAAA,CAAA,EAAI,YAAY,CAAA,CAAA;AAAA,QAC3B;AAAA,OACF,CAAE,SAAS,QAAQ,CAAA;AAEnB,MAAA,MAAM,WAAW,MAAMC,sBAAA;AAAA,QACrB,gDAAA;AAAA,QACA;AAAA,UACE,MAAA,EAAQ,MAAA;AAAA,UACR,OAAA,EAAS;AAAA,YACP,cAAA,EAAgB,mCAAA;AAAA,YAChB,aAAA,EAAe,SAAS,WAAW,CAAA;AAAA,WACrC;AAAA,UACA,IAAA,EAAM;AAAA;AACR,OACF;AAEA,MAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,QAAA,MAAM,IAAI,KAAA;AAAA,UACR,CAAA,kDAAA,EAAqD,QAAA,CAAS,MAAM,CAAA,CAAA,EAAI,SAAS,UAAU,CAAA;AAAA,SAC7F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version":3,"file":"core.cjs.js","sources":["../../src/bitbucketCloud/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 parseGitUrl from 'git-url-parse';\nimport { parseGitUrlSafe } from '../helpers';\nimport { BitbucketCloudIntegrationConfig } from './config';\nimport { DateTime } from 'luxon';\n\ntype OAuthTokenData = {\n token: string;\n expiresAt: DateTime;\n};\n\n// In-memory token cache (single entry since there's only one Bitbucket Cloud integration)\nlet cachedToken: OAuthTokenData | undefined;\n\n// Track in-flight token refresh request to prevent concurrent fetches\nlet refreshPromise: Promise<string> | undefined;\n\n/**\n * Fetches an OAuth access token from Bitbucket Cloud using client credentials flow.\n * Tokens are cached with a 10-minute grace period to account for clock skew.\n * Implements concurrent refresh protection to prevent multiple simultaneous token requests.\n *\n * @param clientId - OAuth client ID\n * @param clientSecret - OAuth client secret\n * @public\n */\nexport async function getBitbucketCloudOAuthToken(\n clientId: string,\n clientSecret: string,\n): Promise<string> {\n // Check cache\n if (cachedToken && DateTime.now() < cachedToken.expiresAt) {\n return cachedToken.token;\n }\n\n // Check if there's already a refresh in progress\n if (refreshPromise) {\n return refreshPromise;\n }\n\n // Start a new token fetch and track it\n refreshPromise = (async () => {\n try {\n // Fetch new token\n const credentials = Buffer.from(\n `${clientId}:${clientSecret}`,\n 'utf8',\n ).toString('base64');\n\n const response = await fetch(\n 'https://bitbucket.org/site/oauth2/access_token',\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n Authorization: `Basic ${credentials}`,\n },\n body: 'grant_type=client_credentials',\n },\n );\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch OAuth token from Bitbucket Cloud: ${response.status} ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n\n if (!data.access_token) {\n throw new Error('OAuth token response missing access_token field');\n }\n\n // Calculate expiration with 10-minute grace period\n const expiresIn = data.expires_in || 3600; // Default to 1 hour\n const expiresAt = DateTime.now()\n .plus({ seconds: expiresIn })\n .minus({ minutes: 10 });\n\n // Cache the token\n cachedToken = {\n token: data.access_token,\n expiresAt,\n };\n\n return data.access_token;\n } catch (error) {\n throw new Error(\n `Failed to fetch OAuth token for Bitbucket Cloud: ${error}`,\n );\n } finally {\n // Clean up the in-flight promise tracking\n refreshPromise = undefined;\n }\n })();\n\n return refreshPromise;\n}\n\n/**\n * Given a URL pointing to a path on a provider, returns the default branch.\n *\n * @param url - A URL pointing to a path\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketCloudDefaultBranch(\n url: string,\n config: BitbucketCloudIntegrationConfig,\n): Promise<string> {\n const { name: repoName, owner: project } = parseGitUrl(url);\n\n const branchUrl = `${config.apiBaseUrl}/repositories/${project}/${repoName}`;\n const response = await fetch(\n branchUrl,\n await getBitbucketCloudRequestOptions(config),\n );\n\n if (!response.ok) {\n const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`;\n throw new Error(message);\n }\n\n const repoInfo = await response.json();\n const defaultBranch = repoInfo.mainbranch.name;\n if (!defaultBranch) {\n throw new Error(\n `Failed to read default branch from ${branchUrl}. ` +\n `Response ${response.status} ${response.json()}`,\n );\n }\n return defaultBranch;\n}\n\n/**\n * Given a URL pointing to a path on a provider, returns a URL that is suitable\n * for downloading the subtree.\n *\n * @param url - A URL pointing to a path\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketCloudDownloadUrl(\n url: string,\n config: BitbucketCloudIntegrationConfig,\n): Promise<string> {\n const {\n name: repoName,\n owner: project,\n ref,\n protocol,\n resource,\n } = parseGitUrlSafe(url);\n\n let branch = ref;\n if (!branch) {\n branch = await getBitbucketCloudDefaultBranch(url, config);\n }\n return `${protocol}://${resource}/${project}/${repoName}/get/${branch}.tar.gz`;\n}\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://bitbucket.org/orgname/reponame/src/master/file.yaml\n * to: https://api.bitbucket.org/2.0/repositories/orgname/reponame/src/master/file.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getBitbucketCloudFileFetchUrl(\n url: string,\n config: BitbucketCloudIntegrationConfig,\n): string {\n try {\n const { owner, name, ref, filepathtype, filepath } = parseGitUrlSafe(url);\n if (!owner || !name || (filepathtype !== 'src' && filepathtype !== 'raw')) {\n throw new Error('Invalid Bitbucket Cloud URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n\n if (!ref) {\n throw new Error('Invalid Bitbucket Cloud URL or file path');\n }\n return `${config.apiBaseUrl}/repositories/${owner}/${name}/src/${ref}/${pathWithoutSlash}`;\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n\n/**\n * Gets the request options necessary to make requests to a given provider.\n * Returns headers for authenticating with Bitbucket Cloud.\n * Supports OAuth (clientId/clientSecret), username/token, and username/appPassword auth.\n *\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketCloudRequestOptions(\n config: BitbucketCloudIntegrationConfig,\n): Promise<{\n headers: Record<string, string>;\n}> {\n const headers: Record<string, string> = {};\n\n // OAuth authentication (clientId/clientSecret)\n if (config.clientId && config.clientSecret) {\n const token = await getBitbucketCloudOAuthToken(\n config.clientId,\n config.clientSecret,\n );\n headers.Authorization = `Bearer ${token}`;\n return { headers };\n }\n\n // Basic authentication (username + token/appPassword)\n // TODO: appPassword can be removed once fully\n // deprecated by BitBucket on 9th June 2026.\n if (config.username && (config.token ?? config.appPassword)) {\n const buffer = Buffer.from(\n `${config.username}:${config.token ?? config.appPassword}`,\n 'utf8',\n );\n headers.Authorization = `Basic ${buffer.toString('base64')}`;\n }\n\n return { headers };\n}\n"],"names":["DateTime","fetch","parseGitUrl","parseGitUrlSafe"],"mappings":";;;;;;;;;;;;AA4BA,IAAI,WAAA;AAGJ,IAAI,cAAA;AAWJ,eAAsB,2BAAA,CACpB,UACA,YAAA,EACiB;AAEjB,EAAA,IAAI,WAAA,IAAeA,cAAA,CAAS,GAAA,EAAI,GAAI,YAAY,SAAA,EAAW;AACzD,IAAA,OAAO,WAAA,CAAY,KAAA;AAAA,EACrB;AAGA,EAAA,IAAI,cAAA,EAAgB;AAClB,IAAA,OAAO,cAAA;AAAA,EACT;AAGA,EAAA,cAAA,GAAA,CAAkB,YAAY;AAC5B,IAAA,IAAI;AAEF,MAAA,MAAM,cAAc,MAAA,CAAO,IAAA;AAAA,QACzB,CAAA,EAAG,QAAQ,CAAA,CAAA,EAAI,YAAY,CAAA,CAAA;AAAA,QAC3B;AAAA,OACF,CAAE,SAAS,QAAQ,CAAA;AAEnB,MAAA,MAAM,WAAW,MAAMC,sBAAA;AAAA,QACrB,gDAAA;AAAA,QACA;AAAA,UACE,MAAA,EAAQ,MAAA;AAAA,UACR,OAAA,EAAS;AAAA,YACP,cAAA,EAAgB,mCAAA;AAAA,YAChB,aAAA,EAAe,SAAS,WAAW,CAAA;AAAA,WACrC;AAAA,UACA,IAAA,EAAM;AAAA;AACR,OACF;AAEA,MAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,QAAA,MAAM,IAAI,KAAA;AAAA,UACR,CAAA,kDAAA,EAAqD,QAAA,CAAS,MAAM,CAAA,CAAA,EAAI,SAAS,UAAU,CAAA;AAAA,SAC7F;AAAA,MACF;AAEA,MAAA,MAAM,IAAA,GAAO,MAAM,QAAA,CAAS,IAAA,EAAK;AAEjC,MAAA,IAAI,CAAC,KAAK,YAAA,EAAc;AACtB,QAAA,MAAM,IAAI,MAAM,iDAAiD,CAAA;A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
|
|
|
5
6
|
let cachedToken;
|
|
@@ -81,7 +82,7 @@ async function getBitbucketCloudDownloadUrl(url, config) {
|
|
|
81
82
|
ref,
|
|
82
83
|
protocol,
|
|
83
84
|
resource
|
|
84
|
-
} =
|
|
85
|
+
} = parseGitUrlSafe(url);
|
|
85
86
|
let branch = ref;
|
|
86
87
|
if (!branch) {
|
|
87
88
|
branch = await getBitbucketCloudDefaultBranch(url, config);
|
|
@@ -90,7 +91,7 @@ async function getBitbucketCloudDownloadUrl(url, config) {
|
|
|
90
91
|
}
|
|
91
92
|
function getBitbucketCloudFileFetchUrl(url, config) {
|
|
92
93
|
try {
|
|
93
|
-
const { owner, name, ref, filepathtype, filepath } =
|
|
94
|
+
const { owner, name, ref, filepathtype, filepath } = parseGitUrlSafe(url);
|
|
94
95
|
if (!owner || !name || filepathtype !== "src" && filepathtype !== "raw") {
|
|
95
96
|
throw new Error("Invalid Bitbucket Cloud URL or file path");
|
|
96
97
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.esm.js","sources":["../../src/bitbucketCloud/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 parseGitUrl from 'git-url-parse';\nimport { BitbucketCloudIntegrationConfig } from './config';\nimport { DateTime } from 'luxon';\n\ntype OAuthTokenData = {\n token: string;\n expiresAt: DateTime;\n};\n\n// In-memory token cache (single entry since there's only one Bitbucket Cloud integration)\nlet cachedToken: OAuthTokenData | undefined;\n\n// Track in-flight token refresh request to prevent concurrent fetches\nlet refreshPromise: Promise<string> | undefined;\n\n/**\n * Fetches an OAuth access token from Bitbucket Cloud using client credentials flow.\n * Tokens are cached with a 10-minute grace period to account for clock skew.\n * Implements concurrent refresh protection to prevent multiple simultaneous token requests.\n *\n * @param clientId - OAuth client ID\n * @param clientSecret - OAuth client secret\n * @public\n */\nexport async function getBitbucketCloudOAuthToken(\n clientId: string,\n clientSecret: string,\n): Promise<string> {\n // Check cache\n if (cachedToken && DateTime.now() < cachedToken.expiresAt) {\n return cachedToken.token;\n }\n\n // Check if there's already a refresh in progress\n if (refreshPromise) {\n return refreshPromise;\n }\n\n // Start a new token fetch and track it\n refreshPromise = (async () => {\n try {\n // Fetch new token\n const credentials = Buffer.from(\n `${clientId}:${clientSecret}`,\n 'utf8',\n ).toString('base64');\n\n const response = await fetch(\n 'https://bitbucket.org/site/oauth2/access_token',\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n Authorization: `Basic ${credentials}`,\n },\n body: 'grant_type=client_credentials',\n },\n );\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch OAuth token from Bitbucket Cloud: ${response.status} ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n\n if (!data.access_token) {\n throw new Error('OAuth token response missing access_token field');\n }\n\n // Calculate expiration with 10-minute grace period\n const expiresIn = data.expires_in || 3600; // Default to 1 hour\n const expiresAt = DateTime.now()\n .plus({ seconds: expiresIn })\n .minus({ minutes: 10 });\n\n // Cache the token\n cachedToken = {\n token: data.access_token,\n expiresAt,\n };\n\n return data.access_token;\n } catch (error) {\n throw new Error(\n `Failed to fetch OAuth token for Bitbucket Cloud: ${error}`,\n );\n } finally {\n // Clean up the in-flight promise tracking\n refreshPromise = undefined;\n }\n })();\n\n return refreshPromise;\n}\n\n/**\n * Given a URL pointing to a path on a provider, returns the default branch.\n *\n * @param url - A URL pointing to a path\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketCloudDefaultBranch(\n url: string,\n config: BitbucketCloudIntegrationConfig,\n): Promise<string> {\n const { name: repoName, owner: project } = parseGitUrl(url);\n\n const branchUrl = `${config.apiBaseUrl}/repositories/${project}/${repoName}`;\n const response = await fetch(\n branchUrl,\n await getBitbucketCloudRequestOptions(config),\n );\n\n if (!response.ok) {\n const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`;\n throw new Error(message);\n }\n\n const repoInfo = await response.json();\n const defaultBranch = repoInfo.mainbranch.name;\n if (!defaultBranch) {\n throw new Error(\n `Failed to read default branch from ${branchUrl}. ` +\n `Response ${response.status} ${response.json()}`,\n );\n }\n return defaultBranch;\n}\n\n/**\n * Given a URL pointing to a path on a provider, returns a URL that is suitable\n * for downloading the subtree.\n *\n * @param url - A URL pointing to a path\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketCloudDownloadUrl(\n url: string,\n config: BitbucketCloudIntegrationConfig,\n): Promise<string> {\n const {\n name: repoName,\n owner: project,\n ref,\n protocol,\n resource,\n } = parseGitUrl(url);\n\n let branch = ref;\n if (!branch) {\n branch = await getBitbucketCloudDefaultBranch(url, config);\n }\n return `${protocol}://${resource}/${project}/${repoName}/get/${branch}.tar.gz`;\n}\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://bitbucket.org/orgname/reponame/src/master/file.yaml\n * to: https://api.bitbucket.org/2.0/repositories/orgname/reponame/src/master/file.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getBitbucketCloudFileFetchUrl(\n url: string,\n config: BitbucketCloudIntegrationConfig,\n): string {\n try {\n const { owner, name, ref, filepathtype, filepath } = parseGitUrl(url);\n if (!owner || !name || (filepathtype !== 'src' && filepathtype !== 'raw')) {\n throw new Error('Invalid Bitbucket Cloud URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n\n if (!ref) {\n throw new Error('Invalid Bitbucket Cloud URL or file path');\n }\n return `${config.apiBaseUrl}/repositories/${owner}/${name}/src/${ref}/${pathWithoutSlash}`;\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n\n/**\n * Gets the request options necessary to make requests to a given provider.\n * Returns headers for authenticating with Bitbucket Cloud.\n * Supports OAuth (clientId/clientSecret), username/token, and username/appPassword auth.\n *\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketCloudRequestOptions(\n config: BitbucketCloudIntegrationConfig,\n): Promise<{\n headers: Record<string, string>;\n}> {\n const headers: Record<string, string> = {};\n\n // OAuth authentication (clientId/clientSecret)\n if (config.clientId && config.clientSecret) {\n const token = await getBitbucketCloudOAuthToken(\n config.clientId,\n config.clientSecret,\n );\n headers.Authorization = `Bearer ${token}`;\n return { headers };\n }\n\n // Basic authentication (username + token/appPassword)\n // TODO: appPassword can be removed once fully\n // deprecated by BitBucket on 9th June 2026.\n if (config.username && (config.token ?? config.appPassword)) {\n const buffer = Buffer.from(\n `${config.username}:${config.token ?? config.appPassword}`,\n 'utf8',\n );\n headers.Authorization = `Basic ${buffer.toString('base64')}`;\n }\n\n return { headers };\n}\n"],"names":[],"mappings":";;;;AA2BA,IAAI,WAAA;AAGJ,IAAI,cAAA;AAWJ,eAAsB,2BAAA,CACpB,UACA,YAAA,EACiB;AAEjB,EAAA,IAAI,WAAA,IAAe,QAAA,CAAS,GAAA,EAAI,GAAI,YAAY,SAAA,EAAW;AACzD,IAAA,OAAO,WAAA,CAAY,KAAA;AAAA,EACrB;AAGA,EAAA,IAAI,cAAA,EAAgB;AAClB,IAAA,OAAO,cAAA;AAAA,EACT;AAGA,EAAA,cAAA,GAAA,CAAkB,YAAY;AAC5B,IAAA,IAAI;AAEF,MAAA,MAAM,cAAc,MAAA,CAAO,IAAA;AAAA,QACzB,CAAA,EAAG,QAAQ,CAAA,CAAA,EAAI,YAAY,CAAA,CAAA;AAAA,QAC3B;AAAA,OACF,CAAE,SAAS,QAAQ,CAAA;AAEnB,MAAA,MAAM,WAAW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AA,IAAS,OAAO,WAAA,CAAA,EAAc;AAC3D,IAAA,MAAM,SAAS,MAAA,CAAO,IAAA;AAAA,MACpB,GAAG,MAAA,CAAO,QAAQ,IAAI,MAAA,CAAO,KAAA,IAAS,OAAO,WAAW,CAAA,CAAA;AAAA,MACxD;AAAA,KACF;AACA,IAAA,OAAA,CAAQ,aAAA,GAAgB,CAAA,MAAA,EAAS,MAAA,CAAO,QAAA,CAAS,QAAQ,CAAC,CAAA,CAAA;AAAA,EAC5D;AAEA,EAAA,OAAO,EAAE,OAAA,EAAQ;AACnB;;;;"}
|
|
1
|
+
{"version":3,"file":"core.esm.js","sources":["../../src/bitbucketCloud/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 parseGitUrl from 'git-url-parse';\nimport { parseGitUrlSafe } from '../helpers';\nimport { BitbucketCloudIntegrationConfig } from './config';\nimport { DateTime } from 'luxon';\n\ntype OAuthTokenData = {\n token: string;\n expiresAt: DateTime;\n};\n\n// In-memory token cache (single entry since there's only one Bitbucket Cloud integration)\nlet cachedToken: OAuthTokenData | undefined;\n\n// Track in-flight token refresh request to prevent concurrent fetches\nlet refreshPromise: Promise<string> | undefined;\n\n/**\n * Fetches an OAuth access token from Bitbucket Cloud using client credentials flow.\n * Tokens are cached with a 10-minute grace period to account for clock skew.\n * Implements concurrent refresh protection to prevent multiple simultaneous token requests.\n *\n * @param clientId - OAuth client ID\n * @param clientSecret - OAuth client secret\n * @public\n */\nexport async function getBitbucketCloudOAuthToken(\n clientId: string,\n clientSecret: string,\n): Promise<string> {\n // Check cache\n if (cachedToken && DateTime.now() < cachedToken.expiresAt) {\n return cachedToken.token;\n }\n\n // Check if there's already a refresh in progress\n if (refreshPromise) {\n return refreshPromise;\n }\n\n // Start a new token fetch and track it\n refreshPromise = (async () => {\n try {\n // Fetch new token\n const credentials = Buffer.from(\n `${clientId}:${clientSecret}`,\n 'utf8',\n ).toString('base64');\n\n const response = await fetch(\n 'https://bitbucket.org/site/oauth2/access_token',\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n Authorization: `Basic ${credentials}`,\n },\n body: 'grant_type=client_credentials',\n },\n );\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch OAuth token from Bitbucket Cloud: ${response.status} ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n\n if (!data.access_token) {\n throw new Error('OAuth token response missing access_token field');\n }\n\n // Calculate expiration with 10-minute grace period\n const expiresIn = data.expires_in || 3600; // Default to 1 hour\n const expiresAt = DateTime.now()\n .plus({ seconds: expiresIn })\n .minus({ minutes: 10 });\n\n // Cache the token\n cachedToken = {\n token: data.access_token,\n expiresAt,\n };\n\n return data.access_token;\n } catch (error) {\n throw new Error(\n `Failed to fetch OAuth token for Bitbucket Cloud: ${error}`,\n );\n } finally {\n // Clean up the in-flight promise tracking\n refreshPromise = undefined;\n }\n })();\n\n return refreshPromise;\n}\n\n/**\n * Given a URL pointing to a path on a provider, returns the default branch.\n *\n * @param url - A URL pointing to a path\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketCloudDefaultBranch(\n url: string,\n config: BitbucketCloudIntegrationConfig,\n): Promise<string> {\n const { name: repoName, owner: project } = parseGitUrl(url);\n\n const branchUrl = `${config.apiBaseUrl}/repositories/${project}/${repoName}`;\n const response = await fetch(\n branchUrl,\n await getBitbucketCloudRequestOptions(config),\n );\n\n if (!response.ok) {\n const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`;\n throw new Error(message);\n }\n\n const repoInfo = await response.json();\n const defaultBranch = repoInfo.mainbranch.name;\n if (!defaultBranch) {\n throw new Error(\n `Failed to read default branch from ${branchUrl}. ` +\n `Response ${response.status} ${response.json()}`,\n );\n }\n return defaultBranch;\n}\n\n/**\n * Given a URL pointing to a path on a provider, returns a URL that is suitable\n * for downloading the subtree.\n *\n * @param url - A URL pointing to a path\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketCloudDownloadUrl(\n url: string,\n config: BitbucketCloudIntegrationConfig,\n): Promise<string> {\n const {\n name: repoName,\n owner: project,\n ref,\n protocol,\n resource,\n } = parseGitUrlSafe(url);\n\n let branch = ref;\n if (!branch) {\n branch = await getBitbucketCloudDefaultBranch(url, config);\n }\n return `${protocol}://${resource}/${project}/${repoName}/get/${branch}.tar.gz`;\n}\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://bitbucket.org/orgname/reponame/src/master/file.yaml\n * to: https://api.bitbucket.org/2.0/repositories/orgname/reponame/src/master/file.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getBitbucketCloudFileFetchUrl(\n url: string,\n config: BitbucketCloudIntegrationConfig,\n): string {\n try {\n const { owner, name, ref, filepathtype, filepath } = parseGitUrlSafe(url);\n if (!owner || !name || (filepathtype !== 'src' && filepathtype !== 'raw')) {\n throw new Error('Invalid Bitbucket Cloud URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n\n if (!ref) {\n throw new Error('Invalid Bitbucket Cloud URL or file path');\n }\n return `${config.apiBaseUrl}/repositories/${owner}/${name}/src/${ref}/${pathWithoutSlash}`;\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n\n/**\n * Gets the request options necessary to make requests to a given provider.\n * Returns headers for authenticating with Bitbucket Cloud.\n * Supports OAuth (clientId/clientSecret), username/token, and username/appPassword auth.\n *\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketCloudRequestOptions(\n config: BitbucketCloudIntegrationConfig,\n): Promise<{\n headers: Record<string, string>;\n}> {\n const headers: Record<string, string> = {};\n\n // OAuth authentication (clientId/clientSecret)\n if (config.clientId && config.clientSecret) {\n const token = await getBitbucketCloudOAuthToken(\n config.clientId,\n config.clientSecret,\n );\n headers.Authorization = `Bearer ${token}`;\n return { headers };\n }\n\n // Basic authentication (username + token/appPassword)\n // TODO: appPassword can be removed once fully\n // deprecated by BitBucket on 9th June 2026.\n if (config.username && (config.token ?? config.appPassword)) {\n const buffer = Buffer.from(\n `${config.username}:${config.token ?? config.appPassword}`,\n 'utf8',\n );\n headers.Authorization = `Basic ${buffer.toString('base64')}`;\n }\n\n return { headers };\n}\n"],"names":[],"mappings":";;;;;AA4BA,IAAI,WAAA;AAGJ,IAAI,cAAA;AAWJ,eAAsB,2BAAA,CACpB,UACA,YAAA,EACiB;AAEjB,EAAA,IAAI,WAAA,IAAe,QAAA,CAAS,GAAA,EAAI,GAAI,YAAY,SAAA,EAAW;AACzD,IAAA,OAAO,WAAA,CAAY,KAAA;AAAA,EACrB;AAGA,EAAA,IAAI,cAAA,EAAgB;AAClB,IAAA,OAAO,cAAA;AAAA,EACT;AAGA,EAAA,cAAA,GAAA,CAAkB,YAAY;AAC5B,IAAA,IAAI;AAEF,MAAA,MAAM,cAAc,MAAA,CAAO,IAAA;AAAA,QACzB,CAAA,EAAG,QAAQ,CAAA,CAAA,EAAI,YAAY,CAAA,CAAA;AAAA,QAC3B;AAAA,OACF,CAAE,SAAS,QAAQ,CAAA;AAEnB,MAAA,MAAM,WAAW,MAAM,KAAA;AAAA,QACrB,gDAAA;AAAA,QACA;AAAA,UACE,MAAA,EAAQ,MAAA;AAAA,UACR,OAAA,EAAS;AAAA,YACP,cAAA,EAAgB,mCAAA;AAAA,YAChB,aAAA,EAAe,SAAS,WAAW,CAAA;AAAA,WACrC;AAAA,UACA,IAAA,EAAM;AAAA;AACR,OACF;AAE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A,GAAgB,CAAA,MAAA,EAAS,MAAA,CAAO,QAAA,CAAS,QAAQ,CAAC,CAAA,CAAA;AAAA,EAC5D;AAEA,EAAA,OAAO,EAAE,OAAA,EAAQ;AACnB;;;;"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var fetch = require('cross-fetch');
|
|
4
4
|
var parseGitUrl = require('git-url-parse');
|
|
5
|
+
var helpers = require('../helpers.cjs.js');
|
|
5
6
|
|
|
6
7
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
7
8
|
|
|
@@ -33,7 +34,12 @@ async function getBitbucketServerDefaultBranch(url, config) {
|
|
|
33
34
|
return defaultBranch;
|
|
34
35
|
}
|
|
35
36
|
async function getBitbucketServerDownloadUrl(url, config) {
|
|
36
|
-
const {
|
|
37
|
+
const {
|
|
38
|
+
name: repoName,
|
|
39
|
+
owner: project,
|
|
40
|
+
ref,
|
|
41
|
+
filepath
|
|
42
|
+
} = helpers.parseGitUrlSafe(url);
|
|
37
43
|
let branch = ref;
|
|
38
44
|
if (!branch) {
|
|
39
45
|
branch = await getBitbucketServerDefaultBranch(url, config);
|
|
@@ -43,7 +49,7 @@ async function getBitbucketServerDownloadUrl(url, config) {
|
|
|
43
49
|
}
|
|
44
50
|
function getBitbucketServerFileFetchUrl(url, config) {
|
|
45
51
|
try {
|
|
46
|
-
const { owner, name, ref, filepathtype, filepath } =
|
|
52
|
+
const { owner, name, ref, filepathtype, filepath } = helpers.parseGitUrlSafe(url);
|
|
47
53
|
if (!owner || !name || filepathtype !== "browse" && filepathtype !== "raw" && filepathtype !== "src") {
|
|
48
54
|
throw new Error("Invalid Bitbucket Server URL or file path");
|
|
49
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.cjs.js","sources":["../../src/bitbucketServer/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 parseGitUrl from 'git-url-parse';\nimport { BitbucketServerIntegrationConfig } from './config';\n\n/**\n * Given a URL pointing to a path on a provider, returns the default branch.\n *\n * @param url - A URL pointing to a path\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketServerDefaultBranch(\n url: string,\n config: BitbucketServerIntegrationConfig,\n): Promise<string> {\n const { name: repoName, owner: project } = parseGitUrl(url);\n\n // Bitbucket Server https://docs.atlassian.com/bitbucket-server/rest/7.9.0/bitbucket-rest.html#idp184\n let branchUrl = `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/default-branch`;\n\n let response = await fetch(\n branchUrl,\n getBitbucketServerRequestOptions(config),\n );\n\n if (response.status === 404) {\n // First try the new format, and then if it gets specifically a 404 it should try the old format\n // (to support old Atlassian Bitbucket Server v5.11.1 format )\n branchUrl = `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/branches/default`;\n response = await fetch(branchUrl, getBitbucketServerRequestOptions(config));\n }\n\n if (!response.ok) {\n const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`;\n throw new Error(message);\n }\n\n const { displayId } = await response.json();\n const defaultBranch = displayId;\n if (!defaultBranch) {\n throw new Error(\n `Failed to read default branch from ${branchUrl}. ` +\n `Response ${response.status} ${response.json()}`,\n );\n }\n return defaultBranch;\n}\n\n/**\n * Given a URL pointing to a path on a provider, returns a URL that is suitable\n * for downloading the subtree.\n *\n * @param url - A URL pointing to a path\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketServerDownloadUrl(\n url: string,\n config: BitbucketServerIntegrationConfig,\n): Promise<string> {\n const {
|
|
1
|
+
{"version":3,"file":"core.cjs.js","sources":["../../src/bitbucketServer/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 parseGitUrl from 'git-url-parse';\nimport { parseGitUrlSafe } from '../helpers';\nimport { BitbucketServerIntegrationConfig } from './config';\n\n/**\n * Given a URL pointing to a path on a provider, returns the default branch.\n *\n * @param url - A URL pointing to a path\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketServerDefaultBranch(\n url: string,\n config: BitbucketServerIntegrationConfig,\n): Promise<string> {\n const { name: repoName, owner: project } = parseGitUrl(url);\n\n // Bitbucket Server https://docs.atlassian.com/bitbucket-server/rest/7.9.0/bitbucket-rest.html#idp184\n let branchUrl = `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/default-branch`;\n\n let response = await fetch(\n branchUrl,\n getBitbucketServerRequestOptions(config),\n );\n\n if (response.status === 404) {\n // First try the new format, and then if it gets specifically a 404 it should try the old format\n // (to support old Atlassian Bitbucket Server v5.11.1 format )\n branchUrl = `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/branches/default`;\n response = await fetch(branchUrl, getBitbucketServerRequestOptions(config));\n }\n\n if (!response.ok) {\n const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`;\n throw new Error(message);\n }\n\n const { displayId } = await response.json();\n const defaultBranch = displayId;\n if (!defaultBranch) {\n throw new Error(\n `Failed to read default branch from ${branchUrl}. ` +\n `Response ${response.status} ${response.json()}`,\n );\n }\n return defaultBranch;\n}\n\n/**\n * Given a URL pointing to a path on a provider, returns a URL that is suitable\n * for downloading the subtree.\n *\n * @param url - A URL pointing to a path\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketServerDownloadUrl(\n url: string,\n config: BitbucketServerIntegrationConfig,\n): Promise<string> {\n const {\n name: repoName,\n owner: project,\n ref,\n filepath,\n } = parseGitUrlSafe(url);\n\n let branch = ref;\n if (!branch) {\n branch = await getBitbucketServerDefaultBranch(url, config);\n }\n // path will limit the downloaded content\n // /docs will only download the docs folder and everything below it\n // /docs/index.md will download the docs folder and everything below it\n const path = filepath\n ? `&path=${encodeURIComponent(decodeURIComponent(filepath))}`\n : '';\n return `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/archive?format=tgz&at=${branch}&prefix=${project}-${repoName}${path}`;\n}\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://bitbucket.company.com/projectname/reponame/src/main/file.yaml\n * to: https://bitbucket.company.com/rest/api/1.0/project/projectname/reponame/raw/file.yaml?at=main\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getBitbucketServerFileFetchUrl(\n url: string,\n config: BitbucketServerIntegrationConfig,\n): string {\n try {\n const { owner, name, ref, filepathtype, filepath } = parseGitUrlSafe(url);\n if (\n !owner ||\n !name ||\n (filepathtype !== 'browse' &&\n filepathtype !== 'raw' &&\n filepathtype !== 'src')\n ) {\n throw new Error('Invalid Bitbucket Server URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n return `${config.apiBaseUrl}/projects/${owner}/repos/${name}/raw/${pathWithoutSlash}?at=${ref}`;\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\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 getBitbucketServerRequestOptions(\n config: BitbucketServerIntegrationConfig,\n): { headers: Record<string, string> } {\n const headers: Record<string, string> = {};\n\n if (config.token) {\n headers.Authorization = `Bearer ${config.token}`;\n } else if (config.username && config.password) {\n const buffer = Buffer.from(`${config.username}:${config.password}`, 'utf8');\n headers.Authorization = `Basic ${buffer.toString('base64')}`;\n }\n\n return {\n headers,\n };\n}\n"],"names":["parseGitUrl","fetch","parseGitUrlSafe"],"mappings":";;;;;;;;;;;AA4BA,eAAsB,+BAAA,CACpB,KACA,MAAA,EACiB;AACjB,EAAA,MAAM,EAAE,IAAA,EAAM,QAAA,EAAU,OAAO,OAAA,EAAQ,GAAIA,6BAAY,GAAG,CAAA;AAG1D,EAAA,IAAI,YAAY,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,UAAA,EAAa,OAAO,UAAU,QAAQ,CAAA,eAAA,CAAA;AAE1E,EAAA,IAAI,WAAW,MAAMC,sBAAA;AAAA,IACnB,SAAA;AAAA,IACA,iCAAiC,MAAM;AAAA,GACzC;AAEA,EAAA,IAAI,QAAA,CAAS,WAAW,GAAA,EAAK;AAG3B,IAAA,SAAA,GAAY,GAAG,MAAA,CAAO,UAAU,CAAA,UAAA,EAAa,OAAO,UAAU,QAAQ,CAAA,iBAAA,CAAA;AACtE,IAAA,QAAA,GAAW,MAAMA,sBAAA,CAAM,SAAA,EAAW,gCAAA,CAAiC,MAAM,CAAC,CAAA;AAAA,EAC5E;AAEA,EAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,IAAA,MAAM,OAAA,GAAU,0CAA0C,SAAS,CAAA,EAAA,EAAK,SAAS,MAAM,CAAA,CAAA,EAAI,SAAS,UAAU,CAAA,CAAA;AAC9G,IAAA,MAAM,IAAI,MAAM,OAAO,CAAA;AAAA,EACzB;AAEA,EAAA,MAAM,EAAE,SAAA,EAAU,GAAI,MAAM,SAAS,IAAA,EAAK;AAC1C,EAAA,MAAM,aAAA,GAAgB,SAAA;AACtB,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,MAAM,IAAI,KAAA;AA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CAAA;AACnD,IAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,UAAA,EAAa,KAAK,UAAU,IAAI,CAAA,KAAA,EAAQ,gBAAgB,CAAA,IAAA,EAAO,GAAG,CAAA,CAAA;AAAA,EAC/F,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EAC/C;AACF;AAQO,SAAS,iCACd,MAAA,EACqC;AACrC,EAAA,MAAM,UAAkC,EAAC;AAEzC,EAAA,IAAI,OAAO,KAAA,EAAO;AAChB,IAAA,OAAA,CAAQ,aAAA,GAAgB,CAAA,OAAA,EAAU,MAAA,CAAO,KAAK,CAAA,CAAA;AAAA,EAChD,CAAA,MAAA,IAAW,MAAA,CAAO,QAAA,IAAY,MAAA,CAAO,QAAA,EAAU;AAC7C,IAAA,MAAM,MAAA,GAAS,MAAA,CAAO,IAAA,CAAK,CAAA,EAAG,MAAA,CAAO,QAAQ,CAAA,CAAA,EAAI,MAAA,CAAO,QAAQ,CAAA,CAAA,EAAI,MAAM,CAAA;AAC1E,IAAA,OAAA,CAAQ,aAAA,GAAgB,CAAA,MAAA,EAAS,MAAA,CAAO,QAAA,CAAS,QAAQ,CAAC,CAAA,CAAA;AAAA,EAC5D;AAEA,EAAA,OAAO;AAAA,IACL;AAAA,GACF;AACF;;;;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fetch from 'cross-fetch';
|
|
2
2
|
import parseGitUrl from 'git-url-parse';
|
|
3
|
+
import { parseGitUrlSafe } from '../helpers.esm.js';
|
|
3
4
|
|
|
4
5
|
async function getBitbucketServerDefaultBranch(url, config) {
|
|
5
6
|
const { name: repoName, owner: project } = parseGitUrl(url);
|
|
@@ -26,7 +27,12 @@ async function getBitbucketServerDefaultBranch(url, config) {
|
|
|
26
27
|
return defaultBranch;
|
|
27
28
|
}
|
|
28
29
|
async function getBitbucketServerDownloadUrl(url, config) {
|
|
29
|
-
const {
|
|
30
|
+
const {
|
|
31
|
+
name: repoName,
|
|
32
|
+
owner: project,
|
|
33
|
+
ref,
|
|
34
|
+
filepath
|
|
35
|
+
} = parseGitUrlSafe(url);
|
|
30
36
|
let branch = ref;
|
|
31
37
|
if (!branch) {
|
|
32
38
|
branch = await getBitbucketServerDefaultBranch(url, config);
|
|
@@ -36,7 +42,7 @@ async function getBitbucketServerDownloadUrl(url, config) {
|
|
|
36
42
|
}
|
|
37
43
|
function getBitbucketServerFileFetchUrl(url, config) {
|
|
38
44
|
try {
|
|
39
|
-
const { owner, name, ref, filepathtype, filepath } =
|
|
45
|
+
const { owner, name, ref, filepathtype, filepath } = parseGitUrlSafe(url);
|
|
40
46
|
if (!owner || !name || filepathtype !== "browse" && filepathtype !== "raw" && filepathtype !== "src") {
|
|
41
47
|
throw new Error("Invalid Bitbucket Server URL or file path");
|
|
42
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.esm.js","sources":["../../src/bitbucketServer/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 parseGitUrl from 'git-url-parse';\nimport { BitbucketServerIntegrationConfig } from './config';\n\n/**\n * Given a URL pointing to a path on a provider, returns the default branch.\n *\n * @param url - A URL pointing to a path\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketServerDefaultBranch(\n url: string,\n config: BitbucketServerIntegrationConfig,\n): Promise<string> {\n const { name: repoName, owner: project } = parseGitUrl(url);\n\n // Bitbucket Server https://docs.atlassian.com/bitbucket-server/rest/7.9.0/bitbucket-rest.html#idp184\n let branchUrl = `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/default-branch`;\n\n let response = await fetch(\n branchUrl,\n getBitbucketServerRequestOptions(config),\n );\n\n if (response.status === 404) {\n // First try the new format, and then if it gets specifically a 404 it should try the old format\n // (to support old Atlassian Bitbucket Server v5.11.1 format )\n branchUrl = `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/branches/default`;\n response = await fetch(branchUrl, getBitbucketServerRequestOptions(config));\n }\n\n if (!response.ok) {\n const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`;\n throw new Error(message);\n }\n\n const { displayId } = await response.json();\n const defaultBranch = displayId;\n if (!defaultBranch) {\n throw new Error(\n `Failed to read default branch from ${branchUrl}. ` +\n `Response ${response.status} ${response.json()}`,\n );\n }\n return defaultBranch;\n}\n\n/**\n * Given a URL pointing to a path on a provider, returns a URL that is suitable\n * for downloading the subtree.\n *\n * @param url - A URL pointing to a path\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketServerDownloadUrl(\n url: string,\n config: BitbucketServerIntegrationConfig,\n): Promise<string> {\n const {
|
|
1
|
+
{"version":3,"file":"core.esm.js","sources":["../../src/bitbucketServer/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 parseGitUrl from 'git-url-parse';\nimport { parseGitUrlSafe } from '../helpers';\nimport { BitbucketServerIntegrationConfig } from './config';\n\n/**\n * Given a URL pointing to a path on a provider, returns the default branch.\n *\n * @param url - A URL pointing to a path\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketServerDefaultBranch(\n url: string,\n config: BitbucketServerIntegrationConfig,\n): Promise<string> {\n const { name: repoName, owner: project } = parseGitUrl(url);\n\n // Bitbucket Server https://docs.atlassian.com/bitbucket-server/rest/7.9.0/bitbucket-rest.html#idp184\n let branchUrl = `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/default-branch`;\n\n let response = await fetch(\n branchUrl,\n getBitbucketServerRequestOptions(config),\n );\n\n if (response.status === 404) {\n // First try the new format, and then if it gets specifically a 404 it should try the old format\n // (to support old Atlassian Bitbucket Server v5.11.1 format )\n branchUrl = `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/branches/default`;\n response = await fetch(branchUrl, getBitbucketServerRequestOptions(config));\n }\n\n if (!response.ok) {\n const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`;\n throw new Error(message);\n }\n\n const { displayId } = await response.json();\n const defaultBranch = displayId;\n if (!defaultBranch) {\n throw new Error(\n `Failed to read default branch from ${branchUrl}. ` +\n `Response ${response.status} ${response.json()}`,\n );\n }\n return defaultBranch;\n}\n\n/**\n * Given a URL pointing to a path on a provider, returns a URL that is suitable\n * for downloading the subtree.\n *\n * @param url - A URL pointing to a path\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketServerDownloadUrl(\n url: string,\n config: BitbucketServerIntegrationConfig,\n): Promise<string> {\n const {\n name: repoName,\n owner: project,\n ref,\n filepath,\n } = parseGitUrlSafe(url);\n\n let branch = ref;\n if (!branch) {\n branch = await getBitbucketServerDefaultBranch(url, config);\n }\n // path will limit the downloaded content\n // /docs will only download the docs folder and everything below it\n // /docs/index.md will download the docs folder and everything below it\n const path = filepath\n ? `&path=${encodeURIComponent(decodeURIComponent(filepath))}`\n : '';\n return `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/archive?format=tgz&at=${branch}&prefix=${project}-${repoName}${path}`;\n}\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://bitbucket.company.com/projectname/reponame/src/main/file.yaml\n * to: https://bitbucket.company.com/rest/api/1.0/project/projectname/reponame/raw/file.yaml?at=main\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getBitbucketServerFileFetchUrl(\n url: string,\n config: BitbucketServerIntegrationConfig,\n): string {\n try {\n const { owner, name, ref, filepathtype, filepath } = parseGitUrlSafe(url);\n if (\n !owner ||\n !name ||\n (filepathtype !== 'browse' &&\n filepathtype !== 'raw' &&\n filepathtype !== 'src')\n ) {\n throw new Error('Invalid Bitbucket Server URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n return `${config.apiBaseUrl}/projects/${owner}/repos/${name}/raw/${pathWithoutSlash}?at=${ref}`;\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\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 getBitbucketServerRequestOptions(\n config: BitbucketServerIntegrationConfig,\n): { headers: Record<string, string> } {\n const headers: Record<string, string> = {};\n\n if (config.token) {\n headers.Authorization = `Bearer ${config.token}`;\n } else if (config.username && config.password) {\n const buffer = Buffer.from(`${config.username}:${config.password}`, 'utf8');\n headers.Authorization = `Basic ${buffer.toString('base64')}`;\n }\n\n return {\n headers,\n };\n}\n"],"names":[],"mappings":";;;;AA4BA,eAAsB,+BAAA,CACpB,KACA,MAAA,EACiB;AACjB,EAAA,MAAM,EAAE,IAAA,EAAM,QAAA,EAAU,OAAO,OAAA,EAAQ,GAAI,YAAY,GAAG,CAAA;AAG1D,EAAA,IAAI,YAAY,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,UAAA,EAAa,OAAO,UAAU,QAAQ,CAAA,eAAA,CAAA;AAE1E,EAAA,IAAI,WAAW,MAAM,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,QAAA,IAAY,MAAA,CAAO,QAAA,EAAU;AAC7C,IAAA,MAAM,MAAA,GAAS,MAAA,CAAO,IAAA,CAAK,CAAA,EAAG,MAAA,CAAO,QAAQ,CAAA,CAAA,EAAI,MAAA,CAAO,QAAQ,CAAA,CAAA,EAAI,MAAM,CAAA;AAC1E,IAAA,OAAA,CAAQ,aAAA,GAAgB,CAAA,MAAA,EAAS,MAAA,CAAO,QAAA,CAAS,QAAQ,CAAC,CAAA,CAAA;AAAA,EAC5D;AAEA,EAAA,OAAO;AAAA,IACL;AAAA,GACF;AACF;;;;"}
|
package/dist/github/core.cjs.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
6
|
-
|
|
7
|
-
var parseGitUrl__default = /*#__PURE__*/_interopDefaultCompat(parseGitUrl);
|
|
3
|
+
var helpers = require('../helpers.cjs.js');
|
|
8
4
|
|
|
9
5
|
function getGithubFileFetchUrl(url, config, credentials) {
|
|
10
6
|
try {
|
|
11
|
-
const { owner, name, ref, filepathtype, filepath } =
|
|
7
|
+
const { owner, name, ref, filepathtype, filepath } = helpers.parseGitUrlSafe(url);
|
|
12
8
|
if (!owner || !name || !ref || // GitHub is automatically redirecting tree urls to blob urls so it's
|
|
13
9
|
// fine to pass a tree url.
|
|
14
10
|
filepathtype !== "blob" && filepathtype !== "raw" && filepathtype !== "tree") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.cjs.js","sources":["../../src/github/core.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport
|
|
1
|
+
{"version":3,"file":"core.cjs.js","sources":["../../src/github/core.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { GithubIntegrationConfig } from './config';\nimport { parseGitUrlSafe } from '../helpers';\nimport { GithubCredentials } from './types';\n\n/**\n * Given a URL pointing to a file on a provider, returns a URL that is suitable\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://github.com/a/b/blob/branchname/path/to/c.yaml\n * to: https://api.github.com/repos/a/b/contents/path/to/c.yaml?ref=branchname\n * or: https://raw.githubusercontent.com/a/b/branchname/c.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getGithubFileFetchUrl(\n url: string,\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): string {\n try {\n const { owner, name, ref, filepathtype, filepath } = parseGitUrlSafe(url);\n if (\n !owner ||\n !name ||\n !ref ||\n // GitHub is automatically redirecting tree urls to blob urls so it's\n // fine to pass a tree url.\n (filepathtype !== 'blob' &&\n filepathtype !== 'raw' &&\n filepathtype !== 'tree')\n ) {\n throw new Error('Invalid GitHub URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n if (chooseEndpoint(config, credentials) === 'api') {\n return `${config.apiBaseUrl}/repos/${owner}/${name}/contents/${pathWithoutSlash}?ref=${ref}`;\n }\n return `${config.rawBaseUrl}/${owner}/${name}/${ref}/${pathWithoutSlash}`;\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n\nexport function chooseEndpoint(\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): 'api' | 'raw' {\n if (config.apiBaseUrl && (credentials.token || !config.rawBaseUrl)) {\n return 'api';\n }\n return 'raw';\n}\n"],"names":["parseGitUrlSafe"],"mappings":";;;;AAmCO,SAAS,qBAAA,CACd,GAAA,EACA,MAAA,EACA,WAAA,EACQ;AACR,EAAA,IAAI;AACF,IAAA,MAAM,EAAE,OAAO,IAAA,EAAM,GAAA,EAAK,cAAc,QAAA,EAAS,GAAIA,wBAAgB,GAAG,CAAA;AACxE,IAAA,IACE,CAAC,KAAA,IACD,CAAC,IAAA,IACD,CAAC,GAAA;AAAA;AAAA,IAGA,YAAA,KAAiB,MAAA,IAChB,YAAA,KAAiB,KAAA,IACjB,iBAAiB,MAAA,EACnB;AACA,MAAA,MAAM,IAAI,MAAM,iCAAiC,CAAA;AAAA,IACnD;AAEA,IAAA,MAAM,gBAAA,GAAmB,QAAA,CAAS,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AACnD,IAAA,IAAI,cAAA,CAAe,MAAA,EAAQ,WAAW,CAAA,KAAM,KAAA,EAAO;AACjD,MAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,OAAA,EAAU,KAAK,IAAI,IAAI,CAAA,UAAA,EAAa,gBAAgB,CAAA,KAAA,EAAQ,GAAG,CAAA,CAAA;AAAA,IAC5F;AACA,IAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,CAAA,EAAI,KAAK,IAAI,IAAI,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,EAAI,gBAAgB,CAAA,CAAA;AAAA,EACzE,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EAC/C;AACF;AAEO,SAAS,cAAA,CACd,QACA,WAAA,EACe;AACf,EAAA,IAAI,OAAO,UAAA,KAAe,WAAA,CAAY,KAAA,IAAS,CAAC,OAAO,UAAA,CAAA,EAAa;AAClE,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,KAAA;AACT;;;;;"}
|
package/dist/github/core.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { parseGitUrlSafe } from '../helpers.esm.js';
|
|
2
2
|
|
|
3
3
|
function getGithubFileFetchUrl(url, config, credentials) {
|
|
4
4
|
try {
|
|
5
|
-
const { owner, name, ref, filepathtype, filepath } =
|
|
5
|
+
const { owner, name, ref, filepathtype, filepath } = parseGitUrlSafe(url);
|
|
6
6
|
if (!owner || !name || !ref || // GitHub is automatically redirecting tree urls to blob urls so it's
|
|
7
7
|
// fine to pass a tree url.
|
|
8
8
|
filepathtype !== "blob" && filepathtype !== "raw" && filepathtype !== "tree") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.esm.js","sources":["../../src/github/core.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport
|
|
1
|
+
{"version":3,"file":"core.esm.js","sources":["../../src/github/core.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { GithubIntegrationConfig } from './config';\nimport { parseGitUrlSafe } from '../helpers';\nimport { GithubCredentials } from './types';\n\n/**\n * Given a URL pointing to a file on a provider, returns a URL that is suitable\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://github.com/a/b/blob/branchname/path/to/c.yaml\n * to: https://api.github.com/repos/a/b/contents/path/to/c.yaml?ref=branchname\n * or: https://raw.githubusercontent.com/a/b/branchname/c.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getGithubFileFetchUrl(\n url: string,\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): string {\n try {\n const { owner, name, ref, filepathtype, filepath } = parseGitUrlSafe(url);\n if (\n !owner ||\n !name ||\n !ref ||\n // GitHub is automatically redirecting tree urls to blob urls so it's\n // fine to pass a tree url.\n (filepathtype !== 'blob' &&\n filepathtype !== 'raw' &&\n filepathtype !== 'tree')\n ) {\n throw new Error('Invalid GitHub URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n if (chooseEndpoint(config, credentials) === 'api') {\n return `${config.apiBaseUrl}/repos/${owner}/${name}/contents/${pathWithoutSlash}?ref=${ref}`;\n }\n return `${config.rawBaseUrl}/${owner}/${name}/${ref}/${pathWithoutSlash}`;\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n\nexport function chooseEndpoint(\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): 'api' | 'raw' {\n if (config.apiBaseUrl && (credentials.token || !config.rawBaseUrl)) {\n return 'api';\n }\n return 'raw';\n}\n"],"names":[],"mappings":";;AAmCO,SAAS,qBAAA,CACd,GAAA,EACA,MAAA,EACA,WAAA,EACQ;AACR,EAAA,IAAI;AACF,IAAA,MAAM,EAAE,OAAO,IAAA,EAAM,GAAA,EAAK,cAAc,QAAA,EAAS,GAAI,gBAAgB,GAAG,CAAA;AACxE,IAAA,IACE,CAAC,KAAA,IACD,CAAC,IAAA,IACD,CAAC,GAAA;AAAA;AAAA,IAGA,YAAA,KAAiB,MAAA,IAChB,YAAA,KAAiB,KAAA,IACjB,iBAAiB,MAAA,EACnB;AACA,MAAA,MAAM,IAAI,MAAM,iCAAiC,CAAA;AAAA,IACnD;AAEA,IAAA,MAAM,gBAAA,GAAmB,QAAA,CAAS,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AACnD,IAAA,IAAI,cAAA,CAAe,MAAA,EAAQ,WAAW,CAAA,KAAM,KAAA,EAAO;AACjD,MAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,OAAA,EAAU,KAAK,IAAI,IAAI,CAAA,UAAA,EAAa,gBAAgB,CAAA,KAAA,EAAQ,GAAG,CAAA,CAAA;AAAA,IAC5F;AACA,IAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,CAAA,EAAI,KAAK,IAAI,IAAI,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,EAAI,gBAAgB,CAAA,CAAA;AAAA,EACzE,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EAC/C;AACF;AAEO,SAAS,cAAA,CACd,QACA,WAAA,EACe;AACf,EAAA,IAAI,OAAO,UAAA,KAAe,WAAA,CAAY,KAAA,IAAS,CAAC,OAAO,UAAA,CAAA,EAAa;AAClE,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,KAAA;AACT;;;;"}
|
package/dist/helpers.cjs.js
CHANGED
|
@@ -7,6 +7,27 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
7
7
|
|
|
8
8
|
var parseGitUrl__default = /*#__PURE__*/_interopDefaultCompat(parseGitUrl);
|
|
9
9
|
|
|
10
|
+
function parseGitUrlSafe(url) {
|
|
11
|
+
const parsed = parseGitUrl__default.default(url);
|
|
12
|
+
if (parsed.filepath) {
|
|
13
|
+
let decoded = parsed.filepath;
|
|
14
|
+
let previous;
|
|
15
|
+
do {
|
|
16
|
+
previous = decoded;
|
|
17
|
+
try {
|
|
18
|
+
decoded = decodeURIComponent(decoded);
|
|
19
|
+
} catch {
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
} while (decoded !== previous);
|
|
23
|
+
if (decoded.split("/").some((segment) => segment === ".." || segment === ".")) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
"Invalid SCM URL: path traversal is not allowed in the URL"
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return parsed;
|
|
30
|
+
}
|
|
10
31
|
function isValidHost(host) {
|
|
11
32
|
const check = new URL("http://example.com");
|
|
12
33
|
check.host = host;
|
|
@@ -47,7 +68,7 @@ function defaultScmResolveUrl(options) {
|
|
|
47
68
|
}
|
|
48
69
|
let updated;
|
|
49
70
|
if (url.startsWith("/")) {
|
|
50
|
-
const { href, filepath } =
|
|
71
|
+
const { href, filepath } = parseGitUrlSafe(base);
|
|
51
72
|
updated = new URL(href);
|
|
52
73
|
const repoRootPath = lodash.trimEnd(
|
|
53
74
|
updated.pathname.substring(0, updated.pathname.length - filepath.length),
|
|
@@ -68,4 +89,5 @@ exports.basicIntegrations = basicIntegrations;
|
|
|
68
89
|
exports.defaultScmResolveUrl = defaultScmResolveUrl;
|
|
69
90
|
exports.isValidHost = isValidHost;
|
|
70
91
|
exports.isValidUrl = isValidUrl;
|
|
92
|
+
exports.parseGitUrlSafe = parseGitUrlSafe;
|
|
71
93
|
//# sourceMappingURL=helpers.cjs.js.map
|
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 } =
|
|
1
|
+
{"version":3,"file":"helpers.cjs.js","sources":["../src/helpers.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport parseGitUrl from 'git-url-parse';\nimport { trimEnd } from 'lodash';\nimport { ScmIntegration, ScmIntegrationsGroup } from './types';\n\n/**\n * Wraps git-url-parse and rejects URLs whose filepath contains path traversal\n * segments. Without this check, a URL like\n * `https://github.com/o/r/blob/main/%2e%2e%2f%2e%2e%2fuser/repos` would be\n * decoded to `../../user/repos` and could escape the expected API path when\n * interpolated into provider API URLs.\n */\nexport function parseGitUrlSafe(url: string) {\n const parsed = parseGitUrl(url);\n if (parsed.filepath) {\n let decoded = parsed.filepath;\n let previous;\n do {\n previous = decoded;\n try {\n decoded = decodeURIComponent(decoded);\n } catch {\n break;\n }\n } while (decoded !== previous);\n\n if (\n decoded.split('/').some(segment => segment === '..' || segment === '.')\n ) {\n throw new Error(\n 'Invalid SCM URL: path traversal is not allowed in the URL',\n );\n }\n }\n return parsed;\n}\n\n/** Checks whether the given argument is a valid URL hostname */\nexport function isValidHost(host: string): boolean {\n const check = new URL('http://example.com');\n check.host = host;\n return check.host === host;\n}\n\n/** Checks whether the given argument is a valid URL */\nexport function isValidUrl(url: string): boolean {\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function basicIntegrations<T extends ScmIntegration>(\n integrations: T[],\n getHost: (integration: T) => string,\n): ScmIntegrationsGroup<T> {\n return {\n list(): T[] {\n return integrations;\n },\n byUrl(url: string | URL): T | undefined {\n try {\n const parsed = typeof url === 'string' ? new URL(url) : url;\n return integrations.find(i => getHost(i) === parsed.host);\n } catch {\n return undefined;\n }\n },\n byHost(host: string): T | undefined {\n return integrations.find(i => getHost(i) === host);\n },\n };\n}\n\n/**\n * Default implementation of {@link ScmIntegration} `resolveUrl`, that only\n * works with URL pathname based providers.\n *\n * @public\n */\nexport function defaultScmResolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n}): string {\n const { url, base, lineNumber } = options;\n\n // If it is a fully qualified URL - then return it verbatim\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return url;\n } catch {\n // ignore intentionally\n }\n\n let updated: URL;\n\n if (url.startsWith('/')) {\n // If it is an absolute path, move relative to the repo root\n const { href, filepath } = parseGitUrlSafe(base);\n\n updated = new URL(href);\n\n const repoRootPath = trimEnd(\n updated.pathname.substring(0, updated.pathname.length - filepath.length),\n '/',\n );\n updated.pathname = `${repoRootPath}${url}`;\n } else {\n // For relative URLs, just let the default URL constructor handle the\n // resolving. Note that this essentially will treat the last segment of the\n // base as a file - NOT a folder - unless the url ends in a slash.\n updated = new URL(url, base);\n }\n\n updated.search = new URL(base).search;\n if (lineNumber) {\n updated.hash = `L${lineNumber}`;\n }\n return updated.toString();\n}\n\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":";;;;;;;;;AA2BO,SAAS,gBAAgB,GAAA,EAAa;AAC3C,EAAA,MAAM,MAAA,GAASA,6BAAY,GAAG,CAAA;AAC9B,EAAA,IAAI,OAAO,QAAA,EAAU;AACnB,IAAA,IAAI,UAAU,MAAA,CAAO,QAAA;AACrB,IAAA,IAAI,QAAA;AACJ,IAAA,GAAG;AACD,MAAA,QAAA,GAAW,OAAA;AACX,MAAA,IAAI;AACF,QA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
|
|
|
4
|
+
function parseGitUrlSafe(url) {
|
|
5
|
+
const parsed = parseGitUrl(url);
|
|
6
|
+
if (parsed.filepath) {
|
|
7
|
+
let decoded = parsed.filepath;
|
|
8
|
+
let previous;
|
|
9
|
+
do {
|
|
10
|
+
previous = decoded;
|
|
11
|
+
try {
|
|
12
|
+
decoded = decodeURIComponent(decoded);
|
|
13
|
+
} catch {
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
} while (decoded !== previous);
|
|
17
|
+
if (decoded.split("/").some((segment) => segment === ".." || segment === ".")) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
"Invalid SCM URL: path traversal is not allowed in the URL"
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return parsed;
|
|
24
|
+
}
|
|
4
25
|
function isValidHost(host) {
|
|
5
26
|
const check = new URL("http://example.com");
|
|
6
27
|
check.host = host;
|
|
@@ -41,7 +62,7 @@ function defaultScmResolveUrl(options) {
|
|
|
41
62
|
}
|
|
42
63
|
let updated;
|
|
43
64
|
if (url.startsWith("/")) {
|
|
44
|
-
const { href, filepath } =
|
|
65
|
+
const { href, filepath } = parseGitUrlSafe(base);
|
|
45
66
|
updated = new URL(href);
|
|
46
67
|
const repoRootPath = trimEnd(
|
|
47
68
|
updated.pathname.substring(0, updated.pathname.length - filepath.length),
|
|
@@ -58,5 +79,5 @@ function defaultScmResolveUrl(options) {
|
|
|
58
79
|
return updated.toString();
|
|
59
80
|
}
|
|
60
81
|
|
|
61
|
-
export { basicIntegrations, defaultScmResolveUrl, isValidHost, isValidUrl };
|
|
82
|
+
export { basicIntegrations, defaultScmResolveUrl, isValidHost, isValidUrl, parseGitUrlSafe };
|
|
62
83
|
//# sourceMappingURL=helpers.esm.js.map
|
package/dist/helpers.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 } =
|
|
1
|
+
{"version":3,"file":"helpers.esm.js","sources":["../src/helpers.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport parseGitUrl from 'git-url-parse';\nimport { trimEnd } from 'lodash';\nimport { ScmIntegration, ScmIntegrationsGroup } from './types';\n\n/**\n * Wraps git-url-parse and rejects URLs whose filepath contains path traversal\n * segments. Without this check, a URL like\n * `https://github.com/o/r/blob/main/%2e%2e%2f%2e%2e%2fuser/repos` would be\n * decoded to `../../user/repos` and could escape the expected API path when\n * interpolated into provider API URLs.\n */\nexport function parseGitUrlSafe(url: string) {\n const parsed = parseGitUrl(url);\n if (parsed.filepath) {\n let decoded = parsed.filepath;\n let previous;\n do {\n previous = decoded;\n try {\n decoded = decodeURIComponent(decoded);\n } catch {\n break;\n }\n } while (decoded !== previous);\n\n if (\n decoded.split('/').some(segment => segment === '..' || segment === '.')\n ) {\n throw new Error(\n 'Invalid SCM URL: path traversal is not allowed in the URL',\n );\n }\n }\n return parsed;\n}\n\n/** Checks whether the given argument is a valid URL hostname */\nexport function isValidHost(host: string): boolean {\n const check = new URL('http://example.com');\n check.host = host;\n return check.host === host;\n}\n\n/** Checks whether the given argument is a valid URL */\nexport function isValidUrl(url: string): boolean {\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function basicIntegrations<T extends ScmIntegration>(\n integrations: T[],\n getHost: (integration: T) => string,\n): ScmIntegrationsGroup<T> {\n return {\n list(): T[] {\n return integrations;\n },\n byUrl(url: string | URL): T | undefined {\n try {\n const parsed = typeof url === 'string' ? new URL(url) : url;\n return integrations.find(i => getHost(i) === parsed.host);\n } catch {\n return undefined;\n }\n },\n byHost(host: string): T | undefined {\n return integrations.find(i => getHost(i) === host);\n },\n };\n}\n\n/**\n * Default implementation of {@link ScmIntegration} `resolveUrl`, that only\n * works with URL pathname based providers.\n *\n * @public\n */\nexport function defaultScmResolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n}): string {\n const { url, base, lineNumber } = options;\n\n // If it is a fully qualified URL - then return it verbatim\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return url;\n } catch {\n // ignore intentionally\n }\n\n let updated: URL;\n\n if (url.startsWith('/')) {\n // If it is an absolute path, move relative to the repo root\n const { href, filepath } = parseGitUrlSafe(base);\n\n updated = new URL(href);\n\n const repoRootPath = trimEnd(\n updated.pathname.substring(0, updated.pathname.length - filepath.length),\n '/',\n );\n updated.pathname = `${repoRootPath}${url}`;\n } else {\n // For relative URLs, just let the default URL constructor handle the\n // resolving. Note that this essentially will treat the last segment of the\n // base as a file - NOT a folder - unless the url ends in a slash.\n updated = new URL(url, base);\n }\n\n updated.search = new URL(base).search;\n if (lineNumber) {\n updated.hash = `L${lineNumber}`;\n }\n return updated.toString();\n}\n\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":";;;AA2BO,SAAS,gBAAgB,GAAA,EAAa;AAC3C,EAAA,MAAM,MAAA,GAAS,YAAY,GAAG,CAAA;AAC9B,EAAA,IAAI,OAAO,QAAA,EAAU;AACnB,IAAA,IAAI,UAAU,MAAA,CAAO,QAAA;AACrB,IAAA,IAAI,QAAA;AACJ,IAAA,GAAG;AACD,MAAA,QAAA,GAAW,OAAA;AACX,MAAA,IAAI;AACF,QAAA,OAAA,GAAU,mBAAmB,OAAO,CAAA;AAAA,MACtC,CAAA,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A,IACnD;AAAA,GACF;AACF;AAQO,SAAS,qBAAqB,OAAA,EAI1B;AACT,EAAA,MAAM,EAAE,GAAA,EAAK,IAAA,EAAM,UAAA,EAAW,GAAI,OAAA;AAGlC,EAAA,IAAI;AAEF,IAAA,IAAI,IAAI,GAAG,CAAA;AACX,IAAA,OAAO,GAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AAAA,EAER;AAEA,EAAA,IAAI,OAAA;AAEJ,EAAA,IAAI,GAAA,CAAI,UAAA,CAAW,GAAG,CAAA,EAAG;AAEvB,IAAA,MAAM,EAAE,IAAA,EAAM,QAAA,EAAS,GAAI,gBAAgB,IAAI,CAAA;AAE/C,IAAA,OAAA,GAAU,IAAI,IAAI,IAAI,CAAA;AAEtB,IAAA,MAAM,YAAA,GAAe,OAAA;AAAA,MACnB,OAAA,CAAQ,SAAS,SAAA,CAAU,CAAA,EAAG,QAAQ,QAAA,CAAS,MAAA,GAAS,SAAS,MAAM,CAAA;AAAA,MACvE;AAAA,KACF;AACA,IAAA,OAAA,CAAQ,QAAA,GAAW,CAAA,EAAG,YAAY,CAAA,EAAG,GAAG,CAAA,CAAA;AAAA,EAC1C,CAAA,MAAO;AAIL,IAAA,OAAA,GAAU,IAAI,GAAA,CAAI,GAAA,EAAK,IAAI,CAAA;AAAA,EAC7B;AAEA,EAAA,OAAA,CAAQ,MAAA,GAAS,IAAI,GAAA,CAAI,IAAI,CAAA,CAAE,MAAA;AAC/B,EAAA,IAAI,UAAA,EAAY;AACd,IAAA,OAAA,CAAQ,IAAA,GAAO,IAAI,UAAU,CAAA,CAAA;AAAA,EAC/B;AACA,EAAA,OAAO,QAAQ,QAAA,EAAS;AAC1B;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/integration",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Helpers for managing integrations towards external systems",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "common-library"
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@azure/identity": "^4.0.0",
|
|
41
41
|
"@azure/storage-blob": "^12.5.0",
|
|
42
|
-
"@backstage/config": "1.3.6",
|
|
43
|
-
"@backstage/errors": "1.2.7",
|
|
42
|
+
"@backstage/config": "^1.3.6",
|
|
43
|
+
"@backstage/errors": "^1.2.7",
|
|
44
44
|
"@octokit/auth-app": "^4.0.0",
|
|
45
45
|
"@octokit/rest": "^19.0.3",
|
|
46
46
|
"cross-fetch": "^4.0.0",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"p-throttle": "^4.1.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@backstage/cli": "0.36.0
|
|
54
|
-
"@backstage/config-loader": "1.10.9
|
|
53
|
+
"@backstage/cli": "^0.36.0",
|
|
54
|
+
"@backstage/config-loader": "^1.10.9",
|
|
55
55
|
"msw": "^1.0.0"
|
|
56
56
|
},
|
|
57
57
|
"configSchema": "config.d.ts",
|