@backstage/integration 0.7.3 → 0.7.4

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,13 @@
1
1
  # @backstage/integration
2
2
 
3
+ ## 0.7.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix for the previous release with missing type declarations.
8
+ - Updated dependencies
9
+ - @backstage/config@0.1.15
10
+
3
11
  ## 0.7.3
4
12
 
5
13
  ### Patch Changes
@@ -0,0 +1,866 @@
1
+ import { Config } from '@backstage/config';
2
+ import { RestEndpointMethodTypes } from '@octokit/rest';
3
+
4
+ /**
5
+ * Encapsulates a single SCM integration.
6
+ *
7
+ * @public
8
+ */
9
+ interface ScmIntegration {
10
+ /**
11
+ * The type of integration, e.g. "github".
12
+ */
13
+ type: string;
14
+ /**
15
+ * A human readable title for the integration, that can be shown to users to
16
+ * differentiate between different integrations.
17
+ */
18
+ title: string;
19
+ /**
20
+ * Resolves an absolute or relative URL in relation to a base URL.
21
+ *
22
+ * This method is adapted for use within SCM systems, so relative URLs are
23
+ * within the context of the root of the hierarchy pointed to by the base
24
+ * URL.
25
+ *
26
+ * For example, if the base URL is `<repo root url>/folder/a.yaml`, i.e.
27
+ * within the file tree of a certain repo, an absolute path of `/b.yaml` does
28
+ * not resolve to `https://hostname/b.yaml` but rather to
29
+ * `<repo root url>/b.yaml` inside the file tree of that same repo.
30
+ */
31
+ resolveUrl(options: {
32
+ /**
33
+ * The (absolute or relative) URL or path to resolve
34
+ */
35
+ url: string;
36
+ /**
37
+ * The base URL onto which this resolution happens
38
+ */
39
+ base: string;
40
+ /**
41
+ * The line number in the target file to link to, starting with 1. Only applicable when linking to files.
42
+ */
43
+ lineNumber?: number;
44
+ }): string;
45
+ /**
46
+ * Resolves the edit URL for a file within the SCM system.
47
+ *
48
+ * Most SCM systems have a web interface that allows viewing and editing files
49
+ * in the repository. The returned URL directly jumps into the edit mode for
50
+ * the file.
51
+ * If this is not possible, the integration can fall back to a URL to view
52
+ * the file in the web interface.
53
+ *
54
+ * @param url - The absolute URL to the file that should be edited.
55
+ */
56
+ resolveEditUrl(url: string): string;
57
+ }
58
+ /**
59
+ * Encapsulates several integrations, that are all of the same type.
60
+ *
61
+ * @public
62
+ */
63
+ interface ScmIntegrationsGroup<T extends ScmIntegration> {
64
+ /**
65
+ * Lists all registered integrations of this type.
66
+ */
67
+ list(): T[];
68
+ /**
69
+ * Fetches an integration of this type by URL.
70
+ *
71
+ * @param url - A URL that matches a registered integration of this type
72
+ */
73
+ byUrl(url: string | URL): T | undefined;
74
+ /**
75
+ * Fetches an integration of this type by host name.
76
+ *
77
+ * @param host - A host name that matches a registered integration of this type
78
+ */
79
+ byHost(host: string): T | undefined;
80
+ }
81
+ /**
82
+ * A factory function that creates an integration group based on configuration.
83
+ *
84
+ * @public
85
+ */
86
+ declare type ScmIntegrationsFactory<T extends ScmIntegration> = (options: {
87
+ config: Config;
88
+ }) => ScmIntegrationsGroup<T>;
89
+
90
+ /**
91
+ * The configuration parameters for a single Azure provider.
92
+ *
93
+ * @public
94
+ */
95
+ declare type AzureIntegrationConfig = {
96
+ /**
97
+ * The host of the target that this matches on, e.g. "dev.azure.com".
98
+ *
99
+ * Currently only "dev.azure.com" is supported.
100
+ */
101
+ host: string;
102
+ /**
103
+ * The authorization token to use for requests.
104
+ *
105
+ * If no token is specified, anonymous access is used.
106
+ */
107
+ token?: string;
108
+ };
109
+ /**
110
+ * Reads a single Azure integration config.
111
+ *
112
+ * @param config - The config object of a single integration
113
+ * @public
114
+ */
115
+ declare function readAzureIntegrationConfig(config: Config): AzureIntegrationConfig;
116
+ /**
117
+ * Reads a set of Azure integration configs, and inserts some defaults for
118
+ * public Azure if not specified.
119
+ *
120
+ * @param configs - All of the integration config objects
121
+ * @public
122
+ */
123
+ declare function readAzureIntegrationConfigs(configs: Config[]): AzureIntegrationConfig[];
124
+
125
+ /**
126
+ * Microsoft Azure based integration.
127
+ *
128
+ * @public
129
+ */
130
+ declare class AzureIntegration implements ScmIntegration {
131
+ private readonly integrationConfig;
132
+ static factory: ScmIntegrationsFactory<AzureIntegration>;
133
+ constructor(integrationConfig: AzureIntegrationConfig);
134
+ get type(): string;
135
+ get title(): string;
136
+ get config(): AzureIntegrationConfig;
137
+ resolveUrl(options: {
138
+ url: string;
139
+ base: string;
140
+ lineNumber?: number;
141
+ }): string;
142
+ resolveEditUrl(url: string): string;
143
+ }
144
+
145
+ /**
146
+ * Given a URL pointing to a file on a provider, returns a URL that is suitable
147
+ * for fetching the contents of the data.
148
+ *
149
+ * @remarks
150
+ *
151
+ * Converts
152
+ * - from: `https://dev.azure.com/{organization}/{project}/_git/reponame?path={path}&version=GB{commitOrBranch}&_a=contents`
153
+ * - to: `https://dev.azure.com/{organization}/{project}/_apis/git/repositories/reponame/items?path={path}&version={commitOrBranch}`
154
+ *
155
+ * @param url - A URL pointing to a file
156
+ * @public
157
+ */
158
+ declare function getAzureFileFetchUrl(url: string): string;
159
+ /**
160
+ * Given a URL pointing to a path on a provider, returns a URL that is suitable
161
+ * for downloading the subtree.
162
+ *
163
+ * @param url - A URL pointing to a path
164
+ * @public
165
+ */
166
+ declare function getAzureDownloadUrl(url: string): string;
167
+ /**
168
+ * Given a URL, return the API URL to fetch commits on the branch.
169
+ *
170
+ * @param url - A URL pointing to a repository or a sub-path
171
+ * @public
172
+ */
173
+ declare function getAzureCommitsUrl(url: string): string;
174
+ /**
175
+ * Gets the request options necessary to make requests to a given provider.
176
+ *
177
+ * @param config - The relevant provider config
178
+ * @public
179
+ */
180
+ declare function getAzureRequestOptions(config: AzureIntegrationConfig, additionalHeaders?: Record<string, string>): {
181
+ headers: Record<string, string>;
182
+ };
183
+
184
+ /**
185
+ * The configuration parameters for a single Bitbucket API provider.
186
+ *
187
+ * @public
188
+ */
189
+ declare type BitbucketIntegrationConfig = {
190
+ /**
191
+ * The host of the target that this matches on, e.g. "bitbucket.org"
192
+ */
193
+ host: string;
194
+ /**
195
+ * The base URL of the API of this provider, e.g. "https://api.bitbucket.org/2.0",
196
+ * with no trailing slash.
197
+ *
198
+ * May be omitted specifically for Bitbucket Cloud; then it will be deduced.
199
+ *
200
+ * The API will always be preferred if both its base URL and a token are
201
+ * present.
202
+ */
203
+ apiBaseUrl?: string;
204
+ /**
205
+ * The authorization token to use for requests to a Bitbucket Server provider.
206
+ *
207
+ * See https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html
208
+ *
209
+ * If no token is specified, anonymous access is used.
210
+ */
211
+ token?: string;
212
+ /**
213
+ * The username to use for requests to Bitbucket Cloud (bitbucket.org).
214
+ */
215
+ username?: string;
216
+ /**
217
+ * Authentication with Bitbucket Cloud (bitbucket.org) is done using app passwords.
218
+ *
219
+ * See https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/
220
+ */
221
+ appPassword?: string;
222
+ };
223
+ /**
224
+ * Reads a single Bitbucket integration config.
225
+ *
226
+ * @param config - The config object of a single integration
227
+ * @public
228
+ */
229
+ declare function readBitbucketIntegrationConfig(config: Config): BitbucketIntegrationConfig;
230
+ /**
231
+ * Reads a set of Bitbucket integration configs, and inserts some defaults for
232
+ * public Bitbucket if not specified.
233
+ *
234
+ * @param configs - All of the integration config objects
235
+ * @public
236
+ */
237
+ declare function readBitbucketIntegrationConfigs(configs: Config[]): BitbucketIntegrationConfig[];
238
+
239
+ /**
240
+ * A Bitbucket based integration.
241
+ *
242
+ * @public
243
+ */
244
+ declare class BitbucketIntegration implements ScmIntegration {
245
+ private readonly integrationConfig;
246
+ static factory: ScmIntegrationsFactory<BitbucketIntegration>;
247
+ constructor(integrationConfig: BitbucketIntegrationConfig);
248
+ get type(): string;
249
+ get title(): string;
250
+ get config(): BitbucketIntegrationConfig;
251
+ resolveUrl(options: {
252
+ url: string;
253
+ base: string;
254
+ lineNumber?: number;
255
+ }): string;
256
+ resolveEditUrl(url: string): string;
257
+ }
258
+
259
+ /**
260
+ * Given a URL pointing to a path on a provider, returns the default branch.
261
+ *
262
+ * @param url - A URL pointing to a path
263
+ * @param config - The relevant provider config
264
+ * @public
265
+ */
266
+ declare function getBitbucketDefaultBranch(url: string, config: BitbucketIntegrationConfig): Promise<string>;
267
+ /**
268
+ * Given a URL pointing to a path on a provider, returns a URL that is suitable
269
+ * for downloading the subtree.
270
+ *
271
+ * @param url - A URL pointing to a path
272
+ * @param config - The relevant provider config
273
+ * @public
274
+ */
275
+ declare function getBitbucketDownloadUrl(url: string, config: BitbucketIntegrationConfig): Promise<string>;
276
+ /**
277
+ * Given a URL pointing to a file on a provider, returns a URL that is suitable
278
+ * for fetching the contents of the data.
279
+ *
280
+ * @remarks
281
+ *
282
+ * Converts
283
+ * from: https://bitbucket.org/orgname/reponame/src/master/file.yaml
284
+ * to: https://api.bitbucket.org/2.0/repositories/orgname/reponame/src/master/file.yaml
285
+ *
286
+ * @param url - A URL pointing to a file
287
+ * @param config - The relevant provider config
288
+ * @public
289
+ */
290
+ declare function getBitbucketFileFetchUrl(url: string, config: BitbucketIntegrationConfig): string;
291
+ /**
292
+ * Gets the request options necessary to make requests to a given provider.
293
+ *
294
+ * @param config - The relevant provider config
295
+ * @public
296
+ */
297
+ declare function getBitbucketRequestOptions(config: BitbucketIntegrationConfig): {
298
+ headers: Record<string, string>;
299
+ };
300
+
301
+ /**
302
+ * The configuration parameters for a single GitHub integration.
303
+ *
304
+ * @public
305
+ */
306
+ declare type GitHubIntegrationConfig = {
307
+ /**
308
+ * The host of the target that this matches on, e.g. "github.com"
309
+ */
310
+ host: string;
311
+ /**
312
+ * The base URL of the API of this provider, e.g. "https://api.github.com",
313
+ * with no trailing slash.
314
+ *
315
+ * May be omitted specifically for GitHub; then it will be deduced.
316
+ *
317
+ * The API will always be preferred if both its base URL and a token are
318
+ * present.
319
+ */
320
+ apiBaseUrl?: string;
321
+ /**
322
+ * The base URL of the raw fetch endpoint of this provider, e.g.
323
+ * "https://raw.githubusercontent.com", with no trailing slash.
324
+ *
325
+ * May be omitted specifically for GitHub; then it will be deduced.
326
+ *
327
+ * The API will always be preferred if both its base URL and a token are
328
+ * present.
329
+ */
330
+ rawBaseUrl?: string;
331
+ /**
332
+ * The authorization token to use for requests to this provider.
333
+ *
334
+ * If no token is specified, anonymous access is used.
335
+ */
336
+ token?: string;
337
+ /**
338
+ * The GitHub Apps configuration to use for requests to this provider.
339
+ *
340
+ * If no apps are specified, token or anonymous is used.
341
+ */
342
+ apps?: GithubAppConfig[];
343
+ };
344
+ /**
345
+ * The configuration parameters for authenticating a GitHub Application.
346
+ *
347
+ * @remarks
348
+ *
349
+ * A GitHub Apps configuration can be generated using the `backstage-cli create-github-app` command.
350
+ *
351
+ * @public
352
+ */
353
+ declare type GithubAppConfig = {
354
+ /**
355
+ * Unique app identifier, found at https://github.com/organizations/$org/settings/apps/$AppName
356
+ */
357
+ appId: number;
358
+ /**
359
+ * The private key is used by the GitHub App integration to authenticate the app.
360
+ * A private key can be generated from the app at https://github.com/organizations/$org/settings/apps/$AppName
361
+ */
362
+ privateKey: string;
363
+ /**
364
+ * Webhook secret can be configured at https://github.com/organizations/$org/settings/apps/$AppName
365
+ */
366
+ webhookSecret: string;
367
+ /**
368
+ * Found at https://github.com/organizations/$org/settings/apps/$AppName
369
+ */
370
+ clientId: string;
371
+ /**
372
+ * Client secrets can be generated at https://github.com/organizations/$org/settings/apps/$AppName
373
+ */
374
+ clientSecret: string;
375
+ /**
376
+ * List of installation owners allowed to be used by this GitHub app. The GitHub UI does not provide a way to list the installations.
377
+ * However you can list the installations with the GitHub API. You can find the list of installations here:
378
+ * https://api.github.com/app/installations
379
+ * The relevant documentation for this is here.
380
+ * https://docs.github.com/en/rest/reference/apps#list-installations-for-the-authenticated-app--code-samples
381
+ */
382
+ allowedInstallationOwners?: string[];
383
+ };
384
+ /**
385
+ * Reads a single GitHub integration config.
386
+ *
387
+ * @param config - The config object of a single integration
388
+ * @public
389
+ */
390
+ declare function readGitHubIntegrationConfig(config: Config): GitHubIntegrationConfig;
391
+ /**
392
+ * Reads a set of GitHub integration configs, and inserts some defaults for
393
+ * public GitHub if not specified.
394
+ *
395
+ * @param configs - All of the integration config objects
396
+ * @public
397
+ */
398
+ declare function readGitHubIntegrationConfigs(configs: Config[]): GitHubIntegrationConfig[];
399
+
400
+ /**
401
+ * The type of credentials produced by the credential provider.
402
+ *
403
+ * @public
404
+ */
405
+ declare type GithubCredentialType = 'app' | 'token';
406
+ /**
407
+ * A set of credentials information for a GitHub integration.
408
+ *
409
+ * @public
410
+ */
411
+ declare type GithubCredentials = {
412
+ headers?: {
413
+ [name: string]: string;
414
+ };
415
+ token?: string;
416
+ type: GithubCredentialType;
417
+ };
418
+ /**
419
+ * This allows implementations to be provided to retrieve GitHub credentials.
420
+ *
421
+ * @public
422
+ *
423
+ */
424
+ interface GithubCredentialsProvider {
425
+ getCredentials(opts: {
426
+ url: string;
427
+ }): Promise<GithubCredentials>;
428
+ }
429
+
430
+ /**
431
+ * Given a URL pointing to a file on a provider, returns a URL that is suitable
432
+ * for fetching the contents of the data.
433
+ *
434
+ * @remarks
435
+ *
436
+ * Converts
437
+ * from: https://github.com/a/b/blob/branchname/path/to/c.yaml
438
+ * to: https://api.github.com/repos/a/b/contents/path/to/c.yaml?ref=branchname
439
+ * or: https://raw.githubusercontent.com/a/b/branchname/c.yaml
440
+ *
441
+ * @param url - A URL pointing to a file
442
+ * @param config - The relevant provider config
443
+ * @public
444
+ */
445
+ declare function getGitHubFileFetchUrl(url: string, config: GitHubIntegrationConfig, credentials: GithubCredentials): string;
446
+ /**
447
+ * Gets the request options necessary to make requests to a given provider.
448
+ *
449
+ * @deprecated This function is no longer used internally
450
+ * @param config - The relevant provider config
451
+ * @public
452
+ */
453
+ declare function getGitHubRequestOptions(config: GitHubIntegrationConfig, credentials: GithubCredentials): {
454
+ headers: Record<string, string>;
455
+ };
456
+
457
+ /**
458
+ * The configuration parameters for a single AWS S3 provider.
459
+ *
460
+ * @public
461
+ */
462
+ declare type AwsS3IntegrationConfig = {
463
+ /**
464
+ * Host, derived from endpoint, and defaults to amazonaws.com
465
+ */
466
+ host: string;
467
+ /**
468
+ * (Optional) AWS Endpoint.
469
+ * The endpoint URI to send requests to. The default endpoint is built from the configured region.
470
+ * @see https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property
471
+ *
472
+ * Supports non-AWS providers, e.g. for LocalStack, endpoint may look like http://localhost:4566
473
+ */
474
+ endpoint?: string;
475
+ /**
476
+ * (Optional) Whether to use path style URLs when communicating with S3.
477
+ * Defaults to false.
478
+ * This allows providers like LocalStack, Minio and Wasabi (and possibly others) to be used.
479
+ */
480
+ s3ForcePathStyle?: boolean;
481
+ /**
482
+ * (Optional) User access key id
483
+ */
484
+ accessKeyId?: string;
485
+ /**
486
+ * (Optional) User secret access key
487
+ */
488
+ secretAccessKey?: string;
489
+ /**
490
+ * (Optional) ARN of role to be assumed
491
+ */
492
+ roleArn?: string;
493
+ };
494
+ /**
495
+ * Reads a single Aws S3 integration config.
496
+ *
497
+ * @param config - The config object of a single integration
498
+ * @public
499
+ */
500
+ declare function readAwsS3IntegrationConfig(config: Config): AwsS3IntegrationConfig;
501
+ /**
502
+ * Reads a set of AWS S3 integration configs, and inserts some defaults for
503
+ * public Amazon AWS if not specified.
504
+ *
505
+ * @param configs - The config objects of the integrations
506
+ * @public
507
+ */
508
+ declare function readAwsS3IntegrationConfigs(configs: Config[]): AwsS3IntegrationConfig[];
509
+
510
+ /**
511
+ * Integrates with AWS S3 or compatible solutions.
512
+ *
513
+ * @public
514
+ */
515
+ declare class AwsS3Integration implements ScmIntegration {
516
+ private readonly integrationConfig;
517
+ static factory: ScmIntegrationsFactory<AwsS3Integration>;
518
+ get type(): string;
519
+ get title(): string;
520
+ get config(): AwsS3IntegrationConfig;
521
+ constructor(integrationConfig: AwsS3IntegrationConfig);
522
+ resolveUrl(options: {
523
+ url: string;
524
+ base: string;
525
+ lineNumber?: number | undefined;
526
+ }): string;
527
+ resolveEditUrl(url: string): string;
528
+ }
529
+
530
+ /**
531
+ * A GitHub based integration.
532
+ *
533
+ * @public
534
+ */
535
+ declare class GitHubIntegration implements ScmIntegration {
536
+ private readonly integrationConfig;
537
+ static factory: ScmIntegrationsFactory<GitHubIntegration>;
538
+ constructor(integrationConfig: GitHubIntegrationConfig);
539
+ get type(): string;
540
+ get title(): string;
541
+ get config(): GitHubIntegrationConfig;
542
+ resolveUrl(options: {
543
+ url: string;
544
+ base: string;
545
+ lineNumber?: number;
546
+ }): string;
547
+ resolveEditUrl(url: string): string;
548
+ }
549
+ /**
550
+ * Takes a GitHub URL and replaces the type part (blob, tree etc).
551
+ *
552
+ * @param url - The original URL
553
+ * @param type - The desired type, e.g. "blob"
554
+ * @public
555
+ */
556
+ declare function replaceGitHubUrlType(url: string, type: 'blob' | 'tree' | 'edit'): string;
557
+
558
+ /**
559
+ * The configuration parameters for a single GitLab integration.
560
+ *
561
+ * @public
562
+ */
563
+ declare type GitLabIntegrationConfig = {
564
+ /**
565
+ * The host of the target that this matches on, e.g. `gitlab.com`.
566
+ */
567
+ host: string;
568
+ /**
569
+ * The base URL of the API of this provider, e.g.
570
+ * `https://gitlab.com/api/v4`, with no trailing slash.
571
+ *
572
+ * May be omitted specifically for public GitLab; then it will be deduced.
573
+ */
574
+ apiBaseUrl: string;
575
+ /**
576
+ * The authorization token to use for requests to this provider.
577
+ *
578
+ * If no token is specified, anonymous access is used.
579
+ */
580
+ token?: string;
581
+ /**
582
+ * The baseUrl of this provider, e.g. `https://gitlab.com`, which is passed
583
+ * into the GitLab client.
584
+ *
585
+ * If no baseUrl is provided, it will default to `https://${host}`
586
+ */
587
+ baseUrl: string;
588
+ };
589
+ /**
590
+ * Reads a single GitLab integration config.
591
+ *
592
+ * @param config - The config object of a single integration
593
+ * @public
594
+ */
595
+ declare function readGitLabIntegrationConfig(config: Config): GitLabIntegrationConfig;
596
+ /**
597
+ * Reads a set of GitLab integration configs, and inserts some defaults for
598
+ * public GitLab if not specified.
599
+ *
600
+ * @param configs - All of the integration config objects
601
+ * @public
602
+ */
603
+ declare function readGitLabIntegrationConfigs(configs: Config[]): GitLabIntegrationConfig[];
604
+
605
+ /**
606
+ * A GitLab based integration.
607
+ *
608
+ * @public
609
+ */
610
+ declare class GitLabIntegration implements ScmIntegration {
611
+ private readonly integrationConfig;
612
+ static factory: ScmIntegrationsFactory<GitLabIntegration>;
613
+ constructor(integrationConfig: GitLabIntegrationConfig);
614
+ get type(): string;
615
+ get title(): string;
616
+ get config(): GitLabIntegrationConfig;
617
+ resolveUrl(options: {
618
+ url: string;
619
+ base: string;
620
+ lineNumber?: number;
621
+ }): string;
622
+ resolveEditUrl(url: string): string;
623
+ }
624
+
625
+ /**
626
+ * Holds all registered SCM integrations, of all types.
627
+ *
628
+ * @public
629
+ */
630
+ interface ScmIntegrationRegistry extends ScmIntegrationsGroup<ScmIntegration> {
631
+ awsS3: ScmIntegrationsGroup<AwsS3Integration>;
632
+ azure: ScmIntegrationsGroup<AzureIntegration>;
633
+ bitbucket: ScmIntegrationsGroup<BitbucketIntegration>;
634
+ github: ScmIntegrationsGroup<GitHubIntegration>;
635
+ gitlab: ScmIntegrationsGroup<GitLabIntegration>;
636
+ /**
637
+ * Resolves an absolute or relative URL in relation to a base URL.
638
+ *
639
+ * This method is adapted for use within SCM systems, so relative URLs are
640
+ * within the context of the root of the hierarchy pointed to by the base
641
+ * URL.
642
+ *
643
+ * For example, if the base URL is `<repo root url>/folder/a.yaml`, i.e.
644
+ * within the file tree of a certain repo, an absolute path of `/b.yaml` does
645
+ * not resolve to `https://hostname/b.yaml` but rather to
646
+ * `<repo root url>/b.yaml` inside the file tree of that same repo.
647
+ */
648
+ resolveUrl(options: {
649
+ /**
650
+ * The (absolute or relative) URL or path to resolve.
651
+ */
652
+ url: string;
653
+ /**
654
+ * The base URL onto which this resolution happens
655
+ */
656
+ base: string;
657
+ /**
658
+ * The line number in the target file to link to, starting with 1. Only applicable when linking to files.
659
+ */
660
+ lineNumber?: number;
661
+ }): string;
662
+ /**
663
+ * Resolves the edit URL for a file within the SCM system.
664
+ *
665
+ * Most SCM systems have a web interface that allows viewing and editing files
666
+ * in the repository. The returned URL directly jumps into the edit mode for
667
+ * the file.
668
+ * If this is not possible, the integration can fall back to a URL to view
669
+ * the file in the web interface.
670
+ *
671
+ * @param url - The absolute URL to the file that should be edited.
672
+ */
673
+ resolveEditUrl(url: string): string;
674
+ }
675
+
676
+ /**
677
+ * Handles the creation and caching of credentials for GitHub integrations.
678
+ *
679
+ * @public
680
+ * @remarks
681
+ *
682
+ * TODO: Possibly move this to a backend only package so that it's not used in the frontend by mistake
683
+ */
684
+ declare class DefaultGithubCredentialsProvider implements GithubCredentialsProvider {
685
+ private readonly providers;
686
+ static fromIntegrations(integrations: ScmIntegrationRegistry): DefaultGithubCredentialsProvider;
687
+ private constructor();
688
+ /**
689
+ * Returns {@link GithubCredentials} for a given URL.
690
+ *
691
+ * @remarks
692
+ *
693
+ * Consecutive calls to this method with the same URL will return cached
694
+ * credentials.
695
+ *
696
+ * The shortest lifetime for a token returned is 10 minutes.
697
+ *
698
+ * @example
699
+ * ```ts
700
+ * const { token, headers } = await getCredentials({
701
+ * url: 'https://github.com/backstage/foobar'
702
+ * })
703
+ *
704
+ * const { token, headers } = await getCredentials({
705
+ * url: 'https://github.com/backstage'
706
+ * })
707
+ * ```
708
+ *
709
+ * @param opts - The organization or repository URL
710
+ * @returns A promise of {@link GithubCredentials}.
711
+ */
712
+ getCredentials(opts: {
713
+ url: string;
714
+ }): Promise<GithubCredentials>;
715
+ }
716
+
717
+ /**
718
+ * Corresponds to a Github installation which internally could hold several GitHub Apps.
719
+ *
720
+ * @public
721
+ */
722
+ declare class GithubAppCredentialsMux {
723
+ private readonly apps;
724
+ constructor(config: GitHubIntegrationConfig);
725
+ getAllInstallations(): Promise<RestEndpointMethodTypes['apps']['listInstallations']['response']['data']>;
726
+ getAppToken(owner: string, repo?: string): Promise<string | undefined>;
727
+ }
728
+ /**
729
+ * Handles the creation and caching of credentials for GitHub integrations.
730
+ *
731
+ * @public
732
+ * @remarks
733
+ *
734
+ * TODO: Possibly move this to a backend only package so that it's not used in the frontend by mistake
735
+ */
736
+ declare class SingleInstanceGithubCredentialsProvider implements GithubCredentialsProvider {
737
+ private readonly githubAppCredentialsMux;
738
+ private readonly token?;
739
+ static create: (config: GitHubIntegrationConfig) => GithubCredentialsProvider;
740
+ private constructor();
741
+ /**
742
+ * Returns {@link GithubCredentials} for a given URL.
743
+ *
744
+ * @remarks
745
+ *
746
+ * Consecutive calls to this method with the same URL will return cached
747
+ * credentials.
748
+ *
749
+ * The shortest lifetime for a token returned is 10 minutes.
750
+ *
751
+ * @example
752
+ * ```ts
753
+ * const { token, headers } = await getCredentials({
754
+ * url: 'github.com/backstage/foobar'
755
+ * })
756
+ * ```
757
+ *
758
+ * @param opts - The organization or repository URL
759
+ * @returns A promise of {@link GithubCredentials}.
760
+ */
761
+ getCredentials(opts: {
762
+ url: string;
763
+ }): Promise<GithubCredentials>;
764
+ }
765
+
766
+ /**
767
+ * Given a URL pointing to a file on a provider, returns a URL that is suitable
768
+ * for fetching the contents of the data.
769
+ *
770
+ * @remarks
771
+ *
772
+ * Converts
773
+ * from: https://gitlab.example.com/a/b/blob/master/c.yaml
774
+ * to: https://gitlab.example.com/a/b/raw/master/c.yaml
775
+ * -or-
776
+ * from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath
777
+ * to: https://gitlab.com/api/v4/projects/projectId/repository/files/filepath?ref=branch
778
+ *
779
+ * @param url - A URL pointing to a file
780
+ * @param config - The relevant provider config
781
+ * @public
782
+ */
783
+ declare function getGitLabFileFetchUrl(url: string, config: GitLabIntegrationConfig): Promise<string>;
784
+ /**
785
+ * Gets the request options necessary to make requests to a given provider.
786
+ *
787
+ * @param config - The relevant provider config
788
+ * @public
789
+ */
790
+ declare function getGitLabRequestOptions(config: GitLabIntegrationConfig): {
791
+ headers: Record<string, string>;
792
+ };
793
+
794
+ /**
795
+ * The configuration parameters for a single Google Cloud Storage provider.
796
+ *
797
+ * @public
798
+ */
799
+ declare type GoogleGcsIntegrationConfig = {
800
+ /**
801
+ * Service account email used to authenticate requests.
802
+ */
803
+ clientEmail?: string;
804
+ /**
805
+ * Service account private key used to authenticate requests.
806
+ */
807
+ privateKey?: string;
808
+ };
809
+ /**
810
+ * Reads a single Google GCS integration config.
811
+ *
812
+ * @param config - The config object of a single integration
813
+ * @public
814
+ */
815
+ declare function readGoogleGcsIntegrationConfig(config: Config): GoogleGcsIntegrationConfig;
816
+
817
+ /**
818
+ * Default implementation of {@link ScmIntegration} `resolveUrl`, that only
819
+ * works with URL pathname based providers.
820
+ *
821
+ * @public
822
+ */
823
+ declare function defaultScmResolveUrl(options: {
824
+ url: string;
825
+ base: string;
826
+ lineNumber?: number;
827
+ }): string;
828
+
829
+ /**
830
+ * The set of supported integrations.
831
+ *
832
+ * @public
833
+ */
834
+ interface IntegrationsByType {
835
+ awsS3: ScmIntegrationsGroup<AwsS3Integration>;
836
+ azure: ScmIntegrationsGroup<AzureIntegration>;
837
+ bitbucket: ScmIntegrationsGroup<BitbucketIntegration>;
838
+ github: ScmIntegrationsGroup<GitHubIntegration>;
839
+ gitlab: ScmIntegrationsGroup<GitLabIntegration>;
840
+ }
841
+ /**
842
+ * Exposes the set of supported integrations.
843
+ *
844
+ * @public
845
+ */
846
+ declare class ScmIntegrations implements ScmIntegrationRegistry {
847
+ private readonly byType;
848
+ static fromConfig(config: Config): ScmIntegrations;
849
+ constructor(integrationsByType: IntegrationsByType);
850
+ get awsS3(): ScmIntegrationsGroup<AwsS3Integration>;
851
+ get azure(): ScmIntegrationsGroup<AzureIntegration>;
852
+ get bitbucket(): ScmIntegrationsGroup<BitbucketIntegration>;
853
+ get github(): ScmIntegrationsGroup<GitHubIntegration>;
854
+ get gitlab(): ScmIntegrationsGroup<GitLabIntegration>;
855
+ list(): ScmIntegration[];
856
+ byUrl(url: string | URL): ScmIntegration | undefined;
857
+ byHost(host: string): ScmIntegration | undefined;
858
+ resolveUrl(options: {
859
+ url: string;
860
+ base: string;
861
+ lineNumber?: number;
862
+ }): string;
863
+ resolveEditUrl(url: string): string;
864
+ }
865
+
866
+ export { AwsS3Integration, AwsS3IntegrationConfig, AzureIntegration, AzureIntegrationConfig, BitbucketIntegration, BitbucketIntegrationConfig, DefaultGithubCredentialsProvider, GitHubIntegration, GitHubIntegrationConfig, GitLabIntegration, GitLabIntegrationConfig, GithubAppConfig, GithubAppCredentialsMux, GithubCredentialType, GithubCredentials, GithubCredentialsProvider, GoogleGcsIntegrationConfig, IntegrationsByType, ScmIntegration, ScmIntegrationRegistry, ScmIntegrations, ScmIntegrationsFactory, ScmIntegrationsGroup, SingleInstanceGithubCredentialsProvider, defaultScmResolveUrl, getAzureCommitsUrl, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAwsS3IntegrationConfig, readAwsS3IntegrationConfigs, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs, readGoogleGcsIntegrationConfig, replaceGitHubUrlType };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/integration",
3
3
  "description": "Helpers for managing integrations towards external systems",
4
- "version": "0.7.3",
4
+ "version": "0.7.4",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -33,7 +33,7 @@
33
33
  "clean": "backstage-cli package clean"
34
34
  },
35
35
  "dependencies": {
36
- "@backstage/config": "^0.1.14",
36
+ "@backstage/config": "^0.1.15",
37
37
  "@octokit/auth-app": "^3.4.0",
38
38
  "@octokit/rest": "^18.5.3",
39
39
  "cross-fetch": "^3.1.5",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@backstage/cli": "^0.14.0",
46
- "@backstage/config-loader": "^0.9.4",
46
+ "@backstage/config-loader": "^0.9.5",
47
47
  "@backstage/test-utils": "^0.2.5",
48
48
  "@types/jest": "^26.0.7",
49
49
  "@types/luxon": "^2.0.4",
@@ -54,6 +54,6 @@
54
54
  "config.d.ts"
55
55
  ],
56
56
  "configSchema": "config.d.ts",
57
- "gitHead": "4805c3d13ce9bfc369e53c271b1b95e722b3b4dc",
57
+ "gitHead": "e244b348c473700e7d5e5fbcef38bd9f9fd1d0ba",
58
58
  "module": "dist/index.esm.js"
59
59
  }