@backstage/integration 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -455,52 +455,76 @@ declare function getGitHubRequestOptions(config: GitHubIntegrationConfig, creden
455
455
  };
456
456
 
457
457
  /**
458
- * Corresponds to a Github installation which internally could hold several GitHub Apps.
458
+ * The configuration parameters for a single AWS S3 provider.
459
459
  *
460
460
  * @public
461
461
  */
462
- declare class GithubAppCredentialsMux {
463
- private readonly apps;
464
- constructor(config: GitHubIntegrationConfig);
465
- getAllInstallations(): Promise<RestEndpointMethodTypes['apps']['listInstallations']['response']['data']>;
466
- getAppToken(owner: string, repo?: string): Promise<string | undefined>;
467
- }
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
+ };
468
494
  /**
469
- * Handles the creation and caching of credentials for GitHub integrations.
495
+ * Reads a single Aws S3 integration config.
470
496
  *
497
+ * @param config - The config object of a single integration
471
498
  * @public
472
- * @remarks
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.
473
504
  *
474
- * TODO: Possibly move this to a backend only package so that it's not used in the frontend by mistake
505
+ * @param configs - The config objects of the integrations
506
+ * @public
475
507
  */
476
- declare class SingleInstanceGithubCredentialsProvider implements GithubCredentialsProvider {
477
- private readonly githubAppCredentialsMux;
478
- private readonly token?;
479
- static create: (config: GitHubIntegrationConfig) => GithubCredentialsProvider;
480
- private constructor();
481
- /**
482
- * Returns {@link GithubCredentials} for a given URL.
483
- *
484
- * @remarks
485
- *
486
- * Consecutive calls to this method with the same URL will return cached
487
- * credentials.
488
- *
489
- * The shortest lifetime for a token returned is 10 minutes.
490
- *
491
- * @example
492
- * ```ts
493
- * const { token, headers } = await getCredentials({
494
- * url: 'github.com/backstage/foobar'
495
- * })
496
- * ```
497
- *
498
- * @param opts - The organization or repository URL
499
- * @returns A promise of {@link GithubCredentials}.
500
- */
501
- getCredentials(opts: {
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: {
502
523
  url: string;
503
- }): Promise<GithubCredentials>;
524
+ base: string;
525
+ lineNumber?: number | undefined;
526
+ }): string;
527
+ resolveEditUrl(url: string): string;
504
528
  }
505
529
 
506
530
  /**
@@ -538,12 +562,12 @@ declare function replaceGitHubUrlType(url: string, type: 'blob' | 'tree' | 'edit
538
562
  */
539
563
  declare type GitLabIntegrationConfig = {
540
564
  /**
541
- * The host of the target that this matches on, e.g. "gitlab.com".
565
+ * The host of the target that this matches on, e.g. `gitlab.com`.
542
566
  */
543
567
  host: string;
544
568
  /**
545
569
  * The base URL of the API of this provider, e.g.
546
- * "https://gitlab.com/api/v4", with no trailing slash.
570
+ * `https://gitlab.com/api/v4`, with no trailing slash.
547
571
  *
548
572
  * May be omitted specifically for public GitLab; then it will be deduced.
549
573
  */
@@ -555,10 +579,10 @@ declare type GitLabIntegrationConfig = {
555
579
  */
556
580
  token?: string;
557
581
  /**
558
- * The baseUrl of this provider, e.g. "https://gitlab.com", which is passed
582
+ * The baseUrl of this provider, e.g. `https://gitlab.com`, which is passed
559
583
  * into the GitLab client.
560
584
  *
561
- * If no baseUrl is provided, it will default to https://${host}
585
+ * If no baseUrl is provided, it will default to `https://${host}`
562
586
  */
563
587
  baseUrl: string;
564
588
  };
@@ -578,34 +602,6 @@ declare function readGitLabIntegrationConfig(config: Config): GitLabIntegrationC
578
602
  */
579
603
  declare function readGitLabIntegrationConfigs(configs: Config[]): GitLabIntegrationConfig[];
580
604
 
581
- /**
582
- * Given a URL pointing to a file on a provider, returns a URL that is suitable
583
- * for fetching the contents of the data.
584
- *
585
- * @remarks
586
- *
587
- * Converts
588
- * from: https://gitlab.example.com/a/b/blob/master/c.yaml
589
- * to: https://gitlab.example.com/a/b/raw/master/c.yaml
590
- * -or-
591
- * from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath
592
- * to: https://gitlab.com/api/v4/projects/projectId/repository/files/filepath?ref=branch
593
- *
594
- * @param url - A URL pointing to a file
595
- * @param config - The relevant provider config
596
- * @public
597
- */
598
- declare function getGitLabFileFetchUrl(url: string, config: GitLabIntegrationConfig): Promise<string>;
599
- /**
600
- * Gets the request options necessary to make requests to a given provider.
601
- *
602
- * @param config - The relevant provider config
603
- * @public
604
- */
605
- declare function getGitLabRequestOptions(config: GitLabIntegrationConfig): {
606
- headers: Record<string, string>;
607
- };
608
-
609
605
  /**
610
606
  * A GitLab based integration.
611
607
  *
@@ -626,114 +622,6 @@ declare class GitLabIntegration implements ScmIntegration {
626
622
  resolveEditUrl(url: string): string;
627
623
  }
628
624
 
629
- /**
630
- * The configuration parameters for a single Google Cloud Storage provider.
631
- *
632
- * @public
633
- */
634
- declare type GoogleGcsIntegrationConfig = {
635
- /**
636
- * Service account email used to authenticate requests.
637
- */
638
- clientEmail?: string;
639
- /**
640
- * Service account private key used to authenticate requests.
641
- */
642
- privateKey?: string;
643
- };
644
- /**
645
- * Reads a single Google GCS integration config.
646
- *
647
- * @param config - The config object of a single integration
648
- * @public
649
- */
650
- declare function readGoogleGcsIntegrationConfig(config: Config): GoogleGcsIntegrationConfig;
651
-
652
- /**
653
- * The configuration parameters for a single AWS S3 provider.
654
- *
655
- * @public
656
- */
657
- declare type AwsS3IntegrationConfig = {
658
- /**
659
- * Host, derived from endpoint, and defaults to amazonaws.com
660
- */
661
- host: string;
662
- /**
663
- * (Optional) AWS Endpoint.
664
- * The endpoint URI to send requests to. The default endpoint is built from the configured region.
665
- * @see https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property
666
- *
667
- * Supports non-AWS providers, e.g. for LocalStack, endpoint may look like http://localhost:4566
668
- */
669
- endpoint?: string;
670
- /**
671
- * (Optional) Whether to use path style URLs when communicating with S3.
672
- * Defaults to false.
673
- * This allows providers like LocalStack, Minio and Wasabi (and possibly others) to be used.
674
- */
675
- s3ForcePathStyle?: boolean;
676
- /**
677
- * (Optional) User access key id
678
- */
679
- accessKeyId?: string;
680
- /**
681
- * (Optional) User secret access key
682
- */
683
- secretAccessKey?: string;
684
- /**
685
- * (Optional) ARN of role to be assumed
686
- */
687
- roleArn?: string;
688
- };
689
- /**
690
- * Reads a single Aws S3 integration config.
691
- *
692
- * @param config - The config object of a single integration
693
- * @public
694
- */
695
- declare function readAwsS3IntegrationConfig(config: Config): AwsS3IntegrationConfig;
696
- /**
697
- * Reads a set of AWS S3 integration configs, and inserts some defaults for
698
- * public Amazon AWS if not specified.
699
- *
700
- * @param configs - The config objects of the integrations
701
- * @public
702
- */
703
- declare function readAwsS3IntegrationConfigs(configs: Config[]): AwsS3IntegrationConfig[];
704
-
705
- /**
706
- * Integrates with AWS S3 or compatible solutions.
707
- *
708
- * @public
709
- */
710
- declare class AwsS3Integration implements ScmIntegration {
711
- private readonly integrationConfig;
712
- static factory: ScmIntegrationsFactory<AwsS3Integration>;
713
- get type(): string;
714
- get title(): string;
715
- get config(): AwsS3IntegrationConfig;
716
- constructor(integrationConfig: AwsS3IntegrationConfig);
717
- resolveUrl(options: {
718
- url: string;
719
- base: string;
720
- lineNumber?: number | undefined;
721
- }): string;
722
- resolveEditUrl(url: string): string;
723
- }
724
-
725
- /**
726
- * Default implementation of {@link ScmIntegration} `resolveUrl`, that only
727
- * works with URL pathname based providers.
728
- *
729
- * @public
730
- */
731
- declare function defaultScmResolveUrl(options: {
732
- url: string;
733
- base: string;
734
- lineNumber?: number;
735
- }): string;
736
-
737
625
  /**
738
626
  * Holds all registered SCM integrations, of all types.
739
627
  *
@@ -785,6 +673,159 @@ interface ScmIntegrationRegistry extends ScmIntegrationsGroup<ScmIntegration> {
785
673
  resolveEditUrl(url: string): string;
786
674
  }
787
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
+
788
829
  /**
789
830
  * The set of supported integrations.
790
831
  *
@@ -822,4 +863,4 @@ declare class ScmIntegrations implements ScmIntegrationRegistry {
822
863
  resolveEditUrl(url: string): string;
823
864
  }
824
865
 
825
- export { AwsS3Integration, AwsS3IntegrationConfig, AzureIntegration, AzureIntegrationConfig, BitbucketIntegration, BitbucketIntegrationConfig, 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 };
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/dist/index.esm.js CHANGED
@@ -659,6 +659,28 @@ SingleInstanceGithubCredentialsProvider.create = (config) => {
659
659
  return new _SingleInstanceGithubCredentialsProvider(new GithubAppCredentialsMux(config), config.token);
660
660
  };
661
661
 
662
+ class DefaultGithubCredentialsProvider {
663
+ constructor(providers) {
664
+ this.providers = providers;
665
+ }
666
+ static fromIntegrations(integrations) {
667
+ const credentialsProviders = /* @__PURE__ */ new Map();
668
+ integrations.github.list().forEach((integration) => {
669
+ const credentialsProvider = SingleInstanceGithubCredentialsProvider.create(integration.config);
670
+ credentialsProviders.set(integration.config.host, credentialsProvider);
671
+ });
672
+ return new DefaultGithubCredentialsProvider(credentialsProviders);
673
+ }
674
+ async getCredentials(opts) {
675
+ const parsed = new URL(opts.url);
676
+ const provider = this.providers.get(parsed.host);
677
+ if (!provider) {
678
+ throw new Error(`There is no GitHub integration that matches ${opts.url}. Please add a configuration for an integration.`);
679
+ }
680
+ return provider.getCredentials(opts);
681
+ }
682
+ }
683
+
662
684
  const _GitHubIntegration = class {
663
685
  constructor(integrationConfig) {
664
686
  this.integrationConfig = integrationConfig;
@@ -962,5 +984,5 @@ class ScmIntegrations {
962
984
  }
963
985
  }
964
986
 
965
- export { AwsS3Integration, AzureIntegration, BitbucketIntegration, GitHubIntegration, GitLabIntegration, GithubAppCredentialsMux, ScmIntegrations, 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 };
987
+ export { AwsS3Integration, AzureIntegration, BitbucketIntegration, DefaultGithubCredentialsProvider, GitHubIntegration, GitLabIntegration, GithubAppCredentialsMux, ScmIntegrations, 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 };
966
988
  //# sourceMappingURL=index.esm.js.map