@backstage/plugin-user-settings-backend 0.0.0-nightly-20220923030237
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 +27 -0
- package/README.md +88 -0
- package/dist/index.cjs.js +128 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/migrations/20220824183000_init.js +41 -0
- package/package.json +53 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# @backstage/plugin-user-settings-backend
|
|
2
|
+
|
|
3
|
+
## 0.0.0-nightly-20220923030237
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @backstage/catalog-model@0.0.0-nightly-20220923030237
|
|
9
|
+
- @backstage/backend-common@0.0.0-nightly-20220923030237
|
|
10
|
+
- @backstage/errors@0.0.0-nightly-20220923030237
|
|
11
|
+
- @backstage/types@1.0.0
|
|
12
|
+
- @backstage/plugin-auth-node@0.0.0-nightly-20220923030237
|
|
13
|
+
|
|
14
|
+
## 0.1.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- 108cdc3912: Added new plugin `@backstage/plugin-user-settings-backend` to store user related
|
|
19
|
+
settings in the database.
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies
|
|
24
|
+
- @backstage/backend-common@0.15.1
|
|
25
|
+
- @backstage/plugin-auth-node@0.2.5
|
|
26
|
+
- @backstage/catalog-model@1.1.1
|
|
27
|
+
- @backstage/errors@1.1.1
|
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# User settings backend
|
|
2
|
+
|
|
3
|
+
This backend allows to save user specific settings. All requests need to be
|
|
4
|
+
authorized, as the user identifier (`userEntityRef`) is resolved using the
|
|
5
|
+
authorization token.
|
|
6
|
+
|
|
7
|
+
## Setup backend
|
|
8
|
+
|
|
9
|
+
1. Install the backend plugin:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# From your Backstage root directory
|
|
13
|
+
yarn --cwd packages/backend add @backstage/plugin-user-settings-backend
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
1. Configure the routes by adding a new `userSettings.ts` file in
|
|
17
|
+
`packages/backend/src/plugins/`:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
// packages/backend/src/plugins/userSettings.ts
|
|
21
|
+
import { createRouter } from '@backstage/plugin-user-settings-backend';
|
|
22
|
+
import { PluginEnvironment } from '../types';
|
|
23
|
+
|
|
24
|
+
export default async function createPlugin(env: PluginEnvironment) {
|
|
25
|
+
return await createRouter({
|
|
26
|
+
database: env.database,
|
|
27
|
+
identity: env.identity,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
3. Add the new routes to your backend by modifying `packages/backend/src/index.ts`:
|
|
33
|
+
|
|
34
|
+
```diff
|
|
35
|
+
// packages/backend/src/index.ts
|
|
36
|
+
+import userSettings from './plugins/userSettings';
|
|
37
|
+
async function main() {
|
|
38
|
+
+ const userSettingsEnv = useHotMemoize(module, () => createEnv('user-settings'));
|
|
39
|
+
const apiRouter = Router();
|
|
40
|
+
+ apiRouter.use('/user-settings', await userSettings(userSettingsEnv));
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Setup app
|
|
45
|
+
|
|
46
|
+
To make use of the user settings backend, replace the `WebStorage` with the
|
|
47
|
+
`UserSettingsStorage` by using the `storageApiRef`.
|
|
48
|
+
|
|
49
|
+
```diff
|
|
50
|
+
// packages/app/src/apis.ts
|
|
51
|
+
import {
|
|
52
|
+
AnyApiFactory,
|
|
53
|
+
createApiFactory,
|
|
54
|
+
+ discoveryApiRef,
|
|
55
|
+
+ fetchApiRef,
|
|
56
|
+
errorApiRef,
|
|
57
|
+
+ identityApi,
|
|
58
|
+
+ storageApiRef,
|
|
59
|
+
} from '@backstage/core-plugin-api';
|
|
60
|
+
+import { UserSettingsStorage } from '@backstage/plugin-user-settings';
|
|
61
|
+
|
|
62
|
+
export const apis: AnyApiFactory[] = [
|
|
63
|
+
+ createApiFactory({
|
|
64
|
+
+ api: storageApiRef,
|
|
65
|
+
+ deps: {
|
|
66
|
+
+ discoveryApi: discoveryApiRef,
|
|
67
|
+
+ errorApi: errorApiRef,
|
|
68
|
+
+ fetchApi: fetchApiRef,
|
|
69
|
+
+ identityApi: identityApiRef
|
|
70
|
+
+ },
|
|
71
|
+
+ factory: deps => UserSettingsStorage.create(deps),
|
|
72
|
+
+ }),
|
|
73
|
+
];
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Development
|
|
77
|
+
|
|
78
|
+
Use `yarn start` to start the local dev environment. To simplify the access to
|
|
79
|
+
the API, the token will automatically be set to `user:default/john_doe`.
|
|
80
|
+
|
|
81
|
+
You can change the user by setting a custom `Authorization` header. To keep
|
|
82
|
+
things simple, the raw `Bearer` value will directly be used as user.
|
|
83
|
+
|
|
84
|
+
_Example:_
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
curl --request GET 'http://localhost:7007/user-settings' --header 'Authorization: Bearer user:default/custom-user'
|
|
88
|
+
```
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var backendCommon = require('@backstage/backend-common');
|
|
6
|
+
var errors = require('@backstage/errors');
|
|
7
|
+
var express = require('express');
|
|
8
|
+
var Router = require('express-promise-router');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
|
|
13
|
+
var Router__default = /*#__PURE__*/_interopDefaultLegacy(Router);
|
|
14
|
+
|
|
15
|
+
const migrationsDir = backendCommon.resolvePackagePath(
|
|
16
|
+
"@backstage/plugin-user-settings-backend",
|
|
17
|
+
"migrations"
|
|
18
|
+
);
|
|
19
|
+
class DatabaseUserSettingsStore {
|
|
20
|
+
constructor(db) {
|
|
21
|
+
this.db = db;
|
|
22
|
+
}
|
|
23
|
+
static async create(options) {
|
|
24
|
+
var _a;
|
|
25
|
+
const { database } = options;
|
|
26
|
+
const client = await database.getClient();
|
|
27
|
+
if (!((_a = database.migrations) == null ? void 0 : _a.skip)) {
|
|
28
|
+
await client.migrate.latest({
|
|
29
|
+
directory: migrationsDir
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return new DatabaseUserSettingsStore(client);
|
|
33
|
+
}
|
|
34
|
+
async get(options) {
|
|
35
|
+
const rows = await this.db("user_settings").where({
|
|
36
|
+
user_entity_ref: options.userEntityRef,
|
|
37
|
+
bucket: options.bucket,
|
|
38
|
+
key: options.key
|
|
39
|
+
}).select(["bucket", "key", "value"]);
|
|
40
|
+
if (!rows.length) {
|
|
41
|
+
throw new errors.NotFoundError(
|
|
42
|
+
`Unable to find '${options.key}' in bucket '${options.bucket}'`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
bucket: rows[0].bucket,
|
|
47
|
+
key: rows[0].key,
|
|
48
|
+
value: JSON.parse(rows[0].value)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
async set(options) {
|
|
52
|
+
await this.db("user_settings").insert({
|
|
53
|
+
user_entity_ref: options.userEntityRef,
|
|
54
|
+
bucket: options.bucket,
|
|
55
|
+
key: options.key,
|
|
56
|
+
value: JSON.stringify(options.value)
|
|
57
|
+
}).onConflict(["user_entity_ref", "bucket", "key"]).merge(["value"]);
|
|
58
|
+
}
|
|
59
|
+
async delete(options) {
|
|
60
|
+
await this.db("user_settings").where({
|
|
61
|
+
user_entity_ref: options.userEntityRef,
|
|
62
|
+
bucket: options.bucket,
|
|
63
|
+
key: options.key
|
|
64
|
+
}).delete();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function createRouter(options) {
|
|
69
|
+
const userSettingsStore = await DatabaseUserSettingsStore.create({
|
|
70
|
+
database: options.database
|
|
71
|
+
});
|
|
72
|
+
return await createRouterInternal({
|
|
73
|
+
userSettingsStore,
|
|
74
|
+
identity: options.identity
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async function createRouterInternal(options) {
|
|
78
|
+
const router = Router__default["default"]();
|
|
79
|
+
router.use(express__default["default"].json());
|
|
80
|
+
const getUserEntityRef = async (req) => {
|
|
81
|
+
const identity = await options.identity.getIdentity({ request: req });
|
|
82
|
+
if (!identity) {
|
|
83
|
+
throw new errors.AuthenticationError(`Missing token in 'authorization' header`);
|
|
84
|
+
}
|
|
85
|
+
return identity.identity.userEntityRef;
|
|
86
|
+
};
|
|
87
|
+
router.get("/buckets/:bucket/keys/:key", async (req, res) => {
|
|
88
|
+
const userEntityRef = await getUserEntityRef(req);
|
|
89
|
+
const { bucket, key } = req.params;
|
|
90
|
+
const setting = await options.userSettingsStore.get({
|
|
91
|
+
userEntityRef,
|
|
92
|
+
bucket,
|
|
93
|
+
key
|
|
94
|
+
});
|
|
95
|
+
res.json(setting);
|
|
96
|
+
});
|
|
97
|
+
router.put("/buckets/:bucket/keys/:key", async (req, res) => {
|
|
98
|
+
const userEntityRef = await getUserEntityRef(req);
|
|
99
|
+
const { bucket, key } = req.params;
|
|
100
|
+
const { value } = req.body;
|
|
101
|
+
if (value === void 0) {
|
|
102
|
+
throw new errors.InputError('Missing required field "value"');
|
|
103
|
+
}
|
|
104
|
+
await options.userSettingsStore.set({
|
|
105
|
+
userEntityRef,
|
|
106
|
+
bucket,
|
|
107
|
+
key,
|
|
108
|
+
value
|
|
109
|
+
});
|
|
110
|
+
const setting = await options.userSettingsStore.get({
|
|
111
|
+
userEntityRef,
|
|
112
|
+
bucket,
|
|
113
|
+
key
|
|
114
|
+
});
|
|
115
|
+
res.json(setting);
|
|
116
|
+
});
|
|
117
|
+
router.delete("/buckets/:bucket/keys/:key", async (req, res) => {
|
|
118
|
+
const userEntityRef = await getUserEntityRef(req);
|
|
119
|
+
const { bucket, key } = req.params;
|
|
120
|
+
await options.userSettingsStore.delete({ userEntityRef, bucket, key });
|
|
121
|
+
res.send(204).end();
|
|
122
|
+
});
|
|
123
|
+
router.use(backendCommon.errorHandler());
|
|
124
|
+
return router;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
exports.createRouter = createRouter;
|
|
128
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/database/DatabaseUserSettingsStore.ts","../src/service/router.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 PluginDatabaseManager,\n resolvePackagePath,\n} from '@backstage/backend-common';\nimport { NotFoundError } from '@backstage/errors';\nimport { JsonValue } from '@backstage/types';\nimport { Knex } from 'knex';\nimport { UserSettingsStore, type UserSetting } from './UserSettingsStore';\n\nconst migrationsDir = resolvePackagePath(\n '@backstage/plugin-user-settings-backend',\n 'migrations',\n);\n\n/**\n * @public\n */\nexport type RawDbUserSettingsRow = {\n user_entity_ref: string;\n bucket: string;\n key: string;\n value: string;\n};\n\n/**\n * Store to manage the user settings.\n *\n * @public\n */\nexport class DatabaseUserSettingsStore implements UserSettingsStore {\n static async create(options: {\n database: PluginDatabaseManager;\n }): Promise<DatabaseUserSettingsStore> {\n const { database } = options;\n const client = await database.getClient();\n\n if (!database.migrations?.skip) {\n await client.migrate.latest({\n directory: migrationsDir,\n });\n }\n\n return new DatabaseUserSettingsStore(client);\n }\n\n private constructor(private readonly db: Knex) {}\n\n async get(options: {\n userEntityRef: string;\n bucket: string;\n key: string;\n }): Promise<UserSetting> {\n const rows = await this.db<RawDbUserSettingsRow>('user_settings')\n .where({\n user_entity_ref: options.userEntityRef,\n bucket: options.bucket,\n key: options.key,\n })\n .select(['bucket', 'key', 'value']);\n\n if (!rows.length) {\n throw new NotFoundError(\n `Unable to find '${options.key}' in bucket '${options.bucket}'`,\n );\n }\n\n return {\n bucket: rows[0].bucket,\n key: rows[0].key,\n value: JSON.parse(rows[0].value),\n };\n }\n\n async set(options: {\n userEntityRef: string;\n bucket: string;\n key: string;\n value: JsonValue;\n }): Promise<void> {\n await this.db<RawDbUserSettingsRow>('user_settings')\n .insert({\n user_entity_ref: options.userEntityRef,\n bucket: options.bucket,\n key: options.key,\n value: JSON.stringify(options.value),\n })\n .onConflict(['user_entity_ref', 'bucket', 'key'])\n .merge(['value']);\n }\n\n async delete(options: {\n userEntityRef: string;\n bucket: string;\n key: string;\n }): Promise<void> {\n await this.db<RawDbUserSettingsRow>('user_settings')\n .where({\n user_entity_ref: options.userEntityRef,\n bucket: options.bucket,\n key: options.key,\n })\n .delete();\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 { errorHandler, PluginDatabaseManager } from '@backstage/backend-common';\nimport { AuthenticationError, InputError } from '@backstage/errors';\nimport { IdentityApi } from '@backstage/plugin-auth-node';\nimport express, { Request } from 'express';\nimport Router from 'express-promise-router';\nimport { DatabaseUserSettingsStore } from '../database/DatabaseUserSettingsStore';\nimport { UserSettingsStore } from '../database/UserSettingsStore';\n\n/**\n * @public\n */\nexport interface RouterOptions {\n database: PluginDatabaseManager;\n identity: IdentityApi;\n}\n\n/**\n * Create the user settings backend routes.\n *\n * @public\n */\nexport async function createRouter(\n options: RouterOptions,\n): Promise<express.Router> {\n const userSettingsStore = await DatabaseUserSettingsStore.create({\n database: options.database,\n });\n\n return await createRouterInternal({\n userSettingsStore,\n identity: options.identity,\n });\n}\n\nexport async function createRouterInternal(options: {\n identity: IdentityApi;\n userSettingsStore: UserSettingsStore;\n}): Promise<express.Router> {\n const router = Router();\n router.use(express.json());\n\n /**\n * Helper method to extract the userEntityRef from the request.\n */\n const getUserEntityRef = async (req: Request): Promise<string> => {\n // throws an AuthenticationError in case the token exists but is invalid\n const identity = await options.identity.getIdentity({ request: req });\n if (!identity) {\n throw new AuthenticationError(`Missing token in 'authorization' header`);\n }\n\n return identity.identity.userEntityRef;\n };\n\n // get a single value\n router.get('/buckets/:bucket/keys/:key', async (req, res) => {\n const userEntityRef = await getUserEntityRef(req);\n const { bucket, key } = req.params;\n\n const setting = await options.userSettingsStore.get({\n userEntityRef,\n bucket,\n key,\n });\n\n res.json(setting);\n });\n\n // set a single value\n router.put('/buckets/:bucket/keys/:key', async (req, res) => {\n const userEntityRef = await getUserEntityRef(req);\n const { bucket, key } = req.params;\n const { value } = req.body;\n\n if (value === undefined) {\n throw new InputError('Missing required field \"value\"');\n }\n\n await options.userSettingsStore.set({\n userEntityRef,\n bucket,\n key,\n value,\n });\n const setting = await options.userSettingsStore.get({\n userEntityRef,\n bucket,\n key,\n });\n\n res.json(setting);\n });\n\n // get a single value\n router.delete('/buckets/:bucket/keys/:key', async (req, res) => {\n const userEntityRef = await getUserEntityRef(req);\n const { bucket, key } = req.params;\n\n await options.userSettingsStore.delete({ userEntityRef, bucket, key });\n\n res.send(204).end();\n });\n\n router.use(errorHandler());\n\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stage/plugin-auth-node';
|
|
3
|
+
import express from 'express';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
interface RouterOptions {
|
|
9
|
+
database: PluginDatabaseManager;
|
|
10
|
+
identity: IdentityApi;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Create the user settings backend routes.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
declare function createRouter(options: RouterOptions): Promise<express.Router>;
|
|
18
|
+
|
|
19
|
+
export { RouterOptions, createRouter };
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
/**
|
|
18
|
+
* @param {import('knex').Knex} knex
|
|
19
|
+
*/
|
|
20
|
+
exports.up = async function up(knex) {
|
|
21
|
+
await knex.schema.createTable('user_settings', table => {
|
|
22
|
+
table.comment('The table of user related settings');
|
|
23
|
+
|
|
24
|
+
table
|
|
25
|
+
.string('user_entity_ref')
|
|
26
|
+
.notNullable()
|
|
27
|
+
.comment('The entityRef of the user');
|
|
28
|
+
table.string('bucket').notNullable().comment('Name of the bucket');
|
|
29
|
+
table.string('key').notNullable().comment('Key of a bucket value');
|
|
30
|
+
table.text('value').notNullable().comment('The value');
|
|
31
|
+
|
|
32
|
+
table.primary(['user_entity_ref', 'bucket', 'key']);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {import('knex').Knex} knex
|
|
38
|
+
*/
|
|
39
|
+
exports.down = async function down(knex) {
|
|
40
|
+
await knex.schema.dropTable('user_settings');
|
|
41
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@backstage/plugin-user-settings-backend",
|
|
3
|
+
"description": "The Backstage backend plugin to manage user settings",
|
|
4
|
+
"version": "0.0.0-nightly-20220923030237",
|
|
5
|
+
"main": "dist/index.cjs.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"backstage": {
|
|
9
|
+
"role": "backend-plugin"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"main": "dist/index.cjs.js",
|
|
14
|
+
"types": "dist/index.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/backstage/backstage",
|
|
19
|
+
"directory": "plugins/user-settings-backend"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"start": "backstage-cli package start",
|
|
23
|
+
"build": "backstage-cli package build",
|
|
24
|
+
"lint": "backstage-cli package lint",
|
|
25
|
+
"test": "backstage-cli package test",
|
|
26
|
+
"prepack": "backstage-cli package prepack",
|
|
27
|
+
"postpack": "backstage-cli package postpack",
|
|
28
|
+
"clean": "backstage-cli package clean"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@backstage/backend-common": "^0.0.0-nightly-20220923030237",
|
|
32
|
+
"@backstage/catalog-model": "^0.0.0-nightly-20220923030237",
|
|
33
|
+
"@backstage/errors": "^0.0.0-nightly-20220923030237",
|
|
34
|
+
"@backstage/plugin-auth-node": "^0.0.0-nightly-20220923030237",
|
|
35
|
+
"@backstage/types": "^1.0.0",
|
|
36
|
+
"@types/express": "^4.17.6",
|
|
37
|
+
"express": "^4.17.1",
|
|
38
|
+
"express-promise-router": "^4.1.0",
|
|
39
|
+
"knex": "^2.0.0",
|
|
40
|
+
"winston": "^3.2.1",
|
|
41
|
+
"yn": "^4.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@backstage/backend-test-utils": "^0.0.0-nightly-20220923030237",
|
|
45
|
+
"@backstage/cli": "^0.0.0-nightly-20220923030237",
|
|
46
|
+
"@types/supertest": "^2.0.8",
|
|
47
|
+
"supertest": "^6.1.3"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"dist",
|
|
51
|
+
"migrations"
|
|
52
|
+
]
|
|
53
|
+
}
|