@backstage/plugin-catalog-backend-module-msgraph 0.6.3-next.1 → 0.6.4-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 +24 -0
- package/alpha/package.json +1 -1
- package/dist/alpha.cjs.js +2 -3
- package/dist/alpha.cjs.js.map +1 -1
- package/dist/alpha.d.ts +3 -43
- package/dist/index.cjs.js +5 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +47 -3
- package/dist/microsoftGraph/client.cjs.js +1 -1
- package/dist/microsoftGraph/client.cjs.js.map +1 -1
- package/dist/module/catalogModuleMicrosoftGraphOrgEntityProvider.cjs.js.map +1 -1
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @backstage/plugin-catalog-backend-module-msgraph
|
|
2
2
|
|
|
3
|
+
## 0.6.4-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @backstage/plugin-catalog-node@1.14.0-next.0
|
|
9
|
+
- @backstage/backend-plugin-api@1.0.2-next.0
|
|
10
|
+
- @backstage/catalog-model@1.7.0
|
|
11
|
+
- @backstage/config@1.2.0
|
|
12
|
+
- @backstage/plugin-catalog-common@1.1.0
|
|
13
|
+
|
|
14
|
+
## 0.6.3
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 4b60e0c: Remove extension points from `/alpha` export, they're available from the main package already
|
|
19
|
+
- 3109c24: The export for the new backend system at the `/alpha` export is now also available via the main entry point, which means that you can remove the `/alpha` suffix from the import.
|
|
20
|
+
- Updated dependencies
|
|
21
|
+
- @backstage/plugin-catalog-node@1.13.1
|
|
22
|
+
- @backstage/backend-plugin-api@1.0.1
|
|
23
|
+
- @backstage/catalog-model@1.7.0
|
|
24
|
+
- @backstage/config@1.2.0
|
|
25
|
+
- @backstage/plugin-catalog-common@1.1.0
|
|
26
|
+
|
|
3
27
|
## 0.6.3-next.1
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/alpha/package.json
CHANGED
package/dist/alpha.cjs.js
CHANGED
|
@@ -4,8 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var catalogModuleMicrosoftGraphOrgEntityProvider = require('./module/catalogModuleMicrosoftGraphOrgEntityProvider.cjs.js');
|
|
6
6
|
|
|
7
|
+
const _feature = catalogModuleMicrosoftGraphOrgEntityProvider.catalogModuleMicrosoftGraphOrgEntityProvider;
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
exports.default = catalogModuleMicrosoftGraphOrgEntityProvider.catalogModuleMicrosoftGraphOrgEntityProvider;
|
|
10
|
-
exports.microsoftGraphOrgEntityProviderTransformExtensionPoint = catalogModuleMicrosoftGraphOrgEntityProvider.microsoftGraphOrgEntityProviderTransformExtensionPoint;
|
|
9
|
+
exports.default = _feature;
|
|
11
10
|
//# sourceMappingURL=alpha.cjs.js.map
|
package/dist/alpha.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alpha.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"alpha.cjs.js","sources":["../src/alpha.ts"],"sourcesContent":["/*\n * Copyright 2023 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 { default as feature } from './module';\n\n/** @alpha */\nconst _feature = feature;\nexport default _feature;\n"],"names":["feature"],"mappings":";;;;;;AAmBA,MAAM,QAAW,GAAAA;;;;"}
|
package/dist/alpha.d.ts
CHANGED
|
@@ -1,46 +1,6 @@
|
|
|
1
1
|
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
-
import { UserTransformer, GroupTransformer, OrganizationTransformer, ProviderConfigTransformer } from '@backstage/plugin-catalog-backend-module-msgraph';
|
|
3
2
|
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* @alpha
|
|
8
|
-
*/
|
|
9
|
-
interface MicrosoftGraphOrgEntityProviderTransformsExtensionPoint {
|
|
10
|
-
/**
|
|
11
|
-
* Set the function that transforms a user entry in msgraph to an entity.
|
|
12
|
-
* Optionally, you can pass separate transformers per provider ID.
|
|
13
|
-
*/
|
|
14
|
-
setUserTransformer(transformer: UserTransformer | Record<string, UserTransformer>): void;
|
|
15
|
-
/**
|
|
16
|
-
* Set the function that transforms a group entry in msgraph to an entity.
|
|
17
|
-
* Optionally, you can pass separate transformers per provider ID.
|
|
18
|
-
*/
|
|
19
|
-
setGroupTransformer(transformer: GroupTransformer | Record<string, GroupTransformer>): void;
|
|
20
|
-
/**
|
|
21
|
-
* Set the function that transforms an organization entry in msgraph to an entity.
|
|
22
|
-
* Optionally, you can pass separate transformers per provider ID.
|
|
23
|
-
*/
|
|
24
|
-
setOrganizationTransformer(transformer: OrganizationTransformer | Record<string, OrganizationTransformer>): void;
|
|
25
|
-
/**
|
|
26
|
-
* Set the function that transforms provider config dynamically.
|
|
27
|
-
* Optionally, you can pass separate transformers per provider ID.
|
|
28
|
-
* Note: adjusting fields that are not used on each scheduled ingestion
|
|
29
|
-
* (e.g., id, schedule) will have no effect.
|
|
30
|
-
*/
|
|
31
|
-
setProviderConfigTransformer(transformer: ProviderConfigTransformer | Record<string, ProviderConfigTransformer>): void;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Extension point used to customize the transforms used by the module.
|
|
35
|
-
*
|
|
36
|
-
* @alpha
|
|
37
|
-
*/
|
|
38
|
-
declare const microsoftGraphOrgEntityProviderTransformExtensionPoint: _backstage_backend_plugin_api.ExtensionPoint<MicrosoftGraphOrgEntityProviderTransformsExtensionPoint>;
|
|
39
|
-
/**
|
|
40
|
-
* Registers the MicrosoftGraphOrgEntityProvider with the catalog processing extension point.
|
|
41
|
-
*
|
|
42
|
-
* @alpha
|
|
43
|
-
*/
|
|
44
|
-
declare const catalogModuleMicrosoftGraphOrgEntityProvider: _backstage_backend_plugin_api.BackendFeature;
|
|
3
|
+
/** @alpha */
|
|
4
|
+
declare const _feature: _backstage_backend_plugin_api.BackendFeature;
|
|
45
5
|
|
|
46
|
-
export {
|
|
6
|
+
export { _feature as default };
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var catalogModuleMicrosoftGraphOrgEntityProvider = require('./module/catalogModuleMicrosoftGraphOrgEntityProvider.cjs.js');
|
|
3
6
|
var client = require('./microsoftGraph/client.cjs.js');
|
|
4
7
|
var config = require('./microsoftGraph/config.cjs.js');
|
|
5
8
|
var constants = require('./microsoftGraph/constants.cjs.js');
|
|
@@ -11,6 +14,8 @@ var MicrosoftGraphOrgReaderProcessor = require('./processors/MicrosoftGraphOrgRe
|
|
|
11
14
|
|
|
12
15
|
|
|
13
16
|
|
|
17
|
+
exports.default = catalogModuleMicrosoftGraphOrgEntityProvider.catalogModuleMicrosoftGraphOrgEntityProvider;
|
|
18
|
+
exports.microsoftGraphOrgEntityProviderTransformExtensionPoint = catalogModuleMicrosoftGraphOrgEntityProvider.microsoftGraphOrgEntityProviderTransformExtensionPoint;
|
|
14
19
|
exports.MicrosoftGraphClient = client.MicrosoftGraphClient;
|
|
15
20
|
exports.readMicrosoftGraphConfig = config.readMicrosoftGraphConfig;
|
|
16
21
|
exports.readProviderConfig = config.readProviderConfig;
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,56 @@
|
|
|
1
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
+
import { SchedulerServiceTaskScheduleDefinition, LoggerService, SchedulerServiceTaskRunner, SchedulerService } from '@backstage/backend-plugin-api';
|
|
3
|
+
import { UserTransformer as UserTransformer$1, GroupTransformer as GroupTransformer$1, OrganizationTransformer as OrganizationTransformer$1, ProviderConfigTransformer as ProviderConfigTransformer$1 } from '@backstage/plugin-catalog-backend-module-msgraph';
|
|
1
4
|
import { TokenCredential } from '@azure/identity';
|
|
2
5
|
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
|
|
3
6
|
import { Response } from 'node-fetch';
|
|
4
|
-
import { SchedulerServiceTaskScheduleDefinition, LoggerService, SchedulerServiceTaskRunner, SchedulerService } from '@backstage/backend-plugin-api';
|
|
5
7
|
import { Config } from '@backstage/config';
|
|
6
8
|
import { GroupEntity, UserEntity } from '@backstage/catalog-model';
|
|
7
9
|
import { EntityProvider, EntityProviderConnection, CatalogProcessor, CatalogProcessorEmit } from '@backstage/plugin-catalog-node';
|
|
8
10
|
import { LocationSpec } from '@backstage/plugin-catalog-common';
|
|
9
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Interface for {@link microsoftGraphOrgEntityProviderTransformExtensionPoint}.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
interface MicrosoftGraphOrgEntityProviderTransformsExtensionPoint {
|
|
18
|
+
/**
|
|
19
|
+
* Set the function that transforms a user entry in msgraph to an entity.
|
|
20
|
+
* Optionally, you can pass separate transformers per provider ID.
|
|
21
|
+
*/
|
|
22
|
+
setUserTransformer(transformer: UserTransformer$1 | Record<string, UserTransformer$1>): void;
|
|
23
|
+
/**
|
|
24
|
+
* Set the function that transforms a group entry in msgraph to an entity.
|
|
25
|
+
* Optionally, you can pass separate transformers per provider ID.
|
|
26
|
+
*/
|
|
27
|
+
setGroupTransformer(transformer: GroupTransformer$1 | Record<string, GroupTransformer$1>): void;
|
|
28
|
+
/**
|
|
29
|
+
* Set the function that transforms an organization entry in msgraph to an entity.
|
|
30
|
+
* Optionally, you can pass separate transformers per provider ID.
|
|
31
|
+
*/
|
|
32
|
+
setOrganizationTransformer(transformer: OrganizationTransformer$1 | Record<string, OrganizationTransformer$1>): void;
|
|
33
|
+
/**
|
|
34
|
+
* Set the function that transforms provider config dynamically.
|
|
35
|
+
* Optionally, you can pass separate transformers per provider ID.
|
|
36
|
+
* Note: adjusting fields that are not used on each scheduled ingestion
|
|
37
|
+
* (e.g., id, schedule) will have no effect.
|
|
38
|
+
*/
|
|
39
|
+
setProviderConfigTransformer(transformer: ProviderConfigTransformer$1 | Record<string, ProviderConfigTransformer$1>): void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Extension point used to customize the transforms used by the module.
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
declare const microsoftGraphOrgEntityProviderTransformExtensionPoint: _backstage_backend_plugin_api.ExtensionPoint<MicrosoftGraphOrgEntityProviderTransformsExtensionPoint>;
|
|
47
|
+
/**
|
|
48
|
+
* Registers the MicrosoftGraphOrgEntityProvider with the catalog processing extension point.
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
declare const catalogModuleMicrosoftGraphOrgEntityProvider: _backstage_backend_plugin_api.BackendFeature;
|
|
53
|
+
|
|
10
54
|
/**
|
|
11
55
|
* The configuration parameters for a single Microsoft Graph provider.
|
|
12
56
|
*
|
|
@@ -314,7 +358,7 @@ declare class MicrosoftGraphClient {
|
|
|
314
358
|
* from Graph API
|
|
315
359
|
*
|
|
316
360
|
* @param entityName - type of parent resource, either `User` or `Group`
|
|
317
|
-
* @param id - The unique identifier for the
|
|
361
|
+
* @param id - The unique identifier for the `entityName` resource
|
|
318
362
|
* @param maxSize - Maximum pixel height of the photo
|
|
319
363
|
*
|
|
320
364
|
*/
|
|
@@ -602,4 +646,4 @@ declare class MicrosoftGraphOrgReaderProcessor implements CatalogProcessor {
|
|
|
602
646
|
readLocation(location: LocationSpec, _optional: boolean, emit: CatalogProcessorEmit): Promise<boolean>;
|
|
603
647
|
}
|
|
604
648
|
|
|
605
|
-
export { type GroupMember, type GroupTransformer, MICROSOFT_EMAIL_ANNOTATION, MICROSOFT_GRAPH_GROUP_ID_ANNOTATION, MICROSOFT_GRAPH_TENANT_ID_ANNOTATION, MICROSOFT_GRAPH_USER_ID_ANNOTATION, MicrosoftGraphClient, MicrosoftGraphOrgEntityProvider, type MicrosoftGraphOrgEntityProviderLegacyOptions, type MicrosoftGraphOrgEntityProviderOptions, MicrosoftGraphOrgReaderProcessor, type MicrosoftGraphProviderConfig, type ODataQuery, type OrganizationTransformer, type ProviderConfigTransformer, type UserTransformer, defaultGroupTransformer, defaultOrganizationTransformer, defaultUserTransformer, normalizeEntityName, readMicrosoftGraphConfig, readMicrosoftGraphOrg, readProviderConfig, readProviderConfigs };
|
|
649
|
+
export { type GroupMember, type GroupTransformer, MICROSOFT_EMAIL_ANNOTATION, MICROSOFT_GRAPH_GROUP_ID_ANNOTATION, MICROSOFT_GRAPH_TENANT_ID_ANNOTATION, MICROSOFT_GRAPH_USER_ID_ANNOTATION, MicrosoftGraphClient, MicrosoftGraphOrgEntityProvider, type MicrosoftGraphOrgEntityProviderLegacyOptions, type MicrosoftGraphOrgEntityProviderOptions, type MicrosoftGraphOrgEntityProviderTransformsExtensionPoint, MicrosoftGraphOrgReaderProcessor, type MicrosoftGraphProviderConfig, type ODataQuery, type OrganizationTransformer, type ProviderConfigTransformer, type UserTransformer, catalogModuleMicrosoftGraphOrgEntityProvider as default, defaultGroupTransformer, defaultOrganizationTransformer, defaultUserTransformer, microsoftGraphOrgEntityProviderTransformExtensionPoint, normalizeEntityName, readMicrosoftGraphConfig, readMicrosoftGraphOrg, readProviderConfig, readProviderConfigs };
|
|
@@ -241,7 +241,7 @@ class MicrosoftGraphClient {
|
|
|
241
241
|
* from Graph API
|
|
242
242
|
*
|
|
243
243
|
* @param entityName - type of parent resource, either `User` or `Group`
|
|
244
|
-
* @param id - The unique identifier for the
|
|
244
|
+
* @param id - The unique identifier for the `entityName` resource
|
|
245
245
|
* @param maxSize - Maximum pixel height of the photo
|
|
246
246
|
*
|
|
247
247
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.cjs.js","sources":["../../src/microsoftGraph/client.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n TokenCredential,\n DefaultAzureCredential,\n ClientSecretCredential,\n} from '@azure/identity';\nimport * as MicrosoftGraph from '@microsoft/microsoft-graph-types';\nimport fetch, { Response } from 'node-fetch';\nimport qs from 'qs';\nimport { MicrosoftGraphProviderConfig } from './config';\n\n/**\n * OData (Open Data Protocol) Query\n *\n * {@link https://docs.microsoft.com/en-us/odata/concepts/queryoptions-overview}\n * {@link https://docs.microsoft.com/en-us/graph/query-parameters}\n * @public\n */\nexport type ODataQuery = {\n /**\n * search resources within a collection matching a free-text search expression.\n */\n search?: string;\n /**\n * filter a collection of resources\n */\n filter?: string;\n /**\n * specifies the related resources or media streams to be included in line with retrieved resources\n */\n expand?: string;\n /**\n * request a specific set of properties for each entity or complex type\n */\n select?: string[];\n /**\n * Retrieves the total count of matching resources.\n */\n count?: boolean;\n /**\n * Maximum number of records to receive in one batch.\n */\n top?: number;\n};\n\n/**\n * Extends the base msgraph types to include the odata type.\n *\n * @public\n */\nexport type GroupMember =\n | (MicrosoftGraph.Group & { '@odata.type': '#microsoft.graph.group' })\n | (MicrosoftGraph.User & { '@odata.type': '#microsoft.graph.user' });\n\n/**\n * A HTTP Client that communicates with Microsoft Graph API.\n * Simplify Authentication and API calls to get `User` and `Group` from Microsoft Graph\n *\n * Uses `msal-node` for authentication\n *\n * @public\n */\nexport class MicrosoftGraphClient {\n /**\n * Factory method that instantiate `msal` client and return\n * an instance of `MicrosoftGraphClient`\n *\n * @public\n *\n * @param config - Configuration for Interacting with Graph API\n */\n static create(config: MicrosoftGraphProviderConfig): MicrosoftGraphClient {\n const options = {\n authorityHost: config.authority,\n tenantId: config.tenantId,\n };\n\n const credential =\n config.clientId && config.clientSecret\n ? new ClientSecretCredential(\n config.tenantId,\n config.clientId,\n config.clientSecret,\n options,\n )\n : new DefaultAzureCredential(options);\n\n return new MicrosoftGraphClient(config.target, credential);\n }\n\n /**\n * @param baseUrl - baseUrl of Graph API {@link MicrosoftGraphProviderConfig.target}\n * @param tokenCredential - instance of `TokenCredential` that is used to acquire token for Graph API calls\n *\n */\n constructor(\n private readonly baseUrl: string,\n private readonly tokenCredential: TokenCredential,\n ) {}\n\n /**\n * Get a collection of resource from Graph API and\n * return an `AsyncIterable` of that resource\n *\n * @public\n * @param path - Resource in Microsoft Graph\n * @param query - OData Query {@link ODataQuery}\n * @param queryMode - Mode to use while querying. Some features are only available at \"advanced\".\n */\n async *requestCollection<T>(\n path: string,\n query?: ODataQuery,\n queryMode?: 'basic' | 'advanced',\n ): AsyncIterable<T> {\n // upgrade to advanced query mode transparently when \"search\" is used\n // to stay backwards compatible.\n const appliedQueryMode = query?.search ? 'advanced' : queryMode ?? 'basic';\n\n // not needed for \"search\"\n // as of https://docs.microsoft.com/en-us/graph/aad-advanced-queries?tabs=http\n // even though a few other places say the opposite\n // - https://docs.microsoft.com/en-us/graph/api/user-list?view=graph-rest-1.0&tabs=http#request-headers\n // - https://docs.microsoft.com/en-us/graph/api/resources/group?view=graph-rest-1.0#properties\n if (appliedQueryMode === 'advanced' && (query?.filter || query?.select)) {\n query.count = true;\n }\n const headers: Record<string, string> =\n appliedQueryMode === 'advanced'\n ? {\n // Eventual consistency is required for advanced querying capabilities\n // like \"$search\" or parts of \"$filter\".\n // If a new user/group is not found, it'll eventually be imported on a subsequent read\n ConsistencyLevel: 'eventual',\n }\n : {};\n\n let response = await this.requestApi(path, query, headers);\n\n for (;;) {\n if (response.status !== 200) {\n await this.handleError(path, response);\n }\n\n const result = await response.json();\n\n // Graph API return array of collections\n const elements: T[] = result.value;\n\n yield* elements;\n\n // Follow cursor to the next page if one is available\n if (!result['@odata.nextLink']) {\n return;\n }\n\n response = await this.requestRaw(result['@odata.nextLink'], headers);\n }\n }\n\n /**\n * Abstract on top of {@link MicrosoftGraphClient.requestRaw}\n *\n * @public\n * @param path - Resource in Microsoft Graph\n * @param query - OData Query {@link ODataQuery}\n * @param headers - optional HTTP headers\n */\n async requestApi(\n path: string,\n query?: ODataQuery,\n headers?: Record<string, string>,\n ): Promise<Response> {\n const queryString = qs.stringify(\n {\n $search: query?.search,\n $filter: query?.filter,\n $select: query?.select?.join(','),\n $expand: query?.expand,\n $count: query?.count,\n $top: query?.top,\n },\n {\n addQueryPrefix: true,\n // Microsoft Graph doesn't like an encoded query string\n encode: false,\n },\n );\n\n return await this.requestRaw(\n `${this.baseUrl}/${path}${queryString}`,\n headers,\n );\n }\n\n /**\n * Makes a HTTP call to Graph API with token\n *\n * @param url - HTTP Endpoint of Graph API\n * @param headers - optional HTTP headers\n */\n async requestRaw(\n url: string,\n headers?: Record<string, string>,\n retryCount = 2,\n ): Promise<Response> {\n // Make sure that we always have a valid access token (might be cached)\n const urlObj = new URL(url);\n const token = await this.tokenCredential.getToken(\n `${urlObj.protocol}//${urlObj.hostname}/.default`,\n );\n\n if (!token) {\n throw new Error('Failed to obtain token from Azure Identity');\n }\n\n try {\n return await fetch(url, {\n headers: {\n ...headers,\n Authorization: `Bearer ${token.token}`,\n },\n });\n } catch (e: any) {\n if (e?.code === 'ETIMEDOUT' && retryCount > 0) {\n return this.requestRaw(url, headers, retryCount - 1);\n }\n throw e;\n }\n }\n\n /**\n * Get {@link https://docs.microsoft.com/en-us/graph/api/resources/profilephoto | profilePhoto}\n * of `User` from Graph API with size limit\n *\n * @param userId - The unique identifier for the `User` resource\n * @param maxSize - Maximum pixel height of the photo\n *\n */\n async getUserPhotoWithSizeLimit(\n userId: string,\n maxSize: number,\n ): Promise<string | undefined> {\n return await this.getPhotoWithSizeLimit('users', userId, maxSize);\n }\n\n async getUserPhoto(\n userId: string,\n sizeId?: string,\n ): Promise<string | undefined> {\n return await this.getPhoto('users', userId, sizeId);\n }\n\n /**\n * Get a collection of\n * {@link https://docs.microsoft.com/en-us/graph/api/resources/user | User}\n * from Graph API and return as `AsyncIterable`\n *\n * @public\n * @param query - OData Query {@link ODataQuery}\n * @param queryMode - Mode to use while querying. Some features are only available at \"advanced\".\n */\n async *getUsers(\n query?: ODataQuery,\n queryMode?: 'basic' | 'advanced',\n ): AsyncIterable<MicrosoftGraph.User> {\n yield* this.requestCollection<MicrosoftGraph.User>(\n `users`,\n query,\n queryMode,\n );\n }\n\n /**\n * Get {@link https://docs.microsoft.com/en-us/graph/api/resources/profilephoto | profilePhoto}\n * of `Group` from Graph API with size limit\n *\n * @param groupId - The unique identifier for the `Group` resource\n * @param maxSize - Maximum pixel height of the photo\n *\n */\n async getGroupPhotoWithSizeLimit(\n groupId: string,\n maxSize: number,\n ): Promise<string | undefined> {\n return await this.getPhotoWithSizeLimit('groups', groupId, maxSize);\n }\n\n async getGroupPhoto(\n groupId: string,\n sizeId?: string,\n ): Promise<string | undefined> {\n return await this.getPhoto('groups', groupId, sizeId);\n }\n\n /**\n * Get a collection of\n * {@link https://docs.microsoft.com/en-us/graph/api/resources/group | Group}\n * from Graph API and return as `AsyncIterable`\n *\n * @public\n * @param query - OData Query {@link ODataQuery}\n * @param queryMode - Mode to use while querying. Some features are only available at \"advanced\".\n */\n async *getGroups(\n query?: ODataQuery,\n queryMode?: 'basic' | 'advanced',\n ): AsyncIterable<MicrosoftGraph.Group> {\n yield* this.requestCollection<MicrosoftGraph.Group>(\n `groups`,\n query,\n queryMode,\n );\n }\n\n /**\n * Get a collection of\n * {@link https://docs.microsoft.com/en-us/graph/api/resources/user | User}\n * belonging to a `Group` from Graph API and return as `AsyncIterable`\n * @public\n * @param groupId - The unique identifier for the `Group` resource\n *\n */\n async *getGroupMembers(\n groupId: string,\n query?: ODataQuery,\n queryMode?: 'basic' | 'advanced',\n ): AsyncIterable<GroupMember> {\n yield* this.requestCollection<GroupMember>(\n `groups/${groupId}/members`,\n query,\n queryMode,\n );\n }\n\n /**\n * Get a collection of\n * {@link https://docs.microsoft.com/en-us/graph/api/resources/user | User}\n * belonging to a `Group` from Graph API and return as `AsyncIterable`\n * @public\n * @param groupId - The unique identifier for the `Group` resource\n * @param query - OData Query {@link ODataQuery}\n * @param queryMode - Mode to use while querying. Some features are only available at \"advanced\".\n */\n async *getGroupUserMembers(\n groupId: string,\n query?: ODataQuery,\n queryMode?: 'basic' | 'advanced',\n ): AsyncIterable<MicrosoftGraph.User> {\n yield* this.requestCollection<MicrosoftGraph.User>(\n `groups/${groupId}/members/microsoft.graph.user/`,\n query,\n queryMode,\n );\n }\n\n /**\n * Get {@link https://docs.microsoft.com/en-us/graph/api/resources/organization | Organization}\n * from Graph API\n * @public\n * @param tenantId - The unique identifier for the `Organization` resource\n *\n */\n async getOrganization(\n tenantId: string,\n ): Promise<MicrosoftGraph.Organization> {\n const response = await this.requestApi(`organization/${tenantId}`);\n\n if (response.status !== 200) {\n await this.handleError(`organization/${tenantId}`, response);\n }\n\n return await response.json();\n }\n\n /**\n * Get {@link https://docs.microsoft.com/en-us/graph/api/resources/profilephoto | profilePhoto}\n * from Graph API\n *\n * @param entityName - type of parent resource, either `User` or `Group`\n * @param id - The unique identifier for the {@link entityName | entityName} resource\n * @param maxSize - Maximum pixel height of the photo\n *\n */\n private async getPhotoWithSizeLimit(\n entityName: string,\n id: string,\n maxSize: number,\n ): Promise<string | undefined> {\n const response = await this.requestApi(`${entityName}/${id}/photos`);\n\n if (response.status === 404) {\n return undefined;\n } else if (response.status !== 200) {\n await this.handleError(`${entityName} photos`, response);\n }\n\n const result = await response.json();\n const photos = result.value as MicrosoftGraph.ProfilePhoto[];\n let selectedPhoto: MicrosoftGraph.ProfilePhoto | undefined = undefined;\n\n // Find the biggest picture that is smaller than the max size\n for (const p of photos) {\n if (\n !selectedPhoto ||\n (p.height! >= selectedPhoto.height! && p.height! <= maxSize)\n ) {\n selectedPhoto = p;\n }\n }\n\n if (!selectedPhoto) {\n return undefined;\n }\n\n return await this.getPhoto(entityName, id, selectedPhoto.id!);\n }\n\n private async getPhoto(\n entityName: string,\n id: string,\n sizeId?: string,\n ): Promise<string | undefined> {\n const path = sizeId\n ? `${entityName}/${id}/photos/${sizeId}/$value`\n : `${entityName}/${id}/photo/$value`;\n const response = await this.requestApi(path);\n\n if (response.status === 404) {\n return undefined;\n } else if (response.status !== 200) {\n await this.handleError('photo', response);\n }\n\n return `data:image/jpeg;base64,${Buffer.from(\n await response.arrayBuffer(),\n ).toString('base64')}`;\n }\n\n private async handleError(path: string, response: Response): Promise<void> {\n const result = await response.json();\n const error = result.error as MicrosoftGraph.PublicError;\n\n throw new Error(\n `Error while reading ${path} from Microsoft Graph: ${error.code} - ${error.message}`,\n );\n }\n}\n"],"names":["ClientSecretCredential","DefaultAzureCredential","qs","fetch"],"mappings":";;;;;;;;;;;AA6EO,MAAM,oBAAqB,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiChC,WAAA,CACmB,SACA,eACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA,CAAA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M,IAAI,KAAA;AAAA,MACR,uBAAuB,IAAI,CAAA,uBAAA,EAA0B,MAAM,IAAI,CAAA,GAAA,EAAM,MAAM,OAAO,CAAA,CAAA;AAAA,KACpF,CAAA;AAAA,GACF;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"client.cjs.js","sources":["../../src/microsoftGraph/client.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n TokenCredential,\n DefaultAzureCredential,\n ClientSecretCredential,\n} from '@azure/identity';\nimport * as MicrosoftGraph from '@microsoft/microsoft-graph-types';\nimport fetch, { Response } from 'node-fetch';\nimport qs from 'qs';\nimport { MicrosoftGraphProviderConfig } from './config';\n\n/**\n * OData (Open Data Protocol) Query\n *\n * {@link https://docs.microsoft.com/en-us/odata/concepts/queryoptions-overview}\n * {@link https://docs.microsoft.com/en-us/graph/query-parameters}\n * @public\n */\nexport type ODataQuery = {\n /**\n * search resources within a collection matching a free-text search expression.\n */\n search?: string;\n /**\n * filter a collection of resources\n */\n filter?: string;\n /**\n * specifies the related resources or media streams to be included in line with retrieved resources\n */\n expand?: string;\n /**\n * request a specific set of properties for each entity or complex type\n */\n select?: string[];\n /**\n * Retrieves the total count of matching resources.\n */\n count?: boolean;\n /**\n * Maximum number of records to receive in one batch.\n */\n top?: number;\n};\n\n/**\n * Extends the base msgraph types to include the odata type.\n *\n * @public\n */\nexport type GroupMember =\n | (MicrosoftGraph.Group & { '@odata.type': '#microsoft.graph.group' })\n | (MicrosoftGraph.User & { '@odata.type': '#microsoft.graph.user' });\n\n/**\n * A HTTP Client that communicates with Microsoft Graph API.\n * Simplify Authentication and API calls to get `User` and `Group` from Microsoft Graph\n *\n * Uses `msal-node` for authentication\n *\n * @public\n */\nexport class MicrosoftGraphClient {\n /**\n * Factory method that instantiate `msal` client and return\n * an instance of `MicrosoftGraphClient`\n *\n * @public\n *\n * @param config - Configuration for Interacting with Graph API\n */\n static create(config: MicrosoftGraphProviderConfig): MicrosoftGraphClient {\n const options = {\n authorityHost: config.authority,\n tenantId: config.tenantId,\n };\n\n const credential =\n config.clientId && config.clientSecret\n ? new ClientSecretCredential(\n config.tenantId,\n config.clientId,\n config.clientSecret,\n options,\n )\n : new DefaultAzureCredential(options);\n\n return new MicrosoftGraphClient(config.target, credential);\n }\n\n /**\n * @param baseUrl - baseUrl of Graph API {@link MicrosoftGraphProviderConfig.target}\n * @param tokenCredential - instance of `TokenCredential` that is used to acquire token for Graph API calls\n *\n */\n constructor(\n private readonly baseUrl: string,\n private readonly tokenCredential: TokenCredential,\n ) {}\n\n /**\n * Get a collection of resource from Graph API and\n * return an `AsyncIterable` of that resource\n *\n * @public\n * @param path - Resource in Microsoft Graph\n * @param query - OData Query {@link ODataQuery}\n * @param queryMode - Mode to use while querying. Some features are only available at \"advanced\".\n */\n async *requestCollection<T>(\n path: string,\n query?: ODataQuery,\n queryMode?: 'basic' | 'advanced',\n ): AsyncIterable<T> {\n // upgrade to advanced query mode transparently when \"search\" is used\n // to stay backwards compatible.\n const appliedQueryMode = query?.search ? 'advanced' : queryMode ?? 'basic';\n\n // not needed for \"search\"\n // as of https://docs.microsoft.com/en-us/graph/aad-advanced-queries?tabs=http\n // even though a few other places say the opposite\n // - https://docs.microsoft.com/en-us/graph/api/user-list?view=graph-rest-1.0&tabs=http#request-headers\n // - https://docs.microsoft.com/en-us/graph/api/resources/group?view=graph-rest-1.0#properties\n if (appliedQueryMode === 'advanced' && (query?.filter || query?.select)) {\n query.count = true;\n }\n const headers: Record<string, string> =\n appliedQueryMode === 'advanced'\n ? {\n // Eventual consistency is required for advanced querying capabilities\n // like \"$search\" or parts of \"$filter\".\n // If a new user/group is not found, it'll eventually be imported on a subsequent read\n ConsistencyLevel: 'eventual',\n }\n : {};\n\n let response = await this.requestApi(path, query, headers);\n\n for (;;) {\n if (response.status !== 200) {\n await this.handleError(path, response);\n }\n\n const result = await response.json();\n\n // Graph API return array of collections\n const elements: T[] = result.value;\n\n yield* elements;\n\n // Follow cursor to the next page if one is available\n if (!result['@odata.nextLink']) {\n return;\n }\n\n response = await this.requestRaw(result['@odata.nextLink'], headers);\n }\n }\n\n /**\n * Abstract on top of {@link MicrosoftGraphClient.requestRaw}\n *\n * @public\n * @param path - Resource in Microsoft Graph\n * @param query - OData Query {@link ODataQuery}\n * @param headers - optional HTTP headers\n */\n async requestApi(\n path: string,\n query?: ODataQuery,\n headers?: Record<string, string>,\n ): Promise<Response> {\n const queryString = qs.stringify(\n {\n $search: query?.search,\n $filter: query?.filter,\n $select: query?.select?.join(','),\n $expand: query?.expand,\n $count: query?.count,\n $top: query?.top,\n },\n {\n addQueryPrefix: true,\n // Microsoft Graph doesn't like an encoded query string\n encode: false,\n },\n );\n\n return await this.requestRaw(\n `${this.baseUrl}/${path}${queryString}`,\n headers,\n );\n }\n\n /**\n * Makes a HTTP call to Graph API with token\n *\n * @param url - HTTP Endpoint of Graph API\n * @param headers - optional HTTP headers\n */\n async requestRaw(\n url: string,\n headers?: Record<string, string>,\n retryCount = 2,\n ): Promise<Response> {\n // Make sure that we always have a valid access token (might be cached)\n const urlObj = new URL(url);\n const token = await this.tokenCredential.getToken(\n `${urlObj.protocol}//${urlObj.hostname}/.default`,\n );\n\n if (!token) {\n throw new Error('Failed to obtain token from Azure Identity');\n }\n\n try {\n return await fetch(url, {\n headers: {\n ...headers,\n Authorization: `Bearer ${token.token}`,\n },\n });\n } catch (e: any) {\n if (e?.code === 'ETIMEDOUT' && retryCount > 0) {\n return this.requestRaw(url, headers, retryCount - 1);\n }\n throw e;\n }\n }\n\n /**\n * Get {@link https://docs.microsoft.com/en-us/graph/api/resources/profilephoto | profilePhoto}\n * of `User` from Graph API with size limit\n *\n * @param userId - The unique identifier for the `User` resource\n * @param maxSize - Maximum pixel height of the photo\n *\n */\n async getUserPhotoWithSizeLimit(\n userId: string,\n maxSize: number,\n ): Promise<string | undefined> {\n return await this.getPhotoWithSizeLimit('users', userId, maxSize);\n }\n\n async getUserPhoto(\n userId: string,\n sizeId?: string,\n ): Promise<string | undefined> {\n return await this.getPhoto('users', userId, sizeId);\n }\n\n /**\n * Get a collection of\n * {@link https://docs.microsoft.com/en-us/graph/api/resources/user | User}\n * from Graph API and return as `AsyncIterable`\n *\n * @public\n * @param query - OData Query {@link ODataQuery}\n * @param queryMode - Mode to use while querying. Some features are only available at \"advanced\".\n */\n async *getUsers(\n query?: ODataQuery,\n queryMode?: 'basic' | 'advanced',\n ): AsyncIterable<MicrosoftGraph.User> {\n yield* this.requestCollection<MicrosoftGraph.User>(\n `users`,\n query,\n queryMode,\n );\n }\n\n /**\n * Get {@link https://docs.microsoft.com/en-us/graph/api/resources/profilephoto | profilePhoto}\n * of `Group` from Graph API with size limit\n *\n * @param groupId - The unique identifier for the `Group` resource\n * @param maxSize - Maximum pixel height of the photo\n *\n */\n async getGroupPhotoWithSizeLimit(\n groupId: string,\n maxSize: number,\n ): Promise<string | undefined> {\n return await this.getPhotoWithSizeLimit('groups', groupId, maxSize);\n }\n\n async getGroupPhoto(\n groupId: string,\n sizeId?: string,\n ): Promise<string | undefined> {\n return await this.getPhoto('groups', groupId, sizeId);\n }\n\n /**\n * Get a collection of\n * {@link https://docs.microsoft.com/en-us/graph/api/resources/group | Group}\n * from Graph API and return as `AsyncIterable`\n *\n * @public\n * @param query - OData Query {@link ODataQuery}\n * @param queryMode - Mode to use while querying. Some features are only available at \"advanced\".\n */\n async *getGroups(\n query?: ODataQuery,\n queryMode?: 'basic' | 'advanced',\n ): AsyncIterable<MicrosoftGraph.Group> {\n yield* this.requestCollection<MicrosoftGraph.Group>(\n `groups`,\n query,\n queryMode,\n );\n }\n\n /**\n * Get a collection of\n * {@link https://docs.microsoft.com/en-us/graph/api/resources/user | User}\n * belonging to a `Group` from Graph API and return as `AsyncIterable`\n * @public\n * @param groupId - The unique identifier for the `Group` resource\n *\n */\n async *getGroupMembers(\n groupId: string,\n query?: ODataQuery,\n queryMode?: 'basic' | 'advanced',\n ): AsyncIterable<GroupMember> {\n yield* this.requestCollection<GroupMember>(\n `groups/${groupId}/members`,\n query,\n queryMode,\n );\n }\n\n /**\n * Get a collection of\n * {@link https://docs.microsoft.com/en-us/graph/api/resources/user | User}\n * belonging to a `Group` from Graph API and return as `AsyncIterable`\n * @public\n * @param groupId - The unique identifier for the `Group` resource\n * @param query - OData Query {@link ODataQuery}\n * @param queryMode - Mode to use while querying. Some features are only available at \"advanced\".\n */\n async *getGroupUserMembers(\n groupId: string,\n query?: ODataQuery,\n queryMode?: 'basic' | 'advanced',\n ): AsyncIterable<MicrosoftGraph.User> {\n yield* this.requestCollection<MicrosoftGraph.User>(\n `groups/${groupId}/members/microsoft.graph.user/`,\n query,\n queryMode,\n );\n }\n\n /**\n * Get {@link https://docs.microsoft.com/en-us/graph/api/resources/organization | Organization}\n * from Graph API\n * @public\n * @param tenantId - The unique identifier for the `Organization` resource\n *\n */\n async getOrganization(\n tenantId: string,\n ): Promise<MicrosoftGraph.Organization> {\n const response = await this.requestApi(`organization/${tenantId}`);\n\n if (response.status !== 200) {\n await this.handleError(`organization/${tenantId}`, response);\n }\n\n return await response.json();\n }\n\n /**\n * Get {@link https://docs.microsoft.com/en-us/graph/api/resources/profilephoto | profilePhoto}\n * from Graph API\n *\n * @param entityName - type of parent resource, either `User` or `Group`\n * @param id - The unique identifier for the `entityName` resource\n * @param maxSize - Maximum pixel height of the photo\n *\n */\n private async getPhotoWithSizeLimit(\n entityName: string,\n id: string,\n maxSize: number,\n ): Promise<string | undefined> {\n const response = await this.requestApi(`${entityName}/${id}/photos`);\n\n if (response.status === 404) {\n return undefined;\n } else if (response.status !== 200) {\n await this.handleError(`${entityName} photos`, response);\n }\n\n const result = await response.json();\n const photos = result.value as MicrosoftGraph.ProfilePhoto[];\n let selectedPhoto: MicrosoftGraph.ProfilePhoto | undefined = undefined;\n\n // Find the biggest picture that is smaller than the max size\n for (const p of photos) {\n if (\n !selectedPhoto ||\n (p.height! >= selectedPhoto.height! && p.height! <= maxSize)\n ) {\n selectedPhoto = p;\n }\n }\n\n if (!selectedPhoto) {\n return undefined;\n }\n\n return await this.getPhoto(entityName, id, selectedPhoto.id!);\n }\n\n private async getPhoto(\n entityName: string,\n id: string,\n sizeId?: string,\n ): Promise<string | undefined> {\n const path = sizeId\n ? `${entityName}/${id}/photos/${sizeId}/$value`\n : `${entityName}/${id}/photo/$value`;\n const response = await this.requestApi(path);\n\n if (response.status === 404) {\n return undefined;\n } else if (response.status !== 200) {\n await this.handleError('photo', response);\n }\n\n return `data:image/jpeg;base64,${Buffer.from(\n await response.arrayBuffer(),\n ).toString('base64')}`;\n }\n\n private async handleError(path: string, response: Response): Promise<void> {\n const result = await response.json();\n const error = result.error as MicrosoftGraph.PublicError;\n\n throw new Error(\n `Error while reading ${path} from Microsoft Graph: ${error.code} - ${error.message}`,\n );\n }\n}\n"],"names":["ClientSecretCredential","DefaultAzureCredential","qs","fetch"],"mappings":";;;;;;;;;;;AA6EO,MAAM,oBAAqB,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiChC,WAAA,CACmB,SACA,eACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA,CAAA;AACA,IAAA,IAAA,CAAA,eAAA,GAAA,eAAA,CAAA;AAAA,GAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA3BH,OAAO,OAAO,MAA4D,EAAA;AACxE,IAAA,MAAM,OAAU,GAAA;AAAA,MACd,eAAe,MAAO,CAAA,SAAA;AAAA,MACtB,UAAU,MAAO,CAAA,QAAA;AAAA,KACnB,CAAA;AAEA,IAAA,MAAM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"],"sourcesContent":["/*\n * Copyright 2022 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 coreServices,\n createBackendModule,\n createExtensionPoint,\n} from '@backstage/backend-plugin-api';\nimport { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha';\nimport {\n GroupTransformer,\n OrganizationTransformer,\n ProviderConfigTransformer,\n UserTransformer,\n} from '@backstage/plugin-catalog-backend-module-msgraph';\nimport { MicrosoftGraphOrgEntityProvider } from '../processors';\n\n/**\n * Interface for {@link microsoftGraphOrgEntityProviderTransformExtensionPoint}.\n *\n * @
|
|
1
|
+
{"version":3,"file":"catalogModuleMicrosoftGraphOrgEntityProvider.cjs.js","sources":["../../src/module/catalogModuleMicrosoftGraphOrgEntityProvider.ts"],"sourcesContent":["/*\n * Copyright 2022 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 coreServices,\n createBackendModule,\n createExtensionPoint,\n} from '@backstage/backend-plugin-api';\nimport { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha';\nimport {\n GroupTransformer,\n OrganizationTransformer,\n ProviderConfigTransformer,\n UserTransformer,\n} from '@backstage/plugin-catalog-backend-module-msgraph';\nimport { MicrosoftGraphOrgEntityProvider } from '../processors';\n\n/**\n * Interface for {@link microsoftGraphOrgEntityProviderTransformExtensionPoint}.\n *\n * @public\n */\nexport interface MicrosoftGraphOrgEntityProviderTransformsExtensionPoint {\n /**\n * Set the function that transforms a user entry in msgraph to an entity.\n * Optionally, you can pass separate transformers per provider ID.\n */\n setUserTransformer(\n transformer: UserTransformer | Record<string, UserTransformer>,\n ): void;\n\n /**\n * Set the function that transforms a group entry in msgraph to an entity.\n * Optionally, you can pass separate transformers per provider ID.\n */\n setGroupTransformer(\n transformer: GroupTransformer | Record<string, GroupTransformer>,\n ): void;\n\n /**\n * Set the function that transforms an organization entry in msgraph to an entity.\n * Optionally, you can pass separate transformers per provider ID.\n */\n setOrganizationTransformer(\n transformer:\n | OrganizationTransformer\n | Record<string, OrganizationTransformer>,\n ): void;\n\n /**\n * Set the function that transforms provider config dynamically.\n * Optionally, you can pass separate transformers per provider ID.\n * Note: adjusting fields that are not used on each scheduled ingestion\n * (e.g., id, schedule) will have no effect.\n */\n setProviderConfigTransformer(\n transformer:\n | ProviderConfigTransformer\n | Record<string, ProviderConfigTransformer>,\n ): void;\n}\n\n/**\n * Extension point used to customize the transforms used by the module.\n *\n * @public\n */\nexport const microsoftGraphOrgEntityProviderTransformExtensionPoint =\n createExtensionPoint<MicrosoftGraphOrgEntityProviderTransformsExtensionPoint>(\n {\n id: 'catalog.microsoftGraphOrgEntityProvider.transforms',\n },\n );\n\n/**\n * Registers the MicrosoftGraphOrgEntityProvider with the catalog processing extension point.\n *\n * @public\n */\nexport const catalogModuleMicrosoftGraphOrgEntityProvider = createBackendModule(\n {\n pluginId: 'catalog',\n moduleId: 'microsoftGraphOrgEntityProvider',\n register(env) {\n let userTransformer:\n | UserTransformer\n | Record<string, UserTransformer>\n | undefined;\n let groupTransformer:\n | GroupTransformer\n | Record<string, GroupTransformer>\n | undefined;\n let organizationTransformer:\n | OrganizationTransformer\n | Record<string, OrganizationTransformer>\n | undefined;\n let providerConfigTransformer:\n | ProviderConfigTransformer\n | Record<string, ProviderConfigTransformer>\n | undefined;\n\n env.registerExtensionPoint(\n microsoftGraphOrgEntityProviderTransformExtensionPoint,\n {\n setUserTransformer(transformer) {\n if (userTransformer) {\n throw new Error('User transformer may only be set once');\n }\n userTransformer = transformer;\n },\n setGroupTransformer(transformer) {\n if (groupTransformer) {\n throw new Error('Group transformer may only be set once');\n }\n groupTransformer = transformer;\n },\n setOrganizationTransformer(transformer) {\n if (organizationTransformer) {\n throw new Error('Organization transformer may only be set once');\n }\n organizationTransformer = transformer;\n },\n setProviderConfigTransformer(transformer) {\n if (providerConfigTransformer) {\n throw new Error('Provider transformer may only be set once');\n }\n providerConfigTransformer = transformer;\n },\n },\n );\n\n env.registerInit({\n deps: {\n catalog: catalogProcessingExtensionPoint,\n config: coreServices.rootConfig,\n logger: coreServices.logger,\n scheduler: coreServices.scheduler,\n },\n async init({ catalog, config, logger, scheduler }) {\n catalog.addEntityProvider(\n MicrosoftGraphOrgEntityProvider.fromConfig(config, {\n logger,\n scheduler,\n userTransformer: userTransformer,\n groupTransformer: groupTransformer,\n organizationTransformer: organizationTransformer,\n providerConfigTransformer: providerConfigTransformer,\n }),\n );\n },\n });\n },\n },\n);\n"],"names":["createExtensionPoint","createBackendModule","catalogProcessingExtensionPoint","coreServices","MicrosoftGraphOrgEntityProvider"],"mappings":";;;;;;;;;;;;;AAgFO,MAAM,sDACX,GAAAA,qCAAA;AAAA,EACE;AAAA,IACE,EAAI,EAAA,oDAAA;AAAA,GACN;AACF,EAAA;AAOK,MAAM,4CAA+C,GAAAC,oCAAA;AAAA,EAC1D;AAAA,IACE,QAAU,EAAA,SAAA;AAAA,IACV,QAAU,EAAA,iCAAA;AAAA,IACV,SAAS,GAAK,EAAA;AACZ,MAAI,IAAA,eAAA,CAAA;AAIJ,MAAI,IAAA,gBAAA,CAAA;AAIJ,MAAI,IAAA,uBAAA,CAAA;AAIJ,MAAI,IAAA,yBAAA,CAAA;AAKJ,MAAI,GAAA,CAAA,sBAAA;A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AA,cACA,yBAAA;AAAA,aACD,CAAA;AAAA,WACH,CAAA;AAAA,SACF;AAAA,OACD,CAAA,CAAA;AAAA,KACH;AAAA,GACF;AACF;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-catalog-backend-module-msgraph",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4-next.0",
|
|
4
4
|
"description": "A Backstage catalog backend module that helps integrate towards Microsoft Graph",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "backend-plugin-module",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"license": "Apache-2.0",
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
25
|
+
"backstage": "@backstage/BackendFeature",
|
|
25
26
|
"require": "./dist/index.cjs.js",
|
|
26
27
|
"types": "./dist/index.d.ts",
|
|
27
28
|
"default": "./dist/index.cjs.js"
|
|
@@ -52,11 +53,11 @@
|
|
|
52
53
|
},
|
|
53
54
|
"dependencies": {
|
|
54
55
|
"@azure/identity": "^4.0.0",
|
|
55
|
-
"@backstage/backend-plugin-api": "1.0.
|
|
56
|
+
"@backstage/backend-plugin-api": "1.0.2-next.0",
|
|
56
57
|
"@backstage/catalog-model": "1.7.0",
|
|
57
58
|
"@backstage/config": "1.2.0",
|
|
58
59
|
"@backstage/plugin-catalog-common": "1.1.0",
|
|
59
|
-
"@backstage/plugin-catalog-node": "1.
|
|
60
|
+
"@backstage/plugin-catalog-node": "1.14.0-next.0",
|
|
60
61
|
"@microsoft/microsoft-graph-types": "^2.6.0",
|
|
61
62
|
"@types/node-fetch": "^2.5.12",
|
|
62
63
|
"lodash": "^4.17.21",
|
|
@@ -66,8 +67,8 @@
|
|
|
66
67
|
"uuid": "^9.0.0"
|
|
67
68
|
},
|
|
68
69
|
"devDependencies": {
|
|
69
|
-
"@backstage/backend-test-utils": "1.0.
|
|
70
|
-
"@backstage/cli": "0.
|
|
70
|
+
"@backstage/backend-test-utils": "1.0.3-next.0",
|
|
71
|
+
"@backstage/cli": "0.29.0-next.0",
|
|
71
72
|
"@types/lodash": "^4.14.151",
|
|
72
73
|
"luxon": "^3.0.0",
|
|
73
74
|
"msw": "^1.0.0"
|