@backstage/integration-react 0.1.12 → 0.1.16

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,42 @@
1
1
  # @backstage/integration-react
2
2
 
3
+ ## 0.1.16
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @backstage/core-plugin-api@0.4.0
9
+ - @backstage/core-components@0.8.2
10
+
11
+ ## 0.1.15
12
+
13
+ ### Patch Changes
14
+
15
+ - cd450844f6: Moved React dependencies to `peerDependencies` and allow both React v16 and v17 to be used.
16
+ - Updated dependencies
17
+ - @backstage/core-components@0.8.0
18
+ - @backstage/core-plugin-api@0.3.0
19
+
20
+ ## 0.1.14
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies
25
+ - @backstage/core-components@0.7.4
26
+ - @backstage/core-plugin-api@0.2.0
27
+
28
+ ## 0.1.13
29
+
30
+ ### Patch Changes
31
+
32
+ - 36e2b548cb: Clean up the API exports
33
+ - Updated dependencies
34
+ - @backstage/config@0.1.11
35
+ - @backstage/theme@0.2.12
36
+ - @backstage/integration@0.6.9
37
+ - @backstage/core-components@0.7.2
38
+ - @backstage/core-plugin-api@0.1.12
39
+
3
40
  ## 0.1.12
4
41
 
5
42
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -4,7 +4,11 @@ import { AuthRequestOptions, ApiRef, OAuthApi } from '@backstage/core-plugin-api
4
4
  import { Config } from '@backstage/config';
5
5
  import { ScmIntegrationRegistry } from '@backstage/integration';
6
6
 
7
- /** @public */
7
+ /**
8
+ * The options that control a {@link ScmAuthApi.getCredentials} call.
9
+ *
10
+ * @public
11
+ */
8
12
  interface ScmAuthTokenOptions extends AuthRequestOptions {
9
13
  /**
10
14
  * The URL of the SCM resource to be accessed.
@@ -25,7 +29,11 @@ interface ScmAuthTokenOptions extends AuthRequestOptions {
25
29
  repoWrite?: boolean;
26
30
  };
27
31
  }
28
- /** @public */
32
+ /**
33
+ * The response from a {@link ScmAuthApi.getCredentials} call.
34
+ *
35
+ * @public
36
+ */
29
37
  interface ScmAuthTokenResponse {
30
38
  /**
31
39
  * An authorization token that can be used to authenticate requests.
@@ -178,16 +186,48 @@ declare class ScmAuth implements ScmAuthApi {
178
186
  * Checks whether the implementation is able to provide authentication for the given URL.
179
187
  */
180
188
  isUrlSupported(url: URL): boolean;
189
+ /**
190
+ * Fetches credentials for the given resource.
191
+ */
181
192
  getCredentials(options: ScmAuthTokenOptions): Promise<ScmAuthTokenResponse>;
182
193
  }
183
194
 
195
+ /**
196
+ * Factory class for creating {@link @backstage/integration#ScmIntegrationRegistry} instances.
197
+ *
198
+ * @public
199
+ */
184
200
  declare class ScmIntegrationsApi {
201
+ /**
202
+ * Instantiates an {@link @backstage/integration#ScmIntegrationRegistry}.
203
+ *
204
+ * @param config - The root of the config hierarchy.
205
+ */
185
206
  static fromConfig(config: Config): ScmIntegrationRegistry;
186
207
  }
208
+ /**
209
+ * The API that holds all configured SCM integrations.
210
+ *
211
+ * @public
212
+ */
187
213
  declare const scmIntegrationsApiRef: ApiRef<ScmIntegrationRegistry>;
188
214
 
189
- declare const ScmIntegrationIcon: ({ type }: {
190
- type?: string | undefined;
191
- }) => JSX.Element;
215
+ /**
216
+ * Props for {@link ScmIntegrationIcon}.
217
+ *
218
+ * @public
219
+ */
220
+ declare type ScmIntegrationIconProps = {
221
+ /**
222
+ * The integration type, e.g. "github".
223
+ */
224
+ type?: string;
225
+ };
226
+ /**
227
+ * An icon that represents a certain SCM integration.
228
+ *
229
+ * @public
230
+ */
231
+ declare const ScmIntegrationIcon: (props: ScmIntegrationIconProps) => JSX.Element;
192
232
 
193
- export { ScmAuth, ScmAuthApi, ScmAuthTokenOptions, ScmAuthTokenResponse, ScmIntegrationIcon, ScmIntegrationsApi, scmAuthApiRef, scmIntegrationsApiRef };
233
+ export { ScmAuth, ScmAuthApi, ScmAuthTokenOptions, ScmAuthTokenResponse, ScmIntegrationIcon, ScmIntegrationIconProps, ScmIntegrationsApi, scmAuthApiRef, scmIntegrationsApiRef };
package/dist/index.esm.js CHANGED
@@ -15,6 +15,11 @@ var __privateGet = (obj, member, getter) => {
15
15
  __accessCheck(obj, member, "read from private field");
16
16
  return getter ? getter.call(obj) : member.get(obj);
17
17
  };
18
+ var __privateAdd = (obj, member, value) => {
19
+ if (member.has(obj))
20
+ throw TypeError("Cannot add the same private member more than once");
21
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
22
+ };
18
23
  var __privateSet = (obj, member, value, setter) => {
19
24
  __accessCheck(obj, member, "write to private field");
20
25
  setter ? setter.call(obj, value) : member.set(obj, value);
@@ -23,7 +28,7 @@ var __privateSet = (obj, member, value, setter) => {
23
28
  var _providers, _api, _host, _scopeMapping;
24
29
  class ScmAuthMux {
25
30
  constructor(providers) {
26
- _providers.set(this, void 0);
31
+ __privateAdd(this, _providers, void 0);
27
32
  __privateSet(this, _providers, providers);
28
33
  }
29
34
  async getCredentials(options) {
@@ -38,9 +43,9 @@ class ScmAuthMux {
38
43
  _providers = new WeakMap();
39
44
  const _ScmAuth = class {
40
45
  constructor(api, host, scopeMapping) {
41
- _api.set(this, void 0);
42
- _host.set(this, void 0);
43
- _scopeMapping.set(this, void 0);
46
+ __privateAdd(this, _api, void 0);
47
+ __privateAdd(this, _host, void 0);
48
+ __privateAdd(this, _scopeMapping, void 0);
44
49
  __privateSet(this, _api, api);
45
50
  __privateSet(this, _host, host);
46
51
  __privateSet(this, _scopeMapping, scopeMapping);
@@ -53,7 +58,7 @@ const _ScmAuth = class {
53
58
  gitlab: gitlabAuthApiRef,
54
59
  azure: microsoftAuthApiRef
55
60
  },
56
- factory: ({github, gitlab, azure}) => _ScmAuth.merge(_ScmAuth.forGithub(github), _ScmAuth.forGitlab(gitlab), _ScmAuth.forAzure(azure))
61
+ factory: ({ github, gitlab, azure }) => _ScmAuth.merge(_ScmAuth.forGithub(github), _ScmAuth.forGitlab(gitlab), _ScmAuth.forAzure(azure))
57
62
  });
58
63
  }
59
64
  static forAuthApi(authApi, options) {
@@ -104,7 +109,7 @@ const _ScmAuth = class {
104
109
  return url.host === __privateGet(this, _host);
105
110
  }
106
111
  async getCredentials(options) {
107
- const {url, additionalScope, ...restOptions} = options;
112
+ const { url, additionalScope, ...restOptions } = options;
108
113
  const scopes = __privateGet(this, _scopeMapping).default.slice();
109
114
  if (additionalScope == null ? void 0 : additionalScope.repoWrite) {
110
115
  scopes.push(...__privateGet(this, _scopeMapping).repoWrite);
@@ -129,12 +134,12 @@ class ScmIntegrationsApi {
129
134
  }
130
135
  }
131
136
  const scmIntegrationsApiRef = createApiRef({
132
- id: "integration.scmintegrations",
133
- description: "All of the registered SCM integrations of your config"
137
+ id: "integration.scmintegrations"
134
138
  });
135
139
 
136
- const ScmIntegrationIcon = ({type}) => {
140
+ const ScmIntegrationIcon = (props) => {
137
141
  var _a;
142
+ const { type } = props;
138
143
  const app = useApp();
139
144
  const DefaultIcon = CodeIcon;
140
145
  const Icon = type ? (_a = app.getSystemIcon(type)) != null ? _a : DefaultIcon : DefaultIcon;
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/api/ScmAuthApi.ts","../src/api/ScmAuth.ts","../src/api/ScmIntegrationsApi.ts","../src/components/ScmIntegrationIcon/ScmIntegrationIcon.tsx"],"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 {\n ApiRef,\n createApiRef,\n AuthRequestOptions,\n} from '@backstage/core-plugin-api';\n\n/** @public */\nexport interface ScmAuthTokenOptions extends AuthRequestOptions {\n /**\n * The URL of the SCM resource to be accessed.\n *\n * @example https://github.com/backstage/backstage\n */\n url: string;\n\n /**\n * Whether to request additional access scope.\n *\n * Read access to user, organization, and repositories is always included.\n */\n additionalScope?: {\n /**\n * Requests access to be able to write repository content, including\n * the ability to create things like issues and pull requests.\n */\n repoWrite?: boolean;\n };\n}\n\n/** @public */\nexport interface ScmAuthTokenResponse {\n /**\n * An authorization token that can be used to authenticate requests.\n */\n token: string;\n\n /**\n * The set of HTTP headers that are needed to authenticate requests.\n */\n headers: { [name: string]: string };\n}\n\n/**\n * ScmAuthApi provides methods for authenticating towards source code management services.\n *\n * As opposed to using the GitHub, GitLab and other auth APIs\n * directly, this API allows for more generic access to SCM services.\n *\n * @public\n */\nexport interface ScmAuthApi {\n /**\n * Requests credentials for accessing an SCM resource.\n */\n getCredentials(options: ScmAuthTokenOptions): Promise<ScmAuthTokenResponse>;\n}\n\n/**\n * The ApiRef for the ScmAuthApi.\n *\n * @public\n */\nexport const scmAuthApiRef: ApiRef<ScmAuthApi> = createApiRef({\n id: 'core.scmauth',\n});\n","/*\n * Copyright 2021 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 {\n createApiFactory,\n githubAuthApiRef,\n gitlabAuthApiRef,\n microsoftAuthApiRef,\n OAuthApi,\n} from '@backstage/core-plugin-api';\nimport {\n ScmAuthApi,\n scmAuthApiRef,\n ScmAuthTokenOptions,\n ScmAuthTokenResponse,\n} from './ScmAuthApi';\n\ntype ScopeMapping = {\n /** The base scopes used for all requests */\n default: string[];\n /** Additional scopes added if `repoWrite` is requested */\n repoWrite: string[];\n};\n\nclass ScmAuthMux implements ScmAuthApi {\n #providers: Array<ScmAuth>;\n\n constructor(providers: ScmAuth[]) {\n this.#providers = providers;\n }\n\n async getCredentials(\n options: ScmAuthTokenOptions,\n ): Promise<ScmAuthTokenResponse> {\n const url = new URL(options.url);\n const provider = this.#providers.find(p => p.isUrlSupported(url));\n if (!provider) {\n throw new Error(\n `No authentication provider available for access to '${options.url}'`,\n );\n }\n\n return provider.getCredentials(options);\n }\n}\n\n/**\n * An implementation of the ScmAuthApi that merges together OAuthApi instances\n * to form a single instance that can handles authentication for multiple providers.\n *\n * @public\n *\n * @example\n * ```\n * // Supports authentication towards both public GitHub and GHE:\n * createApiFactory({\n * api: scmAuthApiRef,\n * deps: {\n * gheAuthApi: gheAuthApiRef,\n * githubAuthApi: githubAuthApiRef,\n * },\n * factory: ({ githubAuthApi, gheAuthApi }) =>\n * ScmAuth.merge(\n * ScmAuth.forGithub(githubAuthApi),\n * ScmAuth.forGithub(gheAuthApi, {\n * host: 'ghe.example.com',\n * }),\n * )\n * })\n * ```\n */\nexport class ScmAuth implements ScmAuthApi {\n /**\n * Creates an API factory that enables auth for each of the default SCM providers.\n */\n static createDefaultApiFactory() {\n return createApiFactory({\n api: scmAuthApiRef,\n deps: {\n github: githubAuthApiRef,\n gitlab: gitlabAuthApiRef,\n azure: microsoftAuthApiRef,\n },\n factory: ({ github, gitlab, azure }) =>\n ScmAuth.merge(\n ScmAuth.forGithub(github),\n ScmAuth.forGitlab(gitlab),\n ScmAuth.forAzure(azure),\n ),\n });\n }\n\n /**\n * Creates a general purpose ScmAuth instance with a custom scope mapping.\n */\n static forAuthApi(\n authApi: OAuthApi,\n options: {\n host: string;\n scopeMapping: {\n default: string[];\n repoWrite: string[];\n };\n },\n ): ScmAuth {\n return new ScmAuth(authApi, options.host, options.scopeMapping);\n }\n\n /**\n * Creates a new ScmAuth instance that handles authentication towards GitHub.\n *\n * The host option determines which URLs that are handled by this instance and defaults to `github.com`.\n *\n * The default scopes are:\n *\n * `repo read:org read:user`\n *\n * If the additional `repoWrite` permission is requested, these scopes are added:\n *\n * `gist`\n */\n static forGithub(\n githubAuthApi: OAuthApi,\n options?: {\n host?: string;\n },\n ): ScmAuth {\n const host = options?.host ?? 'github.com';\n return new ScmAuth(githubAuthApi, host, {\n default: ['repo', 'read:org', 'read:user'],\n repoWrite: ['gist'],\n });\n }\n\n /**\n * Creates a new ScmAuth instance that handles authentication towards GitLab.\n *\n * The host option determines which URLs that are handled by this instance and defaults to `gitlab.com`.\n *\n * The default scopes are:\n *\n * `read_user read_api read_repository`\n *\n * If the additional `repoWrite` permission is requested, these scopes are added:\n *\n * `write_repository api`\n */\n static forGitlab(\n gitlabAuthApi: OAuthApi,\n options?: {\n host?: string;\n },\n ): ScmAuth {\n const host = options?.host ?? 'gitlab.com';\n return new ScmAuth(gitlabAuthApi, host, {\n default: ['read_user', 'read_api', 'read_repository'],\n repoWrite: ['write_repository', 'api'],\n });\n }\n\n /**\n * Creates a new ScmAuth instance that handles authentication towards Azure.\n *\n * The host option determines which URLs that are handled by this instance and defaults to `dev.azure.com`.\n *\n * The default scopes are:\n *\n * `vso.build vso.code vso.graph vso.project vso.profile`\n *\n * If the additional `repoWrite` permission is requested, these scopes are added:\n *\n * `vso.code_manage`\n */\n static forAzure(\n microsoftAuthApi: OAuthApi,\n options?: {\n host?: string;\n },\n ): ScmAuth {\n const host = options?.host ?? 'dev.azure.com';\n return new ScmAuth(microsoftAuthApi, host, {\n default: [\n 'vso.build',\n 'vso.code',\n 'vso.graph',\n 'vso.project',\n 'vso.profile',\n ],\n repoWrite: ['vso.code_manage'],\n });\n }\n\n /**\n * Creates a new ScmAuth instance that handles authentication towards Bitbucket.\n *\n * The host option determines which URLs that are handled by this instance and defaults to `bitbucket.org`.\n *\n * The default scopes are:\n *\n * `account team pullrequest snippet issue`\n *\n * If the additional `repoWrite` permission is requested, these scopes are added:\n *\n * `pullrequest:write snippet:write issue:write`\n */\n static forBitbucket(\n bitbucketAuthApi: OAuthApi,\n options?: {\n host?: string;\n },\n ): ScmAuth {\n const host = options?.host ?? 'bitbucket.org';\n return new ScmAuth(bitbucketAuthApi, host, {\n default: ['account', 'team', 'pullrequest', 'snippet', 'issue'],\n repoWrite: ['pullrequest:write', 'snippet:write', 'issue:write'],\n });\n }\n\n /**\n * Merges together multiple ScmAuth instances into one that\n * routes requests to the correct instance based on the URL.\n */\n static merge(...providers: ScmAuth[]): ScmAuthApi {\n return new ScmAuthMux(providers);\n }\n\n #api: OAuthApi;\n #host: string;\n #scopeMapping: ScopeMapping;\n\n private constructor(api: OAuthApi, host: string, scopeMapping: ScopeMapping) {\n this.#api = api;\n this.#host = host;\n this.#scopeMapping = scopeMapping;\n }\n\n /**\n * Checks whether the implementation is able to provide authentication for the given URL.\n */\n isUrlSupported(url: URL): boolean {\n return url.host === this.#host;\n }\n\n async getCredentials(\n options: ScmAuthTokenOptions,\n ): Promise<ScmAuthTokenResponse> {\n const { url, additionalScope, ...restOptions } = options;\n\n const scopes = this.#scopeMapping.default.slice();\n if (additionalScope?.repoWrite) {\n scopes.push(...this.#scopeMapping.repoWrite);\n }\n\n const token = await this.#api.getAccessToken(scopes, restOptions);\n return {\n token,\n headers: {\n Authorization: `Bearer ${token}`,\n },\n };\n }\n}\n","/*\n * Copyright 2021 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 { Config } from '@backstage/config';\nimport {\n ScmIntegrationRegistry,\n ScmIntegrations,\n} from '@backstage/integration';\nimport { ApiRef, createApiRef } from '@backstage/core-plugin-api';\n\nexport class ScmIntegrationsApi {\n static fromConfig(config: Config): ScmIntegrationRegistry {\n return ScmIntegrations.fromConfig(config);\n }\n}\n\nexport const scmIntegrationsApiRef: ApiRef<ScmIntegrationRegistry> =\n createApiRef({\n id: 'integration.scmintegrations',\n description: 'All of the registered SCM integrations of your config',\n });\n","/*\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 */\nimport CodeIcon from '@material-ui/icons/Code';\nimport React from 'react';\nimport { useApp } from '@backstage/core-plugin-api';\n\nexport const ScmIntegrationIcon = ({ type }: { type?: string }) => {\n const app = useApp();\n const DefaultIcon = CodeIcon;\n const Icon = type ? app.getSystemIcon(type) ?? DefaultIcon : DefaultIcon;\n return <Icon />;\n};\n"],"names":[],"mappings":";;;;;MA8Ea,gBAAoC,aAAa;AAAA,EAC5D,IAAI;AAAA;;;;;;;;;;;;;;;AC/EN;AAqCA,iBAAuC;AAAA,EAGrC,YAAY,WAAsB;AAFlC;AAGE,uBAAK,YAAa;AAAA;AAAA,QAGd,eACJ,SAC+B;AAC/B,UAAM,MAAM,IAAI,IAAI,QAAQ;AAC5B,UAAM,WAAW,mBAAK,YAAW,KAAK,OAAK,EAAE,eAAe;AAC5D,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,MACR,uDAAuD,QAAQ;AAAA;AAInE,WAAO,SAAS,eAAe;AAAA;AAAA;AAjBjC;AA8CK,uBAAoC;AAAA,EA+JjC,YAAY,KAAe,MAAc,cAA4B;AAJ7E;AACA;AACA;AAGE,uBAAK,MAAO;AACZ,uBAAK,OAAQ;AACb,uBAAK,eAAgB;AAAA;AAAA,SA9JhB,0BAA0B;AAC/B,WAAO,iBAAiB;AAAA,MACtB,KAAK;AA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AS,mBAAK;AAAA;AAAA,QAGrB,eACJ,SAC+B;AAC/B,UAAM,CAAE,KAAK,oBAAoB,eAAgB;AAEjD,UAAM,SAAS,mBAAK,eAAc,QAAQ;AAC1C,QAAI,mDAAiB,WAAW;AAC9B,aAAO,KAAK,GAAG,mBAAK,eAAc;AAAA;AAGpC,UAAM,QAAQ,MAAM,mBAAK,MAAK,eAAe,QAAQ;AACrD,WAAO;AAAA,MACL;AAAA,MACA,SAAS;AAAA,QACP,eAAe,UAAU;AAAA;AAAA;AAAA;AAAA;;AA/B/B;AACA;AACA;;yBC1N8B;AAAA,SACvB,WAAW,QAAwC;AACxD,WAAO,gBAAgB,WAAW;AAAA;AAAA;MAIzB,wBACX,aAAa;AAAA,EACX,IAAI;AAAA,EACJ,aAAa;AAAA;;MCbJ,qBAAqB,CAAC,CAAE,UAA8B;AAnBnE;AAoBE,QAAM,MAAM;AACZ,QAAM,cAAc;AACpB,QAAM,OAAO,OAAO,UAAI,cAAc,UAAlB,YAA2B,cAAc;AAC7D,6CAAQ,MAAD;AAAA;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/api/ScmAuthApi.ts","../src/api/ScmAuth.ts","../src/api/ScmIntegrationsApi.ts","../src/components/ScmIntegrationIcon/ScmIntegrationIcon.tsx"],"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 {\n ApiRef,\n createApiRef,\n AuthRequestOptions,\n} from '@backstage/core-plugin-api';\n\n/**\n * The options that control a {@link ScmAuthApi.getCredentials} call.\n *\n * @public\n */\nexport interface ScmAuthTokenOptions extends AuthRequestOptions {\n /**\n * The URL of the SCM resource to be accessed.\n *\n * @example https://github.com/backstage/backstage\n */\n url: string;\n\n /**\n * Whether to request additional access scope.\n *\n * Read access to user, organization, and repositories is always included.\n */\n additionalScope?: {\n /**\n * Requests access to be able to write repository content, including\n * the ability to create things like issues and pull requests.\n */\n repoWrite?: boolean;\n };\n}\n\n/**\n * The response from a {@link ScmAuthApi.getCredentials} call.\n *\n * @public\n */\nexport interface ScmAuthTokenResponse {\n /**\n * An authorization token that can be used to authenticate requests.\n */\n token: string;\n\n /**\n * The set of HTTP headers that are needed to authenticate requests.\n */\n headers: { [name: string]: string };\n}\n\n/**\n * ScmAuthApi provides methods for authenticating towards source code management services.\n *\n * As opposed to using the GitHub, GitLab and other auth APIs\n * directly, this API allows for more generic access to SCM services.\n *\n * @public\n */\nexport interface ScmAuthApi {\n /**\n * Requests credentials for accessing an SCM resource.\n */\n getCredentials(options: ScmAuthTokenOptions): Promise<ScmAuthTokenResponse>;\n}\n\n/**\n * The ApiRef for the ScmAuthApi.\n *\n * @public\n */\nexport const scmAuthApiRef: ApiRef<ScmAuthApi> = createApiRef({\n id: 'core.scmauth',\n});\n","/*\n * Copyright 2021 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 {\n createApiFactory,\n githubAuthApiRef,\n gitlabAuthApiRef,\n microsoftAuthApiRef,\n OAuthApi,\n} from '@backstage/core-plugin-api';\nimport {\n ScmAuthApi,\n scmAuthApiRef,\n ScmAuthTokenOptions,\n ScmAuthTokenResponse,\n} from './ScmAuthApi';\n\ntype ScopeMapping = {\n /** The base scopes used for all requests */\n default: string[];\n /** Additional scopes added if `repoWrite` is requested */\n repoWrite: string[];\n};\n\nclass ScmAuthMux implements ScmAuthApi {\n #providers: Array<ScmAuth>;\n\n constructor(providers: ScmAuth[]) {\n this.#providers = providers;\n }\n\n async getCredentials(\n options: ScmAuthTokenOptions,\n ): Promise<ScmAuthTokenResponse> {\n const url = new URL(options.url);\n const provider = this.#providers.find(p => p.isUrlSupported(url));\n if (!provider) {\n throw new Error(\n `No authentication provider available for access to '${options.url}'`,\n );\n }\n\n return provider.getCredentials(options);\n }\n}\n\n/**\n * An implementation of the ScmAuthApi that merges together OAuthApi instances\n * to form a single instance that can handles authentication for multiple providers.\n *\n * @public\n *\n * @example\n * ```\n * // Supports authentication towards both public GitHub and GHE:\n * createApiFactory({\n * api: scmAuthApiRef,\n * deps: {\n * gheAuthApi: gheAuthApiRef,\n * githubAuthApi: githubAuthApiRef,\n * },\n * factory: ({ githubAuthApi, gheAuthApi }) =>\n * ScmAuth.merge(\n * ScmAuth.forGithub(githubAuthApi),\n * ScmAuth.forGithub(gheAuthApi, {\n * host: 'ghe.example.com',\n * }),\n * )\n * })\n * ```\n */\nexport class ScmAuth implements ScmAuthApi {\n /**\n * Creates an API factory that enables auth for each of the default SCM providers.\n */\n static createDefaultApiFactory() {\n return createApiFactory({\n api: scmAuthApiRef,\n deps: {\n github: githubAuthApiRef,\n gitlab: gitlabAuthApiRef,\n azure: microsoftAuthApiRef,\n },\n factory: ({ github, gitlab, azure }) =>\n ScmAuth.merge(\n ScmAuth.forGithub(github),\n ScmAuth.forGitlab(gitlab),\n ScmAuth.forAzure(azure),\n ),\n });\n }\n\n /**\n * Creates a general purpose ScmAuth instance with a custom scope mapping.\n */\n static forAuthApi(\n authApi: OAuthApi,\n options: {\n host: string;\n scopeMapping: {\n default: string[];\n repoWrite: string[];\n };\n },\n ): ScmAuth {\n return new ScmAuth(authApi, options.host, options.scopeMapping);\n }\n\n /**\n * Creates a new ScmAuth instance that handles authentication towards GitHub.\n *\n * The host option determines which URLs that are handled by this instance and defaults to `github.com`.\n *\n * The default scopes are:\n *\n * `repo read:org read:user`\n *\n * If the additional `repoWrite` permission is requested, these scopes are added:\n *\n * `gist`\n */\n static forGithub(\n githubAuthApi: OAuthApi,\n options?: {\n host?: string;\n },\n ): ScmAuth {\n const host = options?.host ?? 'github.com';\n return new ScmAuth(githubAuthApi, host, {\n default: ['repo', 'read:org', 'read:user'],\n repoWrite: ['gist'],\n });\n }\n\n /**\n * Creates a new ScmAuth instance that handles authentication towards GitLab.\n *\n * The host option determines which URLs that are handled by this instance and defaults to `gitlab.com`.\n *\n * The default scopes are:\n *\n * `read_user read_api read_repository`\n *\n * If the additional `repoWrite` permission is requested, these scopes are added:\n *\n * `write_repository api`\n */\n static forGitlab(\n gitlabAuthApi: OAuthApi,\n options?: {\n host?: string;\n },\n ): ScmAuth {\n const host = options?.host ?? 'gitlab.com';\n return new ScmAuth(gitlabAuthApi, host, {\n default: ['read_user', 'read_api', 'read_repository'],\n repoWrite: ['write_repository', 'api'],\n });\n }\n\n /**\n * Creates a new ScmAuth instance that handles authentication towards Azure.\n *\n * The host option determines which URLs that are handled by this instance and defaults to `dev.azure.com`.\n *\n * The default scopes are:\n *\n * `vso.build vso.code vso.graph vso.project vso.profile`\n *\n * If the additional `repoWrite` permission is requested, these scopes are added:\n *\n * `vso.code_manage`\n */\n static forAzure(\n microsoftAuthApi: OAuthApi,\n options?: {\n host?: string;\n },\n ): ScmAuth {\n const host = options?.host ?? 'dev.azure.com';\n return new ScmAuth(microsoftAuthApi, host, {\n default: [\n 'vso.build',\n 'vso.code',\n 'vso.graph',\n 'vso.project',\n 'vso.profile',\n ],\n repoWrite: ['vso.code_manage'],\n });\n }\n\n /**\n * Creates a new ScmAuth instance that handles authentication towards Bitbucket.\n *\n * The host option determines which URLs that are handled by this instance and defaults to `bitbucket.org`.\n *\n * The default scopes are:\n *\n * `account team pullrequest snippet issue`\n *\n * If the additional `repoWrite` permission is requested, these scopes are added:\n *\n * `pullrequest:write snippet:write issue:write`\n */\n static forBitbucket(\n bitbucketAuthApi: OAuthApi,\n options?: {\n host?: string;\n },\n ): ScmAuth {\n const host = options?.host ?? 'bitbucket.org';\n return new ScmAuth(bitbucketAuthApi, host, {\n default: ['account', 'team', 'pullrequest', 'snippet', 'issue'],\n repoWrite: ['pullrequest:write', 'snippet:write', 'issue:write'],\n });\n }\n\n /**\n * Merges together multiple ScmAuth instances into one that\n * routes requests to the correct instance based on the URL.\n */\n static merge(...providers: ScmAuth[]): ScmAuthApi {\n return new ScmAuthMux(providers);\n }\n\n #api: OAuthApi;\n #host: string;\n #scopeMapping: ScopeMapping;\n\n private constructor(api: OAuthApi, host: string, scopeMapping: ScopeMapping) {\n this.#api = api;\n this.#host = host;\n this.#scopeMapping = scopeMapping;\n }\n\n /**\n * Checks whether the implementation is able to provide authentication for the given URL.\n */\n isUrlSupported(url: URL): boolean {\n return url.host === this.#host;\n }\n\n /**\n * Fetches credentials for the given resource.\n */\n async getCredentials(\n options: ScmAuthTokenOptions,\n ): Promise<ScmAuthTokenResponse> {\n const { url, additionalScope, ...restOptions } = options;\n\n const scopes = this.#scopeMapping.default.slice();\n if (additionalScope?.repoWrite) {\n scopes.push(...this.#scopeMapping.repoWrite);\n }\n\n const token = await this.#api.getAccessToken(scopes, restOptions);\n return {\n token,\n headers: {\n Authorization: `Bearer ${token}`,\n },\n };\n }\n}\n","/*\n * Copyright 2021 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 { Config } from '@backstage/config';\nimport {\n ScmIntegrationRegistry,\n ScmIntegrations,\n} from '@backstage/integration';\nimport { ApiRef, createApiRef } from '@backstage/core-plugin-api';\n\n/**\n * Factory class for creating {@link @backstage/integration#ScmIntegrationRegistry} instances.\n *\n * @public\n */\nexport class ScmIntegrationsApi {\n /**\n * Instantiates an {@link @backstage/integration#ScmIntegrationRegistry}.\n *\n * @param config - The root of the config hierarchy.\n */\n static fromConfig(config: Config): ScmIntegrationRegistry {\n return ScmIntegrations.fromConfig(config);\n }\n}\n\n/**\n * The API that holds all configured SCM integrations.\n *\n * @public\n */\nexport const scmIntegrationsApiRef: ApiRef<ScmIntegrationRegistry> =\n createApiRef({\n id: 'integration.scmintegrations',\n });\n","/*\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 */\nimport CodeIcon from '@material-ui/icons/Code';\nimport React from 'react';\nimport { useApp } from '@backstage/core-plugin-api';\n\n/**\n * Props for {@link ScmIntegrationIcon}.\n *\n * @public\n */\nexport type ScmIntegrationIconProps = {\n /**\n * The integration type, e.g. \"github\".\n */\n type?: string;\n};\n\n/**\n * An icon that represents a certain SCM integration.\n *\n * @public\n */\nexport const ScmIntegrationIcon = (props: ScmIntegrationIconProps) => {\n const { type } = props;\n const app = useApp();\n const DefaultIcon = CodeIcon;\n const Icon = type ? app.getSystemIcon(type) ?? DefaultIcon : DefaultIcon;\n return <Icon />;\n};\n"],"names":[],"mappings":";;;;;MAsFa,gBAAoC,aAAa;AAAA,EAC5D,IAAI;AAAA;;;;;;;;;;;;;;;;;;;;ACvFN;AAqCA,iBAAuC;AAAA,EAGrC,YAAY,WAAsB;AAFlC;AAGE,uBAAK,YAAa;AAAA;AAAA,QAGd,eACJ,SAC+B;AAC/B,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A;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA;AAAA,MAEF,WAAW,CAAC;AAAA;AAAA;AAAA,SAiBT,aACL,kBACA,SAGS;AA/Nb;AAgOI,UAAM,OAAO,yCAAS,SAAT,YAAiB;AAC9B,WAAO,IAAI,SAAQ,kBAAkB,MAAM;AAAA,MACzC,SAAS,CAAC,WAAW,QAAQ,eAAe,WAAW;AAAA,MACvD,WAAW,CAAC,qBAAqB,iBAAiB;AAAA;AAAA;AAAA,SAQ/C,SAAS,WAAkC;AAChD,WAAO,IAAI,WAAW;AAAA;AAAA,EAgBxB,eAAe,KAAmB;AAChC,WAAO,IAAI,SAAS,mBAAK;AAAA;AAAA,QAMrB,eACJ,SAC+B;AAC/B,UAAM,EAAE,KAAK,oBAAoB,gBAAgB;AAEjD,UAAM,SAAS,mBAAK,eAAc,QAAQ;AAC1C,QAAI,mDAAiB,WAAW;AAC9B,aAAO,KAAK,GAAG,mBAAK,eAAc;AAAA;AAGpC,UAAM,QAAQ,MAAM,mBAAK,MAAK,eAAe,QAAQ;AACrD,WAAO;AAAA,MACL;AAAA,MACA,SAAS;AAAA,QACP,eAAe,UAAU;AAAA;AAAA;AAAA;AAAA;;AAlC/B;AACA;AACA;;yBCrN8B;AAAA,SAMvB,WAAW,QAAwC;AACxD,WAAO,gBAAgB,WAAW;AAAA;AAAA;MASzB,wBACX,aAAa;AAAA,EACX,IAAI;AAAA;;MCVK,qBAAqB,CAAC,UAAmC;AApCtE;AAqCE,QAAM,EAAE,SAAS;AACjB,QAAM,MAAM;AACZ,QAAM,cAAc;AACpB,QAAM,OAAO,OAAO,UAAI,cAAc,UAAlB,YAA2B,cAAc;AAC7D,6CAAQ,MAAD;AAAA;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/integration-react",
3
3
  "description": "Frontend package for managing integrations towards external systems",
4
- "version": "0.1.12",
4
+ "version": "0.1.16",
5
5
  "main": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -21,32 +21,33 @@
21
21
  "clean": "backstage-cli clean"
22
22
  },
23
23
  "dependencies": {
24
- "@backstage/config": "^0.1.10",
25
- "@backstage/core-components": "^0.7.0",
26
- "@backstage/core-plugin-api": "^0.1.9",
27
- "@backstage/integration": "^0.6.8",
28
- "@backstage/theme": "^0.2.11",
24
+ "@backstage/config": "^0.1.11",
25
+ "@backstage/core-components": "^0.8.2",
26
+ "@backstage/core-plugin-api": "^0.4.0",
27
+ "@backstage/integration": "^0.6.10",
28
+ "@backstage/theme": "^0.2.14",
29
29
  "@material-ui/core": "^4.12.2",
30
30
  "@material-ui/icons": "^4.9.1",
31
31
  "@material-ui/lab": "4.0.0-alpha.57",
32
- "react": "^16.13.1",
33
- "react-dom": "^16.13.1",
34
32
  "react-use": "^17.2.4"
35
33
  },
34
+ "peerDependencies": {
35
+ "react": "^16.13.1 || ^17.0.0"
36
+ },
36
37
  "devDependencies": {
37
- "@backstage/cli": "^0.7.16",
38
- "@backstage/dev-utils": "^0.2.12",
39
- "@backstage/test-utils": "^0.1.19",
38
+ "@backstage/cli": "^0.10.3",
39
+ "@backstage/dev-utils": "^0.2.15",
40
+ "@backstage/test-utils": "^0.2.0",
40
41
  "@testing-library/jest-dom": "^5.10.1",
41
42
  "@testing-library/react": "^11.2.5",
42
43
  "@testing-library/user-event": "^13.1.8",
43
44
  "@types/jest": "^26.0.7",
44
45
  "@types/node": "^14.14.32",
45
46
  "cross-fetch": "^3.0.6",
46
- "msw": "^0.29.0"
47
+ "msw": "^0.35.0"
47
48
  },
48
49
  "files": [
49
50
  "dist"
50
51
  ],
51
- "gitHead": "1b02df9f467ea11a4571df46faabe655c3ee10c8"
52
+ "gitHead": "b315430f9dfcfa19ab0dd90f5b4ac6904938fba7"
52
53
  }