@backstage/plugin-catalog-backend-module-bitbucket-server 0.0.0-nightly-20220810023539
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 +118 -0
- package/README.md +9 -0
- package/config.d.ts +80 -0
- package/dist/index.cjs.js +269 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +127 -0
- package/package.json +56 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# @backstage/plugin-catalog-backend-module-bitbucket-server
|
|
2
|
+
|
|
3
|
+
## 0.0.0-nightly-20220810023539
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f7607f9d85: Add new plugin catalog-backend-module-bitbucket-server which adds the `BitbucketServerEntityProvider`.
|
|
8
|
+
|
|
9
|
+
The entity provider is meant as a replacement for the `BitbucketDiscoveryProcessor` to be used with Bitbucket Server (Bitbucket Cloud already has a replacement).
|
|
10
|
+
|
|
11
|
+
**Before:**
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
// packages/backend/src/plugins/catalog.ts
|
|
15
|
+
builder.addProcessor(
|
|
16
|
+
BitbucketDiscoveryProcessor.fromConfig(env.config, { logger: env.logger }),
|
|
17
|
+
);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```yaml
|
|
21
|
+
# app-config.yaml
|
|
22
|
+
catalog:
|
|
23
|
+
locations:
|
|
24
|
+
- type: bitbucket-discovery
|
|
25
|
+
target: 'https://bitbucket.mycompany.com/projects/*/repos/*/catalog-info.yaml
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**After:**
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
// packages/backend/src/plugins/catalog.ts
|
|
32
|
+
builder.addEntityProvider(
|
|
33
|
+
BitbucketServerEntityProvider.fromConfig(env.config, {
|
|
34
|
+
logger: env.logger,
|
|
35
|
+
schedule: env.scheduler.createScheduledTaskRunner({
|
|
36
|
+
frequency: { minutes: 30 },
|
|
37
|
+
timeout: { minutes: 3 },
|
|
38
|
+
}),
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```yaml
|
|
44
|
+
# app-config.yaml
|
|
45
|
+
catalog:
|
|
46
|
+
providers:
|
|
47
|
+
bitbucketServer:
|
|
48
|
+
yourProviderId: # identifies your ingested dataset
|
|
49
|
+
catalogPath: /catalog-info.yaml # default value
|
|
50
|
+
filters: # optional
|
|
51
|
+
projectKey: '.*' # optional; RegExp
|
|
52
|
+
repoSlug: '.*' # optional; RegExp
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- Updated dependencies
|
|
58
|
+
- @backstage/backend-common@0.0.0-nightly-20220810023539
|
|
59
|
+
- @backstage/integration@0.0.0-nightly-20220810023539
|
|
60
|
+
- @backstage/backend-tasks@0.0.0-nightly-20220810023539
|
|
61
|
+
- @backstage/plugin-catalog-backend@0.0.0-nightly-20220810023539
|
|
62
|
+
|
|
63
|
+
## 0.1.0-next.0
|
|
64
|
+
|
|
65
|
+
### Minor Changes
|
|
66
|
+
|
|
67
|
+
- f7607f9d85: Add new plugin catalog-backend-module-bitbucket-server which adds the `BitbucketServerEntityProvider`.
|
|
68
|
+
|
|
69
|
+
The entity provider is meant as a replacement for the `BitbucketDiscoveryProcessor` to be used with Bitbucket Server (Bitbucket Cloud already has a replacement).
|
|
70
|
+
|
|
71
|
+
**Before:**
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
// packages/backend/src/plugins/catalog.ts
|
|
75
|
+
builder.addProcessor(
|
|
76
|
+
BitbucketDiscoveryProcessor.fromConfig(env.config, { logger: env.logger }),
|
|
77
|
+
);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```yaml
|
|
81
|
+
# app-config.yaml
|
|
82
|
+
catalog:
|
|
83
|
+
locations:
|
|
84
|
+
- type: bitbucket-discovery
|
|
85
|
+
target: 'https://bitbucket.mycompany.com/projects/*/repos/*/catalog-info.yaml
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**After:**
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
// packages/backend/src/plugins/catalog.ts
|
|
92
|
+
builder.addEntityProvider(
|
|
93
|
+
BitbucketServerEntityProvider.fromConfig(env.config, {
|
|
94
|
+
logger: env.logger,
|
|
95
|
+
schedule: env.scheduler.createScheduledTaskRunner({
|
|
96
|
+
frequency: { minutes: 30 },
|
|
97
|
+
timeout: { minutes: 3 },
|
|
98
|
+
}),
|
|
99
|
+
}),
|
|
100
|
+
);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
```yaml
|
|
104
|
+
# app-config.yaml
|
|
105
|
+
catalog:
|
|
106
|
+
providers:
|
|
107
|
+
bitbucketServer:
|
|
108
|
+
yourProviderId: # identifies your ingested dataset
|
|
109
|
+
catalogPath: /catalog-info.yaml # default value
|
|
110
|
+
filters: # optional
|
|
111
|
+
projectKey: '.*' # optional; RegExp
|
|
112
|
+
repoSlug: '.*' # optional; RegExp
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Patch Changes
|
|
116
|
+
|
|
117
|
+
- Updated dependencies
|
|
118
|
+
- @backstage/plugin-catalog-backend@1.3.1-next.2
|
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Catalog Backend Module for Bitbucket Server
|
|
2
|
+
|
|
3
|
+
This is an extension module to the catalog-backend plugin,
|
|
4
|
+
providing extensions targeted at Bitbucket Server offerings.
|
|
5
|
+
|
|
6
|
+
## Getting started
|
|
7
|
+
|
|
8
|
+
See [Backstage documentation](https://backstage.io/docs/integrations/bitbucketServer/discovery)
|
|
9
|
+
for details on how to install and configure the plugin.
|
package/config.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 The Backstage Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export interface Config {
|
|
18
|
+
catalog?: {
|
|
19
|
+
/**
|
|
20
|
+
* List of provider-specific options and attributes
|
|
21
|
+
*/
|
|
22
|
+
providers?: {
|
|
23
|
+
/**
|
|
24
|
+
* BitbucketServerEntityProvider configuration
|
|
25
|
+
*
|
|
26
|
+
* Uses "default" as default id for the single config variant.
|
|
27
|
+
*/
|
|
28
|
+
bitbucketServer?:
|
|
29
|
+
| {
|
|
30
|
+
/**
|
|
31
|
+
* (Optional) Path to the catalog file. Default to "/catalog-info.yaml".
|
|
32
|
+
* @visibility frontend
|
|
33
|
+
*/
|
|
34
|
+
catalogPath?: string;
|
|
35
|
+
/**
|
|
36
|
+
* (Optional) Filters applied to discovered catalog files in repositories.
|
|
37
|
+
* @visibility frontend
|
|
38
|
+
*/
|
|
39
|
+
filters?: {
|
|
40
|
+
/**
|
|
41
|
+
* (Optional) Filter for the repository slug.
|
|
42
|
+
* @visibility frontend
|
|
43
|
+
*/
|
|
44
|
+
repoSlug?: RegExp;
|
|
45
|
+
/**
|
|
46
|
+
* (Optional) Filter for the project key.
|
|
47
|
+
* @visibility frontend
|
|
48
|
+
*/
|
|
49
|
+
projectKey?: RegExp;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
| Record<
|
|
53
|
+
string,
|
|
54
|
+
{
|
|
55
|
+
/**
|
|
56
|
+
* (Optional) Path to the catalog file. Default to "/catalog-info.yaml".
|
|
57
|
+
* @visibility frontend
|
|
58
|
+
*/
|
|
59
|
+
catalogPath?: string;
|
|
60
|
+
/**
|
|
61
|
+
* (Optional) Filters applied to discovered catalog files in repositories.
|
|
62
|
+
* @visibility frontend
|
|
63
|
+
*/
|
|
64
|
+
filters?: {
|
|
65
|
+
/**
|
|
66
|
+
* (Optional) Filter for the repository slug.
|
|
67
|
+
* @visibility frontend
|
|
68
|
+
*/
|
|
69
|
+
repoSlug?: RegExp;
|
|
70
|
+
/**
|
|
71
|
+
* (Optional) Filter for the project key.
|
|
72
|
+
* @visibility frontend
|
|
73
|
+
*/
|
|
74
|
+
projectKey?: RegExp;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
>;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var crossFetch = require('cross-fetch');
|
|
6
|
+
var integration = require('@backstage/integration');
|
|
7
|
+
var uuid = require('uuid');
|
|
8
|
+
var pluginCatalogBackend = require('@backstage/plugin-catalog-backend');
|
|
9
|
+
var errors = require('@backstage/errors');
|
|
10
|
+
|
|
11
|
+
function _interopNamespace(e) {
|
|
12
|
+
if (e && e.__esModule) return e;
|
|
13
|
+
var n = Object.create(null);
|
|
14
|
+
if (e) {
|
|
15
|
+
Object.keys(e).forEach(function (k) {
|
|
16
|
+
if (k !== 'default') {
|
|
17
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return e[k]; }
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
n["default"] = e;
|
|
26
|
+
return Object.freeze(n);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var uuid__namespace = /*#__PURE__*/_interopNamespace(uuid);
|
|
30
|
+
|
|
31
|
+
class BitbucketServerClient {
|
|
32
|
+
static fromConfig(options) {
|
|
33
|
+
return new BitbucketServerClient(options);
|
|
34
|
+
}
|
|
35
|
+
constructor(options) {
|
|
36
|
+
this.config = options.config;
|
|
37
|
+
}
|
|
38
|
+
async listProjects(options) {
|
|
39
|
+
return this.pagedRequest(
|
|
40
|
+
`${this.config.apiBaseUrl}/projects`,
|
|
41
|
+
options.listOptions
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
async listRepositories(options) {
|
|
45
|
+
return this.pagedRequest(
|
|
46
|
+
`${this.config.apiBaseUrl}/projects/${encodeURIComponent(
|
|
47
|
+
options.projectKey
|
|
48
|
+
)}/repos`,
|
|
49
|
+
options.listOptions
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
async getFile(options) {
|
|
53
|
+
const base = new URL(this.config.apiBaseUrl);
|
|
54
|
+
return crossFetch.fetch(
|
|
55
|
+
`${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}/raw/${options.path}`,
|
|
56
|
+
integration.getBitbucketServerRequestOptions(this.config)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
async getRepository(options) {
|
|
60
|
+
const request = `${this.config.apiBaseUrl}/projects/${options.projectKey}/repos/${options.repo}`;
|
|
61
|
+
const response = await crossFetch.fetch(
|
|
62
|
+
request,
|
|
63
|
+
integration.getBitbucketServerRequestOptions(this.config)
|
|
64
|
+
);
|
|
65
|
+
return response.json();
|
|
66
|
+
}
|
|
67
|
+
resolvePath(options) {
|
|
68
|
+
const base = new URL(this.config.apiBaseUrl || "");
|
|
69
|
+
return {
|
|
70
|
+
path: `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}${options.path}`
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async pagedRequest(endpoint, options) {
|
|
74
|
+
const request = new URL(endpoint);
|
|
75
|
+
for (const key in options) {
|
|
76
|
+
if (options[key]) {
|
|
77
|
+
request.searchParams.append(key, options[key].toString());
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return this.getTypeMapped(request);
|
|
81
|
+
}
|
|
82
|
+
async getTypeMapped(url) {
|
|
83
|
+
return this.get(url).then((response) => {
|
|
84
|
+
return response.json();
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
async get(url) {
|
|
88
|
+
return this.request(new crossFetch.Request(url.toString(), { method: "GET" }));
|
|
89
|
+
}
|
|
90
|
+
async request(req) {
|
|
91
|
+
return crossFetch.fetch(req, integration.getBitbucketServerRequestOptions(this.config)).then(
|
|
92
|
+
(response) => {
|
|
93
|
+
if (!response.ok) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
`Unexpected response for ${req.method} ${req.url}. Expected 200 but got ${response.status} - ${response.statusText}`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
return response;
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async function* paginated(request, options) {
|
|
104
|
+
const opts = options || { start: 0 };
|
|
105
|
+
let res;
|
|
106
|
+
do {
|
|
107
|
+
res = await request(opts);
|
|
108
|
+
opts.start = res.nextPageStart;
|
|
109
|
+
for (const item of res.values) {
|
|
110
|
+
yield item;
|
|
111
|
+
}
|
|
112
|
+
} while (!res.isLastPage);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const defaultBitbucketServerLocationParser = async function* defaultBitbucketServerLocationParser2(options) {
|
|
116
|
+
yield pluginCatalogBackend.locationSpecToLocationEntity({ location: options.location });
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const DEFAULT_CATALOG_PATH = "/catalog-info.yaml";
|
|
120
|
+
const DEFAULT_PROVIDER_ID = "default";
|
|
121
|
+
function readProviderConfigs(config) {
|
|
122
|
+
const providersConfig = config.getOptionalConfig(
|
|
123
|
+
"catalog.providers.bitbucketServer"
|
|
124
|
+
);
|
|
125
|
+
if (!providersConfig) {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
if (providersConfig.has("host")) {
|
|
129
|
+
return [readProviderConfig(DEFAULT_PROVIDER_ID, providersConfig)];
|
|
130
|
+
}
|
|
131
|
+
return providersConfig.keys().map((id) => {
|
|
132
|
+
const providerConfig = providersConfig.getConfig(id);
|
|
133
|
+
return readProviderConfig(id, providerConfig);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function readProviderConfig(id, config) {
|
|
137
|
+
var _a;
|
|
138
|
+
const host = config.getString("host");
|
|
139
|
+
const catalogPath = (_a = config.getOptionalString("catalogPath")) != null ? _a : DEFAULT_CATALOG_PATH;
|
|
140
|
+
const projectKeyPattern = config.getOptionalString("filters.projectKey");
|
|
141
|
+
const repoSlugPattern = config.getOptionalString("filters.repoSlug");
|
|
142
|
+
return {
|
|
143
|
+
id,
|
|
144
|
+
host,
|
|
145
|
+
catalogPath,
|
|
146
|
+
filters: {
|
|
147
|
+
projectKey: projectKeyPattern ? new RegExp(projectKeyPattern) : void 0,
|
|
148
|
+
repoSlug: repoSlugPattern ? new RegExp(repoSlugPattern) : void 0
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
class BitbucketServerEntityProvider {
|
|
154
|
+
static fromConfig(config, options) {
|
|
155
|
+
const integrations = integration.ScmIntegrations.fromConfig(config);
|
|
156
|
+
return readProviderConfigs(config).map((providerConfig) => {
|
|
157
|
+
const integration = integrations.bitbucketServer.byHost(
|
|
158
|
+
providerConfig.host
|
|
159
|
+
);
|
|
160
|
+
if (!integration) {
|
|
161
|
+
throw new errors.InputError(
|
|
162
|
+
`No BitbucketServer integration found that matches host ${providerConfig.host}`
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
return new BitbucketServerEntityProvider(
|
|
166
|
+
providerConfig,
|
|
167
|
+
integration,
|
|
168
|
+
options.logger,
|
|
169
|
+
options.schedule,
|
|
170
|
+
options.parser
|
|
171
|
+
);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
constructor(config, integration, logger, schedule, parser) {
|
|
175
|
+
this.integration = integration;
|
|
176
|
+
this.config = config;
|
|
177
|
+
this.parser = parser || defaultBitbucketServerLocationParser;
|
|
178
|
+
this.logger = logger.child({
|
|
179
|
+
target: this.getProviderName()
|
|
180
|
+
});
|
|
181
|
+
this.scheduleFn = this.createScheduleFn(schedule);
|
|
182
|
+
}
|
|
183
|
+
createScheduleFn(schedule) {
|
|
184
|
+
return async () => {
|
|
185
|
+
const taskId = `${this.getProviderName()}:refresh`;
|
|
186
|
+
return schedule.run({
|
|
187
|
+
id: taskId,
|
|
188
|
+
fn: async () => {
|
|
189
|
+
const logger = this.logger.child({
|
|
190
|
+
class: BitbucketServerEntityProvider.prototype.constructor.name,
|
|
191
|
+
taskId,
|
|
192
|
+
taskInstanceId: uuid__namespace.v4()
|
|
193
|
+
});
|
|
194
|
+
try {
|
|
195
|
+
await this.refresh(logger);
|
|
196
|
+
} catch (error) {
|
|
197
|
+
logger.error(error);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
getProviderName() {
|
|
204
|
+
return `bitbucketServer-provider:${this.config.id}`;
|
|
205
|
+
}
|
|
206
|
+
async connect(connection) {
|
|
207
|
+
this.connection = connection;
|
|
208
|
+
await this.scheduleFn();
|
|
209
|
+
}
|
|
210
|
+
async refresh(logger) {
|
|
211
|
+
if (!this.connection) {
|
|
212
|
+
throw new Error("Not initialized");
|
|
213
|
+
}
|
|
214
|
+
logger.info("Discovering catalog files in Bitbucket Server repositories");
|
|
215
|
+
const entities = await this.findEntities();
|
|
216
|
+
await this.connection.applyMutation({
|
|
217
|
+
type: "full",
|
|
218
|
+
entities: entities.map((entity) => ({
|
|
219
|
+
locationKey: this.getProviderName(),
|
|
220
|
+
entity
|
|
221
|
+
}))
|
|
222
|
+
});
|
|
223
|
+
logger.info(
|
|
224
|
+
`Committed ${entities.length} entities for Bitbucket Server repositories`
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
async findEntities() {
|
|
228
|
+
var _a, _b, _c, _d;
|
|
229
|
+
const client = BitbucketServerClient.fromConfig({
|
|
230
|
+
config: this.integration.config
|
|
231
|
+
});
|
|
232
|
+
const projects = paginated(
|
|
233
|
+
(options) => client.listProjects({ listOptions: options })
|
|
234
|
+
);
|
|
235
|
+
const result = [];
|
|
236
|
+
for await (const project of projects) {
|
|
237
|
+
if (((_b = (_a = this.config) == null ? void 0 : _a.filters) == null ? void 0 : _b.projectKey) && !this.config.filters.projectKey.test(project.key)) {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const repositories = paginated(
|
|
241
|
+
(options) => client.listRepositories({
|
|
242
|
+
projectKey: project.key,
|
|
243
|
+
listOptions: options
|
|
244
|
+
})
|
|
245
|
+
);
|
|
246
|
+
for await (const repository of repositories) {
|
|
247
|
+
if (((_d = (_c = this.config) == null ? void 0 : _c.filters) == null ? void 0 : _d.repoSlug) && !this.config.filters.repoSlug.test(repository.slug)) {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
for await (const entity of this.parser({
|
|
251
|
+
client,
|
|
252
|
+
logger: this.logger,
|
|
253
|
+
location: {
|
|
254
|
+
type: "url",
|
|
255
|
+
target: `${repository.links.self[0].href}${this.config.catalogPath}`,
|
|
256
|
+
presence: "optional"
|
|
257
|
+
}
|
|
258
|
+
})) {
|
|
259
|
+
result.push(entity);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return result;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
exports.BitbucketServerClient = BitbucketServerClient;
|
|
268
|
+
exports.BitbucketServerEntityProvider = BitbucketServerEntityProvider;
|
|
269
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/lib/BitbucketServerClient.ts","../src/providers/BitbucketServerLocationParser.ts","../src/providers/BitbucketServerEntityProviderConfig.ts","../src/providers/BitbucketServerEntityProvider.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 { fetch, Request } from 'cross-fetch';\nimport {\n BitbucketServerIntegrationConfig,\n getBitbucketServerRequestOptions,\n} from '@backstage/integration';\nimport { BitbucketServerProject, BitbucketServerRepository } from './types';\n\n/**\n * A client for interacting with a Bitbucket Server instance\n *\n * @public\n */\nexport class BitbucketServerClient {\n private readonly config: BitbucketServerIntegrationConfig;\n\n static fromConfig(options: {\n config: BitbucketServerIntegrationConfig;\n }): BitbucketServerClient {\n return new BitbucketServerClient(options);\n }\n\n constructor(options: { config: BitbucketServerIntegrationConfig }) {\n this.config = options.config;\n }\n\n async listProjects(options: {\n listOptions?: BitbucketServerListOptions;\n }): Promise<BitbucketServerPagedResponse<BitbucketServerProject>> {\n return this.pagedRequest(\n `${this.config.apiBaseUrl}/projects`,\n options.listOptions,\n );\n }\n\n async listRepositories(options: {\n projectKey: string;\n listOptions?: BitbucketServerListOptions;\n }): Promise<BitbucketServerPagedResponse<BitbucketServerRepository>> {\n return this.pagedRequest(\n `${this.config.apiBaseUrl}/projects/${encodeURIComponent(\n options.projectKey,\n )}/repos`,\n options.listOptions,\n );\n }\n\n async getFile(options: {\n projectKey: string;\n repo: string;\n path: string;\n }): Promise<Response> {\n const base = new URL(this.config.apiBaseUrl);\n return fetch(\n `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}/raw/${options.path}`,\n getBitbucketServerRequestOptions(this.config),\n );\n }\n\n async getRepository(options: {\n projectKey: string;\n repo: string;\n }): Promise<BitbucketServerRepository> {\n const request = `${this.config.apiBaseUrl}/projects/${options.projectKey}/repos/${options.repo}`;\n const response = await fetch(\n request,\n getBitbucketServerRequestOptions(this.config),\n );\n return response.json();\n }\n\n resolvePath(options: { projectKey: string; repo: string; path: string }): {\n path: string;\n } {\n const base = new URL(this.config.apiBaseUrl || '');\n\n return {\n path: `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}${options.path}`,\n };\n }\n\n private async pagedRequest(\n endpoint: string,\n options?: BitbucketServerListOptions,\n ): Promise<BitbucketServerPagedResponse<any>> {\n const request = new URL(endpoint);\n for (const key in options) {\n if (options[key]) {\n request.searchParams.append(key, options[key]!.toString());\n }\n }\n return this.getTypeMapped(request);\n }\n\n private async getTypeMapped<T = any>(url: URL): Promise<T> {\n return this.get(url).then((response: Response) => {\n return response.json() as Promise<T>;\n });\n }\n\n private async get(url: URL): Promise<Response> {\n return this.request(new Request(url.toString(), { method: 'GET' }));\n }\n\n private async request(req: Request): Promise<Response> {\n return fetch(req, getBitbucketServerRequestOptions(this.config)).then(\n (response: Response) => {\n if (!response.ok) {\n throw new Error(\n `Unexpected response for ${req.method} ${req.url}. Expected 200 but got ${response.status} - ${response.statusText}`,\n );\n }\n return response;\n },\n );\n }\n}\n\n/**\n * @public\n */\nexport type BitbucketServerListOptions = {\n [key: string]: number | undefined;\n limit?: number | undefined;\n start?: number | undefined;\n};\n\n/**\n * @public\n */\nexport type BitbucketServerPagedResponse<T> = {\n size: number;\n limit: number;\n start: number;\n isLastPage: boolean;\n values: T[];\n nextPageStart: number;\n};\n\nexport async function* paginated(\n request: (\n options: BitbucketServerListOptions,\n ) => Promise<BitbucketServerPagedResponse<any>>,\n options?: BitbucketServerListOptions,\n) {\n const opts = options || { start: 0 };\n let res;\n do {\n res = await request(opts);\n opts.start = res.nextPageStart;\n for (const item of res.values) {\n yield item;\n }\n } while (!res.isLastPage);\n}\n","/*\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 LocationSpec,\n locationSpecToLocationEntity,\n} from '@backstage/plugin-catalog-backend';\nimport { Entity } from '@backstage/catalog-model';\nimport { Logger } from 'winston';\nimport { BitbucketServerClient } from '../lib';\n\n/**\n * A custom callback that reacts to finding a location by yielding entities.\n * Can be used for custom location/repository parsing logic.\n *\n * @public\n */\nexport type BitbucketServerLocationParser = (options: {\n client: BitbucketServerClient;\n location: LocationSpec;\n logger: Logger;\n}) => AsyncIterable<Entity>;\n\nexport const defaultBitbucketServerLocationParser =\n async function* defaultBitbucketServerLocationParser(options: {\n location: LocationSpec;\n }) {\n yield locationSpecToLocationEntity({ location: options.location });\n };\n","/*\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 { Config } from '@backstage/config';\n\nconst DEFAULT_CATALOG_PATH = '/catalog-info.yaml';\nconst DEFAULT_PROVIDER_ID = 'default';\n\nexport type BitbucketServerEntityProviderConfig = {\n id: string;\n host: string;\n catalogPath: string;\n filters?: {\n projectKey?: RegExp;\n repoSlug?: RegExp;\n };\n};\n\nexport function readProviderConfigs(\n config: Config,\n): BitbucketServerEntityProviderConfig[] {\n const providersConfig = config.getOptionalConfig(\n 'catalog.providers.bitbucketServer',\n );\n if (!providersConfig) {\n return [];\n }\n if (providersConfig.has('host')) {\n // simple/single config variant\n return [readProviderConfig(DEFAULT_PROVIDER_ID, providersConfig)];\n }\n\n return providersConfig.keys().map(id => {\n const providerConfig = providersConfig.getConfig(id);\n\n return readProviderConfig(id, providerConfig);\n });\n}\n\nfunction readProviderConfig(\n id: string,\n config: Config,\n): BitbucketServerEntityProviderConfig {\n const host = config.getString('host');\n const catalogPath =\n config.getOptionalString('catalogPath') ?? DEFAULT_CATALOG_PATH;\n const projectKeyPattern = config.getOptionalString('filters.projectKey');\n const repoSlugPattern = config.getOptionalString('filters.repoSlug');\n\n return {\n id,\n host,\n catalogPath,\n filters: {\n projectKey: projectKeyPattern ? new RegExp(projectKeyPattern) : undefined,\n repoSlug: repoSlugPattern ? new RegExp(repoSlugPattern) : undefined,\n },\n };\n}\n","/*\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 EntityProvider,\n EntityProviderConnection,\n} from '@backstage/plugin-catalog-backend';\nimport { Logger } from 'winston';\nimport { Config } from '@backstage/config';\nimport { TaskRunner } from '@backstage/backend-tasks';\nimport * as uuid from 'uuid';\nimport {\n BitbucketServerLocationParser,\n defaultBitbucketServerLocationParser,\n} from './BitbucketServerLocationParser';\nimport {\n BitbucketServerIntegration,\n ScmIntegrations,\n} from '@backstage/integration';\nimport { BitbucketServerClient, paginated } from '../lib';\nimport { InputError } from '@backstage/errors';\nimport {\n BitbucketServerEntityProviderConfig,\n readProviderConfigs,\n} from './BitbucketServerEntityProviderConfig';\nimport { Entity } from '@backstage/catalog-model';\n\n/**\n * Discovers catalog files located in Bitbucket Server.\n * The provider will search your Bitbucket Server instance and register catalog files matching the configured path\n * as Location entity and via following processing steps add all contained catalog entities.\n * This can be useful as an alternative to static locations or manually adding things to the catalog.\n *\n * @public\n */\nexport class BitbucketServerEntityProvider implements EntityProvider {\n private readonly integration: BitbucketServerIntegration;\n private readonly config: BitbucketServerEntityProviderConfig;\n private readonly parser: BitbucketServerLocationParser;\n private readonly logger: Logger;\n private readonly scheduleFn: () => Promise<void>;\n private connection?: EntityProviderConnection;\n\n static fromConfig(\n config: Config,\n options: {\n logger: Logger;\n schedule: TaskRunner;\n parser?: BitbucketServerLocationParser;\n },\n ): BitbucketServerEntityProvider[] {\n const integrations = ScmIntegrations.fromConfig(config);\n\n return readProviderConfigs(config).map(providerConfig => {\n const integration = integrations.bitbucketServer.byHost(\n providerConfig.host,\n );\n if (!integration) {\n throw new InputError(\n `No BitbucketServer integration found that matches host ${providerConfig.host}`,\n );\n }\n return new BitbucketServerEntityProvider(\n providerConfig,\n integration,\n options.logger,\n options.schedule,\n options.parser,\n );\n });\n }\n\n private constructor(\n config: BitbucketServerEntityProviderConfig,\n integration: BitbucketServerIntegration,\n logger: Logger,\n schedule: TaskRunner,\n parser?: BitbucketServerLocationParser,\n ) {\n this.integration = integration;\n this.config = config;\n this.parser = parser || defaultBitbucketServerLocationParser;\n this.logger = logger.child({\n target: this.getProviderName(),\n });\n this.scheduleFn = this.createScheduleFn(schedule);\n }\n\n private createScheduleFn(schedule: TaskRunner): () => Promise<void> {\n return async () => {\n const taskId = `${this.getProviderName()}:refresh`;\n return schedule.run({\n id: taskId,\n fn: async () => {\n const logger = this.logger.child({\n class: BitbucketServerEntityProvider.prototype.constructor.name,\n taskId,\n taskInstanceId: uuid.v4(),\n });\n\n try {\n await this.refresh(logger);\n } catch (error) {\n logger.error(error);\n }\n },\n });\n };\n }\n\n /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.getProviderName} */\n getProviderName(): string {\n return `bitbucketServer-provider:${this.config.id}`;\n }\n\n /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.connect} */\n async connect(connection: EntityProviderConnection): Promise<void> {\n this.connection = connection;\n await this.scheduleFn();\n }\n\n async refresh(logger: Logger) {\n if (!this.connection) {\n throw new Error('Not initialized');\n }\n\n logger.info('Discovering catalog files in Bitbucket Server repositories');\n\n const entities = await this.findEntities();\n\n await this.connection.applyMutation({\n type: 'full',\n entities: entities.map(entity => ({\n locationKey: this.getProviderName(),\n entity: entity,\n })),\n });\n\n logger.info(\n `Committed ${entities.length} entities for Bitbucket Server repositories`,\n );\n }\n\n private async findEntities(): Promise<Entity[]> {\n const client = BitbucketServerClient.fromConfig({\n config: this.integration.config,\n });\n const projects = paginated(options =>\n client.listProjects({ listOptions: options }),\n );\n const result: Entity[] = [];\n for await (const project of projects) {\n if (\n this.config?.filters?.projectKey &&\n !this.config.filters.projectKey.test(project.key)\n ) {\n continue;\n }\n const repositories = paginated(options =>\n client.listRepositories({\n projectKey: project.key,\n listOptions: options,\n }),\n );\n for await (const repository of repositories) {\n if (\n this.config?.filters?.repoSlug &&\n !this.config.filters.repoSlug.test(repository.slug)\n ) {\n continue;\n }\n for await (const entity of this.parser({\n client,\n logger: this.logger,\n location: {\n type: 'url',\n target: `${repository.links.self[0].href}${this.config.catalogPath}`,\n presence: 'optional',\n },\n })) {\n result.push(entity);\n }\n }\n }\n return result;\n }\n}\n"],"names":["fetch","getBitbucketServerRequestOptions","Request","locationSpecToLocationEntity","ScmIntegrations","InputError","uuid"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIO,MAAM,qBAAqB,CAAC;AACnC,EAAE,OAAO,UAAU,CAAC,OAAO,EAAE;AAC7B,IAAI,OAAO,IAAI,qBAAqB,CAAC,OAAO,CAAC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AChF,YAAY,QAAQ,EAAE,UAAU;AAChC,WAAW;AACX,SAAS,CAAC,EAAE;AACZ,UAAU,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC9B,SAAS;AACT,OAAO;AACP,KAAK;AACL,IAAI,OAAO,MAAM,CAAC;AAClB,GAAG;AACH;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { BitbucketServerIntegrationConfig } from '@backstage/integration';
|
|
2
|
+
import { LocationSpec, EntityProvider, EntityProviderConnection } from '@backstage/plugin-catalog-backend';
|
|
3
|
+
import { Logger } from 'winston';
|
|
4
|
+
import { Config } from '@backstage/config';
|
|
5
|
+
import { TaskRunner } from '@backstage/backend-tasks';
|
|
6
|
+
import { Entity } from '@backstage/catalog-model';
|
|
7
|
+
|
|
8
|
+
/** @public */
|
|
9
|
+
declare type BitbucketServerRepository = {
|
|
10
|
+
project: {
|
|
11
|
+
key: string;
|
|
12
|
+
};
|
|
13
|
+
slug: string;
|
|
14
|
+
description: string;
|
|
15
|
+
links: Record<string, {
|
|
16
|
+
href: string;
|
|
17
|
+
}[]>;
|
|
18
|
+
};
|
|
19
|
+
/** @public */
|
|
20
|
+
declare type BitbucketServerProject = {
|
|
21
|
+
key: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A client for interacting with a Bitbucket Server instance
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
declare class BitbucketServerClient {
|
|
30
|
+
private readonly config;
|
|
31
|
+
static fromConfig(options: {
|
|
32
|
+
config: BitbucketServerIntegrationConfig;
|
|
33
|
+
}): BitbucketServerClient;
|
|
34
|
+
constructor(options: {
|
|
35
|
+
config: BitbucketServerIntegrationConfig;
|
|
36
|
+
});
|
|
37
|
+
listProjects(options: {
|
|
38
|
+
listOptions?: BitbucketServerListOptions;
|
|
39
|
+
}): Promise<BitbucketServerPagedResponse<BitbucketServerProject>>;
|
|
40
|
+
listRepositories(options: {
|
|
41
|
+
projectKey: string;
|
|
42
|
+
listOptions?: BitbucketServerListOptions;
|
|
43
|
+
}): Promise<BitbucketServerPagedResponse<BitbucketServerRepository>>;
|
|
44
|
+
getFile(options: {
|
|
45
|
+
projectKey: string;
|
|
46
|
+
repo: string;
|
|
47
|
+
path: string;
|
|
48
|
+
}): Promise<Response>;
|
|
49
|
+
getRepository(options: {
|
|
50
|
+
projectKey: string;
|
|
51
|
+
repo: string;
|
|
52
|
+
}): Promise<BitbucketServerRepository>;
|
|
53
|
+
resolvePath(options: {
|
|
54
|
+
projectKey: string;
|
|
55
|
+
repo: string;
|
|
56
|
+
path: string;
|
|
57
|
+
}): {
|
|
58
|
+
path: string;
|
|
59
|
+
};
|
|
60
|
+
private pagedRequest;
|
|
61
|
+
private getTypeMapped;
|
|
62
|
+
private get;
|
|
63
|
+
private request;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
declare type BitbucketServerListOptions = {
|
|
69
|
+
[key: string]: number | undefined;
|
|
70
|
+
limit?: number | undefined;
|
|
71
|
+
start?: number | undefined;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
declare type BitbucketServerPagedResponse<T> = {
|
|
77
|
+
size: number;
|
|
78
|
+
limit: number;
|
|
79
|
+
start: number;
|
|
80
|
+
isLastPage: boolean;
|
|
81
|
+
values: T[];
|
|
82
|
+
nextPageStart: number;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* A custom callback that reacts to finding a location by yielding entities.
|
|
87
|
+
* Can be used for custom location/repository parsing logic.
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
declare type BitbucketServerLocationParser = (options: {
|
|
92
|
+
client: BitbucketServerClient;
|
|
93
|
+
location: LocationSpec;
|
|
94
|
+
logger: Logger;
|
|
95
|
+
}) => AsyncIterable<Entity>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Discovers catalog files located in Bitbucket Server.
|
|
99
|
+
* The provider will search your Bitbucket Server instance and register catalog files matching the configured path
|
|
100
|
+
* as Location entity and via following processing steps add all contained catalog entities.
|
|
101
|
+
* This can be useful as an alternative to static locations or manually adding things to the catalog.
|
|
102
|
+
*
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
declare class BitbucketServerEntityProvider implements EntityProvider {
|
|
106
|
+
private readonly integration;
|
|
107
|
+
private readonly config;
|
|
108
|
+
private readonly parser;
|
|
109
|
+
private readonly logger;
|
|
110
|
+
private readonly scheduleFn;
|
|
111
|
+
private connection?;
|
|
112
|
+
static fromConfig(config: Config, options: {
|
|
113
|
+
logger: Logger;
|
|
114
|
+
schedule: TaskRunner;
|
|
115
|
+
parser?: BitbucketServerLocationParser;
|
|
116
|
+
}): BitbucketServerEntityProvider[];
|
|
117
|
+
private constructor();
|
|
118
|
+
private createScheduleFn;
|
|
119
|
+
/** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.getProviderName} */
|
|
120
|
+
getProviderName(): string;
|
|
121
|
+
/** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.connect} */
|
|
122
|
+
connect(connection: EntityProviderConnection): Promise<void>;
|
|
123
|
+
refresh(logger: Logger): Promise<void>;
|
|
124
|
+
private findEntities;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { BitbucketServerClient, BitbucketServerEntityProvider, BitbucketServerListOptions, BitbucketServerLocationParser, BitbucketServerPagedResponse, BitbucketServerProject, BitbucketServerRepository };
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@backstage/plugin-catalog-backend-module-bitbucket-server",
|
|
3
|
+
"version": "0.0.0-nightly-20220810023539",
|
|
4
|
+
"main": "dist/index.cjs.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"private": false,
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public",
|
|
10
|
+
"main": "dist/index.cjs.js",
|
|
11
|
+
"types": "dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"backstage": {
|
|
14
|
+
"role": "backend-plugin-module"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://backstage.io",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/backstage/backstage",
|
|
20
|
+
"directory": "plugins/catalog-backend-module-bitbucket-server"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"backstage"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"start": "backstage-cli package start",
|
|
27
|
+
"build": "backstage-cli package build",
|
|
28
|
+
"lint": "backstage-cli package lint",
|
|
29
|
+
"test": "backstage-cli package test",
|
|
30
|
+
"clean": "backstage-cli package clean",
|
|
31
|
+
"prepack": "backstage-cli package prepack",
|
|
32
|
+
"postpack": "backstage-cli package postpack"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@backstage/backend-common": "0.0.0-nightly-20220810023539",
|
|
36
|
+
"@backstage/backend-tasks": "0.0.0-nightly-20220810023539",
|
|
37
|
+
"@backstage/catalog-model": "^1.0.1",
|
|
38
|
+
"@backstage/config": "^1.0.0",
|
|
39
|
+
"@backstage/errors": "^1.0.0",
|
|
40
|
+
"@backstage/integration": "0.0.0-nightly-20220810023539",
|
|
41
|
+
"@backstage/plugin-catalog-backend": "0.0.0-nightly-20220810023539",
|
|
42
|
+
"cross-fetch": "^3.1.5",
|
|
43
|
+
"uuid": "^8.0.0",
|
|
44
|
+
"winston": "^3.2.1"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@backstage/backend-test-utils": "0.0.0-nightly-20220810023539",
|
|
48
|
+
"@backstage/cli": "0.0.0-nightly-20220810023539",
|
|
49
|
+
"msw": "^0.44.0"
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"dist",
|
|
53
|
+
"config.d.ts"
|
|
54
|
+
],
|
|
55
|
+
"configSchema": "config.d.ts"
|
|
56
|
+
}
|