@backstage/integration 1.4.2-next.0 → 1.4.3-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @backstage/integration
2
2
 
3
+ ## 1.4.3-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 52b0022dab7: Updated dependency `msw` to `^1.0.0`.
8
+ - Updated dependencies
9
+ - @backstage/errors@1.1.5-next.0
10
+ - @backstage/config@1.0.7-next.0
11
+
12
+ ## 1.4.2
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies
17
+ - @backstage/config@1.0.6
18
+ - @backstage/errors@1.1.4
19
+
3
20
  ## 1.4.2-next.0
4
21
 
5
22
  ### Patch Changes
package/dist/index.cjs.js CHANGED
@@ -193,6 +193,11 @@ const _AzureUrl = class {
193
193
  __privateSet(this, _path, path);
194
194
  __privateSet(this, _ref, ref);
195
195
  }
196
+ /**
197
+ * Parses an azure URL as copied from the browser address bar.
198
+ *
199
+ * Throws an error if the URL is not a valid azure repo URL.
200
+ */
196
201
  static fromRepoUrl(repoUrl) {
197
202
  var _a;
198
203
  const url = new URL(repoUrl);
@@ -227,6 +232,11 @@ const _AzureUrl = class {
227
232
  }
228
233
  return new _AzureUrl(url.origin, owner, project, repo, path, ref);
229
234
  }
235
+ /**
236
+ * Returns a repo URL that can be used to navigate to the resource in azure.
237
+ *
238
+ * Throws an error if the URL is not a valid azure repo URL.
239
+ */
230
240
  toRepoUrl() {
231
241
  let url;
232
242
  if (__privateGet(this, _project) === __privateGet(this, _repo)) {
@@ -242,6 +252,11 @@ const _AzureUrl = class {
242
252
  }
243
253
  return url.toString();
244
254
  }
255
+ /**
256
+ * Returns the file download URL for this azure resource.
257
+ *
258
+ * Throws an error if the URL does not point to a file.
259
+ */
245
260
  toFileUrl() {
246
261
  if (!__privateGet(this, _path)) {
247
262
  throw new Error(
@@ -256,6 +271,11 @@ const _AzureUrl = class {
256
271
  }
257
272
  return url.toString();
258
273
  }
274
+ /**
275
+ * Returns the archive download URL for this azure resource.
276
+ *
277
+ * Throws an error if the URL does not point to a repo.
278
+ */
259
279
  toArchiveUrl() {
260
280
  const url = __privateGet(this, _baseUrl).call(this, __privateGet(this, _owner), __privateGet(this, _project), "_apis", "git", "repositories", __privateGet(this, _repo), "items");
261
281
  url.searchParams.set("recursionLevel", "full");
@@ -269,6 +289,11 @@ const _AzureUrl = class {
269
289
  }
270
290
  return url.toString();
271
291
  }
292
+ /**
293
+ * Returns the API url for fetching commits from a branch for this azure resource.
294
+ *
295
+ * Throws an error if the URL does not point to a commit.
296
+ */
272
297
  toCommitsUrl() {
273
298
  const url = __privateGet(this, _baseUrl).call(this, __privateGet(this, _owner), __privateGet(this, _project), "_apis", "git", "repositories", __privateGet(this, _repo), "commits");
274
299
  url.searchParams.set("api-version", "6.0");
@@ -277,18 +302,33 @@ const _AzureUrl = class {
277
302
  }
278
303
  return url.toString();
279
304
  }
305
+ /**
306
+ * Returns the name of the owner, a user or an organization.
307
+ */
280
308
  getOwner() {
281
309
  return __privateGet(this, _owner);
282
310
  }
311
+ /**
312
+ * Returns the name of the project.
313
+ */
283
314
  getProject() {
284
315
  return __privateGet(this, _project);
285
316
  }
317
+ /**
318
+ * Returns the name of the repo.
319
+ */
286
320
  getRepo() {
287
321
  return __privateGet(this, _repo);
288
322
  }
323
+ /**
324
+ * Returns the file path within the repo if the URL contains one.
325
+ */
289
326
  getPath() {
290
327
  return __privateGet(this, _path);
291
328
  }
329
+ /**
330
+ * Returns the git ref in the repo if the URL contains one.
331
+ */
292
332
  getRef() {
293
333
  return __privateGet(this, _ref);
294
334
  }
@@ -335,6 +375,11 @@ const _AzureIntegration = class {
335
375
  get config() {
336
376
  return this.integrationConfig;
337
377
  }
378
+ /*
379
+ * Azure repo URLs on the form with a `path` query param are treated specially.
380
+ *
381
+ * Example base URL: https://dev.azure.com/organization/project/_git/repository?path=%2Fcatalog-info.yaml
382
+ */
338
383
  resolveUrl(options) {
339
384
  var _a;
340
385
  const { url, base } = options;
@@ -474,6 +519,9 @@ BitbucketIntegration.factory = ({
474
519
  var _a, _b, _c;
475
520
  const configs = readBitbucketIntegrationConfigs(
476
521
  (_c = config.getOptionalConfigArray("integrations.bitbucket")) != null ? _c : [
522
+ // if integrations.bitbucket was not used assume the use was migrated to the new configs
523
+ // and backport for the deprecated integration to be usable for other parts of the system
524
+ // until these got migrated
477
525
  ...(_a = config.getOptionalConfigArray("integrations.bitbucketCloud")) != null ? _a : [],
478
526
  ...(_b = config.getOptionalConfigArray("integrations.bitbucketServer")) != null ? _b : []
479
527
  ]
@@ -1140,7 +1188,9 @@ function readGithubIntegrationConfigs(configs) {
1140
1188
  function getGithubFileFetchUrl(url, config, credentials) {
1141
1189
  try {
1142
1190
  const { owner, name, ref, filepathtype, filepath } = parseGitUrl__default["default"](url);
1143
- if (!owner || !name || !ref || filepathtype !== "blob" && filepathtype !== "raw" && filepathtype !== "tree") {
1191
+ if (!owner || !name || !ref || // GitHub is automatically redirecting tree urls to blob urls so it's
1192
+ // fine to pass a tree url.
1193
+ filepathtype !== "blob" && filepathtype !== "raw" && filepathtype !== "tree") {
1144
1194
  throw new Error("Invalid GitHub URL or file path");
1145
1195
  }
1146
1196
  const pathWithoutSlash = filepath.replace(/^\//, "");
@@ -1202,6 +1252,7 @@ const HEADERS = {
1202
1252
  Accept: "application/vnd.github.machine-man-preview+json"
1203
1253
  };
1204
1254
  class GithubAppManager {
1255
+ // undefined allows all installations
1205
1256
  constructor(config, baseUrl) {
1206
1257
  this.cache = new Cache();
1207
1258
  this.allowedInstallationOwners = config.allowedInstallationOwners;
@@ -1322,6 +1373,26 @@ const _SingleInstanceGithubCredentialsProvider = class {
1322
1373
  this.githubAppCredentialsMux = githubAppCredentialsMux;
1323
1374
  this.token = token;
1324
1375
  }
1376
+ /**
1377
+ * Returns {@link GithubCredentials} for a given URL.
1378
+ *
1379
+ * @remarks
1380
+ *
1381
+ * Consecutive calls to this method with the same URL will return cached
1382
+ * credentials.
1383
+ *
1384
+ * The shortest lifetime for a token returned is 10 minutes.
1385
+ *
1386
+ * @example
1387
+ * ```ts
1388
+ * const { token, headers } = await getCredentials({
1389
+ * url: 'github.com/backstage/foobar'
1390
+ * })
1391
+ * ```
1392
+ *
1393
+ * @param opts - The organization or repository URL
1394
+ * @returns A promise of {@link GithubCredentials}.
1395
+ */
1325
1396
  async getCredentials(opts) {
1326
1397
  const parsed = parseGitUrl__default["default"](opts.url);
1327
1398
  const owner = parsed.owner || parsed.name;
@@ -1359,6 +1430,30 @@ class DefaultGithubCredentialsProvider {
1359
1430
  });
1360
1431
  return new DefaultGithubCredentialsProvider(credentialsProviders);
1361
1432
  }
1433
+ /**
1434
+ * Returns {@link GithubCredentials} for a given URL.
1435
+ *
1436
+ * @remarks
1437
+ *
1438
+ * Consecutive calls to this method with the same URL will return cached
1439
+ * credentials.
1440
+ *
1441
+ * The shortest lifetime for a token returned is 10 minutes.
1442
+ *
1443
+ * @example
1444
+ * ```ts
1445
+ * const { token, headers } = await getCredentials({
1446
+ * url: 'https://github.com/backstage/foobar'
1447
+ * })
1448
+ *
1449
+ * const { token, headers } = await getCredentials({
1450
+ * url: 'https://github.com/backstage'
1451
+ * })
1452
+ * ```
1453
+ *
1454
+ * @param opts - The organization or repository URL
1455
+ * @returns A promise of {@link GithubCredentials}.
1456
+ */
1362
1457
  async getCredentials(opts) {
1363
1458
  const parsed = new URL(opts.url);
1364
1459
  const provider = this.providers.get(parsed.host);
@@ -1610,6 +1705,9 @@ class ScmIntegrations {
1610
1705
  get azure() {
1611
1706
  return this.byType.azure;
1612
1707
  }
1708
+ /**
1709
+ * @deprecated in favor of `bitbucketCloud()` and `bitbucketServer()`
1710
+ */
1613
1711
  get bitbucket() {
1614
1712
  return this.byType.bitbucket;
1615
1713
  }